Reindented server/core/filter.c
This commit is contained in:
@ -56,7 +56,9 @@ filter_alloc(char *name, char *module)
|
|||||||
FILTER_DEF *filter;
|
FILTER_DEF *filter;
|
||||||
|
|
||||||
if ((filter = (FILTER_DEF *)malloc(sizeof(FILTER_DEF))) == NULL)
|
if ((filter = (FILTER_DEF *)malloc(sizeof(FILTER_DEF))) == NULL)
|
||||||
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
filter->name = strdup(name);
|
filter->name = strdup(name);
|
||||||
filter->module = strdup(module);
|
filter->module = strdup(module);
|
||||||
filter->filter = NULL;
|
filter->filter = NULL;
|
||||||
@ -102,8 +104,10 @@ FILTER_DEF *ptr;
|
|||||||
ptr = ptr->next;
|
ptr = ptr->next;
|
||||||
}
|
}
|
||||||
if (ptr)
|
if (ptr)
|
||||||
|
{
|
||||||
ptr->next = filter->next;
|
ptr->next = filter->next;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
spinlock_release(&filter_spin);
|
spinlock_release(&filter_spin);
|
||||||
|
|
||||||
/* Clean up session and free the memory */
|
/* Clean up session and free the memory */
|
||||||
@ -130,7 +134,9 @@ FILTER_DEF *filter;
|
|||||||
while (filter)
|
while (filter)
|
||||||
{
|
{
|
||||||
if (strcmp(filter->name, name) == 0)
|
if (strcmp(filter->name, name) == 0)
|
||||||
|
{
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
filter = filter->next;
|
filter = filter->next;
|
||||||
}
|
}
|
||||||
spinlock_release(&filter_spin);
|
spinlock_release(&filter_spin);
|
||||||
@ -146,7 +152,9 @@ int
|
|||||||
filter_standard_parameter(char *name)
|
filter_standard_parameter(char *name)
|
||||||
{
|
{
|
||||||
if (strcmp(name, "type") == 0 || strcmp(name, "module") == 0)
|
if (strcmp(name, "type") == 0 || strcmp(name, "module") == 0)
|
||||||
|
{
|
||||||
return 1;
|
return 1;
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,13 +180,19 @@ int i;
|
|||||||
{
|
{
|
||||||
dcb_printf(dcb, "\tOptions: ");
|
dcb_printf(dcb, "\tOptions: ");
|
||||||
for (i = 0; ptr->options && ptr->options[i]; i++)
|
for (i = 0; ptr->options && ptr->options[i]; i++)
|
||||||
|
{
|
||||||
dcb_printf(dcb, "%s ", ptr->options[i]);
|
dcb_printf(dcb, "%s ", ptr->options[i]);
|
||||||
|
}
|
||||||
dcb_printf(dcb, "\n");
|
dcb_printf(dcb, "\n");
|
||||||
}
|
}
|
||||||
if (ptr->obj && ptr->filter)
|
if (ptr->obj && ptr->filter)
|
||||||
|
{
|
||||||
ptr->obj->diagnostics(ptr->filter, NULL, dcb);
|
ptr->obj->diagnostics(ptr->filter, NULL, dcb);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
dcb_printf(dcb, "\tModule not loaded.\n");
|
dcb_printf(dcb, "\tModule not loaded.\n");
|
||||||
|
}
|
||||||
ptr = ptr->next;
|
ptr = ptr->next;
|
||||||
}
|
}
|
||||||
spinlock_release(&filter_spin);
|
spinlock_release(&filter_spin);
|
||||||
@ -201,12 +215,16 @@ int i;
|
|||||||
{
|
{
|
||||||
dcb_printf(dcb, "\tOptions: ");
|
dcb_printf(dcb, "\tOptions: ");
|
||||||
for (i = 0; filter->options && filter->options[i]; i++)
|
for (i = 0; filter->options && filter->options[i]; i++)
|
||||||
|
{
|
||||||
dcb_printf(dcb, "%s ", filter->options[i]);
|
dcb_printf(dcb, "%s ", filter->options[i]);
|
||||||
|
}
|
||||||
dcb_printf(dcb, "\n");
|
dcb_printf(dcb, "\n");
|
||||||
}
|
}
|
||||||
if (filter->obj && filter->filter)
|
if (filter->obj && filter->filter)
|
||||||
|
{
|
||||||
filter->obj->diagnostics(filter->filter, NULL, dcb);
|
filter->obj->diagnostics(filter->filter, NULL, dcb);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List all filters in a tabular form to a DCB
|
* List all filters in a tabular form to a DCB
|
||||||
@ -233,12 +251,17 @@ int i;
|
|||||||
dcb_printf(dcb, "%-19s | %-15s | ",
|
dcb_printf(dcb, "%-19s | %-15s | ",
|
||||||
ptr->name, ptr->module);
|
ptr->name, ptr->module);
|
||||||
for (i = 0; ptr->options && ptr->options[i]; i++)
|
for (i = 0; ptr->options && ptr->options[i]; i++)
|
||||||
|
{
|
||||||
dcb_printf(dcb, "%s ", ptr->options[i]);
|
dcb_printf(dcb, "%s ", ptr->options[i]);
|
||||||
|
}
|
||||||
dcb_printf(dcb, "\n");
|
dcb_printf(dcb, "\n");
|
||||||
ptr = ptr->next;
|
ptr = ptr->next;
|
||||||
}
|
}
|
||||||
if (allFilters)
|
if (allFilters)
|
||||||
dcb_printf(dcb, "--------------------+-----------------+----------------------------------------\n\n");
|
{
|
||||||
|
dcb_printf(dcb,
|
||||||
|
"--------------------+-----------------+----------------------------------------\n\n");
|
||||||
|
}
|
||||||
spinlock_release(&filter_spin);
|
spinlock_release(&filter_spin);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -263,9 +286,10 @@ int i;
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
for (i = 0; filter->options[i]; i++)
|
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] = strdup(option);
|
||||||
filter->options[i+1] = NULL;
|
filter->options[i+1] = NULL;
|
||||||
}
|
}
|
||||||
@ -293,7 +317,9 @@ int i;
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
for (i = 0; filter->parameters[i]; i++)
|
for (i = 0; filter->parameters[i]; i++)
|
||||||
|
{
|
||||||
;
|
;
|
||||||
|
}
|
||||||
filter->parameters = (FILTER_PARAMETER **)realloc(filter->parameters,
|
filter->parameters = (FILTER_PARAMETER **)realloc(filter->parameters,
|
||||||
(i + 2) * sizeof(FILTER_PARAMETER *));
|
(i + 2) * sizeof(FILTER_PARAMETER *));
|
||||||
}
|
}
|
||||||
@ -401,7 +427,9 @@ UPSTREAM *me = NULL;
|
|||||||
* not require to see results and can be left out of the chain.
|
* not require to see results and can be left out of the chain.
|
||||||
*/
|
*/
|
||||||
if (filter->obj->setUpstream == NULL)
|
if (filter->obj->setUpstream == NULL)
|
||||||
|
{
|
||||||
return upstream;
|
return upstream;
|
||||||
|
}
|
||||||
|
|
||||||
if (filter->obj->clientReply != NULL)
|
if (filter->obj->clientReply != NULL)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -41,7 +41,8 @@ typedef void *FILTER;
|
|||||||
/**
|
/**
|
||||||
* The structure used to pass name, value pairs to the filter instances
|
* The structure used to pass name, value pairs to the filter instances
|
||||||
*/
|
*/
|
||||||
typedef struct {
|
typedef struct
|
||||||
|
{
|
||||||
char *name; /**< Name of the parameter */
|
char *name; /**< Name of the parameter */
|
||||||
char *value; /**< Value of the parameter */
|
char *value; /**< Value of the parameter */
|
||||||
} FILTER_PARAMETER;
|
} FILTER_PARAMETER;
|
||||||
@ -69,7 +70,8 @@ typedef struct {
|
|||||||
*
|
*
|
||||||
* @see load_module
|
* @see load_module
|
||||||
*/
|
*/
|
||||||
typedef struct filter_object {
|
typedef struct filter_object
|
||||||
|
{
|
||||||
FILTER *(*createInstance)(char **options, FILTER_PARAMETER **);
|
FILTER *(*createInstance)(char **options, FILTER_PARAMETER **);
|
||||||
void *(*newSession)(FILTER *instance, SESSION *session);
|
void *(*newSession)(FILTER *instance, SESSION *session);
|
||||||
void (*closeSession)(FILTER *instance, void *fsession);
|
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
|
* This is basically the link between a plugin to load and the
|
||||||
* optons to pass to that plugin.
|
* optons to pass to that plugin.
|
||||||
*/
|
*/
|
||||||
typedef struct filter_def {
|
typedef struct filter_def
|
||||||
|
{
|
||||||
char *name; /**< The Filter name */
|
char *name; /**< The Filter name */
|
||||||
char *module; /**< The module to load */
|
char *module; /**< The module to load */
|
||||||
char **options; /**< The options set for this filter */
|
char **options; /**< The options set for this filter */
|
||||||
FILTER_PARAMETER
|
FILTER_PARAMETER **parameters; /**< The filter parameters */
|
||||||
**parameters; /**< The filter parameters */
|
|
||||||
FILTER filter; /**< The runtime filter */
|
FILTER filter; /**< The runtime filter */
|
||||||
FILTER_OBJECT *obj; /**< The "MODULE_OBJECT" for the filter */
|
FILTER_OBJECT *obj; /**< The "MODULE_OBJECT" for the filter */
|
||||||
SPINLOCK spin; /**< Spinlock to protect the filter definition */
|
SPINLOCK spin; /**< Spinlock to protect the filter definition */
|
||||||
struct filter_def
|
struct filter_def *next; /**< Next filter in the chain of all filters */
|
||||||
*next; /**< Next filter in the chain of all filters */
|
|
||||||
} FILTER_DEF;
|
} FILTER_DEF;
|
||||||
|
|
||||||
FILTER_DEF *filter_alloc(char *, char *);
|
FILTER_DEF *filter_alloc(char *, char *);
|
||||||
@ -117,4 +118,5 @@ int filter_standard_parameter(char *);
|
|||||||
void dprintAllFilters(DCB *);
|
void dprintAllFilters(DCB *);
|
||||||
void dprintFilter(DCB *, FILTER_DEF *);
|
void dprintFilter(DCB *, FILTER_DEF *);
|
||||||
void dListFilters(DCB *);
|
void dListFilters(DCB *);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user