X-Git-Url: http://git.bytex64.net/?a=blobdiff_plain;f=database%2Ftags.c;h=ba7c376031d246a65473e7b9729c5b882a40f472;hb=948ce5be6ef6bba36edfb544565ca22e316afb0a;hp=dc6bac83879b30f311fe5719c25e9c7cc8ad82e8;hpb=ec8746b44dc85fd3e3b42835f779890684a9e90a;p=blerg.git diff --git a/database/tags.c b/database/tags.c index dc6bac8..ba7c376 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,11 +59,13 @@ 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; + const char *tagval = tag + 1; memset(t.author, 0, 32); strncpy(t.author, author, 32); @@ -70,10 +73,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, tagval); break; case '@': - snprintf(filename, 512, "%s/%s", REF_TAGS_PATH, tag + 1); + snprintf(filename, FILENAME_MAX, "%s/%s", blergconf.ref_tags_path, tagval); break; default: fprintf(stderr, "Invalid tag type: %s\n", tag); @@ -94,11 +97,20 @@ int tag_add(const char *author, const char *tag, uint64_t record) { flock(tag_fd, LOCK_UN); close(tag_fd); + /* Set a flag for mentioned users */ + if (tag[0] == '@' && blerg_exists(tagval)) { + struct blerg *b = blerg_open(tagval); + if (b != NULL) { + blerg_set_status(b, BLERGSTATUS_MENTIONED, 1); + blerg_close(b); + } + } + return 1; } 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 +118,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 +187,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 +199,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);