Пример #1
0
static void
unlock_cookie(struct listbox_item *item)
{
    if (item->type == BI_LEAF)
        object_unlock((struct cookie *) item->udata);
    else
        object_unlock((struct cookie_server *) item->udata);
}
Пример #2
0
static widget_handler_status_T
dlg_abort_download(struct dialog_data *dlg_data, struct widget_data *widget_data)
{
	struct file_download *file_download = dlg_data->dlg->udata;

	object_unlock(file_download);
	register_bottom_half(do_abort_download, file_download);
	return EVENT_PROCESSED;
}
Пример #3
0
/* @bookmark_class.finalize, @bookmark_folder_class.finalize */
static void
bookmark_finalize(JSContext *ctx, JSObject *obj)
{
	struct bookmark *bookmark;

	assert(JS_InstanceOf(ctx, obj, (JSClass *) &bookmark_class, NULL)
	    || JS_InstanceOf(ctx, obj, (JSClass *) &bookmark_folder_class, NULL));
	if_assert_failed return;

	bookmark = JS_GetPrivate(ctx, obj); /* from @bookmark_class or @bookmark_folder_class */

	if (bookmark) object_unlock(bookmark);
}
Пример #4
0
/* @smjs_globhist_item_class.finalize */
static void
smjs_globhist_item_finalize(JSContext *ctx, JSObject *obj)
{
	struct global_history_item *history_item;

	assert(JS_InstanceOf(ctx, obj, (JSClass *) &smjs_globhist_item_class, NULL));
	if_assert_failed return;

	history_item = JS_GetInstancePrivate(ctx, obj,
					     (JSClass *) &smjs_globhist_item_class,
					     NULL);

	if (history_item) object_unlock(history_item);
}
Пример #5
0
static widget_handler_status_T
push_delete_button(struct dialog_data *dlg_data, struct widget_data *widget_data)
{
	struct file_download *file_download = dlg_data->dlg->udata;

	file_download->delete_ = 1;
#if CONFIG_BITTORRENT
	if (file_download->uri->protocol == PROTOCOL_BITTORRENT)
		set_bittorrent_files_for_deletion(&file_download->download);
#endif
	object_unlock(file_download);
	register_bottom_half(do_abort_download, file_download);
	return EVENT_PROCESSED;
}
Пример #6
0
void client_submit_error(YAAMP_CLIENT *client, YAAMP_JOB *job, int id, const char *message, char *extranonce2, char *ntime, char *nonce)
{
//	if(job->templ->created+2 > time(NULL))
	if(job && job->deleted)
		client_send_result(client, "true");

	else
	{
		client_send_error(client, id, message);
		share_add(client, job, false, extranonce2, ntime, nonce, id);

		client->submit_bad++;
//		dump_submit_debug(message, client, job, extranonce2, ntime, nonce);
	}

	object_unlock(job);
}
Пример #7
0
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;
}
Пример #8
0
static void
unlock_cache_entry(struct listbox_item *item)
{
	object_unlock((struct cache_entry *) item->udata);
}
Пример #9
0
bool client_submit(YAAMP_CLIENT *client, json_value *json_params)
{
	// submit(worker_name, jobid, extranonce2, ntime, nonce):
	if(json_params->u.array.length<5)
	{
		debuglog("%s - %s bad message\n", client->username, client->sock->ip);
		client->submit_bad++;
		return false;
	}

//	char name[1024];
	char extranonce2[32];
	char ntime[32];
	char nonce[32];

	memset(extranonce2, 0, 32);
	memset(ntime, 0, 32);
	memset(nonce, 0, 32);

	int jobid = htoi(json_params->u.array.values[1]->u.string.ptr);
	strncpy(extranonce2, json_params->u.array.values[2]->u.string.ptr, 31);
	strncpy(ntime, json_params->u.array.values[3]->u.string.ptr, 31);
	strncpy(nonce, json_params->u.array.values[4]->u.string.ptr, 31);

//	debuglog("submit %s %d, %s, %s, %s\n", client->sock->ip, jobid, extranonce2, ntime, nonce);

	string_lower(extranonce2);
	string_lower(ntime);
	string_lower(nonce);

	YAAMP_JOB *job = (YAAMP_JOB *)object_find(&g_list_job, jobid, true);
	if(!job)
	{
		client_submit_error(client, NULL, 21, "Invalid job id", extranonce2, ntime, nonce);
		return true;
	}

	if(job->deleted)
	{
		client_send_result(client, "true");
		object_unlock(job);

		return true;
	}

	YAAMP_JOB_TEMPLATE *templ = job->templ;
//	dump_submit_debug(client, job, extranonce2, ntime, nonce);

	if(strlen(nonce) != YAAMP_NONCE_SIZE*2)
	{
		client_submit_error(client, job, 20, "Invalid nonce size", extranonce2, ntime, nonce);
		return true;
	}

//	if(strcmp(ntime, templ->ntime))
//	{
//		client_submit_error(client, job, 23, "Invalid time rolling", extranonce2, ntime, nonce);
//		return true;
//	}

	YAAMP_SHARE *share = share_find(job->id, extranonce2, ntime, nonce, client->extranonce1);
	if(share)
	{
		client_submit_error(client, job, 22, "Duplicate share", extranonce2, ntime, nonce);
		return true;
	}

	if(strlen(extranonce2) != client->extranonce2size*2)
	{
		client_submit_error(client, job, 24, "Invalid extranonce2 size", extranonce2, ntime, nonce);
		return true;
	}

	///////////////////////////////////////////////////////////////////////////////////////////

	YAAMP_JOB_VALUES submitvalues;
	memset(&submitvalues, 0, sizeof(submitvalues));

	build_submit_values(&submitvalues, templ, client->extranonce1, extranonce2, ntime, nonce);
	if(submitvalues.hash_bin[30] || submitvalues.hash_bin[31])
	{
		client_submit_error(client, job, 25, "Invalid share", extranonce2, ntime, nonce);
		return true;
	}

	uint64_t hash_int = get_hash_difficulty(submitvalues.hash_bin);
	uint64_t user_target = diff_to_target(client->difficulty_actual);
	uint64_t coin_target = decode_compact(templ->nbits);

//	debuglog("%016llx actual\n", hash_int);
//	debuglog("%016llx target\n", user_target);
//	debuglog("%016llx coin\n", coin_target);

	if(hash_int > user_target && hash_int > coin_target)
	{
		client_submit_error(client, job, 26, "Low difficulty share", extranonce2, ntime, nonce);
		return true;
	}

	if(job->coind)
		client_do_submit(client, job, &submitvalues, extranonce2, ntime, nonce);
	else
		remote_submit(client, job, &submitvalues, extranonce2, ntime, nonce);

	client_send_result(client, "true");
	client_record_difficulty(client);
	client->submit_bad = 0;

	share_add(client, job, true, extranonce2, ntime, nonce, 0);
	object_unlock(job);

	return true;
}
Пример #10
0
/* @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;
}
Пример #11
0
/* @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;
}
Пример #12
0
static void
unlock_file_download(struct listbox_item *item)
{
	object_unlock((struct file_download *) item->udata);
}