Changeset 263
- Timestamp:
- 04/26/07 16:10:49 (2 years ago)
- Files:
-
- honeyclient/branches/exp/kindlund-filesystem/etc/honeyclient.xml (modified) (2 diffs)
- honeyclient/branches/exp/kindlund-filesystem/lib/HoneyClient/Agent/Integrity.pm (modified) (2 diffs)
- honeyclient/branches/exp/kindlund-filesystem/lib/HoneyClient/Util/Config.pm (modified) (9 diffs)
- honeyclient/branches/exp/kindlund-filesystem/t/honeyclient_util_config.t (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
honeyclient/branches/exp/kindlund-filesystem/etc/honeyclient.xml
r233 r263 84 84 -1 85 85 </max_relative_links_to_visit> 86 <goodwords description="A comma-separated list of good words which will increase the score of links within a webpage." default="">86 <goodwords description="A comma-separated list of good words which will increase the score of links within a webpage." default=""> 87 87 news,new,big,latest,main,update,sell,free,buy 88 88 </goodwords> 89 <badwords description="A comma-separated list of bad words which will decrease the score of links within a webpage." default="">89 <badwords description="A comma-separated list of bad words which will decrease the score of links within a webpage." default=""> 90 90 archive,privacy,legal,disclaim,about,contact,copyright,jobs,careers 91 91 </badwords> … … 364 364 </Bar> 365 365 </Foo> 366 <Yok> 367 <childA>12345678</childA> 368 <childA>ABCDEFGH</childA> 369 <childB>09876543</childB> 370 <childB>ZYXVTUWG</childB> 371 </Yok> 366 372 </Test> 367 373 </Config> honeyclient/branches/exp/kindlund-filesystem/lib/HoneyClient/Agent/Integrity.pm
r246 r263 334 334 # XXX: All dirs must NEVER end in a trailing slash. 335 335 my @default_file_exclude_array = ( 336 '/cygdrive/c/cygwin/tmp', 336 337 '/cygdrive/c/cygwin/tmp/changes.txt', 337 338 '/cygdrive/c/cygwin/tmp/cleanfile.txt', … … 358 359 '/cygdrive/c/Program Files/Mozilla Firefox/active-update.xml', 359 360 '/cygdrive/c/Program Files/Mozilla Firefox/updates.xml', 361 '/cygdrive/c/System Volume Information', 360 362 '/cygdrive/c/WINDOWS/SoftwareDistribution/WuRedir', 361 363 '/cygdrive/c/WINDOWS/SYSTEM32/config/SecEvent.Evt', honeyclient/branches/exp/kindlund-filesystem/lib/HoneyClient/Util/Config.pm
r234 r263 328 328 a value like the following, within the global configuration file: 329 329 330 <HoneyClient>331 <Agent>332 <Driver>333 <address>localhost</address>334 </Driver>335 </Agent>336 </HoneyClient>330 <HoneyClient> 331 <Agent> 332 <Driver> 333 <address>localhost</address> 334 </Driver> 335 </Agent> 336 </HoneyClient> 337 337 338 338 If the "address" value is not found at this level within the XML tree, … … 341 341 # First try: 342 342 343 <HoneyClient>344 <Agent>345 <address>localhost</address>346 </Agent>347 </HoneyClient>343 <HoneyClient> 344 <Agent> 345 <address>localhost</address> 346 </Agent> 347 </HoneyClient> 348 348 349 349 # Last try: 350 350 351 <HoneyClient>352 <address>localhost</address>353 </HoneyClient>351 <HoneyClient> 352 <address>localhost</address> 353 </HoneyClient> 354 354 355 355 This function will stop its recursive search at the first value found, … … 357 357 358 358 Even after performing a recursive search, if no variable name exists, 359 then the function will croak with errors. 359 then the function will issue a warning and return undef. 360 361 If the variable found is an element that contains child elements, then 362 a corresponding hashtable will be returned. For example, if we perform 363 a getVar(name => "foo") on the following XML: 364 365 <HoneyClient> 366 <foo> 367 <bar>123</bar> 368 <bar>456</bar> 369 <yok>789</yok> 370 <yok>xxx</yok> 371 </foo> 372 </HoneyClient> 373 374 Then the following $hashref will be returned: 375 376 $hashref = { 377 'bar' => [ '123', '456' ], 378 'yok' => [ '789', 'xxx' ], 379 } 360 380 361 381 I<Inputs>: … … 367 387 should return the attribute associated with the variable's element. 368 388 369 I<Output>: The variable's element/attribute value, if found; warns and 370 returns undef otherwise. 389 I<Output>: The variable's element/attribute value or hashtable (for 390 multi-value elements), if found; warns and returns undef otherwise. 391 392 B<Note>: If the target variable to return is an element that contains 393 B<combinations> of text and sub-elements, then only the text within 394 the sub-elements will be returned in the previously mentioned 395 $hashref format. 396 397 For example, if we perform a getVar(name => "foo") on the following XML: 398 399 <HoneyClient> 400 <foo> 401 THIS_TEXT_WILL_BE_LOST 402 <bar>123</bar> 403 <bar>456</bar> 404 <yok>789</yok> 405 <yok>xxx</yok> 406 <yok><CHILD>zzz</CHILD></yok> 407 </foo> 408 </HoneyClient> 409 410 Then the following $hashref will be returned: 411 412 $hashref = { 413 'bar' => [ '123', '456' ], 414 'yok' => [ '789', 'xxx', 'zzz' ], 415 } 416 417 Notice how the B<THIS_TEXT_WILL_BE_LOST> string got dropped and that 418 the B<E<lt>CHILDE<gt>> tags were silently stripped from the B<zzz> 419 string. In other words, in each target element, B<don't mix text 420 with sub-elements> and B<don't nest sub-elements> if you want the 421 nested structure preserved when a getVar() is called on the 422 B<grandparent element>. 371 423 372 424 =back … … 388 440 is($value, "localhost", "getVar(name => 'address', namespace => 'HoneyClient::Util::Config::Test::Undefined::Child', attribute => 'default')") 389 441 or diag("The getVar() call failed. Attempted to get attribute 'default' for variable 'address' using namespace 'HoneyClient::Util::Config::Test::Undefined::Child' within the global configuration file."); 442 443 # This check tests to make sure getVar() returns the expected hashref 444 # when getting data from a target element that contains child sub-elements. 445 $value = getVar(name => "Yok", namespace => "HoneyClient::Util::Config::Test"); 446 my $expectedValue = { 447 'childA' => [ '12345678', 'ABCDEFGH' ], 448 'childB' => [ '09876543', 'ZYXVTUWG' ], 449 }; 450 is_deeply($value, $expectedValue, "getVar(name => 'Yok', namespace => 'HoneyClient::Util::Config::Test')") 451 or diag("The getVar() call failed. Attempted to get variable 'Yok' using namespace 'HoneyClient::Util::Config::Test' within the global configuration file."); 390 452 391 453 =end testing … … 428 490 # The first string is the path that matches the node we want and all ancestors 429 491 # The second string tells us whether to get the text() or an attribute 430 my $exp = $namespace . "/ancestor-or-self::*/$args{name} /" .431 (defined $args{attribute} ? " attribute::" . $args{attribute}:"text()");492 my $exp = $namespace . "/ancestor-or-self::*/$args{name}" . 493 (defined $args{attribute} ? "/attribute::" . $args{attribute} : ""); 432 494 my $nodeset = $xp->findnodes($exp); 433 495 … … 440 502 return; 441 503 } 442 my $val = $nodeset->pop->string_value; 443 444 # Trail leading and trailing whitespace 445 $val =~ s/^\s+|\s+$//g; 446 447 # For some reason attributes return attribute_name="value" 448 $val =~ s/.*"(.*)".*/$1/; 504 505 # Figure out if the (most specific) node has any children. 506 my $parent = $nodeset->pop(); 507 $nodeset = $xp->findnodes("*", $parent); 508 my $val = undef; 509 if ($nodeset->size() <= 0) { 510 # There are no child elements, thus stingify 511 # all textual components. 512 513 $val = $parent->string_value(); 514 515 # Trail leading and trailing whitespace 516 $val =~ s/^\s+|\s+$//g; 517 } else { 518 519 # There are child elements; return a 520 # hashtable accordingly. 521 my @children = $nodeset->get_nodelist(); 522 523 # Now, build the hashtable of array references. 524 $val = {}; 525 foreach my $child (@children) { 526 push (@{$val->{$child->getName()}}, $child->string_value()); 527 } 528 } 449 529 450 530 return $val; … … 452 532 453 533 =pod 454 455 =head1 EXPORTS456 534 457 535 =head2 setVar(name => $varName, namespace => $caller, attribute => $attribute, value => $value) … … 572 650 variable setting, first. If that setting is not specified, the function 573 651 call will recursively search for the same variable located within any 574 parent (or global) regions of the configuration file. See the getVar() 575 documentation for further details. 652 parent (or global) regions of the configuration file. 653 654 Furthermore, getVar() returns hashrefs for target elements that contain 655 additional child sub-elements. However, the format of this hashref 656 is B<NOT> necessarily intuitive. See the getVar() documentation for 657 further details. 576 658 577 659 =head1 SEE ALSO honeyclient/branches/exp/kindlund-filesystem/t/honeyclient_util_config.t
r131 r263 83 83 is($value, "localhost", "getVar(name => 'address', namespace => 'HoneyClient::Util::Config::Test::Undefined::Child', attribute => 'default')") 84 84 or diag("The getVar() call failed. Attempted to get attribute 'default' for variable 'address' using namespace 'HoneyClient::Util::Config::Test::Undefined::Child' within the global configuration file."); 85 86 # This check tests to make sure getVar() returns the expected hashref 87 # when getting data from a target element that contains child sub-elements. 88 $value = getVar(name => "Yok", namespace => "HoneyClient::Util::Config::Test"); 89 my $expectedValue = { 90 'childA' => [ '12345678', 'ABCDEFGH' ], 91 'childB' => [ '09876543', 'ZYXVTUWG' ], 92 }; 93 is_deeply($value, $expectedValue, "getVar(name => 'Yok', namespace => 'HoneyClient::Util::Config::Test')") 94 or diag("The getVar() call failed. Attempted to get variable 'Yok' using namespace 'HoneyClient::Util::Config::Test' within the global configuration file."); 85 95 } 86 96
