Skip to content

Commit

Permalink
Merge pull request #16 from respoke/feature/MER-4340-add-respoke-sdk-…
Browse files Browse the repository at this point in the history
…header

Add Respoke-SDK header to ws connect and requests
  • Loading branch information
chadxz committed Sep 23, 2015
2 parents a878829 + e65097d commit 61fbec0
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 4 deletions.
33 changes: 33 additions & 0 deletions res/res_respoke/include/respoke_sdk_header.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Respoke - Web communications made easy
*
* Copyright (C) 2015, D.C.S. LLC
*
* Chad McElligott <[email protected]>
*
* See https://www.respoke.io for more information about
* Respoke. Please do not directly contact any of the
* maintainers of this project for assistance.
* Respoke offers a community forum to submit and discuss
* issues at http://community.respoke.io; please raise any
* issues there.
*
* See http://www.asterisk.org for more information about
* the Asterisk project. Please do not directly contact
* any of the maintainers of this project for assistance;
* the project provides a web site, mailing lists and IRC
* channels for your use.
*
* This program is free software, distributed under the terms of
* the GNU General Public License Version 2. See the LICENSE file
* at the top of the source tree.
*/

#ifndef RESPOKE_SDK_HEADER_H_
#define RESPOKE_SDK_HEADER_H_

#include <stddef.h>

int respoke_get_sdk_header(char *buf, size_t len);

#endif /* RESPOKE_SDK_HEADER_H_ */
12 changes: 10 additions & 2 deletions res/res_respoke/respoke_endpoint.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "asterisk/respoke_transport.h"
#include "include/respoke_private.h"
#include "include/respoke_app.h"
#include "include/respoke_sdk_header.h"

struct endpoint_identifier_list {
const struct respoke_endpoint_identifier *identifier;
Expand Down Expand Up @@ -229,6 +230,8 @@ static int respoke_endpoint_apply(const struct ast_sorcery *sorcery, void *obj)
struct respoke_transport *transport;
char *name;
struct ast_uri *uri;
char sdk_header[80] = "";
char encoded_sdk_header[180] = "";

if (!endpoint->register_with_service) {
/* This is done in case the configuration for the endpoint goes from register with service
Expand Down Expand Up @@ -303,13 +306,18 @@ static int respoke_endpoint_apply(const struct ast_sorcery *sorcery, void *obj)
endpoint->state->transport->uri, ast_sorcery_object_get_id(endpoint));
return -1;
}
ast_string_field_build(endpoint->state->transport, uri, "%s%s%s%s%s/?app-secret=%s",

respoke_get_sdk_header(sdk_header, sizeof(sdk_header));
ast_uri_encode(sdk_header, encoded_sdk_header, sizeof(encoded_sdk_header), ast_uri_http);
ast_string_field_build(endpoint->state->transport, uri, "%s%s%s%s%s/?app-secret=%s&Respoke-SDK=%s",
S_OR(ast_uri_scheme(uri), ""),
!ast_strlen_zero(ast_uri_scheme(uri)) ? "://" : "",
ast_uri_host(uri),
!ast_strlen_zero(ast_uri_port(uri)) ? ":" : "",
S_OR(ast_uri_port(uri), ""),
app->secret);
app->secret,
encoded_sdk_header);

ao2_ref(uri, -1);
ast_string_field_set(endpoint->state->transport, app_secret, app->secret);

Expand Down
9 changes: 7 additions & 2 deletions res/res_respoke/respoke_message_json.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "asterisk/respoke_message.h"
#include "asterisk/respoke_transport.h"
#include "include/respoke_app.h"
#include "include/respoke_sdk_header.h"

#define HEADER "header"
#define HEADER_TYPE "type"
Expand Down Expand Up @@ -1232,15 +1233,19 @@ int respoke_message_sail(struct respoke_message *message)
{
struct ast_json *obj, *headers;
struct ast_variable *header;
char sdk_header[80] = "";

/* In case we need to retransmit don't re-sail the message */
if (message->sailed) {
return 0;
}

respoke_get_sdk_header(sdk_header, sizeof(sdk_header));

if (!(headers = ast_json_pack(
"{s:s}",
"App-Secret", message->transport->app_secret))) {
"{s:s,s:s}",
"App-Secret", message->transport->app_secret,
"Respoke-SDK", sdk_header))) {
return -1;
}

Expand Down
41 changes: 41 additions & 0 deletions res/res_respoke/respoke_sdk_header.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Respoke - Web communications made easy
*
* Copyright (C) 2015, D.C.S. LLC
*
* Chad McElligott <[email protected]>
*
* See https://www.respoke.io for more information about
* Respoke. Please do not directly contact any of the
* maintainers of this project for assistance.
* Respoke offers a community forum to submit and discuss
* issues at http://community.respoke.io; please raise any
* issues there.
*
* See http://www.asterisk.org for more information about
* the Asterisk project. Please do not directly contact
* any of the maintainers of this project for assistance;
* the project provides a web site, mailing lists and IRC
* channels for your use.
*
* This program is free software, distributed under the terms of
* the GNU General Public License Version 2. See the LICENSE file
* at the top of the source tree.
*/

#include <stddef.h>
#include <sys/utsname.h>
#include <stdio.h>
#include "asterisk/ast_version.h"
#include "include/respoke_version.h"

int respoke_get_sdk_header(char *buf, size_t len) {
const char *asterisk_version = ast_get_version();
const char *respoke_version = respoke_get_version();
struct utsname un;
uname(&un);

return snprintf(buf, len-1,
"Respoke-Asterisk/%s (%s %s) Asterisk/%s",
respoke_version, un.sysname, un.release, asterisk_version);
}

0 comments on commit 61fbec0

Please sign in to comment.