nmsg  1.0.0
io.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008-2019 by Farsight Security, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef NMSG_IO_H
18 #define NMSG_IO_H
19 
20 #include <nmsg/input.h>
21 #include <nmsg/output.h>
22 
47 typedef enum {
48  nmsg_io_close_type_eof, /*%< end of file */
49  nmsg_io_close_type_count, /*%< payload count reached */
50  nmsg_io_close_type_interval /*%< interval elapsed */
52 
56 typedef enum {
57  nmsg_io_io_type_input, /*%< close event input */
58  nmsg_io_io_type_output /*%< close event output */
60 
64 typedef enum {
65  nmsg_io_output_mode_stripe, /*%< stripe payloads across output */
66  nmsg_io_output_mode_mirror /*%< mirror payloads across output */
68 
105  union {
106  nmsg_input_t *input; /*%< pointer to input stream */
107  nmsg_output_t *output; /*%< pointer to output stream */
108  };
109  union {
110  nmsg_input_type input_type; /*%< type of 'input' field */
111  nmsg_output_type output_type; /*%< type of 'output' field */
112  };
113  nmsg_io_t io; /*%< this nmsg_io loop */
114  nmsg_io_io_type io_type; /*%< whether 'input' or 'output' */
115  nmsg_io_close_type close_type; /*%< why the stream was closed */
116  void *user; /*%< caller-provided user pointer */
117 };
118 
124 typedef void (*nmsg_io_close_fp)(struct nmsg_io_close_event *ce);
125 
129 typedef void (*nmsg_io_user_fp)(unsigned threadno, void *user);
130 
136 nmsg_io_t
138 
179 nmsg_res
180 nmsg_io_add_filter(nmsg_io_t io, nmsg_filter_message_fp fp, void *data);
181 
204 nmsg_res
205 nmsg_io_add_filter_module(nmsg_io_t io, const char *name,
206  const void *param, const size_t len_param);
207 
221 nmsg_res
222 nmsg_io_add_input(nmsg_io_t io, nmsg_input_t input, void *user);
223 
242 nmsg_res
243 nmsg_io_add_input_channel(nmsg_io_t io, const char *chan, void *user);
244 
260 nmsg_res
261 nmsg_io_add_input_zmq_channel(nmsg_io_t io, void *zmq_ctx, const char *chan, void *user);
262 
282 nmsg_res
283 nmsg_io_add_input_sockspec(nmsg_io_t io, const char *sockspec, void *user);
284 
298 nmsg_res
299 nmsg_io_add_input_fname(nmsg_io_t io, const char *fname, void *user);
300 
314 nmsg_res
315 nmsg_io_add_output(nmsg_io_t io, nmsg_output_t output, void *user);
316 
335 nmsg_res
336 nmsg_io_loop(nmsg_io_t io);
337 
348 void
350 
356 void
357 nmsg_io_destroy(nmsg_io_t *io);
358 
364 unsigned
366 
372 unsigned
374 
387 void
389 
400 void
401 nmsg_io_set_atstart_fp(nmsg_io_t io, nmsg_io_user_fp user_fp, void *user);
402 
413 void
414 nmsg_io_set_atexit_fp(nmsg_io_t io, nmsg_io_user_fp user_fp, void *user);
415 
433 void
434 nmsg_io_set_count(nmsg_io_t io, unsigned count);
435 
444 void
445 nmsg_io_set_debug(nmsg_io_t io, int debug);
446 
461 void
463 
478 void
479 nmsg_io_set_interval(nmsg_io_t io, unsigned interval);
480 
490 void
491 nmsg_io_set_interval_randomized(nmsg_io_t io, bool randomized);
492 
506 void
508 
526 nmsg_res
527 nmsg_io_get_stats(nmsg_io_t io, uint64_t *sum_in, uint64_t *sum_out, uint64_t *container_recvs, uint64_t *container_drops);
528 
529 
530 #endif /* NMSG_IO_H */
nmsg_res(* nmsg_filter_message_fp)(nmsg_message_t *msg, void *user, nmsg_filter_message_verdict *vres)
Function pointer type for a function that performs message filtering.
Definition: filter.h:72
nmsg_filter_message_verdict
Definition: filter.h:24
Convert input streams to nmsg format.
nmsg_input_type
An enum identifying the underlying implementation of an nmsg_input_t object.
Definition: input.h:54
void nmsg_io_set_atstart_fp(nmsg_io_t io, nmsg_io_user_fp user_fp, void *user)
Set a user-specified function to be called in each thread after the thread starts.
nmsg_res nmsg_io_get_stats(nmsg_io_t io, uint64_t *sum_in, uint64_t *sum_out, uint64_t *container_recvs, uint64_t *container_drops)
Get counters of input and output payloads and containers received and dropped since the start of nmsg...
void nmsg_io_set_interval_randomized(nmsg_io_t io, bool randomized)
Configure the nmsg_io_t object to randomize the initial second within the interval where it closes in...
nmsg_res nmsg_io_add_filter_module(nmsg_io_t io, const char *name, const void *param, const size_t len_param)
Add a filter module to the filter chain.
nmsg_res nmsg_io_loop(nmsg_io_t io)
Begin processing the data specified by the configured inputs and outputs.
void nmsg_io_set_atexit_fp(nmsg_io_t io, nmsg_io_user_fp user_fp, void *user)
Set a user-specified function to be called in each thread before the thread exits.
void nmsg_io_set_filter_policy(nmsg_io_t io, const nmsg_filter_message_verdict policy)
Set the filter policy for the nmsg_io_t object's filter chain.
void nmsg_io_breakloop(nmsg_io_t io)
Force a currently executing nmsg_io_loop() to stop looping and return.
nmsg_res nmsg_io_add_filter(nmsg_io_t io, nmsg_filter_message_fp fp, void *data)
Add a user-specified filter function to the filter chain.
nmsg_res nmsg_io_add_output(nmsg_io_t io, nmsg_output_t output, void *user)
Add an nmsg output to an nmsg_io_t object.
void nmsg_io_set_interval(nmsg_io_t io, unsigned interval)
Configure the nmsg_io_t object to close inputs periodically, every #interval seconds.
void(* nmsg_io_user_fp)(unsigned threadno, void *user)
Optional user-specified function to be run at thread start or thread stop.
Definition: io.h:129
nmsg_res nmsg_io_add_input_zmq_channel(nmsg_io_t io, void *zmq_ctx, const char *chan, void *user)
Add an nmsg ZMQ input channel to an nmsg_io_t object.
nmsg_io_io_type
Type of the stream associated with a close event.
Definition: io.h:56
@ nmsg_io_io_type_output
close event output
Definition: io.h:58
@ nmsg_io_io_type_input
close event input
Definition: io.h:57
nmsg_io_close_type
Type of a close event notification.
Definition: io.h:47
@ nmsg_io_close_type_interval
interval elapsed
Definition: io.h:50
@ nmsg_io_close_type_count
payload count reached
Definition: io.h:49
@ nmsg_io_close_type_eof
end of file
Definition: io.h:48
void nmsg_io_set_count(nmsg_io_t io, unsigned count)
Configure the nmsg_io_t object to close inputs after processing a certain non-zero number of payloads...
void nmsg_io_destroy(nmsg_io_t *io)
Deallocate the resources associated with an nmsg_io_t object.
nmsg_res nmsg_io_add_input_fname(nmsg_io_t io, const char *fname, void *user)
Add an NMSG file to an nmsg_io_t object.
unsigned nmsg_io_get_num_outputs(nmsg_io_t io)
Get the number of outputs bound to the nmsg_io_t object.
void nmsg_io_set_close_fp(nmsg_io_t io, nmsg_io_close_fp close_fp)
Set the close event notification function associated with an nmsg_io_t object.
void(* nmsg_io_close_fp)(struct nmsg_io_close_event *ce)
Function for handling close event notifications.
Definition: io.h:124
nmsg_io_t nmsg_io_init(void)
Initialize a new nmsg_io_t object.
nmsg_res nmsg_io_add_input_sockspec(nmsg_io_t io, const char *sockspec, void *user)
Add an nmsg input sockspec to an nmsg_io_t object.
void nmsg_io_set_output_mode(nmsg_io_t io, nmsg_io_output_mode output_mode)
Set the output mode behavior for an nmsg_io_t object.
void nmsg_io_set_debug(nmsg_io_t io, int debug)
Set the debug level for an nmsg_io_t object.
nmsg_res nmsg_io_add_input_channel(nmsg_io_t io, const char *chan, void *user)
Add an nmsg input channel to an nmsg_io_t object.
nmsg_io_output_mode
Output behavior when multiple outputs are present.
Definition: io.h:64
@ nmsg_io_output_mode_mirror
mirror payloads across output
Definition: io.h:66
@ nmsg_io_output_mode_stripe
stripe payloads across output
Definition: io.h:65
nmsg_res nmsg_io_add_input(nmsg_io_t io, nmsg_input_t input, void *user)
Add an nmsg input to an nmsg_io_t object.
unsigned nmsg_io_get_num_inputs(nmsg_io_t io)
Get the number of inputs bound to the nmsg_io_t object.
Write nmsg containers to output streams.
nmsg_output_type
An enum identifying the underlying implementation of an nmsg_output_t object.
Definition: output.h:38
nmsg_res
nmsg result code
Definition: res.h:25
Structure for passing information about a close event between the nmsg_io processing loop and the ori...
Definition: io.h:104
nmsg_output_type output_type
type of 'output' field
Definition: io.h:111
void * user
caller-provided user pointer
Definition: io.h:116
nmsg_io_t io
this nmsg_io loop
Definition: io.h:113
nmsg_input_type input_type
type of 'input' field
Definition: io.h:110
nmsg_input_t * input
pointer to input stream
Definition: io.h:106
nmsg_output_t * output
pointer to output stream
Definition: io.h:107
nmsg_io_close_type close_type
why the stream was closed
Definition: io.h:115
nmsg_io_io_type io_type
whether 'input' or 'output'
Definition: io.h:114