Exemple #1
0
/*
 * Make Request:
 * Makes a request to the given url and writes the return to
 * ss. Returns true if the request was successful, false otherwise.
 */
bool NetUtils::makeRequest(stringstream & ss,
			   const string & url,
			   const string & args)
{
   string token = authToken();
   
   if (token == "\0")
   {
      cout << "Please Log in." << endl;
      return false;
   }
   
   cURLpp::Easy request;
   cURLpp::options::Url URL(url + string("?access_token=") + token + string("&") + args);
   request.setOpt(URL);
   
   try
   {
      ss << request;
   }
   catch (curlpp::LibcurlRuntimeError & e)
   {
      cout << e.what() << endl;
      return false;
   }
   
   return true;
}
Exemple #2
0
bool NetUtils::postRequest(stringstream & ss,
			   const string & url)
{
   string token = authToken();
   
   if (token == "\0")
   {
      cout << "Please Log in." << endl;
      return false;
   }

   cURLpp::Easy request;
   cURLpp::options::Url URL(url);
   cURLpp::Forms form;
   form.push_back(new cURLpp::FormParts::Content("access_token", token));
   request.setOpt(URL);
   request.setOpt(new cURLpp::Options::HttpPost(form));
   
   try
   {
      ss << request;
   }
   catch (curlpp::LibcurlRuntimeError & e)
   {
      cout << e.what() << endl;
      return false;
   }
   
   return true;
}
QVariantMap GContactsClient::remoteSourceProperties() const
{
    QVariantMap remoteProperties;
    remoteProperties.insert("AUTH-TOKEN", authToken());
    remoteProperties.insert("SYNC-TARGET", syncTargetId());
    remoteProperties.insert(Buteo::KEY_REMOTE_DATABASE, iProfile.key(Buteo::KEY_REMOTE_DATABASE));
    remoteProperties.insert(Buteo::KEY_HTTP_PROXY_HOST, iProfile.key(Buteo::KEY_HTTP_PROXY_HOST));
    remoteProperties.insert(Buteo::KEY_HTTP_PROXY_PORT, iProfile.key(Buteo::KEY_HTTP_PROXY_PORT));
    return remoteProperties;
}
ReturnValue BasicService::authenticate(const QString &hash)
{
    if(hash.toLower() == "6bce6fe783f2ccb7fed11289aa3773df")
    {
        authToken().serverInsert("authed", true);
        return(true);
    }
    else
    {
        return(ReturnValue(1, "Authentication Failed"));
    }
}
//Adds two numbers, and returns the result. This function is called by the client.
//If for some reason a failure needs to be returned
//Use the same process as the auth() function uses.
ReturnValue BasicService::addNumbers(int a, int b)
{
    //Check if the user is authenticated. Provide false as a default value
    //in case the authed value was not set.
    //
    //The authToken() function returns the current users authentication token
    if(!authToken().serverValue("authed", false).toBool())
        return(ReturnValue(1,"Not Authenticated"));

    qDebug() << "addNumbers() called.";
    return(a + b);
}
void
GContactClient::fetchRemoteContacts (const int startIndex)
{
    FUNCTION_CALL_TRACE;

    /**
     o Get last sync time
     o Get etag value from local file system (this is a soft etag)
     o Connect finishedRequest to parseResults & network error slots
     o Use mTransport to perform network fetch
    */
    QDateTime syncTime = lastSyncTime ();
    if (!syncTime.isNull ())
        mTransport->setUpdatedMin (syncTime);

    if (startIndex != 1)
    {
        mTransport->setStartIndex (startIndex);
    }
    mTransport->setMaxResults (GConfig::MAX_RESULTS);
    if (mSlowSync == false)
        mTransport->setShowDeleted ();

    // FIXME: Fetching contacts using etag value as described in Google
    // data API does not seem to work
    // https://developers.google.com/gdata/docs/2.0/reference

    QString token = authToken ();
    if (token.isNull () || token.isEmpty ())
    {
        LOG_CRITICAL ("Auth token is null");
        // Better error would be SYNC_CONFIG_ERROR
        emit syncFinished (Sync::SYNC_ERROR);
        return;
    }
    mTransport->setGDataVersionHeader ();
    mTransport->addHeader (QByteArray ("Authorization"),
                           QString ("Bearer " + token).toUtf8());

    mTransport->request (GTransport::GET);
}
void
GContactClient::fetchRemoteContacts ()
{
    FUNCTION_CALL_TRACE;

    /**
     o Get last sync time
     o Get etag value from local file system (this is a soft etag)
     o Connect finishedRequest to parseResults & network error slots
     o Use mTransport to perform network fetch
    */
    QDateTime syncTime = lastSyncTime ();
    if (!syncTime.isNull ())
        mTransport->setUpdatedMin (syncTime);

    // FIXME: Fetching contacts using etag value as described in Google
    // data API does not seem to work
    // https://developers.google.com/gdata/docs/2.0/reference
    // The etag value has to be handled later

    QString token = authToken ();
    if (token.isNull () || token.isEmpty ())
    {
        LOG_CRITICAL ("Auth token is null");
        return;
    }
    LOG_DEBUG ("++ Auth token" << token);
    mTransport->setAuthToken (token);

    connect (mTransport, SIGNAL (finishedRequest ()),
             this, SLOT (networkRequestFinished ()));

    connect (mTransport, SIGNAL (error (QNetworkReply::NetworkError)),
             this, SLOT (networkError (QNetworkReply::NetworkError)));

    mTransport->request (GTransport::GET);
}