Utils: add function to extract/create node in lists

* lasso_extract_gtype_from_list_or_new will help for method with create
   or extend nodes in lists.
This commit is contained in:
Benjamin Dauvergne 2010-06-09 16:54:49 +00:00
parent 4c130d779a
commit 80a930cc37
9 changed files with 38 additions and 1 deletions

View File

@ -19,6 +19,9 @@ liblasso_saml_20_la_SOURCES = \
logout.c \
name_id_management.c \
server.c \
saml2_conditions_addons.c \
saml2_assertion_addons.c \
samlp2_authn_request_addons.c \
saml2_helper.c
liblassoinclude_HEADERS = \
@ -27,6 +30,9 @@ liblassoinclude_HEADERS = \
profile.h \
name_id_management.h \
provider.h \
saml2_conditions_addons.h \
saml2_assertion_addons.h \
samlp2_authn_request_addons.h \
saml2_helper.h
lasso_private_h_sources = \

View File

View File

View File

View File

View File

@ -127,10 +127,37 @@ lasso_extract_gtype_from_list(GType type, GList *list)
{
GList *needle;
needle = g_list_find_custom(list, (gconstpointer)type, (GCompareFunc)lasso_gobject_is_of_type);
if (needle) {
return needle->data;
}
return NULL;
}
/**
* lasso_extract_gtype_from_list_or_new:
* @type: a #GType
* @list: a pointer to a #GList pointer variable
* @create: whether to look up an object whose #GType is type, or to just create it.
*
* If create is TRUE, add a new object of type @type to @list and return it.
* Otherwise try to look up an object of type @type, and if none is found add a new one and return
* it.
*
* Return value: a #GObject of type @type.
*/
GObject *
lasso_extract_gtype_from_list_or_new(GType type, GList **list, gboolean create)
{
GObject *result = NULL;
g_assert (list);
if (! create) {
result = lasso_extract_gtype_from_list(type, *list);
}
if (result == NULL) {
result = g_object_new(type, NULL);
lasso_list_add_new_gobject(*list, result);
}
return result;
}

View File

@ -599,9 +599,13 @@ lasso_is_empty_string(const char *str) {
/* Get a printable extract for error messages */
char* lasso_safe_prefix_string(const char *str, gsize length);
int lasso_gobject_is_of_type(GObject *a, GType b);
GObject *lasso_extract_gtype_from_list(GType type, GList *list);
GObject * lasso_extract_gtype_from_list_or_new(GType type, GList **list, gboolean create);
/* Get first node of this type in a list */
/* ex: lasso_extract_node (LassoNode, LASSO_TYPE_NODE, list) */
#define lasso_extract_gobject_from_list(type, gobjecttype, list) \