diff options
Diffstat (limited to 'plugins/signal-protocol/src/signal_helper.c')
-rw-r--r-- | plugins/signal-protocol/src/signal_helper.c | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/plugins/signal-protocol/src/signal_helper.c b/plugins/signal-protocol/src/signal_helper.c index d13b9c95..5cbf2ce2 100644 --- a/plugins/signal-protocol/src/signal_helper.c +++ b/plugins/signal-protocol/src/signal_helper.c @@ -3,14 +3,30 @@ #include <gcrypt.h> -signal_protocol_address* signal_protocol_address_new() { +signal_type_base* signal_type_ref_vapi(signal_type_base* instance) { + g_return_val_if_fail(instance != NULL, NULL); + signal_type_ref(instance); + return instance; +} + +signal_type_base* signal_type_unref_vapi(signal_type_base* instance) { + g_return_val_if_fail(instance != NULL, NULL); + signal_type_unref(instance); + return NULL; +} + +signal_protocol_address* signal_protocol_address_new(const gchar* name, int32_t device_id) { + g_return_val_if_fail(name != NULL, NULL); signal_protocol_address* address = malloc(sizeof(signal_protocol_address)); - address->name = 0; - address->device_id = 0; + address->device_id = NULL; + address->name = NULL; + signal_protocol_address_set_name(address, name); + signal_protocol_address_set_device_id(address, device_id); return address; } void signal_protocol_address_free(signal_protocol_address* ptr) { + g_return_if_fail(ptr != NULL); if (ptr->name) { g_free((void*)ptr->name); } @@ -18,6 +34,8 @@ void signal_protocol_address_free(signal_protocol_address* ptr) { } void signal_protocol_address_set_name(signal_protocol_address* self, const gchar* name) { + g_return_if_fail(self != NULL); + g_return_if_fail(name != NULL); gchar* n = g_malloc(strlen(name)+1); memcpy(n, name, strlen(name)); n[strlen(name)] = 0; @@ -29,13 +47,25 @@ void signal_protocol_address_set_name(signal_protocol_address* self, const gchar } gchar* signal_protocol_address_get_name(signal_protocol_address* self) { - if (self->name == 0) return 0; + g_return_val_if_fail(self != NULL, NULL); + g_return_val_if_fail(self->name != NULL, 0); gchar* res = g_malloc(sizeof(char) * (self->name_len + 1)); memcpy(res, self->name, self->name_len); res[self->name_len] = 0; return res; } +int32_t signal_protocol_address_get_device_id(signal_protocol_address* self) { + g_return_val_if_fail(self != NULL, NULL); + return self->device_id; +} + +void signal_protocol_address_set_device_id(signal_protocol_address* self, int32_t device_id) { + g_return_if_fail(self != NULL); + self->device_id = device_id; +} + + session_pre_key* session_pre_key_new(uint32_t pre_key_id, ec_key_pair* pair, int* err) { session_pre_key* res; *err = session_pre_key_create(&res, pre_key_id, pair); |