static void lock_cookie(struct listbox_item *item) { if (item->type == BI_LEAF) object_lock((struct cookie *) item->udata); else object_lock((struct cookie_server *) item->udata); }
static widget_handler_status_T push_add_button(struct dialog_data *dlg_data, struct widget_data *button) { struct listbox_data *box = get_dlg_listbox_data(dlg_data); struct terminal *term = dlg_data->win->term; struct cookie *new_cookie; struct cookie_server *server; if (!box->sel || !box->sel->udata) return EVENT_PROCESSED; if (box->sel->type == BI_FOLDER) { assert(box->sel->depth == 0); server = (struct cookie_server *)box->sel->udata; } else { struct cookie *cookie = (struct cookie *)box->sel->udata; server = cookie->server; } object_lock(server); /* ref consumed by init_cookie */ new_cookie = init_cookie(stracpy((const unsigned char *)"") /* name */, stracpy((const unsigned char *)"") /* value */, stracpy((const unsigned char *)"/") /* path */, stracpy(server->host) /* domain */, server); if (!new_cookie) return EVENT_PROCESSED; accept_cookie(new_cookie); build_edit_dialog(term, new_cookie); return EVENT_PROCESSED; }
void display_download(struct terminal *term, struct file_download *file_download, struct session *ses) { /* [gettext_accelerator_context(display_download)] */ struct dialog *dlg; if (!is_in_downloads_list(file_download)) return; #if CONFIG_BITTORRENT #define DOWNLOAD_WIDGETS_COUNT 5 #else #define DOWNLOAD_WIDGETS_COUNT 4 #endif dlg = calloc_dialog(DOWNLOAD_WIDGETS_COUNT, 0); if (!dlg) return; undisplay_download(file_download); file_download->ses = ses; dlg->title = _("Download", term); dlg->layouter = download_dialog_layouter; dlg->abort = download_abort_function; dlg->udata = file_download; object_lock(file_download); add_dlg_button(dlg, _("~Background", term), B_ENTER | B_ESC, dlg_undisplay_download, NULL); add_dlg_button(dlg, _("Background with ~notify", term), B_ENTER | B_ESC, dlg_set_notify, NULL); #if CONFIG_BITTORRENT if (file_download->uri->protocol == PROTOCOL_BITTORRENT) add_dlg_button(dlg, _("~Info", term), B_ENTER | B_ESC, dlg_show_bittorrent_info, NULL); #endif add_dlg_button(dlg, _("~Abort", term), 0, dlg_abort_download, NULL); /* Downloads scheduled to be opened by external handlers are always * deleted. */ if (!file_download->external_handler) { add_dlg_button(dlg, _("Abort and ~delete file", term), 0, push_delete_button, NULL); } #if CONFIG_BITTORRENT add_dlg_end(dlg, DOWNLOAD_WIDGETS_COUNT - !!file_download->external_handler - (file_download->uri->protocol != PROTOCOL_BITTORRENT)); #else add_dlg_end(dlg, DOWNLOAD_WIDGETS_COUNT - !!file_download->external_handler); #endif do_dialog(term, dlg, getml(dlg, (void *) NULL)); }
static JSObject * smjs_get_globhist_item_object(struct global_history_item *history_item) { JSObject *jsobj; jsobj = JS_NewObject(smjs_ctx, (JSClass *) &smjs_globhist_item_class, NULL, NULL); if (!jsobj || JS_TRUE != JS_DefineProperties(smjs_ctx, jsobj, (JSPropertySpec *) smjs_globhist_item_props) || JS_TRUE != JS_SetPrivate(smjs_ctx, jsobj, history_item)) /* to @smjs_globhist_item_class */ return NULL; object_lock(history_item); return jsobj; }
static JSObject * smjs_get_bookmark_generic_object(struct bookmark *bookmark, JSClass *clasp) { JSObject *jsobj; assert(clasp == &bookmark_class || clasp == &bookmark_folder_class); if_assert_failed return NULL; jsobj = JS_NewObject(smjs_ctx, clasp, NULL, NULL); if (!jsobj) return NULL; if (!bookmark) return jsobj; if (JS_TRUE == JS_SetPrivate(smjs_ctx, jsobj, bookmark)) { /* to @bookmark_class or @bookmark_folder_class */ object_lock(bookmark); return jsobj; } return NULL; };
static void smjs_loading_callback(struct download *download, void *data) { struct session *saved_smjs_ses = smjs_ses; struct smjs_load_uri_hop *hop = data; jsval args[1], rval; JSObject *cache_entry_object; if (is_in_progress_state(download->state)) return; if (!download->cached) goto end; /* download->cached->object.refcount is typically 0 here * because no struct document uses the cache entry. Because * the connection is no longer using the cache entry either, * it can be garbage collected. Don't let that happen while * the script is using it. */ object_lock(download->cached); smjs_ses = hop->ses; cache_entry_object = smjs_get_cache_entry_object(download->cached); if (!cache_entry_object) goto end; args[0] = OBJECT_TO_JSVAL(cache_entry_object); JS_CallFunctionValue(smjs_ctx, NULL, hop->callback, 1, args, &rval); end: if (download->cached) object_unlock(download->cached); JS_RemoveValueRoot(smjs_ctx, &hop->callback); mem_free(download->data); mem_free(download); smjs_ses = saved_smjs_ses; }
static void lock_cache_entry(struct listbox_item *item) { object_lock((struct cache_entry *) item->udata); }
/* @cache_entry_class.getProperty */ static JSBool cache_entry_get_property(JSContext *ctx, JSObject *obj, jsid id, jsval *vp) { struct cache_entry *cached; JSBool ret; /* This can be called if @obj if not itself an instance of the * appropriate class but has one in its prototype chain. Fail * such calls. */ if (!JS_InstanceOf(ctx, obj, (JSClass *) &cache_entry_class, NULL)) return JS_FALSE; cached = JS_GetInstancePrivate(ctx, obj, (JSClass *) &cache_entry_class, NULL); if (!cached) return JS_FALSE; /* already detached */ assert(cache_entry_is_valid(cached)); if_assert_failed return JS_FALSE; /* Get a strong reference to the cache entry to prevent it * from being deleted if some function called below decides to * collect garbage. After this, all code paths must * eventually unlock the object. */ object_lock(cached); undef_to_jsval(ctx, vp); if (!JSID_IS_INT(id)) ret = JS_FALSE; else switch (JSID_TO_INT(id)) { case CACHE_ENTRY_CONTENT: { struct fragment *fragment = get_cache_fragment(cached); if (!fragment) { ret = JS_FALSE; break; } *vp = STRING_TO_JSVAL(JS_NewStringCopyN(smjs_ctx, fragment->data, fragment->length)); ret = JS_TRUE; break; } case CACHE_ENTRY_TYPE: *vp = STRING_TO_JSVAL(JS_NewStringCopyZ(smjs_ctx, cached->content_type)); ret = JS_TRUE; break; case CACHE_ENTRY_HEAD: *vp = STRING_TO_JSVAL(JS_NewStringCopyZ(smjs_ctx, cached->head)); ret = JS_TRUE; break; case CACHE_ENTRY_LENGTH: *vp = INT_TO_JSVAL(cached->length); ret = JS_TRUE; break; case CACHE_ENTRY_URI: *vp = STRING_TO_JSVAL(JS_NewStringCopyZ(smjs_ctx, struri(cached->uri))); ret = JS_TRUE; break; default: /* Unrecognized integer property ID; someone is using * the object as an array. SMJS builtin classes (e.g. * js_RegExpClass) just return JS_TRUE in this case * and leave *@vp unchanged. Do the same here. * (Actually not quite the same, as we already used * @undef_to_jsval.) */ ret = JS_TRUE; break; } object_unlock(cached); return ret; }
/* @cache_entry_class.setProperty */ static JSBool cache_entry_set_property(JSContext *ctx, JSObject *obj, jsid id, JSBool strict, jsval *vp) { struct cache_entry *cached; JSBool ret; /* This can be called if @obj if not itself an instance of the * appropriate class but has one in its prototype chain. Fail * such calls. */ if (!JS_InstanceOf(ctx, obj, (JSClass *) &cache_entry_class, NULL)) return JS_FALSE; cached = JS_GetInstancePrivate(ctx, obj, (JSClass *) &cache_entry_class, NULL); if (!cached) return JS_FALSE; /* already detached */ assert(cache_entry_is_valid(cached)); if_assert_failed return JS_FALSE; /* Get a strong reference to the cache entry to prevent it * from being deleted if some function called below decides to * collect garbage. After this, all code paths must * eventually unlock the object. */ object_lock(cached); if (!JSID_IS_INT(id)) ret = JS_FALSE; else switch (JSID_TO_INT(id)) { case CACHE_ENTRY_CONTENT: { JSString *jsstr = JS_ValueToString(smjs_ctx, *vp); unsigned char *str = JS_EncodeString(smjs_ctx, jsstr); size_t len = JS_GetStringLength(jsstr); add_fragment(cached, 0, str, len); normalize_cache_entry(cached, len); ret = JS_TRUE; break; } case CACHE_ENTRY_TYPE: { JSString *jsstr = JS_ValueToString(smjs_ctx, *vp); unsigned char *str = JS_EncodeString(smjs_ctx, jsstr); mem_free_set(&cached->content_type, stracpy(str)); ret = JS_TRUE; break; } case CACHE_ENTRY_HEAD: { JSString *jsstr = JS_ValueToString(smjs_ctx, *vp); unsigned char *str = JS_EncodeString(smjs_ctx, jsstr); mem_free_set(&cached->head, stracpy(str)); ret = JS_TRUE; break; } default: /* Unrecognized integer property ID; someone is using * the object as an array. SMJS builtin classes (e.g. * js_RegExpClass) just return JS_TRUE in this case. * Do the same here. */ ret = JS_TRUE; break; } object_unlock(cached); return ret; }
static void lock_file_download(struct listbox_item *item) { object_lock((struct file_download *) item->udata); }
static void lock_auth_entry(struct listbox_item *item) { object_lock((struct auth_entry *) item->udata); }