Changeset 200


Ignore:
Timestamp:
06/03/10 01:08:20 (14 years ago)
Author:
tim
Message:

redesigned python key iterator and test script
updated documentation

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • test/pyregfi-smoketest.py

    r199 r200  
    1515
    1616
    17 def walk_tree(iter):
    18     total_keys = 1
    19     total_values = iter_values(iter)
    20     print "total_values:", total_values
    21    
    22     for sub_key in iter:
    23         print sub_key.keyname
    24        
    25         print iter.down()
    26         num_keys,num_values = walk_tree(iter)
    27         total_keys += num_keys
    28         total_values += num_values
    29         iter.up()
    30 
    31     return (total_keys, total_values)
    32 
    33 
    3417for f in files:
    3518    rf = pyregfi.RegistryFile(f)
    3619    iter = rf.get_key()
    37     print walk_tree(iter)
     20
     21    num_keys = 0
     22    num_values = 0
     23    # The iterator now walks the entire registry hive, depth-first
     24    for key in iter:
     25        #print key.keyname
     26        num_keys +=1
     27        num_values += iter_values(iter)
     28
     29    print "keys: %d" % num_keys
     30    print "values: %d" % num_values
  • trunk/include/regfi.h

    r199 r200  
    10671067
    10681068/** Sets the internal subkey index to the first subkey referenced by the current
    1069  *  key and returns that key.
     1069 *  key.
    10701070 *
    10711071 * @param i the iterator
    10721072 *
    1073  * @return A newly allocated key structure for the newly referenced first
    1074  *         subkey, or NULL on failure.  Failure may be due to a lack of any
    1075  *         subkeys or other errors.  Newly allocated keys must be freed with
    1076  *         @ref regfi_free_record.
     1073 * @return True if the current key has any subkeys, false otherwise.
    10771074 *
    10781075 * @ingroup regfiIteratorLayer
     
    10941091
    10951092
    1096 /** Increments the internal subkey index to the next key in the subkey-list and
    1097  *  returns the subkey for that index.
     1093/** Increments the internal subkey index to the next key in the subkey-list.
    10981094 *
    10991095 * @param i the iterator
    11001096 *
    1101  * @return A newly allocated key structure for the next subkey or NULL on
    1102  *         failure.  Newly allocated keys must be freed with
    1103  *         @ref regfi_free_record.
     1097 * @return True if another subkey should exist, false otherwise.
    11041098 *
    11051099 * @ingroup regfiIteratorLayer
     
    11231117
    11241118/** Sets the internal value index to the first value referenced by the current
    1125  *  key and returns that value.
     1119 *  key.
    11261120 *
    11271121 * @param i the iterator
    11281122 *
    1129  * @return  A newly allocated value structure for the newly referenced first
    1130  *          value, or NULL on failure.  Failure may be due to a lack of any
    1131  *          values or other errors.  Newly allocated keys must be freed with
    1132  *          @ref regfi_free_record.
     1123 * @return True if the current key has any values, false otherwise.
    11331124 *
    11341125 * @ingroup regfiIteratorLayer
     
    11501141
    11511142
    1152 /** Increments the internal value index to the next value in the value-list and
    1153  *  returns the value for that index.
     1143/** Increments the internal value index to the next value in the value-list.
    11541144 *
    11551145 * @param i the iterator
    11561146 *
    1157  * @return  A newly allocated key structure for the next value or NULL on
    1158  *          failure.  Newly allocated keys must be freed with
    1159  *          @ref regfi_free_record.
     1147 * @return True if another value should exist, false otherwise.
    11601148 *
    11611149 * @ingroup regfiIteratorLayer
  • trunk/lib/regfi.c

    r199 r200  
    6767void regfi_init()
    6868{
     69fprintf(stderr, "regfi_init called\n");
    6970  int err;
    7071  if((err = pthread_key_create(&regfi_log_key, regfi_log_free)) != 0)
  • trunk/python2/regfi/pyregfi.h

    r199 r200  
    4949CLASS(KeyIterator, Object)
    5050     PRIVATE REGFI_ITERATOR *iter;
    51      PRIVATE bool first_called;
     51     PRIVATE bool root_traversed;
    5252
    5353     KeyIterator METHOD(KeyIterator, Con, struct RegistryFile_t *file, char **path,
     
    5656     struct ValueIterator_t *METHOD(KeyIterator, list_values);
    5757
    58      KeyIterator METHOD(KeyIterator, __iter__);
    59      REGFI_NK_REC *METHOD(KeyIterator, iternext);
     58     void METHOD(KeyIterator, __iter__);
     59     BORROWED REGFI_NK_REC *METHOD(KeyIterator, iternext);
    6060
    6161     int METHOD(KeyIterator, down);
     
    7171
    7272     void METHOD(ValueIterator, __iter__);
    73      RawData METHOD(ValueIterator, iternext);
     73     REGFI_VK_REC *METHOD(ValueIterator, iternext);
    7474END_CLASS
    7575
  • trunk/python2/regfi/regfi.c

    r199 r200  
    3030
    3131  if(!self->reg) {
    32     /*RaiseError(ERuntimeError, "REGFI Error: %s", regfi_log_get_str());*/
     32    RaiseError(ERuntimeError, "REGFI Error: %s", regfi_log_get_str());
    3333    /*char* e = regfi_log_get_str();*/
    3434    /*fprintf(stderr, "%p\n", e);*/
     
    6161}
    6262
    63 static KeyIterator KeyIterator_Con(KeyIterator self, RegistryFile file, char **path,
    64                              REGFI_ENCODING encoding) {
     63static KeyIterator KeyIterator_Con(KeyIterator self,
     64                                   RegistryFile file,
     65                                   char **path,
     66                                   REGFI_ENCODING encoding)
     67{
    6568  self->iter = regfi_iterator_new(file->reg, encoding);
    6669
     
    8083  }
    8184
    82   fprintf(stderr, "Con called\n");
    83   self->first_called = false;
     85  self->root_traversed = false;
    8486
    8587  return self;
     
    8890}
    8991
    90 static KeyIterator KeyIterator__iter__(KeyIterator self) {
    91   return self;
    92 }
    93 
    94 
    95 static const REGFI_NK_REC* KeyIterator_next(KeyIterator self) {
    96 
    97   fprintf(stderr, "next called\n");
    98 
    99   if(!self->first_called)
     92static void KeyIterator__iter__(KeyIterator self)
     93{
     94  return;
     95}
     96
     97
     98static const REGFI_NK_REC *KeyIterator_next(KeyIterator self)
     99{
     100  if(!self->root_traversed)
     101    self->root_traversed = true;
     102  else if(!regfi_iterator_down(self->iter))
    100103  {
    101     regfi_iterator_first_subkey(self->iter);
    102     self->first_called = true;
    103   }
    104   else
    105     regfi_iterator_next_subkey(self->iter);
    106    
    107   return regfi_iterator_cur_subkey(self->iter);
     104    do
     105    {
     106      if(!regfi_iterator_up(self->iter))
     107        return NULL;
     108    } while(!regfi_iterator_next_subkey(self->iter));
     109
     110    /* XXX: This is an error condition. 
     111     *      Probably should throw an exception or something. */
     112    if(!regfi_iterator_down(self->iter))
     113      return NULL;
     114  }
     115
     116  regfi_iterator_first_subkey(self->iter);
     117  return regfi_iterator_cur_key(self->iter);
    108118}
    109119
    110120
    111121static int KeyIterator_down(KeyIterator self) {
    112   fprintf(stderr, "down cur_subkey: %d\n", self->iter->cur_subkey);
    113122  int result = regfi_iterator_down(self->iter);
    114   fprintf(stderr, "down result: %d\n", result);
    115123  regfi_iterator_first_subkey(self->iter);
    116124  regfi_iterator_first_value(self->iter);
     
    153161}
    154162
    155 static ValueIterator ValueIterator__iter__(ValueIterator self) {
    156   return self;
    157 }
    158 
    159 static RawData ValueIterator_iternext(ValueIterator self) {
     163static void ValueIterator__iter__(ValueIterator self) {
     164  return;
     165}
     166
     167static REGFI_VK_REC* ValueIterator_iternext(ValueIterator self) {
    160168  RawData result;
    161169  const REGFI_DATA* data;
     
    172180  rec = regfi_iterator_cur_value(self->iter);
    173181
     182  return rec;
     183
    174184  if(!rec) return NULL;
    175185
     
    177187   *      Instead, make data fetching a method and parse it then.
    178188   */
     189  /*
    179190  data = (REGFI_DATA *)regfi_iterator_fetch_data(self->iter, rec);
    180191  if(!data) {
     
    198209    break;
    199210  }
     211  */
    200212
    201213  return result;
Note: See TracChangeset for help on using the changeset viewer.