D CGI Hang with fgets

Morgan McDermott morganmcdermott at gmail.com
Sun Nov 26 22:29:58 PST 2006


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;

			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



More information about the Digitalmars-d-learn mailing list