diff options
author | Erik Fonnesbeck <efonnes@gmail.com> | 2010-03-16 20:50:59 -0600 |
---|---|---|
committer | Erik Fonnesbeck <efonnes@gmail.com> | 2010-03-16 20:59:06 -0600 |
commit | 2843a3ec5d4a160646e496f3922266415151902a (patch) | |
tree | 2016d8ddea473176fe96ff2c83c1612110ee6bc0 /etc/inc/xmlparse.inc | |
parent | 2f27dffda9dbab1294334c7dc05244efa41e0d41 (diff) | |
download | pfsense-2843a3ec5d4a160646e496f3922266415151902a.zip pfsense-2843a3ec5d4a160646e496f3922266415151902a.tar.gz |
Add optional support for reading attributes to xmlparse.inc and move regdomain.xml parsing from regdomain.inc to xmlparse.inc.
Diffstat (limited to 'etc/inc/xmlparse.inc')
-rw-r--r-- | etc/inc/xmlparse.inc | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/etc/inc/xmlparse.inc b/etc/inc/xmlparse.inc index 7c5a554..f8a90c1 100644 --- a/etc/inc/xmlparse.inc +++ b/etc/inc/xmlparse.inc @@ -59,14 +59,28 @@ function listtags_pkg() { return $ret; } +/* The following items will be treated as arrays in regdomain.xml */ +function listtags_rd() { + $ret = explode(" ", + "band country flags freqband netband rd " + ); + return $ret; +} + function startElement($parser, $name, $attrs) { - global $parsedcfg, $depth, $curpath, $havedata, $listtags; + global $parsedcfg, $depth, $curpath, $havedata, $listtags, $parsedattrs, $parsingattrs; array_push($curpath, strtolower($name)); $ptr =& $parsedcfg; + if (isset($parsingattrs) && !empty($attrs)) { + $attrptr =& $parsedattrs; + $writeattrs = true; + } foreach ($curpath as $path) { $ptr =& $ptr[$path]; + if (isset($writeattrs)) + $attrptr =& $attrptr[$path]; } /* is it an element that belongs to a list? */ @@ -80,11 +94,19 @@ function startElement($parser, $name, $attrs) { array_push($curpath, count($ptr)); + if (isset($writeattrs)) { + if (!is_array($attrptr)) + $attrptr = array(); + $attrptr[count($ptr)] = $attrs; + } + } else if (isset($ptr)) { /* multiple entries not allowed for this element, bail out */ die(sprintf("XML error: %s at line %d cannot occur more than once\n", $name, xml_get_current_line_number($parser))); + } else if (isset($writeattrs)) { + $attrptr = $attrs; } $depth++; @@ -154,6 +176,18 @@ function parse_xml_config_pkg($cffile, $rootobj, $isstring = "false") { return parse_xml_config_raw($cffile, $rootobj, $isstring); } +function parse_xml_regdomain(&$rdattributes, $rdfile = '/etc/regdomain.xml', $rootobj = 'regulatory-data') { + global $listtags, $parsedattrs, $parsingattrs; + $listtags = listtags_rd(); + $parsedattrs = array(); + $parsingattrs = true; + $ret = parse_xml_config_raw($rdfile, $rootobj); + $rdattributes = $parsedattrs[$rootobj]; + unset($parsedattrs); + unset($parsingattrs); + return $ret; +} + function parse_xml_config_raw($cffile, $rootobj, $isstring = "false") { global $depth, $curpath, $parsedcfg, $havedata, $listtags; |