Sanitize python object -> tag number exception handling
[platform/upstream/rpm.git] / lib / fprint.h
1 #ifndef H_FINGERPRINT
2 #define H_FINGERPRINT
3
4 /** \ingroup rpmtrans
5  * \file lib/fprint.h
6  * Identify a file name path by a unique "finger print".
7  */
8
9 #include <rpm/header.h>
10 #include <rpm/rpmte.h>
11 #include "lib/rpmdb_internal.h"
12
13 /**
14  */
15 typedef struct fprintCache_s * fingerPrintCache;
16
17 /**
18  * @todo Convert to pointer and make abstract.
19  */
20 typedef struct fingerPrint_s fingerPrint;
21
22 /**
23  * Associates a trailing sub-directory and final base name with an existing
24  * directory finger print.
25  */
26 struct fingerPrint_s {
27 /*! directory finger print entry (the directory path is stat(2)-able */
28     const struct fprintCacheEntry_s * entry;
29 /*! trailing sub-directory path (directories that are not stat(2)-able */
30 const char * subDir;
31 const char * baseName;  /*!< file base name */
32 };
33
34 /* Create new hash table data type */
35 #define HASHTYPE rpmFpEntryHash
36 #define HTKEYTYPE const char *
37 #define HTDATATYPE const struct fprintCacheEntry_s *
38 #include "lib/rpmhash.H"
39
40 /**
41  * Finger print cache entry.
42  * This is really a directory and symlink cache. We don't differentiate between
43  * the two. We can prepopulate it, which allows us to easily conduct "fake"
44  * installs of a system w/o actually mounting filesystems.
45  */
46 struct fprintCacheEntry_s {
47     const char * dirName;               /*!< path to existing directory */
48     dev_t dev;                          /*!< stat(2) device number */
49     ino_t ino;                          /*!< stat(2) inode number */
50 };
51
52 /**
53  * Finger print cache.
54  */
55 struct fprintCache_s {
56     rpmFpEntryHash ht;                  /*!< hashed by dirName */
57 };
58
59 /* Create new hash table data type */
60
61 struct rpmffi_s {
62   rpmte p;
63   int   fileno;
64 };
65
66 #undef HASHTYPE
67 #undef HTKEYTYPE
68 #undef HTDATATYPE
69
70 #define HASHTYPE rpmFpHash
71 #define HTKEYTYPE const fingerPrint *
72 #define HTDATATYPE struct rpmffi_s
73 #include "lib/rpmhash.H"
74
75 /** */
76 #define FP_ENTRY_EQUAL(a, b) (((a)->dev == (b)->dev) && ((a)->ino == (b)->ino))
77
78 /** */
79 #define FP_EQUAL(a, b) ( \
80         FP_ENTRY_EQUAL((a).entry, (b).entry) && \
81         !strcmp((a).baseName, (b).baseName) && ( \
82             ((a).subDir == (b).subDir) || \
83             ((a).subDir && (b).subDir && !strcmp((a).subDir, (b).subDir)) \
84         ) \
85     )
86
87 #ifdef __cplusplus
88 extern "C" {
89 #endif
90
91 /**
92  * Create finger print cache.
93  * @param sizeHint      number of elements expected
94  * @return pointer to initialized fingerprint cache
95  */
96 RPM_GNUC_INTERNAL
97 fingerPrintCache fpCacheCreate(int sizeHint);
98
99 /**
100  * Destroy finger print cache.
101  * @param cache         pointer to fingerprint cache
102  * @return              NULL always
103  */
104 RPM_GNUC_INTERNAL
105 fingerPrintCache fpCacheFree(fingerPrintCache cache);
106
107 /**
108  * Return finger print of a file path.
109  * @param cache         pointer to fingerprint cache
110  * @param dirName       leading directory name of file path
111  * @param baseName      base name of file path
112  * @param scareMemory
113  * @return pointer to the finger print associated with a file path.
114  */
115 RPM_GNUC_INTERNAL
116 fingerPrint fpLookup(fingerPrintCache cache, const char * dirName, 
117                         const char * baseName, int scareMemory);
118
119 /**
120  * Return hash value for a finger print.
121  * Hash based on dev and inode only!
122  * @param key           pointer to finger print entry
123  * @return hash value
124  */
125 RPM_GNUC_INTERNAL
126 unsigned int fpHashFunction(const fingerPrint * key);
127
128 /**
129  * Compare two finger print entries.
130  * This routine is exactly equivalent to the FP_EQUAL macro.
131  * @param key1          finger print 1
132  * @param key2          finger print 2
133  * @return result of comparing key1 and key2
134  */
135 RPM_GNUC_INTERNAL
136 int fpEqual(const fingerPrint * key1, const fingerPrint * key2);
137
138 /**
139  * Return finger prints of an array of file paths.
140  * @warning: scareMemory is assumed!
141  * @param cache         pointer to fingerprint cache
142  * @param dirNames      directory names
143  * @param baseNames     file base names
144  * @param dirIndexes    index into dirNames for each baseNames
145  * @param fileCount     number of file entries
146  * @retval fpList       pointer to array of finger prints
147  */
148 RPM_GNUC_INTERNAL
149 void fpLookupList(fingerPrintCache cache, const char ** dirNames, 
150                   const char ** baseNames, const uint32_t * dirIndexes, 
151                   int fileCount, fingerPrint * fpList);
152
153 /**
154  * Check file for to be installed symlinks in their path,
155  *  correct their fingerprint and add it to newht.
156  * @param ht            hash table containing all files fingerprints
157  * @param newht         hash table to add the corrected fingerprints
158  * @param fpc           fingerprint cache
159  * @param fi            file iterator of the package
160  * @param filenr        the number of the file we are dealing with
161  */
162 void fpLookupSubdir(rpmFpHash symlinks, rpmFpHash fphash, fingerPrintCache fpc, rpmte p, int filenr);
163
164
165 #ifdef __cplusplus
166 }
167 #endif
168
169 #endif