nserror content__init(struct content *c, const content_handler *handler, lwc_string *imime_type, const http_parameter *params, llcache_handle *llcache, const char *fallback_charset, bool quirks) { struct content_user *user_sentinel; nserror error; LOG(("url "URL_FMT_SPC" -> %p", nsurl_access(llcache_handle_get_url(llcache)), c)); user_sentinel = calloc(1, sizeof(struct content_user)); if (user_sentinel == NULL) { return NSERROR_NOMEM; } if (fallback_charset != NULL) { c->fallback_charset = strdup(fallback_charset); if (c->fallback_charset == NULL) { free(user_sentinel); return NSERROR_NOMEM; } } c->llcache = llcache; c->mime_type = lwc_string_ref(imime_type); c->handler = handler; c->status = CONTENT_STATUS_LOADING; c->width = 0; c->height = 0; c->available_width = 0; c->quirks = quirks; c->refresh = 0; c->time = wallclock(); c->size = 0; c->title = NULL; c->active = 0; user_sentinel->callback = NULL; user_sentinel->pw = NULL; user_sentinel->next = NULL; c->user_list = user_sentinel; c->sub_status[0] = 0; c->locked = false; c->total_size = 0; c->http_code = 0; c->error_count = 0; content_set_status(c, messages_get("Loading")); /* Finally, claim low-level cache events */ error = llcache_handle_change_callback(llcache, content_llcache_callback, c); if (error != NSERROR_OK) { lwc_string_unref(c->mime_type); return error; } return NSERROR_OK; }
/* See download.h for documentation */ nserror download_context_create(llcache_handle *llcache, struct gui_window *parent) { download_context *ctx; ctx = malloc(sizeof(*ctx)); if (ctx == NULL) return NSERROR_NOMEM; ctx->llcache = llcache; ctx->parent = parent; ctx->mime_type = NULL; ctx->total_length = 0; ctx->window = NULL; llcache_handle_change_callback(llcache, download_callback, ctx); return NSERROR_OK; }
/** * Clone a content's data members * * \param c Content to clone * \param nc Content to populate * \return NSERROR_OK on success, appropriate error otherwise */ nserror content__clone(const struct content *c, struct content *nc) { nserror error; error = llcache_handle_clone(c->llcache, &(nc->llcache)); if (error != NSERROR_OK) { return error; } llcache_handle_change_callback(nc->llcache, content_llcache_callback, nc); nc->mime_type = lwc_string_ref(c->mime_type); nc->handler = c->handler; nc->status = c->status; nc->width = c->width; nc->height = c->height; nc->available_width = c->available_width; nc->quirks = c->quirks; if (c->fallback_charset != NULL) { nc->fallback_charset = strdup(c->fallback_charset); if (nc->fallback_charset == NULL) { return NSERROR_NOMEM; } } if (c->refresh != NULL) { nc->refresh = nsurl_ref(c->refresh); if (nc->refresh == NULL) { return NSERROR_NOMEM; } } nc->time = c->time; nc->reformat_time = c->reformat_time; nc->size = c->size; if (c->title != NULL) { nc->title = strdup(c->title); if (nc->title == NULL) { return NSERROR_NOMEM; } } nc->active = c->active; nc->user_list = calloc(1, sizeof(struct content_user)); if (nc->user_list == NULL) { return NSERROR_NOMEM; } memcpy(&(nc->status_message), &(c->status_message), 120); memcpy(&(nc->sub_status), &(c->sub_status), 80); nc->locked = c->locked; nc->total_size = c->total_size; nc->http_code = c->http_code; return NSERROR_OK; }