X-Git-Url: http://git.bytex64.net/?a=blobdiff_plain;f=database%2Ftags.c;h=3e3b14fa864f592ba05e38d962ad9ef34d7ca25b;hb=c38b2e192d8de8ef38389cc8071881464fff99bb;hp=dc6bac83879b30f311fe5719c25e9c7cc8ad82e8;hpb=ec8746b44dc85fd3e3b42835f779890684a9e90a;p=blerg.git diff --git a/database/tags.c b/database/tags.c index dc6bac8..3e3b14f 100644 --- a/database/tags.c +++ b/database/tags.c @@ -14,6 +14,7 @@ #include "util.h" #include "database.h" #include "config.h" +#include "configuration.h" int tag_scan(const char *author, const char *data, int len, uint64_t record) { @@ -58,10 +59,11 @@ tag_scan_start: tag_add(author, taglist[i], record); free(taglist[i]); } + return 1; } int tag_add(const char *author, const char *tag, uint64_t record) { - char filename[512]; + char filename[FILENAME_MAX]; struct blergref t; memset(t.author, 0, 32); @@ -70,10 +72,10 @@ int tag_add(const char *author, const char *tag, uint64_t record) { switch(tag[0]) { case '#': - snprintf(filename, 512, "%s/%s", HASH_TAGS_PATH, tag + 1); + snprintf(filename, FILENAME_MAX, "%s/%s", blergconf.hash_tags_path, tag + 1); break; case '@': - snprintf(filename, 512, "%s/%s", REF_TAGS_PATH, tag + 1); + snprintf(filename, FILENAME_MAX, "%s/%s", blergconf.ref_tags_path, tag + 1); break; default: fprintf(stderr, "Invalid tag type: %s\n", tag); @@ -98,7 +100,7 @@ int tag_add(const char *author, const char *tag, uint64_t record) { } struct blergref * tag_list(const char *tag, uint64_t offset, int *count, int direction) { - char filename[512]; + char filename[FILENAME_MAX]; struct stat st; struct blergref *taglist; struct blergref *retlist; @@ -106,13 +108,18 @@ struct blergref * tag_list(const char *tag, uint64_t offset, int *count, int dir if (!valid_tag_name(tag + 1)) return NULL; + + if (!(direction == 1 || direction == -1)) { + fprintf(stderr, "Invalid direction: %d\n", direction); + return NULL; + } switch(tag[0]) { case '#': - snprintf(filename, 512, "%s/%s", HASH_TAGS_PATH, tag + 1); + snprintf(filename, FILENAME_MAX, "%s/%s", blergconf.hash_tags_path, tag + 1); break; case '@': - snprintf(filename, 512, "%s/%s", REF_TAGS_PATH, tag + 1); + snprintf(filename, FILENAME_MAX, "%s/%s", blergconf.ref_tags_path, tag + 1); break; default: fprintf(stderr, "Invalid tag type: %s\n", tag); @@ -170,7 +177,7 @@ tag_list_open_failed: } int tag_exists(const char *tag) { - char filename[512]; + char filename[FILENAME_MAX]; if (!valid_tag_name(tag + 1)) return 0; @@ -182,10 +189,10 @@ int tag_exists(const char *tag) { switch(tag[0]) { case '#': - snprintf(filename, 512, "%s/%s", HASH_TAGS_PATH, tag + 1); + snprintf(filename, FILENAME_MAX, "%s/%s", blergconf.hash_tags_path, tag + 1); break; case '@': - snprintf(filename, 512, "%s/%s", REF_TAGS_PATH, tag + 1); + snprintf(filename, FILENAME_MAX, "%s/%s", blergconf.ref_tags_path, tag + 1); break; default: fprintf(stderr, "Invalid tag type: %s\n", tag);