vnstat  2.9
About: vnStat is a console-based network traffic monitor (using the /proc filesystem).
  Fossies Dox: vnstat-2.9.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

dbsql.h File Reference
#include <sqlite3.h>
#include "iflist.h"
Include dependency graph for dbsql.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  dbdatalist
 
struct  dbdatalistinfo
 
struct  interfaceinfo
 

Typedefs

typedef struct dbdatalist dbdatalist
 
typedef struct dbdatalistinfo dbdatalistinfo
 
typedef struct interfaceinfo interfaceinfo
 

Functions

int db_open_ro (void)
 
int db_open_rw (const int createifnotfound)
 
int db_open (const int createifnotfound, const int readonly)
 
int db_validate (const int readonly)
 
int db_setpragmas (void)
 
int db_close (void)
 
int db_exec (const char *sql)
 
int db_create (void)
 
int db_addinterface (const char *iface)
 
int db_removeinterface (const char *iface)
 
int db_renameinterface (const char *iface, const char *newifname)
 
uint64_t db_getinterfacecount (void)
 
uint64_t db_getinterfacecountbyname (const char *iface)
 
sqlite3_int64 db_getinterfaceid (const char *iface, const int createifnotfound)
 
char * db_getinterfaceidin (const char *iface)
 
int db_setinterfacebyalias (char *iface, const char *alias, const int matchmethod)
 
int db_setactive (const char *iface, const int active)
 
int db_setupdated (const char *iface, const time_t timestamp)
 
int db_setcounters (const char *iface, const uint64_t rxcounter, const uint64_t txcounter)
 
int db_getcounters (const char *iface, uint64_t *rxcounter, uint64_t *txcounter)
 
int db_getinterfaceinfo (const char *iface, interfaceinfo *info)
 
int db_setalias (const char *iface, const char *alias)
 
int db_setinfo (const char *name, const char *value, const int createifnotfound)
 
char * db_getinfo (const char *name)
 
int db_getiflist (iflist **ifl)
 
int db_getiflist_sorted (iflist **ifl, const int orderbytraffic)
 
char * db_get_date_generator (const int range, const short direct, const char *nowdate)
 
int db_addtraffic (const char *iface, const uint64_t rx, const uint64_t tx)
 
int db_addtraffic_dated (const char *iface, const uint64_t rx, const uint64_t tx, const uint64_t timestamp)
 
int db_setcreation (const char *iface, const time_t timestamp)
 
int db_settotal (const char *iface, const uint64_t rx, const uint64_t tx)
 
int db_insertdata (const char *table, const char *iface, const uint64_t rx, const uint64_t tx, const uint64_t timestamp)
 
int db_removeoldentries (void)
 
int db_removeoldentries_top (void)
 
int db_vacuum (void)
 
int db_begintransaction (void)
 
int db_committransaction (void)
 
int db_rollbacktransaction (void)
 
int db_iserrcodefatal (int errcode)
 
int db_isdiskfull (int errcode)
 
int db_getdata (dbdatalist **dbdata, dbdatalistinfo *listinfo, const char *iface, const char *table, const uint32_t resultlimit)
 
int db_getdata_range (dbdatalist **dbdata, dbdatalistinfo *listinfo, const char *iface, const char *table, const uint32_t resultlimit, const char *databegin, const char *dataend)
 
void updatelistinfo (dbdatalistinfo *listinfo, const uint64_t rx, const uint64_t tx, const time_t timestamp)
 
int dbdatalistadd (dbdatalist **dbdata, const uint64_t rx, const uint64_t tx, const time_t timestamp, const int64_t rowid)
 
void dbdatalistfree (dbdatalist **dbdata)
 
unsigned int getqueryinterfacecount (const char *input)
 
char * getifaceinquery (const char *input)
 

Variables

sqlite3 * db
 
int db_errcode
 
int db_intransaction
 

Typedef Documentation

◆ dbdatalist

typedef struct dbdatalist dbdatalist

◆ dbdatalistinfo

◆ interfaceinfo

typedef struct interfaceinfo interfaceinfo

Function Documentation

◆ db_addinterface()

int db_addinterface ( const char *  iface)

Definition at line 370 of file dbsql.c.

References cfg, db_exec(), and CFG::dbtzmodifier.

Referenced by addinterfaces(), db_getinterfaceid(), handleaddinterface(), and importlegacydb().

◆ db_addtraffic()

int db_addtraffic ( const char *  iface,
const uint64_t  rx,
const uint64_t  tx 
)

Definition at line 843 of file dbsql.c.

References db_addtraffic_dated().

◆ db_addtraffic_dated()

int db_addtraffic_dated ( const char *  iface,
const uint64_t  rx,
const uint64_t  tx,
const uint64_t  timestamp 
)

◆ db_begintransaction()

int db_begintransaction ( void  )

◆ db_close()

◆ db_committransaction()

int db_committransaction ( void  )

◆ db_create()

int db_create ( void  )

◆ db_exec()

◆ db_get_date_generator()

char * db_get_date_generator ( const int  range,
const short  direct,
const char *  nowdate 
)

Definition at line 807 of file dbsql.c.

References cfg, CFG::dbtzmodifier, CFG::monthrotate, and CFG::monthrotateyears.

Referenced by db_addtraffic_dated(), and db_insertdata().

◆ db_getcounters()

int db_getcounters ( const char *  iface,
uint64_t *  rxcounter,
uint64_t *  txcounter 
)

Definition at line 616 of file dbsql.c.

References db, db_errcode, db_getinterfaceid(), errorstring, printe(), and PT_Error.

◆ db_getdata()

int db_getdata ( dbdatalist **  dbdata,
dbdatalistinfo listinfo,
const char *  iface,
const char *  table,
const uint32_t  resultlimit 
)

◆ db_getdata_range()

int db_getdata_range ( dbdatalist **  dbdata,
dbdatalistinfo listinfo,
const char *  iface,
const char *  table,
const uint32_t  resultlimit,
const char *  databegin,
const char *  dataend 
)

◆ db_getiflist()

int db_getiflist ( iflist **  ifl)

◆ db_getiflist_sorted()

int db_getiflist_sorted ( iflist **  ifl,
const int  orderbytraffic 
)

Definition at line 771 of file dbsql.c.

References db, db_errcode, errorstring, iflistadd(), printe(), and PT_Error.

Referenced by db_getiflist(), handledatabase(), and handleifselection().

◆ db_getinfo()

char * db_getinfo ( const char *  name)

Definition at line 739 of file dbsql.c.

References db, db_errcode, errorstring, printe(), PT_Error, and strncpy_nt().

Referenced by db_validate(), and detectboot().

◆ db_getinterfacecount()

uint64_t db_getinterfacecount ( void  )

Definition at line 414 of file dbsql.c.

References db_getinterfacecountbyname().

Referenced by main(), and preparedatabase().

◆ db_getinterfacecountbyname()

◆ db_getinterfaceid()

◆ db_getinterfaceidin()

char * db_getinterfaceidin ( const char *  iface)

Definition at line 496 of file dbsql.c.

References db, db_errcode, errorstring, getifaceinquery(), printe(), and PT_Error.

Referenced by db_getdata_range(), and db_getinterfaceinfo().

◆ db_getinterfaceinfo()

◆ db_insertdata()

int db_insertdata ( const char *  table,
const char *  iface,
const uint64_t  rx,
const uint64_t  tx,
const uint64_t  timestamp 
)

Definition at line 938 of file dbsql.c.

References cfg, db_exec(), db_get_date_generator(), db_getinterfaceid(), and CFG::useutc.

Referenced by insertlegacydata().

◆ db_isdiskfull()

int db_isdiskfull ( int  errcode)

Definition at line 1182 of file dbsql.c.

Referenced by handledatabaseerror().

◆ db_iserrcodefatal()

int db_iserrcodefatal ( int  errcode)

Definition at line 1168 of file dbsql.c.

Referenced by handledatabaseerror().

◆ db_open()

int db_open ( const int  createifnotfound,
const int  readonly 
)

◆ db_open_ro()

int db_open_ro ( void  )

Definition at line 11 of file dbsql.c.

References db_open().

Referenced by handledatabase(), handleifselection(), main(), and showdbiflist().

◆ db_open_rw()

int db_open_rw ( const int  createifnotfound)

◆ db_removeinterface()

int db_removeinterface ( const char *  iface)

Definition at line 382 of file dbsql.c.

References db_exec(), and db_getinterfaceid().

Referenced by addinterfaces(), flushcachetodisk(), and handleremoveinterface().

◆ db_removeoldentries()

◆ db_removeoldentries_top()

int db_removeoldentries_top ( void  )

◆ db_renameinterface()

int db_renameinterface ( const char *  iface,
const char *  newifname 
)

Definition at line 396 of file dbsql.c.

References db_exec(), and db_getinterfaceid().

Referenced by handlerenameinterface().

◆ db_rollbacktransaction()

int db_rollbacktransaction ( void  )

◆ db_setactive()

int db_setactive ( const char *  iface,
const int  active 
)

Definition at line 574 of file dbsql.c.

References db_exec(), and db_getinterfaceid().

Referenced by flushcachetodisk(), and insertlegacydata().

◆ db_setalias()

int db_setalias ( const char *  iface,
const char *  alias 
)

Definition at line 708 of file dbsql.c.

References db_exec(), and db_getinterfaceid().

Referenced by handlesetalias(), and insertlegacydata().

◆ db_setcounters()

int db_setcounters ( const char *  iface,
const uint64_t  rxcounter,
const uint64_t  txcounter 
)

Definition at line 602 of file dbsql.c.

References db_exec(), and db_getinterfaceid().

Referenced by addinterfaces(), flushcachetodisk(), and insertlegacydata().

◆ db_setcreation()

int db_setcreation ( const char *  iface,
const time_t  timestamp 
)

Definition at line 909 of file dbsql.c.

References cfg, db_exec(), db_getinterfaceid(), and CFG::dbtzmodifier.

Referenced by insertlegacydata().

◆ db_setinfo()

int db_setinfo ( const char *  name,
const char *  value,
const int  createifnotfound 
)

Definition at line 722 of file dbsql.c.

References db, and db_exec().

Referenced by db_create(), db_open(), and detectboot().

◆ db_setinterfacebyalias()

int db_setinterfacebyalias ( char *  iface,
const char *  alias,
const int  matchmethod 
)

Definition at line 527 of file dbsql.c.

References db, db_errcode, errorstring, printe(), PT_Error, and strncpy_nt().

Referenced by handledatabase(), and validateinterface().

◆ db_setpragmas()

int db_setpragmas ( void  )

Definition at line 171 of file dbsql.c.

References cfg, db, db_errcode, db_exec(), CFG::dbsynchronous, errorstring, printe(), PT_Error, and CFG::waldb.

Referenced by db_open().

◆ db_settotal()

int db_settotal ( const char *  iface,
const uint64_t  rx,
const uint64_t  tx 
)

Definition at line 923 of file dbsql.c.

References db_exec(), and db_getinterfaceid().

Referenced by insertlegacydata().

◆ db_setupdated()

int db_setupdated ( const char *  iface,
const time_t  timestamp 
)

Definition at line 588 of file dbsql.c.

References cfg, db_exec(), db_getinterfaceid(), and CFG::dbtzmodifier.

Referenced by flushcachetodisk().

◆ db_vacuum()

int db_vacuum ( void  )

Definition at line 1097 of file dbsql.c.

References db_exec(), and debug.

◆ db_validate()

int db_validate ( const int  readonly)

Definition at line 131 of file dbsql.c.

References db_errcode, db_getinfo(), debug, and SQLDBVERSION.

Referenced by db_open().

◆ dbdatalistadd()

int dbdatalistadd ( dbdatalist **  dbdata,
const uint64_t  rx,
const uint64_t  tx,
const time_t  timestamp,
const int64_t  rowid 
)

◆ dbdatalistfree()

◆ getifaceinquery()

char * getifaceinquery ( const char *  input)

Definition at line 1425 of file dbsql.c.

References getqueryinterfacecount(), and panicexit().

Referenced by db_getinterfacecountbyname(), and db_getinterfaceidin().

◆ getqueryinterfacecount()

unsigned int getqueryinterfacecount ( const char *  input)

Definition at line 1404 of file dbsql.c.

Referenced by db_getinterfacecountbyname(), and getifaceinquery().

◆ updatelistinfo()

void updatelistinfo ( dbdatalistinfo listinfo,
const uint64_t  rx,
const uint64_t  tx,
const time_t  timestamp 
)

Variable Documentation

◆ db

◆ db_errcode

◆ db_intransaction

int db_intransaction
extern