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.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
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>.
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
29 #include <ac/stdlib.h>
30 #include <ac/string.h>
31 #include <ac/unistd.h>
37 #include "ldap_defaults.h"
40 main(int argc
, char *argv
[])
53 fprintf( stderr
, "usage: urltest <url>\n" );
59 if ( ldap_is_ldaps_url( url
) ) {
60 fprintf( stdout
, "LDAPS url\n" );
63 } else if ( ldap_is_ldapi_url( url
) ) {
64 fprintf( stdout
, "LDAPI url\n" );
67 } else if ( ldap_is_ldap_url( url
) ) {
68 fprintf( stdout
, "generic LDAP url\n" );
71 fprintf( stderr
, "Need a valid LDAP url\n" );
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
);
81 fprintf( stdout
, "PROTO: %s\n", lud
->lud_scheme
);
84 fprintf( stdout
, "PATH: %s\n", lud
->lud_host
);
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
) {
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
);
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
) {
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
));