- Timestamp:
- 05/04/11 10:55:22 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/reglookup.c
r233 r249 52 52 53 53 54 static bool keysEqual(const REGFI_NK* x, const REGFI_NK* y) 55 { 56 return (x != NULL && y != NULL && x->offset == y->offset); 57 } 58 54 59 void printValue(REGFI_ITERATOR* iter, const REGFI_VK* vk, char* prefix) 55 60 { 61 const REGFI_NK* cur_key; 56 62 const REGFI_DATA* data; 57 63 char* quoted_value = NULL; … … 100 106 if(print_value_mtime) 101 107 { 102 *tmp_time = regfi_nt2unix_time(&iter->cur_key->mtime); 108 cur_key = regfi_iterator_cur_key(iter); 109 *tmp_time = regfi_nt2unix_time(&cur_key->mtime); 103 110 tmp_time_s = gmtime(tmp_time); 104 111 strftime(mtime, sizeof(mtime), "%Y-%m-%d %H:%M:%S", tmp_time_s); 112 regfi_free_record(iter->f, cur_key); 105 113 } 106 114 else … … 201 209 202 210 203 /* Returns a quoted path from an iterator's stack*/211 /* Returns a quoted path of the current iterator's position */ 204 212 char* iter2Path(REGFI_ITERATOR* i) 205 213 { 206 const REGFI_ ITER_POSITION* cur;207 const REGFI_NK* tmp_key;214 const REGFI_NK** path; 215 uint32_t k; 208 216 uint32_t buf_left = 127; 209 217 uint32_t buf_len = buf_left+1; … … 213 221 char* new_buf; 214 222 char* name; 215 void_stack_iterator* iter;216 223 217 224 buf = (char*)malloc((buf_len)*sizeof(char)); … … 220 227 buf[0] = '\0'; 221 228 222 iter = void_stack_iterator_new(i->key_positions);223 if (iter== NULL)229 path = regfi_iterator_cur_path(i); 230 if(path == NULL) 224 231 { 225 232 free(buf); … … 227 234 } 228 235 229 /* skip root element */ 230 if(void_stack_size(i->key_positions) < 1) 231 { 232 buf[0] = '/'; 233 buf[1] = '\0'; 234 return buf; 235 } 236 cur = void_stack_iterator_next(iter); 237 238 do 239 { 240 cur = void_stack_iterator_next(iter); 241 if (cur == NULL) 242 tmp_key = i->cur_key; 236 for(k=0; path[k] != NULL; k++) 237 { 238 /* skip root element's name */ 239 if(k == 0) 240 { 241 buf[0] = '/'; 242 buf[1] = '\0'; 243 } 243 244 else 244 tmp_key = cur->nk; 245 246 name = get_quoted_keyname(tmp_key); 247 248 buf[buf_len-buf_left-1] = '/'; 249 buf_left -= 1; 250 name_len = strlen(name); 251 if(name_len+1 > buf_left) 252 { 253 grow_amt = (uint32_t)(buf_len/2); 254 buf_len += name_len+1+grow_amt-buf_left; 255 if((new_buf = realloc(buf, buf_len)) == NULL) 245 { 246 name = get_quoted_keyname(path[k]); 247 248 buf[buf_len-buf_left-1] = '/'; 249 buf_left -= 1; 250 name_len = strlen(name); 251 if(name_len+1 > buf_left) 256 252 { 257 free(name); 258 free(buf); 259 free(iter); 260 return NULL; 253 grow_amt = (uint32_t)(buf_len/2); 254 buf_len += name_len+1+grow_amt-buf_left; 255 if((new_buf = realloc(buf, buf_len)) == NULL) 256 { 257 regfi_free_record(i->f, path); 258 free(name); 259 free(buf); 260 return NULL; 261 } 262 buf = new_buf; 263 buf_left = grow_amt + name_len + 1; 261 264 } 262 buf = new_buf; 263 buf_left = grow_amt + name_len + 1; 264 } 265 strncpy(buf+(buf_len-buf_left-1), name, name_len); 266 buf_left -= name_len; 267 buf[buf_len-buf_left-1] = '\0'; 268 free(name); 269 } while(cur != NULL); 270 265 strncpy(buf+(buf_len-buf_left-1), name, name_len); 266 buf_left -= name_len; 267 buf[buf_len-buf_left-1] = '\0'; 268 free(name); 269 } 270 } 271 272 regfi_free_record(i->f, path); 271 273 return buf; 272 274 } … … 378 380 bool print_this = true; 379 381 380 root = cur = regfi_iterator_cur_key(iter); 382 root = regfi_iterator_cur_key(iter); 383 regfi_reference_record(iter->f, root); 384 cur = root; 381 385 regfi_iterator_first_subkey(iter); 382 386 sub = regfi_iterator_cur_subkey(iter); … … 404 408 if(sub == NULL) 405 409 { 406 if( cur != root)410 if(!keysEqual(cur, root)) 407 411 { 408 412 regfi_free_record(iter->f, cur); 413 cur = NULL; 409 414 /* We're done with this sub-tree, going up and hitting other branches. */ 410 415 if(!regfi_iterator_up(iter)) … … 431 436 */ 432 437 regfi_free_record(iter->f, cur); 438 cur = NULL; 433 439 if(!regfi_iterator_down(iter)) 434 440 { … … 444 450 } 445 451 printMsgs(iter->f); 446 } while(!((cur == root) && (sub == NULL))); 452 } while(!(keysEqual(cur, root) && (sub == NULL))); 453 if(cur != NULL) 454 regfi_free_record(iter->f, cur); 447 455 regfi_free_record(iter->f, root); 448 456
Note: See TracChangeset
for help on using the changeset viewer.