loudmouth/lm-old-socket.c
author Frank Zschockelt <lm@freakysoft.de>
Sat, 11 May 2019 22:25:15 +0200
changeset 737 ca896de7b10d
parent 736 97f3ff94976f
permissions -rw-r--r--
Handle G_IO_HUP and G_IO_NVAL when connecting
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 -*- */
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
     2
/*
512
9f050099129d Updated copyright years
Mikael Hallendal <micke@imendio.com>
parents: 502
diff changeset
     3
 * Copyright (C) 2006-2008 Imendio AB
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
     4
 * Copyright (C) 2006 Nokia Corporation. All rights reserved.
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
     5
 * Copyright (C) 2007 Collabora Ltd.
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
     6
 *
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
     7
 * This program is free software; you can redistribute it and/or
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
     8
 * modify it under the terms of the GNU Lesser General Public License as
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
     9
 * published by the Free Software Foundation; either version 2 of the
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    10
 * License, or (at your option) any later version.
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    11
 *
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    12
 * This program is distributed in the hope that it will be useful,
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    15
 * Lesser General Public License for more details.
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    16
 *
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    17
 * You should have received a copy of the GNU Lesser General Public
690
7ccf2113ec5f Update the postal address of the FSF
Frank Zschockelt <lm@freakysoft.de>
parents: 664
diff changeset
    18
 * License along with this program; if not, see <https://www.gnu.org/licenses>
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    19
 */
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    20
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    21
#include <config.h>
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    22
726
ea6aaf57f344 Support connecting to IPv6 servers
Michał Kępień <github@kempniu.pl>
parents: 723
diff changeset
    23
#include <errno.h>
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    24
#include <string.h>
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    25
#include <sys/types.h>
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    26
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    27
/* Needed on Mac OS X */
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    28
#if HAVE_NETINET_IN_H
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    29
#include <netinet/in.h>
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    30
#endif
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    31
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    32
/* Needed on Mac OS X */
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    33
#if HAVE_ARPA_NAMESER_COMPAT_H
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    34
#include <arpa/nameser_compat.h>
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    35
#endif
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    36
588
d4468955feb1 Logging Adjustments
Jayson Vantuyl <jvantuyl@engineyard.com>
parents: 587
diff changeset
    37
#include <arpa/inet.h>
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    38
#include <arpa/nameser.h>
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    39
#include <resolv.h>
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    40
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    41
#include "lm-debug.h"
475
001da49d7fd1 Added cancel operation for asyncns resolver
Mikael Hallendal <micke@imendio.com>
parents: 470
diff changeset
    42
#include "lm-error.h"
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    43
#include "lm-internals.h"
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    44
#include "lm-misc.h"
475
001da49d7fd1 Added cancel operation for asyncns resolver
Mikael Hallendal <micke@imendio.com>
parents: 470
diff changeset
    45
#include "lm-proxy.h"
001da49d7fd1 Added cancel operation for asyncns resolver
Mikael Hallendal <micke@imendio.com>
parents: 470
diff changeset
    46
#include "lm-resolver.h"
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    47
#include "lm-ssl.h"
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    48
#include "lm-ssl-internals.h"
475
001da49d7fd1 Added cancel operation for asyncns resolver
Mikael Hallendal <micke@imendio.com>
parents: 470
diff changeset
    49
#include "lm-sock.h"
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    50
#include "lm-old-socket.h"
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    51
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    52
#define IN_BUFFER_SIZE 1024
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    53
#define SRV_LEN 8192
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    54
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    55
struct _LmOldSocket {
530
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
    56
    LmConnection      *connection;
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
    57
    GMainContext      *context;
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    58
530
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
    59
    gchar             *domain;
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
    60
    gchar             *server;
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
    61
    guint              port;
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    62
530
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
    63
    LmSSL             *ssl;
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
    64
    gboolean           ssl_started;
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
    65
    LmProxy           *proxy;
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    66
530
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
    67
    GIOChannel        *io_channel;
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
    68
    GSource           *watch_in;
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
    69
    GSource           *watch_err;
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
    70
    GSource           *watch_hup;
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    71
530
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
    72
    LmOldSocketT       fd;
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    73
530
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
    74
    GSource           *watch_connect;
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    75
530
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
    76
    gboolean           cancel_open;
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
    77
530
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
    78
    GSource           *watch_out;
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
    79
    GString           *out_buf;
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    80
530
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
    81
    LmConnectData     *connect_data;
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    82
530
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
    83
    IncomingDataFunc   data_func;
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
    84
    SocketClosedFunc   closed_func;
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
    85
    ConnectResultFunc  connect_func;
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
    86
    gpointer           user_data;
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    87
530
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
    88
    guint              ref_count;
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    89
530
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
    90
    LmResolver        *resolver;
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
    91
};
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    92
530
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
    93
static void         socket_free                    (LmOldSocket    *socket);
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
    94
static gboolean     socket_do_connect              (LmConnectData  *connect_data);
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
    95
static gboolean     socket_connect_cb              (GIOChannel     *source,
530
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
    96
                                                    GIOCondition    condition,
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
    97
                                                    LmConnectData  *connect_data);
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
    98
static gboolean     socket_in_event                (GIOChannel     *source,
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
    99
                                                    GIOCondition    condition,
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   100
                                                    LmOldSocket    *socket);
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   101
static gboolean     socket_hup_event               (GIOChannel     *source,
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   102
                                                    GIOCondition    condition,
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   103
                                                    LmOldSocket    *socket);
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   104
static gboolean     socket_error_event             (GIOChannel     *source,
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   105
                                                    GIOCondition    condition,
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   106
                                                    LmOldSocket    *socket);
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   107
static gboolean     socket_buffered_write_cb       (GIOChannel     *source,
530
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   108
                                                    GIOCondition    condition,
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   109
                                                    LmOldSocket    *socket);
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   110
static void         socket_close_io_channel        (GIOChannel     *io_channel);
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   111
static gboolean     old_socket_output_is_buffered  (LmOldSocket    *socket,
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   112
                                                    const gchar    *buffer,
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   113
                                                    gint            len);
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   114
static void         old_socket_setup_output_buffer (LmOldSocket    *socket,
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   115
                                                    const gchar    *buffer,
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   116
                                                    gint            len);
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   117
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   118
static void
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   119
socket_free (LmOldSocket *socket)
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   120
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   121
    g_free (socket->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
   122
    g_free (socket->domain);
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   123
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   124
    if (socket->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
   125
        lm_ssl_unref (socket->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
   126
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   127
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   128
    if (socket->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
   129
        lm_proxy_unref (socket->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
   130
    }
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   131
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   132
    if (socket->out_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
   133
        g_string_free (socket->out_buf, 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
   134
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   135
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   136
    if (socket->resolver) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   137
        g_object_unref (socket->resolver);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   138
    }
476
08d36982e998 First cut of integrating the new resolver in LmOldSocket
Mikael Hallendal <micke@imendio.com>
parents: 475
diff changeset
   139
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   140
    g_free (socket);
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   141
}
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   142
448
4aec5fbe96f1 Split out old_socket_do_write from lm_old_socket_do_write.
Mikael Hallendal <micke@imendio.com>
parents: 447
diff changeset
   143
static gint
4aec5fbe96f1 Split out old_socket_do_write from lm_old_socket_do_write.
Mikael Hallendal <micke@imendio.com>
parents: 447
diff changeset
   144
old_socket_do_write (LmOldSocket *socket, const gchar *buf, guint len)
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   145
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   146
    gint b_written;
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   147
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   148
    if (socket->ssl_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
   149
        b_written = _lm_ssl_send (socket->ssl, buf, 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
   150
    } 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
   151
        GIOStatus io_status = G_IO_STATUS_AGAIN;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   152
        gsize     bytes_written;
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   153
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   154
        while (io_status == G_IO_STATUS_AGAIN) {
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   155
            io_status = g_io_channel_write_chars (socket->io_channel,
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   156
                                                  buf, len,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   157
                                                  &bytes_written,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   158
                                                  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
   159
        }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   160
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   161
        b_written = bytes_written;
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   162
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   163
        if (io_status != G_IO_STATUS_NORMAL) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   164
            b_written = -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
   165
        }
cdd6a0c5b439 Went 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
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   167
518
cdd6a0c5b439 Went 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
    return b_written;
448
4aec5fbe96f1 Split out old_socket_do_write from lm_old_socket_do_write.
Mikael Hallendal <micke@imendio.com>
parents: 447
diff changeset
   169
}
4aec5fbe96f1 Split out old_socket_do_write from lm_old_socket_do_write.
Mikael Hallendal <micke@imendio.com>
parents: 447
diff changeset
   170
4aec5fbe96f1 Split out old_socket_do_write from lm_old_socket_do_write.
Mikael Hallendal <micke@imendio.com>
parents: 447
diff changeset
   171
gint
4aec5fbe96f1 Split out old_socket_do_write from lm_old_socket_do_write.
Mikael Hallendal <micke@imendio.com>
parents: 447
diff changeset
   172
lm_old_socket_write (LmOldSocket *socket, const gchar *buf, gint len)
4aec5fbe96f1 Split out old_socket_do_write from lm_old_socket_do_write.
Mikael Hallendal <micke@imendio.com>
parents: 447
diff changeset
   173
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   174
    gint b_written;
448
4aec5fbe96f1 Split out old_socket_do_write from lm_old_socket_do_write.
Mikael Hallendal <micke@imendio.com>
parents: 447
diff changeset
   175
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   176
    if (old_socket_output_is_buffered (socket, buf, 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
   177
        return 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
   178
    }
448
4aec5fbe96f1 Split out old_socket_do_write from lm_old_socket_do_write.
Mikael Hallendal <micke@imendio.com>
parents: 447
diff changeset
   179
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   180
    b_written = old_socket_do_write (socket, buf, len);
448
4aec5fbe96f1 Split out old_socket_do_write from lm_old_socket_do_write.
Mikael Hallendal <micke@imendio.com>
parents: 447
diff changeset
   181
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   182
    if (b_written < len && b_written != -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
   183
        old_socket_setup_output_buffer (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
   184
                                        buf + b_written,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   185
                                        len - b_written);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   186
        return 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
   187
    }
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   188
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   189
    return b_written;
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   190
}
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   191
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   192
static gboolean
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   193
socket_read_incoming (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
   194
                      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
   195
                      gsize     buf_size,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   196
                      gsize    *bytes_read,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   197
                      gboolean *hangup,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   198
                      gint     *reason)
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   199
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   200
    GIOStatus status;
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   201
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   202
    *hangup = FALSE;
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   203
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   204
    if (socket->ssl_started) {
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   205
        status = _lm_ssl_read (socket->ssl,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   206
                               buf, buf_size - 1, bytes_read);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   207
    } 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
   208
        status = g_io_channel_read_chars (socket->io_channel,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   209
                                          buf, buf_size - 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
   210
                                          bytes_read,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   211
                                          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
   212
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   213
658
352d622c2401 fix compilation warnings
Johannes Wienke <languitar@semipol.de>
parents: 624
diff changeset
   214
    if (status != G_IO_STATUS_NORMAL) {
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   215
        switch (status) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   216
        case G_IO_STATUS_EOF:
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   217
            *reason = LM_DISCONNECT_REASON_HUP;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   218
            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
   219
        case G_IO_STATUS_AGAIN:
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   220
            /* No data readable but we didn't hangup */
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   221
            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
   222
            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
   223
        case G_IO_STATUS_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
   224
            *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
   225
            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
   226
        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
   227
            *reason = LM_DISCONNECT_REASON_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
   228
        }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   229
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   230
        /* Notify connection_in_event that we hangup 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
   231
        *hangup = TRUE;
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   232
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   233
        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
   234
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
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
    buf[*bytes_read] = '\0';
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
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
    /* There is more data to be read */
cdd6a0c5b439 Went 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
    return TRUE;
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   240
}
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   241
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   242
static gboolean
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   243
socket_in_event (GIOChannel   *source,
518
cdd6a0c5b439 Went 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
                 GIOCondition  condition,
cdd6a0c5b439 Went 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
                 LmOldSocket     *socket)
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   246
{
530
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   247
    gchar    buf[IN_BUFFER_SIZE];
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   248
    gsize    bytes_read = 0;
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   249
    gboolean read_anything = FALSE;
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   250
    gboolean hangup = 0;
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   251
    gint     reason = 0;
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   252
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   253
    if (!socket->io_channel) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   254
        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
   255
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   256
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   257
    while (socket_read_incoming (socket, buf, IN_BUFFER_SIZE,
554
df52d7a1a9af Removed the check for IO condition in socket_in_event [#23]
Mikael Hallendal <micke@imendio.com>
parents: 553
diff changeset
   258
                                 &bytes_read, &hangup, &reason)) {
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   259
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   260
        g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_NET, "\nRECV [%d]:\n",
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   261
               (int)bytes_read);
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   262
        g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_NET,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   263
               "-----------------------------------\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
   264
        g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_NET, "'%s'\n", buf);
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   265
        g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_NET,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   266
               "-----------------------------------\n");
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   267
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   268
        lm_verbose ("Read: %d chars\n", (int)bytes_read);
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
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
        (socket->data_func) (socket, buf, socket->user_data);
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   271
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   272
        read_anything = 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
   273
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   274
518
cdd6a0c5b439 Went 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
    /* If we have read something, delay the hangup so that the data can be
cdd6a0c5b439 Went 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
     * processed. */
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   277
    if (hangup && !read_anything) {
cdd6a0c5b439 Went 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
        (socket->closed_func) (socket, reason, socket->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
   279
        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
   280
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
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
    return TRUE;
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   283
}
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   284
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   285
static gboolean
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   286
socket_hup_event (GIOChannel   *source,
518
cdd6a0c5b439 Went 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
                  GIOCondition  condition,
cdd6a0c5b439 Went 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
                  LmOldSocket     *socket)
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   289
{
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   290
    lm_verbose ("HUP event: %d->'%s'\n",
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   291
                condition, lm_misc_io_condition_to_str (condition));
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   292
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   293
    if (!socket->io_channel) {
cdd6a0c5b439 Went 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
        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
   295
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   296
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   297
    (socket->closed_func) (socket, LM_DISCONNECT_REASON_HUP,
518
cdd6a0c5b439 Went 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
                           socket->user_data);
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   299
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   300
    return TRUE;
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   301
}
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   302
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   303
static gboolean
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   304
socket_error_event (GIOChannel   *source,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   305
                    GIOCondition  condition,
cdd6a0c5b439 Went 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
                    LmOldSocket     *socket)
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   307
{
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   308
    lm_verbose ("ERROR event: %d->'%s'\n",
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   309
                condition, lm_misc_io_condition_to_str (condition));
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   310
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   311
    if (!socket->io_channel) {
cdd6a0c5b439 Went 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
        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
   313
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   314
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   315
    (socket->closed_func) (socket, LM_DISCONNECT_REASON_ERROR,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   316
                           socket->user_data);
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   317
518
cdd6a0c5b439 Went 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 TRUE;
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   319
}
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   320
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   321
static gboolean
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   322
_lm_old_socket_ssl_init (LmOldSocket *socket, gboolean delayed)
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   323
{
518
cdd6a0c5b439 Went 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
    GError *error = NULL;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   325
    const gchar *ssl_verify_domain = NULL;
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   326
518
cdd6a0c5b439 Went 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
    lm_verbose ("Setting up SSL...\n");
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   328
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   329
    _lm_ssl_initialize (socket->ssl);
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   330
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   331
#ifdef HAVE_GNUTLS
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   332
    /* GNU TLS requires the socket to be blocking */
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   333
    _lm_sock_set_blocking (socket->fd, TRUE);
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   334
#endif
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
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
    /* If we're using StartTLS, the correct thing is to verify against
cdd6a0c5b439 Went 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
     * the domain. If we're using old SSL, we should verify against 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
   338
     * hostname. */
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   339
    if (delayed)
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   340
        ssl_verify_domain = socket->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
   341
    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
   342
        ssl_verify_domain = socket->server;
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   343
518
cdd6a0c5b439 Went 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
    if (!_lm_ssl_begin (socket->ssl, socket->fd, ssl_verify_domain, &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
   345
        lm_verbose ("Could not begin SSL\n");
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   346
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   347
        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
   348
            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
   349
                   "%s\n", error->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
   350
            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
   351
        }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   352
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   353
        _lm_sock_shutdown (socket->fd);
cdd6a0c5b439 Went 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
        _lm_sock_close (socket->fd);
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   355
518
cdd6a0c5b439 Went 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
        if (!delayed && socket->connect_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
   357
            (socket->connect_func) (socket, FALSE, socket->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
   358
        }
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   359
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   360
        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
   361
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   362
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   363
#ifdef HAVE_GNUTLS
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   364
    _lm_sock_set_blocking (socket->fd, FALSE);
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   365
#endif
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   366
518
cdd6a0c5b439 Went 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
    socket->ssl_started = TRUE;
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   368
518
cdd6a0c5b439 Went 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 TRUE;
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   370
}
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   371
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   372
gboolean
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   373
lm_old_socket_starttls (LmOldSocket *socket)
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   374
{
518
cdd6a0c5b439 Went 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
    g_return_val_if_fail (lm_ssl_get_use_starttls (socket->ssl) == TRUE, FALSE);
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
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
    return _lm_old_socket_ssl_init (socket, TRUE);
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   378
}
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   379
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   380
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   381
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   382
void
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   383
_lm_old_socket_succeeded (LmConnectData *connect_data)
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   384
{
530
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   385
    LmOldSocket *socket;
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   386
518
cdd6a0c5b439 Went 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
    socket = connect_data->socket;
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   388
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   389
    if (socket->watch_connect) {
cdd6a0c5b439 Went 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
        g_source_destroy (socket->watch_connect);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   391
        socket->watch_connect = 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
   392
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   393
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   394
    /* Need some way to report error/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
   395
    if (socket->cancel_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
   396
        lm_verbose ("Cancelling 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
   397
        if (socket->connect_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
   398
            (socket->connect_func) (socket, FALSE, socket->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
   399
        }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   400
        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
   401
    }
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   402
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   403
    socket->fd = connect_data->fd;
cdd6a0c5b439 Went 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
    socket->io_channel = connect_data->io_channel;
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   405
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   406
    g_object_unref (socket->resolver);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   407
    socket->resolver = NULL;
476
08d36982e998 First cut of integrating the new resolver in LmOldSocket
Mikael Hallendal <micke@imendio.com>
parents: 475
diff changeset
   408
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   409
    socket->connect_data = 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
   410
    g_free (connect_data);
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   411
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   412
    /* old-style ssl should be started immediately */
cdd6a0c5b439 Went 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
    if (socket->ssl && (lm_ssl_get_use_starttls (socket->ssl) == 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
   414
        if (!_lm_old_socket_ssl_init (socket, 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
   415
            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
   416
        }
cdd6a0c5b439 Went 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
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   418
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   419
    socket->watch_in =
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   420
        lm_misc_add_io_watch (socket->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
   421
                              socket->io_channel,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   422
                              G_IO_IN,
cdd6a0c5b439 Went 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
                              (GIOFunc) socket_in_event,
cdd6a0c5b439 Went 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
                              socket);
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   425
518
cdd6a0c5b439 Went 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
    /* FIXME: if we add these, we don't get ANY
cdd6a0c5b439 Went 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
     * response from the server, this is to do with the way that
cdd6a0c5b439 Went 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
     * windows handles watches, see bug #331214.
cdd6a0c5b439 Went 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
     */
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   430
#ifndef G_OS_WIN32
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   431
    socket->watch_err =
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   432
        lm_misc_add_io_watch (socket->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
   433
                              socket->io_channel,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   434
                              G_IO_ERR,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   435
                              (GIOFunc) socket_error_event,
cdd6a0c5b439 Went 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
                              socket);
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   437
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   438
    socket->watch_hup =
cdd6a0c5b439 Went 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
        lm_misc_add_io_watch (socket->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
   440
                              socket->io_channel,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   441
                              G_IO_HUP,
cdd6a0c5b439 Went 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
                              (GIOFunc) socket_hup_event,
cdd6a0c5b439 Went 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
                              socket);
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   444
#endif
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   445
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   446
    if (socket->connect_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
   447
        (socket->connect_func) (socket, TRUE, socket->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
   448
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   449
}
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   450
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   451
gboolean
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   452
_lm_old_socket_failed_with_error (LmConnectData *connect_data, int error)
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   453
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   454
    LmOldSocket *socket;
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   455
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   456
    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 failed: %s (error %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
   458
           _lm_sock_get_error_str (error), error);
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   459
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   460
    socket = lm_old_socket_ref (connect_data->socket);
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   461
518
cdd6a0c5b439 Went 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
    connect_data->current_addr = lm_resolver_results_get_next (socket->resolver);
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   463
518
cdd6a0c5b439 Went 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
    if (socket->watch_connect) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   465
        g_source_destroy (socket->watch_connect);
cdd6a0c5b439 Went 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
        socket->watch_connect = 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
   467
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   468
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   469
    if (connect_data->io_channel != 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
   470
        socket_close_io_channel (connect_data->io_channel);
615
9a0fa0dabcdf Fix a double-free triggered by failed connection attempts
Frank Zschockelt <lm@freakysoft.de>
parents: 607
diff changeset
   471
        connect_data->io_channel = 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
   472
    }
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   473
587
7c793095138e Fixed Retry Behavior, Fixed Crash on IPv6 Addresses, Log and Exit On No Host
Jayson Vantuyl <jvantuyl@engineyard.com>
parents: 585
diff changeset
   474
    if (connect_data->current_addr == NULL) { /*Ran Out Of Addresses*/
518
cdd6a0c5b439 Went 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
        if (socket->connect_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
   476
            (socket->connect_func) (socket, FALSE, socket->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
   477
        }
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   478
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   479
        /* if the user callback called connection_close(), this is already freed */
cdd6a0c5b439 Went 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
        if (socket->connect_data != 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
   481
            if (socket->resolver) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   482
                g_object_unref (socket->resolver);
cdd6a0c5b439 Went 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
            }
476
08d36982e998 First cut of integrating the new resolver in LmOldSocket
Mikael Hallendal <micke@imendio.com>
parents: 475
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
            socket->connect_data = 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
   486
            g_free (connect_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
   487
        }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   488
    } 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
   489
        /* try to connect to the next host */
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   490
        return socket_do_connect (connect_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
   491
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   492
544
ae5934e51dc2 Minor style fix
Mikael Hallendal <micke@imendio.com>
parents: 530
diff changeset
   493
    lm_old_socket_unref (socket);
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
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
    return FALSE;
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   496
}
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   497
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   498
gboolean
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   499
_lm_old_socket_failed (LmConnectData *connect_data)
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   500
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   501
    return _lm_old_socket_failed_with_error (connect_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
   502
                                             _lm_sock_get_last_error());
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   503
}
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   504
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   505
static gboolean
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   506
socket_connect_cb (GIOChannel   *source,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   507
                   GIOCondition  condition,
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   508
                   LmConnectData *connect_data)
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   509
{
530
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   510
    LmOldSocket     *socket;
624
a94013a4555d Fix some gcc warnings
Mikael Berthe <mikael@lilotux.net>
parents: 615
diff changeset
   511
    /* struct addrinfo *addr; */
518
cdd6a0c5b439 Went 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
    int              err;
cdd6a0c5b439 Went 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
    socklen_t        len;
530
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   514
    LmOldSocketT     fd;
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   515
    gboolean         result = FALSE;
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   516
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   517
    socket = lm_old_socket_ref (connect_data->socket);
624
a94013a4555d Fix some gcc warnings
Mikael Berthe <mikael@lilotux.net>
parents: 615
diff changeset
   518
    /* addr = connect_data->current_addr; */
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   519
    fd = g_io_channel_unix_get_fd (source);
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   520
737
ca896de7b10d Handle G_IO_HUP and G_IO_NVAL when connecting
Frank Zschockelt <lm@freakysoft.de>
parents: 736
diff changeset
   521
    if (condition & (G_IO_ERR | G_IO_HUP | G_IO_NVAL)) {
518
cdd6a0c5b439 Went 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
        len = sizeof (err);
cdd6a0c5b439 Went 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
        _lm_sock_get_error (fd, &err, &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
   524
        if (!_lm_sock_is_blocking_error (err)) {
588
d4468955feb1 Logging Adjustments
Jayson Vantuyl <jvantuyl@engineyard.com>
parents: 587
diff changeset
   525
            g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_VERBOSE,
518
cdd6a0c5b439 Went 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 failed.\n");
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   527
518
cdd6a0c5b439 Went 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
            /* error condition, but might be possible to recover
cdd6a0c5b439 Went 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
             * from it (by connecting to the next host) */
cdd6a0c5b439 Went 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
            if (!_lm_old_socket_failed_with_error (connect_data, err)) {
cdd6a0c5b439 Went 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
                socket->watch_connect = 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
   532
            }
730
202bc8bac438 Fix falling back to another resolver result when connecting
Michał Kępień <github@kempniu.pl>
parents: 726
diff changeset
   533
            goto out;
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   534
        }
cdd6a0c5b439 Went 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
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   536
545
58954d98a7f9 Removed the async_connect_waiting and blocking states from LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 544
diff changeset
   537
#if 0
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   538
    if (_lm_connection_async_connect_waiting (socket->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
   539
        gint res;
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   540
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   541
        fd = g_io_channel_unix_get_fd (source);
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   542
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   543
        res = _lm_sock_connect (fd, addr->ai_addr, (int)addr->ai_addrlen);
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   544
        if (res < 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
   545
            err = _lm_sock_get_last_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
   546
            if (_lm_sock_is_blocking_success (err)) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   547
                _lm_connection_set_async_connect_waiting (socket->connection, FALSE);
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
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
                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
   550
                       "Connection success (1).\n");
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   551
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   552
                _lm_old_socket_succeeded (connect_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
   553
            }
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   554
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   555
            if (_lm_connection_async_connect_waiting (socket->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
   556
                !_lm_sock_is_blocking_error (err)) {
cdd6a0c5b439 Went 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
                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
   558
                       "Connection failed.\n");
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   559
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   560
                _lm_sock_close (connect_data->fd);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   561
                _lm_old_socket_failed_with_error (connect_data, err);
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   562
518
cdd6a0c5b439 Went 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
                socket->watch_connect = 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
   564
                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
   565
            }
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   566
        }
545
58954d98a7f9 Removed the async_connect_waiting and blocking states from LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 544
diff changeset
   567
    } else {
58954d98a7f9 Removed the async_connect_waiting and blocking states from LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 544
diff changeset
   568
#endif
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   569
    {
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   570
        /* for blocking sockets, G_IO_OUT means we are connected */
588
d4468955feb1 Logging Adjustments
Jayson Vantuyl <jvantuyl@engineyard.com>
parents: 587
diff changeset
   571
        g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_VERBOSE,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   572
               "Connection success (2).\n");
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
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
        _lm_old_socket_succeeded (connect_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
   575
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   576
518
cdd6a0c5b439 Went 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
    result = TRUE;
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   578
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   579
 out:
518
cdd6a0c5b439 Went 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_old_socket_unref(socket);
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   582
    return result;
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   583
}
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   584
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   585
static gboolean
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   586
socket_do_connect (LmConnectData *connect_data)
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   587
{
530
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   588
    LmOldSocket     *socket;
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   589
    LmOldSocketT     fd;
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   590
    int              res, err;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   591
    int              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
   592
    char             name[NI_MAXHOST];
cdd6a0c5b439 Went 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
    char             portname[NI_MAXSERV];
cdd6a0c5b439 Went 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
    struct addrinfo *addr;
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
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
    socket = connect_data->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
   597
    addr = connect_data->current_addr;
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   598
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   599
    if (socket->port == 0) {
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   600
        socket->port = 5222;
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   601
    }
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   602
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   603
    if (socket->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
   604
        port = htons (lm_proxy_get_port (socket->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
   605
    } 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
   606
        port = htons (socket->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
   607
    }
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   608
726
ea6aaf57f344 Support connecting to IPv6 servers
Michał Kępień <github@kempniu.pl>
parents: 723
diff changeset
   609
    switch (addr->ai_family) {
ea6aaf57f344 Support connecting to IPv6 servers
Michał Kępień <github@kempniu.pl>
parents: 723
diff changeset
   610
    case AF_INET:
ea6aaf57f344 Support connecting to IPv6 servers
Michał Kępień <github@kempniu.pl>
parents: 723
diff changeset
   611
        ((struct sockaddr_in *) addr->ai_addr)->sin_port = port;
ea6aaf57f344 Support connecting to IPv6 servers
Michał Kępień <github@kempniu.pl>
parents: 723
diff changeset
   612
        break;
ea6aaf57f344 Support connecting to IPv6 servers
Michał Kępień <github@kempniu.pl>
parents: 723
diff changeset
   613
    case AF_INET6:
ea6aaf57f344 Support connecting to IPv6 servers
Michał Kępień <github@kempniu.pl>
parents: 723
diff changeset
   614
        ((struct sockaddr_in6 *) addr->ai_addr)->sin6_port = port;
ea6aaf57f344 Support connecting to IPv6 servers
Michał Kępień <github@kempniu.pl>
parents: 723
diff changeset
   615
        break;
ea6aaf57f344 Support connecting to IPv6 servers
Michał Kępień <github@kempniu.pl>
parents: 723
diff changeset
   616
    default:
ea6aaf57f344 Support connecting to IPv6 servers
Michał Kępień <github@kempniu.pl>
parents: 723
diff changeset
   617
        g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_VERBOSE,
ea6aaf57f344 Support connecting to IPv6 servers
Michał Kępień <github@kempniu.pl>
parents: 723
diff changeset
   618
               "Unknown socket family %d\n", addr->ai_family);
ea6aaf57f344 Support connecting to IPv6 servers
Michał Kępień <github@kempniu.pl>
parents: 723
diff changeset
   619
#ifndef G_OS_WIN32
ea6aaf57f344 Support connecting to IPv6 servers
Michał Kępień <github@kempniu.pl>
parents: 723
diff changeset
   620
        return _lm_old_socket_failed_with_error (connect_data, EAFNOSUPPORT);
ea6aaf57f344 Support connecting to IPv6 servers
Michał Kępień <github@kempniu.pl>
parents: 723
diff changeset
   621
#else
ea6aaf57f344 Support connecting to IPv6 servers
Michał Kępień <github@kempniu.pl>
parents: 723
diff changeset
   622
        return _lm_old_socket_failed_with_error (connect_data, WSAEAFNOSUPPORT);
ea6aaf57f344 Support connecting to IPv6 servers
Michał Kępień <github@kempniu.pl>
parents: 723
diff changeset
   623
#endif
ea6aaf57f344 Support connecting to IPv6 servers
Michał Kępień <github@kempniu.pl>
parents: 723
diff changeset
   624
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   625
518
cdd6a0c5b439 Went 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
    res = getnameinfo (addr->ai_addr,
cdd6a0c5b439 Went 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
                       (socklen_t)addr->ai_addrlen,
cdd6a0c5b439 Went 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
                       name,     sizeof (name),
cdd6a0c5b439 Went 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
                       portname, sizeof (portname),
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   630
                       NI_NUMERICHOST | NI_NUMERICSERV);
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
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
    if (res < 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
   633
        return _lm_old_socket_failed (connect_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
   634
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   635
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   636
    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
   637
           "Trying %s port %s...\n", name, portname);
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   638
518
cdd6a0c5b439 Went 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
    fd = _lm_sock_makesocket (addr->ai_family,
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   640
                              addr->ai_socktype,
518
cdd6a0c5b439 Went 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
                              addr->ai_protocol);
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   642
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   643
    if (!_LM_SOCK_VALID (fd)) {
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   644
        g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_NET,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   645
               "Failed making socket, error:%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
   646
               _lm_sock_get_last_error ());
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   647
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   648
        return _lm_old_socket_failed (connect_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
   649
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
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
    /* Even though it says _unix_new(), it is supported by glib on
cdd6a0c5b439 Went 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
     * win32 because glib does some cool stuff to find out if it
cdd6a0c5b439 Went 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
     * can treat it as a FD or a windows 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
   654
     */
cdd6a0c5b439 Went 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
    connect_data->fd = fd;
cdd6a0c5b439 Went 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
    connect_data->io_channel = g_io_channel_unix_new (fd);
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   657
518
cdd6a0c5b439 Went 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
    g_io_channel_set_encoding (connect_data->io_channel, 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
   659
    g_io_channel_set_buffered (connect_data->io_channel, FALSE);
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   660
553
876d92399bbb Always set the socket to be non-blocking.
Mikael Hallendal <micke@imendio.com>
parents: 549
diff changeset
   661
    _lm_sock_set_blocking (connect_data->fd, FALSE);
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   662
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   663
    if (socket->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
   664
        socket->watch_connect =
cdd6a0c5b439 Went 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
            lm_misc_add_io_watch (socket->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
   666
                                  connect_data->io_channel,
737
ca896de7b10d Handle G_IO_HUP and G_IO_NVAL when connecting
Frank Zschockelt <lm@freakysoft.de>
parents: 736
diff changeset
   667
                                  G_IO_OUT | G_IO_ERR | G_IO_HUP | G_IO_NVAL,
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   668
                                  (GIOFunc) _lm_proxy_connect_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
   669
                                  connect_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
   670
    } 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
   671
        socket->watch_connect =
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   672
            lm_misc_add_io_watch (socket->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
   673
                                  connect_data->io_channel,
737
ca896de7b10d Handle G_IO_HUP and G_IO_NVAL when connecting
Frank Zschockelt <lm@freakysoft.de>
parents: 736
diff changeset
   674
                                  G_IO_OUT | G_IO_ERR | G_IO_HUP | G_IO_NVAL,
518
cdd6a0c5b439 Went 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
                                  (GIOFunc) 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
   676
                                  connect_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
   677
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   678
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   679
    res = _lm_sock_connect (connect_data->fd,
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   680
                            addr->ai_addr, (int)addr->ai_addrlen);
518
cdd6a0c5b439 Went 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 (res < 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
   682
        err = _lm_sock_get_last_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
   683
        if (!_lm_sock_is_blocking_error (err)) {
cdd6a0c5b439 Went 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
            _lm_sock_close (connect_data->fd);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   685
            return _lm_old_socket_failed_with_error (connect_data, err);
cdd6a0c5b439 Went 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
        }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   687
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   688
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   689
    return TRUE;
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   690
}
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   691
444
57c59cfdd77c Made the output buffer functions private to LmOldSocket.
Mikael Hallendal <micke@imendio.com>
parents: 443
diff changeset
   692
static gboolean
57c59cfdd77c Made the output buffer functions private to LmOldSocket.
Mikael Hallendal <micke@imendio.com>
parents: 443
diff changeset
   693
old_socket_output_is_buffered (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
   694
                               const gchar  *buffer,
cdd6a0c5b439 Went 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
                               gint          len)
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   696
{
518
cdd6a0c5b439 Went 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
    if (socket->out_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
   698
        lm_verbose ("Appending %d bytes to output buffer\n", 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
   699
        g_string_append_len (socket->out_buf, buffer, 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
   700
        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
   701
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   702
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   703
    return FALSE;
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   704
}
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   705
444
57c59cfdd77c Made the output buffer functions private to LmOldSocket.
Mikael Hallendal <micke@imendio.com>
parents: 443
diff changeset
   706
static void
57c59cfdd77c Made the output buffer functions private to LmOldSocket.
Mikael Hallendal <micke@imendio.com>
parents: 443
diff changeset
   707
old_socket_setup_output_buffer (LmOldSocket *socket, const gchar *buffer, gint len)
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   708
{
518
cdd6a0c5b439 Went 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
    lm_verbose ("OUTPUT BUFFER ENABLED\n");
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   710
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   711
    socket->out_buf = g_string_new_len (buffer, len);
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   712
518
cdd6a0c5b439 Went 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
    socket->watch_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
   714
        lm_misc_add_io_watch (socket->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
   715
                              socket->io_channel,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   716
                              G_IO_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
   717
                              (GIOFunc) socket_buffered_write_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
   718
                              socket);
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   719
}
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   720
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   721
static gboolean
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   722
socket_buffered_write_cb (GIOChannel   *source,
518
cdd6a0c5b439 Went 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
                          GIOCondition  condition,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   724
                          LmOldSocket     *socket)
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   725
{
518
cdd6a0c5b439 Went 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
    gint     b_written;
cdd6a0c5b439 Went 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
    GString *out_buf;
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   728
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   729
    out_buf = socket->out_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
   730
    if (!out_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
   731
        /* Should not be possible */
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   732
        return 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
   733
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   734
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   735
    b_written = old_socket_do_write (socket, out_buf->str, out_buf->len);
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   736
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   737
    if (b_written < 0) {
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   738
        (socket->closed_func) (socket, LM_DISCONNECT_REASON_ERROR,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   739
                               socket->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
   740
        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
   741
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   742
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   743
    g_string_erase (out_buf, 0, (gsize) b_written);
cdd6a0c5b439 Went 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
    if (out_buf->len == 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
   745
        lm_verbose ("Output buffer is empty, going back to normal output\n");
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
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
        if (socket->watch_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
   748
            g_source_destroy (socket->watch_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
   749
            socket->watch_out = 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
   750
        }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   751
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   752
        g_string_free (out_buf, 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
   753
        socket->out_buf = 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
   754
        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
   755
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   756
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   757
    return TRUE;
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   758
}
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   759
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   760
static void
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   761
socket_close_io_channel (GIOChannel *io_channel)
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   762
{
518
cdd6a0c5b439 Went 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
    gint fd;
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   764
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   765
    g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_NET,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   766
           "Freeing up IOChannel and file descriptor\n");
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   767
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   768
    fd = g_io_channel_unix_get_fd (io_channel);
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   769
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   770
    g_io_channel_unref (io_channel);
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   771
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   772
    _lm_sock_close (fd);
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   773
}
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   774
547
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   775
static void
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   776
old_socket_resolver_host_cb (LmResolver       *resolver,
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   777
                             LmResolverResult  result,
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   778
                             gpointer          user_data)
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   779
{
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   780
    LmOldSocket *socket = (LmOldSocket *) user_data;
588
d4468955feb1 Logging Adjustments
Jayson Vantuyl <jvantuyl@engineyard.com>
parents: 587
diff changeset
   781
    char dispbuf[128];
726
ea6aaf57f344 Support connecting to IPv6 servers
Michał Kępień <github@kempniu.pl>
parents: 723
diff changeset
   782
    struct addrinfo *addr;
ea6aaf57f344 Support connecting to IPv6 servers
Michał Kępień <github@kempniu.pl>
parents: 723
diff changeset
   783
    void *sock_addr;
547
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   784
548
60c1d6cbde10 Added some verbose debug output
Mikael Hallendal <micke@imendio.com>
parents: 547
diff changeset
   785
    lm_verbose ("LmOldSocket::host_cb (result=%d)\n", result);
60c1d6cbde10 Added some verbose debug output
Mikael Hallendal <micke@imendio.com>
parents: 547
diff changeset
   786
726
ea6aaf57f344 Support connecting to IPv6 servers
Michał Kępień <github@kempniu.pl>
parents: 723
diff changeset
   787
    if (result == LM_RESOLVER_RESULT_OK) {
ea6aaf57f344 Support connecting to IPv6 servers
Michał Kępień <github@kempniu.pl>
parents: 723
diff changeset
   788
        /* Find and use the first result with a supported address family */
ea6aaf57f344 Support connecting to IPv6 servers
Michał Kępień <github@kempniu.pl>
parents: 723
diff changeset
   789
        while ((addr = lm_resolver_results_get_next (resolver))) {
ea6aaf57f344 Support connecting to IPv6 servers
Michał Kępień <github@kempniu.pl>
parents: 723
diff changeset
   790
            switch (addr->ai_family) {
ea6aaf57f344 Support connecting to IPv6 servers
Michał Kępień <github@kempniu.pl>
parents: 723
diff changeset
   791
            case AF_INET:
ea6aaf57f344 Support connecting to IPv6 servers
Michał Kępień <github@kempniu.pl>
parents: 723
diff changeset
   792
                sock_addr = & (((struct sockaddr_in *) addr->ai_addr)->sin_addr);
ea6aaf57f344 Support connecting to IPv6 servers
Michał Kępień <github@kempniu.pl>
parents: 723
diff changeset
   793
                break;
ea6aaf57f344 Support connecting to IPv6 servers
Michał Kępień <github@kempniu.pl>
parents: 723
diff changeset
   794
            case AF_INET6:
ea6aaf57f344 Support connecting to IPv6 servers
Michał Kępień <github@kempniu.pl>
parents: 723
diff changeset
   795
                sock_addr = & (((struct sockaddr_in6 *) addr->ai_addr)->sin6_addr);
ea6aaf57f344 Support connecting to IPv6 servers
Michał Kępień <github@kempniu.pl>
parents: 723
diff changeset
   796
                break;
ea6aaf57f344 Support connecting to IPv6 servers
Michał Kępień <github@kempniu.pl>
parents: 723
diff changeset
   797
            default:
ea6aaf57f344 Support connecting to IPv6 servers
Michał Kępień <github@kempniu.pl>
parents: 723
diff changeset
   798
                g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_VERBOSE,
ea6aaf57f344 Support connecting to IPv6 servers
Michał Kępień <github@kempniu.pl>
parents: 723
diff changeset
   799
                       "Resolver returned a socket address with unknown family %d\n", addr->ai_family);
ea6aaf57f344 Support connecting to IPv6 servers
Michał Kępień <github@kempniu.pl>
parents: 723
diff changeset
   800
                continue;
ea6aaf57f344 Support connecting to IPv6 servers
Michał Kępień <github@kempniu.pl>
parents: 723
diff changeset
   801
            }
ea6aaf57f344 Support connecting to IPv6 servers
Michał Kępień <github@kempniu.pl>
parents: 723
diff changeset
   802
            if (inet_ntop (addr->ai_family, sock_addr, dispbuf, sizeof(dispbuf))) {
ea6aaf57f344 Support connecting to IPv6 servers
Michał Kępień <github@kempniu.pl>
parents: 723
diff changeset
   803
                g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_VERBOSE,
ea6aaf57f344 Support connecting to IPv6 servers
Michał Kępień <github@kempniu.pl>
parents: 723
diff changeset
   804
                       "Attempting Connection to %s\n", dispbuf);
ea6aaf57f344 Support connecting to IPv6 servers
Michał Kępień <github@kempniu.pl>
parents: 723
diff changeset
   805
            } else {
ea6aaf57f344 Support connecting to IPv6 servers
Michał Kępień <github@kempniu.pl>
parents: 723
diff changeset
   806
                g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_VERBOSE,
ea6aaf57f344 Support connecting to IPv6 servers
Michał Kępień <github@kempniu.pl>
parents: 723
diff changeset
   807
                       "Attempting Connection (unable to convert address to presentable format)\n");
ea6aaf57f344 Support connecting to IPv6 servers
Michał Kępień <github@kempniu.pl>
parents: 723
diff changeset
   808
            };
ea6aaf57f344 Support connecting to IPv6 servers
Michał Kępień <github@kempniu.pl>
parents: 723
diff changeset
   809
            socket->connect_data->current_addr = addr;
ea6aaf57f344 Support connecting to IPv6 servers
Michał Kępień <github@kempniu.pl>
parents: 723
diff changeset
   810
            socket_do_connect (socket->connect_data);
ea6aaf57f344 Support connecting to IPv6 servers
Michał Kępień <github@kempniu.pl>
parents: 723
diff changeset
   811
            return;
547
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   812
        }
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   813
    }
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   814
726
ea6aaf57f344 Support connecting to IPv6 servers
Michał Kępień <github@kempniu.pl>
parents: 723
diff changeset
   815
    lm_verbose ("error while resolving, bailing out\n");
ea6aaf57f344 Support connecting to IPv6 servers
Michał Kępień <github@kempniu.pl>
parents: 723
diff changeset
   816
    if (socket->connect_func) {
ea6aaf57f344 Support connecting to IPv6 servers
Michał Kępień <github@kempniu.pl>
parents: 723
diff changeset
   817
        (socket->connect_func) (socket, FALSE, socket->user_data);
ea6aaf57f344 Support connecting to IPv6 servers
Michał Kępień <github@kempniu.pl>
parents: 723
diff changeset
   818
    }
ea6aaf57f344 Support connecting to IPv6 servers
Michał Kępień <github@kempniu.pl>
parents: 723
diff changeset
   819
    /*FIXME: Leaking Resolvers Until Clean Up Can Be Properly Handled
ea6aaf57f344 Support connecting to IPv6 servers
Michał Kępień <github@kempniu.pl>
parents: 723
diff changeset
   820
    g_object_unref (socket->resolver);
ea6aaf57f344 Support connecting to IPv6 servers
Michał Kępień <github@kempniu.pl>
parents: 723
diff changeset
   821
    socket->resolver = NULL;*/
ea6aaf57f344 Support connecting to IPv6 servers
Michał Kępień <github@kempniu.pl>
parents: 723
diff changeset
   822
    g_free (socket->connect_data);
ea6aaf57f344 Support connecting to IPv6 servers
Michał Kępień <github@kempniu.pl>
parents: 723
diff changeset
   823
    socket->connect_data = NULL;
547
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   824
}
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   825
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   826
/* FIXME: Need to have a way to only get srv reply and then decide if the
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   827
 *        resolver should continue to look the host up.
476
08d36982e998 First cut of integrating the new resolver in LmOldSocket
Mikael Hallendal <micke@imendio.com>
parents: 475
diff changeset
   828
 *
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   829
 *        This is needed for the case when we do a SRV lookup to lookup the
476
08d36982e998 First cut of integrating the new resolver in LmOldSocket
Mikael Hallendal <micke@imendio.com>
parents: 475
diff changeset
   830
 *        real host of the service and then connect to it through a proxy.
08d36982e998 First cut of integrating the new resolver in LmOldSocket
Mikael Hallendal <micke@imendio.com>
parents: 475
diff changeset
   831
 */
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   832
static void
476
08d36982e998 First cut of integrating the new resolver in LmOldSocket
Mikael Hallendal <micke@imendio.com>
parents: 475
diff changeset
   833
old_socket_resolver_srv_cb (LmResolver       *resolver,
08d36982e998 First cut of integrating the new resolver in LmOldSocket
Mikael Hallendal <micke@imendio.com>
parents: 475
diff changeset
   834
                            LmResolverResult  result,
08d36982e998 First cut of integrating the new resolver in LmOldSocket
Mikael Hallendal <micke@imendio.com>
parents: 475
diff changeset
   835
                            gpointer          user_data)
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   836
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   837
    LmOldSocket *socket = (LmOldSocket *) 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
   838
    const gchar *remote_addr;
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   839
548
60c1d6cbde10 Added some verbose debug output
Mikael Hallendal <micke@imendio.com>
parents: 547
diff changeset
   840
    lm_verbose ("LmOldSocket::srv_cb (result=%d)\n", result);
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   841
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   842
    if (result != LM_RESOLVER_RESULT_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
   843
        lm_verbose ("SRV lookup failed, trying jid domain\n");
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   844
        socket->server = g_strdup (socket->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
   845
    } 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
   846
        g_object_get (resolver, "host", &socket->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
   847
        g_object_get (resolver, "port", &socket->port, 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
   848
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   849
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   850
    if (socket->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
   851
        remote_addr = lm_proxy_get_server (socket->proxy);
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   852
    } else if (socket->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
   853
        remote_addr = socket->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
   854
    }
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   855
    else {
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   856
        remote_addr = socket->domain;
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   857
    }
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   858
547
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   859
    g_object_unref (socket->resolver);
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   860
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   861
    socket->resolver =
547
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   862
            lm_resolver_new_for_host (remote_addr,
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   863
                                      old_socket_resolver_host_cb,
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   864
                                      socket);
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   865
547
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   866
    lm_resolver_lookup (socket->resolver);
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   867
}
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   868
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   869
LmOldSocket *
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   870
lm_old_socket_create (GMainContext      *context,
451
0c8ea9d1bec2 Some style fixes
Mikael Hallendal <micke@imendio.com>
parents: 450
diff changeset
   871
                      IncomingDataFunc   data_func,
0c8ea9d1bec2 Some style fixes
Mikael Hallendal <micke@imendio.com>
parents: 450
diff changeset
   872
                      SocketClosedFunc   closed_func,
0c8ea9d1bec2 Some style fixes
Mikael Hallendal <micke@imendio.com>
parents: 450
diff changeset
   873
                      ConnectResultFunc  connect_func,
0c8ea9d1bec2 Some style fixes
Mikael Hallendal <micke@imendio.com>
parents: 450
diff changeset
   874
                      gpointer           user_data,
0c8ea9d1bec2 Some style fixes
Mikael Hallendal <micke@imendio.com>
parents: 450
diff changeset
   875
                      LmConnection      *connection,
0c8ea9d1bec2 Some style fixes
Mikael Hallendal <micke@imendio.com>
parents: 450
diff changeset
   876
                      const gchar       *server,
0c8ea9d1bec2 Some style fixes
Mikael Hallendal <micke@imendio.com>
parents: 450
diff changeset
   877
                      const gchar       *domain,
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   878
                      guint              port,
451
0c8ea9d1bec2 Some style fixes
Mikael Hallendal <micke@imendio.com>
parents: 450
diff changeset
   879
                      LmSSL             *ssl,
0c8ea9d1bec2 Some style fixes
Mikael Hallendal <micke@imendio.com>
parents: 450
diff changeset
   880
                      LmProxy           *proxy,
0c8ea9d1bec2 Some style fixes
Mikael Hallendal <micke@imendio.com>
parents: 450
diff changeset
   881
                      GError           **error)
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
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
    LmOldSocket   *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
   884
    LmConnectData *data;
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   885
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   886
    g_return_val_if_fail (domain != 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
   887
    g_return_val_if_fail ((port >= LM_MIN_PORT && port <= LM_MAX_PORT), 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
   888
    g_return_val_if_fail (data_func != 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
   889
    g_return_val_if_fail (closed_func != 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
   890
    g_return_val_if_fail (connect_func != NULL, NULL);
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   891
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   892
    socket = g_new0 (LmOldSocket, 1);
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   893
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   894
    socket->ref_count = 1;
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   895
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   896
    socket->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
   897
    socket->domain = g_strdup (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
   898
    socket->server = g_strdup (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
   899
    socket->port = 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
   900
    socket->cancel_open = 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
    socket->ssl = 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
   902
    socket->ssl_started = 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
   903
    socket->proxy = NULL;
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   904
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   905
    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
   906
        socket->context = g_main_context_ref (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
   907
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   908
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   909
    if (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
   910
        socket->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
   911
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   912
518
cdd6a0c5b439 Went 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
    data = g_new0 (LmConnectData, 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
   914
    data->socket = 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
   915
    data->connection = socket->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
   916
    data->fd = -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
   917
    socket->connect_data = data;
502
4b69fbfa8797 Create connect_data in LmOldSocket, revert a segfault when working on LmResolver.
Mikael Hallendal <micke@imendio.com>
parents: 476
diff changeset
   918
518
cdd6a0c5b439 Went 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
    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
   920
        socket->resolver = lm_resolver_new_for_service (socket->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
   921
                                                        "xmpp-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
   922
                                                        "tcp",
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   923
                                                        old_socket_resolver_srv_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
   924
                                                        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
   925
    } else {
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   926
        socket->resolver =
518
cdd6a0c5b439 Went 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
            lm_resolver_new_for_host (socket->server ? socket->server : socket->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
   928
                                      old_socket_resolver_host_cb,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   929
                                      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
   930
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   931
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   932
    if (socket->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
   933
        g_object_set (socket->resolver, "context", context, 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
   934
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
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
    socket->data_func = data_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
   937
    socket->closed_func = closed_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
   938
    socket->connect_func = connect_func;
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   939
    socket->user_data = user_data;
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   940
518
cdd6a0c5b439 Went 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
    lm_resolver_lookup (socket->resolver);
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   942
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   943
    return socket;
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   944
}
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   945
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   946
void
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   947
lm_old_socket_flush (LmOldSocket *socket)
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   948
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   949
    g_return_if_fail (socket != 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
   950
    g_return_if_fail (socket->io_channel != NULL);
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   951
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   952
    g_io_channel_flush (socket->io_channel, NULL);
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   953
}
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   954
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   955
void
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   956
lm_old_socket_close (LmOldSocket *socket)
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
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
    LmConnectData *data;
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
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
    g_return_if_fail (socket != NULL);
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   961
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   962
    if (socket->watch_connect) {
cdd6a0c5b439 Went 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
        g_source_destroy (socket->watch_connect);
cdd6a0c5b439 Went 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
        socket->watch_connect = 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
   965
    }
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   966
518
cdd6a0c5b439 Went 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
    data = socket->connect_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
   968
    if (data) {
605
8b8e7ba6634e lm_old_socket_close() leaks a file descriptor if connect() has not
Frank Zschockelt <lm@freakysoft.de>
parents: 588
diff changeset
   969
        if (data->io_channel) {
664
f57b1b61e1fe Remove trailing whitespace and mixed indenting
Till Maas <opensource@till.name>
parents: 658
diff changeset
   970
            socket_close_io_channel (data->io_channel);
605
8b8e7ba6634e lm_old_socket_close() leaks a file descriptor if connect() has not
Frank Zschockelt <lm@freakysoft.de>
parents: 588
diff changeset
   971
        }
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   972
        socket->connect_data = 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
   973
        g_free (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
   974
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   975
585
bccdb423a8e9 Fixed Resolver Memory Management Issues (by creating less severe issues)
Jayson Vantuyl <jvantuyl@engineyard.com>
parents: 581
diff changeset
   976
    /* FIXME: Leaking Resolvers Until Clean Up Can Be Corrected
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   977
    if (socket->resolver) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   978
        g_object_unref (socket->resolver);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   979
        socket->resolver = NULL;
585
bccdb423a8e9 Fixed Resolver Memory Management Issues (by creating less severe issues)
Jayson Vantuyl <jvantuyl@engineyard.com>
parents: 581
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
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   982
    if (socket->io_channel) {
cdd6a0c5b439 Went 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
        if (socket->watch_in) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   984
            g_source_destroy (socket->watch_in);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   985
            socket->watch_in = NULL;
476
08d36982e998 First cut of integrating the new resolver in LmOldSocket
Mikael Hallendal <micke@imendio.com>
parents: 475
diff changeset
   986
        }
08d36982e998 First cut of integrating the new resolver in LmOldSocket
Mikael Hallendal <micke@imendio.com>
parents: 475
diff changeset
   987
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   988
        if (socket->watch_err) {
cdd6a0c5b439 Went 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
            g_source_destroy (socket->watch_err);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   990
            socket->watch_err = 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
   991
        }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
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 (socket->watch_hup) {
cdd6a0c5b439 Went 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
            g_source_destroy (socket->watch_hup);
cdd6a0c5b439 Went 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
            socket->watch_hup = NULL;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   996
        }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   997
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   998
        if (socket->watch_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
   999
            g_source_destroy (socket->watch_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
  1000
            socket->watch_out = 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
  1001
        }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
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
        socket_close_io_channel (socket->io_channel);
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1004
518
cdd6a0c5b439 Went 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
        socket->io_channel = 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
  1006
        socket->fd = -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
  1007
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
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 (socket->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
  1010
        _lm_ssl_close (socket->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
  1011
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1012
}
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1013
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1014
gchar *
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1015
lm_old_socket_get_local_host (LmOldSocket *socket)
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1016
{
518
cdd6a0c5b439 Went 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
    return _lm_sock_get_local_host (socket->fd);
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1018
}
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1019
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1020
LmOldSocket *
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1021
lm_old_socket_ref (LmOldSocket *socket)
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1022
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1023
    g_return_val_if_fail (socket != NULL, NULL);
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1024
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1025
    socket->ref_count++;
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1026
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1027
    return socket;
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1028
}
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1029
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1030
void
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1031
lm_old_socket_unref (LmOldSocket *socket)
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1032
{
518
cdd6a0c5b439 Went 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
    g_return_if_fail (socket != NULL);
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1034
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1035
    socket->ref_count--;
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1036
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1037
    if (socket->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
  1038
        socket_free (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
  1039
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1040
}
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1041
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1042
gboolean
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1043
lm_old_socket_set_keepalive (LmOldSocket *socket, int delay)
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1044
{
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1045
#ifdef USE_TCP_KEEPALIVES
518
cdd6a0c5b439 Went 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
    return _lm_sock_set_keepalive (socket->fd, delay);
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1047
#else
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1048
    return FALSE;
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1049
#endif /* USE_TCP_KEEPALIVES */
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1050
}
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1051
446
e97c43e6f05f Moved the ifdefs for HAVE_ASYNCNS to the LmOldSocket code.
Mikael Hallendal <micke@imendio.com>
parents: 445
diff changeset
  1052
void
e97c43e6f05f Moved the ifdefs for HAVE_ASYNCNS to the LmOldSocket code.
Mikael Hallendal <micke@imendio.com>
parents: 445
diff changeset
  1053
lm_old_socket_asyncns_cancel (LmOldSocket *socket)
e97c43e6f05f Moved the ifdefs for HAVE_ASYNCNS to the LmOldSocket code.
Mikael Hallendal <micke@imendio.com>
parents: 445
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
    if (!socket->resolver) {
cdd6a0c5b439 Went 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
        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
  1057
    }
446
e97c43e6f05f Moved the ifdefs for HAVE_ASYNCNS to the LmOldSocket code.
Mikael Hallendal <micke@imendio.com>
parents: 445
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
    lm_resolver_cancel (socket->resolver);
446
e97c43e6f05f Moved the ifdefs for HAVE_ASYNCNS to the LmOldSocket code.
Mikael Hallendal <micke@imendio.com>
parents: 445
diff changeset
  1060
}
e97c43e6f05f Moved the ifdefs for HAVE_ASYNCNS to the LmOldSocket code.
Mikael Hallendal <micke@imendio.com>
parents: 445
diff changeset
  1061
450
548b5e3d9bea Refactored some of the SSL code in LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 449
diff changeset
  1062
gboolean
548b5e3d9bea Refactored some of the SSL code in LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 449
diff changeset
  1063
lm_old_socket_get_use_starttls (LmOldSocket *socket)
548b5e3d9bea Refactored some of the SSL code in LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 449
diff changeset
  1064
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1065
    if (!socket->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
  1066
        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
  1067
    }
446
e97c43e6f05f Moved the ifdefs for HAVE_ASYNCNS to the LmOldSocket code.
Mikael Hallendal <micke@imendio.com>
parents: 445
diff changeset
  1068
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1069
    return lm_ssl_get_use_starttls (socket->ssl);
450
548b5e3d9bea Refactored some of the SSL code in LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 449
diff changeset
  1070
}
548b5e3d9bea Refactored some of the SSL code in LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 449
diff changeset
  1071
548b5e3d9bea Refactored some of the SSL code in LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 449
diff changeset
  1072
gboolean
548b5e3d9bea Refactored some of the SSL code in LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 449
diff changeset
  1073
lm_old_socket_get_require_starttls (LmOldSocket *socket)
548b5e3d9bea Refactored some of the SSL code in LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 449
diff changeset
  1074
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1075
    if (!socket->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
  1076
        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
  1077
    }
450
548b5e3d9bea Refactored some of the SSL code in LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 449
diff changeset
  1078
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1079
    return lm_ssl_get_require_starttls (socket->ssl);
450
548b5e3d9bea Refactored some of the SSL code in LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 449
diff changeset
  1080
}