--- /dev/null
+/*
+ * Copyright (C) 2005-2008 Atsushi Konno All rights reserved.
+ * Copyright (C) 2005 QSDN,Inc. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __CHXJ_PREG_REPLACE_H__
+#define __CHXJ_PREG_REPLACE_H__
+
+#include "mod_chxj.h"
+
+extern ap_regex_t *chxj_compile_for_preg_replace(apr_pool_t *p, const char *pattern);
+extern char *chxj_preg_str_replace(apr_pool_t *p, const char *pattern, const char *replacement, const char *str);
+extern char *chxj_preg_str_replace_all(apr_pool_t *p, const char *pattern, const char *replacement, const char *str);
+extern char *chxj_preg_replace(apr_pool_t *p, ap_regex_t *regexp, const char *replacement, const char *str);
+extern char *chxj_preg_replace_all(apr_pool_t *p, ap_regex_t *regexp, const char *replacement, const char *str);
+
+#endif
chxj_node_exchange.c \
chxj_url_encode.c \
chxj_cookie.c \
+ chxj_preg_replace.c \
chxj_emoji.c
#include "chxj_apply_convrule.h"
#include "chxj_url_encode.h"
#include "qs_parse_string.h"
+#include "chxj_preg_replace.h"
#include <limits.h>
" </DISPLAY>\r\n"
"<HDML>\r\n";
+static ap_regex_t *v_docomo_serial_pattern1 = NULL;
+static ap_regex_t *v_docomo_serial_pattern2 = NULL;
+static ap_regex_t *v_docomo_serial_pattern3 = NULL;
+static ap_regex_t *v_softbank_serial_pattern1 = NULL;
+
/*----------------------------------------------------------------------------*/
/* Prototype declaration */
/*----------------------------------------------------------------------------*/
-static char *s_create_workfile(request_rec *,
+static char *s_create_workfile_name(request_rec *,
mod_chxj_config *,
const char *,
query_string_param_t *);
/*--------------------------------------------------------------------------*/
/* Create Workfile Name */
/*--------------------------------------------------------------------------*/
- tmpfile = s_create_workfile(r, conf, user_agent, qsp);
+ tmpfile = s_create_workfile_name(r, conf, user_agent, qsp);
DBG(r,"workfile=[%s]", tmpfile);
rv = apr_stat(&st, r->filename, APR_FINFO_MIN, r->pool);
}
+static void
+s_init_serial_pattern(apr_pool_t *p)
+{
+ if (!v_docomo_serial_pattern1) {
+ v_docomo_serial_pattern1 = chxj_compile_for_preg_replace(p, "/ser[^;\\)]+");
+ }
+ if (!v_docomo_serial_pattern2) {
+ v_docomo_serial_pattern2 = chxj_compile_for_preg_replace(p, ";ser[^;\\)]+");
+ }
+ if (!v_docomo_serial_pattern3) {
+ v_docomo_serial_pattern3 = chxj_compile_for_preg_replace(p, ";icc[^;\\)]+");
+ }
+ if (!v_softbank_serial_pattern1) {
+ v_softbank_serial_pattern1 = chxj_compile_for_preg_replace(p, "/SN[0-9a-zA-Z][0-9a-zA-Z][0-9a-zA-Z][0-9a-zA-Z][0-9a-zA-Z][0-9a-zA-Z][0-9a-zA-Z][0-9a-zA-Z][0-9a-zA-Z][0-9a-zA-Z][0-9a-zA-Z] ");
+ }
+}
+
static char *
-s_create_workfile(
+s_create_workfile_name(
request_rec *r,
mod_chxj_config *conf,
const char *user_agent,
int len;
char *w = apr_palloc(r->pool, 256);
char *fname;
+ char *new_user_agent;
+
+ s_init_serial_pattern(r->pool);
+
+ /* for DoCoMo */
+ new_user_agent = chxj_preg_replace(r->pool, v_docomo_serial_pattern1, "", user_agent);
+ new_user_agent = chxj_preg_replace(r->pool, v_docomo_serial_pattern2, "", new_user_agent);
+ new_user_agent = chxj_preg_replace(r->pool, v_docomo_serial_pattern3, "", new_user_agent);
+
+ /* for SoftBank */
+ new_user_agent = chxj_preg_replace(r->pool, v_softbank_serial_pattern1, " ", new_user_agent);
memset(w, 0, 256);
switch (qsp->mode) {
--- /dev/null
+/*
+ * Copyright (C) 2005-2008 Atsushi Konno All rights reserved.
+ * Copyright (C) 2005 QSDN,Inc. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <apr.h>
+#include <ap_config.h>
+#include <ap_regex.h>
+#include <apr_strings.h>
+#include <httpd.h>
+
+#include "chxj_preg_replace.h"
+
+static inline char *
+s_init_pattern(apr_pool_t *p, const char *old)
+{
+ return apr_psprintf(p, "^(.*)(%s)(.*)$", old);
+}
+
+
+static inline ap_regex_t *
+s_compile_regex(apr_pool_t *p, const char *pattern)
+{
+ char *new_pat;
+ new_pat = s_init_pattern(p, pattern);
+ return ap_pregcomp(p, new_pat, AP_REG_EXTENDED|AP_REG_ICASE);
+}
+
+ap_regex_t *
+chxj_compile_for_preg_replace(apr_pool_t *p, const char *pattern)
+{
+ return s_compile_regex(p, pattern);
+}
+
+
+static inline char *
+s_one_time_replace(apr_pool_t *p, ap_regex_t *regexp, const char *replacement, const char *str)
+{
+ ap_regmatch_t match[10];
+
+ if (ap_regexec(regexp, str, regexp->re_nsub + 1, match, 0) == 0) {
+ /* Match */
+ char *one = ap_pregsub(p, "$1", str, regexp->re_nsub + 1, match);
+ char *three = ap_pregsub(p, "$3", str, regexp->re_nsub + 1, match);
+ if (strlen(replacement)) {
+ return apr_pstrcat(p, one, replacement, three, NULL);
+ }
+ return apr_pstrcat(p, one, three, NULL);
+ }
+ /* Not Match */
+ return NULL;
+}
+
+
+char *
+chxj_preg_str_replace(apr_pool_t *p, const char *pattern, const char *replacement, const char *str)
+{
+ return chxj_preg_replace(p, s_compile_regex(p, pattern), replacement, str);
+}
+
+
+char *
+chxj_preg_str_replace_all(apr_pool_t *p, const char *pattern, const char *replacement, const char *str)
+{
+ return chxj_preg_replace_all(p, s_compile_regex(p, pattern), replacement, str);
+}
+
+
+char *
+chxj_preg_replace(apr_pool_t *p, ap_regex_t *regexp, const char *replacement, const char *str)
+{
+ char *result;
+
+ result = s_one_time_replace(p, regexp, replacement, str);
+ if (result == NULL)
+ return apr_pstrdup(p, str);
+
+ return result;
+}
+
+
+char *
+chxj_preg_replace_all(apr_pool_t *p, ap_regex_t *regexp, const char *replacement, const char *str)
+{
+ char *result;
+ char *pre_result;
+
+ result = apr_pstrdup(p, str);
+ for (;;) {
+ pre_result = s_one_time_replace(p, regexp, replacement, result);
+ if (pre_result == NULL)
+ break;
+ result = pre_result;
+ }
+
+ return result;
+}
+
+