# src/image.c src/image.h \
# src/dbsql.c src/dbsql.h \
# src/dbaccess.c src/dbaccess.h \
-# src/dbmerge.c src/dbmerge.h \
# src/common.c src/common.h \
# src/misc.c src/misc.h \
# src/fs.c src/fs.h \
src/dbsql.c src/dbsql.h \
src/dbaccess.c src/dbaccess.h \
src/datacache.c src/datacache.h \
+ src/dbshow.c src/dbshow.h \
+ src/dbjson.c src/dbjson.h \
+ src/dbxml.c src/dbxml.h \
src/ibw.c src/ibw.h \
src/ifinfo.c src/ifinfo.h \
src/misc.c src/misc.h \
src/id.c src/id.h
endif
-#check_vnstat_SOURCES += src/cfg.c src/cfg.h \
-# src/common.c src/common.h \
-# src/daemon.c src/daemon.h \
-# src/dbsql.c src/dbsql.h \
-# src/dbaccess.c src/dbaccess.h \
-# src/datacache.c src/datacache.h \
-# src/dbjson.c src/dbjson.h \
-# src/dbmerge.c src/dbmerge.h \
-# src/dbshow.c src/dbshow.h \
-# src/dbxml.c src/dbxml.h \
-# src/ibw.c src/ibw.h \
-# src/ifinfo.c src/ifinfo.h \
-# src/misc.c src/misc.h \
-# src/fs.c src/fs.h \
-# src/id.c src/id.h \
-# src/traffic.c src/traffic.h
-#endif
-
setdebug:
CFLAGS='-Wall -Wextra -g' ./configure
tests/id_tests.h tests/daemon_tests.c tests/daemon_tests.h \
src/cfg.c src/cfg.h src/common.c src/common.h src/daemon.c \
src/daemon.h src/dbsql.c src/dbsql.h src/dbaccess.c \
- src/dbaccess.h src/datacache.c src/datacache.h src/ibw.c \
- src/ibw.h src/ifinfo.c src/ifinfo.h src/misc.c src/misc.h \
- src/fs.c src/fs.h src/id.c src/id.h
+ src/dbaccess.h src/datacache.c src/datacache.h src/dbshow.c \
+ src/dbshow.h src/dbjson.c src/dbjson.h src/dbxml.c src/dbxml.h \
+ src/ibw.c src/ibw.h src/ifinfo.c src/ifinfo.h src/misc.c \
+ src/misc.h src/fs.c src/fs.h src/id.c src/id.h
am__dirstamp = $(am__leading_dot)dirstamp
@HAVE_CHECK_TRUE@am_check_vnstat_OBJECTS = \
@HAVE_CHECK_TRUE@ tests/check_vnstat-vnstat_tests.$(OBJEXT) \
@HAVE_CHECK_TRUE@ src/check_vnstat-dbsql.$(OBJEXT) \
@HAVE_CHECK_TRUE@ src/check_vnstat-dbaccess.$(OBJEXT) \
@HAVE_CHECK_TRUE@ src/check_vnstat-datacache.$(OBJEXT) \
+@HAVE_CHECK_TRUE@ src/check_vnstat-dbshow.$(OBJEXT) \
+@HAVE_CHECK_TRUE@ src/check_vnstat-dbjson.$(OBJEXT) \
+@HAVE_CHECK_TRUE@ src/check_vnstat-dbxml.$(OBJEXT) \
@HAVE_CHECK_TRUE@ src/check_vnstat-ibw.$(OBJEXT) \
@HAVE_CHECK_TRUE@ src/check_vnstat-ifinfo.$(OBJEXT) \
@HAVE_CHECK_TRUE@ src/check_vnstat-misc.$(OBJEXT) \
@HAVE_CHECK_TRUE@ src/common.c src/common.h src/daemon.c \
@HAVE_CHECK_TRUE@ src/daemon.h src/dbsql.c src/dbsql.h \
@HAVE_CHECK_TRUE@ src/dbaccess.c src/dbaccess.h src/datacache.c \
-@HAVE_CHECK_TRUE@ src/datacache.h src/ibw.c src/ibw.h \
-@HAVE_CHECK_TRUE@ src/ifinfo.c src/ifinfo.h src/misc.c \
-@HAVE_CHECK_TRUE@ src/misc.h src/fs.c src/fs.h src/id.c \
-@HAVE_CHECK_TRUE@ src/id.h
+@HAVE_CHECK_TRUE@ src/datacache.h src/dbshow.c src/dbshow.h \
+@HAVE_CHECK_TRUE@ src/dbjson.c src/dbjson.h src/dbxml.c \
+@HAVE_CHECK_TRUE@ src/dbxml.h src/ibw.c src/ibw.h src/ifinfo.c \
+@HAVE_CHECK_TRUE@ src/ifinfo.h src/misc.c src/misc.h src/fs.c \
+@HAVE_CHECK_TRUE@ src/fs.h src/id.c src/id.h
all: all-recursive
.SUFFIXES:
src/$(DEPDIR)/$(am__dirstamp)
src/check_vnstat-datacache.$(OBJEXT): src/$(am__dirstamp) \
src/$(DEPDIR)/$(am__dirstamp)
+src/check_vnstat-dbshow.$(OBJEXT): src/$(am__dirstamp) \
+ src/$(DEPDIR)/$(am__dirstamp)
+src/check_vnstat-dbjson.$(OBJEXT): src/$(am__dirstamp) \
+ src/$(DEPDIR)/$(am__dirstamp)
+src/check_vnstat-dbxml.$(OBJEXT): src/$(am__dirstamp) \
+ src/$(DEPDIR)/$(am__dirstamp)
src/check_vnstat-ibw.$(OBJEXT): src/$(am__dirstamp) \
src/$(DEPDIR)/$(am__dirstamp)
src/check_vnstat-ifinfo.$(OBJEXT): src/$(am__dirstamp) \
@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/check_vnstat-daemon.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/check_vnstat-datacache.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/check_vnstat-dbaccess.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/check_vnstat-dbjson.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/check_vnstat-dbshow.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/check_vnstat-dbsql.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/check_vnstat-dbxml.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/check_vnstat-fs.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/check_vnstat-ibw.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/check_vnstat-id.Po@am__quote@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o src/check_vnstat-datacache.obj `if test -f 'src/datacache.c'; then $(CYGPATH_W) 'src/datacache.c'; else $(CYGPATH_W) '$(srcdir)/src/datacache.c'; fi`
+src/check_vnstat-dbshow.o: src/dbshow.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT src/check_vnstat-dbshow.o -MD -MP -MF src/$(DEPDIR)/check_vnstat-dbshow.Tpo -c -o src/check_vnstat-dbshow.o `test -f 'src/dbshow.c' || echo '$(srcdir)/'`src/dbshow.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/check_vnstat-dbshow.Tpo src/$(DEPDIR)/check_vnstat-dbshow.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='src/dbshow.c' object='src/check_vnstat-dbshow.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o src/check_vnstat-dbshow.o `test -f 'src/dbshow.c' || echo '$(srcdir)/'`src/dbshow.c
+
+src/check_vnstat-dbshow.obj: src/dbshow.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT src/check_vnstat-dbshow.obj -MD -MP -MF src/$(DEPDIR)/check_vnstat-dbshow.Tpo -c -o src/check_vnstat-dbshow.obj `if test -f 'src/dbshow.c'; then $(CYGPATH_W) 'src/dbshow.c'; else $(CYGPATH_W) '$(srcdir)/src/dbshow.c'; fi`
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/check_vnstat-dbshow.Tpo src/$(DEPDIR)/check_vnstat-dbshow.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='src/dbshow.c' object='src/check_vnstat-dbshow.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o src/check_vnstat-dbshow.obj `if test -f 'src/dbshow.c'; then $(CYGPATH_W) 'src/dbshow.c'; else $(CYGPATH_W) '$(srcdir)/src/dbshow.c'; fi`
+
+src/check_vnstat-dbjson.o: src/dbjson.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT src/check_vnstat-dbjson.o -MD -MP -MF src/$(DEPDIR)/check_vnstat-dbjson.Tpo -c -o src/check_vnstat-dbjson.o `test -f 'src/dbjson.c' || echo '$(srcdir)/'`src/dbjson.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/check_vnstat-dbjson.Tpo src/$(DEPDIR)/check_vnstat-dbjson.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='src/dbjson.c' object='src/check_vnstat-dbjson.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o src/check_vnstat-dbjson.o `test -f 'src/dbjson.c' || echo '$(srcdir)/'`src/dbjson.c
+
+src/check_vnstat-dbjson.obj: src/dbjson.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT src/check_vnstat-dbjson.obj -MD -MP -MF src/$(DEPDIR)/check_vnstat-dbjson.Tpo -c -o src/check_vnstat-dbjson.obj `if test -f 'src/dbjson.c'; then $(CYGPATH_W) 'src/dbjson.c'; else $(CYGPATH_W) '$(srcdir)/src/dbjson.c'; fi`
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/check_vnstat-dbjson.Tpo src/$(DEPDIR)/check_vnstat-dbjson.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='src/dbjson.c' object='src/check_vnstat-dbjson.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o src/check_vnstat-dbjson.obj `if test -f 'src/dbjson.c'; then $(CYGPATH_W) 'src/dbjson.c'; else $(CYGPATH_W) '$(srcdir)/src/dbjson.c'; fi`
+
+src/check_vnstat-dbxml.o: src/dbxml.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT src/check_vnstat-dbxml.o -MD -MP -MF src/$(DEPDIR)/check_vnstat-dbxml.Tpo -c -o src/check_vnstat-dbxml.o `test -f 'src/dbxml.c' || echo '$(srcdir)/'`src/dbxml.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/check_vnstat-dbxml.Tpo src/$(DEPDIR)/check_vnstat-dbxml.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='src/dbxml.c' object='src/check_vnstat-dbxml.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o src/check_vnstat-dbxml.o `test -f 'src/dbxml.c' || echo '$(srcdir)/'`src/dbxml.c
+
+src/check_vnstat-dbxml.obj: src/dbxml.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT src/check_vnstat-dbxml.obj -MD -MP -MF src/$(DEPDIR)/check_vnstat-dbxml.Tpo -c -o src/check_vnstat-dbxml.obj `if test -f 'src/dbxml.c'; then $(CYGPATH_W) 'src/dbxml.c'; else $(CYGPATH_W) '$(srcdir)/src/dbxml.c'; fi`
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/check_vnstat-dbxml.Tpo src/$(DEPDIR)/check_vnstat-dbxml.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='src/dbxml.c' object='src/check_vnstat-dbxml.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o src/check_vnstat-dbxml.obj `if test -f 'src/dbxml.c'; then $(CYGPATH_W) 'src/dbxml.c'; else $(CYGPATH_W) '$(srcdir)/src/dbxml.c'; fi`
+
src/check_vnstat-ibw.o: src/ibw.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT src/check_vnstat-ibw.o -MD -MP -MF src/$(DEPDIR)/check_vnstat-ibw.Tpo -c -o src/check_vnstat-ibw.o `test -f 'src/ibw.c' || echo '$(srcdir)/'`src/ibw.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/check_vnstat-ibw.Tpo src/$(DEPDIR)/check_vnstat-ibw.Po
uninstall-man1 uninstall-man5 uninstall-sbinPROGRAMS
-#check_vnstat_SOURCES += src/cfg.c src/cfg.h \
-# src/common.c src/common.h \
-# src/daemon.c src/daemon.h \
-# src/dbsql.c src/dbsql.h \
-# src/dbaccess.c src/dbaccess.h \
-# src/datacache.c src/datacache.h \
-# src/dbjson.c src/dbjson.h \
-# src/dbmerge.c src/dbmerge.h \
-# src/dbshow.c src/dbshow.h \
-# src/dbxml.c src/dbxml.h \
-# src/ibw.c src/ibw.h \
-# src/ifinfo.c src/ifinfo.h \
-# src/misc.c src/misc.h \
-# src/fs.c src/fs.h \
-# src/id.c src/id.h \
-# src/traffic.c src/traffic.h
-#endif
-
setdebug:
CFLAGS='-Wall -Wextra -g' ./configure
* `grep TODO src/* tests/*`
* continue daemon refactoring
* add missing sanity checks to daemon
- * console outputs
- * export?
* image outputs
* all
* use of 5 minute resolution statistics
dbdatalist *datalist = NULL, *datalist_i = NULL;
dbdatalistinfo datainfo;
- /* TODO: add table check */
-
if (!db_getdata(&datalist, &datainfo, interface->name, tablename, -1)) {
/* TODO: match with other output style */
- printf("Error: failed to fetch monthly data\n");
+ printf("Error: failed to fetch %s data\n", tablename);
return;
}
+++ /dev/null
-#include "common.h"
-#include "dbaccess.h"
-#include "dbmerge.h"
-
-int mergedb(char iface[], char dirname[])
-{
- DATA mergedata;
- char *ifaceptr;
-
- if (!strstr(iface, "+")) {
- return 0;
- }
-
- /* create empty database */
- emptydb(&mergedata);
- strncpy_nt(mergedata.interface, iface, 32);
- strncpy_nt(mergedata.nick, mergedata.interface, 32);
-
- if (debug)
- printf("iface merge: %s\n", iface);
-
- ifaceptr = strtok(iface, "+");
-
- /* merge all databases in given string */
- while (ifaceptr != NULL) {
- if (debug)
- printf("merging %s:\n", ifaceptr);
-
- if (readdb(ifaceptr, dirname, 0)!=0) {
- printf("Merge \"%s\" failed.\n", mergedata.interface);
- return 0;
- }
-
- if (!mergewith(&mergedata)) {
- printf("Merge \"%s\" failed for interface \"%s\".\n", mergedata.interface, ifaceptr);
- return 0;
- }
-
- ifaceptr = strtok(NULL, "+");
- }
-
- /* clean possible glitches */
- cleanmerged(&mergedata);
-
- /* replace active data with merged */
- if (memcpy(&data, &mergedata, sizeof(data)) != NULL) {
- return 1;
- } else {
- return 0;
- }
-}
-
-void emptydb(DATA *dat)
-{
- int i;
- struct tm *d;
- time_t current;
-
- current = time(NULL);
-
- dat->version = DBVERSION;
- dat->active = 1;
- dat->totalrx = 0;
- dat->totaltx = 0;
- dat->currx = 0;
- dat->curtx = 0;
- dat->totalrxk = 0;
- dat->totaltxk = 0;
- dat->lastupdated = 0;
- dat->created = current;
-
- /* days */
- d = localtime(¤t);
- for (i=0;i<=29;i++) {
- dat->day[i].rx = 0;
- dat->day[i].tx = 0;
- dat->day[i].rxk = 0;
- dat->day[i].txk = 0;
- dat->day[i].date = mktime(d);
- dat->day[i].used = 1;
- d->tm_mday--;
- }
-
- /* months */
- d = localtime(¤t);
- for (i=0;i<=11;i++) {
- dat->month[i].rx = 0;
- dat->month[i].tx = 0;
- dat->month[i].rxk = 0;
- dat->month[i].txk = 0;
- dat->month[i].month = mktime(d);
- dat->month[i].used = 1;
- d->tm_mon--;
- }
-
- /* top10 */
- for (i=0;i<=9;i++) {
- dat->top10[i].rx = 0;
- dat->top10[i].tx = 0;
- dat->top10[i].rxk = 0;
- dat->top10[i].txk = 0;
- dat->top10[i].date = 0;
- dat->top10[i].used = 0;
- }
-
- /* hours */
- for (i=0;i<=23;i++) {
- dat->hour[i].rx = 0;
- dat->hour[i].tx = 0;
- dat->hour[i].date = 0;
- }
-
- dat->btime = 0;
-}
-
-int mergewith(DATA *dat)
-{
- int i, j, orig, merged;
- struct tm *d;
-
- /* merge totals */
- dat->totalrx += data.totalrx;
- dat->totaltx += data.totaltx;
- dat->totalrxk += data.totalrxk;
- dat->totaltxk += data.totaltxk;
-
- if (data.created < dat->created) {
- dat->created = data.created;
- }
-
- if (data.lastupdated > dat->lastupdated) {
- dat->lastupdated = data.lastupdated;
- }
-
- /* clean hours from loaded db */
- cleanhours();
-
- /* merge hours */
- for (i=0;i<=23;i++) {
- if (data.hour[i].date!=0) {
- dat->hour[i].rx += data.hour[i].rx;
- dat->hour[i].tx += data.hour[i].tx;
- dat->hour[i].date = data.hour[i].date;
- }
- }
-
- /* merge days */
- for (i=0;i<=29;i++) {
- if (data.day[i].used) {
- d = localtime(&data.day[i].date);
- orig = d->tm_year * 1000 + d->tm_yday;
-
- for (j=0;j<=29;j++) {
- d = localtime(&dat->day[j].date);
- merged = d->tm_year * 1000 + d->tm_yday;
-
- if (orig == merged) {
- dat->day[j].rx += data.day[i].rx;
- dat->day[j].tx += data.day[i].tx;
- dat->day[j].rxk += data.day[i].rxk;
- dat->day[j].txk += data.day[i].txk;
- if (dat->day[j].date > data.day[i].date) {
- dat->day[j].date = data.day[i].date;
- }
- } else if (merged < orig) {
- break;
- }
- }
-
- }
- }
-
- /* merge months */
- for (i=0;i<=11;i++) {
- if (data.month[i].used) {
- d = localtime(&data.month[i].month);
- orig = d->tm_year * 100 + d->tm_mon;
-
- for (j=0;j<=11;j++) {
- d = localtime(&dat->month[j].month);
- merged = d->tm_year * 100 + d->tm_mon;
-
- if (orig == merged) {
- dat->month[j].rx += data.month[i].rx;
- dat->month[j].tx += data.month[i].tx;
- dat->month[j].rxk += data.month[i].rxk;
- dat->month[j].txk += data.month[i].txk;
- if (dat->month[j].month > data.month[i].month) {
- dat->month[j].month = data.month[i].month;
- }
- } else if (merged < orig) {
- break;
- }
- }
-
- }
- }
-
- return 1;
-}
-
-void cleanmerged(DATA *dat)
-{
- int i;
-
- /* clean days */
- for (i=29;i>=0;i--) {
- if ((dat->day[i].rx == 0) && (dat->day[i].tx == 0) && (dat->day[i].rxk == 0) && (dat->day[i].txk == 0)) {
- dat->day[i].used = 0;
- } else {
- break;
- }
- }
-
- /* clean days */
- for (i=11;i>=0;i--) {
- if ((dat->month[i].rx == 0) && (dat->month[i].tx == 0) && (dat->month[i].rxk == 0) && (dat->month[i].txk == 0)) {
- dat->month[i].used = 0;
- } else {
- break;
- }
- }
-}
+++ /dev/null
-#ifndef DBMERGE_H
-#define DBMERGE_H
-
-int mergedb(char iface[], char dirname[]);
-void emptydb(DATA *dat);
-int mergewith(DATA *dat);
-void cleanmerged(DATA *dat);
-
-#endif
case 3:
showlist(&info, "top");
break;
-/* case 4:
- exportdb();
- break; */
+ case 4:
+ exportdb(&info);
+ break;
case 5:
showsummary(&info, 1);
break;
char matrix[24][81]; /* width is one over 80 so that snprintf can write the end char */
char unit[4];
struct tm *d;
- dbdatalist *datalist = NULL, *datalist_i = NULL;
- dbdatalistinfo datainfo;
+ dbdatalist *datalist = NULL, *datalist_i = NULL;
+ dbdatalistinfo datainfo;
HOURDATA hourdata[24];
for (i=0; i<24; i++) {
if (!db_getdata(&datalist, &datainfo, interface->name, "hour", 24)) {
/* TODO: match with other output style */
- printf("\nError: failed to fetch monthly data\n");
+ printf("\nError: failed to fetch hourly data\n");
return;
}
}
}
+void exportdb(const interfaceinfo *interface)
+{
+ int i;
+ dbdatalist *datalist = NULL, *datalist_i = NULL;
+ dbdatalistinfo datainfo;
+ char *datatables[] = {"hour", "day", "month", "year", "top"};
+
+ printf("version;%s\n", db_getinfo("dbversion"));
+ printf("vnstat;%s\n", db_getinfo("vnstatversion"));
+ printf("active;%d\n", interface->active);
+ printf("interface;%s\n", interface->name);
+ printf("alias;%s\n", interface->alias);
+ printf("created;%"PRIu64"\n", (uint64_t)interface->created);
+ printf("updated;%"PRIu64"\n", (uint64_t)interface->updated);
+
+ printf("totalrx;%"PRIu64"\n", interface->rxtotal);
+ printf("totaltx;%"PRIu64"\n", interface->rxtotal);
+ printf("currx;%"PRIu64"\n", interface->rxcounter);
+ printf("curtx;%"PRIu64"\n", interface->txcounter);
+ printf("btime;%s\n", db_getinfo("btime"));
+
+ for (i=0; i<5; i++) {
+
+ if (!db_getdata(&datalist, &datainfo, interface->name, datatables[i], -1)) {
+ printf("\nError: failed to fetch %s data\n", datatables[i]);
+ return;
+ }
+ datalist_i = datalist;
+ while (datalist_i != NULL) {
+ printf("%c;%"PRId64";%"PRIu64";%"PRIu64";%"PRIu64"\n", datatables[i][0], datalist_i->rowid, (uint64_t)datalist_i->timestamp, datalist_i->rx, datalist_i->tx);
+ datalist_i = datalist_i->next;
+ }
+ dbdatalistfree(&datalist);
+ }
+}
+
int showbar(const uint64_t rx, const uint64_t tx, const uint64_t max, const int len)
{
int i, l, width = len;
void showlist(const interfaceinfo *interface, const char *listname);
void showoneline(const interfaceinfo *interface);
void showhours(const interfaceinfo *interface);
+void exportdb(const interfaceinfo *interface);
int showbar(uint64_t rx, uint64_t tx, uint64_t max, const int len);
void indent(int i);
dbdatalist *datalist = NULL, *datalist_i = NULL;
dbdatalistinfo datainfo;
- /* TODO: add table check */
-
if (!db_getdata(&datalist, &datainfo, interface->name, tablename, -1)) {
/* TODO: match with other output style */
- printf("Error: failed to fetch monthly data\n");
+ printf("Error: failed to fetch %s data\n", tablename);
return;
}
cfg.qmode=6;
} else if ((strcmp(argv[currentarg],"-h")==0) || (strcmp(argv[currentarg],"--hours")==0)) {
cfg.qmode=7;
-/* } else if ((strcmp(argv[currentarg],"--exportdb")==0) || (strcmp(argv[currentarg],"--dumpdb")==0)) {
- cfg.qmode=4; */
+ } else if ((strcmp(argv[currentarg],"--exportdb")==0) || (strcmp(argv[currentarg],"--dumpdb")==0)) {
+ cfg.qmode=4;
} else if (strcmp(argv[currentarg],"--oneline")==0) {
cfg.qmode=9;
if (currentarg+1<argc && argv[currentarg+1][0]!='-') {
printf(" -s, --short use short output\n");
printf(" -ru, --rateunit swap configured rate unit\n");
printf(" --oneline show simple parseable format\n");
- //printf(" --exportdb dump database in text format\n");
+ printf(" --exportdb dump database in text format\n");
printf(" --json show database in json format\n");
printf(" --xml show database in xml format\n");
/*
-vnStat daemon - Copyright (c) 2008-2016 Teemu Toivola <tst@iki.fi>
+vnStat daemon - Copyright (c) 2008-2017 Teemu Toivola <tst@iki.fi>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
/*
-vnStat image output - Copyright (c) 2007-2016 Teemu Toivola <tst@iki.fi>
+vnStat image output - Copyright (c) 2007-2017 Teemu Toivola <tst@iki.fi>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
#include "image.h"
#include "cfg.h"
#include "dbaccess.h"
-#include "dbmerge.h"
#include "vnstati.h"
int main(int argc, char *argv[])
#include "common.h"
#include "dbaccess.h"
#include "ifinfo.h"
-//#include "dbshow.h"
-//#include "dbxml.h"
-//#include "dbjson.h"
+#include "dbsql.h"
+#include "dbshow.h"
+#include "dbxml.h"
+#include "dbjson.h"
#include "cfg.h"
#include "ibw.h"
#include "fs.h"
ck_assert_int_eq(validatedb(&data), 0);
}
END_TEST
-/*
+
START_TEST(database_outputs_do_not_crash)
{
- int i;
+ int ret, i;
- initdb();
defaultcfg();
- strcpy(data.interface, "something");
- strcpy(data.nick, "nothing");
- data.totalrx = 1;
- data.totaltx = 2;
- data.currx = 3;
- data.curtx = 4;
- data.totalrxk = 5;
- data.totaltxk = 6;
- data.btime = 7;
-
- for (i=0; i<30; i++) {
- data.day[i].date = i+1;
- data.day[i].rx = data.day[i].tx = i*100;
- data.day[i].rxk = data.day[i].txk = i;
- data.day[i].used = 1;
- }
-
- for (i=0; i<10; i++) {
- data.top10[i].date = i+1;
- data.top10[i].rx = data.top10[i].tx = i*100;
- data.top10[i].rxk = data.top10[i].txk = i;
- data.top10[i].used = 1;
- }
- for (i=0; i<12; i++) {
- data.month[i].month = i+1;
- data.month[i].rx = data.month[i].tx = i*100;
- data.month[i].rxk = data.month[i].txk = i;
- data.month[i].used = 1;
- }
+ ret = db_open(1);
+ ck_assert_int_eq(ret, 1);
+ ret = db_addinterface("something");
+ ck_assert_int_eq(ret, 1);
- for (i=0; i<24; i++) {
- data.hour[i].date = i+1;
- data.hour[i].rx = data.hour[i].tx = i*100;
+ for (i=1; i<100; i++) {
+ ret = db_addtraffic_dated("something", i*1234, i*2345, i*85000);
+ ck_assert_int_eq(ret, 1);
}
suppress_output();
- showdb(0);
- showdb(1);
- showdb(2);
- showdb(3);
- showdb(4);
- showdb(5);
- showdb(6);
- showdb(7);
- showdb(8);
- showdb(9);
+ showdb("something", 0);
+ showdb("something", 1);
+ showdb("something", 2);
+ showdb("something", 3);
+ showdb("something", 4);
+ showdb("something", 5);
+ showdb("something", 6);
+ showdb("something", 7);
+ showdb("something", 8);
+ showdb("something", 9);
xmlheader();
- showxml('d');
- showxml('m');
- showxml('t');
- showxml('h');
- showxml('a');
+ showxml("something", 'd');
+ showxml("something", 'm');
+ showxml("something", 't');
+ showxml("something", 'h');
+ showxml("something", 'a');
xmlfooter();
jsonheader();
- showjson(0, 'd');
- showjson(0, 'm');
- showjson(0, 't');
- showjson(0, 'h');
- showjson(0, 'a');
+ showjson("something", 0, 'd');
+ showjson("something", 0, 'm');
+ showjson("something", 0, 't');
+ showjson("something", 0, 'h');
+ showjson("something", 0, 'a');
jsonfooter();
}
END_TEST
{
int len;
suppress_output();
- len = showbar(1, 0, 2, 0, 3, 0);
+ len = showbar(1, 2, 3, 0);
ck_assert_int_eq(len, 0);
}
END_TEST
{
int len;
suppress_output();
- len = showbar(0, 1, 0, 2, 1000, 10);
+ len = showbar(1, 2, 1000, 10);
ck_assert_int_eq(len, 0);
}
END_TEST
cfg.rxchar[0] = 'r';
cfg.txchar[0] = 't';
pipe = pipe_output();
- len = showbar(0, 1, 0, 0, 1, 10);
+ len = showbar(1, 0, 1, 10);
ck_assert_int_eq(len, 10);
fflush(stdout);
cfg.rxchar[0] = 'r';
cfg.txchar[0] = 't';
pipe = pipe_output();
- len = showbar(0, 0, 0, 1, 1, 10);
+ len = showbar(0, 1, 1, 10);
ck_assert_int_eq(len, 10);
fflush(stdout);
cfg.rxchar[0] = 'r';
cfg.txchar[0] = 't';
pipe = pipe_output();
- len = showbar(0, 1, 0, 1, 2, 10);
+ len = showbar(1, 1, 2, 10);
ck_assert_int_eq(len, 10);
fflush(stdout);
cfg.rxchar[0] = 'r';
cfg.txchar[0] = 't';
pipe = pipe_output();
- len = showbar(0, 1, 0, 9, 10, 10);
+ len = showbar(1, 9, 10, 10);
ck_assert_int_eq(len, 10);
fflush(stdout);
cfg.rxchar[0] = 'r';
cfg.txchar[0] = 't';
pipe = pipe_output();
- len = showbar(0, 1, 0, 1000, 1001, 10);
+ len = showbar(1, 1000, 1001, 10);
ck_assert_int_eq(len, 10);
fflush(stdout);
{
int len;
suppress_output();
- len = showbar(0, 1, 0, 2, 1, 10);
+ len = showbar(1, 2, 1, 10);
ck_assert_int_eq(len, 0);
}
END_TEST
-START_TEST(showbar_can_also_do_mb_calculations)
-{
- int pipe, len;
- char buffer[512];
- memset(&buffer, '\0', sizeof(buffer));
-
- defaultcfg();
- cfg.rxchar[0] = 'r';
- cfg.txchar[0] = 't';
- pipe = pipe_output();
- len = showbar(0, 1024, 0, 1024, 2048, 2);
- ck_assert_int_eq(len, 2);
- fflush(stdout);
-
- len = read(pipe, buffer, 512);
- ck_assert_str_eq(buffer, " rt");
-}
-END_TEST
-*/
void add_database_tests(Suite *s)
{
TCase *tc_db = tcase_create("Database");
tcase_add_test(tc_db, validatedb_with_initdb);
tcase_add_test(tc_db, validatedb_with_invalid_totals);
tcase_add_test(tc_db, validatedb_with_top10_use);
- /*tcase_add_test(tc_db, database_outputs_do_not_crash);
+ tcase_add_test(tc_db, database_outputs_do_not_crash);
tcase_add_test(tc_db, showbar_with_zero_len_is_nothing);
tcase_add_test(tc_db, showbar_with_big_max_and_small_numbers);
tcase_add_test(tc_db, showbar_with_all_rx);
tcase_add_test(tc_db, showbar_with_one_tenth);
tcase_add_test(tc_db, showbar_with_small_rx_shows_all_tx);
tcase_add_test(tc_db, showbar_with_max_smaller_than_real_max);
- tcase_add_test(tc_db, showbar_can_also_do_mb_calculations);*/
suite_add_tcase(s, tc_db);
}