Commit aaea686fedfba7efe24da024c2856d370d9f9de5

Authored by Georg Hopp
1 parent 262f8f65

some smaller fixes as well as a complete test create_token implementation.

... ... @@ -25,7 +25,7 @@ __construct(struct BIGPOINT_DYNTYPE * _this, va_list * params)
25 25 break;
26 26
27 27 case BIGPOINT_DYNTYPE_HASH:
28   - (_this->data)._hash = new(BIGPOINT_HASH);
  28 + (_this->data)._hash = va_arg(* params, struct BIGPOINT_HASH *);
29 29 break;
30 30
31 31 default:
... ...
... ... @@ -85,15 +85,15 @@ _updateHashSize(struct BIGPOINT_HASH * _this)
85 85
86 86 _this->keys = realloc(_this->keys, sizeof(char*) * _this->size);
87 87 memset(_this->keys + (_this->used * sizeof(char*)),
88   - HASH_ENTRY_CHUNK_SIZE * sizeof(char*),
89   - 0);
  88 + 0,
  89 + HASH_ENTRY_CHUNK_SIZE * sizeof(char*));
90 90
91 91 _this->values = realloc(
92 92 _this->values,
93 93 sizeof(struct BIGPOINT_DYNTYPE *) * _this->size);
94 94 memset(_this->values + (_this->used * sizeof(struct BIGPOINT_DYNTYPE *)),
95   - HASH_ENTRY_CHUNK_SIZE * sizeof(struct BIGPOINT_DYNTYPE *),
96   - 0);
  95 + 0,
  96 + HASH_ENTRY_CHUNK_SIZE * sizeof(struct BIGPOINT_DYNTYPE *));
97 97 }
98 98 }
99 99
... ...
1 1 #include <json/json.h>
2 2
3   -#include "bigpoint_container_packet.h"
  3 +#include "bigpoint_packet.h"
4 4
5 5
6 6 static
7 7 void
8 8 __construct(struct BIGPOINT_PACKET * _this, va_list * params)
9 9 {
10   - bigpoint_container_packet_set_default_content(_this);
  10 + bigpoint_packet_set_default_content(_this);
11 11 }
12 12
13 13 static
... ... @@ -53,38 +53,40 @@ __toJson(struct BIGPOINT_PACKET * _this)
53 53 }
54 54
55 55 static const
56   -struct BIGPOINT_CLASS _bigpoint_packet = {
  56 +struct BIGPOINT_CCLASS _bigpoint_packet = {
57 57 sizeof(struct BIGPOINT_PACKET),
58 58 (ctor)__construct,
59   - __jsonConst,
  59 + (jCtor)__jsonConst,
60 60 (dtor)__destruct,
61   - __toJson
  61 + (jTo)__toJson
62 62 };
63 63
64 64 const struct BIGPOINT_CCLASS * const BIGPOINT_PACKET = &_bigpoint_packet;
65 65
66   -void *
  66 +struct BIGPOINT_DYNTYPE *
67 67 bigpoint_packet_getHeader(
68 68 struct BIGPOINT_PACKET * _this)
69 69 {
70 70 return _this->content[BIGPOINT_PACKET_HEADER];
71 71 }
72 72
73   -void *
  73 +struct BIGPOINT_DYNTYPE *
74 74 bigpoint_packet_getData(
75 75 struct BIGPOINT_PACKET * _this)
76 76 {
77 77 return _this->content[BIGPOINT_PACKET_DATA];
78 78 }
79 79
80   -void bigpoint_packet_setHeader(
  80 +void
  81 +bigpoint_packet_setHeader(
81 82 struct BIGPOINT_PACKET * _this,
82 83 struct BIGPOINT_DYNTYPE * header)
83 84 {
84 85 _this->content[BIGPOINT_PACKET_HEADER] = header;
85 86 }
86 87
87   -void bigpoint_packet_setData(
  88 +void
  89 +bigpoint_packet_setData(
88 90 struct BIGPOINT_PACKET * _this,
89 91 struct BIGPOINT_DYNTYPE * data)
90 92 {
... ... @@ -92,7 +94,7 @@ void bigpoint_packet_setData(
92 94 }
93 95
94 96 void
95   -bigpoint_container_packet_set_default_content(
  97 +bigpoint_packet_set_default_content(
96 98 struct BIGPOINT_PACKET * _this)
97 99 {
98 100 _this->content[BIGPOINT_PACKET_HEADER] = NULL;
... ...
... ... @@ -17,10 +17,10 @@ struct BIGPOINT_PACKET {
17 17
18 18 extern const struct BIGPOINT_CCLASS * const BIGPOINT_PACKET;
19 19
20   -void * bigpoint_packet_getHeader(
  20 +struct BIGPOINT_DYNTYPE * bigpoint_packet_getHeader(
21 21 struct BIGPOINT_PACKET * _this);
22 22
23   -void * bigpoint_packet_getData(
  23 +struct BIGPOINT_DYNTYPE * bigpoint_packet_getData(
24 24 struct BIGPOINT_PACKET * _this);
25 25
26 26 void bigpoint_packet_setHeader(
... ...
  1 +#include <mcrypt.h>
  2 +#include <stdlib.h>
  3 +#include <stdio.h>
  4 +#include <string.h>
  5 +#include <time.h>
  6 +#include <json/json.h>
  7 +
  8 +#include "bigpoint_cclass.h"
  9 +#include "bigpoint_packet.h"
  10 +#include "bigpoint_dyntype.h"
  11 +#include "bigpoint_hash.h"
  12 +#include "bigpoint_crypt.h"
  13 +#include "base64.h"
  14 +
  15 +
  16 +void
  17 +setHashString(struct BIGPOINT_HASH * hash, const char * key, const char * value)
  18 +{
  19 + struct BIGPOINT_DYNTYPE * dyn;
  20 +
  21 + dyn = new(BIGPOINT_DYNTYPE, BIGPOINT_DYNTYPE_STRING, strlen(value), value);
  22 + bigpoint_hash_set(hash, key, dyn);
  23 +}
  24 +
  25 +void
  26 +setHashInt(struct BIGPOINT_HASH * hash, const char * key, const int value)
  27 +{
  28 + struct BIGPOINT_DYNTYPE * dyn;
  29 +
  30 + dyn = new(BIGPOINT_DYNTYPE, BIGPOINT_DYNTYPE_INT, sizeof(int), value);
  31 + bigpoint_hash_set(hash, key, dyn);
  32 +}
  33 +
  34 +int
  35 +main(int argc, char * argv[])
  36 +{
  37 + struct BIGPOINT_CRYPT * crypt;
  38 + struct BIGPOINT_PACKET * packet;
  39 + struct BIGPOINT_HASH * data;
  40 + struct json_object * json;
  41 + const char * json_str;
  42 + char * encrypted;
  43 + char * b64d;
  44 + char pass[] = "1234";
  45 + size_t length;
  46 +
  47 + packet = new(BIGPOINT_PACKET);
  48 +
  49 + bigpoint_packet_setHeader(
  50 + packet,
  51 + new(BIGPOINT_DYNTYPE, BIGPOINT_DYNTYPE_INT, sizeof(int), time(NULL)));
  52 +
  53 + data = new(BIGPOINT_HASH);
  54 +
  55 + setHashString(data, "#C#", "this comes from C");
  56 + setHashString(data, "usr", "ppohg");
  57 + setHashString(data, "pas", "yyyyy");
  58 + setHashInt(data, "val", 321);
  59 +
  60 + bigpoint_packet_setData(
  61 + packet,
  62 + new(BIGPOINT_DYNTYPE,
  63 + BIGPOINT_DYNTYPE_HASH,
  64 + sizeof(struct BIGPOINT_HASH *),
  65 + data));
  66 +
  67 + json = toJson(packet);
  68 + json_str = json_object_to_json_string(json);
  69 + length = strlen(json_str);
  70 +
  71 + crypt = new(BIGPOINT_CRYPT, MCRYPT_RIJNDAEL_256, MCRYPT_CFB);
  72 + encrypted = bigpoint_crypt_encrypt(crypt, json_str, pass, &length);
  73 +
  74 + delete(crypt);
  75 + json_object_put(json);
  76 +
  77 + b64d = calloc(BASE64_LENGTH(length), sizeof(char));
  78 + base64_encode(encrypted, length, b64d, BASE64_LENGTH(length));
  79 + free(encrypted);
  80 +
  81 + b64d = realloc(b64d, BASE64_LENGTH(length) + 1);
  82 + b64d[BASE64_LENGTH(length)] = '\0';
  83 +
  84 + printf("%s\n", b64d);
  85 + free(b64d);
  86 +
  87 + delete(bigpoint_hash_get(data, "#C#"));
  88 + delete(bigpoint_hash_get(data, "usr"));
  89 + delete(bigpoint_hash_get(data, "pas"));
  90 + delete(bigpoint_hash_get(data, "val"));
  91 + delete(bigpoint_packet_getHeader(packet));
  92 + delete(bigpoint_packet_getData(packet));
  93 + delete(packet);
  94 +
  95 +
  96 + return 0;
  97 +}
  98 +
  99 +// vim: set et ts=4 sw=4:
... ...
  1 +#include <stdlib.h>
  2 +#include <stdio.h>
  3 +#include <string.h>
  4 +#include <time.h>
  5 +#include <json/json.h>
  6 +
  7 +#include "../bigpoint_cclass.h"
  8 +#include "../bigpoint_packet.h"
  9 +#include "../bigpoint_dyntype.h"
  10 +#include "../bigpoint_hash.h"
  11 +
  12 +
  13 +void
  14 +setHashString(struct BIGPOINT_HASH * hash, const char * key, const char * value)
  15 +{
  16 + struct BIGPOINT_DYNTYPE * dyn;
  17 +
  18 + dyn = new(BIGPOINT_DYNTYPE, BIGPOINT_DYNTYPE_STRING, strlen(value), value);
  19 + bigpoint_hash_set(hash, key, dyn);
  20 +}
  21 +
  22 +void
  23 +setHashInt(struct BIGPOINT_HASH * hash, const char * key, const int value)
  24 +{
  25 + struct BIGPOINT_DYNTYPE * dyn;
  26 +
  27 + dyn = new(BIGPOINT_DYNTYPE, BIGPOINT_DYNTYPE_INT, sizeof(int), value);
  28 + bigpoint_hash_set(hash, key, dyn);
  29 +}
  30 +
  31 +int
  32 +main(int argc, char * argv[])
  33 +{
  34 + struct BIGPOINT_PACKET * packet;
  35 + struct BIGPOINT_HASH * data;
  36 + struct json_object * json;
  37 + char * json_str;
  38 +
  39 + packet = new(BIGPOINT_PACKET);
  40 +
  41 + bigpoint_packet_setHeader(
  42 + packet,
  43 + new(BIGPOINT_DYNTYPE, BIGPOINT_DYNTYPE_INT, sizeof(int), time(NULL)));
  44 +
  45 + data = new(BIGPOINT_HASH);
  46 +
  47 + setHashString(data, "#C#", "this comes from C");
  48 + setHashString(data, "usr", "ppohg");
  49 + setHashString(data, "pas", "yyyyy");
  50 + setHashInt(data, "val", 321);
  51 +
  52 + bigpoint_packet_setData(
  53 + packet,
  54 + new(BIGPOINT_DYNTYPE,
  55 + BIGPOINT_DYNTYPE_HASH,
  56 + sizeof(struct BIGPOINT_HASH *),
  57 + data));
  58 +
  59 + json = toJson(packet);
  60 +
  61 + json_str = calloc(
  62 + strlen(json_object_to_json_string(json)) + 1,
  63 + sizeof(char));
  64 + memcpy(json_str,
  65 + json_object_to_json_string(json),
  66 + strlen(json_object_to_json_string(json)));
  67 +
  68 + printf("%s\n", json_str);
  69 +
  70 + delete(bigpoint_hash_get(data, "#C#"));
  71 + delete(bigpoint_hash_get(data, "usr"));
  72 + delete(bigpoint_hash_get(data, "pas"));
  73 + delete(bigpoint_hash_get(data, "val"));
  74 + delete(bigpoint_packet_getHeader(packet));
  75 + delete(bigpoint_packet_getData(packet));
  76 + delete(packet);
  77 +
  78 + json_object_put(json);
  79 +
  80 + json = json_tokener_parse(json_str);
  81 + packet = newFromJson(BIGPOINT_PACKET, json);
  82 +
  83 + printf("%s\n", json_object_to_json_string(json));
  84 +
  85 + data = (bigpoint_packet_getData(packet)->data)._hash;
  86 + delete(bigpoint_hash_get(data, "#C#"));
  87 + delete(bigpoint_hash_get(data, "usr"));
  88 + delete(bigpoint_hash_get(data, "pas"));
  89 + delete(bigpoint_hash_get(data, "val"));
  90 + delete(bigpoint_packet_getHeader(packet));
  91 + delete(bigpoint_packet_getData(packet));
  92 + delete(packet);
  93 + free(json_str);
  94 +
  95 + json_object_put(json);
  96 +
  97 + return 0;
  98 +}
  99 +
  100 +// vim: set et ts=4 sw=4:
... ...
Please register or login to post a comment