82 out->
buff = out_base + (in->
buff - in_base);
92 memset(a_out, 0,
sizeof(*a_out));
96 std::string_view url_list_sv =
97 std::string_view(a_url_list->
buf, a_url_list->
length);
99 if (url_list_sv.empty() || url_list_sv ==
"<>")
103 auto it{url_list_sv.begin()};
106 for (++it; it < url_list_sv.end() - 1; it++) {
107 if (*it ==
'<' || (*it ==
'>' && *++it !=
'<'))
115 if ((ch0 ==
'<' && ch1 !=
'>') || (ch0 !=
'<' && ch1 ==
'>'))
117 if (!(ch0 ==
'<' && ch1 ==
'>'))
121 auto url_list_size = url_list_sv.size();
122 char* base_urls =
static_cast<char*
>(malloc(url_list_size + 1));
126 base_urls[url_list_sv.copy(base_urls, url_list_size)] =
'\0';
127 std::string_view base_urls_sv = std::string_view(base_urls, url_list_size);
144 std::string_view base_url_sv;
146 for (
size_t i{}; i < url_count; i++) {
147 size_t pos = base_urls_sv.find_first_of(
'>');
148 base_url_sv = base_urls_sv.substr(0, pos);
149 base_url_sv.remove_prefix(1);
150 base_urls_sv.remove_prefix(pos + 1);
154 parse_uri(base_url_sv.data(), base_url_sv.size(), &splitted_url);
160 parsed_urls[store_idx++] = splitted_url;
171 a_out->
URLs = base_urls;
172 a_out->
size = store_idx;
174 if (store_idx > INT_MAX)
176 return static_cast<int>(store_idx);
185 size_t len = strlen(in->
URLs) + 1;
186 out->
URLs =
static_cast<char*
>(malloc(len));
199 for (
size_t i{0}; i < in->
size; i++) {
213 sizeof(
struct sockaddr_storage));
228 list->
size = (size_t)0;
232#if defined(DEBUG_URI) || defined(DOXYGEN_RUN)
243 fprintf(stderr,
"Token Size : %" PRIzu
"\n\'", in->
size);
244 for (i = 0; i < in->
size; i++)
245 putchar(in->
buff[i]);
252 size_t in2_length = strlen(in2);
253 if (in1->
buff ==
nullptr && in2_length == 0)
255 else if (in1->
buff ==
nullptr && in2_length != 0)
257 else if (in1->
size < in2_length)
259 else if (in1->
size > in2_length)
262 return strncasecmp(in1->
buff, in2, in1->
size);
283 if (a_base_url ==
nullptr && a_rel_url !=
nullptr) {
296 out_str = uri_refObj.
str();
300 if (a_base_url !=
nullptr && a_rel_url !=
nullptr) {
317 out_str = uri_relObj.
str();
325 UPnPsdk::CUri uriObj(a_base_url ==
nullptr ?
"" : a_base_url);
326 uriObj = a_rel_url ==
nullptr ?
"" : a_rel_url;
335 out_str = uriObj.
str();
337 }
catch (
const std::invalid_argument& ex) {
338 UPnPsdk_LOGCATCH(
"MSG1046")
"Catched next line...\n"
339 << ex.what() <<
'\n';
345 char* out =
static_cast<char*
>(malloc(out_str.size() + 1));
348 out_str.copy(out, std::string::npos);
349 out[out_str.size()] =
'\0';
UPnPsdk_EXTERN unsigned gIF_INDEX
Index/scope-id from the used network interface.
int copy_URL_list(URL_list *in, URL_list *out)
Copies one URL_list into another.
int token_cmp(token *in1, token *in2)
Compares two tokens.
int token_string_casecmp(token *in1, const char *in2)
Compares buffer in the token object with the buffer in in2 case insensitive.
char * resolve_rel_url(char *a_base_url, char *a_rel_url)
Resolves a relative url with a base url.
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 create_url_list(memptr *a_url_list, URL_list *a_out)
Function to parse the Callback header value in subscription requests.
void free_URL_list(URL_list *list)
Frees the memory associated with a URL_list.
size_t size
Number of urls (not characters).
Represents a list of URLs as in the "callback" header of SUBSCRIBE message in GENA.
Manage Uniform Resource Identifier (URI) as specified with RFC 3986.
token fragment
Member variable.
token scheme
Member variable.
@ Relative
The URI is relative, means it hasn't a 'scheme' component.
@ Absolute
The URI is absolute, means it has a 'scheme' component.
hostport_type hostport
Member variable.
size_t size
Size of the buffer.
@ ABS_PATH
The 'path' component begins with a '/'.
@ REL_PATH
The 'path' component doesn't begin with a '/'.
pathType path_type
Member variable.
token pathquery
Member variable.
sockaddr_storage IPaddress
Network socket address.
constexpr int HTTP_SUCCESS
Yet another success code.
uriType type
Member variable.
token text
Pointing to the full host:port string representation.
Represents a URI used in parse_uri and elsewhere.
Buffer used in parsing http messages, urls, etc. Generally this simply holds a pointer into a larger ...
Declaration of the Addrinfo class.
Get information from the operating system about an internet address.
bool get_first()
Get the first entry of an address info from the operating system.
STATE state() const
Get state of the component.
STATE
Defines the possible states of a URI component.
std::string str() const
Get URI reference string.
Representing a URI that can be modified with a relative reference.
CUriRef target
Resulting URI of merged relative reference to the base URI.
std::string str() const
Get the resulting URI string merged with the relative reference.
UPnPsdk_VIS int parse_uri(const char *in, size_t max, uri_type *out)
Parses a uri as defined in RFC 3986 (Uniform Resource Identifier).
size_t length
length of memory without terminating '\0' (read-only).
char * buf
start of memory (read/write).
pointer to a chunk of memory.
#define UPNP_E_OUTOF_MEMORY
Not enough resources are currently available to complete the operation.
#define UPNP_E_INVALID_URL
An URL passed into the function is invalid.
void copy_token(const token *in, const char *in_base, token *out, char *out_base)
Copy the offset and size from a token to another token.
Define macro for synced logging to the console for detailed info and debug.
#define UPnPsdk_EXTERN
Prefix for a portable 'extern' declaration.