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

static int rpl_mod_link_resolve ( rpl_c_str_t  link,
rpl_str_t  rdp 
) [static]

Resolves link fragment and checks local file existence if appropriate.

Parameters:
link fragment pointing to (possible) local resource.
Returns:
-1 if link pointers to non-existent local resource, otherwise 0.

Definition at line 81 of file mod_link.c.

References rpl_cfg_get_trf_tpl_domain(), rpl_fs_file_exists(), rpl_me_free(), rpl_me_malloc(), and rpl_mod_link_normalize().

Referenced by rpl_mod_link_start().

{
      rpl_str_t domain, nlink;
      rpl_str_t resource = NULL;
      int rc = 0;

      assert(link != NULL); 

      if(rdp == NULL)
            rdp = "";
      nlink = rpl_mod_link_normalize(link);
      domain = rpl_cfg_get_trf_tpl_domain();

      /* check if the link refers to a local resource */
      if(strncmp(link, domain, strlen(domain)) == 0)
      {
            /* matches the domain so must be an internal fully qualified name */
            resource = rpl_me_malloc(strlen(rpl_link_base_dir) + strlen(nlink) - strlen(domain) + 3);
            sprintf(resource, "%s/%s", rpl_link_base_dir, nlink + strlen(domain));
      } else if((strncmp(nlink, "http://", 7) != 0) && (strncmp(nlink, "https://", 8) != 0) 
                        && (strncmp(nlink, "mailto:", 7) != 0)) {
            /* not an external reference so must be an internal relative link */
            resource = rpl_me_malloc(strlen(rpl_link_base_dir) + strlen(rdp) + strlen(nlink) + 1);
            sprintf(resource, "%s/%s/%s", rpl_link_base_dir, rdp, nlink);
      } 

      /* check presence of the resource */
      if(resource != NULL)
      {
            rc = rpl_fs_file_exists(resource);
            rpl_me_free(resource);
      }
      rpl_me_free(nlink);

      return rc;
}


Generated by  Doxygen 1.6.0   Back to index