]> git.sur5r.net Git - openldap/blob - libraries/libldap/options.c
struct ldap is now opaque to clients.
[openldap] / libraries / libldap / options.c
1 #include "portable.h"
2
3 #include <stdio.h>
4 #include <stdlib.h>
5
6 #include <ac/socket.h>
7 #include <ac/string.h>
8
9 #include "ldap-int.h"
10
11 int
12 ldap_get_option(
13         LDAP    *ldp,
14         int             option,
15         void    *outvalue)
16 {
17         LDAP *ld;
18
19         if(!openldap_ldap_initialized) {
20                 openldap_ldap_initialize();
21         }
22
23         if(outvalue == NULL) {
24                 /* no place to get to */
25                 return -1;
26         }
27
28         if(ldp == NULL) {
29                 ld = &openldap_ld_globals;
30         } else {
31                 ld = ld;
32         }
33
34         switch(option) {
35         case LDAP_OPT_API_INFO: {
36                         struct ldapapiinfo *info = (struct ldapapiinfo *) outvalue;
37
38                         if(info == NULL) {
39                                 /* outvalue must point to an apiinfo structure */
40                                 return -1;
41                         }
42
43                         if(info->ldapai_info_version != 1) {
44                                 /* version mismatch */
45                                 return -1;
46                         }
47
48                         info->ldapai_api_version = LDAP_API_VERSION;
49                         info->ldapai_protocol_version = LDAP_VERSION_MAX;
50                         info->ldapai_extensions = NULL;
51                         info->ldapai_vendor_name = strdup(LDAP_VENDOR);
52                         info->ldapai_vendor_version = LDAP_VENDOR_VERSION;
53
54                         return 0;
55                 } break;
56
57         case LDAP_OPT_DESC:
58                 if(ldp == NULL) {
59                         /* bad param */
60                         break;
61                 } 
62
63                 * (int *) outvalue = ld->ld_sb.sb_sd;
64                 return 0;
65
66         case LDAP_OPT_DEREF:
67                 * (int *) outvalue = ld->ld_deref;
68                 return 0;
69
70         case LDAP_OPT_SIZELIMIT:
71                 * (int *) outvalue = ld->ld_sizelimit;
72                 return 0;
73
74         case LDAP_OPT_TIMELIMIT:
75                 * (int *) outvalue = ld->ld_timelimit;
76                 return 0;
77
78         case LDAP_OPT_REFERRALS:
79                 * (int *) outvalue = (int) LDAP_BOOL_GET(ld, LDAP_BOOL_REFERRALS);
80                 return 0;
81                 
82         case LDAP_OPT_RESTART:
83                 * (int *) outvalue = (int) LDAP_BOOL_GET(ld, LDAP_BOOL_RESTART);
84                 return 0;
85
86         case LDAP_OPT_DNS:      /* LDAPv2 */
87                 * (int *) outvalue = (int) LDAP_BOOL_GET(ld, LDAP_BOOL_DNS);
88                 return 0;
89
90         case LDAP_OPT_PROTOCOL_VERSION:
91                 * (int *) outvalue = ld->ld_version;
92                 return 0;
93
94         case LDAP_OPT_SERVER_CONTROLS:
95         case LDAP_OPT_CLIENT_CONTROLS:
96                 /* not yet supported */
97                 break;
98
99         case LDAP_OPT_HOST_NAME:
100                 * (char **) outvalue = ld->ld_host;
101                 return 0;
102
103         case LDAP_OPT_ERROR_NUMBER:
104                 * (int *) outvalue = ld->ld_errno;
105                 return 0;
106
107         case LDAP_OPT_ERROR_STRING:
108                 /* not yet supported */
109                 break;
110
111         default:
112                 /* bad param */
113                 break;
114         }
115
116         return -1;
117 }
118
119 int
120 ldap_set_option(
121         LDAP    *ldp,
122         int             option,
123         void    *invalue)
124 {
125         LDAP *ld;
126
127         if(!openldap_ldap_initialized) {
128                 openldap_ldap_initialize();
129         }
130
131         if(invalue == NULL) {
132                 /* no place to set from */
133                 return -1;
134         }
135
136         if(ldp == NULL) {
137                 ld = &openldap_ld_globals;
138         } else {
139                 ld = ld;
140         }
141
142         switch(option) {
143         case LDAP_OPT_API_INFO:
144         case LDAP_OPT_DESC:
145                 /* READ ONLY */
146                 break;
147
148         case LDAP_OPT_DEREF:
149                 ld->ld_deref = * (int *) invalue;
150                 return 0;
151
152         case LDAP_OPT_SIZELIMIT:
153                 ld->ld_sizelimit = * (int *) invalue;
154                 return 0;
155
156         case LDAP_OPT_TIMELIMIT:
157                 ld->ld_timelimit = * (int *) invalue;
158                 return 0;
159
160         case LDAP_OPT_REFERRALS:
161                 if((int) invalue == (int) LDAP_OPT_ON) {
162                         LDAP_BOOL_SET(ld, LDAP_BOOL_REFERRALS);
163                 } else {
164                         LDAP_BOOL_CLR(ld, LDAP_BOOL_REFERRALS);
165                 }
166                 return 0;
167
168         case LDAP_OPT_RESTART:
169                 if((int) invalue == (int) LDAP_OPT_ON) {
170                         LDAP_BOOL_SET(ld, LDAP_BOOL_RESTART);
171                 } else {
172                         LDAP_BOOL_CLR(ld, LDAP_BOOL_RESTART);
173                 }
174                 return 0;
175
176         case LDAP_OPT_PROTOCOL_VERSION: {
177                         int vers = * (int *) invalue;
178                         if (vers > LDAP_VERSION_MAX) {
179                                 /* not supported */
180                                 break;
181                         }
182                         ld->ld_version = vers;
183                 } return 0;
184
185         case LDAP_OPT_SERVER_CONTROLS:
186         case LDAP_OPT_CLIENT_CONTROLS:
187         case LDAP_OPT_HOST_NAME:
188         case LDAP_OPT_ERROR_NUMBER:
189         case LDAP_OPT_ERROR_STRING:
190                 /* not yet supported */
191                 break;
192         default:
193                 /* bad param */
194                 break;
195         }
196         return -1;
197 }