Code segragation: create new source files for new functions

This commit is contained in:
Omar Kallel 2022-02-23 18:08:25 +01:00
parent 049779d10c
commit 236e8fb73b
24 changed files with 165 additions and 84 deletions

View file

@ -22,6 +22,7 @@
#include "soap.h"
#include "upload.h"
#include "sched_inform.h"
#include "cwmp_event.h"
static mxml_node_t *bkp_tree = NULL;
pthread_mutex_t mutex_backup_session = PTHREAD_MUTEX_INITIALIZER;

View file

@ -8,12 +8,15 @@ icwmpd_SOURCES = \
../log.c \
../cwmp_uci.c \
../config.c \
../cwmp_config.c \
../session.c \
../backupSession.c \
../md5.c \
../digestauth.c \
../event.c \
../cwmp_event.c \
../http.c \
../cwmp_http.c \
../netlink.c \
../ubus.c \
../datamodel_interface.c \
@ -26,7 +29,7 @@ icwmpd_SOURCES = \
../upload.c \
../sched_inform.c \
../xml.c \
../soap.c \
../soap.c \
../diagnostic.c \
../reboot.c \
../cwmp.c

View file

@ -626,16 +626,6 @@ end:
return error;
}
int cwmp_get_deviceid()
{
cwmp_get_leaf_value("Device.DeviceInfo.Manufacturer", &cwmp_main->deviceid.manufacturer);
cwmp_get_leaf_value("Device.DeviceInfo.SerialNumber", &cwmp_main->deviceid.serialnumber);
cwmp_get_leaf_value("Device.DeviceInfo.ProductClass", &cwmp_main->deviceid.productclass);
cwmp_get_leaf_value("Device.DeviceInfo.ManufacturerOUI", &cwmp_main->deviceid.oui);
cwmp_get_leaf_value("Device.DeviceInfo.SoftwareVersion", &cwmp_main->deviceid.softwareversion);
return CWMP_OK;
}
int cwmp_config_reload()
{
memset(&cwmp_main->env, 0, sizeof(struct env));

4
cwmp.c
View file

@ -22,6 +22,7 @@
#include "session.h"
#include "backupSession.h"
#include "http.h"
#include "cwmp_http.h"
#include "diagnostic.h"
#include "config.h"
#include "ubus.h"
@ -35,6 +36,9 @@
#include "digestauth.h"
#include "soap.h"
#include "netlink.h"
#include "cwmp_http.h"
#include "cwmp_config.h"
#include "cwmp_http.h"
void load_forced_inform_json_file()
{

22
cwmp_config.c Normal file
View file

@ -0,0 +1,22 @@
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* Copyright (C) 2013-2021 iopsys Software Solutions AB
* Author Omar Kallel <omar.kallel@pivasoftware.com>
*
*/
#include "cwmp_config.h"
#include "datamodel_interface.h"
int cwmp_get_deviceid()
{
cwmp_get_leaf_value("Device.DeviceInfo.Manufacturer", &cwmp_main->deviceid.manufacturer);
cwmp_get_leaf_value("Device.DeviceInfo.SerialNumber", &cwmp_main->deviceid.serialnumber);
cwmp_get_leaf_value("Device.DeviceInfo.ProductClass", &cwmp_main->deviceid.productclass);
cwmp_get_leaf_value("Device.DeviceInfo.ManufacturerOUI", &cwmp_main->deviceid.oui);
cwmp_get_leaf_value("Device.DeviceInfo.SoftwareVersion", &cwmp_main->deviceid.softwareversion);
return CWMP_OK;
}

49
cwmp_event.c Normal file
View file

@ -0,0 +1,49 @@
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* Copyright (C) 2013-2021 iopsys Software Solutions AB
* Author Omar Kallel <omar.kallel@pivasoftware.com>
*/
#include "cwmp_event.h"
#include "common.h"
#include "session.h"
struct event_container *__cwmp_add_event_container(int event_code, char *command_key)
{
static int id;
struct event_container *event_container;
list_for_each_entry(event_container, &cwmp_main->session->events, list) {
if (event_container->code == event_code && EVENT_CONST[event_code].TYPE == EVENT_TYPE_SINGLE) {
return event_container;
}
if (event_container->code > event_code) {
break;
}
}
event_container = calloc(1, sizeof(struct event_container));
if (event_container == NULL) {
return NULL;
}
INIT_LIST_HEAD(&(event_container->head_dm_parameter));
list_add_tail(&(event_container->list), &(cwmp_main->session->events));
event_container->code = event_code;
event_container->command_key = command_key ? strdup(command_key) : strdup("");
if ((id < 0) || (id >= MAX_INT_ID)) {
id = 0;
}
id++;
event_container->id = id;
return event_container;
}
struct event_container *cwmp_add_event_container(int event_code, char *command_key)
{
pthread_mutex_lock(&add_event_mutext);
struct event_container *event = __cwmp_add_event_container(event_code, command_key);
pthread_mutex_unlock(&add_event_mutext);
return event;
}

46
cwmp_http.c Normal file
View file

@ -0,0 +1,46 @@
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* Copyright (C) 2013-2021 iopsys Software Solutions AB
* Author Omar Kallel <omar.kallel@pivasoftware.com>
*/
#include <pthread.h>
#include "common.h"
#include "cwmp_http.h"
#include "http.h"
#include "log.h"
struct uloop_fd http_event6;
pthread_t http_cr_server_thread;
void http_server_listen_uloop(struct uloop_fd *ufd __attribute__((unused)), unsigned events __attribute__((unused)))
{
http_server_listen();
}
void http_server_start_uloop(void)
{
http_server_init();
http_event6.fd = cwmp_main->cr_socket_desc;
http_event6.cb = http_server_listen_uloop;
uloop_fd_add(&http_event6, ULOOP_READ | ULOOP_EDGE_TRIGGER);
}
static void *thread_http_cr_server_listen(void *v __attribute__((unused)))
{
http_server_listen();
return NULL;
}
void http_server_start(void)
{
int error = pthread_create(&http_cr_server_thread, NULL, &thread_http_cr_server_listen, NULL);
if (error < 0) {
CWMP_LOG(ERROR, "Error when creating the http connection request server thread!");
}
}

37
event.c
View file

@ -23,6 +23,7 @@
#include "upload.h"
#include "sched_inform.h"
#include "ubus.h"
#include "cwmp_event.h"
pthread_mutex_t add_event_mutext = PTHREAD_MUTEX_INITIALIZER;
@ -62,42 +63,6 @@ void cwmp_save_event_container(struct event_container *event_container) //to be
}
}
struct event_container *__cwmp_add_event_container(int event_code, char *command_key)
{
static int id;
struct event_container *event_container;
list_for_each_entry(event_container, &cwmp_main->session->events, list) {
if (event_container->code == event_code && EVENT_CONST[event_code].TYPE == EVENT_TYPE_SINGLE) {
return event_container;
}
if (event_container->code > event_code) {
break;
}
}
event_container = calloc(1, sizeof(struct event_container));
if (event_container == NULL) {
return NULL;
}
INIT_LIST_HEAD(&(event_container->head_dm_parameter));
list_add_tail(&(event_container->list), &(cwmp_main->session->events));
event_container->code = event_code;
event_container->command_key = command_key ? strdup(command_key) : strdup("");
if ((id < 0) || (id >= MAX_INT_ID)) {
id = 0;
}
id++;
event_container->id = id;
return event_container;
}
struct event_container *cwmp_add_event_container(int event_code, char *command_key)
{
pthread_mutex_lock(&add_event_mutext);
struct event_container *event = __cwmp_add_event_container(event_code, command_key);
pthread_mutex_unlock(&add_event_mutext);
return event;
}
void cwmp_root_cause_event_diagnostic(void)
{
struct event_container *event_container;

30
http.c
View file

@ -36,13 +36,10 @@
static struct http_client http_c;
pthread_t http_cr_server_thread;
static CURL *curl = NULL;
char *fc_cookies = "/tmp/icwmp_cookies";
struct uloop_fd http_event6;
void http_set_timeout(void)
{
if (curl)
@ -466,30 +463,3 @@ void http_server_listen(void)
return;
}
}
void http_server_listen_uloop(struct uloop_fd *ufd __attribute__((unused)), unsigned events __attribute__((unused)))
{
http_server_listen();
}
void http_server_start_uloop(void)
{
http_server_init();
http_event6.fd = cwmp_main->cr_socket_desc;
http_event6.cb = http_server_listen_uloop;
uloop_fd_add(&http_event6, ULOOP_READ | ULOOP_EDGE_TRIGGER);
}
static void *thread_http_cr_server_listen(void *v __attribute__((unused)))
{
http_server_listen();
return NULL;
}
void http_server_start(void)
{
int error = pthread_create(&http_cr_server_thread, NULL, &thread_http_cr_server_listen, NULL);
if (error < 0) {
CWMP_LOG(ERROR, "Error when creating the http connection request server thread!");
}
}

View file

@ -20,7 +20,6 @@ extern pthread_mutex_t mutex_config_load;
int global_conf_init();
int get_global_config();
int cwmp_get_deviceid();
int cwmp_config_reload();
#endif

6
inc/cwmp_config.h Normal file
View file

@ -0,0 +1,6 @@
#ifndef CWMP_CONF_H
#define CWMP_CONF_H
int cwmp_get_deviceid();
#endif

5
inc/cwmp_event.h Normal file
View file

@ -0,0 +1,5 @@
#ifndef CWMP_EVENT_H
#define CWMP_EVENT_H
#include "event.h"
struct event_container *cwmp_add_event_container(int event_code, char *command_key);
#endif

7
inc/cwmp_http.h Normal file
View file

@ -0,0 +1,7 @@
#ifndef CWMP_HTTP_H
#define CWMP_HTTP_H
#include "http.h"
extern pthread_t http_cr_server_thread;
void http_server_start(void);
#endif

View file

@ -68,7 +68,6 @@ enum event_idx_enum
extern const struct EVENT_CONST_STRUCT EVENT_CONST[__EVENT_IDX_MAX];
extern pthread_mutex_t add_event_mutext;
struct event_container *cwmp_add_event_container(int event_idx, char *command_key);
int event_remove_all_event_container(int rem_from);
int event_remove_noretry_event_container();
void cwmp_save_event_container(struct event_container *event_container);

View file

@ -13,8 +13,6 @@
#include "common.h"
extern char *fc_cookies;
extern pthread_t http_cr_server_thread;
#define HTTP_TIMEOUT 30
struct http_client {
@ -29,7 +27,7 @@ void http_client_exit(void);
int http_send_message(char *msg_out, int msg_out_len, char **msg_in);
int http_cr_server_init(void);
void http_server_start(void);
void http_success_cr(void);
void http_server_init(void);
void http_server_listen(void);
#endif

View file

@ -20,6 +20,7 @@
#include "ubus.h"
#include "cwmp_uci.h"
#include "log.h"
#include "cwmp_event.h"
LIST_HEAD(list_value_change);
LIST_HEAD(list_lw_value_change);

View file

@ -5,7 +5,6 @@
* (at your option) any later version.
*
* Copyright (C) 2021 iopsys Software Solutions AB
* Author Amin Ben Ramdhane <amin.benramdhane@pivasoftware.com>
* Author Omar Kallel <omar.kallel@pivasoftware.com>
*
*/

View file

@ -13,6 +13,7 @@
#include "log.h"
#include "backupSession.h"
#include "event.h"
#include "cwmp_event.h"
LIST_HEAD(list_schedule_inform);
pthread_mutex_t mutex_schedule_inform = PTHREAD_MUTEX_INITIALIZER;

View file

@ -22,6 +22,7 @@
#include "ubus.h"
#include "download.h"
#include "upload.h"
#include "cwmp_event.h"
pthread_mutex_t start_session_mutext = PTHREAD_MUTEX_INITIALIZER;
static void cwmp_priodic_session_timer(struct uloop_timeout *timeout);

1
soap.c
View file

@ -31,6 +31,7 @@
#include "download.h"
#include "upload.h"
#include "sched_inform.h"
#include "cwmp_event.h"
#define DM_CONN_REQ_URL "Device.ManagementServer.ConnectionRequestURL"

View file

@ -1,3 +1,14 @@
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* Copyright (C) 2013-2021 iopsys Software Solutions AB
* Author Omar Kallel <omar.kallel@pivasoftware.com>
*
*/
#include <libubox/blobmsg_json.h>
#include <stdbool.h>

View file

@ -12,7 +12,7 @@ VALGRIND = valgrind --leak-check=full --show-reachable=yes --show-leak-kinds=all
libobj:
$(CC) $(LIBCFLAGS) ../../subprocess.c ../../download.c ../../upload.c ../../log.c ../../md5.c ../../digestauth.c ../../netlink.c ../../cwmp_cli.c ../../cwmp_du_state.c ../../sched_inform.c \
../../diagnostic.c ../../reboot.c ../../notifications.c ../../cwmp_zlib.c ../../datamodel_interface.c ../../http.c ../../backupSession.c \
../../cwmp_time.c ../../config.c ../../event.c ../../session.c ../../ubus.c ../../common.c ../../xml.c ../../soap.c ../../cwmp_uci.c ../../cwmp.c $(LDFLAGS)
../../cwmp_time.c ../../config.c ../../event.c ../../session.c ../../ubus.c ../../common.c ../../xml.c ../../soap.c ../../cwmp_uci.c ../../cwmp.c ../../cwmp_config.c ../../cwmp_event.c ../../cwmp_http.c $(LDFLAGS)
libicwmp: $(LIBOBJ)
$(CC) -shared -Wl,-soname,libicwmp.so.1 -o libicwmp.so.1.0 *.o

View file

@ -22,6 +22,8 @@
#include <libicwmp/log.h>
#include <libicwmp/download.h>
#include <libicwmp/cwmp_uci.h>
#include <libicwmp/cwmp_config.h>
#include <libicwmp/cwmp_event.h>
#include "icwmp_soap_msg_unit_test.h"

1
ubus.c
View file

@ -25,6 +25,7 @@
#include "upload.h"
#include "http.h"
#include "soap.h"
#include "cwmp_event.h"
static struct ubus_context *ctx = NULL;