aboutsummaryrefslogtreecommitdiff
path: root/common/subscriptions.c
diff options
context:
space:
mode:
authorJulien Dessaux2019-08-06 15:44:18 +0200
committerJulien Dessaux2019-08-06 17:42:06 +0200
commitfea924350b6ba50dc0cb0e5e133cbbd914137e61 (patch)
tree68e119dec63829356db8614204d0a6b4bb7e5221 /common/subscriptions.c
parentCosmetics (diff)
downloadrocket-cli-client-fea924350b6ba50dc0cb0e5e133cbbd914137e61.tar.gz
rocket-cli-client-fea924350b6ba50dc0cb0e5e133cbbd914137e61.tar.bz2
rocket-cli-client-fea924350b6ba50dc0cb0e5e133cbbd914137e61.zip
Added a proper subscriptions listing for the direct conversations closer
Diffstat (limited to '')
-rw-r--r--common/subscriptions.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/common/subscriptions.c b/common/subscriptions.c
new file mode 100644
index 0000000..d6d15aa
--- /dev/null
+++ b/common/subscriptions.c
@@ -0,0 +1,39 @@
+#include "subscriptions.h"
+
+void common_subscription_add(struct subscription** subscriptions, const char* id, const char* name, enum subscription_type type)
+{
+ struct subscription * subscription = common_subscription_new(id, name, type);
+ HASH_ADD_KEYPTR(hh, *subscriptions, subscription->id, strlen(id), subscription);
+}
+
+struct subscription* common_subscription_new(const char* id, const char* name, enum subscription_type type)
+{
+ struct subscription* subscription = malloc(sizeof(struct subscription));
+ subscription->id = malloc(strlen(id) + 1);
+ strcpy(subscription->id, id);
+ subscription->name = malloc(strlen(name) + 1);
+ strcpy(subscription->name, name);
+ subscription->type = type;
+ return subscription;
+}
+
+void common_subscriptions_free(struct subscription* subscriptions)
+{
+ struct subscription *sub, *tmp;
+
+ HASH_ITER(hh, subscriptions, sub, tmp) {
+ HASH_DEL(subscriptions, sub);
+ free(sub->id);
+ free(sub->name);
+ free(sub);
+ }
+}
+
+void common_subscriptions_const_walk(const struct subscription* subscriptions, void (*func)(const struct subscription*))
+{
+ const struct subscription *sub, *tmp;
+
+ HASH_ITER(hh, subscriptions, sub, tmp) {
+ func(sub);
+ }
+}