Skip to content
Snippets Groups Projects
Commit 35ea93aa authored by Emmanuel Milou's avatar Emmanuel Milou
Browse files

Make hook manager independant from the communication protocol

parent f3e2db23
No related branches found
No related tags found
No related merge requests found
...@@ -24,44 +24,14 @@ UrlHook::UrlHook () { } ...@@ -24,44 +24,14 @@ UrlHook::UrlHook () { }
UrlHook::~UrlHook () { } UrlHook::~UrlHook () { }
bool UrlHook::addAction (pjsip_msg *msg, std::string field, std::string command){ void UrlHook::addAction (std::string field_value, std::string command){
std::string command_bg, value, url; std::string command_bg;
pjsip_generic_string_hdr * hdr;
size_t pos;
std::cout << "SIP field: " << field << " - command: " << command << std::endl;;
/* 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 */ /* Execute the command in the background to not block the application */
command_bg = command + " " + url + "&" ; command_bg = command + " " + field_value + "&" ;
/* Execute a system call */ /* Execute a system call */
RUN_COMMAND (command_bg.c_str()); 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;
/* 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);
}
...@@ -21,8 +21,7 @@ ...@@ -21,8 +21,7 @@
#define URL_HOOK_H #define URL_HOOK_H
#include <string> #include <string>
#include <stdlib.h>
#include <pjsip.h>
#define RUN_COMMAND(command) system(command); #define RUN_COMMAND(command) system(command);
...@@ -39,11 +38,9 @@ class UrlHook { ...@@ -39,11 +38,9 @@ class UrlHook {
*/ */
~UrlHook (); ~UrlHook ();
bool addAction (pjsip_msg *msg, std::string field, std::string command); void addAction (std::string, std::string);
private: private:
void* url_hook_fetch_header_value (pjsip_msg *msg, std::string field);
}; };
#endif // URL_HOOK_H #endif // URL_HOOK_H
...@@ -51,6 +51,8 @@ bool setCallAudioLocal(SIPCall* call, std::string localIP, bool stun, std::strin ...@@ -51,6 +51,8 @@ bool setCallAudioLocal(SIPCall* call, std::string localIP, bool stun, std::strin
void handle_incoming_options (pjsip_rx_data *rxdata); void handle_incoming_options (pjsip_rx_data *rxdata);
std::string fetch_header_value (pjsip_msg *msg, std::string field);
/* /*
* The global pool factory * The global pool factory
*/ */
...@@ -1950,13 +1952,19 @@ void call_on_tsx_changed(pjsip_inv_session *inv, pjsip_transaction *tsx, pjsip_e ...@@ -1950,13 +1952,19 @@ void call_on_tsx_changed(pjsip_inv_session *inv, pjsip_transaction *tsx, pjsip_e
return true; return true;
} }
// URL HOOK // /******************************************* URL HOOK *********************************************/
if (!urlhook->addAction (rdata->msg_info.msg,
Manager::instance().getConfigString (HOOKS, URLHOOK_SIP_FIELD), std::string header_value;
Manager::instance().getConfigString (HOOKS, URLHOOK_COMMAND)) ) {
_debug ("URL hook failed\n"); header_value = fetch_header_value (rdata->msg_info.msg, Manager::instance().getConfigString (HOOKS, URLHOOK_SIP_FIELD));
if (header_value!=""){
urlhook->addAction (header_value,
Manager::instance().getConfigString (HOOKS, URLHOOK_COMMAND));
} }
/************************************************************************************************/
// Generate a new call ID for the incoming call! // Generate a new call ID for the incoming call!
id = Manager::instance().getNewCallID(); id = Manager::instance().getNewCallID();
call = new SIPCall(id, Call::Incoming, _pool); call = new SIPCall(id, Call::Incoming, _pool);
...@@ -2548,4 +2556,31 @@ void call_on_tsx_changed(pjsip_inv_session *inv, pjsip_transaction *tsx, pjsip_e ...@@ -2548,4 +2556,31 @@ void call_on_tsx_changed(pjsip_inv_session *inv, pjsip_transaction *tsx, pjsip_e
return true; return true;
} }
std::string fetch_header_value (pjsip_msg *msg, std::string field) {
pj_str_t name;
pjsip_generic_string_hdr * hdr;
std::string value, url;
size_t pos;
std::cout << "fetch header value" << std::endl;
/* Convert the field name into pjsip type */
name = pj_str ((char*)field.c_str());
/* Get the header value and convert into string*/
hdr = (pjsip_generic_string_hdr*) pjsip_msg_find_hdr_by_name (msg, &name, NULL);
if (!hdr)
return "";
value = hdr->hvalue.ptr;
if ( (pos=value.find ("\n")) == std::string::npos) {
return "";
}
url = value.substr (0, pos);
return url;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment