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