Ejemplo n.º 1
0
static struct mbb_task *mbb_task_new(GQuark name, struct mbb_task_hook *hook, gpointer data)
{
	struct mbb_task *task;

	task = g_new(struct mbb_task, 1);
	task->name = name;
	time(&task->start);
	task->cancel = FALSE;
	task->run = TRUE;

	task->sid = mbb_thread_get_tid();
	if (task->sid >= 0)
		task->user = mbb_user_ref(mbb_thread_get_user());
	else {
		task->sid = mbb_task_get_tid();
		task->user = mbb_user_ref(mbb_task_get_user());
	}

	task->hook = hook;
	task->data = data;

	task->mutex = g_mutex_new();
	task->cond = g_cond_new();

	task->mod = mbb_module_last_used();
	mbb_module_use(task->mod);

	mbb_plock_writer_lock();

	if (ht == NULL)
		ht = g_hash_table_new(g_direct_hash, g_direct_equal);
	task->id = task_id++;
	g_hash_table_insert(ht, GINT_TO_POINTER(task->id), task);

	mbb_plock_writer_unlock();

	return task;
}
Ejemplo n.º 2
0
gboolean mbb_session_auth(struct mbb_session *ss, gchar *login, gchar *secret,
			  gchar *type)
{
	MbbUser *user;

	mbb_lock_reader_lock();
	user = mbb_auth(login, secret, type);
	if (user != NULL) {
		if (ss->user != NULL)
			mbb_user_unref(ss->user);

		ss->user = mbb_user_ref(user);
		mbb_log("auth as %s", user->name);
	}
	mbb_lock_reader_unlock();

	return user != NULL;
}