void mupnp_upnpav_dmr_device_httprequestrecieved(mUpnpHttpRequest *httpReq)
{
	mUpnpAvRenderer *dmr;
	mUpnpDevice *dev;
	CG_UPNPAV_HTTP_LISTENER userHttpListener;

	dev = (mUpnpDevice *)mupnp_http_request_getuserdata(httpReq);
	if (!dev) {
		mupnp_device_httprequestrecieved(httpReq);
		return;
	}

	dmr = (mUpnpAvRenderer *)mupnp_device_getuserdata(dev);
	if (!dmr) {
		mupnp_device_httprequestrecieved(httpReq);
		return;
	}

	userHttpListener = mupnp_upnpav_dmr_gethttplistener(dmr);
	if (userHttpListener) {
		if (userHttpListener(httpReq))
			return;
	}

	mupnp_device_httprequestrecieved(httpReq);
}
/**
 * The function that calls all HTTP listener callback functions. Do not call
 * this from applications.
 *
 * @param httpReq The received HTTP request
 */
void mupnp_controlpoint_httprequestreceived(mUpnpHttpRequest *httpReq)
{
	mUpnpControlPoint *ctrlPoint = NULL;
	mUpnpNotifyRequest *notifyReq = NULL;
	mUpnpPropertyList *propList = NULL;
	mUpnpProperty *prop = NULL;
	mUpnpEventListenerList *eventListeners = NULL;
	const char *sid = NULL;
	long seq = 0;
	long timeout = 0;
	mUpnpDevice *dev = NULL;
	mUpnpService *service = NULL;
	int notifyListeners = 0;
	
	mupnp_log_debug_l4("Entering...\n");

	ctrlPoint = (mUpnpControlPoint *)mupnp_http_request_getuserdata(httpReq);

	mupnp_controlpoint_lock(ctrlPoint);

#if !defined(MUPNP_NOUSE_SUBSCRIPTION)
	if (mupnp_http_request_isnotifyrequest(httpReq) == true) {	
		notifyReq = mupnp_event_notify_request_new();
		mupnp_event_notify_request_sethttprequest(notifyReq, httpReq);

		/* Get service according to SID */
		sid = mupnp_event_notify_request_getsid(notifyReq);
		
		for (dev = mupnp_controlpoint_getdevices(ctrlPoint); 
		     dev != NULL;
		     dev = mupnp_device_next(dev))
		{
			service = mupnp_device_getservicebysid(dev, sid);
			if (service != NULL) break;
		}

		if (service != NULL) {
			/* We found a service */
			seq = mupnp_event_notify_request_getseq(notifyReq);
			
			/* Check that event key = previous + 1 */
			if (seq != 0 && seq != mupnp_service_geteventkey(service) + 1)
			{
				/* The sequence does not match, unsubscribe and subscribe */
				timeout = mupnp_service_getsubscriptiontimeout(service);
				mupnp_controlpoint_unsubscribe(ctrlPoint, service);
				mupnp_controlpoint_subscribe(ctrlPoint, service, timeout);
			} else {
				/* Wrap seq, so that assertion is true next time */
				if (seq == MUPNP_EVENT_MAX_SEQ) seq = 0;
				
				/* Set event key */
				mupnp_service_seteventkey(service, seq);
				
				notifyListeners = 1;
				propList = mupnp_event_notify_request_getpropertylist(notifyReq); 
				for (prop=mupnp_propertylist_gets(propList); 
				     prop != NULL; 
				     prop = mupnp_property_next(prop)) 
				{
					/* Update the service's state table from the event */
					mupnp_controlpoint_updatestatetablefromproperty(service, prop);
				}
			}
		}
		eventListeners = mupnp_controlpoint_geteventlisteners(ctrlPoint);
		mupnp_controlpoint_unlock(ctrlPoint);

		if (notifyListeners && propList != NULL) 
		{
			/* Notify listeners out of control point lock */
			for (prop=mupnp_propertylist_gets(propList); 
			     prop != NULL; 
			     prop = mupnp_property_next(prop)) 
			{
//                printf("\n%s\n%s\n%s\n", prop->name->value, prop->sid->value, prop->value->value);
				mupnp_eventlistenerlist_notify(ctrlPoint, eventListeners, prop);
			}
		}

		mupnp_event_notify_request_delete(notifyReq);
		mupnp_http_request_postokrequest(httpReq);
		
		return;
	}
#endif
	
	mupnp_controlpoint_unlock(ctrlPoint);
	mupnp_http_request_postbadrequest(httpReq);

	mupnp_log_debug_l4("Leaving...\n");
}
Beispiel #3
0
void upnp_clock_device_httprequestrecieved(mUpnpHttpRequest *httpReq)
{
	mUpnpTime currTime;
	mUpnpDevice *dev;
	char *uri;
	char content[2048];
	char sysTimeStr[SYSTEM_TIME_BUF_LEN];
	char serverName[MUPNP_SEVERNAME_MAXLEN];
	mUpnpHttpResponse *httpRes;
	BOOL postRet;
	
	dev = (mUpnpDevice *)mupnp_http_request_getuserdata(httpReq);

	uri = mupnp_http_request_geturi(httpReq);
	if (strcmp(uri, "/presentation") != 0) {
		mupnp_device_httprequestrecieved(httpReq);
		return;
	}

	currTime = mupnp_getcurrentsystemtime();

#if defined(HAVE_SNPRINTF)
	snprintf(content, sizeof(content),
#else
	sprintf(content,
#endif
		"<HTML>"
		"<HEAD>"
		"<TITLE>UPnP Clock Sample</TITLE>"
		"</HEAD>"
		"<META HTTP-EQUIV=\"Refresh\" CONTENT=\"1; URL=/presentation\">"
		"<BODY><CENTER>"
		"<H1>UPnP Clock Sample</H1>"
		"<TABLE border=\"0\" cellpadding=\"0\" cellspacing=\"0\">"
		"<TR>"
		"<TD style=\"width: 50px; height: 50px; background-color: rgb(176, 176, 176);\"></TD>"
		"<TD style=\"background-color: rgb(176, 176, 176);\"></TD>"
		"<TD style=\"width: 50px; height: 50px; background-color: rgb(176, 176, 176);\"></TD>"
		"</TR>"
		"<TR>"
		"<TD style=\"height: 50px; background-color: rgb(176, 176, 176);\"></TD>"
		"<TD style=\"height: 50px; background-color: rgb(221, 236, 245);\" align=\"center\"><H1>"
		"%s"
		"</H1></TD>"
		"<TD style=\"height: 50px; background-color: rgb(176, 176, 176);\"></TD>"
		"</TR>"
		"<TR>"
		"<TD style=\"height: 50px; background-color: rgb(176, 176, 176);\"></TD>"
		"<TD style=\"height: 50px; background-color: rgb(221, 236, 245);\" align=\"center\"><H3>"
		"Server : %s"
		"</H3></TD>"
		"<TD style=\"height: 30px; background-color: rgb(176, 176, 176);\"></TD>"
		"</TR>"
		"<TR>"
		"<TD style=\"width: 30px; height: 50px; background-color: rgb(176, 176, 176);\"></TD>"
		"<TD style=\"background-color: rgb(176, 176, 176);\"></TD>"
		"<TD style=\"width: 30px; height: 50px; background-color: rgb(176, 176, 176);\"></TD>"
		"</TR>"
		"</TABLE>"
		"<CENTER></BODY>"
		"</HTML>",
		GetSystemTimeString(currTime, sysTimeStr),
		mupnp_getservername(serverName, sizeof(serverName)));

	httpRes = mupnp_http_response_new();
	mupnp_http_response_setstatuscode(httpRes, CG_HTTP_STATUS_OK);
	mupnp_http_response_setcontent(httpRes, content);
	mupnp_http_response_setcontenttype(httpRes, "text/html");
	mupnp_http_response_setcontentlength(httpRes, strlen(content));
	postRet = mupnp_http_request_postresponse(httpReq, httpRes);
	mupnp_http_response_delete(httpRes);
}