X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/mLib-python/blobdiff_plain/b3c87d862e8f44754113ee9bf374e9fcfbc9e7ac..HEAD:/ident.pyx diff --git a/ident.pyx b/ident.pyx index e7c05d2..9a522bd 100644 --- a/ident.pyx +++ b/ident.pyx @@ -1,29 +1,27 @@ -# -*-pyrex-*- -# -# $Id$ -# -# Ident client -# -# (c) 2005 Straylight/Edgeware -# +### -*-pyrex-*- +### +### Ident client +### +### (c) 2005 Straylight/Edgeware +### -#----- Licensing notice ----------------------------------------------------- -# -# This file is part of the Python interface to mLib. -# -# mLib/Python is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# mLib/Python is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with mLib/Python; if not, write to the Free Software Foundation, -# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +###----- Licensing notice --------------------------------------------------- +### +### This file is part of the Python interface to mLib. +### +### mLib/Python is free software; you can redistribute it and/or modify +### it under the terms of the GNU General Public License as published by +### the Free Software Foundation; either version 2 of the License, or +### (at your option) any later version. +### +### mLib/Python is distributed in the hope that it will be useful, +### but WITHOUT ANY WARRANTY; without even the implied warranty of +### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +### GNU General Public License for more details. +### +### You should have received a copy of the GNU General Public License +### along with mLib/Python; if not, write to the Free Software Foundation, +### Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. import socket @@ -43,6 +41,12 @@ cdef _inaddr_topy(sockaddr_in *sin): return inet_ntoa(sin.sin_addr), ntohs(sin.sin_port) cdef class SelIdentify: + """ + SelIdentify(SK, [userproc = None], [bogusproc = None], + [badproc = None], [errorproc = None],) + + Asynchronously enquire about remote user of socket SK. + """ cdef ident_request irq cdef int _activep cdef readonly localaddr @@ -50,16 +54,13 @@ cdef class SelIdentify: cdef _user cdef _bad cdef _error - cdef _failed cdef _bogus - def __new__(me, sk, - userproc = None, bogusproc = None, - badproc = None, errorproc = None, failedproc = None, - *hunoz, **hukairz): + def __cinit__(me, sk, userproc = None, bogusproc = None, + badproc = None, errorproc = None, *hunoz, **hukairz): cdef sockaddr_in s_in, s_out - cdef size_t sz_in, sz_out + cdef socklen_t sz_in, sz_out cdef int fd - if PyObject_TypeCheck(sk, socket.SocketType): + if typecheck(sk, socket.SocketType): fd = sk.fileno() sz_in = PSIZEOF(&s_in) sz_out = PSIZEOF(&s_out) @@ -80,29 +81,24 @@ cdef class SelIdentify: me._user = _checkcallable(userproc, 'user proc') me._bad = _checkcallable(badproc, 'bad proc') me._error = _checkcallable(errorproc, 'error proc') - me._failed = _checkcallable(failedproc, 'failed proc') me._bogus = _checkcallable(bogusproc, 'bogus proc') def __dealloc__(me): if me._activep: ident_abort(&me.irq) property activep: + """I.activep -> BOOL: query still in progress?""" def __get__(me): return _tobool(me._activep) property userproc: + """I.userproc -> FUNC: call FUNC(OS, USER) if server replied""" def __get__(me): return me._user def __set__(me, proc): me._user = _checkcallable(proc, 'user proc') def __del__(me): me._user = None - property eofproc: - def __get__(me): - return me._eof - def __set__(me, proc): - me._eof = _checkcallable(proc, 'eof proc') - def __del__(me): - me._eof = None property badproc: + """I.badproc -> FUNC: call FUNC() if server's reply was broken""" def __get__(me): return me._bad def __set__(me, proc): @@ -110,20 +106,15 @@ cdef class SelIdentify: def __del__(me): me._bad = None property errorproc: + """I.errorproc -> FUNC: call FUNC(ERR) if server reported error""" def __get__(me): return me._error def __set__(me, proc): me._error = _checkcallable(proc, 'error proc') def __del__(me): me._error = None - property failedproc: - def __get__(me): - return me._failed - def __set__(me, proc): - me._failed = _checkcallable(proc, 'failed proc') - def __del__(me): - me._failed = None property bogusproc: + """I.bogusproc -> FUNC: call FUNC() on failure if no specific handler""" def __get__(me): return me._bogus def __set__(me, proc): @@ -131,6 +122,7 @@ cdef class SelIdentify: def __del__(me): me._bogus = None def kill(me): + """I.kill(): cancel ident query""" if not me._activep: raise ValueError, 'already disabled' ident_abort(&me.irq) @@ -139,25 +131,26 @@ cdef class SelIdentify: me._activep = 0 me.dead() def dead(me): + """I.dead(): called when operation completes or fails""" pass def user(me, os, user): + """I.user(OS, USER): called if server returns user name""" return _maybecall(me._user, (os, user)) def bad(me): + """I.bad(): called if server's reply is invalid""" if me._bad is not None: return me._bad() return me.bogus() def error(me, error): + """I.error(ERR): called if server returns an error""" if me._error is not None: return me._error(error) return me.bogus() - def failed(me, errno, strerror): - if me._failed is not None: - return me._failed(errno, strerror) - return me.bogus() def bogus(me): + """I.bogus(): called on failure if there's no more specific handler""" return _maybecall(me._bogus, ()) -cdef void _identfunc2(ident_reply *i, void *arg): +cdef void _identfunc(ident_reply *i, void *arg): cdef SelIdentify id id = arg id._dead() @@ -167,9 +160,5 @@ cdef void _identfunc2(ident_reply *i, void *arg): id.error(i.u.error) elif i.type == IDENT_USERID: id.user(i.u.userid.os, i.u.userid.user) -cdef void _identfunc(ident_reply *i, void *arg): - PyEval_AcquireLock() - _identfunc2(i, arg) - PyEval_ReleaseLock() -#----- That's all, folks ---------------------------------------------------- +###----- That's all, folks --------------------------------------------------