📄 ws_tasks.c
字号:
* the HTTP request.
*
* OUTPUTS
*
* INT
*
************************************************************************/
INT WS_File_Status(WS_REQUEST * req)
{
#ifndef WS_FS_IN_MEMORY
FAL_DIR statobj;
CHAR buf[WS_FS_LEN];
INT32 attrib = 0;
WS_Name_File(req, buf);
if (FAL_Find_First((CHAR *)buf,&statobj,&attrib) == 0)
{
req->ws_stat->ws_size = statobj.fsize;
req->ws_stat->ws_flags = WS_FOUND;
FAL_Find_Close(0,&statobj);
return(SUCCESS);
}
else
return(FAILURE);
#else
UNUSED_PARAMETER(req);
return(FAILURE);
#endif
}
/************************************************************************
* FUNCTION
*
* WS_Name_File
*
* DESCRIPTION
*
* Places the file name in the correct format so it can be read, or
* written with an external file system.
*
* AUTHOR
*
* Don Sharer, Accelerated Technology
*
* INPUTS
*
* Request *req Pointer to Request structure that
* holds all information pertaining to
* the HTTP request.
* CHAR *buf Pointer to the filename that will
* contain the proper command.
*
* OUTPUTS
*
* None.
*
************************************************************************/
VOID WS_Name_File(WS_REQUEST * req, CHAR * buf )
{
#ifndef WS_FS_IN_MEMORY
CHAR *path;
CHAR *name;
strcpy(buf, WS_FS_PREFIX); /* base of server root */
name = req->ws_fname;
while (*name == '/')
name++;
for(path = name;*path;path++)
if(*path == '/')
*path = '\\';
strcat(buf,name);
#ifdef NU_WEBSERV_DEBUG
printf("NAME = %s\n",buf);
#endif
#else
UNUSED_PARAMETER(req);
UNUSED_PARAMETER(buf);
#endif
}
/************************************************************************
* FUNCTION
*
* WS_Send_File
*
* DESCRIPTION
*
* Function to write the file to the socket.
*
* AUTHOR
*
* Don Sharer, Accelerated Technology
*
* INPUTS
*
* req Pointer to Request structure that
* holds all information pertaining to
* the HTTP request.
*
* OUTPUTS
*
* Return SUCCESS if Successful.
* Returns Failure if unsuccessful.
*
************************************************************************/
INT WS_Send_File(WS_REQUEST * req)
{
#ifndef WS_FS_IN_MEMORY
CHAR buf[WS_FS_LEN];
CHAR fbuf[WS_FBUF_SZ];
FAL_FILE fd = FILE_CHECK;
UINT16 mode;
UINT32 j;
WS_Name_File(req,buf);
mode = FAL_IREAD;
if( (fd = FAL_Open((CHAR *)buf, PO_RDONLY, (UINT16)mode)) != (FAL_FILE)FILE_CHECK)
{
while( (j = FAL_Fread((CHAR *)fbuf, WS_FBUF_SZ, fd)) > 0)
WS_Write_To_Net(req, fbuf, j, WS_FILETRNSFR);
}
else
{
#ifdef NU_WEBSERV_DEBUG
printf("can't open %s \n",buf);
#endif
return FAILURE;
}
FAL_Fclose(fd,0);
return SUCCESS;
#else
UNUSED_PARAMETER(req);
return FAILURE;
#endif
}
/************************************************************************
* FUNCTION
*
* WS_Read_File
*
* DESCRIPTION
*
* Copy the file to an array.
*
* AUTHOR
*
* Don Sharer, Accelerated Technology
*
* INPUTS
*
* req Pointer to Request structure that
* holds all information pertaining to
* the HTTP request.
* buffer Pointer to the buffer that bytes read
* from the file is to be placed.
*
* OUTPUTS
*
* Return NU_SUCCESS if Successful.
* Returns WS_FAILURE if unsuccessful.
*
************************************************************************/
INT WS_Read_File(WS_REQUEST * req, CHAR * buffer )
{
/* Remove Warnings */
#ifndef WS_FS_IN_MEMORY
CHAR buf[WS_FS_LEN];
FAL_FILE fd = FILE_CHECK;
UINT32 j;
INT mode = 0;
WS_Name_File(req,buf);
mode = FAL_IREAD;
if( (fd = FAL_Open((CHAR *)buf, PO_RDONLY,(UINT16)mode)) != (FAL_FILE )FILE_CHECK)
{
j = FAL_Fread((CHAR *)buffer, (UINT16)req->ws_stat->ws_size, fd);
if (j != (UINT32)req->ws_stat->ws_size)
{
FAL_Fclose(fd, 0);
return(WS_FAILURE);
}
else
{
FAL_Fclose(fd, 0);
return(NU_SUCCESS);
}
}
else
{
#ifdef NU_WEBSERV_DEBUG
printf("can't open %s \n",buf);
#endif
return WS_FAILURE;
}
#else
UNUSED_PARAMETER(req);
UNUSED_PARAMETER(buffer);
return WS_FAILURE;
#endif
}
/************************************************************************
* FUNCTION
*
* WS_Write_File_System
*
* DESCRIPTION
*
* Function that used for hook to implement support for a hard disk
* or other(non memory-base FS) mass storage.
*
* AUTHOR
*
* Don Sharer, Accelerated Technology
*
* INPUTS
*
* fname File name to be written under.
* filemem The pointer to the file in memory.
* length The length of the file.
*
* OUTPUTS
*
* Return NU_SUCCESS if Successful.
* Returns WS_FAILURE if unsuccessful.
*
************************************************************************/
INT WS_Write_File_System(CHAR * fname, CHAR HUGE* filemem, UINT32 length)
{
#ifndef WS_FS_IN_MEMORY
FAL_FILE fd = FILE_CHECK;
UINT16 mode = 0;
filemem = (CHAR HUGE*)TLS_Normalize_Ptr(filemem);
mode = FAL_IWRITE;
FAL_Become_File_User();
if( (fd = FAL_Open(fname, PO_WRONLY|PO_CREAT, mode)) != (FAL_FILE)FILE_CHECK)
{
while(length)
{
if(length > WS_MAX_16_BIT)
{
if((FAL_Fwrite((CHAR*)filemem, (UINT16)WS_MAX_16_BIT, fd)) != WS_MAX_16_BIT)
{
FAL_Fclose(fd, 0);
return WS_FAILURE;
}
length -= WS_MAX_16_BIT;
filemem += WS_MAX_16_BIT;
}
else
{
if((FAL_Fwrite((CHAR*)filemem, (UINT16)length, fd)) != length )
{
FAL_Fclose(fd, 0);
return WS_FAILURE;
}
length = 0;
}
}
FAL_Fclose(fd, 0);
return(NU_SUCCESS);
}
else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -