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