~ubuntu-branches/ubuntu/jaunty/lasso/jaunty

« back to all changes in this revision

Viewing changes to lasso/id-wsf/profile_service.c

  • Committer: Bazaar Package Importer
  • Author(s): Loic Pefferkorn
  • Date: 2005-11-25 19:20:59 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051125192059-m4894lhpynmkrmwr
Tags: 0.6.3-4ubuntu1
Resynchronise with Debian.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: profile_service.c,v 1.5 2005/04/11 12:17:37 nclapies Exp $
2
 
 *
3
 
 * Lasso - A free implementation of the Liberty Alliance specifications.
4
 
 *
5
 
 * Copyright (C) 2004, 2005 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, write to the Free Software
22
 
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23
 
 */
24
 
 
25
 
#include <lasso/id-wsf/profile_service.h>
26
 
#include <lasso/xml/dst_query.h>
27
 
#include <lasso/xml/dst_query_response.h>
28
 
#include <lasso/xml/dst_modify.h>
29
 
#include <lasso/xml/dst_modify_response.h>
30
 
#include <lasso/xml/soap_binding_correlation.h>
31
 
 
32
 
/*****************************************************************************/
33
 
/* public methods                                                            */
34
 
/*****************************************************************************/
35
 
 
36
 
gint
37
 
lasso_profile_service_add_data(LassoProfileService *service, const gchar *xmlNodeBuffer)
38
 
{
39
 
        LassoWsfProfile *profile;
40
 
        LassoDstData *data;
41
 
        xmlNode *root, *xmlnode;
42
 
        xmlDoc *doc;
43
 
        
44
 
        g_return_val_if_fail(LASSO_IS_PROFILE_SERVICE(service) == TRUE, -1);
45
 
        g_return_val_if_fail(xmlNodeBuffer != NULL, -1);
46
 
 
47
 
        profile = LASSO_WSF_PROFILE(service);
48
 
 
49
 
        /* xmlBuffer must be parsed and set in LassoDstData */
50
 
        doc = xmlParseMemory(xmlNodeBuffer, strlen(xmlNodeBuffer));
51
 
        root = xmlDocGetRootElement(doc);
52
 
        xmlnode = xmlCopyNode(root, 1);
53
 
 
54
 
        data = lasso_dst_data_new();
55
 
        data->any = g_list_append(data->any, xmlnode);
56
 
 
57
 
        LASSO_DST_QUERY_RESPONSE(profile->response)->Data = \
58
 
                g_list_append(LASSO_DST_QUERY_RESPONSE(profile->response)->Data, data);
59
 
 
60
 
        return 0;
61
 
}
62
 
 
63
 
LassoDstModification*
64
 
lasso_profile_service_add_modification(LassoProfileService *service, const gchar *select)
65
 
{
66
 
        LassoWsfProfile *profile;
67
 
        LassoDstModification *modification;
68
 
 
69
 
        g_return_val_if_fail(LASSO_IS_PROFILE_SERVICE(service), NULL);
70
 
        g_return_val_if_fail(select != NULL, NULL);
71
 
 
72
 
        profile = LASSO_WSF_PROFILE(service);
73
 
 
74
 
        modification = lasso_dst_modification_new(select);
75
 
        LASSO_DST_MODIFY(profile->request)->Modification = g_list_append(
76
 
                LASSO_DST_MODIFY(profile->request)->Modification, (gpointer)modification);
77
 
 
78
 
        return modification;
79
 
}
80
 
 
81
 
LassoDstQueryItem*
82
 
lasso_profile_service_add_query_item(LassoProfileService *service, const gchar *select)
83
 
{
84
 
        LassoWsfProfile *profile;
85
 
        LassoDstQueryItem *query_item;
86
 
 
87
 
        g_return_val_if_fail(LASSO_IS_PROFILE_SERVICE(service), NULL);
88
 
        g_return_val_if_fail(select != NULL, NULL);
89
 
 
90
 
        profile = LASSO_WSF_PROFILE(service);
91
 
 
92
 
        query_item = lasso_dst_query_item_new(select);
93
 
        LASSO_DST_QUERY(profile->request)->QueryItem = g_list_append(
94
 
                LASSO_DST_QUERY(profile->request)->QueryItem, (gpointer)query_item);
95
 
 
96
 
        return query_item;
97
 
}
98
 
 
99
 
LassoDstModification*
100
 
lasso_profile_service_init_modify(LassoProfileService *service,
101
 
                                  const gchar *prefix,
102
 
                                  const gchar *href,
103
 
                                  LassoDiscoResourceOffering *resourceOffering,
104
 
                                  LassoDiscoDescription *description,
105
 
                                  const gchar *select)
106
 
{
107
 
        LassoDstModification *modification;
108
 
        LassoWsfProfile *profile;
109
 
 
110
 
        LassoSoapEnvelope *envelope;
111
 
        LassoDstModify *modify;
112
 
 
113
 
        g_return_val_if_fail(LASSO_IS_PROFILE_SERVICE(service), NULL);
114
 
        g_return_val_if_fail(LASSO_IS_DISCO_RESOURCE_OFFERING(resourceOffering), NULL);
115
 
        g_return_val_if_fail(LASSO_IS_DISCO_DESCRIPTION(description), NULL);
116
 
 
117
 
        profile = LASSO_WSF_PROFILE(service);
118
 
 
119
 
        /* init Modify */
120
 
        modification = lasso_dst_modification_new(select);
121
 
 
122
 
        modify = lasso_dst_modify_new(modification);
123
 
        profile->request = LASSO_NODE(modify);
124
 
 
125
 
        LASSO_DST_MODIFY(profile->request)->prefixServiceType = g_strdup(prefix);
126
 
        LASSO_DST_MODIFY(profile->request)->hrefServiceType = g_strdup(href);
127
 
 
128
 
        envelope = lasso_wsf_profile_build_soap_envelope(NULL);
129
 
        LASSO_WSF_PROFILE(service)->soap_envelope_request = envelope;
130
 
        envelope->Body->any = g_list_append(envelope->Body->any, modify);
131
 
 
132
 
        /* get ResourceID / EncryptedResourceID */
133
 
        if (resourceOffering->ResourceID != NULL) {
134
 
                LASSO_DST_MODIFY(profile->request)->ResourceID = resourceOffering->ResourceID;
135
 
        }
136
 
        else {
137
 
          LASSO_DST_MODIFY(profile->request)->EncryptedResourceID = \
138
 
                  resourceOffering->EncryptedResourceID;
139
 
        }
140
 
 
141
 
        /* set msg_url */
142
 
        /* TODO : implement WSDLRef */
143
 
        if (description->Endpoint) {
144
 
                profile->msg_url = g_strdup(description->Endpoint);
145
 
        }
146
 
 
147
 
        return modification;
148
 
}
149
 
 
150
 
LassoDstQueryItem*
151
 
lasso_profile_service_init_query(LassoProfileService *service,
152
 
                                 const gchar *prefix,
153
 
                                 const gchar *href,
154
 
                                 LassoDiscoResourceOffering *resourceOffering,
155
 
                                 LassoDiscoDescription *description,
156
 
                                 const gchar *select)
157
 
{
158
 
        LassoDstQueryItem *query_item;
159
 
        LassoWsfProfile *profile;
160
 
 
161
 
        LassoSoapEnvelope *envelope;
162
 
        LassoDstQuery *query;
163
 
 
164
 
        g_return_val_if_fail(LASSO_IS_PROFILE_SERVICE(service), NULL);
165
 
        g_return_val_if_fail(LASSO_IS_DISCO_RESOURCE_OFFERING(resourceOffering), NULL);
166
 
        g_return_val_if_fail(LASSO_IS_DISCO_DESCRIPTION(description), NULL);
167
 
        g_return_val_if_fail(select != NULL, NULL);
168
 
 
169
 
        profile = LASSO_WSF_PROFILE(service);
170
 
        
171
 
        /* init Query */
172
 
        query_item = lasso_dst_query_item_new(select);
173
 
 
174
 
        query = lasso_dst_query_new(query_item);
175
 
        profile->request = LASSO_NODE(query);
176
 
 
177
 
        LASSO_DST_QUERY(profile->request)->prefixServiceType = g_strdup(prefix);
178
 
        LASSO_DST_QUERY(profile->request)->hrefServiceType = g_strdup(href);
179
 
        
180
 
        envelope = lasso_wsf_profile_build_soap_envelope(NULL);
181
 
        LASSO_WSF_PROFILE(service)->soap_envelope_request = envelope;
182
 
        envelope->Body->any = g_list_append(envelope->Body->any, query);
183
 
 
184
 
        /* get ResourceID / EncryptedResourceID */
185
 
        if (resourceOffering->ResourceID != NULL) {
186
 
                LASSO_DST_QUERY(profile->request)->ResourceID = resourceOffering->ResourceID;
187
 
        }
188
 
        else {
189
 
          LASSO_DST_QUERY(profile->request)->EncryptedResourceID = \
190
 
                  resourceOffering->EncryptedResourceID;
191
 
        }
192
 
        
193
 
        /* set msg_url */
194
 
        /* TODO : implement WSDLRef */
195
 
        if (description->Endpoint) {
196
 
                profile->msg_url = g_strdup(description->Endpoint);
197
 
        }
198
 
 
199
 
        return query_item;
200
 
}
201
 
 
202
 
gint
203
 
lasso_profile_service_process_modify_msg(LassoProfileService *service,
204
 
                                         const gchar *prefix, /* FIXME : must be get from message */
205
 
                                         const gchar *href,   /* FIXME : must be get from message */
206
 
                                         const gchar *modify_soap_msg)
207
 
{
208
 
        LassoDstModifyResponse *response;
209
 
        LassoSoapBindingCorrelation *correlation;
210
 
        LassoSoapEnvelope *envelope;
211
 
        LassoUtilityStatus *status;
212
 
        LassoWsfProfile *profile;
213
 
        gchar *messageId;
214
 
 
215
 
        g_return_val_if_fail(LASSO_IS_PROFILE_SERVICE(service), -1);
216
 
        g_return_val_if_fail(modify_soap_msg != NULL, -1);
217
 
 
218
 
        profile = LASSO_WSF_PROFILE(service);
219
 
 
220
 
        envelope = LASSO_SOAP_ENVELOPE(lasso_node_new_from_dump(modify_soap_msg));
221
 
        LASSO_WSF_PROFILE(service)->soap_envelope_request = envelope;
222
 
        LASSO_WSF_PROFILE(service)->request = LASSO_NODE(envelope->Body->any->data);
223
 
 
224
 
        correlation = envelope->Header->Other->data;
225
 
        messageId = correlation->messageID;
226
 
        envelope = lasso_wsf_profile_build_soap_envelope(messageId);
227
 
        LASSO_WSF_PROFILE(service)->soap_envelope_response = envelope;
228
 
 
229
 
        /* init QueryResponse */
230
 
        status = lasso_utility_status_new(LASSO_DST_STATUS_CODE_OK);
231
 
        response = lasso_dst_modify_response_new(status);
232
 
        LASSO_WSF_PROFILE(service)->response = LASSO_NODE(response);
233
 
        LASSO_DST_MODIFY_RESPONSE(profile->response)->prefixServiceType = g_strdup(prefix);
234
 
        LASSO_DST_MODIFY_RESPONSE(profile->response)->hrefServiceType = g_strdup(href);
235
 
 
236
 
        envelope->Body->any = g_list_append(envelope->Body->any, response);
237
 
 
238
 
        return 0;
239
 
}
240
 
 
241
 
gint
242
 
lasso_profile_service_process_query_msg(LassoProfileService *service,
243
 
                                        const gchar *prefix, /* FIXME : must be get from message */
244
 
                                        const gchar *href,   /* FIXME : must be get from message */
245
 
                                        const gchar *soap_msg)
246
 
{
247
 
        LassoDstQueryResponse *response;
248
 
        LassoSoapBindingCorrelation *correlation;
249
 
        LassoSoapEnvelope *envelope;
250
 
        LassoUtilityStatus *status;
251
 
        LassoWsfProfile *profile;
252
 
        gchar *messageId;
253
 
 
254
 
        g_return_val_if_fail(LASSO_IS_PROFILE_SERVICE(service), -1);
255
 
        g_return_val_if_fail(soap_msg != NULL, -1);
256
 
 
257
 
        profile = LASSO_WSF_PROFILE(service);
258
 
 
259
 
        envelope = LASSO_SOAP_ENVELOPE(lasso_node_new_from_dump(soap_msg));
260
 
        LASSO_WSF_PROFILE(service)->soap_envelope_request = envelope;
261
 
        LASSO_WSF_PROFILE(service)->request = LASSO_NODE(envelope->Body->any->data);
262
 
 
263
 
        correlation = envelope->Header->Other->data;
264
 
        messageId = correlation->messageID;
265
 
        envelope = lasso_wsf_profile_build_soap_envelope(messageId);
266
 
        LASSO_WSF_PROFILE(service)->soap_envelope_response = envelope;
267
 
 
268
 
        /* init QueryResponse */
269
 
        status = lasso_utility_status_new(LASSO_DST_STATUS_CODE_OK);
270
 
        response = lasso_dst_query_response_new(status);
271
 
        LASSO_WSF_PROFILE(service)->response = LASSO_NODE(response);
272
 
        LASSO_DST_QUERY_RESPONSE(profile->response)->prefixServiceType = g_strdup(prefix);
273
 
        LASSO_DST_QUERY_RESPONSE(profile->response)->hrefServiceType = g_strdup(href);
274
 
 
275
 
        envelope->Body->any = g_list_append(envelope->Body->any, response);
276
 
 
277
 
        return 0;
278
 
}
279
 
 
280
 
gint
281
 
lasso_profile_service_process_query_response_msg(LassoProfileService *service,
282
 
                                                 const gchar *prefix,
283
 
                                                 const gchar *href,
284
 
                                                 const gchar *soap_msg)
285
 
{
286
 
        LassoDstQueryResponse *response;
287
 
        LassoSoapEnvelope *envelope;
288
 
 
289
 
        g_return_val_if_fail(LASSO_IS_PROFILE_SERVICE(service), -1);
290
 
        g_return_val_if_fail(soap_msg != NULL, -1);
291
 
 
292
 
        envelope = LASSO_SOAP_ENVELOPE(lasso_node_new_from_dump(soap_msg));
293
 
        LASSO_WSF_PROFILE(service)->soap_envelope_response = envelope;
294
 
 
295
 
        response = envelope->Body->any->data;
296
 
        LASSO_WSF_PROFILE(service)->response = LASSO_NODE(response);
297
 
 
298
 
        return 0;
299
 
}
300
 
 
301
 
gint
302
 
lasso_profile_service_process_modify_response_msg(LassoProfileService *service,
303
 
                                                  const gchar *prefix,
304
 
                                                  const gchar *href,
305
 
                                                  const gchar *soap_msg)
306
 
{
307
 
        LassoDstModifyResponse *response;
308
 
        LassoSoapEnvelope *envelope;
309
 
 
310
 
        g_return_val_if_fail(LASSO_IS_PROFILE_SERVICE(service), -1);
311
 
        g_return_val_if_fail(soap_msg != NULL, -1);
312
 
 
313
 
        envelope = LASSO_SOAP_ENVELOPE(lasso_node_new_from_dump(soap_msg));
314
 
        LASSO_WSF_PROFILE(service)->soap_envelope_response = envelope;
315
 
 
316
 
        response = envelope->Body->any->data;
317
 
        LASSO_WSF_PROFILE(service)->response = LASSO_NODE(response);
318
 
 
319
 
        return 0;
320
 
}
321
 
 
322
 
 
323
 
/*****************************************************************************/
324
 
/* private methods                                                           */
325
 
/*****************************************************************************/
326
 
 
327
 
/*****************************************************************************/
328
 
/* instance and class init functions                                         */
329
 
/*****************************************************************************/
330
 
 
331
 
static void
332
 
instance_init(LassoProfileService *service)
333
 
{
334
 
 
335
 
}
336
 
 
337
 
static void
338
 
class_init(LassoProfileServiceClass *klass)
339
 
{
340
 
 
341
 
}
342
 
 
343
 
GType
344
 
lasso_profile_service_get_type()
345
 
{
346
 
        static GType this_type = 0;
347
 
 
348
 
        if (!this_type) {
349
 
                static const GTypeInfo this_info = {
350
 
                        sizeof(LassoProfileServiceClass),
351
 
                        NULL,
352
 
                        NULL,
353
 
                        (GClassInitFunc) class_init,
354
 
                        NULL,
355
 
                        NULL,
356
 
                        sizeof(LassoProfileService),
357
 
                        0,
358
 
                        (GInstanceInitFunc) instance_init,
359
 
                };
360
 
 
361
 
                this_type = g_type_register_static(LASSO_TYPE_WSF_PROFILE,
362
 
                                "LassoProfileService", &this_info, 0);
363
 
        }
364
 
        return this_type;
365
 
}
366
 
 
367
 
LassoProfileService*
368
 
lasso_profile_service_new(LassoServer *server)
369
 
{
370
 
        LassoProfileService *service = NULL;
371
 
 
372
 
        g_return_val_if_fail(LASSO_IS_SERVER(server) == TRUE, NULL);
373
 
 
374
 
        service = g_object_new(LASSO_TYPE_PROFILE_SERVICE, NULL);
375
 
 
376
 
        return service;
377
 
}