Reindented server/core/hint.c

This commit is contained in:
Johan Wikman
2015-11-30 13:47:56 +02:00
parent 255a5b53c1
commit 486f724dc1
2 changed files with 120 additions and 97 deletions

View File

@ -50,16 +50,26 @@ HINT *nlhead = NULL, *nltail = NULL, *ptr1, *ptr2;
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)
{
@ -90,13 +100,19 @@ hint_create_route(HINT *head, HINT_TYPE type, char *data)
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;
}
@ -115,7 +131,9 @@ hint_create_parameter(HINT *head, char *pname, char *value)
HINT *hint;
if ((hint = (HINT *)malloc(sizeof(HINT))) == NULL)
{
return head;
}
hint->next = head;
hint->type = HINT_PARAMETER;
hint->data = strdup(pname);
@ -132,14 +150,17 @@ void
hint_free(HINT *hint)
{
if (hint->data)
{
free(hint->data);
}
if (hint->value)
{
free(hint->value);
}
free(hint);
}
bool hint_exists(
HINT** p_hint,
bool hint_exists(HINT** p_hint,
HINT_TYPE type)
{
bool succp = false;

View File

@ -36,7 +36,8 @@
/**
* The types of hint that are supported by the generic hinting mechanism.
*/
typedef enum {
typedef enum
{
HINT_ROUTE_TO_MASTER = 1,
HINT_ROUTE_TO_SLAVE,
HINT_ROUTE_TO_NAMED_SERVER,
@ -52,7 +53,8 @@ typedef enum {
* specific data.
* Multiple hints may be attached to a single buffer.
*/
typedef struct hint {
typedef struct hint
{
HINT_TYPE type; /*< The Type of hint */
void *data; /*< Type specific data */
void *value; /*< Parameter value for hint */