Use blergconf for paths
[blerg.git] / database / subscription.c
index e55e8f1..b2c89d4 100644 (file)
 #include "subscription.h"
 #include "stringbucket.h"
 #include "config.h"
+#include "configuration.h"
 
 int subscription_add(const char *from, const char *to) {
-       char filename[512];
+       char filename[FILENAME_MAX];
        struct stringbucket * sb;
 
-       snprintf(filename, 512, "%s/%s/subscriptions", DATA_PATH, from);
+       snprintf(filename, FILENAME_MAX, "%s/%s/subscriptions", blergconf.data_path, from);
        sb = stringbucket_open(filename);
        stringbucket_add(sb, to);
        stringbucket_close(sb);
 
-       snprintf(filename, 512, "%s/%s/subscribers", DATA_PATH, to);
+       snprintf(filename, FILENAME_MAX, "%s/%s/subscribers", blergconf.data_path, to);
        sb = stringbucket_open(filename);
        stringbucket_add(sb, from);
        stringbucket_close(sb);
@@ -30,15 +31,15 @@ int subscription_add(const char *from, const char *to) {
 }
 
 int subscription_remove(const char *from, const char *to) {
-       char filename[512];
+       char filename[FILENAME_MAX];
        struct stringbucket * sb;
 
-       snprintf(filename, 512, "%s/%s/subscriptions", DATA_PATH, from);
+       snprintf(filename, FILENAME_MAX, "%s/%s/subscriptions", blergconf.data_path, from);
        sb = stringbucket_open(filename);
        stringbucket_delete(sb, to);
        stringbucket_close(sb);
 
-       snprintf(filename, 512, "%s/%s/subscribers", DATA_PATH, to);
+       snprintf(filename, FILENAME_MAX, "%s/%s/subscribers", blergconf.data_path, to);
        sb = stringbucket_open(filename);
        stringbucket_delete(sb, from);
        stringbucket_close(sb);
@@ -47,22 +48,22 @@ int subscription_remove(const char *from, const char *to) {
 }
 
 void subscription_notify_add_item(char *to, void *stuff) {
-       char filename[512];
+       char filename[FILENAME_MAX];
 
-       snprintf(filename, 512, "%s/%s/subscription_feed", DATA_PATH, to);
+       snprintf(filename, FILENAME_MAX, "%s/%s/subscription_feed", blergconf.data_path, to);
        int fd = open(filename, O_WRONLY | O_APPEND | O_CREAT, 0600);
        write(fd, stuff, sizeof(struct blergref));
        close(fd);
 }
 
 int subscription_notify(const char *author, uint64_t record) {
-       char filename[512];
+       char filename[FILENAME_MAX];
        struct blergref r;
 
        strncpy(r.author, author, 32);
        r.record = record;
 
-       snprintf(filename, 512, "%s/%s/subscribers", DATA_PATH, author);
+       snprintf(filename, FILENAME_MAX, "%s/%s/subscribers", blergconf.data_path, author);
        struct stringbucket * sb = stringbucket_open(filename);
        stringbucket_iterate(sb, subscription_notify_add_item, &r);
        stringbucket_close(sb);
@@ -71,7 +72,7 @@ int subscription_notify(const char *author, uint64_t record) {
 }
 
 struct blergref * subscription_list(const char *author, uint64_t offset, int *count, int direction) {
-       char filename[512];
+       char filename[FILENAME_MAX];
        struct stat st;
        struct blergref * slist;
        struct blergref * retlist;
@@ -80,7 +81,7 @@ struct blergref * subscription_list(const char *author, uint64_t offset, int *co
        if (!valid_name(author))
                return NULL;
 
-       snprintf(filename, 512, "%s/%s/subscription_feed", DATA_PATH, author);
+       snprintf(filename, FILENAME_MAX, "%s/%s/subscription_feed", blergconf.data_path, author);
 
        int feed_fd = open(filename, O_RDONLY);
        if (feed_fd == -1) {
@@ -136,11 +137,11 @@ subscription_list_open_failed:
 }
 
 int is_subscribed(const char *from, const char *to) {
-       char filename[512];
+       char filename[FILENAME_MAX];
        struct stringbucket * sb;
        int ret = 0;
 
-       snprintf(filename, 512, "%s/%s/subscriptions", DATA_PATH, from);
+       snprintf(filename, FILENAME_MAX, "%s/%s/subscriptions", blergconf.data_path, from);
        sb = stringbucket_open(filename);
        if (stringbucket_find(sb, to) != -1)
                ret = 1;
@@ -150,13 +151,13 @@ int is_subscribed(const char *from, const char *to) {
 }
 
 int subscription_count_items(const char *user) {
-       char filename[512];
+       char filename[FILENAME_MAX];
        struct stat st;
 
        if (!valid_name(user))
                return -1;
 
-       snprintf(filename, 512, "%s/%s/subscription_feed", DATA_PATH, user);
+       snprintf(filename, FILENAME_MAX, "%s/%s/subscription_feed", blergconf.data_path, user);
 
        if (access(filename, R_OK) != 0)
                return 0;