repo: shell-daemons action: blob revision: path_from: read_cgi_headers.c revision_from: refs/heads/master: path_to: revision_to:
blob of:
/ read_cgi_headers.c
refs/heads/master:/read_cgi_headers.c
#include//#include //toupper #include //strcpy, cat, etc #include //getenv #include //execv // this program is to read in headers like the type in: // urn:ietf:rfc:3864 // from stdin and then store them in the stack until we // find the Status: header. // then we print it reformated, and then print the rest of the headers. int until_status() { char line[8192]; int r=0; fgets(line,sizeof(line)-1,stdin); if(strchr(line,'\n')) *strchr(line,'\n')=0; if(strchr(line,'\r')) *strchr(line,'\r')=0; if(!strlen(line)) { // we got to the last line... uh.. what now? printf("%s %s\r\n",getenv("SERVER_PROTOCOL"),"200 OK"); // need to default to HTTP/1.1 200 OK return 1; } if(!strncasecmp(line,"Status: ",8)) { printf("%s %s\r\n",getenv("SERVER_PROTOCOL"),line+8); return 0; } r=until_status(); printf("%s\r\n",line); return r; } int main(int argc,char *argv[]) { setlinebuf(stdout); char line[8192];//lol. how long should this be? if(!until_status()) { while(fgets(line,sizeof(line)-1,stdin)) { if(strchr(line,'\n')) *strchr(line,'\n')=0; if(strchr(line,'\r')) *strchr(line,'\r')=0; if(!strlen(line)) { break;//got a blank line. abort. } printf("%s\r\n",line); } } printf("\r\n"); //printf("what the fucK?"); if(argc > 1) { execv(argv[1],argv+1);//run argv perror("execv"); } printf("usage: read_cgi_headers /external/program arg1 arg2\n"); return 1;//if we got here it was an error of some kind. }