~ubuntu-branches/ubuntu/gutsy/lasso/gutsy-security

« back to all changes in this revision

Viewing changes to lasso/protocols/register_name_identifier_response.c

  • Committer: Bazaar Package Importer
  • Author(s): Stephan Hermann
  • Date: 2005-09-16 02:16:49 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050916021649-lr5tuka6pfmmks44
Tags: 0.6.2-3ubuntu1
* debian/control: removed hardcoded php dependency, added php:Depends
  substvar
* debian/rules: added phpapiver, added substitution of php:Depends

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: register_name_identifier_response.c,v 1.16 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/register_name_identifier_response.h>
27
 
 
28
 
/*****************************************************************************/
29
 
/* public methods                                                            */
30
 
/*****************************************************************************/
31
 
 
32
 
/*****************************************************************************/
33
 
/* private methods                                                           */
34
 
/*****************************************************************************/
35
 
 
36
 
static LassoNode*
37
 
lasso_register_name_identifier_response_new_from_query(gchar *query)
38
 
{
39
 
  LassoNode *response;
40
 
  xmlChar *relayState;
41
 
  GData *gd;
42
 
  
43
 
  response = LASSO_NODE(g_object_new(LASSO_TYPE_REGISTER_NAME_IDENTIFIER_RESPONSE, NULL));
44
 
 
45
 
  gd = lasso_query_to_dict(query);
46
 
  
47
 
  /* ResponseID */
48
 
  lasso_samlp_response_abstract_set_responseID(LASSO_SAMLP_RESPONSE_ABSTRACT(response),
49
 
                                               lasso_g_ptr_array_index((GPtrArray *)g_datalist_get_data(&gd, "ResponseID"), 0));
50
 
  
51
 
  /* MajorVersion */
52
 
  lasso_samlp_response_abstract_set_majorVersion(LASSO_SAMLP_RESPONSE_ABSTRACT(response),
53
 
                                                 lasso_g_ptr_array_index((GPtrArray *)g_datalist_get_data(&gd, "MajorVersion"), 0));
54
 
  
55
 
  /* MinorVersion */
56
 
  lasso_samlp_response_abstract_set_minorVersion(LASSO_SAMLP_RESPONSE_ABSTRACT(response),
57
 
                                                 lasso_g_ptr_array_index((GPtrArray *)g_datalist_get_data(&gd, "MinorVersion"), 0));
58
 
  
59
 
  /* IssueInstant */
60
 
  lasso_samlp_response_abstract_set_issueInstant(LASSO_SAMLP_RESPONSE_ABSTRACT(response),
61
 
                                                 lasso_g_ptr_array_index((GPtrArray *)g_datalist_get_data(&gd, "IssueInstant"), 0));
62
 
  
63
 
  /* InResponseTo */
64
 
  lasso_samlp_response_abstract_set_inResponseTo(LASSO_SAMLP_RESPONSE_ABSTRACT(response),
65
 
                                                 lasso_g_ptr_array_index((GPtrArray *)g_datalist_get_data(&gd, "InResponseTo"), 0));
66
 
  
67
 
  /* Recipient */
68
 
  lasso_samlp_response_abstract_set_recipient(LASSO_SAMLP_RESPONSE_ABSTRACT(response),
69
 
                                              lasso_g_ptr_array_index((GPtrArray *)g_datalist_get_data(&gd, "Recipient"), 0));
70
 
  
71
 
  /* ProviderID */
72
 
  lasso_lib_status_response_set_providerID(LASSO_LIB_STATUS_RESPONSE(response),
73
 
                                           lasso_g_ptr_array_index((GPtrArray *)g_datalist_get_data(&gd, "ProviderID"), 0));
74
 
  
75
 
  /* RelayState */
76
 
  relayState = lasso_g_ptr_array_index((GPtrArray *)g_datalist_get_data(&gd, "RelayState"), 0);
77
 
  if (relayState != NULL)
78
 
    lasso_lib_status_response_set_relayState(LASSO_LIB_STATUS_RESPONSE(response), relayState);
79
 
  
80
 
  g_datalist_clear(&gd);
81
 
 
82
 
  return response;
83
 
}
84
 
 
85
 
static LassoNode*
86
 
lasso_register_name_identifier_response_new_from_soap(gchar *buffer)
87
 
{
88
 
  LassoNode *response;
89
 
  LassoNode *envelope, *lassoNode_response;
90
 
  xmlNodePtr xmlNode_response;
91
 
  LassoNodeClass *class;
92
 
 
93
 
  response = LASSO_NODE(g_object_new(LASSO_TYPE_REGISTER_NAME_IDENTIFIER_RESPONSE, NULL));
94
 
 
95
 
  envelope = lasso_node_new_from_dump(buffer);
96
 
  lassoNode_response = lasso_node_get_child(envelope, "RegisterNameIdentifierResponse",
97
 
                                            lassoLibHRef, NULL);
98
 
  
99
 
  class = LASSO_NODE_GET_CLASS(lassoNode_response);
100
 
  xmlNode_response = xmlCopyNode(class->get_xmlNode(LASSO_NODE(lassoNode_response)), 1);
101
 
  lasso_node_destroy(lassoNode_response);
102
 
 
103
 
  class = LASSO_NODE_GET_CLASS(response);
104
 
  class->set_xmlNode(LASSO_NODE(response), xmlNode_response);
105
 
  lasso_node_destroy(envelope);
106
 
  
107
 
  return response;
108
 
}
109
 
 
110
 
/*****************************************************************************/
111
 
/* instance and class init functions                                         */
112
 
/*****************************************************************************/
113
 
 
114
 
static void
115
 
lasso_register_name_identifier_response_instance_init(LassoRegisterNameIdentifierResponse *response)
116
 
{
117
 
}
118
 
 
119
 
static void
120
 
lasso_register_name_identifier_response_class_init(LassoRegisterNameIdentifierResponseClass *class)
121
 
{
122
 
}
123
 
 
124
 
GType lasso_register_name_identifier_response_get_type() {
125
 
  static GType this_type = 0;
126
 
 
127
 
  if (!this_type) {
128
 
    static const GTypeInfo this_info = {
129
 
      sizeof (LassoRegisterNameIdentifierResponseClass),
130
 
      NULL,
131
 
      NULL,
132
 
      (GClassInitFunc) lasso_register_name_identifier_response_class_init,
133
 
      NULL,
134
 
      NULL,
135
 
      sizeof(LassoRegisterNameIdentifierResponse),
136
 
      0,
137
 
      (GInstanceInitFunc) lasso_register_name_identifier_response_instance_init,
138
 
    };
139
 
    
140
 
    this_type = g_type_register_static(LASSO_TYPE_LIB_REGISTER_NAME_IDENTIFIER_RESPONSE,
141
 
                                       "LassoRegisterNameIdentifierResponse",
142
 
                                       &this_info, 0);
143
 
  }
144
 
  return this_type;
145
 
}
146
 
 
147
 
LassoNode*
148
 
lasso_register_name_identifier_response_new(gchar     *providerID,
149
 
                                            gchar     *statusCodeValue,
150
 
                                            LassoNode *request)
151
 
{
152
 
  /* FIXME : change request type */
153
 
  LassoNode *response, *ss, *ssc;
154
 
  xmlChar *inResponseTo, *request_providerID, *request_relayState;
155
 
  xmlChar *id, *time;
156
 
 
157
 
  response = LASSO_NODE(g_object_new(LASSO_TYPE_REGISTER_NAME_IDENTIFIER_RESPONSE, NULL));
158
 
  
159
 
  /* Set ONLY required elements/attributes */
160
 
  /* ResponseID */
161
 
  id = lasso_build_unique_id(32);
162
 
  lasso_samlp_response_abstract_set_responseID(LASSO_SAMLP_RESPONSE_ABSTRACT(response),
163
 
                                               (const xmlChar *)id);
164
 
  xmlFree(id);
165
 
  /* MajorVersion */
166
 
  lasso_samlp_response_abstract_set_majorVersion(LASSO_SAMLP_RESPONSE_ABSTRACT(response),
167
 
                                                 lassoLibMajorVersion);
168
 
  /* MinorVersion */
169
 
  lasso_samlp_response_abstract_set_minorVersion(LASSO_SAMLP_RESPONSE_ABSTRACT(response),
170
 
                                                 lassoLibMinorVersion);
171
 
  /* IssueInstant */
172
 
  time = lasso_get_current_time();
173
 
  lasso_samlp_response_abstract_set_issueInstant(LASSO_SAMLP_RESPONSE_ABSTRACT(response),
174
 
                                                 (const xmlChar *)time);
175
 
  xmlFree(time);
176
 
  /* ProviderID */
177
 
  lasso_lib_status_response_set_providerID(LASSO_LIB_STATUS_RESPONSE(response),
178
 
                                           providerID);
179
 
 
180
 
  inResponseTo = lasso_node_get_attr_value(request, "RequestID", NULL);
181
 
  lasso_samlp_response_abstract_set_inResponseTo(LASSO_SAMLP_RESPONSE_ABSTRACT(response),
182
 
                                                 inResponseTo);
183
 
  xmlFree(inResponseTo);
184
 
 
185
 
  request_providerID = lasso_node_get_child_content(request, "ProviderID", NULL, NULL);
186
 
  lasso_samlp_response_abstract_set_recipient(LASSO_SAMLP_RESPONSE_ABSTRACT(response),
187
 
                                              request_providerID);
188
 
  xmlFree(request_providerID);
189
 
 
190
 
  request_relayState = lasso_node_get_child_content(request, "RelayState", NULL, NULL);
191
 
  if (request_relayState != NULL) {
192
 
    lasso_lib_status_response_set_relayState(LASSO_LIB_STATUS_RESPONSE(response),
193
 
                                             request_relayState);
194
 
    xmlFree(request_relayState);
195
 
  }
196
 
 
197
 
  ss = lasso_samlp_status_new();
198
 
  ssc = lasso_samlp_status_code_new();
199
 
  lasso_samlp_status_code_set_value(LASSO_SAMLP_STATUS_CODE(ssc),
200
 
                                    statusCodeValue);
201
 
  lasso_samlp_status_set_statusCode(LASSO_SAMLP_STATUS(ss),
202
 
                                    LASSO_SAMLP_STATUS_CODE(ssc));
203
 
  lasso_lib_status_response_set_status(LASSO_LIB_STATUS_RESPONSE(response),
204
 
                                       LASSO_SAMLP_STATUS(ss));
205
 
  lasso_node_destroy(ssc);
206
 
  lasso_node_destroy(ss);
207
 
 
208
 
  return response;
209
 
}
210
 
 
211
 
LassoNode*
212
 
lasso_register_name_identifier_response_new_from_request_export(gchar               *buffer,
213
 
                                                                lassoNodeExportType  export_type,
214
 
                                                                gchar               *providerID,
215
 
                                                                gchar               *statusCodeValue)
216
 
{
217
 
  LassoNode *request, *response;
218
 
 
219
 
  g_return_val_if_fail(buffer != NULL, NULL);
220
 
 
221
 
  request = lasso_register_name_identifier_request_new_from_export(buffer, export_type);
222
 
 
223
 
  if(request){
224
 
    message(G_LOG_LEVEL_WARNING, "Error while building RegisterNameIdentifierRequest\n");
225
 
    return NULL;
226
 
  }
227
 
 
228
 
  response = lasso_register_name_identifier_response_new(providerID,
229
 
                                                         statusCodeValue,
230
 
                                                         request);
231
 
 
232
 
  return response;
233
 
}
234
 
 
235
 
LassoNode*
236
 
lasso_register_name_identifier_response_new_from_export(gchar               *buffer,
237
 
                                                        lassoNodeExportType  export_type)
238
 
{
239
 
  LassoNode *response;
240
 
 
241
 
  g_return_val_if_fail(buffer != NULL, NULL);
242
 
 
243
 
  switch(export_type){
244
 
  case lassoNodeExportTypeQuery:
245
 
    response = lasso_register_name_identifier_response_new_from_query(buffer);
246
 
    break;
247
 
  case lassoNodeExportTypeSoap:
248
 
    response = lasso_register_name_identifier_response_new_from_soap(buffer);
249
 
    break;
250
 
  default:
251
 
    message(G_LOG_LEVEL_WARNING, "Invalid export type\n");
252
 
    return NULL;
253
 
  }
254
 
 
255
 
  return response;
256
 
}