Opennet Firmware
 Alle Dateien Funktionen Variablen Gruppen Seiten
olsrd_add_ondataservice.patch
gehe zur Dokumentation dieser Datei
1 Quelle: http://absorb.it/software/opennet/ondataservice/olsrd-0.6.6.2.tgz
2 --- a/routing/olsrd/Makefile
3 +++ b/routing/olsrd/Makefile
4 @@ -95,6 +95,18 @@ define Package/olsrd-mod-nameservice
5  TITLE:=Lightweight hostname resolver plugin
6  endef
7 
8 +define Package/olsrd-mod-ondataservice
9 + $(call Package/olsrd/template)
10 + DEPENDS:=olsrd +libsqlite3 +sqlite3-cli
11 + TITLE:=Opennet Dataservice SQLite3 plugin
12 +endef
13 +
14 +define Package/olsrd-mod-ondataservice_light
15 + $(call Package/olsrd/template)
16 + DEPENDS:=olsrd
17 + TITLE:=Opennet Dataservice JSON plugin
18 +endef
19 +
20  define Package/olsrd-mod-p2pd
21  $(call Package/olsrd/template)
22  DEPENDS:=olsrd
23 @@ -162,7 +174,7 @@ MAKE_FLAGS+= \
24  DESTDIR="$(PKG_INSTALL_DIR)" \
25  STRIP="true" \
26  INSTALL_LIB="true" \
27 - SUBDIRS="arprefresh bmf dot_draw dyn_gw dyn_gw_plain httpinfo jsoninfo mdns nameservice p2pd pgraph pud quagga secure sgwdynspeed txtinfo watchdog"
28 + SUBDIRS="arprefresh bmf dot_draw dyn_gw dyn_gw_plain httpinfo jsoninfo mdns nameservice ondataservice ondataservice_light p2pd pgraph pud quagga secure sgwdynspeed txtinfo watchdog"
29 
30  define Build/Compile
31  $(call Build/Compile/Default,all)
32 @@ -229,6 +241,16 @@ define Package/olsrd-mod-nameservice/ins
33  $(INSTALL_BIN) $(PKG_BUILD_DIR)/lib/nameservice/olsrd_nameservice.so.* $(1)/usr/lib/
34  endef
35 
36 +define Package/olsrd-mod-ondataservice/install
37 + $(INSTALL_DIR) $(1)/usr/lib
38 + $(INSTALL_BIN) $(PKG_BUILD_DIR)/lib/ondataservice/olsrd_ondataservice.so.* $(1)/usr/lib/
39 +endef
40 +
41 +define Package/olsrd-mod-ondataservice_light/install
42 + $(INSTALL_DIR) $(1)/usr/lib
43 + $(INSTALL_BIN) $(PKG_BUILD_DIR)/lib/ondataservice_light/olsrd_ondataservice_light.so.* $(1)/usr/lib/
44 +endef
45 +
46  define Package/olsrd-mod-p2pd/install
47  $(INSTALL_DIR) $(1)/usr/lib
48  $(INSTALL_BIN) $(PKG_BUILD_DIR)/lib/p2pd/olsrd_p2pd.so.* $(1)/usr/lib/
49 @@ -287,6 +309,8 @@ $(eval $(call BuildPackage,olsrd-mod-htt
50  $(eval $(call BuildPackage,olsrd-mod-jsoninfo))
51  $(eval $(call BuildPackage,olsrd-mod-mdns))
52  $(eval $(call BuildPackage,olsrd-mod-nameservice))
53 +$(eval $(call BuildPackage,olsrd-mod-ondataservice))
54 +$(eval $(call BuildPackage,olsrd-mod-ondataservice_light))
55  $(eval $(call BuildPackage,olsrd-mod-p2pd))
56  $(eval $(call BuildPackage,olsrd-mod-pgraph))
57  $(eval $(call BuildPackage,olsrd-mod-pud))
58 --- /dev/null
59 +++ b/routing/olsrd/info.txt
60 @@ -0,0 +1,29 @@
61 +olsrd fuer Opennet
62 +==================
63 +
64 +Problemlage
65 +-----------
66 +
67 +* wir verwenden ein olsrd-Plugin namens ondataservice zur Erfassung von AP-Informationen
68 +* das Plugin funktioniert (nach einem fluechtigen Test) nicht mit olsrd v0.6.6 (segfault innerhalb von Minuten)
69 + * diese Tests fanden auf dem yurika-Server statt
70 +
71 +
72 +Kurzfristiger Workaround
73 +------------------------
74 +
75 +Die Quelle der aktuellen olsrd-Version ist folgender Commit des routing-Repositories:
76 + commit f7dfc4f2a55b39cfb5ef06b075264d05c82761d3
77 + Author: Saverio Proto <zioproto@gmail.com>
78 + Date: Fri Jul 6 00:19:26 2012 +0000
79 +
80 +
81 +Langfristige Loesung
82 +--------------------
83 +
84 +* Test und gegenenfalls Anpassung des ondataservice-Plugin auf eine aktuelle olsrd-Version
85 +* Übertragung des ondataservice-Patches (siehe patches-Verzeichnis im olsrd-Verzeichnis) in das Routing-Repository
86 +* Übertragung des Makefile-Patches (Makefile_ondataservice.patch) in das meta-Patches-Verzeichnis
87 +
88 +Eine Integration des ondataservice-Plugin in den olsrd-Upstream-Code wurde im jahr 2013 kurz auf der Mailingliste erwogen, wird aber wohl nicht stattfinden.
89 +
90 --- /dev/null
91 +++ b/routing/olsrd/patches/023-ondataservice.patch
92 @@ -0,0 +1,2895 @@
93 +diff --git a/Makefile b/Makefile
94 +index 8ce6dc5..cf3b410 100644
95 +--- a/Makefile
96 ++++ b/Makefile
97 +@@ -197,7 +197,7 @@ rpm:
98 +
99 + # This is quite ugly but at least it works
100 + ifeq ($(OS),linux)
101 +-SUBDIRS := arprefresh bmf dot_draw dyn_gw dyn_gw_plain httpinfo jsoninfo mdns mini nameservice p2pd pgraph pud quagga secure sgwdynspeed txtinfo watchdog
102 ++SUBDIRS := arprefresh bmf dot_draw dyn_gw dyn_gw_plain httpinfo jsoninfo mdns mini nameservice p2pd pgraph pud quagga secure sgwdynspeed txtinfo watchdog ondataservice ondataservice_light
103 + else
104 + ifeq ($(OS),win32)
105 + SUBDIRS := dot_draw httpinfo jsoninfo mini pgraph secure txtinfo
106 +@@ -449,6 +449,29 @@ watchdog_install:
107 + watchdog_uninstall:
108 + $(MAKECMDPREFIX)$(MAKECMD) -C lib/watchdog DESTDIR=$(DESTDIR) uninstall
109 +
110 ++ondataservice:
111 ++ $(MAKECMDPREFIX)$(MAKECMD) -C lib/ondataservice
112 ++
113 ++ondataservice_clean:
114 ++ $(MAKECMDPREFIX)$(MAKECMD) -C lib/ondataservice clean
115 ++
116 ++ondataservice_install:
117 ++ $(MAKECMDPREFIX)$(MAKECMD) -C lib/ondataservice DESTDIR=$(DESTDIR) install
118 ++
119 ++ondataservice_uninstall:
120 ++ $(MAKECMDPREFIX)$(MAKECMD) -C lib/ondataservice DESTDIR=$(DESTDIR) uninstall
121 ++
122 ++ondataservice_light:
123 ++ $(MAKECMDPREFIX)$(MAKECMD) -C lib/ondataservice_light
124 ++
125 ++ondataservice_light_clean:
126 ++ $(MAKECMDPREFIX)$(MAKECMD) -C lib/ondataservice_light clean
127 ++
128 ++ondataservice_light_install:
129 ++ $(MAKECMDPREFIX)$(MAKECMD) -C lib/ondataservice_light DESTDIR=$(DESTDIR) install
130 ++
131 ++ondataservice_light_uninstall:
132 ++ $(MAKECMDPREFIX)$(MAKECMD) -C lib/ondataservice_light DESTDIR=$(DESTDIR) uninstall
133 +
134 + build_all: all switch libs
135 + install_all: install install_libs
136 +diff --git a/lib/ondataservice/Makefile b/lib/ondataservice/Makefile
137 +new file mode 100644
138 +index 0000000..951ed28
139 +--- /dev/null
140 ++++ b/lib/ondataservice/Makefile
141 +@@ -0,0 +1,79 @@
142 ++# The olsr.org Optimized Link-State Routing daemon(olsrd)
143 ++# Copyright (c) 2004, Andreas Tonnesen(andreto@olsr.org)
144 ++# All rights reserved.
145 ++#
146 ++# Redistribution and use in source and binary forms, with or without
147 ++# modification, are permitted provided that the following conditions
148 ++# are met:
149 ++#
150 ++# * Redistributions of source code must retain the above copyright
151 ++# notice, this list of conditions and the following disclaimer.
152 ++# * Redistributions in binary form must reproduce the above copyright
153 ++# notice, this list of conditions and the following disclaimer in
154 ++# the documentation and/or other materials provided with the
155 ++# distribution.
156 ++# * Neither the name of olsr.org, olsrd nor the names of its
157 ++# contributors may be used to endorse or promote products derived
158 ++# from this software without specific prior written permission.
159 ++#
160 ++# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
161 ++# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
162 ++# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
163 ++# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
164 ++# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
165 ++# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
166 ++# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
167 ++# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
168 ++# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
169 ++# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
170 ++# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
171 ++# POSSIBILITY OF SUCH DAMAGE.
172 ++#
173 ++# Visit http://www.olsr.org for more information.
174 ++#
175 ++# If you find this software useful feel free to make a donation
176 ++# to the project. For more information see the website or contact
177 ++# the copyright holders.
178 ++#
179 ++
180 ++OLSRD_PLUGIN = true
181 ++PLUGIN_NAME = olsrd_ondataservice
182 ++# dont change version here for backward-compatible changes,
183 ++# it will change the library name and won't load with the
184 ++# olsrd-config already existing on the device
185 ++PLUGIN_VER = 0.1
186 ++
187 ++LIBS += -lsqlite3
188 ++
189 ++TOPDIR = ../..
190 ++include $(TOPDIR)/Makefile.inc
191 ++
192 ++ifeq ($(OS),win32)
193 ++default_target install clean:
194 ++ @echo "**** We use the regex library here. Does Win32 has something like this?"
195 ++else
196 ++ifeq ($(OS),android)
197 ++# On Android Google forgot to include regex engine code for Froyo version (but also there was
198 ++# no support in older versions for it) so we have here this missing code.
199 ++# http://groups.google.com/group/android-ndk/browse_thread/thread/5ea6f0650f0e3fc
200 ++SRCS += $(wildcard $(TOPDIR)/android/regex/reg*.c)
201 ++HDRS += $(wildcard $(TOPDIR)/android/regex/*.h)
202 ++CFLAGS += -D__POSIX_VISIBLE
203 ++endif
204 ++
205 ++default_target: $(PLUGIN_FULLNAME)
206 ++
207 ++$(PLUGIN_FULLNAME): $(OBJS) version-script.txt
208 ++ @echo "[LD] $@"
209 ++ @$(CC) $(LDFLAGS) -o $(PLUGIN_FULLNAME) $(OBJS) $(LIBS)
210 ++
211 ++install: $(PLUGIN_FULLNAME)
212 ++ $(STRIP) $(PLUGIN_FULLNAME)
213 ++ $(INSTALL_LIB)
214 ++
215 ++uninstall:
216 ++ $(UNINSTALL_LIB)
217 ++
218 ++clean:
219 ++ rm -f $(OBJS) $(SRCS:%.c=%.d) $(PLUGIN_FULLNAME)
220 ++endif
221 +diff --git a/lib/ondataservice/README_ONDATASERVICE b/lib/ondataservice/README_ONDATASERVICE
222 +new file mode 100644
223 +index 0000000..0aae865
224 +--- /dev/null
225 ++++ b/lib/ondataservice/README_ONDATASERVICE
226 +@@ -0,0 +1,74 @@
227 ++---------------------------------------------------------------------
228 ++ONDATASERVICE PLUGIN FOR OLSRD
229 ++by Rene Ejury <opennet@absorb.it>
230 ++based on and copied from:
231 ++NAMESERVICE PLUGIN FOR OLSRD
232 ++by Bruno Randolf <bruno.randolf@4g-systems.biz>
233 ++---------------------------------------------------------------------
234 ++ full version, can receive data but requires sqlite3-library
235 ++
236 ++---------------------------------------------------------------------
237 ++PLUGIN PARAMETERS (PlParam)
238 ++---------------------------------------------------------------------
239 ++
240 ++PlParam "interval" "SEC"
241 ++ interval for sending the DATABASE in seconds.
242 ++ (default: 10800 - 3 hours)
243 ++
244 ++PlParam "inc_interval" "SEC"
245 ++ interval for continously sending TABLES from DATABASE in seconds.
246 ++ (default: 5 seconds)
247 ++
248 ++PlParam "cleanup_interval" "SEC"
249 ++ Interval how often DATABASE should be checked for old DATASETS.
250 ++ (default: 1800 - 0.5 hours)
251 ++
252 ++PlParam "timeout" "SEC"
253 ++ validity time for received NAME messages in seconds.
254 ++ (how long received data stays in the database)
255 ++ (default: 21600 - 6 hours)
256 ++
257 ++PlParam "vtime" "SEC"
258 ++ validity time for sended message-packages in seconds.
259 ++ (how long this message-data is forwarded through the net)
260 ++ (default: 300 - 5 mins)
261 ++
262 ++PlParam "database" "/path/to/database"
263 ++ Path to the database
264 ++
265 ++PlParam "dbcreatescript" "/path/to/dbcreatescript"
266 ++ Path to some executable script to create the database. This will
267 ++ be called anytime the database can't be opened.
268 ++ script will be called with database-path (see PlParam above)
269 ++ as only parameter
270 ++ (default not set, database is not created if not existent)
271 ++
272 ++PlParam "dberrorscript" "/path/to/dberrorscript"
273 ++ Path to some executable script to check if the database is ok and
274 ++ create the database in case of error. This will be called anytime
275 ++ some data can't be written to the database.
276 ++ script will be called with database-path (see PlParam above)
277 ++ as only parameter
278 ++ (default not set, database is not re-created if there are problems)
279 ++
280 ++PlParam "receive" "false|true"
281 ++ Set to true if you like to receive and store the values.
282 ++ Otherwise the values from other Nodes are ignored.
283 ++ (default: false - not stored)
284 ++
285 ++PlParam "spreadall" "false|true"
286 ++ Set to true if you like to spread all data from the database.
287 ++ (default: false - only data for own mainip is spreaded)
288 ++
289 ++---------------------------------------------------------------------
290 ++SAMPLE CONFIG
291 ++---------------------------------------------------------------------
292 ++
293 ++add in /etc/olsrd.conf:
294 ++
295 ++LoadPlugin "olsrd_ondataservice.so.0.1"
296 ++{
297 ++ PlParam "interval" "120"
298 ++ PlParam "timeout" "300"
299 ++ PlParam "database" "/tmp/database"
300 ++}
301 +diff --git a/lib/ondataservice/SAMPLE_DBCREATESCRIPT.sh b/lib/ondataservice/SAMPLE_DBCREATESCRIPT.sh
302 +new file mode 100755
303 +index 0000000..22dd4e9
304 +--- /dev/null
305 ++++ b/lib/ondataservice/SAMPLE_DBCREATESCRIPT.sh
306 +@@ -0,0 +1,34 @@
307 ++#!/bin/sh
308 ++SQL_STRING="CREATE TABLE nodes
309 ++ (originator text, mainip text, sys_ver text, sys_board text, sys_cpu text, sys_mem int, sys_uptime text,
310 ++ sys_load text, sys_free int, sys_watchdog bool, sys_os_type text,
311 ++ sys_os_name text, sys_os_rel text, sys_os_ver text, sys_os_arc text,
312 ++ sys_os_insttime int, on_core_ver text, on_core_insttime int, on_packages text,
313 ++ on_id text, on_olsrd_status text, on_olsrd_mainip text,
314 ++ on_wifidog_status bool, on_wifidog_id text, on_vpn_cn text, on_vpn_status bool,
315 ++ on_vpn_gw text, on_vpn_autosearch bool, on_vpn_sort text, on_vpn_gws text, on_vpn_blist text,
316 ++ on_ugw_status bool, on_ugw_enabled bool, on_ugw_possible bool, on_ugw_tunnel bool,
317 ++ on_ugw_connected text, on_ugw_presetips text, on_ugw_presetnames text,
318 ++ on_old_autoadapttxpwr text, on_old_remoteconf text,
319 ++ db_time text, db_epoch int, db_ver text, db_update int, CONSTRAINT key_nodes PRIMARY KEY (mainip) ON CONFLICT REPLACE);
320 ++
321 ++ CREATE TABLE ifaces
322 ++ (originator text, mainip text, if_name text, if_type_bridge text, if_type_bridgedif bool, if_hwaddr text,
323 ++ ip_label text, ip_addr text, ip_broadcast text,
324 ++ on_networks text, on_zones text, on_olsr bool,
325 ++ dhcp_start text, dhcp_limit text, dhcp_leasetime text, dhcp_fwd text,
326 ++ ifstat_collisions int, ifstat_rx_compressed int, ifstat_rx_errors int,
327 ++ ifstat_rx_length_errors int, ifstat_rx_packets int, ifstat_tx_carrier_errors int,
328 ++ ifstat_tx_errors int, ifstat_tx_packets int, ifstat_multicast int,
329 ++ ifstat_rx_crc_errors int, ifstat_rx_fifo_errors int, ifstat_rx_missed_errors int,
330 ++ ifstat_tx_aborted_errors int, ifstat_tx_compressed int, ifstat_tx_fifo_errors int,
331 ++ ifstat_tx_window_errors int, ifstat_rx_bytes int, ifstat_rx_dropped int,
332 ++ ifstat_rx_frame_errors int, ifstat_rx_over_errors int, ifstat_tx_bytes int,
333 ++ ifstat_tx_dropped int, ifstat_tx_heartbeat_errors int,
334 ++ wlan_essid text, wlan_apmac text, wlan_type text, wlan_hwmode text, wlan_mode text,
335 ++ wlan_channel text, wlan_freq text, wlan_txpower text, wlan_signal text, wlan_noise text,
336 ++ wlan_bitrate text, wlan_crypt text, wlan_vaps text,
337 ++ db_ver text, db_update int, CONSTRAINT key_ifaces PRIMARY KEY (mainip, if_name) ON CONFLICT REPLACE);"
338 ++
339 ++sqlite3 -batch $1 "$SQL_STRING"
340 ++
341 +diff --git a/lib/ondataservice/SAMPLE_DBERRORSCRIPT.sh b/lib/ondataservice/SAMPLE_DBERRORSCRIPT.sh
342 +new file mode 100755
343 +index 0000000..cd81e77
344 +--- /dev/null
345 ++++ b/lib/ondataservice/SAMPLE_DBERRORSCRIPT.sh
346 +@@ -0,0 +1,39 @@
347 ++#!/bin/sh
348 ++SQL_STRING="CREATE TABLE nodes
349 ++ (originator text, mainip text, sys_ver text, sys_board text, sys_cpu text, sys_mem int, sys_uptime text,
350 ++ sys_load text, sys_free int, sys_watchdog bool, sys_os_type text,
351 ++ sys_os_name text, sys_os_rel text, sys_os_ver text, sys_os_arc text,
352 ++ sys_os_insttime int, on_core_ver text, on_core_insttime int, on_packages text,
353 ++ on_id text, on_olsrd_status text, on_olsrd_mainip text,
354 ++ on_wifidog_status bool, on_wifidog_id text, on_vpn_cn text, on_vpn_status bool,
355 ++ on_vpn_gw text, on_vpn_autosearch bool, on_vpn_sort text, on_vpn_gws text, on_vpn_blist text,
356 ++ on_ugw_status bool, on_ugw_enabled bool, on_ugw_possible bool, on_ugw_tunnel bool,
357 ++ on_ugw_connected text, on_ugw_presetips text, on_ugw_presetnames text,
358 ++ on_old_autoadapttxpwr text, on_old_remoteconf text,
359 ++ db_time text, db_epoch int, db_ver text, db_update int, CONSTRAINT key_nodes PRIMARY KEY (mainip) ON CONFLICT REPLACE);
360 ++
361 ++ CREATE TABLE ifaces
362 ++ (originator text, mainip text, if_name text, if_type_bridge text, if_type_bridgedif bool, if_hwaddr text,
363 ++ ip_label text, ip_addr text, ip_broadcast text,
364 ++ on_networks text, on_zones text, on_olsr bool,
365 ++ dhcp_start text, dhcp_limit text, dhcp_leasetime text, dhcp_fwd text,
366 ++ ifstat_collisions int, ifstat_rx_compressed int, ifstat_rx_errors int,
367 ++ ifstat_rx_length_errors int, ifstat_rx_packets int, ifstat_tx_carrier_errors int,
368 ++ ifstat_tx_errors int, ifstat_tx_packets int, ifstat_multicast int,
369 ++ ifstat_rx_crc_errors int, ifstat_rx_fifo_errors int, ifstat_rx_missed_errors int,
370 ++ ifstat_tx_aborted_errors int, ifstat_tx_compressed int, ifstat_tx_fifo_errors int,
371 ++ ifstat_tx_window_errors int, ifstat_rx_bytes int, ifstat_rx_dropped int,
372 ++ ifstat_rx_frame_errors int, ifstat_rx_over_errors int, ifstat_tx_bytes int,
373 ++ ifstat_tx_dropped int, ifstat_tx_heartbeat_errors int,
374 ++ wlan_essid text, wlan_apmac text, wlan_type text, wlan_hwmode text, wlan_mode text,
375 ++ wlan_channel text, wlan_freq text, wlan_txpower text, wlan_signal text, wlan_noise text,
376 ++ wlan_bitrate text, wlan_crypt text, wlan_vaps text,
377 ++ db_ver text, db_update int, CONSTRAINT key_ifaces PRIMARY KEY (mainip, if_name) ON CONFLICT REPLACE);"
378 ++
379 ++ifaces_columns=$(sqlite3 /tmp/ondatabase.sqlite "PRAGMA table_info(ifaces);" | wc -l)
380 ++nodes_columns=$(sqlite3 /tmp/ondatabase.sqlite "PRAGMA table_info(nodes);" | wc -l)
381 ++
382 ++if [ "$ifaces_columns" != "54" ] || [ "$nodes_columns" != "44" ]; then
383 ++ sqlite3 -batch $1 "$SQL_STRING"
384 ++fi
385 ++
386 +diff --git a/lib/ondataservice/src/compat.c b/lib/ondataservice/src/compat.c
387 +new file mode 100644
388 +index 0000000..4d639be
389 +--- /dev/null
390 ++++ b/lib/ondataservice/src/compat.c
391 +@@ -0,0 +1,35 @@
392 ++#include "compat.h"
393 ++
394 ++#if !defined(__linux__) && !defined(__GLIBC__)
395 ++#include <stdlib.h>
396 ++#include <string.h>
397 ++
398 ++/* strndup() is a GNU extention */
399 ++char *
400 ++strndup(const char *ptr, size_t size)
401 ++{
402 ++ size_t len = strlen(ptr);
403 ++ char *ret = NULL;
404 ++
405 ++ if (len > size)
406 ++ len = size;
407 ++
408 ++ ret = malloc(len + 1);
409 ++
410 ++ if (!ret)
411 ++ return NULL;
412 ++
413 ++ memcpy(ret, ptr, len);
414 ++ ret[len] = '\0';
415 ++
416 ++ return ret;
417 ++}
418 ++
419 ++#endif
420 ++
421 ++/*
422 ++ * Local Variables:
423 ++ * c-basic-offset: 2
424 ++ * indent-tabs-mode: nil
425 ++ * End:
426 ++ */
427 +diff --git a/lib/ondataservice/src/compat.h b/lib/ondataservice/src/compat.h
428 +new file mode 100644
429 +index 0000000..c607c91
430 +--- /dev/null
431 ++++ b/lib/ondataservice/src/compat.h
432 +@@ -0,0 +1,17 @@
433 ++#ifndef _NAMESERVICE_COMPAT
434 ++#define _NAMESERVICE_COMPAT
435 ++
436 ++#include <sys/types.h>
437 ++
438 ++#if !defined(__linux__) && !defined(__GLIBC__)
439 ++char *strndup(const char *ptr, size_t size);
440 ++#endif
441 ++
442 ++#endif
443 ++
444 ++/*
445 ++ * Local Variables:
446 ++ * c-basic-offset: 2
447 ++ * indent-tabs-mode: nil
448 ++ * End:
449 ++ */
450 +diff --git a/lib/ondataservice/src/crc16.c b/lib/ondataservice/src/crc16.c
451 +new file mode 100644
452 +index 0000000..dc877ca
453 +--- /dev/null
454 ++++ b/lib/ondataservice/src/crc16.c
455 +@@ -0,0 +1,62 @@
456 ++#include <stdlib.h>
457 ++#include "crc16.h"
458 ++
459 ++// ------------ http://stackoverflow.com/questions/3853670/are-there-any-free-crc-libraries-that-covers-a-lot-of-the-crc-algorithms
460 ++
461 ++/******************************************/
462 ++/* CRC table for polynomial 0xA001 CCITT */
463 ++/******************************************/
464 ++
465 ++#define CRC16(crc,c) crc = (crc >> 8) ^ crctab[(crc ^ c) & 0xff]
466 ++
467 ++const u_int16_t crctab[256] = {
468 ++ 0x0000, 0xc0c1, 0xc181, 0x0140, 0xc301, 0x03c0, 0x0280, 0xc241,
469 ++ 0xc601, 0x06c0, 0x0780, 0xc741, 0x0500, 0xc5c1, 0xc481, 0x0440,
470 ++ 0xcc01, 0x0cc0, 0x0d80, 0xcd41, 0x0f00, 0xcfc1, 0xce81, 0x0e40,
471 ++ 0x0a00, 0xcac1, 0xcb81, 0x0b40, 0xc901, 0x09c0, 0x0880, 0xc841,
472 ++ 0xd801, 0x18c0, 0x1980, 0xd941, 0x1b00, 0xdbc1, 0xda81, 0x1a40,
473 ++ 0x1e00, 0xdec1, 0xdf81, 0x1f40, 0xdd01, 0x1dc0, 0x1c80, 0xdc41,
474 ++ 0x1400, 0xd4c1, 0xd581, 0x1540, 0xd701, 0x17c0, 0x1680, 0xd641,
475 ++ 0xd201, 0x12c0, 0x1380, 0xd341, 0x1100, 0xd1c1, 0xd081, 0x1040,
476 ++ 0xf001, 0x30c0, 0x3180, 0xf141, 0x3300, 0xf3c1, 0xf281, 0x3240,
477 ++ 0x3600, 0xf6c1, 0xf781, 0x3740, 0xf501, 0x35c0, 0x3480, 0xf441,
478 ++ 0x3c00, 0xfcc1, 0xfd81, 0x3d40, 0xff01, 0x3fc0, 0x3e80, 0xfe41,
479 ++ 0xfa01, 0x3ac0, 0x3b80, 0xfb41, 0x3900, 0xf9c1, 0xf881, 0x3840,
480 ++ 0x2800, 0xe8c1, 0xe981, 0x2940, 0xeb01, 0x2bc0, 0x2a80, 0xea41,
481 ++ 0xee01, 0x2ec0, 0x2f80, 0xef41, 0x2d00, 0xedc1, 0xec81, 0x2c40,
482 ++ 0xe401, 0x24c0, 0x2580, 0xe541, 0x2700, 0xe7c1, 0xe681, 0x2640,
483 ++ 0x2200, 0xe2c1, 0xe381, 0x2340, 0xe101, 0x21c0, 0x2080, 0xe041,
484 ++ 0xa001, 0x60c0, 0x6180, 0xa141, 0x6300, 0xa3c1, 0xa281, 0x6240,
485 ++ 0x6600, 0xa6c1, 0xa781, 0x6740, 0xa501, 0x65c0, 0x6480, 0xa441,
486 ++ 0x6c00, 0xacc1, 0xad81, 0x6d40, 0xaf01, 0x6fc0, 0x6e80, 0xae41,
487 ++ 0xaa01, 0x6ac0, 0x6b80, 0xab41, 0x6900, 0xa9c1, 0xa881, 0x6840,
488 ++ 0x7800, 0xb8c1, 0xb981, 0x7940, 0xbb01, 0x7bc0, 0x7a80, 0xba41,
489 ++ 0xbe01, 0x7ec0, 0x7f80, 0xbf41, 0x7d00, 0xbdc1, 0xbc81, 0x7c40,
490 ++ 0xb401, 0x74c0, 0x7580, 0xb541, 0x7700, 0xb7c1, 0xb681, 0x7640,
491 ++ 0x7200, 0xb2c1, 0xb381, 0x7340, 0xb101, 0x71c0, 0x7080, 0xb041,
492 ++ 0x5000, 0x90c1, 0x9181, 0x5140, 0x9301, 0x53c0, 0x5280, 0x9241,
493 ++ 0x9601, 0x56c0, 0x5780, 0x9741, 0x5500, 0x95c1, 0x9481, 0x5440,
494 ++ 0x9c01, 0x5cc0, 0x5d80, 0x9d41, 0x5f00, 0x9fc1, 0x9e81, 0x5e40,
495 ++ 0x5a00, 0x9ac1, 0x9b81, 0x5b40, 0x9901, 0x59c0, 0x5880, 0x9841,
496 ++ 0x8801, 0x48c0, 0x4980, 0x8941, 0x4b00, 0x8bc1, 0x8a81, 0x4a40,
497 ++ 0x4e00, 0x8ec1, 0x8f81, 0x4f40, 0x8d01, 0x4dc0, 0x4c80, 0x8c41,
498 ++ 0x4400, 0x84c1, 0x8581, 0x4540, 0x8701, 0x47c0, 0x4680, 0x8641,
499 ++ 0x8201, 0x42c0, 0x4380, 0x8341, 0x4100, 0x81c1, 0x8081, 0x4040
500 ++};
501 ++
502 ++//=========================================================================
503 ++// Description: Calculate a CRC on a buffer
504 ++// Parameters: buffer - address of buffer
505 ++// length - length of buffer
506 ++// Returns: CRC
507 ++//=========================================================================
508 ++u_int16_t crcCalculate(char *buffer, unsigned int length)
509 ++{
510 ++ u_int16_t Crc = 0;
511 ++
512 ++ for (; length; --length) {
513 ++ CRC16(Crc, *buffer++);
514 ++ }
515 ++ return(Crc);
516 ++}
517 ++
518 +diff --git a/lib/ondataservice/src/crc16.h b/lib/ondataservice/src/crc16.h
519 +new file mode 100644
520 +index 0000000..729d784
521 +--- /dev/null
522 ++++ b/lib/ondataservice/src/crc16.h
523 +@@ -0,0 +1,6 @@
524 ++
525 ++// copied from http://stackoverflow.com/questions/3853670/are-there-any-free-crc-libraries-that-covers-a-lot-of-the-crc-algorithms
526 ++
527 ++
528 ++u_int16_t crcCalculate(char *buffer, unsigned int length);
529 ++
530 +diff --git a/lib/ondataservice/src/olsrd_plugin.c b/lib/ondataservice/src/olsrd_plugin.c
531 +new file mode 100644
532 +index 0000000..c6989c5
533 +--- /dev/null
534 ++++ b/lib/ondataservice/src/olsrd_plugin.c
535 +@@ -0,0 +1,84 @@
536 ++
537 ++/*
538 ++ * Copyright (c) 2005, Bruno Randolf <bruno.randolf@4g-systems.biz>
539 ++ * Copyright (c) 2004, Andreas Tonnesen(andreto-at-olsr.org)
540 ++ * All rights reserved.
541 ++ *
542 ++ * Redistribution and use in source and binary forms, with or without
543 ++ * modification, are permitted provided that the following conditions
544 ++ * are met:
545 ++ *
546 ++ * * Redistributions of source code must retain the above copyright notice,
547 ++ * this list of conditions and the following disclaimer.
548 ++ * * Redistributions in binary form must reproduce the above copyright notice,
549 ++ * this list of conditions and the following disclaimer in the documentation
550 ++ * and/or other materials provided with the distribution.
551 ++ * * Neither the name of the UniK olsr daemon nor the names of its contributors
552 ++ * may be used to endorse or promote products derived from this software
553 ++ * without specific prior written permission.
554 ++ *
555 ++ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
556 ++ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
557 ++ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
558 ++ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
559 ++ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
560 ++ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
561 ++ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
562 ++ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
563 ++ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
564 ++ * OF THE POSSIBILITY OF SUCH DAMAGE.
565 ++ *
566 ++ */
567 ++
568 ++/*
569 ++ * Dynamic linked library for olsr.org olsrd
570 ++ */
571 ++
572 ++#include <stdio.h>
573 ++#include <string.h>
574 ++
575 ++#include "olsrd_plugin.h"
576 ++#include "ondataservice.h"
577 ++
578 ++#define MOD_DESC PLUGIN_NAME " " PLUGIN_VERSION
579 ++#define PLUGIN_INTERFACE_VERSION 5
580 ++
581 ++static void __attribute__ ((constructor)) my_init(void);
582 ++
583 ++static void __attribute__ ((destructor)) my_fini(void);
584 ++
585 ++int
586 ++olsrd_plugin_interface_version(void)
587 ++{
588 ++ return PLUGIN_INTERFACE_VERSION;
589 ++}
590 ++
591 ++int
592 ++olsrd_plugin_init(void)
593 ++{
594 ++ return ondata_init();
595 ++}
596 ++
597 ++static void
598 ++my_init(void)
599 ++{
600 ++ /* Print plugin info to stdout */
601 ++ printf("%s\n", MOD_DESC);
602 ++
603 ++ ondata_constructor();
604 ++
605 ++ return;
606 ++}
607 ++
608 ++static void
609 ++my_fini(void)
610 ++{
611 ++ ondata_destructor();
612 ++}
613 ++
614 ++/*
615 ++ * Local Variables:
616 ++ * c-basic-offset: 2
617 ++ * indent-tabs-mode: nil
618 ++ * End:
619 ++ */
620 +diff --git a/lib/ondataservice/src/ondataservice.c b/lib/ondataservice/src/ondataservice.c
621 +new file mode 100644
622 +index 0000000..c1e1076
623 +--- /dev/null
624 ++++ b/lib/ondataservice/src/ondataservice.c
625 +@@ -0,0 +1,619 @@
626 ++
627 ++/*
628 ++ * Copyright (c) 2011, Rene Ejury <opennet@absorb.it>
629 ++ * Copyright (c) 2006, Jens Nachtigall <nachtigall@web.de>
630 ++ * Copyright (c) 2005, Bruno Randolf <bruno.randolf@4g-systems.biz>
631 ++ * Copyright (c) 2004, Andreas Tonnesen(andreto-at-olsr.org)
632 ++ * Copyright (c) 2007, Sven-Ola <sven-ola@gmx.de>
633 ++ * All rights reserved.
634 ++ *
635 ++ * Redistribution and use in source and binary forms, with or without
636 ++ * modification, are permitted provided that the following conditions
637 ++ * are met:
638 ++ *
639 ++ * * Redistributions of source code must retain the above copyright notice,
640 ++ * this list of conditions and the following disclaimer.
641 ++ * * Redistributions in binary form must reproduce the above copyright notice,
642 ++ * this list of conditions and the following disclaimer in the documentation
643 ++ * and/or other materials provided with the distribution.
644 ++ * * Neither the name of the UniK olsr daemon nor the names of its contributors
645 ++ * may be used to endorse or promote products derived from this software
646 ++ * without specific prior written permission.
647 ++ *
648 ++ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
649 ++ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
650 ++ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
651 ++ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
652 ++ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
653 ++ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
654 ++ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
655 ++ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
656 ++ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
657 ++ * OF THE POSSIBILITY OF SUCH DAMAGE.
658 ++ *
659 ++ */
660 ++
661 ++/*
662 ++ * Dynamic linked library for UniK OLSRd
663 ++ */
664 ++
665 ++#define _GNU_SOURCE 1
666 ++
667 ++#include <stdio.h>
668 ++#include <string.h>
669 ++#include <stdlib.h>
670 ++#include <unistd.h>
671 ++#include <ctype.h>
672 ++#include <sys/types.h>
673 ++#include <sys/stat.h>
674 ++#include <signal.h>
675 ++#include <fcntl.h>
676 ++#include <time.h>
677 ++#include <sqlite3.h>
678 ++
679 ++#include "olsr.h"
680 ++#include "net_olsr.h"
681 ++#include "parser.h"
682 ++
683 ++#include "plugin_util.h"
684 ++#include "ondataservice.h"
685 ++#include "compat.h"
686 ++#include "crc16.h"
687 ++
688 ++const char *DATABASE_TABLES[2] = {"nodes", "ifaces"};
689 ++const int unsigned numberOfTables = 2;
690 ++
691 ++/* config parameters */
692 ++static int my_interval = EMISSION_INTERVAL;
693 ++static int my_inc_interval = EMISSION_INC_INTERVAL;
694 ++static int my_cleanup_interval = CLEANUP_INTERVAL; // how often database will be cleaned of outdated data
695 ++static int my_timeout = ONDATA_TIMEOUT; // how long the data stays valid
696 ++static int my_vtime = ONDATA_VALID_TIME; // how long the data will be spread trough the net
697 ++static char my_database[MAX_FILE + 1];
698 ++static char my_dbcreatescript[MAX_FILE + 1];
699 ++static char my_dberrorscript[MAX_FILE + 1];
700 ++static bool my_receive = false;
701 ++static bool my_spreadall = false;
702 ++
703 ++/* periodic message generation */
704 ++struct timer_entry *msg_gen_timer = NULL;
705 ++struct timer_entry *db_cleanup_timer = NULL;
706 ++
707 ++/**
708 ++ * do initialization
709 ++ */
710 ++void
711 ++ondata_constructor(void)
712 ++{
713 ++#ifdef WIN32
714 ++ int len;
715 ++
716 ++ GetWindowsDirectory(my_database, MAX_FILE - 12);
717 ++
718 ++ len = strlen(my_database);
719 ++ if (my_database[len - 1] != '\\')
720 ++ strscat(my_database, "\\", sizeof(my_database));
721 ++ strscat(my_database, DATABASE_FILE, sizeof(my_database));
722 ++
723 ++ GetWindowsDirectory(my_dbcreatescript, MAX_FILE - 12);
724 ++
725 ++ len = strlen(my_dbcreatescript);
726 ++ if (my_dbcreatescript[len - 1] != '\\')
727 ++ strscat(my_dbcreatescript, "\\", sizeof(my_dbcreatescript));
728 ++ strscat(my_dbcreatescript, "", sizeof(my_dbcreatescript));
729 ++#else
730 ++ strscpy(my_database, DATABASE_FILE, sizeof(my_database));
731 ++ strscpy(my_dbcreatescript, "", sizeof(my_dbcreatescript));
732 ++#endif
733 ++
734 ++}
735 ++
736 ++
737 ++/* *INDENT-OFF* */
738 ++static const struct olsrd_plugin_parameters plugin_parameters[] = {
739 ++ { .name = "interval", .set_plugin_parameter = &set_plugin_int, .data = &my_interval },
740 ++ { .name = "inc_interval", .set_plugin_parameter = &set_plugin_int, .data = &my_inc_interval },
741 ++ { .name = "cleanup_interval", .set_plugin_parameter = &set_plugin_int, .data = &my_cleanup_interval },
742 ++ { .name = "timeout", .set_plugin_parameter = &set_plugin_int, .data = &my_timeout },
743 ++ { .name = "database", .set_plugin_parameter = &set_plugin_string, .data = &my_database, .addon = {sizeof(my_database)} },
744 ++ { .name = "dbcreatescript", .set_plugin_parameter = &set_plugin_string, .data = &my_dbcreatescript, .addon = {sizeof(my_dbcreatescript)} },
745 ++ { .name = "dberrorscript", .set_plugin_parameter = &set_plugin_string, .data = &my_dberrorscript, .addon = {sizeof(my_dberrorscript)} },
746 ++ { .name = "receive", .set_plugin_parameter = &set_plugin_boolean, .data = &my_receive },
747 ++ { .name = "spreadall", .set_plugin_parameter = &set_plugin_boolean, .data = &my_spreadall },
748 ++ { .name = "vtime", .set_plugin_parameter = &set_plugin_int, .data = &my_vtime },
749 ++};
750 ++/* *INDENT-OFF* */
751 ++
752 ++void
753 ++olsrd_get_plugin_parameters(const struct olsrd_plugin_parameters **params, int *size)
754 ++{
755 ++ *params = plugin_parameters;
756 ++ *size = sizeof(plugin_parameters) / sizeof(*plugin_parameters);
757 ++}
758 ++
759 ++/**
760 ++ * last initialization
761 ++ *
762 ++ * we have to do this here because some things like main_addr
763 ++ * or the dns suffix (for validation) are not known before
764 ++ *
765 ++ * this is beause of the order in which the plugin is initialized
766 ++ * by the plugin loader:
767 ++ * - first the parameters are sent
768 ++ * - then register_olsr_data() from olsrd_plugin.c is called
769 ++ * which sets up main_addr and some other variables
770 ++ * - register_olsr_data() then then finally calls this function
771 ++ */
772 ++int
773 ++ondata_init(void)
774 ++{
775 ++ /* register functions with olsrd */
776 ++ if (my_receive) olsr_parser_add_function(&olsr_parser, PARSER_TYPE);
777 ++
778 ++ /* periodic message generation */
779 ++ msg_gen_timer = olsr_start_timer(my_interval * MSEC_PER_SEC, EMISSION_JITTER, OLSR_TIMER_PERIODIC, &olsr_ondatasvc_gen, NULL, 0);
780 ++
781 ++ /* periodic database cleanup generation */
782 ++ 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);
783 ++
784 ++ return 1;
785 ++}
786 ++
787 ++/**
788 ++ * called at unload: free everything
789 ++ *
790 ++ * XXX: should I delete the hosts/services/resolv.conf files on exit?
791 ++ */
792 ++void
793 ++ondata_destructor(void)
794 ++{
795 ++ olsr_stop_timer(msg_gen_timer);
796 ++
797 ++ if (my_receive) olsr_stop_timer(db_cleanup_timer);
798 ++}
799 ++
800 ++int
801 ++open_database(sqlite3 **localdb)
802 ++{
803 ++ int unsigned rc = sqlite3_open_v2(my_database, localdb, SQLITE_OPEN_READWRITE, NULL);
804 ++ if(rc != SQLITE_OK && strlen(my_dbcreatescript) != 0){
805 ++ char *buf;
806 ++ fprintf(stderr, "Can't open database, trying to (re)create database: %s\n", my_dbcreatescript);
807 ++ asprintf(&buf,"%s %s", my_dbcreatescript, my_database);
808 ++ system(buf);
809 ++ free(buf);
810 ++ rc = sqlite3_open_v2(my_database, localdb, SQLITE_OPEN_READWRITE, NULL);
811 ++ }
812 ++ if(rc != SQLITE_OK && strlen(my_dberrorscript) != 0){
813 ++ char *buf;
814 ++ fprintf(stderr, "Can't open database, running database-error script: %s\n", my_dberrorscript);
815 ++ asprintf(&buf,"%s %s", my_dberrorscript, my_database);
816 ++ system(buf);
817 ++ free(buf);
818 ++ rc = sqlite3_open_v2(my_database, localdb, SQLITE_OPEN_READWRITE, NULL);
819 ++ }
820 ++ return rc;
821 ++}
822 ++
823 ++
824 ++/**
825 ++ * wrapper for sqlite3_prepare_v2, calls error handle script on error
826 ++ */
827 ++int unsigned
828 ++local_sqlite3_prepare_v2(
829 ++ sqlite3 *db, /* Database handle */
830 ++ const char *zSql, /* SQL statement, UTF-8 encoded */
831 ++ int nByte, /* Maximum length of zSql in bytes. */
832 ++ sqlite3_stmt **ppStmt, /* OUT: Statement handle */
833 ++ const char **pzTail /* OUT: Pointer to unused portion of zSql */
834 ++)
835 ++{
836 ++ int unsigned rc;
837 ++ rc = sqlite3_prepare_v2(db, zSql, nByte, ppStmt, pzTail);
838 ++ if(rc != SQLITE_OK && strlen(my_dberrorscript) != 0){
839 ++ char *buf;
840 ++ fprintf(stderr, "running database-error script: %s\n", my_dberrorscript);
841 ++ asprintf(&buf,"%s %s", my_dberrorscript, my_database);
842 ++ system(buf);
843 ++ free(buf);
844 ++ rc = sqlite3_prepare_v2(db, zSql, nByte, ppStmt, pzTail);
845 ++ }
846 ++ return rc;
847 ++}
848 ++
849 ++/**
850 ++ * Callback for the db validity timer.
851 ++ */
852 ++void
853 ++olsr_ondataservice_expire_db_timer(void *foo __attribute__ ((unused)))
854 ++{
855 ++ sqlite3 *localdb;
856 ++ sqlite3_stmt *localppStmt;
857 ++ char *localzSql;
858 ++ const char *pzTail; /* OUT of sqlite3_prepare_v2: Pointer to unused portion of zSql */
859 ++ const char *SQLframe = "DELETE FROM %s WHERE (originator != '' AND mainip != '%s' AND db_update < %lu );";
860 ++ struct ipaddr_str main_addr;
861 ++ const char *mainip;
862 ++ int unsigned currentTable = 0, rc;
863 ++ long unsigned min_update_time;
864 ++
865 ++ min_update_time = time(NULL) - my_timeout;
866 ++ mainip = olsr_ip_to_string(&main_addr, &olsr_cnf->main_addr);
867 ++
868 ++ rc = open_database(&localdb);
869 ++ if( rc == SQLITE_OK ){
870 ++ while (currentTable < numberOfTables) {
871 ++
872 ++ // build Database statement / assumption that time will not be bigger than 20chars long
873 ++ localzSql = olsr_malloc(strlen(SQLframe) + strlen(mainip) + strlen(DATABASE_TABLES[currentTable]) + 20 + 1, "update_ondata_entry: space for SQL query");
874 ++ sprintf(localzSql, SQLframe, DATABASE_TABLES[currentTable], mainip, min_update_time);
875 ++
876 ++ // apply statement to database
877 ++ // use 1500 as max MTU and therefore as max SQL size (which is not quite accurate)
878 ++ rc = local_sqlite3_prepare_v2(localdb, localzSql, 1500, &localppStmt, &pzTail);
879 ++ if( rc == SQLITE_OK ){
880 ++ sqlite3_step(localppStmt);
881 ++ sqlite3_finalize(localppStmt);
882 ++ OLSR_PRINTF(5, "ONDATA PLUGIN: Database cleaned: %s\n", localzSql);
883 ++ }
884 ++ else fprintf(stderr, "SQL error: %s\n", sqlite3_errmsg(localdb));
885 ++ free(localzSql);
886 ++ currentTable++;
887 ++ }
888 ++ }
889 ++ else fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(localdb));
890 ++
891 ++ sqlite3_close(localdb);
892 ++}
893 ++
894 ++/**
895 ++ * Scheduled event: generate and send ONDATA packet
896 ++ */
897 ++void
898 ++olsr_ondatasvc_gen(void *foo __attribute__ ((unused)))
899 ++{
900 ++ /* send buffer: huge */
901 ++ char buffer[10240];
902 ++ union olsr_message *message = (union olsr_message *)buffer;
903 ++ struct interface *ifn;
904 ++ int ondatasize;
905 ++
906 ++ /* fill message */
907 ++ if (olsr_cnf->ip_version == AF_INET) {
908 ++ /* IPv4 */
909 ++ message->v4.olsr_msgtype = MESSAGE_TYPE;
910 ++ message->v4.olsr_vtime = reltime_to_me((double)my_vtime * MSEC_PER_SEC);
911 ++ memcpy(&message->v4.originator, &olsr_cnf->main_addr, olsr_cnf->ipsize);
912 ++ message->v4.ttl = MAX_TTL;
913 ++ message->v4.hopcnt = 0;
914 ++ message->v4.seqno = htons(get_msg_seqno());
915 ++
916 ++ ondatasize = encap_ondatamsg((struct ondatamsg *)ARM_NOWARN_ALIGN(&message->v4.message));
917 ++ if (!ondatasize) return;
918 ++ ondatasize = ondatasize + sizeof(struct olsrmsg);
919 ++ message->v4.olsr_msgsize = htons(ondatasize);
920 ++ } else {
921 ++ /* IPv6 */
922 ++ message->v6.olsr_msgtype = MESSAGE_TYPE;
923 ++ message->v6.olsr_vtime = reltime_to_me((double)my_vtime * MSEC_PER_SEC);
924 ++ memcpy(&message->v6.originator, &olsr_cnf->main_addr, olsr_cnf->ipsize);
925 ++ message->v6.ttl = MAX_TTL;
926 ++ message->v6.hopcnt = 0;
927 ++ message->v6.seqno = htons(get_msg_seqno());
928 ++
929 ++ ondatasize = encap_ondatamsg((struct ondatamsg *)ARM_NOWARN_ALIGN(&message->v6.message));
930 ++ if (!ondatasize) return;
931 ++ ondatasize = ondatasize + sizeof(struct olsrmsg6);
932 ++
933 ++ message->v6.olsr_msgsize = htons(ondatasize);
934 ++ }
935 ++
936 ++ /* looping trough interfaces */
937 ++ for (ifn = ifnet; ifn; ifn = ifn->int_next) {
938 ++ OLSR_PRINTF(3, "ONDATA PLUGIN: Generating packet - [%s]\n", ifn->int_name);
939 ++
940 ++ if (net_outbuffer_push(ifn, message, ondatasize) != ondatasize) {
941 ++ /* send data and try again */
942 ++ net_output(ifn);
943 ++ if (net_outbuffer_push(ifn, message, ondatasize) != ondatasize) {
944 ++ OLSR_PRINTF(1, "ONDATA PLUGIN: could not send on interface: %s\n", ifn->int_name);
945 ++ }
946 ++ }
947 ++ }
948 ++}
949 ++
950 ++/**
951 ++ * Parse ondata olsr message of ONDATA type
952 ++ */
953 ++bool
954 ++olsr_parser(union olsr_message *m, struct interface *in_if __attribute__ ((unused)), union olsr_ip_addr *ipaddr __attribute__ ((unused)))
955 ++{
956 ++ struct ondatamsg *ondatamessage;
957 ++ union olsr_ip_addr originator;
958 ++ int size;
959 ++
960 ++ /* Fetch the originator of the messsage */
961 ++ if (olsr_cnf->ip_version == AF_INET) {
962 ++ memcpy(&originator, &m->v4.originator, olsr_cnf->ipsize);
963 ++ } else {
964 ++ memcpy(&originator, &m->v6.originator, olsr_cnf->ipsize);
965 ++ }
966 ++
967 ++ /* Fetch the message based on IP version */
968 ++ if (olsr_cnf->ip_version == AF_INET) {
969 ++ size = ntohs(m->v4.olsr_msgsize);
970 ++ ondatamessage = (struct ondatamsg *)ARM_NOWARN_ALIGN(&m->v4.message);
971 ++ } else {
972 ++ size = ntohs(m->v6.olsr_msgsize);
973 ++ ondatamessage = (struct ondatamsg *)ARM_NOWARN_ALIGN(&m->v6.message);
974 ++ }
975 ++
976 ++ /* Check if message originated from this node.
977 ++ If so - back off */
978 ++ if (ipequal(&originator, &olsr_cnf->main_addr))
979 ++ return false;
980 ++
981 ++ update_ondata_entry(&originator, ondatamessage, size);
982 ++ /* Forward the message */
983 ++ return true;
984 ++}
985 ++
986 ++// Database Variables / should be kept over different calls, therefore global
987 ++sqlite3 *db;
988 ++sqlite3_stmt *ppStmt;
989 ++char *zSql;
990 ++
991 ++int unsigned currentTable = 0;
992 ++bool db_open = 0;
993 ++bool table_open = 0;
994 ++
995 ++/**
996 ++ * Encapsulate a ondata message into a packet.
997 ++ *
998 ++ * It assumed that there is enough space in the buffer to do this!
999 ++ *
1000 ++ * Returns: the length of the message that was appended
1001 ++ */
1002 ++int
1003 ++encap_ondatamsg(struct ondatamsg *msg)
1004 ++{
1005 ++ const char *pzTail; /* OUT of sqlite3_prepare_v2: Pointer to unused portion of zSql */
1006 ++ const char *SQLframe = "SELECT * FROM %s WHERE mainip = '%s';";
1007 ++ const char *SQLframeSpreadAll = "SELECT * FROM %s WHERE originator = '';";
1008 ++
1009 ++ struct ipaddr_str main_addr;
1010 ++ const char *mainip;
1011 ++ char *pos;
1012 ++ int iCol, rc;
1013 ++ uint16_t checksum;
1014 ++ uint16_t messageLength = 0;
1015 ++
1016 ++ // open Database if this not a 'continued Transmission - and Database is already open'
1017 ++ mainip = olsr_ip_to_string(&main_addr, &olsr_cnf->main_addr);
1018 ++
1019 ++ if (!db_open) {
1020 ++ OLSR_PRINTF(5, "ONDATA PLUGIN: opening database\n");
1021 ++
1022 ++ currentTable = 0;
1023 ++ rc = open_database(&db);
1024 ++
1025 ++ if( rc == SQLITE_OK) db_open = 1;
1026 ++ else {
1027 ++ fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
1028 ++ sqlite3_close(db); return 0;
1029 ++ }
1030 ++ }
1031 ++
1032 ++ // if there is no Data available, search next Table with Data
1033 ++ if (!table_open) {
1034 ++ while (currentTable < numberOfTables) {
1035 ++ OLSR_PRINTF(5, "ONDATA PLUGIN: using next table %s\n", DATABASE_TABLES[currentTable]);
1036 ++ // build SQL-query
1037 ++ if (!my_spreadall) {
1038 ++ zSql = olsr_malloc(strlen(SQLframe) + strlen(DATABASE_TABLES[currentTable]) + strlen(mainip) + 1, "encap_ondatamsg: space for SQL query");
1039 ++ sprintf(zSql, SQLframe, DATABASE_TABLES[currentTable], mainip);
1040 ++ }
1041 ++ else {
1042 ++ zSql = olsr_malloc(strlen(SQLframeSpreadAll) + strlen(DATABASE_TABLES[currentTable])+ 1, "encap_ondatamsg: space for SQL query");
1043 ++ sprintf(zSql, SQLframeSpreadAll, DATABASE_TABLES[currentTable]);
1044 ++ }
1045 ++ // open table
1046 ++ rc = local_sqlite3_prepare_v2(db, zSql, 100, &ppStmt, &pzTail);
1047 ++ if( rc == SQLITE_OK) {
1048 ++ table_open = 1;
1049 ++ break;
1050 ++ }
1051 ++ else {
1052 ++ fprintf(stderr, "SQL error: %s\n", sqlite3_errmsg(db));
1053 ++ free(zSql);
1054 ++ }
1055 ++ currentTable++;
1056 ++ }
1057 ++ }
1058 ++
1059 ++ // if still no valid table found, give up
1060 ++ if (!table_open) {
1061 ++ OLSR_PRINTF(5, "ONDATA PLUGIN: no further table found\n");
1062 ++ sqlite3_close(db);
1063 ++ db_open = 0;
1064 ++ // reset timer to normal interval
1065 ++ olsr_change_timer(msg_gen_timer, my_interval * MSEC_PER_SEC, EMISSION_JITTER, OLSR_TIMER_PERIODIC);
1066 ++ return 0;
1067 ++ }
1068 ++
1069 ++ // add all datasets
1070 ++ if (sqlite3_step(ppStmt) == SQLITE_ROW) {
1071 ++ OLSR_PRINTF(5, "ONDATA PLUGIN: adding all datasets\n");
1072 ++ // add all the entries after the ondatamsg header (and keep space for it)
1073 ++ pos = (char *)msg + sizeof(struct ondatamsg);
1074 ++
1075 ++ // always add the Table-Name as first field
1076 ++ pos = create_packet((struct ondata *)ARM_NOWARN_ALIGN(pos), DATABASE_TABLES[currentTable]);
1077 ++
1078 ++ // never transmit originator (col=0), this will be detected at the other end_pos
1079 ++ // skip last column, it will set at destination to the receiving-time
1080 ++ iCol = 1;
1081 ++ while (iCol < sqlite3_column_count(ppStmt) - 1) {
1082 ++ pos = create_packet((struct ondata *)ARM_NOWARN_ALIGN(pos), (const char *)sqlite3_column_text(ppStmt, iCol));
1083 ++ iCol++;
1084 ++ }
1085 ++ // write the ondatamsg header with the number of announced entries and the protocol version
1086 ++ msg->nr_datasets = htons(--iCol); // it won't count the table-name as dataset (and neither mainip-Col)
1087 ++ msg->version = htons(ONDATA_PROTOCOL_VERSION);
1088 ++ messageLength = pos - (char *)msg;
1089 ++ msg->length = htons(messageLength);
1090 ++ checksum = crcCalculate((char *)msg + sizeof(uint16_t), messageLength - sizeof(uint16_t));
1091 ++ msg->checksum = htons(checksum);
1092 ++
1093 ++ OLSR_PRINTF(3, "ONDATA PLUGIN: ##### finished creating packet, length=%d, crc16=0x%x\n", messageLength, checksum);
1094 ++ }
1095 ++ else {
1096 ++ OLSR_PRINTF(5, "ONDATA PLUGIN: finalize query\n");
1097 ++ sqlite3_finalize(ppStmt);
1098 ++ free(zSql);
1099 ++ currentTable++;
1100 ++ table_open = 0;
1101 ++ }
1102 ++
1103 ++ // increase Transmission-Time as long as there is data
1104 ++ olsr_change_timer(msg_gen_timer, 1 * MSEC_PER_SEC, EMISSION_JITTER, OLSR_TIMER_PERIODIC);
1105 ++ return messageLength; //length
1106 ++}
1107 ++
1108 ++
1114 ++char *
1115 ++create_packet(struct ondata *to, const char *value )
1116 ++{
1117 ++ char *pos = (char *)to; int valuelen = strlen((const char*)value);
1118 ++ int k;
1119 ++ to->valuelen = htons(valuelen);
1120 ++ OLSR_PRINTF(5, "ONDATA PLUGIN: Announcing value %s %d\n", value, valuelen);
1121 ++ pos += sizeof(struct ondata);
1122 ++ memcpy(pos, value, valuelen);
1123 ++ pos += valuelen;
1124 ++ // do 4-byte padding
1125 ++ for (k = sizeof(struct ondata) + valuelen; (k & 3) != 0; k++)
1126 ++ *pos++ = '\0';
1127 ++
1128 ++ return pos;
1129 ++}
1130 ++
1131 ++
1135 ++void
1136 ++update_ondata_entry(union olsr_ip_addr *originator, struct ondatamsg *msg, int msg_size)
1137 ++{
1138 ++ struct ipaddr_str strbuf;
1139 ++ char *pos, *end_pos, *values, *valuepos, *table;
1140 ++ const char *originatorIP;
1141 ++ struct ondata *from_packet;
1142 ++ int i, rc;
1143 ++ uint16_t checksum;
1144 ++ sqlite3 *localdb;
1145 ++ sqlite3_stmt *localppStmt;
1146 ++ char *localzSql;
1147 ++ const char *SQLframe = "INSERT OR REPLACE INTO %s VALUES (%s);", *pzTail;
1148 ++
1149 ++
1150 ++ originatorIP = olsr_ip_to_string(&strbuf, originator);
1151 ++ 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));
1152 ++
1153 ++ if (ntohs(msg->version) != ONDATA_PROTOCOL_VERSION) {
1154 ++ OLSR_PRINTF(3, "ONDATA PLUGIN: ignoring wrong version %d\n", ntohs(msg->version));
1155 ++ return;
1156 ++ }
1157 ++
1158 ++ // calculate checksum
1159 ++ checksum = crcCalculate((char *)msg + sizeof(uint16_t), ntohs(msg->length) - sizeof(uint16_t));
1160 ++ if (ntohs(msg->checksum) != checksum) {
1161 ++ OLSR_PRINTF(3, "ONDATA PLUGIN: ignoring checksum error 0x%x\n", checksum);
1162 ++ return;
1163 ++ }
1164 ++ else OLSR_PRINTF(5, "ONDATA PLUGIN: validated checksum 0x%x\n", checksum);
1165 ++
1166 ++
1167 ++ // every value will be enclosed in brackets "'" and separated by a comma ","
1168 ++ // so we need four bytes more per value (and we take more than we need, yeah)
1169 ++ values = olsr_malloc(strlen(originatorIP) + 1 + ntohs(msg->length) + msg->nr_datasets*3, "update_ondata_entry: space for SQL values");
1170 ++ valuepos = values;
1171 ++
1172 ++ // checksum is valid, now add the values to the database.
1173 ++ // first field is the tablename, abort if it does not exist
1174 ++ // all following fields contain the table-values for one row.
1175 ++
1176 ++ pos = (char *)msg + sizeof(struct ondatamsg);
1177 ++ end_pos = pos + msg_size - sizeof(struct ondata *); // at least one struct ondata has to be left
1178 ++
1179 ++
1180 ++ from_packet = (struct ondata *)ARM_NOWARN_ALIGN(pos);
1181 ++ table = olsr_malloc(ntohs(from_packet->valuelen) + 1, "update_ondata_entry: space for Table Name");
1182 ++
1183 ++ memcpy(table, (char *)from_packet + sizeof(struct ondata), ntohs(from_packet->valuelen));
1184 ++ *(table + ntohs(from_packet->valuelen)) = '\0';
1185 ++
1186 ++ // set new position and calculate alignment
1187 ++ pos += ((sizeof(struct ondata) + ntohs(from_packet->valuelen) - 1) | 3) + 1;
1188 ++
1189 ++ // add originator IP
1190 ++ memcpy(valuepos++, "'", 1);
1191 ++ memcpy(valuepos, originatorIP, strlen(originatorIP));
1192 ++ valuepos += strlen(originatorIP);
1193 ++ memcpy(valuepos, "',", 2);
1194 ++ valuepos += 2;
1195 ++
1196 ++ for (i = ntohs(msg->nr_datasets); i > 0 && pos < end_pos; i--) {
1197 ++ from_packet = (struct ondata *)ARM_NOWARN_ALIGN(pos);
1198 ++
1199 ++ memcpy(valuepos++, "'", 1);
1200 ++ memcpy(valuepos, (char *)from_packet + sizeof(struct ondata), ntohs(from_packet->valuelen));
1201 ++ valuepos += ntohs(from_packet->valuelen);
1202 ++ memcpy(valuepos, "',", 2);
1203 ++ valuepos += 2;
1204 ++
1205 ++ // set new position and calculate alignment
1206 ++ pos += ((sizeof(struct ondata) + ntohs(from_packet->valuelen) - 1) | 3) + 1;
1207 ++ }
1208 ++
1209 ++ // add current time to detect age of datasets (and remove them after timeout)
1210 ++ sprintf(valuepos, "'%lu'", (uintmax_t)time(NULL));
1211 ++
1212 ++ // build Database statement
1213 ++ localzSql = olsr_malloc(strlen(SQLframe) + strlen(table) + strlen(values) + 1, "update_ondata_entry: space for SQL query");
1214 ++ sprintf(localzSql, SQLframe, table, values);
1215 ++ free(table); free(values);
1216 ++
1217 ++ // apply statement to database
1218 ++ rc = open_database(&localdb);
1219 ++ if( rc == SQLITE_OK ){
1220 ++ // use 1500 as max MTU and therefore as max SQL size (which is not quite accurate)
1221 ++ rc = local_sqlite3_prepare_v2(localdb, localzSql, 1500, &localppStmt, &pzTail);
1222 ++ if( rc == SQLITE_OK ){
1223 ++ sqlite3_step(localppStmt);
1224 ++ sqlite3_finalize(localppStmt);
1225 ++ OLSR_PRINTF(5, "ONDATA PLUGIN: Data added: %s\n", localzSql);
1226 ++ }
1227 ++ else fprintf(stderr, "SQL error: %s\n", sqlite3_errmsg(localdb));
1228 ++ }
1229 ++ else fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(localdb));
1230 ++
1231 ++ sqlite3_close(localdb);
1232 ++ free(localzSql);
1233 ++}
1234 ++
1235 ++/*
1236 ++ * Local Variables:
1237 ++ * mode: c
1238 ++ * c-indent-tabs-mode: t
1239 ++ * indent-tabs-mode: t
1240 ++ * c-basic-offset: 4
1241 ++ * tab-width: 4
1242 ++ * End:
1243 ++ */
1244 ++
1245 +diff --git a/lib/ondataservice/src/ondataservice.h b/lib/ondataservice/src/ondataservice.h
1246 +new file mode 100644
1247 +index 0000000..cc1251b
1248 +--- /dev/null
1249 ++++ b/lib/ondataservice/src/ondataservice.h
1250 +@@ -0,0 +1,109 @@
1251 ++
1252 ++/*
1253 ++ * Copyright (c) 2005, Bruno Randolf <bruno.randolf@4g-systems.biz>
1254 ++ * Copyright (c) 2004, Andreas Tonnesen(andreto-at-olsr.org)
1255 ++ * All rights reserved.
1256 ++ *
1257 ++ * Redistribution and use in source and binary forms, with or without
1258 ++ * modification, are permitted provided that the following conditions
1259 ++ * are met:
1260 ++ *
1261 ++ * * Redistributions of source code must retain the above copyright notice,
1262 ++ * this list of conditions and the following disclaimer.
1263 ++ * * Redistributions in binary form must reproduce the above copyright notice,
1264 ++ * this list of conditions and the following disclaimer in the documentation
1265 ++ * and/or other materials provided with the distribution.
1266 ++ * * Neither the name of the UniK olsr daemon nor the names of its contributors
1267 ++ * may be used to endorse or promote products derived from this software
1268 ++ * without specific prior written permission.
1269 ++ *
1270 ++ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
1271 ++ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
1272 ++ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1273 ++ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
1274 ++ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
1275 ++ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
1276 ++ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
1277 ++ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
1278 ++ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
1279 ++ * OF THE POSSIBILITY OF SUCH DAMAGE.
1280 ++ *
1281 ++ */
1282 ++
1283 ++/*
1284 ++ * Dynamic linked library for UniK OLSRd
1285 ++ */
1286 ++
1287 ++#ifndef _ONDATASERVICE_PLUGIN
1288 ++#define _ONDATASERVICE_PLUGIN
1289 ++
1290 ++#include <sys/time.h>
1291 ++// #include <regex.h>
1292 ++
1293 ++#include "olsr_types.h"
1294 ++#include "interfaces.h"
1295 ++#include "olsr_protocol.h"
1296 ++#include "common/list.h"
1297 ++
1298 ++#include "olsrd_plugin.h"
1299 ++#include "ondataservice_msg.h"
1300 ++#include "hashing.h"
1301 ++// #include "mapwrite.h"
1302 ++// #include "mantissa.h"
1303 ++
1304 ++#define PLUGIN_NAME "OLSRD ondataservice plugin"
1305 ++#define PLUGIN_VERSION "0.3"
1306 ++#define PLUGIN_AUTHOR "Rene Ejury, Bruno Randolf, Jens Nachtigall, Sven-Ola Tuecke"
1307 ++#define DATABASE_FILE "/tmp/database"
1308 ++
1309 ++#define MESSAGE_TYPE 222 /* hope this is a good choice */
1310 ++#define PARSER_TYPE MESSAGE_TYPE
1311 ++#define EMISSION_INTERVAL 10800 /* seconds - 10800 = 3hours */
1312 ++#define EMISSION_INC_INTERVAL 5 /* seconds between transmission of rows from one dataset */
1313 ++#define EMISSION_JITTER 25 /* percent */
1314 ++#define ONDATA_TIMEOUT 21600 /* seconds, how long old data stays valid - 21600 = 6hours */
1315 ++#define ONDATA_VALID_TIME 300 /* seconds, how long a package should maximally be spreaded through the net - 300 - 5mins*/
1316 ++#define CLEANUP_INTERVAL 1800 /* seconds, how often cleanup will be triggered - 1800 = 0.5hours */
1317 ++
1318 ++#define ONDATA_PROTOCOL_VERSION 1
1319 ++
1320 ++#define MAX_FILE 255
1321 ++
1322 ++/* Parser function to register with the scheduler */
1323 ++bool olsr_parser(union olsr_message *, struct interface *, union olsr_ip_addr *);
1324 ++
1325 ++/* callback for periodic timer */
1326 ++void olsr_ondatasvc_gen(void *);
1327 ++
1328 ++/* open or create and open database */
1329 ++#include <sqlite3.h>
1330 ++int open_database(sqlite3 **localdb);
1331 ++int unsigned local_sqlite3_prepare_v2(sqlite3 *db, const char *zSql, int nByte, sqlite3_stmt **ppStmt, const char **pzTail);
1332 ++
1333 ++/* callback for database cleanup */
1334 ++void olsr_ondataservice_expire_db_timer(void *);
1335 ++
1336 ++int encap_ondatamsg(struct ondatamsg *);
1337 ++
1338 ++void update_ondata_entry(union olsr_ip_addr *, struct ondatamsg *, int);
1339 ++
1340 ++int register_olsr_param(char *key, char *value);
1341 ++
1342 ++
1343 ++char *create_packet(struct ondata *to, const char *value);
1344 ++
1345 ++void ondata_constructor(void);
1346 ++
1347 ++void ondata_destructor(void);
1348 ++
1349 ++int ondata_init(void);
1350 ++
1351 ++#endif
1352 ++
1353 ++/*
1354 ++ * Local Variables:
1355 ++ * c-basic-offset: 2
1356 ++ * indent-tabs-mode: nil
1357 ++ * End:
1358 ++ */
1359 ++
1360 +diff --git a/lib/ondataservice/src/ondataservice_msg.h b/lib/ondataservice/src/ondataservice_msg.h
1361 +new file mode 100644
1362 +index 0000000..b22fbee
1363 +--- /dev/null
1364 ++++ b/lib/ondataservice/src/ondataservice_msg.h
1365 +@@ -0,0 +1,68 @@
1366 ++
1367 ++/*
1368 ++ * Copyright (c) 2005, Bruno Randolf <bruno.randolf@4g-systems.biz>
1369 ++ * Copyright (c) 2004, Andreas Tonnesen(andreto-at-olsr.org)
1370 ++ * All rights reserved.
1371 ++ *
1372 ++ * Redistribution and use in source and binary forms, with or without
1373 ++ * modification, are permitted provided that the following conditions
1374 ++ * are met:
1375 ++ *
1376 ++ * * Redistributions of source code must retain the above copyright notice,
1377 ++ * this list of conditions and the following disclaimer.
1378 ++ * * Redistributions in binary form must reproduce the above copyright notice,
1379 ++ * this list of conditions and the following disclaimer in the documentation
1380 ++ * and/or other materials provided with the distribution.
1381 ++ * * Neither the name of the UniK olsr daemon nor the names of its contributors
1382 ++ * may be used to endorse or promote products derived from this software
1383 ++ * without specific prior written permission.
1384 ++ *
1385 ++ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
1386 ++ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
1387 ++ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1388 ++ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
1389 ++ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
1390 ++ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
1391 ++ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
1392 ++ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
1393 ++ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
1394 ++ * OF THE POSSIBILITY OF SUCH DAMAGE.
1395 ++ *
1396 ++ */
1397 ++
1398 ++/*
1399 ++ * Dynamic linked library for UniK OLSRd
1400 ++ */
1401 ++
1402 ++#ifndef _ONDATASERVICE_MSG
1403 ++#define _ONDATASERVICE_MSG
1404 ++
1405 ++
1409 ++struct ondata {
1410 ++ uint16_t valuelen; // length of the value
1411 ++ /*
1412 ++ * value is written separatedly in plain text after this struct and padded to 4 byte
1413 ++ */
1414 ++};
1415 ++
1416 ++struct ondatamsg {
1417 ++ uint16_t checksum;
1418 ++ uint16_t version; // version number of the ondataservice plugin
1419 ++ uint16_t nr_datasets; // number of following packets including all the data
1420 ++ uint16_t length; // length in bytes / required to calculate checksum on receive
1421 ++ /*
1422 ++ * at least one struct name following
1423 ++ */
1424 ++};
1425 ++
1426 ++#endif
1427 ++
1428 ++/*
1429 ++ * Local Variables:
1430 ++ * c-basic-offset: 2
1431 ++ * indent-tabs-mode: nil
1432 ++ * End:
1433 ++ */
1434 +diff --git a/lib/ondataservice/version-script.txt b/lib/ondataservice/version-script.txt
1435 +new file mode 100644
1436 +index 0000000..a145659
1437 +--- /dev/null
1438 ++++ b/lib/ondataservice/version-script.txt
1439 +@@ -0,0 +1,10 @@
1440 ++VERS_1.0
1441 ++{
1442 ++ global:
1443 ++ olsrd_plugin_interface_version;
1444 ++ olsrd_plugin_init;
1445 ++ olsrd_get_plugin_parameters;
1446 ++
1447 ++ local:
1448 ++ *;
1449 ++};
1450 +diff --git a/lib/ondataservice_light/Makefile b/lib/ondataservice_light/Makefile
1451 +new file mode 100644
1452 +index 0000000..01dd2db
1453 +--- /dev/null
1454 ++++ b/lib/ondataservice_light/Makefile
1455 +@@ -0,0 +1,79 @@
1456 ++# The olsr.org Optimized Link-State Routing daemon(olsrd)
1457 ++# Copyright (c) 2004, Andreas Tonnesen(andreto@olsr.org)
1458 ++# All rights reserved.
1459 ++#
1460 ++# Redistribution and use in source and binary forms, with or without
1461 ++# modification, are permitted provided that the following conditions
1462 ++# are met:
1463 ++#
1464 ++# * Redistributions of source code must retain the above copyright
1465 ++# notice, this list of conditions and the following disclaimer.
1466 ++# * Redistributions in binary form must reproduce the above copyright
1467 ++# notice, this list of conditions and the following disclaimer in
1468 ++# the documentation and/or other materials provided with the
1469 ++# distribution.
1470 ++# * Neither the name of olsr.org, olsrd nor the names of its
1471 ++# contributors may be used to endorse or promote products derived
1472 ++# from this software without specific prior written permission.
1473 ++#
1474 ++# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1475 ++# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1476 ++# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
1477 ++# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
1478 ++# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
1479 ++# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
1480 ++# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
1481 ++# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
1482 ++# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
1483 ++# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
1484 ++# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
1485 ++# POSSIBILITY OF SUCH DAMAGE.
1486 ++#
1487 ++# Visit http://www.olsr.org for more information.
1488 ++#
1489 ++# If you find this software useful feel free to make a donation
1490 ++# to the project. For more information see the website or contact
1491 ++# the copyright holders.
1492 ++#
1493 ++
1494 ++OLSRD_PLUGIN = true
1495 ++PLUGIN_NAME = olsrd_ondataservice_light
1496 ++# dont change version here for backward-compatible changes,
1497 ++# it will change the library name and won't load with the
1498 ++# olsrd-config already existing on the device
1499 ++PLUGIN_VER = 0.1
1500 ++
1501 ++LIBS +=
1502 ++
1503 ++TOPDIR = ../..
1504 ++include $(TOPDIR)/Makefile.inc
1505 ++
1506 ++ifeq ($(OS),win32)
1507 ++default_target install clean:
1508 ++ @echo "**** We use the regex library here. Does Win32 has something like this?"
1509 ++else
1510 ++ifeq ($(OS),android)
1511 ++# On Android Google forgot to include regex engine code for Froyo version (but also there was
1512 ++# no support in older versions for it) so we have here this missing code.
1513 ++# http://groups.google.com/group/android-ndk/browse_thread/thread/5ea6f0650f0e3fc
1514 ++SRCS += $(wildcard $(TOPDIR)/android/regex/reg*.c)
1515 ++HDRS += $(wildcard $(TOPDIR)/android/regex/*.h)
1516 ++CFLAGS += -D__POSIX_VISIBLE
1517 ++endif
1518 ++
1519 ++default_target: $(PLUGIN_FULLNAME)
1520 ++
1521 ++$(PLUGIN_FULLNAME): $(OBJS) version-script.txt
1522 ++ @echo "[LD] $@"
1523 ++ @$(CC) $(LDFLAGS) -o $(PLUGIN_FULLNAME) $(OBJS) $(LIBS)
1524 ++
1525 ++install: $(PLUGIN_FULLNAME)
1526 ++ $(STRIP) $(PLUGIN_FULLNAME)
1527 ++ $(INSTALL_LIB)
1528 ++
1529 ++uninstall:
1530 ++ $(UNINSTALL_LIB)
1531 ++
1532 ++clean:
1533 ++ rm -f $(OBJS) $(SRCS:%.c=%.d) $(PLUGIN_FULLNAME)
1534 ++endif
1535 +diff --git a/lib/ondataservice_light/README_ONDATASERVICE_LIGHT b/lib/ondataservice_light/README_ONDATASERVICE_LIGHT
1536 +new file mode 100644
1537 +index 0000000..174cd28
1538 +--- /dev/null
1539 ++++ b/lib/ondataservice_light/README_ONDATASERVICE_LIGHT
1540 +@@ -0,0 +1,42 @@
1541 ++---------------------------------------------------------------------
1542 ++ONDATASERVICE_LIGHT PLUGIN FOR OLSRD
1543 ++by Rene Ejury <opennet@absorb.it>
1544 ++based on and copied from:
1545 ++NAMESERVICE PLUGIN FOR OLSRD
1546 ++by Bruno Randolf <bruno.randolf@4g-systems.biz>
1547 ++---------------------------------------------------------------------
1548 ++
1549 ++Plugin just to spread json-values stored in a json-database
1550 ++no reception possible, but does not require sqlite-library
1551 ++
1552 ++---------------------------------------------------------------------
1553 ++PLUGIN PARAMETERS (PlParam)
1554 ++---------------------------------------------------------------------
1555 ++
1556 ++PlParam "interval" "SEC"
1557 ++ interval for sending the DATABASE in seconds.
1558 ++ (default: 10800 - 3 hours)
1559 ++
1560 ++PlParam "inc_interval" "SEC"
1561 ++ interval for continously sending TABLES from DATABASE in seconds.
1562 ++ (default: 5 seconds)
1563 ++
1564 ++PlParam "database" "/path/to/database"
1565 ++ Path to the database (json)
1566 ++
1567 ++PlParam "vtime" "SEC"
1568 ++ validity time for sended message-packages in seconds.
1569 ++ (how long this message-data is forwarded through the net)
1570 ++ (default: 300 - 5 mins)
1571 ++
1572 ++---------------------------------------------------------------------
1573 ++SAMPLE CONFIG
1574 ++---------------------------------------------------------------------
1575 ++
1576 ++add in /etc/olsrd.conf:
1577 ++
1578 ++LoadPlugin "olsrd_ondataservice_light.so.0.1"
1579 ++{
1580 ++ PlParam "interval" "120"
1581 ++ PlParam "database" "/tmp/database.json"
1582 ++}
1583 +diff --git a/lib/ondataservice_light/src/cJSON.c b/lib/ondataservice_light/src/cJSON.c
1584 +new file mode 100644
1585 +index 0000000..a5d910e
1586 +--- /dev/null
1587 ++++ b/lib/ondataservice_light/src/cJSON.c
1588 +@@ -0,0 +1,516 @@
1589 ++/*
1590 ++ Copyright (c) 2009 Dave Gamble
1591 ++
1592 ++ Permission is hereby granted, free of charge, to any person obtaining a copy
1593 ++ of this software and associated documentation files (the "Software"), to deal
1594 ++ in the Software without restriction, including without limitation the rights
1595 ++ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1596 ++ copies of the Software, and to permit persons to whom the Software is
1597 ++ furnished to do so, subject to the following conditions:
1598 ++
1599 ++ The above copyright notice and this permission notice shall be included in
1600 ++ all copies or substantial portions of the Software.
1601 ++
1602 ++ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1603 ++ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1604 ++ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1605 ++ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1606 ++ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1607 ++ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
1608 ++ THE SOFTWARE.
1609 ++*/
1610 ++
1611 ++/* cJSON */
1612 ++/* JSON parser in C. */
1613 ++
1614 ++#include <string.h>
1615 ++#include <stdio.h>
1616 ++#include <math.h>
1617 ++#include <stdlib.h>
1618 ++#include <float.h>
1619 ++#include <limits.h>
1620 ++#include <ctype.h>
1621 ++#include "cJSON.h"
1622 ++
1623 ++static const char *ep;
1624 ++
1625 ++// const char *cJSON_GetErrorPtr(void) {return ep;}
1626 ++
1627 ++// static int cJSON_strcasecmp(const char *s1,const char *s2)
1628 ++// {
1629 ++// if (!s1) return (s1==s2)?0:1;if (!s2) return 1;
1630 ++// for(; tolower(*s1) == tolower(*s2); ++s1, ++s2) if(*s1 == 0) return 0;
1631 ++// return tolower(*(const unsigned char *)s1) - tolower(*(const unsigned char *)s2);
1632 ++// }
1633 ++
1634 ++static void *(*cJSON_malloc)(size_t sz) = malloc;
1635 ++static void (*cJSON_free)(void *ptr) = free;
1636 ++
1637 ++static char* cJSON_strdup(const char* str)
1638 ++{
1639 ++ size_t len;
1640 ++ char* copy;
1641 ++
1642 ++ len = strlen(str) + 1;
1643 ++ if (!(copy = (char*)cJSON_malloc(len))) return 0;
1644 ++ memcpy(copy,str,len);
1645 ++ return copy;
1646 ++}
1647 ++
1648 ++void cJSON_InitHooks(cJSON_Hooks* hooks)
1649 ++{
1650 ++ if (!hooks) { /* Reset hooks */
1651 ++ cJSON_malloc = malloc;
1652 ++ cJSON_free = free;
1653 ++ return;
1654 ++ }
1655 ++
1656 ++ cJSON_malloc = (hooks->malloc_fn)?hooks->malloc_fn:malloc;
1657 ++ cJSON_free = (hooks->free_fn)?hooks->free_fn:free;
1658 ++}
1659 ++
1660 ++/* Internal constructor. */
1661 ++static cJSON *cJSON_New_Item(void)
1662 ++{
1663 ++ cJSON* node = (cJSON*)cJSON_malloc(sizeof(cJSON));
1664 ++ if (node) memset(node,0,sizeof(cJSON));
1665 ++ return node;
1666 ++}
1667 ++
1668 ++/* Delete a cJSON structure. */
1669 ++void cJSON_Delete(cJSON *c)
1670 ++{
1671 ++ cJSON *next;
1672 ++ while (c)
1673 ++ {
1674 ++ next=c->next;
1675 ++ if (!(c->type&cJSON_IsReference) && c->child) cJSON_Delete(c->child);
1676 ++ if (!(c->type&cJSON_IsReference) && c->valuestring) cJSON_free(c->valuestring);
1677 ++ if (c->string) cJSON_free(c->string);
1678 ++ cJSON_free(c);
1679 ++ c=next;
1680 ++ }
1681 ++}
1682 ++
1683 ++// /* Parse the input text to generate a number, and populate the result into item. */
1684 ++// static const char *parse_number(cJSON *item,const char *num)
1685 ++// {
1686 ++// double n=0,sign=1,scale=0;int subscale=0,signsubscale=1;
1687 ++//
1688 ++// /* Could use sscanf for this? */
1689 ++// if (*num=='-') sign=-1,num++; /* Has sign? */
1690 ++// if (*num=='0') num++; /* is zero */
1691 ++// if (*num>='1' && *num<='9') do n=(n*10.0)+(*num++ -'0'); while (*num>='0' && *num<='9'); /* Number? */
1692 ++// if (*num=='.' && num[1]>='0' && num[1]<='9') {num++; do n=(n*10.0)+(*num++ -'0'),scale--; while (*num>='0' && *num<='9');} /* Fractional part? */
1693 ++// if (*num=='e' || *num=='E') /* Exponent? */
1694 ++// { num++;if (*num=='+') num++; else if (*num=='-') signsubscale=-1,num++; /* With sign? */
1695 ++// while (*num>='0' && *num<='9') subscale=(subscale*10)+(*num++ - '0'); /* Number? */
1696 ++// }
1697 ++//
1698 ++// n=sign*n*pow(10.0,(scale+subscale*signsubscale)); /* number = +/- number.fraction * 10^+/- exponent */
1699 ++//
1700 ++// item->valuedouble=n;
1701 ++// item->valueint=(int)n;
1702 ++// item->type=cJSON_Number;
1703 ++// return num;
1704 ++// }
1705 ++
1706 ++// /* Render the number nicely from the given item into a string. */
1707 ++// static char *print_number(cJSON *item)
1708 ++// {
1709 ++// char *str;
1710 ++// double d=item->valuedouble;
1711 ++// if (fabs(((double)item->valueint)-d)<=DBL_EPSILON && d<=INT_MAX && d>=INT_MIN)
1712 ++// {
1713 ++// str=(char*)cJSON_malloc(21); /* 2^64+1 can be represented in 21 chars. */
1714 ++// if (str) sprintf(str,"%d",item->valueint);
1715 ++// }
1716 ++// else
1717 ++// {
1718 ++// str=(char*)cJSON_malloc(64); /* This is a nice tradeoff. */
1719 ++// if (str)
1720 ++// {
1721 ++// if (fabs(floor(d)-d)<=DBL_EPSILON) sprintf(str,"%.0f",d);
1722 ++// else if (fabs(d)<1.0e-6 || fabs(d)>1.0e9) sprintf(str,"%e",d);
1723 ++// else sprintf(str,"%f",d);
1724 ++// }
1725 ++// }
1726 ++// return str;
1727 ++// }
1728 ++
1729 ++/* Parse the input text into an unescaped cstring, and populate item. */
1730 ++static const unsigned char firstByteMark[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };
1731 ++static const char *parse_string(cJSON *item,const char *str)
1732 ++{
1733 ++ const char *ptr=str+1;char *ptr2;char *out;int len=0;unsigned uc,uc2;
1734 ++ if (*str!='\"') {ep=str;return 0;} /* not a string! */
1735 ++
1736 ++ while (*ptr!='\"' && *ptr && ++len) if (*ptr++ == '\\') ptr++; /* Skip escaped quotes. */
1737 ++
1738 ++ out=(char*)cJSON_malloc(len+1); /* This is how long we need for the string, roughly. */
1739 ++ if (!out) return 0;
1740 ++
1741 ++ ptr=str+1;ptr2=out;
1742 ++ while (*ptr!='\"' && *ptr)
1743 ++ {
1744 ++ if (*ptr!='\\') *ptr2++=*ptr++;
1745 ++ else
1746 ++ {
1747 ++ ptr++;
1748 ++ switch (*ptr)
1749 ++ {
1750 ++ case 'b': *ptr2++='\b'; break;
1751 ++ case 'f': *ptr2++='\f'; break;
1752 ++ case 'n': *ptr2++='\n'; break;
1753 ++ case 'r': *ptr2++='\r'; break;
1754 ++ case 't': *ptr2++='\t'; break;
1755 ++ case 'u': /* transcode utf16 to utf8. */
1756 ++ sscanf(ptr+1,"%4x",&uc);ptr+=4; /* get the unicode char. */
1757 ++
1758 ++ if ((uc>=0xDC00 && uc<=0xDFFF) || uc==0) break; // check for invalid.
1759 ++
1760 ++ if (uc>=0xD800 && uc<=0xDBFF) // UTF16 surrogate pairs.
1761 ++ {
1762 ++ if (ptr[1]!='\\' || ptr[2]!='u') break; // missing second-half of surrogate.
1763 ++ sscanf(ptr+3,"%4x",&uc2);ptr+=6;
1764 ++ if (uc2<0xDC00 || uc2>0xDFFF) break; // invalid second-half of surrogate.
1765 ++ uc=0x10000 | ((uc&0x3FF)<<10) | (uc2&0x3FF);
1766 ++ }
1767 ++
1768 ++ len=4;if (uc<0x80) len=1;else if (uc<0x800) len=2;else if (uc<0x10000) len=3; ptr2+=len;
1769 ++
1770 ++ switch (len) {
1771 ++ case 4: *--ptr2 =((uc | 0x80) & 0xBF); uc >>= 6;
1772 ++ case 3: *--ptr2 =((uc | 0x80) & 0xBF); uc >>= 6;
1773 ++ case 2: *--ptr2 =((uc | 0x80) & 0xBF); uc >>= 6;
1774 ++ case 1:
1775 ++ default:
1776 ++ *--ptr2 =(uc | firstByteMark[len]);
1777 ++ }
1778 ++ ptr2+=len;
1779 ++ break;
1780 ++ default: *ptr2++=*ptr; break;
1781 ++ }
1782 ++ ptr++;
1783 ++ }
1784 ++ }
1785 ++ *ptr2=0;
1786 ++ if (*ptr=='\"') ptr++;
1787 ++ item->valuestring=out;
1788 ++ item->type=cJSON_String;
1789 ++ return ptr;
1790 ++}
1791 ++
1792 ++// /* Render the cstring provided to an escaped version that can be printed. */
1793 ++// static char *print_string_ptr(const char *str)
1794 ++// {
1795 ++// const char *ptr;char *ptr2,*out;int len=0;unsigned char token;
1796 ++//
1797 ++// if (!str) return cJSON_strdup("");
1798 ++// ptr=str;while ((token=*ptr) && ++len) {if (strchr("\"\\\b\f\n\r\t",token)) len++; else if (token<32) len+=5;ptr++;}
1799 ++//
1800 ++// out=(char*)cJSON_malloc(len+3);
1801 ++// if (!out) return 0;
1802 ++//
1803 ++// ptr2=out;ptr=str;
1804 ++// *ptr2++='\"';
1805 ++// while (*ptr)
1806 ++// {
1807 ++// if ((unsigned char)*ptr>31 && *ptr!='\"' && *ptr!='\\') *ptr2++=*ptr++;
1808 ++// else
1809 ++// {
1810 ++// *ptr2++='\\';
1811 ++// switch (token=*ptr++)
1812 ++// {
1813 ++// case '\\': *ptr2++='\\'; break;
1814 ++// case '\"': *ptr2++='\"'; break;
1815 ++// case '\b': *ptr2++='b'; break;
1816 ++// case '\f': *ptr2++='f'; break;
1817 ++// case '\n': *ptr2++='n'; break;
1818 ++// case '\r': *ptr2++='r'; break;
1819 ++// case '\t': *ptr2++='t'; break;
1820 ++// default: sprintf(ptr2,"u%04x",token);ptr2+=5; break; /* escape and print */
1821 ++// }
1822 ++// }
1823 ++// }
1824 ++// *ptr2++='\"';*ptr2++=0;
1825 ++// return out;
1826 ++// }
1827 ++// /* Invote print_string_ptr (which is useful) on an item. */
1828 ++// static char *print_string(cJSON *item) {return print_string_ptr(item->valuestring);}
1829 ++
1830 ++/* Predeclare these prototypes. */
1831 ++static const char *parse_value(cJSON *item,const char *value);
1832 ++// static char *print_value(cJSON *item,int depth,int fmt);
1833 ++// static const char *parse_array(cJSON *item,const char *value);
1834 ++// static char *print_array(cJSON *item,int depth,int fmt);
1835 ++static const char *parse_object(cJSON *item,const char *value);
1836 ++// static char *print_object(cJSON *item,int depth,int fmt);
1837 ++
1838 ++/* Utility to jump whitespace and cr/lf */
1839 ++static const char *skip(const char *in) {while (in && *in && (unsigned char)*in<=32) in++; return in;}
1840 ++
1841 ++/* Parse an object - create a new root, and populate. */
1842 ++cJSON *cJSON_Parse(const char *value)
1843 ++{
1844 ++ cJSON *c=cJSON_New_Item();
1845 ++ ep=0;
1846 ++ if (!c) return 0; /* memory fail */
1847 ++
1848 ++ if (!parse_value(c,skip(value))) {cJSON_Delete(c);return 0;}
1849 ++ return c;
1850 ++}
1851 ++
1852 ++/* Render a cJSON item/entity/structure to text. */
1853 ++// char *cJSON_Print(cJSON *item) {return print_value(item,0,1);}
1854 ++// char *cJSON_PrintUnformatted(cJSON *item) {return print_value(item,0,0);}
1855 ++
1856 ++/* Parser core - when encountering text, process appropriately. */
1857 ++static const char *parse_value(cJSON *item,const char *value)
1858 ++{
1859 ++ if (!value) return 0; /* Fail on null. */
1860 ++// if (!strncmp(value,"null",4)) { item->type=cJSON_NULL; return value+4; }
1861 ++// if (!strncmp(value,"false",5)) { item->type=cJSON_False; return value+5; }
1862 ++// if (!strncmp(value,"true",4)) { item->type=cJSON_True; item->valueint=1; return value+4; }
1863 ++ if (*value=='\"') { return parse_string(item,value); }
1864 ++// if (*value=='-' || (*value>='0' && *value<='9')) { return parse_number(item,value); }
1865 ++// if (*value=='[') { return parse_array(item,value); }
1866 ++ if (*value=='{') { return parse_object(item,value); }
1867 ++
1868 ++ ep=value;return 0; /* failure. */
1869 ++}
1870 ++
1871 ++/* Render a value to text. */
1872 ++// static char *print_value(cJSON *item,int depth,int fmt)
1873 ++// {
1874 ++// char *out=0;
1875 ++// if (!item) return 0;
1876 ++// switch ((item->type)&255)
1877 ++// {
1878 ++// case cJSON_NULL: out=cJSON_strdup("null"); break;
1879 ++// case cJSON_False: out=cJSON_strdup("false");break;
1880 ++// case cJSON_True: out=cJSON_strdup("true"); break;
1881 ++// case cJSON_Number: out=print_number(item);break;
1882 ++// case cJSON_String: out=print_string(item);break;
1883 ++// case cJSON_Array: out=print_array(item,depth,fmt);break;
1884 ++// case cJSON_Object: out=print_object(item,depth,fmt);break;
1885 ++// }
1886 ++// return out;
1887 ++// }
1888 ++
1889 ++// /* Build an array from input text. */
1890 ++// static const char *parse_array(cJSON *item,const char *value)
1891 ++// {
1892 ++// cJSON *child;
1893 ++// if (*value!='[') {ep=value;return 0;} /* not an array! */
1894 ++//
1895 ++// item->type=cJSON_Array;
1896 ++// value=skip(value+1);
1897 ++// if (*value==']') return value+1; /* empty array. */
1898 ++//
1899 ++// item->child=child=cJSON_New_Item();
1900 ++// if (!item->child) return 0; /* memory fail */
1901 ++// value=skip(parse_value(child,skip(value))); /* skip any spacing, get the value. */
1902 ++// if (!value) return 0;
1903 ++//
1904 ++// while (*value==',')
1905 ++// {
1906 ++// cJSON *new_item;
1907 ++// if (!(new_item=cJSON_New_Item())) return 0; /* memory fail */
1908 ++// child->next=new_item;new_item->prev=child;child=new_item;
1909 ++// value=skip(parse_value(child,skip(value+1)));
1910 ++// if (!value) return 0; /* memory fail */
1911 ++// }
1912 ++//
1913 ++// if (*value==']') return value+1; /* end of array */
1914 ++// ep=value;return 0; /* malformed. */
1915 ++// }
1916 ++
1917 ++/* Render an array to text */
1918 ++// static char *print_array(cJSON *item,int depth,int fmt)
1919 ++// {
1920 ++// char **entries;
1921 ++// char *out=0,*ptr,*ret;int len=5;
1922 ++// cJSON *child=item->child;
1923 ++// int numentries=0,i=0,fail=0;
1924 ++//
1925 ++// /* How many entries in the array? */
1926 ++// while (child) numentries++,child=child->next;
1927 ++// /* Allocate an array to hold the values for each */
1928 ++// entries=(char**)cJSON_malloc(numentries*sizeof(char*));
1929 ++// if (!entries) return 0;
1930 ++// memset(entries,0,numentries*sizeof(char*));
1931 ++// /* Retrieve all the results: */
1932 ++// child=item->child;
1933 ++// while (child && !fail)
1934 ++// {
1935 ++// ret=print_value(child,depth+1,fmt);
1936 ++// entries[i++]=ret;
1937 ++// if (ret) len+=strlen(ret)+2+(fmt?1:0); else fail=1;
1938 ++// child=child->next;
1939 ++// }
1940 ++//
1941 ++// /* If we didn't fail, try to malloc the output string */
1942 ++// if (!fail) out=(char*)cJSON_malloc(len);
1943 ++// /* If that fails, we fail. */
1944 ++// if (!out) fail=1;
1945 ++//
1946 ++// /* Handle failure. */
1947 ++// if (fail)
1948 ++// {
1949 ++// for (i=0;i<numentries;i++) if (entries[i]) cJSON_free(entries[i]);
1950 ++// cJSON_free(entries);
1951 ++// return 0;
1952 ++// }
1953 ++//
1954 ++// /* Compose the output array. */
1955 ++// *out='[';
1956 ++// ptr=out+1;*ptr=0;
1957 ++// for (i=0;i<numentries;i++)
1958 ++// {
1959 ++// strcpy(ptr,entries[i]);ptr+=strlen(entries[i]);
1960 ++// if (i!=numentries-1) {*ptr++=',';if(fmt)*ptr++=' ';*ptr=0;}
1961 ++// cJSON_free(entries[i]);
1962 ++// }
1963 ++// cJSON_free(entries);
1964 ++// *ptr++=']';*ptr++=0;
1965 ++// return out;
1966 ++// }
1967 ++
1968 ++/* Build an object from the text. */
1969 ++static const char *parse_object(cJSON *item,const char *value)
1970 ++{
1971 ++ cJSON *child;
1972 ++ if (*value!='{') {ep=value;return 0;} /* not an object! */
1973 ++
1974 ++ item->type=cJSON_Object;
1975 ++ value=skip(value+1);
1976 ++ if (*value=='}') return value+1; /* empty array. */
1977 ++
1978 ++ item->child=child=cJSON_New_Item();
1979 ++ if (!item->child) return 0;
1980 ++ value=skip(parse_string(child,skip(value)));
1981 ++ if (!value) return 0;
1982 ++ child->string=child->valuestring;child->valuestring=0;
1983 ++ if (*value!=':') {ep=value;return 0;} /* fail! */
1984 ++ value=skip(parse_value(child,skip(value+1))); /* skip any spacing, get the value. */
1985 ++ if (!value) return 0;
1986 ++
1987 ++ while (*value==',')
1988 ++ {
1989 ++ cJSON *new_item;
1990 ++ if (!(new_item=cJSON_New_Item())) return 0; /* memory fail */
1991 ++ child->next=new_item;new_item->prev=child;child=new_item;
1992 ++ value=skip(parse_string(child,skip(value+1)));
1993 ++ if (!value) return 0;
1994 ++ child->string=child->valuestring;child->valuestring=0;
1995 ++ if (*value!=':') {ep=value;return 0;} /* fail! */
1996 ++ value=skip(parse_value(child,skip(value+1))); /* skip any spacing, get the value. */
1997 ++ if (!value) return 0;
1998 ++ }
1999 ++
2000 ++ if (*value=='}') return value+1; /* end of array */
2001 ++ ep=value;return 0; /* malformed. */
2002 ++}
2003 ++
2004 ++// /* Render an object to text. */
2005 ++// static char *print_object(cJSON *item,int depth,int fmt)
2006 ++// {
2007 ++// char **entries=0,**names=0;
2008 ++// char *out=0,*ptr,*ret,*str;int len=7,i=0,j;
2009 ++// cJSON *child=item->child;
2010 ++// int numentries=0,fail=0;
2011 ++// /* Count the number of entries. */
2012 ++// while (child) numentries++,child=child->next;
2013 ++// /* Allocate space for the names and the objects */
2014 ++// entries=(char**)cJSON_malloc(numentries*sizeof(char*));
2015 ++// if (!entries) return 0;
2016 ++// names=(char**)cJSON_malloc(numentries*sizeof(char*));
2017 ++// if (!names) {cJSON_free(entries);return 0;}
2018 ++// memset(entries,0,sizeof(char*)*numentries);
2019 ++// memset(names,0,sizeof(char*)*numentries);
2020 ++//
2021 ++// /* Collect all the results into our arrays: */
2022 ++// child=item->child;depth++;if (fmt) len+=depth;
2023 ++// while (child)
2024 ++// {
2025 ++// names[i]=str=print_string_ptr(child->string);
2026 ++// entries[i++]=ret=print_value(child,depth,fmt);
2027 ++// if (str && ret) len+=strlen(ret)+strlen(str)+2+(fmt?2+depth:0); else fail=1;
2028 ++// child=child->next;
2029 ++// }
2030 ++//
2031 ++// /* Try to allocate the output string */
2032 ++// if (!fail) out=(char*)cJSON_malloc(len);
2033 ++// if (!out) fail=1;
2034 ++//
2035 ++// /* Handle failure */
2036 ++// if (fail)
2037 ++// {
2038 ++// for (i=0;i<numentries;i++) {if (names[i]) cJSON_free(names[i]);if (entries[i]) cJSON_free(entries[i]);}
2039 ++// cJSON_free(names);cJSON_free(entries);
2040 ++// return 0;
2041 ++// }
2042 ++//
2043 ++// /* Compose the output: */
2044 ++// *out='{';ptr=out+1;if (fmt)*ptr++='\n';*ptr=0;
2045 ++// for (i=0;i<numentries;i++)
2046 ++// {
2047 ++// if (fmt) for (j=0;j<depth;j++) *ptr++='\t';
2048 ++// strcpy(ptr,names[i]);ptr+=strlen(names[i]);
2049 ++// *ptr++=':';if (fmt) *ptr++='\t';
2050 ++// strcpy(ptr,entries[i]);ptr+=strlen(entries[i]);
2051 ++// if (i!=numentries-1) *ptr++=',';
2052 ++// if (fmt) *ptr++='\n';*ptr=0;
2053 ++// cJSON_free(names[i]);cJSON_free(entries[i]);
2054 ++// }
2055 ++//
2056 ++// cJSON_free(names);cJSON_free(entries);
2057 ++// if (fmt) for (i=0;i<depth-1;i++) *ptr++='\t';
2058 ++// *ptr++='}';*ptr++=0;
2059 ++// return out;
2060 ++// }
2061 ++
2062 ++/* Get Array size/item / object item. */
2063 ++// int cJSON_GetArraySize(cJSON *array) {cJSON *c=array->child;int i=0;while(c)i++,c=c->next;return i;}
2064 ++// cJSON *cJSON_GetArrayItem(cJSON *array,int item) {cJSON *c=array->child; while (c && item>0) item--,c=c->next; return c;}
2065 ++// cJSON *cJSON_GetObjectItem(cJSON *object,const char *string) {cJSON *c=object->child; while (c && cJSON_strcasecmp(c->string,string)) c=c->next; return c;}
2066 ++
2067 ++/* Utility for array list handling. */
2068 ++// static void suffix_object(cJSON *prev,cJSON *item) {prev->next=item;item->prev=prev;}
2069 ++/* Utility for handling references. */
2070 ++// 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;}
2071 ++
2072 ++/* Add item to array/object. */
2073 ++// 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);}}
2074 ++// 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);}
2075 ++// void cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item) {cJSON_AddItemToArray(array,create_reference(item));}
2076 ++// void cJSON_AddItemReferenceToObject(cJSON *object,const char *string,cJSON *item) {cJSON_AddItemToObject(object,string,create_reference(item));}
2077 ++
2078 ++// cJSON *cJSON_DetachItemFromArray(cJSON *array,int which) {cJSON *c=array->child;while (c && which>0) c=c->next,which--;if (!c) return 0;
2079 ++// 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;}
2080 ++// void cJSON_DeleteItemFromArray(cJSON *array,int which) {cJSON_Delete(cJSON_DetachItemFromArray(array,which));}
2081 ++// 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;}
2082 ++// void cJSON_DeleteItemFromObject(cJSON *object,const char *string) {cJSON_Delete(cJSON_DetachItemFromObject(object,string));}
2083 ++
2084 ++/* Replace array/object items with new ones. */
2085 ++// void cJSON_ReplaceItemInArray(cJSON *array,int which,cJSON *newitem) {cJSON *c=array->child;while (c && which>0) c=c->next,which--;if (!c) return;
2086 ++// newitem->next=c->next;newitem->prev=c->prev;if (newitem->next) newitem->next->prev=newitem;
2087 ++// if (c==array->child) array->child=newitem; else newitem->prev->next=newitem;c->next=c->prev=0;cJSON_Delete(c);}
2088 ++// 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);}}
2089 ++
2090 ++/* Create basic types: */
2091 ++// cJSON *cJSON_CreateNull(void) {cJSON *item=cJSON_New_Item();if(item)item->type=cJSON_NULL;return item;}
2092 ++// cJSON *cJSON_CreateTrue(void) {cJSON *item=cJSON_New_Item();if(item)item->type=cJSON_True;return item;}
2093 ++// cJSON *cJSON_CreateFalse(void) {cJSON *item=cJSON_New_Item();if(item)item->type=cJSON_False;return item;}
2094 ++// cJSON *cJSON_CreateBool(int b) {cJSON *item=cJSON_New_Item();if(item)item->type=b?cJSON_True:cJSON_False;return item;}
2095 ++// 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;}
2096 ++cJSON *cJSON_CreateString(const char *string) {cJSON *item=cJSON_New_Item();if(item){item->type=cJSON_String;item->valuestring=cJSON_strdup(string);}return item;}
2097 ++// cJSON *cJSON_CreateArray(void) {cJSON *item=cJSON_New_Item();if(item)item->type=cJSON_Array;return item;}
2098 ++cJSON *cJSON_CreateObject(void) {cJSON *item=cJSON_New_Item();if(item)item->type=cJSON_Object;return item;}
2099 ++
2100 ++/* Create Arrays: */
2101 ++// 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;}
2102 ++// 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;}
2103 ++// 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;}
2104 ++// 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;}
2105 +diff --git a/lib/ondataservice_light/src/cJSON.h b/lib/ondataservice_light/src/cJSON.h
2106 +new file mode 100644
2107 +index 0000000..158160c
2108 +--- /dev/null
2109 ++++ b/lib/ondataservice_light/src/cJSON.h
2110 +@@ -0,0 +1,127 @@
2111 ++/*
2112 ++ Copyright (c) 2009 Dave Gamble
2113 ++
2114 ++ Permission is hereby granted, free of charge, to any person obtaining a copy
2115 ++ of this software and associated documentation files (the "Software"), to deal
2116 ++ in the Software without restriction, including without limitation the rights
2117 ++ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
2118 ++ copies of the Software, and to permit persons to whom the Software is
2119 ++ furnished to do so, subject to the following conditions:
2120 ++
2121 ++ The above copyright notice and this permission notice shall be included in
2122 ++ all copies or substantial portions of the Software.
2123 ++
2124 ++ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
2125 ++ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2126 ++ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
2127 ++ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2128 ++ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2129 ++ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2130 ++ THE SOFTWARE.
2131 ++*/
2132 ++
2133 ++#ifndef cJSON__h
2134 ++#define cJSON__h
2135 ++
2136 ++#ifdef __cplusplus
2137 ++extern "C"
2138 ++{
2139 ++#endif
2140 ++
2141 ++/* cJSON Types: */
2142 ++#define cJSON_False 0
2143 ++#define cJSON_True 1
2144 ++#define cJSON_NULL 2
2145 ++#define cJSON_Number 3
2146 ++#define cJSON_String 4
2147 ++#define cJSON_Array 5
2148 ++#define cJSON_Object 6
2149 ++
2150 ++#define cJSON_IsReference 256
2151 ++
2152 ++/* The cJSON structure: */
2153 ++typedef struct cJSON {
2154 ++ struct cJSON *next,*prev; /* next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem */
2155 ++ struct cJSON *child; /* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */
2156 ++
2157 ++ int type; /* The type of the item, as above. */
2158 ++
2159 ++ char *valuestring; /* The item's string, if type==cJSON_String */
2160 ++ int valueint; /* The item's number, if type==cJSON_Number */
2161 ++ double valuedouble; /* The item's number, if type==cJSON_Number */
2162 ++
2163 ++ char *string; /* The item's name string, if this item is the child of, or is in the list of subitems of an object. */
2164 ++} cJSON;
2165 ++
2166 ++typedef struct cJSON_Hooks {
2167 ++ void *(*malloc_fn)(size_t sz);
2168 ++ void (*free_fn)(void *ptr);
2169 ++} cJSON_Hooks;
2170 ++
2171 ++/* Supply malloc, realloc and free functions to cJSON */
2172 ++extern void cJSON_InitHooks(cJSON_Hooks* hooks);
2173 ++
2174 ++
2175 ++/* Supply a block of JSON, and this returns a cJSON object you can interrogate. Call cJSON_Delete when finished. */
2176 ++extern cJSON *cJSON_Parse(const char *value);
2177 ++/* Render a cJSON entity to text for transfer/storage. Free the char* when finished. */
2178 ++// extern char *cJSON_Print(cJSON *item);
2179 ++/* Render a cJSON entity to text for transfer/storage without any formatting. Free the char* when finished. */
2180 ++// extern char *cJSON_PrintUnformatted(cJSON *item);
2181 ++/* Delete a cJSON entity and all subentities. */
2182 ++extern void cJSON_Delete(cJSON *c);
2183 ++
2184 ++/* Returns the number of items in an array (or object). */
2185 ++// extern int cJSON_GetArraySize(cJSON *array);
2186 ++/* Retrieve item number "item" from array "array". Returns NULL if unsuccessful. */
2187 ++// extern cJSON *cJSON_GetArrayItem(cJSON *array,int item);
2188 ++/* Get item "string" from object. Case insensitive. */
2189 ++// extern cJSON *cJSON_GetObjectItem(cJSON *object,const char *string);
2190 ++
2191 ++/* 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. */
2192 ++// extern const char *cJSON_GetErrorPtr(void);
2193 ++
2194 ++/* These calls create a cJSON item of the appropriate type. */
2195 ++// extern cJSON *cJSON_CreateNull(void);
2196 ++// extern cJSON *cJSON_CreateTrue(void);
2197 ++// extern cJSON *cJSON_CreateFalse(void);
2198 ++// extern cJSON *cJSON_CreateBool(int b);
2199 ++// extern cJSON *cJSON_CreateNumber(double num);
2200 ++extern cJSON *cJSON_CreateString(const char *string);
2201 ++// extern cJSON *cJSON_CreateArray(void);
2202 ++extern cJSON *cJSON_CreateObject(void);
2203 ++
2204 ++/* These utilities create an Array of count items. */
2205 ++// extern cJSON *cJSON_CreateIntArray(int *numbers,int count);
2206 ++// extern cJSON *cJSON_CreateFloatArray(float *numbers,int count);
2207 ++// extern cJSON *cJSON_CreateDoubleArray(double *numbers,int count);
2208 ++// extern cJSON *cJSON_CreateStringArray(const char **strings,int count);
2209 ++
2210 ++/* Append item to the specified array/object. */
2211 ++// extern void cJSON_AddItemToArray(cJSON *array, cJSON *item);
2212 ++// extern void cJSON_AddItemToObject(cJSON *object,const char *string,cJSON *item);
2213 ++/* 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. */
2214 ++// extern void cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item);
2215 ++// extern void cJSON_AddItemReferenceToObject(cJSON *object,const char *string,cJSON *item);
2216 ++
2217 ++/* Remove/Detatch items from Arrays/Objects. */
2218 ++// extern cJSON *cJSON_DetachItemFromArray(cJSON *array,int which);
2219 ++// extern void cJSON_DeleteItemFromArray(cJSON *array,int which);
2220 ++// extern cJSON *cJSON_DetachItemFromObject(cJSON *object,const char *string);
2221 ++// extern void cJSON_DeleteItemFromObject(cJSON *object,const char *string);
2222 ++
2223 ++/* Update array items. */
2224 ++// extern void cJSON_ReplaceItemInArray(cJSON *array,int which,cJSON *newitem);
2225 ++// extern void cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem);
2226 ++
2227 ++#define cJSON_AddNullToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateNull())
2228 ++#define cJSON_AddTrueToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateTrue())
2229 ++#define cJSON_AddFalseToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateFalse())
2230 ++#define cJSON_AddNumberToObject(object,name,n) cJSON_AddItemToObject(object, name, cJSON_CreateNumber(n))
2231 ++#define cJSON_AddStringToObject(object,name,s) cJSON_AddItemToObject(object, name, cJSON_CreateString(s))
2232 ++
2233 ++#ifdef __cplusplus
2234 ++}
2235 ++#endif
2236 ++
2237 ++#endif
2238 +diff --git a/lib/ondataservice_light/src/compat.c b/lib/ondataservice_light/src/compat.c
2239 +new file mode 100644
2240 +index 0000000..4d639be
2241 +--- /dev/null
2242 ++++ b/lib/ondataservice_light/src/compat.c
2243 +@@ -0,0 +1,35 @@
2244 ++#include "compat.h"
2245 ++
2246 ++#if !defined(__linux__) && !defined(__GLIBC__)
2247 ++#include <stdlib.h>
2248 ++#include <string.h>
2249 ++
2250 ++/* strndup() is a GNU extention */
2251 ++char *
2252 ++strndup(const char *ptr, size_t size)
2253 ++{
2254 ++ size_t len = strlen(ptr);
2255 ++ char *ret = NULL;
2256 ++
2257 ++ if (len > size)
2258 ++ len = size;
2259 ++
2260 ++ ret = malloc(len + 1);
2261 ++
2262 ++ if (!ret)
2263 ++ return NULL;
2264 ++
2265 ++ memcpy(ret, ptr, len);
2266 ++ ret[len] = '\0';
2267 ++
2268 ++ return ret;
2269 ++}
2270 ++
2271 ++#endif
2272 ++
2273 ++/*
2274 ++ * Local Variables:
2275 ++ * c-basic-offset: 2
2276 ++ * indent-tabs-mode: nil
2277 ++ * End:
2278 ++ */
2279 +diff --git a/lib/ondataservice_light/src/compat.h b/lib/ondataservice_light/src/compat.h
2280 +new file mode 100644
2281 +index 0000000..c607c91
2282 +--- /dev/null
2283 ++++ b/lib/ondataservice_light/src/compat.h
2284 +@@ -0,0 +1,17 @@
2285 ++#ifndef _NAMESERVICE_COMPAT
2286 ++#define _NAMESERVICE_COMPAT
2287 ++
2288 ++#include <sys/types.h>
2289 ++
2290 ++#if !defined(__linux__) && !defined(__GLIBC__)
2291 ++char *strndup(const char *ptr, size_t size);
2292 ++#endif
2293 ++
2294 ++#endif
2295 ++
2296 ++/*
2297 ++ * Local Variables:
2298 ++ * c-basic-offset: 2
2299 ++ * indent-tabs-mode: nil
2300 ++ * End:
2301 ++ */
2302 +diff --git a/lib/ondataservice_light/src/crc16.c b/lib/ondataservice_light/src/crc16.c
2303 +new file mode 100644
2304 +index 0000000..dc877ca
2305 +--- /dev/null
2306 ++++ b/lib/ondataservice_light/src/crc16.c
2307 +@@ -0,0 +1,62 @@
2308 ++#include <stdlib.h>
2309 ++#include "crc16.h"
2310 ++
2311 ++// ------------ http://stackoverflow.com/questions/3853670/are-there-any-free-crc-libraries-that-covers-a-lot-of-the-crc-algorithms
2312 ++
2313 ++/******************************************/
2314 ++/* CRC table for polynomial 0xA001 CCITT */
2315 ++/******************************************/
2316 ++
2317 ++#define CRC16(crc,c) crc = (crc >> 8) ^ crctab[(crc ^ c) & 0xff]
2318 ++
2319 ++const u_int16_t crctab[256] = {
2320 ++ 0x0000, 0xc0c1, 0xc181, 0x0140, 0xc301, 0x03c0, 0x0280, 0xc241,
2321 ++ 0xc601, 0x06c0, 0x0780, 0xc741, 0x0500, 0xc5c1, 0xc481, 0x0440,
2322 ++ 0xcc01, 0x0cc0, 0x0d80, 0xcd41, 0x0f00, 0xcfc1, 0xce81, 0x0e40,
2323 ++ 0x0a00, 0xcac1, 0xcb81, 0x0b40, 0xc901, 0x09c0, 0x0880, 0xc841,
2324 ++ 0xd801, 0x18c0, 0x1980, 0xd941, 0x1b00, 0xdbc1, 0xda81, 0x1a40,
2325 ++ 0x1e00, 0xdec1, 0xdf81, 0x1f40, 0xdd01, 0x1dc0, 0x1c80, 0xdc41,
2326 ++ 0x1400, 0xd4c1, 0xd581, 0x1540, 0xd701, 0x17c0, 0x1680, 0xd641,
2327 ++ 0xd201, 0x12c0, 0x1380, 0xd341, 0x1100, 0xd1c1, 0xd081, 0x1040,
2328 ++ 0xf001, 0x30c0, 0x3180, 0xf141, 0x3300, 0xf3c1, 0xf281, 0x3240,
2329 ++ 0x3600, 0xf6c1, 0xf781, 0x3740, 0xf501, 0x35c0, 0x3480, 0xf441,
2330 ++ 0x3c00, 0xfcc1, 0xfd81, 0x3d40, 0xff01, 0x3fc0, 0x3e80, 0xfe41,
2331 ++ 0xfa01, 0x3ac0, 0x3b80, 0xfb41, 0x3900, 0xf9c1, 0xf881, 0x3840,
2332 ++ 0x2800, 0xe8c1, 0xe981, 0x2940, 0xeb01, 0x2bc0, 0x2a80, 0xea41,
2333 ++ 0xee01, 0x2ec0, 0x2f80, 0xef41, 0x2d00, 0xedc1, 0xec81, 0x2c40,
2334 ++ 0xe401, 0x24c0, 0x2580, 0xe541, 0x2700, 0xe7c1, 0xe681, 0x2640,
2335 ++ 0x2200, 0xe2c1, 0xe381, 0x2340, 0xe101, 0x21c0, 0x2080, 0xe041,
2336 ++ 0xa001, 0x60c0, 0x6180, 0xa141, 0x6300, 0xa3c1, 0xa281, 0x6240,
2337 ++ 0x6600, 0xa6c1, 0xa781, 0x6740, 0xa501, 0x65c0, 0x6480, 0xa441,
2338 ++ 0x6c00, 0xacc1, 0xad81, 0x6d40, 0xaf01, 0x6fc0, 0x6e80, 0xae41,
2339 ++ 0xaa01, 0x6ac0, 0x6b80, 0xab41, 0x6900, 0xa9c1, 0xa881, 0x6840,
2340 ++ 0x7800, 0xb8c1, 0xb981, 0x7940, 0xbb01, 0x7bc0, 0x7a80, 0xba41,
2341 ++ 0xbe01, 0x7ec0, 0x7f80, 0xbf41, 0x7d00, 0xbdc1, 0xbc81, 0x7c40,
2342 ++ 0xb401, 0x74c0, 0x7580, 0xb541, 0x7700, 0xb7c1, 0xb681, 0x7640,
2343 ++ 0x7200, 0xb2c1, 0xb381, 0x7340, 0xb101, 0x71c0, 0x7080, 0xb041,
2344 ++ 0x5000, 0x90c1, 0x9181, 0x5140, 0x9301, 0x53c0, 0x5280, 0x9241,
2345 ++ 0x9601, 0x56c0, 0x5780, 0x9741, 0x5500, 0x95c1, 0x9481, 0x5440,
2346 ++ 0x9c01, 0x5cc0, 0x5d80, 0x9d41, 0x5f00, 0x9fc1, 0x9e81, 0x5e40,
2347 ++ 0x5a00, 0x9ac1, 0x9b81, 0x5b40, 0x9901, 0x59c0, 0x5880, 0x9841,
2348 ++ 0x8801, 0x48c0, 0x4980, 0x8941, 0x4b00, 0x8bc1, 0x8a81, 0x4a40,
2349 ++ 0x4e00, 0x8ec1, 0x8f81, 0x4f40, 0x8d01, 0x4dc0, 0x4c80, 0x8c41,
2350 ++ 0x4400, 0x84c1, 0x8581, 0x4540, 0x8701, 0x47c0, 0x4680, 0x8641,
2351 ++ 0x8201, 0x42c0, 0x4380, 0x8341, 0x4100, 0x81c1, 0x8081, 0x4040
2352 ++};
2353 ++
2354 ++//=========================================================================
2355 ++// Description: Calculate a CRC on a buffer
2356 ++// Parameters: buffer - address of buffer
2357 ++// length - length of buffer
2358 ++// Returns: CRC
2359 ++//=========================================================================
2360 ++u_int16_t crcCalculate(char *buffer, unsigned int length)
2361 ++{
2362 ++ u_int16_t Crc = 0;
2363 ++
2364 ++ for (; length; --length) {
2365 ++ CRC16(Crc, *buffer++);
2366 ++ }
2367 ++ return(Crc);
2368 ++}
2369 ++
2370 +diff --git a/lib/ondataservice_light/src/crc16.h b/lib/ondataservice_light/src/crc16.h
2371 +new file mode 100644
2372 +index 0000000..729d784
2373 +--- /dev/null
2374 ++++ b/lib/ondataservice_light/src/crc16.h
2375 +@@ -0,0 +1,6 @@
2376 ++
2377 ++// copied from http://stackoverflow.com/questions/3853670/are-there-any-free-crc-libraries-that-covers-a-lot-of-the-crc-algorithms
2378 ++
2379 ++
2380 ++u_int16_t crcCalculate(char *buffer, unsigned int length);
2381 ++
2382 +diff --git a/lib/ondataservice_light/src/olsrd_plugin.c b/lib/ondataservice_light/src/olsrd_plugin.c
2383 +new file mode 100644
2384 +index 0000000..c6989c5
2385 +--- /dev/null
2386 ++++ b/lib/ondataservice_light/src/olsrd_plugin.c
2387 +@@ -0,0 +1,84 @@
2388 ++
2389 ++/*
2390 ++ * Copyright (c) 2005, Bruno Randolf <bruno.randolf@4g-systems.biz>
2391 ++ * Copyright (c) 2004, Andreas Tonnesen(andreto-at-olsr.org)
2392 ++ * All rights reserved.
2393 ++ *
2394 ++ * Redistribution and use in source and binary forms, with or without
2395 ++ * modification, are permitted provided that the following conditions
2396 ++ * are met:
2397 ++ *
2398 ++ * * Redistributions of source code must retain the above copyright notice,
2399 ++ * this list of conditions and the following disclaimer.
2400 ++ * * Redistributions in binary form must reproduce the above copyright notice,
2401 ++ * this list of conditions and the following disclaimer in the documentation
2402 ++ * and/or other materials provided with the distribution.
2403 ++ * * Neither the name of the UniK olsr daemon nor the names of its contributors
2404 ++ * may be used to endorse or promote products derived from this software
2405 ++ * without specific prior written permission.
2406 ++ *
2407 ++ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
2408 ++ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
2409 ++ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2410 ++ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
2411 ++ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
2412 ++ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2413 ++ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
2414 ++ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
2415 ++ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
2416 ++ * OF THE POSSIBILITY OF SUCH DAMAGE.
2417 ++ *
2418 ++ */
2419 ++
2420 ++/*
2421 ++ * Dynamic linked library for olsr.org olsrd
2422 ++ */
2423 ++
2424 ++#include <stdio.h>
2425 ++#include <string.h>
2426 ++
2427 ++#include "olsrd_plugin.h"
2428 ++#include "ondataservice.h"
2429 ++
2430 ++#define MOD_DESC PLUGIN_NAME " " PLUGIN_VERSION
2431 ++#define PLUGIN_INTERFACE_VERSION 5
2432 ++
2433 ++static void __attribute__ ((constructor)) my_init(void);
2434 ++
2435 ++static void __attribute__ ((destructor)) my_fini(void);
2436 ++
2437 ++int
2438 ++olsrd_plugin_interface_version(void)
2439 ++{
2440 ++ return PLUGIN_INTERFACE_VERSION;
2441 ++}
2442 ++
2443 ++int
2444 ++olsrd_plugin_init(void)
2445 ++{
2446 ++ return ondata_init();
2447 ++}
2448 ++
2449 ++static void
2450 ++my_init(void)
2451 ++{
2452 ++ /* Print plugin info to stdout */
2453 ++ printf("%s\n", MOD_DESC);
2454 ++
2455 ++ ondata_constructor();
2456 ++
2457 ++ return;
2458 ++}
2459 ++
2460 ++static void
2461 ++my_fini(void)
2462 ++{
2463 ++ ondata_destructor();
2464 ++}
2465 ++
2466 ++/*
2467 ++ * Local Variables:
2468 ++ * c-basic-offset: 2
2469 ++ * indent-tabs-mode: nil
2470 ++ * End:
2471 ++ */
2472 +diff --git a/lib/ondataservice_light/src/ondataservice.c b/lib/ondataservice_light/src/ondataservice.c
2473 +new file mode 100644
2474 +index 0000000..4f685c9
2475 +--- /dev/null
2476 ++++ b/lib/ondataservice_light/src/ondataservice.c
2477 +@@ -0,0 +1,313 @@
2478 ++
2479 ++/*
2480 ++ * Copyright (c) 2011, Rene Ejury <opennet@absorb.it>
2481 ++ * All rights reserved.
2482 ++ *
2483 ++ * Redistribution and use in source and binary forms, with or without
2484 ++ * modification, are permitted provided that the following conditions
2485 ++ * are met:
2486 ++ *
2487 ++ * * Redistributions of source code must retain the above copyright notice,
2488 ++ * this list of conditions and the following disclaimer.
2489 ++ * * Redistributions in binary form must reproduce the above copyright notice,
2490 ++ * this list of conditions and the following disclaimer in the documentation
2491 ++ * and/or other materials provided with the distribution.
2492 ++ * * Neither the name of the UniK olsr daemon nor the names of its contributors
2493 ++ * may be used to endorse or promote products derived from this software
2494 ++ * without specific prior written permission.
2495 ++ *
2496 ++ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
2497 ++ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
2498 ++ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2499 ++ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
2500 ++ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
2501 ++ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2502 ++ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
2503 ++ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
2504 ++ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
2505 ++ * OF THE POSSIBILITY OF SUCH DAMAGE.
2506 ++ *
2507 ++ */
2508 ++
2509 ++/*
2510 ++ * Dynamic linked library for UniK OLSRd
2511 ++ */
2512 ++
2513 ++#define _GNU_SOURCE 1
2514 ++
2515 ++#include <stdio.h>
2516 ++#include <string.h>
2517 ++#include <stdlib.h>
2518 ++#include <unistd.h>
2519 ++#include <ctype.h>
2520 ++#include <sys/types.h>
2521 ++#include <sys/stat.h>
2522 ++#include <signal.h>
2523 ++#include <fcntl.h>
2524 ++#include <time.h>
2525 ++
2526 ++
2527 ++#include "olsr.h"
2528 ++#include "net_olsr.h"
2529 ++#include "parser.h"
2530 ++
2531 ++#include "plugin_util.h"
2532 ++#include "ondataservice.h"
2533 ++#include "compat.h"
2534 ++#include "crc16.h"
2535 ++#include "cJSON.h"
2536 ++
2537 ++/* config parameters */
2538 ++static int my_interval = EMISSION_INTERVAL;
2539 ++static int my_inc_interval = EMISSION_INC_INTERVAL;
2540 ++static char my_database[MAX_FILE + 1];
2541 ++static int my_vtime = ONDATA_VALID_TIME; // how long the data will be spread trough the net
2542 ++
2543 ++/* periodic message generation */
2544 ++struct timer_entry *msg_gen_timer = NULL;
2545 ++
2546 ++
2549 ++void
2550 ++ondata_constructor(void)
2551 ++{
2552 ++#ifdef WIN32
2553 ++ int len;
2554 ++
2555 ++ GetWindowsDirectory(my_database, MAX_FILE - 12);
2556 ++
2557 ++ len = strlen(my_database);
2558 ++ if (my_database[len - 1] != '\\')
2559 ++ strscat(my_database, "\\", sizeof(my_database));
2560 ++ strscat(my_database, DATABASE_FILE, sizeof(my_database));
2561 ++
2562 ++#else
2563 ++ strscpy(my_database, DATABASE_FILE, sizeof(my_database));
2564 ++#endif
2565 ++
2566 ++}
2567 ++
2568 ++/* *INDENT-OFF* */
2569 ++static const struct olsrd_plugin_parameters plugin_parameters[] = {
2570 ++ { .name = "interval", .set_plugin_parameter = &set_plugin_int, .data = &my_interval },
2571 ++ { .name = "inc_interval", .set_plugin_parameter = &set_plugin_int, .data = &my_inc_interval },
2572 ++ { .name = "database", .set_plugin_parameter = &set_plugin_string, .data = &my_database, .addon = {sizeof(my_database)} },
2573 ++ { .name = "vtime", .set_plugin_parameter = &set_plugin_int, .data = &my_vtime },
2574 ++};
2575 ++/* *INDENT-OFF* */
2576 ++
2577 ++void
2578 ++olsrd_get_plugin_parameters(const struct olsrd_plugin_parameters **params, int *size)
2579 ++{
2580 ++ *params = plugin_parameters;
2581 ++ *size = sizeof(plugin_parameters) / sizeof(*plugin_parameters);
2582 ++}
2583 ++
2584 ++
2597 ++int
2598 ++ondata_init(void)
2599 ++{
2600 ++ /* periodic message generation */
2601 ++ msg_gen_timer = olsr_start_timer(my_interval * MSEC_PER_SEC, EMISSION_JITTER, OLSR_TIMER_PERIODIC, &olsr_ondatasvc_gen, NULL, 0);
2602 ++
2603 ++ return 1;
2604 ++}
2605 ++
2606 ++
2611 ++void
2612 ++ondata_destructor(void)
2613 ++{
2614 ++ olsr_stop_timer(msg_gen_timer);
2615 ++}
2616 ++
2617 ++
2620 ++void
2621 ++olsr_ondatasvc_gen(void *foo __attribute__ ((unused)))
2622 ++{
2623 ++ /* send buffer: huge */
2624 ++ char buffer[10240];
2625 ++ union olsr_message *message = (union olsr_message *)buffer;
2626 ++ struct interface *ifn;
2627 ++ int ondatasize;
2628 ++
2629 ++ /* fill message */
2630 ++ if (olsr_cnf->ip_version == AF_INET) {
2631 ++ /* IPv4 */
2632 ++ message->v4.olsr_msgtype = MESSAGE_TYPE;
2633 ++ message->v4.olsr_vtime = reltime_to_me((double)my_vtime * MSEC_PER_SEC);
2634 ++ memcpy(&message->v4.originator, &olsr_cnf->main_addr, olsr_cnf->ipsize);
2635 ++ message->v4.ttl = MAX_TTL;
2636 ++ message->v4.hopcnt = 0;
2637 ++ message->v4.seqno = htons(get_msg_seqno());
2638 ++
2639 ++ ondatasize = encap_ondatamsg((struct ondatamsg *)ARM_NOWARN_ALIGN(&message->v4.message));
2640 ++ if (!ondatasize) return;
2641 ++ ondatasize = ondatasize + sizeof(struct olsrmsg);
2642 ++ message->v4.olsr_msgsize = htons(ondatasize);
2643 ++ } else {
2644 ++ /* IPv6 */
2645 ++ message->v6.olsr_msgtype = MESSAGE_TYPE;
2646 ++ message->v6.olsr_vtime = reltime_to_me((double)my_vtime * MSEC_PER_SEC);
2647 ++ memcpy(&message->v6.originator, &olsr_cnf->main_addr, olsr_cnf->ipsize);
2648 ++ message->v6.ttl = MAX_TTL;
2649 ++ message->v6.hopcnt = 0;
2650 ++ message->v6.seqno = htons(get_msg_seqno());
2651 ++
2652 ++ ondatasize = encap_ondatamsg((struct ondatamsg *)ARM_NOWARN_ALIGN(&message->v6.message));
2653 ++ if (!ondatasize) return;
2654 ++ ondatasize = ondatasize + sizeof(struct olsrmsg6);
2655 ++
2656 ++ message->v6.olsr_msgsize = htons(ondatasize);
2657 ++ }
2658 ++
2659 ++ /* looping trough interfaces */
2660 ++ for (ifn = ifnet; ifn; ifn = ifn->int_next) {
2661 ++ OLSR_PRINTF(3, "ONDATA PLUGIN: Generating packet - [%s]\n", ifn->int_name);
2662 ++
2663 ++ if (net_outbuffer_push(ifn, message, ondatasize) != ondatasize) {
2664 ++ /* send data and try again */
2665 ++ net_output(ifn);
2666 ++ if (net_outbuffer_push(ifn, message, ondatasize) != ondatasize) {
2667 ++ OLSR_PRINTF(1, "ONDATA PLUGIN: could not send on interface: %s\n", ifn->int_name);
2668 ++ }
2669 ++ }
2670 ++ }
2671 ++}
2672 ++
2673 ++// Database Variables / should be kept over different calls, therefore global
2674 ++FILE *fp = NULL;
2675 ++
2676 ++
2683 ++int
2684 ++encap_ondatamsg(struct ondatamsg *msg)
2685 ++{
2686 ++ struct ipaddr_str main_addr;
2687 ++ char *pos;
2688 ++ int iCol;
2689 ++ uint16_t checksum;
2690 ++ uint16_t messageLength = 0;
2691 ++ cJSON *json = NULL, *elem;
2692 ++ char line [ 3000 ]; /* or other suitable maximum line size */
2693 ++
2694 ++ // open Database if this not a 'continued Transmission - and Database is already open'
2695 ++ if (fp == NULL) {
2696 ++ OLSR_PRINTF(0, "ONDATA PLUGIN: opening json file\n");
2697 ++ json = NULL;
2698 ++ fp=fopen(my_database, "r");
2699 ++
2700 ++ if(fp == NULL) {
2701 ++ fprintf(stderr, "Can't open json file %s\n", my_database);
2702 ++ return 0;
2703 ++ }
2704 ++ }
2705 ++
2706 ++ // search next Table with Data
2707 ++ if (fp != NULL) {
2708 ++ if ( fgets ( line, sizeof line, fp ) != NULL ) {
2709 ++ json=cJSON_Parse(line);
2710 ++ }
2711 ++ }
2712 ++
2713 ++ // if no further Table give up
2714 ++ if (!json) {
2715 ++ OLSR_PRINTF(0, "ONDATA PLUGIN: no further table found\n");
2716 ++ olsr_change_timer(msg_gen_timer, my_interval * MSEC_PER_SEC, EMISSION_JITTER, OLSR_TIMER_PERIODIC);
2717 ++ fclose (fp);
2718 ++ fp = NULL;
2719 ++ return 0;
2720 ++ }
2721 ++
2722 ++ OLSR_PRINTF(0, "ONDATA PLUGIN: using next table %s\n", json->child->string);
2723 ++
2724 ++ // add all datasets
2725 ++ OLSR_PRINTF(0, "ONDATA PLUGIN: adding all datasets\n");
2726 ++ // add all the entries after the ondatamsg header (and keep space for it)
2727 ++ pos = (char *)msg + sizeof(struct ondatamsg);
2728 ++
2729 ++ // always add the Table-Name as first field
2730 ++ pos = create_packet((struct ondata *)ARM_NOWARN_ALIGN(pos), json->child->string);
2731 ++
2732 ++ // never transmit originator (col=0), this will be detected at the other end_pos
2733 ++ elem = json->child->child->next;
2734 ++ // skip last column, it will set at destination to the receiving-time
2735 ++ iCol = 1;
2736 ++ do {
2737 ++ pos = create_packet((struct ondata *)ARM_NOWARN_ALIGN(pos), elem->valuestring);
2738 ++ iCol++;
2739 ++ elem = elem->next;
2740 ++ } while(elem->next);
2741 ++ cJSON_Delete(json);
2742 ++
2743 ++ // write the ondatamsg header with the number of announced entries and the protocol version
2744 ++ msg->nr_datasets = htons(--iCol); // it won't count the table-name as dataset (and neither mainip-Col)
2745 ++ msg->version = htons(ONDATA_PROTOCOL_VERSION);
2746 ++ messageLength = pos - (char *)msg;
2747 ++ msg->length = htons(messageLength);
2748 ++ checksum = crcCalculate((char *)msg + sizeof(uint16_t), messageLength - sizeof(uint16_t));
2749 ++ msg->checksum = htons(checksum);
2750 ++
2751 ++ OLSR_PRINTF(0, "ONDATA PLUGIN: ##### finished creating packet, length=%d, crc16=0x%x\n", messageLength, checksum);
2752 ++
2753 ++ // increase Transmission-Time as long as there is data
2754 ++ olsr_change_timer(msg_gen_timer, 1 * MSEC_PER_SEC, EMISSION_JITTER, OLSR_TIMER_PERIODIC);
2755 ++ return messageLength; //length
2756 ++}
2757 ++
2758 ++
2764 ++char *
2765 ++create_packet(struct ondata *to, const char *value )
2766 ++{
2767 ++ char *pos = (char *)to; int valuelen = strlen((const char*)value);
2768 ++ int k;
2769 ++ to->valuelen = htons(valuelen);
2770 ++ OLSR_PRINTF(5, "ONDATA PLUGIN: Announcing value %s %d\n", value, valuelen);
2771 ++ pos += sizeof(struct ondata);
2772 ++ memcpy(pos, value, valuelen);
2773 ++ pos += valuelen;
2774 ++ // do 4-byte padding
2775 ++ for (k = sizeof(struct ondata) + valuelen; (k & 3) != 0; k++)
2776 ++ *pos++ = '\0';
2777 ++
2778 ++ return pos;
2779 ++}
2780 ++
2781 ++/*
2782 ++ * Local Variables:
2783 ++ * mode: c
2784 ++ * c-indent-tabs-mode: t
2785 ++ * indent-tabs-mode: t
2786 ++ * c-basic-offset: 4
2787 ++ * tab-width: 4
2788 ++ * End:
2789 ++ */
2790 ++
2791 +diff --git a/lib/ondataservice_light/src/ondataservice.h b/lib/ondataservice_light/src/ondataservice.h
2792 +new file mode 100644
2793 +index 0000000..aea2f4c
2794 +--- /dev/null
2795 ++++ b/lib/ondataservice_light/src/ondataservice.h
2796 +@@ -0,0 +1,101 @@
2797 ++
2798 ++/*
2799 ++ * Copyright (c) 2011, Rene Ejury <opennet@absorb.it>
2800 ++ * All rights reserved.
2801 ++ *
2802 ++ * Redistribution and use in source and binary forms, with or without
2803 ++ * modification, are permitted provided that the following conditions
2804 ++ * are met:
2805 ++ *
2806 ++ * * Redistributions of source code must retain the above copyright notice,
2807 ++ * this list of conditions and the following disclaimer.
2808 ++ * * Redistributions in binary form must reproduce the above copyright notice,
2809 ++ * this list of conditions and the following disclaimer in the documentation
2810 ++ * and/or other materials provided with the distribution.
2811 ++ * * Neither the name of the UniK olsr daemon nor the names of its contributors
2812 ++ * may be used to endorse or promote products derived from this software
2813 ++ * without specific prior written permission.
2814 ++ *
2815 ++ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
2816 ++ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
2817 ++ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2818 ++ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
2819 ++ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
2820 ++ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2821 ++ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
2822 ++ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
2823 ++ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
2824 ++ * OF THE POSSIBILITY OF SUCH DAMAGE.
2825 ++ *
2826 ++ */
2827 ++
2828 ++/*
2829 ++ * Dynamic linked library for UniK OLSRd
2830 ++ */
2831 ++
2832 ++#ifndef _ONDATASERVICE_PLUGIN
2833 ++#define _ONDATASERVICE_PLUGIN
2834 ++
2835 ++#include <sys/time.h>
2836 ++// #include <regex.h>
2837 ++
2838 ++#include "olsr_types.h"
2839 ++#include "interfaces.h"
2840 ++#include "olsr_protocol.h"
2841 ++#include "common/list.h"
2842 ++
2843 ++#include "olsrd_plugin.h"
2844 ++#include "ondataservice_msg.h"
2845 ++#include "hashing.h"
2846 ++// #include "mapwrite.h"
2847 ++// #include "mantissa.h"
2848 ++
2849 ++#define PLUGIN_NAME "OLSRD ondataservice plugin"
2850 ++#define PLUGIN_VERSION "0.3"
2851 ++#define PLUGIN_AUTHOR "Rene Ejury, Bruno Randolf, Jens Nachtigall, Sven-Ola Tuecke"
2852 ++#define DATABASE_FILE "/tmp/database.json"
2853 ++
2854 ++#define MESSAGE_TYPE 222 /* hope this is a good choice */
2855 ++#define PARSER_TYPE MESSAGE_TYPE
2856 ++#define EMISSION_INTERVAL 10800 /* seconds - 10800 = 3hours */
2857 ++#define EMISSION_INC_INTERVAL 5 /* seconds between transmission of rows from one dataset */
2858 ++#define EMISSION_JITTER 25 /* percent */
2859 ++#define ONDATA_VALID_TIME 300 /* seconds, how long a package should maximally be spreaded through the net - 300 - 5mins*/
2860 ++
2861 ++#define ONDATA_PROTOCOL_VERSION 1
2862 ++
2863 ++#define MAX_FILE 255
2864 ++
2865 ++/* Parser function to register with the scheduler */
2866 ++bool olsr_parser(union olsr_message *, struct interface *, union olsr_ip_addr *);
2867 ++
2868 ++/* callback for periodic timer */
2869 ++void olsr_ondatasvc_gen(void *);
2870 ++
2871 ++/* callback for database cleanup */
2872 ++void olsr_ondataservice_expire_db_timer(void *);
2873 ++
2874 ++int encap_ondatamsg(struct ondatamsg *);
2875 ++
2876 ++void update_ondata_entry(union olsr_ip_addr *, struct ondatamsg *, int);
2877 ++
2878 ++int register_olsr_param(char *key, char *value);
2879 ++
2880 ++
2881 ++char *create_packet(struct ondata *to, const char *value);
2882 ++
2883 ++void ondata_constructor(void);
2884 ++
2885 ++void ondata_destructor(void);
2886 ++
2887 ++int ondata_init(void);
2888 ++
2889 ++#endif
2890 ++
2891 ++/*
2892 ++ * Local Variables:
2893 ++ * c-basic-offset: 2
2894 ++ * indent-tabs-mode: nil
2895 ++ * End:
2896 ++ */
2897 ++
2898 +diff --git a/lib/ondataservice_light/src/ondataservice_msg.h b/lib/ondataservice_light/src/ondataservice_msg.h
2899 +new file mode 100644
2900 +index 0000000..b22fbee
2901 +--- /dev/null
2902 ++++ b/lib/ondataservice_light/src/ondataservice_msg.h
2903 +@@ -0,0 +1,68 @@
2904 ++
2905 ++/*
2906 ++ * Copyright (c) 2005, Bruno Randolf <bruno.randolf@4g-systems.biz>
2907 ++ * Copyright (c) 2004, Andreas Tonnesen(andreto-at-olsr.org)
2908 ++ * All rights reserved.
2909 ++ *
2910 ++ * Redistribution and use in source and binary forms, with or without
2911 ++ * modification, are permitted provided that the following conditions
2912 ++ * are met:
2913 ++ *
2914 ++ * * Redistributions of source code must retain the above copyright notice,
2915 ++ * this list of conditions and the following disclaimer.
2916 ++ * * Redistributions in binary form must reproduce the above copyright notice,
2917 ++ * this list of conditions and the following disclaimer in the documentation
2918 ++ * and/or other materials provided with the distribution.
2919 ++ * * Neither the name of the UniK olsr daemon nor the names of its contributors
2920 ++ * may be used to endorse or promote products derived from this software
2921 ++ * without specific prior written permission.
2922 ++ *
2923 ++ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
2924 ++ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
2925 ++ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2926 ++ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
2927 ++ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
2928 ++ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2929 ++ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
2930 ++ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
2931 ++ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
2932 ++ * OF THE POSSIBILITY OF SUCH DAMAGE.
2933 ++ *
2934 ++ */
2935 ++
2936 ++/*
2937 ++ * Dynamic linked library for UniK OLSRd
2938 ++ */
2939 ++
2940 ++#ifndef _ONDATASERVICE_MSG
2941 ++#define _ONDATASERVICE_MSG
2942 ++
2943 ++
2947 ++struct ondata {
2948 ++ uint16_t valuelen; // length of the value
2949 ++ /*
2950 ++ * value is written separatedly in plain text after this struct and padded to 4 byte
2951 ++ */
2952 ++};
2953 ++
2954 ++struct ondatamsg {
2955 ++ uint16_t checksum;
2956 ++ uint16_t version; // version number of the ondataservice plugin
2957 ++ uint16_t nr_datasets; // number of following packets including all the data
2958 ++ uint16_t length; // length in bytes / required to calculate checksum on receive
2959 ++ /*
2960 ++ * at least one struct name following
2961 ++ */
2962 ++};
2963 ++
2964 ++#endif
2965 ++
2966 ++/*
2967 ++ * Local Variables:
2968 ++ * c-basic-offset: 2
2969 ++ * indent-tabs-mode: nil
2970 ++ * End:
2971 ++ */
2972 +diff --git a/lib/ondataservice_light/version-script.txt b/lib/ondataservice_light/version-script.txt
2973 +new file mode 100644
2974 +index 0000000..a145659
2975 +--- /dev/null
2976 ++++ b/lib/ondataservice_light/version-script.txt
2977 +@@ -0,0 +1,10 @@
2978 ++VERS_1.0
2979 ++{
2980 ++ global:
2981 ++ olsrd_plugin_interface_version;
2982 ++ olsrd_plugin_init;
2983 ++ olsrd_get_plugin_parameters;
2984 ++
2985 ++ local:
2986 ++ *;
2987 ++};