libUPnP  1.14.20
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 
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
70 extern "C" {
71 #endif
72 
73 #define MARK "-_.!~*'()"
74 
76 #define RESERVED ";/?:@&=+$,{}"
77 
78 #define HTTP_SUCCESS 1
79 
80 enum hostType
81 {
82  HOSTNAME,
83  IPv4address
84 };
85 
86 enum 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. */
95 enum uriType
96 {
97  absolute,
98  relative
99 };
100 #else
101 enum uriType
102 {
103  ABSOLUTE,
104  RELATIVE
105 };
106 #endif
107 
112 typedef struct TOKEN
113 {
114  const char *buff;
115  size_t size;
117 
122 typedef struct HOSTPORT
123 {
126  /* Network Byte Order */
127  struct sockaddr_storage IPaddress;
129 
133 typedef struct URI
134 {
135  enum uriType type;
136  token scheme;
137  enum pathType path_type;
138  token pathquery;
139  token fragment;
140  hostport_type hostport;
142 
147 typedef struct URL_LIST
148 {
150  size_t size;
152  char *URLs;
154  uri_type *parsedURLs;
156 
169 int replace_escaped(
171  char *in,
173  size_t index,
175  size_t *max);
176 
188 int copy_URL_list(
190  URL_list *in,
192  URL_list *out);
193 
200 void free_URL_list(
202  URL_list *list);
203 
207 #ifdef DEBUG
210  uri_type *in);
211 #else
212  #define print_uri(in) \
213  do { \
214  } while (0)
215 #endif
216 
220 #ifdef DEBUG
223  token *in);
224 #else
225  #define print_token(in) \
226  do { \
227  } while (0)
228 #endif
229 
240  token *in1,
242  const char *in2);
243 
252 int token_cmp(
254  token *in1,
256  token *in2);
257 
269  char *in,
271  size_t *size);
272 
295 int remove_dots(
297  char *in,
299  size_t size);
300 
315 char *resolve_rel_url(
317  char *base_url,
319  char *rel_url);
320 
333 int parse_uri(
335  const char *in,
337  size_t max,
340  uri_type *out);
341 
349  char *in,
351  token *out,
353  int max_size);
354 
355 #ifdef __cplusplus
356 }
357 #endif
358 
359 #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
Buffer used in parsinghttp messages, urls, etc. generally this simply holds a pointer into a larger a...
Definition: uri.h:113
Represents a URI used in parse_uri and elsewhere.
Definition: uri.h:134
Represents a list of URLs as in the "callback" header of SUBSCRIBE message in GENA....
Definition: uri.h:148
char * URLs
Definition: uri.h:152
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:210
struct TOKEN token
Buffer used in parsinghttp messages, urls, etc. generally this simply holds a pointer into a larger a...
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:128
int remove_dots(char *in, size_t size)
Removes ".", and ".." from a path.
Definition: uri.c:513
int token_cmp(token *in1, token *in2)
Compares two tokens.
Definition: uri.c:296
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:581
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:287
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:489
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:727
void free_URL_list(URL_list *list)
Frees the memory associated with a URL_list.
Definition: uri.c:254