Commit d37efa1cd5832d99b1929c1e27448ebd997cc232
1 parent
990647a5
code cleanups, made naming more consisten, etc.
Showing
14 changed files
with
270 additions
and
258 deletions
| 1 | +2011-11-20 09:50:00 +0100 Georg Hopp | ||
| 2 | + | ||
| 3 | + * code cleanups, made naming more consisten, etc. (HEAD, master) | ||
| 4 | + | ||
| 1 | 2011-11-20 05:49:12 +0100 Georg Hopp | 5 | 2011-11-20 05:49:12 +0100 Georg Hopp |
| 2 | 6 | ||
| 3 | - * added a doxygen config as well as the patch for doxygen to handle my own class definitions. Changed all copyright to file scope (HEAD, master) | 7 | + * added a doxygen config as well as the patch for doxygen to handle my own class definitions. Changed all copyright to file scope (origin/master, origin/HEAD) |
| 4 | 8 | ||
| 5 | 2011-11-20 02:39:21 +0100 Georg Hopp | 9 | 2011-11-20 02:39:21 +0100 Georg Hopp |
| 6 | 10 | ||
| 7 | - * finished tests for packet (origin/master, origin/HEAD) | 11 | + * finished tests for packet |
| 8 | 12 | ||
| 9 | 2011-11-20 00:41:23 +0100 Georg Hopp | 13 | 2011-11-20 00:41:23 +0100 Georg Hopp |
| 10 | 14 |
| @@ -23,15 +23,8 @@ | @@ -23,15 +23,8 @@ | ||
| 23 | #include <sys/types.h> | 23 | #include <sys/types.h> |
| 24 | #include <json/json.h> | 24 | #include <json/json.h> |
| 25 | 25 | ||
| 26 | -#define SWAP(a, b) a ^= b; b ^= a; a ^= b; | ||
| 27 | - | ||
| 28 | #define CCLASS_MAGIC 0xFEFE | 26 | #define CCLASS_MAGIC 0xFEFE |
| 29 | 27 | ||
| 30 | -#define CLASS(_class) \ | ||
| 31 | - struct _##_class; \ | ||
| 32 | - typedef struct _##_class * _class; \ | ||
| 33 | - extern const _CCLASS const __##_class; \ | ||
| 34 | - struct _##_class | ||
| 35 | 28 | ||
| 36 | typedef void (* ctor)(void *, va_list *); | 29 | typedef void (* ctor)(void *, va_list *); |
| 37 | typedef void (* clr)(void *); | 30 | typedef void (* clr)(void *); |
| @@ -39,51 +32,65 @@ typedef void (* dtor)(void *); | @@ -39,51 +32,65 @@ typedef void (* dtor)(void *); | ||
| 39 | typedef void (* jCtor)(void *, struct json_object *); | 32 | typedef void (* jCtor)(void *, struct json_object *); |
| 40 | typedef void (* jTo)(void *, struct json_object **); | 33 | typedef void (* jTo)(void *, struct json_object **); |
| 41 | 34 | ||
| 42 | -typedef struct CCLASS { | 35 | +typedef struct _CCLASS { |
| 43 | const int magic; | 36 | const int magic; |
| 44 | size_t size; | 37 | size_t size; |
| 45 | - void (* __construct)(void * _this, va_list * params); | ||
| 46 | - void (* __clear)(void * _this); | ||
| 47 | - void (* __destruct)(void * _this); | ||
| 48 | - void (* __jsonConst)(void * _this, struct json_object * json); | ||
| 49 | - void (* __toJson)(void * _this, struct json_object ** json); | ||
| 50 | -} * _CCLASS; | ||
| 51 | -#define _CCLASS_SIZE sizeof(_CCLASS) | ||
| 52 | -#define CCLASS_SIZE sizeof(struct CCLASS) | 38 | + ctor __construct; |
| 39 | + clr __clear; | ||
| 40 | + dtor __destruct; | ||
| 41 | + jCtor __jsonConst; | ||
| 42 | + jTo __toJson; | ||
| 43 | +} * CCLASS; | ||
| 44 | + | ||
| 45 | +#define CCLASS_SIZE sizeof(struct _CCLASS) | ||
| 46 | +#define CCLASS_PTR_SIZE sizeof(CCLASS) | ||
| 53 | 47 | ||
| 54 | -#define __construct(class) static void __construct(class _this, va_list * params) | ||
| 55 | -#define __clear(class) static void __clear(class _this) | ||
| 56 | -#define __destruct(class) static void __destruct(class _this) | ||
| 57 | -#define __jsonConst(class) static void __jsonConst(class _this, struct json_object * json) | ||
| 58 | -#define __toJson(class) static void __toJson(class _this, struct json_object ** json) | 48 | +#define __construct(_class) \ |
| 49 | + static void __construct(_class this, va_list * params) | ||
| 50 | +#define __clear(_class) \ | ||
| 51 | + static void __clear(_class this) | ||
| 52 | +#define __destruct(_class) \ | ||
| 53 | + static void __destruct(_class this) | ||
| 54 | +#define __jsonConst(_class) \ | ||
| 55 | + static void __jsonConst(_class this, struct json_object * json) | ||
| 56 | +#define __toJson(_class) \ | ||
| 57 | + static void __toJson(_class this, struct json_object ** json) | ||
| 59 | 58 | ||
| 60 | -#define INIT_CCLASS(class) \ | ||
| 61 | - __construct(class); \ | ||
| 62 | - __clear(class); \ | ||
| 63 | - __destruct(class); \ | ||
| 64 | - __jsonConst(class); \ | ||
| 65 | - __toJson(class); \ | ||
| 66 | - static const struct CCLASS _class = { \ | 59 | +#define CLASS(_class) \ |
| 60 | + struct _##_class; \ | ||
| 61 | + typedef struct _##_class * _class; \ | ||
| 62 | + extern const CCLASS const __##_class; \ | ||
| 63 | + struct _##_class | ||
| 64 | + | ||
| 65 | +#define INIT_CLASS(_class) \ | ||
| 66 | + __construct(_class); \ | ||
| 67 | + __clear(_class); \ | ||
| 68 | + __destruct(_class); \ | ||
| 69 | + __jsonConst(_class); \ | ||
| 70 | + __toJson(_class); \ | ||
| 71 | + static const struct _CCLASS _cclass = { \ | ||
| 67 | CCLASS_MAGIC, \ | 72 | CCLASS_MAGIC, \ |
| 68 | - sizeof(struct _##class), \ | 73 | + sizeof(struct _##_class), \ |
| 69 | (ctor)__construct, \ | 74 | (ctor)__construct, \ |
| 70 | (clr)__clear, \ | 75 | (clr)__clear, \ |
| 71 | (dtor)__destruct, \ | 76 | (dtor)__destruct, \ |
| 72 | (jCtor)__jsonConst, \ | 77 | (jCtor)__jsonConst, \ |
| 73 | (jTo)__toJson \ | 78 | (jTo)__toJson \ |
| 74 | - }; const _CCLASS __##class = (const _CCLASS)&_class | 79 | + }; const CCLASS __##_class = (const CCLASS)&_cclass |
| 80 | + | ||
| 81 | +void * _new(const CCLASS _class, ...); | ||
| 82 | +#define new(_class, ...) _new((__##_class), __VA_ARGS__) | ||
| 83 | + | ||
| 84 | +void * _newFromJson(const CCLASS _class, struct json_object * json); | ||
| 85 | +#define newFromJson(_class, json) _newFromJson((__##_class), (json)) | ||
| 86 | + | ||
| 87 | +int _instanceOf(const CCLASS _class, void * _object); | ||
| 88 | +#define instanceOf(_class, object) _instanceOf((__##_class), (object)) | ||
| 75 | 89 | ||
| 76 | -void * _new(const _CCLASS _class, ...); | ||
| 77 | -void * _newFromJson(const _CCLASS _class, struct json_object * json); | ||
| 78 | void clear(void * _object); | 90 | void clear(void * _object); |
| 79 | void delete(void * _object); | 91 | void delete(void * _object); |
| 80 | void toJson(void * _object, struct json_object ** json); | 92 | void toJson(void * _object, struct json_object ** json); |
| 81 | int isObject(void * _object); | 93 | int isObject(void * _object); |
| 82 | -int _instanceOf(const _CCLASS _class, void * _object); | ||
| 83 | - | ||
| 84 | -#define new(class, ...) _new((__##class), __VA_ARGS__) | ||
| 85 | -#define newFromJson(class, json) _newFromJson((__##class), (json)) | ||
| 86 | -#define instanceOf(class, object) _instanceOf((__##class), (object)) | ||
| 87 | 94 | ||
| 88 | #endif//__CCLASS_H__ | 95 | #endif//__CCLASS_H__ |
| 89 | 96 |
| @@ -25,7 +25,7 @@ | @@ -25,7 +25,7 @@ | ||
| 25 | 25 | ||
| 26 | 26 | ||
| 27 | CLASS(CRYPT) { | 27 | CLASS(CRYPT) { |
| 28 | - const _CCLASS const class; | 28 | + const CCLASS const class; |
| 29 | const char * algorithm; | 29 | const char * algorithm; |
| 30 | const char * mode; | 30 | const char * mode; |
| 31 | MCRYPT mcrypt; | 31 | MCRYPT mcrypt; |
| @@ -35,21 +35,21 @@ CLASS(CRYPT) { | @@ -35,21 +35,21 @@ CLASS(CRYPT) { | ||
| 35 | }; | 35 | }; |
| 36 | 36 | ||
| 37 | void * crypt_encrypt( | 37 | void * crypt_encrypt( |
| 38 | - CRYPT _this, | 38 | + CRYPT this, |
| 39 | const void * const data, | 39 | const void * const data, |
| 40 | const char * const password, | 40 | const char * const password, |
| 41 | size_t * length); | 41 | size_t * length); |
| 42 | 42 | ||
| 43 | void * crypt_decrypt( | 43 | void * crypt_decrypt( |
| 44 | - CRYPT _this, | 44 | + CRYPT this, |
| 45 | const void * const data, | 45 | const void * const data, |
| 46 | const char * const password, | 46 | const char * const password, |
| 47 | size_t * length); | 47 | size_t * length); |
| 48 | 48 | ||
| 49 | -void * crypt_createIv(CRYPT _this); | ||
| 50 | -void crypt_setIv(CRYPT _this, const void * const iv); | ||
| 51 | -void crypt_setIvsize(CRYPT _this, const size_t size); | ||
| 52 | -void crypt_setKeysize(CRYPT _this, const size_t size); | 49 | +void * crypt_createIv(CRYPT this); |
| 50 | +void crypt_setIv(CRYPT this, const void * const iv); | ||
| 51 | +void crypt_setIvsize(CRYPT this, const size_t size); | ||
| 52 | +void crypt_setKeysize(CRYPT this, const size_t size); | ||
| 53 | 53 | ||
| 54 | #endif//__CRYPT_H__ | 54 | #endif//__CRYPT_H__ |
| 55 | // vim: set et ts=4 sw=4: | 55 | // vim: set et ts=4 sw=4: |
| @@ -39,9 +39,9 @@ enum DYNTYPE_TYPES { | @@ -39,9 +39,9 @@ enum DYNTYPE_TYPES { | ||
| 39 | 39 | ||
| 40 | 40 | ||
| 41 | CLASS(DYNTYPE) { | 41 | CLASS(DYNTYPE) { |
| 42 | - const _CCLASS const class; | 42 | + const CCLASS const class; |
| 43 | enum DYNTYPE_TYPES type; | 43 | enum DYNTYPE_TYPES type; |
| 44 | - union _data { | 44 | + union { |
| 45 | unsigned char _boolean; | 45 | unsigned char _boolean; |
| 46 | int _int; | 46 | int _int; |
| 47 | double _double; | 47 | double _double; |
| @@ -60,14 +60,14 @@ CLASS(DYNTYPE) { | @@ -60,14 +60,14 @@ CLASS(DYNTYPE) { | ||
| 60 | #define dyntype_newArray(value) new(DYNTYPE, DYNTYPE_TYPE_ARRAY, value) | 60 | #define dyntype_newArray(value) new(DYNTYPE, DYNTYPE_TYPE_ARRAY, value) |
| 61 | #define dyntype_newHash(value) new(DYNTYPE, DYNTYPE_TYPE_HASH, value) | 61 | #define dyntype_newHash(value) new(DYNTYPE, DYNTYPE_TYPE_HASH, value) |
| 62 | 62 | ||
| 63 | -enum DYNTYPE_TYPES dyntype_getType(DYNTYPE _this); | ||
| 64 | -size_t dyntype_getSize(DYNTYPE _this); | ||
| 65 | -unsigned char dyntype_getBoolean(DYNTYPE _this); | ||
| 66 | -int dyntype_getInt(DYNTYPE _this); | ||
| 67 | -double dyntype_getDouble(DYNTYPE _this); | ||
| 68 | -char * dyntype_getString(DYNTYPE _this); | ||
| 69 | -DYNTYPE * dyntype_getArray(DYNTYPE _this); | ||
| 70 | -DYNTYPE_HASH dyntype_getHash(DYNTYPE _this); | 63 | +enum DYNTYPE_TYPES dyntype_getType(DYNTYPE this); |
| 64 | +size_t dyntype_getSize(DYNTYPE this); | ||
| 65 | +unsigned char dyntype_getBoolean(DYNTYPE this); | ||
| 66 | +int dyntype_getInt(DYNTYPE this); | ||
| 67 | +double dyntype_getDouble(DYNTYPE this); | ||
| 68 | +char * dyntype_getString(DYNTYPE this); | ||
| 69 | +DYNTYPE * dyntype_getArray(DYNTYPE this); | ||
| 70 | +DYNTYPE_HASH dyntype_getHash(DYNTYPE this); | ||
| 71 | 71 | ||
| 72 | #endif//__DYNTYPE_H__ | 72 | #endif//__DYNTYPE_H__ |
| 73 | 73 |
| @@ -32,7 +32,7 @@ struct _DYNTYPE_HASH; | @@ -32,7 +32,7 @@ struct _DYNTYPE_HASH; | ||
| 32 | #define __DYNTYPE_HASH_H__ | 32 | #define __DYNTYPE_HASH_H__ |
| 33 | 33 | ||
| 34 | CLASS(DYNTYPE_HASH) { | 34 | CLASS(DYNTYPE_HASH) { |
| 35 | - const _CCLASS const class; | 35 | + const CCLASS const class; |
| 36 | char ** keys; | 36 | char ** keys; |
| 37 | DYNTYPE * values; | 37 | DYNTYPE * values; |
| 38 | size_t size; | 38 | size_t size; |
| @@ -40,9 +40,9 @@ CLASS(DYNTYPE_HASH) { | @@ -40,9 +40,9 @@ CLASS(DYNTYPE_HASH) { | ||
| 40 | }; | 40 | }; |
| 41 | 41 | ||
| 42 | 42 | ||
| 43 | -void dyntype_hash_set(DYNTYPE_HASH _this, const char * key, struct _DYNTYPE * value); | ||
| 44 | -DYNTYPE dyntype_hash_get(DYNTYPE_HASH _this, const char * key); | ||
| 45 | -void dyntype_hash_del(DYNTYPE_HASH _this, const char * key); | 43 | +void dyntype_hash_set(DYNTYPE_HASH this, const char * key, struct _DYNTYPE * value); |
| 44 | +DYNTYPE dyntype_hash_get(DYNTYPE_HASH this, const char * key); | ||
| 45 | +void dyntype_hash_del(DYNTYPE_HASH this, const char * key); | ||
| 46 | 46 | ||
| 47 | #endif | 47 | #endif |
| 48 | 48 |
| @@ -30,16 +30,16 @@ enum PACKET_CONTENT_KEYS { | @@ -30,16 +30,16 @@ enum PACKET_CONTENT_KEYS { | ||
| 30 | 30 | ||
| 31 | 31 | ||
| 32 | CLASS(PACKET) { | 32 | CLASS(PACKET) { |
| 33 | - const _CCLASS const class; | 33 | + const CCLASS const class; |
| 34 | DYNTYPE content[2]; | 34 | DYNTYPE content[2]; |
| 35 | }; | 35 | }; |
| 36 | 36 | ||
| 37 | 37 | ||
| 38 | -DYNTYPE packet_getHeader(PACKET _this); | ||
| 39 | -DYNTYPE packet_getData(PACKET _this); | ||
| 40 | -void packet_setHeader(PACKET _this, DYNTYPE header); | ||
| 41 | -void packet_setData(PACKET _this, DYNTYPE data); | ||
| 42 | -void packet_set_default_content(PACKET _this); | 38 | +DYNTYPE packet_getHeader(PACKET this); |
| 39 | +DYNTYPE packet_getData(PACKET this); | ||
| 40 | +void packet_setHeader(PACKET this, DYNTYPE header); | ||
| 41 | +void packet_setData(PACKET this, DYNTYPE data); | ||
| 42 | +void packet_set_default_content(PACKET this); | ||
| 43 | 43 | ||
| 44 | #endif//__PACKET_H__ | 44 | #endif//__PACKET_H__ |
| 45 | 45 |
| @@ -30,12 +30,12 @@ | @@ -30,12 +30,12 @@ | ||
| 30 | #undef __toJson | 30 | #undef __toJson |
| 31 | 31 | ||
| 32 | void * | 32 | void * |
| 33 | -_new(const _CCLASS _class, ...) | 33 | +_new(const CCLASS _class, ...) |
| 34 | { | 34 | { |
| 35 | - const _CCLASS class = _class; | ||
| 36 | - void * object = calloc(1, class->size); | 35 | + const CCLASS class = _class; |
| 36 | + void * object = calloc(1, class->size); | ||
| 37 | 37 | ||
| 38 | - * (const struct CCLASS **) object = class; | 38 | + * (const struct _CCLASS **) object = class; |
| 39 | 39 | ||
| 40 | if (class->__construct) { | 40 | if (class->__construct) { |
| 41 | va_list params; | 41 | va_list params; |
| @@ -49,12 +49,12 @@ _new(const _CCLASS _class, ...) | @@ -49,12 +49,12 @@ _new(const _CCLASS _class, ...) | ||
| 49 | } | 49 | } |
| 50 | 50 | ||
| 51 | void * | 51 | void * |
| 52 | -_newFromJson(const _CCLASS _class, struct json_object * json) | 52 | +_newFromJson(const CCLASS _class, struct json_object * json) |
| 53 | { | 53 | { |
| 54 | - const struct CCLASS * class = _class; | ||
| 55 | - void * object = calloc(1, class->size); | 54 | + const CCLASS class = _class; |
| 55 | + void * object = calloc(1, class->size); | ||
| 56 | 56 | ||
| 57 | - * (const struct CCLASS **) object = class; | 57 | + * (const struct _CCLASS **) object = class; |
| 58 | 58 | ||
| 59 | if (class->__jsonConst && json) { | 59 | if (class->__jsonConst && json) { |
| 60 | class->__jsonConst(object, json); | 60 | class->__jsonConst(object, json); |
| @@ -63,10 +63,19 @@ _newFromJson(const _CCLASS _class, struct json_object * json) | @@ -63,10 +63,19 @@ _newFromJson(const _CCLASS _class, struct json_object * json) | ||
| 63 | return object; | 63 | return object; |
| 64 | } | 64 | } |
| 65 | 65 | ||
| 66 | +int | ||
| 67 | +_instanceOf(const CCLASS _class, void * _object) | ||
| 68 | +{ | ||
| 69 | + const CCLASS * class = _object; | ||
| 70 | + | ||
| 71 | + return (class && _class == *class); | ||
| 72 | +} | ||
| 73 | + | ||
| 74 | + | ||
| 66 | void | 75 | void |
| 67 | clear(void * _object) | 76 | clear(void * _object) |
| 68 | { | 77 | { |
| 69 | - const struct CCLASS ** class = _object; | 78 | + const CCLASS * class = _object; |
| 70 | 79 | ||
| 71 | if (_object && *class && (*class)->__clear) { | 80 | if (_object && *class && (*class)->__clear) { |
| 72 | (*class)->__clear(_object); | 81 | (*class)->__clear(_object); |
| @@ -76,7 +85,7 @@ clear(void * _object) | @@ -76,7 +85,7 @@ clear(void * _object) | ||
| 76 | void | 85 | void |
| 77 | delete(void * _object) | 86 | delete(void * _object) |
| 78 | { | 87 | { |
| 79 | - const struct CCLASS ** class = *(void**)_object; | 88 | + const CCLASS * class = *(void**)_object; |
| 80 | 89 | ||
| 81 | if (*(void**)_object && *class && (*class)->__destruct) { | 90 | if (*(void**)_object && *class && (*class)->__destruct) { |
| 82 | (*class)->__destruct(*(void**)_object); | 91 | (*class)->__destruct(*(void**)_object); |
| @@ -89,7 +98,7 @@ delete(void * _object) | @@ -89,7 +98,7 @@ delete(void * _object) | ||
| 89 | void | 98 | void |
| 90 | toJson(void * _object, struct json_object ** json) | 99 | toJson(void * _object, struct json_object ** json) |
| 91 | { | 100 | { |
| 92 | - const struct CCLASS ** class = _object; | 101 | + const CCLASS * class = _object; |
| 93 | 102 | ||
| 94 | if (_object && *class && (*class)->__toJson) { | 103 | if (_object && *class && (*class)->__toJson) { |
| 95 | (*class)->__toJson(_object, json); | 104 | (*class)->__toJson(_object, json); |
| @@ -99,17 +108,9 @@ toJson(void * _object, struct json_object ** json) | @@ -99,17 +108,9 @@ toJson(void * _object, struct json_object ** json) | ||
| 99 | int | 108 | int |
| 100 | isObject(void * _object) | 109 | isObject(void * _object) |
| 101 | { | 110 | { |
| 102 | - const struct CCLASS ** class = _object; | 111 | + const CCLASS * class = _object; |
| 103 | 112 | ||
| 104 | return (_object && (*class) && CCLASS_MAGIC == (*class)->magic); | 113 | return (_object && (*class) && CCLASS_MAGIC == (*class)->magic); |
| 105 | } | 114 | } |
| 106 | 115 | ||
| 107 | -int | ||
| 108 | -_instanceOf(const _CCLASS _class, void * _object) | ||
| 109 | -{ | ||
| 110 | - const struct CCLASS ** class = _object; | ||
| 111 | - | ||
| 112 | - return (class && _class == *class); | ||
| 113 | -} | ||
| 114 | - | ||
| 115 | // vim: set et ts=4 sw=4: | 116 | // vim: set et ts=4 sw=4: |
| @@ -29,30 +29,30 @@ | @@ -29,30 +29,30 @@ | ||
| 29 | #include "token/crypt.h" | 29 | #include "token/crypt.h" |
| 30 | 30 | ||
| 31 | 31 | ||
| 32 | -INIT_CCLASS(CRYPT); | 32 | +INIT_CLASS(CRYPT); |
| 33 | 33 | ||
| 34 | __construct(CRYPT) | 34 | __construct(CRYPT) |
| 35 | { | 35 | { |
| 36 | - _this->algorithm = va_arg(* params, const char * const); | ||
| 37 | - _this->mode = va_arg(* params, const char * const); | 36 | + this->algorithm = va_arg(* params, const char * const); |
| 37 | + this->mode = va_arg(* params, const char * const); | ||
| 38 | 38 | ||
| 39 | - _this->mcrypt = mcrypt_module_open( | ||
| 40 | - (char *)_this->algorithm, | 39 | + this->mcrypt = mcrypt_module_open( |
| 40 | + (char *)this->algorithm, | ||
| 41 | NULL, | 41 | NULL, |
| 42 | - (char *)_this->mode, | 42 | + (char *)this->mode, |
| 43 | NULL); | 43 | NULL); |
| 44 | 44 | ||
| 45 | - _this->ivsize = mcrypt_enc_get_iv_size(_this->mcrypt); | ||
| 46 | - _this->keysize = mcrypt_enc_get_key_size(_this->mcrypt); | 45 | + this->ivsize = mcrypt_enc_get_iv_size(this->mcrypt); |
| 46 | + this->keysize = mcrypt_enc_get_key_size(this->mcrypt); | ||
| 47 | } | 47 | } |
| 48 | 48 | ||
| 49 | __destruct(CRYPT) | 49 | __destruct(CRYPT) |
| 50 | { | 50 | { |
| 51 | - if (_this->iv) { | ||
| 52 | - free(_this->iv); | 51 | + if (this->iv) { |
| 52 | + free(this->iv); | ||
| 53 | } | 53 | } |
| 54 | 54 | ||
| 55 | - mcrypt_module_close(_this->mcrypt); | 55 | + mcrypt_module_close(this->mcrypt); |
| 56 | } | 56 | } |
| 57 | 57 | ||
| 58 | __jsonConst(CRYPT) {} | 58 | __jsonConst(CRYPT) {} |
| @@ -60,18 +60,18 @@ __toJson(CRYPT) {} | @@ -60,18 +60,18 @@ __toJson(CRYPT) {} | ||
| 60 | __clear(CRYPT) {} | 60 | __clear(CRYPT) {} |
| 61 | 61 | ||
| 62 | void * | 62 | void * |
| 63 | -crypt_createIv(CRYPT _this) | 63 | +crypt_createIv(CRYPT this) |
| 64 | { | 64 | { |
| 65 | int urandom; | 65 | int urandom; |
| 66 | size_t rsize = 0; | 66 | size_t rsize = 0; |
| 67 | void * iv = NULL; | 67 | void * iv = NULL; |
| 68 | 68 | ||
| 69 | - iv = calloc(_this->ivsize, sizeof(char)); | 69 | + iv = calloc(this->ivsize, sizeof(char)); |
| 70 | 70 | ||
| 71 | urandom = open("/dev/urandom", O_RDONLY); | 71 | urandom = open("/dev/urandom", O_RDONLY); |
| 72 | - rsize = read(urandom, iv, _this->ivsize); | 72 | + rsize = read(urandom, iv, this->ivsize); |
| 73 | 73 | ||
| 74 | - if (_this->ivsize != rsize) { | 74 | + if (this->ivsize != rsize) { |
| 75 | free(iv); | 75 | free(iv); |
| 76 | iv = NULL; | 76 | iv = NULL; |
| 77 | } | 77 | } |
| @@ -81,18 +81,18 @@ crypt_createIv(CRYPT _this) | @@ -81,18 +81,18 @@ crypt_createIv(CRYPT _this) | ||
| 81 | 81 | ||
| 82 | static | 82 | static |
| 83 | void * | 83 | void * |
| 84 | -createKey(CRYPT _this, const char * const password) | 84 | +createKey(CRYPT this, const char * const password) |
| 85 | { | 85 | { |
| 86 | void * key = NULL; | 86 | void * key = NULL; |
| 87 | 87 | ||
| 88 | - key = calloc(_this->keysize, sizeof(char)); | 88 | + key = calloc(this->keysize, sizeof(char)); |
| 89 | 89 | ||
| 90 | mhash_keygen( | 90 | mhash_keygen( |
| 91 | KEYGEN_MCRYPT, | 91 | KEYGEN_MCRYPT, |
| 92 | MHASH_SHA256, | 92 | MHASH_SHA256, |
| 93 | mhash_keygen_count(), | 93 | mhash_keygen_count(), |
| 94 | key, | 94 | key, |
| 95 | - _this->keysize, | 95 | + this->keysize, |
| 96 | NULL, | 96 | NULL, |
| 97 | 0, | 97 | 0, |
| 98 | (mutils_word8 *)password, // @TODO: bad karma...this might change password. | 98 | (mutils_word8 *)password, // @TODO: bad karma...this might change password. |
| @@ -103,7 +103,7 @@ createKey(CRYPT _this, const char * const password) | @@ -103,7 +103,7 @@ createKey(CRYPT _this, const char * const password) | ||
| 103 | 103 | ||
| 104 | void * | 104 | void * |
| 105 | crypt_encrypt( | 105 | crypt_encrypt( |
| 106 | - CRYPT _this, | 106 | + CRYPT this, |
| 107 | const void * const data, | 107 | const void * const data, |
| 108 | const char * const password, | 108 | const char * const password, |
| 109 | size_t * length) | 109 | size_t * length) |
| @@ -112,25 +112,25 @@ crypt_encrypt( | @@ -112,25 +112,25 @@ crypt_encrypt( | ||
| 112 | void * iv; | 112 | void * iv; |
| 113 | void * key; | 113 | void * key; |
| 114 | 114 | ||
| 115 | - key = createKey(_this, password); | ||
| 116 | - if(_this->iv) { | ||
| 117 | - iv = _this->iv; | 115 | + key = createKey(this, password); |
| 116 | + if(this->iv) { | ||
| 117 | + iv = this->iv; | ||
| 118 | } else { | 118 | } else { |
| 119 | - iv = crypt_createIv(_this); | 119 | + iv = crypt_createIv(this); |
| 120 | } | 120 | } |
| 121 | 121 | ||
| 122 | - mcrypt_generic_init(_this->mcrypt, key, _this->keysize, iv); | 122 | + mcrypt_generic_init(this->mcrypt, key, this->keysize, iv); |
| 123 | 123 | ||
| 124 | - encrypted = calloc(_this->ivsize + *length, sizeof(char)); | ||
| 125 | - memcpy(encrypted, iv, _this->ivsize); | ||
| 126 | - memcpy(encrypted + _this->ivsize, data, *length); | 124 | + encrypted = calloc(this->ivsize + *length, sizeof(char)); |
| 125 | + memcpy(encrypted, iv, this->ivsize); | ||
| 126 | + memcpy(encrypted + this->ivsize, data, *length); | ||
| 127 | 127 | ||
| 128 | - mcrypt_generic(_this->mcrypt, encrypted + _this->ivsize, *length); | ||
| 129 | - mcrypt_generic_deinit(_this->mcrypt); | ||
| 130 | - *length += _this->ivsize; | 128 | + mcrypt_generic(this->mcrypt, encrypted + this->ivsize, *length); |
| 129 | + mcrypt_generic_deinit(this->mcrypt); | ||
| 130 | + *length += this->ivsize; | ||
| 131 | 131 | ||
| 132 | free(key); | 132 | free(key); |
| 133 | - if (_this->iv != iv) { | 133 | + if (this->iv != iv) { |
| 134 | free(iv); | 134 | free(iv); |
| 135 | } | 135 | } |
| 136 | 136 | ||
| @@ -139,7 +139,7 @@ crypt_encrypt( | @@ -139,7 +139,7 @@ crypt_encrypt( | ||
| 139 | 139 | ||
| 140 | void * | 140 | void * |
| 141 | crypt_decrypt( | 141 | crypt_decrypt( |
| 142 | - CRYPT _this, | 142 | + CRYPT this, |
| 143 | const void * const data, | 143 | const void * const data, |
| 144 | const char * const password, | 144 | const char * const password, |
| 145 | size_t * length) | 145 | size_t * length) |
| @@ -148,18 +148,18 @@ crypt_decrypt( | @@ -148,18 +148,18 @@ crypt_decrypt( | ||
| 148 | void * iv; | 148 | void * iv; |
| 149 | void * key; | 149 | void * key; |
| 150 | 150 | ||
| 151 | - key = createKey(_this, password); | ||
| 152 | - iv = calloc(_this->ivsize, sizeof(char)); | ||
| 153 | - memcpy(iv, data, _this->ivsize); | 151 | + key = createKey(this, password); |
| 152 | + iv = calloc(this->ivsize, sizeof(char)); | ||
| 153 | + memcpy(iv, data, this->ivsize); | ||
| 154 | 154 | ||
| 155 | - mcrypt_generic_init(_this->mcrypt, key, _this->keysize, iv); | 155 | + mcrypt_generic_init(this->mcrypt, key, this->keysize, iv); |
| 156 | 156 | ||
| 157 | - *length -= _this->ivsize; | 157 | + *length -= this->ivsize; |
| 158 | decrypted = calloc(*length, sizeof(char)); | 158 | decrypted = calloc(*length, sizeof(char)); |
| 159 | - memcpy(decrypted, data + _this->ivsize, *length); | 159 | + memcpy(decrypted, data + this->ivsize, *length); |
| 160 | 160 | ||
| 161 | - mdecrypt_generic(_this->mcrypt, decrypted, *length); | ||
| 162 | - mcrypt_generic_deinit(_this->mcrypt); | 161 | + mdecrypt_generic(this->mcrypt, decrypted, *length); |
| 162 | + mcrypt_generic_deinit(this->mcrypt); | ||
| 163 | 163 | ||
| 164 | free(key); | 164 | free(key); |
| 165 | free(iv); | 165 | free(iv); |
| @@ -35,15 +35,15 @@ size_t _dyntype_sizes[] = { | @@ -35,15 +35,15 @@ size_t _dyntype_sizes[] = { | ||
| 35 | sizeof(DYNTYPE_HASH) | 35 | sizeof(DYNTYPE_HASH) |
| 36 | }; | 36 | }; |
| 37 | 37 | ||
| 38 | -INIT_CCLASS(DYNTYPE); | 38 | +INIT_CLASS(DYNTYPE); |
| 39 | 39 | ||
| 40 | __construct(DYNTYPE) | 40 | __construct(DYNTYPE) |
| 41 | { | 41 | { |
| 42 | - _this->type = va_arg(* params, enum DYNTYPE_TYPES); | 42 | + this->type = va_arg(* params, enum DYNTYPE_TYPES); |
| 43 | 43 | ||
| 44 | - switch(_this->type) { | 44 | + switch(this->type) { |
| 45 | case DYNTYPE_TYPE_INT: | 45 | case DYNTYPE_TYPE_INT: |
| 46 | - (_this->data)._int = va_arg(* params, int); | 46 | + (this->data)._int = va_arg(* params, int); |
| 47 | break; | 47 | break; |
| 48 | 48 | ||
| 49 | case DYNTYPE_TYPE_STRING: | 49 | case DYNTYPE_TYPE_STRING: |
| @@ -51,17 +51,17 @@ __construct(DYNTYPE) | @@ -51,17 +51,17 @@ __construct(DYNTYPE) | ||
| 51 | const char * string = va_arg(* params, const char *); | 51 | const char * string = va_arg(* params, const char *); |
| 52 | const size_t length = strlen(string); | 52 | const size_t length = strlen(string); |
| 53 | 53 | ||
| 54 | - (_this->data)._string = calloc(length + 1, sizeof(char)); | ||
| 55 | - memcpy((_this->data)._string, string, length); | 54 | + (this->data)._string = calloc(length + 1, sizeof(char)); |
| 55 | + memcpy((this->data)._string, string, length); | ||
| 56 | } | 56 | } |
| 57 | break; | 57 | break; |
| 58 | 58 | ||
| 59 | case DYNTYPE_TYPE_HASH: | 59 | case DYNTYPE_TYPE_HASH: |
| 60 | - (_this->data)._hash = va_arg(* params, DYNTYPE_HASH); | 60 | + (this->data)._hash = va_arg(* params, DYNTYPE_HASH); |
| 61 | break; | 61 | break; |
| 62 | 62 | ||
| 63 | default: | 63 | default: |
| 64 | - (_this->data)._hash = NULL; | 64 | + (this->data)._hash = NULL; |
| 65 | } | 65 | } |
| 66 | } | 66 | } |
| 67 | 67 | ||
| @@ -69,8 +69,8 @@ __jsonConst(DYNTYPE) | @@ -69,8 +69,8 @@ __jsonConst(DYNTYPE) | ||
| 69 | { | 69 | { |
| 70 | switch (json_object_get_type(json)) { | 70 | switch (json_object_get_type(json)) { |
| 71 | case json_type_int: | 71 | case json_type_int: |
| 72 | - _this->type = DYNTYPE_TYPE_INT; | ||
| 73 | - (_this->data)._int = (int)json_object_get_int(json); | 72 | + this->type = DYNTYPE_TYPE_INT; |
| 73 | + (this->data)._int = (int)json_object_get_int(json); | ||
| 74 | break; | 74 | break; |
| 75 | 75 | ||
| 76 | case json_type_string: | 76 | case json_type_string: |
| @@ -78,21 +78,21 @@ __jsonConst(DYNTYPE) | @@ -78,21 +78,21 @@ __jsonConst(DYNTYPE) | ||
| 78 | const char * string = json_object_get_string(json); | 78 | const char * string = json_object_get_string(json); |
| 79 | const size_t length = strlen(string); | 79 | const size_t length = strlen(string); |
| 80 | 80 | ||
| 81 | - _this->type = DYNTYPE_TYPE_STRING; | ||
| 82 | - (_this->data)._string = calloc(length + 1, sizeof(char)); | ||
| 83 | - memcpy((_this->data)._string, string, length); | 81 | + this->type = DYNTYPE_TYPE_STRING; |
| 82 | + (this->data)._string = calloc(length + 1, sizeof(char)); | ||
| 83 | + memcpy((this->data)._string, string, length); | ||
| 84 | // the json object handles the memory for string.... | 84 | // the json object handles the memory for string.... |
| 85 | } | 85 | } |
| 86 | break; | 86 | break; |
| 87 | 87 | ||
| 88 | case json_type_object: | 88 | case json_type_object: |
| 89 | - _this->type = DYNTYPE_TYPE_HASH; | ||
| 90 | - (_this->data)._hash = newFromJson(DYNTYPE_HASH, json); | 89 | + this->type = DYNTYPE_TYPE_HASH; |
| 90 | + (this->data)._hash = newFromJson(DYNTYPE_HASH, json); | ||
| 91 | break; | 91 | break; |
| 92 | 92 | ||
| 93 | default: | 93 | default: |
| 94 | - _this->type = DYNTYPE_TYPE_NULL; | ||
| 95 | - (_this->data)._hash = NULL; | 94 | + this->type = DYNTYPE_TYPE_NULL; |
| 95 | + (this->data)._hash = NULL; | ||
| 96 | } | 96 | } |
| 97 | } | 97 | } |
| 98 | 98 | ||
| @@ -100,14 +100,14 @@ __clear(DYNTYPE) {} | @@ -100,14 +100,14 @@ __clear(DYNTYPE) {} | ||
| 100 | 100 | ||
| 101 | __destruct(DYNTYPE) | 101 | __destruct(DYNTYPE) |
| 102 | { | 102 | { |
| 103 | - if (_this) { | ||
| 104 | - switch(_this->type) { | 103 | + if (this) { |
| 104 | + switch(this->type) { | ||
| 105 | case DYNTYPE_TYPE_STRING: | 105 | case DYNTYPE_TYPE_STRING: |
| 106 | - free((_this->data)._string); | 106 | + free((this->data)._string); |
| 107 | break; | 107 | break; |
| 108 | 108 | ||
| 109 | case DYNTYPE_TYPE_HASH: | 109 | case DYNTYPE_TYPE_HASH: |
| 110 | - delete(&((_this->data)._hash)); | 110 | + delete(&((this->data)._hash)); |
| 111 | break; | 111 | break; |
| 112 | 112 | ||
| 113 | default: | 113 | default: |
| @@ -118,17 +118,17 @@ __destruct(DYNTYPE) | @@ -118,17 +118,17 @@ __destruct(DYNTYPE) | ||
| 118 | 118 | ||
| 119 | __toJson(DYNTYPE) | 119 | __toJson(DYNTYPE) |
| 120 | { | 120 | { |
| 121 | - switch(_this->type) { | 121 | + switch(this->type) { |
| 122 | case DYNTYPE_TYPE_INT: | 122 | case DYNTYPE_TYPE_INT: |
| 123 | - *json = json_object_new_int((_this->data)._int); | 123 | + *json = json_object_new_int((this->data)._int); |
| 124 | break; | 124 | break; |
| 125 | 125 | ||
| 126 | case DYNTYPE_TYPE_STRING: | 126 | case DYNTYPE_TYPE_STRING: |
| 127 | - *json = json_object_new_string((_this->data)._string); | 127 | + *json = json_object_new_string((this->data)._string); |
| 128 | break; | 128 | break; |
| 129 | 129 | ||
| 130 | case DYNTYPE_TYPE_HASH: | 130 | case DYNTYPE_TYPE_HASH: |
| 131 | - toJson((_this->data)._hash, json); | 131 | + toJson((this->data)._hash, json); |
| 132 | break; | 132 | break; |
| 133 | 133 | ||
| 134 | default: | 134 | default: |
| @@ -137,51 +137,51 @@ __toJson(DYNTYPE) | @@ -137,51 +137,51 @@ __toJson(DYNTYPE) | ||
| 137 | } | 137 | } |
| 138 | 138 | ||
| 139 | enum DYNTYPE_TYPES | 139 | enum DYNTYPE_TYPES |
| 140 | -dyntype_getType(DYNTYPE _this) | 140 | +dyntype_getType(DYNTYPE this) |
| 141 | { | 141 | { |
| 142 | - return _this->type; | 142 | + return this->type; |
| 143 | } | 143 | } |
| 144 | 144 | ||
| 145 | size_t | 145 | size_t |
| 146 | -dyntype_getSize(DYNTYPE _this) | 146 | +dyntype_getSize(DYNTYPE this) |
| 147 | { | 147 | { |
| 148 | - return _dyntype_sizes[_this->type]; | 148 | + return _dyntype_sizes[this->type]; |
| 149 | } | 149 | } |
| 150 | 150 | ||
| 151 | unsigned char | 151 | unsigned char |
| 152 | -dyntype_getBoolean(DYNTYPE _this) | 152 | +dyntype_getBoolean(DYNTYPE this) |
| 153 | { | 153 | { |
| 154 | - return (_this->data)._boolean; | 154 | + return (this->data)._boolean; |
| 155 | } | 155 | } |
| 156 | 156 | ||
| 157 | int | 157 | int |
| 158 | -dyntype_getInt(DYNTYPE _this) | 158 | +dyntype_getInt(DYNTYPE this) |
| 159 | { | 159 | { |
| 160 | - return (_this->data)._int; | 160 | + return (this->data)._int; |
| 161 | } | 161 | } |
| 162 | 162 | ||
| 163 | double | 163 | double |
| 164 | -dyntype_getDouble(DYNTYPE _this) | 164 | +dyntype_getDouble(DYNTYPE this) |
| 165 | { | 165 | { |
| 166 | - return (_this->data)._double; | 166 | + return (this->data)._double; |
| 167 | } | 167 | } |
| 168 | 168 | ||
| 169 | char * | 169 | char * |
| 170 | -dyntype_getString(DYNTYPE _this) | 170 | +dyntype_getString(DYNTYPE this) |
| 171 | { | 171 | { |
| 172 | - return (_this->data)._string; | 172 | + return (this->data)._string; |
| 173 | } | 173 | } |
| 174 | 174 | ||
| 175 | DYNTYPE * | 175 | DYNTYPE * |
| 176 | -dyntype_getArray(DYNTYPE _this) | 176 | +dyntype_getArray(DYNTYPE this) |
| 177 | { | 177 | { |
| 178 | - return (_this->data)._array; | 178 | + return (this->data)._array; |
| 179 | } | 179 | } |
| 180 | 180 | ||
| 181 | DYNTYPE_HASH | 181 | DYNTYPE_HASH |
| 182 | -dyntype_getHash(DYNTYPE _this) | 182 | +dyntype_getHash(DYNTYPE this) |
| 183 | { | 183 | { |
| 184 | - return (_this->data)._hash; | 184 | + return (this->data)._hash; |
| 185 | } | 185 | } |
| 186 | 186 | ||
| 187 | 187 |
| @@ -28,29 +28,29 @@ | @@ -28,29 +28,29 @@ | ||
| 28 | #define HASH_ENTRY_CHUNK_SIZE 128 | 28 | #define HASH_ENTRY_CHUNK_SIZE 128 |
| 29 | 29 | ||
| 30 | 30 | ||
| 31 | -static void _updateHashSize(DYNTYPE_HASH _this); | 31 | +static void _updateHashSize(DYNTYPE_HASH this); |
| 32 | 32 | ||
| 33 | -INIT_CCLASS(DYNTYPE_HASH); | 33 | +INIT_CLASS(DYNTYPE_HASH); |
| 34 | 34 | ||
| 35 | __construct(DYNTYPE_HASH) | 35 | __construct(DYNTYPE_HASH) |
| 36 | { | 36 | { |
| 37 | - _this->size = 0; | ||
| 38 | - _this->used = 0; | ||
| 39 | - _updateHashSize(_this); | 37 | + this->size = 0; |
| 38 | + this->used = 0; | ||
| 39 | + _updateHashSize(this); | ||
| 40 | } | 40 | } |
| 41 | 41 | ||
| 42 | #undef __construct | 42 | #undef __construct |
| 43 | 43 | ||
| 44 | __jsonConst(DYNTYPE_HASH) | 44 | __jsonConst(DYNTYPE_HASH) |
| 45 | { | 45 | { |
| 46 | - __construct(_this, NULL); | 46 | + __construct(this, NULL); |
| 47 | 47 | ||
| 48 | if (json_type_object != json_object_get_type(json)) { | 48 | if (json_type_object != json_object_get_type(json)) { |
| 49 | return; | 49 | return; |
| 50 | } | 50 | } |
| 51 | 51 | ||
| 52 | json_object_object_foreach(json, key, value) { | 52 | json_object_object_foreach(json, key, value) { |
| 53 | - dyntype_hash_set(_this, key, newFromJson(DYNTYPE, value)); | 53 | + dyntype_hash_set(this, key, newFromJson(DYNTYPE, value)); |
| 54 | } | 54 | } |
| 55 | } | 55 | } |
| 56 | 56 | ||
| @@ -60,16 +60,16 @@ __destruct(DYNTYPE_HASH) | @@ -60,16 +60,16 @@ __destruct(DYNTYPE_HASH) | ||
| 60 | { | 60 | { |
| 61 | size_t index; | 61 | size_t index; |
| 62 | 62 | ||
| 63 | - for (index = 0; index < _this->used; index ++) { | ||
| 64 | - free(_this->keys[index]); | ||
| 65 | - delete(_this->values[index]); | 63 | + for (index = 0; index < this->used; index ++) { |
| 64 | + free(this->keys[index]); | ||
| 65 | + delete(this->values[index]); | ||
| 66 | } | 66 | } |
| 67 | 67 | ||
| 68 | - free(_this->keys); | ||
| 69 | - free(_this->values); | 68 | + free(this->keys); |
| 69 | + free(this->values); | ||
| 70 | 70 | ||
| 71 | - _this->size = _this->used = 0; | ||
| 72 | - _updateHashSize(_this); | 71 | + this->size = this->used = 0; |
| 72 | + _updateHashSize(this); | ||
| 73 | } | 73 | } |
| 74 | 74 | ||
| 75 | __toJson(DYNTYPE_HASH) | 75 | __toJson(DYNTYPE_HASH) |
| @@ -77,31 +77,31 @@ __toJson(DYNTYPE_HASH) | @@ -77,31 +77,31 @@ __toJson(DYNTYPE_HASH) | ||
| 77 | size_t index; | 77 | size_t index; |
| 78 | *json = json_object_new_object(); | 78 | *json = json_object_new_object(); |
| 79 | 79 | ||
| 80 | - for (index = 0; index < _this->used; index ++) { | 80 | + for (index = 0; index < this->used; index ++) { |
| 81 | struct json_object * values; | 81 | struct json_object * values; |
| 82 | 82 | ||
| 83 | - toJson(_this->values[index], &values); | 83 | + toJson(this->values[index], &values); |
| 84 | 84 | ||
| 85 | - json_object_object_add(*json, _this->keys[index], values); | 85 | + json_object_object_add(*json, this->keys[index], values); |
| 86 | } | 86 | } |
| 87 | } | 87 | } |
| 88 | 88 | ||
| 89 | static | 89 | static |
| 90 | void | 90 | void |
| 91 | -_updateHashSize(DYNTYPE_HASH _this) | 91 | +_updateHashSize(DYNTYPE_HASH this) |
| 92 | { | 92 | { |
| 93 | - if (_this->used == _this->size) { | ||
| 94 | - _this->size += HASH_ENTRY_CHUNK_SIZE; | 93 | + if (this->used == this->size) { |
| 94 | + this->size += HASH_ENTRY_CHUNK_SIZE; | ||
| 95 | 95 | ||
| 96 | - _this->keys = realloc(_this->keys, sizeof(char*) * _this->size); | ||
| 97 | - memset(_this->keys + (_this->used * sizeof(char*)), | 96 | + this->keys = realloc(this->keys, sizeof(char*) * this->size); |
| 97 | + memset(this->keys + (this->used * sizeof(char*)), | ||
| 98 | 0, | 98 | 0, |
| 99 | HASH_ENTRY_CHUNK_SIZE * sizeof(char*)); | 99 | HASH_ENTRY_CHUNK_SIZE * sizeof(char*)); |
| 100 | 100 | ||
| 101 | - _this->values = realloc( | ||
| 102 | - _this->values, | ||
| 103 | - sizeof(DYNTYPE) * _this->size); | ||
| 104 | - memset(_this->values + (_this->used * sizeof(DYNTYPE)), | 101 | + this->values = realloc( |
| 102 | + this->values, | ||
| 103 | + sizeof(DYNTYPE) * this->size); | ||
| 104 | + memset(this->values + (this->used * sizeof(DYNTYPE)), | ||
| 105 | 0, | 105 | 0, |
| 106 | HASH_ENTRY_CHUNK_SIZE * sizeof(DYNTYPE)); | 106 | HASH_ENTRY_CHUNK_SIZE * sizeof(DYNTYPE)); |
| 107 | } | 107 | } |
| @@ -109,66 +109,66 @@ _updateHashSize(DYNTYPE_HASH _this) | @@ -109,66 +109,66 @@ _updateHashSize(DYNTYPE_HASH _this) | ||
| 109 | 109 | ||
| 110 | static | 110 | static |
| 111 | size_t | 111 | size_t |
| 112 | -_getHashIdx(DYNTYPE_HASH _this, const char * key) | 112 | +_getHashIdx(DYNTYPE_HASH this, const char * key) |
| 113 | { | 113 | { |
| 114 | size_t index; | 114 | size_t index; |
| 115 | 115 | ||
| 116 | for (index = 0; | 116 | for (index = 0; |
| 117 | - index < _this->used && strcmp(_this->keys[index], key); | 117 | + index < this->used && strcmp(this->keys[index], key); |
| 118 | index++); | 118 | index++); |
| 119 | 119 | ||
| 120 | return index; | 120 | return index; |
| 121 | } | 121 | } |
| 122 | 122 | ||
| 123 | void | 123 | void |
| 124 | -dyntype_hash_set(DYNTYPE_HASH _this, const char * key, DYNTYPE value) | 124 | +dyntype_hash_set(DYNTYPE_HASH this, const char * key, DYNTYPE value) |
| 125 | { | 125 | { |
| 126 | - size_t index = _getHashIdx(_this, key); | 126 | + size_t index = _getHashIdx(this, key); |
| 127 | 127 | ||
| 128 | - _this->keys[index] = calloc(strlen(key) + 1, sizeof(char)); | ||
| 129 | - memcpy(_this->keys[index], key, strlen(key)); | 128 | + this->keys[index] = calloc(strlen(key) + 1, sizeof(char)); |
| 129 | + memcpy(this->keys[index], key, strlen(key)); | ||
| 130 | 130 | ||
| 131 | - _this->values[index] = value; | 131 | + this->values[index] = value; |
| 132 | 132 | ||
| 133 | - if (index == _this->used) { | ||
| 134 | - _this->used += 1; | 133 | + if (index == this->used) { |
| 134 | + this->used += 1; | ||
| 135 | } | 135 | } |
| 136 | 136 | ||
| 137 | - _updateHashSize(_this); | 137 | + _updateHashSize(this); |
| 138 | } | 138 | } |
| 139 | 139 | ||
| 140 | DYNTYPE | 140 | DYNTYPE |
| 141 | -dyntype_hash_get(DYNTYPE_HASH _this, const char * key) | 141 | +dyntype_hash_get(DYNTYPE_HASH this, const char * key) |
| 142 | { | 142 | { |
| 143 | - size_t index = _getHashIdx(_this, key); | 143 | + size_t index = _getHashIdx(this, key); |
| 144 | 144 | ||
| 145 | - if (index == _this->used) { | 145 | + if (index == this->used) { |
| 146 | return NULL; | 146 | return NULL; |
| 147 | } | 147 | } |
| 148 | 148 | ||
| 149 | - return _this->values[index]; | 149 | + return this->values[index]; |
| 150 | } | 150 | } |
| 151 | 151 | ||
| 152 | void | 152 | void |
| 153 | -dyntype_hash_del(DYNTYPE_HASH _this, const char * key) | 153 | +dyntype_hash_del(DYNTYPE_HASH this, const char * key) |
| 154 | { | 154 | { |
| 155 | - size_t index = _getHashIdx(_this, key); | 155 | + size_t index = _getHashIdx(this, key); |
| 156 | 156 | ||
| 157 | - if (index == _this->used) { | ||
| 158 | - return NULL; | 157 | + if (index == this->used) { |
| 158 | + return; | ||
| 159 | } | 159 | } |
| 160 | 160 | ||
| 161 | - free(_this->keys[index]); | 161 | + free(this->keys[index]); |
| 162 | 162 | ||
| 163 | - memmove(_this->keys + index + 1, | ||
| 164 | - _this->keys + index, | ||
| 165 | - (_this->size - index) * sizeof(char*)); | 163 | + memmove(this->keys + index + 1, |
| 164 | + this->keys + index, | ||
| 165 | + (this->size - index) * sizeof(char*)); | ||
| 166 | 166 | ||
| 167 | - memmove(_this->values + index + 1, | ||
| 168 | - _this->values + index, | ||
| 169 | - (_this->size - index) * sizeof(DYNTYPE)); | 167 | + memmove(this->values + index + 1, |
| 168 | + this->values + index, | ||
| 169 | + (this->size - index) * sizeof(DYNTYPE)); | ||
| 170 | 170 | ||
| 171 | - _this->used -= 1; | 171 | + this->used -= 1; |
| 172 | } | 172 | } |
| 173 | 173 | ||
| 174 | // vim: set et ts=4 sw=4: | 174 | // vim: set et ts=4 sw=4: |
| @@ -21,7 +21,7 @@ | @@ -21,7 +21,7 @@ | ||
| 21 | #include "token/packet.h" | 21 | #include "token/packet.h" |
| 22 | 22 | ||
| 23 | 23 | ||
| 24 | -INIT_CCLASS(PACKET); | 24 | +INIT_CLASS(PACKET); |
| 25 | 25 | ||
| 26 | __construct(PACKET) | 26 | __construct(PACKET) |
| 27 | { | 27 | { |
| @@ -34,12 +34,12 @@ __construct(PACKET) | @@ -34,12 +34,12 @@ __construct(PACKET) | ||
| 34 | 34 | ||
| 35 | if (instanceOf(DYNTYPE, data)) { | 35 | if (instanceOf(DYNTYPE, data)) { |
| 36 | 36 | ||
| 37 | - packet_setHeader(_this, header); | ||
| 38 | - packet_setData(_this, data); | 37 | + packet_setHeader(this, header); |
| 38 | + packet_setData(this, data); | ||
| 39 | 39 | ||
| 40 | } else { | 40 | } else { |
| 41 | 41 | ||
| 42 | - packet_set_default_content(_this); | 42 | + packet_set_default_content(this); |
| 43 | 43 | ||
| 44 | } | 44 | } |
| 45 | } | 45 | } |
| @@ -50,12 +50,12 @@ __jsonConst(PACKET) | @@ -50,12 +50,12 @@ __jsonConst(PACKET) | ||
| 50 | struct json_object * data = NULL; | 50 | struct json_object * data = NULL; |
| 51 | 51 | ||
| 52 | if (json_type_array != json_object_get_type(json)) { | 52 | if (json_type_array != json_object_get_type(json)) { |
| 53 | - packet_set_default_content(_this); | 53 | + packet_set_default_content(this); |
| 54 | return; | 54 | return; |
| 55 | } | 55 | } |
| 56 | 56 | ||
| 57 | if (2 != json_object_array_length(json)) { | 57 | if (2 != json_object_array_length(json)) { |
| 58 | - packet_set_default_content(_this); | 58 | + packet_set_default_content(this); |
| 59 | return; | 59 | return; |
| 60 | } | 60 | } |
| 61 | 61 | ||
| @@ -63,20 +63,20 @@ __jsonConst(PACKET) | @@ -63,20 +63,20 @@ __jsonConst(PACKET) | ||
| 63 | data = json_object_array_get_idx(json, 1); | 63 | data = json_object_array_get_idx(json, 1); |
| 64 | 64 | ||
| 65 | if (! (header && data)) { | 65 | if (! (header && data)) { |
| 66 | - packet_set_default_content(_this); | 66 | + packet_set_default_content(this); |
| 67 | return; | 67 | return; |
| 68 | } | 68 | } |
| 69 | 69 | ||
| 70 | - packet_setHeader(_this, newFromJson(DYNTYPE, header)); | ||
| 71 | - packet_setData(_this, newFromJson(DYNTYPE, data)); | 70 | + packet_setHeader(this, newFromJson(DYNTYPE, header)); |
| 71 | + packet_setData(this, newFromJson(DYNTYPE, data)); | ||
| 72 | } | 72 | } |
| 73 | 73 | ||
| 74 | __clear(PACKET) {} | 74 | __clear(PACKET) {} |
| 75 | 75 | ||
| 76 | __destruct(PACKET) | 76 | __destruct(PACKET) |
| 77 | { | 77 | { |
| 78 | - DYNTYPE header = packet_getHeader(_this); | ||
| 79 | - DYNTYPE data = packet_getData(_this); | 78 | + DYNTYPE header = packet_getHeader(this); |
| 79 | + DYNTYPE data = packet_getData(this); | ||
| 80 | 80 | ||
| 81 | if (NULL != header) { | 81 | if (NULL != header) { |
| 82 | delete(&header); | 82 | delete(&header); |
| @@ -93,40 +93,40 @@ __toJson(PACKET) | @@ -93,40 +93,40 @@ __toJson(PACKET) | ||
| 93 | 93 | ||
| 94 | *json = json_object_new_array(); | 94 | *json = json_object_new_array(); |
| 95 | 95 | ||
| 96 | - toJson(packet_getHeader(_this), &value); | 96 | + toJson(packet_getHeader(this), &value); |
| 97 | json_object_array_add(*json, value); | 97 | json_object_array_add(*json, value); |
| 98 | 98 | ||
| 99 | - toJson(packet_getData(_this), &value); | 99 | + toJson(packet_getData(this), &value); |
| 100 | json_object_array_add(*json, value); | 100 | json_object_array_add(*json, value); |
| 101 | } | 101 | } |
| 102 | 102 | ||
| 103 | -DYNTYPE packet_getHeader(PACKET _this) | 103 | +DYNTYPE packet_getHeader(PACKET this) |
| 104 | { | 104 | { |
| 105 | - return _this->content[PACKET_HEADER]; | 105 | + return this->content[PACKET_HEADER]; |
| 106 | } | 106 | } |
| 107 | 107 | ||
| 108 | -DYNTYPE packet_getData(PACKET _this) | 108 | +DYNTYPE packet_getData(PACKET this) |
| 109 | { | 109 | { |
| 110 | - return _this->content[PACKET_DATA]; | 110 | + return this->content[PACKET_DATA]; |
| 111 | } | 111 | } |
| 112 | 112 | ||
| 113 | void | 113 | void |
| 114 | -packet_setHeader(PACKET _this, DYNTYPE header) | 114 | +packet_setHeader(PACKET this, DYNTYPE header) |
| 115 | { | 115 | { |
| 116 | - _this->content[PACKET_HEADER] = header; | 116 | + this->content[PACKET_HEADER] = header; |
| 117 | } | 117 | } |
| 118 | 118 | ||
| 119 | void | 119 | void |
| 120 | -packet_setData(PACKET _this, DYNTYPE data) | 120 | +packet_setData(PACKET this, DYNTYPE data) |
| 121 | { | 121 | { |
| 122 | - _this->content[PACKET_DATA] = data; | 122 | + this->content[PACKET_DATA] = data; |
| 123 | } | 123 | } |
| 124 | 124 | ||
| 125 | void | 125 | void |
| 126 | -packet_set_default_content(PACKET _this) | 126 | +packet_set_default_content(PACKET this) |
| 127 | { | 127 | { |
| 128 | - _this->content[PACKET_HEADER] = NULL; | ||
| 129 | - _this->content[PACKET_DATA] = NULL; | 128 | + this->content[PACKET_HEADER] = NULL; |
| 129 | + this->content[PACKET_DATA] = NULL; | ||
| 130 | } | 130 | } |
| 131 | 131 | ||
| 132 | // vim: set et ts=4 sw=4: | 132 | // vim: set et ts=4 sw=4: |
| @@ -24,12 +24,12 @@ | @@ -24,12 +24,12 @@ | ||
| 24 | 24 | ||
| 25 | char _called; | 25 | char _called; |
| 26 | 26 | ||
| 27 | -INIT_CCLASS(MOCK_CLASS); | 27 | +INIT_CLASS(MOCK_CLASS); |
| 28 | 28 | ||
| 29 | __construct(MOCK_CLASS) | 29 | __construct(MOCK_CLASS) |
| 30 | { | 30 | { |
| 31 | _called = 1; | 31 | _called = 1; |
| 32 | - _this->value = va_arg(* params, int); | 32 | + this->value = va_arg(* params, int); |
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | __jsonConst(MOCK_CLASS) | 35 | __jsonConst(MOCK_CLASS) |
| @@ -37,7 +37,7 @@ __jsonConst(MOCK_CLASS) | @@ -37,7 +37,7 @@ __jsonConst(MOCK_CLASS) | ||
| 37 | _called = 1; | 37 | _called = 1; |
| 38 | assert(json_type_int == json_object_get_type(json)); | 38 | assert(json_type_int == json_object_get_type(json)); |
| 39 | 39 | ||
| 40 | - _this->value = json_object_get_int(json); | 40 | + this->value = json_object_get_int(json); |
| 41 | } | 41 | } |
| 42 | 42 | ||
| 43 | __clear(MOCK_CLASS) {} | 43 | __clear(MOCK_CLASS) {} |
| @@ -49,7 +49,7 @@ __destruct(MOCK_CLASS) | @@ -49,7 +49,7 @@ __destruct(MOCK_CLASS) | ||
| 49 | 49 | ||
| 50 | __toJson(MOCK_CLASS) | 50 | __toJson(MOCK_CLASS) |
| 51 | { | 51 | { |
| 52 | - *json = json_object_new_int(_this->value); | 52 | + *json = json_object_new_int(this->value); |
| 53 | _called = 1; | 53 | _called = 1; |
| 54 | } | 54 | } |
| 55 | 55 | ||
| @@ -58,15 +58,15 @@ __toJson(MOCK_CLASS) | @@ -58,15 +58,15 @@ __toJson(MOCK_CLASS) | ||
| 58 | */ | 58 | */ |
| 59 | 59 | ||
| 60 | int | 60 | int |
| 61 | -mock_class_getValue(MOCK_CLASS _this) | 61 | +mock_class_getValue(MOCK_CLASS this) |
| 62 | { | 62 | { |
| 63 | - return _this->value; | 63 | + return this->value; |
| 64 | } | 64 | } |
| 65 | 65 | ||
| 66 | void | 66 | void |
| 67 | -mock_class_setValue(MOCK_CLASS _this, int value) | 67 | +mock_class_setValue(MOCK_CLASS this, int value) |
| 68 | { | 68 | { |
| 69 | - _this->value = value; | 69 | + this->value = value; |
| 70 | } | 70 | } |
| 71 | 71 | ||
| 72 | /** | 72 | /** |
| @@ -35,18 +35,16 @@ _reset() | @@ -35,18 +35,16 @@ _reset() | ||
| 35 | 35 | ||
| 36 | 36 | ||
| 37 | CLASS(MOCK_CLASS) { | 37 | CLASS(MOCK_CLASS) { |
| 38 | - const _CCLASS const class; | 38 | + const CCLASS const class; |
| 39 | int value; | 39 | int value; |
| 40 | }; | 40 | }; |
| 41 | 41 | ||
| 42 | -extern const _CCLASS const __MOCK_CLASS; | ||
| 43 | - | ||
| 44 | /** | 42 | /** |
| 45 | * ~~~ method declarations ~~~~~~~~ | 43 | * ~~~ method declarations ~~~~~~~~ |
| 46 | */ | 44 | */ |
| 47 | 45 | ||
| 48 | -int mock_class_getValue(MOCK_CLASS _this); | ||
| 49 | -void mock_class_setValue(MOCK_CLASS _this, int value); | 46 | +int mock_class_getValue(MOCK_CLASS this); |
| 47 | +void mock_class_setValue(MOCK_CLASS this, int value); | ||
| 50 | 48 | ||
| 51 | #endif//__MOCK_CLASS_H__ | 49 | #endif//__MOCK_CLASS_H__ |
| 52 | // vim: set et ts=4 sw=4: | 50 | // vim: set et ts=4 sw=4: |
| @@ -39,13 +39,15 @@ const char results[3] = { | @@ -39,13 +39,15 @@ const char results[3] = { | ||
| 39 | int | 39 | int |
| 40 | isObjectNull(void * _object) | 40 | isObjectNull(void * _object) |
| 41 | { | 41 | { |
| 42 | - const struct CCLASS ** class = _object; | 42 | + const CCLASS * class = _object; |
| 43 | 43 | ||
| 44 | if (! isObject(_object)) { | 44 | if (! isObject(_object)) { |
| 45 | return 0; | 45 | return 0; |
| 46 | } | 46 | } |
| 47 | 47 | ||
| 48 | - return isMemNull(_object + _CCLASS_SIZE, (*class)->size - _CCLASS_SIZE); | 48 | + return isMemNull( |
| 49 | + _object + CCLASS_PTR_SIZE, | ||
| 50 | + (*class)->size - CCLASS_PTR_SIZE); | ||
| 49 | } | 51 | } |
| 50 | 52 | ||
| 51 | int | 53 | int |
Please
register
or
login
to post a comment