Add RSS CGI, also quite a lot of refactoring
[blerg.git] / common / app.c
1 #include <stdio.h>
2 #include <string.h>
3 #include <stdlib.h>
4 #include "app.h"
5
6 int parse_url_info(const char *url, struct url_info *info) {
7         const char *c;
8         int len;
9         info->contents = 0;
10
11         c = strchr(url, '/');
12         if (c == NULL) {
13                 len = strlen(url);
14         } else {
15                 len = c - url;
16         }
17         if (len == 0)
18                 return 0;
19         memcpy(info->author, url, len);
20         info->author[len] = 0;
21         info->contents |= URL_INFO_AUTHOR;
22
23         if (c == NULL || c[1] == 0)
24                 return info->contents;
25
26         info->record = strtoull(c + 1, NULL, 10);
27         info->contents |= URL_INFO_RECORD;
28
29         c = strchr(c, '-');
30         if (c == NULL || c[1] == 0)
31                 return info->contents;
32
33         info->record_to = strtoull(c + 1, NULL, 10);
34         info->contents |= URL_INFO_RECORD_TO;
35
36         return info->contents;
37 }
38
39 uint64_t *make_sequential_list(uint64_t from, uint64_t to) {
40         uint64_t len = to - from + 1;
41         uint64_t *list = malloc(len * sizeof(uint64_t));
42         uint64_t i;
43
44         for (i = 0; i < len; i++) {
45                 list[i] = from + i;
46         }
47
48         return list;
49 }