--- libaitio/inc/aitio.h 2012/03/29 01:31:33 1.16 +++ libaitio/inc/aitio.h 2012/04/02 08:10:57 1.16.2.4 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: aitio.h,v 1.16 2012/03/29 01:31:33 misho Exp $ +* $Id: aitio.h,v 1.16.2.4 2012/04/02 08:10:57 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -91,7 +91,7 @@ typedef enum { typedef struct { uint8_t val_type; uint8_t val_pad; - uint16_t val_hash; + uint16_t val_key; uint32_t val_len; union { uint64_t net; @@ -116,13 +116,13 @@ typedef struct { #define AIT_TYPE(_vl) ((ait_type_t) (_vl)->val_type) #define AIT_LEN(_vl) (_vl)->val_len -#define AIT_HASH(_vl) (_vl)->val_hash +#define AIT_KEY(_vl) (_vl)->val_key #define AIT_RAW(_vl) (_vl)->val.net #define AIT_VOID(_vl) (_vl)->val.ptr #define AIT_BLOB_CHUNKS(_vl, _n) (assert((_vl)), AIT_LEN((_vl)) / _n + (AIT_LEN((_vl)) % _n) ? 1 : 0) #define AIT_ISEMPTY(_vl) (assert((_vl)), AIT_TYPE((_vl)) == empty) -#define AIT_GET_LIKE(_vl, _type) (assert((_vl)), (_type) (_vl)->val.ptr) +#define AIT_GET_LIKE(_vl, _type) ((_type) ((_vl) ? (_vl)->val.ptr : NULL)) #define AIT_GET_PTR(_vl) (assert((_vl)), assert(AIT_TYPE((_vl)) == ptr), (_vl)->val.ptr) #define AIT_GET_DATA(_vl) (assert((_vl)), assert(AIT_TYPE((_vl)) == data), (_vl)->val_data) @@ -166,11 +166,13 @@ typedef struct { } } while (0) #define AIT_SET_STRCAT(_vl, _v) do { ait_val_t *__val = (_vl); assert(__val); \ assert(AIT_TYPE(__val) == string); \ - void *__p = realloc(AIT_LEN(__val) + strlen((_v))); \ + void *__p = realloc(__val->val.string, \ + AIT_LEN(__val) + strlen((_v))); \ if (__p) { \ __val->val.string = __p; \ AIT_LEN(__val) += strlen((_v)); \ - strlcat(__val->val.string, (_v), AIT_LEN(__val)); \ + strlcat((char*) __val->val.string, (_v), \ + AIT_LEN(__val)); \ } } while (0) #define AIT_SET_BLOB(_vl, _n, _len) do { ait_val_t *__val = (_vl); assert(__val); \ __val->val_type = blob; AIT_LEN(__val) = _len; \ @@ -375,6 +377,24 @@ inline int io_clrVars(array_t * __restrict vars); * return: none */ inline void io_freeVars(array_t ** __restrict vars); +/* + * io_sortVars() Sorting array with variables + * + * @vars = Variable array + * @order = Sort order. If =0 ascend ot !=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*)); +/* + * 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); /*