mirror of
https://dev.iopsys.eu/bbf/bbfdm.git
synced 2025-12-10 07:44:39 +01:00
bbf: Fix some transaction issues and improve the code
This commit is contained in:
parent
44b6c08273
commit
d5bf04b6a2
7 changed files with 77 additions and 53 deletions
|
|
@ -67,9 +67,18 @@ int bbfdmuci_lookup_ptr(struct uci_context *ctx, struct uci_ptr *ptr, char *pack
|
|||
return dmuci_lookup_ptr(ctx, ptr, package, section, option, value);
|
||||
}
|
||||
|
||||
int bbf_uci_commit_bbfdm(void)
|
||||
void bbf_uci_commit_bbfdm(void)
|
||||
{
|
||||
return dmuci_commit_bbfdm();
|
||||
dmuci_init_bbfdm();
|
||||
dmuci_commit_bbfdm();
|
||||
dmuci_exit_bbfdm();
|
||||
}
|
||||
|
||||
void bbf_uci_revert_bbfdm(void)
|
||||
{
|
||||
dmuci_init_bbfdm();
|
||||
dmuci_revert_bbfdm();
|
||||
dmuci_exit_bbfdm();
|
||||
}
|
||||
|
||||
int bbf_set_ip_version(int ipversion)
|
||||
|
|
|
|||
|
|
@ -18,7 +18,8 @@
|
|||
extern unsigned int upnp_in_user_mask;
|
||||
extern struct list_head list_execute_end_session;
|
||||
|
||||
int bbf_uci_commit_bbfdm(void);
|
||||
void bbf_uci_commit_bbfdm(void);
|
||||
void bbf_uci_revert_bbfdm(void);
|
||||
int set_bbfdatamodel_type(int bbf_type);
|
||||
int get_bbfdatamodel_type(void);
|
||||
int bbf_set_ip_version(int ipversion);
|
||||
|
|
|
|||
|
|
@ -606,7 +606,7 @@ int start_upload_download_diagnostic(int diagnostic_type, char *proto)
|
|||
dmcmd("/bin/sh", 5, DOWNLOAD_DIAGNOSTIC_PATH, "run", proto, url, device);
|
||||
|
||||
// Allocate uci_ctx_bbfdm
|
||||
alloc_uci_ctx_bbfdm();
|
||||
dmuci_init_bbfdm();
|
||||
|
||||
url = get_diagnostics_option("download", "url");
|
||||
status = get_diagnostics_option("download", "DiagnosticState");
|
||||
|
|
@ -625,7 +625,7 @@ int start_upload_download_diagnostic(int diagnostic_type, char *proto)
|
|||
dmcmd("/bin/sh", 6, UPLOAD_DIAGNOSTIC_PATH, "run", proto, url, device, size);
|
||||
|
||||
// Allocate uci_ctx_bbfdm
|
||||
alloc_uci_ctx_bbfdm();
|
||||
dmuci_init_bbfdm();
|
||||
|
||||
url = get_diagnostics_option("upload", "url");
|
||||
status = get_diagnostics_option("upload", "DiagnosticState");
|
||||
|
|
|
|||
17
dmentry.c
17
dmentry.c
|
|
@ -156,7 +156,7 @@ static int dm_ctx_init_custom(struct dmctx *ctx, unsigned int dm_type, unsigned
|
|||
UPNP_SUPPORTED_DM *tUPNPSupportedDM = NULL;
|
||||
#endif
|
||||
if (custom == CTX_INIT_ALL)
|
||||
dmuci_init();
|
||||
bbf_uci_init();
|
||||
|
||||
INIT_LIST_HEAD(&ctx->list_parameter);
|
||||
INIT_LIST_HEAD(&ctx->set_list_tmp);
|
||||
|
|
@ -210,7 +210,7 @@ static int dm_ctx_clean_custom(struct dmctx *ctx, int custom)
|
|||
free_all_list_fault_param(ctx);
|
||||
DMFREE(ctx->addobj_instance);
|
||||
if (custom == CTX_INIT_ALL) {
|
||||
dmuci_end();
|
||||
bbf_uci_exit();
|
||||
dmubus_free();
|
||||
dmcleanmem();
|
||||
}
|
||||
|
|
@ -259,7 +259,6 @@ int dm_entry_param_method(struct dmctx *ctx, int cmd, char *inparam, char *arg1,
|
|||
{
|
||||
int err = 0, fault = 0;
|
||||
bool setnotif = true;
|
||||
bool bbfdm_commit = true;
|
||||
#ifdef BBF_TR064
|
||||
bool alarm = false, event = false;
|
||||
int err2 = 0;
|
||||
|
|
@ -306,7 +305,6 @@ int dm_entry_param_method(struct dmctx *ctx, int cmd, char *inparam, char *arg1,
|
|||
fault = dm_entry_set_value(ctx);
|
||||
if (fault)
|
||||
add_list_fault_param(ctx, ctx->in_param, usp_fault_map(fault));
|
||||
bbfdm_commit = false;
|
||||
break;
|
||||
case CMD_SET_NOTIFICATION:
|
||||
if (arg2)
|
||||
|
|
@ -337,7 +335,6 @@ int dm_entry_param_method(struct dmctx *ctx, int cmd, char *inparam, char *arg1,
|
|||
dmuci_set_value("cwmp", "acs", "ParameterKey", arg1 ? arg1 : "");
|
||||
dmuci_change_packages(&head_package_change);
|
||||
}
|
||||
bbfdm_commit = false;
|
||||
break;
|
||||
case CMD_DEL_OBJECT:
|
||||
fault = dm_entry_delete_object(ctx);
|
||||
|
|
@ -345,7 +342,6 @@ int dm_entry_param_method(struct dmctx *ctx, int cmd, char *inparam, char *arg1,
|
|||
dmuci_set_value("cwmp", "acs", "ParameterKey", arg1 ? arg1 : "");
|
||||
dmuci_change_packages(&head_package_change);
|
||||
}
|
||||
bbfdm_commit = false;
|
||||
break;
|
||||
case CMD_USP_OPERATE:
|
||||
ctx->in_value = arg1 ? arg1 : "";
|
||||
|
|
@ -418,9 +414,6 @@ int dm_entry_param_method(struct dmctx *ctx, int cmd, char *inparam, char *arg1,
|
|||
#endif
|
||||
}
|
||||
|
||||
if (bbfdm_commit)
|
||||
dmuci_commit_bbfdm();
|
||||
|
||||
dmuci_save();
|
||||
return usp_fault_map(fault);
|
||||
}
|
||||
|
|
@ -876,11 +869,13 @@ int dm_entry_restart_services(void)
|
|||
{
|
||||
struct package_change *pc;
|
||||
|
||||
bbf_uci_commit_bbfdm();
|
||||
|
||||
list_for_each_entry(pc, &head_package_change, list) {
|
||||
if (strcmp(pc->package, "cwmp") == 0) {
|
||||
dmuci_init();
|
||||
dmuci_commit_package("cwmp");
|
||||
dmuci_end();
|
||||
dmuci_exit();
|
||||
} else {
|
||||
dmubus_call_set("uci", "commit", UBUS_ARGS{{"config", pc->package, String}}, 1);
|
||||
}
|
||||
|
|
@ -894,6 +889,8 @@ int dm_entry_revert_changes(void)
|
|||
{
|
||||
struct package_change *pc;
|
||||
|
||||
bbf_uci_revert_bbfdm();
|
||||
|
||||
list_for_each_entry(pc, &head_package_change, list) {
|
||||
dmubus_call_set("uci", "revert", UBUS_ARGS{{"config", pc->package, String}}, 1);
|
||||
}
|
||||
|
|
|
|||
10
dmoperate.c
10
dmoperate.c
|
|
@ -351,7 +351,7 @@ static opr_ret_t ip_diagnostics_ipping(struct dmctx *dmctx, char *path, json_obj
|
|||
dmcmd("/bin/sh", 3, IPPING_PATH, "run", "usp");
|
||||
|
||||
// Allocate uci_ctx_bbfdm
|
||||
alloc_uci_ctx_bbfdm();
|
||||
dmuci_init_bbfdm();
|
||||
|
||||
ipping.success_count = get_diagnostics_option("ipping", "SuccessCount");
|
||||
ipping.failure_count = get_diagnostics_option("ipping", "FailureCount");
|
||||
|
|
@ -409,7 +409,7 @@ static opr_ret_t ip_diagnostics_traceroute(struct dmctx *dmctx, char *path, json
|
|||
dmcmd("/bin/sh", 3, TRACEROUTE_PATH, "run", "usp");
|
||||
|
||||
// Allocate uci_ctx_bbfdm
|
||||
alloc_uci_ctx_bbfdm();
|
||||
dmuci_init_bbfdm();
|
||||
|
||||
traceroute.response_time = get_diagnostics_option("traceroute", "ResponseTime");
|
||||
add_list_parameter(dmctx, dmstrdup("ResponseTime"), traceroute.response_time, DMT_TYPE[DMT_UNINT], NULL, 0, NULL);
|
||||
|
|
@ -588,7 +588,7 @@ static opr_ret_t ip_diagnostics_udpecho(struct dmctx *dmctx, char *path, json_ob
|
|||
dmcmd("/bin/sh", 3, UDPECHO_PATH, "run", "usp");
|
||||
|
||||
// Allocate uci_ctx_bbfdm
|
||||
alloc_uci_ctx_bbfdm();
|
||||
dmuci_init_bbfdm();
|
||||
|
||||
udpecho.success_count = get_diagnostics_option("udpechodiag", "SuccessCount");
|
||||
udpecho.failure_count = get_diagnostics_option("udpechodiag", "FailureCount");
|
||||
|
|
@ -639,7 +639,7 @@ static opr_ret_t ip_diagnostics_serverselection(struct dmctx *dmctx, char *path,
|
|||
dmcmd("/bin/sh", 3, SERVERSELECTION_PATH, "run", "usp");
|
||||
|
||||
// Allocate uci_ctx_bbfdm
|
||||
alloc_uci_ctx_bbfdm();
|
||||
dmuci_init_bbfdm();
|
||||
|
||||
serverselection.fasthost = get_diagnostics_option("serverselection", "FastestHost");
|
||||
serverselection.average_response_time = get_diagnostics_option("serverselection", "AverageResponseTime");
|
||||
|
|
@ -683,7 +683,7 @@ static opr_ret_t ip_diagnostics_nslookup(struct dmctx *dmctx, char *path, json_o
|
|||
dmcmd("/bin/sh", 3, NSLOOKUP_PATH, "run", "usp");
|
||||
|
||||
// Allocate uci_ctx_bbfdm
|
||||
alloc_uci_ctx_bbfdm();
|
||||
dmuci_init_bbfdm();
|
||||
|
||||
nslookup.success_count = get_diagnostics_option("nslookup", "SuccessCount");
|
||||
char *param_success_count = dmstrdup("SuccessCount");
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
#include "dmuci.h"
|
||||
#include "dmmem.h"
|
||||
|
||||
static struct uci_context *uci_ctx;
|
||||
static struct uci_context *uci_ctx = NULL;
|
||||
static struct uci_context *uci_varstate_ctx;
|
||||
static char *db_config = NULL;
|
||||
|
||||
|
|
@ -24,9 +24,25 @@ NEW_UCI_PATH(bbfdm, BBFDM_CONFIG, BBFDM_SAVEDIR)
|
|||
|
||||
int dmuci_init(void)
|
||||
{
|
||||
uci_ctx = uci_alloc_context();
|
||||
if (!uci_ctx)
|
||||
return -1;
|
||||
if (uci_ctx == NULL) {
|
||||
uci_ctx = uci_alloc_context();
|
||||
if (!uci_ctx)
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void dmuci_exit(void)
|
||||
{
|
||||
if (uci_ctx)
|
||||
uci_free_context(uci_ctx);
|
||||
uci_ctx = NULL;
|
||||
}
|
||||
|
||||
int bbf_uci_init(void)
|
||||
{
|
||||
dmuci_init();
|
||||
|
||||
uci_varstate_ctx = uci_alloc_context();
|
||||
if (!uci_varstate_ctx)
|
||||
|
|
@ -39,11 +55,9 @@ int dmuci_init(void)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int dmuci_end(void)
|
||||
int bbf_uci_exit(void)
|
||||
{
|
||||
if (uci_ctx)
|
||||
uci_free_context(uci_ctx);
|
||||
uci_ctx = NULL;
|
||||
dmuci_exit();
|
||||
|
||||
if (uci_varstate_ctx)
|
||||
uci_free_context(uci_varstate_ctx);
|
||||
|
|
@ -292,20 +306,15 @@ int dmuci_commit(void)
|
|||
{
|
||||
char **configs = NULL;
|
||||
char **p;
|
||||
int rc = 0;
|
||||
|
||||
if ((uci_list_configs(uci_ctx, &configs) != UCI_OK) || !configs) {
|
||||
rc = -1;
|
||||
goto end;
|
||||
}
|
||||
if ((uci_list_configs(uci_ctx, &configs) != UCI_OK) || !configs)
|
||||
return -1;
|
||||
|
||||
for (p = configs; *p; p++)
|
||||
dmuci_commit_package(*p);
|
||||
|
||||
free(configs);
|
||||
|
||||
end:
|
||||
return rc;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**** UCI SAVE *****/
|
||||
|
|
@ -814,11 +823,6 @@ int varstate_get_value_string(char *package, char *section, char *option, char *
|
|||
return 0;
|
||||
}
|
||||
|
||||
void alloc_uci_ctx_bbfdm(void)
|
||||
{
|
||||
dmuci_init_bbfdm();
|
||||
}
|
||||
|
||||
void commit_and_free_uci_ctx_bbfdm(char *dmmap_config)
|
||||
{
|
||||
dmuci_commit_package_bbfdm(dmmap_config);
|
||||
|
|
|
|||
|
|
@ -145,7 +145,7 @@ static inline void uci_list_init(struct uci_list *ptr)
|
|||
}
|
||||
|
||||
#define NEW_UCI_PATH(UCI_PATH, CPATH, DPATH) \
|
||||
struct uci_context *uci_ctx_##UCI_PATH; \
|
||||
struct uci_context *uci_ctx_##UCI_PATH = NULL; \
|
||||
const char *uci_savedir_##UCI_PATH = DPATH; \
|
||||
const char *uci_confdir_##UCI_PATH = CPATH; \
|
||||
int dmuci_get_section_type_##UCI_PATH(char *package, char *section,char **value) \
|
||||
|
|
@ -159,20 +159,20 @@ int dmuci_get_section_type_##UCI_PATH(char *package, char *section,char **value)
|
|||
}\
|
||||
int dmuci_init_##UCI_PATH(void) \
|
||||
{\
|
||||
uci_ctx_##UCI_PATH = uci_alloc_context(); \
|
||||
if (!uci_ctx_##UCI_PATH) { \
|
||||
return -1; \
|
||||
} \
|
||||
uci_add_delta_path(uci_ctx_##UCI_PATH, uci_ctx_##UCI_PATH->savedir); \
|
||||
uci_set_savedir(uci_ctx_##UCI_PATH, uci_savedir_##UCI_PATH); \
|
||||
uci_set_confdir(uci_ctx_##UCI_PATH, uci_confdir_##UCI_PATH); \
|
||||
if (uci_ctx_##UCI_PATH == NULL) { \
|
||||
uci_ctx_##UCI_PATH = uci_alloc_context(); \
|
||||
if (!uci_ctx_##UCI_PATH) \
|
||||
return -1; \
|
||||
uci_add_delta_path(uci_ctx_##UCI_PATH, uci_ctx_##UCI_PATH->savedir); \
|
||||
uci_set_savedir(uci_ctx_##UCI_PATH, uci_savedir_##UCI_PATH); \
|
||||
uci_set_confdir(uci_ctx_##UCI_PATH, uci_confdir_##UCI_PATH); \
|
||||
} \
|
||||
return 0; \
|
||||
}\
|
||||
int dmuci_exit_##UCI_PATH(void) \
|
||||
void dmuci_exit_##UCI_PATH(void) \
|
||||
{\
|
||||
if (uci_ctx_##UCI_PATH) uci_free_context(uci_ctx_##UCI_PATH);\
|
||||
uci_ctx_##UCI_PATH = NULL; \
|
||||
return 0; \
|
||||
}\
|
||||
int dmuci_get_option_value_string_##UCI_PATH(char *package, char *section, char *option, char **value) \
|
||||
{\
|
||||
|
|
@ -291,6 +291,15 @@ int dmuci_commit_##UCI_PATH(void) \
|
|||
uci_ctx = save_uci_ctx; \
|
||||
return res; \
|
||||
}\
|
||||
int dmuci_revert_##UCI_PATH(void) \
|
||||
{\
|
||||
struct uci_context *save_uci_ctx; \
|
||||
save_uci_ctx = uci_ctx; \
|
||||
uci_ctx = uci_ctx_##UCI_PATH; \
|
||||
int res = dmuci_revert(); \
|
||||
uci_ctx = save_uci_ctx; \
|
||||
return res; \
|
||||
}\
|
||||
int dmuci_save_package_##UCI_PATH(char *package) \
|
||||
{\
|
||||
struct uci_context *save_uci_ctx; \
|
||||
|
|
@ -302,7 +311,9 @@ int dmuci_save_package_##UCI_PATH(char *package) \
|
|||
}\
|
||||
|
||||
int dmuci_init(void);
|
||||
int dmuci_end(void);
|
||||
void dmuci_exit(void);
|
||||
int bbf_uci_init(void);
|
||||
int bbf_uci_exit(void);
|
||||
char *dmuci_list_to_string(struct uci_list *list, char *delimitor);
|
||||
void uci_add_list_to_list(struct uci_list *addlist, struct uci_list *list);
|
||||
void free_all_list_package_change(struct list_head *clist);
|
||||
|
|
@ -343,9 +354,11 @@ int dmuci_delete_by_section_unnamed_bbfdm(struct uci_section *s, char *option, c
|
|||
int dmuci_delete_by_section_bbfdm(struct uci_section *s, char *option, char *value);
|
||||
int dmuci_commit_package_bbfdm(char *package);
|
||||
int dmuci_commit_bbfdm(void);
|
||||
int dmuci_revert_bbfdm(void);
|
||||
struct uci_section *dmuci_walk_section_bbfdm(char *package, char *stype, void *arg1, void *arg2, int cmp , int (*filter)(struct uci_section *s, void *value), struct uci_section *prev_section, int walk);
|
||||
|
||||
void alloc_uci_ctx_bbfdm(void);
|
||||
int dmuci_init_bbfdm(void);
|
||||
void dmuci_exit_bbfdm(void);
|
||||
void commit_and_free_uci_ctx_bbfdm(char *dmmap_config);
|
||||
|
||||
int db_get_value_string(char *package, char *section, char *option, char **value);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue