support multiple output plugins at the same time
[prads.git] / src / output-plugins / log_dispatch.c
blob9c637c293d8c4e8de8adc350573ebfea45c1a957
1 /**
2 * \author Edward Fjellskål <edward.fjellskaal@redpill-linpro.com>
3 * \author Kacper Wysocki <comotion@krutt.org>
4 */
6 //#include "../common.h"
7 //#include "log_sguil.h"
9 #include "../prads.h"
10 #include "../sys_func.h" // u_ntop
11 #include "log.h"
12 #include "log_stdout.h"
13 #include "log_file.h"
15 int n_outputs = 0;
16 output_plugin *log_output[LOG_MAX];
18 /* set up function pointers for logging */
19 int init_logging(int logtype, const char *file, int flags)
21 output_plugin *log_fun;
22 switch (logtype)
24 case LOG_FILE:
25 log_fun = init_log_file();
26 break;
27 case LOG_STDOUT:
28 log_fun = init_log_stdout();
29 break;
30 case LOG_SGUIL:
31 //init_output_sguil(&log_fun, file, flags);
32 break;
33 /* these types are coming !*/
34 case LOG_ASCII:
35 break;
36 case LOG_UNIFIED:
37 break;
38 default:
39 fprintf(stderr,"whoops! init_logging\n");
41 if(log_fun){
42 log_output[n_outputs++] = log_fun;
43 if(log_fun->init)
44 return log_fun->init(log_fun, file, flags);
45 else
46 return 0;
48 return 0xFABE;
51 /* magic logging function - iterate over all loggers */
52 // note... this breaks anywhere non-GNU!
53 #define log_foo(func, all, count, ...) do { int _i; for(_i = 0; _i < (count) ; _i++) { output_plugin* _p = all[_i]; if(_p && _p -> func) _p -> func(_p, ##__VA_ARGS__); } }while(0)
56 void end_logging()
58 log_foo(denit, log_output, n_outputs);
61 void log_asset_arp (asset *masset)
63 #ifdef DEBUG
64 //static char ip_addr_s[INET6_ADDRSTRLEN];
65 //inet_ntop(AF_INET, &masset->ip_addr.s6_addr32[0], ip_addr_s, INET_ADDRSTRLEN + 1 );
66 //dlog("[*] added mac address to asset: %s\n",ip_addr_s);
67 #endif
68 log_foo(arp, log_output, n_outputs, masset);
71 void log_asset_os (asset *main, os_asset *os)
73 #ifdef DEBUG
74 static char ip_addr_s[INET6_ADDRSTRLEN];
75 u_ntop(main->ip_addr, main->af, ip_addr_s);
76 //dlog("[%lu] Incoming asset, %s: %s:%u [%s]\n",
77 //os->last_seen, (char*)bdata(os->detection),ip_addr_s,ntohs(os->port),(char*)bdata(os->raw_fp));
78 #endif
79 log_foo(os, log_output, n_outputs, main, os);
82 void log_asset_service (asset *main, serv_asset *service)
84 #ifdef DEBUG
85 static char ip_addr_s[INET6_ADDRSTRLEN];
86 u_ntop(main->ip_addr, main->af, ip_addr_s);
87 if (service->role == 1) {
88 fprintf(stderr, "[*] new service: %s:%d %s\n",ip_addr_s,ntohs(service->port),(char *)bdata(service->application));
89 } else {
90 fprintf(stderr, "[*] new client: %s:%d %s\n",ip_addr_s,ntohs(service->port),(char *)bdata(service->application));
92 #endif
93 log_foo(service, log_output, n_outputs, main, service);