2 * Copyright (C) 2005-2008 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.
19 #include "chxj_img_conv_format.h"
20 #include "chxj_specified_device.h"
21 #include "chxj_str_util.h"
22 #include "chxj_qr_code.h"
23 #include "chxj_apply_convrule.h"
24 #include "chxj_url_encode.h"
25 #include "qs_parse_string.h"
27 #include "http_core.h"
29 #include <wand/magick_wand.h>
32 #define EXIT_MAGICK_ERROR() \
34 char *description; ExceptionType severity; \
35 description=MagickGetException(magick_wand,&severity); \
36 ap_log_rerror(APLOG_MARK,APLOG_DEBUG, 0, r,"%s %s %d %s\n",__FILE__,(__func__),__LINE__,description); \
37 description=(char *) MagickRelinquishMemory(description); \
38 DestroyMagickWand(magick_wand); \
41 typedef enum img_conv_mode_t {
42 IMG_CONV_MODE_NORMAL = 0,
43 IMG_CONV_MODE_THUMBNAIL,
44 IMG_CONV_MODE_WALLPAPER,
48 /*----------------------------------------------------------------------------*/
49 /* User-Agent use flag */
50 /*----------------------------------------------------------------------------*/
51 typedef enum _ua_use_flag_t {
52 UA_USE=0, /* User-Agent is used. */
53 UA_IGN, /* User-Agent is disregarded. */
56 /*----------------------------------------------------------------------------*/
57 /* Request parameter maintenance structure */
58 /*----------------------------------------------------------------------------*/
59 typedef struct query_string_param_t query_string_param_t;
61 struct query_string_param_t {
64 ua_use_flag_t ua_flag;
66 char* name; /* for EZGET */
67 long offset; /* for EZGET */
68 long count; /* for EZGET */
73 /*----------------------------------------------------------------------------*/
74 /* Device_spec when User-Agent is disregarded */
75 /*----------------------------------------------------------------------------*/
76 static device_table v_ignore_spec = {
97 /*----------------------------------------------------------------------------*/
98 /* CRC calculation table for AU */
99 /*----------------------------------------------------------------------------*/
100 static unsigned short AU_CRC_TBL[256] = {
101 0x0000,0x1021,0x2042,0x3063,0x4084,0x50A5,0x60C6,0x70E7,
102 0x8108,0x9129,0xA14A,0xB16B,0xC18C,0xD1AD,0xE1CE,0xF1EF,
103 0x1231,0x0210,0x3273,0x2252,0x52B5,0x4294,0x72F7,0x62D6,
104 0x9339,0x8318,0xB37B,0xA35A,0xD3BD,0xC39C,0xF3FF,0xE3DE,
105 0x2462,0x3443,0x0420,0x1401,0x64E6,0x74C7,0x44A4,0x5485,
106 0xA56A,0xB54B,0x8528,0x9509,0xE5EE,0xF5CF,0xC5AC,0xD58D,
107 0x3653,0x2672,0x1611,0x0630,0x76D7,0x66F6,0x5695,0x46B4,
108 0xB75B,0xA77A,0x9719,0x8738,0xF7DF,0xE7FE,0xD79D,0xC7BC,
109 0x48C4,0x58E5,0x6886,0x78A7,0x0840,0x1861,0x2802,0x3823,
110 0xC9CC,0xD9ED,0xE98E,0xF9AF,0x8948,0x9969,0xA90A,0xB92B,
111 0x5AF5,0x4AD4,0x7AB7,0x6A96,0x1A71,0x0A50,0x3A33,0x2A12,
112 0xDBFD,0xCBDC,0xFBBF,0xEB9E,0x9B79,0x8B58,0xBB3B,0xAB1A,
113 0x6CA6,0x7C87,0x4CE4,0x5CC5,0x2C22,0x3C03,0x0C60,0x1C41,
114 0xEDAE,0xFD8F,0xCDEC,0xDDCD,0xAD2A,0xBD0B,0x8D68,0x9D49,
115 0x7E97,0x6EB6,0x5ED5,0x4EF4,0x3E13,0x2E32,0x1E51,0x0E70,
116 0xFF9F,0xEFBE,0xDFDD,0xCFFC,0xBF1B,0xAF3A,0x9F59,0x8F78,
117 0x9188,0x81A9,0xB1CA,0xA1EB,0xD10C,0xC12D,0xF14E,0xE16F,
118 0x1080,0x00A1,0x30C2,0x20E3,0x5004,0x4025,0x7046,0x6067,
119 0x83B9,0x9398,0xA3FB,0xB3DA,0xC33D,0xD31C,0xE37F,0xF35E,
120 0x02B1,0x1290,0x22F3,0x32D2,0x4235,0x5214,0x6277,0x7256,
121 0xB5EA,0xA5CB,0x95A8,0x8589,0xF56E,0xE54F,0xD52C,0xC50D,
122 0x34E2,0x24C3,0x14A0,0x0481,0x7466,0x6447,0x5424,0x4405,
123 0xA7DB,0xB7FA,0x8799,0x97B8,0xE75F,0xF77E,0xC71D,0xD73C,
124 0x26D3,0x36F2,0x0691,0x16B0,0x6657,0x7676,0x4615,0x5634,
125 0xD94C,0xC96D,0xF90E,0xE92F,0x99C8,0x89E9,0xB98A,0xA9AB,
126 0x5844,0x4865,0x7806,0x6827,0x18C0,0x08E1,0x3882,0x28A3,
127 0xCB7D,0xDB5C,0xEB3F,0xFB1E,0x8BF9,0x9BD8,0xABBB,0xBB9A,
128 0x4A75,0x5A54,0x6A37,0x7A16,0x0AF1,0x1AD0,0x2AB3,0x3A92,
129 0xFD2E,0xED0F,0xDD6C,0xCD4D,0xBDAA,0xAD8B,0x9DE8,0x8DC9,
130 0x7C26,0x6C07,0x5C64,0x4C45,0x3CA2,0x2C83,0x1CE0,0x0CC1,
131 0xEF1F,0xFF3E,0xCF5D,0xDF7C,0xAF9B,0xBFBA,0x8FD9,0x9FF8,
132 0x6E17,0x7E36,0x4E55,0x5E74,0x2E93,0x3EB2,0x0ED1,0x1EF0
135 /*----------------------------------------------------------------------------*/
136 /* Download page for AU */
137 /*----------------------------------------------------------------------------*/
138 static const char* HDML_FIRST_PAGE =
139 "<HDML VERSION=3.0 TTL=0 PUBLIC=TRUE>\r\n"
141 " <ACTION TYPE=ACCEPT TASK=GOSUB DEST=\"device:data/dnld?url=%s&name=%s%s&size=%ld&disposition=%s&title=%s\">\r\n"
145 static const char* HDML_SUCCESS_PAGE =
146 "<HDML VERSION=3.0 TTL=0 PUBLIC=TRUE>\r\n"
148 " <ACTION TYPE=ACCEPT TASK=RETURN>\r\n"
149 " \x83\x5f\x83\x45\x83\x93\x83\x8d\x81\x5b\x83\x68\x82\xc9\x90\xac\x8c\xf7\x82\xb5\x82\xdc\x82\xb5\x82\xbd\r\n"
153 static const char* HDML_FAIL_PAGE =
154 "<HDML VERSION=3.0 TTL=0 PUBLIC=TRUE>\r\n"
156 " <ACTION TYPE=ACCEPT TASK=RETURN>\r\n"
157 " \x83\x5f\x83\x45\x83\x93\x83\x8d\x81\x5b\x83\x68\x82\xc9\x8e\xb8\x94\x73\x82\xb5\x82\xdc\x82\xb5\x82\xbd\r\n"
161 /*----------------------------------------------------------------------------*/
162 /* Prototype declaration */
163 /*----------------------------------------------------------------------------*/
164 static char* s_create_workfile( request_rec*,
167 query_string_param_t*);
169 static apr_status_t s_create_cache_file(request_rec* r,
173 query_string_param_t* qsp);
175 static apr_status_t s_send_cache_file( device_table* spec,
176 query_string_param_t* query_string,
178 const char* tmpfile);
180 static apr_status_t s_send_original_file(request_rec* r,
181 const char* originalfile);
183 static apr_status_t s_header_only_cache_file(device_table* spec,
184 query_string_param_t* query_string,
186 const char* tmpfile);
188 static query_string_param_t* s_get_query_string_param(request_rec *r);
190 static unsigned short s_add_crc( const char* writedata,
191 apr_size_t witebyte);
193 static MagickWand* s_fixup_size(MagickWand* ,
196 query_string_param_t *qsp);
198 static MagickWand* s_fixup_color(MagickWand* magick_wand,
201 img_conv_mode_t mode);
202 static MagickWand* s_fixup_depth(MagickWand* magick_wand,
203 request_rec* r, device_table* spec);
204 static MagickWand* s_img_down_sizing(MagickWand* magick_wand,
205 request_rec* r, device_table* spec);
207 static MagickWand* s_add_copyright(MagickWand* magick_wand,
211 static char* s_create_blob_data(request_rec* r,
213 query_string_param_t* qsp,
217 static int s_img_conv_format_from_file(request_rec* r,
218 mod_chxj_config* conf,
219 const char* user_agent,
220 query_string_param_t* qsp,
226 chxj_img_conv_format_handler(request_rec* r)
228 mod_chxj_config* conf;
229 query_string_param_t* qsp;
232 chxjconvrule_entry* entryp;
234 DBG(r, "start chxj_img_conv_format_handler()");
236 if ((*r->handler != 'c' && *r->handler != 'C')
237 || (strcasecmp(r->handler, "chxj-picture")
238 && strcasecmp(r->handler, "chxj-qrcode"))) {
239 DBG(r, "end chxj_img_conv_format_handler()");
243 qsp = s_get_query_string_param(r);
244 conf = ap_get_module_config(r->per_dir_config, &chxj_module);
246 DBG(r, "end chxj_img_conv_format_handler() conf is null");
250 if (strcasecmp(r->handler, "chxj-qrcode") == 0 && conf->image == CHXJ_IMG_OFF) {
255 /*------------------------------------------------------------------------*/
256 /* get UserAgent from http header */
257 /*------------------------------------------------------------------------*/
258 /*--------------------------------------------------------------------------*/
259 /* User-Agent to spec */
260 /*--------------------------------------------------------------------------*/
261 if (qsp->user_agent) {
262 user_agent = apr_pstrdup(r->pool, qsp->user_agent);
265 entryp = chxj_apply_convrule(r, conf->convrules);
266 if (entryp && entryp->user_agent) {
267 user_agent = (char*)apr_table_get(r->headers_in, CHXJ_HTTP_USER_AGENT);
270 user_agent = (char*)apr_table_get(r->headers_in, HTTP_USER_AGENT);
276 if (qsp->ua_flag == UA_IGN)
277 spec = &v_ignore_spec;
279 spec = chxj_specified_device(r, user_agent);
281 DBG1(r,"found device_name=[%s]", spec->device_name);
282 DBG1(r,"User-Agent=[%s]", user_agent);
285 if (spec->width == 0 || spec->heigh == 0)
289 return s_img_conv_format_from_file(r, conf, user_agent, qsp, spec);
295 * It converts it from ImageData corresponding to each model.
298 * @param src [i] It is former image binary data.
299 * @param len [i/o] It is length of former image binary data.
302 chxj_exchange_image(request_rec *r, const char** src, apr_size_t* len)
304 mod_chxj_config* conf;
305 query_string_param_t* qsp;
310 chxjconvrule_entry* entryp;
312 DBG(r, "start chxj_exchange_image()");
314 conv_check = (char*)apr_table_get(r->headers_in, "CHXJ_IMG_CONV");
316 DBG(r, "end chxj_exchnage_image() already convert.");
321 qsp = s_get_query_string_param(r);
322 conf = ap_get_module_config(r->per_dir_config, &chxj_module);
324 DBG(r, "end chxj_exchange_image()");
328 /*--------------------------------------------------------------------------*/
329 /* User-Agent to spec */
330 /*--------------------------------------------------------------------------*/
331 if (qsp->user_agent) {
332 user_agent = apr_pstrdup(r->pool, qsp->user_agent);
335 entryp = chxj_apply_convrule(r, conf->convrules);
336 if (entryp && entryp->user_agent) {
337 user_agent = (char*)apr_table_get(r->headers_in, CHXJ_HTTP_USER_AGENT);
340 user_agent = (char*)apr_table_get(r->headers_in, HTTP_USER_AGENT);
344 if (qsp->ua_flag == UA_IGN)
345 spec = &v_ignore_spec;
347 spec = chxj_specified_device(r, user_agent);
349 DBG1(r,"found device_name=[%s]", spec->device_name);
350 DBG1(r, "User-Agent=[%s]", user_agent);
352 if (spec->width == 0 || spec->heigh == 0)
355 dst = s_create_blob_data(r, spec, qsp, (char*)*src, len);
359 DBG(r, "end chxj_exchange_image()");
365 s_img_conv_format_from_file(
367 mod_chxj_config* conf,
368 const char* user_agent,
369 query_string_param_t* qsp,
374 apr_finfo_t cache_st;
377 if (spec->html_spec_type == CHXJ_SPEC_UNKNOWN) {
379 * If ``ua'' parameter is specified, it must be CHXJ_SPEC_HTML.
381 return s_send_original_file(r, r->filename);
384 /*--------------------------------------------------------------------------*/
385 /* Create Workfile Name */
386 /*--------------------------------------------------------------------------*/
387 tmpfile = s_create_workfile(r, conf, user_agent, qsp);
388 DBG1(r,"workfile=[%s]", tmpfile);
390 rv = apr_stat(&st, r->filename, APR_FINFO_MIN, r->pool);
391 if (rv != APR_SUCCESS)
392 return HTTP_NOT_FOUND;
395 DBG1(r,"found [%s]", r->filename);
396 rv = apr_stat(&cache_st, tmpfile, APR_FINFO_MIN, r->pool);
397 DBG1(r,"found [%s]", r->filename);
399 if (rv != APR_SUCCESS || cache_st.ctime < st.mtime) {
400 /*------------------------------------------------------------------------*/
401 /* It tries to make the cash file when it doesn't exist or there is */
402 /* change time later since the making time of the cash file. */
403 /*------------------------------------------------------------------------*/
404 rv = s_create_cache_file(r,tmpfile, spec, &st, qsp);
409 DBG1(r,"color=[%d]", spec->color);
410 if (! r->header_only) {
411 rv = s_send_cache_file(spec, qsp,r, tmpfile);
416 rv = s_header_only_cache_file(spec, qsp, r, tmpfile);
420 apr_table_setn(r->headers_in, "CHXJ_IMG_CONV", "done");
422 DBG(r,"end chxj_img_conv_format");
429 s_create_cache_file(request_rec* r,
433 query_string_param_t *qsp)
437 apr_size_t writebyte;
439 img_conv_mode_t mode = qsp->mode;
441 char* writedata = NULL;
442 char* readdata = NULL;
447 MagickWand* magick_wand;
449 if ((*r->handler == 'c' || *r->handler == 'C')
450 && strcasecmp(r->handler, "chxj-qrcode") == 0) {
451 /*------------------------------------------------------------------------*/
452 /* QRCODEÍѤΥե¡¥¤¥ë¤Î¾ì¹ç */
453 /*------------------------------------------------------------------------*/
459 memset(&doc, 0, sizeof(Doc));
460 memset(&qrcode, 0, sizeof(qr_code_t));
462 doc.parse_mode = PARSE_MODE_CHTML;
466 qs_init_malloc(&doc);
468 root = qs_parse_file(&doc, r->filename);
470 chxj_qrcode_node_to_qrcode(&qrcode, root);
472 qs_all_free(&doc,QX_LOGMARK);
474 sts = chxj_qrcode_create_image_data(&qrcode, &readdata, &readbyte);
476 ERR(r, "qrcode create failed.");
481 /*------------------------------------------------------------------------*/
482 /* Ä̾ï¤Î¥¤¥á¡¼¥¸¥Õ¥¡¥¤¥ë¤Î¾ì¹ç */
483 /*------------------------------------------------------------------------*/
484 rv = apr_file_open(&fin,
486 APR_READ|APR_BINARY ,
489 if (rv != APR_SUCCESS) {
490 DBG1(r,"file open failed.[%s]", r->filename);
491 return HTTP_NOT_FOUND;
494 readdata = apr_palloc(r->pool, st->size);
495 rv = apr_file_read_full(fin, (void*)readdata, st->size, &readbyte);
496 if (rv != APR_SUCCESS || readbyte != st->size) {
497 DBG1(r,"file read failed.[%s]", r->filename);
500 return HTTP_NOT_FOUND;
503 DBG(r,"start img convert");
506 magick_wand = NewMagickWand();
507 if (MagickReadImageBlob(magick_wand,readdata, readbyte) == MagickFalse) {
509 return HTTP_NOT_FOUND;
512 if (spec->html_spec_type != CHXJ_SPEC_UNKNOWN) {
514 * The size of the image is changed.
516 DBG(r,"call s_fixup_size()");
518 if ((magick_wand = s_fixup_size(magick_wand, r, spec, qsp)) == NULL)
519 return HTTP_NOT_FOUND;
522 * The colors of the image is changed.
524 DBG(r,"call s_fixup_color()");
526 if ((magick_wand = s_fixup_color(magick_wand, r,spec, mode)) == NULL)
527 return HTTP_NOT_FOUND;
530 * DEPTH of the image is changed.
532 DBG(r,"call s_fixup_depth()");
534 if ((magick_wand = s_fixup_depth(magick_wand, r, spec)) == NULL)
535 return HTTP_NOT_FOUND;
539 DBG(r,"start convert and compression");
541 if (spec->available_jpeg) {
542 if (MagickSetImageCompression(magick_wand,JPEGCompression) == MagickFalse) {
544 return HTTP_NOT_FOUND;
547 if (MagickSetImageFormat(magick_wand, "jpg") == MagickFalse) {
549 return HTTP_NOT_FOUND;
552 if (MagickStripImage(magick_wand) == MagickFalse) {
554 return HTTP_NOT_FOUND;
557 if ((magick_wand = s_img_down_sizing(magick_wand, r, spec)) == NULL)
558 return HTTP_NOT_FOUND;
560 r->content_type = apr_psprintf(r->pool, "image/jpeg");
561 DBG(r,"convert to jpg");
564 if (spec->available_png) {
566 if (MagickSetImageCompression(magick_wand,ZipCompression) == MagickFalse) {
568 return HTTP_NOT_FOUND;
571 if (MagickSetImageFormat(magick_wand, "png") == MagickFalse) {
573 return HTTP_NOT_FOUND;
576 if (MagickStripImage(magick_wand) == MagickFalse) {
578 return HTTP_NOT_FOUND;
581 if ((magick_wand = s_img_down_sizing(magick_wand, r, spec)) == NULL)
582 return HTTP_NOT_FOUND;
584 r->content_type = apr_psprintf(r->pool, "image/png");
585 DBG(r, "convert to png");
588 if (spec->available_gif) {
590 if (MagickSetImageCompression(magick_wand,LZWCompression) == MagickFalse) {
592 return HTTP_NOT_FOUND;
595 if (MagickSetImageFormat(magick_wand, "gif") == MagickFalse) {
597 return HTTP_NOT_FOUND;
600 if (MagickStripImage(magick_wand) == MagickFalse) {
602 return HTTP_NOT_FOUND;
605 if ((magick_wand = s_img_down_sizing(magick_wand, r, spec)) == NULL)
606 return HTTP_NOT_FOUND;
608 r->content_type = apr_psprintf(r->pool, "image/gif");
610 DBG(r,"convert to gif");
613 if (spec->available_bmp2 || spec->available_bmp4) {
615 if (MagickSetImageCompression(magick_wand,NoCompression) == MagickFalse) {
617 return HTTP_NOT_FOUND;
620 if (MagickSetImageFormat(magick_wand, "bmp") == MagickFalse) {
622 return HTTP_NOT_FOUND;
625 if (MagickStripImage(magick_wand) == MagickFalse) {
627 return HTTP_NOT_FOUND;
630 if ((magick_wand = s_img_down_sizing(magick_wand, r, spec)) == NULL)
631 return HTTP_NOT_FOUND;
633 r->content_type = apr_psprintf(r->pool, "image/bmp");
635 DBG(r, "convert to bmp(unsupported)");
639 * Add Comment (Copyright and so on.)
641 DBG(r, "call s_add_copyright()");
643 if ((magick_wand = s_add_copyright(magick_wand, r, spec)) == NULL)
644 return HTTP_NOT_FOUND;
648 fmt = MagickGetImageFormat(magick_wand);
650 if (MagickSetImageFormat(magick_wand, "jpg") == MagickFalse) {
652 return HTTP_NOT_FOUND;
655 r->content_type = apr_psprintf(r->pool, "image/jpeg");
658 if (strcasecmp(fmt, "jpg") == 0) {
659 r->content_type = apr_psprintf(r->pool, "image/jpeg");
662 if (strcasecmp(fmt, "jpeg") == 0) {
663 r->content_type = apr_psprintf(r->pool, "image/jpeg");
666 if (strcasecmp(fmt, "gif") == 0) {
667 r->content_type = apr_psprintf(r->pool, "image/gif");
670 if (strcasecmp(fmt, "png") == 0) {
671 r->content_type = apr_psprintf(r->pool, "image/png");
676 writedata = (char*)MagickGetImageBlob(magick_wand, &writebyte);
679 DestroyMagickWand(magick_wand);
680 ERR1(r,"convert failure to Jpeg [%s]", tmpfile);
682 return HTTP_INTERNAL_SERVER_ERROR;
685 DBG(r, "end convert and compression");
688 rv = apr_file_open(&fout, tmpfile,
689 APR_WRITE| APR_CREATE | APR_BINARY | APR_SHARELOCK ,APR_OS_DEFAULT,
691 if (rv != APR_SUCCESS) {
692 DestroyMagickWand(magick_wand);
693 ERR1(r,"file open error.[%s]", tmpfile);
694 return HTTP_INTERNAL_SERVER_ERROR;
697 rv = apr_file_write(fout, (void*)writedata, &writebyte);
698 if (rv != APR_SUCCESS) {
699 DestroyMagickWand(magick_wand);
700 apr_file_close(fout);
701 return HTTP_INTERNAL_SERVER_ERROR;
705 * CRC is added for AU for EzGET.
707 if (spec->html_spec_type == CHXJ_SPEC_XHtml_Mobile_1_0
708 || spec->html_spec_type == CHXJ_SPEC_Hdml ) {
710 crc = s_add_crc(writedata, writebyte);
712 rv = apr_file_putc((crc >> 8) & 0xff, fout);
713 if (rv != APR_SUCCESS) {
714 DestroyMagickWand(magick_wand);
715 return HTTP_INTERNAL_SERVER_ERROR;
718 rv = apr_file_putc( crc & 0xff, fout);
719 if (rv != APR_SUCCESS) {
720 DestroyMagickWand(magick_wand);
721 return HTTP_INTERNAL_SERVER_ERROR;
725 DestroyMagickWand(magick_wand);
727 rv = apr_file_close(fout);
728 if (rv != APR_SUCCESS) {
729 DBG1(r,"file write error.[%s]", tmpfile);
730 return HTTP_INTERNAL_SERVER_ERROR;
738 s_create_blob_data(request_rec* r,
740 query_string_param_t *qsp,
744 apr_size_t writebyte;
746 img_conv_mode_t mode = qsp->mode;
748 char* writedata = NULL;
751 MagickWand* magick_wand;
753 magick_wand = NewMagickWand();
755 if (MagickReadImageBlob(magick_wand,indata, *len) == MagickFalse) {
761 * The size of the image is changed.
763 DBG(r, "call s_fixup_size()");
765 if ((magick_wand = s_fixup_size(magick_wand, r, spec, qsp)) == NULL)
769 * The colors of the image is changed.
771 DBG(r, "call s_fixup_color()");
773 if ((magick_wand = s_fixup_color(magick_wand, r,spec, mode)) == NULL)
777 * DEPTH of the image is changed.
780 DBG(r,"call s_fixup_depth()");
782 if ((magick_wand = s_fixup_depth(magick_wand, r, spec)) == NULL)
787 DBG(r,"start convert and compression");
789 if (spec->available_jpeg) {
790 if (MagickSetImageCompression(magick_wand,JPEGCompression) == MagickFalse) {
795 if (MagickSetImageFormat(magick_wand, "jpg") == MagickFalse) {
800 if (MagickStripImage(magick_wand) == MagickFalse) {
805 if ((magick_wand = s_img_down_sizing(magick_wand, r, spec)) == NULL)
808 r->content_type = apr_psprintf(r->pool, "image/jpeg");
810 DBG(r, "convert to jpg");
813 if (spec->available_png) {
814 if (MagickSetImageCompression(magick_wand,ZipCompression) == MagickFalse) {
819 if (MagickSetImageFormat(magick_wand, "png") == MagickFalse) {
824 if (MagickStripImage(magick_wand) == MagickFalse) {
829 if ((magick_wand = s_img_down_sizing(magick_wand, r, spec)) == NULL)
832 r->content_type = apr_psprintf(r->pool, "image/png");
834 DBG(r,"convert to png");
837 if (spec->available_gif) {
839 if (MagickSetImageCompression(magick_wand,LZWCompression) == MagickFalse) {
844 if (MagickSetImageFormat(magick_wand, "gif") == MagickFalse) {
849 if (MagickStripImage(magick_wand) == MagickFalse) {
854 if ((magick_wand = s_img_down_sizing(magick_wand, r, spec)) == NULL)
857 r->content_type = apr_psprintf(r->pool, "image/gif");
859 DBG(r,"convert to gif");
862 if (spec->available_bmp2 || spec->available_bmp4) {
863 if (MagickSetImageCompression(magick_wand,NoCompression) == MagickFalse) {
868 if (MagickSetImageFormat(magick_wand, "bmp") == MagickFalse) {
873 if (MagickStripImage(magick_wand) == MagickFalse) {
878 if ((magick_wand = s_img_down_sizing(magick_wand, r, spec)) == NULL)
881 r->content_type = apr_psprintf(r->pool, "image/bmp");
883 DBG(r,"convert to bmp(unsupported)");
885 /*--------------------------------------------------------------------------*/
886 /* Add Comment (Copyright and so on.) */
887 /*--------------------------------------------------------------------------*/
888 DBG(r,"call s_add_copyright()");
890 if ((magick_wand = s_add_copyright(magick_wand, r, spec)) == NULL)
893 writedata = (char*)MagickGetImageBlob(magick_wand, &writebyte);
896 DestroyMagickWand(magick_wand);
897 DBG(r,"convert failure to Jpeg ");
901 DBG(r,"end convert and compression");
905 dst = apr_palloc(r->pool, writebyte+2);
907 memcpy(dst, writedata, writebyte);
908 /*--------------------------------------------------------------------------*/
909 /* CRC is added for AU for EzGET. */
910 /*--------------------------------------------------------------------------*/
911 if (spec->html_spec_type == CHXJ_SPEC_XHtml_Mobile_1_0
912 || spec->html_spec_type == CHXJ_SPEC_Hdml) {
913 crc = s_add_crc(writedata, writebyte);
914 dst[writebyte + 0] = (crc >> 8) & 0xff;
915 dst[writebyte + 1] = (crc ) & 0xff;
919 DestroyMagickWand(magick_wand);
926 s_fixup_size(MagickWand* magick_wand,
929 query_string_param_t *qsp)
931 img_conv_mode_t mode = qsp->mode;
939 oldw = MagickGetImageWidth(magick_wand);
940 oldh = MagickGetImageHeight(magick_wand);
942 DBG1(r,"detect width=[%d]", oldw);
943 DBG1(r,"detect heigh=[%d]", oldh);
948 DBG1(r,"detect spec width=[%d]", spec->width);
949 DBG1(r,"detect spec heigh=[%d]", spec->heigh);
951 c_width = spec->width;
952 c_heigh = spec->heigh;
955 case IMG_CONV_MODE_THUMBNAIL:
957 DBG(r,"**** detect thumbnail mode ****");
959 if (neww > c_width) {
960 newh = (int)((double)newh * (double)((double)c_width / (double)neww));
961 neww = (int)((double)neww * (double)((double)c_width / (double)neww));
963 if (newh > c_heigh) {
964 neww = (int)((double)neww * (double)((double)c_heigh / (double)newh));
965 newh = (int)((double)newh * (double)((double)c_heigh / (double)newh));
968 neww = (int)((double)(neww / 3) * 0.8);
969 newh = (int)((double)(newh / 3) * 0.8);
972 case IMG_CONV_MODE_WALLPAPER:
973 case IMG_CONV_MODE_EZGET:
975 DBG(r,"**** detect wallpaper mode ****");
977 if (spec->wp_width && spec->wp_heigh) {
978 c_width = spec->wp_width;
979 c_heigh = spec->wp_heigh;
982 DBG(r,"calc new width and height");
984 neww = (int)((double)neww * (double)((double)c_heigh / (double)newh));
985 newh = (int)((double)newh * (double)((double)c_heigh / (double)newh));
987 DBG2(r,"newh = [%d] neww = [%d]", newh, neww);
992 DBG(r,"**** detect normal mode ****");
994 if (qsp->ua_flag != UA_IGN && spec->html_spec_type != CHXJ_SPEC_UNKNOWN) {
995 if (neww > c_width) {
996 newh = (int)((double)newh * (double)((double)c_width / (double)neww));
997 neww = (int)((double)neww * (double)((double)c_width / (double)neww));
1000 if (newh > c_heigh) {
1001 neww = (int)((double)neww * (double)((double)c_heigh / (double)newh));
1002 newh = (int)((double)newh * (double)((double)c_heigh / (double)newh));
1008 if (spec->html_spec_type != CHXJ_SPEC_UNKNOWN) {
1009 DBG2(r,"convert width=[%d --> %d]", oldw, neww);
1010 DBG2(r,"convert heigh=[%d --> %d]", oldh, newh);
1012 MagickResetIterator(magick_wand);
1014 while (MagickNextImage(magick_wand) != MagickFalse) {
1016 case IMG_CONV_MODE_WALLPAPER:
1017 case IMG_CONV_MODE_EZGET:
1019 if (MagickResizeImage(magick_wand,neww,newh,LanczosFilter,1.0) == MagickFalse) {
1020 EXIT_MAGICK_ERROR();
1024 if (MagickCropImage(magick_wand,
1025 (unsigned long)c_width,
1026 (unsigned long)c_heigh,
1027 (long)((neww - c_width) / 2),
1028 (long)((newh - c_heigh) / 2)) == MagickFalse) {
1029 EXIT_MAGICK_ERROR();
1034 case IMG_CONV_MODE_NORMAL:
1036 DBG2(r,"convert width=[%d --> %d]", neww, qsp->width);
1040 DBG2(r,"convert heigh=[%d --> %d]", newh, qsp->height);
1045 if (MagickResizeImage(magick_wand,neww,newh,LanczosFilter,1.0) == MagickFalse) {
1046 EXIT_MAGICK_ERROR();
1052 if (spec->html_spec_type != CHXJ_SPEC_UNKNOWN) {
1053 if (MagickSetImageUnits(magick_wand, PixelsPerInchResolution) == MagickFalse) {
1054 EXIT_MAGICK_ERROR();
1058 if (MagickSetImageResolution(magick_wand,
1059 (double)spec->dpi_width,
1060 (double)spec->dpi_heigh) == MagickFalse) {
1061 EXIT_MAGICK_ERROR();
1065 if (MagickSetImageDispose(magick_wand, BackgroundDispose) == MagickFalse) {
1066 EXIT_MAGICK_ERROR();
1076 s_fixup_color(MagickWand* magick_wand, request_rec* r, device_table* spec, img_conv_mode_t UNUSED(mode))
1078 DBG(r,"start chxj_fixup_clor()");
1080 if (spec->html_spec_type == CHXJ_SPEC_UNKNOWN) {
1081 DBG(r, "Pass s_fixup_color proc");
1085 if (spec->color >= 256) {
1087 DBG1(r,"call MagickQuantizeImage() spec->color=[%d]",spec->color);
1089 if (MagickQuantizeImage(magick_wand,
1094 0) == MagickFalse) {
1095 EXIT_MAGICK_ERROR();
1099 DBG1(r,"call end MagickQuantizeImage() spec->color=[%d]",spec->color);
1103 DBG1(r,"call MagickQuantizeImage() spec->color=[%d]",spec->color);
1105 if (MagickQuantizeImage(magick_wand,
1110 0) == MagickFalse) {
1111 EXIT_MAGICK_ERROR();
1115 DBG1(r,"call end MagickQuantizeImage() spec->color=[%d]",spec->color);
1119 DBG(r,"end chxj_fixup_clor()");
1127 s_fixup_depth(MagickWand* magick_wand, request_rec* r, device_table* spec)
1129 if (spec->html_spec_type == CHXJ_SPEC_UNKNOWN) {
1130 DBG(r, "Pass s_fixup_depth proc");
1134 if (spec->color == 15680000) {
1135 if (MagickSetImageDepth(magick_wand, 24) == MagickFalse) {
1136 EXIT_MAGICK_ERROR();
1141 if (spec->color == 262144) {
1142 if (MagickSetImageDepth(magick_wand, 18) == MagickFalse) {
1143 EXIT_MAGICK_ERROR();
1148 if (spec->color == 65536) {
1149 if (MagickSetImageDepth(magick_wand, 16) == MagickFalse) {
1150 EXIT_MAGICK_ERROR();
1155 if (spec->color == 4096) {
1156 if (MagickSetImageDepth(magick_wand, 12) == MagickFalse) {
1157 EXIT_MAGICK_ERROR();
1162 if (spec->color == 256) {
1163 if (MagickSetImageDepth(magick_wand, 8) == MagickFalse) {
1164 EXIT_MAGICK_ERROR();
1169 if (spec->color == 4) {
1170 if (MagickSetImageDepth(magick_wand, 2) == MagickFalse) {
1171 EXIT_MAGICK_ERROR();
1176 if (spec->color == 2) {
1177 if (MagickSetImageDepth(magick_wand, 1) == MagickFalse) {
1178 EXIT_MAGICK_ERROR();
1188 s_add_copyright(MagickWand* magick_wand, request_rec* r, device_table* spec)
1190 mod_chxj_config* conf = ap_get_module_config(r->per_dir_config, &chxj_module);
1192 if (spec->html_spec_type == CHXJ_SPEC_UNKNOWN) {
1193 DBG(r, "Pass add_copiright proc");
1197 if (conf->image_copyright) {
1199 DBG1(r, "Add COPYRIGHT [%s]", conf->image_copyright);
1201 if (spec->html_spec_type == CHXJ_SPEC_Jhtml) {
1202 apr_table_setn(r->headers_out, "x-jphone-copyright", "no-transfer");
1203 if (MagickCommentImage(magick_wand,
1204 apr_psprintf(r->pool,
1206 conf->image_copyright)) == MagickFalse)
1210 if (spec->html_spec_type == CHXJ_SPEC_XHtml_Mobile_1_0
1211 || spec->html_spec_type == CHXJ_SPEC_Hdml) {
1212 if (MagickCommentImage(magick_wand,
1213 apr_psprintf(r->pool,
1214 "kddi_copyright=on,%s",
1215 conf->image_copyright)) == MagickFalse)
1219 if (MagickCommentImage(magick_wand,
1220 apr_psprintf(r->pool,
1222 conf->image_copyright)) == MagickFalse)
1227 if (MagickCommentImage(magick_wand, "mod_chxj") == MagickFalse)
1233 EXIT_MAGICK_ERROR();
1238 s_img_down_sizing(MagickWand* magick_wand, request_rec* r, device_table* spec)
1240 MagickBooleanType status;
1241 unsigned long quality = 70;
1242 apr_size_t writebyte = 0;
1244 apr_size_t prev_size = 0;
1245 int revers_flag = 0;
1247 writedata = (char*)MagickGetImageBlob(magick_wand, &writebyte);
1248 prev_size = writebyte;
1251 if (MagickSetImageCompressionQuality(magick_wand, quality) == MagickFalse) {
1252 EXIT_MAGICK_ERROR();
1256 writedata = (char*)MagickGetImageBlob(magick_wand, &writebyte);
1257 if (writebyte >= prev_size || revers_flag) {
1258 DBG2(r, "quality=[%ld] size=[%d]", (long)quality, (int)writebyte);
1261 if (quality > 100) {
1262 if (MagickSetImageCompression(magick_wand,NoCompression) == MagickFalse) {
1263 EXIT_MAGICK_ERROR();
1268 prev_size = writebyte;
1272 DBG2(r, "quality=[%ld] size=[%d]", (long)quality, (int)writebyte);
1274 if (spec->cache == 0)
1277 if (writebyte <= (unsigned int)spec->cache)
1282 if (quality == 0 || quality > 100)
1290 && writebyte > (unsigned int)spec->cache) {
1291 unsigned long now_color = spec->color;
1292 unsigned long depth = 0;
1295 case 2: depth = 1; break;
1296 case 4: now_color = 2; depth = 1; break;
1297 case 8: now_color = 4; depth = 2; break;
1298 case 16: now_color = 8; depth = 3; break;
1299 case 256: now_color = 16; depth = 4; break;
1300 case 4096: now_color = 256; depth = 8; break;
1301 case 65536: now_color = 4096; depth = 12; break;
1302 case 262144: now_color = 65536; depth = 16; break;
1303 case 15680000: now_color = 262144; depth = 18; break;
1309 if (now_color <= 2) break;
1311 if (now_color >= 8) {
1312 status = MagickQuantizeImage(magick_wand,
1320 status = MagickQuantizeImage(magick_wand,
1326 MagickSetImageType(magick_wand, GrayscaleType);
1328 if (status == MagickFalse) {
1329 EXIT_MAGICK_ERROR();
1333 if (MagickSetImageDepth(magick_wand, depth) == MagickFalse) {
1334 EXIT_MAGICK_ERROR();
1338 writedata = (char*)MagickGetImageBlob(magick_wand, &writebyte);
1340 DBG2(r,"now_color=[%ld] size=[%d]", (long)now_color, (int)writebyte);
1342 /* Once per request */
1345 while(now_color > 2);
1352 s_send_cache_file(device_table* spec, query_string_param_t* query_string, request_rec* r, const char* tmpfile)
1357 apr_size_t sendbyte;
1358 char* contentLength;
1360 rv = apr_stat(&st, tmpfile, APR_FINFO_MIN, r->pool);
1361 if (rv != APR_SUCCESS)
1362 return HTTP_NOT_FOUND;
1364 DBG1(r, "mode:[%d]", query_string->mode);
1365 DBG1(r, "name:[%s]", query_string->name);
1366 DBG1(r, "offset:[%ld]", query_string->offset);
1367 DBG1(r, "count:[%ld]", query_string->count);
1369 if (spec->available_jpeg) {
1370 r->content_type = apr_psprintf(r->pool, "image/jpeg");
1373 if (spec->available_png) {
1374 r->content_type = apr_psprintf(r->pool, "image/png");
1377 if (spec->available_gif) {
1378 r->content_type = apr_psprintf(r->pool, "image/gif");
1381 if (spec->available_bmp2 || spec->available_bmp4) {
1382 r->content_type = apr_psprintf(r->pool, "image/bmp");
1385 if (query_string->mode != IMG_CONV_MODE_EZGET && query_string->name == NULL) {
1386 contentLength = apr_psprintf(r->pool, "%d", (int)st.size);
1387 apr_table_setn(r->headers_out, "Content-Length", (const char*)contentLength);
1389 DBG1(r,"Content-Length:[%d]", (int)st.size);
1391 rv = apr_file_open(&fout, tmpfile,
1392 APR_READ | APR_BINARY, APR_OS_DEFAULT, r->pool);
1393 if (rv != APR_SUCCESS) {
1394 DBG1(r, "tmpfile open failed[%s]", tmpfile);
1395 return HTTP_NOT_FOUND;
1398 ap_send_fd(fout, r, 0, st.size, &sendbyte);
1399 apr_file_close(fout);
1401 DBG1(r, "send file data[%d]byte", (int)sendbyte);
1404 if (query_string->mode == IMG_CONV_MODE_EZGET) {
1405 char* name = apr_pstrdup(r->pool, basename(r->filename));
1406 name[strlen(name)-4] = 0;
1407 if (strcasecmp(r->content_type, "image/jpeg") == 0) {
1409 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1410 ap_rprintf(r, HDML_FIRST_PAGE, r->uri, name, ".jpg", (long)st.size, "devjaww", name);
1413 if (strcasecmp(r->content_type, "image/bmp") == 0) {
1414 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1415 ap_rprintf(r, HDML_FIRST_PAGE, r->uri, name, ".bmp", (long)st.size, "devabm", name);
1418 if (strcasecmp(r->content_type, "image/png") == 0) {
1419 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1420 ap_rprintf(r, HDML_FIRST_PAGE, r->uri, name, ".png", (long)st.size, "dev8aww", name);
1423 if (strcasecmp(r->content_type, "image/gif") == 0) {
1424 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1425 ap_rprintf(r, HDML_FIRST_PAGE, r->uri, name, ".gif", (long)st.size, "devgi0z", name);
1429 if (query_string->mode == IMG_CONV_MODE_WALLPAPER && query_string->name != NULL) {
1430 if (query_string->count == -1 && query_string->offset == -1) {
1431 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1432 ap_rprintf(r, HDML_SUCCESS_PAGE);
1436 if (query_string->count == -2 && query_string->offset == -1) {
1437 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1438 ap_rprintf(r, HDML_FAIL_PAGE);
1442 ap_set_content_type(r, "application/x-up-download");
1443 contentLength = apr_psprintf(r->pool, "%ld", query_string->count);
1444 apr_table_setn(r->headers_out, "Content-Length", (const char*)contentLength);
1446 DBG1(r, "Content-Length:[%d]", (int)st.size);
1448 rv = apr_file_open(&fout, tmpfile,
1449 APR_READ | APR_BINARY, APR_OS_DEFAULT, r->pool);
1451 if (rv != APR_SUCCESS) {
1452 DBG1(r,"tmpfile open failed[%s]", tmpfile);
1453 return HTTP_NOT_FOUND;
1456 ap_send_fd(fout, r, query_string->offset, query_string->count, &sendbyte);
1457 apr_file_close(fout);
1459 DBG1(r, "send file data[%d]byte", (int)sendbyte);
1468 s_send_original_file(request_rec* r, const char* originalfile)
1473 apr_size_t sendbyte = 0;
1475 rv = apr_stat(&st, originalfile, APR_FINFO_MIN, r->pool);
1476 if (rv != APR_SUCCESS)
1477 return HTTP_NOT_FOUND;
1479 rv = apr_file_open(&fout, originalfile,
1480 APR_READ | APR_BINARY, APR_OS_DEFAULT, r->pool);
1481 if (rv != APR_SUCCESS) {
1482 DBG1(r, "originalfile open failed[%s]", originalfile);
1483 return HTTP_NOT_FOUND;
1486 ap_send_fd(fout, r, 0, st.size, &sendbyte);
1487 apr_file_close(fout);
1489 DBG1(r, "send file data[%d]byte", (int)sendbyte);
1495 s_header_only_cache_file(device_table* spec, query_string_param_t* query_string, request_rec* r, const char* tmpfile)
1499 char* contentLength;
1501 rv = apr_stat(&st, tmpfile, APR_FINFO_MIN, r->pool);
1502 if (rv != APR_SUCCESS)
1503 return HTTP_NOT_FOUND;
1505 DBG1(r, "mode:[%d]", query_string->mode);
1506 DBG1(r, "name:[%s]", query_string->name);
1507 DBG1(r, "offset:[%ld]", query_string->offset);
1508 DBG1(r, "count:[%ld]", query_string->count);
1510 if (spec->available_jpeg) {
1511 r->content_type = apr_psprintf(r->pool, "image/jpeg");
1514 if (spec->available_png) {
1515 r->content_type = apr_psprintf(r->pool, "image/png");
1518 if (spec->available_gif) {
1519 r->content_type = apr_psprintf(r->pool, "image/gif");
1522 if (spec->available_bmp2 || spec->available_bmp4) {
1523 r->content_type = apr_psprintf(r->pool, "image/bmp");
1526 if (query_string->mode != IMG_CONV_MODE_EZGET && query_string->name == NULL) {
1527 contentLength = apr_psprintf(r->pool, "%d", (int)st.size);
1528 apr_table_setn(r->headers_out, "Content-Length", (const char*)contentLength);
1530 DBG1(r,"Content-Length:[%d]", (int)st.size);
1533 if (query_string->mode == IMG_CONV_MODE_EZGET) {
1534 char* name = apr_pstrdup(r->pool, basename(r->filename));
1535 name[strlen(name)-4] = 0;
1536 if (strcasecmp(r->content_type, "image/jpeg") == 0) {
1538 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1541 if (strcasecmp(r->content_type, "image/bmp") == 0) {
1542 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1545 if (strcasecmp(r->content_type, "image/png") == 0) {
1546 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1549 if (strcasecmp(r->content_type, "image/gif") == 0) {
1550 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1554 if (query_string->mode == IMG_CONV_MODE_WALLPAPER && query_string->name != NULL) {
1555 if (query_string->count == -1 && query_string->offset == -1) {
1556 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1559 if (query_string->count == -2 && query_string->offset == -1) {
1560 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1563 ap_set_content_type(r, "application/x-up-download");
1564 contentLength = apr_psprintf(r->pool, "%ld", query_string->count);
1565 apr_table_setn(r->headers_out, "Content-Length", (const char*)contentLength);
1567 DBG1(r, "Content-Length:[%d]", (int)st.size);
1579 mod_chxj_config* conf,
1580 const char* user_agent,
1581 query_string_param_t *qsp)
1586 char* w = apr_palloc(r->pool, 256);
1590 switch (qsp->mode) {
1591 case IMG_CONV_MODE_THUMBNAIL:
1592 fname = apr_psprintf(r->pool, "%s.%s.thumbnail", r->filename, user_agent);
1593 DBG1(r, "mode=thumbnail [%s]", fname);
1595 case IMG_CONV_MODE_WALLPAPER:
1596 case IMG_CONV_MODE_EZGET:
1597 fname = apr_psprintf(r->pool, "%s.%s.wallpaper", r->filename, user_agent);
1598 DBG1(r, "mode=WallPaper [%s]", fname);
1600 case IMG_CONV_MODE_NORMAL:
1603 fname = apr_psprintf(r->pool, "%s.%s", r->filename, user_agent);
1606 fname = apr_psprintf(r->pool, "%s.w%d", fname, qsp->width);
1609 fname = apr_psprintf(r->pool, "%s.h%d", fname, qsp->height);
1611 DBG1(r,"mode=normal [%s]", fname);
1614 if (qsp->ua_flag == UA_IGN) {
1615 fname = apr_psprintf(r->pool, "%s.IGN", fname);
1618 len = strlen(fname);
1620 for (ii=0; ii<len; ii++) {
1621 if (fname[ii] == '/'
1625 || fname[ii] == ')') {
1629 w[jj++] = fname[ii];
1633 return apr_psprintf(r->pool, "%s/%s", conf->image_cache_dir,w);
1636 static unsigned short
1637 s_add_crc(const char* writedata, apr_size_t writebyte)
1639 unsigned short crc = 0xffff;
1643 for(ii=0;ii<writebyte;ii++) {
1645 crc = AU_CRC_TBL[(crc>>8^ch)&0xff]^(crc<<8);
1651 chxj_trans_name(request_rec *r)
1658 mod_chxj_config* conf;
1666 "qrc", /* QRCode½ÐÎÏÍÑ¥Õ¥¡¥¤¥ë¤Î³ÈÄ¥»Ò */
1672 int do_ext_check = TRUE;
1673 int next_ok = FALSE;
1675 DBG(r, "start chxj_trans_name()");
1677 conf = ap_get_module_config(r->per_dir_config, &chxj_module);
1680 DBG1(r, "end chxj_trans_name() conf is null[%s]", r->uri);
1684 if (conf->image != CHXJ_IMG_ON) {
1685 DBG(r, "end chxj_trans_name() conf not found");
1690 DBG1(r,"Match URI[%s]", r->uri);
1693 if (r->filename == NULL)
1694 r->filename = apr_pstrdup(r->pool, r->uri);
1697 if ((idx = strchr(r->filename, ':')) != NULL)
1698 filename_sv = idx+1;
1700 filename_sv = r->filename;
1702 DBG1(r,"r->filename[%s]", filename_sv);
1704 ccp = ap_document_root(r);
1706 return HTTP_INTERNAL_SERVER_ERROR;
1708 docroot = apr_pstrdup(r->pool, ccp);
1709 len = strlen(docroot);
1711 if (docroot[len-1] == '/')
1712 docroot[len-1] = '\0';
1716 && *filename_sv == *r->server->path
1717 && strncmp(filename_sv, r->server->path, r->server->pathlen) == 0)
1718 filename_sv = apr_pstrcat(r->pool, docroot, (filename_sv + r->server->pathlen), NULL);
1720 filename_sv = apr_pstrcat(r->pool, docroot, filename_sv, NULL);
1722 DBG1(r,"URI[%s]", filename_sv);
1724 do_ext_check = TRUE;
1725 for (ii=0; ii<7-1; ii++) {
1726 char* pos = strrchr(filename_sv, '.');
1728 if (strcasecmp(pos, ext[ii]) == 0) {
1729 do_ext_check = FALSE;
1730 fname = apr_psprintf(r->pool, "%s", filename_sv);
1737 for (ii=0; ii<7; ii++) {
1738 if (strlen(ext[ii]) == 0) {
1739 fname = apr_psprintf(r->pool, "%s", filename_sv);
1742 fname = apr_psprintf(r->pool, "%s.%s", filename_sv, ext[ii]);
1744 DBG1(r,"search [%s]", fname);
1746 rv = apr_stat(&st, fname, APR_FINFO_MIN, r->pool);
1747 if (rv == APR_SUCCESS) {
1748 if (st.filetype != APR_DIR)
1755 if (fname == NULL) {
1756 DBG1(r,"NotFound [%s]", r->filename);
1759 for (ii=0; ii<7-1; ii++) {
1760 char* pos = strrchr(fname, '.');
1762 if (strcasecmp(pos, ext[ii]) == 0) {
1770 DBG1(r,"NotFound [%s]", r->filename);
1774 if (r->handler == NULL || strcasecmp(r->handler, "chxj-qrcode") != 0) {
1775 DBG1(r,"Found [%s]", fname);
1777 r->filename = apr_psprintf(r->pool, "%s", fname);
1779 if (strcasecmp("qrc", ext[ii]) == 0)
1780 r->handler = apr_psprintf(r->pool, "chxj-qrcode");
1782 r->handler = apr_psprintf(r->pool, "chxj-picture");
1784 DBG(r, "end chxj_trans_name()");
1791 * It converts it from QUERYSTRING.
1795 static query_string_param_t*
1796 s_get_query_string_param(request_rec *r)
1804 query_string_param_t* param;
1806 s = apr_pstrdup(r->pool, r->parsed_uri.query);
1807 param = apr_palloc(r->pool, sizeof(query_string_param_t));
1808 param->mode = IMG_CONV_MODE_NORMAL;
1809 param->user_agent = NULL;
1810 param->ua_flag = UA_USE;
1817 if (s == NULL) return param;
1820 if ((pair = apr_strtok(s, "&", &pstate)) == NULL) break;
1823 name = apr_strtok(pair, "=", &vstate);
1824 value = apr_strtok(NULL, "=", &vstate);
1829 if (value && (strcasecmp(name, "mode") == 0 || strcasecmp(name, "m") == 0)) {
1834 if (strcasecmp(value, "thumbnail") == 0 || strcasecmp(value, "tb") == 0)
1835 param->mode = IMG_CONV_MODE_THUMBNAIL;
1840 if (strcasecmp(value, "WP") == 0 || strcasecmp(value, "WallPaper") == 0)
1841 param->mode = IMG_CONV_MODE_WALLPAPER;
1846 if (strcasecmp(value, "EZGET") == 0)
1847 param->mode = IMG_CONV_MODE_EZGET;
1857 if (value && (strcasecmp(name, "ua") == 0 || strcasecmp(name, "user-agent") == 0)) {
1858 ap_unescape_url(value);
1860 if ((*value == 'i' || *value == 'I') && strcasecmp(value, "IGN") == 0)
1861 param->ua_flag = UA_IGN;
1863 param->user_agent = apr_pstrdup(r->pool, value);
1869 if (value && strcasecmp(name, "name") == 0)
1870 param->name = apr_pstrdup(r->pool, value);
1875 if (value && strcasecmp(name, "offset") == 0 && (! chxj_chk_numeric(value)))
1876 param->offset = chxj_atoi(value);
1882 if (value && strcasecmp(name, "count") == 0 && (! chxj_chk_numeric(value)))
1883 param->count = chxj_atoi(value);
1888 if (value && strcasecmp(name, "w") == 0 && (! chxj_chk_numeric(value)))
1889 param->width = chxj_atoi(value);
1894 if (value && strcasecmp(name, "h") == 0 && (! chxj_chk_numeric(value)))
1895 param->height = chxj_atoi(value);
1903 if (param->mode == IMG_CONV_MODE_NORMAL && param->name)
1904 param->mode = IMG_CONV_MODE_WALLPAPER;