loudmouth/lm-connection.c
author psykose <alice@ayaya.dev>
Thu, 21 Apr 2022 20:23:32 +0200
changeset 744 4ebe32453682
parent 735 7ae46452fb10
permissions -rw-r--r--
fix macro define for freeaddrinfo with asyncns previously, this define was only made in lm-asyncns-resolver.c, which does not propagate it to lm-resolver.c, where freeaddrinfo() is used. this means that when asyncns support is used, the standard libc freeaddrinfo() is called on an addrinfo acquired from asyncns_getaddrinfo, which is undefined behaviour, and leads to a segfault on musl libc.
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
690
7ccf2113ec5f Update the postal address of the FSF
Frank Zschockelt <lm@freakysoft.de>
parents: 648
diff changeset
    18
 * License along with this program; if not, see <https://www.gnu.org/licenses>
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    19
 */
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    20
417
364c17252e5f Added inlined documentation from generated through the Gtk-doc migration script.
Mikael Hallendal <micke@imendio.com>
parents: 416
diff changeset
    21
/**
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
    22
 * SECTION:lm-connection
421
2a91651d22de Added Title to the inlined documentation
Mikael Hallendal <micke@imendio.com>
parents: 420
diff changeset
    23
 * @Title: LmConnection
417
364c17252e5f Added inlined documentation from generated through the Gtk-doc migration script.
Mikael Hallendal <micke@imendio.com>
parents: 416
diff changeset
    24
 * @Short_description: A client connection to the server
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
    25
 *
417
364c17252e5f Added inlined documentation from generated through the Gtk-doc migration script.
Mikael Hallendal <micke@imendio.com>
parents: 416
diff changeset
    26
 * 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
    27
 * <informalexample><programlisting>
364c17252e5f Added inlined documentation from generated through the Gtk-doc migration script.
Mikael Hallendal <micke@imendio.com>
parents: 416
diff changeset
    28
 * int
364c17252e5f Added inlined documentation from generated through the Gtk-doc migration script.
Mikael Hallendal <micke@imendio.com>
parents: 416
diff changeset
    29
 * 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
    30
 * {
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
    31
 *      LmConnection *connection;
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
    32
 *      GError       *error = NULL;
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
    33
 *      gint          i;
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
    34
 *      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
    35
 *
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
    36
 *      connection = lm_connection_new ("myserver");
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
    37
 *
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
    38
 *      if (!lm_connection_open_and_block (connection, &amp;error)) {
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
    39
 *          g_error ("Failed to open: &percnt;s\n", error->message);
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
    40
 *      }
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
    41
 *
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
    42
 *      if (!lm_connection_authenticate_and_block (connection,
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
    43
 *                                                 "username", "password",
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
    44
 *                                                 "resource",
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
    45
 *                                                 &amp;error)) {
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
    46
 *          g_error ("Failed to authenticate: &percnt;s\n", error->message);
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
    47
 *      }
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
    48
 *
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
    49
 *      m = lm_message_new ("recipient", LM_MESSAGE_TYPE_MESSAGE);
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
    50
 *      lm_message_node_add_child (m->node, "body", "message");
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
    51
 *
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
    52
 *      if (!lm_connection_send (connection, m, &amp;error)) {
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
    53
 *          g_error ("Send failed: &percnt;s\n", error->message);
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
    54
 *      }
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
    55
 *
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
    56
 *      lm_message_unref (m);
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_connection_close (connection, NULL);
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
    59
 *      lm_connection_unref (connection);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
    60
 *
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
    61
 *      return 0;
417
364c17252e5f Added inlined documentation from generated through the Gtk-doc migration script.
Mikael Hallendal <micke@imendio.com>
parents: 416
diff changeset
    62
 * }
364c17252e5f Added inlined documentation from generated through the Gtk-doc migration script.
Mikael Hallendal <micke@imendio.com>
parents: 416
diff changeset
    63
 * </programlisting></informalexample>
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
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    66
#include <config.h>
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    67
12
fc5e71b1369c 2003-07-07 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 9
diff changeset
    68
#include <string.h>
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
    69
#include <sys/stat.h>
12
fc5e71b1369c 2003-07-07 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 9
diff changeset
    70
#include <sys/types.h>
59
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
    71
#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
    72
7bc0c6ad11ff Fixes LM-118 so that building on Mac OS X works again.
Richard Hult <richard@imendio.com>
parents: 324
diff changeset
    73
/* 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
    74
#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
    75
#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
    76
#endif
7bc0c6ad11ff Fixes LM-118 so that building on Mac OS X works again.
Richard Hult <richard@imendio.com>
parents: 324
diff changeset
    77
271
52ea4e0b897a Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents: 256
diff changeset
    78
#include <arpa/nameser.h>
52ea4e0b897a Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents: 256
diff changeset
    79
#include <resolv.h>
9
2e14e3ab411b 2003-06-24 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 7
diff changeset
    80
422
1c00df7a8b11 Depend on GObject and initialize GType
Mikael Hallendal <micke@imendio.com>
parents: 421
diff changeset
    81
#include <glib-object.h>
140
103227122f45 2006-04-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 137
diff changeset
    82
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
    83
#include "lm-data-objects.h"
140
103227122f45 2006-04-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 137
diff changeset
    84
#include "lm-sock.h"
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    85
#include "lm-debug.h"
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    86
#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
    87
#include "lm-feature-ping.h"
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    88
#include "lm-internals.h"
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
    89
#include "lm-message-queue.h"
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
    90
#include "lm-misc.h"
137
18785575aa7a 2006-04-05 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 133
diff changeset
    91
#include "lm-ssl-internals.h"
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    92
#include "lm-parser.h"
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    93
#include "lm-sha.h"
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    94
#include "lm-connection.h"
155
d24c4392d4e3 2006-06-16 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 153
diff changeset
    95
#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
    96
#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
    97
#include "lm-sasl.h"
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
    98
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    99
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
   100
    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
   101
    LmMessageHandler  *handler;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   102
} HandlerData;
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   103
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   104
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
   105
    /* Parameters */
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   106
    GMainContext      *context;
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   107
533
c45243823756 Added some TODO items and minor style fixes
Mikael Hallendal <micke@imendio.com>
parents: 532
diff changeset
   108
    /* 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
   109
    gchar             *server;
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   110
    gchar             *jid;
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   111
    gchar             *effective_jid;
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   112
    guint              port;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   113
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   114
    LmOldSocket       *socket;
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   115
    LmSSL             *ssl;
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   116
    LmProxy           *proxy;
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   117
    LmParser          *parser;
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   118
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   119
    gchar             *stream_id;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   120
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   121
    GHashTable        *id_handlers;
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   122
    GSList            *handlers[LM_MESSAGE_TYPE_UNKNOWN];
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   123
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   124
    /* XMPP1.0 stuff (SASL, resource binding, StartTLS) */
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   125
    gboolean           use_sasl;
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   126
    LmSASL            *sasl;
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   127
    gchar             *resource;
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   128
    LmMessageHandler  *features_cb;
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   129
    LmMessageHandler  *starttls_cb;
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   130
    gboolean           tls_started;
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
   131
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   132
    /* Communication */
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   133
    guint              open_id;
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   134
    LmCallback        *open_cb;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   135
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   136
    gboolean           cancel_open;
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   137
    LmCallback        *auth_cb;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   138
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   139
    LmCallback        *disconnect_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
    LmMessageQueue    *queue;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   142
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   143
    LmConnectionState  state;
59
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
   144
533
c45243823756 Added some TODO items and minor style fixes
Mikael Hallendal <micke@imendio.com>
parents: 532
diff changeset
   145
    /* 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
   146
    guint              keep_alive_rate;
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   147
    LmFeaturePing     *feature_ping;
184
4e16d32b2410 2006-10-16 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 181
diff changeset
   148
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   149
    gint               ref_count;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   150
};
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   151
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   152
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
   153
    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
   154
    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
   155
    AUTH_TYPE_0K     = 4
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   156
} AuthType;
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   157
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
   158
#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
   159
#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
   160
#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
   161
416
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   162
static void     connection_free              (LmConnection        *connection);
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   163
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
   164
                                              LmMessage           *message);
416
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   165
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
   166
                                              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
   167
                                              LmConnection        *connection);
416
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   168
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
   169
                                              GError             **error);
416
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   170
void            connection_do_close          (LmConnection        *connection);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   171
static LmMessage *
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
   172
connection_create_auth_req_msg               (LmAuthParameters    *auth_params);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   173
416
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   174
static LmMessage *
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   175
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
   176
                                              LmAuthParameters    *auth_params,
416
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   177
                                              gint                 auth_type);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   178
static LmHandlerResult
416
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   179
connection_auth_req_reply                    (LmMessageHandler    *handler,
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   180
                                              LmConnection        *connection,
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   181
                                              LmMessage           *m,
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   182
                                              gpointer             user_data);
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   183
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
   184
static LmHandlerResult
416
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   185
connection_auth_reply                        (LmMessageHandler    *handler,
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   186
                                              LmConnection        *connection,
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   187
                                              LmMessage           *m,
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   188
                                              gpointer             user_data);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   189
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
   190
                                              LmMessage           *m);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   191
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
   192
                                              LmMessage           *m);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   193
static gint
416
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   194
connection_handler_compare_func              (HandlerData         *a,
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   195
                                              HandlerData         *b);
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   196
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
   197
static void     connection_stop_keep_alive   (LmConnection        *connection);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   198
static gboolean connection_send              (LmConnection        *connection,
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   199
                                              const gchar         *str,
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   200
                                              gint                 len,
416
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   201
                                              GError             **error);
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   202
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
   203
                                              LmConnection        *connection);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   204
static void
416
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   205
connection_signal_disconnect                 (LmConnection        *connection,
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   206
                                              LmDisconnectReason   reason);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   207
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
   208
                                              const gchar         *buf,
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   209
                                              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
   210
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
   211
                                              LmDisconnectReason   reason,
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   212
                                              LmConnection        *connection);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   213
static void
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   214
connection_socket_connect_cb                 (LmOldSocket         *socket,
416
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   215
                                              gboolean             result,
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   216
                                              LmConnection        *connection);
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   217
static gboolean
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   218
connection_get_server_from_jid               (const gchar         *jid,
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   219
                                              gchar              **server);
416
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   220
static void
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   221
connection_send_stream_header                (LmConnection        *connection);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   222
static LmHandlerResult
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   223
connection_features_cb                       (LmMessageHandler    *handler,
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   224
                                              LmConnection        *connection,
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   225
                                              LmMessage           *message,
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   226
                                              gpointer             user_data);
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   227
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
   228
                                              LmAuthParameters    *auth_params,
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   229
                                              GError             **errror);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   230
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   231
static void
405
f33dcdadf95c Factored out connection_free_handlers from connection_free
Mikael Hallendal <micke@imendio.com>
parents: 394
diff changeset
   232
connection_free_handlers (LmConnection *connection)
f33dcdadf95c Factored out connection_free_handlers from connection_free
Mikael Hallendal <micke@imendio.com>
parents: 394
diff changeset
   233
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   234
    int i;
405
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
    /* 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
   237
    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
   238
        GSList *l;
405
f33dcdadf95c Factored out connection_free_handlers from connection_free
Mikael Hallendal <micke@imendio.com>
parents: 394
diff changeset
   239
518
cdd6a0c5b439 Went 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
        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
   241
            HandlerData *hd = (HandlerData *) l->data;
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   242
518
cdd6a0c5b439 Went 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
            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
   244
            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
   245
        }
405
f33dcdadf95c Factored out connection_free_handlers from connection_free
Mikael Hallendal <micke@imendio.com>
parents: 394
diff changeset
   246
518
cdd6a0c5b439 Went 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
        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
   248
    }
405
f33dcdadf95c Factored out connection_free_handlers from connection_free
Mikael Hallendal <micke@imendio.com>
parents: 394
diff changeset
   249
}
f33dcdadf95c Factored out connection_free_handlers from connection_free
Mikael Hallendal <micke@imendio.com>
parents: 394
diff changeset
   250
f33dcdadf95c Factored out connection_free_handlers from connection_free
Mikael Hallendal <micke@imendio.com>
parents: 394
diff changeset
   251
static void
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   252
connection_free (LmConnection *connection)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   253
{
573
038320b7357e Don't free connection internals before it's closed. [#34]
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   254
    /* 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
   255
     * 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
   256
     * 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
   257
     */
038320b7357e Don't free connection internals before it's closed. [#34]
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   258
    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
   259
        connection_do_close (connection);
038320b7357e Don't free connection internals before it's closed. [#34]
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   260
    }
038320b7357e Don't free connection internals before it's closed. [#34]
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   261
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   262
    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
   263
    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
   264
    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
   265
    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
   266
    g_free (connection->resource);
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
   267
518
cdd6a0c5b439 Went 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
    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
   269
        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
   270
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   271
518
cdd6a0c5b439 Went 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
    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
   273
        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
   274
    }
153
b2324df84971 2006-06-06 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 143
diff changeset
   275
518
cdd6a0c5b439 Went 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
    connection_free_handlers (connection);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
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
    g_hash_table_destroy (connection->id_handlers);
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
    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
   281
        _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
   282
    }
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   283
518
cdd6a0c5b439 Went 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
    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
   285
        _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
   286
    }
143
92193c23b0c7 2006-05-26 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 140
diff changeset
   287
518
cdd6a0c5b439 Went 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
    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
   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
    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
   291
        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
   292
    }
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
   293
518
cdd6a0c5b439 Went 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
    lm_message_queue_unref (connection->queue);
115
f2a921e232e5 2005-04-24 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 114
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
    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
   297
        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
   298
    }
133
f7522d7ed6dc 2006-04-03 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 132
diff changeset
   299
518
cdd6a0c5b439 Went 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
    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
   301
        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
   302
    }
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   303
518
cdd6a0c5b439 Went 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
    g_slice_free (LmConnection, connection);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   305
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   306
408
b07ef2183e6b Factored out connection_run_message_handler from connection_handle_message.
Mikael Hallendal <micke@imendio.com>
parents: 406
diff changeset
   307
static LmHandlerResult
b07ef2183e6b Factored out connection_run_message_handler from connection_handle_message.
Mikael Hallendal <micke@imendio.com>
parents: 406
diff changeset
   308
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
   309
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   310
    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
   311
    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
   312
    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
   313
518
cdd6a0c5b439 Went 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
    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
   315
    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
   316
        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
   317
    }
408
b07ef2183e6b Factored out connection_run_message_handler from connection_handle_message.
Mikael Hallendal <micke@imendio.com>
parents: 406
diff changeset
   318
518
cdd6a0c5b439 Went 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
    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
   320
    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
   321
        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
   322
                                                     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
   323
                                                     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
   324
        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
   325
                             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
   326
    }
408
b07ef2183e6b Factored out connection_run_message_handler from connection_handle_message.
Mikael Hallendal <micke@imendio.com>
parents: 406
diff changeset
   327
518
cdd6a0c5b439 Went 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
    return result;
408
b07ef2183e6b Factored out connection_run_message_handler from connection_handle_message.
Mikael Hallendal <micke@imendio.com>
parents: 406
diff changeset
   329
}
b07ef2183e6b Factored out connection_run_message_handler from connection_handle_message.
Mikael Hallendal <micke@imendio.com>
parents: 406
diff changeset
   330
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   331
static void
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   332
connection_handle_message (LmConnection *connection, LmMessage *m)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   333
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   334
    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
   335
    LmHandlerResult  result = LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   336
518
cdd6a0c5b439 Went 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
    lm_connection_ref (connection);
143
92193c23b0c7 2006-05-26 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 140
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
    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
   340
        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
   341
        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
   342
    }
306
d466fc30829f Added disconnect error for resource conflict. Fixes LM-55.
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 297
diff changeset
   343
613
174c17adc1e7 Refine "Allow replies to non-iq stanzas"
Frank Zschockelt <lm@freakysoft.de>
parents: 609
diff changeset
   344
    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
   345
        (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
   346
        (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
   347
        result = connection_run_message_handler (connection, m);
174c17adc1e7 Refine "Allow replies to non-iq stanzas"
Frank Zschockelt <lm@freakysoft.de>
parents: 609
diff changeset
   348
        if (result == LM_HANDLER_RESULT_REMOVE_MESSAGE) {
174c17adc1e7 Refine "Allow replies to non-iq stanzas"
Frank Zschockelt <lm@freakysoft.de>
parents: 609
diff changeset
   349
            goto out;
174c17adc1e7 Refine "Allow replies to non-iq stanzas"
Frank Zschockelt <lm@freakysoft.de>
parents: 609
diff changeset
   350
        }
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   351
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   352
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   353
    for (l = connection->handlers[lm_message_get_type (m)];
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   354
         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
   355
         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
   356
        HandlerData *hd = (HandlerData *) l->data;
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   357
518
cdd6a0c5b439 Went 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
        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
   359
                                                     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
   360
                                                     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
   361
    }
143
92193c23b0c7 2006-05-26 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 140
diff changeset
   362
518
cdd6a0c5b439 Went 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
    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
   364
        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
   365
        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
   366
    }
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   367
518
cdd6a0c5b439 Went 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
 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
   369
    lm_connection_unref (connection);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   370
518
cdd6a0c5b439 Went 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
    return;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   372
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   373
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   374
static void
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   375
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
   376
                           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
   377
                           LmConnection *connection)
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   378
{
518
cdd6a0c5b439 Went 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
    const gchar *from;
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
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
    lm_message_ref (m);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
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
    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
   384
    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
   385
        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
   386
    }
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   387
518
cdd6a0c5b439 Went 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
    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
   389
                _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
   390
                from);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   391
518
cdd6a0c5b439 Went 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
    lm_message_queue_push_tail (connection->queue, m);
82
a32b54e654e2 2004-03-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 80
diff changeset
   393
}
a32b54e654e2 2004-03-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 80
diff changeset
   394
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
   395
static void
529
6bb284696153 More style fixes
Mikael Hallendal <micke@imendio.com>
parents: 528
diff changeset
   396
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
   397
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   398
    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
   399
    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
   400
                                  LM_DISCONNECT_REASON_PING_TIME_OUT);
90
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
   401
}
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
   402
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
   403
static void
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
   404
connection_start_keep_alive (LmConnection *connection)
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
   405
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   406
    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
   407
        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
   408
    }
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
   409
518
cdd6a0c5b439 Went 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
    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
   411
                                             "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
   412
                                             "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
   413
                                             NULL);
90
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
   414
518
cdd6a0c5b439 Went 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
    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
   416
                      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
   417
                      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
   418
518
cdd6a0c5b439 Went 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
    lm_feature_ping_start (connection->feature_ping);
90
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
   420
}
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
   421
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
   422
static void
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
   423
connection_stop_keep_alive (LmConnection *connection)
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
   424
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   425
    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
   426
        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
   427
        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
   428
                                              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
   429
                                              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
   430
        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
   431
    }
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   432
518
cdd6a0c5b439 Went 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
    connection->feature_ping = NULL;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   434
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   435
406
3c6b13d37d41 Factored out connection_log_send from connection_send
Mikael Hallendal <micke@imendio.com>
parents: 405
diff changeset
   436
static void
3c6b13d37d41 Factored out connection_log_send from connection_send
Mikael Hallendal <micke@imendio.com>
parents: 405
diff changeset
   437
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
   438
                     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
   439
                     gint          len)
406
3c6b13d37d41 Factored out connection_log_send from connection_send
Mikael Hallendal <micke@imendio.com>
parents: 405
diff changeset
   440
{
518
cdd6a0c5b439 Went 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
    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
   442
    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
   443
           "-----------------------------------\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
   444
    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
   445
    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
   446
           "-----------------------------------\n");
406
3c6b13d37d41 Factored out connection_log_send from connection_send
Mikael Hallendal <micke@imendio.com>
parents: 405
diff changeset
   447
}
3c6b13d37d41 Factored out connection_log_send from connection_send
Mikael Hallendal <micke@imendio.com>
parents: 405
diff changeset
   448
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   449
static gboolean
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   450
connection_send (LmConnection  *connection,
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   451
                 const gchar   *str,
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   452
                 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
   453
                 GError       **error)
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   454
{
518
cdd6a0c5b439 Went 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
    gint b_written;
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
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
    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
   458
        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
   459
               "Connection is not open.\n");
140
103227122f45 2006-04-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 137
diff changeset
   460
518
cdd6a0c5b439 Went 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
        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
   462
                     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
   463
                     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
   464
                     "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
   465
        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
   466
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   467
518
cdd6a0c5b439 Went 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
    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
   469
        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
   470
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   471
518
cdd6a0c5b439 Went 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
    connection_log_send (connection, str, len);
68
28203e15de0e 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 67
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
    /* 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
   475
       buffer and return */
133
f7522d7ed6dc 2006-04-03 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 132
diff changeset
   476
518
cdd6a0c5b439 Went 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
    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
   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
    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
   480
        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
   481
                     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
   482
                     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
   483
                     "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
   484
        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
   485
    }
133
f7522d7ed6dc 2006-04-03 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 132
diff changeset
   486
518
cdd6a0c5b439 Went 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
    return TRUE;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   488
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   489
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   490
static void
249
2cca5ec7b573 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 248
diff changeset
   491
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
   492
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   493
    LmMessage *m;
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
    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
   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
    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
   498
        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
   499
        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
   500
    }
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   501
}
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   502
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   503
/* Returns directly */
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   504
/* 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
   505
static gboolean
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   506
connection_do_open (LmConnection *connection, GError **error)
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   507
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   508
    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
   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
    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
   511
        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
   512
                     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
   513
                     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
   514
                     "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
   515
        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
   516
    }
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   517
518
cdd6a0c5b439 Went 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
    domain = _lm_connection_get_server (connection);
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
    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
   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
    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
   523
                                               (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
   524
                                               (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
   525
                                               (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
   526
                                               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
   527
                                               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
   528
                                               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
   529
                                               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
   530
                                               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
   531
                                               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
   532
                                               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
   533
                                               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
   534
518
cdd6a0c5b439 Went 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
    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
   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
    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
   538
        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
   539
    }
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   540
518
cdd6a0c5b439 Went 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
    lm_message_queue_attach (connection->queue, connection->context);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
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
    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
   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
    return TRUE;
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   546
}
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   547
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   548
void
256
2266e56746ed Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 255
diff changeset
   549
connection_do_close (LmConnection *connection)
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   550
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   551
    connection_stop_keep_alive (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
    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
   554
        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
   555
    }
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   556
518
cdd6a0c5b439 Went 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
    lm_message_queue_detach (connection->queue);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
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
    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
   560
        /* 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
   561
        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
   562
        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
   563
    }
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   564
518
cdd6a0c5b439 Went 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
    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
   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
    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
   568
        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
   569
        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
   570
    }
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   571
}
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   572
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   573
static LmMessage *
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
   574
connection_create_auth_req_msg (LmAuthParameters *auth_params)
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   575
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   576
    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
   577
    LmMessageNode *q_node;
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   578
518
cdd6a0c5b439 Went 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
    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
   580
                                      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
   581
    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
   582
    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
   583
                                    "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
   584
                                    NULL);
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
   585
    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
   586
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   587
    return m;
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   588
}
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   589
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   590
static LmMessage *
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
   591
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
   592
                            LmAuthParameters *auth_params,
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
   593
                            gint              auth_type)
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   594
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   595
    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
   596
    LmMessageNode *q_node;
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   597
518
cdd6a0c5b439 Went 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
    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
   599
                                             LM_MESSAGE_SUB_TYPE_SET);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   600
518
cdd6a0c5b439 Went 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
    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
   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
    lm_message_node_set_attributes (q_node,
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   604
                                    "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
   605
                                    NULL);
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   606
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
   607
    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
   608
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   609
    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
   610
        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
   611
        /* 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
   612
    }
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   613
518
cdd6a0c5b439 Went 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
    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
   615
        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
   616
        gchar *digest;
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   617
518
cdd6a0c5b439 Went 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
        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
   619
        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
   620
        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
   621
        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
   622
        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
   623
        g_free (digest);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   624
    }
518
cdd6a0c5b439 Went 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
    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
   626
        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
   627
        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
   628
    } 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
   629
        /* 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
   630
    }
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   631
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
   632
    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
   633
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   634
    return auth_msg;
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   635
}
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   636
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   637
static LmHandlerResult
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   638
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
   639
                           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
   640
                           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
   641
                           gpointer          user_data)
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   642
{
518
cdd6a0c5b439 Went 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
    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
   644
    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
   645
    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
   646
    LmAuthParameters *auth_params = (LmAuthParameters *) user_data;
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   647
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   648
    auth_type = connection_check_auth_type (m);
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   649
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
   650
    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
   651
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   652
    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
   653
                                           NULL, NULL);
624
a94013a4555d Fix some gcc warnings
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   654
    lm_connection_send_with_reply (connection, auth_msg,
a94013a4555d Fix some gcc warnings
Mikael Berthe <mikael@lilotux.net>
parents: 619
diff changeset
   655
                                   auth_handler, 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
   656
    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
   657
    lm_message_unref (auth_msg);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   658
518
cdd6a0c5b439 Went 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
    return LM_HANDLER_RESULT_REMOVE_MESSAGE;
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   660
}
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   661
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   662
static int
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   663
connection_check_auth_type (LmMessage *auth_req_rpl)
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   664
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   665
    LmMessageNode *q_node;
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   666
    gint           ret_val = 0;
21
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
    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
   669
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   670
    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
   671
        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
   672
    }
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   673
518
cdd6a0c5b439 Went 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
    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
   675
        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
   676
    }
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   677
518
cdd6a0c5b439 Went 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
    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
   679
        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
   680
    }
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   681
518
cdd6a0c5b439 Went 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
    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
   683
        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
   684
        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
   685
    }
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   686
518
cdd6a0c5b439 Went 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
    return ret_val;
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   688
}
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   689
644
4fc5eab77197 Use connection_call_auth_cb in one more place
Myhailo Danylenko <isbear@ukrpost.net>
parents: 624
diff changeset
   690
static void
4fc5eab77197 Use connection_call_auth_cb in one more place
Myhailo Danylenko <isbear@ukrpost.net>
parents: 624
diff changeset
   691
connection_call_auth_cb (LmConnection *connection, gboolean success)
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   692
{
644
4fc5eab77197 Use connection_call_auth_cb in one more place
Myhailo Danylenko <isbear@ukrpost.net>
parents: 624
diff changeset
   693
    if (success) {
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   694
        connection->state = LM_CONNECTION_STATE_AUTHENTICATED;
644
4fc5eab77197 Use connection_call_auth_cb in one more place
Myhailo Danylenko <isbear@ukrpost.net>
parents: 624
diff changeset
   695
    } else {
518
cdd6a0c5b439 Went 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
        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
   697
    }
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
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
    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
   700
        LmCallback *cb = connection->auth_cb;
143
92193c23b0c7 2006-05-26 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 140
diff changeset
   701
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   702
        connection->auth_cb = NULL;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   703
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   704
        if (cb->func) {
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   705
            (* ((LmResultFunction) cb->func)) (connection,
644
4fc5eab77197 Use connection_call_auth_cb in one more place
Myhailo Danylenko <isbear@ukrpost.net>
parents: 624
diff changeset
   706
                                               success,
518
cdd6a0c5b439 Went 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
                                               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
   708
        }
143
92193c23b0c7 2006-05-26 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 140
diff changeset
   709
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   710
        _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
   711
    }
644
4fc5eab77197 Use connection_call_auth_cb in one more place
Myhailo Danylenko <isbear@ukrpost.net>
parents: 624
diff changeset
   712
}
4fc5eab77197 Use connection_call_auth_cb in one more place
Myhailo Danylenko <isbear@ukrpost.net>
parents: 624
diff changeset
   713
4fc5eab77197 Use connection_call_auth_cb in one more place
Myhailo Danylenko <isbear@ukrpost.net>
parents: 624
diff changeset
   714
static LmHandlerResult
4fc5eab77197 Use connection_call_auth_cb in one more place
Myhailo Danylenko <isbear@ukrpost.net>
parents: 624
diff changeset
   715
connection_auth_reply (LmMessageHandler *handler,
4fc5eab77197 Use connection_call_auth_cb in one more place
Myhailo Danylenko <isbear@ukrpost.net>
parents: 624
diff changeset
   716
                       LmConnection     *connection,
4fc5eab77197 Use connection_call_auth_cb in one more place
Myhailo Danylenko <isbear@ukrpost.net>
parents: 624
diff changeset
   717
                       LmMessage        *m,
4fc5eab77197 Use connection_call_auth_cb in one more place
Myhailo Danylenko <isbear@ukrpost.net>
parents: 624
diff changeset
   718
                       gpointer          user_data)
4fc5eab77197 Use connection_call_auth_cb in one more place
Myhailo Danylenko <isbear@ukrpost.net>
parents: 624
diff changeset
   719
{
4fc5eab77197 Use connection_call_auth_cb in one more place
Myhailo Danylenko <isbear@ukrpost.net>
parents: 624
diff changeset
   720
    LmMessageSubType type;
4fc5eab77197 Use connection_call_auth_cb in one more place
Myhailo Danylenko <isbear@ukrpost.net>
parents: 624
diff changeset
   721
    g_return_val_if_fail (connection != NULL,
4fc5eab77197 Use connection_call_auth_cb in one more place
Myhailo Danylenko <isbear@ukrpost.net>
parents: 624
diff changeset
   722
                          LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS);
4fc5eab77197 Use connection_call_auth_cb in one more place
Myhailo Danylenko <isbear@ukrpost.net>
parents: 624
diff changeset
   723
4fc5eab77197 Use connection_call_auth_cb in one more place
Myhailo Danylenko <isbear@ukrpost.net>
parents: 624
diff changeset
   724
    type = lm_message_get_sub_type (m);
4fc5eab77197 Use connection_call_auth_cb in one more place
Myhailo Danylenko <isbear@ukrpost.net>
parents: 624
diff changeset
   725
    connection_call_auth_cb (connection, type == LM_MESSAGE_SUB_TYPE_RESULT);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   726
518
cdd6a0c5b439 Went 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
    return LM_HANDLER_RESULT_REMOVE_MESSAGE;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   728
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   729
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   730
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
   731
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
   732
_lm_connection_starttls_cb (LmMessageHandler *handler,
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   733
                            LmConnection     *connection,
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   734
                            LmMessage        *message,
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   735
                            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
   736
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   737
    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
   738
        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
   739
        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
   740
    } 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
   741
        connection_do_close (connection);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   742
        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
   743
                                      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
   744
    }
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
   745
518
cdd6a0c5b439 Went 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
    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
   747
}
02b814ccc535 Register starttls handler at the proper moment, when the stream is received.
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 317
diff changeset
   748
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   749
static void
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   750
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
   751
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   752
    /* 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
   753
     * 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
   754
    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
   755
        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
   756
        !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
   757
        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
   758
            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
   759
                                    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
   760
        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
   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
                                                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
   763
                                                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
   764
    }
450
548b5e3d9bea Refactored some of the SSL code in LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 449
diff changeset
   765
}
548b5e3d9bea Refactored some of the SSL code in LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 449
diff changeset
   766
548b5e3d9bea Refactored some of the SSL code in LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 449
diff changeset
   767
static void
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   768
connection_stream_received (LmConnection *connection, LmMessage *m)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   769
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   770
    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
   771
    const char *xmpp_version;
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   772
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   773
    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
   774
    g_return_if_fail (m != NULL);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   775
518
cdd6a0c5b439 Went 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
    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
   777
                                                                     "id"));
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
   778
518
cdd6a0c5b439 Went 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
    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
   780
    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
   781
        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
   782
                    connection->stream_id);
220
f6b9482ae89e Some style fixes to the SASL patch.
Mikael Hallendal <micke@imendio.com>
parents: 219
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
        connection->use_sasl = TRUE;
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   785
518
cdd6a0c5b439 Went 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
        /* 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
   787
         * 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
   788
        if (!connection->sasl) {
541
9c315096fa5a Minor style fixes
Mikael Hallendal <micke@imendio.com>
parents: 540
diff changeset
   789
            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
   790
        }
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
   791
518
cdd6a0c5b439 Went 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
        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
   793
    } else {
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   794
        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
   795
                    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
   796
    }
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   797
518
cdd6a0c5b439 Went 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
    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
   799
        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
   800
    }
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   801
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   802
    /* 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
   803
    result = TRUE;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   804
518
cdd6a0c5b439 Went 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
    connection_start_keep_alive (connection);
90
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
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
    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
   808
        LmCallback *cb = connection->open_cb;
143
92193c23b0c7 2006-05-26 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 140
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->open_cb = NULL;
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
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 (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
   813
            (* ((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
   814
                                               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
   815
        }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   816
        _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
   817
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   818
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   819
306
d466fc30829f Added disconnect error for resource conflict. Fixes LM-55.
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 297
diff changeset
   820
static void
d466fc30829f Added disconnect error for resource conflict. Fixes LM-55.
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 297
diff changeset
   821
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
   822
{
534
19327ccf6099 Minor style fix
Mikael Hallendal <micke@imendio.com>
parents: 533
diff changeset
   823
    LmMessageNode      *node;
19327ccf6099 Minor style fix
Mikael Hallendal <micke@imendio.com>
parents: 533
diff changeset
   824
    LmMessageNode      *reason_node;
19327ccf6099 Minor style fix
Mikael Hallendal <micke@imendio.com>
parents: 533
diff changeset
   825
    LmDisconnectReason  reason;
306
d466fc30829f Added disconnect error for resource conflict. Fixes LM-55.
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 297
diff changeset
   826
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   827
    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
   828
    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
   829
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   830
    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
   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
    /* 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
   833
    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
   834
    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
   835
        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
   836
        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
   837
        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
   838
    }
306
d466fc30829f Added disconnect error for resource conflict. Fixes LM-55.
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 297
diff changeset
   839
518
cdd6a0c5b439 Went 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
    /* 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
   841
    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
   842
    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
   843
        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
   844
        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
   845
        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
   846
    }
306
d466fc30829f Added disconnect error for resource conflict. Fixes LM-55.
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 297
diff changeset
   847
518
cdd6a0c5b439 Went 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: 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
   849
    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
   850
    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
   851
                                                                     "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
   852
    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
   853
    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
   854
}
d466fc30829f Added disconnect error for resource conflict. Fixes LM-55.
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 297
diff changeset
   855
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   856
static gint
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   857
connection_handler_compare_func (HandlerData *a, HandlerData *b)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   858
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   859
    return b->priority - a->priority;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   860
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   861
256
2266e56746ed Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 255
diff changeset
   862
static void
2266e56746ed Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 255
diff changeset
   863
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
   864
                              LmDisconnectReason  reason)
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   865
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   866
    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
   867
        LmCallback *cb = connection->disconnect_cb;
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   868
518
cdd6a0c5b439 Went 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
        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
   870
        (* ((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
   871
                                               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
   872
                                               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
   873
        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
   874
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   875
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   876
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   877
static void
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   878
connection_incoming_data (LmOldSocket  *socket,
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   879
                          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
   880
                          LmConnection *connection)
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   881
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   882
    lm_parser_parse (connection->parser, buf);
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   883
}
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   884
256
2266e56746ed Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 255
diff changeset
   885
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
   886
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
   887
                             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
   888
                             LmConnection       *connection)
256
2266e56746ed Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 255
diff changeset
   889
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   890
    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
   891
    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
   892
}
2266e56746ed Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 255
diff changeset
   893
2266e56746ed Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 255
diff changeset
   894
static void
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   895
connection_socket_connect_cb (LmOldSocket  *socket,
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   896
                              gboolean      result,
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   897
                              LmConnection *connection)
256
2266e56746ed Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 255
diff changeset
   898
{
735
7ae46452fb10 Always signal a disconnect after connection_do_close()
Frank Zschockelt <lm@freakysoft.de>
parents: 690
diff changeset
   899
    /* FIXME: Set up according to XMPP 1.0 specification */
7ae46452fb10 Always signal a disconnect after connection_do_close()
Frank Zschockelt <lm@freakysoft.de>
parents: 690
diff changeset
   900
    /*        StartTLS and the like */
7ae46452fb10 Always signal a disconnect after connection_do_close()
Frank Zschockelt <lm@freakysoft.de>
parents: 690
diff changeset
   901
    if (result == TRUE && !connection_send (connection,
7ae46452fb10 Always signal a disconnect after connection_do_close()
Frank Zschockelt <lm@freakysoft.de>
parents: 690
diff changeset
   902
                          "<?xml version='1.0' encoding='UTF-8'?>", -1,
7ae46452fb10 Always signal a disconnect after connection_do_close()
Frank Zschockelt <lm@freakysoft.de>
parents: 690
diff changeset
   903
                          NULL)) {
7ae46452fb10 Always signal a disconnect after connection_do_close()
Frank Zschockelt <lm@freakysoft.de>
parents: 690
diff changeset
   904
        lm_verbose ("Failed to send xml version and encoding\n");
7ae46452fb10 Always signal a disconnect after connection_do_close()
Frank Zschockelt <lm@freakysoft.de>
parents: 690
diff changeset
   905
        result = FALSE;
7ae46452fb10 Always signal a disconnect after connection_do_close()
Frank Zschockelt <lm@freakysoft.de>
parents: 690
diff changeset
   906
    }
7ae46452fb10 Always signal a disconnect after connection_do_close()
Frank Zschockelt <lm@freakysoft.de>
parents: 690
diff changeset
   907
518
cdd6a0c5b439 Went 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
    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
   909
        connection_do_close (connection);
256
2266e56746ed Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 255
diff changeset
   910
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   911
        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
   912
            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
   913
518
cdd6a0c5b439 Went 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
            connection->open_cb = NULL;
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   915
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   916
            (* ((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
   917
                                               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
   918
            _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
   919
        }
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   920
735
7ae46452fb10 Always signal a disconnect after connection_do_close()
Frank Zschockelt <lm@freakysoft.de>
parents: 690
diff changeset
   921
    } else {
7ae46452fb10 Always signal a disconnect after connection_do_close()
Frank Zschockelt <lm@freakysoft.de>
parents: 690
diff changeset
   922
        connection_send_stream_header (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
    }
256
2266e56746ed Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 255
diff changeset
   924
}
2266e56746ed Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 255
diff changeset
   925
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
   926
static gboolean
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   927
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
   928
{
518
cdd6a0c5b439 Went 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
    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
   930
    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
   931
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   932
    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
   933
        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
   934
        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
   935
            *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
   936
        } 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
   937
            *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
   938
        }
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
        return TRUE;
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   941
    }
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   942
518
cdd6a0c5b439 Went 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
    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
   944
}
df2655dbe873 Make LmConnection accept not having a server set as long as JID is set.
Mikael Hallendal <micke@imendio.com>
parents: 244
diff changeset
   945
248
09a3e0e55ab8 Refactored sending of the stream header.
Mikael Hallendal <micke@imendio.com>
parents: 247
diff changeset
   946
static void
09a3e0e55ab8 Refactored sending of the stream header.
Mikael Hallendal <micke@imendio.com>
parents: 247
diff changeset
   947
connection_send_stream_header (LmConnection *connection)
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   948
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   949
    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
   950
    gchar     *server_from_jid;
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   951
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   952
    lm_verbose ("Sending stream header\n");
248
09a3e0e55ab8 Refactored sending of the stream header.
Mikael Hallendal <micke@imendio.com>
parents: 247
diff changeset
   953
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   954
    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
   955
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   956
    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
   957
    lm_message_node_set_attributes (m->node,
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
   958
                                    "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
   959
                                    "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
   960
                                    "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
   961
                                    "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
   962
                                    NULL);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
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
    g_free (server_from_jid);
248
09a3e0e55ab8 Refactored sending of the stream header.
Mikael Hallendal <micke@imendio.com>
parents: 247
diff changeset
   965
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   966
    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
   967
        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
   968
        connection_do_close (connection);
735
7ae46452fb10 Always signal a disconnect after connection_do_close()
Frank Zschockelt <lm@freakysoft.de>
parents: 690
diff changeset
   969
        connection_signal_disconnect (connection, LM_DISCONNECT_REASON_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
   970
    }
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
    lm_message_unref (m);
248
09a3e0e55ab8 Refactored sending of the stream header.
Mikael Hallendal <micke@imendio.com>
parents: 247
diff changeset
   973
}
09a3e0e55ab8 Refactored sending of the stream header.
Mikael Hallendal <micke@imendio.com>
parents: 247
diff changeset
   974
500
915cd386918e Added _lm_connection_get_context as internal function.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   975
GMainContext *
915cd386918e Added _lm_connection_get_context as internal function.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   976
_lm_connection_get_context (LmConnection *conn)
915cd386918e Added _lm_connection_get_context as internal function.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   977
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   978
    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
   979
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   980
    return conn->context;
500
915cd386918e Added _lm_connection_get_context as internal function.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   981
}
915cd386918e Added _lm_connection_get_context as internal function.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   982
501
5f71592beac8 Added _lm_connection_get_server that returns the server string.
Mikael Hallendal <micke@imendio.com>
parents: 500
diff changeset
   983
gchar *
5f71592beac8 Added _lm_connection_get_server that returns the server string.
Mikael Hallendal <micke@imendio.com>
parents: 500
diff changeset
   984
_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
   985
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   986
    gchar *server;
501
5f71592beac8 Added _lm_connection_get_server that returns the server string.
Mikael Hallendal <micke@imendio.com>
parents: 500
diff changeset
   987
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   988
    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
   989
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   990
    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
   991
        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
   992
    }
501
5f71592beac8 Added _lm_connection_get_server that returns the server string.
Mikael Hallendal <micke@imendio.com>
parents: 500
diff changeset
   993
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   994
    return server;
501
5f71592beac8 Added _lm_connection_get_server that returns the server string.
Mikael Hallendal <micke@imendio.com>
parents: 500
diff changeset
   995
}
5f71592beac8 Added _lm_connection_get_server that returns the server string.
Mikael Hallendal <micke@imendio.com>
parents: 500
diff changeset
   996
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
   997
static LmHandlerResult
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
   998
connection_bind_reply (LmMessageHandler *handler,
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   999
                       LmConnection     *connection,
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
  1000
                       LmMessage        *message,
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
  1001
                       gpointer          user_data)
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1002
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1003
    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
  1004
    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
  1005
    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
  1006
    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
  1007
    LmMessageSubType  type;
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1008
518
cdd6a0c5b439 Went 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
    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
  1010
    if (type == LM_MESSAGE_SUB_TYPE_ERROR) {
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1011
        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
  1012
               "%s: error while binding to resource\n", G_STRFUNC);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1013
518
cdd6a0c5b439 Went 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
        connection_call_auth_cb (connection, FALSE);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
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
        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
  1017
    }
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1018
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1019
    /* 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
  1020
    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
  1021
    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
  1022
        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
  1023
        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
  1024
            (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
  1025
    }
297
f65eee8ec802 Support for returning effective JID, possibly changed by the server.
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 294
diff changeset
  1026
f65eee8ec802 Support for returning effective JID, possibly changed by the server.
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 294
diff changeset
  1027
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1028
    m = lm_message_new_with_sub_type (NULL,
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1029
                                      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
  1030
                                      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
  1031
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1032
    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
  1033
    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
  1034
                                    "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
  1035
                                    NULL);
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1036
518
cdd6a0c5b439 Went 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
    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
  1038
    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
  1039
    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
  1040
        connection_do_close (connection);
735
7ae46452fb10 Always signal a disconnect after connection_do_close()
Frank Zschockelt <lm@freakysoft.de>
parents: 690
diff changeset
  1041
        connection_signal_disconnect (connection, LM_DISCONNECT_REASON_ERROR);
7ae46452fb10 Always signal a disconnect after connection_do_close()
Frank Zschockelt <lm@freakysoft.de>
parents: 690
diff changeset
  1042
    } else {
7ae46452fb10 Always signal a disconnect after connection_do_close()
Frank Zschockelt <lm@freakysoft.de>
parents: 690
diff changeset
  1043
        /* We may finally tell the client they're authorized */
7ae46452fb10 Always signal a disconnect after connection_do_close()
Frank Zschockelt <lm@freakysoft.de>
parents: 690
diff changeset
  1044
        connection_call_auth_cb (connection, TRUE);
518
cdd6a0c5b439 Went 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
    }
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
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;
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1048
}
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1049
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1050
static LmHandlerResult
256
2266e56746ed Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 255
diff changeset
  1051
connection_features_cb (LmMessageHandler *handler,
412
d355b566f141 Fixed indentation
Mikael Hallendal <micke@imendio.com>
parents: 411
diff changeset
  1052
                        LmConnection     *connection,
d355b566f141 Fixed indentation
Mikael Hallendal <micke@imendio.com>
parents: 411
diff changeset
  1053
                        LmMessage        *message,
d355b566f141 Fixed indentation
Mikael Hallendal <micke@imendio.com>
parents: 411
diff changeset
  1054
                        gpointer          user_data)
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1055
{
518
cdd6a0c5b439 Went 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
    LmMessageNode *bind_node;
530
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 529
diff changeset
  1057
    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
  1058
    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
  1059
    LmMessageNode *sasl_mechanisms;
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1060
518
cdd6a0c5b439 Went 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
    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
  1062
    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
  1063
        if (starttls_node) {
530
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 529
diff changeset
  1064
            LmMessage *msg;
274
c32a7011e435 Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents: 271
diff changeset
  1065
518
cdd6a0c5b439 Went 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
            msg = lm_message_new (NULL, LM_MESSAGE_TYPE_STARTTLS);
274
c32a7011e435 Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents: 271
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
            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
  1069
                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
  1070
                "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
  1071
                NULL);
274
c32a7011e435 Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents: 271
diff changeset
  1072
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1073
            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
  1074
            lm_message_unref (msg);
274
c32a7011e435 Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents: 271
diff changeset
  1075
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1076
            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
  1077
        } 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
  1078
                   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
  1079
            /* 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
  1080
             * the place to scream. */
274
c32a7011e435 Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents: 271
diff changeset
  1081
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1082
            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
  1083
                   "%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
  1084
            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
  1085
            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
  1086
                                          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
  1087
            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
  1088
        }
cdd6a0c5b439 Went 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
    }
274
c32a7011e435 Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents: 271
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
    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
  1092
    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
  1093
        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
  1094
        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
  1095
        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
  1096
        int               result;
223
b343ed8b3fea More style fixes to the SASL patch
Mikael Hallendal <micke@imendio.com>
parents: 222
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
        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
  1099
        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
  1100
            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
  1101
        }
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
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
        bind_msg = lm_message_new_with_sub_type (NULL,
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1104
                                                 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
  1105
                                                 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
  1106
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1107
        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
  1108
                                               "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
  1109
        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
  1110
                                        "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
  1111
                                        NULL);
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1112
518
cdd6a0c5b439 Went 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
        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
  1114
                                   connection->resource);
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1115
518
cdd6a0c5b439 Went 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
        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
  1117
                                               NULL, NULL);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1118
        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
  1119
                                                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
  1120
        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
  1121
        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
  1122
518
cdd6a0c5b439 Went 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
        if (result < 0) {
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1124
            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
  1125
                   "%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
  1126
            connection_do_close (connection);
735
7ae46452fb10 Always signal a disconnect after connection_do_close()
Frank Zschockelt <lm@freakysoft.de>
parents: 690
diff changeset
  1127
            connection_signal_disconnect (connection,
7ae46452fb10 Always signal a disconnect after connection_do_close()
Frank Zschockelt <lm@freakysoft.de>
parents: 690
diff changeset
  1128
                                          LM_DISCONNECT_REASON_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
  1129
        }
cdd6a0c5b439 Went 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
    }
220
f6b9482ae89e Some style fixes to the SASL patch.
Mikael Hallendal <micke@imendio.com>
parents: 219
diff changeset
  1131
619
a3facd81de25 Revert "Code looks for an auth element below the returned streams:feature"
Frank Zschockelt <lm@freakysoft.de>
parents: 614
diff changeset
  1132
    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
  1133
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1134
    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
  1135
    if (connection->use_sasl && old_auth != NULL && sasl_mechanisms == NULL) {
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1136
        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
  1137
               "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
  1138
        /* 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
  1139
         * 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
  1140
518
cdd6a0c5b439 Went 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
        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
  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
        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
  1144
            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
  1145
                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
  1146
                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
  1147
                                     &error);
332
6b6ad42cd508 Support obsolete XEP-0078 (old-style jabber auth for XMPP1.0).
Senko Rasic <senko@phyrexia.lan>
parents: 329
diff changeset
  1148
518
cdd6a0c5b439 Went 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
                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
  1150
                    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
  1151
                }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1152
            }
332
6b6ad42cd508 Support obsolete XEP-0078 (old-style jabber auth for XMPP1.0).
Senko Rasic <senko@phyrexia.lan>
parents: 329
diff changeset
  1153
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1154
            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
  1155
            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
  1156
        }
cdd6a0c5b439 Went 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
    }
332
6b6ad42cd508 Support obsolete XEP-0078 (old-style jabber auth for XMPP1.0).
Senko Rasic <senko@phyrexia.lan>
parents: 329
diff changeset
  1158
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1159
    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
  1160
}
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1161
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1162
/**
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1163
 * lm_connection_new:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1164
 * @server: The hostname to the server for the connection.
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1165
 *
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1166
 * Creates a new closed connection. To open the connection call
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1167
 * 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
  1168
 *
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1169
 * Return value: A newly created LmConnection, should be unreffed with lm_connection_unref().
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1170
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1171
LmConnection *
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1172
lm_connection_new (const gchar *server)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1173
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1174
    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
  1175
    gint          i;
422
1c00df7a8b11 Depend on GObject and initialize GType
Mikael Hallendal <micke@imendio.com>
parents: 421
diff changeset
  1176
648
b29eecd0ac08 Disable g_type_init for glib >= 2.35
Frank Zschockelt <lm@freakysoft.de>
parents: 644
diff changeset
  1177
#if !GLIB_CHECK_VERSION(2, 35, 0)
518
cdd6a0c5b439 Went 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_type_init (); /* Ensure that the GLib type library is initialized */
648
b29eecd0ac08 Disable g_type_init for glib >= 2.35
Frank Zschockelt <lm@freakysoft.de>
parents: 644
diff changeset
  1179
#endif
518
cdd6a0c5b439 Went 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
    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
  1181
    _lm_sock_library_init ();
140
103227122f45 2006-04-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 137
diff changeset
  1182
518
cdd6a0c5b439 Went 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 = g_slice_new0 (LmConnection);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1184
518
cdd6a0c5b439 Went 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
    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
  1186
        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
  1187
    }
82
a32b54e654e2 2004-03-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 80
diff changeset
  1188
532
c917a1900d5c Style fix in lm_connection_new
Mikael Hallendal <micke@imendio.com>
parents: 531
diff changeset
  1189
    connection->port        = LM_CONNECTION_DEFAULT_PORT;
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1190
    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
  1191
                                                          connection);
532
c917a1900d5c Style fix in lm_connection_new
Mikael Hallendal <micke@imendio.com>
parents: 531
diff changeset
  1192
    connection->state       = LM_CONNECTION_STATE_CLOSED;
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
    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
  1195
                                                     g_str_equal,
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1196
                                                     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
  1197
                                                     (GDestroyNotify) lm_message_handler_unref);
532
c917a1900d5c Style fix in lm_connection_new
Mikael Hallendal <micke@imendio.com>
parents: 531
diff changeset
  1198
    connection->ref_count   = 1;
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1199
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1200
    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
  1201
        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
  1202
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1203
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1204
    connection->parser = lm_parser_new
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1205
        ((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
  1206
         connection, NULL);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1207
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1208
    return connection;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1209
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1210
82
a32b54e654e2 2004-03-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 80
diff changeset
  1211
/**
a32b54e654e2 2004-03-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 80
diff changeset
  1212
 * lm_connection_new_with_context:
a32b54e654e2 2004-03-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 80
diff changeset
  1213
 * @server: The hostname to the server for the connection.
a32b54e654e2 2004-03-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 80
diff changeset
  1214
 * @context: The context this connection should be running in.
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1215
 *
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1216
 * 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
  1217
 * 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
  1218
 * before calling #lm_connection_open.
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1219
 *
82
a32b54e654e2 2004-03-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 80
diff changeset
  1220
 * 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
  1221
 **/
a32b54e654e2 2004-03-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 80
diff changeset
  1222
LmConnection *
a32b54e654e2 2004-03-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 80
diff changeset
  1223
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
  1224
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1225
    LmConnection *connection;
82
a32b54e654e2 2004-03-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 80
diff changeset
  1226
518
cdd6a0c5b439 Went 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 = 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
  1228
    connection->context = context;
82
a32b54e654e2 2004-03-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 80
diff changeset
  1229
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1230
    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
  1231
        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
  1232
    }
82
a32b54e654e2 2004-03-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 80
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;
82
a32b54e654e2 2004-03-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 80
diff changeset
  1235
}
63
7b8d0db459ff 2004-01-05 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 62
diff changeset
  1236
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1237
/**
62
39b83ccd70ff 2003-12-27 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 61
diff changeset
  1238
 * lm_connection_open:
39b83ccd70ff 2003-12-27 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 61
diff changeset
  1239
 * @connection: #LmConnection to open
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1240
 * @function: Callback function that will be called when the connection is open.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1241
 * @user_data: User data that will be passed to @function.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1242
 * @notify: Function for freeing that user_data, can be NULL.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1243
 * @error: location to store error, or %NULL
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1244
 *
62
39b83ccd70ff 2003-12-27 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 61
diff changeset
  1245
 * 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
  1246
 *
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1247
 * Return value: #TRUE if everything went fine, otherwise #FALSE.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1248
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1249
gboolean
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1250
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
  1251
                    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
  1252
                    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
  1253
                    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
  1254
                    GError           **error)
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
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
    g_return_val_if_fail (connection != NULL, FALSE);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1257
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1258
    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
  1259
                                                  user_data, notify);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1260
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1261
    return connection_do_open (connection, error);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1262
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1263
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1264
/**
62
39b83ccd70ff 2003-12-27 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 61
diff changeset
  1265
 * lm_connection_open_and_block:
39b83ccd70ff 2003-12-27 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 61
diff changeset
  1266
 * @connection: an #LmConnection to open
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1267
 * @error: location to store error, or %NULL
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1268
 *
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1269
 * Opens @connection and waits until the stream is setup.
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1270
 *
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1271
 * Return value: #TRUE if no errors where encountered during opening and stream setup successfully, #FALSE otherwise.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1272
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1273
gboolean
62
39b83ccd70ff 2003-12-27 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 61
diff changeset
  1274
lm_connection_open_and_block (LmConnection *connection, GError **error)
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1275
{
543
fe1b614022fb Removed unused variable in lm_connection_open_and_block
Mikael Hallendal <micke@imendio.com>
parents: 542
diff changeset
  1276
    gboolean result;
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1277
518
cdd6a0c5b439 Went 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
    g_return_val_if_fail (connection != NULL, FALSE);
57
6b168a8917f7 2003-12-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 56
diff changeset
  1279
518
cdd6a0c5b439 Went 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
    connection->open_cb = NULL;
140
103227122f45 2006-04-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 137
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
    result = connection_do_open (connection, error);
63
7b8d0db459ff 2004-01-05 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 62
diff changeset
  1283
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1284
    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
  1285
        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
  1286
    }
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1287
543
fe1b614022fb Removed unused variable in lm_connection_open_and_block
Mikael Hallendal <micke@imendio.com>
parents: 542
diff changeset
  1288
    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
  1289
        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
  1290
            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
  1291
        } 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
  1292
            /* 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
  1293
            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
  1294
        }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1295
    }
64
dd835d5cee71 2004-01-06 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 63
diff changeset
  1296
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1297
    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
  1298
        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
  1299
        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
  1300
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1301
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1302
    /* 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
  1303
    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
  1304
                 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
  1305
                 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
  1306
                 "Opening the connection failed");
132
8c9c1629f691 2006-03-20 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 130
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
    return FALSE;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1309
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1310
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1311
/**
59
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  1312
 * lm_connection_cancel_open:
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  1313
 * @connection: an #LmConnection to cancel opening on
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  1314
 *
91
d51b8e4f43d9 2004-08-27 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 90
diff changeset
  1315
 * 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
  1316
 **/
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  1317
void
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  1318
lm_connection_cancel_open (LmConnection *connection)
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  1319
{
518
cdd6a0c5b439 Went 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
    g_return_if_fail (connection != NULL);
59
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  1321
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1322
    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
  1323
        _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
  1324
        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
  1325
    }
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
  1326
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1327
    connection->cancel_open = TRUE;
271
52ea4e0b897a Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents: 256
diff changeset
  1328
518
cdd6a0c5b439 Went 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
    lm_old_socket_asyncns_cancel (connection->socket);
57
6b168a8917f7 2003-12-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 56
diff changeset
  1330
}
6b168a8917f7 2003-12-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 56
diff changeset
  1331
6b168a8917f7 2003-12-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 56
diff changeset
  1332
/**
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1333
 * lm_connection_close:
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1334
 * @connection: #LmConnection to close
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1335
 * @error: location to store error, or %NULL
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1336
 *
56
3bf928955fc5 2003-11-20 Ross Burton <ross@burtonini.com>
hallski <hallski>
parents: 55
diff changeset
  1337
 * 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
  1338
 *
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1339
 * Return value: Returns #TRUE if no errors where detected, otherwise #FALSE.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1340
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1341
gboolean
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
  1342
lm_connection_close (LmConnection *connection, GError **error)
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1343
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1344
    gboolean no_errors = TRUE;
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
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_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
  1347
cdd6a0c5b439 Went 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->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
  1349
        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
  1350
    }
156
8c054d9e98b8 2006-06-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 155
diff changeset
  1351
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1352
    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
  1353
        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
  1354
                     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
  1355
                     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
  1356
                     "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
  1357
        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
  1358
    }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1359
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1360
    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
  1361
                connection->server, connection->port);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1362
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1363
    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
  1364
        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
  1365
            no_errors = FALSE;
503
c7c1722ec2db Fixed a crash when lm_connection_close was called.
Mikael Hallendal <micke@imendio.com>
parents: 501
diff changeset
  1366
        }
271
52ea4e0b897a Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents: 256
diff changeset
  1367
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1368
        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
  1369
    }
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1370
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1371
    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
  1372
    connection_signal_disconnect (connection, LM_DISCONNECT_REASON_OK);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1373
518
cdd6a0c5b439 Went 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
    return no_errors;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1375
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1376
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1377
static void
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
  1378
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
  1379
                               LmConnection *connection,
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
  1380
                               gboolean      success,
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
  1381
                               const gchar  *reason)
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1382
{
518
cdd6a0c5b439 Went 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
    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
  1384
        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
  1385
        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
  1386
        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
  1387
    }
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
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
    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
  1390
}
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1391
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1392
/**
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1393
 * lm_connection_authenticate:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1394
 * @connection: #LmConnection to authenticate.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1395
 * @username: Username used to authenticate.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1396
 * @password: Password corresponding to @username.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1397
 * @resource: Resource used for this connection.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1398
 * @function: Callback called when authentication is finished.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1399
 * @user_data: Userdata passed to @function when called.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1400
 * @notify: Destroy function to free the memory used by @user_data, can be NULL.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1401
 * @error: location to store error, or %NULL
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1402
 *
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1403
 * 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
  1404
 *
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1405
 * Return value: #TRUE if no errors where detected while sending the authentication message, #FALSE otherwise.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1406
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1407
gboolean
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1408
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
  1409
                            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
  1410
                            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
  1411
                            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
  1412
                            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
  1413
                            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
  1414
                            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
  1415
                            GError           **error)
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1416
{
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
  1417
    LmAuthParameters *auth_params;
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
  1418
    gboolean          ret_val;
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1419
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1420
    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
  1421
    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
  1422
    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
  1423
    g_return_val_if_fail (resource != NULL, FALSE);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1424
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
  1425
    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
  1426
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1427
    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
  1428
        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
  1429
                     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
  1430
                     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
  1431
                     "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
  1432
        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
  1433
    }
59
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  1434
518
cdd6a0c5b439 Went 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
    connection->state = LM_CONNECTION_STATE_AUTHENTICATING;
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1436
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1437
    connection->auth_cb = _lm_utils_new_callback (function,
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1438
                                                  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
  1439
                                                  notify);
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
  1440
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
  1441
    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
  1442
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1443
    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
  1444
                                                 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
  1445
533
c45243823756 Added some TODO items and minor style fixes
Mikael Hallendal <micke@imendio.com>
parents: 532
diff changeset
  1446
    /* 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
  1447
     *       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
  1448
    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
  1449
        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
  1450
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
  1451
        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
  1452
            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
  1453
        }
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
  1454
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
  1455
        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
  1456
                              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
  1457
        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
  1458
518
cdd6a0c5b439 Went 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
        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
  1460
            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
  1461
                                    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
  1462
        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
  1463
                                                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
  1464
                                                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
  1465
                                                LM_HANDLER_PRIORITY_FIRST);
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
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
        ret_val = TRUE;
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
  1468
    } else {
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
  1469
        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
  1470
    }
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1471
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
  1472
    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
  1473
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
  1474
    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
  1475
}
6b6ad42cd508 Support obsolete XEP-0078 (old-style jabber auth for XMPP1.0).
Senko Rasic <senko@phyrexia.lan>
parents: 329
diff changeset
  1476
415
14ff0a255a86 Moved _lm_connection_old_auth from public header file.
Mikael Hallendal <micke@imendio.com>
parents: 413
diff changeset
  1477
static gboolean
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
  1478
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
  1479
                     LmAuthParameters  *auth_params,
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
  1480
                     GError           **error)
332
6b6ad42cd508 Support obsolete XEP-0078 (old-style jabber auth for XMPP1.0).
Senko Rasic <senko@phyrexia.lan>
parents: 329
diff changeset
  1481
{
518
cdd6a0c5b439 Went 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
    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
  1483
    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
  1484
    gboolean          result;
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1485
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
  1486
    m = connection_create_auth_req_msg (auth_params);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1487
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1488
    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
  1489
                                      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
  1490
                                      (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
  1491
    result = lm_connection_send_with_reply (connection, m, handler, error);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1492
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1493
    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
  1494
    lm_message_unref (m);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1495
518
cdd6a0c5b439 Went 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
    return result;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1497
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1498
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1499
/**
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1500
 * lm_connection_authenticate_and_block:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1501
 * @connection: an #LmConnection
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1502
 * @username: Username used to authenticate.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1503
 * @password: Password corresponding to @username.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1504
 * @resource: Resource used for this connection.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1505
 * @error: location to store error, or %NULL
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1506
 *
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1507
 * 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
  1508
 *
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1509
 * Return value: #TRUE if no errors where detected and authentication was successful. #FALSE otherwise.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1510
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1511
gboolean
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1512
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
  1513
                                      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
  1514
                                      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
  1515
                                      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
  1516
                                      GError       **error)
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1517
{
530
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 529
diff changeset
  1518
    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
  1519
518
cdd6a0c5b439 Went 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
    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
  1521
                                         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
  1522
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1523
    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
  1524
        return result;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1525
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1526
    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
  1527
        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
  1528
            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
  1529
        } 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
  1530
            /* 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
  1531
            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
  1532
        }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1533
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1534
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1535
    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
  1536
    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
  1537
        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
  1538
        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
  1539
    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
  1540
        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
  1541
                     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
  1542
                     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
  1543
                     "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
  1544
        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
  1545
        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
  1546
    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
  1547
        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
  1548
        break;
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1549
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1550
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1551
    return FALSE;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1552
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1553
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1554
/**
394
03933ba2fb40 Added lm_connection_get_keep_alive.
Mikael Hallendal <micke@imendio.com>
parents: 345
diff changeset
  1555
 * lm_connection_get_keep_alive_rate:
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1556
 * @connection: an #LmConnection
394
03933ba2fb40 Added lm_connection_get_keep_alive.
Mikael Hallendal <micke@imendio.com>
parents: 345
diff changeset
  1557
 *
03933ba2fb40 Added lm_connection_get_keep_alive.
Mikael Hallendal <micke@imendio.com>
parents: 345
diff changeset
  1558
 * 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
  1559
 *
03933ba2fb40 Added lm_connection_get_keep_alive.
Mikael Hallendal <micke@imendio.com>
parents: 345
diff changeset
  1560
 * Since 1.3.5
03933ba2fb40 Added lm_connection_get_keep_alive.
Mikael Hallendal <micke@imendio.com>
parents: 345
diff changeset
  1561
 **/
03933ba2fb40 Added lm_connection_get_keep_alive.
Mikael Hallendal <micke@imendio.com>
parents: 345
diff changeset
  1562
guint
03933ba2fb40 Added lm_connection_get_keep_alive.
Mikael Hallendal <micke@imendio.com>
parents: 345
diff changeset
  1563
lm_connection_get_keep_alive_rate (LmConnection *connection)
03933ba2fb40 Added lm_connection_get_keep_alive.
Mikael Hallendal <micke@imendio.com>
parents: 345
diff changeset
  1564
{
518
cdd6a0c5b439 Went 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
    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
  1566
518
cdd6a0c5b439 Went 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
    return connection->keep_alive_rate;
394
03933ba2fb40 Added lm_connection_get_keep_alive.
Mikael Hallendal <micke@imendio.com>
parents: 345
diff changeset
  1568
}
03933ba2fb40 Added lm_connection_get_keep_alive.
Mikael Hallendal <micke@imendio.com>
parents: 345
diff changeset
  1569
03933ba2fb40 Added lm_connection_get_keep_alive.
Mikael Hallendal <micke@imendio.com>
parents: 345
diff changeset
  1570
/**
90
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
  1571
 * lm_connection_set_keep_alive_rate:
394
03933ba2fb40 Added lm_connection_get_keep_alive.
Mikael Hallendal <micke@imendio.com>
parents: 345
diff changeset
  1572
 * @connection: an #LmConnection
90
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
  1573
 * @rate: Number of seconds between keep alive packages are sent.
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1574
 *
90
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
  1575
 * 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
  1576
 * A keep alive message is a single space character.
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
  1577
 **/
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
  1578
void
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
  1579
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
  1580
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1581
    g_return_if_fail (connection != NULL);
90
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
  1582
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1583
    connection_stop_keep_alive (connection);
90
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
  1584
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1585
    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
  1586
        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
  1587
    }
90
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
  1588
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1589
    connection->keep_alive_rate = rate;
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
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
    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
  1592
        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
  1593
    }
90
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
  1594
}
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
  1595
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
  1596
/**
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1597
 * lm_connection_is_open:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1598
 * @connection: #LmConnection to check if it is open.
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1599
 *
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1600
 * Check if the @connection is currently open.
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1601
 *
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1602
 * Return value: #TRUE if connection is open and #FALSE if it is closed.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1603
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1604
gboolean
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1605
lm_connection_is_open (LmConnection *connection)
50e230cf7818 Initial revision
hallski <hallski>
parents:
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_val_if_fail (connection != NULL, FALSE);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
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
    return connection->state >= LM_CONNECTION_STATE_OPEN;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1610
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1611
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1612
/**
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1613
 * lm_connection_is_authenticated:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1614
 * @connection: #LmConnection to check if it is authenticated
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1615
 *
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1616
 * Check if @connection is authenticated.
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1617
 *
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1618
 * Return value: #TRUE if connection is authenticated, #FALSE otherwise.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1619
 **/
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1620
gboolean
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1621
lm_connection_is_authenticated (LmConnection *connection)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1622
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1623
    g_return_val_if_fail (connection != NULL, FALSE);
66
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1624
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1625
    return connection->state >= LM_CONNECTION_STATE_AUTHENTICATED;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1626
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1627
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1628
/**
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1629
 * lm_connection_get_server:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1630
 * @connection: an #LmConnection
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1631
 *
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1632
 * Fetches the server address that @connection is using.
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1633
 *
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1634
 * Return value: the server address
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1635
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1636
const gchar *
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1637
lm_connection_get_server (LmConnection *connection)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1638
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1639
    g_return_val_if_fail (connection != NULL, NULL);
66
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1640
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1641
    return connection->server;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1642
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1643
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1644
/**
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1645
 * lm_connection_set_server:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1646
 * @connection: an #LmConnection
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1647
 * @server: Address of the server
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1648
 *
87
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
  1649
 * 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
  1650
 * can't be open while doing this.
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1651
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1652
void
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1653
lm_connection_set_server (LmConnection *connection, const gchar *server)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1654
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1655
    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
  1656
    g_return_if_fail (server != NULL);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1657
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1658
    if (lm_connection_is_open (connection)) {
614
773201ca404c Replaced every g_warning() with g_log()
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1659
        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
  1660
               "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
  1661
        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
  1662
    }
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1663
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1664
    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
  1665
    connection->server = _lm_utils_hostname_to_punycode (server);
87
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
  1666
}
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
  1667
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
  1668
/**
89
e756a937e540 2004-08-09 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 87
diff changeset
  1669
 * lm_connection_get_jid:
87
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
  1670
 * @connection: an #LmConnection
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1671
 *
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1672
 * Fetches the jid set for @connection is using.
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1673
 *
89
e756a937e540 2004-08-09 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 87
diff changeset
  1674
 * Return value: the jid
87
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
  1675
 **/
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
  1676
const gchar *
89
e756a937e540 2004-08-09 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 87
diff changeset
  1677
lm_connection_get_jid (LmConnection *connection)
87
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
  1678
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1679
    g_return_val_if_fail (connection != NULL, NULL);
87
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
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
    return connection->jid;
87
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
  1682
}
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
  1683
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
  1684
/**
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
  1685
 * 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
  1686
 * @connection: an #LmConnection
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1687
 *
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
  1688
 * 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
  1689
 * 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
  1690
 *
f65eee8ec802 Support for returning effective JID, possibly changed by the server.
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 294
diff changeset
  1691
 * 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
  1692
 **/
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
  1693
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
  1694
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
  1695
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1696
    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
  1697
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1698
    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
  1699
}
f65eee8ec802 Support for returning effective JID, possibly changed by the server.
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 294
diff changeset
  1700
f65eee8ec802 Support for returning effective JID, possibly changed by the server.
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 294
diff changeset
  1701
/**
89
e756a937e540 2004-08-09 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 87
diff changeset
  1702
 * lm_connection_set_jid:
87
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
  1703
 * @connection: an #LmConnection
89
e756a937e540 2004-08-09 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 87
diff changeset
  1704
 * @jid: JID to be used for @connection
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1705
 *
89
e756a937e540 2004-08-09 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 87
diff changeset
  1706
 * Sets the JID to be used for @connection.
87
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
  1707
 **/
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1708
void
89
e756a937e540 2004-08-09 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 87
diff changeset
  1709
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
  1710
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1711
    g_return_if_fail (connection != NULL);
87
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
  1712
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1713
    if (lm_connection_is_open (connection)) {
614
773201ca404c Replaced every g_warning() with g_log()
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1714
        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
  1715
                   "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
  1716
        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
  1717
    }
87
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
  1718
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1719
    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
  1720
    connection->jid = g_strdup (jid);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1721
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1722
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1723
/**
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1724
 * lm_connection_get_port:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1725
 * @connection: an #LmConnection
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1726
 *
56
3bf928955fc5 2003-11-20 Ross Burton <ross@burtonini.com>
hallski <hallski>
parents: 55
diff changeset
  1727
 * Fetches the port that @connection is using.
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1728
 *
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1729
 * Return value:
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1730
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1731
guint
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1732
lm_connection_get_port (LmConnection *connection)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1733
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1734
    g_return_val_if_fail (connection != NULL, 0);
66
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1735
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1736
    return connection->port;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1737
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1738
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1739
/**
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1740
 * lm_connection_set_port:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1741
 * @connection: an #LmConnection
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1742
 * @port: server port
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1743
 *
56
3bf928955fc5 2003-11-20 Ross Burton <ross@burtonini.com>
hallski <hallski>
parents: 55
diff changeset
  1744
 * Sets the server port that @connection will be using.
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1745
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1746
void
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1747
lm_connection_set_port (LmConnection *connection, guint port)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1748
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1749
    g_return_if_fail (connection != NULL);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1750
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1751
    if (lm_connection_is_open (connection)) {
614
773201ca404c Replaced every g_warning() with g_log()
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1752
        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
  1753
               "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
  1754
        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
  1755
    }
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1756
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1757
    connection->port = port;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1758
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1759
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1760
/**
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1761
 * lm_connection_get_ssl:
68
28203e15de0e 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 67
diff changeset
  1762
 * @connection: an #LmConnection
15
1ff2f81867e1 2003-07-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 12
diff changeset
  1763
 *
68
28203e15de0e 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 67
diff changeset
  1764
 * Returns the SSL struct if the connection is using one.
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1765
 *
68
28203e15de0e 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 67
diff changeset
  1766
 * 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
  1767
 **/
68
28203e15de0e 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 67
diff changeset
  1768
LmSSL *
28203e15de0e 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 67
diff changeset
  1769
lm_connection_get_ssl (LmConnection *connection)
15
1ff2f81867e1 2003-07-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 12
diff changeset
  1770
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1771
    g_return_val_if_fail (connection != NULL, NULL);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1772
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1773
    return connection->ssl;
15
1ff2f81867e1 2003-07-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 12
diff changeset
  1774
}
68
28203e15de0e 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 67
diff changeset
  1775
28203e15de0e 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 67
diff changeset
  1776
/**
28203e15de0e 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 67
diff changeset
  1777
 * lm_connection_set_ssl:
28203e15de0e 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 67
diff changeset
  1778
 * @connection: An #LmConnection
28203e15de0e 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 67
diff changeset
  1779
 * @ssl: An #LmSSL
28203e15de0e 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 67
diff changeset
  1780
 *
28203e15de0e 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 67
diff changeset
  1781
 * 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
  1782
 */
39b83ccd70ff 2003-12-27 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 61
diff changeset
  1783
void
68
28203e15de0e 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 67
diff changeset
  1784
lm_connection_set_ssl (LmConnection *connection, LmSSL *ssl)
62
39b83ccd70ff 2003-12-27 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 61
diff changeset
  1785
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1786
    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
  1787
    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
  1788
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1789
    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
  1790
        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
  1791
    }
66
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1792
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1793
    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
  1794
        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
  1795
    } 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
  1796
        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
  1797
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1798
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1799
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1800
/**
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1801
 * lm_connection_get_proxy:
66
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1802
 * @connection: an #LmConnection
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1803
 *
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1804
 * Returns the proxy if the connection is using one.
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1805
 *
66
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1806
 * 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
  1807
 **/
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1808
LmProxy *
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1809
lm_connection_get_proxy (LmConnection *connection)
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1810
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1811
    g_return_val_if_fail (connection != NULL, NULL);
66
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1812
518
cdd6a0c5b439 Went 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
    return connection->proxy;
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1814
}
66
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1815
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1816
/**
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1817
 * lm_connection_set_proxy:
66
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1818
 * @connection: an #LmConnection
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1819
 * @proxy: an #LmProxy
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1820
 *
94
85b606ac2c0c 2004-09-02 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 93
diff changeset
  1821
 * 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
  1822
 *
66
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1823
 **/
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1824
void
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1825
lm_connection_set_proxy (LmConnection *connection, LmProxy *proxy)
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1826
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1827
    g_return_if_fail (connection != NULL);
66
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1828
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1829
    if (lm_connection_is_open (connection)) {
614
773201ca404c Replaced every g_warning() with g_log()
Mikael Berthe <mikael@lilotux.net>
parents: 613
diff changeset
  1830
        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
  1831
               "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
  1832
        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
  1833
    }
87
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
  1834
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1835
    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
  1836
        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
  1837
        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
  1838
    }
66
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1839
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1840
    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
  1841
        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
  1842
    }
66
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1843
}
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1844
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1845
/**
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1846
 * lm_connection_send:
56
3bf928955fc5 2003-11-20 Ross Burton <ross@burtonini.com>
hallski <hallski>
parents: 55
diff changeset
  1847
 * @connection: #LmConnection to send message over.
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1848
 * @message: #LmMessage to send.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1849
 * @error: location to store error, or %NULL
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1850
 *
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1851
 * Asynchronous call to send a message.
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1852
 *
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1853
 * Return value: Returns #TRUE if no errors where detected while sending, #FALSE otherwise.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1854
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1855
gboolean
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1856
lm_connection_send (LmConnection  *connection,
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1857
                    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
  1858
                    GError       **error)
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1859
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1860
    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
  1861
    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
  1862
    gboolean  result;
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1863
518
cdd6a0c5b439 Went 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
    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
  1865
    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
  1866
518
cdd6a0c5b439 Went 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
    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
  1868
    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
  1869
        *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
  1870
    }
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1871
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1872
    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
  1873
    g_free (xml_str);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1874
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1875
    return result;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1876
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1877
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1878
/**
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1879
 * lm_connection_send_with_reply:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1880
 * @connection: #LmConnection used to send message.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1881
 * @message: #LmMessage to send.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1882
 * @handler: #LmMessageHandler that will be used when a reply to @message arrives
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1883
 * @error: location to store error, or %NULL
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1884
 *
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1885
 * Send a #LmMessage which will result in a reply.
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1886
 *
56
3bf928955fc5 2003-11-20 Ross Burton <ross@burtonini.com>
hallski <hallski>
parents: 55
diff changeset
  1887
 * Return value: Returns #TRUE if no errors where detected while sending, #FALSE otherwise.
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1888
 **/
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1889
gboolean
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1890
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
  1891
                               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
  1892
                               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
  1893
                               GError           **error)
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1894
{
518
cdd6a0c5b439 Went 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
    gchar *id;
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1896
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1897
    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
  1898
    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
  1899
    g_return_val_if_fail (handler != NULL, FALSE);
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
    if (lm_message_node_get_attribute (message->node, "id")) {
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1902
        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
  1903
                                                      "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
  1904
    } 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
  1905
        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
  1906
        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
  1907
    }
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1908
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1909
    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
  1910
                         id, lm_message_handler_ref (handler));
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1911
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1912
    return lm_connection_send (connection, message, error);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1913
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1914
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1915
/**
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1916
 * lm_connection_send_with_reply_and_block:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1917
 * @connection: an #LmConnection
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1918
 * @message: an #LmMessage
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1919
 * @error: Set if error was detected during sending.
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1920
 *
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1921
 * Send @message and wait for return.
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1922
 *
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1923
 * Return value: The reply
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1924
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1925
LmMessage *
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1926
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
  1927
                                         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
  1928
                                         GError       **error)
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1929
{
518
cdd6a0c5b439 Went 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
    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
  1931
    LmMessage *reply = NULL;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1932
518
cdd6a0c5b439 Went 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
    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
  1934
    g_return_val_if_fail (message != NULL, NULL);
66
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1935
518
cdd6a0c5b439 Went 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
    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
  1937
        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
  1938
                     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
  1939
                     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
  1940
                     "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
  1941
        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
  1942
    }
125
6163119136b5 2005-08-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 124
diff changeset
  1943
6163119136b5 2005-08-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 124
diff changeset
  1944
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1945
    if (lm_message_node_get_attribute (message->node, "id")) {
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1946
        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
  1947
                                                      "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
  1948
    } 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
  1949
        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
  1950
        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
  1951
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1952
518
cdd6a0c5b439 Went 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
    lm_message_queue_detach (connection->queue);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1954
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1955
    lm_connection_send (connection, message, error);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1956
518
cdd6a0c5b439 Went 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
    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
  1958
        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
  1959
        guint        n;
39
b909b5af5a97 2003-10-01 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 37
diff changeset
  1960
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1961
        g_main_context_iteration (connection->context, TRUE);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1962
518
cdd6a0c5b439 Went 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
        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
  1964
            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
  1965
        }
39
b909b5af5a97 2003-10-01 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 37
diff changeset
  1966
518
cdd6a0c5b439 Went 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
        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
  1968
            LmMessage *m;
39
b909b5af5a97 2003-10-01 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 37
diff changeset
  1969
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1970
            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
  1971
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1972
            m_id = lm_message_node_get_attribute (m->node, "id");
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  1973
518
cdd6a0c5b439 Went 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
            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
  1975
                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
  1976
                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
  1977
                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
  1978
            }
cdd6a0c5b439 Went 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
        }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1980
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1981
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1982
    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
  1983
    lm_message_queue_attach (connection->queue, connection->context);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1984
518
cdd6a0c5b439 Went 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
    return reply;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1986
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1987
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1988
/**
609
8dab2a5c2123 Added lm_connection_unregister_reply_handler()
Frank Zschockelt <flm@freakysoft.de>
parents: 608
diff changeset
  1989
 * lm_connection_unregister_reply_handler:
8dab2a5c2123 Added lm_connection_unregister_reply_handler()
Frank Zschockelt <flm@freakysoft.de>
parents: 608
diff changeset
  1990
 * @connection: Connection to unregister a handler for.
8dab2a5c2123 Added lm_connection_unregister_reply_handler()
Frank Zschockelt <flm@freakysoft.de>
parents: 608
diff changeset
  1991
 * @handler: The handler to unregister.
8dab2a5c2123 Added lm_connection_unregister_reply_handler()
Frank Zschockelt <flm@freakysoft.de>
parents: 608
diff changeset
  1992
 *
8dab2a5c2123 Added lm_connection_unregister_reply_handler()
Frank Zschockelt <flm@freakysoft.de>
parents: 608
diff changeset
  1993
 * 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
  1994
 * 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
  1995
 **/
8dab2a5c2123 Added lm_connection_unregister_reply_handler()
Frank Zschockelt <flm@freakysoft.de>
parents: 608
diff changeset
  1996
void
8dab2a5c2123 Added lm_connection_unregister_reply_handler()
Frank Zschockelt <flm@freakysoft.de>
parents: 608
diff changeset
  1997
lm_connection_unregister_reply_handler (LmConnection     *connection,
8dab2a5c2123 Added lm_connection_unregister_reply_handler()
Frank Zschockelt <flm@freakysoft.de>
parents: 608
diff changeset
  1998
                                        LmMessageHandler *handler)
8dab2a5c2123 Added lm_connection_unregister_reply_handler()
Frank Zschockelt <flm@freakysoft.de>
parents: 608
diff changeset
  1999
{
8dab2a5c2123 Added lm_connection_unregister_reply_handler()
Frank Zschockelt <flm@freakysoft.de>
parents: 608
diff changeset
  2000
    GHashTableIter iter;
8dab2a5c2123 Added lm_connection_unregister_reply_handler()
Frank Zschockelt <flm@freakysoft.de>
parents: 608
diff changeset
  2001
    gpointer key, value;
8dab2a5c2123 Added lm_connection_unregister_reply_handler()
Frank Zschockelt <flm@freakysoft.de>
parents: 608
diff changeset
  2002
8dab2a5c2123 Added lm_connection_unregister_reply_handler()
Frank Zschockelt <flm@freakysoft.de>
parents: 608
diff changeset
  2003
    g_return_if_fail (connection != NULL);
8dab2a5c2123 Added lm_connection_unregister_reply_handler()
Frank Zschockelt <flm@freakysoft.de>
parents: 608
diff changeset
  2004
    g_return_if_fail (handler != NULL);
8dab2a5c2123 Added lm_connection_unregister_reply_handler()
Frank Zschockelt <flm@freakysoft.de>
parents: 608
diff changeset
  2005
8dab2a5c2123 Added lm_connection_unregister_reply_handler()
Frank Zschockelt <flm@freakysoft.de>
parents: 608
diff changeset
  2006
    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
  2007
    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
  2008
        if (handler == value) {
8dab2a5c2123 Added lm_connection_unregister_reply_handler()
Frank Zschockelt <flm@freakysoft.de>
parents: 608
diff changeset
  2009
            g_hash_table_iter_remove (&iter);
8dab2a5c2123 Added lm_connection_unregister_reply_handler()
Frank Zschockelt <flm@freakysoft.de>
parents: 608
diff changeset
  2010
            break;
8dab2a5c2123 Added lm_connection_unregister_reply_handler()
Frank Zschockelt <flm@freakysoft.de>
parents: 608
diff changeset
  2011
        }
8dab2a5c2123 Added lm_connection_unregister_reply_handler()
Frank Zschockelt <flm@freakysoft.de>
parents: 608
diff changeset
  2012
    }
8dab2a5c2123 Added lm_connection_unregister_reply_handler()
Frank Zschockelt <flm@freakysoft.de>
parents: 608
diff changeset
  2013
}
8dab2a5c2123 Added lm_connection_unregister_reply_handler()
Frank Zschockelt <flm@freakysoft.de>
parents: 608
diff changeset
  2014
8dab2a5c2123 Added lm_connection_unregister_reply_handler()
Frank Zschockelt <flm@freakysoft.de>
parents: 608
diff changeset
  2015
/**
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2016
 * lm_connection_register_message_handler:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2017
 * @connection: Connection to register a handler for.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2018
 * @handler: Message handler to register.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2019
 * @type: Message type that @handler will handle.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2020
 * @priority: The priority in which to call @handler.
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  2021
 *
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2022
 * Registers a #LmMessageHandler to handle incoming messages of a certain type.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2023
 * To unregister the handler call lm_connection_unregister_message_handler().
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2024
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2025
void
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
  2026
lm_connection_register_message_handler  (LmConnection      *connection,
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
  2027
                                         LmMessageHandler  *handler,
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
  2028
                                         LmMessageType      type,
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
  2029
                                         LmHandlerPriority  priority)
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2030
{
530
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 529
diff changeset
  2031
    HandlerData *hd;
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  2032
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2033
    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
  2034
    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
  2035
    g_return_if_fail (type != LM_MESSAGE_TYPE_UNKNOWN);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2036
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2037
    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
  2038
    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
  2039
    hd->handler  = lm_message_handler_ref (handler);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2040
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2041
    connection->handlers[type] = g_slist_insert_sorted (connection->handlers[type],
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  2042
                                                        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
  2043
                                                        (GCompareFunc) connection_handler_compare_func);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2044
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2045
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2046
/**
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2047
 * lm_connection_unregister_message_handler:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2048
 * @connection: Connection to unregister a handler for.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2049
 * @handler: The handler to unregister.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2050
 * @type: What type of messages to unregister this handler for.
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  2051
 *
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  2052
 * Unregisters a handler for @connection. @handler will no longer be called
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2053
 * when incoming messages of @type arrive.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2054
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2055
void
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
  2056
lm_connection_unregister_message_handler (LmConnection     *connection,
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
  2057
                                          LmMessageHandler *handler,
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
  2058
                                          LmMessageType     type)
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2059
{
518
cdd6a0c5b439 Went 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
    GSList *l;
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  2061
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2062
    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
  2063
    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
  2064
    g_return_if_fail (type != LM_MESSAGE_TYPE_UNKNOWN);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2065
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2066
    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
  2067
        HandlerData *hd = (HandlerData *) l->data;
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  2068
518
cdd6a0c5b439 Went 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
        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
  2070
            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
  2071
            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
  2072
            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
  2073
            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
  2074
            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
  2075
        }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2076
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2077
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2078
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2079
/**
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2080
 * lm_connection_set_disconnect_function:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2081
 * @connection: Connection to register disconnect callback for.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2082
 * @function: Function to be called when @connection is closed.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2083
 * @user_data: User data passed to @function.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2084
 * @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
  2085
 *
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  2086
 * Set the callback that will be called when a connection is closed.
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2087
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2088
void
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2089
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
  2090
                                       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
  2091
                                       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
  2092
                                       GDestroyNotify        notify)
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2093
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2094
    g_return_if_fail (connection != NULL);
66
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  2095
518
cdd6a0c5b439 Went 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
    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
  2097
        _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
  2098
    }
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  2099
518
cdd6a0c5b439 Went 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
    if (function) {
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  2101
        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
  2102
                                                            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
  2103
                                                            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
  2104
    } 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
  2105
        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
  2106
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2107
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2108
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2109
/**
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2110
 * lm_connection_send_raw:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2111
 * @connection: Connection used to send
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2112
 * @str: The string to send, the entire string will be sent.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2113
 * @error: Set if error was detected during sending.
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  2114
 *
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2115
 * 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
  2116
 *
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  2117
 * Return value: Returns #TRUE if no errors was detected during sending,
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2118
 * #FALSE otherwise.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2119
 **/
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  2120
gboolean
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  2121
lm_connection_send_raw (LmConnection  *connection,
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  2122
                        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
  2123
                        GError       **error)
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2124
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2125
    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
  2126
    g_return_val_if_fail (str != NULL, FALSE);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2127
518
cdd6a0c5b439 Went 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
    return connection_send (connection, str, -1, error);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2129
}
59
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  2130
/**
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  2131
 * lm_connection_get_state:
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  2132
 * @connection: Connection to get state on
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  2133
 *
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  2134
 * Returns the state of the connection.
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  2135
 *
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  2136
 * Return value: The state of the connection.
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  2137
 **/
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  2138
LmConnectionState
59
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  2139
lm_connection_get_state (LmConnection *connection)
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  2140
{
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  2141
    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
  2142
                          LM_CONNECTION_STATE_CLOSED);
59
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  2143
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2144
    return connection->state;
59
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  2145
}
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2146
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2147
/**
308
7e2050a6df75 Added lm_connection_get_client_host (forward-port from LM1.2).
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 307
diff changeset
  2148
 * 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
  2149
 * @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
  2150
 *
7e2050a6df75 Added lm_connection_get_client_host (forward-port from LM1.2).
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 307
diff changeset
  2151
 * 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
  2152
 *
7e2050a6df75 Added lm_connection_get_client_host (forward-port from LM1.2).
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 307
diff changeset
  2153
 * 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
  2154
 **/
7e2050a6df75 Added lm_connection_get_client_host (forward-port from LM1.2).
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 307
diff changeset
  2155
gchar *
7e2050a6df75 Added lm_connection_get_client_host (forward-port from LM1.2).
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 307
diff changeset
  2156
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
  2157
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2158
    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
  2159
}
7e2050a6df75 Added lm_connection_get_client_host (forward-port from LM1.2).
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 307
diff changeset
  2160
7e2050a6df75 Added lm_connection_get_client_host (forward-port from LM1.2).
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 307
diff changeset
  2161
/**
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2162
 * lm_connection_ref:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2163
 * @connection: Connection to add a reference to.
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  2164
 *
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  2165
 * Add a reference on @connection. To remove a reference call
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2166
 * lm_connection_unref().
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  2167
 *
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2168
 * Return value: Returns the same connection.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2169
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2170
LmConnection*
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2171
lm_connection_ref (LmConnection *connection)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2172
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2173
    g_return_val_if_fail (connection != NULL, NULL);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  2174
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2175
    connection->ref_count++;
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  2176
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2177
    return connection;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2178
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2179
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2180
/**
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2181
 * lm_connection_unref:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2182
 * @connection: Connection to remove reference from.
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  2183
 *
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2184
 * 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
  2185
 * @connection it will be freed and shouldn't be used again.
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2186
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2187
void
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2188
lm_connection_unref (LmConnection *connection)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2189
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2190
    g_return_if_fail (connection != NULL);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  2191
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2192
    connection->ref_count--;
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 600
diff changeset
  2193
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2194
    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
  2195
        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
  2196
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2197
}