CGI scripts with slinger using C

Hello.

I have been trying to write a CGI bin script, written in C, which will
work with slinger. My index file is as follows:

Test Page for QNX4 Slinger

This is a test page for the QNX Slinger Web Server.

Click here to run CGI script.

My CGI program written in C is:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

main(int argc, char *argv[])
{
char *test=“This is a test.

”;


fprintf(stdout,"");
fprintf(stdout,"");

fprintf(stdout,“

Query Results

”);

fprintf(stdout,getenv(“QUERY_STRING”) );
fprintf(stdout,“Test String = %s.\n”, test);
fprintf(stderr, “

End of example.

”);

fprintf(stdout,"");
fprintf(stdout,"");
return;
}

When I click on the reference to the CGI script from the test page in my
Netscape browser, the script executes and I see the title, displayed in
H1 format but the stuff following the title shows as follows:

Test string = %s.\n

It would appear that the fprintf statements are not substituting the
variables appropriately, since it is just printing the string as is. I
am not sure if this is an inadequacy with slinger or if I am just not
writing the CGI program properly. I copied it from a web page on CGI
scripts, so I believe that it is correct. At least it would appear to
be working. I guess I would be curious to find out how slinger executes
a CGI script from an HTML anchor.

TIA.

Rodney Lott

I’m using apache not slinger but one problem is the lack of a header
defining a mime-type, followed by at least one blank line to separate it
from the document… I’m suprised your getting anything, IE would have choked
on it.
something like:

printf(“Content-type: text/html\n\n”);

which goes before your

you’ve got an unmatched

in there too (char *test=“This is a
test.

”; ) which might confuse things

John Uff
juff@fax.co.uk
http://fax.co.uk The UK’s Email to Fax gateway



“Rodney Lott” <rod@fuelcelltechnologies.ca> wrote in message
news:39BD2D30.E7F3B785@fuelcelltechnologies.ca

Hello.

I have been trying to write a CGI bin script, written in C, which will
work with slinger. My index file is as follows:

html
head
title>Test Page for QNX4 Slinger</title
/head

body

p>This is a test page for the QNX Slinger Web Server.</p

a href="/cgibin/myecho?name=test">Click here to run CGI script.</a

/body
/html

My CGI program written in C is:

#include <stdio.h
#include <stdlib.h
#include <string.h

main(int argc, char *argv[])


char *test=“This is a test.

”;


fprintf(stdout,"");
fprintf(stdout,"");

fprintf(stdout,“

Query Results

”);

fprintf(stdout,getenv(“QUERY_STRING”) );
fprintf(stdout,“Test String = %s.\n”, test);
fprintf(stderr, “

End of example.

”);

fprintf(stdout,"");
fprintf(stdout,"");
return;
}

When I click on the reference to the CGI script from the test page in my
Netscape browser, the script executes and I see the title, displayed in
H1 format but the stuff following the title shows as follows:

blank line where the QUERY_STRING should have displayed
Test string = %s.\n

miscallaneous characters and garble

It would appear that the fprintf statements are not substituting the
variables appropriately, since it is just printing the string as is. I
am not sure if this is an inadequacy with slinger or if I am just not
writing the CGI program properly. I copied it from a web page on CGI
scripts, so I believe that it is correct. At least it would appear to
be working. I guess I would be curious to find out how slinger executes
a CGI script from an HTML anchor.

TIA.

Rodney Lott

Thanks for replying. I fixed my

error and added the “Content-type”
statement (forgot about that one). I am still getting the same result
on Netscape, however. Any other ideas?

You also mentioned that you are using apache. What version are you
using? I am currently trying out apache myself and downloaded the
binary distribution from the Apache website for QNX (ie.
apache_1.3.9-PCI-qssl-qnx32.tar.gz). I would be interested in learning
what you did, in terms of whether you just used a binary distribution or
whether you compiled the code yourself.

Rodney Lott

John Uff wrote:

I’m using apache not slinger but one problem is the lack of a header
defining a mime-type, followed by at least one blank line to separate it
from the document… I’m suprised your getting anything, IE would have choked
on it.
something like:

printf(“Content-type: text/html\n\n”);

which goes before your <html

you’ve got an unmatched

in there too (char *test=“This is a
test.

”; ) which might confuse things

John Uff
juff@fax.co.uk
http://fax.co.uk > The UK’s Email to Fax gateway

“Rodney Lott” <> rod@fuelcelltechnologies.ca> > wrote in message
news:> 39BD2D30.E7F3B785@fuelcelltechnologies.ca> …
Hello.

I have been trying to write a CGI bin script, written in C, which will
work with slinger. My index file is as follows:

html
head
title>Test Page for QNX4 Slinger</title
/head

body

p>This is a test page for the QNX Slinger Web Server.</p

a href="/cgibin/myecho?name=test">Click here to run CGI script.</a

/body
/html

My CGI program written in C is:

#include <stdio.h
#include <stdlib.h
#include <string.h

main(int argc, char *argv[])


char *test=“This is a test.

”;


fprintf(stdout,"");
fprintf(stdout,"");

fprintf(stdout,“

Query Results

”);

fprintf(stdout,getenv(“QUERY_STRING”) );
fprintf(stdout,“Test String = %s.\n”, test);
fprintf(stderr, “

End of example.

”);

fprintf(stdout,"");
fprintf(stdout,"");
return;
}

When I click on the reference to the CGI script from the test page in my
Netscape browser, the script executes and I see the title, displayed in
H1 format but the stuff following the title shows as follows:

blank line where the QUERY_STRING should have displayed
Test string = %s.\n

miscallaneous characters and garble

It would appear that the fprintf statements are not substituting the
variables appropriately, since it is just printing the string as is. I
am not sure if this is an inadequacy with slinger or if I am just not
writing the CGI program properly. I copied it from a web page on CGI
scripts, so I believe that it is correct. At least it would appear to
be working. I guess I would be curious to find out how slinger executes
a CGI script from an HTML anchor.

TIA.

Rodney Lott

Just a note:
We’re also using apache (apache_1.3.9-PCI-qssl-qnx32.tar.gz)
and its working great. We’re using it to both serve HTML and
also to control/query our processes via CGI-BIN.
-Paul

John Uff wrote in message …

I’m using apache not slinger but one problem is the lack of a header
defining a mime-type, followed by at least one blank line to separate it
from the document… I’m suprised your getting anything, IE would have
choked
on it.
something like:

printf(“Content-type: text/html\n\n”);

which goes before your <html

you’ve got an unmatched

in there too (char *test=“This is a
test.

”; ) which might confuse things

You also have one of your messages going to ‘stderr’ that will go
to oblivion.

A quick & easy test is from the command line:
QUERY_STRING=test ./myecho
… and see if it comes out correctly.

I use slinger & CGI all the time but recently switch to Apache and PHP4
for all web-based development work.

Much simpler then “C” for CGI-type stuff.

Jay

Hello.

That’s something that I am interested in. Did you download the binaries
and use them as is from the Apache site or did you compile from source
code. I have been also trying to get the very same distribution working
(as an alternative) but I am having problems even getting the server to
start up. I think it has to do with the fact that the local node I am
running it on doesn’t use a fully qualified domain name. That is, in
/etc/hosts there is the following:

node1

I believe that the problem is that the name is not being resolved by the
gethostbyname() function properly, since the error_log for Apache makes
reference to this:

[alert] mod_unique_id: unable to gethostbyname(“node1”)

I suspect that this function is trying to use some name resolution
instead of getting the IP address from the /etc/hosts table. I have
read somewhere that the order Apache uses for name resolution is NIS,
DNS, host table. Would you be able to confirm what this order is and if
it is possible via a command line option to use the hosts table?

Thanks for your help. What you are doing is very much the same as what
I am wanting to do: access my processes via HTML and control/query them
via CGI-BIN.

Rodney Lott

Paul Russell wrote:

Just a note:
We’re also using apache (apache_1.3.9-PCI-qssl-qnx32.tar.gz)
and its working great. We’re using it to both serve HTML and
also to control/query our processes via CGI-BIN.
-Paul

Oops. Yeah, the stderr line was incorrect.

I tried the test you proposed and the HTML string comes out fine. So it
would seem that the problem is with slinger and its interpretation of
fprintf statements.

I am currently looking into Apache as well but I need to use the C-based
CGI so that I can communicate with some of my C processes via a library
call. So, using a C-based CGI is of utmost importance, albeit that it
is more difficult.

Thanks.

Rodney Lott

Jay Hogg wrote:

John Uff wrote in message …

I’m using apache not slinger but one problem is the lack of a header
defining a mime-type, followed by at least one blank line to separate it
from the document… I’m suprised your getting anything, IE would have
choked
on it.
something like:

printf(“Content-type: text/html\n\n”);

which goes before your <html

you’ve got an unmatched

in there too (char *test=“This is a
test.

”; ) which might confuse things

You also have one of your messages going to ‘stderr’ that will go
to oblivion.

A quick & easy test is from the command line:
QUERY_STRING=test ./myecho
… and see if it comes out correctly.

I use slinger & CGI all the time but recently switch to Apache and PHP4
for all web-based development work.

Much simpler then “C” for CGI-type stuff.

Jay