tags must be preceeded by whitespace or start at the beginning of the record
authorChip Black <bytex64@bytex64.net>
Sun, 16 Jan 2011 12:08:22 +0000 (06:08 -0600)
committerChip Black <bytex64@bytex64.net>
Sun, 16 Jan 2011 12:08:22 +0000 (06:08 -0600)
config.h
database/tags.c

index 9a16246..b363206 100644 (file)
--- a/config.h
+++ b/config.h
@@ -10,4 +10,7 @@
 #define RECORDS_PER_SEGMENT 65536
 #define MAX_RECORD_SIZE 65535  /* No greater than 65535 */
 
+#define MAX_TAG_LENGTH 64
+#define MAX_TAGS_PER_RECORD 1024
+
 #endif //_CONFIG_H
index 8386705..a28df02 100644 (file)
 #include "util.h"
 #include "config.h"
 
-#define MAX_TAG_LENGTH 64
-#define MAX_TAGS 1024
-
 #define TAG_CHAR(c) ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '-' || c == '_')
+#define WHITESPACE(c) (c == ' ' || c == '\t' || c == '\n' || c == '\r')
 
 int tag_scan(const char *author, const char *data, int len, uint64_t record) {
-       char *taglist[MAX_TAGS];
+       char *taglist[MAX_TAGS_PER_RECORD];
+       char last_char = ' ';
        int n_tags = 0;
        int i, j;
 
        for (i = 0; i < len; i++) {
 tag_scan_start:
-               if (data[i] == '#' || data[i] == '@') {
-                       if (n_tags == MAX_TAGS) {
+               if (WHITESPACE(last_char) && (data[i] == '#' || data[i] == '@')) {
+                       if (n_tags == MAX_TAGS_PER_RECORD) {
                                fprintf(stderr, "Too many tags in message\n");
                                break;
                        }
@@ -43,14 +42,17 @@ tag_scan_start:
                                if (!strncmp(tag, taglist[j], MAX_TAG_LENGTH)) {
                                        // We already have this tag.  Start over.
                                        free(tag);
+                                       last_char = data[i-1];
                                        goto tag_scan_start;
                                }
                        }
                        taglist[n_tags] = tag;
                        n_tags++;
+                       last_char = data[i-1];
                        // We goto here so i doesn't get incremented
                        goto tag_scan_start;
                }
+               last_char = data[i];
        }
 
        for (i = 0; i < n_tags; i++) {