]> git.sur5r.net Git - openldap/blob - libraries/libldap/options.c
Add descriptive comment at top.
[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 = ldp;
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 != LDAP_API_INFO_VERSION) {
44                                 /* api info version mismatch */
45                                 info->ldapai_info_version = LDAP_API_INFO_VERSION;
46                                 return -1;
47                         }
48
49                         info->ldapai_api_version = LDAP_API_VERSION;
50                         info->ldapai_api_version = LDAP_API_VERSION;
51                         info->ldapai_protocol_version = LDAP_VERSION_MAX;
52                         info->ldapai_extensions = NULL;
53                         info->ldapai_vendor_name = strdup(LDAP_VENDOR_NAME);
54                         info->ldapai_vendor_version = LDAP_VENDOR_VERSION;
55
56                         return 0;
57                 } break;
58
59         case LDAP_OPT_DESC:
60                 if(ldp == NULL) {
61                         /* bad param */
62                         break;
63                 } 
64
65                 * (int *) outvalue = ld->ld_sb.sb_sd;
66                 return 0;
67
68         case LDAP_OPT_DEREF:
69                 * (int *) outvalue = ld->ld_deref;
70                 return 0;
71
72         case LDAP_OPT_SIZELIMIT:
73                 * (int *) outvalue = ld->ld_sizelimit;
74                 return 0;
75
76         case LDAP_OPT_TIMELIMIT:
77                 * (int *) outvalue = ld->ld_timelimit;
78                 return 0;
79
80         case LDAP_OPT_REFERRALS:
81                 * (int *) outvalue = (int) LDAP_BOOL_GET(ld, LDAP_BOOL_REFERRALS);
82                 return 0;
83                 
84         case LDAP_OPT_RESTART:
85                 * (int *) outvalue = (int) LDAP_BOOL_GET(ld, LDAP_BOOL_RESTART);
86                 return 0;
87
88         case LDAP_OPT_DNS:      /* LDAPv2 */
89                 * (int *) outvalue = (int) LDAP_BOOL_GET(ld, LDAP_BOOL_DNS);
90                 return 0;
91
92         case LDAP_OPT_PROTOCOL_VERSION:
93                 * (int *) outvalue = ld->ld_version;
94                 return 0;
95
96         case LDAP_OPT_SERVER_CONTROLS:
97         case LDAP_OPT_CLIENT_CONTROLS:
98                 /* not yet supported */
99                 break;
100
101         case LDAP_OPT_HOST_NAME:
102                 * (char **) outvalue = ld->ld_host;
103                 return 0;
104
105         case LDAP_OPT_ERROR_NUMBER:
106                 * (int *) outvalue = ld->ld_errno;
107                 return 0;
108
109         case LDAP_OPT_ERROR_STRING:
110                 /* not yet supported */
111                 break;
112
113         default:
114                 /* bad param */
115                 break;
116         }
117
118         return -1;
119 }
120
121 int
122 ldap_set_option(
123         LDAP    *ldp,
124         int             option,
125         void    *invalue)
126 {
127         LDAP *ld;
128
129         if(!openldap_ldap_initialized) {
130                 openldap_ldap_initialize();
131         }
132
133         if(invalue == NULL) {
134                 /* no place to set from */
135                 return -1;
136         }
137
138         if(ldp == NULL) {
139                 ld = &openldap_ld_globals;
140         } else {
141                 ld = ldp;
142         }
143
144         switch(option) {
145         case LDAP_OPT_API_INFO:
146         case LDAP_OPT_DESC:
147                 /* READ ONLY */
148                 break;
149
150         case LDAP_OPT_DEREF:
151                 ld->ld_deref = * (int *) invalue;
152                 return 0;
153
154         case LDAP_OPT_SIZELIMIT:
155                 ld->ld_sizelimit = * (int *) invalue;
156                 return 0;
157
158         case LDAP_OPT_TIMELIMIT:
159                 ld->ld_timelimit = * (int *) invalue;
160                 return 0;
161
162         case LDAP_OPT_REFERRALS:
163                 if((int) invalue == (int) LDAP_OPT_ON) {
164                         LDAP_BOOL_SET(ld, LDAP_BOOL_REFERRALS);
165                 } else {
166                         LDAP_BOOL_CLR(ld, LDAP_BOOL_REFERRALS);
167                 }
168                 return 0;
169
170         case LDAP_OPT_RESTART:
171                 if((int) invalue == (int) LDAP_OPT_ON) {
172                         LDAP_BOOL_SET(ld, LDAP_BOOL_RESTART);
173                 } else {
174                         LDAP_BOOL_CLR(ld, LDAP_BOOL_RESTART);
175                 }
176                 return 0;
177
178         case LDAP_OPT_PROTOCOL_VERSION: {
179                         int vers = * (int *) invalue;
180                         if (vers < LDAP_VERSION_MIN || vers > LDAP_VERSION_MAX) {
181                                 /* not supported */
182                                 break;
183                         }
184                         ld->ld_version = vers;
185                 } return 0;
186
187         case LDAP_OPT_SERVER_CONTROLS:
188         case LDAP_OPT_CLIENT_CONTROLS:
189         case LDAP_OPT_HOST_NAME:
190         case LDAP_OPT_ERROR_NUMBER:
191         case LDAP_OPT_ERROR_STRING:
192                 /* not yet supported */
193                 break;
194         default:
195                 /* bad param */
196                 break;
197         }
198         return -1;
199 }