loudmouth/lm-connection.c
author Frank Zschockelt <lm@freakysoft.de>
Tue, 13 Apr 2010 23:21:01 +0200
changeset 619 a3facd81de25
parent 614 773201ca404c
child 624 a94013a4555d
permissions -rw-r--r--
Revert "Code looks for an auth element below the returned streams:feature" This reverts commit b94583bb7db80803c48add517a5559d45b6f3a58. Do not try to hack around bugs of the server...
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
516
4dd3aa6b83e5 Change the tab width to 4 steps in the emacs headers
Mikael Hallendal <micke@imendio.com>
parents: 515
diff changeset
     1
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
     2
/*
512
9f050099129d Updated copyright years
Mikael Hallendal <micke@imendio.com>
parents: 510
diff changeset
     3
 * Copyright (C) 2003-2008 Imendio AB
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
     4
 * Copyright (C) 2006 Nokia Corporation. All rights reserved.
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
     5
 * Copyright (C) 2007 Collabora Ltd.
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
     6
 *
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
     7
 * This program is free software; you can redistribute it and/or
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
     8
 * modify it under the terms of the GNU Lesser General Public License as
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
     9
 * published by the Free Software Foundation; either version 2 of the
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    10
 * License, or (at your option) any later version.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    11
 *
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    12
 * This program is distributed in the hope that it will be useful,
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    15
 * Lesser General Public License for more details.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    16
 *
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    17
 * You should have received a copy of the GNU Lesser General Public
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    18
 * License along with this program; if not, write to the
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    19
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    20
 * Boston, MA 02111-1307, USA.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    21
 */
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    22
417
364c17252e5f Added inlined documentation from generated through the Gtk-doc migration script.
Mikael Hallendal <micke@imendio.com>
parents: 416
diff changeset
    23
/**
420
f40434cca022 Fixed the SECTION parts of the inlined docs so that gtk-doc finds them.
Mikael Hallendal <micke@imendio.com>
parents: 417
diff changeset
    24
 * SECTION:lm-connection
421
2a91651d22de Added Title to the inlined documentation
Mikael Hallendal <micke@imendio.com>
parents: 420
diff changeset
    25
 * @Title: LmConnection
417
364c17252e5f Added inlined documentation from generated through the Gtk-doc migration script.
Mikael Hallendal <micke@imendio.com>
parents: 416
diff changeset
    26
 * @Short_description: A client connection to the server
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
    27
 *
417
364c17252e5f Added inlined documentation from generated through the Gtk-doc migration script.
Mikael Hallendal <micke@imendio.com>
parents: 416
diff changeset
    28
 * An example of how to use Loudmouth with the synchronous API.
364c17252e5f Added inlined documentation from generated through the Gtk-doc migration script.
Mikael Hallendal <micke@imendio.com>
parents: 416
diff changeset
    29
 * <informalexample><programlisting>
364c17252e5f Added inlined documentation from generated through the Gtk-doc migration script.
Mikael Hallendal <micke@imendio.com>
parents: 416
diff changeset
    30
 * int
364c17252e5f Added inlined documentation from generated through the Gtk-doc migration script.
Mikael Hallendal <micke@imendio.com>
parents: 416
diff changeset
    31
 * main (int argc, char **argv)
364c17252e5f Added inlined documentation from generated through the Gtk-doc migration script.
Mikael Hallendal <micke@imendio.com>
parents: 416
diff changeset
    32
 * {
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
    33
 *      LmConnection *connection;
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
    34
 *      GError       *error = NULL;
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
    35
 *      gint          i;
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
    36
 *      LmMessage    *m;
420
f40434cca022 Fixed the SECTION parts of the inlined docs so that gtk-doc finds them.
Mikael Hallendal <micke@imendio.com>
parents: 417
diff changeset
    37
 *
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
    38
 *      connection = lm_connection_new ("myserver");
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
    39
 *
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
    40
 *      if (!lm_connection_open_and_block (connection, &amp;error)) {
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
    41
 *          g_error ("Failed to open: &percnt;s\n", error->message);
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
    42
 *      }
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
    43
 *
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
    44
 *      if (!lm_connection_authenticate_and_block (connection,
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
    45
 *                                                 "username", "password",
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
    46
 *                                                 "resource",
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
    47
 *                                                 &amp;error)) {
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
    48
 *          g_error ("Failed to authenticate: &percnt;s\n", error->message);
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
    49
 *      }
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
    50
 *
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
    51
 *      m = lm_message_new ("recipient", LM_MESSAGE_TYPE_MESSAGE);
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
    52
 *      lm_message_node_add_child (m->node, "body", "message");
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
    53
 *
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
    54
 *      if (!lm_connection_send (connection, m, &amp;error)) {
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
    55
 *          g_error ("Send failed: &percnt;s\n", error->message);
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
    56
 *      }
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
    57
 *
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
    58
 *      lm_message_unref (m);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
    59
 *
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
    60
 *      lm_connection_close (connection, NULL);
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
    61
 *      lm_connection_unref (connection);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
    62
 *
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
    63
 *      return 0;
417
364c17252e5f Added inlined documentation from generated through the Gtk-doc migration script.
Mikael Hallendal <micke@imendio.com>
parents: 416
diff changeset
    64
 * }
364c17252e5f Added inlined documentation from generated through the Gtk-doc migration script.
Mikael Hallendal <micke@imendio.com>
parents: 416
diff changeset
    65
 * </programlisting></informalexample>
364c17252e5f Added inlined documentation from generated through the Gtk-doc migration script.
Mikael Hallendal <micke@imendio.com>
parents: 416
diff changeset
    66
 */
364c17252e5f Added inlined documentation from generated through the Gtk-doc migration script.
Mikael Hallendal <micke@imendio.com>
parents: 416
diff changeset
    67
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    68
#include <config.h>
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    69
12
fc5e71b1369c 2003-07-07 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 9
diff changeset
    70
#include <string.h>
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
    71
#include <sys/stat.h>
12
fc5e71b1369c 2003-07-07 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 9
diff changeset
    72
#include <sys/types.h>
59
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
    73
#include <fcntl.h>
337
7bc0c6ad11ff Fixes LM-118 so that building on Mac OS X works again.
Richard Hult <richard@imendio.com>
parents: 324
diff changeset
    74
7bc0c6ad11ff Fixes LM-118 so that building on Mac OS X works again.
Richard Hult <richard@imendio.com>
parents: 324
diff changeset
    75
/* Needed on Mac OS X */
7bc0c6ad11ff Fixes LM-118 so that building on Mac OS X works again.
Richard Hult <richard@imendio.com>
parents: 324
diff changeset
    76
#if HAVE_NETINET_IN_H
7bc0c6ad11ff Fixes LM-118 so that building on Mac OS X works again.
Richard Hult <richard@imendio.com>
parents: 324
diff changeset
    77
#include <netinet/in.h>
7bc0c6ad11ff Fixes LM-118 so that building on Mac OS X works again.
Richard Hult <richard@imendio.com>
parents: 324
diff changeset
    78
#endif
7bc0c6ad11ff Fixes LM-118 so that building on Mac OS X works again.
Richard Hult <richard@imendio.com>
parents: 324
diff changeset
    79
271
52ea4e0b897a Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents: 256
diff changeset
    80
#include <arpa/nameser.h>
52ea4e0b897a Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents: 256
diff changeset
    81
#include <resolv.h>
9
2e14e3ab411b 2003-06-24 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 7
diff changeset
    82
422
1c00df7a8b11 Depend on GObject and initialize GType
Mikael Hallendal <micke@imendio.com>
parents: 421
diff changeset
    83
#include <glib-object.h>
140
103227122f45 2006-04-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 137
diff changeset
    84
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
    85
#include "lm-data-objects.h"
140
103227122f45 2006-04-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 137
diff changeset
    86
#include "lm-sock.h"
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    87
#include "lm-debug.h"
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    88
#include "lm-error.h"
508
0850b3400a8c Cleaned up the moved XMPP Ping code from LmConnection and hooked up the LmFeaturePing object.
Mikael Hallendal <micke@imendio.com>
parents: 504
diff changeset
    89
#include "lm-feature-ping.h"
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    90
#include "lm-internals.h"
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
    91
#include "lm-message-queue.h"
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
    92
#include "lm-misc.h"
137
18785575aa7a 2006-04-05 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 133
diff changeset
    93
#include "lm-ssl-internals.h"
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    94
#include "lm-parser.h"
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    95
#include "lm-sha.h"
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    96
#include "lm-connection.h"
155
d24c4392d4e3 2006-06-16 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 153
diff changeset
    97
#include "lm-utils.h"
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents: 422
diff changeset
    98
#include "lm-old-socket.h"
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
    99
#include "lm-sasl.h"
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
   100
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   101
typedef struct {
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   102
    LmHandlerPriority  priority;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   103
    LmMessageHandler  *handler;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   104
} HandlerData;
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   105
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   106
struct _LmConnection {
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   107
    /* Parameters */
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   108
    GMainContext      *context;
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   109
533
c45243823756 Added some TODO items and minor style fixes
Mikael Hallendal <micke@imendio.com>
parents: 532
diff changeset
   110
    /* TODO: Clean up this and make some parameter object for server, jid, effective jid etc */
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   111
    gchar             *server;
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   112
    gchar             *jid;
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   113
    gchar             *effective_jid;
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   114
    guint              port;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   115
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   116
    LmOldSocket       *socket;
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   117
    LmSSL             *ssl;
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   118
    LmProxy           *proxy;
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   119
    LmParser          *parser;
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   120
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   121
    gchar             *stream_id;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   122
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   123
    GHashTable        *id_handlers;
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   124
    GSList            *handlers[LM_MESSAGE_TYPE_UNKNOWN];
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   125
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   126
    /* XMPP1.0 stuff (SASL, resource binding, StartTLS) */
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   127
    gboolean           use_sasl;
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   128
    LmSASL            *sasl;
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   129
    gchar             *resource;
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   130
    LmMessageHandler  *features_cb;
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   131
    LmMessageHandler  *starttls_cb;
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   132
    gboolean           tls_started;
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
   133
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   134
    /* Communication */
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   135
    guint              open_id;
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   136
    LmCallback        *open_cb;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   137
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   138
    gboolean           cancel_open;
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   139
    LmCallback        *auth_cb;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   140
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   141
    LmCallback        *disconnect_cb;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   142
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   143
    LmMessageQueue    *queue;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   144
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   145
    LmConnectionState  state;
59
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
   146
533
c45243823756 Added some TODO items and minor style fixes
Mikael Hallendal <micke@imendio.com>
parents: 532
diff changeset
   147
    /* TODO: Move the rate to use the one in LmFeaturePing instead of keeping the two in sync */
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   148
    guint              keep_alive_rate;
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   149
    LmFeaturePing     *feature_ping;
184
4e16d32b2410 2006-10-16 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 181
diff changeset
   150
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   151
    gint               ref_count;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   152
};
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   153
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   154
typedef enum {
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   155
    AUTH_TYPE_PLAIN  = 1,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   156
    AUTH_TYPE_DIGEST = 2,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   157
    AUTH_TYPE_0K     = 4
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   158
} AuthType;
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   159
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
   160
#define XMPP_NS_BIND "urn:ietf:params:xml:ns:xmpp-bind"
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
   161
#define XMPP_NS_SESSION "urn:ietf:params:xml:ns:xmpp-session"
274
c32a7011e435 Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents: 271
diff changeset
   162
#define XMPP_NS_STARTTLS "urn:ietf:params:xml:ns:xmpp-tls"
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
   163
416
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   164
static void     connection_free              (LmConnection        *connection);
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   165
static void     connection_handle_message    (LmConnection        *connection,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   166
                                              LmMessage           *message);
416
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   167
static void     connection_new_message_cb    (LmParser            *parser,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   168
                                              LmMessage           *message,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   169
                                              LmConnection        *connection);
416
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   170
static gboolean connection_do_open           (LmConnection        *connection,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   171
                                              GError             **error);
416
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   172
void            connection_do_close          (LmConnection        *connection);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   173
static LmMessage *
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
   174
connection_create_auth_req_msg               (LmAuthParameters    *auth_params);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   175
416
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   176
static LmMessage *
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   177
connection_create_auth_msg                   (LmConnection        *connection,
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
   178
                                              LmAuthParameters    *auth_params,
416
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   179
                                              gint                 auth_type);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   180
static LmHandlerResult
416
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   181
connection_auth_req_reply                    (LmMessageHandler    *handler,
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   182
                                              LmConnection        *connection,
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   183
                                              LmMessage           *m,
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   184
                                              gpointer             user_data);
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   185
static int      connection_check_auth_type   (LmMessage           *auth_req_rpl);
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   186
static LmHandlerResult
416
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   187
connection_auth_reply                        (LmMessageHandler    *handler,
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   188
                                              LmConnection        *connection,
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   189
                                              LmMessage           *m,
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   190
                                              gpointer             user_data);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   191
static void     connection_stream_received   (LmConnection        *connection,
416
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   192
                                              LmMessage           *m);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   193
static void     connection_stream_error      (LmConnection        *connection,
416
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   194
                                              LmMessage           *m);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   195
static gint
416
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   196
connection_handler_compare_func              (HandlerData         *a,
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   197
                                              HandlerData         *b);
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   198
static void     connection_start_keep_alive  (LmConnection        *connection);
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   199
static void     connection_stop_keep_alive   (LmConnection        *connection);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   200
static gboolean connection_send              (LmConnection        *connection,
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   201
                                              const gchar         *str,
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   202
                                              gint                 len,
416
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   203
                                              GError             **error);
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   204
static void     connection_message_queue_cb  (LmMessageQueue      *queue,
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   205
                                              LmConnection        *connection);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   206
static void
416
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   207
connection_signal_disconnect                 (LmConnection        *connection,
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   208
                                              LmDisconnectReason   reason);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   209
static void     connection_incoming_data     (LmOldSocket         *socket,
416
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   210
                                              const gchar         *buf,
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   211
                                              LmConnection        *connection);
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents: 422
diff changeset
   212
static void     connection_socket_closed_cb  (LmOldSocket            *socket,
416
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   213
                                              LmDisconnectReason   reason,
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   214
                                              LmConnection        *connection);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   215
static void
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   216
connection_socket_connect_cb                 (LmOldSocket         *socket,
416
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   217
                                              gboolean             result,
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   218
                                              LmConnection        *connection);
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   219
static gboolean
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   220
connection_get_server_from_jid               (const gchar         *jid,
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   221
                                              gchar              **server);
416
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   222
static void
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   223
connection_send_stream_header                (LmConnection        *connection);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   224
static LmHandlerResult
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   225
connection_features_cb                       (LmMessageHandler    *handler,
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   226
                                              LmConnection        *connection,
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   227
                                              LmMessage           *message,
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   228
                                              gpointer             user_data);
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   229
static gboolean connection_old_auth          (LmConnection        *connection,
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
   230
                                              LmAuthParameters    *auth_params,
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   231
                                              GError             **errror);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   232
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   233
static void
405
f33dcdadf95c Factored out connection_free_handlers from connection_free
Mikael Hallendal <micke@imendio.com>
parents: 394
diff changeset
   234
connection_free_handlers (LmConnection *connection)
f33dcdadf95c Factored out connection_free_handlers from connection_free
Mikael Hallendal <micke@imendio.com>
parents: 394
diff changeset
   235
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   236
    int i;
405
f33dcdadf95c Factored out connection_free_handlers from connection_free
Mikael Hallendal <micke@imendio.com>
parents: 394
diff changeset
   237
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   238
    /* Unref handlers */
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   239
    for (i = 0; i < LM_MESSAGE_TYPE_UNKNOWN; ++i) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   240
        GSList *l;
405
f33dcdadf95c Factored out connection_free_handlers from connection_free
Mikael Hallendal <micke@imendio.com>
parents: 394
diff changeset
   241
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   242
        for (l = connection->handlers[i]; l; l = l->next) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   243
            HandlerData *hd = (HandlerData *) l->data;
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   244
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   245
            lm_message_handler_unref (hd->handler);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   246
            g_free (hd);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   247
        }
405
f33dcdadf95c Factored out connection_free_handlers from connection_free
Mikael Hallendal <micke@imendio.com>
parents: 394
diff changeset
   248
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   249
        g_slist_free (connection->handlers[i]);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   250
    }
405
f33dcdadf95c Factored out connection_free_handlers from connection_free
Mikael Hallendal <micke@imendio.com>
parents: 394
diff changeset
   251
}
f33dcdadf95c Factored out connection_free_handlers from connection_free
Mikael Hallendal <micke@imendio.com>
parents: 394
diff changeset
   252
f33dcdadf95c Factored out connection_free_handlers from connection_free
Mikael Hallendal <micke@imendio.com>
parents: 394
diff changeset
   253
static void
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   254
connection_free (LmConnection *connection)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   255
{
573
038320b7357e Don't free connection internals before it's closed. [#34]
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   256
    /* This needs to be run before starting to free internal states.
038320b7357e Don't free connection internals before it's closed. [#34]
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   257
     * It used to be run after the handlers where freed which lead to a crash
038320b7357e Don't free connection internals before it's closed. [#34]
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   258
     * when the connection was freed prior to running lm_connection_close.
038320b7357e Don't free connection internals before it's closed. [#34]
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   259
     */
038320b7357e Don't free connection internals before it's closed. [#34]
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   260
    if (connection->state >= LM_CONNECTION_STATE_OPENING) {
038320b7357e Don't free connection internals before it's closed. [#34]
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   261
        connection_do_close (connection);
038320b7357e Don't free connection internals before it's closed. [#34]
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   262
    }
038320b7357e Don't free connection internals before it's closed. [#34]
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   263
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   264
    g_free (connection->server);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   265
    g_free (connection->jid);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   266
    g_free (connection->effective_jid);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   267
    g_free (connection->stream_id);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   268
    g_free (connection->resource);
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
   269
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   270
    if (connection->sasl) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   271
        lm_sasl_free (connection->sasl);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   272
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   273
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   274
    if (connection->parser) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   275
        lm_parser_free (connection->parser);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   276
    }
153
b2324df84971 2006-06-06 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 143
diff changeset
   277
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   278
    connection_free_handlers (connection);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   279
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   280
    g_hash_table_destroy (connection->id_handlers);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   281
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   282
    if (connection->open_cb) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   283
        _lm_utils_free_callback (connection->open_cb);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   284
    }
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   285
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   286
    if (connection->auth_cb) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   287
        _lm_utils_free_callback (connection->auth_cb);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   288
    }
143
92193c23b0c7 2006-05-26 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 140
diff changeset
   289
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   290
    lm_connection_set_disconnect_function (connection, NULL, NULL, NULL);
143
92193c23b0c7 2006-05-26 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 140
diff changeset
   291
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   292
    if (connection->proxy) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   293
        lm_proxy_unref (connection->proxy);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   294
    }
211
efbf2da5e443 Added checks when freeing proxy and closing socket. Also free open_cb in cancel_open.
Mikael Hallendal <micke@imendio.com>
parents: 210
diff changeset
   295
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   296
    lm_message_queue_unref (connection->queue);
115
f2a921e232e5 2005-04-24 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 114
diff changeset
   297
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   298
    if (connection->context) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   299
        g_main_context_unref (connection->context);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   300
    }
133
f7522d7ed6dc 2006-04-03 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 132
diff changeset
   301
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   302
    if (connection->socket) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   303
        lm_old_socket_unref (connection->socket);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   304
    }
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   305
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   306
    g_slice_free (LmConnection, connection);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   307
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   308
408
b07ef2183e6b Factored out connection_run_message_handler from connection_handle_message.
Mikael Hallendal <micke@imendio.com>
parents: 406
diff changeset
   309
static LmHandlerResult
b07ef2183e6b Factored out connection_run_message_handler from connection_handle_message.
Mikael Hallendal <micke@imendio.com>
parents: 406
diff changeset
   310
connection_run_message_handler (LmConnection *connection, LmMessage *m)
b07ef2183e6b Factored out connection_run_message_handler from connection_handle_message.
Mikael Hallendal <micke@imendio.com>
parents: 406
diff changeset
   311
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   312
    LmMessageHandler *handler;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   313
    const gchar      *id;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   314
    LmHandlerResult   result = LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS;
408
b07ef2183e6b Factored out connection_run_message_handler from connection_handle_message.
Mikael Hallendal <micke@imendio.com>
parents: 406
diff changeset
   315
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   316
    id = lm_message_node_get_attribute (m->node, "id");
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   317
    if (!id) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   318
        return LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   319
    }
408
b07ef2183e6b Factored out connection_run_message_handler from connection_handle_message.
Mikael Hallendal <micke@imendio.com>
parents: 406
diff changeset
   320
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   321
    handler = g_hash_table_lookup (connection->id_handlers, id);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   322
    if (handler) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   323
        result = _lm_message_handler_handle_message (handler,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   324
                                                     connection,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   325
                                                     m);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   326
        g_hash_table_remove (connection->id_handlers,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   327
                             id);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   328
    }
408
b07ef2183e6b Factored out connection_run_message_handler from connection_handle_message.
Mikael Hallendal <micke@imendio.com>
parents: 406
diff changeset
   329
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   330
    return result;
408
b07ef2183e6b Factored out connection_run_message_handler from connection_handle_message.
Mikael Hallendal <micke@imendio.com>
parents: 406
diff changeset
   331
}
b07ef2183e6b Factored out connection_run_message_handler from connection_handle_message.
Mikael Hallendal <micke@imendio.com>
parents: 406
diff changeset
   332
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   333
static void
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   334
connection_handle_message (LmConnection *connection, LmMessage *m)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   335
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   336
    GSList          *l;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   337
    LmHandlerResult  result = LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   338
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   339
    lm_connection_ref (connection);
143
92193c23b0c7 2006-05-26 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 140
diff changeset
   340
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   341
    if (lm_message_get_type (m) == LM_MESSAGE_TYPE_STREAM) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   342
        connection_stream_received (connection, m);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   343
        goto out;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   344
    }
306
d466fc30829f Added disconnect error for resource conflict. Fixes LM-55.
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 297
diff changeset
   345
613
174c17adc1e7 Refine "Allow replies to non-iq stanzas"
Frank Zschockelt <lm@freakysoft.de>
parents: 609
diff changeset
   346
    if ((lm_message_get_type (m) != LM_MESSAGE_TYPE_IQ) ||
174c17adc1e7 Refine "Allow replies to non-iq stanzas"
Frank Zschockelt <lm@freakysoft.de>
parents: 609
diff changeset
   347
        (lm_message_get_sub_type (m) == LM_MESSAGE_SUB_TYPE_ERROR) ||
174c17adc1e7 Refine "Allow replies to non-iq stanzas"
Frank Zschockelt <lm@freakysoft.de>
parents: 609
diff changeset
   348
        (lm_message_get_sub_type (m) == LM_MESSAGE_SUB_TYPE_RESULT)) {
174c17adc1e7 Refine "Allow replies to non-iq stanzas"
Frank Zschockelt <lm@freakysoft.de>
parents: 609
diff changeset
   349
        result = connection_run_message_handler (connection, m);
174c17adc1e7 Refine "Allow replies to non-iq stanzas"
Frank Zschockelt <lm@freakysoft.de>
parents: 609
diff changeset
   350
        if (result == LM_HANDLER_RESULT_REMOVE_MESSAGE) {
174c17adc1e7 Refine "Allow replies to non-iq stanzas"
Frank Zschockelt <lm@freakysoft.de>
parents: 609
diff changeset
   351
            goto out;
174c17adc1e7 Refine "Allow replies to non-iq stanzas"
Frank Zschockelt <lm@freakysoft.de>
parents: 609
diff changeset
   352
        }
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   353
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   354
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   355
    for (l = connection->handlers[lm_message_get_type (m)];
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   356
         l && result == LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS;
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   357
         l = l->next) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   358
        HandlerData *hd = (HandlerData *) l->data;
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   359
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   360
        result = _lm_message_handler_handle_message (hd->handler,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   361
                                                     connection,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   362
                                                     m);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   363
    }
143
92193c23b0c7 2006-05-26 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 140
diff changeset
   364
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   365
    if (lm_message_get_type (m) == LM_MESSAGE_TYPE_STREAM_ERROR) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   366
        connection_stream_error (connection, m);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   367
        goto out;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   368
    }
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   369
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   370
 out:
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   371
    lm_connection_unref (connection);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   372
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   373
    return;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   374
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   375
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   376
static void
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   377
connection_new_message_cb (LmParser     *parser,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   378
                           LmMessage    *m,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   379
                           LmConnection *connection)
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   380
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   381
    const gchar *from;
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   382
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   383
    lm_message_ref (m);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   384
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   385
    from = lm_message_node_get_attribute (m->node, "from");
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   386
    if (!from) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   387
        from = "unknown";
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   388
    }
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   389
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   390
    lm_verbose ("New message with type=\"%s\" from: %s\n",
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   391
                _lm_message_type_to_string (lm_message_get_type (m)),
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   392
                from);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   393
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   394
    lm_message_queue_push_tail (connection->queue, m);
82
a32b54e654e2 2004-03-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 80
diff changeset
   395
}
a32b54e654e2 2004-03-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 80
diff changeset
   396
508
0850b3400a8c Cleaned up the moved XMPP Ping code from LmConnection and hooked up the LmFeaturePing object.
Mikael Hallendal <micke@imendio.com>
parents: 504
diff changeset
   397
static void
529
6bb284696153 More style fixes
Mikael Hallendal <micke@imendio.com>
parents: 528
diff changeset
   398
connection_ping_timed_out (LmFeaturePing *fp, LmConnection *connection)
504
1fafee646928 Use XMPP Ping (XEP-0199) instead of white space ping for keep alive. [#15]
Frank Zschockelt <lm@freakysoft.de>
parents: 503
diff changeset
   399
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   400
    connection_do_close (connection);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   401
    connection_signal_disconnect (connection,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   402
                                  LM_DISCONNECT_REASON_PING_TIME_OUT);
90
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
   403
}
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
   404
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
   405
static void
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
   406
connection_start_keep_alive (LmConnection *connection)
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
   407
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   408
    if (connection->feature_ping) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   409
        connection_stop_keep_alive (connection);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   410
    }
292
bb7269466be2 Use TCP keepalives on Linux if available; if not, fallback to manual keepalives.
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 291
diff changeset
   411
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   412
    connection->feature_ping = g_object_new (LM_TYPE_FEATURE_PING,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   413
                                             "connection", connection,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   414
                                             "rate", connection->keep_alive_rate,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   415
                                             NULL);
90
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
   416
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   417
    g_signal_connect (connection->feature_ping, "timed-out",
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   418
                      G_CALLBACK (connection_ping_timed_out),
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   419
                      connection);
508
0850b3400a8c Cleaned up the moved XMPP Ping code from LmConnection and hooked up the LmFeaturePing object.
Mikael Hallendal <micke@imendio.com>
parents: 504
diff changeset
   420
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   421
    lm_feature_ping_start (connection->feature_ping);
90
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
   422
}
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
   423
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
   424
static void
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
   425
connection_stop_keep_alive (LmConnection *connection)
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
   426
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   427
    if (connection->feature_ping) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   428
        lm_feature_ping_stop (connection->feature_ping);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   429
        g_signal_handlers_disconnect_by_func (connection->feature_ping,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   430
                                              G_CALLBACK (connection_ping_timed_out),
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   431
                                              connection);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   432
        g_object_unref (connection->feature_ping);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   433
    }
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   434
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   435
    connection->feature_ping = NULL;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   436
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   437
406
3c6b13d37d41 Factored out connection_log_send from connection_send
Mikael Hallendal <micke@imendio.com>
parents: 405
diff changeset
   438
static void
3c6b13d37d41 Factored out connection_log_send from connection_send
Mikael Hallendal <micke@imendio.com>
parents: 405
diff changeset
   439
connection_log_send (LmConnection *connection,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   440
                     const gchar  *str,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   441
                     gint          len)
406
3c6b13d37d41 Factored out connection_log_send from connection_send
Mikael Hallendal <micke@imendio.com>
parents: 405
diff changeset
   442
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   443
    g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_NET, "\nSEND:\n");
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   444
    g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_NET,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   445
           "-----------------------------------\n");
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   446
    g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_NET, "%s\n", str);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   447
    g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_NET,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   448
           "-----------------------------------\n");
406
3c6b13d37d41 Factored out connection_log_send from connection_send
Mikael Hallendal <micke@imendio.com>
parents: 405
diff changeset
   449
}
3c6b13d37d41 Factored out connection_log_send from connection_send
Mikael Hallendal <micke@imendio.com>
parents: 405
diff changeset
   450
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   451
static gboolean
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   452
connection_send (LmConnection  *connection,
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   453
                 const gchar   *str,
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   454
                 gint           len,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   455
                 GError       **error)
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   456
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   457
    gint b_written;
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   458
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   459
    if (connection->state < LM_CONNECTION_STATE_OPENING) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   460
        g_log (LM_LOG_DOMAIN,LM_LOG_LEVEL_NET,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   461
               "Connection is not open.\n");
140
103227122f45 2006-04-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 137
diff changeset
   462
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   463
        g_set_error (error,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   464
                     LM_ERROR,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   465
                     LM_ERROR_CONNECTION_NOT_OPEN,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   466
                     "Connection is not open, call lm_connection_open() first");
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   467
        return FALSE;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   468
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   469
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   470
    if (len == -1) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   471
        len = strlen (str);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   472
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   473
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   474
    connection_log_send (connection, str, len);
68
28203e15de0e 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 67
diff changeset
   475
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   476
    /* Check to see if there already is an output buffer, if so, add to the
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   477
       buffer and return */
133
f7522d7ed6dc 2006-04-03 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 132
diff changeset
   478
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   479
    b_written = lm_old_socket_write (connection->socket, str, len);
133
f7522d7ed6dc 2006-04-03 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 132
diff changeset
   480
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   481
    if (b_written < 0) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   482
        g_set_error (error,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   483
                     LM_ERROR,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   484
                     LM_ERROR_CONNECTION_FAILED,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   485
                     "Server closed the connection");
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   486
        return FALSE;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   487
    }
133
f7522d7ed6dc 2006-04-03 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 132
diff changeset
   488
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   489
    return TRUE;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   490
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   491
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   492
static void
249
2cca5ec7b573 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 248
diff changeset
   493
connection_message_queue_cb (LmMessageQueue *queue, LmConnection *connection)
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   494
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   495
    LmMessage *m;
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   496
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   497
    m = lm_message_queue_pop_nth (connection->queue, 0);
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   498
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   499
    if (m) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   500
        connection_handle_message (connection, m);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   501
        lm_message_unref (m);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   502
    }
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   503
}
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   504
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   505
/* Returns directly */
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   506
/* Setups all data needed to start the connection attempts */
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   507
static gboolean
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   508
connection_do_open (LmConnection *connection, GError **error)
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   509
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   510
    gchar *domain = NULL;
245
df2655dbe873 Make LmConnection accept not having a server set as long as JID is set.
Mikael Hallendal <micke@imendio.com>
parents: 244
diff changeset
   511
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   512
    if (lm_connection_is_open (connection)) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   513
        g_set_error (error,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   514
                     LM_ERROR,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   515
                     LM_ERROR_CONNECTION_NOT_OPEN,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   516
                     "Connection is already open, call lm_connection_close() first");
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   517
        return FALSE;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   518
    }
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   519
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   520
    domain = _lm_connection_get_server (connection);
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   521
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   522
    lm_verbose ("Connecting to: %s:%d\n", connection->server, connection->port);
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   523
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   524
    connection->socket = lm_old_socket_create (connection->context,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   525
                                               (IncomingDataFunc) connection_incoming_data,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   526
                                               (SocketClosedFunc) connection_socket_closed_cb,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   527
                                               (ConnectResultFunc) connection_socket_connect_cb,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   528
                                               connection,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   529
                                               connection,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   530
                                               connection->server,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   531
                                               domain,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   532
                                               connection->port,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   533
                                               connection->ssl,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   534
                                               connection->proxy,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   535
                                               error);
245
df2655dbe873 Make LmConnection accept not having a server set as long as JID is set.
Mikael Hallendal <micke@imendio.com>
parents: 244
diff changeset
   536
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   537
    g_free (domain);
281
4e0421c44a73 Fixed a leak in extracting the domain name from the jid.
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 275
diff changeset
   538
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   539
    if (!connection->socket) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   540
        return FALSE;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   541
    }
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   542
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   543
    lm_message_queue_attach (connection->queue, connection->context);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   544
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   545
    connection->state = LM_CONNECTION_STATE_OPENING;
344
11473296fea5 Return FALSE from lm_connection_open in the synchronous case instead of open callback
Owen Taylor <otaylor@redhat.com>
parents: 341
diff changeset
   546
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   547
    return TRUE;
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   548
}
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   549
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   550
void
256
2266e56746ed Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 255
diff changeset
   551
connection_do_close (LmConnection *connection)
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   552
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   553
    connection_stop_keep_alive (connection);
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   554
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   555
    if (connection->socket) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   556
        lm_old_socket_close (connection->socket);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   557
    }
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   558
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   559
    lm_message_queue_detach (connection->queue);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   560
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   561
    if (!lm_connection_is_open (connection)) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   562
        /* lm_connection_is_open is FALSE for state OPENING as well */
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   563
        connection->state = LM_CONNECTION_STATE_CLOSED;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   564
        return;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   565
    }
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   566
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   567
    connection->state = LM_CONNECTION_STATE_CLOSED;
324
4b06b1173262 Properly clean up SASL context on disconnect, allowing connection object reuse.
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 323
diff changeset
   568
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   569
    if (connection->sasl) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   570
        lm_sasl_free (connection->sasl);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   571
        connection->sasl = NULL;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   572
    }
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   573
}
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   574
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   575
static LmMessage *
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
   576
connection_create_auth_req_msg (LmAuthParameters *auth_params)
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   577
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   578
    LmMessage     *m;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   579
    LmMessageNode *q_node;
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   580
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   581
    m = lm_message_new_with_sub_type (NULL, LM_MESSAGE_TYPE_IQ,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   582
                                      LM_MESSAGE_SUB_TYPE_GET);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   583
    q_node = lm_message_node_add_child (m->node, "query", NULL);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   584
    lm_message_node_set_attributes (q_node,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   585
                                    "xmlns", "jabber:iq:auth",
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   586
                                    NULL);
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
   587
    lm_message_node_add_child (q_node, "username", lm_auth_parameters_get_username (auth_params));
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   588
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   589
    return m;
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   590
}
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   591
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   592
static LmMessage *
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
   593
connection_create_auth_msg (LmConnection     *connection,
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
   594
                            LmAuthParameters *auth_params,
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
   595
                            gint              auth_type)
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   596
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   597
    LmMessage     *auth_msg;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   598
    LmMessageNode *q_node;
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   599
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   600
    auth_msg = lm_message_new_with_sub_type (NULL, LM_MESSAGE_TYPE_IQ,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   601
                                             LM_MESSAGE_SUB_TYPE_SET);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   602
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   603
    q_node = lm_message_node_add_child (auth_msg->node, "query", NULL);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   604
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   605
    lm_message_node_set_attributes (q_node,
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   606
                                    "xmlns", "jabber:iq:auth",
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   607
                                    NULL);
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   608
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
   609
    lm_message_node_add_child (q_node, "username", lm_auth_parameters_get_username (auth_params));
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   610
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   611
    if (auth_type & AUTH_TYPE_0K) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   612
        lm_verbose ("Using 0k auth (not implemented yet)\n");
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   613
        /* TODO: Should probably use this? */
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   614
    }
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   615
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   616
    if (auth_type & AUTH_TYPE_DIGEST) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   617
        gchar *str;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   618
        gchar *digest;
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   619
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   620
        lm_verbose ("Using digest\n");
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
   621
        str = g_strconcat (connection->stream_id, lm_auth_parameters_get_password (auth_params), NULL);
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   622
        digest = lm_sha_hash (str);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   623
        g_free (str);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   624
        lm_message_node_add_child (q_node, "digest", digest);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   625
        g_free (digest);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   626
    }
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   627
    else if (auth_type & AUTH_TYPE_PLAIN) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   628
        lm_verbose ("Using plaintext auth\n");
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
   629
        lm_message_node_add_child (q_node, "password", lm_auth_parameters_get_password (auth_params));
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   630
    } else {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   631
        /* TODO: Report error somehow */
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   632
    }
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   633
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
   634
    lm_message_node_add_child (q_node, "resource", lm_auth_parameters_get_resource (auth_params));
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   635
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   636
    return auth_msg;
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   637
}
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   638
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   639
static LmHandlerResult
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   640
connection_auth_req_reply (LmMessageHandler *handler,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   641
                           LmConnection     *connection,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   642
                           LmMessage        *m,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   643
                           gpointer          user_data)
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   644
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   645
    int               auth_type;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   646
    LmMessage        *auth_msg;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   647
    LmMessageHandler *auth_handler;
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
   648
    LmAuthParameters *auth_params = (LmAuthParameters *) user_data;
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   649
    gboolean          result;
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   650
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   651
    auth_type = connection_check_auth_type (m);
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   652
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
   653
    auth_msg = connection_create_auth_msg (connection, auth_params, auth_type);
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   654
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   655
    auth_handler = lm_message_handler_new (connection_auth_reply,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   656
                                           NULL, NULL);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   657
    result = lm_connection_send_with_reply (connection, auth_msg,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   658
                                            auth_handler, NULL);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   659
    lm_message_handler_unref (auth_handler);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   660
    lm_message_unref (auth_msg);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   661
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   662
    return LM_HANDLER_RESULT_REMOVE_MESSAGE;
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   663
}
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   664
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   665
static int
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   666
connection_check_auth_type (LmMessage *auth_req_rpl)
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   667
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   668
    LmMessageNode *q_node;
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   669
    gint           ret_val = 0;
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   670
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   671
    q_node = lm_message_node_get_child (auth_req_rpl->node, "query");
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   672
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   673
    if (!q_node) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   674
        return AUTH_TYPE_PLAIN;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   675
    }
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   676
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   677
    if (lm_message_node_get_child (q_node, "password")) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   678
        ret_val |= AUTH_TYPE_PLAIN;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   679
    }
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   680
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   681
    if (lm_message_node_get_child (q_node, "digest")) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   682
        ret_val |= AUTH_TYPE_DIGEST;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   683
    }
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   684
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   685
    if (lm_message_node_get_child (q_node, "sequence") &&
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   686
        lm_message_node_get_child (q_node, "token")) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   687
        ret_val |= AUTH_TYPE_0K;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   688
    }
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   689
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   690
    return ret_val;
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   691
}
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   692
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   693
static LmHandlerResult
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   694
connection_auth_reply (LmMessageHandler *handler,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   695
                       LmConnection     *connection,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   696
                       LmMessage        *m,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   697
                       gpointer          user_data)
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   698
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   699
    const gchar *type;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   700
    gboolean     result = TRUE;
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   701
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   702
    g_return_val_if_fail (connection != NULL,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   703
                          LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   704
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   705
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   706
    type = lm_message_node_get_attribute (m->node, "type");
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   707
    if (strcmp (type, "result") == 0) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   708
        result = TRUE;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   709
        connection->state = LM_CONNECTION_STATE_AUTHENTICATED;
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   710
    }
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   711
    else if (strcmp (type, "error") == 0) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   712
        result = FALSE;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   713
        connection->state = LM_CONNECTION_STATE_OPEN;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   714
    }
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   715
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   716
    lm_verbose ("AUTH reply: %d\n", result);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   717
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   718
    if (connection->auth_cb) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   719
        LmCallback *cb = connection->auth_cb;
143
92193c23b0c7 2006-05-26 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 140
diff changeset
   720
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   721
        connection->auth_cb = NULL;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   722
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   723
        if (cb->func) {
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   724
            (* ((LmResultFunction) cb->func)) (connection,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   725
                                               result,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   726
                                               cb->user_data);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   727
        }
143
92193c23b0c7 2006-05-26 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 140
diff changeset
   728
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   729
        _lm_utils_free_callback (cb);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   730
    }
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   731
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   732
    return LM_HANDLER_RESULT_REMOVE_MESSAGE;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   733
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   734
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   735
320
02b814ccc535 Register starttls handler at the proper moment, when the stream is received.
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 317
diff changeset
   736
static LmHandlerResult
02b814ccc535 Register starttls handler at the proper moment, when the stream is received.
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 317
diff changeset
   737
_lm_connection_starttls_cb (LmMessageHandler *handler,
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   738
                            LmConnection     *connection,
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   739
                            LmMessage        *message,
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   740
                            gpointer          user_data)
320
02b814ccc535 Register starttls handler at the proper moment, when the stream is received.
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 317
diff changeset
   741
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   742
    if (lm_old_socket_starttls (connection->socket)) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   743
        connection->tls_started = TRUE;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   744
        connection_send_stream_header (connection);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   745
    } else {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   746
        connection_do_close (connection);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   747
        connection_signal_disconnect (connection,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   748
                                      LM_DISCONNECT_REASON_ERROR);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   749
    }
320
02b814ccc535 Register starttls handler at the proper moment, when the stream is received.
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 317
diff changeset
   750
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   751
    return LM_HANDLER_RESULT_REMOVE_MESSAGE;
320
02b814ccc535 Register starttls handler at the proper moment, when the stream is received.
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 317
diff changeset
   752
}
02b814ccc535 Register starttls handler at the proper moment, when the stream is received.
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 317
diff changeset
   753
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   754
static void
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   755
connection_possibly_register_starttls_handler (LmConnection *connection)
450
548b5e3d9bea Refactored some of the SSL code in LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 449
diff changeset
   756
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   757
    /* if we'd like to use tls and we didn't already start
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   758
     * it, prepare for it now */
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   759
    if (connection->ssl &&
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   760
        lm_old_socket_get_use_starttls (connection->socket) &&
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   761
        !connection->starttls_cb) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   762
        connection->starttls_cb  =
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   763
            lm_message_handler_new (_lm_connection_starttls_cb,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   764
                                    NULL, NULL);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   765
        lm_connection_register_message_handler (connection,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   766
                                                connection->starttls_cb,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   767
                                                LM_MESSAGE_TYPE_PROCEED,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   768
                                                LM_HANDLER_PRIORITY_FIRST);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   769
    }
450
548b5e3d9bea Refactored some of the SSL code in LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 449
diff changeset
   770
}
548b5e3d9bea Refactored some of the SSL code in LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 449
diff changeset
   771
548b5e3d9bea Refactored some of the SSL code in LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 449
diff changeset
   772
static void
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   773
connection_stream_received (LmConnection *connection, LmMessage *m)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   774
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   775
    gboolean result;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   776
    const char *xmpp_version;
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   777
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   778
    g_return_if_fail (connection != NULL);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   779
    g_return_if_fail (m != NULL);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   780
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   781
    connection->stream_id = g_strdup (lm_message_node_get_attribute (m->node,
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   782
                                                                     "id"));
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
   783
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   784
    xmpp_version = lm_message_node_get_attribute (m->node, "version");
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   785
    if (xmpp_version && strcmp (xmpp_version, "1.0") == 0) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   786
        lm_verbose ("XMPP 1.0 stream received: %s\n",
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   787
                    connection->stream_id);
220
f6b9482ae89e Some style fixes to the SASL patch.
Mikael Hallendal <micke@imendio.com>
parents: 219
diff changeset
   788
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   789
        connection->use_sasl = TRUE;
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   790
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   791
        /* stream is started multiple times, but we only want
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   792
         * one sasl mechanism */
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   793
        if (!connection->sasl) {
541
9c315096fa5a Minor style fixes
Mikael Hallendal <micke@imendio.com>
parents: 540
diff changeset
   794
            connection->sasl = lm_sasl_new (connection);
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   795
        }
320
02b814ccc535 Register starttls handler at the proper moment, when the stream is received.
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 317
diff changeset
   796
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   797
        connection_possibly_register_starttls_handler (connection);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   798
    } else {
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   799
        lm_verbose ("Old Jabber stream received: %s\n",
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   800
                    connection->stream_id);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   801
    }
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   802
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   803
    if (connection->state < LM_CONNECTION_STATE_OPEN) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   804
        connection->state = LM_CONNECTION_STATE_OPEN;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   805
    }
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   806
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   807
    /* Check to see if the stream is correctly set up */
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   808
    result = TRUE;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   809
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   810
    connection_start_keep_alive (connection);
90
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
   811
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   812
    if (connection->open_cb) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   813
        LmCallback *cb = connection->open_cb;
143
92193c23b0c7 2006-05-26 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 140
diff changeset
   814
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   815
        connection->open_cb = NULL;
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   816
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   817
        if (cb->func) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   818
            (* ((LmResultFunction) cb->func)) (connection, result,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   819
                                               cb->user_data);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   820
        }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   821
        _lm_utils_free_callback (cb);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   822
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   823
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   824
306
d466fc30829f Added disconnect error for resource conflict. Fixes LM-55.
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 297
diff changeset
   825
static void
d466fc30829f Added disconnect error for resource conflict. Fixes LM-55.
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 297
diff changeset
   826
connection_stream_error (LmConnection *connection, LmMessage *m)
d466fc30829f Added disconnect error for resource conflict. Fixes LM-55.
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 297
diff changeset
   827
{
534
19327ccf6099 Minor style fix
Mikael Hallendal <micke@imendio.com>
parents: 533
diff changeset
   828
    LmMessageNode      *node;
19327ccf6099 Minor style fix
Mikael Hallendal <micke@imendio.com>
parents: 533
diff changeset
   829
    LmMessageNode      *reason_node;
19327ccf6099 Minor style fix
Mikael Hallendal <micke@imendio.com>
parents: 533
diff changeset
   830
    LmDisconnectReason  reason;
306
d466fc30829f Added disconnect error for resource conflict. Fixes LM-55.
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 297
diff changeset
   831
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   832
    g_return_if_fail (connection != NULL);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   833
    g_return_if_fail (m != NULL);
306
d466fc30829f Added disconnect error for resource conflict. Fixes LM-55.
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 297
diff changeset
   834
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   835
    node = m->node;
306
d466fc30829f Added disconnect error for resource conflict. Fixes LM-55.
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 297
diff changeset
   836
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   837
    /* Resource conflict */
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   838
    reason_node = lm_message_node_get_child (node, "conflict");
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   839
    if (reason_node) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   840
        lm_verbose ("Stream error: Conflict (resource connected elsewhere)\n");
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   841
        reason = LM_DISCONNECT_REASON_RESOURCE_CONFLICT;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   842
        return;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   843
    }
306
d466fc30829f Added disconnect error for resource conflict. Fixes LM-55.
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 297
diff changeset
   844
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   845
    /* XML is crack */
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   846
    reason_node = lm_message_node_get_child (node, "xml-not-well-formed");
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   847
    if (reason_node) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   848
        lm_verbose ("Stream error: XML not well formed\n");
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   849
        reason = LM_DISCONNECT_REASON_INVALID_XML;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   850
        return;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   851
    }
306
d466fc30829f Added disconnect error for resource conflict. Fixes LM-55.
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 297
diff changeset
   852
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   853
    lm_verbose ("Stream error: Unrecognised error\n");
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   854
    reason = LM_DISCONNECT_REASON_ERROR;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   855
    connection->stream_id = g_strdup (lm_message_node_get_attribute (m->node,
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   856
                                                                     "id"));
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   857
    connection_do_close (connection);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   858
    connection_signal_disconnect (connection, reason);
306
d466fc30829f Added disconnect error for resource conflict. Fixes LM-55.
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 297
diff changeset
   859
}
d466fc30829f Added disconnect error for resource conflict. Fixes LM-55.
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 297
diff changeset
   860
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   861
static gint
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   862
connection_handler_compare_func (HandlerData *a, HandlerData *b)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   863
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   864
    return b->priority - a->priority;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   865
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   866
256
2266e56746ed Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 255
diff changeset
   867
static void
2266e56746ed Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 255
diff changeset
   868
connection_signal_disconnect (LmConnection       *connection,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   869
                              LmDisconnectReason  reason)
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   870
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   871
    if (connection->disconnect_cb && connection->disconnect_cb->func) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   872
        LmCallback *cb = connection->disconnect_cb;
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   873
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   874
        lm_connection_ref (connection);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   875
        (* ((LmDisconnectFunction) cb->func)) (connection,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   876
                                               reason,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   877
                                               cb->user_data);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   878
        lm_connection_unref (connection);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   879
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   880
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   881
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   882
static void
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   883
connection_incoming_data (LmOldSocket  *socket,
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   884
                          const gchar  *buf,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   885
                          LmConnection *connection)
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   886
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   887
    lm_parser_parse (connection->parser, buf);
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   888
}
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   889
256
2266e56746ed Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 255
diff changeset
   890
static void
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents: 422
diff changeset
   891
connection_socket_closed_cb (LmOldSocket        *socket,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   892
                             LmDisconnectReason reason,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   893
                             LmConnection       *connection)
256
2266e56746ed Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 255
diff changeset
   894
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   895
    connection_do_close (connection);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   896
    connection_signal_disconnect (connection, reason);
256
2266e56746ed Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 255
diff changeset
   897
}
2266e56746ed Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 255
diff changeset
   898
2266e56746ed Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 255
diff changeset
   899
static void
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   900
connection_socket_connect_cb (LmOldSocket  *socket,
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   901
                              gboolean      result,
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   902
                              LmConnection *connection)
256
2266e56746ed Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 255
diff changeset
   903
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   904
    if (result == FALSE) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   905
        connection_do_close (connection);
256
2266e56746ed Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 255
diff changeset
   906
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   907
        if (connection->open_cb) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   908
            LmCallback *cb = connection->open_cb;
256
2266e56746ed Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 255
diff changeset
   909
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   910
            connection->open_cb = NULL;
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   911
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   912
            (* ((LmResultFunction) cb->func)) (connection, FALSE,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   913
                                               cb->user_data);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   914
            _lm_utils_free_callback (cb);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   915
        }
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   916
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   917
        return;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   918
    }
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   919
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   920
    /* FIXME: Set up according to XMPP 1.0 specification */
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   921
    /*        StartTLS and the like */
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   922
    if (!connection_send (connection,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   923
                          "<?xml version='1.0' encoding='UTF-8'?>", -1,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   924
                          NULL)) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   925
        lm_verbose ("Failed to send xml version and encoding\n");
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   926
        connection_do_close (connection);
256
2266e56746ed Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 255
diff changeset
   927
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   928
        return;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   929
    }
256
2266e56746ed Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 255
diff changeset
   930
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   931
    connection_send_stream_header (connection);
256
2266e56746ed Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 255
diff changeset
   932
}
2266e56746ed Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 255
diff changeset
   933
245
df2655dbe873 Make LmConnection accept not having a server set as long as JID is set.
Mikael Hallendal <micke@imendio.com>
parents: 244
diff changeset
   934
static gboolean
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   935
connection_get_server_from_jid (const gchar *jid, gchar **server)
245
df2655dbe873 Make LmConnection accept not having a server set as long as JID is set.
Mikael Hallendal <micke@imendio.com>
parents: 244
diff changeset
   936
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   937
    gchar *ch;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   938
    gchar *ch_end;
245
df2655dbe873 Make LmConnection accept not having a server set as long as JID is set.
Mikael Hallendal <micke@imendio.com>
parents: 244
diff changeset
   939
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   940
    if (jid != NULL && (ch = strchr (jid, '@')) != NULL) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   941
        ch_end = strchr(ch + 1, '/');
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   942
        if (ch_end != NULL) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   943
            *server = g_strndup (ch + 1, ch_end - ch - 1);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   944
        } else {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   945
            *server = g_strdup (ch + 1);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   946
        }
245
df2655dbe873 Make LmConnection accept not having a server set as long as JID is set.
Mikael Hallendal <micke@imendio.com>
parents: 244
diff changeset
   947
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   948
        return TRUE;
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   949
    }
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   950
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   951
    return FALSE;
245
df2655dbe873 Make LmConnection accept not having a server set as long as JID is set.
Mikael Hallendal <micke@imendio.com>
parents: 244
diff changeset
   952
}
df2655dbe873 Make LmConnection accept not having a server set as long as JID is set.
Mikael Hallendal <micke@imendio.com>
parents: 244
diff changeset
   953
248
09a3e0e55ab8 Refactored sending of the stream header.
Mikael Hallendal <micke@imendio.com>
parents: 247
diff changeset
   954
static void
09a3e0e55ab8 Refactored sending of the stream header.
Mikael Hallendal <micke@imendio.com>
parents: 247
diff changeset
   955
connection_send_stream_header (LmConnection *connection)
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   956
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   957
    LmMessage *m;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   958
    gchar     *server_from_jid;
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   959
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   960
    lm_verbose ("Sending stream header\n");
248
09a3e0e55ab8 Refactored sending of the stream header.
Mikael Hallendal <micke@imendio.com>
parents: 247
diff changeset
   961
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   962
    server_from_jid = _lm_connection_get_server (connection);
248
09a3e0e55ab8 Refactored sending of the stream header.
Mikael Hallendal <micke@imendio.com>
parents: 247
diff changeset
   963
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   964
    m = lm_message_new (server_from_jid, LM_MESSAGE_TYPE_STREAM);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   965
    lm_message_node_set_attributes (m->node,
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   966
                                    "xmlns:stream",
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   967
                                    "http://etherx.jabber.org/streams",
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   968
                                    "xmlns", "jabber:client",
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   969
                                    "version", "1.0",
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   970
                                    NULL);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   971
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   972
    g_free (server_from_jid);
248
09a3e0e55ab8 Refactored sending of the stream header.
Mikael Hallendal <micke@imendio.com>
parents: 247
diff changeset
   973
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   974
    if (!lm_connection_send (connection, m, NULL)) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   975
        lm_verbose ("Failed to send stream information\n");
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   976
        connection_do_close (connection);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   977
    }
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   978
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   979
    lm_message_unref (m);
248
09a3e0e55ab8 Refactored sending of the stream header.
Mikael Hallendal <micke@imendio.com>
parents: 247
diff changeset
   980
}
09a3e0e55ab8 Refactored sending of the stream header.
Mikael Hallendal <micke@imendio.com>
parents: 247
diff changeset
   981
500
915cd386918e Added _lm_connection_get_context as internal function.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   982
GMainContext *
915cd386918e Added _lm_connection_get_context as internal function.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   983
_lm_connection_get_context (LmConnection *conn)
915cd386918e Added _lm_connection_get_context as internal function.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   984
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   985
    g_return_val_if_fail (conn != NULL, NULL);
500
915cd386918e Added _lm_connection_get_context as internal function.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   986
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   987
    return conn->context;
500
915cd386918e Added _lm_connection_get_context as internal function.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   988
}
915cd386918e Added _lm_connection_get_context as internal function.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   989
501
5f71592beac8 Added _lm_connection_get_server that returns the server string.
Mikael Hallendal <micke@imendio.com>
parents: 500
diff changeset
   990
gchar *
5f71592beac8 Added _lm_connection_get_server that returns the server string.
Mikael Hallendal <micke@imendio.com>
parents: 500
diff changeset
   991
_lm_connection_get_server (LmConnection *conn)
5f71592beac8 Added _lm_connection_get_server that returns the server string.
Mikael Hallendal <micke@imendio.com>
parents: 500
diff changeset
   992
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   993
    gchar *server;
501
5f71592beac8 Added _lm_connection_get_server that returns the server string.
Mikael Hallendal <micke@imendio.com>
parents: 500
diff changeset
   994
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   995
    g_return_val_if_fail (conn != NULL, NULL);
501
5f71592beac8 Added _lm_connection_get_server that returns the server string.
Mikael Hallendal <micke@imendio.com>
parents: 500
diff changeset
   996
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   997
    if (!connection_get_server_from_jid (conn->jid, &server)) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   998
        server = g_strdup (conn->server);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   999
    }
501
5f71592beac8 Added _lm_connection_get_server that returns the server string.
Mikael Hallendal <micke@imendio.com>
parents: 500
diff changeset
  1000
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1001
    return server;
501
5f71592beac8 Added _lm_connection_get_server that returns the server string.
Mikael Hallendal <micke@imendio.com>
parents: 500
diff changeset
  1002
}
5f71592beac8 Added _lm_connection_get_server that returns the server string.
Mikael Hallendal <micke@imendio.com>
parents: 500
diff changeset
  1003
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1004
static void
222
ca97251ddee8 Renamed internal functions to conform to code style.
Mikael Hallendal <micke@imendio.com>
parents: 221
diff changeset
  1005
connection_call_auth_cb (LmConnection *connection, gboolean success)
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1006
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1007
    if (success) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1008
        connection->state = LM_CONNECTION_STATE_AUTHENTICATED;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1009
    } else {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1010
        connection->state = LM_CONNECTION_STATE_OPEN;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1011
    }
226
5a31f474b9fd Update the connection state after SASL authentication result.
Mikael Hallendal <micke@imendio.com>
parents: 223
diff changeset
  1012
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1013
    if (connection->auth_cb) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1014
        LmCallback *cb = connection->auth_cb;
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1015
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1016
        connection->auth_cb = NULL;
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1017
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1018
        if (cb->func) {
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1019
            (* ((LmResultFunction) cb->func)) (connection,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1020
                                               success,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1021
                                               cb->user_data);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1022
        }
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1023
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1024
        _lm_utils_free_callback (cb);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1025
    }
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1026
}
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1027
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1028
static LmHandlerResult
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1029
connection_bind_reply (LmMessageHandler *handler,
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
  1030
                       LmConnection     *connection,
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
  1031
                       LmMessage        *message,
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
  1032
                       gpointer          user_data)
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1033
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1034
    LmMessage        *m;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1035
    LmMessageNode    *session_node;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1036
    LmMessageNode    *jid_node;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1037
    int               result;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1038
    LmMessageSubType  type;
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1039
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1040
    type = lm_message_get_sub_type (message);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1041
    if (type == LM_MESSAGE_SUB_TYPE_ERROR) {
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1042
        g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_SASL,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1043
               "%s: error while binding to resource\n", G_STRFUNC);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1044
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1045
        connection_call_auth_cb (connection, FALSE);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1046
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1047
        return LM_HANDLER_RESULT_REMOVE_MESSAGE;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1048
    }
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1049
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1050
    /* use whatever server returns as our effective jid */
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1051
    jid_node = lm_message_node_find_child (message->node, "jid");
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1052
    if (jid_node) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1053
        g_free (connection->effective_jid);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1054
        connection->effective_jid = g_strdup
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1055
            (lm_message_node_get_value (jid_node));
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1056
    }
297
f65eee8ec802 Support for returning effective JID, possibly changed by the server.
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 294
diff changeset
  1057
f65eee8ec802 Support for returning effective JID, possibly changed by the server.
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 294
diff changeset
  1058
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1059
    m = lm_message_new_with_sub_type (NULL,
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1060
                                      LM_MESSAGE_TYPE_IQ,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1061
                                      LM_MESSAGE_SUB_TYPE_SET);
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1062
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1063
    session_node = lm_message_node_add_child (m->node, "session", NULL);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1064
    lm_message_node_set_attributes (session_node,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1065
                                    "xmlns", XMPP_NS_SESSION,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1066
                                    NULL);
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1067
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1068
    result = lm_connection_send (connection, m, NULL);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1069
    lm_message_unref (m);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1070
    if (result < 0) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1071
        connection_do_close (connection);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1072
    }
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1073
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1074
    /* We may finally tell the client they're authorized */
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1075
    connection_call_auth_cb (connection, TRUE);
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1076
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1077
    return LM_HANDLER_RESULT_REMOVE_MESSAGE;
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1078
}
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1079
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1080
static LmHandlerResult
256
2266e56746ed Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 255
diff changeset
  1081
connection_features_cb (LmMessageHandler *handler,
412
d355b566f141 Fixed indentation
Mikael Hallendal <micke@imendio.com>
parents: 411
diff changeset
  1082
                        LmConnection     *connection,
d355b566f141 Fixed indentation
Mikael Hallendal <micke@imendio.com>
parents: 411
diff changeset
  1083
                        LmMessage        *message,
d355b566f141 Fixed indentation
Mikael Hallendal <micke@imendio.com>
parents: 411
diff changeset
  1084
                        gpointer          user_data)
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1085
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1086
    LmMessageNode *bind_node;
530
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 529
diff changeset
  1087
    LmMessageNode *starttls_node;
619
a3facd81de25 Revert "Code looks for an auth element below the returned streams:feature"
Frank Zschockelt <lm@freakysoft.de>
parents: 614
diff changeset
  1088
    LmMessageNode *old_auth;
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1089
    LmMessageNode *sasl_mechanisms;
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1090
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1091
    starttls_node = lm_message_node_find_child (message->node, "starttls");
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1092
    if (connection->ssl && lm_old_socket_get_use_starttls (connection->socket)) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1093
        if (starttls_node) {
530
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 529
diff changeset
  1094
            LmMessage *msg;
274
c32a7011e435 Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents: 271
diff changeset
  1095
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1096
            msg = lm_message_new (NULL, LM_MESSAGE_TYPE_STARTTLS);
274
c32a7011e435 Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents: 271
diff changeset
  1097
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1098
            lm_message_node_set_attributes (
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1099
                msg->node,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1100
                "xmlns", XMPP_NS_STARTTLS,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1101
                NULL);
274
c32a7011e435 Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents: 271
diff changeset
  1102
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1103
            lm_connection_send (connection, msg, NULL);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1104
            lm_message_unref (msg);
274
c32a7011e435 Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents: 271
diff changeset
  1105
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1106
            return LM_HANDLER_RESULT_REMOVE_MESSAGE;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1107
        } else if (!connection->tls_started &&
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1108
                   lm_old_socket_get_require_starttls (connection->socket)) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1109
            /* If there were no starttls features present and we require it, this is
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1110
             * the place to scream. */
274
c32a7011e435 Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents: 271
diff changeset
  1111
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1112
            g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_SASL,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1113
                   "%s: required StartTLS feature not supported by server\n", G_STRFUNC);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1114
            connection_do_close (connection);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1115
            connection_signal_disconnect (connection,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1116
                                          LM_DISCONNECT_REASON_ERROR);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1117
            return LM_HANDLER_RESULT_REMOVE_MESSAGE;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1118
        }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1119
    }
274
c32a7011e435 Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents: 271
diff changeset
  1120
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1121
    bind_node = lm_message_node_find_child (message->node, "bind");
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1122
    if (bind_node) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1123
        LmMessageHandler *bind_handler;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1124
        LmMessage        *bind_msg;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1125
        const gchar      *ns;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1126
        int               result;
223
b343ed8b3fea More style fixes to the SASL patch
Mikael Hallendal <micke@imendio.com>
parents: 222
diff changeset
  1127
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1128
        ns = lm_message_node_get_attribute (bind_node, "xmlns");
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1129
        if (!ns || strcmp (ns, XMPP_NS_BIND) != 0) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1130
            return LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1131
        }
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1132
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1133
        bind_msg = lm_message_new_with_sub_type (NULL,
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1134
                                                 LM_MESSAGE_TYPE_IQ,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1135
                                                 LM_MESSAGE_SUB_TYPE_SET);
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1136
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1137
        bind_node = lm_message_node_add_child (bind_msg->node,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1138
                                               "bind", NULL);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1139
        lm_message_node_set_attributes (bind_node,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1140
                                        "xmlns", XMPP_NS_BIND,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1141
                                        NULL);
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1142
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1143
        lm_message_node_add_child (bind_node, "resource",
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1144
                                   connection->resource);
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1145
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1146
        bind_handler = lm_message_handler_new (connection_bind_reply,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1147
                                               NULL, NULL);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1148
        result = lm_connection_send_with_reply (connection, bind_msg,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1149
                                                bind_handler, NULL);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1150
        lm_message_handler_unref (bind_handler);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1151
        lm_message_unref (bind_msg);
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1152
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1153
        if (result < 0) {
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1154
            g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_SASL,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1155
                   "%s: can't send resource binding request\n", G_STRFUNC);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1156
            connection_do_close (connection);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1157
        }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1158
    }
220
f6b9482ae89e Some style fixes to the SASL patch.
Mikael Hallendal <micke@imendio.com>
parents: 219
diff changeset
  1159
619
a3facd81de25 Revert "Code looks for an auth element below the returned streams:feature"
Frank Zschockelt <lm@freakysoft.de>
parents: 614
diff changeset
  1160
    old_auth = lm_message_node_find_child (message->node, "auth");
a3facd81de25 Revert "Code looks for an auth element below the returned streams:feature"
Frank Zschockelt <lm@freakysoft.de>
parents: 614
diff changeset
  1161
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1162
    sasl_mechanisms = lm_message_node_find_child (message->node, "mechanisms");
619
a3facd81de25 Revert "Code looks for an auth element below the returned streams:feature"
Frank Zschockelt <lm@freakysoft.de>
parents: 614
diff changeset
  1163
    if (connection->use_sasl && old_auth != NULL && sasl_mechanisms == NULL) {
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1164
        g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_SASL,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1165
               "Server uses XEP-0078 (jabber iq auth) instead of SASL\n");
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1166
        /* So the server is XMPP1.0, but doesn't support SASL and uses
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1167
         * obsolete XEP-0078 instead. Let's cope. */
332
6b6ad42cd508 Support obsolete XEP-0078 (old-style jabber auth for XMPP1.0).
Senko Rasic <senko@phyrexia.lan>
parents: 329
diff changeset
  1168
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1169
        connection->use_sasl = FALSE;
332
6b6ad42cd508 Support obsolete XEP-0078 (old-style jabber auth for XMPP1.0).
Senko Rasic <senko@phyrexia.lan>
parents: 329
diff changeset
  1170
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1171
        if (connection->sasl) {
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
  1172
            if (lm_sasl_get_auth_params (connection->sasl)) {
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1173
                GError *error = NULL;
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
  1174
                connection_old_auth (connection, lm_sasl_get_auth_params (connection->sasl),
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1175
                                     &error);
332
6b6ad42cd508 Support obsolete XEP-0078 (old-style jabber auth for XMPP1.0).
Senko Rasic <senko@phyrexia.lan>
parents: 329
diff changeset
  1176
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1177
                if (error) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1178
                    g_error_free (error);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1179
                }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1180
            }
332
6b6ad42cd508 Support obsolete XEP-0078 (old-style jabber auth for XMPP1.0).
Senko Rasic <senko@phyrexia.lan>
parents: 329
diff changeset
  1181
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1182
            lm_sasl_free (connection->sasl);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1183
            connection->sasl = NULL;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1184
        }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1185
    }
332
6b6ad42cd508 Support obsolete XEP-0078 (old-style jabber auth for XMPP1.0).
Senko Rasic <senko@phyrexia.lan>
parents: 329
diff changeset
  1186
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1187
    return LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS;
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1188
}
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1189
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1190
/**
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1191
 * lm_connection_new:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1192
 * @server: The hostname to the server for the connection.
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1193
 *
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1194
 * Creates a new closed connection. To open the connection call
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1195
 * lm_connection_open(). @server can be #NULL but must be set before calling lm_connection_open().
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1196
 *
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1197
 * Return value: A newly created LmConnection, should be unreffed with lm_connection_unref().
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1198
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1199
LmConnection *
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1200
lm_connection_new (const gchar *server)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1201
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1202
    LmConnection *connection;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1203
    gint          i;
422
1c00df7a8b11 Depend on GObject and initialize GType
Mikael Hallendal <micke@imendio.com>
parents: 421
diff changeset
  1204
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1205
    g_type_init (); /* Ensure that the GLib type library is initialized */
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1206
    lm_debug_init ();
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1207
    _lm_sock_library_init ();
140
103227122f45 2006-04-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 137
diff changeset
  1208
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1209
    connection = g_slice_new0 (LmConnection);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1210
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1211
    if (server) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1212
        connection->server  = _lm_utils_hostname_to_punycode (server);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1213
    }
82
a32b54e654e2 2004-03-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 80
diff changeset
  1214
532
c917a1900d5c Style fix in lm_connection_new
Mikael Hallendal <micke@imendio.com>
parents: 531
diff changeset
  1215
    connection->port        = LM_CONNECTION_DEFAULT_PORT;
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1216
    connection->queue       = lm_message_queue_new ((LmMessageQueueCallback) connection_message_queue_cb,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1217
                                                          connection);
532
c917a1900d5c Style fix in lm_connection_new
Mikael Hallendal <micke@imendio.com>
parents: 531
diff changeset
  1218
    connection->state       = LM_CONNECTION_STATE_CLOSED;
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1219
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1220
    connection->id_handlers = g_hash_table_new_full (g_str_hash,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1221
                                                     g_str_equal,
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1222
                                                     g_free,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1223
                                                     (GDestroyNotify) lm_message_handler_unref);
532
c917a1900d5c Style fix in lm_connection_new
Mikael Hallendal <micke@imendio.com>
parents: 531
diff changeset
  1224
    connection->ref_count   = 1;
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1225
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1226
    for (i = 0; i < LM_MESSAGE_TYPE_UNKNOWN; ++i) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1227
        connection->handlers[i] = NULL;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1228
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1229
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1230
    connection->parser = lm_parser_new
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1231
        ((LmParserMessageFunction) connection_new_message_cb,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1232
         connection, NULL);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1233
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1234
    return connection;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1235
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1236
82
a32b54e654e2 2004-03-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 80
diff changeset
  1237
/**
a32b54e654e2 2004-03-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 80
diff changeset
  1238
 * lm_connection_new_with_context:
a32b54e654e2 2004-03-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 80
diff changeset
  1239
 * @server: The hostname to the server for the connection.
a32b54e654e2 2004-03-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 80
diff changeset
  1240
 * @context: The context this connection should be running in.
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1241
 *
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1242
 * Creates a new closed connection running in a certain context. To open the
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1243
 * connection call #lm_connection_open. @server can be #NULL but must be set
82
a32b54e654e2 2004-03-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 80
diff changeset
  1244
 * before calling #lm_connection_open.
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1245
 *
82
a32b54e654e2 2004-03-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 80
diff changeset
  1246
 * Return value: A newly created LmConnection, should be unreffed with lm_connection_unref().
a32b54e654e2 2004-03-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 80
diff changeset
  1247
 **/
a32b54e654e2 2004-03-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 80
diff changeset
  1248
LmConnection *
a32b54e654e2 2004-03-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 80
diff changeset
  1249
lm_connection_new_with_context (const gchar *server, GMainContext *context)
a32b54e654e2 2004-03-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 80
diff changeset
  1250
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1251
    LmConnection *connection;
82
a32b54e654e2 2004-03-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 80
diff changeset
  1252
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1253
    connection = lm_connection_new (server);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1254
    connection->context = context;
82
a32b54e654e2 2004-03-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 80
diff changeset
  1255
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1256
    if (context) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1257
        g_main_context_ref (connection->context);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1258
    }
82
a32b54e654e2 2004-03-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 80
diff changeset
  1259
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1260
    return connection;
82
a32b54e654e2 2004-03-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 80
diff changeset
  1261
}
63
7b8d0db459ff 2004-01-05 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 62
diff changeset
  1262
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1263
/**
62
39b83ccd70ff 2003-12-27 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 61
diff changeset
  1264
 * lm_connection_open:
39b83ccd70ff 2003-12-27 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 61
diff changeset
  1265
 * @connection: #LmConnection to open
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1266
 * @function: Callback function that will be called when the connection is open.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1267
 * @user_data: User data that will be passed to @function.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1268
 * @notify: Function for freeing that user_data, can be NULL.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1269
 * @error: location to store error, or %NULL
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1270
 *
62
39b83ccd70ff 2003-12-27 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 61
diff changeset
  1271
 * An async call to open @connection. When the connection is open @function will be called.
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1272
 *
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1273
 * Return value: #TRUE if everything went fine, otherwise #FALSE.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1274
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1275
gboolean
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1276
lm_connection_open (LmConnection      *connection,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1277
                    LmResultFunction   function,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1278
                    gpointer           user_data,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1279
                    GDestroyNotify     notify,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1280
                    GError           **error)
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1281
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1282
    g_return_val_if_fail (connection != NULL, FALSE);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1283
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1284
    connection->open_cb = _lm_utils_new_callback (function,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1285
                                                  user_data, notify);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1286
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1287
    return connection_do_open (connection, error);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1288
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1289
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1290
/**
62
39b83ccd70ff 2003-12-27 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 61
diff changeset
  1291
 * lm_connection_open_and_block:
39b83ccd70ff 2003-12-27 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 61
diff changeset
  1292
 * @connection: an #LmConnection to open
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1293
 * @error: location to store error, or %NULL
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1294
 *
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1295
 * Opens @connection and waits until the stream is setup.
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1296
 *
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1297
 * Return value: #TRUE if no errors where encountered during opening and stream setup successfully, #FALSE otherwise.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1298
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1299
gboolean
62
39b83ccd70ff 2003-12-27 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 61
diff changeset
  1300
lm_connection_open_and_block (LmConnection *connection, GError **error)
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1301
{
543
fe1b614022fb Removed unused variable in lm_connection_open_and_block
Mikael Hallendal <micke@imendio.com>
parents: 542
diff changeset
  1302
    gboolean result;
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1303
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1304
    g_return_val_if_fail (connection != NULL, FALSE);
57
6b168a8917f7 2003-12-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 56
diff changeset
  1305
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1306
    connection->open_cb = NULL;
140
103227122f45 2006-04-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 137
diff changeset
  1307
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1308
    result = connection_do_open (connection, error);
63
7b8d0db459ff 2004-01-05 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 62
diff changeset
  1309
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1310
    if (result == FALSE) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1311
        return FALSE;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1312
    }
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1313
543
fe1b614022fb Removed unused variable in lm_connection_open_and_block
Mikael Hallendal <micke@imendio.com>
parents: 542
diff changeset
  1314
    while (lm_connection_get_state (connection) == LM_CONNECTION_STATE_OPENING) {
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1315
        if (g_main_context_pending (connection->context)) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1316
            g_main_context_iteration (connection->context, TRUE);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1317
        } else {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1318
            /* Sleep for 1 millisecond */
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1319
            g_usleep (1000);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1320
        }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1321
    }
64
dd835d5cee71 2004-01-06 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 63
diff changeset
  1322
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1323
    if (lm_connection_is_open (connection)) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1324
        connection_start_keep_alive (connection);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1325
        return TRUE;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1326
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1327
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1328
    /* Need to set the error here: LM-15 */
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1329
    g_set_error (error,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1330
                 LM_ERROR,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1331
                 LM_ERROR_CONNECTION_FAILED,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1332
                 "Opening the connection failed");
132
8c9c1629f691 2006-03-20 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 130
diff changeset
  1333
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1334
    return FALSE;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1335
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1336
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1337
/**
59
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  1338
 * lm_connection_cancel_open:
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  1339
 * @connection: an #LmConnection to cancel opening on
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  1340
 *
91
d51b8e4f43d9 2004-08-27 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 90
diff changeset
  1341
 * Cancels the open operation of a connection. The connection should be in the state #LM_CONNECTION_STATE_OPENING.
59
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  1342
 **/
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  1343
void
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  1344
lm_connection_cancel_open (LmConnection *connection)
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  1345
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1346
    g_return_if_fail (connection != NULL);
59
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  1347
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1348
    if (connection->open_cb) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1349
        _lm_utils_free_callback (connection->open_cb);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1350
        connection->open_cb = NULL;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1351
    }
211
efbf2da5e443 Added checks when freeing proxy and closing socket. Also free open_cb in cancel_open.
Mikael Hallendal <micke@imendio.com>
parents: 210
diff changeset
  1352
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1353
    connection->cancel_open = TRUE;
271
52ea4e0b897a Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents: 256
diff changeset
  1354
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1355
    lm_old_socket_asyncns_cancel (connection->socket);
57
6b168a8917f7 2003-12-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 56
diff changeset
  1356
}
6b168a8917f7 2003-12-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 56
diff changeset
  1357
6b168a8917f7 2003-12-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 56
diff changeset
  1358
/**
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1359
 * lm_connection_close:
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1360
 * @connection: #LmConnection to close
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1361
 * @error: location to store error, or %NULL
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1362
 *
56
3bf928955fc5 2003-11-20 Ross Burton <ross@burtonini.com>
hallski <hallski>
parents: 55
diff changeset
  1363
 * A synchronous call to close the connection. When returning the connection is considered to be closed and can be opened again with lm_connection_open().
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1364
 *
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1365
 * Return value: Returns #TRUE if no errors where detected, otherwise #FALSE.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1366
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1367
gboolean
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
  1368
lm_connection_close (LmConnection *connection, GError **error)
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1369
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1370
    gboolean no_errors = TRUE;
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1371
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1372
    g_return_val_if_fail (connection != NULL, FALSE);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1373
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1374
    if (connection->socket) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1375
        lm_old_socket_asyncns_cancel (connection->socket);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1376
    }
156
8c054d9e98b8 2006-06-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 155
diff changeset
  1377
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1378
    if (connection->state == LM_CONNECTION_STATE_CLOSED) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1379
        g_set_error (error,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1380
                     LM_ERROR,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1381
                     LM_ERROR_CONNECTION_NOT_OPEN,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1382
                     "Connection is not open, call lm_connection_open() first");
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1383
        return FALSE;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1384
    }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1385
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1386
    lm_verbose ("Disconnecting from: %s:%d\n",
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1387
                connection->server, connection->port);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1388
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1389
    if (lm_connection_is_open (connection)) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1390
        if (!connection_send (connection, "</stream:stream>", -1, error)) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1391
            no_errors = FALSE;
503
c7c1722ec2db Fixed a crash when lm_connection_close was called.
Mikael Hallendal <micke@imendio.com>
parents: 501
diff changeset
  1392
        }
271
52ea4e0b897a Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents: 256
diff changeset
  1393
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1394
        lm_old_socket_flush (connection->socket);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1395
    }
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1396
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1397
    connection_do_close (connection);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1398
    connection_signal_disconnect (connection, LM_DISCONNECT_REASON_OK);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1399
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1400
    return no_errors;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1401
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1402
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1403
static void
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
  1404
connection_sasl_auth_finished (LmSASL       *sasl,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1405
                               LmConnection *connection,
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
  1406
                               gboolean      success,
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
  1407
                               const gchar  *reason)
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1408
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1409
    if (!success) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1410
        lm_verbose ("SASL authentication failed, closing connection\n");
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1411
        connection_call_auth_cb (connection, FALSE);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1412
        return;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1413
    }
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1414
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1415
    connection_send_stream_header (connection);
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1416
}
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1417
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1418
/**
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1419
 * lm_connection_authenticate:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1420
 * @connection: #LmConnection to authenticate.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1421
 * @username: Username used to authenticate.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1422
 * @password: Password corresponding to @username.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1423
 * @resource: Resource used for this connection.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1424
 * @function: Callback called when authentication is finished.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1425
 * @user_data: Userdata passed to @function when called.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1426
 * @notify: Destroy function to free the memory used by @user_data, can be NULL.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1427
 * @error: location to store error, or %NULL
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1428
 *
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1429
 * Tries to authenticate a user against the server. The #LmResult in the result callback @function will say whether it succeeded or not.
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1430
 *
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1431
 * Return value: #TRUE if no errors where detected while sending the authentication message, #FALSE otherwise.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1432
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1433
gboolean
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1434
lm_connection_authenticate (LmConnection      *connection,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1435
                            const gchar       *username,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1436
                            const gchar       *password,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1437
                            const gchar       *resource,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1438
                            LmResultFunction   function,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1439
                            gpointer           user_data,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1440
                            GDestroyNotify     notify,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1441
                            GError           **error)
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1442
{
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
  1443
    LmAuthParameters *auth_params;
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
  1444
    gboolean          ret_val;
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1445
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1446
    g_return_val_if_fail (connection != NULL, FALSE);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1447
    g_return_val_if_fail (username != NULL, FALSE);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1448
    g_return_val_if_fail (password != NULL, FALSE);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1449
    g_return_val_if_fail (resource != NULL, FALSE);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1450
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
  1451
    auth_params = lm_auth_parameters_new (username, password, resource);
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
  1452
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1453
    if (!lm_connection_is_open (connection)) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1454
        g_set_error (error,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1455
                     LM_ERROR,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1456
                     LM_ERROR_CONNECTION_NOT_OPEN,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1457
                     "Connection is not open, call lm_connection_open() first");
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1458
        return FALSE;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1459
    }
59
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  1460
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1461
    connection->state = LM_CONNECTION_STATE_AUTHENTICATING;
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1462
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1463
    connection->auth_cb = _lm_utils_new_callback (function,
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1464
                                                  user_data,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1465
                                                  notify);
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
  1466
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
  1467
    connection->resource = g_strdup (lm_auth_parameters_get_resource (auth_params));
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1468
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1469
    connection->effective_jid = g_strdup_printf ("%s/%s",
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1470
                                                 connection->jid, connection->resource);
307
f169e9281745 Rename lm_conn_get_effective_jid() to lm_conn_get_full_jid() to
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 306
diff changeset
  1471
533
c45243823756 Added some TODO items and minor style fixes
Mikael Hallendal <micke@imendio.com>
parents: 532
diff changeset
  1472
    /* TODO: Break out Credentials (or use the already existing AuthReqData struct for *
c45243823756 Added some TODO items and minor style fixes
Mikael Hallendal <micke@imendio.com>
parents: 532
diff changeset
  1473
     *       Username/Password and Resource                                            */
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1474
    if (connection->use_sasl) {
600
7f0be2600f6d The Digest URI in the MD5 SASL Response wasn't set correctly when using
Sjoerd Simons <sjoerd.simons@collabora.co.uk>
parents: 573
diff changeset
  1475
        gchar *domain = NULL;
7f0be2600f6d The Digest URI in the MD5 SASL Response wasn't set correctly when using
Sjoerd Simons <sjoerd.simons@collabora.co.uk>
parents: 573
diff changeset
  1476
7f0be2600f6d The Digest URI in the MD5 SASL Response wasn't set correctly when using
Sjoerd Simons <sjoerd.simons@collabora.co.uk>
parents: 573
diff changeset
  1477
        if (!connection_get_server_from_jid (connection->jid, &domain)) {
7f0be2600f6d The Digest URI in the MD5 SASL Response wasn't set correctly when using
Sjoerd Simons <sjoerd.simons@collabora.co.uk>
parents: 573
diff changeset
  1478
            domain = g_strdup (connection->server);
7f0be2600f6d The Digest URI in the MD5 SASL Response wasn't set correctly when using
Sjoerd Simons <sjoerd.simons@collabora.co.uk>
parents: 573
diff changeset
  1479
        }
7f0be2600f6d The Digest URI in the MD5 SASL Response wasn't set correctly when using
Sjoerd Simons <sjoerd.simons@collabora.co.uk>
parents: 573
diff changeset
  1480
7f0be2600f6d The Digest URI in the MD5 SASL Response wasn't set correctly when using
Sjoerd Simons <sjoerd.simons@collabora.co.uk>
parents: 573
diff changeset
  1481
        lm_sasl_authenticate (connection->sasl, auth_params, domain,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1482
                              connection_sasl_auth_finished);
600
7f0be2600f6d The Digest URI in the MD5 SASL Response wasn't set correctly when using
Sjoerd Simons <sjoerd.simons@collabora.co.uk>
parents: 573
diff changeset
  1483
        g_free (domain);
255
704881ac7788 Fixed potential problem if auth was not called from the open callback.
Mikael Hallendal <micke@imendio.com>
parents: 249
diff changeset
  1484
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1485
        connection->features_cb  =
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1486
            lm_message_handler_new (connection_features_cb,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1487
                                    NULL, NULL);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1488
        lm_connection_register_message_handler (connection,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1489
                                                connection->features_cb,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1490
                                                LM_MESSAGE_TYPE_STREAM_FEATURES,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1491
                                                LM_HANDLER_PRIORITY_FIRST);
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1492
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
  1493
        ret_val = TRUE;
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
  1494
    } else {
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
  1495
        ret_val = connection_old_auth (connection, auth_params, error);
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1496
    }
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1497
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
  1498
    lm_auth_parameters_unref (auth_params);
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
  1499
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
  1500
    return ret_val;
332
6b6ad42cd508 Support obsolete XEP-0078 (old-style jabber auth for XMPP1.0).
Senko Rasic <senko@phyrexia.lan>
parents: 329
diff changeset
  1501
}
6b6ad42cd508 Support obsolete XEP-0078 (old-style jabber auth for XMPP1.0).
Senko Rasic <senko@phyrexia.lan>
parents: 329
diff changeset
  1502
415
14ff0a255a86 Moved _lm_connection_old_auth from public header file.
Mikael Hallendal <micke@imendio.com>
parents: 413
diff changeset
  1503
static gboolean
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
  1504
connection_old_auth (LmConnection      *connection,
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
  1505
                     LmAuthParameters  *auth_params,
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
  1506
                     GError           **error)
332
6b6ad42cd508 Support obsolete XEP-0078 (old-style jabber auth for XMPP1.0).
Senko Rasic <senko@phyrexia.lan>
parents: 329
diff changeset
  1507
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1508
    LmMessage        *m;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1509
    LmMessageHandler *handler;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1510
    gboolean          result;
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1511
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
  1512
    m = connection_create_auth_req_msg (auth_params);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1513
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1514
    handler = lm_message_handler_new (connection_auth_req_reply,
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
  1515
                                      lm_auth_parameters_ref (auth_params),
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
  1516
                                      (GDestroyNotify) lm_auth_parameters_unref);
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1517
    result = lm_connection_send_with_reply (connection, m, handler, error);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1518
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1519
    lm_message_handler_unref (handler);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1520
    lm_message_unref (m);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1521
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1522
    return result;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1523
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1524
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1525
/**
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1526
 * lm_connection_authenticate_and_block:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1527
 * @connection: an #LmConnection
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1528
 * @username: Username used to authenticate.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1529
 * @password: Password corresponding to @username.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1530
 * @resource: Resource used for this connection.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1531
 * @error: location to store error, or %NULL
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1532
 *
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1533
 * Tries to authenticate a user against the server. This function blocks until a reply to the authentication attempt is returned and returns whether it was successful or not.
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1534
 *
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1535
 * Return value: #TRUE if no errors where detected and authentication was successful. #FALSE otherwise.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1536
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1537
gboolean
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1538
lm_connection_authenticate_and_block (LmConnection  *connection,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1539
                                      const gchar   *username,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1540
                                      const gchar   *password,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1541
                                      const gchar   *resource,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1542
                                      GError       **error)
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1543
{
530
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 529
diff changeset
  1544
    gboolean result;
323
64ea88f05696 Make lm_connection_authenticate_and_block reuse lm_connection_authenticate
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 320
diff changeset
  1545
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1546
    result = lm_connection_authenticate (connection, username, password,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1547
                                         resource, NULL, NULL, NULL, error);
323
64ea88f05696 Make lm_connection_authenticate_and_block reuse lm_connection_authenticate
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 320
diff changeset
  1548
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1549
    if (!result)
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1550
        return result;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1551
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1552
    while (lm_connection_get_state (connection) == LM_CONNECTION_STATE_AUTHENTICATING) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1553
        if (g_main_context_pending (connection->context)) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1554
            g_main_context_iteration (connection->context, TRUE);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1555
        } else {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1556
            /* Sleep for 1 millisecond */
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1557
            g_usleep (1000);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1558
        }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1559
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1560
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1561
    switch (lm_connection_get_state (connection)) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1562
    case LM_CONNECTION_STATE_AUTHENTICATED:
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1563
        return TRUE;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1564
        break;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1565
    case LM_CONNECTION_STATE_OPEN:
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1566
        g_set_error (error,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1567
                     LM_ERROR,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1568
                     LM_ERROR_AUTH_FAILED,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1569
                     "Authentication failed");
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1570
        return FALSE;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1571
        break;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1572
    default:
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1573
        g_assert_not_reached ();
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1574
        break;
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1575
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1576
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1577
    return FALSE;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1578
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1579
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1580
/**
394
03933ba2fb40 Added lm_connection_get_keep_alive.
Mikael Hallendal <micke@imendio.com>
parents: 345
diff changeset
  1581
 * lm_connection_get_keep_alive_rate:
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1582
 * @connection: an #LmConnection
394
03933ba2fb40 Added lm_connection_get_keep_alive.
Mikael Hallendal <micke@imendio.com>
parents: 345
diff changeset
  1583
 *
03933ba2fb40 Added lm_connection_get_keep_alive.
Mikael Hallendal <micke@imendio.com>
parents: 345
diff changeset
  1584
 * Get the keep alive rate, in seconds. Zero is returned if no keep alive rate has been set.
03933ba2fb40 Added lm_connection_get_keep_alive.
Mikael Hallendal <micke@imendio.com>
parents: 345
diff changeset
  1585
 *
03933ba2fb40 Added lm_connection_get_keep_alive.
Mikael Hallendal <micke@imendio.com>
parents: 345
diff changeset
  1586
 * Since 1.3.5
03933ba2fb40 Added lm_connection_get_keep_alive.
Mikael Hallendal <micke@imendio.com>
parents: 345
diff changeset
  1587
 **/
03933ba2fb40 Added lm_connection_get_keep_alive.
Mikael Hallendal <micke@imendio.com>
parents: 345
diff changeset
  1588
guint
03933ba2fb40 Added lm_connection_get_keep_alive.
Mikael Hallendal <micke@imendio.com>
parents: 345
diff changeset
  1589
lm_connection_get_keep_alive_rate (LmConnection *connection)
03933ba2fb40 Added lm_connection_get_keep_alive.
Mikael Hallendal <micke@imendio.com>
parents: 345
diff changeset
  1590
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1591
    g_return_val_if_fail (connection != NULL, 0);
394
03933ba2fb40 Added lm_connection_get_keep_alive.
Mikael Hallendal <micke@imendio.com>
parents: 345
diff changeset
  1592
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1593
    return connection->keep_alive_rate;
394
03933ba2fb40 Added lm_connection_get_keep_alive.
Mikael Hallendal <micke@imendio.com>
parents: 345
diff changeset
  1594
}
03933ba2fb40 Added lm_connection_get_keep_alive.
Mikael Hallendal <micke@imendio.com>
parents: 345
diff changeset
  1595
03933ba2fb40 Added lm_connection_get_keep_alive.
Mikael Hallendal <micke@imendio.com>
parents: 345
diff changeset
  1596
/**
90
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
  1597
 * lm_connection_set_keep_alive_rate:
394
03933ba2fb40 Added lm_connection_get_keep_alive.
Mikael Hallendal <micke@imendio.com>
parents: 345
diff changeset
  1598
 * @connection: an #LmConnection
90
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
  1599
 * @rate: Number of seconds between keep alive packages are sent.
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1600
 *
90
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
  1601
 * Set the keep alive rate, in seconds. Set to 0 to prevent keep alive messages to be sent.
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
  1602
 * A keep alive message is a single space character.
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
  1603
 **/
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
  1604
void
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
  1605
lm_connection_set_keep_alive_rate (LmConnection *connection, guint rate)
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
  1606
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1607
    g_return_if_fail (connection != NULL);
90
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
  1608
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1609
    connection_stop_keep_alive (connection);
90
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
  1610
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1611
    if (rate == 0) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1612
        return;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1613
    }
90
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
  1614
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1615
    connection->keep_alive_rate = rate;
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1616
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1617
    if (lm_connection_is_open (connection)) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1618
        connection_start_keep_alive (connection);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1619
    }
90
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
  1620
}
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
  1621
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
  1622
/**
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1623
 * lm_connection_is_open:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1624
 * @connection: #LmConnection to check if it is open.
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1625
 *
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1626
 * Check if the @connection is currently open.
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1627
 *
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1628
 * Return value: #TRUE if connection is open and #FALSE if it is closed.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1629
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1630
gboolean
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1631
lm_connection_is_open (LmConnection *connection)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1632
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1633
    g_return_val_if_fail (connection != NULL, FALSE);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1634
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1635
    return connection->state >= LM_CONNECTION_STATE_OPEN;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1636
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1637
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1638
/**
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1639
 * lm_connection_is_authenticated:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1640
 * @connection: #LmConnection to check if it is authenticated
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1641
 *
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1642
 * Check if @connection is authenticated.
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1643
 *
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1644
 * Return value: #TRUE if connection is authenticated, #FALSE otherwise.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1645
 **/
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1646
gboolean
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1647
lm_connection_is_authenticated (LmConnection *connection)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1648
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1649
    g_return_val_if_fail (connection != NULL, FALSE);
66
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1650
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1651
    return connection->state >= LM_CONNECTION_STATE_AUTHENTICATED;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1652
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1653
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1654
/**
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1655
 * lm_connection_get_server:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1656
 * @connection: an #LmConnection
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1657
 *
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1658
 * Fetches the server address that @connection is using.
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1659
 *
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1660
 * Return value: the server address
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1661
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1662
const gchar *
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1663
lm_connection_get_server (LmConnection *connection)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1664
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1665
    g_return_val_if_fail (connection != NULL, NULL);
66
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1666
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1667
    return connection->server;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1668
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1669
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1670
/**
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1671
 * lm_connection_set_server:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1672
 * @connection: an #LmConnection
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1673
 * @server: Address of the server
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1674
 *
87
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
  1675
 * Sets the server address for @connection to @server. Notice that @connection
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1676
 * can't be open while doing this.
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1677
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1678
void
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1679
lm_connection_set_server (LmConnection *connection, const gchar *server)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1680
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1681
    g_return_if_fail (connection != NULL);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1682
    g_return_if_fail (server != NULL);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1683
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1684
    if (lm_connection_is_open (connection)) {
614
773201ca404c Replaced every g_warning() with g_log()
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1685
        g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_VERBOSE,
773201ca404c Replaced every g_warning() with g_log()
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1686
               "Can't change server address while connected");
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1687
        return;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1688
    }
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1689
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1690
    g_free (connection->server);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1691
    connection->server = _lm_utils_hostname_to_punycode (server);
87
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
  1692
}
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
  1693
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
  1694
/**
89
e756a937e540 2004-08-09 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 87
diff changeset
  1695
 * lm_connection_get_jid:
87
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
  1696
 * @connection: an #LmConnection
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1697
 *
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1698
 * Fetches the jid set for @connection is using.
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1699
 *
89
e756a937e540 2004-08-09 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 87
diff changeset
  1700
 * Return value: the jid
87
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
  1701
 **/
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
  1702
const gchar *
89
e756a937e540 2004-08-09 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 87
diff changeset
  1703
lm_connection_get_jid (LmConnection *connection)
87
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
  1704
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1705
    g_return_val_if_fail (connection != NULL, NULL);
87
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
  1706
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1707
    return connection->jid;
87
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
  1708
}
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
  1709
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
  1710
/**
307
f169e9281745 Rename lm_conn_get_effective_jid() to lm_conn_get_full_jid() to
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 306
diff changeset
  1711
 * lm_connection_get_full_jid:
297
f65eee8ec802 Support for returning effective JID, possibly changed by the server.
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 294
diff changeset
  1712
 * @connection: an #LmConnection
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1713
 *
307
f169e9281745 Rename lm_conn_get_effective_jid() to lm_conn_get_full_jid() to
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 306
diff changeset
  1714
 * Returns the full jid that server set for us after
f169e9281745 Rename lm_conn_get_effective_jid() to lm_conn_get_full_jid() to
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 306
diff changeset
  1715
 * resource binding, complete with the resource.
297
f65eee8ec802 Support for returning effective JID, possibly changed by the server.
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 294
diff changeset
  1716
 *
f65eee8ec802 Support for returning effective JID, possibly changed by the server.
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 294
diff changeset
  1717
 * Return value: the jid
f65eee8ec802 Support for returning effective JID, possibly changed by the server.
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 294
diff changeset
  1718
 **/
307
f169e9281745 Rename lm_conn_get_effective_jid() to lm_conn_get_full_jid() to
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 306
diff changeset
  1719
gchar *
f169e9281745 Rename lm_conn_get_effective_jid() to lm_conn_get_full_jid() to
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 306
diff changeset
  1720
lm_connection_get_full_jid (LmConnection *connection)
297
f65eee8ec802 Support for returning effective JID, possibly changed by the server.
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 294
diff changeset
  1721
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1722
    g_return_val_if_fail (connection != NULL, NULL);
297
f65eee8ec802 Support for returning effective JID, possibly changed by the server.
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 294
diff changeset
  1723
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1724
    return connection->effective_jid;
297
f65eee8ec802 Support for returning effective JID, possibly changed by the server.
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 294
diff changeset
  1725
}
f65eee8ec802 Support for returning effective JID, possibly changed by the server.
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 294
diff changeset
  1726
f65eee8ec802 Support for returning effective JID, possibly changed by the server.
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 294
diff changeset
  1727
/**
89
e756a937e540 2004-08-09 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 87
diff changeset
  1728
 * lm_connection_set_jid:
87
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
  1729
 * @connection: an #LmConnection
89
e756a937e540 2004-08-09 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 87
diff changeset
  1730
 * @jid: JID to be used for @connection
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1731
 *
89
e756a937e540 2004-08-09 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 87
diff changeset
  1732
 * Sets the JID to be used for @connection.
87
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
  1733
 **/
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1734
void
89
e756a937e540 2004-08-09 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 87
diff changeset
  1735
lm_connection_set_jid (LmConnection *connection, const gchar *jid)
87
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
  1736
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1737
    g_return_if_fail (connection != NULL);
87
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
  1738
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1739
    if (lm_connection_is_open (connection)) {
614
773201ca404c Replaced every g_warning() with g_log()
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1740
        g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_VERBOSE,
773201ca404c Replaced every g_warning() with g_log()
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1741
                   "Can't change JID while connected");
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1742
        return;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1743
    }
87
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
  1744
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1745
    g_free (connection->jid);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1746
    connection->jid = g_strdup (jid);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1747
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1748
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1749
/**
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1750
 * lm_connection_get_port:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1751
 * @connection: an #LmConnection
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1752
 *
56
3bf928955fc5 2003-11-20 Ross Burton <ross@burtonini.com>
hallski <hallski>
parents: 55
diff changeset
  1753
 * Fetches the port that @connection is using.
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1754
 *
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1755
 * Return value:
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1756
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1757
guint
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1758
lm_connection_get_port (LmConnection *connection)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1759
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1760
    g_return_val_if_fail (connection != NULL, 0);
66
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1761
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1762
    return connection->port;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1763
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1764
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1765
/**
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1766
 * lm_connection_set_port:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1767
 * @connection: an #LmConnection
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1768
 * @port: server port
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1769
 *
56
3bf928955fc5 2003-11-20 Ross Burton <ross@burtonini.com>
hallski <hallski>
parents: 55
diff changeset
  1770
 * Sets the server port that @connection will be using.
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1771
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1772
void
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1773
lm_connection_set_port (LmConnection *connection, guint port)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1774
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1775
    g_return_if_fail (connection != NULL);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1776
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1777
    if (lm_connection_is_open (connection)) {
614
773201ca404c Replaced every g_warning() with g_log()
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1778
        g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_VERBOSE,
773201ca404c Replaced every g_warning() with g_log()
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1779
               "Can't change server port while connected");
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1780
        return;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1781
    }
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1782
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1783
    connection->port = port;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1784
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1785
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1786
/**
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1787
 * lm_connection_get_ssl:
68
28203e15de0e 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 67
diff changeset
  1788
 * @connection: an #LmConnection
15
1ff2f81867e1 2003-07-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 12
diff changeset
  1789
 *
68
28203e15de0e 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 67
diff changeset
  1790
 * Returns the SSL struct if the connection is using one.
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1791
 *
68
28203e15de0e 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 67
diff changeset
  1792
 * Return value: The ssl struct or %NULL if no proxy is used.
15
1ff2f81867e1 2003-07-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 12
diff changeset
  1793
 **/
68
28203e15de0e 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 67
diff changeset
  1794
LmSSL *
28203e15de0e 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 67
diff changeset
  1795
lm_connection_get_ssl (LmConnection *connection)
15
1ff2f81867e1 2003-07-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 12
diff changeset
  1796
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1797
    g_return_val_if_fail (connection != NULL, NULL);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1798
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1799
    return connection->ssl;
15
1ff2f81867e1 2003-07-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 12
diff changeset
  1800
}
68
28203e15de0e 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 67
diff changeset
  1801
28203e15de0e 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 67
diff changeset
  1802
/**
28203e15de0e 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 67
diff changeset
  1803
 * lm_connection_set_ssl:
28203e15de0e 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 67
diff changeset
  1804
 * @connection: An #LmConnection
28203e15de0e 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 67
diff changeset
  1805
 * @ssl: An #LmSSL
28203e15de0e 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 67
diff changeset
  1806
 *
28203e15de0e 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 67
diff changeset
  1807
 * Sets SSL struct or unset if @ssl is %NULL. If set @connection will use SSL to for the connection.
62
39b83ccd70ff 2003-12-27 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 61
diff changeset
  1808
 */
39b83ccd70ff 2003-12-27 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 61
diff changeset
  1809
void
68
28203e15de0e 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 67
diff changeset
  1810
lm_connection_set_ssl (LmConnection *connection, LmSSL *ssl)
62
39b83ccd70ff 2003-12-27 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 61
diff changeset
  1811
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1812
    g_return_if_fail (connection != NULL);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1813
    g_return_if_fail (lm_ssl_is_supported () == TRUE);
66
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1814
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1815
    if (connection->ssl) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1816
        lm_ssl_unref (connection->ssl);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1817
    }
66
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1818
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1819
    if (ssl) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1820
        connection->ssl = lm_ssl_ref (ssl);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1821
    } else {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1822
        connection->ssl = NULL;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1823
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1824
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1825
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1826
/**
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1827
 * lm_connection_get_proxy:
66
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1828
 * @connection: an #LmConnection
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1829
 *
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1830
 * Returns the proxy if the connection is using one.
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1831
 *
66
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1832
 * Return value: The proxy or %NULL if no proxy is used.
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1833
 **/
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1834
LmProxy *
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1835
lm_connection_get_proxy (LmConnection *connection)
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1836
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1837
    g_return_val_if_fail (connection != NULL, NULL);
66
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1838
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1839
    return connection->proxy;
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1840
}
66
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1841
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1842
/**
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1843
 * lm_connection_set_proxy:
66
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1844
 * @connection: an #LmConnection
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1845
 * @proxy: an #LmProxy
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1846
 *
94
85b606ac2c0c 2004-09-02 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 93
diff changeset
  1847
 * Sets the proxy to use for this connection. To unset pass #NULL.
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1848
 *
66
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1849
 **/
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1850
void
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1851
lm_connection_set_proxy (LmConnection *connection, LmProxy *proxy)
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1852
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1853
    g_return_if_fail (connection != NULL);
66
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1854
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1855
    if (lm_connection_is_open (connection)) {
614
773201ca404c Replaced every g_warning() with g_log()
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1856
        g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_VERBOSE,
773201ca404c Replaced every g_warning() with g_log()
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1857
               "Can't change server proxy while connected");
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1858
        return;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1859
    }
87
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
  1860
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1861
    if (connection->proxy) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1862
        lm_proxy_unref (connection->proxy);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1863
        connection->proxy = NULL;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1864
    }
66
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1865
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1866
    if (proxy && lm_proxy_get_type (proxy) != LM_PROXY_TYPE_NONE) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1867
        connection->proxy = lm_proxy_ref (proxy);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1868
    }
66
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1869
}
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1870
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1871
/**
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1872
 * lm_connection_send:
56
3bf928955fc5 2003-11-20 Ross Burton <ross@burtonini.com>
hallski <hallski>
parents: 55
diff changeset
  1873
 * @connection: #LmConnection to send message over.
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1874
 * @message: #LmMessage to send.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1875
 * @error: location to store error, or %NULL
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1876
 *
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1877
 * Asynchronous call to send a message.
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1878
 *
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1879
 * Return value: Returns #TRUE if no errors where detected while sending, #FALSE otherwise.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1880
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1881
gboolean
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1882
lm_connection_send (LmConnection  *connection,
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1883
                    LmMessage     *message,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1884
                    GError       **error)
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1885
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1886
    gchar    *xml_str;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1887
    gchar    *ch;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1888
    gboolean  result;
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1889
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1890
    g_return_val_if_fail (connection != NULL, FALSE);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1891
    g_return_val_if_fail (message != NULL, FALSE);
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
  1892
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1893
    xml_str = lm_message_node_to_string (message->node);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1894
    if ((ch = strstr (xml_str, "</stream:stream>"))) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1895
        *ch = '\0';
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1896
    }
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1897
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1898
    result = connection_send (connection, xml_str, -1, error);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1899
    g_free (xml_str);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1900
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1901
    return result;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1902
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1903
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1904
/**
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1905
 * lm_connection_send_with_reply:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1906
 * @connection: #LmConnection used to send message.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1907
 * @message: #LmMessage to send.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1908
 * @handler: #LmMessageHandler that will be used when a reply to @message arrives
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1909
 * @error: location to store error, or %NULL
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1910
 *
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1911
 * Send a #LmMessage which will result in a reply.
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1912
 *
56
3bf928955fc5 2003-11-20 Ross Burton <ross@burtonini.com>
hallski <hallski>
parents: 55
diff changeset
  1913
 * Return value: Returns #TRUE if no errors where detected while sending, #FALSE otherwise.
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1914
 **/
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1915
gboolean
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1916
lm_connection_send_with_reply (LmConnection      *connection,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1917
                               LmMessage         *message,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1918
                               LmMessageHandler  *handler,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1919
                               GError           **error)
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1920
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1921
    gchar *id;
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1922
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1923
    g_return_val_if_fail (connection != NULL, FALSE);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1924
    g_return_val_if_fail (message != NULL, FALSE);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1925
    g_return_val_if_fail (handler != NULL, FALSE);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1926
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1927
    if (lm_message_node_get_attribute (message->node, "id")) {
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1928
        id = g_strdup (lm_message_node_get_attribute (message->node,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1929
                                                      "id"));
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1930
    } else {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1931
        id = _lm_utils_generate_id ();
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1932
        lm_message_node_set_attributes (message->node, "id", id, NULL);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1933
    }
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1934
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1935
    g_hash_table_insert (connection->id_handlers,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1936
                         id, lm_message_handler_ref (handler));
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1937
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1938
    return lm_connection_send (connection, message, error);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1939
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1940
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1941
/**
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1942
 * lm_connection_send_with_reply_and_block:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1943
 * @connection: an #LmConnection
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1944
 * @message: an #LmMessage
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1945
 * @error: Set if error was detected during sending.
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1946
 *
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1947
 * Send @message and wait for return.
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1948
 *
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1949
 * Return value: The reply
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1950
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1951
LmMessage *
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1952
lm_connection_send_with_reply_and_block (LmConnection  *connection,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1953
                                         LmMessage     *message,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1954
                                         GError       **error)
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1955
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1956
    gchar     *id;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1957
    LmMessage *reply = NULL;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1958
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1959
    g_return_val_if_fail (connection != NULL, NULL);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1960
    g_return_val_if_fail (message != NULL, NULL);
66
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1961
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1962
    if (connection->state < LM_CONNECTION_STATE_OPENING) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1963
        g_set_error (error,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1964
                     LM_ERROR,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1965
                     LM_ERROR_CONNECTION_NOT_OPEN,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1966
                     "Connection is not open, call lm_connection_open() first");
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1967
        return FALSE;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1968
    }
125
6163119136b5 2005-08-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 124
diff changeset
  1969
6163119136b5 2005-08-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 124
diff changeset
  1970
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1971
    if (lm_message_node_get_attribute (message->node, "id")) {
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1972
        id = g_strdup (lm_message_node_get_attribute (message->node,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1973
                                                      "id"));
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1974
    } else {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1975
        id = _lm_utils_generate_id ();
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1976
        lm_message_node_set_attributes (message->node, "id", id, NULL);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1977
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1978
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1979
    lm_message_queue_detach (connection->queue);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1980
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1981
    lm_connection_send (connection, message, error);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1982
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1983
    while (!reply) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1984
        const gchar *m_id;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1985
        guint        n;
39
b909b5af5a97 2003-10-01 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 37
diff changeset
  1986
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1987
        g_main_context_iteration (connection->context, TRUE);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1988
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1989
        if (lm_message_queue_is_empty (connection->queue)) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1990
            continue;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1991
        }
39
b909b5af5a97 2003-10-01 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 37
diff changeset
  1992
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1993
        for (n = 0; n < lm_message_queue_get_length (connection->queue); n++) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1994
            LmMessage *m;
39
b909b5af5a97 2003-10-01 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 37
diff changeset
  1995
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1996
            m = (LmMessage *) lm_message_queue_peek_nth (connection->queue, n);
39
b909b5af5a97 2003-10-01 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 37
diff changeset
  1997
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1998
            m_id = lm_message_node_get_attribute (m->node, "id");
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1999
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2000
            if (m_id && strcmp (m_id, id) == 0) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2001
                reply = m;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2002
                lm_message_queue_pop_nth (connection->queue, n);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2003
                break;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2004
            }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2005
        }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2006
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2007
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2008
    g_free (id);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2009
    lm_message_queue_attach (connection->queue, connection->context);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2010
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2011
    return reply;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2012
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2013
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2014
/**
609
8dab2a5c2123 Added lm_connection_unregister_reply_handler()
Frank Zschockelt <flm@freakysoft.de>
parents: 608
diff changeset
  2015
 * lm_connection_unregister_reply_handler:
8dab2a5c2123 Added lm_connection_unregister_reply_handler()
Frank Zschockelt <flm@freakysoft.de>
parents: 608
diff changeset
  2016
 * @connection: Connection to unregister a handler for.
8dab2a5c2123 Added lm_connection_unregister_reply_handler()
Frank Zschockelt <flm@freakysoft.de>
parents: 608
diff changeset
  2017
 * @handler: The handler to unregister.
8dab2a5c2123 Added lm_connection_unregister_reply_handler()
Frank Zschockelt <flm@freakysoft.de>
parents: 608
diff changeset
  2018
 *
8dab2a5c2123 Added lm_connection_unregister_reply_handler()
Frank Zschockelt <flm@freakysoft.de>
parents: 608
diff changeset
  2019
 * Unregisters the reply handler for @connection. @handler will no longer be
8dab2a5c2123 Added lm_connection_unregister_reply_handler()
Frank Zschockelt <flm@freakysoft.de>
parents: 608
diff changeset
  2020
 * called if an incoming message has the id for which it was registered.
8dab2a5c2123 Added lm_connection_unregister_reply_handler()
Frank Zschockelt <flm@freakysoft.de>
parents: 608
diff changeset
  2021
 **/
8dab2a5c2123 Added lm_connection_unregister_reply_handler()
Frank Zschockelt <flm@freakysoft.de>
parents: 608
diff changeset
  2022
void
8dab2a5c2123 Added lm_connection_unregister_reply_handler()
Frank Zschockelt <flm@freakysoft.de>
parents: 608
diff changeset
  2023
lm_connection_unregister_reply_handler (LmConnection     *connection,
8dab2a5c2123 Added lm_connection_unregister_reply_handler()
Frank Zschockelt <flm@freakysoft.de>
parents: 608
diff changeset
  2024
                                        LmMessageHandler *handler)
8dab2a5c2123 Added lm_connection_unregister_reply_handler()
Frank Zschockelt <flm@freakysoft.de>
parents: 608
diff changeset
  2025
{
8dab2a5c2123 Added lm_connection_unregister_reply_handler()
Frank Zschockelt <flm@freakysoft.de>
parents: 608
diff changeset
  2026
    GHashTableIter iter;
8dab2a5c2123 Added lm_connection_unregister_reply_handler()
Frank Zschockelt <flm@freakysoft.de>
parents: 608
diff changeset
  2027
    gpointer key, value;
8dab2a5c2123 Added lm_connection_unregister_reply_handler()
Frank Zschockelt <flm@freakysoft.de>
parents: 608
diff changeset
  2028
8dab2a5c2123 Added lm_connection_unregister_reply_handler()
Frank Zschockelt <flm@freakysoft.de>
parents: 608
diff changeset
  2029
    g_return_if_fail (connection != NULL);
8dab2a5c2123 Added lm_connection_unregister_reply_handler()
Frank Zschockelt <flm@freakysoft.de>
parents: 608
diff changeset
  2030
    g_return_if_fail (handler != NULL);
8dab2a5c2123 Added lm_connection_unregister_reply_handler()
Frank Zschockelt <flm@freakysoft.de>
parents: 608
diff changeset
  2031
8dab2a5c2123 Added lm_connection_unregister_reply_handler()
Frank Zschockelt <flm@freakysoft.de>
parents: 608
diff changeset
  2032
    g_hash_table_iter_init (&iter, connection -> id_handlers);
8dab2a5c2123 Added lm_connection_unregister_reply_handler()
Frank Zschockelt <flm@freakysoft.de>
parents: 608
diff changeset
  2033
    while (g_hash_table_iter_next (&iter, &key, &value)) {
8dab2a5c2123 Added lm_connection_unregister_reply_handler()
Frank Zschockelt <flm@freakysoft.de>
parents: 608
diff changeset
  2034
        if (handler == value) {
8dab2a5c2123 Added lm_connection_unregister_reply_handler()
Frank Zschockelt <flm@freakysoft.de>
parents: 608
diff changeset
  2035
            g_hash_table_iter_remove (&iter);
8dab2a5c2123 Added lm_connection_unregister_reply_handler()
Frank Zschockelt <flm@freakysoft.de>
parents: 608
diff changeset
  2036
            break;
8dab2a5c2123 Added lm_connection_unregister_reply_handler()
Frank Zschockelt <flm@freakysoft.de>
parents: 608
diff changeset
  2037
        }
8dab2a5c2123 Added lm_connection_unregister_reply_handler()
Frank Zschockelt <flm@freakysoft.de>
parents: 608
diff changeset
  2038
    }
8dab2a5c2123 Added lm_connection_unregister_reply_handler()
Frank Zschockelt <flm@freakysoft.de>
parents: 608
diff changeset
  2039
}
8dab2a5c2123 Added lm_connection_unregister_reply_handler()
Frank Zschockelt <flm@freakysoft.de>
parents: 608
diff changeset
  2040
8dab2a5c2123 Added lm_connection_unregister_reply_handler()
Frank Zschockelt <flm@freakysoft.de>
parents: 608
diff changeset
  2041
/**
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2042
 * lm_connection_register_message_handler:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2043
 * @connection: Connection to register a handler for.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2044
 * @handler: Message handler to register.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2045
 * @type: Message type that @handler will handle.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2046
 * @priority: The priority in which to call @handler.
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  2047
 *
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2048
 * Registers a #LmMessageHandler to handle incoming messages of a certain type.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2049
 * To unregister the handler call lm_connection_unregister_message_handler().
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2050
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2051
void
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
  2052
lm_connection_register_message_handler  (LmConnection      *connection,
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
  2053
                                         LmMessageHandler  *handler,
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
  2054
                                         LmMessageType      type,
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
  2055
                                         LmHandlerPriority  priority)
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2056
{
530
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 529
diff changeset
  2057
    HandlerData *hd;
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  2058
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2059
    g_return_if_fail (connection != NULL);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2060
    g_return_if_fail (handler != NULL);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2061
    g_return_if_fail (type != LM_MESSAGE_TYPE_UNKNOWN);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2062
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2063
    hd = g_new0 (HandlerData, 1);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2064
    hd->priority = priority;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2065
    hd->handler  = lm_message_handler_ref (handler);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2066
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2067
    connection->handlers[type] = g_slist_insert_sorted (connection->handlers[type],
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  2068
                                                        hd,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2069
                                                        (GCompareFunc) connection_handler_compare_func);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2070
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2071
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2072
/**
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2073
 * lm_connection_unregister_message_handler:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2074
 * @connection: Connection to unregister a handler for.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2075
 * @handler: The handler to unregister.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2076
 * @type: What type of messages to unregister this handler for.
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  2077
 *
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  2078
 * Unregisters a handler for @connection. @handler will no longer be called
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2079
 * when incoming messages of @type arrive.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2080
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2081
void
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
  2082
lm_connection_unregister_message_handler (LmConnection     *connection,
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
  2083
                                          LmMessageHandler *handler,
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
  2084
                                          LmMessageType     type)
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2085
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2086
    GSList *l;
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  2087
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2088
    g_return_if_fail (connection != NULL);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2089
    g_return_if_fail (handler != NULL);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2090
    g_return_if_fail (type != LM_MESSAGE_TYPE_UNKNOWN);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2091
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2092
    for (l = connection->handlers[type]; l; l = l->next) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2093
        HandlerData *hd = (HandlerData *) l->data;
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  2094
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2095
        if (handler == hd->handler) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2096
            connection->handlers[type] = g_slist_remove_link (connection->handlers[type], l);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2097
            g_slist_free (l);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2098
            lm_message_handler_unref (hd->handler);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2099
            g_free (hd);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2100
            break;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2101
        }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2102
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2103
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2104
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2105
/**
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2106
 * lm_connection_set_disconnect_function:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2107
 * @connection: Connection to register disconnect callback for.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2108
 * @function: Function to be called when @connection is closed.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2109
 * @user_data: User data passed to @function.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2110
 * @notify: Function that will be called with @user_data when @user_data needs to be freed. Pass #NULL if it shouldn't be freed.
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  2111
 *
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  2112
 * Set the callback that will be called when a connection is closed.
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2113
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2114
void
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2115
lm_connection_set_disconnect_function (LmConnection         *connection,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2116
                                       LmDisconnectFunction  function,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2117
                                       gpointer              user_data,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2118
                                       GDestroyNotify        notify)
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2119
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2120
    g_return_if_fail (connection != NULL);
66
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  2121
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2122
    if (connection->disconnect_cb) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2123
        _lm_utils_free_callback (connection->disconnect_cb);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2124
    }
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  2125
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2126
    if (function) {
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  2127
        connection->disconnect_cb = _lm_utils_new_callback (function,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2128
                                                            user_data,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2129
                                                            notify);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2130
    } else {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2131
        connection->disconnect_cb = NULL;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2132
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2133
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2134
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2135
/**
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2136
 * lm_connection_send_raw:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2137
 * @connection: Connection used to send
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2138
 * @str: The string to send, the entire string will be sent.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2139
 * @error: Set if error was detected during sending.
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  2140
 *
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2141
 * Asynchronous call to send a raw string. Useful for debugging and testing.
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  2142
 *
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  2143
 * Return value: Returns #TRUE if no errors was detected during sending,
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2144
 * #FALSE otherwise.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2145
 **/
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  2146
gboolean
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  2147
lm_connection_send_raw (LmConnection  *connection,
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  2148
                        const gchar   *str,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2149
                        GError       **error)
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2150
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2151
    g_return_val_if_fail (connection != NULL, FALSE);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2152
    g_return_val_if_fail (str != NULL, FALSE);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2153
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2154
    return connection_send (connection, str, -1, error);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2155
}
59
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  2156
/**
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  2157
 * lm_connection_get_state:
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  2158
 * @connection: Connection to get state on
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  2159
 *
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  2160
 * Returns the state of the connection.
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  2161
 *
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  2162
 * Return value: The state of the connection.
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  2163
 **/
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  2164
LmConnectionState
59
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  2165
lm_connection_get_state (LmConnection *connection)
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  2166
{
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  2167
    g_return_val_if_fail (connection != NULL,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2168
                          LM_CONNECTION_STATE_CLOSED);
59
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  2169
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2170
    return connection->state;
59
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  2171
}
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2172
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2173
/**
308
7e2050a6df75 Added lm_connection_get_client_host (forward-port from LM1.2).
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 307
diff changeset
  2174
 * lm_connection_get_client_host:
7e2050a6df75 Added lm_connection_get_client_host (forward-port from LM1.2).
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 307
diff changeset
  2175
 * @connection: An #LmConnection
7e2050a6df75 Added lm_connection_get_client_host (forward-port from LM1.2).
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 307
diff changeset
  2176
 *
7e2050a6df75 Added lm_connection_get_client_host (forward-port from LM1.2).
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 307
diff changeset
  2177
 * Returns the local host name of the connection.
7e2050a6df75 Added lm_connection_get_client_host (forward-port from LM1.2).
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 307
diff changeset
  2178
 *
7e2050a6df75 Added lm_connection_get_client_host (forward-port from LM1.2).
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 307
diff changeset
  2179
 * Return value: A newly allocated string representing the local host name.
7e2050a6df75 Added lm_connection_get_client_host (forward-port from LM1.2).
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 307
diff changeset
  2180
 **/
7e2050a6df75 Added lm_connection_get_client_host (forward-port from LM1.2).
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 307
diff changeset
  2181
gchar *
7e2050a6df75 Added lm_connection_get_client_host (forward-port from LM1.2).
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 307
diff changeset
  2182
lm_connection_get_local_host (LmConnection *connection)
7e2050a6df75 Added lm_connection_get_client_host (forward-port from LM1.2).
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 307
diff changeset
  2183
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2184
    return lm_old_socket_get_local_host (connection->socket);
308
7e2050a6df75 Added lm_connection_get_client_host (forward-port from LM1.2).
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 307
diff changeset
  2185
}
7e2050a6df75 Added lm_connection_get_client_host (forward-port from LM1.2).
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 307
diff changeset
  2186
7e2050a6df75 Added lm_connection_get_client_host (forward-port from LM1.2).
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 307
diff changeset
  2187
/**
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2188
 * lm_connection_ref:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2189
 * @connection: Connection to add a reference to.
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  2190
 *
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  2191
 * Add a reference on @connection. To remove a reference call
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2192
 * lm_connection_unref().
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  2193
 *
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2194
 * Return value: Returns the same connection.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2195
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2196
LmConnection*
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2197
lm_connection_ref (LmConnection *connection)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2198
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2199
    g_return_val_if_fail (connection != NULL, NULL);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  2200
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2201
    connection->ref_count++;
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  2202
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2203
    return connection;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2204
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2205
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2206
/**
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2207
 * lm_connection_unref:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2208
 * @connection: Connection to remove reference from.
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  2209
 *
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2210
 * Removes a reference on @connection. If there are no references to
56
3bf928955fc5 2003-11-20 Ross Burton <ross@burtonini.com>
hallski <hallski>
parents: 55
diff changeset
  2211
 * @connection it will be freed and shouldn't be used again.
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2212
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2213
void
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2214
lm_connection_unref (LmConnection *connection)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2215
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2216
    g_return_if_fail (connection != NULL);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  2217
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2218
    connection->ref_count--;
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  2219
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2220
    if (connection->ref_count == 0) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2221
        connection_free (connection);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2222
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2223
}