logging.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /* Feel free to use this example code in any way
  2. you see fit (Public Domain) */
  3. #include <sys/types.h>
  4. #ifndef _WIN32
  5. #include <sys/select.h>
  6. #include <sys/socket.h>
  7. #else
  8. #include <winsock2.h>
  9. #endif
  10. #include <microhttpd.h>
  11. #include <stdio.h>
  12. #define PORT 8888
  13. static enum MHD_Result
  14. print_out_key (void *cls, enum MHD_ValueKind kind, const char *key,
  15. const char *value)
  16. {
  17. (void) cls; /* Unused. Silent compiler warning. */
  18. (void) kind; /* Unused. Silent compiler warning. */
  19. printf ("%s: %s\n", key, value);
  20. return MHD_YES;
  21. }
  22. static enum MHD_Result
  23. answer_to_connection (void *cls, struct MHD_Connection *connection,
  24. const char *url, const char *method,
  25. const char *version, const char *upload_data,
  26. size_t *upload_data_size, void **req_cls)
  27. {
  28. (void) cls; /* Unused. Silent compiler warning. */
  29. (void) version; /* Unused. Silent compiler warning. */
  30. (void) upload_data; /* Unused. Silent compiler warning. */
  31. (void) upload_data_size; /* Unused. Silent compiler warning. */
  32. (void) req_cls; /* Unused. Silent compiler warning. */
  33. printf ("New %s request for %s using version %s\n", method, url, version);
  34. MHD_get_connection_values (connection, MHD_HEADER_KIND, print_out_key,
  35. NULL);
  36. return MHD_NO;
  37. }
  38. int
  39. main (void)
  40. {
  41. struct MHD_Daemon *daemon;
  42. daemon = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD, PORT, NULL, NULL,
  43. &answer_to_connection, NULL, MHD_OPTION_END);
  44. if (NULL == daemon)
  45. return 1;
  46. (void) getchar ();
  47. MHD_stop_daemon (daemon);
  48. return 0;
  49. }