#include "twister_rss.h" #include "init.h" #include "bitcoinrpc.h" #include "json/json_spirit.h" #include #include #include #include #ifdef HAVE_BOOST_REGEX #include #endif #include using namespace std; using namespace json_spirit; int generateRSS(string uri, string *output) { #ifndef HAVE_BOOST_REGEX return RSS_ERROR_BOOST_REGEX; #else map parameterMap = parseQuery(uri); int max = 20; //default value string account = parameterMap["account"]; string strMax = parameterMap["max"]; string author = parameterMap["author"]; if(strMax!="") { try { max = boost::lexical_cast(strMax); } catch(boost::bad_lexical_cast e) { return RSS_ERROR_NOT_A_NUMBER; } } const Array emptyArray; Array accountsArray = listwalletusers(emptyArray,false).get_array(); // if no account was specified, choose the first one if(account=="") { if(accountsArray.size()>0) { account = accountsArray[0].get_str(); } else return RSS_ERROR_NO_ACCOUNT; } // if an account name was specified, check that it exists else { bool accountExists = false; for(int i=0;i outputVector; if(GetBoolArg("-rss_dm",false)) //synchronizing direct messages is disabled by default { Array params3; params3.push_back(account); params3.push_back(max); params3.push_back(postSources); Object messages = getdirectmsgs(params3,false).get_obj(); for(int j=0;j\n" << "\n" << "\n" << " Twister Postboard - " << account << "\n" << " New posts from Twister\n"; int outputSize = (outputVector.size()>max)?max:outputVector.size(); for(int i=0;i\n" << " " << find_value(item,"title").get_str() << "\n" << " " << find_value(item,"author").get_str() << "\n" << " " << find_value(item,"msg").get_str() << "\n" << " " << timeString << "\n" << " \n"; } ret << "\n" << "\n"; *output = ret.str(); return RSS_OK; #endif } #ifdef HAVE_BOOST_REGEX map parseQuery(const string& query) { map data; boost::regex pattern("([\\w+%]+)=([^&]*)"); boost::sregex_iterator words_begin = boost::sregex_iterator(query.begin(), query.end(), pattern); boost::sregex_iterator words_end = boost::sregex_iterator(); for (boost::sregex_iterator i = words_begin; i != words_end; i++) { string key = (*i)[1].str(); string value = (*i)[2].str(); data[key] = value; } return data; } #endif bool sortByTime (Object i,Object j) { return (find_value(i,"time").get_int64()>find_value(j,"time").get_int64()); } void encodeXmlCharacters(std::string& data) { std::string buffer; buffer.reserve(data.size()); for(size_t pos = 0; pos != data.size(); ++pos) { switch(data[pos]) { case '&': buffer.append("&"); break; case '\"': buffer.append("""); break; case '\'': buffer.append("'"); break; case '<': buffer.append("<"); break; case '>': buffer.append(">"); break; default: buffer.append(&data[pos], 1); break; } } data.swap(buffer); }