mirror of
https://dev.iopsys.eu/bbf/icwmp.git
synced 2026-01-28 01:27:16 +01:00
Fix logging and acs_changed logic
This commit is contained in:
parent
994135c662
commit
7b0f7382a9
8 changed files with 76 additions and 32 deletions
|
|
@ -92,8 +92,10 @@ int bkp_session_check_file()
|
|||
|
||||
int save_acs_bkp_config()
|
||||
{
|
||||
CWMP_LOG(DEBUG, "%s:%d entry", __func__, __LINE__);
|
||||
bkp_session_simple_insert("acs", "URL", cwmp_main->conf.acs_url);
|
||||
bkp_session_save();
|
||||
CWMP_LOG(DEBUG, "%s:%d exit", __func__, __LINE__);
|
||||
return CWMP_OK;
|
||||
}
|
||||
|
||||
|
|
|
|||
30
src/config.c
30
src/config.c
|
|
@ -118,20 +118,30 @@ int cwmp_get_deviceid()
|
|||
{
|
||||
struct cwmp_dm_parameter dm_param = {0};
|
||||
|
||||
cwmp_get_parameter_value("Device.DeviceInfo.Manufacturer", &dm_param);
|
||||
snprintf(cwmp_main->deviceid.manufacturer, sizeof(cwmp_main->deviceid.manufacturer), "%s", dm_param.value ? dm_param.value : "");
|
||||
if (CWMP_STRLEN(cwmp_main->deviceid.manufacturer) == 0) {
|
||||
cwmp_get_parameter_value("Device.DeviceInfo.Manufacturer", &dm_param);
|
||||
snprintf(cwmp_main->deviceid.manufacturer, sizeof(cwmp_main->deviceid.manufacturer), "%s", dm_param.value ? dm_param.value : "");
|
||||
}
|
||||
|
||||
cwmp_get_parameter_value("Device.DeviceInfo.SerialNumber", &dm_param);
|
||||
snprintf(cwmp_main->deviceid.serialnumber, sizeof(cwmp_main->deviceid.serialnumber), "%s", dm_param.value ? dm_param.value : "");
|
||||
if (CWMP_STRLEN(cwmp_main->deviceid.serialnumber) == 0) {
|
||||
cwmp_get_parameter_value("Device.DeviceInfo.SerialNumber", &dm_param);
|
||||
snprintf(cwmp_main->deviceid.serialnumber, sizeof(cwmp_main->deviceid.serialnumber), "%s", dm_param.value ? dm_param.value : "");
|
||||
}
|
||||
|
||||
cwmp_get_parameter_value("Device.DeviceInfo.ProductClass", &dm_param);
|
||||
snprintf(cwmp_main->deviceid.productclass, sizeof(cwmp_main->deviceid.productclass), "%s", dm_param.value ? dm_param.value : "");
|
||||
if (CWMP_STRLEN(cwmp_main->deviceid.productclass) == 0) {
|
||||
cwmp_get_parameter_value("Device.DeviceInfo.ProductClass", &dm_param);
|
||||
snprintf(cwmp_main->deviceid.productclass, sizeof(cwmp_main->deviceid.productclass), "%s", dm_param.value ? dm_param.value : "");
|
||||
}
|
||||
|
||||
cwmp_get_parameter_value("Device.DeviceInfo.ManufacturerOUI", &dm_param);
|
||||
snprintf(cwmp_main->deviceid.oui, sizeof(cwmp_main->deviceid.oui), "%s", dm_param.value ? dm_param.value : "");
|
||||
if (CWMP_STRLEN(cwmp_main->deviceid.oui) == 0) {
|
||||
cwmp_get_parameter_value("Device.DeviceInfo.ManufacturerOUI", &dm_param);
|
||||
snprintf(cwmp_main->deviceid.oui, sizeof(cwmp_main->deviceid.oui), "%s", dm_param.value ? dm_param.value : "");
|
||||
}
|
||||
|
||||
cwmp_get_parameter_value("Device.DeviceInfo.SoftwareVersion", &dm_param);
|
||||
snprintf(cwmp_main->deviceid.softwareversion, sizeof(cwmp_main->deviceid.softwareversion), "%s", dm_param.value ? dm_param.value : "");
|
||||
if (CWMP_STRLEN(cwmp_main->deviceid.softwareversion) == 0) {
|
||||
cwmp_get_parameter_value("Device.DeviceInfo.SoftwareVersion", &dm_param);
|
||||
snprintf(cwmp_main->deviceid.softwareversion, sizeof(cwmp_main->deviceid.softwareversion), "%s", dm_param.value ? dm_param.value : "");
|
||||
}
|
||||
|
||||
return CWMP_OK;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,6 +60,7 @@ void move_next_session_events_to_actual_session()
|
|||
|
||||
int cwmp_remove_all_session_events()
|
||||
{
|
||||
CWMP_LOG(DEBUG, "%s:%d entry", __func__, __LINE__);
|
||||
struct list_head *events_ptr = cwmp_main->session->events.next;
|
||||
while (events_ptr != &cwmp_main->session->events) {
|
||||
struct event_container *event_container;
|
||||
|
|
@ -76,11 +77,13 @@ int cwmp_remove_all_session_events()
|
|||
events_ptr = cwmp_main->session->events.next;
|
||||
}
|
||||
bkp_session_save();
|
||||
CWMP_LOG(DEBUG, "%s:%d exit", __func__, __LINE__);
|
||||
return CWMP_OK;
|
||||
}
|
||||
|
||||
int remove_single_event(int event_code)
|
||||
{
|
||||
CWMP_LOG(DEBUG, "%s:%d entry", __func__, __LINE__);
|
||||
while (cwmp_main->session->events.next != &cwmp_main->session->events) {
|
||||
struct event_container *event_container;
|
||||
event_container = list_entry(cwmp_main->session->events.next, struct event_container, list);
|
||||
|
|
@ -104,5 +107,6 @@ int remove_single_event(int event_code)
|
|||
free(event_container);
|
||||
}
|
||||
}
|
||||
CWMP_LOG(DEBUG, "%s:%d exit", __func__, __LINE__);
|
||||
return CWMP_OK;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -117,8 +117,8 @@ static int cwmp_root_cause_event_bootstrap(void)
|
|||
if (acsurl == NULL || CWMP_STRCMP(cwmp_main->conf.acs_url, acsurl) != 0) {
|
||||
struct event_container *event_container;
|
||||
event_container = cwmp_add_event_container(EVENT_IDX_0BOOTSTRAP, "");
|
||||
FREE(acsurl);
|
||||
if (event_container == NULL) {
|
||||
FREE(acsurl);
|
||||
CWMP_LOG(ERROR, "event %s: event_container is null", __FUNCTION__);
|
||||
return CWMP_MEM_ERR;
|
||||
}
|
||||
|
|
@ -128,13 +128,10 @@ static int cwmp_root_cause_event_bootstrap(void)
|
|||
cwmp_scheduledDownload_remove_all();
|
||||
cwmp_scheduled_Download_remove_all();
|
||||
cwmp_scheduledUpload_remove_all();
|
||||
|
||||
cwmp_main->acs_changed = true;
|
||||
} else {
|
||||
FREE(acsurl);
|
||||
cwmp_main->acs_changed = false;
|
||||
}
|
||||
|
||||
FREE(acsurl);
|
||||
|
||||
return CWMP_OK;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -299,7 +299,7 @@ int icwmp_http_send_message(char *msg_out, int msg_out_len, char **msg_in)
|
|||
errbuf[len - 1] = '\0';
|
||||
CWMP_LOG(ERROR, "libcurl: (%d) %s", res, errbuf);
|
||||
} else {
|
||||
CWMP_LOG(ERROR, "libcurl: (%d) %s", res, curl_easy_strerror(res));
|
||||
CWMP_LOG(ERROR, "libcurl: [%d] %s", res, curl_easy_strerror(res));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
12
src/log.c
12
src/log.c
|
|
@ -31,7 +31,7 @@ static pthread_mutex_t mutex_log = PTHREAD_MUTEX_INITIALIZER;
|
|||
|
||||
int log_set_severity_idx(char *value)
|
||||
{
|
||||
if (value == NULL)
|
||||
if (CWMP_STRLEN(value) == 0)
|
||||
return 1;
|
||||
|
||||
int i;
|
||||
|
|
@ -46,7 +46,7 @@ int log_set_severity_idx(char *value)
|
|||
|
||||
int log_set_log_file_name(char *value)
|
||||
{
|
||||
if (value != NULL) {
|
||||
if (CWMP_STRLEN(value) != 0) {
|
||||
snprintf(log_file_name, sizeof(log_file_name), "%s", value);
|
||||
} else {
|
||||
snprintf(log_file_name, sizeof(log_file_name), "%s", DEFAULT_LOG_FILE_NAME);
|
||||
|
|
@ -56,7 +56,7 @@ int log_set_log_file_name(char *value)
|
|||
|
||||
int log_set_file_max_size(char *value)
|
||||
{
|
||||
if (value != NULL) {
|
||||
if (CWMP_STRLEN(value) != 0) {
|
||||
log_max_size = atol(value);
|
||||
} else {
|
||||
log_max_size = 102400;
|
||||
|
|
@ -66,7 +66,7 @@ int log_set_file_max_size(char *value)
|
|||
|
||||
int log_set_on_console(char *value)
|
||||
{
|
||||
if (value == NULL)
|
||||
if (CWMP_STRLEN(value) == 0)
|
||||
return 1;
|
||||
|
||||
enable_log_stdout = str_to_bool(value);
|
||||
|
|
@ -75,7 +75,7 @@ int log_set_on_console(char *value)
|
|||
|
||||
int log_set_on_file(char *value)
|
||||
{
|
||||
if (value == NULL)
|
||||
if (CWMP_STRLEN(value) == 0)
|
||||
return 1;
|
||||
|
||||
enable_log_file = str_to_bool(value);
|
||||
|
|
@ -84,7 +84,7 @@ int log_set_on_file(char *value)
|
|||
|
||||
int log_set_on_syslog(char *value)
|
||||
{
|
||||
if (value == NULL)
|
||||
if (CWMP_STRLEN(value) == 0)
|
||||
return 1;
|
||||
|
||||
enable_log_syslog = str_to_bool(value);
|
||||
|
|
|
|||
|
|
@ -275,6 +275,7 @@ static void set_cwmp_session_status_state(int status)
|
|||
|
||||
void set_cwmp_session_status(int status, int retry_time)
|
||||
{
|
||||
CWMP_LOG(DEBUG, "%s:%d entry", __func__, __LINE__);
|
||||
cwmp_main->session->session_status.last_status = status;
|
||||
set_cwmp_session_status_state(status);
|
||||
if (status == SESSION_SUCCESS) {
|
||||
|
|
@ -290,6 +291,7 @@ void set_cwmp_session_status(int status, int retry_time)
|
|||
cwmp_main->session->session_status.next_retry = time(NULL) + retry_time;
|
||||
cwmp_main->session->session_status.failure_session++;
|
||||
}
|
||||
CWMP_LOG(DEBUG, "%s:%d exit", __func__, __LINE__);
|
||||
}
|
||||
|
||||
void rpc_exit()
|
||||
|
|
@ -401,18 +403,21 @@ void start_cwmp_session(void)
|
|||
schedule_session_retry();
|
||||
} else {
|
||||
save_acs_bkp_config();
|
||||
if (!cwmp_main->session->session_status.is_heartbeat)
|
||||
if (!cwmp_main->session->session_status.is_heartbeat) {
|
||||
cwmp_remove_all_session_events();
|
||||
else
|
||||
} else {
|
||||
remove_single_event(EVENT_IDX_14HEARTBEAT);
|
||||
}
|
||||
|
||||
cwmp_main->retry_count_session = 0;
|
||||
set_cwmp_session_status(SESSION_SUCCESS, 0);
|
||||
if (cwmp_main->throttle_session_triggered == true) {
|
||||
cwmp_main->throttle_session_triggered = false;
|
||||
if (!cwmp_main->throttle_session)
|
||||
if (!cwmp_main->throttle_session) {
|
||||
uloop_timeout_cancel(&throttle_session_timer);
|
||||
else
|
||||
} else {
|
||||
cwmp_main->throttle_session = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
run_session_end_func();
|
||||
|
|
|
|||
|
|
@ -121,7 +121,15 @@ static void config_get_acs_elements(struct uci_section *s)
|
|||
|
||||
char *url = get_value_from_uci_option(acs_tb[UCI_ACS_URL]);
|
||||
char *dhcp_url = get_value_from_uci_option(acs_tb[UCI_ACS_DHCP_URL]);
|
||||
snprintf(cwmp_main->conf.acs_url, sizeof(cwmp_main->conf.acs_url), "%s", cwmp_main->conf.dhcp_discovery ? (strlen(dhcp_url) ? dhcp_url : url) : url);
|
||||
char *new_url = cwmp_main->conf.dhcp_discovery ? (CWMP_STRLEN(dhcp_url) ? dhcp_url : url) : url;
|
||||
|
||||
if (CWMP_STRCMP(cwmp_main->conf.acs_url, new_url) != 0) {
|
||||
if (CWMP_STRLEN(cwmp_main->conf.acs_url) != 0 && CWMP_STRLEN(new_url) != 0)
|
||||
cwmp_main->acs_changed = true;
|
||||
|
||||
snprintf(cwmp_main->conf.acs_url, sizeof(cwmp_main->conf.acs_url), "%s", new_url);
|
||||
}
|
||||
|
||||
CWMP_LOG(DEBUG, "CWMP CONFIG - acs url: %s", cwmp_main->conf.acs_url);
|
||||
|
||||
snprintf(cwmp_main->conf.acs_userid, sizeof(cwmp_main->conf.acs_userid), "%s", get_value_from_uci_option(acs_tb[UCI_ACS_USERID]));
|
||||
|
|
@ -605,6 +613,8 @@ int get_uci_path_value(const char *conf_dir, char *path, char *value, size_t max
|
|||
return -1;
|
||||
}
|
||||
|
||||
// init with default null data
|
||||
value[0]='\0';
|
||||
pthread_mutex_lock(&mutex_config_load);
|
||||
uci_ctx = uci_alloc_context();
|
||||
if (!uci_ctx) {
|
||||
|
|
@ -624,13 +634,29 @@ int get_uci_path_value(const char *conf_dir, char *path, char *value, size_t max
|
|||
goto exit;
|
||||
}
|
||||
|
||||
if ((ptr.flags & UCI_LOOKUP_COMPLETE)
|
||||
&& (ptr.o != NULL)
|
||||
&& (ptr.o->v.string!=NULL)) {
|
||||
if (ptr.flags & UCI_LOOKUP_COMPLETE) {
|
||||
ret = 0;
|
||||
CWMP_STRNCPY(value, ptr.o->v.string, max_value_len);
|
||||
if (ptr.o->type == UCI_TYPE_STRING) {
|
||||
CWMP_STRNCPY(value, ptr.o->v.string, max_value_len);
|
||||
} else if (ptr.o->type == UCI_TYPE_LIST) {
|
||||
struct uci_element *e;
|
||||
size_t len;
|
||||
|
||||
uci_foreach_element(&ptr.o->v.list, e) {
|
||||
len = CWMP_STRLEN(value);
|
||||
if (max_value_len < len + CWMP_STRLEN(e->name)) {
|
||||
break;
|
||||
}
|
||||
snprintf(value + len, max_value_len - len, "%s,", e->name);
|
||||
}
|
||||
len = CWMP_STRLEN(value);
|
||||
value[len - 1] = '\0';
|
||||
} else if (ptr.s) {
|
||||
CWMP_STRNCPY(value, ptr.s->type, max_value_len);
|
||||
}
|
||||
}
|
||||
|
||||
CWMP_LOG(DEBUG, "UCI [%s::%s]", path, value);
|
||||
exit:
|
||||
FREE(str);
|
||||
if (uci_ctx) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue