void dav_request_execute(DavServer *server, DavRequest *request) { dav_response_clear(server, request); /* check url */ if (0 == request->url_path->len) { dav_response_error(server, request, 400); return; } if ('/' != request->url_path->str[0]) { /* only the OPTIONS method allows an url not starting with "/", and it must be "*", nothing else */ if ('*' != request->url_path->str[0] || 1 != request->url_path->len || DAV_OPTIONS != request->method) { dav_response_error(server, request, 400); return; } } switch (request->method) { case DAV_OPTIONS: request_options(server, request); break; case DAV_PROPFIND: request_propfind(server, request); break; case DAV_PROPPATCH: request_proppatch(server, request); break; case DAV_MKCOL: request_mkcol(server, request); break; case DAV_GET: case DAV_HEAD: request_get_and_head(server, request); break; case DAV_DELETE: request_del(server, request); break; case DAV_PUT: request_put(server, request); break; case DAV_COPY: case DAV_MOVE: case DAV_LOCK: case DAV_UNLOCK: break; } if (0 == request->response_status) { dav_response_error(server, request, 500); } if (NULL != request->response_text) { g_string_append_printf(dav_response_get_header(server, request), "Content-Length: %" G_GOFFSET_FORMAT "\r\n", (goffset) request->response_text->len); } else if (NULL == request->response_filename && -1 == request->response_fd) { if (DAV_HEAD != request->method || 200 != request->response_status) { g_string_append_len(dav_response_get_header(server, request), CONST_STR_LEN("Content-Length: 0\r\n")); } } }
int answer_to_connection (void *cls, struct MHD_Connection *connection,const char *url, const char *method,const char *version, const char *upload_data, size_t *upload_data_size, void **con_cls) { struct MHD_Response *response; puts(page); if (strcmp(method,"GET") == 0) { printf("%s New %s request for %s using version %s",__func__, method, url, version); request_get(cls, connection, url, method, version, upload_data, upload_data_size, con_cls); return 1; } else if (strcmp(method,"PUT") == 0) { printf("%s New %s request for %s using version %s",__func__, method, url, version); request_put( cls, connection, url, method, version, upload_data, upload_data_size,con_cls); return 1; } else if (strcmp(method,"DELETE") == 0) { printf("%s New %s request for %s using version %s",__func__, method, url, version); request_delete( cls, connection, url, method, version, upload_data, upload_data_size,con_cls); } else if (strcmp(method,"HEAD") == 0) { printf("%s New %s request for %s using version %s",__func__, method, url, version); request_head( cls, connection, url, method, version, upload_data, upload_data_size,con_cls); return 1; } else if (strcmp(method,"POST") == 0) { printf("%s New %s request for %s using version %s",__func__, method, url, version); request_post(cls, connection, url, method, version, upload_data, upload_data_size, con_cls); return 1; } else printf("%s ERROR %s request for %s using version %s",__func__, method, url, version); return 0; }
static int request_send(struct mwChannel *chan, struct mwStorageReq *req) { struct mwPutBuffer *b; struct mwOpaque o = { 0, 0 }; int ret; b = mwPutBuffer_new(); request_put(b, req); mwPutBuffer_finalize(&o, b); ret = mwChannel_send(chan, req->action, &o); mwOpaque_clear(&o); if(! ret) { if(req->action == action_save) { req->action = action_saved; } else if(req->action == action_load) { req->action = action_loaded; } } return ret; }
int main (int argc, char* argv[]) { menu_option current_option; // Menu action char arg[BUFSIZE]; // Menu action argument char *host; // Hostname to connect to short portnum; // Port of the server int sock, // Socket to host conn; // Connection to the host // Get server hostname if (argc == 3) { host = argv[1]; // Extract the hostname portnum = atoi(argv[2]); // Extract the port number } else { fprintf(stderr, "Usage: %s <host> <port>\n", argv[0]); exit(1); } // Initialize the connection printf("Connecting..."); fflush(stdout); if (setup(host, portnum, &sock, &conn) < 0) { fprintf(stderr, "\nCould not connect to %s:%d\n", host, portnum); exit(1); } printf("\rConnected to %s:%d\n", host, portnum); // Request the desired action from the user for (;;) { current_option = handle_input(host, arg, sizeof(arg)); switch (current_option) { // Close the socket before quitting case QUIT: close(sock); exit(1); break; case LISTFILES: if (request_file_list(sock) < 0) fatal("[!!] Request File List failed."); break; case GETFILE: if (request_file(sock, arg) < 0) fatal("[!!] Request Get File failed."); break; case PUTFILE: if (request_put(sock, arg) < 0) fatal("[!!] Request Put File failed."); break; case RENAMEFILE: if (request_rename(sock, arg) < 0) fatal("[!! Request Rename failed."); break; default: fprintf(stderr, "[!!] Unknown command\n"); break; } } return 0; }
/* int print_out_key (void *cls, enum MHD_ValueKind kind, const char *key, const char *value) { SimpleLog_Write(SL_DEBUG, __func__, "%s: %s", key, value); return MHD_YES; } */ int answer_to_connection (void *cls, struct MHD_Connection *connection, const char *url, const char *method, const char *version, const char *upload_data, size_t *upload_data_size, void **con_cls) { /*the info of this thread, so we need there to be defined in function, not be defined as global variables. */ // json_object * Response_page = json_object_new_object(); //json_object * Response_heads = json_object_new_object(); //const char *page = "hello, cloud store!"; struct MHD_Response *response; //puts(page); //int ret; char pathname[128]; char pathname_mnt[128]; get_sonstr(url,pathname); memset(pathname_mnt,0,sizeof(pathname_mnt)); strcat(strcat(pathname_mnt,"/mnt/supercache/"),pathname); //printf("pathname %s pathname_mnt %s \n",pathname,pathname_mnt); if (strcmp(method,"GET") == 0) { printf("haha\n"); //SimpleLog_Write(SL_DEBUG, __func__, "New %s request for %s using version %s", method, url, version); printf("%s New %s request for %s using version %s",__func__, method, url, version); /******************add by Jin*********************************/ /*time_t arrive_time; time(&arrive_time); IO_Type io_type=READ; queue_in_wait(pathname_mnt,io_type,arrive_time); int already_queue_out=0;//the mark of read out early Meta_Data * meta_data=(Meta_Data*)malloc(sizeof(Meta_Data)); if(md_get(pathname_mnt,meta_data)==0) { u32 head_next=((*meta_data).ioq.head+1)%IO_Q_LEN; //if one read comes after one read ,queue out early if((*meta_data).ioq.io_q_node[head_next].io_type==READ) { read_queue_out(pathname_mnt,io_type,arrive_time); already_queue_out=1; } }*/ /*******************************************************/ request_get(cls, connection, url, method, version, upload_data, upload_data_size, con_cls); /* if(already_queue_out==0) { read_queue_out(pathname_mnt,io_type,arrive_time); }*/ return 1; } else if (strcmp(method,"PUT") == 0) { //SimpleLog_Write(SL_DEBUG, __func__, "New %s request for %s using version %s", method, url, version); printf("%s New %s request for %s using version %s",__func__, method, url, version); /******************************************************/ /*time_t arrive_time; time(&arrive_time); IO_Type io_type=WRITE; queue_in_wait(pathname_mnt,io_type,arrive_time);*/ /********************************************************/ request_put( cls, connection, url, method, version, upload_data, upload_data_size,con_cls); /*********************************************************/ /*u64 offset=0;char *data="never mind!";size_t size1=11; write_queue_out(pathname_mnt,io_type,arrive_time,offset,data,size1);//should change it*/ /*********************************************************/ return 1; } else if (strcmp(method,"DELETE") == 0) { //SimpleLog_Write(SL_DEBUG, __func__, "New %s request for %s using version %s", method, url, version); printf("%s New %s request for %s using version %s",__func__, method, url, version); /************************************************/ /* time_t arrive_time; time(&arrive_time); IO_Type io_type=REMOVE; queue_in_wait(pathname_mnt,io_type,arrive_time);*/ /************************************************/ request_delete( cls, connection, url, method, version, upload_data, upload_data_size,con_cls); //remove_queue_out(pathname_mnt,io_type); } else if (strcmp(method,"HEAD") == 0) { //SimpleLog_Write(SL_DEBUG, __func__, "New %s request for %s using version %s", method, url, version); printf("%s New %s request for %s using version %s",__func__, method, url, version); request_head( cls, connection, url, method, version, upload_data, upload_data_size,con_cls); return 1; } else if (strcmp(method,"POST") == 0) { //printf("()()()()\n"); //SimpleLog_Write(SL_DEBUG, __func__, "New %s request for %s using version %s", method, url, version); //printf("%s New %s request for %s using version %s\n",__func__, method, url, version); //printf("up_load_size:%u %s\n",upload_data_size,upload_data); /******************************************************/ /*time_t arrive_time; time(&arrive_time); IO_Type io_type=WRITE; queue_in_wait(pathname_mnt,io_type,arrive_time);*/ /********************************************************/ request_post(cls, connection, url, method, version, upload_data, upload_data_size, con_cls); /*********************************************************/ /*u64 offset=0;char *data="never mind!";size_t size1=11; write_queue_out(pathname_mnt,io_type,arrive_time,offset,data,size1);//should change it*/ /*********************************************************/ return 1; } else printf("%s ERROR %s request for %s using version %s",__func__, method, url, version); return 0; }