17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the Netscape Public
37c478bd9Sstevel@tonic-gate  * License Version 1.1 (the "License"); you may not use this file
47c478bd9Sstevel@tonic-gate  * except in compliance with the License. You may obtain a copy of
57c478bd9Sstevel@tonic-gate  * the License at http://www.mozilla.org/NPL/
67c478bd9Sstevel@tonic-gate  *
77c478bd9Sstevel@tonic-gate  * Software distributed under the License is distributed on an "AS
87c478bd9Sstevel@tonic-gate  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
97c478bd9Sstevel@tonic-gate  * implied. See the License for the specific language governing
107c478bd9Sstevel@tonic-gate  * rights and limitations under the License.
117c478bd9Sstevel@tonic-gate  *
127c478bd9Sstevel@tonic-gate  * The Original Code is Mozilla Communicator client code, released
137c478bd9Sstevel@tonic-gate  * March 31, 1998.
147c478bd9Sstevel@tonic-gate  *
157c478bd9Sstevel@tonic-gate  * The Initial Developer of the Original Code is Netscape
167c478bd9Sstevel@tonic-gate  * Communications Corporation. Portions created by Netscape are
177c478bd9Sstevel@tonic-gate  * Copyright (C) 1998-1999 Netscape Communications Corporation. All
187c478bd9Sstevel@tonic-gate  * Rights Reserved.
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * Contributor(s):
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate 
237c478bd9Sstevel@tonic-gate /*
247c478bd9Sstevel@tonic-gate  *  LIBLDAP unescape.c -- LDAP URL un-escape routines
257c478bd9Sstevel@tonic-gate  *  We also tolerate URLs that look like: <ldapurl> and <URL:ldapurl>
267c478bd9Sstevel@tonic-gate  */
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate #include "ldap-int.h"
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate static int unhex( char c );
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate void
nsldapi_hex_unescape(char * s)357c478bd9Sstevel@tonic-gate nsldapi_hex_unescape( char *s )
367c478bd9Sstevel@tonic-gate {
377c478bd9Sstevel@tonic-gate /*
387c478bd9Sstevel@tonic-gate  * Remove URL hex escapes from s... done in place.  The basic concept for
397c478bd9Sstevel@tonic-gate  * this routine is borrowed from the WWW library HTUnEscape() routine.
407c478bd9Sstevel@tonic-gate  */
417c478bd9Sstevel@tonic-gate 	char	*p;
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate 	for ( p = s; *s != '\0'; ++s ) {
447c478bd9Sstevel@tonic-gate 		if ( *s == '%' ) {
45*8df617e1SDouglas Bagnall 			if ( *++s == '\0' ) {
46*8df617e1SDouglas Bagnall 				break;
477c478bd9Sstevel@tonic-gate 			}
48*8df617e1SDouglas Bagnall 			*p = unhex( *s ) << 4;
49*8df617e1SDouglas Bagnall 			if ( *++s == '\0' ) {
50*8df617e1SDouglas Bagnall 				break;
517c478bd9Sstevel@tonic-gate 			}
52*8df617e1SDouglas Bagnall 			*p++ += unhex( *s );
53*8df617e1SDouglas Bagnall 
547c478bd9Sstevel@tonic-gate 		} else {
557c478bd9Sstevel@tonic-gate 			*p++ = *s;
567c478bd9Sstevel@tonic-gate 		}
577c478bd9Sstevel@tonic-gate 	}
587c478bd9Sstevel@tonic-gate 
597c478bd9Sstevel@tonic-gate 	*p = '\0';
607c478bd9Sstevel@tonic-gate }
617c478bd9Sstevel@tonic-gate 
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate static int
unhex(char c)647c478bd9Sstevel@tonic-gate unhex( char c )
657c478bd9Sstevel@tonic-gate {
667c478bd9Sstevel@tonic-gate 	return( c >= '0' && c <= '9' ? c - '0'
677c478bd9Sstevel@tonic-gate 	    : c >= 'A' && c <= 'F' ? c - 'A' + 10
687c478bd9Sstevel@tonic-gate 	    : c - 'a' + 10 );
697c478bd9Sstevel@tonic-gate }
70