static void *fetch_rsrc_setup(struct fetch *parent_fetch, nsurl *url, bool only_2xx, bool downgrade_tls, const char *post_urlenc, const struct fetch_multipart_data *post_multipart, const char **headers) { struct fetch_rsrc_context *ctx; ctx = (struct fetch_rsrc_context *)calloc(1, sizeof(*ctx)); if (ctx == NULL) return NULL; ctx->parent_fetch = parent_fetch; /* TODO: keep as nsurl to avoid copy */ ctx->url = (char *)malloc(nsurl_length(url) + 1); if (ctx->url == NULL) { free(ctx); return NULL; } memcpy(ctx->url, nsurl_access(url), nsurl_length(url) + 1); RING_INSERT(ring, ctx); return ctx; }
END_TEST /** * check length asserts on NULL parameter */ START_TEST(nsurl_api_assert_length_test) { size_t res = 0; res = nsurl_length(NULL); ck_assert(res == 0); }
static bool save_complete_rewrite_url_value(save_complete_ctx *ctx, const char *value, size_t value_len) { nsurl *url; hlcache_handle *content; char *escaped; nserror error; utf8_convert_ret ret; error = nsurl_join(ctx->base, value, &url); if (error == NSERROR_NOMEM) return false; if (url != NULL) { content = save_complete_ctx_find_content(ctx, url); if (content != NULL) { /* found a match */ nsurl_unref(url); fprintf(ctx->fp, "\"%p\"", content); } else { /* no match found */ ret = utf8_to_html(nsurl_access(url), "UTF-8", nsurl_length(url), &escaped); nsurl_unref(url); if (ret != UTF8_CONVERT_OK) return false; fprintf(ctx->fp, "\"%s\"", escaped); free(escaped); } } else { ret = utf8_to_html(value, "UTF-8", value_len, &escaped); if (ret != UTF8_CONVERT_OK) return false; fprintf(ctx->fp, "\"%s\"", escaped); free(escaped); } return true; }
/** * Set a global history entry's data from the url_data. * * \param e Global history entry to set up * \param data Data associated with entry's URL * \return NSERROR_OK on success, appropriate error otherwise */ static nserror global_history_create_treeview_field_data( struct global_history_entry *e, const struct url_data *data) { const char *title = (data->title != NULL) ? data->title : messages_get("NoTitle"); char buffer[16]; const char *last_visited; char *last_visited2; int len; e->data[GH_TITLE].field = gh_ctx.fields[GH_TITLE].field; e->data[GH_TITLE].value = strdup(title); e->data[GH_TITLE].value_len = (e->data[GH_TITLE].value != NULL) ? strlen(title) : 0; e->data[GH_URL].field = gh_ctx.fields[GH_URL].field; e->data[GH_URL].value = nsurl_access(e->url); e->data[GH_URL].value_len = nsurl_length(e->url); last_visited = ctime(&data->last_visit); last_visited2 = strdup(last_visited); if (last_visited2 != NULL) { assert(last_visited2[24] == '\n'); last_visited2[24] = '\0'; } e->data[GH_LAST_VISIT].field = gh_ctx.fields[GH_LAST_VISIT].field; e->data[GH_LAST_VISIT].value = last_visited2; e->data[GH_LAST_VISIT].value_len = (last_visited2 != NULL) ? 24 : 0; len = snprintf(buffer, 16, "%u", data->visits); if (len == 16) { len--; buffer[len] = '\0'; } e->data[GH_VISITS].field = gh_ctx.fields[GH_VISITS].field; e->data[GH_VISITS].value = strdup(buffer); e->data[GH_VISITS].value_len = len; return NSERROR_OK; }
END_TEST /** * url length test * * uses access dataset and test unit */ START_TEST(nsurl_length_test) { nserror err; nsurl *res_url; const struct test_triplets *tst = &access_tests[_i]; /* not testing create, this should always succeed */ err = nsurl_create(tst->test1, &res_url); ck_assert(err == NSERROR_OK); ck_assert_int_eq(nsurl_length(res_url), strlen(tst->test2)); nsurl_unref(res_url); }
/** * URL resolution callback for libcss * * \param pw Resolution context * \param base Base URI * \param rel Relative URL * \param abs Pointer to location to receive resolved URL * \return CSS_OK on success, * CSS_NOMEM on memory exhaustion, * CSS_INVALID if resolution failed. */ css_error nscss_resolve_url(void *pw, const char *base, lwc_string *rel, lwc_string **abs) { lwc_error lerror; nserror error; nsurl *nsbase; nsurl *nsabs; /* Create nsurl from base */ /* TODO: avoid this */ error = nsurl_create(base, &nsbase); if (error != NSERROR_OK) { return error == NSERROR_NOMEM ? CSS_NOMEM : CSS_INVALID; } /* Resolve URI */ error = nsurl_join(nsbase, lwc_string_data(rel), &nsabs); if (error != NSERROR_OK) { nsurl_unref(nsbase); return error == NSERROR_NOMEM ? CSS_NOMEM : CSS_INVALID; } nsurl_unref(nsbase); /* Intern it */ lerror = lwc_intern_string(nsurl_access(nsabs), nsurl_length(nsabs), abs); if (lerror != lwc_error_ok) { *abs = NULL; nsurl_unref(nsabs); return lerror == lwc_error_oom ? CSS_NOMEM : CSS_INVALID; } nsurl_unref(nsabs); return CSS_OK; }
void ro_gui_url_complete_redraw(wimp_draw *redraw) { osbool more; os_error *error; int line; const struct url_data *data; int type; /* initialise our icon */ url_complete_icon.flags = wimp_ICON_INDIRECTED | wimp_ICON_VCENTRED | wimp_ICON_TEXT | wimp_ICON_FILLED | (wimp_COLOUR_BLACK << wimp_ICON_FG_COLOUR_SHIFT) | (wimp_COLOUR_WHITE << wimp_ICON_BG_COLOUR_SHIFT); url_complete_icon.extent.x0 = 50; url_complete_icon.extent.x1 = 16384; url_complete_icon.data.indirected_text.validation = url_complete_icon_null; url_complete_sprite.flags = wimp_ICON_TEXT | wimp_ICON_SPRITE | wimp_ICON_INDIRECTED | wimp_ICON_FILLED | wimp_ICON_HCENTRED | wimp_ICON_VCENTRED; url_complete_sprite.extent.x0 = 0; url_complete_sprite.extent.x1 = 50; url_complete_sprite.data.indirected_text.text = url_complete_icon_null; url_complete_sprite.data.indirected_text.validation = url_complete_icon_sprite; url_complete_sprite.data.indirected_text.size = 1; /* no matches? no redraw */ if (!url_complete_matches) { LOG("Attempt to redraw with no matches made"); /* Fill is never used, so make it something obvious */ ro_gui_user_redraw(redraw, false, os_COLOUR_BLACK); return; } /* redraw */ more = wimp_redraw_window(redraw); while (more) { int first_line, last_line; int origin_y = redraw->box.y1 - redraw->yscroll; int clip_y0 = redraw->clip.y0 - origin_y; int clip_y1 = redraw->clip.y1 - origin_y; first_line = (-clip_y1) / 44; last_line = (-clip_y0 + 43) / 44; for (line = first_line; line < last_line; line++) { if (line == url_complete_matches_selection) url_complete_icon.flags |= wimp_ICON_SELECTED; else url_complete_icon.flags &= ~wimp_ICON_SELECTED; url_complete_icon.extent.y1 = -line * 44; url_complete_icon.extent.y0 = -(line + 1) * 44; url_complete_icon.data.indirected_text.text = (char *)nsurl_access( url_complete_matches[line]); url_complete_icon.data.indirected_text.size = nsurl_length( url_complete_matches[line]); error = xwimp_plot_icon(&url_complete_icon); if (error) { LOG("xwimp_plot_icon: 0x%x: %s", error->errnum, error->errmess); ro_warn_user("WimpError", error->errmess); } data = urldb_get_url_data(url_complete_matches[line]); if (data) type = ro_content_filetype_from_type( data->type); else type = 0; sprintf(url_complete_icon_sprite, "Ssmall_%.3x", type); if (!ro_gui_wimp_sprite_exists( url_complete_icon_sprite + 1)) sprintf(url_complete_icon_sprite, "Ssmall_xxx"); url_complete_sprite.extent.y1 = -line * 44; url_complete_sprite.extent.y0 = -(line + 1) * 44; error = xwimp_plot_icon(&url_complete_sprite); if (error) { LOG("xwimp_plot_icon: 0x%x: %s", error->errnum, error->errmess); ro_warn_user("WimpError", error->errmess); } } more = wimp_get_rectangle(redraw); } }