static hlcache_handle *save_complete_ctx_find_content(save_complete_ctx *ctx, const nsurl *url) { save_complete_entry *entry; for (entry = ctx->list; entry != NULL; entry = entry->next) if (nsurl_compare(url, hlcache_handle_get_url(entry->content), NSURL_COMPLETE)) return entry->content; return NULL; }
END_TEST /** * check compare asserts on NULL parameter */ START_TEST(nsurl_api_assert_compare2_test) { nserror err; nsurl *res; bool same; err = nsurl_create(base_str, &res); ck_assert(err == NSERROR_OK); same = nsurl_compare(res, NULL, NSURL_PATH); ck_assert(same == false); }
/** * Find an entry in the global history * * \param url The URL to find * \return Pointer to history entry, or NULL if not found */ static struct global_history_entry *global_history_find(nsurl *url) { int i; struct global_history_entry *e; for (i = 0; i < N_DAYS; i++) { e = gh_list[i]; while (e != NULL) { if (nsurl_compare(e->url, url, NSURL_COMPLETE) == true) { /* Got a match */ return e; } e = e->next; } } /* No match found */ return NULL; }
/** * Handle notification of the need for an imported stylesheet * * \param pw CSS object requesting the import * \param parent Stylesheet requesting the import * \param url URL of the imported sheet * \param media Applicable media for the imported sheet * \return CSS_OK on success, appropriate error otherwise */ css_error nscss_handle_import(void *pw, css_stylesheet *parent, lwc_string *url, uint64_t media) { content_type accept = CONTENT_CSS; struct content_css_data *c = pw; nscss_import_ctx *ctx; hlcache_child_context child; struct nscss_import *imports; const char *referer; css_error error; nserror nerror; nsurl *ns_url; nsurl *ns_ref; assert(parent == c->sheet); error = css_stylesheet_get_url(c->sheet, &referer); if (error != CSS_OK) { return error; } ctx = malloc(sizeof(*ctx)); if (ctx == NULL) return CSS_NOMEM; ctx->css = c; ctx->index = c->import_count; /* Increase space in table */ imports = realloc(c->imports, (c->import_count + 1) * sizeof(struct nscss_import)); if (imports == NULL) { free(ctx); return CSS_NOMEM; } c->imports = imports; /** \todo fallback charset */ child.charset = NULL; error = css_stylesheet_quirks_allowed(c->sheet, &child.quirks); if (error != CSS_OK) { free(ctx); return error; } /* Create content */ c->imports[c->import_count].media = media; /* TODO: Why aren't we getting a relative url part, to join? */ nerror = nsurl_create(lwc_string_data(url), &ns_url); if (nerror != NSERROR_OK) { free(ctx); return CSS_NOMEM; } /* TODO: Constructing nsurl for referer here is silly, avoid */ nerror = nsurl_create(referer, &ns_ref); if (nerror != NSERROR_OK) { nsurl_unref(ns_url); free(ctx); return CSS_NOMEM; } /* Avoid importing ourself */ if (nsurl_compare(ns_url, ns_ref, NSURL_COMPLETE)) { c->imports[c->import_count].c = NULL; /* No longer require context as we're not fetching anything */ free(ctx); ctx = NULL; } else { nerror = hlcache_handle_retrieve(ns_url, 0, ns_ref, NULL, nscss_import, ctx, &child, accept, &c->imports[c->import_count].c); if (nerror != NSERROR_OK) { free(ctx); return CSS_NOMEM; } } nsurl_unref(ns_url); nsurl_unref(ns_ref); #ifdef NSCSS_IMPORT_TRACE LOG(("Import %d '%s' -> (handle: %p ctx: %p)", c->import_count, lwc_string_data(url), c->imports[c->import_count].c, ctx)); #endif c->import_count++; return CSS_OK; }