2 * Copyright (C) 2005-2009 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.
17 #include "chxj_tag_util.h"
18 #include "chxj_url_encode.h"
19 #include "chxj_str_util.h"
20 #include "chxj_jreserved_tag.h"
25 * The value of the VALUE attribute that the object tag node maintains is
28 * @param doc [i] The pointer to the Doc structure to be scanned is
30 * @param node [i] The tag node to be scanned is specified.
31 * @param pool [i] To use POOL.
32 * @return The value of the VALUE attribute that the object tag node maintains
33 * is returned. NULL is returned when not found.
36 qs_get_value_attr(Doc *doc, Node *node, apr_pool_t *pool)
40 /*--------------------------------------------------------------------------*/
41 /* The object tag node is scanned. */
42 /*--------------------------------------------------------------------------*/
43 for (attr = qs_get_attr(doc,node);
45 attr = qs_get_next_attr(doc,attr)) {
46 char *name = qs_get_attr_name(doc,attr);
47 char *value = qs_get_attr_value(doc,attr);
48 if (STRCASEEQ('v','V',"value",name)) {
49 /*----------------------------------------------------------------------*/
50 /* The VALUE attribute was found. */
51 /*----------------------------------------------------------------------*/
52 return apr_pstrdup(pool, value);
55 /*--------------------------------------------------------------------------*/
57 /*--------------------------------------------------------------------------*/
63 * The value of the checked tag is acquired.
65 * @param doc [i] The pointer to the Doc structure to be scanned is
67 * @param tag [i] The tag node to be scanned is specified.
68 * @param pool [i] To use POOL(unused).
69 * @return The value of the checked tag is returned. NULL is returned when
73 qs_get_checked_attr(Doc *doc, Node *tag, apr_pool_t *UNUSED(pool))
76 /*--------------------------------------------------------------------------*/
77 /* The object tag node is scanned. */
78 /*--------------------------------------------------------------------------*/
79 for (attr = qs_get_attr(doc,tag);
81 attr = qs_get_next_attr(doc,attr)) {
82 char *name = qs_get_attr_name(doc,attr);
83 if (STRCASEEQ('c','C',"checked",name)) {
84 /*----------------------------------------------------------------------*/
85 /* The VALUE attribute was found. */
86 /*----------------------------------------------------------------------*/
90 /*------------------------------------------------------------------------*/
92 /*------------------------------------------------------------------------*/
98 * The value of the type attribute is acquired.
100 * @param doc [i] The pointer to the Doc structure to be scanned is
102 * @param tag [i] The tag node to be scanned is specified.
103 * @param r [i] To use POOL, the pointer to request_rec is specified.
104 * @return The value of the type attribute is returned. NULL is returned when
108 qs_get_type_attr(Doc *doc, Node *tag, apr_pool_t *pool)
111 /*--------------------------------------------------------------------------*/
112 /* The object tag node is scanned. */
113 /*--------------------------------------------------------------------------*/
114 for (attr = qs_get_attr(doc,tag);
116 attr = qs_get_next_attr(doc,attr)) {
117 char *name = qs_get_attr_name(doc,attr);
118 char *value = qs_get_attr_value(doc,attr);
119 if (STRCASEEQ('t','T',"type",name)) {
120 /*----------------------------------------------------------------------*/
121 /* The VALUE attribute was found. */
122 /*----------------------------------------------------------------------*/
123 return apr_pstrdup(pool, value);
126 /*--------------------------------------------------------------------------*/
128 /*--------------------------------------------------------------------------*/
134 * The character string area in 0 bytes is allocated.
136 * @param pool [i] To use POOL.
137 * @return The allocated 0 byte character string is returned.
140 qs_alloc_zero_byte_string(apr_pool_t *pool)
147 tgt = apr_palloc(pool, 1);
155 * A consecutive head and the last WHITESPACE are removed.
157 * @param p [i] To use POOL
158 * @param s [i] The character string that should be removed is specified.
159 * @return The character string that has been removed is returned.
162 qs_trim_string(apr_pool_t *p, char *s)
168 if (! s) return apr_pstrdup(p, "");
170 ss = apr_pstrdup(p, s);
173 for (ii = 0;is_white_space(*ss) && ii < len; ss++, ii++);
176 for(;is_white_space(ss[ii-1]) && ii > 0; ii--);
185 * The value of child TEXT of tag that maintains the SELECTED attribute is
188 * @param Doc [i] The pointer to the Doc structure to be scanned is
190 * @param node [i] The tag node to be scanned is specified.
191 * @param pool [i] To use POOL.
192 * @reutrn The value of child TEXT of tag that maintains the SELECTED
193 * attribute is returned. NULL is returned when not found.
196 qs_get_selected_value_text(Doc *doc, Node *node, apr_pool_t *pool)
202 for (child = qs_get_child_node(doc,node);
204 child = qs_get_next_node(doc,child)) {
205 char *name = qs_get_node_name(doc,child);
206 /*------------------------------------------------------------------------*/
208 /*------------------------------------------------------------------------*/
209 if (STRCASEEQ('o','O',"option",name)) {
211 for (attr = qs_get_attr(doc,child);
213 attr = qs_get_next_attr(doc,attr)) {
214 char *name2 = qs_get_attr_name(doc,attr);
215 if (STRCASEEQ('s','S',"selected",name2)) {
216 /*------------------------------------------------------------------*/
217 /* SELECTED Value Found */
218 /*------------------------------------------------------------------*/
219 selchild = qs_get_child_node(doc, child);
222 return apr_pstrdup(pool, "");
224 return qs_get_node_value(doc, selchild);
229 if ((result = qs_get_selected_value_text(doc, child, pool)) != NULL) {
234 /*--------------------------------------------------------------------------*/
236 /*--------------------------------------------------------------------------*/
242 * The value of tag that maintains the SELECTED attribute is acquired.
244 * @param doc [i] The pointer to the Doc structure to be scanned is
246 * @param node [i] The SELECT tag node is specified.
247 * @param pool [i] To use POOL.
248 * @return The value of tag that maintains the SELECTED attribute is
249 * returned. NULL is returned when not found.
252 qs_get_selected_value(Doc *doc, Node *node, apr_pool_t *pool)
257 for (child = qs_get_child_node(doc,node);
259 child = qs_get_next_node(doc,child)) {
260 char *name = qs_get_node_name(doc,child);
261 /*------------------------------------------------------------------------*/
263 /*------------------------------------------------------------------------*/
264 if (STRCASEEQ('o','O',"option",name)) {
266 for (attr = qs_get_attr(doc,child);
268 attr = qs_get_next_attr(doc,attr)) {
269 char *name2 = qs_get_attr_name(doc,attr);
270 if (STRCASEEQ('s','S',"selected",name2)) {
271 /*------------------------------------------------------------------*/
272 /* SELECTED Value Found */
273 /*------------------------------------------------------------------*/
274 return qs_get_value_attr(doc, child, doc->buf.pool);
279 if ((result = qs_get_selected_value(doc, child, pool)) != NULL) {
284 /*--------------------------------------------------------------------------*/
286 /*--------------------------------------------------------------------------*/
292 * The value of the NAME attribute is acquired.
294 * @param doc [i] The pointer to the Doc structure at the output
295 * destination is specified.
296 * @param tag [i] The tag node to want to acquire the SIZE attribute
298 * @param pool [i] To use POOL.
299 * @return The value of the NAME attribute is returned. NULL is
300 * returned when not is.
303 qs_get_name_attr(Doc *doc, Node *tag, apr_pool_t *pool)
306 for (attr = qs_get_attr(doc,tag);
308 attr = qs_get_next_attr(doc,attr)) {
309 char *name = qs_get_attr_name(doc,attr);
310 char *value = qs_get_attr_value(doc,attr);
311 if (STRCASEEQ('n','N',"name",name)) {
312 return apr_pstrdup(pool, (value ? value : ""));
320 * The value of the SIZE attribute is acquired.
322 * @param doc [i] The pointer to the Doc structure at the output
323 * destination is specified.
324 * @param tag [i] The tag node to want to acquire the SIZE attribute
326 * @param pool [i] To use POOL.
327 * @return The value of the SIZE attribute is returned. NULL is
328 * returned when not is.
331 qs_get_size_attr(Doc *doc, Node *tag, apr_pool_t *pool)
334 for (attr = qs_get_attr(doc,tag);
336 attr = qs_get_next_attr(doc,attr)) {
337 char *name = qs_get_attr_name(doc,attr);
338 char *value = qs_get_attr_value(doc,attr);
339 if (STRCASEEQ('s','S',"size",name)) {
340 return apr_pstrdup(pool, (value ? value : ""));
348 * The value of the ACCESSKEY attribute is acquired.
350 * @param doc [i] The pointer to the Doc structure at the output
351 * destination is specified.
352 * @param tag [i] The tag node to want to acquire the ACCESSKEY attribute
354 * @param pool [i] To use POOL.
355 * @return The value of the ACCESSKEY attribute is returned. NULL is
356 * returned when not is.
359 qs_get_accesskey_attr(Doc *doc, Node *tag, apr_pool_t *pool)
362 for (attr = qs_get_attr(doc,tag);
364 attr = qs_get_next_attr(doc,attr)) {
365 char *name = qs_get_attr_name(doc,attr);
366 char *value = qs_get_attr_value(doc,attr);
367 if (STRCASEEQ('a','A',"accesskey",name)) {
368 return apr_pstrdup(pool, value);
376 * The value of the ISTYLE attribute is acquired.
378 * @param doc [i] The pointer to the Doc structure at the output
379 * destination is specified.
380 * @param tag [i] The tag node to want to acquire the ISTYLE attribute
382 * @param pool [i] To use POOL.
383 * @return The value of the ISTYLE attribute is returned. NULL is
384 * returned when not is.
387 qs_get_istyle_attr(Doc *doc, Node *tag, apr_pool_t *pool)
390 for (attr = qs_get_attr(doc,tag);
392 attr = qs_get_next_attr(doc,attr)) {
393 char *name = qs_get_attr_name(doc,attr);
394 char *value = qs_get_attr_value(doc,attr);
395 if (STRCASEEQ('i','I',"istyle",name)) {
396 return apr_pstrdup(pool, value);
404 * The value of the MAXLENGTH attribute is acquired from the tag node of the
407 * @param doc [i] The pointer to the Doc structure at the output
408 * destination is specified.
409 * @param tag [i] The tag node to want to acquire the MAXLENGTH attribute
411 * @param pool [i] To use POOL.
412 * @return The value of the MAXLENGTH attribute is returned. NULL is
413 * returned when not is.
416 qs_get_maxlength_attr(Doc *doc, Node *tag, apr_pool_t *pool)
419 for (attr = qs_get_attr(doc,tag);
421 attr = qs_get_next_attr(doc,attr)) {
422 char *name = qs_get_attr_name(doc,attr);
423 char *value = qs_get_attr_value(doc,attr);
424 if (STRCASEEQ('m','M',"maxlength",name)) {
425 return apr_pstrdup(pool, value);
433 * It is scanned whether the CHECKBOX tag of the object is CHECKED.
435 * @param doc [i] The pointer to the Doc structure at the output
436 * destination is specified.
437 * @param tag [i] The tag node to want to acquire the CHECKBOX attribute
439 * @param pool [i] To use POOL.
440 * @return 1 is returned when it is CHECKED and, additionally, 0 is returned.
443 qs_is_checked_checkbox_attr(Doc *doc, Node *tag, apr_pool_t *UNUSED(pool))
446 for (attr = qs_get_attr(doc,tag);
448 attr = qs_get_next_attr(doc,attr)) {
449 char *name = qs_get_attr_name(doc,attr);
450 if (STRCASEEQ('c','C',"checked",name)) {
459 chxj_chxjif_is_mine(device_table *spec, Doc *doc, Node *tag)
461 request_rec *r = doc->r;
464 for (attr = qs_get_attr(doc,tag);
466 attr = qs_get_next_attr(doc,attr)) {
467 char *name = qs_get_attr_name(doc,attr);
468 char *value = qs_get_attr_value(doc,attr);
469 if ((*name == 'l' || *name == 'L') && strcasecmp(name, "lang") == 0) {
471 DBG(r, "lang found [%s] spec [%d]", value, spec->html_spec_type);
472 if (STRCASEEQ('a','A',"all",value)) {
475 else if (STRCASEEQ('x','X',"xhtml",value)) {
476 if (spec->html_spec_type == CHXJ_SPEC_XHtml_Mobile_1_0) {
477 /* Yes , it is mine */
481 else if (STRCASEEQ('h','H',"hdml",value)) {
482 if (spec->html_spec_type == CHXJ_SPEC_Hdml) {
483 /* Yes , it is mine */
487 else if (STRCASEEQ('j','J',"jhtml",value)) {
488 if (spec->html_spec_type == CHXJ_SPEC_Jhtml) {
489 /* Yes , it is mine */
493 else if (STRCASEEQ('j','J',"jxhtml",value)) {
494 if (spec->html_spec_type == CHXJ_SPEC_Jxhtml) {
495 /* Yes , it is mine */
499 else if (STRCASEEQ('c','C',"chtml",value)) {
500 switch (spec->html_spec_type) {
501 case CHXJ_SPEC_Chtml_1_0:
502 case CHXJ_SPEC_Chtml_2_0:
503 case CHXJ_SPEC_Chtml_3_0:
504 case CHXJ_SPEC_Chtml_4_0:
505 case CHXJ_SPEC_Chtml_5_0:
506 case CHXJ_SPEC_Chtml_6_0:
507 case CHXJ_SPEC_Chtml_7_0:
513 else if (STRCASEEQ('c','C',"cxhtml",value)) {
514 switch (spec->html_spec_type) {
515 case CHXJ_SPEC_Chtml_6_0:
516 case CHXJ_SPEC_Chtml_7_0:
525 /* No, it is not mine. */
531 * The value of the DESTLANG attribute is acquired from the tag node of the
534 * @param doc [i] The pointer to the Doc structure at the output
535 * destination is specified.
536 * @param tag [i] The tag node to want to acquire the DESTLANG attribute
538 * @param pool [i] To use POOL.
539 * @return The value of the DESTLANG attribute is returned. NULL is
540 * returned when not is.
543 qs_get_destlang_attr(Doc *doc, Node *tag, apr_pool_t *pool)
546 for (attr = qs_get_attr(doc,tag);
548 attr = qs_get_next_attr(doc,attr)) {
549 char *name = qs_get_attr_name(doc,attr);
550 char *value = qs_get_attr_value(doc,attr);
551 if (STRCASEEQ('d','D',"destlang",name)) {
552 return apr_pstrdup(pool, value);
561 * The value of the PARSE attribute is acquired.
563 * @param doc [i] The pointer to the Doc structure to be scanned is
565 * @param tag [i] The tag node to be scanned is specified.
566 * @param pool [i] To use POOL.
567 * @return The value of the PARSE attribute is returned. NULL is returned when
571 qs_get_parse_attr(Doc *doc, Node *tag, apr_pool_t *pool)
574 /*--------------------------------------------------------------------------*/
575 /* The object tag node is scanned. */
576 /*--------------------------------------------------------------------------*/
577 for (attr = qs_get_attr(doc,tag);
579 attr = qs_get_next_attr(doc,attr)) {
580 char *name = qs_get_attr_name(doc,attr);
581 char *value = qs_get_attr_value(doc,attr);
582 if (STRCASEEQ('p','P',"parse",name)) {
583 /*----------------------------------------------------------------------*/
584 /* The VALUE attribute was found. */
585 /*----------------------------------------------------------------------*/
586 return apr_pstrdup(pool, value);
590 /*--------------------------------------------------------------------------*/
592 /*--------------------------------------------------------------------------*/
598 chxj_form_action_to_hidden_tag(
604 char **new_query_string,
607 chxjconvrule_entry *entryp)
609 char *s = apr_pstrdup(pool, str);
610 *new_query_string = NULL;
611 int no_qsconv_flag = (((unsigned int)entryp->action & CONVRULE_QSCONV_OFF_BIT) != 0);
613 if (chxj_starts_with(s, "http://") || chxj_starts_with(s, "https://")) {
615 apr_uri_parse(pool, s, &url);
616 if (url.hostname && strcasecmp(url.hostname, r->hostname) != 0) {
628 char *pair = apr_strtok(s, "&", &pstat);
630 if (strncasecmp(pair, "amp;", 4) == 0) {
634 char *key = apr_strtok(pair, "=", &pstat2);
637 val = apr_strtok(NULL, "=", &pstat2);
642 if (no_qsconv_flag) {
643 if (*new_query_string) {
644 *new_query_string = apr_psprintf(pool, "%s&%s=%s", *new_query_string, chxj_jreserved_to_safe_tag(r, key, entryp), val);
647 *new_query_string = apr_psprintf(pool, "%s=%s", chxj_jreserved_to_safe_tag(r, key, entryp), val);
651 if (post && strcasecmp(key, "guid") == 0 && docomo) {
652 *new_query_string = apr_psprintf(pool, "%s=%s", key, val);
655 if (! post || strcasecmp(key, "_chxj_cc") == 0 || strcasecmp(key, "_chxj_nc") == 0) {
657 tmp = apr_psprintf(pool,
658 "<input type=\"hidden\" name=\"%s\" value=\"%s\"%s>",
659 chxj_jreserved_to_safe_tag(r,
660 chxj_url_decode(pool, key),
662 chxj_url_decode(pool, val),
663 (xmlFlag == 1) ? " /" : "");
666 tmp = apr_psprintf(pool,
667 "<input type=\"hidden\" name=\"%s\" value=\"%s\"%s>",
668 chxj_url_decode(pool, key),
669 chxj_url_decode(pool, val),
670 (xmlFlag == 1) ? " /" : "");
674 if (entryp->action & CONVRULE_JRCONV_OFF_BIT) {
675 if (chxj_is_jreserved_tag(key)) {
676 tmp = apr_psprintf(pool,
677 "<input type=\"hidden\" name=\"%s\" value=\"%s\"%s>",
678 chxj_url_decode(pool, key),
679 chxj_url_decode(pool, val),
680 (xmlFlag == 1) ? " /" : "");
683 tmp = apr_psprintf(pool,
684 "<input type=\"hidden\" name=\"_chxj_qs_%s\" value=\"%s\"%s>",
685 chxj_url_decode(pool, key),
686 chxj_url_decode(pool, val),
687 (xmlFlag == 1) ? " /" : "");
691 tmp = apr_psprintf(pool,
692 "<input type=\"hidden\" name=\"_chxj_qs_%s\" value=\"%s\"%s>",
693 chxj_url_decode(pool, key),
694 chxj_url_decode(pool, val),
695 (xmlFlag == 1) ? " /" : "");
699 result = apr_pstrcat(pool, result, tmp, NULL);
712 chxj_delete_chxj_cc_param(
720 DBG(r, "REQ[%X] start chxj_delete_chxj_cc_param() str:[%s]", TO_ADDR(r),str);
722 apr_pool_create(&pool, r->pool);
723 s = apr_pstrdup(pool, str);
726 DBG(r, "REQ[%X] end chxj_delete_chxj_cc_param() Memory Allocation Error", TO_ADDR(r));
734 char *pair = apr_strtok(s, "&", &pstat);
736 if (strncasecmp(pair, "amp;", 4) == 0) {
741 char *key = apr_strtok(pair, "=", &pstat2);
744 val = apr_strtok(NULL, "=", &pstat2);
747 if (strcasecmp(key, "_chxj_cc")) {
749 result = apr_pstrcat(pool, result, ((xmlFlag) ? "&" : "&"), key, "=", val, NULL);
752 result = apr_pstrcat(pool, key, "=", val, NULL);
756 DBG(r, "REQ[%X] result:[%s]", TO_ADDR(r), result);
757 DBG(r, "REQ[%X] end chxj_delete_chxj_cc_param() ", TO_ADDR(r));