1 /* $Id$
2 *
3 * Lasso - A free implementation of the Liberty Alliance specifications.
4 *
5 * Copyright (C) 2004-2007 Entr'ouvert
6 * http://lasso.entrouvert.org
7 *
8 * Authors: See AUTHORS file in top-level directory.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, see <http://www.gnu.org/licenses/>.
22 */
23
24 #include "private.h"
25 #include "saml_name_identifier.h"
26 #include <libxml/uri.h>
27
28 /**
29 * SECTION:saml_name_identifier
30 * @short_description: <saml:NameIdentifier>
31 *
32 * <figure><title>Schema fragment for saml:NameIdentifier</title>
33 * <programlisting><![CDATA[
34 *
35 * <element name="NameIdentifier" type="saml:NameIdentifierType"/>
36 * <complexType name="NameIdentifierType">
37 * <simpleContent>
38 * <extension base="string">
39 * <attribute name="NameQualifier" type="string" use="optional"/>
40 * <attribute name="Format" type="anyURI" use="optional"/>
41 * </extension>
42 * </simpleContent>
43 * </complexType>
44 * ]]></programlisting>
45 * </figure>
46 */
47
48 /*****************************************************************************/
49 /* private methods */
50 /*****************************************************************************/
51
52 static struct XmlSnippet schema_snippets[] = {
53 { "NameQualifier", SNIPPET_ATTRIBUTE,
54 G_STRUCT_OFFSET(LassoSamlNameIdentifier, NameQualifier), NULL, NULL, NULL},
55 { "Format", SNIPPET_ATTRIBUTE, G_STRUCT_OFFSET(LassoSamlNameIdentifier, Format), NULL, NULL, NULL},
56 { "content", SNIPPET_TEXT_CHILD, G_STRUCT_OFFSET(LassoSamlNameIdentifier, content), NULL, NULL, NULL},
57 {NULL, 0, 0, NULL, NULL, NULL}
58 };
59
60 /*****************************************************************************/
61 /* instance and class init functions */
62 /*****************************************************************************/
63
64 static void
class_init(LassoSamlNameIdentifierClass * klass,void * unused G_GNUC_UNUSED)65 class_init(LassoSamlNameIdentifierClass *klass, void *unused G_GNUC_UNUSED)
66 {
67 LassoNodeClass *nclass = LASSO_NODE_CLASS(klass);
68
69 nclass->node_data = g_new0(LassoNodeClassData, 1);
70 lasso_node_class_set_nodename(nclass, "NameIdentifier");
71 lasso_node_class_set_ns(nclass, LASSO_SAML_ASSERTION_HREF, LASSO_SAML_ASSERTION_PREFIX);
72 lasso_node_class_add_snippets(nclass, schema_snippets);
73 }
74
75 GType
lasso_saml_name_identifier_get_type()76 lasso_saml_name_identifier_get_type()
77 {
78 static GType this_type = 0;
79
80 if (!this_type) {
81 static const GTypeInfo this_info = {
82 sizeof (LassoSamlNameIdentifierClass),
83 NULL,
84 NULL,
85 (GClassInitFunc) class_init,
86 NULL,
87 NULL,
88 sizeof(LassoSamlNameIdentifier),
89 0,
90 NULL,
91 NULL
92 };
93
94 this_type = g_type_register_static(LASSO_TYPE_NODE,
95 "LassoSamlNameIdentifier", &this_info, 0);
96 }
97 return this_type;
98 }
99
100 gboolean
lasso_saml_name_identifier_equals(LassoSamlNameIdentifier * a,LassoSamlNameIdentifier * b)101 lasso_saml_name_identifier_equals(LassoSamlNameIdentifier *a,
102 LassoSamlNameIdentifier *b) {
103 if (a == NULL || b == NULL)
104 return FALSE;
105
106 if (! LASSO_IS_SAML_NAME_IDENTIFIER(a) && ! LASSO_IS_SAML_NAME_IDENTIFIER(b)) {
107 return FALSE;
108 }
109 return lasso_strisequal(a->NameQualifier, b->NameQualifier)
110 && lasso_strisequal(a->Format, b->Format)
111 && lasso_strisequal(a->content, b->content);
112 }
113
114 /**
115 * lasso_saml_name_identifier_new:
116 *
117 * Creates a new #LassoSamlNameIdentifier object.
118 *
119 * Return value: a newly created #LassoSamlNameIdentifier object
120 **/
121 LassoSamlNameIdentifier*
lasso_saml_name_identifier_new()122 lasso_saml_name_identifier_new()
123 {
124 return g_object_new(LASSO_TYPE_SAML_NAME_IDENTIFIER, NULL);
125 }
126
127
128 LassoSamlNameIdentifier*
lasso_saml_name_identifier_new_from_xmlNode(xmlNode * xmlnode)129 lasso_saml_name_identifier_new_from_xmlNode(xmlNode *xmlnode)
130 {
131 LassoNode *node;
132
133 node = g_object_new(LASSO_TYPE_SAML_NAME_IDENTIFIER, NULL);
134 lasso_node_init_from_xml(node, xmlnode);
135 return LASSO_SAML_NAME_IDENTIFIER(node);
136 }
137