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