#include "conn.h"
#include "radlog.h"
+#include "stgpair.h"
#include "stg/json_parser.h"
#include "stg/json_generator.h"
std::map<std::string, Packet> packetCodes;
std::map<std::string, bool> resultCodes;
+std::map<std::string, int> returnCodes;
class PacketParser : public EnumParser<Packet>
{
}
};
+class ReturnCodeParser : public EnumParser<int>
+{
+ public:
+ ReturnCodeParser(NodeParser* next, int& returnCode, std::string& returnCodeStr)
+ : EnumParser(next, returnCode, returnCodeStr, returnCodes)
+ {
+ if (!returnCodes.empty())
+ return;
+ returnCodes["reject"] = STG_REJECT;
+ returnCodes["fail"] = STG_FAIL;
+ returnCodes["ok"] = STG_OK;
+ returnCodes["handled"] = STG_HANDLED;
+ returnCodes["invalid"] = STG_INVALID;
+ returnCodes["userlock"] = STG_USERLOCK;
+ returnCodes["notfound"] = STG_NOTFOUND;
+ returnCodes["noop"] = STG_NOOP;
+ returnCodes["updated"] = STG_UPDATED;
+ }
+};
+
class TopParser : public NodeParser
{
public:
TopParser(Callback callback, void* data)
: m_packet(PING),
m_result(false),
+ m_returnCode(STG_REJECT),
m_packetParser(this, m_packet, m_packetStr),
m_resultParser(this, m_result, m_resultStr),
+ m_returnCodeParser(this, m_returnCode, m_returnCodeStr),
m_replyParser(this, m_reply),
m_modifyParser(this, m_modify),
m_callback(callback), m_data(data)
return &m_replyParser;
else if (key == "modify")
return &m_modifyParser;
+ else if (key == "return_code")
+ return &m_returnCodeParser;
return this;
}
Packet packet() const { return m_packet; }
const std::string& resultStr() const { return m_resultStr; }
bool result() const { return m_result; }
+ const std::string& returnCodeStr() const { return m_returnCodeStr; }
+ int returnCode() const { return m_returnCode; }
const PairsParser::Pairs& reply() const { return m_reply; }
const PairsParser::Pairs& modify() const { return m_modify; }
Packet m_packet;
std::string m_resultStr;
bool m_result;
+ std::string m_returnCodeStr;
+ int m_returnCode;
PairsParser::Pairs m_reply;
PairsParser::Pairs m_modify;
PacketParser m_packetParser;
ResultParser m_resultParser;
+ ReturnCodeParser m_returnCodeParser;
PairsParser m_replyParser;
PairsParser m_modifyParser;
Packet packet() const { return m_topParser.packet(); }
const std::string& resultStr() const { return m_topParser.resultStr(); }
bool result() const { return m_topParser.result(); }
+ const std::string& returnCodeStr() const { return m_topParser.returnCodeStr(); }
+ int returnCode() const { return m_topParser.returnCode(); }
const PairsParser::Pairs& reply() const { return m_topParser.reply(); }
const PairsParser::Pairs& modify() const { return m_topParser.modify(); }
void Conn::Impl::processData()
{
RESULT data;
- for (PairsParser::Pairs::const_iterator it = m_parser.reply().begin(); it != m_parser.reply().end(); ++it)
- data.reply.push_back(std::make_pair(it->first, it->second));
- for (PairsParser::Pairs::const_iterator it = m_parser.modify().begin(); it != m_parser.modify().end(); ++it)
- data.modify.push_back(std::make_pair(it->first, it->second));
- m_callback(m_data, data, m_parser.result());
+ if (m_parser.result())
+ {
+ for (PairsParser::Pairs::const_iterator it = m_parser.reply().begin(); it != m_parser.reply().end(); ++it)
+ data.reply.push_back(std::make_pair(it->first, it->second));
+ for (PairsParser::Pairs::const_iterator it = m_parser.modify().begin(); it != m_parser.modify().end(); ++it)
+ data.modify.push_back(std::make_pair(it->first, it->second));
+ data.returnCode = STG_UPDATED;
+ }
+ else
+ data.returnCode = m_parser.returnCode();
+ m_callback(m_data, data);
}
bool Conn::Impl::sendPing()
return res;
}
+static int toRLMCode(int code)
+{
+ switch (code)
+ {
+ case STG_REJECT: return RLM_MODULE_REJECT;
+ case STG_FAIL: return RLM_MODULE_FAIL;
+ case STG_OK: return RLM_MODULE_OK;
+ case STG_HANDLED: return RLM_MODULE_HANDLED;
+ case STG_INVALID: return RLM_MODULE_INVALID;
+ case STG_USERLOCK: return RLM_MODULE_USERLOCK;
+ case STG_NOTFOUND: return RLM_MODULE_NOTFOUND;
+ case STG_NOOP: return RLM_MODULE_NOOP;
+ case STG_UPDATED: return RLM_MODULE_UPDATED;
+ }
+ return RLM_MODULE_REJECT;
+}
+
/*
* Do any per-module initialization that is separate to each
* configured instance of the module. e.g. set up connections
if (count)
return RLM_MODULE_UPDATED;
- return RLM_MODULE_NOOP;
+ return toRLMCode(result.returnCode);
}
/*
if (count)
return RLM_MODULE_UPDATED;
- return RLM_MODULE_NOOP;
+ return toRLMCode(result.returnCode);
}
/*
if (count)
return RLM_MODULE_UPDATED;
- return RLM_MODULE_NOOP;
+ return toRLMCode(result.returnCode);
}
/*
if (count)
return RLM_MODULE_UPDATED;
- return RLM_MODULE_OK;
+ return toRLMCode(result.returnCode);
}
/*
if (count)
return RLM_MODULE_UPDATED;
- return RLM_MODULE_NOOP;
+ return toRLMCode(result.returnCode);
}
static int stg_detach(void* instance)