jingle-s5b/socks5-proto.c
author Gu1 <gu1@aeroxteam.fr>
Sun, 12 Sep 2010 18:32:57 +0200
changeset 168 f699f6b47613
permissions -rw-r--r--
S5B: SOCKSv5 implementation based on the one in the glib's git repository committer: Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
168
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
     1
/*
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
     2
 * socks5-proto.c
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
     3
 *
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
     4
 * Based on the gio socks5 implementation that is not yet included in
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
     5
 * the latest stable glib release.
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
     6
 * Original Authors:
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
     7
 * Youness Alaoui <youness.alaoui@collabora.co.uk>
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
     8
 * Nicolas Dufresne <nicolas.dufresne@collabora.co.uk>
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
     9
 *
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    10
 * Copyrigth (C) 2010 Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    11
 *
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    12
 * This program is free software; you can redistribute it and/or modify
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    13
 * it under the terms of the GNU General Public License as published by
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    14
 * the Free Software Foundation; either version 2 of the License, or (at
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    15
 * your option) any later version.
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    16
 *
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    17
 * This program is distributed in the hope that it will be useful, but
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    18
 * WITHOUT ANY WARRANTY; without even the implied warranty of
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    20
 * General Public License for more details.
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    21
 *
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    22
 * You should have received a copy of the GNU General Public License
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    23
 * along with this program; if not, write to the Free Software
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    24
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    25
 * USA
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    26
 */
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    27
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    28
#include <glib.h>
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    29
#include <gio/gio.h>
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    30
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    31
#include <string.h>
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    32
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    33
#include "socks5-proto.h"
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    34
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    35
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    36
#define SOCKS5_VERSION            0x05
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    37
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    38
#define SOCKS5_CMD_CONNECT        0x01
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    39
#define SOCKS5_CMD_BIND           0x02
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    40
#define SOCKS5_CMD_UDP_ASSOCIATE  0x03
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    41
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    42
#define SOCKS5_ATYP_IPV4          0x01
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    43
#define SOCKS5_ATYP_DOMAINNAME    0x03
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    44
#define SOCKS5_ATYP_IPV6          0x04
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    45
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    46
#define SOCKS5_AUTH_VERSION       0x01
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    47
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    48
#define SOCKS5_AUTH_NONE          0x00
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    49
#define SOCKS5_AUTH_GSSAPI        0x01
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    50
#define SOCKS5_AUTH_USR_PASS      0x02
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    51
#define SOCKS5_AUTH_NO_ACCEPT     0xff
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    52
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    53
#define SOCKS5_MAX_LEN            255
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    54
#define SOCKS5_RESERVED           0x00
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    55
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    56
#define SOCKS5_REP_SUCCEEDED      0x00
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    57
#define SOCKS5_REP_SRV_FAILURE    0x01
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    58
#define SOCKS5_REP_NOT_ALLOWED    0x02
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    59
#define SOCKS5_REP_NET_UNREACH    0x03
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    60
#define SOCKS5_REP_HOST_UNREACH   0x04
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    61
#define SOCKS5_REP_REFUSED        0x05
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    62
#define SOCKS5_REP_TTL_EXPIRED    0x06
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    63
#define SOCKS5_REP_CMD_NOT_SUP    0x07
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    64
#define SOCKS5_REP_ATYPE_NOT_SUP  0x08
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    65
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    66
#define S5B_DST_PORT              0
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    67
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    68
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    69
/*
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    70
 * +----+----------+----------+
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    71
 * |VER | NMETHODS | METHODS  |
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    72
 * +----+----------+----------+
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    73
 * | 1  |    1     | 1 to 255 |
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    74
 * +----+----------+----------+
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    75
 */
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    76
#define SOCKS5_NEGO_MSG_LEN       4
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    77
static gint
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    78
client_set_nego_msg (guint8 *msg, gboolean has_auth)
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    79
{
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    80
  gint len = 3;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    81
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    82
  msg[0] = SOCKS5_VERSION;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    83
  msg[1] = 0x01; /* number of methods supported */
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    84
  msg[2] = SOCKS5_AUTH_NONE;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    85
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    86
  /* add support for authentication method */
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    87
  if (has_auth) {
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    88
    msg[1] = 0x02; /* number of methods supported */
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    89
    msg[3] = SOCKS5_AUTH_USR_PASS;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    90
    len++;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    91
  }
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    92
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    93
  return len;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    94
}
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    95
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    96
/*
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    97
 * +----+--------+
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    98
 * |VER | METHOD |
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
    99
 * +----+--------+
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   100
 * | 1  |   1    |
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   101
 * +----+--------+
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   102
 */
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   103
static gint
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   104
server_set_nego_reply_msg (guint8 *msg, guint8 method)
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   105
{
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   106
  gint len = 2;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   107
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   108
  msg[0] = SOCKS5_VERSION;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   109
  msg[1] = method; /* selected method */
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   110
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   111
  return len;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   112
}
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   113
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   114
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   115
/*
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   116
 * +----+--------+
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   117
 * |VER | METHOD |
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   118
 * +----+--------+
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   119
 * | 1  |   1    |
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   120
 * +----+--------+
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   121
 */
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   122
#define SOCKS5_NEGO_REP_LEN       2
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   123
static gboolean
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   124
client_parse_nego_reply (const guint8 *data,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   125
                         gboolean     has_auth,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   126
                         gboolean    *must_auth,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   127
                         GError     **error)
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   128
{
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   129
  if (data[0] != SOCKS5_VERSION) {
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   130
    g_set_error_literal (error, S5B_SOCKS5_ERROR, S5B_SOCKS5_ERROR_FAILED,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   131
                         "The server is not a SOCKSv5 proxy server.");
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   132
    return FALSE;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   133
  }
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   134
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   135
  switch (data[1]) {
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   136
    case SOCKS5_AUTH_NONE:
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   137
      *must_auth = FALSE;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   138
      break;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   139
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   140
    case SOCKS5_AUTH_USR_PASS:
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   141
      if (!has_auth) {
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   142
        g_set_error_literal (error, S5B_SOCKS5_ERROR, S5B_SOCKS5_ERROR_NEED_AUTH,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   143
                             "The SOCKSv5 proxy requires authentication.");
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   144
        return FALSE;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   145
      }
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   146
      *must_auth = TRUE;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   147
      break;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   148
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   149
    case SOCKS5_AUTH_GSSAPI:
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   150
    case SOCKS5_AUTH_NO_ACCEPT:
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   151
    default:
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   152
      g_set_error_literal (error, S5B_SOCKS5_ERROR, S5B_SOCKS5_ERROR_AUTH_FAILED,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   153
                           "The SOCKSv5 require an authentication method that is not "
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   154
                           "supported.");
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   155
      return FALSE;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   156
      break;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   157
  }
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   158
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   159
  return TRUE;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   160
}
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   161
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   162
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   163
/*
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   164
 * +----+----------+----------+
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   165
 * |VER | NMETHODS | METHODS  |
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   166
 * +----+----------+----------+
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   167
 * | 1  |    1     | 1 to 255 |
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   168
 * +----+----------+----------+
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   169
 */
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   170
static gboolean
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   171
server_parse_nego_init (const guint8 *data,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   172
                        gssize        datalen,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   173
                        GError      **error)
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   174
{
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   175
  guint i;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   176
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   177
  if (data[0] != SOCKS5_VERSION) {
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   178
    g_set_error_literal (error, S5B_SOCKS5_ERROR, S5B_SOCKS5_ERROR_FAILED,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   179
                         "The client is not a SOCKSv5 client.");
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   180
    return FALSE;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   181
  }
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   182
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   183
  for (i = 2; i < datalen && i < data[1]; ++i) {
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   184
    guint8 method = data[i];
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   185
    if (method == 0x00)
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   186
      return TRUE;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   187
  }
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   188
  
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   189
  g_set_error_literal (error, S5B_SOCKS5_ERROR, S5B_SOCKS5_ERROR_AUTH_FAILED,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   190
                       "The client did not offer any authentication method "
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   191
                       "we support.");
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   192
  return FALSE;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   193
}
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   194
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   195
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   196
#define SOCKS5_AUTH_MSG_LEN       515
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   197
static gint
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   198
set_auth_msg (guint8      *msg,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   199
              const gchar *username,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   200
              const gchar *password,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   201
              GError **error)
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   202
{
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   203
  gint len = 0;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   204
  gint ulen = 0; /* username length */
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   205
  gint plen = 0; /* Password length */
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   206
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   207
  if (username)
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   208
    ulen = strlen (username);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   209
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   210
  if (password)
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   211
    plen = strlen (password);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   212
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   213
  if (ulen > SOCKS5_MAX_LEN || plen > SOCKS5_MAX_LEN) {
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   214
    g_set_error (error, S5B_SOCKS5_ERROR, S5B_SOCKS5_ERROR_FAILED,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   215
                 "Username or password is too long for SOCKSv5 "
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   216
                 "protocol (max. is %i).",
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   217
                 SOCKS5_MAX_LEN);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   218
    return FALSE;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   219
  }
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   220
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   221
  msg[len++] = SOCKS5_AUTH_VERSION;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   222
  msg[len++] = ulen;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   223
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   224
  if (ulen > 0)
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   225
    memcpy (msg + len, username, ulen);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   226
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   227
  len += ulen;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   228
  msg[len++] = plen;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   229
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   230
  if (plen > 0)
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   231
    memcpy (msg + len, password, plen);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   232
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   233
  len += plen;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   234
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   235
  return len;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   236
}
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   237
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   238
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   239
static gboolean
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   240
check_auth_status (const guint8 *data, GError **error)
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   241
{
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   242
  if (data[0] != SOCKS5_VERSION
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   243
      || data[1] != SOCKS5_REP_SUCCEEDED) {
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   244
    g_set_error_literal (error, S5B_SOCKS5_ERROR, S5B_SOCKS5_ERROR_AUTH_FAILED,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   245
                         "SOCKSv5 authentication failed due to wrong "
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   246
                         "username or password.");
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   247
    return FALSE;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   248
  }
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   249
  return TRUE;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   250
}
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   251
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   252
/*
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   253
 * +----+-----+-------+------+----------+----------+
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   254
 * |VER | CMD |  RSV  | ATYP | DST.ADDR | DST.PORT |
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   255
 * +----+-----+-------+------+----------+----------+
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   256
 * | 1  |  1  | X'00' |  1   | Variable |    2     |
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   257
 * +----+-----+-------+------+----------+----------+
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   258
 * DST.ADDR is a string with first byte being the size. So DST.ADDR may not be
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   259
 * longer then 256 bytes.
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   260
 */
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   261
#define SOCKS5_CONN_MSG_LEN       262
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   262
static gint
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   263
client_set_connect_msg (guint8       *msg,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   264
                        const gchar *hostname,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   265
                        guint16      port,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   266
                        GError     **error)
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   267
{
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   268
  guint len = 0;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   269
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   270
  msg[len++] = SOCKS5_VERSION;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   271
  msg[len++] = SOCKS5_CMD_CONNECT;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   272
  msg[len++] = SOCKS5_RESERVED;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   273
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   274
  gsize host_len = strlen (hostname);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   275
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   276
  if (host_len > SOCKS5_MAX_LEN) {
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   277
    g_set_error (error, S5B_SOCKS5_ERROR, S5B_SOCKS5_ERROR_FAILED,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   278
                 "Hostname '%s' too long for SOCKSv5 protocol "
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   279
                 "(maximum is %i bytes)",
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   280
                 hostname, SOCKS5_MAX_LEN);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   281
    return -1;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   282
  }
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   283
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   284
  msg[len++] = SOCKS5_ATYP_DOMAINNAME;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   285
  msg[len++] = (guint8) host_len;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   286
  memcpy (msg + len, hostname, host_len);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   287
  len += host_len;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   288
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   289
  {
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   290
    guint16 hp = g_htons (port);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   291
    memcpy (msg + len, &hp, 2);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   292
    len += 2;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   293
  }
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   294
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   295
  return len;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   296
}
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   297
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   298
static guint
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   299
server_parse_connect_msg (const guint8 *data, gint *atype, GError **error)
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   300
{
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   301
  if (data[0] != SOCKS5_VERSION) {
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   302
    g_set_error_literal (error, S5B_SOCKS5_ERROR, S5B_SOCKS5_ERROR_FAILED,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   303
                         "The client is not a SOCKSv5 client.");
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   304
    return FALSE;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   305
  }
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   306
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   307
  if (data[1] != SOCKS5_CMD_CONNECT) {
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   308
    g_set_error_literal (error, S5B_SOCKS5_ERROR, S5B_SOCKS5_ERROR_FAILED,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   309
                         "The server only supports the CONNECT command.");
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   310
  }
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   311
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   312
  switch (data[3]) {
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   313
    case SOCKS5_ATYP_IPV4:
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   314
      *atype = SOCKS5_ATYP_IPV4;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   315
      break;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   316
    case SOCKS5_ATYP_DOMAINNAME:
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   317
      *atype = SOCKS5_ATYP_DOMAINNAME;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   318
      break;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   319
    case SOCKS5_ATYP_IPV6:
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   320
      *atype = SOCKS5_ATYP_IPV6;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   321
      break;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   322
    default:
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   323
      g_set_error_literal (error, S5B_SOCKS5_ERROR, S5B_SOCKS5_ERROR_FAILED,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   324
                           "The client sent an invalid address type.");
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   325
      return FALSE;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   326
  }
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   327
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   328
  return TRUE;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   329
}
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   330
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   331
/*
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   332
 * +----+-----+-------+------+----------+----------+
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   333
 * |VER | REP |  RSV  | ATYP | BND.ADDR | BND.PORT |
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   334
 * +----+-----+-------+------+----------+----------+
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   335
 * | 1  |  1  | X'00' |  1   | Variable |    2     |
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   336
 * +----+-----+-------+------+----------+----------+
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   337
 * This reply need to be read by small part to determin size. Buffer
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   338
 * size is determined in function of the biggest part to read.
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   339
 *
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   340
 * The parser only requires 4 bytes.
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   341
 */
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   342
#define SOCKS5_CONN_REP_LEN       255
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   343
static gboolean
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   344
client_parse_connect_reply (const guint8 *data, gint *atype, GError **error)
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   345
{
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   346
  if (data[0] != SOCKS5_VERSION) {
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   347
    g_set_error_literal (error, S5B_SOCKS5_ERROR, S5B_SOCKS5_ERROR_FAILED,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   348
                         "The server is not a SOCKSv5 proxy server.");
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   349
    return FALSE;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   350
  }
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   351
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   352
  switch (data[1]) {
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   353
    case SOCKS5_REP_SUCCEEDED:
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   354
      if (data[2] != SOCKS5_RESERVED) {
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   355
        g_set_error_literal (error, S5B_SOCKS5_ERROR, S5B_SOCKS5_ERROR_FAILED,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   356
                             "The server is not a SOCKSv5 proxy server.");
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   357
        return FALSE;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   358
      }
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   359
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   360
      switch (data[3]) {
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   361
        case SOCKS5_ATYP_IPV4:
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   362
        case SOCKS5_ATYP_IPV6:
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   363
        case SOCKS5_ATYP_DOMAINNAME:
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   364
          *atype = data[3];
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   365
          break;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   366
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   367
        default:
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   368
          g_set_error_literal (error, S5B_SOCKS5_ERROR, S5B_SOCKS5_ERROR_FAILED,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   369
                               "The SOCKSv5 proxy server uses unkown address type.");
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   370
          return FALSE;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   371
      }
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   372
      break;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   373
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   374
    case SOCKS5_REP_SRV_FAILURE:
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   375
      g_set_error_literal (error, S5B_SOCKS5_ERROR, S5B_SOCKS5_ERROR_FAILED,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   376
                           "Internal SOCKSv5 proxy server error.");
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   377
      return FALSE;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   378
      break;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   379
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   380
    case SOCKS5_REP_NOT_ALLOWED:
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   381
      g_set_error_literal (error, S5B_SOCKS5_ERROR, S5B_SOCKS5_ERROR_NOT_ALLOWED,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   382
                           "SOCKSv5 connection not allowed by ruleset.");
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   383
      return FALSE;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   384
      break;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   385
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   386
    case SOCKS5_REP_TTL_EXPIRED:
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   387
    case SOCKS5_REP_HOST_UNREACH:
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   388
      g_set_error_literal (error, S5B_SOCKS5_ERROR, S5B_SOCKS5_ERROR_HOST_UNREACHABLE,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   389
                           "Host unreachable through SOCKSv5 server.");
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   390
      return FALSE;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   391
      break;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   392
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   393
    case SOCKS5_REP_NET_UNREACH:
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   394
      g_set_error_literal (error, S5B_SOCKS5_ERROR, S5B_SOCKS5_ERROR_NETWORK_UNREACHABLE,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   395
                           "Network unreachable through SOCKSv5 proxy.");
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   396
      return FALSE;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   397
      break;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   398
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   399
    case SOCKS5_REP_REFUSED:
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   400
      g_set_error_literal (error, S5B_SOCKS5_ERROR, S5B_SOCKS5_ERROR_CONNECTION_REFUSED,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   401
                           "Connection refused through SOCKSv5 proxy.");
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   402
      return FALSE;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   403
      break;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   404
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   405
    case SOCKS5_REP_CMD_NOT_SUP:
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   406
      g_set_error_literal (error, S5B_SOCKS5_ERROR, S5B_SOCKS5_ERROR_FAILED,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   407
                           "SOCKSv5 proxy does not support 'connect' command.");
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   408
      return FALSE;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   409
      break;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   410
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   411
    case SOCKS5_REP_ATYPE_NOT_SUP:
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   412
      g_set_error_literal (error, G_IO_ERROR, S5B_SOCKS5_ERROR_FAILED,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   413
                           "SOCKSv5 proxy does not support provided address type.");
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   414
      return FALSE;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   415
      break;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   416
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   417
    default: /* Unknown error */
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   418
      g_set_error_literal (error, G_IO_ERROR, S5B_SOCKS5_ERROR_FAILED,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   419
                           "Unkown SOCKSv5 proxy error.");
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   420
      return FALSE;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   421
      break;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   422
  }
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   423
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   424
  return TRUE;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   425
}
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   426
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   427
static gint
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   428
server_set_connect_reply (guint8 *msg,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   429
                          guint8 rep,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   430
                          guint8 atype,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   431
                          const guint8 *bndaddr,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   432
                          guint16 bndport)
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   433
{
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   434
  guint len = 0, host_len;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   435
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   436
  msg[len++] = SOCKS5_VERSION;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   437
  msg[len++] = rep;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   438
  if (rep != 0)
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   439
    return len;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   440
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   441
  len++;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   442
  msg[len++] = atype;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   443
  switch (atype) {
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   444
    case SOCKS5_ATYP_IPV4:
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   445
      // bndaddr should already be in network byte order
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   446
      msg[len++] = SOCKS5_ATYP_IPV4;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   447
      memcpy (msg + len, bndaddr, 4);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   448
      len += 4;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   449
      break;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   450
    case SOCKS5_ATYP_DOMAINNAME:
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   451
      host_len = strlen((gchar* )bndaddr);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   452
      msg[len++] = SOCKS5_ATYP_DOMAINNAME;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   453
      msg[len++] = (guint8) host_len;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   454
      memcpy (msg + len, bndaddr, host_len);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   455
      len += host_len;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   456
      break;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   457
    case SOCKS5_ATYP_IPV6:
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   458
      msg[len++] = SOCKS5_ATYP_IPV6;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   459
      memcpy (msg + len, bndaddr, 16);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   460
      len += 16;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   461
      break;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   462
    default:
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   463
      return 0;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   464
  }
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   465
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   466
  {
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   467
    guint16 hp = g_htons (bndport);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   468
    memcpy (msg + len, &hp, 2);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   469
    len += 2;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   470
  }
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   471
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   472
  return len;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   473
}
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   474
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   475
typedef struct
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   476
{
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   477
  GSimpleAsyncResult *simple;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   478
  GIOStream *io_stream;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   479
  GInetSocketAddress *external_address;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   480
  gchar *hostname;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   481
  //guint16 port; // port is always 0
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   482
  gchar *username;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   483
  gchar *password;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   484
  guint8 *buffer;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   485
  gssize length;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   486
  gssize offset;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   487
  GCancellable *cancellable;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   488
} ConnectAsyncData;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   489
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   490
static void nego_msg_write_cb              (GObject          *source,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   491
                                            GAsyncResult     *res,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   492
                                            gpointer          user_data);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   493
static void nego_msg_read_cb               (GObject          *source,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   494
                                            GAsyncResult     *res,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   495
                                            gpointer          user_data);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   496
static void no_supported_method_cb         (GObject      *source,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   497
                                            GAsyncResult *res,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   498
                                            gpointer      user_data);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   499
static void nego_reply_read_cb             (GObject          *source,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   500
                                            GAsyncResult     *res,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   501
                                            gpointer          user_data);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   502
static void nego_reply_write_cb            (GObject      *source,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   503
                                            GAsyncResult *result,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   504
                                            gpointer      user_data);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   505
static void auth_msg_write_cb              (GObject          *source,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   506
                                           GAsyncResult     *res,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   507
                                            gpointer          user_data);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   508
static void auth_reply_read_cb             (GObject          *source,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   509
                                            GAsyncResult     *result,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   510
                                            gpointer          user_data);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   511
static void send_connect_msg               (ConnectAsyncData *data);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   512
static void connect_msg_write_cb           (GObject          *source,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   513
                                            GAsyncResult     *result,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   514
                                            gpointer          user_data);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   515
static void connect_msg_read_cb            (GObject      *source,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   516
                                            GAsyncResult *result,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   517
                                            gpointer      user_data);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   518
static void connect_addr_len_read_cb       (GObject      *source,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   519
                                            GAsyncResult *result,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   520
                                            gpointer      user_data);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   521
static void connect_addr_read_cb           (GObject      *source,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   522
                                            GAsyncResult *result,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   523
                                            gpointer      user_data);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   524
static void connect_reply_write_cb         (GObject      *source,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   525
                                            GAsyncResult *result,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   526
                                            gpointer      user_data);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   527
static void connect_reply_read_cb          (GObject          *source,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   528
                                            GAsyncResult     *result,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   529
                                            gpointer          user_data);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   530
static void connect_reply_addr_len_read_cb (GObject          *source,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   531
                                            GAsyncResult     *result,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   532
                                            gpointer          user_data);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   533
static void connect_reply_addr_read_cb     (GObject          *source,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   534
                                            GAsyncResult     *result,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   535
                                            gpointer          user_data);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   536
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   537
static void
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   538
free_connect_data (ConnectAsyncData *data)
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   539
{
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   540
  if (data->io_stream)
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   541
    g_object_unref (data->io_stream);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   542
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   543
  if (data->external_address)
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   544
    g_object_unref(data->external_address);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   545
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   546
  g_free (data->hostname);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   547
  g_free (data->username);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   548
  g_free (data->password);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   549
  
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   550
  if (data->cancellable)
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   551
    g_object_unref (data->cancellable);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   552
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   553
  g_slice_free (ConnectAsyncData, data);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   554
}
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   555
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   556
static void
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   557
complete_async_from_error (ConnectAsyncData *data, GError *error)
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   558
{
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   559
  GSimpleAsyncResult *simple = data->simple;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   560
  g_simple_async_result_set_from_error (data->simple,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   561
                                        error);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   562
  g_error_free (error);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   563
  g_simple_async_result_set_op_res_gpointer (simple, NULL, NULL);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   564
  g_simple_async_result_complete (simple);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   565
  g_object_unref (simple);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   566
}
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   567
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   568
static void
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   569
do_read (GAsyncReadyCallback callback, ConnectAsyncData *data)
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   570
{
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   571
   GInputStream *in;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   572
   in = g_io_stream_get_input_stream (data->io_stream);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   573
   g_input_stream_read_async (in,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   574
                              data->buffer + data->offset,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   575
                              data->length - data->offset,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   576
                              G_PRIORITY_DEFAULT, data->cancellable,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   577
                              callback, data);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   578
}
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   579
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   580
static void
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   581
do_write (GAsyncReadyCallback callback, ConnectAsyncData *data)
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   582
{
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   583
  GOutputStream *out;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   584
  out = g_io_stream_get_output_stream (data->io_stream);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   585
  g_output_stream_write_async (out,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   586
                               data->buffer + data->offset,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   587
                               data->length - data->offset,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   588
                               G_PRIORITY_DEFAULT, data->cancellable,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   589
                               callback, data);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   590
}
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   591
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   592
/**
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   593
 * @param hostname  with SOCKS5 Bytestreams, the hostname (dst.addr) actually
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   594
 *                  contains SHA1 Hash of: (SID + Requester JID + Target JID)
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   595
 * 
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   596
 * Function called when we act as a client and want to negociate
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   597
 * with a SOCKS5 server.
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   598
 */
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   599
void
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   600
socks5_client_nego (GIOStream            *io_stream,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   601
                    gchar                *hostname,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   602
                    GCancellable         *cancellable,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   603
                    GAsyncReadyCallback   callback,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   604
                    gpointer              user_data)
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   605
{
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   606
  GSimpleAsyncResult *simple;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   607
  ConnectAsyncData *data;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   608
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   609
  simple = g_simple_async_result_new (NULL,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   610
                                      callback, user_data,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   611
                                      socks5_client_nego);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   612
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   613
  data = g_slice_new0 (ConnectAsyncData);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   614
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   615
  data->simple = simple;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   616
  data->io_stream = g_object_ref (io_stream);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   617
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   618
  if (cancellable)
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   619
    data->cancellable = g_object_ref (cancellable);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   620
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   621
  data->hostname = g_strdup(hostname);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   622
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   623
  g_simple_async_result_set_op_res_gpointer (simple, data, 
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   624
                                             (GDestroyNotify) free_connect_data);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   625
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   626
  data->buffer = g_malloc0 (SOCKS5_NEGO_MSG_LEN);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   627
  data->length = client_set_nego_msg (data->buffer,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   628
                                      data->username || data->password);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   629
  data->offset = 0;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   630
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   631
  do_write (nego_msg_write_cb, data);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   632
}
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   633
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   634
/**
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   635
 * Function called when we act as a server and want to negociate
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   636
 * with a client.
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   637
 */
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   638
#define SOCKS5_NEGO_MSG_MAX_LEN       257 // 1 + 1 + 255
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   639
void
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   640
socks5_server_nego (GIOStream            *io_stream,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   641
                    gchar                *allowed_hostname,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   642
                    GInetSocketAddress   *external_address,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   643
                    GCancellable         *cancellable,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   644
                    GAsyncReadyCallback   callback,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   645
                    gpointer              user_data)
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   646
{
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   647
  GSimpleAsyncResult *simple;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   648
  ConnectAsyncData *data;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   649
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   650
  simple = g_simple_async_result_new (NULL,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   651
                                      callback, user_data,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   652
                                      socks5_server_nego);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   653
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   654
  data = g_slice_new0 (ConnectAsyncData);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   655
  data->simple = simple;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   656
  data->io_stream = g_object_ref (io_stream);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   657
  data->external_address = g_object_ref (external_address);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   658
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   659
  if (cancellable)
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   660
    data->cancellable = g_object_ref (cancellable);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   661
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   662
  data->hostname = g_strdup(allowed_hostname);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   663
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   664
  g_simple_async_result_set_op_res_gpointer (simple, data, 
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   665
                                             (GDestroyNotify) free_connect_data);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   666
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   667
  data->buffer = g_malloc0 (SOCKS5_NEGO_MSG_LEN);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   668
  data->length = SOCKS5_NEGO_MSG_MAX_LEN;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   669
  data->offset = 0;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   670
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   671
  do_read (nego_msg_read_cb, data);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   672
}
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   673
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   674
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   675
static void
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   676
nego_msg_write_cb (GObject      *source,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   677
                   GAsyncResult *res,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   678
                   gpointer      user_data)
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   679
{
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   680
  GError *error = NULL;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   681
  ConnectAsyncData *data = user_data;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   682
  gssize written;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   683
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   684
  written = g_output_stream_write_finish (G_OUTPUT_STREAM (source),
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   685
                                          res, &error);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   686
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   687
  if (written < 0) {
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   688
    complete_async_from_error (data, error);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   689
    return;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   690
  }
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   691
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   692
  data->offset += written;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   693
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   694
  if (data->offset == data->length) {
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   695
    g_free (data->buffer);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   696
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   697
    data->buffer = g_malloc0 (SOCKS5_NEGO_REP_LEN);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   698
    data->length = SOCKS5_NEGO_REP_LEN;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   699
    data->offset = 0;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   700
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   701
    do_read (nego_reply_read_cb, data);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   702
  } else {
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   703
    do_write (nego_msg_write_cb, data);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   704
  }
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   705
}
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   706
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   707
static void
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   708
nego_msg_read_cb (GObject      *source,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   709
                  GAsyncResult *res,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   710
                  gpointer      user_data)
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   711
{
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   712
  GError *error = NULL;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   713
  ConnectAsyncData *data = user_data;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   714
  gssize read;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   715
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   716
  read = g_input_stream_read_finish (G_INPUT_STREAM (source),
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   717
                                     res, &error);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   718
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   719
  if (read < 0) {
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   720
    complete_async_from_error (data, error);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   721
    return;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   722
  }
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   723
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   724
  data->offset += read;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   725
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   726
  /* if the client already send at least NMETHODS, no need to
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   727
   * read until data->length, which is the max size */
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   728
  if ((data->offset >= 2 && data->offset-2 > data->buffer[2]) ||
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   729
      data->offset == data->length) {
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   730
    GError *error;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   731
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   732
    if (!server_parse_nego_init (data->buffer, data->offset, &error)) {
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   733
      if (g_error_matches (error, S5B_SOCKS5_ERROR, S5B_SOCKS5_ERROR_AUTH_FAILED)) {
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   734
        /* "If the selected METHOD is X'FF', none of the methods listed by the
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   735
           client are acceptable, and the client MUST close the connection." */
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   736
        g_free (data->buffer);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   737
        data->buffer = g_malloc0(SOCKS5_NEGO_REP_LEN);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   738
        data->length = server_set_nego_reply_msg(data->buffer, SOCKS5_AUTH_NO_ACCEPT);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   739
        data->offset = 0;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   740
        do_write (no_supported_method_cb, data);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   741
        return;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   742
	  }
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   743
      complete_async_from_error (data, error);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   744
      return;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   745
	}
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   746
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   747
    g_free (data->buffer);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   748
    data->buffer = g_malloc0 (SOCKS5_NEGO_REP_LEN);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   749
    data->length = server_set_nego_reply_msg (data->buffer, SOCKS5_AUTH_NONE);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   750
    data->offset = 0;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   751
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   752
    do_write (nego_reply_write_cb, data);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   753
  } else {
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   754
    do_read (nego_msg_read_cb, data);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   755
  }
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   756
}
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   757
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   758
static void
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   759
no_supported_method_cb (GObject      *source,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   760
                        GAsyncResult *res,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   761
                        gpointer      user_data)
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   762
{
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   763
  GError *error = NULL;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   764
  ConnectAsyncData *data = user_data;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   765
  gssize written;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   766
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   767
  written = g_output_stream_write_finish (G_OUTPUT_STREAM (source),
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   768
                                          res, &error);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   769
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   770
  if (written < 0) {
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   771
    complete_async_from_error (data, error);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   772
    return;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   773
  }
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   774
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   775
  data->offset += written;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   776
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   777
  if (data->offset == data->length) {
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   778
    GError *error;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   779
    error = g_error_new_literal (S5B_SOCKS5_ERROR, S5B_SOCKS5_ERROR_AUTH_FAILED,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   780
                                 "The client did not offer any authentication "
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   781
                                  "method we support.");
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   782
    complete_async_from_error (data, error);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   783
  } else {
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   784
    do_write(no_supported_method_cb, data);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   785
  }
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   786
}
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   787
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   788
static void
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   789
nego_reply_read_cb (GObject      *source,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   790
                    GAsyncResult *res,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   791
                    gpointer      user_data)
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   792
{
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   793
  GError *error = NULL;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   794
  ConnectAsyncData *data = user_data;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   795
  gssize read;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   796
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   797
  read = g_input_stream_read_finish (G_INPUT_STREAM (source),
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   798
                                     res, &error);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   799
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   800
  if (read < 0) {
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   801
    complete_async_from_error (data, error);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   802
    return;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   803
  }
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   804
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   805
  data->offset += read;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   806
  
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   807
  if (data->offset == data->length) {
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   808
    GError *error;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   809
    gboolean must_auth = FALSE;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   810
    gboolean has_auth = data->username || data->password;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   811
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   812
    if (!client_parse_nego_reply (data->buffer, has_auth, &must_auth, &error)) {
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   813
      complete_async_from_error (data, error);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   814
      return;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   815
    }
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   816
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   817
    if (must_auth) {
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   818
      g_free (data->buffer);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   819
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   820
      data->buffer = g_malloc0 (SOCKS5_AUTH_MSG_LEN);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   821
      data->length = set_auth_msg (data->buffer,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   822
                                   data->username,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   823
                                   data->password,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   824
                                   &error);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   825
      data->offset = 0;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   826
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   827
      if (data->length < 0) {
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   828
        complete_async_from_error (data, error);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   829
        return;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   830
      }
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   831
          
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   832
      do_write (auth_msg_write_cb, data);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   833
    } else {
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   834
      send_connect_msg (data);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   835
    }
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   836
  } else {
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   837
    do_read (nego_reply_read_cb, data);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   838
  }
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   839
}
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   840
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   841
static void
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   842
nego_reply_write_cb (GObject      *source,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   843
                     GAsyncResult *res,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   844
                     gpointer      user_data)
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   845
{
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   846
  GError *error = NULL;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   847
  ConnectAsyncData *data = user_data;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   848
  gssize written;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   849
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   850
  written = g_output_stream_write_finish (G_OUTPUT_STREAM (source),
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   851
                                          res, &error);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   852
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   853
  if (written < 0) {
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   854
    complete_async_from_error (data, error);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   855
    return;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   856
  }
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   857
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   858
  data->offset += written;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   859
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   860
  if (data->offset == data->length) {
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   861
    g_free (data->buffer);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   862
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   863
    data->buffer = g_malloc0 (SOCKS5_CONN_MSG_LEN);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   864
    data->length = 4;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   865
    data->offset = 0;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   866
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   867
    do_read (connect_msg_read_cb, data);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   868
  } else {
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   869
    do_write (nego_reply_write_cb, data);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   870
  }
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   871
}
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   872
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   873
static void
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   874
auth_msg_write_cb (GObject      *source,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   875
                   GAsyncResult *result,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   876
                   gpointer      user_data)
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   877
{
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   878
  GError *error = NULL;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   879
  ConnectAsyncData *data = user_data;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   880
  gssize written;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   881
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   882
  written = g_output_stream_write_finish (G_OUTPUT_STREAM (source),
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   883
                                          result, &error);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   884
  
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   885
  if (written < 0) {
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   886
    complete_async_from_error (data, error);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   887
    return;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   888
  }
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   889
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   890
  data->offset += written;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   891
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   892
  if (data->offset == data->length) {
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   893
    g_free (data->buffer);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   894
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   895
    data->buffer = g_malloc0 (SOCKS5_NEGO_REP_LEN);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   896
    data->length = SOCKS5_NEGO_REP_LEN;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   897
    data->offset = 0;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   898
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   899
    do_read (auth_reply_read_cb, data);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   900
  } else {
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   901
    do_write (auth_msg_write_cb, data);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   902
  }
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   903
}
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   904
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   905
static void
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   906
auth_reply_read_cb (GObject      *source,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   907
                    GAsyncResult *result,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   908
                    gpointer      user_data)
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   909
{
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   910
  GError *error = NULL;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   911
  ConnectAsyncData *data = user_data;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   912
  gssize read;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   913
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   914
  read = g_input_stream_read_finish (G_INPUT_STREAM (source),
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   915
                                     result, &error);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   916
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   917
  if (read < 0) {
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   918
    complete_async_from_error (data, error);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   919
    return;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   920
  }
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   921
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   922
  data->offset += read;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   923
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   924
  if (data->offset == data->length) {
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   925
    if (!check_auth_status (data->buffer, &error)) {
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   926
      complete_async_from_error (data, error);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   927
      return;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   928
    }
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   929
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   930
    send_connect_msg (data);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   931
  } else {
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   932
    do_read (auth_reply_read_cb, data);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   933
  }
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   934
}
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   935
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   936
static void
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   937
send_connect_msg (ConnectAsyncData *data)
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   938
{
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   939
  GError *error = NULL;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   940
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   941
  g_free (data->buffer);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   942
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   943
  data->buffer = g_malloc0 (SOCKS5_CONN_MSG_LEN);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   944
  data->length = client_set_connect_msg (data->buffer,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   945
                                         data->hostname,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   946
                                         S5B_DST_PORT,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   947
                                         &error);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   948
  data->offset = 0;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   949
  
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   950
  if (data->length < 0) {
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   951
    complete_async_from_error (data, error);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   952
    return;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   953
  }
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   954
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   955
  do_write (connect_msg_write_cb, data);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   956
}
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   957
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   958
static void
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   959
connect_msg_write_cb (GObject      *source,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   960
                      GAsyncResult *result,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   961
                      gpointer      user_data)
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   962
{
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   963
  GError *error = NULL;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   964
  ConnectAsyncData *data = user_data;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   965
  gssize written;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   966
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   967
  written = g_output_stream_write_finish (G_OUTPUT_STREAM (source),
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   968
                                          result, &error);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   969
  
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   970
  if (written < 0) {
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   971
    complete_async_from_error (data, error);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   972
    return;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   973
  }
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   974
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   975
  data->offset += written;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   976
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   977
  if (data->offset == data->length) {
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   978
    g_free (data->buffer);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   979
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   980
    data->buffer = g_malloc0 (SOCKS5_CONN_REP_LEN);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   981
    data->length = 4;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   982
    data->offset = 0;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   983
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   984
    do_read (connect_reply_read_cb, data);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   985
  } else {
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   986
    do_write (connect_msg_write_cb, data);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   987
  }
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   988
}
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   989
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   990
static void
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   991
connect_msg_read_cb (GObject      *source,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   992
                     GAsyncResult *result,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   993
                     gpointer      user_data)
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   994
{
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   995
  GError *error = NULL;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   996
  ConnectAsyncData *data = user_data;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   997
  gssize read;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   998
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
   999
  read = g_input_stream_read_finish (G_INPUT_STREAM (source),
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1000
                                     result, &error);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1001
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1002
  if (read < 0) {
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1003
    complete_async_from_error (data, error);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1004
    return;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1005
  }
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1006
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1007
  data->offset += read;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1008
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1009
  if (data->offset == data->length) {
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1010
    gint atype;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1011
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1012
    if (!server_parse_connect_msg (data->buffer, &atype, &error)) {
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1013
      complete_async_from_error (data, error);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1014
      return;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1015
    }
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1016
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1017
    switch (atype) {
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1018
      case SOCKS5_ATYP_DOMAINNAME:
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1019
        data->length = 1;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1020
        data->offset = 0;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1021
        do_read (connect_addr_len_read_cb, data);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1022
        break;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1023
      default:
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1024
        g_set_error_literal (&error, S5B_SOCKS5_ERROR, S5B_SOCKS5_ERROR_FAILED,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1025
                             "This SOCKSv5 server implementation only support "
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1026
                             "DOMAINNAME addresses.");
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1027
        complete_async_from_error (data, error);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1028
        return;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1029
    }
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1030
  } else {
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1031
    do_read (connect_msg_read_cb, data);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1032
  }
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1033
}
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1034
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1035
static void
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1036
connect_addr_len_read_cb (GObject      *source,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1037
                          GAsyncResult *result,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1038
                          gpointer      user_data)
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1039
{
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1040
  GError *error = NULL;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1041
  ConnectAsyncData *data = user_data;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1042
  gssize read;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1043
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1044
  read = g_input_stream_read_finish (G_INPUT_STREAM (source),
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1045
                                     result, &error);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1046
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1047
  if (read < 0) {
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1048
    complete_async_from_error (data, error);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1049
    return;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1050
  }
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1051
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1052
  data->length = data->buffer[0] + 2;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1053
  data->offset = 0;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1054
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1055
  do_read (connect_addr_read_cb, data);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1056
}
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1057
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1058
static void
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1059
connect_addr_read_cb (GObject      *source,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1060
                      GAsyncResult *result,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1061
                      gpointer      user_data)
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1062
{
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1063
  GError *error = NULL;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1064
  ConnectAsyncData *data = user_data;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1065
  gssize read;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1066
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1067
  read = g_input_stream_read_finish (G_INPUT_STREAM (source),
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1068
                                     result, &error);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1069
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1070
  if (read < 0) {
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1071
    complete_async_from_error (data, error);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1072
    return;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1073
  }
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1074
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1075
  data->offset += read;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1076
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1077
  if (data->offset == data->length) {
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1078
    gchar *hostname = g_strndup ((gchar *)data->buffer, data->length-2);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1079
    if (!g_strcmp0 (data->hostname, hostname)) {
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1080
      guint8 atype;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1081
      GInetAddress *address = g_inet_socket_address_get_address (data->external_address);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1082
      g_free(data->buffer);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1083
      if (g_inet_address_get_family (address) == G_SOCKET_FAMILY_IPV4)
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1084
        atype = SOCKS5_ATYP_IPV4;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1085
      else
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1086
        atype = SOCKS5_ATYP_IPV6;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1087
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1088
      data->buffer = g_malloc0 (SOCKS5_CONN_REP_LEN);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1089
      data->length = server_set_connect_reply (data->buffer, SOCKS5_REP_SUCCEEDED,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1090
                                               atype, g_inet_address_to_bytes(address),
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1091
                                               g_inet_socket_address_get_port(data->external_address));
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1092
      data->offset = 0;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1093
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1094
      do_write (connect_reply_write_cb, data);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1095
	} else {
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1096
      // wrong hostname ! we should respond: X'02' connection not allowed by ruleset
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1097
      g_set_error_literal (&error, S5B_SOCKS5_ERROR, S5B_SOCKS5_ERROR_NOT_ALLOWED,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1098
                           "The client gave an invalid hostname");
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1099
      complete_async_from_error (data, error);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1100
	}
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1101
	g_free (hostname);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1102
  } else {
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1103
    do_read (connect_reply_read_cb, data);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1104
  }
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1105
}
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1106
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1107
static void
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1108
connect_reply_write_cb (GObject      *source,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1109
                        GAsyncResult *result,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1110
                        gpointer      user_data)
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1111
{
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1112
  GError *error = NULL;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1113
  ConnectAsyncData *data = user_data;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1114
  gssize written;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1115
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1116
  written = g_output_stream_write_finish (G_OUTPUT_STREAM (source),
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1117
                                          result, &error);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1118
  
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1119
  if (written < 0) {
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1120
    complete_async_from_error (data, error);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1121
    return;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1122
  }
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1123
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1124
  data->offset += written;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1125
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1126
  if (data->offset == data->length) {
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1127
    GSimpleAsyncResult *simple = data->simple;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1128
    g_simple_async_result_complete (simple);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1129
    g_object_unref (simple);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1130
  } else {
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1131
    do_write (connect_reply_write_cb, data);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1132
  }
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1133
}
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1134
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1135
static void
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1136
connect_reply_read_cb (GObject       *source,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1137
                       GAsyncResult  *result,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1138
                       gpointer       user_data)
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1139
{
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1140
  GError *error = NULL;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1141
  ConnectAsyncData *data = user_data;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1142
  gssize read;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1143
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1144
  read = g_input_stream_read_finish (G_INPUT_STREAM (source),
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1145
                                     result, &error);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1146
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1147
  if (read < 0) {
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1148
    complete_async_from_error (data, error);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1149
    return;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1150
  }
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1151
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1152
  data->offset += read;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1153
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1154
  if (data->offset == data->length) {
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1155
    gint atype;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1156
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1157
    if (!client_parse_connect_reply (data->buffer, &atype, &error)) {
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1158
      complete_async_from_error (data, error);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1159
      return;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1160
    }
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1161
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1162
    switch (atype) {
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1163
      case SOCKS5_ATYP_IPV4:
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1164
        data->length = 6;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1165
        data->offset = 0;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1166
        do_read (connect_reply_addr_read_cb, data);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1167
            break;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1168
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1169
      case SOCKS5_ATYP_IPV6:
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1170
        data->length = 18;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1171
        data->offset = 0;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1172
        do_read (connect_reply_addr_read_cb, data);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1173
        break;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1174
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1175
      case SOCKS5_ATYP_DOMAINNAME:
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1176
        data->length = 1;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1177
        data->offset = 0;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1178
        do_read (connect_reply_addr_len_read_cb, data);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1179
        break;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1180
    }
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1181
  } else {
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1182
    do_read (connect_reply_read_cb, data);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1183
  }
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1184
}
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1185
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1186
static void
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1187
connect_reply_addr_len_read_cb (GObject      *source,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1188
                                GAsyncResult *result,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1189
                                gpointer      user_data)
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1190
{
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1191
  GError *error = NULL;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1192
  ConnectAsyncData *data = user_data;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1193
  gssize read;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1194
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1195
  read = g_input_stream_read_finish (G_INPUT_STREAM (source),
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1196
                                     result, &error);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1197
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1198
  if (read < 0) {
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1199
    complete_async_from_error (data, error);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1200
    return;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1201
  }
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1202
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1203
  data->length = data->buffer[0] + 2;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1204
  data->offset = 0;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1205
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1206
  do_read (connect_addr_read_cb, data);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1207
}
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1208
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1209
static void
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1210
connect_reply_addr_read_cb (GObject      *source,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1211
                            GAsyncResult *result,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1212
                            gpointer      user_data)
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1213
{
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1214
  GError *error = NULL;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1215
  ConnectAsyncData *data = user_data;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1216
  gssize read;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1217
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1218
  read = g_input_stream_read_finish (G_INPUT_STREAM (source),
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1219
                                     result, &error);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1220
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1221
  if (read < 0) {
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1222
    complete_async_from_error (data, error);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1223
    return;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1224
  }
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1225
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1226
  data->offset += read;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1227
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1228
  if (data->offset == data->length) {
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1229
    GSimpleAsyncResult *simple = data->simple;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1230
    g_simple_async_result_complete (simple);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1231
    g_object_unref (simple);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1232
  } else {
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1233
    do_read (connect_reply_read_cb, data);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1234
  }
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1235
}
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1236
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1237
GIOStream *
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1238
g_socks5_proxy_connect_finish (GAsyncResult *result,
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1239
                               GError      **error)
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1240
{
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1241
  GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1242
  ConnectAsyncData *data = g_simple_async_result_get_op_res_gpointer (simple);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1243
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1244
  if (g_simple_async_result_propagate_error (simple, error))
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1245
    return NULL;
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1246
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1247
  return g_object_ref (data->io_stream);
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1248
}
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1249
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1250
GQuark s5b_proxy_error_quark(void)
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1251
{
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1252
  return g_quark_from_string("S5B_SOCKS5_ERROR");
f699f6b47613 S5B: SOCKSv5 implementation based on the one in the glib's git repository
Gu1 <gu1@aeroxteam.fr>
parents:
diff changeset
  1253
}