2 * Copyright (C) 2005-2009 Atsushi Konno All rights reserved.
3 * Copyright (C) 2005 QSDN,Inc. All rights reserved.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * 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 #include "chxj_jreserved_tag.h"
19 #include "chxj_url_encode.h"
21 typedef struct r_table {
27 static r_table_t reserved_start_with_table[] = {
36 #define RESERVED_NELT (16)
37 #define RESERVED_NELT_START_WITH (1)
39 static r_table_t reserved_table[] = {
124 chxj_jreserved_to_safe_tag(request_rec *r, const char *src, chxjconvrule_entry *entryp)
127 if (entryp->action & CONVRULE_JRCONV_OFF_BIT) {
130 for (ii=0;ii<RESERVED_NELT;ii++) {
131 if (STRCASEEQ(reserved_table[ii].lower,
132 reserved_table[ii].upper,
133 reserved_table[ii].name,
135 return apr_psprintf(r->pool, "%s%s", CHXJ_SOFTBANK_RESERVED_TAG_PREFIX, reserved_table[ii].name);
138 for (ii=0; ii<RESERVED_NELT_START_WITH; ii++) {
139 if (strncasecmp(reserved_start_with_table[ii].name, src, sizeof(reserved_start_with_table[ii].name)) == 0) {
140 return apr_psprintf(r->pool, "%s%s", CHXJ_SOFTBANK_RESERVED_TAG_PREFIX, src);
148 chxj_safe_to_jreserved_tag(request_rec *r, const char *src)
150 if (strncasecmp(CHXJ_SOFTBANK_RESERVED_TAG_PREFIX, src, sizeof(CHXJ_SOFTBANK_RESERVED_TAG_PREFIX)-1) == 0) {
151 return apr_pstrdup(r->pool, &src[sizeof(CHXJ_SOFTBANK_RESERVED_TAG_PREFIX)-1]);
157 chxj_jreserved_tag_to_safe_for_query_string(request_rec *r, const char *query_string, chxjconvrule_entry *entryp, int xmlflag)
160 apr_pool_create(&pool, r->pool);
161 char *s = apr_pstrdup(pool, query_string);
164 if (entryp->action & CONVRULE_JRCONV_OFF_BIT) {
167 if (!s) return apr_pstrdup(pool, "");
170 if (!s) return result;
173 fname = apr_pstrdup(pool, result);
181 pair = apr_strtok(s, "&", &pstat);
184 pair = apr_strtok(s, "&", &pstat);
188 char *key = apr_strtok(pair, "=", &pstat2);
191 val = apr_strtok(NULL, "=", &pstat2);
195 if (strcasecmp(key, "guid") == 0) {
196 tmp = apr_psprintf(pool, "%s=%s", key, val);
199 tmp = apr_psprintf(pool, "%s=%s", chxj_jreserved_to_safe_tag(r, key, entryp), chxj_url_decode(pool, val));
202 result = apr_pstrcat(pool, result, "&" ,tmp, NULL);
205 result = apr_pstrcat(pool, result, "&" ,tmp, NULL);
213 return apr_pstrcat(pool, fname, "?" , result, NULL);