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

@ -44,22 +44,32 @@
HINT * HINT *
hint_dup(HINT *hint) hint_dup(HINT *hint)
{ {
HINT *nlhead = NULL, *nltail = NULL, *ptr1, *ptr2; HINT *nlhead = NULL, *nltail = NULL, *ptr1, *ptr2;
ptr1 = hint; ptr1 = hint;
while (ptr1) while (ptr1)
{ {
if ((ptr2 = (HINT *)malloc(sizeof(HINT))) == NULL) if ((ptr2 = (HINT *)malloc(sizeof(HINT))) == NULL)
{
return nlhead; return nlhead;
}
ptr2->type = ptr1->type; ptr2->type = ptr1->type;
if (ptr1->data) if (ptr1->data)
{
ptr2->data = strdup(ptr1->data); ptr2->data = strdup(ptr1->data);
}
else else
{
ptr2->data = NULL; ptr2->data = NULL;
}
if (ptr1->value) if (ptr1->value)
{
ptr2->value = strdup(ptr1->value); ptr2->value = strdup(ptr1->value);
}
else else
{
ptr2->value = NULL; ptr2->value = NULL;
}
ptr2->next = NULL; ptr2->next = NULL;
if (nltail) if (nltail)
{ {
@ -87,16 +97,22 @@ HINT *nlhead = NULL, *nltail = NULL, *ptr1, *ptr2;
HINT * HINT *
hint_create_route(HINT *head, HINT_TYPE type, char *data) hint_create_route(HINT *head, HINT_TYPE type, char *data)
{ {
HINT *hint; HINT *hint;
if ((hint = (HINT *)malloc(sizeof(HINT))) == NULL) if ((hint = (HINT *)malloc(sizeof(HINT))) == NULL)
{
return head; return head;
}
hint->next = head; hint->next = head;
hint->type = type; hint->type = type;
if (data) if (data)
{
hint->data = strdup(data); hint->data = strdup(data);
}
else else
{
hint->data = NULL; hint->data = NULL;
}
hint->value = NULL; hint->value = NULL;
return hint; return hint;
} }
@ -112,10 +128,12 @@ HINT *hint;
HINT * HINT *
hint_create_parameter(HINT *head, char *pname, char *value) hint_create_parameter(HINT *head, char *pname, char *value)
{ {
HINT *hint; HINT *hint;
if ((hint = (HINT *)malloc(sizeof(HINT))) == NULL) if ((hint = (HINT *)malloc(sizeof(HINT))) == NULL)
{
return head; return head;
}
hint->next = head; hint->next = head;
hint->type = HINT_PARAMETER; hint->type = HINT_PARAMETER;
hint->data = strdup(pname); hint->data = strdup(pname);
@ -132,14 +150,17 @@ void
hint_free(HINT *hint) hint_free(HINT *hint)
{ {
if (hint->data) if (hint->data)
{
free(hint->data); free(hint->data);
}
if (hint->value) if (hint->value)
{
free(hint->value); free(hint->value);
}
free(hint); free(hint);
} }
bool hint_exists( bool hint_exists(HINT** p_hint,
HINT** p_hint,
HINT_TYPE type) HINT_TYPE type)
{ {
bool succp = false; bool succp = false;

View File

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