Exemplo n.º 1
1
int hostnameEdit(const char *option2) {

  struct uci_context *c;
  struct uci_ptr p;

  int length2= strlen("system.@system[0].hostname=")+strlen(option2)+1;
  char *hostname = safe_malloc(length2);
  strcpy(hostname,"system.@system[0].hostname="); 
  strcat(hostname,option2); 

  c = uci_alloc_context();
  if (uci_lookup_ptr (c, &p, hostname, true) != UCI_OK)
    {
      uci_perror (c, "XXX");
      return 1;
    }

  uci_set(c,&p);   
  uci_save(c, p.p);
  uci_commit(c, &p.p, false);
  uci_free_context (c);
 free(hostname);
  return(0); 
}
Exemplo n.º 2
0
int ssidEdit(const char *option1) {

  struct uci_context *c;
  struct uci_ptr p;

  int length1= strlen("wireless.@wifi-iface[0].ssid=")+strlen(option1)+1;
  char *ssid = safe_malloc(length1);
  strcpy(ssid,"wireless.@wifi-iface[0].ssid="); 
  strcat(ssid,option1); 


  c = uci_alloc_context();
  if (uci_lookup_ptr (c, &p, ssid, true) != UCI_OK)
    {
      uci_perror (c, "XXX");
      return 1;
    }

  uci_set(c,&p);   
  uci_save(c, p.p);
  uci_commit(c, &p.p, false);
  uci_free_context (c);
 free(ssid);
  return(0); 
}
Exemplo n.º 3
0
/*********************************************
*   载入配置文件,并遍历Section.
*/
static int uci_do_add(struct uci_context *ctx,struct uci_package *pkg,char *section_type,Meter *meter)
{
	struct uci_section *s = NULL;
	int ret;
	struct uci_ptr ptr;
	struct uci_element *e = NULL;

	ret = uci_add_section(ctx, pkg, section_type, &s);
	if (ret != UCI_OK){
		fprintf(stderr,"add  section failed.\n");
		return ret;
	}

	char ptr_str[64] = {0};
	sprintf(ptr_str,"meter_lastvalue.%s.modbus_id=%d",s->e.name,meter->modbus_id);
	printf("ptr_str is %s.\n",ptr_str);

	if (uci_lookup_ptr(ctx, &ptr, ptr_str, true) != UCI_OK) { printf("lookup_ptr failed.\n");
	    return 1;
	}
    
	ret = uci_set(ctx, &ptr);
	if (ret != UCI_OK){
		fprintf(stderr,"ret is not ok.\n");
		return ret;
	}

	int i;
	Meter_Attribute *attribute = meter->attribute;

	for(i = 0; i < meter->attr_num; i++,attribute++)
	{
	    sprintf(ptr_str,"meter_lastvalue.%s.%s=%d",s->e.name,attribute->value_unit,777);
	    printf("ptr_str is %s.\n",ptr_str);
	    if ((ret = uci_lookup_ptr(ctx, &ptr, ptr_str, true)) != UCI_OK) { 
		printf("lookup_ptr failed.\n");
		return ret;
	    }
	    ret = uci_set(ctx, &ptr);
	    if (ret != UCI_OK){
		fprintf(stderr,"ret is not ok.\n");
		return ret;
	    }
	
	}
	if ( UCI_OK != (ret = uci_commit(ctx, &pkg, false))) {
	    printf("uci commit failed.\n");
	    return ret;
	}



	return ret;
}
Exemplo n.º 4
0
static void shift_uci_commit(void)
{
	int i;
	struct uci_ptr ptr;
	char str[CONFIG_STR_MAX];

	for (i = 0; i < CONFIG_MAX_ANALOG_PORTS; i++) {
		snprintf(str, CONFIG_STR_MAX, SHIFT_UCI_SET_TPL, i + 1,
		         conf.port[i].shift);
		if (uci_lookup_ptr(conf.uci_ctx, &ptr, str, true) != UCI_OK) {
			uci_perror(conf.uci_ctx, str);
			exit(9);
		}
		uci_set(conf.uci_ctx, &ptr);
		uci_save(conf.uci_ctx, ptr.p);
	}
	if (uci_lookup_ptr(conf.uci_ctx, &ptr, SHIFT_UCI, true) != UCI_OK) {
		uci_perror(conf.uci_ctx, SHIFT_UCI);
		exit(10);
	}
	uci_commit(conf.uci_ctx, &ptr.p, false);
}