X-Git-Url: http://git.bytex64.net/?a=blobdiff_plain;f=database%2Fdatabase.c;h=9d96f43ab28d25ca2ff8dad40ca86fc4045c2468;hb=948ce5be6ef6bba36edfb544565ca22e316afb0a;hp=91e6aa22f9b0e9e4c04c0e4b5968f5deb9b71f45;hpb=0647b76522be38edfe4b1fbae32addbbf8bb4128;p=blerg.git diff --git a/database/database.c b/database/database.c index 91e6aa2..9d96f43 100644 --- a/database/database.c +++ b/database/database.c @@ -15,6 +15,7 @@ #include "database.h" #include "configuration.h" #include "subscription.h" +#include "tags.h" #include "util.h" #include "config.h" @@ -79,7 +80,7 @@ int blerg_remap_data(struct blerg *blerg) { } int blerg_segment_switch(struct blerg *blerg, int new_segment) { - char filename[512]; + char filename[FILENAME_MAX]; uint64_t max_sequence_no = blerg_get_record_count(blerg); struct stat st; @@ -99,7 +100,7 @@ int blerg_segment_switch(struct blerg *blerg, int new_segment) { blerg_segment_close(blerg); /* Load and map the index */ - snprintf(filename, 512, "%s/index%d", blerg->base_path, new_segment); + snprintf(filename, FILENAME_MAX, "%s/index%d", blerg->base_path, new_segment); blerg->index_fd = open(filename, O_RDWR | O_CREAT, 0600); if (blerg->index_fd == -1) { perror("Could not open index"); @@ -122,7 +123,7 @@ int blerg_segment_switch(struct blerg *blerg, int new_segment) { } /* Load data file */ - sprintf(filename, "%s/data%d", blerg->base_path, new_segment); + snprintf(filename, FILENAME_MAX, "%s/data%d", blerg->base_path, new_segment); blerg->data_fd = open(filename, O_RDWR | O_APPEND | O_CREAT, 0600); if (blerg->data_fd == -1) { perror("Could not open data"); @@ -148,15 +149,14 @@ open_failed_index_open: } int blerg_exists(const char *name) { - int namelen = strlen(name); - char filename[512]; + char filename[FILENAME_MAX]; if (!valid_name(name)) { fprintf(stderr, "Invalid name\n"); return 0; } - snprintf(filename, 512, "%s/%s", DATA_PATH, name); + snprintf(filename, FILENAME_MAX, "%s/%s", blergconf.data_path, name); if (access(filename, F_OK) == -1) return 0; else @@ -165,9 +165,8 @@ int blerg_exists(const char *name) { struct blerg *blerg_open(const char *name) { int namelen = strlen(name); - char filename[512]; + char filename[FILENAME_MAX]; struct stat st; - uint64_t sequence; if (!valid_name(name)) { fprintf(stderr, "Invalid name\n"); @@ -186,13 +185,13 @@ struct blerg *blerg_open(const char *name) { blerg->data = NULL; /* Make the directory if it doesn't exist */ - blerg->base_path = malloc(512); - snprintf(blerg->base_path, 512, "%s/%s", DATA_PATH, name); + blerg->base_path = malloc(FILENAME_MAX); + snprintf(blerg->base_path, FILENAME_MAX, "%s/%s", blergconf.data_path, name); if (access(blerg->base_path, F_OK) == -1) mkdir(blerg->base_path, 0755); /* Open and map metadata */ - snprintf(filename, 512, "%s/meta", blerg->base_path); + snprintf(filename, FILENAME_MAX, "%s/meta", blerg->base_path); blerg->meta_fd = open(filename, O_RDWR | O_CREAT, 0600); if (blerg->meta_fd == -1) { perror("Could not open metadata"); @@ -291,7 +290,7 @@ uint64_t blerg_store(struct blerg *blerg, const char *data, int length) { flock(blerg->data_fd, LOCK_UN); flock(blerg->index_fd, LOCK_UN); - if (!blerg_get_mute(blerg)) { + if (!blerg_get_status(blerg, BLERGSTATUS_MUTED)) { /* Now do those dirty microblogging deeds */ tag_scan(blerg->name, data, length, record); subscription_notify(blerg->name, record); @@ -379,17 +378,17 @@ uint64_t blerg_get_subscription_mark(struct blerg *blerg) { return blerg->meta->subscription_mark; } -int blerg_set_mute(struct blerg *blerg, int v) { +int blerg_set_status(struct blerg *blerg, uint32_t status, int v) { CHECK_VALID_BLERG(0) if (v) { - blerg->meta->status |= BLERGMETA_MUTED; + blerg->meta->status |= status; } else { - blerg->meta->status &= ~BLERGMETA_MUTED; + blerg->meta->status &= ~status; } return 1; } -int blerg_get_mute(struct blerg *blerg) { +int blerg_get_status(struct blerg *blerg, uint32_t status) { CHECK_VALID_BLERG(0) - return (blerg->meta->status & BLERGMETA_MUTED) > 0; + return (blerg->meta->status & status) > 0; }