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

« back to all changes in this revision

Viewing changes to lasso/protocols/federation.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: federation.c,v 1.7 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: Nicolas Clapies <nclapies@entrouvert.com>
 
9
 *          Valery Febvre <vfebvre@easter-eggs.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/federation.h>
 
27
 
 
28
struct _LassoFederationPrivate
 
29
{
 
30
  gboolean dispose_has_run;
 
31
};
 
32
 
 
33
static GObjectClass *parent_class = NULL;
 
34
 
 
35
/*****************************************************************************/
 
36
/* public methods                                                            */
 
37
/*****************************************************************************/
 
38
 
 
39
LassoFederation*
 
40
lasso_federation_copy(LassoFederation *federation)
 
41
{
 
42
  LassoFederation *copy;
 
43
 
 
44
  g_return_val_if_fail(LASSO_IS_FEDERATION(federation), NULL);
 
45
 
 
46
  copy = LASSO_FEDERATION(g_object_new(LASSO_TYPE_FEDERATION, NULL));
 
47
  copy->remote_providerID = g_strdup(federation->remote_providerID);
 
48
  if (federation->local_nameIdentifier != NULL) {
 
49
    copy->local_nameIdentifier = lasso_node_copy(federation->local_nameIdentifier);
 
50
  }
 
51
  if (federation->remote_nameIdentifier != NULL) {
 
52
    copy->remote_nameIdentifier = lasso_node_copy(federation->remote_nameIdentifier);
 
53
  }
 
54
 
 
55
  return copy;
 
56
}
 
57
 
 
58
void
 
59
lasso_federation_destroy(LassoFederation *federation)
 
60
{
 
61
  g_object_unref(G_OBJECT(federation));
 
62
}
 
63
 
 
64
gchar *
 
65
lasso_federation_dump(LassoFederation *federation)
 
66
{
 
67
  LassoNode *federation_node, *nameIdentifier;
 
68
  LassoNode *local_nameIdentifier, *remote_nameIdentifier;
 
69
  LassoNodeClass *federation_class, *class;
 
70
  gchar *dump;
 
71
 
 
72
  federation_node = lasso_node_new();
 
73
  federation_class = LASSO_NODE_GET_CLASS(federation_node);
 
74
  federation_class->set_name(federation_node, LASSO_FEDERATION_NODE);
 
75
  federation_class->set_ns(federation_node, lassoLassoHRef, NULL);
 
76
 
 
77
  /* set the remote providerID */
 
78
  federation_class->set_prop(federation_node, LASSO_FEDERATION_REMOTE_PROVIDERID_NODE,
 
79
                             federation->remote_providerID);
 
80
 
 
81
  /* add the remote name identifier */
 
82
  if(federation->remote_nameIdentifier != NULL) {
 
83
    nameIdentifier = lasso_node_new();
 
84
    class = LASSO_NODE_GET_CLASS(nameIdentifier);
 
85
    class->set_name(nameIdentifier, LASSO_FEDERATION_REMOTE_NAME_IDENTIFIER_NODE);
 
86
    remote_nameIdentifier = lasso_node_copy(federation->remote_nameIdentifier);
 
87
    class->add_child(nameIdentifier, remote_nameIdentifier, FALSE);
 
88
    lasso_node_destroy(remote_nameIdentifier);
 
89
    federation_class->add_child(federation_node, nameIdentifier, FALSE);
 
90
    lasso_node_destroy(nameIdentifier);
 
91
  }
 
92
 
 
93
  /* add the local name identifier */
 
94
  if(federation->local_nameIdentifier != NULL) {
 
95
    nameIdentifier = lasso_node_new();
 
96
    class = LASSO_NODE_GET_CLASS(nameIdentifier);
 
97
    class->set_name(nameIdentifier, LASSO_FEDERATION_LOCAL_NAME_IDENTIFIER_NODE);
 
98
    local_nameIdentifier = lasso_node_copy(federation->local_nameIdentifier);
 
99
    class->add_child(nameIdentifier, local_nameIdentifier, FALSE);
 
100
    lasso_node_destroy(local_nameIdentifier);
 
101
    federation_class->add_child(federation_node, nameIdentifier, FALSE);
 
102
    lasso_node_destroy(nameIdentifier);
 
103
  }
 
104
 
 
105
  dump = lasso_node_export(federation_node);
 
106
  lasso_node_destroy(federation_node);
 
107
 
 
108
  return dump;
 
109
}
 
110
 
 
111
LassoNode *
 
112
lasso_federation_get_local_nameIdentifier(LassoFederation *federation)
 
113
{
 
114
  if (federation->local_nameIdentifier != NULL) {
 
115
    return lasso_node_copy(federation->local_nameIdentifier);
 
116
  }
 
117
  else {
 
118
    return NULL;
 
119
  }
 
120
}
 
121
 
 
122
LassoNode *
 
123
lasso_federation_get_remote_nameIdentifier(LassoFederation *federation)
 
124
{
 
125
  if (federation->remote_nameIdentifier != NULL) {
 
126
    return lasso_node_copy(federation->remote_nameIdentifier);
 
127
  }
 
128
  else {
 
129
    return NULL;
 
130
  }
 
131
}
 
132
 
 
133
void
 
134
lasso_federation_remove_local_nameIdentifier(LassoFederation *federation)
 
135
{
 
136
  if(federation->local_nameIdentifier != NULL) {
 
137
    lasso_node_destroy(federation->local_nameIdentifier);
 
138
  }
 
139
}
 
140
 
 
141
void
 
142
lasso_federation_remove_remote_nameIdentifier(LassoFederation *federation)
 
143
{
 
144
  if(federation->remote_nameIdentifier != NULL){
 
145
    lasso_node_destroy(federation->remote_nameIdentifier);
 
146
  }
 
147
}
 
148
 
 
149
void
 
150
lasso_federation_set_local_nameIdentifier(LassoFederation *federation,
 
151
                                          LassoNode       *nameIdentifier)
 
152
{
 
153
  federation->local_nameIdentifier = lasso_node_copy(nameIdentifier);
 
154
}
 
155
 
 
156
void
 
157
lasso_federation_set_remote_nameIdentifier(LassoFederation *federation,
 
158
                                           LassoNode       *nameIdentifier)
 
159
{
 
160
  federation->remote_nameIdentifier = lasso_node_copy(nameIdentifier);
 
161
}
 
162
 
 
163
gboolean
 
164
lasso_federation_verify_nameIdentifier(LassoFederation *federation,
 
165
                                       LassoNode       *nameIdentifier)
 
166
{
 
167
  gchar *federation_content, *nameIdentifier_content;
 
168
 
 
169
  nameIdentifier_content = lasso_node_get_content(nameIdentifier, NULL);
 
170
  if(federation->local_nameIdentifier != NULL) {
 
171
    federation_content = lasso_node_get_content(federation->local_nameIdentifier,
 
172
                                                NULL);
 
173
    if(xmlStrEqual(federation_content, nameIdentifier_content)) {
 
174
      xmlFree(federation_content);
 
175
      return TRUE;
 
176
    }
 
177
    xmlFree(federation_content);
 
178
  }
 
179
  if(federation->remote_nameIdentifier != NULL) {
 
180
    federation_content = lasso_node_get_content(federation->remote_nameIdentifier,
 
181
                                                NULL);
 
182
    if(xmlStrEqual(federation_content, nameIdentifier_content)) {
 
183
      xmlFree(federation_content);
 
184
      return TRUE;
 
185
    }
 
186
    xmlFree(federation_content);
 
187
  }
 
188
  xmlFree(nameIdentifier_content);
 
189
    
 
190
  return FALSE;
 
191
}
 
192
 
 
193
/*****************************************************************************/
 
194
/* overrided parent class methods                                            */
 
195
/*****************************************************************************/
 
196
 
 
197
static void
 
198
lasso_federation_dispose(LassoFederation *federation)
 
199
{
 
200
  if (federation->private->dispose_has_run) {
 
201
    return;
 
202
  }
 
203
  federation->private->dispose_has_run = TRUE;
 
204
 
 
205
  debug("Federation object 0x%x disposed ...\n", federation);
 
206
 
 
207
  /* unref reference counted objects */
 
208
  lasso_node_destroy(federation->local_nameIdentifier);
 
209
  lasso_node_destroy(federation->remote_nameIdentifier);
 
210
 
 
211
  parent_class->dispose(G_OBJECT(federation));
 
212
}
 
213
 
 
214
static void
 
215
lasso_federation_finalize(LassoFederation *federation)
 
216
{
 
217
  debug("Federation object 0x%x finalized ...\n", federation);
 
218
 
 
219
  g_free(federation->remote_providerID);
 
220
  g_free(federation->private);
 
221
 
 
222
  parent_class->finalize(G_OBJECT(federation));
 
223
}
 
224
 
 
225
/*****************************************************************************/
 
226
/* instance and class init functions                                         */
 
227
/*****************************************************************************/
 
228
 
 
229
static void
 
230
lasso_federation_instance_init(LassoFederation *federation)
 
231
{
 
232
  federation->private = g_new (LassoFederationPrivate, 1);
 
233
  federation->private->dispose_has_run = FALSE;
 
234
 
 
235
  federation->remote_providerID  = NULL;
 
236
  federation->local_nameIdentifier  = NULL;
 
237
  federation->remote_nameIdentifier = NULL;
 
238
}
 
239
 
 
240
static void
 
241
lasso_federation_class_init(LassoFederationClass *g_class)
 
242
{
 
243
  GObjectClass *gobject_class = G_OBJECT_CLASS (g_class);
 
244
 
 
245
  parent_class = g_type_class_peek_parent(g_class);
 
246
  /* override parent class methods */
 
247
  gobject_class->dispose  = (void *)lasso_federation_dispose;
 
248
  gobject_class->finalize = (void *)lasso_federation_finalize;
 
249
}
 
250
 
 
251
GType lasso_federation_get_type() {
 
252
  static GType this_type = 0;
 
253
 
 
254
  if (!this_type) {
 
255
    static const GTypeInfo this_info = {
 
256
      sizeof (LassoFederationClass),
 
257
      NULL,
 
258
      NULL,
 
259
      (GClassInitFunc) lasso_federation_class_init,
 
260
      NULL,
 
261
      NULL,
 
262
      sizeof(LassoFederation),
 
263
      0,
 
264
      (GInstanceInitFunc) lasso_federation_instance_init,
 
265
    };
 
266
    
 
267
    this_type = g_type_register_static(G_TYPE_OBJECT,
 
268
                                       "LassoFederation",
 
269
                                       &this_info, 0);
 
270
  }
 
271
  return this_type;
 
272
}
 
273
 
 
274
LassoFederation*
 
275
lasso_federation_new(gchar *remote_providerID)
 
276
{
 
277
  LassoFederation *federation;
 
278
 
 
279
  g_return_val_if_fail(remote_providerID != NULL, NULL);
 
280
 
 
281
  federation = LASSO_FEDERATION(g_object_new(LASSO_TYPE_FEDERATION, NULL));
 
282
 
 
283
  federation->remote_providerID = g_strdup(remote_providerID);
 
284
 
 
285
  return federation;
 
286
}
 
287
 
 
288
LassoFederation*
 
289
lasso_federation_new_from_dump(gchar *dump)
 
290
{
 
291
  LassoFederation *federation;
 
292
 
 
293
  g_return_val_if_fail(dump != NULL, NULL);
 
294
 
 
295
  federation = LASSO_FEDERATION(g_object_new(LASSO_TYPE_FEDERATION, NULL));
 
296
 
 
297
  return federation;
 
298
}