aboutsummaryrefslogtreecommitdiffstats
path: root/USER/USER.xs
blob: d0bc77c3277f09cff9631a89e8288d98917905fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
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()