update files and add function for add/del object of x_inteno_se_ipacccfg file

This commit is contained in:
Imen Bhiri 2015-08-28 17:45:36 +01:00
parent de77c86dd8
commit a79d9d71c3
8 changed files with 93 additions and 13 deletions

View file

@ -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;

View file

@ -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;

View file

@ -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);

View file

@ -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;
}

View file

@ -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);
}

View file

@ -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

View file

@ -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);

View file

@ -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