limal
UrlUtils.hpp
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | |
3 | _ _ _ _ __ _ |
4 | | | | | | \_/ | / \ | | |
5 | | | | | | |_| | / /\ \ | | |
6 | | |__ | | | | | | / ____ \ | |__ |
7 | |____||_| |_| |_|/ / \ \|____| |
8 | |
9 | core library |
10 | |
11 | (C) SUSE Linux Products GmbH |
12 \----------------------------------------------------------------------/
13 
14  File: UrlUtils.hpp
15 
16  Author: Marius Tomaschewski
17  Maintainer: Marius Tomaschewski
18 
19 /-*/
24 #ifndef LIMAL_URLUTILS_HPP
25 #define LIMAL_URLUTILS_HPP
26 
27 #include <limal/config.h>
28 #include <limal/ByteBuffer.hpp>
29 #include "blocxx/Exception.hpp"
30 #include <blocxx/String.hpp>
31 #include <blocxx/Array.hpp>
32 #include <blocxx/Map.hpp>
33 
34 
35 // -------------------------------------------------------------------
36 namespace LIMAL_NAMESPACE
37 {
38 namespace url
39 {
40 
41 // -------------------------------------------------------------------
46 BLOCXX_DECLARE_EXCEPTION (Url);
47 
48 
49 // -------------------------------------------------------------------
54 BLOCXX_DECLARE_EXCEPTION2(UrlParsing, UrlException);
55 
56 
57 // -------------------------------------------------------------------
62 BLOCXX_DECLARE_EXCEPTION2(UrlDecoding, UrlException);
63 
64 
65 // -------------------------------------------------------------------
70 BLOCXX_DECLARE_EXCEPTION2(UrlBadComponent, UrlException);
71 
72 
73 // -------------------------------------------------------------------
78 BLOCXX_DECLARE_EXCEPTION2(UrlNotAllowed, UrlException);
79 
80 
81 // -------------------------------------------------------------------
87 BLOCXX_DECLARE_EXCEPTION2(UrlNotSupported, UrlException);
88 
89 
90 // -------------------------------------------------------------------
95 typedef blocxx::Map<blocxx::String,blocxx::String> ParamMap;
96 
97 
98 // -------------------------------------------------------------------
103 {
104  blocxx::String scheme;
105  blocxx::String authority;
106  blocxx::String pathdata;
107  blocxx::String querystr;
108  blocxx::String fragment;
113 };
114 
115 
116 // -------------------------------------------------------------------
121 {
122  blocxx::String user;
123  blocxx::String pass;
124  blocxx::String host;
125  blocxx::String port;
126  bool has_user;
127  bool has_pass;
128  bool has_port;
129 };
130 
131 
132 // -------------------------------------------------------------------
135 typedef enum {
138 } EEncoding;
139 
140 
141 // -------------------------------------------------------------------
167 blocxx::String
168 encode(const blocxx::String &str,
169  const blocxx::String &safe = "",
171 
172 
173 // -------------------------------------------------------------------
184 blocxx::String
185 encode_buf(const limal::ByteBuffer &buf,
186  const blocxx::String &safe = "",
188 
189 
190 // -------------------------------------------------------------------
204 blocxx::String
205 decode(const blocxx::String &str);
206 
207 
208 // -------------------------------------------------------------------
225 decode_buf(const blocxx::String &str, bool allowNUL);
226 
227 
228 // -------------------------------------------------------------------
238 blocxx::String
239 encode_octet(const unsigned char c);
240 
241 
242 // -------------------------------------------------------------------
261 int
262 decode_octet(const char *hex);
263 
264 
265 // -------------------------------------------------------------------
279 blocxx::StringArray
280 split(const blocxx::String &pstr,
281  const blocxx::String &psep);
282 
283 
284 // -------------------------------------------------------------------
313 split(const blocxx::String &pstr,
314  const blocxx::String &psep,
315  const blocxx::String &vsep,
316  EEncoding eflag = E_ENCODED);
317 
318 
319 // -------------------------------------------------------------------
333 blocxx::String
334 join(const blocxx::StringArray &parr,
335  const blocxx::String &psep);
336 
337 
338 // -------------------------------------------------------------------
360 blocxx::String
361 join(const limal::url::ParamMap &pmap,
362  const blocxx::String &psep,
363  const blocxx::String &vsep,
364  const blocxx::String &safe);
365 
366 
367 // -------------------------------------------------------------------
368 /*
369  * Parse the @p url string by common URL separator characters
370  * and return an url main component structure.
371  * @returns An url components structure.
372  */
373 UrlComponents
374 parse_url_string(const blocxx::String &url);
375 
376 
377 // -------------------------------------------------------------------
378 /*
379  * Parse the @p authority string and return the URL authority
380  * components structure.
381  * @returns An string array containing authority components.
382  */
383 UrlAuthority
384 parse_url_authority(const blocxx::String &authority);
385 
386 
387 // -------------------------------------------------------------------
388 } // End url namespace
389 } // End of LIMAL_NAMESPACE
390 #endif // LIMAL_URLUTILS_HPP
391 // vim: set ts=8 sts=8 sw=8 ai noet: