From d260e7cb971bfeb031f40c3d61e4778dd326083d Mon Sep 17 00:00:00 2001 From: methodus Date: Mon, 29 Apr 2013 20:48:55 +0200 Subject: Added X_MS_MediaReceiverRegistrar service for device management --- httptnt/x_mrr_scpd.ecpp | 100 ++++++++++++++++++++++++++++++ include/mediaReceiverRegistrar.h | 50 +++++++++++++++ server/mediaReceiverRegistrar.cpp | 125 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 275 insertions(+) create mode 100644 httptnt/x_mrr_scpd.ecpp create mode 100644 include/mediaReceiverRegistrar.h create mode 100644 server/mediaReceiverRegistrar.cpp diff --git a/httptnt/x_mrr_scpd.ecpp b/httptnt/x_mrr_scpd.ecpp new file mode 100644 index 0000000..33168e2 --- /dev/null +++ b/httptnt/x_mrr_scpd.ecpp @@ -0,0 +1,100 @@ + +<# + +This is the Media Receiver Registrar Service Description File + +It contains the service description for the connection manager of the media server. + +#> +<{ reply.setContentType("text/xml"); }> + + + 1 + 0 + + + + IsAuthorized + + + DeviceID + in + A_ARG_TYPE_DeviceID + + + Result + out + A_ARG_TYPE_Result + + + +<# + + RegisterDevice + + + RegistrationReqMsg + in + A_ARG_TYPE_RegistrationReqMsg + + + RegistrationRespMsg + out + A_ARG_TYPE_RegistrationRespMsg + + + + + IsValidated + + + DeviceID + in + A_ARG_TYPE_DeviceID + + + Result + out + A_ARG_TYPE_Result + + + +#> + + + + A_ARG_TYPE_DeviceID + string + + + A_ARG_TYPE_Result + int + +<# + + A_ARG_TYPE_RegistrationReqMsg + bin.base64 + + + A_ARG_TYPE_RegistrationRespMsg + bin.base64 + + + ValidationSucceededUpdateID + ui4 + + + ValidationRevokedUpdateID + ui4 + +#> + + AuthorizationGrantedUpdateID + ui4 + + + AuthorizationDeniedUpdateID + ui4 + + + \ No newline at end of file diff --git a/include/mediaReceiverRegistrar.h b/include/mediaReceiverRegistrar.h new file mode 100644 index 0000000..63239b9 --- /dev/null +++ b/include/mediaReceiverRegistrar.h @@ -0,0 +1,50 @@ +/* + * mediaReceiverRegistrar.h + * + * Created on: 28.04.2013 + * Author: savop + */ + +#ifndef MEDIARECEIVERREGISTRAR_H_ +#define MEDIARECEIVERREGISTRAR_H_ + +#include "../include/service.h" +#include "../include/tools.h" + +namespace upnp { + +class cMediaReceiverRegistrar : public cUPnPService { + +public: + + cMediaReceiverRegistrar(); + virtual ~cMediaReceiverRegistrar(); + + virtual int Subscribe( + Upnp_Subscription_Request* Request ///< Information about the subscription + ); + + virtual int Execute( + Upnp_Action_Request* Request ///< Input and output parameters of an action + ); + +private: + + int IsAuthorized(Upnp_Action_Request* Request); + int RegisterDevice(Upnp_Action_Request* Request); + int IsValidated(Upnp_Action_Request* Request); + + uint32_t authorizationGrantedUpdateID; + uint32_t authorizationDeniedUpdateID; + + int UpdateGrantedUpdateID(); + int UpdateDeniedUpdateID(); + int TriggerNotificationForUpdateIDs(); + +} MediaReceiverRegistrar; + +} // namespace upnp + + + +#endif /* MEDIARECEIVERREGISTRAR_H_ */ diff --git a/server/mediaReceiverRegistrar.cpp b/server/mediaReceiverRegistrar.cpp new file mode 100644 index 0000000..4326bdd --- /dev/null +++ b/server/mediaReceiverRegistrar.cpp @@ -0,0 +1,125 @@ +/* + * mediaReceiverRegistrar.cpp + * + * Created on: 28.04.2013 + * Author: savop + */ + +#include "../include/server.h" +#include "../include/mediaReceiverRegistrar.h" +#include +#include + +namespace upnp { + +#define X_MS_MRR_ACTION_ISAUTHORIZED "IsAuthorized" +#define X_MS_MRR_ACTION_ISVALIDATED "IsValidated" +#define X_MS_MRR_ACTION_REGISTERDEVICE "RegisterDevice" + +cMediaReceiverRegistrar::cMediaReceiverRegistrar() +: cUPnPService( + cUPnPService::Description( + "urn:microsoft.com:service:X_MS_MediaReceiverRegistrar:1", + "urn:microsoft.com:serviceId:X_MS_MediaReceiverRegistrar", + "x_mrr_scpd.xml", + "x_mrr_control", + "x_mrr_event" + )), + authorizationGrantedUpdateID((uint32_t)time(NULL)), + authorizationDeniedUpdateID((uint32_t)time(NULL)) +{ +} + +cMediaReceiverRegistrar::~cMediaReceiverRegistrar(){ + +} + +int cMediaReceiverRegistrar::Subscribe(Upnp_Subscription_Request* request){ + IXML_Document* PropertySet = NULL; + + /* UpdateID for granted authorizations */ + UpnpAddToPropertySet(&PropertySet, "AuthorizationGrantedUpdateID", tools::ToString(authorizationGrantedUpdateID).c_str()); + /* UpdateID for denied authorizations */ + UpnpAddToPropertySet(&PropertySet, "AuthorizationDeniedUpdateID", tools::ToString(authorizationDeniedUpdateID).c_str()); + // Accept subscription + int ret = UpnpAcceptSubscriptionExt(this->mDeviceHandle, request->UDN, request->ServiceId, PropertySet, request->Sid); + + if(ret != UPNP_E_SUCCESS){ + esyslog("UPnP\tSubscription failed (Error code: %d)", ret); + } + + ixmlDocument_free(PropertySet); + return ret; +} + +int cMediaReceiverRegistrar::Execute(Upnp_Action_Request* request){ + if (request == NULL) { + esyslog("UPnP\tCMS Action Handler - request is null"); + return UPNP_E_BAD_REQUEST; + } + + if(!strcmp(request->ActionName, X_MS_MRR_ACTION_ISAUTHORIZED)) + return this->IsAuthorized(request); + if(!strcmp(request->ActionName, X_MS_MRR_ACTION_ISVALIDATED)) + return this->IsValidated(request); + if(!strcmp(request->ActionName, X_MS_MRR_ACTION_REGISTERDEVICE)) + return this->RegisterDevice(request); + + return UPNP_E_BAD_REQUEST; +} + +int cMediaReceiverRegistrar::UpdateDeniedUpdateID(){ + authorizationDeniedUpdateID = (uint32_t)time(NULL); + + return TriggerNotificationForUpdateIDs(); +} + +int cMediaReceiverRegistrar::UpdateGrantedUpdateID(){ + authorizationGrantedUpdateID = (uint32_t)time(NULL); + + return TriggerNotificationForUpdateIDs(); +} + +int cMediaReceiverRegistrar::TriggerNotificationForUpdateIDs(){ + IXML_Document* PropertySet = NULL; + + /* UpdateID for granted authorizations */ + UpnpAddToPropertySet(&PropertySet, "AuthorizationGrantedUpdateID", tools::ToString(authorizationGrantedUpdateID).c_str()); + /* UpdateID for denied authorizations */ + UpnpAddToPropertySet(&PropertySet, "AuthorizationDeniedUpdateID", tools::ToString(authorizationDeniedUpdateID).c_str()); + // Trigger notification + int ret = UpnpNotifyExt(this->mDeviceHandle, this->mMediaServer->GetDeviceUUID().c_str(), + this->mServiceDescription.serviceID.c_str(), PropertySet); + + if(ret != UPNP_E_SUCCESS){ + esyslog("UPnP\tNotification failed (Error code: %d)", ret); + } + + ixmlDocument_free(PropertySet); + return ret; +} + +int cMediaReceiverRegistrar::IsAuthorized(Upnp_Action_Request* request){ + std::stringstream ss; + + ss << "ActionName << "Response xmlns:u=\"" << GetServiceDescription().serviceType << "\">" + << " " << 1 << "" + << "ActionName << "Response>"; + + request->ActionResult = ixmlParseBuffer(ss.str().c_str()); + request->ErrCode = UPNP_E_SUCCESS; + + return request->ErrCode; +} + +int cMediaReceiverRegistrar::RegisterDevice(Upnp_Action_Request* request){ + SetError(request, UPNP_SOAP_E_ACTION_NOT_IMPLEMENTED); + return request->ErrCode; +} + +int cMediaReceiverRegistrar::IsValidated(Upnp_Action_Request* request){ + SetError(request, UPNP_SOAP_E_ACTION_NOT_IMPLEMENTED); + return request->ErrCode; +} + +} // namespace upnp -- cgit v1.2.3