?? httpreqparse.cpp
字號:
//table->RespServiceBuffer=...
//table->ResponseCode=...
if(stricmp((char *)(table->ResponseCode),"500")
&&stricmp((char *)(table->ResponseCode),"501"))//判斷響應碼
//if(table->Content_Length!=0&&(!stricmp((char *)(table->Content_Type),"text/html")))
if(table->Content_Length!=0)
{
if(func_HTTP_ParseHTTPInfoData2(HTTPData, &MsgHead, &MsgBody))//HTTP數據解析處理
{
//printf("MsgHead----->%s\n",MsgHead);
//printf("MsgBody----->%s\n",MsgBody);
//printf("MsgBody2----->%s\n",MsgBody2);
if(func_HTTP_ParseHTTPHtmlStart(MsgBody,&befHtml,&behHtml))
{
printf("查到html\n");
table->HtmStart=1;
strcpy(filename,"unknown");
printf("behHtml----->%s\n",behHtml);
if(func_HTTP_ParseHTTPStytleStart(behHtml,&befStytle,&behStytle))
{
printf("behStytle----->%s\n",behStytle);
if(func_HTTP_ParseHTTPStytleEnd(behStytle,&bef_Stytle,&beh_Stytle))
{
printf("bef_Stytle----->%s\n",bef_Stytle);
printf("beh_Stytle----->%s\n",beh_Stytle);
strcpy(filename,bef_Stytle+7);
printf("filename----->%s\n",filename);
htmfilename=CString("e:\\outdata\\")+CString(filename)+CString(".htm");
table->HtmFileName=htmfilename;
fpHtm1=fopen(htmfilename,"w");
fprintf(fpHtm1,"%s",behHtml);
fprintf(fpHtm1,"%s","<");
fprintf(fpHtm1,"%s",beh_Stytle);
fclose(fpHtm1);
}//func_HTTP_ParseHTTPStytleEnd
}//func_HTTP_ParseHTTPStytleStart
else
{
printf("filename----->%s\n",filename);
htmfilename=CString("e:\\outdata\\")+CString(filename)+CString(".htm");
table->HtmFileName=htmfilename;
fpHtm1=fopen(htmfilename,"w");
fprintf(fpHtm1,"%s",behHtml);
fclose(fpHtm1);
}
}//func_HTTP_ParseHTTPHtmlStart
//找到</HTML>則此輪結束,釋放工作區
if(func_HTTP_ParseHTTPHtmlEnd(HTTPData,&bef_Html,&beh_Html))
{
func_ReleaseWorkTable(ReqRespSeq);
}
}//func_HTTP_ParseHTTPInfoData2
}//Content_Length!=0
}//HTTP/1.1
else//完全消息體
{
if(table==NULL)
{
for(i=0;i<MaxRequestNum;i++)
{
if(HTTPRequestSeqFlag[i]==0)
{
ReqRespSeq=i;
HTTPRequestSeqFlag[i]=1;
break;
}
}
if(i>=MaxRequestNum)
{printf("工作區滿!\n");return(0);}
table=&HTTPWorkTable[ReqRespSeq];
}
printf("此IP包是完全消息體內容!\n");
if(table->HTTPState==HTTP_Request_State)
{
table->HTTPState=HTTP_RequestBody_State;
}
else if(table->HTTPState==HTTP_Response_State||table->HTTPState==HTTP_ResponseBody_State)
{
table->HTTPState=HTTP_ResponseBody_State;
htmfilename=table->HtmFileName;
printf("是響應消息消息體!\n");
/*if(table->GzipState==1)
{
func_GzipDecode(HTTPData,&HTTPData2);//有解碼函數嗎?
HTTPData=HTTPData2;
}*/
if(func_HTTP_ParseHTTPHtmlEnd(HTTPData,&bef_Html,&beh_Html))
{
printf("bef_Html----->%s\n",bef_Html);
fpHtm1=fopen(htmfilename,"a");
fprintf(fpHtm1,"%s",bef_Html);
fprintf(fpHtm1,"%s","</HTML>");
fclose(fpHtm1);
func_ReleaseWorkTable(ReqRespSeq);
//if(table->Content_Length!=0)
//{
//}
}
else
{
if(table->HtmStart==1)
{
fpHtm1=fopen(htmfilename,"a");
fprintf(fpHtm1,"%s",HTTPData);
fclose(fpHtm1);
}
}
}
else
printf("state error\n");
}
return(1);
}
//func_HTTP_ParseHTTPHtmlStart
BOOL func_HTTP_ParseHTTPHtmlStart(char* pStr, char** ppToken1, char** ppToken2)
{
*ppToken1=pStr;
char* pch=strstr(pStr, "<html");
if(pch) //找到匹配字符第一個' '
{
*ppToken2=pch;//ppToken2字符串從此開始
return TRUE;
}
else
{
pch=strstr(pStr, "<HTML");
if(pch) //找到匹配字符第一個' '
{
*ppToken2=pch;//ppToken2字符串從此開始
return TRUE;
}
}
return FALSE;
}
//func_HTTP_ParseHTTPStytleStart
BOOL func_HTTP_ParseHTTPStytleStart(char* pStr, char** ppToken1, char** ppToken2)
{
*ppToken1=pStr;
char* pch=strstr(pStr, "<TITLE>");
if(pch) //找到匹配字符第一個' '
{
//*pch='\0';//ppToken1字符串至此結束
//pch++;
*ppToken2=pch;//ppToken2字符串從此開始
return TRUE;
}
else
{
pch=strstr(pStr, "<title>");
if(pch) //找到匹配字符第一個' '
{
//*pch='\0';//ppToken1字符串至此結束
//pch++;
*ppToken2=pch;//ppToken2字符串從此開始
return TRUE;
}
}
return FALSE;
}
//func_HTTP_ParseHTTPStytleEnd
BOOL func_HTTP_ParseHTTPStytleEnd(char* pStr, char** ppToken1, char** ppToken2)
{
*ppToken1=pStr;
char* pch=strstr(pStr, "</TITLE>");
if(pch) //找到匹配字符第一個' '
{
*pch='\0';//ppToken1字符串至此結束
pch++;
*ppToken2=pch;//ppToken2字符串從此開始
return TRUE;
}
else
{
pch=strstr(pStr, "</title>");
if(pch) //找到匹配字符第一個' '
{
*pch='\0';//ppToken1字符串至此結束
pch++;
*ppToken2=pch;//ppToken2字符串從此開始
return TRUE;
}
}
return FALSE;
}
//func_HTTP_ParseHTTPHtmlEnd
BOOL func_HTTP_ParseHTTPHtmlEnd(char* pStr, char** ppToken1, char** ppToken2)
{
*ppToken1=pStr;
char* pch=strstr(pStr, "</html>");
if(pch) //找到匹配字符串第一個
{
*pch='\0';//ppToken1字符串至此結束
pch++;
*ppToken2=pch;//ppToken2字符串從此開始
return TRUE;
}
else
{
pch=strstr(pStr, "</HTML>");
if(pch) //找到匹配字符串第一個
{
*pch='\0';//ppToken1字符串至此結束
pch++;
*ppToken2=pch;//ppToken2字符串從此開始
return TRUE;
}
}
return FALSE;
}
int func_HTTP_Init()
{
int ii;
struct HTTPWorkTable_STRU *table=NULL;
for(ii=0;ii<MaxRequestNum;ii++)
{
table=&HTTPWorkTable[ii];
table->HTTPState=0;
strcpy(table->ResponseCode,"\0");
strcpy(table->Content_Type,"\0");
strcpy(table->Content_Coding,"\0");
table->HtmFileName="\0";
table->Content_Length=1;
table->ReqServiceBuffer=NULL;
table->RespServiceBuffer=NULL;
table->HtmStart=0;
table->GETStart=0;
table->GzipState=0;
HTTPRequestSeqFlag[ii]=0;
}
return(1);
}
int func_ReleaseWorkTable(int seq)
{
struct HTTPWorkTable_STRU *table=NULL;
table=&HTTPWorkTable[seq];
table->HTTPState=0;
strcpy(table->ResponseCode,"\0");
strcpy(table->Content_Type,"\0");
strcpy(table->Content_Coding,"\0");
table->HtmFileName="\0";
table->Content_Length=1;
table->ReqServiceBuffer=NULL;
table->RespServiceBuffer=NULL;
table->HtmStart=0;
table->GETStart=0;
table->GzipState=0;
//HTTPRequestSeqFlag[seq]=0;
return(1);
}
/*int func_ParseHeadFieldsLoc(char *MsgHead,char *str1,char *str2,char *str3,char *str4)
{
char *pch1=strstr(MsgHead, str1);
char *pch2=strstr(MsgHead, str2);
char *pch3=strstr(MsgHead, str3);
char *pch4=strstr(MsgHead, str4);
//排序......
if(pch) //找到匹配字符串
{
//*pch='\0';//ppToken1字符串至此結束
//pch++;
*ppToken2=pch;//ppToken2字符串從此開始
pch=strstr(ppToken2, "\r\n");
if(pch)
{
*pch='\0';//ppToken1字符串至此結束
//pch++;
//*ppToken2=pch;//ppToken2字符串從此開始
return TRUE;
}
}
return FALSE;
do
{
if((*(pToken3+len)=='H')&&(*(pToken3+len+1)=='o')&&(*(pToken3+len+2)=='s')
&&(*(pToken3+len+3)=='t')&&(*(pToken3+len+4)==':'))
{
yes=0;
temp2=pToken3;
Parse2(temp2+len+5, &pToken4);
printf("解析host--->%s\n",pToken4);
}
len++;
}while(yes);
}*/
int func_ParseAcceptEncodingGZIP(char* pStr, char** ppToken1, char** ppToken3)
{
*ppToken1=pStr;
char* pch=strstr(pStr, "Accept-Encoding: gzip");
if(pch) //找到匹配字符第一個' '
{
*pch='\0';//ppToken1字符串至此結束
pch++;
*ppToken3=pch;
return TRUE;
}
return FALSE;
}
int func_ParseContentEncodingGZIP(char* pStr, char** ppToken1, char** ppToken3)
{
*ppToken1=pStr;
char* pch=strstr(pStr, "Content-Encoding: gzip");
if(pch) //找到匹配字符第一個' '
{
*pch='\0';//ppToken1字符串至此結束
pch++;
*ppToken3=pch;
return TRUE;
}
return FALSE;
}
int func_GzipDecode(char* pStr, char** ppToken1)
{
return(1);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -