Commit 35ea93aa authored by Emmanuel Milou's avatar Emmanuel Milou

Make hook manager independant from the communication protocol

parent f3e2db23
......@@ -24,44 +24,14 @@ 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;
pjsip_generic_string_hdr * hdr;
size_t pos;
std::string command_bg;
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 */
command_bg = command + " " + url + "&" ;
/* Execute a system call */
RUN_COMMAND (command_bg.c_str());
return true;
}
else
return false;
}
return false;
/* Execute the command in the background to not block the application */
command_bg = command + " " + field_value + "&" ;
/* Execute a system call */
RUN_COMMAND (command_bg.c_str());
}
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 @@
#define URL_HOOK_H
#include <string>
#include <pjsip.h>
#include <stdlib.h>
#define RUN_COMMAND(command) system(command);
......@@ -39,11 +38,9 @@ class UrlHook {
*/
~UrlHook ();
bool addAction (pjsip_msg *msg, std::string field, std::string command);
void addAction (std::string, std::string);
private:
void* url_hook_fetch_header_value (pjsip_msg *msg, std::string field);
};
#endif // URL_HOOK_H
......@@ -51,6 +51,8 @@ bool setCallAudioLocal(SIPCall* call, std::string localIP, bool stun, std::strin
void handle_incoming_options (pjsip_rx_data *rxdata);
std::string fetch_header_value (pjsip_msg *msg, std::string field);
/*
* The global pool factory
*/
......@@ -1950,13 +1952,19 @@ void call_on_tsx_changed(pjsip_inv_session *inv, pjsip_transaction *tsx, pjsip_e
return true;
}
// URL HOOK //
if (!urlhook->addAction (rdata->msg_info.msg,
Manager::instance().getConfigString (HOOKS, URLHOOK_SIP_FIELD),
Manager::instance().getConfigString (HOOKS, URLHOOK_COMMAND)) ) {
_debug ("URL hook failed\n");
/******************************************* URL HOOK *********************************************/
std::string header_value;
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!
id = Manager::instance().getNewCallID();
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
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;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment