1 /* $OpenLDAP: pkg/ldap/libraries/libldap/dds.c,v 1.2.2.3 2008/02/11 23:26:41 kurt Exp $ */
2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 2005-2008 The OpenLDAP Foundation.
5 * Portions Copyright 2005-2006 SysNet s.n.c.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
17 * This work was developed by Pierangelo Masarati for inclusion
18 * in OpenLDAP Software */
23 #include <ac/stdlib.h>
24 #include <ac/string.h>
30 ldap_parse_refresh( LDAP
*ld
, LDAPMessage
*res
, ber_int_t
*newttl
)
33 struct berval
*retdata
= NULL
;
38 assert( LDAP_VALID( ld
) );
39 assert( res
!= NULL
);
40 assert( newttl
!= NULL
);
44 rc
= ldap_parse_extended_result( ld
, res
, NULL
, &retdata
, 0 );
46 if ( rc
!= LDAP_SUCCESS
) {
50 if ( ld
->ld_errno
!= LDAP_SUCCESS
) {
54 if ( retdata
== NULL
) {
55 rc
= ld
->ld_errno
= LDAP_DECODING_ERROR
;
59 ber
= ber_init( retdata
);
61 rc
= ld
->ld_errno
= LDAP_NO_MEMORY
;
66 tag
= ber_scanf( ber
, "{i}", newttl
);
69 if ( tag
!= LDAP_TAG_EXOP_REFRESH_RES_TTL
) {
71 rc
= ld
->ld_errno
= LDAP_DECODING_ERROR
;
76 ber_bvfree( retdata
);
91 struct berval bv
= { 0, NULL
};
92 BerElement
*ber
= NULL
;
96 assert( LDAP_VALID( ld
) );
98 assert( msgidp
!= NULL
);
102 ber
= ber_alloc_t( LBER_USE_DER
);
105 ld
->ld_errno
= LDAP_NO_MEMORY
;
109 ber_printf( ber
, "{tOtiN}",
110 LDAP_TAG_EXOP_REFRESH_REQ_DN
, dn
,
111 LDAP_TAG_EXOP_REFRESH_REQ_TTL
, ttl
);
113 rc
= ber_flatten2( ber
, &bv
, 0 );
116 rc
= ld
->ld_errno
= LDAP_ENCODING_ERROR
;
120 rc
= ldap_extended_operation( ld
, LDAP_EXOP_REFRESH
, &bv
,
121 sctrls
, cctrls
, msgidp
);
135 LDAPControl
**sctrls
,
136 LDAPControl
**cctrls
)
142 rc
= ldap_refresh( ld
, dn
, ttl
, sctrls
, cctrls
, &msgid
);
143 if ( rc
!= LDAP_SUCCESS
) return rc
;
145 rc
= ldap_result( ld
, msgid
, LDAP_MSG_ALL
, (struct timeval
*)NULL
, &res
);
146 if( rc
== -1 || !res
) return ld
->ld_errno
;
148 rc
= ldap_parse_refresh( ld
, res
, newttl
);
149 if( rc
!= LDAP_SUCCESS
) {
154 return ldap_result2error( ld
, res
, 1 );