You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
86 lines
2.7 KiB
86 lines
2.7 KiB
#include "protocolHTTP.h"
|
|
|
|
#define LOG( X ) basicLogCollection::getInstance()->Log( "protocolHTTP", this, X )
|
|
#define LOG_ERROR( X ) basicLogCollection::getInstance()->Log( "protocolHTTP", this, _LOG_ERROR, X )
|
|
// Constructor
|
|
protocolHTTP::protocolHTTP(config_setting_t *Settings){
|
|
m_pSettings = Settings;
|
|
config_setting_t * pSetting;
|
|
m_pCurlPostType = (CSTR)malloc(128);
|
|
if( m_pCurlPostType == NULL ) return;
|
|
if (!config_setting_lookup_string(m_pSettings, HTTP_PROTOCOL_CONTENT_SETTINGS, (const char**)&m_pCurlPostType)){
|
|
sprintf( m_pCurlPostType, DEFAULT_CONTENT_TYPE );
|
|
pSetting = config_setting_add(m_pSettings, HTTP_PROTOCOL_CONTENT_SETTINGS, CONFIG_TYPE_STRING);
|
|
config_setting_set_string( pSetting, m_pCurlPostType );
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
};
|
|
LOG( m_pCurlPostType );
|
|
basicSettingsProvider::getInstance()->validate();
|
|
m_pHttpAccessManager = curlRequestsManager::getInstance();
|
|
};
|
|
|
|
protocolHTTP::~protocolHTTP(){
|
|
delete m_pHttpAccessManager;
|
|
m_pHttpAccessManager = NULL;
|
|
};
|
|
|
|
bool protocolHTTP::issueGet(CSTR URL){
|
|
curlRequest *tRequest = new curlRequest(URL, m_pCurlPostType );
|
|
if (tRequest != NULL){
|
|
tRequest->setHandler(this, &protocolHTTP::requestFinished, tRequest);
|
|
if (m_pHttpAccessManager->get(tRequest)){
|
|
//LOG("GET Req");
|
|
} else {
|
|
LOG_ERROR("Cannot issue request!");
|
|
};
|
|
};
|
|
return true;
|
|
};
|
|
|
|
bool protocolHTTP::issuePost(CSTR URL, char *Buffer, int &BufferSize ){
|
|
curlRequest *tRequest = new curlRequest(URL, m_pCurlPostType);
|
|
if (tRequest != NULL){
|
|
tRequest->setPOST( Buffer, BufferSize );
|
|
tRequest->setHandler(this, &protocolHTTP::requestFinished, tRequest );
|
|
if (m_pHttpAccessManager->get(tRequest)){
|
|
//LOG("POST Req");
|
|
} else {
|
|
LOG_ERROR("Cannot issue request!");
|
|
};
|
|
};
|
|
return true;
|
|
};
|
|
|
|
void *protocolHTTP::requestFinished(void *ptr1, void *ptr2){
|
|
if (!ptr1) return NULL;
|
|
if (!ptr2) return NULL;
|
|
protocolHTTP *me;
|
|
curlRequest *rr;
|
|
me = (protocolHTTP*)ptr1;
|
|
rr = (curlRequest *)ptr2;
|
|
//qDebug() << "MapNetwork::requestFinished" << rr->getPath();
|
|
//(const char *)rr->getBuffer(), (int)rr->getSize()
|
|
protocolPackage *Package;
|
|
Package = NULL;
|
|
Package = (protocolPackage*) malloc( sizeof( protocolPackage ));
|
|
if( Package != NULL ){
|
|
Package->m_pData = NULL;
|
|
Package->m_nCode = 0;
|
|
Package->m_nSize = 0;
|
|
Package->m_pData = (U8 *) malloc( rr->getSize() );
|
|
if( Package->m_pData != NULL ){
|
|
memcpy( Package->m_pData, rr->getBuffer(), rr->getSize() );
|
|
Package->m_nCode = 200;
|
|
Package->m_nSize = rr->getSize();
|
|
me->packetHandler( Package );
|
|
free( Package->m_pData );
|
|
};
|
|
Package->m_nSize = 0;
|
|
//me->m_lRequestsList.removeAll(rr);
|
|
free( Package );
|
|
};
|
|
return NULL;
|
|
};
|
|
|
|
#undef LOG
|
|
#undef LOG_ERROR
|