diff options
Diffstat (limited to 'USER/USER.xs')
-rw-r--r-- | USER/USER.xs | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/USER/USER.xs b/USER/USER.xs new file mode 100644 index 0000000..d0bc77c --- /dev/null +++ b/USER/USER.xs @@ -0,0 +1,122 @@ +/* Copyright (C) 2003 MandrakeSoft SA Daouda Lo (daouda at mandrakesoft at com) + * This program is free software; you can redistribute it and/or + * modify it under the same terms as Perl itself. + */ + +#include "EXTERN.h" +#include "perl.h" +#include "XSUB.h" + +#include "ppport.h" + +#include <grp.h> +#include <pwd.h> +#include <stdlib.h> +#include <unistd.h> +#include <glib.h> +#include <libuser/user.h> +#include <libuser/user_private.h> + +typedef struct lu_context* USER__ADMIN; +typedef struct lu_ent* USER__ENT; +typedef struct lu_error* USER__ERR; + +static SV ** +convert_value_array_list(register SV **sp, GValueArray *array) { + GValue *value; + int i; + long l; + STRLEN len; + const char *s; + for (i = 0; (array != NULL) && (i < array->n_values); i++) { + value = g_value_array_get_nth(array, i); + /* If the item is a G_TYPE_LONG, add it as a double. */ + if (G_VALUE_HOLDS_LONG(value)) { + l = g_value_get_long(value); + XPUSHs(sv_2mortal(newSViv(l))); + } else if (G_VALUE_HOLDS_STRING(value)) { + s = g_value_get_string(value); + XPUSHs(sv_2mortal(newSVpv(s, len))); + } + } + return sp; +} +void +convert_to_value( SV *item, GValue *value) { + +} + +MODULE = USER PACKAGE = USER::ADMIN PREFIX = Admin_ + +USER::ADMIN +Admin_new(CLASS) + char *CLASS + CODE: + RETVAL = (USER__ADMIN)safemalloc( sizeof( USER__ADMIN ) ); + if( RETVAL == NULL ){ + warn("unable to malloc USER__ADMIN"); + XSRETURN_UNDEF; + } + OUTPUT: + RETVAL + +void +Admin_DESTROY(self) + USER::ADMIN self + CODE: + lu_end(self); + lu_ctx_free(self) + +void +Admin_lookup_user_name(self, name) + USER::ADMIN self + char *name + PREINIT: + USER::ENT ent; + USER__ERR err; + PPCODE: + ent = lu_ent_new(); + if ( lu_user_lookup_name(self, name, ent, &err)) { + XPUSHs(sv_2mortal(newSViv(ent))) + } else { + /* No such user. Clean up and bug out. */ + lu_ent_free(ent); + } + +MODULE = USER PACKAGE = USER::ENT Prefix = PREFIX_ + +USER::ENT +Ent_new (CLASS) + char *CLASS + CODE: + RETVAL = (USER__ENT)safemalloc( sizeof( USER__ENT ) ); + if( RETVAL == NULL ){ + warn("unable to malloc USER__CTX"); + XSRETURN_UNDEF; + } + OUTPUT: + RETVAL + +void +Ent_DESTROY(self) + USER::ENT self + CODE: + lu_ent_free(self); + +/* Get the names of the modules which had something to do with this object. */ +void +Ent_modules(self) + USER::ENT self + PPCODE: + SP = convert_value_array_list(SP, self->modules); + +void +Ent_add(self, val) + USER::ENT self + char *val + PREINIT: + GValue value; + CODE: + memset(&value, 0, sizeof(value)); + convert_to_value(val, &value); + lu_ent_add() |