43#include <umock/netdb.hpp>
52using compa::pathType::ABS_PATH;
53using compa::pathType::OPAQUE_PART;
54using compa::pathType::REL_PATH;
55using compa::uriType::Absolute;
56using compa::uriType::Relative;
74 const unsigned char in) {
75 if (strchr(
";/?:@&=+$,{}", in)) {
92 const unsigned char in) {
93 if (strchr(
"-_.!~*'()", in)) {
110 const unsigned char in) {
111 if (isalnum(in) ||
is_mark(in)) {
128 const unsigned char* in) {
131 if (in[0] ==
'%' && isxdigit(in[1]) && isxdigit(in[2])) {
158 ((i + (
size_t)2 < max) &&
159 is_escaped(
reinterpret_cast<const unsigned char*
>(&in[i]))))) {
185 out->
buff = out_base + (in->
buff - in_base);
201 unsigned short int defaultPort,
206 struct sockaddr_in* sai4 = (
struct sockaddr_in*)&out->
IPaddress;
207 struct sockaddr_in6* sai6 = (
struct sockaddr_in6*)&out->
IPaddress;
208 char* srvname = NULL;
209 char* srvport = NULL;
210 char* last_dot = NULL;
211 unsigned short int port;
213 size_t hostport_size;
218 memset(workbuf, 0,
sizeof(workbuf));
220 strncpy(workbuf, in,
sizeof(workbuf) - 1);
225 while (*c !=
'\0' && *c !=
']')
240 while (*c !=
':' && *c !=
'/' &&
241 (isalnum(*c) || *c ==
'.' || *c ==
'-')) {
246 has_port = (*c ==
':') ? 1 : 0;
251 if (last_dot != NULL && isdigit(*(last_dot + 1)))
256 struct addrinfo hints, *res, *res0;
258 memset(&hints, 0,
sizeof(hints));
259 hints.ai_family = AF_UNSPEC;
260 hints.ai_socktype = SOCK_STREAM;
262 ret = umock::netdb_h.getaddrinfo(srvname, NULL, &hints, &res0);
264 for (res = res0; res; res = res->ai_next) {
265 switch (res->ai_family) {
270 memcpy(&out->
IPaddress, res->ai_addr, res->ai_addrlen);
275 umock::netdb_h.freeaddrinfo(res0);
289 while (*c !=
'\0' && isdigit(*c))
291 port = (
unsigned short int)atoi(srvport);
300 hostport_size = (size_t)c - (
size_t)workbuf;
304 sai4->sin_family = (sa_family_t)af;
305 sai4->sin_port = htons(port);
306 ret = inet_pton(AF_INET, srvname, &sai4->sin_addr);
309 sai6->sin6_family = (sa_family_t)af;
310 sai6->sin6_port = htons(port);
312 ret = inet_pton(AF_INET6, srvname, &sai6->sin6_addr);
317 if (out->
IPaddress.ss_family == (sa_family_t)AF_INET)
318 sai4->sin_port = htons(port);
320 sai6->sin6_port = htons(port);
329 return (
int)hostport_size;
357 size_t i = (size_t)0;
359 out->
size = (size_t)0;
362 if ((max == (
size_t)0) || (!isalpha(in[0])))
366 while ((i < max) && (in[i] !=
':')) {
367 if (!(isalnum(in[i]) || (in[i] ==
'+') || (in[i] ==
'-') ||
399 size_t i = (size_t)0;
400 size_t j = (size_t)0;
402 if (in[index] ==
'%' && isxdigit(in[index + (
size_t)1]) &&
403 isxdigit(in[index + (
size_t)2])) {
407 if (sscanf_s(&in[index + (
size_t)1],
409 if (sscanf(&in[index + (
size_t)1],
411 "%2x", (
unsigned int*)&tempInt) != 1) {
414 tempChar = (char)tempInt;
415 for (i = index + (
size_t)3, j = index; j < *max; i++, j++) {
432 size_t len = strlen(in->
URLs) + (size_t)1;
433 size_t i = (size_t)0;
437 out->
size = (size_t)0;
442 out->
URLs = (
char*)malloc(len);
459 for (i = (
size_t)0; i < in->
size; i++) {
473 sizeof(
struct sockaddr_storage));
487 list->
size = (size_t)0;
491#if defined(DEBUG_URI) || defined(DOXYGEN_RUN)
502 fprintf(stderr,
"Token Size : %" PRIzu
"\n\'", in->
size);
503 for (i = 0; i < in->
size; i++)
504 putchar(in->
buff[i]);
511 size_t in2_length = strlen(in2);
512 if (in1->
size != in2_length)
515 return strncasecmp(in1->
buff, in2, in1->
size);
528 size_t i = (size_t)0;
530 for (i = (
size_t)0; i < *size; i++) {
541 char* max = buf + size;
549 if (strncmp(in,
"./", 2) == 0) {
551 }
else if (strncmp(in,
"../", 3) == 0) {
554 }
else if (strncmp(in,
"/./", 3) == 0) {
556 }
else if (strncmp(in,
"/.", 2) == 0 &&
is_end_path(in[2])) {
560 }
else if (strncmp(in,
"/../", 4) == 0 ||
561 (strncmp(in,
"/..", 3) == 0 &&
is_end_path(in[3]))) {
579 }
else if (strncmp(in,
".", 1) == 0 &&
is_end_path(in[1])) {
581 }
else if (strncmp(in,
"..", 2) == 0 &&
is_end_path(in[2])) {
590 while (in < max && in[0] !=
'/' && !
is_end_path(in[0]))
621 return strdup(rel_url);
625 len_rel = strlen(rel_url);
628 if (rel.
type == Absolute)
629 return strdup(rel_url);
631 len_base = strlen(base_url);
633 (base.
type != Absolute))
635 if (len_rel == (
size_t)0)
636 return strdup(base_url);
638 len = len_base + len_rel + (size_t)2;
639 out = (
char*)malloc(len);
646 rv = snprintf(out_finger, len,
"%.*s:", (
int)base.
scheme.
size,
648 if (rv < 0 || rv >= (
int)len)
655 rv = snprintf(out_finger, len,
"%s", rel_url);
656 if (rv < 0 || rv >= (
int)len)
663 if (rv < 0 || rv >= (
int)len)
672 rv = snprintf(out_finger, len,
"%s", rel_url);
674 rv = snprintf(out_finger, len,
"/%s", rel_url);
677 rv = snprintf(out_finger, len,
"%.*s", (
int)base.
pathquery.
size,
698 out_finger += prefix;
700 rv = snprintf(out_finger, len,
"%.*s", (
int)rel.
pathquery.
size,
703 if (rv < 0 || rv >= (
int)len)
710 rv = snprintf(out_finger, len,
"#%.*s", (
int)rel.
fragment.
size,
713 rv = snprintf(out_finger, len,
"#%.*s", (
int)base.
fragment.
size,
718 if (rv < 0 || rv >= (
int)len)
735 size_t begin_hostport = (size_t)0;
736 size_t begin_fragment = (size_t)0;
737 unsigned short int defaultPort = 80;
740 if (begin_hostport) {
741 out->
type = Absolute;
745 out->
type = Relative;
748 if (begin_hostport + (
size_t)1 < max && in[begin_hostport] ==
'/' &&
749 in[begin_hostport + (
size_t)1] ==
'/') {
750 begin_hostport += (size_t)2;
756 if (begin_path >= 0) {
757 begin_path += (int)begin_hostport;
762 begin_path = (int)begin_hostport;
770 if (begin_fragment < max && in[begin_fragment] ==
'#') {
token fragment
Member variable.
token scheme
Member variable.
char * URLs
Dynamic memory for all urls, delimited by <>
hostport_type hostport
Member variable.
uri_type * parsedURLs
parsed URLs
size_t size
Size of the buffer.
compa::uriType type
Member variable.
token pathquery
Member variable.
sockaddr_storage IPaddress
Network socket address.
constexpr int HTTP_SUCCESS
Yet another success code.
compa::pathType path_type
Member variable.
token text
Pointing to the full host:port string representation.
Represents a list of URLs as in the "callback" header of SUBSCRIBE message in GENA.
Represents a URI used in parse_uri and elsewhere.
Buffer used in parsinghttp messages, urls, etc. Generally this simply holds a pointer into a larger a...
Represents a host port, e.g. "127.127.0.1:80".
#define UPNP_E_SUCCESS
The operation completed successfully.
#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.
int is_mark(const unsigned char in)
Check for a MARK character.
int is_end_path(char c)
Check if end of a path.
int is_escaped(const unsigned char *in)
Check that a char[3] sequence is ESCAPED.
int is_reserved(const unsigned char in)
Check for a RESERVED character.
size_t parse_uric(const char *in, size_t max, token *out)
Parses a string of uric characters starting at in[0].
size_t parse_scheme(const char *in, size_t max, token *out)
parses a uri scheme starting at in[0].
int is_unreserved(const unsigned char in)
Check for an UNRESERVED character.
int parse_hostport(const char *in, unsigned short int defaultPort, hostport_type *out)
Parses a string with host and port and fills a hostport structure.
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.
Specifications to be portable with sockets between different platforms.
UPnPsdk_EXTERN unsigned gIF_INDEX
Contains network interface index of the link local address gIF_IPV6 that is used as its scope_id.
char * resolve_rel_url(char *base_url, char *rel_url)
Resolves a relative url with a base url.
int remove_dots(char *buf, size_t size)
Removes ".", and ".." from a path.
int copy_URL_list(URL_list *in, URL_list *out)
Copies one URL_list into another.
int replace_escaped(char *in, size_t index, size_t *max)
Replaces one single escaped character within a string with its unescaped version.
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.
int remove_escaped_chars(char *in, size_t *size)
Removes http escaped characters such as: "%20" and replaces them with their character representation.
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 RFC 2396 (explaining URIs).
void free_URL_list(URL_list *list)
Frees the memory associated with a URL_list.
#define UPnPsdk_EXTERN
Prefix for a portable 'extern' declaration.