Sync usage with man page.
[netbsd-mini2440.git] / external / bsd / openldap / dist / libraries / libldap / dds.c
blob656040a835275cfb52f1cf2c22ba6a5517206792
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.
6 * All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
10 * Public License.
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>.
16 /* ACKNOWLEDGEMENTS:
17 * This work was developed by Pierangelo Masarati for inclusion
18 * in OpenLDAP Software */
20 #include "portable.h"
22 #include <stdio.h>
23 #include <ac/stdlib.h>
24 #include <ac/string.h>
25 #include <ac/time.h>
27 #include "ldap-int.h"
29 int
30 ldap_parse_refresh( LDAP *ld, LDAPMessage *res, ber_int_t *newttl )
32 int rc;
33 struct berval *retdata = NULL;
34 ber_tag_t tag;
35 BerElement *ber;
37 assert( ld != NULL );
38 assert( LDAP_VALID( ld ) );
39 assert( res != NULL );
40 assert( newttl != NULL );
42 *newttl = 0;
44 rc = ldap_parse_extended_result( ld, res, NULL, &retdata, 0 );
46 if ( rc != LDAP_SUCCESS ) {
47 return rc;
50 if ( ld->ld_errno != LDAP_SUCCESS ) {
51 return ld->ld_errno;
54 if ( retdata == NULL ) {
55 rc = ld->ld_errno = LDAP_DECODING_ERROR;
56 return rc;
59 ber = ber_init( retdata );
60 if ( ber == NULL ) {
61 rc = ld->ld_errno = LDAP_NO_MEMORY;
62 goto done;
65 /* check the tag */
66 tag = ber_scanf( ber, "{i}", newttl );
67 ber_free( ber, 1 );
69 if ( tag != LDAP_TAG_EXOP_REFRESH_RES_TTL ) {
70 *newttl = 0;
71 rc = ld->ld_errno = LDAP_DECODING_ERROR;
74 done:;
75 if ( retdata ) {
76 ber_bvfree( retdata );
79 return rc;
82 int
83 ldap_refresh(
84 LDAP *ld,
85 struct berval *dn,
86 ber_int_t ttl,
87 LDAPControl **sctrls,
88 LDAPControl **cctrls,
89 int *msgidp )
91 struct berval bv = { 0, NULL };
92 BerElement *ber = NULL;
93 int rc;
95 assert( ld != NULL );
96 assert( LDAP_VALID( ld ) );
97 assert( dn != NULL );
98 assert( msgidp != NULL );
100 *msgidp = -1;
102 ber = ber_alloc_t( LBER_USE_DER );
104 if ( ber == NULL ) {
105 ld->ld_errno = LDAP_NO_MEMORY;
106 return ld->ld_errno;
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 );
115 if ( rc < 0 ) {
116 rc = ld->ld_errno = LDAP_ENCODING_ERROR;
117 goto done;
120 rc = ldap_extended_operation( ld, LDAP_EXOP_REFRESH, &bv,
121 sctrls, cctrls, msgidp );
123 done:;
124 ber_free( ber, 1 );
126 return rc;
130 ldap_refresh_s(
131 LDAP *ld,
132 struct berval *dn,
133 ber_int_t ttl,
134 ber_int_t *newttl,
135 LDAPControl **sctrls,
136 LDAPControl **cctrls )
138 int rc;
139 int msgid;
140 LDAPMessage *res;
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 ) {
150 ldap_msgfree( res );
151 return rc;
154 return ldap_result2error( ld, res, 1 );