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