void standard_request_handler(void *cls, struct SPDY_Request * request, uint8_t priority, const char *method, const char *path, const char *version, const char *host, const char *scheme, struct SPDY_NameValue * headers, bool more) { (void)cls; (void)request; (void)priority; (void)host; (void)scheme; (void)headers; (void)method; (void)version; struct SPDY_Response *response=NULL; if(strcmp(CLS,cls)!=0) { killchild(child,"wrong cls"); } if(false != more){ fprintf(stdout,"more has wrong value\n"); exit(5); } response = SPDY_build_response(200,NULL,SPDY_HTTP_VERSION_1_1,NULL,RESPONSE_BODY,strlen(RESPONSE_BODY)); if(NULL==response){ fprintf(stdout,"no response obj\n"); exit(3); } if(SPDY_queue_response(request,response,true,false,NULL,(void*)strdup(path))!=SPDY_YES) { fprintf(stdout,"queue\n"); exit(4); } }
static void standard_request_handler(void *cls, struct SPDY_Request * request, uint8_t priority, const char *method, const char *path, const char *version, const char *host, const char *scheme, struct SPDY_NameValue * headers, bool more) { (void)cls; (void)request; (void)priority; (void)host; (void)scheme; (void)headers; (void)more; char *html; struct SPDY_Response *response=NULL; struct SPDY_NameValue *resp_headers; printf("received request for '%s %s %s'\n", method, path, version); if(strcmp(path,"/spdy-draft.txt")==0) { FILE *fd = fopen(DATA_DIR "spdy-draft.txt","r"); if(NULL == (resp_headers = SPDY_name_value_create())) { fprintf(stdout,"SPDY_name_value_create failed\n"); abort(); } if(SPDY_YES != SPDY_name_value_add(resp_headers,SPDY_HTTP_HEADER_CONTENT_TYPE,"text/plain")) { fprintf(stdout,"SPDY_name_value_add failed\n"); abort(); } response = SPDY_build_response_with_callback(200,NULL, SPDY_HTTP_VERSION_1_1,resp_headers,&response_callback,fd,SPDY_MAX_SUPPORTED_FRAME_SIZE); SPDY_name_value_destroy(resp_headers); } else { if(strcmp(path,"/close")==0) { asprintf(&html,"<html>" "<body><b>Closing now!</body></html>"); run = 0; } else { asprintf(&html,"<html>" "<body><a href=\"/spdy-draft.txt\">/spdy-draft.txt</a><br></body></html>"); } response = SPDY_build_response(200,NULL,SPDY_HTTP_VERSION_1_1,NULL,html,strlen(html)); free(html); } if(NULL==response) { fprintf(stdout,"no response obj\n"); abort(); } void *clspath = strdup(path); if(SPDY_queue_response(request,response,true,false,&response_done_callback,clspath)!=SPDY_YES) { fprintf(stdout,"queue\n"); abort(); } }
void standard_request_handler(void *cls, struct SPDY_Request * request, uint8_t priority, const char *method, const char *path, const char *version, const char *host, const char *scheme, struct SPDY_NameValue * headers, bool more) { (void)cls; (void)request; (void)priority; (void)host; (void)scheme; (void)headers; (void)method; (void)version; (void)more; struct SPDY_Response *response=NULL; struct SPDY_NameValue *resp_headers; char *fname; char *fsize; char *mime=NULL; char *date=NULL; ssize_t filesize = -666; FILE *fd = NULL; int ret = -666; //printf("received request for '%s %s %s'\n", method, path, version); if(strlen(path) > 1 && NULL == strstr(path, "..") && '/' == path[0]) { asprintf(&fname,"%s%s",basedir,path); if(0 == access(fname, R_OK)) { if(NULL == (fd = fopen(fname,"r")) || 0 != (ret = fseek(fd, 0L, SEEK_END)) || -1 == (filesize = ftell(fd)) || 0 != (ret = fseek(fd, 0L, SEEK_SET))) { printf("Error on opening %s\n%p %i %zd\n",fname, fd, ret, filesize); response = SPDY_build_response(SPDY_HTTP_INTERNAL_SERVER_ERROR,NULL,SPDY_HTTP_VERSION_1_1,NULL,NULL,0); } else { if(NULL == (resp_headers = SPDY_name_value_create())) { printf("SPDY_name_value_create failed\n"); abort(); } date = Rfc1123_DateTimeNow(); if(NULL == date || SPDY_YES != SPDY_name_value_add(resp_headers,SPDY_HTTP_HEADER_DATE,date)) { printf("SPDY_name_value_add or Rfc1123_DateTimeNow failed\n"); abort(); } free(date); if(-1 == asprintf(&fsize, "%zd", filesize) || SPDY_YES != SPDY_name_value_add(resp_headers,SPDY_HTTP_HEADER_CONTENT_LENGTH,fsize)) { printf("SPDY_name_value_add or asprintf failed\n"); abort(); } free(fsize); GET_MIME_TYPE(path,mime); if(SPDY_YES != SPDY_name_value_add(resp_headers,SPDY_HTTP_HEADER_CONTENT_TYPE,mime)) { printf("SPDY_name_value_add failed\n"); abort(); } free(mime); if(SPDY_YES != SPDY_name_value_add(resp_headers,SPDY_HTTP_HEADER_SERVER,"libmicrospdy/fileserver")) { printf("SPDY_name_value_add failed\n"); abort(); } response = SPDY_build_response_with_callback(200,NULL, SPDY_HTTP_VERSION_1_1,resp_headers,&response_callback,fd,SPDY_MAX_SUPPORTED_FRAME_SIZE); SPDY_name_value_destroy(resp_headers); } if(NULL==response){ printf("no response obj\n"); abort(); } if(SPDY_queue_response(request,response,true,false,&response_done_callback,fd)!=SPDY_YES) { printf("queue\n"); abort(); } free(fname); return; } free(fname); } if(strcmp(path,"/close")==0) { run = 0; } response = SPDY_build_response(SPDY_HTTP_NOT_FOUND,NULL,SPDY_HTTP_VERSION_1_1,NULL,NULL,0); printf("Not found %s\n",path); if(NULL==response){ printf("no response obj\n"); abort(); } if(SPDY_queue_response(request,response,true,false,&response_done_callback,NULL)!=SPDY_YES) { printf("queue\n"); abort(); } }