jsoninfo: formatting
authorFerry Huberts <ferry.huberts@pelagic.nl>
Mon, 20 Apr 2015 10:26:13 +0000 (12:26 +0200)
committerFerry Huberts <ferry.huberts@pelagic.nl>
Mon, 20 Apr 2015 12:38:42 +0000 (14:38 +0200)
Signed-off-by: Ferry Huberts <ferry.huberts@pelagic.nl>
lib/jsoninfo/src/olsrd_jsoninfo.c
lib/jsoninfo/src/olsrd_jsoninfo.h
lib/jsoninfo/src/olsrd_plugin.c

index afbc4c0..a7f172b 100644 (file)
@@ -48,7 +48,6 @@
  * Dynamic linked library for the olsr.org olsr daemon
  */
 
-
 #include <sys/types.h>
 #include <sys/socket.h>
 #ifndef _WIN32
@@ -130,8 +129,7 @@ static void ipc_print_interfaces(struct autobuf *);
 static void ipc_print_plugins(struct autobuf *);
 static void ipc_print_olsrd_conf(struct autobuf *abuf);
 
-static size_t build_http_header(const char *status, const char *mime,
-  uint32_t msgsize, char *buf, uint32_t bufsize);
+static size_t build_http_header(const char *status, const char *mime, uint32_t msgsize, char *buf, uint32_t bufsize);
 
 /*
  * this is the size of the buffer used for build_http_header
@@ -180,34 +178,27 @@ char uuidfile[FILENAME_MAX];
 static struct timeval start_time;
 static struct timer_entry *writetimer_entry;
 
-
 /* JSON support functions */
 
 /* JSON does not allow commas dangling at the end of arrays, so we need to
  * count which entry number we're at in order to make sure we don't tack a
  * dangling comma on at the end */
-static int entrynumber[5] = {0,0,0,0,0};
+static int entrynumber[5] = { 0, 0, 0, 0, 0 };
 static int currentjsondepth = 0;
 
-static void
-abuf_json_open_object(struct autobuf *abuf, const char* header)
-{
+static void abuf_json_open_object(struct autobuf *abuf, const char* header) {
   abuf_appendf(abuf, "\"%s\": {", header);
   entrynumber[currentjsondepth]++;
   currentjsondepth++;
   entrynumber[currentjsondepth] = 0;
 }
 
-static void
-abuf_json_close_object(struct autobuf *abuf)
-{
+static void abuf_json_close_object(struct autobuf *abuf) {
   abuf_appendf(abuf, "\t}\n");
   currentjsondepth--;
 }
 
-static void
-abuf_json_open_array(struct autobuf *abuf, const char* header)
-{
+static void abuf_json_open_array(struct autobuf *abuf, const char* header) {
   if (entrynumber[currentjsondepth])
     abuf_appendf(abuf, ",\n\t");
   abuf_appendf(abuf, "\"%s\": [\n", header);
@@ -216,17 +207,13 @@ abuf_json_open_array(struct autobuf *abuf, const char* header)
   entrynumber[currentjsondepth] = 0;
 }
 
-static void
-abuf_json_close_array(struct autobuf *abuf)
-{
+static void abuf_json_close_array(struct autobuf *abuf) {
   abuf_appendf(abuf, "]\n");
   entrynumber[currentjsondepth] = 0;
   currentjsondepth--;
 }
 
-static void
-abuf_json_open_array_entry(struct autobuf *abuf)
-{
+static void abuf_json_open_array_entry(struct autobuf *abuf) {
   if (entrynumber[currentjsondepth])
     abuf_appendf(abuf, ",\n{");
   else
@@ -236,17 +223,13 @@ abuf_json_open_array_entry(struct autobuf *abuf)
   entrynumber[currentjsondepth] = 0;
 }
 
-static void
-abuf_json_close_array_entry(struct autobuf *abuf)
-{
+static void abuf_json_close_array_entry(struct autobuf *abuf) {
   abuf_appendf(abuf, "}");
   entrynumber[currentjsondepth] = 0;
   currentjsondepth--;
 }
 
-static void
-abuf_json_insert_comma(struct autobuf *abuf)
-{
+static void abuf_json_insert_comma(struct autobuf *abuf) {
   if (entrynumber[currentjsondepth])
     abuf_appendf(abuf, ",\n");
   else
@@ -254,57 +237,44 @@ abuf_json_insert_comma(struct autobuf *abuf)
   entrynumber[currentjsondepth]++;
 }
 
-static void
-abuf_json_boolean(struct autobuf *abuf, const char* key, int value)
-{
+static void abuf_json_boolean(struct autobuf *abuf, const char* key, int value) {
   abuf_json_insert_comma(abuf);
   abuf_appendf(abuf, "\t\"%s\": %s", key, value ? "true" : "false");
 }
 
-static void
-abuf_json_string(struct autobuf *abuf, const char* key, const char* value)
-{
+static void abuf_json_string(struct autobuf *abuf, const char* key, const char* value) {
   abuf_json_insert_comma(abuf);
   abuf_appendf(abuf, "\t\"%s\": \"%s\"", key, value);
 }
 
-static void
-abuf_json_int(struct autobuf *abuf, const char* key, long value)
-{
+static void abuf_json_int(struct autobuf *abuf, const char* key, long value) {
   abuf_json_insert_comma(abuf);
   abuf_appendf(abuf, "\t\"%s\": %li", key, value);
 }
 
-static void
-abuf_json_float(struct autobuf *abuf, const char* key, float value)
-{
+static void abuf_json_float(struct autobuf *abuf, const char* key, float value) {
   abuf_json_insert_comma(abuf);
-  abuf_appendf(abuf, "\t\"%s\": %.03f", key, (double)value);
+  abuf_appendf(abuf, "\t\"%s\": %.03f", key, (double) value);
 }
 
-
-
 /* Linux specific functions for getting system info */
 
 #ifdef __linux__
-static int get_string_from_file(const char* filename, char* buf, int len)
-{
+static int get_string_from_file(const char* filename, char* buf, int len) {
   int bytes = -1;
   int fd = open(filename, O_RDONLY);
   if (fd > -1) {
     bytes = read(fd, buf, len);
     if (bytes < len)
-      buf[bytes-1] = '\0'; // remove trailing \n
+      buf[bytes - 1] = '\0'; // remove trailing \n
     else
-      buf[len-1] = '\0';
+      buf[len - 1] = '\0';
     close(fd);
   }
   return bytes;
 }
 
-static int
-abuf_json_sysdata(struct autobuf *abuf, const char* key, const char* syspath)
-{
+static int abuf_json_sysdata(struct autobuf *abuf, const char* key, const char* syspath) {
   int ret = -1;
   char buf[256];
   *buf = 0;
@@ -314,10 +284,7 @@ abuf_json_sysdata(struct autobuf *abuf, const char* key, const char* syspath)
   return ret;
 }
 
-static void
-abuf_json_sys_class_net(struct autobuf *abuf, const char* key,
-                        const char* ifname, const char* datapoint)
-{
+static void abuf_json_sys_class_net(struct autobuf *abuf, const char* key, const char* ifname, const char* datapoint) {
   char filename[256];
   snprintf(filename, 255, "/sys/class/net/%s/%s", ifname, datapoint);
   abuf_json_sysdata(abuf, key, filename);
@@ -325,17 +292,13 @@ abuf_json_sys_class_net(struct autobuf *abuf, const char* key,
 
 #endif /* __linux__ */
 
-
-
 /**
  *Do initialization here
  *
  *This function is called by the my_init
  *function in uolsrd_plugin.c
  */
-int
-olsrd_plugin_init(void)
-{
+int olsrd_plugin_init(void) {
   /* Initial IPC value */
   ipc_socket = -1;
 
@@ -353,16 +316,12 @@ olsrd_plugin_init(void)
 /**
  * destructor - called at unload
  */
-void
-olsr_plugin_exit(void)
-{
+void olsr_plugin_exit(void) {
   if (ipc_socket != -1)
     close(ipc_socket);
 }
 
-static int
-plugin_ipc_init(void)
-{
+static int plugin_ipc_init(void) {
   union olsr_sockaddr sst;
   uint32_t yes = 1;
   socklen_t addrlen;
@@ -374,7 +333,7 @@ plugin_ipc_init(void)
 #endif /* NODEBUG */
     return 0;
   } else {
-    if (setsockopt(ipc_socket, SOL_SOCKET, SO_REUSEADDR, (char *)&yes, sizeof(yes)) < 0) {
+    if (setsockopt(ipc_socket, SOL_SOCKET, SO_REUSEADDR, (char *) &yes, sizeof(yes)) < 0) {
 #ifndef NODEBUG
       olsr_printf(1, "(JSONINFO) setsockopt()=%s\n", strerror(errno));
 #endif /* NODEBUG */
@@ -388,7 +347,7 @@ plugin_ipc_init(void)
 #endif /* (defined __FreeBSD__ || defined __FreeBSD_kernel__) && defined SO_NOSIGPIPE */
 #if defined linux && defined IPV6_V6ONLY
     if (jsoninfo_ipv6_only && olsr_cnf->ip_version == AF_INET6) {
-      if (setsockopt(ipc_socket, IPPROTO_IPV6, IPV6_V6ONLY, (char *)&yes, sizeof(yes)) < 0) {
+      if (setsockopt(ipc_socket, IPPROTO_IPV6, IPV6_V6ONLY, (char *) &yes, sizeof(yes)) < 0) {
         perror("IPV6_V6ONLY failed");
         return 0;
       }
@@ -442,9 +401,7 @@ plugin_ipc_init(void)
   return 1;
 }
 
-static int
-read_uuid_from_file(const char *file)
-{
+static int read_uuid_from_file(const char *file) {
   FILE *f;
   char* end;
   int r = 0;
@@ -454,9 +411,8 @@ read_uuid_from_file(const char *file)
 
   f = fopen(file, "r");
   olsr_printf(1, "(JSONINFO) Reading UUID from '%s'\n", file);
-  if (f == NULL ) {
-    olsr_printf(1, "(JSONINFO) Could not open '%s': %s\n",
-                file, strerror(errno));
+  if (f == NULL) {
+    olsr_printf(1, "(JSONINFO) Could not open '%s': %s\n", file, strerror(errno));
     return -1;
   }
   chars = fread(uuid, 1, UUIDLEN, f);
@@ -465,12 +421,11 @@ read_uuid_from_file(const char *file)
 
     /* we only use the first line of the file */
     end = strchr(uuid, '\n');
-    if(end)
+    if (end)
       *end = 0;
     r = 0;
   } else {
-    olsr_printf(1, "(JSONINFO) Could not read UUID from '%s': %s\n",
-                file, strerror(errno));
+    olsr_printf(1, "(JSONINFO) Could not read UUID from '%s': %s\n", file, strerror(errno));
     r = -1;
   }
 
@@ -478,9 +433,7 @@ read_uuid_from_file(const char *file)
   return r;
 }
 
-static void
-ipc_action(int fd, void *data __attribute__ ((unused)), unsigned int flags __attribute__ ((unused)))
-{
+static void ipc_action(int fd, void *data __attribute__ ((unused)), unsigned int flags __attribute__ ((unused))) {
   union olsr_sockaddr pin;
 
   char addr[INET6_ADDRSTRLEN];
@@ -506,11 +459,11 @@ ipc_action(int fd, void *data __attribute__ ((unused)), unsigned int flags __att
 #ifdef JSONINFO_ALLOW_LOCALHOST
       if (pin.in4.sin_addr.s_addr != INADDR_LOOPBACK) {
 #endif /* JSONINFO_ALLOW_LOCALHOST */
-        olsr_printf(1, "(JSONINFO) From host(%s) not allowed!\n", addr);
-        close(ipc_connection);
-        return;
+      olsr_printf(1, "(JSONINFO) From host(%s) not allowed!\n", addr);
+      close(ipc_connection);
+      return;
 #ifdef JSONINFO_ALLOW_LOCALHOST
-      }
+    }
 #endif /* JSONINFO_ALLOW_LOCALHOST */
     }
   } else {
@@ -530,16 +483,17 @@ ipc_action(int fd, void *data __attribute__ ((unused)), unsigned int flags __att
 
   /* purge read buffer to prevent blocking on linux */
   FD_ZERO(&rfds);
-  FD_SET((unsigned int)ipc_connection, &rfds);  /* Win32 needs the cast here */
+  FD_SET((unsigned int )ipc_connection, &rfds); /* Win32 needs the cast here */
   if (0 <= select(ipc_connection + 1, &rfds, NULL, NULL, &tv)) {
     char requ[1024];
-    ssize_t s = recv(ipc_connection, (void *)&requ, sizeof(requ)-1, 0);   /* Win32 needs the cast here */
+    ssize_t s = recv(ipc_connection, (void *) &requ, sizeof(requ) - 1, 0); /* Win32 needs the cast here */
 
-    if (s == sizeof(requ)-1) {
+    if (s == sizeof(requ) - 1) {
       /* input was too much long, just skip the rest */
       char dummy[1024];
 
-      while (recv(ipc_connection, (void *)&dummy, sizeof(dummy), 0) == sizeof(dummy));
+      while (recv(ipc_connection, (void *) &dummy, sizeof(dummy), 0) == sizeof(dummy))
+        ;
     }
     if (0 < s) {
       requ[s] = 0;
@@ -550,30 +504,41 @@ ipc_action(int fd, void *data __attribute__ ((unused)), unsigned int flags __att
         send_what = SIW_ALL;
       else {
         // these are the two overarching categories
-        if (0 != strstr(requ, "/runtime")) send_what |= SIW_RUNTIME_ALL;
-        if (0 != strstr(requ, "/startup")) send_what |= SIW_STARTUP_ALL;
+        if (0 != strstr(requ, "/runtime"))
+          send_what |= SIW_RUNTIME_ALL;
+        if (0 != strstr(requ, "/startup"))
+          send_what |= SIW_STARTUP_ALL;
         // these are the individual sections
-        if (0 != strstr(requ, "/neighbors")) send_what |= SIW_NEIGHBORS;
-        if (0 != strstr(requ, "/links")) send_what |= SIW_LINKS;
-        if (0 != strstr(requ, "/routes")) send_what |= SIW_ROUTES;
-        if (0 != strstr(requ, "/hna")) send_what |= SIW_HNA;
-        if (0 != strstr(requ, "/mid")) send_what |= SIW_MID;
-        if (0 != strstr(requ, "/topology")) send_what |= SIW_TOPOLOGY;
-        if (0 != strstr(requ, "/gateways")) send_what |= SIW_GATEWAYS;
-        if (0 != strstr(requ, "/interfaces")) send_what |= SIW_INTERFACES;
-        if (0 != strstr(requ, "/config")) send_what |= SIW_CONFIG;
-        if (0 != strstr(requ, "/plugins")) send_what |= SIW_PLUGINS;
+        if (0 != strstr(requ, "/neighbors"))
+          send_what |= SIW_NEIGHBORS;
+        if (0 != strstr(requ, "/links"))
+          send_what |= SIW_LINKS;
+        if (0 != strstr(requ, "/routes"))
+          send_what |= SIW_ROUTES;
+        if (0 != strstr(requ, "/hna"))
+          send_what |= SIW_HNA;
+        if (0 != strstr(requ, "/mid"))
+          send_what |= SIW_MID;
+        if (0 != strstr(requ, "/topology"))
+          send_what |= SIW_TOPOLOGY;
+        if (0 != strstr(requ, "/gateways"))
+          send_what |= SIW_GATEWAYS;
+        if (0 != strstr(requ, "/interfaces"))
+          send_what |= SIW_INTERFACES;
+        if (0 != strstr(requ, "/config"))
+          send_what |= SIW_CONFIG;
+        if (0 != strstr(requ, "/plugins"))
+          send_what |= SIW_PLUGINS;
       }
     }
-    if ( send_what == 0 ) send_what = SIW_ALL;
+    if (send_what == 0)
+      send_what = SIW_ALL;
   }
 
   send_info(send_what, ipc_connection);
 }
 
-static void
-ipc_print_neighbors(struct autobuf *abuf)
-{
+static void ipc_print_neighbors(struct autobuf *abuf) {
   struct ipaddr_str buf1;
   struct neighbor_entry *neigh;
   struct neighbor_2_list_entry *list_2;
@@ -582,172 +547,149 @@ ipc_print_neighbors(struct autobuf *abuf)
   abuf_json_open_array(abuf, "neighbors");
 
   /* Neighbors */
-  OLSR_FOR_ALL_NBR_ENTRIES(neigh) {
-    abuf_json_open_array_entry(abuf);
-    abuf_json_string(abuf, "ipv4Address",
-                     olsr_ip_to_string(&buf1, &neigh->neighbor_main_addr));
-    abuf_json_boolean(abuf, "symmetric", (neigh->status == SYM));
-    abuf_json_boolean(abuf, "multiPointRelay", neigh->is_mpr);
-    abuf_json_boolean(abuf, "multiPointRelaySelector",
-                      olsr_lookup_mprs_set(&neigh->neighbor_main_addr) != NULL);
-    abuf_json_int(abuf, "willingness", neigh->willingness);
-    abuf_appendf(abuf, ",\n");
-
-    thop_cnt = 0;
-    if (neigh->neighbor_2_list.next) {
-      abuf_appendf(abuf, "\t\"twoHopNeighbors\": [");
-      for (list_2 = neigh->neighbor_2_list.next; list_2 != &neigh->neighbor_2_list; list_2 = list_2->next) {
-        if (thop_cnt)
-          abuf_appendf(abuf, ", ");
-        abuf_appendf(abuf,
-                     "\"%s\"",
-                     olsr_ip_to_string(&buf1, &list_2->neighbor_2->neighbor_2_addr));
-        thop_cnt++;
-      }
-    }
-    abuf_appendf(abuf, "]");
-    abuf_json_int(abuf, "twoHopNeighborCount", thop_cnt);
-    abuf_json_close_array_entry(abuf);
-  }
-  OLSR_FOR_ALL_NBR_ENTRIES_END(neigh);
+  OLSR_FOR_ALL_NBR_ENTRIES(neigh)
+      {
+        abuf_json_open_array_entry(abuf);
+        abuf_json_string(abuf, "ipv4Address", olsr_ip_to_string(&buf1, &neigh->neighbor_main_addr));
+        abuf_json_boolean(abuf, "symmetric", (neigh->status == SYM));
+        abuf_json_boolean(abuf, "multiPointRelay", neigh->is_mpr);
+        abuf_json_boolean(abuf, "multiPointRelaySelector", olsr_lookup_mprs_set(&neigh->neighbor_main_addr) != NULL);
+        abuf_json_int(abuf, "willingness", neigh->willingness);
+        abuf_appendf(abuf, ",\n");
+
+        thop_cnt = 0;
+        if (neigh->neighbor_2_list.next) {
+          abuf_appendf(abuf, "\t\"twoHopNeighbors\": [");
+          for (list_2 = neigh->neighbor_2_list.next; list_2 != &neigh->neighbor_2_list; list_2 = list_2->next) {
+            if (thop_cnt)
+              abuf_appendf(abuf, ", ");
+            abuf_appendf(abuf, "\"%s\"", olsr_ip_to_string(&buf1, &list_2->neighbor_2->neighbor_2_addr));
+            thop_cnt++;
+          }
+        }
+        abuf_appendf(abuf, "]");
+        abuf_json_int(abuf, "twoHopNeighborCount", thop_cnt);
+        abuf_json_close_array_entry(abuf);
+      }OLSR_FOR_ALL_NBR_ENTRIES_END(neigh);
   abuf_json_close_array(abuf);
 }
 
-static void
-ipc_print_links(struct autobuf *abuf)
-{
+static void ipc_print_links(struct autobuf *abuf) {
   struct ipaddr_str buf1, buf2;
   struct lqtextbuffer lqbuffer1;
 
   struct link_entry *my_link = NULL;
 
   abuf_json_open_array(abuf, "links");
-  OLSR_FOR_ALL_LINK_ENTRIES(my_link) {
-    const char* lqs;
-    int diff = (unsigned int)(my_link->link_timer->timer_clock - now_times);
+  OLSR_FOR_ALL_LINK_ENTRIES(my_link)
+      {
+        const char* lqs;
+        int diff = (unsigned int) (my_link->link_timer->timer_clock - now_times);
 
-    abuf_json_open_array_entry(abuf);
-    abuf_json_string(abuf, "localIP",
-                     olsr_ip_to_string(&buf1, &my_link->local_iface_addr));
-    abuf_json_string(abuf, "remoteIP",
-                     olsr_ip_to_string(&buf2, &my_link->neighbor_iface_addr));
-    abuf_json_int(abuf, "validityTime", diff);
-    lqs = get_link_entry_text(my_link, '\t', &lqbuffer1);
-    abuf_json_float(abuf, "linkQuality", atof(lqs));
-    abuf_json_float(abuf, "neighborLinkQuality", atof(strrchr(lqs, '\t')));
-    if (my_link->linkcost >= LINK_COST_BROKEN)
-      abuf_json_int(abuf, "linkCost", LINK_COST_BROKEN);
-    else
-      abuf_json_int(abuf, "linkCost", my_link->linkcost);
-    abuf_json_close_array_entry(abuf);
-  }
-  OLSR_FOR_ALL_LINK_ENTRIES_END(my_link);
+        abuf_json_open_array_entry(abuf);
+        abuf_json_string(abuf, "localIP", olsr_ip_to_string(&buf1, &my_link->local_iface_addr));
+        abuf_json_string(abuf, "remoteIP", olsr_ip_to_string(&buf2, &my_link->neighbor_iface_addr));
+        abuf_json_int(abuf, "validityTime", diff);
+        lqs = get_link_entry_text(my_link, '\t', &lqbuffer1);
+        abuf_json_float(abuf, "linkQuality", atof(lqs));
+        abuf_json_float(abuf, "neighborLinkQuality", atof(strrchr(lqs, '\t')));
+        if (my_link->linkcost >= LINK_COST_BROKEN)
+          abuf_json_int(abuf, "linkCost", LINK_COST_BROKEN);
+        else
+          abuf_json_int(abuf, "linkCost", my_link->linkcost);
+        abuf_json_close_array_entry(abuf);
+      }OLSR_FOR_ALL_LINK_ENTRIES_END(my_link);
   abuf_json_close_array(abuf);
 }
 
-static void
-ipc_print_routes(struct autobuf *abuf)
-{
+static void ipc_print_routes(struct autobuf *abuf) {
   struct ipaddr_str buf1, buf2;
   struct rt_entry *rt;
 
   abuf_json_open_array(abuf, "routes");
 
   /* Walk the route table */
-  OLSR_FOR_ALL_RT_ENTRIES(rt) {
-    abuf_json_open_array_entry(abuf);
-    abuf_json_string(abuf, "destination",
-                     olsr_ip_to_string(&buf1, &rt->rt_dst.prefix));
-    abuf_json_int(abuf, "genmask", rt->rt_dst.prefix_len);
-    abuf_json_string(abuf, "gateway",
-                     olsr_ip_to_string(&buf2, &rt->rt_best->rtp_nexthop.gateway));
-    abuf_json_int(abuf, "metric", rt->rt_best->rtp_metric.hops);
-    if (rt->rt_best->rtp_metric.cost >= ROUTE_COST_BROKEN)
-      abuf_json_int(abuf, "rtpMetricCost", ROUTE_COST_BROKEN);
-    else
-      abuf_json_int(abuf, "rtpMetricCost", rt->rt_best->rtp_metric.cost);
-    abuf_json_string(abuf, "networkInterface",
-                     if_ifwithindex_name(rt->rt_best->rtp_nexthop.iif_index));
-    abuf_json_close_array_entry(abuf);
-  }
-  OLSR_FOR_ALL_RT_ENTRIES_END(rt);
+  OLSR_FOR_ALL_RT_ENTRIES(rt)
+      {
+        abuf_json_open_array_entry(abuf);
+        abuf_json_string(abuf, "destination", olsr_ip_to_string(&buf1, &rt->rt_dst.prefix));
+        abuf_json_int(abuf, "genmask", rt->rt_dst.prefix_len);
+        abuf_json_string(abuf, "gateway", olsr_ip_to_string(&buf2, &rt->rt_best->rtp_nexthop.gateway));
+        abuf_json_int(abuf, "metric", rt->rt_best->rtp_metric.hops);
+        if (rt->rt_best->rtp_metric.cost >= ROUTE_COST_BROKEN)
+          abuf_json_int(abuf, "rtpMetricCost", ROUTE_COST_BROKEN);
+        else
+          abuf_json_int(abuf, "rtpMetricCost", rt->rt_best->rtp_metric.cost);
+        abuf_json_string(abuf, "networkInterface", if_ifwithindex_name(rt->rt_best->rtp_nexthop.iif_index));
+        abuf_json_close_array_entry(abuf);
+      }OLSR_FOR_ALL_RT_ENTRIES_END(rt);
 
   abuf_json_close_array(abuf);
 }
 
-static void
-ipc_print_topology(struct autobuf *abuf)
-{
+static void ipc_print_topology(struct autobuf *abuf) {
   struct tc_entry *tc;
 
   abuf_json_open_array(abuf, "topology");
 
   /* Topology */
-  OLSR_FOR_ALL_TC_ENTRIES(tc) {
-    struct tc_edge_entry *tc_edge;
-    OLSR_FOR_ALL_TC_EDGE_ENTRIES(tc, tc_edge) {
-      if (tc_edge->edge_inv) {
-        struct ipaddr_str dstbuf, addrbuf;
-        struct lqtextbuffer lqbuffer1;
-        uint32_t vt = tc->validity_timer != NULL ? (tc->validity_timer->timer_clock - now_times) : 0;
-        int diff = (int)(vt);
-        const char* lqs;
-        abuf_json_open_array_entry(abuf);
-        abuf_json_string(abuf, "destinationIP",
-                         olsr_ip_to_string(&dstbuf, &tc_edge->T_dest_addr));
-        abuf_json_string(abuf, "lastHopIP",
-                         olsr_ip_to_string(&addrbuf, &tc->addr));
-        lqs = get_tc_edge_entry_text(tc_edge, '\t', &lqbuffer1);
-        abuf_json_float(abuf, "linkQuality", atof(lqs));
-        abuf_json_float(abuf, "neighborLinkQuality", atof(strrchr(lqs, '\t')));
-        if (tc_edge->cost >= LINK_COST_BROKEN)
-          abuf_json_int(abuf, "tcEdgeCost", LINK_COST_BROKEN);
-        else
-          abuf_json_int(abuf, "tcEdgeCost", tc_edge->cost);
-        abuf_json_int(abuf, "validityTime", diff);
-        abuf_json_close_array_entry(abuf);
-      }
-    }
-    OLSR_FOR_ALL_TC_EDGE_ENTRIES_END(tc, tc_edge);
-  }
-  OLSR_FOR_ALL_TC_ENTRIES_END(tc);
+  OLSR_FOR_ALL_TC_ENTRIES(tc)
+      {
+        struct tc_edge_entry *tc_edge;
+        OLSR_FOR_ALL_TC_EDGE_ENTRIES(tc, tc_edge)
+            {
+              if (tc_edge->edge_inv) {
+                struct ipaddr_str dstbuf, addrbuf;
+                struct lqtextbuffer lqbuffer1;
+                uint32_t vt = tc->validity_timer != NULL ? (tc->validity_timer->timer_clock - now_times) : 0;
+                int diff = (int) (vt);
+                const char* lqs;
+                abuf_json_open_array_entry(abuf);
+                abuf_json_string(abuf, "destinationIP", olsr_ip_to_string(&dstbuf, &tc_edge->T_dest_addr));
+                abuf_json_string(abuf, "lastHopIP", olsr_ip_to_string(&addrbuf, &tc->addr));
+                lqs = get_tc_edge_entry_text(tc_edge, '\t', &lqbuffer1);
+                abuf_json_float(abuf, "linkQuality", atof(lqs));
+                abuf_json_float(abuf, "neighborLinkQuality", atof(strrchr(lqs, '\t')));
+                if (tc_edge->cost >= LINK_COST_BROKEN)
+                  abuf_json_int(abuf, "tcEdgeCost", LINK_COST_BROKEN);
+                else
+                  abuf_json_int(abuf, "tcEdgeCost", tc_edge->cost);
+                abuf_json_int(abuf, "validityTime", diff);
+                abuf_json_close_array_entry(abuf);
+              }
+            }OLSR_FOR_ALL_TC_EDGE_ENTRIES_END(tc, tc_edge);
+      }OLSR_FOR_ALL_TC_ENTRIES_END(tc);
 
   abuf_json_close_array(abuf);
 }
 
-static void
-ipc_print_hna(struct autobuf *abuf)
-{
+static void ipc_print_hna(struct autobuf *abuf) {
   struct hna_entry *tmp_hna;
   struct hna_net *tmp_net;
   struct ipaddr_str buf, mainaddrbuf;
 
   abuf_json_open_array(abuf, "hna");
 
-  OLSR_FOR_ALL_HNA_ENTRIES(tmp_hna) {
-
-    /* Check all networks */
-    for (tmp_net = tmp_hna->networks.next; tmp_net != &tmp_hna->networks; tmp_net = tmp_net->next) {
-      uint32_t vt = tmp_net->hna_net_timer != NULL ? (tmp_net->hna_net_timer->timer_clock - now_times) : 0;
-      int diff = (int)(vt);
-      abuf_json_open_array_entry(abuf);
-      abuf_json_string(abuf, "destination",
-                       olsr_ip_to_string(&buf, &tmp_net->hna_prefix.prefix)),
-      abuf_json_int(abuf, "genmask", tmp_net->hna_prefix.prefix_len);
-      abuf_json_string(abuf, "gateway",
-                       olsr_ip_to_string(&mainaddrbuf, &tmp_hna->A_gateway_addr));
-      abuf_json_int(abuf, "validityTime", diff);
-      abuf_json_close_array_entry(abuf);
-    }
-  }
-  OLSR_FOR_ALL_HNA_ENTRIES_END(tmp_hna);
+  OLSR_FOR_ALL_HNA_ENTRIES(tmp_hna)
+        {
+
+          /* Check all networks */
+          for (tmp_net = tmp_hna->networks.next; tmp_net != &tmp_hna->networks; tmp_net = tmp_net->next) {
+            uint32_t vt = tmp_net->hna_net_timer != NULL ? (tmp_net->hna_net_timer->timer_clock - now_times) : 0;
+            int diff = (int) (vt);
+            abuf_json_open_array_entry(abuf);
+            abuf_json_string(abuf, "destination", olsr_ip_to_string(&buf, &tmp_net->hna_prefix.prefix)), abuf_json_int(abuf, "genmask",
+                tmp_net->hna_prefix.prefix_len);
+            abuf_json_string(abuf, "gateway", olsr_ip_to_string(&mainaddrbuf, &tmp_hna->A_gateway_addr));
+            abuf_json_int(abuf, "validityTime", diff);
+            abuf_json_close_array_entry(abuf);
+          }
+        }OLSR_FOR_ALL_HNA_ENTRIES_END(tmp_hna);
 
   abuf_json_close_array(abuf);
 }
 
-static void
-ipc_print_mid(struct autobuf *abuf)
-{
+static void ipc_print_mid(struct autobuf *abuf) {
   int idx;
   struct mid_entry *entry;
   struct mid_address *alias;
@@ -761,18 +703,16 @@ ipc_print_mid(struct autobuf *abuf)
     while (entry != &mid_set[idx]) {
       struct ipaddr_str buf, buf2;
       abuf_json_open_array_entry(abuf);
-      abuf_json_string(abuf, "ipAddress",
-                       olsr_ip_to_string(&buf, &entry->main_addr));
+      abuf_json_string(abuf, "ipAddress", olsr_ip_to_string(&buf, &entry->main_addr));
 
       abuf_json_open_array(abuf, "aliases");
       alias = entry->aliases;
       while (alias) {
         uint32_t vt = alias->vtime - now_times;
-        int diff = (int)(vt);
+        int diff = (int) (vt);
 
         abuf_json_open_array_entry(abuf);
-        abuf_json_string(abuf, "ipAddress",
-                         olsr_ip_to_string(&buf2, &alias->alias));
+        abuf_json_string(abuf, "ipAddress", olsr_ip_to_string(&buf2, &alias->alias));
         abuf_json_int(abuf, "validityTime", diff);
         abuf_json_close_array_entry(abuf);
 
@@ -786,9 +726,7 @@ ipc_print_mid(struct autobuf *abuf)
   abuf_json_close_array(abuf); // mid
 }
 
-static void
-ipc_print_gateways(struct autobuf *abuf)
-{
+static void ipc_print_gateways(struct autobuf *abuf) {
 #ifndef __linux__
   abuf_json_string(abuf, "error", "Gateway mode is only supported in Linux");
 #else /* __linux__ */
@@ -797,66 +735,60 @@ ipc_print_gateways(struct autobuf *abuf)
   struct gateway_entry *gw;
 
   abuf_json_open_array(abuf, "gateways");
-  OLSR_FOR_ALL_GATEWAY_ENTRIES(gw) {
-    const char *v4 = "", *v6 = "";
-    bool autoV4 = false, autoV6 = false;
-    const char *ipType = "";
-    struct tc_entry *tc;
-
-    if ((tc = olsr_lookup_tc_entry(&gw->originator)) == NULL) {
-      continue;
-    }
+  OLSR_FOR_ALL_GATEWAY_ENTRIES(gw)
+      {
+        const char *v4 = "", *v6 = "";
+        bool autoV4 = false, autoV6 = false;
+        const char *ipType = "";
+        struct tc_entry *tc;
+
+        if ((tc = olsr_lookup_tc_entry(&gw->originator)) == NULL) {
+          continue;
+        }
 
-    if (gw == olsr_get_inet_gateway(false)) {
-      v4 = "s";
-    } else if (gw->ipv4 && (olsr_cnf->ip_version == AF_INET || olsr_cnf->use_niit)
-               && (olsr_cnf->smart_gw_allow_nat || !gw->ipv4nat)) {
-      v4 = "u";
-    }
+        if (gw == olsr_get_inet_gateway(false)) {
+          v4 = "s";
+        } else if (gw->ipv4 && (olsr_cnf->ip_version == AF_INET || olsr_cnf->use_niit) && (olsr_cnf->smart_gw_allow_nat || !gw->ipv4nat)) {
+          v4 = "u";
+        }
 
-    if (gw == olsr_get_inet_gateway(true)) {
-      v6 = "s";
-    } else if (gw->ipv6 && olsr_cnf->ip_version == AF_INET6) {
-      v6 = "u";
-    }
+        if (gw == olsr_get_inet_gateway(true)) {
+          v6 = "s";
+        } else if (gw->ipv6 && olsr_cnf->ip_version == AF_INET6) {
+          v6 = "u";
+        }
 
-    abuf_json_open_array_entry(abuf);
-    if (gw->ipv4) {
-      ipType = "ipv4";
-      abuf_json_string(abuf, "ipv4Status", v4);
-    } else if (gw->ipv6) {
-      ipType = "ipv6";
-      abuf_json_string(abuf, "ipv6Status", v6);
-    }
-    abuf_json_string(abuf, "ipType", ipType);
-    abuf_json_boolean(abuf, "ipv4", gw->ipv4);
-    abuf_json_boolean(abuf, "ipv4Nat", gw->ipv4nat);
-    abuf_json_boolean(abuf, "ipv6", gw->ipv6);
-    abuf_json_boolean(abuf, "autoIpv4", autoV4);
-    abuf_json_boolean(abuf, "autoIpv6", autoV6);
-    abuf_json_string(abuf, "ipAddress",
-                     olsr_ip_to_string(&buf, &gw->originator));
-    if (tc->path_cost >= ROUTE_COST_BROKEN)
-      abuf_json_int(abuf, "tcPathCost", ROUTE_COST_BROKEN);
-    else
-      abuf_json_int(abuf, "tcPathCost", tc->path_cost);
-    abuf_json_int(abuf, "hopCount", tc->hops);
-    abuf_json_int(abuf, "uplinkSpeed", gw->uplink);
-    abuf_json_int(abuf, "downlinkSpeed", gw->downlink);
-    if(gw->external_prefix.prefix_len == 0)
-      abuf_json_string(abuf, "externalPrefix",
-                       olsr_ip_prefix_to_string(&gw->external_prefix));
-    abuf_json_close_array_entry(abuf);
-  }
-  OLSR_FOR_ALL_GATEWAY_ENTRIES_END(gw)
+        abuf_json_open_array_entry(abuf);
+        if (gw->ipv4) {
+          ipType = "ipv4";
+          abuf_json_string(abuf, "ipv4Status", v4);
+        } else if (gw->ipv6) {
+          ipType = "ipv6";
+          abuf_json_string(abuf, "ipv6Status", v6);
+        }
+        abuf_json_string(abuf, "ipType", ipType);
+        abuf_json_boolean(abuf, "ipv4", gw->ipv4);
+        abuf_json_boolean(abuf, "ipv4Nat", gw->ipv4nat);
+        abuf_json_boolean(abuf, "ipv6", gw->ipv6);
+        abuf_json_boolean(abuf, "autoIpv4", autoV4);
+        abuf_json_boolean(abuf, "autoIpv6", autoV6);
+        abuf_json_string(abuf, "ipAddress", olsr_ip_to_string(&buf, &gw->originator));
+        if (tc->path_cost >= ROUTE_COST_BROKEN)
+          abuf_json_int(abuf, "tcPathCost", ROUTE_COST_BROKEN);
+        else
+          abuf_json_int(abuf, "tcPathCost", tc->path_cost);
+        abuf_json_int(abuf, "hopCount", tc->hops);
+        abuf_json_int(abuf, "uplinkSpeed", gw->uplink);
+        abuf_json_int(abuf, "downlinkSpeed", gw->downlink);
+        if (gw->external_prefix.prefix_len == 0)
+          abuf_json_string(abuf, "externalPrefix", olsr_ip_prefix_to_string(&gw->external_prefix));
+        abuf_json_close_array_entry(abuf);
+      }OLSR_FOR_ALL_GATEWAY_ENTRIES_END(gw)
   abuf_json_close_array(abuf);
 #endif /* __linux__ */
 }
 
-
-static void
-ipc_print_plugins(struct autobuf *abuf)
-{
+static void ipc_print_plugins(struct autobuf *abuf) {
   struct plugin_entry *pentry;
   struct plugin_param *pparam;
   abuf_json_open_array(abuf, "plugins");
@@ -886,15 +818,12 @@ ipc_print_plugins(struct autobuf *abuf)
   abuf_json_close_array(abuf);
 }
 
-
-static void
-ipc_print_config(struct autobuf *abuf)
-{
+static void ipc_print_config(struct autobuf *abuf) {
   struct ip_prefix_list *hna;
   struct ipaddr_str buf, mainaddrbuf;
   struct ip_prefix_list *ipcn;
   struct olsr_lq_mult *mult;
-  char ipv6_buf[INET6_ADDRSTRLEN];                  /* buffer for IPv6 inet_htop */
+  char ipv6_buf[INET6_ADDRSTRLEN]; /* buffer for IPv6 inet_htop */
 
   abuf_json_open_object(abuf, "config");
 
@@ -921,69 +850,52 @@ ipc_print_config(struct autobuf *abuf)
 
   abuf_json_string(abuf, "fibMetrics", FIB_METRIC_TXT[olsr_cnf->fib_metric]);
 
-  abuf_json_string(abuf, "defaultIpv6Multicast",
-                   inet_ntop(AF_INET6, &olsr_cnf->interface_defaults->ipv6_multicast.v6,
-                             ipv6_buf, sizeof(ipv6_buf)));
+  abuf_json_string(abuf, "defaultIpv6Multicast", inet_ntop(AF_INET6, &olsr_cnf->interface_defaults->ipv6_multicast.v6, ipv6_buf, sizeof(ipv6_buf)));
   if (olsr_cnf->interface_defaults->ipv4_multicast.v4.s_addr)
-    abuf_json_string(abuf, "defaultIpv4Broadcast",
-                     inet_ntoa(olsr_cnf->interface_defaults->ipv4_multicast.v4));
+    abuf_json_string(abuf, "defaultIpv4Broadcast", inet_ntoa(olsr_cnf->interface_defaults->ipv4_multicast.v4));
   else
     abuf_json_string(abuf, "defaultIpv4Broadcast", "auto");
 
-  if (olsr_cnf->interface_defaults->mode==IF_MODE_ETHER)
+  if (olsr_cnf->interface_defaults->mode == IF_MODE_ETHER)
     abuf_json_string(abuf, "defaultInterfaceMode", "ether");
   else
     abuf_json_string(abuf, "defaultInterfaceMode", "mesh");
 
-  abuf_json_float(abuf, "defaultHelloEmissionInterval",
-                  olsr_cnf->interface_defaults->hello_params.emission_interval);
-  abuf_json_float(abuf, "defaultHelloValidityTime",
-                  olsr_cnf->interface_defaults->hello_params.validity_time);
-  abuf_json_float(abuf, "defaultTcEmissionInterval",
-                  olsr_cnf->interface_defaults->tc_params.emission_interval);
-  abuf_json_float(abuf, "defaultTcValidityTime",
-                  olsr_cnf->interface_defaults->tc_params.validity_time);
-  abuf_json_float(abuf, "defaultMidEmissionInterval",
-                  olsr_cnf->interface_defaults->mid_params.emission_interval);
-  abuf_json_float(abuf, "defaultMidValidityTime",
-                  olsr_cnf->interface_defaults->mid_params.validity_time);
-  abuf_json_float(abuf, "defaultHnaEmissionInterval",
-                  olsr_cnf->interface_defaults->hna_params.emission_interval);
-  abuf_json_float(abuf, "defaultHnaValidityTime",
-                  olsr_cnf->interface_defaults->hna_params.validity_time);
-  abuf_json_boolean(abuf, "defaultAutoDetectChanges",
-                    olsr_cnf->interface_defaults->autodetect_chg);
+  abuf_json_float(abuf, "defaultHelloEmissionInterval", olsr_cnf->interface_defaults->hello_params.emission_interval);
+  abuf_json_float(abuf, "defaultHelloValidityTime", olsr_cnf->interface_defaults->hello_params.validity_time);
+  abuf_json_float(abuf, "defaultTcEmissionInterval", olsr_cnf->interface_defaults->tc_params.emission_interval);
+  abuf_json_float(abuf, "defaultTcValidityTime", olsr_cnf->interface_defaults->tc_params.validity_time);
+  abuf_json_float(abuf, "defaultMidEmissionInterval", olsr_cnf->interface_defaults->mid_params.emission_interval);
+  abuf_json_float(abuf, "defaultMidValidityTime", olsr_cnf->interface_defaults->mid_params.validity_time);
+  abuf_json_float(abuf, "defaultHnaEmissionInterval", olsr_cnf->interface_defaults->hna_params.emission_interval);
+  abuf_json_float(abuf, "defaultHnaValidityTime", olsr_cnf->interface_defaults->hna_params.validity_time);
+  abuf_json_boolean(abuf, "defaultAutoDetectChanges", olsr_cnf->interface_defaults->autodetect_chg);
 
   abuf_json_open_array(abuf, "defaultLinkQualityMultipliers");
-  for (mult = olsr_cnf->interface_defaults->lq_mult; mult != NULL; mult = mult->next) {
+  for (mult = olsr_cnf->interface_defaults->lq_mult; mult != NULL ; mult = mult->next) {
     abuf_json_open_array_entry(abuf);
-    abuf_json_string(abuf, "route",
-                     inet_ntop(olsr_cnf->ip_version, &mult->addr, ipv6_buf, sizeof(ipv6_buf)));
+    abuf_json_string(abuf, "route", inet_ntop(olsr_cnf->ip_version, &mult->addr, ipv6_buf, sizeof(ipv6_buf)));
     abuf_json_float(abuf, "multiplier", mult->value / 65535.0);
     abuf_json_close_array_entry(abuf);
   }
   abuf_json_close_array(abuf);
 
   abuf_json_open_array(abuf, "hna");
-  for (hna = olsr_cnf->hna_entries; hna != NULL; hna = hna->next) {
+  for (hna = olsr_cnf->hna_entries; hna != NULL ; hna = hna->next) {
     abuf_json_open_array_entry(abuf);
-    abuf_json_string(abuf, "destination",
-                     olsr_ip_to_string(&buf, &hna->net.prefix));
+    abuf_json_string(abuf, "destination", olsr_ip_to_string(&buf, &hna->net.prefix));
     abuf_json_int(abuf, "genmask", hna->net.prefix_len);
-    abuf_json_string(abuf, "gateway",
-                     olsr_ip_to_string(&mainaddrbuf, &olsr_cnf->main_addr));
+    abuf_json_string(abuf, "gateway", olsr_ip_to_string(&mainaddrbuf, &olsr_cnf->main_addr));
     abuf_json_close_array_entry(abuf);
   }
   abuf_json_close_array(abuf);
 
-
   abuf_json_int(abuf, "totalIpcConnectionsAllowed", olsr_cnf->ipc_connections);
   abuf_json_open_array(abuf, "ipcAllowedAddresses");
   if (olsr_cnf->ipc_connections) {
-    for (ipcn = olsr_cnf->ipc_nets; ipcn != NULL; ipcn = ipcn->next) {
+    for (ipcn = olsr_cnf->ipc_nets; ipcn != NULL ; ipcn = ipcn->next) {
       abuf_json_open_array_entry(abuf);
-      abuf_json_string(abuf, "ipAddress",
-                       olsr_ip_to_string(&mainaddrbuf, &ipcn->net.prefix));
+      abuf_json_string(abuf, "ipAddress", olsr_ip_to_string(&mainaddrbuf, &ipcn->net.prefix));
       abuf_json_int(abuf, "netmask", ipcn->net.prefix_len);
       abuf_json_close_array_entry(abuf);
     }
@@ -1026,7 +938,7 @@ ipc_print_config(struct autobuf *abuf)
       struct sgw_egress_if * egressif = olsr_cnf->smart_gw_egress_interfaces;
 
       abuf_init(&egressbuf, (olsr_cnf->smart_gw_egress_interfaces_count * IFNAMSIZ) /* interface names */
-          + (olsr_cnf->smart_gw_egress_interfaces_count - 1) /* commas */);
+      + (olsr_cnf->smart_gw_egress_interfaces_count - 1) /* commas */);
       while (egressif) {
         if (egressbuf.len) {
           abuf_puts(&egressbuf, ",");
@@ -1047,16 +959,13 @@ ipc_print_config(struct autobuf *abuf)
     abuf_json_int(abuf, "smartGatewayUplink", olsr_cnf->smart_gw_uplink);
     abuf_json_int(abuf, "smartGatewayDownlink", olsr_cnf->smart_gw_downlink);
     abuf_json_int(abuf, "smartGatewayType", olsr_cnf->smart_gw_type);
-    abuf_json_string(abuf, "smartGatewayPrefix",
-                     olsr_ip_to_string(&mainaddrbuf, &olsr_cnf->smart_gw_prefix.prefix));
+    abuf_json_string(abuf, "smartGatewayPrefix", olsr_ip_to_string(&mainaddrbuf, &olsr_cnf->smart_gw_prefix.prefix));
     abuf_json_int(abuf, "smartGatewayPrefixLength", olsr_cnf->smart_gw_prefix.prefix_len);
   }
 #endif /* __linux__ */
 
-  abuf_json_string(abuf, "mainIpAddress",
-                   olsr_ip_to_string(&mainaddrbuf, &olsr_cnf->main_addr));
-  abuf_json_string(abuf, "unicastSourceIpAddress",
-                   olsr_ip_to_string(&mainaddrbuf, &olsr_cnf->unicast_src_ip));
+  abuf_json_string(abuf, "mainIpAddress", olsr_ip_to_string(&mainaddrbuf, &olsr_cnf->main_addr));
+  abuf_json_string(abuf, "unicastSourceIpAddress", olsr_ip_to_string(&mainaddrbuf, &olsr_cnf->unicast_src_ip));
 
   abuf_json_boolean(abuf, "useSourceIpRoutes", olsr_cnf->use_src_ip_routes);
 
@@ -1114,27 +1023,24 @@ ipc_print_config(struct autobuf *abuf)
   abuf_json_close_object(abuf);
 }
 
-static void
-ipc_print_interfaces(struct autobuf *abuf)
-{
+static void ipc_print_interfaces(struct autobuf *abuf) {
 #ifdef __linux__
   int linklen;
   char path[PATH_MAX], linkpath[PATH_MAX];
 #endif /* __linux__ */
-  char ipv6_buf[INET6_ADDRSTRLEN];                  /* buffer for IPv6 inet_htop */
+  char ipv6_buf[INET6_ADDRSTRLEN]; /* buffer for IPv6 inet_htop */
   struct olsr_lq_mult *mult;
   const struct olsr_if *ifs;
   abuf_json_open_array(abuf, "interfaces");
-  for (ifs = olsr_cnf->interfaces; ifs != NULL; ifs = ifs->next) {
-    const struct interface_olsr *const rifs = ifs->interf;
+  for (ifs = olsr_cnf->interfaces; ifs != NULL ; ifs = ifs->next) {
+    const struct interface_olsr * const rifs = ifs->interf;
     abuf_json_open_array_entry(abuf);
     abuf_json_string(abuf, "name", ifs->name);
 
     abuf_json_open_array(abuf, "linkQualityMultipliers");
-    for (mult = ifs->cnf->lq_mult; mult != NULL; mult = mult->next) {
+    for (mult = ifs->cnf->lq_mult; mult != NULL ; mult = mult->next) {
       abuf_json_open_array_entry(abuf);
-      abuf_json_string(abuf, "route",
-                       inet_ntop(olsr_cnf->ip_version, &mult->addr, ipv6_buf, sizeof(ipv6_buf)));
+      abuf_json_string(abuf, "route", inet_ntop(olsr_cnf->ip_version, &mult->addr, ipv6_buf, sizeof(ipv6_buf)));
       abuf_json_float(abuf, "multiplier", mult->value / 65535.0);
       abuf_json_close_array_entry(abuf);
     }
@@ -1167,18 +1073,13 @@ ipc_print_interfaces(struct autobuf *abuf)
 
       if (olsr_cnf->ip_version == AF_INET) {
         struct ipaddr_str addrbuf, maskbuf, bcastbuf;
-        abuf_json_string(abuf, "ipv4Address",
-                             ip4_to_string(&addrbuf, rifs->int_addr.sin_addr));
-        abuf_json_string(abuf, "netmask",
-                             ip4_to_string(&maskbuf, rifs->int_netmask.sin_addr));
-        abuf_json_string(abuf, "broadcast",
-                             ip4_to_string(&bcastbuf, rifs->int_broadaddr.sin_addr));
+        abuf_json_string(abuf, "ipv4Address", ip4_to_string(&addrbuf, rifs->int_addr.sin_addr));
+        abuf_json_string(abuf, "netmask", ip4_to_string(&maskbuf, rifs->int_netmask.sin_addr));
+        abuf_json_string(abuf, "broadcast", ip4_to_string(&bcastbuf, rifs->int_broadaddr.sin_addr));
       } else {
         struct ipaddr_str addrbuf, maskbuf;
-        abuf_json_string(abuf, "ipv6Address",
-                             ip6_to_string(&addrbuf, &rifs->int6_addr.sin6_addr));
-        abuf_json_string(abuf, "multicast",
-                             ip6_to_string(&maskbuf, &rifs->int6_multaddr.sin6_addr));
+        abuf_json_string(abuf, "ipv6Address", ip6_to_string(&addrbuf, &rifs->int6_addr.sin6_addr));
+        abuf_json_string(abuf, "multicast", ip6_to_string(&maskbuf, &rifs->int6_multaddr.sin6_addr));
       }
     }
 #ifdef __linux__
@@ -1238,26 +1139,20 @@ ipc_print_interfaces(struct autobuf *abuf)
   abuf_json_close_array(abuf);
 }
 
-
-static void
-ipc_print_olsrd_conf(struct autobuf *abuf)
-{
+static void ipc_print_olsrd_conf(struct autobuf *abuf) {
   olsrd_write_cnf_autobuf(abuf, olsr_cnf);
 }
 
-
-static void
-jsoninfo_write_data(void *foo __attribute__ ((unused)))
-{
+static void jsoninfo_write_data(void *foo __attribute__ ((unused))) {
   fd_set set;
   int result, i, j, max;
   struct timeval tv;
 
   FD_ZERO(&set);
   max = 0;
-  for (i=0; i<outbuffer_count; i++) {
+  for (i = 0; i < outbuffer_count; i++) {
     /* And we cast here since we get a warning on Win32 */
-    FD_SET((unsigned int)(outbuffer_socket[i]), &set);
+    FD_SET((unsigned int )(outbuffer_socket[i]), &set);
 
     if (outbuffer_socket[i] > max) {
       max = outbuffer_socket[i];
@@ -1272,12 +1167,9 @@ jsoninfo_write_data(void *foo __attribute__ ((unused)))
     return;
   }
 
-  for (i=0; i<outbuffer_count; i++) {
+  for (i = 0; i < outbuffer_count; i++) {
     if (FD_ISSET(outbuffer_socket[i], &set)) {
-      result = send(outbuffer_socket[i],
-                    outbuffer[i] + outbuffer_written[i],
-                    outbuffer_size[i] - outbuffer_written[i],
-                    0);
+      result = send(outbuffer_socket[i], outbuffer[i] + outbuffer_written[i], outbuffer_size[i] - outbuffer_written[i], 0);
       if (result > 0) {
         outbuffer_written[i] += result;
       }
@@ -1285,13 +1177,13 @@ jsoninfo_write_data(void *foo __attribute__ ((unused)))
       if (result <= 0 || outbuffer_written[i] == outbuffer_size[i]) {
         /* close this socket and cleanup*/
         close(outbuffer_socket[i]);
-        free (outbuffer[i]);
+        free(outbuffer[i]);
 
-        for (j=i+1; j<outbuffer_count; j++) {
-          outbuffer[j-1] = outbuffer[j];
-          outbuffer_size[j-1] = outbuffer_size[j];
-          outbuffer_socket[j-1] = outbuffer_socket[j];
-          outbuffer_written[j-1] = outbuffer_written[j];
+        for (j = i + 1; j < outbuffer_count; j++) {
+          outbuffer[j - 1] = outbuffer[j];
+          outbuffer_size[j - 1] = outbuffer_size[j];
+          outbuffer_socket[j - 1] = outbuffer_socket[j];
+          outbuffer_written[j - 1] = outbuffer_written[j];
         }
         outbuffer_count--;
       }
@@ -1302,9 +1194,7 @@ jsoninfo_write_data(void *foo __attribute__ ((unused)))
   }
 }
 
-static void
-send_info(unsigned int send_what, int the_socket)
-{
+static void send_info(unsigned int send_what, int the_socket) {
   struct autobuf abuf;
   size_t header_len = 0;
   char header_buf[MAX_HTTPHEADER_SIZE];
@@ -1316,22 +1206,33 @@ send_info(unsigned int send_what, int the_socket)
 
   abuf_init(&abuf, 32768);
 
- // only add if outputing JSON
-  if (send_what & SIW_ALL) abuf_puts(&abuf, "{");
-
-  if ((send_what & SIW_LINKS) == SIW_LINKS) ipc_print_links(&abuf);
-  if ((send_what & SIW_NEIGHBORS) == SIW_NEIGHBORS) ipc_print_neighbors(&abuf);
-  if ((send_what & SIW_TOPOLOGY) == SIW_TOPOLOGY) ipc_print_topology(&abuf);
-  if ((send_what & SIW_HNA) == SIW_HNA) ipc_print_hna(&abuf);
-  if ((send_what & SIW_MID) == SIW_MID) ipc_print_mid(&abuf);
-  if ((send_what & SIW_ROUTES) == SIW_ROUTES) ipc_print_routes(&abuf);
-  if ((send_what & SIW_GATEWAYS) == SIW_GATEWAYS) ipc_print_gateways(&abuf);
-  if ((send_what & SIW_INTERFACES) == SIW_INTERFACES) ipc_print_interfaces(&abuf);
+  // only add if outputing JSON
+  if (send_what & SIW_ALL)
+    abuf_puts(&abuf, "{");
+
+  if ((send_what & SIW_LINKS) == SIW_LINKS)
+    ipc_print_links(&abuf);
+  if ((send_what & SIW_NEIGHBORS) == SIW_NEIGHBORS)
+    ipc_print_neighbors(&abuf);
+  if ((send_what & SIW_TOPOLOGY) == SIW_TOPOLOGY)
+    ipc_print_topology(&abuf);
+  if ((send_what & SIW_HNA) == SIW_HNA)
+    ipc_print_hna(&abuf);
+  if ((send_what & SIW_MID) == SIW_MID)
+    ipc_print_mid(&abuf);
+  if ((send_what & SIW_ROUTES) == SIW_ROUTES)
+    ipc_print_routes(&abuf);
+  if ((send_what & SIW_GATEWAYS) == SIW_GATEWAYS)
+    ipc_print_gateways(&abuf);
+  if ((send_what & SIW_INTERFACES) == SIW_INTERFACES)
+    ipc_print_interfaces(&abuf);
   if ((send_what & SIW_CONFIG) == SIW_CONFIG) {
-    if (send_what != SIW_CONFIG) abuf_puts(&abuf, ",");
+    if (send_what != SIW_CONFIG)
+      abuf_puts(&abuf, ",");
     ipc_print_config(&abuf);
   }
-  if ((send_what & SIW_PLUGINS) == SIW_PLUGINS) ipc_print_plugins(&abuf);
+  if ((send_what & SIW_PLUGINS) == SIW_PLUGINS)
+    ipc_print_plugins(&abuf);
 
   /* output overarching meta data last so we can use abuf_json_* functions, they add a comma at the beginning */
   if (send_what & SIW_ALL) {
@@ -1347,7 +1248,7 @@ send_info(unsigned int send_what, int the_socket)
     ipc_print_olsrd_conf(&abuf);
   }
 
-  if(http_headers) {
+  if (http_headers) {
     header_len = build_http_header(HTTP_200, content_type, abuf.len, header_buf, sizeof(header_buf));
   }
 
@@ -1361,21 +1262,15 @@ send_info(unsigned int send_what, int the_socket)
   outbuffer_count++;
 
   if (outbuffer_count == 1) {
-    writetimer_entry = olsr_start_timer(100,
-                                        0,
-                                        OLSR_TIMER_PERIODIC,
-                                        &jsoninfo_write_data,
-                                        NULL,
-                                        0);
+    writetimer_entry = olsr_start_timer(100, 0,
+    OLSR_TIMER_PERIODIC, &jsoninfo_write_data,
+    NULL, 0);
   }
 
   abuf_free(&abuf);
 }
 
-static size_t
-build_http_header(const char *status, const char *mime, uint32_t msgsize,
-  char *buf, uint32_t bufsize)
-{
+static size_t build_http_header(const char *status, const char *mime, uint32_t msgsize, char *buf, uint32_t bufsize) {
   time_t currtime;
   size_t size;
 
@@ -1392,7 +1287,7 @@ build_http_header(const char *status, const char *mime, uint32_t msgsize,
   size += snprintf(&buf[size], bufsize - size, "Connection: closed\r\n");
 
   /* MIME type */
-  if(mime != NULL) {
+  if (mime != NULL) {
     size += snprintf(&buf[size], bufsize - size, "Content-type: %s\r\n", mime);
   }
 
index 28e57e6..25ed487 100644 (file)
@@ -1,4 +1,3 @@
-
 /*
  * The olsr.org Optimized Link-State Routing daemon(olsrd)
  * Copyright (c) 2004, Andreas Tonnesen(andreto@olsr.org)
index 13a4418..12fc2fb 100644 (file)
@@ -1,4 +1,3 @@
-
 /*
  * The olsr.org Optimized Link-State Routing daemon(olsrd)
  * Copyright (c) 2004, Andreas Tonnesen(andreto@olsr.org)
@@ -73,9 +72,7 @@ static void my_fini(void) __attribute__ ((destructor));
 /**
  *Constructor
  */
-static void
-my_init(void)
-{
+static void my_init(void) {
   /* Print plugin info to stdout */
   printf("%s\n", MOD_DESC);
 
@@ -99,9 +96,7 @@ my_init(void)
 /**
  *Destructor
  */
-static void
-my_fini(void)
-{
+static void my_fini(void) {
   /* Calls the destruction function
    * olsr_plugin_exit()
    * This function should be present in your
@@ -111,25 +106,19 @@ my_fini(void)
   olsr_plugin_exit();
 }
 
-int
-olsrd_plugin_interface_version(void)
-{
+int olsrd_plugin_interface_version(void) {
   return PLUGIN_INTERFACE_VERSION;
 }
 
-static int
-store_string(const char *value, void *data, set_plugin_parameter_addon addon __attribute__ ((unused)))
-{
+static int store_string(const char *value, void *data, set_plugin_parameter_addon addon __attribute__ ((unused))) {
   char *str = data;
   snprintf(str, FILENAME_MAX, "%s", value);
   return 0;
 }
 
-static int
-store_boolean(const char *value, void *data, set_plugin_parameter_addon addon __attribute__ ((unused)))
-{
+static int store_boolean(const char *value, void *data, set_plugin_parameter_addon addon __attribute__ ((unused))) {
   bool *dest = data;
-  if(strcmp(value, "yes") == 0)
+  if (strcmp(value, "yes") == 0)
     *dest = true;
   else if (strcmp(value, "no") == 0)
     *dest = false;
@@ -139,18 +128,13 @@ store_boolean(const char *value, void *data, set_plugin_parameter_addon addon __
   return 0;
 }
 
-static const struct olsrd_plugin_parameters plugin_parameters[] = {
-  {.name = "port",.set_plugin_parameter = &set_plugin_port,.data = &ipc_port},
-  {.name = "accept",.set_plugin_parameter = &set_plugin_ipaddress,.data = &jsoninfo_accept_ip},
-  {.name = "listen",.set_plugin_parameter = &set_plugin_ipaddress,.data = &jsoninfo_listen_ip},
-  {.name = "uuidfile",.set_plugin_parameter = &store_string,.data = uuidfile},
-  {.name = "httpheaders",.set_plugin_parameter = &store_boolean,.data = &http_headers},
-  {.name = "ipv6only", .set_plugin_parameter = &set_plugin_boolean, .data = &jsoninfo_ipv6_only},
-};
-
-void
-olsrd_get_plugin_parameters(const struct olsrd_plugin_parameters **params, int *size)
-{
+static const struct olsrd_plugin_parameters plugin_parameters[] = { { .name = "port", .set_plugin_parameter = &set_plugin_port, .data = &ipc_port }, { .name =
+    "accept", .set_plugin_parameter = &set_plugin_ipaddress, .data = &jsoninfo_accept_ip }, { .name = "listen", .set_plugin_parameter = &set_plugin_ipaddress,
+    .data = &jsoninfo_listen_ip }, { .name = "uuidfile", .set_plugin_parameter = &store_string, .data = uuidfile }, { .name = "httpheaders",
+    .set_plugin_parameter = &store_boolean, .data = &http_headers }, { .name = "ipv6only", .set_plugin_parameter = &set_plugin_boolean, .data =
+    &jsoninfo_ipv6_only }, };
+
+void olsrd_get_plugin_parameters(const struct olsrd_plugin_parameters **params, int *size) {
   *params = plugin_parameters;
   *size = sizeof(plugin_parameters) / sizeof(*plugin_parameters);
 }