diff --git a/server/core/hint.c b/server/core/hint.c index 65a3816c9..abeaf7b4e 100644 --- a/server/core/hint.c +++ b/server/core/hint.c @@ -26,8 +26,8 @@ * @verbatim * Revision History * - * Date Who Description - * 25/07/14 Mark Riddoch Initial implementation + * Date Who Description + * 25/07/14 Mark Riddoch Initial implementation * * @endverbatim */ @@ -36,121 +36,142 @@ /** * Duplicate a list of hints * - * @param hint The hint list to duplicate - * @return A duplicate of the list - * + * @param hint The hint list to duplicate + * @return A duplicate of the list + * * Note : Optimize this to use version numbering instead of copying memory */ HINT * hint_dup(HINT *hint) { -HINT *nlhead = NULL, *nltail = NULL, *ptr1, *ptr2; + HINT *nlhead = NULL, *nltail = NULL, *ptr1, *ptr2; - ptr1 = hint; - while (ptr1) - { - if ((ptr2 = (HINT *)malloc(sizeof(HINT))) == NULL) - return nlhead; - ptr2->type = ptr1->type; - if (ptr1->data) - ptr2->data = strdup(ptr1->data); - else - ptr2->data = NULL; - if (ptr1->value) - ptr2->value = strdup(ptr1->value); - else - ptr2->value = NULL; - ptr2->next = NULL; - if (nltail) - { - nltail->next = ptr2; - nltail = ptr2; - } - else - { - nlhead = ptr2; - nltail = ptr2; - } - ptr1 = ptr1->next; - } - return nlhead; + ptr1 = hint; + while (ptr1) + { + if ((ptr2 = (HINT *)malloc(sizeof(HINT))) == NULL) + { + return nlhead; + } + ptr2->type = ptr1->type; + if (ptr1->data) + { + ptr2->data = strdup(ptr1->data); + } + else + { + ptr2->data = NULL; + } + if (ptr1->value) + { + ptr2->value = strdup(ptr1->value); + } + else + { + ptr2->value = NULL; + } + ptr2->next = NULL; + if (nltail) + { + nltail->next = ptr2; + nltail = ptr2; + } + else + { + nlhead = ptr2; + nltail = ptr2; + } + ptr1 = ptr1->next; + } + return nlhead; } /** * Create a ROUTE TO type hint * - * @param head The current hint list - * @param type The HINT_TYPE - * @param data Data may be NULL or the name of a server to route to + * @param head The current hint list + * @param type The HINT_TYPE + * @param data Data may be NULL or the name of a server to route to * @return The result hint list */ HINT * hint_create_route(HINT *head, HINT_TYPE type, char *data) { -HINT *hint; + HINT *hint; - if ((hint = (HINT *)malloc(sizeof(HINT))) == NULL) - return head; - hint->next = head; - hint->type = type; - if (data) - hint->data = strdup(data); - else - hint->data = NULL; - hint->value = NULL; - return hint; + if ((hint = (HINT *)malloc(sizeof(HINT))) == NULL) + { + return head; + } + hint->next = head; + hint->type = type; + if (data) + { + hint->data = strdup(data); + } + else + { + hint->data = NULL; + } + hint->value = NULL; + return hint; } /** * Create name/value parameter hint * - * @param head The current hint list - * @param pname The parameter name - * @param value The parameter value + * @param head The current hint list + * @param pname The parameter name + * @param value The parameter value * @return The result hint list */ HINT * hint_create_parameter(HINT *head, char *pname, char *value) { -HINT *hint; + HINT *hint; - if ((hint = (HINT *)malloc(sizeof(HINT))) == NULL) - return head; - hint->next = head; - hint->type = HINT_PARAMETER; - hint->data = strdup(pname); - hint->value = strdup(value); - return hint; + if ((hint = (HINT *)malloc(sizeof(HINT))) == NULL) + { + return head; + } + hint->next = head; + hint->type = HINT_PARAMETER; + hint->data = strdup(pname); + hint->value = strdup(value); + return hint; } /** * free_hint - free a hint * - * @param hint The hint to free + * @param hint The hint to free */ void hint_free(HINT *hint) { - if (hint->data) - free(hint->data); - if (hint->value) - free(hint->value); - free(hint); + if (hint->data) + { + free(hint->data); + } + if (hint->value) + { + free(hint->value); + } + free(hint); } -bool hint_exists( - HINT** p_hint, - HINT_TYPE type) +bool hint_exists(HINT** p_hint, + HINT_TYPE type) { - bool succp = false; - - while (*p_hint != NULL) + bool succp = false; + + while (*p_hint != NULL) + { + if ((*p_hint)->type == type) { - if ((*p_hint)->type == type) - { - succp = true; - } - p_hint = &(*p_hint)->next; + succp = true; } - return succp; + p_hint = &(*p_hint)->next; + } + return succp; } diff --git a/server/include/hint.h b/server/include/hint.h index 4cc687731..7eaca1080 100644 --- a/server/include/hint.h +++ b/server/include/hint.h @@ -24,8 +24,8 @@ * @verbatim * Revision History * - * Date Who Description - * 10/07/14 Mark Riddoch Initial implementation + * Date Who Description + * 10/07/14 Mark Riddoch Initial implementation * * @endverbatim */ @@ -36,13 +36,14 @@ /** * The types of hint that are supported by the generic hinting mechanism. */ -typedef enum { - HINT_ROUTE_TO_MASTER = 1, - HINT_ROUTE_TO_SLAVE, - HINT_ROUTE_TO_NAMED_SERVER, - HINT_ROUTE_TO_UPTODATE_SERVER, - HINT_ROUTE_TO_ALL, /*< not implemented yet */ - HINT_PARAMETER +typedef enum +{ + HINT_ROUTE_TO_MASTER = 1, + HINT_ROUTE_TO_SLAVE, + HINT_ROUTE_TO_NAMED_SERVER, + HINT_ROUTE_TO_UPTODATE_SERVER, + HINT_ROUTE_TO_ALL, /*< not implemented yet */ + HINT_PARAMETER } HINT_TYPE; /** @@ -52,18 +53,19 @@ typedef enum { * specific data. * Multiple hints may be attached to a single buffer. */ -typedef struct hint { - HINT_TYPE type; /*< The Type of hint */ - void *data; /*< Type specific data */ - void *value; /*< Parameter value for hint */ - unsigned int dsize; /*< Size of the hint data */ - struct hint *next; /*< Another hint for this buffer */ +typedef struct hint +{ + HINT_TYPE type; /*< The Type of hint */ + void *data; /*< Type specific data */ + void *value; /*< Parameter value for hint */ + unsigned int dsize; /*< Size of the hint data */ + struct hint *next; /*< Another hint for this buffer */ } HINT; -extern HINT *hint_alloc(HINT_TYPE, void *, unsigned int); -extern HINT *hint_create_parameter(HINT *, char *, char *); -extern HINT *hint_create_route(HINT *, HINT_TYPE, char *); -extern void hint_free(HINT *); -extern HINT *hint_dup(HINT *); +extern HINT *hint_alloc(HINT_TYPE, void *, unsigned int); +extern HINT *hint_create_parameter(HINT *, char *, char *); +extern HINT *hint_create_route(HINT *, HINT_TYPE, char *); +extern void hint_free(HINT *); +extern HINT *hint_dup(HINT *); bool hint_exists(HINT **, HINT_TYPE); #endif