X-Git-Url: http://git.bytex64.net/?a=blobdiff_plain;f=lib%2Fperl%2FBlerg-Database%2FDatabase.xs;h=1ad9fa65b892b4982c1cb5ebca0eea412fe37549;hb=ac2c65c84fed370fb4dc21e40dce5b407e230821;hp=a26e736f24bfca928f05dde0e025af30ae1b550c;hpb=71d846fac84f2266b1a4a0324f2932a0435aab1d;p=blerg.git diff --git a/lib/perl/Blerg-Database/Database.xs b/lib/perl/Blerg-Database/Database.xs index a26e736..1ad9fa6 100644 --- a/lib/perl/Blerg-Database/Database.xs +++ b/lib/perl/Blerg-Database/Database.xs @@ -4,14 +4,28 @@ #include "ppport.h" -#include "const-c.inc" - +#include "config.h" #include "database/database.h" #include "database/blergref.h" #include "database/tags.h" #include "database/subscription.h" #include "database/util.h" +#include "const-c.inc" + +HV * blergref_to_perl_hash(struct blergref *list) { + HV *tmp; + char buf[21]; + int n; + + tmp = newHV(); + hv_store(tmp, "author", 6, newSVpv(list->author, 0), 0); + n = snprintf(buf, 21, "%llu", list->record); + hv_store(tmp, "record", 6, newSVpv(buf, n), 0); + + return tmp; +} + MODULE = Blerg::Database PACKAGE = Blerg::Database INCLUDE: const-xs.inc @@ -99,13 +113,12 @@ int _get_mute(struct blerg *ptr) OUTPUT: RETVAL -void _tag_list(const char *tag, const char *str_offset, int direction) +void tag_list(const char *tag, const char *str_offset, int direction) INIT: HV * tmp; struct blergref *list; uint64_t offset; - char buf[21]; - int count, i, n; + int count, i; PPCODE: offset = strtoull(str_offset, NULL, 0); list = tag_list(tag, offset, &count, direction); @@ -115,11 +128,45 @@ void _tag_list(const char *tag, const char *str_offset, int direction) i = count - 1; while (i >= 0) { - tmp = newHV(); - hv_store(tmp, "author", 6, newSVpv(list[i].author, 0), 0); - n = snprintf(buf, 21, "%llu", list[i].record); - hv_store(tmp, "record", 6, newSVpv(buf, n), 0); + tmp = blergref_to_perl_hash(&list[i]); + XPUSHs(sv_2mortal(newRV_noinc((SV*)tmp))); + i--; + } + free(list); + +int subscription_add(const char *from, const char *to) + CODE: + RETVAL = subscription_add(from, to); + OUTPUT: + RETVAL + +int subscription_remove(const char *from, const char *to) + CODE: + RETVAL = subscription_remove(from, to); + OUTPUT: + RETVAL + +void subscription_list(const char *author, const char *str_offset, int direction) + INIT: + HV *tmp; + struct blergref *list; + uint64_t offset; + int count, i; + PPCODE: + offset = strtoull(str_offset, NULL, 0); + list = subscription_list(author, offset, &count, direction); + if (list == NULL) { + XSRETURN_UNDEF; + } + + i = count - 1; + while (i >= 0) { + tmp = blergref_to_perl_hash(&list[i]); XPUSHs(sv_2mortal(newRV_noinc((SV*)tmp))); i--; } free(list); + +int valid_tag_name(const char *name) + +int valid_name(const char *name)