~ubuntu-branches/debian/experimental/gpac/experimental

« back to all changes in this revision

Viewing changes to extra_lib/include/platinum/NptUri.h

  • Committer: Package Import Robot
  • Author(s): Reinhard Tartler
  • Date: 2014-02-22 18:15:00 UTC
  • mfrom: (1.2.2) (3.1.6 sid)
  • Revision ID: package-import@ubuntu.com-20140222181500-b4phupo05gjpmopa
Tags: 0.5.0+svn5104~dfsg1-1
* New  upstream version 0.5.0+svn5104~dfsg1:
  - src/utils/sha1.c is relicensed under LGPLv2.1, Closes: #730759
* Don't install modules in multi-arch directories, Closes: #730497
* Add libusb-1.0.0-dev headers because libfreenect requires this
* Fix install rule
* Follow upstream soname bump
  - Drop the symbols file for now until it has been revised thourougly
* Let binaries produce the correct svn revision
* Refresh patches
* Patch and build against libav10, Closes: #739321
* Bump standards version, no changes necessary

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
/*----------------------------------------------------------------------
42
42
|   constants
43
43
+---------------------------------------------------------------------*/
44
 
const NPT_UInt16 NPT_URL_INVALID_PORT = 0;
 
44
const NPT_UInt16 NPT_URL_INVALID_PORT       = 0;
 
45
const NPT_UInt16 NPT_URL_DEFAULT_HTTP_PORT  = 80;
 
46
const NPT_UInt16 NPT_URL_DEFAULT_HTTPS_PORT = 443;
45
47
 
46
48
/*----------------------------------------------------------------------
47
49
|   NPT_Uri
51
53
    // types
52
54
    typedef enum {
53
55
        SCHEME_ID_UNKNOWN,
54
 
        SCHEME_ID_HTTP
 
56
        SCHEME_ID_HTTP,
 
57
        SCHEME_ID_HTTPS
55
58
    } SchemeId;
56
59
 
57
60
    // constants. use as a parameter to Encode()
95
98
    
96
99
    // types
97
100
    struct Field {
98
 
        Field(const char* name, const char* value) :
99
 
            m_Name(name), m_Value(value) {}
 
101
        Field(const char* name, const char* value, bool encoded);
100
102
        NPT_String m_Name;
101
103
        NPT_String m_Value;
102
104
    };
110
112
 
111
113
    // methods
112
114
    NPT_Result  Parse(const char* query);
113
 
    NPT_Result  SetField(const char* name, const char* value);
114
 
    NPT_Result  AddField(const char* name, const char* value);
 
115
    NPT_Result  SetField(const char* name, const char* value, bool encoded=false);
 
116
    NPT_Result  AddField(const char* name, const char* value, bool encoded=false);
115
117
    const char* GetField(const char* name);
116
118
    NPT_String  ToString();
117
119
 
125
127
+---------------------------------------------------------------------*/
126
128
class NPT_Url : public NPT_Uri {
127
129
public:
128
 
    // constructors and destructor
 
130
    /**
 
131
     * Default constructor. This does not construct a valid URL, but an
 
132
     * uninitialized one that can later be initialized to a valid URL by
 
133
     * parsing or setting some of its fields.
 
134
     */
129
135
    NPT_Url();
130
 
    NPT_Url(const char* url, 
131
 
            SchemeId    expected_scheme = SCHEME_ID_UNKNOWN, 
132
 
            NPT_UInt16  default_port = NPT_URL_INVALID_PORT);
 
136
    
 
137
    /**
 
138
     * Construct a URL by parsing an input string in its fully encoded form.
 
139
     * If an error occurs during parsing (such as an invalid syntax), the
 
140
     * URL will be in an invalid state (a call to IsValid() will return false).
 
141
     *
 
142
     * @param url The URL string in its encoded form
 
143
     * @param default_port The default port number, or 0 if not specified
 
144
     */
 
145
    NPT_Url(const char* url, NPT_UInt16  default_port = 0);
 
146
    
 
147
    /**
 
148
     * Construct a URL from its components. When constructing a URL from
 
149
     * components, the components are assumed to be passed in their non-encoded
 
150
     * form, and will thus be encoded automatically.
 
151
     *
 
152
     * @param scheme The URL scheme
 
153
     * @param port The port number
 
154
     * @param path The path
 
155
     * @param query The query, if any, or NULL
 
156
     * @param fragment The fragment, if any, or NULL
 
157
     */
133
158
    NPT_Url(const char* scheme,
134
159
            const char* host, 
135
160
            NPT_UInt16  port, 
137
162
            const char* query = NULL,
138
163
            const char* fragment = NULL);
139
164
 
140
 
    // methods
141
 
    const NPT_String&  GetHost() const     { return m_Host;     }
142
 
    NPT_UInt16         GetPort() const     { return m_Port;     }
143
 
    const NPT_String&  GetPath() const     { return m_Path;     }
144
 
    const NPT_String&  GetQuery() const    { return m_Query;    }
145
 
    const NPT_String&  GetFragment() const { return m_Fragment; }
146
 
    virtual bool       IsValid() const;
147
 
    bool               HasQuery()    const { return m_HasQuery;    } 
148
 
    bool               HasFragment() const { return m_HasFragment; }
149
 
    NPT_Result         SetHost(const char*  host);
150
 
    NPT_Result         SetPort(NPT_UInt16 port);
151
 
    NPT_Result         SetPath(const char* path);
152
 
    NPT_Result         SetPathPlus(const char* path_plus);
153
 
    NPT_Result         SetQuery(const char* query);
154
 
    NPT_Result         SetFragment(const char* fragment);
 
165
    /**
 
166
     * Parse a URL from its fully encoded form.
 
167
     *
 
168
     * @param url The URL string in its encoded form
 
169
     * @param default port The defautl port number, or 0 if not specified
 
170
     */
 
171
    NPT_Result Parse(const char* url, NPT_UInt16  default_port = 0);
 
172
    
 
173
    /**
 
174
     * Parse just the path plus optional query and fragment from a fully encoded form.
 
175
     *
 
176
     * @param path_plus The URL path plus optional query and fragment
 
177
     */
 
178
    NPT_Result ParsePathPlus(const char* path_plus);
 
179
    
 
180
    /**
 
181
     * Returns the host part of the URL, in its encoded form
 
182
     */
 
183
    const NPT_String& GetHost() const { return m_Host;     }
 
184
    
 
185
    /**
 
186
     * Returns the port number of the URL.
 
187
     */
 
188
    NPT_UInt16 GetPort() const { return m_Port;     }
 
189
 
 
190
    /**
 
191
     * Returns the path part of the URL, in its encoded form
 
192
     */
 
193
    const NPT_String& GetPath() const { return m_Path; }
 
194
    
 
195
    /**
 
196
     * Returns the path part of the URL, in its encoded or decoded form
 
197
     */
 
198
    NPT_String GetPath(bool decoded) const { return decoded?NPT_Uri::PercentDecode(m_Path):m_Path;}
 
199
 
 
200
    /**
 
201
     * Returns the query part of the URL, in its encoded form
 
202
     */
 
203
    const NPT_String& GetQuery() const { return m_Query; }
 
204
    
 
205
    /**
 
206
     * Returns the fragment part of the URL, in its encoded form
 
207
     */
 
208
    const NPT_String& GetFragment() const { return m_Fragment; }
 
209
    
 
210
    /**
 
211
     * Returns whether the URL is valid or not. Invalid URLs are uninitialized or
 
212
     * not fully initialized URLs.
 
213
     *
 
214
     * @return true if the URL is valid, false if it is not.
 
215
     */
 
216
    virtual bool IsValid() const;
 
217
    
 
218
    /**
 
219
     * Resets a URL to an uninitialized state.
 
220
     */
 
221
    void Reset();
 
222
    
 
223
    /**
 
224
     * Returns whether the URL has a query part or not.
 
225
     *
 
226
     * @return true if the URL has a query part, false if it does not.
 
227
     */
 
228
    bool HasQuery() const { return m_HasQuery; } 
 
229
 
 
230
    /**
 
231
     * Returns whether the URL has a fragment part or not.
 
232
     *
 
233
     * @return true if the URL has a fragment part, false if it does not.
 
234
     */
 
235
    bool HasFragment() const { return m_HasFragment; }
 
236
 
 
237
    /**
 
238
     * Sets the host part of the URL.
 
239
     *
 
240
     * @param host The host part of the URL
 
241
     */
 
242
    NPT_Result SetHost(const char* host);
 
243
    
 
244
    /**
 
245
     * Sets the port number of the URL.
 
246
     *
 
247
     * @param port The port number of the URL
 
248
     */
 
249
    NPT_Result SetPort(NPT_UInt16 port);
 
250
    
 
251
    /**
 
252
     * Sets the path part of the URL.
 
253
     *
 
254
     * @param path The path part of the URL
 
255
     * @param encoded Boolean flag indicating whether the path parameter is
 
256
     * already encoded or not. If it is not already encoded, it will be
 
257
     * automatically encoded.
 
258
     */
 
259
    NPT_Result SetPath(const char* path, bool encoded=false);
 
260
    
 
261
    /**
 
262
     * Sets the query part of the URL.
 
263
     * 
 
264
     * @param query The query part of the URL
 
265
     * @param encoded Boolean flag indicating whether the query parameter is
 
266
     * already encoded or not. If it is not already encoded, it will be
 
267
     * automatically encoded.
 
268
     */     
 
269
    NPT_Result SetQuery(const char* query, bool encoded=false);
 
270
 
 
271
    /**
 
272
     * Sets the fragment part of the URL.
 
273
     * 
 
274
     * @param query The fragment part of the URL
 
275
     * @param encoded Boolean flag indicating whether the fragment parameter is
 
276
     * already encoded or not. If it is not already encoded, it will be
 
277
     * automatically encoded.
 
278
     */     
 
279
    NPT_Result SetFragment(const char* fragment, bool encoded=false);
 
280
 
 
281
    /**
 
282
     * Return the string representation of the URL in a way that can be used in 
 
283
     * an HTTP request (i.e just the portion of the URL starting with the path)
 
284
     *
 
285
     * @param with_fragment Boolean flag specifiying whether the fragment part of 
 
286
     * the URL should be included in the returned string or not.
 
287
     */
155
288
    virtual NPT_String ToRequestString(bool with_fragment = false) const;
 
289
 
 
290
    /**
 
291
     * Return the string representation of the URL.
 
292
     *
 
293
     * @param default_port default port number for the scheme. If the port number of
 
294
     * the URL is not equal to the default port, then port number is explicitely 
 
295
     * included in the string representation of the URL. 
 
296
     * @param with_fragment Boolean flag specifiying whether the fragment part of 
 
297
     * the URL should be included in the returned string or not.
 
298
     */
156
299
    virtual NPT_String ToStringWithDefaultPort(NPT_UInt16 default_port, bool with_fragment = true) const;
 
300
 
 
301
    /**
 
302
     * Return the string representation of the URL.
 
303
     *
 
304
     * @param with_fragment Boolean flag specifiying whether the fragment part of 
 
305
     * the URL should be included in the returned string or not.
 
306
     */
157
307
    virtual NPT_String ToString(bool with_fragment = true) const;
158
308
 
159
309
protected: