- 论坛徽章:
- 1
|
- void bannedObject(DataBuffer* body)
- {
- #define OBJLEN 7 //"<object"
- #define ENDOBJLEN 9 //"</object>"
- #define CLASSIDLEN 5 //" classid="
- #define CLASSID_SIZE 42
- #define CLASSID_COLON_LEN 8 //"classid:"
- #define VIDEO_NUMBER 6
- const char * const CLASSID_COLON = "classid:";
- //const char * const FLASH_CLSID = "D27CDB6E-AE6D-11cf-96B8-444553540000";
-
- const char * const AVI_CLSID = "CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA";
- const char * const MPEG_CLSID = "05589FA1-C356-11CE-BF01-00AA0055595A";
- const char * const QTIME_CLSID = "02BF25D5-8C17-4B23-BC80-D3488ABDDC6B";
- const char * const MSMEDIAPLAYER_CLSID = "6BF52A52-394A-11d3-B153-00C04F79FAA6";
- const char * const WMA_CLSID = "22d6f312-b0f6-11d0-94ab-0080c74c7e95";
- const char * const RM_CLSID = "CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA";
- const char * const VIDEO[] = {AVI_CLSID,MPEG_CLSID,QTIME_CLSID,MSMEDIAPLAYER_CLSID,WMA_CLSID ,RM_CLSID};
- int bodylen = body->buffer_length;
- char* rawbody = body->data;
- char* bodylc = new char[bodylen + 128];
- if(bodylc == NULL)
- {
- return;
- }
- char *p;
- char *plc;
- int sizediff = 0;
- char *t,*t1,*t2,*t3;
- int find_string;
- for(p = rawbody,plc = bodylc;;)
- {
- t = strcasestr(p,"<object ");
- if(t == NULL)
- {
- break;
- }
- t1 = find_casestrings(t + OBJLEN ,2,&find_string," classid=","</object>");
- if(t1 == NULL)
- {
- break;
- }
- if(find_string == 0)
- {
- t2 = find_casestrings(t1 + CLASSIDLEN ,3,&find_string," ",">","</object>");
- if(t2 == NULL)
- {
- break;
- }
- if(find_string != 2)
- {
- t3 = strcasestr(t2,"</object>");
- if(t3 == NULL)
- {
- break;
- }
- char *classid;
- classid = t1 + CLASSIDLEN ;
- if(*classid == '\"')
- {
- classid++;
- }
- if(strncasecmp(classid,CLASSID_COLON,CLASSID_COLON_LEN) == 0)
- {
- classid += CLASSID_COLON_LEN;
- }
- bool isvideo = false;
- for(int i = 0;i < VIDEO_NUMBER; i++)
- {
- if( strncasecmp(classid,VIDEO[i],CLASSID_SIZE) == 0 )
- {
- isvideo = true;
- break;
- }
- }
- if( isvideo )
- {
- strncpy(plc,p,t1 - p );
- plc += (t1 - p);
- strncpy(plc,t2,t3 - t2 + ENDOBJLEN);
- plc += (t3 - t2 + ENDOBJLEN);
- p = t3 + ENDOBJLEN;
- sizediff -= (t2 - t1);
- }
- else
- {
- strncpy(plc,p ,t3 - p + ENDOBJLEN);
- plc += (t3 - p + ENDOBJLEN);
- p = t3 + ENDOBJLEN;
- }
- }
- else
- {
- strncpy(plc,p,t1 - p );
- plc += (t1 - p);
- strncpy(plc,"</object>" ,ENDOBJLEN);
- plc += ENDOBJLEN;
- p = t2 + ENDOBJLEN;
- sizediff -= (t2 - t1 + 1);
- }
- }
- else
- {
- strncpy(plc,p ,t1 - p + ENDOBJLEN);
- plc += (t1 - p + ENDOBJLEN);
- p = t1 + ENDOBJLEN;
- }
- }
- strcpy(plc,p);
- delete[] body->data;
- body->data = bodylc;
- body->buffer_length = body->buffer_length + sizediff;
- }
复制代码
[ 本帖最后由 yecheng_110 于 2006-11-29 13:03 编辑 ] |
|