Changeset 199
- Timestamp:
- 06/02/10 21:53:31 (15 years ago)
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
test/pyregfi-smoketest.py
r198 r199 11 11 for value in iter.list_values(): 12 12 i += 1 13 14 return i 15 13 16 14 17 def walk_tree(iter): 15 total_keys = 0 16 total_values = 0 17 18 for sub_key in iter: 19 num_keys,num_values = walk_tree(sub_key) 20 total_keys += num_keys + 1 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 21 28 total_values += num_values 22 23 num_values += iter_values(iter) 29 iter.up() 24 30 25 31 return (total_keys, total_values) … … 30 36 iter = rf.get_key() 31 37 print walk_tree(iter) 32 -
trunk/include/regfi.h
r193 r199 1078 1078 * @ingroup regfiIteratorLayer 1079 1079 */ 1080 const REGFI_NK_REC*regfi_iterator_first_subkey(REGFI_ITERATOR* i);1080 bool regfi_iterator_first_subkey(REGFI_ITERATOR* i); 1081 1081 1082 1082 … … 1105 1105 * @ingroup regfiIteratorLayer 1106 1106 */ 1107 const REGFI_NK_REC*regfi_iterator_next_subkey(REGFI_ITERATOR* i);1107 bool regfi_iterator_next_subkey(REGFI_ITERATOR* i); 1108 1108 1109 1109 … … 1134 1134 * @ingroup regfiIteratorLayer 1135 1135 */ 1136 const REGFI_VK_REC*regfi_iterator_first_value(REGFI_ITERATOR* i);1136 bool regfi_iterator_first_value(REGFI_ITERATOR* i); 1137 1137 1138 1138 … … 1161 1161 * @ingroup regfiIteratorLayer 1162 1162 */ 1163 const REGFI_VK_REC*regfi_iterator_next_value(REGFI_ITERATOR* i);1163 bool regfi_iterator_next_value(REGFI_ITERATOR* i); 1164 1164 1165 1165 -
trunk/lib/regfi.c
r193 r199 1848 1848 1849 1849 /* XXX: this alloc/free of each sub key might be a bit excessive */ 1850 subkey = (REGFI_NK_REC*)regfi_iterator_first_subkey(i);1851 while((subkey != NULL)&& (found == false))1850 regfi_iterator_first_subkey(i); 1851 while((subkey = regfi_iterator_cur_subkey(i)) != NULL && (found == false)) 1852 1852 { 1853 1853 if(subkey->keyname != NULL … … 1857 1857 { 1858 1858 talloc_unlink(NULL, subkey); 1859 subkey = (REGFI_NK_REC*)regfi_iterator_next_subkey(i);1859 regfi_iterator_next_subkey(i); 1860 1860 } 1861 1861 } … … 1918 1918 /****************************************************************************** 1919 1919 *****************************************************************************/ 1920 const REGFI_NK_REC*regfi_iterator_first_subkey(REGFI_ITERATOR* i)1920 bool regfi_iterator_first_subkey(REGFI_ITERATOR* i) 1921 1921 { 1922 1922 i->cur_subkey = 0; 1923 return regfi_iterator_cur_subkey(i); 1923 1924 return ((i->cur_key != NULL) && (i->cur_key->subkeys_off!=REGFI_OFFSET_NONE) 1925 && (i->cur_subkey < i->cur_key->num_subkeys)); 1924 1926 } 1925 1927 … … 1931 1933 uint32_t nk_offset; 1932 1934 1933 /* see if there is anything left to report */ 1934 if (!(i->cur_key) || (i->cur_key->subkeys_off==REGFI_OFFSET_NONE) 1935 || (i->cur_subkey >= i->cur_key->num_subkeys)) 1936 return NULL; 1937 1938 nk_offset = i->cur_key->subkeys->elements[i->cur_subkey].offset; 1939 1940 return regfi_load_key(i->f, nk_offset+REGFI_REGF_SIZE, 1941 i->string_encoding, true); 1935 if((i->cur_key != NULL) && (i->cur_key->subkeys_off!=REGFI_OFFSET_NONE) 1936 && (i->cur_subkey < i->cur_key->num_subkeys)) 1937 { 1938 nk_offset = i->cur_key->subkeys->elements[i->cur_subkey].offset; 1939 1940 return regfi_load_key(i->f, nk_offset+REGFI_REGF_SIZE, 1941 i->string_encoding, true); 1942 } 1943 1944 return NULL; 1942 1945 } 1943 1946 … … 1945 1948 /****************************************************************************** 1946 1949 *****************************************************************************/ 1947 /* XXX: some way of indicating reason for failure should be added. */ 1948 const REGFI_NK_REC* regfi_iterator_next_subkey(REGFI_ITERATOR* i) 1949 { 1950 const REGFI_NK_REC* subkey; 1951 1950 bool regfi_iterator_next_subkey(REGFI_ITERATOR* i) 1951 { 1952 1952 i->cur_subkey++; 1953 subkey = regfi_iterator_cur_subkey(i); 1954 1955 if(subkey == NULL) 1956 i->cur_subkey--; 1957 1958 return subkey; 1953 1954 return ((i->cur_key != NULL) && (i->cur_key->subkeys_off!=REGFI_OFFSET_NONE) 1955 && (i->cur_subkey < i->cur_key->num_subkeys)); 1959 1956 } 1960 1957 … … 1974 1971 return false; 1975 1972 1976 cur =regfi_iterator_first_value(i);1977 while((cur != NULL)&& (found == false))1973 regfi_iterator_first_value(i); 1974 while((cur = regfi_iterator_cur_value(i)) != NULL && (found == false)) 1978 1975 { 1979 1976 if((cur->valuename != NULL) … … 1983 1980 { 1984 1981 regfi_free_record(cur); 1985 cur =regfi_iterator_next_value(i);1982 regfi_iterator_next_value(i); 1986 1983 } 1987 1984 } … … 2000 1997 /****************************************************************************** 2001 1998 *****************************************************************************/ 2002 const REGFI_VK_REC*regfi_iterator_first_value(REGFI_ITERATOR* i)1999 bool regfi_iterator_first_value(REGFI_ITERATOR* i) 2003 2000 { 2004 2001 i->cur_value = 0; 2005 return regfi_iterator_cur_value(i); 2002 return (i->cur_key->values != NULL && i->cur_key->values->elements != NULL 2003 && (i->cur_value < i->cur_key->values->num_values)); 2006 2004 } 2007 2005 … … 2014 2012 uint32_t voffset; 2015 2013 2016 if(i->cur_key->values != NULL && i->cur_key->values->elements != NULL) 2017 { 2018 if(i->cur_value < i->cur_key->values->num_values) 2019 { 2020 voffset = i->cur_key->values->elements[i->cur_value]; 2021 ret_val = regfi_load_value(i->f, voffset+REGFI_REGF_SIZE, 2022 i->string_encoding, true); 2023 } 2014 if(i->cur_key->values != NULL && i->cur_key->values->elements != NULL 2015 && (i->cur_value < i->cur_key->values->num_values)) 2016 { 2017 voffset = i->cur_key->values->elements[i->cur_value]; 2018 ret_val = regfi_load_value(i->f, voffset+REGFI_REGF_SIZE, 2019 i->string_encoding, true); 2024 2020 } 2025 2021 … … 2030 2026 /****************************************************************************** 2031 2027 *****************************************************************************/ 2032 const REGFI_VK_REC* regfi_iterator_next_value(REGFI_ITERATOR* i) 2033 { 2034 const REGFI_VK_REC* ret_val; 2035 2028 bool regfi_iterator_next_value(REGFI_ITERATOR* i) 2029 { 2036 2030 i->cur_value++; 2037 ret_val = regfi_iterator_cur_value(i); 2038 if(ret_val == NULL) 2039 i->cur_value--; 2040 2041 return ret_val; 2031 return (i->cur_key->values != NULL && i->cur_key->values->elements != NULL 2032 && (i->cur_value < i->cur_key->values->num_values)); 2042 2033 } 2043 2034 -
trunk/python2/SConstruct
r198 r199 29 29 nenv.config = config 30 30 if config.DEBUG: 31 nenv.Append(CFLAGS = "-ggdb - pedantic -Wall -std=gnu99")31 nenv.Append(CFLAGS = "-ggdb -O0 -pedantic -Wall -std=gnu99") 32 32 nenv.Append(CPPPATH=['../include', 'include']) 33 33 nenv.python_cppflags = '-I/usr/include/python2.5_d' -
trunk/python2/regfi/pyregfi.h
r198 r199 49 49 CLASS(KeyIterator, Object) 50 50 PRIVATE REGFI_ITERATOR *iter; 51 PRIVATE const REGFI_NK_REC *next_item;51 PRIVATE bool first_called; 52 52 53 53 KeyIterator METHOD(KeyIterator, Con, struct RegistryFile_t *file, char **path, … … 56 56 struct ValueIterator_t *METHOD(KeyIterator, list_values); 57 57 58 voidMETHOD(KeyIterator, __iter__);58 KeyIterator METHOD(KeyIterator, __iter__); 59 59 REGFI_NK_REC *METHOD(KeyIterator, iternext); 60 61 int METHOD(KeyIterator, down); 62 int METHOD(KeyIterator, up); 60 63 END_CLASS 61 64 62 65 /** This is an iterator for reading values from the registry */ 63 66 CLASS(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); 66 71 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); 71 74 END_CLASS 72 75 -
trunk/python2/regfi/regfi.c
r198 r199 58 58 59 59 regfi_iterator_free(this->iter); 60 if(this->next_item) {61 regfi_free_record(this->next_item);62 }63 64 60 return 0; 65 61 } … … 76 72 talloc_set_destructor((void*)self, KeyIterator_dest); 77 73 78 / / Traverse to the path74 /* Traverse to the path */ 79 75 if(path[0]) { 80 76 if(!regfi_iterator_walk_path(self->iter, (const char **)path)) { … … 84 80 } 85 81 86 // Get the first key in the list87 self-> next_item = regfi_iterator_first_subkey(self->iter);82 fprintf(stderr, "Con called\n"); 83 self->first_called = false; 88 84 89 85 return self; … … 92 88 } 93 89 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 } 90 static KeyIterator KeyIterator__iter__(KeyIterator self) { 91 return self; 92 } 93 101 94 102 95 static 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 111 static 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); 111 117 return result; 118 } 119 120 static int KeyIterator_up(KeyIterator self) { 121 return regfi_iterator_up(self->iter); 112 122 } 113 123 … … 119 129 VMETHOD(Con) = KeyIterator_Con; 120 130 VMETHOD(iternext) = KeyIterator_next; 131 VMETHOD(down) = KeyIterator_down; 132 VMETHOD(up) = KeyIterator_up; 121 133 VMETHOD(__iter__) = KeyIterator__iter__; 122 134 VMETHOD(list_values) = KeyIterator_list_values; … … 126 138 ValueIterator this = (ValueIterator)self; 127 139 128 if(this->next_item) regfi_free_record(this->next_item);140 talloc_unlink(this, this->iter); 129 141 130 142 return 0; … … 136 148 talloc_reference(self, self->iter); 137 149 138 self->next_item = regfi_iterator_first_value(self->iter);139 140 150 talloc_set_destructor((void *)self, ValueIterator_dest); 141 151 … … 143 153 } 144 154 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); 155 static ValueIterator ValueIterator__iter__(ValueIterator self) { 156 return self; 149 157 } 150 158 151 159 static RawData ValueIterator_iternext(ValueIterator self) { 152 160 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); 155 173 156 174 if(!rec) return NULL; 157 175 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 */ 158 179 data = (REGFI_DATA *)regfi_iterator_fetch_data(self->iter, rec); 159 180 if(!data) { … … 162 183 } 163 184 164 switch( self->next_item->type) {185 switch(rec->type) { 165 186 case REG_EXPAND_SZ: 166 187 case REG_SZ: … … 178 199 } 179 200 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 188 201 return result; 189 202 error: … … 255 268 256 269 void pyregfi_init() { 270 regfi_init(); 257 271 INIT_CLASS(RegistryFile); 258 259 } 272 } -
trunk/python2/utils.py
r198 r199 267 267 """ Implementation from Richard Levitte email to 268 268 org.tigris.scons.dev dated Jan 26, 2006 7:05:10 am.""" 269 python_cppflags = distutils.util.split_quoted( 270 "-I"+sysconfig.get_python_inc()) 269 python_cppflags = "-I"+sysconfig.get_python_inc() 271 270 272 271 def PythonModule(self, libname, lib_objs=[], **kwargs): -
trunk/src/reglookup.c
r185 r199 277 277 const REGFI_VK_REC* value; 278 278 279 value =regfi_iterator_first_value(iter);280 while( value!= NULL)279 regfi_iterator_first_value(iter); 280 while((value = regfi_iterator_cur_value(iter)) != NULL) 281 281 { 282 282 if(!type_filter_enabled || (value->type == type_filter)) 283 283 printValue(iter, value, prefix); 284 284 regfi_free_record(value); 285 value =regfi_iterator_next_value(iter);285 regfi_iterator_next_value(iter); 286 286 printMsgs(iter->f); 287 287 } … … 379 379 380 380 root = cur = regfi_iterator_cur_key(iter); 381 sub = regfi_iterator_first_subkey(iter); 381 regfi_iterator_first_subkey(iter); 382 sub = regfi_iterator_cur_subkey(iter); 382 383 printMsgs(iter->f); 383 384 … … 419 420 } 420 421 421 sub = regfi_iterator_next_subkey(iter); 422 regfi_iterator_next_subkey(iter); 423 sub = regfi_iterator_cur_subkey(iter); 422 424 } 423 425 print_this = false; … … 435 437 cur = regfi_iterator_cur_key(iter); 436 438 regfi_free_record(sub); 437 sub = regfi_iterator_first_subkey(iter); 439 regfi_iterator_first_subkey(iter); 440 sub = regfi_iterator_cur_subkey(iter); 438 441 print_this = true; 439 442 }
Note: See TracChangeset
for help on using the changeset viewer.