txtinfo: determine the mime type via the functions table
authorFerry Huberts <ferry.huberts@pelagic.nl>
Wed, 2 Dec 2015 10:29:32 +0000 (11:29 +0100)
committerFerry Huberts <ferry.huberts@pelagic.nl>
Wed, 2 Dec 2015 17:41:14 +0000 (18:41 +0100)
Signed-off-by: Ferry Huberts <ferry.huberts@pelagic.nl>
lib/info/info_types.h
lib/txtinfo/src/olsrd_txtinfo.c

index bd5905f..7b51b48 100644 (file)
 /* this data is not normal format but olsrd.conf format */
 #define SIW_OLSRD_CONF 0x2000
 
+typedef const char * (*mime_type)(unsigned int send_what);
 typedef void (*printer_neighbors)(struct autobuf *abuf, bool list_2hop);
 typedef void (*printer_generic)(struct autobuf *abuf);
 
 typedef struct {
+    mime_type determine_mime_type;
     printer_neighbors neighbors;
     printer_generic links;
     printer_generic routes;
index e4070fd..74a9379 100644 (file)
@@ -86,6 +86,7 @@ static struct timer_entry *writetimer_entry;
 
 static printer_functions_t printer_functions = { //
     //
+        .determine_mime_type = NULL, //
         .neighbors = &ipc_print_neighbors, //
         .links = &ipc_print_links, //
         .routes = &ipc_print_routes, //
@@ -395,7 +396,7 @@ static void info_write_data(void *foo __attribute__ ((unused))) {
 static void send_info(unsigned int send_what, int the_socket) {
   struct autobuf abuf;
 
-  const char *content_type = "text/plain; charset=utf-8";
+  const char *content_type = (printer_functions.determine_mime_type) ? (*printer_functions.determine_mime_type)(send_what) : "text/plain; charset=utf-8";
   int contentLengthPlaceholderStart = 0;
   int headerLength = 0;