X-Git-Url: http://git.bytex64.net/?a=blobdiff_plain;f=database%2Ftags.c;h=356ef8860f9f8fa7f84750a9cfecb23b4964c745;hb=4e824b6fa432f65753fd00323375c6bbdde7a7f9;hp=1911ac8d9e6f812f4ed50ce8ca513c7a3e46b486;hpb=1cf0f1ebfbd5b5a621af2a49ac0328fd0cec4bf4;p=blerg.git diff --git a/database/tags.c b/database/tags.c index 1911ac8..356ef88 100644 --- a/database/tags.c +++ b/database/tags.c @@ -8,6 +8,7 @@ #include #include #include "tags.h" +#include "util.h" #include "config.h" #define MAX_TAG_LENGTH 64 @@ -92,12 +93,15 @@ int tag_add(const char *author, const char *tag, uint64_t record) { return 1; } -struct tag * tag_list(const char *tag, uint64_t offset, uint64_t *count, int direction) { +struct tag * tag_list(const char *tag, uint64_t offset, int *count, int direction) { char filename[512]; struct stat st; struct tag *taglist; struct tag *retlist; uint64_t n_tag_records; + + if (!valid_name(tag + 1)) + return NULL; switch(tag[0]) { case '#': @@ -108,7 +112,7 @@ struct tag * tag_list(const char *tag, uint64_t offset, uint64_t *count, int dir break; default: fprintf(stderr, "Invalid tag type: %s\n", tag); - return 0; + return NULL; } int tag_fd = open(filename, O_RDONLY, 0600); @@ -164,16 +168,11 @@ tag_list_open_failed: } int tag_exists(const char *tag) { - int taglen = strlen(tag); char filename[512]; - if (taglen < 2) { - fprintf(stderr, "Tag too short\n"); + if (!valid_name(tag + 1)) return 0; - } else if (taglen > 33) { - fprintf(stderr, "Tag too long\n"); - return 0; - } + if (!(tag[0] == '@' || tag[0] == '#')) { fprintf(stderr, "Invalid tag: %s\n", tag); return 0;