loudmouth/lm-old-socket.c
author Johannes Wienke <languitar@semipol.de>
Sat, 07 Feb 2015 22:15:08 +0100
changeset 658 352d622c2401
parent 624 a94013a4555d
child 664 f57b1b61e1fe
permissions -rw-r--r--
fix compilation warnings * Make LmLogLevelFlags a typedef to GLogLevelFlags to avoid implicit casting * Remove a useless comparison of an unsigned int < 0
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
658
352d622c2401 fix compilation warnings
Johannes Wienke <languitar@semipol.de>
parents: 624
diff changeset
   215
    if (status != G_IO_STATUS_NORMAL) {
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   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);
615
9a0fa0dabcdf Fix a double-free triggered by failed connection attempts
Frank Zschockelt <lm@freakysoft.de>
parents: 607
diff changeset
   472
        connect_data->io_channel = NULL;
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   473
    }
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   474
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
   475
    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
   476
        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
   477
            (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
   478
        }
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   479
518
cdd6a0c5b439 Went 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 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
   481
        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
   482
            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
   483
                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
   484
            }
476
08d36982e998 First cut of integrating the new resolver in LmOldSocket
Mikael Hallendal <micke@imendio.com>
parents: 475
diff changeset
   485
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   486
            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
   487
            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
   488
        }
cdd6a0c5b439 Went 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
    } 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
   490
        /* 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
   491
        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
   492
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   493
544
ae5934e51dc2 Minor style fix
Mikael Hallendal <micke@imendio.com>
parents: 530
diff changeset
   494
    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
   495
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   496
    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
   497
}
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   498
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   499
gboolean
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   500
_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
   501
{
518
cdd6a0c5b439 Went 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
    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
   503
                                             _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
   504
}
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   505
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   506
static gboolean
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   507
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
   508
                   GIOCondition  condition,
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   509
                   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
   510
{
530
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   511
    LmOldSocket     *socket;
624
a94013a4555d Fix some gcc warnings
Mikael Berthe <mikael@lilotux.net>
parents: 615
diff changeset
   512
    /* struct addrinfo *addr; */
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   513
    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
   514
    socklen_t        len;
530
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   515
    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
   516
    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
   517
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   518
    socket = lm_old_socket_ref (connect_data->socket);
624
a94013a4555d Fix some gcc warnings
Mikael Berthe <mikael@lilotux.net>
parents: 615
diff changeset
   519
    /* addr = connect_data->current_addr; */
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   520
    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
   521
518
cdd6a0c5b439 Went 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
    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
   523
        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
   524
        _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
   525
        if (!_lm_sock_is_blocking_error (err)) {
588
d4468955feb1 Logging Adjustments
Jayson Vantuyl <jvantuyl@engineyard.com>
parents: 587
diff changeset
   526
            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
   527
                   "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
   528
518
cdd6a0c5b439 Went 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
            /* 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
   530
             * 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
   531
            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
   532
                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
   533
                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
   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
        }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   536
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   537
545
58954d98a7f9 Removed the async_connect_waiting and blocking states from LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 544
diff changeset
   538
#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
   539
    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
   540
        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
   541
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   542
        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
   543
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   544
        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
   545
        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
   546
            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
   547
            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
   548
                _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
   549
518
cdd6a0c5b439 Went 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
                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
   551
                       "Connection success (1).\n");
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   552
518
cdd6a0c5b439 Went 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
                _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
   554
            }
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   555
518
cdd6a0c5b439 Went 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
            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
   557
                !_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
   558
                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
   559
                       "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
   560
518
cdd6a0c5b439 Went 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_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
   562
                _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
   563
518
cdd6a0c5b439 Went 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
                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
   565
                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
   566
            }
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   567
        }
545
58954d98a7f9 Removed the async_connect_waiting and blocking states from LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 544
diff changeset
   568
    } else {
58954d98a7f9 Removed the async_connect_waiting and blocking states from LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 544
diff changeset
   569
#endif
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   570
    {
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   571
        /* for blocking sockets, G_IO_OUT means we are connected */
588
d4468955feb1 Logging Adjustments
Jayson Vantuyl <jvantuyl@engineyard.com>
parents: 587
diff changeset
   572
        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
   573
               "Connection success (2).\n");
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   574
518
cdd6a0c5b439 Went 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
        _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
   576
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   577
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   578
    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
   579
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   580
 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
   581
    lm_old_socket_unref(socket);
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   582
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   583
    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
   584
}
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   585
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   586
static gboolean
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   587
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
   588
{
530
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   589
    LmOldSocket     *socket;
4b34a9381345 More styling
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   590
    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
   591
    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
   592
    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
   593
    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
   594
    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
   595
    struct addrinfo *addr;
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   596
518
cdd6a0c5b439 Went 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
    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
   598
    addr = connect_data->current_addr;
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   599
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   600
    if (socket->port == 0) {
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   601
        socket->port = 5222;
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   602
    }
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   603
518
cdd6a0c5b439 Went 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
    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
   605
        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
   606
    } 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
   607
        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
   608
    }
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   609
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   610
    ((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
   611
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   612
    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
   613
                       (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
   614
                       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
   615
                       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
   616
                       NI_NUMERICHOST | NI_NUMERICSERV);
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   617
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   618
    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
   619
        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
   620
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   621
518
cdd6a0c5b439 Went 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
    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
   623
           "Trying %s port %s...\n", name, portname);
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   624
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   625
    fd = _lm_sock_makesocket (addr->ai_family,
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   626
                              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
   627
                              addr->ai_protocol);
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   628
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   629
    if (!_LM_SOCK_VALID (fd)) {
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   630
        g_print("invalid fd\n");
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   631
        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
   632
               "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
   633
               _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
   634
518
cdd6a0c5b439 Went 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
        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
   636
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   637
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   638
    /* 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
   639
     * 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
   640
     * 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
   641
     */
cdd6a0c5b439 Went 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->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
   643
    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
   644
518
cdd6a0c5b439 Went 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_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
   646
    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
   647
553
876d92399bbb Always set the socket to be non-blocking.
Mikael Hallendal <micke@imendio.com>
parents: 549
diff changeset
   648
    _lm_sock_set_blocking (connect_data->fd, FALSE);
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   649
518
cdd6a0c5b439 Went 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
    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
   651
        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
   652
            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
   653
                                  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
   654
                                  G_IO_OUT|G_IO_ERR,
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   655
                                  (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
   656
                                  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
   657
    } 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
   658
        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
   659
            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
   660
                                  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
   661
                                  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
   662
                                  (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
   663
                                  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
   664
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   665
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   666
    res = _lm_sock_connect (connect_data->fd,
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   667
                            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
   668
    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
   669
        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
   670
        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
   671
            _lm_sock_close (connect_data->fd);
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   672
            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
   673
            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
   674
        }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   675
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   676
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   677
    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
   678
}
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   679
444
57c59cfdd77c Made the output buffer functions private to LmOldSocket.
Mikael Hallendal <micke@imendio.com>
parents: 443
diff changeset
   680
static gboolean
57c59cfdd77c Made the output buffer functions private to LmOldSocket.
Mikael Hallendal <micke@imendio.com>
parents: 443
diff changeset
   681
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
   682
                               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
   683
                               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
   684
{
518
cdd6a0c5b439 Went 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
    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
   686
        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
   687
        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
   688
        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
   689
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   690
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   691
    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
   692
}
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   693
444
57c59cfdd77c Made the output buffer functions private to LmOldSocket.
Mikael Hallendal <micke@imendio.com>
parents: 443
diff changeset
   694
static void
57c59cfdd77c Made the output buffer functions private to LmOldSocket.
Mikael Hallendal <micke@imendio.com>
parents: 443
diff changeset
   695
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
   696
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   697
    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
   698
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   699
    socket->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
   700
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   701
    socket->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
   702
        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
   703
                              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
   704
                              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
   705
                              (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
   706
                              socket);
431
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
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   709
static gboolean
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   710
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
   711
                          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
   712
                          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
   713
{
518
cdd6a0c5b439 Went 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
    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
   715
    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
   716
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   717
    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
   718
    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
   719
        /* 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
   720
        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
   721
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   722
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   723
    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
   724
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   725
    if (b_written < 0) {
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   726
        (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
   727
                               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
   728
        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
   729
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   730
518
cdd6a0c5b439 Went 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
    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
   732
    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
   733
        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
   734
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   735
        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
   736
            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
   737
            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
   738
        }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   739
518
cdd6a0c5b439 Went 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
        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
   741
        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
   742
        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
   743
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   744
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   745
    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
   746
}
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   747
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   748
static void
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   749
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
   750
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   751
    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
   752
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   753
    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
   754
           "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
   755
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   756
    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
   757
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   758
    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
   759
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   760
    _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
   761
}
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   762
547
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   763
static void
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   764
old_socket_resolver_host_cb (LmResolver       *resolver,
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   765
                             LmResolverResult  result,
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   766
                             gpointer          user_data)
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   767
{
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   768
    LmOldSocket *socket = (LmOldSocket *) user_data;
588
d4468955feb1 Logging Adjustments
Jayson Vantuyl <jvantuyl@engineyard.com>
parents: 587
diff changeset
   769
    char dispbuf[128];
d4468955feb1 Logging Adjustments
Jayson Vantuyl <jvantuyl@engineyard.com>
parents: 587
diff changeset
   770
    struct sockaddr_in *addr; /* FIXME:IPv6 */
d4468955feb1 Logging Adjustments
Jayson Vantuyl <jvantuyl@engineyard.com>
parents: 587
diff changeset
   771
    const char *converr;
547
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   772
548
60c1d6cbde10 Added some verbose debug output
Mikael Hallendal <micke@imendio.com>
parents: 547
diff changeset
   773
    lm_verbose ("LmOldSocket::host_cb (result=%d)\n", result);
60c1d6cbde10 Added some verbose debug output
Mikael Hallendal <micke@imendio.com>
parents: 547
diff changeset
   774
547
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   775
    if (result != LM_RESOLVER_RESULT_OK) {
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   776
        lm_verbose ("error while resolving, bailing out\n");
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   777
        if (socket->connect_func) {
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   778
            (socket->connect_func) (socket, FALSE, socket->user_data);
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   779
        }
585
bccdb423a8e9 Fixed Resolver Memory Management Issues (by creating less severe issues)
Jayson Vantuyl <jvantuyl@engineyard.com>
parents: 581
diff changeset
   780
        /*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
   781
        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
   782
        socket->resolver = NULL;*/
547
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   783
        g_free (socket->connect_data);
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   784
        socket->connect_data = NULL;
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   785
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   786
        return;
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   787
    }
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   788
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   789
    socket->connect_data->current_addr =
547
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   790
        lm_resolver_results_get_next (resolver);
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   791
588
d4468955feb1 Logging Adjustments
Jayson Vantuyl <jvantuyl@engineyard.com>
parents: 587
diff changeset
   792
    if (socket->connect_data->current_addr) { /* FIXME:IPv6 */
d4468955feb1 Logging Adjustments
Jayson Vantuyl <jvantuyl@engineyard.com>
parents: 587
diff changeset
   793
        addr = (struct sockaddr_in *) (socket->connect_data->current_addr->ai_addr);
d4468955feb1 Logging Adjustments
Jayson Vantuyl <jvantuyl@engineyard.com>
parents: 587
diff changeset
   794
        converr = inet_ntop(AF_INET,&(addr->sin_addr),dispbuf,sizeof(dispbuf));
d4468955feb1 Logging Adjustments
Jayson Vantuyl <jvantuyl@engineyard.com>
parents: 587
diff changeset
   795
        if (converr) {
d4468955feb1 Logging Adjustments
Jayson Vantuyl <jvantuyl@engineyard.com>
parents: 587
diff changeset
   796
            g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_VERBOSE,
d4468955feb1 Logging Adjustments
Jayson Vantuyl <jvantuyl@engineyard.com>
parents: 587
diff changeset
   797
                   "Attempting Connection to %s\n",dispbuf);
d4468955feb1 Logging Adjustments
Jayson Vantuyl <jvantuyl@engineyard.com>
parents: 587
diff changeset
   798
        } else {
d4468955feb1 Logging Adjustments
Jayson Vantuyl <jvantuyl@engineyard.com>
parents: 587
diff changeset
   799
            g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_VERBOSE,
d4468955feb1 Logging Adjustments
Jayson Vantuyl <jvantuyl@engineyard.com>
parents: 587
diff changeset
   800
                   "Attempting Connection (unable to convert address to presentable format)\n");
d4468955feb1 Logging Adjustments
Jayson Vantuyl <jvantuyl@engineyard.com>
parents: 587
diff changeset
   801
        };
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
   802
        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
   803
    } 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
   804
        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
   805
               "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
   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
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 605
diff changeset
   808
    /* FIXME: What do we do here?  How to make the mainloop exit with an
587
7c793095138e Fixed Retry Behavior, Fixed Crash on IPv6 Addresses, Log and Exit On No Host
Jayson Vantuyl <jvantuyl@engineyard.com>
parents: 585
diff changeset
   809
       error, while having no ref to said mainloop */
547
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   810
}
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   811
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   812
/* 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
   813
 *        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
   814
 *
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   815
 *        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
   816
 *        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
   817
 */
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   818
static void
476
08d36982e998 First cut of integrating the new resolver in LmOldSocket
Mikael Hallendal <micke@imendio.com>
parents: 475
diff changeset
   819
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
   820
                            LmResolverResult  result,
08d36982e998 First cut of integrating the new resolver in LmOldSocket
Mikael Hallendal <micke@imendio.com>
parents: 475
diff changeset
   821
                            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
   822
{
518
cdd6a0c5b439 Went 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
    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
   824
    const gchar *remote_addr;
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   825
548
60c1d6cbde10 Added some verbose debug output
Mikael Hallendal <micke@imendio.com>
parents: 547
diff changeset
   826
    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
   827
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   828
    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
   829
        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
   830
        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
   831
    } 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
   832
        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
   833
        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
   834
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   835
518
cdd6a0c5b439 Went 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
    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
   837
        remote_addr = lm_proxy_get_server (socket->proxy);
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   838
    } 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
   839
        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
   840
    }
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   841
    else {
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   842
        remote_addr = socket->domain;
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   843
    }
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   844
547
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   845
    g_object_unref (socket->resolver);
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   846
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   847
    socket->resolver =
547
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   848
            lm_resolver_new_for_host (remote_addr,
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   849
                                      old_socket_resolver_host_cb,
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   850
                                      socket);
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   851
547
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 545
diff changeset
   852
    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
   853
}
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   854
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   855
LmOldSocket *
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   856
lm_old_socket_create (GMainContext      *context,
451
0c8ea9d1bec2 Some style fixes
Mikael Hallendal <micke@imendio.com>
parents: 450
diff changeset
   857
                      IncomingDataFunc   data_func,
0c8ea9d1bec2 Some style fixes
Mikael Hallendal <micke@imendio.com>
parents: 450
diff changeset
   858
                      SocketClosedFunc   closed_func,
0c8ea9d1bec2 Some style fixes
Mikael Hallendal <micke@imendio.com>
parents: 450
diff changeset
   859
                      ConnectResultFunc  connect_func,
0c8ea9d1bec2 Some style fixes
Mikael Hallendal <micke@imendio.com>
parents: 450
diff changeset
   860
                      gpointer           user_data,
0c8ea9d1bec2 Some style fixes
Mikael Hallendal <micke@imendio.com>
parents: 450
diff changeset
   861
                      LmConnection      *connection,
0c8ea9d1bec2 Some style fixes
Mikael Hallendal <micke@imendio.com>
parents: 450
diff changeset
   862
                      const gchar       *server,
0c8ea9d1bec2 Some style fixes
Mikael Hallendal <micke@imendio.com>
parents: 450
diff changeset
   863
                      const gchar       *domain,
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   864
                      guint              port,
451
0c8ea9d1bec2 Some style fixes
Mikael Hallendal <micke@imendio.com>
parents: 450
diff changeset
   865
                      LmSSL             *ssl,
0c8ea9d1bec2 Some style fixes
Mikael Hallendal <micke@imendio.com>
parents: 450
diff changeset
   866
                      LmProxy           *proxy,
0c8ea9d1bec2 Some style fixes
Mikael Hallendal <micke@imendio.com>
parents: 450
diff changeset
   867
                      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
   868
{
518
cdd6a0c5b439 Went 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
    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
   870
    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
   871
518
cdd6a0c5b439 Went 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 (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
   873
    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
   874
    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
   875
    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
   876
    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
   877
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   878
    socket = 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
   879
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   880
    socket->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
   881
518
cdd6a0c5b439 Went 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->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
   883
    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
   884
    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
   885
    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
   886
    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
   887
    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
   888
    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
   889
    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
   890
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   891
    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
   892
        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
   893
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   894
518
cdd6a0c5b439 Went 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
    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
   896
        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
   897
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   898
518
cdd6a0c5b439 Went 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 = 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
   900
    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
   901
    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
   902
    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
   903
    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
   904
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   905
    if (!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
   906
        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
   907
                                                        "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
   908
                                                        "tcp",
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   909
                                                        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
   910
                                                        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
   911
    } else {
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   912
        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
   913
            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
   914
                                      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
   915
                                      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
   916
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   917
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   918
    if (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
   919
        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
   920
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   921
518
cdd6a0c5b439 Went 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->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
   923
    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
   924
    socket->connect_func = connect_func;
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   925
    socket->user_data = user_data;
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   926
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   927
    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
   928
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   929
    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
   930
}
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   931
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   932
void
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   933
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
   934
{
518
cdd6a0c5b439 Went 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 != 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
   936
    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
   937
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   938
    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
   939
}
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   940
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   941
void
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   942
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
   943
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   944
    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
   945
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   946
    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
   947
518
cdd6a0c5b439 Went 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
    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
   949
        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
   950
        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
   951
    }
581
757d716a8f8a Applied ksmith's DNS patch.
Samuel Tesla <stesla@engineyard.com>
parents: 554
diff changeset
   952
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   953
    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
   954
    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
   955
        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
   956
	    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
   957
        }
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   958
        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
   959
        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
   960
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   961
585
bccdb423a8e9 Fixed Resolver Memory Management Issues (by creating less severe issues)
Jayson Vantuyl <jvantuyl@engineyard.com>
parents: 581
diff changeset
   962
    /* 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
   963
    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
   964
        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
   965
        socket->resolver = NULL;
585
bccdb423a8e9 Fixed Resolver Memory Management Issues (by creating less severe issues)
Jayson Vantuyl <jvantuyl@engineyard.com>
parents: 581
diff changeset
   966
    } */
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   967
cdd6a0c5b439 Went 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->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
   969
        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
   970
            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
   971
            socket->watch_in = NULL;
476
08d36982e998 First cut of integrating the new resolver in LmOldSocket
Mikael Hallendal <micke@imendio.com>
parents: 475
diff changeset
   972
        }
08d36982e998 First cut of integrating the new resolver in LmOldSocket
Mikael Hallendal <micke@imendio.com>
parents: 475
diff changeset
   973
518
cdd6a0c5b439 Went 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
        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
   975
            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
   976
            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
   977
        }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   978
518
cdd6a0c5b439 Went 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
        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
   980
            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
   981
            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
   982
        }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   983
518
cdd6a0c5b439 Went 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
        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
   985
            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
   986
            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
   987
        }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   988
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   989
        socket_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
   990
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   991
        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
   992
        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
   993
    }
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   994
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   995
    if (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
        _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
   997
    }
431
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
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1000
gchar *
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1001
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
  1002
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1003
    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
  1004
}
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1005
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1006
LmOldSocket *
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1007
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
  1008
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1009
    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
  1010
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1011
    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
  1012
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1013
    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
  1014
}
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1015
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1016
void
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1017
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
  1018
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1019
    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
  1020
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1021
    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
  1022
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1023
    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
  1024
        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
  1025
    }
431
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
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1028
gboolean
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1029
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
  1030
{
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1031
#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
  1032
    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
  1033
#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
  1034
    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
  1035
#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
  1036
}
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1037
446
e97c43e6f05f Moved the ifdefs for HAVE_ASYNCNS to the LmOldSocket code.
Mikael Hallendal <micke@imendio.com>
parents: 445
diff changeset
  1038
void
e97c43e6f05f Moved the ifdefs for HAVE_ASYNCNS to the LmOldSocket code.
Mikael Hallendal <micke@imendio.com>
parents: 445
diff changeset
  1039
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
  1040
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1041
    if (!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
  1042
        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
  1043
    }
446
e97c43e6f05f Moved the ifdefs for HAVE_ASYNCNS to the LmOldSocket code.
Mikael Hallendal <micke@imendio.com>
parents: 445
diff changeset
  1044
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1045
    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
  1046
}
e97c43e6f05f Moved the ifdefs for HAVE_ASYNCNS to the LmOldSocket code.
Mikael Hallendal <micke@imendio.com>
parents: 445
diff changeset
  1047
450
548b5e3d9bea Refactored some of the SSL code in LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 449
diff changeset
  1048
gboolean
548b5e3d9bea Refactored some of the SSL code in LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 449
diff changeset
  1049
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
  1050
{
518
cdd6a0c5b439 Went 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
    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
  1052
        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
  1053
    }
446
e97c43e6f05f Moved the ifdefs for HAVE_ASYNCNS to the LmOldSocket code.
Mikael Hallendal <micke@imendio.com>
parents: 445
diff changeset
  1054
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1055
    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
  1056
}
548b5e3d9bea Refactored some of the SSL code in LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 449
diff changeset
  1057
548b5e3d9bea Refactored some of the SSL code in LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 449
diff changeset
  1058
gboolean
548b5e3d9bea Refactored some of the SSL code in LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 449
diff changeset
  1059
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
  1060
{
518
cdd6a0c5b439 Went 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
    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
  1062
        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
  1063
    }
450
548b5e3d9bea Refactored some of the SSL code in LmConnection.
Mikael Hallendal <micke@imendio.com>
parents: 449
diff changeset
  1064
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1065
    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
  1066
}