Changeset 199 for trunk/python2/regfi


Ignore:
Timestamp:
06/02/10 21:53:31 (14 years ago)
Author:
tim
Message:

reworked part of regfi C API to make python wrappers simpler
continued work on python wrappers
fixed some issues in pyregfi-smoketest. WIP

Location:
trunk/python2/regfi
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/python2/regfi/pyregfi.h

    r198 r199  
    4949CLASS(KeyIterator, Object)
    5050     PRIVATE REGFI_ITERATOR *iter;
    51      PRIVATE const REGFI_NK_REC *next_item;
     51     PRIVATE bool first_called;
    5252
    5353     KeyIterator METHOD(KeyIterator, Con, struct RegistryFile_t *file, char **path,
     
    5656     struct ValueIterator_t *METHOD(KeyIterator, list_values);
    5757
    58      void METHOD(KeyIterator, __iter__);
     58     KeyIterator METHOD(KeyIterator, __iter__);
    5959     REGFI_NK_REC *METHOD(KeyIterator, iternext);
     60
     61     int METHOD(KeyIterator, down);
     62     int METHOD(KeyIterator, up);
    6063END_CLASS
    6164
    6265/** This is an iterator for reading values from the registry */
    6366CLASS(ValueIterator, Object)
    64     PRIVATE REGFI_ITERATOR *iter;
    65     PRIVATE const REGFI_VK_REC *next_item;
     67     PRIVATE REGFI_ITERATOR *iter;
     68     PRIVATE bool first_called;
     69     
     70     ValueIterator METHOD(ValueIterator, Con, KeyIterator key);
    6671
    67     ValueIterator METHOD(ValueIterator, Con, KeyIterator key);
    68 
    69     void METHOD(ValueIterator, __iter__);
    70     RawData METHOD(ValueIterator, iternext);
     72     void METHOD(ValueIterator, __iter__);
     73     RawData METHOD(ValueIterator, iternext);
    7174END_CLASS
    7275
  • trunk/python2/regfi/regfi.c

    r198 r199  
    5858
    5959  regfi_iterator_free(this->iter);
    60   if(this->next_item) {
    61     regfi_free_record(this->next_item);
    62   }
    63 
    6460  return 0;
    6561}
     
    7672  talloc_set_destructor((void*)self, KeyIterator_dest);
    7773
    78   // Traverse to the path
     74  /* Traverse to the path */
    7975  if(path[0]) {
    8076    if(!regfi_iterator_walk_path(self->iter, (const char **)path)) {
     
    8480  }
    8581
    86   // Get the first key in the list
    87   self->next_item = regfi_iterator_first_subkey(self->iter);
     82  fprintf(stderr, "Con called\n");
     83  self->first_called = false;
    8884
    8985  return self;
     
    9288}
    9389
    94 static void KeyIterator__iter__(KeyIterator self) {
    95   if(self->next_item) {
    96     regfi_free_record(self->next_item);
    97   };
    98 
    99   self->next_item = regfi_iterator_first_subkey(self->iter);
    100 }
     90static KeyIterator KeyIterator__iter__(KeyIterator self) {
     91  return self;
     92}
     93
    10194
    10295static const REGFI_NK_REC* KeyIterator_next(KeyIterator self) {
    103   const REGFI_NK_REC* result;
    104 
    105   if(!self->next_item) return NULL;
    106 
    107   result = self->next_item;
    108 
    109   self->next_item = regfi_iterator_next_subkey(self->iter);
    110 
     96
     97  fprintf(stderr, "next called\n");
     98
     99  if(!self->first_called)
     100  {
     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);
     108}
     109
     110
     111static int KeyIterator_down(KeyIterator self) {
     112  fprintf(stderr, "down cur_subkey: %d\n", self->iter->cur_subkey);
     113  int result = regfi_iterator_down(self->iter);
     114  fprintf(stderr, "down result: %d\n", result);
     115  regfi_iterator_first_subkey(self->iter);
     116  regfi_iterator_first_value(self->iter);
    111117  return result;
     118}
     119
     120static int KeyIterator_up(KeyIterator self) {
     121  return regfi_iterator_up(self->iter);
    112122}
    113123
     
    119129  VMETHOD(Con) = KeyIterator_Con;
    120130  VMETHOD(iternext) = KeyIterator_next;
     131  VMETHOD(down) = KeyIterator_down;
     132  VMETHOD(up) = KeyIterator_up;
    121133  VMETHOD(__iter__) = KeyIterator__iter__;
    122134  VMETHOD(list_values) = KeyIterator_list_values;
     
    126138  ValueIterator this = (ValueIterator)self;
    127139
    128   if(this->next_item) regfi_free_record(this->next_item);
     140  talloc_unlink(this, this->iter);
    129141
    130142  return 0;
     
    136148  talloc_reference(self, self->iter);
    137149
    138   self->next_item = regfi_iterator_first_value(self->iter);
    139 
    140150  talloc_set_destructor((void *)self, ValueIterator_dest);
    141151
     
    143153}
    144154
    145 static void ValueIterator__iter__(ValueIterator self) {
    146   if(self->next_item) regfi_free_record(self->next_item);
    147 
    148   self->next_item = regfi_iterator_first_value(self->iter);
     155static ValueIterator ValueIterator__iter__(ValueIterator self) {
     156  return self;
    149157}
    150158
    151159static RawData ValueIterator_iternext(ValueIterator self) {
    152160  RawData result;
    153   const REGFI_DATA *data;
    154   const REGFI_VK_REC *rec = self->next_item;
     161  const REGFI_DATA* data;
     162  const REGFI_VK_REC* rec;
     163
     164  if(!self->first_called)
     165  {
     166    regfi_iterator_first_value(self->iter);
     167    self->first_called = true;
     168  }
     169  else
     170    regfi_iterator_next_value(self->iter);
     171
     172  rec = regfi_iterator_cur_value(self->iter);
    155173
    156174  if(!rec) return NULL;
    157175
     176  /* XXX: shouldn't parse data here every time we walk over a value. 
     177   *      Instead, make data fetching a method and parse it then.
     178   */
    158179  data = (REGFI_DATA *)regfi_iterator_fetch_data(self->iter, rec);
    159180  if(!data) {
     
    162183  }
    163184
    164   switch(self->next_item->type) {
     185  switch(rec->type) {
    165186  case REG_EXPAND_SZ:
    166187  case REG_SZ:
     
    178199  }
    179200
    180 
    181   /*  if(self->next_item) {
    182     regfi_free_record(self->next_item);
    183   };
    184   */
    185 
    186   self->next_item = regfi_iterator_next_value(self->iter);
    187 
    188201  return result;
    189202 error:
     
    255268
    256269void pyregfi_init() {
     270  regfi_init();
    257271  INIT_CLASS(RegistryFile);
    258 
    259 }
     272}
Note: See TracChangeset for help on using the changeset viewer.