annotate lib/https.c @ 516:fbb5a02beddb

2004-7-26 Brian Masney <masneyb@gftp.org> * lib/config_file.c lib/local.c lib/ftps.c lib/gftp.h lib/httpcommon.h lib/https.c lib/misc.c lib/protocols.c lib/pty.c lib/rfc2068.c lib/rfc959.c lib/sshv2.c - various fixes found through a static code analysis checker. (some signed/unsigned fixes, removed unneeded casts, removed unneeded variables, more consistency, largefile fixes). Thanks to Derek M Jones for running the static code analysis for me * lib/cache.c - s/remove/del_entry/g * lib/bookmark.c lib/protocols.c (gftp_parse_bookmark) - allow the third parameter of this function to be a NULL pointer
author masneyb
date Tue, 27 Jul 2004 02:46:54 +0000
parents 1ffdbc487a70
children 1808cebed602
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
1 /*****************************************************************************/
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
2 /* https.c - General purpose routines for the HTTPS protocol */
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
3 /* Copyright (C) 1998-2003 Brian Masney <masneyb@gftp.org> */
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
4 /* */
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
5 /* This program is free software; you can redistribute it and/or modify */
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
6 /* it under the terms of the GNU General Public License as published by */
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
7 /* the Free Software Foundation; either version 2 of the License, or */
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
8 /* (at your option) any later version. */
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
9 /* */
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
10 /* This program is distributed in the hope that it will be useful, */
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
11 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
12 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
13 /* GNU General Public License for more details. */
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
14 /* */
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
15 /* You should have received a copy of the GNU General Public License */
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
16 /* along with this program; if not, write to the Free Software */
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
17 /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA */
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
18 /*****************************************************************************/
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
19
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
20 #include "gftp.h"
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
21 #include "httpcommon.h"
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
22
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
23 static const char cvsid[] = "$Id$";
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
24
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
25 #ifdef USE_SSL
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
26 static int
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
27 https_get_next_file (gftp_request * request, gftp_file * fle, int fd)
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
28 {
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
29 rfc2068_params * params;
516
fbb5a02beddb 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 415
diff changeset
30 int resetptr;
fbb5a02beddb 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 415
diff changeset
31 size_t ret;
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
32
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
33 params = request->protocol_data;
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
34 if (request->cached)
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
35 {
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
36 params->real_read_function = gftp_fd_read;
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
37 request->write_function = gftp_fd_write;
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
38 resetptr = 1;
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
39 }
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
40 else
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
41 resetptr = 0;
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
42
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
43 ret = rfc2068_get_next_file (request, fle, fd);
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
44
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
45 if (resetptr)
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
46 {
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
47 params->real_read_function = gftp_ssl_read;
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
48 request->write_function = gftp_ssl_write;
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
49 }
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
50
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
51 return (ret);
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
52 }
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
53 #endif
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
54
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
55 void
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
56 https_register_module (void)
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
57 {
174
e643d287fe32 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 173
diff changeset
58 #ifdef USE_SSL
e643d287fe32 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 173
diff changeset
59 ssl_register_module ();
e643d287fe32 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 173
diff changeset
60 #endif
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
61 }
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
62
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
63
173
4c288d05b26a 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 169
diff changeset
64 int
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
65 https_init (gftp_request * request)
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
66 {
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
67 #ifdef USE_SSL
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
68 rfc2068_params * params;
173
4c288d05b26a 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 169
diff changeset
69 int ret;
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
70
173
4c288d05b26a 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 169
diff changeset
71 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
72
173
4c288d05b26a 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 169
diff changeset
73 if ((ret = gftp_protocols[GFTP_HTTP_NUM].init (request)) < 0)
4c288d05b26a 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 169
diff changeset
74 return (ret);
4c288d05b26a 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 169
diff changeset
75
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
76 params = request->protocol_data;
415
1ffdbc487a70 2004-3-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 186
diff changeset
77 request->protonum = GFTP_HTTPS_NUM;
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
78 request->init = https_init;
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
79 request->post_connect = gftp_ssl_session_setup;
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
80 params->real_read_function = gftp_ssl_read;
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
81 request->write_function = gftp_ssl_write;
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
82 request->get_next_file = https_get_next_file;
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
83 request->url_prefix = g_strdup ("https");
173
4c288d05b26a 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 169
diff changeset
84
4c288d05b26a 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 169
diff changeset
85 if ((ret = gftp_ssl_startup (NULL)) < 0)
4c288d05b26a 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 169
diff changeset
86 return (ret);
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
87
173
4c288d05b26a 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 169
diff changeset
88 return (0);
4c288d05b26a 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 169
diff changeset
89 #else
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 174
diff changeset
90 request->logging_function (gftp_logging_error, request,
173
4c288d05b26a 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 169
diff changeset
91 _("HTTPS Support unavailable since SSL support was not compiled in. Aborting connection.\n"));
4c288d05b26a 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 169
diff changeset
92
4c288d05b26a 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 169
diff changeset
93 return (GFTP_EFATAL);
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
94 #endif
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
95 }
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
96