00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "brisaeventmessage.h"
00030
00031 using namespace BrisaUpnp;
00032
00033 BrisaEventMessage::BrisaEventMessage(BrisaEventSubscription &subscription,
00034 const QList<BrisaStateVariable *> *variables, QObject *parent) :
00035 BrisaAbstractEventMessage(parent),
00036 SEQ(subscription.getNextSeq()),
00037 VARIABLES(variables),
00038 subscription(subscription)
00039 {
00040 }
00041
00042 #ifdef USE_NEW_BRISA_WEBSERVER
00043
00044 QByteArray BrisaEventMessage::getRequestMessage() const
00045 {
00046 static const QString genericRequest = "NOTIFY %1 HTTP/1.1\r\n"
00047 "HOST: %2:%3\r\n"
00048 "Connection: close\r\n"
00049 "CONTENT-TYPE: text/xml\r\n"
00050 "CONTENT-LENGTH: %4\r\n"
00051 "NT: upnp:event\r\n"
00052 "NTS: upnp:propchange\r\n"
00053 "SID: uuid:%5\r\n"
00054 "SEQ: %6\r\n"
00055 "\r\n"
00056 "%7";
00057
00058 QString body = "<?xml version=\"1.0\"?>\r\n"
00059 "<e:propertyset xmlns:e=\"urn:schemas-upnp-org:event-1-0\">\r\n";
00060
00061 for (QList<BrisaStateVariable *>::const_iterator i =
00062 VARIABLES->begin(); i != VARIABLES->end(); ++i) {
00063 QString variableName = (*i)->getAttribute(BrisaStateVariable::Name);
00064
00065 body.append(" <e:property>\r\n"
00066 " <" + variableName + ">"
00067 + (*i)->getAttribute(BrisaStateVariable::Value)
00068 + "</" + variableName + ">\r\n"
00069 " </e:property>\r\n"
00070 );
00071 }
00072
00073 body.append("</e:propertyset>\r\n");
00074
00075 QUrl url(callback);
00076
00077 return genericRequest.arg(url.path(),
00078 url.host(),
00079 QString::number(url.port()),
00080 QString::number(body.size()),
00081 subscription.getSid(),
00082 QString::number(SEQ),
00083 body
00084 ).toAscii();
00085 }
00086
00087 #else // !USE_NEW_BRISA_WEBSERVER
00088
00089 QHttpRequestHeader BrisaEventMessage::getMessageHeader() const {
00090
00091 QString callback = "";
00092 QStringList urlList = subscription.getCallbackUrls();
00093 if (urlList.size() > 0)
00094 callback = urlList[0];
00095
00096 QUrl url(callback);
00097
00098
00099 QHttpRequestHeader header("NOTIFY", url.path());
00100
00101 header.setValue("HOST", url.host() + ":" + QString::number(url.port()));
00102 header.setValue("CONTENT-TYPE", "text/xml");
00103 header.setValue("CONTENT-LENGTH", QString::number(
00104 this->getMessageBody().size()));
00105 header.setValue("NT", "upnp:event");
00106 header.setValue("NTS", "upnp:propchange");
00107 header.setValue("SID", "uuid:" + subscription.getSid());
00108 header.setValue("SEQ", QString::number(SEQ));
00109
00110 return header;
00111 }
00112
00113 QByteArray BrisaEventMessage::getMessageBody() const {
00114 QByteArray body;
00115
00116 body.append("<?xml version=\"1.0\"?>\r\n");
00117 body.append(
00118 "<e:propertyset xmlns:e=\"urn:schemas-upnp-org:event-1-0\">\r\n");
00119
00120 for (QList<BrisaStateVariable *>::const_iterator i =
00121 this->VARIABLES->begin(); i != this->VARIABLES->end(); ++i) {
00122 QString variableName = (*i)->getAttribute(BrisaStateVariable::Name);
00123 QString variableValue = (*i)->getAttribute(BrisaStateVariable::Value);
00124
00125 body.append(" <e:property>\r\n");
00126 body.append(" <" + variableName + ">" + variableValue + "</"
00127 + variableName + ">\r\n");
00128 body.append(" </e:property>\r\n");
00129 }
00130
00131 body.append("</e:propertyset>\r\n");
00132
00133 return body;
00134 }
00135
00136 #endif // USE_NEW_BRISA_WEBSERVER