static void om_kafka_config(nx_module_t *module) { const nx_directive_t* volatile curr; nx_om_kafka_conf_t* volatile modconf; nx_exception_t e; curr = module->directives; modconf = apr_pcalloc(module->pool, sizeof(nx_om_kafka_conf_t)); module->config = modconf; modconf->partition = RD_KAFKA_PARTITION_UA; while (curr != NULL) { if (nx_module_common_keyword(curr->directive) == TRUE) { //ignore common configuration keywords } else if (strcasecmp(curr->directive, "brokerlist") == 0) { modconf->brokerlist = curr->args; } else if (strcasecmp(curr->directive, "topic") == 0) { modconf->topic = curr->args; } else if (strcasecmp(curr->directive, "compression") == 0) { modconf->compression = curr->args; } else if (strcasecmp(curr->directive, "partition") == 0) { modconf->partition = atoi(curr->args); } else { log_warn("Kafka output module ignored directive \"%s\" set to \"%s\"\n", curr->directive, curr->args); } curr = curr->next; } }
static void pm_norepeat_config(nx_module_t *module) { const nx_directive_t *curr; nx_pm_norepeat_conf_t *modconf; const char *start, *ptr, *end; char *field = NULL; apr_size_t len; modconf = apr_pcalloc(module->pool, sizeof(nx_pm_norepeat_conf_t)); module->config = modconf; curr = module->directives; while ( curr != NULL ) { if ( nx_module_common_keyword(curr->directive) == TRUE ) { } else if ( strcasecmp(curr->directive, "CheckFields") == 0 ) { if ( modconf->fields != NULL ) { nx_conf_error(curr, "CheckFields already defined"); } ptr = curr->args; for ( ; (ptr != NULL) && apr_isspace(*ptr); (ptr)++ ); if ( (curr->args == NULL) || (strlen(ptr) == 0) ) { nx_conf_error(curr, "value missing for CheckFields"); } end = ptr + strlen(ptr); modconf->fields = apr_array_make(module->pool, 5, sizeof(const char *)); while ( *ptr != '\0' ) { start = ptr; for ( ; !((*ptr == '\0') || apr_isspace(*ptr) || (*ptr == ',')); ptr++ ); if ( ptr > start ) { len = (apr_size_t) (ptr - start + 1); field = apr_palloc(module->pool, len); apr_cpystrn(field, start, len); } *((const char **) apr_array_push(modconf->fields)) = field; for ( ; apr_isspace(*ptr) || (*ptr == ','); ptr++ ); } } else { nx_conf_error(curr, "invalid pm_norepeat keyword: %s", curr->directive); } curr = curr->next; } modconf->pid = (int) getpid(); }
static void xm_charconv_config(nx_module_t *module) { const nx_directive_t *curr; nx_xm_charconv_conf_t *modconf; char *list; const char *charset; int i; curr = module->directives; modconf = apr_pcalloc(module->pool, sizeof(nx_xm_charconv_conf_t)); module->config = modconf; while ( curr != NULL ) { if ( nx_module_common_keyword(curr->directive) == TRUE ) { } else if ( strcasecmp(curr->directive, "AutodetectCharsets") == 0 ) { list = apr_pstrdup(module->pool, curr->args); for ( i = 0; (charset = list_parse(&list)) != NULL; i++ ) { log_debug("adding xm_charconv charset: %s", charset); if ( i >= NX_XM_CHARCONV_MAX_CHARSETS - 1 ) { throw_msg("maximum number of charsets reached, limit is %d", NX_XM_CHARCONV_MAX_CHARSETS); } modconf->autocharsets[i] = charset; } modconf->num_charsets = i; } curr = curr->next; } log_debug("locale charset: %s", nx_get_locale_charset()); }
static void xm_json_config(nx_module_t *module) { const nx_directive_t *curr; nx_xm_json_conf_t *modconf; curr = module->directives; modconf = apr_pcalloc(module->pool, sizeof(nx_xm_json_conf_t)); module->config = modconf; while ( curr != NULL ) { if ( nx_module_common_keyword(curr->directive) == TRUE ) { } else { nx_conf_error(curr, "invalid keyword: %s", curr->directive); } curr = curr->next; } }
static void im_ssl_config(nx_module_t *module) { const nx_directive_t *curr; nx_im_ssl_conf_t *imconf; unsigned int port; ASSERT(module->directives != NULL); curr = module->directives; imconf = apr_pcalloc(module->pool, sizeof(nx_im_ssl_conf_t)); module->config = imconf; imconf->ssl_ctx.keypass = nx_module_get_resource(module, "keypass", NX_RESOURCE_TYPE_PASSWORD); while ( curr != NULL ) { if ( nx_module_common_keyword(curr->directive) == TRUE ) { } else if ( strcasecmp(curr->directive, "host") == 0 ) { if ( imconf->host != NULL ) { nx_conf_error(curr, "host is already defined"); } imconf->host = apr_pstrdup(module->pool, curr->args); } else if ( strcasecmp(curr->directive, "port") == 0 ) { if ( imconf->port != 0 ) { nx_conf_error(curr, "port is already defined"); } if ( sscanf(curr->args, "%u", &port) != 1 ) { nx_conf_error(curr, "invalid port: %s", curr->args); } imconf->port = (apr_port_t) port; } else if ( strcasecmp(curr->directive, "certfile") == 0 ) { if ( imconf->ssl_ctx.certfile != NULL ) { nx_conf_error(curr, "CertFile is already defined"); } imconf->ssl_ctx.certfile = apr_pstrdup(module->pool, curr->args); } else if ( strcasecmp(curr->directive, "certkeyfile") == 0 ) { if ( imconf->ssl_ctx.certkeyfile != NULL ) { nx_conf_error(curr, "CertKeyFile is already defined"); } imconf->ssl_ctx.certkeyfile = apr_pstrdup(module->pool, curr->args); } else if ( strcasecmp(curr->directive, "keypass") == 0 ) { if ( imconf->ssl_ctx.keypass != NULL ) { nx_conf_error(curr, "KeyPass is already defined"); } imconf->ssl_ctx.keypass = apr_pstrdup(module->pool, curr->args); } else if ( strcasecmp(curr->directive, "cafile") == 0 ) { if ( imconf->ssl_ctx.cafile != NULL ) { nx_conf_error(curr, "CAFile is already defined"); } imconf->ssl_ctx.cafile = apr_pstrdup(module->pool, curr->args); } else if ( strcasecmp(curr->directive, "cadir") == 0 ) { if ( imconf->ssl_ctx.cadir != NULL ) { nx_conf_error(curr, "CADir is already defined"); } imconf->ssl_ctx.cadir = apr_pstrdup(module->pool, curr->args); } else if ( strcasecmp(curr->directive, "crlfile") == 0 ) { if ( imconf->ssl_ctx.crlfile != NULL ) { nx_conf_error(curr, "CRLFile is already defined"); } imconf->ssl_ctx.crlfile = apr_pstrdup(module->pool, curr->args); } else if ( strcasecmp(curr->directive, "crldir") == 0 ) { if ( imconf->ssl_ctx.crldir != NULL ) { nx_conf_error(curr, "CRLDir is already defined"); } imconf->ssl_ctx.crldir = apr_pstrdup(module->pool, curr->args); } else if ( strcasecmp(curr->directive, "RequireCert") == 0 ) { } else if ( strcasecmp(curr->directive, "AllowUntrusted") == 0 ) { } else if ( strcasecmp(curr->directive, "InputType") == 0 ) { if ( imconf->inputfunc != NULL ) { nx_conf_error(curr, "InputType is already defined"); } if ( curr->args != NULL ) { imconf->inputfunc = nx_module_input_func_lookup(curr->args); } if ( imconf->inputfunc == NULL ) { nx_conf_error(curr, "Invalid InputType '%s'", curr->args); } } else { nx_conf_error(curr, "invalid keyword: %s", curr->directive); } curr = curr->next; } if ( imconf->inputfunc == NULL ) { imconf->inputfunc = nx_module_input_func_lookup("linebased"); } ASSERT(imconf->inputfunc != NULL); if ( imconf->ssl_ctx.certfile == NULL ) { nx_conf_error(module->directives, "'CertFile' missing for module im_ssl"); } if ( imconf->ssl_ctx.certkeyfile == NULL ) { nx_conf_error(module->directives, "'CertKeyFile' missing for module im_ssl"); } /* if ( imconf->ssl_ctx.keypass == NULL ) { nx_conf_error(module->directives, "'KeyPass' missing for module im_ssl"); } */ imconf->ssl_ctx.require_cert = TRUE; imconf->ssl_ctx.allow_untrusted = FALSE; nx_cfg_get_boolean(module->directives, "RequireCert", &(imconf->ssl_ctx.require_cert)); nx_cfg_get_boolean(module->directives, "AllowUntrusted", &(imconf->ssl_ctx.allow_untrusted)); if ( imconf->host == NULL ) { imconf->host = apr_pstrdup(module->pool, IM_SSL_DEFAULT_HOST); } if ( imconf->port == 0 ) { imconf->port = IM_SSL_DEFAULT_PORT; } module->input.pool = nx_pool_create_child(module->pool); imconf->connections = apr_pcalloc(module->pool, sizeof(nx_module_input_list_t)); }
static void im_exec_config(nx_module_t *module) { const nx_directive_t *curr; nx_im_exec_conf_t *imconf; int argc = 0; ASSERT(module->directives != NULL); curr = module->directives; imconf = apr_pcalloc(module->pool, sizeof(nx_im_exec_conf_t)); module->config = imconf; while ( curr != NULL ) { if ( nx_module_common_keyword(curr->directive) == TRUE ) { } else if ( strcasecmp(curr->directive, "command") == 0 ) { if ( imconf->cmd != NULL ) { nx_conf_error(curr, "Command is already defined"); } if ( argc >= NX_IM_EXEC_MAX_ARGC ) { nx_conf_error(curr, "too many arguments"); } imconf->cmd = apr_pstrdup(module->pool, curr->args); imconf->argv[argc] = imconf->cmd; argc++; } else if ( strcasecmp(curr->directive, "arg") == 0 ) { if ( argc >= NX_IM_EXEC_MAX_ARGC ) { nx_conf_error(curr, "too many arguments"); } imconf->argv[argc] = apr_pstrdup(module->pool, curr->args); argc++; } else if ( strcasecmp(curr->directive, "InputType") == 0 ) { if ( imconf->inputfunc != NULL ) { nx_conf_error(curr, "InputType is already defined"); } if ( curr->args != NULL ) { imconf->inputfunc = nx_module_input_func_lookup(curr->args); } if ( imconf->inputfunc == NULL ) { nx_conf_error(curr, "Invalid InputType '%s'", curr->args); } } else if ( strcasecmp(curr->directive, "restart") == 0 ) { } else { nx_conf_error(curr, "invalid keyword: %s", curr->directive); } curr = curr->next; } nx_cfg_get_boolean(module->directives, "restart", &(imconf->restart)); if ( imconf->inputfunc == NULL ) { imconf->inputfunc = nx_module_input_func_lookup("linebased"); } ASSERT(imconf->inputfunc != NULL); if ( imconf->cmd == NULL ) { nx_conf_error(module->directives, "'Command' missing for module im_exec"); } module->input.pool = nx_pool_create_child(module->pool); }
static void xm_multiline_config(nx_module_t *module) { nx_xm_multiline_conf_t *modconf; const nx_directive_t * volatile curr; nx_exception_t e; modconf = apr_pcalloc(module->pool, sizeof(nx_xm_multiline_conf_t)); module->config = modconf; curr = module->directives; while ( curr != NULL ) { if ( nx_module_common_keyword(curr->directive) == TRUE ) { } else if ( strcasecmp(curr->directive, "headerline") == 0 ) { if ( modconf->headerline != NULL ) { nx_conf_error(curr, "HeaderLine is already defined"); } try { if ( (strlen(curr->args) > 1) && (curr->args[0] == '/') && (curr->args[strlen(curr->args) - 1] == '/') ) { // TODO: this is a hack because regexp and division are not correctly // handled by the lexer/parser. expr-tokens.l needs to be fixed and // needs to be stateful. curr->args[strlen(curr->args) - 1] = '\0'; modconf->headerline = nx_value_new_regexp(curr->args + 1); } else { modconf->headerline_expr = nx_expr_parse(module, curr->args, module->pool, curr->filename, curr->line_num, curr->argsstart); if ( !((modconf->headerline_expr->rettype == NX_VALUE_TYPE_STRING) || (modconf->headerline_expr->rettype == NX_VALUE_TYPE_REGEXP)) ) { throw_msg("string or regexp type required in expression, found '%s'", nx_value_type_to_string(modconf->headerline_expr->rettype)); } if ( modconf->headerline_expr->type == NX_EXPR_TYPE_VALUE ) { ASSERT(modconf->headerline_expr->value.defined == TRUE); modconf->headerline = &(modconf->headerline_expr->value); } } } catch(e) { log_exception(e); nx_conf_error(curr, "invalid expression in 'HeaderLine'"); } } else if ( strcasecmp(curr->directive, "endline") == 0 ) { if ( modconf->endline != NULL ) { nx_conf_error(curr, "EndLine is already defined"); } try { if ( (strlen(curr->args) > 1) && (curr->args[0] == '/') && (curr->args[strlen(curr->args) - 1] == '/') ) { // TODO: this is a hack because regexp and division are not correctly // handled by the lexer/parser. expr-tokens.l needs to be fixed and // needs to be stateful. curr->args[strlen(curr->args) - 1] = '\0'; modconf->endline = nx_value_new_regexp(curr->args + 1); } else { modconf->endline_expr = nx_expr_parse(module, curr->args, module->pool, curr->filename, curr->line_num, curr->argsstart); if ( !((modconf->endline_expr->rettype == NX_VALUE_TYPE_STRING) || (modconf->endline_expr->rettype == NX_VALUE_TYPE_REGEXP)) ) { throw_msg("string or regexp type required in expression, found '%s'", nx_value_type_to_string(modconf->endline_expr->rettype)); } if ( modconf->endline_expr->type == NX_EXPR_TYPE_VALUE ) { ASSERT(modconf->endline_expr->value.defined == TRUE); modconf->endline = &(modconf->endline_expr->value); } } } catch(e) { log_exception(e); nx_conf_error(curr, "invalid expression in 'Endline'"); } } else if ( strcasecmp(curr->directive, "fixedlinecount") == 0 ) { if ( modconf->fixedlinecount != 0 ) { nx_conf_error(curr, "FixedLineCount is already defined"); } if ( sscanf(curr->args, "%u", &(modconf->fixedlinecount)) != 1 ) { nx_conf_error(curr, "invalid number: %s", curr->args); } } else { nx_conf_error(curr, "invalid keyword: %s", curr->directive); } curr = curr->next; } if ( (modconf->headerline == NULL) && (modconf->endline == NULL) && (modconf->fixedlinecount == 0) ) { nx_conf_error(module->directives, "At least one of HeaderLine, EndLine or FixedLineCount is required"); } if ( (modconf->headerline != NULL) && (modconf->endline != NULL) && (nx_value_eq(modconf->headerline, modconf->endline) == TRUE) ) { nx_conf_error(module->directives, "HeaderLine and EndLine cannot be the same"); } if ( nx_module_input_func_lookup(module->name) == NULL ) { nx_module_input_func_register(NULL, module->name, &xm_multiline_input_func, module); log_debug("Inputreader '%s' registered", module->name); } }
static void im_tcp_config(nx_module_t *module) { const nx_directive_t *curr; nx_im_tcp_conf_t *imconf; unsigned int port; ASSERT(module->directives != NULL); curr = module->directives; imconf = apr_pcalloc(module->pool, sizeof(nx_im_tcp_conf_t)); module->config = imconf; imconf->nodelay = TRUE; while ( curr != NULL ) { if ( nx_module_common_keyword(curr->directive) == TRUE ) { } else if ( strcasecmp(curr->directive, "host") == 0 ) { if ( imconf->host != NULL ) { nx_conf_error(curr, "host is already defined"); } imconf->host = apr_pstrdup(module->pool, curr->args); } else if ( strcasecmp(curr->directive, "port") == 0 ) { if ( imconf->port != 0 ) { nx_conf_error(curr, "port is already defined"); } if ( sscanf(curr->args, "%u", &port) != 1 ) { nx_conf_error(curr, "invalid port: %s", curr->args); } imconf->port = (apr_port_t) port; } else if ( strcasecmp(curr->directive, "nodelay") == 0 ) { } else if ( strcasecmp(curr->directive, "InputType") == 0 ) { if ( imconf->inputfunc != NULL ) { nx_conf_error(curr, "InputType is already defined"); } if ( curr->args != NULL ) { imconf->inputfunc = nx_module_input_func_lookup(curr->args); } if ( imconf->inputfunc == NULL ) { nx_conf_error(curr, "Invalid InputType '%s'", curr->args); } } else { nx_conf_error(curr, "invalid keyword: %s", curr->directive); } curr = curr->next; } nx_cfg_get_boolean(module->directives, "nodelay", &(imconf->nodelay)); if ( imconf->inputfunc == NULL ) { imconf->inputfunc = nx_module_input_func_lookup("linebased"); } ASSERT(imconf->inputfunc != NULL); if ( imconf->host == NULL ) { imconf->host = apr_pstrdup(module->pool, IM_TCP_DEFAULT_HOST); } if ( imconf->port == 0 ) { imconf->port = IM_TCP_DEFAULT_PORT; } module->input.pool = nx_pool_create_child(module->pool); imconf->connections = apr_pcalloc(module->pool, sizeof(nx_module_input_list_t)); }