📄 ip.cpp
字号:
/*____________________________________________________________________________*\
*
Copyright (c) 1997-2003 John Roy, Holger Zimmermann. All rights reserved.
These sources, libraries and applications are
FREE FOR COMMERCIAL AND NON-COMMERCIAL USE
as long as the following conditions are adhered to.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHORS OR ITS CONTRIBUTORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
OF THE POSSIBILITY OF SUCH DAMAGE.
*____________________________________________________________________________*|
*
* $Source: /cvsroot/pi3web/Pi3Web_200/Source/EnhPi3/IP.cpp,v $
* $Date: 2003/05/13 18:41:58 $
*
Description:
Hastily thrown together configuration page for IP virtual hosts.
\*____________________________________________________________________________*/
/* $SourceTop:$ */
#include <windows.h>
#include <windowsx.h>
#include <commctrl.h>
#include <assert.h>
#include "DblList.h"
#include "PIString.h"
#include "resrc1.h"
#include "Dialogs.h"
#include "Config.h"
#include "PIUtil.h"
/*____________________________________________________________________________*\
*
Description:
Definitions and global values
\*____________________________________________________________________________*/
static HWND hWndList = 0;
static HWND hWndIPAddress = 0;
static HWND hWndHostname = 0;
static HWND hWndDocumentRoot = 0;
static HWND hWndAdd = 0;
static HWND hWndReplace = 0;
static HWND hWndDelete = 0;
static HWND hWndAdministrator = 0;
static DblList lIPs;
static DblList lHostnames;
static DblList lDocumentRoots;
static DblList lAdministrators;
#define SECTION "VirtualHosts"
#define VARIABLE "IP"
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
\*____________________________________________________________________________*/
static int Internal_verifyFields( HWND hDlg, char *pszBuf, int iBufSize )
{
int iToLen;
/*
** Get the 'To' field
*/
SendMessage( hWndDocumentRoot, WM_GETTEXT, iBufSize, (LPARAM)pszBuf );
/*
** 'DocumentRoot' field must end with '/'
*/
assert( *pszBuf );
iToLen = strlen(pszBuf);
if ( pszBuf[iToLen-1]!='/' && pszBuf[iToLen-1]!='\\' )
{
MessageBox( hDlg, "'DocumentRoot' field must end with a forward-slash ('/') \
or a backslash ('\\').",
"Error in 'DocumentRoot' Field", MB_OK | MB_ICONEXCLAMATION );
::SetFocus( hWndDocumentRoot );
::SendMessage( hWndDocumentRoot, EM_SETSEL, (WPARAM)(INT)0, (LPARAM)(INT)-1 );
goto verify_fail;
};
/*
** Good
*/
return 1;
verify_fail:
return 0;
}
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
\*____________________________________________________________________________*/
static void Internal_addLine( const char *pLine )
{
assert( pLine );
assert( lIPs.Size()==lHostnames.Size() );
assert( lHostnames.Size()==lDocumentRoots.Size() );
assert( lDocumentRoots.Size()==lAdministrators.Size() );
int i, j;
i = 0;
for( ; pLine[i] && isspace(pLine[i]); i++ );
j = i;
for( ; pLine[i] && !isspace(pLine[i]); i++ );
/* --- scan to tab --- */
lIPs.Append( (DblList::type)PI_NEW( PIString( &(pLine[j]), i-j)));
/* --- scan over whitespace to start of second field --- */
for( ; pLine[i] && isspace(pLine[i]); i++ );
j = i;
for( ; pLine[i] && !isspace(pLine[i]); i++ );
lHostnames.Append((DblList::type)PI_NEW( PIString( &(pLine[j]), i-j)));
/* --- scan over whitespace to start of second field --- */
for( ; pLine[i] && isspace(pLine[i]); i++ );
j = i;
for( ; pLine[i] && !isspace(pLine[i]); i++ );
lDocumentRoots.Append((DblList::type)PI_NEW( PIString( &(pLine[j]), i-j)));
/* --- scan over whitespace to start of third field --- */
for( ; pLine[i] && isspace(pLine[i]); i++ );
j = i;
for( ; pLine[i] && !isspace(pLine[i]); i++ );
lAdministrators.Append((DblList::type)PI_NEW( PIString( &(pLine[j]), i-j)));
assert( lIPs.Size()==lHostnames.Size() );
assert( lHostnames.Size()==lDocumentRoots.Size() );
assert( lDocumentRoots.Size()==lAdministrators.Size() );
}
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
\*____________________________________________________________________________*/
static void Internal_clearArrays()
{
DblListIterator w( lIPs );
DblListIterator x( lHostnames );
DblListIterator y( lDocumentRoots );
DblListIterator z( lAdministrators );
for( ; !x.BadIndex(); w++, x++, y++, z++ )
{
assert( !w.BadIndex() && !x.BadIndex() && !y.BadIndex() && !z.BadIndex() );
PI_DELETE( (PIString *)w.Current() );
PI_DELETE( (PIString *)x.Current() );
PI_DELETE( (PIString *)y.Current() );
PI_DELETE( (PIString *)z.Current() );
};
lIPs.Clear();
lHostnames.Clear();
lDocumentRoots.Clear();
lAdministrators.Clear();
}
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
\*____________________________________________________________________________*/
static void Internal_reloadArrays()
{
enum { BUF_SIZE=2047 };
char szBuf[BUF_SIZE+1];
Internal_clearArrays();
/*
** Get number of items
*/
int iCount = SendMessage( hWndList, LB_GETCOUNT, 0, 0 );
/*
** Insert from listbox into internal arrays
*/
int i;
for( i=0; i<iCount; i++ )
{
SendMessage( hWndList, LB_GETTEXT, i, (LPARAM)szBuf );
Internal_addLine( szBuf );
};
}
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
\*____________________________________________________________________________*/
static void Internal_updateButtons( WPARAM wParam, LPARAM lParam,
HWND hWndEdit1, HWND hWndEdit2, const char *pData )
{
if ( GET_WM_COMMAND_CMD(wParam, lParam)!=EN_CHANGE )
{ return; };
int iExistingIndex = -1;
assert( pData );
int iChangeToIndex = -1;
int iIndex = 0;
if ( *pData )
{
for( DblListIterator i( lIPs ); !i.BadIndex(); i++, iIndex++ )
{
PIString *pString = (PIString *)i.Current();
assert( pString );
if ( !PIUtil_strncmpi( (*pString), pData, strlen( pData ) ) )
{
iChangeToIndex = iIndex;
/*
** If this is a full index, select it
*/
if ( !stricmp( (*pString), pData ) )
{ iExistingIndex = iIndex; };
break;
};
};
};
/*
** Remove listbox selection or scroll to correct line
** as appropriate
*/
SendMessage( hWndList, LB_SETCURSEL, iChangeToIndex, 0 );
/*
** Set buttons
*/
if ( ::SendMessage( hWndEdit1, EM_LINELENGTH, 0, 0 )==0 ||
::SendMessage( hWndDocumentRoot, EM_LINELENGTH, 0, 0 )==0 ||
::SendMessage( hWndAdministrator, EM_LINELENGTH, 0, 0 )==0 )
{
if ( IsWindowEnabled( hWndAdd ) ) EnableWindow( hWndAdd, FALSE );
if ( IsWindowEnabled( hWndReplace ) ) EnableWindow( hWndReplace, FALSE );
}
else if ( SendMessage( hWndEdit2, EM_LINELENGTH, 0, 0 )!=0 )
{
if ( iExistingIndex>-1 ) /* --- disable add, enable replace --- */
{
if ( IsWindowEnabled( hWndAdd ) ) EnableWindow( hWndAdd, FALSE );
if ( !IsWindowEnabled( hWndReplace ) ) EnableWindow( hWndReplace, TRUE );
}
else /* --- disable replace, enable add --- */
{
if ( !IsWindowEnabled( hWndAdd ) ) EnableWindow( hWndAdd, TRUE );
if ( IsWindowEnabled( hWndReplace ) ) EnableWindow( hWndReplace, FALSE );
};
};
/*
** If there is a selected item in the listbox then
** enable delete, otherwise disable delete
*/
if ( SendMessage( hWndList, LB_GETCURSEL, 0, 0 )==LB_ERR )
{ EnableWindow( hWndDelete, FALSE ); }
else
{ EnableWindow( hWndDelete, TRUE ); };
}
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
\*____________________________________________________________________________*/
static BOOL CALLBACK DialogProc(HWND hDlg, UINT uMsg, WPARAM wParam,
LPARAM lParam)
{
enum { BUF_SIZE=1023 };
char szBuf[BUF_SIZE+1];
int aTabstop[4];
switch (uMsg)
{
case WM_INITDIALOG:
AD_hourglassOn();
{
const char *pTmp;
int iTmp;
hWndList = GetDlgItem( hDlg, IDC_LIST );
hWndIPAddress = GetDlgItem( hDlg, IDC_IPADDRESS );
hWndHostname = GetDlgItem( hDlg, IDC_HOSTNAME );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -