Guest User

Untitled

a guest
Jun 20th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. int MHD_answer_to_connection (void* cls, struct MHD_Connection* connection,
  2. const char* url,
  3. const char* method, const char* version,
  4. const char* upload_data,
  5. size_t* upload_data_size, void** con_cls) {
  6.  
  7.  
  8. // Initializes parser/camera/settings...
  9. static Parser parser;
  10.  
  11. // The first time only the headers are valid, do not respond in the first round
  12. static int dummy;
  13. if (*con_cls != &dummy) {
  14. *con_cls = &dummy;
  15. return MHD_YES;
  16. }
  17.  
  18. // Parse URL to get the resource
  19. int resource = parser.getRequestedResource(url);
  20.  
  21. // Check wether if it's a GET or a POST method
  22. if(strcmp(method, MHD_HTTP_METHOD_GET) == 0) {
  23. parser.processGetRequest(resource);
  24. }
  25. else {
  26. parser.processPutRequest(upload_data, *upload_data_size);
  27. }
  28.  
  29. // Building HTTP response (headers+data)
  30. MHD_Response* httpResponse = parser.getResponse();
  31.  
  32. int ret = MHD_queue_response (connection, MHD_HTTP_OK, httpResponse);
  33.  
  34. if (ret != MHD_YES) {
  35. Logger::get().error("Error queuing message");
  36. }
  37.  
  38. MHD_destroy_response (httpResponse);
  39. // Clear context pointer
  40. *con_cls = NULL;
  41.  
  42. return ret;
  43. }
  44.  
  45. static int answer_to_connection (void *cls, struct MHD_Connection *connection,
  46. const char *url, const char *method,
  47. const char *version, const char *upload_data,
  48. size_t *upload_data_size, void **con_cls)
  49. {
  50.  
  51.  
  52. ...
  53.  
  54. if (0 == strcmp (method, "POST"))
  55. {
  56. struct connection_info_struct *con_info = *con_cls;
  57.  
  58. if (*upload_data_size != 0)
  59. {
  60. MHD_post_process (con_info->postprocessor, upload_data,
  61. *upload_data_size);
  62. *upload_data_size = 0;
  63.  
  64. return MHD_YES;
  65. }
  66. else if (NULL != con_info->answerstring)
  67. return send_page (connection, con_info->answerstring);
  68. }
  69. ...
Add Comment
Please, Sign In to add comment