mirror of
https://gitlab.xiph.org/xiph/icecast-common.git
synced 2024-12-04 14:46:31 -05:00
Feature: Added flags to igloo_ro_stringify() to support object and content stringification
This commit is contained in:
parent
38eff2ae99
commit
db30985dca
@ -131,12 +131,34 @@ typedef igloo_ro_t (*igloo_ro_convert_t)(igloo_ro_t self, const igloo_ro_type_t
|
||||
*/
|
||||
typedef igloo_ro_t (*igloo_ro_get_interface_t)(igloo_ro_t self, const igloo_ro_type_t *type, const char *name, igloo_ro_t associated);
|
||||
|
||||
/* Type used to store flags for stringify operation.
|
||||
*/
|
||||
#ifdef IGLOO_CTC_HAVE_STDINT_H
|
||||
typedef uint_least32_t igloo_ro_sy_t;
|
||||
#else
|
||||
typedef unsigned long int igloo_ro_sy_t;
|
||||
#endif
|
||||
/* No stringify flags set. Usefull for variable initialization. */
|
||||
#define igloo_RO_SY_NONE ((igloo_ro_sy_t)0x0000)
|
||||
/* Stringify using defaults. */
|
||||
#define igloo_RO_SY_DEFAULT ((igloo_ro_sy_t)0x1000)
|
||||
/* Stringify the object itself, do not touch the content.
|
||||
* When set together with igloo_RO_SY_CONTENT the libigloo will select the mode.
|
||||
*/
|
||||
#define igloo_RO_SY_OBJECT ((igloo_ro_sy_t)0x0001)
|
||||
/* Stringify the object's content.
|
||||
* When set together with igloo_RO_SY_OBJECT the libigloo will select the mode.
|
||||
*/
|
||||
#define igloo_RO_SY_CONTENT ((igloo_ro_sy_t)0x0002)
|
||||
|
||||
/* Type used for callback called when the object needs to be converted to a string.
|
||||
*
|
||||
* This is used mostly for debugging or preseting the object to the user.
|
||||
* The callback is not expected to return a string that can be used to reconstruct the object.
|
||||
*
|
||||
* igloo_RO_SY_OBJECT is always set when this is called.
|
||||
*/
|
||||
typedef char * (*igloo_ro_stringify_t)(igloo_ro_t self);
|
||||
typedef char * (*igloo_ro_stringify_t)(igloo_ro_t self, igloo_ro_sy_t flags);
|
||||
|
||||
/* Type used as a result of a compare between objects.
|
||||
*/
|
||||
@ -350,10 +372,13 @@ igloo_ro_t igloo_ro_get_interface(igloo_ro_t self, const igloo_ro_type_t *type,
|
||||
* Parameters:
|
||||
* self
|
||||
* The object to convert to a string.
|
||||
* flags
|
||||
* Flags used to select options to the conversion.
|
||||
* Should normally be igloo_RO_SY_DEFAULT.
|
||||
* Returns:
|
||||
* A string as allocated using malloc(3). The caller must call free(3).
|
||||
*/
|
||||
char * igloo_ro_stringify(igloo_ro_t self);
|
||||
char * igloo_ro_stringify(igloo_ro_t self, igloo_ro_sy_t flags);
|
||||
|
||||
/* Compare two objects.
|
||||
*
|
||||
|
@ -31,7 +31,7 @@ struct igloo_buffer_tag {
|
||||
};
|
||||
|
||||
static void __free(igloo_ro_t self);
|
||||
static char * __stringify(igloo_ro_t self);
|
||||
static char * __stringify(igloo_ro_t self, igloo_ro_sy_t flags);
|
||||
|
||||
igloo_RO_PUBLIC_TYPE(igloo_buffer_t,
|
||||
igloo_RO_TYPEDECL_FREE(__free),
|
||||
@ -141,7 +141,7 @@ int igloo_buffer_get_string(igloo_buffer_t *buffer, const char **string)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static char * __stringify(igloo_ro_t self)
|
||||
static char * __stringify(igloo_ro_t self, igloo_ro_sy_t flags)
|
||||
{
|
||||
igloo_buffer_t *buffer = igloo_RO_TO_TYPE(self, igloo_buffer_t);
|
||||
const char *ret;
|
||||
|
21
src/ro.c
21
src/ro.c
@ -392,16 +392,26 @@ igloo_ro_t igloo_ro_get_interface(igloo_ro_t self, const igloo_ro_type_t *type,
|
||||
return ret;
|
||||
}
|
||||
|
||||
char * igloo_ro_stringify(igloo_ro_t self)
|
||||
char * igloo_ro_stringify(igloo_ro_t self, igloo_ro_sy_t flags)
|
||||
{
|
||||
igloo_ro_base_t *base = igloo_RO__GETBASE(self);
|
||||
char *ret = NULL;
|
||||
|
||||
if (!base)
|
||||
if (flags & igloo_RO_SY_DEFAULT)
|
||||
flags |= igloo_RO_SY_OBJECT|igloo_RO_SY_CONTENT;
|
||||
|
||||
|
||||
if (!base) {
|
||||
if (flags & igloo_RO_SY_OBJECT) {
|
||||
return strdup("{igloo_RO_NULL}");
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
igloo_thread_mutex_lock(&(base->lock));
|
||||
if (!base->refc) {
|
||||
if (flags & igloo_RO_SY_OBJECT) {
|
||||
int len;
|
||||
char buf;
|
||||
|
||||
@ -414,14 +424,16 @@ char * igloo_ro_stringify(igloo_ro_t self)
|
||||
snprintf(ret, len + 1, STRINGIFY_FORMAT_WEAK);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
igloo_thread_mutex_unlock(&(base->lock));
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (base->type->type_stringifycb) {
|
||||
ret = base->type->type_stringifycb(self);
|
||||
if (base->type->type_stringifycb && (flags & igloo_RO_SY_CONTENT)) {
|
||||
ret = base->type->type_stringifycb(self, flags);
|
||||
} else {
|
||||
if (flags & igloo_RO_SY_OBJECT) {
|
||||
int len;
|
||||
char buf;
|
||||
|
||||
@ -435,6 +447,7 @@ char * igloo_ro_stringify(igloo_ro_t self)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
igloo_thread_mutex_unlock(&(base->lock));
|
||||
|
||||
return ret;
|
||||
|
Loading…
Reference in New Issue
Block a user