"$Id: spacetrace.c,v 1.48 2003/06/18 02:13:42 alecf%flett.org Exp $",
"$Id: spacetrace.c,v 1.49 2004/01/13 16:35:45 alecf%flett.org Exp $",
handleClient(void *inArg){    PRFileDesc *aFD = NULL;    aFD = (PRFileDesc *) inArg;    if (NULL != aFD) {        PRStatus closeRes = PR_SUCCESS;        char aBuffer[2048];        PRInt32 readRes = 0;        readRes = PR_Read(aFD, aBuffer, sizeof(aBuffer));        if (0 <= readRes) {            const char *sanityCheck = "GET /";            if (0 == strncmp(sanityCheck, aBuffer, 5)) {                char *eourl = NULL;                char *start = &aBuffer[5];                char *getData = NULL;                int realFun = 0;                const char *crlf = "\015\012";                char *eoline = NULL;                FormData *fdGet = NULL;                /*                 ** Truncate the line if possible.                 ** Only want first one.                 */                eoline = strstr(aBuffer, crlf);                if (NULL != eoline) {                    *eoline = '\0';                }                /*                 ** Find the whitespace.                 ** That is either end of line or the " HTTP/1.x" suffix.                 ** We do not care.                 */                for (eourl = start; 0 == isspace(*eourl) && '\0' != *eourl;                     eourl++) {                    /*                     ** No body.                     */                }                /*                 ** Cap it off.                 ** Convert empty '/' to index.html.                 */                *eourl = '\0';                if ('\0' == *start) {                    strcpy(start, "index.html");                }                /*                 ** Have we got any GET form data?                 */                getData = strchr(start, '?');                if (NULL != getData) {                    /*                     ** Whack it off.                     */                    *getData = '\0';                    getData++;                }                /*                 **  Convert get data into a more useful format.                 */                fdGet = FormData_Create(getData);                /*                 ** This is totally a hack, but oh well....                 **                 ** Send that the request was OK, regardless.                 **                 ** If we have any get data, then it is a set of options                 **      we attempt to apply.                 **                 ** Other code will tell the user they were wrong or if                 **      there was an error.                 ** If the filename contains a ".png", then send the image                 **      mime type, otherwise, say it is text/html.                  */                PR_fprintf(aFD, "HTTP/1.1 200 OK%s", crlf);                PR_fprintf(aFD, "Server: %s%s",                           "$Id: spacetrace.c,v 1.48 2003/06/18 02:13:42 alecf%flett.org Exp $",                           crlf);                PR_fprintf(aFD, "Content-type: ");                if (NULL != strstr(start, ".png")) {                    PR_fprintf(aFD, "image/png");                }                else if (NULL != strstr(start, ".jpg")) {                    PR_fprintf(aFD, "image/jpeg");                }                else if (NULL != strstr(start, ".txt")) {                    PR_fprintf(aFD, "text/plain");                }                else if (NULL != strstr(start, ".css")) {                    PR_fprintf(aFD, "text/css");                }                else {                    PR_fprintf(aFD, "text/html");                }                PR_fprintf(aFD, crlf);                /*                 ** One more to seperate headers from content.                 */                PR_fprintf(aFD, crlf);                /*                 ** Ready for the real fun.                 */                realFun = handleRequest(globals.mTMR, aFD, start, fdGet);                if (0 != realFun) {                    REPORT_ERROR(__LINE__, handleRequest);                }                /*                 **  Free off get data if around.                 */                FormData_Destroy(fdGet);                fdGet = NULL;            }            else {                REPORT_ERROR(__LINE__, handleClient);            }        }        else {            REPORT_ERROR(__LINE__, lineReader);        }        /*         ** Done with the connection.         */        closeRes = PR_Close(aFD);        if (PR_SUCCESS != closeRes) {            REPORT_ERROR(__LINE__, PR_Close);        }    }    else {        REPORT_ERROR(__LINE__, handleClient);    }}