149 parsed * |
152 parsed * |
150 find_rule( char *key, parsed *p_request ) |
153 find_rule( char *key, parsed *p_request ) |
151 { |
154 { |
152 if ( key == NULL ) return( NULL ); |
155 if ( key == NULL ) return( NULL ); |
153 |
156 |
154 struct cdb cdb; |
|
155 struct cdb_find cdbf; /* structure to hold current find position */ |
157 struct cdb_find cdbf; /* structure to hold current find position */ |
156 |
158 |
157 parsed *rule = NULL; |
159 parsed *rule = NULL; |
158 char *val = NULL; |
160 char *val = NULL; |
159 unsigned int vlen, vpos; |
161 unsigned int vlen, vpos; |
160 |
162 |
161 /* initialize search structs */ |
163 /* initialize search structs */ |
162 if ( db_attach() == -1 ) return( NULL ); |
164 if ( db_attach() == -1 ) return( NULL ); |
163 cdb_init( &cdb, v.db_fd ); |
165 cdb_findinit( &cdbf, &v.db, key, (int)strlen(key) ); |
164 cdb_findinit( &cdbf, &cdb, key, (int)strlen(key) ); |
|
165 |
166 |
166 while ( cdb_findnext( &cdbf ) > 0 ) { |
167 while ( cdb_findnext( &cdbf ) > 0 ) { |
167 vpos = cdb_datapos( &cdb ); |
168 vpos = cdb_datapos( &v.db ); |
168 vlen = cdb_datalen( &cdb ); |
169 vlen = cdb_datalen( &v.db ); |
169 |
170 |
170 /* pull the value from the db */ |
171 /* pull the value from the db */ |
171 if ( (val = calloc( vlen, sizeof(char) )) == NULL ) { |
172 if ( (val = calloc( vlen, sizeof(char) )) == NULL ) { |
172 debug( 5, LOC, "Unable to allocate memory for DB value storage: %s\n", |
173 debug( 5, LOC, "Unable to allocate memory for DB value storage: %s\n", |
173 strerror(errno) ); |
174 strerror(errno) ); |
174 cdb_free( &cdb ); |
|
175 return( NULL ); |
175 return( NULL ); |
176 } |
176 } |
177 cdb_read( &cdb, val, vlen, vpos ); |
177 cdb_read( &v.db, val, vlen, vpos ); |
178 |
178 |
179 /* check it against the request */ |
179 /* check it against the request */ |
180 debug( 4, LOC, "DB match for key '%s': %s\n", key, val ); |
180 debug( 4, LOC, "DB match for key '%s': %s\n", key, val ); |
181 rule = parse_rule( val ); |
181 rule = parse_rule( val ); |
182 free( val ); |
182 free( val ); |