示例#1
0
int SSDPNotifyBye::Process(struct sockaddr* sender, std::vector<SSDP_HTTP_HEADER*> msgheaders){
	int ret = 0;
	u8* usn;
	int usnlen;
	ssdpuuid uuid;
	
	//Get the Device USN (Unique Service Name)	
	ret=GetHeaderValueFromCollection(msgheaders, (u8*)"USN", 3, &usn, &usnlen);
	if(ret != 0 || usnlen<=0){
		ret = -1;
		goto EXIT;
	}
	
	ret = ParseUSN(usn, usnlen, &uuid);
	if(ret < 0){
		goto EXIT; //Unknown format
	}
		
	//Delete the UUID
	//Specs : If a control point has received at least one ssdp:byebye message of a root device, any of its embedded devices or any of its
	//        services then the control point can assume that all are no longer available.
	mDB->DeleteDevicesByUuid(uuid.uuid, uuid.uuidlen);
	
	printf("SSDPNotifyBey\n");
	
	
EXIT:
	return ret;
}
示例#2
0
int SSDPNotifyAlive::Process(struct sockaddr* sender, std::vector<SSDP_HTTP_HEADER*> msgheaders){
    u8* usn;
    int usnlen;
    int ret;
    u8* val;
    int vallen;
    int cache;
    SSDPDBDevice *device;
    //SSDPDBService *service;
    ssdpuuid uuid;



    //Get the Device USN (Unique Service Name)
    ret=GetHeaderValueFromCollection(msgheaders, (u8*)"USN", 3, &usn, &usnlen);
    if(ret != 0 || usnlen<=0){
        ret = -1;
        return ret;
    }

    ret = ParseUSN(usn, usnlen, &uuid);
    if(ret < 0){
        return ret;//Unknown format
    }


    mDB->Lock();


    //Device or service update

    //Is the device already registered ?
    device = mDB->GetDevice(usn, usnlen);

    GetHeaderValueFromCollection(msgheaders, (u8*)"CACHE-CONTROL", 13, &val, &vallen);
    cache = cachecontroltoi(val, vallen);

    if(device == NULL && cache >= 0){ //cachecontrol is mandatory, if not formatted well we ignore all to avoid conflicts with the db cleanup
        device = mDB->InsertDevice(usn, usnlen);

        memcpy(&(device->ip), (u8*)sender->sa_data+2, 4);
        memcpy(&(device->port), sender->sa_data, 2);
        device->port = ntohs(device->port);

        //uuid
        device->uuid.assign((const char*)uuid.uuid, uuid.uuidlen);
        device->isroot = uuid.isrootdevice;
        device->isdevice = uuid.isdevice;
        device->isservice = uuid.isservice;
        device->type.assign((const char*)uuid.type, uuid.typelen);
        if(!device->isroot){
            device->urn.assign((const char*)uuid.fullurn, uuid.fullurnlen);
            device->version.assign((const char*)uuid.version, uuid.versionlen);
        }
        //host
        GetHeaderValueFromCollection(msgheaders, (u8*)"HOST", 4, &val, &vallen);
        device->host.assign((const char*)val, vallen);
        //Location
        GetHeaderValueFromCollection(msgheaders, (u8*)"LOCATION", 8, &val, &vallen);
        device->location.assign((const char*)val, vallen);


        //Workaround for MusicPal bug
        size_t wrongdev = device->urn.find("schemas-upnp-org:device:RenderingControl:1");
        if(wrongdev != std::string::npos){
            //replace schemas-upnp-org:device:RenderingControl:1 with schemas-upnp-org:service:RenderingControl:1
            char buf[] = "schemas-upnp-org:service:RenderingControl:1";
            device->urn.replace(wrongdev, sizeof(buf), buf);
        }
        //end workaround

        mDB->Unlock();
        //Inform the observers
        if(uuid.isdevice || uuid.isrootdevice){
            mDB->DeviceUpdate(device);
        }else if(uuid.isservice){
            mDB->ServiceUpdate(device);
        }

    }
    else
    {
        mDB->Unlock();
    }

    //always update cache control
    if(device != NULL && cache >= 0){
        mDB->UpdateCacheControl(uuid.uuid, uuid.uuidlen, cache);
    }

    //printf("%s\n", device->uuid.c_str());

    


    //printf("SSDPNotifyAlive\n");
    return ret;
}
示例#3
0
int SSDPSearchResp::Process(struct sockaddr* sender, std::vector<SSDP_HTTP_HEADER*> msgheaders){
	u8* usn;
	int usnlen;
	int ret;
	u8* val;
	int vallen;
	int cache;
	SSDPDBDevice *device;
	//SSDPDBService *service;
	ssdpuuid uuid;
	
	
	
	//Get the Device USN (Unique Service Name)	
	ret=GetHeaderValueFromCollection(msgheaders, (u8*)"USN", 3, &usn, &usnlen);
	if(ret != 0 || usnlen<=0){
		ret = -1;
		goto EXIT;
	}
	
	ret = ParseUSN(usn, usnlen, &uuid);
	if(ret < 0){
		goto EXIT; //Unknown format
	}
	
	
	mDB->Lock();	
	
	
	//Device or service update
	
	//Is the device already registered ?
	device = mDB->GetDevice(usn, usnlen);
	
	GetHeaderValueFromCollection(msgheaders, (u8*)"CACHE-CONTROL", 13, &val, &vallen);
	cache = cachecontroltoi(val, vallen);
	
	if(device == NULL && cache >= 0){ //cachecontrol is mandatory, if not formatted well we ignore all to avoid conflicts with the db cleanup
		device = mDB->InsertDevice(usn, usnlen);	
		memcpy(&(device->ip), (u8*)sender->sa_data+2, 4);
		memcpy(&(device->port), sender->sa_data, 2);
		device->port = ntohs(device->port);
		
		//uuid
		device->uuid.assign((const char*)uuid.uuid, uuid.uuidlen);
		device->isroot = uuid.isrootdevice;		
		device->isdevice = uuid.isdevice;
		device->isservice = uuid.isservice;
		device->type.assign((const char*)uuid.type, uuid.typelen);	
		if(!device->isroot){
			device->urn.assign((const char*)uuid.fullurn, uuid.fullurnlen);
			device->version.assign((const char*)uuid.version, uuid.versionlen);
		}
		//host
		GetHeaderValueFromCollection(msgheaders, (u8*)"HOST", 4, &val, &vallen);
		device->host.assign((const char*)val, vallen);
		//Location
		GetHeaderValueFromCollection(msgheaders, (u8*)"LOCATION", 8, &val, &vallen);
		device->location.assign((const char*)val, vallen);
		
		
		//Workaround for MusicPal bug
		int wrongloc = device->location.find("://127.0.0.1");
		if(wrongloc > 0){
			//replace 127.0.0.1 with source ip address
			char ipbuf[255];
			sprintf(ipbuf, "://%d.%d.%d.%d", (unsigned char)((char*)&(device->ip))[0], (unsigned char)((char*)&(device->ip))[1], (unsigned char)((char*)&(device->ip))[2], (unsigned char)((char*)&(device->ip))[3] );
			device->location.replace(wrongloc, 12, ipbuf);
		}
		//end workaround	
#pragma mark - Jon's chanages
		//Workaround for another MusicPal bug
		int wrongdev = device->urn.find("schemas-upnp-org:device:RenderingControl:1");
		if(wrongdev > 0){
			//replace schemas-upnp-org:device:RenderingControl:1 with schemas-upnp-org:service:RenderingControl:1
			char buf[] = "schemas-upnp-org:service:RenderingControl:1";
			device->urn.replace(wrongdev, sizeof(buf), buf);
		}
		//end workaround			
		
        // This is the place where we used to inform the observers

	}

    // Always Inform the observers
    if(uuid.isdevice || uuid.isrootdevice){
        mDB->DeviceUpdate(device);
    }else if(uuid.isservice){
        mDB->ServiceUpdate(device);
    }
    // End changes
    
	//always update cache control
	if(device != NULL && cache >= 0){
		mDB->UpdateCacheControl(uuid.uuid, uuid.uuidlen, cache);
	}
	
	//printf("%s\n", device->uuid.c_str());
	
	mDB->Unlock();	
	
	
EXIT:
	return ret;
}