9 #include "database/database.h"
10 #include "database/blergref.h"
11 #include "database/tags.h"
12 #include "database/subscription.h"
13 #include "database/util.h"
15 HV * blergref_to_perl_hash(struct blergref *list) {
21 hv_store(tmp, "author", 6, newSVpv(list->author, 0), 0);
22 n = snprintf(buf, 21, "%llu", list->record);
23 hv_store(tmp, "record", 6, newSVpv(buf, n), 0);
28 MODULE = Blerg::Database PACKAGE = Blerg::Database
33 int exists(const char *name)
35 RETVAL = blerg_exists(name);
39 struct blerg * _open(const char *name)
41 RETVAL = blerg_open(name);
45 int _close(struct blerg *ptr)
47 RETVAL = blerg_close(ptr);
51 int _store(struct blerg *ptr, const char *data, int length(data))
54 RETVAL = blerg_store(ptr, data, XSauto_length_of_data);
58 const char * _fetch(struct blerg *ptr, int record)
64 n = blerg_fetch(ptr, record, &buf, &buflen);
68 XPUSHs(sv_2mortal(newSVpvn(buf, buflen)));
71 const char * _get_record_count(struct blerg *ptr)
77 count = blerg_get_record_count(ptr);
78 n = snprintf(buf, 21, "%llu", count);
79 XPUSHs(sv_2mortal(newSVpv(buf, n)));
81 time_t _get_timestamp(struct blerg *ptr, int record)
83 RETVAL = blerg_get_timestamp(ptr, record);
87 int _set_subscription_mark(struct blerg *ptr)
89 RETVAL = blerg_set_subscription_mark(ptr);
93 const char * _get_subscription_mark(struct blerg *ptr)
99 mark = blerg_get_subscription_mark(ptr);
100 n = snprintf(buf, 21, "%llu", mark);
101 XPUSHs(sv_2mortal(newSVpv(buf, n)));
103 int _set_mute(struct blerg *ptr, int v)
105 RETVAL = blerg_set_mute(ptr, v);
109 int _get_mute(struct blerg *ptr)
111 RETVAL = blerg_get_mute(ptr);
115 void _tag_list(const char *tag, const char *str_offset, int direction)
118 struct blergref *list;
122 offset = strtoull(str_offset, NULL, 0);
123 list = tag_list(tag, offset, &count, direction);
130 tmp = blergref_to_perl_hash(&list[i]);
131 XPUSHs(sv_2mortal(newRV_noinc((SV*)tmp)));
136 int subscription_add(const char *from, const char *to)
138 RETVAL = subscription_add(from, to);
142 int subscription_remove(const char *from, const char *to)
144 RETVAL = subscription_remove(from, to);
148 void subscription_list(const char *author, const char *str_offset, int direction)
151 struct blergref *list;
155 offset = strtoull(str_offset, NULL, 0);
156 list = subscription_list(author, offset, &count, direction);
163 tmp = blergref_to_perl_hash(&list[i]);
164 XPUSHs(sv_2mortal(newRV_noinc((SV*)tmp)));
169 int valid_tag_name(const char *name)
171 int valid_name(const char *name)