xref: /onnv-gate/usr/src/lib/libldap5/sources/ldap/common/unescape.c (revision 0:68f95e015346)
1*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
2*0Sstevel@tonic-gate 
3*0Sstevel@tonic-gate /*
4*0Sstevel@tonic-gate  * The contents of this file are subject to the Netscape Public
5*0Sstevel@tonic-gate  * License Version 1.1 (the "License"); you may not use this file
6*0Sstevel@tonic-gate  * except in compliance with the License. You may obtain a copy of
7*0Sstevel@tonic-gate  * the License at http://www.mozilla.org/NPL/
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * Software distributed under the License is distributed on an "AS
10*0Sstevel@tonic-gate  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
11*0Sstevel@tonic-gate  * implied. See the License for the specific language governing
12*0Sstevel@tonic-gate  * rights and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * The Original Code is Mozilla Communicator client code, released
15*0Sstevel@tonic-gate  * March 31, 1998.
16*0Sstevel@tonic-gate  *
17*0Sstevel@tonic-gate  * The Initial Developer of the Original Code is Netscape
18*0Sstevel@tonic-gate  * Communications Corporation. Portions created by Netscape are
19*0Sstevel@tonic-gate  * Copyright (C) 1998-1999 Netscape Communications Corporation. All
20*0Sstevel@tonic-gate  * Rights Reserved.
21*0Sstevel@tonic-gate  *
22*0Sstevel@tonic-gate  * Contributor(s):
23*0Sstevel@tonic-gate  */
24*0Sstevel@tonic-gate 
25*0Sstevel@tonic-gate /*
26*0Sstevel@tonic-gate  *  LIBLDAP unescape.c -- LDAP URL un-escape routines
27*0Sstevel@tonic-gate  *  We also tolerate URLs that look like: <ldapurl> and <URL:ldapurl>
28*0Sstevel@tonic-gate  */
29*0Sstevel@tonic-gate 
30*0Sstevel@tonic-gate #include "ldap-int.h"
31*0Sstevel@tonic-gate 
32*0Sstevel@tonic-gate 
33*0Sstevel@tonic-gate static int unhex( char c );
34*0Sstevel@tonic-gate 
35*0Sstevel@tonic-gate 
36*0Sstevel@tonic-gate void
nsldapi_hex_unescape(char * s)37*0Sstevel@tonic-gate nsldapi_hex_unescape( char *s )
38*0Sstevel@tonic-gate {
39*0Sstevel@tonic-gate /*
40*0Sstevel@tonic-gate  * Remove URL hex escapes from s... done in place.  The basic concept for
41*0Sstevel@tonic-gate  * this routine is borrowed from the WWW library HTUnEscape() routine.
42*0Sstevel@tonic-gate  */
43*0Sstevel@tonic-gate 	char	*p;
44*0Sstevel@tonic-gate 
45*0Sstevel@tonic-gate 	for ( p = s; *s != '\0'; ++s ) {
46*0Sstevel@tonic-gate 		if ( *s == '%' ) {
47*0Sstevel@tonic-gate 			if ( *++s != '\0' ) {
48*0Sstevel@tonic-gate 				*p = unhex( *s ) << 4;
49*0Sstevel@tonic-gate 			}
50*0Sstevel@tonic-gate 			if ( *++s != '\0' ) {
51*0Sstevel@tonic-gate 				*p++ += unhex( *s );
52*0Sstevel@tonic-gate 			}
53*0Sstevel@tonic-gate 		} else {
54*0Sstevel@tonic-gate 			*p++ = *s;
55*0Sstevel@tonic-gate 		}
56*0Sstevel@tonic-gate 	}
57*0Sstevel@tonic-gate 
58*0Sstevel@tonic-gate 	*p = '\0';
59*0Sstevel@tonic-gate }
60*0Sstevel@tonic-gate 
61*0Sstevel@tonic-gate 
62*0Sstevel@tonic-gate static int
unhex(char c)63*0Sstevel@tonic-gate unhex( char c )
64*0Sstevel@tonic-gate {
65*0Sstevel@tonic-gate 	return( c >= '0' && c <= '9' ? c - '0'
66*0Sstevel@tonic-gate 	    : c >= 'A' && c <= 'F' ? c - 'A' + 10
67*0Sstevel@tonic-gate 	    : c - 'a' + 10 );
68*0Sstevel@tonic-gate }
69