Ejemplo 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); 
}
Ejemplo n.º 2
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;
}
Ejemplo n.º 3
0
uint32_t system_helpers_get_nodeid()
{
    char *opt;
    struct uci_ptr uciptr;
    int retval;
    long node_id;
    struct uci_context *ctx = uci_alloc_context();

    if(ctx == NULL)
        return 0;

    opt = malloc(strlen(NODEIDPATH)+1);
    strcpy(opt, NODEIDPATH);
    memset(&uciptr, 0, sizeof(uciptr));

    retval = uci_lookup_ptr(ctx, &uciptr, opt, true);

    if (retval != UCI_OK || uciptr.o == NULL) {
        free(opt);
        uci_free_context(ctx);
        return 0;
    }

    node_id = atol(uciptr.o->v.string);
    free(opt);
    uci_free_context(ctx);

    if (node_id <= 0 || node_id > UINT32_MAX)
        return 0;

    return (uint32_t) node_id;
}
Ejemplo n.º 4
0
static struct json_object * get_hostname(void) {
	struct json_object *ret = NULL;

	struct uci_context *ctx = uci_alloc_context();
	ctx->flags &= ~UCI_FLAG_STRICT;

	char section[] = "system.@system[0]";
	struct uci_ptr ptr;
	if (uci_lookup_ptr(ctx, &ptr, section, true))
		goto error;

	struct uci_section *s = ptr.s;

	const char *hostname = uci_lookup_option_string(ctx, s, "pretty_hostname");

	if (!hostname)
		hostname = uci_lookup_option_string(ctx, s, "hostname");

	ret = gluonutil_wrap_string(hostname);

error:
	uci_free_context(ctx);

	return ret;
}
Ejemplo n.º 5
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); 
}
Ejemplo n.º 6
0
static inline int ucix_get_ptr(struct uci_context *ctx, const char *p, const char *s, const char *o, const char *t)
{
	memset(&ptr, 0, sizeof(ptr));
	ptr.package = p;
	ptr.section = s;
	ptr.option = o;
	ptr.value = t;
	return uci_lookup_ptr(ctx, &ptr, NULL, true);
}
Ejemplo n.º 7
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);
}
Ejemplo n.º 8
0
char * ssidRead() {

  struct uci_context *c;
  struct uci_ptr p;

  char *ssid = safe_strdup ("wireless.@wifi-iface[0].ssid"); 
  c = uci_alloc_context();
  if (uci_lookup_ptr (c, &p, ssid, true) != UCI_OK)
    {
      uci_perror (c, "XXX");
      return 1;
    }

  char *str = strdup(p.o->v.string);
  uci_free_context (c);
  free(ssid);
  return str; 
}
Ejemplo n.º 9
0
char * hostnameRead() {

  struct uci_context *c;
  struct uci_ptr p;

  char *ssid = strdup ("system.@system[0].hostname"); 
  c = uci_alloc_context();
  if (uci_lookup_ptr (c, &p, ssid, true) != UCI_OK)
    {
      uci_perror (c, "XXX");
      return 1;
    }

  char *str = safe_strdup(p.o->v.string);
  uci_free_context (c);
  free(ssid);
  return str; 
}
Ejemplo n.º 10
0
char * urlRead() {

  struct uci_context *c;
  struct uci_ptr p;

  char *url = safe_strdup ("smartwifi.@smartwifi[0].imageurl"); 
  c = uci_alloc_context();
  if (uci_lookup_ptr (c, &p, url, true) != UCI_OK)
    {
      uci_perror (c, "XXX");
      return 1;
    }

  char *str = strdup(p.o->v.string);
  uci_free_context (c);
  free(url);
  return str; 
}
Ejemplo n.º 11
0
static bool config_load_str(char *key, char *value)
{
	struct uci_ptr ptr;
	char str[CONFIG_STR_MAX];

	strncpy(str, key, CONFIG_STR_MAX);
	if (uci_lookup_ptr(conf.uci_ctx, &ptr, str, true) != UCI_OK) {
		uci_perror(conf.uci_ctx, key);
		return false;
	}
	if (!(ptr.flags & UCI_LOOKUP_COMPLETE)) {
		conf.uci_ctx->err = UCI_ERR_NOTFOUND;
		uci_perror(conf.uci_ctx, key);
		return false;
	}
	strncpy(value, ptr.o->v.string, CONFIG_STR_MAX);
	if (conf.verbosity > 0) {
		fprintf(stdout, "[uci] %s=%s\n", key, value);
	}
	return true;
}