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 int _store(struct blerg *ptr, const char *data, int length(data))
55 RETVAL = blerg_store(ptr, data, XSauto_length_of_data);
59 const char * _fetch(struct blerg *ptr, int record)
65 n = blerg_fetch(ptr, record, &buf, &buflen);
69 XPUSHs(sv_2mortal(newSVpvn(buf, buflen)));
72 const char * _get_record_count(struct blerg *ptr)
78 count = blerg_get_record_count(ptr);
79 n = snprintf(buf, 21, "%llu", count);
80 XPUSHs(sv_2mortal(newSVpv(buf, n)));
82 time_t _get_timestamp(struct blerg *ptr, int record)
84 RETVAL = blerg_get_timestamp(ptr, record);
88 int _set_subscription_mark(struct blerg *ptr)
90 RETVAL = blerg_set_subscription_mark(ptr);
94 const char * _get_subscription_mark(struct blerg *ptr)
100 mark = blerg_get_subscription_mark(ptr);
101 n = snprintf(buf, 21, "%llu", mark);
102 XPUSHs(sv_2mortal(newSVpv(buf, n)));
104 int _set_mute(struct blerg *ptr, int v)
106 RETVAL = blerg_set_mute(ptr, v);
110 int _get_mute(struct blerg *ptr)
112 RETVAL = blerg_get_mute(ptr);
116 void tag_list(const char *tag, const char *str_offset, int direction)
119 struct blergref *list;
123 offset = strtoull(str_offset, NULL, 0);
124 list = tag_list(tag, offset, &count, direction);
131 tmp = blergref_to_perl_hash(&list[i]);
132 XPUSHs(sv_2mortal(newRV_noinc((SV*)tmp)));
137 int subscription_add(const char *from, const char *to)
139 RETVAL = subscription_add(from, to);
143 int subscription_remove(const char *from, const char *to)
145 RETVAL = subscription_remove(from, to);
149 void subscription_list(const char *author, const char *str_offset, int direction)
152 struct blergref *list;
156 offset = strtoull(str_offset, NULL, 0);
157 list = subscription_list(author, offset, &count, direction);
164 tmp = blergref_to_perl_hash(&list[i]);
165 XPUSHs(sv_2mortal(newRV_noinc((SV*)tmp)));
170 int valid_tag_name(const char *name)
172 int valid_name(const char *name)