8 #include "database/database.h"
9 #include "database/blergref.h"
10 #include "database/tags.h"
11 #include "database/subscription.h"
12 #include "database/util.h"
13 #include "common/auth.h"
15 #include "const-c.inc"
17 HV * blergref_to_perl_hash(struct blergref *list) {
23 hv_store(tmp, "author", 6, newSVpv(list->author, 0), 0);
24 n = snprintf(buf, 21, "%llu", list->record);
25 hv_store(tmp, "record", 6, newSVpv(buf, n), 0);
30 MODULE = Blerg::Database PACKAGE = Blerg::Database
37 RETVAL = blerg_init();
41 int exists(const char *name)
43 RETVAL = blerg_exists(name);
47 struct blerg * _open(const char *name)
49 RETVAL = blerg_open(name);
53 int _close(struct blerg *ptr)
55 RETVAL = blerg_close(ptr);
59 const char * _store(struct blerg *ptr, const char *data, int length(data))
66 record = blerg_store(ptr, data, XSauto_length_of_data);
67 n = snprintf(buf, 21, "%llu", record);
68 XPUSHs(sv_2mortal(newSVpv(buf, n)));
70 const char * _fetch(struct blerg *ptr, const char *str_record)
77 record = strtoull(str_record, NULL, 0);
78 n = blerg_fetch(ptr, record, &buf, &buflen);
82 XPUSHs(sv_2mortal(newSVpvn(buf, buflen)));
85 const char * _get_record_count(struct blerg *ptr)
91 count = blerg_get_record_count(ptr);
92 n = snprintf(buf, 21, "%llu", count);
93 XPUSHs(sv_2mortal(newSVpv(buf, n)));
95 time_t _get_timestamp(struct blerg *ptr, const char *str_record)
99 record = strtoull(str_record, NULL, 0);
100 RETVAL = blerg_get_timestamp(ptr, record);
104 int _set_subscription_mark(struct blerg *ptr)
106 RETVAL = blerg_set_subscription_mark(ptr);
110 const char * _get_subscription_mark(struct blerg *ptr)
116 mark = blerg_get_subscription_mark(ptr);
117 n = snprintf(buf, 21, "%llu", mark);
118 XPUSHs(sv_2mortal(newSVpv(buf, n)));
120 int _set_status(struct blerg *ptr, int status, int v)
122 RETVAL = blerg_set_status(ptr, status, v);
126 int _get_status(struct blerg *ptr, int status)
128 RETVAL = blerg_get_status(ptr, status);
132 void tag_list(const char *tag, const char *str_offset, int direction)
135 struct blergref *list;
139 offset = strtoull(str_offset, NULL, 0);
141 list = tag_list(tag, offset, &count, direction);
148 tmp = blergref_to_perl_hash(&list[i]);
149 XPUSHs(sv_2mortal(newRV_noinc((SV*)tmp)));
154 int subscription_add(const char *from, const char *to)
156 int subscription_remove(const char *from, const char *to)
158 void _subscription_list(const char *author, const char *str_offset, int direction)
161 struct blergref *list;
165 offset = strtoull(str_offset, NULL, 0);
167 list = subscription_list(author, offset, &count, direction);
174 tmp = blergref_to_perl_hash(&list[i]);
175 XPUSHs(sv_2mortal(newRV_noinc((SV*)tmp)));
180 int valid_tag_name(const char *name)
182 int valid_name(const char *name)
184 int auth_set_password(const char *username, const char *password)
186 int auth_check_password(const char *username, const char *password)
188 char * auth_login(const char *username, const char *password)
192 token = auth_login(username, password);
194 XPUSHs(sv_2mortal(newSVpv(token, TOKEN_SIZE * 2)));
200 int auth_logout(const char *username, const char *token)
202 int auth_check_token(const char *username, const char *given_token)