www.pudn.com > Net_apps.rar > HttpFileSystem.c
//*************************************************************
// Copyright 2003 Service & Quality Technology CO., LTD.
// ALL RIGHTS RESERVED.
// This software is provided under license and contains proprietary
// and confidential material which is the property of SQ tech.
//
// FileName : HttpFileSystem.c
// Description : fileSystem
// Reversion : 0.1 ,Date : 2004/03/18 ,Author : gofly
// Comment : first implementation
//
//*************************************************************
#include "opt.h"
#if HTTP_OPEN
#include "..\include\L3\net_apps\httpd\api\HttpFileSystem.h"
//#include "..\include\L3\net_apps\httpd\api\HttpApi.h"
#include "..\include\L3\net_apps\IoEnv.h"
#include "..\include\L3\net_apps\demo\Tx6Rx6DisplayTv.h"
//***********************************************
// HttpOpenFile(void *data)
// Description :
// Parameters :
// Returns : allow order return HTTP_R_OK
// deny order return HTTP_R_ERR
//***********************************************
INT8U HttpOpenFile(void *data, INT8U index)
{
INT8U Msg[256];
INT32U FileArrMum = sizeof(HttpFileArr)/sizeof(THttpFile);
THttpCtrlBlack *ptHCB = data ;
INT32U i;
INT16U j,k;
INT8U Order[128];
INT8U OrderLength;
JPG_BUF *jpeg_inf;
INT8U *p,*q;
//---- gofly debug for test open & close socket--//
#if 0
sprintf((char*)Msg, "HTTP requested %s was not found UID %d PID %d\n"
, Order, ptHCB->UID[index], ptHCB->PID[index]);
HttpAddHead(ptHCB->SockSendBuf[index], ptHCB->ExHttpHead[index], Msg);
goto GOTO_HttpOpenFile_END;
#endif
//------------------------------------------------------------------------//
// GET ORDER
//------------------------------------------------------------------------//
OrderLength = strcspn((const char*)ptHCB->Order[index],
(const char*)"\x3f\x26\x20\x3d\x0d\x0a\x00");
if( OrderLength > sizeof(Order))
{
strcpy((char*)Order, (const char*)"ERR REQUEST");
i = FileArrMum;// to bring about search file destory
}
else
{
memcpy((void*)Order, (const void*)ptHCB->Order[index], OrderLength ) ;
Order[OrderLength] = 0x00;
i = 0;
}
//------------------------------------------------------------------------//
// change order by UID
//------------------------------------------------------------------------//
if(!extra_strncmp(Order, "/check_user.html"))
{
INT8U tmp[16]; //add by jgy 8/30/05
sprintf( ptHCB->ExHttpHead[index],
"Set-Cookie: webcamPWD=%s\x0d\x0a", IoCookie(NULL,NULL, IOR, ptHCB->UID[index]));
switch(ptHCB->UID[index])
{
case ROOT:
//strcpy(Order, "/RootSys.html"); //mark by jjl
//strcpy(Order, "/LiveView.html");
strcpy(tmp, "NetCamPTZ.htm"); //modified by jgy 22/06/05
break;
case USER:
// strcpy(Order, "/UserSys.html");
//strcpy(Order, "/LiveView.html");
strcpy(tmp, "main_pz.htm"); //modified by jgy
break;
case OTHER:
//strcpy(Order, "/OtherSys.html");
strcpy(tmp, "denied.htm"); //modified by jgy
break;
}
//add by jgy 8/30/05
sprintf(Msg,"" \
" \r\n", tmp);
HttpAddHead(ptHCB->SockSendBuf[index], ptHCB->ExHttpHead[index], Msg);
goto GOTO_HttpOpenFile_END;
//jgy++
}
//------------------------------------------------------------------------//
// change order by view count if order == "/index.html" '/" change after
//------------------------------------------------------------------------//
/*
if(!strncmp(ptHCB->Order[index], "/LiveView.html" , 13) )
{
//imgmax = HttpStreamCount(data)+1;
if(HttpStreamCount(data) >= 15 )
{
sprintf(Msg, "HTTP system busy total socket = %d , general socket %d ,view socket = %d UID %d PID%d\n\x00"
, HTTP_MAX_SOCKET
, HttpUserSockCount(data)
, HttpStreamCount(data)
, ptHCB->UID[index]
, ptHCB->PID[index]);
HttpAddHead(ptHCB->SockSendBuf[index], ptHCB->ExHttpHead[index], Msg);
goto GOTO_HttpOpenFile_END;
}
}
*/
if(!strncmp(ptHCB->Order[index], "/cgi-bin/Stream?Video" , 21))
{
#if 1
//if (atol(IoViewUser(NULL,NULL,IOR,0))<=7 )
//{
if(!strncmp(ptHCB->Order[index]+21, "_Server", 7))
{
video_server_ref++;
jpgsmp[index] = 1;
}
imgmax[index]=1;
ptHCB->SendLen[index] = 0;
ptHCB->FileType[index] = FILE_TYPE_STREAM;
ptHCB->Stat[index] = HTTP_SEND;
return HTTP_R_OK;
//}
//else
//{
// return HTTP_R_ERR;
//}
#else
return StreamAdd((void*)data, index);
#endif
}
if(!strncmp(Order, "/cgi-bin/StreamVideoClose",25))
{
if(!strncmp(Order+25, "_Server", 7))
{
if(video_server_ref > 0) video_server_ref--;
imgmax[atoi((const char *)(Order+32))] = 0;
jpgsmp[atoi((const char *)(Order+32))] = 0;
}
else
imgmax[atoi((const char *)(Order+25))]=0;
return HTTP_R_ERR;
}
if(!strncmp(ptHCB->Order[index], "/cgi-bin/HistoryVideo" , 21) ||
!strncmp(ptHCB->Order[index], "/cgi-bin/Stream?HistoryVideo" , 28))
{
if(hist_video_blk.status == SDH_STOP)
{
ptHCB->Stat[index] = HTTP_STOP; //至关重要! 在读出历史数据前暂时不理会这个socket.
//确保即时监控画面的流畅性. jgy 10/28/05
hist_video_blk.status = SDH_START;
hist_video_blk.hist_idx = index;
hist_video_blk.rdy = 0;
imgmax[index]=2;
ptHCB->SendLen[index] = 0;
ptHCB->FileType[index] = FILE_TYPE_STREAM;
}
else
{
//send(ptHCB->Sock[index], "FAILED: another server is downloading", 37, 0);
sprintf(ptHCB->SockSendBuf[index], "FAILED: another server is downloading");
goto GOTO_HttpOpenFile_END;
}
return HTTP_R_OK;
}
if(!strncmp(ptHCB->Order[index], "/GET?" , 5))
{
memset(GBody, 0x00 ,sizeof(GBody));
*(ptHCB->Order[index] + strcspn((const char*)ptHCB->Order[index],
(const char*)"\x20\x0d\x0a\x00")) = 0x00;
HttpCgi(GBody, ptHCB->ExHttpHead[index], ptHCB->Order[index] + 5, ptHCB->UID[index]);
HttpAddHead(ptHCB->SockSendBuf[index], ptHCB->ExHttpHead[index], GBody);
i = FileArrMum;
sprintf(Msg, "HTTP UID %d PID %d send GET? length %d \n\x00"
, ptHCB->UID[index], ptHCB->PID[index]
, strlen(ptHCB->SockSendBuf[index]));
goto GOTO_HttpOpenFile_END;
}
if(!strncmp(ptHCB->Order[index], "/SET?" , 5))
{
memcpy(ptHCB->Order[index],"\x0d\x0a\x0d\x0a", 4);// HttpSolPost waill skip before \n\n data
HttpSolPost(ptHCB->SockRecvBuf[index], ptHCB->UID[index], ptHCB->SockSendBuf[index]);
memset(GBody, 0x00 ,sizeof(GBody));
HttpCgi(GBody, ptHCB->ExHttpHead[index], ptHCB->SockSendBuf[index], ptHCB->UID[index]);
HttpAddHead(ptHCB->SockSendBuf[index], ptHCB->ExHttpHead[index], GBody);
i = FileArrMum;
sprintf(Msg, "HTTP UID %d PID %d send GET? length %d \n\x00"
, ptHCB->UID[index], ptHCB->PID[index]
, strlen(ptHCB->SockSendBuf[index]));
goto GOTO_HttpOpenFile_END;
}
if(!strncmp(ptHCB->Order[index], "/EVENT?" , 7))
{
memset(GBody, 0x00 ,sizeof(GBody));
HttpSolEvent(ptHCB->Order[index],
GBody, HTTP_MAX_SEND_BUFF, ptHCB->UID[index]);
HttpAddHead(ptHCB->SockSendBuf[index], ptHCB->ExHttpHead[index], GBody);
sprintf(Msg, "HTTP UID %d PID %d send EVENT? length %d \n\x00"
, ptHCB->UID[index], ptHCB->PID[index]
, strlen(ptHCB->SockSendBuf[index]));
i = FileArrMum;
goto GOTO_HttpOpenFile_END;
}
//-------------- STORAGE ---------------//
//if(!strncmp(ptHCB->Order[index], "/storage_page.html?" , 19))
if(!strncmp(ptHCB->Order[index], "/CaptureView.htm?" , 17))
{
IoStorage(NULL, ptHCB->Order[index] + 17, IOW, USER);
}
if(!strncmp(ptHCB->Order[index], "/STHtml" , 6))
{
IoStorage("HTML_INDEX", ptHCB->Order[index] + 7, IOW, USER);
strcpy(Order, "/STHtml.html\x00");
}
if(!strncmp(ptHCB->Order[index], "/SImage" , 7))
{
int i,j=0;
// 42 bytes
//video_image_qsearch((void *)&ptHCB->send_jpg[index]);
//jpeg_inf = &ptHCB->send_jpg[index];
//p=jpeg_inf->jpg_file;
//q = p+42;
for (i=0;iOrder[index]+7, p+42/*StImageBuf+42*/,&ptHCB->TotalLen[index]);
if (!j)
{
sdimg_critical_section[index] =1;
StorageReadFile(ptHCB->Order[index]+7, StImageBuf+42,&ptHCB->TotalLen[index]);
ptHCB->Stat[index] = HTTP_SEND;
}
else
{
ptHCB->Stat[index] = HTTP_CONT;
}
#else
memcpy(StImageBuf + 42,LogoImage+74, sizeof(LogoImage)-74);
ptHCB->TotalLen[index] = sizeof(LogoImage)-74;
#endif
ptHCB->File[index] = StImageBuf;//jpeg_inf->jpg_file;
ptHCB->TotalLen[index] += 42; //headsize
ptHCB->FileType[index] = FILE_TYPE_FSR;
//sprintf(StImageBuf,"HTTP/1.1 200 OK""\x0d\x0a""CONTENE-LENGTH:%06d""\x0d\x0a\x0d\x0a",(INT16U)ptHCB->TotalLen[index]);
sprintf(StImageBuf,"HTTP/1.1 200 OK""\x0d\x0a""CONTENE-LENGTH:%03d%03d""\x0d\x0a\x0d\x0a",
(INT16U)(ptHCB->TotalLen[index]/1000),(INT16U)(ptHCB->TotalLen[index]%1000));
// sprintf 会将oxoo 补到最后
StImageBuf[42] = 0xff;// jpeg "0x00" 0xd8 => 0xff 0xd8
return HTTP_R_OK;
}
if(!strncmp(ptHCB->Order[index], "/LOG?" , 5))
{
GBody[0]=0x00;
#if FTP_OPEN
if(!strncmp(ptHCB->Order[index], "/LOG?FtpRequest" , 15))
FtpLog (GBody,sizeof(GBody),IOR);
else
#endif // FTP_OPEN
#if SMTP_OPEN
if(!strncmp(ptHCB->Order[index], "/LOG?SmtpRequest" , 15))
SmtpLog (GBody,sizeof(GBody),IOR);
else
#endif
#if DDNS_OPEN
if(!strncmp(ptHCB->Order[index], "/LOG?DdnsRequest" , 15))
DdnsLog (GBody,sizeof(GBody),IOR);
#endif // DDNS_OPEN
#if TX6RX6DISPLAYTV
if(!strncmp(ptHCB->Order[index], "/LOG?Tx6Rx6DisplayTv" , 20))
Tx6Rx6DisplayTvLog (GBody,sizeof(GBody),IOR);
#endif // TX6RX6DISPLAYTV
HttpAddHead(ptHCB->SockSendBuf[index], ptHCB->ExHttpHead[index], GBody);
i = FileArrMum;
goto GOTO_HttpOpenFile_END;
}
OrderLength = strlen(Order);
for(; i < FileArrMum; i++)
{
if(OrderLength == strlen((const char*)HttpFileArr[i].FileName))
{
if(!strncmp((const char*)Order,
(const char*)HttpFileArr[i].FileName ,
(size_t)OrderLength))
{
break;
}
}
}
// printf("@ %d\n",i);
if(i == FileArrMum)
{
sprintf((char*)Msg, "HTTP requested %s was not found UID %d PID %d\n"
, Order, ptHCB->UID[index], ptHCB->PID[index]);
HttpAddHead(ptHCB->SockSendBuf[index], ptHCB->ExHttpHead[index], Msg);
// SHOW_EX1(HTTP_DEBUG, Msg);
goto GOTO_HttpOpenFile_END;
}
if(ptHCB->UID[index] > HttpFileArr[i].Own )
{
INT8U tmp[16];
switch(ptHCB->UID[index])
{
case USER:
//memcpy(tmp,"LiveView.html\0x00",14);
//INT8U tmp[]= "LiveView.html";
memcpy(tmp, "main_pz.htm\0x00", 12); //modified by jgy 22/06/05
break;
case OTHER:
//INT8U tmp[]= "logon.html";
//memcpy(tmp,"logon.html\0x00",11);
memcpy(tmp, "index.html\0x00", 11); //modified by jgy
break;
}
sprintf(Msg,"HTTP You don't have permission to access %s UID %d PID%d\n\x00"
,tmp, HttpFileArr[i].FileName, ptHCB->UID[index], ptHCB->PID[index]);
//---- gofly debug --------------------------------------
HttpAddHead(ptHCB->SockSendBuf[index], ptHCB->ExHttpHead[index], Msg);
// SHOW_EX1(HTTP_DEBUG, Msg);
goto GOTO_HttpOpenFile_END;
}
memset(ptHCB->SockSendBuf[index], 0x00 ,HTTP_MAX_SEND_BUFF);
ptHCB->FileType[index] = HttpFileArr[i].FileType;
if(HttpFileArr[i].FileType == FILE_TYPE_STATIC_HTML)
{
HttpAddHead(ptHCB->SockSendBuf[index], ptHCB->ExHttpHead[index], HttpFileArr[i].pFile);
goto GOTO_HttpOpenFile_END;
}
if(HttpFileArr[i].FileType == FILE_TYPE_DYNAMIC_HTML)
{
memset(GBody, 0x00 ,sizeof(GBody));
HttpCgi(GBody, ptHCB->ExHttpHead[index], HttpFileArr[i].pFile, ptHCB->UID[index]);
HttpAddHead(ptHCB->SockSendBuf[index], ptHCB->ExHttpHead[index], GBody);
goto GOTO_HttpOpenFile_END;
}
if(HttpFileArr[i].FileType == FILE_TYPE_IMAGE || HttpFileArr[i].FileType == FILE_TYPE_CAB)
{
ptHCB->File[index] = HttpFileArr[i].pFile;
ptHCB->TotalLen[index] = HttpFileArr[i].FileLenght;
ptHCB->Stat[index] = HTTP_SEND;
sprintf(Msg, "HTTP UID %d PID %d send %s length %d \n\x00"
, ptHCB->UID[index], ptHCB->PID[index]
, HttpFileArr[i].FileName, ptHCB->TotalLen[index]);
SHOW_EX1(HTTP_DEBUG, Msg);
return HTTP_R_OK;
}
if(HttpFileArr[i].FileType == FILE_TYPE_INFINITE )
{
memset(ptHCB->SockSendBuf[index],0x00,HTTP_MAX_SEND_BUFF);
ptHCB->File[index] = ptHCB->SockSendBuf[index];
ptHCB->TotalLen[index] = HTTP_MAX_SEND_BUFF;
ptHCB->Stat[index] = HTTP_SEND;
return HTTP_R_OK;
}
if(HttpFileArr[i].FileType == FILE_TYPE_STORAGE )
{
//StoragePageMax(void);
//sprintf(GBody, "HTTP You don't have permission to access %s UID %d PID%d\n\x00"
// , HttpFileArr[i].FileName, ptHCB->UID[index], ptHCB->PID[index]);
GBody[0] = 0x00;
#if 1
StoragePageMax(&j);
#else
j = 60;
#endif
k=j;
for(j=1; j<=k; j++)
{
if(strlen(GBody) + 100 > sizeof(GBody)) break;
sprintf(GBody + strlen(GBody),"Page%06d \x00", (INT16U)j, (INT16U)j);
//sprintf(GBody + strlen(GBody),"\x00",(INT16U)j);
//if( j == 0) break;
}
HttpAddHead(ptHCB->SockSendBuf[index], ptHCB->ExHttpHead[index], GBody);
goto GOTO_HttpOpenFile_END;
}
GOTO_HttpOpenFile_END:
ptHCB->File[index] = ptHCB->SockSendBuf[index];
ptHCB->TotalLen[index] = ustrlen((const char*)ptHCB->File[index]);
ptHCB->Stat[index] = HTTP_SEND;
if(i != FileArrMum)
{
sprintf(Msg, "HTTP UID %d PID %d send %s length %d \n\x00"
, ptHCB->UID[index], ptHCB->PID[index]
, HttpFileArr[i].FileName, ptHCB->TotalLen[index]);
}
SHOW_EX1(HTTP_DEBUG, Msg);
return HTTP_R_OK;
}
#endif /*HTTP_OPEN*/