diff options
author | Daouda Lo <daouda@mandriva.com> | 2003-05-16 12:40:02 +0000 |
---|---|---|
committer | Daouda Lo <daouda@mandriva.com> | 2003-05-16 12:40:02 +0000 |
commit | 8282c99321d51f1d54177f1e04b36b6e622e7dd3 (patch) | |
tree | 8550404eee52a6118dbcae68adbb07292a8a039c | |
parent | 5b688b33c4541d5b0487ed8bfe4224137b629b0e (diff) | |
download | userdrake-8282c99321d51f1d54177f1e04b36b6e622e7dd3.tar userdrake-8282c99321d51f1d54177f1e04b36b6e622e7dd3.tar.gz userdrake-8282c99321d51f1d54177f1e04b36b6e622e7dd3.tar.bz2 userdrake-8282c99321d51f1d54177f1e04b36b6e622e7dd3.tar.xz userdrake-8282c99321d51f1d54177f1e04b36b6e622e7dd3.zip |
- bless eachiindex of returned ent arrays
-rw-r--r-- | USER/USER.xs | 341 |
1 files changed, 305 insertions, 36 deletions
diff --git a/USER/USER.xs b/USER/USER.xs index c294d06..ff955ea 100644 --- a/USER/USER.xs +++ b/USER/USER.xs @@ -25,7 +25,6 @@ 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); @@ -35,34 +34,47 @@ static SV ** convert_value_array_list(register SV **sp, GValueArray *array) { XPUSHs(sv_2mortal(newSViv(l))); } else if (G_VALUE_HOLDS_STRING(value)) { s = g_value_get_string(value); - XPUSHs(sv_2mortal(newSVpv(s, len))); + XPUSHs(sv_2mortal(newSVpv(s, 0))); } } return sp; } char * -get_name(USER__ENT *ent, const char *attribute) +get_name(USER__ENT *ent, char *attribute) { GValueArray *values; GValue *value; - char *name; + const char *name = NULL; values = lu_ent_get(ent, attribute); - value = gvalue_array_get_nth(values, 0); - strcpy(name, g_value_get_string(value)); + if (values != NULL) { + value = g_value_array_get_nth(values, 0); + if (G_VALUE_HOLDS_STRING(value)) { + name = g_value_get_string(value); + } else if (G_VALUE_HOLDS_LONG(value)) { + name = g_strdup_printf("%ld", g_value_get_long(value)); /*leak*/ + } + } return name; } -static int -get_int(USER__ENT *ent, const char *attribute) +static long +get_int(USER__ENT *ent, char *attribute) { GValueArray *values; GValue *value; - int i; + long i = -1; values = lu_ent_get(ent, attribute); - value = gvalue_array_get_nth(values, 0); + if (values != NULL) { + value = g_value_array_get_nth(values, 0); + if (G_VALUE_HOLDS_LONG(value)) { + i = g_value_get_long(value); + } else if (G_VALUE_HOLDS_STRING(value)) { + i = atol(g_value_get_string(value)); + } + } i = g_value_get_long(value); - return i ? i : -1; + return i; } MODULE = USER PACKAGE = USER::ADMIN PREFIX = Admin_ @@ -84,10 +96,9 @@ void Admin_DESTROY(self) USER::ADMIN *self CODE: - printf("freeing ADMIN"); - if (self) { - lu_end(self); - }; + printf("freeing ADMIN\n"); + if (self) lu_end(self) ; + safefree((char*)self); void Admin_lookup_user_name(self, name) @@ -104,17 +115,17 @@ Admin_lookup_user_name(self, name) } AV * -Admin_users_enumerate_full(self, pattern) +Admin_users_enumerate_full(self) USER::ADMIN *self - char *pattern CODE: int c; USER__ERR *error = NULL; + const char *pattern = NULL; RETVAL = (AV*)sv_2mortal((SV*)newAV()); GPtrArray *accounts; accounts = lu_users_enumerate_full(self, pattern, &error); for (c = 0; (accounts != NULL) && (c < accounts->len); c++) { - if( av_store(RETVAL, c, newSViv(g_ptr_array_index(accounts, c))) == NULL ){ + if( av_store(RETVAL, c, sv_bless(newRV_noinc(newSViv(g_ptr_array_index(accounts, c))), gv_stashpv("USER::ENT", 1))) == NULL ){ warn("XS_UsersEnumerateFull: failed to store elems"); } } @@ -123,18 +134,17 @@ Admin_users_enumerate_full(self, pattern) RETVAL AV * -Admin_groups_enumerate_full(self, pattern) +Admin_groups_enumerate_full(self) USER::ADMIN *self - char *pattern - PREINIT: + CODE: int c; USER__ERR *error = NULL; - CODE: + const char *pattern = NULL; RETVAL = (AV*)sv_2mortal((SV*)newAV()); GPtrArray *accounts; accounts = lu_groups_enumerate_full(self, pattern, &error); for (c = 0; (accounts != NULL) && (c < accounts->len); c++) { - if( av_store( RETVAL, c, newSViv(g_ptr_array_index(accounts, c)) ) == NULL ){ + if( av_store(RETVAL, c, sv_bless(newRV_noinc(newSViv(g_ptr_array_index(accounts, c))), gv_stashpv("USER::ENT", 1))) == NULL ){ warn("XS_UsersEnumerateFull: failed to store elems"); } } @@ -164,12 +174,11 @@ USER::ENT * Ent_new (CLASS) char *CLASS CODE: - RETVAL = (USER__ENT *)safemalloc( sizeof( USER__ENT ) ); + RETVAL = (USER__ENT *)lu_ent_new(); if( RETVAL == NULL ){ warn("unable to malloc USER__ENT"); XSRETURN_UNDEF; - } - RETVAL = lu_ent_new(); + } OUTPUT: RETVAL @@ -177,15 +186,274 @@ void Ent_DESTROY(self) USER::ENT *self CODE: - lu_ent_free(self); - safefree(self); + printf("freeing ENT\n"); + if (self) lu_ent_free(self); + +void +Ent_EntType(self) + USER::ENT *self + CODE: + switch (self->type) { + case lu_invalid: + break; + case lu_user: + XPUSHs(sv_2mortal(newSVpv("user", 0))); + break; + case lu_group: + XPUSHs(sv_2mortal(newSVpv("group", 0))); + break; + default: + break; + } + OUTPUT: + RETVAL + +void +Ent_UserName(self) + USER::ENT *self + PPCODE: + GValueArray *values; + GValue *value; + values = lu_ent_get(self, LU_USERNAME); + if (values != NULL) { + value = g_value_array_get_nth(values, 0); + if (G_VALUE_HOLDS_STRING(value)) { + XPUSHs(sv_2mortal(newSVpv(g_value_get_string(value), 0))); + } else if (G_VALUE_HOLDS_LONG(value)) { + XPUSHs(sv_2mortal(newSVpv(g_strdup_printf("%ld", g_value_get_long(value)), 0))); + } + } + +void +Ent_GroupName(self) + USER::ENT *self + PPCODE: + GValueArray *values; + GValue *value; + values = lu_ent_get(self, LU_GROUPNAME); + if (values != NULL) { + value = g_value_array_get_nth(values, 0); + if (G_VALUE_HOLDS_LONG(value)) { + XPUSHs(sv_2mortal(newSViv(g_value_get_long(value)))); + } else if (G_VALUE_HOLDS_STRING(value)) { + XPUSHs(sv_2mortal(newSViv(atol(g_value_get_string(value))))); + } + } + +void +Ent_Uid(self) + USER::ENT *self + PPCODE: + GValueArray *values; + GValue *value; + values = lu_ent_get(self, LU_UIDNUMBER); + if (values != NULL) { + value = g_value_array_get_nth(values, 0); + if (G_VALUE_HOLDS_LONG(value)) { + XPUSHs(sv_2mortal(newSViv(g_value_get_long(value)))); + } else if (G_VALUE_HOLDS_STRING(value)) { + XPUSHs(sv_2mortal(newSViv(atol(g_value_get_string(value))))); + } + } + +void +Ent_Gid(self) + USER::ENT *self + PPCODE: + GValueArray *values; + GValue *value; + values = lu_ent_get(self, LU_GIDNUMBER); + if (values != NULL) { + value = g_value_array_get_nth(values, 0); + if (G_VALUE_HOLDS_LONG(value)) { + XPUSHs(sv_2mortal(newSViv(g_value_get_long(value)))); + } else if (G_VALUE_HOLDS_STRING(value)) { + XPUSHs(sv_2mortal(newSViv(atol(g_value_get_string(value))))); + } + } + +void +Ent_Gecos(self) + USER::ENT *self + PPCODE: + GValueArray *values; + GValue *value; + values = lu_ent_get(self, LU_GECOS); + if (values != NULL) { + value = g_value_array_get_nth(values, 0); + if (G_VALUE_HOLDS_STRING(value)) { + XPUSHs(sv_2mortal(newSVpv(g_value_get_string(value), 0))); + } else if (G_VALUE_HOLDS_LONG(value)) { + XPUSHs(sv_2mortal(newSVpv(g_strdup_printf("%ld", g_value_get_long(value)), 0))); + } + } + +void +Ent_HomeDir(self) + USER::ENT *self + PPCODE: + GValueArray *values; + GValue *value; + values = lu_ent_get(self, LU_HOMEDIRECTORY); + if (values != NULL) { + value = g_value_array_get_nth(values, 0); + if (G_VALUE_HOLDS_STRING(value)) { + XPUSHs(sv_2mortal(newSVpv(g_value_get_string(value), 0))); + } else if (G_VALUE_HOLDS_LONG(value)) { + XPUSHs(sv_2mortal(newSVpv(g_strdup_printf("%ld", g_value_get_long(value)), 0))); + } + } + +void +Ent_LoginShell(self) + USER::ENT *self + PPCODE: + GValueArray *values; + GValue *value; + values = lu_ent_get(self, LU_LOGINSHELL); + if (values != NULL) { + value = g_value_array_get_nth(values, 0); + if (G_VALUE_HOLDS_STRING(value)) { + XPUSHs(sv_2mortal(newSVpv(g_value_get_string(value), 0))); + } else if (G_VALUE_HOLDS_LONG(value)) { + XPUSHs(sv_2mortal(newSVpv(g_strdup_printf("%ld", g_value_get_long(value)), 0))); + } + } + +void +Ent_ShadowPass(self) + USER::ENT *self + PPCODE: + GValueArray *values; + GValue *value; + values = lu_ent_get(self, LU_SHADOWPASSWORD); + if (values != NULL) { + value = g_value_array_get_nth(values, 0); + if (G_VALUE_HOLDS_STRING(value)) { + XPUSHs(sv_2mortal(newSVpv(g_value_get_string(value), 0))); + } else if (G_VALUE_HOLDS_LONG(value)) { + XPUSHs(sv_2mortal(newSVpv(g_strdup_printf("%ld", g_value_get_long(value)), 0))); + } + } + +void +Ent_ShadowWarn(self) + USER::ENT *self + PPCODE: + GValueArray *values; + GValue *value; + values = lu_ent_get(self, LU_SHADOWWARNING); + if (values != NULL) { + value = g_value_array_get_nth(values, 0); + if (G_VALUE_HOLDS_STRING(value)) { + XPUSHs(sv_2mortal(newSVpv(g_value_get_string(value), 0))); + } else if (G_VALUE_HOLDS_LONG(value)) { + XPUSHs(sv_2mortal(newSVpv(g_strdup_printf("%ld", g_value_get_long(value)), 0))); + } + } + +void +Ent_ShadowLastChange(self) + USER::ENT *self + PPCODE: + GValueArray *values; + GValue *value; + values = lu_ent_get(self, LU_SHADOWLASTCHANGE); + if (values != NULL) { + value = g_value_array_get_nth(values, 0); + if (G_VALUE_HOLDS_LONG(value)) { + XPUSHs(sv_2mortal(newSViv(g_value_get_long(value)))); + } else if (G_VALUE_HOLDS_STRING(value)) { + XPUSHs(sv_2mortal(newSViv(atol(g_value_get_string(value))))); + } + } + +void +Ent_ShadowMin(self) + USER::ENT *self + PPCODE: + GValueArray *values; + GValue *value; + values = lu_ent_get(self, LU_SHADOWMIN); + if (values != NULL) { + value = g_value_array_get_nth(values, 0); + if (G_VALUE_HOLDS_LONG(value)) { + XPUSHs(sv_2mortal(newSViv(g_value_get_long(value)))); + } else if (G_VALUE_HOLDS_STRING(value)) { + XPUSHs(sv_2mortal(newSViv(atol(g_value_get_string(value))))); + } + } + +void +Ent_ShadowMax(self) + USER::ENT *self + PPCODE: + GValueArray *values; + GValue *value; + values = lu_ent_get(self, LU_SHADOWMAX); + if (values != NULL) { + value = g_value_array_get_nth(values, 0); + if (G_VALUE_HOLDS_LONG(value)) { + XPUSHs(sv_2mortal(newSViv(g_value_get_long(value)))); + } else if (G_VALUE_HOLDS_STRING(value)) { + XPUSHs(sv_2mortal(newSViv(atol(g_value_get_string(value))))); + } + } + +void +Ent_ShadowInact(self) + USER::ENT *self + PPCODE: + GValueArray *values; + GValue *value; + values = lu_ent_get(self, LU_SHADOWINACTIVE); + if (values != NULL) { + value = g_value_array_get_nth(values, 0); + if (G_VALUE_HOLDS_LONG(value)) { + XPUSHs(sv_2mortal(newSViv(g_value_get_long(value)))); + } else if (G_VALUE_HOLDS_STRING(value)) { + XPUSHs(sv_2mortal(newSViv(atol(g_value_get_string(value))))); + } + } + +void +Ent_ShadowExpire(self) + USER::ENT *self + PPCODE: + GValueArray *values; + GValue *value; + values = lu_ent_get(self, LU_SHADOWEXPIRE); + if (values != NULL) { + value = g_value_array_get_nth(values, 0); + if (G_VALUE_HOLDS_LONG(value)) { + XPUSHs(sv_2mortal(newSViv(g_value_get_long(value)))); + } else if (G_VALUE_HOLDS_STRING(value)) { + XPUSHs(sv_2mortal(newSViv(atol(g_value_get_string(value))))); + } + } + +void +Ent_ShadowFlag(self) + USER::ENT *self + PPCODE: + GValueArray *values; + GValue *value; + values = lu_ent_get(self, LU_SHADOWFLAG); + if (values != NULL) { + value = g_value_array_get_nth(values, 0); + if (G_VALUE_HOLDS_LONG(value)) { + XPUSHs(sv_2mortal(newSViv(g_value_get_long(value)))); + } else if (G_VALUE_HOLDS_STRING(value)) { + XPUSHs(sv_2mortal(newSViv(atol(g_value_get_string(value))))); + } + } HV * Ent_get_attributes(self) USER::ENT *self CODE: - int i,j; RETVAL = (HV*)sv_2mortal((SV*)newHV()); + printf("%s", self->type); switch (self->type) { case lu_invalid: break; @@ -198,16 +466,17 @@ Ent_get_attributes(self) hv_store(RETVAL, "home", 4, newSVpv(get_name(self, LU_HOMEDIRECTORY), 0), 0); hv_store(RETVAL, "shell", 5, newSVpv(get_name(self, LU_LOGINSHELL), 0), 0); hv_store(RETVAL, "shadowpass", 10, newSVpv(get_name(self, LU_SHADOWPASSWORD), 0), 0); - hv_store(RETVAL, "shadowlastchange", 16, newSViv(get_name(self, LU_SHADOWLASTCHANGE)), 0); - hv_store(RETVAL, "shadowmin", 9, newSViv(get_name(self, LU_SHADOWMIN)), 0); - hv_store(RETVAL, "shadowmax", 9, newSViv(get_name(self, LU_SHADOWMAX)), 0); + hv_store(RETVAL, "shadowlastchange", 16, newSViv(get_int(self, LU_SHADOWLASTCHANGE)), 0); + hv_store(RETVAL, "shadowmin", 9, newSViv(get_int(self, LU_SHADOWMIN)), 0); + hv_store(RETVAL, "shadowmax", 9, newSViv(get_int(self, LU_SHADOWMAX)), 0); hv_store(RETVAL, "shadowwarning", 13, newSVpv(get_name(self, LU_SHADOWWARNING), 0), 0); - hv_store(RETVAL, "shadowinact", 11, newSViv(get_name(self, LU_SHADOWINACTIVE)), 0); - hv_store(RETVAL, "shadowexpire", 12, newSViv(get_name(self, LU_SHADOWINACTIVE)), 0); - hv_store(RETVAL, "shadowflag", 10, newSViv(get_name(self, LU_SHADOWINACTIVE)), 0); + hv_store(RETVAL, "shadowinact", 11, newSViv(get_int(self, LU_SHADOWINACTIVE)), 0); + hv_store(RETVAL, "shadowexpire", 12, newSViv(get_int(self, LU_SHADOWEXPIRE)), 0); + hv_store(RETVAL, "shadowflag", 10, newSViv(get_int(self, LU_SHADOWFLAG)), 0); + break; case lu_group: hv_store(RETVAL, "type", 4, newSVpv("group", 0), 0); - hv_store(RETVAL, "groupname", 8, newSVpv(get_name(self, LU_GROUPNAME), 0), 0); + hv_store(RETVAL, "groupname", 9, newSVpv(get_name(self, LU_GROUPNAME), 0), 0); hv_store(RETVAL, "gid", 3, newSViv(get_int(self, LU_GIDNUMBER)), 0); break; default: |