EDGESEC  0.1.0-alpha.0+sha.ca29a8277b72f80785649ea9ef9cd7edf642d939
Secure router - reference implementation
middlewares_list.h
Go to the documentation of this file.
1 
13 #ifndef MIDDLEWARES_LIST_H
14 #define MIDDLEWARES_LIST_H
15 
16 #include <eloop.h>
17 #include <pcap.h>
18 #include <sqlite3.h>
19 #include <utarray.h>
20 #include "middleware.h"
21 
29  const struct capture_middleware f;
36 };
37 
39 static const UT_icd middleware_icd = {sizeof(struct middleware_handlers), NULL,
40  NULL, NULL};
41 
50 UT_array *assign_middlewares(void);
51 
65 static inline int init_middlewares(UT_array *handlers, sqlite3 *db,
66  char *db_path, struct eloop_data *eloop,
67  struct pcap_context *pc, char *params) {
68  struct middleware_handlers *handler = NULL;
69 
70  while ((handler =
71  (struct middleware_handlers *)utarray_next(handlers, handler))) {
72  log_trace("Initialising capture middleware: %s", handler->f.name);
73  handler->context = handler->f.init(db, db_path, eloop, pc, params);
74  if (handler->context == NULL) {
75  log_error("handle init error");
76  return -1;
77  }
78  }
79 
80  return 0;
81 }
82 
89 static inline void free_middlewares(UT_array *handlers) {
90  struct middleware_handlers *handler = NULL;
91 
92  if (handlers == NULL) {
93  return;
94  }
95 
96  while ((handler =
97  (struct middleware_handlers *)utarray_next(handlers, handler))) {
98  handler->f.free(handler->context);
99  handler->context = NULL;
100  }
101 
102  utarray_free(handlers);
103 }
104 
116 static inline void process_middlewares(UT_array *handlers, char *ltype,
117  struct pcap_pkthdr *header,
118  uint8_t *packet, char *ifname) {
119  struct middleware_handlers *handler = NULL;
120 
121  while ((handler =
122  (struct middleware_handlers *)utarray_next(handlers, handler))) {
123  if (handler->f.process(handler->context, ltype, header, packet, ifname) <
124  0) {
125  log_error("handler process fail");
126  }
127  }
128 }
129 
130 #endif /* !MIDDLEWARES_LIST_H */
#define log_error(...)
Logs an error message. Do not use this for if you want to log errno, instead use log_errno for this.
Definition: log.h:68
#define log_trace(...)
Definition: log.h:57
File containing the definition of a generic middleware.
UT_array * assign_middlewares(void)
Constructs the list of middlewares to use.
Structure describing a middleware for the EDGESec capture service.
Definition: middleware.h:41
void(*const free)(struct middleware_context *context)
Frees the middleware context.
Definition: middleware.h:77
int(*const process)(struct middleware_context *context, const char *ltype, struct pcap_pkthdr *header, uint8_t *packet, char *ifname)
Runs the middleware.
Definition: middleware.h:68
const char *const name
Human readable name for middleware.
Definition: middleware.h:84
struct middleware_context *(*const init)(sqlite3 *db, char *db_path, struct eloop_data *eloop, struct pcap_context *pc, char *params)
Initialises the middleware.
Definition: middleware.h:52
Definition: middleware.h:22
Generic middleware context and functions.
Definition: middlewares_list.h:25
const struct capture_middleware f
The implementation of the middleware functions.
Definition: middlewares_list.h:29
struct middleware_context * context
The storage of the middleware. This should be created by capture_middleware::init() and freed with ca...
Definition: middlewares_list.h:35
Pcap context structure definition.
Definition: pcap_service.h:29