~ubuntu-branches/ubuntu/utopic/lasso/utopic-proposed

« back to all changes in this revision

Viewing changes to lasso/protocols/name_identifier_mapping_request.c

  • Committer: Bazaar Package Importer
  • Author(s): Frederic Peters
  • Date: 2004-09-13 09:26:34 UTC
  • Revision ID: james.westby@ubuntu.com-20040913092634-01vdfl8j9cp94exa
Tags: upstream-0.4.1
ImportĀ upstreamĀ versionĀ 0.4.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Id: name_identifier_mapping_request.c,v 1.12 2004/09/01 09:59:53 fpeters Exp $ 
 
2
 *
 
3
 * Lasso - A free implementation of the Liberty Alliance specifications.
 
4
 *
 
5
 * Copyright (C) 2004 Entr'ouvert
 
6
 * http://lasso.entrouvert.org
 
7
 * 
 
8
 * Authors: Valery Febvre   <vfebvre@easter-eggs.com>
 
9
 *          Nicolas Clapies <nclapies@entrouvert.com>
 
10
 *
 
11
 * This program is free software; you can redistribute it and/or modify
 
12
 * it under the terms of the GNU General Public License as published by
 
13
 * the Free Software Foundation; either version 2 of the License, or
 
14
 * (at your option) any later version.
 
15
 * 
 
16
 * This program is distributed in the hope that it will be useful,
 
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
19
 * GNU General Public License for more details.
 
20
 * 
 
21
 * You should have received a copy of the GNU General Public License
 
22
 * along with this program; if not, write to the Free Software
 
23
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
24
 */
 
25
 
 
26
#include <lasso/protocols/name_identifier_mapping_request.h>
 
27
#include <lasso/xml/saml_name_identifier.h>
 
28
 
 
29
/*****************************************************************************/
 
30
/* public methods                                                            */
 
31
/*****************************************************************************/
 
32
 
 
33
/*****************************************************************************/
 
34
/* instance and class init functions                                         */
 
35
/*****************************************************************************/
 
36
 
 
37
static void
 
38
lasso_name_identifier_mapping_request_instance_init(LassoNameIdentifierMappingRequest *request)
 
39
{
 
40
}
 
41
 
 
42
static void
 
43
lasso_name_identifier_mapping_request_class_init(LassoNameIdentifierMappingRequestClass *class)
 
44
{
 
45
}
 
46
 
 
47
GType lasso_name_identifier_mapping_request_get_type() {
 
48
  static GType this_type = 0;
 
49
 
 
50
  if (!this_type) {
 
51
    static const GTypeInfo this_info = {
 
52
      sizeof (LassoNameIdentifierMappingRequestClass),
 
53
      NULL,
 
54
      NULL,
 
55
      (GClassInitFunc) lasso_name_identifier_mapping_request_class_init,
 
56
      NULL,
 
57
      NULL,
 
58
      sizeof(LassoNameIdentifierMappingRequest),
 
59
      0,
 
60
      (GInstanceInitFunc) lasso_name_identifier_mapping_request_instance_init,
 
61
    };
 
62
    
 
63
    this_type = g_type_register_static(LASSO_TYPE_LIB_NAME_IDENTIFIER_MAPPING_REQUEST,
 
64
                                       "LassoNameIdentifierMappingRequest",
 
65
                                       &this_info, 0);
 
66
  }
 
67
  return this_type;
 
68
}
 
69
 
 
70
LassoNode*
 
71
lasso_name_identifier_mapping_request_new(const xmlChar *providerID,
 
72
                                          const xmlChar *nameIdentifier,
 
73
                                          const xmlChar *nameQualifier,
 
74
                                          const xmlChar *format)
 
75
{
 
76
  LassoNode *request, *identifier;
 
77
  xmlChar *id, *time;
 
78
 
 
79
  g_return_val_if_fail(providerID != NULL, NULL);
 
80
  g_return_val_if_fail(nameIdentifier != NULL, NULL);
 
81
  g_return_val_if_fail(nameQualifier != NULL, NULL);
 
82
  g_return_val_if_fail(format != NULL, NULL);
 
83
 
 
84
  request = LASSO_NODE(g_object_new(LASSO_TYPE_NAME_IDENTIFIER_MAPPING_REQUEST, NULL));
 
85
  
 
86
  /* Set ONLY required elements/attributes */
 
87
  /* RequestID */
 
88
  id = lasso_build_unique_id(32);
 
89
  lasso_samlp_request_abstract_set_requestID(LASSO_SAMLP_REQUEST_ABSTRACT(request),
 
90
                                             (const xmlChar *)id);
 
91
  xmlFree(id);
 
92
  /* MajorVersion */
 
93
  lasso_samlp_request_abstract_set_majorVersion(LASSO_SAMLP_REQUEST_ABSTRACT(request),
 
94
                                                lassoLibMajorVersion);
 
95
  /* MinorVersion */
 
96
  lasso_samlp_request_abstract_set_minorVersion(LASSO_SAMLP_REQUEST_ABSTRACT(request), 
 
97
                                                lassoLibMinorVersion);
 
98
  /* IssueInstant */
 
99
  time = lasso_get_current_time();
 
100
  lasso_samlp_request_abstract_set_issueInstant(LASSO_SAMLP_REQUEST_ABSTRACT(request),
 
101
                                                (const xmlChar *)time);
 
102
  xmlFree(time);
 
103
  /* ProviderID */
 
104
  lasso_lib_name_identifier_mapping_request_set_providerID(LASSO_LIB_NAME_IDENTIFIER_MAPPING_REQUEST(request),
 
105
                                                           providerID);
 
106
 
 
107
  identifier = lasso_saml_name_identifier_new(nameIdentifier);
 
108
  lasso_saml_name_identifier_set_nameQualifier(LASSO_SAML_NAME_IDENTIFIER(identifier),
 
109
                                               nameQualifier);
 
110
  lasso_saml_name_identifier_set_format(LASSO_SAML_NAME_IDENTIFIER(identifier),
 
111
                                        format);
 
112
 
 
113
  lasso_lib_name_identifier_mapping_request_set_nameIdentifier(LASSO_LIB_NAME_IDENTIFIER_MAPPING_REQUEST(request),
 
114
                                                               LASSO_SAML_NAME_IDENTIFIER(identifier));
 
115
  lasso_node_destroy(identifier);
 
116
 
 
117
  return request;
 
118
}
 
119
 
 
120
LassoNode *
 
121
lasso_name_identifier_mapping_request_new_from_query(const gchar *query)
 
122
{
 
123
  LassoNode *request, *identifier;
 
124
  xmlChar *str;
 
125
  GData *gd;
 
126
 
 
127
  request = LASSO_NODE(g_object_new(LASSO_TYPE_NAME_IDENTIFIER_MAPPING_REQUEST, NULL));
 
128
 
 
129
  gd = lasso_query_to_dict(query);
 
130
 
 
131
  /* RequestID */
 
132
  str = lasso_g_ptr_array_index((GPtrArray *)g_datalist_get_data(&gd, "RequestID"), 0);
 
133
  lasso_samlp_request_abstract_set_requestID(LASSO_SAMLP_REQUEST_ABSTRACT(request), str);
 
134
  
 
135
  /* MajorVersion */
 
136
  str = lasso_g_ptr_array_index((GPtrArray *)g_datalist_get_data(&gd, "MajorVersion"), 0);
 
137
  lasso_samlp_request_abstract_set_majorVersion(LASSO_SAMLP_REQUEST_ABSTRACT(request), str);
 
138
  
 
139
  /* MinorVersion */
 
140
  str = lasso_g_ptr_array_index((GPtrArray *)g_datalist_get_data(&gd, "MinorVersion"), 0);
 
141
  lasso_samlp_request_abstract_set_minorVersion(LASSO_SAMLP_REQUEST_ABSTRACT(request), str);
 
142
  
 
143
  /* IssueInstant */
 
144
  str = lasso_g_ptr_array_index((GPtrArray *)g_datalist_get_data(&gd, "IssueInstant"), 0);
 
145
  lasso_samlp_request_abstract_set_issueInstant(LASSO_SAMLP_REQUEST_ABSTRACT(request), str);
 
146
  
 
147
  /* ProviderID */
 
148
  str = lasso_g_ptr_array_index((GPtrArray *)g_datalist_get_data(&gd, "ProviderID"), 0);
 
149
  lasso_lib_name_identifier_mapping_request_set_providerID(LASSO_LIB_NAME_IDENTIFIER_MAPPING_REQUEST(request), str);
 
150
 
 
151
  /* NameIdentifier */
 
152
  str = lasso_g_ptr_array_index((GPtrArray *)g_datalist_get_data(&gd, "NameIdentifier"), 0);
 
153
  identifier = lasso_saml_name_identifier_new(str);
 
154
  str = lasso_g_ptr_array_index((GPtrArray *)g_datalist_get_data(&gd, "NameQualifier"), 0);
 
155
  lasso_saml_name_identifier_set_nameQualifier(LASSO_SAML_NAME_IDENTIFIER(identifier), str);
 
156
  str = lasso_g_ptr_array_index((GPtrArray *)g_datalist_get_data(&gd, "Format"), 0);
 
157
  lasso_saml_name_identifier_set_format(LASSO_SAML_NAME_IDENTIFIER(identifier), str);
 
158
     
 
159
  lasso_lib_name_identifier_mapping_request_set_nameIdentifier(LASSO_LIB_NAME_IDENTIFIER_MAPPING_REQUEST(request),
 
160
                                                               LASSO_SAML_NAME_IDENTIFIER(identifier));
 
161
  lasso_node_destroy(identifier);
 
162
  
 
163
  /* consent */
 
164
  str = lasso_g_ptr_array_index((GPtrArray *)g_datalist_get_data(&gd, "consent"), 0);
 
165
  if (str != NULL)
 
166
    lasso_lib_name_identifier_mapping_request_set_consent(LASSO_LIB_NAME_IDENTIFIER_MAPPING_REQUEST(request), str);
 
167
 
 
168
  g_datalist_clear(&gd);
 
169
 
 
170
  return request;
 
171
}
 
172
 
 
173
LassoNode *
 
174
lasso_name_identifier_mapping_request_new_from_soap(const gchar *buffer)
 
175
{
 
176
  LassoNode *request;
 
177
  LassoNode *envelope, *lassoNode_request;
 
178
  xmlNodePtr xmlNode_request;
 
179
  LassoNodeClass *class;
 
180
 
 
181
  request = LASSO_NODE(g_object_new(LASSO_TYPE_NAME_IDENTIFIER_MAPPING_REQUEST, NULL));
 
182
 
 
183
  envelope = lasso_node_new_from_dump(buffer);
 
184
  lassoNode_request = lasso_node_get_child(envelope, "NameIdentifierMappingRequest",
 
185
                                           lassoLibHRef, NULL);
 
186
  
 
187
  class = LASSO_NODE_GET_CLASS(lassoNode_request);
 
188
  xmlNode_request = xmlCopyNode(class->get_xmlNode(LASSO_NODE(lassoNode_request)), 1);
 
189
  lasso_node_destroy(lassoNode_request);
 
190
 
 
191
  class = LASSO_NODE_GET_CLASS(request);
 
192
  class->set_xmlNode(LASSO_NODE(request), xmlNode_request);
 
193
  lasso_node_destroy(envelope);
 
194
  
 
195
  return request;
 
196
}