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'
41 return _tobool(me._activep)
44 raise ValueError, 'already dead'
53 property resolvedproc:
56 def __set__(me, proc):
57 me._resolved = _checkcallable(proc, 'resolved proc')
63 def __set__(me, proc):
64 me._failed = _checkcallable(proc, 'failed proc')
67 def resolved(me, name, aliases, addrs):
68 return _maybecall(me._resolved, (name, aliases, addrs))
70 return _maybecall(me._failed, ())
72 cdef class SelResolveByName (SelResolve):
73 def __cinit__(me, char *name, resolvedproc = None, failedproc = None,
75 me._resolved = _checkcallable(resolvedproc, 'resolved proc')
76 me._failed = _checkcallable(failedproc, 'failed proc')
78 bres_byname(&me.r, name, _resfunc, <void *>me)
79 def __init__(me, name, resolvedproc = None, failedproc = None):
82 cdef class SelResolveByAddr (SelResolve):
83 def __cinit__(me, char *addr, resolvedproc = None, failedproc = None,
86 if not inet_aton(addr, &ia):
87 raise TypeError, 'bad IP address'
88 me._resolved = _checkcallable(resolvedproc, 'resolved proc')
89 me._failed = _checkcallable(failedproc, 'failed proc')
91 bres_byaddr(&me.r, ia, _resfunc, <void *>me)
92 def __init__(me, addr, resolvedproc = None, failedproc = None):
95 cdef void _resfunc(hostent *h, void *arg):
106 while h.h_aliases[i]:
107 alias.append(h.h_aliases[i])
110 while h.h_addr_list[i]:
111 addr.append(inet_ntoa((<in_addr *>h.h_addr_list[i])[0]))
113 r.resolved(h.h_name, alias, addr)
118 #----- That's all, folks ----------------------------------------------------