2007-11-21 12:31:47 +01:00
/*
2006-03-07 20:42:47 +00:00
Unix S M B / C I F S i m p l e m e n t a t i o n .
S w i g interface to l d b .
2006-04-03 09:26:38 +00:00
C o p y r i g h t ( C ) 2005 , 2006 T i m P o t t e r < t p o t @ s a m b a . o r g >
2006-03-07 20:42:47 +00:00
C o p y r i g h t ( C ) 2006 S i m o S o r c e < i d r a @ s a m b a . o r g >
2007-11-21 12:31:47 +01:00
C o p y r i g h t ( C ) 2007 J e l m e r V e r n o o i j < j e l m e r @ s a m b a . o r g >
2006-03-07 20:42:47 +00:00
* * N O T E ! T h e f o l l o w i n g L G P L l i c e n s e a p p l i e s to t h e l d b
* * library . T h i s d o e s NOT i m p l y t h a t all of S a m b a is r e l e a s e d
* * u n d e r t h e L G P L
T h i s library is f r e e s o f t w a r e ; y o u c a n r e d i s t r i b u t e i t and / or
m o d i f y i t u n d e r t h e t e r m s of t h e G N U L e s s e r G e n e r a l Public
L i c e n s e as p u b l i s h e d by t h e F r e e S o f t w a r e F o u n d a t i o n ; e i t h e r
2007-07-10 02:46:15 +00:00
version 3 of t h e L i c e n s e , or ( at y o u r option ) any l a t e r version .
2006-03-07 20:42:47 +00:00
T h i s library is d i s t r i b u t e d in t h e h o p e t h a t i t w i l l b e u s e f u l ,
b u t W I T H O U T ANY W A R R A N T Y ; w i t h o u t e v e n t h e i m p l i e d w a r r a n t y of
M E R C H A N T A B I L I T Y or 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 . S e e t h e G N U
L e s s e r G e n e r a l Public L i c e n s e for m o r e d e t a i l s .
Y o u s h o u l d h a v e r e c e i v e d a c o p y of t h e G N U L e s s e r G e n e r a l Public
2007-07-10 03:42:26 +00:00
L i c e n s e a l o n g with t h i s library ; if not , s e e < h t t p : //www.gnu.org/licenses/>.
2006-03-07 20:42:47 +00:00
* /
2007-11-21 12:31:47 +01:00
% m o d u l e ( p a c k a g e = "ldb" ) l d b
2006-03-07 20:42:47 +00:00
% {
2007-11-21 12:31:47 +01:00
# i n c l u d e < s t d i n t . h >
2007-10-05 23:04:46 +00:00
# i n c l u d e < s t d b o o l . h >
# i n c l u d e "talloc.h"
# i n c l u d e "ldb.h"
2007-11-21 12:31:47 +01:00
# i n c l u d e "ldb_errors.h"
t y p e def s t r u c t l d b _ m e s s a g e l d b _ m s g ;
t y p e def s t r u c t l d b _ c o n t e x t l d b ;
t y p e def s t r u c t l d b _ d n l d b _ d n ;
t y p e def s t r u c t l d b _ l d i f l d b _ l d i f ;
t y p e def s t r u c t l d b _ m e s s a g e _ e l e m e n t l d b _ m s g _ e l e m e n t ;
t y p e def int l d b _ e r r o r ;
2006-03-07 20:42:47 +00:00
% }
2007-11-21 12:31:47 +01:00
% import "carrays.i"
% import "typemaps.i"
2006-04-03 09:26:38 +00:00
% i n c l u d e "exception.i"
2007-11-21 12:31:47 +01:00
% import "stdint.i"
2006-03-07 20:42:47 +00:00
2007-11-21 12:31:47 +01:00
% c o n s t a n t int S C O P E _ D E F A U L T = L D B _ S C O P E _ D E F A U L T ;
% c o n s t a n t int S C O P E _ B A S E = L D B _ S C O P E _ B A S E ;
% c o n s t a n t int S C O P E _ O N E L E V E L = L D B _ S C O P E _ O N E L E V E L ;
% c o n s t a n t int S C O P E _ S U B T R E E = L D B _ S C O P E _ S U B T R E E ;
2006-04-16 03:46:05 +00:00
2007-11-21 12:31:47 +01:00
% c o n s t a n t int C H A N G E T Y P E _ N O N E = L D B _ C H A N G E T Y P E _ N O N E ;
% c o n s t a n t int C H A N G E T Y P E _ A D D = L D B _ C H A N G E T Y P E _ A D D ;
% c o n s t a n t int C H A N G E T Y P E _ D E L E T E = L D B _ C H A N G E T Y P E _ D E L E T E ;
% c o n s t a n t int C H A N G E T Y P E _ M O D I F Y = L D B _ C H A N G E T Y P E _ M O D I F Y ;
2006-04-16 03:46:05 +00:00
2006-04-03 09:26:38 +00:00
/*
* W r a p s t r u c t l d b _ c o n t e x t
* /
/* T h e l d b f u n c t i o n s w i l l c r a s h i f a N U L L l d b c o n t e x t i s p a s s e d s o
catch t h i s b e f o r e i t h a p p e n s . * /
2006-03-07 20:42:47 +00:00
% t y p e m a p ( check ) s t r u c t l d b _ c o n t e x t * {
if ( $ 1 = = NULL )
S W I G _ e x c e p t i o n ( S W I G _ V a l u e E r r o r ,
"ldb context must be non-NULL" ) ;
}
2007-11-21 12:31:47 +01:00
% t y p e m a p ( check ) l d b _ m s g * {
if ( $ 1 = = NULL )
S W I G _ e x c e p t i o n ( S W I G _ V a l u e E r r o r ,
"Message can not be None" ) ;
}
2006-04-03 09:26:38 +00:00
/*
* W r a p s t r u c t l d b _ v a l
* /
2006-04-03 08:03:44 +00:00
2006-04-16 03:46:05 +00:00
% t y p e m a p ( in ) s t r u c t l d b _ v a l * INPUT ( s t r u c t l d b _ v a l t e m p ) {
2006-04-15 10:13:09 +00:00
$ 1 = &temp;
2006-04-03 08:03:44 +00:00
if ( ! P y S t r i n g _ 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 , "string arg expected" ) ;
return NULL ;
}
2006-04-15 10:13:09 +00:00
$ 1 - > length = P y S t r i n g _ S i z e ( $ input ) ;
$ 1 - > d a t a = P y S t r i n g _ A s S t r i n g ( $ input ) ;
2006-04-03 08:03:44 +00:00
}
2006-04-16 03:46:05 +00:00
% t y p e m a p ( o u t ) s t r u c t l d b _ v a l {
2007-11-21 12:31:47 +01:00
$ r e s u l t = P y S t r i n g _ F r o m S t r i n g A n d S i z e ( ( c o n s t char * ) $ 1 . d a t a , $ 1 . length ) ;
2006-03-07 20:42:47 +00:00
}
2007-11-21 12:31:47 +01:00
% t y p e m a p ( in ) l d b _ m s g * a d d _ m s g ( int d i c t _ p o s , int m s g _ p o s , P y O b j e c t * key ,
P y O b j e c t * value , l d b _ m s g _ e l e m e n t * m s g e l ) {
if ( P y D i c t _ C h e c k ( $ input ) ) {
$ 1 = l d b _ m s g _ n e w ( NULL ) ;
$ 1 - > n u m _ e l e m e n t s = P y D i c t _ S i z e ( $ input ) - 1 ; /* d n i s n ' t i n t h e r e */
$ 1 - > e l e m e n t s = t a l l o c _ z e r o _ a r r a y ( $ 1 , s t r u c t l d b _ m e s s a g e _ e l e m e n t , $ 1 - > n u m _ e l e m e n t s + 1 ) ;
m s g _ p o s = d i c t _ p o s = 0 ;
while ( P y D i c t _ N e x t ( $ input , &dict_pos, &key, &value)) {
if ( ! s t r c m p ( P y S t r i n g _ A s S t r i n g ( key ) , "dn" ) ) {
if ( l d b _ d n _ f r o m _ p y o b j e c t ( value , &$1->dn) != 0)
S W I G _ e x c e p t i o n ( S W I G _ T y p e E r r o r , "unable to convert dn" ) ;
} else {
m s g e l = l d b _ m s g _ e l e m e n t _ f r o m _ p y o b j e c t ( value , 0 , P y S t r i n g _ A s S t r i n g ( key ) ) ;
m e m c p y ( &$1->elements[msg_pos], msgel, sizeof(*msgel));
m s g _ p o s + + ;
}
d i c t _ p o s + + ;
}
if ( $ 1 - > d n = = NULL )
S W I G _ e x c e p t i o n ( S W I G _ T y p e E r r o r , "no dn set" ) ;
} else {
2007-11-25 20:12:08 +01:00
if ( S W I G _ C o n v e r t P t r ( $ input , ( void * * ) &$1, SWIGTYPE_p_ldb_message, 0) != 0)
2007-11-21 12:31:47 +01:00
return NULL ;
}
2006-04-03 08:03:44 +00:00
}
2007-11-21 12:31:47 +01:00
% t y p e m a p ( f r e e a r g ) l d b _ m s g * a d d _ m s g {
//talloc_free($1);
}
2006-04-03 09:26:38 +00:00
/*
2007-11-21 12:31:47 +01:00
* W r a p s t r u c t l d b _ r e s u l t
2006-04-03 09:26:38 +00:00
* /
2007-11-21 12:31:47 +01:00
% t y p e m a p ( in , n u m i n p u t s = 0 ) s t r u c t l d b _ r e s u l t * * O U T ( s t r u c t l d b _ r e s u l t * t e m p _ l d b _ r e s u l t ) {
$ 1 = &temp_ldb_result;
}
2006-04-03 09:26:38 +00:00
2007-11-21 12:31:47 +01:00
# i f def S W I G P Y T H O N
% t y p e m a p ( a r g o u t ) s t r u c t l d b _ r e s u l t * * ( int i ) {
$ r e s u l t = P y L i s t _ N e w ( ( * $ 1 ) - > count ) ;
for ( i = 0 ; i < ( * $ 1 ) - > count ; i + + ) {
P y L i s t _ S e t I t e m ( $ r e s u l t , i ,
S W I G _ N e w P o i n t e r O b j ( ( * $ 1 ) - > m s g s [ i ] , S W I G T Y P E _ p _ l d b _ m e s s a g e , 0 )
) ;
}
}
2006-04-03 08:03:44 +00:00
2007-11-21 12:31:47 +01:00
% t y p e m a p ( in , n u m i n p u t s = 1 ) c o n s t char * c o n s t * a t t r s {
if ( $ input = = P y _ N o n e ) {
$ 1 = NULL ;
} else if ( P y S e q u e n c e _ C h e c k ( $ input ) ) {
int i ;
$ 1 = t a l l o c _ a r r a y ( NULL , char * , P y S e q u e n c e _ S i z e ( $ input ) + 1 ) ;
for ( i = 0 ; i < P y S e q u e n c e _ S i z e ( $ input ) ; i + + )
$ 1 [ i ] = P y S t r i n g _ A s S t r i n g ( P y S e q u e n c e _ G e t I t e m ( $ input , i ) ) ;
$ 1 [ i ] = NULL ;
} else {
S W I G _ e x c e p t i o n ( S W I G _ T y p e E r r o r , "expected sequence" ) ;
}
}
2006-04-04 01:22:38 +00:00
2007-11-21 12:31:47 +01:00
% t y p e m a p ( f r e e a r g ) c o n s t char * c o n s t * a t t r s {
t a l l o c _ f r e e ( $ 1 ) ;
}
# e n d i f
2006-04-04 01:22:38 +00:00
2007-11-21 12:31:47 +01:00
% t y p e s ( s t r u c t l d b _ r e s u l t * ) ;
2006-04-04 01:22:38 +00:00
2006-04-03 09:26:38 +00:00
/*
2007-11-21 12:31:47 +01:00
* W r a p s t r u c t l d b _ d n
2006-04-03 09:26:38 +00:00
* /
2006-03-07 20:42:47 +00:00
2007-11-21 12:31:47 +01:00
% r e n a m e ( _ _ s t r _ _ ) l d b _ d n : : g e t _ l i n e a r i z e d ;
% r e n a m e ( _ _ c m p _ _ ) l d b _ d n : : c o m p a r e ;
% r e n a m e ( _ _ l e n _ _ ) l d b _ d n : : g e t _ c o m p _ n u m ;
% r e n a m e ( D n ) l d b _ d n ;
t y p e def s t r u c t l d b _ d n {
% e x t e n d {
l d b _ d n ( l d b * l d b , c o n s t char * s t r )
{
l d b _ d n * r e t = l d b _ d n _ n e w ( l d b , l d b , s t r ) ;
/* l d b _ d n _ n e w ( ) d o e s n ' t a c c e p t N U L L a s m e m o r y c o n t e x t , s o
w e do i t t h i s w a y . . . * /
t a l l o c _ s t e a l ( NULL , r e t ) ;
if ( r e t = = NULL )
S W I G _ e x c e p t i o n ( S W I G _ V a l u e E r r o r ,
"unable to parse dn string" ) ;
f a i l :
return r e t ;
}
~ l d b _ d n ( ) { t a l l o c _ f r e e ( $ s e l f ) ; }
b o o l validate ( ) ;
c o n s t char * g e t _ c a s e f o l d ( ) ;
c o n s t char * g e t _ l i n e a r i z e d ( ) ;
l d b _ d n * parent ( ) { r e t u r n l d b _ d n _ g e t _ p a r e n t ( N U L L , $ s e l f ) ; }
int c o m p a r e ( l d b _ d n * o t h e r ) ;
b o o l i s _ v a l i d ( ) ;
b o o l i s _ s p e c i a l ( ) ;
b o o l i s _ n u l l ( ) ;
b o o l c h e c k _ s p e c i a l ( c o n s t char * name ) ;
int g e t _ c o m p _ n u m ( ) ;
b o o l a d d _ c h i l d ( l d b _ d n * c h i l d ) ;
b o o l a d d _ b a s e ( l d b _ d n * b a s e ) ;
c o n s t char * c a n o n i c a l _ s t r ( ) {
return l d b _ d n _ c a n o n i c a l _ s t r i n g ( $ self , $ self ) ;
}
c o n s t char * c a n o n i c a l _ e x _ s t r ( ) {
return l d b _ d n _ c a n o n i c a l _ e x _ s t r i n g ( $ self , $ self ) ;
}
# i f def S W I G P Y T H O N
l d b _ d n * _ _ a d d _ _ ( l d b _ d n * o t h e r )
{
l d b _ d n * r e t = l d b _ d n _ c o p y ( NULL , $ self ) ;
l d b _ d n _ a d d _ c h i l d ( r e t , o t h e r ) ;
return r e t ;
}
/* F I X M E : i m p l e m e n t _ _ g e t s l i c e _ _ */
# e n d i f
}
} l d b _ d n ;
# i f def S W I G P Y T H O N
% i n l i n e {
int l d b _ d n _ f r o m _ p y o b j e c t ( P y O b j e c t * o b j e c t , l d b _ d n * * d n )
{
2007-11-25 20:12:08 +01:00
return S W I G _ C o n v e r t P t r ( o b j e c t , ( void * * ) d n , S W I G T Y P E _ p _ l d b _ d n , 0 ) ;
2007-11-21 12:31:47 +01:00
}
2006-04-17 21:59:44 +00:00
2007-11-21 12:31:47 +01:00
l d b _ m s g _ e l e m e n t * l d b _ m s g _ e l e m e n t _ f r o m _ p y o b j e c t ( P y O b j e c t * s e t _ o b j , int f l a g s ,
c o n s t char * a t t r _ n a m e )
{
s t r u c t l d b _ m e s s a g e _ e l e m e n t * m e = t a l l o c ( NULL , s t r u c t l d b _ m e s s a g e _ e l e m e n t ) ;
m e - > name = a t t r _ n a m e ;
m e - > f l a g s = f l a g s ;
if ( P y S t r i n g _ C h e c k ( s e t _ o b j ) ) {
m e - > n u m _ v a l u e s = 1 ;
m e - > values = t a l l o c _ a r r a y ( m e , s t r u c t l d b _ v a l , m e - > n u m _ v a l u e s ) ;
m e - > values [ 0 ] . length = P y S t r i n g _ S i z e ( s e t _ o b j ) ;
m e - > values [ 0 ] . d a t a = ( u i n t 8 _ t * ) t a l l o c _ s t r d u p ( m e - > values ,
P y S t r i n g _ A s S t r i n g ( s e t _ o b j ) ) ;
} else if ( P y S e q u e n c e _ C h e c k ( s e t _ o b j ) ) {
int i ;
m e - > n u m _ v a l u e s = P y S e q u e n c e _ S i z e ( s e t _ o b j ) ;
m e - > values = t a l l o c _ a r r a y ( m e , s t r u c t l d b _ v a l , m e - > n u m _ v a l u e s ) ;
for ( i = 0 ; i < m e - > n u m _ v a l u e s ; i + + ) {
P y O b j e c t * o b j = P y S e q u e n c e _ G e t I t e m ( s e t _ o b j , i ) ;
m e - > values [ i ] . length = P y S t r i n g _ S i z e ( o b j ) ;
m e - > values [ i ] . d a t a = ( u i n t 8 _ t * ) P y S t r i n g _ A s S t r i n g ( o b j ) ;
}
} else {
t a l l o c _ f r e e ( m e ) ;
m e = NULL ;
}
return m e ;
}
2006-03-07 20:42:47 +00:00
2007-11-21 12:31:47 +01:00
P y O b j e c t * l d b _ m s g _ e l e m e n t _ t o _ s e t ( l d b _ m s g _ e l e m e n t * m e )
{
int i ;
P y O b j e c t * r e s u l t ;
2006-05-02 05:14:00 +00:00
2007-11-21 12:31:47 +01:00
/* P y t h o n < < 2 . 5 d o e s n ' t h a v e P y S e t _ N e w a n d P y S e t _ A d d . */
r e s u l t = P y L i s t _ N e w ( m e - > n u m _ v a l u e s ) ;
2006-04-04 01:22:38 +00:00
2007-11-21 12:31:47 +01:00
for ( i = 0 ; i < m e - > n u m _ v a l u e s ; i + + ) {
P y L i s t _ S e t I t e m ( r e s u l t , i ,
P y S t r i n g _ F r o m S t r i n g A n d S i z e ( ( c o n s t char * ) m e - > values [ i ] . d a t a ,
m e - > values [ i ] . length ) ) ;
}
2006-05-02 05:14:00 +00:00
2007-11-21 12:31:47 +01:00
return r e s u l t ;
}
2006-03-07 20:42:47 +00:00
2007-11-21 12:31:47 +01:00
}
# e n d i f
/* l d b _ m e s s a g e _ e l e m e n t */
% r e n a m e ( _ _ c m p _ _ ) l d b _ m e s s a g e _ e l e m e n t : : c o m p a r e ;
% r e n a m e ( M e s s a g e E l e m e n t ) l d b _ m s g _ e l e m e n t ;
t y p e def s t r u c t l d b _ m e s s a g e _ e l e m e n t {
% e x t e n d {
# i f def S W I G P Y T H O N
P y O b j e c t * _ _ i t e r _ _ ( void )
{
return P y O b j e c t _ G e t I t e r ( l d b _ m s g _ e l e m e n t _ t o _ s e t ( $ self ) ) ;
}
P y O b j e c t * _ _ s e t _ _ ( void )
{
return l d b _ m s g _ e l e m e n t _ t o _ s e t ( $ self ) ;
}
l d b _ m s g _ e l e m e n t ( P y O b j e c t * s e t _ o b j , int f l a g s = 0 , c o n s t char * name = NULL )
{
return l d b _ m s g _ e l e m e n t _ f r o m _ p y o b j e c t ( s e t _ o b j , f l a g s , name ) ;
}
# e n d i f
~ l d b _ m s g _ e l e m e n t ( ) { t a l l o c _ f r e e ( $ s e l f ) ; }
int c o m p a r e ( l d b _ m s g _ e l e m e n t * ) ;
}
} l d b _ m s g _ e l e m e n t ;
/* l d b _ m e s s a g e */
% r e n a m e ( Message ) l d b _ m e s s a g e ;
# i f def S W I G P Y T H O N
% r e n a m e ( _ _ d e l i t e m _ _ ) l d b _ m e s s a g e : : r e m o v e _ a t t r ;
% t y p e m a p ( o u t ) l d b _ m s g _ e l e m e n t * {
if ( $ 1 = = NULL )
P y E r r _ S e t S t r i n g ( P y E x c _ K e y E r r o r , "no such element" ) ;
else
$ r e s u l t = S W I G _ N e w P o i n t e r O b j ( $ 1 , S W I G T Y P E _ p _ l d b _ m e s s a g e _ e l e m e n t , 0 ) ;
}
% r e n a m e ( _ _ g e t i t e m _ _ ) l d b _ m e s s a g e : : f i n d _ e l e m e n t ;
//%typemap(out) ldb_msg_element *;
% i n l i n e {
P y O b j e c t * l d b _ m s g _ l i s t _ e l e m e n t s ( l d b _ m s g * m s g )
{
int i ;
P y O b j e c t * o b j = P y L i s t _ N e w ( m s g - > n u m _ e l e m e n t s ) ;
for ( i = 0 ; i < m s g - > n u m _ e l e m e n t s ; i + + )
P y L i s t _ S e t I t e m ( o b j , i , P y S t r i n g _ F r o m S t r i n g ( m s g - > e l e m e n t s [ i ] . name ) ) ;
return o b j ;
}
}
2006-04-04 01:22:38 +00:00
2007-11-21 12:31:47 +01:00
# e n d i f
t y p e def s t r u c t l d b _ m e s s a g e {
l d b _ d n * d n ;
% e x t e n d {
l d b _ m s g ( l d b _ d n * d n = NULL ) {
l d b _ m s g * r e t = l d b _ m s g _ n e w ( NULL ) ;
r e t - > d n = t a l l o c _ r e f e r e n c e ( r e t , d n ) ;
return r e t ;
}
~ l d b _ m s g ( ) { t a l l o c _ f r e e ( $ s e l f ) ; }
l d b _ m s g _ e l e m e n t * f i n d _ e l e m e n t ( c o n s t char * name ) ;
# i f def S W I G P Y T H O N
void _ _ s e t i t e m _ _ ( c o n s t char * a t t r _ n a m e , l d b _ m s g _ e l e m e n t * v a l )
{
s t r u c t l d b _ m e s s a g e _ e l e m e n t * e l ;
l d b _ m s g _ r e m o v e _ a t t r ( $ self , a t t r _ n a m e ) ;
e l = t a l l o c ( $ self , s t r u c t l d b _ m e s s a g e _ e l e m e n t ) ;
e l - > name = t a l l o c _ s t r d u p ( e l , a t t r _ n a m e ) ;
e l - > n u m _ v a l u e s = v a l - > n u m _ v a l u e s ;
e l - > values = t a l l o c _ r e f e r e n c e ( e l , v a l - > values ) ;
l d b _ m s g _ a d d ( $ self , e l , v a l - > f l a g s ) ;
}
void _ _ s e t i t e m _ _ ( c o n s t char * a t t r _ n a m e , P y O b j e c t * v a l )
{
s t r u c t l d b _ m e s s a g e _ e l e m e n t * e l = l d b _ m s g _ e l e m e n t _ f r o m _ p y o b j e c t (
v a l , 0 , a t t r _ n a m e ) ;
t a l l o c _ s t e a l ( $ self , e l ) ;
l d b _ m s g _ r e m o v e _ a t t r ( $ self , a t t r _ n a m e ) ;
l d b _ m s g _ a d d ( $ self , e l , e l - > f l a g s ) ;
}
u n s i g n e d int _ _ l e n _ _ ( ) { r e t u r n $ s e l f - > n u m _ e l e m e n t s ; }
P y O b j e c t * keys ( void )
{
return l d b _ m s g _ l i s t _ e l e m e n t s ( $ self ) ;
}
P y O b j e c t * _ _ i t e r _ _ ( void )
{
return P y O b j e c t _ G e t I t e r ( l d b _ m s g _ l i s t _ e l e m e n t s ( $ self ) ) ;
}
# e n d i f
void r e m o v e _ a t t r ( c o n s t char * name ) ;
}
} l d b _ m s g ;
/* F I X M E : C o n v e r t l d b _ r e s u l t t o 3 - t u p l e :
( m s g s , r e f s , c o n t r o l s )
* /
2006-04-04 01:22:38 +00:00
2007-11-21 12:31:47 +01:00
t y p e def s t r u c t l d b _ l d i f l d b _ l d i f ;
2006-04-04 01:22:38 +00:00
2007-11-21 12:31:47 +01:00
# i f def S W I G P Y T H O N
% {
static void p y _ l d b _ d e b u g ( void * context , enum l d b _ d e b u g _ l e v e l l e v e l , c o n s t char * f m t , v a _ l i s t a p )
{
char * text ;
P y O b j e c t * f n = context ;
v a s p r i n t f ( &text, fmt, ap);
P y O b j e c t _ C a l l F u n c t i o n ( f n , "(i,s)" , l e v e l , text ) ;
f r e e ( text ) ;
}
% }
2006-04-15 10:13:09 +00:00
2007-11-21 12:31:47 +01:00
% t y p e m a p ( in , n u m i n p u t s = 1 ) ( void ( * debug ) ( void * context , enum l d b _ d e b u g _ l e v e l l e v e l , c o n s t char * f m t , v a _ l i s t a p ) ,
void * context ) {
$ 1 = p y _ l d b _ d e b u g ;
2007-11-25 14:26:16 +01:00
/* F I X M E : S h o u l d b e d e c r e a s e d s o m e w h e r e a s w e l l . P e r h a p s r e g i s t e r a
destructor and t i e i t to t h e l d b context ? * /
2007-11-21 12:31:47 +01:00
P y _ I N C R E F ( $ input ) ;
$ 2 = $ input ;
}
# e n d i f
% i n l i n e {
static P y O b j e c t * l d b _ l d i f _ t o _ p y o b j e c t ( l d b _ l d i f * l d i f )
{
if ( l d i f = = NULL ) {
return P y _ N o n e ;
} else {
return P y _ B u i l d V a l u e ( "(iO)" , l d i f - > c h a n g e t y p e ,
S W I G _ N e w P o i n t e r O b j ( l d i f - > m s g , S W I G T Y P E _ p _ l d b _ m e s s a g e , 0 ) ) ;
}
}
}
2006-05-02 05:14:00 +00:00
2007-11-21 12:31:47 +01:00
/*
* W r a p l d b e r r o r s
* /
2006-05-02 05:14:00 +00:00
2007-11-21 12:31:47 +01:00
% {
P y O b j e c t * P y E x c _ L d b E r r o r ;
% }
2006-05-02 05:14:00 +00:00
2007-11-21 12:31:47 +01:00
% p y t h o n c o d e % {
L d b E r r o r = _ l d b . L d b E r r o r
% }
2006-04-16 06:05:33 +00:00
2007-11-21 12:31:47 +01:00
% init % {
P y E x c _ L d b E r r o r = P y E r r _ N e w E x c e p t i o n ( "_ldb.LdbError" , NULL , NULL ) ;
P y D i c t _ S e t I t e m S t r i n g ( d , "LdbError" , P y E x c _ L d b E r r o r ) ;
% }
2006-05-02 05:14:00 +00:00
2007-11-21 12:31:47 +01:00
% i g n o r e _ L D B _ E R R O R S _ H _ ;
% i g n o r e L D B _ S U C C E S S ;
% i n c l u d e "include/ldb_errors.h"
2006-05-02 05:14:00 +00:00
2007-11-21 12:31:47 +01:00
/*
* W r a p l d b f u n c t i o n s
* /
2006-05-02 05:14:00 +00:00
2007-11-21 12:31:47 +01:00
% r e n a m e ( L d b ) l d b ;
/* T o p - l e v e l l d b o p e r a t i o n s */
t y p e def s t r u c t l d b _ c o n t e x t {
% t y p e m a p ( o u t ) l d b _ e r r o r {
if ( $ 1 ! = L D B _ S U C C E S S ) {
P y E r r _ S e t O b j e c t ( P y E x c _ L d b E r r o r , P y _ B u i l d V a l u e ( "(i,s)" , $ 1 , l d b _ s t r e r r o r ( $ 1 ) ) ) ;
S W I G _ f a i l ;
}
$ r e s u l t = P y _ N o n e ;
} ;
% e x t e n d {
l d b ( c o n s t char * url = NULL , u n s i g n e d int f l a g s = 0 ,
c o n s t char * o p t i o n s [ ] = NULL )
{
l d b * l d b = l d b _ i n i t ( NULL ) ;
if ( url ! = NULL ) {
int r e t ;
r e t = l d b _ c o n n e c t ( l d b , url , f l a g s , o p t i o n s ) ;
if ( r e t ! = L D B _ S U C C E S S )
S W I G _ e x c e p t i o n ( S W I G _ V a l u e E r r o r , l d b _ e r r s t r i n g ( l d b ) ) ;
}
return l d b ;
f a i l :
t a l l o c _ f r e e ( l d b ) ;
return NULL ;
}
l d b _ e r r o r connect ( c o n s t char * url , u n s i g n e d int f l a g s = 0 ,
c o n s t char * o p t i o n s [ ] = NULL ) ;
~ l d b ( ) { t a l l o c _ f r e e ( $ s e l f ) ; }
l d b _ e r r o r search ( l d b _ d n * b a s e = NULL ,
enum l d b _ s c o p e s c o p e = L D B _ S C O P E _ D E F A U L T ,
c o n s t char * e x p r e s s i o n = NULL ,
c o n s t char * c o n s t * a t t r s = NULL ,
s t r u c t l d b _ r e s u l t * * O U T ) ;
l d b _ e r r o r delete ( l d b _ d n * d n ) ;
l d b _ e r r o r r e n a m e ( l d b _ d n * o l d d n , l d b _ d n * n e w d n ) ;
l d b _ e r r o r add ( l d b _ m s g * a d d _ m s g ) ;
l d b _ e r r o r m o d i f y ( l d b _ m s g * message ) ;
l d b _ d n * g e t _ c o n f i g _ b a s e d n ( ) ;
l d b _ d n * g e t _ r o o t _ b a s e d n ( ) ;
l d b _ d n * g e t _ s c h e m a _ b a s e d n ( ) ;
l d b _ d n * g e t _ d e f a u l t _ b a s e d n ( ) ;
c o n s t char * e r r s t r i n g ( ) ;
void s e t _ c r e a t e _ p e r m s ( u n s i g n e d int p e r m s ) ;
void s e t _ m o d u l e s _ d i r ( c o n s t char * p a t h ) ;
l d b _ e r r o r s e t _ d e b u g ( void ( * debug ) ( void * context , enum l d b _ d e b u g _ l e v e l l e v e l ,
c o n s t char * f m t , v a _ l i s t a p ) ,
void * context ) ;
l d b _ e r r o r s e t _ o p a q u e ( c o n s t char * name , void * value ) ;
void * g e t _ o p a q u e ( c o n s t char * name ) ;
l d b _ e r r o r t r a n s a c t i o n _ s t a r t ( ) ;
l d b _ e r r o r t r a n s a c t i o n _ c o m m i t ( ) ;
l d b _ e r r o r t r a n s a c t i o n _ c a n c e l ( ) ;
# i f def S W I G P Y T H O N
2007-11-25 14:26:16 +01:00
% t y p e m a p ( in , n u m i n p u t s = 0 ) s t r u c t l d b _ r e s u l t * * r e s u l t _ a s _ b o o l ( s t r u c t l d b _ r e s u l t * t m p ) { $ 1 = & t m p ; }
% t y p e m a p ( a r g o u t ) s t r u c t l d b _ r e s u l t * * r e s u l t _ a s _ b o o l { $ r e s u l t = ( ( * $ 1 ) - > c o u n t > 0 ) ? P y _ T r u e : P y _ F a l s e ; }
2007-11-28 22:41:34 +01:00
% t y p e m a p ( f r e e a r g ) s t r u c t l d b _ r e s u l t * * r e s u l t _ a s _ b o o l { t a l l o c _ f r e e ( * $ 1 ) ; }
2007-11-25 14:26:16 +01:00
l d b _ e r r o r _ _ c o n t a i n s _ _ ( l d b _ d n * d n , s t r u c t l d b _ r e s u l t * * r e s u l t _ a s _ b o o l )
2007-11-21 12:31:47 +01:00
{
2007-11-25 14:26:16 +01:00
return l d b _ s e a r c h ( $ self , d n , L D B _ S C O P E _ B A S E , NULL , NULL ,
r e s u l t _ a s _ b o o l ) ;
2007-11-21 12:31:47 +01:00
}
P y O b j e c t * p a r s e _ l d i f ( c o n s t char * s )
{
P y O b j e c t * l i s t = P y L i s t _ N e w ( 0 ) ;
s t r u c t l d b _ l d i f * l d i f ;
while ( ( l d i f = l d b _ l d i f _ r e a d _ s t r i n g ( $ self , &s)) != NULL) {
P y L i s t _ A p p e n d ( l i s t , l d b _ l d i f _ t o _ p y o b j e c t ( l d i f ) ) ;
}
return P y O b j e c t _ G e t I t e r ( l i s t ) ;
}
# e n d i f
}
} l d b ;
% n o d e f a u l t l d b _ m e s s a g e ;
% n o d e f a u l t L d b ;
% n o d e f a u l t D n ;
% r e n a m e ( v a l i d _ a t t r _ n a m e ) l d b _ v a l i d _ a t t r _ n a m e ;
int l d b _ v a l i d _ a t t r _ n a m e ( c o n s t char * s ) ;
t y p e def u n s i g n e d l o n g t i m e _ t ;
2006-05-02 05:14:00 +00:00
2007-11-21 13:07:16 +01:00
% i n l i n e % {
static char * t i m e s t r i n g ( t i m e _ t t )
2007-11-21 12:31:47 +01:00
{
char * t r e s u l t = l d b _ t i m e s t r i n g ( NULL , t ) ;
char * r e s u l t = s t r d u p ( t r e s u l t ) ;
t a l l o c _ f r e e ( t r e s u l t ) ;
return r e s u l t ;
}
% }
2007-10-05 23:04:46 +00:00
2007-11-21 12:31:47 +01:00
% r e n a m e ( s t r i n g _ t o _ t i m e ) l d b _ s t r i n g _ t o _ t i m e ;
t i m e _ t l d b _ s t r i n g _ t o _ t i m e ( c o n s t char * s ) ;