author | Michael Krelin <hacker@klever.net> | 2005-05-09 11:00:28 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2005-05-09 11:00:28 (UTC) |
commit | 43d47575878e4eaf3c8da84bf609fcd0bde595fb (patch) (unidiff) | |
tree | f7ec4d1f0d0a01b43feb5c9b4f414e870036522c /src/util.cc | |
parent | d9578a5ae0ac4e44ff5e3c13d3f39f400f51bcf2 (diff) | |
download | kingate-43d47575878e4eaf3c8da84bf609fcd0bde595fb.zip kingate-43d47575878e4eaf3c8da84bf609fcd0bde595fb.tar.gz kingate-43d47575878e4eaf3c8da84bf609fcd0bde595fb.tar.bz2 |
1. http headers container added
2. preliminary cookies support
3. absolutely useless http_quoted_string and http_quote utility functions added
-rw-r--r-- | src/util.cc | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/util.cc b/src/util.cc index 3166e62..48e486a 100644 --- a/src/util.cc +++ b/src/util.cc | |||
@@ -51,3 +51,56 @@ namespace kingate { | |||
51 | return rv; | 51 | return rv; |
52 | } | 52 | } |
53 | |||
54 | /* | ||
55 | * RFC 2616: | ||
56 | * | ||
57 | * separators = "(" | ")" | "<" | ">" | "@" | ||
58 | * | "," | ";" | ":" | "\" | <"> | ||
59 | * | "/" | "[" | "]" | "?" | "=" | ||
60 | * | "{" | "}" | SP | HT | ||
61 | */ | ||
62 | |||
63 | /* | ||
64 | * RFC 2616: | ||
65 | * | ||
66 | * token = 1*<any CHAR except CTLs or separators> | ||
67 | */ | ||
68 | |||
69 | static const char *quotible_chars = | ||
70 | "\001\002\003\004\005\006\007\010" | ||
71 | "\011\012\013\014\015\016\017\020" | ||
72 | "\021\022\023\024\025\026\027\030" | ||
73 | "\031\032\033\034\035\036\037\040" | ||
74 | "()<>@,;:\\\"/[]?={}" /* separator chars (except for SP and HT mentioned elsewhere */ | ||
75 | "\177" | ||
76 | ; | ||
77 | |||
78 | /* | ||
79 | * RFC 2616: | ||
80 | * | ||
81 | * quoted-string = ( <"> *(qdtext | quoted-pair ) <"> ) | ||
82 | * qdtext = <any TEXT except <">> | ||
83 | * | ||
84 | * The backslash character ("\") MAY be used as a single-character | ||
85 | * quoting mechanism only within quoted-string and comment constructs. | ||
86 | * | ||
87 | * quoted-pair = "\" CHAR | ||
88 | */ | ||
89 | |||
90 | string http_quoted_string(const string& str) { | ||
91 | string rv = str; | ||
92 | string::size_type sp=0; | ||
93 | for(string::size_type q=rv.find('"');(q=rv.find('"',q))!=string::npos;q+=2) | ||
94 | rv.insert(q,1,'\\'); | ||
95 | rv.insert(0,1,'"'); | ||
96 | rv += '"'; | ||
97 | return rv; | ||
98 | } | ||
99 | |||
100 | string http_quote(const string& str) { | ||
101 | if(str.find_first_of(quotible_chars)==string::npos) | ||
102 | return str; | ||
103 | return http_quoted_string(str); | ||
104 | } | ||
105 | |||
53 | } | 106 | } |