Esempio n. 1
0
File: xrdp.c Progetto: dlinz/xrdp-ng
/* This function is used to run a function from the main thread.
 Sync_func is the function pointer that will run from main thread
 The function can have two long in parameters and must return long */
long g_xrdp_sync(long(*sync_func)(long param1, long param2), long sync_param1, long sync_param2)
{
	long sync_result;
	int sync_command;

	/* If the function is called from the main thread, the function can
	 * be called directly. g_threadid= main thread ID*/
	if (tc_threadid_equal(tc_get_threadid(), g_threadid))
	{
		/* this is the main thread, call the function directly */
		/* in fork mode, this always happens too */
		sync_result = sync_func(sync_param1, sync_param2);
		/*g_writeln("g_xrdp_sync processed IN main thread -> continue");*/
	}
	else
	{
		/* All threads have to wait here until the main thread
		 * process the function. g_process_waiting_function() is called
		 * from the listening thread. g_process_waiting_function() process the function*/
		tc_mutex_lock(g_sync1_mutex);
		tc_mutex_lock(g_sync_mutex);
		g_sync_param1 = sync_param1;
		g_sync_param2 = sync_param2;
		g_sync_func = sync_func;
		/* set a value THREAD_WAITING so the g_process_waiting_function function
		 * know if any function must be processed */
		g_sync_command = THREAD_WAITING;
		tc_mutex_unlock(g_sync_mutex);
		/* set this event so that the main thread know if
		 * g_process_waiting_function() must be called */
		SetEvent(g_SyncEvent);

		do
		{
			g_sleep(100);
			tc_mutex_lock(g_sync_mutex);
			/* load new value from global to see if the g_process_waiting_function()
			 * function has processed the function */
			sync_command = g_sync_command;
			sync_result = g_sync_result;
			tc_mutex_unlock(g_sync_mutex);
		} while (sync_command != 0); /* loop until g_process_waiting_function()

		 * has processed the request */
		tc_mutex_unlock(g_sync1_mutex);
		/*g_writeln("g_xrdp_sync processed BY main thread -> continue");*/
	}

	return sync_result;
}
Esempio n. 2
0
void APP_CC
lock_sync_acquire(void)
{
  /* lock sync variable */
  LOG_DBG("lock_sync_acquire()");
  tc_mutex_lock(g_sync_mutex);
}
Esempio n. 3
0
void APP_CC
lock_chain_acquire(void)
{
  /* lock the chain */
  LOG_DBG("lock_chain_acquire()");
  tc_mutex_lock(g_lock_chain);
}
Esempio n. 4
0
static int tc_import_thread_is_active(TCImportData *imdata)
{
    int flag;
    tc_mutex_lock(&imdata->lock);
    flag = imdata->active_flag;
    tc_mutex_unlock(&imdata->lock);
    return flag;;
}
Esempio n. 5
0
int tc_unref_graphicsmagick(void)
{
    int ref = 0;
    tc_mutex_lock(&tc_magick_mutex);
    ref = --magick_refcount;
    tc_mutex_unlock(&tc_magick_mutex);
    return ref;
}
Esempio n. 6
0
int tc_socket_get_pv_cmd(TCSockPVCmd *pvcmd)
{
    tc_mutex_lock(&tc_socket_msg_lock);
    pvcmd->cmd = sock_cmd.cmd;
    pvcmd->arg = sock_cmd.arg;
    sock_cmd.cmd = TC_SOCK_PV_NONE;
    tc_mutex_unlock(&tc_socket_msg_lock);

    return TC_OK;
}
Esempio n. 7
0
long APP_CC
g_xrdp_sync(long (*sync_func)(long param1, long param2), long sync_param1,
            long sync_param2)
{
    long sync_result;
    int sync_command;

    if (tc_threadid_equal(tc_get_threadid(), g_threadid))
    {
        /* this is the main thread, call the function directly */
        sync_result = sync_func(sync_param1, sync_param2);
    }
    else
    {
        tc_mutex_lock(g_sync1_mutex);
        tc_mutex_lock(g_sync_mutex);
        g_sync_param1 = sync_param1;
        g_sync_param2 = sync_param2;
        g_sync_func = sync_func;
        g_sync_command = 100;
        tc_mutex_unlock(g_sync_mutex);
        g_set_wait_obj(g_sync_event);

        do
        {
            g_sleep(100);
            tc_mutex_lock(g_sync_mutex);
            sync_command = g_sync_command;
            sync_result = g_sync_result;
            tc_mutex_unlock(g_sync_mutex);
        }
        while (sync_command != 0);

        tc_mutex_unlock(g_sync1_mutex);
    }

    return sync_result;
}
Esempio n. 8
0
File: xrdp.c Progetto: dlinz/xrdp-ng
/*Some function must be called from the main thread.
 if g_sync_command==THREAD_WAITING a function is waiting to be processed*/
void g_process_waiting_function(void)
{
	tc_mutex_lock(g_sync_mutex);

	if (g_sync_command != 0)
	{
		if (g_sync_func != 0)
		{
			if (g_sync_command == THREAD_WAITING)
			{
				g_sync_result = g_sync_func(g_sync_param1, g_sync_param2);
			}
		}

		g_sync_command = 0;
	}

	tc_mutex_unlock(g_sync_mutex);
}
Esempio n. 9
0
static int probe_im_stream(const char *src, ProbeInfo *info)
{
    static TCMutex probe_lock; /* FIXME */
    static int inited = 0;
    /* UGLY! */
    int ret = 1; /* be optimistic! */

    if (!inited) { /* FIXME */
        tc_mutex_init(&probe_lock);
        inited = 1;
    }

    tc_mutex_lock(&probe_lock);
    ret = probe_stream_data(src, seek_range, info);
    tc_mutex_unlock(&probe_lock);

    dump_probeinfo(info, 0, "probed");

    return ret;
}
Esempio n. 10
0
void APP_CC
g_process_waiting_function(void)
{
    tc_mutex_lock(g_sync_mutex);

    if (g_sync_command != 0)
    {
        if (g_sync_func != 0)
        {
            if (g_sync_command == 100)
            {
                g_sync_result = g_sync_func(g_sync_param1, g_sync_param2);
            }
        }

        g_sync_command = 0;
    }

    tc_mutex_unlock(g_sync_mutex);
}
Esempio n. 11
0
static int APP_CC
rail_process_exec(struct stream *s, int size)
{
    int flags;
    int ExeOrFileLength;
    int WorkingDirLength;
    int ArgumentsLen;
    char *ExeOrFile;
    char *WorkingDir;
    char *Arguments;

    LOG(0, ("chansrv::rail_process_exec:"));
    in_uint16_le(s, flags);
    in_uint16_le(s, ExeOrFileLength);
    in_uint16_le(s, WorkingDirLength);
    in_uint16_le(s, ArgumentsLen);
    ExeOrFile = read_uni(s, ExeOrFileLength);
    WorkingDir = read_uni(s, WorkingDirLength);
    Arguments = read_uni(s, ArgumentsLen);
    LOG(10, ("  flags 0x%8.8x ExeOrFileLength %d WorkingDirLength %d "
             "ArgumentsLen %d ExeOrFile [%s] WorkingDir [%s] "
             "Arguments [%s]", flags, ExeOrFileLength, WorkingDirLength,
             ArgumentsLen, ExeOrFile, WorkingDir, Arguments));

    if (g_strlen(ExeOrFile) > 0)
    {
        LOG(10, ("rail_process_exec: pre"));
        /* ask main thread to fork */
        tc_mutex_lock(g_exec_mutex);
        g_exec_name = ExeOrFile;
        g_set_wait_obj(g_exec_event);
        tc_sem_dec(g_exec_sem);
        tc_mutex_unlock(g_exec_mutex);
        LOG(10, ("rail_process_exec: post"));
    }

    g_free(ExeOrFile);
    g_free(WorkingDir);
    g_free(Arguments);
    return 0;
}
Esempio n. 12
0
void DEFAULT_CC
scp_v0_process(struct SCP_CONNECTION* c, struct SCP_SESSION* s)
{
	int display = 0;
	tbus data;
	struct session_item* s_item;

	tc_mutex_lock(session_creation_lock);
	data = auth_userpass(NULL, s->username, s->password);

	#ifdef CHECK_PREMIUM_EDITION
	bool valid = true;
	if (get_module_version(get_module_name()) & PREMIUM_EDITION) {
	  printf("%s %i %i  %i \n", __FUNCTION__, g_time3(), last_time_premium_edition_check, CHECK_INTERVAL);
	  if (((g_time3() - last_time_premium_edition_check) > CHECK_INTERVAL) ||  last_time_premium_edition_check == 0) {
	    printf("%s FOFOFOOF\n", __FUNCTION__);
	    valid = check_premium_edition();
	  }
	}
	if (!valid) {
	  data = 0;
	  scp_v0s_deny_connection(c, "Unable to launch the session\nInvalid License\nPlease contact your administrator\n");
	  tc_mutex_unlock(session_creation_lock);
	  return;
	}
#endif

	if (data == 0)
	{
		log_message(&(g_cfg->log), LOG_LEVEL_WARNING, "User %s failed to authenticate", s->username);
		scp_v0s_deny_connection(c, "Your username or \nyour password is invalid");
		tc_mutex_unlock(session_creation_lock);
		return;
	}
	lock_chain_acquire();
	s_item = session_get_bydata(s->username);
	lock_chain_release();

	if (s_item != 0)
	{
		log_message(&(g_cfg->log), LOG_LEVEL_INFO, "A session for User %s already exist", s->username);
		display = s_item->display;
		if (s_item->status == SESMAN_SESSION_STATUS_TO_DESTROY)
		{
			log_message(&(g_cfg->log), LOG_LEVEL_WARNING, "Session for user %s is in destroy, unable to initialize a new session", s->username);
			scp_v0s_deny_connection(c, "Your last session is currently \nended, retry later");
		}
		else
		{
			session_update_status_by_user(s_item->name, SESMAN_SESSION_STATUS_ACTIVE);
			log_message(&(g_cfg->log), LOG_LEVEL_INFO, "switch from status DISCONNECTED to ACTIVE");
			session_switch_resolution(s->width, s->height, display);
			session_add_client_pid(s_item->name, s->client_pid);

			scp_v0s_allow_connection(c, display);
		}

		auth_end(data);
		tc_mutex_unlock(session_creation_lock);
		return;
	}
	log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, "No session already started for the user %s", s->username);
	if (access_login_allowed(s->username) == 0)
	{
		log_message(&(g_cfg->log), LOG_LEVEL_WARNING, "User %s is not allow to start session", s->username);
		display = 0;
		scp_v0s_deny_connection(c, "You are not allowed\nto start a session\n");

		auth_end(data);
		tc_mutex_unlock(session_creation_lock);
		return;
	}

	log_message(&(g_cfg->log), LOG_LEVEL_INFO, "granted TS access to user %s", s->username);
	if (SCP_SESSION_TYPE_XVNC == s->type)
	{
		log_message(&(g_cfg->log), LOG_LEVEL_INFO, "starting Xvnc session for the user %s ...", s->username);
		display = session_start(s->width, s->height, s->bpp, s->username,
				s->password, data, SESMAN_SESSION_TYPE_XVNC,
				s->domain, s->program, s->directory, s->keylayout, s->client_pid, s->use_scim);
	}
	else
	{
		log_message(&(g_cfg->log), LOG_LEVEL_INFO, "starting X11rdp session for the user %s ...", s->username);
		display = session_start(s->width, s->height, s->bpp, s->username,
				s->password, data, SESMAN_SESSION_TYPE_XRDP,
				s->domain, s->program, s->directory, s->keylayout, s->client_pid, s->use_scim);
	}

	auth_end(data);
	if (display == 0)
	{
		data = 0;
		scp_v0s_deny_connection(c, "Unable to launch the session\nPlease contact\nyour administrator\n");
	}
	else
	{
		scp_v0s_allow_connection(c, display);
	}

	tc_mutex_unlock(session_creation_lock);
}
Esempio n. 13
0
void tc_lock_libavcodec(void)
{
    tc_mutex_lock(&tc_libavcodec_mutex);
}
Esempio n. 14
0
/*
 * tc_import_thread_start (Thread safe): mark the import status flag
 * as `started'; import thread become running and it starts producing data.
 *
 * Parameters:
 *      imdata: pointer to a TCImportData structure representing the
 *               import thread to start.
 * Return Value:
 *      None
 */
static void tc_import_thread_start(TCImportData *imdata)
{
    tc_mutex_lock(&imdata->lock);
    imdata->active_flag = TC_TRUE;
    tc_mutex_unlock(&imdata->lock);
}
Esempio n. 15
0
static int handle_preview(char *params)
{
    int filter_id, cmd, arg;
    char *cmdstr, *argstr;

    /* Check that the preview filter is loaded, and load it if not */
    filter_id = tc_filter_find("pv");
    if (!filter_id) {
        filter_id = tc_filter_add("pv", "cache=20");
        if (!filter_id)
            return 0;
    }

    /* Parse out preview command name and (optional) argument */
    cmdstr = strtok(params, " \t");
    if (cmdstr)  // there are strtok() implementations that crash without this!
        argstr = strtok(NULL, " \t");
    else
        argstr = NULL;
    if (argstr)
        arg = atoi(argstr);
    else
        arg = 0;

    if        (!strncasecmp(cmdstr, "draw",    2)) {
        cmd = TC_SOCK_PV_DRAW;
    } else if (!strncasecmp(cmdstr, "pause",  2)) {
        cmd = TC_SOCK_PV_PAUSE;
    } else if (!strncasecmp(cmdstr, "undo", 2)) {
        cmd = TC_SOCK_PV_UNDO;
    } else if (!strncasecmp(cmdstr, "fastfw", 6)) {
        cmd = TC_SOCK_PV_FAST_FW;
    } else if (!strncasecmp(cmdstr, "fastbw", 6)) {
        cmd = TC_SOCK_PV_FAST_BW;
    } else if (!strncasecmp(cmdstr, "slowfw", 6)) {
        cmd = TC_SOCK_PV_SLOW_FW;
    } else if (!strncasecmp(cmdstr, "slowbw", 6)) {
        cmd = TC_SOCK_PV_SLOW_BW;
    } else if (!strncasecmp(cmdstr, "toggle", 6)) {
        cmd = TC_SOCK_PV_TOGGLE;
    } else if (!strncasecmp(cmdstr, "slower", 6)) {
        cmd = TC_SOCK_PV_SLOWER;
    } else if (!strncasecmp(cmdstr, "faster", 6)) {
        cmd = TC_SOCK_PV_FASTER;
    } else if (!strncasecmp(cmdstr, "rotate", 6)) {
        cmd = TC_SOCK_PV_ROTATE;
    } else if (!strncasecmp(cmdstr, "display", 6)) {
        cmd = TC_SOCK_PV_DISPLAY;
    } else if (!strncasecmp(cmdstr, "grab", 4)) {
        cmd = TC_SOCK_PV_SAVE_JPG;
    } else {
        return 0;
    }

    tc_mutex_lock(&tc_socket_msg_lock);
    sock_cmd.cmd = cmd;
    sock_cmd.arg = arg;
    tc_mutex_unlock(&tc_socket_msg_lock);

    return 1;
}
Esempio n. 16
0
	void
thread_pool_acquire_job(THREAD_POOL* pool)
{
	tc_mutex_lock(pool->job_wait);
}
Esempio n. 17
0
	void
thread_pool_lock_thread(THREAD_POOL* pool)
{
	tc_mutex_lock(pool->thread_wait);
}