version 1.5, 2012/03/29 01:31:34
|
version 1.5.2.4, 2012/04/02 09:10:31
|
Line 47 SUCH DAMAGE.
|
Line 47 SUCH DAMAGE.
|
|
|
|
|
/* |
/* |
* io_vars2buffer() Marshaling data from array with variables to buffer | * io_vars2buffer() - Marshaling data from array with variables to buffer |
* |
* |
* @buf = Buffer |
* @buf = Buffer |
* @buflen = Size of buffer |
* @buflen = Size of buffer |
Line 86 io_vars2buffer(u_char *buf, int buflen, array_t *vars)
|
Line 86 io_vars2buffer(u_char *buf, int buflen, array_t *vars)
|
val = io_array(vars, i, ait_val_t*); |
val = io_array(vars, i, ait_val_t*); |
|
|
v[i].val_type = val->val_type; |
v[i].val_type = val->val_type; |
AIT_HASH(&v[i]) = htobe16(AIT_HASH(val)); | AIT_KEY(&v[i]) = htobe16(AIT_KEY(val)); |
AIT_LEN(&v[i]) = htobe32(AIT_LEN(val)); |
AIT_LEN(&v[i]) = htobe32(AIT_LEN(val)); |
|
|
switch (AIT_TYPE(val)) { |
switch (AIT_TYPE(val)) { |
Line 141 io_vars2buffer(u_char *buf, int buflen, array_t *vars)
|
Line 141 io_vars2buffer(u_char *buf, int buflen, array_t *vars)
|
} |
} |
|
|
/* |
/* |
* io_buffer2vars() De-marshaling data from buffer to array with variables | * io_buffer2vars() - De-marshaling data from buffer to array with variables |
* |
* |
* @buf = Buffer |
* @buf = Buffer |
* @buflen = Size of buffer |
* @buflen = Size of buffer |
Line 193 io_buffer2vars(u_char *buf, int buflen, int vnum, int
|
Line 193 io_buffer2vars(u_char *buf, int buflen, int vnum, int
|
val->val_type = v[i].val_type; |
val->val_type = v[i].val_type; |
#if defined(__OpenBSD__) |
#if defined(__OpenBSD__) |
AIT_LEN(val) = betoh32(AIT_LEN(&v[i])); |
AIT_LEN(val) = betoh32(AIT_LEN(&v[i])); |
AIT_HASH(val) = betoh16(AIT_HASH(&v[i])); | AIT_KEY(val) = betoh16(AIT_KEY(&v[i])); |
#else |
#else |
AIT_LEN(val) = be32toh(AIT_LEN(&v[i])); |
AIT_LEN(val) = be32toh(AIT_LEN(&v[i])); |
AIT_HASH(val) = be16toh(AIT_HASH(&v[i])); | AIT_KEY(val) = be16toh(AIT_KEY(&v[i])); |
#endif |
#endif |
|
|
switch (AIT_TYPE(val)) { |
switch (AIT_TYPE(val)) { |
Line 261 io_buffer2vars(u_char *buf, int buflen, int vnum, int
|
Line 261 io_buffer2vars(u_char *buf, int buflen, int vnum, int
|
/* buffer marshaling without swapping bytes to network order */ |
/* buffer marshaling without swapping bytes to network order */ |
|
|
/* |
/* |
* io_vars2map() Marshaling data from array with variables to memory map | * io_vars2map() - Marshaling data from array with variables to memory map |
* |
* |
* @buf = Buffer |
* @buf = Buffer |
* @buflen = Size of buffer |
* @buflen = Size of buffer |
Line 300 io_vars2map(u_char *buf, int buflen, array_t *vars)
|
Line 300 io_vars2map(u_char *buf, int buflen, array_t *vars)
|
val = io_array(vars, i, ait_val_t*); |
val = io_array(vars, i, ait_val_t*); |
|
|
v[i].val_type = val->val_type; |
v[i].val_type = val->val_type; |
AIT_HASH(&v[i]) = AIT_HASH(val); | AIT_KEY(&v[i]) = AIT_KEY(val); |
AIT_LEN(&v[i]) = AIT_LEN(val); |
AIT_LEN(&v[i]) = AIT_LEN(val); |
|
|
switch (AIT_TYPE(val)) { |
switch (AIT_TYPE(val)) { |
Line 355 io_vars2map(u_char *buf, int buflen, array_t *vars)
|
Line 355 io_vars2map(u_char *buf, int buflen, array_t *vars)
|
} |
} |
|
|
/* |
/* |
* io_map2vars() De-marshaling data from memory map to array with variables | * io_map2vars() - De-marshaling data from memory map to array with variables |
* |
* |
* @buf = Buffer |
* @buf = Buffer |
* @buflen = Size of buffer |
* @buflen = Size of buffer |
Line 405 io_map2vars(u_char *buf, int buflen, int vnum, int zcp
|
Line 405 io_map2vars(u_char *buf, int buflen, int vnum, int zcp
|
io_arraySet(vars, i, val); |
io_arraySet(vars, i, val); |
|
|
val->val_type = v[i].val_type; |
val->val_type = v[i].val_type; |
AIT_HASH(val) = AIT_HASH(&v[i]); | AIT_KEY(val) = AIT_KEY(&v[i]); |
AIT_LEN(val) = AIT_LEN(&v[i]); |
AIT_LEN(val) = AIT_LEN(&v[i]); |
|
|
switch (AIT_TYPE(val)) { |
switch (AIT_TYPE(val)) { |
Line 465 io_map2vars(u_char *buf, int buflen, int vnum, int zcp
|
Line 465 io_map2vars(u_char *buf, int buflen, int vnum, int zcp
|
|
|
|
|
/* |
/* |
* io_allocVars() Allocate ait_val_t array | * io_allocVars() - Allocate ait_val_t array |
* |
* |
* @varnum = Number of variables |
* @varnum = Number of variables |
* return: =NULL error or !=NULL allocated array |
* return: =NULL error or !=NULL allocated array |
Line 496 io_allocVars(int varnum)
|
Line 496 io_allocVars(int varnum)
|
} |
} |
|
|
/* |
/* |
* io_clrVars() Clear ait_val_t elements from array | * io_clrVars() - Clear ait_val_t elements from array |
* |
* |
* @vars = Variable array |
* @vars = Variable array |
* return: -1 error or size of array |
* return: -1 error or size of array |
Line 518 io_clrVars(array_t * __restrict vars)
|
Line 518 io_clrVars(array_t * __restrict vars)
|
} |
} |
|
|
/* |
/* |
* io_freeVars() Free ait_val_t array | * io_freeVars() - Free ait_val_t array |
* |
* |
* @vars = Variable array |
* @vars = Variable array |
* return: none |
* return: none |
Line 535 io_freeVars(array_t ** __restrict vars)
|
Line 535 io_freeVars(array_t ** __restrict vars)
|
} |
} |
|
|
/* |
/* |
* io_allocVar() Allocate memory for variable | * io_allocVar() - Allocate memory for variable |
* |
* |
* return: NULL error or new variable, after use free variable with io_freeVar() |
* return: NULL error or new variable, after use free variable with io_freeVar() |
*/ |
*/ |
Line 556 io_allocVar(void)
|
Line 556 io_allocVar(void)
|
} |
} |
|
|
/* |
/* |
* io_freeVar() Free allocated memory for variable | * io_freeVar() - Free allocated memory for variable |
* |
* |
* @val = Variable |
* @val = Variable |
* return: none |
* return: none |
Line 569 io_freeVar(ait_val_t * __restrict val)
|
Line 569 io_freeVar(ait_val_t * __restrict val)
|
free(val); |
free(val); |
val = NULL; |
val = NULL; |
} |
} |
|
} |
|
|
|
static int |
|
_cmp_arr_key_asc(const void *a, const void *b) |
|
{ |
|
return AIT_KEY(*(ait_val_t**) a) - AIT_KEY(*(ait_val_t**) b); |
|
} |
|
|
|
static int |
|
_cmp_arr_key_desc(const void *a, const void *b) |
|
{ |
|
return AIT_KEY(*(ait_val_t**) b) - AIT_KEY(*(ait_val_t**) a); |
|
} |
|
|
|
/* |
|
* io_sortVars() - Sorting array with variables |
|
* |
|
* @vars = Variable array |
|
* @order = Sort order. If =0 ascend or !=0 descend |
|
* @cmp = Compare function for sorting. If =NULL compare by key |
|
* return: none |
|
*/ |
|
inline void |
|
io_sortVars(array_t * __restrict vars, int order, int (*cmp)(const void*, const void*)) |
|
{ |
|
if (!vars) |
|
return; |
|
|
|
if (cmp) |
|
qsort(vars->arr_data, vars->arr_num, sizeof(void*), cmp); |
|
else if (order) |
|
qsort(vars->arr_data, vars->arr_num, sizeof(void*), _cmp_arr_key_desc); |
|
else |
|
qsort(vars->arr_data, vars->arr_num, sizeof(void*), _cmp_arr_key_asc); |
|
} |
|
|
|
/* |
|
* io_findKeyVars() - Find variable by key from array |
|
* |
|
* @vars = Variables |
|
* @key = Search key |
|
* return: NULL error or not found, !=NULL valid element |
|
*/ |
|
ait_val_t * |
|
io_findKeyVars(array_t * __restrict vars, u_short key) |
|
{ |
|
array_t *tmp; |
|
ait_val_t **vv, *v = NULL; |
|
register int i; |
|
const u_char *p; |
|
|
|
if (!vars) |
|
return NULL; |
|
|
|
if (io_arrayCopy(&tmp, vars) == -1) |
|
return NULL; |
|
else |
|
qsort(tmp->arr_data, tmp->arr_num, sizeof(void*), _cmp_arr_key_asc); |
|
|
|
/* binary search */ |
|
for (p = (const u_char*) tmp->arr_data, i = io_arraySize(tmp); i; i >>= 1) { |
|
vv = (ait_val_t**) (p + (i >> 1) * sizeof(void*)); |
|
if (!(key - AIT_KEY(*vv))) { /* found! */ |
|
v = *vv; |
|
break; |
|
} |
|
if ((key - AIT_KEY(*vv)) > 0) { /* move right key > current */ |
|
p = (const u_char*) vv + sizeof(void*); |
|
i--; |
|
} /* else move left */ |
|
} |
|
|
|
io_arrayDestroy(&tmp); |
|
return v; |
} |
} |