]> git.sur5r.net Git - openldap/blob - libraries/libldap/apitest.c
cd0a02ad0c7c22d1e8fdaa539a2ec39371fdbda9
[openldap] / libraries / libldap / apitest.c
1 /*
2  * OpenLDAP API Test
3  *      Written by: Kurt Zeilenga
4  *
5  * This program is designed to test API features of libldap.
6  *
7  * The API specification can be found in:
8  *
9  *       draft-api-ldapext-ldap-c-api-01.txt 
10  *
11  * and discussions on ietf-ldapext mailing list.
12  *
13  */
14 #include "portable.h"
15
16 #include <stdio.h>
17 #include <stdlib.h>
18
19 #include "lber.h"
20 #include "ldap.h"
21
22 int
23 main(int argc, char **argv)
24 {
25         LDAPAPIInfo api;
26         int ival;
27         char *sval;
28
29 #ifdef LDAP_API_INFO_VERSION
30         api.ldapai_info_version = LDAP_API_INFO_VERSION;
31 #else
32         api.ldapai_info_version = 1;
33 #endif
34
35         printf("Compile time API Information\n");
36         printf("  API Info version:  %d\n", api.ldapai_info_version);
37         printf("  API version:       %d\n", LDAP_API_VERSION);
38 #ifdef LDAP_VERSION
39         printf("  Protocol Version:  %d\n", LDAP_VERSION);
40 #else
41         printf("  Protocol Version:  unknown\n");
42 #endif
43 #ifdef LDAP_VERSION_MIN
44         printf("  Protocol Min:      %d\n", LDAP_VERSION_MIN);
45 #else
46         printf("  Protocol Min:      unknown\n");
47 #endif
48 #ifdef LDAP_VERSION_MAX
49         printf("  Protocol Max:      %d\n", LDAP_VERSION_MAX);
50 #else
51         printf("  Protocol Max:      unknown\n");
52 #endif
53 #ifdef LDAP_VENDOR_NAME
54         printf("  Vendor Name:       %s\n", LDAP_VENDOR_NAME);
55 #else
56         printf("  Vendor Name:       unknown\n");
57 #endif
58 #ifdef LDAP_VENDOR_VERSION
59         printf("  Vendor Version:    %d\n", LDAP_VENDOR_VERSION);
60 #else
61         printf("  Vendor Version:    unknown\n");
62 #endif
63
64         if(ldap_get_option(NULL, LDAP_OPT_API_INFO, &api) != LDAP_SUCCESS) {
65                 fprintf(stderr, "%s: ldap_get_option(api) failed\n", argv[0]);
66                 exit(-1);
67         }
68
69         printf("\nExecution time API Information\n");
70         printf("  API Info version:  %d\n", api.ldapai_info_version);
71
72         if (api.ldapai_info_version != LDAP_API_INFO_VERSION) {
73                 printf(" API INFO version mismatch!\n");
74                 exit(-1);
75         }
76
77         printf("  API Version:       %d\n", api.ldapai_api_version);
78         printf("  Protocol Max:      %d\n", api.ldapai_protocol_version);
79
80         if(api.ldapai_extensions == NULL) {
81                 printf("  Extensions:        none\n");
82
83         } else {
84                 int i;
85                 for(i=0; api.ldapai_extensions[i] != NULL; i++) /* empty */;
86                 printf("  Extensions:        %d\n", i);
87                 for(i=0; api.ldapai_extensions[i] != NULL; i++) {
88 #ifndef LDAP_API_FEATURE_INFO
89                         printf("                     %s\n",
90                                 api.ldapai_extensions[i]);
91 #else
92                         LDAPAPIFeatureInfo fi;
93                         fi.ldapaif_name = api.ldapai_extensions[i];
94                         fi.ldapaif_version = 0;
95
96                         ldap_get_option(NULL, LDAP_OPT_API_FEATURE_INFO, &fi);
97
98                         printf("                     %s (%d)\n",
99                                 api.ldapai_extensions[i], fi.ldapaif_version);
100 #endif
101                 }
102         }
103
104         printf("  Vendor Name:       %s\n", api.ldapai_vendor_name);
105         printf("  Vendor Version:    %d\n", api.ldapai_vendor_version);
106
107         printf("\nExecution time Default Options\n");
108
109         if(ldap_get_option(NULL, LDAP_OPT_DEREF, &ival) != LDAP_SUCCESS) {
110                 fprintf(stderr, "%s: ldap_get_option(api) failed\n", argv[0]);
111                 exit(-1);
112         }
113         printf("  DEREF:             %d\n", ival);
114
115         if(ldap_get_option(NULL, LDAP_OPT_SIZELIMIT, &ival) != LDAP_SUCCESS) {
116                 fprintf(stderr, "%s: ldap_get_option(sizelimit) failed\n", argv[0]);
117                 exit(-1);
118         }
119         printf("  SIZELIMIT:         %d\n", ival);
120
121         if(ldap_get_option(NULL, LDAP_OPT_TIMELIMIT, &ival) != LDAP_SUCCESS) {
122                 fprintf(stderr, "%s: ldap_get_option(timelimit) failed\n", argv[0]);
123                 exit(-1);
124         }
125         printf("  TIMELIMIT:         %d\n", ival);
126
127         if(ldap_get_option(NULL, LDAP_OPT_REFERRALS, &ival) != LDAP_SUCCESS) {
128                 fprintf(stderr, "%s: ldap_get_option(referrals) failed\n", argv[0]);
129                 exit(-1);
130         }
131         printf("  REFERRALS:         %s\n",
132                 ival == (int) LDAP_OPT_ON ? "on" : "off");
133
134         if(ldap_get_option(NULL, LDAP_OPT_RESTART, &ival) != LDAP_SUCCESS) {
135                 fprintf(stderr, "%s: ldap_get_option(restart) failed\n", argv[0]);
136                 exit(-1);
137         }
138         printf("  RESTART:           %s\n",
139                 ival == (int) LDAP_OPT_ON ? "on" : "off");
140
141         if(ldap_get_option(NULL, LDAP_OPT_PROTOCOL_VERSION, &ival) != LDAP_SUCCESS) {
142                 fprintf(stderr, "%s: ldap_get_option(protocol version) failed\n", argv[0]);
143                 exit(-1);
144         }
145         printf("  PROTOCOL VERSION:  %d\n", ival);
146
147         if(ldap_get_option(NULL, LDAP_OPT_HOST_NAME, &sval) != LDAP_SUCCESS) {
148                 fprintf(stderr, "%s: ldap_get_option(host name) failed\n", argv[0]);
149                 exit(-1);
150         }
151         printf("  HOST NAME:         %s\n", sval);
152
153         exit(0);
154         return 0;
155 }