File: rfc1738.h

package info (click to toggle)
squid 7.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 33,440 kB
  • sloc: cpp: 184,513; ansic: 12,442; sh: 5,688; makefile: 5,247; perl: 2,560; sql: 326; python: 240; awk: 141; sed: 1
file content (71 lines) | stat: -rw-r--r-- 2,996 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
 * Copyright (C) 1996-2025 The Squid Software Foundation and contributors
 *
 * Squid software is distributed under GPLv2+ license and includes
 * contributions from numerous individuals and organizations.
 * Please see the COPYING and CONTRIBUTORS files for details.
 */

#ifndef SQUID_INCLUDE_RFC1738_H
#define SQUID_INCLUDE_RFC1738_H

#ifdef __cplusplus
extern "C" {
#endif

/* Encoder rfc1738_do_escape flag values. */
#define RFC1738_ESCAPE_CTRLS       1
#define RFC1738_ESCAPE_UNSAFE      2
#define RFC1738_ESCAPE_RESERVED    4
#define RFC1738_ESCAPE_ALL         (RFC1738_ESCAPE_UNSAFE|RFC1738_ESCAPE_RESERVED|RFC1738_ESCAPE_CTRLS)
// exclusions
#define RFC1738_ESCAPE_NOSPACE     128
#define RFC1738_ESCAPE_NOPERCENT   256
// Backward compatibility
#define RFC1738_ESCAPE_UNESCAPED   (RFC1738_ESCAPE_UNSAFE|RFC1738_ESCAPE_CTRLS|RFC1738_ESCAPE_NOPERCENT)

/**
 * RFC 1738 URL-escaping
 *
 * Public API is formed of a triplet of encode functions mapping to the rfc1738_do_encode() engine.
 *
 * ASCII characters are split into four groups:
 * \li SAFE     Characters which are safe to occur in any URL. For example A,B,C
 * \li CTRLS    Binary control codes. Dangerous to include in URLs.
 * \li UNSAFE   Characters which are completely usafe to occur in any URL. For example; backspace, tab, space, newline.
 * \li RESERVED Characters which are reserved for special meaning and may only occur in certain parts of a URL.
 *
 * Returns a static buffer containing the RFC 1738 compliant, escaped version of the given url.
 *
 * \param flags  RFC1738_ESCAPE_CTRLS     Encode the blatantly dangerous binary codes.
 * \param flags  RFC1738_ESCAPE_UNSAFE    Encode printable unsafe characters (excluding CTRLs).
 * \param flags  RFC1738_ESCAPE_RESERVED  Encode reserved characters.
 * \param flags  RFC1738_ESCAPE_ALL       Encode all binary CTRL, unsafe and reserved characters.
 * \param flags  RFC1738_ESCAPE_NOSPACE   Ignore the space whitespace character.
 * \param flags  RFC1738_ESCAPE_NOPERCENT Ignore the escaping delimiter '%'.
 */
extern char *rfc1738_do_escape(const char *url, int flags);

/* Old API functions */

/* Default RFC 1738 escaping. Escape all UNSAFE characters and binary CTRL codes */
#define rfc1738_escape(x)  rfc1738_do_escape(x, RFC1738_ESCAPE_UNSAFE|RFC1738_ESCAPE_CTRLS)

/* Escape a partial URL. Encoding every binary code, unsafe or reserved character. */
#define rfc1738_escape_part(x)  rfc1738_do_escape(x, RFC1738_ESCAPE_ALL)

/* Escape a URL. Encoding every unsafe characters but skipping reserved and already-encoded bytes.
 * Suitable for safely encoding an absolute URL which may be encoded but is not trusted. */
#define rfc1738_escape_unescaped(x)  rfc1738_do_escape(x, RFC1738_ESCAPE_UNSAFE|RFC1738_ESCAPE_CTRLS|RFC1738_ESCAPE_NOPERCENT)

/**
 * Unescape a URL string according to RFC 1738 specification.
 * String is unescaped in-place
 */
extern void rfc1738_unescape(char *url);

#ifdef __cplusplus
}
#endif
#endif /* SQUID_INCLUDE_RFC1738_H */