--- /dev/null
+/*
+ * Copyright (C) 2005 QSDN,Inc. All rights reserved.
+ * Copyright (C) 2005 Atsushi Konno 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_COOKIE_H__
+#define __CHXJ_COOKIE_H__
+
+#include "mod_chxj.h"
+
+extern void chxj_save_cookie(request_rec *r);
+
+#endif
+/*
+ * vim:ts=2 et
+ */
--- /dev/null
+/*
+ * Copyright (C) 2005 QSDN,Inc. All rights reserved.
+ * Copyright (C) 2005 Atsushi Konno 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_URL_ENCODE_H__
+#define __CHXJ_URL_ENCODE_H__
+
+#include "mod_chxj.h"
+
+extern char* chxj_url_encode(request_rec* r, const char* src);
+extern char* chxj_url_decode(request_rec* r, const char* src);
+
+#endif
+/*
+ * vim:ts=2 et
+ */
--- /dev/null
+/* include/config.h. Generated by configure. */
+/* include/config.h.in. Generated from configure.ac by autoheader. */
+
+/* Define to 1 if you have the <ap_regex.h> header file. */
+#define HAVE_AP_REGEX_H
+
+/* Define to 1 if you have the `close' function. */
+#define HAVE_CLOSE 1
+
+/* Define to 1 if you have the <dlfcn.h> header file. */
+#define HAVE_DLFCN_H 1
+
+/* Define to 1 if you have the <fcntl.h> header file. */
+#define HAVE_FCNTL_H 1
+
+/* Define to 1 if you have the <inttypes.h> header file. */
+#define HAVE_INTTYPES_H 1
+
+/* Define to 1 if you have the `apr-0' library (-lapr-0). */
+#define HAVE_LIBAPR_0 1
+
+/* Define to 1 if you have the <libgen.h> header file. */
+#define HAVE_LIBGEN_H 1
+
+/* Define to 1 if you have the iconv library file. */
+/* #undef HAVE_LIBICONV */
+
+/* Define to 1 if you have the iconv_hook library file. */
+#define HAVE_LIBICONV_HOOK
+
+/* Define to 1 if your system has a GNU libc compatible `malloc' function, and
+ to 0 otherwise. */
+#define HAVE_MALLOC 1
+
+/* Define to 1 if you have the `memcpy' function. */
+#define HAVE_MEMCPY 1
+
+/* Define to 1 if you have the <memory.h> header file. */
+#define HAVE_MEMORY_H 1
+
+/* Define to 1 if you have the `memset' function. */
+#define HAVE_MEMSET 1
+
+/* Define to 1 if you have the `mmap' function. */
+#define HAVE_MMAP 1
+
+/* Define to 1 if you have the `open' function. */
+#define HAVE_OPEN 1
+
+/* Define to 1 if you have the <stdint.h> header file. */
+#define HAVE_STDINT_H 1
+
+/* Define to 1 if you have the <stdlib.h> header file. */
+#define HAVE_STDLIB_H 1
+
+/* Define to 1 if you have the `strcasecmp' function. */
+#define HAVE_STRCASECMP 1
+
+/* Define to 1 if you have the <strings.h> header file. */
+#define HAVE_STRINGS_H 1
+
+/* Define to 1 if you have the <string.h> header file. */
+#define HAVE_STRING_H 1
+
+/* Define to 1 if you have the `strncasecmp' function. */
+#define HAVE_STRNCASECMP 1
+
+/* Define to 1 if you have the `strstr' function. */
+#define HAVE_STRSTR 1
+
+/* Define to 1 if you have the <sys/mman.h> header file. */
+#define HAVE_SYS_MMAN_H 1
+
+/* Define to 1 if you have the <sys/stat.h> header file. */
+#define HAVE_SYS_STAT_H 1
+
+/* Define to 1 if you have the <sys/types.h> header file. */
+#define HAVE_SYS_TYPES_H 1
+
+/* Define to 1 if you have the <unistd.h> header file. */
+#define HAVE_UNISTD_H 1
+
+/* Name of package */
+#define PACKAGE "mod_chxj"
+
+/* Define to the address where bug reports for this package should be sent. */
+#define PACKAGE_BUGREPORT ""
+
+/* Define to the full name of this package. */
+#define PACKAGE_NAME "mod_chxj"
+
+/* Define to the full name and version of this package. */
+#define PACKAGE_STRING "mod_chxj 0.8.0"
+
+/* Define to the one symbol short name of this package. */
+#define PACKAGE_TARNAME "mod_chxj"
+
+/* Define to the version of this package. */
+#define PACKAGE_VERSION "0.8.0"
+
+/* Define to 1 if you have the ANSI C header files. */
+#define STDC_HEADERS 1
+
+/* Version number of package */
+#define VERSION "0.8.0"
+
+/* Define to empty if `const' does not conform to ANSI C. */
+/* #undef const */
+
+/* Define to rpl_malloc if the replacement function should be used. */
+/* #undef malloc */
#define DBG5(X,Y,Za,Zb,Zc,Zd,Ze) ap_log_rerror(APLOG_MARK,APLOG_DEBUG,0,(X),(Y),(Za),(Zb),(Zc),(Zd),(Ze))
#define ERR(X,Y) ap_log_rerror(APLOG_MARK,APLOG_ERR,0,(X),(Y))
#define ERR1(X,Y,Za) ap_log_rerror(APLOG_MARK,APLOG_ERR,0,(X),(Y),(Za))
+#define ERR2(X,Y,Za,Zb) ap_log_rerror(APLOG_MARK,APLOG_ERR,0,(X),(Y),(Za),(Zb))
extern tag_handlers chxj_tag_handlers[];
extern tag_handler chtml10_handler[];
chxj_calc_ecc.c \
chxj_apply_convrule.c \
chxj_encoding.c \
- chxj_node_exchange.c
+ chxj_node_exchange.c \
+ chxj_url_encode.c \
+ chxj_cookie.c
libmod_chxj_la_CFLAGS = -Wall -O2 -prefer-pic @QDEFS@ @DDEFS@ -I. -I../include -I@with_apache_header@
--- /dev/null
+/*
+ * Copyright (C) 2005 QSDN,Inc. All rights reserved.
+ * Copyright (C) 2005 Atsushi Konno 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 "mod_chxj.h"
+#include "chxj_cookie.h"
+#include "chxj_url_encode.h"
+
+#include "apu.h"
+#include "apr_dbm.h"
+#include "apr_uuid.h"
+#include "apr_md5.h"
+#include "apr_base64.h"
+
+/*
+ *
+ */
+void
+chxj_save_cookie(request_rec* r)
+{
+ int ii;
+ char* cookie;
+ apr_array_header_t* headers;
+ apr_table_entry_t* entryp;
+ apr_status_t retval;
+ apr_datum_t dbmkey;
+ apr_datum_t dbmval;
+ apr_dbm_t* f;
+ apr_uuid_t uuid;
+ char* uuid_string;
+ unsigned char* md5_value;
+ char* md5_string;
+
+
+ DBG(r, "start chxj_save_cookie()");
+
+ headers = (apr_array_header_t*)apr_table_elts(r->headers_out);
+ entryp = (apr_table_entry_t*)headers->elts;
+
+ retval = apr_dbm_open_ex(&f,
+ "default",
+ "/tmp/cookie.db",
+ APR_DBM_RWCREATE,
+ APR_OS_DEFAULT,
+ r->pool);
+ if (retval != APR_SUCCESS) {
+ ERR2(r, "could not open dbm (type %s) auth file: %s", "default", "/tmp/cookie.db");
+ return;
+ }
+
+ cookie = apr_palloc(r->pool, 1);
+ cookie[0] = 0;
+
+ for (ii=0; ii<headers->nelts; ii++) {
+ if (strcasecmp(entryp[ii].key, "Set-Cookie") == 0) {
+ DBG(r, "=====================================");
+ DBG2(r, "cookie=[%s:%s]", entryp[ii].key, entryp[ii].val);
+ cookie = apr_pstrcat(r->pool, cookie, "\r\n", entryp[ii].val, NULL);
+ DBG(r, "=====================================");
+ }
+ }
+ apr_uuid_get(&uuid);
+ uuid_string = apr_palloc(r->pool, APR_UUID_FORMATTED_LENGTH + 1);
+ memset(uuid_string, 0, APR_UUID_FORMATTED_LENGTH + 1);
+ apr_uuid_format(uuid_string, &uuid);;
+
+ md5_value = (unsigned char*)apr_palloc(r->pool, APR_MD5_DIGESTSIZE + 1);
+ memset(md5_value, 0, APR_MD5_DIGESTSIZE + 1);
+ retval = apr_md5(md5_value,
+ (const char*)uuid_string, (apr_size_t)APR_UUID_FORMATTED_LENGTH);
+ if (retval != APR_SUCCESS) {
+ ERR(r, "md5 failed.");
+ goto on_error;
+ }
+
+ md5_string = apr_palloc(r->pool, apr_base64_encode_len(APR_MD5_DIGESTSIZE)+1);
+ memset(md5_string, 0, APR_MD5_DIGESTSIZE+1);
+ apr_base64_encode(md5_string, (char*)md5_value, APR_MD5_DIGESTSIZE);
+
+ DBG1(r, "md5_string=[%s]", md5_string);
+
+ md5_string = chxj_url_encode(r,md5_string);
+
+ DBG1(r, "md5_string=[%s]", md5_string);
+
+ /*
+ * create key
+ */
+
+ dbmkey.dptr = md5_string;
+ dbmkey.dsize = strlen(md5_string);
+
+ /*
+ * create val
+ */
+ dbmval.dptr = cookie;
+ dbmval.dsize = strlen(cookie);
+
+ /*
+ * store to db
+ */
+ retval = apr_dbm_store(f, dbmkey, dbmval);
+ if (retval != APR_SUCCESS) {
+ ERR1(r, "Cannot store SSL session to DBM file `%s'","/tmp/cookie.db");
+ goto on_error;
+ }
+
+
+on_error:
+ apr_dbm_close(f);
+
+ DBG(r, "end chxj_save_cookie()");
+}
+
+/*
+ * vim:ts=2 et
+ */
#include "chxj_str_util.h"
#include "chxj_qr_code.h"
#include "chxj_apply_convrule.h"
+#include "chxj_url_encode.h"
#include "qs_parse_string.h"
#include "http_core.h"
--- /dev/null
+/*
+ * Copyright (C) 2005 QSDN,Inc. All rights reserved.
+ * Copyright (C) 2005 Atsushi Konno 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 "mod_chxj.h"
+#include "chxj_url_encode.h"
+
+#define IS_ALPHA_UPPER(X) (((X) >='A') && ((X) <= 'Z'))
+#define IS_ALPHA_LOWER(X) (((X) >='a') && ((X) <= 'z'))
+#define IS_DIGIT(X) (((X) >='0') && ((X) <= '9'))
+#define TO_HEXSTRING(X) (((X) < 10) ? (X) + '0' : (X) + ('A' - 10))
+#define IS_HEXCHAR(X) ( \
+ ((X) >= 'A' && (X) <= 'F') \
+ || ((X) >= 'a' && (X) <= 'f') \
+ || ((X) >= '0' && (X) <= '9') \
+ )
+
+static inline char
+s_hex_value(char c)
+{
+ if (c >= 'A' && c <= 'F') return (c - 'A' + 10);
+ if (c >= 'a' && c <= 'f') return (c - 'a' + 10);
+ if (c >= '0' && c <= '9') return (c - '0' + 0);
+ return 0;
+}
+
+char*
+chxj_url_encode(request_rec* r, const char* src)
+{
+ char* dst;
+ char* sp = (char*)src;
+ unsigned char tmp;
+
+ dst = apr_palloc(r->pool, 1);
+ dst[0] = 0;
+
+ if (!src) return dst;
+
+
+ while(*sp) {
+
+ if (IS_ALPHA_UPPER(*sp) || IS_ALPHA_LOWER(*sp) || IS_DIGIT(*sp)) {
+ dst = apr_psprintf(r->pool, "%s%c", dst, *sp);
+ sp++;
+ continue;
+ }
+
+ if (*sp == ' ') {
+ dst = apr_pstrcat(r->pool, dst, "+", NULL);
+ sp++;
+ continue;
+ }
+
+ tmp = (*sp >> 4) & 0x0f;
+ dst = apr_psprintf(r->pool, "%s%%%c", dst, TO_HEXSTRING(tmp));
+ tmp = *sp & 0x0f;
+ dst = apr_psprintf(r->pool, "%s%c", dst, TO_HEXSTRING(tmp));
+
+ sp++;
+ }
+
+ return dst;
+}
+
+char*
+chxj_url_decode(request_rec* r, const char* src)
+{
+ char* dst;
+ int len;
+ int ii;
+ int jj;
+
+
+ if (!src) return NULL;
+
+ len = strlen(src);
+ dst = apr_palloc(r->pool, len+1);
+ memset(dst, 0, len+1);
+
+ for (jj=0,ii=0; src[ii] != '\0' && ii < len; ii++) {
+ if (src[ii] == '%') {
+ if (ii + 2 <= len && IS_HEXCHAR(src[ii+1]) && IS_HEXCHAR(src[ii+2])) {
+ dst[jj++] = s_hex_value(src[ii+1]) * 16 + s_hex_value(src[ii+2]);
+ ii+=2;
+ }
+ }
+ else {
+ dst[jj++] = src[ii];
+ }
+ }
+
+ return dst;
+}
+/*
+ * vim:ts=2 et
+ */
#include "chxj_qr_code.h"
#include "chxj_encoding.h"
#include "chxj_apply_convrule.h"
+#include "chxj_cookie.h"
#define CHXJ_VERSION_PREFIX PACKAGE_NAME "/"
return (char*)*src;
}
+ /*
+ * save cookie.
+ */
+ chxj_save_cookie(r);
+
if (!r->header_only) {
device_table* spec = chxj_specified_device(r, user_agent);
char* dvalue;
dlen = strlen(value);
- ap_unescape_url(value);
+ value = chxj_url_decode(r, value);
DBG1(r, "************ before encoding[%s]", value);
dvalue = chxj_rencoding(r, value, &dlen);
- dvalue = ap_escape_uri(r->pool,dvalue);
+ dvalue = chxj_url_encode(r, dvalue);
DBG1(r, "************ after encoding[%s]", dvalue);
char* dvalue;
dlen = strlen(value);
- ap_unescape_url(value);
+ value = chxj_url_decode(r, value);
DBG1(r, "************ before encoding[%s]", value);
dvalue = chxj_rencoding(r, value, &dlen);
- dvalue = ap_escape_uri(r->pool,dvalue);
+ dvalue = chxj_url_encode(r,dvalue);
DBG1(r, "************ after encoding[%s]", dvalue);
char* dvalue;
dlen = strlen(value);
- ap_unescape_url(value);
+ value = chxj_url_decode(r, value);
DBG1(r, "************ before encoding[%s]", value);
dvalue = chxj_rencoding(r, value, &dlen);
- dvalue = ap_escape_uri(r->pool,dvalue);
+ dvalue = chxj_url_encode(r,dvalue);
DBG1(r, "************ after encoding[%s]", dvalue);
DBG(r, "start of chxj_output_filter()");
+
if (!f->ctx) {
if ((f->r->proto_num >= 1001)
&& !f->r->main