vici: Add convenience value/string/integer getter to libvici
This commit is contained in:
@@ -574,6 +574,43 @@ char* vici_parse_value_str(vici_res_t *res)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void* vici_find(vici_res_t *res, int *len, char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list args;
|
||||||
|
chunk_t value;
|
||||||
|
|
||||||
|
va_start(args, fmt);
|
||||||
|
value = res->message->vget_value(res->message, chunk_empty, fmt, args);
|
||||||
|
va_end(args);
|
||||||
|
|
||||||
|
*len = value.len;
|
||||||
|
return value.ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
char* vici_find_str(vici_res_t *res, char *def, char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list args;
|
||||||
|
char *str;
|
||||||
|
|
||||||
|
va_start(args, fmt);
|
||||||
|
str = res->message->vget_str(res->message, def, fmt, args);
|
||||||
|
va_end(args);
|
||||||
|
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
int vici_find_int(vici_res_t *res, int def, char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list args;
|
||||||
|
int val;
|
||||||
|
|
||||||
|
va_start(args, fmt);
|
||||||
|
val = res->message->vget_int(res->message, def, fmt, args);
|
||||||
|
va_end(args);
|
||||||
|
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
void vici_free_res(vici_res_t *res)
|
void vici_free_res(vici_res_t *res)
|
||||||
{
|
{
|
||||||
res->strings->destroy_function(res->strings, free);
|
res->strings->destroy_function(res->strings, free);
|
||||||
|
|||||||
@@ -307,6 +307,45 @@ void* vici_parse_value(vici_res_t *res, int *len);
|
|||||||
*/
|
*/
|
||||||
char* vici_parse_value_str(vici_res_t *res);
|
char* vici_parse_value_str(vici_res_t *res);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find a blob value in a message for a given key.
|
||||||
|
*
|
||||||
|
* Sections can be selected by prefixing them separated by dots.
|
||||||
|
*
|
||||||
|
* @param res response message to parse
|
||||||
|
* @param len length of returned object
|
||||||
|
* @param fmt printf format string of key and sections
|
||||||
|
* @param ... arguments to format string
|
||||||
|
* @return blob value, having *len bytes, NULL if not found
|
||||||
|
*/
|
||||||
|
void *vici_find(vici_res_t *res, int *len, char *fmt, ...);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find a string value in a message for a given key.
|
||||||
|
*
|
||||||
|
* Sections can be selected by prefixing them separated by dots.
|
||||||
|
*
|
||||||
|
* @param res response message to parse
|
||||||
|
* @param def default value, if key not found
|
||||||
|
* @param fmt printf format string of key and sections
|
||||||
|
* @param ... arguments to format string
|
||||||
|
* @return string, def if not found
|
||||||
|
*/
|
||||||
|
char* vici_find_str(vici_res_t *res, char *def, char *fmt, ...);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find an integer value in a message for a given key.
|
||||||
|
*
|
||||||
|
* Sections can be selected by prefixing them separated by dots.
|
||||||
|
*
|
||||||
|
* @param res response message to parse
|
||||||
|
* @param def default value, if key not found
|
||||||
|
* @param fmt printf format string of key and sections
|
||||||
|
* @param ... arguments to format string
|
||||||
|
* @return integer value, def if not found
|
||||||
|
*/
|
||||||
|
int vici_find_int(vici_res_t *res, int def, char *fmt, ...);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clean up a received response message.
|
* Clean up a received response message.
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user