5 # Background name resolution
7 # (c) 2005 Straylight/Edgeware
10 #----- Licensing notice -----------------------------------------------------
12 # This file is part of the Python interface to mLib.
14 # mLib/Python is free software; you can redistribute it and/or modify
15 # it under the terms of the GNU General Public License as published by
16 # the Free Software Foundation; either version 2 of the License, or
17 # (at your option) any later version.
19 # mLib/Python is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU General Public License for more details.
24 # You should have received a copy of the GNU General Public License
25 # along with mLib/Python; if not, write to the Free Software Foundation,
26 # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 cdef class SelResolve:
33 def __init__(me, *hunoz, **hukairz):
34 raise TypeError, 'abstract class'
37 return _tobool(me._activep)
40 raise ValueError, 'already dead'
49 property resolvedproc:
52 def __set__(me, proc):
53 me._resolved = _checkcallable(proc, 'resolved proc')
59 def __set__(me, proc):
60 me._failed = _checkcallable(proc, 'failed proc')
63 def resolved(me, name, aliases, addrs):
64 return _maybecall(me._resolved, (name, aliases, addrs))
66 return _maybecall(me._failed, ())
68 cdef class SelResolveByName (SelResolve):
69 def __new__(me, char *name, resolvedproc = None, failedproc = None,
71 bres_byname(&me.r, name, _resfunc, <void *>me)
72 me._resolved = _checkcallable(resolvedproc, 'resolved proc')
73 me._failed = _checkcallable(failedproc, 'failed proc')
75 def __init__(me, name, resolvedproc = None, failedproc = None):
78 cdef class SelResolveByAddr (SelResolve):
79 def __new__(me, char *addr, resolvedproc = None, failedproc = None,
82 if not inet_aton(addr, &ia):
83 raise TypeError, 'bad IP address'
84 bres_byaddr(&me.r, ia, _resfunc, <void *>me)
85 me._resolved = _checkcallable(resolvedproc, 'resolved proc')
86 me._failed = _checkcallable(failedproc, 'failed proc')
88 def __init__(me, addr, resolvedproc = None, failedproc = None):
91 cdef void _resfunc(hostent *h, void *arg):
102 while h.h_aliases[i]:
103 alias.append(h.h_aliases[i])
106 while h.h_addr_list[i]:
107 addr.append(inet_ntoa((<in_addr *>h.h_addr_list[i])[0]))
109 r.resolved(h.h_name, alias, addr)
114 #----- That's all, folks ----------------------------------------------------