mirror of
https://gitlab.xiph.org/xiph/icecast-common.git
synced 2024-11-03 04:17:20 -05:00
Update: Added "igloo_" to all #defines and types
This commit is contained in:
parent
5cc52a7b3d
commit
2f7226c8bd
122
avl/avl.c
122
avl/avl.c
@ -27,7 +27,7 @@
|
||||
|
||||
/*
|
||||
* This is a fairly straightfoward translation of a prototype
|
||||
* written in python, 'avl_tree.py'. Read that file first.
|
||||
* written in python, 'igloo_avl_tree.py'. Read that file first.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
@ -39,11 +39,11 @@
|
||||
|
||||
#include "avl.h"
|
||||
|
||||
avl_node *
|
||||
igloo_avl_node *
|
||||
igloo_avl_node_new (void * key,
|
||||
avl_node * parent)
|
||||
igloo_avl_node * parent)
|
||||
{
|
||||
avl_node * node = (avl_node *) malloc (sizeof (avl_node));
|
||||
igloo_avl_node * node = (igloo_avl_node *) malloc (sizeof (igloo_avl_node));
|
||||
|
||||
if (!node) {
|
||||
return NULL;
|
||||
@ -62,16 +62,16 @@ igloo_avl_node_new (void * key,
|
||||
}
|
||||
}
|
||||
|
||||
avl_tree *
|
||||
igloo_avl_tree_new (avl_key_compare_fun_type compare_fun,
|
||||
igloo_avl_tree *
|
||||
igloo_avl_tree_new (igloo_avl_key_compare_fun_type compare_fun,
|
||||
void * compare_arg)
|
||||
{
|
||||
avl_tree * t = (avl_tree *) malloc (sizeof (avl_tree));
|
||||
igloo_avl_tree * t = (igloo_avl_tree *) malloc (sizeof (igloo_avl_tree));
|
||||
|
||||
if (!t) {
|
||||
return NULL;
|
||||
} else {
|
||||
avl_node * root = igloo_avl_node_new((void *)NULL, (avl_node *) NULL);
|
||||
igloo_avl_node * root = igloo_avl_node_new((void *)NULL, (igloo_avl_node *) NULL);
|
||||
if (!root) {
|
||||
free (t);
|
||||
return NULL;
|
||||
@ -88,7 +88,7 @@ igloo_avl_tree_new (avl_key_compare_fun_type compare_fun,
|
||||
}
|
||||
|
||||
static void
|
||||
igloo_avl_tree_free_helper (avl_node * node, avl_free_key_fun_type free_key_fun)
|
||||
igloo_avl_tree_free_helper (igloo_avl_node * node, igloo_avl_free_key_fun_type free_key_fun)
|
||||
{
|
||||
if (node->left) {
|
||||
igloo_avl_tree_free_helper (node->left, free_key_fun);
|
||||
@ -105,7 +105,7 @@ igloo_avl_tree_free_helper (avl_node * node, avl_free_key_fun_type free_key_fun)
|
||||
}
|
||||
|
||||
void
|
||||
igloo_avl_tree_free (avl_tree * tree, avl_free_key_fun_type free_key_fun)
|
||||
igloo_avl_tree_free (igloo_avl_tree * tree, igloo_avl_free_key_fun_type free_key_fun)
|
||||
{
|
||||
if (tree->length) {
|
||||
igloo_avl_tree_free_helper (tree->root->right, free_key_fun);
|
||||
@ -121,11 +121,11 @@ igloo_avl_tree_free (avl_tree * tree, avl_free_key_fun_type free_key_fun)
|
||||
}
|
||||
|
||||
int
|
||||
igloo_avl_insert (avl_tree * ob,
|
||||
igloo_avl_insert (igloo_avl_tree * ob,
|
||||
void * key)
|
||||
{
|
||||
if (!(ob->root->right)) {
|
||||
avl_node * node = igloo_avl_node_new (key, ob->root);
|
||||
igloo_avl_node * node = igloo_avl_node_new (key, ob->root);
|
||||
if (!node) {
|
||||
return -1;
|
||||
} else {
|
||||
@ -134,7 +134,7 @@ igloo_avl_insert (avl_tree * ob,
|
||||
return 0;
|
||||
}
|
||||
} else { /* not self.right == None */
|
||||
avl_node *t, *p, *s, *q, *r;
|
||||
igloo_avl_node *t, *p, *s, *q, *r;
|
||||
int a;
|
||||
|
||||
t = ob->root;
|
||||
@ -147,7 +147,7 @@ igloo_avl_insert (avl_tree * ob,
|
||||
q = p->left;
|
||||
if (!q) {
|
||||
/* insert */
|
||||
avl_node * q_node = igloo_avl_node_new (key, p);
|
||||
igloo_avl_node * q_node = igloo_avl_node_new (key, p);
|
||||
if (!q_node) {
|
||||
return (-1);
|
||||
} else {
|
||||
@ -165,7 +165,7 @@ igloo_avl_insert (avl_tree * ob,
|
||||
q = p->right;
|
||||
if (!q) {
|
||||
/* insert */
|
||||
avl_node * q_node = igloo_avl_node_new (key, p);
|
||||
igloo_avl_node * q_node = igloo_avl_node_new (key, p);
|
||||
if (!q_node) {
|
||||
return -1;
|
||||
} else {
|
||||
@ -297,11 +297,11 @@ igloo_avl_insert (avl_tree * ob,
|
||||
}
|
||||
|
||||
int
|
||||
igloo_avl_get_by_index (avl_tree * tree,
|
||||
igloo_avl_get_by_index (igloo_avl_tree * tree,
|
||||
unsigned long index,
|
||||
void ** value_address)
|
||||
{
|
||||
avl_node * p = tree->root->right;
|
||||
igloo_avl_node * p = tree->root->right;
|
||||
unsigned long m = index + 1;
|
||||
while (1) {
|
||||
if (!p) {
|
||||
@ -320,11 +320,11 @@ igloo_avl_get_by_index (avl_tree * tree,
|
||||
}
|
||||
|
||||
int
|
||||
igloo_avl_get_by_key (avl_tree * tree,
|
||||
igloo_avl_get_by_key (igloo_avl_tree * tree,
|
||||
void * key,
|
||||
void **value_address)
|
||||
{
|
||||
avl_node * x = tree->root->right;
|
||||
igloo_avl_node * x = tree->root->right;
|
||||
if (!x) {
|
||||
return -1;
|
||||
}
|
||||
@ -349,9 +349,9 @@ igloo_avl_get_by_key (avl_tree * tree,
|
||||
}
|
||||
}
|
||||
|
||||
int igloo_avl_delete(avl_tree *tree, void *key, avl_free_key_fun_type free_key_fun)
|
||||
int igloo_avl_delete(igloo_avl_tree *tree, void *key, igloo_avl_free_key_fun_type free_key_fun)
|
||||
{
|
||||
avl_node *x, *y, *p, *q, *r, *top, *x_child;
|
||||
igloo_avl_node *x, *y, *p, *q, *r, *top, *x_child;
|
||||
int shortened_side, shorter;
|
||||
|
||||
x = tree->root->right;
|
||||
@ -625,8 +625,8 @@ int igloo_avl_delete(avl_tree *tree, void *key, avl_free_key_fun_type free_key_f
|
||||
}
|
||||
|
||||
static int
|
||||
igloo_avl_iterate_inorder_helper (avl_node * node,
|
||||
avl_iter_fun_type iter_fun,
|
||||
igloo_avl_iterate_inorder_helper (igloo_avl_node * node,
|
||||
igloo_avl_iter_fun_type iter_fun,
|
||||
void * iter_arg)
|
||||
{
|
||||
int result;
|
||||
@ -650,8 +650,8 @@ igloo_avl_iterate_inorder_helper (avl_node * node,
|
||||
}
|
||||
|
||||
int
|
||||
igloo_avl_iterate_inorder (avl_tree * tree,
|
||||
avl_iter_fun_type iter_fun,
|
||||
igloo_avl_iterate_inorder (igloo_avl_tree * tree,
|
||||
igloo_avl_iter_fun_type iter_fun,
|
||||
void * iter_arg)
|
||||
{
|
||||
int result;
|
||||
@ -664,9 +664,9 @@ igloo_avl_iterate_inorder (avl_tree * tree,
|
||||
}
|
||||
}
|
||||
|
||||
avl_node *igloo_avl_get_first(avl_tree *tree)
|
||||
igloo_avl_node *igloo_avl_get_first(igloo_avl_tree *tree)
|
||||
{
|
||||
avl_node *node;
|
||||
igloo_avl_node *node;
|
||||
|
||||
node = tree->root->right;
|
||||
if (node == NULL || node->key == NULL) return NULL;
|
||||
@ -677,7 +677,7 @@ avl_node *igloo_avl_get_first(avl_tree *tree)
|
||||
return node;
|
||||
}
|
||||
|
||||
avl_node *igloo_avl_get_prev(avl_node *node)
|
||||
igloo_avl_node *igloo_avl_get_prev(igloo_avl_node *node)
|
||||
{
|
||||
if (node->left) {
|
||||
node = node->left;
|
||||
@ -687,7 +687,7 @@ avl_node *igloo_avl_get_prev(avl_node *node)
|
||||
|
||||
return node;
|
||||
} else {
|
||||
avl_node *child = node;
|
||||
igloo_avl_node *child = node;
|
||||
while (node->parent && node->parent->key) {
|
||||
node = node->parent;
|
||||
if (child == node->right) {
|
||||
@ -700,7 +700,7 @@ avl_node *igloo_avl_get_prev(avl_node *node)
|
||||
}
|
||||
}
|
||||
|
||||
avl_node *igloo_avl_get_next(avl_node *node)
|
||||
igloo_avl_node *igloo_avl_get_next(igloo_avl_node *node)
|
||||
{
|
||||
if (node->right) {
|
||||
node = node->right;
|
||||
@ -710,7 +710,7 @@ avl_node *igloo_avl_get_next(avl_node *node)
|
||||
|
||||
return node;
|
||||
} else {
|
||||
avl_node *child = node;
|
||||
igloo_avl_node *child = node;
|
||||
while (node->parent && node->parent->key) {
|
||||
node = node->parent;
|
||||
if (child == node->left) {
|
||||
@ -726,15 +726,15 @@ avl_node *igloo_avl_get_next(avl_node *node)
|
||||
/* iterate a function over a range of indices, using get_predecessor */
|
||||
|
||||
int
|
||||
igloo_avl_iterate_index_range (avl_tree * tree,
|
||||
avl_iter_index_fun_type iter_fun,
|
||||
igloo_avl_iterate_index_range (igloo_avl_tree * tree,
|
||||
igloo_avl_iter_index_fun_type iter_fun,
|
||||
unsigned long low,
|
||||
unsigned long high,
|
||||
void * iter_arg)
|
||||
{
|
||||
unsigned long m;
|
||||
unsigned long num_left;
|
||||
avl_node * node;
|
||||
igloo_avl_node * node;
|
||||
|
||||
if (high > tree->length) {
|
||||
return -1;
|
||||
@ -769,12 +769,12 @@ igloo_avl_iterate_index_range (avl_tree * tree,
|
||||
* representing the closest preceding value.
|
||||
*/
|
||||
|
||||
static avl_node *
|
||||
igloo_avl_get_index_by_key (avl_tree * tree,
|
||||
static igloo_avl_node *
|
||||
igloo_avl_get_index_by_key (igloo_avl_tree * tree,
|
||||
void * key,
|
||||
unsigned long * index)
|
||||
{
|
||||
avl_node * x = tree->root->right;
|
||||
igloo_avl_node * x = tree->root->right;
|
||||
unsigned long m;
|
||||
|
||||
if (!x) {
|
||||
@ -811,13 +811,13 @@ igloo_avl_get_index_by_key (avl_tree * tree,
|
||||
/* return the (low index, high index) pair that spans the given key */
|
||||
|
||||
int
|
||||
igloo_avl_get_span_by_key (avl_tree * tree,
|
||||
igloo_avl_get_span_by_key (igloo_avl_tree * tree,
|
||||
void * key,
|
||||
unsigned long * low,
|
||||
unsigned long * high)
|
||||
{
|
||||
unsigned long m, i, j;
|
||||
avl_node * node;
|
||||
igloo_avl_node * node;
|
||||
|
||||
node = igloo_avl_get_index_by_key (tree, key, &m);
|
||||
|
||||
@ -827,7 +827,7 @@ igloo_avl_get_span_by_key (avl_tree * tree,
|
||||
* the arrangement of like keys.
|
||||
*/
|
||||
if (node) {
|
||||
avl_node * left, * right;
|
||||
igloo_avl_node * left, * right;
|
||||
/* search left */
|
||||
left = igloo_avl_get_prev (node);
|
||||
i = m;
|
||||
@ -854,14 +854,14 @@ igloo_avl_get_span_by_key (avl_tree * tree,
|
||||
/* return the (low index, high index) pair that spans the given key */
|
||||
|
||||
int
|
||||
igloo_avl_get_span_by_two_keys (avl_tree * tree,
|
||||
igloo_avl_get_span_by_two_keys (igloo_avl_tree * tree,
|
||||
void * low_key,
|
||||
void * high_key,
|
||||
unsigned long * low,
|
||||
unsigned long * high)
|
||||
{
|
||||
unsigned long i, j;
|
||||
avl_node * low_node, * high_node;
|
||||
igloo_avl_node * low_node, * high_node;
|
||||
int order;
|
||||
|
||||
/* we may need to swap them */
|
||||
@ -876,7 +876,7 @@ igloo_avl_get_span_by_two_keys (avl_tree * tree,
|
||||
high_node = igloo_avl_get_index_by_key (tree, high_key, &j);
|
||||
|
||||
if (low_node) {
|
||||
avl_node * left;
|
||||
igloo_avl_node * left;
|
||||
/* search left */
|
||||
left = igloo_avl_get_prev (low_node);
|
||||
while (left && (i > 0) && (tree->compare_fun (tree->compare_arg, low_key, left->key) == 0)) {
|
||||
@ -887,7 +887,7 @@ igloo_avl_get_span_by_two_keys (avl_tree * tree,
|
||||
i = i + 1;
|
||||
}
|
||||
if (high_node) {
|
||||
avl_node * right;
|
||||
igloo_avl_node * right;
|
||||
/* search right */
|
||||
right = igloo_avl_get_next (high_node);
|
||||
while (right && (j <= tree->length) && (tree->compare_fun (tree->compare_arg, high_key, right->key) == 0)) {
|
||||
@ -905,11 +905,11 @@ igloo_avl_get_span_by_two_keys (avl_tree * tree,
|
||||
|
||||
|
||||
int
|
||||
igloo_avl_get_item_by_key_most (avl_tree * tree,
|
||||
igloo_avl_get_item_by_key_most (igloo_avl_tree * tree,
|
||||
void * key,
|
||||
void **value_address)
|
||||
{
|
||||
avl_node * x = tree->root->right;
|
||||
igloo_avl_node * x = tree->root->right;
|
||||
*value_address = NULL;
|
||||
|
||||
if (!x) {
|
||||
@ -949,11 +949,11 @@ igloo_avl_get_item_by_key_most (avl_tree * tree,
|
||||
}
|
||||
|
||||
int
|
||||
igloo_avl_get_item_by_key_least (avl_tree * tree,
|
||||
igloo_avl_get_item_by_key_least (igloo_avl_tree * tree,
|
||||
void * key,
|
||||
void **value_address)
|
||||
{
|
||||
avl_node * x = tree->root->right;
|
||||
igloo_avl_node * x = tree->root->right;
|
||||
*value_address = NULL;
|
||||
|
||||
if (!x) {
|
||||
@ -993,7 +993,7 @@ igloo_avl_get_item_by_key_least (avl_tree * tree,
|
||||
#define AVL_MAX(X, Y) ((X) > (Y) ? (X) : (Y))
|
||||
|
||||
static long
|
||||
igloo_avl_verify_balance (avl_node * node)
|
||||
igloo_avl_verify_balance (igloo_avl_node * node)
|
||||
{
|
||||
if (!node) {
|
||||
return 0;
|
||||
@ -1011,7 +1011,7 @@ igloo_avl_verify_balance (avl_node * node)
|
||||
}
|
||||
|
||||
static void
|
||||
igloo_avl_verify_parent (avl_node * node, avl_node * parent)
|
||||
igloo_avl_verify_parent (igloo_avl_node * node, igloo_avl_node * parent)
|
||||
{
|
||||
if (node->parent != parent) {
|
||||
return;
|
||||
@ -1025,7 +1025,7 @@ igloo_avl_verify_parent (avl_node * node, avl_node * parent)
|
||||
}
|
||||
|
||||
static long
|
||||
igloo_avl_verify_rank (avl_node * node)
|
||||
igloo_avl_verify_rank (igloo_avl_node * node)
|
||||
{
|
||||
if (!node) {
|
||||
return 0;
|
||||
@ -1048,7 +1048,7 @@ igloo_avl_verify_rank (avl_node * node)
|
||||
/* sanity-check the tree */
|
||||
|
||||
int
|
||||
igloo_avl_verify (avl_tree * tree)
|
||||
igloo_avl_verify (igloo_avl_tree * tree)
|
||||
{
|
||||
if (tree->length) {
|
||||
igloo_avl_verify_balance (tree->root->right);
|
||||
@ -1113,8 +1113,8 @@ igloo_print_connectors (link_node * link)
|
||||
*/
|
||||
|
||||
static void
|
||||
igloo_print_node (avl_key_printer_fun_type key_printer,
|
||||
avl_node * node,
|
||||
igloo_print_node (igloo_avl_key_printer_fun_type key_printer,
|
||||
igloo_avl_node * node,
|
||||
link_node * link)
|
||||
{
|
||||
char buffer[AVL_KEY_PRINTER_BUFLEN];
|
||||
@ -1148,7 +1148,7 @@ igloo_print_node (avl_key_printer_fun_type key_printer,
|
||||
}
|
||||
|
||||
void
|
||||
igloo_avl_print_tree (avl_tree * tree, avl_key_printer_fun_type key_printer)
|
||||
igloo_avl_print_tree (igloo_avl_tree * tree, igloo_avl_key_printer_fun_type key_printer)
|
||||
{
|
||||
link_node top = {NULL, 0, 0};
|
||||
if (!key_printer) {
|
||||
@ -1162,33 +1162,33 @@ igloo_avl_print_tree (avl_tree * tree, avl_key_printer_fun_type key_printer)
|
||||
}
|
||||
|
||||
|
||||
void igloo_avl_tree_rlock(avl_tree *tree)
|
||||
void igloo_avl_tree_rlock(igloo_avl_tree *tree)
|
||||
{
|
||||
thread_rwlock_rlock(&tree->rwlock);
|
||||
}
|
||||
|
||||
void igloo_avl_tree_wlock(avl_tree *tree)
|
||||
void igloo_avl_tree_wlock(igloo_avl_tree *tree)
|
||||
{
|
||||
thread_rwlock_wlock(&tree->rwlock);
|
||||
}
|
||||
|
||||
void igloo_avl_tree_unlock(avl_tree *tree)
|
||||
void igloo_avl_tree_unlock(igloo_avl_tree *tree)
|
||||
{
|
||||
thread_rwlock_unlock(&tree->rwlock);
|
||||
}
|
||||
|
||||
#ifdef HAVE_AVL_NODE_LOCK
|
||||
void avl_node_rlock(avl_node *node)
|
||||
void avl_node_rlock(igloo_avl_node *node)
|
||||
{
|
||||
thread_rwlock_rlock(&node->rwlock);
|
||||
}
|
||||
|
||||
void avl_node_wlock(avl_node *node)
|
||||
void avl_node_wlock(igloo_avl_node *node)
|
||||
{
|
||||
thread_rwlock_wlock(&node->rwlock);
|
||||
}
|
||||
|
||||
void avl_node_unlock(avl_node *node)
|
||||
void avl_node_unlock(igloo_avl_node *node)
|
||||
{
|
||||
thread_rwlock_unlock(&node->rwlock);
|
||||
}
|
||||
|
92
avl/avl.h
92
avl/avl.h
@ -24,11 +24,11 @@ extern "C" {
|
||||
#define thread_rwlock_unlock(x) do{}while(0)
|
||||
#endif
|
||||
|
||||
typedef struct avl_node_tag {
|
||||
typedef struct igloo_avl_node_tag {
|
||||
void * key;
|
||||
struct avl_node_tag * left;
|
||||
struct avl_node_tag * right;
|
||||
struct avl_node_tag * parent;
|
||||
struct igloo_avl_node_tag * left;
|
||||
struct igloo_avl_node_tag * right;
|
||||
struct igloo_avl_node_tag * parent;
|
||||
/*
|
||||
* The lower 2 bits of <rank_and_balance> specify the balance
|
||||
* factor: 00==-1, 01==0, 10==+1.
|
||||
@ -36,9 +36,9 @@ typedef struct avl_node_tag {
|
||||
*/
|
||||
unsigned int rank_and_balance;
|
||||
#if !defined(NO_THREAD) && defined(HAVE_AVL_NODE_LOCK)
|
||||
rwlock_t rwlock;
|
||||
igloo_rwlock_t rwlock;
|
||||
#endif
|
||||
} avl_node;
|
||||
} igloo_avl_node;
|
||||
|
||||
#define AVL_GET_BALANCE(n) ((int)(((n)->rank_and_balance & 3) - 1))
|
||||
|
||||
@ -52,124 +52,124 @@ typedef struct avl_node_tag {
|
||||
((n)->rank_and_balance) = \
|
||||
(((n)->rank_and_balance & 3) | (r << 2))
|
||||
|
||||
struct _avl_tree;
|
||||
struct igloo__avl_tree;
|
||||
|
||||
typedef int (*avl_key_compare_fun_type) (void * compare_arg, void * a, void * b);
|
||||
typedef int (*avl_iter_fun_type) (void * key, void * iter_arg);
|
||||
typedef int (*avl_iter_index_fun_type) (unsigned long index, void * key, void * iter_arg);
|
||||
typedef int (*avl_free_key_fun_type) (void * key);
|
||||
typedef int (*avl_key_printer_fun_type) (char *, void *);
|
||||
typedef int (*igloo_avl_key_compare_fun_type) (void * compare_arg, void * a, void * b);
|
||||
typedef int (*igloo_avl_iter_fun_type) (void * key, void * iter_arg);
|
||||
typedef int (*igloo_avl_iter_index_fun_type) (unsigned long index, void * key, void * iter_arg);
|
||||
typedef int (*igloo_avl_free_key_fun_type) (void * key);
|
||||
typedef int (*igloo_avl_key_printer_fun_type) (char *, void *);
|
||||
|
||||
/*
|
||||
* <compare_fun> and <compare_arg> let us associate a particular compare
|
||||
* function with each tree, separately.
|
||||
*/
|
||||
|
||||
typedef struct _avl_tree {
|
||||
avl_node * root;
|
||||
typedef struct igloo__avl_tree {
|
||||
igloo_avl_node * root;
|
||||
unsigned int height;
|
||||
unsigned int length;
|
||||
avl_key_compare_fun_type compare_fun;
|
||||
igloo_avl_key_compare_fun_type compare_fun;
|
||||
void * compare_arg;
|
||||
#ifndef NO_THREAD
|
||||
rwlock_t rwlock;
|
||||
igloo_rwlock_t rwlock;
|
||||
#endif
|
||||
} avl_tree;
|
||||
} igloo_avl_tree;
|
||||
|
||||
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);
|
||||
igloo_avl_tree * igloo_avl_tree_new (igloo_avl_key_compare_fun_type compare_fun, void * compare_arg);
|
||||
igloo_avl_node * igloo_avl_node_new (void * key, igloo_avl_node * parent);
|
||||
|
||||
void igloo_avl_tree_free (
|
||||
avl_tree * tree,
|
||||
avl_free_key_fun_type free_key_fun
|
||||
igloo_avl_tree * tree,
|
||||
igloo_avl_free_key_fun_type free_key_fun
|
||||
);
|
||||
|
||||
int igloo_avl_insert (
|
||||
avl_tree * ob,
|
||||
igloo_avl_tree * ob,
|
||||
void * key
|
||||
);
|
||||
|
||||
int igloo_avl_delete (
|
||||
avl_tree * tree,
|
||||
igloo_avl_tree * tree,
|
||||
void * key,
|
||||
avl_free_key_fun_type free_key_fun
|
||||
igloo_avl_free_key_fun_type free_key_fun
|
||||
);
|
||||
|
||||
int igloo_avl_get_by_index (
|
||||
avl_tree * tree,
|
||||
igloo_avl_tree * tree,
|
||||
unsigned long index,
|
||||
void ** value_address
|
||||
);
|
||||
|
||||
int igloo_avl_get_by_key (
|
||||
avl_tree * tree,
|
||||
igloo_avl_tree * tree,
|
||||
void * key,
|
||||
void ** value_address
|
||||
);
|
||||
|
||||
int igloo_avl_iterate_inorder (
|
||||
avl_tree * tree,
|
||||
avl_iter_fun_type iter_fun,
|
||||
igloo_avl_tree * tree,
|
||||
igloo_avl_iter_fun_type iter_fun,
|
||||
void * iter_arg
|
||||
);
|
||||
|
||||
int igloo_avl_iterate_index_range (
|
||||
avl_tree * tree,
|
||||
avl_iter_index_fun_type iter_fun,
|
||||
igloo_avl_tree * tree,
|
||||
igloo_avl_iter_index_fun_type iter_fun,
|
||||
unsigned long low,
|
||||
unsigned long high,
|
||||
void * iter_arg
|
||||
);
|
||||
|
||||
int igloo_avl_get_span_by_key (
|
||||
avl_tree * tree,
|
||||
igloo_avl_tree * tree,
|
||||
void * key,
|
||||
unsigned long * low,
|
||||
unsigned long * high
|
||||
);
|
||||
|
||||
int igloo_avl_get_span_by_two_keys (
|
||||
avl_tree * tree,
|
||||
igloo_avl_tree * tree,
|
||||
void * key_a,
|
||||
void * key_b,
|
||||
unsigned long * low,
|
||||
unsigned long * high
|
||||
);
|
||||
|
||||
int igloo_avl_verify (avl_tree * tree);
|
||||
int igloo_avl_verify (igloo_avl_tree * tree);
|
||||
|
||||
void igloo_avl_print_tree (
|
||||
avl_tree * tree,
|
||||
avl_key_printer_fun_type key_printer
|
||||
igloo_avl_tree * tree,
|
||||
igloo_avl_key_printer_fun_type key_printer
|
||||
);
|
||||
|
||||
avl_node *igloo_avl_get_first(avl_tree *tree);
|
||||
igloo_avl_node *igloo_avl_get_first(igloo_avl_tree *tree);
|
||||
|
||||
avl_node *igloo_avl_get_prev(avl_node * node);
|
||||
igloo_avl_node *igloo_avl_get_prev(igloo_avl_node * node);
|
||||
|
||||
avl_node *igloo_avl_get_next(avl_node * node);
|
||||
igloo_avl_node *igloo_avl_get_next(igloo_avl_node * node);
|
||||
|
||||
/* These two are from David Ascher <david_ascher@brown.edu> */
|
||||
|
||||
int igloo_avl_get_item_by_key_most (
|
||||
avl_tree * tree,
|
||||
igloo_avl_tree * tree,
|
||||
void * key,
|
||||
void ** value_address
|
||||
);
|
||||
|
||||
int igloo_avl_get_item_by_key_least (
|
||||
avl_tree * tree,
|
||||
igloo_avl_tree * tree,
|
||||
void * key,
|
||||
void ** value_address
|
||||
);
|
||||
|
||||
/* optional locking stuff */
|
||||
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);
|
||||
void igloo_avl_tree_rlock(igloo_avl_tree *tree);
|
||||
void igloo_avl_tree_wlock(igloo_avl_tree *tree);
|
||||
void igloo_avl_tree_unlock(igloo_avl_tree *tree);
|
||||
void avl_node_rlock(igloo_avl_node *node);
|
||||
void avl_node_wlock(igloo_avl_node *node);
|
||||
void avl_node_unlock(igloo_avl_node *node);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -12,8 +12,8 @@ int _printer(char *buff, void *key);
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int i, max_nodes;
|
||||
avl_tree *tree;
|
||||
avl_node *node;
|
||||
igloo_avl_tree *tree;
|
||||
igloo_avl_node *node;
|
||||
|
||||
max_nodes = 25;
|
||||
|
||||
|
@ -34,11 +34,11 @@
|
||||
|
||||
#include "encoding.h"
|
||||
|
||||
struct httpp_encoding_tag {
|
||||
struct igloo_httpp_encoding_tag {
|
||||
size_t refc;
|
||||
|
||||
ssize_t (*process_read)(httpp_encoding_t *self, void *buf, size_t len, ssize_t (*cb)(void*, void*, size_t), void *userdata);
|
||||
ssize_t (*process_write)(httpp_encoding_t *self, const void *buf, size_t len, ssize_t (*cb)(void*, const void*, size_t), void *userdata);
|
||||
ssize_t (*process_read)(igloo_httpp_encoding_t *self, void *buf, size_t len, ssize_t (*cb)(void*, void*, size_t), void *userdata);
|
||||
ssize_t (*process_write)(igloo_httpp_encoding_t *self, const void *buf, size_t len, ssize_t (*cb)(void*, const void*, size_t), void *userdata);
|
||||
|
||||
httpp_meta_t *meta_read;
|
||||
httpp_meta_t *meta_write;
|
||||
@ -62,10 +62,10 @@ struct httpp_encoding_tag {
|
||||
|
||||
|
||||
/* Handlers, at end of file */
|
||||
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);
|
||||
static ssize_t igloo___enc_identity_read(igloo_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(igloo_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(igloo_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(igloo_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 igloo___copy_buffer(void *dst, void **src, size_t *boffset, size_t *blen, size_t len)
|
||||
@ -100,7 +100,7 @@ ssize_t igloo___copy_buffer(void *dst, void **src, size_t *boffset, size_t *blen
|
||||
}
|
||||
|
||||
/* try to flush output buffers */
|
||||
static inline void __flush_output(httpp_encoding_t *self, ssize_t (*cb)(void*, const void*, size_t), void *userdata)
|
||||
static inline void __flush_output(igloo_httpp_encoding_t *self, ssize_t (*cb)(void*, const void*, size_t), void *userdata)
|
||||
{
|
||||
if (cb && self->buf_write_encoded) {
|
||||
ssize_t ret = cb(userdata,
|
||||
@ -177,18 +177,18 @@ int igloo_httpp_encoding_meta_append(httpp_meta_t **dst, httpp_met
|
||||
}
|
||||
|
||||
/* General setup */
|
||||
httpp_encoding_t *igloo_httpp_encoding_new(const char *encoding) {
|
||||
httpp_encoding_t *ret = calloc(1, sizeof(httpp_encoding_t));
|
||||
igloo_httpp_encoding_t *igloo_httpp_encoding_new(const char *encoding) {
|
||||
igloo_httpp_encoding_t *ret = calloc(1, sizeof(igloo_httpp_encoding_t));
|
||||
if (!ret)
|
||||
return NULL;
|
||||
|
||||
ret->refc = 1;
|
||||
ret->bytes_till_eof = -1;
|
||||
|
||||
if (strcasecmp(encoding, HTTPP_ENCODING_IDENTITY) == 0) {
|
||||
if (strcasecmp(encoding, igloo_HTTPP_ENCODING_IDENTITY) == 0) {
|
||||
ret->process_read = igloo___enc_identity_read;
|
||||
ret->process_write = igloo___enc_identity_write;
|
||||
} else if (strcasecmp(encoding, HTTPP_ENCODING_CHUNKED) == 0) {
|
||||
} else if (strcasecmp(encoding, igloo_HTTPP_ENCODING_CHUNKED) == 0) {
|
||||
ret->process_read = igloo___enc_chunked_read;
|
||||
ret->process_write = igloo___enc_chunked_write;
|
||||
} else {
|
||||
@ -202,7 +202,7 @@ fail:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int igloo_httpp_encoding_addref(httpp_encoding_t *self)
|
||||
int igloo_httpp_encoding_addref(igloo_httpp_encoding_t *self)
|
||||
{
|
||||
if (!self)
|
||||
return -1;
|
||||
@ -210,7 +210,7 @@ int igloo_httpp_encoding_addref(httpp_encoding_t *self)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int igloo_httpp_encoding_release(httpp_encoding_t *self)
|
||||
int igloo_httpp_encoding_release(igloo_httpp_encoding_t *self)
|
||||
{
|
||||
if (!self)
|
||||
return -1;
|
||||
@ -237,7 +237,7 @@ 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 igloo_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(igloo_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;
|
||||
@ -281,7 +281,7 @@ ssize_t igloo_httpp_encoding_read(httpp_encoding_t *self, void *buf, s
|
||||
return done;
|
||||
}
|
||||
|
||||
int igloo_httpp_encoding_eof(httpp_encoding_t *self, int (*cb)(void*), void *userdata)
|
||||
int igloo_httpp_encoding_eof(igloo_httpp_encoding_t *self, int (*cb)(void*), void *userdata)
|
||||
{
|
||||
if (!self)
|
||||
return -1;
|
||||
@ -302,7 +302,7 @@ int igloo_httpp_encoding_eof(httpp_encoding_t *self, int (*cb)(voi
|
||||
* 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 *igloo_httpp_encoding_get_meta(httpp_encoding_t *self)
|
||||
httpp_meta_t *igloo_httpp_encoding_get_meta(igloo_httpp_encoding_t *self)
|
||||
{
|
||||
httpp_meta_t *ret;
|
||||
|
||||
@ -319,7 +319,7 @@ httpp_meta_t *igloo_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 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 igloo_httpp_encoding_write(igloo_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 igloo_httpp_encoding_write(httpp_encoding_t *self, const void
|
||||
}
|
||||
|
||||
/* Check if we have something to flush. */
|
||||
ssize_t igloo_httpp_encoding_pending(httpp_encoding_t *self)
|
||||
ssize_t igloo_httpp_encoding_pending(igloo_httpp_encoding_t *self)
|
||||
{
|
||||
if (!self)
|
||||
return -1;
|
||||
@ -351,7 +351,7 @@ 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 igloo_httpp_encoding_append_meta(httpp_encoding_t *self, httpp_meta_t *meta)
|
||||
int igloo_httpp_encoding_append_meta(igloo_httpp_encoding_t *self, httpp_meta_t *meta)
|
||||
{
|
||||
if (!self)
|
||||
return -1;
|
||||
@ -359,7 +359,7 @@ int igloo_httpp_encoding_append_meta(httpp_encoding_t *self, httpp
|
||||
}
|
||||
|
||||
/* handlers for encodings */
|
||||
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_read(igloo_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 igloo___enc_identity_read(httpp_encoding_t *self, void *buf, size
|
||||
return cb(userdata, buf, len);
|
||||
}
|
||||
|
||||
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_identity_write(igloo_httpp_encoding_t *self, const void *buf, size_t len, ssize_t (*cb)(void*, const void*, size_t), void *userdata)
|
||||
{
|
||||
(void)self;
|
||||
if (!cb)
|
||||
@ -388,7 +388,7 @@ static ssize_t igloo___enc_identity_write(httpp_encoding_t *self, const void *bu
|
||||
*
|
||||
*/
|
||||
|
||||
static void __enc_chunked_read_extentions(httpp_encoding_t *self, char *p, size_t len)
|
||||
static void __enc_chunked_read_extentions(igloo_httpp_encoding_t *self, char *p, size_t len)
|
||||
{
|
||||
/* ok. If you want to ruin your day... go ahead and try to understand this. */
|
||||
httpp_meta_t **parent;
|
||||
@ -482,7 +482,7 @@ static void __enc_chunked_read_extentions(httpp_encoding_t *self, char *p, size_
|
||||
}
|
||||
}
|
||||
|
||||
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_read(igloo_httpp_encoding_t *self, void *buf, size_t len, ssize_t (*cb)(void*, void*, size_t), void *userdata)
|
||||
{
|
||||
ssize_t ret;
|
||||
size_t buflen;
|
||||
@ -718,7 +718,7 @@ static size_t __enc_chunked_write_extensions_valuelen(httpp_meta_t *cur)
|
||||
return ret;
|
||||
}
|
||||
|
||||
static char *__enc_chunked_write_extensions(httpp_encoding_t *self)
|
||||
static char *__enc_chunked_write_extensions(igloo_httpp_encoding_t *self)
|
||||
{
|
||||
size_t buflen;
|
||||
void *buf;
|
||||
@ -785,7 +785,7 @@ static char *__enc_chunked_write_extensions(httpp_encoding_t *self)
|
||||
|
||||
return buf;
|
||||
}
|
||||
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)
|
||||
static ssize_t igloo___enc_chunked_write(igloo_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;
|
||||
|
@ -28,13 +28,13 @@
|
||||
#include <sys/types.h>
|
||||
|
||||
/* known encodings */
|
||||
#define HTTPP_ENCODING_IDENTITY "identity" /* RFC2616 */
|
||||
#define HTTPP_ENCODING_CHUNKED "chunked" /* RFC2616 */
|
||||
#define HTTPP_ENCODING_GZIP "gzip" /* RFC1952 */
|
||||
#define HTTPP_ENCODING_COMPRESS "compress" /* ??? */
|
||||
#define HTTPP_ENCODING_DEFLATE "deflate" /* RFC1950, RFC1951 */
|
||||
#define igloo_HTTPP_ENCODING_IDENTITY "identity" /* RFC2616 */
|
||||
#define igloo_HTTPP_ENCODING_CHUNKED "chunked" /* RFC2616 */
|
||||
#define igloo_HTTPP_ENCODING_GZIP "gzip" /* RFC1952 */
|
||||
#define igloo_HTTPP_ENCODING_COMPRESS "compress" /* ??? */
|
||||
#define igloo_HTTPP_ENCODING_DEFLATE "deflate" /* RFC1950, RFC1951 */
|
||||
|
||||
typedef struct httpp_encoding_tag httpp_encoding_t;
|
||||
typedef struct igloo_httpp_encoding_tag igloo_httpp_encoding_t;
|
||||
|
||||
typedef struct httpp_meta_tag httpp_meta_t;
|
||||
struct httpp_meta_tag {
|
||||
@ -51,39 +51,39 @@ 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 *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);
|
||||
igloo_httpp_encoding_t *igloo_httpp_encoding_new(const char *encoding);
|
||||
int igloo_httpp_encoding_addref(igloo_httpp_encoding_t *self);
|
||||
int igloo_httpp_encoding_release(igloo_httpp_encoding_t *self);
|
||||
|
||||
/* Read data from backend.
|
||||
* if cb is NULL this will read from the internal buffer.
|
||||
*/
|
||||
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 igloo_httpp_encoding_read(igloo_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 igloo_httpp_encoding_eof(httpp_encoding_t *self, int (*cb)(void*), void *userdata);
|
||||
int igloo_httpp_encoding_eof(igloo_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 *igloo_httpp_encoding_get_meta(httpp_encoding_t *self);
|
||||
httpp_meta_t *igloo_httpp_encoding_get_meta(igloo_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 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 igloo_httpp_encoding_write(igloo_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 igloo_httpp_encoding_pending(httpp_encoding_t *self);
|
||||
ssize_t igloo_httpp_encoding_pending(igloo_httpp_encoding_t *self);
|
||||
|
||||
/* Attach meta data to the stream.
|
||||
* this is to be written out as soon as the encoding supports.
|
||||
*/
|
||||
int igloo_httpp_encoding_append_meta(httpp_encoding_t *self, httpp_meta_t *meta);
|
||||
int igloo_httpp_encoding_append_meta(igloo_httpp_encoding_t *self, httpp_meta_t *meta);
|
||||
|
||||
#endif
|
||||
|
184
httpp/httpp.c
184
httpp/httpp.c
@ -53,72 +53,72 @@ 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 *igloo__httpp_get_param_var(avl_tree *tree, const char *name);
|
||||
static void parse_query(igloo_avl_tree *tree, const char *query, size_t len);
|
||||
static const char *_httpp_get_param(igloo_avl_tree *tree, const char *name);
|
||||
static void _httpp_set_param_nocopy(igloo_avl_tree *tree, char *name, char *value, int replace);
|
||||
static void _httpp_set_param(igloo_avl_tree *tree, const char *name, const char *value);
|
||||
static igloo_http_var_t *igloo__httpp_get_param_var(igloo_avl_tree *tree, const char *name);
|
||||
|
||||
httpp_request_info_t igloo_httpp_request_info(httpp_request_type_e req)
|
||||
igloo_httpp_request_info_t igloo_httpp_request_info(igloo_httpp_request_type_e req)
|
||||
{
|
||||
#if 0
|
||||
#define HTTPP_REQUEST_IS_SAFE ((httpp_request_info_t)0x0001U)
|
||||
#define HTTPP_REQUEST_IS_IDEMPOTENT ((httpp_request_info_t)0x0002U)
|
||||
#define HTTPP_REQUEST_IS_CACHEABLE ((httpp_request_info_t)0x0004U)
|
||||
#define HTTPP_REQUEST_HAS_RESPONSE_BODY ((httpp_request_info_t)0x0010U)
|
||||
#define HTTPP_REQUEST_HAS_REQUEST_BODY ((httpp_request_info_t)0x0100U)
|
||||
#define HTTPP_REQUEST_HAS_OPTIONAL_REQUEST_BODY ((httpp_request_info_t)0x0200U)
|
||||
#define igloo_HTTPP_REQUEST_IS_SAFE ((igloo_httpp_request_info_t)0x0001U)
|
||||
#define igloo_HTTPP_REQUEST_IS_IDEMPOTENT ((igloo_httpp_request_info_t)0x0002U)
|
||||
#define igloo_HTTPP_REQUEST_IS_CACHEABLE ((igloo_httpp_request_info_t)0x0004U)
|
||||
#define igloo_HTTPP_REQUEST_HAS_RESPONSE_BODY ((igloo_httpp_request_info_t)0x0010U)
|
||||
#define igloo_HTTPP_REQUEST_HAS_REQUEST_BODY ((igloo_httpp_request_info_t)0x0100U)
|
||||
#define igloo_HTTPP_REQUEST_HAS_OPTIONAL_REQUEST_BODY ((igloo_httpp_request_info_t)0x0200U)
|
||||
#endif
|
||||
switch (req) {
|
||||
/* offical methods */
|
||||
case httpp_req_get:
|
||||
return HTTPP_REQUEST_IS_SAFE|HTTPP_REQUEST_IS_IDEMPOTENT|HTTPP_REQUEST_IS_CACHEABLE|HTTPP_REQUEST_HAS_RESPONSE_BODY|HTTPP_REQUEST_HAS_OPTIONAL_REQUEST_BODY;
|
||||
return igloo_HTTPP_REQUEST_IS_SAFE|igloo_HTTPP_REQUEST_IS_IDEMPOTENT|igloo_HTTPP_REQUEST_IS_CACHEABLE|igloo_HTTPP_REQUEST_HAS_RESPONSE_BODY|igloo_HTTPP_REQUEST_HAS_OPTIONAL_REQUEST_BODY;
|
||||
break;
|
||||
case httpp_req_post:
|
||||
return HTTPP_REQUEST_IS_CACHEABLE|HTTPP_REQUEST_HAS_RESPONSE_BODY|HTTPP_REQUEST_HAS_REQUEST_BODY;
|
||||
return igloo_HTTPP_REQUEST_IS_CACHEABLE|igloo_HTTPP_REQUEST_HAS_RESPONSE_BODY|igloo_HTTPP_REQUEST_HAS_REQUEST_BODY;
|
||||
break;
|
||||
case httpp_req_put:
|
||||
return HTTPP_REQUEST_IS_IDEMPOTENT|HTTPP_REQUEST_HAS_RESPONSE_BODY|HTTPP_REQUEST_HAS_REQUEST_BODY;
|
||||
return igloo_HTTPP_REQUEST_IS_IDEMPOTENT|igloo_HTTPP_REQUEST_HAS_RESPONSE_BODY|igloo_HTTPP_REQUEST_HAS_REQUEST_BODY;
|
||||
break;
|
||||
case httpp_req_head:
|
||||
return HTTPP_REQUEST_IS_SAFE|HTTPP_REQUEST_IS_IDEMPOTENT|HTTPP_REQUEST_IS_CACHEABLE;
|
||||
return igloo_HTTPP_REQUEST_IS_SAFE|igloo_HTTPP_REQUEST_IS_IDEMPOTENT|igloo_HTTPP_REQUEST_IS_CACHEABLE;
|
||||
break;
|
||||
case httpp_req_options:
|
||||
return HTTPP_REQUEST_IS_SAFE|HTTPP_REQUEST_IS_IDEMPOTENT|HTTPP_REQUEST_HAS_RESPONSE_BODY|HTTPP_REQUEST_HAS_OPTIONAL_REQUEST_BODY;
|
||||
return igloo_HTTPP_REQUEST_IS_SAFE|igloo_HTTPP_REQUEST_IS_IDEMPOTENT|igloo_HTTPP_REQUEST_HAS_RESPONSE_BODY|igloo_HTTPP_REQUEST_HAS_OPTIONAL_REQUEST_BODY;
|
||||
break;
|
||||
case httpp_req_delete:
|
||||
return HTTPP_REQUEST_IS_IDEMPOTENT|HTTPP_REQUEST_HAS_RESPONSE_BODY;
|
||||
return igloo_HTTPP_REQUEST_IS_IDEMPOTENT|igloo_HTTPP_REQUEST_HAS_RESPONSE_BODY;
|
||||
break;
|
||||
case httpp_req_trace:
|
||||
return HTTPP_REQUEST_IS_SAFE|HTTPP_REQUEST_IS_IDEMPOTENT|HTTPP_REQUEST_HAS_RESPONSE_BODY;
|
||||
return igloo_HTTPP_REQUEST_IS_SAFE|igloo_HTTPP_REQUEST_IS_IDEMPOTENT|igloo_HTTPP_REQUEST_HAS_RESPONSE_BODY;
|
||||
break;
|
||||
case httpp_req_connect:
|
||||
return HTTPP_REQUEST_HAS_RESPONSE_BODY|HTTPP_REQUEST_HAS_REQUEST_BODY;
|
||||
return igloo_HTTPP_REQUEST_HAS_RESPONSE_BODY|igloo_HTTPP_REQUEST_HAS_REQUEST_BODY;
|
||||
break;
|
||||
|
||||
/* Icecast specific methods */
|
||||
case httpp_req_source:
|
||||
return HTTPP_REQUEST_HAS_RESPONSE_BODY|HTTPP_REQUEST_HAS_REQUEST_BODY;
|
||||
return igloo_HTTPP_REQUEST_HAS_RESPONSE_BODY|igloo_HTTPP_REQUEST_HAS_REQUEST_BODY;
|
||||
break;
|
||||
case httpp_req_play:
|
||||
return HTTPP_REQUEST_IS_SAFE|HTTPP_REQUEST_HAS_RESPONSE_BODY|HTTPP_REQUEST_HAS_OPTIONAL_REQUEST_BODY;
|
||||
return igloo_HTTPP_REQUEST_IS_SAFE|igloo_HTTPP_REQUEST_HAS_RESPONSE_BODY|igloo_HTTPP_REQUEST_HAS_OPTIONAL_REQUEST_BODY;
|
||||
break;
|
||||
case httpp_req_stats:
|
||||
return HTTPP_REQUEST_IS_SAFE|HTTPP_REQUEST_HAS_RESPONSE_BODY|HTTPP_REQUEST_HAS_OPTIONAL_REQUEST_BODY;
|
||||
return igloo_HTTPP_REQUEST_IS_SAFE|igloo_HTTPP_REQUEST_HAS_RESPONSE_BODY|igloo_HTTPP_REQUEST_HAS_OPTIONAL_REQUEST_BODY;
|
||||
break;
|
||||
|
||||
/* Virtual and other methods */
|
||||
case httpp_req_none:
|
||||
case httpp_req_unknown:
|
||||
default:
|
||||
return HTTPP_REQUEST_HAS_RESPONSE_BODY|HTTPP_REQUEST_HAS_OPTIONAL_REQUEST_BODY;
|
||||
return igloo_HTTPP_REQUEST_HAS_RESPONSE_BODY|igloo_HTTPP_REQUEST_HAS_OPTIONAL_REQUEST_BODY;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
http_parser_t *igloo_httpp_create_parser(void)
|
||||
igloo_http_parser_t *igloo_httpp_create_parser(void)
|
||||
{
|
||||
http_parser_t *parser = calloc(1, sizeof(http_parser_t));
|
||||
igloo_http_parser_t *parser = calloc(1, sizeof(igloo_http_parser_t));
|
||||
|
||||
parser->refc = 1;
|
||||
parser->req_type = httpp_req_none;
|
||||
@ -130,9 +130,9 @@ http_parser_t *igloo_httpp_create_parser(void)
|
||||
return parser;
|
||||
}
|
||||
|
||||
void igloo_httpp_initialize(http_parser_t *parser, http_varlist_t *defaults)
|
||||
void igloo_httpp_initialize(igloo_http_parser_t *parser, igloo_http_varlist_t *defaults)
|
||||
{
|
||||
http_varlist_t *list;
|
||||
igloo_http_varlist_t *list;
|
||||
|
||||
/* now insert the default variables */
|
||||
list = defaults;
|
||||
@ -177,7 +177,7 @@ static int igloo_split_headers(char *data, unsigned long len, char **line)
|
||||
return lines;
|
||||
}
|
||||
|
||||
static void igloo_parse_headers(http_parser_t *parser, char **line, int lines)
|
||||
static void igloo_parse_headers(igloo_http_parser_t *parser, char **line, int lines)
|
||||
{
|
||||
int i, l;
|
||||
int whitespace, slen;
|
||||
@ -216,7 +216,7 @@ static void igloo_parse_headers(http_parser_t *parser, char **line, int lines)
|
||||
}
|
||||
}
|
||||
|
||||
int igloo_httpp_parse_response(http_parser_t *parser, const char *http_data, unsigned long len, const char *uri)
|
||||
int igloo_httpp_parse_response(igloo_http_parser_t *parser, const char *http_data, unsigned long len, const char *uri)
|
||||
{
|
||||
char *data;
|
||||
char *line[MAX_HEADERS];
|
||||
@ -260,14 +260,14 @@ int igloo_httpp_parse_response(http_parser_t *parser, const char *http_data, uns
|
||||
return 0;
|
||||
}
|
||||
|
||||
igloo_httpp_setvar(parser, HTTPP_VAR_ERROR_CODE, resp_code);
|
||||
igloo_httpp_setvar(parser, igloo_HTTPP_VAR_ERROR_CODE, resp_code);
|
||||
code = atoi(resp_code);
|
||||
if(code < 200 || code >= 300) {
|
||||
igloo_httpp_setvar(parser, HTTPP_VAR_ERROR_MESSAGE, message);
|
||||
igloo_httpp_setvar(parser, igloo_HTTPP_VAR_ERROR_MESSAGE, message);
|
||||
}
|
||||
|
||||
igloo_httpp_setvar(parser, HTTPP_VAR_URI, uri);
|
||||
igloo_httpp_setvar(parser, HTTPP_VAR_REQ_TYPE, "NONE");
|
||||
igloo_httpp_setvar(parser, igloo_HTTPP_VAR_URI, uri);
|
||||
igloo_httpp_setvar(parser, igloo_HTTPP_VAR_REQ_TYPE, "NONE");
|
||||
|
||||
igloo_parse_headers(parser, line, lines);
|
||||
|
||||
@ -276,7 +276,7 @@ int igloo_httpp_parse_response(http_parser_t *parser, const char *http_data, uns
|
||||
return 1;
|
||||
}
|
||||
|
||||
int igloo_httpp_parse_postdata(http_parser_t *parser, const char *body_data, size_t len)
|
||||
int igloo_httpp_parse_postdata(igloo_http_parser_t *parser, const char *body_data, size_t len)
|
||||
{
|
||||
const char *header = igloo_httpp_getvar(parser, "content-type");
|
||||
|
||||
@ -350,7 +350,7 @@ static char *igloo_url_unescape(const char *src, size_t len)
|
||||
return (char *)decoded;
|
||||
}
|
||||
|
||||
static void parse_query_element(avl_tree *tree, const char *start, const char *mid, const char *end)
|
||||
static void parse_query_element(igloo_avl_tree *tree, const char *start, const char *mid, const char *end)
|
||||
{
|
||||
size_t keylen;
|
||||
char *key;
|
||||
@ -379,7 +379,7 @@ static void parse_query_element(avl_tree *tree, const char *start, const char *m
|
||||
_httpp_set_param_nocopy(tree, key, value, 0);
|
||||
}
|
||||
|
||||
static void parse_query(avl_tree *tree, const char *query, size_t len)
|
||||
static void parse_query(igloo_avl_tree *tree, const char *query, size_t len)
|
||||
{
|
||||
const char *start = query;
|
||||
const char *mid = NULL;
|
||||
@ -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 igloo_httpp_parse(http_parser_t *parser, const char *http_data, unsigned long len)
|
||||
int igloo_httpp_parse(igloo_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 */
|
||||
@ -467,8 +467,8 @@ int igloo_httpp_parse(http_parser_t *parser, const char *http_data, unsigned lon
|
||||
if (uri != NULL && strlen(uri) > 0) {
|
||||
char *query;
|
||||
if((query = strchr(uri, '?')) != NULL) {
|
||||
igloo_httpp_setvar(parser, HTTPP_VAR_RAWURI, uri);
|
||||
igloo_httpp_setvar(parser, HTTPP_VAR_QUERYARGS, query);
|
||||
igloo_httpp_setvar(parser, igloo_HTTPP_VAR_RAWURI, uri);
|
||||
igloo_httpp_setvar(parser, igloo_HTTPP_VAR_QUERYARGS, query);
|
||||
*query = 0;
|
||||
query++;
|
||||
parse_query(parser->queryvars, query, strlen(query));
|
||||
@ -483,8 +483,8 @@ int igloo_httpp_parse(http_parser_t *parser, const char *http_data, unsigned lon
|
||||
if ((version != NULL) && ((tmp = strchr(version, '/')) != NULL)) {
|
||||
tmp[0] = '\0';
|
||||
if ((strlen(version) > 0) && (strlen(&tmp[1]) > 0)) {
|
||||
igloo_httpp_setvar(parser, HTTPP_VAR_PROTOCOL, version);
|
||||
igloo_httpp_setvar(parser, HTTPP_VAR_VERSION, &tmp[1]);
|
||||
igloo_httpp_setvar(parser, igloo_HTTPP_VAR_PROTOCOL, version);
|
||||
igloo_httpp_setvar(parser, igloo_HTTPP_VAR_VERSION, &tmp[1]);
|
||||
} else {
|
||||
free(data);
|
||||
return 0;
|
||||
@ -497,37 +497,37 @@ int igloo_httpp_parse(http_parser_t *parser, const char *http_data, unsigned lon
|
||||
if (parser->req_type != httpp_req_none && parser->req_type != httpp_req_unknown) {
|
||||
switch (parser->req_type) {
|
||||
case httpp_req_get:
|
||||
igloo_httpp_setvar(parser, HTTPP_VAR_REQ_TYPE, "GET");
|
||||
igloo_httpp_setvar(parser, igloo_HTTPP_VAR_REQ_TYPE, "GET");
|
||||
break;
|
||||
case httpp_req_post:
|
||||
igloo_httpp_setvar(parser, HTTPP_VAR_REQ_TYPE, "POST");
|
||||
igloo_httpp_setvar(parser, igloo_HTTPP_VAR_REQ_TYPE, "POST");
|
||||
break;
|
||||
case httpp_req_put:
|
||||
igloo_httpp_setvar(parser, HTTPP_VAR_REQ_TYPE, "PUT");
|
||||
igloo_httpp_setvar(parser, igloo_HTTPP_VAR_REQ_TYPE, "PUT");
|
||||
break;
|
||||
case httpp_req_head:
|
||||
igloo_httpp_setvar(parser, HTTPP_VAR_REQ_TYPE, "HEAD");
|
||||
igloo_httpp_setvar(parser, igloo_HTTPP_VAR_REQ_TYPE, "HEAD");
|
||||
break;
|
||||
case httpp_req_options:
|
||||
igloo_httpp_setvar(parser, HTTPP_VAR_REQ_TYPE, "OPTIONS");
|
||||
igloo_httpp_setvar(parser, igloo_HTTPP_VAR_REQ_TYPE, "OPTIONS");
|
||||
break;
|
||||
case httpp_req_delete:
|
||||
igloo_httpp_setvar(parser, HTTPP_VAR_REQ_TYPE, "DELETE");
|
||||
igloo_httpp_setvar(parser, igloo_HTTPP_VAR_REQ_TYPE, "DELETE");
|
||||
break;
|
||||
case httpp_req_trace:
|
||||
igloo_httpp_setvar(parser, HTTPP_VAR_REQ_TYPE, "TRACE");
|
||||
igloo_httpp_setvar(parser, igloo_HTTPP_VAR_REQ_TYPE, "TRACE");
|
||||
break;
|
||||
case httpp_req_connect:
|
||||
igloo_httpp_setvar(parser, HTTPP_VAR_REQ_TYPE, "CONNECT");
|
||||
igloo_httpp_setvar(parser, igloo_HTTPP_VAR_REQ_TYPE, "CONNECT");
|
||||
break;
|
||||
case httpp_req_source:
|
||||
igloo_httpp_setvar(parser, HTTPP_VAR_REQ_TYPE, "SOURCE");
|
||||
igloo_httpp_setvar(parser, igloo_HTTPP_VAR_REQ_TYPE, "SOURCE");
|
||||
break;
|
||||
case httpp_req_play:
|
||||
igloo_httpp_setvar(parser, HTTPP_VAR_REQ_TYPE, "PLAY");
|
||||
igloo_httpp_setvar(parser, igloo_HTTPP_VAR_REQ_TYPE, "PLAY");
|
||||
break;
|
||||
case httpp_req_stats:
|
||||
igloo_httpp_setvar(parser, HTTPP_VAR_REQ_TYPE, "STATS");
|
||||
igloo_httpp_setvar(parser, igloo_HTTPP_VAR_REQ_TYPE, "STATS");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -538,7 +538,7 @@ int igloo_httpp_parse(http_parser_t *parser, const char *http_data, unsigned lon
|
||||
}
|
||||
|
||||
if (parser->uri != NULL) {
|
||||
igloo_httpp_setvar(parser, HTTPP_VAR_URI, parser->uri);
|
||||
igloo_httpp_setvar(parser, igloo_HTTPP_VAR_URI, parser->uri);
|
||||
} else {
|
||||
free(data);
|
||||
return 0;
|
||||
@ -551,9 +551,9 @@ int igloo_httpp_parse(http_parser_t *parser, const char *http_data, unsigned lon
|
||||
return 1;
|
||||
}
|
||||
|
||||
void igloo_httpp_deletevar(http_parser_t *parser, const char *name)
|
||||
void igloo_httpp_deletevar(igloo_http_parser_t *parser, const char *name)
|
||||
{
|
||||
http_var_t var;
|
||||
igloo_http_var_t var;
|
||||
|
||||
if (parser == NULL || name == NULL)
|
||||
return;
|
||||
@ -564,14 +564,14 @@ void igloo_httpp_deletevar(http_parser_t *parser, const char *name)
|
||||
igloo_avl_delete(parser->vars, (void *)&var, igloo__free_vars);
|
||||
}
|
||||
|
||||
void igloo_httpp_setvar(http_parser_t *parser, const char *name, const char *value)
|
||||
void igloo_httpp_setvar(igloo_http_parser_t *parser, const char *name, const char *value)
|
||||
{
|
||||
http_var_t *var;
|
||||
igloo_http_var_t *var;
|
||||
|
||||
if (name == NULL || value == NULL)
|
||||
return;
|
||||
|
||||
var = (http_var_t *)calloc(1, sizeof(http_var_t));
|
||||
var = (igloo_http_var_t *)calloc(1, sizeof(igloo_http_var_t));
|
||||
if (var == NULL) return;
|
||||
|
||||
var->value = calloc(1, sizeof(*var->value));
|
||||
@ -592,10 +592,10 @@ void igloo_httpp_setvar(http_parser_t *parser, const char *name, const char *val
|
||||
}
|
||||
}
|
||||
|
||||
const char *igloo_httpp_getvar(http_parser_t *parser, const char *name)
|
||||
const char *igloo_httpp_getvar(igloo_http_parser_t *parser, const char *name)
|
||||
{
|
||||
http_var_t var;
|
||||
http_var_t *found;
|
||||
igloo_http_var_t var;
|
||||
igloo_http_var_t *found;
|
||||
void *fp;
|
||||
|
||||
if (parser == NULL || name == NULL)
|
||||
@ -614,9 +614,9 @@ const char *igloo_httpp_getvar(http_parser_t *parser, const char *name)
|
||||
}
|
||||
}
|
||||
|
||||
static void _httpp_set_param_nocopy(avl_tree *tree, char *name, char *value, int replace)
|
||||
static void _httpp_set_param_nocopy(igloo_avl_tree *tree, char *name, char *value, int replace)
|
||||
{
|
||||
http_var_t *var, *found;
|
||||
igloo_http_var_t *var, *found;
|
||||
char **n;
|
||||
|
||||
if (name == NULL || value == NULL)
|
||||
@ -625,7 +625,7 @@ static void _httpp_set_param_nocopy(avl_tree *tree, char *name, char *value, int
|
||||
found = igloo__httpp_get_param_var(tree, name);
|
||||
|
||||
if (replace || !found) {
|
||||
var = (http_var_t *)calloc(1, sizeof(http_var_t));
|
||||
var = (igloo_http_var_t *)calloc(1, sizeof(igloo_http_var_t));
|
||||
if (var == NULL) {
|
||||
free(name);
|
||||
free(value);
|
||||
@ -659,7 +659,7 @@ static void _httpp_set_param_nocopy(avl_tree *tree, char *name, char *value, int
|
||||
}
|
||||
}
|
||||
|
||||
static void _httpp_set_param(avl_tree *tree, const char *name, const char *value)
|
||||
static void _httpp_set_param(igloo_avl_tree *tree, const char *name, const char *value)
|
||||
{
|
||||
if (name == NULL || value == NULL)
|
||||
return;
|
||||
@ -667,10 +667,10 @@ static void _httpp_set_param(avl_tree *tree, const char *name, const char *value
|
||||
_httpp_set_param_nocopy(tree, strdup(name), igloo_url_unescape(value, strlen(value)), 1);
|
||||
}
|
||||
|
||||
static http_var_t *igloo__httpp_get_param_var(avl_tree *tree, const char *name)
|
||||
static igloo_http_var_t *igloo__httpp_get_param_var(igloo_avl_tree *tree, const char *name)
|
||||
{
|
||||
http_var_t var;
|
||||
http_var_t *found;
|
||||
igloo_http_var_t var;
|
||||
igloo_http_var_t *found;
|
||||
void *fp;
|
||||
|
||||
fp = &found;
|
||||
@ -682,9 +682,9 @@ static http_var_t *igloo__httpp_get_param_var(avl_tree *tree, const char *name)
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
static const char *_httpp_get_param(avl_tree *tree, const char *name)
|
||||
static const char *_httpp_get_param(igloo_avl_tree *tree, const char *name)
|
||||
{
|
||||
http_var_t *res = igloo__httpp_get_param_var(tree, name);
|
||||
igloo_http_var_t *res = igloo__httpp_get_param_var(tree, name);
|
||||
|
||||
if (!res)
|
||||
return NULL;
|
||||
@ -695,29 +695,29 @@ static const char *_httpp_get_param(avl_tree *tree, const char *name)
|
||||
return res->value[0];
|
||||
}
|
||||
|
||||
void igloo_httpp_set_query_param(http_parser_t *parser, const char *name, const char *value)
|
||||
void igloo_httpp_set_query_param(igloo_http_parser_t *parser, const char *name, const char *value)
|
||||
{
|
||||
return _httpp_set_param(parser->queryvars, name, value);
|
||||
}
|
||||
|
||||
const char *igloo_httpp_get_query_param(http_parser_t *parser, const char *name)
|
||||
const char *igloo_httpp_get_query_param(igloo_http_parser_t *parser, const char *name)
|
||||
{
|
||||
return _httpp_get_param(parser->queryvars, name);
|
||||
}
|
||||
|
||||
void igloo_httpp_set_post_param(http_parser_t *parser, const char *name, const char *value)
|
||||
void igloo_httpp_set_post_param(igloo_http_parser_t *parser, const char *name, const char *value)
|
||||
{
|
||||
return _httpp_set_param(parser->postvars, name, value);
|
||||
}
|
||||
|
||||
const char *igloo_httpp_get_post_param(http_parser_t *parser, const char *name)
|
||||
const char *igloo_httpp_get_post_param(igloo_http_parser_t *parser, const char *name)
|
||||
{
|
||||
return _httpp_get_param(parser->postvars, name);
|
||||
}
|
||||
|
||||
const http_var_t *igloo_httpp_get_param_var(http_parser_t *parser, const char *name)
|
||||
const igloo_http_var_t *igloo_httpp_get_param_var(igloo_http_parser_t *parser, const char *name)
|
||||
{
|
||||
http_var_t *ret = igloo__httpp_get_param_var(parser->postvars, name);
|
||||
igloo_http_var_t *ret = igloo__httpp_get_param_var(parser->postvars, name);
|
||||
|
||||
if (ret)
|
||||
return ret;
|
||||
@ -725,9 +725,9 @@ const http_var_t *igloo_httpp_get_param_var(http_parser_t *parser, const char *n
|
||||
return igloo__httpp_get_param_var(parser->queryvars, name);
|
||||
}
|
||||
|
||||
const http_var_t *igloo_httpp_get_any_var(http_parser_t *parser, httpp_ns_t ns, const char *name)
|
||||
const igloo_http_var_t *igloo_httpp_get_any_var(igloo_http_parser_t *parser, igloo_httpp_ns_t ns, const char *name)
|
||||
{
|
||||
avl_tree *tree = NULL;
|
||||
igloo_avl_tree *tree = NULL;
|
||||
|
||||
if (!parser || !name)
|
||||
return NULL;
|
||||
@ -757,10 +757,10 @@ const http_var_t *igloo_httpp_get_any_var(http_parser_t *parser, httpp_ns_t ns,
|
||||
return igloo__httpp_get_param_var(tree, name);
|
||||
}
|
||||
|
||||
char ** igloo_httpp_get_any_key(http_parser_t *parser, httpp_ns_t ns)
|
||||
char ** igloo_httpp_get_any_key(igloo_http_parser_t *parser, igloo_httpp_ns_t ns)
|
||||
{
|
||||
avl_tree *tree = NULL;
|
||||
avl_node *avlnode;
|
||||
igloo_avl_tree *tree = NULL;
|
||||
igloo_avl_node *avlnode;
|
||||
char **ret;
|
||||
size_t len;
|
||||
size_t pos = 0;
|
||||
@ -791,7 +791,7 @@ char ** igloo_httpp_get_any_key(http_parser_t *parser, httpp_ns_t ns)
|
||||
len = 8;
|
||||
|
||||
for (avlnode = igloo_avl_get_first(tree); avlnode; avlnode = igloo_avl_get_next(avlnode)) {
|
||||
http_var_t *var = avlnode->key;
|
||||
igloo_http_var_t *var = avlnode->key;
|
||||
|
||||
if (ns == HTTPP_NS_VAR) {
|
||||
if (var->name[0] != '_' || var->name[1] != '_') {
|
||||
@ -839,7 +839,7 @@ void igloo_httpp_free_any_key(char **keys)
|
||||
free(keys);
|
||||
}
|
||||
|
||||
const char *igloo_httpp_get_param(http_parser_t *parser, const char *name)
|
||||
const char *igloo_httpp_get_param(igloo_http_parser_t *parser, const char *name)
|
||||
{
|
||||
const char *ret = _httpp_get_param(parser->postvars, name);
|
||||
|
||||
@ -849,7 +849,7 @@ const char *igloo_httpp_get_param(http_parser_t *parser, const char *name)
|
||||
return _httpp_get_param(parser->queryvars, name);
|
||||
}
|
||||
|
||||
static void httpp_clear(http_parser_t *parser)
|
||||
static void httpp_clear(igloo_http_parser_t *parser)
|
||||
{
|
||||
parser->req_type = httpp_req_none;
|
||||
if (parser->uri)
|
||||
@ -861,7 +861,7 @@ static void httpp_clear(http_parser_t *parser)
|
||||
parser->vars = NULL;
|
||||
}
|
||||
|
||||
int igloo_httpp_addref(http_parser_t *parser)
|
||||
int igloo_httpp_addref(igloo_http_parser_t *parser)
|
||||
{
|
||||
if (!parser)
|
||||
return -1;
|
||||
@ -871,7 +871,7 @@ int igloo_httpp_addref(http_parser_t *parser)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int igloo_httpp_release(http_parser_t *parser)
|
||||
int igloo_httpp_release(igloo_http_parser_t *parser)
|
||||
{
|
||||
if (!parser)
|
||||
return -1;
|
||||
@ -897,17 +897,17 @@ static char *_lowercase(char *str)
|
||||
|
||||
static int igloo__compare_vars(void *compare_arg, void *a, void *b)
|
||||
{
|
||||
http_var_t *vara, *varb;
|
||||
igloo_http_var_t *vara, *varb;
|
||||
|
||||
vara = (http_var_t *)a;
|
||||
varb = (http_var_t *)b;
|
||||
vara = (igloo_http_var_t *)a;
|
||||
varb = (igloo_http_var_t *)b;
|
||||
|
||||
return strcmp(vara->name, varb->name);
|
||||
}
|
||||
|
||||
static int igloo__free_vars(void *key)
|
||||
{
|
||||
http_var_t *var = (http_var_t *)key;
|
||||
igloo_http_var_t *var = (igloo_http_var_t *)key;
|
||||
size_t i;
|
||||
|
||||
free(var->name);
|
||||
@ -921,7 +921,7 @@ static int igloo__free_vars(void *key)
|
||||
return 1;
|
||||
}
|
||||
|
||||
httpp_request_type_e igloo_httpp_str_to_method(const char * method) {
|
||||
igloo_httpp_request_type_e igloo_httpp_str_to_method(const char * method) {
|
||||
if (strcasecmp("GET", method) == 0) {
|
||||
return httpp_req_get;
|
||||
} else if (strcasecmp("POST", method) == 0) {
|
||||
|
102
httpp/httpp.h
102
httpp/httpp.h
@ -29,22 +29,22 @@
|
||||
|
||||
#include <avl/avl.h>
|
||||
|
||||
#define HTTPP_VAR_PROTOCOL "__protocol"
|
||||
#define HTTPP_VAR_VERSION "__version"
|
||||
#define HTTPP_VAR_URI "__uri"
|
||||
#define HTTPP_VAR_RAWURI "__rawuri"
|
||||
#define HTTPP_VAR_QUERYARGS "__queryargs"
|
||||
#define HTTPP_VAR_REQ_TYPE "__req_type"
|
||||
#define HTTPP_VAR_ERROR_MESSAGE "__errormessage"
|
||||
#define HTTPP_VAR_ERROR_CODE "__errorcode"
|
||||
#define HTTPP_VAR_ICYPASSWORD "__icy_password"
|
||||
#define igloo_HTTPP_VAR_PROTOCOL "__protocol"
|
||||
#define igloo_HTTPP_VAR_VERSION "__version"
|
||||
#define igloo_HTTPP_VAR_URI "__uri"
|
||||
#define igloo_HTTPP_VAR_RAWURI "__rawuri"
|
||||
#define igloo_HTTPP_VAR_QUERYARGS "__queryargs"
|
||||
#define igloo_HTTPP_VAR_REQ_TYPE "__req_type"
|
||||
#define igloo_HTTPP_VAR_ERROR_MESSAGE "__errormessage"
|
||||
#define igloo_HTTPP_VAR_ERROR_CODE "__errorcode"
|
||||
#define igloo_HTTPP_VAR_ICYPASSWORD "__icy_password"
|
||||
|
||||
typedef enum {
|
||||
HTTPP_NS_VAR,
|
||||
HTTPP_NS_HEADER,
|
||||
HTTPP_NS_QUERY_STRING,
|
||||
HTTPP_NS_POST_BODY
|
||||
} httpp_ns_t;
|
||||
} igloo_httpp_ns_t;
|
||||
|
||||
typedef enum httpp_request_type_tag {
|
||||
/* Initial and internally used state of the engine */
|
||||
@ -66,62 +66,62 @@ typedef enum httpp_request_type_tag {
|
||||
httpp_req_stats,
|
||||
/* Used if request method is unknown. MUST BE LAST ONE IN LIST. */
|
||||
httpp_req_unknown
|
||||
} httpp_request_type_e;
|
||||
} igloo_httpp_request_type_e;
|
||||
|
||||
typedef unsigned int httpp_request_info_t;
|
||||
#define HTTPP_REQUEST_IS_SAFE ((httpp_request_info_t)0x0001U)
|
||||
#define HTTPP_REQUEST_IS_IDEMPOTENT ((httpp_request_info_t)0x0002U)
|
||||
#define HTTPP_REQUEST_IS_CACHEABLE ((httpp_request_info_t)0x0004U)
|
||||
#define HTTPP_REQUEST_HAS_RESPONSE_BODY ((httpp_request_info_t)0x0010U)
|
||||
#define HTTPP_REQUEST_HAS_REQUEST_BODY ((httpp_request_info_t)0x0100U)
|
||||
#define HTTPP_REQUEST_HAS_OPTIONAL_REQUEST_BODY ((httpp_request_info_t)0x0200U)
|
||||
typedef unsigned int igloo_httpp_request_info_t;
|
||||
#define igloo_HTTPP_REQUEST_IS_SAFE ((igloo_httpp_request_info_t)0x0001U)
|
||||
#define igloo_HTTPP_REQUEST_IS_IDEMPOTENT ((igloo_httpp_request_info_t)0x0002U)
|
||||
#define igloo_HTTPP_REQUEST_IS_CACHEABLE ((igloo_httpp_request_info_t)0x0004U)
|
||||
#define igloo_HTTPP_REQUEST_HAS_RESPONSE_BODY ((igloo_httpp_request_info_t)0x0010U)
|
||||
#define igloo_HTTPP_REQUEST_HAS_REQUEST_BODY ((igloo_httpp_request_info_t)0x0100U)
|
||||
#define igloo_HTTPP_REQUEST_HAS_OPTIONAL_REQUEST_BODY ((igloo_httpp_request_info_t)0x0200U)
|
||||
|
||||
typedef struct http_var_tag http_var_t;
|
||||
struct http_var_tag {
|
||||
typedef struct igloo_http_var_tag igloo_http_var_t;
|
||||
struct igloo_http_var_tag {
|
||||
char *name;
|
||||
size_t values;
|
||||
char **value;
|
||||
};
|
||||
|
||||
typedef struct http_varlist_tag {
|
||||
http_var_t var;
|
||||
struct http_varlist_tag *next;
|
||||
} http_varlist_t;
|
||||
typedef struct igloo_http_varlist_tag {
|
||||
igloo_http_var_t var;
|
||||
struct igloo_http_varlist_tag *next;
|
||||
} igloo_http_varlist_t;
|
||||
|
||||
typedef struct http_parser_tag {
|
||||
typedef struct igloo_http_parser_tag {
|
||||
size_t refc;
|
||||
httpp_request_type_e req_type;
|
||||
igloo_httpp_request_type_e req_type;
|
||||
char *uri;
|
||||
avl_tree *vars;
|
||||
avl_tree *queryvars;
|
||||
avl_tree *postvars;
|
||||
} http_parser_t;
|
||||
igloo_avl_tree *vars;
|
||||
igloo_avl_tree *queryvars;
|
||||
igloo_avl_tree *postvars;
|
||||
} igloo_http_parser_t;
|
||||
|
||||
httpp_request_info_t igloo_httpp_request_info(httpp_request_type_e req);
|
||||
igloo_httpp_request_info_t igloo_httpp_request_info(igloo_httpp_request_type_e req);
|
||||
|
||||
http_parser_t *igloo_httpp_create_parser(void);
|
||||
void igloo_httpp_initialize(http_parser_t *parser, http_varlist_t *defaults);
|
||||
int igloo_httpp_parse(http_parser_t *parser, const char *http_data, unsigned long len);
|
||||
int httpp_parse_icy(http_parser_t *parser, const char *http_data, unsigned long len);
|
||||
int igloo_httpp_parse_response(http_parser_t *parser, const char *http_data, unsigned long len, const char *uri);
|
||||
int igloo_httpp_parse_postdata(http_parser_t *parser, const char *body_data, size_t len);
|
||||
void igloo_httpp_setvar(http_parser_t *parser, const char *name, const char *value);
|
||||
void igloo_httpp_deletevar(http_parser_t *parser, const char *name);
|
||||
const char *igloo_httpp_getvar(http_parser_t *parser, const char *name);
|
||||
void igloo_httpp_set_query_param(http_parser_t *parser, const char *name, const char *value);
|
||||
const char *igloo_httpp_get_query_param(http_parser_t *parser, const char *name);
|
||||
void igloo_httpp_set_post_param(http_parser_t *parser, const char *name, const char *value);
|
||||
const char *igloo_httpp_get_post_param(http_parser_t *parser, const char *name);
|
||||
const char *igloo_httpp_get_param(http_parser_t *parser, const char *name);
|
||||
const http_var_t *igloo_httpp_get_param_var(http_parser_t *parser, const char *name);
|
||||
const http_var_t *igloo_httpp_get_any_var(http_parser_t *parser, httpp_ns_t ns, const char *name);
|
||||
char ** igloo_httpp_get_any_key(http_parser_t *parser, httpp_ns_t ns);
|
||||
igloo_http_parser_t *igloo_httpp_create_parser(void);
|
||||
void igloo_httpp_initialize(igloo_http_parser_t *parser, igloo_http_varlist_t *defaults);
|
||||
int igloo_httpp_parse(igloo_http_parser_t *parser, const char *http_data, unsigned long len);
|
||||
int httpp_parse_icy(igloo_http_parser_t *parser, const char *http_data, unsigned long len);
|
||||
int igloo_httpp_parse_response(igloo_http_parser_t *parser, const char *http_data, unsigned long len, const char *uri);
|
||||
int igloo_httpp_parse_postdata(igloo_http_parser_t *parser, const char *body_data, size_t len);
|
||||
void igloo_httpp_setvar(igloo_http_parser_t *parser, const char *name, const char *value);
|
||||
void igloo_httpp_deletevar(igloo_http_parser_t *parser, const char *name);
|
||||
const char *igloo_httpp_getvar(igloo_http_parser_t *parser, const char *name);
|
||||
void igloo_httpp_set_query_param(igloo_http_parser_t *parser, const char *name, const char *value);
|
||||
const char *igloo_httpp_get_query_param(igloo_http_parser_t *parser, const char *name);
|
||||
void igloo_httpp_set_post_param(igloo_http_parser_t *parser, const char *name, const char *value);
|
||||
const char *igloo_httpp_get_post_param(igloo_http_parser_t *parser, const char *name);
|
||||
const char *igloo_httpp_get_param(igloo_http_parser_t *parser, const char *name);
|
||||
const igloo_http_var_t *igloo_httpp_get_param_var(igloo_http_parser_t *parser, const char *name);
|
||||
const igloo_http_var_t *igloo_httpp_get_any_var(igloo_http_parser_t *parser, igloo_httpp_ns_t ns, const char *name);
|
||||
char ** igloo_httpp_get_any_key(igloo_http_parser_t *parser, igloo_httpp_ns_t ns);
|
||||
void igloo_httpp_free_any_key(char **keys);
|
||||
int igloo_httpp_addref(http_parser_t *parser);
|
||||
int igloo_httpp_release(http_parser_t *parser);
|
||||
int igloo_httpp_addref(igloo_http_parser_t *parser);
|
||||
int igloo_httpp_release(igloo_http_parser_t *parser);
|
||||
#define httpp_destroy(x) igloo_httpp_release((x))
|
||||
|
||||
/* util functions */
|
||||
httpp_request_type_e igloo_httpp_str_to_method(const char * method);
|
||||
igloo_httpp_request_type_e igloo_httpp_str_to_method(const char * method);
|
||||
|
||||
#endif
|
||||
|
@ -8,9 +8,9 @@ int main(int argc, char **argv)
|
||||
{
|
||||
char buff[8192];
|
||||
int readed;
|
||||
http_parser_t parser;
|
||||
avl_node *node;
|
||||
http_var_t *var;
|
||||
igloo_http_parser_t parser;
|
||||
igloo_avl_node *node;
|
||||
igloo_http_var_t *var;
|
||||
|
||||
igloo_httpp_initialize(&parser, NULL);
|
||||
|
||||
@ -39,7 +39,7 @@ int main(int argc, char **argv)
|
||||
|
||||
node = igloo_avl_get_first(parser.vars);
|
||||
while (node) {
|
||||
var = (http_var_t *)node->key;
|
||||
var = (igloo_http_var_t *)node->key;
|
||||
|
||||
if (var)
|
||||
printf("Iterating variable(s): %s = %s\n", var->name, var->value);
|
||||
|
22
log/log.c
22
log/log.c
@ -57,14 +57,14 @@
|
||||
#define LOG_MAXLINELEN 1024
|
||||
|
||||
#ifdef _WIN32
|
||||
#define mutex_t CRITICAL_SECTION
|
||||
#define igloo_mutex_t CRITICAL_SECTION
|
||||
#define snprintf _snprintf
|
||||
#define vsnprintf _vsnprintf
|
||||
#else
|
||||
#define mutex_t pthread_mutex_t
|
||||
#define igloo_mutex_t pthread_mutex_t
|
||||
#endif
|
||||
|
||||
static mutex_t igloo__logger_mutex;
|
||||
static igloo_mutex_t igloo__logger_mutex;
|
||||
static int igloo__initialized = 0;
|
||||
|
||||
typedef struct _log_entry_t
|
||||
@ -189,10 +189,10 @@ int igloo_log_open_file(FILE *file)
|
||||
{
|
||||
int log_id;
|
||||
|
||||
if(file == NULL) return LOG_EINSANE;
|
||||
if(file == NULL) return igloo_LOG_EINSANE;
|
||||
|
||||
log_id = _get_log_id();
|
||||
if (log_id < 0) return LOG_ENOMORELOGS;
|
||||
if (log_id < 0) return igloo_LOG_ENOMORELOGS;
|
||||
|
||||
igloo_loglist[log_id].logfile = file;
|
||||
igloo_loglist[log_id].filename = NULL;
|
||||
@ -207,8 +207,8 @@ int igloo_log_open(const char *filename)
|
||||
int id;
|
||||
FILE *file;
|
||||
|
||||
if (filename == NULL) return LOG_EINSANE;
|
||||
if (strcmp(filename, "") == 0) return LOG_EINSANE;
|
||||
if (filename == NULL) return igloo_LOG_EINSANE;
|
||||
if (strcmp(filename, "") == 0) return igloo_LOG_EINSANE;
|
||||
|
||||
file = fopen(filename, "a");
|
||||
|
||||
@ -244,10 +244,10 @@ void igloo_log_set_trigger(int id, unsigned trigger)
|
||||
int igloo_log_set_filename(int id, const char *filename)
|
||||
{
|
||||
if (id < 0 || id >= LOG_MAXLOGS)
|
||||
return LOG_EINSANE;
|
||||
return igloo_LOG_EINSANE;
|
||||
/* NULL filename is ok, empty filename is not. */
|
||||
if ((filename && !strcmp(filename, "")) || igloo_loglist [id] . in_use == 0)
|
||||
return LOG_EINSANE;
|
||||
return igloo_LOG_EINSANE;
|
||||
_lock_logger();
|
||||
if (igloo_loglist [id] . filename)
|
||||
free (igloo_loglist [id] . filename);
|
||||
@ -262,7 +262,7 @@ int igloo_log_set_filename(int id, const char *filename)
|
||||
int igloo_log_set_archive_timestamp(int id, int value)
|
||||
{
|
||||
if (id < 0 || id >= LOG_MAXLOGS)
|
||||
return LOG_EINSANE;
|
||||
return igloo_LOG_EINSANE;
|
||||
_lock_logger();
|
||||
igloo_loglist[id].archive_timestamp = value;
|
||||
_unlock_logger();
|
||||
@ -273,7 +273,7 @@ int igloo_log_set_archive_timestamp(int id, int value)
|
||||
int igloo_log_open_with_buffer(const char *filename, int size)
|
||||
{
|
||||
/* not implemented */
|
||||
return LOG_ENOTIMPL;
|
||||
return igloo_LOG_ENOTIMPL;
|
||||
}
|
||||
|
||||
|
||||
|
10
log/log.h
10
log/log.h
@ -31,11 +31,11 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#define LOG_EINSANE -1
|
||||
#define LOG_ENOMORELOGS -2
|
||||
#define LOG_ECANTOPEN -3
|
||||
#define LOG_ENOTOPEN -4
|
||||
#define LOG_ENOTIMPL -5
|
||||
#define igloo_LOG_EINSANE -1
|
||||
#define igloo_LOG_ENOMORELOGS -2
|
||||
#define igloo_LOG_ECANTOPEN -3
|
||||
#define igloo_LOG_ENOTOPEN -4
|
||||
#define igloo_LOG_ENOTIMPL -5
|
||||
|
||||
#ifdef _WIN32
|
||||
#define IO_BUFFER_TYPE _IONBF
|
||||
|
@ -60,7 +60,7 @@ static int _isip(const char *what);
|
||||
/* internal data */
|
||||
|
||||
#ifndef NO_THREAD
|
||||
static mutex_t igloo__resolver_mutex;
|
||||
static igloo_mutex_t igloo__resolver_mutex;
|
||||
#endif
|
||||
static int igloo__initialized = 0;
|
||||
|
||||
|
150
net/sock.c
150
net/sock.c
@ -202,9 +202,9 @@ static int sock_connect_pending (int error)
|
||||
|
||||
/* igloo_sock_valid_socket
|
||||
**
|
||||
** determines if a sock_t represents a valid socket
|
||||
** determines if a igloo_sock_t represents a valid socket
|
||||
*/
|
||||
int igloo_sock_valid_socket(sock_t sock)
|
||||
int igloo_sock_valid_socket(igloo_sock_t sock)
|
||||
{
|
||||
int ret;
|
||||
int optval;
|
||||
@ -219,7 +219,7 @@ int igloo_sock_valid_socket(sock_t sock)
|
||||
|
||||
|
||||
/* determines if the passed socket is still connected */
|
||||
int igloo_sock_active (sock_t sock)
|
||||
int igloo_sock_active (igloo_sock_t sock)
|
||||
{
|
||||
char c;
|
||||
int l;
|
||||
@ -227,7 +227,7 @@ int igloo_sock_active (sock_t sock)
|
||||
l = recv (sock, &c, 1, MSG_PEEK);
|
||||
if (l == 0)
|
||||
return 0;
|
||||
if (l == SOCK_ERROR && igloo_sock_recoverable (igloo_sock_error()))
|
||||
if (l == igloo_SOCK_ERROR && igloo_sock_recoverable (igloo_sock_error()))
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
@ -257,7 +257,7 @@ int inet_aton(const char *s, struct in_addr *a)
|
||||
* 1 for blocking
|
||||
* 0 for nonblocking
|
||||
*/
|
||||
int igloo_sock_set_blocking(sock_t sock, int block)
|
||||
int igloo_sock_set_blocking(igloo_sock_t sock, int block)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
#ifdef __MINGW32__
|
||||
@ -268,7 +268,7 @@ int igloo_sock_set_blocking(sock_t sock, int block)
|
||||
#endif
|
||||
|
||||
if ((!igloo_sock_valid_socket(sock)) || (block < 0) || (block > 1))
|
||||
return SOCK_ERROR;
|
||||
return igloo_SOCK_ERROR;
|
||||
|
||||
#ifdef _WIN32
|
||||
if (block) varblock = 0;
|
||||
@ -278,14 +278,14 @@ int igloo_sock_set_blocking(sock_t sock, int block)
|
||||
#endif
|
||||
}
|
||||
|
||||
int igloo_sock_set_nolinger(sock_t sock)
|
||||
int igloo_sock_set_nolinger(igloo_sock_t sock)
|
||||
{
|
||||
struct linger lin = { 0, 0 };
|
||||
return setsockopt(sock, SOL_SOCKET, SO_LINGER, (void *)&lin,
|
||||
sizeof(struct linger));
|
||||
}
|
||||
|
||||
int igloo_sock_set_nodelay(sock_t sock)
|
||||
int igloo_sock_set_nodelay(igloo_sock_t sock)
|
||||
{
|
||||
int nodelay = 1;
|
||||
|
||||
@ -293,7 +293,7 @@ int igloo_sock_set_nodelay(sock_t sock)
|
||||
sizeof(int));
|
||||
}
|
||||
|
||||
int igloo_sock_set_keepalive(sock_t sock)
|
||||
int igloo_sock_set_keepalive(igloo_sock_t sock)
|
||||
{
|
||||
int keepalive = 1;
|
||||
return setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, (void *)&keepalive,
|
||||
@ -304,7 +304,7 @@ int igloo_sock_set_keepalive(sock_t sock)
|
||||
**
|
||||
** close the socket
|
||||
*/
|
||||
int igloo_sock_close(sock_t sock)
|
||||
int igloo_sock_close(igloo_sock_t sock)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
return closesocket(sock);
|
||||
@ -319,14 +319,14 @@ int igloo_sock_close(sock_t sock)
|
||||
*/
|
||||
#ifdef HAVE_WRITEV
|
||||
|
||||
ssize_t igloo_sock_writev (sock_t sock, const struct iovec *iov, size_t count)
|
||||
ssize_t igloo_sock_writev (igloo_sock_t sock, const struct iovec *iov, size_t count)
|
||||
{
|
||||
return writev (sock, iov, count);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
ssize_t igloo_sock_writev (sock_t sock, const struct iovec *iov, size_t count)
|
||||
ssize_t igloo_sock_writev (igloo_sock_t sock, const struct iovec *iov, size_t count)
|
||||
{
|
||||
int i = count, accum = 0, ret;
|
||||
const struct iovec *v = iov;
|
||||
@ -357,15 +357,15 @@ ssize_t igloo_sock_writev (sock_t sock, const struct iovec *iov, size_t count)
|
||||
** write bytes to the socket
|
||||
** this function will _NOT_ block
|
||||
*/
|
||||
int igloo_sock_write_bytes(sock_t sock, const void *buff, size_t len)
|
||||
int igloo_sock_write_bytes(igloo_sock_t sock, const void *buff, size_t len)
|
||||
{
|
||||
/* sanity check */
|
||||
if (!buff) {
|
||||
return SOCK_ERROR;
|
||||
return igloo_SOCK_ERROR;
|
||||
} else if (len <= 0) {
|
||||
return SOCK_ERROR;
|
||||
return igloo_SOCK_ERROR;
|
||||
} /*else if (!igloo_sock_valid_socket(sock)) {
|
||||
return SOCK_ERROR;
|
||||
return igloo_SOCK_ERROR;
|
||||
} */
|
||||
|
||||
return send(sock, buff, len, 0);
|
||||
@ -376,7 +376,7 @@ int igloo_sock_write_bytes(sock_t sock, const void *buff, size_t len)
|
||||
** writes a string to a socket
|
||||
** This function must only be called with a blocking socket.
|
||||
*/
|
||||
int igloo_sock_write_string(sock_t sock, const char *buff)
|
||||
int igloo_sock_write_string(igloo_sock_t sock, const char *buff)
|
||||
{
|
||||
return (igloo_sock_write_bytes(sock, buff, strlen(buff)) > 0);
|
||||
}
|
||||
@ -387,7 +387,7 @@ int igloo_sock_write_string(sock_t sock, const char *buff)
|
||||
** this function must only be called with a blocking socket.
|
||||
** will truncate the string if it's greater than 1024 chars.
|
||||
*/
|
||||
int igloo_sock_write(sock_t sock, const char *fmt, ...)
|
||||
int igloo_sock_write(igloo_sock_t sock, const char *fmt, ...)
|
||||
{
|
||||
int rc;
|
||||
va_list ap;
|
||||
@ -400,7 +400,7 @@ int igloo_sock_write(sock_t sock, const char *fmt, ...)
|
||||
}
|
||||
|
||||
#ifdef HAVE_OLD_VSNPRINTF
|
||||
int igloo_sock_write_fmt(sock_t sock, const char *fmt, va_list ap)
|
||||
int igloo_sock_write_fmt(igloo_sock_t sock, const char *fmt, va_list ap)
|
||||
{
|
||||
va_list ap_local;
|
||||
unsigned int len = 1024;
|
||||
@ -428,11 +428,11 @@ int igloo_sock_write_fmt(sock_t sock, const char *fmt, va_list ap)
|
||||
return ret;
|
||||
}
|
||||
#else
|
||||
int igloo_sock_write_fmt(sock_t sock, const char *fmt, va_list ap)
|
||||
int igloo_sock_write_fmt(igloo_sock_t sock, const char *fmt, va_list ap)
|
||||
{
|
||||
char buffer [1024], *buff = buffer;
|
||||
int len;
|
||||
int rc = SOCK_ERROR;
|
||||
int rc = igloo_SOCK_ERROR;
|
||||
va_list ap_retry;
|
||||
|
||||
va_copy (ap_retry, ap);
|
||||
@ -463,7 +463,7 @@ int igloo_sock_write_fmt(sock_t sock, const char *fmt, va_list ap)
|
||||
#endif
|
||||
|
||||
|
||||
int igloo_sock_read_bytes(sock_t sock, char *buff, size_t len)
|
||||
int igloo_sock_read_bytes(igloo_sock_t sock, char *buff, size_t len)
|
||||
{
|
||||
|
||||
/*if (!igloo_sock_valid_socket(sock)) return 0; */
|
||||
@ -481,7 +481,7 @@ int igloo_sock_read_bytes(sock_t sock, char *buff, size_t len)
|
||||
**
|
||||
** this function will probably not work on sockets in nonblocking mode
|
||||
*/
|
||||
int igloo_sock_read_line(sock_t sock, char *buff, const int len)
|
||||
int igloo_sock_read_line(igloo_sock_t sock, char *buff, const int len)
|
||||
{
|
||||
char c = '\0';
|
||||
int read_bytes, pos;
|
||||
@ -517,23 +517,23 @@ int igloo_sock_read_line(sock_t sock, char *buff, const int len)
|
||||
|
||||
/* see if a connection has been established. If timeout is < 0 then wait
|
||||
* indefinitely, else wait for the stated number of seconds.
|
||||
* return SOCK_TIMEOUT for timeout
|
||||
* return SOCK_ERROR for failure
|
||||
* return igloo_SOCK_TIMEOUT for timeout
|
||||
* return igloo_SOCK_ERROR for failure
|
||||
* return 0 for try again, interrupted
|
||||
* return 1 for ok
|
||||
*/
|
||||
#ifdef HAVE_POLL
|
||||
int igloo_sock_connected (sock_t sock, int timeout)
|
||||
int igloo_sock_connected (igloo_sock_t sock, int timeout)
|
||||
{
|
||||
struct pollfd check;
|
||||
int val = SOCK_ERROR;
|
||||
int val = igloo_SOCK_ERROR;
|
||||
socklen_t size = sizeof val;
|
||||
|
||||
check.fd = sock;
|
||||
check.events = POLLOUT;
|
||||
switch (poll (&check, 1, timeout*1000))
|
||||
{
|
||||
case 0: return SOCK_TIMEOUT;
|
||||
case 0: return igloo_SOCK_TIMEOUT;
|
||||
default:
|
||||
/* on windows getsockopt.val is defined as char* */
|
||||
if (getsockopt(sock, SOL_SOCKET, SO_ERROR, (void*) &val, &size) == 0)
|
||||
@ -546,16 +546,16 @@ int igloo_sock_connected (sock_t sock, int timeout)
|
||||
case -1:
|
||||
if (igloo_sock_recoverable (igloo_sock_error()))
|
||||
return 0;
|
||||
return SOCK_ERROR;
|
||||
return igloo_SOCK_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
int igloo_sock_connected (sock_t sock, int timeout)
|
||||
int igloo_sock_connected (igloo_sock_t sock, int timeout)
|
||||
{
|
||||
fd_set wfds;
|
||||
int val = SOCK_ERROR;
|
||||
int val = igloo_SOCK_ERROR;
|
||||
socklen_t size = sizeof val;
|
||||
struct timeval tv, *timeval = NULL;
|
||||
|
||||
@ -573,7 +573,7 @@ int igloo_sock_connected (sock_t sock, int timeout)
|
||||
switch (select(sock + 1, NULL, &wfds, NULL, timeval))
|
||||
{
|
||||
case 0:
|
||||
return SOCK_TIMEOUT;
|
||||
return igloo_SOCK_TIMEOUT;
|
||||
default:
|
||||
/* on windows getsockopt.val is defined as char* */
|
||||
if (getsockopt(sock, SOL_SOCKET, SO_ERROR, (void*) &val, &size) == 0)
|
||||
@ -586,21 +586,21 @@ int igloo_sock_connected (sock_t sock, int timeout)
|
||||
case -1:
|
||||
if (igloo_sock_recoverable (igloo_sock_error()))
|
||||
return 0;
|
||||
return SOCK_ERROR;
|
||||
return igloo_SOCK_ERROR;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
sock_t igloo_sock_connect_wto (const char *hostname, int port, int timeout)
|
||||
igloo_sock_t igloo_sock_connect_wto (const char *hostname, int port, int timeout)
|
||||
{
|
||||
return igloo_sock_connect_wto_bind(hostname, port, NULL, timeout);
|
||||
}
|
||||
|
||||
#ifdef HAVE_GETADDRINFO
|
||||
|
||||
sock_t igloo_sock_connect_non_blocking (const char *hostname, unsigned port)
|
||||
igloo_sock_t igloo_sock_connect_non_blocking (const char *hostname, unsigned port)
|
||||
{
|
||||
int sock = SOCK_ERROR;
|
||||
int sock = igloo_SOCK_ERROR;
|
||||
struct addrinfo *ai, *head, hints;
|
||||
char service[8];
|
||||
|
||||
@ -611,7 +611,7 @@ sock_t igloo_sock_connect_non_blocking (const char *hostname, unsigned port)
|
||||
snprintf (service, sizeof (service), "%u", port);
|
||||
|
||||
if (getaddrinfo (hostname, service, &hints, &head))
|
||||
return SOCK_ERROR;
|
||||
return igloo_SOCK_ERROR;
|
||||
|
||||
ai = head;
|
||||
while (ai)
|
||||
@ -624,7 +624,7 @@ sock_t igloo_sock_connect_non_blocking (const char *hostname, unsigned port)
|
||||
!sock_connect_pending(igloo_sock_error()))
|
||||
{
|
||||
igloo_sock_close (sock);
|
||||
sock = SOCK_ERROR;
|
||||
sock = igloo_SOCK_ERROR;
|
||||
}
|
||||
else
|
||||
break;
|
||||
@ -640,9 +640,9 @@ sock_t igloo_sock_connect_non_blocking (const char *hostname, unsigned port)
|
||||
* timeout is 0 or less then we will wait until the OS gives up on the connect
|
||||
* The socket is returned
|
||||
*/
|
||||
sock_t igloo_sock_connect_wto_bind (const char *hostname, int port, const char *bnd, int timeout)
|
||||
igloo_sock_t igloo_sock_connect_wto_bind (const char *hostname, int port, const char *bnd, int timeout)
|
||||
{
|
||||
sock_t sock = SOCK_ERROR;
|
||||
igloo_sock_t sock = igloo_SOCK_ERROR;
|
||||
struct addrinfo *ai, *head, *b_head=NULL, hints;
|
||||
char service[8];
|
||||
|
||||
@ -652,7 +652,7 @@ sock_t igloo_sock_connect_wto_bind (const char *hostname, int port, const char *
|
||||
snprintf (service, sizeof (service), "%u", port);
|
||||
|
||||
if (getaddrinfo (hostname, service, &hints, &head))
|
||||
return SOCK_ERROR;
|
||||
return igloo_SOCK_ERROR;
|
||||
|
||||
ai = head;
|
||||
while (ai)
|
||||
@ -673,7 +673,7 @@ sock_t igloo_sock_connect_wto_bind (const char *hostname, int port, const char *
|
||||
bind (sock, b_head->ai_addr, b_head->ai_addrlen) < 0)
|
||||
{
|
||||
igloo_sock_close (sock);
|
||||
sock = SOCK_ERROR;
|
||||
sock = igloo_SOCK_ERROR;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -682,7 +682,7 @@ sock_t igloo_sock_connect_wto_bind (const char *hostname, int port, const char *
|
||||
break;
|
||||
|
||||
/* loop as the connect maybe async */
|
||||
while (sock != SOCK_ERROR)
|
||||
while (sock != igloo_SOCK_ERROR)
|
||||
{
|
||||
if (igloo_sock_recoverable (igloo_sock_error()))
|
||||
{
|
||||
@ -697,9 +697,9 @@ sock_t igloo_sock_connect_wto_bind (const char *hostname, int port, const char *
|
||||
}
|
||||
}
|
||||
igloo_sock_close (sock);
|
||||
sock = SOCK_ERROR;
|
||||
sock = igloo_SOCK_ERROR;
|
||||
}
|
||||
if (sock != SOCK_ERROR)
|
||||
if (sock != igloo_SOCK_ERROR)
|
||||
break;
|
||||
}
|
||||
ai = ai->ai_next;
|
||||
@ -712,7 +712,7 @@ sock_t igloo_sock_connect_wto_bind (const char *hostname, int port, const char *
|
||||
}
|
||||
|
||||
|
||||
sock_t igloo_sock_get_server_socket (int port, const char *sinterface)
|
||||
igloo_sock_t igloo_sock_get_server_socket (int port, const char *sinterface)
|
||||
{
|
||||
struct sockaddr_storage sa;
|
||||
struct addrinfo hints, *res, *ai;
|
||||
@ -720,7 +720,7 @@ sock_t igloo_sock_get_server_socket (int port, const char *sinterface)
|
||||
int sock;
|
||||
|
||||
if (port < 0)
|
||||
return SOCK_ERROR;
|
||||
return igloo_SOCK_ERROR;
|
||||
|
||||
memset (&sa, 0, sizeof(sa));
|
||||
memset (&hints, 0, sizeof(hints));
|
||||
@ -731,7 +731,7 @@ sock_t igloo_sock_get_server_socket (int port, const char *sinterface)
|
||||
snprintf (service, sizeof (service), "%d", port);
|
||||
|
||||
if (getaddrinfo (sinterface, service, &hints, &res))
|
||||
return SOCK_ERROR;
|
||||
return igloo_SOCK_ERROR;
|
||||
ai = res;
|
||||
do
|
||||
{
|
||||
@ -757,14 +757,14 @@ sock_t igloo_sock_get_server_socket (int port, const char *sinterface)
|
||||
} while ((ai = ai->ai_next));
|
||||
|
||||
freeaddrinfo (res);
|
||||
return SOCK_ERROR;
|
||||
return igloo_SOCK_ERROR;
|
||||
}
|
||||
|
||||
|
||||
#else
|
||||
|
||||
|
||||
int sock_try_connection (sock_t sock, const char *hostname, unsigned int port)
|
||||
int sock_try_connection (igloo_sock_t sock, const char *hostname, unsigned int port)
|
||||
{
|
||||
struct sockaddr_in sin, server;
|
||||
char ip[MAX_ADDR_LEN];
|
||||
@ -795,13 +795,13 @@ int sock_try_connection (sock_t sock, const char *hostname, unsigned int port)
|
||||
return connect(sock, (struct sockaddr *)&server, sizeof(server));
|
||||
}
|
||||
|
||||
sock_t igloo_sock_connect_non_blocking (const char *hostname, unsigned port)
|
||||
igloo_sock_t igloo_sock_connect_non_blocking (const char *hostname, unsigned port)
|
||||
{
|
||||
sock_t sock;
|
||||
igloo_sock_t sock;
|
||||
|
||||
sock = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if (sock == SOCK_ERROR)
|
||||
return SOCK_ERROR;
|
||||
if (sock == igloo_SOCK_ERROR)
|
||||
return igloo_SOCK_ERROR;
|
||||
|
||||
igloo_sock_set_blocking (sock, 0);
|
||||
sock_try_connection (sock, hostname, port);
|
||||
@ -809,13 +809,13 @@ sock_t igloo_sock_connect_non_blocking (const char *hostname, unsigned port)
|
||||
return sock;
|
||||
}
|
||||
|
||||
sock_t igloo_sock_connect_wto_bind (const char *hostname, int port, const char *bnd, int timeout)
|
||||
igloo_sock_t igloo_sock_connect_wto_bind (const char *hostname, int port, const char *bnd, int timeout)
|
||||
{
|
||||
sock_t sock;
|
||||
igloo_sock_t sock;
|
||||
|
||||
sock = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if (sock == SOCK_ERROR)
|
||||
return SOCK_ERROR;
|
||||
if (sock == igloo_SOCK_ERROR)
|
||||
return igloo_SOCK_ERROR;
|
||||
|
||||
if (bnd)
|
||||
{
|
||||
@ -828,7 +828,7 @@ sock_t igloo_sock_connect_wto_bind (const char *hostname, int port, const char *
|
||||
bind (sock, (struct sockaddr *)&sa, sizeof(sa)) < 0)
|
||||
{
|
||||
igloo_sock_close (sock);
|
||||
return SOCK_ERROR;
|
||||
return igloo_SOCK_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
@ -841,7 +841,7 @@ sock_t igloo_sock_connect_wto_bind (const char *hostname, int port, const char *
|
||||
if (ret <= 0)
|
||||
{
|
||||
igloo_sock_close (sock);
|
||||
return SOCK_ERROR;
|
||||
return igloo_SOCK_ERROR;
|
||||
}
|
||||
}
|
||||
igloo_sock_set_blocking(sock, 1);
|
||||
@ -851,7 +851,7 @@ sock_t igloo_sock_connect_wto_bind (const char *hostname, int port, const char *
|
||||
if (sock_try_connection (sock, hostname, port) < 0)
|
||||
{
|
||||
igloo_sock_close (sock);
|
||||
sock = SOCK_ERROR;
|
||||
sock = igloo_SOCK_ERROR;
|
||||
}
|
||||
}
|
||||
return sock;
|
||||
@ -862,17 +862,17 @@ sock_t igloo_sock_connect_wto_bind (const char *hostname, int port, const char *
|
||||
**
|
||||
** create a socket for incoming requests on a specified port and
|
||||
** interface. if interface is null, listen on all interfaces.
|
||||
** returns the socket, or SOCK_ERROR on failure
|
||||
** returns the socket, or igloo_SOCK_ERROR on failure
|
||||
*/
|
||||
sock_t igloo_sock_get_server_socket(int port, const char *sinterface)
|
||||
igloo_sock_t igloo_sock_get_server_socket(int port, const char *sinterface)
|
||||
{
|
||||
struct sockaddr_in sa;
|
||||
int error, opt;
|
||||
sock_t sock;
|
||||
igloo_sock_t sock;
|
||||
char ip[MAX_ADDR_LEN];
|
||||
|
||||
if (port < 0)
|
||||
return SOCK_ERROR;
|
||||
return igloo_SOCK_ERROR;
|
||||
|
||||
/* defaults */
|
||||
memset(&sa, 0, sizeof(sa));
|
||||
@ -880,10 +880,10 @@ sock_t igloo_sock_get_server_socket(int port, const char *sinterface)
|
||||
/* set the interface to bind to if specified */
|
||||
if (sinterface != NULL) {
|
||||
if (!igloo_resolver_getip(sinterface, ip, sizeof (ip)))
|
||||
return SOCK_ERROR;
|
||||
return igloo_SOCK_ERROR;
|
||||
|
||||
if (!inet_aton(ip, &sa.sin_addr)) {
|
||||
return SOCK_ERROR;
|
||||
return igloo_SOCK_ERROR;
|
||||
} else {
|
||||
sa.sin_family = AF_INET;
|
||||
sa.sin_port = htons((short)port);
|
||||
@ -897,7 +897,7 @@ sock_t igloo_sock_get_server_socket(int port, const char *sinterface)
|
||||
/* get a socket */
|
||||
sock = socket (AF_INET, SOCK_STREAM, 0);
|
||||
if (sock == -1)
|
||||
return SOCK_ERROR;
|
||||
return igloo_SOCK_ERROR;
|
||||
|
||||
/* reuse it if we can */
|
||||
opt = 1;
|
||||
@ -906,19 +906,19 @@ sock_t igloo_sock_get_server_socket(int port, const char *sinterface)
|
||||
/* bind socket to port */
|
||||
error = bind(sock, (struct sockaddr *)&sa, sizeof (struct sockaddr_in));
|
||||
if (error == -1)
|
||||
return SOCK_ERROR;
|
||||
return igloo_SOCK_ERROR;
|
||||
|
||||
return sock;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void igloo_sock_set_send_buffer (sock_t sock, int win_size)
|
||||
void igloo_sock_set_send_buffer (igloo_sock_t sock, int win_size)
|
||||
{
|
||||
setsockopt (sock, SOL_SOCKET, SO_SNDBUF, (char *) &win_size, sizeof(win_size));
|
||||
}
|
||||
|
||||
int igloo_sock_listen(sock_t serversock, int backlog)
|
||||
int igloo_sock_listen(igloo_sock_t serversock, int backlog)
|
||||
{
|
||||
if (!igloo_sock_valid_socket(serversock))
|
||||
return 0;
|
||||
@ -929,23 +929,23 @@ int igloo_sock_listen(sock_t serversock, int backlog)
|
||||
return (listen(serversock, backlog) == 0);
|
||||
}
|
||||
|
||||
sock_t igloo_sock_accept(sock_t serversock, char *ip, size_t len)
|
||||
igloo_sock_t igloo_sock_accept(igloo_sock_t serversock, char *ip, size_t len)
|
||||
{
|
||||
#ifdef HAVE_GETNAMEINFO
|
||||
struct sockaddr_storage sa;
|
||||
#else
|
||||
struct sockaddr_in sa;
|
||||
#endif
|
||||
sock_t ret;
|
||||
igloo_sock_t ret;
|
||||
socklen_t slen;
|
||||
|
||||
if (ip == NULL || len == 0 || !igloo_sock_valid_socket(serversock))
|
||||
return SOCK_ERROR;
|
||||
return igloo_SOCK_ERROR;
|
||||
|
||||
slen = sizeof(sa);
|
||||
ret = accept(serversock, (struct sockaddr *)&sa, &slen);
|
||||
|
||||
if (ret != SOCK_ERROR)
|
||||
if (ret != igloo_SOCK_ERROR)
|
||||
{
|
||||
#ifdef HAVE_GETNAMEINFO
|
||||
if (getnameinfo ((struct sockaddr *)&sa, slen, ip, len, NULL, 0, NI_NUMERICHOST))
|
||||
|
56
net/sock.h
56
net/sock.h
@ -62,17 +62,17 @@ struct iovec
|
||||
#define MAX_ADDR_LEN 46
|
||||
#endif
|
||||
|
||||
#ifndef sock_t
|
||||
#define sock_t int
|
||||
#ifndef igloo_sock_t
|
||||
#define igloo_sock_t int
|
||||
#endif
|
||||
|
||||
/* The following values are based on unix avoiding errno value clashes */
|
||||
#define SOCK_SUCCESS 0
|
||||
#define SOCK_ERROR (sock_t)-1
|
||||
#define SOCK_TIMEOUT -2
|
||||
#define igloo_SOCK_SUCCESS 0
|
||||
#define igloo_SOCK_ERROR (igloo_sock_t)-1
|
||||
#define igloo_SOCK_TIMEOUT -2
|
||||
|
||||
/* sock connect macro */
|
||||
#define sock_connect(h, p) igloo_sock_connect_wto(h, p, 0)
|
||||
#define igloo_sock_connect(h, p) igloo_sock_connect_wto(h, p, 0)
|
||||
|
||||
/* Misc socket functions */
|
||||
void igloo_sock_initialize(void);
|
||||
@ -81,38 +81,38 @@ char *igloo_sock_get_localip(char *buff, int len);
|
||||
int igloo_sock_error(void);
|
||||
int igloo_sock_recoverable(int error);
|
||||
int igloo_sock_stalled(int error);
|
||||
int igloo_sock_valid_socket(sock_t sock);
|
||||
int igloo_sock_active (sock_t sock);
|
||||
int igloo_sock_set_blocking(sock_t sock, int block);
|
||||
int igloo_sock_set_nolinger(sock_t sock);
|
||||
int igloo_sock_set_keepalive(sock_t sock);
|
||||
int igloo_sock_set_nodelay(sock_t sock);
|
||||
void igloo_sock_set_send_buffer (sock_t sock, int win_size);
|
||||
int igloo_sock_valid_socket(igloo_sock_t sock);
|
||||
int igloo_sock_active (igloo_sock_t sock);
|
||||
int igloo_sock_set_blocking(igloo_sock_t sock, int block);
|
||||
int igloo_sock_set_nolinger(igloo_sock_t sock);
|
||||
int igloo_sock_set_keepalive(igloo_sock_t sock);
|
||||
int igloo_sock_set_nodelay(igloo_sock_t sock);
|
||||
void igloo_sock_set_send_buffer (igloo_sock_t sock, int win_size);
|
||||
void igloo_sock_set_error(int val);
|
||||
int igloo_sock_close(sock_t sock);
|
||||
int igloo_sock_close(igloo_sock_t sock);
|
||||
|
||||
/* Connection related socket functions */
|
||||
sock_t igloo_sock_connect_wto(const char *hostname, int port, int timeout);
|
||||
sock_t igloo_sock_connect_wto_bind(const char *hostname, int port, const char *bnd, int timeout);
|
||||
sock_t igloo_sock_connect_non_blocking(const char *host, unsigned port);
|
||||
int igloo_sock_connected(sock_t sock, int timeout);
|
||||
igloo_sock_t igloo_sock_connect_wto(const char *hostname, int port, int timeout);
|
||||
igloo_sock_t igloo_sock_connect_wto_bind(const char *hostname, int port, const char *bnd, int timeout);
|
||||
igloo_sock_t igloo_sock_connect_non_blocking(const char *host, unsigned port);
|
||||
int igloo_sock_connected(igloo_sock_t sock, int timeout);
|
||||
|
||||
/* Socket write functions */
|
||||
int igloo_sock_write_bytes(sock_t sock, const void *buff, size_t len);
|
||||
int igloo_sock_write(sock_t sock, const char *fmt, ...);
|
||||
int igloo_sock_write_fmt(sock_t sock, const char *fmt, va_list ap);
|
||||
int igloo_sock_write_string(sock_t sock, const char *buff);
|
||||
ssize_t igloo_sock_writev (sock_t sock, const struct iovec *iov, size_t count);
|
||||
int igloo_sock_write_bytes(igloo_sock_t sock, const void *buff, size_t len);
|
||||
int igloo_sock_write(igloo_sock_t sock, const char *fmt, ...);
|
||||
int igloo_sock_write_fmt(igloo_sock_t sock, const char *fmt, va_list ap);
|
||||
int igloo_sock_write_string(igloo_sock_t sock, const char *buff);
|
||||
ssize_t igloo_sock_writev (igloo_sock_t sock, const struct iovec *iov, size_t count);
|
||||
|
||||
|
||||
/* Socket read functions */
|
||||
int igloo_sock_read_bytes(sock_t sock, char *buff, size_t len);
|
||||
int igloo_sock_read_line(sock_t sock, char *string, const int len);
|
||||
int igloo_sock_read_bytes(igloo_sock_t sock, char *buff, size_t len);
|
||||
int igloo_sock_read_line(igloo_sock_t sock, char *string, const int len);
|
||||
|
||||
/* server socket functions */
|
||||
sock_t igloo_sock_get_server_socket(int port, const char *sinterface);
|
||||
int igloo_sock_listen(sock_t serversock, int backlog);
|
||||
sock_t igloo_sock_accept(sock_t serversock, char *ip, size_t len);
|
||||
igloo_sock_t igloo_sock_get_server_socket(int port, const char *sinterface);
|
||||
int igloo_sock_listen(igloo_sock_t serversock, int backlog);
|
||||
igloo_sock_t igloo_sock_accept(igloo_sock_t serversock, char *ip, size_t len);
|
||||
|
||||
#ifdef _WIN32
|
||||
int inet_aton(const char *s, struct in_addr *a);
|
||||
|
138
thread/thread.c
138
thread/thread.c
@ -86,19 +86,19 @@ typedef struct thread_start_tag {
|
||||
/* the other stuff we need to make sure this thread is inserted into
|
||||
** the thread tree
|
||||
*/
|
||||
thread_type *thread;
|
||||
igloo_thread_type *thread;
|
||||
pthread_t sys_thread;
|
||||
} thread_start_t;
|
||||
|
||||
static long igloo__next_thread_id = 0;
|
||||
static int igloo__initialized = 0;
|
||||
static avl_tree *igloo__threadtree = NULL;
|
||||
static igloo_avl_tree *igloo__threadtree = NULL;
|
||||
|
||||
#ifdef DEBUG_MUTEXES
|
||||
static mutex_t igloo__threadtree_mutex = { -1, NULL, MUTEX_STATE_UNINIT, NULL, -1,
|
||||
static igloo_mutex_t igloo__threadtree_mutex = { -1, NULL, igloo_MUTEX_STATE_UNINIT, NULL, -1,
|
||||
PTHREAD_MUTEX_INITIALIZER};
|
||||
#else
|
||||
static mutex_t igloo__threadtree_mutex = { PTHREAD_MUTEX_INITIALIZER };
|
||||
static igloo_mutex_t igloo__threadtree_mutex = { PTHREAD_MUTEX_INITIALIZER };
|
||||
#endif
|
||||
|
||||
|
||||
@ -107,16 +107,16 @@ static mutex_t igloo__threadtree_mutex = { PTHREAD_MUTEX_INITIALIZER };
|
||||
static int _logid = -1;
|
||||
static long _next_mutex_id = 0;
|
||||
|
||||
static avl_tree *_mutextree = NULL;
|
||||
static mutex_t _mutextree_mutex = { -1, NULL, MUTEX_STATE_UNINIT, NULL, -1,
|
||||
static igloo_avl_tree *_mutextree = NULL;
|
||||
static igloo_mutex_t _mutextree_mutex = { -1, NULL, igloo_MUTEX_STATE_UNINIT, NULL, -1,
|
||||
PTHREAD_MUTEX_INITIALIZER};
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG_MUTEXES
|
||||
static mutex_t igloo__library_mutex = { -1, NULL, MUTEX_STATE_UNINIT, NULL, -1,
|
||||
static igloo_mutex_t igloo__library_mutex = { -1, NULL, igloo_MUTEX_STATE_UNINIT, NULL, -1,
|
||||
PTHREAD_MUTEX_INITIALIZER};
|
||||
#else
|
||||
static mutex_t igloo__library_mutex = { PTHREAD_MUTEX_INITIALIZER };
|
||||
static igloo_mutex_t igloo__library_mutex = { PTHREAD_MUTEX_INITIALIZER };
|
||||
#endif
|
||||
|
||||
/* INTERNAL FUNCTIONS */
|
||||
@ -131,9 +131,9 @@ static int igloo__compare_threads(void *compare_arg, void *a, void *b);
|
||||
static int igloo__free_thread(void *key);
|
||||
|
||||
/* mutex fuctions */
|
||||
static void _mutex_create(mutex_t *mutex);
|
||||
static void _mutex_lock(mutex_t *mutex);
|
||||
static void _mutex_unlock(mutex_t *mutex);
|
||||
static void _mutex_create(igloo_mutex_t *mutex);
|
||||
static void _mutex_lock(igloo_mutex_t *mutex);
|
||||
static void _mutex_unlock(igloo_mutex_t *mutex);
|
||||
|
||||
/* misc thread stuff */
|
||||
static void *igloo__start_routine(void *arg);
|
||||
@ -144,7 +144,7 @@ static void _block_signals(void);
|
||||
|
||||
void igloo_thread_initialize(void)
|
||||
{
|
||||
thread_type *thread;
|
||||
igloo_thread_type *thread;
|
||||
|
||||
/* set up logging */
|
||||
|
||||
@ -175,7 +175,7 @@ void igloo_thread_initialize(void)
|
||||
|
||||
igloo__threadtree = igloo_avl_tree_new(igloo__compare_threads, NULL);
|
||||
|
||||
thread = (thread_type *)malloc(sizeof(thread_type));
|
||||
thread = (igloo_thread_type *)malloc(sizeof(igloo_thread_type));
|
||||
|
||||
thread->thread_id = igloo__next_thread_id++;
|
||||
thread->line = 0;
|
||||
@ -268,14 +268,14 @@ static void _catch_signals(void)
|
||||
}
|
||||
|
||||
|
||||
thread_type *igloo_thread_create_c(char *name, void *(*start_routine)(void *),
|
||||
igloo_thread_type *igloo_thread_create_c(char *name, void *(*start_routine)(void *),
|
||||
void *arg, int detached, int line, char *file)
|
||||
{
|
||||
thread_type *thread = NULL;
|
||||
igloo_thread_type *thread = NULL;
|
||||
thread_start_t *start = NULL;
|
||||
pthread_attr_t attr;
|
||||
|
||||
thread = (thread_type *)calloc(1, sizeof(thread_type));
|
||||
thread = (igloo_thread_type *)calloc(1, sizeof(igloo_thread_type));
|
||||
do {
|
||||
if (thread == NULL)
|
||||
break;
|
||||
@ -333,17 +333,17 @@ thread_type *igloo_thread_create_c(char *name, void *(*start_routine)(void *),
|
||||
**
|
||||
** creates a mutex
|
||||
*/
|
||||
static void _mutex_create(mutex_t *mutex)
|
||||
static void _mutex_create(igloo_mutex_t *mutex)
|
||||
{
|
||||
#ifdef DEBUG_MUTEXES
|
||||
mutex->thread_id = MUTEX_STATE_NEVERLOCKED;
|
||||
mutex->thread_id = igloo_MUTEX_STATE_NEVERLOCKED;
|
||||
mutex->line = -1;
|
||||
#endif
|
||||
|
||||
pthread_mutex_init(&mutex->sys_mutex, NULL);
|
||||
}
|
||||
|
||||
void igloo_thread_mutex_create_c(mutex_t *mutex, int line, char *file)
|
||||
void igloo_thread_mutex_create_c(igloo_mutex_t *mutex, int line, char *file)
|
||||
{
|
||||
_mutex_create(mutex);
|
||||
|
||||
@ -355,7 +355,7 @@ void igloo_thread_mutex_create_c(mutex_t *mutex, int line, char *file)
|
||||
#endif
|
||||
}
|
||||
|
||||
void igloo_thread_mutex_destroy (mutex_t *mutex)
|
||||
void igloo_thread_mutex_destroy (igloo_mutex_t *mutex)
|
||||
{
|
||||
pthread_mutex_destroy(&mutex->sys_mutex);
|
||||
|
||||
@ -366,10 +366,10 @@ void igloo_thread_mutex_destroy (mutex_t *mutex)
|
||||
#endif
|
||||
}
|
||||
|
||||
void igloo_thread_mutex_lock_c(mutex_t *mutex, int line, char *file)
|
||||
void igloo_thread_mutex_lock_c(igloo_mutex_t *mutex, int line, char *file)
|
||||
{
|
||||
#ifdef DEBUG_MUTEXES
|
||||
thread_type *th = igloo_thread_self();
|
||||
igloo_thread_type *th = igloo_thread_self();
|
||||
|
||||
if (!th) LOG_WARN("No mt record for %u in lock [%s:%d]", igloo_thread_self(), file, line);
|
||||
|
||||
@ -382,15 +382,15 @@ void igloo_thread_mutex_lock_c(mutex_t *mutex, int line, char *file)
|
||||
|
||||
if (th) {
|
||||
int locks = 0;
|
||||
avl_node *node;
|
||||
mutex_t *tmutex;
|
||||
igloo_avl_node *node;
|
||||
igloo_mutex_t *tmutex;
|
||||
|
||||
_mutex_lock(&_mutextree_mutex);
|
||||
|
||||
node = igloo_avl_get_first (_mutextree);
|
||||
|
||||
while (node) {
|
||||
tmutex = (mutex_t *)node->key;
|
||||
tmutex = (igloo_mutex_t *)node->key;
|
||||
|
||||
if (tmutex->mutex_id == mutex->mutex_id) {
|
||||
if (tmutex->thread_id == th->thread_id) {
|
||||
@ -438,10 +438,10 @@ void igloo_thread_mutex_lock_c(mutex_t *mutex, int line, char *file)
|
||||
#endif /* DEBUG_MUTEXES */
|
||||
}
|
||||
|
||||
void igloo_thread_mutex_unlock_c(mutex_t *mutex, int line, char *file)
|
||||
void igloo_thread_mutex_unlock_c(igloo_mutex_t *mutex, int line, char *file)
|
||||
{
|
||||
#ifdef DEBUG_MUTEXES
|
||||
thread_type *th = igloo_thread_self();
|
||||
igloo_thread_type *th = igloo_thread_self();
|
||||
|
||||
if (!th) {
|
||||
LOG_ERROR3("No record for %u in unlock [%s:%d]", igloo_thread_self(), file, line);
|
||||
@ -454,13 +454,13 @@ void igloo_thread_mutex_unlock_c(mutex_t *mutex, int line, char *file)
|
||||
# ifdef CHECK_MUTEXES
|
||||
if (th) {
|
||||
int locks = 0;
|
||||
avl_node *node;
|
||||
mutex_t *tmutex;
|
||||
igloo_avl_node *node;
|
||||
igloo_mutex_t *tmutex;
|
||||
|
||||
_mutex_lock(&_mutextree_mutex);
|
||||
|
||||
while (node) {
|
||||
tmutex = (mutex_t *)node->key;
|
||||
tmutex = (igloo_mutex_t *)node->key;
|
||||
|
||||
if (tmutex->mutex_id == mutex->mutex_id) {
|
||||
if (tmutex->thread_id != th->thread_id) {
|
||||
@ -494,7 +494,7 @@ void igloo_thread_mutex_unlock_c(mutex_t *mutex, int line, char *file)
|
||||
LOG_DEBUG2("Unlocked %p by thread %d", mutex, th ? th->thread_id : -1);
|
||||
mutex->line = -1;
|
||||
if (mutex->thread_id == th->thread_id) {
|
||||
mutex->thread_id = MUTEX_STATE_NOTLOCKED;
|
||||
mutex->thread_id = igloo_MUTEX_STATE_NOTLOCKED;
|
||||
}
|
||||
|
||||
_mutex_unlock(&_mutextree_mutex);
|
||||
@ -503,29 +503,29 @@ void igloo_thread_mutex_unlock_c(mutex_t *mutex, int line, char *file)
|
||||
#endif /* DEBUG_MUTEXES */
|
||||
}
|
||||
|
||||
void igloo_thread_cond_create_c(cond_t *cond, int line, char *file)
|
||||
void igloo_thread_cond_create_c(igloo_cond_t *cond, int line, char *file)
|
||||
{
|
||||
pthread_cond_init(&cond->sys_cond, NULL);
|
||||
pthread_mutex_init(&cond->cond_mutex, NULL);
|
||||
}
|
||||
|
||||
void igloo_thread_cond_destroy(cond_t *cond)
|
||||
void igloo_thread_cond_destroy(igloo_cond_t *cond)
|
||||
{
|
||||
pthread_mutex_destroy(&cond->cond_mutex);
|
||||
pthread_cond_destroy(&cond->sys_cond);
|
||||
}
|
||||
|
||||
void igloo_thread_cond_signal_c(cond_t *cond, int line, char *file)
|
||||
void igloo_thread_cond_signal_c(igloo_cond_t *cond, int line, char *file)
|
||||
{
|
||||
pthread_cond_signal(&cond->sys_cond);
|
||||
}
|
||||
|
||||
void igloo_thread_cond_broadcast_c(cond_t *cond, int line, char *file)
|
||||
void igloo_thread_cond_broadcast_c(igloo_cond_t *cond, int line, char *file)
|
||||
{
|
||||
pthread_cond_broadcast(&cond->sys_cond);
|
||||
}
|
||||
|
||||
void igloo_thread_cond_timedwait_c(cond_t *cond, int millis, int line, char *file)
|
||||
void igloo_thread_cond_timedwait_c(igloo_cond_t *cond, int millis, int line, char *file)
|
||||
{
|
||||
struct timespec time;
|
||||
|
||||
@ -537,52 +537,52 @@ void igloo_thread_cond_timedwait_c(cond_t *cond, int millis, int line, char *fil
|
||||
pthread_mutex_unlock(&cond->cond_mutex);
|
||||
}
|
||||
|
||||
void igloo_thread_cond_wait_c(cond_t *cond, int line, char *file)
|
||||
void igloo_thread_cond_wait_c(igloo_cond_t *cond, int line, char *file)
|
||||
{
|
||||
pthread_mutex_lock(&cond->cond_mutex);
|
||||
pthread_cond_wait(&cond->sys_cond, &cond->cond_mutex);
|
||||
pthread_mutex_unlock(&cond->cond_mutex);
|
||||
}
|
||||
|
||||
void igloo_thread_rwlock_create_c(rwlock_t *rwlock, int line, char *file)
|
||||
void igloo_thread_rwlock_create_c(igloo_rwlock_t *rwlock, int line, char *file)
|
||||
{
|
||||
pthread_rwlock_init(&rwlock->sys_rwlock, NULL);
|
||||
}
|
||||
|
||||
void igloo_thread_rwlock_destroy(rwlock_t *rwlock)
|
||||
void igloo_thread_rwlock_destroy(igloo_rwlock_t *rwlock)
|
||||
{
|
||||
pthread_rwlock_destroy(&rwlock->sys_rwlock);
|
||||
}
|
||||
|
||||
void igloo_thread_rwlock_rlock_c(rwlock_t *rwlock, int line, char *file)
|
||||
void igloo_thread_rwlock_rlock_c(igloo_rwlock_t *rwlock, int line, char *file)
|
||||
{
|
||||
pthread_rwlock_rdlock(&rwlock->sys_rwlock);
|
||||
}
|
||||
|
||||
void igloo_thread_rwlock_wlock_c(rwlock_t *rwlock, int line, char *file)
|
||||
void igloo_thread_rwlock_wlock_c(igloo_rwlock_t *rwlock, int line, char *file)
|
||||
{
|
||||
pthread_rwlock_wrlock(&rwlock->sys_rwlock);
|
||||
}
|
||||
|
||||
void igloo_thread_rwlock_unlock_c(rwlock_t *rwlock, int line, char *file)
|
||||
void igloo_thread_rwlock_unlock_c(igloo_rwlock_t *rwlock, int line, char *file)
|
||||
{
|
||||
pthread_rwlock_unlock(&rwlock->sys_rwlock);
|
||||
}
|
||||
|
||||
void igloo_thread_exit_c(long val, int line, char *file)
|
||||
{
|
||||
thread_type *th = igloo_thread_self();
|
||||
igloo_thread_type *th = igloo_thread_self();
|
||||
|
||||
#if defined(DEBUG_MUTEXES) && defined(CHECK_MUTEXES)
|
||||
if (th) {
|
||||
avl_node *node;
|
||||
mutex_t *tmutex;
|
||||
igloo_avl_node *node;
|
||||
igloo_mutex_t *tmutex;
|
||||
char name[40];
|
||||
|
||||
_mutex_lock(&_mutextree_mutex);
|
||||
|
||||
while (node) {
|
||||
tmutex = (mutex_t *)node->key;
|
||||
tmutex = (igloo_mutex_t *)node->key;
|
||||
|
||||
if (tmutex->thread_id == th->thread_id) {
|
||||
LOG_WARN("Thread %d [%s] exiting in file %s line %d, without unlocking mutex [%s]",
|
||||
@ -647,7 +647,7 @@ static void *igloo__start_routine(void *arg)
|
||||
thread_start_t *start = (thread_start_t *)arg;
|
||||
void *(*start_routine)(void *) = start->start_routine;
|
||||
void *real_arg = start->arg;
|
||||
thread_type *thread = start->thread;
|
||||
igloo_thread_type *thread = start->thread;
|
||||
|
||||
_block_signals();
|
||||
|
||||
@ -679,10 +679,10 @@ static void *igloo__start_routine(void *arg)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
thread_type *igloo_thread_self(void)
|
||||
igloo_thread_type *igloo_thread_self(void)
|
||||
{
|
||||
avl_node *node;
|
||||
thread_type *th;
|
||||
igloo_avl_node *node;
|
||||
igloo_thread_type *th;
|
||||
pthread_t sys_thread = pthread_self();
|
||||
|
||||
_mutex_lock(&igloo__threadtree_mutex);
|
||||
@ -698,7 +698,7 @@ thread_type *igloo_thread_self(void)
|
||||
node = igloo_avl_get_first(igloo__threadtree);
|
||||
|
||||
while (node) {
|
||||
th = (thread_type *)node->key;
|
||||
th = (igloo_thread_type *)node->key;
|
||||
|
||||
if (th && pthread_equal(sys_thread, th->sys_thread)) {
|
||||
_mutex_unlock(&igloo__threadtree_mutex);
|
||||
@ -719,7 +719,7 @@ thread_type *igloo_thread_self(void)
|
||||
|
||||
void igloo_thread_rename(const char *name)
|
||||
{
|
||||
thread_type *th;
|
||||
igloo_thread_type *th;
|
||||
|
||||
th = igloo_thread_self();
|
||||
if (th->name) free(th->name);
|
||||
@ -727,12 +727,12 @@ void igloo_thread_rename(const char *name)
|
||||
th->name = strdup(name);
|
||||
}
|
||||
|
||||
static void _mutex_lock(mutex_t *mutex)
|
||||
static void _mutex_lock(igloo_mutex_t *mutex)
|
||||
{
|
||||
pthread_mutex_lock(&mutex->sys_mutex);
|
||||
}
|
||||
|
||||
static void _mutex_unlock(mutex_t *mutex)
|
||||
static void _mutex_unlock(igloo_mutex_t *mutex)
|
||||
{
|
||||
pthread_mutex_unlock(&mutex->sys_mutex);
|
||||
}
|
||||
@ -748,7 +748,7 @@ void igloo_thread_library_unlock(void)
|
||||
_mutex_unlock(&igloo__library_mutex);
|
||||
}
|
||||
|
||||
void igloo_thread_join(thread_type *thread)
|
||||
void igloo_thread_join(igloo_thread_type *thread)
|
||||
{
|
||||
void *ret;
|
||||
|
||||
@ -763,10 +763,10 @@ void igloo_thread_join(thread_type *thread)
|
||||
#ifdef DEBUG_MUTEXES
|
||||
static int _compare_mutexes(void *compare_arg, void *a, void *b)
|
||||
{
|
||||
mutex_t *m1, *m2;
|
||||
igloo_mutex_t *m1, *m2;
|
||||
|
||||
m1 = (mutex_t *)a;
|
||||
m2 = (mutex_t *)b;
|
||||
m1 = (igloo_mutex_t *)a;
|
||||
m2 = (igloo_mutex_t *)b;
|
||||
|
||||
if (m1->mutex_id > m2->mutex_id)
|
||||
return 1;
|
||||
@ -778,10 +778,10 @@ static int _compare_mutexes(void *compare_arg, void *a, void *b)
|
||||
|
||||
static int igloo__compare_threads(void *compare_arg, void *a, void *b)
|
||||
{
|
||||
thread_type *t1, *t2;
|
||||
igloo_thread_type *t1, *t2;
|
||||
|
||||
t1 = (thread_type *)a;
|
||||
t2 = (thread_type *)b;
|
||||
t1 = (igloo_thread_type *)a;
|
||||
t2 = (igloo_thread_type *)b;
|
||||
|
||||
if (t1->thread_id > t2->thread_id)
|
||||
return 1;
|
||||
@ -793,9 +793,9 @@ static int igloo__compare_threads(void *compare_arg, void *a, void *b)
|
||||
#ifdef DEBUG_MUTEXES
|
||||
static int _free_mutex(void *key)
|
||||
{
|
||||
mutex_t *m;
|
||||
igloo_mutex_t *m;
|
||||
|
||||
m = (mutex_t *)key;
|
||||
m = (igloo_mutex_t *)key;
|
||||
|
||||
if (m && m->file) {
|
||||
free(m->file);
|
||||
@ -810,9 +810,9 @@ static int _free_mutex(void *key)
|
||||
|
||||
static int igloo__free_thread(void *key)
|
||||
{
|
||||
thread_type *t;
|
||||
igloo_thread_type *t;
|
||||
|
||||
t = (thread_type *)key;
|
||||
t = (igloo_thread_type *)key;
|
||||
|
||||
if (t->file)
|
||||
free(t->file);
|
||||
@ -826,26 +826,26 @@ static int igloo__free_thread(void *key)
|
||||
|
||||
|
||||
#ifdef HAVE_PTHREAD_SPIN_LOCK
|
||||
void igloo_thread_spin_create (spin_t *spin)
|
||||
void igloo_thread_spin_create (igloo_spin_t *spin)
|
||||
{
|
||||
int x = pthread_spin_init (&spin->lock, PTHREAD_PROCESS_PRIVATE);
|
||||
if (x)
|
||||
abort();
|
||||
}
|
||||
|
||||
void igloo_thread_spin_destroy (spin_t *spin)
|
||||
void igloo_thread_spin_destroy (igloo_spin_t *spin)
|
||||
{
|
||||
pthread_spin_destroy (&spin->lock);
|
||||
}
|
||||
|
||||
void igloo_thread_spin_lock (spin_t *spin)
|
||||
void igloo_thread_spin_lock (igloo_spin_t *spin)
|
||||
{
|
||||
int x = pthread_spin_lock (&spin->lock);
|
||||
if (x != 0)
|
||||
abort();
|
||||
}
|
||||
|
||||
void igloo_thread_spin_unlock (spin_t *spin)
|
||||
void igloo_thread_spin_unlock (igloo_spin_t *spin)
|
||||
{
|
||||
pthread_spin_unlock (&spin->lock);
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ typedef struct {
|
||||
|
||||
/* the system specific thread */
|
||||
pthread_t sys_thread;
|
||||
} thread_type;
|
||||
} igloo_thread_type;
|
||||
|
||||
typedef struct {
|
||||
#ifdef DEBUG_MUTEXES
|
||||
@ -67,7 +67,7 @@ typedef struct {
|
||||
|
||||
/* the system specific mutex */
|
||||
pthread_mutex_t sys_mutex;
|
||||
} mutex_t;
|
||||
} igloo_mutex_t;
|
||||
|
||||
typedef struct {
|
||||
#ifdef THREAD_DEBUG
|
||||
@ -77,7 +77,7 @@ typedef struct {
|
||||
|
||||
pthread_mutex_t cond_mutex;
|
||||
pthread_cond_t sys_cond;
|
||||
} cond_t;
|
||||
} igloo_cond_t;
|
||||
|
||||
typedef struct {
|
||||
#ifdef THREAD_DEBUG
|
||||
@ -93,20 +93,20 @@ typedef struct {
|
||||
#endif
|
||||
|
||||
pthread_rwlock_t sys_rwlock;
|
||||
} rwlock_t;
|
||||
} igloo_rwlock_t;
|
||||
|
||||
#ifdef HAVE_PTHREAD_SPIN_LOCK
|
||||
typedef struct
|
||||
{
|
||||
pthread_spinlock_t lock;
|
||||
} spin_t;
|
||||
} igloo_spin_t;
|
||||
|
||||
void igloo_thread_spin_create (spin_t *spin);
|
||||
void igloo_thread_spin_destroy (spin_t *spin);
|
||||
void igloo_thread_spin_lock (spin_t *spin);
|
||||
void igloo_thread_spin_unlock (spin_t *spin);
|
||||
void igloo_thread_spin_create (igloo_spin_t *spin);
|
||||
void igloo_thread_spin_destroy (igloo_spin_t *spin);
|
||||
void igloo_thread_spin_lock (igloo_spin_t *spin);
|
||||
void igloo_thread_spin_unlock (igloo_spin_t *spin);
|
||||
#else
|
||||
typedef mutex_t spin_t;
|
||||
typedef igloo_mutex_t igloo_spin_t;
|
||||
#define igloo_thread_spin_create(x) thread_mutex_create(x)
|
||||
#define igloo_thread_spin_destroy(x) igloo_thread_mutex_destroy(x)
|
||||
#define igloo_thread_spin_lock(x) thread_mutex_lock(x)
|
||||
@ -128,11 +128,11 @@ typedef mutex_t spin_t;
|
||||
#define thread_rwlock_unlock(x) igloo_thread_rwlock_unlock_c(x,__LINE__,__FILE__)
|
||||
#define thread_exit(x) igloo_thread_exit_c(x,__LINE__,__FILE__)
|
||||
|
||||
#define MUTEX_STATE_NOTLOCKED -1
|
||||
#define MUTEX_STATE_NEVERLOCKED -2
|
||||
#define MUTEX_STATE_UNINIT -3
|
||||
#define THREAD_DETACHED 1
|
||||
#define THREAD_ATTACHED 0
|
||||
#define igloo_MUTEX_STATE_NOTLOCKED -1
|
||||
#define igloo_MUTEX_STATE_NEVERLOCKED -2
|
||||
#define igloo_MUTEX_STATE_UNINIT -3
|
||||
#define igloo_THREAD_DETACHED 1
|
||||
#define igloo_THREAD_ATTACHED 0
|
||||
|
||||
/* init/shutdown of the library */
|
||||
void igloo_thread_initialize(void);
|
||||
@ -140,23 +140,23 @@ void thread_initialize_with_log_id(int log_id);
|
||||
void igloo_thread_shutdown(void);
|
||||
|
||||
/* creation, destruction, locking, unlocking, signalling and waiting */
|
||||
thread_type *igloo_thread_create_c(char *name, void *(*start_routine)(void *),
|
||||
igloo_thread_type *igloo_thread_create_c(char *name, void *(*start_routine)(void *),
|
||||
void *arg, int detached, int line, char *file);
|
||||
void igloo_thread_mutex_create_c(mutex_t *mutex, int line, char *file);
|
||||
void igloo_thread_mutex_lock_c(mutex_t *mutex, int line, char *file);
|
||||
void igloo_thread_mutex_unlock_c(mutex_t *mutex, int line, char *file);
|
||||
void igloo_thread_mutex_destroy(mutex_t *mutex);
|
||||
void igloo_thread_cond_create_c(cond_t *cond, int line, char *file);
|
||||
void igloo_thread_cond_signal_c(cond_t *cond, int line, char *file);
|
||||
void igloo_thread_cond_broadcast_c(cond_t *cond, int line, char *file);
|
||||
void igloo_thread_cond_wait_c(cond_t *cond, int line, char *file);
|
||||
void igloo_thread_cond_timedwait_c(cond_t *cond, int millis, int line, char *file);
|
||||
void igloo_thread_cond_destroy(cond_t *cond);
|
||||
void igloo_thread_rwlock_create_c(rwlock_t *rwlock, int line, char *file);
|
||||
void igloo_thread_rwlock_rlock_c(rwlock_t *rwlock, int line, char *file);
|
||||
void igloo_thread_rwlock_wlock_c(rwlock_t *rwlock, int line, char *file);
|
||||
void igloo_thread_rwlock_unlock_c(rwlock_t *rwlock, int line, char *file);
|
||||
void igloo_thread_rwlock_destroy(rwlock_t *rwlock);
|
||||
void igloo_thread_mutex_create_c(igloo_mutex_t *mutex, int line, char *file);
|
||||
void igloo_thread_mutex_lock_c(igloo_mutex_t *mutex, int line, char *file);
|
||||
void igloo_thread_mutex_unlock_c(igloo_mutex_t *mutex, int line, char *file);
|
||||
void igloo_thread_mutex_destroy(igloo_mutex_t *mutex);
|
||||
void igloo_thread_cond_create_c(igloo_cond_t *cond, int line, char *file);
|
||||
void igloo_thread_cond_signal_c(igloo_cond_t *cond, int line, char *file);
|
||||
void igloo_thread_cond_broadcast_c(igloo_cond_t *cond, int line, char *file);
|
||||
void igloo_thread_cond_wait_c(igloo_cond_t *cond, int line, char *file);
|
||||
void igloo_thread_cond_timedwait_c(igloo_cond_t *cond, int millis, int line, char *file);
|
||||
void igloo_thread_cond_destroy(igloo_cond_t *cond);
|
||||
void igloo_thread_rwlock_create_c(igloo_rwlock_t *rwlock, int line, char *file);
|
||||
void igloo_thread_rwlock_rlock_c(igloo_rwlock_t *rwlock, int line, char *file);
|
||||
void igloo_thread_rwlock_wlock_c(igloo_rwlock_t *rwlock, int line, char *file);
|
||||
void igloo_thread_rwlock_unlock_c(igloo_rwlock_t *rwlock, int line, char *file);
|
||||
void igloo_thread_rwlock_destroy(igloo_rwlock_t *rwlock);
|
||||
void igloo_thread_exit_c(long val, int line, char *file);
|
||||
|
||||
/* sleeping */
|
||||
@ -168,12 +168,12 @@ void igloo_thread_library_unlock(void);
|
||||
#define PROTECT_CODE(code) { igloo_thread_library_lock(); code; igloo_thread_library_unlock(); }
|
||||
|
||||
/* thread information functions */
|
||||
thread_type *igloo_thread_self(void);
|
||||
igloo_thread_type *igloo_thread_self(void);
|
||||
|
||||
/* renames current thread */
|
||||
void igloo_thread_rename(const char *name);
|
||||
|
||||
/* waits until thread_exit is called for another thread */
|
||||
void igloo_thread_join(thread_type *thread);
|
||||
void igloo_thread_join(igloo_thread_type *thread);
|
||||
|
||||
#endif /* __THREAD_H__ */
|
||||
|
Loading…
Reference in New Issue
Block a user