loudmouth/lm-connection.c
author Samuel Tesla <stesla@engineyard.com>
Mon, 09 Mar 2009 18:05:59 -0500
changeset 593 2c04915af500
parent 573 038320b7357e
child 600 7f0be2600f6d
permissions -rw-r--r--
Update release information files. * Combined AUTHORS and CONTRIBUTORS. * Added some more folks to the AUTHORS file based on commit history. * Added Makefile recipe to dynamically generate ChangeLog from last annotated tag or a specified ref. * Added ignores for tarballs and ChangeLog.
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
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
    85
#include "lm-data-objects.h"
140
103227122f45 2006-04-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 137
diff changeset
    86
#include "lm-sock.h"
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    87
#include "lm-debug.h"
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    88
#include "lm-error.h"
508
0850b3400a8c Cleaned up the moved XMPP Ping code from LmConnection and hooked up the LmFeaturePing object.
Mikael Hallendal <micke@imendio.com>
parents: 504
diff changeset
    89
#include "lm-feature-ping.h"
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    90
#include "lm-internals.h"
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
    91
#include "lm-message-queue.h"
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
    92
#include "lm-misc.h"
137
18785575aa7a 2006-04-05 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 133
diff changeset
    93
#include "lm-ssl-internals.h"
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    94
#include "lm-parser.h"
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    95
#include "lm-sha.h"
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    96
#include "lm-connection.h"
155
d24c4392d4e3 2006-06-16 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 153
diff changeset
    97
#include "lm-utils.h"
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents: 422
diff changeset
    98
#include "lm-old-socket.h"
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
    99
#include "lm-sasl.h"
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
   100
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   101
typedef struct {
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   102
    LmHandlerPriority  priority;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   103
    LmMessageHandler  *handler;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   104
} HandlerData;
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   105
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   106
struct _LmConnection {
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   107
    /* Parameters */
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   108
    GMainContext      *context;
533
c45243823756 Added some TODO items and minor style fixes
Mikael Hallendal <micke@imendio.com>
parents: 532
diff changeset
   109
    
c45243823756 Added some TODO items and minor style fixes
Mikael Hallendal <micke@imendio.com>
parents: 532
diff changeset
   110
    /* TODO: Clean up this and make some parameter object for server, jid, effective jid etc */
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   111
    gchar             *server;
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   112
    gchar             *jid;
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   113
    gchar             *effective_jid;
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   114
    guint              port;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   115
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   116
    LmOldSocket       *socket;
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   117
    LmSSL             *ssl;
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   118
    LmProxy           *proxy;
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   119
    LmParser          *parser;
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   120
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   121
    gchar             *stream_id;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   122
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   123
    GHashTable        *id_handlers;
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   124
    GSList            *handlers[LM_MESSAGE_TYPE_UNKNOWN];
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   125
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   126
    /* XMPP1.0 stuff (SASL, resource binding, StartTLS) */
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   127
    gboolean           use_sasl;
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   128
    LmSASL            *sasl;
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   129
    gchar             *resource;
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   130
    LmMessageHandler  *features_cb;
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   131
    LmMessageHandler  *starttls_cb;
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   132
    gboolean           tls_started;
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
   133
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   134
    /* Communication */
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   135
    guint              open_id;
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   136
    LmCallback        *open_cb;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   137
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   138
    gboolean           cancel_open;
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   139
    LmCallback        *auth_cb;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   140
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   141
    LmCallback        *disconnect_cb;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   142
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   143
    LmMessageQueue    *queue;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   144
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   145
    LmConnectionState  state;
59
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
   146
533
c45243823756 Added some TODO items and minor style fixes
Mikael Hallendal <micke@imendio.com>
parents: 532
diff changeset
   147
    /* TODO: Move the rate to use the one in LmFeaturePing instead of keeping the two in sync */
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   148
    guint              keep_alive_rate;
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   149
    LmFeaturePing     *feature_ping;
184
4e16d32b2410 2006-10-16 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 181
diff changeset
   150
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   151
    gint               ref_count;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   152
};
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   153
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   154
typedef enum {
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   155
    AUTH_TYPE_PLAIN  = 1,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   156
    AUTH_TYPE_DIGEST = 2,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   157
    AUTH_TYPE_0K     = 4
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   158
} AuthType;
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   159
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
   160
#define XMPP_NS_BIND "urn:ietf:params:xml:ns:xmpp-bind"
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
   161
#define XMPP_NS_SESSION "urn:ietf:params:xml:ns:xmpp-session"
274
c32a7011e435 Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents: 271
diff changeset
   162
#define XMPP_NS_STARTTLS "urn:ietf:params:xml:ns:xmpp-tls"
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
   163
416
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   164
static void     connection_free              (LmConnection        *connection);
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   165
static void     connection_handle_message    (LmConnection        *connection,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   166
                                              LmMessage           *message);
416
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   167
static void     connection_new_message_cb    (LmParser            *parser,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   168
                                              LmMessage           *message,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   169
                                              LmConnection        *connection);
416
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   170
static gboolean connection_do_open           (LmConnection        *connection,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   171
                                              GError             **error);
416
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   172
void            connection_do_close          (LmConnection        *connection);
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   173
static LmMessage *     
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
   174
connection_create_auth_req_msg               (LmAuthParameters    *auth_params);
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
   175
    
416
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   176
static LmMessage *
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   177
connection_create_auth_msg                   (LmConnection        *connection,
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
   178
                                              LmAuthParameters    *auth_params,
416
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   179
                                              gint                 auth_type);
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   180
static LmHandlerResult 
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   181
connection_auth_req_reply                    (LmMessageHandler    *handler,
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   182
                                              LmConnection        *connection,
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   183
                                              LmMessage           *m,
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   184
                                              gpointer             user_data);
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   185
static int      connection_check_auth_type   (LmMessage           *auth_req_rpl);
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   186
static LmHandlerResult
416
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   187
connection_auth_reply                        (LmMessageHandler    *handler,
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   188
                                              LmConnection        *connection,
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   189
                                              LmMessage           *m,
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   190
                                              gpointer             user_data);
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   191
static void     connection_stream_received   (LmConnection        *connection, 
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   192
                                              LmMessage           *m);
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   193
static void     connection_stream_error      (LmConnection        *connection, 
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   194
                                              LmMessage           *m);
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   195
static gint      
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   196
connection_handler_compare_func              (HandlerData         *a,
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   197
                                              HandlerData         *b);
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   198
static void     connection_start_keep_alive  (LmConnection        *connection);
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   199
static void     connection_stop_keep_alive   (LmConnection        *connection);
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   200
static gboolean connection_send              (LmConnection        *connection, 
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   201
                                              const gchar         *str, 
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   202
                                              gint                 len, 
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   203
                                              GError             **error);
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   204
static void     connection_message_queue_cb  (LmMessageQueue      *queue,
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   205
                                              LmConnection        *connection);
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   206
static void      
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   207
connection_signal_disconnect                 (LmConnection        *connection,
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   208
                                              LmDisconnectReason   reason);
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   209
static void     connection_incoming_data     (LmOldSocket         *socket, 
416
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   210
                                              const gchar         *buf,
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   211
                                              LmConnection        *connection);
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents: 422
diff changeset
   212
static void     connection_socket_closed_cb  (LmOldSocket            *socket,
416
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   213
                                              LmDisconnectReason   reason,
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   214
                                              LmConnection        *connection);
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   215
static void      
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   216
connection_socket_connect_cb                 (LmOldSocket         *socket,
416
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   217
                                              gboolean             result,
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   218
                                              LmConnection        *connection);
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   219
static gboolean
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   220
connection_get_server_from_jid               (const gchar         *jid,
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   221
                                              gchar              **server);
416
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   222
static void
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   223
connection_send_stream_header                (LmConnection        *connection);
416
70e99906149f Cleaned declarations of static functions in LmConnection
Mikael Hallendal <micke@imendio.com>
parents: 415
diff changeset
   224
static LmHandlerResult 
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   225
connection_features_cb                       (LmMessageHandler    *handler,
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   226
                                              LmConnection        *connection,
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   227
                                              LmMessage           *message,
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   228
                                              gpointer             user_data);
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   229
static gboolean connection_old_auth          (LmConnection        *connection,
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
   230
                                              LmAuthParameters    *auth_params,
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   231
                                              GError             **errror);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   232
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   233
static void
405
f33dcdadf95c Factored out connection_free_handlers from connection_free
Mikael Hallendal <micke@imendio.com>
parents: 394
diff changeset
   234
connection_free_handlers (LmConnection *connection)
f33dcdadf95c Factored out connection_free_handlers from connection_free
Mikael Hallendal <micke@imendio.com>
parents: 394
diff changeset
   235
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   236
    int i;
405
f33dcdadf95c Factored out connection_free_handlers from connection_free
Mikael Hallendal <micke@imendio.com>
parents: 394
diff changeset
   237
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   238
    /* Unref handlers */
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   239
    for (i = 0; i < LM_MESSAGE_TYPE_UNKNOWN; ++i) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   240
        GSList *l;
405
f33dcdadf95c Factored out connection_free_handlers from connection_free
Mikael Hallendal <micke@imendio.com>
parents: 394
diff changeset
   241
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   242
        for (l = connection->handlers[i]; l; l = l->next) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   243
            HandlerData *hd = (HandlerData *) l->data;
cdd6a0c5b439 Went 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
            
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   245
            lm_message_handler_unref (hd->handler);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   246
            g_free (hd);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   247
        }
405
f33dcdadf95c Factored out connection_free_handlers from connection_free
Mikael Hallendal <micke@imendio.com>
parents: 394
diff changeset
   248
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   249
        g_slist_free (connection->handlers[i]);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   250
    }
405
f33dcdadf95c Factored out connection_free_handlers from connection_free
Mikael Hallendal <micke@imendio.com>
parents: 394
diff changeset
   251
}
f33dcdadf95c Factored out connection_free_handlers from connection_free
Mikael Hallendal <micke@imendio.com>
parents: 394
diff changeset
   252
f33dcdadf95c Factored out connection_free_handlers from connection_free
Mikael Hallendal <micke@imendio.com>
parents: 394
diff changeset
   253
static void
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   254
connection_free (LmConnection *connection)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   255
{
573
038320b7357e Don't free connection internals before it's closed. [#34]
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   256
    /* This needs to be run before starting to free internal states.
038320b7357e Don't free connection internals before it's closed. [#34]
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   257
     * It used to be run after the handlers where freed which lead to a crash
038320b7357e Don't free connection internals before it's closed. [#34]
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   258
     * when the connection was freed prior to running lm_connection_close.
038320b7357e Don't free connection internals before it's closed. [#34]
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   259
     */
038320b7357e Don't free connection internals before it's closed. [#34]
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   260
    if (connection->state >= LM_CONNECTION_STATE_OPENING) {
038320b7357e Don't free connection internals before it's closed. [#34]
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   261
        connection_do_close (connection);
038320b7357e Don't free connection internals before it's closed. [#34]
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   262
    }
038320b7357e Don't free connection internals before it's closed. [#34]
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   263
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   264
    g_free (connection->server);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   265
    g_free (connection->jid);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   266
    g_free (connection->effective_jid);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   267
    g_free (connection->stream_id);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   268
    g_free (connection->resource);
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
   269
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   270
    if (connection->sasl) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   271
        lm_sasl_free (connection->sasl);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   272
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   273
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   274
    if (connection->parser) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   275
        lm_parser_free (connection->parser);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   276
    }
153
b2324df84971 2006-06-06 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 143
diff changeset
   277
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   278
    connection_free_handlers (connection);
cdd6a0c5b439 Went 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
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   280
    g_hash_table_destroy (connection->id_handlers);
573
038320b7357e Don't free connection internals before it's closed. [#34]
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   281
    
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   282
    if (connection->open_cb) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   283
        _lm_utils_free_callback (connection->open_cb);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   284
    }
cdd6a0c5b439 Went 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
    if (connection->auth_cb) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   287
        _lm_utils_free_callback (connection->auth_cb);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   288
    }
143
92193c23b0c7 2006-05-26 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 140
diff changeset
   289
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   290
    lm_connection_set_disconnect_function (connection, NULL, NULL, NULL);
143
92193c23b0c7 2006-05-26 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 140
diff changeset
   291
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   292
    if (connection->proxy) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   293
        lm_proxy_unref (connection->proxy);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   294
    }
211
efbf2da5e443 Added checks when freeing proxy and closing socket. Also free open_cb in cancel_open.
Mikael Hallendal <micke@imendio.com>
parents: 210
diff changeset
   295
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   296
    lm_message_queue_unref (connection->queue);
115
f2a921e232e5 2005-04-24 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 114
diff changeset
   297
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   298
    if (connection->context) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   299
        g_main_context_unref (connection->context);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   300
    }
133
f7522d7ed6dc 2006-04-03 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 132
diff changeset
   301
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   302
    if (connection->socket) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   303
        lm_old_socket_unref (connection->socket);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   304
    }
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   305
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   306
    g_slice_free (LmConnection, connection);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   307
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   308
408
b07ef2183e6b Factored out connection_run_message_handler from connection_handle_message.
Mikael Hallendal <micke@imendio.com>
parents: 406
diff changeset
   309
static LmHandlerResult
b07ef2183e6b Factored out connection_run_message_handler from connection_handle_message.
Mikael Hallendal <micke@imendio.com>
parents: 406
diff changeset
   310
connection_run_message_handler (LmConnection *connection, LmMessage *m)
b07ef2183e6b Factored out connection_run_message_handler from connection_handle_message.
Mikael Hallendal <micke@imendio.com>
parents: 406
diff changeset
   311
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   312
    LmMessageHandler *handler;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   313
    const gchar      *id;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   314
    LmHandlerResult   result = LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS;
408
b07ef2183e6b Factored out connection_run_message_handler from connection_handle_message.
Mikael Hallendal <micke@imendio.com>
parents: 406
diff changeset
   315
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   316
    id = lm_message_node_get_attribute (m->node, "id");
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   317
    if (!id) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   318
        return LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   319
    }
408
b07ef2183e6b Factored out connection_run_message_handler from connection_handle_message.
Mikael Hallendal <micke@imendio.com>
parents: 406
diff changeset
   320
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   321
    handler = g_hash_table_lookup (connection->id_handlers, id);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   322
    if (handler) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   323
        result = _lm_message_handler_handle_message (handler,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   324
                                                     connection,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   325
                                                     m);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   326
        g_hash_table_remove (connection->id_handlers,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   327
                             id);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   328
    }
408
b07ef2183e6b Factored out connection_run_message_handler from connection_handle_message.
Mikael Hallendal <micke@imendio.com>
parents: 406
diff changeset
   329
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   330
    return result;
408
b07ef2183e6b Factored out connection_run_message_handler from connection_handle_message.
Mikael Hallendal <micke@imendio.com>
parents: 406
diff changeset
   331
}
b07ef2183e6b Factored out connection_run_message_handler from connection_handle_message.
Mikael Hallendal <micke@imendio.com>
parents: 406
diff changeset
   332
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   333
static void
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   334
connection_handle_message (LmConnection *connection, LmMessage *m)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   335
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   336
    GSList          *l;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   337
    LmHandlerResult  result = LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   338
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   339
    lm_connection_ref (connection);
143
92193c23b0c7 2006-05-26 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 140
diff changeset
   340
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   341
    if (lm_message_get_type (m) == LM_MESSAGE_TYPE_STREAM) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   342
        connection_stream_received (connection, m);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   343
        goto out;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   344
    }
306
d466fc30829f Added disconnect error for resource conflict. Fixes LM-55.
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 297
diff changeset
   345
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   346
    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
   347
    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
   348
        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
   349
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   350
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   351
    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
   352
         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
   353
         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
   354
        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
   355
        
cdd6a0c5b439 Went 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
        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
   357
                                                     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
   358
                                                     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
   359
    }
143
92193c23b0c7 2006-05-26 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 140
diff changeset
   360
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   361
    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
   362
        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
   363
        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
   364
    }
cdd6a0c5b439 Went 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
 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
   367
    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
   368
    
cdd6a0c5b439 Went 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
    return;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   370
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   371
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   372
static void
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   373
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
   374
                           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
   375
                           LmConnection *connection)
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   376
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   377
    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
   378
    
cdd6a0c5b439 Went 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
    lm_message_ref (m);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   380
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   381
    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
   382
    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
   383
        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
   384
    }
cdd6a0c5b439 Went 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
    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
   387
                _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
   388
                from);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   389
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   390
    lm_message_queue_push_tail (connection->queue, m);
82
a32b54e654e2 2004-03-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 80
diff changeset
   391
}
a32b54e654e2 2004-03-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 80
diff changeset
   392
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
   393
static void
529
6bb284696153 More style fixes
Mikael Hallendal <micke@imendio.com>
parents: 528
diff changeset
   394
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
   395
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   396
    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
   397
    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
   398
                                  LM_DISCONNECT_REASON_PING_TIME_OUT);
90
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
   399
}
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
static void
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
   402
connection_start_keep_alive (LmConnection *connection)
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
   403
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   404
    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
   405
        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
   406
    }
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
   407
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   408
    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
   409
                                             "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
   410
                                             "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
   411
                                             NULL);
90
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
   412
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   413
    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
   414
                      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
   415
                      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
   416
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   417
    lm_feature_ping_start (connection->feature_ping);
90
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
   418
}
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
static void
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
   421
connection_stop_keep_alive (LmConnection *connection)
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
   422
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   423
    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
   424
        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
   425
        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
   426
                                              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
   427
                                              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
   428
        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
   429
    }
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
   430
        
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   431
    connection->feature_ping = NULL;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   432
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   433
406
3c6b13d37d41 Factored out connection_log_send from connection_send
Mikael Hallendal <micke@imendio.com>
parents: 405
diff changeset
   434
static void
3c6b13d37d41 Factored out connection_log_send from connection_send
Mikael Hallendal <micke@imendio.com>
parents: 405
diff changeset
   435
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
   436
                     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
   437
                     gint          len)
406
3c6b13d37d41 Factored out connection_log_send from connection_send
Mikael Hallendal <micke@imendio.com>
parents: 405
diff changeset
   438
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   439
    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
   440
    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
   441
           "-----------------------------------\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
   442
    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
   443
    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
   444
           "-----------------------------------\n");
406
3c6b13d37d41 Factored out connection_log_send from connection_send
Mikael Hallendal <micke@imendio.com>
parents: 405
diff changeset
   445
}
3c6b13d37d41 Factored out connection_log_send from connection_send
Mikael Hallendal <micke@imendio.com>
parents: 405
diff changeset
   446
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   447
static gboolean
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   448
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
   449
                 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
   450
                 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
   451
                 GError       **error)
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   452
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   453
    gint b_written;
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   454
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   455
    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
   456
        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
   457
               "Connection is not open.\n");
140
103227122f45 2006-04-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 137
diff changeset
   458
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   459
        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
   460
                     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
   461
                     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
   462
                     "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
   463
        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
   464
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   465
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   466
    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
   467
        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
   468
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   469
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   470
    connection_log_send (connection, str, len);
68
28203e15de0e 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 67
diff changeset
   471
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   472
    /* 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
   473
       buffer and return */
133
f7522d7ed6dc 2006-04-03 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 132
diff changeset
   474
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   475
    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
   476
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   477
    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
   478
        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
   479
                     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
   480
                     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
   481
                     "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
   482
        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
   483
    }
133
f7522d7ed6dc 2006-04-03 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 132
diff changeset
   484
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   485
    return TRUE;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   486
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   487
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   488
static void
249
2cca5ec7b573 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 248
diff changeset
   489
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
   490
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   491
    LmMessage *m;
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   492
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   493
    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
   494
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   495
    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
   496
        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
   497
        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
   498
    }
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   499
}
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
/* Returns directly */
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   502
/* 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
   503
static gboolean
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   504
connection_do_open (LmConnection *connection, GError **error) 
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   505
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   506
    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
   507
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   508
    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
   509
        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
   510
                     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
   511
                     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
   512
                     "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
   513
        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
   514
    }
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   515
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   516
    domain = _lm_connection_get_server (connection);
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   517
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   518
    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
   519
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   520
    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
   521
                                               (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
   522
                                               (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
   523
                                               (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
   524
                                               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
   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->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
   527
                                               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
   528
                                               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
   529
                                               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
   530
                                               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
   531
                                               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
   532
518
cdd6a0c5b439 Went 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
    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
   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
    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
   536
        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
   537
    }
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   538
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   539
    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
   540
    
cdd6a0c5b439 Went 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
    connection->state = LM_CONNECTION_STATE_OPENING;
344
11473296fea5 Return FALSE from lm_connection_open in the synchronous case instead of open callback
Owen Taylor <otaylor@redhat.com>
parents: 341
diff changeset
   542
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   543
    return TRUE;
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   544
}
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   545
                    
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   546
void
256
2266e56746ed Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 255
diff changeset
   547
connection_do_close (LmConnection *connection)
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   548
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   549
    connection_stop_keep_alive (connection);
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   550
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   551
    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
   552
        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
   553
    }
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   554
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   555
    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
   556
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   557
    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
   558
        /* 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
   559
        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
   560
        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
   561
    }
cdd6a0c5b439 Went 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
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   563
    connection->state = LM_CONNECTION_STATE_CLOSED;
324
4b06b1173262 Properly clean up SASL context on disconnect, allowing connection object reuse.
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 323
diff changeset
   564
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   565
    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
   566
        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
   567
        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
   568
    }
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   569
}
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   570
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   571
static LmMessage *
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
   572
connection_create_auth_req_msg (LmAuthParameters *auth_params)
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   573
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   574
    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
   575
    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
   576
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   577
    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
   578
                                      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
   579
    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
   580
    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
   581
                                    "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
   582
                                    NULL);
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
   583
    lm_message_node_add_child (q_node, "username", lm_auth_parameters_get_username (auth_params));
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   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
    return m;
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   586
}
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   587
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   588
static LmMessage *
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
   589
connection_create_auth_msg (LmConnection     *connection,
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
   590
                            LmAuthParameters *auth_params,
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
   591
                            gint              auth_type)
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   592
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   593
    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
   594
    LmMessageNode *q_node;
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   595
518
cdd6a0c5b439 Went 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
    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
   597
                                             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
   598
    
cdd6a0c5b439 Went 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 (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
   600
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   601
    lm_message_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
   602
                                    "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
   603
                                    NULL);
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   604
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
   605
    lm_message_node_add_child (q_node, "username", lm_auth_parameters_get_username (auth_params));
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   606
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   607
    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
   608
        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
   609
        /* 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
   610
    }
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   611
518
cdd6a0c5b439 Went 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
    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
   613
        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
   614
        gchar *digest;
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   615
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   616
        lm_verbose ("Using digest\n");
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
   617
        str = g_strconcat (connection->stream_id, lm_auth_parameters_get_password (auth_params), NULL);
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   618
        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
   619
        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
   620
        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
   621
        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
   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
    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
   624
        lm_verbose ("Using plaintext auth\n");
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
   625
        lm_message_node_add_child (q_node, "password", lm_auth_parameters_get_password (auth_params));
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   626
    } 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
   627
        /* 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
   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
    
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
   630
    lm_message_node_add_child (q_node, "resource", lm_auth_parameters_get_resource (auth_params));
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   631
518
cdd6a0c5b439 Went 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
    return auth_msg;
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   633
}
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   634
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   635
static LmHandlerResult
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   636
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
   637
                           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
   638
                           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
   639
                           gpointer          user_data)
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   640
{
518
cdd6a0c5b439 Went 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
    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
   642
    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
   643
    LmMessageHandler *auth_handler;
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
   644
    LmAuthParameters *auth_params = (LmAuthParameters *) user_data;
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   645
    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
   646
    
cdd6a0c5b439 Went 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
    auth_type = connection_check_auth_type (m);
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   648
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
   649
    auth_msg = connection_create_auth_msg (connection, auth_params, auth_type);
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   650
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   651
    auth_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
   652
                                           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
   653
    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
   654
                                            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
   655
    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
   656
    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
   657
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   658
    return LM_HANDLER_RESULT_REMOVE_MESSAGE;
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   659
}
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   660
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   661
static int
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   662
connection_check_auth_type (LmMessage *auth_req_rpl)
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   663
{
518
cdd6a0c5b439 Went 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
    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
   665
    gint           ret_val = 0; 
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   666
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   667
    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
   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
    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
   670
        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
   671
    }
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   672
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   673
    if (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
   674
        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
   675
    }
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   676
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   677
    if (lm_message_node_get_child (q_node, "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
   678
        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
   679
    }
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   680
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   681
    if (lm_message_node_get_child (q_node, "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
   682
        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
   683
        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
   684
    }
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   685
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   686
    return ret_val;
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   687
}
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
   688
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   689
static LmHandlerResult 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   690
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
   691
                       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
   692
                       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
   693
                       gpointer          user_data)
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   694
{
518
cdd6a0c5b439 Went 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
    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
   696
    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
   697
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   698
    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
   699
                          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
   700
    
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   701
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   702
    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
   703
    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
   704
        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
   705
        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
   706
    } 
cdd6a0c5b439 Went 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
    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
   708
        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
   709
        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
   710
    }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   711
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   712
    lm_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
   713
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   714
    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
   715
        LmCallback *cb = connection->auth_cb;
143
92193c23b0c7 2006-05-26 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 140
diff changeset
   716
518
cdd6a0c5b439 Went 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
        connection->auth_cb = NULL;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   718
518
cdd6a0c5b439 Went 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
        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
   720
            (* ((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
   721
                                               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
   722
                                               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
   723
        }
143
92193c23b0c7 2006-05-26 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 140
diff changeset
   724
518
cdd6a0c5b439 Went 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_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
   726
    }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   727
    
cdd6a0c5b439 Went 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
    return LM_HANDLER_RESULT_REMOVE_MESSAGE;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   729
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   730
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   731
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
   732
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
   733
_lm_connection_starttls_cb (LmMessageHandler *handler,
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   734
                            LmConnection     *connection,
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   735
                            LmMessage        *message,
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   736
                            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
   737
{
518
cdd6a0c5b439 Went 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
    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
   739
        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
   740
        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
   741
    } 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
   742
        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
   743
        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
   744
                                      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
   745
    }
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
   746
518
cdd6a0c5b439 Went 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
    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
   748
}
02b814ccc535 Register starttls handler at the proper moment, when the stream is received.
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 317
diff changeset
   749
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   750
static void
450
548b5e3d9bea Refactored some of the SSL code in LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 449
diff changeset
   751
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
   752
{
518
cdd6a0c5b439 Went 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
    /* 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
   754
     * 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
   755
    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
   756
        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
   757
        !connection->starttls_cb) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   758
        connection->starttls_cb  =
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   759
            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
   760
                                    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
   761
        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
   762
                                                connection->starttls_cb,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   763
                                                LM_MESSAGE_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
   764
                                                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
   765
    }
450
548b5e3d9bea Refactored some of the SSL code in LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 449
diff changeset
   766
}
548b5e3d9bea Refactored some of the SSL code in LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 449
diff changeset
   767
548b5e3d9bea Refactored some of the SSL code in LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 449
diff changeset
   768
static void
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   769
connection_stream_received (LmConnection *connection, LmMessage *m)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   770
{
518
cdd6a0c5b439 Went 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
    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
   772
    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
   773
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   774
    g_return_if_fail (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
   775
    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
   776
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   777
    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
   778
                                                                     "id"));
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
   779
518
cdd6a0c5b439 Went 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
    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
   781
    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
   782
        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
   783
                    connection->stream_id);
220
f6b9482ae89e Some style fixes to the SASL patch.
Mikael Hallendal <micke@imendio.com>
parents: 219
diff changeset
   784
518
cdd6a0c5b439 Went 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
        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
   786
        
cdd6a0c5b439 Went 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
        /* 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
   788
         * 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
   789
        if (!connection->sasl) {
541
9c315096fa5a Minor style fixes
Mikael Hallendal <micke@imendio.com>
parents: 540
diff changeset
   790
            connection->sasl = lm_sasl_new (connection);
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   791
        }
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
   792
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   793
        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
   794
    } 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
   795
        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
   796
                    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
   797
    }
cdd6a0c5b439 Went 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
    
cdd6a0c5b439 Went 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
    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
   800
        connection->state = LM_CONNECTION_STATE_OPEN;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   801
    }
cdd6a0c5b439 Went 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
    /* 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
   804
    result = TRUE;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
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
    connection_start_keep_alive (connection);
90
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
   807
518
cdd6a0c5b439 Went 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
    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
   809
        LmCallback *cb = connection->open_cb;
143
92193c23b0c7 2006-05-26 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 140
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->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
   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
        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
   814
            (* ((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
   815
                                               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
   816
        }
cdd6a0c5b439 Went 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
        _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
   818
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   819
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   820
306
d466fc30829f Added disconnect error for resource conflict. Fixes LM-55.
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 297
diff changeset
   821
static void
d466fc30829f Added disconnect error for resource conflict. Fixes LM-55.
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 297
diff changeset
   822
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
   823
{
534
19327ccf6099 Minor style fix
Mikael Hallendal <micke@imendio.com>
parents: 533
diff changeset
   824
    LmMessageNode      *node;
19327ccf6099 Minor style fix
Mikael Hallendal <micke@imendio.com>
parents: 533
diff changeset
   825
    LmMessageNode      *reason_node;
19327ccf6099 Minor style fix
Mikael Hallendal <micke@imendio.com>
parents: 533
diff changeset
   826
    LmDisconnectReason  reason;
306
d466fc30829f Added disconnect error for resource conflict. Fixes LM-55.
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 297
diff changeset
   827
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   828
    g_return_if_fail (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
   829
    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
   830
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   831
    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
   832
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   833
    /* 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
   834
    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
   835
    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
   836
        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
   837
        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
   838
        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
   839
    }
306
d466fc30829f Added disconnect error for resource conflict. Fixes LM-55.
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 297
diff changeset
   840
518
cdd6a0c5b439 Went 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
    /* 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
   842
    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
   843
    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
   844
        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
   845
        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
   846
        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
   847
    }
306
d466fc30829f Added disconnect error for resource conflict. Fixes LM-55.
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 297
diff changeset
   848
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   849
    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
   850
    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
   851
    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
   852
                                                                     "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
   853
    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
   854
    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
   855
}
d466fc30829f Added disconnect error for resource conflict. Fixes LM-55.
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 297
diff changeset
   856
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   857
static gint
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   858
connection_handler_compare_func (HandlerData *a, HandlerData *b)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   859
{
518
cdd6a0c5b439 Went 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
    return b->priority - a->priority;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   861
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   862
256
2266e56746ed Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 255
diff changeset
   863
static void
2266e56746ed Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 255
diff changeset
   864
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
   865
                              LmDisconnectReason  reason)
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   866
{
518
cdd6a0c5b439 Went 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
    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
   868
        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
   869
        
cdd6a0c5b439 Went 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
        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
   871
        (* ((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
   872
                                               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
   873
                                               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
   874
        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
   875
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   876
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   877
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   878
static void
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   879
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
   880
                          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
   881
                          LmConnection *connection)
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   882
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   883
    lm_parser_parse (connection->parser, buf);
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   884
}
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   885
256
2266e56746ed Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 255
diff changeset
   886
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
   887
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
   888
                             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
   889
                             LmConnection       *connection)
256
2266e56746ed Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 255
diff changeset
   890
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   891
    connection_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
   892
    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
   893
}
2266e56746ed Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 255
diff changeset
   894
2266e56746ed Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 255
diff changeset
   895
static void
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   896
connection_socket_connect_cb (LmOldSocket  *socket,
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   897
                              gboolean      result,
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   898
                              LmConnection *connection)
256
2266e56746ed Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 255
diff changeset
   899
{
518
cdd6a0c5b439 Went 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
    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
   901
        connection_do_close (connection);
256
2266e56746ed Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 255
diff changeset
   902
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   903
        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
   904
            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
   905
518
cdd6a0c5b439 Went 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
            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
   907
            
cdd6a0c5b439 Went 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
            (* ((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
   909
                                               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
   910
            _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
   911
        }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   912
    
cdd6a0c5b439 Went 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
        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
   914
    }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   915
    
cdd6a0c5b439 Went 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
    /* 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
   917
    /*        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
   918
    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
   919
                          "<?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
   920
                          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
   921
        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
   922
        connection_do_close (connection);
256
2266e56746ed Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 255
diff changeset
   923
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   924
        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
   925
    }
256
2266e56746ed Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 255
diff changeset
   926
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   927
    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
   928
}
2266e56746ed Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 255
diff changeset
   929
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
   930
static gboolean
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
   931
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
   932
{
518
cdd6a0c5b439 Went 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
    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
   934
    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
   935
518
cdd6a0c5b439 Went 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
    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
   937
        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
   938
        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
   939
            *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
   940
        } 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
   941
            *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
   942
        }
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
   943
518
cdd6a0c5b439 Went 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
        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
   945
    } 
cdd6a0c5b439 Went 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
    
cdd6a0c5b439 Went 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
    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
   948
}
df2655dbe873 Make LmConnection accept not having a server set as long as JID is set.
Mikael Hallendal <micke@imendio.com>
parents: 244
diff changeset
   949
248
09a3e0e55ab8 Refactored sending of the stream header.
Mikael Hallendal <micke@imendio.com>
parents: 247
diff changeset
   950
static void
09a3e0e55ab8 Refactored sending of the stream header.
Mikael Hallendal <micke@imendio.com>
parents: 247
diff changeset
   951
connection_send_stream_header (LmConnection *connection)
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   952
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   953
    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
   954
    gchar     *server_from_jid;
196
209bfa124066 Imported LmConnection refactor from old repository.
Mikael Hallendal <micke@imendio.com>
parents: 187
diff changeset
   955
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   956
    lm_verbose ("Sending stream header\n");
248
09a3e0e55ab8 Refactored sending of the stream header.
Mikael Hallendal <micke@imendio.com>
parents: 247
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
    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
   959
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   960
    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
   961
    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
   962
                                    "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
   963
                                    "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
   964
                                    "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
   965
                                    "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
   966
                                    NULL);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   967
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   968
    g_free (server_from_jid);
248
09a3e0e55ab8 Refactored sending of the stream header.
Mikael Hallendal <micke@imendio.com>
parents: 247
diff changeset
   969
518
cdd6a0c5b439 Went 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
    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
   971
        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
   972
        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
   973
    }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   974
        
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   975
    lm_message_unref (m);
248
09a3e0e55ab8 Refactored sending of the stream header.
Mikael Hallendal <micke@imendio.com>
parents: 247
diff changeset
   976
}
09a3e0e55ab8 Refactored sending of the stream header.
Mikael Hallendal <micke@imendio.com>
parents: 247
diff changeset
   977
500
915cd386918e Added _lm_connection_get_context as internal function.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   978
GMainContext *
915cd386918e Added _lm_connection_get_context as internal function.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   979
_lm_connection_get_context (LmConnection *conn)
915cd386918e Added _lm_connection_get_context as internal function.
Mikael Hallendal <micke@imendio.com>
parents: 497
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
    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
   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
    return conn->context;
500
915cd386918e Added _lm_connection_get_context as internal function.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   984
}
915cd386918e Added _lm_connection_get_context as internal function.
Mikael Hallendal <micke@imendio.com>
parents: 497
diff changeset
   985
501
5f71592beac8 Added _lm_connection_get_server that returns the server string.
Mikael Hallendal <micke@imendio.com>
parents: 500
diff changeset
   986
gchar *
5f71592beac8 Added _lm_connection_get_server that returns the server string.
Mikael Hallendal <micke@imendio.com>
parents: 500
diff changeset
   987
_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
   988
{
518
cdd6a0c5b439 Went 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
    gchar *server;
501
5f71592beac8 Added _lm_connection_get_server that returns the server string.
Mikael Hallendal <micke@imendio.com>
parents: 500
diff changeset
   990
518
cdd6a0c5b439 Went 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
    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
   992
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   993
    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
   994
        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
   995
    }
501
5f71592beac8 Added _lm_connection_get_server that returns the server string.
Mikael Hallendal <micke@imendio.com>
parents: 500
diff changeset
   996
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   997
    return server;
501
5f71592beac8 Added _lm_connection_get_server that returns the server string.
Mikael Hallendal <micke@imendio.com>
parents: 500
diff changeset
   998
}
5f71592beac8 Added _lm_connection_get_server that returns the server string.
Mikael Hallendal <micke@imendio.com>
parents: 500
diff changeset
   999
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1000
static void
222
ca97251ddee8 Renamed internal functions to conform to code style.
Mikael Hallendal <micke@imendio.com>
parents: 221
diff changeset
  1001
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
  1002
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1003
    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
  1004
        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
  1005
    } 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
  1006
        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
  1007
    }
226
5a31f474b9fd Update the connection state after SASL authentication result.
Mikael Hallendal <micke@imendio.com>
parents: 223
diff changeset
  1008
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1009
    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
  1010
        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
  1011
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1012
        connection->auth_cb = NULL;
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
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
        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
  1015
            (* ((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
  1016
                                               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
  1017
                                               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
  1018
        }
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1019
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1020
        _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
  1021
    }
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1022
}
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1023
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1024
static LmHandlerResult
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1025
connection_bind_reply (LmMessageHandler *handler,
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
  1026
                       LmConnection     *connection,
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
  1027
                       LmMessage        *message,
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
  1028
                       gpointer          user_data)
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1029
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1030
    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
  1031
    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
  1032
    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
  1033
    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
  1034
    LmMessageSubType  type;
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1035
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1036
    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
  1037
    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
  1038
        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
  1039
               "%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
  1040
    
cdd6a0c5b439 Went 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
        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
  1042
        
cdd6a0c5b439 Went 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
        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
  1044
    }
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1045
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1046
    /* 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
  1047
    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
  1048
    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
  1049
        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
  1050
        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
  1051
            (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
  1052
    }
297
f65eee8ec802 Support for returning effective JID, possibly changed by the server.
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 294
diff changeset
  1053
f65eee8ec802 Support for returning effective JID, possibly changed by the server.
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 294
diff changeset
  1054
518
cdd6a0c5b439 Went 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
    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
  1056
                                      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
  1057
                                      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
  1058
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1059
    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
  1060
    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
  1061
                                    "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
  1062
                                    NULL);
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1063
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1064
    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
  1065
    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
  1066
    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
  1067
        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
  1068
    }
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1069
518
cdd6a0c5b439 Went 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
    /* 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
  1071
    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
  1072
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1073
    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
  1074
}
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1075
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1076
static LmHandlerResult
256
2266e56746ed Refactoring to clear up interface between LmSocket and LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 255
diff changeset
  1077
connection_features_cb (LmMessageHandler *handler,
412
d355b566f141 Fixed indentation
Mikael Hallendal <micke@imendio.com>
parents: 411
diff changeset
  1078
                        LmConnection     *connection,
d355b566f141 Fixed indentation
Mikael Hallendal <micke@imendio.com>
parents: 411
diff changeset
  1079
                        LmMessage        *message,
d355b566f141 Fixed indentation
Mikael Hallendal <micke@imendio.com>
parents: 411
diff changeset
  1080
                        gpointer          user_data)
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1081
{
518
cdd6a0c5b439 Went 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
    LmMessageNode *bind_node;
530
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 529
diff changeset
  1083
    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
  1084
    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
  1085
    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
  1086
    
cdd6a0c5b439 Went 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
    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
  1088
    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
  1089
        if (starttls_node) {
530
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 529
diff changeset
  1090
            LmMessage *msg;
274
c32a7011e435 Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents: 271
diff changeset
  1091
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1092
            msg = lm_message_new (NULL, LM_MESSAGE_TYPE_STARTTLS);
274
c32a7011e435 Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents: 271
diff changeset
  1093
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1094
            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
  1095
                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
  1096
                "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
  1097
                NULL);
274
c32a7011e435 Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents: 271
diff changeset
  1098
518
cdd6a0c5b439 Went 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
            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
  1100
            lm_message_unref (msg);
274
c32a7011e435 Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents: 271
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
            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
  1103
        } 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
  1104
                   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
  1105
            /* 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
  1106
             * the place to scream. */
274
c32a7011e435 Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents: 271
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
            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
  1109
                   "%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
  1110
            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
  1111
            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
  1112
                                          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
  1113
            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
  1114
        }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1115
    }
274
c32a7011e435 Adding StartTLS support.
Senko Rasic <senko@phyrexia.(none)>
parents: 271
diff changeset
  1116
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1117
    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
  1118
    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
  1119
        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
  1120
        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
  1121
        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
  1122
        int               result;
223
b343ed8b3fea More style fixes to the SASL patch
Mikael Hallendal <micke@imendio.com>
parents: 222
diff changeset
  1123
518
cdd6a0c5b439 Went 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
        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
  1125
        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
  1126
            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
  1127
        }
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1128
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1129
        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
  1130
                                                 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
  1131
                                                 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
  1132
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1133
        bind_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
  1134
                                               "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
  1135
        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
  1136
                                        "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
  1137
                                        NULL);
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1138
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1139
        lm_message_node_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
  1140
                                   connection->resource);
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1141
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1142
        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
  1143
                                               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
  1144
        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
  1145
                                                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
  1146
        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
  1147
        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
  1148
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1149
        if (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
  1150
            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
  1151
                   "%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
  1152
            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
  1153
        }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1154
    }
220
f6b9482ae89e Some style fixes to the SASL patch.
Mikael Hallendal <micke@imendio.com>
parents: 219
diff changeset
  1155
518
cdd6a0c5b439 Went 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
    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
  1157
518
cdd6a0c5b439 Went 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
    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
  1159
    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
  1160
        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
  1161
               "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
  1162
        /* 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
  1163
         * 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
  1164
518
cdd6a0c5b439 Went 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
        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
  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
        if (connection->sasl) {
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
  1168
            if (lm_sasl_get_auth_params (connection->sasl)) {
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1169
                GError *error = NULL;
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
  1170
                connection_old_auth (connection, lm_sasl_get_auth_params (connection->sasl),
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1171
                                     &error);
332
6b6ad42cd508 Support obsolete XEP-0078 (old-style jabber auth for XMPP1.0).
Senko Rasic <senko@phyrexia.lan>
parents: 329
diff changeset
  1172
518
cdd6a0c5b439 Went 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
                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
  1174
                    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
  1175
                }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1176
            }
332
6b6ad42cd508 Support obsolete XEP-0078 (old-style jabber auth for XMPP1.0).
Senko Rasic <senko@phyrexia.lan>
parents: 329
diff changeset
  1177
518
cdd6a0c5b439 Went 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
            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
  1179
            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
  1180
        }
cdd6a0c5b439 Went 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
    }
332
6b6ad42cd508 Support obsolete XEP-0078 (old-style jabber auth for XMPP1.0).
Senko Rasic <senko@phyrexia.lan>
parents: 329
diff changeset
  1182
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1183
    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
  1184
}
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1185
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1186
/**
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1187
 * lm_connection_new:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1188
 * @server: The hostname to the server for the connection.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1189
 * 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1190
 * Creates a new closed connection. To open the connection call 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1191
 * lm_connection_open(). @server can be #NULL but must be set before calling lm_connection_open().
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1192
 * 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1193
 * Return value: A newly created LmConnection, should be unreffed with lm_connection_unref().
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1194
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1195
LmConnection *
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1196
lm_connection_new (const gchar *server)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1197
{
518
cdd6a0c5b439 Went 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
    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
  1199
    gint          i;
422
1c00df7a8b11 Depend on GObject and initialize GType
Mikael Hallendal <micke@imendio.com>
parents: 421
diff changeset
  1200
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1201
    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
  1202
    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
  1203
    _lm_sock_library_init ();
140
103227122f45 2006-04-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 137
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
    connection = g_slice_new0 (LmConnection);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1206
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1207
    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
  1208
        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
  1209
    }
82
a32b54e654e2 2004-03-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 80
diff changeset
  1210
532
c917a1900d5c Style fix in lm_connection_new
Mikael Hallendal <micke@imendio.com>
parents: 531
diff changeset
  1211
    connection->port        = LM_CONNECTION_DEFAULT_PORT;
c917a1900d5c Style fix in lm_connection_new
Mikael Hallendal <micke@imendio.com>
parents: 531
diff changeset
  1212
    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
  1213
                                                          connection);
532
c917a1900d5c Style fix in lm_connection_new
Mikael Hallendal <micke@imendio.com>
parents: 531
diff changeset
  1214
    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
  1215
    
cdd6a0c5b439 Went 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
    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
  1217
                                                     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
  1218
                                                     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
  1219
                                                     (GDestroyNotify) lm_message_handler_unref);
532
c917a1900d5c Style fix in lm_connection_new
Mikael Hallendal <micke@imendio.com>
parents: 531
diff changeset
  1220
    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
  1221
    
cdd6a0c5b439 Went 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
    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
  1223
        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
  1224
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
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
    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
  1227
        ((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
  1228
         connection, NULL);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1229
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1230
    return connection;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1231
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1232
82
a32b54e654e2 2004-03-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 80
diff changeset
  1233
/**
a32b54e654e2 2004-03-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 80
diff changeset
  1234
 * lm_connection_new_with_context:
a32b54e654e2 2004-03-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 80
diff changeset
  1235
 * @server: The hostname to the server for the connection.
a32b54e654e2 2004-03-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 80
diff changeset
  1236
 * @context: The context this connection should be running in.
a32b54e654e2 2004-03-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 80
diff changeset
  1237
 * 
a32b54e654e2 2004-03-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 80
diff changeset
  1238
 * 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
  1239
 * 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
  1240
 * before calling #lm_connection_open.
a32b54e654e2 2004-03-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 80
diff changeset
  1241
 * 
a32b54e654e2 2004-03-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 80
diff changeset
  1242
 * 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
  1243
 **/
a32b54e654e2 2004-03-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 80
diff changeset
  1244
LmConnection *
a32b54e654e2 2004-03-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 80
diff changeset
  1245
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
  1246
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1247
    LmConnection *connection;
82
a32b54e654e2 2004-03-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 80
diff changeset
  1248
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1249
    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
  1250
    connection->context = context;
82
a32b54e654e2 2004-03-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 80
diff changeset
  1251
518
cdd6a0c5b439 Went 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
    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
  1253
        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
  1254
    }
82
a32b54e654e2 2004-03-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 80
diff changeset
  1255
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1256
    return connection;
82
a32b54e654e2 2004-03-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 80
diff changeset
  1257
}
63
7b8d0db459ff 2004-01-05 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 62
diff changeset
  1258
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1259
/**
62
39b83ccd70ff 2003-12-27 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 61
diff changeset
  1260
 * lm_connection_open:
39b83ccd70ff 2003-12-27 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 61
diff changeset
  1261
 * @connection: #LmConnection to open
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1262
 * @function: Callback function that will be called when the connection is open.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1263
 * @user_data: User data that will be passed to @function.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1264
 * @notify: Function for freeing that user_data, can be NULL.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1265
 * @error: location to store error, or %NULL
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1266
 * 
62
39b83ccd70ff 2003-12-27 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 61
diff changeset
  1267
 * An async call to open @connection. When the connection is open @function will be called.
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1268
 * 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1269
 * Return value: #TRUE if everything went fine, otherwise #FALSE.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1270
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1271
gboolean
62
39b83ccd70ff 2003-12-27 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 61
diff changeset
  1272
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
  1273
                    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
  1274
                    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
  1275
                    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
  1276
                    GError           **error)
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1277
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1278
    g_return_val_if_fail (connection != NULL, FALSE);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1279
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1280
    connection->open_cb = _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
  1281
                                                  user_data, notify);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1282
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1283
    return connection_do_open (connection, error);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1284
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1285
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1286
/**
62
39b83ccd70ff 2003-12-27 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 61
diff changeset
  1287
 * lm_connection_open_and_block:
39b83ccd70ff 2003-12-27 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 61
diff changeset
  1288
 * @connection: an #LmConnection to open
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1289
 * @error: location to store error, or %NULL
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1290
 * 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1291
 * Opens @connection and waits until the stream is setup. 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1292
 * 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1293
 * Return value: #TRUE if no errors where encountered during opening and stream setup successfully, #FALSE otherwise.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1294
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1295
gboolean
62
39b83ccd70ff 2003-12-27 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 61
diff changeset
  1296
lm_connection_open_and_block (LmConnection *connection, GError **error)
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1297
{
543
fe1b614022fb Removed unused variable in lm_connection_open_and_block
Mikael Hallendal <micke@imendio.com>
parents: 542
diff changeset
  1298
    gboolean result;
518
cdd6a0c5b439 Went 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
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1300
    g_return_val_if_fail (connection != NULL, FALSE);
57
6b168a8917f7 2003-12-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 56
diff changeset
  1301
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1302
    connection->open_cb = NULL;
140
103227122f45 2006-04-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 137
diff changeset
  1303
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1304
    result = connection_do_open (connection, error);
63
7b8d0db459ff 2004-01-05 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 62
diff changeset
  1305
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1306
    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
  1307
        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
  1308
    }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1309
        
543
fe1b614022fb Removed unused variable in lm_connection_open_and_block
Mikael Hallendal <micke@imendio.com>
parents: 542
diff changeset
  1310
    while (lm_connection_get_state (connection) == LM_CONNECTION_STATE_OPENING) {
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1311
        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
  1312
            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
  1313
        } 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
  1314
            /* 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
  1315
            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
  1316
        }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1317
    }
64
dd835d5cee71 2004-01-06 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 63
diff changeset
  1318
518
cdd6a0c5b439 Went 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
    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
  1320
        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
  1321
        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
  1322
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1323
518
cdd6a0c5b439 Went 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
    /* 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
  1325
    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
  1326
                 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
  1327
                 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
  1328
                 "Opening the connection failed");
132
8c9c1629f691 2006-03-20 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 130
diff changeset
  1329
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1330
    return FALSE;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1331
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1332
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1333
/**
59
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  1334
 * lm_connection_cancel_open:
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  1335
 * @connection: an #LmConnection to cancel opening on
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  1336
 *
91
d51b8e4f43d9 2004-08-27 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 90
diff changeset
  1337
 * 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
  1338
 **/
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  1339
void
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  1340
lm_connection_cancel_open (LmConnection *connection)
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  1341
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1342
    g_return_if_fail (connection != NULL);
59
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
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
    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
  1345
        _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
  1346
        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
  1347
    }
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
  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->cancel_open = TRUE;
271
52ea4e0b897a Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents: 256
diff changeset
  1350
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1351
    lm_old_socket_asyncns_cancel (connection->socket);
57
6b168a8917f7 2003-12-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 56
diff changeset
  1352
}
6b168a8917f7 2003-12-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 56
diff changeset
  1353
6b168a8917f7 2003-12-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 56
diff changeset
  1354
/**
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1355
 * lm_connection_close:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1356
 * @connection: #LmConnection to close 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1357
 * @error: location to store error, or %NULL
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1358
 * 
56
3bf928955fc5 2003-11-20 Ross Burton <ross@burtonini.com>
hallski <hallski>
parents: 55
diff changeset
  1359
 * 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
  1360
 * 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1361
 * Return value: Returns #TRUE if no errors where detected, otherwise #FALSE.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1362
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1363
gboolean
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
  1364
lm_connection_close (LmConnection *connection, GError **error)
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1365
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1366
    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
  1367
    
cdd6a0c5b439 Went 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
    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
  1369
cdd6a0c5b439 Went 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
    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
  1371
        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
  1372
    }
156
8c054d9e98b8 2006-06-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 155
diff changeset
  1373
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1374
    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
  1375
        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
  1376
                     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
  1377
                     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
  1378
                     "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
  1379
        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
  1380
    }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1381
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1382
    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
  1383
                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
  1384
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1385
    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
  1386
        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
  1387
            no_errors = FALSE;
503
c7c1722ec2db Fixed a crash when lm_connection_close was called.
Mikael Hallendal <micke@imendio.com>
parents: 501
diff changeset
  1388
        }
271
52ea4e0b897a Perform name resolution asynchronously. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents: 256
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
        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
  1391
    }
cdd6a0c5b439 Went 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
    
cdd6a0c5b439 Went 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
    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
  1394
    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
  1395
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1396
    return no_errors;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1397
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1398
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1399
static void
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
  1400
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
  1401
                               LmConnection *connection,
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
  1402
                               gboolean      success,
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
  1403
                               const gchar  *reason)
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1404
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1405
    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
  1406
        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
  1407
        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
  1408
        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
  1409
    }
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1410
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1411
    connection_send_stream_header (connection);
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1412
}
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1413
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1414
/**
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1415
 * lm_connection_authenticate:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1416
 * @connection: #LmConnection to authenticate.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1417
 * @username: Username used to authenticate.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1418
 * @password: Password corresponding to @username.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1419
 * @resource: Resource used for this connection.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1420
 * @function: Callback called when authentication is finished.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1421
 * @user_data: Userdata passed to @function when called.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1422
 * @notify: Destroy function to free the memory used by @user_data, can be NULL.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1423
 * @error: location to store error, or %NULL
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1424
 * 
56
3bf928955fc5 2003-11-20 Ross Burton <ross@burtonini.com>
hallski <hallski>
parents: 55
diff changeset
  1425
 * 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
  1426
 * 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1427
 * Return value: #TRUE if no errors where detected while sending the authentication message, #FALSE otherwise.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1428
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1429
gboolean
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1430
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
  1431
                            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
  1432
                            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
  1433
                            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
  1434
                            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
  1435
                            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
  1436
                            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
  1437
                            GError           **error)
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1438
{
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
  1439
    LmAuthParameters *auth_params;
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
  1440
    gboolean          ret_val;
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
  1441
    
518
cdd6a0c5b439 Went 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
    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
  1443
    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
  1444
    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
  1445
    g_return_val_if_fail (resource != NULL, FALSE);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1446
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
  1447
    auth_params = lm_auth_parameters_new (username, password, resource);
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
  1448
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1449
    if (!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
  1450
        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
  1451
                     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
  1452
                     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
  1453
                     "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
  1454
        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
  1455
    }
59
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  1456
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1457
    connection->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
  1458
    
cdd6a0c5b439 Went 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->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
  1460
                                                  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
  1461
                                                  notify);
21
091f3e5ec468 2003-07-17 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 15
diff changeset
  1462
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
  1463
    connection->resource = g_strdup (lm_auth_parameters_get_resource (auth_params));
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
  1464
                                              
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1465
    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
  1466
                                                 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
  1467
533
c45243823756 Added some TODO items and minor style fixes
Mikael Hallendal <micke@imendio.com>
parents: 532
diff changeset
  1468
    /* 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
  1469
     *       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
  1470
    if (connection->use_sasl) {
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
  1471
        lm_sasl_authenticate (connection->sasl, auth_params, connection->server,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1472
                              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
  1473
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1474
        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
  1475
            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
  1476
                                    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
  1477
        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
  1478
                                                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
  1479
                                                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
  1480
                                                LM_HANDLER_PRIORITY_FIRST);
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1481
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
  1482
        ret_val = TRUE;
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
  1483
    } else {
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
  1484
        ret_val = connection_old_auth (connection, auth_params, error);
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1485
    }
219
6daf884bc7bd Added SASL-support to LmConnection, patch from Senko Rasic
Mikael Hallendal <micke@imendio.com>
parents: 211
diff changeset
  1486
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
  1487
    lm_auth_parameters_unref (auth_params);
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
  1488
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
  1489
    return ret_val;
332
6b6ad42cd508 Support obsolete XEP-0078 (old-style jabber auth for XMPP1.0).
Senko Rasic <senko@phyrexia.lan>
parents: 329
diff changeset
  1490
}
6b6ad42cd508 Support obsolete XEP-0078 (old-style jabber auth for XMPP1.0).
Senko Rasic <senko@phyrexia.lan>
parents: 329
diff changeset
  1491
415
14ff0a255a86 Moved _lm_connection_old_auth from public header file.
Mikael Hallendal <micke@imendio.com>
parents: 413
diff changeset
  1492
static gboolean
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
  1493
connection_old_auth (LmConnection      *connection,
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
  1494
                     LmAuthParameters  *auth_params,
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
  1495
                     GError           **error)
332
6b6ad42cd508 Support obsolete XEP-0078 (old-style jabber auth for XMPP1.0).
Senko Rasic <senko@phyrexia.lan>
parents: 329
diff changeset
  1496
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1497
    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
  1498
    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
  1499
    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
  1500
    
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
  1501
    m = connection_create_auth_req_msg (auth_params);
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1502
        
cdd6a0c5b439 Went 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
    handler = lm_message_handler_new (connection_auth_req_reply, 
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
  1504
                                      lm_auth_parameters_ref (auth_params),
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 534
diff changeset
  1505
                                      (GDestroyNotify) lm_auth_parameters_unref);
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1506
    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
  1507
    
cdd6a0c5b439 Went 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
    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
  1509
    lm_message_unref (m);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1510
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1511
    return result;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1512
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1513
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1514
/**
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1515
 * lm_connection_authenticate_and_block:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1516
 * @connection: an #LmConnection
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1517
 * @username: Username used to authenticate.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1518
 * @password: Password corresponding to @username.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1519
 * @resource: Resource used for this connection.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1520
 * @error: location to store error, or %NULL
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1521
 * 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1522
 * 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
  1523
 * 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1524
 * Return value: #TRUE if no errors where detected and authentication was successful. #FALSE otherwise.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1525
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1526
gboolean
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1527
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
  1528
                                      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
  1529
                                      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
  1530
                                      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
  1531
                                      GError       **error)
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1532
{
530
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 529
diff changeset
  1533
    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
  1534
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1535
    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
  1536
                                         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
  1537
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1538
    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
  1539
        return result;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1540
518
cdd6a0c5b439 Went 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
    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
  1542
        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
  1543
            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
  1544
        } 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
  1545
            /* 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
  1546
            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
  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
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1549
518
cdd6a0c5b439 Went 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
    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
  1551
    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
  1552
        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
  1553
        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
  1554
    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
  1555
        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
  1556
                     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
  1557
                     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
  1558
                     "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
  1559
        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
  1560
        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
  1561
    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
  1562
        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
  1563
        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
  1564
    } 
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1565
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1566
    return FALSE;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1567
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1568
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1569
/**
394
03933ba2fb40 Added lm_connection_get_keep_alive.
Mikael Hallendal <micke@imendio.com>
parents: 345
diff changeset
  1570
 * lm_connection_get_keep_alive_rate:
03933ba2fb40 Added lm_connection_get_keep_alive.
Mikael Hallendal <micke@imendio.com>
parents: 345
diff changeset
  1571
 * @connection: an #LmConnection 
03933ba2fb40 Added lm_connection_get_keep_alive.
Mikael Hallendal <micke@imendio.com>
parents: 345
diff changeset
  1572
 *
03933ba2fb40 Added lm_connection_get_keep_alive.
Mikael Hallendal <micke@imendio.com>
parents: 345
diff changeset
  1573
 * 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
  1574
 *
03933ba2fb40 Added lm_connection_get_keep_alive.
Mikael Hallendal <micke@imendio.com>
parents: 345
diff changeset
  1575
 * Since 1.3.5
03933ba2fb40 Added lm_connection_get_keep_alive.
Mikael Hallendal <micke@imendio.com>
parents: 345
diff changeset
  1576
 **/
03933ba2fb40 Added lm_connection_get_keep_alive.
Mikael Hallendal <micke@imendio.com>
parents: 345
diff changeset
  1577
guint
03933ba2fb40 Added lm_connection_get_keep_alive.
Mikael Hallendal <micke@imendio.com>
parents: 345
diff changeset
  1578
lm_connection_get_keep_alive_rate (LmConnection *connection)
03933ba2fb40 Added lm_connection_get_keep_alive.
Mikael Hallendal <micke@imendio.com>
parents: 345
diff changeset
  1579
{
518
cdd6a0c5b439 Went 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
    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
  1581
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1582
    return connection->keep_alive_rate;
394
03933ba2fb40 Added lm_connection_get_keep_alive.
Mikael Hallendal <micke@imendio.com>
parents: 345
diff changeset
  1583
}
03933ba2fb40 Added lm_connection_get_keep_alive.
Mikael Hallendal <micke@imendio.com>
parents: 345
diff changeset
  1584
03933ba2fb40 Added lm_connection_get_keep_alive.
Mikael Hallendal <micke@imendio.com>
parents: 345
diff changeset
  1585
/**
90
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
  1586
 * lm_connection_set_keep_alive_rate:
394
03933ba2fb40 Added lm_connection_get_keep_alive.
Mikael Hallendal <micke@imendio.com>
parents: 345
diff changeset
  1587
 * @connection: an #LmConnection
90
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
  1588
 * @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
  1589
 * 
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
  1590
 * 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
  1591
 * A keep alive message is a single space character.
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
  1592
 **/
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
  1593
void
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
  1594
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
  1595
{
518
cdd6a0c5b439 Went 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_return_if_fail (connection != NULL);
90
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
  1597
518
cdd6a0c5b439 Went 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
    connection_stop_keep_alive (connection);
90
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
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
    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
  1601
        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
  1602
    }
90
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
  1603
518
cdd6a0c5b439 Went 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
    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
  1605
    
cdd6a0c5b439 Went 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
    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
  1607
        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
  1608
    }
90
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
  1609
}
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
  1610
3f4b38614416 2004-08-25 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 89
diff changeset
  1611
/**
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1612
 * lm_connection_is_open:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1613
 * @connection: #LmConnection to check if it is open.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1614
 * 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1615
 * Check if the @connection is currently open.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1616
 * 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1617
 * Return value: #TRUE if connection is open and #FALSE if it is closed.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1618
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1619
gboolean
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1620
lm_connection_is_open (LmConnection *connection)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1621
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1622
    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
  1623
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1624
    return connection->state >= LM_CONNECTION_STATE_OPEN;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1625
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1626
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1627
/**
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1628
 * lm_connection_is_authenticated:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1629
 * @connection: #LmConnection to check if it is authenticated
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1630
 * 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1631
 * Check if @connection is authenticated.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1632
 * 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1633
 * Return value: #TRUE if connection is authenticated, #FALSE otherwise.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1634
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1635
gboolean 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1636
lm_connection_is_authenticated (LmConnection *connection)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1637
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1638
    g_return_val_if_fail (connection != NULL, FALSE);
66
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1639
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1640
    return connection->state >= LM_CONNECTION_STATE_AUTHENTICATED;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1641
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1642
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1643
/**
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1644
 * lm_connection_get_server:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1645
 * @connection: an #LmConnection
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1646
 * 
89
e756a937e540 2004-08-09 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 87
diff changeset
  1647
 * Fetches the server address that @connection is using. 
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1648
 * 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1649
 * Return value: the server address
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1650
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1651
const gchar *
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1652
lm_connection_get_server (LmConnection *connection)
50e230cf7818 Initial revision
hallski <hallski>
parents:
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
    g_return_val_if_fail (connection != NULL, NULL);
66
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1655
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1656
    return connection->server;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1657
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1658
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1659
/**
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1660
 * lm_connection_set_server:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1661
 * @connection: an #LmConnection
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1662
 * @server: Address of the server
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1663
 * 
87
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
  1664
 * 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
  1665
 * can't be open while doing this. 
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1666
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1667
void
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1668
lm_connection_set_server (LmConnection *connection, const gchar *server)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1669
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1670
    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
  1671
    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
  1672
    
cdd6a0c5b439 Went 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
    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
  1674
        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
  1675
        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
  1676
    }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1677
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1678
    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
  1679
    connection->server = _lm_utils_hostname_to_punycode (server);
87
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
  1680
}
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
  1681
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
  1682
/**
89
e756a937e540 2004-08-09 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 87
diff changeset
  1683
 * lm_connection_get_jid:
87
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
  1684
 * @connection: an #LmConnection
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
  1685
 * 
89
e756a937e540 2004-08-09 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 87
diff changeset
  1686
 * Fetches the jid set for @connection is using. 
87
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
  1687
 * 
89
e756a937e540 2004-08-09 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 87
diff changeset
  1688
 * Return value: the jid
87
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
  1689
 **/
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
  1690
const gchar *
89
e756a937e540 2004-08-09 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 87
diff changeset
  1691
lm_connection_get_jid (LmConnection *connection)
87
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
  1692
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1693
    g_return_val_if_fail (connection != NULL, NULL);
87
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
  1694
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1695
    return connection->jid;
87
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
  1696
}
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
  1697
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
  1698
/**
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
  1699
 * 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
  1700
 * @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
  1701
 * 
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
  1702
 * 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
  1703
 * 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
  1704
 *
f65eee8ec802 Support for returning effective JID, possibly changed by the server.
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 294
diff changeset
  1705
 * 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
  1706
 **/
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
  1707
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
  1708
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
  1709
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1710
    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
  1711
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1712
    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
  1713
}
f65eee8ec802 Support for returning effective JID, possibly changed by the server.
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 294
diff changeset
  1714
f65eee8ec802 Support for returning effective JID, possibly changed by the server.
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 294
diff changeset
  1715
/**
89
e756a937e540 2004-08-09 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 87
diff changeset
  1716
 * lm_connection_set_jid:
87
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
  1717
 * @connection: an #LmConnection
89
e756a937e540 2004-08-09 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 87
diff changeset
  1718
 * @jid: JID to be used for @connection
87
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
  1719
 * 
89
e756a937e540 2004-08-09 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 87
diff changeset
  1720
 * Sets the JID to be used for @connection.
87
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
  1721
 **/
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
  1722
void 
89
e756a937e540 2004-08-09 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 87
diff changeset
  1723
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
  1724
{
518
cdd6a0c5b439 Went 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
    g_return_if_fail (connection != NULL);
87
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
  1726
518
cdd6a0c5b439 Went 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
    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
  1728
        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
  1729
        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
  1730
    }
87
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
  1731
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1732
    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
  1733
    connection->jid = g_strdup (jid);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1734
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1735
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1736
/**
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1737
 * lm_connection_get_port:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1738
 * @connection: an #LmConnection
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1739
 * 
56
3bf928955fc5 2003-11-20 Ross Burton <ross@burtonini.com>
hallski <hallski>
parents: 55
diff changeset
  1740
 * Fetches the port that @connection is using.
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1741
 * 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1742
 * Return value: 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1743
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1744
guint
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1745
lm_connection_get_port (LmConnection *connection)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1746
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1747
    g_return_val_if_fail (connection != NULL, 0);
66
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1748
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1749
    return connection->port;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1750
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1751
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1752
/**
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1753
 * lm_connection_set_port:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1754
 * @connection: an #LmConnection
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1755
 * @port: server port
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1756
 * 
56
3bf928955fc5 2003-11-20 Ross Burton <ross@burtonini.com>
hallski <hallski>
parents: 55
diff changeset
  1757
 * Sets the server port that @connection will be using.
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1758
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1759
void
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1760
lm_connection_set_port (LmConnection *connection, guint port)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1761
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1762
    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
  1763
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1764
    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
  1765
        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
  1766
        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
  1767
    }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1768
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1769
    connection->port = port;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1770
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1771
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1772
/**
68
28203e15de0e 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 67
diff changeset
  1773
 * lm_connection_get_ssl: 
28203e15de0e 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 67
diff changeset
  1774
 * @connection: an #LmConnection
15
1ff2f81867e1 2003-07-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 12
diff changeset
  1775
 *
68
28203e15de0e 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 67
diff changeset
  1776
 * 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
  1777
 * 
28203e15de0e 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 67
diff changeset
  1778
 * 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
  1779
 **/
68
28203e15de0e 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 67
diff changeset
  1780
LmSSL *
28203e15de0e 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 67
diff changeset
  1781
lm_connection_get_ssl (LmConnection *connection)
15
1ff2f81867e1 2003-07-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 12
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_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
  1784
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1785
    return connection->ssl;
15
1ff2f81867e1 2003-07-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 12
diff changeset
  1786
}
68
28203e15de0e 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 67
diff changeset
  1787
28203e15de0e 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 67
diff changeset
  1788
/**
28203e15de0e 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 67
diff changeset
  1789
 * lm_connection_set_ssl:
28203e15de0e 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 67
diff changeset
  1790
 * @connection: An #LmConnection
28203e15de0e 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 67
diff changeset
  1791
 * @ssl: An #LmSSL
28203e15de0e 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 67
diff changeset
  1792
 *
28203e15de0e 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 67
diff changeset
  1793
 * 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
  1794
 */
39b83ccd70ff 2003-12-27 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 61
diff changeset
  1795
void
68
28203e15de0e 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 67
diff changeset
  1796
lm_connection_set_ssl (LmConnection *connection, LmSSL *ssl)
62
39b83ccd70ff 2003-12-27 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 61
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_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
  1799
    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
  1800
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1801
    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
  1802
        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
  1803
    }
66
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1804
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1805
    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
  1806
        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
  1807
    } 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
  1808
        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
  1809
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1810
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1811
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1812
/**
66
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1813
 * lm_connection_get_proxy: 
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1814
 * @connection: an #LmConnection
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1815
 *
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1816
 * Returns the proxy if the connection is using one.
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1817
 * 
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1818
 * 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
  1819
 **/
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1820
LmProxy *
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1821
lm_connection_get_proxy (LmConnection *connection)
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1822
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1823
    g_return_val_if_fail (connection != NULL, NULL);
66
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1824
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1825
    return connection->proxy;
66
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1826
} 
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1827
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1828
/**
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1829
 * lm_connection_set_proxy: 
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1830
 * @connection: an #LmConnection
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1831
 * @proxy: an #LmProxy
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1832
 *
94
85b606ac2c0c 2004-09-02 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 93
diff changeset
  1833
 * 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
  1834
 * 
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1835
 **/
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1836
void
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1837
lm_connection_set_proxy (LmConnection *connection, LmProxy *proxy)
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1838
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1839
    g_return_if_fail (connection != NULL);
66
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1840
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1841
    if (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
  1842
        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
  1843
        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
  1844
    }
87
2d68f59e3fd4 2004-08-08 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
  1845
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1846
    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
  1847
        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
  1848
        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
  1849
    }
66
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1850
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1851
    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
  1852
        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
  1853
    }
66
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1854
}
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1855
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1856
/**
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1857
 * lm_connection_send: 
56
3bf928955fc5 2003-11-20 Ross Burton <ross@burtonini.com>
hallski <hallski>
parents: 55
diff changeset
  1858
 * @connection: #LmConnection to send message over.
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1859
 * @message: #LmMessage to send.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1860
 * @error: location to store error, or %NULL
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1861
 * 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1862
 * Asynchronous call to send a message.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1863
 * 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1864
 * Return value: Returns #TRUE if no errors where detected while sending, #FALSE otherwise.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1865
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1866
gboolean
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1867
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
  1868
                    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
  1869
                    GError       **error)
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1870
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1871
    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
  1872
    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
  1873
    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
  1874
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1875
    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
  1876
    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
  1877
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1878
    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
  1879
    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
  1880
        *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
  1881
    }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1882
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1883
    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
  1884
    g_free (xml_str);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1885
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1886
    return result;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1887
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1888
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1889
/**
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1890
 * lm_connection_send_with_reply:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1891
 * @connection: #LmConnection used to send message.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1892
 * @message: #LmMessage to send.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1893
 * @handler: #LmMessageHandler that will be used when a reply to @message arrives
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1894
 * @error: location to store error, or %NULL
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1895
 * 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1896
 * Send a #LmMessage which will result in a reply. 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1897
 * 
56
3bf928955fc5 2003-11-20 Ross Burton <ross@burtonini.com>
hallski <hallski>
parents: 55
diff changeset
  1898
 * Return value: Returns #TRUE if no errors where detected while sending, #FALSE otherwise.
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1899
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1900
gboolean 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1901
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
  1902
                               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
  1903
                               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
  1904
                               GError           **error)
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1905
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1906
    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
  1907
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1908
    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
  1909
    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
  1910
    g_return_val_if_fail (handler != NULL, FALSE);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1911
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1912
    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
  1913
        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
  1914
                                                      "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
  1915
    } 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
  1916
        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
  1917
        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
  1918
    }
cdd6a0c5b439 Went 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
    
cdd6a0c5b439 Went 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
    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
  1921
                         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
  1922
    
cdd6a0c5b439 Went 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
    return lm_connection_send (connection, message, error);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1924
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1925
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1926
/**
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1927
 * lm_connection_send_with_reply_and_block:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1928
 * @connection: an #LmConnection
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1929
 * @message: an #LmMessage
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1930
 * @error: Set if error was detected during sending.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1931
 * 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1932
 * Send @message and wait for return.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1933
 * 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1934
 * Return value: The reply
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1935
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1936
LmMessage *
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1937
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
  1938
                                         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
  1939
                                         GError       **error)
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1940
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1941
    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
  1942
    LmMessage *reply = NULL;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1943
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1944
    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
  1945
    g_return_val_if_fail (message != NULL, NULL);
66
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  1946
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1947
    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
  1948
        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
  1949
                     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
  1950
                     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
  1951
                     "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
  1952
        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
  1953
    }
125
6163119136b5 2005-08-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 124
diff changeset
  1954
6163119136b5 2005-08-12 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 124
diff changeset
  1955
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1956
    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
  1957
        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
  1958
                                                      "id"));
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1959
    } 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
  1960
        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
  1961
        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
  1962
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1963
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1964
    lm_message_queue_detach (connection->queue);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1965
518
cdd6a0c5b439 Went 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
    lm_connection_send (connection, message, error);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1967
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1968
    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
  1969
        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
  1970
        guint        n;
39
b909b5af5a97 2003-10-01 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 37
diff changeset
  1971
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1972
        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
  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
        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
  1975
            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
  1976
        }
39
b909b5af5a97 2003-10-01 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 37
diff changeset
  1977
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1978
        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
  1979
            LmMessage *m;
39
b909b5af5a97 2003-10-01 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 37
diff changeset
  1980
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1981
            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
  1982
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1983
            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
  1984
            
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1985
            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
  1986
                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
  1987
                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
  1988
                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
  1989
            }
cdd6a0c5b439 Went 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
        }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1991
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1992
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1993
    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
  1994
    lm_message_queue_attach (connection->queue, connection->context);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1995
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1996
    return reply;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1997
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1998
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  1999
/**
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2000
 * lm_connection_register_message_handler:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2001
 * @connection: Connection to register a handler for.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2002
 * @handler: Message handler to register.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2003
 * @type: Message type that @handler will handle.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2004
 * @priority: The priority in which to call @handler.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2005
 * 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2006
 * Registers a #LmMessageHandler to handle incoming messages of a certain type.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2007
 * To unregister the handler call lm_connection_unregister_message_handler().
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2008
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2009
void
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
  2010
lm_connection_register_message_handler  (LmConnection      *connection,
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
  2011
                                         LmMessageHandler  *handler,
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
  2012
                                         LmMessageType      type,
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
  2013
                                         LmHandlerPriority  priority)
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2014
{
530
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 529
diff changeset
  2015
    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
  2016
    
cdd6a0c5b439 Went 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
    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
  2018
    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
  2019
    g_return_if_fail (type != LM_MESSAGE_TYPE_UNKNOWN);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2020
518
cdd6a0c5b439 Went 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
    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
  2022
    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
  2023
    hd->handler  = lm_message_handler_ref (handler);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2024
518
cdd6a0c5b439 Went 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
    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
  2026
                                                        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
  2027
                                                        (GCompareFunc) connection_handler_compare_func);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2028
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2029
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2030
/**
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2031
 * lm_connection_unregister_message_handler:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2032
 * @connection: Connection to unregister a handler for.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2033
 * @handler: The handler to unregister.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2034
 * @type: What type of messages to unregister this handler for.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2035
 * 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2036
 * Unregisters a handler for @connection. @handler will no longer be called 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2037
 * when incoming messages of @type arrive.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2038
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2039
void
528
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
  2040
lm_connection_unregister_message_handler (LmConnection     *connection,
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
  2041
                                          LmMessageHandler *handler,
5b46873eeef8 Style fixes
Mikael Hallendal <micke@imendio.com>
parents: 519
diff changeset
  2042
                                          LmMessageType     type)
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
    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
  2045
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2046
    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
  2047
    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
  2048
    g_return_if_fail (type != LM_MESSAGE_TYPE_UNKNOWN);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2049
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2050
    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
  2051
        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
  2052
        
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2053
        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
  2054
            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
  2055
            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
  2056
            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
  2057
            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
  2058
            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
  2059
        }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2060
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2061
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2062
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2063
/**
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2064
 * lm_connection_set_disconnect_function:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2065
 * @connection: Connection to register disconnect callback for.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2066
 * @function: Function to be called when @connection is closed.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2067
 * @user_data: User data passed to @function.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2068
 * @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
  2069
 * 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2070
 * Set the callback that will be called when a connection is closed. 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2071
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2072
void
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2073
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
  2074
                                       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
  2075
                                       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
  2076
                                       GDestroyNotify        notify)
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2077
{
518
cdd6a0c5b439 Went 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
    g_return_if_fail (connection != NULL);
66
577d5059b718 2004-01-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 65
diff changeset
  2079
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2080
    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
  2081
        _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
  2082
    }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2083
        
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2084
    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
  2085
        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
  2086
                                                            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
  2087
                                                            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
  2088
    } 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
  2089
        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
  2090
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2091
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2092
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2093
/**
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2094
 * lm_connection_send_raw:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2095
 * @connection: Connection used to send
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2096
 * @str: The string to send, the entire string will be sent.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2097
 * @error: Set if error was detected during sending.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2098
 * 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2099
 * Asynchronous call to send a raw string. Useful for debugging and testing.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2100
 * 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2101
 * Return value: Returns #TRUE if no errors was detected during sending, 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2102
 * #FALSE otherwise.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2103
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2104
gboolean 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2105
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
  2106
                        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
  2107
                        GError       **error)
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2108
{
518
cdd6a0c5b439 Went 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
    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
  2110
    g_return_val_if_fail (str != NULL, FALSE);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2111
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2112
    return connection_send (connection, str, -1, error);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2113
}
59
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  2114
/**
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  2115
 * lm_connection_get_state:
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  2116
 * @connection: Connection to get state on
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  2117
 *
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  2118
 * Returns the state of the connection.
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  2119
 *
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  2120
 * Return value: The state of the connection.
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  2121
 **/
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  2122
LmConnectionState 
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  2123
lm_connection_get_state (LmConnection *connection)
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  2124
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2125
    g_return_val_if_fail (connection != NULL, 
cdd6a0c5b439 Went 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
                          LM_CONNECTION_STATE_CLOSED);
59
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  2127
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2128
    return connection->state;
59
ef952e8c114d 2003-12-19 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 57
diff changeset
  2129
}
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2130
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2131
/**
308
7e2050a6df75 Added lm_connection_get_client_host (forward-port from LM1.2).
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 307
diff changeset
  2132
 * 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
  2133
 * @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
  2134
 *
7e2050a6df75 Added lm_connection_get_client_host (forward-port from LM1.2).
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 307
diff changeset
  2135
 * 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
  2136
 *
7e2050a6df75 Added lm_connection_get_client_host (forward-port from LM1.2).
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 307
diff changeset
  2137
 * 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
  2138
 **/
7e2050a6df75 Added lm_connection_get_client_host (forward-port from LM1.2).
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 307
diff changeset
  2139
gchar *
7e2050a6df75 Added lm_connection_get_client_host (forward-port from LM1.2).
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 307
diff changeset
  2140
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
  2141
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2142
    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
  2143
}
7e2050a6df75 Added lm_connection_get_client_host (forward-port from LM1.2).
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 307
diff changeset
  2144
7e2050a6df75 Added lm_connection_get_client_host (forward-port from LM1.2).
Senko Rasic <senko.rasic@collabora.co.uk>
parents: 307
diff changeset
  2145
/**
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2146
 * lm_connection_ref:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2147
 * @connection: Connection to add a reference to.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2148
 * 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2149
 * Add a reference on @connection. To remove a reference call 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2150
 * lm_connection_unref().
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2151
 * 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2152
 * Return value: Returns the same connection.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2153
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2154
LmConnection*
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2155
lm_connection_ref (LmConnection *connection)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2156
{
518
cdd6a0c5b439 Went 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
    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
  2158
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2159
    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
  2160
    
cdd6a0c5b439 Went 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
    return connection;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2162
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2163
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2164
/**
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2165
 * lm_connection_unref:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2166
 * @connection: Connection to remove reference from.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2167
 * 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2168
 * 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
  2169
 * @connection it will be freed and shouldn't be used again.
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2170
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2171
void
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2172
lm_connection_unref (LmConnection *connection)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2173
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2174
    g_return_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
  2175
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2176
    connection->ref_count--;
cdd6a0c5b439 Went 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
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  2178
    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
  2179
        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
  2180
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
  2181
}