Skip to Content
[CAIDA - Cooperative Association for Internet Data Analysis logo]
The Cooperative Association for Internet Data Analysis
corsaro_plugin.h
Go to the documentation of this file.
1 /*
2  * corsaro
3  *
4  * Alistair King, CAIDA, UC San Diego
5  * corsaro-info@caida.org
6  *
7  * Copyright (C) 2012 The Regents of the University of California.
8  *
9  * This file is part of corsaro.
10  *
11  * corsaro is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation, either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * corsaro is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with corsaro. If not, see <http://www.gnu.org/licenses/>.
23  *
24  */
25 
26 #ifndef __CORSARO_PLUGIN_H
27 #define __CORSARO_PLUGIN_H
28 
29 #include "corsaro_int.h"
30 
44 #define CORSARO_PLUGIN_GENERATE_PROTOS(plugin) \
45  corsaro_plugin_t * plugin##_alloc(); \
46  int plugin##_probe_filename(const char *fname); \
47  int plugin##_probe_magic(struct corsaro_in * corsaro, corsaro_file_in_t *file); \
48  int plugin##_init_input(struct corsaro_in *corsaro); \
49  int plugin##_init_output(struct corsaro *corsaro); \
50  int plugin##_close_input(struct corsaro_in *corsaro); \
51  int plugin##_close_output(struct corsaro *corsaro); \
52  off_t plugin##_read_record(struct corsaro_in *corsaro, \
53  enum corsaro_in_record_type *record_type, \
54  struct corsaro_in_record *record); \
55  off_t plugin##_read_global_data_record(struct corsaro_in *corsaro, \
56  enum corsaro_in_record_type *record_type, \
57  struct corsaro_in_record *record); \
58  int plugin##_start_interval(struct corsaro *corsaro, \
59  struct corsaro_interval *int_start); \
60  int plugin##_end_interval(struct corsaro *corsaro, \
61  struct corsaro_interval *int_end); \
62  int plugin##_process_packet(struct corsaro *corsaro, \
63  struct corsaro_packet *packet);
64 
70 #define CORSARO_PLUGIN_GENERATE_PTRS(plugin) \
71  plugin##_probe_filename, \
72  plugin##_probe_magic, \
73  plugin##_init_input, \
74  plugin##_init_output, \
75  plugin##_close_input, \
76  plugin##_close_output, \
77  plugin##_read_record, \
78  plugin##_read_global_data_record, \
79  plugin##_start_interval, \
80  plugin##_end_interval, \
81  plugin##_process_packet
82 
87 #define CORSARO_PLUGIN_STATE(corsaro, type, id) \
88  ((struct corsaro_##type##_state_t*) \
89  ((corsaro)->plugin_manager->plugins_state[(id)-1]))
90 
95 #define CORSARO_PLUGIN_PLUGIN(corsaro, id) \
96  ((corsaro)->plugin_manager->plugins[(id)-1])
97 
106 typedef enum corsaro_plugin_id
107 {
115 
118 
121 
125 
127 /* All functions should return -1, or NULL on failure */
128 typedef struct corsaro_plugin
129 {
132  const char *name;
133 
134 #if 0
135 
137  /*const char *version;*/
138 #endif
139 
142 
144  const uint32_t magic;
145 
152  int (*probe_filename)(const char *fname);
153 
162 
168  int (*init_input)(struct corsaro_in *corsaro);
169 
175  int (*init_output)(struct corsaro *corsaro);
176 
182  int (*close_input)(struct corsaro_in *corsaro);
183 
189  int (*close_output)(struct corsaro *corsaro);
190 
202  off_t (*read_record)(struct corsaro_in *corsaro,
203  enum corsaro_in_record_type *record_type,
204  struct corsaro_in_record *record);
205 
218  enum corsaro_in_record_type *record_type,
219  struct corsaro_in_record *record);
220 
227  int (*start_interval)(struct corsaro *corsaro, struct corsaro_interval *int_start);
228 
237  int (*end_interval)(struct corsaro *corsaro, struct corsaro_interval *int_end);
238 
251  int (*process_packet)(struct corsaro *corsaro, struct corsaro_packet *packet);
252 
256 
258 
265 {
270  uint16_t *plugins_enabled;
271 
274 
277 
280 
283 
285  uint16_t plugins_cnt;
286 
289 
291 
297 
302 int corsaro_plugin_manager_start(corsaro_plugin_manager_t *manager);
303 
313 void corsaro_plugin_manager_free(corsaro_plugin_manager_t *manager);
314 
321 corsaro_plugin_t *corsaro_plugin_get_by_id(corsaro_plugin_manager_t *manager,
322  int id);
323 
330 corsaro_plugin_t *corsaro_plugin_get_by_name(corsaro_plugin_manager_t *manager,
331  const char *name);
332 
341 corsaro_plugin_t *corsaro_plugin_next(corsaro_plugin_manager_t *manager,
342  corsaro_plugin_t *plugin);
343 
350 void corsaro_plugin_register_state(corsaro_plugin_manager_t *manager,
351  corsaro_plugin_t *plugin,
352  void *state);
353 
359 void corsaro_plugin_free_state(corsaro_plugin_manager_t *manager,
360  corsaro_plugin_t *plugin);
361 
368 int corsaro_plugin_probe_filename(const char *fname, corsaro_plugin_t *plugin);
369 
377 const char *corsaro_plugin_get_name(corsaro_plugin_manager_t *manager,
378  int id);
379 
389 int corsaro_plugin_is_enabled(corsaro_plugin_manager_t *manager,
390  corsaro_plugin_t *plugin);
391 
400 int corsaro_plugin_enable_plugin(corsaro_plugin_manager_t *manager,
401  const char *plugin_name);
402 
403 #endif /* __CORSARO_PLUGIN_H */