I am trying to create a custom Asterisk PJSIP module that can:
- 1) analyse incoming sip messages
- 2) print info from sip header into log/console
Here is my code (simplified) :
#include "asterisk.h"
ASTERISK_REGISTER_FILE()
#ifndef AST_MODULE
#define AST_MODULE "res_modul"
#endif
//bunch of libraries here
static pj_bool_t logging_on_rx_msg(pjsip_rx_data *rdata);
static pj_bool_t logging_on_rx_msg(pjsip_rx_data *rdata)
{
char *method;
method= rdata->pkt_info.packet;
ast_log(LOG_NOTICE,"SIP METHOD is: %.8s \n",method);
return PJ_SUCCESS;
}
static pjsip_module logging_module = {
.name = { "Test module", 20 },
.priority = 0,
.on_rx_request = logging_on_rx_msg,
.on_rx_response = logging_on_rx_msg,
};
static int load_module(void)
{
CHECK_PJSIP_MODULE_LOADED();
ast_log(AST_LOG_WARNING, "Success in loading!");
ast_sip_register_service(&logging_module);
return AST_MODULE_LOAD_SUCCESS;
}
static int unload_module(void)
{
ast_sip_unregister_service(&logging_module);
return 0;
}
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "Test module",
.support_level = AST_MODULE_SUPPORT_EXTENDED,
.load = load_module,
.unload = unload_module,
.load_pri = AST_MODPRI_DEFAULT,
);
When I try to compile Asterisk with my module i get a compilation error:
menuselect/menuselect --check-deps menuselect.makeopts
[CC] res_modul.c -> res_modul.o
[LD] res_modul.o -> res_modul.so
[LD] res_pjsip.o res_pjsip/security_events.o res_pjsip/pjsip_options.o res_pjsip/location.o res_pjsip/config_global.o res_pjsip/pjsip_transport_events.o res_pjsip/presence_xml.o res_pjsip/pjsip_resolver.o res_pjsip/config_system.o res_pjsip/config_domain_aliases.o res_pjsip/config_transport.o res_pjsip/pjsip_distributor.o res_pjsip/pjsip_configuration.o res_pjsip/res_modul.o res_pjsip/pjsip_session.o res_pjsip/pjsip_message_filter.o res_pjsip/pjsip_global_headers.o res_pjsip/pjsip_transport_management.o res_pjsip/pjsip_cli.o res_pjsip/config_auth.o res_pjsip/pjsip_scheduler.o -> res_pjsip.so
res_pjsip/res_modul.o: In function `__internal_res_pjsip_self':
/usr/local/src/asterisk-14.7.6/res/res_pjsip/res_modul.c:136: multiple definition of `__internal_res_pjsip_self'
res_pjsip.o:/usr/local/src/asterisk-14.7.6/res/res_pjsip.c:4918: first defined here
collect2: error: ld returned 1 exit status
I have no idea what causes this, there's no definition of `__internal_res_pjsip_self' in the source code. Not in my module, not in the res_pjsip.c file. According to the compilation error, its defined in res_pjsip.c:4918, but at that line is just the AST_MODULE_INFO.