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"
24 * The value of the VALUE attribute that the object tag node maintains is
27 * @param doc [i] The pointer to the Doc structure to be scanned is
29 * @param node [i] The tag node to be scanned is specified.
30 * @param pool [i] To use POOL.
31 * @return The value of the VALUE attribute that the object tag node maintains
32 * is returned. NULL is returned when not found.
35 qs_get_value_attr(Doc *doc, Node *node, apr_pool_t *pool)
39 /*--------------------------------------------------------------------------*/
40 /* The object tag node is scanned. */
41 /*--------------------------------------------------------------------------*/
42 for (attr = qs_get_attr(doc,node);
44 attr = qs_get_next_attr(doc,attr)) {
45 char *name = qs_get_attr_name(doc,attr);
46 char *value = qs_get_attr_value(doc,attr);
47 if (STRCASEEQ('v','V',"value",name)) {
48 /*----------------------------------------------------------------------*/
49 /* The VALUE attribute was found. */
50 /*----------------------------------------------------------------------*/
51 return apr_pstrdup(pool, value);
54 /*--------------------------------------------------------------------------*/
56 /*--------------------------------------------------------------------------*/
62 * The value of the checked tag is acquired.
64 * @param doc [i] The pointer to the Doc structure to be scanned is
66 * @param tag [i] The tag node to be scanned is specified.
67 * @param pool [i] To use POOL(unused).
68 * @return The value of the checked tag is returned. NULL is returned when
72 qs_get_checked_attr(Doc *doc, Node *tag, apr_pool_t *UNUSED(pool))
75 /*--------------------------------------------------------------------------*/
76 /* The object tag node is scanned. */
77 /*--------------------------------------------------------------------------*/
78 for (attr = qs_get_attr(doc,tag);
80 attr = qs_get_next_attr(doc,attr)) {
81 char *name = qs_get_attr_name(doc,attr);
82 if (STRCASEEQ('c','C',"checked",name)) {
83 /*----------------------------------------------------------------------*/
84 /* The VALUE attribute was found. */
85 /*----------------------------------------------------------------------*/
89 /*------------------------------------------------------------------------*/
91 /*------------------------------------------------------------------------*/
97 * The value of the type attribute is acquired.
99 * @param doc [i] The pointer to the Doc structure to be scanned is
101 * @param tag [i] The tag node to be scanned is specified.
102 * @param r [i] To use POOL, the pointer to request_rec is specified.
103 * @return The value of the type attribute is returned. NULL is returned when
107 qs_get_type_attr(Doc *doc, Node *tag, apr_pool_t *pool)
110 /*--------------------------------------------------------------------------*/
111 /* The object tag node is scanned. */
112 /*--------------------------------------------------------------------------*/
113 for (attr = qs_get_attr(doc,tag);
115 attr = qs_get_next_attr(doc,attr)) {
116 char *name = qs_get_attr_name(doc,attr);
117 char *value = qs_get_attr_value(doc,attr);
118 if (STRCASEEQ('t','T',"type",name)) {
119 /*----------------------------------------------------------------------*/
120 /* The VALUE attribute was found. */
121 /*----------------------------------------------------------------------*/
122 return apr_pstrdup(pool, value);
125 /*--------------------------------------------------------------------------*/
127 /*--------------------------------------------------------------------------*/
133 * The character string area in 0 bytes is allocated.
135 * @param pool [i] To use POOL.
136 * @return The allocated 0 byte character string is returned.
139 qs_alloc_zero_byte_string(apr_pool_t *pool)
146 tgt = apr_palloc(pool, 1);
154 * A consecutive head and the last WHITESPACE are removed.
156 * @param p [i] To use POOL
157 * @param s [i] The character string that should be removed is specified.
158 * @return The character string that has been removed is returned.
161 qs_trim_string(apr_pool_t *p, char *s)
167 if (! s) return apr_pstrdup(p, "");
169 ss = apr_pstrdup(p, s);
172 for (ii = 0;is_white_space(*ss) && ii < len; ss++, ii++);
175 for(;is_white_space(ss[ii-1]) && ii > 0; ii--);
184 * The value of child TEXT of tag that maintains the SELECTED attribute is
187 * @param Doc [i] The pointer to the Doc structure to be scanned is
189 * @param node [i] The tag node to be scanned is specified.
190 * @param pool [i] To use POOL.
191 * @reutrn The value of child TEXT of tag that maintains the SELECTED
192 * attribute is returned. NULL is returned when not found.
195 qs_get_selected_value_text(Doc *doc, Node *node, apr_pool_t *pool)
201 for (child = qs_get_child_node(doc,node);
203 child = qs_get_next_node(doc,child)) {
204 char *name = qs_get_node_name(doc,child);
205 /*------------------------------------------------------------------------*/
207 /*------------------------------------------------------------------------*/
208 if (STRCASEEQ('o','O',"option",name)) {
210 for (attr = qs_get_attr(doc,child);
212 attr = qs_get_next_attr(doc,attr)) {
213 char *name2 = qs_get_attr_name(doc,attr);
214 if (STRCASEEQ('s','S',"selected",name2)) {
215 /*------------------------------------------------------------------*/
216 /* SELECTED Value Found */
217 /*------------------------------------------------------------------*/
218 selchild = qs_get_child_node(doc, child);
221 return apr_pstrdup(pool, "");
223 return qs_get_node_value(doc, selchild);
228 if ((result = qs_get_selected_value_text(doc, child, pool)) != NULL) {
233 /*--------------------------------------------------------------------------*/
235 /*--------------------------------------------------------------------------*/
241 * The value of tag that maintains the SELECTED attribute is acquired.
243 * @param doc [i] The pointer to the Doc structure to be scanned is
245 * @param node [i] The SELECT tag node is specified.
246 * @param pool [i] To use POOL.
247 * @return The value of tag that maintains the SELECTED attribute is
248 * returned. NULL is returned when not found.
251 qs_get_selected_value(Doc *doc, Node *node, apr_pool_t *pool)
256 for (child = qs_get_child_node(doc,node);
258 child = qs_get_next_node(doc,child)) {
259 char *name = qs_get_node_name(doc,child);
260 /*------------------------------------------------------------------------*/
262 /*------------------------------------------------------------------------*/
263 if (STRCASEEQ('o','O',"option",name)) {
265 for (attr = qs_get_attr(doc,child);
267 attr = qs_get_next_attr(doc,attr)) {
268 char *name2 = qs_get_attr_name(doc,attr);
269 if (STRCASEEQ('s','S',"selected",name2)) {
270 /*------------------------------------------------------------------*/
271 /* SELECTED Value Found */
272 /*------------------------------------------------------------------*/
273 return qs_get_value_attr(doc, child, doc->buf.pool);
278 if ((result = qs_get_selected_value(doc, child, pool)) != NULL) {
283 /*--------------------------------------------------------------------------*/
285 /*--------------------------------------------------------------------------*/
291 * The value of the NAME attribute is acquired.
293 * @param doc [i] The pointer to the Doc structure at the output
294 * destination is specified.
295 * @param tag [i] The tag node to want to acquire the SIZE attribute
297 * @param pool [i] To use POOL.
298 * @return The value of the NAME attribute is returned. NULL is
299 * returned when not is.
302 qs_get_name_attr(Doc *doc, Node *tag, apr_pool_t *pool)
305 for (attr = qs_get_attr(doc,tag);
307 attr = qs_get_next_attr(doc,attr)) {
308 char *name = qs_get_attr_name(doc,attr);
309 char *value = qs_get_attr_value(doc,attr);
310 if (STRCASEEQ('n','N',"name",name)) {
311 return apr_pstrdup(pool, (value ? value : ""));
319 * The value of the SIZE attribute is acquired.
321 * @param doc [i] The pointer to the Doc structure at the output
322 * destination is specified.
323 * @param tag [i] The tag node to want to acquire the SIZE attribute
325 * @param pool [i] To use POOL.
326 * @return The value of the SIZE attribute is returned. NULL is
327 * returned when not is.
330 qs_get_size_attr(Doc *doc, Node *tag, apr_pool_t *pool)
333 for (attr = qs_get_attr(doc,tag);
335 attr = qs_get_next_attr(doc,attr)) {
336 char *name = qs_get_attr_name(doc,attr);
337 char *value = qs_get_attr_value(doc,attr);
338 if (STRCASEEQ('s','S',"size",name)) {
339 return apr_pstrdup(pool, (value ? value : ""));
347 * The value of the ACCESSKEY attribute is acquired.
349 * @param doc [i] The pointer to the Doc structure at the output
350 * destination is specified.
351 * @param tag [i] The tag node to want to acquire the ACCESSKEY attribute
353 * @param pool [i] To use POOL.
354 * @return The value of the ACCESSKEY attribute is returned. NULL is
355 * returned when not is.
358 qs_get_accesskey_attr(Doc *doc, Node *tag, apr_pool_t *pool)
361 for (attr = qs_get_attr(doc,tag);
363 attr = qs_get_next_attr(doc,attr)) {
364 char *name = qs_get_attr_name(doc,attr);
365 char *value = qs_get_attr_value(doc,attr);
366 if (STRCASEEQ('a','A',"accesskey",name)) {
367 return apr_pstrdup(pool, value);
375 * The value of the ISTYLE attribute is acquired.
377 * @param doc [i] The pointer to the Doc structure at the output
378 * destination is specified.
379 * @param tag [i] The tag node to want to acquire the ISTYLE attribute
381 * @param pool [i] To use POOL.
382 * @return The value of the ISTYLE attribute is returned. NULL is
383 * returned when not is.
386 qs_get_istyle_attr(Doc *doc, Node *tag, apr_pool_t *pool)
389 for (attr = qs_get_attr(doc,tag);
391 attr = qs_get_next_attr(doc,attr)) {
392 char *name = qs_get_attr_name(doc,attr);
393 char *value = qs_get_attr_value(doc,attr);
394 if (STRCASEEQ('i','I',"istyle",name)) {
395 return apr_pstrdup(pool, value);
403 * The value of the MAXLENGTH attribute is acquired from the tag node of the
406 * @param doc [i] The pointer to the Doc structure at the output
407 * destination is specified.
408 * @param tag [i] The tag node to want to acquire the MAXLENGTH attribute
410 * @param pool [i] To use POOL.
411 * @return The value of the MAXLENGTH attribute is returned. NULL is
412 * returned when not is.
415 qs_get_maxlength_attr(Doc *doc, Node *tag, apr_pool_t *pool)
418 for (attr = qs_get_attr(doc,tag);
420 attr = qs_get_next_attr(doc,attr)) {
421 char *name = qs_get_attr_name(doc,attr);
422 char *value = qs_get_attr_value(doc,attr);
423 if (STRCASEEQ('m','M',"maxlength",name)) {
424 return apr_pstrdup(pool, value);
432 * It is scanned whether the CHECKBOX tag of the object is CHECKED.
434 * @param doc [i] The pointer to the Doc structure at the output
435 * destination is specified.
436 * @param tag [i] The tag node to want to acquire the CHECKBOX attribute
438 * @param pool [i] To use POOL.
439 * @return 1 is returned when it is CHECKED and, additionally, 0 is returned.
442 qs_is_checked_checkbox_attr(Doc *doc, Node *tag, apr_pool_t *UNUSED(pool))
445 for (attr = qs_get_attr(doc,tag);
447 attr = qs_get_next_attr(doc,attr)) {
448 char *name = qs_get_attr_name(doc,attr);
449 if (STRCASEEQ('c','C',"checked",name)) {
458 chxj_chxjif_is_mine(device_table *spec, Doc *doc, Node *tag)
460 request_rec *r = doc->r;
463 for (attr = qs_get_attr(doc,tag);
465 attr = qs_get_next_attr(doc,attr)) {
466 char *name = qs_get_attr_name(doc,attr);
467 char *value = qs_get_attr_value(doc,attr);
468 if ((*name == 'l' || *name == 'L') && strcasecmp(name, "lang") == 0) {
470 DBG(r, "lang found [%s] spec [%d]", value, spec->html_spec_type);
471 if (STRCASEEQ('a','A',"all",value)) {
474 else if (STRCASEEQ('x','X',"xhtml",value)) {
475 if (spec->html_spec_type == CHXJ_SPEC_XHtml_Mobile_1_0) {
476 /* Yes , it is mine */
480 else if (STRCASEEQ('h','H',"hdml",value)) {
481 if (spec->html_spec_type == CHXJ_SPEC_Hdml) {
482 /* Yes , it is mine */
486 else if (STRCASEEQ('j','J',"jhtml",value)) {
487 if (spec->html_spec_type == CHXJ_SPEC_Jhtml) {
488 /* Yes , it is mine */
492 else if (STRCASEEQ('j','J',"jxhtml",value)) {
493 if (spec->html_spec_type == CHXJ_SPEC_Jxhtml) {
494 /* Yes , it is mine */
498 else if (STRCASEEQ('c','C',"chtml",value)) {
499 switch (spec->html_spec_type) {
500 case CHXJ_SPEC_Chtml_1_0:
501 case CHXJ_SPEC_Chtml_2_0:
502 case CHXJ_SPEC_Chtml_3_0:
503 case CHXJ_SPEC_Chtml_4_0:
504 case CHXJ_SPEC_Chtml_5_0:
505 case CHXJ_SPEC_Chtml_6_0:
506 case CHXJ_SPEC_Chtml_7_0:
512 else if (STRCASEEQ('c','C',"cxhtml",value)) {
513 switch (spec->html_spec_type) {
514 case CHXJ_SPEC_Chtml_6_0:
515 case CHXJ_SPEC_Chtml_7_0:
524 /* No, it is not mine. */
530 * The value of the DESTLANG attribute is acquired from the tag node of the
533 * @param doc [i] The pointer to the Doc structure at the output
534 * destination is specified.
535 * @param tag [i] The tag node to want to acquire the DESTLANG attribute
537 * @param pool [i] To use POOL.
538 * @return The value of the DESTLANG attribute is returned. NULL is
539 * returned when not is.
542 qs_get_destlang_attr(Doc *doc, Node *tag, apr_pool_t *pool)
545 for (attr = qs_get_attr(doc,tag);
547 attr = qs_get_next_attr(doc,attr)) {
548 char *name = qs_get_attr_name(doc,attr);
549 char *value = qs_get_attr_value(doc,attr);
550 if (STRCASEEQ('d','D',"destlang",name)) {
551 return apr_pstrdup(pool, value);
560 * The value of the PARSE attribute is acquired.
562 * @param doc [i] The pointer to the Doc structure to be scanned is
564 * @param tag [i] The tag node to be scanned is specified.
565 * @param pool [i] To use POOL.
566 * @return The value of the PARSE attribute is returned. NULL is returned when
570 qs_get_parse_attr(Doc *doc, Node *tag, apr_pool_t *pool)
573 /*--------------------------------------------------------------------------*/
574 /* The object tag node is scanned. */
575 /*--------------------------------------------------------------------------*/
576 for (attr = qs_get_attr(doc,tag);
578 attr = qs_get_next_attr(doc,attr)) {
579 char *name = qs_get_attr_name(doc,attr);
580 char *value = qs_get_attr_value(doc,attr);
581 if (STRCASEEQ('p','P',"parse",name)) {
582 /*----------------------------------------------------------------------*/
583 /* The VALUE attribute was found. */
584 /*----------------------------------------------------------------------*/
585 return apr_pstrdup(pool, value);
589 /*--------------------------------------------------------------------------*/
591 /*--------------------------------------------------------------------------*/
597 chxj_form_action_to_hidden_tag(
603 char **new_query_string,
606 chxjconvrule_entry *entryp)
608 char *s = apr_pstrdup(pool, str);
609 *new_query_string = NULL;
610 int no_qsconv_flag = (((unsigned int)entryp->action & CONVRULE_QSCONV_OFF_BIT) != 0);
612 if (chxj_starts_with(s, "http://") || chxj_starts_with(s, "https://")) {
614 apr_uri_parse(pool, s, &url);
615 if (url.hostname && strcasecmp(url.hostname, r->hostname) != 0) {
627 char *pair = apr_strtok(s, "&", &pstat);
629 if (strncasecmp(pair, "amp;", 4) == 0) {
633 char *key = apr_strtok(pair, "=", &pstat2);
636 val = apr_strtok(NULL, "=", &pstat2);
641 if (no_qsconv_flag) {
642 if (*new_query_string) {
643 *new_query_string = apr_psprintf(pool, "%s&%s=%s", *new_query_string, chxj_jreserved_to_safe_tag(r, key, entryp), val);
646 *new_query_string = apr_psprintf(pool, "%s=%s", chxj_jreserved_to_safe_tag(r, key, entryp), val);
650 if (post && strcasecmp(key, "guid") == 0 && docomo) {
651 *new_query_string = apr_psprintf(pool, "%s=%s", key, val);
654 if (! post || strcasecmp(key, "_chxj_cc") == 0 || strcasecmp(key, "_chxj_nc") == 0) {
656 tmp = apr_psprintf(pool,
657 "<input type=\"hidden\" name=\"%s\" value=\"%s\"%s>",
658 chxj_jreserved_to_safe_tag(r,
659 chxj_url_decode(pool, key),
661 chxj_url_decode(pool, val),
662 (xmlFlag == 1) ? " /" : "");
665 tmp = apr_psprintf(pool,
666 "<input type=\"hidden\" name=\"%s\" value=\"%s\"%s>",
667 chxj_url_decode(pool, key),
668 chxj_url_decode(pool, val),
669 (xmlFlag == 1) ? " /" : "");
673 tmp = apr_psprintf(pool,
674 "<input type=\"hidden\" name=\"_chxj_qs_%s\" value=\"%s\"%s>",
675 chxj_url_decode(pool, key),
676 chxj_url_decode(pool, val),
677 (xmlFlag == 1) ? " /" : "");
680 result = apr_pstrcat(pool, result, tmp, NULL);