/** * \internal * \brief Retrieves a value for a yaml mapping. The sequence from the yaml * conf file, from which the conf value has to be retrieved can be * specified by supplying a SCRuleVarsType enum. The string mapping * for each of the SCRuleVarsType is present in sc_rule_vars_type_map. * * \param conf_var_name Pointer to a character string containing the conf var * name, whose value has to be retrieved from the yaml * conf file. * \param conf_vars_type Holds an enum value that indicates the kind of yaml * mapping that has to be retrieved. Can be one of the * values in SCRuleVarsType. * * \retval conf_var_name_value Pointer to the string containing the conf value * on success; NULL on failure. */ char *SCRuleVarsGetConfVar(const char *conf_var_name, SCRuleVarsType conf_vars_type) { SCEnter(); const char *conf_var_type_name = NULL; char conf_var_full_name[1024] = ""; char *conf_var_full_name_value = NULL; if (conf_var_name == NULL) goto end; (conf_var_name[0] == '$') ? conf_var_name++ : conf_var_name; conf_var_type_name = SCMapEnumValueToName(conf_vars_type, sc_rule_vars_type_map); if (conf_var_type_name == NULL) goto end; if (snprintf(conf_var_full_name, sizeof(conf_var_full_name), "%s.%s", conf_var_type_name, conf_var_name) < 0) { goto end; } if (ConfGet(conf_var_full_name, &conf_var_full_name_value) != 1) { SCLogError(SC_ERR_UNDEFINED_VAR, "Variable \"%s\" is not defined in " "configuration file", conf_var_name); goto end; } SCLogDebug("Value obtained from the yaml conf file, for the var " "\"%s\" is \"%s\"", conf_var_name, conf_var_full_name_value); end: SCReturnCharPtr(conf_var_full_name_value); }
/** * \internal * \brief Retrieves a value for a yaml mapping. The sequence from the yaml * conf file, from which the conf value has to be retrieved can be * specified by supplying a SCRuleVarsType enum. The string mapping * for each of the SCRuleVarsType is present in sc_rule_vars_type_map. * * \param conf_var_name Pointer to a character string containing the conf var * name, whose value has to be retrieved from the yaml * conf file. * \param conf_vars_type Holds an enum value that indicates the kind of yaml * mapping that has to be retrieved. Can be one of the * values in SCRuleVarsType. * * \retval conf_var_name_value Pointer to the string containing the conf value * on success; NULL on failure. */ char *SCRuleVarsGetConfVar(const DetectEngineCtx *de_ctx, const char *conf_var_name, SCRuleVarsType conf_vars_type) { SCEnter(); const char *conf_var_type_name = NULL; char conf_var_full_name[2048] = ""; char *conf_var_full_name_value = NULL; if (conf_var_name == NULL) goto end; while (conf_var_name[0] != '\0' && isspace(conf_var_name[0])) { conf_var_name++; } (conf_var_name[0] == '$') ? conf_var_name++ : conf_var_name; conf_var_type_name = SCMapEnumValueToName(conf_vars_type, sc_rule_vars_type_map); if (conf_var_type_name == NULL) goto end; if (de_ctx != NULL && strlen(de_ctx->config_prefix) > 0) { if (snprintf(conf_var_full_name, sizeof(conf_var_full_name), "%s.%s.%s", de_ctx->config_prefix, conf_var_type_name, conf_var_name) < 0) { goto end; } } else { if (snprintf(conf_var_full_name, sizeof(conf_var_full_name), "%s.%s", conf_var_type_name, conf_var_name) < 0) { goto end; } } if (ConfGet(conf_var_full_name, &conf_var_full_name_value) != 1) { SCLogError(SC_ERR_UNDEFINED_VAR, "Variable \"%s\" is not defined in " "configuration file", conf_var_name); goto end; } SCLogDebug("Value obtained from the yaml conf file, for the var " "\"%s\" is \"%s\"", conf_var_name, conf_var_full_name_value); end: SCReturnCharPtr(conf_var_full_name_value); }