00001 #include "mythsoap.h"
00002 #include <iostream>
00003
00004 using namespace std;
00005
00006 void MythSoap::doSoapRequest(QString host, QString path, QString soapAction,
00007 QString query)
00008 {
00009 connect(&http, SIGNAL(done(bool)), this, SLOT(httpDone(bool)));
00010
00011 QHttpRequestHeader header("POST", path);
00012 header.setValue("Host", host);
00013 header.setValue("SOAPAction", soapAction);
00014 header.setContentType("text/xml");
00015
00016 http.setHost(host);
00017 QByteArray bArray(query.utf8());
00018 bArray.resize(bArray.size() - 1);
00019 http.request(header, bArray);
00020 }
00021
00022 QByteArray MythSoap::getResponseData()
00023 {
00024 return m_data;
00025 }
00026
00027 bool MythSoap::isDone()
00028 {
00029 return m_done;
00030 }
00031
00032 bool MythSoap::hasError()
00033 {
00034 return m_error;
00035 }
00036
00037 void MythSoap::httpDone(bool error)
00038 {
00039 if (error)
00040 {
00041 cerr << "Error in mythsoap.o retrieving data: " << http.errorString() << endl << flush;
00042 m_error = true;
00043 }
00044 else
00045 {
00046 const Q_ULONG len = http.bytesAvailable();
00047
00048 char* buffer = new char[len + 1];
00049 if (buffer)
00050 {
00051 http.readBlock(buffer, len);
00052 buffer[len] = '\0';
00053 m_data.assign(buffer, len + 1);
00054 }
00055 else
00056 {
00057 cerr << "Failed to alloc memory in mythsoap.o" << endl;
00058 }
00059 }
00060 m_done = true;
00061 }
00062
00063 MythSoap::MythSoap()
00064 {
00065 m_done = false;
00066 m_error = false;
00067 }