version 1.5.2.2, 2012/03/29 12:23:00
|
version 1.10, 2012/07/03 08:51:05
|
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 71 io_vars2buffer(u_char *buf, int buflen, array_t *vars)
|
Line 71 io_vars2buffer(u_char *buf, int buflen, array_t *vars)
|
|
|
Limit = sizeof(ait_val_t) * io_arraySize(vars); |
Limit = sizeof(ait_val_t) * io_arraySize(vars); |
if (Limit > buflen) { |
if (Limit > buflen) { |
io_SetErr(EMSGSIZE, "Error:: too short buffer buflen=%d needed min %d ...\n", | io_SetErr(EMSGSIZE, "Short buffer buflen=%d needed min %d", |
buflen, Limit); |
buflen, Limit); |
return -1; |
return -1; |
} else { |
} else { |
Line 105 io_vars2buffer(u_char *buf, int buflen, array_t *vars)
|
Line 105 io_vars2buffer(u_char *buf, int buflen, array_t *vars)
|
break; |
break; |
case data: |
case data: |
if (AIT_LEN(val) > buflen - Limit) { |
if (AIT_LEN(val) > buflen - Limit) { |
io_SetErr(EMSGSIZE, "Error:: too short buffer buflen=%d " | io_SetErr(EMSGSIZE, "Short buffer buflen=%d " |
"needed min %d ...\n", buflen, Limit + AIT_LEN(val)); | "needed min %d", buflen, Limit + AIT_LEN(val)); |
return -1; |
return -1; |
} else |
} else |
Limit += AIT_LEN(val); |
Limit += AIT_LEN(val); |
Line 119 io_vars2buffer(u_char *buf, int buflen, array_t *vars)
|
Line 119 io_vars2buffer(u_char *buf, int buflen, array_t *vars)
|
case buffer: |
case buffer: |
case string: |
case string: |
if (AIT_LEN(val) > buflen - Limit) { |
if (AIT_LEN(val) > buflen - Limit) { |
io_SetErr(EMSGSIZE, "Error:: too short buffer buflen=%d " | io_SetErr(EMSGSIZE, "Short buffer buflen=%d " |
"needed min %d ...\n", buflen, Limit + AIT_LEN(val)); | "needed min %d", buflen, Limit + AIT_LEN(val)); |
return -1; |
return -1; |
} else |
} else |
Limit += AIT_LEN(val); |
Limit += AIT_LEN(val); |
Line 131 io_vars2buffer(u_char *buf, int buflen, array_t *vars)
|
Line 131 io_vars2buffer(u_char *buf, int buflen, array_t *vars)
|
dat += AIT_LEN(val); |
dat += AIT_LEN(val); |
break; |
break; |
default: |
default: |
io_SetErr(EINVAL, "Error:: unsupported variable type=%d at element #%d ...\n", | io_SetErr(EINVAL, "Unsupported variable type=%d at element #%d", |
AIT_TYPE(val), i); |
AIT_TYPE(val), i); |
return -1; |
return -1; |
} |
} |
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 165 io_buffer2vars(u_char *buf, int buflen, int vnum, int
|
Line 165 io_buffer2vars(u_char *buf, int buflen, int vnum, int
|
|
|
Limit = sizeof(ait_val_t) * vnum; |
Limit = sizeof(ait_val_t) * vnum; |
if (Limit > buflen) { |
if (Limit > buflen) { |
io_SetErr(EMSGSIZE, "Error:: too short buffer buflen=%d needed min %d ...\n", | io_SetErr(EMSGSIZE, "Short buffer buflen=%d needed min %d", |
buflen, Limit); |
buflen, Limit); |
return NULL; |
return NULL; |
} else { |
} else { |
Line 179 io_buffer2vars(u_char *buf, int buflen, int vnum, int
|
Line 179 io_buffer2vars(u_char *buf, int buflen, int vnum, int
|
/* de-marshaling */ |
/* de-marshaling */ |
for (i = 0; i < io_arraySize(vars); i++) { |
for (i = 0; i < io_arraySize(vars); i++) { |
if (!zcpy) { |
if (!zcpy) { |
val = malloc(sizeof(ait_val_t)); | val = io_malloc(sizeof(ait_val_t)); |
if (!val) { |
if (!val) { |
LOGERR; |
LOGERR; |
io_arrayFree(vars); |
io_arrayFree(vars); |
Line 223 io_buffer2vars(u_char *buf, int buflen, int vnum, int
|
Line 223 io_buffer2vars(u_char *buf, int buflen, int vnum, int
|
case buffer: |
case buffer: |
case string: |
case string: |
if (AIT_LEN(val) > buflen - Limit) { |
if (AIT_LEN(val) > buflen - Limit) { |
io_SetErr(EMSGSIZE, "Error:: too short buffer buflen=%d " | io_SetErr(EMSGSIZE, "Short buffer buflen=%d " |
"needed min %d ...\n", buflen, Limit + AIT_LEN(val)); | "needed min %d", buflen, Limit + AIT_LEN(val)); |
if (!zcpy) |
if (!zcpy) |
io_arrayFree(vars); |
io_arrayFree(vars); |
io_arrayDestroy(&vars); |
io_arrayDestroy(&vars); |
Line 233 io_buffer2vars(u_char *buf, int buflen, int vnum, int
|
Line 233 io_buffer2vars(u_char *buf, int buflen, int vnum, int
|
Limit += AIT_LEN(val); |
Limit += AIT_LEN(val); |
|
|
if (!zcpy) { |
if (!zcpy) { |
val->val.buffer = malloc(AIT_LEN(val)); | val->val.buffer = io_malloc(AIT_LEN(val)); |
if (!val->val.buffer) { |
if (!val->val.buffer) { |
LOGERR; |
LOGERR; |
io_arrayFree(vars); |
io_arrayFree(vars); |
Line 246 io_buffer2vars(u_char *buf, int buflen, int vnum, int
|
Line 246 io_buffer2vars(u_char *buf, int buflen, int vnum, int
|
dat += AIT_LEN(val); |
dat += AIT_LEN(val); |
break; |
break; |
default: |
default: |
io_SetErr(EINVAL, "Error:: unsupported variable type=%d at element #%d ...\n", | io_SetErr(EINVAL, "Unsupported variable type=%d at element #%d", |
AIT_TYPE(val), i); |
AIT_TYPE(val), i); |
if (!zcpy) |
if (!zcpy) |
io_arrayFree(vars); |
io_arrayFree(vars); |
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 285 io_vars2map(u_char *buf, int buflen, array_t *vars)
|
Line 285 io_vars2map(u_char *buf, int buflen, array_t *vars)
|
|
|
Limit = sizeof(ait_val_t) * io_arraySize(vars); |
Limit = sizeof(ait_val_t) * io_arraySize(vars); |
if (Limit > buflen) { |
if (Limit > buflen) { |
io_SetErr(EMSGSIZE, "Error:: too short buffer buflen=%d needed min %d ...\n", | io_SetErr(EMSGSIZE, "Short buffer buflen=%d needed min %d", |
buflen, Limit); |
buflen, Limit); |
return -1; |
return -1; |
} else { |
} else { |
Line 319 io_vars2map(u_char *buf, int buflen, array_t *vars)
|
Line 319 io_vars2map(u_char *buf, int buflen, array_t *vars)
|
break; |
break; |
case data: |
case data: |
if (AIT_LEN(val) > buflen - Limit) { |
if (AIT_LEN(val) > buflen - Limit) { |
io_SetErr(EMSGSIZE, "Error:: too short buffer buflen=%d " | io_SetErr(EMSGSIZE, "Short buffer buflen=%d " |
"needed min %d ...\n", buflen, Limit + AIT_LEN(val)); | "needed min %d", buflen, Limit + AIT_LEN(val)); |
return -1; |
return -1; |
} else |
} else |
Limit += AIT_LEN(val); |
Limit += AIT_LEN(val); |
Line 333 io_vars2map(u_char *buf, int buflen, array_t *vars)
|
Line 333 io_vars2map(u_char *buf, int buflen, array_t *vars)
|
case buffer: |
case buffer: |
case string: |
case string: |
if (AIT_LEN(val) > buflen - Limit) { |
if (AIT_LEN(val) > buflen - Limit) { |
io_SetErr(EMSGSIZE, "Error:: too short buffer buflen=%d " | io_SetErr(EMSGSIZE, "Short buffer buflen=%d " |
"needed min %d ...\n", buflen, Limit + AIT_LEN(val)); | "needed min %d", buflen, Limit + AIT_LEN(val)); |
return -1; |
return -1; |
} else |
} else |
Limit += AIT_LEN(val); |
Limit += AIT_LEN(val); |
Line 345 io_vars2map(u_char *buf, int buflen, array_t *vars)
|
Line 345 io_vars2map(u_char *buf, int buflen, array_t *vars)
|
dat += AIT_LEN(val); |
dat += AIT_LEN(val); |
break; |
break; |
default: |
default: |
io_SetErr(EINVAL, "Error:: unsupported variable type=%d at element #%d ...\n", | io_SetErr(EINVAL, "Unsupported variable type=%d at element #%d", |
AIT_TYPE(val), i); |
AIT_TYPE(val), i); |
return -1; |
return -1; |
} |
} |
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 379 io_map2vars(u_char *buf, int buflen, int vnum, int zcp
|
Line 379 io_map2vars(u_char *buf, int buflen, int vnum, int zcp
|
|
|
Limit = sizeof(ait_val_t) * vnum; |
Limit = sizeof(ait_val_t) * vnum; |
if (Limit > buflen) { |
if (Limit > buflen) { |
io_SetErr(EMSGSIZE, "Error:: too short buffer buflen=%d needed min %d ...\n", | io_SetErr(EMSGSIZE, "Short buffer buflen=%d needed min %d", |
buflen, Limit); |
buflen, Limit); |
return NULL; |
return NULL; |
} else { |
} else { |
Line 393 io_map2vars(u_char *buf, int buflen, int vnum, int zcp
|
Line 393 io_map2vars(u_char *buf, int buflen, int vnum, int zcp
|
/* de-marshaling */ |
/* de-marshaling */ |
for (i = 0; i < io_arraySize(vars); i++) { |
for (i = 0; i < io_arraySize(vars); i++) { |
if (!zcpy) { |
if (!zcpy) { |
val = malloc(sizeof(ait_val_t)); | val = io_malloc(sizeof(ait_val_t)); |
if (!val) { |
if (!val) { |
LOGERR; |
LOGERR; |
io_arrayFree(vars); |
io_arrayFree(vars); |
Line 428 io_map2vars(u_char *buf, int buflen, int vnum, int zcp
|
Line 428 io_map2vars(u_char *buf, int buflen, int vnum, int zcp
|
case buffer: |
case buffer: |
case string: |
case string: |
if (AIT_LEN(val) > buflen - Limit) { |
if (AIT_LEN(val) > buflen - Limit) { |
io_SetErr(EMSGSIZE, "Error:: too short buffer buflen=%d " | io_SetErr(EMSGSIZE, "short buffer buflen=%d " |
"needed min %d ...\n", buflen, Limit + AIT_LEN(val)); | "needed min %d", buflen, Limit + AIT_LEN(val)); |
if (!zcpy) |
if (!zcpy) |
io_arrayFree(vars); |
io_arrayFree(vars); |
io_arrayDestroy(&vars); |
io_arrayDestroy(&vars); |
Line 438 io_map2vars(u_char *buf, int buflen, int vnum, int zcp
|
Line 438 io_map2vars(u_char *buf, int buflen, int vnum, int zcp
|
Limit += AIT_LEN(val); |
Limit += AIT_LEN(val); |
|
|
if (!zcpy) { |
if (!zcpy) { |
val->val.buffer = malloc(AIT_LEN(val)); | val->val.buffer = io_malloc(AIT_LEN(val)); |
if (!val->val.buffer) { |
if (!val->val.buffer) { |
LOGERR; |
LOGERR; |
io_arrayFree(vars); |
io_arrayFree(vars); |
Line 451 io_map2vars(u_char *buf, int buflen, int vnum, int zcp
|
Line 451 io_map2vars(u_char *buf, int buflen, int vnum, int zcp
|
dat += AIT_LEN(val); |
dat += AIT_LEN(val); |
break; |
break; |
default: |
default: |
io_SetErr(EINVAL, "Error:: unsupported variable type=%d at element #%d ...\n", | io_SetErr(EINVAL, "Unsupported variable type=%d at element #%d", |
AIT_TYPE(val), i); |
AIT_TYPE(val), i); |
if (!zcpy) |
if (!zcpy) |
io_arrayFree(vars); |
io_arrayFree(vars); |
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 477 io_allocVars(int varnum)
|
Line 477 io_allocVars(int varnum)
|
register int i; |
register int i; |
ait_val_t *v; |
ait_val_t *v; |
|
|
if (!varnum || !(arr = io_arrayInit(varnum))) | if (!(arr = io_arrayInit(varnum))) |
return NULL; |
return NULL; |
|
|
for (i = 0; i < io_arraySize(arr); i++) { |
for (i = 0; i < io_arraySize(arr); i++) { |
v = malloc(sizeof(ait_val_t)); | if (!(v = io_allocVar())) { |
if (!v) { | |
LOGERR; | |
io_freeVars(&arr); |
io_freeVars(&arr); |
return NULL; |
return NULL; |
} else { | } else |
memset(v, 0, sizeof(ait_val_t)); | |
io_arraySet(arr, i, v); |
io_arraySet(arr, i, v); |
} |
|
} |
} |
|
|
return arr; |
return arr; |
} |
} |
|
|
/* |
/* |
* io_clrVars() Clear ait_val_t elements from array | * io_getVars() - Get ait_val_t element from array and if not exists allocate it |
* |
* |
* @vars = Variable array |
* @vars = Variable array |
|
* @n = index of variable into array |
|
* return: NULL error or !=NULL ait_val_t element |
|
*/ |
|
inline ait_val_t * |
|
io_getVars(array_t ** __restrict vars, int n) |
|
{ |
|
register int i; |
|
ait_val_t *v; |
|
|
|
if (!vars) |
|
return NULL; |
|
|
|
if (!*vars) { |
|
if (!(*vars = io_allocVars(n + 1))) |
|
return NULL; |
|
} else { |
|
if (n >= (i = io_arraySize(*vars))) { |
|
if (io_arrayGrow(*vars, n + 1, 0)) |
|
return NULL; |
|
for (; i < io_arraySize(*vars); i++) |
|
if (!io_arrayGet(*vars, i)) { |
|
if (!(v = io_allocVar())) |
|
return NULL; |
|
else |
|
io_arraySet(*vars, n, v); |
|
} |
|
} |
|
} |
|
|
|
return io_array(*vars, n, ait_val_t*); |
|
} |
|
|
|
/* |
|
* io_clrVars() - Clear ait_val_t elements from array |
|
* |
|
* @vars = Variable array |
* return: -1 error or size of array |
* return: -1 error or size of array |
*/ |
*/ |
inline int |
inline int |
Line 518 io_clrVars(array_t * __restrict vars)
|
Line 550 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 567 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 544 io_allocVar(void)
|
Line 576 io_allocVar(void)
|
{ |
{ |
ait_val_t *v = NULL; |
ait_val_t *v = NULL; |
|
|
v = malloc(sizeof(ait_val_t)); | v = io_malloc(sizeof(ait_val_t)); |
if (!v) { |
if (!v) { |
LOGERR; |
LOGERR; |
return NULL; |
return NULL; |
Line 556 io_allocVar(void)
|
Line 588 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 |
*/ |
*/ |
inline void |
inline void |
io_freeVar(ait_val_t * __restrict val) | io_freeVar(ait_val_t ** __restrict val) |
{ |
{ |
if (val) { | if (val && *val) { |
AIT_FREE_VAL(val); | AIT_FREE_VAL(*val); |
free(val); | io_free(*val); |
val = NULL; | *val = NULL; |
} |
} |
} |
} |
|
|
Line 584 _cmp_arr_key_desc(const void *a, const void *b)
|
Line 616 _cmp_arr_key_desc(const void *a, const void *b)
|
} |
} |
|
|
/* |
/* |
* io_sortVars() Sorting array with variables | * io_sortVars() - Sorting array with variables |
* |
* |
* @vars = Variable array |
* @vars = Variable array |
* @order = Sort order. If =0 ascend or !=0 descend |
* @order = Sort order. If =0 ascend or !=0 descend |
Line 606 io_sortVars(array_t * __restrict vars, int order, int
|
Line 638 io_sortVars(array_t * __restrict vars, int order, int
|
} |
} |
|
|
/* |
/* |
* io_findKeyVars() Find variable by key from array | * io_findKeyVars() - Find variable by key from array |
* |
* |
* @vars = Variables |
* @vars = Variables |
* @key = Search key |
* @key = Search key |
Line 616 ait_val_t *
|
Line 648 ait_val_t *
|
io_findKeyVars(array_t * __restrict vars, u_short key) |
io_findKeyVars(array_t * __restrict vars, u_short key) |
{ |
{ |
array_t *tmp; |
array_t *tmp; |
ait_val_t **v = NULL; | ait_val_t **vv, *v = NULL; |
register int i; |
register int i; |
const u_char *p; |
const u_char *p; |
|
|
Line 630 io_findKeyVars(array_t * __restrict vars, u_short key)
|
Line 662 io_findKeyVars(array_t * __restrict vars, u_short key)
|
|
|
/* binary search */ |
/* binary search */ |
for (p = (const u_char*) tmp->arr_data, i = io_arraySize(tmp); i; i >>= 1) { |
for (p = (const u_char*) tmp->arr_data, i = io_arraySize(tmp); i; i >>= 1) { |
v = (ait_val_t**) (p + (i >> 1) * sizeof(void*)); | vv = (ait_val_t**) (p + (i >> 1) * sizeof(void*)); |
if (!(key - AIT_KEY(*v))) { /* found! */ | if (!(key - AIT_KEY(*vv))) { /* found! */ |
io_arrayDestroy(&tmp); | v = *vv; |
return *v; | break; |
} |
} |
if ((key - AIT_KEY(*v)) > 0) { /* move right key > current */ | if ((key - AIT_KEY(*vv)) > 0) { /* move right key > current */ |
p = (const u_char*) v + sizeof(void*); | p = (const u_char*) vv + sizeof(void*); |
i--; |
i--; |
} /* else move left */ |
} /* else move left */ |
} |
} |
|
|
io_arrayDestroy(&tmp); |
io_arrayDestroy(&tmp); |
return NULL; | return v; |
} |
} |