~ubuntu-branches/ubuntu/utopic/libinfinity/utopic-proposed

« back to all changes in this revision

Viewing changes to libinfinity/common/inf-session.c

  • Committer: Bazaar Package Importer
  • Author(s): Philipp Kern
  • Date: 2011-04-01 10:44:57 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20110401104457-q7927ly61fr51tqs
Tags: 0.5.0-1
* New upstream release.
* Drop patches applied upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* libinfinity - a GObject-based infinote implementation
2
 
 * Copyright (C) 2007, 2008, 2009 Armin Burgmeier <armin@arbur.net>
 
2
 * Copyright (C) 2007-2011 Armin Burgmeier <armin@arbur.net>
3
3
 *
4
4
 * This library is free software; you can redistribute it and/or
5
5
 * modify it under the terms of the GNU Lesser General Public
43
43
 * To be notified about changes other users make to a session, you need to
44
44
 * subscribe to the session (on client side), or wait for incoming
45
45
 * subscriptions (on server side). This is normally done by
46
 
 * infc_browser_subscribe_session(). The first action that is performed upon
47
 
 * subscription is a synchronization as described above. When the
 
46
 * infc_browser_iter_subscribe_session(). The first action that is performed
 
47
 * upon subscription is a synchronization as described above. When the
48
48
 * synchronization is complete, the #InfSession::synchronization-complete signal
49
49
 * is emitted.
50
50
 *
51
51
 * After subscription, one can observe modifications other users make, but it is
52
52
 * not possible to make own modifications. Before doing so, a #InfUser needs to
53
53
 * be joined. This is done by client/server specific API such as
54
 
 * infc_session_proxy_join_user() or infd_session_proxy_join_user(). The
 
54
 * infc_session_proxy_join_user() or infd_session_proxy_add_user(). The
55
55
 * required parameters still depend on the actual note type, which is why most
56
56
 * note implementations offer their own API to join a user.
57
57
 **/
318
318
{
319
319
  InfSessionPrivate* priv;
320
320
  xmlNodePtr node;
321
 
  gchar code_buf[16];
322
321
 
323
322
  priv = INF_SESSION_PRIVATE(session);
324
323
 
325
324
  g_return_if_fail(priv->status == INF_SESSION_SYNCHRONIZING);
326
325
  g_return_if_fail(priv->shared.sync.conn != NULL);
327
326
 
328
 
  node = xmlNewNode(NULL, (const xmlChar*)"sync-error");
329
 
 
330
 
  xmlNewProp(
331
 
     node,
332
 
    (const xmlChar*)"domain",
333
 
    (const xmlChar*)g_quark_to_string(error->domain)
334
 
  );
335
 
 
336
 
  sprintf(code_buf, "%u", (unsigned int)error->code);
337
 
  xmlNewProp(node, (const xmlChar*)"code", (const xmlChar*)code_buf);
 
327
  node = inf_xml_util_new_node_from_error(error, NULL, "sync-error");
338
328
 
339
329
  inf_communication_group_send_message(
340
330
    priv->shared.sync.group,
1469
1459
  InfSessionPrivate* priv;
1470
1460
  InfSessionSync* sync;
1471
1461
  gboolean result;
1472
 
  GQuark domain;
1473
 
  InfSessionSyncError code;
1474
 
  xmlChar* domain_attr;
1475
 
  xmlChar* code_attr;
1476
1462
  GError* local_error;
 
1463
  const gchar* local_message;
1477
1464
 
1478
1465
  session = INF_SESSION(comm_object);
1479
1466
  priv = INF_SESSION_PRIVATE(session);
1532
1519
    {
1533
1520
      if(strcmp((const gchar*)node->name, "sync-error") == 0)
1534
1521
      {
1535
 
        local_error = NULL;
1536
 
 
1537
1522
        /* There was an error during synchronization, cancel remaining
1538
1523
         * messages. */
1539
1524
        inf_communication_group_cancel_messages(sync->group, connection);
1540
1525
 
1541
 
        domain_attr = xmlGetProp(node, (const xmlChar*)"domain");
1542
 
        code_attr = xmlGetProp(node, (const xmlChar*)"code");
 
1526
        local_error = inf_xml_util_new_error_from_node(node);
1543
1527
 
1544
 
        if(domain_attr != NULL && code_attr != NULL)
 
1528
        if(local_error != NULL)
1545
1529
        {
1546
 
          domain = g_quark_from_string((const gchar*)domain_attr);
1547
 
          code = strtoul((const gchar*)code_attr, NULL, 0);
1548
 
 
1549
 
          g_set_error(
1550
 
            &local_error,
1551
 
            domain,
1552
 
            code,
1553
 
            "%s",
1554
 
            inf_session_get_sync_error_message(domain, code)
1555
 
          );
 
1530
          local_message =
 
1531
            inf_session_get_sync_error_message(local_error->domain,
 
1532
                                               local_error->code);
 
1533
          if(local_message != NULL)
 
1534
          {
 
1535
            if(local_error->message != NULL)
 
1536
              g_free(local_error->message);
 
1537
            local_error->message = g_strdup(local_message);
 
1538
          }
1556
1539
        }
1557
1540
        else
1558
1541
        {
1565
1548
          );
1566
1549
        }
1567
1550
 
1568
 
        if(domain_attr != NULL) xmlFree(domain_attr);
1569
 
        if(code_attr != NULL) xmlFree(code_attr);
1570
 
 
1571
1551
        /* Note the default handler actually removes the sync */
1572
1552
        g_signal_emit(
1573
1553
          G_OBJECT(session),
2104
2084
   * This signal is emitted whenever a new XML node has been sent or received
2105
2085
   * over @connection as part of a synchronization. The process is completed
2106
2086
   * when @progress reaches the value 1.0. At this point,
2107
 
   * #InfSession::synchronisation-complete is also emitted.
 
2087
   * #InfSession::synchronization-complete is also emitted.
2108
2088
   *
2109
 
   * If @sessions&apos;s status is %INF_SESSION_SYNCHRONIZING, the local
 
2089
   * If @session&apos;s status is %INF_SESSION_SYNCHRONIZING, the local
2110
2090
   * side is being synchronized by the remote side. If the status is
2111
2091
   * %INF_SESSION_RUNNING, the local side is updating the remote side.
2112
2092
   */
2535
2515
 * Changes the status of the given @user which needs to have the
2536
2516
 * %INF_USER_LOCAL flag set for this function to be called. If the status
2537
2517
 * is changed to %INF_USER_UNAVAILABLE, then the user leaves the session. To
2538
 
 * rejoin use infc_session_proxy_join_user or infd_session_proxy_join_user,
 
2518
 * rejoin use infc_session_proxy_join_user() or infd_session_proxy_add_user(),
2539
2519
 * respectively for a proxy proxying @session.
2540
2520
 **/
2541
2521
void