libUPnP 1.14.19
Data Structures | Macros | Typedefs | Enumerations | Functions
uri.h File Reference
#include <sys/param.h>
#include "UpnpGlobal.h"
#include "UpnpInet.h"
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <time.h>
#include <netdb.h>
Include dependency graph for uri.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  TOKEN
 Buffer used in parsinghttp messages, urls, etc. generally this simply holds a pointer into a larger array. More...
 
struct  HOSTPORT
 Represents a host port: e.g. "127.127.0.1:80" text is a token pointing to the full string representation. More...
 
struct  URI
 Represents a URI used in parse_uri and elsewhere. More...
 
struct  URL_LIST
 Represents a list of URLs as in the "callback" header of SUBSCRIBE message in GENA. "char *" URLs holds dynamic memory. More...
 

Macros

#define MARK   "-_.!~*'()"
 
#define RESERVED   ";/?:@&=+$,{}"
 
#define HTTP_SUCCESS   1
 

Typedefs

typedef struct TOKEN token
 Buffer used in parsinghttp messages, urls, etc. generally this simply holds a pointer into a larger array.
 
typedef struct HOSTPORT hostport_type
 Represents a host port: e.g. "127.127.0.1:80" text is a token pointing to the full string representation.
 
typedef struct URI uri_type
 Represents a URI used in parse_uri and elsewhere.
 
typedef struct URL_LIST URL_list
 Represents a list of URLs as in the "callback" header of SUBSCRIBE message in GENA. "char *" URLs holds dynamic memory.
 

Enumerations

enum  hostType { HOSTNAME , IPv4address }
 
enum  pathType { ABS_PATH , REL_PATH , OPAQUE_PART }
 
enum  uriType { ABSOLUTE , RELATIVE }
 

Functions

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.txt (RFC explaining URIs)
 
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.
 
int token_cmp (token *in1, token *in2)
 Compares two tokens.
 
int remove_escaped_chars (char *in, size_t *size)
 Removes http escaped characters such as: "%20" and replaces them with their character representation. i.e. "hello%20foo" -> "hello foo".
 
int remove_dots (char *in, size_t size)
 Removes ".", and ".." from a path.
 
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.
 
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).
 
int parse_token (char *in, token *out, int max_size)
 

Macro Definition Documentation

◆ RESERVED

#define RESERVED   ";/?:@&=+$,{}"

added {} for compatibility

Typedef Documentation

◆ hostport_type

typedef struct HOSTPORT hostport_type

Represents a host port: e.g. "127.127.0.1:80" text is a token pointing to the full string representation.

◆ token

typedef struct TOKEN token

Buffer used in parsinghttp messages, urls, etc. generally this simply holds a pointer into a larger array.

◆ uri_type

typedef struct URI uri_type

Represents a URI used in parse_uri and elsewhere.

◆ URL_list

typedef struct URL_LIST URL_list

Represents a list of URLs as in the "callback" header of SUBSCRIBE message in GENA. "char *" URLs holds dynamic memory.

Function Documentation

◆ 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
  • HTTP_SUCCESS - On Success.
  • UPNP_E_OUTOF_MEMORY - On Failure to allocate memory.
Parameters
[in]inSource URL list.
[out]outDestination URL list.

References copy_token(), HOSTPORT::text, UPNP_E_OUTOF_MEMORY, and URL_LIST::URLs.

Referenced by copy_subscription().

◆ 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.

References URL_LIST::URLs.

Referenced by freeSubscription().

◆ parse_token()

int parse_token ( char *  in,
token out,
int  max_size 
)
Returns
Parameters
[in]in.
[out]out.
[in]max_size.

◆ parse_uri()

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).

Handles absolute, relative, and opaque uris. Parses into the following pieces: scheme, hostport, pathquery, fragment (path and query are treated as one token)

Caller should check for the pieces they require.

Returns
Parameters
[in]inCharacter string containing uri information to be parsed.
[in]maxMaximum limit on the number of characters.
[out]outOutput parameter which will have the parsed uri information.

References parse_hostport(), parse_scheme(), parse_uric(), and token_string_casecmp().

Referenced by create_url_list(), FindServiceControlURLPath(), FindServiceEventURLPath(), http_FixStrUrl(), and resolve_rel_url().

◆ print_token()

void print_token ( token in)

Function useful in debugging for printing a token.

Parameters
[in]inToken object to print.

◆ print_uri()

void print_uri ( uri_type in)

Function useful in debugging for printing a parsed uri.

Parameters
[in]inURI object to print.

◆ remove_dots()

int remove_dots ( char *  in,
size_t  size 
)

Removes ".", and ".." from a path.

If a ".." can not be resolved (i.e. the .. would go past the root of the path) an error is returned.

The input IS modified in place.)

Note
Examples char path[30]="/../hello"; remove_dots(path, strlen(path)) -> UPNP_E_INVALID_URL char path[30]="/./hello"; remove_dots(path, strlen(path)) -> UPNP_E_SUCCESS, in = "/hello" char path[30]="/./hello/foo/../goodbye" -> UPNP_E_SUCCESS, in = "/hello/goodbye"
Returns
  • UPNP_E_SUCCESS - On Success.
  • UPNP_E_OUTOF_MEMORY - On failure to allocate memory.
  • UPNP_E_INVALID_URL - Failure to resolve URL.
Parameters
[in]inString of characters from which "dots" have to be removed.
[in]sizeSize limit for the number of characters.

References UPNP_E_SUCCESS.

Referenced by process_request(), and resolve_rel_url().

◆ remove_escaped_chars()

int remove_escaped_chars ( char *  in,
size_t *  size 
)

Removes http escaped characters such as: "%20" and replaces them with their character representation. i.e. "hello%20foo" -> "hello foo".

The input IS MODIFIED in place (shortened). Extra characters are replaced with NULL.

Returns
UPNP_E_SUCCESS.
Parameters
[in,out]inString of characters to be modified.
[in,out]sizeSize limit for the number of characters.

References replace_escaped(), and UPNP_E_SUCCESS.

Referenced by process_request().

◆ replace_escaped()

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.txt (RFC explaining URIs)

Size of array is NOT checked (MUST be checked by caller)

Note
This function modifies the string. If the sequence is an escaped sequence it is replaced, the other characters in the string are shifted over, and NULL characters are placed at the end of the string.
Returns
Parameters
[in,out]inString of characters.
[in]indexIndex at which to start checking the characters.
[out]max.

Referenced by remove_escaped_chars().

◆ resolve_rel_url()

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.

If the base_url is NULL, then a copy of the rel_url is passed back if the rel_url is absolute then a copy of the rel_url is passed back if neither the base nor the rel_url are Absolute then NULL is returned. Otherwise it tries and resolves the relative url with the base as described in http://www.ietf.org/rfc/rfc2396.txt (RFCs explaining URIs).

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

Returns
Parameters
[in]base_urlBase URL.
[in]rel_urlRelative URL.

References parse_uri(), remove_dots(), HOSTPORT::text, and UPNP_E_SUCCESS.

Referenced by UpnpResolveURL(), and UpnpResolveURL2().

◆ 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.

Referenced by FindServiceControlURLPath(), and FindServiceEventURLPath().

◆ token_string_casecmp()

int token_string_casecmp ( token in1,
const char *  in2 
)

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

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.

Referenced by http_FixUrl(), http_OpenHttpConnection(), and parse_uri().