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 "database/configuration.h"
14 #include "common/auth.h"
16 #include "const-c.inc"
18 HV * blergref_to_perl_hash(struct blergref *list) {
24 hv_store(tmp, "author", 6, newSVpv(list->author, 0), 0);
25 n = snprintf(buf, 21, "%llu", list->record);
26 hv_store(tmp, "record", 6, newSVpv(buf, n), 0);
31 MODULE = Blerg::Database PACKAGE = Blerg::Database
38 RETVAL = blerg_init();
42 int exists(const char *name)
44 RETVAL = blerg_exists(name);
48 struct blerg * _open(const char *name)
50 RETVAL = blerg_open(name);
54 int _close(struct blerg *ptr)
56 RETVAL = blerg_close(ptr);
60 const char * _store(struct blerg *ptr, const char *data, int length(data))
67 record = blerg_store(ptr, data, XSauto_length_of_data);
68 n = snprintf(buf, 21, "%llu", record);
69 XPUSHs(sv_2mortal(newSVpv(buf, n)));
71 const char * _fetch(struct blerg *ptr, const char *str_record)
78 record = strtoull(str_record, NULL, 0);
79 n = blerg_fetch(ptr, record, &buf, &buflen);
83 XPUSHs(sv_2mortal(newSVpvn(buf, buflen)));
86 const char * _get_record_count(struct blerg *ptr)
92 count = blerg_get_record_count(ptr);
93 n = snprintf(buf, 21, "%llu", count);
94 XPUSHs(sv_2mortal(newSVpv(buf, n)));
96 time_t _get_timestamp(struct blerg *ptr, const char *str_record)
100 record = strtoull(str_record, NULL, 0);
101 RETVAL = blerg_get_timestamp(ptr, record);
105 int _set_subscription_mark(struct blerg *ptr)
107 RETVAL = blerg_set_subscription_mark(ptr);
111 const char * _get_subscription_mark(struct blerg *ptr)
117 mark = blerg_get_subscription_mark(ptr);
118 n = snprintf(buf, 21, "%llu", mark);
119 XPUSHs(sv_2mortal(newSVpv(buf, n)));
121 int _set_status(struct blerg *ptr, int status, int v)
123 RETVAL = blerg_set_status(ptr, status, v);
127 int _get_status(struct blerg *ptr, int status)
129 RETVAL = blerg_get_status(ptr, status);
133 void tag_list(const char *tag, const char *str_offset, int direction)
136 struct blergref *list;
140 offset = strtoull(str_offset, NULL, 0);
142 list = tag_list(tag, offset, &count, direction);
149 tmp = blergref_to_perl_hash(&list[i]);
150 XPUSHs(sv_2mortal(newRV_noinc((SV*)tmp)));
155 int subscription_add(const char *from, const char *to)
157 int subscription_remove(const char *from, const char *to)
159 void _subscription_list(const char *author, const char *str_offset, int direction)
162 struct blergref *list;
166 offset = strtoull(str_offset, NULL, 0);
168 list = subscription_list(author, offset, &count, direction);
175 tmp = blergref_to_perl_hash(&list[i]);
176 XPUSHs(sv_2mortal(newRV_noinc((SV*)tmp)));
181 int valid_tag_name(const char *name)
183 int valid_name(const char *name)
185 int auth_set_password(const char *username, const char *password)
187 int auth_check_password(const char *username, const char *password)
189 char * auth_login(const char *username, const char *password)
193 token = auth_login(username, password);
195 XPUSHs(sv_2mortal(newSVpv(token, TOKEN_SIZE * 2)));
201 int auth_logout(const char *username, const char *token)
203 int auth_check_token(const char *username, const char *given_token)
205 void auth_get_counter(const char *username)
207 uint32_t counter = 0;
209 if (auth_get_counter(username, &counter)) {
210 XPUSHs(sv_2mortal(newSVuv(counter)));
220 hv_store(confhash, "base_path", 9, newSVpv(blergconf.base_path, 0), 0);
221 hv_store(confhash, "data_path", 9, newSVpv(blergconf.data_path, 0), 0);
222 hv_store(confhash, "hash_tags_path", 14, newSVpv(blergconf.hash_tags_path, 0), 0);
223 hv_store(confhash, "ref_tags_path", 13, newSVpv(blergconf.ref_tags_path, 0), 0);
225 XPUSHs(sv_2mortal(newRV_noinc((SV*)confhash)));