jsoninfo: move determining the action into a separate function
authorFerry Huberts <ferry.huberts@pelagic.nl>
Tue, 1 Dec 2015 06:41:37 +0000 (07:41 +0100)
committerFerry Huberts <ferry.huberts@pelagic.nl>
Wed, 2 Dec 2015 17:41:13 +0000 (18:41 +0100)
Signed-off-by: Ferry Huberts <ferry.huberts@pelagic.nl>
lib/jsoninfo/src/olsrd_jsoninfo.c

index e6caf93..5206aad 100644 (file)
@@ -145,6 +145,57 @@ static int outbuffer_count = 0;
 static struct timer_entry *writetimer_entry;
 static struct timeval start_time;
 
+static void determine_action(unsigned int *send_what, char *requ) {
+  if (strstr(requ, "/olsrd.conf"))
+    *send_what |= SIW_OLSRD_CONF;
+  else if (strstr(requ, "/all"))
+    *send_what = SIW_ALL;
+  else {
+    // these are the two overarching categories
+    if (strstr(requ, "/runtime"))
+      *send_what |= SIW_RUNTIME_ALL;
+    if (strstr(requ, "/startup"))
+      *send_what |= SIW_STARTUP_ALL;
+
+    // these are the individual sections
+    if (strstr(requ, "/neighbors"))
+      *send_what |= SIW_NEIGHBORS;
+    if (strstr(requ, "/links"))
+      *send_what |= SIW_LINKS;
+    if (strstr(requ, "/routes"))
+      *send_what |= SIW_ROUTES;
+    if (strstr(requ, "/hna"))
+      *send_what |= SIW_HNA;
+    if (strstr(requ, "/mid"))
+      *send_what |= SIW_MID;
+    if (strstr(requ, "/topology"))
+      *send_what |= SIW_TOPOLOGY;
+    if (strstr(requ, "/gateways"))
+      *send_what |= SIW_GATEWAYS;
+    if (strstr(requ, "/interfaces"))
+      *send_what |= SIW_INTERFACES;
+    if (strstr(requ, "/2hop"))
+      *send_what |= SIW_2HOP;
+    if (strstr(requ, "/sgw"))
+      *send_what |= SIW_SGW;
+
+    // specials
+    if (strstr(requ, "/version"))
+      *send_what |= SIW_VERSION;
+    if (strstr(requ, "/config"))
+      *send_what |= SIW_CONFIG;
+    if (strstr(requ, "/plugins"))
+      *send_what |= SIW_PLUGINS;
+
+    /* To print out neighbours only on the Freifunk Status
+     * page the normal output is somewhat lengthy. The
+     * header parsing is sufficient for standard wget.
+     */
+    if (strstr(requ, "/neighbours"))
+      *send_what = SIW_NEIGHBORS | SIW_LINKS;
+  }
+}
+
 /**
  *Do initialization here
  *
@@ -323,55 +374,7 @@ static void ipc_action(int fd, void *data __attribute__ ((unused)), unsigned int
 
     if (0 < s) {
       requ[s] = 0;
-      /* print out the requested tables */
-      if (strstr(requ, "/olsrd.conf"))
-        send_what |= SIW_OLSRD_CONF;
-      else if (strstr(requ, "/all"))
-        send_what = SIW_ALL;
-      else {
-        // these are the two overarching categories
-        if (strstr(requ, "/runtime"))
-          send_what |= SIW_RUNTIME_ALL;
-        if (strstr(requ, "/startup"))
-          send_what |= SIW_STARTUP_ALL;
-
-        // these are the individual sections
-        if (strstr(requ, "/neighbors"))
-          send_what |= SIW_NEIGHBORS;
-        if (strstr(requ, "/links"))
-          send_what |= SIW_LINKS;
-        if (strstr(requ, "/routes"))
-          send_what |= SIW_ROUTES;
-        if (strstr(requ, "/hna"))
-          send_what |= SIW_HNA;
-        if (strstr(requ, "/mid"))
-          send_what |= SIW_MID;
-        if (strstr(requ, "/topology"))
-          send_what |= SIW_TOPOLOGY;
-        if (strstr(requ, "/gateways"))
-          send_what |= SIW_GATEWAYS;
-        if (strstr(requ, "/interfaces"))
-          send_what |= SIW_INTERFACES;
-        if (strstr(requ, "/2hop"))
-          send_what |= SIW_2HOP;
-        if (strstr(requ, "/sgw"))
-          send_what |= SIW_SGW;
-
-        // specials
-        if (strstr(requ, "/version"))
-          send_what |= SIW_VERSION;
-        if (strstr(requ, "/config"))
-          send_what |= SIW_CONFIG;
-        if (strstr(requ, "/plugins"))
-          send_what |= SIW_PLUGINS;
-
-        /* To print out neighbours only on the Freifunk Status
-         * page the normal output is somewhat lengthy. The
-         * header parsing is sufficient for standard wget.
-         */
-        if (strstr(requ, "/neighbours"))
-          send_what = SIW_NEIGHBORS | SIW_LINKS;
-      }
+      determine_action(&send_what, requ);
     }
 
     if (!send_what)