Genericize and extend url_info
The url_info struct's author member was too small to snarf 64-byte tags,
so that field was renamed to 'name' and extended. parse_url_info also
now checks the maximum length.
}
ret = parse_url_info(path + 5, &info);
- if ((ret & URL_INFO_AUTHOR) == 0) {
+ if ((ret & URL_INFO_NAME) == 0) {
respond_404();
exit(0);
}
- if (!blerg_exists(info.author)) {
+ if (!blerg_exists(info.name)) {
respond_404();
exit(0);
}
- struct blerg *b = blerg_open(info.author);
+ struct blerg *b = blerg_open(info.name);
if ((ret & URL_INFO_RECORD) && (ret & URL_INFO_RECORD_TO)) {
respond_for_range(b, info.record, info.record_to);
}
ret = parse_url_info(path + 5, &info);
- if ((ret & URL_INFO_AUTHOR) == 0) {
+ if ((ret & URL_INFO_NAME) == 0) {
respond_404();
exit(0);
}
- if (info.author[0] == 'H')
- info.author[0] = '#';
- if (!tag_exists(info.author)) {
+ if (info.name[0] == 'H')
+ info.name[0] = '#';
+ if (!tag_exists(info.name)) {
respond_404();
exit(0);
}
int recs = 50;
- struct tag *taglist = tag_list(info.author, 0, &recs, -1);
+ struct tag *taglist = tag_list(info.name, 0, &recs, -1);
if (recs == 0) {
respond_simple_data("[]", 2);
}
ret = parse_url_info(path + 6, &info);
- if ((ret & URL_INFO_AUTHOR) == 0) {
+ if ((ret & URL_INFO_NAME) == 0) {
respond_404();
exit(0);
}
- if (!blerg_exists(info.author)) {
+ if (!blerg_exists(info.name)) {
respond_404();
exit(0);
}
- struct blerg *b = blerg_open(info.author);
+ struct blerg *b = blerg_open(info.name);
uint64_t record_count = blerg_get_record_count(b);
blerg_close(b);
}
ret = parse_url_info(path + 1, &info);
- if ((ret & URL_INFO_AUTHOR) == 0) {
+ if ((ret & URL_INFO_NAME) == 0) {
respond_404();
exit(0);
}
- if (!blerg_exists(info.author)) {
+ if (!blerg_exists(info.name)) {
respond_404();
exit(0);
}
printf("Content-type: application/rss+xml\r\n\r\n");
- fprint_rss(stdout, info.author);
+ fprint_rss(stdout, info.name);
}
}
if (len == 0)
return 0;
- memcpy(info->author, url, len);
- info->author[len] = 0;
- info->contents |= URL_INFO_AUTHOR;
+ if (len > MAX_TAG_LENGTH)
+ len = MAX_TAG_LENGTH;
+ memcpy(info->name, url, len);
+ info->name[len] = 0;
+ info->contents |= URL_INFO_NAME;
if (c == NULL || c[1] == 0)
return info->contents;
#include <yajl/yajl_gen.h>
#include "database.h"
+#include "config.h"
#define REALM "Blerg"
#define JSON_SUCCESS "{\"status\": \"success\"}"
#define JSON_FAILURE "{\"status\": \"failure\"}"
-#define URL_INFO_AUTHOR 0x1
+#define URL_INFO_NAME 0x1
#define URL_INFO_RECORD 0x2
#define URL_INFO_RECORD_TO 0x4
#define DERP "DERP DERP DERP"
struct url_info {
unsigned int contents;
- char author[33];
+ char name[MAX_TAG_LENGTH + 1];
uint64_t record;
uint64_t record_to;
};
struct tag *retlist;
uint64_t n_tag_records;
- if (!valid_name(tag + 1))
+ if (!valid_tag_name(tag + 1))
return NULL;
switch(tag[0]) {
int tag_exists(const char *tag) {
char filename[512];
- if (!valid_name(tag + 1))
+ if (!valid_tag_name(tag + 1))
return 0;
if (!(tag[0] == '@' || tag[0] == '#')) {
*/
#include "database.h"
+#include "config.h"
-int valid_name(const char *name) {
+int valid_name_len(const char *name, int maxlength) {
int i;
- for (i = 0; i < 32; i++) {
+ for (i = 0; i < maxlength; i++) {
if (name[i] == 0) break;
if (!VALID_CHAR(name[i])) return 0;
}
- if (i >= 32)
+ if (i >= maxlength)
return 0;
return 1;
}
+
+int valid_tag_name(const char *name) {
+ return valid_name_len(name, MAX_TAG_LENGTH);
+}
+
+int valid_name(const char *name) {
+ return valid_name_len(name, 32);
+}
#ifndef _UTIL_H
#define _UTIL_H
+int valid_tag_name(const char *name);
int valid_name(const char *name);
#endif /* _UTIL_H */
return respond_404(connection);
ret = parse_url_info(url + 5, &info);
- if ((ret & URL_INFO_AUTHOR) == 0)
+ if ((ret & URL_INFO_NAME) == 0)
return respond_404(connection);
- if (!blerg_exists(info.author))
+ if (!blerg_exists(info.name))
return respond_404(connection);
*ptr == NULL;
- struct blerg *b = blerg_open(info.author);
+ struct blerg *b = blerg_open(info.name);
if ((ret & URL_INFO_RECORD) && (ret & URL_INFO_RECORD_TO)) {
response = create_response_for_range(b, info.record, info.record_to);
return respond_404(connection);
ret = parse_url_info(url + 5, &info);
- if ((ret & URL_INFO_AUTHOR) == 0)
+ if ((ret & URL_INFO_NAME) == 0)
return respond_404(connection);
- if (!tag_exists(info.author))
+ if (!tag_exists(info.name))
return respond_404(connection);
int recs = 50;
- struct tag *taglist = tag_list(info.author, 0, &recs, -1);
+ struct tag *taglist = tag_list(info.name, 0, &recs, -1);
if (recs == 0) {
response = MHD_create_response_from_data(2, "[]", MHD_NO, MHD_NO);
return respond_404(connection);
ret = parse_url_info(url + 6, &info);
- if ((ret & URL_INFO_AUTHOR) == 0)
+ if ((ret & URL_INFO_NAME) == 0)
return respond_404(connection);
- if (!blerg_exists(info.author))
+ if (!blerg_exists(info.name))
return respond_404(connection);
*ptr == NULL;
- struct blerg *b = blerg_open(info.author);
+ struct blerg *b = blerg_open(info.name);
uint64_t record_count = blerg_get_record_count(b);
blerg_close(b);