Mercurial > projects > hoofbaby
comparison deps/Platinum/ThirdParty/Neptune/Source/Core/NptUri.h @ 0:3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
author | fraserofthenight |
---|---|
date | Mon, 06 Jul 2009 08:06:28 -0700 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:3425707ddbf6 |
---|---|
1 /***************************************************************** | |
2 | | |
3 | Neptune - URI | |
4 | | |
5 | Copyright (c) 2002-2008, Axiomatic Systems, LLC. | |
6 | All rights reserved. | |
7 | | |
8 | Redistribution and use in source and binary forms, with or without | |
9 | modification, are permitted provided that the following conditions are met: | |
10 | * Redistributions of source code must retain the above copyright | |
11 | notice, this list of conditions and the following disclaimer. | |
12 | * Redistributions in binary form must reproduce the above copyright | |
13 | notice, this list of conditions and the following disclaimer in the | |
14 | documentation and/or other materials provided with the distribution. | |
15 | * Neither the name of Axiomatic Systems nor the | |
16 | names of its contributors may be used to endorse or promote products | |
17 | derived from this software without specific prior written permission. | |
18 | | |
19 | THIS SOFTWARE IS PROVIDED BY AXIOMATIC SYSTEMS ''AS IS'' AND ANY | |
20 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
22 | DISCLAIMED. IN NO EVENT SHALL AXIOMATIC SYSTEMS BE LIABLE FOR ANY | |
23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |
26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |
28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
29 | | |
30 ****************************************************************/ | |
31 | |
32 #ifndef _NPT_URI_H_ | |
33 #define _NPT_URI_H_ | |
34 | |
35 /*---------------------------------------------------------------------- | |
36 | includes | |
37 +---------------------------------------------------------------------*/ | |
38 #include "NptStrings.h" | |
39 #include "NptList.h" | |
40 | |
41 /*---------------------------------------------------------------------- | |
42 | constants | |
43 +---------------------------------------------------------------------*/ | |
44 const NPT_UInt16 NPT_URL_INVALID_PORT = 0; | |
45 | |
46 /*---------------------------------------------------------------------- | |
47 | NPT_Uri | |
48 +---------------------------------------------------------------------*/ | |
49 class NPT_Uri { | |
50 public: | |
51 // types | |
52 typedef enum { | |
53 SCHEME_ID_UNKNOWN, | |
54 SCHEME_ID_HTTP | |
55 } SchemeId; | |
56 | |
57 // constants. use as a parameter to Encode() | |
58 static const char* const PathCharsToEncode; | |
59 static const char* const QueryCharsToEncode; | |
60 static const char* const FragmentCharsToEncode; | |
61 static const char* const UnsafeCharsToEncode; | |
62 | |
63 // class methods | |
64 static NPT_String PercentEncode(const char* str, const char* chars, bool encode_percents=true); | |
65 static NPT_String PercentDecode(const char* str); | |
66 static SchemeId ParseScheme(const NPT_String& scheme); | |
67 | |
68 // methods | |
69 NPT_Uri() : m_SchemeId(SCHEME_ID_UNKNOWN) {} | |
70 virtual ~NPT_Uri() {} | |
71 const NPT_String& GetScheme() const { | |
72 return m_Scheme; | |
73 } | |
74 void SetScheme(const char* scheme); | |
75 NPT_Result SetSchemeFromUri(const char* uri); | |
76 SchemeId GetSchemeId() const { | |
77 return m_SchemeId; | |
78 } | |
79 | |
80 protected: | |
81 // members | |
82 NPT_String m_Scheme; | |
83 SchemeId m_SchemeId; | |
84 }; | |
85 | |
86 /*---------------------------------------------------------------------- | |
87 | NPT_UrlQuery | |
88 +---------------------------------------------------------------------*/ | |
89 class NPT_UrlQuery | |
90 { | |
91 public: | |
92 // class methods | |
93 static NPT_String UrlEncode(const char* str, bool encode_percents=true); | |
94 static NPT_String UrlDecode(const char* str); | |
95 | |
96 // types | |
97 struct Field { | |
98 Field(const char* name, const char* value) : | |
99 m_Name(name), m_Value(value) {} | |
100 NPT_String m_Name; | |
101 NPT_String m_Value; | |
102 }; | |
103 | |
104 // constructor | |
105 NPT_UrlQuery() {} | |
106 NPT_UrlQuery(const char* query); | |
107 | |
108 // accessors | |
109 NPT_List<Field>& GetFields() { return m_Fields; } | |
110 | |
111 // methods | |
112 NPT_Result Parse(const char* query); | |
113 NPT_Result AddField(const char* name, const char* value); | |
114 const char* GetField(const char* name); | |
115 NPT_String ToString(); | |
116 | |
117 private: | |
118 // members | |
119 NPT_List<Field> m_Fields; | |
120 }; | |
121 | |
122 /*---------------------------------------------------------------------- | |
123 | NPT_Url | |
124 +---------------------------------------------------------------------*/ | |
125 class NPT_Url : public NPT_Uri { | |
126 public: | |
127 // constructors and destructor | |
128 NPT_Url(); | |
129 NPT_Url(const char* url, | |
130 SchemeId expected_scheme = SCHEME_ID_UNKNOWN, | |
131 NPT_UInt16 default_port = NPT_URL_INVALID_PORT); | |
132 NPT_Url(const char* scheme, | |
133 const char* host, | |
134 NPT_UInt16 port, | |
135 const char* path, | |
136 const char* query = NULL, | |
137 const char* fragment = NULL); | |
138 | |
139 // methods | |
140 const NPT_String& GetHost() const { return m_Host; } | |
141 NPT_UInt16 GetPort() const { return m_Port; } | |
142 const NPT_String& GetPath() const { return m_Path; } | |
143 const NPT_String& GetQuery() const { return m_Query; } | |
144 const NPT_String& GetFragment() const { return m_Fragment; } | |
145 virtual bool IsValid() const; | |
146 bool HasQuery() const { return m_HasQuery; } | |
147 bool HasFragment() const { return m_HasFragment; } | |
148 NPT_Result SetHost(const char* host); | |
149 NPT_Result SetPort(NPT_UInt16 port); | |
150 NPT_Result SetPath(const char* path); | |
151 NPT_Result SetPathPlus(const char* path_plus); | |
152 NPT_Result SetQuery(const char* query); | |
153 NPT_Result SetFragment(const char* fragment); | |
154 virtual NPT_String ToRequestString(bool with_fragment = false) const; | |
155 virtual NPT_String ToStringWithDefaultPort(NPT_UInt16 default_port, bool with_fragment = true) const; | |
156 virtual NPT_String ToString(bool with_fragment = true) const; | |
157 | |
158 protected: | |
159 // members | |
160 NPT_String m_Host; | |
161 NPT_UInt16 m_Port; | |
162 NPT_String m_Path; | |
163 bool m_HasQuery; | |
164 NPT_String m_Query; | |
165 bool m_HasFragment; | |
166 NPT_String m_Fragment; | |
167 }; | |
168 | |
169 #endif // _NPT_URI_H_ |