- Timestamp:
- 05/04/11 10:55:22 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/regfi.c
r233 r249 1823 1823 if(ret_val == NULL) 1824 1824 return NULL; 1825 1826 ret_val->cur = talloc(ret_val, REGFI_ITER_POSITION); 1827 if(ret_val->cur == NULL) 1828 { 1829 talloc_free(ret_val); 1830 return NULL; 1831 } 1832 1833 ret_val->key_positions = void_stack_new(REGFI_MAX_DEPTH); 1834 if(ret_val->key_positions == NULL) 1835 { 1836 talloc_free(ret_val); 1837 return NULL; 1838 } 1839 talloc_reparent(NULL, ret_val, ret_val->key_positions); 1825 1840 1826 1841 root = (REGFI_NK*)regfi_get_rootkey(file); … … 1830 1845 return NULL; 1831 1846 } 1832 ret_val->cur_key = root; 1833 talloc_reparent(NULL, ret_val, root); 1834 1835 ret_val->key_positions = void_stack_new(REGFI_MAX_DEPTH); 1836 if(ret_val->key_positions == NULL) 1837 { 1838 talloc_free(ret_val); 1839 return NULL; 1840 } 1841 talloc_reparent(NULL, ret_val, ret_val->key_positions); 1842 1847 1848 ret_val->cur->offset = root->offset; 1849 if(root->subkeys_off == REGFI_OFFSET_NONE) 1850 ret_val->cur->num_subkeys = 0; 1851 else 1852 ret_val->cur->num_subkeys = regfi_fetch_num_subkeys(root); 1853 1854 if(root->values_off == REGFI_OFFSET_NONE) 1855 ret_val->cur->num_values = 0; 1856 else 1857 ret_val->cur->num_values = regfi_fetch_num_values(root); 1858 1859 ret_val->cur->cur_subkey = 0; 1860 ret_val->cur->cur_value = 0; 1843 1861 ret_val->f = file; 1844 ret_val->cur_subkey = 0; 1845 ret_val->cur_value = 0; 1846 1862 1863 regfi_free_record(ret_val->f, root); 1847 1864 return ret_val; 1848 1865 } … … 1855 1872 talloc_unlink(NULL, i); 1856 1873 } 1857 1858 1874 1859 1875 … … 1864 1880 { 1865 1881 REGFI_NK* subkey; 1866 REGFI_ITER_POSITION* pos; 1867 1868 pos = talloc(i->key_positions, REGFI_ITER_POSITION); 1882 REGFI_ITER_POSITION* pos = talloc(i, REGFI_ITER_POSITION); 1869 1883 if(pos == NULL) 1870 1884 return false; … … 1873 1887 if(subkey == NULL) 1874 1888 { 1889 regfi_log_add(REGFI_LOG_WARN, "Could not obtain cur_subkey during" 1890 " iterator_down with subkey index (%d) and key offset=%.8X\n", 1891 i->cur->cur_subkey, i->cur->offset); 1875 1892 talloc_free(pos); 1876 1893 return false; 1877 1894 } 1878 1895 1879 pos->nk = i->cur_key; 1880 pos->cur_subkey = i->cur_subkey; 1881 if(!void_stack_push(i->key_positions, pos)) 1896 if(!void_stack_push(i->key_positions, i->cur)) 1882 1897 { 1883 1898 talloc_free(pos); 1884 talloc_unlink(NULL, subkey);1899 regfi_free_record(i->f, subkey); 1885 1900 return false; 1886 } 1887 talloc_reparent(NULL, i, subkey); 1888 1889 i->cur_key = subkey; 1890 i->cur_subkey = 0; 1891 i->cur_value = 0; 1892 1901 } 1902 1903 pos->offset = subkey->offset; 1904 if(subkey->subkeys_off == REGFI_OFFSET_NONE) 1905 pos->num_subkeys = 0; 1906 else 1907 pos->num_subkeys = regfi_fetch_num_subkeys(subkey); 1908 1909 if(subkey->values_off == REGFI_OFFSET_NONE) 1910 pos->num_values = 0; 1911 else 1912 pos->num_values = regfi_fetch_num_values(subkey); 1913 1914 pos->cur_subkey = 0; 1915 pos->cur_value = 0; 1916 i->cur = pos; 1917 1918 regfi_free_record(i->f, subkey); 1893 1919 return true; 1894 1920 } … … 1908 1934 return false; 1909 1935 1910 talloc_unlink(i, i->cur_key); 1936 talloc_unlink(i, i->cur); 1937 1911 1938 regfi_unlock(i->f, &i->f->mem_lock, "regfi_iterator_up"); 1912 1939 1913 i->cur_key = pos->nk; 1914 i->cur_subkey = pos->cur_subkey; 1915 i->cur_value = 0; 1916 talloc_free(pos); 1917 1940 i->cur = pos; 1918 1941 return true; 1919 1942 } … … 1935 1958 bool regfi_iterator_find_subkey(REGFI_ITERATOR* i, const char* name) 1936 1959 { 1960 const REGFI_NK* cur_key; 1937 1961 uint32_t new_index; 1938 1939 if(regfi_find_subkey(i->f, i->cur_key, name, &new_index)) 1940 { 1941 i->cur_subkey = new_index; 1942 return true; 1943 } 1944 1945 return false; 1962 bool ret_val = false; 1963 1964 cur_key = regfi_iterator_cur_key(i); 1965 if(cur_key == NULL) 1966 /* XXX: report error */ 1967 return ret_val; 1968 1969 if(regfi_find_subkey(i->f, cur_key, name, &new_index)) 1970 { 1971 i->cur->cur_subkey = new_index; 1972 ret_val = true; 1973 } 1974 1975 regfi_free_record(i->f, cur_key); 1976 return ret_val; 1946 1977 } 1947 1978 … … 1982 2013 return ret_val; 1983 2014 1984 ret_val = talloc_reference(NULL, i->cur_key);2015 ret_val = regfi_load_key(i->f, i->cur->offset, i->f->string_encoding, true); 1985 2016 1986 2017 regfi_unlock(i->f, &i->f->mem_lock, "regfi_iterator_cur_key"); … … 2004 2035 bool regfi_iterator_first_subkey(REGFI_ITERATOR* i) 2005 2036 { 2006 i->cur_subkey = 0; 2007 2008 return ((i->cur_key != NULL) && (i->cur_key->subkeys_off!=REGFI_OFFSET_NONE) 2009 && (i->cur_subkey < regfi_fetch_num_subkeys(i->cur_key))); 2037 i->cur->cur_subkey = 0; 2038 return (i->cur->cur_subkey < i->cur->num_subkeys); 2010 2039 } 2011 2040 … … 2015 2044 const REGFI_NK* regfi_iterator_cur_subkey(REGFI_ITERATOR* i) 2016 2045 { 2017 return regfi_get_subkey(i->f, i->cur_key, i->cur_subkey); 2046 const REGFI_NK* cur_key; 2047 const REGFI_NK* ret_val; 2048 2049 cur_key = regfi_iterator_cur_key(i); 2050 if(cur_key == NULL) 2051 /* XXX: report error */ 2052 return NULL; 2053 2054 ret_val = regfi_get_subkey(i->f, cur_key, i->cur->cur_subkey); 2055 2056 regfi_free_record(i->f, cur_key); 2057 return ret_val; 2018 2058 } 2019 2059 … … 2023 2063 bool regfi_iterator_next_subkey(REGFI_ITERATOR* i) 2024 2064 { 2025 i->cur_subkey++; 2026 2027 return ((i->cur_key != NULL) && (i->cur_key->subkeys_off!=REGFI_OFFSET_NONE) 2028 && (i->cur_subkey < regfi_fetch_num_subkeys(i->cur_key))); 2065 i->cur->cur_subkey++; 2066 return (i->cur->cur_subkey < i->cur->num_subkeys); 2029 2067 } 2030 2068 … … 2034 2072 bool regfi_iterator_find_value(REGFI_ITERATOR* i, const char* name) 2035 2073 { 2074 const REGFI_NK* cur_key; 2036 2075 uint32_t new_index; 2037 2038 if(regfi_find_value(i->f, i->cur_key, name, &new_index)) 2039 { 2040 i->cur_value = new_index; 2041 return true; 2042 } 2043 2044 return false; 2076 bool ret_val = false; 2077 2078 cur_key = regfi_iterator_cur_key(i); 2079 if(cur_key == NULL) 2080 /* XXX: report error */ 2081 return ret_val; 2082 2083 if(regfi_find_value(i->f, cur_key, name, &new_index)) 2084 { 2085 i->cur->cur_value = new_index; 2086 ret_val = true; 2087 } 2088 2089 regfi_free_record(i->f, cur_key); 2090 return ret_val; 2045 2091 } 2046 2092 … … 2050 2096 bool regfi_iterator_first_value(REGFI_ITERATOR* i) 2051 2097 { 2052 i->cur_value = 0; 2053 return (i->cur_key->values != NULL && i->cur_key->values->elements != NULL 2054 && (i->cur_value < regfi_fetch_num_values(i->cur_key))); 2098 i->cur->cur_value = 0; 2099 return (i->cur->cur_value < i->cur->num_values); 2055 2100 } 2056 2101 … … 2060 2105 const REGFI_VK* regfi_iterator_cur_value(REGFI_ITERATOR* i) 2061 2106 { 2062 return regfi_get_value(i->f, i->cur_key, i->cur_value); 2107 const REGFI_NK* cur_key; 2108 const REGFI_VK* ret_val = NULL; 2109 2110 cur_key = regfi_iterator_cur_key(i); 2111 if(cur_key == NULL) 2112 /* XXX: report error */ 2113 return ret_val; 2114 2115 ret_val = regfi_get_value(i->f, cur_key, i->cur->cur_value); 2116 2117 regfi_free_record(i->f, cur_key); 2118 return ret_val; 2063 2119 } 2064 2120 … … 2068 2124 bool regfi_iterator_next_value(REGFI_ITERATOR* i) 2069 2125 { 2070 i->cur_value++; 2071 return (i->cur_key->values != NULL && i->cur_key->values->elements != NULL 2072 && (i->cur_value < regfi_fetch_num_values(i->cur_key))); 2126 i->cur->cur_value++; 2127 return (i->cur->cur_value < i->cur->num_values); 2128 } 2129 2130 2131 2132 2133 /****************************************************************************** 2134 *****************************************************************************/ 2135 const REGFI_NK** regfi_iterator_cur_path(REGFI_ITERATOR* i) 2136 { 2137 REGFI_NK** ret_val; 2138 void_stack_iterator* iter; 2139 const REGFI_ITER_POSITION* cur; 2140 uint16_t k; 2141 2142 ret_val = talloc_array(NULL, REGFI_NK*, void_stack_size(i->key_positions)+2); 2143 if(ret_val == NULL) 2144 return NULL; 2145 2146 iter = void_stack_iterator_new(i->key_positions); 2147 if (iter == NULL) 2148 { 2149 talloc_free(ret_val); 2150 return NULL; 2151 } 2152 2153 if(!regfi_lock(i->f, &i->f->mem_lock, "regfi_cur_path")) 2154 { 2155 talloc_free(ret_val); 2156 return NULL; 2157 } 2158 2159 for(cur=void_stack_iterator_next(iter), k=0; 2160 cur != NULL; cur=void_stack_iterator_next(iter), k++) 2161 { 2162 ret_val[k] = regfi_load_key(i->f, cur->offset, i->f->string_encoding, true); 2163 talloc_reparent(NULL, ret_val, ret_val[k]); 2164 } 2165 ret_val[k] = regfi_load_key(i->f, i->cur->offset, i->f->string_encoding, true); 2166 talloc_reparent(NULL, ret_val, ret_val[k]); 2167 2168 regfi_unlock(i->f, &i->f->mem_lock, "regfi_cur_path"); 2169 void_stack_iterator_free(iter); 2170 2171 ret_val[++k] = NULL; 2172 return (const REGFI_NK**)ret_val; 2073 2173 } 2074 2174
Note: See TracChangeset
for help on using the changeset viewer.