Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * Copyright 2009 John-Mark Bell <jmb@netsurf-browser.org>
  3.  *
  4.  * This file is part of NetSurf, http://www.netsurf-browser.org/
  5.  *
  6.  * NetSurf is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation; version 2 of the License.
  9.  *
  10.  * NetSurf is distributed in the hope that it will be useful,
  11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  * GNU General Public License for more details.
  14.  *
  15.  * You should have received a copy of the GNU General Public License
  16.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  17.  */
  18.  
  19. #include <string.h>
  20.  
  21. #include "css/internal.h"
  22.  
  23. #include "utils/nsurl.h"
  24.  
  25. /**
  26.  * URL resolution callback for libcss
  27.  *
  28.  * \param pw    Resolution context
  29.  * \param base  Base URI
  30.  * \param rel   Relative URL
  31.  * \param abs   Pointer to location to receive resolved URL
  32.  * \return CSS_OK       on success,
  33.  *         CSS_NOMEM    on memory exhaustion,
  34.  *         CSS_INVALID  if resolution failed.
  35.  */
  36. css_error nscss_resolve_url(void *pw, const char *base,
  37.                 lwc_string *rel, lwc_string **abs)
  38. {
  39.         lwc_error lerror;
  40.         nserror error;
  41.         nsurl *nsbase;
  42.         nsurl *nsabs;
  43.  
  44.         /* Create nsurl from base */
  45.         /* TODO: avoid this */
  46.         error = nsurl_create(base, &nsbase);
  47.         if (error != NSERROR_OK) {
  48.                 return error == NSERROR_NOMEM ? CSS_NOMEM : CSS_INVALID;
  49.         }
  50.  
  51.         /* Resolve URI */
  52.         error = nsurl_join(nsbase, lwc_string_data(rel), &nsabs);
  53.         if (error != NSERROR_OK) {
  54.                 nsurl_unref(nsbase);
  55.                 return error == NSERROR_NOMEM ? CSS_NOMEM : CSS_INVALID;
  56.         }
  57.  
  58.         nsurl_unref(nsbase);
  59.  
  60.         /* Intern it */
  61.         lerror = lwc_intern_string(nsurl_access(nsabs),
  62.                         nsurl_length(nsabs), abs);
  63.         if (lerror != lwc_error_ok) {
  64.                 *abs = NULL;
  65.                 nsurl_unref(nsabs);
  66.                 return lerror == lwc_error_oom ? CSS_NOMEM : CSS_INVALID;
  67.         }
  68.  
  69.         nsurl_unref(nsabs);
  70.  
  71.         return CSS_OK;
  72. }
  73.  
  74.