2 * Copyright (C) 2005 QSDN,Inc. All rights reserved.
3 * Copyright (C) 2005 Atsushi Konno 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) {
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 DBG2(r,"convert width=[%d --> %d]", oldw, neww);
999 DBG2(r,"convert heigh=[%d --> %d]", oldh, newh);
1001 MagickResetIterator(magick_wand);
1003 while (MagickNextImage(magick_wand) != MagickFalse) {
1005 case IMG_CONV_MODE_WALLPAPER:
1006 case IMG_CONV_MODE_EZGET:
1008 if (MagickResizeImage(magick_wand,neww,newh,LanczosFilter,1.0) == MagickFalse) {
1009 EXIT_MAGICK_ERROR();
1013 if (MagickCropImage(magick_wand,
1014 (unsigned long)c_width,
1015 (unsigned long)c_heigh,
1016 (long)((neww - c_width) / 2),
1017 (long)((newh - c_heigh) / 2)) == MagickFalse) {
1018 EXIT_MAGICK_ERROR();
1023 case IMG_CONV_MODE_NORMAL:
1025 DBG2(r,"convert width=[%d --> %d]", neww, qsp->width);
1029 DBG2(r,"convert heigh=[%d --> %d]", newh, qsp->height);
1034 if (MagickResizeImage(magick_wand,neww,newh,LanczosFilter,1.0) == MagickFalse) {
1035 EXIT_MAGICK_ERROR();
1041 if (MagickSetImageUnits(magick_wand, PixelsPerInchResolution) == MagickFalse) {
1042 EXIT_MAGICK_ERROR();
1046 if (MagickSetImageResolution(magick_wand,
1047 (double)spec->dpi_width,
1048 (double)spec->dpi_heigh) == MagickFalse) {
1049 EXIT_MAGICK_ERROR();
1053 if (MagickSetImageDispose(magick_wand, BackgroundDispose) == MagickFalse) {
1054 EXIT_MAGICK_ERROR();
1063 s_fixup_color(MagickWand* magick_wand, request_rec* r, device_table* spec, img_conv_mode_t mode)
1065 DBG(r,"start chxj_fixup_clor()");
1067 if (spec->color >= 256) {
1069 DBG1(r,"call MagickQuantizeImage() spec->color=[%d]",spec->color);
1071 if (MagickQuantizeImage(magick_wand,
1076 0) == MagickFalse) {
1077 EXIT_MAGICK_ERROR();
1081 DBG1(r,"call end MagickQuantizeImage() spec->color=[%d]",spec->color);
1085 DBG1(r,"call MagickQuantizeImage() spec->color=[%d]",spec->color);
1087 if (MagickQuantizeImage(magick_wand,
1092 0) == MagickFalse) {
1093 EXIT_MAGICK_ERROR();
1097 DBG1(r,"call end MagickQuantizeImage() spec->color=[%d]",spec->color);
1101 DBG(r,"end chxj_fixup_clor()");
1109 s_fixup_depth(MagickWand* magick_wand, request_rec* r, device_table* spec)
1111 if (spec->color == 15680000) {
1112 if (MagickSetImageDepth(magick_wand, 24) == MagickFalse) {
1113 EXIT_MAGICK_ERROR();
1118 if (spec->color == 262144) {
1119 if (MagickSetImageDepth(magick_wand, 18) == MagickFalse) {
1120 EXIT_MAGICK_ERROR();
1125 if (spec->color == 65536) {
1126 if (MagickSetImageDepth(magick_wand, 16) == MagickFalse) {
1127 EXIT_MAGICK_ERROR();
1132 if (spec->color == 4096) {
1133 if (MagickSetImageDepth(magick_wand, 12) == MagickFalse) {
1134 EXIT_MAGICK_ERROR();
1139 if (spec->color == 256) {
1140 if (MagickSetImageDepth(magick_wand, 8) == MagickFalse) {
1141 EXIT_MAGICK_ERROR();
1146 if (spec->color == 4) {
1147 if (MagickSetImageDepth(magick_wand, 2) == MagickFalse) {
1148 EXIT_MAGICK_ERROR();
1153 if (spec->color == 2) {
1154 if (MagickSetImageDepth(magick_wand, 1) == MagickFalse) {
1155 EXIT_MAGICK_ERROR();
1165 s_add_copyright(MagickWand* magick_wand, request_rec* r, device_table* spec)
1167 mod_chxj_config* conf = ap_get_module_config(r->per_dir_config, &chxj_module);
1169 if (conf->image_copyright) {
1171 DBG1(r, "Add COPYRIGHT [%s]", conf->image_copyright);
1173 if (spec->html_spec_type == CHXJ_SPEC_Jhtml) {
1174 apr_table_setn(r->headers_out, "x-jphone-copyright", "no-transfer");
1175 if (MagickCommentImage(magick_wand,
1176 apr_psprintf(r->pool,
1178 conf->image_copyright)) == MagickFalse)
1182 if (spec->html_spec_type == CHXJ_SPEC_XHtml_Mobile_1_0
1183 || spec->html_spec_type == CHXJ_SPEC_Hdml) {
1184 if (MagickCommentImage(magick_wand,
1185 apr_psprintf(r->pool,
1186 "kddi_copyright=on,%s",
1187 conf->image_copyright)) == MagickFalse)
1191 if (MagickCommentImage(magick_wand,
1192 apr_psprintf(r->pool,
1194 conf->image_copyright)) == MagickFalse)
1199 if (MagickCommentImage(magick_wand, "mod_chxj") == MagickFalse)
1205 EXIT_MAGICK_ERROR();
1210 s_img_down_sizing(MagickWand* magick_wand, request_rec* r, device_table* spec)
1212 MagickBooleanType status;
1213 unsigned long quality = 70;
1214 apr_size_t writebyte = 0;
1216 apr_size_t prev_size = 0;
1217 int revers_flag = 0;
1219 writedata = (char*)MagickGetImageBlob(magick_wand, &writebyte);
1220 prev_size = writebyte;
1223 if (MagickSetImageCompressionQuality(magick_wand, quality) == MagickFalse) {
1224 EXIT_MAGICK_ERROR();
1228 writedata = (char*)MagickGetImageBlob(magick_wand, &writebyte);
1229 if (writebyte >= prev_size || revers_flag) {
1230 DBG2(r, "quality=[%ld] size=[%d]", (long)quality, writebyte);
1233 if (quality > 100) {
1234 if (MagickSetImageCompression(magick_wand,NoCompression) == MagickFalse) {
1235 EXIT_MAGICK_ERROR();
1240 prev_size = writebyte;
1244 DBG2(r, "quality=[%ld] size=[%d]", (long)quality, writebyte);
1246 if (spec->cache == 0)
1249 if (writebyte <= spec->cache)
1254 if (quality == 0 || quality > 100)
1262 && writebyte > spec->cache) {
1263 unsigned long now_color = spec->color;
1264 unsigned long depth = 0;
1267 case 2: depth = 1; break;
1268 case 4: now_color = 2; depth = 1; break;
1269 case 8: now_color = 4; depth = 2; break;
1270 case 16: now_color = 8; depth = 3; break;
1271 case 256: now_color = 16; depth = 4; break;
1272 case 4096: now_color = 256; depth = 8; break;
1273 case 65536: now_color = 4096; depth = 12; break;
1274 case 262144: now_color = 65536; depth = 16; break;
1275 case 15680000: now_color = 262144; depth = 18; break;
1281 if (now_color <= 2) break;
1283 if (now_color >= 8) {
1284 status = MagickQuantizeImage(magick_wand,
1292 status = MagickQuantizeImage(magick_wand,
1298 MagickSetImageType(magick_wand, GrayscaleType);
1300 if (status == MagickFalse) {
1301 EXIT_MAGICK_ERROR();
1305 if (MagickSetImageDepth(magick_wand, depth) == MagickFalse) {
1306 EXIT_MAGICK_ERROR();
1310 writedata = (char*)MagickGetImageBlob(magick_wand, &writebyte);
1312 DBG2(r,"now_color=[%ld] size=[%d]", (long)now_color, writebyte);
1314 /* Once per request */
1317 while(now_color > 2);
1324 s_send_cache_file(device_table* spec, query_string_param_t* query_string, request_rec* r, const char* tmpfile)
1329 apr_size_t sendbyte;
1330 char* contentLength;
1332 rv = apr_stat(&st, tmpfile, APR_FINFO_MIN, r->pool);
1333 if (rv != APR_SUCCESS)
1334 return HTTP_NOT_FOUND;
1336 DBG1(r, "mode:[%d]", query_string->mode);
1337 DBG1(r, "name:[%s]", query_string->name);
1338 DBG1(r, "offset:[%ld]", query_string->offset);
1339 DBG1(r, "count:[%ld]", query_string->count);
1341 if (spec->available_jpeg) {
1342 r->content_type = apr_psprintf(r->pool, "image/jpeg");
1345 if (spec->available_png) {
1346 r->content_type = apr_psprintf(r->pool, "image/png");
1349 if (spec->available_gif) {
1350 r->content_type = apr_psprintf(r->pool, "image/gif");
1353 if (spec->available_bmp2 || spec->available_bmp4) {
1354 r->content_type = apr_psprintf(r->pool, "image/bmp");
1357 if (query_string->mode != IMG_CONV_MODE_EZGET && query_string->name == NULL) {
1358 contentLength = apr_psprintf(r->pool, "%d", (int)st.size);
1359 apr_table_setn(r->headers_out, "Content-Length", (const char*)contentLength);
1361 DBG1(r,"Content-Length:[%d]", (int)st.size);
1363 rv = apr_file_open(&fout, tmpfile,
1364 APR_READ | APR_BINARY, APR_OS_DEFAULT, r->pool);
1365 if (rv != APR_SUCCESS) {
1366 DBG1(r, "tmpfile open failed[%s]", tmpfile);
1367 return HTTP_NOT_FOUND;
1370 ap_send_fd(fout, r, 0, st.size, &sendbyte);
1371 apr_file_close(fout);
1373 DBG1(r, "send file data[%d]byte", sendbyte);
1376 if (query_string->mode == IMG_CONV_MODE_EZGET) {
1377 char* name = apr_pstrdup(r->pool, basename(r->filename));
1378 name[strlen(name)-4] = 0;
1379 if (strcasecmp(r->content_type, "image/jpeg") == 0) {
1381 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1382 ap_rprintf(r, HDML_FIRST_PAGE, r->uri, name, ".jpg", (long)st.size, "devjaww", name);
1385 if (strcasecmp(r->content_type, "image/bmp") == 0) {
1386 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1387 ap_rprintf(r, HDML_FIRST_PAGE, r->uri, name, ".bmp", (long)st.size, "devabm", name);
1390 if (strcasecmp(r->content_type, "image/png") == 0) {
1391 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1392 ap_rprintf(r, HDML_FIRST_PAGE, r->uri, name, ".png", (long)st.size, "dev8aww", name);
1395 if (strcasecmp(r->content_type, "image/gif") == 0) {
1396 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1397 ap_rprintf(r, HDML_FIRST_PAGE, r->uri, name, ".gif", (long)st.size, "devgi0z", name);
1401 if (query_string->mode == IMG_CONV_MODE_WALLPAPER && query_string->name != NULL) {
1402 if (query_string->count == -1 && query_string->offset == -1) {
1403 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1404 ap_rprintf(r, HDML_SUCCESS_PAGE);
1408 if (query_string->count == -2 && query_string->offset == -1) {
1409 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1410 ap_rprintf(r, HDML_FAIL_PAGE);
1414 ap_set_content_type(r, "application/x-up-download");
1415 contentLength = apr_psprintf(r->pool, "%ld", query_string->count);
1416 apr_table_setn(r->headers_out, "Content-Length", (const char*)contentLength);
1418 DBG1(r, "Content-Length:[%d]", (int)st.size);
1420 rv = apr_file_open(&fout, tmpfile,
1421 APR_READ | APR_BINARY, APR_OS_DEFAULT, r->pool);
1423 if (rv != APR_SUCCESS) {
1424 DBG1(r,"tmpfile open failed[%s]", tmpfile);
1425 return HTTP_NOT_FOUND;
1428 ap_send_fd(fout, r, query_string->offset, query_string->count, &sendbyte);
1429 apr_file_close(fout);
1431 DBG1(r, "send file data[%d]byte", sendbyte);
1439 s_header_only_cache_file(device_table* spec, query_string_param_t* query_string, request_rec* r, const char* tmpfile)
1443 char* contentLength;
1445 rv = apr_stat(&st, tmpfile, APR_FINFO_MIN, r->pool);
1446 if (rv != APR_SUCCESS)
1447 return HTTP_NOT_FOUND;
1449 DBG1(r, "mode:[%d]", query_string->mode);
1450 DBG1(r, "name:[%s]", query_string->name);
1451 DBG1(r, "offset:[%ld]", query_string->offset);
1452 DBG1(r, "count:[%ld]", query_string->count);
1454 if (spec->available_jpeg) {
1455 r->content_type = apr_psprintf(r->pool, "image/jpeg");
1458 if (spec->available_png) {
1459 r->content_type = apr_psprintf(r->pool, "image/png");
1462 if (spec->available_gif) {
1463 r->content_type = apr_psprintf(r->pool, "image/gif");
1466 if (spec->available_bmp2 || spec->available_bmp4) {
1467 r->content_type = apr_psprintf(r->pool, "image/bmp");
1470 if (query_string->mode != IMG_CONV_MODE_EZGET && query_string->name == NULL) {
1471 contentLength = apr_psprintf(r->pool, "%d", (int)st.size);
1472 apr_table_setn(r->headers_out, "Content-Length", (const char*)contentLength);
1474 DBG1(r,"Content-Length:[%d]", (int)st.size);
1477 if (query_string->mode == IMG_CONV_MODE_EZGET) {
1478 char* name = apr_pstrdup(r->pool, basename(r->filename));
1479 name[strlen(name)-4] = 0;
1480 if (strcasecmp(r->content_type, "image/jpeg") == 0) {
1482 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1485 if (strcasecmp(r->content_type, "image/bmp") == 0) {
1486 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1489 if (strcasecmp(r->content_type, "image/png") == 0) {
1490 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1493 if (strcasecmp(r->content_type, "image/gif") == 0) {
1494 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1498 if (query_string->mode == IMG_CONV_MODE_WALLPAPER && query_string->name != NULL) {
1499 if (query_string->count == -1 && query_string->offset == -1) {
1500 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1503 if (query_string->count == -2 && query_string->offset == -1) {
1504 ap_set_content_type(r, "text/x-hdml; charset=Shift_JIS");
1507 ap_set_content_type(r, "application/x-up-download");
1508 contentLength = apr_psprintf(r->pool, "%ld", query_string->count);
1509 apr_table_setn(r->headers_out, "Content-Length", (const char*)contentLength);
1511 DBG1(r, "Content-Length:[%d]", (int)st.size);
1523 mod_chxj_config* conf,
1524 const char* user_agent,
1525 query_string_param_t *qsp)
1530 char* w = apr_palloc(r->pool, 256);
1534 switch (qsp->mode) {
1535 case IMG_CONV_MODE_THUMBNAIL:
1536 fname = apr_psprintf(r->pool, "%s.%s.thumbnail", r->filename, user_agent);
1537 DBG1(r, "mode=thumbnail [%s]", fname);
1539 case IMG_CONV_MODE_WALLPAPER:
1540 case IMG_CONV_MODE_EZGET:
1541 fname = apr_psprintf(r->pool, "%s.%s.wallpaper", r->filename, user_agent);
1542 DBG1(r, "mode=WallPaper [%s]", fname);
1544 case IMG_CONV_MODE_NORMAL:
1547 fname = apr_psprintf(r->pool, "%s.%s", r->filename, user_agent);
1550 fname = apr_psprintf(r->pool, "%s.w%d", fname, qsp->width);
1553 fname = apr_psprintf(r->pool, "%s.h%d", fname, qsp->height);
1555 DBG1(r,"mode=normal [%s]", fname);
1558 if (qsp->ua_flag == UA_IGN) {
1559 fname = apr_psprintf(r->pool, "%s.IGN", fname);
1562 len = strlen(fname);
1564 for (ii=0; ii<len; ii++) {
1565 if (fname[ii] == '/'
1569 || fname[ii] == ')') {
1573 w[jj++] = fname[ii];
1577 return apr_psprintf(r->pool, "%s/%s", conf->image_cache_dir,w);
1580 static unsigned short
1581 s_add_crc(const char* writedata, apr_size_t writebyte)
1583 unsigned short crc = 0xffff;
1587 for(ii=0;ii<writebyte;ii++) {
1589 crc = AU_CRC_TBL[(crc>>8^ch)&0xff]^(crc<<8);
1595 chxj_trans_name(request_rec *r)
1602 mod_chxj_config* conf;
1610 "qrc", /* QRCode½ÐÎÏÍÑ¥Õ¥¡¥¤¥ë¤Î³ÈÄ¥»Ò */
1616 int do_ext_check = TRUE;
1617 int next_ok = FALSE;
1619 DBG(r, "start chxj_trans_name()");
1621 conf = ap_get_module_config(r->per_dir_config, &chxj_module);
1624 DBG1(r, "end chxj_trans_name() conf is null[%s]", r->uri);
1628 if (conf->image != CHXJ_IMG_ON) {
1629 DBG(r, "end chxj_trans_name() conf not found");
1634 DBG1(r,"Match URI[%s]", r->uri);
1637 if (r->filename == NULL)
1638 r->filename = apr_pstrdup(r->pool, r->uri);
1641 if ((idx = strchr(r->filename, ':')) != NULL)
1642 filename_sv = idx+1;
1644 filename_sv = r->filename;
1646 DBG1(r,"r->filename[%s]", filename_sv);
1648 ccp = ap_document_root(r);
1650 return HTTP_INTERNAL_SERVER_ERROR;
1652 docroot = apr_pstrdup(r->pool, ccp);
1653 len = strlen(docroot);
1655 if (docroot[len-1] == '/')
1656 docroot[len-1] = '\0';
1660 && *filename_sv == *r->server->path
1661 && strncmp(filename_sv, r->server->path, r->server->pathlen) == 0)
1662 filename_sv = apr_pstrcat(r->pool, docroot, (filename_sv + r->server->pathlen), NULL);
1664 filename_sv = apr_pstrcat(r->pool, docroot, filename_sv, NULL);
1666 DBG1(r,"URI[%s]", filename_sv);
1668 do_ext_check = TRUE;
1669 for (ii=0; ii<7-1; ii++) {
1670 char* pos = strrchr(filename_sv, '.');
1672 if (strcasecmp(pos, ext[ii]) == 0) {
1673 do_ext_check = FALSE;
1674 fname = apr_psprintf(r->pool, "%s", filename_sv);
1681 for (ii=0; ii<7; ii++) {
1682 if (strlen(ext[ii]) == 0) {
1683 fname = apr_psprintf(r->pool, "%s", filename_sv);
1686 fname = apr_psprintf(r->pool, "%s.%s", filename_sv, ext[ii]);
1688 DBG1(r,"search [%s]", fname);
1690 rv = apr_stat(&st, fname, APR_FINFO_MIN, r->pool);
1691 if (rv == APR_SUCCESS) {
1692 if (st.filetype != APR_DIR)
1699 if (fname == NULL) {
1700 DBG1(r,"NotFound [%s]", r->filename);
1703 for (ii=0; ii<7-1; ii++) {
1704 char* pos = strrchr(fname, '.');
1706 if (strcasecmp(pos, ext[ii]) == 0) {
1714 DBG1(r,"NotFound [%s]", r->filename);
1718 if (r->handler == NULL || strcasecmp(r->handler, "chxj-qrcode") != 0) {
1719 DBG1(r,"Found [%s]", fname);
1721 r->filename = apr_psprintf(r->pool, "%s", fname);
1723 if (strcasecmp("qrc", ext[ii]) == 0)
1724 r->handler = apr_psprintf(r->pool, "chxj-qrcode");
1726 r->handler = apr_psprintf(r->pool, "chxj-picture");
1728 DBG(r, "end chxj_trans_name()");
1735 * It converts it from QUERYSTRING.
1739 static query_string_param_t*
1740 s_get_query_string_param(request_rec *r)
1748 query_string_param_t* param;
1750 s = apr_pstrdup(r->pool, r->parsed_uri.query);
1751 param = apr_palloc(r->pool, sizeof(query_string_param_t));
1752 param->mode = IMG_CONV_MODE_NORMAL;
1753 param->user_agent = NULL;
1754 param->ua_flag = UA_USE;
1761 if (s == NULL) return param;
1764 if ((pair = apr_strtok(s, "&", &pstate)) == NULL) break;
1767 name = apr_strtok(pair, "=", &vstate);
1768 value = apr_strtok(NULL, "=", &vstate);
1773 if (value && (strcasecmp(name, "mode") == 0 || strcasecmp(name, "m") == 0)) {
1778 if (strcasecmp(value, "thumbnail") == 0 || strcasecmp(value, "tb") == 0)
1779 param->mode = IMG_CONV_MODE_THUMBNAIL;
1784 if (strcasecmp(value, "WP") == 0 || strcasecmp(value, "WallPaper") == 0)
1785 param->mode = IMG_CONV_MODE_WALLPAPER;
1790 if (strcasecmp(value, "EZGET") == 0)
1791 param->mode = IMG_CONV_MODE_EZGET;
1801 if (value && (strcasecmp(name, "ua") == 0 || strcasecmp(name, "user-agent") == 0)) {
1802 ap_unescape_url(value);
1804 if ((*value == 'i' || *value == 'I') && strcasecmp(value, "IGN") == 0)
1805 param->ua_flag = UA_IGN;
1807 param->user_agent = apr_pstrdup(r->pool, value);
1813 if (value && strcasecmp(name, "name") == 0)
1814 param->name = apr_pstrdup(r->pool, value);
1819 if (value && strcasecmp(name, "offset") == 0 && (! chxj_chk_numeric(value)))
1820 param->offset = chxj_atoi(value);
1826 if (value && strcasecmp(name, "count") == 0 && (! chxj_chk_numeric(value)))
1827 param->count = chxj_atoi(value);
1832 if (value && strcasecmp(name, "w") == 0 && (! chxj_chk_numeric(value)))
1833 param->width = chxj_atoi(value);
1838 if (value && strcasecmp(name, "h") == 0 && (! chxj_chk_numeric(value)))
1839 param->height = chxj_atoi(value);
1847 if (param->mode == IMG_CONV_MODE_NORMAL && param->name)
1848 param->mode = IMG_CONV_MODE_WALLPAPER;