⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frame.c

📁 g729 coding ipaddressing
💻 C
📖 第 1 页 / 共 5 页
字号:
    hwndClient = findClientByHost(&sockHost);
    
    if (hwndClient != NULL) {
    	if (IsIconic(hwndClient)) {
			FORWARD_WM_MDIRESTORE(hwndMDIClient, hwndClient, SendMessage);
    	}
		BringWindowToTop(hwndClient);
		pClientData = CLIENTPTR(hwndClient);
    } else {
	
	    //  Allocate a new connection structure
	
	    pClientData = (LPCLIENT_DATA) GlobalAllocPtr(GPTR, sizeof(CLIENT_DATA));
	
	    if (pClientData != NULL) {
		
		    //  Initialize the connection descriptor
		    
		    memset(pClientData, 0, sizeof(CLIENT_DATA));
		    pClientData->dwType = WINDOW_TYPE_CLIENT;
		    pClientData->wantsInput = FALSE;
		    pClientData->broadcastBeginTime = GetTickCount();
		    pClientData->broadcastEnd = FALSE;
		    pClientData->state = Embryonic;
		    pClientData->sReply = pClientData->sControl = INVALID_SOCKET;
		    pClientData->timeout = -1;		// Connection with local origin is immortal
		    pClientData->sendSDEStimer = 0;
		    pClientData->buttonUpTimer = FALSE;
		    pClientData->inetSock.sin_addr.s_addr = addrHost.s_addr;
			pClientData->localLoopback = IS_LOCALHOST(addrHost.s_addr);
		    pClientData->modemConnection = (addrHost.s_addr == 0);
		    pClientData->hFile = HFILE_ERROR;
		    pClientData->multicast_scope = 1;
		    pClientData->szFile[0] = '\0';
	    	pClientData->face_stat = FSinit;
			pClientData->protocol = PROTOCOL_UNKNOWN;
			pClientData->llhead = pClientData->lltail = NULL;
			pClientData->uname = NULL;
			pClientData->email[0] = 0;
			pClientData->port = ntohs(sockHost.sin_port);
			pClientData->auxSock = NULL;
			pClientData->d_celp_ctx = NULL;
	    	memcpy(pClientData->session_id, "\221\007\311\201", 4);
	    	pClientData->face_bmp = NULL;
		    strcpy(pClientData->szHost, szHostName);
		} else {
	        return;
	    }
	
	    //  Create the connection child window
	
	    hwndClient = createNewConnection(pClientData);
	
	    if (hwndClient == NULL) {
	        GlobalFreePtr(pClientData);
	        return;
	    }
	}	    
	    
    /*	If the connection was defined in a file, restore the
    	parameters to those saved in the file.  */
	    	
    if (connectionFile != NULL) {
	    	    	
    	strcpy(pClientData->connectionFileName, connectionFile); 
	    
	    cg = rstring(IDS_PF_DEBUG);			
    	pClientData->debugging = GetPrivateProfileInt(cg,
    		rstring(IDS_PF_DEBUGGING), FALSE, connectionFile);	
    	pClientData->loopback = GetPrivateProfileInt(cg,
    		rstring(IDS_PF_LOOPBACK), FALSE, connectionFile);
	    
	    cg = rstring(IDS_PF_MULTICAST);			
    	pClientData->multicast_scope = GetPrivateProfileInt(cg,
    		rstring(IDS_PF_SCOPE), 1, connectionFile);
    	
    	cg = rstring(IDS_PF_ENCRYPTION);	
    	pClientData->saveKeys = GetPrivateProfileInt(cg,
    		rstring(IDS_PF_SAVE_KEYS), FALSE, connectionFile);
		GetPrivateProfileString(cg, rstring(IDS_PF_PGP_USER_NAMES), "",
			pClientData->opgpUserList,
			sizeof pClientData->opgpUserList, connectionFile);	    	
    	if (pClientData->saveKeys) {
			GetPrivateProfileString(cg, rstring(IDS_PF_DES_KEY), "",
				pClientData->desKeyString,
				sizeof pClientData->desKeyString, connectionFile);	    	
			GetPrivateProfileString(cg, rstring(IDS_PF_IDEA_KEY), "",
				pClientData->ideaKeyString,
				sizeof pClientData->ideaKeyString, connectionFile);	    	
			GetPrivateProfileString(cg, rstring(IDS_PF_BLOWFISH_KEY), "",
				pClientData->blowfishKeyString,
				sizeof pClientData->blowfishKeyString, connectionFile);	    	
			GetPrivateProfileString(cg, rstring(IDS_PF_AES_KEY), "",
				pClientData->aesKeyString,
				sizeof pClientData->aesKeyString, connectionFile);	    	
    		pClientData->aesKeyHex = GetPrivateProfileInt(cg,
    			rstring(IDS_PF_AES_KEY_HEX), FALSE, connectionFile);
			GetPrivateProfileString(cg, rstring(IDS_PF_KEY_FILE), "",
				pClientData->otpFileName,
				sizeof pClientData->otpFileName, connectionFile);
    	}
    	
    	//	Initialise settings derived from saved parameters

		if (!makeInternalEncryptionKeys(hwndClient, pClientData)) {
			pClientData->otpFileName[0] = 0;	
		}
	    	
    	/*	Caution: don't reference connectionFile anywhere after
    		the call to rememberNewConnection.  If we're re-opening
    		a remembered connection, the call may release it.  */
	    	
    	rememberNewConnection(connectionFile);
    }
#undef addrHost	
}

#ifdef CRYPTO

/*	PGPSETSESSIONKEY  --  If needed, invoke PGP to decrypt the session
						  key and set it in effect for PGP encrypted
						  packets.  */
						  
static void pgpSetSessionKey(HWND hwnd, LPCLIENT_DATA conn, soundbuf *d)
{
	char cmd[MAX_PATH + 40], kmd[16];
	HFILE kfile;
	struct MD5Context md5c;

	MD5Init(&md5c);
	MD5Update(&md5c, d->buffer.buffer_val, (unsigned) d->buffer.buffer_len);
	MD5Final(kmd, &md5c);

	if (memcmp(conn->pgpkeymd5, kmd, 16) != 0) {
		char td[MAX_PATH];

		GetTempPath(sizeof td, td);

		conn->pgpkey[0] = FALSE;
		memcpy(conn->pgpkeymd5, kmd, 16);
		GetTempFileName(
						td
						 , "PK", 0, conn->pgpFileName);

        kfile = _lcreat(conn->pgpFileName, 0);
		if (kfile == HFILE_ERROR) {
            MessageBox(hwnd, rstring(IDS_T_OPEN_SESSION_KEY_FILE_ERR),
            	rstring(IDS_T_PGP_KEY_ERR_TITLE), MB_ICONEXCLAMATION | MB_OK);
		} else {
			UINT execStat = 0;
		
			_lwrite(kfile, d->buffer.buffer_val, (UINT) d->buffer.buffer_len);
			_lclose(kfile);
			
			/*	First try to run PGP via the PIF in our own directory.  This
				guarantees it's run with the modes we've chosen, such as
				in a window rather than full-screen.  */
			
			if (GetModuleFileName(hInst, cmd, sizeof cmd) > 0) {
				char *cp = cmd + strlen(cmd);
				
				while (cp >= cmd && *cp != '\\' && *cp != ':') {
					cp--;
				}
				cp[1] = 0;
				if (pk_package == GPG) {
					strcpy(td, conn->pgpFileName);
					td[strlen(td) - 4] = 0;
					wsprintf(cmd + strlen(cmd), Format(83), td, conn->pgpFileName);
				} else {                     
					wsprintf(cmd + strlen(cmd), Format(52), conn->pgpFileName);
				}
//cPrintf("CMD: %s", cmd);
				execStat = WinExec(cmd, SW_SHOW); 
			}
//cPrintf("execStat = %d", execStat);

			/*	If that didn't work, attempt to run PGP by straight path
				search using the default modes.  */
				
			if (execStat < 32) {                       
				if (pk_package == GPG) {
            		wsprintf(cmd, Format(84), td, conn->pgpFileName);
				} else {
            		wsprintf(cmd, Format(1), conn->pgpFileName);
            	}
//cPrintf("CMD: %s", cmd);
            	execStat = WinExec(cmd, SW_SHOW);
//cPrintf("execStat = %d", execStat);
            }
            
            //	Set timer to poll for completion of decoding
            
            if (execStat >= 32) {
	            conn->pgpFileName[strlen(conn->pgpFileName) - 4] = 0;
	            SetTimer(hwnd, 3, 1000, NULL);
	        } else {
	        	wsprintf(cmd + strlen(cmd), Format(51), execStat);
	        	MessageBox(hwnd, cmd, rstring(IDS_T_CANT_INVOKE_PGP),
			   		MB_OK | MB_ICONEXCLAMATION);
	        }
		}
	}
}
#endif 						  

//	onCreate  --  Initialise frame window when newly created

static BOOL onCreate(HWND hwnd, CREATESTRUCT *pCreateStruct)
{
    CLIENTCREATESTRUCT ccs;
    WSADATA wsadata;
    SOCKERR serr;
    HDC hdc;
    TEXTMETRIC tm;
	HFONT ofont;
    int i, j, isPC_NFS, winShowMode = SW_SHOW;
    char pfn[80], cg[80];
    char md5key[16];

    //  Initialize the sockets library

    serr = WSAStartup(DESIRED_WINSOCK_VERSION, &wsadata);

    if (serr != 0) {
        MsgBox(NULL, MB_ICONSTOP | MB_OK, Format(12), serr, SockerrToString(serr));
        return -1;
    }

    if (wsadata.wVersion < MINIMUM_WINSOCK_VERSION) {
        MsgBox(NULL, MB_ICONSTOP | MB_OK, Format(13), LOBYTE(wsadata.wVersion),
                HIBYTE(wsadata.wVersion), LOBYTE(MINIMUM_WINSOCK_VERSION),
                HIBYTE(MINIMUM_WINSOCK_VERSION));
        return -1;
    }
    aboutUDPmax = wsadata.iMaxUdpDg;
    isPC_NFS = strcmp(wsadata.szDescription, rstring(IDS_T_SUN_SIGNATURE)) == 0;
    
    /*	If the network can't transmit sound packets as large as we'd like
    	to send, restrict the size to what it can accommodate.  */
    	
    if (aboutUDPmax > 0) {
    	if ((netMaxSamples + (sizeof(soundbuf) - BUFL) + 40) > (UINT) aboutUDPmax) {
    		netMaxSamples = aboutUDPmax - ((sizeof(soundbuf) - BUFL) + 40); 
    	}
    }

    //  Create the command and control sockets

    serr = CreateSocket(&sCommand, SOCK_DGRAM, htonl(INADDR_ANY), htons(NETFONE_COMMAND_PORT));
	if (serr != 0) {
        MsgBox(NULL, MB_ICONSTOP | MB_OK, Format(14),
                serr, SockerrToString(serr));
        return -1;
	}
    serr = CreateSocket(&sControl, SOCK_DGRAM, htonl(INADDR_ANY),
    					htons(NETFONE_COMMAND_PORT + 1));
	if (serr != 0) {
        MsgBox(NULL, MB_ICONSTOP | MB_OK, Format(14),
                serr, SockerrToString(serr));
        return -1;
	}
   
    //	Load cursors
    
    phoneCursor = LoadCursor(hInst, MAKEINTRESOURCE(IDC_CURSOR_PHONE));
    earCursor = LoadCursor(hInst, MAKEINTRESOURCE(IDC_CURSOR_EAR));
    boltCursor = LoadCursor(hInst, MAKEINTRESOURCE(IDC_CURSOR_BOLT));
    
    //	Register the message for file open/save help button pressed
    
    fileOpenHelpButton = RegisterWindowMessage(HELPMSGSTRING);
    
    //	Initialise GSM encoding and decoding

    gsmh = gsm_create();

	// Initialise LPC encoding and decoding

	if (!lpc_start()) {
        MsgBox(NULL, MB_ICONSTOP | MB_OK, rstring(IDS_T_LWL_ALLOC));
        return -1;
	}
	lpc_init();

	//	Initialise LPC10 decoding

	lpc10init();
		
	//	Initialise CELP decoding
		
#ifndef CELP_USE_CONTEXT
	celp_init(FALSE);
#endif

	//	Initialise simple (2X) compression

	rate_start(&xrate, 8000, 4000);
    
    //	Initialise DES

#ifdef CRYPTO    
    desinit(1);
#endif    
    
    //	Initialise RTP randomised parameters

	sessionKeyGenerate(md5key, TRUE);
	memcpy((char *) &ssrc, md5key, sizeof ssrc);
	memcpy((char *) &timestamp, md5key + sizeof ssrc,
		  sizeof timestamp);
	memcpy((char *) &seq, md5key + sizeof ssrc + sizeof timestamp,
		  sizeof seq);
	memcpy((char *) &rtpdesrand, md5key + sizeof ssrc + sizeof timestamp +
		  sizeof seq, sizeof rtpdesrand);

    //  Create the MDI client window

    ccs.hWindowMenu  = GetSubMenu(GetMenu(hwnd), 3);	// Identify Window menu
    ccs.idFirstChild = IDM_WINDOW_FIRST_CHILD;

    hwndMDIClient = CreateWindow(pszMDIClientClass, NULL,
                                 WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL | WS_HSCROLL,
                                 0, 0, 0, 0, hwnd, 0, hInst, (LPSTR) &ccs);

    if (hwndMDIClient == NULL) {
        return -1;
    }

    ShowWindow(hwndMDIClient, winShowMode);
   
    //	Load remembered recent connections
    
	strcpy(pfn, rstring(IDS_PF_PROFILE_FILE));
    strcpy(cg, rstring(IDS_PF_CONNECTIONS));
    rememberedConnections = GetPrivateProfileInt(cg, rstring(IDS_PF_CONNCOUNT),
    	0, pfn);
    if (rememberedConnections > REMEMBER_CONNECTIONS) {
    	rememberedConnections = REMEMBER_CONNECTIONS;
    }
    for (i = j = 0; i < rememberedConnections; i++) {
    	char psn[12], rcr[MAX_HOST];
    	
    	wsprintf(psn, Format(2), i + 1);
    	GetPrivateProfileString(cg, psn, "", rcr,
    		sizeof rcr, pfn);
    	if (strlen(rcr) > 0) {
    		LPSTR rcon = (LPSTR) GlobalAllocPtr(GPTR, strlen(rcr) + 1);
    		
    		if (rcon!= NULL) {
    			strcpy(rcon, rcr);
    			rememberedConnection[j++] = rcon;
    		} 
    	} 
    }
    rememberedConnections = j;
    
#ifdef IP_MAX_MEMBERSHIPS
    
    //	Restore multicast group memberships
    
    strcpy(cg, rstring(IDS_PF_MULTIGROUPS));
    multiMemberships = GetPrivateProfileInt(cg, rstring(IDS_PF_CONNCOUNT),
    	0, pfn);
    if (multiMemberships > IP_MAX_MEMBERSHIPS) {
    	multiMemberships = IP_MAX_MEMBERSHIPS;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -