diff options
author | methodus <methodus@web.de> | 2013-04-29 20:48:55 +0200 |
---|---|---|
committer | methodus <methodus@web.de> | 2013-04-29 20:48:55 +0200 |
commit | d260e7cb971bfeb031f40c3d61e4778dd326083d (patch) | |
tree | a6c8d69e6bd79bae916e4a99b7f5bbf601f620e4 | |
parent | 6457b2456fa09061afe3cc5360e74d0464fa1007 (diff) | |
download | vdr-plugin-upnp-d260e7cb971bfeb031f40c3d61e4778dd326083d.tar.gz vdr-plugin-upnp-d260e7cb971bfeb031f40c3d61e4778dd326083d.tar.bz2 |
Added X_MS_MediaReceiverRegistrar service for device management
-rw-r--r-- | httptnt/x_mrr_scpd.ecpp | 100 | ||||
-rw-r--r-- | include/mediaReceiverRegistrar.h | 50 | ||||
-rw-r--r-- | server/mediaReceiverRegistrar.cpp | 125 |
3 files changed, 275 insertions, 0 deletions
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 @@ +<?xml version = "1.0" encoding = "utf-8"?> +<# + +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"); }> +<scpd xmlns="urn:schemas-upnp-org:service-1-0"> + <specVersion> + <major>1</major> + <minor>0</minor> + </specVersion> + <actionList> + <action> + <name>IsAuthorized</name> + <argumentList> + <argument> + <name>DeviceID</name> + <direction>in</direction> + <relatedStateVariable>A_ARG_TYPE_DeviceID</relatedStateVariable> + </argument> + <argument> + <name>Result</name> + <direction>out</direction> + <relatedStateVariable>A_ARG_TYPE_Result</relatedStateVariable> + </argument> + </argumentList> + </action> +<# + <action> + <name>RegisterDevice</name> + <argumentList> + <argument> + <name>RegistrationReqMsg</name> + <direction>in</direction> + <relatedStateVariable>A_ARG_TYPE_RegistrationReqMsg</relatedStateVariable> + </argument> + <argument> + <name>RegistrationRespMsg</name> + <direction>out</direction> + <relatedStateVariable>A_ARG_TYPE_RegistrationRespMsg</relatedStateVariable> + </argument> + </argumentList> + </action> + <action> + <name>IsValidated</name> + <argumentList> + <argument> + <name>DeviceID</name> + <direction>in</direction> + <relatedStateVariable>A_ARG_TYPE_DeviceID</relatedStateVariable> + </argument> + <argument> + <name>Result</name> + <direction>out</direction> + <relatedStateVariable>A_ARG_TYPE_Result</relatedStateVariable> + </argument> + </argumentList> + </action> +#> + </actionList> + <serviceStateTable> + <stateVariable sendEvents="no"> + <name>A_ARG_TYPE_DeviceID</name> + <dataType>string</dataType> + </stateVariable> + <stateVariable sendEvents="no"> + <name>A_ARG_TYPE_Result</name> + <dataType>int</dataType> + </stateVariable> +<# + <stateVariable sendEvents="no"> + <name>A_ARG_TYPE_RegistrationReqMsg</name> + <dataType>bin.base64</dataType> + </stateVariable> + <stateVariable sendEvents="no"> + <name>A_ARG_TYPE_RegistrationRespMsg</name> + <dataType>bin.base64</dataType> + </stateVariable> + <stateVariable sendEvents="yes"> + <name>ValidationSucceededUpdateID</name> + <dataType>ui4</dataType> + </stateVariable> + <stateVariable sendEvents="yes"> + <name>ValidationRevokedUpdateID</name> + <dataType>ui4</dataType> + </stateVariable> +#> + <stateVariable sendEvents="yes"> + <name>AuthorizationGrantedUpdateID</name> + <dataType>ui4</dataType> + </stateVariable> + <stateVariable sendEvents="yes"> + <name>AuthorizationDeniedUpdateID</name> + <dataType>ui4</dataType> + </stateVariable> + </serviceStateTable> +</scpd>
\ 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 <sstream> +#include <time.h> + +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 << "<u:" << request->ActionName << "Response xmlns:u=\"" << GetServiceDescription().serviceType << "\">" + << " <Result>" << 1 << "</Result>" + << "</u:" << request->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 |