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_header_only_cache_file(device_table* spec,
181 query_string_param_t* query_string,
183 const char* tmpfile);
185 static query_string_param_t* s_get_query_string_param(request_rec *r);
187 static unsigned short s_add_crc( const char* writedata,
188 apr_size_t witebyte);
190 static MagickWand* s_fixup_size(MagickWand* ,
193 query_string_param_t *qsp);
195 static MagickWand* s_fixup_color(MagickWand* magick_wand,
198 img_conv_mode_t mode);
199 static MagickWand* s_fixup_depth(MagickWand* magick_wand,
200 request_rec* r, device_table* spec);
201 static MagickWand* s_img_down_sizing(MagickWand* magick_wand,
202 request_rec* r, device_table* spec);
204 static MagickWand* s_add_copyright(MagickWand* magick_wand,
208 static char* s_create_blob_data(request_rec* r,
210 query_string_param_t* qsp,
214 static int s_img_conv_format_from_file(request_rec* r,
215 mod_chxj_config* conf,
216 const char* user_agent,
217 query_string_param_t* qsp,
223 chxj_img_conv_format_handler(request_rec* r)
225 mod_chxj_config* conf;
226 query_string_param_t* qsp;
229 chxjconvrule_entry* entryp;
231 DBG(r, "start chxj_img_conv_format_handler()");
233 if ((*r->handler != 'c' && *r->handler != 'C')
234 || (strcasecmp(r->handler, "chxj-picture")
235 && strcasecmp(r->handler, "chxj-qrcode"))) {
236 DBG(r, "end chxj_img_conv_format_handler()");
240 qsp = s_get_query_string_param(r);
241 conf = ap_get_module_config(r->per_dir_config, &chxj_module);
243 DBG(r, "end chxj_img_conv_format_handler() conf is null");
247 if (strcasecmp(r->handler, "chxj-qrcode") == 0 && conf->image == CHXJ_IMG_OFF) {
252 /*------------------------------------------------------------------------*/
253 /* get UserAgent from http header */
254 /*------------------------------------------------------------------------*/
255 /*--------------------------------------------------------------------------*/
256 /* User-Agent to spec */
257 /*--------------------------------------------------------------------------*/
258 if (qsp->user_agent) {
259 user_agent = apr_pstrdup(r->pool, qsp->user_agent);
262 entryp = chxj_apply_convrule(r, conf->convrules);
263 if (entryp && entryp->user_agent) {
264 user_agent = (char*)apr_table_get(r->headers_in, CHXJ_HTTP_USER_AGENT);
267 user_agent = (char*)apr_table_get(r->headers_in, HTTP_USER_AGENT);
273 if (qsp->ua_flag == UA_IGN)
274 spec = &v_ignore_spec;
276 spec = chxj_specified_device(r, user_agent);
278 DBG1(r,"found device_name=[%s]", spec->device_name);
279 DBG1(r,"User-Agent=[%s]", user_agent);
282 if (spec->width == 0 || spec->heigh == 0)
286 return s_img_conv_format_from_file(r, conf, user_agent, qsp, spec);
292 * It converts it from ImageData corresponding to each model.
295 * @param src [i] It is former image binary data.
296 * @param len [i/o] It is length of former image binary data.
299 chxj_exchange_image(request_rec *r, const char** src, apr_size_t* len)
301 mod_chxj_config* conf;
302 query_string_param_t* qsp;
307 chxjconvrule_entry* entryp;
309 DBG(r, "start chxj_exchange_image()");
311 conv_check = (char*)apr_table_get(r->headers_in, "CHXJ_IMG_CONV");
313 DBG(r, "end chxj_exchnage_image() already convert.");
318 qsp = s_get_query_string_param(r);
319 conf = ap_get_module_config(r->per_dir_config, &chxj_module);
321 DBG(r, "end chxj_exchange_image()");
325 /*--------------------------------------------------------------------------*/
326 /* User-Agent to spec */
327 /*--------------------------------------------------------------------------*/
328 if (qsp->user_agent) {
329 user_agent = apr_pstrdup(r->pool, qsp->user_agent);
332 entryp = chxj_apply_convrule(r, conf->convrules);
333 if (entryp && entryp->user_agent) {
334 user_agent = (char*)apr_table_get(r->headers_in, CHXJ_HTTP_USER_AGENT);
337 user_agent = (char*)apr_table_get(r->headers_in, HTTP_USER_AGENT);
341 if (qsp->ua_flag == UA_IGN)
342 spec = &v_ignore_spec;
344 spec = chxj_specified_device(r, user_agent);
346 DBG1(r,"found device_name=[%s]", spec->device_name);
347 DBG1(r, "User-Agent=[%s]", user_agent);
349 if (spec->width == 0 || spec->heigh == 0)
352 dst = s_create_blob_data(r, spec, qsp, (char*)*src, len);
356 DBG(r, "end chxj_exchange_image()");
362 s_img_conv_format_from_file(
364 mod_chxj_config* conf,
365 const char* user_agent,
366 query_string_param_t* qsp,
371 apr_finfo_t cache_st;
374 /*--------------------------------------------------------------------------*/
375 /* Create Workfile Name */
376 /*--------------------------------------------------------------------------*/
377 tmpfile = s_create_workfile(r, conf, user_agent, qsp);
378 DBG1(r,"workfile=[%s]", tmpfile);
380 rv = apr_stat(&st, r->filename, APR_FINFO_MIN, r->pool);
381 if (rv != APR_SUCCESS)
382 return HTTP_NOT_FOUND;
385 DBG1(r,"found [%s]", r->filename);
386 rv = apr_stat(&cache_st, tmpfile, APR_FINFO_MIN, r->pool);
387 DBG1(r,"found [%s]", r->filename);
389 if (rv != APR_SUCCESS || cache_st.ctime < st.mtime) {
390 /*------------------------------------------------------------------------*/
391 /* It tries to make the cash file when it doesn't exist or there is */
392 /* change time later since the making time of the cash file. */
393 /*------------------------------------------------------------------------*/
394 rv = s_create_cache_file(r,tmpfile, spec, &st, qsp);
399 DBG1(r,"color=[%d]", spec->color);
400 if (! r->header_only) {
401 rv = s_send_cache_file(spec, qsp,r, tmpfile);
406 rv = s_header_only_cache_file(spec, qsp, r, tmpfile);
410 apr_table_setn(r->headers_in, "CHXJ_IMG_CONV", "done");
412 DBG(r,"end chxj_img_conv_format");
419 s_create_cache_file(request_rec* r,
423 query_string_param_t *qsp)
427 apr_size_t writebyte;
429 img_conv_mode_t mode = qsp->mode;
431 char* writedata = NULL;
432 char* readdata = NULL;
437 MagickWand* magick_wand;
439 if ((*r->handler == 'c' || *r->handler == 'C')
440 && strcasecmp(r->handler, "chxj-qrcode") == 0) {
441 /*------------------------------------------------------------------------*/
442 /* QRCODEÍѤΥե¡¥¤¥ë¤Î¾ì¹ç */
443 /*------------------------------------------------------------------------*/
449 memset(&doc, 0, sizeof(Doc));
450 memset(&qrcode, 0, sizeof(qr_code_t));
452 doc.parse_mode = PARSE_MODE_CHTML;
456 qs_init_malloc(&doc);
458 root = qs_parse_file(&doc, r->filename);
460 chxj_qrcode_node_to_qrcode(&qrcode, root);
462 qs_all_free(&doc,QX_LOGMARK);
464 sts = chxj_qrcode_create_image_data(&qrcode, &readdata, &readbyte);
466 ERR(r, "qrcode create failed.");
471 /*------------------------------------------------------------------------*/
472 /* Ä̾ï¤Î¥¤¥á¡¼¥¸¥Õ¥¡¥¤¥ë¤Î¾ì¹ç */
473 /*------------------------------------------------------------------------*/
474 rv = apr_file_open(&fin,
476 APR_READ|APR_BINARY ,
479 if (rv != APR_SUCCESS) {
480 DBG1(r,"file open failed.[%s]", r->filename);
481 return HTTP_NOT_FOUND;
484 readdata = apr_palloc(r->pool, st->size);
485 rv = apr_file_read_full(fin, (void*)readdata, st->size, &readbyte);
486 if (rv != APR_SUCCESS || readbyte != st->size) {
487 DBG1(r,"file read failed.[%s]", r->filename);
490 return HTTP_NOT_FOUND;
493 DBG(r,"start img convert");
496 magick_wand = NewMagickWand();
497 if (MagickReadImageBlob(magick_wand,readdata, readbyte) == MagickFalse) {
499 return HTTP_NOT_FOUND;
502 if (spec->html_spec_type != CHXJ_SPEC_UNKNOWN) {
504 * The size of the image is changed.
506 DBG(r,"call s_fixup_size()");
508 if ((magick_wand = s_fixup_size(magick_wand, r, spec, qsp)) == NULL)
509 return HTTP_NOT_FOUND;
512 * The colors of the image is changed.
514 DBG(r,"call s_fixup_color()");
516 if ((magick_wand = s_fixup_color(magick_wand, r,spec, mode)) == NULL)
517 return HTTP_NOT_FOUND;
520 * DEPTH of the image is changed.
522 DBG(r,"call s_fixup_depth()");
524 if ((magick_wand = s_fixup_depth(magick_wand, r, spec)) == NULL)
525 return HTTP_NOT_FOUND;
529 DBG(r,"start convert and compression");
531 if (spec->available_jpeg) {
532 if (MagickSetImageCompression(magick_wand,JPEGCompression) == MagickFalse) {
534 return HTTP_NOT_FOUND;
537 if (MagickSetImageFormat(magick_wand, "jpg") == MagickFalse) {
539 return HTTP_NOT_FOUND;
542 if (MagickStripImage(magick_wand) == MagickFalse) {
544 return HTTP_NOT_FOUND;
547 if ((magick_wand = s_img_down_sizing(magick_wand, r, spec)) == NULL)
548 return HTTP_NOT_FOUND;
550 r->content_type = apr_psprintf(r->pool, "image/jpeg");
551 DBG(r,"convert to jpg");
554 if (spec->available_png) {
556 if (MagickSetImageCompression(magick_wand,ZipCompression) == MagickFalse) {
558 return HTTP_NOT_FOUND;
561 if (MagickSetImageFormat(magick_wand, "png") == MagickFalse) {
563 return HTTP_NOT_FOUND;
566 if (MagickStripImage(magick_wand) == MagickFalse) {
568 return HTTP_NOT_FOUND;
571 if ((magick_wand = s_img_down_sizing(magick_wand, r, spec)) == NULL)
572 return HTTP_NOT_FOUND;
574 r->content_type = apr_psprintf(r->pool, "image/png");
575 DBG(r, "convert to png");
578 if (spec->available_gif) {
580 if (MagickSetImageCompression(magick_wand,LZWCompression) == MagickFalse) {
582 return HTTP_NOT_FOUND;
585 if (MagickSetImageFormat(magick_wand, "gif") == MagickFalse) {
587 return HTTP_NOT_FOUND;
590 if (MagickStripImage(magick_wand) == MagickFalse) {
592 return HTTP_NOT_FOUND;
595 if ((magick_wand = s_img_down_sizing(magick_wand, r, spec)) == NULL)
596 return HTTP_NOT_FOUND;
598 r->content_type = apr_psprintf(r->pool, "image/gif");
600 DBG(r,"convert to gif");
603 if (spec->available_bmp2 || spec->available_bmp4) {
605 if (MagickSetImageCompression(magick_wand,NoCompression) == MagickFalse) {
607 return HTTP_NOT_FOUND;
610 if (MagickSetImageFormat(magick_wand, "bmp") == MagickFalse) {
612 return HTTP_NOT_FOUND;
615 if (MagickStripImage(magick_wand) == MagickFalse) {
617 return HTTP_NOT_FOUND;
620 if ((magick_wand = s_img_down_sizing(magick_wand, r, spec)) == NULL)
621 return HTTP_NOT_FOUND;
623 r->content_type = apr_psprintf(r->pool, "image/bmp");
625 DBG(r, "convert to bmp(unsupported)");
629 * Add Comment (Copyright and so on.)
631 DBG(r, "call s_add_copyright()");
633 if ((magick_wand = s_add_copyright(magick_wand, r, spec)) == NULL)
634 return HTTP_NOT_FOUND;
638 fmt = MagickGetImageFormat(magick_wand);
640 if (MagickSetImageFormat(magick_wand, "jpg") == MagickFalse) {
642 return HTTP_NOT_FOUND;
645 r->content_type = apr_psprintf(r->pool, "image/jpeg");
648 if (strcasecmp(fmt, "jpg") == 0) {
649 r->content_type = apr_psprintf(r->pool, "image/jpeg");
652 if (strcasecmp(fmt, "jpeg") == 0) {
653 r->content_type = apr_psprintf(r->pool, "image/jpeg");
656 if (strcasecmp(fmt, "gif") == 0) {
657 r->content_type = apr_psprintf(r->pool, "image/gif");
660 if (strcasecmp(fmt, "png") == 0) {
661 r->content_type = apr_psprintf(r->pool, "image/png");
666 writedata = (char*)MagickGetImageBlob(magick_wand, &writebyte);
669 DestroyMagickWand(magick_wand);
670 ERR1(r,"convert failure to Jpeg [%s]", tmpfile);
672 return HTTP_INTERNAL_SERVER_ERROR;
675 DBG(r, "end convert and compression");
678 rv = apr_file_open(&fout, tmpfile,
679 APR_WRITE| APR_CREATE | APR_BINARY | APR_SHARELOCK ,APR_OS_DEFAULT,
681 if (rv != APR_SUCCESS) {
682 DestroyMagickWand(magick_wand);
683 ERR1(r,"file open error.[%s]", tmpfile);
684 return HTTP_INTERNAL_SERVER_ERROR;
687 rv = apr_file_write(fout, (void*)writedata, &writebyte);
688 if (rv != APR_SUCCESS) {
689 DestroyMagickWand(magick_wand);
690 apr_file_close(fout);
691 return HTTP_INTERNAL_SERVER_ERROR;
695 * CRC is added for AU for EzGET.
697 if (spec->html_spec_type == CHXJ_SPEC_XHtml_Mobile_1_0
698 || spec->html_spec_type == CHXJ_SPEC_Hdml ) {
700 crc = s_add_crc(writedata, writebyte);
702 rv = apr_file_putc((crc >> 8) & 0xff, fout);
703 if (rv != APR_SUCCESS) {
704 DestroyMagickWand(magick_wand);
705 return HTTP_INTERNAL_SERVER_ERROR;
708 rv = apr_file_putc( crc & 0xff, fout);
709 if (rv != APR_SUCCESS) {
710 DestroyMagickWand(magick_wand);
711 return HTTP_INTERNAL_SERVER_ERROR;
715 DestroyMagickWand(magick_wand);
717 rv = apr_file_close(fout);
718 if (rv != APR_SUCCESS) {
719 DBG1(r,"file write error.[%s]", tmpfile);
720 return HTTP_INTERNAL_SERVER_ERROR;
728 s_create_blob_data(request_rec* r,
730 query_string_param_t *qsp,
734 apr_size_t writebyte;
736 img_conv_mode_t mode = qsp->mode;
738 char* writedata = NULL;
741 MagickWand* magick_wand;
743 magick_wand = NewMagickWand();
745 if (MagickReadImageBlob(magick_wand,indata, *len) == MagickFalse) {
751 * The size of the image is changed.
753 DBG(r, "call s_fixup_size()");
755 if ((magick_wand = s_fixup_size(magick_wand, r, spec, qsp)) == NULL)
759 * The colors of the image is changed.
761 DBG(r, "call s_fixup_color()");
763 if ((magick_wand = s_fixup_color(magick_wand, r,spec, mode)) == NULL)
767 * DEPTH of the image is changed.
770 DBG(r,"call s_fixup_depth()");
772 if ((magick_wand = s_fixup_depth(magick_wand, r, spec)) == NULL)
777 DBG(r,"start convert and compression");
779 if (spec->available_jpeg) {
780 if (MagickSetImageCompression(magick_wand,JPEGCompression) == MagickFalse) {
785 if (MagickSetImageFormat(magick_wand, "jpg") == MagickFalse) {
790 if (MagickStripImage(magick_wand) == MagickFalse) {
795 if ((magick_wand = s_img_down_sizing(magick_wand, r, spec)) == NULL)
798 r->content_type = apr_psprintf(r->pool, "image/jpeg");
800 DBG(r, "convert to jpg");
803 if (spec->available_png) {
804 if (MagickSetImageCompression(magick_wand,ZipCompression) == MagickFalse) {
809 if (MagickSetImageFormat(magick_wand, "png") == MagickFalse) {
814 if (MagickStripImage(magick_wand) == MagickFalse) {
819 if ((magick_wand = s_img_down_sizing(magick_wand, r, spec)) == NULL)
822 r->content_type = apr_psprintf(r->pool, "image/png");
824 DBG(r,"convert to png");
827 if (spec->available_gif) {
829 if (MagickSetImageCompression(magick_wand,LZWCompression) == MagickFalse) {
834 if (MagickSetImageFormat(magick_wand, "gif") == MagickFalse) {
839 if (MagickStripImage(magick_wand) == MagickFalse) {
844 if ((magick_wand = s_img_down_sizing(magick_wand, r, spec)) == NULL)
847 r->content_type = apr_psprintf(r->pool, "image/gif");
849 DBG(r,"convert to gif");
852 if (spec->available_bmp2 || spec->available_bmp4) {
853 if (MagickSetImageCompression(magick_wand,NoCompression) == MagickFalse) {
858 if (MagickSetImageFormat(magick_wand, "bmp") == MagickFalse) {
863 if (MagickStripImage(magick_wand) == MagickFalse) {
868 if ((magick_wand = s_img_down_sizing(magick_wand, r, spec)) == NULL)
871 r->content_type = apr_psprintf(r->pool, "image/bmp");
873 DBG(r,"convert to bmp(unsupported)");
875 /*--------------------------------------------------------------------------*/
876 /* Add Comment (Copyright and so on.) */
877 /*--------------------------------------------------------------------------*/
878 DBG(r,"call s_add_copyright()");
880 if ((magick_wand = s_add_copyright(magick_wand, r, spec)) == NULL)
883 writedata = (char*)MagickGetImageBlob(magick_wand, &writebyte);
886 DestroyMagickWand(magick_wand);
887 DBG(r,"convert failure to Jpeg ");
891 DBG(r,"end convert and compression");
895 dst = apr_palloc(r->pool, writebyte+2);
897 memcpy(dst, writedata, writebyte);
898 /*--------------------------------------------------------------------------*/
899 /* CRC is added for AU for EzGET. */
900 /*--------------------------------------------------------------------------*/
901 if (spec->html_spec_type == CHXJ_SPEC_XHtml_Mobile_1_0
902 || spec->html_spec_type == CHXJ_SPEC_Hdml) {
903 crc = s_add_crc(writedata, writebyte);
904 dst[writebyte + 0] = (crc >> 8) & 0xff;
905 dst[writebyte + 1] = (crc ) & 0xff;
909 DestroyMagickWand(magick_wand);
916 s_fixup_size(MagickWand* magick_wand,
919 query_string_param_t *qsp)
921 img_conv_mode_t mode = qsp->mode;
929 oldw = MagickGetImageWidth(magick_wand);
930 oldh = MagickGetImageHeight(magick_wand);
932 DBG1(r,"detect width=[%d]", oldw);
933 DBG1(r,"detect heigh=[%d]", oldh);
938 DBG1(r,"detect spec width=[%d]", spec->width);
939 DBG1(r,"detect spec heigh=[%d]", spec->heigh);
941 c_width = spec->width;
942 c_heigh = spec->heigh;
945 case IMG_CONV_MODE_THUMBNAIL:
947 DBG(r,"**** detect thumbnail mode ****");
949 if (neww > c_width) {
950 newh = (int)((double)newh * (double)((double)c_width / (double)neww));
951 neww = (int)((double)neww * (double)((double)c_width / (double)neww));
953 if (newh > c_heigh) {
954 neww = (int)((double)neww * (double)((double)c_heigh / (double)newh));
955 newh = (int)((double)newh * (double)((double)c_heigh / (double)newh));
958 neww = (int)((double)(neww / 3) * 0.8);
959 newh = (int)((double)(newh / 3) * 0.8);
962 case IMG_CONV_MODE_WALLPAPER:
963 case IMG_CONV_MODE_EZGET:
965 DBG(r,"**** detect wallpaper mode ****");
967 if (spec->wp_width && spec->wp_heigh) {
968 c_width = spec->wp_width;
969 c_heigh = spec->wp_heigh;
972 DBG(r,"calc new width and height");
974 neww = (int)((double)neww * (double)((double)c_heigh / (double)newh));
975 newh = (int)((double)newh * (double)((double)c_heigh / (double)newh));
977 DBG2(r,"newh = [%d] neww = [%d]", newh, neww);
982 DBG(r,"**** detect normal mode ****");
984 if (qsp->ua_flag != UA_IGN && spec->html_spec_type != CHXJ_SPEC_UNKNOWN) {
985 if (neww > c_width) {
986 newh = (int)((double)newh * (double)((double)c_width / (double)neww));
987 neww = (int)((double)neww * (double)((double)c_width / (double)neww));
990 if (newh > c_heigh) {
991 neww = (int)((double)neww * (double)((double)c_heigh / (double)newh));
992 newh = (int)((double)newh * (double)((double)c_heigh / (double)newh));
998 if (spec->html_spec_type != CHXJ_SPEC_UNKNOWN) {
999 DBG2(r,"convert width=[%d --> %d]", oldw, neww);
1000 DBG2(r,"convert heigh=[%d --> %d]", oldh, newh);
1002 MagickResetIterator(magick_wand);
1004 while (MagickNextImage(magick_wand) != MagickFalse) {
1006 case IMG_CONV_MODE_WALLPAPER:
1007 case IMG_CONV_MODE_EZGET:
1009 if (MagickResizeImage(magick_wand,neww,newh,LanczosFilter,1.0) == MagickFalse) {
1010 EXIT_MAGICK_ERROR();
1014 if (MagickCropImage(magick_wand,
1015 (unsigned long)c_width,
1016 (unsigned long)c_heigh,
1017 (long)((neww - c_width) / 2),
1018 (long)((newh - c_heigh) / 2)) == MagickFalse) {
1019 EXIT_MAGICK_ERROR();
1024 case IMG_CONV_MODE_NORMAL:
1026 DBG2(r,"convert width=[%d --> %d]", neww, qsp->width);
1030 DBG2(r,"convert heigh=[%d --> %d]", newh, qsp->height);
1035 if (MagickResizeImage(magick_wand,neww,newh,LanczosFilter,1.0) == MagickFalse) {
1036 EXIT_MAGICK_ERROR();
1042 if (spec->html_spec_type != CHXJ_SPEC_UNKNOWN) {
1043 if (MagickSetImageUnits(magick_wand, PixelsPerInchResolution) == MagickFalse) {
1044 EXIT_MAGICK_ERROR();
1048 if (MagickSetImageResolution(magick_wand,
1049 (double)spec->dpi_width,
1050 (double)spec->dpi_heigh) == MagickFalse) {
1051 EXIT_MAGICK_ERROR();
1055 if (MagickSetImageDispose(magick_wand, BackgroundDispose) == MagickFalse) {
1056 EXIT_MAGICK_ERROR();
1066 s_fixup_color(MagickWand* magick_wand, request_rec* r, device_table* spec, img_conv_mode_t UNUSED(mode))
1068 DBG(r,"start chxj_fixup_clor()");
1070 if (spec->html_spec_type == CHXJ_SPEC_UNKNOWN) {
1071 DBG(r, "Pass s_fixup_color proc");
1075 if (spec->color >= 256) {
1077 DBG1(r,"call MagickQuantizeImage() spec->color=[%d]",spec->color);
1079 if (MagickQuantizeImage(magick_wand,
1084 0) == MagickFalse) {
1085 EXIT_MAGICK_ERROR();
1089 DBG1(r,"call end MagickQuantizeImage() spec->color=[%d]",spec->color);
1093 DBG1(r,"call MagickQuantizeImage() spec->color=[%d]",spec->color);
1095 if (MagickQuantizeImage(magick_wand,
1100 0) == MagickFalse) {
1101 EXIT_MAGICK_ERROR();
1105 DBG1(r,"call end MagickQuantizeImage() spec->color=[%d]",spec->color);
1109 DBG(r,"end chxj_fixup_clor()");
1117 s_fixup_depth(MagickWand* magick_wand, request_rec* r, device_table* spec)
1119 if (spec->html_spec_type == CHXJ_SPEC_UNKNOWN) {
1120 DBG(r, "Pass s_fixup_depth proc");
1124 if (spec->color == 15680000) {
1125 if (MagickSetImageDepth(magick_wand, 24) == MagickFalse) {
1126 EXIT_MAGICK_ERROR();
1131 if (spec->color == 262144) {
1132 if (MagickSetImageDepth(magick_wand, 18) == MagickFalse) {
1133 EXIT_MAGICK_ERROR();
1138 if (spec->color == 65536) {
1139 if (MagickSetImageDepth(magick_wand, 16) == MagickFalse) {
1140 EXIT_MAGICK_ERROR();
1145 if (spec->color == 4096) {
1146 if (MagickSetImageDepth(magick_wand, 12) == MagickFalse) {
1147 EXIT_MAGICK_ERROR();
1152 if (spec->color == 256) {
1153 if (MagickSetImageDepth(magick_wand, 8) == MagickFalse) {
1154 EXIT_MAGICK_ERROR();
1159 if (spec->color == 4) {
1160 if (MagickSetImageDepth(magick_wand, 2) == MagickFalse) {
1161 EXIT_MAGICK_ERROR();
1166 if (spec->color == 2) {
1167 if (MagickSetImageDepth(magick_wand, 1) == MagickFalse) {
1168 EXIT_MAGICK_ERROR();
1178 s_add_copyright(MagickWand* magick_wand, request_rec* r, device_table* spec)
1180 mod_chxj_config* conf = ap_get_module_config(r->per_dir_config, &chxj_module);
1182 if (spec->html_spec_type == CHXJ_SPEC_UNKNOWN) {
1183 DBG(r, "Pass add_copiright proc");
1187 if (conf->image_copyright) {
1189 DBG1(r, "Add COPYRIGHT [%s]", conf->image_copyright);
1191 if (spec->html_spec_type == CHXJ_SPEC_Jhtml) {
1192 apr_table_setn(r->headers_out, "x-jphone-copyright", "no-transfer");
1193 if (MagickCommentImage(magick_wand,
1194 apr_psprintf(r->pool,
1196 conf->image_copyright)) == MagickFalse)
1200 if (spec->html_spec_type == CHXJ_SPEC_XHtml_Mobile_1_0
1201 || spec->html_spec_type == CHXJ_SPEC_Hdml) {
1202 if (MagickCommentImage(magick_wand,
1203 apr_psprintf(r->pool,
1204 "kddi_copyright=on,%s",
1205 conf->image_copyright)) == MagickFalse)
1209 if (MagickCommentImage(magick_wand,
1210 apr_psprintf(r->pool,
1212 conf->image_copyright)) == MagickFalse)
1217 if (MagickCommentImage(magick_wand, "mod_chxj") == MagickFalse)
1223 EXIT_MAGICK_ERROR();
1228 s_img_down_sizing(MagickWand* magick_wand, request_rec* r, device_table* spec)
1230 MagickBooleanType status;
1231 unsigned long quality = 70;
1232 apr_size_t writebyte = 0;
1234 apr_size_t prev_size = 0;
1235 int revers_flag = 0;
1237 writedata = (char*)MagickGetImageBlob(magick_wand, &writebyte);
1238 prev_size = writebyte;
1241 if (MagickSetImageCompressionQuality(magick_wand, quality) == MagickFalse) {
1242 EXIT_MAGICK_ERROR();
1246 writedata = (char*)MagickGetImageBlob(magick_wand, &writebyte);
1247 if (writebyte >= prev_size || revers_flag) {
1248 DBG2(r, "quality=[%ld] size=[%d]", (long)quality, (int)writebyte);
1251 if (quality > 100) {
1252 if (MagickSetImageCompression(magick_wand,NoCompression) == MagickFalse) {
1253 EXIT_MAGICK_ERROR();
1258 prev_size = writebyte;
1262 DBG2(r, "quality=[%ld] size=[%d]", (long)quality, (int)writebyte);
1264 if (spec->cache == 0)
1267 if (writebyte <= (unsigned int)spec->cache)
1272 if (quality == 0 || quality > 100)
1280 && writebyte > (unsigned int)spec->cache) {
1281 unsigned long now_color = spec->color;
1282 unsigned long depth = 0;
1285 case 2: depth = 1; break;
1286 case 4: now_color = 2; depth = 1; break;
1287 case 8: now_color = 4; depth = 2; break;
1288 case 16: now_color = 8; depth = 3; break;
1289 case 256: now_color = 16; depth = 4; break;
1290 case 4096: now_color = 256; depth = 8; break;
1291 case 65536: now_color = 4096; depth = 12; break;
1292 case 262144: now_color = 65536; depth = 16; break;
1293 case 15680000: now_color = 262144; depth = 18; break;
1299 if (now_color <= 2) break;
1301 if (now_color >= 8) {
1302 status = MagickQuantizeImage(magick_wand,
1310 status = MagickQuantizeImage(magick_wand,
1316 MagickSetImageType(magick_wand, GrayscaleType);
1318 if (status == MagickFalse) {
1319 EXIT_MAGICK_ERROR();
1323 if (MagickSetImageDepth(magick_wand, depth) == MagickFalse) {
1324 EXIT_MAGICK_ERROR();
1328 writedata = (char*)MagickGetImageBlob(magick_wand, &writebyte);
1330 DBG2(r,"now_color=[%ld] size=[%d]", (long)now_color, (int)writebyte);
1332 /* Once per request */
1335 while(now_color > 2);
1342 s_send_cache_file(device_table* spec, query_string_param_t* query_string, request_rec* r, const char* tmpfile)
1347 apr_size_t sendbyte;
1348 char* contentLength;
1350 rv = apr_stat(&st, tmpfile, APR_FINFO_MIN, r->pool);
1351 if (rv != APR_SUCCESS)
1352 return HTTP_NOT_FOUND;
1354 DBG1(r, "mode:[%d]", query_string->mode);
1355 DBG1(r, "name:[%s]", query_string->name);
1356 DBG1(r, "offset:[%ld]", query_string->offset);
1357 DBG1(r, "count:[%ld]", query_string->count);
1359 if (spec->available_jpeg) {
1360 r->content_type = apr_psprintf(r->pool, "image/jpeg");
1363 if (spec->available_png) {
1364 r->content_type = apr_psprintf(r->pool, "image/png");
1367 if (spec->available_gif) {
1368 r->content_type = apr_psprintf(r->pool, "image/gif");
1371 if (spec->available_bmp2 || spec->available_bmp4) {
1372 r->content_type = apr_psprintf(r->pool, "image/bmp");
1375 if (query_string->mode != IMG_CONV_MODE_EZGET && query_string->name == NULL) {
1376 contentLength = apr_psprintf(r->pool, "%d", (int)st.size);
1377 apr_table_setn(r->headers_out, "Content-Length", (const char*)contentLength);
1379 DBG1(r,"Content-Length:[%d]", (int)st.size);
1381 rv = apr_file_open(&fout, tmpfile,
1382 APR_READ | APR_BINARY, APR_OS_DEFAULT, r->pool);
1383 if (rv != APR_SUCCESS) {
1384 DBG1(r, "tmpfile open failed[%s]", tmpfile);
1385 return HTTP_NOT_FOUND;
1388 ap_send_fd(fout, r, 0, st.size, &sendbyte);
1389 apr_file_close(fout);
1391 DBG1(r, "send file data[%d]byte", (int)sendbyte);
1394 if (query_string->mode == IMG_CONV_MODE_EZGET) {
1395 char* name = apr_pstrdup(r->pool, basename(r->filename));
1396 name[strlen(name)-4] = 0;
1397 if (strcasecmp(r->content_type, "image/jpeg") == 0) {
1399 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1400 ap_rprintf(r, HDML_FIRST_PAGE, r->uri, name, ".jpg", (long)st.size, "devjaww", name);
1403 if (strcasecmp(r->content_type, "image/bmp") == 0) {
1404 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1405 ap_rprintf(r, HDML_FIRST_PAGE, r->uri, name, ".bmp", (long)st.size, "devabm", name);
1408 if (strcasecmp(r->content_type, "image/png") == 0) {
1409 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1410 ap_rprintf(r, HDML_FIRST_PAGE, r->uri, name, ".png", (long)st.size, "dev8aww", name);
1413 if (strcasecmp(r->content_type, "image/gif") == 0) {
1414 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1415 ap_rprintf(r, HDML_FIRST_PAGE, r->uri, name, ".gif", (long)st.size, "devgi0z", name);
1419 if (query_string->mode == IMG_CONV_MODE_WALLPAPER && query_string->name != NULL) {
1420 if (query_string->count == -1 && query_string->offset == -1) {
1421 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1422 ap_rprintf(r, HDML_SUCCESS_PAGE);
1426 if (query_string->count == -2 && query_string->offset == -1) {
1427 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1428 ap_rprintf(r, HDML_FAIL_PAGE);
1432 ap_set_content_type(r, "application/x-up-download");
1433 contentLength = apr_psprintf(r->pool, "%ld", query_string->count);
1434 apr_table_setn(r->headers_out, "Content-Length", (const char*)contentLength);
1436 DBG1(r, "Content-Length:[%d]", (int)st.size);
1438 rv = apr_file_open(&fout, tmpfile,
1439 APR_READ | APR_BINARY, APR_OS_DEFAULT, r->pool);
1441 if (rv != APR_SUCCESS) {
1442 DBG1(r,"tmpfile open failed[%s]", tmpfile);
1443 return HTTP_NOT_FOUND;
1446 ap_send_fd(fout, r, query_string->offset, query_string->count, &sendbyte);
1447 apr_file_close(fout);
1449 DBG1(r, "send file data[%d]byte", (int)sendbyte);
1457 s_header_only_cache_file(device_table* spec, query_string_param_t* query_string, request_rec* r, const char* tmpfile)
1461 char* contentLength;
1463 rv = apr_stat(&st, tmpfile, APR_FINFO_MIN, r->pool);
1464 if (rv != APR_SUCCESS)
1465 return HTTP_NOT_FOUND;
1467 DBG1(r, "mode:[%d]", query_string->mode);
1468 DBG1(r, "name:[%s]", query_string->name);
1469 DBG1(r, "offset:[%ld]", query_string->offset);
1470 DBG1(r, "count:[%ld]", query_string->count);
1472 if (spec->available_jpeg) {
1473 r->content_type = apr_psprintf(r->pool, "image/jpeg");
1476 if (spec->available_png) {
1477 r->content_type = apr_psprintf(r->pool, "image/png");
1480 if (spec->available_gif) {
1481 r->content_type = apr_psprintf(r->pool, "image/gif");
1484 if (spec->available_bmp2 || spec->available_bmp4) {
1485 r->content_type = apr_psprintf(r->pool, "image/bmp");
1488 if (query_string->mode != IMG_CONV_MODE_EZGET && query_string->name == NULL) {
1489 contentLength = apr_psprintf(r->pool, "%d", (int)st.size);
1490 apr_table_setn(r->headers_out, "Content-Length", (const char*)contentLength);
1492 DBG1(r,"Content-Length:[%d]", (int)st.size);
1495 if (query_string->mode == IMG_CONV_MODE_EZGET) {
1496 char* name = apr_pstrdup(r->pool, basename(r->filename));
1497 name[strlen(name)-4] = 0;
1498 if (strcasecmp(r->content_type, "image/jpeg") == 0) {
1500 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1503 if (strcasecmp(r->content_type, "image/bmp") == 0) {
1504 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1507 if (strcasecmp(r->content_type, "image/png") == 0) {
1508 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1511 if (strcasecmp(r->content_type, "image/gif") == 0) {
1512 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1516 if (query_string->mode == IMG_CONV_MODE_WALLPAPER && query_string->name != NULL) {
1517 if (query_string->count == -1 && query_string->offset == -1) {
1518 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1521 if (query_string->count == -2 && query_string->offset == -1) {
1522 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1525 ap_set_content_type(r, "application/x-up-download");
1526 contentLength = apr_psprintf(r->pool, "%ld", query_string->count);
1527 apr_table_setn(r->headers_out, "Content-Length", (const char*)contentLength);
1529 DBG1(r, "Content-Length:[%d]", (int)st.size);
1541 mod_chxj_config* conf,
1542 const char* user_agent,
1543 query_string_param_t *qsp)
1548 char* w = apr_palloc(r->pool, 256);
1552 switch (qsp->mode) {
1553 case IMG_CONV_MODE_THUMBNAIL:
1554 fname = apr_psprintf(r->pool, "%s.%s.thumbnail", r->filename, user_agent);
1555 DBG1(r, "mode=thumbnail [%s]", fname);
1557 case IMG_CONV_MODE_WALLPAPER:
1558 case IMG_CONV_MODE_EZGET:
1559 fname = apr_psprintf(r->pool, "%s.%s.wallpaper", r->filename, user_agent);
1560 DBG1(r, "mode=WallPaper [%s]", fname);
1562 case IMG_CONV_MODE_NORMAL:
1565 fname = apr_psprintf(r->pool, "%s.%s", r->filename, user_agent);
1568 fname = apr_psprintf(r->pool, "%s.w%d", fname, qsp->width);
1571 fname = apr_psprintf(r->pool, "%s.h%d", fname, qsp->height);
1573 DBG1(r,"mode=normal [%s]", fname);
1576 if (qsp->ua_flag == UA_IGN) {
1577 fname = apr_psprintf(r->pool, "%s.IGN", fname);
1580 len = strlen(fname);
1582 for (ii=0; ii<len; ii++) {
1583 if (fname[ii] == '/'
1587 || fname[ii] == ')') {
1591 w[jj++] = fname[ii];
1595 return apr_psprintf(r->pool, "%s/%s", conf->image_cache_dir,w);
1598 static unsigned short
1599 s_add_crc(const char* writedata, apr_size_t writebyte)
1601 unsigned short crc = 0xffff;
1605 for(ii=0;ii<writebyte;ii++) {
1607 crc = AU_CRC_TBL[(crc>>8^ch)&0xff]^(crc<<8);
1613 chxj_trans_name(request_rec *r)
1620 mod_chxj_config* conf;
1628 "qrc", /* QRCode½ÐÎÏÍÑ¥Õ¥¡¥¤¥ë¤Î³ÈÄ¥»Ò */
1634 int do_ext_check = TRUE;
1635 int next_ok = FALSE;
1637 DBG(r, "start chxj_trans_name()");
1639 conf = ap_get_module_config(r->per_dir_config, &chxj_module);
1642 DBG1(r, "end chxj_trans_name() conf is null[%s]", r->uri);
1646 if (conf->image != CHXJ_IMG_ON) {
1647 DBG(r, "end chxj_trans_name() conf not found");
1652 DBG1(r,"Match URI[%s]", r->uri);
1655 if (r->filename == NULL)
1656 r->filename = apr_pstrdup(r->pool, r->uri);
1659 if ((idx = strchr(r->filename, ':')) != NULL)
1660 filename_sv = idx+1;
1662 filename_sv = r->filename;
1664 DBG1(r,"r->filename[%s]", filename_sv);
1666 ccp = ap_document_root(r);
1668 return HTTP_INTERNAL_SERVER_ERROR;
1670 docroot = apr_pstrdup(r->pool, ccp);
1671 len = strlen(docroot);
1673 if (docroot[len-1] == '/')
1674 docroot[len-1] = '\0';
1678 && *filename_sv == *r->server->path
1679 && strncmp(filename_sv, r->server->path, r->server->pathlen) == 0)
1680 filename_sv = apr_pstrcat(r->pool, docroot, (filename_sv + r->server->pathlen), NULL);
1682 filename_sv = apr_pstrcat(r->pool, docroot, filename_sv, NULL);
1684 DBG1(r,"URI[%s]", filename_sv);
1686 do_ext_check = TRUE;
1687 for (ii=0; ii<7-1; ii++) {
1688 char* pos = strrchr(filename_sv, '.');
1690 if (strcasecmp(pos, ext[ii]) == 0) {
1691 do_ext_check = FALSE;
1692 fname = apr_psprintf(r->pool, "%s", filename_sv);
1699 for (ii=0; ii<7; ii++) {
1700 if (strlen(ext[ii]) == 0) {
1701 fname = apr_psprintf(r->pool, "%s", filename_sv);
1704 fname = apr_psprintf(r->pool, "%s.%s", filename_sv, ext[ii]);
1706 DBG1(r,"search [%s]", fname);
1708 rv = apr_stat(&st, fname, APR_FINFO_MIN, r->pool);
1709 if (rv == APR_SUCCESS) {
1710 if (st.filetype != APR_DIR)
1717 if (fname == NULL) {
1718 DBG1(r,"NotFound [%s]", r->filename);
1721 for (ii=0; ii<7-1; ii++) {
1722 char* pos = strrchr(fname, '.');
1724 if (strcasecmp(pos, ext[ii]) == 0) {
1732 DBG1(r,"NotFound [%s]", r->filename);
1736 if (r->handler == NULL || strcasecmp(r->handler, "chxj-qrcode") != 0) {
1737 DBG1(r,"Found [%s]", fname);
1739 r->filename = apr_psprintf(r->pool, "%s", fname);
1741 if (strcasecmp("qrc", ext[ii]) == 0)
1742 r->handler = apr_psprintf(r->pool, "chxj-qrcode");
1744 r->handler = apr_psprintf(r->pool, "chxj-picture");
1746 DBG(r, "end chxj_trans_name()");
1753 * It converts it from QUERYSTRING.
1757 static query_string_param_t*
1758 s_get_query_string_param(request_rec *r)
1766 query_string_param_t* param;
1768 s = apr_pstrdup(r->pool, r->parsed_uri.query);
1769 param = apr_palloc(r->pool, sizeof(query_string_param_t));
1770 param->mode = IMG_CONV_MODE_NORMAL;
1771 param->user_agent = NULL;
1772 param->ua_flag = UA_USE;
1779 if (s == NULL) return param;
1782 if ((pair = apr_strtok(s, "&", &pstate)) == NULL) break;
1785 name = apr_strtok(pair, "=", &vstate);
1786 value = apr_strtok(NULL, "=", &vstate);
1791 if (value && (strcasecmp(name, "mode") == 0 || strcasecmp(name, "m") == 0)) {
1796 if (strcasecmp(value, "thumbnail") == 0 || strcasecmp(value, "tb") == 0)
1797 param->mode = IMG_CONV_MODE_THUMBNAIL;
1802 if (strcasecmp(value, "WP") == 0 || strcasecmp(value, "WallPaper") == 0)
1803 param->mode = IMG_CONV_MODE_WALLPAPER;
1808 if (strcasecmp(value, "EZGET") == 0)
1809 param->mode = IMG_CONV_MODE_EZGET;
1819 if (value && (strcasecmp(name, "ua") == 0 || strcasecmp(name, "user-agent") == 0)) {
1820 ap_unescape_url(value);
1822 if ((*value == 'i' || *value == 'I') && strcasecmp(value, "IGN") == 0)
1823 param->ua_flag = UA_IGN;
1825 param->user_agent = apr_pstrdup(r->pool, value);
1831 if (value && strcasecmp(name, "name") == 0)
1832 param->name = apr_pstrdup(r->pool, value);
1837 if (value && strcasecmp(name, "offset") == 0 && (! chxj_chk_numeric(value)))
1838 param->offset = chxj_atoi(value);
1844 if (value && strcasecmp(name, "count") == 0 && (! chxj_chk_numeric(value)))
1845 param->count = chxj_atoi(value);
1850 if (value && strcasecmp(name, "w") == 0 && (! chxj_chk_numeric(value)))
1851 param->width = chxj_atoi(value);
1856 if (value && strcasecmp(name, "h") == 0 && (! chxj_chk_numeric(value)))
1857 param->height = chxj_atoi(value);
1865 if (param->mode == IMG_CONV_MODE_NORMAL && param->name)
1866 param->mode = IMG_CONV_MODE_WALLPAPER;