rbroccoli 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/MIT-LICENSE +21 -0
- data/README +40 -0
- data/data/bro/callback-typemaps.yml +1010 -0
- data/data/bro/record-typemaps.yml +332 -0
- data/ext/broccoli_ext/autogen.sh +3 -0
- data/ext/broccoli_ext/broccoli.i +463 -0
- data/ext/broccoli_ext/broccoli_wrap.c +4213 -0
- data/ext/broccoli_ext/extconf.rb +15 -0
- data/ext/broccoli_ext/post-clean.rb +3 -0
- data/ext/broccoli_ext/pre-config.rb +5 -0
- data/ext/broccoli_ext/test/broconftest.rb +12 -0
- data/ext/broccoli_ext/test/test.rb +174 -0
- data/lib/Bro/connection.rb +73 -0
- data/lib/Bro/event.rb +34 -0
- data/lib/Bro/record.rb +60 -0
- data/lib/Bro/typemap.rb +158 -0
- data/lib/bro.rb +105 -0
- metadata +64 -0
@@ -0,0 +1,332 @@
|
|
1
|
+
# This file was autogenerated on Tue Aug 22 15:06:07 EDT 2006
|
2
|
+
# Please do not edit!
|
3
|
+
---
|
4
|
+
:X509:
|
5
|
+
:subject: :string
|
6
|
+
:orig_addr: :addr
|
7
|
+
:issuer: :string
|
8
|
+
:nfs3_lookup_args:
|
9
|
+
:name: :string
|
10
|
+
:fh: :string
|
11
|
+
:udp_hdr:
|
12
|
+
:sport: :port
|
13
|
+
:ulen: :count
|
14
|
+
:dport: :port
|
15
|
+
:pcap_packet:
|
16
|
+
:len: :count
|
17
|
+
:ts_sec: :count
|
18
|
+
:ts_usec: :count
|
19
|
+
:data: :string
|
20
|
+
:caplen: :count
|
21
|
+
:event_peer:
|
22
|
+
:host: :addr
|
23
|
+
:p: :port
|
24
|
+
:is_local: :bool
|
25
|
+
:descr: :string
|
26
|
+
:id: :peer_id
|
27
|
+
:endpoint:
|
28
|
+
:size: :count
|
29
|
+
:state: :count
|
30
|
+
:icmp_context:
|
31
|
+
:frag_offset: :count
|
32
|
+
:bad_hdr_len: :bool
|
33
|
+
:len: :count
|
34
|
+
:bad_checksum: :bool
|
35
|
+
:MF: :bool
|
36
|
+
:DF: :bool
|
37
|
+
:proto: :count
|
38
|
+
:id: :conn_id
|
39
|
+
:dns_soa:
|
40
|
+
:serial: :count
|
41
|
+
:mname: :string
|
42
|
+
:minimum: :interval
|
43
|
+
:rname: :string
|
44
|
+
:refresh: :interval
|
45
|
+
:expire: :interval
|
46
|
+
:retry: :interval
|
47
|
+
:pm_mapping:
|
48
|
+
:p: :port
|
49
|
+
:version: :count
|
50
|
+
:program: :count
|
51
|
+
:irc_join_info:
|
52
|
+
:usermode: :string
|
53
|
+
:password: :string
|
54
|
+
:nick: :string
|
55
|
+
:channel: :string
|
56
|
+
:nfs3_lookup_reply:
|
57
|
+
:dir_attr: :nfs3_opt_attrs
|
58
|
+
:fh: :string
|
59
|
+
:file_attr: :nfs3_opt_attrs
|
60
|
+
:net_stats:
|
61
|
+
:pkts_recvd: :count
|
62
|
+
:pkts_dropped: :count
|
63
|
+
:pkts_link: :count
|
64
|
+
:dns_edns_additional:
|
65
|
+
:query: :string
|
66
|
+
:TTL: :interval
|
67
|
+
:is_query: :count
|
68
|
+
:qtype: :count
|
69
|
+
:payload_size: :count
|
70
|
+
:extended_rcode: :count
|
71
|
+
:z_field: :count
|
72
|
+
:t: :count
|
73
|
+
:version: :count
|
74
|
+
:pm_port_request:
|
75
|
+
:is_tcp: :bool
|
76
|
+
:version: :count
|
77
|
+
:program: :count
|
78
|
+
:sw_substring:
|
79
|
+
:new: :bool
|
80
|
+
:aligns: :sw_align_vec
|
81
|
+
:str: :string
|
82
|
+
:packet:
|
83
|
+
:conn: :connection
|
84
|
+
:seq: :count
|
85
|
+
:timestamp: :time
|
86
|
+
:is_orig: :bool
|
87
|
+
:connection:
|
88
|
+
:addl: :string
|
89
|
+
:hot: :count
|
90
|
+
:history: :string
|
91
|
+
:start_time: :time
|
92
|
+
:duration: :interval
|
93
|
+
:resp: :endpoint
|
94
|
+
:orig: :endpoint
|
95
|
+
:service: :string
|
96
|
+
:id: :conn_id
|
97
|
+
:software_version:
|
98
|
+
:addl: :string
|
99
|
+
:minor: :int
|
100
|
+
:minor2: :int
|
101
|
+
:major: :int
|
102
|
+
:nfs3_fsstat:
|
103
|
+
:tfiles: :double
|
104
|
+
:ffiles: :double
|
105
|
+
:attrs: :nfs3_opt_attrs
|
106
|
+
:afiles: :double
|
107
|
+
:tbytes: :double
|
108
|
+
:invarsec: :interval
|
109
|
+
:fbytes: :double
|
110
|
+
:abytes: :double
|
111
|
+
:rotate_info:
|
112
|
+
:open: :time
|
113
|
+
:old_name: :string
|
114
|
+
:new_name: :string
|
115
|
+
:close: :time
|
116
|
+
:endpoint_stats:
|
117
|
+
:num_repl: :count
|
118
|
+
:num_pkts: :count
|
119
|
+
:endian_type: :count
|
120
|
+
:num_rxmit: :count
|
121
|
+
:num_rxmit_bytes: :count
|
122
|
+
:num_in_order: :count
|
123
|
+
:num_OO: :count
|
124
|
+
:pattern_match_result:
|
125
|
+
:matched: :bool
|
126
|
+
:off: :count
|
127
|
+
:str: :string
|
128
|
+
:signature_state:
|
129
|
+
:conn: :connection
|
130
|
+
:payload_size: :count
|
131
|
+
:is_orig: :bool
|
132
|
+
:id: :string
|
133
|
+
:dns_tsig_additional:
|
134
|
+
:query: :string
|
135
|
+
:orig_id: :count
|
136
|
+
:is_query: :count
|
137
|
+
:rr_error: :count
|
138
|
+
:qtype: :count
|
139
|
+
:alg_name: :string
|
140
|
+
:sig: :string
|
141
|
+
:time_signed: :time
|
142
|
+
:fudge: :time
|
143
|
+
:pkt_hdr:
|
144
|
+
:ip: :ip_hdr
|
145
|
+
:ntp_msg:
|
146
|
+
:receive_t: :time
|
147
|
+
:precision: :int
|
148
|
+
:xmit_t: :time
|
149
|
+
:distance: :interval
|
150
|
+
:dispersion: :interval
|
151
|
+
:ref_t: :time
|
152
|
+
:stratum: :count
|
153
|
+
:originate_t: :time
|
154
|
+
:code: :count
|
155
|
+
:id: :count
|
156
|
+
:poll: :count
|
157
|
+
:nfs3_opt_attrs: {}
|
158
|
+
|
159
|
+
:ip_hdr:
|
160
|
+
:len: :count
|
161
|
+
:hl: :count
|
162
|
+
:tos: :count
|
163
|
+
:src: :addr
|
164
|
+
:p: :count
|
165
|
+
:dst: :addr
|
166
|
+
:ttl: :count
|
167
|
+
:id: :count
|
168
|
+
:sw_params: {}
|
169
|
+
|
170
|
+
:software:
|
171
|
+
:name: :string
|
172
|
+
:version: :software_version
|
173
|
+
:http_message_stat:
|
174
|
+
:body_length: :count
|
175
|
+
:start: :time
|
176
|
+
:content_gap_length: :count
|
177
|
+
:header_length: :count
|
178
|
+
:interrupted: :bool
|
179
|
+
:finish_msg: :string
|
180
|
+
:pm_callit_request:
|
181
|
+
:proc: :count
|
182
|
+
:arg_size: :count
|
183
|
+
:version: :count
|
184
|
+
:program: :count
|
185
|
+
:tcp_hdr:
|
186
|
+
:ack: :count
|
187
|
+
:hl: :count
|
188
|
+
:dl: :count
|
189
|
+
:seq: :count
|
190
|
+
:win: :count
|
191
|
+
:flags: :count
|
192
|
+
:sport: :port
|
193
|
+
:dport: :port
|
194
|
+
:bro_resources:
|
195
|
+
:num_packets: :count
|
196
|
+
:system_time: :interval
|
197
|
+
:max_ICMP_conns: :count
|
198
|
+
:num_context: :count
|
199
|
+
:num_timers: :count
|
200
|
+
:minor_faults: :count
|
201
|
+
:debug: :bool
|
202
|
+
:max_fragments: :count
|
203
|
+
:num_TCP_conns: :count
|
204
|
+
:mem: :count
|
205
|
+
:num_events_queued: :count
|
206
|
+
:major_faults: :count
|
207
|
+
:max_timers: :count
|
208
|
+
:num_UDP_conns: :count
|
209
|
+
:start_time: :time
|
210
|
+
:num_events_dispatched: :count
|
211
|
+
:num_swap: :count
|
212
|
+
:num_ICMP_conns: :count
|
213
|
+
:real_time: :interval
|
214
|
+
:max_TCP_conns: :count
|
215
|
+
:blocking_input: :count
|
216
|
+
:num_fragments: :count
|
217
|
+
:user_time: :interval
|
218
|
+
:max_UDP_conns: :count
|
219
|
+
:blocking_output: :count
|
220
|
+
:version: :string
|
221
|
+
:icmp_hdr:
|
222
|
+
:icmp_type: :count
|
223
|
+
:interconn_endp_stats:
|
224
|
+
:is_partial: :bool
|
225
|
+
:num_pkts: :count
|
226
|
+
:num_7bit_ascii: :count
|
227
|
+
:num_keystrokes_two_in_row: :count
|
228
|
+
:num_lines: :count
|
229
|
+
:num_normal_interarrivals: :count
|
230
|
+
:num_normal_lines: :count
|
231
|
+
:num_8k0_pkts: :count
|
232
|
+
:num_bytes: :count
|
233
|
+
:num_8k4_pkts: :count
|
234
|
+
:dns_msg:
|
235
|
+
:num_answers: :count
|
236
|
+
:AA: :bool
|
237
|
+
:num_auth: :count
|
238
|
+
:TC: :bool
|
239
|
+
:num_addl: :count
|
240
|
+
:RD: :bool
|
241
|
+
:opcode: :count
|
242
|
+
:RA: :bool
|
243
|
+
:rcode: :count
|
244
|
+
:Z: :count
|
245
|
+
:num_queries: :count
|
246
|
+
:QR: :bool
|
247
|
+
:id: :count
|
248
|
+
:mime_header_rec:
|
249
|
+
:value: :string
|
250
|
+
:name: :string
|
251
|
+
:sw_align:
|
252
|
+
:index: :count
|
253
|
+
:str: :string
|
254
|
+
:SYN_packet:
|
255
|
+
:win_scale: :int
|
256
|
+
:MSS: :count
|
257
|
+
:size: :count
|
258
|
+
:SACK_OK: :bool
|
259
|
+
:is_orig: :bool
|
260
|
+
:ttl: :count
|
261
|
+
:DF: :bool
|
262
|
+
:win_size: :count
|
263
|
+
:http_stats_rec:
|
264
|
+
:num_requests: :count
|
265
|
+
:num_replies: :count
|
266
|
+
:request_version: :double
|
267
|
+
:reply_version: :double
|
268
|
+
:nfs3_attrs:
|
269
|
+
:mtime: :time
|
270
|
+
:rdev2: :count
|
271
|
+
:mode: :count
|
272
|
+
:ctime: :time
|
273
|
+
:fsid: :double
|
274
|
+
:nlink: :count
|
275
|
+
:fileid: :double
|
276
|
+
:uid: :count
|
277
|
+
:size: :double
|
278
|
+
:gid: :count
|
279
|
+
:used: :double
|
280
|
+
:ftype: :nfs3_file_type
|
281
|
+
:atime: :time
|
282
|
+
:rdev1: :count
|
283
|
+
:ftp_port:
|
284
|
+
:valid: :bool
|
285
|
+
:p: :port
|
286
|
+
:h: :addr
|
287
|
+
:icmp_conn:
|
288
|
+
:itype: :count
|
289
|
+
:len: :count
|
290
|
+
:orig_h: :addr
|
291
|
+
:icode: :count
|
292
|
+
:resp_h: :addr
|
293
|
+
:OS_version:
|
294
|
+
:match_type: :OS_version_inference
|
295
|
+
:genre: :string
|
296
|
+
:detail: :string
|
297
|
+
:dist: :count
|
298
|
+
:backdoor_endp_stats:
|
299
|
+
:is_partial: :bool
|
300
|
+
:num_pkts: :count
|
301
|
+
:num_7bit_ascii: :count
|
302
|
+
:num_lines: :count
|
303
|
+
:num_normal_lines: :count
|
304
|
+
:num_8k0_pkts: :count
|
305
|
+
:num_bytes: :count
|
306
|
+
:num_8k4_pkts: :count
|
307
|
+
:dns_answer:
|
308
|
+
:query: :string
|
309
|
+
:TTL: :interval
|
310
|
+
:qtype: :count
|
311
|
+
:answer_type: :count
|
312
|
+
:qclass: :count
|
313
|
+
:matcher_stats:
|
314
|
+
:dfa_states: :count
|
315
|
+
:computed: :count
|
316
|
+
:mem: :count
|
317
|
+
:hits: :count
|
318
|
+
:misses: :count
|
319
|
+
:avg_nfa_states: :count
|
320
|
+
:matchers: :count
|
321
|
+
:dns_mapping:
|
322
|
+
:req_host: :string
|
323
|
+
:req_addr: :addr
|
324
|
+
:hostname: :string
|
325
|
+
:valid: :bool
|
326
|
+
:addrs: :addr_set
|
327
|
+
:creation_time: :time
|
328
|
+
:conn_id:
|
329
|
+
:orig_h: :addr
|
330
|
+
:orig_p: :port
|
331
|
+
:resp_h: :addr
|
332
|
+
:resp_p: :port
|
@@ -0,0 +1,463 @@
|
|
1
|
+
%module "broccoli_ext"
|
2
|
+
|
3
|
+
%include cpointer.i
|
4
|
+
%include typemaps.i
|
5
|
+
|
6
|
+
%{
|
7
|
+
/* Includes the header in the wrapper code */
|
8
|
+
#include "broccoli.h"
|
9
|
+
#include "stdarg.h"
|
10
|
+
%}
|
11
|
+
|
12
|
+
%{
|
13
|
+
|
14
|
+
/* Convert Ruby String to BroString */
|
15
|
+
BroString to_brostring(VALUE obj){
|
16
|
+
if(!NIL_P(obj)){
|
17
|
+
Check_Type(obj, T_STRING);
|
18
|
+
BroString bs;
|
19
|
+
bro_string_set(&bs, STR2CSTR(obj));
|
20
|
+
return bs;
|
21
|
+
}
|
22
|
+
}
|
23
|
+
|
24
|
+
//VALUE
|
25
|
+
//from_brostring(BroString *bs) {
|
26
|
+
// printf("Converting a brostring to char*\n");
|
27
|
+
// return rb_str_new( (uchar *) (bs->str_val), bs->str_len );
|
28
|
+
//}
|
29
|
+
|
30
|
+
|
31
|
+
|
32
|
+
void
|
33
|
+
wrap_BroEventFunc(BroConn *bc, void *data, ...)
|
34
|
+
{
|
35
|
+
va_list argp;
|
36
|
+
int i = 0;
|
37
|
+
int callback_arity = 0;
|
38
|
+
int typemap_arity = 0;
|
39
|
+
VALUE proc;
|
40
|
+
VALUE event_name;
|
41
|
+
VALUE typemap;
|
42
|
+
VALUE input = (VALUE)data;
|
43
|
+
VALUE class_name;
|
44
|
+
VALUE out[15] = {Qnil,Qnil,Qnil,Qnil,Qnil,Qnil,Qnil,Qnil,
|
45
|
+
Qnil,Qnil,Qnil,Qnil,Qnil,Qnil,Qnil};
|
46
|
+
|
47
|
+
if (strcmp("Array",
|
48
|
+
STR2CSTR(rb_funcall(rb_funcall(input, rb_intern("class"), 0), rb_intern("to_s"), 0))) != 0)
|
49
|
+
{
|
50
|
+
printf("There is a problem!\n");
|
51
|
+
return;
|
52
|
+
}
|
53
|
+
|
54
|
+
event_name = rb_funcall(input, rb_intern("at"), 1, INT2NUM(0));
|
55
|
+
typemap = rb_funcall(input, rb_intern("at"), 1, INT2NUM(1));
|
56
|
+
proc = rb_funcall(input, rb_intern("at"), 1, INT2NUM(2));
|
57
|
+
|
58
|
+
callback_arity = NUM2INT(rb_funcall(proc, rb_intern("arity"), 0));
|
59
|
+
typemap_arity = NUM2INT(rb_funcall(typemap, rb_intern("size"), 0));
|
60
|
+
if( callback_arity != typemap_arity ) {
|
61
|
+
printf("There is a problem with the argument definition for either the typemap "
|
62
|
+
"or the callback for the %s event handler\n", STR2CSTR(event_name));
|
63
|
+
}
|
64
|
+
va_start(argp, data);
|
65
|
+
for(i=0 ; i < callback_arity ; i++) {
|
66
|
+
//printf("Loop #%i\n", i);
|
67
|
+
switch (NUM2INT(rb_funcall(typemap, rb_intern("at"), 1, INT2NUM(i))))
|
68
|
+
{
|
69
|
+
case BRO_TYPE_RECORD:
|
70
|
+
//printf("Found a BroRecord in the callback wrapper\n");
|
71
|
+
out[i] = SWIG_NewPointerObj(SWIG_as_voidptr( va_arg(argp, BroRecord *) ), SWIGTYPE_p_bro_record, 0 | 0 );
|
72
|
+
rb_funcall(out[i], rb_intern("from_callback="), 1, event_name);
|
73
|
+
rb_funcall(out[i], rb_intern("arg_num="), 1, INT2NUM(i));
|
74
|
+
break;
|
75
|
+
case BRO_TYPE_PORT:
|
76
|
+
out[i] = SWIG_NewPointerObj(SWIG_as_voidptr( va_arg(argp, BroPort *) ), SWIGTYPE_p_bro_port, 0 | 0 );
|
77
|
+
break;
|
78
|
+
case BRO_TYPE_INT:
|
79
|
+
case BRO_TYPE_ENUM:
|
80
|
+
//printf("Found an integer in the callback wrapper\n");
|
81
|
+
out[i] = INT2NUM( *((int *)(va_arg(argp, int*))) );
|
82
|
+
break;
|
83
|
+
case BRO_TYPE_BOOL:
|
84
|
+
//printf("Found a boolean in the callback wrapper\n");
|
85
|
+
out[i] = *((int *)(va_arg(argp, int*))) ? Qtrue : Qfalse;
|
86
|
+
break;
|
87
|
+
case BRO_TYPE_STRING:
|
88
|
+
1; //for some reason the compiler doesn't like variable defs in the first line
|
89
|
+
//printf("Found a BroString in the callback wrapper\n");
|
90
|
+
BroString *foo_string = va_arg(argp, BroString *);
|
91
|
+
out[i] = rb_str_new( (char*) bro_string_get_data(foo_string), bro_string_get_length(foo_string) );
|
92
|
+
//out[i] = rb_str_new2(foo_string->str_val);
|
93
|
+
break;
|
94
|
+
case BRO_TYPE_TIME:
|
95
|
+
case BRO_TYPE_DOUBLE:
|
96
|
+
case BRO_TYPE_INTERVAL:
|
97
|
+
//printf("Found a double in the callback wrapper\n");
|
98
|
+
out[i] = rb_float_new( *((double *)(va_arg(argp, double *))) );
|
99
|
+
break;
|
100
|
+
case BRO_TYPE_COUNT:
|
101
|
+
case BRO_TYPE_NET:
|
102
|
+
//printf("Found a 32bit unsigned integer in the callback wrapper\n");
|
103
|
+
//uint32 *int_tt_foo = va_arg(argp, uint32 *);
|
104
|
+
//out[i] = UINT2NUM( *int_tt_foo );
|
105
|
+
out[i] = UINT2NUM( *((uint32 *)(va_arg(argp, uint32 *))) );
|
106
|
+
break;
|
107
|
+
case BRO_TYPE_IPADDR:
|
108
|
+
//printf("I found an ip addres... making it a string\n");
|
109
|
+
//output ip addresses as strings that can be unpacked from ruby.
|
110
|
+
out[i] = rb_str_new2( (char *) (va_arg(argp, char *)) );
|
111
|
+
break;
|
112
|
+
default:
|
113
|
+
printf("Invalid type was registered for callback!\n");
|
114
|
+
va_arg(argp, void*); // do this to throw out an item and keep 'i' correct
|
115
|
+
break;
|
116
|
+
}
|
117
|
+
}
|
118
|
+
va_end(argp);
|
119
|
+
|
120
|
+
// Call the ruby proc object finally!
|
121
|
+
rb_funcall2(proc, rb_intern("call"), callback_arity, out);
|
122
|
+
|
123
|
+
bc = NULL;
|
124
|
+
data = NULL;
|
125
|
+
}
|
126
|
+
|
127
|
+
%}
|
128
|
+
|
129
|
+
|
130
|
+
%typemap(in) (BroEventFunc func, void *user_data)
|
131
|
+
{
|
132
|
+
$1 = (BroEventFunc) wrap_BroEventFunc;
|
133
|
+
$2 = (void *)$input;
|
134
|
+
}
|
135
|
+
|
136
|
+
// The equality comparisons in this are a hack and throw
|
137
|
+
// a lot of compiler warnings because this typemap is used for
|
138
|
+
// two different functions that have different numbers of args
|
139
|
+
%typemap(in) (const char *type_name, const void *val)
|
140
|
+
{
|
141
|
+
// Get the ruby class of the incoming data
|
142
|
+
char *class = STR2CSTR(rb_funcall(rb_funcall($input, rb_intern("class"), 0), rb_intern("to_s"), 0));
|
143
|
+
//printf("Received type: %s...", class);
|
144
|
+
if(arg3 == BRO_TYPE_INT || arg2 == BRO_TYPE_INT ||
|
145
|
+
arg3 == BRO_TYPE_ENUM || arg2 == BRO_TYPE_ENUM ||
|
146
|
+
arg3 == BRO_TYPE_BOOL || arg2 == BRO_TYPE_BOOL) {
|
147
|
+
int foo;
|
148
|
+
if(strcmp(class, "TrueClass") == 0 || strcmp(class, "FalseClass") == 0) {
|
149
|
+
//printf("Matched on boolean! Storing value as an integer\n");
|
150
|
+
foo = $input ? 1 : 0;
|
151
|
+
} else {
|
152
|
+
//printf("Matched on Fixnum! Storing value as an int (%i)\n", NUM2INT($input));
|
153
|
+
foo = NUM2INT($input);
|
154
|
+
}
|
155
|
+
$2 = &foo;
|
156
|
+
}
|
157
|
+
else if(arg3 == BRO_TYPE_DOUBLE || arg2 == BRO_TYPE_DOUBLE ||
|
158
|
+
arg3 == BRO_TYPE_TIME || arg2 == BRO_TYPE_TIME ||
|
159
|
+
arg3 == BRO_TYPE_INTERVAL || arg2 == BRO_TYPE_INTERVAL) {
|
160
|
+
//printf("Storing value as a double (%f)\n", rb_num2dbl($input));
|
161
|
+
double foo = rb_num2dbl($input);
|
162
|
+
$2 = &foo;
|
163
|
+
}
|
164
|
+
else if(arg3 == BRO_TYPE_COUNT || arg2 == BRO_TYPE_COUNT ||
|
165
|
+
arg3 == BRO_TYPE_IPADDR || arg2 == BRO_TYPE_IPADDR ||
|
166
|
+
arg3 == BRO_TYPE_NET || arg2 == BRO_TYPE_NET) {
|
167
|
+
//printf("Storing value as a uint32\n");
|
168
|
+
uint32 foo = rb_num2ulong($input);
|
169
|
+
$2 = &foo;
|
170
|
+
}
|
171
|
+
else if(arg3 == BRO_TYPE_STRING || arg2 == BRO_TYPE_STRING) {
|
172
|
+
//printf("Storing value as a BroString\n");
|
173
|
+
BroString foo = to_brostring($input);
|
174
|
+
$2 = &foo;
|
175
|
+
}
|
176
|
+
else if(arg3 == BRO_TYPE_PORT || arg2 == BRO_TYPE_PORT) {
|
177
|
+
//printf("Storing value as a BroPort\n");
|
178
|
+
void *p1 = 0;
|
179
|
+
int res = 0;
|
180
|
+
res = SWIG_ConvertPtr($input, &p1, SWIGTYPE_p_bro_port, 0 | 0 );
|
181
|
+
if (!SWIG_IsOK(res)) {
|
182
|
+
SWIG_exception_fail(SWIG_ArgError(res), "the val was supposed to be a BroPort");
|
183
|
+
}
|
184
|
+
BroPort *output;
|
185
|
+
output = (BroPort *)(p1);
|
186
|
+
$2 = output;
|
187
|
+
}
|
188
|
+
else if(arg3 == BRO_TYPE_SUBNET || arg2 == BRO_TYPE_SUBNET) {
|
189
|
+
//printf("Storing value as a BroSubnet\n");
|
190
|
+
void *p1 = 0;
|
191
|
+
int res = 0;
|
192
|
+
res = SWIG_ConvertPtr($input, &p1, SWIGTYPE_p_bro_subnet, 0 | 0 );
|
193
|
+
if (!SWIG_IsOK(res)) {
|
194
|
+
SWIG_exception_fail(SWIG_ArgError(res), "the val was supposed to be a BroSubnet");
|
195
|
+
}
|
196
|
+
BroSubnet *output = (BroSubnet *) 0 ;
|
197
|
+
output = (BroSubnet *)(p1);
|
198
|
+
$2 = output;
|
199
|
+
}
|
200
|
+
else if(arg3 == BRO_TYPE_RECORD || arg2 == BRO_TYPE_RECORD) {
|
201
|
+
//printf("Storing value as a BroRecord\n");
|
202
|
+
void *p1 = 0;
|
203
|
+
int res = 0;
|
204
|
+
res = SWIG_ConvertPtr($input, &p1, SWIGTYPE_p_bro_record, 0 | 0 );
|
205
|
+
if (!SWIG_IsOK(res)) {
|
206
|
+
SWIG_exception_fail(SWIG_ArgError(res), "the val was supposed to be a BroRecord");
|
207
|
+
}
|
208
|
+
BroRecord *output;
|
209
|
+
output = (BroRecord *)(p1);
|
210
|
+
$2 = output;
|
211
|
+
}
|
212
|
+
else {
|
213
|
+
printf("Couldn't find a type to convert to\n");
|
214
|
+
}
|
215
|
+
// This seems to always be null, so keep it out of the ruby api for now.
|
216
|
+
$1 = NULL;
|
217
|
+
}
|
218
|
+
|
219
|
+
|
220
|
+
%typemap(out) void* bro_conn_data_get {
|
221
|
+
if( strcmp(arg2, "service") == 0 ||
|
222
|
+
strcmp(arg2, "addl") == 0 ||
|
223
|
+
strcmp(arg2, "history") == 0) {
|
224
|
+
//printf("converting to a ruby string...\n");
|
225
|
+
$result = rb_str_new( (char*)bro_string_get_data((BroString*) $1), bro_string_get_length((BroString*) $1) );
|
226
|
+
}
|
227
|
+
else if( strcmp(arg2, "") == 0 ) {
|
228
|
+
|
229
|
+
}
|
230
|
+
else
|
231
|
+
{
|
232
|
+
printf("Couldn't find the correct data type to convert to...\n");
|
233
|
+
$result = Qnil;
|
234
|
+
}
|
235
|
+
}
|
236
|
+
|
237
|
+
%typemap(out) void* bro_record_get_named_val,
|
238
|
+
void* bro_record_get_nth_val {
|
239
|
+
if(arg3 == BRO_TYPE_BOOL) {
|
240
|
+
//printf("Ruby: Getting data matched on boolean\n");
|
241
|
+
int *i = $1;
|
242
|
+
$result = (*i ? Qtrue : Qfalse);
|
243
|
+
}
|
244
|
+
else if(arg3 == BRO_TYPE_INT ||
|
245
|
+
arg3 == BRO_TYPE_ENUM) {
|
246
|
+
//printf("Ruby: Getting data matched on int\n");
|
247
|
+
int *i = $1;
|
248
|
+
$result = INT2NUM(*i);
|
249
|
+
}
|
250
|
+
else if(arg3 == BRO_TYPE_TIME ||
|
251
|
+
arg3 == BRO_TYPE_DOUBLE ||
|
252
|
+
arg3 == BRO_TYPE_INTERVAL) {
|
253
|
+
//printf("Ruby: Getting data matched on time\n");
|
254
|
+
double *i = $1;
|
255
|
+
$result = rb_float_new(*i);
|
256
|
+
}
|
257
|
+
else if(arg3 == BRO_TYPE_STRING) {
|
258
|
+
BroString *i = $1;
|
259
|
+
$result = rb_str_new((char*)i->str_val, i->str_len);
|
260
|
+
}
|
261
|
+
else if(arg3 == BRO_TYPE_COUNT) {
|
262
|
+
//printf("Ruby: Getting data matched on uint32\n");
|
263
|
+
uint32 *i = $1;
|
264
|
+
$result = ULONG2NUM(*i);
|
265
|
+
}
|
266
|
+
else if(arg3 == BRO_TYPE_IPADDR ||
|
267
|
+
arg3 == BRO_TYPE_NET) {
|
268
|
+
//printf("I found an ip address... making it a network byte ordered string\n");
|
269
|
+
$result = rb_str_new2( (char *) $1);
|
270
|
+
}
|
271
|
+
else if(arg3 == BRO_TYPE_RECORD) {
|
272
|
+
//printf("Ruby: Getting data matched as a BroRecord\n");
|
273
|
+
$result = SWIG_NewPointerObj(SWIG_as_voidptr( (BroRecord *) $1 ), SWIGTYPE_p_bro_record, 0);
|
274
|
+
}
|
275
|
+
else if(arg3 == BRO_TYPE_PORT) {
|
276
|
+
$result = SWIG_NewPointerObj(SWIG_as_voidptr( (BroPort *) $1 ), SWIGTYPE_p_bro_port, 0);
|
277
|
+
}
|
278
|
+
else {
|
279
|
+
printf("No type recognized when getting value\n");
|
280
|
+
}
|
281
|
+
}
|
282
|
+
|
283
|
+
|
284
|
+
|
285
|
+
// When methods output an integer, it's usually boolean, make it so.
|
286
|
+
%typemap(out) int bro_conn_connect,
|
287
|
+
int bro_conn_alive,
|
288
|
+
int bro_conn_delete,
|
289
|
+
int bro_conn_process_input,
|
290
|
+
int bro_event_add_val,
|
291
|
+
int bro_event_set_val,
|
292
|
+
int bro_event_send,
|
293
|
+
int bro_record_set_nth_val,
|
294
|
+
int bro_record_set_named_val,
|
295
|
+
int bro_packet_send "$result = $1 ? Qtrue:Qfalse;"
|
296
|
+
|
297
|
+
// Allow "true" and "false" for setting debug vars
|
298
|
+
%typemap(varin) int bro_debug_calltrace,
|
299
|
+
int bro_debug_messages "$1 = $input ? 1:0;"
|
300
|
+
|
301
|
+
%typemap(in) uchar * "$1 = (uchar*)STR2CSTR($input);"
|
302
|
+
%typemap(out) uchar * "$result = rb_str_new2((char*)$1);"
|
303
|
+
|
304
|
+
/* Convert Ruby string to BroString (i'm not sure BroString's are ever
|
305
|
+
used in an applicable situation) */
|
306
|
+
/*%typemap(in) BroString "$1 = to_BroString($input);";*/
|
307
|
+
|
308
|
+
%predicate bro_conn_alive(const BroConn *bc);
|
309
|
+
|
310
|
+
BroString to_brostring(VALUE obj);
|
311
|
+
|
312
|
+
//%freefunc BroEvent "bro_event_free";
|
313
|
+
//%freefunc BroRecord "bro_record_free";
|
314
|
+
//%freefunc BroString "bro_string_free";
|
315
|
+
//// I may not want to do the following line...
|
316
|
+
//%freefunc BroConn "bro_conn_delete";
|
317
|
+
|
318
|
+
//%apply SWIGTYPE *DISOWN { BroEvent *ev };
|
319
|
+
|
320
|
+
|
321
|
+
|
322
|
+
extern int bro_debug_calltrace;
|
323
|
+
extern int bro_debug_messages;
|
324
|
+
|
325
|
+
#define BRO_TYPE_BOOL 1
|
326
|
+
#define BRO_TYPE_INT 2
|
327
|
+
#define BRO_TYPE_COUNT 3
|
328
|
+
#define BRO_TYPE_COUNTER 4
|
329
|
+
#define BRO_TYPE_DOUBLE 5
|
330
|
+
#define BRO_TYPE_TIME 6
|
331
|
+
#define BRO_TYPE_INTERVAL 7
|
332
|
+
#define BRO_TYPE_STRING 8
|
333
|
+
#define BRO_TYPE_PATTERN 9
|
334
|
+
#define BRO_TYPE_ENUM 10
|
335
|
+
#define BRO_TYPE_TIMER 11
|
336
|
+
#define BRO_TYPE_PORT 12
|
337
|
+
#define BRO_TYPE_IPADDR 13
|
338
|
+
#define BRO_TYPE_NET 14
|
339
|
+
#define BRO_TYPE_SUBNET 15
|
340
|
+
#define BRO_TYPE_ANY 16
|
341
|
+
#define BRO_TYPE_TABLE 17
|
342
|
+
#define BRO_TYPE_UNION 18
|
343
|
+
#define BRO_TYPE_RECORD 19
|
344
|
+
#define BRO_TYPE_LIST 20
|
345
|
+
#define BRO_TYPE_FUNC 21
|
346
|
+
#define BRO_TYPE_FILE 22
|
347
|
+
#define BRO_TYPE_VECTOR 23
|
348
|
+
#define BRO_TYPE_ERROR 24
|
349
|
+
#define BRO_TYPE_PACKET 25 /* CAUTION -- not defined in Bro! */
|
350
|
+
#define BRO_TYPE_MAX 26
|
351
|
+
|
352
|
+
|
353
|
+
#define BRO_CFLAG_NONE 0
|
354
|
+
#define BRO_CFLAG_RECONNECT (1 << 0) /* Attempt transparent reconnects */
|
355
|
+
#define BRO_CFLAG_ALWAYS_QUEUE (1 << 1) /* Queue events sent while disconnected */
|
356
|
+
#define BRO_CFLAG_SHAREABLE (1 << 2) /* Allow sharing handle across threads/procs */
|
357
|
+
#define BRO_CFLAG_DONTCACHE (1 << 3) /* Ask peer not to use I/O cache */
|
358
|
+
|
359
|
+
typedef unsigned int uint32;
|
360
|
+
typedef unsigned short uint16;
|
361
|
+
typedef unsigned char uchar;
|
362
|
+
|
363
|
+
typedef struct bro_conn BroConn;
|
364
|
+
typedef struct bro_event BroEvent;
|
365
|
+
typedef struct bro_buf BroBuf;
|
366
|
+
typedef struct bro_record BroRecord;
|
367
|
+
|
368
|
+
typedef void (*BroEventFunc) (BroConn *bc, ...);
|
369
|
+
|
370
|
+
typedef struct bro_string {
|
371
|
+
uint32 str_len;
|
372
|
+
uchar *str_val;
|
373
|
+
} BroString;
|
374
|
+
|
375
|
+
typedef struct bro_port {
|
376
|
+
uint16 port_num; /* port number in host byte order */
|
377
|
+
int port_proto; /* IPPROTO_xxx */
|
378
|
+
} BroPort;
|
379
|
+
|
380
|
+
typedef struct bro_subnet
|
381
|
+
{
|
382
|
+
uint32 sn_net; /* IP address in network byte order */
|
383
|
+
uint32 sn_width; /* Length of prefix to consider. */
|
384
|
+
} BroSubnet;
|
385
|
+
|
386
|
+
BroConn* bro_conn_new_str(const char *hostname,
|
387
|
+
int flags);
|
388
|
+
|
389
|
+
int bro_conn_connect (BroConn *bc);
|
390
|
+
int bro_conn_process_input (BroConn *bc);
|
391
|
+
int bro_conn_delete (BroConn *bc);
|
392
|
+
int bro_conn_alive (const BroConn *bc);
|
393
|
+
void* bro_conn_data_get (BroConn *bc, const char *key);
|
394
|
+
int bro_conn_get_fd (BroConn *bc);
|
395
|
+
|
396
|
+
int bro_conf_get_int(const char *val_name, int *OUTPUT);
|
397
|
+
int bro_conf_get_dbl(const char *val_name, double *OUTPUT);
|
398
|
+
const char* bro_conf_get_str(const char *val_name);
|
399
|
+
|
400
|
+
|
401
|
+
void bro_string_init (BroString *bs);
|
402
|
+
int bro_string_set (BroString *bs,
|
403
|
+
const char *s);
|
404
|
+
int bro_string_set_data (BroString *bs,
|
405
|
+
const uchar *data,
|
406
|
+
int data_len);
|
407
|
+
const uchar* bro_string_get_data (const BroString *bs);
|
408
|
+
uint32 bro_string_get_length (const BroString *bs);
|
409
|
+
BroString* bro_string_copy (BroString *bs);
|
410
|
+
void bro_string_cleanup (BroString *bs);
|
411
|
+
void bro_string_free (BroString *bs);
|
412
|
+
|
413
|
+
|
414
|
+
|
415
|
+
BroRecord* bro_record_new(void);
|
416
|
+
int bro_record_add_val(BroRecord *rec,
|
417
|
+
const char *name,
|
418
|
+
int type,
|
419
|
+
const char *type_name,
|
420
|
+
const void *val);
|
421
|
+
void* bro_record_get_named_val(BroRecord *rec,
|
422
|
+
const char *name,
|
423
|
+
int type);
|
424
|
+
void* bro_record_get_nth_val(BroRecord *rec,
|
425
|
+
int num,
|
426
|
+
int type);
|
427
|
+
int bro_record_set_nth_val (BroRecord *rec,
|
428
|
+
int num,
|
429
|
+
int type,
|
430
|
+
const char *type_name,
|
431
|
+
const void *val);
|
432
|
+
int bro_record_set_named_val (BroRecord *rec,
|
433
|
+
const char *name,
|
434
|
+
int type,
|
435
|
+
const char *type_name,
|
436
|
+
const void *val);
|
437
|
+
void bro_record_free(BroRecord *rec);
|
438
|
+
|
439
|
+
BroEvent *bro_event_new(const char *event_name);
|
440
|
+
|
441
|
+
int bro_event_add_val (BroEvent *be,
|
442
|
+
int type,
|
443
|
+
const char *type_name,
|
444
|
+
const void *val);
|
445
|
+
|
446
|
+
void bro_event_registry_add (BroConn *bc,
|
447
|
+
const char *event_name,
|
448
|
+
BroEventFunc func,
|
449
|
+
void *user_data);
|
450
|
+
|
451
|
+
void bro_event_registry_request (BroConn *bc);
|
452
|
+
int bro_event_queue_length (BroConn *bc);
|
453
|
+
int bro_event_queue_flush (BroConn *bc);
|
454
|
+
|
455
|
+
int bro_event_send(BroConn *bc,
|
456
|
+
BroEvent *be);
|
457
|
+
|
458
|
+
void bro_event_free(BroEvent *be);
|
459
|
+
|
460
|
+
double bro_util_current_time(void);
|
461
|
+
|
462
|
+
|
463
|
+
|