Пример #1
0
XmlTag *mbb_time_test_order(time_t a, time_t b, time_t pa, time_t pb)
{
	if (a < 0 && b < 0)
		;
	else if (a < 0) {
		if (mbb_time_becmp(pa, b) > 0)
			return mbb_xml_msg(MBB_MSG_PSTART_MORE_END);
	} else if (b < 0) {
		if (mbb_time_becmp(a, pb) > 0)
			return mbb_xml_msg(MBB_MSG_PEND_LESS_START);
	} else if (mbb_time_becmp(a, b) > 0)
		return mbb_xml_msg(MBB_MSG_INVALID_TIME_ORDER);

	return NULL;
}
Пример #2
0
static void process_request(struct http_thread_env *hte)
{
	gchar *method;
	XmlTag *ans;

	method = hte->method;

	if (method != NULL) {
		if (hte->root_tag == NULL)
			hte->root_tag = xml_tag_newc("request");

		xml_tag_set_attr(hte->root_tag,
			"name", variant_new_static_string(method)
		);

		if (mbb_func_call(method, hte->root_tag, &ans) == FALSE)
			ans = mbb_xml_msg(MBB_MSG_UNKNOWN_METHOD, method);
	} else {
		Variant *var;
		XmlTag *tag;
		XmlTag *xt;

		ans = mbb_xml_msg_ok();
		xt = xml_tag_get_child(hte->root_tag, "request");
		xml_tag_reorder(xt);

		for (; xt != NULL; xt = xt->next) {
			var = xml_tag_get_attr(xt, "name");
			if (var == NULL)
				continue;

			method = variant_get_string(var);
			if (mbb_func_call(method, xt, &tag) == FALSE)
				tag = mbb_xml_msg(MBB_MSG_UNKNOWN_METHOD, method);
			else if (tag == NULL)
				tag = mbb_xml_msg_ok();

			xml_tag_set_attr(tag,
				"origin", variant_new_static_string(method)
			);
			xml_tag_add_child(ans, tag);
		}

		xml_tag_reorder(xml_tag_get_child(ans, "response"));
	}

	push_http_xml_msg(hte, ans);
}
Пример #3
0
static void task_cancel(XmlTag *tag, XmlTag **ans)
{
	DEFINE_XTV(XTV_TASK_ID);

	struct mbb_task *task;
	guint id;

	MBB_XTV_CALL(&id);

	mbb_plock_reader_lock();

	on_final { mbb_plock_reader_unlock(); }

	task = mbb_task_get(id);
	if (task == NULL) final
		*ans = mbb_xml_msg(MBB_MSG_UNKNOWN_TASK);

	task->cancel = TRUE;
	g_mutex_lock(task->mutex);
	if (task->run == FALSE) {
		task->run = TRUE;
		mbb_task_resume(task);
	}
	g_mutex_unlock(task->mutex);

	mbb_plock_reader_unlock();
}
Пример #4
0
static void task_do_run(XmlTag *tag, XmlTag **ans, gboolean run)
{
	DEFINE_XTV(XTV_TASK_ID);

	struct mbb_task *task;
	guint id;

	MBB_XTV_CALL(&id);

	mbb_plock_reader_lock();

	on_final { mbb_plock_reader_unlock(); }

	task = mbb_task_get(id);
	if (task == NULL) final
		*ans = mbb_xml_msg(MBB_MSG_UNKNOWN_TASK);

	g_mutex_lock(task->mutex);
	if (task->run == run) final {
		g_mutex_unlock(task->mutex);
		*ans = mbb_xml_msg_error(
			"task is already %s", run ? "run" : "stop"
		);
	}

	task->run = run;
	if (run) mbb_task_resume(task);
	g_mutex_unlock(task->mutex);

	mbb_plock_reader_unlock();
}
Пример #5
0
static void unit_show_raw_inet(XmlTag *tag, XmlTag **ans)
{
	DEFINE_XTVN(xtvars, XTV_UNIT_NAME_);
	gchar *name = NULL;

	xml_tag_scan(tag, xtvars, NULL, &name);

	mbb_lock_reader_lock();

	if (name == NULL) {
		MbbInetPool *pool;

		*ans = mbb_xml_msg_ok();
		pool = mbb_unit_get_pool();

		mbb_inet_pool_foreach(
			pool, (GFunc) gather_entry_with_owner, *ans
		);
	} else {
		MbbUnit *unit;

		unit = mbb_unit_get_by_name(name);
		if (unit == NULL) final {
			mbb_lock_reader_unlock();
			*ans = mbb_xml_msg(MBB_MSG_UNKNOWN_UNIT);
		}

		*ans = mbb_xml_msg_ok();
		g_queue_foreach(&unit->sep.queue, (GFunc) gather_entry, *ans);
	}

	mbb_lock_reader_unlock();
}
Пример #6
0
static void unit_clear_inet(XmlTag *tag, XmlTag **ans)
{
	DEFINE_XTV(XTV_UNIT_NAME);

	MbbUnit *unit;
	gchar *name;
	GError *error;

	MBB_XTV_CALL(&name);

	mbb_lock_writer_lock();

	on_final { mbb_lock_writer_unlock(); }

	unit = mbb_unit_get_by_name(name);
	if (unit == NULL) final
		*ans = mbb_xml_msg(MBB_MSG_UNKNOWN_UNIT);

	error = NULL;
	if (! mbb_db_inet_pool_clear(unit->id, &error)) final
		*ans = mbb_xml_msg_from_error(error);

	mbb_unit_clear_inet(unit);

	mbb_lock_writer_unlock();

	mbb_log_debug("unit '%s' clear inet", name);
}
Пример #7
0
static void drop_inet(XmlTag *tag, XmlTag **ans)
{
	DEFINE_XTV(XTV_INET_ID);

	MbbInetPoolEntry *entry;
	MbbInetPool *pool;
	GError *error;
	gint id;

	MBB_XTV_CALL(&id);

	mbb_lock_writer_lock();

	on_final { mbb_lock_writer_unlock(); }

	pool = mbb_unit_get_pool();
	entry = mbb_inet_pool_get(pool, id);

	if (entry == NULL) final
		*ans = mbb_xml_msg(MBB_MSG_UNKNOWN_INET);

	error = NULL;
	if (! mbb_db_inet_pool_drop(entry->id, &error)) final
		*ans = mbb_xml_msg_from_error(error);

	mbb_unit_del_inet(entry->owner->ptr, entry);

	mbb_lock_writer_unlock();
}
Пример #8
0
static void unit_add_inet(XmlTag *tag, XmlTag **ans)
{
	DEFINE_XTV(
		XTV_UNIT_NAME, XTV_INET_INET,
		XTV_INET_EXCLUSIVE_, XTV_INET_NICE_, XTV_INET_INHERIT_
	);

	MbbInetPoolEntry entry;
	MbbUnit *unit;
	gchar *name;

	gboolean inherit = FALSE;
	GError *error = NULL;

	mbb_inet_pool_entry_init(&entry);

	entry.flag = FALSE;
	entry.nice = 0;
	MBB_XTV_CALL(&name, &entry.inet, &entry.flag, &entry.nice, &inherit);
	entry.flag = ! entry.flag;

	mbb_lock_writer_lock();

	on_final { mbb_lock_writer_unlock(); }

	unit = mbb_unit_get_by_name(name);
	if (unit == NULL) final
		*ans = mbb_xml_msg(MBB_MSG_UNKNOWN_UNIT);

	if (inherit == FALSE && mbb_unit_get_end(unit) != 0) final
		*ans = mbb_xml_msg(MBB_MSG_UNIT_FREEZED, name);

	entry.owner = &unit->self;
	entry.end = -1;
	if (inherit)
		entry.start = -1;
	else
		time(&entry.start);

	entry.id = mbb_db_inet_pool_add(&entry, unit->id, &error);
	if (entry.id < 0) final
		*ans = mbb_xml_msg_from_error(error);

	mbb_unit_add_inet(unit, g_memdup(&entry, sizeof(entry)));

	mbb_lock_writer_unlock();
}
Пример #9
0
static void unit_mod_inet_time(XmlTag *tag, XmlTag **ans)
{
	DEFINE_XTV(XTV_INET_ID, XTV_ETIME_START_, XTV_ETIME_END_);

	MbbInetPoolEntry *entry;
	time_t start, end;
	gint id;

	start = end = MBB_TIME_UNSET;
	MBB_XTV_CALL(&id, &start, &end);

	if (start == MBB_TIME_UNSET && end == MBB_TIME_UNSET) final
		*ans = mbb_xml_msg(MBB_MSG_TIME_MISSED);

	mbb_lock_writer_lock();

	on_final { mbb_lock_writer_unlock(); }

	entry = mbb_inet_pool_get(mbb_unit_get_pool(), id);

	if (entry == NULL) final
		*ans = mbb_xml_msg(MBB_MSG_UNKNOWN_INET);

	exec_if(start = entry->start, start == MBB_TIME_UNSET);
	exec_if(end = entry->end, end == MBB_TIME_UNSET);

	*ans = mbb_time_test_order(start, end,
		mbb_unit_get_start(entry->owner->ptr),
		mbb_unit_get_end(entry->owner->ptr));

	if (*ans == NULL) {
		GError *error = NULL;

		if (! mbb_db_inet_pool_mod_time(entry->id, start, end, &error))
			final *ans = mbb_xml_msg_from_error(error);
	}