[Olsr-dev] [PATCH v1 031/115] jsoninfo: determine the mime type via the functions table

Ferry Huberts (spam-protected)
Wed Dec 2 21:28:04 CET 2015


From: Ferry Huberts <(spam-protected)>

Signed-off-by: Ferry Huberts <(spam-protected)>
---
 lib/jsoninfo/src/jsoninfo_printers.c | 5 +++++
 lib/jsoninfo/src/jsoninfo_printers.h | 2 ++
 lib/jsoninfo/src/olsrd_jsoninfo.c    | 3 ++-
 3 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/lib/jsoninfo/src/jsoninfo_printers.c b/lib/jsoninfo/src/jsoninfo_printers.c
index 145e66f..f0bd1cc 100644
--- a/lib/jsoninfo/src/jsoninfo_printers.c
+++ b/lib/jsoninfo/src/jsoninfo_printers.c
@@ -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;
diff --git a/lib/jsoninfo/src/jsoninfo_printers.h b/lib/jsoninfo/src/jsoninfo_printers.h
index 43052a9..cf83a97 100644
--- a/lib/jsoninfo/src/jsoninfo_printers.h
+++ b/lib/jsoninfo/src/jsoninfo_printers.h
@@ -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);
diff --git a/lib/jsoninfo/src/olsrd_jsoninfo.c b/lib/jsoninfo/src/olsrd_jsoninfo.c
index 1236228..9c9a1e1 100644
--- a/lib/jsoninfo/src/olsrd_jsoninfo.c
+++ b/lib/jsoninfo/src/olsrd_jsoninfo.c
@@ -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;
 
-- 
2.5.0




More information about the Olsr-dev mailing list