Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| SHA1 Hash: | 9897316dbea9c9fa6b9575ada04a408f1863daa8 |
|---|---|
| Date: | 2008-09-18 16:09:26 |
| User: | stephan |
| Comment: | fixed file URLs to fail if there is more than one : after the scheme |
Tags And Properties
- branch=trunk inherited from [d45e7467f2]
- sym-trunk inherited from [d45e7467f2]
Changes
Changes to parsepp_url.hpp
| Old (68112ef8f8acc8d9) | New (23247e29208cbda2) | |||
|---|---|---|---|---|
| 1 | #ifndef S11N_NET_PARSEPP_URL_H_INCLUDED | 1 | #ifndef S11N_NET_PARSEPP_URL_H_INCLUDED | |
| 2 | #define S11N_NET_PARSEPP_URL_H_INCLUDED 1 | 2 | #define S11N_NET_PARSEPP_URL_H_INCLUDED 1 | |
| 3 | 3 | |||
| 4 | #include "parsepp.hpp" | 4 | #include "parsepp.hpp" | |
| 5 | #include <map> | 5 | #include <map> | |
| 61 hidden lines | ||||
| 67 | s.params[s.key = m] = ""; // ensure an empty value in case the val field is empty. | 67 | s.params[s.key = m] = ""; // ensure an empty value in case the val field is empty. | |
| 68 | } | 68 | } | |
| 69 | }; | 69 | }; | |
| 70 | 70 | |||
| 71 | 71 | |||
| > | 72 | /** | ||
| > | 73 | Internal helper. If IsEsc then all matches are assumed to be | ||
| > | 74 | %XX escape sequences, otherwise they are assumed to be unescaped | ||
| > | 75 | text. | ||
| > | 76 | */ | ||
| 72 | template <bool IsEsc> | 77 | template <bool IsEsc> | |
| 73 | struct a_esc_append | 78 | struct a_esc_append | |
| 74 | { | 79 | { | |
| 75 | static void matched( Ps::parser_state &, const std::string & m, std::string & s ) | 80 | static void matched( Ps::parser_state &, const std::string & m, std::string & s ) | |
| 76 | { | 81 | { | |
| 77 | CERR << "a_esc_append<"<<IsEsc<<">:["<<m<<"]\n"; | | | 82 | //CERR << "a_esc_append<"<<IsEsc<<">:["<<m<<"]\n"; |
| 78 | if( IsEsc ) | | | 83 | if( IsEsc ) |
| 79 | { | | | 84 | { |
| 80 | std::istringstream is(m); | | | 85 | std::istringstream is(m); |
| 81 | int x = '?'; | | | 86 | short x = '?'; |
| 82 | is >> std::hex >> x; // weird: reading directly into ch missing the std::hex handling | | | 87 | is >> std::hex >> x; // weird: reading directly into a char-type x misses the std::hex handling |
| 83 | s.push_back(std::string::value_type(x)); | | | 88 | s.push_back(std::string::value_type(x)); |
| 84 | } | | | 89 | } |
| 85 | else | | | 90 | else |
| 86 | { | | | 91 | { |
| 87 | s += m; | | | 92 | s += m; |
| 88 | } | | | 93 | } |
| 89 | } | 94 | } | |
| 90 | }; | 95 | }; | |
| 91 | 96 | |||
| 92 | 97 | |||
| 93 | /** | 98 | /** | |
| 4 hidden lines | ||||
| 98 | */ | 103 | */ | |
| 99 | struct a_kvp_set_val | 104 | struct a_kvp_set_val | |
| 100 | { | 105 | { | |
| 101 | static void matched( Ps::parser_state &, const std::string & m, url_state & s ) | 106 | static void matched( Ps::parser_state &, const std::string & m, url_state & s ) | |
| 102 | { | 107 | { | |
| 103 | COUT << "a_kvp_set_val: " << s.key << '='<<m << '\n'; | | | 108 | //COUT << "a_kvp_set_val: " << s.key << '='<<m << '\n'; |
| 104 | if( ! m.empty() ) | 109 | if( ! m.empty() ) | |
| 105 | { | 110 | { | |
| 106 | std::string unesc; | 111 | std::string unesc; | |
| 107 | typedef r_ch<'%'> PCT; | 112 | typedef r_ch<'%'> PCT; | |
| 108 | typedef r_repeat<r_xdigit,2> DIGITS; | 113 | typedef r_repeat<r_xdigit,2> DIGITS; | |
| 30 hidden lines | ||||
| 139 | : r_action< r_star< r_notch< '&' > >, a_kvp_set_val > | 144 | : r_action< r_star< r_notch< '&' > >, a_kvp_set_val > | |
| 140 | {}; | 145 | {}; | |
| 141 | 146 | |||
| 142 | /** Reads a single key/val pair. */ | 147 | /** Reads a single key/val pair. */ | |
| 143 | struct r_kvp | 148 | struct r_kvp | |
| 144 | : r_and< RL< r_kvp_key, r_ch<'='>, r_opt<r_kvp_val> > > | | | 149 | : r_and< RL< |
| | | 150 | r_kvp_key, | ||
| | | 151 | r_ch<'='>, | ||
| | | 152 | r_opt<r_kvp_val> | ||
| | | 153 | > > | ||
| 145 | {}; | 154 | {}; | |
| 146 | 155 | |||
| 147 | /** Reads a sequence of key/val pairs, delimited by '&' (http-style). */ | 156 | /** Reads a sequence of key/val pairs, delimited by '&' (http-style). */ | |
| 148 | struct r_kvps | 157 | struct r_kvps | |
| 149 | : r_and< RL< r_kvp, r_star< r_and< RL< r_ch<'&'>, r_opt<r_kvp> > > > > > | 158 | : r_and< RL< r_kvp, r_star< r_and< RL< r_ch<'&'>, r_opt<r_kvp> > > > > > | |
| 43 hidden lines | ||||
| 193 | } | 202 | } | |
| 194 | }; | 203 | }; | |
| 195 | 204 | |||
| 196 | struct r_scheme | 205 | struct r_scheme | |
| 197 | : r_and< RL< r_action< r_identifier, a_scheme >, r_ch<':'>, r_plus< r_ch<'/'> > > > | 206 | : r_and< RL< r_action< r_identifier, a_scheme >, r_ch<':'>, r_plus< r_ch<'/'> > > > | |
| 198 | // ^^^ FIXME: keep the last / for file:/ and file:/// | < | ||
| 199 | {}; | 207 | {}; | |
| 200 | 208 | |||
| 201 | struct a_path | 209 | struct a_path | |
| 202 | { | 210 | { | |
| 203 | static void matched( Ps::parser_state &, const std::string & v, url_state & s ) | 211 | static void matched( Ps::parser_state &, const std::string & v, url_state & s ) | |
| 64 hidden lines | ||||
| 268 | 276 | |||
| 269 | /** | 277 | /** | |
| 270 | r_alnum+(:[^@]))?@ | 278 | r_alnum+(:[^@]))?@ | |
| 271 | */ | 279 | */ | |
| 272 | struct r_login | 280 | struct r_login | |
| 273 | /** | < | ||
| 274 | action< | < | ||
| 275 | seq< r_user, opt< seq< one<':'>, r_password > >, | < | ||
| 276 | one<'@'> >, a_login> | < | ||
| 277 | */ | < | ||
| 278 | : r_action< | 281 | : r_action< | |
| 279 | r_and< RL< | 282 | r_and< RL< | |
| 280 | r_user, | 283 | r_user, | |
| 281 | r_opt< r_and<RL<r_ch<':'>,r_opt<r_password> > > >, | 284 | r_opt< r_and<RL<r_ch<':'>,r_opt<r_password> > > >, | |
| 282 | r_ch<'@'> | 285 | r_ch<'@'> | |
| 12 hidden lines | ||||
| 295 | 298 | |||
| 296 | seq< action< seq< string<'f','i','l','e'>, one<':'> >, a_scheme >, | 299 | seq< action< seq< string<'f','i','l','e'>, one<':'> >, a_scheme >, | |
| 297 | seq< opt< string<'/','/'> >, action< r_filepath, a_path > > > | 300 | seq< opt< string<'/','/'> >, action< r_filepath, a_path > > > | |
| 298 | 301 | |||
| 299 | */ | 302 | */ | |
| 300 | struct r_fileurl | | | 303 | struct r_fileurl : |
| 301 | : r_and< RL< | | | 304 | r_and< RL< |
| 302 | r_action< r_and< RL< | | | 305 | r_action< r_and< RL< |
| 303 | r_chseq<CL<'f','i','l','e'> >, | | | 306 | r_chseq<CL<'f','i','l','e'> >, |
| 304 | r_ch<':'> | | | 307 | r_ch<':'> |
| 305 | > >, a_scheme >, | | | 308 | > >, a_scheme >, |
| 306 | r_and<RL< r_opt< r_repeat< r_ch<'/'>,2> >, | | | 309 | r_notat< r_ch<':'> >, |
| 307 | r_action< r_filepath, a_path > | | | 310 | r_and<RL< r_opt< r_repeat< r_ch<'/'>,2> >, |
| 308 | > > | | | 311 | r_action< r_filepath, a_path > |
| | | 312 | > > | ||
| 309 | > > | 313 | > > | |
| 310 | {}; | 314 | {}; | |
| 311 | 315 | |||
| 312 | struct r_stdurl | 316 | struct r_stdurl | |
| 313 | : r_and< RL< r_scheme, | 317 | : r_and< RL< r_scheme, | |
| 9 hidden lines | ||||
| 323 | 327 | |||
| 324 | #undef RL | 328 | #undef RL | |
| 325 | #undef CL | 329 | #undef CL | |
| 326 | 330 | |||
| 327 | /** | 331 | /** | |
| 328 | Convenience function to parse the given URL and stuff the data into | | | 332 | Convenience function to parse the given URL and stuff the data |
| 329 | tgt. | | | 333 | into tgt. On success, tgt contains valid URL data. On error, |
| | | 334 | tgt is not modified. | ||
| 330 | */ | 335 | */ | |
| 331 | inline bool parse_url( std::string const & src, url_state & tgt ) | 336 | inline bool parse_url( std::string const & src, url_state & tgt ) | |
| 332 | { | 337 | { | |
| 333 | return Ps::parse< r_url >( src, tgt ); | | | 338 | url_state tmp; |
| | | 339 | return Ps::parse< r_url >( src, tmp ) | ||
| | | 340 | ? ((tgt=tmp),true) | ||
| | | 341 | : false; | ||
| 334 | } | 342 | } | |
| 335 | 343 | |||
| 336 | }} // namespaces | 344 | }} // namespaces | |
| 337 | 345 | |||
| 338 | #endif // S11N_NET_PARSEPP_URL_H_INCLUDED | 346 | #endif // S11N_NET_PARSEPP_URL_H_INCLUDED | |