comparison lib/rfc959.c @ 126:1e65871fdfa1

2003-4-9 Brian Masney <masneyb@gftp.org> * lib/gftp.h lib/config_file.c - reordered config option types. Added gftp_option_type_textcomboedt type * lib/options.h lib/rfc959.c - moved gftp_proxy_type to rfc959.c * lib/rfc959.c - added proxy_type that is gftp_option_type_textcomboedt. Consolidated help text into comment. In parse_ftp_proxy_string(), improve parsing of proxy config
author masneyb
date Thu, 10 Apr 2003 02:29:44 +0000
parents 65048c959029
children 84b3e69807a2
comparison
equal deleted inserted replaced
125:b875de05c22d 126:1e65871fdfa1
18 /*****************************************************************************/ 18 /*****************************************************************************/
19 19
20 #include "gftp.h" 20 #include "gftp.h"
21 static const char cvsid[] = "$Id$"; 21 static const char cvsid[] = "$Id$";
22 22
23 static gftp_textcomboedt_data gftp_proxy_type[] = {
24 {N_("none"), ""},
25 {N_("SITE command"), "USER %pu\nPASS %pp\nSITE %hh\nUSER %hu\nPASS %hp\n"},
26 {N_("user@host"), "USER %pu\nPASS %pp\nUSER %hu@%hh\nPASS %hp\n"},
27 {N_("user@host:port"), "USER %hu@%hh:%ho\nPASS %hp\n"},
28 {N_("AUTHENTICATE"), "USER %hu@%hh\nPASS %hp\nSITE AUTHENTICATE %pu\nSITE RESPONSE %pp\n"},
29 {N_("user@host port"), "USER %hu@%hh %ho\nPASS %hp\n"},
30 {N_("user@host NOAUTH"), "USER %hu@%hh\nPASS %hp\n"},
31 {N_("HTTP Proxy"), "http"},
32 {N_("Custom"), ""},
33 {NULL, NULL}
34 };
35
23 static gftp_config_vars config_vars[] = 36 static gftp_config_vars config_vars[] =
24 { 37 {
25 {"", N_("FTP"), gftp_option_type_notebook, NULL, NULL, 0, NULL, 38 {"", N_("FTP"), gftp_option_type_notebook, NULL, NULL, 0, NULL,
26 GFTP_PORT_GTK, NULL}, 39 GFTP_PORT_GTK, NULL},
27 40
37 gftp_option_type_checkbox, GINT_TO_POINTER(1), NULL, 0, 50 gftp_option_type_checkbox, GINT_TO_POINTER(1), NULL, 0,
38 N_("The remote FTP server will attempt to resolve symlinks in the directory listings. Generally, this is a good idea to leave enabled. The only time you will want to disable this is if the remote FTP server doesn't support the -L option to LIST"), 51 N_("The remote FTP server will attempt to resolve symlinks in the directory listings. Generally, this is a good idea to leave enabled. The only time you will want to disable this is if the remote FTP server doesn't support the -L option to LIST"),
39 GFTP_PORT_ALL, NULL}, 52 GFTP_PORT_ALL, NULL},
40 {"ascii_transfers", N_("Transfer files in ASCII mode"), 53 {"ascii_transfers", N_("Transfer files in ASCII mode"),
41 gftp_option_type_checkbox, GINT_TO_POINTER(0), NULL, 0, 54 gftp_option_type_checkbox, GINT_TO_POINTER(0), NULL, 0,
42 N_("If you are transfering a text file from Windows to UNIX box or vice versa, then you should enable this. Each system represents newlines differently. If you are transfering from UNIX to UNIX, then it is safe to leave this off."), 55 N_("If you are transfering a text file from Windows to UNIX box or vice versa, then you should enable this. Each system represents newlines differently for text files. If you are transfering from UNIX to UNIX, then it is safe to leave this off. If you are downloading binary data, you will want to disable this."),
43 GFTP_PORT_ALL, NULL}, 56 GFTP_PORT_ALL, NULL},
44 {"ftp_proxy_host", N_("Proxy hostname:"), 57 {"ftp_proxy_host", N_("Proxy hostname:"),
45 gftp_option_type_text, "", NULL, 0, 58 gftp_option_type_text, "", NULL, 0,
46 N_("Firewall hostname"), GFTP_PORT_ALL, NULL}, 59 N_("Firewall hostname"), GFTP_PORT_ALL, NULL},
47 {"ftp_proxy_port", N_("Proxy port:"), 60 {"ftp_proxy_port", N_("Proxy port:"),
56 {"ftp_proxy_account", N_("Proxy account:"), 69 {"ftp_proxy_account", N_("Proxy account:"),
57 gftp_option_type_text, "", NULL, 0, 70 gftp_option_type_text, "", NULL, 0,
58 N_("Your firewall account (optional)"), GFTP_PORT_ALL, NULL}, 71 N_("Your firewall account (optional)"), GFTP_PORT_ALL, NULL},
59 72
60 {"", "", gftp_option_type_newtable, "", NULL, 0, "", GFTP_PORT_GTK, NULL}, 73 {"", "", gftp_option_type_newtable, "", NULL, 0, "", GFTP_PORT_GTK, NULL},
61 /* FIXME {"", N_("Proxy server type"), CONFIG_COMBO, "PS", NULL, GFTP_PORT_GTK},*/ 74
62 {"proxy_config", N_("Proxy config"), 75 {"proxy_config", N_("Proxy server type:"),
63 gftp_option_type_textbox, "", NULL, 0, 76 gftp_option_type_textcomboedt, "", gftp_proxy_type, 0,
64 N_("This specifies how your proxy server expects us to log in"), 77 N_("This specifies how your proxy server expects us to log in. You can specify a 2 character replacement string prefixed by a % that will be replaced with the proper data. The first character can be either p for proxy or h for the host of the FTP server. The second character can be u (user), p (pass), h (host), o (port) or a (account). For example, to specify the proxy user, you can you type in %pu"),
65 GFTP_PORT_GTK, NULL}, 78 GFTP_PORT_ALL, NULL},
66 79
67 {"", N_("%pu = proxy user"), gftp_option_type_label, "", NULL, 0, "",
68 GFTP_PORT_GTK, NULL},
69 {"", N_("%hu = host user"), gftp_option_type_label, "", NULL, 0, "",
70 GFTP_PORT_GTK, NULL},
71 {"", N_("%pp = proxy pass"), gftp_option_type_label, "", NULL, 0, "",
72 GFTP_PORT_GTK, NULL},
73 {"", N_("%hp = host pass"), gftp_option_type_label, "", NULL, 0, "",
74 GFTP_PORT_GTK, NULL},
75 {"", N_("%ph = proxy host"), gftp_option_type_label, "", NULL, 0, "",
76 GFTP_PORT_GTK, NULL},
77 {"", N_("%hh = host"), gftp_option_type_label, "", NULL, 0, "",
78 GFTP_PORT_GTK, NULL},
79 {"", N_("%po = proxy port"), gftp_option_type_label, "", NULL, 0, "",
80 GFTP_PORT_GTK, NULL},
81 {"", N_("%ho = host port"), gftp_option_type_label, "", NULL, 0, "",
82 GFTP_PORT_GTK, NULL},
83 {"", N_("%pa = proxy account"), gftp_option_type_label, "", NULL, 0, "",
84 GFTP_PORT_GTK, NULL},
85 {"", N_("%ha = host account"), gftp_option_type_label, "", NULL, 0, "",
86 GFTP_PORT_GTK, NULL},
87 {NULL, NULL, 0, NULL, NULL, 0, NULL, 0, NULL} 80 {NULL, NULL, 0, NULL, NULL, 0, NULL, 0, NULL}
88 }; 81 };
89 82
90 83
91 typedef struct rfc959_params_tag 84 typedef struct rfc959_params_tag
181 174
182 175
183 static char * 176 static char *
184 parse_ftp_proxy_string (gftp_request * request) 177 parse_ftp_proxy_string (gftp_request * request)
185 { 178 {
186 char *startpos, *endpos, *oldstr, *newstr, *newval, *tempport, *proxy_config; 179 char *startpos, *endpos, *newstr, *newval, tempport[6], *proxy_config,
180 savechar;
181 size_t len;
187 int tmp; 182 int tmp;
188 183
189 g_return_val_if_fail (request != NULL, NULL); 184 g_return_val_if_fail (request != NULL, NULL);
190 g_return_val_if_fail (request->protonum == GFTP_FTP_NUM, NULL); 185 g_return_val_if_fail (request->protonum == GFTP_FTP_NUM, NULL);
191 186
192 newstr = g_malloc (1);
193 *newstr = '\0';
194 gftp_lookup_request_option (request, "proxy_config", &proxy_config); 187 gftp_lookup_request_option (request, "proxy_config", &proxy_config);
188
189 newstr = g_malloc0 (1);
190 len = 0;
195 startpos = endpos = proxy_config; 191 startpos = endpos = proxy_config;
196 while (*endpos != '\0') 192 while (*endpos != '\0')
197 { 193 {
198 tempport = NULL;
199 if (*endpos == '%' && tolower ((int) *(endpos + 1)) == 'p') 194 if (*endpos == '%' && tolower ((int) *(endpos + 1)) == 'p')
200 { 195 {
201 switch (tolower ((int) *(endpos + 2))) 196 switch (tolower ((int) *(endpos + 2)))
202 { 197 {
203 case 'u': 198 case 'u':
209 case 'h': 204 case 'h':
210 gftp_lookup_request_option (request, "ftp_proxy_host", &newval); 205 gftp_lookup_request_option (request, "ftp_proxy_host", &newval);
211 break; 206 break;
212 case 'o': 207 case 'o':
213 gftp_lookup_request_option (request, "ftp_proxy_port", &tmp); 208 gftp_lookup_request_option (request, "ftp_proxy_port", &tmp);
214 tempport = g_strdup_printf ("%d", tmp); 209 g_snprintf (tempport, sizeof (tempport), "%d", tmp);
215 newval = tempport; 210 newval = tempport;
216 break; 211 break;
217 case 'a': 212 case 'a':
218 gftp_lookup_request_option (request, "ftp_proxy_account", &newval); 213 gftp_lookup_request_option (request, "ftp_proxy_account", &newval);
219 break; 214 break;
234 break; 229 break;
235 case 'h': 230 case 'h':
236 newval = request->hostname; 231 newval = request->hostname;
237 break; 232 break;
238 case 'o': 233 case 'o':
239 tempport = g_strdup_printf ("%d", request->port); 234 g_snprintf (tempport, sizeof (tempport), "%d", request->port);
240 newval = tempport; 235 newval = tempport;
241 break; 236 break;
242 case 'a': 237 case 'a':
243 newval = request->account; 238 newval = request->account;
244 break; 239 break;
247 continue; 242 continue;
248 } 243 }
249 } 244 }
250 else if (*endpos == '%' && tolower ((int) *(endpos + 1)) == 'n') 245 else if (*endpos == '%' && tolower ((int) *(endpos + 1)) == 'n')
251 { 246 {
252 *endpos = '\0'; 247 savechar = *endpos;
253 oldstr = newstr; 248 *endpos = '\0';
254 newstr = g_strconcat (oldstr, startpos, "\r\n", NULL); 249
255 g_free (oldstr); 250 len += strlen (startpos) + 2;
251 newstr = g_realloc (newstr, sizeof (char) * (len + 1));
252 strcat (newstr, startpos);
253 strcat (newstr, "\r\n");
254
255 *endpos = savechar;
256 endpos += 2; 256 endpos += 2;
257 startpos = endpos; 257 startpos = endpos;
258 continue; 258 continue;
259 } 259 }
260 else 260 else
261 { 261 {
262 endpos++; 262 endpos++;
263 continue; 263 continue;
264 } 264 }
265 265
266 savechar = *endpos;
266 *endpos = '\0'; 267 *endpos = '\0';
267 oldstr = newstr; 268 len += strlen (startpos);
268 if (!newval) 269 if (!newval)
269 newstr = g_strconcat (oldstr, startpos, NULL); 270 {
271 newstr = g_realloc (newstr, sizeof (char) * (len + 1));
272 strcat (newstr, startpos);
273 }
270 else 274 else
271 newstr = g_strconcat (oldstr, startpos, newval, NULL); 275 {
272 if (tempport) 276 len += strlen (newval);
273 { 277 newstr = g_realloc (newstr, sizeof (char) * (len + 1));
274 g_free (tempport); 278 strcat (newstr, startpos);
275 tempport = NULL; 279 strcat (newstr, newval);
276 } 280 }
277 g_free (oldstr); 281
282 *endpos = savechar;
278 endpos += 3; 283 endpos += 3;
279 startpos = endpos; 284 startpos = endpos;
280 } 285 }
286
281 return (newstr); 287 return (newstr);
282 } 288 }
283 289
284 290
285 static int 291 static int