| 1 | + | /* | 
 
 
 
 
 
 
 
 | 2 | + | * i-scream central monitoring system | 
 
 
 
 
 
 
 
 | 3 | + | * http://www.i-scream.org.uk | 
 
 
 
 
 
 
 
 | 4 | + | * Copyright (C) 2000-2002 i-scream | 
 
 
 
 
 
 
 
 | 5 | + | * | 
 
 
 
 
 
 
 
 | 6 | + | * This program is free software; you can redistribute it and/or | 
 
 
 
 
 
 
 
 | 7 | + | * modify it under the terms of the GNU General Public License | 
 
 
 
 
 
 
 
 | 8 | + | * as published by the Free Software Foundation; either version 2 | 
 
 
 
 
 
 
 
 | 9 | + | * of the License, or (at your option) any later version. | 
 
 
 
 
 
 
 
 | 10 | + | * | 
 
 
 
 
 
 
 
 | 11 | + | * This program is distributed in the hope that it will be useful, | 
 
 
 
 
 
 
 
 | 12 | + | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
 
 
 
 
 
 
 
 | 13 | + | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
 
 
 
 
 
 
 
 | 14 | + | * GNU General Public License for more details. | 
 
 
 
 
 
 
 
 | 15 | + | * | 
 
 
 
 
 
 
 
 | 16 | + | * You should have received a copy of the GNU General Public License | 
 
 
 
 
 
 
 
 | 17 | + | * along with this program; if not, write to the Free Software | 
 
 
 
 
 
 
 
 | 18 | + | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. | 
 
 
 
 
 
 
 
 | 19 | + | */ | 
 
 
 
 
 
 
 
 | 20 | + |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 21 |  | #include "SysMon.h" | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 22 |  |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 23 |  | SysMon::SysMon( Config config, int printDebug){ | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 31 |  | // setup some standard variables | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 32 |  | sequence = 0; // no packets sent yet | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 33 |  |  | 
 
 
 
 
 
 
 
 
 | 14 | – | // get our values from config | 
 
 
 
 
 
 
 
 
 | 15 | – |  | 
 
 
 
 
 
 
 
 
 | 16 | – |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 34 |  | // setup our arrays | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 35 |  | titlepointer = 0; | 
 
 
 
 
 
 
 
 
 
 
 | 36 | < | for ( int i=0; i < maxTitles; i++ ){ | 
 
 
 
 
 
 
 
 
 | 36 | > | for ( int i=0; i < max_titles; i++ ){ | 
 
 
 
 
 
 
 
 
 
 
 | 37 |  | titles[i] = ""; | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 38 |  | values[i] = ""; | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 39 |  | } | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 45 |  | int SysMon::collect(){ | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 46 |  | if ( debug == 1 ){ | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 47 |  | std::cout << "SysMon::collect()\n"; | 
 
 
 
 
 
 
 
 
 
 
 | 48 | < | } | 
 
 
 
 
 
 
 
 
 | 48 | > | } // if | 
 
 
 
 
 
 
 
 
 
 
 | 49 |  |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 50 |  | // say we have checked again | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 51 |  | checks++; | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 52 |  |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 53 |  | // collect the system data and place it in an array of strings. | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 54 |  | // presume that the data is all formtted correctly. | 
 
 
 
 
 
 
 
 
 
 
 | 55 | < | // char input[2048]; | 
 
 
 
 
 
 
 
 
 | 55 | > |  | 
 
 
 
 
 
 
 
 
 
 
 | 56 |  | if ( debug == 1 ){ | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 57 |  | std::cout << "SysMon::collect::ipipestream\n"; | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 58 |  | } | 
 
 
 
 
 
 
 
 
 
 
 | 59 | < | // ipipestream p("statgrab.pl"); | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 60 | < | p = new SubPipe("statgrab.pl"); | 
 
 
 
 
 
 
 
 
 | 59 | > |  | 
 
 
 
 
 | 60 | > | p = new SubPipe("./statgrab.pl"); | 
 
 
 
 
 
 
 
 
 
 
 | 61 |  |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 62 |  | // get the output into input from statgrab | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 63 |  | string sinput; | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 64 |  | while ( p->getLine(&sinput) == 0 ){ | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 65 |  |  | 
 
 
 
 
 
 
 
 | 66 | + | if ( titlepointer == max_titles ){ | 
 
 
 
 
 
 
 
 | 67 | + | std::cout << "WARNING: Max Titles reached, skipping remaining" << endl; | 
 
 
 
 
 
 
 
 | 68 | + | std::cout << "Try recompiling with a value greater than the current (" << max_titles << ")" << endl; | 
 
 
 
 
 
 
 
 | 69 | + | titlepointer--; | 
 
 
 
 
 
 
 
 | 70 | + | break; | 
 
 
 
 
 
 
 
 | 71 | + | } // if | 
 
 
 
 
 
 
 
 | 72 | + |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 73 |  | // locate the first white space | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 74 |  | int found = sinput.find(" ",0); | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 75 |  | if ( found == string::npos ){ | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 76 |  | // error | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 77 |  | if ( debug == 1 ){ | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 78 |  | std::cout << "SysMon::collect::Parse error from statgrab.pl\n"; | 
 
 
 
 
 
 
 
 
 
 
 | 79 | < | } | 
 
 
 
 
 
 
 
 
 | 79 | > | } // if | 
 
 
 
 
 
 
 
 
 
 
 | 80 |  | } else { | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 81 |  | int gotTitle = 0; | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 82 |  | // now use the array of titles and values | 
 
 
 
 
 
 
 
 
 
 
 | 83 | < | for ( int i = 0; i < maxTitles; i++ ){ | 
 
 
 
 
 
 
 
 
 | 83 | > | for ( int i = 0; i < max_titles; i++ ){ | 
 
 
 
 
 
 
 
 
 
 
 | 84 |  | // check against the array value | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 85 |  | if ( titles[i] == sinput.substr(0,found) ){ | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 86 |  | // is the one we are looking for. | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 97 |  | if ( gotTitle == 0 ){ | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 98 |  | // didnt | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 99 |  | if ( debug == 1 ){ | 
 
 
 
 
 
 
 
 
 
 
 | 100 | < | std::cout << "SysMon::collect::Adding New Value\n"; | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 101 | < | std::cout << "'" << sinput.substr(0,found) << "' : "; | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 102 | < | std::cout << "'" <<  sinput.substr(found+1, sinput.length()) << "'\n"; | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 103 | < | } | 
 
 
 
 
 
 
 
 
 | 100 | > | std::cout << "SysMon::collect::Adding New Value\n"; | 
 
 
 
 
 | 101 | > | std::cout << "'" << sinput.substr(0,found) << "' : "; | 
 
 
 
 
 | 102 | > | std::cout << "'" <<  sinput.substr(found+1, sinput.length()) << "'\n"; | 
 
 
 
 
 | 103 | > | } // if | 
 
 
 
 
 
 
 
 
 
 
 | 104 |  | titles[titlepointer] = sinput.substr(0,found); | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 105 |  | values[titlepointer] = sinput.substr(found+1, sinput.length()); | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 106 |  | titlepointer++; | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 110 |  |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 111 |  | } // while | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 112 |  |  | 
 
 
 
 
 
 
 
 | 113 | + | // delete the pointer to free up memory | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 114 |  | delete p; | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 115 |  |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 116 |  | if ( debug == 1 ){ | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 117 |  | std::cout << "SysMon::collect::Parse from StatGrab finished\n"; | 
 
 
 
 
 
 
 
 
 
 
 | 118 | < | } | 
 
 
 
 
 
 
 
 
 | 118 | > | } // if | 
 
 
 
 
 
 
 
 
 
 
 | 119 |  |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 120 |  | // return sucessful | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 121 |  | return 0; | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 125 |  | void SysMon::clearData(){ | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 126 |  |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 127 |  | titlepointer = 0; | 
 
 
 
 
 
 
 
 
 
 
 | 128 | < | for ( int i=0; i < maxTitles; i++ ){ | 
 
 
 
 
 
 
 
 
 | 128 | > | for ( int i=0; i < max_titles; i++ ){ | 
 
 
 
 
 
 
 
 
 
 
 | 129 |  | titles[i] = ""; | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 130 |  | values[i] = ""; | 
 
 
 
 
 
 
 
 
 
 
 | 131 | < | } | 
 
 
 
 
 
 
 
 
 | 131 | > | } // for | 
 
 
 
 
 
 
 
 
 
 
 | 132 |  |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 133 |  | return; | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 134 |  |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 139 |  |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 140 |  | if ( debug == 1 ){ | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 141 |  | std::cout << "SysMon::getData()\n"; | 
 
 
 
 
 
 
 
 
 
 
 | 142 | < | } | 
 
 
 
 
 
 
 
 
 | 142 | > | } // if | 
 
 
 
 
 
 
 
 
 
 
 | 143 |  |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 144 |  | // create an xml object | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 145 |  | XMLFormatter xml = XMLFormatter(); | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 146 |  |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 147 |  | if ( debug == 1 ){ | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 148 |  | std::cout << "SysMon::getData::Sorting " << titlepointer << " elements\n"; | 
 
 
 
 
 
 
 
 
 
 
 | 149 | < | } | 
 
 
 
 
 
 
 
 
 | 149 | > | } // if | 
 
 
 
 
 
 
 
 
 
 
 | 150 |  |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 151 |  | // firstly sort the data. | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 152 |  | // simple bubble sort | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 170 |  | } // for | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 171 |  | } // while | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 172 |  |  | 
 
 
 
 
 
 
 
 
 
 
 | 173 | < | /* | 
 
 
 
 
 
 
 
 
 | 173 | > | /* used to check the array has sorted correctly | 
 
 
 
 
 
 
 
 
 
 
 | 174 |  | for ( int i=0; i < titlepointer; i++ ){ | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 175 |  | std::cout << titles[i] << endl; | 
 
 
 
 
 
 
 
 
 | 151 | – |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 176 |  | } | 
 
 
 
 
 
 
 
 
 
 
 | 177 | < | */ | 
 
 
 
 
 
 
 
 
 | 177 | > | */ | 
 
 
 
 
 
 
 
 
 
 
 | 178 |  |  | 
 
 
 
 
 
 
 
 
 | 155 | – |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 179 |  | // work through each one of the titles in turn and | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 180 |  | // work out their levels. | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 181 |  |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 195 |  |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 196 |  | if ( debug == 1 ){ | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 197 |  | std::cout << "SysMon::getData::Starting while\n"; | 
 
 
 
 
 
 
 
 
 
 
 | 198 | < | } | 
 
 
 
 
 
 
 
 
 | 198 | > | } // if | 
 
 
 
 
 
 
 
 
 
 
 | 199 |  |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 200 |  | while ( count <= titlepointer ){ | 
 
 
 
 
 
 
 
 
 
 
 | 201 | < |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 179 | < |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 180 | < |  | 
 
 
 
 
 
 
 
 
 | 201 | > |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 202 |  | if ( debug == 1 ){ | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 203 |  | std::cout << "Processing: " << titles[count] << endl; | 
 
 
 
 
 
 
 
 
 
 
 | 204 | < | } | 
 
 
 
 
 
 
 
 
 | 204 | > | } // if | 
 
 
 
 
 
 
 
 
 
 
 | 205 |  |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 206 |  | retryCount++; | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 207 |  |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 245 |  | // first one mind! | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 246 |  | if ( levels[0] == "packet" ){ | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 247 |  | level--; | 
 
 
 
 
 
 
 
 
 
 
 | 248 | < | } | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 248 | > | } // if | 
 
 
 
 
 | 249 | > |  | 
 
 
 
 
 
 
 
 
 
 
 | 250 |  | } // while dotPosition | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 251 |  |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 252 |  | // now grab the value title | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 268 |  | xml.addElement(attributeLevel,attributes,""); | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 269 |  | if ( debug == 1 ){ | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 270 |  | std::cout << "Adding Element + attributes" << endl; | 
 
 
 
 
 
 
 
 
 
 
 | 271 | < | } | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 272 | < | count++; | 
 
 
 
 
 
 
 
 
 | 271 | > | } // if | 
 
 
 
 
 | 272 | > |  | 
 
 
 
 
 
 
 
 
 
 
 | 273 |  | } // if | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 274 |  | isAttrib = 0; | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 275 |  | attributeLevel = ""; | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 279 |  | newLevelString += levels[i]; | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 280 |  | if ( i != level-1 ){ | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 281 |  | newLevelString += "."; | 
 
 
 
 
 
 
 
 
 
 
 | 282 | < | } | 
 
 
 
 
 
 
 
 
 | 282 | > | } // if | 
 
 
 
 
 
 
 
 
 
 
 | 283 |  | } // for | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 284 |  | } // if levels[level] | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 285 |  |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 292 |  | newLevelString += levels[i]; | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 293 |  | if ( i != level-1 ){ | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 294 |  | newLevelString += "."; | 
 
 
 
 
 
 
 
 
 
 
 | 295 | < | } | 
 
 
 
 
 
 
 
 
 | 295 | > | } // if | 
 
 
 
 
 
 
 
 
 
 
 | 296 |  | } // for | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 297 |  |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 298 |  | isAttrib = 1; | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 305 |  | if ( attributeLevel != levels[level] ){ | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 306 |  | xml.addElement(attributeLevel,attributes,""); | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 307 |  | if ( debug == 1 ){ | 
 
 
 
 
 
 
 
 
 
 
 | 308 | < | std::cout << "Adding Element + attributes" << endl; | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 309 | < | } | 
 
 
 
 
 
 
 
 
 | 308 | > | std::cout << "Adding Element + attributes1" << endl; | 
 
 
 
 
 | 309 | > | } // if | 
 
 
 
 
 
 
 
 
 
 
 | 310 |  | attributeLevel = ""; | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 311 |  | attributes = ""; | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 312 |  | count++; | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 314 |  | if ( count == titlepointer ){ | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 315 |  | xml.addElement(attributeLevel,attributes,""); | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 316 |  | if ( debug == 1 ){ | 
 
 
 
 
 
 
 
 
 
 
 | 317 | < | std::cout << "Adding Element + attributes" << endl; | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 318 | < | } | 
 
 
 
 
 
 
 
 
 | 317 | > | std::cout << "Adding Element + attributes2" << endl; | 
 
 
 
 
 | 318 | > | } // if | 
 
 
 
 
 
 
 
 
 
 
 | 319 |  | attributeLevel = ""; | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 320 |  | attributes = ""; | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 321 |  | count++; | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 330 |  | if ( attributeLevel != "" ){ | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 331 |  | xml.addElement(attributeLevel,attributes,""); | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 332 |  | if ( debug == 1 ){ | 
 
 
 
 
 
 
 
 
 
 
 | 333 | < | std::cout << "Adding Element + attributes" << endl; | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 334 | < | } | 
 
 
 
 
 
 
 
 
 | 333 | > | std::cout << "Adding Element + attributes3" << endl; | 
 
 
 
 
 | 334 | > | } // if | 
 
 
 
 
 
 
 
 
 
 
 | 335 |  | attributeLevel = ""; | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 336 |  | attributes = ""; | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 337 |  | count++; | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 343 |  | newLevelString += levels[i]; | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 344 |  | if ( i != level-1 ){ | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 345 |  | newLevelString += "."; | 
 
 
 
 
 
 
 
 
 
 
 | 346 | < | } | 
 
 
 
 
 
 
 
 
 | 346 | > | } // if | 
 
 
 
 
 
 
 
 
 
 
 | 347 |  | } // for | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 348 |  | } // if level == 1 | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 349 |  |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 352 |  | // it is the same level, just add this as another element | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 353 |  | if ( isAttrib ){ | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 354 |  | attributes += levels[level+2]; | 
 
 
 
 
 
 
 
 
 
 
 | 355 | < | attributes += "="; | 
 
 
 
 
 
 
 
 
 | 355 | > | attributes += "=\""; | 
 
 
 
 
 
 
 
 
 
 
 | 356 |  | attributes += values[count]; | 
 
 
 
 
 
 
 
 
 
 
 | 357 | < | attributes += " "; | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 358 | < | // now check if this is the last element | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 337 | < |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 338 | < |  | 
 
 
 
 
 
 
 
 
 | 357 | > | attributes += "\" "; | 
 
 
 
 
 | 358 | > |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 359 |  | } else { | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 360 |  | xml.addElement(levels[level],  values[count]); | 
 
 
 
 
 
 
 
 | 361 | + | count++; | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 362 |  | if ( debug == 1 ){ | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 363 |  | std::cout << "Adding Element" << endl; | 
 
 
 
 
 
 
 
 
 
 
 | 364 | < | } | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 365 | < | } | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 366 | < | count++; | 
 
 
 
 
 
 
 
 
 | 364 | > | } // if | 
 
 
 
 
 | 365 | > | } // if | 
 
 
 
 
 | 366 | > |  | 
 
 
 
 
 
 
 
 
 
 
 | 367 |  | } else { | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 368 |  | // gotta change it | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 369 |  |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 371 |  |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 372 |  | if ( currentLevelint <= 0 ){ | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 373 |  | break; | 
 
 
 
 
 
 
 
 
 
 
 | 374 | < | } | 
 
 
 
 
 
 
 
 
 | 374 | > | } // if | 
 
 
 
 
 
 
 
 
 
 
 | 375 |  |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 376 |  | // back up atleast one level... | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 377 |  | xml.closeNest(); | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 378 |  | if ( debug == 1 ){ | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 379 |  | std::cout << "Closing Nest" << endl; | 
 
 
 
 
 
 
 
 
 
 
 | 380 | < | } | 
 
 
 
 
 
 
 
 
 | 380 | > | } // if | 
 
 
 
 
 
 
 
 
 
 
 | 381 |  | // remove the last item | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 382 |  | currentLevelint--; | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 383 |  |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 401 |  | xml.addNest(levels[currentLevelint]); | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 402 |  | if ( debug == 1 ){ | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 403 |  | std::cout << "Adding nest " << levels[currentLevelint] << endl; | 
 
 
 
 
 
 
 
 
 
 
 | 404 | < | } | 
 
 
 
 
 
 
 
 
 | 404 | > | } // if | 
 
 
 
 
 
 
 
 
 
 
 | 405 |  |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 406 |  | // set this to be the top level of the new level | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 407 |  | currentLevelint++; | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 435 |  |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 436 |  | if ( debug == 1 ){ | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 437 |  | std::cout << "\n"; | 
 
 
 
 
 
 
 
 
 
 
 | 438 | < | } | 
 
 
 
 
 
 
 
 
 | 438 | > | } // if | 
 
 
 
 
 
 
 
 
 
 
 | 439 |  |  | 
 
 
 
 
 
 
 
 
 | 419 | – | std::cout << xml.returnXML() << endl; | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 440 |  | // return the string | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 441 |  | return xml.returnXML(); | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 442 |  |  |