NetSurf
internal.c
Go to the documentation of this file.
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#include <libcss/libcss.h>
21
22#include "utils/nsurl.h"
23
24#include "css/internal.h"
25
26/* exported interface documented in content/handlers/css/internal.h */
27css_error nscss_resolve_url(void *pw, const char *base,
28 lwc_string *rel, lwc_string **abs)
29{
30 lwc_error lerror;
31 nserror error;
32 nsurl *nsbase;
33 nsurl *nsabs;
34
35 /* Create nsurl from base */
36 /* TODO: avoid this */
37 error = nsurl_create(base, &nsbase);
38 if (error != NSERROR_OK) {
39 return error == NSERROR_NOMEM ? CSS_NOMEM : CSS_INVALID;
40 }
41
42 /* Resolve URI */
43 error = nsurl_join(nsbase, lwc_string_data(rel), &nsabs);
44 if (error != NSERROR_OK) {
45 nsurl_unref(nsbase);
46 return error == NSERROR_NOMEM ? CSS_NOMEM : CSS_INVALID;
47 }
48
49 nsurl_unref(nsbase);
50
51 /* Intern it */
52 lerror = lwc_intern_string(nsurl_access(nsabs),
53 nsurl_length(nsabs), abs);
54 if (lerror != lwc_error_ok) {
55 *abs = NULL;
56 nsurl_unref(nsabs);
57 return lerror == lwc_error_oom ? CSS_NOMEM : CSS_INVALID;
58 }
59
60 nsurl_unref(nsabs);
61
62 return CSS_OK;
63}
nserror
Enumeration of error codes.
Definition: errors.h:29
@ NSERROR_NOMEM
Memory exhaustion.
Definition: errors.h:32
@ NSERROR_OK
No error.
Definition: errors.h:30
css_error nscss_resolve_url(void *pw, const char *base, lwc_string *rel, lwc_string **abs)
URL resolution callback for libcss.
Definition: internal.c:27
NetSurf URL handling (interface).
nserror nsurl_create(const char *const url_s, nsurl **url)
Create a NetSurf URL object from a URL string.
void nsurl_unref(nsurl *url)
Drop a reference to a NetSurf URL object.
const char * nsurl_access(const nsurl *url)
Access a NetSurf URL object as a string.
size_t nsurl_length(const nsurl *url)
Find the length of a NetSurf URL object's URL, as returned by nsurl_access.
nserror nsurl_join(const nsurl *base, const char *rel, nsurl **joined)
Join a base url to a relative link part, creating a new NetSurf URL object.
struct nsurl nsurl
NetSurf URL object.
Definition: nsurl.h:31
@ base
Definition: punycode.c:19
Interface to utility string handling.