libUPnP 22.0.4
uri.h
Go to the documentation of this file.
1/*******************************************************************************
2 *
3 * Copyright (c) 2000-2003 Intel Corporation
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 *
9 * - Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
14 * - Neither name of Intel Corporation nor the names of its contributors
15 * may be used to endorse or promote products derived from this software
16 * without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
22 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
25 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
26 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27 * 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 GENLIB_NET_URI_H
33#define GENLIB_NET_URI_H
34
38
39#if !defined(_WIN32)
40 #include <sys/param.h>
41#endif
42
43#include "UpnpGlobal.h" /* for */
44#include "UpnpInet.h"
45
46#include <ctype.h>
47#include <errno.h>
48#include <fcntl.h>
49#include <stdlib.h>
50#include <string.h>
51#include <sys/types.h>
52#include <time.h>
53
54#ifdef _WIN32
55 #if !defined(UPNP_USE_MSVCPP) && !defined(UPNP_USE_BCBPP)
56 /* VC Winsocks2 includes these functions */
57 #include "inet_pton.h"
58 #endif
59#else
60 #include <netdb.h> /* for struct addrinfo */
61#endif
62
63#ifdef _WIN32
64 #define strncasecmp strnicmp
65#else
66 /* Other systems have strncasecmp */
67#endif
68
69#ifdef __cplusplus
70extern "C" {
71#endif
72
73#define MARK "-_.!~*'()"
74
76#define RESERVED ";/?:@&=+$,{}"
77
78#define HTTP_SUCCESS 1
79
80enum hostType
81{
82 HOSTNAME,
83 IPv4address
84};
85
86enum pathType
87{
88 ABS_PATH,
89 REL_PATH,
90 OPAQUE_PART
91};
92
93#ifdef _WIN32
94/* there is a conflict in windows with other symbols. */
95enum uriType
96{
97 absolute,
98 relative
99};
100#else
101enum uriType
102{
103 ABSOLUTE,
104 RELATIVE
105};
106#endif
107
112typedef struct TOKEN
113{
114 const char *buff;
115 size_t size;
117
122typedef struct HOSTPORT
123{
126 /* Network Byte Order */
127 struct sockaddr_storage IPaddress;
131 unsigned short int port;
133
137typedef struct URI
138{
139 enum uriType type;
140 token scheme;
141 enum pathType path_type;
142 token pathquery;
143 token fragment;
144 hostport_type hostport;
146
151typedef struct URL_LIST
152{
154 size_t size;
156 char *URLs;
158 uri_type *parsedURLs;
160
175 char *in,
177 size_t index,
179 size_t *max);
180
192int copy_URL_list(
194 URL_list *in,
196 URL_list *out);
197
204void free_URL_list(
206 URL_list *list);
207
211#ifdef DEBUG
214 uri_type *in);
215#else
216 #define print_uri(in) \
217 do { \
218 } while (0)
219#endif
220
224#ifdef DEBUG
227 token *in);
228#else
229 #define print_token(in) \
230 do { \
231 } while (0)
232#endif
233
244 token *in1,
246 const char *in2);
247
256int token_cmp(
258 token *in1,
260 token *in2);
261
273 char *in,
275 size_t *size);
276
299int remove_dots(
301 char *in,
303 size_t size);
304
319char *resolve_rel_url(
321 char *base_url,
323 char *rel_url);
324
337int parse_uri(
339 const char *in,
341 size_t max,
344 uri_type *out);
345
361 hostport_type *hostport);
362
370 char *in,
372 token *out,
374 int max_size);
375
376#ifdef __cplusplus
377}
378#endif
379
380#endif /* GENLIB_NET_URI_H */
Defines constants that for some reason are not defined on some systems.
Provides a platform independent way to include TCP/IP types and functions.
Represents a host port: e.g. "127.127.0.1:80" text is a token pointing to the full string representat...
Definition uri.h:123
token text
Definition uri.h:125
unsigned short int port
Definition uri.h:131
Buffer used in parsing http messages, urls, etc. generally this simply holds a pointer into a larger ...
Definition uri.h:113
Represents a URI used in parse_uri and elsewhere.
Definition uri.h:138
Represents a list of URLs as in the "callback" header of SUBSCRIBE message in GENA....
Definition uri.h:152
char * URLs
Definition uri.h:156
char * resolve_rel_url(char *base_url, char *rel_url)
resolves a relative url with a base url returning a NEW (dynamically allocated with malloc) full url.
Definition uri.c:627
int parse_token(char *in, token *out, int max_size)
struct URL_LIST URL_list
Represents a list of URLs as in the "callback" header of SUBSCRIBE message in GENA....
int copy_URL_list(URL_list *in, URL_list *out)
Copies one URL_list into another.
Definition uri.c:221
struct TOKEN token
Buffer used in parsing http messages, urls, etc. generally this simply holds a pointer into a larger ...
int replace_escaped(char *in, size_t index, size_t *max)
Replaces an escaped sequence with its unescaped version as in http://www.ietf.org/rfc/rfc2396....
Definition uri.c:139
int remove_dots(char *in, size_t size)
Removes ".", and ".." from a path.
Definition uri.c:559
int token_cmp(token *in1, token *in2)
Compares two tokens.
Definition uri.c:309
int resolve_hostport(hostport_type *hostport)
Resolves a hostport's host to an IP address, performing a DNS lookup if it isn't already a literal IP...
Definition uri.c:437
struct HOSTPORT hostport_type
Represents a host port: e.g. "127.127.0.1:80" text is a token pointing to the full string representat...
int token_string_casecmp(token *in1, const char *in2)
Compares buffer in the token object with the buffer in in2.
Definition uri.c:300
struct URI uri_type
Represents a URI used in parse_uri and elsewhere.
int remove_escaped_chars(char *in, size_t *size)
Removes http escaped characters such as: "%20" and replaces them with their character representation....
Definition uri.c:535
void print_uri(uri_type *in)
Function useful in debugging for printing a parsed uri.
void print_token(token *in)
Function useful in debugging for printing a token.
int parse_uri(const char *in, size_t max, uri_type *out)
Parses a uri as defined in http://www.ietf.org/rfc/rfc2396.txt (RFC explaining URIs).
Definition uri.c:773
void free_URL_list(URL_list *list)
Frees the memory associated with a URL_list.
Definition uri.c:267