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

📄 ssi.c

📁 修改后的thttp
💻 C
📖 第 1 页 / 共 2 页
字号:
    time_t t;    /* Prints the value of one of the include variables.  Any dates are    ** printed subject to the currently configured timefmt.  The only valid    ** tag is var, whose value is the name of the variable you wish to echo.    */    if ( strcmp( tag, "var" ) != 0 )	unknown_tag( filename, directive, tag );    else	{	if ( strcmp( val, "DOCUMENT_NAME" ) == 0 )	    {	    /* The current filename. */	    (void) fputs( filename, stdout );	    }	else if ( strcmp( val, "DOCUMENT_URI" ) == 0 )	    {	    /* The virtual path to this file (such as /~robm/foo.shtml). */	    (void) fputs( vfilename, stdout );	    }	else if ( strcmp( val, "QUERY_STRING_UNESCAPED" ) == 0 )	    {	    /* The unescaped version of any search query the client sent. */	    cp = getenv( "QUERY_STRING" );	    if ( cp != (char*) 0 )		(void) fputs( cp, stdout );	    }	else if ( strcmp( val, "DATE_LOCAL" ) == 0 )	    {	    /* The current date, local time zone. */	    t = time( (time_t*) 0 );	    show_time( t, 0 );	    }	else if ( strcmp( val, "DATE_GMT" ) == 0 )	    {	    /* Same as DATE_LOCAL but in Greenwich mean time. */	    t = time( (time_t*) 0 );	    show_time( t, 1 );	    }	else if ( strcmp( val, "LAST_MODIFIED" ) == 0 )	    {	    /* The last modification date of the current document. */	    if ( fstat( fileno( fp ), &sb ) >= 0 )		show_time( sb.st_mtime, 0 );	    }	else	    {	    /* Try an environment variable. */	    cp = getenv( val );	    if ( cp == (char*) 0 )		unknown_value( filename, directive, tag, val );	    else		(void) fputs( cp, stdout );	    }	}    }static voiddo_fsize( char* vfilename, char* filename, FILE* fp, char* directive, char* tag, char* val )    {    char filename2[1000];    /* Prints the size of the specified file. */    if ( get_filename(	     vfilename, filename, directive, tag, val, filename2,	     sizeof(filename2) ) < 0 )	return;    if ( stat( filename2, &sb ) < 0 )	{	not_found2( directive, tag, filename2 );	return;	}    show_size( sb.st_size );    }static voiddo_flastmod( char* vfilename, char* filename, FILE* fp, char* directive, char* tag, char* val )    {    char filename2[1000];    /* Prints the last modification date of the specified file. */    if ( get_filename(	     vfilename, filename, directive, tag, val, filename2,	     sizeof(filename2) ) < 0 )	return;    if ( stat( filename2, &sb ) < 0 )	{	not_found2( directive, tag, filename2 );	return;	}    show_time( sb.st_mtime, 0 );    }static voidparse( char* vfilename, char* filename, FILE* fp, char* str )    {    char* directive;    char* cp;    int ntags;    char* tags[200];    int dirn;#define DI_CONFIG 0#define DI_INCLUDE 1#define DI_ECHO 2#define DI_FSIZE 3#define DI_FLASTMOD 4    int i;    char* val;    directive = str;    directive += strspn( directive, " \t\n\r" );    ntags = 0;    cp = directive;    for (;;)	{	cp = strpbrk( cp, " \t\n\r\"" );	if ( cp == (char*) 0 )	    break;	if ( *cp == '"' )	    {	    cp = strpbrk( cp + 1, "\"" );	    ++cp;	    if ( *cp == '\0' )		break;	    }	*cp++ = '\0';	cp += strspn( cp, " \t\n\r" );	if ( *cp == '\0' )	    break;	if ( ntags < sizeof(tags)/sizeof(*tags) )	    tags[ntags++] = cp;	}        if ( strcmp( directive, "config" ) == 0 )	dirn = DI_CONFIG;    else if ( strcmp( directive, "include" ) == 0 )	dirn = DI_INCLUDE;    else if ( strcmp( directive, "echo" ) == 0 )	dirn = DI_ECHO;    else if ( strcmp( directive, "fsize" ) == 0 )	dirn = DI_FSIZE;    else if ( strcmp( directive, "flastmod" ) == 0 )	dirn = DI_FLASTMOD;    else	{	unknown_directive( filename, directive );	return;	}    for ( i = 0; i < ntags; ++i )	{	if ( i > 0 )	    putchar( ' ' );	val = strchr( tags[i], '=' );	if ( val == (char*) 0 )	    val = "";	else	    *val++ = '\0';	if ( *val == '"' && val[strlen( val ) - 1] == '"' )	    {	    val[strlen( val ) - 1] = '\0';	    ++val;	    }	switch( dirn )	    {	    case DI_CONFIG:	    do_config( vfilename, filename, fp, directive, tags[i], val );	    break;	    case DI_INCLUDE:	    do_include( vfilename, filename, fp, directive, tags[i], val );	    break;	    case DI_ECHO:	    do_echo( vfilename, filename, fp, directive, tags[i], val );	    break;	    case DI_FSIZE:	    do_fsize( vfilename, filename, fp, directive, tags[i], val );	    break;	    case DI_FLASTMOD:	    do_flastmod( vfilename, filename, fp, directive, tags[i], val );	    break;	    }	}    }static voidslurp( char* vfilename, char* filename, FILE* fp )    {    char buf[1000];    int i;    int state;    int ich;    /* First, write out a close-comment sequence. */    (void) fputs( "-->", stdout );    /* Now slurp in the rest of the comment from the input file. */    i = 0;    state = ST_GROUND;    while ( ( ich = getc( fp ) ) != EOF )	{	switch ( state )	    {	    case ST_GROUND:	    if ( ich == '-' )		state = ST_MINUS1;	    break;	    case ST_MINUS1:	    if ( ich == '-' )		state = ST_MINUS2;	    break;	    case ST_MINUS2:	    if ( ich == '>' )		{		buf[i - 2] = '\0';		parse( vfilename, filename, fp, buf );		return;		}	    break;	    }	if ( i < sizeof(buf) - 1 )	    buf[i++] = (char) ich;	}    }static voidread_file( char* vfilename, char* filename, FILE* fp )    {    int ich;    int state;    /* Copy it to output, while running a state-machine to look for    ** SSI directives.    */    state = ST_GROUND;    while ( ( ich = getc( fp ) ) != EOF )	{	switch ( state )	    {	    case ST_GROUND:	    if ( ich == '<' )		state = ST_LESSTHAN;	    break;	    case ST_LESSTHAN:	    if ( ich == '!' )		state = ST_BANG;	    break;	    case ST_BANG:	    if ( ich == '-' )		state = ST_MINUS1;	    break;	    case ST_MINUS1:	    if ( ich == '-' )		state = ST_MINUS2;	    break;	    case ST_MINUS2:	    if ( ich == '#' )		{		slurp( vfilename, filename, fp );		state = ST_GROUND;		continue;		}	    break;	    }	putchar( (char) ich );	}    }intmain( int argc, char** argv )    {    char* script_name;    char* path_info;    char* path_translated;    FILE* fp;    argv0 = argv[0];    /* Default formats. */    (void) strcpy( timefmt, "%a %b %e %T %Z %Y" );    sizefmt = SF_BYTES;    /* Get the name that we were run as. */    script_name = getenv( "SCRIPT_NAME" );    if ( script_name == (char*) 0 )	{	internal_error( "Couldn't get SCRIPT_NAME environment variable." );	exit( 1 );	}    /* Append the PATH_INFO, if any, to get the full URL. */    path_info = getenv( "PATH_INFO" );    if ( path_info == (char*) 0 )	{	internal_error( "Couldn't get PATH_INFO environment variable." );	exit( 1 );	}    url = (char*) malloc( strlen( script_name ) + strlen( path_info ) + 1 );    if ( url == (char*) 0 )	{	internal_error( "Out of memory." );	exit( 1 );	}    (void) sprintf( url, "%s%s", script_name, path_info );    /* Get the name of the file to parse. */    path_translated = getenv( "PATH_TRANSLATED" );    if ( path_translated == (char*) 0 )	{	internal_error( "Couldn't get PATH_TRANSLATED environment variable." );	exit( 1 );	}    /* Open it. */    fp = fopen( path_translated, "r" );    if ( fp == (FILE*) 0 )	{	not_found( path_translated );	exit( 1 );	}    /* The MIME type has to be text/html. */    (void) fputs( "Content-type: text/html\n\n", stdout );    /* Read and handle the file. */    read_file( path_info, path_translated, fp );    (void) fclose( fp );    exit( 0 );    }

⌨️ 快捷键说明

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