<commit_before>/*
 * Copyright (C) 2005 QSDN,Inc. All rights reserved.
 * Copyright (C) 2005 <NAME> All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#include "chxj_chtml10.h"
#include "chxj_hdml.h"
#include "chxj_dump.h"
#include "chxj_img_conv.h"
#include "chxj_qr_code.h"
#include "chxj_cookie.h"

#define GET_CHTML10(X) ((chtml10_t*)(X))

static char* s_chtml10_start_html_tag     (void* pdoc, Node* node);
static char* s_chtml10_end_html_tag       (void* pdoc, Node* node);
static char* s_chtml10_start_meta_tag     (void* pdoc, Node* node);
static char* s_chtml10_end_meta_tag       (void* pdoc, Node* node);
static char* s_chtml10_start_textarea_tag (void* pdoc, Node* node);
static char* s_chtml10_end_textarea_tag   (void* pdoc, Node* node);
static char* s_chtml10_start_p_tag        (void* pdoc, Node* node);
static char* s_chtml10_end_p_tag          (void* pdoc, Node* node);
static char* s_chtml10_start_pre_tag      (void* pdoc, Node* node);
static char* s_chtml10_end_pre_tag        (void* pdoc, Node* node);
static char* s_chtml10_start_ul_tag       (void* pdoc, Node* node);
static char* s_chtml10_end_ul_tag         (void* pdoc, Node* node);
static char* s_chtml10_start_li_tag       (void* pdoc, Node* node);
static char* s_chtml10_end_li_tag         (void* pdoc, Node* node);
static char* s_chtml10_start_ol_tag       (void* pdoc, Node* node);
static char* s_chtml10_end_ol_tag         (void* pdoc, Node* node);
static char* s_chtml10_start_h1_tag       (void* pdoc, Node* node);
static char* s_chtml10_end_h1_tag         (void* pdoc, Node* node);
static char* s_chtml10_start_h2_tag       (void* pdoc, Node* node);
static char* s_chtml10_end_h2_tag         (void* pdoc, Node* node);
static char* s_chtml10_start_h3_tag       (void* pdoc, Node* node);
static char* s_chtml10_end_h3_tag         (void* pdoc, Node* node);
static char* s_chtml10_start_h4_tag       (void* pdoc, Node* node);
static char* s_chtml10_end_h4_tag         (void* pdoc, Node* node);
static char* s_chtml10_start_h5_tag       (void* pdoc, Node* node);
static char* s_chtml10_end_h5_tag         (void* pdoc, Node* node);
static char* s_chtml10_start_h6_tag       (void* pdoc, Node* node);
static char* s_chtml10_end_h6_tag         (void* pdoc, Node* node);
static char* s_chtml10_start_head_tag     (void* pdoc, Node* node);
static char* s_chtml10_end_head_tag       (void* pdoc, Node* node);
static char* s_chtml10_start_title_tag    (void* pdoc, Node* node);
static char* s_chtml10_end_title_tag      (void* pdoc, Node* node);
static char* s_chtml10_start_base_tag     (void* pdoc, Node* node);
static char* s_chtml10_end_base_tag       (void* pdoc, Node* node);
static char* s_chtml10_start_body_tag     (void* pdoc, Node* node);
static char* s_chtml10_end_body_tag       (void* pdoc, Node* node);
static char* s_chtml10_start_a_tag        (void* pdoc, Node* node);
static char* s_chtml10_end_a_tag          (void* pdoc, Node* node);
static char* s_chtml10_start_br_tag       (void* pdoc, Node* node);
static char* s_chtml10_end_br_tag         (void* pdoc, Node* node);
static char* s_chtml10_start_tr_tag       (void* pdoc, Node* node);
static char* s_chtml10_end_tr_tag         (void* pdoc, Node* node);
static char* s_chtml10_start_font_tag     (void* pdoc, Node* node);
static char* s_chtml10_end_font_tag       (void* pdoc, Node* node);
static char* s_chtml10_start_input_tag    (void* pdoc, Node* node);
static char* s_chtml10_end_input_tag      (void* pdoc, Node* node);
static char* s_chtml10_start_form_tag     (void* pdoc, Node* node);
static char* s_chtml10_end_form_tag       (void* pdoc, Node* node);
static char* s_chtml10_start_center_tag   (void* pdoc, Node* node);
static char* s_chtml10_end_center_tag     (void* pdoc, Node* node);
static char* s_chtml10_start_hr_tag       (void* pdoc, Node* node);
static char* s_chtml10_end_hr_tag         (void* pdoc, Node* node);
static char* s_chtml10_start_img_tag      (void* pdoc, Node* node);
static char* s_chtml10_end_img_tag        (void* pdoc, Node* node);
static char* s_chtml10_start_select_tag   (void* pdoc, Node* node);
static char* s_chtml10_end_select_tag     (void* pdoc, Node* node);
static char* s_chtml10_start_option_tag   (void* pdoc, Node* node);
static char* s_chtml10_end_option_tag     (void* pdoc, Node* node);
static char* s_chtml10_start_div_tag      (void* pdoc, Node* node);
static char* s_chtml10_end_div_tag        (void* pdoc, Node* node);

static void  s_init_chtml10(chtml10_t* chtml, Doc* doc, request_rec* r, device_table* spec);

static int   s_chtml10_search_emoji(chtml10_t* chtml, char* txt, char** rslt);
static char* s_chtml10_chxjif_tag        (void* pdoc, Node* node);
static char* s_chtml10_text              (void* pdoc, Node* node);

tag_handler chtml10_handler[] = {
  /* tagHTML */
  {
    s_chtml10_start_html_tag,
    s_chtml10_end_html_tag,
  },
  /* tagMETA */
  {
    s_chtml10_start_meta_tag,
    s_chtml10_end_meta_tag,
  },
  /* tagTEXTAREA */
  {
    s_chtml10_start_textarea_tag,
    s_chtml10_end_textarea_tag,
  },
  /* tagP */
  {
    s_chtml10_start_p_tag,
    s_chtml10_end_p_tag,
  },
  /* tagPRE */
  {
    s_chtml10_start_pre_tag,
    s_chtml10_end_pre_tag,
  },
  /* tagUL */
  {
    s_chtml10_start_ul_tag,
    s_chtml10_end_ul_tag,
  },
  /* tagLI */
  {
    s_chtml10_start_li_tag,
    s_chtml10_end_li_tag,
  },
  /* tagOL */
  {
    s_chtml10_start_ol_tag,
    s_chtml10_end_ol_tag,
  },
  /* tagH1 */
  {
    s_chtml10_start_h1_tag,
    s_chtml10_end_h1_tag,
  },
  /* tagH2 */
  {
    s_chtml10_start_h2_tag,
    s_chtml10_end_h2_tag,
  },
  /* tagH3 */
  {
    s_chtml10_start_h3_tag,
    s_chtml10_end_h3_tag,
  },
  /* tagH4 */
  {
    s_chtml10_start_h4_tag,
    s_chtml10_end_h4_tag,
  },
  /* tagH5 */
  {
    s_chtml10_start_h5_tag,
    s_chtml10_end_h5_tag,
  },
  /* tagH6 */
  {
    s_chtml10_start_h6_tag,
    s_chtml10_end_h6_tag,
  },
  /* tagHEAD */
  {
    s_chtml10_start_head_tag,
    s_chtml10_end_head_tag,
  },
  /* tagTITLE */
  {
    s_chtml10_start_title_tag,
    s_chtml10_end_title_tag,
  },
  /* tagBASE */
  {
    s_chtml10_start_base_tag,
    s_chtml10_end_base_tag,
  },
  /* tagBODY */
  {
    s_chtml10_start_body_tag,
    s_chtml10_end_body_tag,
  },
  /* tagA */
  {
    s_chtml10_start_a_tag,
    s_chtml10_end_a_tag,
  },
  /* tagBR */
  {
    s_chtml10_start_br_tag,
    s_chtml10_end_br_tag,
  },
  /* tagTABLE */
  {
    NULL,
    NULL,
  },
  /* tagTR */
  {
    s_chtml10_start_tr_tag,
    s_chtml10_end_tr_tag,
  },
  /* tagTD */
  {
    NULL,
    NULL,
  },
  /* tagTBODY */
  {
    NULL,
    NULL,
  },
  /* tagFONT */
  {
    s_chtml10_start_font_tag,
    s_chtml10_end_font_tag,
  },
  /* tagFORM */
  {
    s_chtml10_start_form_tag,
    s_chtml10_end_form_tag,
  },
  /* tagINPUT */
  {
    s_chtml10_start_input_tag,
    s_chtml10_end_input_tag,
  },
  /* tagCENTER */
  {
    s_chtml10_start_center_tag,
    s_chtml10_end_center_tag,
  },
  /* tagHR */
  {
    s_chtml10_start_hr_tag,
    s_chtml10_end_hr_tag,
  },
  /* tagIMG */
  {
    s_chtml10_start_img_tag,
    s_chtml10_end_img_tag,
  },
  /* tagSELECT */
  {
    s_chtml10_start_select_tag,
    s_chtml10_end_select_tag,
  },
  /* tagOPTION */
  {
    s_chtml10_start_option_tag,
    s_chtml10_end_option_tag,
  },
  /* tagDIV */
  {
    s_chtml10_start_div_tag,
    s_chtml10_end_div_tag,
  },
  /* tagCHXJIF */
  {
    s_chtml10_chxjif_tag,
    NULL,
  },
  /* tagNOBR */
  {
    NULL,
    NULL,
  },
  /* tagSMALL */
  {
    NULL,
    NULL,
  },
  /* tagSTYLE */
  {
    NULL,
    NULL,
  },
  /* tagSPAN */
  {
    NULL,
    NULL,
  },
  /* tagTEXT */
  {
    s_chtml10_text,
    NULL,
  },
  /* tagTH */
  {
    NULL,
    NULL,
  },
  /* tagB */
  {
    NULL,
    NULL,
  },
};


/**
 * converts from CHTML5.0 to CHTML1.0.
 *
 * @param r     [i]   Requet_rec is appointed.
 * @param spec  [i]   The result of the device specification processing which 
 *                    was done in advance is appointed.
 * @param src   [i]   The character string before the converting is appointed.
 * @return The character string after the converting is returned.
 */
char*
chxj_exchange_chtml10(
  request_rec*        r,
  device_table*       spec,
  const char*         src,
  apr_size_t          srclen,
  apr_size_t*         dstlen,
  chxjconvrule_entry* entryp,
  const char*         cookie_id
)
{
  char*     dst;
  char*     ss;
  chtml10_t chtml10;
  Doc       doc;

  dst = NULL;

  DBG1(r, "start chxj_exchange_chtml10() cookie_id=[%s]", cookie_id);

  /*--------------------------------------------------------------------------*/
  /* If qrcode xml                                                            */
  /*--------------------------------------------------------------------------*/
  *dstlen = srclen;
  dst = chxj_qr_code_blob_handler(r, src, (size_t*)dstlen);
  if (dst) {
    DBG(r,"i found qrcode xml");
    return dst;
  }
  DBG(r,"not found qrcode xml");

  /*--------------------------------------------------------------------------*/
  /* The CHTML structure is initialized.                                      */
  /*--------------------------------------------------------------------------*/
  s_init_chtml10(&chtml10, &doc, r, spec);
  chtml10.entryp    = entryp;
  chtml10.cookie_id = (char*)cookie_id;

  ap_set_content_type(r, "text/html; charset=Windows-31J");

  /*--------------------------------------------------------------------------*/
  /* The character string of the input is analyzed.                           */
  /*--------------------------------------------------------------------------*/
  qs_init_malloc(&doc);
  qs_init_root_node(&doc);

  ss = apr_pcalloc(r->pool, srclen + 1);
  memset(ss, 0,   srclen + 1);
  memcpy(ss, src, srclen);

#ifdef DUMP_LOG
  chxj_dump_out("[src] CHTML -> CHTML1.0", ss, srclen);
#endif

  qs_parse_string(&doc,ss, strlen(ss));

  /*--------------------------------------------------------------------------*/
  /* It converts it from CHTML to CHTML.                                      */
  /*--------------------------------------------------------------------------*/
  chxj_node_exchange(spec,r,(void*)&chtml10, &doc, qs_get_root(&doc), 0);
  dst = chtml10.out;


  qs_all_free(&doc,QX_LOGMARK);

  if (!dst)
    return apr_pstrdup(r->pool,ss);

  if (strlen(dst) == 0) {
    dst = apr_psprintf(r->pool, "\n");
  }
  *dstlen = strlen(dst);

#ifdef DUMP_LOG
  chxj_dump_out("[dst] CHTML -> CHTML1.0", dst, *dstlen);
#endif

  DBG1(r, "end   chxj_exchange_chtml10() cookie_id=[%s]", cookie_id);

  return dst;
}


/**
 * The CHTML structure is initialized.
 *
 * @param chtml10 [i/o] The pointer to the HDML structure that wants to be
 *                   initialized is specified.
 * @param doc   [i]   The Doc structure that should be set to the initialized
 *                   HDML structure is specified.
 * @param r     [i]   To use POOL, the pointer to request_rec is specified.
 * @param spec  [i]   The pointer to the device_table
 */
static void
s_init_chtml10(
  chtml10_t*    chtml10, 
  Doc*          doc, 
  request_rec*  r, 
  device_table* spec)
{
  memset(doc,     0, sizeof(Doc));
  memset(chtml10, 0, sizeof(chtml10_t));

  doc->r      = r;
  chtml10->doc  = doc;
  chtml10->spec = spec;
  chtml10->out  = qs_alloc_zero_byte_string(r);
  chtml10->conf = ap_get_module_config(r->per_dir_config, &chxj_module);
  chtml10->doc->parse_mode = PARSE_MODE_CHTML;
}


/**
 * Corresponding EMOJI to a current character-code is retrieved. 
 * The substitution character string is stored in the rslt pointer if agreeing.
 *
 * @param chtml10   [i]   The pointer to the CHTML structure is specified. 
 * @param txt     [i]   The character string to want to examine whether it is 
 *                      EMOJI is specified. 
 * @param rslt    [o]   The pointer to the pointer that stores the result is 
 *                      specified. 
 * @return When corresponding EMOJI exists, it returns it excluding 0. 
 */
static int
s_chtml10_search_emoji(chtml10_t* chtml10, char* txt, char** rslt)
{
  emoji_t*      ee;
  request_rec*  r;
  device_table* spec;
  int           len;

  spec = chtml10->spec;

  len = strlen(txt);
  r = chtml10->doc->r;

  if (!spec) {
    DBG(r,"spec is NULL");
  }

  for (ee = chtml10->conf->emoji;
       ee;
       ee = ee->next) {

    if (!ee->imode) {
      DBG(r,"emoji->imode is NULL");
      continue;
    }

    if (ee->imode->string
    &&  txt
    &&  strlen(ee->imode->string) > 0
    &&  *ee->imode->string == *txt
    &&  strncasecmp(ee->imode->string, txt, strlen(ee->imode->string)) == 0) {
      if (!spec || !spec->emoji_type) {
        *rslt = apr_palloc(r->pool, 3);
        (*rslt)[0] = ee->imode->hex1byte & 0xff;
        (*rslt)[1] = ee->imode->hex2byte & 0xff;
        (*rslt)[2] = 0;
        return strlen(ee->imode->string);
      }

      return 0;
    }
  }
  return 0;
}


/**
 * It is a handler who processes the HTML tag.
 *
 * @param chtml10  [i/o] The pointer to the CHTML structure at the output
 *                     destination is specified.
 * @param node   [i]   The HTML tag node is specified.
 * @return The conversion result is returned.
 */
static char*
s_chtml10_start_html_tag(void* pdoc, Node* node) 
{
  Doc*          doc;
  request_rec*  r;
  chtml10_t*    chtml10;

  chtml10 = GET_CHTML10(pdoc);
  doc     = chtml10->doc;
  r       = doc->r;

  /*--------------------------------------------------------------------------*/
  /* start HTML tag                                                           */
  /*--------------------------------------------------------------------------*/
  chtml10->out = apr_pstrcat(r->pool, chtml10->out, "<html>\n", NULL);

  return chtml10->out;
}


/**
 * It is a handler who processes the HTML tag.
 *
 * @param pdoc  [i/o] The pointer to the CHTML structure at the output
 *                     destination is specified.
 * @param node   [i]   The HTML tag node is specified.
 * @return The conversion result is returned.
 */
static char*
s_chtml10_end_html_tag(void* pdoc, Node* child) 
{
  Doc*          doc;
  request_rec*  r;
  chtml10_t*    chtml10;

  
  chtml10 = GET_CHTML10(pdoc);
  doc     = chtml10->doc;
  r       = doc->r;

  chtml10->out = apr_pstrcat(r->pool, chtml10->out, "</html>\n", NULL);

  return chtml10->out;
}


/**
 * It is a handler who processes the META tag.
 *
 * @param pdoc  [i/o] The pointer to the CHTML structure at the output
 *                     destination is specified.
 * @param node   [i]   The META tag node is specified.
 * @return The conversion result is returned.
 */
static char*
s_chtml10_start_meta_tag(void* pdoc, Node* node) 
{
  chtml10_t* chtml10;

  chtml10 = GET_CHTML10(pdoc);

  /* ignore */

  return chtml10->out;
}


/**
 * It is a handler who processes the META tag.
 *
 * @param pdoc  [i/o] The pointer to the CHTML structure at the output
 *                     destination is specified.
 * @param node   [i]   The META tag node is specified.
 * @return The conversion result is returned.
 */
static char*
s_chtml10_end_meta_tag(void* pdoc, Node* child) 
{
  chtml10_t* chtml10;

  chtml10 = GET_CHTML10(pdoc);

  return chtml10->out;
}


/**
 * It is a handler who processes the HEAD tag.
 *
 * @param pdoc  [i/o] The pointer to the CHTML structure at the output
 *                     destination is specified.
 * @param node   [i]   The HEAD tag node is specified.
 * @return The conversion result is returned.
 */
static char*
s_chtml10_start_head_tag(void* pdoc, Node* node) 
{
  Doc*          doc;
  request_rec*  r;
  chtml10_t*    chtml10;

  chtml10 = GET_CHTML10(pdoc);
  doc     = chtml10->doc;
  r       = doc->r;

  chtml10->out = apr_pstrcat(r->pool, chtml10->out, "<head>\r\n", NULL);

  return chtml10->out;
}


/**
 * It is a handler who processes the HEAD tag.
 *
 * @param pdoc  [i/o] The pointer to the CHTML structure at the output
 *                     destination is specified.
 * @param node   [i]   The HEAD tag node is specified.
 * @return The conversion result is returned.
 */
static char*
s_chtml10_end_head_tag(void* pdoc, Node* child) 
{
  Doc*          doc;
  request_rec*  r;
  chtml10_t*    chtml10;

  chtml10 = GET_CHTML10(pdoc);
  doc     = chtml10->doc;
  r       = doc->r;

  chtml10->out = apr_pstrcat(r->pool, chtml10->out, "</head>\r\n", NULL);

  return chtml10->out;
}


/**
 * It is a handler who processes the OL tag.
 *
 * @param pdoc  [i/o] The pointer to the CHTML structure at the output
 *                     destination is specified.
 * @param node   [i]   The OL tag node is specified.
 * @return The conversion result is returned.
 */
static char*
s_chtml10_start_ol_tag(void* pdoc, Node* node) 
{
  Doc*          doc;
  request_rec*  r;
  chtml10_t*    chtml10;

  chtml10 = GET_CHTML10(pdoc);
  doc     = chtml10->doc;
  r       = doc->r;

  chtml10->out = apr_pstrcat(r->pool, chtml10->out, "<ol>\r\n", NULL);

  return chtml10->out;
}


/**
 * It is a handler who processes the OL tag.
 *
 * @param pdoc  [i/o] The pointer to the CHTML structure at the output
 *                     destination is specified.
 * @param node   [i]   The OL tag node is specified.
 * @return The conversion result is returned.
 */
static char*
s_chtml10_end_ol_tag(void* pdoc, Node* child) 
{
  Doc*          doc;
  request_rec*  r;
  chtml10_t*    chtml10;

  chtml10 = GET_CHTML10(pdoc);
  doc     = chtml10->doc;
  r       = doc->r;

  chtml10->out = apr_pstrcat(r->pool, chtml10->out, "</ol>\r\n", NULL);

  return chtml10->out;
}


/**
 * It is a handler who processes the UL tag.
 *
 * @param pdoc  [i/o] The pointer to the CHTML structure at the output
 *                     destination is specified.
 * @param node   [i]   The UL tag node is specified.
 * @return The conversion result is returned.
 */
static char*
s_chtml10_start_ul_tag(void* pdoc, Node* node) 
{
  Doc*          doc;
  request_rec*  r;
  chtml10_t*    chtml10;

  chtml10    = GET_CHTML10(pdoc);
  doc        = chtml10->doc;
  r          = doc->r;

  chtml10->out = apr_pstrcat(r->pool, chtml10->out, "<ul>\r\n", NULL);

  return chtml10->out;
}


/**
 * It is a handler who processes the UL tag.
 *
 * @param pdoc  [i/o] The pointer to the CHTML structure at the output
 *                     destination is specified.
 * @param node   [i]   The UL tag node is specified.
 * @return The conversion result is returned.
 */
static char*
s_chtml10_end_ul_tag(void* pdoc, Node* child) 
{
  Doc*          doc;
  request_rec*  r;
  chtml10_t*    chtml10;

  chtml10 = GET_CHTML10(pdoc);
  doc     = chtml10->doc;
  r       = doc->r;

  chtml10->out = apr_pstrcat(r->pool, chtml10->out, "</ul>\r\n", NULL);

  return chtml10->out;
}


/**
 * It is a handler who processes the LI tag.
 *
 * @param pdoc  [i/o] The pointer to the CHTML structure at the output
 *                     destination is specified.
 * @param node   [i]   The LI tag node is specified.
 * @return The conversion result is returned.
 */
static char*
s_chtml10_start_li_tag(void* pdoc, Node* node) 
{
  Doc*          doc;
  request_rec*  r;
  chtml10_t*    chtml10;

  chtml10 = GET_CHTML10(pdoc);
  doc     = chtml10->doc;
  r       = doc->r;

  chtml10->out = apr_pstrcat(r->pool, chtml10->out, "<li>\r\n", NULL);

  return chtml10->out;
}


/**
 * It is a handler who processes the LI tag.
 *
 * @param pdoc  [i/o] The pointer to the CHTML structure at the output
 *                     destination is specified.
 * @param node   [i]   The LI tag node is specified.
 * @return The conversion result is returned.
 */
static char*
s_chtml10_end_li_tag(void* pdoc, Node* child) 
{
  chtml10_t*    chtml10;
  Doc*          doc;
  request_rec*  r;

  chtml10 = GET_CHTML10(pdoc);
  doc     = chtml10->doc;
  r       = doc->r;

  chtml10->out = apr_pstrcat(r->pool, chtml10->out, "</li>\r\n", NULL);

  return chtml10->out;
}


/**
 * It is a handler who processes the H1 tag.
 *
 * @param pdoc  [i/o] The pointer to the CHTML structure at the output
 *                     destination is specified.
 * @param node   [i]   The H1 tag node is specified.
 * @return The conversion result is returned.
 */
static char*
s_chtml10_start_h1_tag(void* pdoc, Node* node) 
{
  Doc*          doc;
  request_rec*  r;
  chtml10_t*    chtml10;

  chtml10 = GET_CHTML10(pdoc);
  doc     = chtml10->doc;
  r       = doc->r;

  chtml10->out = apr_pstrcat(r->pool, chtml10->out, "<h1>\r\n", NULL);

  return chtml10->out;
}


/**
 * It is a handler who processes the H1 tag.
 *
 * @param pdoc  [i/o] The pointer to the CHTML structure at the output
 *                     destination is specified.
 * @param node   [i]   The H1 tag node is specified.
 * @return The conversion result is returned.
 */
static char*
s_chtml10_end_h1_tag(void* pdoc, Node* child) 
{
  Doc*          doc;
  request_rec*  r;
  chtml10_t*    chtml10;

  chtml10 = GET_CHTML10(pdoc);
  doc     = chtml10->doc;
  r       = doc->r;

  chtml10->out = apr_pstrcat(r->pool, chtml10->out, "</h1>\r\n", NULL);

  return chtml10->out;
}


/**
 * It is a handler who processes the H2 tag.
 *
 * @param pdoc  [i/o] The pointer to the CHTML structure at the output
 *                     destination is specified.
 * @param node   [i]   The H2 tag node is specified.
 * @return The conversion result is returned.
 */
static char*
s_chtml10_start_h2_tag(void* pdoc, Node* node) 
{
  Doc*          doc;
  request_rec*  r;
  chtml10_t*    chtml10;

  chtml10 = GET_CHTML10(pdoc);
  doc     = chtml10->doc;
  r       = doc->r;

  chtml10->out = apr_pstrcat(r->pool, chtml10->out, "<h2>\r\n", NULL);

  return chtml10->out;
}


/**
 * It is a handler who processes the H2 tag.
 *
 * @param pdoc  [i/o] The pointer to the CHTML structure at the output
 *                     destination is specified.
 * @param node   [i]   The H2 tag node is specified.
 * @return The conversion result is returned.
 */
static char*
s_chtml10_end_h2_tag(void* pdoc, Node* child) 
{
  Doc*          doc;
  request_rec*  r;
  chtml10_t*    chtml10;

  chtml10 = GET_CHTML10(pdoc);
  doc     = chtml10->doc;
  r       = doc->r;

  chtml10->out = apr_pstrcat(r->pool, chtml10->out, "</h2>\r\n", NULL);

  return chtml10->out;
}

/**
 * It is a handler who processes the H3 tag.
 *
 * @param pdoc  [i/o] The pointer to the CHTML structure at the output
 *                     destination is specified.
 * @param node   [i]   The H3 tag node is specified.
 * @return The conversion result is returned.
 */
static char*
s_chtml10_start_h3_tag(void* pdoc, Node* node) 
{
  Doc*          doc;
  request_rec*  r;
  chtml10_t*    chtml10;

  chtml10 = GET_CHTML10(pdoc);
  doc     = chtml10->doc;<commit_msg>  * change writting.<commit_after>/*
 * Copyright (C) 2005 QSDN,Inc. All rights reserved.
 * Copyright (C) 2005 <NAME> All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#include "chxj_chtml10.h"
#include "chxj_hdml.h"
#include "chxj_dump.h"
#include "chxj_img_conv.h"
#include "chxj_qr_code.h"
#include "chxj_cookie.h"

#define GET_CHTML10(X) ((chtml10_t*)(X))

static char* s_chtml10_start_html_tag     (void* pdoc, Node* node);
static char* s_chtml10_end_html_tag       (void* pdoc, Node* node);
static char* s_chtml10_start_meta_tag     (void* pdoc, Node* node);
static char* s_chtml10_end_meta_tag       (void* pdoc, Node* node);
static char* s_chtml10_start_textarea_tag (void* pdoc, Node* node);
static char* s_chtml10_end_textarea_tag   (void* pdoc, Node* node);
static char* s_chtml10_start_p_tag        (void* pdoc, Node* node);
static char* s_chtml10_end_p_tag          (void* pdoc, Node* node);
static char* s_chtml10_start_pre_tag      (void* pdoc, Node* node);
static char* s_chtml10_end_pre_tag        (void* pdoc, Node* node);
static char* s_chtml10_start_ul_tag       (void* pdoc, Node* node);
static char* s_chtml10_end_ul_tag         (void* pdoc, Node* node);
static char* s_chtml10_start_li_tag       (void* pdoc, Node* node);
static char* s_chtml10_end_li_tag         (void* pdoc, Node* node);
static char* s_chtml10_start_ol_tag       (void* pdoc, Node* node);
static char* s_chtml10_end_ol_tag         (void* pdoc, Node* node);
static char* s_chtml10_start_h1_tag       (void* pdoc, Node* node);
static char* s_chtml10_end_h1_tag         (void* pdoc, Node* node);
static char* s_chtml10_start_h2_tag       (void* pdoc, Node* node);
static char* s_chtml10_end_h2_tag         (void* pdoc, Node* node);
static char* s_chtml10_start_h3_tag       (void* pdoc, Node* node);
static char* s_chtml10_end_h3_tag         (void* pdoc, Node* node);
static char* s_chtml10_start_h4_tag       (void* pdoc, Node* node);
static char* s_chtml10_end_h4_tag         (void* pdoc, Node* node);
static char* s_chtml10_start_h5_tag       (void* pdoc, Node* node);
static char* s_chtml10_end_h5_tag         (void* pdoc, Node* node);
static char* s_chtml10_start_h6_tag       (void* pdoc, Node* node);
static char* s_chtml10_end_h6_tag         (void* pdoc, Node* node);
static char* s_chtml10_start_head_tag     (void* pdoc, Node* node);
static char* s_chtml10_end_head_tag       (void* pdoc, Node* node);
static char* s_chtml10_start_title_tag    (void* pdoc, Node* node);
static char* s_chtml10_end_title_tag      (void* pdoc, Node* node);
static char* s_chtml10_start_base_tag     (void* pdoc, Node* node);
static char* s_chtml10_end_base_tag       (void* pdoc, Node* node);
static char* s_chtml10_start_body_tag     (void* pdoc, Node* node);
static char* s_chtml10_end_body_tag       (void* pdoc, Node* node);
static char* s_chtml10_start_a_tag        (void* pdoc, Node* node);
static char* s_chtml10_end_a_tag          (void* pdoc, Node* node);
static char* s_chtml10_start_br_tag       (void* pdoc, Node* node);
static char* s_chtml10_end_br_tag         (void* pdoc, Node* node);
static char* s_chtml10_start_tr_tag       (void* pdoc, Node* node);
static char* s_chtml10_end_tr_tag         (void* pdoc, Node* node);
static char* s_chtml10_start_font_tag     (void* pdoc, Node* node);
static char* s_chtml10_end_font_tag       (void* pdoc, Node* node);
static char* s_chtml10_start_input_tag    (void* pdoc, Node* node);
static char* s_chtml10_end_input_tag      (void* pdoc, Node* node);
static char* s_chtml10_start_form_tag     (void* pdoc, Node* node);
static char* s_chtml10_end_form_tag       (void* pdoc, Node* node);
static char* s_chtml10_start_center_tag   (void* pdoc, Node* node);
static char* s_chtml10_end_center_tag     (void* pdoc, Node* node);
static char* s_chtml10_start_hr_tag       (void* pdoc, Node* node);
static char* s_chtml10_end_hr_tag         (void* pdoc, Node* node);
static char* s_chtml10_start_img_tag      (void* pdoc, Node* node);
static char* s_chtml10_end_img_tag        (void* pdoc, Node* node);
static char* s_chtml10_start_select_tag   (void* pdoc, Node* node);
static char* s_chtml10_end_select_tag     (void* pdoc, Node* node);
static char* s_chtml10_start_option_tag   (void* pdoc, Node* node);
static char* s_chtml10_end_option_tag     (void* pdoc, Node* node);
static char* s_chtml10_start_div_tag      (void* pdoc, Node* node);
static char* s_chtml10_end_div_tag        (void* pdoc, Node* node);

static void  s_init_chtml10(chtml10_t* chtml, Doc* doc, request_rec* r, device_table* spec);

static int   s_chtml10_search_emoji(chtml10_t* chtml, char* txt, char** rslt);
static char* s_chtml10_chxjif_tag        (void* pdoc, Node* node);
static char* s_chtml10_text              (void* pdoc, Node* node);

tag_handler chtml10_handler[] = {
  /* tagHTML */
  {
    s_chtml10_start_html_tag,
    s_chtml10_end_html_tag,
  },
  /* tagMETA */
  {
    s_chtml10_start_meta_tag,
    s_chtml10_end_meta_tag,
  },
  /* tagTEXTAREA */
  {
    s_chtml10_start_textarea_tag,
    s_chtml10_end_textarea_tag,
  },
  /* tagP */
  {
    s_chtml10_start_p_tag,
    s_chtml10_end_p_tag,
  },
  /* tagPRE */
  {
    s_chtml10_start_pre_tag,
    s_chtml10_end_pre_tag,
  },
  /* tagUL */
  {
    s_chtml10_start_ul_tag,
    s_chtml10_end_ul_tag,
  },
  /* tagLI */
  {
    s_chtml10_start_li_tag,
    s_chtml10_end_li_tag,
  },
  /* tagOL */
  {
    s_chtml10_start_ol_tag,
    s_chtml10_end_ol_tag,
  },
  /* tagH1 */
  {
    s_chtml10_start_h1_tag,
    s_chtml10_end_h1_tag,
  },
  /* tagH2 */
  {
    s_chtml10_start_h2_tag,
    s_chtml10_end_h2_tag,
  },
  /* tagH3 */
  {
    s_chtml10_start_h3_tag,
    s_chtml10_end_h3_tag,
  },
  /* tagH4 */
  {
    s_chtml10_start_h4_tag,
    s_chtml10_end_h4_tag,
  },
  /* tagH5 */
  {
    s_chtml10_start_h5_tag,
    s_chtml10_end_h5_tag,
  },
  /* tagH6 */
  {
    s_chtml10_start_h6_tag,
    s_chtml10_end_h6_tag,
  },
  /* tagHEAD */
  {
    s_chtml10_start_head_tag,
    s_chtml10_end_head_tag,
  },
  /* tagTITLE */
  {
    s_chtml10_start_title_tag,
    s_chtml10_end_title_tag,
  },
  /* tagBASE */
  {
    s_chtml10_start_base_tag,
    s_chtml10_end_base_tag,
  },
  /* tagBODY */
  {
    s_chtml10_start_body_tag,
    s_chtml10_end_body_tag,
  },
  /* tagA */
  {
    s_chtml10_start_a_tag,
    s_chtml10_end_a_tag,
  },
  /* tagBR */
  {
    s_chtml10_start_br_tag,
    s_chtml10_end_br_tag,
  },
  /* tagTABLE */
  {
    NULL,
    NULL,
  },
  /* tagTR */
  {
    s_chtml10_start_tr_tag,
    s_chtml10_end_tr_tag,
  },
  /* tagTD */
  {
    NULL,
    NULL,
  },
  /* tagTBODY */
  {
    NULL,
    NULL,
  },
  /* tagFONT */
  {
    s_chtml10_start_font_tag,
    s_chtml10_end_font_tag,
  },
  /* tagFORM */
  {
    s_chtml10_start_form_tag,
    s_chtml10_end_form_tag,
  },
  /* tagINPUT */
  {
    s_chtml10_start_input_tag,
    s_chtml10_end_input_tag,
  },
  /* tagCENTER */
  {
    s_chtml10_start_center_tag,
    s_chtml10_end_center_tag,
  },
  /* tagHR */
  {
    s_chtml10_start_hr_tag,
    s_chtml10_end_hr_tag,
  },
  /* tagIMG */
  {
    s_chtml10_start_img_tag,
    s_chtml10_end_img_tag,
  },
  /* tagSELECT */
  {
    s_chtml10_start_select_tag,
    s_chtml10_end_select_tag,
  },
  /* tagOPTION */
  {
    s_chtml10_start_option_tag,
    s_chtml10_end_option_tag,
  },
  /* tagDIV */
  {
    s_chtml10_start_div_tag,
    s_chtml10_end_div_tag,
  },
  /* tagCHXJIF */
  {
    s_chtml10_chxjif_tag,
    NULL,
  },
  /* tagNOBR */
  {
    NULL,
    NULL,
  },
  /* tagSMALL */
  {
    NULL,
    NULL,
  },
  /* tagSTYLE */
  {
    NULL,
    NULL,
  },
  /* tagSPAN */
  {
    NULL,
    NULL,
  },
  /* tagTEXT */
  {
    s_chtml10_text,
    NULL,
  },
  /* tagTH */
  {
    NULL,
    NULL,
  },
  /* tagB */
  {
    NULL,
    NULL,
  },
};


/**
 * converts from CHTML5.0 to CHTML1.0.
 *
 * @param r     [i]   Requet_rec is appointed.
 * @param spec  [i]   The result of the device specification processing which 
 *                    was done in advance is appointed.
 * @param src   [i]   The character string before the converting is appointed.
 * @return The character string after the converting is returned.
 */
char*
chxj_exchange_chtml10(
  request_rec*        r,
  device_table*       spec,
  const char*         src,
  apr_size_t          srclen,
  apr_size_t*         dstlen,
  chxjconvrule_entry* entryp,
  const char*         cookie_id
)
{
  char*     dst;
  char*     ss;
  chtml10_t chtml10;
  Doc       doc;

  dst = NULL;

  DBG1(r, "start chxj_exchange_chtml10() cookie_id=[%s]", cookie_id);

  /*--------------------------------------------------------------------------*/
  /* If qrcode xml                                                            */
  /*--------------------------------------------------------------------------*/
  *dstlen = srclen;
  dst = chxj_qr_code_blob_handler(r, src, (size_t*)dstlen);
  if (dst) {
    DBG(r,"i found qrcode xml");
    return dst;
  }
  DBG(r,"not found qrcode xml");

  /*--------------------------------------------------------------------------*/
  /* The CHTML structure is initialized.                                      */
  /*--------------------------------------------------------------------------*/
  s_init_chtml10(&chtml10, &doc, r, spec);
  chtml10.entryp    = entryp;
  chtml10.cookie_id = (char*)cookie_id;

  ap_set_content_type(r, "text/html; charset=Windows-31J");

  /*--------------------------------------------------------------------------*/
  /* The character string of the input is analyzed.                           */
  /*--------------------------------------------------------------------------*/
  qs_init_malloc(&doc);
  qs_init_root_node(&doc);

  ss = apr_pcalloc(r->pool, srclen + 1);
  memset(ss, 0,   srclen + 1);
  memcpy(ss, src, srclen);

#ifdef DUMP_LOG
  chxj_dump_out("[src] CHTML -> CHTML1.0", ss, srclen);
#endif

  qs_parse_string(&doc,ss, strlen(ss));

  /*--------------------------------------------------------------------------*/
  /* It converts it from CHTML to CHTML.                                      */
  /*--------------------------------------------------------------------------*/
  chxj_node_exchange(spec,r,(void*)&chtml10, &doc, qs_get_root(&doc), 0);
  dst = chtml10.out;


  qs_all_free(&doc,QX_LOGMARK);

  if (!dst)
    return apr_pstrdup(r->pool,ss);

  if (strlen(dst) == 0) {
    dst = apr_psprintf(r->pool, "\n");
  }
  *dstlen = strlen(dst);

#ifdef DUMP_LOG
  chxj_dump_out("[dst] CHTML -> CHTML1.0", dst, *dstlen);
#endif

  DBG1(r, "end   chxj_exchange_chtml10() cookie_id=[%s]", cookie_id);

  return dst;
}


/**
 * The CHTML structure is initialized.
 *
 * @param chtml10 [i/o] The pointer to the HDML structure that wants to be
 *                   initialized is specified.
 * @param doc   [i]   The Doc structure that should be set to the initialized
 *                   HDML structure is specified.
 * @param r     [i]   To use POOL, the pointer to request_rec is specified.
 * @param spec  [i]   The pointer to the device_table
 */
static void
s_init_chtml10(
  chtml10_t*    chtml10, 
  Doc*          doc, 
  request_rec*  r, 
  device_table* spec)
{
  memset(doc,     0, sizeof(Doc));
  memset(chtml10, 0, sizeof(chtml10_t));

  doc->r      = r;
  chtml10->doc  = doc;
  chtml10->spec = spec;
  chtml10->out  = qs_alloc_zero_byte_string(r);
  chtml10->conf = ap_get_module_config(r->per_dir_config, &chxj_module);
  chtml10->doc->parse_mode = PARSE_MODE_CHTML;
}


/**
 * Corresponding EMOJI to a current character-code is retrieved. 
 * The substitution character string is stored in the rslt pointer if agreeing.
 *
 * @param chtml10   [i]   The pointer to the CHTML structure is specified. 
 * @param txt     [i]   The character string to want to examine whether it is 
 *                      EMOJI is specified. 
 * @param rslt    [o]   The pointer to the pointer that stores the result is 
 *                      specified. 
 * @return When corresponding EMOJI exists, it returns it excluding 0. 
 */
static int
s_chtml10_search_emoji(chtml10_t* chtml10, char* txt, char** rslt)
{
  emoji_t*      ee;
  request_rec*  r;
  device_table* spec;
  int           len;

  spec = chtml10->spec;

  len = strlen(txt);
  r = chtml10->doc->r;

  if (!spec) {
    DBG(r,"spec is NULL");
  }

  for (ee = chtml10->conf->emoji;
       ee;
       ee = ee->next) {

    if (!ee->imode) {
      DBG(r,"emoji->imode is NULL");
      continue;
    }

    if (ee->imode->string
    &&  txt
    &&  strlen(ee->imode->string) > 0
    &&  *ee->imode->string == *txt
    &&  strncasecmp(ee->imode->string, txt, strlen(ee->imode->string)) == 0) {
      if (!spec || !spec->emoji_type) {
        *rslt = apr_palloc(r->pool, 3);
        (*rslt)[0] = ee->imode->hex1byte & 0xff;
        (*rslt)[1] = ee->imode->hex2byte & 0xff;
        (*rslt)[2] = 0;
        return strlen(ee->imode->string);
      }

      return 0;
    }
  }
  return 0;
}


/**
 * It is a handler who processes the HTML tag.
 *
 * @param chtml10  [i/o] The pointer to the CHTML structure at the output
 *                     destination is specified.
 * @param node   [i]   The HTML tag node is specified.
 * @return The conversion result is returned.
 */
static char*
s_chtml10_start_html_tag(void* pdoc, Node* node) 
{
  Doc*          doc;
  request_rec*  r;
  chtml10_t*    chtml10;

  chtml10 = GET_CHTML10(pdoc);
  doc     = chtml10->doc;
  r       = doc->r;

  /*--------------------------------------------------------------------------*/
  /* start HTML tag                                                           */
  /*--------------------------------------------------------------------------*/
  chtml10->out = apr_pstrcat(r->pool, chtml10->out, "<html>\n", NULL);

  return chtml10->out;
}


/**
 * It is a handler who processes the HTML tag.
 *
 * @param pdoc  [i/o] The pointer to the CHTML structure at the output
 *                     destination is specified.
 * @param node   [i]   The HTML tag node is specified.
 * @return The conversion result is returned.
 */
static char*
s_chtml10_end_html_tag(void* pdoc, Node* child) 
{
  Doc*          doc;
  request_rec*  r;
  chtml10_t*    chtml10;

  
  chtml10 = GET_CHTML10(pdoc);
  doc     = chtml10->doc;
  r       = doc->r;

  chtml10->out = apr_pstrcat(r->pool, chtml10->out, "</html>\n", NULL);

  return chtml10->out;
}


/**
 * It is a handler who processes the META tag.
 *
 * @param pdoc  [i/o] The pointer to the CHTML structure at the output
 *                     destination is specified.
 * @param node   [i]   The META tag node is specified.
 * @return The conversion result is returned.
 */
static char*
s_chtml10_start_meta_tag(void* pdoc, Node* node) 
{
  chtml10_t* chtml10;

  chtml10 = GET_CHTML10(pdoc);

  /* ignore */

  return chtml10->out;
}


/**
 * It is a handler who processes the META tag.
 *
 * @param pdoc  [i/o] The pointer to the CHTML structure at the output
 *                     destination is specified.
 * @param node   [i]   The META tag node is specified.
 * @return The conversion result is returned.
 */
static char*
s_chtml10_end_meta_tag(void* pdoc, Node* child) 
{
  chtml10_t* chtml10;

  chtml10 = GET_CHTML10(pdoc);

  return chtml10->out;
}


/**
 * It is a handler who processes the HEAD tag.
 *
 * @param pdoc  [i/o] The pointer to the CHTML structure at the output
 *                     destination is specified.
 * @param node   [i]   The HEAD tag node is specified.
 * @return The conversion result is returned.
 */
static char*
s_chtml10_start_head_tag(void* pdoc, Node* node) 
{
  Doc*          doc;
  request_rec*  r;
  chtml10_t*    chtml10;

  chtml10 = GET_CHTML10(pdoc);
  doc     = chtml10->doc;
  r       = doc->r;

  chtml10->out = apr_pstrcat(r->pool, chtml10->out, "<head>\r\n", NULL);

  return chtml10->out;
}


/**
 * It is a handler who processes the HEAD tag.
 *
 * @param pdoc  [i/o] The pointer to the CHTML structure at the output
 *                     destination is specified.
 * @param node   [i]   The HEAD tag node is specified.
 * @return The conversion result is returned.
 */
static char*
s_chtml10_end_head_tag(void* pdoc, Node* child) 
{
  Doc*          doc;
  request_rec*  r;
  chtml10_t*    chtml10;

  chtml10 = GET_CHTML10(pdoc);
  doc     = chtml10->doc;
  r       = doc->r;

  chtml10->out = apr_pstrcat(r->pool, chtml10->out, "</head>\r\n", NULL);

  return chtml10->out;
}


/**
 * It is a handler who processes the OL tag.
 *
 * @param pdoc  [i/o] The pointer to the CHTML structure at the output
 *                     destination is specified.
 * @param node   [i]   The OL tag node is specified.
 * @return The conversion result is returned.
 */
static char*
s_chtml10_start_ol_tag(void* pdoc, Node* node) 
{
  Doc*          doc;
  request_rec*  r;
  chtml10_t*    chtml10;

  chtml10 = GET_CHTML10(pdoc);
  doc     = chtml10->doc;
  r       = doc->r;

  chtml10->out = apr_pstrcat(r->pool, chtml10->out, "<ol>\r\n", NULL);

  return chtml10->out;
}


/**
 * It is a handler who processes the OL tag.
 *
 * @param pdoc  [i/o] The pointer to the CHTML structure at the output
 *                     destination is specified.
 * @param node   [i]   The OL tag node is specified.
 * @return The conversion result is returned.
 */
static char*
s_chtml10_end_ol_tag(void* pdoc, Node* child) 
{
  Doc*          doc;
  request_rec*  r;
  chtml10_t*    chtml10;

  chtml10 = GET_CHTML10(pdoc);
  doc     = chtml10->doc;
  r       = doc->r;

  chtml10->out = apr_pstrcat(r->pool, chtml10->out, "</ol>\r\n", NULL);

  return chtml10->out;
}


/**
 * It is a handler who processes the UL tag.
 *
 * @param pdoc  [i/o] The pointer to the CHTML structure at the output
 *                     destination is specified.
 * @param node   [i]   The UL tag node is specified.
 * @return The conversion result is returned.
 */
static char*
s_chtml10_start_ul_tag(void* pdoc, Node* node) 
{
  Doc*          doc;
  request_rec*  r;
  chtml10_t*    chtml10;

  chtml10    = GET_CHTML10(pdoc);
  doc        = chtml10->doc;
  r          = doc->r;

  chtml10->out = apr_pstrcat(r->pool, chtml10->out, "<ul>\r\n", NULL);

  return chtml10->out;
}


/**
 * It is a handler who processes the UL tag.
 *
 * @param pdoc  [i/o] The pointer to the CHTML structure at the output
 *                     destination is specified.
 * @param node   [i]   The UL tag node is specified.
 * @return The conversion result is returned.
 */
static char*
s_chtml10_end_ul_tag(void* pdoc, Node* child) 
{
  Doc*          doc;
  request_rec*  r;
  chtml10_t*    chtml10;

  chtml10 = GET_CHTML10(pdoc);
  doc     = chtml10->doc;
  r       = doc->r;

  chtml10->out = apr_pstrcat(r->pool, chtml10->out, "</ul>\r\n", NULL);

  return chtml10->out;
}


/**
 * It is a handler who processes the LI tag.
 *
 * @param pdoc  [i/o] The pointer to the CHTML structure at the output
 *                     destination is specified.
 * @param node   [i]   The LI tag node is specified.
 * @return The conversion result is returned.
 */
static char*
s_chtml10_start_li_tag(void* pdoc, Node* node) 
{
  Doc*          doc;
  request_rec*  r;
  chtml10_t*    chtml10;

  chtml10 = GET_CHTML10(pdoc);
  doc     = chtml10->doc;
  r       = doc->r;

  chtml10->out = apr_pstrcat(r->pool, chtml10->out, "<li>\r\n", NULL);

  return chtml10->out;
}


/**
 * It is a handler who processes the LI tag.
 *
 * @param pdoc  [i/o] The pointer to the CHTML structure at the output
 *                     destination is specified.
 * @param node   [i]   The LI tag node is specified.
 * @return The conversion result is returned.
 */
static char*
s_chtml10_end_li_tag(void* pdoc, Node* child) 
{
  chtml10_t*    chtml10;
  Doc*          doc;
  request_rec*  r;

  chtml10 = GET_CHTML10(pdoc);
  doc     = chtml10->doc;
  r       = doc->r;

  chtml10->out = apr_pstrcat(r->pool, chtml10->out, "</li>\r\n", NULL);

  return chtml10->out;
}


/**
 * It is a handler who processes the H1 tag.
 *
 * @param pdoc  [i/o] The pointer to the CHTML structure at the output
 *                     destination is specified.
 * @param node   [i]   The H1 tag node is specified.
 * @return The conversion result is returned.
 */
static char*
s_chtml10_start_h1_tag(void* pdoc, Node* node) 
{
  Doc*          doc;
  request_rec*  r;
  chtml10_t*    chtml10;

  chtml10 = GET_CHTML10(pdoc);
  doc     = chtml10->doc;
  r       = doc->r;

  chtml10->out = apr_pstrcat(r->pool, chtml10->out, "<h1>\r\n", NULL);

  return chtml10->out;
}


/**
 * It is a handler who processes the H1 tag.
 *
 * @param pdoc  [i/o] The pointer to the CHTML structure at the output
 *                     destination is specified.
 * @param node   [i]   The H1 tag node is specified.
 * @return The conversion result is returned.
 */
static char*
s_chtml10_end_h1_tag(void* pdoc, Node* child) 
{
  Doc*          doc;
  request_rec*  r;
  chtml10_t*    chtml10;

  chtml10 = GET_CHTML10(pdoc);
  doc     = chtml10->doc;
  r       = doc->r;

  chtml10->out = apr_pstrcat(r->pool, chtml10->out, "</h1>\r\n", NULL);

  return chtml10->out;
}


/**
 * It is a handler who processes the H2 tag.
 *
 * @param pdoc  [i/o] The pointer to the CHTML structure at the output
 *                     destination is specified.
 * @param node   [i]   The H2 tag node is specified.
 * @return The conversion result is returned.
 */
static char*
s_chtml10_start_h2_tag(void* pdoc, Node* node) 
{
  Doc*          doc;
  request_rec*  r;
  chtml10_t*    chtml10;

  chtml10 = GET_CHTML10(pdoc);
  doc     = chtml10->doc;
  r       = doc->r;

  chtml10->out = apr_pstrcat(r->pool, chtml10->out, "<h2>\r\n", NULL);

  return chtml10->out;
}


/**
 * It is a handler who processes the H2 tag.
 *
 * @param pdoc  [i/o] The pointer to the CHTML structure at the output
 *                     destination is specified.
 * @param node   [i]   The H2 tag node is specified.
 * @return The conversion result is returned.
 */
static char*
s_chtml10_end_h2_tag(void* pdoc, Node* child) 
{
  Doc*          doc;
  request_rec*  r;
  chtml10_t*    chtml10;

  chtml10 = GET_CHTML10(pdoc);
  doc     = chtml10->doc;
  r       = doc->r;

  chtml10->out = apr_pstrcat(r->pool, chtml10->out, "</h2>\r\n", NULL);

  return chtml10->out;
}


/**
 * It is a handler who processes the H3 tag.
 *
 * @param pdoc  [i/o] The pointer to the CHTML structure at the output
 *                     destination is specified.
 * @param node   [i]   The H3 tag node is specified.
 * @return The conversion result is returned.
 */
static char*
s_chtml10_start_h3_tag(void* pdoc, Node* node) 
{
  Doc*          doc;
  request_rec*  r;
  chtml10_t*    chtml10;

  chtml10 = GET_CHTML10(pdoc);
  doc     = chtml10->doc;
{'fraction_non_alphanumeric': 0.14702198419211332, 'fraction_numerical': 0.03049280870729495, 'mean_word_length': 2.3514511109502787, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 287, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '873540', 'n_tokens_mistral': 18204, 'n_tokens_neox': 17203, 'n_words': 4323}