libUPnP  1.14.5
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  HOSTNAME,
82  IPv4address
83 };
84 
85 enum pathType {
86  ABS_PATH,
87  REL_PATH,
88  OPAQUE_PART
89 };
90 
91 #ifdef _WIN32
92  /* there is a conflict in windows with other symbols. */
93  enum uriType {
94  absolute,
95  relative
96  };
97 #else
98  enum uriType {
99  ABSOLUTE,
100  RELATIVE
101  };
102 #endif
103 
108 typedef struct TOKEN {
109  const char *buff;
110  size_t size;
112 
117 typedef struct HOSTPORT {
120  /* Network Byte Order */
121  struct sockaddr_storage IPaddress;
123 
127 typedef struct URI{
128  enum uriType type;
129  token scheme;
130  enum pathType path_type;
131  token pathquery;
132  token fragment;
133  hostport_type hostport;
135 
140 typedef struct URL_LIST {
142  size_t size;
144  char *URLs;
146  uri_type *parsedURLs;
148 
161 int replace_escaped(
163  char *in,
165  size_t index,
167  size_t *max);
168 
180 int copy_URL_list(
182  URL_list *in,
184  URL_list *out);
185 
192 void free_URL_list(
194  URL_list *list);
195 
199 #ifdef DEBUG
202  uri_type *in);
203 #else
204 #define print_uri(in) do {} while (0)
205 #endif
206 
210 #ifdef DEBUG
213  token *in);
214 #else
215 #define print_token(in) do {} while (0)
216 #endif
217 
228  token *in1,
230  const char *in2);
231 
240 int token_cmp(
242  token *in1,
244  token *in2);
245 
257  char *in,
259  size_t *size);
260 
283 int remove_dots(
285  char *in,
287  size_t size);
288 
303 char *resolve_rel_url(
305  char *base_url,
307  char *rel_url);
308 
321 int parse_uri(
323  const char *in,
325  size_t max,
327  uri_type *out);
328 
336  char *in,
338  token *out,
340  int max_size);
341 
342 #ifdef __cplusplus
343 }
344 #endif
345 
346 
347 #endif /* GENLIB_NET_URI_H */
348 
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:117
token text
Definition: uri.h:119
Buffer used in parsinghttp messages, urls, etc. generally this simply holds a pointer into a larger a...
Definition: uri.h:108
Represents a URI used in parse_uri and elsewhere.
Definition: uri.h:127
Represents a list of URLs as in the "callback" header of SUBSCRIBE message in GENA....
Definition: uri.h:140
char * URLs
Definition: uri.h:144
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:206
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:511
int token_cmp(token *in1, token *in2)
Compares two tokens.
Definition: uri.c:292
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:579
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:283
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:487
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:725
void free_URL_list(URL_list *list)
Frees the memory associated with a URL_list.
Definition: uri.c:250