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"
14 #include "const-c.inc"
16 HV * blergref_to_perl_hash(struct blergref *list) {
22 hv_store(tmp, "author", 6, newSVpv(list->author, 0), 0);
23 n = snprintf(buf, 21, "%llu", list->record);
24 hv_store(tmp, "record", 6, newSVpv(buf, n), 0);
29 MODULE = Blerg::Database PACKAGE = Blerg::Database
34 int exists(const char *name)
36 RETVAL = blerg_exists(name);
40 struct blerg * _open(const char *name)
42 RETVAL = blerg_open(name);
46 int _close(struct blerg *ptr)
48 RETVAL = blerg_close(ptr);
52 const char * _store(struct blerg *ptr, const char *data, int length(data))
59 record = blerg_store(ptr, data, XSauto_length_of_data);
60 n = snprintf(buf, 21, "%llu", record);
61 XPUSHs(sv_2mortal(newSVpv(buf, n)));
63 const char * _fetch(struct blerg *ptr, const char *str_record)
70 record = strtoull(str_record, NULL, 0);
71 n = blerg_fetch(ptr, record, &buf, &buflen);
75 XPUSHs(sv_2mortal(newSVpvn(buf, buflen)));
78 const char * _get_record_count(struct blerg *ptr)
84 count = blerg_get_record_count(ptr);
85 n = snprintf(buf, 21, "%llu", count);
86 XPUSHs(sv_2mortal(newSVpv(buf, n)));
88 time_t _get_timestamp(struct blerg *ptr, const char *str_record)
92 record = strtoull(str_record, NULL, 0);
93 RETVAL = blerg_get_timestamp(ptr, record);
97 int _set_subscription_mark(struct blerg *ptr)
99 RETVAL = blerg_set_subscription_mark(ptr);
103 const char * _get_subscription_mark(struct blerg *ptr)
109 mark = blerg_get_subscription_mark(ptr);
110 n = snprintf(buf, 21, "%llu", mark);
111 XPUSHs(sv_2mortal(newSVpv(buf, n)));
113 int _set_mute(struct blerg *ptr, int v)
115 RETVAL = blerg_set_mute(ptr, v);
119 int _get_mute(struct blerg *ptr)
121 RETVAL = blerg_get_mute(ptr);
125 void tag_list(const char *tag, const char *str_offset, int direction)
128 struct blergref *list;
132 offset = strtoull(str_offset, NULL, 0);
133 list = tag_list(tag, offset, &count, direction);
140 tmp = blergref_to_perl_hash(&list[i]);
141 XPUSHs(sv_2mortal(newRV_noinc((SV*)tmp)));
146 int subscription_add(const char *from, const char *to)
148 RETVAL = subscription_add(from, to);
152 int subscription_remove(const char *from, const char *to)
154 RETVAL = subscription_remove(from, 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);
166 list = subscription_list(author, offset, &count, direction);
173 tmp = blergref_to_perl_hash(&list[i]);
174 XPUSHs(sv_2mortal(newRV_noinc((SV*)tmp)));
179 int valid_tag_name(const char *name)
181 int valid_name(const char *name)