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_is_jreserved_tag(const char *src)
127 for (ii=0;ii<RESERVED_NELT;ii++) {
128 if (STRCASEEQ(reserved_table[ii].lower,
129 reserved_table[ii].upper,
130 reserved_table[ii].name,
139 chxj_jreserved_to_safe_tag(request_rec *r, const char *src, chxjconvrule_entry *entryp)
142 if (entryp->action & CONVRULE_JRCONV_OFF_BIT) {
145 for (ii=0;ii<RESERVED_NELT;ii++) {
146 if (STRCASEEQ(reserved_table[ii].lower,
147 reserved_table[ii].upper,
148 reserved_table[ii].name,
150 return apr_psprintf(r->pool, "%s%s", CHXJ_SOFTBANK_RESERVED_TAG_PREFIX, reserved_table[ii].name);
153 for (ii=0; ii<RESERVED_NELT_START_WITH; ii++) {
154 if (strncasecmp(reserved_start_with_table[ii].name, src, sizeof(reserved_start_with_table[ii].name)) == 0) {
155 return apr_psprintf(r->pool, "%s%s", CHXJ_SOFTBANK_RESERVED_TAG_PREFIX, src);
163 chxj_safe_to_jreserved_tag(request_rec *r, const char *src)
165 if (strncasecmp(CHXJ_SOFTBANK_RESERVED_TAG_PREFIX, src, sizeof(CHXJ_SOFTBANK_RESERVED_TAG_PREFIX)-1) == 0) {
166 return apr_pstrdup(r->pool, &src[sizeof(CHXJ_SOFTBANK_RESERVED_TAG_PREFIX)-1]);
172 chxj_jreserved_tag_to_safe_for_query_string(request_rec *r, const char *query_string, chxjconvrule_entry *entryp)
175 apr_pool_create(&pool, r->pool);
176 char *s = apr_pstrdup(pool, query_string);
179 if (entryp->action & CONVRULE_JRCONV_OFF_BIT) {
182 if (!s) return apr_pstrdup(pool, "");
185 if (!s) return result;
188 fname = apr_pstrdup(pool, result);
194 char *pair = apr_strtok(s, "&", &pstat);
197 char *key = apr_strtok(pair, "=", &pstat2);
200 val = apr_strtok(NULL, "=", &pstat2);
204 if (strcasecmp(key, "guid") == 0) {
205 tmp = apr_psprintf(pool, "%s=%s", key, val);
207 result = apr_pstrcat(pool, result, "&" ,tmp, NULL);
214 tmp = apr_psprintf(pool, "%s=%s", chxj_jreserved_to_safe_tag(r, key, entryp), chxj_url_decode(pool, val));
216 result = apr_pstrcat(pool, result, "&" ,tmp, NULL);
223 return apr_pstrcat(pool, fname, "?" , result, NULL);