projects
/
blerg.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Add some subscription (a.k.a. "follow") functionality
[blerg.git]
/
database
/
tags.c
diff --git
a/database/tags.c
b/database/tags.c
index
1911ac8
..
d15f8b8
100644
(file)
--- a/
database/tags.c
+++ b/
database/tags.c
@@
-1,3
+1,6
@@
+/* Blerg is (C) 2011 The Dominion of Awesome, and is distributed under a
+ * BSD-style license. Please see the COPYING file for details.
+ */
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
@@
-8,28
+11,27
@@
#include <sys/file.h>
#include <sys/mman.h>
#include "tags.h"
#include <sys/file.h>
#include <sys/mman.h>
#include "tags.h"
+#include "util.h"
+#include "database.h"
#include "config.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 == '_')
int tag_scan(const char *author, const char *data, int len, uint64_t record) {
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:
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;
}
int begin = i;
int start = ++i;
fprintf(stderr, "Too many tags in message\n");
break;
}
int begin = i;
int start = ++i;
- while (i < len &&
TAG
_CHAR(data[i]) && (i - start < MAX_TAG_LENGTH)) {
+ while (i < len &&
VALID
_CHAR(data[i]) && (i - start < MAX_TAG_LENGTH)) {
i++;
}
if (start - i == 0) continue;
i++;
}
if (start - i == 0) continue;
@@
-39,14
+41,17
@@
tag_scan_start:
if (!strncmp(tag, taglist[j], MAX_TAG_LENGTH)) {
// We already have this tag. Start over.
free(tag);
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++;
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;
}
// We goto here so i doesn't get incremented
goto tag_scan_start;
}
+ last_char = data[i];
}
for (i = 0; i < n_tags; i++) {
}
for (i = 0; i < n_tags; i++) {
@@
-92,12
+97,15
@@
int tag_add(const char *author, const char *tag, uint64_t record) {
return 1;
}
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,
in
t *count, int direction) {
char filename[512];
struct stat st;
struct tag *taglist;
struct tag *retlist;
uint64_t n_tag_records;
char filename[512];
struct stat st;
struct tag *taglist;
struct tag *retlist;
uint64_t n_tag_records;
+
+ if (!valid_tag_name(tag + 1))
+ return NULL;
switch(tag[0]) {
case '#':
switch(tag[0]) {
case '#':
@@
-108,7
+116,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);
break;
default:
fprintf(stderr, "Invalid tag type: %s\n", tag);
- return
0
;
+ return
NULL
;
}
int tag_fd = open(filename, O_RDONLY, 0600);
}
int tag_fd = open(filename, O_RDONLY, 0600);
@@
-164,16
+172,11
@@
tag_list_open_failed:
}
int tag_exists(const char *tag) {
}
int tag_exists(const char *tag) {
- int taglen = strlen(tag);
char filename[512];
char filename[512];
- if (taglen < 2) {
- fprintf(stderr, "Tag too short\n");
- return 0;
- } else if (taglen > 33) {
- fprintf(stderr, "Tag too long\n");
+ if (!valid_tag_name(tag + 1))
return 0;
return 0;
- }
+
if (!(tag[0] == '@' || tag[0] == '#')) {
fprintf(stderr, "Invalid tag: %s\n", tag);
return 0;
if (!(tag[0] == '@' || tag[0] == '#')) {
fprintf(stderr, "Invalid tag: %s\n", tag);
return 0;