aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/CMakeLists.txt1
-rw-r--r--common/subscriptions.c39
-rw-r--r--common/subscriptions.h28
3 files changed, 68 insertions, 0 deletions
diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt
index aa5402a..876571b 100644
--- a/common/CMakeLists.txt
+++ b/common/CMakeLists.txt
@@ -2,3 +2,4 @@ file(GLOB_RECURSE SOURCES *.c)
include_directories("${CMAKE_CURRENT_BINARY_DIR}")
ADD_LIBRARY(common STATIC ${SOURCES})
+target_link_libraries(common config curl)
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);
+ }
+}
diff --git a/common/subscriptions.h b/common/subscriptions.h
new file mode 100644
index 0000000..6c10a24
--- /dev/null
+++ b/common/subscriptions.h
@@ -0,0 +1,28 @@
+#ifndef COMMON_SUBSCRIPTIONS_H_
+#define COMMON_SUBSCRIPTIONS_H_
+
+#include <uthash.h>
+
+static const char *subscription_type_str[] = {
+ "channel", "direct", "private",
+};
+
+enum subscription_type {
+ SUBSCRIPTION_CHANNEL,
+ SUBSCRIPTION_DIRECT,
+ SUBSCRIPTION_PRIVATE,
+};
+
+struct subscription {
+ char* id;
+ char* name;
+ enum subscription_type type;
+ UT_hash_handle hh;
+};
+
+void common_subscription_add(struct subscription** subscriptions, const char* id, const char* name, enum subscription_type type);
+struct subscription* common_subscription_new(const char* id, const char* name, enum subscription_type type);
+void common_subscriptions_free(struct subscription* subscriptions);
+void common_subscriptions_const_walk(const struct subscription* subscriptions, void (*func)(const struct subscription*));
+
+#endif