txtinfo plugin: add more http options
authorMarkus Kittenberger <Markus.Kittenberger@gmx.at>
Wed, 5 Mar 2008 07:46:43 +0000 (08:46 +0100)
committerMarkus Kittenberger <Markus.Kittenberger@gmx.at>
Wed, 5 Mar 2008 07:46:43 +0000 (08:46 +0100)
lib/txtinfo/src/olsrd_txtinfo.c

index 75190c0..2620786 100644 (file)
@@ -95,11 +95,13 @@ static int ipc_socket_up;
 /* IPC initialization function */
 static int plugin_ipc_init(void);
 
-static void  send_info(int neighonly);
+static void send_info(int send_what);
 
 static void ipc_action(int);
 
-static void ipc_print_neigh_link(void);
+static void ipc_print_neigh(void);
+
+static void ipc_print_link(void);
 
 static void ipc_print_routes(void);
 
@@ -110,6 +112,16 @@ static void ipc_print_hna(void);
 static void ipc_print_mid(void);
 
 #define TXT_IPC_BUFSIZE 256
+
+#define SIW_ALL 0
+#define SIW_NEIGH 1
+#define SIW_LINK 2
+#define SIW_ROUTE 3
+#define SIW_HNA 4
+#define SIW_MID 5
+#define SIW_TOPO 6
+#define SIW_NEIGHLINK 7
+
 static int ipc_sendf(const char* format, ...) __attribute__((format(printf, 1, 2)));
 
 /**
@@ -230,7 +242,7 @@ static void ipc_action(int fd)
     char addr[INET6_ADDRSTRLEN];
     fd_set rfds;
     struct timeval tv;
-    int neighonly = 0;
+    int send_what = 0;
 
     socklen_t addrlen = sizeof(struct sockaddr_storage);
 
@@ -285,40 +297,29 @@ static void ipc_action(int fd)
              * page the normal output is somewhat lengthy. The
              * header parsing is sufficient for standard wget.
              */
-            neighonly = (0 != strstr(requ, "/neighbours"));
+            if (0 != strstr(requ, "/neighbours")) send_what=SIW_NEIGHLINK;
+            else if (0 != strstr(requ, "/neigh")) send_what=SIW_NEIGH;
+            else if (0 != strstr(requ, "/link")) send_what=SIW_LINK;
+            else if (0 != strstr(requ, "/route")) send_what=SIW_ROUTE;
+            else if (0 != strstr(requ, "/hna")) send_what=SIW_HNA;
+            else if (0 != strstr(requ, "/mid")) send_what=SIW_MID;
+            else if (0 != strstr(requ, "/topo")) send_what=SIW_TOPO;
         }
     }
 
-    send_info(neighonly);
+       send_info(send_what);
          
     close(ipc_connection);
     ipc_open = 0;
 }
 
-static void ipc_print_neigh_link(void)
+static void ipc_print_neigh(void)
 {
-    struct ipaddr_str buf1, buf2;
+    struct ipaddr_str buf1;
     struct neighbor_entry *neigh;
     struct neighbor_2_list_entry *list_2;
-    struct link_entry *link = NULL;
     int index, thop_cnt;
 
-    ipc_sendf("Table: Links\nLocal IP\tremote IP\tHysteresis\tLinkQuality\tlost\ttotal\tNLQ\tETX\n");
-
-    /* Link set */
-    link = link_set;
-    while(link)        {
-       ipc_sendf( "%s\t%s\t%s\t%s\t%d\t%d\t%s\t%s\t\n",
-                   olsr_ip_to_string(&buf1, &link->local_iface_addr),
-                   olsr_ip_to_string(&buf2, &link->neighbor_iface_addr),
-                   fpmtoa(link->L_link_quality), 
-                   fpmtoa(link->loss_link_quality),
-                   link->lost_packets, 
-                   link->total_packets,
-                   fpmtoa(link->neigh_link_quality), 
-                   etxtoa(olsr_calc_link_etx(link)));
-        link = link->next;
-    }
     ipc_sendf("\nTable: Neighbors\nIP address\tSYM\tMPR\tMPRS\tWillingness\t2 Hop Neighbors\n");
 
     /* Neighbors */
@@ -347,6 +348,31 @@ static void ipc_print_neigh_link(void)
     ipc_sendf("\n");
 }
 
+static void ipc_print_link(void)
+{
+    struct ipaddr_str buf1, buf2;
+    struct link_entry *link = NULL;
+
+    ipc_sendf("Table: Links\nLocal IP\tremote IP\tHysteresis\tLinkQuality\tlost\ttotal\tNLQ\tETX\n");
+
+    /* Link set */
+    link = link_set;
+    while(link)        {
+       ipc_sendf( "%s\t%s\t%0.2f\t%0.2f\t%d\t%d\t%0.2f\t%0.2f\t\n",
+                   olsr_ip_to_string(&buf1, &link->local_iface_addr),
+                   olsr_ip_to_string(&buf2, &link->neighbor_iface_addr),
+                   link->L_link_quality, 
+                   link->loss_link_quality,
+                   link->lost_packets, 
+                   link->total_packets,
+                   link->neigh_link_quality, 
+                   olsr_calc_link_etx(link));
+        link = link->next;
+    }
+
+    ipc_sendf("\n");
+}
+
 static void ipc_print_routes(void)
 {
     struct ipaddr_str buf1, buf2;
@@ -362,12 +388,12 @@ static void ipc_print_routes(void)
 
         rt = rt_tree_node->data;
 
-        ipc_sendf( "%s/%d\t%s\t%d\t%s\t%s\t\n",
+        ipc_sendf( "%s/%d\t%s\t%d\t%.3f\t%s\t\n",
                    olsr_ip_to_string(&buf1, &rt->rt_dst.prefix),
                    rt->rt_dst.prefix_len,
                    olsr_ip_to_string(&buf2, &rt->rt_best->rtp_nexthop.gateway),
                    rt->rt_best->rtp_metric.hops,
-                   etxtoa(rt->rt_best->rtp_metric.etx),
+                   rt->rt_best->rtp_metric.etx,
                    if_ifwithindex_name(rt->rt_best->rtp_nexthop.iif_index));
     }
     ipc_sendf("\n");
@@ -385,12 +411,12 @@ static void ipc_print_topology(void)
         struct tc_edge_entry *tc_edge;
         OLSR_FOR_ALL_TC_EDGE_ENTRIES(tc, tc_edge) {
             struct ipaddr_str dstbuf, addrbuf;
-            ipc_sendf( "%s\t%s\t%s\t%s\t%s\n", 
+            ipc_sendf( "%s\t%s\t%0.2f\t%0.2f\t%0.2f\n", 
                        olsr_ip_to_string(&dstbuf, &tc_edge->T_dest_addr),
                        olsr_ip_to_string(&addrbuf, &tc->addr), 
-                       fpmtoa(tc_edge->link_quality),
-                       fpmtoa(tc_edge->inverse_link_quality),
-                       etxtoa(olsr_calc_tc_etx(tc_edge)));
+                       tc_edge->link_quality,
+                       tc_edge->inverse_link_quality,
+                       olsr_calc_tc_etx(tc_edge));
 
         } OLSR_FOR_ALL_TC_EDGE_ENTRIES_END(tc, tc_edge);
     } OLSR_FOR_ALL_TC_ENTRIES_END(tc);
@@ -482,7 +508,7 @@ static void ipc_print_mid(void)
 }
 
 
-static void  send_info(int neighonly)
+static void  send_info(int send_what)
 {
     /* Print minimal http header */
     ipc_sendf("HTTP/1.0 200 OK\n");
@@ -491,19 +517,21 @@ static void  send_info(int neighonly)
     /* Print tables to IPC socket */
        
     /* links + Neighbors */
-    ipc_print_neigh_link();
+    if ((send_what==SIW_ALL)||(send_what==SIW_NEIGHLINK)||(send_what==SIW_LINK)) ipc_print_link();
+
+    if ((send_what==SIW_ALL)||(send_what==SIW_NEIGHLINK)||(send_what==SIW_NEIGH)) ipc_print_neigh();
        
     /* topology */
-    if (!neighonly) ipc_print_topology();
+    if ((send_what==SIW_ALL)||(send_what==SIW_TOPO)) ipc_print_topology();
        
     /* hna */
-    if (!neighonly) ipc_print_hna();
+    if ((send_what==SIW_ALL)||(send_what==SIW_HNA)) ipc_print_hna();
 
     /* mid */
-    if (!neighonly) ipc_print_mid();
+    if ((send_what==SIW_ALL)||(send_what==SIW_MID)) ipc_print_mid();
 
     /* routes */
-    if (!neighonly) ipc_print_routes();
+    if ((send_what==SIW_ALL)||(send_what==SIW_ROUTE)) ipc_print_routes();
 }
 
 /*