1 /*
2 *
3 * Copyright 1998 Sun Microsystems, Inc. All rights reserved.
4 * Use is subject to license terms.
5 *
6 *
7 * Comments:
8 *
9 */
10
11 #pragma ident "%Z%%M% %I% %E% SMI"
12
13 #include <stdio.h>
14 #include <ctype.h>
15 #include <string.h>
16 #include "lber.h"
17 #include "ldap.h"
18 #include "ldap-private.h"
19 #include "ldap-int.h"
20
ldap_first_reference(LDAP * ld,LDAPMessage * res)21 LDAPMessage * ldap_first_reference(LDAP *ld, LDAPMessage *res)
22 {
23 LDAPMessage *msg = res;
24
25 while ( msg != NULLMSG) {
26 if (msg->lm_msgtype == LDAP_RES_SEARCH_REFERENCE)
27 break;
28 msg = msg->lm_chain;
29 }
30 return (msg);
31 }
32
ldap_next_reference(LDAP * ld,LDAPMessage * entry)33 LDAPMessage * ldap_next_reference(LDAP *ld, LDAPMessage *entry)
34 {
35 LDAPMessage *msg;
36
37 if ( entry == NULLMSG)
38 return( NULLMSG );
39
40 msg = entry->lm_chain;
41 while(msg != NULLMSG){
42 if (msg->lm_msgtype == LDAP_RES_SEARCH_REFERENCE)
43 break;
44 msg = msg->lm_chain;
45 }
46
47 return( msg );
48 }
49
50 int
ldap_count_references(LDAP * ld,LDAPMessage * res)51 ldap_count_references( LDAP *ld, LDAPMessage *res )
52 {
53 int i;
54
55 for ( i = 0; res != NULL; res = res->lm_chain )
56 if (res->lm_msgtype == LDAP_RES_SEARCH_REFERENCE)
57 i++;
58
59 return( i );
60 }
61
ldap_get_reference_urls(LDAP * ld,LDAPMessage * res)62 char ** ldap_get_reference_urls(LDAP *ld, LDAPMessage *res)
63 {
64 BerElement tmp;
65 char **urls = NULL;
66
67 Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 1274, "ldap_get_reference_urls\n"), 0, 0, 0 );
68
69 if (res == NULL){
70 ld->ld_errno = LDAP_PARAM_ERROR;
71 return (NULL);
72 }
73 tmp = *res->lm_ber; /* struct copy */
74 if ( ber_scanf( &tmp, "{v}", &urls) == LBER_ERROR){
75 ld->ld_errno = LDAP_DECODING_ERROR;
76 return (NULL);
77 }
78 return (urls);
79 }
80