2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 /***************************************************************************
19 * Description: URL manipulation subroutines. (ported from mod_proxy). *
20 * Version: $Revision: 531816 $ *
21 ***************************************************************************/
23 #include "jk_global.h"
27 #define JK_ISXDIGIT(x) apr_isxdigit((x))
28 #define JK_ISDIGIT(x) apr_isdigit((x))
29 #define JK_ISUPPER(x) apr_isupper((x))
30 #define JK_ISALNUM(x) apr_isalnum((x))
32 #define JK_ISXDIGIT(x) isxdigit((int)(unsigned char)((x)))
33 #define JK_ISDIGIT(x) isdigit((int)(unsigned char)((x)))
34 #define JK_ISUPPER(x) isupper((int)(unsigned char)((x)))
35 #define JK_ISALNUM(x) isalnum((int)(unsigned char)((x)))
38 static void jk_c2hex(int ch, char *x)
46 x[1] = ('A' - 10) + i;
54 x[2] = ('A' - 10) + i;
59 #else /*CHARSET_EBCDIC*/
60 static const char ntoa[] = { "0123456789ABCDEF" };
66 jk_xlate_to_ascii(buf, 1);
69 x[1] = ntoa[(buf[0] >> 4) & 0x0F];
70 x[2] = ntoa[buf[0] & 0x0F];
72 #endif /*CHARSET_EBCDIC*/
76 * Convert a URL-encoded string to canonical form.
77 * It encodes those which must be encoded, and does not touch
78 * those which must not be touched.
79 * String x must be '\0'-terminated.
80 * String y must be pre-allocated with len maxlen
81 * (including the terminating '\0').
83 int jk_canonenc(const char *x, char *y, int maxlen)
87 char *allowed; /* characters which should not be encoded */
88 char *reserved; /* characters which much not be en/de-coded */
91 * N.B. in addition to :@&=, this allows ';' in an http path
92 * and '?' in an ftp path -- this may be revised
94 allowed = "~$-_.+!*'(),;:@&=";
97 for (i = 0, j = 0; ch != '\0' && j < maxlen; i++, j++, ch=x[i]) {
98 /* always handle '/' first */
99 if (strchr(reserved, ch)) {
103 /* recode it, if necessary */
104 if (!JK_ISALNUM(ch) && !strchr(allowed, ch)) {