Make gwbuf_{add|get}_property const correct

The function now takes const arguments.
This commit is contained in:
Markus Mäkelä 2018-01-24 20:29:09 +02:00
parent dfbecc41e2
commit 6b877de5bc
2 changed files with 11 additions and 12 deletions

View File

@ -355,7 +355,7 @@ extern void gwbuf_set_type(GWBUF *head, uint32_t type);
*
* @return True on success, false otherwise.
*/
extern bool gwbuf_add_property(GWBUF *buf, char *name, char *value);
extern bool gwbuf_add_property(GWBUF *buf, const char *name, const char *value);
/**
* Return the value of a buffer property
@ -365,7 +365,7 @@ extern bool gwbuf_add_property(GWBUF *buf, char *name, char *value);
*
* @return The property value or NULL if the property was not found.
*/
extern char *gwbuf_get_property(GWBUF *buf, char *name);
extern char *gwbuf_get_property(GWBUF *buf, const char *name);
/**
* Convert a chain of GWBUF structures into a single GWBUF structure

View File

@ -738,23 +738,22 @@ static buffer_object_t* gwbuf_remove_buffer_object(GWBUF* buf, buffer_object_t*
}
bool
gwbuf_add_property(GWBUF *buf, char *name, char *value)
gwbuf_add_property(GWBUF *buf, const char *name, const char *value)
{
name = MXS_STRDUP(name);
value = MXS_STRDUP(value);
char* my_name = MXS_STRDUP(name);
char* my_value = MXS_STRDUP(value);
BUF_PROPERTY *prop = (BUF_PROPERTY *)MXS_MALLOC(sizeof(BUF_PROPERTY));
if (!name || !value || !prop)
if (!my_name || !my_value || !prop)
{
MXS_FREE(name);
MXS_FREE(value);
MXS_FREE(my_name);
MXS_FREE(my_value);
MXS_FREE(prop);
return false;
}
prop->name = name;
prop->value = value;
prop->name = my_name;
prop->value = my_value;
spinlock_acquire(&buf->gwbuf_lock);
prop->next = buf->properties;
buf->properties = prop;
@ -763,7 +762,7 @@ gwbuf_add_property(GWBUF *buf, char *name, char *value)
}
char *
gwbuf_get_property(GWBUF *buf, char *name)
gwbuf_get_property(GWBUF *buf, const char *name)
{
BUF_PROPERTY *prop;