mirror of
https://gitlab.xiph.org/xiph/icecast-common.git
synced 2025-01-03 14:56:36 -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);
|
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.
|
/* 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.
|
* 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.
|
* 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.
|
/* 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:
|
* Parameters:
|
||||||
* self
|
* self
|
||||||
* The object to convert to a string.
|
* The object to convert to a string.
|
||||||
|
* flags
|
||||||
|
* Flags used to select options to the conversion.
|
||||||
|
* Should normally be igloo_RO_SY_DEFAULT.
|
||||||
* Returns:
|
* Returns:
|
||||||
* A string as allocated using malloc(3). The caller must call free(3).
|
* 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.
|
/* Compare two objects.
|
||||||
*
|
*
|
||||||
|
@ -31,7 +31,7 @@ struct igloo_buffer_tag {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static void __free(igloo_ro_t self);
|
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_PUBLIC_TYPE(igloo_buffer_t,
|
||||||
igloo_RO_TYPEDECL_FREE(__free),
|
igloo_RO_TYPEDECL_FREE(__free),
|
||||||
@ -141,7 +141,7 @@ int igloo_buffer_get_string(igloo_buffer_t *buffer, const char **string)
|
|||||||
return 0;
|
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);
|
igloo_buffer_t *buffer = igloo_RO_TO_TYPE(self, igloo_buffer_t);
|
||||||
const char *ret;
|
const char *ret;
|
||||||
|
55
src/ro.c
55
src/ro.c
@ -392,26 +392,37 @@ igloo_ro_t igloo_ro_get_interface(igloo_ro_t self, const igloo_ro_type_t *type,
|
|||||||
return ret;
|
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);
|
igloo_ro_base_t *base = igloo_RO__GETBASE(self);
|
||||||
char *ret = NULL;
|
char *ret = NULL;
|
||||||
|
|
||||||
if (!base)
|
if (flags & igloo_RO_SY_DEFAULT)
|
||||||
return strdup("{igloo_RO_NULL}");
|
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));
|
igloo_thread_mutex_lock(&(base->lock));
|
||||||
if (!base->refc) {
|
if (!base->refc) {
|
||||||
int len;
|
if (flags & igloo_RO_SY_OBJECT) {
|
||||||
char buf;
|
int len;
|
||||||
|
char buf;
|
||||||
|
|
||||||
#define STRINGIFY_FORMAT_WEAK "{%s@%p, weak}", base->type->type_name, base
|
#define STRINGIFY_FORMAT_WEAK "{%s@%p, weak}", base->type->type_name, base
|
||||||
len = snprintf(&buf, 1, STRINGIFY_FORMAT_WEAK);
|
len = snprintf(&buf, 1, STRINGIFY_FORMAT_WEAK);
|
||||||
if (len > 2) {
|
if (len > 2) {
|
||||||
/* We add 2 bytes just to make sure no buggy interpretation of \0 inclusion could bite us. */
|
/* We add 2 bytes just to make sure no buggy interpretation of \0 inclusion could bite us. */
|
||||||
ret = calloc(1, len + 2);
|
ret = calloc(1, len + 2);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
snprintf(ret, len + 1, STRINGIFY_FORMAT_WEAK);
|
snprintf(ret, len + 1, STRINGIFY_FORMAT_WEAK);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -419,19 +430,21 @@ char * igloo_ro_stringify(igloo_ro_t self)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (base->type->type_stringifycb) {
|
if (base->type->type_stringifycb && (flags & igloo_RO_SY_CONTENT)) {
|
||||||
ret = base->type->type_stringifycb(self);
|
ret = base->type->type_stringifycb(self, flags);
|
||||||
} else {
|
} else {
|
||||||
int len;
|
if (flags & igloo_RO_SY_OBJECT) {
|
||||||
char buf;
|
int len;
|
||||||
|
char buf;
|
||||||
|
|
||||||
#define STRINGIFY_FORMAT_FULL "{%s@%p, strong, name=\"%s\", associated=%p}", base->type->type_name, base, base->name, igloo_RO__GETBASE(base->associated)
|
#define STRINGIFY_FORMAT_FULL "{%s@%p, strong, name=\"%s\", associated=%p}", base->type->type_name, base, base->name, igloo_RO__GETBASE(base->associated)
|
||||||
len = snprintf(&buf, 1, STRINGIFY_FORMAT_FULL);
|
len = snprintf(&buf, 1, STRINGIFY_FORMAT_FULL);
|
||||||
if (len > 2) {
|
if (len > 2) {
|
||||||
/* We add 2 bytes just to make sure no buggy interpretation of \0 inclusion could bite us. */
|
/* We add 2 bytes just to make sure no buggy interpretation of \0 inclusion could bite us. */
|
||||||
ret = calloc(1, len + 2);
|
ret = calloc(1, len + 2);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
snprintf(ret, len + 1, STRINGIFY_FORMAT_FULL);
|
snprintf(ret, len + 1, STRINGIFY_FORMAT_FULL);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user