~ubuntu-branches/ubuntu/feisty/elinks/feisty-updates

« back to all changes in this revision

Viewing changes to src/protocol/protocol.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2006-06-30 08:57:43 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060630085743-l81fgbw9dehvl1ds
Tags: 0.11.1-1ubuntu1
* Merge to Debian unstable.
* Removed gnutls12 porting, this is upstream now.
* Only Ubuntu changes left:
  - Killed type-handling.
  - Add X-Ubuntu-Gettext-Domain to .desktop files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* Protocol implementation manager. */
2
 
/* $Id: protocol.c,v 1.90.2.3 2005/05/01 21:32:11 jonas Exp $ */
3
2
 
4
3
#ifdef HAVE_CONFIG_H
5
4
#include "config.h"
14
13
#include "document/view.h"
15
14
#include "ecmascript/ecmascript.h"
16
15
#include "intl/gettext/libintl.h"
17
 
#include "modules/module.h"
 
16
#include "main/module.h"
 
17
#include "network/connection.h"
18
18
#include "protocol/protocol.h"
19
19
#include "protocol/uri.h"
20
 
#include "sched/connection.h"
21
 
#include "sched/session.h"
 
20
#include "session/session.h"
 
21
#include "terminal/terminal.h"
22
22
#include "terminal/window.h"
23
23
#include "util/memory.h"
24
24
#include "util/string.h"
26
26
/* Backends dynamic area: */
27
27
 
28
28
#include "protocol/about.h"
 
29
#include "protocol/bittorrent/bittorrent.h"
 
30
#include "protocol/bittorrent/connection.h"
29
31
#include "protocol/data.h"
30
32
#include "protocol/file/file.h"
31
33
#include "protocol/finger/finger.h"
 
34
#include "protocol/fsp/fsp.h"
32
35
#include "protocol/ftp/ftp.h"
33
36
#include "protocol/gopher/gopher.h"
34
37
#include "protocol/http/http.h"
42
45
struct protocol_backend {
43
46
        unsigned char *name;
44
47
        int port;
45
 
        protocol_handler *handler;
 
48
        protocol_handler_T *handler;
46
49
        unsigned int need_slashes:1;
47
50
        unsigned int need_slash_after_host:1;
48
51
        unsigned int free_syntax:1;
50
53
};
51
54
 
52
55
static const struct protocol_backend protocol_backends[] = {
53
 
        { "about",         0, about_protocol_handler,   0, 0, 1, 0 },
54
 
        { "data",          0, data_protocol_handler,    0, 0, 1, 0 },
55
 
        { "file",          0, file_protocol_handler,    1, 0, 0, 0 },
56
 
        { "finger",       79, finger_protocol_handler,  1, 1, 0, 0 },
57
 
        { "ftp",          21, ftp_protocol_handler,     1, 1, 0, 0 },
58
 
        { "gopher",       70, gopher_protocol_handler,  1, 1, 0, 0 },
59
 
        { "http",         80, http_protocol_handler,    1, 1, 0, 0 },
60
 
        { "https",       443, https_protocol_handler,   1, 1, 0, 1 },
61
 
        { "javascript",    0, NULL,                     0, 0, 1, 0 },
62
 
        { "news",          0, news_protocol_handler,    0, 0, 1, 0 },
63
 
        { "nntp",        119, nntp_protocol_handler,    1, 1, 0, 0 },
64
 
        { "nntps",       563, nntp_protocol_handler,    1, 1, 0, 1 },
65
 
        { "proxy",      3128, proxy_protocol_handler,   1, 1, 0, 0 },
66
 
        { "smb",         139, smb_protocol_handler,     1, 1, 0, 0 },
67
 
        { "snews",         0, news_protocol_handler,    0, 0, 1, 0 },
 
56
        { "about",         0, about_protocol_handler,           0, 0, 1, 0 },
 
57
        { "bittorrent",    0, bittorrent_protocol_handler,      0, 0, 1, 0 },
 
58
        { "data",          0, data_protocol_handler,            0, 0, 1, 0 },
 
59
        { "file",          0, file_protocol_handler,            1, 0, 0, 0 },
 
60
        { "finger",       79, finger_protocol_handler,          1, 1, 0, 0 },
 
61
        { "fsp",          21, fsp_protocol_handler,             1, 1, 0, 0 },
 
62
        { "ftp",          21, ftp_protocol_handler,             1, 1, 0, 0 },
 
63
        { "gopher",       70, gopher_protocol_handler,          1, 1, 0, 0 },
 
64
        { "http",         80, http_protocol_handler,            1, 1, 0, 0 },
 
65
        { "https",       443, https_protocol_handler,           1, 1, 0, 1 },
 
66
        { "javascript",    0, NULL,                             0, 0, 1, 0 },
 
67
        { "news",          0, news_protocol_handler,            0, 0, 1, 0 },
 
68
        { "nntp",        119, nntp_protocol_handler,            1, 1, 0, 0 },
 
69
        { "nntps",       563, nntp_protocol_handler,            1, 1, 0, 1 },
 
70
        { "proxy",      3128, proxy_protocol_handler,           1, 1, 0, 0 },
 
71
        { "smb",         139, smb_protocol_handler,             1, 1, 0, 0 },
 
72
        { "snews",         0, news_protocol_handler,            0, 0, 1, 0 },
68
73
 
69
74
        /* Keep these last! */
70
75
        { NULL,            0, NULL,                     0, 0, 1, 0 },
91
96
        int start, end;
92
97
        enum protocol protocol;
93
98
 
94
 
        /* First check if this isn't some custom (protocol.user) protocol. It
95
 
         * has higher precedence than builtin handlers. */
96
 
        /* TODO: In order to fully give higher precedence to user chosen
97
 
         *       protocols we have to get some terminal to pass along. */
98
 
        if (get_user_program(NULL, name, namelen))
99
 
                return PROTOCOL_USER;
100
 
 
101
99
        /* Almost dichotomic search is used here */
102
100
        /* Starting at the HTTP entry which is the most common that will make
103
101
         * file and NNTP the next entries checked and amongst the third checks
131
129
 
132
130
                protocol = (start + end) / 2;
133
131
        }
 
132
        /* Custom (protocol.user) protocol has higher precedence than builtin
 
133
         * handlers, but we will check for it when following a link.
 
134
         * Calling get_user_program for every link is too expensive. --witekfl */
 
135
        /* TODO: In order to fully give higher precedence to user chosen
 
136
         *       protocols we have to get some terminal to pass along. */
 
137
 
 
138
        if (get_user_program(NULL, name, namelen))
 
139
                return PROTOCOL_USER;
134
140
 
135
141
        return PROTOCOL_UNKNOWN;
136
142
}
182
188
        return protocol_backends[protocol].need_ssl;
183
189
}
184
190
 
185
 
protocol_handler *
 
191
protocol_handler_T *
186
192
get_protocol_handler(enum protocol protocol)
187
193
{
188
194
        assert(VALID_PROTOCOL(protocol));
231
237
        print_error_dialog(ses, state, uri, PRI_CANCEL);
232
238
}
233
239
 
234
 
protocol_external_handler *
235
 
get_protocol_external_handler(enum protocol protocol)
 
240
protocol_external_handler_T *
 
241
get_protocol_external_handler(struct terminal *term, struct uri *uri)
236
242
{
237
 
        assert(VALID_PROTOCOL(protocol));
 
243
        unsigned char *prog;
 
244
 
 
245
        assert(uri && VALID_PROTOCOL(uri->protocol));
238
246
        if_assert_failed return NULL;
239
247
 
240
 
        if (protocol == PROTOCOL_USER)
 
248
        prog = get_user_program(term, struri(uri), uri->protocollen);
 
249
        if (prog && *prog)
241
250
                return user_protocol_handler;
242
251
 
243
 
        if (!protocol_backends[protocol].handler)
 
252
        if (!protocol_backends[uri->protocol].handler)
244
253
                return generic_external_protocol_handler;
245
254
 
246
255
        return NULL;
262
271
        NULL_OPTION_INFO,
263
272
};
264
273
static struct module *protocol_submodules[] = {
 
274
#ifdef CONFIG_BITTORRENT
 
275
        &bittorrent_protocol_module,
 
276
#endif
265
277
        &file_protocol_module,
266
278
#ifdef CONFIG_FINGER
267
279
        &finger_protocol_module,
268
280
#endif
 
281
#ifdef CONFIG_FSP
 
282
        &fsp_protocol_module,
 
283
#endif
269
284
#ifdef CONFIG_FTP
270
285
        &ftp_protocol_module,
271
286
#endif