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

rpl_wk_status rpl_mod_init_process ( rpl_c_str_t  filename,
struct stat  statbuf 
)

Parameters:
filename name of file to be registered.
st_buf stat of file.

Definition at line 74 of file mod_init.c.

References rpl_fs_mkdir(), rpl_fs_resolve_paths(), rpl_log_info(), rpl_me_free(), rpl_me_malloc(), rpl_message_get(), rpl_mime_get_type(), rpl_reg_insert(), rpl_str_concat(), rpl_wa_init(), rpl_wa_set_filename(), rpl_wa_set_key(), rpl_wa_set_mime_type(), and rpl_wa_set_rel_dir().

Referenced by rpl_mod_init_configure().

{
      rpl_wk_status status = RPL_WK_OK;
      rpl_web_asset *wa;
      rpl_str_t msg, mime_type, rdp, fp, key, terr_fp, tout_fp, parse_fp, xslt_fp;

      assert(filename != NULL);

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

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

      if(S_ISREG(statbuf.st_mode))
      {
            /* TODO: decide how best to set the contributor detail */
            wa = (rpl_web_asset *)rpl_me_malloc(sizeof(rpl_web_asset));
            rpl_wa_init(wa);

            /* set mime type based on filename extension */
            mime_type = rpl_mime_get_type(filename);
            rpl_wa_set_mime_type(mime_type, wa);
            rpl_me_free(mime_type);

            /* populate web asset fields */
            rpl_wa_set_rel_dir(rdp, wa);
            rpl_wa_set_filename(fp, wa);
            rpl_wa_set_key(wa);

            rpl_reg_insert(wa);     


      } else if(S_ISDIR(statbuf.st_mode)) {

            if(strlen(rdp) + strlen(fp) > 0)
            {
                  /* use relative path to resolve directories for errors and output */
                  terr_fp = (rpl_str_t)rpl_me_malloc(strlen(terr_dir) + strlen(key) + 2);
                  sprintf(terr_fp, "%s/%s", terr_dir, key);
                  tout_fp = (rpl_str_t)rpl_me_malloc(strlen(tout_dir) + strlen(key) + 2);
                  sprintf(tout_fp, "%s/%s", tout_dir, key);
                  parse_fp = (rpl_str_t)rpl_me_malloc(strlen(parse_dir) + strlen(key) + 2);
                  sprintf(parse_fp, "%s/%s", parse_dir, key);
                  xslt_fp = (rpl_str_t)rpl_me_malloc(strlen(xslt_dir) + strlen(key) + 2);
                  sprintf(xslt_fp, "%s/%s", xslt_dir, key);

                  rpl_fs_mkdir(terr_fp);
                  rpl_fs_mkdir(tout_fp);
                  rpl_fs_mkdir(parse_fp);
                  rpl_fs_mkdir(xslt_fp);

                  rpl_me_free(terr_fp);
                  rpl_me_free(tout_fp);
                  rpl_me_free(parse_fp);
                  rpl_me_free(xslt_fp);

                  rpl_me_free(rdp);
                  rpl_me_free(fp);
                  rpl_me_free(key);
            }
      }


      return status; 
}


Generated by  Doxygen 1.6.0   Back to index