コード例 #1
0
ファイル: topfilter.c プロジェクト: DBMSRmutl/MaxScale
/**
 * Create an instance of the filter for a particular service
 * within MaxScale.
 *
 * @param options   The options for this filter
 * @param params    The array of name/value pair parameters for the filter
 *
 * @return The instance data for this new instance
 */
static FILTER *
createInstance(char **options, FILTER_PARAMETER **params)
{
    int i;
    TOPN_INSTANCE *my_instance;

    if ((my_instance = calloc(1, sizeof(TOPN_INSTANCE))) != NULL)
    {
        my_instance->topN = 10;
        my_instance->match = NULL;
        my_instance->exclude = NULL;
        my_instance->source = NULL;
        my_instance->user = NULL;
        my_instance->filebase = strdup("top");
        for (i = 0; params && params[i]; i++)
        {
            if (!strcmp(params[i]->name, "count"))
            {
                my_instance->topN = atoi(params[i]->value);
            }
            else if (!strcmp(params[i]->name, "filebase"))
            {
                free(my_instance->filebase);
                my_instance->filebase = strdup(params[i]->value);
            }
            else if (!strcmp(params[i]->name, "match"))
            {
                my_instance->match = strdup(params[i]->value);
            }
            else if (!strcmp(params[i]->name, "exclude"))
            {
                my_instance->exclude = strdup(params[i]->value);
            }
            else if (!strcmp(params[i]->name, "source"))
            {
                my_instance->source = strdup(params[i]->value);
            }
            else if (!strcmp(params[i]->name, "user"))
            {
                my_instance->user = strdup(params[i]->value);
            }
            else if (!filter_standard_parameter(params[i]->name))
            {
                MXS_ERROR("topfilter: Unexpected parameter '%s'.",
                          params[i]->name);
            }
        }
        if (options)
        {
            MXS_ERROR("topfilter: Options are not supported by this "
                      " filter. They will be ignored.");
        }
        my_instance->sessions = 0;
        if (my_instance->match &&
            regcomp(&my_instance->re, my_instance->match, REG_ICASE))
        {
            MXS_ERROR("topfilter: Invalid regular expression '%s'"
                      " for the match parameter.",
                      my_instance->match);
            free(my_instance->match);
            free(my_instance->source);
            free(my_instance->user);
            free(my_instance->filebase);
            free(my_instance);
            return NULL;
        }
        if (my_instance->exclude &&
            regcomp(&my_instance->exre, my_instance->exclude,
                    REG_ICASE))
        {
            MXS_ERROR("qlafilter: Invalid regular expression '%s'"
                      " for the nomatch paramter.\n",
                      my_instance->match);
            regfree(&my_instance->re);
            free(my_instance->match);
            free(my_instance->source);
            free(my_instance->user);
            free(my_instance->filebase);
            free(my_instance);
            return NULL;
        }
    }
    return(FILTER *) my_instance;
}
コード例 #2
0
ファイル: luafilter.c プロジェクト: bigshuai/MaxScale
/**
 * Create a new instance of the Lua filter.
 *
 * The global script will be loaded in this function and executed once on a global
 * level before calling the createInstance function in the Lua script.
 * @param options The options for this filter
 * @param params  Filter parameters
 * @return The instance data for this new instance
 */
static FILTER *
createInstance(char **options, FILTER_PARAMETER **params)
{
    LUA_INSTANCE *my_instance;
    bool error = false;

    if ((my_instance = (LUA_INSTANCE*) calloc(1, sizeof(LUA_INSTANCE))) == NULL)
    {
        return NULL;
    }

    spinlock_init(&my_instance->lock);

    for (int i = 0; params[i] && !error; i++)
    {
        if (strcmp(params[i]->name, "global_script") == 0)
        {
            error = (my_instance->global_script = strdup(params[i]->value)) == NULL;
        }
        else if (strcmp(params[i]->name, "session_script") == 0)
        {
            error = (my_instance->session_script = strdup(params[i]->value)) == NULL;
        }
        else if (!filter_standard_parameter(params[i]->name))
        {
            MXS_ERROR("Unexpected parameter '%s'", params[i]->name);
            error = true;
        }
    }

    if (error)
    {
        free(my_instance->global_script);
        free(my_instance->session_script);
        free(my_instance);
        return NULL;
    }

    if (my_instance->global_script)
    {
        if ((my_instance->global_lua_state = luaL_newstate()))
        {
            luaL_openlibs(my_instance->global_lua_state);

            if (luaL_dofile(my_instance->global_lua_state, my_instance->global_script))
            {
                MXS_ERROR("luafilter: Failed to execute global script at '%s':%s.",
                          my_instance->global_script, lua_tostring(my_instance->global_lua_state, -1));
                free(my_instance->global_script);
                free(my_instance->session_script);
                free(my_instance);
                my_instance = NULL;
            }
            else if (my_instance->global_lua_state)
            {
                lua_getglobal(my_instance->global_lua_state, "createInstance");
                if (lua_pcall(my_instance->global_lua_state, 0, 0, 0))
                {
                    MXS_WARNING("luafilter: Failed to get global variable 'createInstance':  %s."
                                " The createInstance entry point will not be called for the global script.",
                                lua_tostring(my_instance->global_lua_state, -1));
                }
            }
        }
        else
        {
            MXS_ERROR("Unable to initialize new Lua state.");
            free(my_instance);
            my_instance = NULL;
        }
    }

    return(FILTER *) my_instance;
}
コード例 #3
0
ファイル: qlafilter.c プロジェクト: littleyang/MaxScale
/**
 * Create an instance of the filter for a particular service
 * within MaxScale.
 * 
 * @param options	The options for this filter
 * @param params	The array of name/value pair parameters for the filter
 *
 * @return The instance data for this new instance
 */
static	FILTER	*
createInstance(char **options, FILTER_PARAMETER **params)
{
QLA_INSTANCE	*my_instance;
int		i;

	if ((my_instance = calloc(1, sizeof(QLA_INSTANCE))) != NULL)
	{
		if (options){
			my_instance->filebase = strdup(options[0]);
		}else{
			my_instance->filebase = strdup("qla");
		}
		my_instance->source = NULL;
		my_instance->userName = NULL;
		my_instance->match = NULL;
		my_instance->nomatch = NULL;
		if (params)
		{
			for (i = 0; params[i]; i++)
			{
				if (!strcmp(params[i]->name, "match"))
				{
					my_instance->match = strdup(params[i]->value);
				}
				else if (!strcmp(params[i]->name, "exclude"))
				{
					my_instance->nomatch = strdup(params[i]->value);
				}
				else if (!strcmp(params[i]->name, "source"))
					my_instance->source = strdup(params[i]->value);
				else if (!strcmp(params[i]->name, "user"))
					my_instance->userName = strdup(params[i]->value);
				else if (!strcmp(params[i]->name, "filebase"))
				{
					if (my_instance->filebase){
						free(my_instance->filebase);
						my_instance->filebase = NULL;
					}
					my_instance->filebase = strdup(params[i]->value);
				}
				else if (!filter_standard_parameter(params[i]->name))
				{
					LOGIF(LE, (skygw_log_write_flush(
						LOGFILE_ERROR,
						"qlafilter: Unexpected parameter '%s'.\n",
						params[i]->name)));
				}
			}
		}
		my_instance->sessions = 0;
		if (my_instance->match &&
			regcomp(&my_instance->re, my_instance->match, REG_ICASE))
		{
			LOGIF(LE, (skygw_log_write_flush(LOGFILE_ERROR,
				"qlafilter: Invalid regular expression '%s'"
				" for the match parameter.\n",
					my_instance->match)));
			free(my_instance->match);
			free(my_instance->source);
			if(my_instance->filebase){
				free(my_instance->filebase);
			}
			free(my_instance);
			return NULL;
		}
		if (my_instance->nomatch &&
			regcomp(&my_instance->nore, my_instance->nomatch,
								REG_ICASE))
		{
			LOGIF(LE, (skygw_log_write_flush(LOGFILE_ERROR,
				"qlafilter: Invalid regular expression '%s'"
				" for the nomatch paramter.\n",
					my_instance->match)));
			if (my_instance->match)
				regfree(&my_instance->re);
			free(my_instance->match);
			free(my_instance->source);
			if(my_instance->filebase){
				free(my_instance->filebase);
			}
			free(my_instance);
			return NULL;
		}
	}
	return (FILTER *)my_instance;
}
コード例 #4
0
ファイル: tee.c プロジェクト: DBMSRmutl/MaxScale
/**
 * Create an instance of the filter for a particular service
 * within MaxScale.
 *
 * @param options	The options for this filter
 * @param params	The array of name/value pair parameters for the filter
 *
 * @return The instance data for this new instance
 */
static FILTER *
createInstance(char **options, FILTER_PARAMETER **params)
{
    TEE_INSTANCE *my_instance;
    int i;

    if ((my_instance = calloc(1, sizeof(TEE_INSTANCE))) != NULL)
    {
        if (options)
        {
            MXS_ERROR("tee: The tee filter has been passed an option, "
                      "this filter does not support any options.");
        }
        my_instance->service = NULL;
        my_instance->source = NULL;
        my_instance->userName = NULL;
        my_instance->match = NULL;
        my_instance->nomatch = NULL;
        if (params)
        {
            for (i = 0; params[i]; i++)
            {
                if (!strcmp(params[i]->name, "service"))
                {
                    if ((my_instance->service = service_find(params[i]->value)) == NULL)
                    {
                        MXS_ERROR("tee: service '%s' not found.\n",
                                  params[i]->value);
                    }
                }
                else if (!strcmp(params[i]->name, "match"))
                {
                    my_instance->match = strdup(params[i]->value);
                }
                else if (!strcmp(params[i]->name, "exclude"))
                {
                    my_instance->nomatch = strdup(params[i]->value);
                }
                else if (!strcmp(params[i]->name, "source"))
                {
                    my_instance->source = strdup(params[i]->value);
                }
                else if (!strcmp(params[i]->name, "user"))
                {
                    my_instance->userName = strdup(params[i]->value);
                }
                else if (!filter_standard_parameter(params[i]->name))
                {
                    MXS_ERROR("tee: Unexpected parameter '%s'.",
                              params[i]->name);
                }
            }
        }
        if (my_instance->service == NULL)
        {
            free(my_instance->match);
            free(my_instance->source);
            free(my_instance);
            return NULL;
        }

        if (my_instance->match &&
            regcomp(&my_instance->re, my_instance->match, REG_ICASE))
        {
            MXS_ERROR("tee: Invalid regular expression '%s'"
                      " for the match parameter.",
                      my_instance->match);
            free(my_instance->match);
            free(my_instance->source);
            free(my_instance);
            return NULL;
        }
        if (my_instance->nomatch &&
            regcomp(&my_instance->nore, my_instance->nomatch,
                    REG_ICASE))
        {
            MXS_ERROR("tee: Invalid regular expression '%s'"
                      " for the nomatch paramter.\n",
                      my_instance->match);
            if (my_instance->match)
                regfree(&my_instance->re);
            free(my_instance->match);
            free(my_instance->source);
            free(my_instance);
            return NULL;
        }
    }
    return(FILTER *) my_instance;
}