Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
savoirfairelinux
jami-daemon
Commits
35ea93aa
Commit
35ea93aa
authored
Mar 24, 2009
by
Emmanuel Milou
Browse files
Make hook manager independant from the communication protocol
parent
f3e2db23
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/hooks/urlhook.cpp
View file @
35ea93aa
...
...
@@ -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
);
}
src/hooks/urlhook.h
View file @
35ea93aa
...
...
@@ -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
src/sipvoiplink.cpp
View file @
35ea93aa
...
...
@@ -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
;
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment