uriparser  0.9.4
About: uriparser is a strictly RFC 3986 compliant URI parsing library (with Unicode support).
  Fossies Dox: uriparser-0.9.4.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

UriBase.h File Reference
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
Include dependency graph for UriBase.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  UriIp4Struct
 
struct  UriIp6Struct
 
struct  UriMemoryManagerStruct
 

Macros

#define URI_ANSI_TO_UNICODE(x)   L##x
 
#define URI_VER_MAJOR   0
 
#define URI_VER_MINOR   9
 
#define URI_VER_RELEASE   4
 
#define URI_VER_SUFFIX_ANSI   ""
 
#define URI_VER_SUFFIX_UNICODE   URI_ANSI_TO_UNICODE(URI_VER_SUFFIX_ANSI)
 
#define URI_INT_TO_ANSI_HELPER(x)   #x
 
#define URI_INT_TO_ANSI(x)   URI_INT_TO_ANSI_HELPER(x)
 
#define URI_INT_TO_UNICODE_HELPER(x)   URI_ANSI_TO_UNICODE(#x)
 
#define URI_INT_TO_UNICODE(x)   URI_INT_TO_UNICODE_HELPER(x)
 
#define URI_VER_ANSI_HELPER(ma, mi, r, s)
 
#define URI_VER_UNICODE_HELPER(ma, mi, r, s)
 
#define URI_VER_ANSI   URI_VER_ANSI_HELPER(URI_VER_MAJOR, URI_VER_MINOR, URI_VER_RELEASE, URI_VER_SUFFIX_ANSI)
 
#define URI_VER_UNICODE   URI_VER_UNICODE_HELPER(URI_VER_MAJOR, URI_VER_MINOR, URI_VER_RELEASE, URI_VER_SUFFIX_UNICODE)
 
#define URI_UNUSED(x)   x
 
#define URI_PUBLIC
 
#define URI_TRUE   1
 
#define URI_FALSE   0
 
#define URI_SUCCESS   0
 
#define URI_ERROR_SYNTAX   1 /* Parsed text violates expected format */
 
#define URI_ERROR_NULL
 
#define URI_ERROR_MALLOC   3 /* Requested memory could not be allocated */
 
#define URI_ERROR_OUTPUT_TOO_LARGE   4 /* Some output is to large for the receiving buffer */
 
#define URI_ERROR_NOT_IMPLEMENTED   8 /* The called function is not implemented yet */
 
#define URI_ERROR_RANGE_INVALID   9 /* The parameters passed contained invalid ranges */
 
#define URI_ERROR_MEMORY_MANAGER_INCOMPLETE   10 /* [>=0.9.0] The UriMemoryManager passed does not implement all needed functions */
 
#define URI_ERROR_TOSTRING_TOO_LONG   URI_ERROR_OUTPUT_TOO_LARGE /* Deprecated, test for URI_ERROR_OUTPUT_TOO_LARGE instead */
 
#define URI_ERROR_ADDBASE_REL_BASE   5 /* Given base is not absolute */
 
#define URI_ERROR_REMOVEBASE_REL_BASE   6 /* Given base is not absolute */
 
#define URI_ERROR_REMOVEBASE_REL_SOURCE   7 /* Given base is not absolute */
 
#define URI_ERROR_MEMORY_MANAGER_FAULTY   11 /* [>=0.9.0] The UriMemoryManager given did not pass the test suite */
 

Typedefs

typedef int UriBool
 
typedef struct UriIp4Struct UriIp4
 
typedef struct UriIp6Struct UriIp6
 
typedef void *(* UriFuncMalloc) (struct UriMemoryManagerStruct *, size_t)
 
typedef void *(* UriFuncCalloc) (struct UriMemoryManagerStruct *, size_t, size_t)
 
typedef void *(* UriFuncRealloc) (struct UriMemoryManagerStruct *, void *, size_t)
 
typedef void *(* UriFuncReallocarray) (struct UriMemoryManagerStruct *, void *, size_t, size_t)
 
typedef void(* UriFuncFree) (struct UriMemoryManagerStruct *, void *)
 
typedef struct UriMemoryManagerStruct UriMemoryManager
 
typedef enum UriBreakConversionEnum UriBreakConversion
 
typedef enum UriNormalizationMaskEnum UriNormalizationMask
 
typedef enum UriResolutionOptionsEnum UriResolutionOptions
 

Enumerations

enum  UriBreakConversionEnum {
  URI_BR_TO_LF, URI_BR_TO_CRLF, URI_BR_TO_CR, URI_BR_TO_UNIX = URI_BR_TO_LF,
  URI_BR_TO_WINDOWS = URI_BR_TO_CRLF, URI_BR_TO_MAC = URI_BR_TO_CR, URI_BR_DONT_TOUCH
}
 
enum  UriNormalizationMaskEnum {
  URI_NORMALIZED = 0, URI_NORMALIZE_SCHEME = 1 << 0, URI_NORMALIZE_USER_INFO = 1 << 1, URI_NORMALIZE_HOST = 1 << 2,
  URI_NORMALIZE_PATH = 1 << 3, URI_NORMALIZE_QUERY = 1 << 4, URI_NORMALIZE_FRAGMENT = 1 << 5
}
 
enum  UriResolutionOptionsEnum { URI_RESOLVE_STRICTLY = 0, URI_RESOLVE_IDENTICAL_SCHEME_COMPAT = 1 << 0 }
 

Functions

int uriCompleteMemoryManager (UriMemoryManager *memory, UriMemoryManager *backend)
 
void * uriEmulateCalloc (UriMemoryManager *memory, size_t nmemb, size_t size)
 
void * uriEmulateReallocarray (UriMemoryManager *memory, void *ptr, size_t nmemb, size_t size)
 
int uriTestMemoryManager (UriMemoryManager *memory)
 

Detailed Description

Holds definitions independent of the encoding pass.

Definition in file UriBase.h.

Macro Definition Documentation

◆ URI_ANSI_TO_UNICODE

#define URI_ANSI_TO_UNICODE (   x)    L##x

Definition at line 52 of file UriBase.h.

◆ URI_ERROR_ADDBASE_REL_BASE

#define URI_ERROR_ADDBASE_REL_BASE   5 /* Given base is not absolute */

Definition at line 146 of file UriBase.h.

◆ URI_ERROR_MALLOC

#define URI_ERROR_MALLOC   3 /* Requested memory could not be allocated */

Definition at line 135 of file UriBase.h.

◆ URI_ERROR_MEMORY_MANAGER_FAULTY

#define URI_ERROR_MEMORY_MANAGER_FAULTY   11 /* [>=0.9.0] The UriMemoryManager given did not pass the test suite */

Definition at line 153 of file UriBase.h.

◆ URI_ERROR_MEMORY_MANAGER_INCOMPLETE

#define URI_ERROR_MEMORY_MANAGER_INCOMPLETE   10 /* [>=0.9.0] The UriMemoryManager passed does not implement all needed functions */

Definition at line 139 of file UriBase.h.

◆ URI_ERROR_NOT_IMPLEMENTED

#define URI_ERROR_NOT_IMPLEMENTED   8 /* The called function is not implemented yet */

Definition at line 137 of file UriBase.h.

◆ URI_ERROR_NULL

#define URI_ERROR_NULL
Value:
2 /* One of the params passed was NULL
although it mustn't be */

Definition at line 134 of file UriBase.h.

◆ URI_ERROR_OUTPUT_TOO_LARGE

#define URI_ERROR_OUTPUT_TOO_LARGE   4 /* Some output is to large for the receiving buffer */

Definition at line 136 of file UriBase.h.

◆ URI_ERROR_RANGE_INVALID

#define URI_ERROR_RANGE_INVALID   9 /* The parameters passed contained invalid ranges */

Definition at line 138 of file UriBase.h.

◆ URI_ERROR_REMOVEBASE_REL_BASE

#define URI_ERROR_REMOVEBASE_REL_BASE   6 /* Given base is not absolute */

Definition at line 149 of file UriBase.h.

◆ URI_ERROR_REMOVEBASE_REL_SOURCE

#define URI_ERROR_REMOVEBASE_REL_SOURCE   7 /* Given base is not absolute */

Definition at line 150 of file UriBase.h.

◆ URI_ERROR_SYNTAX

#define URI_ERROR_SYNTAX   1 /* Parsed text violates expected format */

Definition at line 133 of file UriBase.h.

◆ URI_ERROR_TOSTRING_TOO_LONG

#define URI_ERROR_TOSTRING_TOO_LONG   URI_ERROR_OUTPUT_TOO_LARGE /* Deprecated, test for URI_ERROR_OUTPUT_TOO_LARGE instead */

Definition at line 143 of file UriBase.h.

◆ URI_FALSE

#define URI_FALSE   0

Definition at line 127 of file UriBase.h.

◆ URI_INT_TO_ANSI

#define URI_INT_TO_ANSI (   x)    URI_INT_TO_ANSI_HELPER(x)

Definition at line 67 of file UriBase.h.

◆ URI_INT_TO_ANSI_HELPER

#define URI_INT_TO_ANSI_HELPER (   x)    #x

Definition at line 66 of file UriBase.h.

◆ URI_INT_TO_UNICODE

#define URI_INT_TO_UNICODE (   x)    URI_INT_TO_UNICODE_HELPER(x)

Definition at line 70 of file UriBase.h.

◆ URI_INT_TO_UNICODE_HELPER

#define URI_INT_TO_UNICODE_HELPER (   x)    URI_ANSI_TO_UNICODE(#x)

Definition at line 69 of file UriBase.h.

◆ URI_PUBLIC

#define URI_PUBLIC

Definition at line 117 of file UriBase.h.

◆ URI_SUCCESS

#define URI_SUCCESS   0

Definition at line 132 of file UriBase.h.

◆ URI_TRUE

#define URI_TRUE   1

Definition at line 126 of file UriBase.h.

◆ URI_UNUSED

#define URI_UNUSED (   x)    x

Definition at line 96 of file UriBase.h.

◆ URI_VER_ANSI

Definition at line 87 of file UriBase.h.

◆ URI_VER_ANSI_HELPER

#define URI_VER_ANSI_HELPER (   ma,
  mi,
  r,
 
)
Value:
URI_INT_TO_ANSI(ma) "." \
URI_INT_TO_ANSI(mi) "." \
URI_INT_TO_ANSI(r) \
s

Definition at line 72 of file UriBase.h.

◆ URI_VER_MAJOR

#define URI_VER_MAJOR   0

Definition at line 57 of file UriBase.h.

◆ URI_VER_MINOR

#define URI_VER_MINOR   9

Definition at line 58 of file UriBase.h.

◆ URI_VER_RELEASE

#define URI_VER_RELEASE   4

Definition at line 59 of file UriBase.h.

◆ URI_VER_SUFFIX_ANSI

#define URI_VER_SUFFIX_ANSI   ""

Definition at line 60 of file UriBase.h.

◆ URI_VER_SUFFIX_UNICODE

#define URI_VER_SUFFIX_UNICODE   URI_ANSI_TO_UNICODE(URI_VER_SUFFIX_ANSI)

Definition at line 61 of file UriBase.h.

◆ URI_VER_UNICODE

Definition at line 88 of file UriBase.h.

◆ URI_VER_UNICODE_HELPER

#define URI_VER_UNICODE_HELPER (   ma,
  mi,
  r,
 
)
Value:
URI_INT_TO_UNICODE(ma) L"." \
URI_INT_TO_UNICODE(mi) L"." \
URI_INT_TO_UNICODE(r) \
s

Definition at line 78 of file UriBase.h.

Typedef Documentation

◆ UriBool

typedef int UriBool

Boolean type

Definition at line 123 of file UriBase.h.

◆ UriBreakConversion

Specifies a line break conversion mode. Specifies a line break conversion mode.

◆ UriFuncCalloc

typedef void*(* UriFuncCalloc) (struct UriMemoryManagerStruct *, size_t, size_t)

Function signature that custom calloc(3) functions must conform to

Since
0.9.0

Definition at line 196 of file UriBase.h.

◆ UriFuncFree

typedef void(* UriFuncFree) (struct UriMemoryManagerStruct *, void *)

Function signature that custom free(3) functions must conform to

Since
0.9.0

Definition at line 217 of file UriBase.h.

◆ UriFuncMalloc

typedef void*(* UriFuncMalloc) (struct UriMemoryManagerStruct *, size_t)

Function signature that custom malloc(3) functions must conform to

Since
0.9.0

Definition at line 189 of file UriBase.h.

◆ UriFuncRealloc

typedef void*(* UriFuncRealloc) (struct UriMemoryManagerStruct *, void *, size_t)

Function signature that custom realloc(3) functions must conform to

Since
0.9.0

Definition at line 203 of file UriBase.h.

◆ UriFuncReallocarray

typedef void*(* UriFuncReallocarray) (struct UriMemoryManagerStruct *, void *, size_t, size_t)

Function signature that custom reallocarray(3) functions must conform to

Since
0.9.0

Definition at line 210 of file UriBase.h.

◆ UriIp4

typedef struct UriIp4Struct UriIp4

Holds an IPv4 address. Holds an IPv4 address.

◆ UriIp6

typedef struct UriIp6Struct UriIp6

Holds an IPv6 address. Holds an IPv6 address.

◆ UriMemoryManager

Class-like interface of custom memory managers

See also
uriCompleteMemoryManager
uriEmulateCalloc
uriEmulateReallocarray
uriTestMemoryManager
Since
0.9.0 Class-like interface of custom memory managers
See also
uriCompleteMemoryManager
uriEmulateCalloc
uriEmulateReallocarray
uriTestMemoryManager
Since
0.9.0

◆ UriNormalizationMask

Specifies which component of a URI has to be normalized. Specifies which component of a URI has to be normalized.

◆ UriResolutionOptions

Specifies how to resolve URI references. Specifies how to resolve URI references.

Enumeration Type Documentation

◆ UriBreakConversionEnum

Specifies a line break conversion mode.

Enumerator
URI_BR_TO_LF 

Convert to Unix line breaks ("\\x0a")

URI_BR_TO_CRLF 

Convert to Windows line breaks ("\\x0d\\x0a")

URI_BR_TO_CR 

Convert to Macintosh line breaks ("\\x0d")

URI_BR_TO_UNIX 

Convert to Unix line breaks ("\\x0a")

URI_BR_TO_WINDOWS 

Convert to Windows line breaks ("\\x0d\\x0a")

URI_BR_TO_MAC 

Convert to Macintosh line breaks ("\\x0d")

URI_BR_DONT_TOUCH 

Copy line breaks unmodified

Definition at line 242 of file UriBase.h.

◆ UriNormalizationMaskEnum

Specifies which component of a URI has to be normalized.

Enumerator
URI_NORMALIZED 

Do not normalize anything

URI_NORMALIZE_SCHEME 

Normalize scheme (fix uppercase letters)

URI_NORMALIZE_USER_INFO 

Normalize user info (fix uppercase percent-encodings)

URI_NORMALIZE_HOST 

Normalize host (fix uppercase letters)

URI_NORMALIZE_PATH 

Normalize path (fix uppercase percent-encodings and redundant dot segments)

URI_NORMALIZE_QUERY 

Normalize query (fix uppercase percent-encodings)

URI_NORMALIZE_FRAGMENT 

Normalize fragment (fix uppercase percent-encodings)

Definition at line 257 of file UriBase.h.

◆ UriResolutionOptionsEnum

Specifies how to resolve URI references.

Enumerator
URI_RESOLVE_STRICTLY 

Full RFC conformance

URI_RESOLVE_IDENTICAL_SCHEME_COMPAT 

Treat URI to resolve with identical scheme as having no scheme

Definition at line 272 of file UriBase.h.

Function Documentation

◆ uriCompleteMemoryManager()

int uriCompleteMemoryManager ( UriMemoryManager memory,
UriMemoryManager backend 
)

Wraps a memory manager backend that only provides malloc and free to make a complete memory manager ready to be used.

The core feature of this wrapper is that you don't need to implement realloc if you don't want to. The wrapped memory manager uses backend->malloc, memcpy, and backend->free and soieof(size_t) extra bytes per allocation to emulate fallback realloc for you.

memory->calloc is uriEmulateCalloc. memory->free uses backend->free and handles the size header. memory->malloc uses backend->malloc and adds a size header. memory->realloc uses memory->malloc, memcpy, and memory->free and reads the size header. memory->reallocarray is uriEmulateReallocarray.

The internal workings behind memory->free, memory->malloc, and memory->realloc may change so the functions exposed by these function pointer sshould be consided internal and not public API.

Parameters
memoryOUT: Where to write the wrapped memory manager to
backendIN: Memory manager to use as a backend
Returns
Error code or 0 on success
See also
uriEmulateCalloc
uriEmulateReallocarray
UriMemoryManager
Since
0.9.0

Definition at line 264 of file UriMemory.c.

References UriMemoryManagerStruct::calloc, UriMemoryManagerStruct::free, UriMemoryManagerStruct::malloc, UriMemoryManagerStruct::realloc, UriMemoryManagerStruct::reallocarray, URI_ERROR_MEMORY_MANAGER_INCOMPLETE, URI_ERROR_NULL, URI_SUCCESS, uriDecorateFree(), uriDecorateMalloc(), uriDecorateRealloc(), uriEmulateCalloc(), uriEmulateReallocarray(), and UriMemoryManagerStruct::userData.

◆ uriEmulateCalloc()

void* uriEmulateCalloc ( UriMemoryManager memory,
size_t  nmemb,
size_t  size 
)

Offers emulation of calloc(3) based on memory->malloc and memset. See "man 3 calloc" as well.

Parameters
memoryIN: Memory manager to use, should not be NULL
nmembIN: Number of elements to allocate
sizeIN: Size in bytes per element
Returns
Pointer to allocated memory or NULL
See also
uriCompleteMemoryManager
uriEmulateReallocarray
UriMemoryManager
Since
0.9.0

Definition at line 129 of file UriMemory.c.

References UriMemoryManagerStruct::malloc, and URI_CHECK_ALLOC_OVERFLOW.

Referenced by uriCompleteMemoryManager().

◆ uriEmulateReallocarray()

void* uriEmulateReallocarray ( UriMemoryManager memory,
void *  ptr,
size_t  nmemb,
size_t  size 
)

Offers emulation of reallocarray(3) based on memory->realloc. See "man 3 reallocarray" as well.

Parameters
memoryIN: Memory manager to use, should not be NULL
ptrIN: Pointer allocated using memory->malloc/... or NULL
nmembIN: Number of elements to allocate
sizeIN: Size in bytes per element
Returns
Pointer to allocated memory or NULL
See also
uriCompleteMemoryManager
uriEmulateCalloc
UriMemoryManager
Since
0.9.0

Definition at line 151 of file UriMemory.c.

References UriMemoryManagerStruct::realloc, and URI_CHECK_ALLOC_OVERFLOW.

Referenced by uriCompleteMemoryManager().

◆ uriTestMemoryManager()

int uriTestMemoryManager ( UriMemoryManager memory)

Run multiple tests against a given memory manager. For example, one test

  1. allocates a small amount of memory,
  2. writes some magic bytes to it,
  3. reallocates it,
  4. checks that previous values are still present,
  5. and frees that memory.

It is recommended to compile with AddressSanitizer enabled to take full advantage of uriTestMemoryManager.

Parameters
memoryIN: Memory manager to use, should not be NULL
Returns
Error code or 0 on success
See also
uriEmulateCalloc
uriEmulateReallocarray
UriMemoryManager
Since
0.9.0

Definition at line 288 of file UriMemory.c.

References UriMemoryManagerStruct::calloc, UriMemoryManagerStruct::free, UriMemoryManagerStruct::malloc, UriMemoryManagerStruct::realloc, UriMemoryManagerStruct::reallocarray, URI_ERROR_MEMORY_MANAGER_FAULTY, URI_ERROR_MEMORY_MANAGER_INCOMPLETE, URI_ERROR_NULL, URI_SUCCESS, URI_TRUE, and uriMemoryManagerIsComplete().

URI_INT_TO_ANSI
#define URI_INT_TO_ANSI(x)
Definition: UriBase.h:66
URI_INT_TO_UNICODE
#define URI_INT_TO_UNICODE(x)
Definition: UriBase.h:69