Revert ubus -s changes

This commit is contained in:
vdutta 2021-05-17 19:27:51 +05:30
parent bb8e30beb5
commit e6586067f9
7 changed files with 39 additions and 49 deletions

View file

@ -27,12 +27,11 @@ char *commandKey = NULL;
long int flashsize = 256000000;
static unsigned long int next_rand_seed = 1;
struct option cwmp_long_options[] = { { "boot-event", no_argument, NULL, 'b' }, { "get-rpc-methods", no_argument, NULL, 'g' }, { "command-input", no_argument, NULL, 'c' }, { "help", no_argument, NULL, 'h' }, { "version", no_argument, NULL, 'v' }, {"ubus_socket", required_argument, NULL, 's'}, { NULL, 0, NULL, 0 } };
struct option cwmp_long_options[] = { { "boot-event", no_argument, NULL, 'b' }, { "get-rpc-methods", no_argument, NULL, 'g' }, { "command-input", no_argument, NULL, 'c' }, { "help", no_argument, NULL, 'h' }, { "version", no_argument, NULL, 'v' }, { NULL, 0, NULL, 0 } };
static void show_help(void)
{
printf("Usage: icwmpd [OPTIONS]\n");
printf(" -s, --ubus_socket Ubus socket path for IPC\n");
printf(" -b, --boot-event (CWMP daemon) Start CWMP with BOOT event\n");
printf(" -g, --get-rpc-methods (CWMP daemon) Start CWMP with GetRPCMethods request to ACS\n");
printf(" -c, --cli CWMP CLI\n");
@ -49,11 +48,11 @@ static void show_version()
#endif
}
int global_env_init(int argc, char **argv, struct env *env, struct config *conf)
int global_env_init(int argc, char **argv, struct env *env)
{
int c, option_index = 0;
while ((c = getopt_long(argc, argv, "bgchvs:", cwmp_long_options, &option_index)) != -1) {
while ((c = getopt_long(argc, argv, "bgchv", cwmp_long_options, &option_index)) != -1) {
switch (c) {
case 'b':
env->boot = CWMP_START_BOOT;
@ -68,9 +67,7 @@ int global_env_init(int argc, char **argv, struct env *env, struct config *conf)
case 'h':
show_help();
exit(0);
case 's':
conf->ubus_socket = strdup(optarg);
break;
case 'v':
show_version();
exit(0);

View file

@ -10,13 +10,9 @@
* Author Omar Kallel <omar.kallel@pivasoftware.com>
*/
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include "config.h"
#include "cwmp_uci.h"
#include "log.h"
#include <time.h>
pthread_mutex_t mutex_config_load = PTHREAD_MUTEX_INITIALIZER;
@ -266,6 +262,18 @@ int get_global_config(struct config *conf)
return error;
}
if ((error = uci_get_value(UCI_CPE_UBUS_SOCKET_PATH, &value)) == CWMP_OK) {
if (value != NULL) {
if (conf->ubus_socket != NULL) {
free(conf->ubus_socket);
}
conf->ubus_socket = value;
value = NULL;
}
} else {
return error;
}
if ((error = uci_get_value(UCI_LOG_SEVERITY_PATH, &value)) == CWMP_OK) {
if (value != NULL) {
log_set_severity_idx(value);

8
cwmp.c
View file

@ -440,6 +440,8 @@ int cwmp_init(int argc, char **argv, struct cwmp *cwmp)
struct env env;
memset(&env, 0, sizeof(struct env));
if ((error = global_env_init(argc, argv, &env)))
return error;
/* Only One instance should run*/
cwmp->pid_file = fopen("/var/run/icwmpd.pid", "w+");
@ -455,10 +457,6 @@ int cwmp_init(int argc, char **argv, struct cwmp *cwmp)
exit(EXIT_SUCCESS);
}
if ((error = global_env_init(argc, argv, &env, &cwmp->conf)))
return error;
pthread_mutex_init(&cwmp->mutex_periodic, NULL);
pthread_mutex_init(&cwmp->mutex_session_queue, NULL);
pthread_mutex_init(&cwmp->mutex_session_send, NULL);
@ -514,8 +512,6 @@ int main(int argc, char **argv)
struct sigaction act = { 0 };
memset(&cwmp_main, 0, sizeof(struct cwmp));
if ((error = cwmp_init(argc, argv, cwmp)))
return error;

View file

@ -194,15 +194,12 @@ bool cwmp_transaction_status()
CWMP_LOG(INFO, "Transaction Status");
bool status = false;
int e = cwmp_ubus_call("usp.raw", "transaction_status", CWMP_UBUS_ARGS{ { "transaction_id", {.int_val = transaction_id }, UBUS_Integer } }, 1, ubus_transaction_status_callback, &status);
if (e != 0) {
CWMP_LOG(INFO, "Transaction status failed: Ubus err code: %d", e);
return false;
}
if (!status) {
if (!status)
CWMP_LOG(INFO, "Transaction with id: %d is not available anymore\n", transaction_id);
}
return status;
}
/*

View file

@ -446,7 +446,7 @@ int cwmp_exit(void);
void add_dm_parameter_to_list(struct list_head *head, char *param_name, char *param_data, char *param_type, int notification, bool writable);
void delete_dm_parameter_from_list(struct cwmp_dm_parameter *dm_parameter);
void cwmp_free_all_dm_parameter_list(struct list_head *list);
int global_env_init(int argc, char **argv, struct env *env, struct config *conf);
int global_env_init(int argc, char **argv, struct env *env);
void cwmp_add_list_fault_param(char *param, int fault, struct list_head *list_set_value_fault);
void cwmp_del_list_fault_param(struct cwmp_param_fault *param_fault);
void cwmp_free_all_list_param_fault(struct list_head *list_param_fault);

View file

@ -37,6 +37,7 @@
#define UCI_CPE_USERID_PATH "cwmp.cpe.userid"
#define UCI_CPE_PASSWD_PATH "cwmp.cpe.passwd"
#define UCI_CPE_INTERFACE_PATH "cwmp.cpe.interface"
#define UCI_CPE_UBUS_SOCKET_PATH "cwmp.cpe.ubus_socket"
#define UCI_CPE_PORT_PATH "cwmp.cpe.port"
#define UCI_CPE_DEFAULT_WAN_IFACE "cwmp.cpe.default_wan_interface"
#define UCI_CPE_CRPATH_PATH "cwmp.cpe.path"

45
ubus.c
View file

@ -50,15 +50,6 @@ void *thread_exit_program(void *v __attribute__((unused)))
exit(EXIT_SUCCESS);
}
static void add_kv_string_to_blob(struct blob_buf *bb, const char *key, const char *val)
{
if (val) {
blobmsg_add_string(bb, key, val);
} else {
blobmsg_add_string(bb, key, "");
}
}
static int cwmp_handle_command(struct ubus_context *ctx, struct ubus_object *obj __attribute__((unused)), struct ubus_request_data *req, const char *method __attribute__((unused)), struct blob_attr *msg)
{
struct blob_attr *tb[__COMMAND_MAX];
@ -119,7 +110,7 @@ static int cwmp_handle_command(struct ubus_context *ctx, struct ubus_object *obj
blobmsg_add_u32(&b, "status", 0);
if (cwmp_asprintf(&info, "icwmpd daemon stopped") == -1)
return -1;
add_kv_string_to_blob(&b, "info", info);
blobmsg_add_string(&b, "info", info);
free(info);
ubus_send_reply(ctx, req, b.head);
@ -141,7 +132,7 @@ static int cwmp_handle_command(struct ubus_context *ctx, struct ubus_object *obj
return -1;
}
add_kv_string_to_blob(&b, "info", info);
blobmsg_add_string(&b, "info", info);
free(info);
ubus_send_reply(ctx, req, b.head);
@ -176,22 +167,22 @@ static int cwmp_handle_status(struct ubus_context *ctx, struct ubus_object *obj
blob_buf_init(&b, 0);
c = blobmsg_open_table(&b, "cwmp");
add_kv_string_to_blob(&b, "status", "up");
add_kv_string_to_blob(&b, "start_time", mix_get_time_of(cwmp_main.start_time));
add_kv_string_to_blob(&b, "acs_url", cwmp_main.conf.acsurl);
blobmsg_add_string(&b, "status", "up");
blobmsg_add_string(&b, "start_time", mix_get_time_of(cwmp_main.start_time));
blobmsg_add_string(&b, "acs_url", cwmp_main.conf.acsurl);
blobmsg_close_table(&b, c);
c = blobmsg_open_table(&b, "last_session");
blobmsg_add_string(&b, "status", (cwmp_main.session_status.last_start_time ? arr_session_status[cwmp_main.session_status.last_status] : "N/A"));
blobmsg_add_string(&b, "start_time", (cwmp_main.session_status.last_start_time ? mix_get_time_of(cwmp_main.session_status.last_start_time) : "N/A"));
blobmsg_add_string(&b, "end_time", (cwmp_main.session_status.last_end_time ? mix_get_time_of(cwmp_main.session_status.last_end_time) : "N/A"));
blobmsg_add_string(&b, "status", cwmp_main.session_status.last_start_time ? arr_session_status[cwmp_main.session_status.last_status] : "N/A");
blobmsg_add_string(&b, "start_time", cwmp_main.session_status.last_start_time ? mix_get_time_of(cwmp_main.session_status.last_start_time) : "N/A");
blobmsg_add_string(&b, "end_time", cwmp_main.session_status.last_end_time ? mix_get_time_of(cwmp_main.session_status.last_end_time) : "N/A");
blobmsg_close_table(&b, c);
c = blobmsg_open_table(&b, "next_session");
blobmsg_add_string(&b, "status", arr_session_status[SESSION_WAITING]);
ntime = get_session_status_next_time();
blobmsg_add_string(&b, "start_time", (ntime ? mix_get_time_of(ntime) : "N/A"));
add_kv_string_to_blob(&b, "end_time", "N/A");
blobmsg_add_string(&b, "start_time", ntime ? mix_get_time_of(ntime) : "N/A");
blobmsg_add_string(&b, "end_time", "N/A");
blobmsg_close_table(&b, c);
c = blobmsg_open_table(&b, "statistics");
@ -251,7 +242,7 @@ static int cwmp_handle_inform(struct ubus_context *ctx, struct ubus_object *obj
pthread_mutex_unlock(&(cwmp_main.mutex_session_queue));
pthread_cond_signal(&(cwmp_main.threshold_session_send));
blobmsg_add_u32(&b, "status", 1);
add_kv_string_to_blob(&b, "info", "Session with GetRPCMethods will start");
blobmsg_add_string(&b, "info", "Session with GetRPCMethods will start");
} else {
int event_code = cwmp_get_int_event_code(event);
pthread_mutex_lock(&(cwmp_main.mutex_session_queue));
@ -260,10 +251,10 @@ static int cwmp_handle_inform(struct ubus_context *ctx, struct ubus_object *obj
pthread_cond_signal(&(cwmp_main.threshold_session_send));
if (cwmp_main.session_status.last_status == SESSION_RUNNING) {
blobmsg_add_u32(&b, "status", -1);
add_kv_string_to_blob(&b, "info", "Session already running, event will be sent at the end of the session");
blobmsg_add_string(&b, "info", "Session already running, event will be sent at the end of the session");
} else {
blobmsg_add_u32(&b, "status", 1);
add_kv_string_to_blob(&b, "info", "Session started");
blobmsg_add_string(&b, "info", "Session started");
}
}
ubus_send_reply(ctx, req, b.head);
@ -334,7 +325,7 @@ int cwmp_ubus_call(const char *obj, const char *method, const struct cwmp_ubus_a
blob_buf_init(&b, 0);
for (i = 0; i < u_args_size; i++) {
if (u_args[i].type == UBUS_String)
add_kv_string_to_blob(&b, u_args[i].key, u_args[i].val.str_val);
blobmsg_add_string(&b, u_args[i].key, u_args[i].val.str_val);
else if (u_args[i].type == UBUS_Integer) {
blobmsg_add_u32(&b, u_args[i].key, u_args[i].val.int_val);
} else if (u_args[i].type == UBUS_Array_Obj || u_args[i].type == UBUS_Array_Str) {
@ -346,7 +337,7 @@ int cwmp_ubus_call(const char *obj, const char *method, const struct cwmp_ubus_a
for (j = 0; j < ARRAY_MAX; j++) {
if (u_args[i].val.array_value[j].param_value.key == NULL || strlen(u_args[i].val.array_value[j].param_value.key) <= 0)
break;
add_kv_string_to_blob(&b, u_args[i].val.array_value[j].param_value.key, u_args[i].val.array_value[j].param_value.value);
blobmsg_add_string(&b, u_args[i].val.array_value[j].param_value.key, u_args[i].val.array_value[j].param_value.value);
}
blobmsg_close_table(&b, t);
}
@ -354,7 +345,7 @@ int cwmp_ubus_call(const char *obj, const char *method, const struct cwmp_ubus_a
for (j = 0; j < ARRAY_MAX; j++) {
if (u_args[i].val.array_value[j].str_value == NULL || strlen(u_args[i].val.array_value[j].str_value) <= 0)
break;
add_kv_string_to_blob(&b, NULL, u_args[i].val.array_value[j].str_value);
blobmsg_add_string(&b, NULL, u_args[i].val.array_value[j].str_value);
}
}
blobmsg_close_array(&b, a);
@ -366,8 +357,8 @@ int cwmp_ubus_call(const char *obj, const char *method, const struct cwmp_ubus_a
if (!param_value->name)
break;
t = blobmsg_open_table(&b, "");
add_kv_string_to_blob(&b, "path", param_value->name);
add_kv_string_to_blob(&b, "value", param_value->value);
blobmsg_add_string(&b, "path", param_value->name);
blobmsg_add_string(&b, "value", param_value->value);
blobmsg_close_table(&b, t);
}
blobmsg_close_array(&b, a);