void HTTPCredentials::updateAuthInfo(HTTPRequest& request)
{
    if (request.has(HTTPRequest::AUTHORIZATION)) {
        const std::string& authorization = request.get(HTTPRequest::AUTHORIZATION);

        if (isBasicCredentials(authorization)) {
            HTTPBasicCredentials(_digest.getUsername(), _digest.getPassword()).authenticate(request);
        } else if (isDigestCredentials(authorization)) {
            _digest.updateAuthInfo(request);
        }
    }
}
Пример #2
0
/**
 * DBInterface::readStatusOK
 * @brief reads the boolean value statusOK from database and returns it.
 * @return returns the value of the boolean value statusOK
 */
bool DBInterface::readStatusOK() {
    // create url-string for select ... from ...
    stringstream httpRequestUrl;
    HTTPRequest req;

    httpRequestUrl << URL_OF_DATABASE << "/query?pretty=true&db=" << NAME_OF_DATBASE << "&q=SELECT+";
    httpRequestUrl << "value+FROM+statusOK";

    string answerJSON = req.get(httpRequestUrl.str());
    setDBFailure(answerJSON == "");

    vector<DataBuffer> dataBufferVec = jsonToDataBufferVector(answerJSON,"");

    double result = dataBufferVec[0].data["value"];

    return (result != 0);
}
Пример #3
0
/**
 * DBInterface::readFromDataBase
 * @brief readFromDataBase reads the data which is requested by dataBuffer_ from database
 * @param dataBuffer_ requested data (is only filled with requested strings)
 * @return returns the requested dataBuffer_ which now contains requested data
 */
vector<DataBuffer> DBInterface::readFromDataBase(DataBuffer& dataBuffer_) {
    // create empty result
    vector<DataBuffer> result;

    if (readStatusOK()) {

        // create url-string for select ... from ...
        stringstream httpRequestUrl;
        httpRequestUrl << URL_OF_DATABASE << "/query?pretty=true&db=" << NAME_OF_DATBASE << "&q=SELECT+"; // << "&precision=s";

        // iterate all requested fields
        bool printComma = false;
        typedef std::map<string, double>::iterator it_type;
        for(it_type iterator = dataBuffer_.data.begin(); iterator != dataBuffer_.data.end(); iterator++) {
            if (printComma) {
                httpRequestUrl << ",";
            } else {
                printComma = true;
            }
            string name = cleanString(iterator->first);
            httpRequestUrl << name << "+";
        }

        // add requested datasource
        if (!dataBuffer_.useDataSource) {
            log << SLevel(ERROR) << "Aborted reading from database because there was either no DataSource specified" <<
            " or the useDataSource-flag was not set to true." << endl;
        } else {
            string dataSource = cleanString(dataBuffer_.dataSource);
            httpRequestUrl << "FROM+point+where+DataSource+=+'" << dataSource << "'";

            // add requested datetime-range
            if (dataBuffer_.useDateTimes) {
                if ( (dataBuffer_.startDateTime.tm_year <= 1971) ||
                     (dataBuffer_.endDateTime.tm_year   <= 1971) ){
                    log << SLevel(ERROR) << "Aborted reading from database because of invalid datetime. " <<
                    "Please use only years bigger than 1971." << endl;
                    setDBFailure(true);
                    return result;
                }
                string startDateTime = cTimeToString(dataBuffer_.startDateTime,false);
                string   endDateTime = cTimeToString(  dataBuffer_.endDateTime,false);
                httpRequestUrl << "+and+time+>=+'" << startDateTime << "'";
                httpRequestUrl << "+and+time+<=+'" <<   endDateTime << "'";
            } else {
                // if no date-time is specified use local time (cut down to current hour)
                struct tm currentLocalDateTime = getCurrentDateTime();
                string startDateTime = cTimeToString(currentLocalDateTime,false);
                string   endDateTime = startDateTime;
                httpRequestUrl << "+and+time+>=+'" << startDateTime << "'";
                httpRequestUrl << "+and+time+<=+'" <<   endDateTime << "'";
            }


            // execute request
            HTTPRequest req;
            string answerJSON = req.get(httpRequestUrl.str());
            setDBFailure(answerJSON == "");

            // convert json to vector of DataBuffer
            result = jsonToDataBufferVector(answerJSON,dataBuffer_.dataSource);

        }
    } else {
        log << SLevel(ERROR) << "Aborted reading from database because of status not OK" << endl;
    }

    // return
    return result;
}
Пример #4
0
SiriTokenProvider::Ptr SiriTokenProvider::FromAceHeader( const string& header )
{
    SiriTokenProvider::Ptr p=new SiriTokenProvider();
    p->m_http_string=header;
    if(p->m_http_string.find("Assistant(iPhone/iPhone4,1;")!=-1)
    {
        stringstream ss(p->m_http_string);
        HTTPRequest req;
        req.read(ss);
        if(req.has("X-Ace-Host"))
        {
            p->m_Ticket.x_ace_host=req["X-Ace-Host"];
        }
        if(req.has("User-Agent"))
        {
            p->m_Ticket.user_agent=req["User-Agent"];
        }
        p->iPhone4s=true;
        p->m_Ticket.iPhone4s=true;
        if(!p->CheckHeader())
        {
            delete p;
            return NULL;
        }
    }
    else
    {
        p->m_http_string=iPhone4s_header_tmpl;
        p->iPhone4s=false;
        p->m_Ticket.iPhone4s=false;
        if(!p->CheckHeader())
        {
            delete p;
            return NULL;
        }

        stringstream ss(p->m_http_string);
        HTTPRequest req;
        req.read(ss);

        string strAceHost;
        size_t offset=p->m_http_string.find("X-Ace-Host");
        if(offset!=-1)
        {
            size_t n1=p->m_http_string.find(":",offset);
            if(n1==(offset+strlen("X-Ace-Host")))
            {
                size_t n2=p->m_http_string.find("\r\n",n1);
                if(n2>n1)
                {
                    string ace_host=p->m_http_string.substr(n1+1,n2-n1);
                    p->m_Ticket.x_ace_host=ace_host;
                    strAceHost=ace_host;
                }
            }
        }
        if(req.has("X-Ace-Host"))
        {
            strAceHost==req.get("X-Ace-Host");
            if(!strAceHost.empty())
                p->m_Ticket.x_ace_host=strAceHost;
        }

        p->m_Ticket.x_ace_host_tmpl=p->m_Ticket.x_ace_host;

        if(!SiriTokenProvider::GetNextTicket(&p->m_Ticket))
        {
            delete p;
            return NULL;
        }

        p->m_http_string=Poco::replace(p->m_http_string,strAceHost,p->m_Ticket.x_ace_host);
        p->m_http_string=Poco::replace(p->m_http_string,"siri.cd-team.org","guzzoni.apple.com");

    }

    return p;
}
bool HTTPCredentials::hasDigestCredentials(const HTTPRequest& request)
{
    return request.has(HTTPRequest::AUTHORIZATION) && isDigestCredentials(request.get(HTTPRequest::AUTHORIZATION));
}
Пример #6
0
bool HTTPCredentials::hasProxyBasicCredentials(const HTTPRequest& request)
{
	return request.has(HTTPRequest::PROXY_AUTHORIZATION) && isBasicCredentials(request.get(HTTPRequest::PROXY_AUTHORIZATION));
}