logging.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 int
  14. print_out_key (void *cls, enum MHD_ValueKind kind, const char *key,
  15. const char *value)
  16. {
  17. printf ("%s: %s\n", key, value);
  18. return MHD_YES;
  19. }
  20. static int
  21. answer_to_connection (void *cls, struct MHD_Connection *connection,
  22. const char *url, const char *method,
  23. const char *version, const char *upload_data,
  24. size_t *upload_data_size, void **con_cls)
  25. {
  26. printf ("New %s request for %s using version %s\n", method, url, version);
  27. MHD_get_connection_values (connection, MHD_HEADER_KIND, print_out_key,
  28. NULL);
  29. return MHD_NO;
  30. }
  31. int
  32. main ()
  33. {
  34. struct MHD_Daemon *daemon;
  35. daemon = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY, PORT, NULL, NULL,
  36. &answer_to_connection, NULL, MHD_OPTION_END);
  37. if (NULL == daemon)
  38. return 1;
  39. (void) getchar ();
  40. MHD_stop_daemon (daemon);
  41. return 0;
  42. }