void Serve_Resource(ReqInfo reqinfo, int conn) { int resource = 0; /* Check whether resource exists, whether we have permission to access it, and update status code accordingly. */ if (reqinfo.status == 200) if ((resource = Check_Resource(&reqinfo)) < 0) { if (errno == EACCES) reqinfo.status = 401; else reqinfo.status = 404; } /* Output HTTP response headers if we have a full request */ if (reqinfo.type == FULL) Output_HTTP_Headers(conn, &reqinfo); /* Service the HTTP request */ // if ( Return_Resource(conn, resource, &reqinfo) ) // Error_Quit("Something wrong returning resource."); // } // else // Return_Error_Msg(conn, &reqinfo); if (resource > 0) if (close(resource) < 0) Error_Quit("Error closing resource."); FreeReqInfo(&reqinfo); }
void *Service_Request(void *f) { int conn = (intptr_t)f; FILE *resource; struct ReqInfo reqinfo; InitReqInfo(&reqinfo); /* Get HTTP request */ if ( Get_Request(conn, &reqinfo) < 0 ) printf("error"); //return -1; if (reqinfo.method == POST){ handlePost(conn,&reqinfo); } if (strlen(reqinfo.resource) == 1) sprintf(reqinfo.resource,"/index.html"); /* Check whether resource exists, whether we have permission to access it, and update status code accordingly. */ if ( reqinfo.status == 200 ){ if ( (resource = Check_Resource(&reqinfo)) < 0 ) { if ( errno == EACCES ) reqinfo.status = 401; else reqinfo.status = 404; } } /* Output HTTP response headers if we have a full request */ if ( reqinfo.type == FULL ) Output_HTTP_Headers(conn, &reqinfo); /* Service the HTTP request */ if ( reqinfo.status == 200 ) { if ( Return_Resource(conn, resource, &reqinfo) ) syslog(LOG_NOTICE,"Something wrong returning resource."); } else Return_Error_Msg(conn, &reqinfo); if ( resource > 0 ) if ( fclose(resource) < 0 ) syslog(LOG_NOTICE,"Error closing resource."); FreeReqInfo(&reqinfo); close(conn); }
// WORKS FINE, but not when debugging int Service_Request(int conn) { struct ReqInfo reqinfo; InitReqInfo(&reqinfo); /* Get HTTP request */ if (Get_Request(conn, &reqinfo) < 0) return -1; else if(reqinfo.type == FULL) Output_HTTP_Headers(conn, &reqinfo); // file system: // Serve_Resource(ReqInfo reqinfo,int conn) CleanURL(reqinfo.resource); initSharedMemory(); // for each forked process! if(strlen(reqinfo.resource)>1000)return 0; char* q = substr(reqinfo.resource, 1, -1); // :::::::::::::::::::::::::::::: int ok=handle(q,conn); // <<<<<<< CENTRAL CALL // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FreeReqInfo(&reqinfo); return ok; }