1
0
Fork 0

Update: Added "igloo_" to all experted symbols

This commit is contained in:
Philipp Schafft 2018-10-12 10:55:24 +00:00
parent f2efba644c
commit 5cc52a7b3d
20 changed files with 723 additions and 723 deletions

146
avl/avl.c
View File

@ -40,7 +40,7 @@
#include "avl.h"
avl_node *
avl_node_new (void * key,
igloo_avl_node_new (void * key,
avl_node * parent)
{
avl_node * node = (avl_node *) malloc (sizeof (avl_node));
@ -63,7 +63,7 @@ avl_node_new (void * key,
}
avl_tree *
avl_tree_new (avl_key_compare_fun_type compare_fun,
igloo_avl_tree_new (avl_key_compare_fun_type compare_fun,
void * compare_arg)
{
avl_tree * t = (avl_tree *) malloc (sizeof (avl_tree));
@ -71,7 +71,7 @@ avl_tree_new (avl_key_compare_fun_type compare_fun,
if (!t) {
return NULL;
} else {
avl_node * root = avl_node_new((void *)NULL, (avl_node *) NULL);
avl_node * root = igloo_avl_node_new((void *)NULL, (avl_node *) NULL);
if (!root) {
free (t);
return NULL;
@ -88,44 +88,44 @@ avl_tree_new (avl_key_compare_fun_type compare_fun,
}
static void
avl_tree_free_helper (avl_node * node, avl_free_key_fun_type free_key_fun)
igloo_avl_tree_free_helper (avl_node * node, avl_free_key_fun_type free_key_fun)
{
if (node->left) {
avl_tree_free_helper (node->left, free_key_fun);
igloo_avl_tree_free_helper (node->left, free_key_fun);
}
if (free_key_fun)
free_key_fun (node->key);
if (node->right) {
avl_tree_free_helper (node->right, free_key_fun);
igloo_avl_tree_free_helper (node->right, free_key_fun);
}
#ifdef HAVE_AVL_NODE_LOCK
thread_rwlock_destroy (&node->rwlock);
igloo_thread_rwlock_destroy (&node->rwlock);
#endif
free (node);
}
void
avl_tree_free (avl_tree * tree, avl_free_key_fun_type free_key_fun)
igloo_avl_tree_free (avl_tree * tree, avl_free_key_fun_type free_key_fun)
{
if (tree->length) {
avl_tree_free_helper (tree->root->right, free_key_fun);
igloo_avl_tree_free_helper (tree->root->right, free_key_fun);
}
if (tree->root) {
#ifdef HAVE_AVL_NODE_LOCK
thread_rwlock_destroy(&tree->root->rwlock);
igloo_thread_rwlock_destroy(&tree->root->rwlock);
#endif
free (tree->root);
}
thread_rwlock_destroy(&tree->rwlock);
igloo_thread_rwlock_destroy(&tree->rwlock);
free (tree);
}
int
avl_insert (avl_tree * ob,
igloo_avl_insert (avl_tree * ob,
void * key)
{
if (!(ob->root->right)) {
avl_node * node = avl_node_new (key, ob->root);
avl_node * node = igloo_avl_node_new (key, ob->root);
if (!node) {
return -1;
} else {
@ -147,7 +147,7 @@ avl_insert (avl_tree * ob,
q = p->left;
if (!q) {
/* insert */
avl_node * q_node = avl_node_new (key, p);
avl_node * q_node = igloo_avl_node_new (key, p);
if (!q_node) {
return (-1);
} else {
@ -165,7 +165,7 @@ avl_insert (avl_tree * ob,
q = p->right;
if (!q) {
/* insert */
avl_node * q_node = avl_node_new (key, p);
avl_node * q_node = igloo_avl_node_new (key, p);
if (!q_node) {
return -1;
} else {
@ -297,7 +297,7 @@ avl_insert (avl_tree * ob,
}
int
avl_get_by_index (avl_tree * tree,
igloo_avl_get_by_index (avl_tree * tree,
unsigned long index,
void ** value_address)
{
@ -320,7 +320,7 @@ avl_get_by_index (avl_tree * tree,
}
int
avl_get_by_key (avl_tree * tree,
igloo_avl_get_by_key (avl_tree * tree,
void * key,
void **value_address)
{
@ -349,7 +349,7 @@ avl_get_by_key (avl_tree * tree,
}
}
int avl_delete(avl_tree *tree, void *key, avl_free_key_fun_type free_key_fun)
int igloo_avl_delete(avl_tree *tree, void *key, avl_free_key_fun_type free_key_fun)
{
avl_node *x, *y, *p, *q, *r, *top, *x_child;
int shortened_side, shorter;
@ -458,7 +458,7 @@ int avl_delete(avl_tree *tree, void *key, avl_free_key_fun_type free_key_fun)
if (free_key_fun)
free_key_fun (x->key);
#ifdef HAVE_AVL_NODE_LOCK
thread_rwlock_destroy (&x->rwlock);
igloo_thread_rwlock_destroy (&x->rwlock);
#endif
free (x);
@ -625,13 +625,13 @@ int avl_delete(avl_tree *tree, void *key, avl_free_key_fun_type free_key_fun)
}
static int
avl_iterate_inorder_helper (avl_node * node,
igloo_avl_iterate_inorder_helper (avl_node * node,
avl_iter_fun_type iter_fun,
void * iter_arg)
{
int result;
if (node->left) {
result = avl_iterate_inorder_helper (node->left, iter_fun, iter_arg);
result = igloo_avl_iterate_inorder_helper (node->left, iter_fun, iter_arg);
if (result != 0) {
return result;
}
@ -641,7 +641,7 @@ avl_iterate_inorder_helper (avl_node * node,
return result;
}
if (node->right) {
result = avl_iterate_inorder_helper (node->right, iter_fun, iter_arg);
result = igloo_avl_iterate_inorder_helper (node->right, iter_fun, iter_arg);
if (result != 0) {
return result;
}
@ -650,21 +650,21 @@ avl_iterate_inorder_helper (avl_node * node,
}
int
avl_iterate_inorder (avl_tree * tree,
igloo_avl_iterate_inorder (avl_tree * tree,
avl_iter_fun_type iter_fun,
void * iter_arg)
{
int result;
if (tree->length) {
result = avl_iterate_inorder_helper (tree->root->right, iter_fun, iter_arg);
result = igloo_avl_iterate_inorder_helper (tree->root->right, iter_fun, iter_arg);
return (result);
} else {
return 0;
}
}
avl_node *avl_get_first(avl_tree *tree)
avl_node *igloo_avl_get_first(avl_tree *tree)
{
avl_node *node;
@ -677,7 +677,7 @@ avl_node *avl_get_first(avl_tree *tree)
return node;
}
avl_node *avl_get_prev(avl_node *node)
avl_node *igloo_avl_get_prev(avl_node *node)
{
if (node->left) {
node = node->left;
@ -700,7 +700,7 @@ avl_node *avl_get_prev(avl_node *node)
}
}
avl_node *avl_get_next(avl_node *node)
avl_node *igloo_avl_get_next(avl_node *node)
{
if (node->right) {
node = node->right;
@ -726,7 +726,7 @@ avl_node *avl_get_next(avl_node *node)
/* iterate a function over a range of indices, using get_predecessor */
int
avl_iterate_index_range (avl_tree * tree,
igloo_avl_iterate_index_range (avl_tree * tree,
avl_iter_index_fun_type iter_fun,
unsigned long low,
unsigned long high,
@ -759,7 +759,7 @@ avl_iterate_index_range (avl_tree * tree,
if (iter_fun (num_left, node->key, iter_arg) != 0) {
return -1;
}
node = avl_get_prev (node);
node = igloo_avl_get_prev (node);
}
return 0;
}
@ -770,7 +770,7 @@ avl_iterate_index_range (avl_tree * tree,
*/
static avl_node *
avl_get_index_by_key (avl_tree * tree,
igloo_avl_get_index_by_key (avl_tree * tree,
void * key,
unsigned long * index)
{
@ -811,7 +811,7 @@ avl_get_index_by_key (avl_tree * tree,
/* return the (low index, high index) pair that spans the given key */
int
avl_get_span_by_key (avl_tree * tree,
igloo_avl_get_span_by_key (avl_tree * tree,
void * key,
unsigned long * low,
unsigned long * high)
@ -819,7 +819,7 @@ avl_get_span_by_key (avl_tree * tree,
unsigned long m, i, j;
avl_node * node;
node = avl_get_index_by_key (tree, key, &m);
node = igloo_avl_get_index_by_key (tree, key, &m);
/* did we find an exact match?
* if so, we have to search left and right
@ -829,17 +829,17 @@ avl_get_span_by_key (avl_tree * tree,
if (node) {
avl_node * left, * right;
/* search left */
left = avl_get_prev (node);
left = igloo_avl_get_prev (node);
i = m;
while (left && (i > 0) && (tree->compare_fun (tree->compare_arg, key, left->key) == 0)) {
left = avl_get_prev (left);
left = igloo_avl_get_prev (left);
i = i - 1;
}
/* search right */
right = avl_get_next (node);
right = igloo_avl_get_next (node);
j = m;
while (right && (j <= tree->length) && (tree->compare_fun (tree->compare_arg, key, right->key) == 0)) {
right = avl_get_next (right);
right = igloo_avl_get_next (right);
j = j + 1;
}
*low = i;
@ -854,7 +854,7 @@ avl_get_span_by_key (avl_tree * tree,
/* return the (low index, high index) pair that spans the given key */
int
avl_get_span_by_two_keys (avl_tree * tree,
igloo_avl_get_span_by_two_keys (avl_tree * tree,
void * low_key,
void * high_key,
unsigned long * low,
@ -872,15 +872,15 @@ avl_get_span_by_two_keys (avl_tree * tree,
high_key = temp;
}
low_node = avl_get_index_by_key (tree, low_key, &i);
high_node = avl_get_index_by_key (tree, high_key, &j);
low_node = igloo_avl_get_index_by_key (tree, low_key, &i);
high_node = igloo_avl_get_index_by_key (tree, high_key, &j);
if (low_node) {
avl_node * left;
/* search left */
left = avl_get_prev (low_node);
left = igloo_avl_get_prev (low_node);
while (left && (i > 0) && (tree->compare_fun (tree->compare_arg, low_key, left->key) == 0)) {
left = avl_get_prev (left);
left = igloo_avl_get_prev (left);
i = i - 1;
}
} else {
@ -889,9 +889,9 @@ avl_get_span_by_two_keys (avl_tree * tree,
if (high_node) {
avl_node * right;
/* search right */
right = avl_get_next (high_node);
right = igloo_avl_get_next (high_node);
while (right && (j <= tree->length) && (tree->compare_fun (tree->compare_arg, high_key, right->key) == 0)) {
right = avl_get_next (right);
right = igloo_avl_get_next (right);
j = j + 1;
}
} else {
@ -905,7 +905,7 @@ avl_get_span_by_two_keys (avl_tree * tree,
int
avl_get_item_by_key_most (avl_tree * tree,
igloo_avl_get_item_by_key_most (avl_tree * tree,
void * key,
void **value_address)
{
@ -949,7 +949,7 @@ avl_get_item_by_key_most (avl_tree * tree,
}
int
avl_get_item_by_key_least (avl_tree * tree,
igloo_avl_get_item_by_key_least (avl_tree * tree,
void * key,
void **value_address)
{
@ -993,13 +993,13 @@ avl_get_item_by_key_least (avl_tree * tree,
#define AVL_MAX(X, Y) ((X) > (Y) ? (X) : (Y))
static long
avl_verify_balance (avl_node * node)
igloo_avl_verify_balance (avl_node * node)
{
if (!node) {
return 0;
} else {
long lh = avl_verify_balance (node->left);
long rh = avl_verify_balance (node->right);
long lh = igloo_avl_verify_balance (node->left);
long rh = igloo_avl_verify_balance (node->right);
if ((rh - lh) != AVL_GET_BALANCE(node)) {
return 0;
}
@ -1011,31 +1011,31 @@ avl_verify_balance (avl_node * node)
}
static void
avl_verify_parent (avl_node * node, avl_node * parent)
igloo_avl_verify_parent (avl_node * node, avl_node * parent)
{
if (node->parent != parent) {
return;
}
if (node->left) {
avl_verify_parent (node->left, node);
igloo_avl_verify_parent (node->left, node);
}
if (node->right) {
avl_verify_parent (node->right, node);
igloo_avl_verify_parent (node->right, node);
}
}
static long
avl_verify_rank (avl_node * node)
igloo_avl_verify_rank (avl_node * node)
{
if (!node) {
return 0;
} else {
unsigned long num_left=0, num_right=0;
if (node->left) {
num_left = avl_verify_rank (node->left);
num_left = igloo_avl_verify_rank (node->left);
}
if (node->right) {
num_right = avl_verify_rank (node->right);
num_right = igloo_avl_verify_rank (node->right);
}
if (AVL_GET_RANK (node) != num_left + 1) {
fprintf (stderr, "invalid rank at node %ld\n", (long) node->key);
@ -1048,12 +1048,12 @@ avl_verify_rank (avl_node * node)
/* sanity-check the tree */
int
avl_verify (avl_tree * tree)
igloo_avl_verify (avl_tree * tree)
{
if (tree->length) {
avl_verify_balance (tree->root->right);
avl_verify_parent (tree->root->right, tree->root);
avl_verify_rank (tree->root->right);
igloo_avl_verify_balance (tree->root->right);
igloo_avl_verify_parent (tree->root->right, tree->root);
igloo_avl_verify_rank (tree->root->right);
}
return (0);
}
@ -1070,10 +1070,10 @@ typedef struct _link_node {
int width;
} link_node;
static char balance_chars[3] = {'\\', '-', '/'};
static char igloo_balance_chars[3] = {'\\', '-', '/'};
static int
default_key_printer (char * buffer, void * key)
igloo_default_key_printer (char * buffer, void * key)
{
return snprintf (buffer, AVL_KEY_PRINTER_BUFLEN, "%p", key);
}
@ -1086,10 +1086,10 @@ default_key_printer (char * buffer, void * key)
*/
static void
print_connectors (link_node * link)
igloo_print_connectors (link_node * link)
{
if (link->parent) {
print_connectors (link->parent);
igloo_print_connectors (link->parent);
}
if (link->parent && (link->parent->direction != link->direction) && (link->parent->parent)) {
int i;
@ -1113,7 +1113,7 @@ print_connectors (link_node * link)
*/
static void
print_node (avl_key_printer_fun_type key_printer,
igloo_print_node (avl_key_printer_fun_type key_printer,
avl_node * node,
link_node * link)
{
@ -1126,11 +1126,11 @@ print_node (avl_key_printer_fun_type key_printer,
here.parent = link;
here.direction = 1;
here.width = width + 11;
print_node (key_printer, node->right, &here);
igloo_print_node (key_printer, node->right, &here);
}
print_connectors (link);
igloo_print_connectors (link);
fprintf (stdout, "+-[%c %s %03d]",
balance_chars[AVL_GET_BALANCE(node)+1],
igloo_balance_chars[AVL_GET_BALANCE(node)+1],
buffer,
(int)AVL_GET_RANK(node));
if (node->left || node->right) {
@ -1143,36 +1143,36 @@ print_node (avl_key_printer_fun_type key_printer,
here.parent = link;
here.direction = -1;
here.width = width + 11;
print_node (key_printer, node->left, &here);
igloo_print_node (key_printer, node->left, &here);
}
}
void
avl_print_tree (avl_tree * tree, avl_key_printer_fun_type key_printer)
igloo_avl_print_tree (avl_tree * tree, avl_key_printer_fun_type key_printer)
{
link_node top = {NULL, 0, 0};
if (!key_printer) {
key_printer = default_key_printer;
key_printer = igloo_default_key_printer;
}
if (tree->length) {
print_node (key_printer, tree->root->right, &top);
igloo_print_node (key_printer, tree->root->right, &top);
} else {
fprintf (stdout, "<empty tree>\n");
}
}
void avl_tree_rlock(avl_tree *tree)
void igloo_avl_tree_rlock(avl_tree *tree)
{
thread_rwlock_rlock(&tree->rwlock);
}
void avl_tree_wlock(avl_tree *tree)
void igloo_avl_tree_wlock(avl_tree *tree)
{
thread_rwlock_wlock(&tree->rwlock);
}
void avl_tree_unlock(avl_tree *tree)
void igloo_avl_tree_unlock(avl_tree *tree)
{
thread_rwlock_unlock(&tree->rwlock);
}

View File

@ -18,7 +18,7 @@ extern "C" {
#include "thread/thread.h"
#else
#define thread_rwlock_create(x) do{}while(0)
#define thread_rwlock_destroy(x) do{}while(0)
#define igloo_thread_rwlock_destroy(x) do{}while(0)
#define thread_rwlock_rlock(x) do{}while(0)
#define thread_rwlock_wlock(x) do{}while(0)
#define thread_rwlock_unlock(x) do{}while(0)
@ -76,44 +76,44 @@ typedef struct _avl_tree {
#endif
} avl_tree;
avl_tree * avl_tree_new (avl_key_compare_fun_type compare_fun, void * compare_arg);
avl_node * avl_node_new (void * key, avl_node * parent);
avl_tree * igloo_avl_tree_new (avl_key_compare_fun_type compare_fun, void * compare_arg);
avl_node * igloo_avl_node_new (void * key, avl_node * parent);
void avl_tree_free (
void igloo_avl_tree_free (
avl_tree * tree,
avl_free_key_fun_type free_key_fun
);
int avl_insert (
int igloo_avl_insert (
avl_tree * ob,
void * key
);
int avl_delete (
int igloo_avl_delete (
avl_tree * tree,
void * key,
avl_free_key_fun_type free_key_fun
);
int avl_get_by_index (
int igloo_avl_get_by_index (
avl_tree * tree,
unsigned long index,
void ** value_address
);
int avl_get_by_key (
int igloo_avl_get_by_key (
avl_tree * tree,
void * key,
void ** value_address
);
int avl_iterate_inorder (
int igloo_avl_iterate_inorder (
avl_tree * tree,
avl_iter_fun_type iter_fun,
void * iter_arg
);
int avl_iterate_index_range (
int igloo_avl_iterate_index_range (
avl_tree * tree,
avl_iter_index_fun_type iter_fun,
unsigned long low,
@ -121,14 +121,14 @@ int avl_iterate_index_range (
void * iter_arg
);
int avl_get_span_by_key (
int igloo_avl_get_span_by_key (
avl_tree * tree,
void * key,
unsigned long * low,
unsigned long * high
);
int avl_get_span_by_two_keys (
int igloo_avl_get_span_by_two_keys (
avl_tree * tree,
void * key_a,
void * key_b,
@ -136,37 +136,37 @@ int avl_get_span_by_two_keys (
unsigned long * high
);
int avl_verify (avl_tree * tree);
int igloo_avl_verify (avl_tree * tree);
void avl_print_tree (
void igloo_avl_print_tree (
avl_tree * tree,
avl_key_printer_fun_type key_printer
);
avl_node *avl_get_first(avl_tree *tree);
avl_node *igloo_avl_get_first(avl_tree *tree);
avl_node *avl_get_prev(avl_node * node);
avl_node *igloo_avl_get_prev(avl_node * node);
avl_node *avl_get_next(avl_node * node);
avl_node *igloo_avl_get_next(avl_node * node);
/* These two are from David Ascher <david_ascher@brown.edu> */
int avl_get_item_by_key_most (
int igloo_avl_get_item_by_key_most (
avl_tree * tree,
void * key,
void ** value_address
);
int avl_get_item_by_key_least (
int igloo_avl_get_item_by_key_least (
avl_tree * tree,
void * key,
void ** value_address
);
/* optional locking stuff */
void avl_tree_rlock(avl_tree *tree);
void avl_tree_wlock(avl_tree *tree);
void avl_tree_unlock(avl_tree *tree);
void igloo_avl_tree_rlock(avl_tree *tree);
void igloo_avl_tree_wlock(avl_tree *tree);
void igloo_avl_tree_unlock(avl_tree *tree);
void avl_node_rlock(avl_node *node);
void avl_node_wlock(avl_node *node);
void avl_node_unlock(avl_node *node);

View File

@ -25,21 +25,21 @@ int main(int argc, char **argv)
printf("avl test... max_nodes = %d...\n", max_nodes);
tree = avl_tree_new(_compare, NULL);
tree = igloo_avl_tree_new(_compare, NULL);
printf("Filling tree...\n");
for (i = 0; i < max_nodes; i++) {
avl_insert(tree, (void *)rand());
igloo_avl_insert(tree, (void *)rand());
}
printf("Traversing tree...\n");
node = avl_get_first(tree);
node = igloo_avl_get_first(tree);
while (node) {
i = (int)node->key;
printf("...%5d\n", i);
node = avl_get_next(node);
node = igloo_avl_get_next(node);
}
printf("Trying to go backwards...\n");
@ -47,13 +47,13 @@ int main(int argc, char **argv)
while (node) {
i = (int)node->key;
printf("...%5d\n", i);
node = avl_get_prev(node);
node = igloo_avl_get_prev(node);
}
printf("Printing tree...\n");
avl_print_tree(tree, _printer);
igloo_avl_print_tree(tree, _printer);
avl_tree_free(tree, _free);
igloo_avl_tree_free(tree, _free);
return 0;
}

View File

@ -62,13 +62,13 @@ struct httpp_encoding_tag {
/* Handlers, at end of file */
static ssize_t __enc_identity_read(httpp_encoding_t *self, void *buf, size_t len, ssize_t (*cb)(void*, void*, size_t), void *userdata);
static ssize_t __enc_identity_write(httpp_encoding_t *self, const void *buf, size_t len, ssize_t (*cb)(void*, const void*, size_t), void *userdata);
static ssize_t __enc_chunked_read(httpp_encoding_t *self, void *buf, size_t len, ssize_t (*cb)(void*, void*, size_t), void *userdata);
static ssize_t __enc_chunked_write(httpp_encoding_t *self, const void *buf, size_t len, ssize_t (*cb)(void*, const void*, size_t), void *userdata);
static ssize_t igloo___enc_identity_read(httpp_encoding_t *self, void *buf, size_t len, ssize_t (*cb)(void*, void*, size_t), void *userdata);
static ssize_t igloo___enc_identity_write(httpp_encoding_t *self, const void *buf, size_t len, ssize_t (*cb)(void*, const void*, size_t), void *userdata);
static ssize_t igloo___enc_chunked_read(httpp_encoding_t *self, void *buf, size_t len, ssize_t (*cb)(void*, void*, size_t), void *userdata);
static ssize_t igloo___enc_chunked_write(httpp_encoding_t *self, const void *buf, size_t len, ssize_t (*cb)(void*, const void*, size_t), void *userdata);
/* function to move some data out of our buffers */
ssize_t __copy_buffer(void *dst, void **src, size_t *boffset, size_t *blen, size_t len)
ssize_t igloo___copy_buffer(void *dst, void **src, size_t *boffset, size_t *blen, size_t len)
{
void *p;
size_t have_len;
@ -120,7 +120,7 @@ static inline void __flush_output(httpp_encoding_t *self, ssize_t (*cb)(void*, c
/* meta data functions */
/* meta data is to be used in a encoding-specific way */
httpp_meta_t *httpp_encoding_meta_new(const char *key, const char *value)
httpp_meta_t *igloo_httpp_encoding_meta_new(const char *key, const char *value)
{
httpp_meta_t *ret = calloc(1, sizeof(httpp_meta_t));
if (!ret)
@ -138,11 +138,11 @@ httpp_meta_t *httpp_encoding_meta_new(const char *key, const char *value)
return ret;
fail:
httpp_encoding_meta_free(ret);
igloo_httpp_encoding_meta_free(ret);
return NULL;
}
int httpp_encoding_meta_free(httpp_meta_t *self)
int igloo_httpp_encoding_meta_free(httpp_meta_t *self)
{
while (self) {
httpp_meta_t *cur = self;
@ -158,7 +158,7 @@ int httpp_encoding_meta_free(httpp_meta_t *self)
return 0;
}
int httpp_encoding_meta_append(httpp_meta_t **dst, httpp_meta_t *next)
int igloo_httpp_encoding_meta_append(httpp_meta_t **dst, httpp_meta_t *next)
{
httpp_meta_t **cur;
@ -177,7 +177,7 @@ int httpp_encoding_meta_append(httpp_meta_t **dst, httpp_meta_t *n
}
/* General setup */
httpp_encoding_t *httpp_encoding_new(const char *encoding) {
httpp_encoding_t *igloo_httpp_encoding_new(const char *encoding) {
httpp_encoding_t *ret = calloc(1, sizeof(httpp_encoding_t));
if (!ret)
return NULL;
@ -186,11 +186,11 @@ httpp_encoding_t *httpp_encoding_new(const char *encoding) {
ret->bytes_till_eof = -1;
if (strcasecmp(encoding, HTTPP_ENCODING_IDENTITY) == 0) {
ret->process_read = __enc_identity_read;
ret->process_write = __enc_identity_write;
ret->process_read = igloo___enc_identity_read;
ret->process_write = igloo___enc_identity_write;
} else if (strcasecmp(encoding, HTTPP_ENCODING_CHUNKED) == 0) {
ret->process_read = __enc_chunked_read;
ret->process_write = __enc_chunked_write;
ret->process_read = igloo___enc_chunked_read;
ret->process_write = igloo___enc_chunked_write;
} else {
goto fail;
}
@ -198,11 +198,11 @@ httpp_encoding_t *httpp_encoding_new(const char *encoding) {
return ret;
fail:
httpp_encoding_release(ret);
igloo_httpp_encoding_release(ret);
return NULL;
}
int httpp_encoding_addref(httpp_encoding_t *self)
int igloo_httpp_encoding_addref(httpp_encoding_t *self)
{
if (!self)
return -1;
@ -210,7 +210,7 @@ int httpp_encoding_addref(httpp_encoding_t *self)
return 0;
}
int httpp_encoding_release(httpp_encoding_t *self)
int igloo_httpp_encoding_release(httpp_encoding_t *self)
{
if (!self)
return -1;
@ -219,8 +219,8 @@ int httpp_encoding_release(httpp_encoding_t *self)
if (self->refc)
return 0;
httpp_encoding_meta_free(self->meta_read);
httpp_encoding_meta_free(self->meta_write);
igloo_httpp_encoding_meta_free(self->meta_read);
igloo_httpp_encoding_meta_free(self->meta_write);
if (self->buf_read_raw)
free(self->buf_read_raw);
@ -237,7 +237,7 @@ int httpp_encoding_release(httpp_encoding_t *self)
/* Read data from backend.
* if cb is NULL this will read from the internal buffer.
*/
ssize_t httpp_encoding_read(httpp_encoding_t *self, void *buf, size_t len, ssize_t (*cb)(void*, void*, size_t), void *userdata)
ssize_t igloo_httpp_encoding_read(httpp_encoding_t *self, void *buf, size_t len, ssize_t (*cb)(void*, void*, size_t), void *userdata)
{
ssize_t done = 0;
ssize_t ret;
@ -248,7 +248,7 @@ ssize_t httpp_encoding_read(httpp_encoding_t *self, void *buf, size_t
if (!len)
return 0;
ret = __copy_buffer(buf, &(self->buf_read_decoded), &(self->buf_read_decoded_offset), &(self->buf_read_decoded_len), len);
ret = igloo___copy_buffer(buf, &(self->buf_read_decoded), &(self->buf_read_decoded_offset), &(self->buf_read_decoded_len), len);
if (ret == (ssize_t)len)
return ret;
@ -270,7 +270,7 @@ ssize_t httpp_encoding_read(httpp_encoding_t *self, void *buf, size_t
len -= ret;
if (len) {
ret = __copy_buffer(buf, &(self->buf_read_decoded), &(self->buf_read_decoded_offset), &(self->buf_read_decoded_len), len);
ret = igloo___copy_buffer(buf, &(self->buf_read_decoded), &(self->buf_read_decoded_offset), &(self->buf_read_decoded_len), len);
if (ret > 0) {
done += ret;
buf += ret;
@ -281,7 +281,7 @@ ssize_t httpp_encoding_read(httpp_encoding_t *self, void *buf, size_t
return done;
}
int httpp_encoding_eof(httpp_encoding_t *self, int (*cb)(void*), void *userdata)
int igloo_httpp_encoding_eof(httpp_encoding_t *self, int (*cb)(void*), void *userdata)
{
if (!self)
return -1;
@ -302,7 +302,7 @@ int httpp_encoding_eof(httpp_encoding_t *self, int (*cb)(void*), v
* After a call to this function the meta data is released from the
* encoding object and the caller is responsible to free it.
*/
httpp_meta_t *httpp_encoding_get_meta(httpp_encoding_t *self)
httpp_meta_t *igloo_httpp_encoding_get_meta(httpp_encoding_t *self)
{
httpp_meta_t *ret;
@ -319,7 +319,7 @@ httpp_meta_t *httpp_encoding_get_meta(httpp_encoding_t *self)
* Depending on encoding flushing buffers may not be safe if not
* at end of stream.
*/
ssize_t httpp_encoding_write(httpp_encoding_t *self, const void *buf, size_t len, ssize_t (*cb)(void*, const void*, size_t), void *userdata)
ssize_t igloo_httpp_encoding_write(httpp_encoding_t *self, const void *buf, size_t len, ssize_t (*cb)(void*, const void*, size_t), void *userdata)
{
ssize_t ret;
@ -339,7 +339,7 @@ ssize_t httpp_encoding_write(httpp_encoding_t *self, const void *buf,
}
/* Check if we have something to flush. */
ssize_t httpp_encoding_pending(httpp_encoding_t *self)
ssize_t igloo_httpp_encoding_pending(httpp_encoding_t *self)
{
if (!self)
return -1;
@ -351,15 +351,15 @@ ssize_t httpp_encoding_pending(httpp_encoding_t *self)
/* Attach meta data to the stream.
* this is to be written out as soon as the encoding supports.
*/
int httpp_encoding_append_meta(httpp_encoding_t *self, httpp_meta_t *meta)
int igloo_httpp_encoding_append_meta(httpp_encoding_t *self, httpp_meta_t *meta)
{
if (!self)
return -1;
return httpp_encoding_meta_append(&(self->meta_write), meta);
return igloo_httpp_encoding_meta_append(&(self->meta_write), meta);
}
/* handlers for encodings */
static ssize_t __enc_identity_read(httpp_encoding_t *self, void *buf, size_t len, ssize_t (*cb)(void*, void*, size_t), void *userdata)
static ssize_t igloo___enc_identity_read(httpp_encoding_t *self, void *buf, size_t len, ssize_t (*cb)(void*, void*, size_t), void *userdata)
{
(void)self;
if (!cb)
@ -367,7 +367,7 @@ static ssize_t __enc_identity_read(httpp_encoding_t *self, void *buf, size_t len
return cb(userdata, buf, len);
}
static ssize_t __enc_identity_write(httpp_encoding_t *self, const void *buf, size_t len, ssize_t (*cb)(void*, const void*, size_t), void *userdata)
static ssize_t igloo___enc_identity_write(httpp_encoding_t *self, const void *buf, size_t len, ssize_t (*cb)(void*, const void*, size_t), void *userdata)
{
(void)self;
if (!cb)
@ -414,7 +414,7 @@ static void __enc_chunked_read_extentions(httpp_encoding_t *self, char *p, size_
p++;
len--;
*parent = meta = httpp_encoding_meta_new(NULL, NULL);
*parent = meta = igloo_httpp_encoding_meta_new(NULL, NULL);
parent = &(meta->next);
for (key_len = 0; key_len < len && p[key_len] != '='; key_len++);
@ -482,7 +482,7 @@ static void __enc_chunked_read_extentions(httpp_encoding_t *self, char *p, size_
}
}
static ssize_t __enc_chunked_read(httpp_encoding_t *self, void *buf, size_t len, ssize_t (*cb)(void*, void*, size_t), void *userdata)
static ssize_t igloo___enc_chunked_read(httpp_encoding_t *self, void *buf, size_t len, ssize_t (*cb)(void*, void*, size_t), void *userdata)
{
ssize_t ret;
size_t buflen;
@ -780,12 +780,12 @@ static char *__enc_chunked_write_extensions(httpp_encoding_t *self)
*p = 0; /* terminate the string */
httpp_encoding_meta_free(self->meta_write);
igloo_httpp_encoding_meta_free(self->meta_write);
self->meta_write = NULL;
return buf;
}
static ssize_t __enc_chunked_write(httpp_encoding_t *self, const void *buf, size_t len, ssize_t (*cb)(void*, const void*, size_t), void *userdata)
static ssize_t igloo___enc_chunked_write(httpp_encoding_t *self, const void *buf, size_t len, ssize_t (*cb)(void*, const void*, size_t), void *userdata)
{
char encoded_length[32];
char *extensions = NULL;
@ -798,7 +798,7 @@ static ssize_t __enc_chunked_write(httpp_encoding_t *self, const void *buf, size
len = 0;
/* refuse to write if we still have stuff to flush. */
if (httpp_encoding_pending(self) > 0)
if (igloo_httpp_encoding_pending(self) > 0)
return 0;
/* limit length to a bit more sane value */

View File

@ -46,44 +46,44 @@ struct httpp_meta_tag {
/* meta data functions */
/* meta data is to be used in a encoding-specific way */
httpp_meta_t *httpp_encoding_meta_new(const char *key, const char *value);
int httpp_encoding_meta_free(httpp_meta_t *self);
int httpp_encoding_meta_append(httpp_meta_t **dst, httpp_meta_t *next);
httpp_meta_t *igloo_httpp_encoding_meta_new(const char *key, const char *value);
int igloo_httpp_encoding_meta_free(httpp_meta_t *self);
int igloo_httpp_encoding_meta_append(httpp_meta_t **dst, httpp_meta_t *next);
/* General setup */
httpp_encoding_t *httpp_encoding_new(const char *encoding);
int httpp_encoding_addref(httpp_encoding_t *self);
int httpp_encoding_release(httpp_encoding_t *self);
httpp_encoding_t *igloo_httpp_encoding_new(const char *encoding);
int igloo_httpp_encoding_addref(httpp_encoding_t *self);
int igloo_httpp_encoding_release(httpp_encoding_t *self);
/* Read data from backend.
* if cb is NULL this will read from the internal buffer.
*/
ssize_t httpp_encoding_read(httpp_encoding_t *self, void *buf, size_t len, ssize_t (*cb)(void*, void*, size_t), void *userdata);
ssize_t igloo_httpp_encoding_read(httpp_encoding_t *self, void *buf, size_t len, ssize_t (*cb)(void*, void*, size_t), void *userdata);
/* Check if EOF is reached.
* If cb is not NULL this also considers backend state.
*/
int httpp_encoding_eof(httpp_encoding_t *self, int (*cb)(void*), void *userdata);
int igloo_httpp_encoding_eof(httpp_encoding_t *self, int (*cb)(void*), void *userdata);
/* Read any meta data that is in buffer.
* After a call to this function the meta data is released from the
* encoding object and the caller is responsible to free it.
*/
httpp_meta_t *httpp_encoding_get_meta(httpp_encoding_t *self);
httpp_meta_t *igloo_httpp_encoding_get_meta(httpp_encoding_t *self);
/* Write data to backend.
* If buf is NULL this will flush buffers.
* Depending on encoding flushing buffers may not be safe if not
* at end of stream.
*/
ssize_t httpp_encoding_write(httpp_encoding_t *self, const void *buf, size_t len, ssize_t (*cb)(void*, const void*, size_t), void *userdata);
ssize_t igloo_httpp_encoding_write(httpp_encoding_t *self, const void *buf, size_t len, ssize_t (*cb)(void*, const void*, size_t), void *userdata);
/* Check if we have something to flush. */
ssize_t httpp_encoding_pending(httpp_encoding_t *self);
ssize_t igloo_httpp_encoding_pending(httpp_encoding_t *self);
/* Attach meta data to the stream.
* this is to be written out as soon as the encoding supports.
*/
int httpp_encoding_append_meta(httpp_encoding_t *self, httpp_meta_t *meta);
int igloo_httpp_encoding_append_meta(httpp_encoding_t *self, httpp_meta_t *meta);
#endif

View File

@ -49,17 +49,17 @@
static char *_lowercase(char *str);
/* for avl trees */
static int _compare_vars(void *compare_arg, void *a, void *b);
static int _free_vars(void *key);
static int igloo__compare_vars(void *compare_arg, void *a, void *b);
static int igloo__free_vars(void *key);
/* For avl tree manipulation */
static void parse_query(avl_tree *tree, const char *query, size_t len);
static const char *_httpp_get_param(avl_tree *tree, const char *name);
static void _httpp_set_param_nocopy(avl_tree *tree, char *name, char *value, int replace);
static void _httpp_set_param(avl_tree *tree, const char *name, const char *value);
static http_var_t *_httpp_get_param_var(avl_tree *tree, const char *name);
static http_var_t *igloo__httpp_get_param_var(avl_tree *tree, const char *name);
httpp_request_info_t httpp_request_info(httpp_request_type_e req)
httpp_request_info_t igloo_httpp_request_info(httpp_request_type_e req)
{
#if 0
#define HTTPP_REQUEST_IS_SAFE ((httpp_request_info_t)0x0001U)
@ -116,21 +116,21 @@ httpp_request_info_t httpp_request_info(httpp_request_type_e req)
}
}
http_parser_t *httpp_create_parser(void)
http_parser_t *igloo_httpp_create_parser(void)
{
http_parser_t *parser = calloc(1, sizeof(http_parser_t));
parser->refc = 1;
parser->req_type = httpp_req_none;
parser->uri = NULL;
parser->vars = avl_tree_new(_compare_vars, NULL);
parser->queryvars = avl_tree_new(_compare_vars, NULL);
parser->postvars = avl_tree_new(_compare_vars, NULL);
parser->vars = igloo_avl_tree_new(igloo__compare_vars, NULL);
parser->queryvars = igloo_avl_tree_new(igloo__compare_vars, NULL);
parser->postvars = igloo_avl_tree_new(igloo__compare_vars, NULL);
return parser;
}
void httpp_initialize(http_parser_t *parser, http_varlist_t *defaults)
void igloo_httpp_initialize(http_parser_t *parser, http_varlist_t *defaults)
{
http_varlist_t *list;
@ -140,14 +140,14 @@ void httpp_initialize(http_parser_t *parser, http_varlist_t *defaults)
size_t i;
for (i = 0; i < list->var.values; i++) {
httpp_setvar(parser, list->var.name, list->var.value[i]);
igloo_httpp_setvar(parser, list->var.name, list->var.value[i]);
}
list = list->next;
}
}
static int split_headers(char *data, unsigned long len, char **line)
static int igloo_split_headers(char *data, unsigned long len, char **line)
{
/* first we count how many lines there are
** and set up the line[] array
@ -177,7 +177,7 @@ static int split_headers(char *data, unsigned long len, char **line)
return lines;
}
static void parse_headers(http_parser_t *parser, char **line, int lines)
static void igloo_parse_headers(http_parser_t *parser, char **line, int lines)
{
int i, l;
int whitespace, slen;
@ -209,14 +209,14 @@ static void parse_headers(http_parser_t *parser, char **line, int lines)
}
if (name != NULL && value != NULL) {
httpp_setvar(parser, _lowercase(name), value);
igloo_httpp_setvar(parser, _lowercase(name), value);
name = NULL;
value = NULL;
}
}
}
int httpp_parse_response(http_parser_t *parser, const char *http_data, unsigned long len, const char *uri)
int igloo_httpp_parse_response(http_parser_t *parser, const char *http_data, unsigned long len, const char *uri)
{
char *data;
char *line[MAX_HEADERS];
@ -232,7 +232,7 @@ int httpp_parse_response(http_parser_t *parser, const char *http_data, unsigned
memcpy(data, http_data, len);
data[len] = 0;
lines = split_headers(data, len, line);
lines = igloo_split_headers(data, len, line);
/* In this case, the first line contains:
* VERSION RESPONSE_CODE MESSAGE, such as HTTP/1.0 200 OK
@ -260,25 +260,25 @@ int httpp_parse_response(http_parser_t *parser, const char *http_data, unsigned
return 0;
}
httpp_setvar(parser, HTTPP_VAR_ERROR_CODE, resp_code);
igloo_httpp_setvar(parser, HTTPP_VAR_ERROR_CODE, resp_code);
code = atoi(resp_code);
if(code < 200 || code >= 300) {
httpp_setvar(parser, HTTPP_VAR_ERROR_MESSAGE, message);
igloo_httpp_setvar(parser, HTTPP_VAR_ERROR_MESSAGE, message);
}
httpp_setvar(parser, HTTPP_VAR_URI, uri);
httpp_setvar(parser, HTTPP_VAR_REQ_TYPE, "NONE");
igloo_httpp_setvar(parser, HTTPP_VAR_URI, uri);
igloo_httpp_setvar(parser, HTTPP_VAR_REQ_TYPE, "NONE");
parse_headers(parser, line, lines);
igloo_parse_headers(parser, line, lines);
free(data);
return 1;
}
int httpp_parse_postdata(http_parser_t *parser, const char *body_data, size_t len)
int igloo_httpp_parse_postdata(http_parser_t *parser, const char *body_data, size_t len)
{
const char *header = httpp_getvar(parser, "content-type");
const char *header = igloo_httpp_getvar(parser, "content-type");
if (strcasecmp(header, "application/x-www-form-urlencoded") != 0) {
return -1;
@ -301,7 +301,7 @@ static int hex(char c)
return -1;
}
static char *url_unescape(const char *src, size_t len)
static char *igloo_url_unescape(const char *src, size_t len)
{
unsigned char *decoded;
size_t i;
@ -374,7 +374,7 @@ static void parse_query_element(avl_tree *tree, const char *start, const char *m
memcpy(key, start, keylen);
key[keylen] = 0;
value = url_unescape(mid + 1, valuelen);
value = igloo_url_unescape(mid + 1, valuelen);
_httpp_set_param_nocopy(tree, key, value, 0);
}
@ -404,7 +404,7 @@ static void parse_query(avl_tree *tree, const char *query, size_t len)
parse_query_element(tree, start, mid, &(query[i]));
}
int httpp_parse(http_parser_t *parser, const char *http_data, unsigned long len)
int igloo_httpp_parse(http_parser_t *parser, const char *http_data, unsigned long len)
{
char *data, *tmp;
char *line[MAX_HEADERS]; /* limited to 32 lines, should be more than enough */
@ -424,7 +424,7 @@ int httpp_parse(http_parser_t *parser, const char *http_data, unsigned long len)
memcpy(data, http_data, len);
data[len] = 0;
lines = split_headers(data, len, line);
lines = igloo_split_headers(data, len, line);
/* parse the first line special
** the format is:
@ -462,13 +462,13 @@ int httpp_parse(http_parser_t *parser, const char *http_data, unsigned long len)
}
}
parser->req_type = httpp_str_to_method(req_type);
parser->req_type = igloo_httpp_str_to_method(req_type);
if (uri != NULL && strlen(uri) > 0) {
char *query;
if((query = strchr(uri, '?')) != NULL) {
httpp_setvar(parser, HTTPP_VAR_RAWURI, uri);
httpp_setvar(parser, HTTPP_VAR_QUERYARGS, query);
igloo_httpp_setvar(parser, HTTPP_VAR_RAWURI, uri);
igloo_httpp_setvar(parser, HTTPP_VAR_QUERYARGS, query);
*query = 0;
query++;
parse_query(parser->queryvars, query, strlen(query));
@ -483,8 +483,8 @@ int httpp_parse(http_parser_t *parser, const char *http_data, unsigned long len)
if ((version != NULL) && ((tmp = strchr(version, '/')) != NULL)) {
tmp[0] = '\0';
if ((strlen(version) > 0) && (strlen(&tmp[1]) > 0)) {
httpp_setvar(parser, HTTPP_VAR_PROTOCOL, version);
httpp_setvar(parser, HTTPP_VAR_VERSION, &tmp[1]);
igloo_httpp_setvar(parser, HTTPP_VAR_PROTOCOL, version);
igloo_httpp_setvar(parser, HTTPP_VAR_VERSION, &tmp[1]);
} else {
free(data);
return 0;
@ -497,37 +497,37 @@ int httpp_parse(http_parser_t *parser, const char *http_data, unsigned long len)
if (parser->req_type != httpp_req_none && parser->req_type != httpp_req_unknown) {
switch (parser->req_type) {
case httpp_req_get:
httpp_setvar(parser, HTTPP_VAR_REQ_TYPE, "GET");
igloo_httpp_setvar(parser, HTTPP_VAR_REQ_TYPE, "GET");
break;
case httpp_req_post:
httpp_setvar(parser, HTTPP_VAR_REQ_TYPE, "POST");
igloo_httpp_setvar(parser, HTTPP_VAR_REQ_TYPE, "POST");
break;
case httpp_req_put:
httpp_setvar(parser, HTTPP_VAR_REQ_TYPE, "PUT");
igloo_httpp_setvar(parser, HTTPP_VAR_REQ_TYPE, "PUT");
break;
case httpp_req_head:
httpp_setvar(parser, HTTPP_VAR_REQ_TYPE, "HEAD");
igloo_httpp_setvar(parser, HTTPP_VAR_REQ_TYPE, "HEAD");
break;
case httpp_req_options:
httpp_setvar(parser, HTTPP_VAR_REQ_TYPE, "OPTIONS");
igloo_httpp_setvar(parser, HTTPP_VAR_REQ_TYPE, "OPTIONS");
break;
case httpp_req_delete:
httpp_setvar(parser, HTTPP_VAR_REQ_TYPE, "DELETE");
igloo_httpp_setvar(parser, HTTPP_VAR_REQ_TYPE, "DELETE");
break;
case httpp_req_trace:
httpp_setvar(parser, HTTPP_VAR_REQ_TYPE, "TRACE");
igloo_httpp_setvar(parser, HTTPP_VAR_REQ_TYPE, "TRACE");
break;
case httpp_req_connect:
httpp_setvar(parser, HTTPP_VAR_REQ_TYPE, "CONNECT");
igloo_httpp_setvar(parser, HTTPP_VAR_REQ_TYPE, "CONNECT");
break;
case httpp_req_source:
httpp_setvar(parser, HTTPP_VAR_REQ_TYPE, "SOURCE");
igloo_httpp_setvar(parser, HTTPP_VAR_REQ_TYPE, "SOURCE");
break;
case httpp_req_play:
httpp_setvar(parser, HTTPP_VAR_REQ_TYPE, "PLAY");
igloo_httpp_setvar(parser, HTTPP_VAR_REQ_TYPE, "PLAY");
break;
case httpp_req_stats:
httpp_setvar(parser, HTTPP_VAR_REQ_TYPE, "STATS");
igloo_httpp_setvar(parser, HTTPP_VAR_REQ_TYPE, "STATS");
break;
default:
break;
@ -538,20 +538,20 @@ int httpp_parse(http_parser_t *parser, const char *http_data, unsigned long len)
}
if (parser->uri != NULL) {
httpp_setvar(parser, HTTPP_VAR_URI, parser->uri);
igloo_httpp_setvar(parser, HTTPP_VAR_URI, parser->uri);
} else {
free(data);
return 0;
}
parse_headers(parser, line, lines);
igloo_parse_headers(parser, line, lines);
free(data);
return 1;
}
void httpp_deletevar(http_parser_t *parser, const char *name)
void igloo_httpp_deletevar(http_parser_t *parser, const char *name)
{
http_var_t var;
@ -561,10 +561,10 @@ void httpp_deletevar(http_parser_t *parser, const char *name)
var.name = (char*)name;
avl_delete(parser->vars, (void *)&var, _free_vars);
igloo_avl_delete(parser->vars, (void *)&var, igloo__free_vars);
}
void httpp_setvar(http_parser_t *parser, const char *name, const char *value)
void igloo_httpp_setvar(http_parser_t *parser, const char *name, const char *value)
{
http_var_t *var;
@ -584,15 +584,15 @@ void httpp_setvar(http_parser_t *parser, const char *name, const char *value)
var->values = 1;
var->value[0] = strdup(value);
if (httpp_getvar(parser, name) == NULL) {
avl_insert(parser->vars, (void *)var);
if (igloo_httpp_getvar(parser, name) == NULL) {
igloo_avl_insert(parser->vars, (void *)var);
} else {
avl_delete(parser->vars, (void *)var, _free_vars);
avl_insert(parser->vars, (void *)var);
igloo_avl_delete(parser->vars, (void *)var, igloo__free_vars);
igloo_avl_insert(parser->vars, (void *)var);
}
}