]> git.saurik.com Git - wxWidgets.git/blame - include/wx/uri.h
proper default for iphone
[wxWidgets.git] / include / wx / uri.h
CommitLineData
dd65d8c8 1/////////////////////////////////////////////////////////////////////////////
2186321f 2// Name: wx/uri.h
ed6d7010 3// Purpose: wxURI - Class for parsing URIs
dd65d8c8 4// Author: Ryan Norton
2186321f 5// Vadim Zeitlin (UTF-8 URI support, many other changes)
dd65d8c8 6// Created: 07/01/2004
2186321f
VZ
7// Copyright: (c) 2004 Ryan Norton
8// 2008 Vadim Zeitlin
99d80019 9// Licence: wxWindows Licence
dd65d8c8
RN
10/////////////////////////////////////////////////////////////////////////////
11
8404931e
VZ
12#ifndef _WX_URI_H_
13#define _WX_URI_H_
dd65d8c8 14
dd65d8c8
RN
15#include "wx/defs.h"
16#include "wx/object.h"
17#include "wx/string.h"
2adc95de 18#include "wx/arrstr.h"
dd65d8c8 19
ce321570 20// Host Type that the server component can be
8404931e 21enum wxURIHostType
dd65d8c8 22{
ed6d7010
DS
23 wxURI_REGNAME, // Host is a normal register name (www.mysite.com etc.)
24 wxURI_IPV4ADDRESS, // Host is a version 4 ip address (192.168.1.100)
ce321570 25 wxURI_IPV6ADDRESS, // Host is a version 6 ip address [aa:aa:aa:aa::aa:aa]:5050
ed6d7010 26 wxURI_IPVFUTURE // Host is a future ip address (wxURI is unsure what kind)
8404931e 27};
dd65d8c8
RN
28
29// Component Flags
8404931e 30enum wxURIFieldType
dd65d8c8
RN
31{
32 wxURI_SCHEME = 1,
4860d40d 33 wxURI_USERINFO = 2,
dd65d8c8
RN
34 wxURI_SERVER = 4,
35 wxURI_PORT = 8,
36 wxURI_PATH = 16,
37 wxURI_QUERY = 32,
38 wxURI_FRAGMENT = 64
8404931e
VZ
39};
40
41// Miscellaneous other flags
42enum wxURIFlags
43{
44 wxURI_STRICT = 1
45};
46
dd65d8c8
RN
47
48// Generic class for parsing URIs.
49//
4cc52142 50// See RFC 3986
fd1017cd 51class WXDLLIMPEXP_BASE wxURI : public wxObject
dd65d8c8
RN
52{
53public:
54 wxURI();
55 wxURI(const wxString& uri);
2186321f
VZ
56
57 // default copy ctor, assignment operator and dtor are ok
58
59 bool Create(const wxString& uri);
60
61 wxURI& operator=(const wxString& string)
62 {
63 Create(string);
64 return *this;
65 }
66
67 bool operator==(const wxURI& uri) const;
68
69 // various accessors
70
71 bool HasScheme() const { return (m_fields & wxURI_SCHEME) != 0; }
72 bool HasUserInfo() const { return (m_fields & wxURI_USERINFO) != 0; }
73 bool HasServer() const { return (m_fields & wxURI_SERVER) != 0; }
74 bool HasPort() const { return (m_fields & wxURI_PORT) != 0; }
75 bool HasPath() const { return (m_fields & wxURI_PATH) != 0; }
76 bool HasQuery() const { return (m_fields & wxURI_QUERY) != 0; }
77 bool HasFragment() const { return (m_fields & wxURI_FRAGMENT) != 0; }
78
79 const wxString& GetScheme() const { return m_scheme; }
80 const wxString& GetPath() const { return m_path; }
81 const wxString& GetQuery() const { return m_query; }
82 const wxString& GetFragment() const { return m_fragment; }
83 const wxString& GetPort() const { return m_port; }
84 const wxString& GetUserInfo() const { return m_userinfo; }
85 const wxString& GetServer() const { return m_server; }
86 wxURIHostType GetHostType() const { return m_hostType; }
87
88 // these functions only work if the user information part of the URI is in
89 // the usual (but insecure and hence explicitly recommended against by the
90 // RFC) "user:password" form
4860d40d
RN
91 wxString GetUser() const;
92 wxString GetPassword() const;
ed6d7010 93
dd65d8c8 94
2186321f
VZ
95 // combine all URI components into a single string
96 //
97 // BuildURI() returns the real URI suitable for use with network libraries,
98 // for example, while BuildUnescapedURI() returns a string suitable to be
99 // shown to the user.
100 wxString BuildURI() const { return DoBuildURI(&wxURI::Nothing); }
101 wxString BuildUnescapedURI() const { return DoBuildURI(&wxURI::Unescape); }
dd65d8c8 102
2186321f
VZ
103 // the escaped URI should contain only ASCII characters, including possible
104 // escape sequences
105 static wxString Unescape(const wxString& escapedURI);
86470d43 106
ed6d7010 107
2186321f
VZ
108 void Resolve(const wxURI& base, int flags = wxURI_STRICT);
109 bool IsReference() const;
dd65d8c8 110
2186321f 111protected:
dd65d8c8
RN
112 void Clear();
113
2186321f
VZ
114 // common part of BuildURI() and BuildUnescapedURI()
115 wxString DoBuildURI(wxString (*funcDecode)(const wxString&)) const;
116
117 // function which returns its argument unmodified, this is used by
118 // BuildURI() to tell DoBuildURI() that nothing needs to be done with the
119 // URI components
120 static wxString Nothing(const wxString& value) { return value; }
121
122 bool Parse(const char* uri);
123
124 const char* ParseAuthority (const char* uri);
125 const char* ParseScheme (const char* uri);
126 const char* ParseUserInfo (const char* uri);
127 const char* ParseServer (const char* uri);
128 const char* ParsePort (const char* uri);
129 const char* ParsePath (const char* uri);
130 const char* ParseQuery (const char* uri);
131 const char* ParseFragment (const char* uri);
132
133
134 static bool ParseH16(const char*& uri);
135 static bool ParseIPv4address(const char*& uri);
136 static bool ParseIPv6address(const char*& uri);
137 static bool ParseIPvFuture(const char*& uri);
138
139 // should be called with i pointing to '%', returns the encoded character
140 // following it or -1 if invalid and advances i past it (so that it points
141 // to the last character consumed on return)
142 static int DecodeEscape(wxString::const_iterator& i);
143
144 // append next character pointer to by p to the string in an escaped form
145 // and advance p past it
146 //
147 // if the next character is '%' and it's followed by 2 hex digits, they are
148 // not escaped (again) by this function, this allows to keep (backwards-
149 // compatible) ambiguity about the input format to wxURI::Create(): it can
150 // be either already escaped or not
151 void AppendNextEscaped(wxString& s, const char *& p);
152
153 // convert hexadecimal digit to its value; return -1 if c isn't valid
154 static int CharToHex(char c);
155
156 // split an URI path string in its component segments (including empty and
157 // "." ones, no post-processing is done)
158 static wxArrayString SplitInSegments(const wxString& path);
159
160 // various URI grammar helpers
161 static bool IsUnreserved(char c);
162 static bool IsReserved(char c);
163 static bool IsGenDelim(char c);
164 static bool IsSubDelim(char c);
165 static bool IsHex(char c);
166 static bool IsAlpha(char c);
167 static bool IsDigit(char c);
168 static bool IsEndPath(char c);
dd65d8c8
RN
169
170 wxString m_scheme;
171 wxString m_path;
172 wxString m_query;
173 wxString m_fragment;
174
4860d40d 175 wxString m_userinfo;
dd65d8c8
RN
176 wxString m_server;
177 wxString m_port;
178
179 wxURIHostType m_hostType;
180
181 size_t m_fields;
182
183 DECLARE_DYNAMIC_CLASS(wxURI)
8404931e
VZ
184};
185
186#endif // _WX_URI_H_
dd65d8c8 187