Reindented server/core/hint.c
This commit is contained in:
@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user