loudmouth/lm-old-socket.c
author Michał Kępień <github@kempniu.pl>
Tue, 25 Sep 2018 21:52:25 +0200
changeset 723 c4953bf0a53d
parent 690 7ccf2113ec5f
child 726 ea6aaf57f344
permissions -rw-r--r--
GIOCondition is a bit field Use bitwise AND instead of equality checks when processing a GIOCondition value passed to a GIOChannel callback since it may be a bitwise combination of multiple enum values (e.g. G_IO_OUT | G_IO_ERR).
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
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    23
#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
    24
#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
    25
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    26
/* 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
    27
#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
    28
#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
    29
#endif
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    30
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    31
/* 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
    32
#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
    33
#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
    34
#endif
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    35
588
d4468955feb1 Logging Adjustments
Jayson Vantuyl <jvantuyl@engineyard.com>
parents: 587
diff changeset
    36
#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
    37
#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
    38
#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
    39
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    40
#include "lm-debug.h"
475
001da49d7fd1 Added cancel operation for asyncns resolver
Mikael Hallendal <micke@imendio.com>
parents: 470
diff changeset
    41
#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
    42
#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
    43
#include "lm-misc.h"
475
001da49d7fd1 Added cancel operation for asyncns resolver
Mikael Hallendal <micke@imendio.com>
parents: 470
diff changeset
    44
#include "lm-proxy.h"
001da49d7fd1 Added cancel operation for asyncns resolver
Mikael Hallendal <micke@imendio.com>
parents: 470
diff changeset
    45
#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
    46
#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
    47
#include "lm-ssl-internals.h"
475
001da49d7fd1 Added cancel operation for asyncns resolver
Mikael Hallendal <micke@imendio.com>
parents: 470
diff changeset
    48
#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
    49
#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
    50
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    51
#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
    52
#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
    53
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    54
struct _LmOldSocket {
530
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
    55
    LmConnection      *connection;
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
    56
    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
    57
530
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
    58
    gchar             *domain;
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
    59
    gchar             *server;
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
    60
    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
    61
530
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
    62
    LmSSL             *ssl;
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
    63
    gboolean           ssl_started;
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
    64
    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
    65
530
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
    66
    GIOChannel        *io_channel;
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
    67
    GSource           *watch_in;
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
    68
    GSource           *watch_err;
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
    69
    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
    70
530
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
    71
    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
    72
530
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
    73
    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
    74
530
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
    75
    gboolean           cancel_open;
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
    76
530
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
    77
    GSource           *watch_out;
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
    78
    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
    79
530
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
    80
    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
    81
530
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
    82
    IncomingDataFunc   data_func;
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
    83
    SocketClosedFunc   closed_func;
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
    84
    ConnectResultFunc  connect_func;
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
    85
    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
    86
530
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
    87
    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
    88
530
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
    89
    LmResolver        *resolver;
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
    90
};
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    91
530
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
    92
static void         socket_free                    (LmOldSocket    *socket);
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
    93
static gboolean     socket_do_connect              (LmConnectData  *connect_data);
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
    94
static gboolean     socket_connect_cb              (GIOChannel     *source,
530
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
    95
                                                    GIOCondition    condition,
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
    96
                                                    LmConnectData  *connect_data);
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
    97
static gboolean     socket_in_event                (GIOChannel     *source,
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
    98
                                                    GIOCondition    condition,
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
    99
                                                    LmOldSocket    *socket);
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   100
static gboolean     socket_hup_event               (GIOChannel     *source,
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   101
                                                    GIOCondition    condition,
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   102
                                                    LmOldSocket    *socket);
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   103
static gboolean     socket_error_event             (GIOChannel     *source,
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   104
                                                    GIOCondition    condition,
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   105
                                                    LmOldSocket    *socket);
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   106
static gboolean     socket_buffered_write_cb       (GIOChannel     *source,
530
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   107
                                                    GIOCondition    condition,
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   108
                                                    LmOldSocket    *socket);
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   109
static void         socket_close_io_channel        (GIOChannel     *io_channel);
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   110
static gboolean     old_socket_output_is_buffered  (LmOldSocket    *socket,
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   111
                                                    const gchar    *buffer,
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   112
                                                    gint            len);
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   113
static void         old_socket_setup_output_buffer (LmOldSocket    *socket,
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   114
                                                    const gchar    *buffer,
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   115
                                                    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
   116
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   117
static void
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   118
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
   119
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   120
    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
   121
    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
   122
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   123
    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
   124
        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
   125
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   126
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   127
    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
   128
        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
   129
    }
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   130
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   131
    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
   132
        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
   133
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   134
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   135
    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
   136
        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
   137
    }
476
08d36982e998 First cut of integrating the new resolver in LmOldSocket
Mikael Hallendal <micke@imendio.com>
parents: 475
diff changeset
   138
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   139
    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
   140
}
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   141
448
4aec5fbe96f1 Split out old_socket_do_write from lm_old_socket_do_write.
Mikael Hallendal <micke@imendio.com>
parents: 447
diff changeset
   142
static gint
4aec5fbe96f1 Split out old_socket_do_write from lm_old_socket_do_write.
Mikael Hallendal <micke@imendio.com>
parents: 447
diff changeset
   143
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
   144
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   145
    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
   146
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   147
    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
   148
        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
   149
    } 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
   150
        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
   151
        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
   152
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   153
        while (io_status == G_IO_STATUS_AGAIN) {
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   154
            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
   155
                                                  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
   156
                                                  &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
   157
                                                  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
   158
        }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   159
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   160
        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
   161
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   162
        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
   163
            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
   164
        }
cdd6a0c5b439 Went 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
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   166
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   167
    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
   168
}
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
gint
4aec5fbe96f1 Split out old_socket_do_write from lm_old_socket_do_write.
Mikael Hallendal <micke@imendio.com>
parents: 447
diff changeset
   171
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
   172
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   173
    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
   174
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   175
    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
   176
        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
   177
    }
448
4aec5fbe96f1 Split out old_socket_do_write from lm_old_socket_do_write.
Mikael Hallendal <micke@imendio.com>
parents: 447
diff changeset
   178
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   179
    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
   180
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   181
    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
   182
        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
   183
                                        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
   184
                                        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
   185
        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
   186
    }
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   187
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   188
    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
   189
}
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
static gboolean
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   192
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
   193
                      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
   194
                      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
   195
                      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
   196
                      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
   197
                      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
   198
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   199
    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
   200
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   201
    *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
   202
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   203
    if (socket->ssl_started) {
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   204
        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
   205
                               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
   206
    } 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
   207
        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
   208
                                          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
   209
                                          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
   210
                                          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
   211
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   212
658
352d622c2401 fix compilation warnings
Johannes Wienke <languitar@semipol.de>
parents: 624
diff changeset
   213
    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
   214
        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
   215
        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
   216
            *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
   217
            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
   218
        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
   219
            /* 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
   220
            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
   221
            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
   222
        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
   223
            *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
   224
            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
   225
        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
   226
            *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
   227
        }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   228
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   229
        /* 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
   230
        *hangup = TRUE;
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   231
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   232
        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
   233
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   234
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   235
    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
   236
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   237
    /* 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
   238
    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
   239
}
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
static gboolean
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   242
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
   243
                 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
   244
                 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
   245
{
530
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   246
    gchar    buf[IN_BUFFER_SIZE];
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   247
    gsize    bytes_read = 0;
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   248
    gboolean read_anything = FALSE;
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   249
    gboolean hangup = 0;
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   250
    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
   251
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   252
    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
   253
        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
   254
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   255
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   256
    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
   257
                                 &bytes_read, &hangup, &reason)) {
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   258
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   259
        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
   260
               (int)bytes_read);
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   261
        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
   262
               "-----------------------------------\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
   263
        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
   264
        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
   265
               "-----------------------------------\n");
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   266
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   267
        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
   268
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   269
        (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
   270
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   271
        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
   272
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   273
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   274
    /* If 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
   275
     * 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
   276
    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
   277
        (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
   278
        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
   279
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   280
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   281
    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
   282
}
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   283
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   284
static gboolean
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   285
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
   286
                  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
   287
                  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
   288
{
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   289
    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
   290
                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
   291
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   292
    if (!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
   293
        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
   294
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   295
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   296
    (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
   297
                           socket->user_data);
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   298
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   299
    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
   300
}
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
static gboolean
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   303
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
   304
                    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
   305
                    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
   306
{
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   307
    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
   308
                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
   309
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   310
    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
   311
        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
   312
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   313
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   314
    (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
   315
                           socket->user_data);
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   316
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   317
    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
   318
}
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
static gboolean
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   321
_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
   322
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   323
    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
   324
    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
   325
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   326
    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
   327
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   328
    _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
   329
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   330
#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
   331
    /* 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
   332
    _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
   333
#endif
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   334
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   335
    /* 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
   336
     * 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
   337
     * 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
   338
    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
   339
        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
   340
    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
   341
        ssl_verify_domain = socket->server;
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   342
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   343
    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
   344
        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
   345
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   346
        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
   347
            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
   348
                   "%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
   349
            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
   350
        }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   351
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   352
        _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
   353
        _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
   354
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   355
        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
   356
            (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
   357
        }
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   358
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   359
        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
   360
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   361
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   362
#ifdef HAVE_GNUTLS
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   363
    _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
   364
#endif
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   365
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   366
    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
   367
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   368
    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
   369
}
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
gboolean
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   372
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
   373
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   374
    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
   375
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   376
    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
   377
}
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
void
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   382
_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
   383
{
530
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   384
    LmOldSocket *socket;
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   385
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   386
    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
   387
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   388
    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
   389
        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
   390
        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
   391
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   392
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   393
    /* 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
   394
    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
   395
        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
   396
        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
   397
            (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
   398
        }
cdd6a0c5b439 Went 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
        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
   400
    }
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   401
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   402
    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
   403
    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
   404
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   405
    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
   406
    socket->resolver = NULL;
476
08d36982e998 First cut of integrating the new resolver in LmOldSocket
Mikael Hallendal <micke@imendio.com>
parents: 475
diff changeset
   407
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   408
    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
   409
    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
   410
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   411
    /* 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
   412
    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
   413
        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
   414
            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
   415
        }
cdd6a0c5b439 Went 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
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   417
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   418
    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
   419
        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
   420
                              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
   421
                              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
   422
                              (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
   423
                              socket);
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   424
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   425
    /* 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
   426
     * 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
   427
     * 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
   428
     */
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   429
#ifndef G_OS_WIN32
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   430
    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
   431
        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
   432
                              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
   433
                              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
   434
                              (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
   435
                              socket);
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   436
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   437
    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
   438
        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
   439
                              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
   440
                              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
   441
                              (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
   442
                              socket);
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   443
#endif
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   444
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   445
    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
   446
        (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
   447
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   448
}
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   449
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   450
gboolean
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   451
_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
   452
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   453
    LmOldSocket *socket;
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   454
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   455
    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
   456
           "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
   457
           _lm_sock_get_error_str (error), error);
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   458
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   459
    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
   460
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   461
    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
   462
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   463
    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
   464
        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
   465
        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
   466
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   467
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   468
    if (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
   469
        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
   470
        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
   471
    }
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   472
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
   473
    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
   474
        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
   475
            (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
   476
        }
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   477
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   478
        /* if 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
   479
        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
   480
            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
   481
                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
   482
            }
476
08d36982e998 First cut of integrating the new resolver in LmOldSocket
Mikael Hallendal <micke@imendio.com>
parents: 475
diff changeset
   483
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   484
            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
   485
            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
   486
        }
cdd6a0c5b439 Went 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
    } 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
   488
        /* 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
   489
        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
   490
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   491
544
ae5934e51dc2 Minor style fix
Mikael Hallendal <micke@imendio.com>
parents: 530
diff changeset
   492
    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
   493
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   494
    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
   495
}
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   496
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   497
gboolean
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   498
_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
   499
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   500
    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
   501
                                             _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
   502
}
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   503
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   504
static gboolean
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   505
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
   506
                   GIOCondition  condition,
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   507
                   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
   508
{
530
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   509
    LmOldSocket     *socket;
624
a94013a4555d Fix some gcc warnings
Mikael Berthe <mikael@lilotux.net>
parents: 615
diff changeset
   510
    /* 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
   511
    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
   512
    socklen_t        len;
530
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   513
    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
   514
    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
   515
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   516
    socket = lm_old_socket_ref (connect_data->socket);
624
a94013a4555d Fix some gcc warnings
Mikael Berthe <mikael@lilotux.net>
parents: 615
diff changeset
   517
    /* 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
   518
    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
   519
723
c4953bf0a53d GIOCondition is a bit field
Michał Kępień <github@kempniu.pl>
parents: 690
diff changeset
   520
    if (condition & G_IO_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
   521
        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
   522
        _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
   523
        if (!_lm_sock_is_blocking_error (err)) {
588
d4468955feb1 Logging Adjustments
Jayson Vantuyl <jvantuyl@engineyard.com>
parents: 587
diff changeset
   524
            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
   525
                   "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
   526
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   527
            /* 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
   528
             * 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
   529
            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
   530
                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
   531
                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
   532
            }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   533
        }
cdd6a0c5b439 Went 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
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   535
545
58954d98a7f9 Removed the async_connect_waiting and blocking states from LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 544
diff changeset
   536
#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
   537
    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
   538
        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
   539
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   540
        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
   541
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   542
        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
   543
        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
   544
            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
   545
            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
   546
                _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
   547
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   548
                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
   549
                       "Connection success (1).\n");
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   550
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   551
                _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
   552
            }
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   553
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   554
            if (_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
   555
                !_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
   556
                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
   557
                       "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
   558
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   559
                _lm_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
   560
                _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
   561
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   562
                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
   563
                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
   564
            }
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   565
        }
545
58954d98a7f9 Removed the async_connect_waiting and blocking states from LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 544
diff changeset
   566
    } else {
58954d98a7f9 Removed the async_connect_waiting and blocking states from LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 544
diff changeset
   567
#endif
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   568
    {
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   569
        /* for blocking sockets, G_IO_OUT means we are connected */
588
d4468955feb1 Logging Adjustments
Jayson Vantuyl <jvantuyl@engineyard.com>
parents: 587
diff changeset
   570
        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
   571
               "Connection success (2).\n");
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   572
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   573
        _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
   574
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   575
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   576
    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
   577
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   578
 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
   579
    lm_old_socket_unref(socket);
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   580
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   581
    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
   582
}
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
static gboolean
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   585
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
   586
{
530
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   587
    LmOldSocket     *socket;
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   588
    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
   589
    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
   590
    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
   591
    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
   592
    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
   593
    struct addrinfo *addr;
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   594
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   595
    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
   596
    addr = connect_data->current_addr;
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   597
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   598
    if (socket->port == 0) {
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   599
        socket->port = 5222;
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   600
    }
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   601
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   602
    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
   603
        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
   604
    } 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
   605
        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
   606
    }
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   607
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   608
    ((struct sockaddr_in *) addr->ai_addr)->sin_port = port;
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   609
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   610
    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
   611
                       (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
   612
                       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
   613
                       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
   614
                       NI_NUMERICHOST | NI_NUMERICSERV);
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   615
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   616
    if (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
   617
        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
   618
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   619
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   620
    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
   621
           "Trying %s port %s...\n", name, portname);
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   622
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   623
    fd = _lm_sock_makesocket (addr->ai_family,
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   624
                              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
   625
                              addr->ai_protocol);
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   626
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   627
    if (!_LM_SOCK_VALID (fd)) {
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   628
        g_print("invalid fd\n");
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   629
        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
   630
               "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
   631
               _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
   632
518
cdd6a0c5b439 Went 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
    /* 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
   637
     * 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
   638
     * 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
   639
     */
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   640
    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
   641
    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
   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
    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
   644
    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
   645
553
876d92399bbb Always set the socket to be non-blocking.
Mikael Hallendal <micke@imendio.com>
parents: 549
diff changeset
   646
    _lm_sock_set_blocking (connect_data->fd, FALSE);
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
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
    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
   649
        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
   650
            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
   651
                                  connect_data->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
   652
                                  G_IO_OUT|G_IO_ERR,
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   653
                                  (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
   654
                                  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
   655
    } 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
   656
        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
   657
            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
   658
                                  connect_data->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
   659
                                  G_IO_OUT|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
   660
                                  (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
   661
                                  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
   662
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   663
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   664
    res = _lm_sock_connect (connect_data->fd,
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   665
                            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
   666
    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
   667
        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
   668
        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
   669
            _lm_sock_close (connect_data->fd);
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   670
            g_print("unable to connect\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
   671
            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
   672
        }
cdd6a0c5b439 Went 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
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   674
518
cdd6a0c5b439 Went 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
    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
   676
}
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   677
444
57c59cfdd77c Made the output buffer functions private to LmOldSocket.
Mikael Hallendal <micke@imendio.com>
parents: 443
diff changeset
   678
static gboolean
57c59cfdd77c Made the output buffer functions private to LmOldSocket.
Mikael Hallendal <micke@imendio.com>
parents: 443
diff changeset
   679
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
   680
                               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
   681
                               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
   682
{
518
cdd6a0c5b439 Went 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 (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
   684
        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
   685
        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
   686
        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
   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 FALSE;
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 void
57c59cfdd77c Made the output buffer functions private to LmOldSocket.
Mikael Hallendal <micke@imendio.com>
parents: 443
diff changeset
   693
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
   694
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   695
    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
   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
    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
   698
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   699
    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
   700
        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
   701
                              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
   702
                              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
   703
                              (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
   704
                              socket);
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   705
}
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   706
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   707
static gboolean
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   708
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
   709
                          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
   710
                          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
   711
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   712
    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
   713
    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
   714
518
cdd6a0c5b439 Went 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
    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
   716
    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
   717
        /* 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
   718
        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
   719
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   720
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   721
    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
   722
518
cdd6a0c5b439 Went 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
    if (b_written < 0) {
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   724
        (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
   725
                               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
   726
        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
   727
    }
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
    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
   730
    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
   731
        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
   732
518
cdd6a0c5b439 Went 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
        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
   734
            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
   735
            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
   736
        }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   737
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   738
        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
   739
        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
   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
    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
   744
}
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   745
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   746
static void
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   747
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
   748
{
518
cdd6a0c5b439 Went 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
    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
   750
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   751
    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
   752
           "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
   753
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   754
    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
   755
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   756
    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
   757
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   758
    _lm_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
   759
}
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   760
547
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   761
static void
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   762
old_socket_resolver_host_cb (LmResolver       *resolver,
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   763
                             LmResolverResult  result,
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   764
                             gpointer          user_data)
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   765
{
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   766
    LmOldSocket *socket = (LmOldSocket *) user_data;
588
d4468955feb1 Logging Adjustments
Jayson Vantuyl <jvantuyl@engineyard.com>
parents: 587
diff changeset
   767
    char dispbuf[128];
d4468955feb1 Logging Adjustments
Jayson Vantuyl <jvantuyl@engineyard.com>
parents: 587
diff changeset
   768
    struct sockaddr_in *addr; /* FIXME:IPv6 */
d4468955feb1 Logging Adjustments
Jayson Vantuyl <jvantuyl@engineyard.com>
parents: 587
diff changeset
   769
    const char *converr;
547
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   770
548
60c1d6cbde10 Added some verbose debug output
Mikael Hallendal <micke@imendio.com>
parents: 547
diff changeset
   771
    lm_verbose ("LmOldSocket::host_cb (result=%d)\n", result);
60c1d6cbde10 Added some verbose debug output
Mikael Hallendal <micke@imendio.com>
parents: 547
diff changeset
   772
547
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   773
    if (result != LM_RESOLVER_RESULT_OK) {
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   774
        lm_verbose ("error while resolving, bailing out\n");
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   775
        if (socket->connect_func) {
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   776
            (socket->connect_func) (socket, FALSE, socket->user_data);
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   777
        }
585
bccdb423a8e9 Fixed Resolver Memory Management Issues (by creating less severe issues)
Jayson Vantuyl <jvantuyl@engineyard.com>
parents: 581
diff changeset
   778
        /*FIXME: Leaking Resolvers Until Clean Up Can Be Properly Handled
547
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   779
        g_object_unref (socket->resolver);
585
bccdb423a8e9 Fixed Resolver Memory Management Issues (by creating less severe issues)
Jayson Vantuyl <jvantuyl@engineyard.com>
parents: 581
diff changeset
   780
        socket->resolver = NULL;*/
547
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   781
        g_free (socket->connect_data);
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   782
        socket->connect_data = NULL;
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   783
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   784
        return;
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   785
    }
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   786
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   787
    socket->connect_data->current_addr =
547
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   788
        lm_resolver_results_get_next (resolver);
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   789
588
d4468955feb1 Logging Adjustments
Jayson Vantuyl <jvantuyl@engineyard.com>
parents: 587
diff changeset
   790
    if (socket->connect_data->current_addr) { /* FIXME:IPv6 */
d4468955feb1 Logging Adjustments
Jayson Vantuyl <jvantuyl@engineyard.com>
parents: 587
diff changeset
   791
        addr = (struct sockaddr_in *) (socket->connect_data->current_addr->ai_addr);
d4468955feb1 Logging Adjustments
Jayson Vantuyl <jvantuyl@engineyard.com>
parents: 587
diff changeset
   792
        converr = inet_ntop(AF_INET,&(addr->sin_addr),dispbuf,sizeof(dispbuf));
d4468955feb1 Logging Adjustments
Jayson Vantuyl <jvantuyl@engineyard.com>
parents: 587
diff changeset
   793
        if (converr) {
d4468955feb1 Logging Adjustments
Jayson Vantuyl <jvantuyl@engineyard.com>
parents: 587
diff changeset
   794
            g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_VERBOSE,
d4468955feb1 Logging Adjustments
Jayson Vantuyl <jvantuyl@engineyard.com>
parents: 587
diff changeset
   795
                   "Attempting Connection to %s\n",dispbuf);
d4468955feb1 Logging Adjustments
Jayson Vantuyl <jvantuyl@engineyard.com>
parents: 587
diff changeset
   796
        } else {
d4468955feb1 Logging Adjustments
Jayson Vantuyl <jvantuyl@engineyard.com>
parents: 587
diff changeset
   797
            g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_VERBOSE,
d4468955feb1 Logging Adjustments
Jayson Vantuyl <jvantuyl@engineyard.com>
parents: 587
diff changeset
   798
                   "Attempting Connection (unable to convert address to presentable format)\n");
d4468955feb1 Logging Adjustments
Jayson Vantuyl <jvantuyl@engineyard.com>
parents: 587
diff changeset
   799
        };
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
   800
        socket_do_connect (socket->connect_data);
7c793095138e Fixed Retry Behavior, Fixed Crash on IPv6 Addresses, Log and Exit On No Host
Jayson Vantuyl <jvantuyl@engineyard.com>
parents: 585
diff changeset
   801
    } else { /* FIXME: IPv6 Support? */
7c793095138e Fixed Retry Behavior, Fixed Crash on IPv6 Addresses, Log and Exit On No Host
Jayson Vantuyl <jvantuyl@engineyard.com>
parents: 585
diff changeset
   802
        g_log (LM_LOG_DOMAIN,G_LOG_LEVEL_ERROR,
7c793095138e Fixed Retry Behavior, Fixed Crash on IPv6 Addresses, Log and Exit On No Host
Jayson Vantuyl <jvantuyl@engineyard.com>
parents: 585
diff changeset
   803
               "Unable to locate server available over IPv4.\n");
7c793095138e Fixed Retry Behavior, Fixed Crash on IPv6 Addresses, Log and Exit On No Host
Jayson Vantuyl <jvantuyl@engineyard.com>
parents: 585
diff changeset
   804
    };
7c793095138e Fixed Retry Behavior, Fixed Crash on IPv6 Addresses, Log and Exit On No Host
Jayson Vantuyl <jvantuyl@engineyard.com>
parents: 585
diff changeset
   805
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 605
diff changeset
   806
    /* FIXME: What do we do here?  How to make the mainloop exit with an
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
   807
       error, while having no ref to said mainloop */
547
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   808
}
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   809
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   810
/* 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
   811
 *        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
   812
 *
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   813
 *        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
   814
 *        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
   815
 */
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   816
static void
476
08d36982e998 First cut of integrating the new resolver in LmOldSocket
Mikael Hallendal <micke@imendio.com>
parents: 475
diff changeset
   817
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
   818
                            LmResolverResult  result,
08d36982e998 First cut of integrating the new resolver in LmOldSocket
Mikael Hallendal <micke@imendio.com>
parents: 475
diff changeset
   819
                            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
   820
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   821
    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
   822
    const gchar *remote_addr;
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   823
548
60c1d6cbde10 Added some verbose debug output
Mikael Hallendal <micke@imendio.com>
parents: 547
diff changeset
   824
    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
   825
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   826
    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
   827
        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
   828
        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
   829
    } 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
   830
        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
   831
        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
   832
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   833
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   834
    if (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
   835
        remote_addr = lm_proxy_get_server (socket->proxy);
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   836
    } 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
   837
        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
   838
    }
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   839
    else {
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   840
        remote_addr = socket->domain;
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   841
    }
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   842
547
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   843
    g_object_unref (socket->resolver);
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   844
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   845
    socket->resolver =
547
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   846
            lm_resolver_new_for_host (remote_addr,
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   847
                                      old_socket_resolver_host_cb,
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   848
                                      socket);
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   849
547
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   850
    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
   851
}
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   852
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   853
LmOldSocket *
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   854
lm_old_socket_create (GMainContext      *context,
451
0c8ea9d1bec2 Some style fixes
Mikael Hallendal <micke@imendio.com>
parents: 450
diff changeset
   855
                      IncomingDataFunc   data_func,
0c8ea9d1bec2 Some style fixes
Mikael Hallendal <micke@imendio.com>
parents: 450
diff changeset
   856
                      SocketClosedFunc   closed_func,
0c8ea9d1bec2 Some style fixes
Mikael Hallendal <micke@imendio.com>
parents: 450
diff changeset
   857
                      ConnectResultFunc  connect_func,
0c8ea9d1bec2 Some style fixes
Mikael Hallendal <micke@imendio.com>
parents: 450
diff changeset
   858
                      gpointer           user_data,
0c8ea9d1bec2 Some style fixes
Mikael Hallendal <micke@imendio.com>
parents: 450
diff changeset
   859
                      LmConnection      *connection,
0c8ea9d1bec2 Some style fixes
Mikael Hallendal <micke@imendio.com>
parents: 450
diff changeset
   860
                      const gchar       *server,
0c8ea9d1bec2 Some style fixes
Mikael Hallendal <micke@imendio.com>
parents: 450
diff changeset
   861
                      const gchar       *domain,
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   862
                      guint              port,
451
0c8ea9d1bec2 Some style fixes
Mikael Hallendal <micke@imendio.com>
parents: 450
diff changeset
   863
                      LmSSL             *ssl,
0c8ea9d1bec2 Some style fixes
Mikael Hallendal <micke@imendio.com>
parents: 450
diff changeset
   864
                      LmProxy           *proxy,
0c8ea9d1bec2 Some style fixes
Mikael Hallendal <micke@imendio.com>
parents: 450
diff changeset
   865
                      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
   866
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   867
    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
   868
    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
   869
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   870
    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
   871
    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
   872
    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
   873
    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
   874
    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
   875
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   876
    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
   877
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   878
    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
   879
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   880
    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
   881
    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
   882
    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
   883
    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
   884
    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
   885
    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
   886
    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
   887
    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
   888
518
cdd6a0c5b439 Went 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
    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
   890
        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
   891
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   892
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   893
    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
   894
        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
   895
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   896
518
cdd6a0c5b439 Went 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
    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
   898
    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
   899
    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
   900
    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
   901
    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
   902
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   903
    if (!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
   904
        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
   905
                                                        "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
   906
                                                        "tcp",
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   907
                                                        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
   908
                                                        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
   909
    } else {
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   910
        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
   911
            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
   912
                                      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
   913
                                      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
   914
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   915
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   916
    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
   917
        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
   918
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   919
518
cdd6a0c5b439 Went 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->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
   921
    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
   922
    socket->connect_func = connect_func;
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   923
    socket->user_data = user_data;
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   924
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   925
    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
   926
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   927
    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
   928
}
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   929
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   930
void
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   931
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
   932
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   933
    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
   934
    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
   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
    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
   937
}
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   938
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   939
void
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   940
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
   941
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   942
    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
   943
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   944
    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
   945
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   946
    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
   947
        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
   948
        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
   949
    }
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   950
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   951
    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
   952
    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
   953
        if (data->io_channel) {
664
f57b1b61e1fe Remove trailing whitespace and mixed indenting
Till Maas <opensource@till.name>
parents: 658
diff changeset
   954
            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
   955
        }
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   956
        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
   957
        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
   958
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   959
585
bccdb423a8e9 Fixed Resolver Memory Management Issues (by creating less severe issues)
Jayson Vantuyl <jvantuyl@engineyard.com>
parents: 581
diff changeset
   960
    /* 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
   961
    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
   962
        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
   963
        socket->resolver = NULL;
585
bccdb423a8e9 Fixed Resolver Memory Management Issues (by creating less severe issues)
Jayson Vantuyl <jvantuyl@engineyard.com>
parents: 581
diff changeset
   964
    } */
518
cdd6a0c5b439 Went 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
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   966
    if (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
   967
        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
   968
            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
   969
            socket->watch_in = NULL;
476
08d36982e998 First cut of integrating the new resolver in LmOldSocket
Mikael Hallendal <micke@imendio.com>
parents: 475
diff changeset
   970
        }
08d36982e998 First cut of integrating the new resolver in LmOldSocket
Mikael Hallendal <micke@imendio.com>
parents: 475
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
        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
   973
            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
   974
            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
   975
        }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   976
518
cdd6a0c5b439 Went 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->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
   978
            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
   979
            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
   980
        }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   981
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   982
        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
   983
            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
   984
            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
   985
        }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   986
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   987
        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
   988
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   989
        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
   990
        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
   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->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
   994
        _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
   995
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   996
}
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   997
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   998
gchar *
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   999
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
  1000
{
518
cdd6a0c5b439 Went 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
    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
  1002
}
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1003
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1004
LmOldSocket *
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1005
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
  1006
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1007
    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
  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
    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
  1010
518
cdd6a0c5b439 Went 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
    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
  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
void
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_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
  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
    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
  1018
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1019
    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
  1020
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1021
    if (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
  1022
        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
  1023
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1024
}
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1025
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1026
gboolean
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1027
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
  1028
{
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1029
#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
  1030
    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
  1031
#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
  1032
    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
  1033
#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
  1034
}
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1035
446
e97c43e6f05f Moved the ifdefs for HAVE_ASYNCNS to the LmOldSocket code.
Mikael Hallendal <micke@imendio.com>
parents: 445
diff changeset
  1036
void
e97c43e6f05f Moved the ifdefs for HAVE_ASYNCNS to the LmOldSocket code.
Mikael Hallendal <micke@imendio.com>
parents: 445
diff changeset
  1037
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
  1038
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1039
    if (!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
  1040
        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
  1041
    }
446
e97c43e6f05f Moved the ifdefs for HAVE_ASYNCNS to the LmOldSocket code.
Mikael Hallendal <micke@imendio.com>
parents: 445
diff changeset
  1042
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1043
    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
  1044
}
e97c43e6f05f Moved the ifdefs for HAVE_ASYNCNS to the LmOldSocket code.
Mikael Hallendal <micke@imendio.com>
parents: 445
diff changeset
  1045
450
548b5e3d9bea Refactored some of the SSL code in LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 449
diff changeset
  1046
gboolean
548b5e3d9bea Refactored some of the SSL code in LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 449
diff changeset
  1047
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
  1048
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1049
    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
  1050
        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
  1051
    }
446
e97c43e6f05f Moved the ifdefs for HAVE_ASYNCNS to the LmOldSocket code.
Mikael Hallendal <micke@imendio.com>
parents: 445
diff changeset
  1052
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1053
    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
  1054
}
548b5e3d9bea Refactored some of the SSL code in LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 449
diff changeset
  1055
548b5e3d9bea Refactored some of the SSL code in LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 449
diff changeset
  1056
gboolean
548b5e3d9bea Refactored some of the SSL code in LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 449
diff changeset
  1057
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
  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
    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
  1060
        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
  1061
    }
450
548b5e3d9bea Refactored some of the SSL code in LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 449
diff changeset
  1062
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1063
    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
  1064
}