annotate lib/rfc2068.c @ 478:97fd5eb34be0

2004-6-6 Brian Masney <masneyb@gftp.org> * acinclude.m4 configure.in - added AC_TYPE_INTPTR_T that will define intptr_t if it does not exist on the system * lib/gftp.h lib/protocols.c lib/rfc959.c src/uicommon/gftpuicallbacks.c - added specify site argument to rfc959_site(). If this is set, then SITE will be prepended to the command
author masneyb
date Sun, 06 Jun 2004 15:12:35 +0000
parents 075f89b4395c
children 7334a74db6f6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1 /*****************************************************************************/
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2 /* rfc2068.c - General purpose routines for the HTTP protocol */
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
3 /* Copyright (C) 1998-2003 Brian Masney <masneyb@gftp.org> */
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
4 /* */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
5 /* This program is free software; you can redistribute it and/or modify */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
6 /* it under the terms of the GNU General Public License as published by */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
7 /* the Free Software Foundation; either version 2 of the License, or */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
8 /* (at your option) any later version. */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
9 /* */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
10 /* This program is distributed in the hope that it will be useful, */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
11 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
12 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
13 /* GNU General Public License for more details. */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
14 /* */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
15 /* You should have received a copy of the GNU General Public License */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
16 /* along with this program; if not, write to the Free Software */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
17 /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
18 /*****************************************************************************/
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
19
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
20 #include "gftp.h"
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
21 #include "httpcommon.h"
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
22
33
c8ec7877432e 2002-10-06 Brian Masney <masneyb@gftp.org>
masneyb
parents: 14
diff changeset
23 static const char cvsid[] = "$Id$";
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
24
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
25 static gftp_config_vars config_vars[] =
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
26 {
227
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 219
diff changeset
27 {"", N_("HTTP"), gftp_option_type_notebook, NULL, NULL,
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 219
diff changeset
28 GFTP_CVARS_FLAGS_SHOW_BOOKMARK, NULL, GFTP_PORT_GTK, NULL},
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
29
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
30 {"http_proxy_host", N_("Proxy hostname:"),
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
31 gftp_option_type_text, "", NULL, 0,
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
32 N_("Firewall hostname"), GFTP_PORT_ALL, 0},
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
33 {"http_proxy_port", N_("Proxy port:"),
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
34 gftp_option_type_int, GINT_TO_POINTER(80), NULL, 0,
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
35 N_("Port to connect to on the firewall"), GFTP_PORT_ALL, NULL},
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
36 {"http_proxy_username", N_("Proxy username:"),
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
37 gftp_option_type_text, "", NULL, 0,
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
38 N_("Your firewall username"), GFTP_PORT_ALL, NULL},
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
39 {"http_proxy_password", N_("Proxy password:"),
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
40 gftp_option_type_hidetext, "", NULL, 0,
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
41 N_("Your firewall password"), GFTP_PORT_ALL, NULL},
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
42
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
43 {"use_http11", N_("Use HTTP/1.1"),
227
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 219
diff changeset
44 gftp_option_type_checkbox, GINT_TO_POINTER(1), NULL,
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 219
diff changeset
45 GFTP_CVARS_FLAGS_SHOW_BOOKMARK,
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
46 N_("Do you want to use HTTP/1.1 or HTTP/1.0"), GFTP_PORT_ALL, NULL},
227
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 219
diff changeset
47
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
48 {NULL, NULL, 0, NULL, NULL, 0, NULL, 0, NULL}
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
49 };
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
50
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
51
219
b9584a877daf 2003-7-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 215
diff changeset
52 static int
b9584a877daf 2003-7-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 215
diff changeset
53 rfc2068_connect (gftp_request * request)
b9584a877daf 2003-7-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 215
diff changeset
54 {
b9584a877daf 2003-7-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 215
diff changeset
55 char *proxy_hostname, *proxy_config;
b9584a877daf 2003-7-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 215
diff changeset
56 rfc2068_params * params;
325
0fcc6468a0af 2003-12-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 309
diff changeset
57 intptr_t proxy_port;
0fcc6468a0af 2003-12-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 309
diff changeset
58 int ret;
219
b9584a877daf 2003-7-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 215
diff changeset
59
b9584a877daf 2003-7-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 215
diff changeset
60 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
b9584a877daf 2003-7-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 215
diff changeset
61 g_return_val_if_fail (request->hostname != NULL, GFTP_EFATAL);
b9584a877daf 2003-7-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 215
diff changeset
62
b9584a877daf 2003-7-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 215
diff changeset
63 params = request->protocol_data;
b9584a877daf 2003-7-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 215
diff changeset
64
b9584a877daf 2003-7-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 215
diff changeset
65 if (request->datafd > 0)
b9584a877daf 2003-7-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 215
diff changeset
66 return (0);
b9584a877daf 2003-7-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 215
diff changeset
67
b9584a877daf 2003-7-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 215
diff changeset
68 gftp_lookup_request_option (request, "proxy_config", &proxy_config);
b9584a877daf 2003-7-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 215
diff changeset
69 gftp_lookup_request_option (request, "http_proxy_host", &proxy_hostname);
b9584a877daf 2003-7-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 215
diff changeset
70 gftp_lookup_request_option (request, "http_proxy_port", &proxy_port);
b9584a877daf 2003-7-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 215
diff changeset
71
b9584a877daf 2003-7-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 215
diff changeset
72 if (proxy_config != NULL && strcmp (proxy_config, "ftp") == 0)
b9584a877daf 2003-7-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 215
diff changeset
73 {
b9584a877daf 2003-7-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 215
diff changeset
74 g_free (request->url_prefix);
b9584a877daf 2003-7-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 215
diff changeset
75 request->url_prefix = g_strdup ("ftp");
b9584a877daf 2003-7-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 215
diff changeset
76 }
b9584a877daf 2003-7-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 215
diff changeset
77
b9584a877daf 2003-7-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 215
diff changeset
78 if ((ret = gftp_connect_server (request, request->url_prefix, proxy_hostname,
b9584a877daf 2003-7-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 215
diff changeset
79 proxy_port)) < 0)
b9584a877daf 2003-7-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 215
diff changeset
80 return (ret);
b9584a877daf 2003-7-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 215
diff changeset
81
b9584a877daf 2003-7-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 215
diff changeset
82 if (request->directory && *request->directory == '\0')
b9584a877daf 2003-7-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 215
diff changeset
83 {
b9584a877daf 2003-7-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 215
diff changeset
84 g_free (request->directory);
b9584a877daf 2003-7-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 215
diff changeset
85 request->directory = NULL;
b9584a877daf 2003-7-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 215
diff changeset
86 }
b9584a877daf 2003-7-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 215
diff changeset
87
b9584a877daf 2003-7-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 215
diff changeset
88 if (!request->directory)
b9584a877daf 2003-7-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 215
diff changeset
89 request->directory = g_strdup ("/");
b9584a877daf 2003-7-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 215
diff changeset
90
b9584a877daf 2003-7-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 215
diff changeset
91 return (0);
b9584a877daf 2003-7-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 215
diff changeset
92 }
b9584a877daf 2003-7-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 215
diff changeset
93
b9584a877daf 2003-7-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 215
diff changeset
94
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
95 static off_t
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
96 rfc2068_read_response (gftp_request * request)
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
97 {
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
98 rfc2068_params * params;
207
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
99 char tempstr[8192];
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
100 int ret, chunked;
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
101
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
102 params = request->protocol_data;
209
d79e2782eb1b 2003-7-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
103 *tempstr = '\0';
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
104 chunked = 0;
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
105 params->chunk_size = 0;
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
106 params->content_length = 0;
209
d79e2782eb1b 2003-7-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
107 params->eof = 0;
207
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
108
105
ae13b18c9336 2003-2-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 102
diff changeset
109 if (request->last_ftp_response)
ae13b18c9336 2003-2-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 102
diff changeset
110 {
ae13b18c9336 2003-2-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 102
diff changeset
111 g_free (request->last_ftp_response);
ae13b18c9336 2003-2-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 102
diff changeset
112 request->last_ftp_response = NULL;
ae13b18c9336 2003-2-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 102
diff changeset
113 }
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
114
207
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
115 if (params->extra_read_buffer != NULL)
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
116 {
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
117 g_free (params->extra_read_buffer);
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
118 params->extra_read_buffer = NULL;
209
d79e2782eb1b 2003-7-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
119 params->extra_read_buffer_len = 0;
207
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
120 }
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
121
105
ae13b18c9336 2003-2-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 102
diff changeset
122 do
ae13b18c9336 2003-2-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 102
diff changeset
123 {
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
124 if ((ret = gftp_get_line (request, &params->rbuf, tempstr,
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
125 sizeof (tempstr), request->datafd)) < 0)
105
ae13b18c9336 2003-2-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 102
diff changeset
126 return (ret);
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
127
105
ae13b18c9336 2003-2-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 102
diff changeset
128 if (request->last_ftp_response == NULL)
ae13b18c9336 2003-2-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 102
diff changeset
129 request->last_ftp_response = g_strdup (tempstr);
ae13b18c9336 2003-2-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 102
diff changeset
130
ae13b18c9336 2003-2-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 102
diff changeset
131 if (*tempstr != '\0')
ae13b18c9336 2003-2-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 102
diff changeset
132 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 177
diff changeset
133 request->logging_function (gftp_logging_recv, request, "%s\n",
105
ae13b18c9336 2003-2-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 102
diff changeset
134 tempstr);
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
135
105
ae13b18c9336 2003-2-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 102
diff changeset
136 if (strncmp (tempstr, "Content-Length:", 15) == 0)
244
afbbc72b73e2 2003-8-3 Brian Masney <masneyb@gftp.org>
masneyb
parents: 227
diff changeset
137 params->content_length = gftp_parse_file_size (tempstr + 16);
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
138 else if (strcmp (tempstr, "Transfer-Encoding: chunked") == 0)
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
139 chunked = 1;
105
ae13b18c9336 2003-2-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 102
diff changeset
140 }
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
141 }
105
ae13b18c9336 2003-2-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 102
diff changeset
142 while (*tempstr != '\0');
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
143
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
144 if (chunked)
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
145 {
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
146 if ((ret = gftp_get_line (request, &params->rbuf, tempstr,
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
147 sizeof (tempstr), request->datafd)) < 0)
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
148 return (ret);
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
149
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
150 if (sscanf ((char *) tempstr, "%lx", &params->chunk_size) != 1)
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
151 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 177
diff changeset
152 request->logging_function (gftp_logging_recv, request,
209
d79e2782eb1b 2003-7-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
153 _("Received wrong response from server, disconnecting\nInvalid chunk size '%s' returned by the remote server\n"),
d79e2782eb1b 2003-7-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
154 tempstr);
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
155 gftp_disconnect (request);
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
156 return (GFTP_EFATAL);
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
157 }
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
158
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
159 if (params->chunk_size == 0)
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
160 return (0);
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
161
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
162 params->chunk_size -= params->rbuf->cur_bufsize;
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
163 if (params->chunk_size < 0)
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
164 {
207
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
165 params->extra_read_buffer_len = params->chunk_size * -1;
209
d79e2782eb1b 2003-7-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
166 params->chunk_size = 0;
207
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
167 params->extra_read_buffer = g_malloc (params->extra_read_buffer_len + 1);
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
168 memcpy (params->extra_read_buffer, params->rbuf->curpos + (params->rbuf->cur_bufsize - params->extra_read_buffer_len), params->extra_read_buffer_len);
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
169 params->extra_read_buffer[params->extra_read_buffer_len] = '\0';
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
170 params->rbuf->cur_bufsize -= params->extra_read_buffer_len;
209
d79e2782eb1b 2003-7-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
171 params->rbuf->curpos[params->rbuf->cur_bufsize] = '\0';
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
172 }
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
173 }
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
174
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
175 params->chunked_transfer = chunked;
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
176 return (params->content_length > 0 ? params->content_length : params->chunk_size);
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
177 }
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
178
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
179
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
180 static off_t
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
181 rfc2068_send_command (gftp_request * request, const void *command, size_t len)
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
182 {
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
183 char *tempstr, *str, *proxy_hostname, *proxy_username, *proxy_password;
325
0fcc6468a0af 2003-12-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 309
diff changeset
184 intptr_t proxy_port;
0fcc6468a0af 2003-12-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 309
diff changeset
185 int conn_ret;
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
186 ssize_t ret;
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
187
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
188 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
189 g_return_val_if_fail (command != NULL, GFTP_EFATAL);
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
190
219
b9584a877daf 2003-7-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 215
diff changeset
191 if (request->datafd < 0 && (conn_ret = rfc2068_connect (request)) != 0)
b9584a877daf 2003-7-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 215
diff changeset
192 return (conn_ret);
b9584a877daf 2003-7-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 215
diff changeset
193
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
194 tempstr = g_strdup_printf ("%sUser-Agent: %s\nHost: %s\n", (char *) command,
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
195 gftp_version, request->hostname);
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
196
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 177
diff changeset
197 request->logging_function (gftp_logging_send, request,
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
198 "%s", tempstr);
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
199
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
200 ret = request->write_function (request, tempstr, strlen (tempstr),
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
201 request->datafd);
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
202 g_free (tempstr);
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
203
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
204 if (ret < 0)
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
205 return (ret);
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
206
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
207 gftp_lookup_request_option (request, "http_proxy_host", &proxy_hostname);
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
208 gftp_lookup_request_option (request, "http_proxy_port", &proxy_port);
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
209 gftp_lookup_request_option (request, "http_proxy_username", &proxy_username);
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
210 gftp_lookup_request_option (request, "http_proxy_password", &proxy_password);
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
211
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
212 if (request->use_proxy && proxy_username != NULL && *proxy_username != '\0')
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
213 {
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
214 tempstr = g_strconcat (proxy_username, ":", proxy_password, NULL);
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
215 str = base64_encode (tempstr);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
216 g_free (tempstr);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
217
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 177
diff changeset
218 request->logging_function (gftp_logging_send, request,
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
219 "Proxy-authorization: Basic xxxx:xxxx\n");
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
220 ret = gftp_writefmt (request, request->datafd,
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
221 "Proxy-authorization: Basic %s\n", str);
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
222 g_free (str);
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
223 if (ret < 0)
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
224 return (ret);
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
225 }
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
226
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
227 if (request->username != NULL && *request->username != '\0')
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
228 {
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
229 tempstr = g_strconcat (request->username, ":", request->password, NULL);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
230 str = base64_encode (tempstr);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
231 g_free (tempstr);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
232
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 177
diff changeset
233 request->logging_function (gftp_logging_send, request,
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
234 "Authorization: Basic xxxx\n");
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
235 ret = gftp_writefmt (request, request->datafd,
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
236 "Authorization: Basic %s\n", str);
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
237 g_free (str);
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
238 if (ret < 0)
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
239 return (ret);
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
240 }
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
241
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
242 if ((ret = request->write_function (request, "\n", 1, request->datafd)) < 0)
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
243 return (ret);
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
244
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
245 return (rfc2068_read_response (request));
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
246 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
247
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
248
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
249 static void
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
250 rfc2068_disconnect (gftp_request * request)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
251 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
252 g_return_if_fail (request != NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
253
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
254 if (request->datafd > 0)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
255 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 177
diff changeset
256 request->logging_function (gftp_logging_misc, request,
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
257 _("Disconnecting from site %s\n"),
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
258 request->hostname);
14
83090328581e * More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents: 7
diff changeset
259
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
260 if (close (request->datafd) < 0)
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 177
diff changeset
261 request->logging_function (gftp_logging_error, request,
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
262 _("Error closing file descriptor: %s\n"),
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
263 g_strerror (errno));
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
264
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
265 request->datafd = -1;
14
83090328581e * More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents: 7
diff changeset
266 }
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
267 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
268
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
269
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
270 static off_t
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
271 rfc2068_get_file (gftp_request * request, const char *filename, int fd,
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
272 off_t startsize)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
273 {
303
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
274 char *tempstr, *oldstr, *hf;
460
075f89b4395c 2004-4-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 427
diff changeset
275 rfc2068_params * params;
325
0fcc6468a0af 2003-12-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 309
diff changeset
276 intptr_t use_http11;
460
075f89b4395c 2004-4-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 427
diff changeset
277 int restarted;
075f89b4395c 2004-4-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 427
diff changeset
278 size_t len;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
279 off_t size;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
280
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
281 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
282 g_return_val_if_fail (filename != NULL, GFTP_EFATAL);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
283
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
284 params = request->protocol_data;
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
285
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
286 gftp_lookup_request_option (request, "use_http11", &use_http11);
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
287
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
288 if (fd > 0)
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
289 request->datafd = fd;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
290
303
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
291 hf = gftp_build_path (request->hostname, filename, NULL);
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
292
7
5551ab2301fe * Fixed a DND crash
masneyb
parents: 1
diff changeset
293 if (request->username == NULL || *request->username == '\0')
303
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
294 tempstr = g_strconcat ("GET ", request->url_prefix, "://", hf,
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
295 use_http11 ? " HTTP/1.1\n" : " HTTP/1.0\n", NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
296 else
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
297 tempstr = g_strconcat ("GET ", request->url_prefix, "://",
303
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
298 request->username, "@", hf,
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
299 use_http11 ? " HTTP/1.1\n" : " HTTP/1.0\n", NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
300
303
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
301 g_free (hf);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
302
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
303 if (use_http11 && startsize > 0)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
304 {
14
83090328581e * More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents: 7
diff changeset
305 #if defined (_LARGEFILE_SOURCE)
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 177
diff changeset
306 request->logging_function (gftp_logging_misc, request,
14
83090328581e * More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents: 7
diff changeset
307 _("Starting the file transfer at offset %lld\n"),
372
44b792841e3f 2003-1-18 Brian Masney <masneyb@gftp.org>
masneyb
parents: 369
diff changeset
308 (long long) startsize);
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
309
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
310 oldstr = tempstr;
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
311 tempstr = g_strdup_printf ("%sRange: bytes=%lld-\n", tempstr, startsize);
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
312 g_free (oldstr);
14
83090328581e * More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents: 7
diff changeset
313 #else
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 177
diff changeset
314 request->logging_function (gftp_logging_misc, request,
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
315 _("Starting the file transfer at offset %ld\n"),
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
316 startsize);
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
317
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
318 oldstr = tempstr;
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
319 tempstr = g_strdup_printf ("%sRange: bytes=%ld-\n", tempstr, startsize);
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
320 g_free (oldstr);
14
83090328581e * More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents: 7
diff changeset
321 #endif
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
322 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
323
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
324 size = rfc2068_send_command (request, tempstr, strlen (tempstr));
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
325 g_free (tempstr);
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
326 if (size < 0)
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
327 return (size);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
328
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
329 restarted = 0;
460
075f89b4395c 2004-4-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 427
diff changeset
330 len = strlen (request->last_ftp_response);
075f89b4395c 2004-4-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 427
diff changeset
331 if (len > 9 && strncmp (request->last_ftp_response + 9, "206", 3) == 0)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
332 restarted = 1;
460
075f89b4395c 2004-4-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 427
diff changeset
333 else if (len < 9 || strncmp (request->last_ftp_response + 9, "200", 3) != 0)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
334 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 177
diff changeset
335 request->logging_function (gftp_logging_error, request,
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
336 _("Cannot retrieve file %s\n"), filename);
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
337 return (GFTP_ERETRYABLE);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
338 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
339
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
340 params->read_bytes = 0;
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
341
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
342 return (restarted ? size + startsize : size);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
343 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
344
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
345
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
346 static ssize_t
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
347 rfc2068_get_next_file_chunk (gftp_request * request, char *buf, size_t size)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
348 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
349 rfc2068_params * params;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
350 size_t len;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
351
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
352 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
353
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
354 params = request->protocol_data;
304
95bcb77d62c1 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 303
diff changeset
355 if (params->rbuf != NULL && params->rbuf->curpos != NULL)
95bcb77d62c1 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 303
diff changeset
356 {
95bcb77d62c1 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 303
diff changeset
357 len = params->rbuf->cur_bufsize > size ? size : params->rbuf->cur_bufsize;
95bcb77d62c1 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 303
diff changeset
358 memcpy (buf, params->rbuf->curpos, len);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
359
304
95bcb77d62c1 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 303
diff changeset
360 if (len == params->rbuf->cur_bufsize)
95bcb77d62c1 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 303
diff changeset
361 gftp_free_getline_buffer (&params->rbuf);
95bcb77d62c1 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 303
diff changeset
362 else
95bcb77d62c1 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 303
diff changeset
363 {
95bcb77d62c1 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 303
diff changeset
364 params->rbuf->curpos += len;
95bcb77d62c1 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 303
diff changeset
365 params->rbuf->cur_bufsize -= len;
95bcb77d62c1 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 303
diff changeset
366 }
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
367
304
95bcb77d62c1 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 303
diff changeset
368 return (len);
95bcb77d62c1 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 303
diff changeset
369 }
95bcb77d62c1 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 303
diff changeset
370
95bcb77d62c1 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 303
diff changeset
371 return (request->read_function (request, buf, size, request->datafd));
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
372 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
373
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
374
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
375 static int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
376 rfc2068_end_transfer (gftp_request * request)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
377 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
378 rfc2068_params * params;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
379
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
380 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
381
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
382 if (request->datafd < 0)
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
383 return (GFTP_EFATAL);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
384
207
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
385 gftp_disconnect (request);
14
83090328581e * More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents: 7
diff changeset
386
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
387 params = request->protocol_data;
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
388 params->content_length = 0;
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
389 params->chunked_transfer = 0;
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
390 params->chunk_size = 0;
209
d79e2782eb1b 2003-7-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
391 params->eof = 0;
14
83090328581e * More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents: 7
diff changeset
392
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
393 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
394 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
395
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
396
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
397 static int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
398 rfc2068_list_files (gftp_request * request)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
399 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
400 rfc2068_params *params;
303
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
401 char *tempstr, *hd;
325
0fcc6468a0af 2003-12-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 309
diff changeset
402 intptr_t use_http11;
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
403 off_t ret;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
404
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
405 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
406
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
407 params = request->protocol_data;
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
408 gftp_lookup_request_option (request, "use_http11", &use_http11);
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
409
369
c63208a1f0f1 2003-1-18 Brian Masney <masneyb@gftp.org>
masneyb
parents: 341
diff changeset
410 if (strncmp (request->directory, "/", strlen (request->directory)) == 0)
c63208a1f0f1 2003-1-18 Brian Masney <masneyb@gftp.org>
masneyb
parents: 341
diff changeset
411 hd = g_strdup (request->hostname);
c63208a1f0f1 2003-1-18 Brian Masney <masneyb@gftp.org>
masneyb
parents: 341
diff changeset
412 else
c63208a1f0f1 2003-1-18 Brian Masney <masneyb@gftp.org>
masneyb
parents: 341
diff changeset
413 hd = gftp_build_path (request->hostname, request->directory, NULL);
303
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
414
7
5551ab2301fe * Fixed a DND crash
masneyb
parents: 1
diff changeset
415 if (request->username == NULL || *request->username == '\0')
303
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
416 tempstr = g_strconcat ("GET ", request->url_prefix, "://", hd,
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
417 use_http11 ? "/ HTTP/1.1\n" : "/ HTTP/1.0\n", NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
418 else
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
419 tempstr = g_strconcat ("GET ", request->url_prefix, "://",
303
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
420 request->username, "@", hd,
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
421 use_http11 ? "/ HTTP/1.1\n" : "/ HTTP/1.0\n", NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
422
303
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
423 g_free (hd);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
424
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
425 ret = rfc2068_send_command (request, tempstr, strlen (tempstr));
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
426 g_free (tempstr);
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
427 if (ret < 0)
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
428 return ((int) ret);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
429
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
430 params->read_bytes = 0;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
431 if (strlen (request->last_ftp_response) > 9 &&
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
432 strncmp (request->last_ftp_response + 9, "200", 3) == 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
433 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 177
diff changeset
434 request->logging_function (gftp_logging_misc, request,
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
435 _("Retrieving directory listing...\n"));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
436 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
437 }
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
438
207
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
439 gftp_end_transfer (request);
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
440
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
441 return (GFTP_ERETRYABLE);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
442 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
443
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
444
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
445 static off_t
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
446 rfc2068_get_file_size (gftp_request * request, const char *filename)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
447 {
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
448 rfc2068_params *params;
303
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
449 char *tempstr, *hf;
325
0fcc6468a0af 2003-12-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 309
diff changeset
450 intptr_t use_http11;
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
451 off_t size;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
452
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
453 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
454 g_return_val_if_fail (filename != NULL, GFTP_EFATAL);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
455
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
456 params = request->protocol_data;
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
457 gftp_lookup_request_option (request, "use_http11", &use_http11);
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
458
303
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
459 hf = gftp_build_path (request->hostname, filename, NULL);
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
460
7
5551ab2301fe * Fixed a DND crash
masneyb
parents: 1
diff changeset
461 if (request->username == NULL || *request->username == '\0')
303
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
462 tempstr = g_strconcat ("HEAD ", request->url_prefix, "://", hf,
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
463 use_http11 ? " HTTP/1.1\n" : " HTTP/1.0\n", NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
464 else
219
b9584a877daf 2003-7-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 215
diff changeset
465 tempstr = g_strconcat ("HEAD ", request->url_prefix, "://",
303
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
466 request->username, "@", hf,
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
467 use_http11 ? " HTTP/1.1\n" : " HTTP/1.0\n", NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
468
303
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
469 g_free (hf);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
470
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
471 size = rfc2068_send_command (request, tempstr, strlen (tempstr));
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
472 g_free (tempstr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
473 return (size);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
474 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
475
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
476
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
477 static int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
478 parse_html_line (char *tempstr, gftp_file * fle)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
479 {
207
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
480 char *stpos, *kpos, *mpos, *pos;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
481 long units;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
482
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
483 memset (fle, 0, sizeof (*fle));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
484
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
485 if ((pos = strstr (tempstr, "<A HREF=")) == NULL &&
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
486 (pos = strstr (tempstr, "<a href=")) == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
487 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
488
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
489 /* Find the filename */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
490 while (*pos != '"' && *pos != '\0')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
491 pos++;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
492 if (*pos == '\0')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
493 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
494 pos++;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
495
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
496 for (stpos = pos; *pos != '"' && *pos != '\0'; pos++);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
497 if (*pos == '\0')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
498 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
499 *pos = '\0';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
500
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
501 /* Copy file attributes. Just about the only thing we can get is whether it
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
502 is a directory or not */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
503 if (*(pos - 1) == '/')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
504 {
336
e0c22c0d9106 2003-12-10 Brian Masney <masneyb@gftp.org>
masneyb
parents: 325
diff changeset
505 fle->attribs = g_strdup ("drwxr-xr-x");
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
506 *(pos - 1) = '\0';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
507 fle->isdir = 1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
508 }
336
e0c22c0d9106 2003-12-10 Brian Masney <masneyb@gftp.org>
masneyb
parents: 325
diff changeset
509 else
e0c22c0d9106 2003-12-10 Brian Masney <masneyb@gftp.org>
masneyb
parents: 325
diff changeset
510 fle->attribs = g_strdup ("-rw-r--r--");
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
511
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
512 /* Copy filename */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
513 if (strchr (stpos, '/') != NULL || strncmp (stpos, "mailto:", 7) == 0 ||
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
514 *stpos == '\0' || *stpos == '?')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
515 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
516
105
ae13b18c9336 2003-2-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 102
diff changeset
517 fle->file = g_strdup (stpos);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
518
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
519 if (*(pos - 1) == '\0')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
520 *(pos - 1) = '/';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
521 *pos = '"';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
522 pos++;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
523
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
524 /* Skip whitespace and html tags after file and before date */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
525 stpos = pos;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
526 if ((pos = strstr (stpos, "</A>")) == NULL &&
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
527 (pos = strstr (stpos, "</a>")) == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
528 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
529
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
530 pos += 4;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
531
105
ae13b18c9336 2003-2-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 102
diff changeset
532 while (*pos == ' ' || *pos == '\t' || *pos == '.' || *pos == '<')
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
533 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
534 if (*pos == '<')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
535 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
536 if (strncmp (pos, "<A ", 3) == 0 || strncmp (pos, "<a ", 3) == 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
537 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
538 stpos = pos;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
539 if ((pos = strstr (stpos, "</A>")) == NULL
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
540 && (pos = strstr (stpos, "</a>")) == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
541 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
542 pos += 4;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
543 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
544 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
545 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
546 while (*pos != '>' && *pos != '\0')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
547 pos++;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
548 if (*pos == '\0')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
549 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
550 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
551 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
552 pos++;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
553 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
554
102
3b573c8ef706 2003-2-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
555 if (*pos == '[')
3b573c8ef706 2003-2-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
556 pos++;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
557
102
3b573c8ef706 2003-2-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
558 fle->datetime = parse_time (pos, &pos);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
559
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
560 fle->user = g_strdup (_("<unknown>"));
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
561 fle->group = g_strdup (_("<unknown>"));
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
562
105
ae13b18c9336 2003-2-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 102
diff changeset
563 if (pos == NULL)
ae13b18c9336 2003-2-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 102
diff changeset
564 return (1);
ae13b18c9336 2003-2-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 102
diff changeset
565
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
566 while (*pos == ' ' || *pos == ']')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
567 pos++;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
568
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
569 /* Get the size */
207
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
570
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
571 kpos = strchr (pos, 'k');
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
572 mpos = strchr (pos, 'M');
427
3a83011227bc 2004-3-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 415
diff changeset
573
3a83011227bc 2004-3-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 415
diff changeset
574 if (kpos != NULL && (mpos == NULL || (kpos < mpos)))
207
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
575 stpos = kpos;
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
576 else
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
577 stpos = mpos;
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
578
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
579 if (stpos == NULL || !isdigit (*(stpos - 1)))
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
580 return (1); /* Return successfully
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
581 since we got the file */
207
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
582
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
583 if (*stpos == 'k')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
584 units = 1024;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
585 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
586 units = 1048576;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
587
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
588 fle->size = 0;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
589
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
590 while (*(stpos - 1) != ' ' && *(stpos - 1) != '\t' && stpos > tempstr)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
591 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
592 stpos--;
207
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
593 if ((*stpos == '.') && isdigit (*(stpos + 1)))
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
594 { /* found decimal point */
244
afbbc72b73e2 2003-8-3 Brian Masney <masneyb@gftp.org>
masneyb
parents: 227
diff changeset
595 fle->size = units * gftp_parse_file_size (stpos + 1) / 10;;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
596 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
597 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
598
244
afbbc72b73e2 2003-8-3 Brian Masney <masneyb@gftp.org>
masneyb
parents: 227
diff changeset
599 fle->size += units * gftp_parse_file_size (stpos);
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
600
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
601 return (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
602 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
603
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
604
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
605 int
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
606 rfc2068_get_next_file (gftp_request * request, gftp_file * fle, int fd)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
607 {
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
608 rfc2068_params * params;
219
b9584a877daf 2003-7-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 215
diff changeset
609 char tempstr[8192];
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
610 ssize_t len;
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
611 int ret;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
612
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
613 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
614 g_return_val_if_fail (fle != NULL, GFTP_EFATAL);
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
615
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
616 params = request->protocol_data;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
617 if (request->last_dir_entry)
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
618 {
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
619 g_free (request->last_dir_entry);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
620 request->last_dir_entry = NULL;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
621 }
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
622
105
ae13b18c9336 2003-2-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 102
diff changeset
623 if (fd < 0)
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
624 fd = request->datafd;
105
ae13b18c9336 2003-2-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 102
diff changeset
625
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
626 while (1)
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
627 {
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
628 if ((ret = gftp_get_line (request, &params->rbuf, tempstr, sizeof (tempstr), fd)) <= 0)
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
629 return (ret);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
630
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
631 if (parse_html_line (tempstr, fle) == 0 || fle->file == NULL)
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
632 gftp_file_destroy (fle);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
633 else
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
634 break;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
635 }
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
636
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
637 if (fle->file == NULL)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
638 {
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
639 gftp_file_destroy (fle);
105
ae13b18c9336 2003-2-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 102
diff changeset
640 return (0);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
641 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
642
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
643 len = strlen (tempstr);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
644 if (!request->cached)
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
645 {
60
8a9324fb63a4 2002-11-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 58
diff changeset
646 request->last_dir_entry = g_strdup_printf ("%s\n", tempstr);
8a9324fb63a4 2002-11-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 58
diff changeset
647 request->last_dir_entry_len = len + 1;
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
648 }
219
b9584a877daf 2003-7-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 215
diff changeset
649
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
650 return (len);
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
651 }
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
652
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
653
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
654 static int
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
655 rfc2068_chdir (gftp_request * request, const char *directory)
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
656 {
204
9b2de8d3fafe 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 201
diff changeset
657 char *tempstr, *olddir;
9b2de8d3fafe 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 201
diff changeset
658
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
659 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
660 g_return_val_if_fail (directory != NULL, GFTP_EFATAL);
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
661
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
662 if (request->directory != directory)
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
663 {
204
9b2de8d3fafe 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 201
diff changeset
664 olddir = request->directory;
9b2de8d3fafe 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 201
diff changeset
665
219
b9584a877daf 2003-7-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 215
diff changeset
666 if (*directory != '/' && request->directory != NULL)
204
9b2de8d3fafe 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 201
diff changeset
667 {
9b2de8d3fafe 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 201
diff changeset
668 tempstr = g_strconcat (request->directory, "/", directory, NULL);
9b2de8d3fafe 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 201
diff changeset
669 request->directory = expand_path (tempstr);
9b2de8d3fafe 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 201
diff changeset
670 g_free (tempstr);
9b2de8d3fafe 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 201
diff changeset
671 }
9b2de8d3fafe 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 201
diff changeset
672 else
9b2de8d3fafe 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 201
diff changeset
673 request->directory = expand_path (directory);
9b2de8d3fafe 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 201
diff changeset
674
9b2de8d3fafe 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 201
diff changeset
675 if (olddir != NULL)
9b2de8d3fafe 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 201
diff changeset
676 g_free (olddir);
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
677 }
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
678 return (0);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
679 }
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
680
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
681
177
aec4b4541d3a 2003-6-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 173
diff changeset
682 static int
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
683 rfc2068_set_config_options (gftp_request * request)
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
684 {
177
aec4b4541d3a 2003-6-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 173
diff changeset
685 return (0);
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
686 }
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
687
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
688
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
689 static void
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
690 rfc2068_destroy (gftp_request * request)
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
691 {
207
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
692 rfc2068_params * params;
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
693
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
694 params = request->protocol_data;
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
695
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
696 if (request->url_prefix)
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
697 {
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
698 g_free (request->url_prefix);
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
699 request->url_prefix = NULL;
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
700 }
207
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
701
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
702 if (params->rbuf != NULL)
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
703 gftp_free_getline_buffer (&params->rbuf);
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
704
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
705 if (params->extra_read_buffer != NULL)
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
706 {
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
707 g_free (params->extra_read_buffer);
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
708 params->extra_read_buffer = NULL;
209
d79e2782eb1b 2003-7-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
709 params->extra_read_buffer_len = 0;
207
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
710 }
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
711 }
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
712
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
713
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
714 static ssize_t
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
715 rfc2068_chunked_read (gftp_request * request, void *ptr, size_t size, int fd)
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
716 {
303
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
717 size_t read_size, begin_ptr_len, current_size, crlfsize;
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
718 rfc2068_params * params;
215
3d6e024dbf31 2003-7-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 209
diff changeset
719 char *stpos, *crlfpos;
209
d79e2782eb1b 2003-7-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
720 void *read_ptr_pos;
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
721 ssize_t retval;
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
722
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
723 params = request->protocol_data;
303
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
724 params->read_ref_cnt++;
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
725
207
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
726 if (params->extra_read_buffer != NULL)
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
727 {
209
d79e2782eb1b 2003-7-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
728 g_return_val_if_fail (params->extra_read_buffer_len <= size, GFTP_EFATAL);
d79e2782eb1b 2003-7-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
729
d79e2782eb1b 2003-7-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
730 memcpy (ptr, params->extra_read_buffer, params->extra_read_buffer_len);
d79e2782eb1b 2003-7-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
731
d79e2782eb1b 2003-7-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
732 begin_ptr_len = params->extra_read_buffer_len;
d79e2782eb1b 2003-7-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
733 read_ptr_pos = (char *) ptr + begin_ptr_len;
d79e2782eb1b 2003-7-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
734
d79e2782eb1b 2003-7-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
735 /* Check for end of chunk */
d79e2782eb1b 2003-7-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
736 if (begin_ptr_len > 5 && strncmp ("\r\n0\r\n", (char *) ptr, 5) == 0)
d79e2782eb1b 2003-7-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
737 read_size = 0;
d79e2782eb1b 2003-7-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
738 else
d79e2782eb1b 2003-7-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
739 read_size = size - begin_ptr_len;
d79e2782eb1b 2003-7-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
740
d79e2782eb1b 2003-7-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
741 g_free (params->extra_read_buffer);
d79e2782eb1b 2003-7-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
742 params->extra_read_buffer = NULL;
d79e2782eb1b 2003-7-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
743 params->extra_read_buffer_len = 0;
207
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
744 }
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
745 else
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
746 {
209
d79e2782eb1b 2003-7-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
747 begin_ptr_len = 0;
d79e2782eb1b 2003-7-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
748 read_ptr_pos = ptr;
d79e2782eb1b 2003-7-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
749
207
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
750 read_size = size;
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
751 if (params->content_length > 0)
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
752 {
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
753 if (params->content_length == params->read_bytes)
303
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
754 {
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
755 params->read_ref_cnt--;
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
756 return (0);
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
757 }
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
758
207
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
759 if (read_size + params->read_bytes > params->content_length)
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
760 read_size = params->content_length - params->read_bytes;
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
761 }
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
762 else if (params->chunked_transfer && params->chunk_size > 0 &&
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
763 params->chunk_size < read_size)
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
764 read_size = params->chunk_size;
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
765 }
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
766
209
d79e2782eb1b 2003-7-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
767 if (read_size > 0 && !params->eof)
d79e2782eb1b 2003-7-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
768 {
293
332beeff0b3d 2003-10-22 Brian Masney <masneyb@gftp.org>
masneyb
parents: 244
diff changeset
769 if (size == read_size)
332beeff0b3d 2003-10-22 Brian Masney <masneyb@gftp.org>
masneyb
parents: 244
diff changeset
770 read_size--; /* decrement by one so that we can put the NUL character
332beeff0b3d 2003-10-22 Brian Masney <masneyb@gftp.org>
masneyb
parents: 244
diff changeset
771 in the buffer */
332beeff0b3d 2003-10-22 Brian Masney <masneyb@gftp.org>
masneyb
parents: 244
diff changeset
772
303
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
773 retval = params->real_read_function (request, read_ptr_pos, read_size,
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
774 fd);
209
d79e2782eb1b 2003-7-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
775
303
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
776 if (retval <= 0)
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
777 {
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
778 params->read_ref_cnt--;
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
779 return (retval);
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
780 }
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
781 else if (retval > 0)
209
d79e2782eb1b 2003-7-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
782 params->read_bytes += retval;
d79e2782eb1b 2003-7-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
783
303
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
784 if (params->chunk_size > 0)
209
d79e2782eb1b 2003-7-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
785 {
d79e2782eb1b 2003-7-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
786 params->chunk_size -= retval;
303
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
787 params->read_ref_cnt--;
209
d79e2782eb1b 2003-7-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
788 return (retval);
d79e2782eb1b 2003-7-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
789 }
d79e2782eb1b 2003-7-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
790
d79e2782eb1b 2003-7-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
791 retval += begin_ptr_len;
d79e2782eb1b 2003-7-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
792 }
d79e2782eb1b 2003-7-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
793 else
d79e2782eb1b 2003-7-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
794 retval = begin_ptr_len;
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
795
215
3d6e024dbf31 2003-7-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 209
diff changeset
796 ((char *) ptr)[retval] = '\0';
3d6e024dbf31 2003-7-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 209
diff changeset
797
303
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
798 if (!params->chunked_transfer)
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
799 {
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
800 params->read_ref_cnt--;
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
801 return (retval);
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
802 }
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
803
209
d79e2782eb1b 2003-7-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
804 stpos = (char *) ptr;
d79e2782eb1b 2003-7-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
805 while (params->chunk_size == 0)
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
806 {
215
3d6e024dbf31 2003-7-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 209
diff changeset
807 current_size = retval - (stpos - (char *) ptr);
303
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
808 if (current_size == 0)
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
809 break;
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
810
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
811 if (*stpos == '\r' && *(stpos + 1) == '\n')
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
812 crlfpos = strstr (stpos + 2, "\r\n");
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
813 else
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
814 crlfpos = NULL;
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
815
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
816 if (crlfpos == NULL)
215
3d6e024dbf31 2003-7-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 209
diff changeset
817 {
3d6e024dbf31 2003-7-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 209
diff changeset
818 /* The current chunk size is split between multiple packets.
3d6e024dbf31 2003-7-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 209
diff changeset
819 Save this chunk and read the next */
3d6e024dbf31 2003-7-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 209
diff changeset
820
3d6e024dbf31 2003-7-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 209
diff changeset
821 params->extra_read_buffer = g_malloc (current_size + 1);
3d6e024dbf31 2003-7-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 209
diff changeset
822 memcpy (params->extra_read_buffer, stpos, current_size);
3d6e024dbf31 2003-7-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 209
diff changeset
823 params->extra_read_buffer[current_size] = '\0';
3d6e024dbf31 2003-7-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 209
diff changeset
824 params->extra_read_buffer_len = current_size;
3d6e024dbf31 2003-7-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 209
diff changeset
825 retval -= current_size;
3d6e024dbf31 2003-7-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 209
diff changeset
826
3d6e024dbf31 2003-7-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 209
diff changeset
827 if (retval == 0)
303
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
828 {
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
829 /* Don't let a hostile web server send us in an infinite recursive
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
830 loop */
215
3d6e024dbf31 2003-7-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 209
diff changeset
831
303
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
832 if (params->read_ref_cnt > 2)
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
833 {
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
834 request->logging_function (gftp_logging_error, request, _("Received wrong response from server, disconnecting\n"));
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
835 gftp_disconnect (request);
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
836 params->read_ref_cnt--;
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
837 return (GFTP_EFATAL);
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
838 }
209
d79e2782eb1b 2003-7-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
839
303
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
840 retval = rfc2068_chunked_read (request, ptr, size, fd);
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
841 }
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
842
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
843 params->read_ref_cnt--;
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
844 return (retval);
209
d79e2782eb1b 2003-7-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
845 }
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
846
215
3d6e024dbf31 2003-7-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 209
diff changeset
847 *crlfpos = '\0';
3d6e024dbf31 2003-7-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 209
diff changeset
848 crlfpos++; /* advance to line feed */
209
d79e2782eb1b 2003-7-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
849
d79e2782eb1b 2003-7-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
850 if (sscanf (stpos + 2, "%lx", &params->chunk_size) != 1)
d79e2782eb1b 2003-7-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
851 {
d79e2782eb1b 2003-7-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
852 request->logging_function (gftp_logging_recv, request,
d79e2782eb1b 2003-7-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
853 _("Received wrong response from server, disconnecting\nInvalid chunk size '%s' returned by the remote server\n"),
d79e2782eb1b 2003-7-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
854 stpos + 2);
d79e2782eb1b 2003-7-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
855 gftp_disconnect (request);
303
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
856 params->read_ref_cnt--;
209
d79e2782eb1b 2003-7-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
857 return (GFTP_EFATAL);
d79e2782eb1b 2003-7-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
858 }
d79e2782eb1b 2003-7-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
859
303
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
860 crlfsize = crlfpos - (char *) stpos + 1;
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
861 retval -= crlfsize;
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
862 current_size -= crlfsize;
215
3d6e024dbf31 2003-7-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 209
diff changeset
863
209
d79e2782eb1b 2003-7-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
864 if (params->chunk_size == 0)
d79e2782eb1b 2003-7-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
865 {
d79e2782eb1b 2003-7-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
866 if (params->eof)
303
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
867 {
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
868 params->read_ref_cnt--;
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
869 return (0);
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
870 }
209
d79e2782eb1b 2003-7-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
871
d79e2782eb1b 2003-7-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
872 params->eof = 1;
303
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
873 params->read_ref_cnt--;
209
d79e2782eb1b 2003-7-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
874 return (retval);
d79e2782eb1b 2003-7-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
875 }
d79e2782eb1b 2003-7-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
876
303
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
877 memmove (stpos, crlfpos + 1, current_size + 1);
209
d79e2782eb1b 2003-7-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
878
303
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
879 if (params->chunk_size < current_size)
209
d79e2782eb1b 2003-7-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
880 {
303
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
881 stpos += params->chunk_size;
209
d79e2782eb1b 2003-7-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
882 params->chunk_size = 0;
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
883 }
303
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
884 else
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
885 params->chunk_size -= current_size;
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
886 }
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
887
303
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
888 params->read_ref_cnt--;
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
889 return (retval);
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
890 }
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
891
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
892
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
893 void
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
894 rfc2068_register_module (void)
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
895 {
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
896 gftp_register_config_vars (config_vars);
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
897 }
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
898
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
899
173
4c288d05b26a 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 169
diff changeset
900 int
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
901 rfc2068_init (gftp_request * request)
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
902 {
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
903 rfc2068_params * params;
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
904
173
4c288d05b26a 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 169
diff changeset
905 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
906
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
907 request->protonum = GFTP_HTTP_NUM;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
908 request->init = rfc2068_init;
309
cc2eeb30b793 2003-11-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 304
diff changeset
909 request->copy_param_options = NULL;
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
910 request->read_function = rfc2068_chunked_read;
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
911 request->write_function = gftp_fd_write;
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
912 request->destroy = rfc2068_destroy;
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
913 request->connect = rfc2068_connect;
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
914 request->post_connect = NULL;
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
915 request->disconnect = rfc2068_disconnect;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
916 request->get_file = rfc2068_get_file;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
917 request->put_file = NULL;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
918 request->transfer_file = NULL;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
919 request->get_next_file_chunk = rfc2068_get_next_file_chunk;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
920 request->put_next_file_chunk = NULL;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
921 request->end_transfer = rfc2068_end_transfer;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
922 request->abort_transfer = rfc2068_end_transfer; /* NOTE: uses end_transfer */
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
923 request->list_files = rfc2068_list_files;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
924 request->get_next_file = rfc2068_get_next_file;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
925 request->get_file_size = rfc2068_get_file_size;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
926 request->chdir = rfc2068_chdir;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
927 request->rmdir = NULL;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
928 request->rmfile = NULL;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
929 request->mkdir = NULL;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
930 request->rename = NULL;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
931 request->chmod = NULL;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
932 request->site = NULL;
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
933 request->parse_url = NULL;
63
41b71c4e5076 2002-11-2333 Brian Masney <masneyb@gftp.org>
masneyb
parents: 60
diff changeset
934 request->swap_socks = NULL;
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
935 request->set_config_options = rfc2068_set_config_options;
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
936 request->url_prefix = g_strdup ("http");
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
937 request->need_hostport = 1;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
938 request->need_userpass = 0;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
939 request->use_cache = 1;
105
ae13b18c9336 2003-2-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 102
diff changeset
940 request->always_connected = 1;
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
941
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
942 request->protocol_data = g_malloc0 (sizeof (rfc2068_params));
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
943 params = request->protocol_data;
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
944 params->real_read_function = gftp_fd_read;
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
945
177
aec4b4541d3a 2003-6-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 173
diff changeset
946 return (gftp_set_config_options (request));
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
947 }
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
948