📄 http_psr.c
字号:
plugin = NU_NULL;
while( *p != '>' && ( (p - insert) < WS_SSI_LINE ) )
/* copy tag into buffer */
{
*q++ = *p++;
}
if( *p == '>' )
*q ='\0';
else
ssi_buf[WS_SSI_LINE - 1] = '\0';
/* size of the ssi tag */
ssilen = strlen(ssi_buf);
/* parse the hard way */
q = plugin_s;
p = ssi_buf;
while( *p != '#' )
p++;
p++;
while(*p != ' ')
*q++ = *p++;
*q = '\0';
for(q = p; *q == ' '; q++);
{
/* does it look like NAME=VALUE ?*/
if( HTTP_In_String("~", q))
{
while(*p != '~')
p++;
/* terminate argument string */
*p = '\0';
}
/* process the arguments */
HTTP_Build_Token_Array(q, &req->ws_pg_args);
}
/* lookup the plugin in the table */
p = plugin_s;
while(*p == '/') p++;
for(i = 0 ; i < WS_MAX_PLUGIN ; i++)
{
if( HTTP_Plugins[i].ws_name )
{
if( strcmp((CHAR*)p, HTTP_Plugins[i].ws_name) == 0 )
{
plugin = HTTP_Plugins[i].plugin;
break;
}
}
}
/* Write Plugin Data */
WS_Write_To_Net(req, last_start, (UINT32)(insert - last_start), WS_PLUGIN_DATA );
last_start = (insert + ssilen) + 1;
if( plugin == NU_NULL )
{
strcpy(ssierror,plugin_s);
strcat(ssierror," CANT FIND SSI plugin");
WS_Write_To_Net(req, ssierror, strlen(ssierror), WS_PLUGIN_DATA);
break;
}
i = (plugin)(req);
/* Post plugin error check */
if(i != WS_REQ_PROCEED)
{
strcpy(req->ws_response, HTTP_Text_H500);
strcpy(buf, HTTP_Text_D500);
strcat(buf, "Plugin Failure");
strcat(buf, HTTP_Text_D500A);
i = strlen(buf);
HTTP_Initiate_Response(req, WS_PLUGIN_PROTO);
WS_Write_To_Net(req, buf, (UINT32)i, WS_PLUGIN_DATA);
WS_Write_To_Net(req, 0, 0, WS_PLUGIN_SEND);
return;
}
/* Clear out the token array */
req->ws_pg_args.ws_token_array[0] = -1;
req->ws_pg_args.ws_token_string = NU_NULL;
insert = (HTTP_Find_Token(WS_SSI_TOKEN, last_start, last_byte));
}
/* write out last piece if any */
if( last_start < ((CHAR HUGE*)file + req->ws_stat->ws_size))
WS_Write_To_Net(req, last_start, (UINT32)(((CHAR HUGE*)file +
req->ws_stat->ws_size) - last_start), WS_PLUGIN_DATA);
/* Send the Data */
WS_Write_To_Net(req, NU_NULL, 0, WS_PLUGIN_SEND);
if( (req->ws_stat->ws_flags & WS_INCORE ) == 0 )
NU_Deallocate_Memory(file);
}
/************************************************************************
*
* FUNCTION
*
* HTTP_Is_SSI
*
* DESCRIPTION
*
* The function checks to see if the current file name is a file
* marked for server side include processing.
*
* INPUTS
*
* *req Pointer to Request structure that
* holds all information pertaining
* to the HTTP request.
*
* OUTPUTS
*
* NU_SUCCESS ssi tag found
* WS_FAILURE Cannot find ssi tag
*
*************************************************************************/
static STATUS HTTP_Is_SSI(WS_REQUEST *req)
{
if( (HTTP_In_String(WS_SSI_LC_MARKER,req->ws_fname)) != FAILURE )
return(NU_SUCCESS);
else if( (HTTP_In_String(WS_SSI_UC_MARKER,req->ws_fname)) != FAILURE )
return(NU_SUCCESS);
else
return(WS_FAILURE);
}
/************************************************************************
*
* FUNCTION
*
* HTTP_Process_POST
*
* DESCRIPTION
*
* The POST method specifies a URI and
* includes optional user input data from
* HTML forms screens. Plugin's can be launched
* thru here.
*
* INPUTS
*
* *req Pointer to Request structure that
* holds all information pertaining
* to the HTTP request.
* *line String to be parced that includes
* value and name arguements.
*
* OUTPUTS
*
* None
*
*************************************************************************/
static VOID HTTP_Process_POST(WS_REQUEST *req, CHAR *line)
{
CHAR *s;
INT i;
CHAR posterror[WS_SSI_LINE];
WS_STAT ps;
INT (*plugin)(WS_REQUEST *) = NU_NULL;
CHAR buf[260];
req->ws_stat = &ps;
if( (HTTP_In_String("multipart/form-data",line)) == FAILURE)
{
if ((s = HTTP_In_String("\r\n\r\n",line)) != FAILURE)
{
s = s + 4;
HTTP_Build_Token_Array(s, &req->ws_pg_args);
}
}
for(s = req->ws_fname;*s == '/';s++);
for(i = 0;i < WS_MAX_PLUGIN; i++ )
{
if(HTTP_Plugins[i].ws_name )
{
if( strcmp(s, HTTP_Plugins[i].ws_name) == 0 )
{
plugin = HTTP_Plugins[i].plugin;
break;
}
}
}
if( plugin == NU_NULL )
{
/* Print error on browser*/
HTTP_Response_Header(req, WS_PROTO_OK);
HTTP_Header_Name_Insert(WS_CONTENT_TYPE, WS_TYPE_TXT_HTML, req->ws_response);
HTTP_Initiate_Response(req, WS_PLUGIN_PROTO);
strcpy(posterror, "Nucleus WebServ: cant find plugin: ");
strcat(posterror, req->ws_fname);
WS_Write_To_Net(req, posterror, strlen(posterror), WS_PLUGIN_DATA);
/* Plug-In Send */
WS_Write_To_Net(req, NU_NULL, 0, WS_PLUGIN_SEND);
return;
}
i = ((plugin)(req));
/* Post plugin error check */
if(i != WS_REQ_PROCEED)
{
strcpy(req->ws_response, HTTP_Text_H500);
strcpy(buf, HTTP_Text_D500);
strcat(buf, "Plugin Failure");
strcat(buf, HTTP_Text_D500A);
i = strlen(buf);
HTTP_Initiate_Response(req, WS_PLUGIN_PROTO);
WS_Write_To_Net(req, buf, (UINT32)i, WS_PLUGIN_DATA);
WS_Write_To_Net(req, 0, 0, WS_PLUGIN_SEND);
}
}
/************************************************************************
*
* FUNCTION
*
* HTTP_Send_Client_HTML_Msg
*
* DESCRIPTION
*
* This function sends an error message to a client when called.
*
* INPUTS
*
* *req Pointer to Request structure that
* holds all information pertaining
* to the HTTP request.
* *mes The message to be sent
* to the client.
*
* OUTPUTS
*
* None.
*
*************************************************************************/
VOID HTTP_Send_Client_HTML_Msg(WS_REQUEST *req, CHAR *mes)
{
CHAR *buf;
buf = &req->ws_rdata->ws_ssi_buf[0];
#ifdef NU_WEBSERV_DEBUG
printf("mes = %s\n", mes);
#endif
/* Print error on browser*/
HTTP_Response_Header(req, WS_PROTO_OK);
HTTP_Header_Name_Insert(WS_CONTENT_TYPE, WS_TYPE_TXT_HTML, req->ws_response);
HTTP_Initiate_Response(req, WS_PLUGIN_PROTO);
strcpy(buf, "Nucleus WebServer: ");
strcat(buf, mes);
WS_Write_To_Net(req, buf, strlen(buf), WS_PLUGIN_DATA);
WS_Write_To_Net(req, buf, strlen(buf), WS_PLUGIN_SEND);
WS_Flush_Net(req);
}
/************************************************************************
*
* FUNCTION
*
* HTTP_Build_Token_Array
*
* DESCRIPTION
*
* This function Parses and converts the clients plug-in
* arguments into individual strings and adds pointers to
* the buffer into the token array.
*
* INPUTS
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -