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

« back to all changes in this revision

Viewing changes to lasso/protocols/response.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: response.c,v 1.10 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/response.h>
 
27
 
 
28
/*****************************************************************************/
 
29
/* functions                                                                 */
 
30
/*****************************************************************************/
 
31
 
 
32
/*****************************************************************************/
 
33
/* public methods                                                            */
 
34
/*****************************************************************************/
 
35
 
 
36
/*****************************************************************************/
 
37
/* instance and class init functions                                         */
 
38
/*****************************************************************************/
 
39
 
 
40
static void
 
41
lasso_response_instance_init(LassoResponse *response)
 
42
{
 
43
}
 
44
 
 
45
static void
 
46
lasso_response_class_init(LassoResponseClass *class)
 
47
{
 
48
}
 
49
 
 
50
GType lasso_response_get_type() {
 
51
  static GType this_type = 0;
 
52
 
 
53
  if (!this_type) {
 
54
    static const GTypeInfo this_info = {
 
55
      sizeof (LassoResponseClass),
 
56
      NULL,
 
57
      NULL,
 
58
      (GClassInitFunc) lasso_response_class_init,
 
59
      NULL,
 
60
      NULL,
 
61
      sizeof(LassoResponse),
 
62
      0,
 
63
      (GInstanceInitFunc) lasso_response_instance_init,
 
64
    };
 
65
    
 
66
    this_type = g_type_register_static(LASSO_TYPE_SAMLP_RESPONSE,
 
67
                                       "LassoResponse",
 
68
                                       &this_info, 0);
 
69
  }
 
70
  return this_type;
 
71
}
 
72
 
 
73
LassoNode*
 
74
lasso_response_new()
 
75
{
 
76
  LassoNode *response;
 
77
  xmlChar   *id, *time;
 
78
  LassoNode *status, *status_code;
 
79
 
 
80
  response = lasso_samlp_response_new();
 
81
 
 
82
  /* Set ONLY required elements/attributes */
 
83
  /* ResponseID */
 
84
  id = lasso_build_unique_id(32);
 
85
  lasso_samlp_response_abstract_set_responseID(LASSO_SAMLP_RESPONSE_ABSTRACT(response),
 
86
                                               (const xmlChar *)id);
 
87
  xmlFree(id);
 
88
  /* MajorVersion */
 
89
  lasso_samlp_response_abstract_set_majorVersion(LASSO_SAMLP_RESPONSE_ABSTRACT(response),
 
90
                                                 lassoLibMajorVersion);
 
91
  /* MinorVersion */
 
92
  lasso_samlp_response_abstract_set_minorVersion(LASSO_SAMLP_RESPONSE_ABSTRACT(response), 
 
93
                                                 lassoLibMinorVersion);
 
94
  /* IssueInstant */
 
95
  time = lasso_get_current_time();
 
96
  lasso_samlp_response_abstract_set_issueInstant(LASSO_SAMLP_RESPONSE_ABSTRACT(response),
 
97
                                                 (const xmlChar *)time);
 
98
  xmlFree(time);
 
99
 
 
100
  /* Add Status */
 
101
  status = lasso_samlp_status_new();
 
102
  status_code = lasso_samlp_status_code_new();
 
103
  lasso_samlp_status_code_set_value(LASSO_SAMLP_STATUS_CODE(status_code), lassoSamlStatusCodeSuccess);
 
104
  lasso_samlp_status_set_statusCode(LASSO_SAMLP_STATUS(status), LASSO_SAMLP_STATUS_CODE(status_code));
 
105
  lasso_samlp_response_set_status(LASSO_SAMLP_RESPONSE(response), LASSO_SAMLP_STATUS(status));
 
106
  lasso_node_destroy(status_code);
 
107
  lasso_node_destroy(status);
 
108
 
 
109
  return response;
 
110
}
 
111
 
 
112
LassoNode*
 
113
lasso_response_new_from_export(gchar               *buffer,
 
114
                               lassoNodeExportType  export_type)
 
115
{
 
116
  LassoNode *response = NULL, *soap_node, *response_node;
 
117
  gchar *export;
 
118
 
 
119
  g_return_val_if_fail(buffer != NULL, NULL);
 
120
 
 
121
  response = LASSO_NODE(g_object_new(LASSO_TYPE_RESPONSE, NULL));
 
122
 
 
123
  switch (export_type) {
 
124
  case lassoNodeExportTypeXml:
 
125
    lasso_node_import(response, buffer);
 
126
    break;
 
127
  case lassoNodeExportTypeBase64:
 
128
  case lassoNodeExportTypeQuery:
 
129
    break;
 
130
  case lassoNodeExportTypeSoap:
 
131
    soap_node = lasso_node_new_from_dump(buffer);
 
132
    response_node = lasso_node_get_child(soap_node, "Response",
 
133
                                         lassoSamlProtocolHRef, NULL);
 
134
    export = lasso_node_export(response_node);
 
135
    lasso_node_import(response, export);
 
136
    g_free(export);
 
137
    lasso_node_destroy(response_node);
 
138
    lasso_node_destroy(soap_node);
 
139
    break;
 
140
  }
 
141
 
 
142
  return response;
 
143
}