bin/pc: Mark non-returning function as void
[haiku.git] / headers / os / support / Url.h
blobda1a44e91330915bb3cc9b54f69d21f8f5505d75
1 /*
2 * Copyright 2010-2016 Haiku Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 */
5 #ifndef _B_URL_H_
6 #define _B_URL_H_
9 #include <Archivable.h>
10 #include <Message.h>
11 #include <Path.h>
12 #include <String.h>
15 class BUrl : public BArchivable {
16 public:
17 BUrl(const char* url);
18 BUrl(BMessage* archive);
19 BUrl(const BUrl& other);
20 BUrl(const BUrl& base, const BString& relative);
21 BUrl(const BPath& path);
22 BUrl();
23 virtual ~BUrl();
25 // URL fields modifiers
26 BUrl& SetUrlString(const BString& url);
27 BUrl& SetProtocol(const BString& scheme);
28 BUrl& SetUserName(const BString& user);
29 BUrl& SetPassword(const BString& password);
30 void SetAuthority(const BString& authority);
31 BUrl& SetHost(const BString& host);
32 BUrl& SetPort(int port);
33 BUrl& SetPath(const BString& path);
34 BUrl& SetRequest(const BString& request);
35 BUrl& SetFragment(const BString& fragment);
37 // URL fields access
38 const BString& UrlString() const;
39 const BString& Protocol() const;
40 const BString& UserName() const;
41 const BString& Password() const;
42 const BString& UserInfo() const;
43 const BString& Host() const;
44 int Port() const;
45 const BString& Authority() const;
46 const BString& Path() const;
47 const BString& Request() const;
48 const BString& Fragment() const;
50 // URL fields tests
51 bool IsValid() const;
52 bool HasProtocol() const;
53 bool HasUserName() const;
54 bool HasPassword() const;
55 bool HasUserInfo() const;
56 bool HasHost() const;
57 bool HasPort() const;
58 bool HasAuthority() const;
59 bool HasPath() const;
60 bool HasRequest() const;
61 bool HasFragment() const;
63 // Url encoding/decoding of needed fields
64 void UrlEncode(bool strict = false);
65 void UrlDecode(bool strict = false);
67 #ifdef HAIKU_TARGET_PLATFORM_HAIKU
68 status_t IDNAToAscii();
69 status_t IDNAToUnicode();
70 #endif
72 // Url encoding/decoding of strings
73 static BString UrlEncode(const BString& url,
74 bool strict = false,
75 bool directory = false);
76 static BString UrlDecode(const BString& url,
77 bool strict = false);
79 #ifdef HAIKU_TARGET_PLATFORM_HAIKU
80 // utility functionality
81 bool HasPreferredApplication() const;
82 BString PreferredApplication() const;
83 status_t OpenWithPreferredApplication(
84 bool onProblemAskUser = true) const;
85 #endif
87 // BArchivable members
88 virtual status_t Archive(BMessage* into,
89 bool deep = true) const;
90 static BArchivable* Instantiate(BMessage* archive);
92 // URL comparison
93 bool operator==(BUrl& other) const;
94 bool operator!=(BUrl& other) const;
96 // URL assignment
97 const BUrl& operator=(const BUrl& other);
98 const BUrl& operator=(const BString& string);
99 const BUrl& operator=(const char* string);
101 // URL to string conversion
102 operator const char*() const;
104 private:
105 void _ResetFields();
106 bool _ContainsDelimiter(const BString& url);
107 status_t _ExplodeUrlString(const BString& urlString);
108 BString _MergePath(const BString& relative) const;
109 void _SetPathUnsafe(const BString& path);
111 static BString _DoUrlEncodeChunk(const BString& chunk,
112 bool strict, bool directory = false);
113 static BString _DoUrlDecodeChunk(const BString& chunk,
114 bool strict);
116 bool _IsProtocolValid();
117 static bool _IsUnreserved(char c);
118 static bool _IsGenDelim(char c);
119 static bool _IsSubDelim(char c);
121 BString _UrlMimeType() const;
123 private:
124 mutable BString fUrlString;
125 mutable BString fAuthority;
126 mutable BString fUserInfo;
128 BString fProtocol;
129 BString fUser;
130 BString fPassword;
131 BString fHost;
132 int fPort;
133 BString fPath;
134 BString fRequest;
135 BString fFragment;
137 mutable bool fUrlStringValid : 1;
138 mutable bool fAuthorityValid : 1;
139 mutable bool fUserInfoValid : 1;
141 bool fHasProtocol : 1;
142 bool fHasUserName : 1;
143 bool fHasPassword : 1;
144 bool fHasHost : 1;
145 bool fHasPort : 1;
146 bool fHasPath : 1;
147 bool fHasRequest : 1;
148 bool fHasFragment : 1;
151 #endif // _B_URL_H_