loudmouth/lm-connection.c
author Mikael Hallendal <micke@imendio.com>
Tue, 21 Oct 2008 02:21:09 +0200
changeset 533 c45243823756
parent 532 c917a1900d5c
child 534 19327ccf6099
permissions -rw-r--r--
Added some TODO items and minor style fixes
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
364c17252e5f Added inlined documentation from generated through the Gtk-doc migration script.
Mikael Hallendal <micke@imendio.com>
parents: 416
diff changeset
    27
 * 
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");
417
364c17252e5f Added inlined documentation from generated through the Gtk-doc migration script.
Mikael Hallendal <micke@imendio.com>
parents: 416
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
 *      }
417
364c17252e5f Added inlined documentation from generated through the Gtk-doc migration script.
Mikael Hallendal <micke@imendio.com>
parents: 416
diff changeset
    43
 * 
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
    44
 *      if (!lm_connection_authenticate_and_block (connection,
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
    45
 *                                                 "username", "password", 
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
 *      }
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
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");
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
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
 *      }
417
364c17252e5f Added inlined documentation from generated through the Gtk-doc migration script.
Mikael Hallendal <micke@imendio.com>
parents: 416
diff changeset
    57
 * 
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
    58
 *      lm_message_unref (m);
417
364c17252e5f Added inlined documentation from generated through the Gtk-doc migration script.
Mikael Hallendal <micke@imendio.com>
parents: 416
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);
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
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>
140
103227122f45 2006-04-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 137
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
103227122f45 2006-04-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 137
diff changeset
    85
#include "lm-sock.h"
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    86
#include "lm-debug.h"
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    87
#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
    88
#include "lm-feature-ping.h"
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    89
#include "lm-internals.h"
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
    90
#include "lm-message-queue.h"
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
    91
#include "lm-misc.h"
137
18785575aa7a 2006-04-05 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 133
diff changeset
    92
#include "lm-ssl-internals.h"
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    93
#include "lm-parser.h"
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    94
#include "lm-sha.h"
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    95
#include "lm-connection.h"
155
d24c4392d4e3 2006-06-16 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 153
diff changeset
    96
#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
    97
#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
    98
#include "lm-sasl.h"
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
    99
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   100
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
   101
    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
   102
    LmMessageHandler  *handler;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   103
} HandlerData;
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   104
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   105
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
   106
    /* Parameters */
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   107
    GMainContext      *context;
533
c45243823756 Added some TODO items and minor style fixes
Mikael Hallendal <micke@imendio.com>
parents: 532
diff changeset
   108
    
c45243823756 Added some TODO items and minor style fixes
Mikael Hallendal <micke@imendio.com>
parents: 532
diff changeset
   109
    /* 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
   110
    gchar             *server;
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   111
    gchar             *jid;
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   112
    gchar             *effective_jid;
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   113
    guint              port;
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   114
    gboolean           use_srv;
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           async_connect_waiting;
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   139
    gboolean           blocking;
140
103227122f45 2006-04-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 137
diff changeset
   140
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   141
    gboolean           cancel_open;
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   142
    LmCallback        *auth_cb;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   143
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   144
    LmCallback        *disconnect_cb;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   145
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   146
    LmMessageQueue    *queue;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   147
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   148
    LmConnectionState  state;
59
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
   149
533
c45243823756 Added some TODO items and minor style fixes
Mikael Hallendal <micke@imendio.com>
parents: 532
diff changeset
   150
    /* 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
   151
    guint              keep_alive_rate;
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   152
    LmFeaturePing     *feature_ping;
184
4e16d32b2410 2006-10-16 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 181
diff changeset
   153
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   154
    gint               ref_count;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   155
};
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   156
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   157
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
   158
    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
   159
    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
   160
    AUTH_TYPE_0K     = 4
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   161
} AuthType;
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   162
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
   163
#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
   164
#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
   165
#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
   166
416
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   167
static void     connection_free              (LmConnection        *connection);
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   168
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
   169
                                              LmMessage           *message);
416
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   170
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
   171
                                              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
   172
                                              LmConnection        *connection);
416
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   173
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
   174
                                              GError             **error);
416
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   175
void            connection_do_close          (LmConnection        *connection);
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_req_msg               (const gchar         *username);
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   178
static LmMessage *
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   179
connection_create_auth_msg                   (LmConnection        *connection,
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   180
                                              const gchar         *username,
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   181
                                              const gchar         *password,
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   182
                                              const gchar         *resource,
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   183
                                              gint                 auth_type);
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   184
static LmHandlerResult 
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   185
connection_auth_req_reply                    (LmMessageHandler    *handler,
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   186
                                              LmConnection        *connection,
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   187
                                              LmMessage           *m,
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   188
                                              gpointer             user_data);
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   189
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
   190
static LmHandlerResult
416
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   191
connection_auth_reply                        (LmMessageHandler    *handler,
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   192
                                              LmConnection        *connection,
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   193
                                              LmMessage           *m,
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   194
                                              gpointer             user_data);
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   195
static void     connection_stream_received   (LmConnection        *connection, 
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   196
                                              LmMessage           *m);
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   197
static void     connection_stream_error      (LmConnection        *connection, 
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   198
                                              LmMessage           *m);
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   199
static gint      
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   200
connection_handler_compare_func              (HandlerData         *a,
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   201
                                              HandlerData         *b);
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   202
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
   203
static void     connection_stop_keep_alive   (LmConnection        *connection);
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   204
static gboolean connection_send              (LmConnection        *connection, 
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   205
                                              const gchar         *str, 
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   206
                                              gint                 len, 
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   207
                                              GError             **error);
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   208
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
   209
                                              LmConnection        *connection);
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   210
static void      
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   211
connection_signal_disconnect                 (LmConnection        *connection,
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   212
                                              LmDisconnectReason   reason);
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   213
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
   214
                                              const gchar         *buf,
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   215
                                              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
   216
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
   217
                                              LmDisconnectReason   reason,
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 void      
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   220
connection_socket_connect_cb                 (LmOldSocket         *socket,
416
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   221
                                              gboolean             result,
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   222
                                              LmConnection        *connection);
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   223
static gboolean
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   224
connection_get_server_from_jid               (const gchar         *jid,
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   225
                                              gchar              **server);
416
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   226
static void
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   227
connection_send_stream_header                (LmConnection        *connection);
416
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   228
static LmHandlerResult 
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   229
connection_features_cb                       (LmMessageHandler    *handler,
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   230
                                              LmConnection        *connection,
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   231
                                              LmMessage           *message,
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   232
                                              gpointer             user_data);
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   233
static gboolean connection_old_auth          (LmConnection        *connection,
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   234
                                              const gchar         *username,
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   235
                                              const gchar         *password,
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   236
                                              const gchar         *resource,
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   237
                                              GError             **errror);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   238
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   239
static void
405
f33dcdadf95c Factored out connection_free_handlers from connection_free
Mikael Hallendal <micke@imendio.com>
parents: 394
diff changeset
   240
connection_free_handlers (LmConnection *connection)
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
    int i;
405
f33dcdadf95c Factored out connection_free_handlers from connection_free
Mikael Hallendal <micke@imendio.com>
parents: 394
diff changeset
   243
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   244
    /* 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
   245
    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
   246
        GSList *l;
405
f33dcdadf95c Factored out connection_free_handlers from connection_free
Mikael Hallendal <micke@imendio.com>
parents: 394
diff changeset
   247
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   248
        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
   249
            HandlerData *hd = (HandlerData *) l->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
   250
            
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   251
            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
   252
            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
   253
        }
405
f33dcdadf95c Factored out connection_free_handlers from connection_free
Mikael Hallendal <micke@imendio.com>
parents: 394
diff changeset
   254
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   255
        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
   256
    }
405
f33dcdadf95c Factored out connection_free_handlers from connection_free
Mikael Hallendal <micke@imendio.com>
parents: 394
diff changeset
   257
}
f33dcdadf95c Factored out connection_free_handlers from connection_free
Mikael Hallendal <micke@imendio.com>
parents: 394
diff changeset
   258
f33dcdadf95c Factored out connection_free_handlers from connection_free
Mikael Hallendal <micke@imendio.com>
parents: 394
diff changeset
   259
static void
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   260
connection_free (LmConnection *connection)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   261
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   262
    g_free (connection->server);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   263
    g_free (connection->jid);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   264
    g_free (connection->effective_jid);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   265
    g_free (connection->stream_id);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   266
    g_free (connection->resource);
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
   267
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   268
    if (connection->sasl) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   269
        lm_sasl_free (connection->sasl);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   270
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   271
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   272
    if (connection->parser) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   273
        lm_parser_free (connection->parser);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   274
    }
153
b2324df84971 2006-06-06 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 143
diff changeset
   275
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   276
    connection_free_handlers (connection);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   277
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   278
    g_hash_table_destroy (connection->id_handlers);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   279
    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
   280
        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
   281
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   282
518
cdd6a0c5b439 Went 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
    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
   284
        _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
   285
    }
cdd6a0c5b439 Went 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
    
cdd6a0c5b439 Went 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
    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
   288
        _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
   289
    }
143
92193c23b0c7 2006-05-26 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 140
diff changeset
   290
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   291
    lm_connection_set_disconnect_function (connection, NULL, NULL, NULL);
143
92193c23b0c7 2006-05-26 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 140
diff changeset
   292
518
cdd6a0c5b439 Went 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
    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
   294
        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
   295
    }
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
   296
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   297
    lm_message_queue_unref (connection->queue);
115
f2a921e232e5 2005-04-24 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 114
diff changeset
   298
518
cdd6a0c5b439 Went 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
    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
   300
        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
   301
    }
133
f7522d7ed6dc 2006-04-03 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 132
diff changeset
   302
518
cdd6a0c5b439 Went 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
    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
   304
        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
   305
    }
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   306
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   307
    g_slice_free (LmConnection, connection);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   308
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   309
408
b07ef2183e6b Factored out connection_run_message_handler from connection_handle_message.
Mikael Hallendal <micke@imendio.com>
parents: 406
diff changeset
   310
static LmHandlerResult
b07ef2183e6b Factored out connection_run_message_handler from connection_handle_message.
Mikael Hallendal <micke@imendio.com>
parents: 406
diff changeset
   311
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
   312
{
518
cdd6a0c5b439 Went 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
    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
   314
    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
   315
    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
   316
518
cdd6a0c5b439 Went 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
    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
   318
    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
   319
        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
   320
    }
408
b07ef2183e6b Factored out connection_run_message_handler from connection_handle_message.
Mikael Hallendal <micke@imendio.com>
parents: 406
diff changeset
   321
518
cdd6a0c5b439 Went 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
    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
   323
    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
   324
        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
   325
                                                     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
   326
                                                     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
   327
        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
   328
                             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
   329
    }
408
b07ef2183e6b Factored out connection_run_message_handler from connection_handle_message.
Mikael Hallendal <micke@imendio.com>
parents: 406
diff changeset
   330
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   331
    return result;
408
b07ef2183e6b Factored out connection_run_message_handler from connection_handle_message.
Mikael Hallendal <micke@imendio.com>
parents: 406
diff changeset
   332
}
b07ef2183e6b Factored out connection_run_message_handler from connection_handle_message.
Mikael Hallendal <micke@imendio.com>
parents: 406
diff changeset
   333
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   334
static void
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   335
connection_handle_message (LmConnection *connection, LmMessage *m)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   336
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   337
    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
   338
    LmHandlerResult  result = LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   339
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   340
    lm_connection_ref (connection);
143
92193c23b0c7 2006-05-26 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 140
diff changeset
   341
518
cdd6a0c5b439 Went 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
    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
   343
        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
   344
        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
   345
    }
306
d466fc30829f Added disconnect error for resource conflict. Fixes LM-55.
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 297
diff changeset
   346
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   347
    result = connection_run_message_handler (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
   348
    if (result == 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
   349
        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
   350
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   351
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   352
    for (l = connection->handlers[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
   353
         l && result == 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
   354
         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
   355
        HandlerData *hd = (HandlerData *) l->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
   356
        
cdd6a0c5b439 Went 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
        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
   358
                                                     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
   359
                                                     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
   360
    }
143
92193c23b0c7 2006-05-26 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 140
diff changeset
   361
518
cdd6a0c5b439 Went 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
    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
   363
        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
   364
        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
   365
    }
cdd6a0c5b439 Went 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
    
cdd6a0c5b439 Went 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
 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
    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
   369
    
cdd6a0c5b439 Went 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
    return;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   371
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   372
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   373
static void
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   374
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
   375
                           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
   376
                           LmConnection *connection)
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   377
{
518
cdd6a0c5b439 Went 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
    const gchar *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
   379
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   380
    lm_message_ref (m);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   381
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   382
    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
   383
    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
   384
        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
   385
    }
cdd6a0c5b439 Went 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
    
cdd6a0c5b439 Went 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
    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
   388
                _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
   389
                from);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   390
518
cdd6a0c5b439 Went 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_queue_push_tail (connection->queue, m);
82
a32b54e654e2 2004-03-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 80
diff changeset
   392
}
a32b54e654e2 2004-03-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 80
diff changeset
   393
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
   394
static void
529
6bb284696153 More style fixes
Mikael Hallendal <micke@imendio.com>
parents: 528
diff changeset
   395
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
   396
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   397
    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
   398
    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
   399
                                  LM_DISCONNECT_REASON_PING_TIME_OUT);
90
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
   400
}
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
   401
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
   402
static void
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
   403
connection_start_keep_alive (LmConnection *connection)
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
   404
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   405
    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
   406
        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
   407
    }
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
   408
518
cdd6a0c5b439 Went 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->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
   410
                                             "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
   411
                                             "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
   412
                                             NULL);
90
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
   413
518
cdd6a0c5b439 Went 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
    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
   415
                      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
   416
                      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
   417
518
cdd6a0c5b439 Went 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
    lm_feature_ping_start (connection->feature_ping);
90
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
   419
}
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
   420
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
   421
static void
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
   422
connection_stop_keep_alive (LmConnection *connection)
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
   423
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   424
    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
   425
        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
   426
        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
   427
                                              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
   428
                                              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
   429
        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
   430
    }
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
   431
        
518
cdd6a0c5b439 Went 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
    connection->feature_ping = NULL;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   433
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   434
406
3c6b13d37d41 Factored out connection_log_send from connection_send
Mikael Hallendal <micke@imendio.com>
parents: 405
diff changeset
   435
static void
3c6b13d37d41 Factored out connection_log_send from connection_send
Mikael Hallendal <micke@imendio.com>
parents: 405
diff changeset
   436
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
   437
                     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
   438
                     gint          len)
406
3c6b13d37d41 Factored out connection_log_send from connection_send
Mikael Hallendal <micke@imendio.com>
parents: 405
diff changeset
   439
{
518
cdd6a0c5b439 Went 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
    g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_NET, "\nSEND:\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
   441
    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
   442
           "-----------------------------------\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
   443
    g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_NET, "%s\n", 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
   444
    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
   445
           "-----------------------------------\n");
406
3c6b13d37d41 Factored out connection_log_send from connection_send
Mikael Hallendal <micke@imendio.com>
parents: 405
diff changeset
   446
}
3c6b13d37d41 Factored out connection_log_send from connection_send
Mikael Hallendal <micke@imendio.com>
parents: 405
diff changeset
   447
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   448
static gboolean
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   449
connection_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
   450
                 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
   451
                 gint           len, 
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   452
                 GError       **error)
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   453
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   454
    gint b_written;
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   455
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   456
    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
   457
        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
   458
               "Connection is not open.\n");
140
103227122f45 2006-04-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 137
diff changeset
   459
518
cdd6a0c5b439 Went 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_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
   461
                     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
   462
                     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
   463
                     "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
   464
        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
   465
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   466
518
cdd6a0c5b439 Went 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
    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
   468
        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
   469
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   470
518
cdd6a0c5b439 Went 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
    connection_log_send (connection, str, len);
68
28203e15de0e 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 67
diff changeset
   472
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   473
    /* 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
   474
       buffer and return */
133
f7522d7ed6dc 2006-04-03 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 132
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
    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
   477
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   478
    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
   479
        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
   480
                     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
   481
                     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
   482
                     "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
   483
        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
   484
    }
133
f7522d7ed6dc 2006-04-03 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 132
diff changeset
   485
518
cdd6a0c5b439 Went 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 TRUE;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   487
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   488
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   489
static void
249
2cca5ec7b573 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 248
diff changeset
   490
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
   491
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   492
    LmMessage *m;
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   493
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   494
    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
   495
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   496
    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
   497
        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
   498
        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
   499
    }
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   500
}
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   501
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   502
/* Returns directly */
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   503
/* 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
   504
static gboolean
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   505
connection_do_open (LmConnection *connection, GError **error) 
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   506
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   507
    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
   508
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   509
    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
   510
        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
   511
                     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
   512
                     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
   513
                     "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
   514
        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
   515
    }
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   516
518
cdd6a0c5b439 Went 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
    domain = _lm_connection_get_server (connection);
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   518
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   519
    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
   520
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   521
    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
   522
                                               (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
   523
                                               (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
   524
                                               (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
   525
                                               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
   526
                                               connection,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   527
                                               connection->blocking,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   528
                                               connection->server,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   529
                                               domain,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   530
                                               connection->port,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   531
                                               connection->ssl,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   532
                                               connection->proxy,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   533
                                               error);
245
df2655dbe873 Make LmConnection accept not having a server set as long as JID is set.
Mikael Hallendal <micke@imendio.com>
parents: 244
diff changeset
   534
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   535
    g_free (domain);
281
4e0421c44a73 Fixed a leak in extracting the domain name from the jid.
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 275
diff changeset
   536
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   537
    if (!connection->socket) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   538
        return FALSE;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   539
    }
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   540
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   541
    lm_message_queue_attach (connection->queue, connection->context);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   542
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   543
    connection->state = LM_CONNECTION_STATE_OPENING;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   544
    connection->async_connect_waiting = FALSE;
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
   545
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   546
    return TRUE;
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   547
}
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   548
                    
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   549
void
256
2266e56746ed Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 255
diff changeset
   550
connection_do_close (LmConnection *connection)
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   551
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   552
    connection_stop_keep_alive (connection);
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   553
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   554
    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
   555
        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
   556
    }
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   557
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   558
    lm_message_queue_detach (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
   559
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   560
    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
   561
        /* 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
   562
        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
   563
        connection->async_connect_waiting = 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
   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
    }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   566
    
cdd6a0c5b439 Went 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;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   568
    connection->async_connect_waiting = FALSE;
324
4b06b1173262 Properly clean up SASL context on disconnect, allowing connection object reuse.
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 323
diff changeset
   569
518
cdd6a0c5b439 Went 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
    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
   571
        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
   572
        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
   573
    }
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   574
}
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   575
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   576
typedef struct {
529
6bb284696153 More style fixes
Mikael Hallendal <micke@imendio.com>
parents: 528
diff changeset
   577
    gchar *username;
6bb284696153 More style fixes
Mikael Hallendal <micke@imendio.com>
parents: 528
diff changeset
   578
    gchar *password;
6bb284696153 More style fixes
Mikael Hallendal <micke@imendio.com>
parents: 528
diff changeset
   579
    gchar *resource;
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   580
} AuthReqData;
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   581
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   582
static void 
345
9a94f040cc56 Some code style fixes
Mikael Hallendal <micke@imendio.com>
parents: 344
diff changeset
   583
auth_req_data_free (AuthReqData *data) 
9a94f040cc56 Some code style fixes
Mikael Hallendal <micke@imendio.com>
parents: 344
diff changeset
   584
{
518
cdd6a0c5b439 Went 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
    g_free (data->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
   586
    g_free (data->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
   587
    g_free (data->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
   588
    g_free (data);
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   589
}
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   590
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   591
static LmMessage *
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   592
connection_create_auth_req_msg (const gchar *username)
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   593
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   594
    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
   595
    LmMessageNode *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
   596
    
cdd6a0c5b439 Went 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
    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
   598
                                      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
   599
    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
   600
    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
   601
                                    "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
   602
                                    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
   603
    lm_message_node_add_child (q_node, "username", username);
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
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
    return m;
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   606
}
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   607
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   608
static LmMessage *
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   609
connection_create_auth_msg (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
   610
                            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
   611
                            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
   612
                            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
   613
                            gint          auth_type)
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   614
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   615
    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
   616
    LmMessageNode *q_node;
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   617
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   618
    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
   619
                                             LM_MESSAGE_SUB_TYPE_SET);
cdd6a0c5b439 Went 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
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   621
    q_node = lm_message_node_add_child (auth_msg->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
   622
    
cdd6a0c5b439 Went 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
    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
   624
                                    "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
   625
                                    NULL);
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
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
    lm_message_node_add_child (q_node, "username", 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
   628
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   629
    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
   630
        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
   631
        /* 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
   632
    }
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   633
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   634
    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
   635
        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
   636
        gchar *digest;
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   637
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   638
        lm_verbose ("Using digest\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
   639
        str = g_strconcat (connection->stream_id, password, 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
   640
        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
   641
        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
   642
        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
   643
        g_free (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
   644
    } 
cdd6a0c5b439 Went 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
    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
   646
        lm_verbose ("Using plaintext auth\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
   647
        lm_message_node_add_child (q_node, "password", 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
   648
    } 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
   649
        /* 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
   650
    }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   651
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   652
    lm_message_node_add_child (q_node, "resource", resource);
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
    return auth_msg;
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   655
}
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   656
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   657
static LmHandlerResult
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   658
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
   659
                           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
   660
                           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
   661
                           gpointer          user_data)
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   662
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   663
    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
   664
    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
   665
    LmMessageHandler *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
   666
    AuthReqData      *data = (AuthReqData *) 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
   667
    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
   668
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   669
    auth_type = connection_check_auth_type (m);
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   670
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   671
    auth_msg = connection_create_auth_msg (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
   672
                                           data->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
   673
                                           data->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
   674
                                           data->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
   675
                                           auth_type);
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   676
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   677
    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
   678
                                           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
   679
    result = lm_connection_send_with_reply (connection, 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
   680
                                            auth_handler, NULL);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   681
    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
   682
    lm_message_unref (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
   683
    
cdd6a0c5b439 Went 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
    return LM_HANDLER_RESULT_REMOVE_MESSAGE;
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   685
}
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   686
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   687
static int
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   688
connection_check_auth_type (LmMessage *auth_req_rpl)
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   689
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   690
    LmMessageNode *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
   691
    gint           ret_val = 0; 
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   692
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   693
    q_node = lm_message_node_get_child (auth_req_rpl->node, "query");
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   694
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   695
    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
   696
        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
   697
    }
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   698
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   699
    if (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
   700
        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
   701
    }
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   702
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   703
    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
   704
        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
   705
    }
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   706
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   707
    if (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
   708
        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
   709
        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
   710
    }
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
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
    return ret_val;
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   713
}
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   714
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   715
static LmHandlerResult 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   716
connection_auth_reply (LmMessageHandler *handler,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   717
                       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
   718
                       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
   719
                       gpointer          user_data)
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   720
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   721
    const gchar *type;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   722
    gboolean     result = TRUE;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   723
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   724
    g_return_val_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
   725
                          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
   726
    
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   727
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   728
    type = lm_message_node_get_attribute (m->node, "type");
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   729
    if (strcmp (type, "result") == 0) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   730
        result = TRUE;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   731
        connection->state = LM_CONNECTION_STATE_AUTHENTICATED;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   732
    } 
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   733
    else if (strcmp (type, "error") == 0) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   734
        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
   735
        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
   736
    }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   737
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   738
    lm_verbose ("AUTH reply: %d\n", 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
   739
    
cdd6a0c5b439 Went 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
    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
   741
        LmCallback *cb = connection->auth_cb;
143
92193c23b0c7 2006-05-26 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 140
diff changeset
   742
518
cdd6a0c5b439 Went 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->auth_cb = NULL;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   744
518
cdd6a0c5b439 Went 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
        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
   746
            (* ((LmResultFunction) 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
   747
                                               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
   748
                                               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
   749
        }
143
92193c23b0c7 2006-05-26 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 140
diff changeset
   750
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   751
        _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
   752
    }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   753
    
cdd6a0c5b439 Went 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
    return LM_HANDLER_RESULT_REMOVE_MESSAGE;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   755
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   756
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   757
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
   758
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
   759
_lm_connection_starttls_cb (LmMessageHandler *handler,
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   760
                            LmConnection     *connection,
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   761
                            LmMessage        *message,
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   762
                            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
   763
{
518
cdd6a0c5b439 Went 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
    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
   765
        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
   766
        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
   767
    } 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
   768
        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
   769
        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
   770
                                      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
   771
    }
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
   772
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   773
    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
   774
}
02b814ccc535 Register starttls handler at the proper moment, when the stream is received.
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 317
diff changeset
   775
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   776
static void
450
548b5e3d9bea Refactored some of the SSL code in LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 449
diff changeset
   777
connection_possibly_register_starttls_handler (LmConnection *connection) 
548b5e3d9bea Refactored some of the SSL code in LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 449
diff changeset
   778
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   779
    /* 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
   780
     * 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
   781
    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
   782
        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
   783
        !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
   784
        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
   785
            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
   786
                                    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
   787
        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
   788
                                                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
   789
                                                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
   790
                                                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
   791
    }
450
548b5e3d9bea Refactored some of the SSL code in LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 449
diff changeset
   792
}
548b5e3d9bea Refactored some of the SSL code in LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 449
diff changeset
   793
548b5e3d9bea Refactored some of the SSL code in LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 449
diff changeset
   794
static void
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   795
connection_stream_received (LmConnection *connection, LmMessage *m)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   796
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   797
    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
   798
    const char *xmpp_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
   799
    
cdd6a0c5b439 Went 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
    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
   801
    g_return_if_fail (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
   802
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   803
    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
   804
                                                                     "id"));
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
   805
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   806
    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
   807
    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
   808
        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
   809
                    connection->stream_id);
220
f6b9482ae89e Some style fixes to the SASL patch.
Mikael Hallendal <micke@imendio.com>
parents: 219
diff changeset
   810
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   811
        connection->use_sasl = 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
   812
        
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   813
        /* 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
   814
         * 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
   815
        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
   816
            connection->sasl = lm_sasl_new(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
   817
        }
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
   818
518
cdd6a0c5b439 Went 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
        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
   820
    } 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
   821
        lm_verbose ("Old Jabber 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
   822
                    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
   823
    }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   824
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   825
    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
   826
        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
   827
    }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   828
    
cdd6a0c5b439 Went 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
    /* 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
   830
    result = TRUE;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
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
    connection_start_keep_alive (connection);
90
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
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
    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
   835
        LmCallback *cb = connection->open_cb;
143
92193c23b0c7 2006-05-26 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 140
diff changeset
   836
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   837
        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
   838
        
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   839
        if (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
   840
            (* ((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
   841
                                               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
   842
        }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   843
        _lm_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
   844
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   845
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   846
306
d466fc30829f Added disconnect error for resource conflict. Fixes LM-55.
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 297
diff changeset
   847
static void
d466fc30829f Added disconnect error for resource conflict. Fixes LM-55.
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 297
diff changeset
   848
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
   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
    LmMessageNode *node, *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
   851
    LmDisconnectReason reason;
306
d466fc30829f Added disconnect error for resource conflict. Fixes LM-55.
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 297
diff changeset
   852
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   853
    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
   854
    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
   855
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   856
    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
   857
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   858
    /* 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
   859
    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
   860
    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
   861
        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
   862
        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
   863
        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
   864
    }
306
d466fc30829f Added disconnect error for resource conflict. Fixes LM-55.
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 297
diff changeset
   865
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   866
    /* 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
   867
    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
   868
    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
   869
        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
   870
        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
   871
        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
   872
    }
306
d466fc30829f Added disconnect error for resource conflict. Fixes LM-55.
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 297
diff changeset
   873
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   874
    lm_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
   875
    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
   876
    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
   877
                                                                     "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
   878
    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
   879
    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
   880
}
d466fc30829f Added disconnect error for resource conflict. Fixes LM-55.
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 297
diff changeset
   881
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   882
static gint
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   883
connection_handler_compare_func (HandlerData *a, HandlerData *b)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   884
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   885
    return b->priority - a->priority;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   886
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   887
256
2266e56746ed Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 255
diff changeset
   888
static void
2266e56746ed Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 255
diff changeset
   889
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
   890
                              LmDisconnectReason  reason)
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
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
    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
   893
        LmCallback *cb = 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
   894
        
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   895
        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
   896
        (* ((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
   897
                                               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
   898
                                               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
   899
        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
   900
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   901
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   902
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   903
static void
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   904
connection_incoming_data (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
   905
                          const gchar  *buf, 
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   906
                          LmConnection *connection)
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   907
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   908
    lm_parser_parse (connection->parser, buf);
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   909
}
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   910
256
2266e56746ed Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 255
diff changeset
   911
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
   912
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
   913
                             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
   914
                             LmConnection       *connection)
256
2266e56746ed Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 255
diff changeset
   915
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   916
    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
   917
    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
   918
}
2266e56746ed Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 255
diff changeset
   919
2266e56746ed Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 255
diff changeset
   920
static void
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   921
connection_socket_connect_cb (LmOldSocket  *socket,
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   922
                              gboolean      result,
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   923
                              LmConnection *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
    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
   926
        connection_do_close (connection);
256
2266e56746ed Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 255
diff changeset
   927
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   928
        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
   929
            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
   930
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   931
            connection->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
   932
            
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   933
            (* ((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
   934
                                               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
   935
            _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
   936
        }
cdd6a0c5b439 Went 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
    
cdd6a0c5b439 Went 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
        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
   939
    }
cdd6a0c5b439 Went 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
    
cdd6a0c5b439 Went 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
    /* 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
   942
    /*        StartTLS and the like */
cdd6a0c5b439 Went 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
    if (!connection_send (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
   944
                          "<?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
   945
                          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
   946
        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
   947
        connection_do_close (connection);
256
2266e56746ed Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 255
diff changeset
   948
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   949
        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
   950
    }
256
2266e56746ed Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 255
diff changeset
   951
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   952
    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
   953
}
2266e56746ed Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 255
diff changeset
   954
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
   955
static gboolean
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   956
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
   957
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   958
    gchar *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
   959
    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
   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
    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
   962
        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
   963
        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
   964
            *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
   965
        } 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
   966
            *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
   967
        }
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
   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
        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
   970
    } 
cdd6a0c5b439 Went 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
    
cdd6a0c5b439 Went 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
    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
   973
}
df2655dbe873 Make LmConnection accept not having a server set as long as JID is set.
Mikael Hallendal <micke@imendio.com>
parents: 244
diff changeset
   974
248
09a3e0e55ab8 Refactored sending of the stream header.
Mikael Hallendal <micke@imendio.com>
parents: 247
diff changeset
   975
static void
09a3e0e55ab8 Refactored sending of the stream header.
Mikael Hallendal <micke@imendio.com>
parents: 247
diff changeset
   976
connection_send_stream_header (LmConnection *connection)
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   977
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   978
    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
   979
    gchar     *server_from_jid;
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   980
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   981
    lm_verbose ("Sending stream header\n");
248
09a3e0e55ab8 Refactored sending of the stream header.
Mikael Hallendal <micke@imendio.com>
parents: 247
diff changeset
   982
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   983
    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
   984
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   985
    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
   986
    lm_message_node_set_attributes (m->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
   987
                                    "xmlns: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
   988
                                    "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
   989
                                    "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
   990
                                    "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
   991
                                    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
   992
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   993
    g_free (server_from_jid);
248
09a3e0e55ab8 Refactored sending of the stream header.
Mikael Hallendal <micke@imendio.com>
parents: 247
diff changeset
   994
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   995
    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
   996
        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
   997
        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
   998
    }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   999
        
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1000
    lm_message_unref (m);
248
09a3e0e55ab8 Refactored sending of the stream header.
Mikael Hallendal <micke@imendio.com>
parents: 247
diff changeset
  1001
}
09a3e0e55ab8 Refactored sending of the stream header.
Mikael Hallendal <micke@imendio.com>
parents: 247
diff changeset
  1002
500
915cd386918e Added _lm_connection_get_context as internal function.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
  1003
GMainContext *
915cd386918e Added _lm_connection_get_context as internal function.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
  1004
_lm_connection_get_context (LmConnection *conn)
915cd386918e Added _lm_connection_get_context as internal function.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
  1005
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1006
    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
  1007
518
cdd6a0c5b439 Went 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
    return conn->context;
500
915cd386918e Added _lm_connection_get_context as internal function.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
  1009
}
915cd386918e Added _lm_connection_get_context as internal function.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
  1010
501
5f71592beac8 Added _lm_connection_get_server that returns the server string.
Mikael Hallendal <micke@imendio.com>
parents: 500
diff changeset
  1011
gchar *
5f71592beac8 Added _lm_connection_get_server that returns the server string.
Mikael Hallendal <micke@imendio.com>
parents: 500
diff changeset
  1012
_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
  1013
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1014
    gchar *server;
501
5f71592beac8 Added _lm_connection_get_server that returns the server string.
Mikael Hallendal <micke@imendio.com>
parents: 500
diff changeset
  1015
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1016
    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
  1017
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1018
    if (!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
  1019
        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
  1020
    }
501
5f71592beac8 Added _lm_connection_get_server that returns the server string.
Mikael Hallendal <micke@imendio.com>
parents: 500
diff changeset
  1021
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1022
    return server;
501
5f71592beac8 Added _lm_connection_get_server that returns the server string.
Mikael Hallendal <micke@imendio.com>
parents: 500
diff changeset
  1023
}
5f71592beac8 Added _lm_connection_get_server that returns the server string.
Mikael Hallendal <micke@imendio.com>
parents: 500
diff changeset
  1024
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
  1025
gboolean 
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
  1026
_lm_connection_async_connect_waiting (LmConnection *connection)
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
  1027
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1028
    return connection->async_connect_waiting;
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
  1029
}
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
  1030
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
  1031
void
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
  1032
_lm_connection_set_async_connect_waiting (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
  1033
                                          gboolean      waiting)
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
  1034
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1035
    connection->async_connect_waiting = waiting;
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
  1036
}
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
  1037
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1038
static void
222
ca97251ddee8 Renamed internal functions to conform to code style.
Mikael Hallendal <micke@imendio.com>
parents: 221
diff changeset
  1039
connection_call_auth_cb (LmConnection *connection, gboolean success)
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  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
    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
  1042
        connection->state = LM_CONNECTION_STATE_AUTHENTICATED;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1043
    } 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
  1044
        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
  1045
    }
226
5a31f474b9fd Update the connection state after SASL authentication result.
Mikael Hallendal <micke@imendio.com>
parents: 223
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
    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
  1048
        LmCallback *cb = connection->auth_cb;
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  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
        connection->auth_cb = NULL;
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1051
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1052
        if (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
  1053
            (* ((LmResultFunction) 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
  1054
                                               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
  1055
                                               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
  1056
        }
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1057
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1058
        _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
  1059
    }
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1060
}
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1061
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1062
static LmHandlerResult
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1063
connection_bind_reply (LmMessageHandler *handler,
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
  1064
                       LmConnection     *connection,
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
  1065
                       LmMessage        *message,
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
  1066
                       gpointer          user_data)
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1067
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1068
    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
  1069
    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
  1070
    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
  1071
    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
  1072
    LmMessageSubType  type;
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1073
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1074
    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
  1075
    if (type == LM_MESSAGE_SUB_TYPE_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
  1076
        g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_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
  1077
               "%s: error while binding to resource\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
  1078
    
cdd6a0c5b439 Went 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
        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
  1080
        
cdd6a0c5b439 Went 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
        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
  1082
    }
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1083
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1084
    /* 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
  1085
    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
  1086
    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
  1087
        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
  1088
        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
  1089
            (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
  1090
    }
297
f65eee8ec802 Support for returning effective JID, possibly changed by the server.
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 294
diff changeset
  1091
f65eee8ec802 Support for returning effective JID, possibly changed by the server.
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 294
diff changeset
  1092
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1093
    m = lm_message_new_with_sub_type (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
  1094
                                      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
  1095
                                      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
  1096
518
cdd6a0c5b439 Went 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
    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
  1098
    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
  1099
                                    "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
  1100
                                    NULL);
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1101
518
cdd6a0c5b439 Went 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
    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
  1103
    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
  1104
    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
  1105
        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
  1106
    }
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1107
518
cdd6a0c5b439 Went 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
    /* 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
  1109
    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
  1110
518
cdd6a0c5b439 Went 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
    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
  1112
}
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1113
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1114
static LmHandlerResult
256
2266e56746ed Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 255
diff changeset
  1115
connection_features_cb (LmMessageHandler *handler,
412
d355b566f141 Fixed indentation
Mikael Hallendal <micke@imendio.com>
parents: 411
diff changeset
  1116
                        LmConnection     *connection,
d355b566f141 Fixed indentation
Mikael Hallendal <micke@imendio.com>
parents: 411
diff changeset
  1117
                        LmMessage        *message,
d355b566f141 Fixed indentation
Mikael Hallendal <micke@imendio.com>
parents: 411
diff changeset
  1118
                        gpointer          user_data)
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1119
{
518
cdd6a0c5b439 Went 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
    LmMessageNode *bind_node;
530
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 529
diff changeset
  1121
    LmMessageNode *starttls_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
  1122
    LmMessageNode *old_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
  1123
    LmMessageNode *sasl_mechanisms;
cdd6a0c5b439 Went 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
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1125
    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
  1126
    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
  1127
        if (starttls_node) {
530
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 529
diff changeset
  1128
            LmMessage *msg;
274
c32a7011e435 Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents: 271
diff changeset
  1129
518
cdd6a0c5b439 Went 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
            msg = lm_message_new (NULL, LM_MESSAGE_TYPE_STARTTLS);
274
c32a7011e435 Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents: 271
diff changeset
  1131
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1132
            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
  1133
                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
  1134
                "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
  1135
                NULL);
274
c32a7011e435 Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents: 271
diff changeset
  1136
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1137
            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
  1138
            lm_message_unref (msg);
274
c32a7011e435 Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents: 271
diff changeset
  1139
518
cdd6a0c5b439 Went 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
            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
  1141
        } 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
  1142
                   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
  1143
            /* 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
  1144
             * the place to scream. */
274
c32a7011e435 Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents: 271
diff changeset
  1145
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1146
            g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_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
  1147
                   "%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
  1148
            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
  1149
            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
  1150
                                          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
  1151
            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
  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
    }
274
c32a7011e435 Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents: 271
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
    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
  1156
    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
  1157
        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
  1158
        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
  1159
        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
  1160
        int               result;
223
b343ed8b3fea More style fixes to the SASL patch
Mikael Hallendal <micke@imendio.com>
parents: 222
diff changeset
  1161
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1162
        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
  1163
        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
  1164
            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
  1165
        }
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1166
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1167
        bind_msg = lm_message_new_with_sub_type (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
  1168
                                                 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
  1169
                                                 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
  1170
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1171
        bind_node = lm_message_node_add_child (bind_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
  1172
                                               "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
  1173
        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
  1174
                                        "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
  1175
                                        NULL);
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1176
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1177
        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
  1178
                                   connection->resource);
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1179
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1180
        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
  1181
                                               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
  1182
        result = lm_connection_send_with_reply (connection, 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
  1183
                                                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
  1184
        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
  1185
        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
  1186
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1187
        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
  1188
            g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_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
  1189
                   "%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
  1190
            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
  1191
        }
cdd6a0c5b439 Went 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
    }
220
f6b9482ae89e Some style fixes to the SASL patch.
Mikael Hallendal <micke@imendio.com>
parents: 219
diff changeset
  1193
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1194
    old_auth = lm_message_node_find_child (message->node, "auth");
510
3f6ec5ce4b1d Use SASL before old style auth if both are supported. [#19]
Jelmer Vernooij <jelmer@samba.org>
parents: 508
diff changeset
  1195
518
cdd6a0c5b439 Went 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
    sasl_mechanisms = lm_message_node_find_child (message->node, "mechanisms");
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1197
    if (connection->use_sasl && old_auth != NULL && sasl_mechanisms == 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
  1198
        g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_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
  1199
               "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
  1200
        /* 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
  1201
         * 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
  1202
518
cdd6a0c5b439 Went 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
        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
  1204
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1205
        if (connection->sasl) {
530
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 529
diff changeset
  1206
            const gchar *user;
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 529
diff changeset
  1207
            const gchar *pass;
332
6b6ad42cd508 Support obsolete XEP-0078 (old-style jabber auth for XMPP1.0).
Senko Rasic <senko@phyrexia.lan>
parents: 329
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
            lm_sasl_get_auth_params (connection->sasl, &user, &pass);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1210
            if (user && pass) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1211
                GError *error = 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
  1212
                connection_old_auth (connection, user, pass,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1213
                                     connection->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
  1214
                                     &error);
332
6b6ad42cd508 Support obsolete XEP-0078 (old-style jabber auth for XMPP1.0).
Senko Rasic <senko@phyrexia.lan>
parents: 329
diff changeset
  1215
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1216
                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
  1217
                    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
  1218
                }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1219
            }
332
6b6ad42cd508 Support obsolete XEP-0078 (old-style jabber auth for XMPP1.0).
Senko Rasic <senko@phyrexia.lan>
parents: 329
diff changeset
  1220
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1221
            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
  1222
            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
  1223
        }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1224
    }
332
6b6ad42cd508 Support obsolete XEP-0078 (old-style jabber auth for XMPP1.0).
Senko Rasic <senko@phyrexia.lan>
parents: 329
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
    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
  1227
}
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1228
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1229
/**
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1230
 * lm_connection_new:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1231
 * @server: The hostname to the server for the connection.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1232
 * 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1233
 * Creates a new closed connection. To open the connection call 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1234
 * lm_connection_open(). @server can be #NULL but must be set before calling lm_connection_open().
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1235
 * 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1236
 * Return value: A newly created LmConnection, should be unreffed with lm_connection_unref().
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1237
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1238
LmConnection *
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1239
lm_connection_new (const gchar *server)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1240
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1241
    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
  1242
    gint          i;
422
1c00df7a8b11 Depend on GObject and initialize GType
Mikael Hallendal <micke@imendio.com>
parents: 421
diff changeset
  1243
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1244
    g_type_init (); /* Ensure that the GLib type library is initialized */
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1245
    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
  1246
    _lm_sock_library_init ();
140
103227122f45 2006-04-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 137
diff changeset
  1247
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1248
    connection = g_slice_new0 (LmConnection);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1249
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1250
    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
  1251
        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
  1252
    } 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
  1253
        connection->use_srv = 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
  1254
    }
82
a32b54e654e2 2004-03-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 80
diff changeset
  1255
532
c917a1900d5c Style fix in lm_connection_new
Mikael Hallendal <micke@imendio.com>
parents: 531
diff changeset
  1256
    connection->port        = LM_CONNECTION_DEFAULT_PORT;
c917a1900d5c Style fix in lm_connection_new
Mikael Hallendal <micke@imendio.com>
parents: 531
diff changeset
  1257
    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
  1258
                                                          connection);
532
c917a1900d5c Style fix in lm_connection_new
Mikael Hallendal <micke@imendio.com>
parents: 531
diff changeset
  1259
    connection->state       = LM_CONNECTION_STATE_CLOSED;
518
cdd6a0c5b439 Went 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
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1261
    connection->id_handlers = g_hash_table_new_full (g_str_hash, 
cdd6a0c5b439 Went 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
                                                     g_str_equal,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1263
                                                     g_free, 
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1264
                                                     (GDestroyNotify) lm_message_handler_unref);
532
c917a1900d5c Style fix in lm_connection_new
Mikael Hallendal <micke@imendio.com>
parents: 531
diff changeset
  1265
    connection->ref_count   = 1;
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1266
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1267
    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
  1268
        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
  1269
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1270
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1271
    connection->parser = lm_parser_new 
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1272
        ((LmParserMessageFunction) connection_new_message_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
  1273
         connection, NULL);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1274
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1275
    return connection;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1276
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1277
82
a32b54e654e2 2004-03-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 80
diff changeset
  1278
/**
a32b54e654e2 2004-03-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 80
diff changeset
  1279
 * lm_connection_new_with_context:
a32b54e654e2 2004-03-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 80
diff changeset
  1280
 * @server: The hostname to the server for the connection.
a32b54e654e2 2004-03-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 80
diff changeset
  1281
 * @context: The context this connection should be running in.
a32b54e654e2 2004-03-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 80
diff changeset
  1282
 * 
a32b54e654e2 2004-03-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 80
diff changeset
  1283
 * Creates a new closed connection running in a certain context. To open the 
a32b54e654e2 2004-03-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 80
diff changeset
  1284
 * connection call #lm_connection_open. @server can be #NULL but must be set 
a32b54e654e2 2004-03-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 80
diff changeset
  1285
 * before calling #lm_connection_open.
a32b54e654e2 2004-03-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 80
diff changeset
  1286
 * 
a32b54e654e2 2004-03-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 80
diff changeset
  1287
 * 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
  1288
 **/
a32b54e654e2 2004-03-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 80
diff changeset
  1289
LmConnection *
a32b54e654e2 2004-03-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 80
diff changeset
  1290
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
  1291
{
518
cdd6a0c5b439 Went 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
    LmConnection *connection;
82
a32b54e654e2 2004-03-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 80
diff changeset
  1293
518
cdd6a0c5b439 Went 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
    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
  1295
    connection->context = context;
82
a32b54e654e2 2004-03-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 80
diff changeset
  1296
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1297
    if (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
  1298
        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
  1299
    }
82
a32b54e654e2 2004-03-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 80
diff changeset
  1300
518
cdd6a0c5b439 Went 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
    return connection;
82
a32b54e654e2 2004-03-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 80
diff changeset
  1302
}
63
7b8d0db459ff 2004-01-05 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 62
diff changeset
  1303
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1304
/**
62
39b83ccd70ff 2003-12-27 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 61
diff changeset
  1305
 * lm_connection_open:
39b83ccd70ff 2003-12-27 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 61
diff changeset
  1306
 * @connection: #LmConnection to open
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1307
 * @function: Callback function that will be called when the connection is open.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1308
 * @user_data: User data that will be passed to @function.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1309
 * @notify: Function for freeing that user_data, can be NULL.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1310
 * @error: location to store error, or %NULL
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1311
 * 
62
39b83ccd70ff 2003-12-27 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 61
diff changeset
  1312
 * An async call to open @connection. When the connection is open @function will be called.
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1313
 * 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1314
 * Return value: #TRUE if everything went fine, otherwise #FALSE.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1315
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1316
gboolean
62
39b83ccd70ff 2003-12-27 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 61
diff changeset
  1317
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
  1318
                    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
  1319
                    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
  1320
                    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
  1321
                    GError           **error)
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
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
    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
  1324
    
cdd6a0c5b439 Went 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 = _lm_utils_new_callback (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
  1326
                                                  user_data, 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
  1327
    connection->blocking = FALSE;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1328
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1329
    return connection_do_open (connection, error);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1330
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1331
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1332
/**
62
39b83ccd70ff 2003-12-27 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 61
diff changeset
  1333
 * lm_connection_open_and_block:
39b83ccd70ff 2003-12-27 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 61
diff changeset
  1334
 * @connection: an #LmConnection to open
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1335
 * @error: location to store error, or %NULL
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1336
 * 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1337
 * Opens @connection and waits until the stream is setup. 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1338
 * 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1339
 * Return value: #TRUE if no errors where encountered during opening and stream setup successfully, #FALSE otherwise.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1340
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1341
gboolean
62
39b83ccd70ff 2003-12-27 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 61
diff changeset
  1342
lm_connection_open_and_block (LmConnection *connection, GError **error)
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1343
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1344
    gboolean          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
  1345
    LmConnectionState state;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1346
    
cdd6a0c5b439 Went 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);
57
6b168a8917f7 2003-12-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 56
diff changeset
  1348
518
cdd6a0c5b439 Went 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
    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
  1350
    connection->blocking = TRUE;
140
103227122f45 2006-04-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 137
diff changeset
  1351
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1352
    result = connection_do_open (connection, error);
63
7b8d0db459ff 2004-01-05 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 62
diff changeset
  1353
518
cdd6a0c5b439 Went 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
    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
  1355
        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
  1356
    }
cdd6a0c5b439 Went 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
        
cdd6a0c5b439 Went 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
    while ((state = lm_connection_get_state (connection)) == 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
  1359
        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
  1360
            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
  1361
        } 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
  1362
            /* 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
  1363
            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
  1364
        }
cdd6a0c5b439 Went 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
    }
64
dd835d5cee71 2004-01-06 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 63
diff changeset
  1366
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1367
    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
  1368
        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
  1369
        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
  1370
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
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
    /* 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
  1373
    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
  1374
                 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
  1375
                 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
  1376
                 "Opening the connection failed");
132
8c9c1629f691 2006-03-20 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 130
diff changeset
  1377
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1378
    return FALSE;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1379
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1380
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1381
/**
59
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  1382
 * lm_connection_cancel_open:
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  1383
 * @connection: an #LmConnection to cancel opening on
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  1384
 *
91
d51b8e4f43d9 2004-08-27 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 90
diff changeset
  1385
 * 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
  1386
 **/
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  1387
void
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  1388
lm_connection_cancel_open (LmConnection *connection)
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
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
    g_return_if_fail (connection != NULL);
59
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  1391
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1392
    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
  1393
        _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
  1394
        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
  1395
    }
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
  1396
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1397
    connection->cancel_open = TRUE;
271
52ea4e0b897a Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents: 256
diff changeset
  1398
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1399
    lm_old_socket_asyncns_cancel (connection->socket);
57
6b168a8917f7 2003-12-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 56
diff changeset
  1400
}
6b168a8917f7 2003-12-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 56
diff changeset
  1401
6b168a8917f7 2003-12-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 56
diff changeset
  1402
/**
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1403
 * lm_connection_close:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1404
 * @connection: #LmConnection to close 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1405
 * @error: location to store error, or %NULL
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1406
 * 
56
3bf928955fc5 2003-11-20 Ross Burton <ross@burtonini.com>
hallski <hallski>
parents: 55
diff changeset
  1407
 * 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().
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1408
 * 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1409
 * Return value: Returns #TRUE if no errors where detected, otherwise #FALSE.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1410
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1411
gboolean
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
  1412
lm_connection_close (LmConnection *connection, GError **error)
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1413
{
518
cdd6a0c5b439 Went 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
    gboolean no_errors = 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
  1415
    
cdd6a0c5b439 Went 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
    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
  1417
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1418
    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
  1419
        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
  1420
    }
156
8c054d9e98b8 2006-06-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 155
diff changeset
  1421
518
cdd6a0c5b439 Went 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
    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
  1423
        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
  1424
                     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
  1425
                     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
  1426
                     "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
  1427
        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
  1428
    }
cdd6a0c5b439 Went 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
cdd6a0c5b439 Went 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_verbose ("Disconnecting from: %s:%d\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
  1431
                connection->server, 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
  1432
    
cdd6a0c5b439 Went 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
    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
  1434
        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
  1435
            no_errors = FALSE;
503
c7c1722ec2db Fixed a crash when lm_connection_close was called.
Mikael Hallendal <micke@imendio.com>
parents: 501
diff changeset
  1436
        }
271
52ea4e0b897a Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents: 256
diff changeset
  1437
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1438
        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
  1439
    }
cdd6a0c5b439 Went 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
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1441
    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
  1442
    connection_signal_disconnect (connection, LM_DISCONNECT_REASON_OK);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1443
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1444
    return no_errors;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1445
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1446
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1447
static void
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
  1448
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
  1449
                               LmConnection *connection,
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
  1450
                               gboolean      success,
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
  1451
                               const gchar  *reason)
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1452
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1453
    if (!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
  1454
        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
  1455
        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
  1456
        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
  1457
    }
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1458
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1459
    connection_send_stream_header (connection);
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1460
}
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1461
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1462
/**
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1463
 * lm_connection_authenticate:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1464
 * @connection: #LmConnection to authenticate.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1465
 * @username: Username used to authenticate.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1466
 * @password: Password corresponding to @username.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1467
 * @resource: Resource used for this connection.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1468
 * @function: Callback called when authentication is finished.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1469
 * @user_data: Userdata passed to @function when called.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1470
 * @notify: Destroy function to free the memory used by @user_data, can be NULL.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1471
 * @error: location to store error, or %NULL
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1472
 * 
56
3bf928955fc5 2003-11-20 Ross Burton <ross@burtonini.com>
hallski <hallski>
parents: 55
diff changeset
  1473
 * Tries to authenticate a user against the server. The #LmResult in the result callback @function will say whether it succeeded or not. 
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1474
 * 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1475
 * Return value: #TRUE if no errors where detected while sending the authentication message, #FALSE otherwise.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1476
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1477
gboolean
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1478
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
  1479
                            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
  1480
                            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
  1481
                            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
  1482
                            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
  1483
                            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
  1484
                            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
  1485
                            GError           **error)
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1486
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1487
    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
  1488
    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
  1489
    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
  1490
    g_return_val_if_fail (resource != NULL, FALSE);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1491
518
cdd6a0c5b439 Went 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
    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
  1493
        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
  1494
                     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
  1495
                     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
  1496
                     "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
  1497
        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
  1498
    }
59
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  1499
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1500
    connection->state = 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
  1501
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1502
    connection->auth_cb = _lm_utils_new_callback (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
  1503
                                                  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
  1504
                                                  notify);
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
  1505
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1506
    connection->resource = g_strdup (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
  1507
    connection->effective_jid = g_strdup_printf ("%s/%s", 
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1508
                                                 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
  1509
533
c45243823756 Added some TODO items and minor style fixes
Mikael Hallendal <micke@imendio.com>
parents: 532
diff changeset
  1510
    /* 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
  1511
     *       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
  1512
    if (connection->use_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
  1513
        lm_sasl_authenticate (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
  1514
                              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
  1515
                              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
  1516
                              connection_sasl_auth_finished);
255
704881ac7788 Fixed potential problem if auth was not called from the open callback.
Mikael Hallendal <micke@imendio.com>
parents: 249
diff changeset
  1517
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1518
        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
  1519
            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
  1520
                                    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
  1521
        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
  1522
                                                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
  1523
                                                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
  1524
                                                LM_HANDLER_PRIORITY_FIRST);
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1525
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1526
        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
  1527
    }
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1528
518
cdd6a0c5b439 Went 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
    return connection_old_auth (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
  1530
                                resource, error);
332
6b6ad42cd508 Support obsolete XEP-0078 (old-style jabber auth for XMPP1.0).
Senko Rasic <senko@phyrexia.lan>
parents: 329
diff changeset
  1531
}
6b6ad42cd508 Support obsolete XEP-0078 (old-style jabber auth for XMPP1.0).
Senko Rasic <senko@phyrexia.lan>
parents: 329
diff changeset
  1532
415
14ff0a255a86 Moved _lm_connection_old_auth from public header file.
Mikael Hallendal <micke@imendio.com>
parents: 413
diff changeset
  1533
static gboolean
14ff0a255a86 Moved _lm_connection_old_auth from public header file.
Mikael Hallendal <micke@imendio.com>
parents: 413
diff changeset
  1534
connection_old_auth (LmConnection  *connection,
14ff0a255a86 Moved _lm_connection_old_auth from public header file.
Mikael Hallendal <micke@imendio.com>
parents: 413
diff changeset
  1535
                     const gchar   *username,
14ff0a255a86 Moved _lm_connection_old_auth from public header file.
Mikael Hallendal <micke@imendio.com>
parents: 413
diff changeset
  1536
                     const gchar   *password,
14ff0a255a86 Moved _lm_connection_old_auth from public header file.
Mikael Hallendal <micke@imendio.com>
parents: 413
diff changeset
  1537
                     const gchar   *resource, 
14ff0a255a86 Moved _lm_connection_old_auth from public header file.
Mikael Hallendal <micke@imendio.com>
parents: 413
diff changeset
  1538
                     GError       **error)
332
6b6ad42cd508 Support obsolete XEP-0078 (old-style jabber auth for XMPP1.0).
Senko Rasic <senko@phyrexia.lan>
parents: 329
diff changeset
  1539
{
518
cdd6a0c5b439 Went 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
    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
  1541
    AuthReqData      *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
  1542
    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
  1543
    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
  1544
    
332
6b6ad42cd508 Support obsolete XEP-0078 (old-style jabber auth for XMPP1.0).
Senko Rasic <senko@phyrexia.lan>
parents: 329
diff changeset
  1545
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1546
    m = connection_create_auth_req_msg (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
  1547
        
cdd6a0c5b439 Went 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
    data = g_new0 (AuthReqData, 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
  1549
    data->username = g_strdup (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
  1550
    data->password = g_strdup (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
  1551
    data->resource = g_strdup (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
  1552
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1553
    handler = lm_message_handler_new (connection_auth_req_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
  1554
                                      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
  1555
                                      (GDestroyNotify) auth_req_data_free);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1556
    result = lm_connection_send_with_reply (connection, m, handler, 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
  1557
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1558
    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
  1559
    lm_message_unref (m);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1560
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1561
    return result;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1562
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1563
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1564
/**
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1565
 * lm_connection_authenticate_and_block:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1566
 * @connection: an #LmConnection
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1567
 * @username: Username used to authenticate.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1568
 * @password: Password corresponding to @username.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1569
 * @resource: Resource used for this connection.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1570
 * @error: location to store error, or %NULL
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1571
 * 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1572
 * 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.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1573
 * 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1574
 * Return value: #TRUE if no errors where detected and authentication was successful. #FALSE otherwise.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1575
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1576
gboolean
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1577
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
  1578
                                      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
  1579
                                      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
  1580
                                      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
  1581
                                      GError       **error)
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1582
{
530
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 529
diff changeset
  1583
    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
  1584
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1585
    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
  1586
                                         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
  1587
518
cdd6a0c5b439 Went 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
    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
  1589
        return result;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1590
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1591
    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
  1592
        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
  1593
            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
  1594
        } 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
  1595
            /* 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
  1596
            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
  1597
        }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1598
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1599
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1600
    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
  1601
    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
  1602
        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
  1603
        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
  1604
    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
  1605
        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
  1606
                     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
  1607
                     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
  1608
                     "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
  1609
        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
  1610
        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
  1611
    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
  1612
        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
  1613
        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
  1614
    } 
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1615
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1616
    return FALSE;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1617
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1618
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1619
/**
394
03933ba2fb40 Added lm_connection_get_keep_alive.
Mikael Hallendal <micke@imendio.com>
parents: 345
diff changeset
  1620
 * lm_connection_get_keep_alive_rate:
03933ba2fb40 Added lm_connection_get_keep_alive.
Mikael Hallendal <micke@imendio.com>
parents: 345
diff changeset
  1621
 * @connection: an #LmConnection 
03933ba2fb40 Added lm_connection_get_keep_alive.
Mikael Hallendal <micke@imendio.com>
parents: 345
diff changeset
  1622
 *
03933ba2fb40 Added lm_connection_get_keep_alive.
Mikael Hallendal <micke@imendio.com>
parents: 345
diff changeset
  1623
 * 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
  1624
 *
03933ba2fb40 Added lm_connection_get_keep_alive.
Mikael Hallendal <micke@imendio.com>
parents: 345
diff changeset
  1625
 * Since 1.3.5
03933ba2fb40 Added lm_connection_get_keep_alive.
Mikael Hallendal <micke@imendio.com>
parents: 345
diff changeset
  1626
 **/
03933ba2fb40 Added lm_connection_get_keep_alive.
Mikael Hallendal <micke@imendio.com>
parents: 345
diff changeset
  1627
guint
03933ba2fb40 Added lm_connection_get_keep_alive.
Mikael Hallendal <micke@imendio.com>
parents: 345
diff changeset
  1628
lm_connection_get_keep_alive_rate (LmConnection *connection)
03933ba2fb40 Added lm_connection_get_keep_alive.
Mikael Hallendal <micke@imendio.com>
parents: 345
diff changeset
  1629
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1630
    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
  1631
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1632
    return connection->keep_alive_rate;
394
03933ba2fb40 Added lm_connection_get_keep_alive.
Mikael Hallendal <micke@imendio.com>
parents: 345
diff changeset
  1633
}
03933ba2fb40 Added lm_connection_get_keep_alive.
Mikael Hallendal <micke@imendio.com>
parents: 345
diff changeset
  1634
03933ba2fb40 Added lm_connection_get_keep_alive.
Mikael Hallendal <micke@imendio.com>
parents: 345
diff changeset
  1635
/**
90
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
  1636
 * lm_connection_set_keep_alive_rate:
394
03933ba2fb40 Added lm_connection_get_keep_alive.
Mikael Hallendal <micke@imendio.com>
parents: 345
diff changeset
  1637
 * @connection: an #LmConnection
90
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
  1638
 * @rate: Number of seconds between keep alive packages are sent.
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
  1639
 * 
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
  1640
 * 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
  1641
 * A keep alive message is a single space character.
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
  1642
 **/
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
  1643
void
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
  1644
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
  1645
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1646
    g_return_if_fail (connection != NULL);
90
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
  1647
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1648
    connection_stop_keep_alive (connection);
90
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
  1649
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1650
    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
  1651
        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
  1652
    }
90
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
  1653
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1654
    connection->keep_alive_rate = 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
  1655
    
cdd6a0c5b439 Went 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
    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
  1657
        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
  1658
    }
90
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
  1659
}
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
  1660
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
  1661
/**
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1662
 * lm_connection_is_open:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1663
 * @connection: #LmConnection to check if it is open.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1664
 * 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1665
 * Check if the @connection is currently open.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1666
 * 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1667
 * Return value: #TRUE if connection is open and #FALSE if it is closed.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1668
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1669
gboolean
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1670
lm_connection_is_open (LmConnection *connection)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1671
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1672
    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
  1673
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1674
    return connection->state >= LM_CONNECTION_STATE_OPEN;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1675
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1676
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1677
/**
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1678
 * lm_connection_is_authenticated:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1679
 * @connection: #LmConnection to check if it is authenticated
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1680
 * 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1681
 * Check if @connection is authenticated.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1682
 * 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1683
 * Return value: #TRUE if connection is authenticated, #FALSE otherwise.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1684
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1685
gboolean 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1686
lm_connection_is_authenticated (LmConnection *connection)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1687
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1688
    g_return_val_if_fail (connection != NULL, FALSE);
66
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1689
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1690
    return connection->state >= LM_CONNECTION_STATE_AUTHENTICATED;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1691
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1692
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1693
/**
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1694
 * lm_connection_get_server:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1695
 * @connection: an #LmConnection
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1696
 * 
89
e756a937e540 2004-08-09 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 87
diff changeset
  1697
 * Fetches the server address that @connection is using. 
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1698
 * 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1699
 * Return value: the server address
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1700
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1701
const gchar *
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1702
lm_connection_get_server (LmConnection *connection)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1703
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1704
    g_return_val_if_fail (connection != NULL, NULL);
66
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1705
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1706
    return connection->server;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1707
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1708
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1709
/**
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1710
 * lm_connection_set_server:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1711
 * @connection: an #LmConnection
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1712
 * @server: Address of the server
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1713
 * 
87
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
  1714
 * Sets the server address for @connection to @server. Notice that @connection
89
e756a937e540 2004-08-09 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 87
diff changeset
  1715
 * can't be open while doing this. 
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1716
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1717
void
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1718
lm_connection_set_server (LmConnection *connection, const gchar *server)
50e230cf7818 Initial revision
hallski <hallski>
parents:
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_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
  1721
    g_return_if_fail (server != 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
  1722
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1723
    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
  1724
        g_warning ("Can't change server address while connected");
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1725
        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
  1726
    }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1727
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1728
    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
  1729
    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
  1730
    connection->use_srv = FALSE;
87
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
  1731
}
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
  1732
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
  1733
/**
89
e756a937e540 2004-08-09 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 87
diff changeset
  1734
 * lm_connection_get_jid:
87
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
  1735
 * @connection: an #LmConnection
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
  1736
 * 
89
e756a937e540 2004-08-09 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 87
diff changeset
  1737
 * Fetches the jid set for @connection is using. 
87
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
  1738
 * 
89
e756a937e540 2004-08-09 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 87
diff changeset
  1739
 * Return value: the jid
87
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
  1740
 **/
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
  1741
const gchar *
89
e756a937e540 2004-08-09 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 87
diff changeset
  1742
lm_connection_get_jid (LmConnection *connection)
87
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
  1743
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1744
    g_return_val_if_fail (connection != NULL, NULL);
87
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
  1745
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1746
    return connection->jid;
87
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
  1747
}
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
  1748
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
  1749
/**
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
  1750
 * 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
  1751
 * @connection: an #LmConnection
f65eee8ec802 Support for returning effective JID, possibly changed by the server.
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 294
diff changeset
  1752
 * 
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
  1753
 * 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
  1754
 * 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
  1755
 *
f65eee8ec802 Support for returning effective JID, possibly changed by the server.
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 294
diff changeset
  1756
 * 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
  1757
 **/
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
  1758
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
  1759
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
  1760
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1761
    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
  1762
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1763
    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
  1764
}
f65eee8ec802 Support for returning effective JID, possibly changed by the server.
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 294
diff changeset
  1765
f65eee8ec802 Support for returning effective JID, possibly changed by the server.
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 294
diff changeset
  1766
/**
89
e756a937e540 2004-08-09 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 87
diff changeset
  1767
 * lm_connection_set_jid:
87
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
  1768
 * @connection: an #LmConnection
89
e756a937e540 2004-08-09 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 87
diff changeset
  1769
 * @jid: JID to be used for @connection
87
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
  1770
 * 
89
e756a937e540 2004-08-09 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 87
diff changeset
  1771
 * Sets the JID to be used for @connection.
87
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
  1772
 **/
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
  1773
void 
89
e756a937e540 2004-08-09 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 87
diff changeset
  1774
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
  1775
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1776
    g_return_if_fail (connection != NULL);
87
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
  1777
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1778
    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
  1779
        g_warning ("Can't change JID while connected");
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1780
        return;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1781
    }
87
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
  1782
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1783
    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
  1784
    connection->jid = g_strdup (jid);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1785
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1786
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1787
/**
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1788
 * lm_connection_get_port:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1789
 * @connection: an #LmConnection
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1790
 * 
56
3bf928955fc5 2003-11-20 Ross Burton <ross@burtonini.com>
hallski <hallski>
parents: 55
diff changeset
  1791
 * Fetches the port that @connection is using.
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1792
 * 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1793
 * Return value: 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1794
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1795
guint
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1796
lm_connection_get_port (LmConnection *connection)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1797
{
518
cdd6a0c5b439 Went 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
    g_return_val_if_fail (connection != NULL, 0);
66
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1799
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1800
    return connection->port;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1801
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1802
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1803
/**
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1804
 * lm_connection_set_port:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1805
 * @connection: an #LmConnection
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1806
 * @port: server port
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1807
 * 
56
3bf928955fc5 2003-11-20 Ross Burton <ross@burtonini.com>
hallski <hallski>
parents: 55
diff changeset
  1808
 * Sets the server port that @connection will be using.
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1809
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1810
void
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1811
lm_connection_set_port (LmConnection *connection, guint port)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1812
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1813
    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
  1814
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1815
    if (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
  1816
        g_warning ("Can't change server port while connected");
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1817
        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
  1818
    }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1819
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1820
    connection->port = port;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1821
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1822
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1823
/**
68
28203e15de0e 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 67
diff changeset
  1824
 * lm_connection_get_ssl: 
28203e15de0e 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 67
diff changeset
  1825
 * @connection: an #LmConnection
15
1ff2f81867e1 2003-07-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 12
diff changeset
  1826
 *
68
28203e15de0e 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 67
diff changeset
  1827
 * Returns the SSL struct if the connection is using one.
28203e15de0e 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 67
diff changeset
  1828
 * 
28203e15de0e 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 67
diff changeset
  1829
 * 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
  1830
 **/
68
28203e15de0e 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 67
diff changeset
  1831
LmSSL *
28203e15de0e 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 67
diff changeset
  1832
lm_connection_get_ssl (LmConnection *connection)
15
1ff2f81867e1 2003-07-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 12
diff changeset
  1833
{
518
cdd6a0c5b439 Went 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
    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
  1835
    
cdd6a0c5b439 Went 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
    return connection->ssl;
15
1ff2f81867e1 2003-07-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 12
diff changeset
  1837
}
68
28203e15de0e 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 67
diff changeset
  1838
28203e15de0e 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 67
diff changeset
  1839
/**
28203e15de0e 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 67
diff changeset
  1840
 * lm_connection_set_ssl:
28203e15de0e 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 67
diff changeset
  1841
 * @connection: An #LmConnection
28203e15de0e 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 67
diff changeset
  1842
 * @ssl: An #LmSSL
28203e15de0e 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 67
diff changeset
  1843
 *
28203e15de0e 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 67
diff changeset
  1844
 * 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
  1845
 */
39b83ccd70ff 2003-12-27 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 61
diff changeset
  1846
void
68
28203e15de0e 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 67
diff changeset
  1847
lm_connection_set_ssl (LmConnection *connection, LmSSL *ssl)
62
39b83ccd70ff 2003-12-27 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 61
diff changeset
  1848
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1849
    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
  1850
    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
  1851
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1852
    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
  1853
        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
  1854
    }
66
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1855
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1856
    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
  1857
        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
  1858
    } 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
  1859
        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
  1860
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1861
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1862
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1863
/**
66
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1864
 * lm_connection_get_proxy: 
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1865
 * @connection: an #LmConnection
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1866
 *
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1867
 * Returns the proxy if the connection is using one.
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1868
 * 
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1869
 * 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
  1870
 **/
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1871
LmProxy *
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1872
lm_connection_get_proxy (LmConnection *connection)
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1873
{
518
cdd6a0c5b439 Went 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_return_val_if_fail (connection != NULL, NULL);
66
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
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 connection->proxy;
66
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1877
} 
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1878
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1879
/**
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1880
 * lm_connection_set_proxy: 
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1881
 * @connection: an #LmConnection
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1882
 * @proxy: an #LmProxy
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1883
 *
94
85b606ac2c0c 2004-09-02 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 93
diff changeset
  1884
 * Sets the proxy to use for this connection. To unset pass #NULL.
66
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1885
 * 
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1886
 **/
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1887
void
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1888
lm_connection_set_proxy (LmConnection *connection, LmProxy *proxy)
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1889
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1890
    g_return_if_fail (connection != NULL);
66
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1891
518
cdd6a0c5b439 Went 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
    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
  1893
        g_warning ("Can't change server proxy while connected");
cdd6a0c5b439 Went 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
        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
  1895
    }
87
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
  1896
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1897
    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
  1898
        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
  1899
        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
  1900
    }
66
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
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 (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
  1903
        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
  1904
    }
66
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1905
}
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1906
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1907
/**
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1908
 * lm_connection_send: 
56
3bf928955fc5 2003-11-20 Ross Burton <ross@burtonini.com>
hallski <hallski>
parents: 55
diff changeset
  1909
 * @connection: #LmConnection to send message over.
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1910
 * @message: #LmMessage to send.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1911
 * @error: location to store error, or %NULL
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1912
 * 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1913
 * Asynchronous call to send a message.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1914
 * 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1915
 * Return value: Returns #TRUE if no errors where detected while sending, #FALSE otherwise.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1916
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1917
gboolean
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1918
lm_connection_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
  1919
                    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
  1920
                    GError       **error)
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1921
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1922
    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
  1923
    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
  1924
    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
  1925
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1926
    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
  1927
    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
  1928
518
cdd6a0c5b439 Went 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
    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
  1930
    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
  1931
        *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
  1932
    }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1933
    
cdd6a0c5b439 Went 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
    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
  1935
    g_free (xml_str);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
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
    return result;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1938
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1939
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1940
/**
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1941
 * lm_connection_send_with_reply:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1942
 * @connection: #LmConnection used to send message.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1943
 * @message: #LmMessage to send.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1944
 * @handler: #LmMessageHandler that will be used when a reply to @message arrives
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1945
 * @error: location to store error, or %NULL
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1946
 * 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1947
 * Send a #LmMessage which will result in a reply. 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1948
 * 
56
3bf928955fc5 2003-11-20 Ross Burton <ross@burtonini.com>
hallski <hallski>
parents: 55
diff changeset
  1949
 * Return value: Returns #TRUE if no errors where detected while sending, #FALSE otherwise.
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1950
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1951
gboolean 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1952
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
  1953
                               LmMessage         *message,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1954
                               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
  1955
                               GError           **error)
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1956
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1957
    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
  1958
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1959
    g_return_val_if_fail (connection != NULL, 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
  1960
    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
  1961
    g_return_val_if_fail (handler != NULL, FALSE);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1962
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1963
    if (lm_message_node_get_attribute (message->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
  1964
        id = g_strdup (lm_message_node_get_attribute (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
  1965
                                                      "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
  1966
    } 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
  1967
        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
  1968
        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
  1969
    }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1970
    
cdd6a0c5b439 Went 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
    g_hash_table_insert (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
  1972
                         id, lm_message_handler_ref (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
  1973
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1974
    return lm_connection_send (connection, message, error);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1975
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1976
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1977
/**
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1978
 * lm_connection_send_with_reply_and_block:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1979
 * @connection: an #LmConnection
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1980
 * @message: an #LmMessage
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1981
 * @error: Set if error was detected during sending.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1982
 * 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1983
 * Send @message and wait for return.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1984
 * 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1985
 * Return value: The reply
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1986
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1987
LmMessage *
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1988
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
  1989
                                         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
  1990
                                         GError       **error)
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1991
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1992
    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
  1993
    LmMessage *reply = NULL;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1994
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1995
    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
  1996
    g_return_val_if_fail (message != NULL, NULL);
66
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1997
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1998
    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
  1999
        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
  2000
                     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
  2001
                     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
  2002
                     "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
  2003
        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
  2004
    }
125
6163119136b5 2005-08-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 124
diff changeset
  2005
6163119136b5 2005-08-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 124
diff changeset
  2006
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2007
    if (lm_message_node_get_attribute (message->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
  2008
        id = g_strdup (lm_message_node_get_attribute (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
  2009
                                                      "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
  2010
    } 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
  2011
        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
  2012
        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
  2013
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2014
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2015
    lm_message_queue_detach (connection->queue);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2016
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2017
    lm_connection_send (connection, message, error);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2018
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2019
    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
  2020
        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
  2021
        guint        n;
39
b909b5af5a97 2003-10-01 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 37
diff changeset
  2022
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2023
        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
  2024
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2025
        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
  2026
            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
  2027
        }
39
b909b5af5a97 2003-10-01 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 37
diff changeset
  2028
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2029
        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
  2030
            LmMessage *m;
39
b909b5af5a97 2003-10-01 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 37
diff changeset
  2031
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2032
            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
  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
            m_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
  2035
            
cdd6a0c5b439 Went 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
            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
  2037
                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
  2038
                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
  2039
                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
  2040
            }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2041
        }
cdd6a0c5b439 Went 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
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2043
518
cdd6a0c5b439 Went 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
    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
  2045
    lm_message_queue_attach (connection->queue, connection->context);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2046
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2047
    return reply;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2048
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2049
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2050
/**
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2051
 * lm_connection_register_message_handler:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2052
 * @connection: Connection to register a handler for.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2053
 * @handler: Message handler to register.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2054
 * @type: Message type that @handler will handle.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2055
 * @priority: The priority in which to call @handler.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2056
 * 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2057
 * Registers a #LmMessageHandler to handle incoming messages of a certain type.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2058
 * To unregister the handler call lm_connection_unregister_message_handler().
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2059
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2060
void
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
  2061
lm_connection_register_message_handler  (LmConnection      *connection,
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
  2062
                                         LmMessageHandler  *handler,
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
  2063
                                         LmMessageType      type,
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
  2064
                                         LmHandlerPriority  priority)
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2065
{
530
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 529
diff changeset
  2066
    HandlerData *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
  2067
    
cdd6a0c5b439 Went 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
    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
  2069
    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
  2070
    g_return_if_fail (type != LM_MESSAGE_TYPE_UNKNOWN);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2071
518
cdd6a0c5b439 Went 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
    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
  2073
    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
  2074
    hd->handler  = lm_message_handler_ref (handler);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2075
518
cdd6a0c5b439 Went 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
    connection->handlers[type] = g_slist_insert_sorted (connection->handlers[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
  2077
                                                        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
  2078
                                                        (GCompareFunc) connection_handler_compare_func);
1
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
/**
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2082
 * lm_connection_unregister_message_handler:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2083
 * @connection: Connection to unregister a handler for.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2084
 * @handler: The handler to unregister.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2085
 * @type: What type of messages to unregister this handler for.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2086
 * 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2087
 * Unregisters a handler for @connection. @handler will no longer be called 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2088
 * when incoming messages of @type arrive.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2089
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2090
void
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
  2091
lm_connection_unregister_message_handler (LmConnection     *connection,
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
  2092
                                          LmMessageHandler *handler,
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
  2093
                                          LmMessageType     type)
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
    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
  2096
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2097
    g_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
  2098
    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
  2099
    g_return_if_fail (type != LM_MESSAGE_TYPE_UNKNOWN);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
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
    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
  2102
        HandlerData *hd = (HandlerData *) l->data;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2103
        
cdd6a0c5b439 Went 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
        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
  2105
            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
  2106
            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
  2107
            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
  2108
            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
  2109
            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
  2110
        }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2111
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2112
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2113
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2114
/**
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2115
 * lm_connection_set_disconnect_function:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2116
 * @connection: Connection to register disconnect callback for.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2117
 * @function: Function to be called when @connection is closed.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2118
 * @user_data: User data passed to @function.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2119
 * @notify: Function that will be called with @user_data when @user_data needs to be freed. Pass #NULL if it shouldn't be freed.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2120
 * 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2121
 * Set the callback that will be called when a connection is closed. 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2122
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2123
void
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2124
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
  2125
                                       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
  2126
                                       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
  2127
                                       GDestroyNotify        notify)
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
    g_return_if_fail (connection != NULL);
66
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  2130
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2131
    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
  2132
        _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
  2133
    }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2134
        
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2135
    if (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
  2136
        connection->disconnect_cb = _lm_utils_new_callback (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
  2137
                                                            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
  2138
                                                            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
  2139
    } 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
  2140
        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
  2141
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2142
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2143
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2144
/**
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2145
 * lm_connection_send_raw:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2146
 * @connection: Connection used to send
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2147
 * @str: The string to send, the entire string will be sent.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2148
 * @error: Set if error was detected during sending.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2149
 * 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2150
 * Asynchronous call to send a raw string. Useful for debugging and testing.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2151
 * 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2152
 * Return value: Returns #TRUE if no errors was detected during sending, 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2153
 * #FALSE otherwise.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2154
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2155
gboolean 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2156
lm_connection_send_raw (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
  2157
                        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
  2158
                        GError       **error)
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2159
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2160
    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
  2161
    g_return_val_if_fail (str != NULL, FALSE);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2162
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2163
    return connection_send (connection, str, -1, error);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2164
}
59
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  2165
/**
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  2166
 * lm_connection_get_state:
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  2167
 * @connection: Connection to get state on
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  2168
 *
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  2169
 * Returns the state of the connection.
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  2170
 *
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  2171
 * Return value: The state of the connection.
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  2172
 **/
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  2173
LmConnectionState 
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  2174
lm_connection_get_state (LmConnection *connection)
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
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
    g_return_val_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
  2177
                          LM_CONNECTION_STATE_CLOSED);
59
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  2178
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2179
    return connection->state;
59
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  2180
}
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2181
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2182
/**
308
7e2050a6df75 Added lm_connection_get_client_host (forward-port from LM1.2).
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 307
diff changeset
  2183
 * 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
  2184
 * @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
  2185
 *
7e2050a6df75 Added lm_connection_get_client_host (forward-port from LM1.2).
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 307
diff changeset
  2186
 * 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
  2187
 *
7e2050a6df75 Added lm_connection_get_client_host (forward-port from LM1.2).
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 307
diff changeset
  2188
 * 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
  2189
 **/
7e2050a6df75 Added lm_connection_get_client_host (forward-port from LM1.2).
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 307
diff changeset
  2190
gchar *
7e2050a6df75 Added lm_connection_get_client_host (forward-port from LM1.2).
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 307
diff changeset
  2191
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
  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
    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
  2194
}
7e2050a6df75 Added lm_connection_get_client_host (forward-port from LM1.2).
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 307
diff changeset
  2195
7e2050a6df75 Added lm_connection_get_client_host (forward-port from LM1.2).
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 307
diff changeset
  2196
/**
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2197
 * lm_connection_ref:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2198
 * @connection: Connection to add a reference to.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2199
 * 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2200
 * Add a reference on @connection. To remove a reference call 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2201
 * lm_connection_unref().
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2202
 * 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2203
 * Return value: Returns the same connection.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2204
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2205
LmConnection*
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2206
lm_connection_ref (LmConnection *connection)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2207
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2208
    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
  2209
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2210
    connection->ref_count++;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2211
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2212
    return connection;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2213
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2214
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2215
/**
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2216
 * lm_connection_unref:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2217
 * @connection: Connection to remove reference from.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2218
 * 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2219
 * 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
  2220
 * @connection it will be freed and shouldn't be used again.
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2221
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2222
void
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2223
lm_connection_unref (LmConnection *connection)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2224
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2225
    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
  2226
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2227
    connection->ref_count--;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2228
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2229
    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
  2230
        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
  2231
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2232
}