Skip to content

Commit

Permalink
Support # in dtmf api (#61)
Browse files Browse the repository at this point in the history
* urldecode dtmf string

Support # character
  • Loading branch information
kingster authored Jun 1, 2022
1 parent e81cc56 commit 688c52a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
2 changes: 1 addition & 1 deletion tinyphone/consts.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@
#define MSG_CONTACT_IT_SUPPORT "ERROR Connecting Audio Device, Please Contact Floor IT Support"
#define MSG_DEVICE_ERROR "Audio Device Test Failed, Please Contact Floor IT Support"

#endif
#endif
14 changes: 14 additions & 0 deletions tinyphone/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,20 @@ namespace tp {
return response;
}

std::string urldecode(std::string data){
std::string out = data;
CURL *curl = curl_easy_init();
if(curl) {
char *decoded = curl_easy_unescape(curl,data.c_str(), data.length(), NULL);
if(decoded) {
out = std::string(decoded);
curl_free(decoded);
}
curl_easy_cleanup(curl);
}
return out;
}

std::string local_ip_address() {
boost::asio::io_service io_service;
boost::asio::ip::tcp::resolver resolver(io_service);
Expand Down
4 changes: 3 additions & 1 deletion tinyphone/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ namespace tp {

tp::HttpResponse http_post(std::string url, std::string body) throw (std::exception);

std::string urldecode(std::string data);

std::string local_ip_address();

bool is_tcp_port_in_use(unsigned short port);
Expand All @@ -33,4 +35,4 @@ namespace tp {

}

#endif
#endif
13 changes: 7 additions & 6 deletions tinyphone/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,8 @@ void TinyPhoneHttpServer::Start() {
}
catch (pj::Error& e) {
tp::MetricsClient.increment("api.login.error.pjsua_error");
CROW_LOG_ERROR << "Exception catched : " << e.reason;
return tp::response(500, DEFAULT_HTTP_SERVER_ERROR_REPONSE);
CROW_LOG_ERROR << "Exception catched : " << e.reason;
return tp::response(500, DEFAULT_HTTP_SERVER_ERROR_REPONSE);
}
catch (std::domain_error& e) {
tp::MetricsClient.increment("api.login.error.device_error");
Expand All @@ -256,9 +256,9 @@ void TinyPhoneHttpServer::Start() {
{ "message", response_msg },
{ "result", 503 }
});
} catch (...){
return tp::response(500, DEFAULT_HTTP_SERVER_ERROR_REPONSE);
}
} catch (...){
return tp::response(500, DEFAULT_HTTP_SERVER_ERROR_REPONSE);
}
});

CROW_ROUTE(app, "/accounts")
Expand Down Expand Up @@ -591,10 +591,11 @@ void TinyPhoneHttpServer::Start() {

CROW_ROUTE(app, "/calls/<int>/dtmf/<string>")
.methods("POST"_method)
([&phone](int call_id, string dtmf_digits) {
([&phone](int call_id, string dtmf_string) {
pj_thread_auto_register();

try {
string dtmf_digits = urldecode(dtmf_string);
SIPCall* call = phone.CallById(call_id);
if (call == nullptr) {
return tp::response(400, {
Expand Down

0 comments on commit 688c52a

Please sign in to comment.