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
35 int exists(const char *name)
37 RETVAL = blerg_exists(name);
41 struct blerg * _open(const char *name)
43 RETVAL = blerg_open(name);
47 int _close(struct blerg *ptr)
49 RETVAL = blerg_close(ptr);
53 const char * _store(struct blerg *ptr, const char *data, int length(data))
60 record = blerg_store(ptr, data, XSauto_length_of_data);
61 n = snprintf(buf, 21, "%llu", record);
62 XPUSHs(sv_2mortal(newSVpv(buf, n)));
64 const char * _fetch(struct blerg *ptr, const char *str_record)
71 record = strtoull(str_record, NULL, 0);
72 n = blerg_fetch(ptr, record, &buf, &buflen);
76 XPUSHs(sv_2mortal(newSVpvn(buf, buflen)));
79 const char * _get_record_count(struct blerg *ptr)
85 count = blerg_get_record_count(ptr);
86 n = snprintf(buf, 21, "%llu", count);
87 XPUSHs(sv_2mortal(newSVpv(buf, n)));
89 time_t _get_timestamp(struct blerg *ptr, const char *str_record)
93 record = strtoull(str_record, NULL, 0);
94 RETVAL = blerg_get_timestamp(ptr, record);
98 int _set_subscription_mark(struct blerg *ptr)
100 RETVAL = blerg_set_subscription_mark(ptr);
104 const char * _get_subscription_mark(struct blerg *ptr)
110 mark = blerg_get_subscription_mark(ptr);
111 n = snprintf(buf, 21, "%llu", mark);
112 XPUSHs(sv_2mortal(newSVpv(buf, n)));
114 int _set_mute(struct blerg *ptr, int v)
116 RETVAL = blerg_set_mute(ptr, v);
120 int _get_mute(struct blerg *ptr)
122 RETVAL = blerg_get_mute(ptr);
126 void tag_list(const char *tag, const char *str_offset, int direction)
129 struct blergref *list;
133 offset = strtoull(str_offset, NULL, 0);
134 list = tag_list(tag, offset, &count, direction);
141 tmp = blergref_to_perl_hash(&list[i]);
142 XPUSHs(sv_2mortal(newRV_noinc((SV*)tmp)));
147 int subscription_add(const char *from, const char *to)
149 int subscription_remove(const char *from, const char *to)
151 void _subscription_list(const char *author, const char *str_offset, int direction)
154 struct blergref *list;
158 offset = strtoull(str_offset, NULL, 0);
159 list = subscription_list(author, offset, &count, direction);
166 tmp = blergref_to_perl_hash(&list[i]);
167 XPUSHs(sv_2mortal(newRV_noinc((SV*)tmp)));
172 int valid_tag_name(const char *name)
174 int valid_name(const char *name)
176 int auth_set_password(const char *username, const char *password)
178 int auth_check_password(const char *username, const char *password)
180 char * auth_login(const char *username, const char *password)
184 token = auth_login(username, password);
186 XPUSHs(sv_2mortal(newSVpv(token, TOKEN_SIZE * 2)));
192 int auth_logout(const char *username, const char *token)
194 int auth_check_token(const char *username, const char *given_token)