X-Git-Url: https://git.sesse.net/?p=itkacl;a=blobdiff_plain;f=perl-itkacl-2.2%2Fitkacl.i;fp=perl-itkacl-2.2%2Fitkacl.i;h=4523e81b8ccccd55ebdbe29827d0d87c67bc86bd;hp=0000000000000000000000000000000000000000;hb=5ea73ea3a1ffa23ca598fac117830664b66a2ebf;hpb=55f933b88c9d9992b1ec0ed7c13a621032f7637d diff --git a/perl-itkacl-2.2/itkacl.i b/perl-itkacl-2.2/itkacl.i new file mode 100644 index 0000000..4523e81 --- /dev/null +++ b/perl-itkacl-2.2/itkacl.i @@ -0,0 +1,44 @@ +/* SWIG interface for libitkacl */ +%module itkacl + +%perlcode %{ +_itkacl_init(); +END { + _itkacl_deinit(); +} + +%} + +/* Convert errors to Perl exceptions and keep the interface clean. */ +%inline %{ + #include "itkacl.h" + + struct itkacl_ctx *_ctx = NULL; + + void _itkacl_init() + { + char errmsg[1024]; + _ctx = itkacl_create_ctx(errmsg, sizeof(errmsg)); + if (_ctx == NULL) + die(errmsg); + } + + void _itkacl_deinit() + { + itkacl_free_ctx(_ctx); + } + + int check(char *realm, char *user) + { + char errmsg[1024]; + int ret = itkacl_check_with_ctx(_ctx, realm, user, errmsg, 1024); + + /* printf("check '%s' vs. '%s' gave %d\n", user, realm, ret); */ + if (ret == -1) + die(errmsg); + else + return (ret == 0); + } + +%} +