3 ### Background name resolution
5 ### (c) 2005 Straylight/Edgeware
8 ###----- Licensing notice ---------------------------------------------------
10 ### This file is part of the Python interface to mLib.
12 ### mLib/Python is free software; you can redistribute it and/or modify
13 ### it under the terms of the GNU General Public License as published by
14 ### the Free Software Foundation; either version 2 of the License, or
15 ### (at your option) any later version.
17 ### mLib/Python is distributed in the hope that it will be useful,
18 ### but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ### GNU General Public License for more details.
22 ### You should have received a copy of the GNU General Public License
23 ### along with mLib/Python; if not, write to the Free Software Foundation,
24 ### Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 cdef class SelResolve:
31 def __init__(me, *hunoz, **hukairz):
32 raise TypeError, 'abstract class'
39 return _tobool(me._activep)
42 raise ValueError, 'already dead'
51 property resolvedproc:
54 def __set__(me, proc):
55 me._resolved = _checkcallable(proc, 'resolved proc')
61 def __set__(me, proc):
62 me._failed = _checkcallable(proc, 'failed proc')
65 def resolved(me, name, aliases, addrs):
66 return _maybecall(me._resolved, (name, aliases, addrs))
68 return _maybecall(me._failed, ())
70 cdef class SelResolveByName (SelResolve):
71 def __cinit__(me, char *name, resolvedproc = None, failedproc = None,
73 me._resolved = _checkcallable(resolvedproc, 'resolved proc')
74 me._failed = _checkcallable(failedproc, 'failed proc')
76 bres_byname(&me.r, name, _resfunc, <void *>me)
77 def __init__(me, name, resolvedproc = None, failedproc = None):
80 cdef class SelResolveByAddr (SelResolve):
81 def __cinit__(me, char *addr, resolvedproc = None, failedproc = None,
84 if not inet_aton(addr, &ia):
85 raise TypeError, 'bad IP address'
86 me._resolved = _checkcallable(resolvedproc, 'resolved proc')
87 me._failed = _checkcallable(failedproc, 'failed proc')
89 bres_byaddr(&me.r, ia, _resfunc, <void *>me)
90 def __init__(me, addr, resolvedproc = None, failedproc = None):
93 cdef void _resfunc(hostent *h, void *arg):
104 while h.h_aliases[i]:
105 alias.append(h.h_aliases[i])
108 while h.h_addr_list[i]:
109 addr.append(inet_ntoa((<in_addr *>h.h_addr_list[i])[0]))
111 r.resolved(h.h_name, alias, addr)
116 ###----- That's all, folks --------------------------------------------------