{GPL, other}: Relicense to MIT license.
[collectd.git] / src / olsrd.c
index 123520a..6d0576c 100644 (file)
@@ -1,22 +1,27 @@
 /**
  * collectd - src/olsrd.c
- * Copyright (C) 2009  Florian octo Forster
+ * Copyright (C) 2009       Florian octo Forster
  *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
- *   Florian octo Forster <octo at verplant.org>
+ *   Florian octo Forster <octo at collectd.org>
  **/
 
 #include "collectd.h"
 #include "plugin.h"
 
 #include <sys/types.h>
-#include <sys/socket.h>
 #include <netdb.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netinet/tcp.h>
 
 #define OLSRD_DEFAULT_NODE "localhost"
 #define OLSRD_DEFAULT_SERVICE "2006"
@@ -257,8 +264,8 @@ static int olsrd_cb_links (int lineno, /* {{{ */
   static double   nlq_sum;
   static uint32_t nlq_num;
 
-  double lq;  /* tx */
-  double nlq; /* rx */
+  double lq;
+  double nlq;
 
   char *endptr;
 
@@ -289,14 +296,14 @@ static int olsrd_cb_links (int lineno, /* {{{ */
       lq = lq_sum / ((double) lq_num);
     DEBUG ("olsrd plugin: Average  LQ: %g", lq);
     olsrd_submit (/* p.-inst = */ "links", /* type = */ "signal_quality",
-        "average-tx", lq);
+        "average-lq", lq);
 
     nlq = NAN;
     if (nlq_num > 0)
       nlq = nlq_sum / ((double) nlq_num);
     DEBUG ("olsrd plugin: Average NLQ: %g", nlq);
     olsrd_submit (/* p.-inst = */ "links", /* type = */ "signal_quality",
-        "average-rx", nlq);
+        "average-nlq", nlq);
 
     return (0);
   }
@@ -325,7 +332,7 @@ static int olsrd_cb_links (int lineno, /* {{{ */
     {
       char type_instance[DATA_MAX_NAME_LEN];
 
-      ssnprintf (type_instance, sizeof (type_instance), "%s-%s-tx",
+      ssnprintf (type_instance, sizeof (type_instance), "%s-%s-lq",
           fields[0], fields[1]);
 
       DEBUG ("olsrd plugin: links: type_instance = %s;  lq = %g;",
@@ -554,7 +561,7 @@ static int olsrd_cb_topology (int lineno, /* {{{ */
       char type_instance[DATA_MAX_NAME_LEN];
 
       memset (type_instance, 0, sizeof (type_instance));
-      ssnprintf (type_instance, sizeof (type_instance), "%s-%s-rx",
+      ssnprintf (type_instance, sizeof (type_instance), "%s-%s-lq",
           fields[0], fields[1]);
       DEBUG ("olsrd plugin: type_instance = %s; lq = %g;", type_instance, lq);
       olsrd_submit (/* p.-inst = */ "topology", /* type = */ "signal_quality",
@@ -578,7 +585,7 @@ static int olsrd_cb_topology (int lineno, /* {{{ */
       char type_instance[DATA_MAX_NAME_LEN];
 
       memset (type_instance, 0, sizeof (type_instance));
-      ssnprintf (type_instance, sizeof (type_instance), "%s-%s-tx",
+      ssnprintf (type_instance, sizeof (type_instance), "%s-%s-nlq",
           fields[0], fields[1]);
       DEBUG ("olsrd plugin: type_instance = %s; nlq = %g;", type_instance, nlq);
       olsrd_submit (/* p.-inst = */ "topology", /* type = */ "signal_quality",
@@ -651,6 +658,9 @@ static int olsrd_read (void) /* {{{ */
   if (fh == NULL)
     return (-1);
 
+  fputs ("\r\n", fh);
+  fflush (fh);
+
   while (fgets (buffer, sizeof (buffer), fh) != NULL)
   {
     buffer_len = strchomp (buffer);