📄 frame.c
字号:
the 80 metre band in 1935--mute the receiver and
blast on our carrier regardless. */
V waveOutReset(hWaveOut);
halfDuplex = TRUE; // Indicate wave output swiped
if (outputPending) {
halfDuplexTransition = TRUE;
propUpdateAudio();
return TRUE;
} else {
V waveOutClose(hWaveOut);
outputActive = FALSE;
propUpdateAudio();
}
continue;
}
waveInGetErrorText(woo, et, sizeof et);
MessageBox(hwnd, et,
rstring(IDS_T_ERR_OPEN_WAVE_INPUT), MB_OK | MB_ICONEXCLAMATION);
return FALSE;
}
break;
}
/* Now allocate and prepare the sound input buffers. Don't
you just love the code vomit Windows' inability to free
resources when a program terminates creates? */
currentInputLength = inputBufferLength();
currentInputSamples = inputSampleCount();
for (i = 0; i < nWaveHeaders; i++) {
inWaveHeader[i] = NULL;
}
for (i = 0; i < nWaveHeaders; i++) {
inWaveHeader[i] = (LPWAVEHDR) GlobalAllocPtr(GMEM_MOVEABLE | GMEM_SHARE,
sizeof(WAVEHDR));
if (inWaveHeader[i] == NULL) {
int j;
for (j = i - 1; j >= 0; j++) {
waveInUnprepareHeader(hWaveIn, inWaveHeader[j], sizeof(WAVEHDR));
GlobalFreePtr(inWaveHeader[j]->lpData);
GlobalFreePtr(inWaveHeader[j]);
inWaveHeader[j] = NULL;
}
MessageBox(hwnd, rstring(IDS_T_INPUT_HEADER_ERR),
NULL, MB_OK | MB_ICONEXCLAMATION);
waveInClose(hWaveIn);
return FALSE;
}
/* Since the user is allowed to change the sample size
and compression modes on the fly, but the audio input
buffers are used for the entire run of the program, we
allocate them for the worst-case scenario: both LPC and
2X compression enabled with 16 bit samples. We've already
established whether the hardware can run at 8000 samples
per second, so only allocate the larger buffer needed for
11025 sample per second hardware if it's actually required. */
inWaveHeader[i]->lpData = (LPSTR) GlobalAllocPtr(GMEM_MOVEABLE | GMEM_SHARE,
(DWORD) ((samplesPerSecond == 8000) ? 7200 : 10000));
if (inWaveHeader[i]->lpData == NULL) {
int j;
GlobalFreePtr(inWaveHeader[i]);
inWaveHeader[i] = 0;
for (j = i - 1; j >= 0; j++) {
waveInUnprepareHeader(hWaveIn, inWaveHeader[j], sizeof(WAVEHDR));
GlobalFreePtr(inWaveHeader[j]->lpData);
GlobalFreePtr(inWaveHeader[j]);
inWaveHeader[j] = NULL;
}
MessageBox(hwnd, rstring(IDS_T_INPUT_BUFFER_ERR),
NULL, MB_OK | MB_ICONEXCLAMATION);
waveInClose(hWaveIn);
return FALSE;
}
inWaveHeader[i]->dwBufferLength = currentInputLength;
inWaveHeader[i]->dwFlags = 0;
waveInPrepareHeader(hWaveIn, inWaveHeader[i], sizeof(WAVEHDR));
}
waveHeadersAllocated = nWaveHeaders;
for (i = 0; i < nWaveHeaders; i++) {
waveInAddBuffer(hWaveIn, inWaveHeader[i], sizeof(WAVEHDR));
}
inputTerm = FALSE;
waveInStart(hWaveIn);
inputActive = TRUE;
aboutInSamples = samplesPerSecond;
aboutInBits = bitsPerSample;
propUpdateAudio();
}
return TRUE;
}
/* TERMINATEWAVEINPUT -- Shut down wave input and release all
resources associated with it. */
void terminateWaveInput(void)
{
if (inputActive) {
int i;
inputTerm = TRUE;
waveInReset(hWaveIn);
#ifdef OLDWAY
for (i = 0; i < nWaveHeaders; i++) {
if (inWaveHeader[i] != NULL) {
waveInUnprepareHeader(hWaveIn, inWaveHeader[i], sizeof(WAVEHDR));
if (inWaveHeader[i]->lpData != NULL) {
GlobalFreePtr(inWaveHeader[i]->lpData);
}
GlobalFreePtr(inWaveHeader[i]);
inWaveHeader[i] = NULL;
}
}
#else
for (i = 0; i < nWaveHeaders; i++) {
inWaveHeader[i] = NULL;
}
#endif
// waveInClose(hWaveIn);
// hWaveIn = NULL;
// inputActive = FALSE;
// propUpdateAudio();
#ifdef TRYTHIS
while (inputActive) {
MSG msg;
while (GetMessage(&msg, NULL, 0, 0)) {
extern void MessageLoop(MSG FAR *pmsg);
MessageLoop(&msg);
}
}
#endif
}
}
/* REMEMBERNEWCONNECTION -- Add a connection file name to the list
of remembered connections. If it's
already in the list, promote it to the
first item. */
static void rememberNewConnection(LPSTR connectionFile)
{
int i;
LPSTR hostSave;
/* See if the connection file already appears in the list
of recent connections. If so, delete it from the list. */
hostSave = GlobalAllocPtr(GPTR, strlen(connectionFile) + 1);
strcpy(hostSave, connectionFile);
/* Careful! Be sure not to reference connectionFile beyond
this point, since if we're re-opening a remembered
connection the following loop may (in fact almost certainly
will) cause it to be deallocated. */
if (hostSave != NULL) {
for (i = 0; i < rememberedConnections; i++) {
if (_stricmp(hostSave, rememberedConnection[i]) == 0) {
int j;
GlobalFreePtr(rememberedConnection[i]);
for (j = i + 1; j < rememberedConnections; j++) {
rememberedConnection[j - 1] = rememberedConnection[j];
}
rememberedConnections--;
}
}
// Push the list of remembered connections and add this one
if (rememberedConnections == REMEMBER_CONNECTIONS) {
GlobalFreePtr(rememberedConnection[REMEMBER_CONNECTIONS - 1]);
rememberedConnections--;
}
for (i = REMEMBER_CONNECTIONS - 1; i >= 1; i--) {
rememberedConnection[i] = rememberedConnection[i - 1];
}
rememberedConnection[0] = hostSave;
rememberedConnections++;
}
}
/* NEWCONNECTION -- Initiate a connection to a given named
host. If there's already a connection
to this host active, activate its window. */
VOID newConnection(HWND hwnd, LPSTR connectionFile, LPSTR knownHost)
{
CHAR szHostName[MAX_HOST];
SOCKADDR_IN sockHost;
#define addrHost sockHost.sin_addr
LPCLIENT_DATA pClientData = NULL;
HWND hwndClient;
unsigned short port;
char *cg;
// Prompt the user for a new host
if (connectionFile == NULL) {
if (knownHost == NULL) {
if (!newHostDialogue(hwndMDIFrame, szHostName, &addrHost, &port)) {
return;
}
} else {
char *cp;
long iport;
char cb[MAX_HOST];
strcpy(cb, knownHost);
if ((cp = strchr(cb, '/')) != NULL ||
(cp = strchr(cb, ':')) != NULL) {
iport = atol(cp + 1);
if (iport <= 0) {
MsgBox(hwnd, MB_ICONSTOP | MB_OK, Format(72), *cp);
return;
}
port = (unsigned short) iport;
*cp = 0;
} else {
port = NETFONE_COMMAND_PORT;
}
wsprintf(szHostName, Format(61), (LPSTR) cb);
addrHost.s_addr = inet_addr(cb);
}
} else {
char inetAddr[64];
/* If the connection file contains a host name and IP address
(which will be the case for any file we write), use them as
given. If only a host name is present, try to find the IP
address with gethostbyname(). This is primarily intended for
programs which wish to launch Speak Freely to contact a host
with known name but unknown IP address. I'm sure the next turn
of the screw will have us doing it the other way around as
well. */
cg = rstring(IDS_PF_HOST);
if (GetPrivateProfileString(cg, rstring(IDS_PF_HOST_NAME), "", szHostName,
sizeof szHostName, connectionFile) == 0) {
MessageBox(hwnd, rstring(IDS_T_CONN_PROFILE_INVALID), connectionFile,
MB_OK | MB_ICONEXCLAMATION);
return;
} else {
if (GetPrivateProfileString(cg, rstring(IDS_PF_NETADDR), "", inetAddr,
sizeof inetAddr, connectionFile) == 0 ||
(addrHost.s_addr = inet_addr(inetAddr)) == INADDR_NONE) {
LPHOSTENT h = gethostbyname(szHostName);
if (h == NULL) {
int serr = WSAGetLastError();
MsgBox(hwnd, MB_ICONSTOP | MB_OK, Format(41),
(LPSTR) szHostName,
serr, SockerrToString(serr));
return;
} else {
struct in_addr newaddr;
newaddr = *((LPIN_ADDR) h->h_addr);
memcpy(&addrHost.s_addr, (h->h_addr),
sizeof addrHost.s_addr);
}
}
port = GetPrivateProfileInt(cg, rstring(IDS_PF_PORT_NUMBER),
NETFONE_COMMAND_PORT, connectionFile);
}
}
/* See if there's already a client window communicating with
this host. Use equality of IP number and port as the criterion to
prevent spoofing due to aliases. */
sockHost.sin_port = htons(port);
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;
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);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -