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

rpl_wk_status rpl_mod_tidy_process ( rpl_c_str_t  filename,
struct stat  statbuf 
)

Performs tidy 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 103 of file mod_tidy.c.

References rpl_fs_resolve_paths(), rpl_log_error(), rpl_log_info(), rpl_me_free(), rpl_me_malloc(), rpl_message_get(), rpl_reg_insert(), rpl_reg_search(), rpl_str_concat(), rpl_wa_get_trf_status_desc(), rpl_wa_is_transformable(), and rpl_wa_set_tidy_stat_desc().

Referenced by rpl_mod_tidy_configure().

{
      TidyDoc tdoc;
      rpl_reg_item item;
    int rc = -1;
      rpl_str_t msg, rdp, fp, key, errfp, outfp;
      rpl_wk_status status = RPL_WK_OK;

    assert(filename != NULL);

      msg = rpl_str_concat(rpl_message_get("WK_PROCESSING", RPL_EOM), "tidy ", filename, RPL_STR_EOC);
      rpl_log_info(msg);
      rpl_me_free(msg);

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

      /* use relative path to resolve directories for errors and output */
      errfp = (rpl_str_t)rpl_me_malloc(strlen(terr_dir) + strlen(rdp) + strlen(fp) + 2);
      sprintf(errfp, "%s/%s/%s", terr_dir, rdp, fp);
      outfp = (rpl_str_t)rpl_me_malloc(strlen(tout_dir) + strlen(rdp) + strlen(fp) + 2);
      sprintf(outfp, "%s/%s/%s", tout_dir, rdp, fp);

      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;
            }

            /* either transform the asset or simply copy it */    
      if(rpl_wa_is_transformable(*item))
            {
                  /* create and configure doc */
                  tdoc = tidyCreate();
                  tidyOptCopyConfig(tdoc, config);

                  /* perform tidy operations */
                  rc = (int)tidySetErrorFile(tdoc, errfp);
                  if (rc >= 0)
                        rc = tidyParseFile(tdoc, filename); 
                  if (rc >= 0)
                        rc = tidyCleanAndRepair(tdoc);
                  if (rc >= 0)
                        rc = tidyRunDiagnostics(tdoc);
                  if (rc > 1)
                        rc = (tidyOptSetBool(tdoc, TidyForceOutput, yes) ? rc : -1);
                  if (rc >= 0)
                        rc = tidySaveFile(tdoc, outfp);

                  /* report outcome */
                  if (rc >= 0)
                  {
                        rc = (rc > 0) ? RPL_WA_TRF_ST_WARNING : RPL_WA_TRF_ST_SUCCESS;
                  } else {
                        rc = RPL_WA_TRF_ST_FAILURE;
                  }
                  rpl_wa_set_tidy_stat_desc(rpl_wa_get_trf_status_desc(rc), item);
                  rpl_reg_insert(item);

                  /* free resources */
                  tidyRelease(tdoc);

            } else {
                  rpl_fs_cp(filename, (rpl_c_str_t)outfp);
            }
      }

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

      return status; 
}


Generated by  Doxygen 1.6.0   Back to index