X-Git-Url: http://git.bytex64.net/?a=blobdiff_plain;f=http%2Fhttp_blerg.c;fp=http%2Fhttp_blerg.c;h=b790183b2715e9995be3c6c28d5b2a5a43b579a1;hb=3d27274b36b44816c736ea8a411341b5a36556f9;hp=73f88fe9393263a9f94771bcd7ee7577eee15ea4;hpb=1cf0f1ebfbd5b5a621af2a49ac0328fd0cec4bf4;p=blerg.git diff --git a/http/http_blerg.c b/http/http_blerg.c index 73f88fe..b790183 100644 --- a/http/http_blerg.c +++ b/http/http_blerg.c @@ -7,14 +7,9 @@ #include "tags.h" #include "auth.h" #include "canned_responses.h" -#include "http.h" +#include "app.h" #include "config.h" -#define URL_INFO_AUTHOR 0x1 -#define URL_INFO_RECORD 0x2 -#define URL_INFO_RECORD_TO 0x4 -#define DERP "DERP DERP DERP" - yajl_gen_config yajl_c = { 0, 0 }; struct create_state { @@ -46,78 +41,6 @@ struct tag_state { int done; }; -int parse_url_info(const char *url, struct url_info *info) { - const char *c; - int len; - info->contents = 0; - - c = strchr(url, '/'); - if (c == NULL) { - len = strlen(url); - } else { - len = c - url; - } - if (len == 0) - return 0; - memcpy(info->author, url, len); - info->author[len] = 0; - info->contents |= URL_INFO_AUTHOR; - - if (c == NULL || c[1] == 0) - return info->contents; - - info->record = strtoull(c + 1, NULL, 10); - info->contents |= URL_INFO_RECORD; - - c = strchr(c, '-'); - if (c == NULL || c[1] == 0) - return info->contents; - - info->record_to = strtoull(c + 1, NULL, 10); - info->contents |= URL_INFO_RECORD_TO; - - return info->contents; -} - -uint64_t *make_sequential_list(uint64_t from, uint64_t to) { - uint64_t len = to - from + 1; - uint64_t *list = malloc(len * sizeof(uint64_t)); - uint64_t i; - - for (i = 0; i < len; i++) { - list[i] = from + i; - } - - return list; -} - -void json_generate_one_record(yajl_gen g, const char *author, struct blerg *b, uint64_t record) { - char *data; - char number[21]; - int len; - - if (!blerg_fetch(b, record, &data, &len)) { - fprintf(stderr, "Could not fetch record\n"); - return; - } - - yajl_gen_map_open(g); - if (author != NULL) { - yajl_gen_string(g, "author", 6); - yajl_gen_string(g, author, strlen(author)); - } - yajl_gen_string(g, "record", 6); - snprintf(number, 21, "%llu", record); - yajl_gen_string(g, number, strlen(number)); - yajl_gen_string(g, "timestamp", 9); - yajl_gen_integer(g, blerg_get_timestamp(b, record)); - yajl_gen_string(g, "data", 4); - yajl_gen_string(g, data, len); - yajl_gen_map_close(g); - - free(data); -} - ssize_t GET_generate_list(void *cls, uint64_t pos, char *buf, size_t max) { struct get_state *gs = cls; const unsigned char *ybuf;