Reindented server/core/filter.c
This commit is contained in:
@ -53,10 +53,12 @@ static FILTER_DEF *allFilters = NULL; /**< The list of all filters */
|
||||
FILTER_DEF *
|
||||
filter_alloc(char *name, char *module)
|
||||
{
|
||||
FILTER_DEF *filter;
|
||||
FILTER_DEF *filter;
|
||||
|
||||
if ((filter = (FILTER_DEF *)malloc(sizeof(FILTER_DEF))) == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
filter->name = strdup(name);
|
||||
filter->module = strdup(module);
|
||||
filter->filter = NULL;
|
||||
@ -84,7 +86,7 @@ FILTER_DEF *filter;
|
||||
void
|
||||
filter_free(FILTER_DEF *filter)
|
||||
{
|
||||
FILTER_DEF *ptr;
|
||||
FILTER_DEF *ptr;
|
||||
|
||||
if (filter)
|
||||
{
|
||||
@ -102,8 +104,10 @@ FILTER_DEF *ptr;
|
||||
ptr = ptr->next;
|
||||
}
|
||||
if (ptr)
|
||||
{
|
||||
ptr->next = filter->next;
|
||||
}
|
||||
}
|
||||
spinlock_release(&filter_spin);
|
||||
|
||||
/* Clean up session and free the memory */
|
||||
@ -123,14 +127,16 @@ FILTER_DEF *ptr;
|
||||
FILTER_DEF *
|
||||
filter_find(char *name)
|
||||
{
|
||||
FILTER_DEF *filter;
|
||||
FILTER_DEF *filter;
|
||||
|
||||
spinlock_acquire(&filter_spin);
|
||||
filter = allFilters;
|
||||
while (filter)
|
||||
{
|
||||
if (strcmp(filter->name, name) == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
filter = filter->next;
|
||||
}
|
||||
spinlock_release(&filter_spin);
|
||||
@ -146,7 +152,9 @@ int
|
||||
filter_standard_parameter(char *name)
|
||||
{
|
||||
if (strcmp(name, "type") == 0 || strcmp(name, "module") == 0)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -159,8 +167,8 @@ filter_standard_parameter(char *name)
|
||||
void
|
||||
dprintAllFilters(DCB *dcb)
|
||||
{
|
||||
FILTER_DEF *ptr;
|
||||
int i;
|
||||
FILTER_DEF *ptr;
|
||||
int i;
|
||||
|
||||
spinlock_acquire(&filter_spin);
|
||||
ptr = allFilters;
|
||||
@ -172,13 +180,19 @@ int i;
|
||||
{
|
||||
dcb_printf(dcb, "\tOptions: ");
|
||||
for (i = 0; ptr->options && ptr->options[i]; i++)
|
||||
{
|
||||
dcb_printf(dcb, "%s ", ptr->options[i]);
|
||||
}
|
||||
dcb_printf(dcb, "\n");
|
||||
}
|
||||
if (ptr->obj && ptr->filter)
|
||||
{
|
||||
ptr->obj->diagnostics(ptr->filter, NULL, dcb);
|
||||
}
|
||||
else
|
||||
{
|
||||
dcb_printf(dcb, "\tModule not loaded.\n");
|
||||
}
|
||||
ptr = ptr->next;
|
||||
}
|
||||
spinlock_release(&filter_spin);
|
||||
@ -193,7 +207,7 @@ int i;
|
||||
void
|
||||
dprintFilter(DCB *dcb, FILTER_DEF *filter)
|
||||
{
|
||||
int i;
|
||||
int i;
|
||||
|
||||
dcb_printf(dcb, "Filter %p (%s)\n", filter, filter->name);
|
||||
dcb_printf(dcb, "\tModule: %s\n", filter->module);
|
||||
@ -201,11 +215,15 @@ int i;
|
||||
{
|
||||
dcb_printf(dcb, "\tOptions: ");
|
||||
for (i = 0; filter->options && filter->options[i]; i++)
|
||||
{
|
||||
dcb_printf(dcb, "%s ", filter->options[i]);
|
||||
}
|
||||
dcb_printf(dcb, "\n");
|
||||
}
|
||||
if (filter->obj && filter->filter)
|
||||
{
|
||||
filter->obj->diagnostics(filter->filter, NULL, dcb);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -215,8 +233,8 @@ int i;
|
||||
void
|
||||
dListFilters(DCB *dcb)
|
||||
{
|
||||
FILTER_DEF *ptr;
|
||||
int i;
|
||||
FILTER_DEF *ptr;
|
||||
int i;
|
||||
|
||||
spinlock_acquire(&filter_spin);
|
||||
ptr = allFilters;
|
||||
@ -233,12 +251,17 @@ int i;
|
||||
dcb_printf(dcb, "%-19s | %-15s | ",
|
||||
ptr->name, ptr->module);
|
||||
for (i = 0; ptr->options && ptr->options[i]; i++)
|
||||
{
|
||||
dcb_printf(dcb, "%s ", ptr->options[i]);
|
||||
}
|
||||
dcb_printf(dcb, "\n");
|
||||
ptr = ptr->next;
|
||||
}
|
||||
if (allFilters)
|
||||
dcb_printf(dcb, "--------------------+-----------------+----------------------------------------\n\n");
|
||||
{
|
||||
dcb_printf(dcb,
|
||||
"--------------------+-----------------+----------------------------------------\n\n");
|
||||
}
|
||||
spinlock_release(&filter_spin);
|
||||
}
|
||||
|
||||
@ -251,7 +274,7 @@ int i;
|
||||
void
|
||||
filterAddOption(FILTER_DEF *filter, char *option)
|
||||
{
|
||||
int i;
|
||||
int i;
|
||||
|
||||
spinlock_acquire(&filter->spin);
|
||||
if (filter->options == NULL)
|
||||
@ -263,9 +286,10 @@ int i;
|
||||
else
|
||||
{
|
||||
for (i = 0; filter->options[i]; i++)
|
||||
{
|
||||
;
|
||||
filter->options = (char **)realloc(filter->options,
|
||||
(i + 2) * sizeof(char *));
|
||||
}
|
||||
filter->options = (char **)realloc(filter->options, (i + 2) * sizeof(char *));
|
||||
filter->options[i] = strdup(option);
|
||||
filter->options[i+1] = NULL;
|
||||
}
|
||||
@ -282,7 +306,7 @@ int i;
|
||||
void
|
||||
filterAddParameter(FILTER_DEF *filter, char *name, char *value)
|
||||
{
|
||||
int i;
|
||||
int i;
|
||||
|
||||
spinlock_acquire(&filter->spin);
|
||||
if (filter->parameters == NULL)
|
||||
@ -293,7 +317,9 @@ int i;
|
||||
else
|
||||
{
|
||||
for (i = 0; filter->parameters[i]; i++)
|
||||
{
|
||||
;
|
||||
}
|
||||
filter->parameters = (FILTER_PARAMETER **)realloc(filter->parameters,
|
||||
(i + 2) * sizeof(FILTER_PARAMETER *));
|
||||
}
|
||||
@ -394,14 +420,16 @@ filterApply(FILTER_DEF *filter, SESSION *session, DOWNSTREAM *downstream)
|
||||
UPSTREAM *
|
||||
filterUpstream(FILTER_DEF *filter, void *fsession, UPSTREAM *upstream)
|
||||
{
|
||||
UPSTREAM *me = NULL;
|
||||
UPSTREAM *me = NULL;
|
||||
|
||||
/*
|
||||
* The the filter has no setUpstream entry point then is does
|
||||
* not require to see results and can be left out of the chain.
|
||||
*/
|
||||
if (filter->obj->setUpstream == NULL)
|
||||
{
|
||||
return upstream;
|
||||
}
|
||||
|
||||
if (filter->obj->clientReply != NULL)
|
||||
{
|
||||
|
||||
@ -41,7 +41,8 @@ typedef void *FILTER;
|
||||
/**
|
||||
* The structure used to pass name, value pairs to the filter instances
|
||||
*/
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
char *name; /**< Name of the parameter */
|
||||
char *value; /**< Value of the parameter */
|
||||
} FILTER_PARAMETER;
|
||||
@ -69,7 +70,8 @@ typedef struct {
|
||||
*
|
||||
* @see load_module
|
||||
*/
|
||||
typedef struct filter_object {
|
||||
typedef struct filter_object
|
||||
{
|
||||
FILTER *(*createInstance)(char **options, FILTER_PARAMETER **);
|
||||
void *(*newSession)(FILTER *instance, SESSION *session);
|
||||
void (*closeSession)(FILTER *instance, void *fsession);
|
||||
@ -92,17 +94,16 @@ typedef struct filter_object {
|
||||
* This is basically the link between a plugin to load and the
|
||||
* optons to pass to that plugin.
|
||||
*/
|
||||
typedef struct filter_def {
|
||||
typedef struct filter_def
|
||||
{
|
||||
char *name; /**< The Filter name */
|
||||
char *module; /**< The module to load */
|
||||
char **options; /**< The options set for this filter */
|
||||
FILTER_PARAMETER
|
||||
**parameters; /**< The filter parameters */
|
||||
FILTER_PARAMETER **parameters; /**< The filter parameters */
|
||||
FILTER filter; /**< The runtime filter */
|
||||
FILTER_OBJECT *obj; /**< The "MODULE_OBJECT" for the filter */
|
||||
SPINLOCK spin; /**< Spinlock to protect the filter definition */
|
||||
struct filter_def
|
||||
*next; /**< Next filter in the chain of all filters */
|
||||
struct filter_def *next; /**< Next filter in the chain of all filters */
|
||||
} FILTER_DEF;
|
||||
|
||||
FILTER_DEF *filter_alloc(char *, char *);
|
||||
@ -117,4 +118,5 @@ int filter_standard_parameter(char *);
|
||||
void dprintAllFilters(DCB *);
|
||||
void dprintFilter(DCB *, FILTER_DEF *);
|
||||
void dListFilters(DCB *);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user