Make icwmp compiling under x86

This commit is contained in:
Omar Kallel 2021-01-18 10:20:10 +01:00
parent 4a4a8a4844
commit fc7687de2d
10 changed files with 144 additions and 93 deletions

View file

@ -169,3 +169,25 @@ void cwmp_free_all_list_param_value(struct list_head *list_param_value)
cwmp_del_list_param_value(param_value);
}
}
int cwmp_asprintf(char **s, const char *format, ...)
{
int size;
char *str = NULL;
va_list arg, argcopy;
va_start(arg,format);
va_copy(argcopy, arg);
size = vsnprintf(NULL, 0, format, argcopy);
if (size < 0)
return -1;
va_end(argcopy);
str = (char *)calloc(sizeof(char), size+1);
vsnprintf(str, size+1, format, arg);
va_end(arg);
*s = strdup(str);
FREE(str);
if (*s == NULL)
return -1;
return 0;
}

36
cwmp.c
View file

@ -457,9 +457,9 @@ int cwmp_init(int argc, char **argv, struct cwmp *cwmp)
return error;
/* Only One instance should run*/
cwmp->pid_file = open("/var/run/icwmpd.pid", O_CREAT | O_RDWR, 0666);
fcntl(cwmp->pid_file, F_SETFD, fcntl(cwmp->pid_file, F_GETFD) | FD_CLOEXEC);
int rc = flock(cwmp->pid_file, LOCK_EX | LOCK_NB);
cwmp->pid_file = fopen("/var/run/icwmpd.pid", "w+");
fcntl(fileno(cwmp->pid_file), F_SETFD, fcntl(fileno(cwmp->pid_file), F_GETFD) | FD_CLOEXEC);
int rc = flock(fileno(cwmp->pid_file), LOCK_EX | LOCK_NB);
if (rc) {
if (EWOULDBLOCK != errno) {
char *piderr = "PID file creation failed: Quit the daemon!";
@ -544,43 +544,53 @@ int main(int argc, char **argv)
sigaction(SIGTERM, &act, 0);
error = pthread_create(&http_cr_server_thread, NULL, &thread_http_cr_server_listen, NULL);
if (error < 0)
if (error < 0) {
CWMP_LOG(ERROR, "Error when creating the http connection request server thread!");
}
error = pthread_create(&ubus_thread, NULL, &thread_uloop_run, NULL);
if (error < 0)
if (error < 0) {
CWMP_LOG(ERROR, "Error when creating the ubus thread!");
}
error = pthread_create(&periodic_event_thread, NULL, &thread_event_periodic, (void *)cwmp);
if (error < 0)
if (error < 0) {
CWMP_LOG(ERROR, "Error when creating the periodic event thread!");
}
error = pthread_create(&periodic_check_notify, NULL, &thread_periodic_check_notify, (void *)cwmp);
if (error < 0)
if (error < 0) {
CWMP_LOG(ERROR, "Error when creating the download thread!");
}
error = pthread_create(&scheduleInform_thread, NULL, &thread_cwmp_rpc_cpe_scheduleInform, (void *)cwmp);
if (error < 0)
if (error < 0) {
CWMP_LOG(ERROR, "Error when creating the scheduled inform thread!");
}
error = pthread_create(&download_thread, NULL, &thread_cwmp_rpc_cpe_download, (void *)cwmp);
if (error < 0)
if (error < 0) {
CWMP_LOG(ERROR, "Error when creating the download thread!");
}
error = pthread_create(&change_du_state_thread, NULL, &thread_cwmp_rpc_cpe_change_du_state, (void *)cwmp);
if (error < 0)
if (error < 0) {
CWMP_LOG(ERROR, "Error when creating the state change thread!");
}
error = pthread_create(&schedule_download_thread, NULL, &thread_cwmp_rpc_cpe_schedule_download, (void *)cwmp);
if (error < 0)
if (error < 0) {
CWMP_LOG(ERROR, "Error when creating the schedule download thread!");
}
error = pthread_create(&apply_schedule_download_thread, NULL, &thread_cwmp_rpc_cpe_apply_schedule_download, (void *)cwmp);
if (error < 0)
if (error < 0) {
CWMP_LOG(ERROR, "Error when creating the schedule download thread!");
}
error = pthread_create(&upload_thread, NULL, &thread_cwmp_rpc_cpe_upload, (void *)cwmp);
if (error < 0)
if (error < 0) {
CWMP_LOG(ERROR, "Error when creating the download thread!");
}
cwmp_schedule_session(cwmp);

View file

@ -15,6 +15,7 @@
#include <unistd.h>
#include <sys/wait.h>
#include <signal.h>
#include <stdio.h>
#include "external.h"
#include "xml.h"
@ -72,7 +73,8 @@ void external_fetch_uninstall_fault_resp(char **fault)
external_MethodFault = NULL;
}
void external_du_change_state_fault_resp(char *fault_code, char *version, char *name, char *uuid, char *env)
void external_du_change_state_fault_resp(char *fault_code, char *version,
char *name, char *uuid, char *env)
{
FREE(external_MethodFault);
external_MethodFault = fault_code ? strdup(fault_code) : NULL;
@ -86,7 +88,8 @@ void external_du_change_state_fault_resp(char *fault_code, char *version, char *
external_MethodENV = env ? strdup(env) : NULL;
}
void external_fetch_du_change_state_fault_resp(char **fault, char **version, char **name, char **uuid, char **env)
void external_fetch_du_change_state_fault_resp(char **fault, char **version,
char **name, char **uuid, char **env)
{
*fault = external_MethodFault;
external_MethodFault = NULL;
@ -102,7 +105,7 @@ void external_fetch_du_change_state_fault_resp(char **fault, char **version, cha
static void external_read_pipe_input(int (*external_handler)(char *msg))
{
char buf[1], *value = NULL, *c = NULL;
struct pollfd fd = {.fd = pfds_in[0], .events = POLLIN };
struct pollfd fd = {.fd = pfds_in[0], .events = POLLIN};
while (1) {
poll(&fd, 1, 500000);
if (!(fd.revents & POLLIN))
@ -111,9 +114,9 @@ static void external_read_pipe_input(int (*external_handler)(char *msg))
break;
if (buf[0] != '\n') {
if (value)
asprintf(&c, "%s%c", value, buf[0]);
cwmp_asprintf(&c, "%s%c", value, buf[0]);
else
asprintf(&c, "%c", buf[0]);
cwmp_asprintf(&c, "%c", buf[0]);
FREE(value);
value = c;
@ -135,7 +138,7 @@ static void external_write_pipe_output(const char *msg)
{
char *value = NULL;
asprintf(&value, "%s\n", msg);
cwmp_asprintf(&value, "%s\n", msg);
if (write(pfds_out[1], value, strlen(value)) == -1) {
CWMP_LOG(ERROR, "Error occured when trying to write to the pipe");
}
@ -176,7 +179,7 @@ void external_init()
argv[i++] = fc_script;
argv[i++] = "json_continuous_input";
argv[i++] = NULL;
execvp(argv[0], (char **)argv);
execvp(argv[0], (char**)argv);
close(pfds_out[0]);
close(pfds_in[1]);
@ -195,7 +198,7 @@ void external_init()
DD(INFO, "icwmp script is listening");
return;
error:
error:
CWMP_LOG(ERROR, "icwmp script intialization failed");
exit(EXIT_FAILURE);
}
@ -256,7 +259,8 @@ int external_simple(char *command, char *arg, int c)
return 0;
}
int external_download(char *url, char *size, char *type, char *user, char *pass, time_t c)
int external_download(char *url, char *size, char *type, char *user, char *pass,
time_t c)
{
DD(INFO, "executing download url '%s'", url);
char *id = NULL;
@ -266,16 +270,17 @@ int external_download(char *url, char *size, char *type, char *user, char *pass,
struct cwmp *cwmp = &cwmp_main;
conf = &(cwmp->conf);
if (strncmp(url, DOWNLOAD_PROTOCOL_HTTPS, strlen(DOWNLOAD_PROTOCOL_HTTPS)) == 0) {
if (strncmp(url, DOWNLOAD_PROTOCOL_HTTPS,
strlen(DOWNLOAD_PROTOCOL_HTTPS)) == 0) {
if (conf->https_ssl_capath)
cert_path = strdup(conf->https_ssl_capath);
else
cert_path = NULL;
}
if (cert_path)
CWMP_LOG(DEBUG, "https certif path %s", cert_path);
if (c)
asprintf(&id, "%ld", c);
CWMP_LOG(DEBUG, "https certif path %s", cert_path)
if (c)
cwmp_asprintf(&id, "%ld", c);
/* send data to the script */
json_obj_out = json_object_new_object();
@ -327,7 +332,8 @@ int external_upload(char *url, char *type, char *user, char *pass, char *name)
return 0;
}
int external_change_du_state_install(char *url, char *uuid, char *user, char *pass, char *env)
int external_change_du_state_install(char *url, char *uuid, char *user,
char *pass, char *env)
{
DD(INFO, "executing DU install");
json_object *json_obj_out;
@ -353,7 +359,8 @@ int external_change_du_state_install(char *url, char *uuid, char *user, char *pa
return 0;
}
int external_change_du_state_update(char *uuid, char *url, char *user, char *pass)
int external_change_du_state_update(char *uuid, char *url, char *user,
char *pass)
{
DD(INFO, "executing DU update");
json_object *json_obj_out;
@ -404,7 +411,7 @@ int external_apply(char *action, char *arg, time_t c)
char *id = NULL;
if (c)
asprintf(&id, "%ld", c);
cwmp_asprintf(&id, "%ld", c);
/* send data to the script */
json_obj_out = json_object_new_object();

10
http.c
View file

@ -50,19 +50,19 @@ int http_client_init(struct cwmp *cwmp)
if (dhcp_dis && cwmp->retry_count_session > 0 && strcmp(dhcp_dis, "enable") == 0) {
uci_get_state_value(UCI_DHCP_ACS_URL, &acs_var_stat);
if (acs_var_stat) {
if (asprintf(&http_c.url, "%s", acs_var_stat) == -1) {
if (cwmp_asprintf(&http_c.url, "%s", acs_var_stat) == -1) {
free(acs_var_stat);
free(dhcp_dis);
return -1;
}
} else {
if (asprintf(&http_c.url, "%s", cwmp->conf.acsurl) == -1) {
if (cwmp_asprintf(&http_c.url, "%s", cwmp->conf.acsurl) == -1) {
free(dhcp_dis);
return -1;
}
}
} else {
if (asprintf(&http_c.url, "%s", cwmp->conf.acsurl) == -1) {
if (cwmp_asprintf(&http_c.url, "%s", cwmp->conf.acsurl) == -1) {
if (dhcp_dis)
free(dhcp_dis);
return -1;
@ -90,7 +90,7 @@ int http_client_init(struct cwmp *cwmp)
curl_easy_perform(curl);
int tmp = inet_pton(AF_INET, ip, buf);
asprintf(&uci_cmd, "cwmp.acs.ip_version=%d", (tmp == 1) ? 4 : 6);
cwmp_asprintf(&uci_cmd, "cwmp.acs.ip_version=%d", (tmp == 1) ? 4 : 6);
uci_set_value(uci_cmd);
free(uci_cmd);
}
@ -115,7 +115,7 @@ static size_t http_get_response(void *buffer, size_t size, size_t rxed, char **m
{
char *c;
if (asprintf(&c, "%s%.*s", *msg_in, (int)(size * rxed), (char *)buffer) == -1) {
if (cwmp_asprintf(&c, "%s%.*s", *msg_in, (int)(size * rxed), (char *)buffer) == -1) {
FREE(*msg_in);
return -1;
}

View file

@ -14,6 +14,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <stdbool.h>
#include <libubox/list.h>
#include <sys/time.h>
@ -125,7 +126,7 @@ typedef struct cwmp {
int count_handle_notify;
int retry_count_session;
struct list_head *head_event_container;
int pid_file;
FILE* pid_file;
time_t start_time;
struct session_status session_status;
unsigned int cwmp_id;
@ -447,6 +448,7 @@ void cwmp_del_list_fault_param(struct cwmp_param_fault *param_fault);
void cwmp_add_list_param_value(char *param, char *value, struct list_head *list_param_value);
void cwmp_del_list_param_value(struct cwmp_param_value *param_value);
void cwmp_free_all_list_param_value(struct list_head *list_param_value);
int cwmp_asprintf(char **s, const char *format, ...);
#ifndef FREE
#define FREE(x) \

4
log.c
View file

@ -106,7 +106,7 @@ void puts_log(int severity, const char *fmt, ...)
FILE *pLog = NULL;
struct stat st;
long int size = 0;
char log_file_name_bak[256];
char log_file_name_bak[258];
char buf[1024];
char buf_file[1024];
@ -169,7 +169,7 @@ void puts_log_xmlmsg(int severity, char *msg, int msgtype)
FILE *pLog = NULL;
struct stat st;
long int size = 0;
char log_file_name_bak[256];
char log_file_name_bak[258];
char buf[1024];
char *description, *separator;

View file

@ -122,7 +122,7 @@ static void freecwmp_netlink_interface(struct nlmsghdr *nlh)
if (cwmp_main.conf.ip)
FREE(cwmp_main.conf.ip);
cwmp_main.conf.ip = strdup(if_addr);
if (asprintf(&c, "cwmp.cpe.ip=%s", cwmp_main.conf.ip) != -1) {
if (cwmp_asprintf(&c, "cwmp.cpe.ip=%s", cwmp_main.conf.ip) != -1) {
uci_set_state_value(c);
free(c);
}
@ -144,7 +144,7 @@ static void freecwmp_netlink_interface(struct nlmsghdr *nlh)
if (cwmp_main.conf.ipv6)
FREE(cwmp_main.conf.ipv6);
cwmp_main.conf.ipv6 = strdup(pradd_v6);
if (asprintf(&c, "cwmp.cpe.ipv6=%s", cwmp_main.conf.ipv6) != -1) {
if (cwmp_asprintf(&c, "cwmp.cpe.ipv6=%s", cwmp_main.conf.ipv6) != -1) {
uci_set_state_value(c);
free(c);
}

View file

@ -230,7 +230,7 @@ static void udplw_server_param(struct addrinfo **res)
conf = &(cwmp->conf);
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_DGRAM;
asprintf(&port, "%d", conf->lw_notification_port);
cwmp_asprintf(&port, "%d", conf->lw_notification_port);
getaddrinfo(conf->lw_notification_hostname, port, &hints, res);
//FREE(port);
}
@ -306,7 +306,7 @@ void cwmp_lwnotification()
udplw_server_param(&servaddr);
xml_prepare_lwnotification_message(&msg_out);
message_compute_signature(msg_out, signature);
asprintf(&msg, "%s \n %s: %s \n %s: %s \n %s: %zd\n %s: %s\n\n%s", "POST /HTTPS/1.1", "HOST", conf->lw_notification_hostname, "Content-Type", "test/xml; charset=utf-8", "Content-Lenght", strlen(msg_out), "Signature", signature, msg_out);
cwmp_asprintf(&msg, "%s \n %s: %s \n %s: %s \n %s: %zd\n %s: %s\n\n%s", "POST /HTTPS/1.1", "HOST", conf->lw_notification_hostname, "Content-Type", "test/xml; charset=utf-8", "Content-Lenght", strlen(msg_out), "Signature", signature, msg_out);
send_udp_message(servaddr, msg);
free_all_list_lw_notify();

19
ubus.c
View file

@ -71,7 +71,7 @@ static int cwmp_handle_command(struct ubus_context *ctx, struct ubus_object *obj
CWMP_LOG(INFO, "triggered ubus reload_end_session");
cwmp_set_end_session(END_SESSION_RELOAD);
blobmsg_add_u32(&b, "status", 0);
if (asprintf(&info, "icwmpd config will reload at the end of the session") == -1)
if (cwmp_asprintf(&info, "icwmpd config will reload at the end of the session") == -1)
return -1;
} else if (!strcmp("reload", cmd)) {
CWMP_LOG(INFO, "triggered ubus reload");
@ -84,34 +84,34 @@ static int cwmp_handle_command(struct ubus_context *ctx, struct ubus_object *obj
cwmp_apply_acs_changes();
pthread_mutex_unlock(&(cwmp_main.mutex_session_queue));
blobmsg_add_u32(&b, "status", 0);
if (asprintf(&info, "icwmpd config reloaded") == -1)
if (cwmp_asprintf(&info, "icwmpd config reloaded") == -1)
return -1;
}
} else if (!strcmp("reboot_end_session", cmd)) {
CWMP_LOG(INFO, "triggered ubus reboot_end_session");
cwmp_set_end_session(END_SESSION_REBOOT);
blobmsg_add_u32(&b, "status", 0);
if (asprintf(&info, "icwmpd will reboot at the end of the session") == -1)
if (cwmp_asprintf(&info, "icwmpd will reboot at the end of the session") == -1)
return -1;
} else if (!strcmp("action_end_session", cmd)) {
CWMP_LOG(INFO, "triggered ubus action_end_session");
cwmp_set_end_session(END_SESSION_EXTERNAL_ACTION);
blobmsg_add_u32(&b, "status", 0);
if (asprintf(&info, "icwmpd will execute the scheduled action commands at the end of the session") == -1)
if (cwmp_asprintf(&info, "icwmpd will execute the scheduled action commands at the end of the session") == -1)
return -1;
} else if (!strcmp("exit", cmd)) {
pthread_t exit_thread;
int error;
CWMP_LOG(INFO, "triggered ubus exit");
int rc = flock(cwmp_main.pid_file, LOCK_UN | LOCK_NB);
close(cwmp_main.pid_file);
int rc = flock(fileno(cwmp_main.pid_file), LOCK_UN | LOCK_NB);
fclose(cwmp_main.pid_file);
if (rc) {
char *piderr = "PID file unlock failed!";
fprintf(stderr, "%s\n", piderr);
CWMP_LOG(ERROR, "%s", piderr);
}
blobmsg_add_u32(&b, "status", 0);
if (asprintf(&info, "icwmpd daemon stopped") == -1)
if (cwmp_asprintf(&info, "icwmpd daemon stopped") == -1)
return -1;
blobmsg_add_string(&b, "info", info);
free(info);
@ -119,7 +119,8 @@ static int cwmp_handle_command(struct ubus_context *ctx, struct ubus_object *obj
ubus_send_reply(ctx, req, b.head);
blob_buf_free(&b);
close(cwmp_main.cr_socket_desc);
FILE *socke_file = fdopen(cwmp_main.cr_socket_desc, "r+");
fclose(socke_file);
CWMP_LOG(INFO, "Close connection request server socket");
error = pthread_create(&exit_thread, NULL, &thread_exit_program, NULL);
if (error < 0) {
@ -130,7 +131,7 @@ static int cwmp_handle_command(struct ubus_context *ctx, struct ubus_object *obj
} else {
blobmsg_add_u32(&b, "status", -1);
if (asprintf(&info, "%s command is not supported", cmd) == -1)
if (cwmp_asprintf(&info, "%s command is not supported", cmd) == -1)
return -1;
}

95
xml.c
View file

@ -269,7 +269,7 @@ int xml_send_message(struct cwmp *cwmp, struct session *session, struct rpc *rpc
/* get NoMoreRequests or HolRequest*/
session->hold_request = false;
if (asprintf(&c, "%s:%s", ns.cwmp, "NoMoreRequests") == -1)
if (cwmp_asprintf(&c, "%s:%s", ns.cwmp, "NoMoreRequests") == -1)
goto error;
b = mxmlFindElement(session->tree_in, session->tree_in, c, NULL, NULL, MXML_DESCEND);
FREE(c);
@ -278,7 +278,7 @@ int xml_send_message(struct cwmp *cwmp, struct session *session, struct rpc *rpc
if (b && b->type == MXML_OPAQUE && b->value.opaque)
session->hold_request = atoi(b->value.opaque);
} else {
if (asprintf(&c, "%s:%s", ns.cwmp, "HoldRequests") == -1)
if (cwmp_asprintf(&c, "%s:%s", ns.cwmp, "HoldRequests") == -1)
goto error;
b = mxmlFindElement(session->tree_in, session->tree_in, c, NULL, NULL, MXML_DESCEND);
@ -332,7 +332,7 @@ int xml_set_cwmp_id(struct session *session)
mxml_node_t *b;
/* define cwmp id */
if (asprintf(&c, "%u", ++(cwmp_main.cwmp_id)) == -1)
if (cwmp_asprintf(&c, "%u", ++(cwmp_main.cwmp_id)) == -1)
return -1;
b = mxmlFindElement(session->tree_out, session->tree_out, "cwmp:ID", NULL, NULL, MXML_DESCEND);
@ -353,7 +353,7 @@ int xml_set_cwmp_id_rpc_cpe(struct session *session)
mxml_node_t *b;
/* handle cwmp:ID */
if (asprintf(&c, "%s:%s", ns.cwmp, "ID") == -1)
if (cwmp_asprintf(&c, "%s:%s", ns.cwmp, "ID") == -1)
return -1;
b = mxmlFindElement(session->tree_in, session->tree_in, c, NULL, NULL, MXML_DESCEND);
@ -394,7 +394,7 @@ int xml_handle_message(struct session *session)
/* get method */
if (asprintf(&c, "%s:%s", ns.soap_env, "Body") == -1) {
if (cwmp_asprintf(&c, "%s:%s", ns.soap_env, "Body") == -1) {
CWMP_LOG(INFO, "Internal error");
session->fault_code = FAULT_CPE_INTERNAL_ERROR;
goto fault;
@ -534,7 +534,7 @@ static int xml_prepare_events_inform(struct session *session, mxml_node_t *tree)
n++;
}
if (n) {
if (asprintf(&c, "cwmp:EventStruct[%u]", n) == -1)
if (cwmp_asprintf(&c, "cwmp:EventStruct[%u]", n) == -1)
return -1;
mxmlElementSetAttr(b1, "xsi:type", "soap_enc:Array");
mxmlElementSetAttr(b1, "soap_enc:arrayType", c);
@ -649,7 +649,7 @@ int xml_prepare_lwnotification_message(char **msg_out)
if (!b)
goto error;
if (asprintf(&c, "%ld", time(NULL)) == -1)
if (cwmp_asprintf(&c, "%ld", time(NULL)) == -1)
goto error;
b = mxmlNewOpaque(b, c);
free(c);
@ -716,7 +716,7 @@ error:
char *xml_get_cwmp_version(int version)
{
int k;
char tmp[10] = "";
char tmp[15] = "";
static char versions[60] = "";
versions[0] = '\0';
@ -863,7 +863,7 @@ int cwmp_rpc_acs_prepare_message_inform(struct cwmp *cwmp, struct session *sessi
}
FREE_JSON(parameters);
}
if (asprintf(&c, "cwmp:ParameterValueStruct[%d]", size) == -1)
if (cwmp_asprintf(&c, "cwmp:ParameterValueStruct[%d]", size) == -1)
goto error;
mxmlElementSetAttr(parameter_list, "xsi:type", "soap_enc:Array");
@ -1248,9 +1248,12 @@ int cwmp_handle_rpc_cpe_get_parameter_values(struct session *session, struct rpc
{
mxml_node_t *n, *parameter_list, *b;
char *parameter_name = NULL;
char *c = NULL;
int counter = 0, fault_code = FAULT_CPE_INTERNAL_ERROR;
struct json_object *parameters = NULL, *param_obj = NULL, *param_name = NULL, *param_value = NULL, *param_type = NULL;
struct json_object *parameters = NULL, *param_obj = NULL, *param_name = NULL, *param_value = NULL;
#ifdef ACS_MULTI
char *c = NULL;
struct json_object *param_type = NULL;
#endif
b = session->body_in;
n = mxmlFindElement(session->tree_out, session->tree_out, "soap_env:Body", NULL, NULL, MXML_DESCEND);
@ -1326,7 +1329,7 @@ int cwmp_handle_rpc_cpe_get_parameter_values(struct session *session, struct rpc
if (!b)
goto fault;
if (asprintf(&c, "cwmp:ParameterValueStruct[%d]", counter) == -1)
if (cwmp_asprintf(&c, "cwmp:ParameterValueStruct[%d]", counter) == -1)
goto fault;
mxmlElementSetAttr(b, "soap_enc:arrayType", c);
@ -1352,10 +1355,11 @@ int cwmp_handle_rpc_cpe_get_parameter_names(struct session *session, struct rpc
mxml_node_t *n, *parameter_list, *b = session->body_in;
char *parameter_name = NULL;
char *NextLevel = NULL;
char *c;
int counter = 0, fault_code = FAULT_CPE_INTERNAL_ERROR;
struct json_object *parameters = NULL, *param_obj = NULL, *param_name = NULL, *writable = NULL;
#ifdef ACS_MULTI
char *c = NULL;
#endif
n = mxmlFindElement(session->tree_out, session->tree_out, "soap_env:Body", NULL, NULL, MXML_DESCEND);
if (!n)
goto fault;
@ -1426,7 +1430,7 @@ int cwmp_handle_rpc_cpe_get_parameter_names(struct session *session, struct rpc
if (!b)
goto fault;
if (asprintf(&c, "cwmp:ParameterInfoStruct[%d]", counter) == -1)
if (cwmp_asprintf(&c, "cwmp:ParameterInfoStruct[%d]", counter) == -1)
goto fault;
mxmlElementSetAttr(b, "soap_enc:arrayType", c);
@ -1453,10 +1457,11 @@ int cwmp_handle_rpc_cpe_get_parameter_attributes(struct session *session, struct
{
mxml_node_t *n, *parameter_list, *b;
char *parameter_name = NULL;
char *c = NULL;
int counter = 0, fault_code = FAULT_CPE_INTERNAL_ERROR;
struct json_object *parameters = NULL, *param_obj = NULL, *param_name = NULL, *notification = NULL;
#ifdef ACS_MULTI
char *c = NULL;
#endif
b = session->body_in;
n = mxmlFindElement(session->tree_out, session->tree_out, "soap_env:Body", NULL, NULL, MXML_DESCEND);
if (!n)
@ -1535,7 +1540,7 @@ int cwmp_handle_rpc_cpe_get_parameter_attributes(struct session *session, struct
if (!b)
goto fault;
if (asprintf(&c, "cwmp:ParameterAttributeStruct[%d]", counter) == -1)
if (cwmp_asprintf(&c, "cwmp:ParameterAttributeStruct[%d]", counter) == -1)
goto fault;
mxmlElementSetAttr(b, "soap_enc:arrayType", c);
@ -1611,7 +1616,7 @@ int cwmp_handle_rpc_cpe_set_parameter_values(struct session *session, struct rpc
v = (char *)mxmlGetOpaque(b);
if (!whitespace)
break;
asprintf(&c, "%s %s", parameter_value, v);
cwmp_asprintf(&c, "%s %s", parameter_value, v);
FREE(parameter_value);
parameter_value = strdup(c);
}
@ -1710,7 +1715,7 @@ int cwmp_handle_rpc_cpe_set_parameter_attributes(struct session *session, struct
int fault_code = FAULT_CPE_INTERNAL_ERROR;
/* handle cwmp:SetParameterAttributes */
if (asprintf(&c, "%s:%s", ns.cwmp, "SetParameterAttributes") == -1)
if (cwmp_asprintf(&c, "%s:%s", ns.cwmp, "SetParameterAttributes") == -1)
goto fault;
n = mxmlFindElement(session->tree_in, session->tree_in, c, NULL, NULL, MXML_DESCEND);
@ -1954,9 +1959,12 @@ error:
int cwmp_handle_rpc_cpe_get_rpc_methods(struct session *session, struct rpc *rpc)
{
mxml_node_t *n, *method_list, *b = session->body_in;
char *c = NULL;
mxml_node_t *n, *method_list;
int i, counter = 0;
#ifdef ACS_MULTI
mxml_node_t *b = session->body_in;
char *c = NULL;
#endif
n = mxmlFindElement(session->tree_out, session->tree_out, "soap_env:Body", NULL, NULL, MXML_DESCEND);
if (!n)
@ -1989,7 +1997,7 @@ int cwmp_handle_rpc_cpe_get_rpc_methods(struct session *session, struct rpc *rpc
goto fault;
mxmlElementSetAttr(b, "xsi:type", "soap_enc:Array");
if (asprintf(&c, "xsd:string[%d]", counter) == -1)
if (cwmp_asprintf(&c, "xsd:string[%d]", counter) == -1)
goto fault;
mxmlElementSetAttr(b, "soap_enc:arrayType", c);
@ -2474,7 +2482,7 @@ int lookup_vcf_name(char *instance, char **value)
json_object *parameters = NULL, *param_obj = NULL, *value_obj = NULL;
char *vcf_name_parameter = NULL;
asprintf(&vcf_name_parameter, "Device.DeviceInfo.VendorConfigFile.%s.Name", instance);
cwmp_asprintf(&vcf_name_parameter, "Device.DeviceInfo.VendorConfigFile.%s.Name", instance);
if (cwmp_get_parameter_values(vcf_name_parameter, &parameters) != NULL) {
FREE(vcf_name_parameter);
return -1;
@ -2608,8 +2616,9 @@ void *thread_cwmp_rpc_cpe_download(void *v)
}
free(fault_code);
if ((error == FAULT_CPE_NO_FAULT) && (pdownload->file_type[0] == '1' || pdownload->file_type[0] == '3' || pdownload->file_type[0] == '6')) {
if (pdownload->file_type[0] == '3')
if (pdownload->file_type[0] == '3') {
CWMP_LOG(INFO, "Download and apply new vendor config file is done successfully");
}
exit(EXIT_SUCCESS);
}
bkp_session_delete_transfer_complete(ptransfer_complete);
@ -3021,9 +3030,9 @@ static char *get_software_module_object_eq(char *param1, char *val1, char *param
json_object *swdu_get_obj = NULL;
if (!param2)
asprintf(&sw_parameter_name, "Device.SoftwareModules.DeploymentUnit.[%s==\\\"%s\\\"].", param1, val1);
cwmp_asprintf(&sw_parameter_name, "Device.SoftwareModules.DeploymentUnit.[%s==\\\"%s\\\"].", param1, val1);
else
asprintf(&sw_parameter_name, "Device.SoftwareModules.DeploymentUnit.[%s==\\\"%s\\\"&& %s==\\\"%s\\\"].", param1, val1, param2, val2);
cwmp_asprintf(&sw_parameter_name, "Device.SoftwareModules.DeploymentUnit.[%s==\\\"%s\\\"&& %s==\\\"%s\\\"].", param1, val1, param2, val2);
err = cwmp_get_parameter_values(sw_parameter_name, &swdu_get_obj);
if (err) {
FREE(sw_parameter_name);
@ -3059,9 +3068,9 @@ static int get_deployment_unit_name_version(char *uuid, char **name, char **vers
if (!sw_by_uuid_instance)
return 0;
asprintf(&name_param, "Device.SoftwareModules.DeploymentUnit.%s.Name", sw_by_uuid_instance);
asprintf(&version_param, "Device.SoftwareModules.DeploymentUnit.%s.Version", sw_by_uuid_instance);
asprintf(&environment_param, "Device.SoftwareModules.DeploymentUnit.%s.ExecutionEnvRef", sw_by_uuid_instance);
cwmp_asprintf(&name_param, "Device.SoftwareModules.DeploymentUnit.%s.Name", sw_by_uuid_instance);
cwmp_asprintf(&version_param, "Device.SoftwareModules.DeploymentUnit.%s.Version", sw_by_uuid_instance);
cwmp_asprintf(&environment_param, "Device.SoftwareModules.DeploymentUnit.%s.ExecutionEnvRef", sw_by_uuid_instance);
foreach_jsonobj_in_array(du_obj, arrobj)
{
@ -3097,7 +3106,7 @@ static char *get_softwaremodules_uuid(char *url)
if (!sw_by_url_instance)
return NULL;
asprintf(&uuid_param, "Device.SoftwareModules.DeploymentUnit.%s.UUID", sw_by_url_instance);
cwmp_asprintf(&uuid_param, "Device.SoftwareModules.DeploymentUnit.%s.UUID", sw_by_url_instance);
foreach_jsonobj_in_array(du_obj, arrobj)
{
@ -3125,7 +3134,7 @@ static char *get_softwaremodules_url(char *uuid)
if (!sw_by_uuid_instance)
return NULL;
asprintf(&url_param, "Device.SoftwareModules.DeploymentUnit.%s.URL", sw_by_uuid_instance);
cwmp_asprintf(&url_param, "Device.SoftwareModules.DeploymentUnit.%s.URL", sw_by_uuid_instance);
foreach_jsonobj_in_array(du_obj, arrobj)
{
@ -3153,7 +3162,7 @@ static char *get_deployment_unit_reference(char *package_name, char *package_env
return NULL;
FREE_JSON(arrobj);
asprintf(&deployment_unit_ref, "Device.SoftwareModules.DeploymentUnit.%s", sw_by_name_env_instance);
cwmp_asprintf(&deployment_unit_ref, "Device.SoftwareModules.DeploymentUnit.%s", sw_by_name_env_instance);
return deployment_unit_ref;
}
@ -3182,7 +3191,7 @@ static char *get_exec_env_name(char *environment_path)
return "";
}
asprintf(&env_param, "%sName", environment_path);
cwmp_asprintf(&env_param, "%sName", environment_path);
foreach_jsonobj_in_array(du_obj, sw_env_get_obj)
{
@ -3792,7 +3801,7 @@ int cwmp_handle_rpc_cpe_change_du_state(struct session *session, struct rpc *rpc
int error = FAULT_CPE_NO_FAULT;
char *c;
if (asprintf(&c, "%s:%s", ns.cwmp, "ChangeDUState") == -1) {
if (cwmp_asprintf(&c, "%s:%s", ns.cwmp, "ChangeDUState") == -1) {
error = FAULT_CPE_INTERNAL_ERROR;
goto fault;
}
@ -3925,7 +3934,7 @@ int cwmp_handle_rpc_cpe_download(struct session *session, struct rpc *rpc)
time_t scheduled_time = 0;
time_t download_delay = 0;
if (asprintf(&c, "%s:%s", ns.cwmp, "Download") == -1) {
if (cwmp_asprintf(&c, "%s:%s", ns.cwmp, "Download") == -1) {
error = FAULT_CPE_INTERNAL_ERROR;
goto fault;
}
@ -3953,7 +3962,7 @@ int cwmp_handle_rpc_cpe_download(struct session *session, struct rpc *rpc)
file_type = strdup(b->value.opaque);
} else {
tmp = file_type;
if (asprintf(&file_type, "%s %s", tmp, b->value.opaque) == -1) {
if (cwmp_asprintf(&file_type, "%s %s", tmp, b->value.opaque) == -1) {
error = FAULT_CPE_INTERNAL_ERROR;
goto fault;
}
@ -4078,7 +4087,7 @@ int cwmp_handle_rpc_cpe_schedule_download(struct session *session, struct rpc *r
struct schedule_download *schedule_download = NULL;
time_t schedule_download_delay[4] = { 0, 0, 0, 0 };
if (asprintf(&c, "%s:%s", ns.cwmp, "ScheduleDownload") == -1) {
if (cwmp_asprintf(&c, "%s:%s", ns.cwmp, "ScheduleDownload") == -1) {
error = FAULT_CPE_INTERNAL_ERROR;
goto fault;
}
@ -4107,7 +4116,7 @@ int cwmp_handle_rpc_cpe_schedule_download(struct session *session, struct rpc *r
file_type = strdup(b->value.opaque);
} else {
tmp = file_type;
if (asprintf(&file_type, "%s %s", tmp, b->value.opaque) == -1) {
if (cwmp_asprintf(&file_type, "%s %s", tmp, b->value.opaque) == -1) {
error = FAULT_CPE_INTERNAL_ERROR;
goto fault;
}
@ -4149,14 +4158,14 @@ int cwmp_handle_rpc_cpe_schedule_download(struct session *session, struct rpc *r
windowmode1 = strdup(t->value.opaque);
} else if (i == 0) {
tmp = windowmode0;
if (asprintf(&windowmode0, "%s %s", tmp, t->value.opaque) == -1) {
if (cwmp_asprintf(&windowmode0, "%s %s", tmp, t->value.opaque) == -1) {
error = FAULT_CPE_INTERNAL_ERROR;
goto fault;
}
FREE(tmp);
} else if (i == 1) {
tmp = windowmode1;
if (asprintf(&windowmode1, "%s %s", tmp, t->value.opaque) == -1) {
if (cwmp_asprintf(&windowmode1, "%s %s", tmp, t->value.opaque) == -1) {
error = FAULT_CPE_INTERNAL_ERROR;
goto fault;
}
@ -4253,7 +4262,7 @@ int cwmp_handle_rpc_cpe_upload(struct session *session, struct rpc *rpc)
time_t scheduled_time = 0;
time_t upload_delay = 0;
if (asprintf(&c, "%s:%s", ns.cwmp, "Upload") == -1) {
if (cwmp_asprintf(&c, "%s:%s", ns.cwmp, "Upload") == -1) {
error = FAULT_CPE_INTERNAL_ERROR;
goto fault;
}
@ -4280,7 +4289,7 @@ int cwmp_handle_rpc_cpe_upload(struct session *session, struct rpc *rpc)
file_type = strdup(b->value.opaque);
} else {
tmp = file_type;
if (asprintf(&file_type, "%s %s", tmp, b->value.opaque) == -1) {
if (cwmp_asprintf(&file_type, "%s %s", tmp, b->value.opaque) == -1) {
error = FAULT_CPE_INTERNAL_ERROR;
goto fault;
}