Logo Search packages:      
Sourcecode: rapple version File versions  Download package

rpl_wk_status rpl_mod_link_process ( rpl_c_str_t  filename,
struct stat  statbuf 
)

Performs xslt operations on web asset.

Parameters:
filename name of file to be transformed relative to website base directory.
st_buf stat of file.

Definition at line 235 of file mod_link.c.

References rpl_fs_f2str(), rpl_fs_resolve_paths(), rpl_log_error(), rpl_log_fatal(), rpl_log_info(), rpl_me_free(), rpl_me_malloc(), rpl_message_get(), rpl_mod_link_end(), rpl_mod_link_start(), rpl_reg_search(), rpl_str_concat(), and rpl_wa_is_transformable().

Referenced by rpl_mod_link_configure().

{
      rpl_str_t msg, rdp, fp, key, line_no;
      rpl_wk_status status = RPL_WK_OK;
      rpl_reg_item item;
      rpl_str_t file, ctnt;

      assert(filename != NULL);

      if(process_flag) 
      {

            /* extract key information */
            if(rpl_fs_resolve_paths(filename, rpl_link_base_dir, &rdp, &fp))
                  return RPL_WK_ERR;
            key = rpl_reg_create_key(rdp, fp);

            /* only parse the files */
            if(S_ISREG(statbuf.st_mode))
            {

                  /* retrieve asset from registry */
                  item = rpl_reg_search(key);
                  if(item == &RPL_REG_WA_NULL)
                  {
                        rpl_log_error(rpl_message_get("REG_ASSET_NOT_FOUND", key, RPL_EOM));
                        return RPL_WK_ERR;
                  }

                  if(rpl_wa_is_transformable(*item))
                  {

                        fprintf(xml_rpt_fp,"%s%s%s", RPL_MOD_LINK_FILE_ENTRY_1, filename, RPL_MOD_LINK_FILE_ENTRY_2);
                        msg = rpl_str_concat(rpl_message_get("WK_PROCESSING", RPL_EOM), "link ", filename, RPL_STR_EOC);
                        rpl_log_info(msg);
                        rpl_me_free(msg);

                        /* retrieve asset from registry */
                        item = rpl_reg_search(key);
                        if(item == &RPL_REG_WA_NULL)
                        {
                              msg = rpl_message_get("REG_ASSET_NOT_FOUND", key, RPL_EOM);
                              rpl_log_error(msg);
                              rpl_me_free(msg);
                              return RPL_WK_ERR;
                        }

                        file = rpl_me_malloc(strlen(rpl_link_base_dir) + strlen(rdp) + strlen(fp) + 3);
                        sprintf(file, "%s/%s/%s", rpl_link_base_dir, rdp, fp);
                        ctnt = rpl_fs_f2str(file);

                        /* new parser created for each document (is there a better way ?) */
                        if((parser = XML_ParserCreate(NULL)) == NULL)
                              rpl_log_fatal(rpl_message_get("OUT_OF_MEMORY", "link checker XML parser", RPL_EOM));
                        XML_SetElementHandler(parser, rpl_mod_link_start, rpl_mod_link_end);
                        XML_SetUserData(parser, (void *)rdp);

                        if (XML_Parse(parser, ctnt, strlen(ctnt), 1) == XML_STATUS_ERROR)
                        {
                              line_no = (rpl_str_t)rpl_me_malloc(12);
                              sprintf(line_no, "(line %d)", XML_GetCurrentLineNumber(parser));
                              msg = rpl_str_concat("XML Parse Error: ", XML_ErrorString(XML_GetErrorCode(parser)), 
                                          " ", line_no, RPL_STR_EOC);
                              rpl_log_error(msg);
                              rpl_me_free(line_no);
                              rpl_me_free(msg);
                              status = RPL_WK_WARN;
                        }

                        XML_ParserFree(parser);

                        fprintf(xml_rpt_fp, "%s", RPL_MOD_LINK_FILE_ENTRY_3);

                        rpl_me_free(file);
                        rpl_me_free(ctnt);

                  }
            }

            /* free resources */
            if(strlen(rdp) > 0)
                  rpl_me_free(rdp);
            if(strlen(fp) > 0)
                  rpl_me_free(fp);

      }

      return status; 
}


Generated by  Doxygen 1.6.0   Back to index