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

« back to all changes in this revision

Viewing changes to src/protocol/rewrite/rewrite.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
/* URI rewriting module */
2
 
/* $Id: rewrite.c,v 1.37.6.3 2005/01/04 00:42:57 jonas Exp $ */
3
2
 
4
3
#ifdef HAVE_CONFIG_H
5
4
#include "config.h"
9
8
 
10
9
#include "config/options.h"
11
10
#include "intl/gettext/libintl.h"
12
 
#include "modules/module.h"
 
11
#include "main/event.h"
 
12
#include "main/module.h"
13
13
#include "protocol/rewrite/rewrite.h"
14
14
#include "protocol/uri.h"
15
 
#include "sched/event.h"
16
 
#include "sched/location.h"
17
 
#include "sched/session.h"
 
15
#include "session/location.h"
 
16
#include "session/session.h"
18
17
#include "util/string.h"
19
18
 
20
19
 
56
55
                N_("Enable dumb prefixes - simple URI abbreviations which can\n"
57
56
                "be written to the Goto URL dialog instead of actual URIs - i.e.\n"
58
57
                "if you write 'elinks' there, you are directed to\n"
59
 
                "http://elinks.or.cz/.")),
 
58
                "http://elinks.cz/.")),
60
59
 
61
60
        INIT_OPT_BOOL("protocol.rewrite", N_("Enable smart prefixes"),
62
61
                "enable-smart", 0, 1,
91
90
                "%0,%1,...,%9 means argument 0, 1, ..., 9\n"
92
91
                "%% in the string means '%'")),
93
92
 
 
93
        INIT_OPT_STRING("protocol.rewrite", N_("Default template"),
 
94
                "default_template", 0, "",
 
95
                N_("Default URI template used when the string entered in\n"
 
96
                "the goto dialog does not appear to be a URI or a filename\n"
 
97
                "(i.e. contains no '.', ':' or '/' characters), and does\n"
 
98
                "not match any defined prefixes. Set the value to \"\" to\n"
 
99
                "disable use of the default template rewrite rule.")),
 
100
 
94
101
#define INIT_OPT_DUMB_PREFIX(prefix, uri) \
95
102
        INIT_OPT_STRING("protocol.rewrite.dumb", NULL, prefix, 0, uri, NULL)
96
103
 
213
220
        return &get_opt_rewrite(tree);
214
221
}
215
222
 
216
 
static inline void
217
 
encode_uri_string_len(struct string *s, unsigned char *a, int alen)
218
 
{
219
 
        unsigned char c = a[alen];
220
 
 
221
 
        a[alen] = 0;
222
 
        encode_uri_string(s, a, 1);
223
 
        a[alen] = c;
224
 
}
225
 
 
226
223
#define MAX_URI_ARGS 10
227
224
 
228
225
static unsigned char *
271
268
                                add_uri_to_string(&n, current_uri, URI_ORIGINAL);
272
269
                                break;
273
270
                        case 's':
274
 
                                if (arg) encode_uri_string(&n, arg, 1);
 
271
                                if (arg) encode_uri_string(&n, arg, -1, 1);
275
272
                                break;
276
273
                        case '%':
277
274
                                add_char_to_string(&n, '%');
287
284
                        case '8':
288
285
                        case '9':
289
286
                                value = *url - '0';
290
 
                                if (value < argc)
291
 
                                        encode_uri_string_len(&n, args[value],
292
 
                                                argslen[value]);
 
287
                                if (value > argc) break;
 
288
                                encode_uri_string(&n, args[value],
 
289
                                                  argslen[value], 1);
293
290
                                break;
294
291
                        default:
295
292
                                add_bytes_to_string(&n, url - 1, 2);
334
331
        if (get_dumb_enable() && !uu && !*argstart)
335
332
                uu = get_uri_rewrite_prefix(URI_REWRITE_DUMB, *url);
336
333
 
 
334
        if (!uu
 
335
            && !strchr(*url, ':')
 
336
            && !strchr(*url, '.')
 
337
            && !strchr(*url, '/')) {
 
338
                uu = get_opt_str("protocol.rewrite.default_template");
 
339
                if (uu && *uu) {
 
340
                        arg = *url;
 
341
                } else {
 
342
                        uu = NULL;
 
343
                }
 
344
        }
 
345
 
337
346
        if (uu) {
338
347
                struct uri *uri = ses && have_location(ses)
339
348
                                ? cur_loc(ses)->vs.uri : NULL;
349
358
}
350
359
 
351
360
struct event_hook_info uri_rewrite_hooks[] = {
352
 
        { "goto-url",   goto_url_hook },
 
361
        { "goto-url", -1, goto_url_hook },
353
362
 
354
363
        NULL_EVENT_HOOK_INFO
355
364
};