UPnPsdk 0.1
Universal Plug and Play +, Software Development Kit
 
Loading...
Searching...
No Matches
uri.cpp File Reference

Modify and parse URIs. More...

#include <upnp.hpp>
#include <uri.hpp>
#include <UPnPsdk/uri.hpp>
#include <UPnPsdk/synclog.hpp>
#include <UPnPsdk/addrinfo.hpp>
+ Include dependency graph for uri.cpp:

Go to the source code of this file.

Functions

int create_url_list (memptr *a_url_list, URL_list *a_out)
 Function to parse the Callback header value in subscription requests.
 
int copy_URL_list (URL_list *in, URL_list *out)
 Copies one URL_list into another.
 
void free_URL_list (URL_list *list)
 Frees the memory associated with a URL_list.
 
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 token_string_casecmp (token *in1, const char *in2)
 Compares buffer in the token object with the buffer in in2 case insensitive.
 
int token_cmp (token *in1, token *in2)
 Compares two tokens.
 
char * resolve_rel_url (char *a_base_url, char *a_rel_url)
 Resolves a relative url with a base url.
 
Scope restricted to file
void anonymous_namespace{uri.cpp}::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.
 

Variables

UPnPsdk_EXTERN unsigned gIF_INDEX
 Index/scope-id from the used network interface.
 

Detailed Description

Modify and parse URIs.

Definition in file uri.cpp.

Function Documentation

◆ create_url_list()

int create_url_list ( memptr a_url_list,
URL_list a_out 
)

Function to parse the Callback header value in subscription requests.

Takes in a buffer containing serialized URLs delimited by '<' and '>'. The entire buffer is copied into dynamic memory and stored in the URL_list. Pointers to the individual urls within this buffer are allocated and stored in the URL_list. Only URLs with network addresses are considered (i.e. host:port or domain name). Because the function expects a serialized list with delimiters, even one url must be surrounded by '<' and '>'.

Note
The result a_out must be freed by the caller with free_URL_list() to avoid memory leaks.
Returns
On success: the number of URLs parsed
On error:
  • UPNP_E_OUTOF_MEMORY
  • UPNP_E_INVALID_URL
Parameters
[in]a_url_listPointer to a buffer containing serialized URLs delimited by '<' and '>' ("<url><url>"). It is not necessary to terminate the string with zero ('\0') but can.
[out]a_outPointer to the new URL list.

Definition at line 89 of file uri.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ copy_URL_list()

int copy_URL_list ( URL_list in,
URL_list out 
)

Copies one URL_list into another.

This includes dynamically allocating the out->URLs field (the full string), and the structures used to hold the parsedURLs. This memory MUST be freed by the caller through: free_URL_list(&out).

Returns
On success: HTTP_SUCCESS
On error:
  • UPNP_E_OUTOF_MEMORY - On Failure to allocate memory.
Parameters
[in]inSource URL list.
[out]outDestination URL list.

Definition at line 180 of file uri.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ free_URL_list()

void free_URL_list ( URL_list list)

Frees the memory associated with a URL_list.

Frees the dynamically allocated members of of list. Does NOT free the pointer to the list itself ( i.e. does NOT free(list)).

Parameters
[in]listURL list object.

Definition at line 221 of file uri.cpp.

+ Here is the caller graph for this function:

◆ print_uri()

void print_uri ( uri_type in)

Function useful in debugging for printing a parsed uri.

This is only available when compiled with DEBUG enabled.

Parameters
[in]inURI object to print.

Definition at line 233 of file uri.cpp.

+ Here is the call graph for this function:

◆ print_token()

void print_token ( token in)

Function useful in debugging for printing a token.

This is only available when compiled with DEBUG enabled.

Parameters
[in]inToken object to print.

Definition at line 240 of file uri.cpp.

+ Here is the caller graph for this function:

◆ token_string_casecmp()

int token_string_casecmp ( token in1,
const char *  in2 
)

Compares buffer in the token object with the buffer in in2 case insensitive.

Returns
  • < 0, if string1 is less than string2.
  • == 0, if string1 is identical to string2 .
  • > 0, if string1 is greater than string2.
Parameters
[in]in1Token object whose buffer is to be compared.
[in]in2String of characters to compare with.

Definition at line 251 of file uri.cpp.

+ Here is the caller graph for this function:

◆ token_cmp()

int token_cmp ( token in1,
token in2 
)

Compares two tokens.

Returns
  • < 0, if string1 is less than string2.
  • == 0, if string1 is identical to string2 .
  • > 0, if string1 is greater than string2.
Parameters
[in]in1First token object whose buffer is to be compared.
[in]in2Second token object used for the comparison.

Definition at line 265 of file uri.cpp.

+ Here is the caller graph for this function:

◆ resolve_rel_url()

char * resolve_rel_url ( char *  a_base_url,
char *  a_rel_url 
)

Resolves a relative url with a base url.

  • If the base_url is a nullptr, then a copy of the rel_url is passed back.
  • If the rel_url is a nullptr, then a copy of the base_url is passed back.
  • If both arguments are nullptr, then a nullptr is passed back.
  • If the base_url is empty (""), then a nullptr is passed back.
  • If the rel_url is empty (""), then a copy of the base_url is passed back.
  • If both arguments are empty (""), then a nullptr is passed back.
  • If the rel_url is absolute (with a valid base_url), then a copy of the rel_url is passed back.
  • If neither the base nor the rel_url are absolute then a nullptr is returned.
  • Otherwise it tries and resolves the relative url with the base as described in RFC 2396 (explaining URIs).

The resolution of '..' is NOT implemented, but '.' is resolved.

Returns
Pointer to a new with malloc dynamically allocated full URL or a nullptr. To avoid memory leaks the caller nust free() it after using.
Parameters
[in]a_base_urlBase URL.
[in]a_rel_urlRelative URL.

Definition at line 275 of file uri.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ gIF_INDEX

UPnPsdk_EXTERN unsigned gIF_INDEX

Index/scope-id from the used network interface.

Definition at line 50 of file uri.cpp.