diff --git a/dm/dmcommon.c b/dm/dmcommon.c index 4ac946f..b6fee45 100644 --- a/dm/dmcommon.c +++ b/dm/dmcommon.c @@ -70,7 +70,7 @@ pid_t get_pid(char *pname) if (fgets(buf, sizeof(buf), fp) != NULL) { /* check the first token in the file, the program name */ char* first = strtok(buf, " "); - if (strstr(first, name)) { + if (strstr(first, pname)) { fclose(fp); closedir(dir); return (pid_t)lpid; diff --git a/dm/dmcwmp.c b/dm/dmcwmp.c index f923955..625cfd1 100644 --- a/dm/dmcwmp.c +++ b/dm/dmcwmp.c @@ -97,6 +97,25 @@ char *update_instance(struct uci_section *s, char *last_inst, char *inst_opt) return instance; } +char *max_instance(char *package, char *stype, char *option, char *inst_opt, char *value) +{ + char *tmp = NULL; + struct uci_section *s; + char *tmp_instance = NULL; + + uci_foreach_option_cont(package, stype, option, value, s) { + dmuci_get_value_by_section_string(s, "inst_option", &tmp); + if (tmp[0] == '\0') + tmp = update_instance(s, tmp_instance, inst_opt); + dmfree(tmp_instance); + tmp_instance = dmstrdup(tmp); + } + if (tmp_instance == NULL) + return "1"; + dmfree(tmp_instance); + return tmp; +} + int get_empty(char *refparam, struct dmctx *args, char **value) { *value = ""; @@ -228,7 +247,7 @@ static char *get_parameter_notification (char *param) static int remove_parameter_notification(char *param) { - unsigned int i; + int i; struct uci_list *list_notif; struct uci_element *e; char *pch; @@ -726,7 +745,7 @@ static int add_object_obj(DMOBJECT_API_ARGS) ctx->addobj_instance = instance; char *objinst; - dmastrcat(&objinst, ctx->current_obj, instance); + dmasprintf(&objinst, "%s%s.", ctx->current_obj, instance); set_parameter_notification(objinst, "0"); dmfree(objinst); return 0; diff --git a/dm/dmcwmp.h b/dm/dmcwmp.h index 0e39161..bc1505a 100644 --- a/dm/dmcwmp.h +++ b/dm/dmcwmp.h @@ -171,6 +171,7 @@ enum fault_code { }; char *update_instance(struct uci_section *s, char *last_inst, char *inst_opt); +char *max_instance(char *package, char *stype, char *option, char *inst_option, char *value); int get_empty(char *refparam, struct dmctx *args, char **value); void add_list_paramameter(struct dmctx *ctx, char *param_name, char *param_data, char *param_type); void del_list_parameter(struct dm_parameter *dm_parameter); diff --git a/dm/dmtree/landevice.c b/dm/dmtree/landevice.c index 5aa95e4..e86eef1 100644 --- a/dm/dmtree/landevice.c +++ b/dm/dmtree/landevice.c @@ -490,7 +490,8 @@ int get_lan_dhcp_leasetime(char *refparam, struct dmctx *ctx, char **value) } } ltime[len] = '\0'; - dmasprintf(*value, "%d", (mtime * atoi(ltime)));//TODO to check // MEM WILL BE FREED IN DMMEMCLEAN + int times = mtime * atoi(ltime); + dmasprintf(value, "%d", times);//TODO to check // MEM WILL BE FREED IN DMMEMCLEAN return 0; } diff --git a/dm/dmtree/times.c b/dm/dmtree/times.c index f75927e..cf0f9a8 100644 --- a/dm/dmtree/times.c +++ b/dm/dmtree/times.c @@ -143,27 +143,27 @@ int set_time_ntpserver(char *refparam, struct dmctx *ctx, int action, char *valu return 0; } -int set_time_ntpserver1(char *refparam, struct dmctx *ctx, int action, char *value, int index) +int set_time_ntpserver1(char *refparam, struct dmctx *ctx, int action, char *value) { return set_time_ntpserver(refparam, ctx, action, value, 1); } -int set_time_ntpserver2(char *refparam, struct dmctx *ctx, int action, char *value, int index) +int set_time_ntpserver2(char *refparam, struct dmctx *ctx, int action, char *value) { return set_time_ntpserver(refparam, ctx, action, value, 2); } -int set_time_ntpserver3(char *refparam, struct dmctx *ctx, int action, char *value, int index) +int set_time_ntpserver3(char *refparam, struct dmctx *ctx, int action, char *value) { return set_time_ntpserver(refparam, ctx, action, value, 3); } -int set_time_ntpserver4(char *refparam, struct dmctx *ctx, int action, char *value, int index) +int set_time_ntpserver4(char *refparam, struct dmctx *ctx, int action, char *value) { return set_time_ntpserver(refparam, ctx, action, value, 4); } -int set_time_ntpserver5(char *refparam, struct dmctx *ctx, int action, char *value, int index) +int set_time_ntpserver5(char *refparam, struct dmctx *ctx, int action, char *value) { return set_time_ntpserver(refparam, ctx, action, value, 5); } diff --git a/dm/dmtree/times.h b/dm/dmtree/times.h index dcd6a2b..c9e10c6 100644 --- a/dm/dmtree/times.h +++ b/dm/dmtree/times.h @@ -3,8 +3,18 @@ int get_time_enable(char *refparam, struct dmctx *ctx, char **value); int set_time_enable(char *refparam, struct dmctx *ctx, int action, char *value); -int get_time_ntpserver(char *refparam, struct dmctx *ctx, char **value); -int set_time_ntpserver(char *refparam, struct dmctx *ctx, int action, char *value); +int get_time_ntpserver(char *refparam, struct dmctx *ctx, char **value, int index); +int get_time_ntpserver1(char *refparam, struct dmctx *ctx, char **value); +int get_time_ntpserver2(char *refparam, struct dmctx *ctx, char **value); +int get_time_ntpserver3(char *refparam, struct dmctx *ctx, char **value); +int get_time_ntpserver4(char *refparam, struct dmctx *ctx, char **value); +int get_time_ntpserver5(char *refparam, struct dmctx *ctx, char **value); +int set_time_ntpserver(char *refparam, struct dmctx *ctx, int action, char *value, int index); +int set_time_ntpserver1(char *refparam, struct dmctx *ctx, int action, char *value); +int set_time_ntpserver2(char *refparam, struct dmctx *ctx, int action, char *value); +int set_time_ntpserver3(char *refparam, struct dmctx *ctx, int action, char *value); +int set_time_ntpserver4(char *refparam, struct dmctx *ctx, int action, char *value); +int set_time_ntpserver5(char *refparam, struct dmctx *ctx, int action, char *value); int entry_method_root_Time(struct dmctx *ctx); #endif \ No newline at end of file diff --git a/dm/dmtree/x_inteno_se_ipacccfg.c b/dm/dmtree/x_inteno_se_ipacccfg.c index f611d34..20110e4 100644 --- a/dm/dmtree/x_inteno_se_ipacccfg.c +++ b/dm/dmtree/x_inteno_se_ipacccfg.c @@ -495,9 +495,56 @@ int set_port_forwarding_src_mac(char *refparam, struct dmctx *ctx, int action, c return 0; } +/***** ADD DEL OBJ *******/ +int add_ipacccfg_port_forwarding(struct dmctx *ctx, char **instancepara) +{ + char *value; + char instance[8] = {0}; + struct uci_section *redirect = NULL; + + dmuci_add_section("firewall", "redirect", &redirect, &value); + dmuci_set_value_by_section(redirect, "enabled", false); + dmuci_set_value_by_section(redirect, "target", "DNAT"); + dmuci_set_value_by_section(redirect, "proto", "tcp udp"); + sprintf(instance, "%s", max_instance("firewall", "redirect", "target", "forwardinstance", "DNAT")); + dmuci_commit(); + *instancepara = dmstrdup(instance); + return 0; +} + + +int delete_ipacccfg_port_forwarding_all(struct dmctx *ctx) +{ + struct uci_section *s = NULL; + struct uci_section *ss = NULL; + int found = 0; + + uci_foreach_option_eq("firewall", "redirect", "target", "DNAT", s) { + if (found != 0) + dmuci_delete_by_section(ss, NULL, NULL); //CHECK IF IT DELETE THE WHOLE SECTION + ss = s; + found++; + } + if (ss != NULL) + dmuci_delete_by_section(ss, NULL, NULL); + dmuci_commit(); + return 0; +} + + +int delete_ipacccfg_port_forwarding_instance(struct dmctx *ctx) +{ + struct pforwardrgs *forwardargs = (struct pforwardrgs *)ctx->args; + + dmuci_delete_by_section(forwardargs->forwardsection, NULL, NULL); + dmuci_commit(); + return 0; +} +/**********************/ + inline int get_object_port_forwarding(struct dmctx *ctx, char *iforward) { - DMOBJECT(DMROOT"X_INTENO_SE_IpAccCfg.X_INTENO_SE_PortForwarding.%s.", ctx, "0", 1, NULL, NULL, NULL, iforward); + DMOBJECT(DMROOT"X_INTENO_SE_IpAccCfg.X_INTENO_SE_PortForwarding.%s.", ctx, "0", 1, NULL, delete_ipacccfg_port_forwarding_instance, NULL, iforward); DMPARAM("Name", ctx, "1", get_port_forwarding_name, set_port_forwarding_name, NULL, 0, 1, UNDEF, NULL); DMPARAM("Enable", ctx, "1", get_port_forwarding_enable, set_port_forwarding_enable, "xsd:boolean", 0, 1, UNDEF, NULL); DMPARAM("EnalbeNatLoopback", ctx, "1", get_port_forwarding_loopback, set_port_forwarding_loopback, "xsd:boolean", 0, 1, UNDEF, NULL); @@ -524,7 +571,7 @@ int entry_method_root_X_INTENO_SE_IpAccCfg(struct dmctx *ctx) IF_MATCH(ctx, DMROOT"X_INTENO_SE_IpAccCfg.") { DMOBJECT(DMROOT"X_INTENO_SE_IpAccCfg.", ctx, "0", 1, NULL, NULL, NULL); DMOBJECT(DMROOT"X_INTENO_SE_IpAccCfg.X_INTENO_SE_IpAccListCfgObj.", ctx, "0", 1, NULL, NULL, NULL); - DMOBJECT(DMROOT"X_INTENO_SE_IpAccCfg.X_INTENO_SE_PortForwarding.", ctx, "1", 1, NULL, NULL, NULL); + DMOBJECT(DMROOT"X_INTENO_SE_IpAccCfg.X_INTENO_SE_PortForwarding.", ctx, "1", 1, add_ipacccfg_port_forwarding, delete_ipacccfg_port_forwarding_all, NULL); uci_foreach_sections("firewall", "rule", s) { if (s != NULL ) { init_args_ipacc(ctx, s); diff --git a/dm/dmtree/x_inteno_se_ipacccfg.h b/dm/dmtree/x_inteno_se_ipacccfg.h index 32acd39..bad0e45 100644 --- a/dm/dmtree/x_inteno_se_ipacccfg.h +++ b/dm/dmtree/x_inteno_se_ipacccfg.h @@ -47,5 +47,7 @@ int set_port_forwarding_source_ipaddress(char *refparam, struct dmctx *ctx, int int get_port_forwarding_src_mac(char *refparam, struct dmctx *ctx, char **value); int set_port_forwarding_src_mac(char *refparam, struct dmctx *ctx, int action, char *value); inline int get_object_port_forwarding(struct dmctx *ctx, char *iforward); +int add_ipacccfg_port_forwarding(struct dmctx *ctx, char **instancepara); +int delete_ipacccfg_port_forwarding_all(struct dmctx *ctx); int entry_method_root_X_INTENO_SE_IpAccCfg(struct dmctx *ctx); #endif \ No newline at end of file