5 #include <pdns/misc.hh>
6 #include <pdns/utility.hh>
9 #ifndef LDAPBACKEND_UTILS_HH
10 #define LDAPBACKEND_UTILS_HH
16 inline string
ptr2ip4( vector
<string
>& parts
)
26 while( !parts
.empty() )
28 ip
+= "." + parts
.back();
36 inline string
ptr2ip6( vector
<string
>& parts
)
45 while( i
< 3 && parts
.size() > 1 && parts
.back() == "0" )
51 while( i
++ < 4 && !parts
.empty() )
57 while( !parts
.empty() )
62 while( i
< 3 && parts
.size() > 1 && parts
.back() == "0" )
68 while( i
++ < 4 && !parts
.empty() )
79 inline string
ip2ptr4( const string
& ip
)
84 stringtok( parts
, ip
, "." );
85 while( !parts
.empty() )
87 ptr
+= parts
.back() + ".";
91 return ptr
+ "in-addr.arpa";
95 inline string
ip2ptr6( const string
& ip
)
97 string ptr
, part
, defstr
;
100 stringtok( parts
, ip
, ":" );
101 while( !parts
.empty() )
106 while( part
.length() < 4 )
119 return ptr
+ "ip6.arpa";
123 inline string
strbind( const string
& search
, const string
& replace
, string subject
)
128 while( ( pos
= subject
.find( search
, pos
) ) != string::npos
)
130 subject
.replace( pos
, search
.size(), replace
);
131 pos
+= replace
.size();
138 * Convert a LDAP time string to a time_t. Return 0 if unable to convert
141 inline time_t str2tstamp( const string
& str
)
146 tmp
= strptime( str
.c_str(), "%Y%m%d%H%M%SZ", &tm
);
148 if( tmp
!= NULL
&& *tmp
== 0 )
150 return Utility::timegm( &tm
);