Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
opendht
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
savoirfairelinux
opendht
Commits
1d6a307b
Commit
1d6a307b
authored
Jan 11, 2018
by
Adrien Béraud
Browse files
Options
Downloads
Patches
Plain Diff
proxy server: send data push message instead of notification
parent
227cca88
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/dht_proxy_server.cpp
+18
-16
18 additions, 16 deletions
src/dht_proxy_server.cpp
with
18 additions
and
16 deletions
src/dht_proxy_server.cpp
+
18
−
16
View file @
1d6a307b
...
@@ -378,34 +378,36 @@ DhtProxyServer::unsubscribe(const std::shared_ptr<restbed::Session>& session) co
...
@@ -378,34 +378,36 @@ DhtProxyServer::unsubscribe(const std::shared_ptr<restbed::Session>& session) co
}
}
void
void
DhtProxyServer
::
sendPushNotification
(
const
std
::
string
&
ke
y
,
const
Json
::
Value
&
json
,
bool
isAndroid
)
const
DhtProxyServer
::
sendPushNotification
(
const
std
::
string
&
to
ke
n
,
const
Json
::
Value
&
json
,
bool
isAndroid
)
const
{
{
restbed
::
Uri
uri
(
HTTP_PROTO
+
pushServer_
+
"/api/push"
);
restbed
::
Uri
uri
(
HTTP_PROTO
+
pushServer_
+
"/api/push"
);
auto
req
=
std
::
make_shared
<
restbed
::
Request
>
(
uri
);
auto
req
=
std
::
make_shared
<
restbed
::
Request
>
(
uri
);
req
->
set_method
(
"POST"
);
req
->
set_method
(
"POST"
);
// NOTE: see https://github.com/appleboy/gorush
Json
::
Value
notification
(
Json
::
objectValue
);
Json
::
Value
tokens
(
Json
::
arrayValue
);
tokens
[
0
]
=
token
;
notification
[
"tokens"
]
=
tokens
;
notification
[
"platform"
]
=
isAndroid
?
2
:
1
;
notification
[
"data"
]
=
json
;
Json
::
Value
notifications
(
Json
::
arrayValue
);
notifications
[
0
]
=
notification
;
Json
::
Value
content
;
content
[
"notifications"
]
=
notifications
;
Json
::
StreamWriterBuilder
wbuilder
;
Json
::
StreamWriterBuilder
wbuilder
;
wbuilder
[
"commentStyle"
]
=
"None"
;
wbuilder
[
"commentStyle"
]
=
"None"
;
wbuilder
[
"indentation"
]
=
""
;
wbuilder
[
"indentation"
]
=
""
;
auto
valueStr
=
Json
::
writeString
(
wbuilder
,
json
);
auto
valueStr
=
Json
::
writeString
(
wbuilder
,
content
);
// Escape JSON
std
::
string
::
size_type
n
=
0
;
while
((
n
=
valueStr
.
find
(
"
\"
"
,
n
))
!=
std
::
string
::
npos
)
{
valueStr
.
replace
(
n
,
1
,
"
\\\"
"
);
n
+=
2
;
}
std
::
replace
(
valueStr
.
begin
(),
valueStr
.
end
(),
'\n'
,
' '
);
// NOTE: see https://github.com/appleboy/gorush
auto
platform
=
isAndroid
?
2
:
1
;
auto
content
=
std
::
string
(
"{
\"
notifications
\"
: [{
\"
tokens
\"
: [
\"
"
+
key
+
"
\"
],
\"
platform
\"
: "
+
std
::
to_string
(
platform
)
+
",
\"
message
\"
:
\"
"
+
valueStr
+
"
\"
}]}"
);
req
->
set_header
(
"Content-Type"
,
"application/json"
);
req
->
set_header
(
"Content-Type"
,
"application/json"
);
req
->
set_header
(
"Accept"
,
"*/*"
);
req
->
set_header
(
"Accept"
,
"*/*"
);
req
->
set_header
(
"Host"
,
pushServer_
);
req
->
set_header
(
"Host"
,
pushServer_
);
req
->
set_header
(
"Content-Length"
,
std
::
to_string
(
content
.
length
()));
req
->
set_header
(
"Content-Length"
,
std
::
to_string
(
valueStr
.
length
()));
req
->
set_body
(
content
);
req
->
set_body
(
valueStr
);
// Send request.
// Send request.
restbed
::
Http
::
async
(
req
,
{});
restbed
::
Http
::
async
(
req
,
{});
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment