📄 pi3file.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/Intrface/Pi3File.cpp,v $
* $Date: 2004/08/01 19:39:00 $
*
Description:
\*____________________________________________________________________________*/
/* $SourceTop:$ */
#include <assert.h>
#include <fstream.h>
#include <ctype.h>
#include "PIString.h"
#include "Pi3File.h"
#include "MiscUtil.h"
/*
** #define D { cerr << __FILE__ << ": " << __LINE__ << endl; }
*/
#define D
/*____________________________________________________________________________*\
*
Description:
\*____________________________________________________________________________*/
#define SECTION_START "+++---AD Section Start, Do not Modify:"
#define SECTION_END "+++---AD Section End---+++"
#define NOTMODIFIED_START "+++---AD Saved Section, modifications will be retained---+++"
#define NOTMODIFIED_END "+++---AD Saved section end---+++"
#define GENERATED_START "+++---AD Generated Section, modifications will be lost---+++"
#define GENERATED_END "+++---AD Generated section end---+++"
/*____________________________________________________________________________*\
*
Description:
Directory index layout names
\*____________________________________________________________________________*/
static const char *__pLayoutNames[] =
{
"HTML table",
"HTML index with fixed font",
"Generic HTML index",
"DOS style HTML index",
"Plain text with Tabs",
"Customized index is used",
/* --- leave this last --- */
0
};
/*____________________________________________________________________________*\
*
Description:
Default MIME Types
\*____________________________________________________________________________*/
static const char *__pMIMETypes[] =
{
"xls\tapplication/msexcel",
"xlt\tapplication/msexcel",
"doc\tapplication/msword",
"bin\tapplication/octet-stream",
"dms\tapplication/octet-stream",
"lha\tapplication/octet-stream",
"lzh\tapplication/octet-stream",
"exe\tapplication/octet-stream",
"class\tapplication/octet-stream",
"oda\tapplication/oda",
"pdf\tapplication/pdf",
"ai\tapplication/postscript",
"eps\tapplication/postscript",
"ps\tapplication/postscript",
"ppt\tapplication/powerpoint",
"rtf\tapplication/rtf",
"bcpio\tapplication/x-bcpio",
"vcd\tapplication/x-cdlink",
"cpio\tapplication/x-cpio",
"csh\tapplication/x-csh",
"dcr\tapplication/x-director",
"dir\tapplication/x-director",
"dxr\tapplication/x-director",
"dvi\tapplication/x-dvi",
"gtar\tapplication/x-gtar",
"gz\tapplication/x-gzip",
"hdf\tapplication/x-hdf",
"skp\tapplication/x-koan",
"skd\tapplication/x-koan",
"skt\tapplication/x-koan",
"skm\tapplication/x-koan",
"latex\tapplication/x-latex",
"mif\tapplication/x-mif",
"nc\tapplication/x-netcdf",
"cdf\tapplication/x-netcdf",
"sh\tapplication/x-sh",
"shar\tapplication/x-shar",
"sit\tapplication/x-stuffit",
"sv4cpio\tapplication/x-sv4cpio",
"sv4crc\tapplication/x-sv4crc",
"tar\tapplication/x-tar",
"tcl\tapplication/x-tcl",
"tex\tapplication/x-tex",
"texinfo\tapplication/x-texinfo",
"texi\tapplication/x-texinfo",
"t\tapplication/x-troff",
"troff\tapplication/x-troff",
"man\tapplication/x-troff-man",
"me\tapplication/x-troff-me",
"ms\tapplication/x-troff-ms",
"ustar\tapplication/x-ustar",
"uu\tapplication/x-uuencoded",
"src\tapplication/x-wais-source",
"zip\tapplication/zip",
"au\taudio/basic",
"snd\taudio/basic",
"mid\taudio/midi",
"midi\taudio/midi",
"kar\taudio/midi",
"mpga\taudio/mpeg",
"mp2\taudio/mpeg",
"aif\taudio/x-aiff",
"aiff\taudio/x-aiff",
"aifc\taudio/x-aiff",
"ram\taudio/x-pn-realaudio",
"rpm\taudio/x-pn-realaudio-plugin",
"ra\taudio/x-realaudio",
"wav\taudio/x-wav",
"pdb\tchemical/x-pdb",
"xyz\tchemical/x-pdb",
"gif\timage/gif",
"ief\timage/ief",
"jpeg\timage/jpeg",
"jpg\timage/jpeg",
"jpe\timage/jpeg",
"png\timage/png",
"tif\timage/tiff",
"tiff\timage/tiff",
"bmp\timage/x-MS-bmp",
"dip\timage/x-MS-bmp",
"ras\timage/x-cmu-raster",
"pnm\timage/x-portable-anymap",
"pbm\timage/x-portable-bitmap",
"pgm\timage/x-portable-graymap",
"ppm\timage/x-portable-pixmap",
"rgb\timage/x-rgb",
"xbm\timage/x-xbitmap",
"xpm\timage/x-xpixmap",
"xwd\timage/x-xwindowdump",
"htm\ttext/html",
"html\ttext/html",
"txt\ttext/plain",
"pi3\ttext/plain",
"rtx\ttext/richtext",
"tsv\ttext/tab-separated-values",
"etx\ttext/x-setext",
"sgm\ttext/x-sgml",
"sgml\ttext/x-sgml",
"c\ttext/x-code",
"cpp\ttext/x-code",
"cxx\ttext/x-code",
"cc\ttext/x-code",
"pm\ttext/x-perl",
"pl\ttext/x-perl",
"mpg\tvideo/mpeg",
"mpeg\tvideo/mpeg",
"mpe\tvideo/mpeg",
"mov\tvideo/quicktime",
"qt\tvideo/quicktime",
"avi\tvideo/x-msvideo",
"movie\tvideo/x-sgi-movie",
"ice\tx-conference/x-cooltalk",
"vrml\tx-world/x-vrml",
"wrl\tx-world/x-vrml",
"shtml\tinternal/x-server-parsed-html",
"html-ssi\tinternal/x-server-parsed-html",
"ssi\tinternal/x-server-parsed-html",
"fcgi\tinternal/x-fastcgi",
"map\tinternal/x-imagemap",
"imap\tinternal/x-imagemap",
"php\tinternal/x-server-parsed-php",
"php3\tinternal/x-server-parsed-php",
"php4\tinternal/x-server-parsed-php",
"psp\tinternal/x-server-parsed-psp",
"ppsp\tinternal/x-server-parsed-psp",
"jsp\tinternal/x-server-parsed-jsp",
"asp\tinternal/x-server-parsed-asp",
"cfm\tinternal/x-server-parsed-cfm",
"xml\tinternal/x-server-parsed-xml",
/* --- leave this last --- */
0
};
/*____________________________________________________________________________*\
*
Description:
Default Mappings
\*____________________________________________________________________________*/
static const char *__pMappings[] =
{
"CGI\t/cgi-bin/\tCgi-Bin\\\t(none)",
"Windows CGI\t/cgi-win/\tCgi-Win\\\t(none)",
"Fast CGI\t/cgi-fcgi/\tCgi-Fcgi\\\t(none)",
"Documents\t/pidocs/\tPi3Docs\\\t(none)",
"Documents\t/icons/\tIcons\\\t(none)",
"Documents\t/images/\tImages\\\t(none)",
"Documents\t/errors/\tFragment\\\t(none)",
"ISAPI\t/isapi/\tIsapi\\\t(none)",
"Documents\t/admin/\tLogs\\\tAdministration",
"Redirect\t/pi3site/\thttp://pi3web.sourceforge.net/\t(none)",
"Documents\t/\tWebRoot\\\t(none)",
/* --- leave this last --- */
0
};
/*____________________________________________________________________________*\
*
Description:
Default Logfiles
\*____________________________________________________________________________*/
static const char *__pLogfiles[] =
{
"Access (CLF)\tLogs\\Access.txt",
/* --- leave this last --- */
0
};
/*____________________________________________________________________________*\
*
Description:
\*____________________________________________________________________________*/
static const char *__pMappingTypes[]=
{
"Documents",
"CGI",
"Windows CGI",
"Fast CGI",
"ISAPI",
"Redirect",
0
};
/*____________________________________________________________________________*\
*
Description:
\*____________________________________________________________________________*/
static const char *__pIOTypes[]=
{
"TCP",
"SSL",
0
};
/*____________________________________________________________________________*\
*
Description:
\*____________________________________________________________________________*/
static const char *__pLoggingTypes[]=
{
"Access (CLF)",
"Referer Logfile",
0
};
/*____________________________________________________________________________*\
*
Description:
\*____________________________________________________________________________*/
static const char *__pIndexFiles[]=
{
"index.ssi",
"index.html",
"index.htm",
"default.ssi",
"default.htm",
"default.html",
/* --- leave this last --- */
0
};
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
\*____________________________________________________________________________*/
void Internal_setupDefaults( QConfig *pConfig )
{
#define AD_DEFAULT(x,y,z) \
{ \
if ( !M_LookupValue( pConfig, x, y ) ) \
{ M_ReplaceValue( pConfig, x, y, z ); }; \
}
/*
** Internal values for allowing extensions.
*/
AD_DEFAULT( "Internal", "URLProtocol", "http://" );
AD_DEFAULT( "Internal", "DefaultPort", "80" );
AD_DEFAULT( "Internal", "ServerIOObjectLine", "\tIOObject ServerIOObject" );
AD_DEFAULT( "Internal", "DefaultMIMEType", "application/octet-stream" );
AD_DEFAULT( "Internal", "HandlerLine", DEFAULT_HANDLERS );
/*
** Identity defaults
*/
AD_DEFAULT( "Identity", "Use", "local" );
AD_DEFAULT( "General", "Port", "80" );
AD_DEFAULT( "General", "Host", "localhost" );
/*
** General and performance defaults
*/
AD_DEFAULT( "General", "Processes", "8" );
AD_DEFAULT( "General", "Threads", "20" );
AD_DEFAULT( "General", "ExitAfter", "1000" );
AD_DEFAULT( "General", "Admin", "webmaster@yourhost.dom" );
AD_DEFAULT( "General", "ExePath", "C:\\Pi3Web\\bin\\EnhPi3.exe" );
AD_DEFAULT( "General", "BinDir", "C:\\Pi3Web\\bin" );
AD_DEFAULT( "General", "InstallDir", "C:\\Pi3Web" );
AD_DEFAULT( "General", "SendTimeout", "350" );
AD_DEFAULT( "General", "RecvTimeout", "400" );
AD_DEFAULT( "General", "DNSReverseLookup", "" );
AD_DEFAULT( "General", "Debug", "" );
AD_DEFAULT( "General", "ErrorLog", "On" );
AD_DEFAULT( "General", "RunMode", "Desktop" );
AD_DEFAULT( "General", "ServiceName", "Pi3Web" );
AD_DEFAULT( "General", "KeepOpen", "On" );
AD_DEFAULT( "General", "KeepOpenCount", "100" );
AD_DEFAULT( "General", "KeepOpenTimeout", "5" );
AD_DEFAULT( "General", "ErrorMessages", "Short" );
AD_DEFAULT( "General", "ReuseThreads", "" );
/*
** Directory indexing defaults
*/
AD_DEFAULT( "DirIndex", "Layout", "1" );
// Type Name Alt Size Date Dscr
// 1 2 4 8 16 32
AD_DEFAULT( "DirIndex", "Columns", "59" );
AD_DEFAULT( "DirIndex", "SortColumn", "Type" );
// Link Case Desc
// 1 2 4
AD_DEFAULT( "DirIndex", "SortFlags", "1" );
// Hdr Ftr Dscr
// 1 2 4
AD_DEFAULT( "DirIndex", "FileFlags", "7" );
AD_DEFAULT( "DirIndex", "TagNew", "10" );
AD_DEFAULT( "DirIndex", "Truncate", "20" );
AD_DEFAULT( "DirIndex", "SizeFormat", "AbbrevSize" );
/*
** HTTP defaults
*/
AD_DEFAULT( "HTTP", "ServerStamp", "Pi3Web/2.0.3" );
// GET HEAD POST PUT DELE OPTI TRACE
// 1 2 4 8 16 32 64
AD_DEFAULT( "HTTP", "Methods", "3" );
AD_DEFAULT( "HTTP", "Description", "On" );
AD_DEFAULT( "HTTP", "Annotation", "On" );
AD_DEFAULT( "HTTP", "UploadPath", "" );
AD_DEFAULT( "HTTP", "UploadLimit", "4194304" );
AD_DEFAULT( "HTTP", "ChunkLimit", "8192" );
AD_DEFAULT( "HTTP", "Ranges", "bytes" );
/*
** Index Files
*/
if ( !M_LookupValue( pConfig, "HTTP", "IndexFile" ) )
{
for( int i=0; __pIndexFiles[i]; i++ )
{
M_AddValue( pConfig, "HTTP", "IndexFile", __pIndexFiles[i] );
};
}
/*
** SSL defaults
*/
AD_DEFAULT( "SSL", "Debug", "" );
// SSL2 SSL3 TLS1 Debg Bugs Hack
// 1 2 4 8 16 32
AD_DEFAULT( "SSL", "Options", "3" );
AD_DEFAULT( "SSL", "PKeyFile", "./key.pem" );
AD_DEFAULT( "SSL", "CertFile", "./cert.pem" );
AD_DEFAULT( "SSL", "Validation", "0" );
AD_DEFAULT( "SSL", "Depth", "1" );
AD_DEFAULT( "SSL", "CaCertPath", "./" );
// AD_DEFAULT( "SSL", "CaCertFile", "" );
AD_DEFAULT( "SSL", "Ciphers", "DEFAULT" );
/*
** MIME Types
*/
if ( !M_LookupValue( pConfig, "MIMETypes", "Mapping" ) )
{
for( int i=0; __pMIMETypes[i]; i++ )
{
M_AddValue( pConfig, "MIMETypes", "Mapping", __pMIMETypes[i] );
};
}
/*
** Mappings
*/
if ( !M_LookupValue( pConfig, "Mappings", "Mapping" ) )
{
for( int i=0; __pMappings[i]; i++ )
{
M_AddValue( pConfig, "Mappings", "Mapping", __pMappings[i] );
};
}
/*
** Logfiles
*/
if ( !M_LookupValue( pConfig, "Logfiles", "Logging" ) )
{
for( int i=0; __pLogfiles[i]; i++ )
{
M_AddValue( pConfig, "Logfiles", "Logging", __pLogfiles[i] );
};
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -