summaryrefslogtreecommitdiff
path: root/server/service.cpp
blob: d127e596c57a1429851bd01a8b09de99f6f22fc3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
 * service.cpp
 *
 *  Created on: 27.08.2012
 *      Author: savop
 */


#include "../include/service.h"
#include "../include/server.h"
#include "../include/tools.h"
#include <vdr/i18n.h>

namespace upnp {

cUPnPService::cUPnPService(Description serviceDescription)
: mMediaServer(NULL)
, mDeviceHandle(0)
, mServiceDescription(serviceDescription)
{
  cMediaServer::RegisterService(this);
}

cUPnPService::~cUPnPService(){}

void cUPnPService::Init(cMediaServer* server, UpnpDevice_Handle deviceHandle){
  mMediaServer = server;
  mDeviceHandle = deviceHandle;
}

void cUPnPService::Stop(){
  return;
}

void cUPnPService::SetError(Upnp_Action_Request* request, int error){
  request->ErrCode = error;
  switch(error){
    case UPNP_SOAP_E_INVALID_ACTION:
        strn0cpy(request->ErrStr,tr("Invalid action"),LINE_SIZE);
        break;
    case UPNP_SOAP_E_INVALID_ARGS:
        strn0cpy(request->ErrStr,tr("Invalid args"),LINE_SIZE);
        break;
    case UPNP_SOAP_E_INVALID_VAR:
        strn0cpy(request->ErrStr,tr("Invalid var"),LINE_SIZE);
        break;
    case UPNP_SOAP_E_ACTION_FAILED:
        strn0cpy(request->ErrStr,tr("Action failed"),LINE_SIZE);
        break;
    case UPNP_SOAP_E_ARGUMENT_INVALID:
        strn0cpy(request->ErrStr,tr("Argument value invalid"),LINE_SIZE);
        break;
    case UPNP_SOAP_E_ARGUMENT_OUT_OF_RANGE:
        strn0cpy(request->ErrStr,tr("Argument value out of range"),LINE_SIZE);
        break;
    case UPNP_SOAP_E_ACTION_NOT_IMPLEMENTED:
        strn0cpy(request->ErrStr,tr("Optional action not implemented"),LINE_SIZE);
        break;
    case UPNP_SOAP_E_OUT_OF_MEMORY:
        strn0cpy(request->ErrStr,tr("Out of memory"),LINE_SIZE);
        break;
    case UPNP_SOAP_E_HUMAN_INTERVENTION:
        strn0cpy(request->ErrStr,tr("Human intervention required"),LINE_SIZE);
        break;
    case UPNP_SOAP_E_STRING_TO_LONG:
        strn0cpy(request->ErrStr,tr("String argument to long"),LINE_SIZE);
        break;
    case UPNP_SOAP_E_NOT_AUTHORIZED:
        strn0cpy(request->ErrStr,tr("Action not authorized"),LINE_SIZE);
        break;
    case UPNP_SOAP_E_SIGNATURE_FAILURE:
        strn0cpy(request->ErrStr,tr("Signature failure"),LINE_SIZE);
        break;
    case UPNP_SOAP_E_SIGNATURE_MISSING:
        strn0cpy(request->ErrStr,tr("Signature missing"),LINE_SIZE);
        break;
    case UPNP_SOAP_E_NOT_ENCRYPTED:
        strn0cpy(request->ErrStr,tr("Not encrypted"),LINE_SIZE);
        break;
    case UPNP_SOAP_E_INVALID_SEQUENCE:
        strn0cpy(request->ErrStr,tr("Invalid sequence"),LINE_SIZE);
        break;
    case UPNP_SOAP_E_INVALID_CONTROL_URL:
        strn0cpy(request->ErrStr,tr("Invalid control URL"),LINE_SIZE);
        break;
    case UPNP_SOAP_E_NO_SUCH_SESSION:
        strn0cpy(request->ErrStr,tr("No such session"),LINE_SIZE);
        break;
    case UPNP_SOAP_E_OUT_OF_SYNC:
    default:
        strn0cpy(request->ErrStr,tr("Unknown error code. Contact the device manufacturer"),LINE_SIZE);
        break;
  }
}

int cUPnPService::ParseIntegerValue(IN IXML_Document* Document, IN std::string Item, OUT long& Value){
  std::string Val;
  int error = ixml::IxmlGetFirstDocumentItem(Document, Item, Val);

  if(error) return error;
  else {
    Value = atol(Val.c_str());
    return 0;
  }
}

int cUPnPService::ParseStringValue(IN IXML_Document* Document, IN std::string Item, OUT std::string& Value){
  return ixml::IxmlGetFirstDocumentItem(Document, Item, Value);
}

cUPnPService::Description::Description(string type, string id, string scpd, string control, string event)
: serviceType(type)
, serviceID(id)
, SCPDXML(scpd)
, controlDescriptor(control)
, eventSubscriberDescriptor(event)
{
}

}  // namespace upnp