Loading hoodselector/src/respondd.c +38 −19 Original line number Diff line number Diff line Loading @@ -102,31 +102,50 @@ static struct json_object * get_mesh_on_lan_wan(void){ ctx->flags &= ~UCI_FLAG_STRICT; struct uci_package *p; if (uci_load(ctx, "network", &p)) goto end; if (!uci_load(ctx, "wireless", &p)) { struct uci_element *e; uci_foreach_element(&p->sections, e) { struct uci_section *s = uci_to_section(e); if (strcmp(s->type, "wifi-iface")) continue; struct uci_section *wan = uci_lookup_section(ctx, p, "mesh_wan"); struct uci_section *lan = uci_lookup_section(ctx, p, "mesh_lan"); if (!wan && !lan) goto end; if (strncmp(e->name, "ibss_", 5)) continue; struct json_object *ret = json_object_new_object(); const char *bssid = uci_lookup_option_string(ctx, s, "bssid"); if (!bssid) continue; if (wan) { const char *wan_enabled = uci_lookup_option_string(ctx, wan, "auto"); json_object_object_add(ret, "wan", json_object_new_boolean(wan_enabled && !strcmp(wan_enabled, "1"))); struct json_object *ret = json_object_new_object(); json_object_object_add(ret, "bssid", gluonutil_wrap_string(bssid)); free((char*)bssid); if(ret) { uci_free_context(ctx); return ret; } } if (lan) { const char *lan_enabled = uci_lookup_option_string(ctx, lan, "auto"); json_object_object_add(ret, "lan", json_object_new_boolean(lan_enabled && !strcmp(lan_enabled, "1"))); } uci_free_context(ctx); return ret; FILE *f = fopen("/tmp/.hoodselector", "r"); if (!f) return NULL; end: uci_free_context(ctx); struct json_object *ret = json_object_new_object(); char *line = NULL; size_t len = 0; while (getline(&line, &len, f) >= 0) { //Get bssid from current selected hood. if (strstw("\"bssid\": ",line)) { if (!strrmbs(line, 10, 12)) continue; json_object_object_add(ret, "bssid", gluonutil_wrap_string(line)); free(line); fclose(f); return ret; } } free(line); fclose(f); return NULL; } Loading Loading
hoodselector/src/respondd.c +38 −19 Original line number Diff line number Diff line Loading @@ -102,31 +102,50 @@ static struct json_object * get_mesh_on_lan_wan(void){ ctx->flags &= ~UCI_FLAG_STRICT; struct uci_package *p; if (uci_load(ctx, "network", &p)) goto end; if (!uci_load(ctx, "wireless", &p)) { struct uci_element *e; uci_foreach_element(&p->sections, e) { struct uci_section *s = uci_to_section(e); if (strcmp(s->type, "wifi-iface")) continue; struct uci_section *wan = uci_lookup_section(ctx, p, "mesh_wan"); struct uci_section *lan = uci_lookup_section(ctx, p, "mesh_lan"); if (!wan && !lan) goto end; if (strncmp(e->name, "ibss_", 5)) continue; struct json_object *ret = json_object_new_object(); const char *bssid = uci_lookup_option_string(ctx, s, "bssid"); if (!bssid) continue; if (wan) { const char *wan_enabled = uci_lookup_option_string(ctx, wan, "auto"); json_object_object_add(ret, "wan", json_object_new_boolean(wan_enabled && !strcmp(wan_enabled, "1"))); struct json_object *ret = json_object_new_object(); json_object_object_add(ret, "bssid", gluonutil_wrap_string(bssid)); free((char*)bssid); if(ret) { uci_free_context(ctx); return ret; } } if (lan) { const char *lan_enabled = uci_lookup_option_string(ctx, lan, "auto"); json_object_object_add(ret, "lan", json_object_new_boolean(lan_enabled && !strcmp(lan_enabled, "1"))); } uci_free_context(ctx); return ret; FILE *f = fopen("/tmp/.hoodselector", "r"); if (!f) return NULL; end: uci_free_context(ctx); struct json_object *ret = json_object_new_object(); char *line = NULL; size_t len = 0; while (getline(&line, &len, f) >= 0) { //Get bssid from current selected hood. if (strstw("\"bssid\": ",line)) { if (!strrmbs(line, 10, 12)) continue; json_object_object_add(ret, "bssid", gluonutil_wrap_string(line)); free(line); fclose(f); return ret; } } free(line); fclose(f); return NULL; } Loading