待解决

来源:互联网 发布:编程珠玑百度云 编辑:程序博客网 时间:2024/04/28 20:23

 
int CCrawlAdapter::MediaMath(const char* strData,const char* url,const char* Ip,const char* domain)
{    
    if(strData == NULL || strlen(strData) == 0)
        return -1;

    int size = strlen(strData);
    char* pData = new char[size + 1];
    memcpy(pData,strData,size);
    pData[size] = 0;
    char* info = pData;

    NetMediaAlarm_t medAlarm;
    memset(&medAlarm,0,sizeof(medAlarm));
    strcpy(medAlarm.SubIP,Ip);
    strcpy(medAlarm.Domain,domain);
    strcpy(medAlarm.PageUrl,url);

    int   len = 0;
    while(len < size)
    {
        LOWCODE(pData[len],pData[len]);
        len++;
    }
    len=0;

// embed img
    //去头
    while(*pData != '<' && *pData != 0)
    {
        pData++;
    }
    if(*pData == 0)
    {
        delete []info;
        info = NULL;
        pData = NULL;
        return 0;
    }
    char* pStart = NULL;
    char* pEnd = NULL;
 
    //先找图片
    pStart = strstr(pData,"<img");
    if(pStart != NULL)
    {        
        while(pStart != NULL && *pStart != '/0')
        {    
            len = 0;
            pStart += 4;
            pStart = strstr(pStart ,"src");
            if(pStart != NULL)
            {
                pStart +=3;

                while(*pStart != '/"' && *pStart != '/'' && *pStart != '/' && ( *pStart < 'a' || *pStart >'z')  && *pStart != '/0' )
                    pStart++;

                if(*pStart == 0)
                {
                    break;
                }else if (*pStart == '/"' || *pStart == '/'')
                {
                    pStart++;

                    while( (*pStart <'a' || *pStart > 'z') && *pStart != '/' && *pStart != '>' && *pStart != '#' && *pStart != '/"' && *pStart != '/'')
                    {
                        pStart++;
                    }
                    pEnd = pStart;
                    while(*pEnd != '/"' && *pEnd != '/'' /*&& *pEnd != 0*/ && *pEnd != ' ' && *pEnd != '>' && *pEnd != '#')
                    {
                        pEnd++;
                        len++;
                    }
                }else if (*pStart == '/' || ( *pStart > 'a' && *pStart <'z') )
                {
                    pEnd = pStart;
                    while(*pEnd != ' ' && *pEnd != '>' && *pEnd != ',' /*&& *pEnd != 0*/)
                    {
                        pEnd++;
                        len++;
                    }
                }
                if(len > 0)
                {
                    GetCurTime(medAlarm.MediaDate,20);
                    char tmp[512] = {0};
                    memcpy(tmp,pStart,len);
                    MediaParam mTmp;
                    memset(&mTmp,0,sizeof(MediaParam));
                    if(strstr(tmp,"http://") == NULL)
                    {
                        int urllen = len + 9 + strlen(domain);
                        char* p = new char[urllen+1];
                        if(tmp[0] == '/')
                        {
                            snprintf(p,urllen+1,"http://%s%s",domain,tmp);
                        }
                        else
                        {
                            snprintf(p,urllen+1,"http://%s/%s",domain,tmp);
                        }

                        p[urllen] = 0;
                        snprintf(medAlarm.MediaUrl,512,"%s",p);
                        mTmp = GetImgSize(p,urllen);
                        snprintf(medAlarm.justsign,64,"%d %s",mTmp.nsize,mTmp.lastModified);
                        snprintf(medAlarm.stype,8,"%s",mTmp.stype);
                        Alarm(medAlarm,IM_RM_RESPONSE_MATCHIMAGE);
                        delete []p;
                        p = NULL;
                    }
                    else
                    {
                        char* p2 = strstr(tmp,"http://");
                        strcpy(medAlarm.MediaUrl,p2);
                        mTmp = GetImgSize(p2,strlen(p2));
                        snprintf(medAlarm.justsign,64,"%d %s",mTmp.nsize,mTmp.lastModified);
                        snprintf(medAlarm.stype,8,"%s",mTmp.stype);
                        Alarm(medAlarm,IM_RM_RESPONSE_MATCHIMAGE);
                    }
                }
                if(pStart != NULL && *pStart != 0)
                    pStart = strstr(pStart,"<img");
            }
        }
    }
    
    //vedio
    pData = (char*)info;

    while(*pData != '<')
        pData++;
    pStart = strstr(pData,"<embed");

    if(pStart == NULL)    
    {
        delete []info;
        info = NULL;
        pData = NULL;
        return 0;
    }

    while(pStart != NULL && *pStart != '/0')
    {
        len = 0;
        pStart += 6;
        pStart = strstr(pStart ,"src");
        if(pData != NULL)
        {
            pStart +=3;
            while( *pStart != '/"' && *pStart != '/'' && *pStart != '/' && ( *pStart < 'a' || *pStart >'z')  && *pStart != '/0')
                pStart++;

            if(*pStart == 0)
            {
                break;
            }else if (*pStart == '/"' || *pStart == '/'')
            {
                pStart++;

                while( (*pStart <'a' || *pStart > 'z') && *pStart != '/' && *pStart != '>' && *pStart != '#' && *pStart != '/"' && *pStart != '/'')
                {
                    pStart++;
                }
                pEnd = pStart;
                while(*pEnd != '/"' && *pEnd != '/'' /*&& *pEnd != 0*/ && *pEnd != ' ' && *pEnd != '>' && *pEnd != '#' )
                {
                    pEnd++;
                    len++;
                }
            }else if (*pStart == '/' || ( *pStart >= 'a' && *pStart <='z'))
            {
                pEnd = pStart;
                while(*pEnd != ' ' && *pEnd != '>' && *pEnd != ',' /*&& *pEnd != 0*/)
                {
                    pEnd++;
                    len++;
                }
            }
            if(len > 0)
            {
                GetCurTime(medAlarm.MediaDate,20);
                char tmp[512] = {0};
                memcpy(tmp,pStart,len);

                MediaParam mTmp;
                memset(&mTmp,0,sizeof(MediaParam));

                if(strstr(tmp,"http://") == NULL)
                {
                    int urllen = len + 9 + strlen(domain);
                    char* p = new char[urllen+1];
                    if(tmp[0] == '/')
                    {
                        snprintf(p,urllen+1,"http://%s%s",domain,tmp);
                    }
                    else
                    {
                        snprintf(p,urllen+1,"http://%s/%s",domain,tmp);
                    }
                    p[urllen] = 0;
                    snprintf(medAlarm.MediaUrl,512,"%s",p);            
                    mTmp = GetImgSize(p,urllen);
                    snprintf(medAlarm.justsign,64,"%d %s",mTmp.nsize,mTmp.lastModified);
                    snprintf(medAlarm.stype,8,"%s",mTmp.stype);
                    Alarm(medAlarm,IM_RM_RESPONSE_MATCHVODIEO);
                    delete []p;
                    p = NULL;
                }
                else
                {
                    char* p2 = strstr(tmp,"http://");
                    strcpy(medAlarm.MediaUrl,p2);
                    mTmp = GetImgSize(p2,strlen(p2));
                    snprintf(medAlarm.justsign,64,"%d %s",mTmp.nsize,mTmp.lastModified);
                    snprintf(medAlarm.stype,8,"%s",mTmp.stype);
                    Alarm(medAlarm,IM_RM_RESPONSE_MATCHVODIEO);
                }
            }
            if(*pStart != 0 && pStart != NULL)
                pStart = strstr(pStart,"<embed");
        }
    }
    delete []info;
    info = NULL;
    pData = NULL;

    return 1;

}