1 /* LIBLDAP url.c -- LDAP URL (RFC 2255) related routines */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2004 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>.
16 /* Portions Copyright (c) 1996 Regents of the University of Michigan.
17 * All rights reserved.
22 * LDAP URLs look like this:
23 * ldap[is]://host:port[/[dn[?[attributes][?[scope][?[filter][?exts]]]]]]
26 * attributes is a comma separated list
27 * scope is one of these three strings: base one sub (default=base)
28 * filter is an string-represented filter as in RFC 2254
30 * e.g., ldap://host:port/dc=com?o,cn?base?(o=openldap)?extension
32 * We also tolerate URLs that look like: <ldapurl> and <URL:ldapurl>
39 #include <ac/stdlib.h>
41 #include <ac/socket.h>
42 #include <ac/string.h>
48 static const char* skip_url_prefix LDAP_P((
51 const char **scheme ));
53 int ldap_pvt_url_scheme2proto( const char *scheme )
57 if( scheme == NULL ) {
61 if( strcmp("ldap", scheme) == 0 ) {
62 return LDAP_PROTO_TCP;
65 if( strcmp("ldapi", scheme) == 0 ) {
66 return LDAP_PROTO_IPC;
69 if( strcmp("ldaps", scheme) == 0 ) {
70 return LDAP_PROTO_TCP;
72 #ifdef LDAP_CONNECTIONLESS
73 if( strcmp("cldap", scheme) == 0 ) {
74 return LDAP_PROTO_UDP;
82 ldap_pvt_url_scheme2tls( const char *scheme )
86 if( scheme == NULL ) {
90 return strcmp("ldaps", scheme) == 0;
94 ldap_is_ldap_url( LDAP_CONST char *url )
103 if( skip_url_prefix( url, &enclosed, &scheme ) == NULL ) {
111 ldap_is_ldaps_url( LDAP_CONST char *url )
120 if( skip_url_prefix( url, &enclosed, &scheme ) == NULL ) {
124 return strcmp(scheme, "ldaps") == 0;
128 ldap_is_ldapi_url( LDAP_CONST char *url )
137 if( skip_url_prefix( url, &enclosed, &scheme ) == NULL ) {
141 return strcmp(scheme, "ldapi") == 0;
144 #ifdef LDAP_CONNECTIONLESS
146 ldap_is_ldapc_url( LDAP_CONST char *url )
155 if( skip_url_prefix( url, &enclosed, &scheme ) == NULL ) {
159 return strcmp(scheme, "cldap") == 0;
167 const char **scheme )
170 * return non-zero if this looks like a LDAP URL; zero if not
171 * if non-zero returned, *urlp will be moved past "ldap://" part of URL
181 /* skip leading '<' (if any) */
189 /* skip leading "URL:" (if any) */
190 if ( strncasecmp( p, LDAP_URL_URLCOLON, LDAP_URL_URLCOLON_LEN ) == 0 ) {
191 p += LDAP_URL_URLCOLON_LEN;
194 /* check for "ldap://" prefix */
195 if ( strncasecmp( p, LDAP_URL_PREFIX, LDAP_URL_PREFIX_LEN ) == 0 ) {
196 /* skip over "ldap://" prefix and return success */
197 p += LDAP_URL_PREFIX_LEN;
202 /* check for "ldaps://" prefix */
203 if ( strncasecmp( p, LDAPS_URL_PREFIX, LDAPS_URL_PREFIX_LEN ) == 0 ) {
204 /* skip over "ldaps://" prefix and return success */
205 p += LDAPS_URL_PREFIX_LEN;
210 /* check for "ldapi://" prefix */
211 if ( strncasecmp( p, LDAPI_URL_PREFIX, LDAPI_URL_PREFIX_LEN ) == 0 ) {
212 /* skip over "ldapi://" prefix and return success */
213 p += LDAPI_URL_PREFIX_LEN;
218 #ifdef LDAP_CONNECTIONLESS
219 /* check for "cldap://" prefix */
220 if ( strncasecmp( p, LDAPC_URL_PREFIX, LDAPC_URL_PREFIX_LEN ) == 0 ) {
221 /* skip over "cldap://" prefix and return success */
222 p += LDAPC_URL_PREFIX_LEN;
232 static int str2scope( const char *p )
234 if ( strcasecmp( p, "one" ) == 0 ) {
235 return LDAP_SCOPE_ONELEVEL;
237 } else if ( strcasecmp( p, "onelevel" ) == 0 ) {
238 return LDAP_SCOPE_ONELEVEL;
240 } else if ( strcasecmp( p, "base" ) == 0 ) {
241 return LDAP_SCOPE_BASE;
243 } else if ( strcasecmp( p, "sub" ) == 0 ) {
244 return LDAP_SCOPE_SUBTREE;
246 } else if ( strcasecmp( p, "subtree" ) == 0 ) {
247 return LDAP_SCOPE_SUBTREE;
249 #ifdef LDAP_SCOPE_SUBORDINATE
250 } else if ( strcasecmp( p, "subordinate" ) == 0 ) {
251 return LDAP_SCOPE_SUBORDINATE;
253 } else if ( strcasecmp( p, "children" ) == 0 ) {
254 return LDAP_SCOPE_SUBORDINATE;
261 static int hex_escape( char *buf, const char *s, int list )
265 static const char hex[] = "0123456789ABCDEF";
267 if( s == NULL ) return 0;
269 for( pos=0,i=0; s[i]; i++ ) {
295 escape = s[i] < 0x20 || 0x1f >= s[i];
300 buf[pos++] = hex[ (s[i] >> 4) & 0x0f ];
301 buf[pos++] = hex[ s[i] & 0x0f ];
311 static int hex_escape_args( char *buf, char **s )
316 if( s == NULL ) return 0;
319 for( i=0; s[i] != NULL; i++ ) {
323 pos += hex_escape( &buf[pos], s[i], 1 );
329 char * ldap_url_desc2str( LDAPURLDesc *u )
336 if( u == NULL ) return NULL;
339 for( i=0; u->lud_exts[i]; i++ ) {
340 len += strlen( u->lud_exts[i] ) + 1;
345 if( u->lud_filter ) {
346 len += strlen( u->lud_filter );
349 if ( len ) len++; /* ? */
351 switch( u->lud_scope ) {
352 case LDAP_SCOPE_BASE:
353 case LDAP_SCOPE_ONELEVEL:
354 case LDAP_SCOPE_SUBTREE:
355 #ifdef LDAP_FEATURE_SUBORDINATE_SCOPE
356 case LDAP_SCOPE_SUBORDINATE:
358 len += sizeof("subordinate");
363 if ( len ) len++; /* ? */
367 for( i=0; u->lud_attrs[i]; i++ ) {
368 len += strlen( u->lud_attrs[i] ) + 1;
371 } else if ( len ) len++; /* ? */
374 len += strlen( u->lud_dn ) + 1;
379 len += sizeof(":65535") - 1;
383 len+=strlen( u->lud_host );
386 len += strlen( u->lud_scheme ) + sizeof("://");
388 /* allocate enough to hex escape everything -- overkill */
389 s = LDAP_MALLOC( 3*len );
391 if( s == NULL ) return NULL;
394 sprintf( s, "%s://%s:%d%n", u->lud_scheme,
395 u->lud_host, u->lud_port, &sofar );
397 sprintf( s, "%s://%s%n", u->lud_scheme,
398 u->lud_host, &sofar );
401 if( sep < 1 ) goto done;
404 sofar += hex_escape( &s[sofar], u->lud_dn, 0 );
406 if( sep < 2 ) goto done;
409 sofar += hex_escape_args( &s[sofar], u->lud_attrs );
411 if( sep < 3 ) goto done;
414 switch( u->lud_scope ) {
415 case LDAP_SCOPE_BASE:
416 strcpy( &s[sofar], "base" );
417 sofar += sizeof("base") - 1;
419 case LDAP_SCOPE_ONELEVEL:
420 strcpy( &s[sofar], "one" );
421 sofar += sizeof("one") - 1;
423 case LDAP_SCOPE_SUBTREE:
424 strcpy( &s[sofar], "sub" );
425 sofar += sizeof("sub") - 1;
427 #ifdef LDAP_FEATURE_SUBORDINATE_SCOPE
428 case LDAP_SCOPE_SUBORDINATE:
429 strcpy( &s[sofar], "children" );
430 sofar += sizeof("children") - 1;
435 if( sep < 4 ) goto done;
438 sofar += hex_escape( &s[sofar], u->lud_filter, 0 );
440 if( sep < 5 ) goto done;
443 sofar += hex_escape_args( &s[sofar], u->lud_exts );
451 ldap_url_parse_ext( LDAP_CONST char *url_in, LDAPURLDesc **ludpp )
454 * Pick apart the pieces of an LDAP URL.
460 const char *scheme = NULL;
464 if( url_in == NULL || ludpp == NULL ) {
465 return LDAP_URL_ERR_PARAM;
468 #ifndef LDAP_INT_IN_KERNEL
469 /* Global options may not be created yet
470 * We can't test if the global options are initialized
471 * because a call to LDAP_INT_GLOBAL_OPT() will try to allocate
472 * the options and cause infinite recursion
475 LDAP_LOG ( OPERATION, ENTRY, "ldap_url_parse_ext(%s)\n", url_in, 0, 0 );
477 Debug( LDAP_DEBUG_TRACE, "ldap_url_parse_ext(%s)\n", url_in, 0, 0 );
481 *ludpp = NULL; /* pessimistic */
483 url_tmp = skip_url_prefix( url_in, &enclosed, &scheme );
485 if ( url_tmp == NULL ) {
486 return LDAP_URL_ERR_BADSCHEME;
491 /* make working copy of the remainder of the URL */
492 url = LDAP_STRDUP( url_tmp );
494 return LDAP_URL_ERR_MEM;
498 p = &url[strlen(url)-1];
502 return LDAP_URL_ERR_BADENCLOSURE;
508 /* allocate return struct */
509 ludp = (LDAPURLDesc *)LDAP_CALLOC( 1, sizeof( LDAPURLDesc ));
511 if ( ludp == NULL ) {
513 return LDAP_URL_ERR_MEM;
516 ludp->lud_next = NULL;
517 ludp->lud_host = NULL;
520 ludp->lud_attrs = NULL;
521 ludp->lud_scope = LDAP_SCOPE_DEFAULT;
522 ludp->lud_filter = NULL;
523 ludp->lud_exts = NULL;
525 ludp->lud_scheme = LDAP_STRDUP( scheme );
527 if ( ludp->lud_scheme == NULL ) {
529 ldap_free_urldesc( ludp );
530 return LDAP_URL_ERR_MEM;
533 /* scan forward for '/' that marks end of hostport and begin. of dn */
534 p = strchr( url, '/' );
537 /* terminate hostport; point to start of dn */
541 /* IPv6 syntax with [ip address]:port */
543 r = strchr( url, ']' );
546 ldap_free_urldesc( ludp );
547 return LDAP_URL_ERR_BADURL;
550 q = strchr( r, ':' );
552 q = strchr( url, ':' );
559 ldap_pvt_hex_unescape( q );
563 ldap_free_urldesc( ludp );
564 return LDAP_URL_ERR_BADURL;
567 ludp->lud_port = strtol( q, &next, 10 );
568 if ( next == NULL || next[0] != '\0' ) {
570 ldap_free_urldesc( ludp );
571 return LDAP_URL_ERR_BADURL;
575 ldap_pvt_hex_unescape( url );
577 /* If [ip address]:port syntax, url is [ip and we skip the [ */
578 ludp->lud_host = LDAP_STRDUP( url + ( *url == '[' ) );
580 if( ludp->lud_host == NULL ) {
582 ldap_free_urldesc( ludp );
583 return LDAP_URL_ERR_MEM;
587 * Kludge. ldap://111.222.333.444:389??cn=abc,o=company
589 * On early Novell releases, search references/referrals were returned
590 * in this format, i.e., the dn was kind of in the scope position,
591 * but the required slash is missing. The whole thing is illegal syntax,
592 * but we need to account for it. Fortunately it can't be confused with
595 if( (p == NULL) && (q != NULL) && ((q = strchr( q, '?')) != NULL)) {
597 /* ? immediately followed by question */
602 ldap_pvt_hex_unescape( q );
603 ludp->lud_dn = LDAP_STRDUP( q );
605 ludp->lud_dn = LDAP_STRDUP( "" );
608 if( ludp->lud_dn == NULL ) {
610 ldap_free_urldesc( ludp );
611 return LDAP_URL_ERR_MEM;
619 return LDAP_URL_SUCCESS;
622 /* scan forward for '?' that may marks end of dn */
623 q = strchr( p, '?' );
626 /* terminate dn part */
632 ldap_pvt_hex_unescape( p );
633 ludp->lud_dn = LDAP_STRDUP( p );
635 ludp->lud_dn = LDAP_STRDUP( "" );
638 if( ludp->lud_dn == NULL ) {
640 ldap_free_urldesc( ludp );
641 return LDAP_URL_ERR_MEM;
648 return LDAP_URL_SUCCESS;
651 /* scan forward for '?' that may marks end of attributes */
653 q = strchr( p, '?' );
656 /* terminate attributes part */
661 /* parse attributes */
662 ldap_pvt_hex_unescape( p );
663 ludp->lud_attrs = ldap_str2charray( p, "," );
665 if( ludp->lud_attrs == NULL ) {
667 ldap_free_urldesc( ludp );
668 return LDAP_URL_ERR_BADATTRS;
676 return LDAP_URL_SUCCESS;
679 /* scan forward for '?' that may marks end of scope */
681 q = strchr( p, '?' );
684 /* terminate the scope part */
689 /* parse the scope */
690 ldap_pvt_hex_unescape( p );
691 ludp->lud_scope = str2scope( p );
693 if( ludp->lud_scope == -1 ) {
695 ldap_free_urldesc( ludp );
696 return LDAP_URL_ERR_BADSCOPE;
704 return LDAP_URL_SUCCESS;
707 /* scan forward for '?' that may marks end of filter */
709 q = strchr( p, '?' );
712 /* terminate the filter part */
717 /* parse the filter */
718 ldap_pvt_hex_unescape( p );
723 ldap_free_urldesc( ludp );
724 return LDAP_URL_ERR_BADFILTER;
727 ludp->lud_filter = LDAP_STRDUP( p );
729 if( ludp->lud_filter == NULL ) {
731 ldap_free_urldesc( ludp );
732 return LDAP_URL_ERR_MEM;
740 return LDAP_URL_SUCCESS;
743 /* scan forward for '?' that may marks end of extensions */
745 q = strchr( p, '?' );
750 ldap_free_urldesc( ludp );
751 return LDAP_URL_ERR_BADURL;
754 /* parse the extensions */
755 ludp->lud_exts = ldap_str2charray( p, "," );
757 if( ludp->lud_exts == NULL ) {
759 ldap_free_urldesc( ludp );
760 return LDAP_URL_ERR_BADEXTS;
763 for( i=0; ludp->lud_exts[i] != NULL; i++ ) {
764 ldap_pvt_hex_unescape( ludp->lud_exts[i] );
766 if( *ludp->lud_exts[i] == '!' ) {
767 /* count the number of critical extensions */
768 ludp->lud_crit_exts++;
773 /* must have 1 or more */
775 ldap_free_urldesc( ludp );
776 return LDAP_URL_ERR_BADEXTS;
782 return LDAP_URL_SUCCESS;
786 ldap_url_parse( LDAP_CONST char *url_in, LDAPURLDesc **ludpp )
788 int rc = ldap_url_parse_ext( url_in, ludpp );
790 if( rc != LDAP_URL_SUCCESS ) {
794 if ((*ludpp)->lud_scope == LDAP_SCOPE_DEFAULT) {
795 (*ludpp)->lud_scope = LDAP_SCOPE_BASE;
798 if ((*ludpp)->lud_host != NULL && *(*ludpp)->lud_host == '\0') {
799 LDAP_FREE( (*ludpp)->lud_host );
800 (*ludpp)->lud_host = NULL;
803 if ((*ludpp)->lud_port == 0) {
804 if( strcmp((*ludpp)->lud_scheme, "ldap") == 0 ) {
805 (*ludpp)->lud_port = LDAP_PORT;
806 #ifdef LDAP_CONNECTIONLESS
807 } else if( strcmp((*ludpp)->lud_scheme, "cldap") == 0 ) {
808 (*ludpp)->lud_port = LDAP_PORT;
810 } else if( strcmp((*ludpp)->lud_scheme, "ldaps") == 0 ) {
811 (*ludpp)->lud_port = LDAPS_PORT;
819 ldap_url_dup ( LDAPURLDesc *ludp )
823 if ( ludp == NULL ) {
827 dest = LDAP_MALLOC( sizeof(LDAPURLDesc) );
832 dest->lud_scheme = NULL;
833 dest->lud_host = NULL;
835 dest->lud_filter = NULL;
836 dest->lud_attrs = NULL;
837 dest->lud_exts = NULL;
838 dest->lud_next = NULL;
840 if ( ludp->lud_scheme != NULL ) {
841 dest->lud_scheme = LDAP_STRDUP( ludp->lud_scheme );
842 if (dest->lud_scheme == NULL) {
843 ldap_free_urldesc(dest);
848 if ( ludp->lud_host != NULL ) {
849 dest->lud_host = LDAP_STRDUP( ludp->lud_host );
850 if (dest->lud_host == NULL) {
851 ldap_free_urldesc(dest);
856 if ( ludp->lud_dn != NULL ) {
857 dest->lud_dn = LDAP_STRDUP( ludp->lud_dn );
858 if (dest->lud_dn == NULL) {
859 ldap_free_urldesc(dest);
864 if ( ludp->lud_filter != NULL ) {
865 dest->lud_filter = LDAP_STRDUP( ludp->lud_filter );
866 if (dest->lud_filter == NULL) {
867 ldap_free_urldesc(dest);
872 if ( ludp->lud_attrs != NULL ) {
873 dest->lud_attrs = ldap_charray_dup( ludp->lud_attrs );
874 if (dest->lud_attrs == NULL) {
875 ldap_free_urldesc(dest);
880 if ( ludp->lud_exts != NULL ) {
881 dest->lud_exts = ldap_charray_dup( ludp->lud_exts );
882 if (dest->lud_exts == NULL) {
883 ldap_free_urldesc(dest);
892 ldap_url_duplist (LDAPURLDesc *ludlist)
894 LDAPURLDesc *dest, *tail, *ludp, *newludp;
898 for (ludp = ludlist; ludp != NULL; ludp = ludp->lud_next) {
899 newludp = ldap_url_dup(ludp);
900 if (newludp == NULL) {
901 ldap_free_urllist(dest);
907 tail->lud_next = newludp;
914 ldap_url_parselist (LDAPURLDesc **ludlist, const char *url )
916 return ldap_url_parselist_ext( ludlist, url, ", " );
920 ldap_url_parselist_ext (LDAPURLDesc **ludlist, const char *url, const char *sep )
926 assert( ludlist != NULL );
927 assert( url != NULL );
931 urls = ldap_str2charray(url, sep);
933 return LDAP_NO_MEMORY;
935 /* count the URLs... */
936 for (i = 0; urls[i] != NULL; i++) ;
937 /* ...and put them in the "stack" backward */
939 rc = ldap_url_parse( urls[i], &ludp );
941 ldap_charray_free(urls);
942 ldap_free_urllist(*ludlist);
946 ludp->lud_next = *ludlist;
949 ldap_charray_free(urls);
955 LDAPURLDesc **ludlist,
963 assert( ludlist != NULL );
964 assert( hosts != NULL );
968 specs = ldap_str2charray(hosts, ", ");
970 return LDAP_NO_MEMORY;
972 /* count the URLs... */
973 for (i = 0; specs[i] != NULL; i++) /* EMPTY */;
975 /* ...and put them in the "stack" backward */
977 ludp = LDAP_CALLOC( 1, sizeof(LDAPURLDesc) );
979 ldap_charray_free(specs);
980 ldap_free_urllist(*ludlist);
982 return LDAP_NO_MEMORY;
984 ludp->lud_port = port;
985 ludp->lud_host = specs[i];
987 p = strchr(ludp->lud_host, ':');
989 /* more than one :, IPv6 address */
990 if ( strchr(p+1, ':') != NULL ) {
991 /* allow [address] and [address]:port */
992 if ( *ludp->lud_host == '[' ) {
993 p = LDAP_STRDUP(ludp->lud_host+1);
994 /* copied, make sure we free source later */
995 specs[i] = ludp->lud_host;
997 p = strchr( ludp->lud_host, ']' );
999 return LDAP_PARAM_ERROR;
1003 return LDAP_PARAM_ERROR;
1014 ldap_pvt_hex_unescape(p);
1015 ludp->lud_port = strtol( p, &next, 10 );
1016 if ( next == NULL || next[0] != '\0' ) {
1017 return LDAP_PARAM_ERROR;
1021 ldap_pvt_hex_unescape(ludp->lud_host);
1022 ludp->lud_scheme = LDAP_STRDUP("ldap");
1023 ludp->lud_next = *ludlist;
1027 /* this should be an array of NULLs now */
1028 /* except entries starting with [ */
1029 ldap_charray_free(specs);
1030 return LDAP_SUCCESS;
1034 ldap_url_list2hosts (LDAPURLDesc *ludlist)
1038 char *s, *p, buf[32]; /* big enough to hold a long decimal # (overkill) */
1040 if (ludlist == NULL)
1043 /* figure out how big the string is */
1044 size = 1; /* nul-term */
1045 for (ludp = ludlist; ludp != NULL; ludp = ludp->lud_next) {
1046 size += strlen(ludp->lud_host) + 1; /* host and space */
1047 if (strchr(ludp->lud_host, ':')) /* will add [ ] below */
1049 if (ludp->lud_port != 0)
1050 size += sprintf(buf, ":%d", ludp->lud_port);
1052 s = LDAP_MALLOC(size);
1057 for (ludp = ludlist; ludp != NULL; ludp = ludp->lud_next) {
1058 if (strchr(ludp->lud_host, ':')) {
1059 p += sprintf(p, "[%s]", ludp->lud_host);
1061 strcpy(p, ludp->lud_host);
1062 p += strlen(ludp->lud_host);
1064 if (ludp->lud_port != 0)
1065 p += sprintf(p, ":%d", ludp->lud_port);
1069 p--; /* nuke that extra space */
1076 LDAPURLDesc *ludlist )
1080 char *s, *p, buf[32]; /* big enough to hold a long decimal # (overkill) */
1082 if (ludlist == NULL)
1085 /* figure out how big the string is */
1086 size = 1; /* nul-term */
1087 for (ludp = ludlist; ludp != NULL; ludp = ludp->lud_next) {
1088 size += strlen(ludp->lud_scheme);
1089 if ( ludp->lud_host ) {
1090 size += strlen(ludp->lud_host);
1091 /* will add [ ] below */
1092 if (strchr(ludp->lud_host, ':'))
1095 size += sizeof(":/// ");
1097 if (ludp->lud_port != 0) {
1098 size += sprintf(buf, ":%d", ludp->lud_port);
1102 s = LDAP_MALLOC(size);
1108 for (ludp = ludlist; ludp != NULL; ludp = ludp->lud_next) {
1109 p += sprintf(p, "%s://", ludp->lud_scheme);
1110 if ( ludp->lud_host ) {
1111 p += sprintf(p, strchr(ludp->lud_host, ':')
1112 ? "[%s]" : "%s", ludp->lud_host);
1114 if (ludp->lud_port != 0)
1115 p += sprintf(p, ":%d", ludp->lud_port);
1120 p--; /* nuke that extra space */
1126 ldap_free_urllist( LDAPURLDesc *ludlist )
1128 LDAPURLDesc *ludp, *next;
1130 for (ludp = ludlist; ludp != NULL; ludp = next) {
1131 next = ludp->lud_next;
1132 ldap_free_urldesc(ludp);
1137 ldap_free_urldesc( LDAPURLDesc *ludp )
1139 if ( ludp == NULL ) {
1143 if ( ludp->lud_scheme != NULL ) {
1144 LDAP_FREE( ludp->lud_scheme );
1147 if ( ludp->lud_host != NULL ) {
1148 LDAP_FREE( ludp->lud_host );
1151 if ( ludp->lud_dn != NULL ) {
1152 LDAP_FREE( ludp->lud_dn );
1155 if ( ludp->lud_filter != NULL ) {
1156 LDAP_FREE( ludp->lud_filter);
1159 if ( ludp->lud_attrs != NULL ) {
1160 LDAP_VFREE( ludp->lud_attrs );
1163 if ( ludp->lud_exts != NULL ) {
1164 LDAP_VFREE( ludp->lud_exts );
1171 ldap_int_unhex( int c )
1173 return( c >= '0' && c <= '9' ? c - '0'
1174 : c >= 'A' && c <= 'F' ? c - 'A' + 10
1179 ldap_pvt_hex_unescape( char *s )
1182 * Remove URL hex escapes from s... done in place. The basic concept for
1183 * this routine is borrowed from the WWW library HTUnEscape() routine.
1187 for ( p = s; *s != '\0'; ++s ) {
1189 if ( *++s == '\0' ) {
1192 *p = ldap_int_unhex( *s ) << 4;
1193 if ( *++s == '\0' ) {
1196 *p++ += ldap_int_unhex( *s );