UPnPsdk 0.1
Universal Plug and Play +, Software Development Kit
 
Loading...
Searching...
No Matches
uri.hpp
Go to the documentation of this file.
1#ifndef COMPA_GENLIB_NET_URI_HPP
2#define COMPA_GENLIB_NET_URI_HPP
3/* *****************************************************************************
4 *
5 * Copyright (c) 2000-2003 Intel Corporation
6 * All rights reserved.
7 * Copyright (C) 2021+ GPL 3 and higher by Ingo Höft, <Ingo@Hoeft-online.de>
8 * Redistribution only with this Copyright remark. Last modified: 2025-06-11
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions are met:
12 *
13 * - Redistributions of source code must retain the above copyright notice,
14 * this list of conditions and the following disclaimer.
15 * - Redistributions in binary form must reproduce the above copyright notice,
16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
18 * - Neither name of Intel Corporation nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
26 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
27 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
28 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
30 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 *
34 * ****************************************************************************/
41
43#include <cctype>
44#include <cstring>
45
46#ifndef _WIN32
47#include <netdb.h> /* for struct addrinfo */
48#endif
49
50#ifdef _WIN32
51#define strncasecmp strnicmp
52#else
53/* Other systems have strncasecmp */
54#endif
56
57namespace compa {
58
60// Must not use ABSOLUTE, RELATIVE; already defined in Win32 for other meaning.
61enum struct uriType { Absolute, Relative };
62
64enum struct pathType { ABS_PATH, REL_PATH, OPAQUE_PART };
65
66} // namespace compa
67
68
70inline constexpr int HTTP_SUCCESS{1};
71
76struct token {
77 const char* buff;
78 size_t size;
79};
80
86 sockaddr_storage IPaddress;
87};
88
103
108struct URL_list {
109 size_t size;
110 char* URLs;
112};
113
133 char* in,
135 size_t index,
138 size_t* max);
139
153 URL_list* in,
155 URL_list* out);
156
165 URL_list* list);
166
167#if defined(DEBUG) || defined(DOXYGEN_RUN)
170void print_uri(uri_type* in
171);
172#else
173#define print_uri(in) \
174 do { \
175 } while (0)
176#endif
177
178#if defined(DEBUG) || defined(DOXYGEN_RUN)
181void print_token( //
182 token* in
183);
184#else
185#define print_token(in) \
186 do { \
187 } while (0)
188#endif
189
201 token* in1,
203 const char* in2);
204
215 token* in1,
217 token* in2);
218
230 char* in,
232 size_t* size);
233
261 char* buf,
263 size_t size);
264
283 char* base_url,
285 char* rel_url);
286
304 const char* in,
306 size_t max,
309 uri_type* out);
310
318 char* in,
320 token* out,
322 int max_size);
323
324#endif /* COMPA_GENLIB_NET_URI_HPP */
token fragment
Member variable.
Definition uri.hpp:99
UPnPsdk_VIS int parse_uri(const char *in, size_t max, uri_type *out)
Parses a uri as defined in RFC 2396 (explaining URIs).
Definition uri.cpp:733
int parse_token(char *in, token *out, int max_size)
token scheme
Member variable.
Definition uri.hpp:96
char * URLs
Dynamic memory for all urls, delimited by <>
Definition uri.hpp:110
hostport_type hostport
Member variable.
Definition uri.hpp:100
uri_type * parsedURLs
parsed URLs
Definition uri.hpp:111
size_t size
Size of the buffer.
Definition uri.hpp:78
UPnPsdk_VIS int replace_escaped(char *in, size_t index, size_t *max)
Replaces one single escaped character within a string with its unescaped version.
Definition uri.cpp:396
size_t size
size
Definition uri.hpp:109
compa::uriType type
Member variable.
Definition uri.hpp:95
UPnPsdk_VIS char * resolve_rel_url(char *base_url, char *rel_url)
Resolves a relative url with a base url.
Definition uri.cpp:605
UPnPsdk_VIS 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.cpp:526
const char * buff
Buffer.
Definition uri.hpp:77
UPnPsdk_VIS int token_cmp(token *in1, token *in2)
Compares two tokens.
Definition uri.cpp:518
token pathquery
Member variable.
Definition uri.hpp:98
sockaddr_storage IPaddress
Network socket address.
Definition uri.hpp:86
UPnPsdk_VIS int token_string_casecmp(token *in1, const char *in2)
Compares buffer in the token object with the buffer in in2 case insensitive.
Definition uri.cpp:510
UPnPsdk_VIS void free_URL_list(URL_list *list)
Frees the memory associated with a URL_list.
Definition uri.cpp:480
constexpr int HTTP_SUCCESS
Yet another success code.
Definition uri.hpp:70
UPnPsdk_VIS int copy_URL_list(URL_list *in, URL_list *out)
Copies one URL_list into another.
Definition uri.cpp:431
UPnPsdk_VIS int remove_dots(char *buf, size_t size)
Removes ".", and ".." from a path.
Definition uri.cpp:538
void print_uri(uri_type *in)
Function useful in debugging for printing a parsed uri.
Definition uri.cpp:492
void print_token(token *in)
Function useful in debugging for printing a token.
Definition uri.cpp:499
compa::pathType path_type
Member variable.
Definition uri.hpp:97
token text
Pointing to the full host:port string representation.
Definition uri.hpp:85
Represents a list of URLs as in the "callback" header of SUBSCRIBE message in GENA.
Definition uri.hpp:108
Represents a URI used in parse_uri and elsewhere.
Definition uri.hpp:92
Buffer used in parsinghttp messages, urls, etc. Generally this simply holds a pointer into a larger a...
Definition uri.hpp:76
Represents a host port, e.g. "127.127.0.1:80".
Definition uri.hpp:84
Refactored pupnp program code that is compatible to the original pupnp code.
uriType
Type of the URI.
Definition uri.hpp:61
pathType
Type of the "path" part of the URI.
Definition uri.hpp:64
Macros to support visibility of external symbols.
#define UPnPsdk_VIS
Prefix to export symbol for external use.