6 changed files with 218 additions and 17 deletions
-
2bigpoint_dyntype.c
-
8bigpoint_hash.c
-
22bigpoint_packet.c
-
4bigpoint_packet.h
-
99createToken.c
-
100tests/packet_test.c
@ -0,0 +1,99 @@ |
|||||
|
#include <mcrypt.h> |
||||
|
#include <stdlib.h> |
||||
|
#include <stdio.h> |
||||
|
#include <string.h> |
||||
|
#include <time.h> |
||||
|
#include <json/json.h> |
||||
|
|
||||
|
#include "bigpoint_cclass.h" |
||||
|
#include "bigpoint_packet.h" |
||||
|
#include "bigpoint_dyntype.h" |
||||
|
#include "bigpoint_hash.h" |
||||
|
#include "bigpoint_crypt.h" |
||||
|
#include "base64.h" |
||||
|
|
||||
|
|
||||
|
void |
||||
|
setHashString(struct BIGPOINT_HASH * hash, const char * key, const char * value) |
||||
|
{ |
||||
|
struct BIGPOINT_DYNTYPE * dyn; |
||||
|
|
||||
|
dyn = new(BIGPOINT_DYNTYPE, BIGPOINT_DYNTYPE_STRING, strlen(value), value); |
||||
|
bigpoint_hash_set(hash, key, dyn); |
||||
|
} |
||||
|
|
||||
|
void |
||||
|
setHashInt(struct BIGPOINT_HASH * hash, const char * key, const int value) |
||||
|
{ |
||||
|
struct BIGPOINT_DYNTYPE * dyn; |
||||
|
|
||||
|
dyn = new(BIGPOINT_DYNTYPE, BIGPOINT_DYNTYPE_INT, sizeof(int), value); |
||||
|
bigpoint_hash_set(hash, key, dyn); |
||||
|
} |
||||
|
|
||||
|
int |
||||
|
main(int argc, char * argv[]) |
||||
|
{ |
||||
|
struct BIGPOINT_CRYPT * crypt; |
||||
|
struct BIGPOINT_PACKET * packet; |
||||
|
struct BIGPOINT_HASH * data; |
||||
|
struct json_object * json; |
||||
|
const char * json_str; |
||||
|
char * encrypted; |
||||
|
char * b64d; |
||||
|
char pass[] = "1234"; |
||||
|
size_t length; |
||||
|
|
||||
|
packet = new(BIGPOINT_PACKET); |
||||
|
|
||||
|
bigpoint_packet_setHeader( |
||||
|
packet, |
||||
|
new(BIGPOINT_DYNTYPE, BIGPOINT_DYNTYPE_INT, sizeof(int), time(NULL))); |
||||
|
|
||||
|
data = new(BIGPOINT_HASH); |
||||
|
|
||||
|
setHashString(data, "#C#", "this comes from C"); |
||||
|
setHashString(data, "usr", "ppohg"); |
||||
|
setHashString(data, "pas", "yyyyy"); |
||||
|
setHashInt(data, "val", 321); |
||||
|
|
||||
|
bigpoint_packet_setData( |
||||
|
packet, |
||||
|
new(BIGPOINT_DYNTYPE, |
||||
|
BIGPOINT_DYNTYPE_HASH, |
||||
|
sizeof(struct BIGPOINT_HASH *), |
||||
|
data)); |
||||
|
|
||||
|
json = toJson(packet); |
||||
|
json_str = json_object_to_json_string(json); |
||||
|
length = strlen(json_str); |
||||
|
|
||||
|
crypt = new(BIGPOINT_CRYPT, MCRYPT_RIJNDAEL_256, MCRYPT_CFB); |
||||
|
encrypted = bigpoint_crypt_encrypt(crypt, json_str, pass, &length); |
||||
|
|
||||
|
delete(crypt); |
||||
|
json_object_put(json); |
||||
|
|
||||
|
b64d = calloc(BASE64_LENGTH(length), sizeof(char)); |
||||
|
base64_encode(encrypted, length, b64d, BASE64_LENGTH(length)); |
||||
|
free(encrypted); |
||||
|
|
||||
|
b64d = realloc(b64d, BASE64_LENGTH(length) + 1); |
||||
|
b64d[BASE64_LENGTH(length)] = '\0'; |
||||
|
|
||||
|
printf("%s\n", b64d); |
||||
|
free(b64d); |
||||
|
|
||||
|
delete(bigpoint_hash_get(data, "#C#")); |
||||
|
delete(bigpoint_hash_get(data, "usr")); |
||||
|
delete(bigpoint_hash_get(data, "pas")); |
||||
|
delete(bigpoint_hash_get(data, "val")); |
||||
|
delete(bigpoint_packet_getHeader(packet)); |
||||
|
delete(bigpoint_packet_getData(packet)); |
||||
|
delete(packet); |
||||
|
|
||||
|
|
||||
|
return 0; |
||||
|
} |
||||
|
|
||||
|
// vim: set et ts=4 sw=4: |
||||
@ -0,0 +1,100 @@ |
|||||
|
#include <stdlib.h> |
||||
|
#include <stdio.h> |
||||
|
#include <string.h> |
||||
|
#include <time.h> |
||||
|
#include <json/json.h> |
||||
|
|
||||
|
#include "../bigpoint_cclass.h" |
||||
|
#include "../bigpoint_packet.h" |
||||
|
#include "../bigpoint_dyntype.h" |
||||
|
#include "../bigpoint_hash.h" |
||||
|
|
||||
|
|
||||
|
void |
||||
|
setHashString(struct BIGPOINT_HASH * hash, const char * key, const char * value) |
||||
|
{ |
||||
|
struct BIGPOINT_DYNTYPE * dyn; |
||||
|
|
||||
|
dyn = new(BIGPOINT_DYNTYPE, BIGPOINT_DYNTYPE_STRING, strlen(value), value); |
||||
|
bigpoint_hash_set(hash, key, dyn); |
||||
|
} |
||||
|
|
||||
|
void |
||||
|
setHashInt(struct BIGPOINT_HASH * hash, const char * key, const int value) |
||||
|
{ |
||||
|
struct BIGPOINT_DYNTYPE * dyn; |
||||
|
|
||||
|
dyn = new(BIGPOINT_DYNTYPE, BIGPOINT_DYNTYPE_INT, sizeof(int), value); |
||||
|
bigpoint_hash_set(hash, key, dyn); |
||||
|
} |
||||
|
|
||||
|
int |
||||
|
main(int argc, char * argv[]) |
||||
|
{ |
||||
|
struct BIGPOINT_PACKET * packet; |
||||
|
struct BIGPOINT_HASH * data; |
||||
|
struct json_object * json; |
||||
|
char * json_str; |
||||
|
|
||||
|
packet = new(BIGPOINT_PACKET); |
||||
|
|
||||
|
bigpoint_packet_setHeader( |
||||
|
packet, |
||||
|
new(BIGPOINT_DYNTYPE, BIGPOINT_DYNTYPE_INT, sizeof(int), time(NULL))); |
||||
|
|
||||
|
data = new(BIGPOINT_HASH); |
||||
|
|
||||
|
setHashString(data, "#C#", "this comes from C"); |
||||
|
setHashString(data, "usr", "ppohg"); |
||||
|
setHashString(data, "pas", "yyyyy"); |
||||
|
setHashInt(data, "val", 321); |
||||
|
|
||||
|
bigpoint_packet_setData( |
||||
|
packet, |
||||
|
new(BIGPOINT_DYNTYPE, |
||||
|
BIGPOINT_DYNTYPE_HASH, |
||||
|
sizeof(struct BIGPOINT_HASH *), |
||||
|
data)); |
||||
|
|
||||
|
json = toJson(packet); |
||||
|
|
||||
|
json_str = calloc( |
||||
|
strlen(json_object_to_json_string(json)) + 1, |
||||
|
sizeof(char)); |
||||
|
memcpy(json_str, |
||||
|
json_object_to_json_string(json), |
||||
|
strlen(json_object_to_json_string(json))); |
||||
|
|
||||
|
printf("%s\n", json_str); |
||||
|
|
||||
|
delete(bigpoint_hash_get(data, "#C#")); |
||||
|
delete(bigpoint_hash_get(data, "usr")); |
||||
|
delete(bigpoint_hash_get(data, "pas")); |
||||
|
delete(bigpoint_hash_get(data, "val")); |
||||
|
delete(bigpoint_packet_getHeader(packet)); |
||||
|
delete(bigpoint_packet_getData(packet)); |
||||
|
delete(packet); |
||||
|
|
||||
|
json_object_put(json); |
||||
|
|
||||
|
json = json_tokener_parse(json_str); |
||||
|
packet = newFromJson(BIGPOINT_PACKET, json); |
||||
|
|
||||
|
printf("%s\n", json_object_to_json_string(json)); |
||||
|
|
||||
|
data = (bigpoint_packet_getData(packet)->data)._hash; |
||||
|
delete(bigpoint_hash_get(data, "#C#")); |
||||
|
delete(bigpoint_hash_get(data, "usr")); |
||||
|
delete(bigpoint_hash_get(data, "pas")); |
||||
|
delete(bigpoint_hash_get(data, "val")); |
||||
|
delete(bigpoint_packet_getHeader(packet)); |
||||
|
delete(bigpoint_packet_getData(packet)); |
||||
|
delete(packet); |
||||
|
free(json_str); |
||||
|
|
||||
|
json_object_put(json); |
||||
|
|
||||
|
return 0; |
||||
|
} |
||||
|
|
||||
|
// vim: set et ts=4 sw=4: |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue