remove the use of dm_enabled_notify file && other cleanup

This commit is contained in:
Omar Kallel 2020-12-17 12:16:04 +01:00
parent 2933c82ea8
commit e73024d706
9 changed files with 4 additions and 147 deletions

View file

@ -51,41 +51,11 @@ void del_list_parameter(struct dm_parameter *dm_parameter)
api_del_list_parameter(dm_parameter); api_del_list_parameter(dm_parameter);
} }
void dmjson_parse_init(char *msg)
{
bbf_api_dmjson_parse_init(msg);
}
void dmjson_parse_fini(void)
{
bbf_api_dmjson_parse_fini();
}
json_object *dmjson_select_obj(json_object * jobj, char *argv[])
{
return (bbf_api_dmjson_select_obj(jobj, argv));
}
void del_list_fault_param(struct param_fault *param_fault) void del_list_fault_param(struct param_fault *param_fault)
{ {
bbf_api_del_list_fault_param(param_fault); bbf_api_del_list_fault_param(param_fault);
} }
int copy_temporary_file_to_original_file(char *f1, char *f2)
{
return bbf_api_copy_temporary_file_to_original_file(f1, f2);
}
void dmjson_get_var(char *jkey, char **jval)
{
bbf_api_dmjson_get_var(jkey, jval);
}
void dmjson_get_string(char *jkey, char **jval)
{
bbf_api_dmjson_get_string(jkey, jval);
}
int get_dm_type(char *dm_str) int get_dm_type(char *dm_str)
{ {
if (dm_str == NULL) if (dm_str == NULL)

View file

@ -20,13 +20,7 @@ void bbf_uci_revert_bbfdm(void);
int set_bbfdatamodel_type(int bbf_type); int set_bbfdatamodel_type(int bbf_type);
int get_bbfdatamodel_type(void); int get_bbfdatamodel_type(void);
void del_list_parameter(struct dm_parameter *dm_parameter); void del_list_parameter(struct dm_parameter *dm_parameter);
void dmjson_parse_init(char *msg);
void dmjson_parse_fini(void);
json_object *dmjson_select_obj(json_object * jobj, char *argv[]);
void del_list_fault_param(struct param_fault *param_fault); void del_list_fault_param(struct param_fault *param_fault);
int copy_temporary_file_to_original_file(char *f1, char *f2);
void dmjson_get_var(char *jkey, char **jval);
void dmjson_get_string(char *jkey, char **jval);
void bbf_set_end_session_flag (struct dmctx *ctx, unsigned int flag); void bbf_set_end_session_flag (struct dmctx *ctx, unsigned int flag);
int bbfdmuci_lookup_ptr(struct uci_context *ctx, struct uci_ptr *ptr, char *package, char *section, char *option, char *value); int bbfdmuci_lookup_ptr(struct uci_context *ctx, struct uci_ptr *ptr, char *package, char *section, char *option, char *value);

View file

@ -321,15 +321,6 @@ int dm_entry_apply(struct dmctx *ctx, int cmd, char *arg1, char *arg2)
return usp_fault_map(fault); return usp_fault_map(fault);
} }
void del_list_enabled_notify(struct dm_enabled_notify *dm_enabled_notify)
{
list_del(&dm_enabled_notify->list); // Should be free and not dmfree
free(dm_enabled_notify->name);
free(dm_enabled_notify->value);
free(dm_enabled_notify->notification);
free(dm_enabled_notify);
}
int adm_entry_get_linker_param(struct dmctx *ctx, char *param, char *linker, char **value) int adm_entry_get_linker_param(struct dmctx *ctx, char *param, char *linker, char **value)
{ {
struct dmctx dmctx = {0}; struct dmctx dmctx = {0};

View file

@ -9,7 +9,7 @@
* Author Imen Bhiri <imen.bhiri@pivasoftware.com> * Author Imen Bhiri <imen.bhiri@pivasoftware.com>
* Author Feten Besbes <feten.besbes@pivasoftware.com> * Author Feten Besbes <feten.besbes@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>
*/ */
#ifndef __DMENTRY_H__ #ifndef __DMENTRY_H__

View file

@ -8,6 +8,7 @@
* Author: Imen Bhiri <imen.bhiri@pivasoftware.com> * Author: Imen Bhiri <imen.bhiri@pivasoftware.com>
* Author: Feten Besbes <feten.besbes@pivasoftware.com> * Author: Feten Besbes <feten.besbes@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>
*/ */
#include "managementserver.h" #include "managementserver.h"

View file

@ -796,60 +796,6 @@ static int check_notification_value(const char *value)
return -1; return -1;
} }
static int bbf_api_dm_update_file_enabled_notify(char *param, char *new_value)
{
FILE *fp, *ftmp;
char buf[512];
char *parameter, *notification, *value, *type, *jval;
fp = fopen(DM_ENABLED_NOTIFY, "r");
if (fp == NULL)
return 0;
ftmp = fopen(DM_ENABLED_NOTIFY_TEMPORARY, "a");
if (ftmp == NULL) {
fclose(fp);
return 0;
}
while (fgets(buf, 512, fp) != NULL) {
int len = strlen(buf);
if (len)
buf[len-1] = '\0';
bbf_api_dmjson_parse_init(buf);
bbf_api_dmjson_get_string("parameter", &jval);
if (jval == NULL || strlen(jval) == 0)
continue;
parameter = dmstrdup(jval?jval:"");
bbf_api_dmjson_get_string("value", &jval);
value = dmstrdup(jval?jval:"");
bbf_api_dmjson_get_string("notification", &jval);
notification = dmstrdup(jval?jval:"");
bbf_api_dmjson_get_string("type", &jval);
type = dmstrdup(jval?jval:"");
bbf_api_dmjson_parse_fini();
if (strcmp(parameter, param) == 0)
dmjson_fprintf(ftmp, 4, DMJSON_ARGS{{"parameter", parameter}, {"notification", notification}, {"value", new_value}, {"type", type}});
else
dmjson_fprintf(ftmp, 4, DMJSON_ARGS{{"parameter", parameter}, {"notification", notification}, {"value", value}, {"type", type}});
}
fclose(fp);
fclose(ftmp);
return 0;
}
static void dm_update_enabled_notify_byname(char *name, char *new_value)
{
int iscopy;
bbf_api_dm_update_file_enabled_notify(name, new_value);
remove(DM_ENABLED_NOTIFY);
iscopy = bbf_api_copy_temporary_file_to_original_file(DM_ENABLED_NOTIFY, DM_ENABLED_NOTIFY_TEMPORARY);
if(iscopy)
remove(DM_ENABLED_NOTIFY_TEMPORARY);
}
int update_param_instance_alias(struct dmctx *ctx, char *param, char **new_param) int update_param_instance_alias(struct dmctx *ctx, char *param, char **new_param)
{ {
char *pch, *spch, *p; char *pch, *spch, *p;
@ -1727,10 +1673,8 @@ static int mparam_set_value(DMPARAM_ARGS)
return fault; return fault;
} }
add_set_list_tmp(dmctx, dmctx->in_param, dmctx->in_value); add_set_list_tmp(dmctx, dmctx->in_param, dmctx->in_value);
} else if (dmctx->setaction == VALUESET) { } else if (dmctx->setaction == VALUESET)
(set_cmd)(refparam, dmctx, data, instance, dmctx->in_value, VALUESET); (set_cmd)(refparam, dmctx, data, instance, dmctx->in_value, VALUESET);
dm_update_enabled_notify_byname(refparam, dmctx->in_value);
}
dmfree(refparam); dmfree(refparam);
return 0; return 0;
} }
@ -1846,7 +1790,6 @@ int dm_entry_enabled_notify(struct dmctx *dmctx)
dmctx->method_param = enabled_notify_check_param; dmctx->method_param = enabled_notify_check_param;
dmctx->checkobj = NULL ; dmctx->checkobj = NULL ;
dmctx->checkleaf = NULL; dmctx->checkleaf = NULL;
remove(DM_ENABLED_NOTIFY);
err = dm_browse(dmctx, &node, root, NULL, NULL); err = dm_browse(dmctx, &node, root, NULL, NULL);
return err; return err;
} }
@ -1872,7 +1815,6 @@ static int enabled_notify_check_obj(DMOBJECT_ARGS)
static int enabled_notify_check_param(DMPARAM_ARGS) static int enabled_notify_check_param(DMPARAM_ARGS)
{ {
char *refparam, *stype, *notif = NULL, *value = ""; char *refparam, *stype, *notif = NULL, *value = "";
FILE *fp;
dmastrcat(&refparam, node->current_object, lastname); dmastrcat(&refparam, node->current_object, lastname);
if ((notif = check_parameter_forced_notification(refparam)) == NULL) if ((notif = check_parameter_forced_notification(refparam)) == NULL)
@ -1883,18 +1825,10 @@ static int enabled_notify_check_param(DMPARAM_ARGS)
return 0; return 0;
} }
(get_cmd)(refparam, dmctx, data, instance, &value); (get_cmd)(refparam, dmctx, data, instance, &value);
fp = fopen(DM_ENABLED_NOTIFY, "a");
if (fp == NULL) {
dmfree(refparam);
return 0;
}
if (notif[0] == '1' || notif[0] == '2' || notif[0] == '4' || notif[0] == '6') { if (notif[0] == '1' || notif[0] == '2' || notif[0] == '4' || notif[0] == '6') {
stype = DMT_TYPE[type]; stype = DMT_TYPE[type];
add_list_parameter(dmctx, refparam, value, DMT_TYPE[type], notif); add_list_parameter(dmctx, refparam, value, DMT_TYPE[type], notif);
dmjson_fprintf(fp, 4, DMJSON_ARGS{{"parameter", refparam}, {"notification", notif}, {"value", value}, {"type", stype}});
} }
fclose(fp);
return 0; return 0;
} }

View file

@ -25,9 +25,6 @@
#include "dmuci.h" #include "dmuci.h"
#include "dmmem.h" #include "dmmem.h"
#define DM_ENABLED_NOTIFY "/etc/bbfdm/.dm_enabled_notify"
#define DM_ENABLED_NOTIFY_TEMPORARY "/tmp/.dm_enabled_notify_temporary"
#ifdef UNDEF #ifdef UNDEF
#undef UNDEF #undef UNDEF
#endif #endif
@ -123,13 +120,6 @@ struct param_fault {
int fault; int fault;
}; };
struct dm_enabled_notify {
struct list_head list;
char *name;
char *notification;
char *value;
};
struct dm_parameter { struct dm_parameter {
struct list_head list; struct list_head list;
char *name; char *name;

View file

@ -1053,29 +1053,6 @@ int command_exec_output_to_array(char *cmd, char **output, int *length)
return 0; return 0;
} }
int bbf_api_copy_temporary_file_to_original_file(char *f1, char *f2)
{
FILE *fp, *ftmp;
char buf[512];
ftmp = fopen(f2, "r");
if (ftmp == NULL)
return 0;
fp = fopen(f1, "w");
if (fp == NULL) {
fclose(ftmp);
return 0;
}
while (fgets(buf, 512, ftmp) != NULL) {
fprintf(fp, "%s", buf);
}
fclose(ftmp);
fclose(fp);
return 1;
}
static inline int char_is_valid(char c) static inline int char_is_valid(char c)
{ {
return c >= 0x20 && c < 0x7f; return c >= 0x20 && c < 0x7f;

View file

@ -8,6 +8,7 @@
* Author: Imen Bhiri <imen.bhiri@pivasoftware.com> * Author: Imen Bhiri <imen.bhiri@pivasoftware.com>
* Author: Feten Besbes <feten.besbes@pivasoftware.com> * Author: Feten Besbes <feten.besbes@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>
*/ */
#ifndef __DM_COMMON_H #ifndef __DM_COMMON_H
@ -255,7 +256,6 @@ struct uci_section *get_dup_section_in_dmmap_eq(char *dmmap_package, char* secti
bool elt_exists_in_array(char **str_array, char *str, int length); bool elt_exists_in_array(char **str_array, char *str, int length);
int get_shift_time_time(int shift_time, char *local_time, int size); int get_shift_time_time(int shift_time, char *local_time, int size);
int command_exec_output_to_array(char *cmd, char **output, int *length); int command_exec_output_to_array(char *cmd, char **output, int *length);
int bbf_api_copy_temporary_file_to_original_file(char *f1, char *f2);
struct uci_section *is_dmmap_section_exist(char* package, char* section); struct uci_section *is_dmmap_section_exist(char* package, char* section);
struct uci_section *is_dmmap_section_exist_eq(char* package, char* section, char* opt, char* value); struct uci_section *is_dmmap_section_exist_eq(char* package, char* section, char* opt, char* value);
int dm_read_sysfs_file(const char *file, char *dst, unsigned len); int dm_read_sysfs_file(const char *file, char *dst, unsigned len);