diff --git a/src/hooks/urlhook.cpp b/src/hooks/urlhook.cpp index 5c8e8c41ada16f43cf4b65743c0b347630f97236..e1d78c40c454edb40f1ee3d67f9ebaff6ed4439d 100644 --- a/src/hooks/urlhook.cpp +++ b/src/hooks/urlhook.cpp @@ -18,21 +18,50 @@ */ #include "urlhook.h" - #include <iostream> UrlHook::UrlHook () { } UrlHook::~UrlHook () { } -void UrlHook::addAction (pjsip_msg *msg, std::string field, std::string command){ +bool UrlHook::addAction (pjsip_msg *msg, std::string field, std::string command){ - std::string command_bg; + std::string command_bg, value, url; + pjsip_generic_string_hdr * hdr; + size_t pos; std::cout << "SIP field: " << field << " - command: " << command << std::endl;; - command_bg = command + "&"; + /* Get the URL in the SIP header */ + if ( (hdr = (pjsip_generic_string_hdr*)this->url_hook_fetch_header_value (msg, field)) != NULL) + { + value = hdr->hvalue.ptr; + if ( (pos=value.find ("\n")) != std::string::npos) { + url = value.substr (0, pos); + + /* Execute the command in the background to not block the application */ + command_bg = command + " " + url + "&" ; + /* Execute a system call */ + RUN_COMMAND (command_bg.c_str()); + + return true; + } + else + return false; + } + + return false; +} + +void* UrlHook::url_hook_fetch_header_value (pjsip_msg *msg, std::string field) { + + pj_str_t name; + + std::cout << "url hook fetch header value" << std::endl; - system (command_bg.c_str()); + /* Convert the field name into pjsip type */ + name = pj_str ((char*)field.c_str()); + /* Get the header value and convert into string*/ + return pjsip_msg_find_hdr_by_name (msg, &name, NULL); } diff --git a/src/hooks/urlhook.h b/src/hooks/urlhook.h index 74cd61045f7dcdad83a6a1c217ea776bb6f132ef..238f983345b13fc4582eee618a0ec0218be3ca1f 100644 --- a/src/hooks/urlhook.h +++ b/src/hooks/urlhook.h @@ -24,6 +24,8 @@ #include <pjsip.h> +#define RUN_COMMAND(command) system(command); + class UrlHook { public: @@ -37,7 +39,11 @@ class UrlHook { */ ~UrlHook (); - void addAction (pjsip_msg *msg, std::string field, std::string command); + bool addAction (pjsip_msg *msg, std::string field, std::string command); + + private: + + void* url_hook_fetch_header_value (pjsip_msg *msg, std::string field); }; #endif // URL_HOOK_H diff --git a/src/sipvoiplink.cpp b/src/sipvoiplink.cpp index 21a97068a9bb1b05b5ea98e2f874abfe53821e3b..4d3944636a0e61ee5fba191bed30f6a96b852a16 100644 --- a/src/sipvoiplink.cpp +++ b/src/sipvoiplink.cpp @@ -1951,9 +1951,11 @@ void call_on_tsx_changed(pjsip_inv_session *inv, pjsip_transaction *tsx, pjsip_e } // URL HOOK // - urlhook->addAction (rdata->msg_info.msg, + if (!urlhook->addAction (rdata->msg_info.msg, Manager::instance().getConfigString (HOOKS, URLHOOK_SIP_FIELD), - Manager::instance().getConfigString (HOOKS, URLHOOK_COMMAND)); + Manager::instance().getConfigString (HOOKS, URLHOOK_COMMAND)) ) { + _debug ("URL hook failed\n"); + } // Generate a new call ID for the incoming call! id = Manager::instance().getNewCallID();