membuffer.h File Reference
`#include <stdlib.h>`
`#include "upnputil.h"`
Include dependency graph for membuffer.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

## Data Structures

struct | memptr
struct | membuffer

## Macros

#define | MINVAL(a, b) ( (a) < (b) ? (a) : (b) )
#define | MAXVAL(a, b) ( (a) > (b) ? (a) : (b) )
#define | MEMBUF_DEF_SIZE_INC (size_t)5

## Functions

char * | str_alloc (const char *str, size_t str_len)
| Allocate memory and copy information from the input string to the newly allocated memory. More...
int | memptr_cmp (memptr *m, const char *s)
| Compares characters of strings passed for number of bytes. If equal for the number of bytes, the length of the bytes determines which buffer is shorter. More...
int | memptr_cmp_nocase (memptr *m, const char *s)
| Compares characters of 2 strings irrespective of the case for a specific count of bytes. More...
int | membuffer_set_size (membuffer *m, size_t new_length)
| Increases or decreases buffer cap so that at least 'new_length' bytes can be stored. More...
void | membuffer_init (membuffer *m)
| Wrapper to membuffer_initialize(). More...
void | membuffer_destroy (membuffer *m)
| Free's memory allocated for membuffer* m. More...
int | membuffer_assign (membuffer *m, const void *buf, size_t buf_len)
| Allocate memory to membuffer *m and copy the contents of the in parameter const void *buf. More...
int | membuffer_assign_str (membuffer *m, const char *c_str)
| Wrapper function for membuffer_assign(). More...
int | membuffer_append (membuffer *m, const void *buf, size_t buf_len)
| Invokes function to appends data from a constant buffer to the buffer. More...
int | membuffer_append_str (membuffer *m, const char *c_str)
| Invokes function to appends data from a constant string to the buffer. More...
int | membuffer_insert (membuffer *m, const void *buf, size_t buf_len, size_t index)
| Allocates memory for the new data to be inserted. Does memory management by moving the data from the existing memory to the newly allocated memory and then appending the new data. More...
void | membuffer_delete (membuffer *m, size_t index, size_t num_bytes)
| Shrink the size of the buffer depending on the current size of the bufer and te input parameters. Move contents from the old buffer to the new sized buffer. More...
char * | membuffer_detach (membuffer *m)
void | membuffer_attach (membuffer *m, char *new_buf, size_t buf_len)

## Macro Definition Documentation

## MEMBUF_DEF_SIZE_INC

#define MEMBUF_DEF_SIZE_INC (size_t)5

default value of size_inc.

Referenced by ixml_membuf_init(), and membuffer_init().

## Function Documentation

## membuffer_append()

int membuffer_append | ( | membuffer * | m,
|  | const void * | buf,
|  | size_t | buf_len
| ) |  |

Invokes function to appends data from a constant buffer to the buffer.

Returns
  int.

Parameters

  [in,out] | m | Buffer whose memory is to be appended.
  [in] | buf | Source buffer whose contents will be copied.
  [in] | buf_len | Length of the source buffer.

References membuffer::length, and membuffer_insert().

## membuffer_append_str()

int membuffer_append_str | ( | membuffer * | m,
|  | const char * | c_str
| ) |  |

Invokes function to appends data from a constant string to the buffer.

Returns
  int.

Parameters

  [in,out] | m | Buffer whose memory is to be appended.
  [in] | c_str | Source buffer whose contents will be copied.

References membuffer::length, and membuffer_insert().

Referenced by web_server_set_alias().

## membuffer_assign()

int membuffer_assign | ( | membuffer * | m,
|  | const void * | buf,
|  | size_t | buf_len
| ) |  |

Allocate memory to membuffer *m and copy the contents of the in parameter const void *buf.

Returns
  - UPNP_E_SUCCESS
  - UPNP_E_OUTOF_MEMORY

Parameters

  [in,out] | m | Buffer whose memory is to be allocated and assigned.
  [in] | buf | Source buffer whose contents will be copied.
  [in] | buf_len | Length of the source buffer.

References membuffer::buf, membuffer::length, membuffer_destroy(), and membuffer_set_size().

Referenced by membuffer_assign_str().

## membuffer_assign_str()

int membuffer_assign_str | ( | membuffer * | m,
|  | const char * | c_str
| ) |  |

Wrapper function for membuffer_assign().

Returns
  - UPNP_E_SUCCESS
  - UPNP_E_OUTOF_MEMORY

Parameters

  [in,out] | m | Buffer to be allocated and assigned.
  [in] | c_str | Source buffer whose contents will be copied.

References membuffer_assign().

Referenced by web_server_set_alias(), and web_server_set_root_dir().

## membuffer_attach()

void membuffer_attach | ( | membuffer * | m,
|  | char * | new_buf,
|  | size_t | buf_len
| ) |  |

Parameters

  [in,out] | m | Buffer to be updated.
  [in] | new_buf | Source buffer which will be assigned to the buffer to be updated.
  [in] | buf_len | Length of the source buffer.

References membuffer::buf, membuffer::capacity, membuffer::length, and membuffer_destroy().

Referenced by web_server_set_alias().

## membuffer_delete()

void membuffer_delete | ( | membuffer * | m,
|  | size_t | index,
|  | size_t | num_bytes
| ) |  |

Shrink the size of the buffer depending on the current size of the bufer and te input parameters. Move contents from the old buffer to the new sized buffer.

Parameters

  [in,out] | m | Buffer whose memory size is to be decreased and copied to the modified location.
  [in] | index | Index to determine bounds while moving data.
  [in] | num_bytes | Number of bytes that the data needs to shrink by.

References membuffer::buf, membuffer::length, and membuffer_set_size().

Referenced by web_server_set_root_dir().

## membuffer_destroy()

void membuffer_destroy | ( | membuffer * | m | ) |

Free's memory allocated for membuffer* m.

Parameters

  [in,out] | m | Buffer to be destroyed.

References membuffer::buf, and membuffer_init().

Referenced by AutoAdvertise(), genaNotify(), membuffer_assign(), and membuffer_attach().

## membuffer_detach()

char* membuffer_detach | ( | membuffer * | m | ) |

Parameters

  [in,out] | m | Buffer to be returned and updated.

References membuffer::buf.

## membuffer_init()

void membuffer_init | ( | membuffer * | m | ) |

Wrapper to membuffer_initialize().

Set the size of the buffer to MEMBUF_DEF_SIZE_INC and Initializes m->buf to NULL, length = 0.

Parameters

  [in,out] | m | Buffer to be initialized.

References MEMBUF_DEF_SIZE_INC, and membuffer::size_inc.

Referenced by CreateServicePacket(), genaNotify(), glob_alias_init(), membuffer_destroy(), and web_server_set_alias().

## membuffer_insert()

int membuffer_insert | ( | membuffer * | m,
|  | const void * | buf,
|  | size_t | buf_len,
|  | size_t | index
| ) |  |

Allocates memory for the new data to be inserted. Does memory management by moving the data from the existing memory to the newly allocated memory and then appending the new data.

Returns
  0 if successful, error code if error.

Parameters

  [in,out] | m | Buffer whose memory size is to be increased and appended.
  [in] | buf | source buffer whose contents will be copied.
  [in] | buf_len | size of the source buffer.
  [in] | index | index to determine the bounds while movinf the data.

References membuffer::length.

Referenced by membuffer_append(), and membuffer_append_str().

## membuffer_set_size()

int membuffer_set_size | ( | membuffer * | m,
|  | size_t | new_length
| ) |  |

Increases or decreases buffer cap so that at least 'new_length' bytes can be stored.

Returns
  - UPNP_E_SUCCESS - On Success
  - UPNP_E_OUTOF_MEMORY - On failure to allocate memory.

Parameters

  [in,out] | m | buffer whose size is to be modified.
  [in] | new_length | new size to which the buffer will be modified.

References membuffer::length.

Referenced by membuffer_assign(), and membuffer_delete().

## memptr_cmp()

int memptr_cmp | ( | memptr * | m,
|  | const char * | s
| ) |  |

Compares characters of strings passed for number of bytes. If equal for the number of bytes, the length of the bytes determines which buffer is shorter.

Returns
  - < 0 string1 substring less than string2 substring
  - == 0 string1 substring identical to string2 substring
  - > 0 string1 substring greater than string2 substring

Parameters

  [in] | m | Input memory object.
  [in] | s | Constatnt string for the memory object to be compared with.

References memptr::buf, and memptr::length.

## memptr_cmp_nocase()

int memptr_cmp_nocase | ( | memptr * | m,
|  | const char * | s
| ) |  |

Compares characters of 2 strings irrespective of the case for a specific count of bytes.

If the character comparison is the same the length of the 2 srings determines the shorter of the 2 strings.

Returns
  - < 0 string1 substring less than string2 substring
  - == 0 string1 substring identical to string2 substring
  - > 0 string1 substring greater than string2 substring

Parameters

  [in] | m | Input memory object.
  [in] | s | Constatnt string for the memory object to be compared with.

References memptr::buf, membuffer::buf, membuffer::capacity, memptr::length, membuffer::length, and UPNP_INLINE.

## str_alloc()

char* str_alloc | ( | const char * | str,
|  | size_t | str_len
| ) |  |

Allocate memory and copy information from the input string to the newly allocated memory.

Returns
  Pointer to the newly allocated memory. NULL if memory cannot be allocated.

Parameters

  [in] | str | Input string object.
  [in] | str_len | Input string length.