summaryrefslogtreecommitdiff
path: root/upnpcomponents/upnpservice.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'upnpcomponents/upnpservice.cpp')
-rw-r--r--upnpcomponents/upnpservice.cpp118
1 files changed, 118 insertions, 0 deletions
diff --git a/upnpcomponents/upnpservice.cpp b/upnpcomponents/upnpservice.cpp
new file mode 100644
index 0000000..a1d6a47
--- /dev/null
+++ b/upnpcomponents/upnpservice.cpp
@@ -0,0 +1,118 @@
+/*
+ * File: upnpservice.cpp
+ * Author: savop
+ *
+ * Created on 21. August 2009, 18:38
+ */
+
+#include "upnpservice.h"
+#include "../common.h"
+#include "../misc/util.h"
+
+cUpnpService::cUpnpService(UpnpDevice_Handle DeviceHandle) {
+ this->mDeviceHandle = DeviceHandle;
+}
+
+int cUpnpService::parseIntegerValue(IXML_Document* Document, const char* Item, int* Value){
+ char* Val = NULL;
+ int Error = 0;
+
+ Val = ixmlGetFirstDocumentItem(Document, Item, &Error);
+
+ if(Error != 0){
+ ERROR("Error while parsing integer value for item=%s", Item);
+ Error = -1;
+ }
+ else if(!Value){
+ WARNING("Value %s empty!", Item);
+ *Value = 0;
+ }
+ else {
+ *Value = atoi(Val);
+ free(Val);
+ }
+ return Error;
+}
+
+int cUpnpService::parseStringValue(IXML_Document* Document, const char* Item, char** Value){
+ char* Val = NULL;
+ int Error = 0;
+
+ Val = ixmlGetFirstDocumentItem(Document, Item, &Error);
+
+ if(Error != 0){
+ ERROR("Error while parsing string value for item=%s", Item);
+ Error = -1;
+ }
+ else if(!Val){
+ WARNING("Value %s empty!", Item);
+ *Value = NULL;
+ }
+ else {
+ *Value = strdup(Val);
+ free(Val);
+ }
+
+ return Error;
+}
+
+void cUpnpService::setError(Upnp_Action_Request* Request, int Error){
+ Request->ErrCode = Error;
+ switch(Error){
+ case UPNP_SOAP_E_INVALID_ACTION:
+ strn0cpy(Request->ErrStr,_("Invalid action"),LINE_SIZE);
+ break;
+ case UPNP_SOAP_E_INVALID_ARGS:
+ strn0cpy(Request->ErrStr,_("Invalid args"),LINE_SIZE);
+ break;
+ case UPNP_SOAP_E_INVALID_VAR:
+ strn0cpy(Request->ErrStr,_("Invalid var"),LINE_SIZE);
+ break;
+ case UPNP_SOAP_E_ACTION_FAILED:
+ strn0cpy(Request->ErrStr,_("Action failed"),LINE_SIZE);
+ break;
+ case UPNP_SOAP_E_ARGUMENT_INVALID:
+ strn0cpy(Request->ErrStr,_("Argument value invalid"),LINE_SIZE);
+ break;
+ case UPNP_SOAP_E_ARGUMENT_OUT_OF_RANGE:
+ strn0cpy(Request->ErrStr,_("Argument value out of range"),LINE_SIZE);
+ break;
+ case UPNP_SOAP_E_ACTION_NOT_IMPLEMENTED:
+ strn0cpy(Request->ErrStr,_("Optional action not implemented"),LINE_SIZE);
+ break;
+ case UPNP_SOAP_E_OUT_OF_MEMORY:
+ strn0cpy(Request->ErrStr,_("Out of memory"),LINE_SIZE);
+ break;
+ case UPNP_SOAP_E_HUMAN_INTERVENTION:
+ strn0cpy(Request->ErrStr,_("Human intervention required"),LINE_SIZE);
+ break;
+ case UPNP_SOAP_E_STRING_TO_LONG:
+ strn0cpy(Request->ErrStr,_("String argument to long"),LINE_SIZE);
+ break;
+ case UPNP_SOAP_E_NOT_AUTHORIZED:
+ strn0cpy(Request->ErrStr,_("Action not authorized"),LINE_SIZE);
+ break;
+ case UPNP_SOAP_E_SIGNATURE_FAILURE:
+ strn0cpy(Request->ErrStr,_("Signature failure"),LINE_SIZE);
+ break;
+ case UPNP_SOAP_E_SIGNATURE_MISSING:
+ strn0cpy(Request->ErrStr,_("Signature missing"),LINE_SIZE);
+ break;
+ case UPNP_SOAP_E_NOT_ENCRYPTED:
+ strn0cpy(Request->ErrStr,_("Not encrypted"),LINE_SIZE);
+ break;
+ case UPNP_SOAP_E_INVALID_SEQUENCE:
+ strn0cpy(Request->ErrStr,_("Invalid sequence"),LINE_SIZE);
+ break;
+ case UPNP_SOAP_E_INVALID_CONTROL_URL:
+ strn0cpy(Request->ErrStr,_("Invalid control URL"),LINE_SIZE);
+ break;
+ case UPNP_SOAP_E_NO_SUCH_SESSION:
+ strn0cpy(Request->ErrStr,_("No such session"),LINE_SIZE);
+ break;
+ case UPNP_SOAP_E_OUT_OF_SYNC:
+ default:
+ strn0cpy(Request->ErrStr,_("Unknown error code. Contact the device manufacturer"),LINE_SIZE);
+ break;
+ }
+} \ No newline at end of file