59#define trap_ctx_t void
88#define TRAP_E_TIMEOUT 1
89#define TRAP_E_INITIALIZED 10
90#define TRAP_E_BADPARAMS 11
91#define TRAP_E_BAD_IFC_INDEX 12
92#define TRAP_E_BAD_FPARAMS 13
93#define TRAP_E_IO_ERROR 14
94#define TRAP_E_TERMINATED 15
95#define TRAP_E_NOT_SELECTED 16
96#define TRAP_E_BAD_CERT 17
98#define TRAP_E_FIELDS_MISMATCH 21
99#define TRAP_E_FIELDS_SUBSET 22
100#define TRAP_E_FORMAT_CHANGED 23
101#define TRAP_E_FORMAT_MISMATCH 24
102#define TRAP_E_NEGOTIATION_FAILED 25
103#define TRAP_E_NOT_INITIALIZED 254
104#define TRAP_E_MEMORY 255
119#define TRAP_NO_WAIT 0
130#define TRAP_HALFWAIT -2
132#define TRAP_TIMEOUT_STR(t) (t==TRAP_WAIT?"TRAP_WAIT":(t==TRAP_NO_WAIT?"TRAP_NO_WAIT":(t==TRAP_HALFWAIT?"TRAP_HALFWAIT":"")))
134#define TRAP_NO_AUTO_FLUSH (-1l)
160#define TRAP_IFC_DELIMITER ','
165#define TRAP_IFC_PARAM_DELIMITER ':'
171#define TRAP_IFC_TYPE_GENERATOR 'g'
172#define TRAP_IFC_TYPE_BLACKHOLE 'b'
173#define TRAP_IFC_TYPE_TCPIP 't'
174#define TRAP_IFC_TYPE_TLS 'T'
175#define TRAP_IFC_TYPE_UNIX 'u'
176#define TRAP_IFC_TYPE_SERVICE 's'
177#define TRAP_IFC_TYPE_FILE 'f'
205#ifndef TRAP_IFC_MESSAGEQ_SIZE
206#define TRAP_IFC_MESSAGEQ_SIZE 100000
513int trap_send_data(
unsigned int ifcidx,
const void *data, uint16_t size,
int timeout);
530int trap_recv(uint32_t ifcidx,
const void **data, uint16_t *size);
545int trap_send(uint32_t ifcidx,
const void *data, uint16_t size);
609int trap_ifcctl(int8_t type, uint32_t ifcidx, int32_t request, ... );
674trap_ctx_t *
trap_ctx_init3(
const char *name,
const char *description, int8_t i_ifcs, int8_t o_ifcs,
const char *ifc_spec,
const char *service_ifcname);
872#define TRAP_DEFAULT_SIGNAL_HANDLER(stop_cmd) \
873 void trap_default_signal_handler(int signal)\
875 if (signal == SIGTERM || signal == SIGINT) { \
887#define TRAP_REGISTER_DEFAULT_SIGNAL_HANDLER() \
889 if (trap_get_verbose_level() >= 1)\
890 printf("Setting signal handler for SIGINT and SIGTERM using 'sigaction' function.\n");\
891 struct sigaction act;\
893 act.sa_handler = trap_default_signal_handler;\
896 sigemptyset(&act.sa_mask);\
897 sigaddset(&act.sa_mask, SIGTERM);\
898 sigaddset(&act.sa_mask, SIGINT);\
900 sigaction(SIGTERM, &act, NULL);\
901 sigaction(SIGINT, &act, NULL);\
904#define TRAP_REGISTER_DEFAULT_SIGNAL_HANDLER() \
906 if (trap_get_verbose_level() >= 1)\
907 printf("Setting signal handler for SIGINT and SIGTERM using 'signal' function.\n");\
908 signal(SIGTERM, trap_default_signal_handler);\
909 signal(SIGINT, trap_default_signal_handler);\
925#define TRAP_DEFAULT_INITIALIZATION(argc, argv, module_info) \
927 trap_ifc_spec_t ifc_spec;\
928 int ret = trap_parse_params(&argc, argv, &ifc_spec);\
929 if (ret != TRAP_E_OK) {\
930 if (ret == TRAP_E_HELP) {\
931 trap_print_help(&module_info);\
932 FREE_MODULE_INFO_STRUCT(MODULE_BASIC_INFO, MODULE_PARAMS) \
935 trap_free_ifc_spec(ifc_spec);\
936 fprintf(stderr, "ERROR in parsing of parameters for TRAP: %s\n", trap_last_error_msg);\
937 FREE_MODULE_INFO_STRUCT(MODULE_BASIC_INFO, MODULE_PARAMS) \
940 ret = trap_init(&module_info, ifc_spec);\
941 if (ret != TRAP_E_OK) {\
942 trap_free_ifc_spec(ifc_spec);\
943 fprintf(stderr, "ERROR in TRAP initialization: %s\n", trap_last_error_msg);\
944 FREE_MODULE_INFO_STRUCT(MODULE_BASIC_INFO, MODULE_PARAMS) \
947 trap_free_ifc_spec(ifc_spec);\
954#define TRAP_DEFAULT_FINALIZATION() \
964#define TRAP_DEFAULT_GET_DATA_ERROR_HANDLING(ret_code, timeout_cmd, error_cmd) \
965 if ((ret_code) != TRAP_E_OK) {\
966 if ((ret_code) == TRAP_E_TIMEOUT) {\
968 } else if ((ret_code) == TRAP_E_TERMINATED) {\
970 } else if (ret_code == TRAP_E_FORMAT_CHANGED) { \
973 } else if (ret_code == TRAP_E_FORMAT_MISMATCH) { \
974 fprintf(stderr, "trap_recv() error: output and input interfaces data formats or data specifiers mismatch.\n"); \
976 } else if (ret_code == TRAP_E_NEGOTIATION_FAILED) { \
977 fprintf(stderr, "trap_recv() error: interface negotiation failed (caused by invalid reply from a remote module, corrupted file or an unknown error).\n"); \
980 fprintf(stderr, "Error: trap_recv() returned %i (%s)\n", (ret_code), trap_last_error_msg);\
991#define TRAP_DEFAULT_RECV_ERROR_HANDLING(ret_code, timeout_cmd, error_cmd) \
992 if ((ret_code) != TRAP_E_OK) {\
993 if ((ret_code) == TRAP_E_TIMEOUT) {\
995 } else if ((ret_code) == TRAP_E_TERMINATED) {\
997 } else if (ret_code == TRAP_E_FORMAT_CHANGED) { \
1000 } else if (ret_code == TRAP_E_FORMAT_MISMATCH) { \
1001 fprintf(stderr, "trap_recv() error: output and input interfaces data formats or data specifiers mismatch.\n"); \
1003 } else if (ret_code == TRAP_E_NEGOTIATION_FAILED) { \
1004 fprintf(stderr, "trap_recv() error: interface negotiation failed (caused by invalid reply from a remote module, corrupted file or an unknown error).\n"); \
1007 fprintf(stderr, "Error: trap_recv() returned %i (%s)\n", (ret_code), trap_last_error_msg);\
1021#define TRAP_DEFAULT_SEND_DATA_ERROR_HANDLING(ret_code, timeout_cmd, error_cmd) \
1022 if ((ret_code) != TRAP_E_OK) {\
1023 if ((ret_code) == TRAP_E_TIMEOUT) {\
1025 } else if ((ret_code) == TRAP_E_TERMINATED) {\
1028 fprintf(stderr, "Error: trap_send_data() returned %i (%s)\n", (ret_code), trap_last_error_msg);\
1040#define TRAP_DEFAULT_SEND_ERROR_HANDLING(ret_code, timeout_cmd, error_cmd) \
1041 if ((ret_code) != TRAP_E_OK) {\
1042 if ((ret_code) == TRAP_E_TIMEOUT) {\
1044 } else if ((ret_code) == TRAP_E_TERMINATED) {\
1047 fprintf(stderr, "Error: trap_send() returned %i (%s)\n", (ret_code), trap_last_error_msg);\
int trap_get_in_ifc_state(uint32_t ifc_idx)
int trap_ctx_cmp_data_fmt(const char *sender_ifc_data_fmt, const char *receiver_ifc_data_fmt)
const char * trap_get_type_and_name_from_string(const char *source, const char **name, const char **type, int *length_name, int *length_type)
void * trap_get_global_ctx()
const char trap_git_version[]
int trap_check_buffer_content(void *buffer, uint32_t buffer_size)
Check content of buffer, iterate over message headers.
const char trap_version[]
struct trap_ifc_spec_s trap_ifc_spec_t
int trap_parse_params(int *argc, char **argv, trap_ifc_spec_t *ifc_spec)
char * trap_default_socket_path_format
char * trap_get_param_by_delimiter(const char *source, char **dest, const char delimiter)
Splitter of params string. Cut the first param, copy it into dest and returns pointer to the start of...
@ TRAPCTL_BUFFERSWITCH
Enable/disable buffering - could be dangerous on input interface!!! expects char argument with value ...
@ TRAPCTL_AUTOFLUSH_TIMEOUT
Set timeout of automatic buffer flushing for interface, expects uint64_t argument with number of micr...
@ TRAPCTL_SETTIMEOUT
Set interface timeout (int32_t): in microseconds for non-blocking mode; timeout can be also: TRAP_WAI...
int trap_ctx_recv(trap_ctx_t *ctx, uint32_t ifc, const void **data, uint16_t *size)
Read data from input interface.
void trap_ctx_create_ifc_dump(trap_ctx_t *ctx, const char *path)
Create dump files.
int trap_ctx_get_last_error(trap_ctx_t *ctx)
Get last result code from libtrap context.
trap_ctx_t * trap_ctx_init2(trap_module_info_t *module_info, trap_ifc_spec_t ifc_spec, const char *service_ifcname)
Initialize and return the context of libtrap.
int trap_ctx_finalize(trap_ctx_t **ctx)
Terminate libtrap context and free resources.
int trap_ctx_vifcctl(trap_ctx_t *ctx, int8_t type, uint32_t ifcidx, int32_t request, va_list ap)
Control TRAP interface.
int trap_ctx_ifcctl(trap_ctx_t *ctx, int8_t type, uint32_t ifcidx, int32_t request,...)
Control TRAP interface.
const char * trap_ctx_get_last_error_msg(trap_ctx_t *ctx)
Get last (error) message from libtrap context.
int trap_ctx_terminate(trap_ctx_t *ctx)
Terminate libtrap context.
void trap_ctx_set_verbose_level(trap_ctx_t *ctx, int level)
Set verbosity level of library functions.
int trap_ctx_send(trap_ctx_t *ctx, unsigned int ifc, const void *data, uint16_t size)
Send data via output interface.
void trap_ctx_send_flush(trap_ctx_t *ctx, uint32_t ifc)
Force flush of buffer.
trap_ctx_t * trap_ctx_init3(const char *name, const char *description, int8_t i_ifcs, int8_t o_ifcs, const char *ifc_spec, const char *service_ifcname)
Initialize and return the context of libtrap.
int trap_ctx_get_client_count(trap_ctx_t *ctx, uint32_t ifcidx)
Get number of connected clients.
trap_ctx_t * trap_ctx_init(trap_module_info_t *module_info, trap_ifc_spec_t ifc_spec)
Initialize and return the context of libtrap.
int trap_ctx_get_verbose_level(trap_ctx_t *ctx)
Get verbosity level.
char trap_ifc_type_supported[]
@ TRAPIFC_OUTPUT
interface is used for sending data out of module
@ TRAPIFC_INPUT
interface acts as source of data for module
int trap_send(uint32_t ifcidx, const void *data, uint16_t size)
Send data via output interface.
const char * trap_last_error_msg
Human-readable message about last error.
void trap_send_flush(uint32_t ifc)
Force flush of buffer.
void trap_print_ifc_spec_help()
int trap_last_error
Code of last error (one of the codes above)
int trap_ifcctl(int8_t type, uint32_t ifcidx, int32_t request,...)
Control TRAP interface.
void trap_set_help_section(int level)
int trap_init(trap_module_info_t *module_info, trap_ifc_spec_t ifc_spec)
void trap_set_verbose_level(int level)
int trap_free_ifc_spec(trap_ifc_spec_t ifc_spec)
void trap_print_help(const trap_module_info_t *module_info)
int trap_send_data(unsigned int ifcidx, const void *data, uint16_t size, int timeout)
int trap_recv(uint32_t ifcidx, const void **data, uint16_t *size)
Receive data from input interface.
int trap_get_verbose_level()
int trap_ctx_set_required_fmt(trap_ctx_t *ctx, uint32_t in_ifc_idx, uint8_t data_type,...)
int trap_ctx_get_in_ifc_state(trap_ctx_t *ctx, uint32_t ifc_idx)
int trap_get_data_fmt(uint8_t ifc_dir, uint32_t ifc_idx, uint8_t *data_type, const char **spec)
int trap_set_required_fmt(uint32_t in_ifc_idx, uint8_t data_type,...)
void trap_set_data_fmt(uint32_t out_ifc_idx, uint8_t data_type,...)
int trap_ctx_get_data_fmt(trap_ctx_t *ctx, uint8_t ifc_dir, uint32_t ifc_idx, uint8_t *data_type, const char **spec)
void trap_ctx_vset_data_fmt(trap_ctx_t *ctx, uint32_t out_ifc_idx, uint8_t data_type, va_list ap)
void trap_ctx_set_data_fmt(trap_ctx_t *ctx, uint32_t out_ifc_idx, uint8_t data_type,...)
int trap_ctx_vset_required_fmt(trap_ctx_t *ctx, uint32_t in_ifc_idx, uint8_t data_type, va_list ap)
int input_ifc_negotiation(void *ifc_priv_data, char ifc_type)
int output_ifc_negotiation(void *ifc_priv_data, char ifc_type, int client_sd, void *ssl)
Structures containing information about Nemea modules and macros for initialization and release of th...