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