- More documentation.
[platform/upstream/libzypp.git] / zypp / url / UrlBase.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /**
10  * \file zypp/url/UrlBase.h
11  */
12 #ifndef   ZYPP_URL_URLBASE_H
13 #define   ZYPP_URL_URLBASE_H
14
15 #include <zypp/url/UrlUtils.h>
16 #include <zypp/base/PtrTypes.h>
17
18
19 //////////////////////////////////////////////////////////////////////
20 namespace zypp
21 { ////////////////////////////////////////////////////////////////////
22
23   ////////////////////////////////////////////////////////////////////
24   namespace url
25   { //////////////////////////////////////////////////////////////////
26
27
28     // ---------------------------------------------------------------
29     /** Url behaviour configuration container.
30      */
31     typedef std::map< std::string, std::string > UrlConfig;
32
33
34     // ---------------------------------------------------------------
35     /** Url toString() view options.
36      */
37     struct ViewOption
38     {
39       /**
40         * @{
41         * Flags 
42         */
43       static const ViewOption WITH_SCHEME;
44       static const ViewOption WITH_USERNAME;
45       static const ViewOption WITH_PASSWORD;
46       static const ViewOption WITH_HOST;
47       static const ViewOption WITH_PORT;
48       static const ViewOption WITH_PATH_NAME;
49       static const ViewOption WITH_PATH_PARAMS;
50       static const ViewOption WITH_QUERY_STR;
51       static const ViewOption WITH_FRAGMENT;
52       /* @} */
53
54       /**
55        * @{
56        * With Empty flags.
57        */
58       static const ViewOption EMPTY_AUTHORITY;
59       static const ViewOption EMPTY_PATH_NAME;
60       static const ViewOption EMPTY_PATH_PARAMS;
61       static const ViewOption EMPTY_QUERY_STR;
62       static const ViewOption EMPTY_FRAGMENT;
63       /* @} */
64
65       /** Default combination of view options.
66        */
67       static const ViewOption DEFAULTS;
68
69       ViewOption(): opt(DEFAULTS.opt)
70       {}
71
72       /** @return The result of a add of \p r from \p l.
73        */
74       friend inline ViewOption
75       operator + (const ViewOption &l, const ViewOption &r)
76       { return ViewOption(l.opt |  r.opt); }
77
78       /** @return The result of a subtract of \p r from \p l.
79        */
80       friend inline ViewOption
81       operator - (const ViewOption &l, const ViewOption &r)
82       { return ViewOption(l.opt & ~r.opt); }
83
84       /** Check if option is set.
85        * \param o    A view option.
86        * \return True, if the current options bitwise matches
87        *         the specified one.
88        */
89       inline bool
90       has(const ViewOption &o) const
91       { return o.opt & opt; }
92
93     private:
94       ViewOption(int o): opt(o) {}
95       int opt;
96     };
97
98
99     // ---------------------------------------------------------------
100     typedef ViewOption ViewOptions;
101
102
103     // ---------------------------------------------------------------
104     /**
105      * FIXME:
106      */
107     class UrlData
108     {
109     public:
110       /**
111        * FIXME:
112        */
113       UrlData()
114       {}
115
116       /**
117        * FIXME:
118        */
119       UrlData(const UrlConfig &conf)
120         : config(conf)
121       {}
122
123       /**
124        * FIXME:
125        */
126       UrlConfig       config;
127       ViewOptions     vopts;
128
129       std::string     scheme;
130       std::string     user;
131       std::string     pass;
132       std::string     host;
133       std::string     port;
134       std::string     pathname;
135       std::string     pathparams;
136       std::string     querystr;
137       std::string     fragment;
138     };
139
140
141     // ---------------------------------------------------------------
142     /**
143      * FIXME:
144      */
145     class UrlBase
146     {
147     public:
148       /**
149        * FIXME:
150        */
151       typedef std::vector<std::string>        Schemes;
152
153       /**
154        * FIXME:
155        */
156       UrlBase();
157
158       /**
159        * FIXME:
160        */
161       UrlBase(const UrlBase &url);
162
163       /**
164        * FIXME:
165        */
166       UrlBase(const std::string &scheme,
167               const std::string &authority,
168               const std::string &pathdata,
169               const std::string &querystr,
170               const std::string &fragment);
171
172       /**
173        * FIXME:
174        */
175       virtual ~UrlBase();
176
177       /**
178        * FIXME:
179        */
180       virtual void
181       clear();
182
183       /**
184        * FIXME:
185        */
186       virtual UrlBase *
187       clone() const;
188
189       /**
190        * FIXME:
191        */
192       virtual void
193       init(const std::string &scheme,
194            const std::string &authority,
195            const std::string &pathdata,
196            const std::string &querystr,
197            const std::string &fragment);
198
199       /**
200        * FIXME:
201        */
202       virtual UrlBase::Schemes
203       getKnownSchemes() const;
204
205       /**
206        * FIXME:
207        */
208       virtual bool
209       isKnownScheme(const std::string &scheme) const;
210
211       /**
212        * FIXME:
213        */
214       virtual bool
215       isValidScheme(const std::string &scheme) const;
216
217
218       /**
219        * FIXME:
220        */
221       virtual bool
222       isValid() const;
223
224
225       /**
226        * FIXME:
227        * TODO: hide pass, ...
228        */
229       virtual std::string
230       toString() const;
231
232       virtual std::string
233       toString(const zypp::url::ViewOptions &opts) const;
234
235
236       // -----------------
237       virtual std::string
238       getScheme() const;
239
240       virtual std::string
241       getAuthority() const;
242
243       virtual std::string
244       getPathData() const;
245
246       virtual std::string
247       getQueryString() const;
248
249       virtual std::string
250       getFragment(EEncoding eflag) const;
251
252
253       // -----------------
254       virtual std::string
255       getUsername(EEncoding eflag) const;
256
257       virtual std::string
258       getPassword(EEncoding eflag) const;
259
260       virtual std::string
261       getHost(EEncoding eflag) const;
262
263       virtual std::string
264       getPort() const;
265
266       virtual std::string
267       getPathName(EEncoding eflag) const;
268
269       virtual std::string
270       getPathParams() const;
271
272
273       // -----------------
274       virtual zypp::url::ParamVec
275       getPathParamsVec() const;
276
277       virtual zypp::url::ParamMap
278       getPathParamsMap(EEncoding eflag) const;
279
280       virtual std::string
281       getPathParam(const std::string &param, EEncoding eflag) const;
282
283
284       virtual zypp::url::ParamVec
285       getQueryStringVec() const;
286
287       virtual zypp::url::ParamMap
288       getQueryStringMap(EEncoding eflag) const;
289
290       virtual std::string
291       getQueryParam(const std::string &param, EEncoding eflag) const;
292
293
294       // -----------------
295       virtual void
296       setScheme(const std::string &scheme);
297
298       virtual void
299       setAuthority(const std::string &authority);
300
301       virtual void
302       setPathData(const std::string &pathdata);
303
304       virtual void
305       setQueryString(const std::string &querystr);
306
307       virtual void
308       setFragment(const std::string &fragment);
309
310
311       // -----------------
312       virtual void
313       setUsername(const std::string &user);
314
315       virtual void
316       setPassword(const std::string &pass);
317
318       virtual void
319       setHost(const std::string &host);
320
321       virtual void
322       setPort(const std::string &port);
323
324       virtual void
325       setPathName(const std::string &path);
326
327       virtual void
328       setPathParams(const std::string &params);
329
330
331       // -----------------
332       virtual void
333       setPathParamsVec(const zypp::url::ParamVec &pvec);
334
335       virtual void
336       setPathParamsMap(const zypp::url::ParamMap &pmap);
337
338       virtual void
339       setPathParam(const std::string &param, const std::string &value);
340
341       virtual void
342       setQueryStringVec(const zypp::url::ParamVec &pmap);
343
344       virtual void
345       setQueryStringMap(const zypp::url::ParamMap &pmap);
346
347       virtual void
348       setQueryParam(const std::string &param, const std::string &value);
349
350
351       // -----------------
352       virtual void
353       configure();
354
355       std::string
356       config(const std::string &opt) const;
357
358     //protected:
359       // friend class Url;
360       void
361       config(const std::string &opt, const std::string &val);
362
363       ViewOptions
364       getViewOptions() const;
365
366       void
367       setViewOptions(const ViewOptions &vopts);
368
369     private:
370       UrlData        *m_data;
371     };
372
373
374     // ---------------------------------------------------------------
375     typedef RWCOW_pointer<UrlBase>          UrlRef;
376
377
378     //////////////////////////////////////////////////////////////////
379   } // namespace url
380   ////////////////////////////////////////////////////////////////////
381
382   ////////////////////////////////////////////////////////////////////
383 } // namespace zypp
384 //////////////////////////////////////////////////////////////////////
385
386 #endif /* ZYPP_URL_URLBASE_H */
387 /*
388 ** vim: set ts=2 sts=2 sw=2 ai et:
389 */