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); }
static void swconfig_load_uci(struct switch_dev *dev, const char *name) { struct uci_context *ctx; struct uci_package *p = NULL; struct uci_element *e; int ret = -1; ctx = uci_alloc_context(); if (!ctx) return; uci_load(ctx, name, &p); if (!p) { uci_perror(ctx, "Failed to load config file: "); goto out; } ret = swlib_apply_from_uci(dev, p); if (ret < 0) fprintf(stderr, "Failed to apply configuration for switch '%s'\n", dev->dev_name); out: uci_free_context(ctx); exit(ret); }
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); }
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; }
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); }
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; }
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; }
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; }