Пример #1
0
Файл: dm.c Проект: bbidulock/wdm
static void ScanServers(void)
{
	char lineBuf[10240];
	int len;
	FILE *serversFile;
	struct stat statb;
	static DisplayType acceptableTypes[] = { {Local, Permanent, FromFile},
	{Foreign, Permanent, FromFile},
	};

#define NumTypes    (sizeof (acceptableTypes) / sizeof (acceptableTypes[0]))

	if (servers[0] == '/') {
		serversFile = fopen(servers, "r");
		if (serversFile == NULL) {
			WDMError("cannot access servers file %s\n", servers);
			return;
		}
		if (ServersModTime == 0) {
			fstat(fileno(serversFile), &statb);
			ServersModTime = statb.st_mtime;
		}
		while (fgets(lineBuf, sizeof(lineBuf) - 1, serversFile)) {
			len = strlen(lineBuf);
			if (lineBuf[len - 1] == '\n')
				lineBuf[len - 1] = '\0';
			ParseDisplay(lineBuf, acceptableTypes, NumTypes);
		}
		fclose(serversFile);
	} else {
		ParseDisplay(servers, acceptableTypes, NumTypes);
	}
}
Пример #2
0
static void
ScanServers (void)
{
    char	lineBuf[10240];
    int		len;
    FILE	*serversFile;
    struct stat	statb;

    if (servers[0] == '/')
    {
	serversFile = fopen (servers, "r");
	if (serversFile == NULL)
	{
	    LogError ("cannot access servers file %s\n", servers);
	    return;
	}
	if (ServersModTime == 0)
	{
	    fstat (fileno (serversFile), &statb);
	    ServersModTime = statb.st_mtime;
	}
	while (fgets (lineBuf, sizeof (lineBuf)-1, serversFile))
	{
	    len = strlen (lineBuf);
	    if (lineBuf[len-1] == '\n')
		lineBuf[len-1] = '\0';
	    ParseDisplay (lineBuf);
	}
	fclose (serversFile);
    }
    else
    {
	ParseDisplay (servers);
    }
}
Пример #3
0
void LoadConfigFile (const char *fn)
{
	xmlDocPtr doc;
	xmlNodePtr root,
		   child;

	doc = xmlParseFile (fn);
	Player *players = g_players;

	if (doc == NULL)
	{
		std::cerr << "Could not parse config file\n";
		return;
	}

	root = xmlDocGetRootElement (doc);

	if (root == NULL)
	{
		std::cerr << "Empty config file\n";
		xmlFreeDoc (doc);
		return;
	}
	
	child = root->xmlChildrenNode;
	while (child != NULL)
	{
		if (!xmlStrcmp (child->name, (const xmlChar*)"display"))
			ParseDisplay (doc, child);
		else if (!xmlStrcmp (child->name, (const xmlChar*)"keyBindings"))
			ParseKeyBindings (doc, child);
		else if (!strncmp ((char*)child->name, "player",6))
		{
			char str[2];
			for (int i=0; i<4; i++)
			{
				str[0] = '1'+i;
				str[1] = '\0';
				if (!strcmp ((char*)child->name+6, str))
					ParsePlayer (players+i, doc, child);
			}
		}
		child = child->next;
	}

	xmlFreeDoc (doc);
	xmlCleanupParser ();
	xmlMemoryDump ();

}
Пример #4
0
BOOL CALLBACK SessionDialog::SessDlgProc(  HWND hwnd,  UINT uMsg,  WPARAM wParam, LPARAM lParam ) {
    // This is a static method, so we don't know which instantiation we're
    // dealing with. But we can get a pseudo-this from the parameter to
    // WM_INITDIALOG, which we therafter store with the window and retrieve
    // as follows:
    SessionDialog*_this = helper::SafeGetWindowUserData<SessionDialog>(hwnd);
    if (_this!=NULL && notset)
    {
        selected=_this->m_pOpt->m_selected_screen;
        notset=false;
    }

    switch (uMsg) {

    case WM_INITDIALOG:
    {
        helper::SafeSetWindowUserData(hwnd, lParam);
        SessionDialog *l_this = (SessionDialog *) lParam;
        //CentreWindow(hwnd);
        SetForegroundWindow(hwnd);
        l_this->m_pCC->m_hSessionDialog = hwnd;

        //List monitors
        tempdisplayclass tdc;
        tdc.Init();
        HWND hcomboscreen = GetDlgItem(  hwnd, IDC_SCREEN);
        for (int i = 0; i < tdc.nr_monitors+1; i++) {
            int pos = SendMessage(hcomboscreen, CB_ADDSTRING, 0, (LPARAM) tdc.monarray[i].buttontext);

        }
        SendMessage(hcomboscreen, CB_SETCURSEL, selected, 0);

        // Set up recently-used list
        HWND hcombo = GetDlgItem(  hwnd, IDC_HOSTNAME_EDIT);
        TCHAR valname[256];

        for (int i = 0; i < l_this->m_pMRU->NumItems(); i++) {
            l_this->m_pMRU->GetItem(i, valname, 255);
            int pos = SendMessage(hcombo, CB_ADDSTRING, 0, (LPARAM) valname);

        }
        SendMessage(hcombo, CB_SETCURSEL, 0, 0);

        // sf@2002 - List available DSM Plugins
        HWND hPlugins = GetDlgItem(hwnd, IDC_PLUGINS_COMBO);
        int nPlugins = l_this->m_pDSMPlugin->ListPlugins(hPlugins);
        if (!nPlugins)
        {
            SendMessage(hPlugins, CB_ADDSTRING, 0, (LPARAM) sz_F11);
        }
        else
        {
            // Use the first detected plugin, so the user doesn't have to check the option
            // HWND hUsePlugin = GetDlgItem(hwnd, IDC_PLUGIN_CHECK);
            // SendMessage(hUsePlugin, BM_SETCHECK, TRUE, 0);
        }
        SendMessage(hPlugins, CB_SETCURSEL, 0, 0);

        HWND hButton = GetDlgItem(hwnd, IDC_PLUGIN_BUTTON);
        EnableWindow(hButton, FALSE); // sf@2009 - Disable plugin config button by default

        //AaronP
        if( strcmp( l_this->m_pOpt->m_szDSMPluginFilename, "" ) != 0 && l_this->m_pOpt->m_fUseDSMPlugin )
        {
            int pos = SendMessage(hPlugins, CB_FINDSTRINGEXACT, -1,
                                  (LPARAM)&(l_this->m_pOpt->m_szDSMPluginFilename[0]));

            if( pos != CB_ERR )
            {
                SendMessage(hPlugins, CB_SETCURSEL, pos, 0);
                HWND hUsePlugin = GetDlgItem(hwnd, IDC_PLUGIN_CHECK);
                SendMessage(hUsePlugin, BM_SETCHECK, TRUE, 0);
                EnableWindow(hButton, TRUE); // sf@2009 - Enable plugin config button
            }
        }
        //EndAaronP

        TCHAR tmphost[256];
        TCHAR tmphost2[256];
        _tcscpy(tmphost, l_this->m_pOpt->m_proxyhost);
        if (strcmp(tmphost,"")!=NULL)
        {
            _tcscat(tmphost,":");
            _tcscat(tmphost,_itoa(l_this->m_pOpt->m_proxyport,tmphost2,10));
            SetDlgItemText(hwnd, IDC_PROXY_EDIT, tmphost);
        }

        HWND hViewOnly = GetDlgItem(hwnd, IDC_VIEWONLY_CHECK);
        SendMessage(hViewOnly, BM_SETCHECK, l_this->m_pOpt->m_ViewOnly, 0);

        HWND hAutoScaling = GetDlgItem(hwnd, IDC_AUTOSCALING_CHECK);
        SendMessage(hAutoScaling, BM_SETCHECK, l_this->m_pOpt->m_fAutoScaling, 0);

        HWND hExitCheck = GetDlgItem(hwnd, IDC_EXIT_CHECK); //PGM @ Advantig
        SendMessage(hExitCheck, BM_SETCHECK, l_this->m_pOpt->m_fExitCheck, 0); //PGM @ Advantig

        HWND hProxy = GetDlgItem(hwnd, IDC_PROXY_CHECK);
        SendMessage(hProxy, BM_SETCHECK, l_this->m_pOpt->m_fUseProxy, 0);


        // sf@2005 - Make the save settings optional but always enabled by default (for now)
        // (maybe disabled as default is better ?)
        HWND hSave = GetDlgItem(hwnd, IDC_SETDEFAULT_CHECK);
//ACT			SendMessage(hSave, BM_SETCHECK, true, 0);


        // sf@2002 - Select Modem Option as default
        l_this->SetQuickOption(l_this, hwnd);

        l_this->m_fFromOptions = false;
        l_this->m_fFromFile = false;

        return TRUE;
    }

    case WM_COMMAND:
        switch (LOWORD(wParam))
        {
        case IDC_DELETE:
        {
            char optionfile[MAX_PATH];
            VNCOptions::GetDefaultOptionsFileName(optionfile);
            DeleteFile(optionfile);
        }
        return TRUE;

        case IDOK:
        {
            TCHAR tmphost[256];
            TCHAR display[256];
            TCHAR fulldisplay[256];

            // sf@2005
            HWND hSave = GetDlgItem(hwnd, IDC_SETDEFAULT_CHECK);
            _this->m_pCC->saved_set = SendMessage(hSave, BM_GETCHECK, 0, 0) == BST_CHECKED;

            _this->m_pOpt->m_selected_screen=SendMessage(GetDlgItem(  hwnd, IDC_SCREEN),CB_GETCURSEL,0,0);

            GetDlgItemText(hwnd, IDC_HOSTNAME_EDIT, display, 256);
            _tcscpy(fulldisplay, display);
            if (!ParseDisplay(display, tmphost, 255, &_this->m_port)) {
                MessageBox(hwnd,
                           sz_F8,
                           sz_F10, MB_OK | MB_ICONEXCLAMATION | MB_SETFOREGROUND | MB_TOPMOST);
            } else {
                for (size_t i = 0, len = strlen(tmphost); i < len; i++)
                {
                    tmphost[i] = toupper(tmphost[i]);
                }
                _tcscpy(_this->m_host_dialog, tmphost);
                _this->m_pMRU->AddItem(fulldisplay);
//				_tcscpy(_this->m_remotehost, fulldisplay);
                EndDialog(hwnd, TRUE);
            }

            GetDlgItemText(hwnd, IDC_PROXY_EDIT, display, 256);
            _tcscpy(fulldisplay, display);

            //adzm 2010-02-15
            if (strlen(display) > 0) {
                TCHAR actualProxy[256];
                strcpy(actualProxy, display);

                if (strncmp(tmphost, "ID", 2) == 0) {

                    int numericId = _this->m_port;

                    int numberOfHosts = 1;
                    for (int i = 0; i < (int)strlen(display); i++) {
                        if (display[i] == ';') {
                            numberOfHosts++;
                        }
                    }

                    if (numberOfHosts <= 1) {
                        // then hostname == actualhostname
                    } else {
                        int modulo = numericId % numberOfHosts;

                        char* szToken = strtok(display, ";");
                        while (szToken) {
                            if (modulo == 0) {
                                strcpy(actualProxy, szToken);
                                break;
                            }

                            modulo--;
                            szToken = strtok(NULL, ";");
                        }
                    }
                }

                if (!ParseDisplay(actualProxy, tmphost, 255, &_this->m_proxyport)) {
                    MessageBox(hwnd,
                               sz_F8,
                               sz_F10, MB_OK | MB_ICONEXCLAMATION | MB_SETFOREGROUND | MB_TOPMOST);
                } else {
                    _tcscpy(_this->m_proxyhost, tmphost);
                    EndDialog(hwnd, TRUE);
                }
            }

            HWND hProxy = GetDlgItem(hwnd, IDC_PROXY_CHECK);
            if (SendMessage(hProxy, BM_GETCHECK, 0, 0) == BST_CHECKED)
            {
                _this->m_pOpt->m_fUseProxy = true;
                _this->m_fUseProxy = true;
            }
            else
            {
                _this->m_pOpt->m_fUseProxy = false;
                _this->m_fUseProxy = false;
            }

            // sf@2002 - DSMPlugin loading
            // If Use plugin is checked, load the plugin if necessary
            HWND hPlugin = GetDlgItem(hwnd, IDC_PLUGIN_CHECK);
            if (SendMessage(hPlugin, BM_GETCHECK, 0, 0) == BST_CHECKED)
            {
                TCHAR szPlugin[MAX_PATH];
                GetDlgItemText(hwnd, IDC_PLUGINS_COMBO, szPlugin, MAX_PATH);
                _this->m_pOpt->m_fUseDSMPlugin = true;
                strcpy(_this->m_pOpt->m_szDSMPluginFilename, szPlugin);

                if (!_this->m_pDSMPlugin->IsLoaded())
                {
                    _this->m_pDSMPlugin->LoadPlugin(szPlugin, _this->m_pOpt->m_listening);
                    if (_this->m_pDSMPlugin->IsLoaded())
                    {
                        if (_this->m_pDSMPlugin->InitPlugin())
                        {
                            if (!_this->m_pDSMPlugin->SupportsMultithreaded())
                                _this->m_pOpt->m_oldplugin=true; //PGM
                            else //PGM
                                _this->m_pOpt->m_oldplugin=false;

                            _this->m_pDSMPlugin->SetEnabled(true);
                            _this->m_pDSMPlugin->DescribePlugin();
                        }
                        else
                        {
                            _this->m_pDSMPlugin->SetEnabled(false);
                            MessageBox(hwnd,
                                       sz_F7,
                                       sz_F6, MB_OK | MB_ICONEXCLAMATION | MB_SETFOREGROUND | MB_TOPMOST);
                            return TRUE;
                        }
                    }
                    else
                    {
                        _this->m_pDSMPlugin->SetEnabled(false);
                        MessageBox(hwnd,
                                   sz_F5,
                                   sz_F6, MB_OK | MB_ICONEXCLAMATION | MB_SETFOREGROUND | MB_TOPMOST);
                        return TRUE;
                    }
                }
                else
                {
                    // sf@2003 - If the plugin is already loaded here it has been loaded
                    // by clicking on the config button: we need to init it !
                    // But we must first check that the loaded plugin is the same that
                    // the one currently selected...
                    _this->m_pDSMPlugin->DescribePlugin();
                    if (_stricmp(_this->m_pDSMPlugin->GetPluginFileName(), szPlugin))
                    {
                        // Unload the previous plugin
                        _this->m_pDSMPlugin->UnloadPlugin();
                        // Load the new selected one
                        _this->m_pDSMPlugin->LoadPlugin(szPlugin, _this->m_pOpt->m_listening);
                    }

                    if (_this->m_pDSMPlugin->IsLoaded())
                    {
                        if (_this->m_pDSMPlugin->InitPlugin())
                        {
                            if (!_this->m_pDSMPlugin->SupportsMultithreaded())
                                _this->m_pOpt->m_oldplugin=true; //PGM
                            else //PGM
                                _this->m_pOpt->m_oldplugin=false;
                            _this->m_pDSMPlugin->SetEnabled(true);
                            _this->m_pDSMPlugin->DescribePlugin();
                        }
                        else
                        {
                            _this->m_pDSMPlugin->SetEnabled(false);
                            MessageBox(hwnd,
                                       sz_F7,
                                       sz_F6, MB_OK | MB_ICONEXCLAMATION | MB_SETFOREGROUND | MB_TOPMOST);
                            return TRUE;
                        }
                    }
                    else
                    {
                        _this->m_pDSMPlugin->SetEnabled(false);
                        MessageBox(hwnd,
                                   sz_F5,
                                   sz_F6, MB_OK | MB_ICONEXCLAMATION | MB_SETFOREGROUND | MB_TOPMOST);
                        return TRUE;
                    }
                }
            }
            else // If Use plugin unchecked but the plugin is loaded, unload it
            {
                _this->m_pOpt->m_fUseDSMPlugin = false;
                if (_this->m_pDSMPlugin->IsEnabled())
                {
                    _this->m_pDSMPlugin->UnloadPlugin();
                    _this->m_pDSMPlugin->SetEnabled(false);
                }
            }

            if (_this->m_fFromOptions || _this->m_fFromFile)
            {
                EndDialog(hwnd, TRUE);
                return TRUE;
            }

            // sf@2002 - Quick options handling
            _this->ManageQuickOptions(_this, hwnd);

            HWND hViewOnly = GetDlgItem(hwnd, IDC_VIEWONLY_CHECK);
            _this->m_pOpt->m_ViewOnly = (SendMessage(hViewOnly, BM_GETCHECK, 0, 0) == BST_CHECKED);

            HWND hAutoScaling = GetDlgItem(hwnd, IDC_AUTOSCALING_CHECK);
            _this->m_pOpt->m_fAutoScaling = (SendMessage(hAutoScaling, BM_GETCHECK, 0, 0) == BST_CHECKED);

            HWND hExitCheck = GetDlgItem(hwnd, IDC_EXIT_CHECK); //PGM @ Advantig
            _this->m_pOpt->m_fExitCheck = (SendMessage(hExitCheck, BM_GETCHECK, 0, 0) == BST_CHECKED); //PGM @ Advantig

            EndDialog(hwnd, TRUE);
            return TRUE;
        }

        case IDCANCEL:
            EndDialog(hwnd, FALSE);
            return TRUE;

        case IDC_OPTIONBUTTON:
        {
            if (!_this->m_fFromFile)
            {
                _this->ManageQuickOptions(_this, hwnd);

                HWND hViewOnly = GetDlgItem(hwnd, IDC_VIEWONLY_CHECK);
                _this->m_pOpt->m_ViewOnly = (SendMessage(hViewOnly, BM_GETCHECK, 0, 0) == BST_CHECKED);

                HWND hAutoScaling = GetDlgItem(hwnd, IDC_AUTOSCALING_CHECK);
                _this->m_pOpt->m_fAutoScaling = (SendMessage(hAutoScaling, BM_GETCHECK, 0, 0) == BST_CHECKED);

                HWND hExitCheck = GetDlgItem(hwnd, IDC_EXIT_CHECK); //PGM @ Advantig
                _this->m_pOpt->m_fExitCheck = (SendMessage(hExitCheck, BM_GETCHECK, 0, 0) == BST_CHECKED); //PGM @ Advantig

            }

            if (_this->m_pOpt->DoDialog())
            {
                _this->m_fFromOptions = true;
                HWND hDyn = GetDlgItem(hwnd, IDC_DYNAMIC);
                SendMessage(hDyn, BM_SETCHECK, false, 0);
                HWND hLan = GetDlgItem(hwnd, IDC_LAN_RB);
                SendMessage(hLan, BM_SETCHECK, false, 0);
                HWND hUltraLan = GetDlgItem(hwnd, IDC_ULTRA_LAN_RB);
                SendMessage(hUltraLan, BM_SETCHECK, false, 0);
                HWND hMedium = GetDlgItem(hwnd, IDC_MEDIUM_RB);
                SendMessage(hMedium, BM_SETCHECK, false, 0);
                HWND hModem = GetDlgItem(hwnd, IDC_MODEM_RB);
                SendMessage(hModem, BM_SETCHECK, false, 0);
                HWND hSlow = GetDlgItem(hwnd, IDC_SLOW_RB);
                SendMessage(hSlow, BM_SETCHECK, false, 0);
                HWND hManual = GetDlgItem(hwnd, IDC_MANUAL);
                SendMessage(hManual, BM_SETCHECK, true, 0);
                _this->m_pOpt->m_quickoption = 8;
            }
            return TRUE;
        }

        // sf@2002
        case IDC_PLUGIN_CHECK:
        {
            HWND hUse = GetDlgItem(hwnd, IDC_PLUGIN_CHECK);
            BOOL enable = SendMessage(hUse, BM_GETCHECK, 0, 0) == BST_CHECKED;
            HWND hButton = GetDlgItem(hwnd, IDC_PLUGIN_BUTTON);
            EnableWindow(hButton, enable);
        }
        return TRUE;


        case IDC_PLUGIN_BUTTON:
        {
            HWND hPlugin = GetDlgItem(hwnd, IDC_PLUGIN_CHECK);
            if (SendMessage(hPlugin, BM_GETCHECK, 0, 0) == BST_CHECKED)
            {
                TCHAR szPlugin[MAX_PATH];
                GetDlgItemText(hwnd, IDC_PLUGINS_COMBO, szPlugin, MAX_PATH);
                // sf@2003 - The config button can be clicked several times with
                // different selected plugins...
                bool fLoadIt = true;
                char szParams[64];
                strcpy(szParams, sz_F4);
                // If a plugin is already loaded, check if it is the same that the one
                // we want to load.
                if (_this->m_pDSMPlugin->IsLoaded())
                {
                    _this->m_pDSMPlugin->DescribePlugin();
                    if (!_stricmp(_this->m_pDSMPlugin->GetPluginFileName(), szPlugin))
                    {
                        fLoadIt = false;
                        _this->m_pDSMPlugin->SetPluginParams(hwnd, szParams);
                    }
                    else
                    {
                        // Unload the previous plugin
                        _this->m_pDSMPlugin->UnloadPlugin();
                        fLoadIt = true;
                    }
                }

                if (!fLoadIt) return TRUE;

                if (_this->m_pDSMPlugin->LoadPlugin(szPlugin, _this->m_pOpt->m_listening))
                {
                    // We don't know the password yet... no matter the plugin requires
                    // it or not, we will provide it later (at plugin "real" startup)
                    // Knowing the environnement ("viewer") right now can be usefull or
                    // even mandatory for the plugin (specific params saving and so on...)
                    // The plugin receives environnement info but isn't inited at this point
                    _this->m_pDSMPlugin->SetPluginParams(hwnd, szParams);
                }
                else
                {
                    MessageBox(hwnd,
                               sz_F1,
                               sz_F3, MB_OK | MB_ICONEXCLAMATION | MB_SETFOREGROUND | MB_TOPMOST);
                }
            }
            return TRUE;
        }

        case IDC_LOADPROFILE_B:
        {
            TCHAR szFileName[MAX_PATH];
            memset(szFileName, '\0', MAX_PATH);
            if (_this->m_pCC->LoadConnection(szFileName, true) != -1)
            {
                TCHAR szHost[250];
                if (_this->m_pCC->m_port == 5900)
                    _tcscpy(szHost, _this->m_pCC->m_host);
                else if (_this->m_pCC->m_port > 5900 && _this->m_pCC->m_port <= 5999)
                    _stprintf(szHost, TEXT("%s:%d"), _this->m_pCC->m_host, _this->m_pCC->m_port - 5900);
                else
                    _stprintf(szHost, TEXT("%s::%d"), _this->m_pCC->m_host, _this->m_pCC->m_port);

                SetDlgItemText(hwnd, IDC_HOSTNAME_EDIT, szHost);
                //AaronP
                HWND hPlugins = GetDlgItem(hwnd, IDC_PLUGINS_COMBO);
                if( strcmp( _this->m_pOpt->m_szDSMPluginFilename, "" ) != 0 && _this->m_pOpt->m_fUseDSMPlugin ) {
                    int pos = SendMessage(hPlugins, CB_FINDSTRINGEXACT, -1,
                                          (LPARAM)&(_this->m_pOpt->m_szDSMPluginFilename[0]));

                    if( pos != CB_ERR ) {
                        SendMessage(hPlugins, CB_SETCURSEL, pos, 0);
                        HWND hUsePlugin = GetDlgItem(hwnd, IDC_PLUGIN_CHECK);
                        SendMessage(hUsePlugin, BM_SETCHECK, TRUE, 0);
                    }
                }
                //EndAaronP
            }
            SetFocus(GetDlgItem(hwnd, IDC_HOSTNAME_EDIT));
            _this->SetQuickOption(_this, hwnd);

            HWND hViewOnly = GetDlgItem(hwnd, IDC_VIEWONLY_CHECK);
            SendMessage(hViewOnly, BM_SETCHECK, _this->m_pOpt->m_ViewOnly, 0);

            HWND hAutoScaling = GetDlgItem(hwnd, IDC_AUTOSCALING_CHECK);
            SendMessage(hAutoScaling, BM_SETCHECK, _this->m_pOpt->m_fAutoScaling, 0);

            HWND hExitCheck = GetDlgItem(hwnd, IDC_EXIT_CHECK); //PGM @ Advantig
            SendMessage(hExitCheck, BM_SETCHECK, _this->m_pOpt->m_fExitCheck, 0); //PGM @ Advantig

            _this->m_fFromOptions = true;
            _this->m_fFromFile = true;
            return TRUE;
        }

        // [v1.0.2-jp1 fix]
        case IDC_HOSTNAME_DEL:
            HWND hcombo = GetDlgItem(  hwnd, IDC_HOSTNAME_EDIT);
            int sel = SendMessage(hcombo, CB_GETCURSEL, 0, 0);
            if(sel != CB_ERR) {
                SendMessage(hcombo, CB_DELETESTRING, sel, 0);
                _this->m_pMRU->RemoveItem(sel);
            }
            return TRUE;
        }

        break;

    case WM_DESTROY:
        EndDialog(hwnd, FALSE);
        return TRUE;
    }
    return 0;
}
Пример #5
0
THREAD_CALL server_listen(LPVOID lpParam)
{
	listener_thread_params *thread_params = (listener_thread_params *)lpParam;
	SOCKET conn;
	struct sockaddr_in client;
	socklen_t socklen = sizeof(client);
	rfbProtocolVersionMsg protocol_version; 
	char host_id[MAX_HOST_NAME_LEN + 1];
	char phost[MAX_HOST_NAME_LEN + 1];
	CARD32 auth_type;
	unsigned char challenge[CHALLENGESIZE];
	uint32_t code;
	char *ip_addr;

	thread_params->sock = create_listener_socket( thread_params->port );
	if (thread_params->sock == INVALID_SOCKET)
    notstopped = false;
	else
		logp(DEBUG, "Listening for incoming server connections on port %d.", thread_params->port);

	while(notstopped)
	{
		conn = socket_accept(thread_params->sock, (struct sockaddr *)&client, &socklen);
		if (conn == INVALID_SOCKET) {
			if (notstopped) logp(ERROR, "server_listen(): accept() failed, errno=%d", getLastErrNo());
		} else {
			ip_addr = inet_ntoa(client.sin_addr); /* IP Address for monitoring purposes */
			logp(INFO, "Server (socket=%d) connection accepted from %s.", conn, ip_addr);

			// First thing is first: Get the repeater ID...
			if( socket_recv(conn, host_id, MAX_HOST_NAME_LEN, "hostid from server") ) {
		    // Check and cypher the ID
		    if( ParseDisplay(host_id, phost, MAX_HOST_NAME_LEN, (int *)&code, challenge) ) {
  		    logp(DEBUG, "Server (socket=%d) sent the host ID:%d.", conn, code);

			    // Continue with the handshake until ClientInit. Read the Protocol Version.
			    if( socket_recv(conn, protocol_version, sz_rfbProtocolVersionMsg, "protocol version from server") ) {
      			// ToDo: Make sure the version is OK!
  			    logp(DEBUG, "Server (socket=%d) sent protocol version.", conn);

			      // Tell the server we are using Protocol Version 3.3
			      sprintf(protocol_version, rfbProtocolVersionFormat, rfbProtocolMajorVersion, rfbProtocolMinorVersion);
			      if( socket_send(conn, protocol_version, sz_rfbProtocolVersionMsg, "protocol version to server") ) {
  			      logp(DEBUG, "Protocol version sent to server (socket=%d).", conn);

			        // The server should send the authentication type it whises to use.
			        // ToDo: We could add a password this would restrict other servers from connecting to our repeater, 
              // in the meanwhile, assume no auth is the only scheme allowed.
			        if( socket_recv(conn, (char *)&auth_type, sizeof(auth_type), "auth type from server") ) {
  			        logp(DEBUG, "Server (socket=%d) sent authentication scheme.", conn);

			          if( Swap32IfLE(auth_type) != rfbNoAuth ) {
				          logp(ERROR, "Invalid authentication scheme sent by server (socket=%d).", conn);
				          socket_close(conn);
			          }
                else
                  add_new_slot(conn, INVALID_SOCKET, challenge, code);
			        }
			      } 
			    }
		    }
        else
			    logp(ERROR, "server_listen(): Reading Proxy settings error %s", host_id);
			}
		}
	}
	notstopped = false;
	socket_close(thread_params->sock);
	log(INFO, "Server listening thread has exited.\n");
	return 0;
}
Пример #6
0
void VNCOptions::SetFromCommandLine(LPTSTR szCmdLine) {
  // We assume no quoting here.
  // Copy the command line - we don't know what might happen to the original
  config_specified=false;
  int cmdlinelen = _tcslen(szCmdLine);
  if (cmdlinelen == 0) return;
	
  TCHAR *cmd = new TCHAR[cmdlinelen + 1];
  _tcscpy(cmd, szCmdLine);
	
	// Count the number of spaces
	// This may be more than the number of arguments, but that doesn't matter.
  int nspaces = 0;
  TCHAR *p = cmd;
  TCHAR *pos = cmd;
  while ( ( pos = _tcschr(p, ' ') ) != NULL ) {
    nspaces ++;
    p = pos + 1;
  }
	
  // Create the array to hold pointers to each bit of string
  TCHAR **args = new LPTSTR[nspaces + 1];
	
  // replace spaces with nulls and
  // create an array of TCHAR*'s which points to start of each bit.
  pos = cmd;
  int i = 0;
  args[i] = cmd;
  bool inquote=false;
  for (pos = cmd; *pos != 0; pos++) {
    // Arguments are normally separated by spaces, unless there's quoting
    if ((*pos == ' ') && !inquote) {
      *pos = '\0';
      p = pos + 1;
      args[++i] = p;
    }
    if (*pos == '"') {  
      if (!inquote) {      // Are we starting a quoted argument?
        args[i] = ++pos; // It starts just after the quote
      } else {
        *pos = '\0';     // Finish a quoted argument?
      }
      inquote = !inquote;
    }
  }
  i++;

  bool hostGiven = false, portGiven = false;
  // take in order.
  for (int j = 0; j < i; j++) {
    if ( SwitchMatch(args[j], _T("help")) ||
         SwitchMatch(args[j], _T("?")) ||
         SwitchMatch(args[j], _T("h")))
	{
	  m_NoStatus = true;
      ShowUsage();
      exit(1);
    }
	else if ( SwitchMatch(args[j], _T("listen")))
	{
      m_listening = true;
      if (j+1 < i && args[j+1][0] >= '0' && args[j+1][0] <= '9') {
        if (_stscanf(args[j+1], _T("%d"), &m_listenPort) != 1) {
          ArgError(sz_D3);
          continue;
        }
        j++;
      }
    } else if (SwitchMatch(args[j], _T("fttimeout"))) { //PGM @ Advantig
      if (j+1 < i && args[j+1][0] >= '0' && args[j+1][0] <= '9') {
        if (_stscanf(args[j+1], _T("%d"), &m_FTTimeout) != 1) {
          ArgError(sz_D3);
          continue;
        }
        if (m_FTTimeout > 60)
            m_FTTimeout = 60;
        j++;
      }
    }  else if (SwitchMatch(args[j], _T("keepalive"))) { //PGM @ Advantig
      if (j+1 < i && args[j+1][0] >= '0' && args[j+1][0] <= '9') {
        if (_stscanf(args[j+1], _T("%d"), &m_keepAliveInterval) != 1) {
          ArgError(sz_D3);
          continue;
        }
        if (m_keepAliveInterval >= (m_FTTimeout - KEEPALIVE_HEADROOM))
          m_keepAliveInterval = (m_FTTimeout - KEEPALIVE_HEADROOM); 
        j++;
      }
    } else if ( SwitchMatch(args[j], _T("askexit"))) { //PGM @ Advantig
      m_fExitCheck = true; //PGM @ Advantig
    } else if ( SwitchMatch(args[j], _T("restricted"))) {
      m_restricted = true;
    } else if ( SwitchMatch(args[j], _T("viewonly"))) {
      m_ViewOnly = true;
	} else if ( SwitchMatch(args[j], _T("nostatus"))) {
      m_NoStatus = true;
	} else if ( SwitchMatch(args[j], _T("nohotkeys"))) {
      m_NoHotKeys = true;
    } else if ( SwitchMatch(args[j], _T("notoolbar"))) {
      m_ShowToolbar = false;
    } else if ( SwitchMatch(args[j], _T("autoscaling"))) {
      m_fAutoScaling = true;
    } else if ( SwitchMatch(args[j], _T("fullscreen"))) {
      m_FullScreen = true;
    } else if ( SwitchMatch(args[j], _T("noauto"))) {
      autoDetect = false;
	  m_quickoption = 0;
    } else if ( SwitchMatch(args[j], _T("8bit"))) {
      m_Use8Bit = rfbPF256Colors; //true;
	} else if ( SwitchMatch(args[j], _T("256colors"))) {
      m_Use8Bit = rfbPF256Colors; //true;
    } else if ( SwitchMatch(args[j], _T("fullcolors"))) {
      m_Use8Bit = rfbPFFullColors;
    } else if ( SwitchMatch(args[j], _T("64colors"))) {
      m_Use8Bit = rfbPF64Colors;
    } else if ( SwitchMatch(args[j], _T("8colors"))) {
      m_Use8Bit = rfbPF8Colors;
    } else if ( SwitchMatch(args[j], _T("8greycolors"))) {
      m_Use8Bit = rfbPF8GreyColors;
    } else if ( SwitchMatch(args[j], _T("4greycolors"))) {
      m_Use8Bit = rfbPF4GreyColors;
    } else if ( SwitchMatch(args[j], _T("2greycolors"))) {
      m_Use8Bit = rfbPF2GreyColors;
    } else if ( SwitchMatch(args[j], _T("shared"))) {
      m_Shared = true;
    } else if ( SwitchMatch(args[j], _T("swapmouse"))) {
      m_SwapMouse = true;
    } else if ( SwitchMatch(args[j], _T("nocursor"))) {
      m_localCursor = NOCURSOR;
    } else if ( SwitchMatch(args[j], _T("dotcursor"))) {
      m_localCursor = DOTCURSOR;
    } else if ( SwitchMatch(args[j], _T("normalcursor"))) {
      m_localCursor = NORMALCURSOR;
    } else if ( SwitchMatch(args[j], _T("belldeiconify") )) {
      m_DeiconifyOnBell = true;
    } else if ( SwitchMatch(args[j], _T("emulate3") )) {
      m_Emul3Buttons = true;
	} else if ( SwitchMatch(args[j], _T("JapKeyboard") )) {
      m_JapKeyboard = true;
    } else if ( SwitchMatch(args[j], _T("noemulate3") )) {
      m_Emul3Buttons = false;
	} else if ( SwitchMatch(args[j], _T("nocursorshape") )) {
			m_requestShapeUpdates = false;
	} else if ( SwitchMatch(args[j], _T("noremotecursor") )) {
			m_requestShapeUpdates = true;
			m_ignoreShapeUpdates = true;
    } else if ( SwitchMatch(args[j], _T("scale") )) {
      if (++j == i) {
        ArgError(sz_D4);
        continue;
      }
      int numscales = _stscanf(args[j], _T("%d/%d"), &m_scale_num, &m_scale_den);
      if (numscales < 1) {
        ArgError(sz_D5);
        continue;
      }
      if (numscales == 1) 
        m_scale_den = 1; // needed if you're overriding a previous setting

    } else if ( SwitchMatch(args[j], _T("emulate3timeout") )) {
      if (++j == i) {
        ArgError(sz_D6);
        continue;
      }
      if (_stscanf(args[j], _T("%d"), &m_Emul3Timeout) != 1) {
        ArgError(sz_D7);
        continue;
      }
			
    } else if ( SwitchMatch(args[j], _T("emulate3fuzz") )) {
      if (++j == i) {
        ArgError(sz_D8);
        continue;
      }
      if (_stscanf(args[j], _T("%d"), &m_Emul3Fuzz) != 1) {
        ArgError(sz_D9);
        continue;
      }
			
    } else if ( SwitchMatch(args[j], _T("disableclipboard") )) {
      m_DisableClipboard = true;
    }
#ifdef UNDER_CE
    // Manual setting of palm vs hpc aspect ratio for dialog boxes.
    else if ( SwitchMatch(args[j], _T("hpc") )) {
      m_palmpc = false;
    } else if ( SwitchMatch(args[j], _T("palm") )) {
      m_palmpc = true;
    } else if ( SwitchMatch(args[j], _T("slow") )) {
      m_slowgdi = true;
    } 
#endif
    else if ( SwitchMatch(args[j], _T("delay") )) {
      if (++j == i) {
        ArgError(sz_D10);
        continue;
      }
      if (_stscanf(args[j], _T("%d"), &m_delay) != 1) {
        ArgError(sz_D11);
        continue;
      }
			
    } else if ( SwitchMatch(args[j], _T("loglevel") )) {
      if (++j == i) {
        ArgError(sz_D12);
        continue;
      }
      if (_stscanf(args[j], _T("%d"), &m_logLevel) != 1) {
        ArgError(sz_D13);
        continue;
      }
			
    } else if ( SwitchMatch(args[j], _T("console") )) {
      m_logToConsole = true;
    } else if ( SwitchMatch(args[j], _T("logfile") )) {
      if (++j == i) {
        ArgError(sz_D14);
        continue;
      }
      if (_stscanf(args[j], _T("%s"), m_logFilename) != 1) {
        ArgError(sz_D15);
        continue;
      } else {
        m_logToFile = true;
      }
    } else if ( SwitchMatch(args[j], _T("config") )) {
      if (++j == i) {
        ArgError(sz_D16);
        continue;
      }
	  else
	  {
		  config_specified=true;
	  }
      // The GetPrivateProfile* stuff seems not to like some relative paths
      _fullpath(m_configFilename, args[j], _MAX_PATH);
      if (_access(m_configFilename, 04)) {
        ArgError(sz_D17);
        PostQuitMessage(1);
        continue;
      } else {
        Load(m_configFilename);
        m_configSpecified = true;
      }
    } else if ( SwitchMatch(args[j], _T("register") )) {
      Register();
      PostQuitMessage(0);
	
	}
	else if ( SwitchMatch(args[j], _T("encoding") )) {
			if (++j == i) {
				ArgError(sz_D18);
				continue;
			}
			int enc = -1;
			if (_tcsicmp(args[j], _T("raw")) == 0) {
				enc = rfbEncodingRaw;
			} else if (_tcsicmp(args[j], _T("rre")) == 0) {
				enc = rfbEncodingRRE;
			} else if (_tcsicmp(args[j], _T("corre")) == 0) {
				enc = rfbEncodingCoRRE;
			} else if (_tcsicmp(args[j], _T("hextile")) == 0) {
				enc = rfbEncodingHextile;
			} else if (_tcsicmp(args[j], _T("zlib")) == 0) {
				enc = rfbEncodingZlib;
			} else if (_tcsicmp(args[j], _T("zlibhex")) == 0) {
				enc = rfbEncodingZlibHex;
			} else if (_tcsicmp(args[j], _T("tight")) == 0) {
				enc = rfbEncodingTight;
			} else if (_tcsicmp(args[j], _T("ultra")) == 0) {
				enc = rfbEncodingUltra;
			} else if (_tcsicmp(args[j], _T("zrle")) == 0) { 
				enc = rfbEncodingZRLE; 
			} else if (_tcsicmp(args[j], _T("zywrle")) == 0) { 
				enc = rfbEncodingZYWRLE; 
			} else {
				ArgError(sz_D19);
				continue;
			}
			if (enc != -1) {
				m_UseEnc[enc] = true;
				m_PreferredEncoding = enc;
			}
	}
	// Tight options
	else if ( SwitchMatch(args[j], _T("compresslevel") )) {
			if (++j == i) {
				ArgError(sz_D20);
				continue;
			}
			m_useCompressLevel = true;
			if (_stscanf(args[j], _T("%d"), &m_compressLevel) != 1) {
				ArgError(sz_D21);
				continue;
			}
		} else if ( SwitchMatch(args[j], _T("quality") )) {
			if (++j == i) {
				ArgError(sz_D22);
				continue;
			}
			m_enableJpegCompression = true;
			if (_stscanf(args[j], _T("%d"), &m_jpegQualityLevel) != 1) {
				ArgError(sz_D23);
				continue;
			}
	}
	// act : add user option on command line
	else if ( SwitchMatch(args[j], _T("user") ))
	{
			if (++j == i)
			{
				ArgError(sz_D24);
				continue;
			}
			strcpy(m_cmdlnUser, args[j]);
	} // act : add user option on command line
	// Modif sf@2002 : password in the command line
	else if ( SwitchMatch(args[j], _T("password") ))
	{
			if (++j == i)
			{
				ArgError(sz_D24);
				continue;
			}
			strcpy(m_clearPassword, args[j]);
	} // Modif sf@2002
	else if ( SwitchMatch(args[j], _T("serverscale") ))
	{
		if (++j == i)
		{
			ArgError(sz_D25);
			continue;
		}
		_stscanf(args[j], _T("%d"), &m_nServerScale);
		if (m_nServerScale < 1 || m_nServerScale > 9) m_nServerScale = 1;
	}
	// Modif sf@2002
	else if ( SwitchMatch(args[j], _T("quickoption") )) 
	{
		if (++j == i)
		{
			ArgError(sz_D26);
			continue;
		}
		_stscanf(args[j], _T("%d"), &m_quickoption);
	}
	// Modif sf@2002 - DSM Plugin 
	else if ( SwitchMatch(args[j], _T("dsmplugin") ))
	{
		if (++j == i)
		{
			ArgError(sz_D27);
			continue;
		}
		m_fUseDSMPlugin = true;
		strcpy(m_szDSMPluginFilename, args[j]);
	}
	else if ( SwitchMatch(args[j], _T("proxy") ))
	{
		if (++j == i)
		{
			ArgError(sz_D27); // sf@ - Todo: put correct message here
			continue;
		}
		TCHAR proxyhost[256];
		if (!ParseDisplay(args[j], proxyhost, 255, &m_proxyport)) {
			ShowUsage(sz_D28);
			PostQuitMessage(1);
		} else {
			m_fUseProxy = true;
			_tcscpy(m_proxyhost, proxyhost);
		}
	}
	else if (SwitchMatch(args[j], _T("autoreconnect"))) 
	{
        if (++j == i) {
            ArgError(_T("You must specify an autoreconnect delay (default is 10s)"));
            PostQuitMessage(1);
            continue;
        }
		_stscanf(args[j], _T("%d"), &m_autoReconnect);
	}
	else
	{
      TCHAR phost[256];
      if (!ParseDisplay(args[j], phost, 255, &m_port)) {
        ShowUsage(sz_D28);
        PostQuitMessage(1);
      } else {
		  for (size_t i = 0, len = strlen(phost); i < len; i++)
						{
							phost[i] = toupper(phost[i]);
						} 
        _tcscpy(m_host_options, phost);
        m_connectionSpecified = true;
      }
    }
  }       
	
  if (m_scale_num != 1 || m_scale_den != 1) 			
    m_scaling = true;

	// reduce scaling factors by greatest common denominator
  if (m_scaling) {
    FixScaling();
  }
  // tidy up
  delete [] cmd;
  delete [] args;
}
Пример #7
0
HRESULT CDVBSub::ParseSample(IMediaSample* pSample)
{
    CheckPointer(pSample, E_POINTER);
    HRESULT hr;
    BYTE* pData = NULL;
    int nSize;
    DVB_SEGMENT_TYPE nCurSegment;

    hr = pSample->GetPointer(&pData);
    if (FAILED(hr) || pData == NULL) {
        return hr;
    }
    nSize = pSample->GetActualDataLength();

    if (*((LONG*)pData) == 0xBD010000) {
        CGolombBuffer gb(pData, nSize);

        gb.SkipBytes(4);
        WORD wLength = (WORD)gb.BitRead(16);
        UNREFERENCED_PARAMETER(wLength);

        if (gb.BitRead(2) != 2) {
            return E_FAIL;  // type
        }

        gb.BitRead(2);      // scrambling
        gb.BitRead(1);      // priority
        gb.BitRead(1);      // alignment
        gb.BitRead(1);      // copyright
        gb.BitRead(1);      // original
        BYTE fpts = (BYTE)gb.BitRead(1);    // fpts
        BYTE fdts = (BYTE)gb.BitRead(1);    // fdts
        gb.BitRead(1);      // escr
        gb.BitRead(1);      // esrate
        gb.BitRead(1);      // dsmtrickmode
        gb.BitRead(1);      // morecopyright
        gb.BitRead(1);      // crc
        gb.BitRead(1);      // extension
        gb.BitRead(8);      // hdrlen

        if (fpts) {
            BYTE b = (BYTE)gb.BitRead(4);
            if (!(fdts && b == 3 || !fdts && b == 2)) {
                ASSERT(0);
                return E_FAIL;
            }

            REFERENCE_TIME pts = 0;
            pts |= gb.BitRead(3) << 30;
            MARKER; // 32..30
            pts |= gb.BitRead(15) << 15;
            MARKER; // 29..15
            pts |= gb.BitRead(15);
            MARKER; // 14..0
            pts = 10000 * pts / 90;

            m_rtStart = pts;
            m_rtStop  = pts + 1;
        } else {
            m_rtStart = INVALID_TIME;
            m_rtStop  = INVALID_TIME;
        }

        nSize -= 14;
        pData += 14;
        pSample->GetTime(&m_rtStart, &m_rtStop);
        pSample->GetMediaTime(&m_rtStart, &m_rtStop);
    } else if (SUCCEEDED(pSample->GetTime(&m_rtStart, &m_rtStop))) {
        pSample->SetTime(&m_rtStart, &m_rtStop);
    }

    //FILE* hFile = fopen("D:\\Sources\\mpc-hc\\A garder\\TestSubRip\\dvbsub.dat", "ab");
    //if (hFile != NULL)
    //{
    //  //BYTE Buff[5] = {48};

    //  //*((DWORD*)(Buff+1)) = lSampleLen;
    //  //fwrite(Buff, 1, sizeof(Buff), hFile);
    //  fwrite(pData, 1, lSampleLen, hFile);
    //  fclose(hFile);
    //}

    if (AddToBuffer(pData, nSize) == S_OK) {
        CGolombBuffer gb(m_pBuffer + m_nBufferReadPos, m_nBufferWritePos - m_nBufferReadPos);
        int nLastPos = 0;

        while (!gb.IsEOF()) {
            if (gb.ReadByte() == 0x0F) {
                TRACE_DVB("DVB - ParseSample\n");

                WORD wPageId;
                WORD wSegLength;

                nCurSegment = (DVB_SEGMENT_TYPE) gb.ReadByte();
                wPageId = gb.ReadShort();
                wSegLength = gb.ReadShort();

                if (gb.RemainingSize() < wSegLength) {
                    hr = S_FALSE;
                    break;
                }

                switch (nCurSegment) {
                case PAGE: {
                    CAutoPtr<DVB_PAGE>  pPage;
                    ParsePage(gb, wSegLength, pPage);

                    if (pPage->PageState == DPS_ACQUISITION) {
                        if (m_pCurrentPage != NULL) {
                            m_pCurrentPage->rtStop = max(m_pCurrentPage->rtStop, m_rtStart);
                            m_Pages.AddTail(m_pCurrentPage.Detach());
                        }
                        UpdateTimeStamp(m_rtStart);

                        m_pCurrentPage = pPage;
                        m_pCurrentPage->rtStart = m_rtStart;
                        m_pCurrentPage->rtStop  = m_pCurrentPage->rtStart + m_pCurrentPage->PageTimeOut * 1000000;

                        TRACE_DVB("DVB - Page started %S, TimeOut = %d\n", ReftimeToString(m_rtStart), m_pCurrentPage->PageTimeOut);
                    } else {
                        TRACE_DVB("DVB - Page update\n");

                        if (m_pCurrentPage && !m_pCurrentPage->RegionCount) {
                            m_pCurrentPage = pPage;
                            m_pCurrentPage->rtStart = m_rtStart;
                            m_pCurrentPage->rtStop  = m_pCurrentPage->rtStart + m_pCurrentPage->PageTimeOut * 1000000;

                            TRACE_DVB("DVB - Page started[update] %S, TimeOut = %d\n", ReftimeToString(m_rtStart), m_pCurrentPage->PageTimeOut);
                        }
                    }
                }
                break;
                case REGION:
                    ParseRegion(gb, wSegLength);
                    TRACE_DVB("DVB - Region\n");
                    break;
                case CLUT:
                    ParseClut(gb, wSegLength);
                    TRACE_DVB("DVB - Clut\n");
                    break;
                case OBJECT:
                    ParseObject(gb, wSegLength);
                    TRACE_DVB("DVB - Object\n");
                    break;
                case DISPLAY:
                    ParseDisplay(gb, wSegLength);
                    TRACE_DVB("DVB - Display\n");
                    break;
                case END_OF_DISPLAY:
                    if (m_pCurrentPage != NULL && (m_pCurrentPage->rtStart != m_rtStart)) {
                        m_pCurrentPage->rtStop = max(m_pCurrentPage->rtStop, m_rtStart);
                        TRACE_DVB("DVB - End display %S - %S\n", ReftimeToString(m_pCurrentPage->rtStart), ReftimeToString(m_pCurrentPage->rtStop));
                        m_Pages.AddTail(m_pCurrentPage.Detach());
                    }
                    break;
                default:
                    break;
                }
                nLastPos = gb.GetPos();
            }
        }
        m_nBufferReadPos += nLastPos;
    }

    return hr;
}
Пример #8
0
HRESULT CDVBSub::ParseSample(IMediaSample* pSample)
{
    CheckPointer(pSample, E_POINTER);
    HRESULT hr;
    BYTE* pData = nullptr;
    int nSize;
    DVB_SEGMENT_TYPE nCurSegment;

    hr = pSample->GetPointer(&pData);
    if (FAILED(hr) || pData == nullptr) {
        return hr;
    }
    nSize = pSample->GetActualDataLength();

    if (*((LONG*)pData) == 0xBD010000) {
        CGolombBuffer gb(pData, nSize);

        gb.SkipBytes(4);
        WORD wLength = (WORD)gb.BitRead(16);
        UNREFERENCED_PARAMETER(wLength);

        if (gb.BitRead(2) != 2) {
            return E_FAIL;  // type
        }

        gb.BitRead(2);      // scrambling
        gb.BitRead(1);      // priority
        gb.BitRead(1);      // alignment
        gb.BitRead(1);      // copyright
        gb.BitRead(1);      // original
        BYTE fpts = (BYTE)gb.BitRead(1);    // fpts
        BYTE fdts = (BYTE)gb.BitRead(1);    // fdts
        gb.BitRead(1);      // escr
        gb.BitRead(1);      // esrate
        gb.BitRead(1);      // dsmtrickmode
        gb.BitRead(1);      // morecopyright
        gb.BitRead(1);      // crc
        gb.BitRead(1);      // extension
        gb.BitRead(8);      // hdrlen

        if (fpts) {
            BYTE b = (BYTE)gb.BitRead(4);
            if (!(fdts && b == 3 || !fdts && b == 2)) {
                ASSERT(0);
                return E_FAIL;
            }

            REFERENCE_TIME pts = 0;
            pts |= gb.BitRead(3) << 30;
            MARKER; // 32..30
            pts |= gb.BitRead(15) << 15;
            MARKER; // 29..15
            pts |= gb.BitRead(15);
            MARKER; // 14..0
            pts = 10000 * pts / 90;

            m_rtStart = pts;
            m_rtStop  = pts + 1;
        } else {
            m_rtStart = INVALID_TIME;
            m_rtStop  = INVALID_TIME;
        }

        nSize -= 14;
        pData += 14;
        pSample->GetTime(&m_rtStart, &m_rtStop);
        pSample->GetMediaTime(&m_rtStart, &m_rtStop);
    } else if (SUCCEEDED(pSample->GetTime(&m_rtStart, &m_rtStop))) {
        pSample->SetTime(&m_rtStart, &m_rtStop);
    }

    if (AddToBuffer(pData, nSize) == S_OK) {
        CGolombBuffer gb(m_pBuffer + m_nBufferReadPos, m_nBufferWritePos - m_nBufferReadPos);
        int nLastPos = 0;

        while (gb.RemainingSize() >= 6) { // Ensure there is enough data to parse the entire segment header
            if (gb.ReadByte() == 0x0F) {
                TRACE_DVB(_T("DVB - ParseSample\n"));

                WORD wPageId;
                WORD wSegLength;

                nCurSegment = (DVB_SEGMENT_TYPE)gb.ReadByte();
                wPageId = gb.ReadShort();
                wSegLength = gb.ReadShort();

                if (gb.RemainingSize() < wSegLength) {
                    hr = S_FALSE;
                    break;
                }

                switch (nCurSegment) {
                    case PAGE: {
                        if (m_pCurrentPage != nullptr) {
                            TRACE_DVB(_T("DVB - Force End display"));
                            EnqueuePage(m_rtStart);
                        }
                        UpdateTimeStamp(m_rtStart);

                        CAutoPtr<DVB_PAGE> pPage;
                        ParsePage(gb, wSegLength, pPage);

                        if (pPage->pageState == DPS_ACQUISITION || pPage->pageState == DPS_MODE_CHANGE) {
                            m_pCurrentPage = pPage;
                            m_pCurrentPage->rtStart = m_rtStart;
                            m_pCurrentPage->rtStop  = m_pCurrentPage->rtStart + m_pCurrentPage->pageTimeOut * 10000000;

                            TRACE_DVB(_T("DVB - Page started [pageState = %d] %s, TimeOut = %ds\n"), m_pCurrentPage->pageState, ReftimeToString(m_rtStart), m_pCurrentPage->pageTimeOut);
                        } else if (!m_Pages.IsEmpty()) {
                            m_pCurrentPage = pPage;
                            m_pCurrentPage->rtStart = m_rtStart;
                            m_pCurrentPage->rtStop  = m_pCurrentPage->rtStart + m_pCurrentPage->pageTimeOut * 10000000;

                            // Copy data from the previous page
                            DVB_PAGE* pPrevPage = m_Pages.GetTail();

                            memcpy(m_pCurrentPage->regions, pPrevPage->regions, sizeof(m_pCurrentPage->regions));

                            for (POSITION pos = pPrevPage->objects.GetHeadPosition(); pos;) {
                                m_pCurrentPage->objects.AddTail(pPrevPage->objects.GetNext(pos)->Copy());
                            }

                            for (POSITION pos = pPrevPage->CLUTs.GetHeadPosition(); pos;) {
                                m_pCurrentPage->CLUTs.AddTail(DEBUG_NEW DVB_CLUT(*pPrevPage->CLUTs.GetNext(pos)));
                            }

                            TRACE_DVB(_T("DVB - Page started [update] %s, TimeOut = %ds\n"), ReftimeToString(m_rtStart), m_pCurrentPage->pageTimeOut);
                        } else {
                            TRACE_DVB(_T("DVB - Page update ignored %s\n"), ReftimeToString(m_rtStart));
                        }
                    }
                    break;
                    case REGION:
                        ParseRegion(gb, wSegLength);
                        TRACE_DVB(_T("DVB - Region\n"));
                        break;
                    case CLUT:
                        ParseClut(gb, wSegLength);
                        TRACE_DVB(_T("DVB - Clut\n"));
                        break;
                    case OBJECT:
                        ParseObject(gb, wSegLength);
                        TRACE_DVB(_T("DVB - Object\n"));
                        break;
                    case DISPLAY:
                        ParseDisplay(gb, wSegLength);
                        TRACE_DVB(_T("DVB - Display\n"));
                        break;
                    case END_OF_DISPLAY:
                        if (m_pCurrentPage == nullptr) {
                            TRACE_DVB(_T("DVB - Ignored End display %s: no current page\n"), ReftimeToString(m_rtStart));
                        } else if (m_pCurrentPage->rtStart < m_rtStart) {
                            TRACE_DVB(_T("DVB - End display"));
                            EnqueuePage(m_rtStart);
                        } else {
                            TRACE_DVB(_T("DVB - Ignored End display %s: no information on page duration\n"), ReftimeToString(m_rtStart));
                        }
                        break;
                    default:
                        break;
                }
                nLastPos = gb.GetPos();
            }
        }
        m_nBufferReadPos += nLastPos;
    }

    return hr;
}
Пример #9
0
BOOL CALLBACK SessionDialog::SessDlgProc(  HWND hwnd,  UINT uMsg,  WPARAM wParam, LPARAM lParam ) {
    // This is a static method, so we don't know which instantiation we're
    // dealing with. But we can get a pseudo-this from the parameter to
    // WM_INITDIALOG, which we therafter store with the window and retrieve
    // as follows:
#ifdef _X64

    SessionDialog *_this = (SessionDialog *) GetWindowLongPtr(hwnd, GWLP_USERDATA);

#else

    SessionDialog *_this = (SessionDialog *) GetWindowLong(hwnd, GWL_USERDATA);

#endif
    switch (uMsg) {

    case WM_INITDIALOG:
    {
        helper::SafeSetWindowUserData(hwnd, (LONG)lParam);
        SessionDialog *_this = (SessionDialog *) lParam;
        CentreWindow(hwnd);
        SetForegroundWindow(hwnd);
        _this->m_pCC->m_hSessionDialog = hwnd;

        // Set up recently-used list
        HWND hcombo = GetDlgItem(  hwnd, IDC_HOSTNAME_EDIT);
        TCHAR valname[256];

        for (int i = 0; i < _this->m_pMRU->NumItems(); i++) {
            _this->m_pMRU->GetItem(i, valname, 255);
            int pos = SendMessage(hcombo, CB_ADDSTRING, 0, (LPARAM) valname);

        }
        SendMessage(hcombo, CB_SETCURSEL, 0, 0);

        // sf@2002 - List available DSM Plugins
        HWND hPlugins = GetDlgItem(hwnd, IDC_PLUGINS_COMBO);
        int nPlugins = _this->m_pDSMPlugin->ListPlugins(hPlugins);
        if (!nPlugins)
        {
            SendMessage(hPlugins, CB_ADDSTRING, 0, (LPARAM) sz_F11);
        }
        else
        {
            // Use the first detected plugin, so the user doesn't have to check the option
            // HWND hUsePlugin = GetDlgItem(hwnd, IDC_PLUGIN_CHECK);
            // SendMessage(hUsePlugin, BM_SETCHECK, TRUE, 0);
        }
        SendMessage(hPlugins, CB_SETCURSEL, 0, 0);

        //AaronP
        if( strcmp( _this->m_pOpt->m_szDSMPluginFilename, "" ) != 0 && _this->m_pOpt->m_fUseDSMPlugin ) {
            int pos = SendMessage(hPlugins, CB_FINDSTRINGEXACT, -1,
                                  (LPARAM)&(_this->m_pOpt->m_szDSMPluginFilename[0]));

            if( pos != CB_ERR ) {
                SendMessage(hPlugins, CB_SETCURSEL, pos, 0);
                HWND hUsePlugin = GetDlgItem(hwnd, IDC_PLUGIN_CHECK);
                SendMessage(hUsePlugin, BM_SETCHECK, TRUE, 0);
            }
        }
        //EndAaronP

        TCHAR tmphost[256];
        TCHAR tmphost2[256];
        _tcscpy(tmphost, _this->m_pOpt->m_proxyhost);
        if (strcmp(tmphost,"")!=NULL)
        {
            _tcscat(tmphost,":");
            _tcscat(tmphost,_itoa(_this->m_pOpt->m_proxyport,tmphost2,10));
            SetDlgItemText(hwnd, IDC_PROXY_EDIT, tmphost);
        }

        HWND hViewOnly = GetDlgItem(hwnd, IDC_VIEWONLY_CHECK);
        SendMessage(hViewOnly, BM_SETCHECK, _this->m_pOpt->m_ViewOnly, 0);

        HWND hAutoScaling = GetDlgItem(hwnd, IDC_AUTOSCALING_CHECK);
        SendMessage(hAutoScaling, BM_SETCHECK, _this->m_pOpt->m_fAutoScaling, 0);

        HWND hProxy = GetDlgItem(hwnd, IDC_PROXY_CHECK);
        SendMessage(hProxy, BM_SETCHECK, _this->m_pOpt->m_fUseProxy, 0);


        // sf@2002 - Select Modem Option as default
        _this->SetQuickOption(_this, hwnd);

        _this->m_fFromOptions = false;
        _this->m_fFromFile = false;

        return TRUE;
    }

    case WM_COMMAND:
        switch (LOWORD(wParam))
        {
        case IDC_DELETE:
        {
            char optionfile[MAX_PATH];
            char *tempvar=NULL;
            tempvar = getenv( "TEMP" );
            if (tempvar) strcpy(optionfile,tempvar);
            else strcpy(optionfile,"");
            strcat(optionfile,"\\options.vnc");
            DeleteFile(optionfile);
        }
        return TRUE;

        case IDSAVE:
            _this->m_pCC->saved_set=true;
        case IDOK:
        {
            TCHAR tmphost[256];
            TCHAR display[256];
            TCHAR fulldisplay[256];

            // sf@2005

            GetDlgItemText(hwnd, IDC_HOSTNAME_EDIT, display, 256);
            _tcscpy(fulldisplay, display);
            if (!ParseDisplay(display, tmphost, 255, &_this->m_port)) {
                MessageBox(NULL,
                           sz_F8,
                           sz_F10, MB_OK | MB_ICONEXCLAMATION | MB_SETFOREGROUND | MB_TOPMOST);
            } else {
                _tcscpy(_this->m_host_dialog, tmphost);
                _this->m_pMRU->AddItem(fulldisplay);
//				_tcscpy(_this->m_remotehost, fulldisplay);
                EndDialog(hwnd, TRUE);
            }

            GetDlgItemText(hwnd, IDC_PROXY_EDIT, display, 256);
            _tcscpy(fulldisplay, display);
            if (!ParseDisplay(display, tmphost, 255, &_this->m_proxyport)) {
                MessageBox(NULL,
                           sz_F8,
                           sz_F10, MB_OK | MB_ICONEXCLAMATION | MB_SETFOREGROUND | MB_TOPMOST);
            } else {
                _tcscpy(_this->m_proxyhost, tmphost);
                EndDialog(hwnd, TRUE);
            }

            HWND hProxy = GetDlgItem(hwnd, IDC_PROXY_CHECK);
            if (SendMessage(hProxy, BM_GETCHECK, 0, 0) == BST_CHECKED)
            {
                _this->m_pOpt->m_fUseProxy = true;
                _this->m_fUseProxy = true;
            }
            else
            {
                _this->m_pOpt->m_fUseProxy = false;
                _this->m_fUseProxy = false;
            }

            // sf@2002 - DSMPlugin loading
            // If Use plugin is checked, load the plugin if necessary
            HWND hPlugin = GetDlgItem(hwnd, IDC_PLUGIN_CHECK);
            if (SendMessage(hPlugin, BM_GETCHECK, 0, 0) == BST_CHECKED)
            {
                TCHAR szPlugin[MAX_PATH];
                GetDlgItemText(hwnd, IDC_PLUGINS_COMBO, szPlugin, MAX_PATH);
                _this->m_pOpt->m_fUseDSMPlugin = true;
                strcpy(_this->m_pOpt->m_szDSMPluginFilename, szPlugin);

                if (!_this->m_pDSMPlugin->IsLoaded())
                {
                    _this->m_pDSMPlugin->LoadPlugin(szPlugin, _this->m_pOpt->m_listening);
                    if (_this->m_pDSMPlugin->IsLoaded())
                    {
                        if (_this->m_pDSMPlugin->InitPlugin())
                        {
                            _this->m_pDSMPlugin->SetEnabled(true);
                            _this->m_pDSMPlugin->DescribePlugin();
                        }
                        else
                        {
                            _this->m_pDSMPlugin->SetEnabled(false);
                            MessageBox(NULL,
                                       sz_F7,
                                       sz_F6, MB_OK | MB_ICONEXCLAMATION | MB_SETFOREGROUND | MB_TOPMOST);
                            return TRUE;
                        }
                    }
                    else
                    {
                        _this->m_pDSMPlugin->SetEnabled(false);
                        MessageBox(NULL,
                                   sz_F5,
                                   sz_F6, MB_OK | MB_ICONEXCLAMATION | MB_SETFOREGROUND | MB_TOPMOST);
                        return TRUE;
                    }
                }
                else
                {
                    // sf@2003 - If the plugin is already loaded here it has been loaded
                    // by clicking on the config button: we need to init it !
                    // But we must first check that the loaded plugin is the same that
                    // the one currently selected...
                    _this->m_pDSMPlugin->DescribePlugin();
                    if (_stricmp(_this->m_pDSMPlugin->GetPluginFileName(), szPlugin))
                    {
                        // Unload the previous plugin
                        _this->m_pDSMPlugin->UnloadPlugin();
                        // Load the new selected one
                        _this->m_pDSMPlugin->LoadPlugin(szPlugin, _this->m_pOpt->m_listening);
                    }

                    if (_this->m_pDSMPlugin->IsLoaded())
                    {
                        if (_this->m_pDSMPlugin->InitPlugin())
                        {
                            _this->m_pDSMPlugin->SetEnabled(true);
                            _this->m_pDSMPlugin->DescribePlugin();
                        }
                        else
                        {
                            _this->m_pDSMPlugin->SetEnabled(false);
                            MessageBox(NULL,
                                       sz_F7,
                                       sz_F6, MB_OK | MB_ICONEXCLAMATION | MB_SETFOREGROUND | MB_TOPMOST);
                            return TRUE;
                        }
                    }
                    else
                    {
                        _this->m_pDSMPlugin->SetEnabled(false);
                        MessageBox(NULL,
                                   sz_F5,
                                   sz_F6, MB_OK | MB_ICONEXCLAMATION | MB_SETFOREGROUND | MB_TOPMOST);
                        return TRUE;
                    }
                }
            }
            else // If Use plugin unchecked but the plugin is loaded, unload it
            {
                _this->m_pOpt->m_fUseDSMPlugin = false;
                if (_this->m_pDSMPlugin->IsEnabled())
                {
                    _this->m_pDSMPlugin->UnloadPlugin();
                    _this->m_pDSMPlugin->SetEnabled(false);
                }
            }

            if (_this->m_fFromOptions || _this->m_fFromFile)
            {
                EndDialog(hwnd, TRUE);
                return TRUE;
            }

            // sf@2002 - Quick options handling
            _this->ManageQuickOptions(_this, hwnd);

            HWND hViewOnly = GetDlgItem(hwnd, IDC_VIEWONLY_CHECK);
            _this->m_pOpt->m_ViewOnly = (SendMessage(hViewOnly, BM_GETCHECK, 0, 0) == BST_CHECKED);

            HWND hAutoScaling = GetDlgItem(hwnd, IDC_AUTOSCALING_CHECK);
            _this->m_pOpt->m_fAutoScaling = (SendMessage(hAutoScaling, BM_GETCHECK, 0, 0) == BST_CHECKED);

            EndDialog(hwnd, TRUE);
            return TRUE;
        }

        case IDCANCEL:
            EndDialog(hwnd, FALSE);
            return TRUE;

        case IDC_OPTIONBUTTON:
        {
            if (!_this->m_fFromFile)
            {
                _this->ManageQuickOptions(_this, hwnd);

                HWND hViewOnly = GetDlgItem(hwnd, IDC_VIEWONLY_CHECK);
                _this->m_pOpt->m_ViewOnly = (SendMessage(hViewOnly, BM_GETCHECK, 0, 0) == BST_CHECKED);

                HWND hAutoScaling = GetDlgItem(hwnd, IDC_AUTOSCALING_CHECK);
                _this->m_pOpt->m_fAutoScaling = (SendMessage(hAutoScaling, BM_GETCHECK, 0, 0) == BST_CHECKED);

            }

            _this->m_pOpt->DoDialog();
            _this->m_fFromOptions = true;

            return TRUE;
        }

        // sf@2002
        case IDC_PLUGIN_CHECK:
        {
            HWND hUse = GetDlgItem(hwnd, IDC_PLUGIN_CHECK);
            BOOL enable = SendMessage(hUse, BM_GETCHECK, 0, 0) == BST_CHECKED;
            HWND hButton = GetDlgItem(hwnd, IDC_PLUGIN_BUTTON);
            EnableWindow(hButton, enable);
        }
        return TRUE;


        case IDC_PLUGIN_BUTTON:
        {
            HWND hPlugin = GetDlgItem(hwnd, IDC_PLUGIN_CHECK);
            if (SendMessage(hPlugin, BM_GETCHECK, 0, 0) == BST_CHECKED)
            {
                TCHAR szPlugin[MAX_PATH];
                GetDlgItemText(hwnd, IDC_PLUGINS_COMBO, szPlugin, MAX_PATH);
                // sf@2003 - The config button can be clicked several times with
                // different selected plugins...
                bool fLoadIt = true;
                char szParams[32];
                strcpy(szParams, sz_F4);
                // If a plugin is already loaded, check if it is the same that the one
                // we want to load.
                if (_this->m_pDSMPlugin->IsLoaded())
                {
                    _this->m_pDSMPlugin->DescribePlugin();
                    if (!_stricmp(_this->m_pDSMPlugin->GetPluginFileName(), szPlugin))
                    {
                        fLoadIt = false;
                        _this->m_pDSMPlugin->SetPluginParams(hwnd, szParams);
                    }
                    else
                    {
                        // Unload the previous plugin
                        _this->m_pDSMPlugin->UnloadPlugin();
                        fLoadIt = true;
                    }
                }

                if (!fLoadIt) return TRUE;

                if (_this->m_pDSMPlugin->LoadPlugin(szPlugin, _this->m_pOpt->m_listening))
                {
                    // We don't know the password yet... no matter the plugin requires
                    // it or not, we will provide it later (at plugin "real" startup)
                    // Knowing the environnement ("viewer") right now can be usefull or
                    // even mandatory for the plugin (specific params saving and so on...)
                    // The plugin receives environnement info but isn't inited at this point
                    _this->m_pDSMPlugin->SetPluginParams(hwnd, szParams);
                }
                else
                {
                    MessageBox(NULL,
                               sz_F1,
                               sz_F3, MB_OK | MB_ICONEXCLAMATION | MB_SETFOREGROUND | MB_TOPMOST);
                }
            }
            return TRUE;
        }

        case IDC_LOADPROFILE_B:
        {
            TCHAR szFileName[MAX_PATH];
            memset(szFileName, '\0', MAX_PATH);
            if (_this->m_pCC->LoadConnection(szFileName, true,false) != -1)
            {
                TCHAR szHost[128];
                if (_this->m_pCC->m_port == 5900)
                    _tcscpy(szHost, _this->m_pCC->m_host);
                else if (_this->m_pCC->m_port > 5900 && _this->m_pCC->m_port <= 5999)
                    _stprintf(szHost, TEXT("%s:%d"), _this->m_pCC->m_host, _this->m_pCC->m_port - 5900);
                else
                    _stprintf(szHost, TEXT("%s::%d"), _this->m_pCC->m_host, _this->m_pCC->m_port);

                SetDlgItemText(hwnd, IDC_HOSTNAME_EDIT, szHost);
                //AaronP
                HWND hPlugins = GetDlgItem(hwnd, IDC_PLUGINS_COMBO);
                if( strcmp( _this->m_pOpt->m_szDSMPluginFilename, "" ) != 0 && _this->m_pOpt->m_fUseDSMPlugin ) {
                    int pos = SendMessage(hPlugins, CB_FINDSTRINGEXACT, -1,
                                          (LPARAM)&(_this->m_pOpt->m_szDSMPluginFilename[0]));

                    if( pos != CB_ERR ) {
                        SendMessage(hPlugins, CB_SETCURSEL, pos, 0);
                        HWND hUsePlugin = GetDlgItem(hwnd, IDC_PLUGIN_CHECK);
                        SendMessage(hUsePlugin, BM_SETCHECK, TRUE, 0);
                    }
                }
                //EndAaronP
            }
            SetFocus(GetDlgItem(hwnd, IDC_HOSTNAME_EDIT));
            _this->SetQuickOption(_this, hwnd);

            HWND hViewOnly = GetDlgItem(hwnd, IDC_VIEWONLY_CHECK);
            SendMessage(hViewOnly, BM_SETCHECK, _this->m_pOpt->m_ViewOnly, 0);

            HWND hAutoScaling = GetDlgItem(hwnd, IDC_AUTOSCALING_CHECK);
            SendMessage(hAutoScaling, BM_SETCHECK, _this->m_pOpt->m_fAutoScaling, 0);

            _this->m_fFromOptions = true;
            _this->m_fFromFile = true;
            return TRUE;
        }

        }

        break;

    case WM_DESTROY:
        EndDialog(hwnd, FALSE);
        return TRUE;
    }
    return 0;
}
Пример #10
0
BOOL CALLBACK SessionDialog::SessDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam,
                                         LPARAM lParam)
{
  // This is a static method, so we don't know which instantiation we're
  // dealing with, but we can get a pseudo-this from the parameter to
  // WM_INITDIALOG, which we thereafter store with the window and retrieve
  // as follows:
  SessionDialog *_this =
    (SessionDialog *)GetWindowLongPtr(hwnd, GWLP_USERDATA);

  int i;
  char tmphost[256];
  char buffer[256];
  HWND hListMode = GetDlgItem(hwnd, IDC_LIST_MODE);
  HWND hcombo = GetDlgItem(hwnd, IDC_HOSTNAME_EDIT);

  switch (uMsg) {
    case WM_INITDIALOG:
    {
      SetWindowLongPtr(hwnd, GWLP_USERDATA, lParam);
      SessionDialog *_this = (SessionDialog *) lParam;
      CenterWindow(hwnd);
      _this->m_cc->m_hSess = hwnd;

      // Load connection history into the combo box
      const int maxEntries = pApp->m_options.m_historyLimit;
      int listIndex = 0;
      for (i = 0; i < maxEntries; i++) {
        char keyName[256];
        _itoa_s(i, keyName, _countof(keyName), 10);
        char buf[256];
        int dwbuflen = 255;
        if (RegQueryValueEx(_this->m_hRegKey, keyName, NULL, NULL, (LPBYTE)buf,
                            (LPDWORD)&dwbuflen) == ERROR_SUCCESS) {
          buf[255] = '\0';
          if (buf[0] != 0)
            SendMessage(hcombo, CB_INSERTSTRING, (WPARAM)listIndex++,
                        (LPARAM)buf);
        }
      }
      if (_this->m_pOpt->m_display[0] == '\0') {
        SendMessage(hcombo, CB_SETCURSEL, 0, 0);
        LRESULT r = SendMessage(hcombo, CB_GETLBTEXTLEN, 0, 0);
        if (r > 1 && r <= 256) {
          r = SendMessage(hcombo, CB_GETLBTEXT, 0, (LPARAM)buffer);
          if (r > 1)
            _this->m_pOpt->LoadOpt(buffer, KEY_VNCVIEWER_HISTORY);
        }
      } else {
        SetDlgItemText(hwnd, IDC_HOSTNAME_EDIT, _this->m_pOpt->m_display);
      }

      UpdateConnectButton(hwnd);
      SetFocus(hcombo);
      return TRUE;
    }
    case WM_HELP:
      help.Popup(lParam);
      return 0;
    case WM_ACTIVATE:
    case WM_ACTIVATEAPP:
      if ((pApp->m_options.m_listening) ||
          (FindWindow("VNCviewer Daemon", 0) != NULL))
        EnableWindow(hListMode, FALSE);
      if ((!pApp->m_options.m_listening) &&
          (FindWindow("VNCviewer Daemon", 0) == NULL))
        EnableWindow(hListMode, TRUE);
      return 0;
    case WM_COMMAND:
      switch (LOWORD(wParam)) {
        case IDC_HOSTNAME_EDIT:
          switch (HIWORD(wParam)) {
            case CBN_SELENDOK:
            {
              int a = (int)SendMessage(hcombo, CB_GETCURSEL, 0, 0L);
              SendMessage(hcombo, CB_GETLBTEXT, a, (LPARAM)(int FAR*)buffer);
              _this->m_pOpt->LoadOpt(buffer, KEY_VNCVIEWER_HISTORY);
              EnableConnectButton(hwnd, TRUE);
              SetFocus(hcombo);
            }
            break;
            case CBN_EDITCHANGE:
              UpdateConnectButton(hwnd);
              break;
          }
          return TRUE;
        case IDC_LOAD:
        {
          char buf[80];
          buf[0] = '\0';
          if (_this->m_cc->LoadConnection(buf, true) != -1) {
            FormatDisplay(_this->m_cc->m_port, _this->m_pOpt->m_display,
                          _countof(_this->m_pOpt->m_display),
                          _this->m_cc->m_host);
            SetDlgItemText(hwnd, IDC_HOSTNAME_EDIT, _this->m_pOpt->m_display);
          }
          UpdateConnectButton(hwnd);
          SetFocus(hcombo);
          return TRUE;
        }
        case IDC_LIST_MODE:
          pApp->m_options.LoadOpt(".listen", KEY_VNCVIEWER_HISTORY);
          pApp->m_options.m_listening = true;
          pApp->ListenMode();
          _this->m_pOpt->CloseDialog();
          EndDialog(hwnd, FALSE);
          return TRUE;
        case IDC_OK:
          char display[256];
          GetDlgItemText(hwnd, IDC_HOSTNAME_EDIT, display, 256);
          if (strlen(display) == 0)
            return TRUE;
          if (!ParseDisplay(display, _countof(display), tmphost,
                            _countof(tmphost), &_this->m_cc->m_port)) {
            MessageBox(NULL,
                "Invalid VNC server specified.\n\r"
                "Server should be of the form host:display.",
                "Connection setup", MB_OK | MB_ICONEXCLAMATION);
            return TRUE;
          } else {
            STRCPY(_this->m_cc->m_host, tmphost);
            STRCPY(_this->m_pOpt->m_display, display);
          }

          _this->m_pOpt->CloseDialog();
          EndDialog(hwnd, TRUE);
          return TRUE;
        case IDCANCEL:
          _this->m_pOpt->CloseDialog();
          EndDialog(hwnd, FALSE);
          return TRUE;
        case IDC_OPTIONBUTTON:
        {
          if (_this->m_pOpt->RaiseDialog())
            return TRUE;  // Options dialog already shown
          HWND hOptionButton = GetDlgItem(hwnd, IDC_OPTIONBUTTON);
          _this->m_pOpt->DoDialog();
          GetDlgItemText(hwnd, IDC_HOSTNAME_EDIT,
                         _this->m_pOpt->m_display, 256);
          SendMessage(hcombo, CB_RESETCONTENT, 0, 0);
          int dwbuflen = 255;
          char valname[256];
          char buf[256];
          int maxEntries = pApp->m_options.m_historyLimit;
          for (i = 0; i < maxEntries; i++) {
            _itoa_s(i, valname, _countof(valname), 10);
            dwbuflen = 255;
            if (RegQueryValueEx(_this->m_hRegKey, (LPTSTR)valname, NULL, NULL,
                (LPBYTE)buf, (LPDWORD)&dwbuflen) != ERROR_SUCCESS)
              break;
            SendMessage(hcombo, CB_INSERTSTRING, (WPARAM)i,
                        (LPARAM)(int FAR*)buf);
          }
          SetDlgItemText(hwnd, IDC_HOSTNAME_EDIT, _this->m_pOpt->m_display);
          SetFocus(hOptionButton);
          return TRUE;
        }
      }
    case WM_DESTROY:
      EndDialog(hwnd, FALSE);
      return TRUE;
  }
  return 0;
}
Пример #11
0
void VNCOptions::SetFromCommandLine(LPTSTR szCmdLine) {
	// We assume no quoting here.
	// Copy the command line - we don't know what might happen to the original
	int cmdlinelen = _tcslen(szCmdLine);
	if (cmdlinelen == 0) return;
	
	TCHAR *cmd = new TCHAR[cmdlinelen + 1];
	_tcscpy(cmd, szCmdLine);
	
	// Count the number of spaces
	// This may be more than the number of arguments, but that doesn't matter.
	int nspaces = 0;
	TCHAR *p = cmd;
	TCHAR *pos = cmd;
	while ( ( pos = _tcschr(p, ' ') ) != NULL ) {
		nspaces ++;
		p = pos + 1;
	}
	
	// Create the array to hold pointers to each bit of string
	TCHAR **args = new LPTSTR[nspaces + 1];
	
	// replace spaces with nulls and
	// create an array of TCHAR*'s which points to start of each bit.
	pos = cmd;
	int i = 0;
	args[i] = cmd;
	bool inquote=false;
	for (pos = cmd; *pos != 0; pos++) {
		// Arguments are normally separated by spaces, unless there's quoting
		if ((*pos == ' ') && !inquote) {
			*pos = '\0';
			p = pos + 1;
			args[++i] = p;
		}
		if (*pos == '"') {  
			if (!inquote) {      // Are we starting a quoted argument?
				args[i] = ++pos; // It starts just after the quote
			} else {
				*pos = '\0';     // Finish a quoted argument?
			}
			inquote = !inquote;
		}
	}
	i++;

	bool hostGiven = false, portGiven = false;
	// take in order.
	for (int j = 0; j < i; j++) {
		if ( SwitchMatch(args[j], _T("help")) ||
			SwitchMatch(args[j], _T("?")) ||
			SwitchMatch(args[j], _T("h"))) {
			ShowUsage();
			PostQuitMessage(1);
		} else if ( SwitchMatch(args[j], _T("listen"))) {
			m_listening = true;
		} else if ( SwitchMatch(args[j], _T("restricted"))) {
			m_restricted = true;
		} else if ( SwitchMatch(args[j], _T("viewonly"))) {
			m_ViewOnly = true;
		} else if ( SwitchMatch(args[j], _T("fullscreen"))) {
			m_FullScreen = true;
		} else if ( SwitchMatch(args[j], _T("8bit"))) {
			m_Use8Bit = true;
		} else if ( SwitchMatch(args[j], _T("shared"))) {
			m_Shared = true;
		} else if ( SwitchMatch(args[j], _T("swapmouse"))) {
			m_SwapMouse = true;
		} else if ( SwitchMatch(args[j], _T("nocursor"))) {
			m_localCursor = NOCURSOR;
		} else if ( SwitchMatch(args[j], _T("dotcursor"))) {
			m_localCursor = DOTCURSOR;
		} else if ( SwitchMatch(args[j], _T("normalcursor"))) {
			m_localCursor = NORMALCURSOR;
		} else if ( SwitchMatch(args[j], _T("belldeiconify") )) {
			m_DeiconifyOnBell = true;
		} else if ( SwitchMatch(args[j], _T("emulate3") )) {
			m_Emul3Buttons = true;
		} else if ( SwitchMatch(args[j], _T("noemulate3") )) {
			m_Emul3Buttons = false;
		} else if ( SwitchMatch(args[j], _T("scale") )) {
			if (++j == i) {
				ArgError(_T("No scaling factor specified"));
				continue;
			}
			int numscales = _stscanf(args[j], _T("%d/%d"), &m_scale_num, &m_scale_den);
			if (numscales < 1) {
				ArgError(_T("Invalid scaling specified"));
				continue;
			}
			if (numscales == 1) 
				m_scale_den = 1; // needed if you're overriding a previous setting

		} else if ( SwitchMatch(args[j], _T("emulate3timeout") )) {
			if (++j == i) {
				ArgError(_T("No timeout specified"));
				continue;
			}
			if (_stscanf(args[j], _T("%d"), &m_Emul3Timeout) != 1) {
				ArgError(_T("Invalid timeout specified"));
				continue;
			}
			
		} else if ( SwitchMatch(args[j], _T("emulate3fuzz") )) {
			if (++j == i) {
				ArgError(_T("No fuzz specified"));
				continue;
			}
			if (_stscanf(args[j], _T("%d"), &m_Emul3Fuzz) != 1) {
				ArgError(_T("Invalid fuzz specified"));
				continue;
			}
			
		} else if ( SwitchMatch(args[j], _T("disableclipboard") )) {
			m_DisableClipboard = true;
		}
#ifdef UNDER_CE
		// Manual setting of palm vs hpc aspect ratio for dialog boxes.
		else if ( SwitchMatch(args[j], _T("hpc") )) {
			m_palmpc = false;
		} else if ( SwitchMatch(args[j], _T("palm") )) {
			m_palmpc = true;
		} else if ( SwitchMatch(args[j], _T("slow") )) {
			m_slowgdi = true;
		} 
#endif
		else if ( SwitchMatch(args[j], _T("delay") )) {
			if (++j == i) {
				ArgError(_T("No delay specified"));
				continue;
			}
			if (_stscanf(args[j], _T("%d"), &m_delay) != 1) {
				ArgError(_T("Invalid delay specified"));
				continue;
			}
			
		} else if ( SwitchMatch(args[j], _T("loglevel") )) {
			if (++j == i) {
				ArgError(_T("No loglevel specified"));
				continue;
			}
			if (_stscanf(args[j], _T("%d"), &m_logLevel) != 1) {
				ArgError(_T("Invalid loglevel specified"));
				continue;
			}
			
		} else if ( SwitchMatch(args[j], _T("console") )) {
			m_logToConsole = true;
		} else if ( SwitchMatch(args[j], _T("logfile") )) {
			if (++j == i) {
				ArgError(_T("No logfile specified"));
				continue;
			}
			if (_stscanf(args[j], _T("%s"), &m_logFilename) != 1) {
				ArgError(_T("Invalid logfile specified"));
				continue;
			} else {
				m_logToFile = true;
			}
		} else if ( SwitchMatch(args[j], _T("config") )) {
			if (++j == i) {
				ArgError(_T("No config file specified"));
				continue;
			}
			// The GetPrivateProfile* stuff seems not to like some relative paths
			_fullpath(m_configFilename, args[j], _MAX_PATH);
			if (_access(m_configFilename, 04)) {
				ArgError(_T("Can't open specified config file for reading."));
				PostQuitMessage(1);
				continue;
			} else {
				Load(m_configFilename);
				m_configSpecified = true;
			}
		} else if ( SwitchMatch(args[j], _T("register") )) {
			Register();
			PostQuitMessage(0);
		} else {
			TCHAR phost[256];
			if (!ParseDisplay(args[j], phost, 255, &m_port)) {
				ShowUsage(_T("Invalid VNC server specified."));
				PostQuitMessage(1);
			} else {
				_tcscpy(m_host, phost);
				m_connectionSpecified = true;
			}
		}
	}       
	
	if (m_scale_num != 1 || m_scale_den != 1) 			
		m_scaling = true;

	// reduce scaling factors by greatest common denominator
	if (m_scaling) {
		FixScaling();
	}
	// tidy up
	delete [] cmd;
	delete [] args;
}
Пример #12
0
HRESULT CDVBSub::ParseSample(IMediaSample* pSample)
{
	CheckPointer (pSample, E_POINTER);
	HRESULT				hr;
	BYTE*				pData = NULL;
	int					nSize;
	DVB_SEGMENT_TYPE	nCurSegment;

	hr = pSample->GetPointer(&pData);
	if (FAILED(hr) || pData == NULL) {
		return hr;
	}
	nSize = pSample->GetActualDataLength();

	if (*((LONG*)pData) == 0xBD010000) {
		CGolombBuffer	gb (pData, nSize);

		gb.SkipBytes(4);
		WORD	wLength	= (WORD)gb.BitRead(16);
		UNREFERENCED_PARAMETER(wLength);

		if (gb.BitRead(2) != 2) {
			return E_FAIL;    // type
		}

		gb.BitRead(2);	// scrambling
		gb.BitRead(1);	// priority
		gb.BitRead(1);	// alignment
		gb.BitRead(1);	// copyright
		gb.BitRead(1);	// original
		BYTE fpts = (BYTE)gb.BitRead(1);	// fpts
		BYTE fdts = (BYTE)gb.BitRead(1);	// fdts
		gb.BitRead(1);	// escr
		gb.BitRead(1);	// esrate
		gb.BitRead(1);	// dsmtrickmode
		gb.BitRead(1);	// morecopyright
		gb.BitRead(1);	// crc
		gb.BitRead(1);	// extension
		gb.BitRead(8);	// hdrlen

		if (fpts) {
			BYTE b = (BYTE)gb.BitRead(4);
			if (!(fdts && b == 3 || !fdts && b == 2)) {
				ASSERT(0);
				return(E_FAIL);
			}

			REFERENCE_TIME	pts = 0;
			pts |= gb.BitRead(3) << 30;
			MARKER; // 32..30
			pts |= gb.BitRead(15) << 15;
			MARKER; // 29..15
			pts |= gb.BitRead(15);
			MARKER; // 14..0
			pts = 10000*pts/90;

			m_rtStart	= pts;
			m_rtStop	= pts+1;
		} else {
			m_rtStart	= INVALID_TIME;
			m_rtStop	= INVALID_TIME;
		}

		nSize -= 14;
		pData += 14;
		pSample->GetTime(&m_rtStart, &m_rtStop);
		pSample->GetMediaTime(&m_rtStart, &m_rtStop);
	} else if (SUCCEEDED (pSample->GetTime(&m_rtStart, &m_rtStop))) {
		pSample->SetTime(&m_rtStart, &m_rtStop);
	}

	if (AddToBuffer (pData, nSize) == S_OK) {
		CGolombBuffer	gb (m_pBuffer+m_nBufferReadPos, m_nBufferWritePos-m_nBufferReadPos);
		int				nLastPos = 0;

		while (!gb.IsEOF()) {
			if (gb.ReadByte() == 0x0F) {
				WORD	wPageId;
				WORD	wSegLength;

				nCurSegment	= (DVB_SEGMENT_TYPE) gb.ReadByte();
				wPageId		= gb.ReadShort();
				wSegLength	= gb.ReadShort();

				if (gb.RemainingSize() < wSegLength) {
					hr = S_FALSE;
					break;
				}

				TRACE_DVB (_T("DVB - ParseSample, Segment = [%ws], PageId = [%d], SegLength/Buffer = [%d]/[%d]\n"), GetSegmentType(nCurSegment), wPageId, wSegLength, gb.RemainingSize());

				switch (nCurSegment) {
					case PAGE : {
						CAutoPtr<DVB_PAGE>	pPage;
						ParsePage(gb, wSegLength, pPage);

						if (pPage->PageState == DPS_ACQUISITION || pPage->PageState == DPS_MODE) {
							TRACE_DVB (_T("DVB - Page start\n"));

							if (m_pCurrentPage != NULL) {
								m_pCurrentPage->rtStop = min(m_pCurrentPage->rtStop, m_rtStart);
								TRACE_DVB (_T("DVB - store Page : %ws => %ws\n"), ReftimeToString(m_pCurrentPage->rtStart), ReftimeToString(m_pCurrentPage->rtStop));
								m_Pages.AddTail (m_pCurrentPage.Detach());
							}
							UpdateTimeStamp(m_rtStart);

							m_pCurrentPage = pPage;
							m_pCurrentPage->rtStart	= m_rtStart;
							m_pCurrentPage->rtStop	= m_pCurrentPage->rtStart + m_pCurrentPage->PageTimeOut * UNITS; // TODO - need to limit the duration of the segment

							TRACE_DVB (_T("DVB - Page started : %ws, TimeOut = %d\n"), ReftimeToString(m_pCurrentPage->rtStart), m_pCurrentPage->PageTimeOut);
						} else if (pPage->PageState == DPS_NORMAL) {
							TRACE_DVB (_T("DVB - Page update\n"));

							if (m_pCurrentPage && !m_pCurrentPage->RegionCount && pPage->RegionCount) {
								m_pCurrentPage = pPage;
								m_pCurrentPage->rtStart	= m_rtStart;
								m_pCurrentPage->rtStop	= m_pCurrentPage->rtStart + m_pCurrentPage->PageTimeOut * UNITS; // TODO - need to limit the duration of the segment

								TRACE_DVB (_T("DVB - Page started[update] : %ws, TimeOut = %d\n"), ReftimeToString(m_pCurrentPage->rtStart), m_pCurrentPage->PageTimeOut);
							}
						}
					}
					break;
					case REGION :
						ParseRegion(gb, wSegLength);
						TRACE_DVB (_T("DVB - Region\n"));
						break;
					case CLUT :
						ParseClut(gb, wSegLength);
						TRACE_DVB (_T("DVB - Clut\n"));
						break;
					case OBJECT :
						ParseObject(gb, wSegLength);
						TRACE_DVB (_T("DVB - Object\n"));
						break;
					case DISPLAY :
						ParseDisplay(gb, wSegLength);
						TRACE_DVB (_T("DVB - Display\n"));
						break;
					case END_OF_DISPLAY :
						/*
						if (m_pCurrentPage != NULL && (m_pCurrentPage->rtStart != m_rtStart)) {
							m_pCurrentPage->rtStop = max(m_pCurrentPage->rtStop, m_rtStart);
							TRACE_DVB (_T("DVB - End display : %ws => %ws\n"), ReftimeToString(m_pCurrentPage->rtStart), ReftimeToString(m_pCurrentPage->rtStop));
							m_Pages.AddTail (m_pCurrentPage.Detach());
						}
						*/
						TRACE_DVB (_T("DVB - End display\n"));
						break;
					default :
						TRACE_DVB (_T("DVB - unknown Segment\n"));
						break;
				}
				nLastPos = gb.GetPos();
			}
		}
		m_nBufferReadPos += nLastPos;
	}

	return hr;
}