jsoninfo: determine the mime type via the functions table
authorFerry Huberts <ferry.huberts@pelagic.nl>
Wed, 2 Dec 2015 10:29:40 +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/jsoninfo/src/jsoninfo_printers.c
lib/jsoninfo/src/jsoninfo_printers.h
lib/jsoninfo/src/olsrd_jsoninfo.c

index 145e66f..f0bd1cc 100644 (file)
@@ -55,6 +55,7 @@
 #include "egressTypes.h"
 #include "olsrd_jsoninfo_helpers.h"
 #include "olsrd_plugin.h"
+#include "../../info/info_types.h"
 
 extern char uuidfile[FILENAME_MAX];
 
@@ -69,6 +70,10 @@ void plugin_init(const char *plugin_name) {
   read_uuid_from_file(plugin_name, uuidfile);
 }
 
+const char * determine_mime_type(unsigned int send_what) {
+  return (send_what & SIW_ALL) ? "application/json; charset=utf-8" : "text/plain; charset=utf-8";
+}
+
 void ipc_print_neighbors(struct autobuf *abuf, bool list_2hop) {
   struct ipaddr_str buf1;
   struct neighbor_entry *neigh;
index 43052a9..cf83a97 100644 (file)
@@ -51,6 +51,8 @@ extern struct timeval start_time;
 
 void plugin_init(const char * plugin_name);
 
+const char * determine_mime_type(unsigned int send_what);
+
 void ipc_print_neighbors(struct autobuf *abuf, bool list_2hop);
 void ipc_print_links(struct autobuf *abuf);
 void ipc_print_routes(struct autobuf *abuf);
index 1236228..9c9a1e1 100644 (file)
@@ -87,6 +87,7 @@ static struct timer_entry *writetimer_entry;
 
 static printer_functions_t printer_functions = { //
     //
+        .determine_mime_type = &determine_mime_type, //
         .neighbors = &ipc_print_neighbors, //
         .links = &ipc_print_links, //
         .routes = &ipc_print_routes, //
@@ -392,7 +393,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 = (send_what & SIW_ALL) ? "application/json; charset=utf-8" : "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;