logging.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #include <sys/types.h>
  2. #include <sys/select.h>
  3. #include <sys/socket.h>
  4. #include <microhttpd.h>
  5. #define PORT 8888
  6. static int
  7. print_out_key (void *cls, enum MHD_ValueKind kind, const char *key,
  8. const char *value)
  9. {
  10. printf ("%s: %s\n", key, value);
  11. return MHD_YES;
  12. }
  13. static int
  14. answer_to_connection (void *cls, struct MHD_Connection *connection,
  15. const char *url, const char *method,
  16. const char *version, const char *upload_data,
  17. size_t *upload_data_size, void **con_cls)
  18. {
  19. printf ("New %s request for %s using version %s\n", method, url, version);
  20. MHD_get_connection_values (connection, MHD_HEADER_KIND, print_out_key,
  21. NULL);
  22. return MHD_NO;
  23. }
  24. int
  25. main ()
  26. {
  27. struct MHD_Daemon *daemon;
  28. daemon = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY, PORT, NULL, NULL,
  29. &answer_to_connection, NULL, MHD_OPTION_END);
  30. if (NULL == daemon)
  31. return 1;
  32. getchar ();
  33. MHD_stop_daemon (daemon);
  34. return 0;
  35. }