D CGI Hang with fgets
Carlos Santander
csantander619 at gmail.com
Mon Nov 27 05:54:51 PST 2006
Morgan McDermott escribió:
> Hi there!
> I'm trying to make a D CGI script, and one of the essential things it
> should do is to get POST data. My attempt below in D hangs at fgets()...
> I've made it output to a file so that it may be tested on a webserver
> (where I've been testing it). When the script has POST data to get, it
> performs exactly the same as it does in the console (hangs at fgets()).
>
> I've been using a guide to C and CGI as my reference here:
> http://www.cs.tut.fi/~jkorpela/forms/cgic.html
>
> <code>
> //Imports
> import std.stdio; //writefln()
> import std.string; //toString()
> import std.date : getUTCtime; // time + benchmarking
> import std.conv; //toInt()
> import std.stream; //testing only
>
> alias char[] string; //ease of use
>
> void writeNewLine(string line, string filename) {
> std.file.append(filename, line~"\n");
> }
>
> extern (C)
> {
> char* getPOSTData(uint len = 2048){
> char *prawData;
>
Have you tried initializing prawData?
prawData = new char [len]; // or similar
> printf("hang?");
> writeNewLine("Hanging point entered \n", "baz.txt");
>
> prawData = fgets(prawData, len+1, stdin);
>
> writeNewLine("Hanging point exited \n", "baz.txt");
> printf("Not hanging.. =-)");
>
> return prawData;
> }
> }
>
> extern (C) char* getenv(char*);
>
> void main() {
> string introduction = "New test at " ~ toString(getUTCtime());
> writeNewLine(introduction, "baz.txt");
>
> char *pdataLength= getenv("CONTENT_LENGTH");
> string scontentLength = toString(pdataLength);
> //Ensure no conversion error when no post data is passed
> if(scontentLength == ""){
> scontentLength = "0";
> }
>
> uint contentLength = toInt(scontentLength);
>
> char *ppostData = getPOSTData();
> writefln("Post Data: %s", toString(ppostData));
> writeNewLine("Post Data: " ~ toString(ppostData), "baz.txt");
> }
> </code>
>
> Any ideas?
>
> Thank you very much for your time,
> ~Morgan McDermott
--
Carlos Santander Bernal
More information about the Digitalmars-d-learn
mailing list