summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2013-05-18 00:27:03 -0400
committerAdam <Adam@anope.org>2013-05-18 00:27:03 -0400
commit879b31058065537d2e30bd74f71403800dd19cf4 (patch)
tree183970955ceecc8a620e69852267aca93d600238
parent5ff3aa7209a768168ddbb6137ee0df06e720b5f3 (diff)
Fix Windows build
-rw-r--r--docs/REDIS4
-rw-r--r--include/modules/redis.h17
-rw-r--r--modules/database/db_redis.cpp36
-rw-r--r--modules/m_redis.cpp23
4 files changed, 47 insertions, 33 deletions
diff --git a/docs/REDIS b/docs/REDIS
index 8c40d5690..375d9b4a2 100644
--- a/docs/REDIS
+++ b/docs/REDIS
@@ -9,7 +9,7 @@ Table of Contents
-----------------
1) Data structure
2) Keyspace notifications
-3) Examples of modfying, deleting, and creating objects
+3) Examples of modifying, deleting, and creating objects
1) Data structure
@@ -99,7 +99,7 @@ Table of Contents
multiple commands, or inserting multiple objects at once, specifically if the
objects depend on each other, you MUST use a transaction.
-3) Examples of modfying, deleting, and creating objects
+3) Examples of modifying, deleting, and creating objects
These examples will ONLY work if you meet the criteria in section 2.
diff --git a/include/modules/redis.h b/include/modules/redis.h
index 4b321a608..d13769d91 100644
--- a/include/modules/redis.h
+++ b/include/modules/redis.h
@@ -14,7 +14,7 @@ namespace Redis
enum Type
{
NOT_PARSED,
- ERROR,
+ NOT_OK,
OK,
INT,
BULK,
@@ -23,12 +23,23 @@ namespace Redis
type;
Reply() { Clear(); }
- void Clear() { type = NOT_PARSED; i = 0; bulk.clear(); multi_bulk_size = 0; multi_bulk.clear(); }
+ ~Reply() { Clear(); }
+
+ void Clear()
+ {
+ type = NOT_PARSED;
+ i = 0;
+ bulk.clear();
+ multi_bulk_size = 0;
+ for (unsigned j = 0; j < multi_bulk.size(); ++j)
+ delete multi_bulk[j];
+ multi_bulk.clear();
+ }
int64_t i;
Anope::string bulk;
int multi_bulk_size;
- std::deque<Reply> multi_bulk;
+ std::deque<Reply *> multi_bulk;
};
class Interface
diff --git a/modules/database/db_redis.cpp b/modules/database/db_redis.cpp
index 1abc6d684..122248f95 100644
--- a/modules/database/db_redis.cpp
+++ b/modules/database/db_redis.cpp
@@ -248,15 +248,15 @@ void TypeLoader::OnResult(const Reply &r)
for (unsigned i = 0; i < r.multi_bulk.size(); ++i)
{
- const Reply &reply = r.multi_bulk[i];
+ const Reply *reply = r.multi_bulk[i];
- if (reply.type != Reply::BULK)
+ if (reply->type != Reply::BULK)
continue;
int64_t id;
try
{
- id = convertTo<int64_t>(reply.bulk);
+ id = convertTo<int64_t>(reply->bulk);
}
catch (const ConvertException &)
{
@@ -287,10 +287,10 @@ void ObjectLoader::OnResult(const Reply &r)
for (unsigned i = 0; i + 1 < r.multi_bulk.size(); i += 2)
{
- const Reply &key = r.multi_bulk[i],
- &value = r.multi_bulk[i + 1];
+ const Reply *key = r.multi_bulk[i],
+ *value = r.multi_bulk[i + 1];
- data[key.bulk] << value.bulk;
+ data[key->bulk] << value->bulk;
}
Serializable* &obj = st->objects[this->id];
@@ -354,12 +354,12 @@ void Deleter::OnResult(const Reply &r)
for (unsigned i = 0; i + 1 < r.multi_bulk.size(); i += 2)
{
- const Reply &key = r.multi_bulk[i],
- &value = r.multi_bulk[i + 1];
+ const Reply *key = r.multi_bulk[i],
+ *value = r.multi_bulk[i + 1];
args.clear();
args.push_back("SREM");
- args.push_back("value:" + this->type + ":" + key.bulk + ":" + value.bulk);
+ args.push_back("value:" + this->type + ":" + key->bulk + ":" + value->bulk);
args.push_back(stringify(this->id));
/* Delete value -> object id */
@@ -397,12 +397,12 @@ void Updater::OnResult(const Reply &r)
for (unsigned i = 0; i + 1 < r.multi_bulk.size(); i += 2)
{
- const Reply &key = r.multi_bulk[i],
- &value = r.multi_bulk[i + 1];
+ const Reply *key = r.multi_bulk[i],
+ *value = r.multi_bulk[i + 1];
std::vector<Anope::string> args;
args.push_back("SREM");
- args.push_back("value:" + this->type + ":" + key.bulk + ":" + value.bulk);
+ args.push_back("value:" + this->type + ":" + key->bulk + ":" + value->bulk);
args.push_back(stringify(this->id));
/* Delete value -> object id */
@@ -461,12 +461,12 @@ void SubscriptionListener::OnResult(const Reply &r)
if (r.multi_bulk.size() != 4)
return;
- size_t sz = r.multi_bulk[2].bulk.find(':');
+ size_t sz = r.multi_bulk[2]->bulk.find(':');
if (sz == Anope::string::npos)
return;
- const Anope::string &key = r.multi_bulk[2].bulk.substr(sz + 1),
- &op = r.multi_bulk[3].bulk;
+ const Anope::string &key = r.multi_bulk[2]->bulk.substr(sz + 1),
+ &op = r.multi_bulk[3]->bulk;
sz = key.rfind(':');
if (sz == Anope::string::npos)
@@ -602,10 +602,10 @@ void ModifiedObject::OnResult(const Reply &r)
for (unsigned i = 0; i + 1 < r.multi_bulk.size(); i += 2)
{
- const Reply &key = r.multi_bulk[i],
- &value = r.multi_bulk[i + 1];
+ const Reply *key = r.multi_bulk[i],
+ *value = r.multi_bulk[i + 1];
- data[key.bulk] << value.bulk;
+ data[key->bulk] << value->bulk;
}
obj = st->Unserialize(obj, data);
diff --git a/modules/m_redis.cpp b/modules/m_redis.cpp
index a593b4cf8..ce3093d50 100644
--- a/modules/m_redis.cpp
+++ b/modules/m_redis.cpp
@@ -11,6 +11,8 @@
#include "module.h"
#include "modules/redis.h"
+#include <iterator> // back_inserter
+
using namespace Redis;
class MyRedisService;
@@ -63,7 +65,7 @@ class Transaction : public Interface
for (unsigned i = 0; i < r.multi_bulk.size(); ++i)
{
- const Reply &reply = r.multi_bulk[i];
+ const Reply *reply = r.multi_bulk[i];
if (interfaces.empty())
break;
@@ -72,7 +74,7 @@ class Transaction : public Interface
interfaces.pop_front();
if (inter)
- inter->OnResult(reply);
+ inter->OnResult(*reply);
}
}
};
@@ -321,7 +323,7 @@ size_t RedisSocket::ParseReply(Reply &r, const char *buffer, size_t l)
Log(LOG_DEBUG) << "redis: status error: " << reason.substr(0, nl);
if (nl != Anope::string::npos)
{
- r.type = Reply::ERROR;
+ r.type = Reply::NOT_OK;
used = 1 + nl + 2;
}
break;
@@ -398,21 +400,22 @@ size_t RedisSocket::ParseReply(Reply &r, const char *buffer, size_t l)
{
/* This multi bulk is already complete, so check the sub bulks */
for (unsigned i = 0; i < r.multi_bulk.size(); ++i)
- if (r.multi_bulk[i].type == Reply::MULTI_BULK)
- ParseReply(r.multi_bulk[i], buffer + used, l - used);
+ if (r.multi_bulk[i]->type == Reply::MULTI_BULK)
+ ParseReply(*r.multi_bulk[i], buffer + used, l - used);
break;
}
for (int i = r.multi_bulk.size(); i < r.multi_bulk_size; ++i)
{
- r.multi_bulk.push_back(Reply());
- size_t u = ParseReply(r.multi_bulk.back(), buffer + used, l - used);
+ Reply *reply = new Reply();
+ size_t u = ParseReply(*reply, buffer + used, l - used);
if (!u)
{
Log(LOG_DEBUG) << "redis: ran out of data to parse";
- r.multi_bulk.pop_back();
+ delete reply;
break;
}
+ r.multi_bulk.push_back(reply);
used += u;
}
break;
@@ -474,7 +477,7 @@ bool RedisSocket::Read(const char *buffer, size_t l)
* __keyevent@0__:set
* key
*/
- std::map<Anope::string, Interface *>::iterator it = this->subinterfaces.find(r.multi_bulk[1].bulk);
+ std::map<Anope::string, Interface *>::iterator it = this->subinterfaces.find(r.multi_bulk[1]->bulk);
if (it != this->subinterfaces.end())
it->second->OnResult(r);
}
@@ -492,7 +495,7 @@ bool RedisSocket::Read(const char *buffer, size_t l)
if (i)
{
- if (r.type != Reply::ERROR)
+ if (r.type != Reply::NOT_OK)
i->OnResult(r);
else
i->OnError(r.bulk);