1 /* $Id: wsse_security_header.c,v 1.0 2005/10/14 15:17:55 fpeters Exp $
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 "wsse_security_header.h"
26 #include "../idwsf_strings.h"
27 #include "../../registry.h"
28 
29 /*
30  * Schema fragment (oasis-200401-wss-wssecurity-secext-1.0.xsd):
31  *
32  * <xs:complexType name="SecurityHeaderType">
33  *   <xs:annotation>
34  *     <xs:documentation>This complexType defines header block to use for security-relevant
35  *             data directed at a specific SOAP actor.</xs:documentation>
36  *     </xs:annotation>
37  *     <xs:sequence>
38  *       <xs:any processContents="lax" minOccurs="0" maxOccurs="unbounded">
39  *         <xs:annotation>
40  *           <xs:documentation>The use of "any" is to allow extensibility and different
41  *                   forms of security data.</xs:documentation>
42  *           </xs:annotation>
43  *         </xs:any>
44  *       </xs:sequence>
45  *       <xs:anyAttribute namespace="##other" processContents="lax"/>
46  *     </xs:complexType>
47  */
48 
49 /*****************************************************************************/
50 /* private methods                                                           */
51 /*****************************************************************************/
52 
53 
54 static struct XmlSnippet schema_snippets[] = {
55 	{ "", SNIPPET_LIST_NODES | SNIPPET_ANY,
56 		G_STRUCT_OFFSET(LassoWsSec1SecurityHeader, any), NULL, NULL, NULL},
57 	{ "attributes", SNIPPET_ATTRIBUTE | SNIPPET_ANY,
58 		G_STRUCT_OFFSET(LassoWsSec1SecurityHeader, attributes), NULL, NULL, NULL},
59 	{NULL, 0, 0, NULL, NULL, NULL}
60 };
61 
62 static LassoNodeClass *parent_class = NULL;
63 
64 
65 /*****************************************************************************/
66 /* instance and class init functions                                         */
67 /*****************************************************************************/
68 
69 static void
instance_init(LassoWsSec1SecurityHeader * node)70 instance_init(LassoWsSec1SecurityHeader *node)
71 {
72 	node->attributes = g_hash_table_new_full(
73 		g_str_hash, g_str_equal, g_free, g_free);
74 }
75 
76 static void
class_init(LassoWsSec1SecurityHeaderClass * klass,void * unused G_GNUC_UNUSED)77 class_init(LassoWsSec1SecurityHeaderClass *klass, void *unused G_GNUC_UNUSED)
78 {
79 	LassoNodeClass *nclass = LASSO_NODE_CLASS(klass);
80 	guint i;
81 	const char *namespaces[] = {
82 		"http://schemas.xmlsoap.org/ws/2002/04/secext",
83 		"http://schemas.xmlsoap.org/ws/2002/07/secext",
84 		"http://schemas.xmlsoap.org/ws/2002/12/secext",
85 		"http://schemas.xmlsoap.org/ws/2003/06/secext",
86 		"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd",
87 		"http://www.docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
88 	};
89 
90 	parent_class = g_type_class_peek_parent(klass);
91 	nclass->node_data = g_new0(LassoNodeClassData, 1);
92 	lasso_node_class_set_nodename(nclass, "Security");
93 	lasso_node_class_set_ns(nclass, LASSO_WSSE1_HREF, LASSO_WSSE1_PREFIX);
94 	lasso_node_class_add_snippets(nclass, schema_snippets);
95 	/* Wsse has lots of namespaces defined */
96 	for (i=0; i < G_N_ELEMENTS(namespaces); i++) {
97 		lasso_registry_default_add_direct_mapping(namespaces[i], "Security", LASSO_LASSO_HREF, "LassoWsSec1SecurityHeader");
98 	}
99 }
100 
101 GType
lasso_wsse_security_header_get_type()102 lasso_wsse_security_header_get_type()
103 {
104 	static GType this_type = 0;
105 
106 	if (!this_type) {
107 		static const GTypeInfo this_info = {
108 			sizeof (LassoWsSec1SecurityHeaderClass),
109 			NULL,
110 			NULL,
111 			(GClassInitFunc) class_init,
112 			NULL,
113 			NULL,
114 			sizeof(LassoWsSec1SecurityHeader),
115 			0,
116 			(GInstanceInitFunc) instance_init,
117 			NULL
118 		};
119 
120 		this_type = g_type_register_static(LASSO_TYPE_NODE,
121 				"LassoWsSec1SecurityHeader", &this_info, 0);
122 	}
123 	return this_type;
124 }
125 
126 /**
127  * lasso_wsse_security_header_new:
128  *
129  * Creates a new #LassoWsSec1SecurityHeader object.
130  *
131  * Return value: a newly created #LassoWsSec1SecurityHeader object
132  **/
133 LassoWsSec1SecurityHeader*
lasso_wsse_security_header_new()134 lasso_wsse_security_header_new()
135 {
136 	return g_object_new(LASSO_TYPE_WSSE_SECURITY_HEADER, NULL);
137 }
138