libmicrohttpd2

HTTP server C library (MHD 2.x, alpha)
Log | Files | Refs | README | LICENSE

logging.c (1697B)


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