libcamgm
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 CA_MGM_URLUTILS_HPP
25 #define CA_MGM_URLUTILS_HPP
26 
27 #include <ca-mgm/config.h>
28 #include <ca-mgm/ByteBuffer.hpp>
29 #include <ca-mgm/Exception.hpp>
30 #include <ca-mgm/String.hpp>
31 
32 #include <map>
33 #include <vector>
34 
35 // -------------------------------------------------------------------
36 namespace CA_MGM_NAMESPACE
37 {
38 namespace url
39 {
40 
41 // -------------------------------------------------------------------
47 
48 
49 // -------------------------------------------------------------------
55 
56 
57 // -------------------------------------------------------------------
63 
64 
65 // -------------------------------------------------------------------
70 CA_MGM_DECLARE_EXCEPTION2(UrlBadComponent, UrlException);
71 
72 
73 // -------------------------------------------------------------------
79 
80 
81 // -------------------------------------------------------------------
87 CA_MGM_DECLARE_EXCEPTION2(UrlNotSupported, UrlException);
88 
89 
90 // -------------------------------------------------------------------
95 typedef std::map<std::string,std::string> ParamMap;
96 
97 
98 // -------------------------------------------------------------------
103 {
104  std::string scheme;
105  std::string authority;
106  std::string pathdata;
107  std::string querystr;
108  std::string fragment;
113 };
114 
115 
116 // -------------------------------------------------------------------
121 {
122  std::string user;
123  std::string pass;
124  std::string host;
125  std::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 std::string
168 encode(const std::string &str,
169  const std::string &safe = "",
171 
172 
173 // -------------------------------------------------------------------
184 std::string
185 encode_buf(const ca_mgm::ByteBuffer &buf,
186  const std::string &safe = "",
188 
189 
190 // -------------------------------------------------------------------
204 std::string
205 decode(const std::string &str);
206 
207 
208 // -------------------------------------------------------------------
225 decode_buf(const std::string &str, bool allowNUL);
226 
227 
228 // -------------------------------------------------------------------
238 std::string
239 encode_octet(const unsigned char c);
240 
241 
242 // -------------------------------------------------------------------
261 int
262 decode_octet(const char *hex);
263 
264 
265 // -------------------------------------------------------------------
279 std::vector<std::string>
280 split(const std::string &pstr,
281  const std::string &psep);
282 
283 
284 // -------------------------------------------------------------------
313 split(const std::string &pstr,
314  const std::string &psep,
315  const std::string &vsep,
316  EEncoding eflag = E_ENCODED);
317 
318 
319 // -------------------------------------------------------------------
333 std::string
334 join(const std::vector<std::string> &parr,
335  const std::string &psep);
336 
337 
338 // -------------------------------------------------------------------
360 std::string
361 join(const ca_mgm::url::ParamMap &pmap,
362  const std::string &psep,
363  const std::string &vsep,
364  const std::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 std::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 std::string &authority);
385 
386 
387 // -------------------------------------------------------------------
388 } // End url namespace
389 } // End of CA_MGM_NAMESPACE
390 #endif // CA_MGM_URLUTILS_HPP
391 // vim: set ts=8 sts=8 sw=8 ai noet:
Definition: UrlUtils.hpp:120
std::string decode(const std::string &str)
std::string authority
Definition: UrlUtils.hpp:105
UrlComponents parse_url_string(const std::string &url)
bool has_user
Definition: UrlUtils.hpp:126
#define CA_MGM_DECLARE_EXCEPTION2(NAME, BASE)
Definition: Exception.hpp:152
std::string querystr
Definition: UrlUtils.hpp:107
Definition: UrlUtils.hpp:102
bool has_authority
Definition: UrlUtils.hpp:110
std::string pathdata
Definition: UrlUtils.hpp:106
std::string pass
Definition: UrlUtils.hpp:123
std::string fragment
Definition: UrlUtils.hpp:108
unsigned split(const C_Str &line_r, _OutputIterator result_r, const C_Str &sepchars_r=" \t")
Definition: String.hpp:350
std::string join(_Iterator begin, _Iterator end, const C_Str &sep_r=" ")
Definition: String.hpp:591
bool has_pass
Definition: UrlUtils.hpp:127
std::string host
Definition: UrlUtils.hpp:124
std::string encode_octet(const unsigned char c)
bool has_querystr
Definition: UrlUtils.hpp:111
std::map< std::string, std::string > ParamMap
Definition: UrlUtils.hpp:95
bool has_scheme
Definition: UrlUtils.hpp:109
std::string scheme
Definition: UrlUtils.hpp:104
bool has_fragment
Definition: UrlUtils.hpp:112
LiMaL byte buffer class.
std::string encode(const std::string &str, const std::string &safe="", ca_mgm::url::EEncoding eflag=E_DECODED)
ca_mgm::ByteBuffer decode_buf(const std::string &str, bool allowNUL)
Common LiMaL exceptions.
Buffer for storing binary data.
Definition: ByteBuffer.hpp:55
int decode_octet(const char *hex)
UrlAuthority parse_url_authority(const std::string &authority)
std::string user
Definition: UrlUtils.hpp:122
std::string encode_buf(const ca_mgm::ByteBuffer &buf, const std::string &safe="", ca_mgm::url::EEncoding eflag=E_DECODED)
Flag to request decoded string(s).
Definition: UrlUtils.hpp:137
std::string port
Definition: UrlUtils.hpp:125
Flag to request encoded string(s).
Definition: UrlUtils.hpp:136
EEncoding
Definition: UrlUtils.hpp:135
bool has_port
Definition: UrlUtils.hpp:128
#define CA_MGM_DECLARE_EXCEPTION(NAME)
Definition: Exception.hpp:167