~ubuntu-branches/ubuntu/maverick/telepathy-salut/maverick

« back to all changes in this revision

Viewing changes to src/salut-muc-manager.c

  • Committer: Bazaar Package Importer
  • Author(s): Sjoerd Simons
  • Date: 2007-06-13 10:54:25 UTC
  • mto: (7.1.1 hardy) (9.1.1 jaunty) (1.3.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 5.
  • Revision ID: james.westby@ubuntu.com-20070613105425-6y7im8a63vq5ooyc
Tags: upstream-0.1.3
ImportĀ upstreamĀ versionĀ 0.1.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
#include "salut-muc-manager.h"
26
26
#include "salut-muc-manager-signals-marshal.h"
27
27
 
28
 
#include "salut-muc-connection.h"
 
28
#include <gibber/gibber-muc-connection.h>
29
29
 
30
30
#include "salut-muc-channel.h"
31
31
#include "salut-contact-manager.h"
202
202
  }
203
203
}
204
204
 
205
 
GObject *
206
 
_get_connection(SalutMucManager *mgr, const gchar *name, 
207
 
               const gchar *protocol, GHashTable *parameters, GError **error) {
208
 
  SalutMucConnection *connection;
 
205
GibberMucConnection *
 
206
_get_connection(SalutMucManager *mgr, const gchar *protocol, 
 
207
    GHashTable *parameters, GError **error) {
 
208
  SalutMucManagerPrivate *priv = SALUT_MUC_MANAGER_GET_PRIVATE(mgr);
209
209
 
210
 
  connection = salut_muc_connection_new(name, protocol, parameters, error);
211
 
  return connection == NULL ? NULL : G_OBJECT(connection);
 
210
  return gibber_muc_connection_new(priv->connection->name, 
 
211
      protocol, parameters, error);
212
212
}
213
213
 
214
214
const gchar **
215
215
_get_connection_parameters(SalutMucManager *mgr, const gchar *protocol) {
216
 
  return salut_muc_connection_get_required_parameters(protocol); 
 
216
  return gibber_muc_connection_get_required_parameters(protocol); 
217
217
}
218
218
 
219
219
static SalutMucChannel *
220
220
salut_muc_manager_new_channel(SalutMucManager *mgr, TpHandle handle,
221
 
                              GObject *connection) {
 
221
                              GibberMucConnection *connection) {
222
222
  SalutMucManagerPrivate *priv = SALUT_MUC_MANAGER_GET_PRIVATE(mgr);
223
223
  TpBaseConnection *base_connection = TP_BASE_CONNECTION(priv->connection);
224
224
  TpHandleRepoIface *room_repo = 
231
231
             == NULL);
232
232
  DEBUG("Requested channel for handle: %d", handle);
233
233
 
234
 
  /* FIXME The name of the muc and the handel might need to be different at
 
234
  /* FIXME The name of the muc and the handle might need to be different at
235
235
   * some point.. E.g. if two rooms are called the same */
236
236
  name = tp_handle_inspect(room_repo, handle);
237
237
  path = g_strdup_printf("%s/MucChannel/%u", 
267
267
  TpHandleRepoIface *room_repo = 
268
268
      tp_base_connection_get_handles(base_connection, TP_HANDLE_TYPE_ROOM);
269
269
  SalutMucChannel *chan;
270
 
  gboolean created = FALSE;
 
270
  TpChannelFactoryRequestStatus status;
271
271
 
272
272
  DEBUG("Muc request");
273
273
 
287
287
  }
288
288
 
289
289
  chan = g_hash_table_lookup(priv->channels, GINT_TO_POINTER(handle));
 
290
 
290
291
  if (chan != NULL) { 
291
292
    *ret = TP_CHANNEL_IFACE(chan);
292
 
    created = FALSE;
 
293
    status = TP_CHANNEL_FACTORY_REQUEST_STATUS_EXISTING;
293
294
  } else {
294
 
    GObject *connection = _get_connection(mgr,
295
 
                                          priv->connection->name,
 
295
    GibberMucConnection *connection = _get_connection(mgr,
296
296
                                          NULL, NULL, NULL);
297
 
    created = TRUE;
 
297
    status = TP_CHANNEL_FACTORY_REQUEST_STATUS_CREATED;
298
298
    if (connection == NULL) {
299
299
      return TP_CHANNEL_FACTORY_REQUEST_STATUS_NOT_AVAILABLE;
300
300
    }
301
 
    chan = salut_muc_manager_new_channel(mgr, handle, connection);
 
301
 
302
302
    /* We requested the channel, so invite ourselves to it */
303
 
    if (chan)  {
304
 
      salut_muc_channel_invited(chan, base_connection->self_handle, "");
 
303
    {
 
304
      GError *cerror = NULL;
 
305
      if (!gibber_muc_connection_connect(connection, &cerror)) {
 
306
        DEBUG("Connect failed: %s", cerror->message);
 
307
        status = TP_CHANNEL_FACTORY_REQUEST_STATUS_ERROR;
 
308
        g_set_error(error, TP_ERRORS,
 
309
                    TP_ERROR_NETWORK_ERROR, cerror->message);
 
310
        g_error_free(cerror);
 
311
        g_object_unref(connection);
 
312
        goto out;
 
313
      }
 
314
      DEBUG("Connect succeeded");
 
315
 
 
316
      chan = salut_muc_manager_new_channel(mgr, handle, connection);
 
317
      /* Inviting ourselves to a connected channel should always succeed */
 
318
      g_assert(salut_muc_channel_invited(chan, base_connection->self_handle,
 
319
                                     NULL, NULL));
305
320
      *ret = TP_CHANNEL_IFACE(chan);
306
321
    }
307
 
    g_assert(chan != NULL);
308
322
  }
 
323
  g_assert(chan != NULL);
309
324
 
310
 
  return created ? TP_CHANNEL_FACTORY_REQUEST_STATUS_CREATED 
311
 
                 : TP_CHANNEL_FACTORY_REQUEST_STATUS_EXISTING;
 
325
out:
 
326
  return status;
312
327
}
313
328
 
314
329
static void salut_muc_manager_factory_iface_init(gpointer *g_iface, 
344
359
  TpHandle invitor_handle;
345
360
  const gchar **p;
346
361
  GHashTable *params_hash;
347
 
  GObject *transport = NULL;
 
362
  GibberMucConnection *connection = NULL;
348
363
 
349
364
  node = gibber_xmpp_node_get_child_ns(message->node, "x", NS_LLMUC);
350
365
  if (node == NULL) 
373
388
  if (reason == NULL) {
374
389
    reason = "";
375
390
  }
376
 
  
 
391
 
377
392
  protocol = gibber_xmpp_node_get_attribute(invite, "protocol");
378
393
  if (protocol == NULL) { 
379
394
    DEBUG("Invalid invitation, (missing protocol) discarding");
408
423
  chan = g_hash_table_lookup(priv->channels, GINT_TO_POINTER(room_handle));
409
424
 
410
425
  if (chan == NULL) {
411
 
    transport = _get_connection(self, room, protocol, params_hash, NULL);
412
 
    if (transport == NULL) {
 
426
    connection = _get_connection(self, protocol, params_hash, NULL);
 
427
    if (connection == NULL) {
413
428
      DEBUG("Invalid invitation, (wrong protocol parameters) discarding");
414
429
      goto discard;
415
430
    }
416
431
 
417
 
    if (transport == NULL) {
 
432
    if (connection == NULL) {
418
433
      tp_handle_unref(room_repo, room_handle);
419
434
      /* FIXME some kinda error to the user maybe ? Ignore for now */
420
435
      goto discard;
421
436
    }
422
437
    /* Need to create a new one */
423
 
    chan = salut_muc_manager_new_channel(self, room_handle, transport);
 
438
    chan = salut_muc_manager_new_channel(self, room_handle, connection);
424
439
  }
425
440
  /* FIXME handle properly */
426
441
  g_assert(chan != NULL);
427
442
 
428
443
  g_object_get(G_OBJECT(imchannel), "handle", &invitor_handle, NULL);
429
 
  salut_muc_channel_invited(chan, invitor_handle, reason);
 
444
  salut_muc_channel_invited(chan, invitor_handle, reason, NULL);
430
445
 
431
446
  g_hash_table_destroy(params_hash);
432
447