T#7705: Code re-organise and improvements

This reverts commit cbfff1b644.
This commit is contained in:
Omar Kallel 2022-07-14 11:21:18 +01:00
parent 4c6065812b
commit 291e11d67a
68 changed files with 4179 additions and 4155 deletions

1
.gitignore vendored
View file

@ -6,6 +6,7 @@
*.xml *.xml
*.so *.so
*.txt *.txt
*.orig
bin/* bin/*
!bin/Makefile.am !bin/Makefile.am
.prepared* .prepared*

View file

@ -5,32 +5,31 @@ CWMP_VERSION = 3.0.1
bin_PROGRAMS = icwmpd bin_PROGRAMS = icwmpd
icwmpd_SOURCES = \ icwmpd_SOURCES = \
./common.c \ ./src/common.c \
./log.c \ ./src/log.c \
./cwmp_uci.c \ ./src/cwmp_uci.c \
./config.c \ ./src/config.c \
./session.c \ ./src/session.c \
./backupSession.c \ ./src/backupSession.c \
./digauth.c \ ./src/digauth.c \
./event.c \ ./src/event.c \
./http.c \ ./src/http.c \
./netlink.c \ ./src/ubus_utils.c \
./ubus_utils.c \ ./src/datamodel_interface.c \
./datamodel_interface.c \ ./src/cwmp_cli.c \
./cwmp_cli.c \ ./src/notifications.c \
./notifications.c \ ./src/cwmp_zlib.c \
./cwmp_zlib.c \ ./src/cwmp_du_state.c \
./cwmp_du_state.c \ ./src/download.c \
./download.c \ ./src/upload.c \
./upload.c \ ./src/sched_inform.c \
./sched_inform.c \ ./src/xml.c \
./xml.c \ ./src/rpc.c \
./rpc_soap.c \ ./src/diagnostic.c \
./diagnostic.c \ ./src/reboot.c \
./reboot.c \ ./src/heartbeat.c \
./heartbeat.c \ ./src/cwmp.c \
./cwmp.c \ ./src/ssl_utils.c
./ssl_utils.c
icwmpd_CFLAGS = \ icwmpd_CFLAGS = \
$(AM_CFLAGS) \ $(AM_CFLAGS) \
@ -66,4 +65,4 @@ icwmpd_LDADD = \
icwmpd_CFLAGS+=-DCWMP_VERSION=\"$(CWMP_VERSION)\" icwmpd_CFLAGS+=-DCWMP_VERSION=\"$(CWMP_VERSION)\"
icwmpd_LDFLAGS+=-DCWMP_VERSION=\"$(CWMP_VERSION)\" icwmpd_LDFLAGS+=-DCWMP_VERSION=\"$(CWMP_VERSION)\"
icwmpd_CFLAGS+=-I./inc icwmpd_CFLAGS+=-I..

View file

@ -1,6 +1,6 @@
AC_INIT([icwmp], [1.0], [dev@iopsys.eu]) AC_INIT([icwmp], [1.0], [dev@iopsys.eu])
AM_INIT_AUTOMAKE AM_INIT_AUTOMAKE
AC_CONFIG_SRCDIR([cwmp.c]) AC_CONFIG_SRCDIR([src/cwmp.c])
AM_INIT_AUTOMAKE([-Wall -Werror foreign subdir-objects]) AM_INIT_AUTOMAKE([-Wall -Werror foreign subdir-objects])

View file

@ -8,6 +8,21 @@ pwd
trap cleanup EXIT trap cleanup EXIT
trap cleanup SIGINT trap cleanup SIGINT
function check_valgrind_xml() {
echo "Checking memory leaks..."
grep -q "<kind>UninitCondition</kind>" memory-report.xml
error_on_zero $?
grep -q "<kind>Leak_PossiblyLost</kind>" memory-report.xml
error_on_zero $?
grep -q "<kind>Leak_DefinitelyLost</kind>" memory-report.xml
error_on_zero $?
grep -q "<kind>Leak_StillReachable</kind>" memory-report.xml
error_on_zero $?
}
date +%s > timestamp.log date +%s > timestamp.log
echo "Compiling icmwp" echo "Compiling icmwp"
build_icwmp build_icwmp
@ -59,6 +74,11 @@ done
echo "Stop all services" echo "Stop all services"
supervisorctl stop icwmpd supervisorctl stop icwmpd
check_valgrind_xml
cp test/files/etc/config/users /etc/config/
cp test/files/etc/config/wireless /etc/config/
echo "Verify Custom notifications" echo "Verify Custom notifications"
echo "#### Start custom_notifications ####" >> "$icwmp_master_log" echo "#### Start custom_notifications ####" >> "$icwmp_master_log"
if ./test/script/verify_custom_notifications.sh; then if ./test/script/verify_custom_notifications.sh; then

View file

@ -38,6 +38,7 @@ function exec_cmd()
function configure_genieacs() function configure_genieacs()
{ {
start_acs
sleep 10 sleep 10
echo "create a new user" echo "create a new user"
curl -X POST 'http://localhost:3000/init' -H "Content-Type: application/json" --data '{"users": true, "presets": true, "filters": true, "device": true, "index": true, "overview": true}' >/dev/null 2>&1 curl -X POST 'http://localhost:3000/init' -H "Content-Type: application/json" --data '{"users": true, "presets": true, "filters": true, "device": true, "index": true, "overview": true}' >/dev/null 2>&1

View file

@ -1,17 +0,0 @@
/*
* 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-2020 iopsys Software Solutions AB
* Author Omar Kallel <omar.kallel@pivasoftware.com>
*
*/
#ifndef __ZLIB_H
#define __ZLIB_H
int zlib_compress(char *message, unsigned char **zmsg, int *zlen, int type);
#endif

View file

@ -1,25 +0,0 @@
/*
* 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) 2019 iopsys Software Solutions AB
* Author: Imen Bhiri <imen.bhiri@pivasoftware.com>
* Author: Amin Ben Ramdhane <amin.benramdhane@pivasoftware.com>
*/
#ifndef __DIAGNOSTIC__H
#define __DIAGNOSTIC__H
bool set_diagnostic_parameter_structure_value(char *parameter_name, char *value);
int cwmp_download_diagnostics();
int cwmp_upload_diagnostics();
int cwmp_ip_ping_diagnostics();
int cwmp_nslookup_diagnostics();
int cwmp_traceroute_diagnostics();
int cwmp_udp_echo_diagnostics();
int cwmp_serverselection_diagnostics();
#endif

View file

@ -1,34 +0,0 @@
/*
* 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) 2011 Luka Perkov <freecwmp@lukaperkov.net>
*/
#ifndef _FREECWMP_HTTP_H__
#define _FREECWMP_HTTP_H__
#include "common.h"
extern char *fc_cookies;
#define HTTP_TIMEOUT 60
struct http_client {
struct curl_slist *header_list;
char *url;
};
void http_set_timeout(void);
int http_client_init(struct cwmp *cwmp);
void http_client_exit(void);
int http_send_message(struct cwmp *cwmp, char *msg_out, int msg_out_len, char **msg_in);
void http_server_init(void);
void http_server_listen(void);
void http_success_cr(void);
#endif

View file

@ -1,19 +0,0 @@
/*
* 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-2019 iopsys Software Solutions AB
* Author Mohamed Kallel <mohamed.kallel@pivasoftware.com>
* Author Anis Ellouze <anis.ellouze@pivasoftware.com>
*
*/
#ifndef _NETLINK_H__
#define _NETLINK_H__
int netlink_init(void);
int netlink_init_v6(void);
#endif

View file

@ -1,19 +0,0 @@
/*
* 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) 2021 iopsys Software Solutions AB
* Author Amin Ben Ramdhane <amin.benramdhane@pivasoftware.com>
*/
#ifndef _REBOOT_H__
#define _REBOOT_H__
#include "common.h"
void launch_reboot_methods(struct cwmp *cwmp);
#endif //_REBOOT_H__

View file

@ -1,34 +0,0 @@
#ifndef __XML__H_
#define __XML__H_
#include <xml_utils.h>
#include "session.h"
#include "common.h"
#define CWMP_MXML_TAB_SPACE " "
#define MAX_SCHEDULE_INFORM_QUEUE 10
#define MXML_DELETE(X) \
do { \
if (X) { \
mxmlDelete(X); \
X = NULL; \
} \
} while (0)
extern const char *cwmp_urls[];
int xml_prepare_msg_out(struct session *session);
int xml_prepare_lwnotification_message(char **msg_out);
int xml_set_cwmp_id_rpc_cpe(struct session *session);
int xml_recreate_namespace(mxml_node_t *tree);
const char *whitespace_cb(mxml_node_t *node, int where);
int xml_set_cwmp_id(struct session *session);
int xml_send_message(struct cwmp *cwmp, struct session *session, struct rpc *rpc);
mxml_node_t *mxmlFindElementOpaque(mxml_node_t *node, mxml_node_t *top, const char *text, int descend);
char *xml__get_attribute_name_by_value(mxml_node_t *node, const char *value);
char *xml_get_cwmp_version(int version);
void xml_exit(void);
void load_response_xml_schema(mxml_node_t **schema);
void load_notification_xml_schema(mxml_node_t **tree);
#endif

282
netlink.c
View file

@ -1,282 +0,0 @@
/*
* 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 Mohamed Kallel <mohamed.kallel@pivasoftware.com>
* Author Ahmed Zribi <ahmed.zribi@pivasoftware.com>
* Copyright (C) 2011-2012 Luka Perkov <freecwmp@lukaperkov.net>
*
*/
#include <netinet/in.h>
#include <net/if.h>
#include <arpa/inet.h>
#include <linux/rtnetlink.h>
#include <linux/netlink.h>
#include <stddef.h>
#include <libubox/uloop.h>
#include <string.h>
#include <stdlib.h>
#include "netlink.h"
#include "cwmp_uci.h"
#include "log.h"
#include "event.h"
static int itfcmp(char *itf1, char *itf2);
static void netlink_new_msg(struct uloop_fd *ufd, unsigned events);
static struct uloop_fd netlink_event = {.cb = netlink_new_msg };
static struct uloop_fd netlink_event_v6 = {.cb = netlink_new_msg };
static int itfcmp(char *itf1, char *itf2)
{
int index = 0;
int status = 1;
char *str = NULL;
char *buf1 = NULL;
char *buf2 = NULL;
if (itf1 == NULL || itf2 == NULL)
return status;
if (itf1[0] == '\0')
goto end;
str = strchr(itf1, '.');
if (str == NULL)
goto end;
index = (int)(str - itf1);
if (!index)
goto end;
buf1 = malloc(index);
if (!buf1)
goto end;
strncpy(buf1, itf1, index);
buf1[index] = '\0';
if (itf2[0] == '\0')
goto end;
str = strchr(itf2, '.');
if (str == NULL)
goto end;
index = (int)(str - itf2);
if (!index)
goto end;
buf2 = malloc(index);
if (!buf2)
goto end;
strncpy(buf2, itf1, index);
buf2[index] = '\0';
if (strcmp(buf1, buf2) == 0)
status = 0;
end:
if (buf1)
free(buf1);
if (buf2)
free(buf2);
return status;
}
static void freecwmp_netlink_interface(struct nlmsghdr *nlh)
{
struct ifaddrmsg *ifa = (struct ifaddrmsg *)NLMSG_DATA(nlh);
struct rtattr *rth = IFA_RTA(ifa);
int rtl = IFA_PAYLOAD(nlh);
char if_name[IFNAMSIZ], if_addr[INET_ADDRSTRLEN];
memset(&if_name, 0, sizeof(if_name));
memset(&if_addr, 0, sizeof(if_addr));
if (ifa->ifa_family == AF_INET) { //CASE IPv4
while (rtl && RTA_OK(rth, rtl)) {
if (rth->rta_type != IFA_LOCAL) {
rth = RTA_NEXT(rth, rtl);
continue;
}
uint32_t addr = htonl(*(uint32_t *)RTA_DATA(rth));
if (htonl(13) == 13) {
// running on big endian system
} else {
// running on little endian system
addr = __builtin_bswap32(addr);
}
if_indextoname(ifa->ifa_index, if_name);
if (itfcmp(cwmp_main.conf.interface, if_name)) {
rth = RTA_NEXT(rth, rtl);
continue;
}
inet_ntop(AF_INET, &(addr), if_addr, INET_ADDRSTRLEN);
FREE(cwmp_main.conf.ip);
cwmp_main.conf.ip = strdup(if_addr);
cwmp_uci_set_varstate_value("cwmp", "cpe", "ip", cwmp_main.conf.ip);
cwmp_commit_package("cwmp", UCI_VARSTATE_CONFIG);
connection_request_ip_value_change(&cwmp_main, IPv4);
break;
}
} else { //CASE IPv6
while (rtl && RTA_OK(rth, rtl)) {
char pradd_v6[128];
if (rth->rta_type != IFA_ADDRESS || ifa->ifa_scope == RT_SCOPE_LINK) {
rth = RTA_NEXT(rth, rtl);
continue;
}
inet_ntop(AF_INET6, RTA_DATA(rth), pradd_v6, sizeof(pradd_v6));
if_indextoname(ifa->ifa_index, if_name);
if (strncmp(cwmp_main.conf.interface, if_name, IFNAMSIZ)) {
rth = RTA_NEXT(rth, rtl);
continue;
}
FREE(cwmp_main.conf.ipv6);
cwmp_main.conf.ipv6 = strdup(pradd_v6);
cwmp_uci_set_varstate_value("cwmp", "cpe", "ipv6", cwmp_main.conf.ip);
cwmp_commit_package("cwmp", UCI_VARSTATE_CONFIG);
connection_request_ip_value_change(&cwmp_main, IPv6);
break;
}
}
}
static void netlink_new_msg(struct uloop_fd *ufd, unsigned events __attribute__((unused)))
{
struct nlmsghdr *nlh;
char buffer[BUFSIZ];
size_t msg_size;
memset(&buffer, 0, sizeof(buffer));
nlh = (struct nlmsghdr *)buffer;
if ((int)(msg_size = recv(ufd->fd, nlh, BUFSIZ, 0)) == -1) {
CWMP_LOG(ERROR, "error receiving netlink message");
return;
}
while ((size_t)msg_size > sizeof(*nlh)) {
int len = nlh->nlmsg_len;
int req_len = len - sizeof(*nlh);
if (req_len < 0 || (size_t)len > msg_size) {
CWMP_LOG(ERROR, "error reading netlink message");
return;
}
if (!NLMSG_OK(nlh, msg_size)) {
CWMP_LOG(ERROR, "netlink message is not NLMSG_OK");
return;
}
if (nlh->nlmsg_type == RTM_NEWADDR)
freecwmp_netlink_interface(nlh);
msg_size -= NLMSG_ALIGN(len);
nlh = (struct nlmsghdr *)((char *)nlh + NLMSG_ALIGN(len));
}
}
int netlink_init_v6(void)
{
struct {
struct nlmsghdr hdr;
struct ifaddrmsg msg;
} req;
struct sockaddr_nl addr;
int sock[2];
memset(&addr, 0, sizeof(addr));
memset(&req, 0, sizeof(req));
if ((sock[0] = socket(PF_NETLINK, SOCK_RAW, NETLINK_ROUTE)) == -1) {
CWMP_LOG(ERROR, "couldn't open NETLINK_ROUTE socket");
return -1;
}
addr.nl_family = AF_NETLINK;
addr.nl_groups = RTMGRP_IPV6_IFADDR;
if ((bind(sock[0], (struct sockaddr *)&addr, sizeof(addr))) == -1) {
CWMP_LOG(ERROR, "couldn't bind netlink socket");
return -1;
}
netlink_event_v6.fd = sock[0];
uloop_fd_add(&netlink_event_v6, ULOOP_READ | ULOOP_EDGE_TRIGGER);
if ((sock[1] = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE)) == -1) {
CWMP_LOG(ERROR, "couldn't open NETLINK_ROUTE socket");
return -1;
}
req.hdr.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg));
req.hdr.nlmsg_flags = NLM_F_REQUEST | NLM_F_ROOT;
req.hdr.nlmsg_type = RTM_GETADDR;
req.msg.ifa_family = AF_INET6;
if ((send(sock[1], &req, req.hdr.nlmsg_len, 0)) == -1) {
CWMP_LOG(ERROR, "couldn't send netlink socket");
return -1;
}
struct uloop_fd dummy_event = {.fd = sock[1] };
netlink_new_msg(&dummy_event, 0);
return 0;
}
int netlink_init(void)
{
struct {
struct nlmsghdr hdr;
struct ifaddrmsg msg;
} req;
struct sockaddr_nl addr;
int sock[2];
memset(&addr, 0, sizeof(addr));
memset(&req, 0, sizeof(req));
if ((sock[0] = socket(PF_NETLINK, SOCK_RAW, NETLINK_ROUTE)) == -1) {
CWMP_LOG(ERROR, "couldn't open NETLINK_ROUTE socket");
return -1;
}
addr.nl_family = AF_NETLINK;
addr.nl_groups = RTMGRP_IPV4_IFADDR;
if ((bind(sock[0], (struct sockaddr *)&addr, sizeof(addr))) == -1) {
CWMP_LOG(ERROR, "couldn't bind netlink socket");
return -1;
}
netlink_event.fd = sock[0];
uloop_fd_add(&netlink_event, ULOOP_READ | ULOOP_EDGE_TRIGGER);
if ((sock[1] = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE)) == -1) {
CWMP_LOG(ERROR, "couldn't open NETLINK_ROUTE socket");
return -1;
}
req.hdr.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg));
req.hdr.nlmsg_flags = NLM_F_REQUEST | NLM_F_ROOT;
req.hdr.nlmsg_type = RTM_GETADDR;
req.msg.ifa_family = AF_INET;
if ((send(sock[1], &req, req.hdr.nlmsg_len, 0)) == -1) {
CWMP_LOG(ERROR, "couldn't send netlink socket");
return -1;
}
struct uloop_fd dummy_event = {.fd = sock[1] };
netlink_new_msg(&dummy_event, 0);
return 0;
}

2852
rpc_soap.c

File diff suppressed because it is too large Load diff

View file

@ -1,13 +1,14 @@
/* /*
* This program is free software: you can redistribute it and/or modify * backupSession.c - API to store/load CWMP session in/from backup XML files
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 2 of the License, or * Copyright (C) 2021-2022, IOPSYS Software Solutions AB.
* (at your option) any later version.
* *
* Copyright (C) 2013-2021 iopsys Software Solutions AB
* Author Mohamed Kallel <mohamed.kallel@pivasoftware.com> * Author Mohamed Kallel <mohamed.kallel@pivasoftware.com>
* Author Ahmed Zribi <ahmed.zribi@pivasoftware.com> * Author Ahmed Zribi <ahmed.zribi@pivasoftware.com>
* Author Omar Kallel <omar.kallel@pivasoftware.com> * Author Omar Kallel <omar.kallel@pivasoftware.com>
*
* See LICENSE file for license related information.
*
*/ */
#include <unistd.h> #include <unistd.h>
@ -521,7 +522,7 @@ void bkp_session_delete_apply_schedule_download(struct apply_schedule_download *
void bkp_session_insert_change_du_state(struct change_du_state *pchange_du_state) void bkp_session_insert_change_du_state(struct change_du_state *pchange_du_state)
{ {
struct operations *p; struct operations *p = NULL;
char schedule_time[128]; char schedule_time[128];
mxml_node_t *b, *n; mxml_node_t *b, *n;
@ -662,7 +663,7 @@ void bkp_session_delete_upload(struct upload *pupload)
void bkp_session_insert_du_state_change_complete(struct du_state_change_complete *pdu_state_change_complete) void bkp_session_insert_du_state_change_complete(struct du_state_change_complete *pdu_state_change_complete)
{ {
char schedule_time[128], resolved[8], fault_code[8]; char schedule_time[128], resolved[8], fault_code[8];
struct opresult *p; struct opresult *p = NULL;
mxml_node_t *b; mxml_node_t *b;
pthread_mutex_lock(&mutex_backup_session); pthread_mutex_lock(&mutex_backup_session);
@ -802,6 +803,10 @@ void load_queue_event(mxml_node_t *tree, struct cwmp *cwmp)
const char *element = mxmlGetElement(b); const char *element = mxmlGetElement(b);
if (strcmp(element, "command_key") == 0) { if (strcmp(element, "command_key") == 0) {
// cppcheck-suppress knownConditionTrueFalse
/*
* idx value can be modified when loading the backup with the function load_specific_backup_attributes
*/
if (idx != -1) { if (idx != -1) {
if (EVENT_CONST[idx].RETRY & EVENT_RETRY_AFTER_REBOOT) { if (EVENT_CONST[idx].RETRY & EVENT_RETRY_AFTER_REBOOT) {
event_container_save = cwmp_add_event_container(cwmp, idx, ((command_key != NULL) ? command_key : "")); event_container_save = cwmp_add_event_container(cwmp, idx, ((command_key != NULL) ? command_key : ""));

View file

@ -1,19 +1,20 @@
/* /*
* This program is free software: you can redistribute it and/or modify * backupSession.h - API to store/load CWMP session in/from backup XML files
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 2 of the License, or * Copyright (C) 2021-2022, IOPSYS Software Solutions AB.
* (at your option) any later version.
* *
* Copyright (C) 2013-2020 iopsys Software Solutions AB
* Author Mohamed Kallel <mohamed.kallel@pivasoftware.com> * Author Mohamed Kallel <mohamed.kallel@pivasoftware.com>
* Author Ahmed Zribi <ahmed.zribi@pivasoftware.com> * Author Ahmed Zribi <ahmed.zribi@pivasoftware.com>
* Author Omar Kallel <omar.kallel@pivasoftware.com>
*
* See LICENSE file for license related information.
* *
*/ */
#ifndef _BACKUPSESSION_H__ #ifndef _BACKUPSESSION_H__
#define _BACKUPSESSION_H__ #define _BACKUPSESSION_H__
#include <xml_utils.h> #include "xml_utils.h"
#include "common.h" #include "common.h"
#define RPC_NO_STATUS -1 #define RPC_NO_STATUS -1

View file

@ -1,12 +1,12 @@
/* /*
* This program is free software: you can redistribute it and/or modify * common.c - Some commun functions used by the application
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 2 of the License, or * Copyright (C) 2021-2022, IOPSYS Software Solutions AB.
* (at your option) any later version.
* *
* Copyright (C) 2013-2021 iopsys Software Solutions AB
* Author Omar Kallel <omar.kallel@pivasoftware.com> * Author Omar Kallel <omar.kallel@pivasoftware.com>
* *
* See LICENSE file for license related information.
*
*/ */
#include <fcntl.h> #include <fcntl.h>
@ -165,6 +165,7 @@ void add_dm_parameter_to_list(struct list_head *head, char *param_name, char *pa
dm_parameter->value = strdup(param_val); dm_parameter->value = strdup(param_val);
dm_parameter->type = strdup(param_type ? param_type : "xsd:string"); dm_parameter->type = strdup(param_type ? param_type : "xsd:string");
dm_parameter->access_list = strdup("");
dm_parameter->notification = notification; dm_parameter->notification = notification;
dm_parameter->writable = writable; dm_parameter->writable = writable;
} }
@ -175,6 +176,7 @@ void delete_dm_parameter_from_list(struct cwmp_dm_parameter *dm_parameter)
free(dm_parameter->name); free(dm_parameter->name);
free(dm_parameter->value); free(dm_parameter->value);
free(dm_parameter->type); free(dm_parameter->type);
free(dm_parameter->access_list);
free(dm_parameter); free(dm_parameter);
} }

View file

@ -1,13 +1,14 @@
/* /*
* This program is free software: you can redistribute it and/or modify * common.h - Some commun functions used by the application
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 2 of the License, or * Copyright (C) 2021-2022, IOPSYS Software Solutions AB.
* (at your option) any later version.
* *
* Copyright (C) 2013-2020 iopsys Software Solutions AB
* Author Omar Kallel <omar.kallel@pivasoftware.com> * Author Omar Kallel <omar.kallel@pivasoftware.com>
* *
* See LICENSE file for license related information.
*
*/ */
#ifndef __CCOMMON_H #ifndef __CCOMMON_H
#define __CCOMMON_H #define __CCOMMON_H
@ -216,6 +217,7 @@ struct cwmp_dm_parameter {
char *name; char *name;
char *value; char *value;
char *type; char *type;
char *access_list;
int notification; int notification;
bool writable; bool writable;
bool forced_notification_param; bool forced_notification_param;

View file

@ -1,14 +1,16 @@
/* /*
* This program is free software: you can redistribute it and/or modify * config.c - load/store icwmp application configuration
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 2 of the License, or * Copyright (C) 2021-2022, IOPSYS Software Solutions AB.
* (at your option) any later version.
* *
* Copyright (C) 2013-2021 iopsys Software Solutions AB
* Author Mohamed Kallel <mohamed.kallel@pivasoftware.com> * Author Mohamed Kallel <mohamed.kallel@pivasoftware.com>
* Author Ahmed Zribi <ahmed.zribi@pivasoftware.com> * Author Ahmed Zribi <ahmed.zribi@pivasoftware.com>
* Author Omar Kallel <omar.kallel@pivasoftware.com> * Author Omar Kallel <omar.kallel@pivasoftware.com>
*
* See LICENSE file for license related information.
*
*/ */
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>

View file

@ -1,13 +1,13 @@
/* /*
* This program is free software: you can redistribute it and/or modify * config.h - load/store icwmp application configuration
* 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-2019 iopsys Software Solutions AB * Copyright (C) 2021-2022, IOPSYS Software Solutions AB.
* Author Mohamed Kallel <mohamed.kallel@pivasoftware.com> *
* Author Omar Kallel <omar.kallel@pivasoftware.com>
* Author Anis Ellouze <anis.ellouze@pivasoftware.com> * Author Anis Ellouze <anis.ellouze@pivasoftware.com>
* *
* See LICENSE file for license related information.
*
*/ */
#ifndef _CONFIG_H__ #ifndef _CONFIG_H__

View file

@ -1,13 +1,14 @@
/* /*
* This program is free software: you can redistribute it and/or modify * cwmp.c - icwmp Main file
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 2 of the License, or * Copyright (C) 2021-2022, IOPSYS Software Solutions AB.
* (at your option) any later version.
* *
* Copyright (C) 2013-2021 iopsys Software Solutions AB
* Author Mohamed Kallel <mohamed.kallel@pivasoftware.com> * Author Mohamed Kallel <mohamed.kallel@pivasoftware.com>
* Author Ahmed Zribi <ahmed.zribi@pivasoftware.com> * Author Ahmed Zribi <ahmed.zribi@pivasoftware.com>
* Author Omar Kallel <omar.kallel@pivasoftware.com> * Author Omar Kallel <omar.kallel@pivasoftware.com>
*
* See LICENSE file for license related information.
*
*/ */
#include <math.h> #include <math.h>
@ -28,7 +29,7 @@
#include "session.h" #include "session.h"
#include "diagnostic.h" #include "diagnostic.h"
#include "http.h" #include "http.h"
#include "rpc_soap.h" #include "rpc.h"
#include "config.h" #include "config.h"
#include "backupSession.h" #include "backupSession.h"
#include "ubus_utils.h" #include "ubus_utils.h"
@ -39,7 +40,6 @@
#include "datamodel_interface.h" #include "datamodel_interface.h"
#include "cwmp_du_state.h" #include "cwmp_du_state.h"
#include "heartbeat.h" #include "heartbeat.h"
#include "netlink.h"
static pthread_t periodic_event_thread; static pthread_t periodic_event_thread;
static pthread_t scheduleInform_thread; static pthread_t scheduleInform_thread;
@ -230,7 +230,7 @@ int cwmp_schedule_rpc(struct cwmp *cwmp, struct session *session)
struct list_head *ilist; struct list_head *ilist;
struct rpc *rpc_acs, *rpc_cpe; struct rpc *rpc_acs, *rpc_cpe;
if (http_client_init(cwmp) || thread_end) { if (icwmp_http_client_init(cwmp) || thread_end) {
CWMP_LOG(INFO, "Initializing http client failed"); CWMP_LOG(INFO, "Initializing http client failed");
goto retry; goto retry;
} }
@ -327,7 +327,7 @@ retry:
end: end:
MXML_DELETE(session->tree_in); MXML_DELETE(session->tree_in);
MXML_DELETE(session->tree_out); MXML_DELETE(session->tree_out);
http_client_exit(); icwmp_http_client_exit();
xml_exit(); xml_exit();
return session->error; return session->error;
} }
@ -571,16 +571,6 @@ static void *thread_uloop_run(void *v __attribute__((unused)))
{ {
uloop_init(); uloop_init();
if (netlink_init()) {
CWMP_LOG(ERROR, "netlink initialization failed");
}
if (cwmp_main.conf.ipv6_enable) {
if (netlink_init_v6()) {
CWMP_LOG(ERROR, "netlink initialization failed");
}
}
ctx = ubus_connect(cwmp_main.conf.ubus_socket); ctx = ubus_connect(cwmp_main.conf.ubus_socket);
if (!ctx) if (!ctx)
return NULL; return NULL;
@ -603,7 +593,7 @@ static void *thread_uloop_run(void *v __attribute__((unused)))
static void *thread_http_cr_server_listen(void *v __attribute__((unused))) static void *thread_http_cr_server_listen(void *v __attribute__((unused)))
{ {
http_server_listen(); icwmp_http_server_listen();
return NULL; return NULL;
} }
@ -830,6 +820,7 @@ end:
static int cwmp_init(struct cwmp *cwmp) static int cwmp_init(struct cwmp *cwmp)
{ {
int error; int error;
icwmp_init_list_services(); icwmp_init_list_services();
cwmp->event_id = 0; cwmp->event_id = 0;
cwmp->cwmp_period = 0; cwmp->cwmp_period = 0;
@ -1011,7 +1002,7 @@ int main(int argc, char **argv)
return error; return error;
configure_var_state(&cwmp_main); configure_var_state(&cwmp_main);
http_server_init(); icwmp_http_server_init();
memset(&act, 0, sizeof(act)); memset(&act, 0, sizeof(act));
act.sa_handler = icwmp_signal_handler; act.sa_handler = icwmp_signal_handler;

View file

@ -1,11 +1,12 @@
/* /*
* This program is free software: you can redistribute it and/or modify * cwmp_cli.c - icwmp CLI
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 2 of the License, or * Copyright (C) 2021-2022, IOPSYS Software Solutions AB.
* (at your option) any later version.
* *
* Copyright (C) 2013-2021 iopsys Software Solutions AB
* Author Omar Kallel <omar.kallel@pivasoftware.com> * Author Omar Kallel <omar.kallel@pivasoftware.com>
*
* See LICENSE file for license related information.
*
*/ */
#include <string.h> #include <string.h>
@ -64,7 +65,7 @@ void display_get_cmd_result(struct cmd_input in __attribute__((unused)), union c
fprintf(stderr, "Fault %s: %s\n", fault, get_fault_message_by_fault_code(fault)); fprintf(stderr, "Fault %s: %s\n", fault, get_fault_message_by_fault_code(fault));
return; return;
} }
struct cwmp_dm_parameter *param_value; struct cwmp_dm_parameter *param_value = NULL;
list_for_each_entry (param_value, res.param_list, list) { list_for_each_entry (param_value, res.param_list, list) {
fprintf(stdout, "%s => %s\n", param_value->name, param_value->value); fprintf(stdout, "%s => %s\n", param_value->name, param_value->value);
} }
@ -89,7 +90,7 @@ char *cmd_set_exec_func(struct cmd_input in, union cmd_result *res __attribute__
int fault_idx = cwmp_set_multiple_parameters_values(&list_set_param_value, "set_key", &flag, &faults_list); int fault_idx = cwmp_set_multiple_parameters_values(&list_set_param_value, "set_key", &flag, &faults_list);
cwmp_free_all_dm_parameter_list(&list_set_param_value); cwmp_free_all_dm_parameter_list(&list_set_param_value);
if (fault_idx != FAULT_CPE_NO_FAULT) { if (fault_idx != FAULT_CPE_NO_FAULT) {
struct cwmp_param_fault *param_fault; struct cwmp_param_fault *param_fault = NULL;
char fault[5] = {0}; char fault[5] = {0};
list_for_each_entry (param_fault, &faults_list, list) { list_for_each_entry (param_fault, &faults_list, list) {
snprintf(fault, sizeof(fault), "%d", param_fault->fault); snprintf(fault, sizeof(fault), "%d", param_fault->fault);
@ -204,7 +205,7 @@ void display_get_notif_cmd_result(struct cmd_input in __attribute__((unused)), u
fprintf(stderr, "Fault %s: %s\n", fault, get_fault_message_by_fault_code(fault)); fprintf(stderr, "Fault %s: %s\n", fault, get_fault_message_by_fault_code(fault));
return; return;
} }
struct cwmp_dm_parameter *param_value; struct cwmp_dm_parameter *param_value = NULL;
list_for_each_entry (param_value, res.param_list, list) { list_for_each_entry (param_value, res.param_list, list) {
fprintf(stdout, "%s => %s\n", param_value->name, param_value->notification == 2 ? "active" : param_value->notification == 1 ? "passive" : "off"); fprintf(stdout, "%s => %s\n", param_value->name, param_value->notification == 2 ? "active" : param_value->notification == 1 ? "passive" : "off");
} }
@ -266,7 +267,7 @@ void display_get_names_cmd_result(struct cmd_input in __attribute__((unused)), u
fprintf(stderr, "Fault %s: %s\n", fault, get_fault_message_by_fault_code(fault)); fprintf(stderr, "Fault %s: %s\n", fault, get_fault_message_by_fault_code(fault));
return; return;
} }
struct cwmp_dm_parameter *param_value; struct cwmp_dm_parameter *param_value = NULL;
list_for_each_entry (param_value, res.param_list, list) { list_for_each_entry (param_value, res.param_list, list) {
fprintf(stdout, "%s => %s\n", param_value->name, param_value->writable ? "writable" : "not-writable"); fprintf(stdout, "%s => %s\n", param_value->name, param_value->writable ? "writable" : "not-writable");
} }

View file

@ -1,3 +1,14 @@
/*
* cwmp_cli.h - icwmp CLI
*
* Copyright (C) 2021-2022, IOPSYS Software Solutions AB.
*
* Author Omar Kallel <omar.kallel@pivasoftware.com>
*
* See LICENSE file for license related information.
*
*/
#ifndef CWMP_CLI #ifndef CWMP_CLI
#define CWMP_CLI #define CWMP_CLI

View file

@ -1,11 +1,12 @@
/* /*
* This program is free software: you can redistribute it and/or modify * cwmp-du_state.c - ChangeDUState method corresponding functions
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 2 of the License, or * Copyright (C) 2021-2022, IOPSYS Software Solutions AB.
* (at your option) any later version.
* *
* Copyright (C) 2013-2021 iopsys Software Solutions AB
* Author Omar Kallel <omar.kallel@pivasoftware.com> * Author Omar Kallel <omar.kallel@pivasoftware.com>
*
* See LICENSE file for license related information.
*
*/ */
#include <libubox/blobmsg_json.h> #include <libubox/blobmsg_json.h>
@ -156,7 +157,7 @@ static int get_deployment_unit_name_version(char *uuid, char **name, char **vers
snprintf(name_param, sizeof(name_param), "Device.SoftwareModules.DeploymentUnit.%s.Name", sw_by_uuid_instance); snprintf(name_param, sizeof(name_param), "Device.SoftwareModules.DeploymentUnit.%s.Name", sw_by_uuid_instance);
snprintf(version_param, sizeof(version_param), "Device.SoftwareModules.DeploymentUnit.%s.Version", sw_by_uuid_instance); snprintf(version_param, sizeof(version_param), "Device.SoftwareModules.DeploymentUnit.%s.Version", sw_by_uuid_instance);
snprintf(environment_param, sizeof(environment_param), "Device.SoftwareModules.DeploymentUnit.%s.ExecutionEnvRef", sw_by_uuid_instance); snprintf(environment_param, sizeof(environment_param), "Device.SoftwareModules.DeploymentUnit.%s.ExecutionEnvRef", sw_by_uuid_instance);
struct cwmp_dm_parameter *param_value; struct cwmp_dm_parameter *param_value = NULL;
list_for_each_entry (param_value, &sw_parameters, list) { list_for_each_entry (param_value, &sw_parameters, list) {
if (strcmp(param_value->name, name_param) == 0) { if (strcmp(param_value->name, name_param) == 0) {
*name = strdup(param_value->value); *name = strdup(param_value->value);
@ -218,7 +219,7 @@ static char *get_exec_env_name(char *environment_path)
if (err) if (err)
return strdup(""); return strdup("");
struct cwmp_dm_parameter *param_value; struct cwmp_dm_parameter *param_value = NULL;
snprintf(env_param, sizeof(env_param), "%sName", environment_path); snprintf(env_param, sizeof(env_param), "%sName", environment_path);
list_for_each_entry (param_value, &environment_list, list) { list_for_each_entry (param_value, &environment_list, list) {
if (strcmp(param_value->name, env_param) == 0) { if (strcmp(param_value->name, env_param) == 0) {

View file

@ -1,11 +1,12 @@
/* /*
* This program is free software: you can redistribute it and/or modify * cwmp-du_state.h - ChangeDUState method corresponding functions
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 2 of the License, or * Copyright (C) 2021-2022, IOPSYS Software Solutions AB.
* (at your option) any later version.
* *
* Copyright (C) 2013-2021 iopsys Software Solutions AB
* Author Omar Kallel <omar.kallel@pivasoftware.com> * Author Omar Kallel <omar.kallel@pivasoftware.com>
*
* See LICENSE file for license related information.
*
*/ */
#ifndef CWMP_DU_STATE_H #ifndef CWMP_DU_STATE_H

View file

@ -1,12 +1,14 @@
/* /*
* This program is free software: you can redistribute it and/or modify * cwmp_uci.c - API to manage UCI packages/sections/options
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 2 of the License, or * Copyright (C) 2021-2022, IOPSYS Software Solutions AB.
* (at your option) any later version.
* *
* Copyright (C) 2013-2021 iopsys Software Solutions AB
* Author Omar Kallel <omar.kallel@pivasoftware.com> * Author Omar Kallel <omar.kallel@pivasoftware.com>
*
* See LICENSE file for license related information.
*
*/ */
#include <ctype.h> #include <ctype.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>

View file

@ -1,14 +1,15 @@
/* /*
* This program is free software: you can redistribute it and/or modify * cwmp_uci.h - API to manage UCI packages/sections/options
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 2 of the License, or * Copyright (C) 2021-2022, IOPSYS Software Solutions AB.
* (at your option) any later version.
* *
* Copyright (C) 2013-2020 iopsys Software Solutions AB
* Author Omar Kallel <omar.kallel@pivasoftware.com> * Author Omar Kallel <omar.kallel@pivasoftware.com>
* *
* See LICENSE file for license related information.
*
*/ */
#ifndef __CWMPUCI_H #ifndef __CWMPUCI_H
#define __CWMPUCI_H #define __CWMPUCI_H

View file

@ -1,11 +1,12 @@
/* /*
* This program is free software: you can redistribute it and/or modify * cwmp_zlib.c - ZLIB compresssion of CWMP messages
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 2 of the License, or * Copyright (C) 2021-2022, IOPSYS Software Solutions AB.
* (at your option) any later version.
* *
* Copyright (C) 2014-2021 iopsys Software Solutions AB
* Author Mohamed Kallel <mohamed.kallel@pivasoftware.com> * Author Mohamed Kallel <mohamed.kallel@pivasoftware.com>
*
* See LICENSE file for license related information.
*
*/ */
#include <zlib.h> #include <zlib.h>

17
src/cwmp_zlib.h Normal file
View file

@ -0,0 +1,17 @@
/*
* cwmp_zlib.h - ZLIB compresssion of CWMP messages
*
* Copyright (C) 2021-2022, IOPSYS Software Solutions AB.
*
* Author Mohamed Kallel <mohamed.kallel@pivasoftware.com>
*
* See LICENSE file for license related information.
*
*/
#ifndef __ZLIB_H
#define __ZLIB_H
int zlib_compress(char *message, unsigned char **zmsg, int *zlen, int type);
#endif

View file

@ -1,11 +1,12 @@
/* /*
* This program is free software: you can redistribute it and/or modify * datamodel_interface.c - API to call BBF datamodel functions (set, get, add, delete, setattributes, getattributes, getnames, ...)
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 2 of the License, or * Copyright (C) 2021-2022, IOPSYS Software Solutions AB.
* (at your option) any later version.
* *
* Copyright (C) 2013-2021 iopsys Software Solutions AB
* Author Omar Kallel <omar.kallel@pivasoftware.com> * Author Omar Kallel <omar.kallel@pivasoftware.com>
*
* See LICENSE file for license related information.
*
*/ */
#include <libubox/blobmsg_json.h> #include <libubox/blobmsg_json.h>
@ -440,7 +441,7 @@ char *cwmp_get_multiple_parameters_values(struct list_head *arg_params_list, str
{ {
int e; int e;
struct cwmp *cwmp = &cwmp_main; struct cwmp *cwmp = &cwmp_main;
struct cwmp_dm_parameter *param_value; struct cwmp_dm_parameter *param_value = NULL;
struct list_params_result get_result = { .parameters_list = parameters_list }; struct list_params_result get_result = { .parameters_list = parameters_list };
struct blob_buf b = { 0 }; struct blob_buf b = { 0 };
@ -536,7 +537,7 @@ void ubus_setm_values_callback(struct ubus_request *req, int type __attribute__(
int cwmp_set_multiple_parameters_values(struct list_head *parameters_values_list, char *parameter_key, int *flag, struct list_head *faults_list) int cwmp_set_multiple_parameters_values(struct list_head *parameters_values_list, char *parameter_key, int *flag, struct list_head *faults_list)
{ {
int e; int e;
struct cwmp_dm_parameter *param_value; struct cwmp_dm_parameter *param_value = NULL;
struct setm_values_res set_result = { .flag = flag, .faults_list = faults_list }; struct setm_values_res set_result = { .flag = flag, .faults_list = faults_list };
struct cwmp *cwmp = &cwmp_main; struct cwmp *cwmp = &cwmp_main;
struct blob_buf b = { 0 }; struct blob_buf b = { 0 };

View file

@ -1,3 +1,14 @@
/*
* datamodel_interface.h - API to call BBF datamodel functions (set, get, add, delete, setattributes, getattributes, getnames, ...)
*
* Copyright (C) 2021-2022, IOPSYS Software Solutions AB.
*
* Author Omar Kallel <omar.kallel@pivasoftware.com>
*
* See LICENSE file for license related information.
*
*/
#ifndef SRC_DATAMODELIFACE_H_ #ifndef SRC_DATAMODELIFACE_H_
#define SRC_DATAMODELIFACE_H_ #define SRC_DATAMODELIFACE_H_

View file

@ -1,14 +1,16 @@
/* /*
* This program is free software: you can redistribute it and/or modify * diagnostic.c - Manage Diagnostics parameters from icwmp
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 2 of the License, or * Copyright (C) 2021-2022, IOPSYS Software Solutions AB.
* (at your option) any later version.
* *
* Copyright (C) 2021 iopsys Software Solutions AB
* Author Imen Bhiri <imen.bhiri@pivasoftware.com> * Author Imen Bhiri <imen.bhiri@pivasoftware.com>
* Author: Amin Ben Ramdhane <amin.benramdhane@pivasoftware.com> * Author: Amin Ben Ramdhane <amin.benramdhane@pivasoftware.com>
* Author: Omar Kallel <omar.kallel@pivasoftware.com> * Author: Omar Kallel <omar.kallel@pivasoftware.com>
*
* See LICENSE file for license related information.
*
*/ */
#include <string.h> #include <string.h>
#include "common.h" #include "common.h"

27
src/diagnostic.h Normal file
View file

@ -0,0 +1,27 @@
/*
* diagnostic.h - Manage Diagnostics parameters from icwmp
*
* Copyright (C) 2021-2022, IOPSYS Software Solutions AB.
*
* Author Imen Bhiri <imen.bhiri@pivasoftware.com>
* Author: Amin Ben Ramdhane <amin.benramdhane@pivasoftware.com>
* Author: Omar Kallel <omar.kallel@pivasoftware.com>
*
* See LICENSE file for license related information.
*
*/
#ifndef __DIAGNOSTIC__H
#define __DIAGNOSTIC__H
bool set_diagnostic_parameter_structure_value(char *parameter_name, char *value);
int cwmp_download_diagnostics();
int cwmp_upload_diagnostics();
int cwmp_ip_ping_diagnostics();
int cwmp_nslookup_diagnostics();
int cwmp_traceroute_diagnostics();
int cwmp_udp_echo_diagnostics();
int cwmp_serverselection_diagnostics();
#endif

View file

@ -144,10 +144,10 @@ static void get_hexstring(unsigned const char *hash, int len, char *hexstr, int
static void get_value_from_header(const char *data) static void get_value_from_header(const char *data)
{ {
if (data == NULL) if (CWMP_STRLEN(data) == 0)
return; return;
int header_len = strlen(data) + 1; int header_len = CWMP_STRLEN(data) + 1;
char header[header_len]; char header[header_len];
memset(header, 0, header_len); memset(header, 0, header_len);
strncpy(header, data, header_len); strncpy(header, data, header_len);
@ -167,7 +167,7 @@ static void get_value_from_header(const char *data)
strip_lead_trail_char(key, '\"'); strip_lead_trail_char(key, '\"');
eq = eq + 1; eq = eq + 1;
char *end = eq + strlen(eq) - 1; char *end = eq + CWMP_STRLEN(eq) - 1;
len = end - eq + 2; len = end - eq + 2;
char val[len]; char val[len];
snprintf(val, len, "%s", eq); snprintf(val, len, "%s", eq);

View file

@ -1,3 +1,13 @@
/*
* digauth.h - HTTP digest authentication utility
*
* Copyright (C) 2022, IOPSYS Software Solutions AB.
*
* Author: suvendhu.hansa@iopsys.eu
*
* See LICENSE file for license related information.
*
*/
#ifndef DIGAUTH_H_ #ifndef DIGAUTH_H_
#define DIGAUTH_H_ #define DIGAUTH_H_

View file

@ -1,13 +1,13 @@
/* /*
* This program is free software: you can redistribute it and/or modify * download.c - Download method functions
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 2 of the License, or * Copyright (C) 2022, IOPSYS Software Solutions AB.
* (at your option) any later version. *
* Author: Omar Kallel <omar.kallel@pivasoftware.com>
*
* See LICENSE file for license related information.
* *
* Copyright (C) 2013-2021 iopsys Software Solutions AB
* Author Omar Kallel <omar.kallel@pivasoftware.com>
*/ */
#include <curl/curl.h> #include <curl/curl.h>
#include <string.h> #include <string.h>
#include <libubox/blobmsg_json.h> #include <libubox/blobmsg_json.h>

View file

@ -1,3 +1,13 @@
/*
* download.h - Download method functions
*
* Copyright (C) 2022, IOPSYS Software Solutions AB.
*
* Author: Omar Kallel <omar.kallel@pivasoftware.com>
*
* See LICENSE file for license related information.
*
*/
#ifndef CWMP_DOWNLOAD_H #ifndef CWMP_DOWNLOAD_H
#define CWMP_DOWNLOAD_H #define CWMP_DOWNLOAD_H

View file

@ -1,14 +1,14 @@
/* /*
* This program is free software: you can redistribute it and/or modify * event.c - Manage CWMP Events
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 2 of the License, or * Copyright (C) 2022, IOPSYS Software Solutions AB.
* (at your option) any later version.
* *
* Copyright (C) 2013-2021 iopsys Software Solutions AB
* Author Mohamed Kallel <mohamed.kallel@pivasoftware.com> * Author Mohamed Kallel <mohamed.kallel@pivasoftware.com>
* Author Ahmed Zribi <ahmed.zribi@pivasoftware.com> * Author Ahmed Zribi <ahmed.zribi@pivasoftware.com>
* Author Omar Kallel <omar.kallel@pivasoftware.com> * Author Omar Kallel <omar.kallel@pivasoftware.com>
* *
* See LICENSE file for license related information.
*
*/ */
#include "backupSession.h" #include "backupSession.h"
@ -389,7 +389,7 @@ void *thread_event_periodic(void *v)
bool event_exist_in_list(struct cwmp *cwmp, int event) bool event_exist_in_list(struct cwmp *cwmp, int event)
{ {
struct event_container *event_container; struct event_container *event_container = NULL;
list_for_each_entry (event_container, cwmp->head_event_container, list) { list_for_each_entry (event_container, cwmp->head_event_container, list) {
if (event_container->code == event) if (event_container->code == event)
return true; return true;

View file

@ -1,12 +1,12 @@
/* /*
* This program is free software: you can redistribute it and/or modify * event.h - Manage CWMP Events
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 2 of the License, or * Copyright (C) 2022, IOPSYS Software Solutions AB.
* (at your option) any later version.
* *
* Copyright (C) 2013-2020 iopsys Software Solutions AB
* Author Omar Kallel <omar.kallel@pivasoftware.com> * Author Omar Kallel <omar.kallel@pivasoftware.com>
* *
* See LICENSE file for license related information.
*
*/ */
#ifndef EVENT_H_ #ifndef EVENT_H_

View file

@ -1,3 +1,13 @@
/*
* heartbeat.c - CWMP HeartBeat mechanism
*
* Copyright (C) 2022, IOPSYS Software Solutions AB.
*
* Author Omar Kallel <omar.kallel@pivasoftware.com>
*
* See LICENSE file for license related information.
*
*/
#include <pthread.h> #include <pthread.h>
#include <unistd.h> #include <unistd.h>

View file

@ -1,3 +1,13 @@
/*
* heartbeat.h - CWMP HeartBeat mechanism
*
* Copyright (C) 2022, IOPSYS Software Solutions AB.
*
* Author Omar Kallel <omar.kallel@pivasoftware.com>
*
* See LICENSE file for license related information.
*
*/
#ifndef HEARTBEAT_H #ifndef HEARTBEAT_H
#define HEARTBEAT_H #define HEARTBEAT_H

View file

@ -1,14 +1,14 @@
/* /*
* This program is free software: you can redistribute it and/or modify * http.c - API for HTTP exchanges
* 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 * Copyright (C) 2022, IOPSYS Software Solutions AB.
*
* Author Omar Kallel <omar.kallel@pivasoftware.com>
* Author Mohamed Kallel <mohamed.kallel@pivasoftware.com> * Author Mohamed Kallel <mohamed.kallel@pivasoftware.com>
* Author Ahmed Zribi <ahmed.zribi@pivasoftware.com> * Author Ahmed Zribi <ahmed.zribi@pivasoftware.com>
* Author Omar Kallel <omar.kallel@pivasoftware.com> *
* Copyright (C) 2011-2012 Luka Perkov <freecwmp@lukaperkov.net> * See LICENSE file for license related information.
*
*/ */
#include <curl/curl.h> #include <curl/curl.h>
#include <arpa/inet.h> #include <arpa/inet.h>
@ -39,7 +39,7 @@ void http_set_timeout(void)
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 1); curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 1);
} }
int http_client_init(struct cwmp *cwmp) int icwmp_http_client_init(struct cwmp *cwmp)
{ {
char *dhcp_dis = NULL; char *dhcp_dis = NULL;
char *acs_var_stat = NULL; char *acs_var_stat = NULL;
@ -96,7 +96,7 @@ int http_client_init(struct cwmp *cwmp)
return 0; return 0;
} }
void http_client_exit(void) void icwmp_http_client_exit(void)
{ {
icwmp_free(http_c.url); icwmp_free(http_c.url);
@ -131,7 +131,69 @@ static size_t http_get_response(void *buffer, size_t size, size_t rxed, char **m
return size * rxed; return size * rxed;
} }
int http_send_message(struct cwmp *cwmp, char *msg_out, int msg_out_len, char **msg_in) static void http_set_security_options(struct cwmp *cwmp)
{
curl_easy_setopt(curl, CURLOPT_USERNAME, cwmp->conf.acs_userid);
curl_easy_setopt(curl, CURLOPT_PASSWORD, cwmp->conf.acs_passwd);
curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC | CURLAUTH_DIGEST);
if (cwmp->conf.acs_ssl_capath)
curl_easy_setopt(curl, CURLOPT_CAPATH, cwmp->conf.acs_ssl_capath);
if (cwmp->conf.insecure_enable) {
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, false);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0);
}
}
static void http_set_connection_options(struct cwmp *cwmp)
{
curl_easy_setopt(curl, CURLOPT_URL, http_c.url);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, HTTP_TIMEOUT);
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, HTTP_TIMEOUT);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_POSTREDIR, CURL_REDIR_POST_ALL);
curl_easy_setopt(curl, CURLOPT_NOBODY, 0);
#ifdef DEVEL
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
#endif
curl_easy_setopt(curl, CURLOPT_COOKIEFILE, fc_cookies);
curl_easy_setopt(curl, CURLOPT_COOKIEJAR, fc_cookies);
curl_easy_setopt(curl, CURLOPT_INTERFACE, cwmp->conf.interface);
}
static void http_set_header_list_options(struct cwmp *cwmp)
{
switch (cwmp->conf.compression) {
case COMP_NONE:
break;
case COMP_GZIP:
curl_easy_setopt(curl, CURLOPT_ACCEPT_ENCODING, "gzip");
http_c.header_list = curl_slist_append(http_c.header_list, "Content-Encoding: gzip");
break;
case COMP_DEFLATE:
curl_easy_setopt(curl, CURLOPT_ACCEPT_ENCODING, "deflate");
http_c.header_list = curl_slist_append(http_c.header_list, "Content-Encoding: deflate");
break;
}
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, http_c.header_list);
}
static void http_set_inout_options(char *msg_out, int msg_out_len, char **msg_in)
{
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, msg_out);
if (msg_out)
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)msg_out_len);
else
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, 0);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, http_get_response);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, msg_in);
}
int icwmp_http_send_message(struct cwmp *cwmp, char *msg_out, int msg_out_len, char **msg_in)
{ {
unsigned char buf[sizeof(struct in6_addr)]; unsigned char buf[sizeof(struct in6_addr)];
int tmp = 0; int tmp = 0;
@ -158,53 +220,13 @@ int http_send_message(struct cwmp *cwmp, char *msg_out, int msg_out_len, char **
if (!http_c.header_list) if (!http_c.header_list)
return -1; return -1;
} }
curl_easy_setopt(curl, CURLOPT_URL, http_c.url); http_set_connection_options(cwmp);
curl_easy_setopt(curl, CURLOPT_USERNAME, cwmp->conf.acs_userid); http_set_security_options(cwmp);
curl_easy_setopt(curl, CURLOPT_PASSWORD, cwmp->conf.acs_passwd); http_set_header_list_options(cwmp);
curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC | CURLAUTH_DIGEST); http_set_inout_options(msg_out, msg_out_len, msg_in);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, HTTP_TIMEOUT);
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, HTTP_TIMEOUT);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_POSTREDIR, CURL_REDIR_POST_ALL);
curl_easy_setopt(curl, CURLOPT_NOBODY, 0);
switch (cwmp->conf.compression) {
case COMP_NONE:
break;
case COMP_GZIP:
curl_easy_setopt(curl, CURLOPT_ACCEPT_ENCODING, "gzip");
http_c.header_list = curl_slist_append(http_c.header_list, "Content-Encoding: gzip");
break;
case COMP_DEFLATE:
curl_easy_setopt(curl, CURLOPT_ACCEPT_ENCODING, "deflate");
http_c.header_list = curl_slist_append(http_c.header_list, "Content-Encoding: deflate");
break;
}
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, http_c.header_list);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, msg_out);
if (msg_out)
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)msg_out_len);
else
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, 0);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, http_get_response);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, msg_in);
#ifdef DEVEL
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
#endif
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errbuf); curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errbuf);
curl_easy_setopt(curl, CURLOPT_COOKIEFILE, fc_cookies);
curl_easy_setopt(curl, CURLOPT_COOKIEJAR, fc_cookies);
if (cwmp->conf.acs_ssl_capath)
curl_easy_setopt(curl, CURLOPT_CAPATH, cwmp->conf.acs_ssl_capath);
if (cwmp->conf.insecure_enable) {
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, false);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0);
}
curl_easy_setopt(curl, CURLOPT_INTERFACE, cwmp->conf.interface);
*msg_in = (char *)calloc(1, sizeof(char)); *msg_in = (char *)calloc(1, sizeof(char));
res = curl_easy_perform(curl); res = curl_easy_perform(curl);
@ -279,7 +301,7 @@ error:
return -1; return -1;
} }
void http_success_cr(void) static void http_success_cr(void)
{ {
CWMP_LOG(INFO, "Connection Request thread: add connection request event in the queue"); CWMP_LOG(INFO, "Connection Request thread: add connection request event in the queue");
pthread_mutex_lock(&(cwmp_main.mutex_session_queue)); pthread_mutex_lock(&(cwmp_main.mutex_session_queue));
@ -291,14 +313,14 @@ void http_success_cr(void)
static void http_cr_new_client(int client, bool service_available) static void http_cr_new_client(int client, bool service_available)
{ {
FILE *fp; FILE *fp;
char buffer[BUFSIZ]; char buffer[BUFSIZ] = {0};
char auth_digest_buffer[BUFSIZ]; char auth_digest_buffer[BUFSIZ] = {0};
int8_t auth_status = 0; int8_t auth_status = 0;
bool auth_digest_checked = false; bool auth_digest_checked = false;
bool method_is_get = false; bool method_is_get = false;
bool internal_error = false; bool internal_error = false;
char cr_http_get_head[HTTP_GET_HDR_LEN]; char cr_http_get_head[HTTP_GET_HDR_LEN] = {0};
pthread_mutex_lock(&mutex_config_load); pthread_mutex_lock(&mutex_config_load);
fp = fdopen(client, "r+"); fp = fdopen(client, "r+");
@ -388,7 +410,7 @@ http_end:
pthread_mutex_unlock(&mutex_config_load); pthread_mutex_unlock(&mutex_config_load);
} }
void http_server_init(void) void icwmp_http_server_init(void)
{ {
struct sockaddr_in6 server = { 0 }; struct sockaddr_in6 server = { 0 };
unsigned short cr_port; unsigned short cr_port;
@ -438,7 +460,7 @@ void http_server_init(void)
CWMP_LOG(INFO, "Connection Request server initiated with the port: %d", cr_port); CWMP_LOG(INFO, "Connection Request server initiated with the port: %d", cr_port);
} }
void http_server_listen(void) void icwmp_http_server_listen(void)
{ {
int client_sock, c; int client_sock, c;
int cr_request = 0; int cr_request = 0;

36
src/http.h Normal file
View file

@ -0,0 +1,36 @@
/*
* http.h - API for HTTP exchanges
*
* Copyright (C) 2022, IOPSYS Software Solutions AB.
*
* Author Omar Kallel <omar.kallel@pivasoftware.com>
* Author Mohamed Kallel <mohamed.kallel@pivasoftware.com>
* Author Ahmed Zribi <ahmed.zribi@pivasoftware.com>
*
* See LICENSE file for license related information.
*
*/
#ifndef _FREECWMP_HTTP_H__
#define _FREECWMP_HTTP_H__
#include "common.h"
extern char *fc_cookies;
#define HTTP_TIMEOUT 60
struct http_client {
struct curl_slist *header_list;
char *url;
};
void http_set_timeout(void);
int icwmp_http_client_init(struct cwmp *cwmp);
void icwmp_http_client_exit(void);
int icwmp_http_send_message(struct cwmp *cwmp, char *msg_out, int msg_out_len, char **msg_in);
void icwmp_http_server_init(void);
void icwmp_http_server_listen(void);
#endif

View file

@ -1,12 +1,13 @@
/* /*
* This program is free software: you can redistribute it and/or modify * log.c - CWMP Logs functions
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 2 of the License, or * Copyright (C) 2022, IOPSYS Software Solutions AB.
* (at your option) any later version.
* *
* Copyright (C) 2013-2021 iopsys Software Solutions AB
* Author Mohamed Kallel <mohamed.kallel@pivasoftware.com> * Author Mohamed Kallel <mohamed.kallel@pivasoftware.com>
* Author Ahmed Zribi <ahmed.zribi@pivasoftware.com> * Author Ahmed Zribi <ahmed.zribi@pivasoftware.com>
* Author Omar Kallel <omar.kallel@pivasoftware.com>
*
* See LICENSE file for license related information.
* *
*/ */

View file

@ -1,12 +1,13 @@
/* /*
* This program is free software: you can redistribute it and/or modify * log.h - CWMP Logs functions
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 2 of the License, or * Copyright (C) 2022, IOPSYS Software Solutions AB.
* (at your option) any later version.
* *
* Copyright (C) 2013-2019 iopsys Software Solutions AB
* Author Mohamed Kallel <mohamed.kallel@pivasoftware.com> * Author Mohamed Kallel <mohamed.kallel@pivasoftware.com>
* Author Ahmed Zribi <ahmed.zribi@pivasoftware.com> * Author Ahmed Zribi <ahmed.zribi@pivasoftware.com>
* Author Omar Kallel <omar.kallel@pivasoftware.com>
*
* See LICENSE file for license related information.
* *
*/ */

View file

@ -1,12 +1,12 @@
/* /*
* This program is free software: you can redistribute it and/or modify * notifications.c - Manage CWMP Notifications
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 2 of the License, or * Copyright (C) 2022, IOPSYS Software Solutions AB.
* (at your option) any later version.
* *
* Copyright (C) 2013-2021 iopsys Software Solutions AB
* Author Omar Kallel <omar.kallel@pivasoftware.com> * Author Omar Kallel <omar.kallel@pivasoftware.com>
* *
* See LICENSE file for license related information.
*
*/ */
#include <netdb.h> #include <netdb.h>
@ -207,7 +207,7 @@ int get_parameter_leaf_notification_from_childs_list(char *parameter_name, struc
{ {
char *parent = NULL; char *parent = NULL;
int ret_notif = -1; int ret_notif = -1;
struct cwmp_dm_parameter *param_value; struct cwmp_dm_parameter *param_value = NULL;
if (childs_list == NULL) if (childs_list == NULL)
return -1; return -1;
list_for_each_entry (param_value, childs_list, list) { list_for_each_entry (param_value, childs_list, list) {
@ -239,7 +239,7 @@ char *cwmp_get_parameter_attributes(char *parameter_name, struct list_head *para
cwmp_free_all_dm_parameter_list(&childs_notifs); cwmp_free_all_dm_parameter_list(&childs_notifs);
return error; return error;
} }
struct cwmp_dm_parameter *param_value; struct cwmp_dm_parameter *param_value = NULL;
list_for_each_entry (param_value, &params_list, list) { list_for_each_entry (param_value, &params_list, list) {
int notif_leaf; int notif_leaf;
notif_leaf = check_parameter_forced_notification(param_value->name); notif_leaf = check_parameter_forced_notification(param_value->name);
@ -307,7 +307,7 @@ void create_list_param_obj_notify()
char* updated_list_param_leaf_notify_with_sub_parameter_list(struct list_head *list_param_leaf_notify, struct cwmp_dm_parameter parent_parameter, void (*update_notify_file_line_arg)(FILE *notify_file, char *param_name, char *param_type, char *param_value, int notification), FILE* notify_file_arg) char* updated_list_param_leaf_notify_with_sub_parameter_list(struct list_head *list_param_leaf_notify, struct cwmp_dm_parameter parent_parameter, void (*update_notify_file_line_arg)(FILE *notify_file, char *param_name, char *param_type, char *param_value, int notification), FILE* notify_file_arg)
{ {
struct cwmp_dm_parameter *param_iter; struct cwmp_dm_parameter *param_iter = NULL;
LIST_HEAD(params_list); LIST_HEAD(params_list);
char *err = cwmp_get_parameter_values(parent_parameter.name, &params_list); char *err = cwmp_get_parameter_values(parent_parameter.name, &params_list);
if (err) if (err)
@ -326,7 +326,7 @@ char* updated_list_param_leaf_notify_with_sub_parameter_list(struct list_head *l
void create_list_param_leaf_notify(struct list_head *list_param_leaf_notify, void (*update_notify_file_line_arg)(FILE *notify_file, char *param_name, char *param_type, char *param_value, int notification), FILE* notify_file_arg) void create_list_param_leaf_notify(struct list_head *list_param_leaf_notify, void (*update_notify_file_line_arg)(FILE *notify_file, char *param_name, char *param_type, char *param_value, int notification), FILE* notify_file_arg)
{ {
struct cwmp_dm_parameter *param_iter; struct cwmp_dm_parameter *param_iter = NULL;
int i; int i;
for (i = 0; i < (int)ARRAY_SIZE(forced_notifications_parameters); i++) for (i = 0; i < (int)ARRAY_SIZE(forced_notifications_parameters); i++)
@ -462,7 +462,7 @@ void load_custom_notify_json(struct cwmp *cwmp)
*/ */
void get_parameter_value_from_parameters_list(struct list_head *params_list, char *parameter_name, char **value, char **type) void get_parameter_value_from_parameters_list(struct list_head *params_list, char *parameter_name, char **value, char **type)
{ {
struct cwmp_dm_parameter *param_value; struct cwmp_dm_parameter *param_value = NULL;
list_for_each_entry (param_value, params_list, list) { list_for_each_entry (param_value, params_list, list) {
if (param_value->name == NULL) if (param_value->name == NULL)
continue; continue;

View file

@ -1,12 +1,12 @@
/* /*
* This program is free software: you can redistribute it and/or modify * notifications.h - Manage CWMP Notifications
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 2 of the License, or * Copyright (C) 2022, IOPSYS Software Solutions AB.
* (at your option) any later version.
* *
* Copyright (C) 2013-2020 iopsys Software Solutions AB
* Author Omar Kallel <omar.kallel@pivasoftware.com> * Author Omar Kallel <omar.kallel@pivasoftware.com>
* *
* See LICENSE file for license related information.
*
*/ */
#ifndef NOTIFICATIONS_H_ #ifndef NOTIFICATIONS_H_

View file

@ -1,11 +1,12 @@
/* /*
* This program is free software: you can redistribute it and/or modify * reboot.c - Reboot method fuctions
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 2 of the License, or * Copyright (C) 2022, IOPSYS Software Solutions AB.
* (at your option) any later version.
* *
* Copyright (C) 2021 iopsys Software Solutions AB
* Author Amin Ben Ramdhane <amin.benramdhane@pivasoftware.com> * Author Amin Ben Ramdhane <amin.benramdhane@pivasoftware.com>
*
* See LICENSE file for license related information.
*
*/ */
#include <unistd.h> #include <unistd.h>

20
src/reboot.h Normal file
View file

@ -0,0 +1,20 @@
/*
* reboot.h - Reboot method fuctions
*
* Copyright (C) 2022, IOPSYS Software Solutions AB.
*
* Author Amin Ben Ramdhane <amin.benramdhane@pivasoftware.com>
*
* See LICENSE file for license related information.
*
*/
#ifndef _REBOOT_H__
#define _REBOOT_H__
#include "common.h"
void launch_reboot_methods(struct cwmp *cwmp);
#endif //_REBOOT_H__

1960
src/rpc.c Executable file

File diff suppressed because it is too large Load diff

View file

@ -1,13 +1,13 @@
/* /*
* This program is free software: you can redistribute it and/or modify * rpc.h - CWMP RPC methods
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 2 of the License, or * Copyright (C) 2021-2022, IOPSYS Software Solutions AB.
* (at your option) any later version.
* *
* Copyright (C) 2013-2019 iopsys Software Solutions AB
* Author Mohamed Kallel <mohamed.kallel@pivasoftware.com> * Author Mohamed Kallel <mohamed.kallel@pivasoftware.com>
* Author Ahmed Zribi <ahmed.zribi@pivasoftware.com> * Author Ahmed Zribi <ahmed.zribi@pivasoftware.com>
* Copyright (C) 2011 Luka Perkov <freecwmp@lukaperkov.net> * Author Omar Kallel <omar.kallel@pivasoftware.com>
*
* See LICENSE file for license related information.
* *
*/ */
@ -51,7 +51,6 @@ int cwmp_rpc_acs_parse_response_get_rpc_methods(struct cwmp *cwmp, struct sessio
int cwmp_rpc_acs_prepare_get_rpc_methods(struct cwmp *cwmp, struct session *session, struct rpc *rpc); int cwmp_rpc_acs_prepare_get_rpc_methods(struct cwmp *cwmp, struct session *session, struct rpc *rpc);
int cwmp_rpc_acs_prepare_transfer_complete(struct cwmp *cwmp, struct session *session, struct rpc *rpc); int cwmp_rpc_acs_prepare_transfer_complete(struct cwmp *cwmp, struct session *session, struct rpc *rpc);
int cwmp_rpc_acs_prepare_du_state_change_complete(struct cwmp *cwmp, struct session *session, struct rpc *rpc); int cwmp_rpc_acs_prepare_du_state_change_complete(struct cwmp *cwmp, struct session *session, struct rpc *rpc);
int cwmp_rpc_acs_destroy_data_inform(struct session *session, struct rpc *rpc);
int xml_handle_message(struct session *session); int xml_handle_message(struct session *session);
int cwmp_create_fault_message(struct session *session, struct rpc *rpc_cpe, int fault_code); int cwmp_create_fault_message(struct session *session, struct rpc *rpc_cpe, int fault_code);

View file

@ -1,11 +1,12 @@
/* /*
* This program is free software: you can redistribute it and/or modify * sched_inform.c - ScheduleInform method corresponding functions
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 2 of the License, or * Copyright (C) 2021-2022, IOPSYS Software Solutions AB.
* (at your option) any later version.
* *
* Copyright (C) 2013-2021 iopsys Software Solutions AB
* Author Omar Kallel <omar.kallel@pivasoftware.com> * Author Omar Kallel <omar.kallel@pivasoftware.com>
*
* See LICENSE file for license related information.
*
*/ */
#include "sched_inform.h" #include "sched_inform.h"

View file

@ -1,11 +1,12 @@
/* /*
* This program is free software: you can redistribute it and/or modify * sched_inform.h - ScheduleInform method corresponding functions
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 2 of the License, or * Copyright (C) 2021-2022, IOPSYS Software Solutions AB.
* (at your option) any later version.
* *
* Copyright (C) 2013-2021 iopsys Software Solutions AB
* Author Omar Kallel <omar.kallel@pivasoftware.com> * Author Omar Kallel <omar.kallel@pivasoftware.com>
*
* See LICENSE file for license related information.
*
*/ */
#ifndef CWMP_SCHED_INFORM_H #ifndef CWMP_SCHED_INFORM_H

View file

@ -1,12 +1,12 @@
/* /*
* This program is free software: you can redistribute it and/or modify * session.c - API for CWMP Session
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 2 of the License, or * Copyright (C) 2021-2022, IOPSYS Software Solutions AB.
* (at your option) any later version.
* *
* Copyright (C) 2013-2021 iopsys Software Solutions AB
* Author Omar Kallel <omar.kallel@pivasoftware.com> * Author Omar Kallel <omar.kallel@pivasoftware.com>
* *
* See LICENSE file for license related information.
*
*/ */
#include <stdlib.h> #include <stdlib.h>
@ -14,7 +14,7 @@
#include "session.h" #include "session.h"
#include "config.h" #include "config.h"
#include "event.h" #include "event.h"
#include "rpc_soap.h" #include "rpc.h"
#include "backupSession.h" #include "backupSession.h"
#include "heartbeat.h" #include "heartbeat.h"

View file

@ -1,18 +1,18 @@
/* /*
* This program is free software: you can redistribute it and/or modify * session.h - API for CWMP Session
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 2 of the License, or * Copyright (C) 2021-2022, IOPSYS Software Solutions AB.
* (at your option) any later version.
* *
* Copyright (C) 2013-2020 iopsys Software Solutions AB
* Author Omar Kallel <omar.kallel@pivasoftware.com> * Author Omar Kallel <omar.kallel@pivasoftware.com>
* *
* See LICENSE file for license related information.
*
*/ */
#ifndef SESSION_H_ #ifndef SESSION_H_
#define SESSION_H_ #define SESSION_H_
#include <xml_utils.h> #include "xml_utils.h"
#include "common.h" #include "common.h"
typedef struct session { typedef struct session {

View file

@ -1,3 +1,13 @@
/*
* ubus_utils.h - ubus methods and utility functions
*
* Copyright (C) 2022, IOPSYS Software Solutions AB.
*
* Author: suvendhu.hansa@iopsys.eu
*
* See LICENSE file for license related information
*
*/
#ifndef __ICWMP_UBUS_UTILS_H__ #ifndef __ICWMP_UBUS_UTILS_H__
#define __ICWMP_UBUS_UTILS_H__ #define __ICWMP_UBUS_UTILS_H__

View file

@ -1,11 +1,12 @@
/* /*
* This program is free software: you can redistribute it and/or modify * upload.c - Upload method corresponding functions
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 2 of the License, or * Copyright (C) 2021-2022, IOPSYS Software Solutions AB.
* (at your option) any later version.
* *
* Copyright (C) 2013-2021 iopsys Software Solutions AB
* Author Omar Kallel <omar.kallel@pivasoftware.com> * Author Omar Kallel <omar.kallel@pivasoftware.com>
*
* See LICENSE file for license related information.
*
*/ */
#include <curl/curl.h> #include <curl/curl.h>
@ -36,7 +37,7 @@ int lookup_vcf_name(int instance, char **value)
CWMP_LOG(ERROR, "Not able to get the value of the parameter %s", vcf_name_parameter); CWMP_LOG(ERROR, "Not able to get the value of the parameter %s", vcf_name_parameter);
return -1; return -1;
} }
struct cwmp_dm_parameter *param_value; struct cwmp_dm_parameter *param_value = NULL;
list_for_each_entry (param_value, &vcf_parameters, list) { list_for_each_entry (param_value, &vcf_parameters, list) {
*value = param_value->value ? strdup(param_value->value) : NULL; *value = param_value->value ? strdup(param_value->value) : NULL;
break; break;
@ -54,7 +55,7 @@ int lookup_vlf_name(int instance, char **value)
CWMP_LOG(ERROR, "Not able to get the value of the parameter %s", vlf_name_parameter); CWMP_LOG(ERROR, "Not able to get the value of the parameter %s", vlf_name_parameter);
return -1; return -1;
} }
struct cwmp_dm_parameter *param_value; struct cwmp_dm_parameter *param_value = NULL;
list_for_each_entry (param_value, &vlf_parameters, list) { list_for_each_entry (param_value, &vlf_parameters, list) {
*value = param_value->value ? strdup(param_value->value) : NULL; *value = param_value->value ? strdup(param_value->value) : NULL;
break; break;

View file

@ -1,11 +1,12 @@
/* /*
* This program is free software: you can redistribute it and/or modify * upload.h - Upload method corresponding functions
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 2 of the License, or * Copyright (C) 2021-2022, IOPSYS Software Solutions AB.
* (at your option) any later version.
* *
* Copyright (C) 2013-2021 iopsys Software Solutions AB
* Author Omar Kallel <omar.kallel@pivasoftware.com> * Author Omar Kallel <omar.kallel@pivasoftware.com>
*
* See LICENSE file for license related information.
*
*/ */
#ifndef CWMP_UPLOAD_H #ifndef CWMP_UPLOAD_H

1434
src/xml.c Normal file

File diff suppressed because it is too large Load diff

255
src/xml.h Normal file
View file

@ -0,0 +1,255 @@
#ifndef __XML__H_
#define __XML__H_
#include "xml_utils.h"
#include "session.h"
#include "common.h"
#define CWMP_MXML_TAB_SPACE " "
#define MAX_SCHEDULE_INFORM_QUEUE 10
#define XML2(A,B) {A, B, 0, NULL}
#define XML3(A,B,C) {A, B, C, NULL}
#define XML4(A,B,D) {A, B, 0, D}
enum soap_methods {
SOAP_REQ_SPV = 1,
SOAP_REQ_GPV,
SOAP_REQ_GPN,
SOAP_REQ_SPA,
SOAP_REQ_GPA,
SOAP_REQ_ADDOBJ,
SOAP_REQ_DELOBJ,
SOAP_REQ_REBOOT,
SOAP_REQ_DOWNLOAD,
SOAP_REQ_UPLOAD,
SOAP_REQ_CANCELTRANSFER,
SOAP_REQ_SCHEDINF,
SOAP_REQ_SCHEDDOWN,
SOAP_REQ_CDU,
SOAP_REQ_SPV_LIST,
SOAP_REQ_SPV_LIST_REF,
SOAP_REQ_GPV_REF,
SOAP_REQ_SPA_REF,
SOAP_REQ_GPA_REF,
SOAP_TIMEWINDOW_REF,
SOAP_TIME_REF,
SOAP_REQ_CDU_OPERATIONS,
SOAP_REQ_CDU_OPS_REF,
SOAP_REQ_DU_INSTALL,
SOAP_REQ_DU_UPDATE,
SOAP_REQ_DU_UNINSTALL,
SOAP_RESP_GPV,
SOAP_PARAM_STRUCT,
SOAP_PARAM_STRUCT_REF,
SOAP_VALUE_STRUCT,
SOAP_RESP_SPV,
SOAP_RESP_GPN,
SOAP_RESP_GPN_REF,
SOAP_RESP_GPA,
SOAP_RESP_GPA_REF,
SOAP_RESP_ADDOBJ,
SOAP_RESP_DELOBJ,
SOAP_RESP_DOWNLOAD,
SOAP_RESP_UPLOAD,
SOAP_RESP_GETRPC,
SOAP_RESP_GETRPC_REF,
SOAP_ACS_TRANSCOMPLETE,
SOAP_ROOT_FAULT,
SOAP_RPC_FAULT,
SOAP_FAULT_DETAIL,
SOAP_CWMP_FAULT,
SOAP_SPV_FAULT,
SOAP_SPV_FAULT_REF,
SOAP_FAULT_STRCT_REF,
SOAP_ENV,
SOAP_HEAD,
SOAP_BODY,
SOAP_INFORM_CWMP,
SOAP_DEVID,
SOAP_DU_CHANGE_COMPLETE,
SOAP_CDU_RESULTS_REF,
SOAP_CDU_OPTS_REF,
ATTR_PARAM_STRUCT,
ATTR_SOAP_ENV,
SOAP_MAX
};
enum xml_tag_types {
XML_STRING,
XML_BOOL,
XML_INTEGER,
XML_LINTEGER,
XML_TIME,
XML_FUNC,
XML_REC,
XML_NODE,
XML_ATTR
};
enum tag_multiple_single {
XML_SINGLE,
XML_LIST
};
enum validation_types {
VALIDATE_STR_SIZE,
VALIDATE_UNINT,
VALIDATE_BOOLEAN,
VALIDATE_INT_RANGE
};
struct xml_tag_validation {
char *tag_name;
int validation_type;
int min;
int max;
};
struct xml_data_struct {
mxml_node_t **parameter_list;
char **name;
char **value;
char **string;
char **parameter_path;
char **parameter_name;
char **object_name;
char **parameter_key;
char **command_key;
char **file_type;
char **url;
char **username;
char **password;
char **uuid;
char **exec_env_ref;
char **du_ref;
char **current_state;
char **version;
char **window_mode;
char **user_message;
char **start_time;
char **complete_time;
char **access_list;
char **fault_string;
char **faultcode;
char **faultstring;
char **manufacturer;
char **oui;
char **serial_number;
char **current_time;
char **product_class;
char **xsi_type;
int *file_size;
int *notification;
int *scheddown_max_retries;
int *status;
int *instance;
int *fault_code;
int *max_envelopes;
int *retry_count;
long int *delay_seconds;
long int *window_start;
long int *window_end;
bool *next_level;
bool *notification_change;
bool *writable;
mxml_node_t **xml_env;
struct list_head *data_list;
char **xcwmp;
int *amd_version;
unsigned int *session_timeout;
int *cdu_type;
int *counter;
struct xml_tag_validation *validations;
int nbre_validations;
};
struct xml_list_data {
struct list_head list;
char *param_name;
char *param_value;
char *param_type;
char *windowmode;
char *usermessage;
char *access_list;
char *rpc_name;
char *fault_string;
char *url;
char *uuid;
char *username;
char *password;
char *execution_env_ref;
char *version;
char *du_ref;
char *current_state;
char *start_time;
char *complete_time;
char *command_key;
long int windowstart;
long int windowend;
int max_retries;
int notification;
int fault_code;
int cdu_type;
int event_code;
bool notification_change;
bool writable;
};
struct xml_tag {
char *tag_name;
int tag_type;
int rec_ref;
int (*xml_func)(mxml_node_t *node, struct xml_data_struct *xml_attrs);
};
struct xml_node_data {
int node_ms;
int tag_node_ref;
char *tag_list_name;
struct xml_tag xml_tags[10];
};
#define MXML_DELETE(X) \
do { \
if (X) { \
mxmlDelete(X); \
X = NULL; \
} \
} while (0)
extern const char *cwmp_urls[];
int xml_prepare_msg_out(struct session *session);
int xml_prepare_lwnotification_message(char **msg_out);
int xml_set_cwmp_id_rpc_cpe(struct session *session);
int xml_recreate_namespace(mxml_node_t *tree);
const char *whitespace_cb(mxml_node_t *node, int where);
int xml_set_cwmp_id(struct session *session);
int xml_send_message(struct cwmp *cwmp, struct session *session, struct rpc *rpc);
mxml_node_t *mxmlFindElementOpaque(mxml_node_t *node, mxml_node_t *top, const char *text, int descend);
char *xml__get_attribute_name_by_value(mxml_node_t *node, const char *value);
char *xml_get_cwmp_version(int version);
void xml_exit(void);
void load_response_xml_schema(mxml_node_t **schema);
void load_notification_xml_schema(mxml_node_t **tree);
int load_xml_node_data(int node_ref, mxml_node_t *node, struct xml_data_struct *xml_attrs);
int build_xml_node_data(int node_ref, mxml_node_t *node, struct xml_data_struct *xml_attrs);
void add_xml_data_list(struct list_head *data_list, struct xml_list_data *xml_data);
mxml_node_t * build_top_body_soap_response(mxml_node_t *node, char *method);
mxml_node_t * build_top_body_soap_request(mxml_node_t *node, char *method);
void dm_parameter_list_to_xml_data_list(struct list_head *dm_parameter_list, struct list_head *xml_data_list);
void xml_data_list_to_dm_parameter_list(struct list_head *xml_data_list, struct list_head *dm_parameter_list);
void xml_data_list_to_cdu_operations_list(struct list_head *xml_data_list, struct list_head *du_op_list);
void cdu_operations_list_to_xml_data_list(struct list_head *du_op_list, struct list_head *xml_data_list);
void event_container_list_to_xml_data_list(struct list_head *event_container, struct list_head *xml_data_list);
void cwmp_param_fault_list_to_xml_data_list(struct list_head *param_fault_list, struct list_head *xml_data_list);
void cwmp_free_all_xml_data_list(struct list_head *list);
int load_upload_filetype(mxml_node_t *b, struct xml_data_struct *xml_attrs);
int load_download_filetype(mxml_node_t *b, struct xml_data_struct *xml_attrs);
int load_sched_download_window_mode(mxml_node_t *b, struct xml_data_struct *xml_attrs);
int load_change_du_state_operation(mxml_node_t *b, struct xml_data_struct *xml_attrs);
int build_inform_events(mxml_node_t *b, struct xml_data_struct *xml_attrs);
int build_inform_env_header(mxml_node_t *b, struct xml_data_struct *xml_attrs);
#endif

View file

@ -4,20 +4,20 @@ LIB_LDFLAGS:= -luci -lblobmsg_json -lubox\
-ljson-c -lubus -lpthread -lcurl\ -ljson-c -lubus -lpthread -lcurl\
-lcrypto -lmxml -lcrypto -lmxml
LIB_CFLAGS:= -fPIC -I../../inc -DLOPENSSL -g -O0 LIB_CFLAGS:= -fPIC -I../../src/ -DLOPENSSL -g -O0
UNIT_TESTS:= icwmp_unit_testd UNIT_TESTS:= icwmp_unit_testd
VALGRIND = /usr/bin/valgrind --xml=yes --xml-file=memory-report.xml --leak-check=full --show-reachable=yes --show-leak-kinds=all --errors-for-leak-kinds=all VALGRIND = /usr/bin/valgrind --xml=yes --xml-file=memory-report.xml --leak-check=full --show-reachable=yes --show-leak-kinds=all --errors-for-leak-kinds=all
ICWMP_SOURCES=$(patsubst ./%.c, ../../%.c, $(icwmpd_SOURCES)) ICWMP_SOURCES=$(patsubst ./src/%.c, ../../src/%.c, $(icwmpd_SOURCES))
ICWMP_OBJS=$(patsubst ../../%.c, %.o, $(ICWMP_SOURCES)) ICWMP_OBJS=$(patsubst ../../src/%.c, %.o, $(ICWMP_SOURCES))
TEST_SRCS = $(wildcard *.c) TEST_SRCS = $(wildcard *.c)
TEST_OBJS = $(TEST_SRCS:=.o) TEST_OBJS = $(TEST_SRCS:=.o)
%.c.o: %.c %.c.o: %.c
$(CC) -g -O0 -I../../inc -c -o $@ $< $(CC) -g -O0 -I../../src/ -c -o $@ $<
%.o: ../../%.c %.o: ../../src/%.c
$(CC) ${LIB_CFLAGS} -c -o $@ $< $(CC) ${LIB_CFLAGS} -c -o $@ $<
libunit: ${ICWMP_OBJS} libunit: ${ICWMP_OBJS}

View file

@ -18,7 +18,7 @@
#include "common.h" #include "common.h"
#include "config.h" #include "config.h"
#include "rpc_soap.h" #include "rpc.h"
static struct cwmp cwmp_main_test = { 0 }; static struct cwmp cwmp_main_test = { 0 };

View file

@ -19,7 +19,7 @@
#include "datamodel_interface.h" #include "datamodel_interface.h"
#include "event.h" #include "event.h"
#include "xml.h" #include "xml.h"
#include "rpc_soap.h" #include "rpc.h"
#include "session.h" #include "session.h"
#include "log.h" #include "log.h"

View file

@ -16,7 +16,7 @@
#include <string.h> #include <string.h>
#include <mxml.h> #include <mxml.h>
#include "rpc_soap.h" #include "rpc.h"
#include "event.h" #include "event.h"
#include "session.h" #include "session.h"
#include "config.h" #include "config.h"

577
xml.c
View file

@ -1,577 +0,0 @@
/*
* 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 Mohamed Kallel <mohamed.kallel@pivasoftware.com>
* Author Ahmed Zribi <ahmed.zribi@pivasoftware.com>
* Author Omar Kallel <omar.kallel@pivasoftware.com>
*/
#include "xml.h"
#include "log.h"
#include "notifications.h"
#include "http.h"
#include "cwmp_zlib.h"
static const char *soap_env_url = "http://schemas.xmlsoap.org/soap/envelope/";
static const char *soap_enc_url = "http://schemas.xmlsoap.org/soap/encoding/";
static const char *xsd_url = "http://www.w3.org/2001/XMLSchema";
static const char *xsi_url = "http://www.w3.org/2001/XMLSchema-instance";
const char *cwmp_urls[] = { "urn:dslforum-org:cwmp-1-0", "urn:dslforum-org:cwmp-1-1", "urn:dslforum-org:cwmp-1-2", "urn:dslforum-org:cwmp-1-2", "urn:dslforum-org:cwmp-1-2", "urn:dslforum-org:cwmp-1-2", NULL };
mxml_node_t * /* O - Element node or NULL */
mxmlFindElementOpaque(mxml_node_t *node, /* I - Current node */
mxml_node_t *top, /* I - Top node */
const char *text, /* I - Element text, if NULL return NULL */
int descend) /* I - Descend into tree - MXML_DESCEND, MXML_NO_DESCEND, or MXML_DESCEND_FIRST */
{
if (!node || !top || !text)
return (NULL);
node = mxmlWalkNext(node, top, descend);
while (node != NULL) {
const char *op = mxmlGetOpaque(node);
if (mxmlGetType(node) == MXML_OPAQUE && op && (!strcmp(op, text))) {
return (node);
}
if (descend == MXML_DESCEND)
node = mxmlWalkNext(node, top, MXML_DESCEND);
else
node = mxmlGetNextSibling(node);
}
return (NULL);
}
char *xml__get_attribute_name_by_value(mxml_node_t *node, const char *value)
{
int attributes_nbre = mxmlElementGetAttrCount(node);
int i;
for (i = 0; i < attributes_nbre; i++) {
char *attr_name = NULL;
const char *attr_value = mxmlElementGetAttrByIndex(node, i, (const char **)&attr_name);
if (strcmp(attr_value, value) == 0)
return attr_name;
}
return NULL;
}
int xml_recreate_namespace(mxml_node_t *tree)
{
const char *cwmp_urn;
int i;
mxml_node_t *b = tree;
do {
char *c;
FREE(ns.soap_env);
FREE(ns.soap_enc);
FREE(ns.xsd);
FREE(ns.xsi);
FREE(ns.cwmp);
c = (char *)xml__get_attribute_name_by_value(b, soap_env_url);
if (c && *(c + 5) == ':') {
ns.soap_env = strdup((c + 6));
} else {
continue;
}
c = (char *)xml__get_attribute_name_by_value(b, soap_enc_url);
if (c && *(c + 5) == ':') {
ns.soap_enc = strdup((c + 6));
} else {
continue;
}
c = (char *)xml__get_attribute_name_by_value(b, xsd_url);
if (c && *(c + 5) == ':') {
ns.xsd = strdup((c + 6));
} else {
continue;
}
c = (char *)xml__get_attribute_name_by_value(b, xsi_url);
if (c && *(c + 5) == ':') {
ns.xsi = strdup((c + 6));
} else {
continue;
}
for (i = 0; cwmp_urls[i] != NULL; i++) {
cwmp_urn = cwmp_urls[i];
c = (char *)xml__get_attribute_name_by_value(b, cwmp_urn);
if (c && *(c + 5) == ':') {
ns.cwmp = strdup((c + 6));
break;
}
}
if (!ns.cwmp)
continue;
return 0;
} while ((b = mxmlWalkNext(b, tree, MXML_DESCEND)));
return -1;
}
void xml_exit(void)
{
FREE(ns.soap_env);
FREE(ns.soap_enc);
FREE(ns.xsd);
FREE(ns.xsi);
FREE(ns.cwmp);
}
int xml_send_message(struct cwmp *cwmp, struct session *session, struct rpc *rpc)
{
char *s, *msg_out = NULL, *msg_in = NULL;
char c[512];
int msg_out_len = 0, f, r = 0;
mxml_node_t *b;
if (session->tree_out) {
unsigned char *zmsg_out;
msg_out = mxmlSaveAllocString(session->tree_out, whitespace_cb);
CWMP_LOG_XML_MSG(DEBUG, msg_out, XML_MSG_OUT);
if (cwmp->conf.compression != COMP_NONE) {
if (zlib_compress(msg_out, &zmsg_out, &msg_out_len, cwmp->conf.compression)) {
return -1;
}
FREE(msg_out);
msg_out = (char *)zmsg_out;
} else {
msg_out_len = strlen(msg_out);
}
}
while (1) {
f = 0;
if (http_send_message(cwmp, msg_out, msg_out_len, &msg_in)) {
goto error;
}
if (msg_in) {
CWMP_LOG_XML_MSG(DEBUG, msg_in, XML_MSG_IN);
if ((s = strstr(msg_in, "<FaultCode>")))
sscanf(s, "<FaultCode>%d</FaultCode>", &f);
if (f) {
if (f == 8005) {
r++;
if (r < 5) {
FREE(msg_in);
continue;
}
goto error;
} else if (rpc && rpc->type != RPC_ACS_INFORM) {
break;
} else {
goto error;
}
} else {
break;
}
} else {
goto end;
}
}
session->tree_in = mxmlLoadString(NULL, msg_in, MXML_OPAQUE_CALLBACK);
if (!session->tree_in)
goto error;
xml_recreate_namespace(session->tree_in);
/* get NoMoreRequests or HolRequest*/
session->hold_request = false;
if (snprintf(c, sizeof(c), "%s:%s", ns.cwmp, "NoMoreRequests") == -1)
goto error;
b = mxmlFindElement(session->tree_in, session->tree_in, c, NULL, NULL, MXML_DESCEND);
if (b) {
b = mxmlWalkNext(b, session->tree_in, MXML_DESCEND_FIRST);
if (b && mxmlGetType(b) == MXML_OPAQUE && mxmlGetOpaque(b))
session->hold_request = atoi(mxmlGetOpaque(b));
} else {
if (snprintf(c, sizeof(c), "%s:%s", ns.cwmp, "HoldRequests") == -1)
goto error;
b = mxmlFindElement(session->tree_in, session->tree_in, c, NULL, NULL, MXML_DESCEND);
if (b) {
b = mxmlWalkNext(b, session->tree_in, MXML_DESCEND_FIRST);
if (b && mxmlGetType(b) == MXML_OPAQUE && mxmlGetOpaque(b))
session->hold_request = atoi(mxmlGetOpaque(b));
}
}
end:
FREE(msg_out);
FREE(msg_in);
return 0;
error:
FREE(msg_out);
FREE(msg_in);
return -1;
}
int xml_prepare_msg_out(struct session *session)
{
struct cwmp *cwmp = &cwmp_main;
struct config *conf;
conf = &(cwmp->conf);
mxml_node_t *n;
load_response_xml_schema(&session->tree_out);
if (!session->tree_out)
return -1;
n = mxmlFindElement(session->tree_out, session->tree_out, "soap_env:Envelope", NULL, NULL, MXML_DESCEND);
if (!n) {
return -1;
}
mxmlElementSetAttr(n, "xmlns:cwmp", cwmp_urls[(conf->amd_version) - 1]);
if (!session->tree_out)
return -1;
return 0;
}
int xml_set_cwmp_id(struct session *session)
{
char c[32];
mxml_node_t *b;
/* define cwmp id */
if (snprintf(c, sizeof(c), "%u", ++(cwmp_main.cwmp_id)) == -1)
return -1;
b = mxmlFindElement(session->tree_out, session->tree_out, "cwmp:ID", NULL, NULL, MXML_DESCEND);
if (!b)
return -1;
b = mxmlNewOpaque(b, c);
if (!b)
return -1;
return 0;
}
int xml_set_cwmp_id_rpc_cpe(struct session *session)
{
char c[512];
mxml_node_t *b;
/* handle cwmp:ID */
if (snprintf(c, sizeof(c), "%s:%s", ns.cwmp, "ID") == -1)
return -1;
b = mxmlFindElement(session->tree_in, session->tree_in, c, NULL, NULL, MXML_DESCEND);
if (b) {
/* ACS send ID parameter */
b = mxmlWalkNext(b, session->tree_in, MXML_DESCEND_FIRST);
if (!b || mxmlGetType(b) != MXML_OPAQUE || !mxmlGetOpaque(b))
return 0;
snprintf(c, sizeof(c), "%s", mxmlGetOpaque(b));
b = mxmlFindElement(session->tree_out, session->tree_out, "cwmp:ID", NULL, NULL, MXML_DESCEND);
if (!b)
return -1;
b = mxmlNewOpaque(b, c);
if (!b)
return -1;
} else {
/* ACS does not send ID parameter */
int r = xml_set_cwmp_id(session);
return r;
}
return 0;
}
const char *get_node_tab_space(mxml_node_t *node)
{
static char tab_space[10 * sizeof(CWMP_MXML_TAB_SPACE) + 1];
int count = 0;
memset(tab_space, 0, sizeof(tab_space));
while ((node = mxmlGetParent(node))) {
count = count + 1;
}
if (count) {
snprintf(tab_space, sizeof(tab_space), "%*s", (int)(count * sizeof(CWMP_MXML_TAB_SPACE)), "");
}
return tab_space;
}
const char *whitespace_cb(mxml_node_t *node, int where __attribute__((unused)))
{
if (mxmlGetType(node) != MXML_ELEMENT)
return NULL;
switch (where) {
case MXML_WS_BEFORE_CLOSE:
if (mxmlGetFirstChild(node) && mxmlGetType(mxmlGetFirstChild(node)) != MXML_ELEMENT)
return NULL;
return get_node_tab_space(node);
case MXML_WS_BEFORE_OPEN:
if (where == MXML_WS_BEFORE_CLOSE && mxmlGetFirstChild(node) && mxmlGetType(mxmlGetFirstChild(node)) != MXML_ELEMENT)
return NULL;
return get_node_tab_space(node);
case MXML_WS_AFTER_OPEN:
return ((mxmlGetFirstChild(node) == NULL || mxmlGetType(mxmlGetFirstChild(node)) == MXML_ELEMENT) ? "\n" : NULL);
case MXML_WS_AFTER_CLOSE:
return "\n";
default:
return NULL;
}
return NULL;
}
char *xml_get_cwmp_version(int version)
{
static char versions[60];
unsigned pos = 0;
int k;
versions[0] = '\0';
for (k = 0; k < version; k++) {
pos += snprintf(&versions[pos], sizeof(versions) - pos, "1.%d, ", k);
}
if (pos)
versions[pos - 2] = 0;
return versions;
}
static int xml_prepare_lwnotifications(mxml_node_t *parameter_list)
{
mxml_node_t *b, *n;
struct list_head *p;
struct cwmp_dm_parameter *lw_notification;
list_for_each (p, &list_lw_value_change) {
lw_notification = list_entry(p, struct cwmp_dm_parameter, list);
n = mxmlNewElement(parameter_list, "Param");
if (!n)
goto error;
b = mxmlNewElement(n, "Name");
if (!b)
goto error;
b = mxmlNewOpaque(b, lw_notification->name);
if (!b)
goto error;
b = mxmlNewElement(n, "Value");
if (!b)
goto error;
#ifdef ACS_MULTI
mxmlElementSetAttr(b, "xsi:type", lw_notification->type);
#endif
b = mxmlNewOpaque(b, lw_notification->value);
if (!b)
goto error;
}
return 0;
error:
return -1;
}
int xml_prepare_lwnotification_message(char **msg_out)
{
mxml_node_t *lw_tree;
load_notification_xml_schema(&lw_tree);
if (!lw_tree)
goto error;
*msg_out = mxmlSaveAllocString(lw_tree, whitespace_cb);
mxmlDelete(lw_tree);
return 0;
error:
return -1;
}
void load_notification_xml_schema(mxml_node_t **tree)
{
char declaration[1024] = {0};
struct cwmp *cwmp = &cwmp_main;
struct config *conf;
conf = &(cwmp->conf);
char *c = NULL;
if (tree == NULL)
return;
*tree = NULL;
snprintf(declaration, sizeof(declaration), "?xml version=\"1.0\" encoding=\"UTF-8\"?");
mxml_node_t *xml = mxmlNewElement(NULL, declaration);
if (xml == NULL)
return;
mxml_node_t *notification = mxmlNewElement(xml, "Notification");
if (notification == NULL) {
MXML_DELETE(xml);
return;
}
mxmlElementSetAttr(notification, "xmlns", "urn:broadband-forum-org:cwmp:lwnotif-1-0");
mxmlElementSetAttr(notification, "xmlns:xs", xsd_url);
mxmlElementSetAttr(notification, "xmlns:xsi", xsi_url);
mxmlElementSetAttr(notification, "xsi:schemaLocation", "urn:broadband-forum-org:cwmp:lxnotif-1-0 http://www.broadband-forum.org/cwmp/cwmp-UDPLightweightNotification-1-0.xsd");
mxml_node_t *ts = mxmlNewElement(notification, "TS");
if (ts == NULL) {
MXML_DELETE(xml);
return;
}
if (cwmp_asprintf(&c, "%ld", time(NULL)) == -1) {
MXML_DELETE(xml);
return;
}
if (NULL == mxmlNewOpaque(ts, c)) {
FREE(c);
MXML_DELETE(xml);
return;
}
FREE(c);
mxml_node_t *un = mxmlNewElement(notification, "UN");
if (un == NULL) {
MXML_DELETE(xml);
return;
}
if (NULL == mxmlNewOpaque(un, conf->acs_userid)) {
MXML_DELETE(xml);
return;
}
mxml_node_t *cn = mxmlNewElement(notification, "CN");
if (cn == NULL) {
MXML_DELETE(xml);
return;
}
c = (char *)calculate_lwnotification_cnonce();
if (!c) {
MXML_DELETE(xml);
return;
}
if (NULL == mxmlNewOpaque(cn, c)) {
FREE(c);
MXML_DELETE(xml);
return;
}
FREE(c);
mxml_node_t *oui = mxmlNewElement(notification, "OUI");
if (oui == NULL) {
MXML_DELETE(xml);
return;
}
if (NULL == mxmlNewOpaque(oui, cwmp->deviceid.oui)) {
MXML_DELETE(xml);
return;
}
mxml_node_t *pclass = mxmlNewElement(notification, "ProductClass");
if (pclass == NULL) {
MXML_DELETE(xml);
return;
}
if (NULL == mxmlNewOpaque(pclass, cwmp->deviceid.productclass ? cwmp->deviceid.productclass : "")) {
MXML_DELETE(xml);
return;
}
mxml_node_t *slno = mxmlNewElement(notification, "SerialNumber");
if (slno == NULL) {
MXML_DELETE(xml);
return;
}
if (NULL == mxmlNewOpaque(slno, cwmp->deviceid.serialnumber ? cwmp->deviceid.serialnumber : "")) {
MXML_DELETE(xml);
return;
}
if (xml_prepare_lwnotifications(notification)) {
MXML_DELETE(xml);
return;
}
*tree = xml;
}
void load_response_xml_schema(mxml_node_t **schema)
{
char declaration[1024] = {0};
if (schema == NULL)
return;
*schema = NULL;
snprintf(declaration, sizeof(declaration), "?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?");
mxml_node_t *xml = mxmlNewElement(NULL, declaration);
if (xml == NULL)
return;
mxml_node_t *envlp = mxmlNewElement(xml, "soap_env:Envelope");
if (envlp == NULL) {
MXML_DELETE(xml);
return;
}
mxmlElementSetAttr(envlp, "xmlns:soap_env", soap_env_url);
mxmlElementSetAttr(envlp, "xmlns:soap_enc", soap_enc_url);
mxmlElementSetAttr(envlp, "xmlns:xsd", xsd_url);
mxmlElementSetAttr(envlp, "xmlns:xsi", xsi_url);
mxml_node_t *header = mxmlNewElement(envlp, "soap_env:Header");
if (header == NULL) {
MXML_DELETE(xml);
return;
}
mxml_node_t *id = mxmlNewElement(header, "cwmp:ID");
if (id == NULL) {
MXML_DELETE(xml);
return;
}
mxmlElementSetAttr(id, "soap_env:mustUnderstand", "1");
if (NULL == mxmlNewElement(envlp, "soap_env:Body")) {
MXML_DELETE(xml);
return;
}
*schema = xml;
}