Changeset 261 for honeyclient/trunk

Show
Ignore:
Timestamp:
04/25/07 17:02:52 (2 years ago)
Author:
kindlund
Message:

sc: merging branch using tags svn+ssh://kindlund@www.honeyclient.org/home/svn/honeyclient/honeyclient/tags/exp/PRE-kindlund-multi_config and svn+ssh://kindlund@www.honeyclient.org/home/svn/honeyclient/honeyclient/branches/exp/kindlund-multi_config

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • honeyclient/trunk/etc/honeyclient.xml

    r233 r261  
    8484                    -1 
    8585                </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=""> 
    8787                    news,new,big,latest,main,update,sell,free,buy 
    8888                </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=""> 
    9090                    archive,privacy,legal,disclaim,about,contact,copyright,jobs,careers 
    9191                </badwords> 
     
    364364                    </Bar> 
    365365                </Foo> 
     366                <Yok> 
     367                    <childA>12345678</childA> 
     368                    <childA>ABCDEFGH</childA> 
     369                    <childB>09876543</childB> 
     370                    <childB>ZYXVTUWG</childB> 
     371                </Yok> 
    366372            </Test> 
    367373        </Config> 
  • honeyclient/trunk/lib/HoneyClient/Agent/Integrity.pm

    r239 r261  
    213213# XXX: All dirs must NEVER end in a trailing slash. 
    214214my @default_file_exclude_array = ( 
     215    '/cygdrive/c/cygwin/tmp', 
    215216    '/cygdrive/c/cygwin/tmp/changes.txt', 
    216217    '/cygdrive/c/cygwin/tmp/cleanfile.txt', 
     
    237238    '/cygdrive/c/Program Files/Mozilla Firefox/active-update.xml', 
    238239    '/cygdrive/c/Program Files/Mozilla Firefox/updates.xml', 
     240    '/cygdrive/c/System Volume Information', 
    239241    '/cygdrive/c/WINDOWS/SoftwareDistribution/WuRedir', 
    240242    '/cygdrive/c/WINDOWS/SYSTEM32/config/SecEvent.Evt', 
  • honeyclient/trunk/lib/HoneyClient/Util/Config.pm

    r234 r261  
    328328a value like the following, within the global configuration file: 
    329329 
    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> 
    337337 
    338338If the "address" value is not found at this level within the XML tree, 
     
    341341# First try: 
    342342 
    343 <HoneyClient> 
    344     <Agent> 
    345         <address>localhost</address> 
    346     </Agent> 
    347 </HoneyClient> 
     343  <HoneyClient> 
     344      <Agent> 
     345          <address>localhost</address> 
     346      </Agent> 
     347  </HoneyClient> 
    348348 
    349349# Last try: 
    350350 
    351 <HoneyClient> 
    352     <address>localhost</address> 
    353 </HoneyClient> 
     351  <HoneyClient> 
     352      <address>localhost</address> 
     353  </HoneyClient> 
    354354 
    355355This function will stop its recursive search at the first value found, 
     
    357357 
    358358Even after performing a recursive search, if no variable name exists, 
    359 then the function will croak with errors. 
     359then the function will issue a warning and return undef. 
     360 
     361If the variable found is an element that contains child elements, then 
     362a corresponding hashtable will be returned.  For example, if we perform 
     363a 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 
     374Then the following $hashref will be returned: 
     375 
     376  $hashref = { 
     377      'bar' => [ '123', '456' ], 
     378      'yok' => [ '789', 'xxx' ], 
     379  } 
    360380 
    361381I<Inputs>: 
     
    367387should return the attribute associated with the variable's element. 
    368388 
    369 I<Output>: The variable's element/attribute value, if found; warns and 
    370 returns undef otherwise. 
     389I<Output>: The variable's element/attribute value or hashtable (for  
     390multi-value elements), if found; warns and returns undef otherwise. 
     391 
     392B<Note>: If the target variable to return is an element that contains 
     393B<combinations> of text and sub-elements, then only the text within 
     394the sub-elements will be returned in the previously mentioned 
     395$hashref format. 
     396 
     397For 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 
     410Then the following $hashref will be returned: 
     411 
     412  $hashref = { 
     413      'bar' => [ '123', '456' ], 
     414      'yok' => [ '789', 'xxx', 'zzz' ], 
     415  } 
     416 
     417Notice how the B<THIS_TEXT_WILL_BE_LOST> string got dropped and that 
     418the B<E<lt>CHILDE<gt>> tags were silently stripped from the B<zzz> 
     419string.  In other words, in each target element, B<don't mix text 
     420with sub-elements> and B<don't nest sub-elements> if you want the  
     421nested structure preserved when a getVar() is called on the 
     422B<grandparent element>. 
    371423 
    372424=back 
     
    388440is($value, "localhost", "getVar(name => 'address', namespace => 'HoneyClient::Util::Config::Test::Undefined::Child', attribute => 'default')")  
    389441    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"); 
     446my $expectedValue = { 
     447    'childA' => [ '12345678', 'ABCDEFGH' ], 
     448    'childB' => [ '09876543', 'ZYXVTUWG' ], 
     449}; 
     450is_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."); 
    390452 
    391453=end testing 
     
    428490    # The first string is the path that matches the node we want and all ancestors 
    429491    # 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} : ""); 
    432494    my $nodeset = $xp->findnodes($exp); 
    433495 
     
    440502        return; 
    441503    } 
    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    } 
    449529 
    450530    return $val; 
     
    452532 
    453533=pod 
    454  
    455 =head1 EXPORTS 
    456534 
    457535=head2 setVar(name => $varName, namespace => $caller, attribute => $attribute, value => $value) 
     
    572650variable setting, first.  If that setting is not specified, the function 
    573651call 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. 
     652parent (or global) regions of the configuration file. 
     653 
     654Furthermore, getVar() returns hashrefs for target elements that contain 
     655additional child sub-elements.  However, the format of this hashref 
     656is B<NOT> necessarily intuitive.  See the getVar() documentation for  
     657further details. 
    576658 
    577659=head1 SEE ALSO 
  • honeyclient/trunk/t/honeyclient_util_config.t

    r131 r261  
    8383is($value, "localhost", "getVar(name => 'address', namespace => 'HoneyClient::Util::Config::Test::Undefined::Child', attribute => 'default')")  
    8484    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"); 
     89my $expectedValue = { 
     90    'childA' => [ '12345678', 'ABCDEFGH' ], 
     91    'childB' => [ '09876543', 'ZYXVTUWG' ], 
     92}; 
     93is_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."); 
    8595} 
    8696