Skip to content
Snippets Groups Projects
Commit 891bb6ca authored by Armin Felder's avatar Armin Felder
Browse files

adapted dockerfile to also checkout pushercpp

parent f48b5c7b
No related branches found
No related tags found
No related merge requests found
...@@ -63,7 +63,7 @@ RUN cd /proxygenSrc/proxygen/proxygen \ ...@@ -63,7 +63,7 @@ RUN cd /proxygenSrc/proxygen/proxygen \
RUN mkdir /pushGateway \ RUN mkdir /pushGateway \
&& cd /pushGateway \ && cd /pushGateway \
&& git clone https://git.fairkom.net/chat/RocketChatMobilePushGateway.git \ && git clone --recursive https://git.fairkom.net/chat/RocketChatMobilePushGateway.git \
&& cd RocketChatMobilePushGateway \ && cd RocketChatMobilePushGateway \
&& cmake . \ && cmake . \
&& make && make
......
...@@ -31,8 +31,6 @@ void HandlerFactory::onServerStop() noexcept{ ...@@ -31,8 +31,6 @@ void HandlerFactory::onServerStop() noexcept{
RequestHandler* HandlerFactory::onRequest(RequestHandler* requestHandler, HTTPMessage* httpMessage) noexcept{ RequestHandler* HandlerFactory::onRequest(RequestHandler* requestHandler, HTTPMessage* httpMessage) noexcept{
if(httpMessage) { if(httpMessage) {
std::cout << "path " << httpMessage->getPath()<<std::endl;
std::cout<< "url "<<httpMessage->getURL()<<std::endl;
std::vector<std::string> segments = utils::getSegments(httpMessage->getURL()); std::vector<std::string> segments = utils::getSegments(httpMessage->getURL());
if(segments.size()>2){ if(segments.size()>2){
if(segments[0] == "push"&&segments[2] == "send"){ if(segments[0] == "push"&&segments[2] == "send"){
......
...@@ -44,6 +44,7 @@ DEFINE_int32(threads, 0, "Number of threads to listen on. Numbers <= 0 " ...@@ -44,6 +44,7 @@ DEFINE_int32(threads, 0, "Number of threads to listen on. Numbers <= 0 "
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
gflags::ParseCommandLineFlags(&argc, &argv, true); gflags::ParseCommandLineFlags(&argc, &argv, true);
google::InitGoogleLogging(argv[0]); google::InitGoogleLogging(argv[0]);
......
...@@ -20,59 +20,95 @@ ...@@ -20,59 +20,95 @@
#include <jsoncpp/json/json.h> #include <jsoncpp/json/json.h>
#include <iostream> #include <iostream>
#include <curl/curl.h>
#include <fstream> #include <fstream>
#include <openssl/ssl.h> #include <algorithm>
#include "ApplePushModel.h" #include "ApplePushModel.h"
ApplePushModel::ApplePushModel(const std::string &pJson):mPusher("credentials/apple/cred.pem") { ApplePushModel::ApplePushModel(const std::string &pJson):mPusher("./credentials/apple/cred.pem") {
Json::Reader reader; Json::Reader reader;
Json::Value obj; Json::Value obj;
reader.parse(pJson, obj); Json::FastWriter fast;
std::cout<<obj["token"].asString()<<std::endl;
if(obj.isMember("token") && obj.isMember("options")){ if(pJson.length()) {
std::string token = obj["token"].asString(); reader.parse(pJson, obj);
Json::Value options = obj["options"];
if(options.isMember("from")&&options.isMember("badge")&&options.isMember("title")&&options.isMember("text")){ if (obj.isMember("token") && obj.isMember("options")) {
std::cout<<"valid json"<<std::endl;
mTitle = std::move(options["title"].asString()); Json::Value options = obj["options"];
mText = std::move(options["text"].asString());
mFrom = std::move(options["from"].asString()); Json::Value apn = options["apn"];
std::string test(fast.write(options));
if (apn.isMember("text")) {
std::string temp = std::move(apn["text"].asString());
unsigned long index = 0;
while(true){
index = temp.find('\n',index);
if(index == std::string::npos){
break;
}
temp.replace(index, 1, "\\r\\n");
index += 4;
}
mApn = std::move(temp);
}
if (options.isMember("title")) {
mTitle = std::move(options["title"].asString());
}
if (options.isMember("text")) {
mText = std::move(options["text"].asString());
}
if (options.isMember("from")) {
mFrom = std::move(options["from"].asString());
}
if (options.isMember("badge")) {
mBadge = options["badge"].asInt();
}
if (options.isMember("payload")) {
mPayload = std::move(fast.write(options["payload"]));
}
if (options.isMember("topic")) {
mTopic = std::move(options["topic"].asString());
}
if (options.isMember("sound")) {
mSound = std::move(options["sound"].asString());
}
mDeviceToken = std::move(obj["token"].asString()); mDeviceToken = std::move(obj["token"].asString());
mBadge = options["badge"].asInt();
} }
} }
} }
bool ApplePushModel::sendMessage() { bool ApplePushModel::sendMessage() {
std::vector<std::string> tokens;
Json::FastWriter fast; Json::FastWriter fast;
std::vector<std::string> tokens;
tokens.push_back(mDeviceToken); tokens.push_back(mDeviceToken);
PusherContent content; PusherContent content;
Json::Value obj; if(mPayload.length()){
Json::Value msg; content.userData = "\"ejson\":"+mPayload+"";
msg["title"] = mTitle; }else{
msg["body"] = mText; content.userData = "";
}
std::string data = fast.write(msg);
content.badge = mBadge; content.badge = mBadge;
content.content = mTitle; content.content = mApn;
content.userData = "\"ejson\":"+data; content.sound = mSound;
mPusher.isSandBox = true; mPusher.isSandBox = true;
mPusher.pushNotification(content, tokens); mPusher.pushNotification(content, tokens);
//TODO: shoud be fixed
std::string url{"https://gateway.sandbox.push.apple.com:2195"};
return false; //TODO: shoud be fixed, pusherCPP does not give a return value
return true;
} }
...@@ -39,6 +39,15 @@ private: ...@@ -39,6 +39,15 @@ private:
std::string mText; std::string mText;
std::string mDeviceToken; std::string mDeviceToken;
std::string mFrom; std::string mFrom;
std::string mPayload;
std::string mSound;
std::string mApn;
std::string mGcm;
std::string mQuery;
bool mSent{false};
int mSendind{0};
std::string mTopic;
int mBadge{0}; int mBadge{0};
}; };
......
...@@ -45,18 +45,55 @@ void GooglePushModel::loadApiKey() { ...@@ -45,18 +45,55 @@ void GooglePushModel::loadApiKey() {
GooglePushModel::GooglePushModel(const std::string &pJson) { GooglePushModel::GooglePushModel(const std::string &pJson) {
Json::Reader reader; Json::Reader reader;
Json::Value obj; Json::Value obj;
reader.parse(pJson, obj); Json::FastWriter fast;
std::cout<<obj["token"].asString()<<std::endl;
if(obj.isMember("token") && obj.isMember("options")){ if(pJson.length()) {
std::string token = obj["token"].asString(); reader.parse(pJson, obj);
Json::Value options = obj["options"];
if(options.isMember("from")&&options.isMember("badge")&&options.isMember("title")&&options.isMember("text")&&options.isMember("badge")){ if (obj.isMember("token") && obj.isMember("options")) {
std::cout<<"valid json"<<std::endl;
mTitle = std::move(options["title"].asString()); Json::Value options = obj["options"];
mText = std::move(options["text"].asString());
mFrom = std::move(options["from"].asString()); Json::Value apn = options["gcm"];
std::string test(fast.write(options));
if (apn.isMember("text")) {
std::string temp = std::move(apn["text"].asString());
unsigned long index = 0;
while(true){
index = temp.find('\n',index);
if(index == std::string::npos){
break;
}
temp.replace(index, 1, "\\r\\n");
index += 4;
}
mApn = std::move(temp);
}
if (options.isMember("title")) {
mTitle = std::move(options["title"].asString());
}
if (options.isMember("text")) {
mText = std::move(options["text"].asString());
}
if (options.isMember("from")) {
mFrom = std::move(options["from"].asString());
}
if (options.isMember("badge")) {
mBadge = options["badge"].asInt();
}
if (options.isMember("payload")) {
mPayload = std::move(fast.write(options["payload"]));
}
if (options.isMember("topic")) {
mTopic = std::move(options["topic"].asString());
}
if (options.isMember("sound")) {
mSound = std::move(options["sound"].asString());
}
mDeviceToken = std::move(obj["token"].asString()); mDeviceToken = std::move(obj["token"].asString());
mBadge = options["badge"].asInt();
} }
} }
} }
...@@ -68,6 +105,9 @@ bool GooglePushModel::sendMessage() { ...@@ -68,6 +105,9 @@ bool GooglePushModel::sendMessage() {
Json::Value msg; Json::Value msg;
msg["title"] = mTitle; msg["title"] = mTitle;
msg["body"] = mText; msg["body"] = mText;
msg["message"] = mGcm;
msg["ejson"] = mPayload;
msg["msgcnt"] = mBadge;
obj["to"] = mDeviceToken; obj["to"] = mDeviceToken;
obj["notification"] = msg; obj["notification"] = msg;
...@@ -84,7 +124,6 @@ bool GooglePushModel::sendMessage() { ...@@ -84,7 +124,6 @@ bool GooglePushModel::sendMessage() {
struct curl_slist *chunk = nullptr; struct curl_slist *chunk = nullptr;
std::cout<<std::string("Authorization: key="+mApiKey)<<std::endl;
chunk = curl_slist_append(chunk, std::string("Authorization: key="+mApiKey).c_str()); chunk = curl_slist_append(chunk, std::string("Authorization: key="+mApiKey).c_str());
chunk = curl_slist_append(chunk, "Content-Type: application/json"); chunk = curl_slist_append(chunk, "Content-Type: application/json");
...@@ -98,12 +137,17 @@ bool GooglePushModel::sendMessage() { ...@@ -98,12 +137,17 @@ bool GooglePushModel::sendMessage() {
res = curl_easy_perform(curl); res = curl_easy_perform(curl);
if(res != CURLE_OK){ if(res != CURLE_OK){
std::cerr<<"curl error: "<<curl_easy_strerror(res)<<std::endl; std::cerr<<"curl error: "<<curl_easy_strerror(res)<<std::endl;
}else{ }else{
curl_easy_cleanup(curl);
curl_slist_free_all(chunk);
return true; return true;
} }
} curl_easy_cleanup(curl);
curl_slist_free_all(chunk);
}
return false; return false;
} }
...@@ -44,8 +44,17 @@ private: ...@@ -44,8 +44,17 @@ private:
std::string mText; std::string mText;
std::string mDeviceToken; std::string mDeviceToken;
std::string mFrom; std::string mFrom;
std::string mPayload;
std::string mSound;
std::string mApn;
std::string mGcm;
std::string mQuery;
bool mSent{false};
int mSendind{0};
std::string mTopic;
int mBadge{0}; int mBadge{0};
}; };
......
...@@ -17,22 +17,28 @@ ...@@ -17,22 +17,28 @@
* along with RocketChatMobilePushGateway. If not, see <http://www.gnu.org/licenses/>. * * along with RocketChatMobilePushGateway. If not, see <http://www.gnu.org/licenses/>. *
* * * *
********************************************************************************************************************/ ********************************************************************************************************************/
#include "utils.h" #include "utils.h"
namespace utils{ namespace utils{
std::vector<std::string> getSegments(const std::string &pPath){ std::vector<std::string> getSegments(const std::string &pPath){
size_t current = 0; unsigned long current = 0;
size_t next = -1; long next = -1;
std::vector<std::string> segments; std::vector<std::string> segments;
do{ do{
current = next +1; current = static_cast<size_t >(next + 1);
next = pPath.find_first_of("/",current); next = pPath.find_first_of('/',current);
std::string segment = pPath.substr(current, next-current); std::string segment = pPath.substr(current, next-current);
if(segment != "") { if(!segment.empty()) {
segments.push_back(segment); segments.push_back(std::move(segment));
std::cout << segment << std::endl;
} }
}while(next != std::string::npos); }while(next != std::string::npos);
return segments; return segments;
} }
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment