📄 ws_tasks.c
字号:
continue;
data_start += 4;
header_length = (INT)(data_start - line);
/* Search for the Content-Length MIME */
s = HTTP_Find_Token(WS_CONTENT_LENGTH, line, data_start);
if(s)
{
/* Increment Pointer to Content String within Buffer */
s = s + 16;
/* get the length of the multiform data (with file)*/
content_length = (INT)NU_ATOL(s);
}
}
/* If the entire request will fit in the receiver buffer and we haven't
* gotten all of the data, then get another packet.
*/
}while((content_length < (WS_RECEIVE_SIZE - header_length)) &&
(connection_bytes < (content_length + header_length)));
if(status != NU_SUCCESS)
continue;
if(HTTP_Find_Token(WS_HTTP_11_STRING, line, data_start))
hsock_ent->ws_http_ver = WS_HTTP_11;
else
hsock_ent->ws_http_ver = WS_HTTP_10;
/*Get the clients IP address */
WS_Set_Client_Addr(&Req,sockfd);
/* Setup state for server */
Req.ws_server = &WS_Master_Server; /* per server info */
Req.ws_sd = sockfd; /* socket descripter */
out_head[0] = 0;
Req.ws_response = out_head; /* storage/output header */
Req.ws_obufcnt = 0;
Req.ws_rdata = reqdat; /* per request allocated data */
Req.ws_nbytes = connection_bytes;
Req.ws_http_ver = &(hsock_ent->ws_http_ver);
/* call the server for every HTTP request */
HTTP_Parse_Request(&Req, line);
WS_Flush_Net(&Req); /* flush the output buffer */
/* Check if version is HTTP 1.1 */
if(hsock_ent->ws_http_ver == WS_HTTP_10)
{
/* Not HTTP 1.1 but HTTP 1.0 so close the socket and
* remove it from the web socket cache.
*/
NU_Close_Socket(hsock_ent->ws_socketd);
WS_Remove_Socket_Entry(&http_sock,&free_sock,hsock_ent);
}
else
{
/* This is HTTP 1.1, update the socket information
* Get the Time Click from when we are complete woth loading the socket
*/
hsock_ent->ws_time_click = NU_Retrieve_Clock();
}
}
#ifdef NU_WEBSERV_DEBUG
printf("REQUEST DONE\n");
#endif
}
}
/* Allow for another task to run */
NU_Relinquish();
} /* (END while ( 1 ) loop */
}
/************************************************************************
* FUNCTION
*
* WS_Set_Client_Addr
*
* DESCRIPTION
*
* Gets the IP address of the current client connection.
*
* AUTHOR
*
* Don Sharer, Accelerated Technology
*
* INPUTS
*
* WS_REQUEST *Req Pointer to Request structure that
* holds all information pertaining to
* the HTTP request.
*
* INT16 sockfd
*
* OUTPUTS
*
* STATUS
*
************************************************************************/
static STATUS WS_Set_Client_Addr(WS_REQUEST *Req,INT sockfd)
{
INT i;
struct sockaddr_struct client_addr;
INT16 size;
STATUS ret_stat;
size = sizeof (struct sockaddr_struct);
if(( ret_stat = NU_Get_Peer_Name(sockfd, &client_addr,&size) ) != NU_SUCCESS)
{
#ifdef NU_WEBSERV_DEBUG
printf("BAD Peer NAME\n");
#endif
}
else
{
for( i = 0; i < WS_IP_SIZE; i++)
Req->ws_ip[i] = *(((CHAR * )&client_addr) + i);
}
return(ret_stat);
}
/************************************************************************
* FUNCTION
*
* WS_Create_Socket_List
*
* DESCRIPTION
*
* Creates an initialized linked list used for holding socket
* information
*
* AUTHOR
*
* Doug Phillips, Accelerated Technology Inc.
*
* INPUTS
*
* free_sock Pointer to the socket list
*
* OUTPUTS
*
* STATUS
*
************************************************************************/
static VOID WS_Create_Socket_List(WS_SOCK_LIST *free_sock)
{
WS_SOCKET_STRUCT *hsock_ent;
INT list_node;
NU_Allocate_Memory(&System_Memory,(VOID **)&hsock_ent,
(sizeof(WS_SOCKET_STRUCT)) * WS_LOCAL_QUEUE_SIZE,
NU_SUSPEND);
for(list_node = 0;list_node < WS_LOCAL_QUEUE_SIZE;list_node++)
{
/* Initialize the free node */
hsock_ent->ws_http_ver = -1;
hsock_ent->ws_socketd = -1;
hsock_ent->ws_time_click = 0;
/* Add the free node to the list of free nodes */
DLL_Enqueue((tqe_t *) free_sock, (tqe_t *) hsock_ent);
/* Increment pointer to next free space in memory */
hsock_ent++;
}
}
/************************************************************************
* FUNCTION
*
* WS_Add_Socket_Entry
*
* DESCRIPTION
*
* Adds a socket entry into the doubly linked list. The node that
* is added comes from a list of already created and initialized nodes.
*
* AUTHOR
*
* Don Sharer, Accelerated Technology
*
* INPUTS
*
* http_sock Pointer to the working socket list.
* free_sock Pointer to the list containing the
* free nodes.
* socket The actual socket to be placed in
* in the list.
*
* OUTPUTS
*
* STATUS
*
************************************************************************/
static STATUS WS_Add_Socket_Entry(WS_SOCK_LIST *http_sock, WS_SOCK_LIST *free_sock, INT socket)
{
/* Set the Values and add the entry into the socket linked list */
free_sock->ws_sock_list_head->ws_socketd = socket;
free_sock->ws_sock_list_head->ws_time_click = NU_Retrieve_Clock();
/* Add this entry to the list. */
DLL_Enqueue((tqe_t *) http_sock, DLL_Dequeue((tqe_t *) free_sock));
/* This socket is no longer connected */
return(-1);
}
/************************************************************************
* FUNCTION
*
* WS_Remove_Socket_Entry
*
* DESCRIPTION
*
* Removes a socket entry from the doubly linked list. The
* removed node is placed back onto the free node list.
*
* AUTHOR
*
* Don Sharer, Accelerated Technology
*
* INPUTS
*
* http_sock Pointer to the working socket list.
* free_sock Pointer to the list containing the
* free nodes.
* hsock_ent Pointer to node which will be removed
* from the list.
*
* OUTPUTS
*
*
*
************************************************************************/
static VOID WS_Remove_Socket_Entry(WS_SOCK_LIST *http_sock, WS_SOCK_LIST *free_sock, WS_SOCKET_STRUCT *hsock_ent)
{
/* Reinitialize the node */
hsock_ent->ws_http_ver = -1;
hsock_ent->ws_socketd = -1;
hsock_ent->ws_time_click = 0;
/* Remove the node from the list of active sockets */
DLL_Remove((tqe_t *) http_sock,(tqe_t *) hsock_ent);
/* Add the node the list of free nodes */
DLL_Enqueue((tqe_t *) free_sock, (tqe_t *) hsock_ent);
}
/************************************************************************
* FUNCTION
*
* WS_File_Status
*
* DESCRIPTION
*
* Checks if the file to be saved is on external storage and fills
* out the request stat structure on file size.
*
* AUTHOR
*
* Don Sharer, Accelerated Technology
*
* INPUTS
*
* req Pointer to Request structure that
* holds all information pertaining to
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -