From 9d0441d125ce91b92c58df87a082e03747cd23d7 Mon Sep 17 00:00:00 2001 From: konn Date: Sat, 28 Jun 2008 12:35:43 +0000 Subject: [PATCH] * Added LINK tag for CHTML4.0 converter. * Added test code of the LINK tag for CHTML4.0 converter. * Added test code of the HTML tag with CSS for CHTML4.0 converter. git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/modchxj/mod_chxj/branches/sandbox@2757 1a406e8e-add9-4483-a2c8-d8cac5b7c224 --- include/chxj_chtml40.h | 23 ++- src/chxj_chtml40.c | 67 +++++- test/chxj_chtml40/Makefile | 5 +- test/chxj_chtml40/test_chxj_chtml40.c | 373 ++++++++++++++++++++++++++++++++++ 4 files changed, 454 insertions(+), 14 deletions(-) diff --git a/include/chxj_chtml40.h b/include/chxj_chtml40.h index a6d985d1..977afd82 100644 --- a/include/chxj_chtml40.h +++ b/include/chxj_chtml40.h @@ -21,6 +21,7 @@ #include "mod_chxj.h" #include "chxj_cookie.h" +#include "chxj_css.h" /*----------------------------------------------------------------------------*/ /* Structure for CHTML4.0 */ @@ -28,17 +29,19 @@ typedef struct chtml40_t chtml40_t; struct chtml40_t { - Doc *doc; - char *out; - int out_len; - int pre_flag; - int textarea_flag; - int font_flag; + Doc *doc; + char *out; + int out_len; + int pre_flag; + int textarea_flag; + int font_flag; - device_table *spec; - mod_chxj_config *conf; - chxjconvrule_entry *entryp; - cookie_t *cookie; + device_table *spec; + mod_chxj_config *conf; + chxjconvrule_entry *entryp; + cookie_t *cookie; + css_stylesheet_t *style; + css_prop_list_stack_t *css_prop_stack; }; /*----------------------------------------------------------------------------*/ diff --git a/src/chxj_chtml40.c b/src/chxj_chtml40.c index e33bc729..3039a165 100644 --- a/src/chxj_chtml40.c +++ b/src/chxj_chtml40.c @@ -114,6 +114,7 @@ static char *s_chtml40_start_plaintext_tag (void *pdoc, Node *node); static char *s_chtml40_start_plaintext_tag_inner (void *pdoc, Node *node); static char *s_chtml40_end_plaintext_tag (void *pdoc, Node *node); static char *s_chtml40_newline_mark (void *pdoc, Node *node); +static char *s_chtml40_link_tag (void *pdoc, Node *node); static void s_init_chtml40(chtml40_t *chtml, Doc *doc, request_rec *r, device_table *spec); @@ -386,6 +387,11 @@ tag_handler chtml40_handler[] = { s_chtml40_start_marquee_tag, s_chtml40_end_marquee_tag, }, + /* tagLINK */ + { + s_chtml40_link_tag, + NULL, + }, /* tagNLMARK */ { s_chtml40_newline_mark, @@ -3240,8 +3246,8 @@ s_chtml40_end_plaintext_tag(void *pdoc, Node *UNUSED(child)) /** - * * It is handler who processes the New Line Code. - * */ + * It is handler who processes the New Line Code. + */ static char * s_chtml40_newline_mark(void *pdoc, Node *UNUSED(node)) { @@ -3250,6 +3256,63 @@ s_chtml40_newline_mark(void *pdoc, Node *UNUSED(node)) W_NLCODE(); return chtml40->out; } + + +/** + * It is a handler who processes the LINK tag. + * + * @param pdoc [i/o] The pointer to the CHTML structure at the output + * destination is specified. + * @param node [i] The LINK tag node is specified. + * @return The conversion result is returned. + */ +static char * +s_chtml40_link_tag(void *pdoc, Node *node) +{ + chtml40_t *chtml40; + Doc *doc; + Attr *attr; + char *rel = NULL; + char *href = NULL; + char *type = NULL; + + chtml40 = GET_CHTML40(pdoc); + doc = chtml40->doc; + + if (! IS_CSS_ON(chtml40->entryp)) { + return chtml40->out; + } + + for (attr = qs_get_attr(doc,node); + attr; + attr = qs_get_next_attr(doc,attr)) { + char *name = qs_get_attr_name(doc,attr); + char *value = qs_get_attr_value(doc,attr); + if (STRCASEEQ('r','R',"rel", name)) { + if (value && *value && STRCASEEQ('s','S',"stylesheet", value)) { + rel = value; + } + } + else if (STRCASEEQ('h','H',"href", name)) { + if (value && *value) { + href = value; + } + } + else if (STRCASEEQ('t','T',"type", name)) { + if (value && *value && STRCASEEQ('t','T',"text/css",value)) { + type = value; + } + } + } + + if (rel && href && type) { + DBG(doc->r, "start load CSS. url:[%s]", href); + chtml40->style = chxj_css_parse_from_uri(doc->r, doc->pool, chtml40->style, href); + DBG(doc->r, "end load CSS. url:[%s]", href); + } + + return chtml40->out; +} /* * vim:ts=2 et */ diff --git a/test/chxj_chtml40/Makefile b/test/chxj_chtml40/Makefile index 88f31ef6..376d3d18 100644 --- a/test/chxj_chtml40/Makefile +++ b/test/chxj_chtml40/Makefile @@ -8,7 +8,8 @@ TOP_DIR=../.. INC_DIR=-I$(TOP_DIR)/include \ -I/usr/include/apache2 \ -I/usr/include/apr-1.0 \ - -I$(TOP_DIR)/src + -I$(TOP_DIR)/src \ + -I$(TOP_DIR)/src/serf all:test @@ -18,7 +19,7 @@ test: $(TARGET) ./$(TARGET) $(TARGET): $(TARGET).c - gcc -g -o $@ -Wall -lcunit $< $(INC_DIR) -DLINUX=2 -D_REENTRANT -D_GNU_SOURCE -D_LARGEFILE64_SOURCE -lapr-1 -laprutil-1 + gcc -g -o $@ -Wall -lcunit $< $(INC_DIR) -DLINUX=2 -D_REENTRANT -D_GNU_SOURCE -D_LARGEFILE64_SOURCE -lapr-1 -laprutil-1 `croco-0.6-config --cflags` `croco-0.6-config --libs` $(TOP_DIR)/src/serf/.libs/libserf-0.a -lpcre clean: diff --git a/test/chxj_chtml40/test_chxj_chtml40.c b/test/chxj_chtml40/test_chxj_chtml40.c index da10d55c..3d61b564 100644 --- a/test/chxj_chtml40/test_chxj_chtml40.c +++ b/test/chxj_chtml40/test_chxj_chtml40.c @@ -34,6 +34,10 @@ #include "chxj_dbm.c" #include "chxj_str_util.c" #include +#include "chxj_serf.h" +#include "chxj_css.h" +#include "chxj_serf.c" +#include "chxj_css.c" @@ -484,6 +488,19 @@ void test_chtml40_font_tag_006(); void test_chtml40_font_tag_007(); void test_chtml40_font_tag_008(); void test_chtml40_font_tag_009(); + +/* CSS */ +void test_chtml40_link_001(); +void test_chtml40_link_002(); +void test_chtml40_link_003(); +void test_chtml40_link_004(); +void test_chtml40_link_005(); +void test_chtml40_link_006(); +void test_chtml40_link_007(); +void test_chtml40_link_008(); +void test_chtml40_link_009(); + +void test_chtml40_html_tag_with_css_001(); /* pend */ int @@ -935,6 +952,19 @@ main() CU_add_test(chtml40_suite, "test 7." , test_chtml40_font_tag_007); CU_add_test(chtml40_suite, "test 8." , test_chtml40_font_tag_008); CU_add_test(chtml40_suite, "test 9." , test_chtml40_font_tag_009); + + /* CSS */ + CU_add_test(chtml40_suite, "test link 001." , test_chtml40_link_001); + CU_add_test(chtml40_suite, "test link 002." , test_chtml40_link_002); + CU_add_test(chtml40_suite, "test link 003." , test_chtml40_link_003); + CU_add_test(chtml40_suite, "test link 004." , test_chtml40_link_004); + CU_add_test(chtml40_suite, "test link 005." , test_chtml40_link_005); + CU_add_test(chtml40_suite, "test link 006." , test_chtml40_link_006); + CU_add_test(chtml40_suite, "test link 007." , test_chtml40_link_007); + CU_add_test(chtml40_suite, "test link 008." , test_chtml40_link_008); + CU_add_test(chtml40_suite, "test link 009." , test_chtml40_link_009); + + CU_add_test(chtml40_suite, "test html with css 001", test_chtml40_html_tag_with_css_001); /* aend */ CU_basic_run_tests(); @@ -12714,6 +12744,349 @@ void test_chtml40_font_tag_009() #undef TEST_STRING #undef RESULT_STRING } + + +/* CSS */ +static int call_check = 0; +char *test_chxj_serf_get001(request_rec *r, apr_pool_t *ppool, const char *uri_path, int ss, apr_size_t *len) +{ + static char *css = "a:focus { display: none }\n" + "a:link { display: none }\n" + "a { display: none }\n" + "hr { display: none }\n" + "a:visited { display:none }"; + *len = strlen(css); + call_check = 1; + return css; +} +void test_chtml40_link_001() +{ +#define TEST_STRING "" +#define RESULT_STRING "\n" + char *ret; + char *tmp; + device_table spec; + chxjconvrule_entry entry; + cookie_t cookie; + apr_size_t destlen; + APR_INIT; + chxj_serf_get = test_chxj_serf_get001; + + call_check = 0; + COOKIE_INIT(cookie); + + SPEC_INIT(spec); + destlen = sizeof(TEST_STRING)-1; + + tmp = chxj_encoding(&r, TEST_STRING, &destlen); + ret = chxj_convert_chtml40(&r, &spec, tmp, destlen, &destlen, &entry, &cookie); + ret = chxj_rencoding(&r, ret, &destlen); + CU_ASSERT(ret != NULL); + CU_ASSERT(strcmp(RESULT_STRING, ret) == 0); + CU_ASSERT(destlen == sizeof(RESULT_STRING)-1); + CU_ASSERT(call_check == 1); + + APR_TERM; +#undef TEST_STRING +#undef RESULT_STRING +} +void test_chtml40_link_002() +{ +#define TEST_STRING "" +#define RESULT_STRING "\n" + char *ret; + char *tmp; + device_table spec; + chxjconvrule_entry entry; + cookie_t cookie; + apr_size_t destlen; + APR_INIT; + chxj_serf_get = test_chxj_serf_get001; + call_check = 0; + + COOKIE_INIT(cookie); + + SPEC_INIT(spec); + destlen = sizeof(TEST_STRING)-1; + + tmp = chxj_encoding(&r, TEST_STRING, &destlen); + ret = chxj_convert_chtml40(&r, &spec, tmp, destlen, &destlen, &entry, &cookie); + ret = chxj_rencoding(&r, ret, &destlen); + CU_ASSERT(ret != NULL); + CU_ASSERT(strcmp(RESULT_STRING, ret) == 0); + CU_ASSERT(destlen == sizeof(RESULT_STRING)-1); + CU_ASSERT(call_check == 0); + + APR_TERM; +#undef TEST_STRING +#undef RESULT_STRING +} +void test_chtml40_link_003() +{ +#define TEST_STRING "" +#define RESULT_STRING "\n" + char *ret; + char *tmp; + device_table spec; + chxjconvrule_entry entry; + cookie_t cookie; + apr_size_t destlen; + APR_INIT; + chxj_serf_get = test_chxj_serf_get001; + call_check = 0; + + COOKIE_INIT(cookie); + + SPEC_INIT(spec); + destlen = sizeof(TEST_STRING)-1; + + tmp = chxj_encoding(&r, TEST_STRING, &destlen); + ret = chxj_convert_chtml40(&r, &spec, tmp, destlen, &destlen, &entry, &cookie); + ret = chxj_rencoding(&r, ret, &destlen); + CU_ASSERT(ret != NULL); + CU_ASSERT(strcmp(RESULT_STRING, ret) == 0); + CU_ASSERT(destlen == sizeof(RESULT_STRING)-1); + CU_ASSERT(call_check == 0); + + APR_TERM; +#undef TEST_STRING +#undef RESULT_STRING +} +void test_chtml40_link_004() +{ +#define TEST_STRING "" +#define RESULT_STRING "\n" + char *ret; + char *tmp; + device_table spec; + chxjconvrule_entry entry; + cookie_t cookie; + apr_size_t destlen; + APR_INIT; + chxj_serf_get = test_chxj_serf_get001; + call_check = 0; + + COOKIE_INIT(cookie); + + SPEC_INIT(spec); + destlen = sizeof(TEST_STRING)-1; + + tmp = chxj_encoding(&r, TEST_STRING, &destlen); + ret = chxj_convert_chtml40(&r, &spec, tmp, destlen, &destlen, &entry, &cookie); + ret = chxj_rencoding(&r, ret, &destlen); + CU_ASSERT(ret != NULL); + CU_ASSERT(strcmp(RESULT_STRING, ret) == 0); + CU_ASSERT(destlen == sizeof(RESULT_STRING)-1); + CU_ASSERT(call_check == 0); + + APR_TERM; +#undef TEST_STRING +#undef RESULT_STRING +} +void test_chtml40_link_005() +{ +#define TEST_STRING "" +#define RESULT_STRING "\n" + char *ret; + char *tmp; + device_table spec; + chxjconvrule_entry entry; + cookie_t cookie; + apr_size_t destlen; + APR_INIT; + chxj_serf_get = test_chxj_serf_get001; + call_check = 0; + + COOKIE_INIT(cookie); + + SPEC_INIT(spec); + destlen = sizeof(TEST_STRING)-1; + + tmp = chxj_encoding(&r, TEST_STRING, &destlen); + ret = chxj_convert_chtml40(&r, &spec, tmp, destlen, &destlen, &entry, &cookie); + ret = chxj_rencoding(&r, ret, &destlen); + CU_ASSERT(ret != NULL); + CU_ASSERT(strcmp(RESULT_STRING, ret) == 0); + CU_ASSERT(destlen == sizeof(RESULT_STRING)-1); + CU_ASSERT(call_check == 0); + + APR_TERM; +#undef TEST_STRING +#undef RESULT_STRING +} +void test_chtml40_link_006() +{ +#define TEST_STRING "" +#define RESULT_STRING "\n" + char *ret; + char *tmp; + device_table spec; + chxjconvrule_entry entry; + cookie_t cookie; + apr_size_t destlen; + APR_INIT; + chxj_serf_get = test_chxj_serf_get001; + call_check = 0; + + COOKIE_INIT(cookie); + + SPEC_INIT(spec); + destlen = sizeof(TEST_STRING)-1; + + tmp = chxj_encoding(&r, TEST_STRING, &destlen); + ret = chxj_convert_chtml40(&r, &spec, tmp, destlen, &destlen, &entry, &cookie); + ret = chxj_rencoding(&r, ret, &destlen); + CU_ASSERT(ret != NULL); + CU_ASSERT(strcmp(RESULT_STRING, ret) == 0); + CU_ASSERT(destlen == sizeof(RESULT_STRING)-1); + CU_ASSERT(call_check == 0); + + APR_TERM; +#undef TEST_STRING +#undef RESULT_STRING +} +void test_chtml40_link_007() +{ +#define TEST_STRING "" +#define RESULT_STRING "\n" + char *ret; + char *tmp; + device_table spec; + chxjconvrule_entry entry; + cookie_t cookie; + apr_size_t destlen; + APR_INIT; + chxj_serf_get = test_chxj_serf_get001; + call_check = 0; + + COOKIE_INIT(cookie); + + SPEC_INIT(spec); + destlen = sizeof(TEST_STRING)-1; + + tmp = chxj_encoding(&r, TEST_STRING, &destlen); + ret = chxj_convert_chtml40(&r, &spec, tmp, destlen, &destlen, &entry, &cookie); + ret = chxj_rencoding(&r, ret, &destlen); + CU_ASSERT(ret != NULL); + CU_ASSERT(strcmp(RESULT_STRING, ret) == 0); + CU_ASSERT(destlen == sizeof(RESULT_STRING)-1); + CU_ASSERT(call_check == 0); + + APR_TERM; +#undef TEST_STRING +#undef RESULT_STRING +} +void test_chtml40_link_008() +{ +#define TEST_STRING "" +#define RESULT_STRING "\n" + char *ret; + char *tmp; + device_table spec; + chxjconvrule_entry entry; + cookie_t cookie; + apr_size_t destlen; + APR_INIT; + chxj_serf_get = test_chxj_serf_get001; + call_check = 0; + + COOKIE_INIT(cookie); + + SPEC_INIT(spec); + destlen = sizeof(TEST_STRING)-1; + + tmp = chxj_encoding(&r, TEST_STRING, &destlen); + ret = chxj_convert_chtml40(&r, &spec, tmp, destlen, &destlen, &entry, &cookie); + ret = chxj_rencoding(&r, ret, &destlen); + CU_ASSERT(ret != NULL); + CU_ASSERT(strcmp(RESULT_STRING, ret) == 0); + CU_ASSERT(destlen == sizeof(RESULT_STRING)-1); + CU_ASSERT(call_check == 0); + + APR_TERM; +#undef TEST_STRING +#undef RESULT_STRING +} +void test_chtml40_link_009() +{ +#define TEST_STRING "" +#define RESULT_STRING "\n" + char *ret; + char *tmp; + device_table spec; + chxjconvrule_entry entry; + cookie_t cookie; + apr_size_t destlen; + APR_INIT; + chxj_serf_get = test_chxj_serf_get001; + call_check = 0; + + COOKIE_INIT(cookie); + + SPEC_INIT(spec); + destlen = sizeof(TEST_STRING)-1; + + tmp = chxj_encoding(&r, TEST_STRING, &destlen); + ret = chxj_convert_chtml40(&r, &spec, tmp, destlen, &destlen, &entry, &cookie); + ret = chxj_rencoding(&r, ret, &destlen); + CU_ASSERT(ret != NULL); + CU_ASSERT(strcmp(RESULT_STRING, ret) == 0); + CU_ASSERT(destlen == sizeof(RESULT_STRING)-1); + CU_ASSERT(call_check == 0); + + APR_TERM; +#undef TEST_STRING +#undef RESULT_STRING +} + + + +/*===========================================================================*/ +/* HTML tag with CSS */ +/*===========================================================================*/ +char *test_chxj_serf_get002(request_rec *r, apr_pool_t *ppool, const char *uri_path, int ss, apr_size_t *len) +{ + static char *css = "a:focus { display: none }\n" + "a:link { display: none }\n" + "a { display: none }\n" + "hr { display: none }\n" + "a:visited { display:none }\n" + "html { display: none }\n"; + *len = strlen(css); + call_check = 1; + return css; +} +void test_chtml40_html_tag_with_css_001() +{ +#define TEST_STRING "" +#define RESULT_STRING "" + char *ret; + char *tmp; + device_table spec; + chxjconvrule_entry entry; + cookie_t cookie; + apr_size_t destlen; + APR_INIT; + chxj_serf_get = test_chxj_serf_get002; + call_check = 0; + + COOKIE_INIT(cookie); + + SPEC_INIT(spec); + destlen = sizeof(TEST_STRING)-1; + + tmp = chxj_encoding(&r, TEST_STRING, &destlen); + ret = chxj_convert_chtml40(&r, &spec, tmp, destlen, &destlen, &entry, &cookie); + ret = chxj_rencoding(&r, ret, &destlen); + CU_ASSERT(ret != NULL); + CU_ASSERT(strcmp(RESULT_STRING, ret) == 0); + CU_ASSERT(destlen == sizeof(RESULT_STRING)-1); + CU_ASSERT(call_check == 1); + + APR_TERM; +#undef TEST_STRING +#undef RESULT_STRING +} /* * vim:ts=2 et */ -- 2.11.0