]> git.sesse.net Git - itkacl/blobdiff - perl-itkacl-2.2/itkacl.i
Use the new library context system in the Perl module.
[itkacl] / perl-itkacl-2.2 / itkacl.i
diff --git a/perl-itkacl-2.2/itkacl.i b/perl-itkacl-2.2/itkacl.i
new file mode 100644 (file)
index 0000000..4523e81
--- /dev/null
@@ -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);
+       }
+       
+%}
+