Fix Transfer complete core dump

This commit is contained in:
Omar Kallel 2022-09-30 14:53:09 +01:00
parent f590a3f64d
commit a51be54532
9 changed files with 34 additions and 14 deletions

View file

@ -870,7 +870,7 @@ void load_upload(mxml_node_t *tree)
}
list_add(&(upload_request->list), ilist->prev);
if (upload_request->scheduled_time != 0)
count_download_queue++;
count_upload_queue++;
}
void load_change_du_state(mxml_node_t *tree)

View file

@ -14,7 +14,7 @@
pthread_mutex_t add_event_mutex = PTHREAD_MUTEX_INITIALIZER;
struct event_container *__cwmp_add_event_container(int event_code, char *command_key)
static struct event_container *__cwmp_add_event_container(int event_code, char *command_key)
{
struct event_container *event_container = NULL;
list_for_each_entry(event_container, &cwmp_main->session->events, list) {

View file

@ -22,6 +22,7 @@
#include "ubus_utils.h"
#include "config.h"
#include "digauth.h"
#include "session.h"
#define REALM "authenticate@cwmp"
#define OPAQUE "11733b200778ce33060f31c9af70a870ba96ddd4"
@ -304,11 +305,13 @@ error:
static void http_success_cr(void)
{
CWMP_LOG(INFO, "Connection Request triggering ...");
pthread_mutex_lock(&cwmp_session_mutex);
struct blob_buf b = { 0 };
memset(&b, 0, sizeof(struct blob_buf));
blob_buf_init(&b, 0);
icwmp_ubus_invoke("tr069", "inform", b.head, NULL, NULL);
blob_buf_free(&b);
pthread_mutex_unlock(&cwmp_session_mutex);
}
static void http_cr_new_client(int client, bool service_available)

View file

@ -618,7 +618,7 @@ int cwmp_rpc_acs_prepare_transfer_complete(struct rpc *rpc)
transfer_complete_xml_attrs.complete_time = &p->complete_time;
}
int faultcode = (p && p->fault_code) ? atoi(FAULT_CPE_ARRAY[p->fault_code].CODE) : 0;
int faultcode = (p && p->fault_code && (p->fault_code < __FAULT_CPE_MAX)) ? atoi(FAULT_CPE_ARRAY[p->fault_code].CODE) : 0;
transfer_complete_xml_attrs.fault_code = &faultcode;
char *faultstring = strdup((p && p->fault_code) ? FAULT_CPE_ARRAY[p->fault_code].DESCRIPTION : "");
transfer_complete_xml_attrs.fault_string = &faultstring;
@ -1439,7 +1439,7 @@ int cancel_transfer(char *key)
bkp_session_save();
list_del(&(pupload->list));
if (pupload->scheduled_time != 0)
count_download_queue--;
count_upload_queue--;
cwmp_free_upload_request(pupload);
}
}
@ -1933,7 +1933,7 @@ int cwmp_handle_rpc_cpe_upload(struct rpc *rpc)
if (error)
goto fault;
if (count_download_queue >= MAX_DOWNLOAD_QUEUE) {
if (count_upload_queue >= MAX_UPLOAD_QUEUE) {
error = FAULT_CPE_RESOURCES_EXCEEDED;
} else if (upload->url == NULL || (strcmp(upload->url, "") == 0)) {
error = FAULT_CPE_REQUEST_DENIED;
@ -1973,7 +1973,7 @@ int cwmp_handle_rpc_cpe_upload(struct rpc *rpc)
}
list_add(&(upload->list), ilist->prev);
if (upload_delay != 0) {
count_download_queue++;
count_upload_queue++;
upload->scheduled_time = scheduled_time;
}
bkp_session_insert_upload(upload);

View file

@ -33,6 +33,8 @@
#include "sched_inform.h"
#include "cwmp_du_state.h"
pthread_mutex_t cwmp_session_mutex = PTHREAD_MUTEX_INITIALIZER;
static void cwmp_periodic_session_timer(struct uloop_timeout *timeout);
struct uloop_timeout session_timer = { .cb = cwmp_schedule_session };
struct uloop_timeout periodic_session_timer = { .cb = cwmp_periodic_session_timer };
@ -86,6 +88,8 @@ int clean_cwmp_session_structure()
int cwmp_session_rpc_destructor(struct rpc *rpc)
{
if (rpc == NULL)
return CWMP_GEN_ERR;
list_del(&(rpc->list));
free(rpc);
return CWMP_OK;
@ -392,7 +396,9 @@ void trigger_cwmp_session_timer()
void cwmp_schedule_session(struct uloop_timeout *timeout __attribute__((unused)))
{
pthread_mutex_lock(&cwmp_session_mutex);
start_cwmp_session();
pthread_mutex_unlock(&cwmp_session_mutex);
}
void trigger_cwmp_session_timer_with_event(struct uloop_timeout *timeout)
@ -404,7 +410,13 @@ void trigger_cwmp_session_timer_with_event(struct uloop_timeout *timeout)
void cwmp_schedule_session_with_event(struct uloop_timeout *timeout)
{
pthread_mutex_lock(&cwmp_session_mutex);
struct session_timer_event *session_event = container_of(timeout, struct session_timer_event, session_timer_evt);
if (session_event == NULL) {
CWMP_LOG(ERROR, "session %s: session_event is null", __FUNCTION__);
pthread_mutex_unlock(&cwmp_session_mutex);
return;
}
FREE(global_session_event);
global_session_event = session_event;
if (session_event->event == TransferClt_Evt) {
@ -431,6 +443,7 @@ void cwmp_schedule_session_with_event(struct uloop_timeout *timeout)
}
start_cwmp_session();
pthread_mutex_unlock(&cwmp_session_mutex);
}
static void cwmp_periodic_session_timer(struct uloop_timeout *timeout __attribute__((unused)))

View file

@ -15,7 +15,7 @@
#include <mxml.h>
#include "common.h"
extern pthread_mutex_t cwmp_session_mutex;
extern struct uloop_timeout retry_session_timer;
typedef struct session_status {

View file

@ -14,7 +14,6 @@
#include <sys/stat.h>
#include "upload.h"
#include "download.h"
#include "datamodel_interface.h"
#include "log.h"
#include "backupSession.h"
@ -25,6 +24,8 @@
#define CURL_TIMEOUT 20
int count_upload_queue = 0;
LIST_HEAD(list_upload);
int lookup_vcf_name(int instance, char **value)
@ -101,6 +102,7 @@ int upload_file(const char *file_path, const char *url, const char *username, co
curl_easy_setopt(curl, CURLOPT_TIMEOUT, CURL_TIMEOUT);
curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 50L);
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
//curl_easy_setopt(curl, CURLOPT_POST, 1L);
curl_easy_setopt(curl, CURLOPT_HTTPAUTH, (long)CURLAUTH_ANY);
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_READDATA, fd_upload);
@ -284,7 +286,7 @@ int cwmp_scheduledUpload_remove_all()
list_del(&(upload->list));
bkp_session_delete_upload(upload);
if (upload->scheduled_time != 0)
count_download_queue--;
count_upload_queue--;
cwmp_free_upload_request(upload);
}
return CWMP_OK;
@ -298,7 +300,7 @@ void cwmp_start_upload(struct uloop_timeout *timeout)
pupload = container_of(timeout, struct upload, handler_timer);
CWMP_LOG(INFO, "Launch download file %s", pupload->url);
CWMP_LOG(INFO, "Launch upload file %s", pupload->url);
error = cwmp_launch_upload(pupload, &ptransfer_complete);
sleep(3);
if (error != FAULT_CPE_NO_FAULT) {
@ -307,10 +309,9 @@ void cwmp_start_upload(struct uloop_timeout *timeout)
bkp_session_insert_transfer_complete(ptransfer_complete);
bkp_session_save();
cwmp_root_cause_transfer_complete(ptransfer_complete);
list_del(&(pupload->list));
if (pupload->scheduled_time != 0)
count_download_queue--;
count_upload_queue--;
cwmp_free_upload_request(pupload);
struct session_timer_event *upload_inform_event = calloc(1, sizeof(struct session_timer_event));
@ -325,7 +326,7 @@ void apply_upload()
{
struct list_head *ilist;
list_for_each (ilist, &(list_upload)) {
struct download *upload = list_entry(ilist, struct download, list);
struct upload *upload = list_entry(ilist, struct upload, list);
int upload_delay = 0;
if (upload->scheduled_time > time(NULL)) {
upload_delay = upload->scheduled_time - time(NULL);

View file

@ -14,7 +14,10 @@
#include "common.h"
#define MAX_UPLOAD_QUEUE 10
extern struct list_head list_upload;
extern int count_upload_queue;
int cwmp_launch_upload(struct upload *pupload, struct transfer_complete **ptransfer_complete);
void *thread_cwmp_rpc_cpe_upload(void *v);

View file

@ -699,7 +699,7 @@ void event_container_list_to_xml_data_list(struct list_head *event_container_lis
struct xml_list_data *xml_data = calloc(1, sizeof(struct xml_list_data));
list_add_tail(&xml_data->list, xml_data_list);
xml_data->event_code = event_container->code;
xml_data->command_key = strdup(event_container->command_key);
xml_data->command_key = strdup(event_container->command_key ? event_container->command_key : "");
}
}