Browse Source

safe fallback when boost-regex is not found

miguelfreitas
Miguel Freitas 11 years ago
parent
commit
4c5c9cf3fc
  1. 3
      src/bitcoinrpc.cpp
  2. 10
      src/twister_rss.cpp
  3. 7
      src/twister_rss.h

3
src/bitcoinrpc.cpp

@ -1057,6 +1057,9 @@ void ServiceConnection(AcceptedConnection *conn) @@ -1057,6 +1057,9 @@ void ServiceConnection(AcceptedConnection *conn)
case RSS_ERROR_NOT_A_NUMBER:
conn->stream() << HTTPReply(HTTP_BAD_REQUEST, "Parameter 'max' must be a number", false) << std::flush;
continue;
case RSS_ERROR_BOOST_REGEX:
conn->stream() << HTTPReply(HTTP_BAD_REQUEST, "boost-regex support missing", false) << std::flush;
continue;
}
}

10
src/twister_rss.cpp

@ -7,7 +7,9 @@ @@ -7,7 +7,9 @@
#include <algorithm>
#include <vector>
#include <ctime>
#include <boost/regex.hpp>
#ifdef HAVE_BOOST_REGEX
#include <boost/regex.hpp>
#endif
#include <boost/lexical_cast.hpp>
using namespace std;
@ -15,6 +17,9 @@ using namespace json_spirit; @@ -15,6 +17,9 @@ using namespace json_spirit;
int generateRSS(string uri, string *output)
{
#ifndef HAVE_BOOST_REGEX
return RSS_ERROR_BOOST_REGEX;
#else
map<string, string> parameterMap = parseQuery(uri);
int max = 20; //default value
string account = parameterMap["account"];
@ -188,8 +193,10 @@ int generateRSS(string uri, string *output) @@ -188,8 +193,10 @@ int generateRSS(string uri, string *output)
*output = ret.str();
return RSS_OK;
#endif
}
#ifdef HAVE_BOOST_REGEX
map<string, string> parseQuery(const string& query)
{
map<string, string> data;
@ -206,6 +213,7 @@ map<string, string> parseQuery(const string& query) @@ -206,6 +213,7 @@ map<string, string> parseQuery(const string& query)
return data;
}
#endif
bool sortByTime (Object i,Object j)
{

7
src/twister_rss.h

@ -10,11 +10,14 @@ enum RSSResultCode @@ -10,11 +10,14 @@ enum RSSResultCode
RSS_OK = 0,
RSS_ERROR_NO_ACCOUNT = -1,
RSS_ERROR_BAD_ACCOUNT = -2,
RSS_ERROR_NOT_A_NUMBER = -3
RSS_ERROR_NOT_A_NUMBER = -3,
RSS_ERROR_BOOST_REGEX = -4
};
extern bool sortByTime (json_spirit::Object i,json_spirit::Object j);
extern std::map<std::string, std::string> parseQuery(const std::string& query);
#ifdef HAVE_BOOST_REGEX
extern std::map<std::string, std::string> parseQuery(const std::string& query);
#endif
extern int generateRSS(std::string uri, std::string *output);
#endif // TWISTER_RSS_H

Loading…
Cancel
Save