1
0
Fork 0
mirror of https://github.com/HackHerz/pusher synced 2025-12-06 02:10:19 +00:00

Added url-decoding

This commit is contained in:
Daniel Stein 2014-09-11 18:43:24 +02:00
parent d11867f430
commit e242b208db
5 changed files with 36 additions and 5 deletions

View file

@ -5,8 +5,8 @@
# Building # Building
## Requirements ## Requirements
* boost `libboost-program-options-dev` * boost
* curl `libcurl4-gnutls-dev` * curl
## Compile ## Compile

View file

@ -24,6 +24,7 @@ AC_LANG_PUSH([C++])
AC_CHECK_HEADERS([boost/property_tree/ptree.hpp], [], [AC_MSG_ERROR(You need the Boost libraries.)]) AC_CHECK_HEADERS([boost/property_tree/ptree.hpp], [], [AC_MSG_ERROR(You need the Boost libraries.)])
AC_CHECK_HEADERS([boost/property_tree/ini_parser.hpp], [], [AC_MSG_ERROR(You need the Boost libraries.)]) AC_CHECK_HEADERS([boost/property_tree/ini_parser.hpp], [], [AC_MSG_ERROR(You need the Boost libraries.)])
AC_CHECK_HEADERS([boost/program_options.hpp], [], [AC_MSG_ERROR(You need the Boost Program Options library.)]) AC_CHECK_HEADERS([boost/program_options.hpp], [], [AC_MSG_ERROR(You need the Boost Program Options library.)])
AC_CHECK_HEADERS([boost/regex.hpp], [], [AC_MSG_ERROR(You need the Boost Regex library.)])
AC_CHECK_HEADERS([curl/curl.h], [], [AC_MSG_ERROR(You need the curl libraries.)]) AC_CHECK_HEADERS([curl/curl.h], [], [AC_MSG_ERROR(You need the curl libraries.)])
AC_LANG_POP([C++]) AC_LANG_POP([C++])

View file

@ -7,6 +7,7 @@ CFLAGS += -std=c++11
# librarys # librarys
LDLIBS = -lcurl LDLIBS = -lcurl
LDLIBS += -lboost_program_options LDLIBS += -lboost_program_options
LDLIBS += -lboost_regex
# details # details

View file

@ -198,9 +198,10 @@ int main(int argc, char **argv)
{ {
string pipeBuffer; string pipeBuffer;
while(cin >> pipeBuffer) while(getline(cin, pipeBuffer))
{ {
message += pipeBuffer; message += pipeBuffer;
message += "\n";
} }
} }
else else

View file

@ -6,11 +6,39 @@
#include <boost/foreach.hpp> #include <boost/foreach.hpp>
#include <boost/property_tree/ptree.hpp> #include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp> #include <boost/property_tree/json_parser.hpp>
#include <boost/regex.hpp>
#include <iostream>
using namespace std; using namespace std;
// urlDecode matches
const char* matches[][2] = {
{"\\$", "%24"},
{"\\&", "%26"},
{"\\+", "%2B"},
{"\\,", "%2C"},
{"\\/", "%2F"},
{"\\:", "%3A"},
{"\\;", "%3B"},
{"\\=", "%3D"},
{"\\?", "%3F"},
{"\\@", "%40"}
};
// neded for urlencoding
string urlDecode(string url)
{
for(unsigned int i = 0; i < (sizeof(matches)/sizeof(matches[0])); i++)
{
boost::regex reg(matches[i][0]);
url = boost::regex_replace(url, reg, matches[i][1]);
}
return url;
}
// needed for handling curl output // needed for handling curl output
static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userp) static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userp)
{ {
@ -191,7 +219,7 @@ void PushHandler::sendToDevice(int id, string message)
% APP_PACKAGE % APP_PACKAGE
% id % id
% "MESSAGE" % "MESSAGE"
% message; % urlDecode(message);
// network request // network request
string readBuffer; string readBuffer;