Add optional support of XMPP

This commit is contained in:
imen.bhiri 2016-05-25 14:13:38 +01:00
parent 9ec671ebf0
commit d17cae05d1
5 changed files with 91 additions and 55 deletions

View file

@ -5,7 +5,6 @@ icwmpd_SOURCES = \
../backupSession.c \
../config.c \
../cwmp.c \
../xmpp_cr.c \
../ipping.c \
../digestauth.c \
../event.c \
@ -38,9 +37,14 @@ icwmpd_SOURCES = \
../dm/dmtree/common/x_inteno_se_logincfg.c \
../dm/dmtree/common/x_inteno_se_power_mgmt.c \
../dm/dmtree/common/softwaremodules.c \
../dm/dmtree/common/xmpp.c \
../dm/dmtree/common/x_inteno_syslog.c
if XMPP_ENABLE
icwmpd_SOURCES += \
../dm/dmtree/common/xmpp.c \
../xmpp_cr.c
endif
if DATAMODEL_TR098
icwmpd_SOURCES += \
../dm/dmtree/tr098/lan_interfaces.c \

111
config.c
View file

@ -793,58 +793,63 @@ int get_global_config(struct config *conf)
{
return error;
}
if((error = uci_get_value(UCI_XMPP_ENABLE,&value)) == CWMP_OK)
{
if(value != NULL)
{
if ((strcasecmp(value,"true")==0) || (strcmp(value,"1")==0))
{
conf->xmpp_enable = true;
CWMP_LOG(INFO,"Xmpp connection id is %d \n", conf->xmpp_enable);
}
value = NULL;
#ifdef XMPP_ENABLE
if(conf->amd_version >= AMD_5)
{
if((error = uci_get_value(UCI_XMPP_ENABLE,&value)) == CWMP_OK)
{
if(value != NULL)
{
if ((strcasecmp(value,"true")==0) || (strcmp(value,"1")==0))
{
conf->xmpp_enable = true;
CWMP_LOG(INFO,"Xmpp connection id is %d \n", conf->xmpp_enable);
}
value = NULL;
}
}
if((error = uci_get_value(UCI_XMPP_CONNECTION_ID,&value)) == CWMP_OK)
{
int a = 0;
if(value != NULL)
{
a = atoi(value);
free(value);
value = NULL;
}
if(a==0)
{
CWMP_LOG(INFO,"Xmpp connection id :Empty");
conf->xmpp_connection_id = 0;
}
else
{
CWMP_LOG(INFO,"Xmpp connection id :%d \n", a);
conf->xmpp_connection_id = a;
}
}
else
{
return error;
}
if((error = uci_get_value(UCI_XMPP_ALLOWED_JID,&value)) == CWMP_OK)
{
if(value != NULL)
{
if (conf->xmpp_allowed_jid != NULL)
{
free(conf->xmpp_allowed_jid);
}
conf->xmpp_allowed_jid = value;
value = NULL;
}
}
else
{
return error;
}
}
if((error = uci_get_value(UCI_XMPP_CONNECTION_ID,&value)) == CWMP_OK)
{
int a = 0;
if(value != NULL)
{
a = atoi(value);
free(value);
value = NULL;
}
if(a==0)
{
CWMP_LOG(INFO,"Xmpp connection id :Empty");
conf->xmpp_connection_id = 0;
}
else
{
CWMP_LOG(INFO,"Xmpp connection id :%d \n", a);
conf->xmpp_connection_id = a;
}
}
else
{
return error;
}
if((error = uci_get_value(UCI_XMPP_ALLOWED_JID,&value)) == CWMP_OK)
{
if(value != NULL)
{
if (conf->xmpp_allowed_jid != NULL)
{
free(conf->xmpp_allowed_jid);
}
conf->xmpp_allowed_jid = value;
value = NULL;
}
}
else
{
return error;
}
#endif
return CWMP_OK;
}
@ -1054,6 +1059,7 @@ int cwmp_get_deviceid(struct cwmp *cwmp) {
return CWMP_OK;
}
#ifdef XMPP_ENABLE
int cwmp_get_xmpp_param(struct cwmp *cwmp) {
struct dmctx dmctx = {0};
@ -1106,6 +1112,7 @@ int cwmp_get_xmpp_param(struct cwmp *cwmp) {
end:
return CWMP_OK;
}
#endif
int cwmp_init(int argc, char** argv,struct cwmp *cwmp)
{
int error;
@ -1144,8 +1151,10 @@ int cwmp_init(int argc, char** argv,struct cwmp *cwmp)
}
dm_global_init();
cwmp_get_deviceid(cwmp);
#ifdef XMPP_ENABLE
if (conf->xmpp_enable && conf->xmpp_connection_id > 0)
cwmp_get_xmpp_param(cwmp);
#endif
dm_entry_load_enabled_notify();
return CWMP_OK;
}
@ -1161,8 +1170,10 @@ int cwmp_config_reload(struct cwmp *cwmp)
{
return error;
}
#ifdef XMPP_ENABLE
if (conf->xmpp_enable && conf->xmpp_connection_id != 0)
cwmp_get_xmpp_param(cwmp);
#endif
dm_entry_load_enabled_notify();
return CWMP_OK;
}

View file

@ -32,6 +32,11 @@ AC_ARG_ENABLE(debug, [AS_HELP_STRING([--enable-debug], [enable debugging message
AC_ARG_ENABLE(devel, [AS_HELP_STRING([--enable-devel], [enable development messages])], AC_DEFINE(WITH_DEV_DEBUG),)
AC_ARG_ENABLE(dummy_mode, [AS_HELP_STRING([--enable-dummy-mode], [enable dummy mode])], AC_DEFINE(DUMMY_MODE),)
AC_ARG_ENABLE(xmpp, [AS_HELP_STRING([--enable-xmpp],
[enable xmpp; (default --enable-xmpp=disable]))],,)
AM_CONDITIONAL([XMPP_DISABLE], [test "x$enable_xmpp" = "xdisable" ])
AM_CONDITIONAL([XMPP_ENABLE], [test "x$enable_xmpp" = "xenable" ])
# checks for programs
AC_PROG_CC
AM_PROG_CC_C_O
@ -110,6 +115,14 @@ AM_COND_IF([DATAMODEL_TR098], [
AM_COND_IF([DATAMODEL_TR181], [
AC_DEFINE(DATAMODEL_TR181)
])
AM_COND_IF([XMPP_DISABLE], [
AC_DEFINE(XMPP_DISABLE)
])
AM_COND_IF([XMPP_ENABLE], [
AC_DEFINE(XMPP_ENABLE)
])
AM_COND_IF([HTTP_CURL], [
AC_DEFINE(HTTP_CURL)
PKG_CHECK_MODULES(LIBCURL, [libcurl])

12
cwmp.c
View file

@ -547,11 +547,13 @@ void signal_handler(int signal_num)
_exit(EXIT_SUCCESS);
}
#ifdef XMPP_ENABLE
void *thread_xmpp_client_listen (void *v)
{
cwmp_xmpp_connect_client();
return NULL;
}
#endif
int main(int argc, char **argv)
{
@ -571,11 +573,12 @@ int main(int argc, char **argv)
pthread_t xmpp_client_thread;
struct sigaction act = {0};
xmpp_stanza_t *reply;
if (error = cwmp_init(argc, argv, cwmp))
{
return error;
}
#ifdef XMPP_ENABLE
xmpp_stanza_t *reply;
if(cwmp->conf.xmpp_enable) {
error = pthread_create(&xmpp_client_thread, NULL, &thread_xmpp_client_listen, NULL);
if (error<0)
@ -583,6 +586,7 @@ int main(int argc, char **argv)
CWMP_LOG(ERROR,"Error when lanching xmpp connection thread!");
}
}
#endif
init_ipping_diagnostic();
CWMP_LOG(INFO,"STARTING ICWMP");
cwmp->start_time = time(NULL);
@ -668,10 +672,12 @@ int main(int argc, char **argv)
pthread_join(apply_schedule_download_thread, NULL);
pthread_join(change_du_state_thread, NULL);
pthread_join(http_cr_server_thread, NULL);
#ifdef XMPP_ENABLE
if(cwmp->conf.xmpp_enable)
pthread_join(xmpp_client_thread, NULL);
exit_ipping_diagnostic();
cwmp_xmpp_exit();
CWMP_LOG(INFO,"EXIT ICWMP");
#endif
exit_ipping_diagnostic();
CWMP_LOG(INFO,"EXIT ICWMP");
return CWMP_OK;
}

View file

@ -124,7 +124,9 @@ struct prefix_method prefix_methods[] = {
{ DMROOT"X_INTENO_SE_PowerManagement.", 1, dm_powermgmt_enable_set, 0, &entry_method_root_X_INTENO_SE_PowerManagement },
{ DMROOT"X_INTENO_SE_SyslogCfg.", 1, NULL, 0, &entry_method_root_syslog },
{ DMROOT"SoftwareModules.", 1, NULL, 0, &entry_method_root_software_modules },
#ifdef XMPP_ENABLE
{ DMROOT"XMPP.", 1, NULL, 0, &entry_method_root_xmpp },
#endif
#ifdef DATAMODEL_TR181
{ DMROOT"Wifi.", 1, NULL, 0, &entry_method_root_Wifi },
{ DMROOT"Ethernet.", 1, NULL, 0, &entry_method_root_Ethernet },