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