[GSoC Uni] XML parsing of the server reply. Username & Password back to std::string.

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/uni@12910 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
unitraxx
2013-06-21 02:12:38 +00:00
parent 2e35f293df
commit 295a86017a
7 changed files with 23 additions and 24 deletions

View File

@@ -49,7 +49,7 @@ CurrentOnlineUser::CurrentOnlineUser(){
// ============================================================================
bool CurrentOnlineUser::signIn(const stringw &username, const stringw &password)
bool CurrentOnlineUser::signIn(const std::string &username, const std::string &password)
{
assert(m_is_signed_in == false);
HTTPConnector * connector = new HTTPConnector((std::string)UserConfigParams::m_server_multiplayer + "client-user.php");
@@ -59,7 +59,6 @@ bool CurrentOnlineUser::signIn(const stringw &username, const stringw &password)
parameters["password"] = password;
const XMLNode * result = connector->getXMLFromPage(parameters);
std::string token;
//const XMLNode * connection = result->getNode("connection");
bool succes = result->get("token", &token);
if(succes)
{
@@ -76,7 +75,7 @@ bool CurrentOnlineUser::signIn(const stringw &username, const stringw &password)
// ============================================================================
core::stringw CurrentOnlineUser::getUserName() const
std::string CurrentOnlineUser::getUserName() const
{
if(m_is_signed_in){
assert(m_user != NULL);

View File

@@ -21,8 +21,6 @@
#include "online/online_user.hpp"
#include <string>
#include <irrString.h>
using namespace irr;
// ============================================================================
@@ -45,9 +43,9 @@ class CurrentOnlineUser
// singleton
static CurrentOnlineUser* get();
static void deallocate();
bool signIn(const core::stringw &username, const core::stringw &password);
bool signIn(const std::string &username, const std::string &password);
/** Returns the username if signed in. */
core::stringw getUserName() const;
std::string getUserName() const;
bool isSignedIn(){ return m_is_signed_in; }
}; // class CurrentOnlineUser

View File

@@ -61,22 +61,26 @@ XMLNode * HTTPConnector::getXMLFromPage(Parameters & post_parameters)
std::string HTTPConnector::getPage(Parameters & post_parameters)
{
Parameters::iterator iter;
core::stringw postString;
std::string postString;
for (iter = post_parameters.begin(); iter != post_parameters.end(); ++iter)
{
if(iter != post_parameters.begin())
postString.append("&");
postString.append(iter->first);
char * escaped = curl_easy_escape(this->curl , iter->first.c_str(), iter->first.size());
postString.append(escaped);
curl_free(escaped);
postString.append("=");
postString.append(iter->second);
escaped = curl_easy_escape(this->curl , iter->second.c_str(), iter->second.size());
postString.append(escaped);
curl_free(escaped);
}
core::stringc postString2 = postString.c_str();
printf("Sending: %s\n", postString2.c_str());
curl_easy_setopt(this->curl, CURLOPT_POSTFIELDS, postString2.c_str());
printf("Sending: %s\n", postString.c_str());
curl_easy_setopt(this->curl, CURLOPT_POSTFIELDS, postString.c_str());
std::string readBuffer;
curl_easy_setopt(this->curl, CURLOPT_WRITEFUNCTION, WriteCallback);
curl_easy_setopt(this->curl, CURLOPT_FILE, &readBuffer);
res = curl_easy_perform(this->curl);
if(res != CURLE_OK)
{
Log::error("online/http_functions", "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
@@ -84,7 +88,7 @@ std::string HTTPConnector::getPage(Parameters & post_parameters)
}else{
printf("Retrieved: %s\n", readBuffer.c_str());
}
return readBuffer;
return readBuffer;
}

View File

@@ -36,7 +36,7 @@ class HTTPConnector
CURLcode res;
public:
typedef std::map<core::stringw, core::stringw> Parameters;
typedef std::map<std::string, std::string> Parameters;
HTTPConnector(const std::string &url);
~HTTPConnector();
std::string getPage(Parameters & post_parameters);

View File

@@ -24,7 +24,7 @@
// ============================================================================
OnlineUser::OnlineUser(const core::stringw &username)
OnlineUser::OnlineUser(const std::string &username)
{
m_username = username;
} // OnlineUser

View File

@@ -19,9 +19,7 @@
#ifndef HEADER_ONLINE_USER_HPP
#define HEADER_ONLINE_USER_HPP
#include <irrString.h>
using namespace irr;
#include <string>
// ============================================================================
@@ -35,17 +33,17 @@ class OnlineUser
protected:
core::stringw m_username;
std::string m_username;
public:
/**
* Constructor
*/
OnlineUser(const core::stringw &username);
OnlineUser(const std::string &username);
/** Returns the username. */
core::stringw getUserName() const { return m_username; }
std::string getUserName() const { return m_username; }
}; // class OnlineUser

View File

@@ -85,8 +85,8 @@ GUIEngine::EventPropagation LoginDialog::processEvent(const std::string& eventSo
sfx_manager->quickSound( "anvil" );
return GUIEngine::EVENT_BLOCK;
}
if(CurrentOnlineUser::get()->signIn(username, password))
;
if(CurrentOnlineUser::get()->signIn(core::stringc(username.c_str()).c_str(), core::stringc(password.c_str()).c_str()))
{
m_self_destroy = true;
}