Send status code 332 when spectrum goes down
This commit is contained in:
parent
05e06dd845
commit
3ff7f92490
4 changed files with 5 additions and 128 deletions
|
@ -1,80 +0,0 @@
|
|||
#include "userdb.h"
|
||||
|
||||
#if 0
|
||||
|
||||
DEFINE_LOGGER(logger, "Twitter Backend Database");
|
||||
|
||||
UserDB::UserDB(std::string database): errMsg(0), rc(0), dbOpen(false)
|
||||
{
|
||||
rc = sqlite3_open(database.c_str(), &db);
|
||||
if( rc ) {
|
||||
LOG4CXX_ERROR(logger, "Failed to open database" << database);
|
||||
sqlite3_close(db);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
LOG4CXX_INFO(logger, "Checking if table users is present")
|
||||
if(exe(std::string("select * from users limit 1;")) != SQLITE_OK) {
|
||||
exe("create table users (user text primarykey, key text, secret text);");
|
||||
LOG4CXX_INFO(logger, "Created table users in the database");
|
||||
}
|
||||
dbOpen = true;
|
||||
}
|
||||
|
||||
int UserDB::exe(std::string s_exe)
|
||||
{
|
||||
data.clear();
|
||||
|
||||
//LOG4CXX_INFO(logger, "Executing: " << s_exe)
|
||||
rc = sqlite3_get_table(db, s_exe.c_str(), &result, &nRow, &nCol, &errMsg);
|
||||
if( rc == SQLITE_OK ) {
|
||||
int col = nCol; //Skip past the headers
|
||||
for(int i = 0; i < nRow; ++i) {
|
||||
std::vector<std::string> row;
|
||||
for(int j = 0 ; j < nCol ; j++) row.push_back(result[col++]);
|
||||
data.push_back(row);
|
||||
}
|
||||
}
|
||||
sqlite3_free_table(result);
|
||||
return rc;
|
||||
}
|
||||
|
||||
void UserDB::insert(UserData info)
|
||||
{
|
||||
std::string q = "insert into users (user,key,secret) values ('" + info.user + "','" + info.accessTokenKey + "','" + info.accessTokenSecret + "');";
|
||||
if(exe(q) != SQLITE_OK) {
|
||||
LOG4CXX_ERROR(logger, "Failed to insert into database!");
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
void UserDB::fetch(std::string user, std::vector<std::string> &row)
|
||||
{
|
||||
std::string q = "select key,secret from users where user='" + user + "'";
|
||||
if(exe(q) != SQLITE_OK) {
|
||||
LOG4CXX_ERROR(logger, "Failed to fetch data from database!");
|
||||
exit(0);
|
||||
}
|
||||
row = data[0];
|
||||
}
|
||||
|
||||
std::set<std::string> UserDB::getRegisteredUsers()
|
||||
{
|
||||
std::string q = "select user from users";
|
||||
if(exe(q) != SQLITE_OK) {
|
||||
LOG4CXX_ERROR(logger, "Failed to registered users from database!");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
std::set<std::string> users;
|
||||
for(int i=0 ; i<data.size() ; i++)
|
||||
users.insert(data[i][0]);
|
||||
return users;
|
||||
}
|
||||
|
||||
UserDB::~UserDB()
|
||||
{
|
||||
sqlite3_close(db);
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,48 +0,0 @@
|
|||
#if 0
|
||||
|
||||
#ifndef USERDB_H
|
||||
#define USERDB_H
|
||||
|
||||
#include <iostream>
|
||||
#include <sqlite3.h>
|
||||
#include <vector>
|
||||
#include <set>
|
||||
#include "transport/logging.h"
|
||||
|
||||
struct UserData
|
||||
{
|
||||
std::string user;
|
||||
std::string accessTokenKey;
|
||||
std::string accessTokenSecret;
|
||||
UserData(){}
|
||||
UserData(std::string _user, std::string key, std::string secret) {
|
||||
user = _user;
|
||||
accessTokenKey = key;
|
||||
accessTokenSecret = secret;
|
||||
}
|
||||
};
|
||||
|
||||
class UserDB {
|
||||
private:
|
||||
sqlite3 *db;
|
||||
char *errMsg;
|
||||
char **result;
|
||||
int rc;
|
||||
int nRow,nCol;
|
||||
bool dbOpen;
|
||||
std::vector< std::vector<std::string> > data;
|
||||
|
||||
public:
|
||||
|
||||
UserDB (std::string database);
|
||||
int exe(std::string s_exe);
|
||||
void insert(UserData info);
|
||||
void fetch(std::string user, std::vector<std::string> &row);
|
||||
std::set<std::string> getRegisteredUsers();
|
||||
~UserDB();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
|
@ -55,6 +55,10 @@ void Conversation::destroyRoom() {
|
|||
Swift::MUCUserPayload *p = new Swift::MUCUserPayload ();
|
||||
p->addItem(item);
|
||||
|
||||
Swift::MUCUserPayload::StatusCode c;
|
||||
c.code = 332;
|
||||
p->addStatusCode(c);
|
||||
|
||||
presence->addPayload(boost::shared_ptr<Swift::Payload>(p));
|
||||
m_conversationManager->getComponent()->getStanzaChannel()->sendPresence(presence);
|
||||
}
|
||||
|
|
|
@ -293,6 +293,7 @@ class ConversationManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTe
|
|||
CPPUNIT_ASSERT_EQUAL(Swift::StatusShow::None, dynamic_cast<Swift::Presence *>(getStanza(received[0]))->getShow());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("user@localhost/resource"), dynamic_cast<Swift::Presence *>(getStanza(received[0]))->getTo().toString());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("#room@localhost/nickname"), dynamic_cast<Swift::Presence *>(getStanza(received[0]))->getFrom().toString());
|
||||
CPPUNIT_ASSERT_EQUAL(332, getStanza(received[0])->getPayload<Swift::MUCUserPayload>()->getStatusCodes()[0].code);
|
||||
}
|
||||
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue