No empty .Rs/.Re
[netbsd-mini2440.git] / external / bsd / openldap / dist / libraries / libldap / urltest.c
blob82f319e131e4dccfab9ce1276e3193d643f35900
1 /* urltest.c -- OpenLDAP URL API Test Program */
2 /* $OpenLDAP: pkg/ldap/libraries/libldap/urltest.c,v 1.1.2.4 2008/02/11 23:26:41 kurt Exp $ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2008 The OpenLDAP Foundation.
6 * All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
10 * Public License.
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
16 /* ACKNOWLEDGEMENT:
17 * This program was initially developed by Pierangelo Masarati
18 * <ando@OpenLDAP.org> for inclusion in OpenLDAP Software.
22 * This program is designed to test the ldap_url_* functions
25 #include "portable.h"
27 #include <stdio.h>
29 #include <ac/stdlib.h>
30 #include <ac/string.h>
31 #include <ac/unistd.h>
33 #include <ldap.h>
35 #include "ldap-int.h"
37 #include "ldap_defaults.h"
39 int
40 main(int argc, char *argv[])
42 const char *url,
43 *scope = NULL;
44 LDAPURLDesc *lud;
45 enum {
46 IS_LDAP = 0,
47 IS_LDAPS,
48 IS_LDAPI
49 } type = IS_LDAP;
50 int rc;
52 if ( argc != 2 ) {
53 fprintf( stderr, "usage: urltest <url>\n" );
54 exit( EXIT_FAILURE );
57 url = argv[ 1 ];
59 if ( ldap_is_ldaps_url( url ) ) {
60 fprintf( stdout, "LDAPS url\n" );
61 type = IS_LDAPS;
63 } else if ( ldap_is_ldapi_url( url ) ) {
64 fprintf( stdout, "LDAPI url\n" );
65 type = IS_LDAPI;
67 } else if ( ldap_is_ldap_url( url ) ) {
68 fprintf( stdout, "generic LDAP url\n" );
70 } else {
71 fprintf( stderr, "Need a valid LDAP url\n" );
72 exit( EXIT_FAILURE );
75 rc = ldap_url_parse( url, &lud );
76 if ( rc != LDAP_URL_SUCCESS ) {
77 fprintf( stderr, "ldap_url_parse(%s) failed (%d)\n", url, rc );
78 exit( EXIT_FAILURE );
81 fprintf( stdout, "PROTO: %s\n", lud->lud_scheme );
82 switch ( type ) {
83 case IS_LDAPI:
84 fprintf( stdout, "PATH: %s\n", lud->lud_host );
85 break;
87 default:
88 fprintf( stdout, "HOST: %s\n", lud->lud_host );
89 if ( lud->lud_port != 0 ) {
90 fprintf( stdout, "PORT: %d\n", lud->lud_port );
94 if ( lud->lud_dn && lud->lud_dn[ 0 ] ) {
95 fprintf( stdout, "DN: %s\n", lud->lud_dn );
98 if ( lud->lud_attrs ) {
99 int i;
101 fprintf( stdout, "ATTRS:\n" );
102 for ( i = 0; lud->lud_attrs[ i ]; i++ ) {
103 fprintf( stdout, "\t%s\n", lud->lud_attrs[ i ] );
107 scope = ldap_pvt_scope2str( lud->lud_scope );
108 if ( scope ) {
109 fprintf( stdout, "SCOPE: %s\n", scope );
112 if ( lud->lud_filter ) {
113 fprintf( stdout, "FILTER: %s\n", lud->lud_filter );
116 if ( lud->lud_exts ) {
117 int i;
119 fprintf( stdout, "EXTS:\n" );
120 for ( i = 0; lud->lud_exts[ i ]; i++ ) {
121 fprintf( stdout, "\t%s\n", lud->lud_exts[ i ] );
125 fprintf( stdout, "URL: %s\n", ldap_url_desc2str( lud ));
127 return EXIT_SUCCESS;