libzypp 17.31.23
UrlBase.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
12#ifndef ZYPP_URL_URLBASE_H
13#define ZYPP_URL_URLBASE_H
14
15#include <zypp-core/url/UrlUtils.h>
16#include <zypp-core/base/PtrTypes.h>
17
18
20namespace zypp
21{
22
24 namespace url
25 {
26
27
28 // ---------------------------------------------------------------
39 struct ViewOption
40 {
51 static const ViewOption WITH_SCHEME;
58 static const ViewOption WITH_USERNAME;
67 static const ViewOption WITH_PASSWORD;
74 static const ViewOption WITH_HOST;
81 static const ViewOption WITH_PORT;
87 static const ViewOption WITH_PATH_NAME;
95 static const ViewOption WITH_PATH_PARAMS;
101 static const ViewOption WITH_QUERY_STR;
107 static const ViewOption WITH_FRAGMENT;
121 static const ViewOption EMPTY_AUTHORITY;
133 static const ViewOption EMPTY_PATH_NAME;
143 static const ViewOption EMPTY_PATH_PARAMS;
154 static const ViewOption EMPTY_QUERY_STR;
165 static const ViewOption EMPTY_FRAGMENT;
177 static const ViewOption DEFAULTS;
184 ViewOption();
185
186
192 friend inline ViewOption
193 operator + (const ViewOption &l, const ViewOption &r)
194 {
195 return ViewOption(l.opt | r.opt);
196 }
197
203 friend inline ViewOption
204 operator - (const ViewOption &l, const ViewOption &r)
205 {
206 return ViewOption(l.opt & ~r.opt);
207 }
208
215 inline ViewOption &
216 operator = (const ViewOption &o)
217 {
218 opt = o.opt; return *this;
219 }
220
227 inline bool
228 has(const ViewOption &o) const
229 {
230 return o.opt & opt;
231 }
232
233 static const ViewOption hotfix1050625;
234 private:
235 ViewOption(int option);
236 int opt;
237 };
238
239
240 // ---------------------------------------------------------------
244 typedef ViewOption ViewOptions;
245
246
247 // ---------------------------------------------------------------
251 typedef std::vector<std::string> UrlSchemes;
252
253
254 // ---------------------------------------------------------------
258 class UrlBaseData;
259
260
261 // ---------------------------------------------------------------
270 class UrlBase
271 {
272 public:
273
274 virtual
275 ~UrlBase();
276
277 UrlBase();
278
283 UrlBase(const UrlBase &url);
284
299 UrlBase(const std::string &scheme,
300 const std::string &authority,
301 const std::string &pathdata,
302 const std::string &querystr,
303 const std::string &fragment);
304
305
306 // -----------------
310 virtual void
311 clear();
312
324 virtual UrlBase *
325 clone() const;
326
340 virtual void
341 init(const std::string &scheme,
342 const std::string &authority,
343 const std::string &pathdata,
344 const std::string &querystr,
345 const std::string &fragment);
346
347
348 // -----------------
366 virtual UrlSchemes
367 getKnownSchemes() const;
368
373 virtual bool
374 isKnownScheme(const std::string &scheme) const;
375
376
389 virtual bool
390 isValidScheme(const std::string &scheme) const;
391
401 virtual bool
402 isValid() const;
403
404
405 // -----------------
413 virtual std::string
414 asString() const;
415
428 virtual std::string
429 asString(const zypp::url::ViewOptions &opts) const;
430
431
432 // -----------------
437 virtual std::string
438 getScheme() const;
439
440
441 // -----------------
451 virtual std::string
452 getAuthority() const;
453
461 virtual std::string
462 getUsername(EEncoding eflag) const;
463
471 virtual std::string
472 getPassword(EEncoding eflag) const;
473
486 virtual std::string
487 getHost(EEncoding eflag) const;
488
493 virtual std::string
494 getPort() const;
495
496
497 // -----------------
507 virtual std::string
508 getPathData() const;
509
518 virtual std::string
519 getPathName(EEncoding eflag) const;
520
525 virtual std::string
526 getPathParams() const;
527
540 virtual zypp::url::ParamVec
541 getPathParamsVec() const;
542
562 virtual zypp::url::ParamMap
563 getPathParamsMap(EEncoding eflag) const;
564
581 virtual std::string
582 getPathParam(const std::string &param, EEncoding eflag) const;
583
584
585 // -----------------
595 virtual std::string
596 getQueryString() const;
597
599 virtual std::string
600 getQueryString( const ViewOptions & viewopts_r ) const;
601
615 virtual zypp::url::ParamVec
616 getQueryStringVec() const;
617
636 virtual zypp::url::ParamMap
637 getQueryStringMap(EEncoding eflag) const;
638
655 virtual std::string
656 getQueryParam(const std::string &param, EEncoding eflag) const;
657
658
659 // -----------------
667 virtual std::string
668 getFragment(EEncoding eflag) const;
669
670
671 // -----------------
678 virtual void
679 setScheme(const std::string &scheme);
680
681
682 // -----------------
696 virtual void
697 setAuthority(const std::string &authority);
698
708 virtual void
709 setUsername(const std::string &user,
710 EEncoding eflag);
711
721 virtual void
722 setPassword(const std::string &pass,
723 EEncoding eflag);
724
745 virtual void
746 setHost(const std::string &host);
747
755 virtual void
756 setPort(const std::string &port);
757
758
759 // -----------------
770 virtual void
771 setPathData(const std::string &pathdata);
772
780 virtual void
781 setPathName(const std::string &path,
782 EEncoding eflag);
783
790 virtual void
791 setPathParams(const std::string &params);
792
799 virtual void
801
808 virtual void
810
820 virtual void
821 setPathParam(const std::string &param, const std::string &value);
822
823
824 // -----------------
837 virtual void
838 setQueryString(const std::string &querystr);
839
846 virtual void
848
855 virtual void
857
867 virtual void
868 setQueryParam(const std::string &param, const std::string &value);
869
878 virtual void
879 delQueryParam(const std::string &param);
880
881
882 // -----------------
890 virtual void
891 setFragment(const std::string &fragment,
892 EEncoding eflag);
893
894
895 // -----------------
951 virtual void
952 configure();
953
954
965 std::string
966 config(const std::string &opt) const;
967
977 void
978 config(const std::string &opt, const std::string &val);
979
980
990 getViewOptions() const;
991
1000 void
1001 setViewOptions(const ViewOptions &vopts);
1002
1003 std::string asString1050625() const;
1004 protected:
1031 virtual std::string
1032 cleanupPathName(const std::string &path, bool authority) const;
1033
1044 virtual std::string
1045 cleanupPathName(const std::string &path) const;
1046
1068 virtual bool
1069 isValidHost(const std::string &host) const;
1070
1077 virtual bool
1078 isValidPort(const std::string &port) const;
1079
1080 private:
1081 UrlBaseData *m_data;
1082 };
1083
1084
1085 // ---------------------------------------------------------------
1089 typedef RWCOW_pointer<UrlBase> UrlRef;
1090
1091
1093 } // namespace url
1095
1097} // namespace zypp
1099
1100#endif /* ZYPP_URL_URLBASE_H */
1101/*
1102** vim: set ts=2 sts=2 sw=2 ai et:
1103*/
virtual UrlBase * clone() const
Returns pointer to a copy of the current object.
Definition: UrlBase.cc:407
virtual void setQueryString(const std::string &querystr)
Set the query string in the URL.
Definition: UrlBase.cc:970
virtual std::string getQueryString() const
Returns the encoded query string component of the URL.
Definition: UrlBase.cc:697
virtual std::string getPort() const
Returns the port number from the URL authority.
Definition: UrlBase.cc:754
virtual void setScheme(const std::string &scheme)
Set the scheme name in the URL.
Definition: UrlBase.cc:891
virtual void setHost(const std::string &host)
Set the hostname or IP in the URL authority.
Definition: UrlBase.cc:1082
virtual zypp::url::ParamMap getPathParamsMap(EEncoding eflag) const
Returns a string map with path parameter keys and values.
Definition: UrlBase.cc:802
virtual zypp::url::ParamVec getPathParamsVec() const
Returns a vector with encoded path parameter substrings.
Definition: UrlBase.cc:781
virtual std::string getUsername(EEncoding eflag) const
Returns the username from the URL authority.
Definition: UrlBase.cc:721
virtual UrlSchemes getKnownSchemes() const
Returns scheme names known by this object.
Definition: UrlBase.cc:415
virtual std::string getAuthority() const
Returns the encoded authority component of the URL.
Definition: UrlBase.cc:660
virtual void setQueryParam(const std::string &param, const std::string &value)
Set or add value for the specified query parameter.
Definition: UrlBase.cc:1323
std::string config(const std::string &opt) const
Get the value of a UrlBase configuration variable.
Definition: UrlBase.cc:367
virtual void setPathParamsVec(const zypp::url::ParamVec &pvec)
Set the path parameters.
Definition: UrlBase.cc:1244
virtual std::string getFragment(EEncoding eflag) const
Returns the encoded fragment component of the URL.
Definition: UrlBase.cc:710
virtual std::string getPathParams() const
Returns the encoded path parameters from the URL.
Definition: UrlBase.cc:773
virtual void setQueryStringMap(const zypp::url::ParamMap &qmap)
Set the query parameters.
Definition: UrlBase.cc:1302
virtual ~UrlBase()
Definition: UrlBase.cc:257
UrlBaseData * m_data
Definition: UrlBase.h:1081
virtual std::string getPassword(EEncoding eflag) const
Returns the password from the URL authority.
Definition: UrlBase.cc:732
virtual std::string getScheme() const
Returns the scheme name of the URL.
Definition: UrlBase.cc:652
virtual zypp::url::ParamMap getQueryStringMap(EEncoding eflag) const
Returns a string map with query parameter and their values.
Definition: UrlBase.cc:857
virtual void setUsername(const std::string &user, EEncoding eflag)
Set the username in the URL authority.
Definition: UrlBase.cc:1014
virtual std::string getPathParam(const std::string &param, EEncoding eflag) const
Return the value for the specified path parameter.
Definition: UrlBase.cc:825
virtual void configure()
Configures behaviour of the instance.
Definition: UrlBase.cc:314
virtual void setPathParamsMap(const zypp::url::ParamMap &pmap)
Set the path parameters.
Definition: UrlBase.cc:1257
virtual std::string cleanupPathName(const std::string &path, bool authority) const
Utility method to cleanup an encoded path name.
Definition: UrlBase.cc:1350
virtual bool isValidHost(const std::string &host) const
Verifies specified host or IP.
Definition: UrlBase.cc:1402
virtual std::string asString() const
Returns a default string representation of the Url object.
Definition: UrlBase.cc:504
virtual bool isKnownScheme(const std::string &scheme) const
Returns if scheme name is known to this object.
Definition: UrlBase.cc:423
virtual std::string getHost(EEncoding eflag) const
Returns the hostname or IP from the URL authority.
Definition: UrlBase.cc:743
virtual void setPathData(const std::string &pathdata)
Set the path data component in the URL.
Definition: UrlBase.cc:945
virtual void setPathName(const std::string &path, EEncoding eflag)
Set the path name.
Definition: UrlBase.cc:1167
virtual void setPort(const std::string &port)
Set the port number in the URL authority.
Definition: UrlBase.cc:1135
virtual std::string getPathData() const
Returns the encoded path component of the URL.
Definition: UrlBase.cc:687
virtual bool isValid() const
Verifies the Url.
Definition: UrlBase.cc:472
virtual std::string getPathName(EEncoding eflag) const
Returns the path name from the URL.
Definition: UrlBase.cc:762
virtual void setFragment(const std::string &fragment, EEncoding eflag)
Set the fragment string in the URL.
Definition: UrlBase.cc:987
virtual void clear()
Clears all data in the object.
Definition: UrlBase.cc:395
virtual bool isValidScheme(const std::string &scheme) const
Verifies specified scheme name.
Definition: UrlBase.cc:440
virtual zypp::url::ParamVec getQueryStringVec() const
Returns a vector with query string parameter substrings.
Definition: UrlBase.cc:836
virtual std::string getQueryParam(const std::string &param, EEncoding eflag) const
Return the value for the specified query parameter.
Definition: UrlBase.cc:880
void setViewOptions(const ViewOptions &vopts)
Change the view options of the current object.
Definition: UrlBase.cc:387
virtual void setQueryStringVec(const zypp::url::ParamVec &qvec)
Set the query parameters.
Definition: UrlBase.cc:1289
virtual void delQueryParam(const std::string &param)
remove the specified query parameter.
Definition: UrlBase.cc:1332
virtual void setPassword(const std::string &pass, EEncoding eflag)
Set the password in the URL authority.
Definition: UrlBase.cc:1048
virtual void setPathParam(const std::string &param, const std::string &value)
Set or add value for the specified path parameter.
Definition: UrlBase.cc:1279
virtual void init(const std::string &scheme, const std::string &authority, const std::string &pathdata, const std::string &querystr, const std::string &fragment)
Initializes current object with new URL components.
Definition: UrlBase.cc:294
virtual void setPathParams(const std::string &params)
Set the path parameters.
Definition: UrlBase.cc:1227
std::string asString1050625() const
Definition: UrlBase.cc:509
virtual void setAuthority(const std::string &authority)
Set the authority component in the URL.
Definition: UrlBase.cc:915
ViewOptions getViewOptions() const
Return the view options of the current object.
Definition: UrlBase.cc:379
virtual bool isValidPort(const std::string &port) const
Verifies specified port number.
Definition: UrlBase.cc:1431
RWCOW_pointer< UrlBase > UrlRef
Copy-On-Write Url reference.
Definition: UrlBase.h:1089
std::vector< std::string > UrlSchemes
Vector of URL scheme names.
Definition: UrlBase.h:251
std::map< std::string, std::string > ParamMap
A parameter map container.
Definition: UrlUtils.h:47
std::vector< std::string > ParamVec
A parameter vector container.
Definition: UrlUtils.h:40
ViewOption ViewOptions
ViewOptions is just an alias for ViewOption.
Definition: UrlBase.h:244
EEncoding
Encoding flags.
Definition: UrlUtils.h:52
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2
Url::asString() view options.
Definition: UrlBase.h:40
static const ViewOption WITH_SCHEME
Option to include scheme name in the URL string.
Definition: UrlBase.h:51
friend ViewOption operator+(const ViewOption &l, const ViewOption &r)
Adds l and r to a new option combination.
Definition: UrlBase.h:193
static const ViewOption WITH_PORT
Option to include port number in the URL string.
Definition: UrlBase.h:81
static const ViewOption EMPTY_QUERY_STR
Explicitely include the query string separator "?".
Definition: UrlBase.h:154
static const ViewOption WITH_PASSWORD
Option to include password in the URL string.
Definition: UrlBase.h:67
static const ViewOption WITH_PATH_PARAMS
Option to include path parameters in the URL string.
Definition: UrlBase.h:95
static const ViewOption WITH_FRAGMENT
Option to include fragment string in the URL string.
Definition: UrlBase.h:107
bool has(const ViewOption &o) const
Check if specified option o is set in the current object.
Definition: UrlBase.h:228
static const ViewOption EMPTY_PATH_NAME
Explicitely include the "/" path character.
Definition: UrlBase.h:133
static const ViewOption WITH_PATH_NAME
Option to include path name in the URL string.
Definition: UrlBase.h:87
static const ViewOption EMPTY_AUTHORITY
Explicitely include the URL authority separator "//".
Definition: UrlBase.h:121
static const ViewOption DEFAULTS
Default combination of view options.
Definition: UrlBase.h:177
static const ViewOption WITH_USERNAME
Option to include username in the URL string.
Definition: UrlBase.h:58
static const ViewOption EMPTY_FRAGMENT
Explicitely include the fragment string separator "#".
Definition: UrlBase.h:165
static const ViewOption hotfix1050625
Definition: UrlBase.h:233
static const ViewOption WITH_QUERY_STR
Option to include query string in the URL string.
Definition: UrlBase.h:101
ViewOption()
Create instance with default combination of view options.
Definition: UrlBase.cc:95
static const ViewOption WITH_HOST
Option to include hostname in the URL string.
Definition: UrlBase.h:74
static const ViewOption EMPTY_PATH_PARAMS
Explicitely include the path parameters separator ";".
Definition: UrlBase.h:143
friend ViewOption operator-(const ViewOption &l, const ViewOption &r)
Substract r from l to a new option combination.
Definition: UrlBase.h:204
ViewOption & operator=(const ViewOption &o)
Assign specified option combination o to the current object.
Definition: UrlBase.h:216