OK, so writing kamailio module was fun and easy. All thanks to Daniel-Constantin for providing very useful hints, it took hardly 2-3 hours to write up a functional module that exposes data received on kamailio socket and data that is about to be sent out, in an event route, where it can be manipulated e.g. to encode and decode per custom encryption algorithms defined by script writer. Here is bleeding edge code,
http://webrtc.voip-demos.com/obfuscate.c.txtMost of the code is borrowed from topoh, nosip and msrp modules and works fine. There is just one little problem, that is unlike nosip module, the event route for obfuscate module gives error when i try to print source address using $si and $sp variables.
Here is an example kamailio.cfg
========================
loadmodule "nosip.so"
loadmodule "obfuscate.so"
...
event_route[nosip:msg] {
xlog("L_INFO", "[$pr:$si:$sp]: Received nosip message '$mb' \n");
}
event_route[obfuscate:msg] {
if (is_msg_obfuscated()) {
xlog("L_INFO", "[$pr:$si:$sp]: Received obfuscated message '$mb' \n");
$avp(msg) = $mb;
} else {
xlog("L_INFO", "[$pr:$dd:$dp]: Sending obfuscated message '$mb' \n");
$avp(msg) = $mb;
};
}
========================
using telnet when i send some random junk i get following in kamailio logs,
========================
webrtc[13284]: :
pv [../../parser/../ip_addr.h:669]: ip_addr2sbuf(): BUG: ip_addr2sbuf: unknown address family 0
webrtc[13284]: INFO: <script>:
[NONE::0]: Received obfuscated message 'lkasndkasldnaklsndklaskndklasnkldnasklndklasndlkasndkasndlkasnkldanskldnaslkdnlkasndlkasnldnaskdnlasdn#015#012#015#012'
webrtc[13284]: INFO: <script>:
[tcp:192.168.100.11:55206]: Received nosip message 'lkasndkasldnaklsndklaskndklasnkldnasklndklasndlkasndkasndlkasnkldanskldnaslkdnlkasndlkasnldnaskdnlasdn#015#012#015#012'
========================
Can you guys give any hint, what is wrong here? The "received msg" code is almost identical to nosip module yet, nosip module is able to show $si and $sp values while my module can not.
Also is it possible to expose destination socket address (ip + port) for "sent msg" (i.e. the destination socket where kamailio is about to send some sip message).