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

📄 connect.c

📁 g729 coding ipaddressing
💻 C
📖 第 1 页 / 共 5 页
字号:
    	pClientData->timeout = 0;
    }
    pClientData->cbSent = 0L;

    //  Try to open it

    hFile = _lopen(pszFile, OF_READ | OF_SHARE_DENY_WRITE);

    if (hFile == HFILE_ERROR) {
        //  Error opening file

        MsgBox(hwnd, MB_ICONSTOP | MB_OK, Format(25),
                pszFile, (LPSTR) pClientData->szHost);
        goto FatalError;
    }
    _lread(hFile, magic, sizeof(long));
    
    /* See if it's a chunky, wavy RIFF.  If so, delegate
       handling of the file to the multimedia I/O package. */
       
	if (memcmp(magic, "RIFF", 4) == 0) {
		_lclose(hFile);
		if (!readWaveInit(hwnd, pClientData, pszFile)) {
			return;
		}
	} else {
	
	    /* If the file has a Sun .au file header, skip it.
	       Note that we still blithely assume the file is
	       8-bit ISDN u-law encoded at 8000 samples per
	       second. */
	
	    if (memcmp(magic, ".snd", 4) == 0) {
	        long startpos;
	
	        _lread(hFile, &startpos, sizeof(long));
	        revlong(&startpos);
	        _llseek(hFile, startpos, 0);
	    } else {
	        _llseek(hFile, 0L, 0);
	    }
	    pClientData->hFile = hFile;
    }
    
    pClientData->state = Transferring;
    spurt = TRUE;						// Consider sound file a "talk spurt"
    if (pClientData->timeout > 0) {
    	pClientData->timeout = 0;
    }

#ifdef SHOW_STATE
    InvalidateRect(hwnd, NULL, TRUE);
    UpdateWindow(hwnd);
#endif    
    DragAcceptFiles(hwnd, FALSE);
    if (SetTimer(hwnd, 2, 200, NULL) == 0) {
        MsgBox(NULL, MB_ICONSTOP | MB_OK, Format(26));
    }
    return;

FatalError:
    if (hFile != HFILE_ERROR) {
        _lclose(hFile);
    }
}

/*  FILEDROPPED  --  Handle file dropped in connection window.  */

static VOID fileDropped(HWND hwnd, HDROP hdrop)
{
    LPCLIENT_DATA pClientData;
    
    pClientData = CLIENTPTR(hwnd);

    //  Retrieve the dropped file

    DragQueryFile(hdrop, 0, pClientData->szFile, sizeof(pClientData->szFile));
    DragFinish(hdrop);
    
    //	Start output
    
    startSoundFile(hwnd, pClientData->szFile); 
}

/*  STATETOSTRING  --  Convert state value to string.  */

static LPSTR stateToString(CLIENT_STATE state)
{
    LPSTR pszResult;

    switch (state) {
	    case Embryonic:
	        pszResult = rstring(IDS_T_INITIALISING);
	        break;
	
	    case Idle:
	        pszResult = rstring(IDS_T_IDLE);
	        break;
	
	    case SendingLiveAudio:
	        pszResult = rstring(IDS_T_SENDING_LIVE);
	        break;
	
	    case Transferring:
	        pszResult = rstring(IDS_T_SENDING_FILE);
	        break;
	
	    case PlayingReceivedAudio:
	        pszResult = rstring(IDS_T_PLAYING_AUDIO);
	        break;
	
	    default:
	        pszResult = rstring(IDS_T_UNKNOWN);
	        break;
    }
    return pszResult;
}

/*  CONNECT_WNDPROC  --  Connection main window procedure.  */

LRESULT CALLBACK connectWndProc(HWND hwnd, UINT nMessage, WPARAM wParam, LPARAM lParam)
{
    LPCLIENT_DATA pClientData;

    pClientData = CLIENTPTR(hwnd);
    
    switch (nMessage) {
        
    	case WM_CHAR:
    		if (wParam == ' ') {
    			if (pClientData != NULL) {
    				if (!pClientData->wantsInput) {
    					goto spacebarOn;
    				} else {
    					goto spacebarOff;
    				}
    			}	
    		}
    		return 0;
        
        case WM_CLOSE:
        	/*	Mark the window closed at the request of the user.
        		We set the "Lazarus timer" running which prevents
        		the connection being remotely re-opened until the
        		timer expires.  */
        	if (pClientData != NULL) {
				Lazarus = pClientData->inetSock.sin_addr.s_addr;
				LazarusLong = LazarusLength;
			}
		    FORWARD_WM_CLOSE(hwnd, DefMDIChildProc);
        	return 0;
        	
        case WM_CREATE:
#ifdef TRACE_FACE
			OutputDebugString("Connection WM_CREATE()\r\n");
#endif
        	SetFocus(hwnd);
        	break;
        
        case WM_DESTROY:
        	if (pClientData != NULL) {
        		SendMessage(hwnd, WM_CLEAN_UP_YOUR_ACT, 0, 0L);
			}        
        	return 0;
        
        case WM_CLEAN_UP_YOUR_ACT:
        	if (pClientData != NULL) {
    			if (pClientData->wantsInput && --listeners <= 0) {
		        	terminateWaveInput();
					inputPaused = FALSE;
		        	listeners = 0;
		        }
        		gsm_destroy(pClientData->gsmh);
        		if (pClientData->hFile != HFILE_ERROR ||
			    	pClientData->mmioHandle != NULL) {
	        		KillTimer(hwnd, 2);
	        		if (pClientData->hFile != HFILE_ERROR) {
	        			_lclose(pClientData->hFile);
	        		}
	    			readWaveTerm(pClientData);
	        	}
	        	
	        	if (pClientData->pgpFileName[0] != 0) {
	        		KillTimer(hwnd, 3);				// Kill timer for incomplete PGP poll
	        		// T'would be nice to clean up the temp files here as well.
	        	}
	        	
	        	if (pClientData->opgpFileName[0] != 0) {
	        		KillTimer(hwnd, 4);				// Kill timer for incomplete PGP poll
	        		// T'would be nice to clean up the temp files here as well.
	        	}
	        	
	        	if (pClientData->face_stat == FSrequest ||
	        		pClientData->face_stat == FSreply) {
	        		KillTimer(hwnd, 5);				// Kill timer for incomplete face image
	        	}
	        	if (pClientData->face_bmp != NULL) {
	        		GlobalFreePtr(pClientData->face_bmp);	// Release face bitmap
	        	}
	        	
	        	/*	If we're transmitting in RTP or VAT protocol, send a
	        		Bye/Done message to indicate the connection's been
	        		closed.  */
	        	
	        	if (pClientData->sControl != INVALID_SOCKET) {
	        		unsigned char byebye[128];
	        		int byel;
	        		
	        		pClientData->sendSDEStimer = TIMEOUT_RESEND_SDES;
	        		if (protocolSent == PROTOCOL_RTP || protocolSent == PROTOCOL_SPEAKFREE) {
	        			byel = rtp_make_bye(byebye, ssrc, rstring(IDS_T_RAISON_CLOSING), TRUE);
	        			if (protocolSent == PROTOCOL_SPEAKFREE) {
	        				byebye[0] = (unsigned char) ((byebye[0] & 0x3F) | (1 << 6));
	        			}
	        		} else {
	        			byel = makevatdone(byebye, 0L);
	        		}
	        		if (!((protocolSent == PROTOCOL_SPEAKFREE) && waProtNoHeartbeat)) {
	        			sendSessionCtrl(pClientData, byebye, byel);
	        		}
	        	}
			    if (pClientData->sReply != INVALID_SOCKET) {
			        ResetSocket(pClientData->sReply);
			        pClientData->sReply = INVALID_SOCKET;
			    }
			    if (pClientData->sControl != INVALID_SOCKET) {
				    LINGER linger;
				
				    /*  Enable linger with a timeout of one second.  This 
				  		should, in theory, allow the BYE message to go out
				  		before the socket is closed.  Why not use the
				  		"graceful disconnect" mechanism?  Because there are
				  		WINSOCKs out there that don't do it right.  */
				
				    linger.l_onoff  = TRUE;
				    linger.l_linger = 1;
				
				    setsockopt(pClientData->sControl, SOL_SOCKET, SO_LINGER, (CHAR *) &linger, sizeof(linger));
				    closesocket(pClientData->sControl);
			        pClientData->sControl = INVALID_SOCKET;
			    }

				/*	If we're listening on a nonstandard channel, decrement
					the reference count on the auxiliary socket pair and
					close if it's zero.  */
					
				if (pClientData->auxSock != NULL) {
					if (--pClientData->auxSock->asrefc == 0) {
#ifdef TRACE_AUX_SOCKET
OutputDebugString("Closing aux socket.\r\n");
#endif					
				        ResetSocket(pClientData->auxSock->asdata);
				        pClientData->auxSock->asdata = INVALID_SOCKET;
				        ResetSocket(pClientData->auxSock->asctrl);
				        pClientData->auxSock->asctrl = INVALID_SOCKET;
					}
				}
			
			    if (pClientData->hFile != HFILE_ERROR) {
			        _lclose(pClientData->hFile);
			        pClientData->hFile = HFILE_ERROR;
			    }
			
#ifdef MODEM
	        	if (pClientData->modemConnection) {
	        		modemSessions--;
	        	}
#endif	        	
	        	
	        	if (pClientData->getNameTask != NULL) {
	        		WSACancelAsyncRequest(pClientData->getNameTask);
	        		pClientData->getNameTask = NULL;	
	        	}
	        	
				if (pClientData->uname != NULL) {
					GlobalFreePtr(pClientData->uname);
					pClientData->uname = NULL;
				}

				if (pClientData->d_celp_ctx != NULL) {	// Release CELP decoding context if allocated
					GlobalFreePtr(pClientData->d_celp_ctx);
					pClientData->d_celp_ctx = NULL;
				}

        		loop_flush(pClientData);				// Flush any queued local loopback data
	        	
        		GlobalFreePtr(pClientData);
        		SetWindowLong(hwnd, GWL_CLIENT, 0L);
			    openConnections--;
				propUpdateAudio();
				updateTrayToolTipText();
	        }
        	return 0;
        	
        case WM_DROPFILES:
        	if (pClientData != NULL && !broadcasting) {
				pClientData->timeout = -1;	// Send file immortalises connection
				fileDropped(hwnd, (HDROP) wParam);
        	}
        	break;

#ifdef GATES_OF_HELL

		/* Well, golly, I though it would be kinda nice to keep
		   the user from inflating the connection window larger than
		   the face image in it--doing so only wastes screen
		   real estate, after all.  Little did I know that by trying
		   to do so (at least with an MDI window), I stuck my toe
		   back into the tree chipper and caused all kinds of
		   things to let go--window size changing when iconised
		   and reactivated, the "disappearing minimise button
		   syndrome", etc. etc.  The Developer CD serves up the
		   usual crop of incoherent blithering.  I give up--go
		   ahead and make the bloody window as big as Siberia
		   if you like. */
        	
        case WM_GETMINMAXINFO:
    		if (pClientData != NULL && pClientData->face_shown) {
    			MINMAXINFO *mm = (MINMAXINFO *) lParam;
				BITMAPINFOHEADER *bmi;
			    RECT cr, wr;
            			
			    GetWindowRect(hwnd, &wr);
			    GetClientRect(hwnd, &cr);
	                        
	            bmi = (BITMAPINFOHEADER *) (pClientData->face_bmp + sizeof(BITMAPFILEHEADER));
    			
    			//	Don't allow resize of window larger than face

    			mm->ptMaxSize.x = mm->ptMaxTrackSize.x = ((int) bmi->biWidth) + ((wr.right - wr.left) - cr.right); 
    			mm->ptMaxSize.x = mm->ptMaxTrackSize.y = ((int) bmi->biHeight) + ((wr.bottom - wr.top) - cr.bottom); 
    		} 
        	break;
#endif        	
        	
        case WM_LBUTTONDBLCLK:
			if (pClientData != NULL && pClientData->wantsInput == TRUE) {
				pClientData->wantsInput = 2;
	        	if (pClientData->buttonUpTimer) {
	        		KillTimer(hwnd, 8);
	        		pClientData->buttonUpTimer = FALSE;
	        	}
				break;
			}        
        case WM_LBUTTONDOWN:
spacebarOn: if (pClientData != NULL && !pClientData->wantsInput && !broadcasting) {
	        	if (listeners == 0) {
					inputPaused = FALSE;
		        	if (!startWaveInput(hwnd)) {
		        		//	Couldn't turn on wave audio input
		        		break;
		        	}
		        }
	        	if (pClientData->buttonUpTimer) {
	        		KillTimer(hwnd, 8);
	        		pClientData->buttonUpTimer = FALSE;
	        	}
		        spurt = TRUE;				// Mark start of talk spurt
		        loop_flush(pClientData);	// Flush any unplayed local loop packets
	        	pClientData->wantsInput = (nMessage == WM_LBUTTONDBLCLK) ? 2 : TRUE;
		        listeners++;
		        pClientData->timeout = -1;	// Send audio immortalises connection
		        pClientData->state = SendingLiveAudio;
	        	SetCursor(earCursor);
	        	changeAudioState(hwnd, pClientData);
	        }
        	break;
        	
        case WM_LBUTTONUP:
        	if (pClientData != NULL && !broadcasting && !pClientData->buttonUpTimer) {
        		SetTimer(hwnd, 8, GetDoubleClickTime(), NULL);
        		pClientData->buttonUpTimer = TRUE;
        		break;
        	}
        
spacebarOff:if (pClientData != NULL && !broadcasting) {
	        	if (pClientData->wantsInput == TRUE) {
		        	pClientData->wantsInput = FALSE;
			        pClientData->state = pClientData->hFile != HFILE_ERROR ?
			        	Transferring : Idle;
		        	SetCursor(phoneCursor);
	        		changeAudioState(hwnd, pClientData);
	    			if (--listeners <= 0) {
			        	terminateWaveInput();
						inputPaused = FALSE;
			        	listeners = 0;
			        }

			    /* If this the button-up following a double click, don't
			       turn off listening.  This allows a double click to latch
			       input mode for a window. */
		        } else if (pClientData->wantsInput == 2) {
		        	pClientData->wantsInput = TRUE;
		        	if (pClientData->buttonUpTimer) {
		        		pClientData->buttonUpTimer = FALSE;
		        		KillTimer(hwnd, 8);
		        	}
		        	SetCursor(earCursor);
	    			UpdateWindow(hwnd);
		        }
	        } 
        	break;
        	

⌨️ 快捷键说明

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