Commit f3e2db23 authored by Emmanuel Milou's avatar Emmanuel Milou

Add functional url hook

parent 0fc88dd5
......@@ -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);
}
......@@ -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
......@@ -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();
......
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