EDGESEC  0.1.0-alpha.0+sha.ca29a8277b72f80785649ea9ef9cd7edf642d939
Secure router - reference implementation
sqlite_pcap.h
Go to the documentation of this file.
1 
11 #ifndef SQLITE_PCAP_H
12 #define SQLITE_PCAP_H
13 
14 #include <stdint.h>
15 #include <sqlite3.h>
16 
17 #include "../../../utils/allocs.h"
18 #include "../../../utils/os.h"
19 #include "../../../utils/squeue.h"
20 
21 #define PCAP_TABLE_NAME "pcap"
22 #define PCAP_CREATE_TABLE \
23  "CREATE TABLE IF NOT EXISTS " PCAP_TABLE_NAME \
24  " (timestamp INTEGER NOT NULL, name TEXT NOT NULL, " \
25  "caplen INTEGER, length INTEGER, " \
26  "PRIMARY KEY (name));"
27 #define PCAP_INSERT_INTO \
28  "INSERT INTO " PCAP_TABLE_NAME " VALUES(@timestamp, @name, @caplen, " \
29  "@length);"
30 #define PCAP_SELECT_FIRST_ENTRY \
31  "SELECT timestamp,caplen FROM " PCAP_TABLE_NAME \
32  " ORDER BY timestamp ASC LIMIT 1;"
33 #define PCAP_SUM_GROUP \
34  "SELECT timestamp,caplen FROM " PCAP_TABLE_NAME \
35  " WHERE timestamp > @lt ORDER BY timestamp ASC LIMIT @lim;"
36 #define PCAP_SELECT_GROUP \
37  "SELECT timestamp,name FROM " PCAP_TABLE_NAME \
38  " WHERE timestamp >= @lt ORDER BY timestamp ASC LIMIT @lim;"
39 #define PCAP_DELETE_GROUP \
40  "DELETE FROM " PCAP_TABLE_NAME " WHERE timestamp >= @lt AND timestamp <= " \
41  "@ht;"
42 
44  uint64_t timestamp;
45  char *name;
46 };
47 
54 int init_sqlite_pcap_db(sqlite3 *db);
55 
66 int save_sqlite_pcap_entry(sqlite3 *db, char *name, uint64_t timestamp,
67  uint32_t caplen, uint32_t length);
68 
77 int get_first_pcap_entry(sqlite3 *db, uint64_t *timestamp, uint64_t *caplen);
78 
88 int get_pcap_meta_array(sqlite3 *db, uint64_t lt, uint32_t lim,
89  UT_array *pcap_meta_arr);
90 
99 int delete_pcap_entries(sqlite3 *db, uint64_t lt, uint64_t ht);
100 
111 int sum_pcap_group(sqlite3 *db, uint64_t lt, uint32_t lim, uint64_t *ht,
112  uint64_t *sum);
113 
114 #endif
int get_pcap_meta_array(sqlite3 *db, uint64_t lt, uint32_t lim, UT_array *pcap_meta_arr)
Returns the pcap meta array.
Definition: sqlite_pcap.c:156
int sum_pcap_group(sqlite3 *db, uint64_t lt, uint32_t lim, uint64_t *ht, uint64_t *sum)
Calculates the sum of the group of a pcap.
Definition: sqlite_pcap.c:114
int get_first_pcap_entry(sqlite3 *db, uint64_t *timestamp, uint64_t *caplen)
Returns the first pcap entry timestamp.
Definition: sqlite_pcap.c:82
int init_sqlite_pcap_db(sqlite3 *db)
Initialisez the sqlite pcap db tables.
Definition: sqlite_pcap.c:24
int save_sqlite_pcap_entry(sqlite3 *db, char *name, uint64_t timestamp, uint32_t caplen, uint32_t length)
Save a pcap entry into the sqlite db.
Definition: sqlite_pcap.c:38
int delete_pcap_entries(sqlite3 *db, uint64_t lt, uint64_t ht)
Removes a set of entries.
Definition: sqlite_pcap.c:199
Definition: sqlite_pcap.h:43
char * name
Definition: sqlite_pcap.h:45
uint64_t timestamp
Definition: sqlite_pcap.h:44