1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
#include "subscriptions.h"
void common_subscription_add(struct subscription** subscriptions, const char* id, const char* name, enum subscription_type type, size_t unread)
{
struct subscription * subscription = common_subscription_new(id, name, type, unread);
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, size_t unread)
{
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;
subscription->unread = unread;
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);
}
}
|