1 import { sorted_json } from "./utils.uc"; 2 import { dirname, glob } from "fs"; 3 4 let ctx; 5 6 function proto_config_load(config_fn, section_name) 7 { 8 if (!ctx) 9 return null; 10 11 let section_data = ctx.get_all("network", section_name); 12 if (!section_data) 13 return null; 14 15 let config_obj = { 16 iface: section_name, 17 section: section_name, 18 data: section_data, 19 uci: ctx, 20 }; 21 22 let result; 23 if (config_fn) 24 result = config_fn(config_obj); 25 else 26 result = section_data; 27 28 return sorted_json(result); 29 } 30 31 netifd.cb.proto_config_load = proto_config_load; 32 33 let base = dirname(sourcepath()); 34 for (let script in glob(base + "/proto/*.uc")) { 35 try { 36 loadfile(script)(); 37 } catch (e) { 38 netifd.log(netifd.L_WARNING, 39 `Error loading proto handler ${script}: ${e}\n${e.stacktrace[0].context}\n`); 40 } 41 } 42 43 function config_init(uci) 44 { 45 ctx = uci; 46 if (!ctx.load("network")) 47 netifd.log(netifd.L_WARNING, `Failed to load network config\n`); 48 } 49 50 return { 51 config_init, 52 };
This page was automatically generated by LXR 0.3.1. • OpenWrt