Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int MHD_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) {
- // Initializes parser/camera/settings...
- static Parser parser;
- // The first time only the headers are valid, do not respond in the first round
- static int dummy;
- if (*con_cls != &dummy) {
- *con_cls = &dummy;
- return MHD_YES;
- }
- // Parse URL to get the resource
- int resource = parser.getRequestedResource(url);
- // Check wether if it's a GET or a POST method
- if(strcmp(method, MHD_HTTP_METHOD_GET) == 0) {
- parser.processGetRequest(resource);
- }
- else {
- parser.processPutRequest(upload_data, *upload_data_size);
- }
- // Building HTTP response (headers+data)
- MHD_Response* httpResponse = parser.getResponse();
- int ret = MHD_queue_response (connection, MHD_HTTP_OK, httpResponse);
- if (ret != MHD_YES) {
- Logger::get().error("Error queuing message");
- }
- MHD_destroy_response (httpResponse);
- // Clear context pointer
- *con_cls = NULL;
- return ret;
- }
- static 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)
- {
- ...
- if (0 == strcmp (method, "POST"))
- {
- struct connection_info_struct *con_info = *con_cls;
- if (*upload_data_size != 0)
- {
- MHD_post_process (con_info->postprocessor, upload_data,
- *upload_data_size);
- *upload_data_size = 0;
- return MHD_YES;
- }
- else if (NULL != con_info->answerstring)
- return send_page (connection, con_info->answerstring);
- }
- ...
Add Comment
Please, Sign In to add comment