58 #include <semaphore.h>    61 #include <sys/socket.h>    62 #include <arpa/inet.h>    63 #include <sys/ioctl.h>    69 #include "../include/libtrap/trap.h"    81 #  include <openssl/ssl.h>    82 #  include <openssl/err.h>   130 #define ifcdir2str(type) (((type) == TRAPIFC_OUTPUT) ? "Output" : "Input")   143    if ((getuid() != geteuid()) || (getgid() != getegid())) {
   158    const char *e = getenv(
"TRAP_SOCKET_DIR");
   166    SSL_load_error_strings();
   167    OpenSSL_add_ssl_algorithms();
   184 trap_module_info_t *
trap_create_module_info(
const char *mname, 
const char *mdesc, int8_t i_ifcs, int8_t o_ifcs, uint16_t param_count)
   186    trap_module_info_t *m = NULL;
   188    m = calloc(1, 
sizeof(trap_module_info_t));
   190       m->params = calloc(param_count + 1, 
sizeof(trap_module_info_parameter_t *));
   191       if (m->params == NULL) {
   197    ALLOCATE_BASIC_INFO_2(m, mname, mdesc, i_ifcs, o_ifcs);
   203 int trap_update_module_param(trap_module_info_t *m, uint16_t param_id, 
char shortopt, 
const char *longopt, 
const char *desc, 
int req_arg, 
const char *arg_type)
   205    ALLOCATE_PARAM_ITEMS_2(m, param_id, shortopt, longopt, desc, req_arg, arg_type)
   224    uint32_t offset, check_mess_counter = 0;
   225    uint16_t *check_mess_header;
   227    void *check_mess_pointer;
   228    for (offset = 0, check_mess_header = check_mess_pointer = buffer;
   230       check_mess_counter++;
   232       offset += 
sizeof(*check_mess_header) + (*check_mess_header);
   233       check_mess_pointer += 
sizeof(*check_mess_header) + (*check_mess_header);
   234       check_mess_header = (uint16_t *) check_mess_pointer;
   236    if (offset != buffer_size) {
   258    pthread_mutex_lock(&ifc->
ifc_mtx);
   261       uint32_t buffer_size_tmp = 0;
   264       result = ifc->
recv(ifc->
priv, ifc->
buffer, &buffer_size_tmp, timeout);
   270 #ifdef BUFFERING_CHECK_HEADERS   285       uint32_t msg_size = (*size) + 
sizeof(*size);
   292          VERBOSE(
CL_WARNING, 
"Attempt to read: %" PRIu64 
" header bytes, %" PRIu16 
" data bytes. However, only %" PRIu32 
" bytes remain.", 
sizeof(*size), *size, ifc->
buffer_unread_bytes);
   311    pthread_mutex_unlock(&ifc->
ifc_mtx);
   341    uint32_t i, j, ifc_count = 0;
   342    char *ifc_spec_str = NULL;
   343    char *ifc_type = NULL;
   347    if (ifc_spec == NULL) {
   348       VERBOSE(
CL_ERROR, 
"Bad pointer 'ifc_spec' passed to trap_parse_params().");
   356    for (i = 0; i < *argc; i++) {
   357       if (strcmp(argv[i], 
"-h") == 0 || strcmp(argv[i], 
"--help") == 0) {
   358          if (i + 1 < *argc && ((strcmp(argv[i + 1], 
"trap") == 0) || (strcmp(argv[i + 1], 
"1") == 0))) {
   362          for (j = i; j + 1 < *argc; j++) {
   363             argv[j] = argv[j + 1];
   371    for (i = 0; i < *argc-1; i++) {
   372       if (argv[i] && strcmp(argv[i], 
"-i") == 0) {
   373          ifc_spec_str = argv[i+1];
   375          for (j = i; j + 2 < *argc; j++) {
   376             argv[j] = argv[j + 2];
   382    if (ifc_spec_str == NULL) {
   390    for (i = 0; i < *argc; i++) {
   392       if (strcmp(argv[i], 
"-v") == 0) {
   394       } 
else if (strcmp(argv[i], 
"-vv") == 0) {
   396       } 
else if (strcmp(argv[i], 
"-vvv") == 0) {
   402       for (j = i; j + 1 < *argc; j++) {
   403          argv[j] = argv[j + 1];
   412    while (p && *p != 
'\0') {
   420    ifc_spec->
types = calloc(ifc_count + 1, 
sizeof(*ifc_spec->
types));
   421    if (ifc_spec->
types == NULL) {
   424    ifc_spec->
params = calloc(ifc_count, 
sizeof(
char *));
   425    if (ifc_spec->
params == NULL) {
   426       free(ifc_spec->
types);
   427       ifc_spec->
types = NULL;
   432    for (i = 0; i < ifc_count; i++) {
   435          ifc_spec->
types[i] = p[0];
   442             ifc_spec->
params[i] = strdup(
"");
   446          VERBOSE(
CL_ERROR, 
"Bad IFC_SPEC '%s'. See -h trap for help.", ifc_spec_str);
   447          ifc_spec->
params[i] = strdup(
"");
   449       if (ifc_spec->
params[i] == NULL) {
   457    for (i = 0; ifc_spec->
types[i] != 0; ++i) {
   459          if (*ifc_type == ifc_spec->
types[i]) {
   463       if (*ifc_type == 0) {
   476    for (i = 0; i < ifc_count; i++) {
   478       if (ifc_spec->
params[i] != NULL) {
   479          free(ifc_spec->
params[i]);
   480          ifc_spec->
params[i] = NULL;
   483    if (ifc_spec->
types != NULL) {
   484       free(ifc_spec->
types);
   500    if (ifc_spec.
types == NULL) {
   503    if (ifc_spec.
params != NULL) {
   504       for (i = 0; i < strlen(ifc_spec.
types); i++) {
   505          if (ifc_spec.
params[i] != NULL) {
   507             ifc_spec.
params[i] = NULL;
   513    free(ifc_spec.
types);
   609 #define SEND_DATA() do { \   610    int res = trap_ctx_send((trap_ctx_t *) trap_glob_ctx, ifcidx, data, size); \   611    if (res != TRAP_E_NOT_INITIALIZED) { \   612       trap_last_error_msg = trap_glob_ctx->trap_last_error_msg;  \   613       trap_last_error = trap_glob_ctx->trap_last_error; \   677          } 
else if (*str == 
'\t') {
   692    printf(
"{\"name\":");
   694    printf(
",\"description\":");
   696    printf(
",\"num_ifc_in\":%u,\"num_ifc_out\":%u,\"params\":[",
   697          info->num_ifc_in, info->num_ifc_out);
   699    while (info->params[i] != NULL) {
   703       printf(
"{\"short_opt\":\"%c\",\"long_opt\":", info->params[i]->short_opt);
   705       printf(
",\"description\":");
   707       printf(
",\"argument_type\":");
   709       printf(
",\"mandatory_argument\": %d}", info->params[i]->param_required_argument);
   725    int32_t tmp = 0, rest, written;
   736             printf(
"%*s", align, 
" ");
   739          while ((*p == 
' ' || *p == 
'\t') && *p != 0) {
   745             for (tmp = cut; tmp > 0; tmp--) {
   770          written = printf(
"%.*s\n", tmp, p);
   790    const char *eol = NULL, *sol = s;
   791    int bufsize = 512, linewidth;
   792    char *buffer = calloc(1, bufsize);
   793    if (buffer == NULL) {
   798       eol = strchr(sol, 
'\n');
   801          linewidth = strlen(sol);
   803          linewidth = eol - sol;
   806       if (linewidth >= bufsize) {
   807          buffer = realloc(buffer, linewidth + 1);
   808          bufsize = linewidth + 1;
   809          if (buffer == NULL) {
   814       strncpy(buffer, sol, linewidth);
   815       if (buffer[linewidth - 1] == 
'\n') {
   816          buffer[linewidth - 1] = 0;
   818          buffer[linewidth] = 0;
   822    } 
while (eol != NULL);
   836    if (ioctl(1, TIOCGWINSZ, &ws) == 0) {
   838          return ws.ws_col - 1;
   854    size_t bufsize = 1024, rv;
   855    char buffer[bufsize], *p, *ret;
   856    FILE *f = fopen(
"/proc/self/cmdline", 
"r");
   859       return strdup(
"module");
   861    rv = fread(buffer, 1, bufsize - 1, f);
   866       ret = strstr(p, 
"python");
   867       if (ret != NULL && ((ret[6] == 0) || (ret[6] == 
'2') || (ret[6] == 
'3'))) {
   871       ret = strrchr(p, 
'/');
   879          if (p[0] == 
'l' && p[1] == 
't' && p[2] == 
'-') {
   887       ret = strdup(
"module");
   900    char *pager = NULL, *output_format = NULL;
   901    const char *temp_env;
   903    uint32_t i, written = 0, tmp = 0, cols;
   905    uint8_t adit_param = 0, opt_param = 0;
   906    uint16_t align_def = 0, align_opt = 0;
   909    temp_env = getenv(
"LIBTRAP_OUTPUT_FORMAT");
   910    if (temp_env != NULL) {
   911       output_format = strdup(temp_env);
   913    if (output_format != NULL) {
   914       if (strcmp(output_format, 
"json") == 0) {
   928    temp_env = getenv(
"PAGER");
   929    if (temp_env != NULL) {
   930       pager = strdup(temp_env);
   933    if ((pager == NULL) || (strcmp(pager, 
"") == 0)) {
   937    if (pipe(pager_fds) < 0) {
   938       fprintf(stderr, 
"pipe() failed.");
   944       fprintf(stderr, 
"fork() failed.");
   950       dup2(pager_fds[1], STDOUT_FILENO);
   955       char *args[] = {pager, NULL};
   958       dup2(pager_fds[0], STDIN_FILENO);
   960       execvp(args[0], args);
   962       perror(
"exec failed");
   970    puts(
"===========================================");
   972       printf(
"Name: %s\n", module_info->name);
   973       if (module_info->num_ifc_in == -1) {
   974          printf(
"Inputs: variable\n");
   976          printf(
"Inputs: %u\n", (module_info->num_ifc_in));
   978       if (module_info->num_ifc_out == -1) {
   979          printf(
"Outputs: variable\n");
   981          printf(
"Outputs: %u\n", module_info->num_ifc_out);
   983       printf(
"Description:\n  ");
   989       printf(
"\nUsage:  %s [COMMON]... ", module_name);
   992       if (module_info->params != NULL) {
   994          while (module_info->params[i] != NULL) {
   995             if (module_info->params[i]->short_opt == 
'-') {
   997             } 
else if ((module_info->params[i]->short_opt >= 
'a' && module_info->params[i]->short_opt <= 
'z')
   998                        || (module_info->params[i]->short_opt >= 
'A' && module_info->params[i]->short_opt <= 
'Z')) {
  1005       if (opt_param == 1) {
  1006          printf(
"[OPTIONS]... ");
  1008       if (adit_param == 1) {
  1009          printf(
"[ADDITIONAL]... ");
  1013       align_def = strlen(
"LIBTRAP_OUTPUT_FORMAT") + 4;
  1016       if (opt_param == 1) {
  1017          for (i = 0; module_info->params[i] != NULL; i++) {
  1018             if (module_info->params[i]->argument_type == NULL) {
  1021             if (HAVE_GETOPT_LONG && module_info->params[i]->long_opt != NULL) {
  1022                tmp = strlen(module_info->params[i]->long_opt) + strlen(module_info->params[i]->argument_type);
  1024                tmp = strlen(module_info->params[i]->argument_type);
  1026             if (tmp > align_opt) {
  1033          if (align_opt > align_def) {
  1034             align_def = align_opt;
  1037          printf(
"\nParameters of module [OPTIONS]:\n-------------------------------\n");
  1040          while (module_info->params[i] != NULL) {
  1042             if (module_info->params[i]->short_opt == 
'-') {
  1045             } 
else if (HAVE_GETOPT_LONG) {
  1046                if (isprint(module_info->params[i]->short_opt)) {
  1047                   written = printf(
"  -%c  --%s ", module_info->params[i]->short_opt,
  1048                                    module_info->params[i]->long_opt);
  1050                   written = printf(
"       --%s ", module_info->params[i]->long_opt);
  1053                written = printf(
"  -%c ", module_info->params[i]->short_opt);
  1055             switch (module_info->params[i]->param_required_argument) {
  1056             case required_argument:
  1057                written += printf(
"<%s>", module_info->params[i]->argument_type);
  1059             case optional_argument:
  1060                written += printf(
"[%s]", module_info->params[i]->argument_type);
  1063                written += printf(
" ");
  1066             if (written < align_def) {
  1067                printf(
"%*s", align_def - written, 
" ");
  1070             print_aligned(module_info->params[i]->description, align_def, cols - align_def);
  1079       if (adit_param == 1) {
  1080          printf(
"\nAdditional parameters of module [ADDITIONAL]:\n---------------------------------------------\n");
  1083          while (module_info->params[i] != NULL) {
  1084             if (module_info->params[i]->short_opt == 
'-') {
  1085                printf(
"  %s", module_info->params[i]->description);
  1086                if (module_info->params[i]->param_required_argument == required_argument) {
  1087                   printf(
" (data type: <%s>)", module_info->params[i]->argument_type);
  1095       printf(
"\nCommon TRAP parameters [COMMON]:\n--------------------------------\n");
  1097 #define X(param, text, align, cut) do { \  1098   written = printf(param); \  1099   if (written < align_def) { \  1100     printf("%*s", align - written, " "); \  1102   print_aligned(text, align, cut); \  1107         "If no argument, print this message. If \"trap\" or 1 is given, print "  1109         align_def, cols - align_def);
  1112         "Specification of interface types and their parameters, "  1113         "see \"-h trap\" (mandatory parameter).",
  1114         align_def, cols - align_def);
  1116       X(
"  -v", 
"Be verbose.", align_def, cols - align_def);
  1117       X(
"  -vv", 
"Be more verbose.", align_def, cols - align_def);
  1118       X(
"  -vvv", 
"Be even more verbose.", align_def, cols - align_def);
  1120       puts(
"\nEnvironment variables that affects output:\n------------------------------------------");
  1121       X(
"  LIBTRAP_OUTPUT_FORMAT", 
"If set to \"json\", information about module is printed in JSON format.",
  1122         align_def, cols - align_def);
  1123       X(
"  PAGER", 
"Show the help output in the set PAGER.",
  1124         align_def, cols - align_def);
  1125       X(
"  TRAP_SOCKET_DIR", 
"Change path to socket directory (default: " DEFAULTSOCKETDIR 
").",
  1126         align_def, cols - align_def);
  1162    char *param_end = NULL;
  1163    unsigned int param_size = 0;
  1165    if (source == NULL) {
  1169    param_end = strchr(source, delimiter);
  1170    if (param_end == NULL) {
  1172       *dest = strdup(source);
  1176    param_size = param_end - source;
  1177    *dest = (
char *) calloc(1, param_size + 1);
  1178    if (*dest == NULL) {
  1181    strncpy(*dest, source, param_size);
  1182    return param_end + 1;
  1192    if (tmnblk == NULL) {
  1197    if (clock_gettime(CLOCK_REALTIME, tmnblk) == -1) {
  1200       tmnblk->tv_nsec = 0;
  1203    if (tm->tv_usec != 0) {
  1204       tmnblk->tv_nsec = (long) tm->tv_usec * 1000;
  1206       tmnblk->tv_nsec = 0;
  1208    tmnblk->tv_sec += (time_t) (tm->tv_sec + (tm->tv_usec / 1000000));
  1221          tm->tv_sec  = timeout / 1000000;
  1222          tm->tv_usec = timeout % 1000000;
  1235    va_start(ap, request);
  1372    struct timespec spec_time;
  1374    clock_gettime(CLOCK_MONOTONIC, &spec_time);
  1376    return spec_time.tv_sec * 1000000 + (spec_time.tv_nsec / 1000);
  1412    if ((ctx == NULL) || (*ctx == NULL)) {
  1485    if (strval == NULL) {
  1486       if (params < setter) {
  1492       for (strval++; *strval != 0; setter++, strval++) {
  1511    p = strstr(params, 
"timeout=");
  1514 #define X(val) do { \  1515    ifc->datatimeout = val; \  1516    ifc->datatimeout_fixed = 1; \  1518       strval = p + 
sizeof(
"timeout=") - 1;
  1519       if (strncmp(strval, 
"WAIT", 4) == 0) {
  1521       } 
else if (strncmp(strval, 
"NO_WAIT", 7) == 0) {
  1524          if (sscanf(strval, 
"%"SCNi32, &ifc->
datatimeout) == 1) {
  1548    switch (ifc_spec->
types[idx]) {
  1552          VERBOSE(
CL_ERROR, 
"Initialization of GENERATOR input interface no. %i failed.", idx);
  1558          VERBOSE(
CL_ERROR, 
"Initialization of TCPIP input interface no. %i failed.", idx);
  1565          VERBOSE(
CL_ERROR, 
"Initialization of TLS input interface no. %i failed.", idx);
  1572          VERBOSE(
CL_ERROR, 
"Initialization of UNIX input interface no. %i failed.", idx);
  1578          VERBOSE(
CL_ERROR, 
"Initialization of FILE input interface no. %i failed.", idx);
  1587    return EXIT_SUCCESS;
  1590    return EXIT_FAILURE;
  1605    p = strstr(params, 
"timeout=");
  1608 #define X(val) do { \  1609    ifc->datatimeout = val; \  1610    ifc->datatimeout_fixed = 1; \  1612       strval = p + 
sizeof(
"timeout=") - 1;
  1613       if (strncmp(strval, 
"WAIT", 4) == 0) {
  1615       } 
else if (strncmp(strval, 
"NO_WAIT", 7) == 0) {
  1617       } 
else if (strncmp(strval, 
"HALF_WAIT", 9) == 0) {
  1620          if (sscanf(strval, 
"%"SCNi32, &ifc->
datatimeout) == 1) {
  1630    p = strstr(params, 
"buffer=");
  1633 #define X(val) do { \  1634    ifc->bufferswitch = val; \  1635    ifc->bufferswitch_fixed = 1; \  1637       char *strval = p + 
sizeof(
"buffer=") - 1;
  1638       if (strncmp(strval, 
"on", 2) == 0) {
  1640       } 
else if (strncmp(strval, 
"off", 3) == 0) {
  1651    p = strstr(params, 
"autoflush=");
  1653       strval = p + 
sizeof(
"autoflush=") - 1;
  1654       if (strncmp(strval, 
"off", 3) == 0) {
  1658          if (sscanf(strval, 
"%"SCNi64, &ifc->
timeout) == 1) {
  1686          VERBOSE(
CL_ERROR, 
"Initialization of BLACKHOLE output interface no. %i failed.", idx);
  1693          VERBOSE(
CL_ERROR, 
"Initialization of TCPIP output interface no. %i failed.", idx);
  1700          VERBOSE(
CL_ERROR, 
"Initialization of TLS output interface no. %i failed.", idx);
  1709          VERBOSE(
CL_ERROR, 
"Initialization of UNIX output interface no. %i failed.", idx);
  1715          VERBOSE(
CL_ERROR, 
"Initialization of FILE output interface no. %i failed.", idx);
  1725    return EXIT_SUCCESS;
  1728    return EXIT_FAILURE;
  1731 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_ifc_name)
  1734    trap_module_info_t module_info;
  1738    char *argv[2] = {
"-i", (
char *) ifc_spec};
  1742       module_info.name = strdup(name);
  1744       module_info.name = strdup(
"nemea-module");
  1746    if (description != NULL) {
  1747       module_info.description = strdup(description);
  1749       module_info.description = strdup(
"");
  1751    module_info.num_ifc_in  = i_ifcs;
  1752    module_info.num_ifc_out = o_ifcs;
  1754    if (module_info.name == NULL || module_info.description == NULL) {
  1756       if (module_info.name != NULL) {
  1757          free(module_info.name);
  1759       if (module_info.description != NULL) {
  1760          free(module_info.description);
  1775    free(module_info.name);
  1776    free(module_info.description);
  1789    char service_sock_spec[19];
  1792    if (snprintf(service_sock_spec, 19, 
"service_%d", getpid()) < 1) {
  1793       VERBOSE(
CL_ERROR, 
"Could not create service socket specifier in service routine.");
  1805    if ((ifc_spec.
types == NULL) || (ifc_spec.
params == NULL)) {
  1813    if (module_info->num_ifc_in < 0 && module_info->num_ifc_out < 0) {
  1816    } 
else if (module_info->num_ifc_in < 0) {
  1817       module_info->num_ifc_in = strlen(ifc_spec.
types) - module_info->num_ifc_out;
  1818    } 
else if (module_info->num_ifc_out < 0) {
  1819       module_info->num_ifc_out = strlen(ifc_spec.
types) - module_info->num_ifc_in;
  1823    if (pthread_mutex_init(&ctx->
error_mtx, NULL) != 0) {
  1834    int strlen_ifc_types = strlen(ifc_spec.
types);
  1838       VERBOSE(
CL_ERROR, 
"Got %d IFCs via -i, expected %d input and %d output IFCs.",
  1860          goto alloc_counter_failed;
  1877             goto freein_on_failed;
  1886             goto freein_on_failed;
  1897          goto freeall_on_failed;
  1910          goto freein_on_failed;
  1918          goto freeall_on_failed;
  1928    if (service_ifc_name != NULL) {
  1935       ctx->service_thread_initialized = 1;
  1937       ctx->service_thread_initialized = 0;
  1941    ctx->initialized = 1;
  1945    if (ctx->out_ifc_list != NULL) {
  1946       for (i=0; i<ctx->num_ifc_out; ++i) {
  1947          pthread_mutex_destroy(&ctx->out_ifc_list[i].ifc_mtx);
  1948          if (ctx->out_ifc_list[i].destroy != NULL && ctx->out_ifc_list[i].priv != NULL) {
  1949             ctx->out_ifc_list[i].destroy(ctx->out_ifc_list[i].priv);
  1953       free(ctx->out_ifc_list);
  1954       ctx->out_ifc_list = NULL;
  1957    if (ctx->in_ifc_list != NULL) {
  1958       for (i=0; i<ctx->num_ifc_in; ++i) {
  1959          pthread_mutex_destroy(&ctx->in_ifc_list[i].ifc_mtx);
  1960          if (ctx->in_ifc_list[i].destroy != NULL && ctx->in_ifc_list[i].priv != NULL) {
  1961             ctx->in_ifc_list[i].destroy(ctx->in_ifc_list[i].priv);
  1964          if (ctx->in_ifc_list[i].buffer != NULL) {
  1965             free(ctx->in_ifc_list[i].buffer);
  1966             ctx->in_ifc_list[i].buffer = NULL;
  1970    ctx->terminated = 1;
  1972    if (ctx->in_ifc_list) {
  1973       free(ctx->in_ifc_list);
  1974       ctx->in_ifc_list = NULL;
  1976 alloc_counter_failed:
  1977    if (ctx->counter_send_message) {
  1978       free(ctx->counter_send_message);
  1979       ctx->counter_send_message = NULL;
  1981    if (ctx->counter_recv_message) {
  1982       free(ctx->counter_recv_message);
  1983       ctx->counter_recv_message = NULL;
  1985    if (ctx->counter_send_buffer) {
  1986       free(ctx->counter_send_buffer);
  1987       ctx->counter_send_buffer = NULL;
  1989    if (ctx->counter_autoflush) {
  1990       free(ctx->counter_autoflush);
  1991       ctx->counter_autoflush = NULL;
  1993    if (ctx->counter_recv_buffer) {
  1994       free(ctx->counter_recv_buffer);
  1995       ctx->counter_recv_buffer = NULL;
  1997    if (ctx->counter_dropped_message) {
  1998       free(ctx->counter_dropped_message);
  1999       ctx->counter_dropped_message = NULL;
  2001    if (ctx->counter_recv_delay_last) {
  2002       free(ctx->counter_recv_delay_last);
  2003       ctx->counter_recv_delay_last = NULL;
  2005    if (ctx->counter_recv_delay_total) {
  2006       free(ctx->counter_recv_delay_total);
  2007       ctx->counter_recv_delay_total = NULL;
  2009    if (ctx->recv_delay_timestamp) {
  2010       free(ctx->recv_delay_timestamp);
  2011       ctx->recv_delay_timestamp = NULL;
  2026    va_start(ap, request);
  2034    char en_dis_switch = 0;
  2035    uint64_t timeout = 0;
  2036    int32_t datatimeout;
  2051       timeout = va_arg(ap, uint64_t);
  2062       en_dis_switch = (char) va_arg(ap, 
int);
  2064               ifcdir2str(type), (
int)ifcidx, ((
int) en_dis_switch ? 
"ON" : 
"OFF"));
  2073       datatimeout = (int32_t) va_arg(ap, int32_t);
  2077          if (ifcidx < c->num_ifc_out) {
  2082             VERBOSE(
CL_ERROR, 
"There is no output IFC with this index. Bad index passed.");
  2085          if (ifcidx < c->num_ifc_in) {
  2090             VERBOSE(
CL_ERROR, 
"There is no input IFC with this index. Bad index passed.");
  2143    int num_of_timeouts = 0;
  2144    int total_receved = 0;
  2145    int last_receved = 0;
  2147    while (total_receved < size) {
  2148       last_receved = recv(sock_d, (*
data) + total_receved, size - total_receved, MSG_DONTWAIT);
  2149       if (last_receved == 0) {
  2151       } 
else if (last_receved == -1) {
  2152          if (errno == EAGAIN  || errno == EWOULDBLOCK) {
  2154             if (num_of_timeouts >= 3) {
  2163       total_receved += last_receved;
  2170    int num_of_timeouts = 0, total_sent = 0, last_sent = 0;
  2172    while (total_sent < size) {
  2173       last_sent = send(sock_d, (*
data) + total_sent, size - total_sent, MSG_DONTWAIT);
  2174       if (last_sent == -1) {
  2175          if (errno == EAGAIN  || errno == EWOULDBLOCK) {
  2177             if (num_of_timeouts >= 3) {
  2186       total_sent += last_sent;
  2195    char *ifc_id = NULL;
  2196    char none_ifc_id[] = 
"none";
  2198    json_t *in_ifc_cnts  = NULL;
  2199    json_t *out_ifc_cnts = NULL;
  2200    json_t *client_stats_arr;
  2205    json_t *in_ifces_arr = json_array();
  2206    if (in_ifces_arr == NULL) {
  2207       VERBOSE(
CL_ERROR, 
"Service thread - could not create json array while creating json string with counters.");
  2210    json_t *out_ifces_arr = json_array();
  2211    if (out_ifces_arr == NULL) {
  2212       VERBOSE(
CL_ERROR, 
"Service thread - could not create json array while creating json string with counters.");
  2216    json_t *result_json = NULL;
  2218    for (x = 0; x < in_cnt; x++) {
  2220       if (ifc_id == NULL) {
  2221          ifc_id = none_ifc_id;
  2223       in_ifc_cnts = json_pack(
"{sisssisIsIsIsI}",
  2230       if (json_array_append_new(in_ifces_arr, in_ifc_cnts) == -1) {
  2231          VERBOSE(
CL_ERROR, 
"Service thread - could not append new item to out_ifces_arr while creating json string with counters..\n");
  2236    for (x = 0; x < out_cnt; x++) {
  2238       if (ifc_id == NULL) {
  2239          ifc_id = none_ifc_id;
  2242       client_stats_arr = json_array();
  2243       if (client_stats_arr == NULL) {
  2244          VERBOSE(
CL_ERROR, 
"Service thread - could not create json array with client statistics\n");
  2249          VERBOSE(
CL_ERROR, 
"Service thread - could not create json array with client statistics\n");
  2253       out_ifc_cnts = json_pack(
"{sosisssisIsIsIsI}",
  2254               "client_stats_arr", client_stats_arr,
  2261       if (json_array_append_new(out_ifces_arr, out_ifc_cnts) == -1) {
  2262          VERBOSE(
CL_ERROR, 
"Service thread - could not append new item to out_ifces_arr while creating json string with counters..\n");
  2267    result_json = json_pack(
"{sisisoso}", 
"in_cnt", in_cnt, 
"out_cnt", out_cnt, 
"in", in_ifces_arr, 
"out", out_ifces_arr);
  2268    if (result_json == NULL) {
  2269       VERBOSE(
CL_ERROR, 
"Service thread - could not create final json object while creating json string with counters.");
  2273    *
data = json_dumps(result_json, 0);
  2274    json_decref(result_json);
  2275    if (*
data == NULL) {
  2296    struct timespec ts = {.tv_sec = 0, .tv_nsec = 100000000};
  2298    char *json_data = NULL;
  2299    int ret_val, supervisor_sd;
  2304    struct pollfd *pfds = NULL;
  2311       goto exit_service_thread;
  2315    if (service_ifc == NULL) {
  2317       goto exit_service_thread;
  2325       goto exit_service_thread;
  2332       goto exit_service_thread;
  2341       pfds[pfds_size++] = (
struct pollfd) {.fd = priv->
server_sd, .events = POLLIN};
  2345             pfds[pfds_size++] = (
struct pollfd) {.fd = cl->
sd, .events = POLLIN};
  2350       ret_val = ppoll(pfds, pfds_size, &ts, NULL);
  2351       if (ret_val == -1) {
  2352          if (errno == EINTR) {
  2358       } 
else if (ret_val == 0) {
  2365             if (cl->
sd > -1 && pfds[++j].revents & POLLIN) {
  2366                supervisor_sd = cl->
sd;
  2369                if (ret_val == -1) {
  2374                } 
else if (ret_val == 0) {
  2384                         header->data_size = strlen(json_data) + 1;
  2415          if (pfds[0].revents & POLL_IN) {
  2421                   goto accept_success;
  2425             int accept_retval = accept(priv->
server_sd, NULL, NULL);
  2426             if (accept_retval >= 0) {
  2427                close(accept_retval);
  2444 exit_service_thread:
  2445    if (json_data != NULL) {
  2450    if (service_ifc != NULL) {
  2475    const char *td = 
"./";
  2520    char *data_fmt_spec = (
char *) va_arg(ap, 
char *);
  2523       VERBOSE(
CL_ERROR, 
"%s: Uninitialized libtrap context or bad parameters.", __func__);
  2529    pthread_mutex_lock(&ifc->
ifc_mtx);
  2531       VERBOSE(
CL_VERBOSE_LIBRARY, 
"Data format setter: not initial setting of data_type -> disconnect all clients of the output interface %d.", out_ifc_idx);
  2542       if (data_fmt_spec == NULL) {
  2548    pthread_mutex_unlock(&ifc->
ifc_mtx);
  2560    va_start(ap, data_type);
  2569    char *req_data_fmt_spec = (
char *) va_arg(ap, 
char *);
  2584    pthread_mutex_lock(&ifc->
ifc_mtx);
  2591       if (req_data_fmt_spec == NULL) {
  2597    pthread_mutex_unlock(&ifc->
ifc_mtx);
  2611    va_start(ap, data_type);
  2634       pthread_mutex_lock(&inifc->
ifc_mtx);
  2636          pthread_mutex_unlock(&inifc->
ifc_mtx);
  2649          pthread_mutex_unlock(&inifc->
ifc_mtx);
  2652       pthread_mutex_unlock(&inifc->
ifc_mtx);
  2661       pthread_mutex_lock(&outifc->
ifc_mtx);
  2663          pthread_mutex_unlock(&outifc->
ifc_mtx);
  2674       pthread_mutex_unlock(&outifc->
ifc_mtx);
  2697    va_start(ap, data_type);
  2707    va_start(ap, data_type);
  2741    int length_type_2 = 0, length_name_2 = 0;
  2742    const char *source_cpy;
  2743    source_cpy = source;
  2744    while (*source != 0 && *source != 
' ') {
  2749    *length_type = length_type_2;
  2752    source_cpy = source;
  2753    while (*source != 0 && *source != 
',') {
  2757    *length_name = length_name_2;
  2759    if (*source == 
',') {
  2767    if (sender_ifc_data_fmt == NULL && receiver_ifc_data_fmt != NULL) {
  2769    } 
else if (sender_ifc_data_fmt != NULL && receiver_ifc_data_fmt == NULL) {
  2771    } 
else if (sender_ifc_data_fmt == NULL && receiver_ifc_data_fmt == NULL) {
  2775    const char *receiver_move,
  2777       *field_name_receiver,
  2779       *field_type_receiver,
  2781    int field_name_receiver_length = 0,
  2782       field_name_sender_length = 0,
  2783       field_type_receiver_length = 0,
  2784       field_type_sender_length = 0;
  2785    int compare_str = 0;
  2786    receiver_move = receiver_ifc_data_fmt;
  2787    sender_move = sender_ifc_data_fmt;
  2789    while (*receiver_move != 0) {
  2792          &field_type_receiver, &field_name_receiver_length, &field_type_receiver_length);
  2794       while (*sender_move != 0 && !compare_str) {
  2797                &field_type_sender, &field_name_sender_length, &field_type_sender_length);
  2798             compare_str = (field_name_sender_length == field_name_receiver_length &&
  2799                field_type_sender_length == field_type_receiver_length &&
  2800                memcmp(field_name_sender, field_name_receiver, field_name_receiver_length) == 0 &&
  2801                memcmp(field_type_sender, field_type_receiver, field_type_receiver_length) == 0);
  2804          VERBOSE(
CL_ERROR, 
"TRAP Negotiation failed: required field `%.*s %.*s` not offered by sender.\nReceived specifier: %s",
  2805                  field_type_receiver_length, field_type_receiver,
  2806                  field_name_receiver_length, field_name_receiver,
  2807                  sender_ifc_data_fmt);
  2811       sender_move = sender_ifc_data_fmt;
  2813    if (strlen(sender_ifc_data_fmt) > strlen(receiver_ifc_data_fmt)) {
  2839    char *buffer = (
char *) calloc(size_of_buffer, 
sizeof(
char));
  2852    char *data_fmt_spec = NULL;
  2853    uint32_t ifc_idx = 0;
  2860       ifc_idx = file_ifc_priv->
ifc_idx;
  2866       ifc_idx = tls_ifc_priv->
ifc_idx;
  2872       ifc_idx = tcp_ifc_priv->
ifc_idx;
  2873       sock_d = tcp_ifc_priv->
clients[client_idx].
sd;
  2887       VERBOSE(
CL_VERBOSE_LIBRARY, 
"Output interface negotiation - the data format or specifier of the output interface %d are not set correctly.", ifc_idx);
  2897       hello_msg_header->
data_type = data_type;
  2914       ret_val = fwrite((
void *) p, 
sizeof(
char), size, file_ifc_priv->
fd);
  2918       ret_val = SSL_write(tls_ifc_priv->
clients[client_idx].
ssl, p, size);
  2922          compare = ret_val + 1;
  2929    if (ret_val != compare) {
  2946       if ((strlen(data_fmt_spec) + 1) > size_of_buffer) {
  2947          buffer = (
char *) realloc(buffer, (strlen(data_fmt_spec) + 1) * 
sizeof(char));
  2948          memset(buffer + size_of_buffer, 0, ((strlen(data_fmt_spec) + 1) - size_of_buffer) * 
sizeof(
char));
  2949          size_of_buffer = (strlen(data_fmt_spec) + 1);
  2951       sprintf(buffer,
"%s",data_fmt_spec);
  2956          ret_val = fwrite((
void *) p, 
sizeof(
char), size, file_ifc_priv->
fd);
  2960          ret_val = SSL_write(tls_ifc_priv->
clients[client_idx].
ssl, p, size);
  2964             compare = ret_val + 1;
  2971       if (ret_val != compare) {
  2982    if (buffer != NULL) {
  2986    if (hello_msg_header != NULL) {
  2987       free (hello_msg_header);
  2988       hello_msg_header = NULL;
  3012    char *req_data_fmt_spec = NULL;
  3013    char *current_data_fmt_spec = NULL;
  3014    char *recv_data_fmt_spec = NULL;
  3043    p_p = (
void *) hello_msg_header;
  3046       ret_val = fread(p_p, 
sizeof(
char), size, file_ifc_priv->
fd);
  3054          ret_val = SSL_read(tls_ifc_priv->
ssl, p_p, size);
  3057          } 
else if (ret_val == -1) {
  3058             ret_val = SSL_get_error(tls_ifc_priv->
ssl, ret_val);
  3059             if (ret_val == SSL_ERROR_WANT_READ) {
  3063             compare = ret_val + 1;
  3065       } 
while (ret_val == -1);
  3068    if (ret_val != compare) {
  3109    } 
else if (hello_msg_header->
data_type != req_data_type) {
  3161       recv_data_fmt_spec = calloc(size+1, 
sizeof(
char));
  3162       p_p = (
void *) recv_data_fmt_spec;
  3166             ret_val = fread(p_p, 
sizeof(
char), size, file_ifc_priv->
fd);
  3173             ret_val = SSL_read(tls_ifc_priv->
ssl, p_p, size);
  3177                compare = ret_val + 1;
  3182          if (ret_val != compare) {
  3195             free(recv_data_fmt_spec);
  3196             recv_data_fmt_spec = NULL;
  3215          ret_val = (req_data_fmt_spec == NULL || req_data_fmt_spec[0] == 0 ||
  3217                     strcmp(req_data_fmt_spec, recv_data_fmt_spec) == 0
  3233          free(recv_data_fmt_spec);
  3234          recv_data_fmt_spec = NULL;
  3260          if (current_data_fmt_spec != NULL) {
  3267                ret_val = (strcmp(current_data_fmt_spec, recv_data_fmt_spec) != 0 ? 1  : 
TRAP_E_OK);
  3326    if (hello_msg_header != NULL) {
  3327       free(hello_msg_header);
  3328       hello_msg_header = NULL;
 
void trap_free_ctx_t(trap_ctx_priv_t **ctx)
int trap_get_data_fmt(uint8_t ifc_dir, uint32_t in_ifc_idx, uint8_t *data_type, const char **spec)
Set interface timeout (int32_t): in microseconds for non-blocking mode; timeout can be also: TRAP_WAI...
#define TRAP_E_OK
Success, no error. 
int trap_ctx_get_in_ifc_state(trap_ctx_t *ctx, uint32_t ifc_idx)
int trap_ctx_set_required_fmt(trap_ctx_t *ctx, uint32_t in_ifc_idx, uint8_t data_type,...)
int create_tls_receiver_ifc(trap_ctx_priv_t *ctx, char *params, trap_input_ifc_t *ifc, uint32_t idx)
Constructor of input TCP/IP IFC module. This function is called by TRAP library to initialize one inp...
#define MAX_ERROR_MSG_BUFF_SIZE
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...
#define TRAP_IFC_TIMEOUT
size of default timeout on output interfaces in microseconds 
int trap_ctx_cmp_data_fmt(const char *sender_ifc_data_fmt, const char *receiver_ifc_data_fmt)
ifc_get_client_stats_json_func_t get_client_stats_json
Pointer to get_client_stats_json function. 
#define NEG_RES_SENDER_FMT_SUBSET
If the data format of input and output interfaces is the same and new data specifier of the output in...
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_ifc_name)
Initialize and return the context of libtrap. 
Internal functions and macros for libtrap Verbose and debug macros from libcommlbr. 
#define TRAP_IFC_PARAM_DELIMITER
int create_tcpip_receiver_ifc(trap_ctx_priv_t *ctx, char *params, trap_input_ifc_t *ifc, uint32_t idx, enum tcpip_ifc_sockettype type)
Constructor of input TCP/IP IFC module. This function is called by TRAP library to initialize one inp...
const char trap_version[]
#define TRAP_E_FORMAT_CHANGED
Returned by trap_recv when format or format spec of the receivers interface has been changed...
int trap_last_error
Code of last error (one of the codes above) 
pthread_mutex_t ifc_mtx
Locking mutex for interface. 
char * trap_default_socket_path_format
#define X(param, text, align, cut)
char * get_module_name(void)
static void print_aligned_multiline(const char *s, uint16_t align, uint16_t cut)
static void remove_setter_from_param(char *params, char *setter)
#define NEG_RES_FAILED
If receiving the data from output interface fails or sending the data to input interface fails...
ifc_autoflush_t * ifc_autoflush_timeout
struct msg_header_s msg_header_t
void trap_json_print_string(char *str)
const char * trap_last_error_msg
Human-readable message about last error. 
#define TRAP_E_BAD_IFC_INDEX
Interface index out of range. 
Set timeout of automatic buffer flushing for interface, expects uint64_t argument with number of micr...
void trap_set_abs_timespec(struct timeval *tm, struct timespec *tmnblk)
Internal function for setting of timeout structs according to libtrap timeout. 
int service_send_data(int sock_d, uint32_t size, void **data)
void trap_set_timeouts(int timeout, struct timeval *tm, struct timespec *tmnblk)
Internal function for setting of timeout structs according to libtrap timeout. 
const char * trap_get_type_and_name_from_string(const char *source, const char **name, const char **type, int *length_name, int *length_type)
static uint16_t get_terminal_width()
void trap_convert_module_info_to_json(const trap_module_info_t *info)
ifc_get_id_func_t get_id
Pointer to get_id function. 
#define TRAP_E_FIELDS_MISMATCH
Returned when receiver fields are not subset of sender fields. 
int trap_ctx_vifcctl(trap_ctx_t *ctx, int8_t type, uint32_t ifcidx, int32_t request, va_list ap)
Control TRAP interface. 
Structure for TLS IFC private information. 
#define TRAP_IFC_TYPE_BLACKHOLE
trap_ifc_dummy blackhole (output) 
const char * trap_ctx_get_last_error_msg(trap_ctx_t *ctx)
Get last (error) message from libtrap context. 
#define TRAP_E_HELP
Returned by parse_parameters when help is requested. 
TRAP TCP/IP interfaces private structures. 
static void handle_outifc_setters(trap_output_ifc_t *ifc, char *params)
int trap_ctx_send(trap_ctx_t *ctx, unsigned int ifc, const void *data, uint16_t size)
Send data via output interface. 
int trap_update_module_param(trap_module_info_t *m, uint16_t param_id, char shortopt, const char *longopt, const char *desc, int req_arg, const char *arg_type)
int output_ifc_negotiation(void *ifc_priv_data, char ifc_type, uint32_t client_idx)
int trap_get_in_ifc_state(uint32_t ifc_idx)
void trap_set_help_section(int level)
#define UNIX_PATH_FILENAME_FORMAT
static int trap_read_from_buffer(trap_ctx_priv_t *ctx, uint32_t ifc_idx, const void **data, uint16_t *size, int timeout)
const char * default_err_msg[256]
static int trapifc_in_construct(trap_ctx_priv_t *ctx, trap_ifc_spec_t *ifc_spec, int idx)
use UNIX socket as a service interface 
char error_msg_buffer[MAX_ERROR_MSG_BUFF_SIZE]
#define TRAP_E_TERMINATED
Interface was terminated during reading/writing. 
int create_blackhole_ifc(trap_ctx_priv_t *ctx, char *params, trap_output_ifc_t *ifc)
void trap_check_global_vars(void)
uint64_t * counter_dropped_message
trap_ctx_priv_t * trap_create_ctx_t()
ifc_create_dump_func_t create_dump
Pointer to function for generating of dump. 
static int trapifc_out_construct(trap_ctx_priv_t *ctx, trap_ifc_spec_t *ifc_spec, int idx)
int create_file_send_ifc(trap_ctx_priv_t *ctx, const char *params, trap_output_ifc_t *ifc, uint32_t idx)
Allocate and initiate file output interface. This function is called by TRAP library to initialize on...
char ifc_type
Type of interface. 
#define NEG_RES_FMT_CHANGED
If the data format has changed (for JSON type, UNIREC type uses *SUBSET variants) ...
void trap_get_internal_buffer(trap_ctx_priv_t *ctx, uint16_t ifc_idx, const void **data, uint32_t *size)
Get pointer to data stored in buffer (with headers) and mark buffer as clean. 
#define VERBOSE(level, format, args...)
TRAP TCP/IP interfaces private structures. 
int trap_init(trap_module_info_t *module_info, trap_ifc_spec_t ifc_spec)
void trap_ctx_vset_data_fmt(trap_ctx_t *ctx, uint32_t out_ifc_idx, uint8_t data_type, va_list ap)
#define DEFAULT_MAX_TERMINAL_WIDTH
static int trap_errorf(trap_ctx_priv_t *ctx, int err_num, const char *msg,...)
int service_get_data(int sock_d, uint32_t size, void **data)
int trap_ifcctl(int8_t type, uint32_t ifcidx, int32_t request,...)
Control TRAP interface. 
int create_tls_sender_ifc(trap_ctx_priv_t *ctx, const char *params, trap_output_ifc_t *ifc, uint32_t idx)
Constructor of output TCP/IP IFC module. This function is called by TRAP library to initialize one ou...
ifc_get_client_count_func_t get_client_count
Pointer to get_client_count function. 
#define NEG_RES_CONT
If the data format and data specifier of input and output interface are the same (input interface can...
void trap_ctx_send_flush(trap_ctx_t *ctx, uint32_t ifc)
Force flush of buffer. 
#define TRAP_IFC_TYPE_GENERATOR
trap_ifc_dummy generator (input) 
ifc_disconn_clients_func_t disconn_clients
Pointer to disconnect_clients function. 
int trap_ctx_get_client_count(trap_ctx_t *ctx, uint32_t ifcidx)
Get number of connected clients. 
void trap_send_flush(uint32_t ifc)
Force flush of buffer. 
int service_thread_initialized
Structure for TCP/IP IFC private information. 
interface acts as source of data for module 
int trap_ctx_ifcctl(trap_ctx_t *ctx, int8_t type, uint32_t ifcidx, int32_t request,...)
Control TRAP interface. 
#define TRAP_E_BAD_FPARAMS
Bad parameters of function. 
use UNIX socket for local communication 
#define TRAP_E_INITIALIZED
TRAP library already initilized. 
char bufferswitch
Enable (1) or Disable (0) buffering, default is Enabled (1). 
uint64_t * counter_recv_message
#define TRAP_IFC_TYPE_TCPIP
trap_ifc_tcpip (input&output part) 
int trap_ctx_finalize(trap_ctx_t **ctx)
Terminate libtrap context and free resources. 
int trap_ctx_recv(trap_ctx_t *ctx, uint32_t ifcidx, const void **data, uint16_t *size)
Read data from input interface. 
static void handle_inifc_setters(trap_input_ifc_t *ifc, char *params)
Structure for TCP/IP IFC client information. 
int trap_ctx_vset_required_fmt(trap_ctx_t *ctx, uint32_t in_ifc_idx, uint8_t data_type, va_list ap)
pthread_mutex_t error_mtx
int create_file_recv_ifc(trap_ctx_priv_t *ctx, const char *params, trap_input_ifc_t *ifc, uint32_t idx)
Allocate and initiate file input interface. This function is called by TRAP library to initialize one...
int32_t datatimeout
Timeout for *_send() calls. 
ifc_send_func_t send
Pointer to send function. 
#define SERVICE_GET_COM
Signaling a request for module statistics (interfaces stats - received messages and buffers...
int trap_ctx_get_last_error(trap_ctx_t *ctx)
Get last result code from libtrap context. 
trap_ctx_priv_t * trap_glob_ctx
trap_module_info_t * trap_create_module_info(const char *mname, const char *mdesc, int8_t i_ifcs, int8_t o_ifcs, uint16_t param_count)
#define TRAP_IFC_DELIMITER
#define NEG_RES_FMT_UNKNOWN
If the output interface has not specified data format. 
#define TRAP_IFC_TYPE_TLS
trap_ifc_tls (input&output part) 
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)
int trap_get_verbose_level()
const char * trap_last_error_msg
void trap_set_verbose_level(int level)
trap_ctx_t * trap_ctx_init2(trap_module_info_t *module_info, trap_ifc_spec_t ifc_spec, const char *service_ifc_name)
Initialize and return the context of libtrap. 
const char * trap_help_ifcspec
uint64_t * recv_delay_timestamp
void * trap_get_global_ctx()
#define NEG_RES_FMT_MISMATCH
If the data format or data specifier of input and output interfaces does not match. 
int trap_parse_params(int *argc, char **argv, trap_ifc_spec_t *ifc_spec)
int trap_free_ifc_spec(trap_ifc_spec_t ifc_spec)
Enable/disable buffering - could be dangerous on input interface!!! expects char argument with value ...
int trap_send_data(unsigned int ifcidx, const void *data, uint16_t size, int timeout)
uint64_t * counter_recv_delay_total
int64_t timeout
Internal structure to send partial data after timeout (autoflush). 
struct hello_msg_header_s hello_msg_header_t
#define TRAP_E_MEMORY
Memory allocation error. 
#define NEG_RES_OK
Signaling success (hello message successfully sent to input interface) 
void trap_free_global_vars(void)
int trap_ctx_terminate(trap_ctx_t *ctx)
Terminate libtrap context. 
int encode_cnts_to_json(char **data, trap_ctx_priv_t *ctx)
void trap_set_data_fmt(uint32_t out_ifc_idx, uint8_t data_type,...)
ifc_destroy_func_t destroy
Pointer to destructor function. 
int create_tcpip_sender_ifc(trap_ctx_priv_t *ctx, const char *params, trap_output_ifc_t *ifc, uint32_t idx, enum tcpip_ifc_sockettype type)
Constructor of output TCP/IP IFC module. This function is called by TRAP library to initialize one ou...
void trap_ctx_create_ifc_dump(trap_ctx_t *ctx, const char *path)
Create dump files. 
uint64_t * counter_recv_buffer
ifc_terminate_func_t terminate
Pointer to terminate function. 
uint32_t clients_arr_size
int trap_recv(uint32_t ifcidx, const void **data, uint16_t *size)
Receive data from input interface. 
int trap_set_required_fmt(uint32_t in_ifc_idx, uint8_t data_type,...)
uint64_t * counter_recv_delay_last
static int trap_error(trap_ctx_priv_t *ctx, int err_num)
#define TRAP_E_TIMEOUT
Read or write operation timeout. 
TRAP dummy interfaces (generator and blackhole) 
#define DEFAULT_SOCKET_FORMAT
uint64_t * counter_autoflush
#define NEG_RES_RECEIVER_FMT_SUBSET
If the data format of input and output interfaces is the same and data specifier of the input interfa...
int create_generator_ifc(trap_ctx_priv_t *ctx, char *params, trap_input_ifc_t *ifc)
#define TRAP_E_NOT_SELECTED
Interface was not selected reading/writing. 
#define TRAP_IFC_TYPE_UNIX
trap_ifc_tcpip via UNIX socket(input&output part) 
static uint64_t get_cur_timestamp()
void trap_print_help(const trap_module_info_t *module_info)
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. 
ifc_flush_func_t flush
Pointer to flush function. 
#define TRAP_IFC_TYPE_FILE
trap_ifc_file (input&output part) 
#define TRAP_NO_AUTO_FLUSH
value to disable autoflushing on output interface 
static void print_aligned(const char *s, uint16_t align, uint16_t cut)
uint64_t * counter_send_buffer
int input_ifc_negotiation(void *ifc_priv_data, char ifc_type)
#define TRAP_E_NOT_INITIALIZED
TRAP library not initilized. 
void trap_ctx_set_data_fmt(trap_ctx_t *ctx, uint32_t out_ifc_idx, uint8_t data_type,...)
int trap_check_buffer_content(void *buffer, uint32_t buffer_size)
Check content of buffer, iterate over message headers. 
void * priv
Pointer to instance's private data. 
trap_output_ifc_t * out_ifc_list
static char * get_param_by_delimiter(const char *source, char **dest, const char delimiter)
Interface of TRAP interfaces. 
#define TRAP_E_FIELDS_SUBSET
Returned when receivers fields are subset of senders fields and both sets are not identical...
uint64_t * counter_send_message
const char trap_git_version[]
#define SERVICE_OK_REPLY
A value used as a reply signaling success. 
const char trap_version [] __attribute__((used))
trap_input_ifc_t * in_ifc_list
void * service_thread_routine(void *arg)
#define TRAP_E_BADPARAMS
Bad parameters passed to interface initializer. 
void trap_print_ifc_spec_help()
interface is used for sending data out of module 
#define TRAP_IFC_MESSAGEQ_SIZE
size of message queue used for buffering 
#define TRAP_IFC_TYPE_SERVICE
service ifc 
int trap_send(uint32_t ifcidx, const void *data, uint16_t size)
Send data via output interface. 
char trap_ifc_type_supported[]