1Quelle: http://absorb.it/software/opennet/ondataservice/olsrd-0.6.6.2.tgz
 
    2Index: firmware/routing/olsrd/Makefile
 
    3===================================================================
 
    4--- firmware.orig/routing/olsrd/Makefile
 
    5+++ firmware/routing/olsrd/Makefile
 
    6@@ -109,6 +109,18 @@ define Package/olsrd-mod-nameservice
 
    7   TITLE:=Lightweight hostname resolver plugin
 
   10+define Package/olsrd-mod-ondataservice
 
   11+  $(call Package/olsrd/template)
 
   12+  DEPENDS:=olsrd +libsqlite3 +sqlite3-cli
 
   13+  TITLE:=Opennet Dataservice SQLite3 plugin
 
   16+define Package/olsrd-mod-ondataservice_light
 
   17+  $(call Package/olsrd/template)
 
   19+  TITLE:=Opennet Dataservice JSON plugin
 
   22 define Package/olsrd-mod-p2pd
 
   23   $(call Package/olsrd/template)
 
   25@@ -181,7 +193,7 @@ MAKE_FLAGS+= \
 
   26    DESTDIR="$(PKG_INSTALL_DIR)" \
 
   29-   SUBDIRS="arprefresh bmf dot_draw dyn_gw dyn_gw_plain httpinfo filtergw jsoninfo netjson mdns nameservice p2pd pgraph pud quagga secure sgwdynspeed txtinfo watchdog"
 
   30+   SUBDIRS="arprefresh bmf dot_draw dyn_gw dyn_gw_plain httpinfo filtergw jsoninfo netjson mdns nameservice ondataservice_light p2pd pgraph pud quagga secure sgwdynspeed txtinfo watchdog"
 
   33    $(call Build/Compile/Default,all)
 
   34@@ -256,6 +268,16 @@ define Package/olsrd-mod-nameservice/ins
 
   35    $(INSTALL_BIN) $(PKG_BUILD_DIR)/lib/nameservice/olsrd_nameservice.so.* $(1)/usr/lib/
 
   38+define Package/olsrd-mod-ondataservice/install
 
   39+   $(INSTALL_DIR) $(1)/usr/lib
 
   40+   $(INSTALL_BIN) $(PKG_BUILD_DIR)/lib/ondataservice/olsrd_ondataservice.so.* $(1)/usr/lib/
 
   43+define Package/olsrd-mod-ondataservice_light/install
 
   44+   $(INSTALL_DIR) $(1)/usr/lib
 
   45+   $(INSTALL_BIN) $(PKG_BUILD_DIR)/lib/ondataservice_light/olsrd_ondataservice_light.so.* $(1)/usr/lib/
 
   48 define Package/olsrd-mod-p2pd/install
 
   49    $(INSTALL_DIR) $(1)/usr/lib
 
   50    $(INSTALL_BIN) $(PKG_BUILD_DIR)/lib/p2pd/olsrd_p2pd.so.* $(1)/usr/lib/
 
   51@@ -321,6 +343,8 @@ $(eval $(call BuildPackage,olsrd-mod-jso
 
   52 $(eval $(call BuildPackage,olsrd-mod-netjson))
 
   53 $(eval $(call BuildPackage,olsrd-mod-mdns))
 
   54 $(eval $(call BuildPackage,olsrd-mod-nameservice))
 
   55+$(eval $(call BuildPackage,olsrd-mod-ondataservice))
 
   56+$(eval $(call BuildPackage,olsrd-mod-ondataservice_light))
 
   57 $(eval $(call BuildPackage,olsrd-mod-p2pd))
 
   58 $(eval $(call BuildPackage,olsrd-mod-pgraph))
 
   59 $(eval $(call BuildPackage,olsrd-mod-pud))
 
   60Index: firmware/routing/olsrd/patches/023-ondataservice.patch
 
   61===================================================================
 
   63+++ firmware/routing/olsrd/patches/023-ondataservice.patch
 
   65+diff --git a/Makefile b/Makefile
 
   66+index 8ce6dc5..cf3b410 100644
 
   69+@@ -224,7 +224,7 @@ rpm:
 
   71+ # This is quite ugly but at least it works
 
   73+-SUBDIRS := arprefresh bmf dot_draw dyn_gw dyn_gw_plain filtergw httpinfo info jsoninfo mdns mini nameservice netjson poprouting p2pd pgraph pud quagga secure sgwdynspeed txtinfo watchdog
 
   74++SUBDIRS := arprefresh bmf dot_draw dyn_gw dyn_gw_plain filtergw httpinfo info jsoninfo mdns mini nameservice netjson poprouting p2pd pgraph pud quagga secure sgwdynspeed txtinfo watchdog ondataservice ondataservice_light
 
   77+ SUBDIRS := dot_draw httpinfo info jsoninfo mini netjson pgraph secure txtinfo
 
   78+@@ -449,6 +449,29 @@ watchdog_install:
 
   80+       $(MAKECMDPREFIX)$(MAKECMD) -C lib/watchdog DESTDIR=$(DESTDIR) uninstall
 
   83++      $(MAKECMDPREFIX)$(MAKECMD) -C lib/ondataservice
 
   86++      $(MAKECMDPREFIX)$(MAKECMD) -C lib/ondataservice clean
 
   88++ondataservice_install:
 
   89++      $(MAKECMDPREFIX)$(MAKECMD) -C lib/ondataservice DESTDIR=$(DESTDIR) install
 
   91++ondataservice_uninstall:
 
   92++      $(MAKECMDPREFIX)$(MAKECMD) -C lib/ondataservice DESTDIR=$(DESTDIR) uninstall
 
   95++      $(MAKECMDPREFIX)$(MAKECMD) -C lib/ondataservice_light
 
   97++ondataservice_light_clean:
 
   98++      $(MAKECMDPREFIX)$(MAKECMD) -C lib/ondataservice_light clean
 
  100++ondataservice_light_install:
 
  101++      $(MAKECMDPREFIX)$(MAKECMD) -C lib/ondataservice_light DESTDIR=$(DESTDIR) install
 
  103++ondataservice_light_uninstall:
 
  104++      $(MAKECMDPREFIX)$(MAKECMD) -C lib/ondataservice_light DESTDIR=$(DESTDIR) uninstall
 
  106+ build_all:    all switch libs
 
  107+ install_all:  install install_libs
 
  108+diff --git a/lib/ondataservice/Makefile b/lib/ondataservice/Makefile
 
  110+index 0000000..951ed28
 
  112++++ b/lib/ondataservice/Makefile
 
  114++# The olsr.org Optimized Link-State Routing daemon(olsrd)
 
  115++# Copyright (c) 2004, Andreas Tonnesen(andreto@olsr.org)
 
  116++# All rights reserved.
 
  118++# Redistribution and use in source and binary forms, with or without
 
  119++# modification, are permitted provided that the following conditions
 
  122++# * Redistributions of source code must retain the above copyright
 
  123++#   notice, this list of conditions and the following disclaimer.
 
  124++# * Redistributions in binary form must reproduce the above copyright
 
  125++#   notice, this list of conditions and the following disclaimer in
 
  126++#   the documentation and/or other materials provided with the
 
  128++# * Neither the name of olsr.org, olsrd nor the names of its
 
  129++#   contributors may be used to endorse or promote products derived
 
  130++#   from this software without specific prior written permission.
 
  132++# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 
  133++# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 
  134++# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 
  135++# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 
  136++# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 
  137++# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 
  138++# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 
  139++# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 
  140++# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 
  141++# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 
  142++# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 
  143++# POSSIBILITY OF SUCH DAMAGE.
 
  145++# Visit http://www.olsr.org for more information.
 
  147++# If you find this software useful feel free to make a donation
 
  148++# to the project. For more information see the website or contact
 
  149++# the copyright holders.
 
  153++PLUGIN_NAME = olsrd_ondataservice
 
  154++# dont change version here for backward-compatible changes,
 
  155++# it will change the library name and won't load with the
 
  156++# olsrd-config already existing on the device
 
  162++include $(TOPDIR)/Makefile.inc
 
  165++default_target install clean:
 
  166++  @echo "**** We use the regex library here. Does Win32 has something like this?"
 
  168++ifeq ($(OS),android)
 
  169++# On Android Google forgot to include regex engine code for Froyo version (but also there was
 
  170++# no support in older versions for it) so we have here this missing code.
 
  171++# http://groups.google.com/group/android-ndk/browse_thread/thread/5ea6f0650f0e3fc
 
  172++SRCS +=     $(wildcard $(TOPDIR)/android/regex/reg*.c)
 
  173++HDRS +=     $(wildcard $(TOPDIR)/android/regex/*.h)
 
  174++CFLAGS += -D__POSIX_VISIBLE
 
  177++default_target: $(PLUGIN_FULLNAME)
 
  179++$(PLUGIN_FULLNAME): $(OBJS) version-script.txt
 
  181++      @$(CC) $(LDFLAGS) -o $(PLUGIN_FULLNAME) $(OBJS) $(LIBS)
 
  183++install:  $(PLUGIN_FULLNAME)
 
  184++      $(STRIP) $(PLUGIN_FULLNAME)
 
  191++      rm -f $(OBJS) $(SRCS:%.c=%.d) $(PLUGIN_FULLNAME)
 
  193+diff --git a/lib/ondataservice/README_ONDATASERVICE b/lib/ondataservice/README_ONDATASERVICE
 
  195+index 0000000..0aae865
 
  197++++ b/lib/ondataservice/README_ONDATASERVICE
 
  199++---------------------------------------------------------------------
 
  200++ONDATASERVICE PLUGIN FOR OLSRD
 
  201++by Rene Ejury <opennet@absorb.it>
 
  202++based on and copied from:
 
  203++NAMESERVICE PLUGIN FOR OLSRD
 
  204++by Bruno Randolf <bruno.randolf@4g-systems.biz>
 
  205++---------------------------------------------------------------------
 
  206++  full version, can receive data but requires sqlite3-library
 
  208++---------------------------------------------------------------------
 
  209++PLUGIN PARAMETERS (PlParam)
 
  210++---------------------------------------------------------------------
 
  212++PlParam "interval" "SEC"
 
  213++  interval for sending the DATABASE in seconds.
 
  214++  (default: 10800 - 3 hours)
 
  216++PlParam "inc_interval" "SEC"
 
  217++    interval for continously sending TABLES from DATABASE in seconds.
 
  218++    (default: 5 seconds)
 
  220++PlParam "cleanup_interval" "SEC"
 
  221++    Interval how often DATABASE should be checked for old DATASETS.
 
  222++    (default: 1800 - 0.5 hours)
 
  224++PlParam "timeout" "SEC"
 
  225++  validity time for received NAME messages in seconds.
 
  226++    (how long received data stays in the database)
 
  227++  (default: 21600 - 6 hours)
 
  229++PlParam "vtime" "SEC"
 
  230++    validity time for sended message-packages in seconds.
 
  231++    (how long this message-data is forwarded through the net)
 
  232++    (default: 300 - 5 mins)
 
  234++PlParam "database" "/path/to/database"
 
  235++        Path to the database
 
  237++PlParam "dbcreatescript" "/path/to/dbcreatescript"
 
  238++        Path to some executable script to create the database. This will
 
  239++        be called anytime the database can't be opened.
 
  240++        script will be called with database-path (see PlParam above)
 
  242++        (default not set, database is not created if not existent)
 
  244++PlParam "dberrorscript" "/path/to/dberrorscript"
 
  245++        Path to some executable script to check if the database is ok and
 
  246++        create the database in case of error. This will be called anytime
 
  247++        some data can't be written to the database.
 
  248++        script will be called with database-path (see PlParam above)
 
  250++        (default not set, database is not re-created if there are problems)
 
  252++PlParam "receive" "false|true"
 
  253++        Set to true if you like to receive and store the values.
 
  254++        Otherwise the values from other Nodes are ignored.
 
  255++        (default: false - not stored)
 
  257++PlParam "spreadall" "false|true"
 
  258++        Set to true if you like to spread all data from the database.
 
  259++        (default: false - only data for own mainip is spreaded)
 
  261++---------------------------------------------------------------------
 
  263++---------------------------------------------------------------------
 
  265++add in /etc/olsrd.conf:
 
  267++LoadPlugin "olsrd_ondataservice.so.0.1"
 
  269++    PlParam "interval"  "120"
 
  270++    PlParam "timeout"   "300"
 
  271++    PlParam "database"  "/tmp/database"
 
  273+diff --git a/lib/ondataservice/SAMPLE_DBCREATESCRIPT.sh b/lib/ondataservice/SAMPLE_DBCREATESCRIPT.sh
 
  275+index 0000000..22dd4e9
 
  277++++ b/lib/ondataservice/SAMPLE_DBCREATESCRIPT.sh
 
  280++SQL_STRING="CREATE TABLE nodes
 
  281++    (originator text, mainip text, sys_ver text, sys_board text, sys_cpu text, sys_mem int, sys_uptime text,
 
  282++    sys_load text, sys_free int, sys_watchdog bool, sys_os_type text,
 
  283++    sys_os_name text, sys_os_rel text, sys_os_ver text, sys_os_arc text,
 
  284++    sys_os_insttime int, on_core_ver text, on_core_insttime int, on_packages text,
 
  285++    on_id text, on_olsrd_status text, on_olsrd_mainip text,
 
  286++    on_wifidog_status bool, on_wifidog_id text, on_vpn_cn text, on_vpn_status bool,
 
  287++    on_vpn_gw text, on_vpn_autosearch bool, on_vpn_sort text, on_vpn_gws text, on_vpn_blist text,
 
  288++    on_ugw_status bool, on_ugw_enabled bool, on_ugw_possible bool, on_ugw_tunnel bool,
 
  289++    on_ugw_connected text, on_ugw_presetips text, on_ugw_presetnames text,
 
  290++    on_old_autoadapttxpwr text, on_old_remoteconf text,
 
  291++    db_time text, db_epoch int, db_ver text, db_update int, CONSTRAINT key_nodes PRIMARY KEY (mainip) ON CONFLICT REPLACE);
 
  293++    CREATE TABLE ifaces
 
  294++    (originator text, mainip text, if_name text, if_type_bridge text, if_type_bridgedif bool, if_hwaddr text,
 
  295++    ip_label text, ip_addr text, ip_broadcast text,
 
  296++    on_networks text, on_zones text, on_olsr bool,
 
  297++    dhcp_start text, dhcp_limit text, dhcp_leasetime text, dhcp_fwd text,
 
  298++    ifstat_collisions int, ifstat_rx_compressed int, ifstat_rx_errors int,
 
  299++    ifstat_rx_length_errors int, ifstat_rx_packets int, ifstat_tx_carrier_errors int,
 
  300++    ifstat_tx_errors int, ifstat_tx_packets int, ifstat_multicast int,
 
  301++    ifstat_rx_crc_errors int, ifstat_rx_fifo_errors int, ifstat_rx_missed_errors int,
 
  302++    ifstat_tx_aborted_errors int, ifstat_tx_compressed int, ifstat_tx_fifo_errors int,
 
  303++    ifstat_tx_window_errors int, ifstat_rx_bytes int, ifstat_rx_dropped int,
 
  304++    ifstat_rx_frame_errors int, ifstat_rx_over_errors int, ifstat_tx_bytes int,
 
  305++    ifstat_tx_dropped int, ifstat_tx_heartbeat_errors int,
 
  306++    wlan_essid text, wlan_apmac text, wlan_type text, wlan_hwmode text, wlan_mode text,
 
  307++    wlan_channel text, wlan_freq text, wlan_txpower text, wlan_signal text, wlan_noise text,
 
  308++    wlan_bitrate text, wlan_crypt text, wlan_vaps text,
 
  309++    db_ver text, db_update int, CONSTRAINT key_ifaces PRIMARY KEY (mainip, if_name) ON CONFLICT REPLACE);"
 
  311++sqlite3 -batch $1 "$SQL_STRING"
 
  313+diff --git a/lib/ondataservice/SAMPLE_DBERRORSCRIPT.sh b/lib/ondataservice/SAMPLE_DBERRORSCRIPT.sh
 
  315+index 0000000..cd81e77
 
  317++++ b/lib/ondataservice/SAMPLE_DBERRORSCRIPT.sh
 
  320++SQL_STRING="CREATE TABLE nodes
 
  321++    (originator text, mainip text, sys_ver text, sys_board text, sys_cpu text, sys_mem int, sys_uptime text,
 
  322++    sys_load text, sys_free int, sys_watchdog bool, sys_os_type text,
 
  323++    sys_os_name text, sys_os_rel text, sys_os_ver text, sys_os_arc text,
 
  324++    sys_os_insttime int, on_core_ver text, on_core_insttime int, on_packages text,
 
  325++    on_id text, on_olsrd_status text, on_olsrd_mainip text,
 
  326++    on_wifidog_status bool, on_wifidog_id text, on_vpn_cn text, on_vpn_status bool,
 
  327++    on_vpn_gw text, on_vpn_autosearch bool, on_vpn_sort text, on_vpn_gws text, on_vpn_blist text,
 
  328++    on_ugw_status bool, on_ugw_enabled bool, on_ugw_possible bool, on_ugw_tunnel bool,
 
  329++    on_ugw_connected text, on_ugw_presetips text, on_ugw_presetnames text,
 
  330++    on_old_autoadapttxpwr text, on_old_remoteconf text,
 
  331++    db_time text, db_epoch int, db_ver text, db_update int, CONSTRAINT key_nodes PRIMARY KEY (mainip) ON CONFLICT REPLACE);
 
  333++    CREATE TABLE ifaces
 
  334++    (originator text, mainip text, if_name text, if_type_bridge text, if_type_bridgedif bool, if_hwaddr text,
 
  335++    ip_label text, ip_addr text, ip_broadcast text,
 
  336++    on_networks text, on_zones text, on_olsr bool,
 
  337++    dhcp_start text, dhcp_limit text, dhcp_leasetime text, dhcp_fwd text,
 
  338++    ifstat_collisions int, ifstat_rx_compressed int, ifstat_rx_errors int,
 
  339++    ifstat_rx_length_errors int, ifstat_rx_packets int, ifstat_tx_carrier_errors int,
 
  340++    ifstat_tx_errors int, ifstat_tx_packets int, ifstat_multicast int,
 
  341++    ifstat_rx_crc_errors int, ifstat_rx_fifo_errors int, ifstat_rx_missed_errors int,
 
  342++    ifstat_tx_aborted_errors int, ifstat_tx_compressed int, ifstat_tx_fifo_errors int,
 
  343++    ifstat_tx_window_errors int, ifstat_rx_bytes int, ifstat_rx_dropped int,
 
  344++    ifstat_rx_frame_errors int, ifstat_rx_over_errors int, ifstat_tx_bytes int,
 
  345++    ifstat_tx_dropped int, ifstat_tx_heartbeat_errors int,
 
  346++    wlan_essid text, wlan_apmac text, wlan_type text, wlan_hwmode text, wlan_mode text,
 
  347++    wlan_channel text, wlan_freq text, wlan_txpower text, wlan_signal text, wlan_noise text,
 
  348++    wlan_bitrate text, wlan_crypt text, wlan_vaps text,
 
  349++    db_ver text, db_update int, CONSTRAINT key_ifaces PRIMARY KEY (mainip, if_name) ON CONFLICT REPLACE);"
 
  351++ifaces_columns=$(sqlite3 /tmp/ondatabase.sqlite "PRAGMA table_info(ifaces);" | wc -l)
 
  352++nodes_columns=$(sqlite3 /tmp/ondatabase.sqlite "PRAGMA table_info(nodes);" | wc -l)
 
  354++if [ "$ifaces_columns" != "54" ] || [ "$nodes_columns" != "44" ]; then
 
  355++  sqlite3 -batch $1 "$SQL_STRING"
 
  358+diff --git a/lib/ondataservice/src/compat.c b/lib/ondataservice/src/compat.c
 
  360+index 0000000..4d639be
 
  362++++ b/lib/ondataservice/src/compat.c
 
  366++#if !defined(__linux__) && !defined(__GLIBC__)
 
  370++/* strndup() is a GNU extention */
 
  372++strndup(const char *ptr, size_t size)
 
  374++  size_t len = strlen(ptr);
 
  380++  ret = malloc(len + 1);
 
  385++  memcpy(ret, ptr, len);
 
  395++ * c-basic-offset: 2
 
  396++ * indent-tabs-mode: nil
 
  399+diff --git a/lib/ondataservice/src/compat.h b/lib/ondataservice/src/compat.h
 
  401+index 0000000..c607c91
 
  403++++ b/lib/ondataservice/src/compat.h
 
  405++#ifndef _NAMESERVICE_COMPAT
 
  406++#define _NAMESERVICE_COMPAT
 
  408++#include <sys/types.h>
 
  410++#if !defined(__linux__) && !defined(__GLIBC__)
 
  411++char *strndup(const char *ptr, size_t size);
 
  418++ * c-basic-offset: 2
 
  419++ * indent-tabs-mode: nil
 
  422+diff --git a/lib/ondataservice/src/crc16.c b/lib/ondataservice/src/crc16.c
 
  424+index 0000000..dc877ca
 
  426++++ b/lib/ondataservice/src/crc16.c
 
  431++// ------------ http://stackoverflow.com/questions/3853670/are-there-any-free-crc-libraries-that-covers-a-lot-of-the-crc-algorithms
 
  433++/******************************************/
 
  434++/*  CRC table for polynomial 0xA001 CCITT */
 
  435++/******************************************/
 
  437++#define CRC16(crc,c) crc = (crc >> 8) ^ crctab[(crc ^ c) & 0xff]
 
  439++const u_int16_t crctab[256] = {
 
  440++    0x0000, 0xc0c1, 0xc181, 0x0140, 0xc301, 0x03c0, 0x0280, 0xc241,
 
  441++    0xc601, 0x06c0, 0x0780, 0xc741, 0x0500, 0xc5c1, 0xc481, 0x0440,
 
  442++    0xcc01, 0x0cc0, 0x0d80, 0xcd41, 0x0f00, 0xcfc1, 0xce81, 0x0e40,
 
  443++    0x0a00, 0xcac1, 0xcb81, 0x0b40, 0xc901, 0x09c0, 0x0880, 0xc841,
 
  444++    0xd801, 0x18c0, 0x1980, 0xd941, 0x1b00, 0xdbc1, 0xda81, 0x1a40,
 
  445++    0x1e00, 0xdec1, 0xdf81, 0x1f40, 0xdd01, 0x1dc0, 0x1c80, 0xdc41,
 
  446++    0x1400, 0xd4c1, 0xd581, 0x1540, 0xd701, 0x17c0, 0x1680, 0xd641,
 
  447++    0xd201, 0x12c0, 0x1380, 0xd341, 0x1100, 0xd1c1, 0xd081, 0x1040,
 
  448++    0xf001, 0x30c0, 0x3180, 0xf141, 0x3300, 0xf3c1, 0xf281, 0x3240,
 
  449++    0x3600, 0xf6c1, 0xf781, 0x3740, 0xf501, 0x35c0, 0x3480, 0xf441,
 
  450++    0x3c00, 0xfcc1, 0xfd81, 0x3d40, 0xff01, 0x3fc0, 0x3e80, 0xfe41,
 
  451++    0xfa01, 0x3ac0, 0x3b80, 0xfb41, 0x3900, 0xf9c1, 0xf881, 0x3840,
 
  452++    0x2800, 0xe8c1, 0xe981, 0x2940, 0xeb01, 0x2bc0, 0x2a80, 0xea41,
 
  453++    0xee01, 0x2ec0, 0x2f80, 0xef41, 0x2d00, 0xedc1, 0xec81, 0x2c40,
 
  454++    0xe401, 0x24c0, 0x2580, 0xe541, 0x2700, 0xe7c1, 0xe681, 0x2640,
 
  455++    0x2200, 0xe2c1, 0xe381, 0x2340, 0xe101, 0x21c0, 0x2080, 0xe041,
 
  456++    0xa001, 0x60c0, 0x6180, 0xa141, 0x6300, 0xa3c1, 0xa281, 0x6240,
 
  457++    0x6600, 0xa6c1, 0xa781, 0x6740, 0xa501, 0x65c0, 0x6480, 0xa441,
 
  458++    0x6c00, 0xacc1, 0xad81, 0x6d40, 0xaf01, 0x6fc0, 0x6e80, 0xae41,
 
  459++    0xaa01, 0x6ac0, 0x6b80, 0xab41, 0x6900, 0xa9c1, 0xa881, 0x6840,
 
  460++    0x7800, 0xb8c1, 0xb981, 0x7940, 0xbb01, 0x7bc0, 0x7a80, 0xba41,
 
  461++    0xbe01, 0x7ec0, 0x7f80, 0xbf41, 0x7d00, 0xbdc1, 0xbc81, 0x7c40,
 
  462++    0xb401, 0x74c0, 0x7580, 0xb541, 0x7700, 0xb7c1, 0xb681, 0x7640,
 
  463++    0x7200, 0xb2c1, 0xb381, 0x7340, 0xb101, 0x71c0, 0x7080, 0xb041,
 
  464++    0x5000, 0x90c1, 0x9181, 0x5140, 0x9301, 0x53c0, 0x5280, 0x9241,
 
  465++    0x9601, 0x56c0, 0x5780, 0x9741, 0x5500, 0x95c1, 0x9481, 0x5440,
 
  466++    0x9c01, 0x5cc0, 0x5d80, 0x9d41, 0x5f00, 0x9fc1, 0x9e81, 0x5e40,
 
  467++    0x5a00, 0x9ac1, 0x9b81, 0x5b40, 0x9901, 0x59c0, 0x5880, 0x9841,
 
  468++    0x8801, 0x48c0, 0x4980, 0x8941, 0x4b00, 0x8bc1, 0x8a81, 0x4a40,
 
  469++    0x4e00, 0x8ec1, 0x8f81, 0x4f40, 0x8d01, 0x4dc0, 0x4c80, 0x8c41,
 
  470++    0x4400, 0x84c1, 0x8581, 0x4540, 0x8701, 0x47c0, 0x4680, 0x8641,
 
  471++    0x8201, 0x42c0, 0x4380, 0x8341, 0x4100, 0x81c1, 0x8081, 0x4040
 
  474++//=========================================================================
 
  475++//  Description:   Calculate a CRC on a buffer
 
  476++//  Parameters:    buffer - address of buffer
 
  477++//                 length - length of buffer
 
  479++//=========================================================================
 
  480++u_int16_t crcCalculate(char *buffer, unsigned int length)
 
  484++    for (; length; --length) {
 
  485++        CRC16(Crc, *buffer++);
 
  490+diff --git a/lib/ondataservice/src/crc16.h b/lib/ondataservice/src/crc16.h
 
  492+index 0000000..729d784
 
  494++++ b/lib/ondataservice/src/crc16.h
 
  497++// copied from http://stackoverflow.com/questions/3853670/are-there-any-free-crc-libraries-that-covers-a-lot-of-the-crc-algorithms
 
  499++#include <sys/types.h>
 
  501++u_int16_t crcCalculate(char *buffer, unsigned int length);
 
  503+diff --git a/lib/ondataservice/src/olsrd_plugin.c b/lib/ondataservice/src/olsrd_plugin.c
 
  505+index 0000000..c6989c5
 
  507++++ b/lib/ondataservice/src/olsrd_plugin.c
 
  511++ * Copyright (c) 2005, Bruno Randolf <bruno.randolf@4g-systems.biz>
 
  512++ * Copyright (c) 2004, Andreas Tonnesen(andreto-at-olsr.org)
 
  513++ * All rights reserved.
 
  515++ * Redistribution and use in source and binary forms, with or without
 
  516++ * modification, are permitted provided that the following conditions
 
  519++ * * Redistributions of source code must retain the above copyright notice,
 
  520++ *   this list of conditions and the following disclaimer.
 
  521++ * * Redistributions in binary form must reproduce the above copyright notice,
 
  522++ *   this list of conditions and the following disclaimer in the documentation
 
  523++ *   and/or other materials provided with the distribution.
 
  524++ * * Neither the name of the UniK olsr daemon nor the names of its contributors
 
  525++ *   may be used to endorse or promote products derived from this software
 
  526++ *   without specific prior written permission.
 
  528++ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 
  529++ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 
  530++ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 
  531++ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 
  532++ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 
  533++ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 
  534++ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 
  535++ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
 
  536++ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 
  537++ * OF THE POSSIBILITY OF SUCH DAMAGE.
 
  542++ * Dynamic linked library for olsr.org olsrd
 
  548++#include "olsrd_plugin.h"
 
  549++#include "ondataservice.h"
 
  551++#define MOD_DESC PLUGIN_NAME " " PLUGIN_VERSION
 
  552++#define PLUGIN_INTERFACE_VERSION 5
 
  554++static void __attribute__ ((constructor)) my_init(void);
 
  556++static void __attribute__ ((destructor)) my_fini(void);
 
  559++olsrd_plugin_interface_version(void)
 
  561++  return PLUGIN_INTERFACE_VERSION;
 
  565++olsrd_plugin_init(void)
 
  567++  return ondata_init();
 
  573++  /* Print plugin info to stdout */
 
  574++  printf("%s\n", MOD_DESC);
 
  576++  ondata_constructor();
 
  584++  ondata_destructor();
 
  589++ * c-basic-offset: 2
 
  590++ * indent-tabs-mode: nil
 
  593+diff --git a/lib/ondataservice/src/ondataservice.c b/lib/ondataservice/src/ondataservice.c
 
  595+index 0000000..c1e1076
 
  597++++ b/lib/ondataservice/src/ondataservice.c
 
  601++ * Copyright (c) 2011, Rene Ejury <opennet@absorb.it>
 
  602++ * Copyright (c) 2006, Jens Nachtigall <nachtigall@web.de>
 
  603++ * Copyright (c) 2005, Bruno Randolf <bruno.randolf@4g-systems.biz>
 
  604++ * Copyright (c) 2004, Andreas Tonnesen(andreto-at-olsr.org)
 
  605++ * Copyright (c) 2007, Sven-Ola <sven-ola@gmx.de>
 
  606++ * All rights reserved.
 
  608++ * Redistribution and use in source and binary forms, with or without
 
  609++ * modification, are permitted provided that the following conditions
 
  612++ * * Redistributions of source code must retain the above copyright notice,
 
  613++ *   this list of conditions and the following disclaimer.
 
  614++ * * Redistributions in binary form must reproduce the above copyright notice,
 
  615++ *   this list of conditions and the following disclaimer in the documentation
 
  616++ *   and/or other materials provided with the distribution.
 
  617++ * * Neither the name of the UniK olsr daemon nor the names of its contributors
 
  618++ *   may be used to endorse or promote products derived from this software
 
  619++ *   without specific prior written permission.
 
  621++ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 
  622++ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 
  623++ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 
  624++ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 
  625++ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 
  626++ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 
  627++ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 
  628++ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
 
  629++ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 
  630++ * OF THE POSSIBILITY OF SUCH DAMAGE.
 
  635++ * Dynamic linked library for UniK OLSRd
 
  638++#define _GNU_SOURCE 1
 
  645++#include <sys/types.h>
 
  646++#include <sys/stat.h>
 
  650++#include <sqlite3.h>
 
  653++#include "net_olsr.h"
 
  656++#include "plugin_util.h"
 
  657++#include "ondataservice.h"
 
  661++const char *DATABASE_TABLES[2] = {"nodes", "ifaces"};
 
  662++const int unsigned numberOfTables = 2;
 
  664++/* config parameters */
 
  665++static int my_interval = EMISSION_INTERVAL;
 
  666++static int my_inc_interval = EMISSION_INC_INTERVAL;
 
  667++static int my_cleanup_interval = CLEANUP_INTERVAL;  // how often database will be cleaned of outdated data
 
  668++static int my_timeout = ONDATA_TIMEOUT;          // how long the data stays valid
 
  669++static int my_vtime = ONDATA_VALID_TIME;            // how long the data will be spread trough the net
 
  670++static char my_database[MAX_FILE + 1];
 
  671++static char my_dbcreatescript[MAX_FILE + 1];
 
  672++static char my_dberrorscript[MAX_FILE + 1];
 
  673++static bool my_receive = false;
 
  674++static bool my_spreadall = false;
 
  676++/* periodic message generation */
 
  677++struct timer_entry *msg_gen_timer = NULL;
 
  678++struct timer_entry *db_cleanup_timer = NULL;
 
  681++ * do initialization
 
  684++ondata_constructor(void)
 
  689++  GetWindowsDirectory(my_database, MAX_FILE - 12);
 
  691++  len = strlen(my_database);
 
  692++  if (my_database[len - 1] != '\\')
 
  693++    strscat(my_database, "\\", sizeof(my_database));
 
  694++  strscat(my_database, DATABASE_FILE, sizeof(my_database));
 
  696++  GetWindowsDirectory(my_dbcreatescript, MAX_FILE - 12);
 
  698++  len = strlen(my_dbcreatescript);
 
  699++  if (my_dbcreatescript[len - 1] != '\\')
 
  700++    strscat(my_dbcreatescript, "\\", sizeof(my_dbcreatescript));
 
  701++  strscat(my_dbcreatescript, "", sizeof(my_dbcreatescript));
 
  703++  strscpy(my_database, DATABASE_FILE, sizeof(my_database));
 
  704++  strscpy(my_dbcreatescript, "", sizeof(my_dbcreatescript));
 
  711++static const struct olsrd_plugin_parameters plugin_parameters[] = {
 
  712++  { .name = "interval",           .set_plugin_parameter = &set_plugin_int,         .data = &my_interval },
 
  713++  { .name = "inc_interval",            .set_plugin_parameter = &set_plugin_int,         .data = &my_inc_interval },
 
  714++  { .name = "cleanup_interval",            .set_plugin_parameter = &set_plugin_int,         .data = &my_cleanup_interval },
 
  715++  { .name = "timeout",            .set_plugin_parameter = &set_plugin_int,         .data = &my_timeout },
 
  716++  { .name = "database",          .set_plugin_parameter = &set_plugin_string,      .data = &my_database,          .addon = {sizeof(my_database)} },
 
  717++  { .name = "dbcreatescript",          .set_plugin_parameter = &set_plugin_string,      .data = &my_dbcreatescript,          .addon = {sizeof(my_dbcreatescript)} },
 
  718++  { .name = "dberrorscript",          .set_plugin_parameter = &set_plugin_string,      .data = &my_dberrorscript,          .addon = {sizeof(my_dberrorscript)} },
 
  719++  { .name = "receive",            .set_plugin_parameter = &set_plugin_boolean,     .data = &my_receive },
 
  720++  { .name = "spreadall",            .set_plugin_parameter = &set_plugin_boolean,     .data = &my_spreadall },
 
  721++  { .name = "vtime",            .set_plugin_parameter = &set_plugin_int,     .data = &my_vtime },
 
  726++olsrd_get_plugin_parameters(const struct olsrd_plugin_parameters **params, int *size)
 
  728++  *params = plugin_parameters;
 
  729++  *size = sizeof(plugin_parameters) / sizeof(*plugin_parameters);
 
  733++ * last initialization
 
  735++ * we have to do this here because some things like main_addr
 
  736++ * or the dns suffix (for validation) are not known before
 
  738++ * this is beause of the order in which the plugin is initialized
 
  739++ * by the plugin loader:
 
  740++ *   - first the parameters are sent
 
  741++ *   - then register_olsr_data() from olsrd_plugin.c is called
 
  742++ *     which sets up main_addr and some other variables
 
  743++ *   - register_olsr_data() then then finally calls this function
 
  748++  /* register functions with olsrd */
 
  749++  if (my_receive) olsr_parser_add_function(&olsr_parser, PARSER_TYPE);
 
  751++  /* periodic message generation */
 
  752++  msg_gen_timer = olsr_start_timer(my_interval * MSEC_PER_SEC, EMISSION_JITTER, OLSR_TIMER_PERIODIC, &olsr_ondatasvc_gen, NULL, 0);
 
  754++  /* periodic database cleanup generation */
 
  755++  if (my_receive) db_cleanup_timer = olsr_start_timer(my_cleanup_interval * MSEC_PER_SEC, EMISSION_JITTER, OLSR_TIMER_PERIODIC, &olsr_ondataservice_expire_db_timer, NULL, 0);
 
  761++ * called at unload: free everything
 
  763++ * XXX: should I delete the hosts/services/resolv.conf files on exit?
 
  766++ondata_destructor(void)
 
  768++  olsr_stop_timer(msg_gen_timer);
 
  770++  if (my_receive) olsr_stop_timer(db_cleanup_timer);
 
  774++open_database(sqlite3 **localdb)
 
  776++  int unsigned rc = sqlite3_open_v2(my_database, localdb, SQLITE_OPEN_READWRITE, NULL);
 
  777++  if(rc != SQLITE_OK && strlen(my_dbcreatescript) != 0){
 
  779++    fprintf(stderr, "Can't open database, trying to (re)create database: %s\n", my_dbcreatescript);
 
  780++    asprintf(&buf,"%s %s", my_dbcreatescript, my_database);
 
  783++    rc = sqlite3_open_v2(my_database, localdb, SQLITE_OPEN_READWRITE, NULL);
 
  785++  if(rc != SQLITE_OK && strlen(my_dberrorscript) != 0){
 
  787++    fprintf(stderr, "Can't open database, running database-error script: %s\n", my_dberrorscript);
 
  788++    asprintf(&buf,"%s %s", my_dberrorscript, my_database);
 
  791++    rc = sqlite3_open_v2(my_database, localdb, SQLITE_OPEN_READWRITE, NULL);
 
  798++ * wrapper for sqlite3_prepare_v2, calls error handle script on error
 
  801++local_sqlite3_prepare_v2(
 
  802++  sqlite3 *db,            /* Database handle */
 
  803++  const char *zSql,       /* SQL statement, UTF-8 encoded */
 
  804++  int nByte,              /* Maximum length of zSql in bytes. */
 
  805++  sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
 
  806++  const char **pzTail     /* OUT: Pointer to unused portion of zSql */
 
  810++  rc = sqlite3_prepare_v2(db, zSql, nByte, ppStmt, pzTail);
 
  811++  if(rc != SQLITE_OK && strlen(my_dberrorscript) != 0){
 
  813++    fprintf(stderr, "running database-error script: %s\n", my_dberrorscript);
 
  814++    asprintf(&buf,"%s %s", my_dberrorscript, my_database);
 
  817++    rc = sqlite3_prepare_v2(db, zSql, nByte, ppStmt, pzTail);
 
  823++ * Callback for the db validity timer.
 
  826++olsr_ondataservice_expire_db_timer(void *foo __attribute__ ((unused)))
 
  829++  sqlite3_stmt *localppStmt;
 
  831++  const char *pzTail;           /* OUT of sqlite3_prepare_v2: Pointer to unused portion of zSql */
 
  832++  const char *SQLframe = "DELETE FROM %s WHERE (originator != '' AND mainip != '%s' AND db_update < %lu );";
 
  833++  struct ipaddr_str main_addr;
 
  834++  const char *mainip;
 
  835++  int unsigned currentTable = 0, rc;
 
  836++  long unsigned min_update_time;
 
  838++  min_update_time = time(NULL) - my_timeout;
 
  839++  mainip = olsr_ip_to_string(&main_addr, &olsr_cnf->main_addr);
 
  841++  rc = open_database(&localdb);
 
  842++  if( rc == SQLITE_OK ){
 
  843++    while (currentTable < numberOfTables) {
 
  845++      // build Database statement / assumption that time will not be bigger than 20chars long
 
  846++      localzSql = olsr_malloc(strlen(SQLframe) + strlen(mainip) + strlen(DATABASE_TABLES[currentTable]) + 20 + 1, "update_ondata_entry: space for SQL query");
 
  847++      sprintf(localzSql, SQLframe, DATABASE_TABLES[currentTable], mainip, min_update_time);
 
  849++      // apply statement to database
 
  850++      // use 1500 as max MTU and therefore as max SQL size (which is not quite accurate)
 
  851++      rc = local_sqlite3_prepare_v2(localdb, localzSql, 1500, &localppStmt, &pzTail);
 
  852++      if( rc == SQLITE_OK ){
 
  853++        sqlite3_step(localppStmt);
 
  854++        sqlite3_finalize(localppStmt);
 
  855++        OLSR_PRINTF(5, "ONDATA PLUGIN: Database cleaned: %s\n", localzSql);
 
  857++      else fprintf(stderr, "SQL error: %s\n", sqlite3_errmsg(localdb));
 
  862++  else fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(localdb));
 
  864++  sqlite3_close(localdb);
 
  868++ * Scheduled event: generate and send ONDATA packet
 
  871++olsr_ondatasvc_gen(void *foo __attribute__ ((unused)))
 
  873++  /* send buffer: huge */
 
  874++  char buffer[10240];
 
  875++  union olsr_message *message = (union olsr_message *)buffer;
 
  876++  struct interface_olsr *ifn;
 
  880++  if (olsr_cnf->ip_version == AF_INET) {
 
  882++    message->v4.olsr_msgtype = MESSAGE_TYPE;
 
  883++    message->v4.olsr_vtime = reltime_to_me((double)my_vtime * MSEC_PER_SEC);
 
  884++    memcpy(&message->v4.originator, &olsr_cnf->main_addr, olsr_cnf->ipsize);
 
  885++    message->v4.ttl = MAX_TTL;
 
  886++    message->v4.hopcnt = 0;
 
  887++    message->v4.seqno = htons(get_msg_seqno());
 
  889++    ondatasize = encap_ondatamsg((struct ondatamsg *)ARM_NOWARN_ALIGN(&message->v4.message));
 
  890++    if (!ondatasize) return;
 
  891++    ondatasize = ondatasize + sizeof(struct olsrmsg);
 
  892++    message->v4.olsr_msgsize = htons(ondatasize);
 
  895++    message->v6.olsr_msgtype = MESSAGE_TYPE;
 
  896++    message->v6.olsr_vtime = reltime_to_me((double)my_vtime * MSEC_PER_SEC);
 
  897++    memcpy(&message->v6.originator, &olsr_cnf->main_addr, olsr_cnf->ipsize);
 
  898++    message->v6.ttl = MAX_TTL;
 
  899++    message->v6.hopcnt = 0;
 
  900++    message->v6.seqno = htons(get_msg_seqno());
 
  902++    ondatasize = encap_ondatamsg((struct ondatamsg *)ARM_NOWARN_ALIGN(&message->v6.message));
 
  903++    if (!ondatasize) return;
 
  904++    ondatasize = ondatasize + sizeof(struct olsrmsg6);
 
  906++    message->v6.olsr_msgsize = htons(ondatasize);
 
  909++  /* looping trough interfaces */
 
  910++  for (ifn = ifnet; ifn; ifn = ifn->int_next) {
 
  911++    OLSR_PRINTF(3, "ONDATA PLUGIN: Generating packet - [%s]\n", ifn->int_name);
 
  913++    if (net_outbuffer_push(ifn, message, ondatasize) != ondatasize) {
 
  914++      /* send data and try again */
 
  916++      if (net_outbuffer_push(ifn, message, ondatasize) != ondatasize) {
 
  917++        OLSR_PRINTF(1, "ONDATA PLUGIN: could not send on interface: %s\n", ifn->int_name);
 
  924++ * Parse ondata olsr message of ONDATA type
 
  927++olsr_parser(union olsr_message *m, struct interface_olsr *in_if __attribute__ ((unused)), union olsr_ip_addr *ipaddr __attribute__ ((unused)))
 
  929++  struct ondatamsg *ondatamessage;
 
  930++  union olsr_ip_addr originator;
 
  933++  /* Fetch the originator of the messsage */
 
  934++  if (olsr_cnf->ip_version == AF_INET) {
 
  935++    memcpy(&originator, &m->v4.originator, olsr_cnf->ipsize);
 
  937++    memcpy(&originator, &m->v6.originator, olsr_cnf->ipsize);
 
  940++  /* Fetch the message based on IP version */
 
  941++  if (olsr_cnf->ip_version == AF_INET) {
 
  942++    size = ntohs(m->v4.olsr_msgsize);
 
  943++    ondatamessage = (struct ondatamsg *)ARM_NOWARN_ALIGN(&m->v4.message);
 
  945++    size = ntohs(m->v6.olsr_msgsize);
 
  946++    ondatamessage = (struct ondatamsg *)ARM_NOWARN_ALIGN(&m->v6.message);
 
  949++  /* Check if message originated from this node.
 
  950++     If so - back off */
 
  951++  if (ipequal(&originator, &olsr_cnf->main_addr))
 
  954++  update_ondata_entry(&originator, ondatamessage, size);
 
  955++  /* Forward the message */
 
  959++// Database Variables / should be kept over different calls, therefore global
 
  961++sqlite3_stmt *ppStmt;
 
  964++int unsigned currentTable = 0;
 
  966++bool table_open = 0;
 
  969++ * Encapsulate a ondata message into a packet.
 
  971++ * It assumed that there is enough space in the buffer to do this!
 
  973++ * Returns: the length of the message that was appended
 
  976++encap_ondatamsg(struct ondatamsg *msg)
 
  978++  const char *pzTail;           /* OUT of sqlite3_prepare_v2: Pointer to unused portion of zSql */
 
  979++  const char *SQLframe = "SELECT * FROM %s WHERE mainip = '%s';";
 
  980++  const char *SQLframeSpreadAll = "SELECT * FROM %s WHERE originator = '';";
 
  982++  struct ipaddr_str main_addr;
 
  983++  const char *mainip;
 
  987++  uint16_t messageLength = 0;
 
  989++  // open Database if this not a 'continued Transmission - and Database is already open'
 
  990++  mainip = olsr_ip_to_string(&main_addr, &olsr_cnf->main_addr);
 
  993++    OLSR_PRINTF(5, "ONDATA PLUGIN: opening database\n");
 
  996++    rc = open_database(&db);
 
  998++    if( rc == SQLITE_OK) db_open = 1;
 
 1000++      fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
 
 1001++      sqlite3_close(db); return 0;
 
 1005++  // if there is no Data available, search next Table with Data
 
 1006++  if (!table_open) {
 
 1007++    while (currentTable < numberOfTables) {
 
 1008++      OLSR_PRINTF(5, "ONDATA PLUGIN: using next table %s\n", DATABASE_TABLES[currentTable]);
 
 1009++      // build SQL-query
 
 1010++      if (!my_spreadall) {
 
 1011++        zSql = olsr_malloc(strlen(SQLframe) + strlen(DATABASE_TABLES[currentTable]) + strlen(mainip) + 1, "encap_ondatamsg: space for SQL query");
 
 1012++        sprintf(zSql, SQLframe, DATABASE_TABLES[currentTable], mainip);
 
 1015++        zSql = olsr_malloc(strlen(SQLframeSpreadAll) + strlen(DATABASE_TABLES[currentTable])+ 1, "encap_ondatamsg: space for SQL query");
 
 1016++        sprintf(zSql, SQLframeSpreadAll, DATABASE_TABLES[currentTable]);
 
 1019++      rc = local_sqlite3_prepare_v2(db, zSql, 100, &ppStmt, &pzTail);
 
 1020++      if( rc == SQLITE_OK) {
 
 1025++        fprintf(stderr, "SQL error: %s\n", sqlite3_errmsg(db));
 
 1032++  // if still no valid table found, give up
 
 1033++  if (!table_open) {
 
 1034++    OLSR_PRINTF(5, "ONDATA PLUGIN: no further table found\n");
 
 1035++    sqlite3_close(db);
 
 1037++    // reset timer to normal interval
 
 1038++    olsr_change_timer(msg_gen_timer, my_interval * MSEC_PER_SEC, EMISSION_JITTER, OLSR_TIMER_PERIODIC);
 
 1042++  // add all datasets
 
 1043++  if (sqlite3_step(ppStmt) == SQLITE_ROW) {
 
 1044++    OLSR_PRINTF(5, "ONDATA PLUGIN: adding all datasets\n");
 
 1045++    // add all the entries after the ondatamsg header (and keep space for it)
 
 1046++    pos = (char *)msg + sizeof(struct ondatamsg);
 
 1048++    // always add the Table-Name as first field
 
 1049++    pos = create_packet((struct ondata *)ARM_NOWARN_ALIGN(pos), DATABASE_TABLES[currentTable]);
 
 1051++    // never transmit originator (col=0), this will be detected at the other end_pos
 
 1052++    // skip last column, it will set at destination to the receiving-time
 
 1054++    while (iCol < sqlite3_column_count(ppStmt) - 1) {
 
 1055++      pos = create_packet((struct ondata *)ARM_NOWARN_ALIGN(pos), (const char *)sqlite3_column_text(ppStmt, iCol));
 
 1058++    // write the ondatamsg header with the number of announced entries and the protocol version
 
 1059++    msg->nr_datasets = htons(--iCol);   // it won't count the table-name as dataset (and neither mainip-Col)
 
 1060++    msg->version = htons(ONDATA_PROTOCOL_VERSION);
 
 1061++    messageLength = pos - (char *)msg;
 
 1062++    msg->length = htons(messageLength);
 
 1063++    checksum = crcCalculate((char *)msg + sizeof(uint16_t), messageLength - sizeof(uint16_t));
 
 1064++    msg->checksum = htons(checksum);
 
 1066++    OLSR_PRINTF(3, "ONDATA PLUGIN: ##### finished creating packet, length=%d, crc16=0x%x\n", messageLength, checksum);
 
 1069++    OLSR_PRINTF(5, "ONDATA PLUGIN: finalize query\n");
 
 1070++    sqlite3_finalize(ppStmt);
 
 1076++  // increase Transmission-Time as long as there is data
 
 1077++  olsr_change_timer(msg_gen_timer, 1 * MSEC_PER_SEC, EMISSION_JITTER, OLSR_TIMER_PERIODIC);
 
 1078++  return messageLength;     //length
 
 1082++ * convert each of my to be announced ondata_entries into network
 
 1083++ * compatible format
 
 1085++ * return the length of the ondata packet
 
 1088++create_packet(struct ondata *to, const char *value )
 
 1090++  char *pos = (char *)to;  int valuelen = strlen((const char*)value);
 
 1092++  to->valuelen = htons(valuelen);
 
 1093++  OLSR_PRINTF(5, "ONDATA PLUGIN: Announcing value %s %d\n", value, valuelen);
 
 1094++  pos += sizeof(struct ondata);
 
 1095++  memcpy(pos, value, valuelen);
 
 1097++  // do 4-byte padding
 
 1098++  for (k = sizeof(struct ondata) + valuelen; (k & 3) != 0; k++)
 
 1105++ * unpack the received message and delegate to the decapsulation function for each
 
 1106++ * ondata entry in the message
 
 1109++update_ondata_entry(union olsr_ip_addr *originator, struct ondatamsg *msg, int msg_size)
 
 1111++  struct ipaddr_str strbuf;
 
 1112++  char *pos, *end_pos, *values, *valuepos, *table;
 
 1113++  const char *originatorIP;
 
 1114++  struct ondata *from_packet;
 
 1116++  uint16_t checksum;
 
 1118++  sqlite3_stmt *localppStmt;
 
 1120++  const char *SQLframe = "INSERT OR REPLACE INTO %s VALUES (%s);", *pzTail;
 
 1123++  originatorIP = olsr_ip_to_string(&strbuf, originator);
 
 1124++  OLSR_PRINTF(3, "ONDATA PLUGIN: Received Message from %s, version %d, msg_size %d, checksum 0x%x\n", originatorIP, ntohs(msg->version), ntohs(msg->length), ntohs(msg->checksum));
 
 1126++  if (ntohs(msg->version) != ONDATA_PROTOCOL_VERSION) {
 
 1127++    OLSR_PRINTF(3, "ONDATA PLUGIN: ignoring wrong version %d\n", ntohs(msg->version));
 
 1131++  // calculate checksum
 
 1132++  checksum = crcCalculate((char *)msg + sizeof(uint16_t), ntohs(msg->length) - sizeof(uint16_t));
 
 1133++  if (ntohs(msg->checksum) != checksum) {
 
 1134++    OLSR_PRINTF(3, "ONDATA PLUGIN: ignoring checksum error 0x%x\n", checksum);
 
 1137++  else OLSR_PRINTF(5, "ONDATA PLUGIN: validated checksum 0x%x\n", checksum);
 
 1140++  // every value will be enclosed in brackets "'" and separated by a comma ","
 
 1141++  // so we need four bytes more per value (and we take more than we need, yeah)
 
 1142++  values = olsr_malloc(strlen(originatorIP) + 1 + ntohs(msg->length) + msg->nr_datasets*3, "update_ondata_entry: space for SQL values");
 
 1143++  valuepos = values;
 
 1145++  // checksum is valid, now add the values to the database.
 
 1146++  // first field is the tablename, abort if it does not exist
 
 1147++  // all following fields contain the table-values for one row.
 
 1149++  pos = (char *)msg + sizeof(struct ondatamsg);
 
 1150++  end_pos = pos + msg_size - sizeof(struct ondata *);     // at least one struct ondata has to be left
 
 1153++  from_packet = (struct ondata *)ARM_NOWARN_ALIGN(pos);
 
 1154++  table = olsr_malloc(ntohs(from_packet->valuelen) + 1, "update_ondata_entry: space for Table Name");
 
 1156++  memcpy(table, (char *)from_packet + sizeof(struct ondata), ntohs(from_packet->valuelen));
 
 1157++  *(table + ntohs(from_packet->valuelen)) = '\0';
 
 1159++  // set new position and calculate alignment
 
 1160++  pos += ((sizeof(struct ondata) + ntohs(from_packet->valuelen) - 1) | 3) + 1;
 
 1162++  // add originator IP
 
 1163++  memcpy(valuepos++, "'", 1);
 
 1164++  memcpy(valuepos, originatorIP, strlen(originatorIP));
 
 1165++  valuepos += strlen(originatorIP);
 
 1166++  memcpy(valuepos, "',", 2);
 
 1169++  for (i = ntohs(msg->nr_datasets); i > 0 && pos < end_pos; i--) {
 
 1170++    from_packet = (struct ondata *)ARM_NOWARN_ALIGN(pos);
 
 1172++    memcpy(valuepos++, "'", 1);
 
 1173++    memcpy(valuepos, (char *)from_packet + sizeof(struct ondata), ntohs(from_packet->valuelen));
 
 1174++    valuepos += ntohs(from_packet->valuelen);
 
 1175++    memcpy(valuepos, "',", 2);
 
 1178++    // set new position and calculate alignment
 
 1179++    pos += ((sizeof(struct ondata) + ntohs(from_packet->valuelen) - 1) | 3) + 1;
 
 1182++  // add current time to detect age of datasets (and remove them after timeout)
 
 1183++  sprintf(valuepos, "'%lu'", (uintmax_t)time(NULL));
 
 1185++  // build Database statement
 
 1186++  localzSql = olsr_malloc(strlen(SQLframe) + strlen(table) + strlen(values) + 1, "update_ondata_entry: space for SQL query");
 
 1187++  sprintf(localzSql, SQLframe, table, values);
 
 1188++  free(table); free(values);
 
 1190++  // apply statement to database
 
 1191++  rc = open_database(&localdb);
 
 1192++  if( rc == SQLITE_OK ){
 
 1193++    // use 1500 as max MTU and therefore as max SQL size (which is not quite accurate)
 
 1194++    rc = local_sqlite3_prepare_v2(localdb, localzSql, 1500, &localppStmt, &pzTail);
 
 1195++    if( rc == SQLITE_OK ){
 
 1196++      sqlite3_step(localppStmt);
 
 1197++      sqlite3_finalize(localppStmt);
 
 1198++      OLSR_PRINTF(5, "ONDATA PLUGIN: Data added: %s\n", localzSql);
 
 1200++    else fprintf(stderr, "SQL error: %s\n", sqlite3_errmsg(localdb));
 
 1202++  else fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(localdb));
 
 1204++  sqlite3_close(localdb);
 
 1209++ * Local Variables:
 
 1211++ * c-indent-tabs-mode: t
 
 1212++ * indent-tabs-mode: t
 
 1213++ * c-basic-offset: 4
 
 1218+diff --git a/lib/ondataservice/src/ondataservice.h b/lib/ondataservice/src/ondataservice.h
 
 1219+new file mode 100644
 
 1220+index 0000000..cc1251b
 
 1222++++ b/lib/ondataservice/src/ondataservice.h
 
 1226++ * Copyright (c) 2005, Bruno Randolf <bruno.randolf@4g-systems.biz>
 
 1227++ * Copyright (c) 2004, Andreas Tonnesen(andreto-at-olsr.org)
 
 1228++ * All rights reserved.
 
 1230++ * Redistribution and use in source and binary forms, with or without
 
 1231++ * modification, are permitted provided that the following conditions
 
 1234++ * * Redistributions of source code must retain the above copyright notice,
 
 1235++ *   this list of conditions and the following disclaimer.
 
 1236++ * * Redistributions in binary form must reproduce the above copyright notice,
 
 1237++ *   this list of conditions and the following disclaimer in the documentation
 
 1238++ *   and/or other materials provided with the distribution.
 
 1239++ * * Neither the name of the UniK olsr daemon nor the names of its contributors
 
 1240++ *   may be used to endorse or promote products derived from this software
 
 1241++ *   without specific prior written permission.
 
 1243++ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 
 1244++ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 
 1245++ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 
 1246++ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 
 1247++ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 
 1248++ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 
 1249++ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 
 1250++ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
 
 1251++ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 
 1252++ * OF THE POSSIBILITY OF SUCH DAMAGE.
 
 1257++ * Dynamic linked library for UniK OLSRd
 
 1260++#ifndef _ONDATASERVICE_PLUGIN
 
 1261++#define _ONDATASERVICE_PLUGIN
 
 1263++#include <sys/time.h>
 
 1264++// #include <regex.h>
 
 1266++#include "olsr_types.h"
 
 1267++#include "interfaces.h"
 
 1268++#include "olsr_protocol.h"
 
 1269++#include "common/list.h"
 
 1271++#include "olsrd_plugin.h"
 
 1272++#include "ondataservice_msg.h"
 
 1273++#include "hashing.h"
 
 1274++// #include "mapwrite.h"
 
 1275++// #include "mantissa.h"
 
 1277++#define PLUGIN_NAME       "OLSRD ondataservice plugin"
 
 1278++#define PLUGIN_VERSION        "0.3"
 
 1279++#define PLUGIN_AUTHOR     "Rene Ejury, Bruno Randolf, Jens Nachtigall, Sven-Ola Tuecke"
 
 1280++#define DATABASE_FILE     "/tmp/database"
 
 1282++#define MESSAGE_TYPE      222 /* hope this is a good choice */
 
 1283++#define PARSER_TYPE       MESSAGE_TYPE
 
 1284++#define EMISSION_INTERVAL 10800 /* seconds - 10800 = 3hours */
 
 1285++#define EMISSION_INC_INTERVAL   5 /* seconds between transmission of rows from one dataset */
 
 1286++#define EMISSION_JITTER         25  /* percent */
 
 1287++#define ONDATA_TIMEOUT  21600  /* seconds, how long old data stays valid - 21600 = 6hours */
 
 1288++#define ONDATA_VALID_TIME 300  /* seconds, how long a package should maximally be spreaded through the net - 300 - 5mins*/
 
 1289++#define CLEANUP_INTERVAL    1800 /* seconds, how often cleanup will be triggered - 1800 = 0.5hours */
 
 1291++#define ONDATA_PROTOCOL_VERSION   1
 
 1293++#define MAX_FILE      255
 
 1295++/* Parser function to register with the scheduler */
 
 1296++bool olsr_parser(union olsr_message *, struct interface_olsr *, union olsr_ip_addr *);
 
 1298++/* callback for periodic timer */
 
 1299++void olsr_ondatasvc_gen(void *);
 
 1301++/* open or create and open database */
 
 1302++#include <sqlite3.h>
 
 1303++int open_database(sqlite3 **localdb);
 
 1304++int unsigned local_sqlite3_prepare_v2(sqlite3 *db, const char *zSql, int nByte, sqlite3_stmt **ppStmt, const char **pzTail);
 
 1306++/* callback for database cleanup */
 
 1307++void olsr_ondataservice_expire_db_timer(void *);
 
 1309++int encap_ondatamsg(struct ondatamsg *);
 
 1311++void update_ondata_entry(union olsr_ip_addr *, struct ondatamsg *, int);
 
 1313++int register_olsr_param(char *key, char *value);
 
 1316++char *create_packet(struct ondata *to, const char *value);
 
 1318++void ondata_constructor(void);
 
 1320++void ondata_destructor(void);
 
 1322++int ondata_init(void);
 
 1327++ * Local Variables:
 
 1328++ * c-basic-offset: 2
 
 1329++ * indent-tabs-mode: nil
 
 1333+diff --git a/lib/ondataservice/src/ondataservice_msg.h b/lib/ondataservice/src/ondataservice_msg.h
 
 1334+new file mode 100644
 
 1335+index 0000000..b22fbee
 
 1337++++ b/lib/ondataservice/src/ondataservice_msg.h
 
 1341++ * Copyright (c) 2005, Bruno Randolf <bruno.randolf@4g-systems.biz>
 
 1342++ * Copyright (c) 2004, Andreas Tonnesen(andreto-at-olsr.org)
 
 1343++ * All rights reserved.
 
 1345++ * Redistribution and use in source and binary forms, with or without
 
 1346++ * modification, are permitted provided that the following conditions
 
 1349++ * * Redistributions of source code must retain the above copyright notice,
 
 1350++ *   this list of conditions and the following disclaimer.
 
 1351++ * * Redistributions in binary form must reproduce the above copyright notice,
 
 1352++ *   this list of conditions and the following disclaimer in the documentation
 
 1353++ *   and/or other materials provided with the distribution.
 
 1354++ * * Neither the name of the UniK olsr daemon nor the names of its contributors
 
 1355++ *   may be used to endorse or promote products derived from this software
 
 1356++ *   without specific prior written permission.
 
 1358++ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 
 1359++ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 
 1360++ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 
 1361++ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 
 1362++ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 
 1363++ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 
 1364++ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 
 1365++ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
 
 1366++ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 
 1367++ * OF THE POSSIBILITY OF SUCH DAMAGE.
 
 1372++ * Dynamic linked library for UniK OLSRd
 
 1375++#ifndef _ONDATASERVICE_MSG
 
 1376++#define _ONDATASERVICE_MSG
 
 1379++ * the data, forwarder or service entry as found in a packet within a
 
 1383++  uint16_t valuelen;                     // length of the value
 
 1385++   * value is written separatedly in plain text after this struct and padded to 4 byte
 
 1390++  uint16_t checksum;
 
 1391++  uint16_t version;                     // version number of the ondataservice plugin
 
 1392++  uint16_t nr_datasets;                 // number of following packets including all the data
 
 1393++  uint16_t length;                      // length in bytes / required to calculate checksum on receive
 
 1395++   * at least one struct name following
 
 1402++ * Local Variables:
 
 1403++ * c-basic-offset: 2
 
 1404++ * indent-tabs-mode: nil
 
 1407+diff --git a/lib/ondataservice/version-script.txt b/lib/ondataservice/version-script.txt
 
 1408+new file mode 100644
 
 1409+index 0000000..a145659
 
 1411++++ b/lib/ondataservice/version-script.txt
 
 1416++    olsrd_plugin_interface_version;
 
 1417++    olsrd_plugin_init;
 
 1418++    olsrd_get_plugin_parameters;
 
 1423+diff --git a/lib/ondataservice_light/Makefile b/lib/ondataservice_light/Makefile
 
 1424+new file mode 100644
 
 1425+index 0000000..01dd2db
 
 1427++++ b/lib/ondataservice_light/Makefile
 
 1429++# The olsr.org Optimized Link-State Routing daemon(olsrd)
 
 1430++# Copyright (c) 2004, Andreas Tonnesen(andreto@olsr.org)
 
 1431++# All rights reserved.
 
 1433++# Redistribution and use in source and binary forms, with or without
 
 1434++# modification, are permitted provided that the following conditions
 
 1437++# * Redistributions of source code must retain the above copyright
 
 1438++#   notice, this list of conditions and the following disclaimer.
 
 1439++# * Redistributions in binary form must reproduce the above copyright
 
 1440++#   notice, this list of conditions and the following disclaimer in
 
 1441++#   the documentation and/or other materials provided with the
 
 1443++# * Neither the name of olsr.org, olsrd nor the names of its
 
 1444++#   contributors may be used to endorse or promote products derived
 
 1445++#   from this software without specific prior written permission.
 
 1447++# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 
 1448++# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 
 1449++# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 
 1450++# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 
 1451++# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 
 1452++# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 
 1453++# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 
 1454++# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 
 1455++# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 
 1456++# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 
 1457++# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 
 1458++# POSSIBILITY OF SUCH DAMAGE.
 
 1460++# Visit http://www.olsr.org for more information.
 
 1462++# If you find this software useful feel free to make a donation
 
 1463++# to the project. For more information see the website or contact
 
 1464++# the copyright holders.
 
 1467++OLSRD_PLUGIN =    true
 
 1468++PLUGIN_NAME = olsrd_ondataservice_light
 
 1469++# dont change version here for backward-compatible changes,
 
 1470++# it will change the library name and won't load with the
 
 1471++# olsrd-config already existing on the device
 
 1477++include $(TOPDIR)/Makefile.inc
 
 1480++default_target install clean:
 
 1481++  @echo "**** We use the regex library here. Does Win32 has something like this?"
 
 1483++ifeq ($(OS),android)
 
 1484++# On Android Google forgot to include regex engine code for Froyo version (but also there was
 
 1485++# no support in older versions for it) so we have here this missing code.
 
 1486++# http://groups.google.com/group/android-ndk/browse_thread/thread/5ea6f0650f0e3fc
 
 1487++SRCS +=     $(wildcard $(TOPDIR)/android/regex/reg*.c)
 
 1488++HDRS +=     $(wildcard $(TOPDIR)/android/regex/*.h)
 
 1489++CFLAGS += -D__POSIX_VISIBLE
 
 1492++default_target: $(PLUGIN_FULLNAME)
 
 1494++$(PLUGIN_FULLNAME): $(OBJS) version-script.txt
 
 1496++      @$(CC) $(LDFLAGS) -o $(PLUGIN_FULLNAME) $(OBJS) $(LIBS)
 
 1498++install:  $(PLUGIN_FULLNAME)
 
 1499++      $(STRIP) $(PLUGIN_FULLNAME)
 
 1506++      rm -f $(OBJS) $(SRCS:%.c=%.d) $(PLUGIN_FULLNAME)
 
 1508+diff --git a/lib/ondataservice_light/README_ONDATASERVICE_LIGHT b/lib/ondataservice_light/README_ONDATASERVICE_LIGHT
 
 1509+new file mode 100644
 
 1510+index 0000000..174cd28
 
 1512++++ b/lib/ondataservice_light/README_ONDATASERVICE_LIGHT
 
 1514++---------------------------------------------------------------------
 
 1515++ONDATASERVICE_LIGHT PLUGIN FOR OLSRD
 
 1516++by Rene Ejury <opennet@absorb.it>
 
 1517++based on and copied from:
 
 1518++NAMESERVICE PLUGIN FOR OLSRD
 
 1519++by Bruno Randolf <bruno.randolf@4g-systems.biz>
 
 1520++---------------------------------------------------------------------
 
 1522++Plugin just to spread json-values stored in a json-database
 
 1523++no reception possible, but does not require sqlite-library
 
 1525++---------------------------------------------------------------------
 
 1526++PLUGIN PARAMETERS (PlParam)
 
 1527++---------------------------------------------------------------------
 
 1529++PlParam "interval" "SEC"
 
 1530++  interval for sending the DATABASE in seconds.
 
 1531++  (default: 10800 - 3 hours)
 
 1533++PlParam "inc_interval" "SEC"
 
 1534++    interval for continously sending TABLES from DATABASE in seconds.
 
 1535++    (default: 5 seconds)
 
 1537++PlParam "database" "/path/to/database"
 
 1538++        Path to the database (json)
 
 1540++PlParam "vtime" "SEC"
 
 1541++    validity time for sended message-packages in seconds.
 
 1542++    (how long this message-data is forwarded through the net)
 
 1543++    (default: 300 - 5 mins)
 
 1545++---------------------------------------------------------------------
 
 1547++---------------------------------------------------------------------
 
 1549++add in /etc/olsrd.conf:
 
 1551++LoadPlugin "olsrd_ondataservice_light.so.0.1"
 
 1553++    PlParam "interval"  "120"
 
 1554++    PlParam "database"  "/tmp/database.json"
 
 1556+diff --git a/lib/ondataservice_light/src/cJSON.c b/lib/ondataservice_light/src/cJSON.c
 
 1557+new file mode 100644
 
 1558+index 0000000..a5d910e
 
 1560++++ b/lib/ondataservice_light/src/cJSON.c
 
 1563++  Copyright (c) 2009 Dave Gamble
 
 1565++  Permission is hereby granted, free of charge, to any person obtaining a copy
 
 1566++  of this software and associated documentation files (the "Software"), to deal
 
 1567++  in the Software without restriction, including without limitation the rights
 
 1568++  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 
 1569++  copies of the Software, and to permit persons to whom the Software is
 
 1570++  furnished to do so, subject to the following conditions:
 
 1572++  The above copyright notice and this permission notice shall be included in
 
 1573++  all copies or substantial portions of the Software.
 
 1575++  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
 1576++  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
 1577++  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 
 1578++  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 
 1579++  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 
 1580++  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 
 1585++/* JSON parser in C. */
 
 1587++#include <string.h>
 
 1590++#include <stdlib.h>
 
 1592++#include <limits.h>
 
 1596++static const char *ep;
 
 1598++// const char *cJSON_GetErrorPtr(void) {return ep;}
 
 1600++// static int cJSON_strcasecmp(const char *s1,const char *s2)
 
 1602++//    if (!s1) return (s1==s2)?0:1;if (!s2) return 1;
 
 1603++//    for(; tolower(*s1) == tolower(*s2); ++s1, ++s2) if(*s1 == 0)    return 0;
 
 1604++//    return tolower(*(const unsigned char *)s1) - tolower(*(const unsigned char *)s2);
 
 1607++static void *(*cJSON_malloc)(size_t sz) = malloc;
 
 1608++static void (*cJSON_free)(void *ptr) = free;
 
 1610++static char* cJSON_strdup(const char* str)
 
 1615++      len = strlen(str) + 1;
 
 1616++      if (!(copy = (char*)cJSON_malloc(len))) return 0;
 
 1617++      memcpy(copy,str,len);
 
 1621++void cJSON_InitHooks(cJSON_Hooks* hooks)
 
 1623++    if (!hooks) { /* Reset hooks */
 
 1624++        cJSON_malloc = malloc;
 
 1625++        cJSON_free = free;
 
 1629++  cJSON_malloc = (hooks->malloc_fn)?hooks->malloc_fn:malloc;
 
 1630++  cJSON_free   = (hooks->free_fn)?hooks->free_fn:free;
 
 1633++/* Internal constructor. */
 
 1634++static cJSON *cJSON_New_Item(void)
 
 1636++  cJSON* node = (cJSON*)cJSON_malloc(sizeof(cJSON));
 
 1637++  if (node) memset(node,0,sizeof(cJSON));
 
 1641++/* Delete a cJSON structure. */
 
 1642++void cJSON_Delete(cJSON *c)
 
 1648++      if (!(c->type&cJSON_IsReference) && c->child) cJSON_Delete(c->child);
 
 1649++      if (!(c->type&cJSON_IsReference) && c->valuestring) cJSON_free(c->valuestring);
 
 1650++      if (c->string) cJSON_free(c->string);
 
 1656++// /* Parse the input text to generate a number, and populate the result into item. */
 
 1657++// static const char *parse_number(cJSON *item,const char *num)
 
 1659++//    double n=0,sign=1,scale=0;int subscale=0,signsubscale=1;
 
 1661++//    /* Could use sscanf for this? */
 
 1662++//    if (*num=='-') sign=-1,num++;   /* Has sign? */
 
 1663++//    if (*num=='0') num++;           /* is zero */
 
 1664++//    if (*num>='1' && *num<='9') do  n=(n*10.0)+(*num++ -'0');   while (*num>='0' && *num<='9'); /* Number? */
 
 1665++//    if (*num=='.' && num[1]>='0' && num[1]<='9') {num++;        do  n=(n*10.0)+(*num++ -'0'),scale--; while (*num>='0' && *num<='9');}  /* Fractional part? */
 
 1666++//    if (*num=='e' || *num=='E')     /* Exponent? */
 
 1667++//    {   num++;if (*num=='+') num++; else if (*num=='-') signsubscale=-1,num++;      /* With sign? */
 
 1668++//        while (*num>='0' && *num<='9') subscale=(subscale*10)+(*num++ - '0');   /* Number? */
 
 1671++//    n=sign*n*pow(10.0,(scale+subscale*signsubscale));   /* number = +/- number.fraction * 10^+/- exponent */
 
 1673++//    item->valuedouble=n;
 
 1674++//    item->valueint=(int)n;
 
 1675++//    item->type=cJSON_Number;
 
 1679++// /* Render the number nicely from the given item into a string. */
 
 1680++// static char *print_number(cJSON *item)
 
 1683++//    double d=item->valuedouble;
 
 1684++//    if (fabs(((double)item->valueint)-d)<=DBL_EPSILON && d<=INT_MAX && d>=INT_MIN)
 
 1686++//        str=(char*)cJSON_malloc(21);    /* 2^64+1 can be represented in 21 chars. */
 
 1687++//        if (str) sprintf(str,"%d",item->valueint);
 
 1691++//        str=(char*)cJSON_malloc(64);    /* This is a nice tradeoff. */
 
 1694++//            if (fabs(floor(d)-d)<=DBL_EPSILON)          sprintf(str,"%.0f",d);
 
 1695++//            else if (fabs(d)<1.0e-6 || fabs(d)>1.0e9)   sprintf(str,"%e",d);
 
 1696++//            else                                        sprintf(str,"%f",d);
 
 1702++/* Parse the input text into an unescaped cstring, and populate item. */
 
 1703++static const unsigned char firstByteMark[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };
 
 1704++static const char *parse_string(cJSON *item,const char *str)
 
 1706++  const char *ptr=str+1;char *ptr2;char *out;int len=0;unsigned uc,uc2;
 
 1707++  if (*str!='\"') {ep=str;return 0;}  /* not a string! */
 
 1709++  while (*ptr!='\"' && *ptr && ++len) if (*ptr++ == '\\') ptr++;  /* Skip escaped quotes. */
 
 1711++  out=(char*)cJSON_malloc(len+1); /* This is how long we need for the string, roughly. */
 
 1712++  if (!out) return 0;
 
 1714++  ptr=str+1;ptr2=out;
 
 1715++  while (*ptr!='\"' && *ptr)
 
 1717++      if (*ptr!='\\') *ptr2++=*ptr++;
 
 1723++              case 'b': *ptr2++='\b'; break;
 
 1724++              case 'f': *ptr2++='\f'; break;
 
 1725++              case 'n': *ptr2++='\n'; break;
 
 1726++              case 'r': *ptr2++='\r'; break;
 
 1727++              case 't': *ptr2++='\t'; break;
 
 1728++              case 'u':    /* transcode utf16 to utf8. */
 
 1729++                  sscanf(ptr+1,"%4x",&uc);ptr+=4; /* get the unicode char. */
 
 1731++                  if ((uc>=0xDC00 && uc<=0xDFFF) || uc==0)    break;  // check for invalid.
 
 1733++                  if (uc>=0xD800 && uc<=0xDBFF)   // UTF16 surrogate pairs.
 
 1735++                      if (ptr[1]!='\\' || ptr[2]!='u')    break;  // missing second-half of surrogate.
 
 1736++                      sscanf(ptr+3,"%4x",&uc2);ptr+=6;
 
 1737++                      if (uc2<0xDC00 || uc2>0xDFFF)       break;  // invalid second-half of surrogate.
 
 1738++                      uc=0x10000 | ((uc&0x3FF)<<10) | (uc2&0x3FF);
 
 1741++                  len=4;if (uc<0x80) len=1;else if (uc<0x800) len=2;else if (uc<0x10000) len=3; ptr2+=len;
 
 1744++                      case 4: *--ptr2 =((uc | 0x80) & 0xBF); uc >>= 6;
 
 1745++                      case 3: *--ptr2 =((uc | 0x80) & 0xBF); uc >>= 6;
 
 1746++                      case 2: *--ptr2 =((uc | 0x80) & 0xBF); uc >>= 6;
 
 1749++              *--ptr2 =(uc | firstByteMark[len]);
 
 1753++              default:  *ptr2++=*ptr; break;
 
 1759++  if (*ptr=='\"') ptr++;
 
 1760++  item->valuestring=out;
 
 1761++  item->type=cJSON_String;
 
 1765++// /* Render the cstring provided to an escaped version that can be printed. */
 
 1766++// static char *print_string_ptr(const char *str)
 
 1768++//    const char *ptr;char *ptr2,*out;int len=0;unsigned char token;
 
 1770++//    if (!str) return cJSON_strdup("");
 
 1771++//    ptr=str;while ((token=*ptr) && ++len) {if (strchr("\"\\\b\f\n\r\t",token)) len++; else if (token<32) len+=5;ptr++;}
 
 1773++//    out=(char*)cJSON_malloc(len+3);
 
 1774++//    if (!out) return 0;
 
 1776++//    ptr2=out;ptr=str;
 
 1780++//        if ((unsigned char)*ptr>31 && *ptr!='\"' && *ptr!='\\') *ptr2++=*ptr++;
 
 1784++//            switch (token=*ptr++)
 
 1786++//                case '\\':  *ptr2++='\\';   break;
 
 1787++//                case '\"':  *ptr2++='\"';   break;
 
 1788++//                case '\b':  *ptr2++='b';    break;
 
 1789++//                case '\f':  *ptr2++='f';    break;
 
 1790++//                case '\n':  *ptr2++='n';    break;
 
 1791++//                case '\r':  *ptr2++='r';    break;
 
 1792++//                case '\t':  *ptr2++='t';    break;
 
 1793++//                default: sprintf(ptr2,"u%04x",token);ptr2+=5;   break;  /* escape and print */
 
 1797++//    *ptr2++='\"';*ptr2++=0;
 
 1800++// /* Invote print_string_ptr (which is useful) on an item. */
 
 1801++// static char *print_string(cJSON *item) {return print_string_ptr(item->valuestring);}
 
 1803++/* Predeclare these prototypes. */
 
 1804++static const char *parse_value(cJSON *item,const char *value);
 
 1805++// static char *print_value(cJSON *item,int depth,int fmt);
 
 1806++// static const char *parse_array(cJSON *item,const char *value);
 
 1807++// static char *print_array(cJSON *item,int depth,int fmt);
 
 1808++static const char *parse_object(cJSON *item,const char *value);
 
 1809++// static char *print_object(cJSON *item,int depth,int fmt);
 
 1811++/* Utility to jump whitespace and cr/lf */
 
 1812++static const char *skip(const char *in) {while (in && *in && (unsigned char)*in<=32) in++; return in;}
 
 1814++/* Parse an object - create a new root, and populate. */
 
 1815++cJSON *cJSON_Parse(const char *value)
 
 1817++  cJSON *c=cJSON_New_Item();
 
 1819++  if (!c) return 0;       /* memory fail */
 
 1821++  if (!parse_value(c,skip(value))) {cJSON_Delete(c);return 0;}
 
 1825++/* Render a cJSON item/entity/structure to text. */
 
 1826++// char *cJSON_Print(cJSON *item)             {return print_value(item,0,1);}
 
 1827++// char *cJSON_PrintUnformatted(cJSON *item)  {return print_value(item,0,0);}
 
 1829++/* Parser core - when encountering text, process appropriately. */
 
 1830++static const char *parse_value(cJSON *item,const char *value)
 
 1832++  if (!value)                     return 0;   /* Fail on null. */
 
 1833++//    if (!strncmp(value,"null",4))   { item->type=cJSON_NULL;  return value+4; }
 
 1834++//    if (!strncmp(value,"false",5))  { item->type=cJSON_False; return value+5; }
 
 1835++//    if (!strncmp(value,"true",4))   { item->type=cJSON_True; item->valueint=1;  return value+4; }
 
 1836++  if (*value=='\"')               { return parse_string(item,value); }
 
 1837++//    if (*value=='-' || (*value>='0' && *value<='9'))    { return parse_number(item,value); }
 
 1838++//    if (*value=='[')                { return parse_array(item,value); }
 
 1839++  if (*value=='{')                { return parse_object(item,value); }
 
 1841++  ep=value;return 0;  /* failure. */
 
 1844++/* Render a value to text. */
 
 1845++// static char *print_value(cJSON *item,int depth,int fmt)
 
 1848++//    if (!item) return 0;
 
 1849++//    switch ((item->type)&255)
 
 1851++//        case cJSON_NULL:    out=cJSON_strdup("null");   break;
 
 1852++//        case cJSON_False:   out=cJSON_strdup("false");break;
 
 1853++//        case cJSON_True:    out=cJSON_strdup("true"); break;
 
 1854++//        case cJSON_Number:  out=print_number(item);break;
 
 1855++//        case cJSON_String:  out=print_string(item);break;
 
 1856++//        case cJSON_Array:   out=print_array(item,depth,fmt);break;
 
 1857++//        case cJSON_Object:  out=print_object(item,depth,fmt);break;
 
 1862++// /* Build an array from input text. */
 
 1863++// static const char *parse_array(cJSON *item,const char *value)
 
 1866++//    if (*value!='[')    {ep=value;return 0;}    /* not an array! */
 
 1868++//    item->type=cJSON_Array;
 
 1869++//    value=skip(value+1);
 
 1870++//    if (*value==']') return value+1;    /* empty array. */
 
 1872++//    item->child=child=cJSON_New_Item();
 
 1873++//    if (!item->child) return 0;      /* memory fail */
 
 1874++//    value=skip(parse_value(child,skip(value))); /* skip any spacing, get the value. */
 
 1875++//    if (!value) return 0;
 
 1877++//    while (*value==',')
 
 1879++//        cJSON *new_item;
 
 1880++//        if (!(new_item=cJSON_New_Item())) return 0;     /* memory fail */
 
 1881++//        child->next=new_item;new_item->prev=child;child=new_item;
 
 1882++//        value=skip(parse_value(child,skip(value+1)));
 
 1883++//        if (!value) return 0;   /* memory fail */
 
 1886++//    if (*value==']') return value+1;    /* end of array */
 
 1887++//    ep=value;return 0;  /* malformed. */
 
 1890++/* Render an array to text */
 
 1891++// static char *print_array(cJSON *item,int depth,int fmt)
 
 1894++//    char *out=0,*ptr,*ret;int len=5;
 
 1895++//    cJSON *child=item->child;
 
 1896++//    int numentries=0,i=0,fail=0;
 
 1898++//    /* How many entries in the array? */
 
 1899++//    while (child) numentries++,child=child->next;
 
 1900++//    /* Allocate an array to hold the values for each */
 
 1901++//    entries=(char**)cJSON_malloc(numentries*sizeof(char*));
 
 1902++//    if (!entries) return 0;
 
 1903++//    memset(entries,0,numentries*sizeof(char*));
 
 1904++//    /* Retrieve all the results: */
 
 1905++//    child=item->child;
 
 1906++//    while (child && !fail)
 
 1908++//        ret=print_value(child,depth+1,fmt);
 
 1909++//        entries[i++]=ret;
 
 1910++//        if (ret) len+=strlen(ret)+2+(fmt?1:0); else fail=1;
 
 1911++//        child=child->next;
 
 1914++//    /* If we didn't fail, try to malloc the output string */
 
 1915++//    if (!fail) out=(char*)cJSON_malloc(len);
 
 1916++//    /* If that fails, we fail. */
 
 1917++//    if (!out) fail=1;
 
 1919++//    /* Handle failure. */
 
 1922++//        for (i=0;i<numentries;i++) if (entries[i]) cJSON_free(entries[i]);
 
 1923++//        cJSON_free(entries);
 
 1927++//    /* Compose the output array. */
 
 1929++//    ptr=out+1;*ptr=0;
 
 1930++//    for (i=0;i<numentries;i++)
 
 1932++//        strcpy(ptr,entries[i]);ptr+=strlen(entries[i]);
 
 1933++//        if (i!=numentries-1) {*ptr++=',';if(fmt)*ptr++=' ';*ptr=0;}
 
 1934++//        cJSON_free(entries[i]);
 
 1936++//    cJSON_free(entries);
 
 1937++//    *ptr++=']';*ptr++=0;
 
 1941++/* Build an object from the text. */
 
 1942++static const char *parse_object(cJSON *item,const char *value)
 
 1945++  if (*value!='{')    {ep=value;return 0;}    /* not an object! */
 
 1947++  item->type=cJSON_Object;
 
 1948++  value=skip(value+1);
 
 1949++  if (*value=='}') return value+1;    /* empty array. */
 
 1951++  item->child=child=cJSON_New_Item();
 
 1952++  if (!item->child) return 0;
 
 1953++  value=skip(parse_string(child,skip(value)));
 
 1954++  if (!value) return 0;
 
 1955++  child->string=child->valuestring;child->valuestring=0;
 
 1956++  if (*value!=':') {ep=value;return 0;}   /* fail! */
 
 1957++  value=skip(parse_value(child,skip(value+1)));   /* skip any spacing, get the value. */
 
 1958++  if (!value) return 0;
 
 1960++  while (*value==',')
 
 1963++      if (!(new_item=cJSON_New_Item()))   return 0; /* memory fail */
 
 1964++      child->next=new_item;new_item->prev=child;child=new_item;
 
 1965++      value=skip(parse_string(child,skip(value+1)));
 
 1966++      if (!value) return 0;
 
 1967++      child->string=child->valuestring;child->valuestring=0;
 
 1968++      if (*value!=':') {ep=value;return 0;}   /* fail! */
 
 1969++      value=skip(parse_value(child,skip(value+1)));   /* skip any spacing, get the value. */
 
 1970++      if (!value) return 0;
 
 1973++  if (*value=='}') return value+1;    /* end of array */
 
 1974++  ep=value;return 0;  /* malformed. */
 
 1977++// /* Render an object to text. */
 
 1978++// static char *print_object(cJSON *item,int depth,int fmt)
 
 1980++//    char **entries=0,**names=0;
 
 1981++//    char *out=0,*ptr,*ret,*str;int len=7,i=0,j;
 
 1982++//    cJSON *child=item->child;
 
 1983++//    int numentries=0,fail=0;
 
 1984++//    /* Count the number of entries. */
 
 1985++//    while (child) numentries++,child=child->next;
 
 1986++//    /* Allocate space for the names and the objects */
 
 1987++//    entries=(char**)cJSON_malloc(numentries*sizeof(char*));
 
 1988++//    if (!entries) return 0;
 
 1989++//    names=(char**)cJSON_malloc(numentries*sizeof(char*));
 
 1990++//    if (!names) {cJSON_free(entries);return 0;}
 
 1991++//    memset(entries,0,sizeof(char*)*numentries);
 
 1992++//    memset(names,0,sizeof(char*)*numentries);
 
 1994++//    /* Collect all the results into our arrays: */
 
 1995++//    child=item->child;depth++;if (fmt) len+=depth;
 
 1998++//        names[i]=str=print_string_ptr(child->string);
 
 1999++//        entries[i++]=ret=print_value(child,depth,fmt);
 
 2000++//        if (str && ret) len+=strlen(ret)+strlen(str)+2+(fmt?2+depth:0); else fail=1;
 
 2001++//        child=child->next;
 
 2004++//    /* Try to allocate the output string */
 
 2005++//    if (!fail) out=(char*)cJSON_malloc(len);
 
 2006++//    if (!out) fail=1;
 
 2008++//    /* Handle failure */
 
 2011++//        for (i=0;i<numentries;i++) {if (names[i]) cJSON_free(names[i]);if (entries[i]) cJSON_free(entries[i]);}
 
 2012++//        cJSON_free(names);cJSON_free(entries);
 
 2016++//    /* Compose the output: */
 
 2017++//    *out='{';ptr=out+1;if (fmt)*ptr++='\n';*ptr=0;
 
 2018++//    for (i=0;i<numentries;i++)
 
 2020++//        if (fmt) for (j=0;j<depth;j++) *ptr++='\t';
 
 2021++//        strcpy(ptr,names[i]);ptr+=strlen(names[i]);
 
 2022++//        *ptr++=':';if (fmt) *ptr++='\t';
 
 2023++//        strcpy(ptr,entries[i]);ptr+=strlen(entries[i]);
 
 2024++//        if (i!=numentries-1) *ptr++=',';
 
 2025++//        if (fmt) *ptr++='\n';*ptr=0;
 
 2026++//        cJSON_free(names[i]);cJSON_free(entries[i]);
 
 2029++//    cJSON_free(names);cJSON_free(entries);
 
 2030++//    if (fmt) for (i=0;i<depth-1;i++) *ptr++='\t';
 
 2031++//    *ptr++='}';*ptr++=0;
 
 2035++/* Get Array size/item / object item. */
 
 2036++// int    cJSON_GetArraySize(cJSON *array)                            {cJSON *c=array->child;int i=0;while(c)i++,c=c->next;return i;}
 
 2037++// cJSON *cJSON_GetArrayItem(cJSON *array,int item)               {cJSON *c=array->child;  while (c && item>0) item--,c=c->next; return c;}
 
 2038++// cJSON *cJSON_GetObjectItem(cJSON *object,const char *string)   {cJSON *c=object->child; while (c && cJSON_strcasecmp(c->string,string)) c=c->next; return c;}
 
 2040++/* Utility for array list handling. */
 
 2041++// static void suffix_object(cJSON *prev,cJSON *item) {prev->next=item;item->prev=prev;}
 
 2042++/* Utility for handling references. */
 
 2043++// static cJSON *create_reference(cJSON *item) {cJSON *ref=cJSON_New_Item();if (!ref) return 0;memcpy(ref,item,sizeof(cJSON));ref->string=0;ref->type|=cJSON_IsReference;ref->next=ref->prev=0;return ref;}
 
 2045++/* Add item to array/object. */
 
 2046++// void   cJSON_AddItemToArray(cJSON *array, cJSON *item)                     {cJSON *c=array->child;if (!item) return; if (!c) {array->child=item;} else {while (c && c->next) c=c->next; suffix_object(c,item);}}
 
 2047++// void   cJSON_AddItemToObject(cJSON *object,const char *string,cJSON *item) {if (!item) return; if (item->string) cJSON_free(item->string);item->string=cJSON_strdup(string);cJSON_AddItemToArray(object,item);}
 
 2048++// void   cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item)                        {cJSON_AddItemToArray(array,create_reference(item));}
 
 2049++// void   cJSON_AddItemReferenceToObject(cJSON *object,const char *string,cJSON *item)    {cJSON_AddItemToObject(object,string,create_reference(item));}
 
 2051++// cJSON *cJSON_DetachItemFromArray(cJSON *array,int which)           {cJSON *c=array->child;while (c && which>0) c=c->next,which--;if (!c) return 0;
 
 2052++//    if (c->prev) c->prev->next=c->next;if (c->next) c->next->prev=c->prev;if (c==array->child) array->child=c->next;c->prev=c->next=0;return c;}
 
 2053++// void   cJSON_DeleteItemFromArray(cJSON *array,int which)           {cJSON_Delete(cJSON_DetachItemFromArray(array,which));}
 
 2054++// cJSON *cJSON_DetachItemFromObject(cJSON *object,const char *string) {int i=0;cJSON *c=object->child;while (c && cJSON_strcasecmp(c->string,string)) i++,c=c->next;if (c) return cJSON_DetachItemFromArray(object,i);return 0;}
 
 2055++// void   cJSON_DeleteItemFromObject(cJSON *object,const char *string) {cJSON_Delete(cJSON_DetachItemFromObject(object,string));}
 
 2057++/* Replace array/object items with new ones. */
 
 2058++// void   cJSON_ReplaceItemInArray(cJSON *array,int which,cJSON *newitem)     {cJSON *c=array->child;while (c && which>0) c=c->next,which--;if (!c) return;
 
 2059++//    newitem->next=c->next;newitem->prev=c->prev;if (newitem->next) newitem->next->prev=newitem;
 
 2060++//    if (c==array->child) array->child=newitem; else newitem->prev->next=newitem;c->next=c->prev=0;cJSON_Delete(c);}
 
 2061++// void   cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem){int i=0;cJSON *c=object->child;while(c && cJSON_strcasecmp(c->string,string))i++,c=c->next;if(c){newitem->string=cJSON_strdup(string);cJSON_ReplaceItemInArray(object,i,newitem);}}
 
 2063++/* Create basic types: */
 
 2064++// cJSON *cJSON_CreateNull(void)                      {cJSON *item=cJSON_New_Item();if(item)item->type=cJSON_NULL;return item;}
 
 2065++// cJSON *cJSON_CreateTrue(void)                      {cJSON *item=cJSON_New_Item();if(item)item->type=cJSON_True;return item;}
 
 2066++// cJSON *cJSON_CreateFalse(void)                     {cJSON *item=cJSON_New_Item();if(item)item->type=cJSON_False;return item;}
 
 2067++// cJSON *cJSON_CreateBool(int b)                 {cJSON *item=cJSON_New_Item();if(item)item->type=b?cJSON_True:cJSON_False;return item;}
 
 2068++// cJSON *cJSON_CreateNumber(double num)          {cJSON *item=cJSON_New_Item();if(item){item->type=cJSON_Number;item->valuedouble=num;item->valueint=(int)num;}return item;}
 
 2069++cJSON *cJSON_CreateString(const char *string) {cJSON *item=cJSON_New_Item();if(item){item->type=cJSON_String;item->valuestring=cJSON_strdup(string);}return item;}
 
 2070++// cJSON *cJSON_CreateArray(void)                     {cJSON *item=cJSON_New_Item();if(item)item->type=cJSON_Array;return item;}
 
 2071++cJSON *cJSON_CreateObject(void)                       {cJSON *item=cJSON_New_Item();if(item)item->type=cJSON_Object;return item;}
 
 2073++/* Create Arrays: */
 
 2074++// cJSON *cJSON_CreateIntArray(int *numbers,int count)                {int i;cJSON *n=0,*p=0,*a=cJSON_CreateArray();for(i=0;a && i<count;i++){n=cJSON_CreateNumber(numbers[i]);if(!i)a->child=n;else suffix_object(p,n);p=n;}return a;}
 
 2075++// cJSON *cJSON_CreateFloatArray(float *numbers,int count)            {int i;cJSON *n=0,*p=0,*a=cJSON_CreateArray();for(i=0;a && i<count;i++){n=cJSON_CreateNumber(numbers[i]);if(!i)a->child=n;else suffix_object(p,n);p=n;}return a;}
 
 2076++// cJSON *cJSON_CreateDoubleArray(double *numbers,int count)      {int i;cJSON *n=0,*p=0,*a=cJSON_CreateArray();for(i=0;a && i<count;i++){n=cJSON_CreateNumber(numbers[i]);if(!i)a->child=n;else suffix_object(p,n);p=n;}return a;}
 
 2077++// cJSON *cJSON_CreateStringArray(const char **strings,int count) {int i;cJSON *n=0,*p=0,*a=cJSON_CreateArray();for(i=0;a && i<count;i++){n=cJSON_CreateString(strings[i]);if(!i)a->child=n;else suffix_object(p,n);p=n;}return a;}
 
 2078+diff --git a/lib/ondataservice_light/src/cJSON.h b/lib/ondataservice_light/src/cJSON.h
 
 2079+new file mode 100644
 
 2080+index 0000000..158160c
 
 2082++++ b/lib/ondataservice_light/src/cJSON.h
 
 2085++  Copyright (c) 2009 Dave Gamble
 
 2087++  Permission is hereby granted, free of charge, to any person obtaining a copy
 
 2088++  of this software and associated documentation files (the "Software"), to deal
 
 2089++  in the Software without restriction, including without limitation the rights
 
 2090++  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 
 2091++  copies of the Software, and to permit persons to whom the Software is
 
 2092++  furnished to do so, subject to the following conditions:
 
 2094++  The above copyright notice and this permission notice shall be included in
 
 2095++  all copies or substantial portions of the Software.
 
 2097++  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
 2098++  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
 2099++  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 
 2100++  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 
 2101++  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 
 2102++  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 
 2115++#define cJSON_False 0
 
 2116++#define cJSON_True 1
 
 2117++#define cJSON_NULL 2
 
 2118++#define cJSON_Number 3
 
 2119++#define cJSON_String 4
 
 2120++#define cJSON_Array 5
 
 2121++#define cJSON_Object 6
 
 2123++#define cJSON_IsReference 256
 
 2125++/* The cJSON structure: */
 
 2126++typedef struct cJSON {
 
 2127++  struct cJSON *next,*prev;   /* next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem */
 
 2128++  struct cJSON *child;        /* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */
 
 2130++  int type;                   /* The type of the item, as above. */
 
 2132++  char *valuestring;          /* The item's string, if type==cJSON_String */
 
 2133++  int valueint;               /* The item's number, if type==cJSON_Number */
 
 2134++  double valuedouble;         /* The item's number, if type==cJSON_Number */
 
 2136++  char *string;               /* The item's name string, if this item is the child of, or is in the list of subitems of an object. */
 
 2139++typedef struct cJSON_Hooks {
 
 2140++      void *(*malloc_fn)(size_t sz);
 
 2141++      void (*free_fn)(void *ptr);
 
 2144++/* Supply malloc, realloc and free functions to cJSON */
 
 2145++extern void cJSON_InitHooks(cJSON_Hooks* hooks);
 
 2148++/* Supply a block of JSON, and this returns a cJSON object you can interrogate. Call cJSON_Delete when finished. */
 
 2149++extern cJSON *cJSON_Parse(const char *value);
 
 2150++/* Render a cJSON entity to text for transfer/storage. Free the char* when finished. */
 
 2151++// extern char  *cJSON_Print(cJSON *item);
 
 2152++/* Render a cJSON entity to text for transfer/storage without any formatting. Free the char* when finished. */
 
 2153++// extern char  *cJSON_PrintUnformatted(cJSON *item);
 
 2154++/* Delete a cJSON entity and all subentities. */
 
 2155++extern void   cJSON_Delete(cJSON *c);
 
 2157++/* Returns the number of items in an array (or object). */
 
 2158++// extern int   cJSON_GetArraySize(cJSON *array);
 
 2159++/* Retrieve item number "item" from array "array". Returns NULL if unsuccessful. */
 
 2160++// extern cJSON *cJSON_GetArrayItem(cJSON *array,int item);
 
 2161++/* Get item "string" from object. Case insensitive. */
 
 2162++// extern cJSON *cJSON_GetObjectItem(cJSON *object,const char *string);
 
 2164++/* For analysing failed parses. This returns a pointer to the parse error. You'll probably need to look a few chars back to make sense of it. Defined when cJSON_Parse() returns 0. 0 when cJSON_Parse() succeeds. */
 
 2165++// extern const char *cJSON_GetErrorPtr(void);
 
 2167++/* These calls create a cJSON item of the appropriate type. */
 
 2168++// extern cJSON *cJSON_CreateNull(void);
 
 2169++// extern cJSON *cJSON_CreateTrue(void);
 
 2170++// extern cJSON *cJSON_CreateFalse(void);
 
 2171++// extern cJSON *cJSON_CreateBool(int b);
 
 2172++// extern cJSON *cJSON_CreateNumber(double num);
 
 2173++extern cJSON *cJSON_CreateString(const char *string);
 
 2174++// extern cJSON *cJSON_CreateArray(void);
 
 2175++extern cJSON *cJSON_CreateObject(void);
 
 2177++/* These utilities create an Array of count items. */
 
 2178++// extern cJSON *cJSON_CreateIntArray(int *numbers,int count);
 
 2179++// extern cJSON *cJSON_CreateFloatArray(float *numbers,int count);
 
 2180++// extern cJSON *cJSON_CreateDoubleArray(double *numbers,int count);
 
 2181++// extern cJSON *cJSON_CreateStringArray(const char **strings,int count);
 
 2183++/* Append item to the specified array/object. */
 
 2184++// extern void cJSON_AddItemToArray(cJSON *array, cJSON *item);
 
 2185++// extern void    cJSON_AddItemToObject(cJSON *object,const char *string,cJSON *item);
 
 2186++/* Append reference to item to the specified array/object. Use this when you want to add an existing cJSON to a new cJSON, but don't want to corrupt your existing cJSON. */
 
 2187++// extern void cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item);
 
 2188++// extern void    cJSON_AddItemReferenceToObject(cJSON *object,const char *string,cJSON *item);
 
 2190++/* Remove/Detatch items from Arrays/Objects. */
 
 2191++// extern cJSON *cJSON_DetachItemFromArray(cJSON *array,int which);
 
 2192++// extern void   cJSON_DeleteItemFromArray(cJSON *array,int which);
 
 2193++// extern cJSON *cJSON_DetachItemFromObject(cJSON *object,const char *string);
 
 2194++// extern void   cJSON_DeleteItemFromObject(cJSON *object,const char *string);
 
 2196++/* Update array items. */
 
 2197++// extern void cJSON_ReplaceItemInArray(cJSON *array,int which,cJSON *newitem);
 
 2198++// extern void cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem);
 
 2200++#define cJSON_AddNullToObject(object,name)    cJSON_AddItemToObject(object, name, cJSON_CreateNull())
 
 2201++#define cJSON_AddTrueToObject(object,name)    cJSON_AddItemToObject(object, name, cJSON_CreateTrue())
 
 2202++#define cJSON_AddFalseToObject(object,name)       cJSON_AddItemToObject(object, name, cJSON_CreateFalse())
 
 2203++#define cJSON_AddNumberToObject(object,name,n)    cJSON_AddItemToObject(object, name, cJSON_CreateNumber(n))
 
 2204++#define cJSON_AddStringToObject(object,name,s)    cJSON_AddItemToObject(object, name, cJSON_CreateString(s))
 
 2211+diff --git a/lib/ondataservice_light/src/compat.c b/lib/ondataservice_light/src/compat.c
 
 2212+new file mode 100644
 
 2213+index 0000000..4d639be
 
 2215++++ b/lib/ondataservice_light/src/compat.c
 
 2217++#include "compat.h"
 
 2219++#if !defined(__linux__) && !defined(__GLIBC__)
 
 2220++#include <stdlib.h>
 
 2221++#include <string.h>
 
 2223++/* strndup() is a GNU extention */
 
 2225++strndup(const char *ptr, size_t size)
 
 2227++  size_t len = strlen(ptr);
 
 2233++  ret = malloc(len + 1);
 
 2238++  memcpy(ret, ptr, len);
 
 2247++ * Local Variables:
 
 2248++ * c-basic-offset: 2
 
 2249++ * indent-tabs-mode: nil
 
 2252+diff --git a/lib/ondataservice_light/src/compat.h b/lib/ondataservice_light/src/compat.h
 
 2253+new file mode 100644
 
 2254+index 0000000..c607c91
 
 2256++++ b/lib/ondataservice_light/src/compat.h
 
 2258++#ifndef _NAMESERVICE_COMPAT
 
 2259++#define _NAMESERVICE_COMPAT
 
 2261++#include <sys/types.h>
 
 2263++#if !defined(__linux__) && !defined(__GLIBC__)
 
 2264++char *strndup(const char *ptr, size_t size);
 
 2270++ * Local Variables:
 
 2271++ * c-basic-offset: 2
 
 2272++ * indent-tabs-mode: nil
 
 2275+diff --git a/lib/ondataservice_light/src/crc16.c b/lib/ondataservice_light/src/crc16.c
 
 2276+new file mode 100644
 
 2277+index 0000000..dc877ca
 
 2279++++ b/lib/ondataservice_light/src/crc16.c
 
 2281++#include <stdlib.h>
 
 2284++// ------------ http://stackoverflow.com/questions/3853670/are-there-any-free-crc-libraries-that-covers-a-lot-of-the-crc-algorithms
 
 2286++/******************************************/
 
 2287++/*  CRC table for polynomial 0xA001 CCITT */
 
 2288++/******************************************/
 
 2290++#define CRC16(crc,c) crc = (crc >> 8) ^ crctab[(crc ^ c) & 0xff]
 
 2292++const u_int16_t crctab[256] = {
 
 2293++    0x0000, 0xc0c1, 0xc181, 0x0140, 0xc301, 0x03c0, 0x0280, 0xc241,
 
 2294++    0xc601, 0x06c0, 0x0780, 0xc741, 0x0500, 0xc5c1, 0xc481, 0x0440,
 
 2295++    0xcc01, 0x0cc0, 0x0d80, 0xcd41, 0x0f00, 0xcfc1, 0xce81, 0x0e40,
 
 2296++    0x0a00, 0xcac1, 0xcb81, 0x0b40, 0xc901, 0x09c0, 0x0880, 0xc841,
 
 2297++    0xd801, 0x18c0, 0x1980, 0xd941, 0x1b00, 0xdbc1, 0xda81, 0x1a40,
 
 2298++    0x1e00, 0xdec1, 0xdf81, 0x1f40, 0xdd01, 0x1dc0, 0x1c80, 0xdc41,
 
 2299++    0x1400, 0xd4c1, 0xd581, 0x1540, 0xd701, 0x17c0, 0x1680, 0xd641,
 
 2300++    0xd201, 0x12c0, 0x1380, 0xd341, 0x1100, 0xd1c1, 0xd081, 0x1040,
 
 2301++    0xf001, 0x30c0, 0x3180, 0xf141, 0x3300, 0xf3c1, 0xf281, 0x3240,
 
 2302++    0x3600, 0xf6c1, 0xf781, 0x3740, 0xf501, 0x35c0, 0x3480, 0xf441,
 
 2303++    0x3c00, 0xfcc1, 0xfd81, 0x3d40, 0xff01, 0x3fc0, 0x3e80, 0xfe41,
 
 2304++    0xfa01, 0x3ac0, 0x3b80, 0xfb41, 0x3900, 0xf9c1, 0xf881, 0x3840,
 
 2305++    0x2800, 0xe8c1, 0xe981, 0x2940, 0xeb01, 0x2bc0, 0x2a80, 0xea41,
 
 2306++    0xee01, 0x2ec0, 0x2f80, 0xef41, 0x2d00, 0xedc1, 0xec81, 0x2c40,
 
 2307++    0xe401, 0x24c0, 0x2580, 0xe541, 0x2700, 0xe7c1, 0xe681, 0x2640,
 
 2308++    0x2200, 0xe2c1, 0xe381, 0x2340, 0xe101, 0x21c0, 0x2080, 0xe041,
 
 2309++    0xa001, 0x60c0, 0x6180, 0xa141, 0x6300, 0xa3c1, 0xa281, 0x6240,
 
 2310++    0x6600, 0xa6c1, 0xa781, 0x6740, 0xa501, 0x65c0, 0x6480, 0xa441,
 
 2311++    0x6c00, 0xacc1, 0xad81, 0x6d40, 0xaf01, 0x6fc0, 0x6e80, 0xae41,
 
 2312++    0xaa01, 0x6ac0, 0x6b80, 0xab41, 0x6900, 0xa9c1, 0xa881, 0x6840,
 
 2313++    0x7800, 0xb8c1, 0xb981, 0x7940, 0xbb01, 0x7bc0, 0x7a80, 0xba41,
 
 2314++    0xbe01, 0x7ec0, 0x7f80, 0xbf41, 0x7d00, 0xbdc1, 0xbc81, 0x7c40,
 
 2315++    0xb401, 0x74c0, 0x7580, 0xb541, 0x7700, 0xb7c1, 0xb681, 0x7640,
 
 2316++    0x7200, 0xb2c1, 0xb381, 0x7340, 0xb101, 0x71c0, 0x7080, 0xb041,
 
 2317++    0x5000, 0x90c1, 0x9181, 0x5140, 0x9301, 0x53c0, 0x5280, 0x9241,
 
 2318++    0x9601, 0x56c0, 0x5780, 0x9741, 0x5500, 0x95c1, 0x9481, 0x5440,
 
 2319++    0x9c01, 0x5cc0, 0x5d80, 0x9d41, 0x5f00, 0x9fc1, 0x9e81, 0x5e40,
 
 2320++    0x5a00, 0x9ac1, 0x9b81, 0x5b40, 0x9901, 0x59c0, 0x5880, 0x9841,
 
 2321++    0x8801, 0x48c0, 0x4980, 0x8941, 0x4b00, 0x8bc1, 0x8a81, 0x4a40,
 
 2322++    0x4e00, 0x8ec1, 0x8f81, 0x4f40, 0x8d01, 0x4dc0, 0x4c80, 0x8c41,
 
 2323++    0x4400, 0x84c1, 0x8581, 0x4540, 0x8701, 0x47c0, 0x4680, 0x8641,
 
 2324++    0x8201, 0x42c0, 0x4380, 0x8341, 0x4100, 0x81c1, 0x8081, 0x4040
 
 2327++//=========================================================================
 
 2328++//  Description:   Calculate a CRC on a buffer
 
 2329++//  Parameters:    buffer - address of buffer
 
 2330++//                 length - length of buffer
 
 2332++//=========================================================================
 
 2333++u_int16_t crcCalculate(char *buffer, unsigned int length)
 
 2335++    u_int16_t Crc = 0;
 
 2337++    for (; length; --length) {
 
 2338++        CRC16(Crc, *buffer++);
 
 2343+diff --git a/lib/ondataservice_light/src/crc16.h b/lib/ondataservice_light/src/crc16.h
 
 2344+new file mode 100644
 
 2345+index 0000000..729d784
 
 2347++++ b/lib/ondataservice_light/src/crc16.h
 
 2350++// copied from http://stackoverflow.com/questions/3853670/are-there-any-free-crc-libraries-that-covers-a-lot-of-the-crc-algorithms
 
 2352++#include <sys/types.h>
 
 2354++u_int16_t crcCalculate(char *buffer, unsigned int length);
 
 2356+diff --git a/lib/ondataservice_light/src/olsrd_plugin.c b/lib/ondataservice_light/src/olsrd_plugin.c
 
 2357+new file mode 100644
 
 2358+index 0000000..c6989c5
 
 2360++++ b/lib/ondataservice_light/src/olsrd_plugin.c
 
 2364++ * Copyright (c) 2005, Bruno Randolf <bruno.randolf@4g-systems.biz>
 
 2365++ * Copyright (c) 2004, Andreas Tonnesen(andreto-at-olsr.org)
 
 2366++ * All rights reserved.
 
 2368++ * Redistribution and use in source and binary forms, with or without
 
 2369++ * modification, are permitted provided that the following conditions
 
 2372++ * * Redistributions of source code must retain the above copyright notice,
 
 2373++ *   this list of conditions and the following disclaimer.
 
 2374++ * * Redistributions in binary form must reproduce the above copyright notice,
 
 2375++ *   this list of conditions and the following disclaimer in the documentation
 
 2376++ *   and/or other materials provided with the distribution.
 
 2377++ * * Neither the name of the UniK olsr daemon nor the names of its contributors
 
 2378++ *   may be used to endorse or promote products derived from this software
 
 2379++ *   without specific prior written permission.
 
 2381++ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 
 2382++ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 
 2383++ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 
 2384++ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 
 2385++ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 
 2386++ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 
 2387++ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 
 2388++ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
 
 2389++ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 
 2390++ * OF THE POSSIBILITY OF SUCH DAMAGE.
 
 2395++ * Dynamic linked library for olsr.org olsrd
 
 2399++#include <string.h>
 
 2401++#include "olsrd_plugin.h"
 
 2402++#include "ondataservice.h"
 
 2404++#define MOD_DESC PLUGIN_NAME " " PLUGIN_VERSION
 
 2405++#define PLUGIN_INTERFACE_VERSION 5
 
 2407++static void __attribute__ ((constructor)) my_init(void);
 
 2409++static void __attribute__ ((destructor)) my_fini(void);
 
 2412++olsrd_plugin_interface_version(void)
 
 2414++  return PLUGIN_INTERFACE_VERSION;
 
 2418++olsrd_plugin_init(void)
 
 2420++  return ondata_init();
 
 2426++  /* Print plugin info to stdout */
 
 2427++  printf("%s\n", MOD_DESC);
 
 2429++  ondata_constructor();
 
 2437++  ondata_destructor();
 
 2441++ * Local Variables:
 
 2442++ * c-basic-offset: 2
 
 2443++ * indent-tabs-mode: nil
 
 2446+diff --git a/lib/ondataservice_light/src/ondataservice.c b/lib/ondataservice_light/src/ondataservice.c
 
 2447+new file mode 100644
 
 2448+index 0000000..4f685c9
 
 2450++++ b/lib/ondataservice_light/src/ondataservice.c
 
 2454++ * Copyright (c) 2011, Rene Ejury <opennet@absorb.it>
 
 2455++ * All rights reserved.
 
 2457++ * Redistribution and use in source and binary forms, with or without
 
 2458++ * modification, are permitted provided that the following conditions
 
 2461++ * * Redistributions of source code must retain the above copyright notice,
 
 2462++ *   this list of conditions and the following disclaimer.
 
 2463++ * * Redistributions in binary form must reproduce the above copyright notice,
 
 2464++ *   this list of conditions and the following disclaimer in the documentation
 
 2465++ *   and/or other materials provided with the distribution.
 
 2466++ * * Neither the name of the UniK olsr daemon nor the names of its contributors
 
 2467++ *   may be used to endorse or promote products derived from this software
 
 2468++ *   without specific prior written permission.
 
 2470++ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 
 2471++ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 
 2472++ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 
 2473++ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 
 2474++ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 
 2475++ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 
 2476++ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 
 2477++ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
 
 2478++ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 
 2479++ * OF THE POSSIBILITY OF SUCH DAMAGE.
 
 2484++ * Dynamic linked library for UniK OLSRd
 
 2487++#define _GNU_SOURCE 1
 
 2490++#include <string.h>
 
 2491++#include <stdlib.h>
 
 2492++#include <unistd.h>
 
 2494++#include <sys/types.h>
 
 2495++#include <sys/stat.h>
 
 2496++#include <signal.h>
 
 2502++#include "net_olsr.h"
 
 2503++#include "parser.h"
 
 2505++#include "plugin_util.h"
 
 2506++#include "ondataservice.h"
 
 2507++#include "compat.h"
 
 2511++/* config parameters */
 
 2512++static int my_interval = EMISSION_INTERVAL;
 
 2513++static int my_inc_interval = EMISSION_INC_INTERVAL;
 
 2514++static char my_database[MAX_FILE + 1];
 
 2515++static int my_vtime = ONDATA_VALID_TIME;            // how long the data will be spread trough the net
 
 2517++/* periodic message generation */
 
 2518++struct timer_entry *msg_gen_timer = NULL;
 
 2521++ * do initialization
 
 2524++ondata_constructor(void)
 
 2529++  GetWindowsDirectory(my_database, MAX_FILE - 12);
 
 2531++  len = strlen(my_database);
 
 2532++  if (my_database[len - 1] != '\\')
 
 2533++    strscat(my_database, "\\", sizeof(my_database));
 
 2534++  strscat(my_database, DATABASE_FILE, sizeof(my_database));
 
 2537++  strscpy(my_database, DATABASE_FILE, sizeof(my_database));
 
 2543++static const struct olsrd_plugin_parameters plugin_parameters[] = {
 
 2544++  { .name = "interval",           .set_plugin_parameter = &set_plugin_int,         .data = &my_interval },
 
 2545++  { .name = "inc_interval",            .set_plugin_parameter = &set_plugin_int,         .data = &my_inc_interval },
 
 2546++  { .name = "database",          .set_plugin_parameter = &set_plugin_string,      .data = &my_database,          .addon = {sizeof(my_database)} },
 
 2547++  { .name = "vtime",            .set_plugin_parameter = &set_plugin_int,     .data = &my_vtime },
 
 2552++olsrd_get_plugin_parameters(const struct olsrd_plugin_parameters **params, int *size)
 
 2554++  *params = plugin_parameters;
 
 2555++  *size = sizeof(plugin_parameters) / sizeof(*plugin_parameters);
 
 2559++ * last initialization
 
 2561++ * we have to do this here because some things like main_addr
 
 2562++ * or the dns suffix (for validation) are not known before
 
 2564++ * this is beause of the order in which the plugin is initialized
 
 2565++ * by the plugin loader:
 
 2566++ *   - first the parameters are sent
 
 2567++ *   - then register_olsr_data() from olsrd_plugin.c is called
 
 2568++ *     which sets up main_addr and some other variables
 
 2569++ *   - register_olsr_data() then then finally calls this function
 
 2574++  /* periodic message generation */
 
 2575++  msg_gen_timer = olsr_start_timer(my_interval * MSEC_PER_SEC, EMISSION_JITTER, OLSR_TIMER_PERIODIC, &olsr_ondatasvc_gen, NULL, 0);
 
 2581++ * called at unload: free everything
 
 2583++ * XXX: should I delete the hosts/services/resolv.conf files on exit?
 
 2586++ondata_destructor(void)
 
 2588++  olsr_stop_timer(msg_gen_timer);
 
 2592++ * Scheduled event: generate and send ONDATA packet
 
 2595++olsr_ondatasvc_gen(void *foo __attribute__ ((unused)))
 
 2597++  /* send buffer: huge */
 
 2598++  char buffer[10240];
 
 2599++  union olsr_message *message = (union olsr_message *)buffer;
 
 2600++  struct interface_olsr *ifn;
 
 2603++  /* fill message */
 
 2604++  if (olsr_cnf->ip_version == AF_INET) {
 
 2606++    message->v4.olsr_msgtype = MESSAGE_TYPE;
 
 2607++    message->v4.olsr_vtime = reltime_to_me((double)my_vtime * MSEC_PER_SEC);
 
 2608++    memcpy(&message->v4.originator, &olsr_cnf->main_addr, olsr_cnf->ipsize);
 
 2609++    message->v4.ttl = MAX_TTL;
 
 2610++    message->v4.hopcnt = 0;
 
 2611++    message->v4.seqno = htons(get_msg_seqno());
 
 2613++    ondatasize = encap_ondatamsg((struct ondatamsg *)ARM_NOWARN_ALIGN(&message->v4.message));
 
 2614++    if (!ondatasize) return;
 
 2615++    ondatasize = ondatasize + sizeof(struct olsrmsg);
 
 2616++    message->v4.olsr_msgsize = htons(ondatasize);
 
 2619++    message->v6.olsr_msgtype = MESSAGE_TYPE;
 
 2620++    message->v6.olsr_vtime = reltime_to_me((double)my_vtime * MSEC_PER_SEC);
 
 2621++    memcpy(&message->v6.originator, &olsr_cnf->main_addr, olsr_cnf->ipsize);
 
 2622++    message->v6.ttl = MAX_TTL;
 
 2623++    message->v6.hopcnt = 0;
 
 2624++    message->v6.seqno = htons(get_msg_seqno());
 
 2626++    ondatasize = encap_ondatamsg((struct ondatamsg *)ARM_NOWARN_ALIGN(&message->v6.message));
 
 2627++    if (!ondatasize) return;
 
 2628++    ondatasize = ondatasize + sizeof(struct olsrmsg6);
 
 2630++    message->v6.olsr_msgsize = htons(ondatasize);
 
 2633++  /* looping trough interfaces */
 
 2634++  for (ifn = ifnet; ifn; ifn = ifn->int_next) {
 
 2635++    OLSR_PRINTF(3, "ONDATA PLUGIN: Generating packet - [%s]\n", ifn->int_name);
 
 2637++    if (net_outbuffer_push(ifn, message, ondatasize) != ondatasize) {
 
 2638++      /* send data and try again */
 
 2640++      if (net_outbuffer_push(ifn, message, ondatasize) != ondatasize) {
 
 2641++        OLSR_PRINTF(1, "ONDATA PLUGIN: could not send on interface: %s\n", ifn->int_name);
 
 2647++// Database Variables / should be kept over different calls, therefore global
 
 2651++ * Encapsulate a ondata message into a packet.
 
 2653++ * It assumed that there is enough space in the buffer to do this!
 
 2655++ * Returns: the length of the message that was appended
 
 2658++encap_ondatamsg(struct ondatamsg *msg)
 
 2660++  struct ipaddr_str main_addr;
 
 2663++  uint16_t checksum;
 
 2664++  uint16_t messageLength = 0;
 
 2665++  cJSON *json = NULL, *elem;
 
 2666++  char line [ 10000 ]; /* or other suitable maximum line size */
 
 2668++  // open Database if this not a 'continued Transmission - and Database is already open'
 
 2670++    OLSR_PRINTF(0, "ONDATA PLUGIN: opening json file\n");
 
 2672++    fp=fopen(my_database, "r");
 
 2675++      fprintf(stderr, "Can't open json file %s\n", my_database);
 
 2680++  // search next Table with Data
 
 2682++    if ( fgets ( line, sizeof line, fp ) != NULL ) {
 
 2683++      json=cJSON_Parse(line);
 
 2687++  // if no further Table give up
 
 2689++    OLSR_PRINTF(0, "ONDATA PLUGIN: no further table found\n");
 
 2690++    olsr_change_timer(msg_gen_timer, my_interval * MSEC_PER_SEC, EMISSION_JITTER, OLSR_TIMER_PERIODIC);
 
 2696++  OLSR_PRINTF(0, "ONDATA PLUGIN: using next table %s\n", json->child->string);
 
 2698++  // add all datasets
 
 2699++  OLSR_PRINTF(0, "ONDATA PLUGIN: adding all datasets\n");
 
 2700++  // add all the entries after the ondatamsg header (and keep space for it)
 
 2701++  pos = (char *)msg + sizeof(struct ondatamsg);
 
 2703++  // always add the Table-Name as first field
 
 2704++  pos = create_packet((struct ondata *)ARM_NOWARN_ALIGN(pos), json->child->string);
 
 2706++  // never transmit originator (col=0), this will be detected at the other end_pos
 
 2707++  elem = json->child->child->next;
 
 2708++  // skip last column, it will set at destination to the receiving-time
 
 2711++    pos = create_packet((struct ondata *)ARM_NOWARN_ALIGN(pos), elem->valuestring);
 
 2713++    elem = elem->next;
 
 2714++  } while(elem->next);
 
 2715++  cJSON_Delete(json);
 
 2717++  // write the ondatamsg header with the number of announced entries and the protocol version
 
 2718++  msg->nr_datasets = htons(--iCol);   // it won't count the table-name as dataset (and neither mainip-Col)
 
 2719++  msg->version = htons(ONDATA_PROTOCOL_VERSION);
 
 2720++  messageLength = pos - (char *)msg;
 
 2721++  msg->length = htons(messageLength);
 
 2722++  checksum = crcCalculate((char *)msg + sizeof(uint16_t), messageLength - sizeof(uint16_t));
 
 2723++  msg->checksum = htons(checksum);
 
 2725++  OLSR_PRINTF(0, "ONDATA PLUGIN: ##### finished creating packet, length=%d, crc16=0x%x\n", messageLength, checksum);
 
 2727++  // increase Transmission-Time as long as there is data
 
 2728++  olsr_change_timer(msg_gen_timer, 1 * MSEC_PER_SEC, EMISSION_JITTER, OLSR_TIMER_PERIODIC);
 
 2729++  return messageLength;     //length
 
 2733++ * convert each of my to be announced ondata_entries into network
 
 2734++ * compatible format
 
 2736++ * return the length of the ondata packet
 
 2739++create_packet(struct ondata *to, const char *value )
 
 2741++  char *pos = (char *)to;  int valuelen = strlen((const char*)value);
 
 2743++  to->valuelen = htons(valuelen);
 
 2744++  OLSR_PRINTF(5, "ONDATA PLUGIN: Announcing value %s %d\n", value, valuelen);
 
 2745++  pos += sizeof(struct ondata);
 
 2746++  memcpy(pos, value, valuelen);
 
 2748++  // do 4-byte padding
 
 2749++  for (k = sizeof(struct ondata) + valuelen; (k & 3) != 0; k++)
 
 2756++ * Local Variables:
 
 2758++ * c-indent-tabs-mode: t
 
 2759++ * indent-tabs-mode: t
 
 2760++ * c-basic-offset: 4
 
 2765+diff --git a/lib/ondataservice_light/src/ondataservice.h b/lib/ondataservice_light/src/ondataservice.h
 
 2766+new file mode 100644
 
 2767+index 0000000..aea2f4c
 
 2769++++ b/lib/ondataservice_light/src/ondataservice.h
 
 2773++ * Copyright (c) 2011, Rene Ejury <opennet@absorb.it>
 
 2774++ * All rights reserved.
 
 2776++ * Redistribution and use in source and binary forms, with or without
 
 2777++ * modification, are permitted provided that the following conditions
 
 2780++ * * Redistributions of source code must retain the above copyright notice,
 
 2781++ *   this list of conditions and the following disclaimer.
 
 2782++ * * Redistributions in binary form must reproduce the above copyright notice,
 
 2783++ *   this list of conditions and the following disclaimer in the documentation
 
 2784++ *   and/or other materials provided with the distribution.
 
 2785++ * * Neither the name of the UniK olsr daemon nor the names of its contributors
 
 2786++ *   may be used to endorse or promote products derived from this software
 
 2787++ *   without specific prior written permission.
 
 2789++ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 
 2790++ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 
 2791++ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 
 2792++ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 
 2793++ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 
 2794++ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 
 2795++ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 
 2796++ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
 
 2797++ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 
 2798++ * OF THE POSSIBILITY OF SUCH DAMAGE.
 
 2803++ * Dynamic linked library for UniK OLSRd
 
 2806++#ifndef _ONDATASERVICE_PLUGIN
 
 2807++#define _ONDATASERVICE_PLUGIN
 
 2809++#include <sys/time.h>
 
 2810++// #include <regex.h>
 
 2812++#include "olsr_types.h"
 
 2813++#include "interfaces.h"
 
 2814++#include "olsr_protocol.h"
 
 2815++#include "common/list.h"
 
 2817++#include "olsrd_plugin.h"
 
 2818++#include "ondataservice_msg.h"
 
 2819++#include "hashing.h"
 
 2820++// #include "mapwrite.h"
 
 2821++// #include "mantissa.h"
 
 2823++#define PLUGIN_NAME       "OLSRD ondataservice plugin"
 
 2824++#define PLUGIN_VERSION        "0.3"
 
 2825++#define PLUGIN_AUTHOR     "Rene Ejury, Bruno Randolf, Jens Nachtigall, Sven-Ola Tuecke"
 
 2826++#define DATABASE_FILE   "/tmp/database.json"
 
 2828++#define MESSAGE_TYPE      222 /* hope this is a good choice */
 
 2829++#define PARSER_TYPE           MESSAGE_TYPE
 
 2830++#define EMISSION_INTERVAL 10800 /* seconds - 10800 = 3hours */
 
 2831++#define EMISSION_INC_INTERVAL   5 /* seconds between transmission of rows from one dataset */
 
 2832++#define EMISSION_JITTER         25  /* percent */
 
 2833++#define ONDATA_VALID_TIME 300  /* seconds, how long a package should maximally be spreaded through the net - 300 - 5mins*/
 
 2835++#define ONDATA_PROTOCOL_VERSION   1
 
 2837++#define MAX_FILE      255
 
 2839++/* Parser function to register with the scheduler */
 
 2840++bool olsr_parser(union olsr_message *, struct interface_olsr *, union olsr_ip_addr *);
 
 2842++/* callback for periodic timer */
 
 2843++void olsr_ondatasvc_gen(void *);
 
 2845++/* callback for database cleanup */
 
 2846++void olsr_ondataservice_expire_db_timer(void *);
 
 2848++int encap_ondatamsg(struct ondatamsg *);
 
 2850++void update_ondata_entry(union olsr_ip_addr *, struct ondatamsg *, int);
 
 2852++int register_olsr_param(char *key, char *value);
 
 2855++char *create_packet(struct ondata *to, const char *value);
 
 2857++void ondata_constructor(void);
 
 2859++void ondata_destructor(void);
 
 2861++int ondata_init(void);
 
 2866++ * Local Variables:
 
 2867++ * c-basic-offset: 2
 
 2868++ * indent-tabs-mode: nil
 
 2872+diff --git a/lib/ondataservice_light/src/ondataservice_msg.h b/lib/ondataservice_light/src/ondataservice_msg.h
 
 2873+new file mode 100644
 
 2874+index 0000000..b22fbee
 
 2876++++ b/lib/ondataservice_light/src/ondataservice_msg.h
 
 2880++ * Copyright (c) 2005, Bruno Randolf <bruno.randolf@4g-systems.biz>
 
 2881++ * Copyright (c) 2004, Andreas Tonnesen(andreto-at-olsr.org)
 
 2882++ * All rights reserved.
 
 2884++ * Redistribution and use in source and binary forms, with or without
 
 2885++ * modification, are permitted provided that the following conditions
 
 2888++ * * Redistributions of source code must retain the above copyright notice,
 
 2889++ *   this list of conditions and the following disclaimer.
 
 2890++ * * Redistributions in binary form must reproduce the above copyright notice,
 
 2891++ *   this list of conditions and the following disclaimer in the documentation
 
 2892++ *   and/or other materials provided with the distribution.
 
 2893++ * * Neither the name of the UniK olsr daemon nor the names of its contributors
 
 2894++ *   may be used to endorse or promote products derived from this software
 
 2895++ *   without specific prior written permission.
 
 2897++ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 
 2898++ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 
 2899++ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 
 2900++ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 
 2901++ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 
 2902++ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 
 2903++ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 
 2904++ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
 
 2905++ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 
 2906++ * OF THE POSSIBILITY OF SUCH DAMAGE.
 
 2911++ * Dynamic linked library for UniK OLSRd
 
 2914++#ifndef _ONDATASERVICE_MSG
 
 2915++#define _ONDATASERVICE_MSG
 
 2918++ * the data, forwarder or service entry as found in a packet within a
 
 2922++  uint16_t valuelen;                     // length of the value
 
 2924++   * value is written separatedly in plain text after this struct and padded to 4 byte
 
 2929++  uint16_t checksum;
 
 2930++  uint16_t version;                     // version number of the ondataservice plugin
 
 2931++  uint16_t nr_datasets;                 // number of following packets including all the data
 
 2932++  uint16_t length;                      // length in bytes / required to calculate checksum on receive
 
 2934++   * at least one struct name following
 
 2941++ * Local Variables:
 
 2942++ * c-basic-offset: 2
 
 2943++ * indent-tabs-mode: nil
 
 2946+diff --git a/lib/ondataservice_light/version-script.txt b/lib/ondataservice_light/version-script.txt
 
 2947+new file mode 100644
 
 2948+index 0000000..a145659
 
 2950++++ b/lib/ondataservice_light/version-script.txt
 
 2955++    olsrd_plugin_interface_version;
 
 2956++    olsrd_plugin_init;
 
 2957++    olsrd_get_plugin_parameters;