2014-10-05 15:44:31 -06:00
/*
2015-12-30 03:57:50 -07:00
* l i b u n b o u n d . i : p y U n b o u n d m o d u l e ( l i b u n b o u n d w r a p p e r for P y t h o n )
2014-10-05 15:44:31 -06:00
*
* C o p y r i g h t ( c ) 2009 , Z d e n e k V a s i c e k ( v a s i c e k AT f i t . v u t b r . c z )
* M a r e k V a v r u s a ( x v a v r u 00 AT s t u d . f i t . v u t b r . c z )
*
* T h i s s o f t w a r e is open source .
*
* R e d i s t r i b u t i o n and use in source and binary f o r m s , with or w i t h o u t
* m o d i f i c a t i o n , a r e p e r m i t t e d p r o v i d e d t h a t t h e f o l l o w i n g c o n d i t i o n s
* a r e m e t :
*
* * R e d i s t r i b u t i o n s of source code m u s t retain t h e a b o v e c o p y r i g h t n o t i c e ,
* t h i s l i s t of c o n d i t i o n s and t h e f o l l o w i n g d i s c l a i m e r .
*
* * R e d i s t r i b u t i o n s in binary form m u s t r e p r o d u c e t h e a b o v e c o p y r i g h t n o t i c e ,
* t h i s l i s t of c o n d i t i o n s and t h e f o l l o w i n g d i s c l a i m e r in t h e d o c u m e n t a t i o n
* and / or o t h e r m a t e r i a l s p r o v i d e d with t h e d i s t r i b u t i o n .
*
* * N e i t h e r t h e name of t h e o r g a n i z a t i o n n o r t h e n a m e s of i t s
* c o n t r i b u t o r s m a y b e u s e d to e n d o r s e or p r o m o t e p r o d u c t s d e r i v e d from t h i s
* s o f t w a r e w i t h o u t s p e c i f i c p r i o r w r i t t e n p e r m i s s i o n .
*
* T H I S S O F T W A R E IS P R O V I D E D BY T H E C O P Y R I G H T H O L D E R S AND C O N T R I B U T O R S
* "AS IS" AND ANY E X P R E S S OR I M P L I E D W A R R A N T I E S , I N C L U D I N G , B U T NOT L I M I T E D
* TO , T H E I M P L I E D W A R R A N T I E S OF M E R C H A N T A B I L I T Y AND F I T N E S S FOR A P A R T I C U L A R
* P U R P O S E A R E D I S C L A I M E D . IN NO EVENT S H A L L T H E R E G E N T S OR C O N T R I B U T O R S B E
* L I A B L E FOR ANY D I R E C T , I N D I R E C T , I N C I D E N T A L , S P E C I A L , E X E M P L A R Y , OR
* C O N S E Q U E N T I A L D A M A G E S ( I N C L U D I N G , B U T NOT L I M I T E D TO , P R O C U R E M E N T OF
* SUBSTITUTE G O O D S OR S E R V I C E S ; L O S S OF USE , D A T A , OR P R O F I T S ; OR B U S I N E S S
* I N T E R R U P T I O N ) H O W E V E R C A U S E D AND ON ANY T H E O R Y OF L I A B I L I T Y , W H E T H E R IN
* C O N T R A C T , STRICT L I A B I L I T Y , OR T O R T ( I N C L U D I N G N E G L I G E N C E OR OTHERWISE )
* A R I S I N G IN ANY W A Y O U T OF T H E USE OF T H I S S O F T W A R E , E V E N IF A D V I S E D OF T H E
* P O S S I B I L I T Y OF S U C H D A M A G E .
* /
% m o d u l e u n b o u n d
% {
# i n c l u d e < s y s / t y p e s . h >
# i n c l u d e < s y s / s o c k e t . h >
# i n c l u d e < n e t i n e t / in . h >
# i n c l u d e < a r p a / i n e t . h >
# i n c l u d e "libunbound/unbound.h"
% }
% p y t h o n c o d e % {
import e n c o d i n g s . i d n a
2015-04-02 03:16:18 -06:00
t r y :
import b u i l t i n s
except I m p o r t E r r o r :
import _ _ b u i l t i n _ _ as b u i l t i n s
2014-10-05 15:44:31 -06:00
# E n s u r e c o m p a t i b i l i t y with o l d e r p y t h o n v e r s i o n s
if 'bytes' not in v a r s ( ) :
b y t e s = s t r
def o r d ( s ) :
if i s i n s t a n c e ( s , int ) :
return s
2015-04-02 03:16:18 -06:00
return b u i l t i n s . o r d ( s )
2014-10-05 15:44:31 -06:00
% }
//%include "doc.i"
2015-05-31 08:36:48 -06:00
# if P Y _ M A J O R _ V E R S I O N > = 3
% i n c l u d e "file_py3.i" // python 3 FILE *
# else
2014-10-05 15:44:31 -06:00
% i n c l u d e "file.i"
2015-05-31 08:36:48 -06:00
# e n d i f
2014-10-05 15:44:31 -06:00
% f e a t u r e ( "docstring" ) s t r e r r o r "Convert error value to a human readable string."
// ================================================================================
// ub_resolve - perform resolution and validation
// ================================================================================
% t y p e m a p ( in , n u m i n p u t s = 0 , n o b l o c k = 1 ) ( s t r u c t u b _ r e s u l t * * r e s u l t )
{
s t r u c t u b _ r e s u l t * n e w u b r ;
$ 1 = &newubr;
}
/* r e s u l t g e n e r a t i o n */
% t y p e m a p ( a r g o u t , n o b l o c k = 1 ) ( s t r u c t u b _ r e s u l t * * r e s u l t )
{
if ( 1 ) { / * n e w c o d e b l o c k f o r v a r i a b l e o n s t a c k * /
P y O b j e c t * t u p l e ;
t u p l e = P y T u p l e _ N e w ( 2 ) ;
P y T u p l e _ S e t I t e m ( t u p l e , 0 , $ r e s u l t ) ;
if ( r e s u l t = = 0 ) {
P y T u p l e _ S e t I t e m ( t u p l e , 1 , S W I G _ N e w P o i n t e r O b j ( S W I G _ a s _ v o i d p t r ( n e w u b r ) , S W I G T Y P E _ p _ u b _ r e s u l t , S W I G _ P O I N T E R _ O W N | 0 ) ) ;
} else {
P y T u p l e _ S e t I t e m ( t u p l e , 1 , P y _ N o n e ) ;
}
$ r e s u l t = t u p l e ;
}
}
// ================================================================================
// ub_ctx - validation context
// ================================================================================
% n o d e f a u l t c t o r u b _ c t x ; //no default constructor & destructor
% n o d e f a u l t d t o r u b _ c t x ;
% n e w o b j e c t u b _ c t x _ c r e a t e ;
% d e l o b j e c t u b _ c t x _ d e l e t e ;
% r e n a m e ( _ u b _ c t x _ d e l e t e ) u b _ c t x _ d e l e t e ;
% n e w o b j e c t u b _ r e s o l v e ;
% i n l i n e % {
void u b _ c t x _ f r e e _ d b g ( s t r u c t u b _ c t x * c ) {
p r i n t f ( "******** UB_CTX free 0x%lX ************\n" , ( l o n g u n s i g n e d int ) c ) ;
u b _ c t x _ d e l e t e ( c ) ;
}
//RR types
enum e n u m _ r r _ t y p e
{
/* * a h o s t a d d r e s s */
R R _ T Y P E _ A = 1 ,
/* * a n a u t h o r i t a t i v e n a m e s e r v e r */
R R _ T Y P E _ N S = 2 ,
/* * a m a i l d e s t i n a t i o n ( O b s o l e t e - u s e M X ) */
R R _ T Y P E _ M D = 3 ,
/* * a m a i l f o r w a r d e r ( O b s o l e t e - u s e M X ) */
R R _ T Y P E _ M F = 4 ,
/* * t h e c a n o n i c a l n a m e f o r a n a l i a s */
R R _ T Y P E _ C N A M E = 5 ,
/* * m a r k s t h e s t a r t o f a z o n e o f a u t h o r i t y */
R R _ T Y P E _ S O A = 6 ,
/* * a m a i l b o x d o m a i n n a m e ( E X P E R I M E N T A L ) */
R R _ T Y P E _ M B = 7 ,
/* * a m a i l g r o u p m e m b e r ( E X P E R I M E N T A L ) */
R R _ T Y P E _ M G = 8 ,
/* * a m a i l r e n a m e d o m a i n n a m e ( E X P E R I M E N T A L ) */
R R _ T Y P E _ M R = 9 ,
/* * a n u l l R R ( E X P E R I M E N T A L ) */
R R _ T Y P E _ N U L L = 10 ,
/* * a w e l l k n o w n s e r v i c e d e s c r i p t i o n */
R R _ T Y P E _ W K S = 11 ,
/* * a d o m a i n n a m e p o i n t e r */
R R _ T Y P E _ P T R = 12 ,
/* * h o s t i n f o r m a t i o n */
R R _ T Y P E _ H I N F O = 13 ,
/* * m a i l b o x o r m a i l l i s t i n f o r m a t i o n */
R R _ T Y P E _ M I N F O = 14 ,
/* * m a i l e x c h a n g e */
R R _ T Y P E _ M X = 15 ,
/* * t e x t s t r i n g s */
R R _ T Y P E _ T X T = 16 ,
/* * R F C 1 1 8 3 */
R R _ T Y P E _ R P = 17 ,
/* * R F C 1 1 8 3 */
R R _ T Y P E _ A F S D B = 18 ,
/* * R F C 1 1 8 3 */
R R _ T Y P E _ X 25 = 19 ,
/* * R F C 1 1 8 3 */
R R _ T Y P E _ I S D N = 20 ,
/* * R F C 1 1 8 3 */
R R _ T Y P E _ R T = 21 ,
/* * R F C 1 7 0 6 */
R R _ T Y P E _ N S A P = 22 ,
/* * R F C 1 3 4 8 */
R R _ T Y P E _ N S A P _ P T R = 23 ,
/* * 2 5 3 5 t y p e c o d e */
R R _ T Y P E _ S I G = 24 ,
/* * 2 5 3 5 t y p e c o d e */
R R _ T Y P E _ K E Y = 25 ,
/* * R F C 2 1 6 3 */
R R _ T Y P E _ P X = 26 ,
/* * R F C 1 7 1 2 */
R R _ T Y P E _ G P O S = 27 ,
/* * i p v 6 a d d r e s s */
R R _ T Y P E _ A A A A = 28 ,
/* * L O C r e c o r d R F C 1 8 7 6 */
R R _ T Y P E _ L O C = 29 ,
/* * 2 5 3 5 t y p e c o d e */
R R _ T Y P E _ N X T = 30 ,
/* * d r a f t - i e t f - n i m r o d - d n s - 0 1 . t x t */
R R _ T Y P E _ E I D = 31 ,
/* * d r a f t - i e t f - n i m r o d - d n s - 0 1 . t x t */
R R _ T Y P E _ N I M L O C = 32 ,
/* * S R V r e c o r d R F C 2 7 8 2 */
R R _ T Y P E _ S R V = 33 ,
/* * h t t p : / / w w w . j h s o f t . c o m / r f c / a f - s a a - 0 0 6 9 . 0 0 0 . r t f */
R R _ T Y P E _ A T M A = 34 ,
/* * R F C 2 9 1 5 */
R R _ T Y P E _ N A P T R = 35 ,
/* * R F C 2 2 3 0 */
R R _ T Y P E _ K X = 36 ,
/* * R F C 2 5 3 8 */
R R _ T Y P E _ C E R T = 37 ,
/* * R F C 2 8 7 4 */
R R _ T Y P E _ A 6 = 38 ,
/* * R F C 2 6 7 2 */
R R _ T Y P E _ D N A M E = 39 ,
/* * d n s i n d - k i t c h e n - s i n k - 0 2 . t x t */
R R _ T Y P E _ S I N K = 40 ,
/* * P s e u d o O P T r e c o r d . . . */
R R _ T Y P E _ O P T = 41 ,
/* * R F C 3 1 2 3 */
R R _ T Y P E _ A P L = 42 ,
/* * d r a f t - i e t f - d n s e x t - d e l e g a t i o n */
R R _ T Y P E _ D S = 43 ,
/* * S S H K e y F i n g e r p r i n t */
R R _ T Y P E _ S S H F P = 44 ,
/* * d r a f t - r i c h a r d s o n - i p s e c k e y - r r - 1 1 . t x t */
R R _ T Y P E _ I P S E C K E Y = 45 ,
/* * d r a f t - i e t f - d n s e x t - d n s s e c - 2 5 */
R R _ T Y P E _ R R S I G = 46 ,
R R _ T Y P E _ N S E C = 47 ,
R R _ T Y P E _ D N S K E Y = 48 ,
R R _ T Y P E _ D H C I D = 49 ,
R R _ T Y P E _ N S E C 3 = 50 ,
R R _ T Y P E _ N S E C 3 P A R A M S = 51 ,
R R _ T Y P E _ U I N F O = 100 ,
R R _ T Y P E _ U I D = 101 ,
R R _ T Y P E _ G I D = 102 ,
R R _ T Y P E _ U N S P E C = 103 ,
R R _ T Y P E _ T S I G = 250 ,
R R _ T Y P E _ I X F R = 251 ,
R R _ T Y P E _ A X F R = 252 ,
/* * A r e q u e s t f o r m a i l b o x - r e l a t e d r e c o r d s ( M B , M G o r M R ) */
R R _ T Y P E _ M A I L B = 253 ,
/* * A r e q u e s t f o r m a i l a g e n t R R s ( O b s o l e t e - s e e M X ) */
R R _ T Y P E _ M A I L A = 254 ,
/* * a n y t y p e ( w i l d c a r d ) */
R R _ T Y P E _ A N Y = 255 ,
/* R F C 4 4 3 1 , 5 0 7 4 , D N S S E C L o o k a s i d e V a l i d a t i o n */
R R _ T Y P E _ D L V = 32769 ,
} ;
// RR classes
enum e n u m _ r r _ c l a s s
{
/* * t h e I n t e r n e t */
R R _ C L A S S _ I N = 1 ,
/* * C h a o s c l a s s */
R R _ C L A S S _ C H = 3 ,
/* * H e s i o d ( D y e r 8 7 ) */
R R _ C L A S S _ H S = 4 ,
/* * N o n e c l a s s , d y n a m i c u p d a t e */
R R _ C L A S S _ N O N E = 254 ,
/* * A n y c l a s s */
R R _ C L A S S _ A N Y = 255 ,
} ;
% }
% f e a t u r e ( "docstring" ) u b _ c t x " U n b o u n d r e s o l v i n g and v a l i d a t i o n context .
T h e v a l i d a t i o n context is c r e a t e d to h o l d t h e r e s o l v e r status , v a l i d a t i o n keys and a s m a l l cache ( c o n t a i n i n g m e s s a g e s , r r s e t s , r o u n d t r i p t i m e s , t r u s t e d keys , l a m e n e s s information ) .
* * U s a g e * *
> > > import u n b o u n d
> > > c t x = u n b o u n d . u b _ c t x ( )
> > > c t x . r e s o l v c o n f ( \ "/etc/resolv.conf\" )
> > > status , r e s u l t = c t x . r e s o l v e ( \ "www.google.com\" , u n b o u n d . R R _ T Y P E _ A , u n b o u n d . R R _ C L A S S _ I N )
> > > if status = = 0 and r e s u l t . h a v e d a t a :
> > > p r i n t \ "Result:\" , r e s u l t . d a t a . a d d r e s s _ l i s t
R e s u l t : [ '74.125.43.147', '74.125.43.99', '74.125.43.103', '74.125.43.104' ]
"
% e x t e n d u b _ c t x
{
% p y t h o n c o d e % {
def _ _ i n i t _ _ ( self ) :
"" " C r e a t e s a r e s o l v i n g and v a l i d a t i o n context .
A n e x c e p t i o n is i n v o k e d if t h e process of c r e a t i o n a n u b _ c t x i n s t a n c e f a i l s .
"" "
self . t h i s = _ u n b o u n d . u b _ c t x _ c r e a t e ( )
if not self . t h i s :
r a i s e E x c e p t i o n ( "Fatal error: unbound context initialization failed" )
# _ _ s w i g _ d e s t r o y _ _ = _ u n b o u n d . u b _ c t x _ f r e e _ d b g
_ _ s w i g _ d e s t r o y _ _ = _ u n b o u n d . _ u b _ c t x _ d e l e t e
# U B _ C T X _ M E T H O D S _ #
def a d d _ t a ( self , t a ) :
"" " Add a t r u s t a n c h o r to t h e g i v e n context .
T h e t r u s t a n c h o r is a string , on o n e line , t h a t h o l d s a v a l i d D N S K E Y or D S R R .
: param t a :
string , with z o n e - f o r m a t R R on o n e line . [ d o m a i n n a m e ] [ T T L o p t i o n a l ] [ type ] [ class o p t i o n a l ] [ r d a t a contents ]
: returns : ( int ) 0 if OK , else error .
"" "
return _ u n b o u n d . u b _ c t x _ a d d _ t a ( self , t a )
# p a r a m e t e r s : s t r u c t u b _ c t x * , char * ,
# r e t v a l s : int
def a d d _ t a _ f i l e ( self , f n a m e ) :
"" " Add t r u s t a n c h o r s to t h e g i v e n context .
P a s s name of a file with D S and D N S K E Y r e c o r d s ( like from d i g or d r i l l ) .
: param f n a m e :
filename of file with k e y f i l e with t r u s t a n c h o r s .
: returns : ( int ) 0 if OK , else error .
"" "
return _ u n b o u n d . u b _ c t x _ a d d _ t a _ f i l e ( self , f n a m e )
# p a r a m e t e r s : s t r u c t u b _ c t x * , char * ,
# r e t v a l s : int
def c o n f i g ( self , f n a m e ) :
"" " s e t u p c o n f i g u r a t i o n for t h e g i v e n context .
: param f n a m e :
u n b o u n d c o n f i g file ( not all s e t t i n g s a p p l i c a b l e ) . T h i s is a p o w e r - u s e r s interface t h a t l e t s y o u s p e c i f y all s o r t s of o p t i o n s . For some s p e c i f i c o p t i o n s , s u c h as a d d i n g t r u s t a n c h o r s , s p e c i a l r o u t i n e s e x i s t .
: returns : ( int ) 0 if OK , else error .
"" "
return _ u n b o u n d . u b _ c t x _ c o n f i g ( self , f n a m e )
# p a r a m e t e r s : s t r u c t u b _ c t x * , char * ,
# r e t v a l s : int
def d e b u g l e v e l ( self , d ) :
"" " Set debug v e r b o s i t y for t h e context Output is d i r e c t e d to s t d e r r .
: param d :
debug l e v e l , 0 is off , 1 is v e r y m i n i m a l , 2 is d e t a i l e d , and 3 is l o t s .
: returns : ( int ) 0 if OK , else error .
"" "
return _ u n b o u n d . u b _ c t x _ d e b u g l e v e l ( self , d )
# p a r a m e t e r s : s t r u c t u b _ c t x * , int ,
# r e t v a l s : int
def d e b u g o u t ( self , o u t ) :
"" " Set debug output ( and error output ) to t h e s p e c i f i e d stream .
P a s s None to disable . Default is s t d e r r .
: param o u t :
File stream to log to .
: returns : ( int ) 0 if OK , else error .
* * U s a g e : * *
In o r d e r to log into file , use
: :
c t x = u n b o u n d . u b _ c t x ( )
f w = f o p e n ( "debug.log" )
c t x . d e b u g l e v e l ( 3 )
c t x . d e b u g o u t ( f w )
A n o t h e r option is to p r i n t t h e debug i n f o r m a t i o n s to s t d e r r output
: :
c t x = u n b o u n d . u b _ c t x ( )
c t x . d e b u g l e v e l ( 10 )
c t x . d e b u g o u t ( s y s . s t d e r r )
"" "
return _ u n b o u n d . u b _ c t x _ d e b u g o u t ( self , o u t )
# p a r a m e t e r s : s t r u c t u b _ c t x * , void * ,
# r e t v a l s : int
def h o s t s ( self , f n a m e = "/etc/hosts" ) :
"" " R e a d l i s t of h o s t s from t h e filename g i v e n .
U s u a l l y "/etc/hosts" . T h e s e a d d r e s s e s a r e not f l a g g e d as D N S S E C s e c u r e when q u e r i e d for .
: param f n a m e :
file name string . If None "/etc/hosts" is u s e d .
: returns : ( int ) 0 if OK , else error .
"" "
return _ u n b o u n d . u b _ c t x _ h o s t s ( self , f n a m e )
# p a r a m e t e r s : s t r u c t u b _ c t x * , char * ,
# r e t v a l s : int
def p r i n t _ l o c a l _ z o n e s ( self ) :
"" " P r i n t t h e l o c a l z o n e s and t h e i r c o n t e n t ( R R d a t a ) to t h e debug output .
: returns : ( int ) 0 if OK , else error .
"" "
return _ u n b o u n d . u b _ c t x _ p r i n t _ l o c a l _ z o n e s ( self )
# p a r a m e t e r s : s t r u c t u b _ c t x * ,
# r e t v a l s : int
def r e s o l v c o n f ( self , f n a m e = "/etc/resolv.conf" ) :
"" " R e a d l i s t of n a m e s e r v e r s to use from t h e filename g i v e n .
U s u a l l y "/etc/resolv.conf" . U s e s t h o s e n a m e s e r v e r s as c a c h i n g p r o x i e s . If t h e y do not s u p p o r t D N S S E C , v a l i d a t i o n m a y f a i l .
O n l y n a m e s e r v e r s a r e p i c k e d up , t h e s e a r c h d o m a i n , n d o t s and o t h e r s e t t i n g s from r e s o l v . c o n f ( 5 ) a r e i g n o r e d .
: param f n a m e :
file name string . If None "/etc/resolv.conf" is u s e d .
: returns : ( int ) 0 if OK , else error .
"" "
return _ u n b o u n d . u b _ c t x _ r e s o l v c o n f ( self , f n a m e )
# p a r a m e t e r s : s t r u c t u b _ c t x * , char * ,
# r e t v a l s : int
def s e t _ a s y n c ( self , d o t h r e a d ) :
"" " Set a context b e h a v i o u r for asynchronous a c t i o n .
: param d o t h r e a d :
if True , e n a b l e s t h r e a d i n g and a call to : m e t h : ` r e s o l v e _ a s y n c ` c r e a t e s a t h r e a d to handle w o r k in t h e background .
If False , a process is f o r k e d to handle w o r k in t h e background .
C h a n g e s to t h i s s e t t i n g a f t e r : m e t h : ` a s y n c ` c a l l s h a v e b e e n m a d e h a v e no e f f e c t ( delete and r e - c r e a t e t h e context to c h a n g e ) .
: returns : ( int ) 0 if OK , else error .
"" "
return _ u n b o u n d . u b _ c t x _ a s y n c ( self , d o t h r e a d )
# p a r a m e t e r s : s t r u c t u b _ c t x * , int ,
# r e t v a l s : int
def s e t _ f w d ( self , a d d r ) :
"" " Set m a c h i n e to forward D N S q u e r i e s to , t h e c a c h i n g r e s o l v e r to use .
I P 4 or I P 6 a d d r e s s . Forwards all D N S r e q u e s t s to t h a t m a c h i n e , w h i c h is e x p e c t e d to run a recursive r e s o l v e r . If t h e is not D N S S E C - c a p a b l e , v a l i d a t i o n m a y f a i l . C a n b e c a l l e d s e v e r a l t i m e s , in t h a t case t h e a d d r e s s e s a r e u s e d as b a c k u p s e r v e r s .
To r e a d t h e l i s t of n a m e s e r v e r s from / e t c / r e s o l v . c o n f ( from D H C P or s o ) , use t h e call : m e t h : ` r e s o l v c o n f ` .
: param a d d r :
a d d r e s s , I P 4 or I P 6 in string format . If t h e a d d r is None , f o r w a r d i n g is disabled .
: returns : ( int ) 0 if OK , else error .
"" "
return _ u n b o u n d . u b _ c t x _ s e t _ f w d ( self , a d d r )
# p a r a m e t e r s : s t r u c t u b _ c t x * , char * ,
# r e t v a l s : int
def s e t _ o p t i o n ( self , o p t , v a l ) :
"" " Set a n option for t h e context .
C h a n g e s to t h e o p t i o n s a f t e r : m e t h : ` r e s o l v e ` , : m e t h : ` r e s o l v e _ a s y n c ` , : m e t h : ` z o n e _ a d d ` , : m e t h : ` z o n e _ r e m o v e ` , : m e t h : ` d a t a _ a d d ` or : m e t h : ` d a t a _ r e m o v e ` h a v e no e f f e c t ( y o u h a v e to delete and r e - c r e a t e t h e context ) .
: param o p t :
option name from t h e u n b o u n d . c o n f c o n f i g file format . ( not all s e t t i n g s a p p l i c a b l e ) . T h e name i n c l u d e s t h e trailing ':' for e x a m p l e s e t _ o p t i o n ( "logfile:" , "mylog.txt" ) ; T h i s is a p o w e r - u s e r s interface t h a t l e t s y o u s p e c i f y all s o r t s of o p t i o n s . For some s p e c i f i c o p t i o n s , s u c h as a d d i n g t r u s t a n c h o r s , s p e c i a l r o u t i n e s e x i s t .
: param v a l :
value of t h e option .
: returns : ( int ) 0 if OK , else error .
"" "
return _ u n b o u n d . u b _ c t x _ s e t _ o p t i o n ( self , o p t , v a l )
# p a r a m e t e r s : s t r u c t u b _ c t x * , char * , char * ,
# r e t v a l s : int
def t r u s t e d k e y s ( self , f n a m e ) :
"" " Add t r u s t a n c h o r s to t h e g i v e n context .
P a s s t h e name of a b i n d - s t y l e c o n f i g file with t r u s t e d - k e y s { } .
: param f n a m e :
filename of file with b i n d - s t y l e c o n f i g e n t r i e s with t r u s t a n c h o r s .
: returns : ( int ) 0 if OK , else error .
"" "
return _ u n b o u n d . u b _ c t x _ t r u s t e d k e y s ( self , f n a m e )
# p a r a m e t e r s : s t r u c t u b _ c t x * , char * ,
# r e t v a l s : int
# _ U B _ C T X _ M E T H O D S #
def z o n e _ p r i n t ( self ) :
2015-12-30 03:57:50 -07:00
"" "Print local zones using debugout" ""
2014-10-05 15:44:31 -06:00
_ u n b o u n d . u b _ c t x _ p r i n t _ l o c a l _ z o n e s ( self )
def z o n e _ a d d ( self , z o n e n a m e , z o n e t y p e ) :
"" " Add new l o c a l z o n e
: param z o n e n a m e : z o n e d o m a i n name ( e . g . m y z o n e . )
: param z o n e t y p e : type of t h e z o n e ( "static" , . . . )
: returns : ( int ) 0 if OK , else error .
"" "
return _ u n b o u n d . u b _ c t x _ z o n e _ a d d ( self , z o n e n a m e , z o n e t y p e )
# p a r a m e t e r s : s t r u c t u b _ c t x * , char * , char *
# r e t v a l s : int
def z o n e _ r e m o v e ( self , z o n e n a m e ) :
"" " R e m o v e l o c a l z o n e
If exists , r e m o v e s l o c a l z o n e with all t h e R R s .
: param z o n e n a m e : z o n e d o m a i n name
: returns : ( int ) 0 if OK , else error .
"" "
return _ u n b o u n d . u b _ c t x _ z o n e _ r e m o v e ( self , z o n e n a m e )
# p a r a m e t e r s : s t r u c t u b _ c t x * , char *
# r e t v a l s : int
def d a t a _ a d d ( self , r r d a t a ) :
"" " Add new l o c a l R R d a t a
: param r r d a t a : string , in z o n e - f o r m a t on o n e line . [ d o m a i n n a m e ] [ T T L o p t i o n a l ] [ type ] [ class o p t i o n a l ] [ r d a t a contents ]
: returns : ( int ) 0 if OK , else error .
* * U s a g e * *
T h e l o c a l d a t a . . .
: :
> > > c t x = u n b o u n d . u b _ c t x ( )
> > > c t x . z o n e _ a d d ( "mydomain.net." , "static" )
0
> > > status = c t x . d a t a _ a d d ( "test.mydomain.net. IN A 192.168.1.1" )
0
> > > status , r e s u l t = c t x . r e s o l v e ( "test.mydomain.net" )
> > > if status = = 0 and r e s u l t . h a v e d a t a :
> > > p r i n t \ "Result:\" , r e s u l t . d a t a . a d d r e s s _ l i s t
R e s u l t : [ '192.168.1.1' ]
"" "
return _ u n b o u n d . u b _ c t x _ d a t a _ a d d ( self , r r d a t a )
# p a r a m e t e r s : s t r u c t u b _ c t x * , char *
# r e t v a l s : int
def d a t a _ r e m o v e ( self , r r d a t a ) :
"" " R e m o v e l o c a l R R d a t a
If exists , r e m o v e r e s o u r c e r e c o r d from l o c a l z o n e
: param r r d a t a : string , in z o n e - f o r m a t on o n e line . [ d o m a i n n a m e ] [ T T L o p t i o n a l ] [ type ] [ class o p t i o n a l ] [ r d a t a contents ]
: returns : ( int ) 0 if OK , else error .
"" "
return _ u n b o u n d . u b _ c t x _ d a t a _ r e m o v e ( self , r r d a t a )
# p a r a m e t e r s : s t r u c t u b _ c t x * , char *
# r e t v a l s : int
# U B _ M E T H O D S _ #
def c a n c e l ( self , a s y n c _ i d ) :
"" " C a n c e l a n a s y n c query in progress .
I t s c a l l b a c k w i l l not b e c a l l e d .
: param a s y n c _ i d :
w h i c h query to c a n c e l .
: returns : ( int ) 0 if OK , else error .
"" "
return _ u n b o u n d . u b _ c a n c e l ( self , a s y n c _ i d )
# p a r a m e t e r s : s t r u c t u b _ c t x * , int ,
# r e t v a l s : int
def g e t _ f d ( self ) :
"" " Get file d e s c r i p t o r .
Wait for i t to b e c o m e r e a d a b l e , at t h i s p o i n t a n s w e r s a r e r e t u r n e d from t h e asynchronous v a l i d a t i n g r e s o l v e r . Then call t h e u b _ p r o c e s s to c o n t i n u e p r o c e s s i n g . T h i s r o u t i n e w o r k s i m m e d i a t e l y a f t e r context c r e a t i o n , t h e f d d o e s not c h a n g e .
: returns : ( int ) - 1 on error , or file d e s c r i p t o r to use select ( 2 ) with .
"" "
return _ u n b o u n d . u b _ f d ( self )
# p a r a m e t e r s : s t r u c t u b _ c t x * ,
# r e t v a l s : int
def p o l l ( self ) :
"" " P o l l a context to s e e if i t h a s any new r e s u l t s Do not p o l l in a l o o p , i n s t e a d e x t r a c t t h e f d b e l o w to p o l l for r e a d i n e s s , and then check , or wait using t h e wait r o u t i n e .
: returns : ( int ) 0 if n o t h i n g to r e a d , or n o n z e r o if a r e s u l t is available . If n o n z e r o , call c t x _ p r o c e s s ( ) to do c a l l b a c k s .
"" "
return _ u n b o u n d . u b _ p o l l ( self )
# p a r a m e t e r s : s t r u c t u b _ c t x * ,
# r e t v a l s : int
def process ( self ) :
"" " Call t h i s r o u t i n e to c o n t i n u e p r o c e s s i n g r e s u l t s from t h e v a l i d a t i n g r e s o l v e r ( when t h e f d b e c o m e s r e a d a b l e ) .
W i l l p e r f o r m n e c e s s a r y c a l l b a c k s .
: returns : ( int ) 0 if OK , else error .
"" "
return _ u n b o u n d . u b _ p r o c e s s ( self )
# p a r a m e t e r s : s t r u c t u b _ c t x * ,
# r e t v a l s : int
def r e s o l v e ( self , name , r r t y p e = R R _ T Y P E _ A , r r c l a s s = R R _ C L A S S _ I N ) :
"" " P e r f o r m r e s o l u t i o n and v a l i d a t i o n of t h e target name .
: param name :
d o m a i n name in text format ( a string or u n i c o d e string ) . I D N d o m a i n name h a v e to b e p a s s e d as a u n i c o d e string .
: param r r t y p e :
type of R R in h o s t o r d e r ( o p t i o n a l a r g u m e n t ) . Default value is R R _ T Y P E _ A ( A class ) .
: param r r c l a s s :
class of R R in h o s t o r d e r ( o p t i o n a l a r g u m e n t ) . Default value is R R _ C L A S S _ I N ( for i n t e r n e t ) .
: returns : * ( int ) 0 if OK , else error .
* ( : class : ` u b _ r e s u l t ` ) t h e r e s u l t d a t a is r e t u r n e d in a n e w l y a l l o c a t e d r e s u l t s t r u c t u r e . M a y b e None on return , return value is set to a n error in t h a t case ( o u t of m e m o r y ) .
"" "
if i s i n s t a n c e ( name , b y t e s ) : # p r o b a b l y I D N
return _ u n b o u n d . u b _ r e s o l v e ( self , name , r r t y p e , r r c l a s s )
else :
return _ u n b o u n d . u b _ r e s o l v e ( self , i d n 2 d n a m e ( name ) , r r t y p e , r r c l a s s )
# p a r a m e t e r s : s t r u c t u b _ c t x * , char * , int , int ,
# r e t v a l s : int , s t r u c t u b _ r e s u l t * *
def r e s o l v e _ a s y n c ( self , name , m y d a t a , c a l l b a c k , r r t y p e = R R _ T Y P E _ A , r r c l a s s = R R _ C L A S S _ I N ) :
"" " P e r f o r m r e s o l u t i o n and v a l i d a t i o n of t h e target name .
Asynchronous , a f t e r a while , t h e c a l l b a c k w i l l b e c a l l e d with y o u r d a t a and t h e r e s u l t .
If a n error h a p p e n s d u r i n g p r o c e s s i n g , y o u r c a l l b a c k w i l l b e c a l l e d with error set to a n o n z e r o value ( and r e s u l t = = None ) .
: param name :
d o m a i n name in text format ( a string or u n i c o d e string ) . I D N d o m a i n name h a v e to b e p a s s e d as a u n i c o d e string .
: param m y d a t a :
t h i s d a t a is y o u r o w n d a t a ( y o u c a n p a s s a r b i t r a r y p y t h o n o b j e c t or None ) w h i c h a r e p a s s e d on to t h e c a l l b a c k function .
: param c a l l b a c k :
c a l l - b a c k function w h i c h is c a l l e d on c o m p l e t i o n of t h e r e s o l u t i o n .
: param r r t y p e :
type of R R in h o s t o r d e r ( o p t i o n a l a r g u m e n t ) . Default value is R R _ T Y P E _ A ( A class ) .
: param r r c l a s s :
class of R R in h o s t o r d e r ( o p t i o n a l a r g u m e n t ) . Default value is R R _ C L A S S _ I N ( for i n t e r n e t ) .
: returns : * ( int ) 0 if OK , else error .
* ( int ) a s y n c _ i d , a n i d e n t i f i e r n u m b e r is r e t u r n e d for t h e query as i t is in progress . I t c a n b e u s e d to c a n c e l t h e query .
* * C a l l - b a c k function : * *
T h e c a l l - b a c k function l o o k s as t h e f o l l o w s : :
def c a l l _ b a c k ( m y d a t a , status , r e s u l t ) :
p a s s
* * P a r a m e t e r s : * *
* ` m y d a t a ` - m y d a t a o b j e c t
* ` status ` - 0 when a r e s u l t h a s b e e n f o u n d
* ` r e s u l t ` - t h e r e s u l t s t r u c t u r e . T h e r e s u l t m a y b e None , in t h a t case e r r is set .
"" "
if i s i n s t a n c e ( name , b y t e s ) : # p r o b a b l y I D N
return _ u n b o u n d . _ u b _ r e s o l v e _ a s y n c ( self , name , r r t y p e , r r c l a s s , m y d a t a , c a l l b a c k )
else :
return _ u n b o u n d . _ u b _ r e s o l v e _ a s y n c ( self , i d n 2 d n a m e ( name ) , r r t y p e , r r c l a s s , m y d a t a , c a l l b a c k )
# p a r a m e t e r s : s t r u c t u b _ c t x * , char * , int , int , void * , u b _ c a l l b a c k _ t ,
# r e t v a l s : int , int
def wait ( self ) :
"" " Wait for a context to f i n i s h with r e s u l t s .
C a l l s a f t e r t h e wait for y o u . A f t e r t h e wait , t h e r e a r e no m o r e o u t s t a n d i n g asynchronous q u e r i e s .
: returns : ( int ) 0 if OK , else error .
"" "
return _ u n b o u n d . u b _ w a i t ( self )
# p a r a m e t e r s : s t r u c t u b _ c t x * ,
# r e t v a l s : int
# _ U B _ M E T H O D S #
% }
}
// ================================================================================
// ub_result - validation and resolution results
// ================================================================================
% n o d e f a u l t c t o r u b _ r e s u l t ; //no default constructor & destructor
% n o d e f a u l t d t o r u b _ r e s u l t ;
% d e l o b j e c t u b _ r e s o l v e _ f r e e ;
% r e n a m e ( _ u b _ r e s o l v e _ f r e e ) u b _ r e s o l v e _ f r e e ;
% i n l i n e % {
void u b _ r e s o l v e _ f r e e _ d b g ( s t r u c t u b _ r e s u l t * r ) {
p r i n t f ( "******** UB_RESOLVE free 0x%lX ************\n" , ( l o n g u n s i g n e d int ) r ) ;
u b _ r e s o l v e _ f r e e ( r ) ;
}
% }
% f e a t u r e ( "docstring" ) u b _ r e s u l t "The validation and resolution results."
//ub_result.rcode
% i n l i n e % {
enum r e s u l t _ e n u m _ r c o d e {
R C O D E _ N O E R R O R = 0 ,
R C O D E _ F O R M E R R = 1 ,
R C O D E _ S E R V F A I L = 2 ,
R C O D E _ N X D O M A I N = 3 ,
R C O D E _ N O T I M P L = 4 ,
R C O D E _ R E F U S E D = 5 ,
R C O D E _ Y X D O M A I N = 6 ,
R C O D E _ Y X R R S E T = 7 ,
R C O D E _ N X R R S E T = 8 ,
R C O D E _ N O T A U T H = 9 ,
R C O D E _ N O T Z O N E = 10
} ;
% }
% p y t h o n c o d e % {
class u b _ d a t a :
"" "Class which makes the resolution results accessible" ""
def _ _ i n i t _ _ ( self , d a t a ) :
"" " C r e a t e s u b _ d a t a class
: param d a t a : a l i s t of t h e r e s u l t d a t a in RAW format
"" "
if d a t a = = None :
r a i s e E x c e p t i o n ( "ub_data init: No data" )
self . d a t a = d a t a
def _ _ s t r _ _ ( self ) :
"" "Represents data as string" ""
return ';'.join([' ' . join ( map ( l a m b d a x : "%02X" % o r d ( x ) , a ) ) for a in self . d a t a ] )
@ s t a t i c m e t h o d
def d n a m e 2 s t r ( s , o f s = 0 , m a x l e n = 0 ) :
"" " P a r s e s D N A M E and p r o d u c e s a l i s t of labels
: param o f s : where t h e c o n v e r s i o n s h o u l d start to p a r s e d a t a
: param m a x l e n : maximum length ( 0 m e a n s p a r s e to t h e end )
: returns : l i s t of labels ( string )
"" "
if not s :
return [ ]
r e s = [ ]
s l e n = l e n ( s )
if m a x l e n > 0 :
s l e n = min ( s l e n , m a x l e n )
i d x = o f s
while ( i d x < s l e n ) :
c o m p l e n = o r d ( s [ i d x ] )
# In p y t h o n 3 . x ` s t r ( ) ` c o n v e r t s t h e string to u n i c o d e w h i c h is t h e e x p e c t e d text string type
2015-04-02 03:16:18 -06:00
r e s . append ( s t r ( s [ i d x + 1 : i d x + 1 + c o m p l e n ] . d e c o d e ( ) ) )
2014-10-05 15:44:31 -06:00
i d x + = c o m p l e n + 1
return r e s
def a s _ r a w _ d a t a ( self ) :
"" "Returns a list of RAW strings" ""
return self . d a t a
raw = property ( a s _ r a w _ d a t a , d o c = "Returns RAW data (a list of binary encoded strings). See :meth:`as_raw_data`" )
def a s _ m x _ l i s t ( self ) :
"" " R e p r e s e n t s d a t a as a l i s t of M X r e c o r d s ( query for R R _ T Y P E _ M X )
: returns : l i s t of t u p l e s ( p r i o r i t y , d n a m e )
"" "
return [ ( 256 * o r d ( r d f [ 0 ] ) + o r d ( r d f [ 1 ] ) , '.' . join ( [ a for a in self . d n a m e 2 s t r ( r d f , 2 ) ] ) ) for r d f in self . d a t a ]
m x _ l i s t = property ( a s _ m x _ l i s t , d o c = "Returns a list of tuples containing priority and domain names. See :meth:`as_mx_list`" )
def a s _ i d n _ m x _ l i s t ( self ) :
"" " R e p r e s e n t s d a t a as a l i s t of M X r e c o r d s ( query for R R _ T Y P E _ M X )
: returns : l i s t of t u p l e s ( p r i o r i t y , u n i c o d e d n a m e )
"" "
return [ ( 256 * o r d ( r d f [ 0 ] ) + o r d ( r d f [ 1 ] ) , '.' . join ( [ e n c o d i n g s . i d n a . T o U n i c o d e ( a ) for a in self . d n a m e 2 s t r ( r d f , 2 ) ] ) ) for r d f in self . d a t a ]
m x _ l i s t _ i d n = property ( a s _ i d n _ m x _ l i s t , d o c = "Returns a list of tuples containing priority and IDN domain names. See :meth:`as_idn_mx_list`" )
def a s _ a d d r e s s _ l i s t ( self ) :
"" " R e p r e s e n t s d a t a as a l i s t of I P a d d r e s s e s ( query for R R _ T Y P E _ P T R )
: returns : l i s t of s t r i n g s
"" "
return [ '.' . join ( map ( l a m b d a x : s t r ( o r d ( x ) ) , a ) ) for a in self . d a t a ]
a d d r e s s _ l i s t = property ( a s _ a d d r e s s _ l i s t , d o c = "Returns a list of IP addresses. See :meth:`as_address_list`" )
def a s _ d o m a i n _ l i s t ( self ) :
"" " R e p r e s e n t s d a t a as a l i s t of d o m a i n n a m e s ( query for R R _ T Y P E _ A )
: returns : l i s t of s t r i n g s
"" "
return map ( l a m b d a x : '.' . join ( self . d n a m e 2 s t r ( x ) ) , self . d a t a )
d o m a i n _ l i s t = property ( a s _ d o m a i n _ l i s t , d o c = "Returns a list of domain names. See :meth:`as_domain_list`" )
def a s _ i d n _ d o m a i n _ l i s t ( self ) :
"" " R e p r e s e n t s d a t a as a l i s t of u n i c o d e d o m a i n n a m e s ( query for R R _ T Y P E _ A )
: returns : l i s t of s t r i n g s
"" "
return map ( l a m b d a x : '.' . join ( [ e n c o d i n g s . i d n a . T o U n i c o d e ( a ) for a in self . d n a m e 2 s t r ( x ) ] ) , self . d a t a )
d o m a i n _ l i s t _ i d n = property ( a s _ i d n _ d o m a i n _ l i s t , d o c = "Returns a list of IDN domain names. See :meth:`as_idn_domain_list`" )
% }
% e x t e n d u b _ r e s u l t
{
% r e n a m e ( _ d a t a ) d a t a ;
P y O b j e c t * _ u b _ r e s u l t _ d a t a ( s t r u c t u b _ r e s u l t * r e s u l t ) {
P y O b j e c t * l i s t ;
int i , c n t ;
( void ) self ;
if ( ( r e s u l t = = 0 ) | | ( ! r e s u l t - > h a v e d a t a ) | | ( r e s u l t - > d a t a = = 0 ) )
return P y _ N o n e ;
for ( c n t = 0 , i = 0 ; ; i + + , c n t + + )
if ( r e s u l t - > d a t a [ i ] = = 0 )
break ;
l i s t = P y L i s t _ N e w ( c n t ) ;
for ( i = 0 ; i < c n t ; i + + )
P y L i s t _ S e t I t e m ( l i s t , i , P y B y t e s _ F r o m S t r i n g A n d S i z e ( r e s u l t - > d a t a [ i ] , r e s u l t - > l e n [ i ] ) ) ;
return l i s t ;
}
P y O b j e c t * _ p a c k e t ( ) {
return P y B y t e s _ F r o m S t r i n g A n d S i z e ( $ s e l f - > a n s w e r _ p a c k e t , $ s e l f - > a n s w e r _ l e n ) ;
}
% p y t h o n c o d e % {
def _ _ i n i t _ _ ( self ) :
r a i s e E x c e p t i o n ( "This class can't be created directly." )
# _ _ s w i g _ d e s t r o y _ _ = _ u n b o u n d . u b _ r e s o l v e _ f r e e _ d b g
_ _ s w i g _ d e s t r o y _ _ = _ u n b o u n d . _ u b _ r e s o l v e _ f r e e
# h a v e d a t a = property ( _ u n b o u n d . u b _ r e s u l t _ h a v e d a t a _ g e t , _ u n b o u n d . u b _ r e s u l t _ h a v e d a t a _ s e t , "Havedata property" )
r c o d e 2 s t r = { R C O D E _ N O E R R O R : ' n o e r r o r ' , R C O D E _ F O R M E R R : ' f o r m e r r o r ' , R C O D E _ S E R V F A I L : ' s e r v f a i l ' , R C O D E _ N X D O M A I N : ' n x d o m a i n ' , R C O D E _ N O T I M P L : ' n o t i m p l e m e n t e d ' , R C O D E _ R E F U S E D : ' r e f u s e d ' , R C O D E _ Y X D O M A I N : ' y x d o m a i n ' , R C O D E _ Y X R R S E T : ' y x r r s e t ' , R C O D E _ N X R R S E T : ' n x r r s e t ' , R C O D E _ N O T A U T H : ' n o t a u t h ' , R C O D E _ N O T Z O N E : ' n o t z o n e ' }
def _ g e t _ r c o d e _ s t r ( self ) :
"" " Returns r c o d e in display r e p r e s e n t a t i o n form
: returns : string
"" "
return self . r c o d e 2 s t r [ self . r c o d e ]
_ _ s w i g _ g e t m e t h o d s _ _ [ "rcode_str" ] = _ g e t _ r c o d e _ s t r
if _ n e w c l a s s : r c o d e _ s t r = _ s w i g _ p r o p e r t y ( _ g e t _ r c o d e _ s t r )
def _ g e t _ r a w _ d a t a ( self ) :
"" " R e s u l t d a t a , a l i s t of n e t w o r k o r d e r D N S r d a t a i t e m s .
D a t a a r e r e p r e s e n t e d as a l i s t of s t r i n g s . To d e c o d e RAW d a t a to t h e l i s t of I P a d d r e s s e s use : attr : ` d a t a ` a t t r i b u t e w h i c h returns a n : class : ` u b _ d a t a ` i n s t a n c e c o n t a i n i n g c o n v e r s i o n function .
"" "
return self . _ u b _ r e s u l t _ d a t a ( self )
_ _ s w i g _ g e t m e t h o d s _ _ [ "rawdata" ] = _ g e t _ r a w _ d a t a
r a w d a t a = property ( _ g e t _ r a w _ d a t a , d o c = "Returns raw data, a list of rdata items. To decode RAW data use the :attr:`data` attribute which returns an instance of :class:`ub_data` containing the conversion functions." )
def _ g e t _ d a t a ( self ) :
if not self . h a v e d a t a : return None
return u b _ d a t a ( self . _ u b _ r e s u l t _ d a t a ( self ) )
_ _ s w i g _ g e t m e t h o d s _ _ [ "data" ] = _ g e t _ d a t a
_ _ s w i g _ g e t m e t h o d s _ _ [ "packet" ] = _ p a c k e t
d a t a = property ( _ g e t _ d a t a , d o c = "Returns :class:`ub_data` instance containing various decoding functions or None" )
% }
}
% e x c e p t i o n u b _ r e s o l v e
% {
//printf("resolve_start(%lX)\n",(long unsigned int)arg1);
P y _ B E G I N _ A L L O W _ T H R E A D S
$ function
P y _ E N D _ A L L O W _ T H R E A D S
//printf("resolve_stop()\n");
% }
% i n c l u d e "libunbound/unbound.h"
% i n l i n e % {
//SWIG will see the ub_ctx as a class
s t r u c t u b _ c t x {
} ;
% }
//ub_ctx_debugout void* parameter correction
int u b _ c t x _ d e b u g o u t ( s t r u c t u b _ c t x * c t x , FILE * o u t ) ;
// ================================================================================
// ub_resolve_async - perform asynchronous resolution and validation
// ================================================================================
% t y p e m a p ( in , n u m i n p u t s = 0 , n o b l o c k = 1 ) ( int * a s y n c _ i d )
{
int a s y n c i d = - 1 ;
$ 1 = &asyncid;
}
% apply P y O b j e c t * { v o i d * m y d a t a }
/* r e s u l t g e n e r a t i o n */
% t y p e m a p ( a r g o u t , n o b l o c k = 1 ) ( int * a s y n c _ i d )
{
if ( 1 ) { / * n e w c o d e b l o c k f o r v a r i a b l e o n s t a c k * /
P y O b j e c t * t u p l e ;
t u p l e = P y T u p l e _ N e w ( 2 ) ;
P y T u p l e _ S e t I t e m ( t u p l e , 0 , $ r e s u l t ) ;
P y T u p l e _ S e t I t e m ( t u p l e , 1 , S W I G _ F r o m _ i n t ( a s y n c i d ) ) ;
$ r e s u l t = t u p l e ;
}
}
// Grab a Python function object as a Python object.
% t y p e m a p ( in ) ( P y O b j e c t * p y f u n c ) {
if ( ! P y C a l l a b l e _ C h e c k ( $ input ) )
{
P y E r r _ S e t S t r i n g ( P y E x c _ T y p e E r r o r , "Need a callable object!" ) ;
return NULL ;
}
$ 1 = $ input ;
}
// Python callback workaround
int _ u b _ r e s o l v e _ a s y n c ( s t r u c t u b _ c t x * c t x , char * name , int r r t y p e , int r r c l a s s , void * m y d a t a , P y O b j e c t * p y f u n c , int * a s y n c _ i d ) ;
% {
s t r u c t c b _ d a t a {
P y O b j e c t * d a t a ;
P y O b j e c t * f u n c ;
} ;
static void P y t h o n C a l l B a c k ( void * i d d a t a , int status , s t r u c t u b _ r e s u l t * r e s u l t )
{
P y O b j e c t * a r g l i s t ;
P y O b j e c t * f r e s u l t ;
s t r u c t c b _ d a t a * i d ;
i d = ( s t r u c t c b _ d a t a * ) i d d a t a ;
a r g l i s t = P y _ B u i l d V a l u e ( "(OiO)" , i d - > d a t a , status , S W I G _ N e w P o i n t e r O b j ( S W I G _ a s _ v o i d p t r ( r e s u l t ) , S W I G T Y P E _ p _ u b _ r e s u l t , 0 | 0 ) ) ; // Build argument list
f r e s u l t = P y E v a l _ C a l l O b j e c t ( i d - > f u n c , a r g l i s t ) ; // Call Python
P y _ D E C R E F ( i d - > f u n c ) ;
P y _ D E C R E F ( i d - > d a t a ) ;
f r e e ( i d ) ;
u b _ r e s o l v e _ f r e e ( r e s u l t ) ; //free ub_result
//ub_resolve_free_dbg(result); //free ub_result
P y _ D E C R E F ( a r g l i s t ) ; // Trash arglist
P y _ X D E C R E F ( f r e s u l t ) ;
}
int _ u b _ r e s o l v e _ a s y n c ( s t r u c t u b _ c t x * c t x , char * name , int r r t y p e , int r r c l a s s , P y O b j e c t * m y d a t a , P y O b j e c t * p y f u n c , int * a s y n c _ i d ) {
int r ;
s t r u c t c b _ d a t a * i d ;
i d = ( s t r u c t c b _ d a t a * ) m a l l o c ( s i z e o f ( s t r u c t c b _ d a t a ) ) ;
i d - > d a t a = m y d a t a ;
i d - > f u n c = p y f u n c ;
r = u b _ r e s o l v e _ a s y n c ( c t x , name , r r t y p e , r r c l a s s , ( void * ) i d , P y t h o n C a l l B a c k , a s y n c _ i d ) ;
P y _ I N C R E F ( m y d a t a ) ;
P y _ I N C R E F ( p y f u n c ) ;
return r ;
}
% }
% p y t h o n c o d e % {
u b _ r e s o l v e _ a s y n c = _ u n b o u n d . _ u b _ r e s o l v e _ a s y n c
def r e v e r s e ( d o m a i n ) :
"" " R e v e r s e d o m a i n name
U s a b l e for r e v e r s e l o o k u p s when t h e I P a d d r e s s s h o u l d b e r e v e r s e d
"" "
return '.' . join ( [ a for a in d o m a i n . s p l i t ( "." ) ] [ : : - 1 ] )
def i d n 2 d n a m e ( i d n n a m e ) :
"" " C o n v e r t s d o m a i n name in I D N format to c a n o n i c d o m a i n name
: param i d n n a m e : ( u n i c o d e string ) I D N name
: returns : ( string ) d o m a i n name
"" "
return '.'.join([encodings.idna.ToASCII(a) for a in idnname.split('.' ) ] )
def d n a m e 2 i d n ( name ) :
"" " C o n v e r t s c a n o n i c d o m a i n name in I D N format to u n i c o d e string
: param name : ( string ) d o m a i n name
: returns : ( u n i c o d e string ) d o m a i n name
"" "
return '.'.join([encodings.idna.ToUnicode(a) for a in name.split('.' ) ] )
% }