From 2adb045057d5a1f2073846b20aa91af4e9ef0380 Mon Sep 17 00:00:00 2001 From: Evan Broder Date: Sun, 15 Mar 2009 18:47:18 -0400 Subject: [PATCH] Add a PTEntry class corresponding to the ptcheckentry struct, and methods to convert between the two. Signed-off-by: Evan Broder --- afs/_pts.pyx | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ afs/afs.pxd | 1 + 2 files changed, 55 insertions(+) diff --git a/afs/_pts.pyx b/afs/_pts.pyx index 5ba1c4f..e25ac61 100644 --- a/afs/_pts.pyx +++ b/afs/_pts.pyx @@ -20,6 +20,17 @@ cdef import from "afs/ptuser.h": unsigned int idlist_len afs_int32 *idlist_val + struct prcheckentry: + afs_int32 flags + afs_int32 id + afs_int32 owner + afs_int32 creator + afs_int32 ngroups + afs_int32 nusers + afs_int32 count + afs_int32 reserved[5] + char name[PR_MAXNAMELEN] + int ubik_PR_NameToID(ubik_client *, afs_int32, namelist *, idlist *) int ubik_PR_IDToName(ubik_client *, afs_int32, idlist *, namelist *) int ubik_PR_INewEntry(ubik_client *, afs_int32, char *, afs_int32, afs_int32) @@ -37,6 +48,49 @@ cdef import from "afs/pterror.h": void initialize_PT_error_table() +cdef class PTEntry: + cdef public afs_int32 flags + cdef public afs_int32 id + cdef public afs_int32 owner + cdef public afs_int32 creator + cdef public afs_int32 ngroups + cdef public afs_int32 nusers + cdef public afs_int32 count + cdef afs_int32 reserved[5] + cdef public char * name + +cdef int _ptentry_from_c(PTEntry p_entry, prcheckentry c_entry) except -1: + if p_entry is None: + raise TypeError + return -1 + + p_entry.flags = c_entry.flags + p_entry.id = c_entry.id + p_entry.owner = c_entry.owner + p_entry.creator = c_entry.creator + p_entry.ngroups = c_entry.ngroups + p_entry.nusers = c_entry.nusers + p_entry.count = c_entry.count + memcpy(p_entry.reserved, c_entry.reserved, sizeof(p_entry.reserved)) + p_entry.name = c_entry.name + return 0 + +cdef int _ptentry_to_c(prcheckentry * c_entry, PTEntry p_entry) except -1: + if p_entry is None: + raise TypeError + return -1 + + c_entry.flags = p_entry.flags + c_entry.id = p_entry.id + c_entry.owner = p_entry.owner + c_entry.creator = p_entry.creator + c_entry.ngroups = p_entry.ngroups + c_entry.nusers = p_entry.nusers + c_entry.count = p_entry.count + memcpy(c_entry.reserved, p_entry.reserved, sizeof(p_entry.reserved)) + strncpy(c_entry.name, p_entry.name, sizeof(c_entry.name)) + return 0 + cdef class PTS: """ A PTS object is essentially a handle to talk to the server in a diff --git a/afs/afs.pxd b/afs/afs.pxd index b34283c..090a65e 100644 --- a/afs/afs.pxd +++ b/afs/afs.pxd @@ -8,6 +8,7 @@ cdef extern from "string.h": char * strerror(int errnum) char * strncpy(char *s1, char *s2, size_t n) void * memset(void *b, int c, size_t n) + void * memcpy(void *s1, void *s2, size_t n) cdef extern from "stdlib.h": void * malloc(size_t size) -- 1.7.9.5