+
+ return 1;
+}
+
+struct blergref * subscription_list(const char *author, uint64_t offset, int *count, int direction) {
+ char filename[FILENAME_MAX];
+ struct stat st;
+ struct blergref * slist;
+ struct blergref * retlist;
+ uint64_t n_subscription_records;
+
+ if (!valid_name(author))
+ return NULL;
+
+ snprintf(filename, FILENAME_MAX, "%s/%s/subscription_feed", blergconf.data_path, author);
+
+ int feed_fd = open(filename, O_RDONLY);
+ if (feed_fd == -1) {
+ perror("Could not open subscription feed");
+ goto subscription_list_open_failed;
+ }
+
+ fstat(feed_fd, &st);
+ if (st.st_size == 0) {
+ fprintf(stderr, "Feed is empty\n");
+ goto subscription_list_map_failed;
+ }
+ n_subscription_records = st.st_size / sizeof(struct blergref);
+ if (*count > n_subscription_records - offset)
+ *count = n_subscription_records - offset;
+ if (offset > n_subscription_records) {
+ fprintf(stderr, "Cannot access subscription record beyond end\n");
+ goto subscription_list_map_failed;
+ close(feed_fd);
+ return NULL;
+ }
+
+ slist = (struct blergref *) mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, feed_fd, 0);
+ if (slist == MAP_FAILED) {
+ perror("Could not mmap tag_file");
+ goto subscription_list_map_failed;
+ }
+ retlist = (struct blergref *) malloc(sizeof(struct blergref) * *count);
+ if (retlist == NULL) {
+ perror("Could not allocate memory for subscription feed list");
+ goto subscription_list_malloc_failed;
+ }
+
+ switch(direction) {
+ case 1:
+ memcpy(retlist, slist + offset, sizeof(struct blergref) * *count);
+ break;
+ case -1:
+ memcpy(retlist, slist + (n_subscription_records - *count - offset), sizeof(struct blergref) * *count);
+ }
+
+ munmap(slist, st.st_size);
+ close(feed_fd);
+ return retlist;
+
+subscription_list_malloc_failed:
+ munmap(slist, st.st_size);
+subscription_list_map_failed:
+ close(feed_fd);
+subscription_list_open_failed:
+ *count = 0;
+ return NULL;
+}
+
+int is_subscribed(const char *from, const char *to) {
+ char filename[FILENAME_MAX];
+ struct stringbucket * sb;
+ int ret = 0;
+
+ snprintf(filename, FILENAME_MAX, "%s/%s/subscriptions", blergconf.data_path, from);
+ sb = stringbucket_open(filename);
+ if (stringbucket_find(sb, to) != -1)
+ ret = 1;
+ stringbucket_close(sb);
+
+ return ret;
+}
+
+int subscription_count_items(const char *user) {
+ char filename[FILENAME_MAX];
+ struct stat st;
+
+ if (!valid_name(user))
+ return -1;
+
+ snprintf(filename, FILENAME_MAX, "%s/%s/subscription_feed", blergconf.data_path, user);
+
+ if (access(filename, R_OK) != 0)
+ return 0;
+ stat(filename, &st);
+ return st.st_size / sizeof(struct blergref);