178 |
175 |
179 BlockInfo* block = NULL; |
176 BlockInfo* block = NULL; |
180 |
177 |
181 if ( b->source() != NULL ) { |
178 if ( b->source() != NULL ) { |
182 block = const_cast<BlockInfo*>(b->source()); |
179 block = const_cast<BlockInfo*>(b->source()); |
183 } else { |
180 log_debug_p(LOG, "BPQBlock::initialise: b->source() != NULL"); |
|
181 } else { |
|
182 log_debug_p(LOG, "BPQBlock::initialise: b->source() == NULL"); |
184 block = b; |
183 block = b; |
185 } |
184 } |
186 |
185 |
187 int decoding_len=0; |
186 int decoding_len=0; |
188 u_int i=0, j=0; |
187 u_int i=0, j=0; |
189 u_int len = block->data_length(); |
188 u_int len = block->data_length(); |
190 u_int num_frags; |
189 u_int num_frags; |
191 u_char* buf = block->data(); |
190 u_char* buf = block->data(); |
192 |
191 |
193 // BPQ-kind 1-byte |
192 // BPQ-kind 1-byte |
194 if ( i < len ) |
193 if ( i < len ) { |
195 kind_ = (kind_t) buf[i++]; |
194 kind_ = (kind_t) buf[i++]; |
|
195 log_debug_p(LOG, "BPQBlock::initialise: kind = %d", kind_); |
|
196 } |
196 |
197 |
197 // matching rule type 1-byte |
198 // matching rule type 1-byte |
198 if ( i < len ) |
199 if ( i < len ) { |
199 matching_rule_ = (u_int) buf[i++]; |
200 matching_rule_ = (u_int) buf[i++]; |
|
201 log_debug_p(LOG, "BPQBlock::initialise: matching rule = %u", matching_rule_); |
|
202 } |
200 |
203 |
201 // Decode the SDNV-encoded query length. Note that we need to know the length of the |
204 // Decode the SDNV-encoded query length. Note that we need to know the length of the |
202 // of the encoded value and provide some pointers to the encoded value along with |
205 // of the encoded value and provide some pointers to the encoded value along with |
203 // where we want the decoded value (in this case, query_len_). |
206 // where we want the decoded value (in this case, query_len_). |
204 if ( i < len && |
207 if ( i < len && |
205 (decoding_len = SDNV::decode(&(buf[i]), len - i, &query_len_)) >= 0 ) |
208 (decoding_len = SDNV::decode(&(buf[i]), len - i, &query_len_)) >= 0 ) { |
206 i += decoding_len; |
209 i += decoding_len; |
|
210 log_debug_p(LOG, "BPQBlock::initialise: query len = %u", query_len_); |
|
211 } |
207 else |
212 else |
208 log_err_p(LOG, "Error decoding BPQ query length"); |
213 log_err_p(LOG, "Error decoding BPQ query length"); |
209 |
214 |
210 // query-value n-bytes |
215 // query-value n-bytes |
211 if ( (i+query_len_) < len ) { |
216 if ( (i+query_len_) < len ) { |
212 query_val_ = (u_char*) malloc ( sizeof(u_char) * query_len_ ); |
217 query_val_ = (u_char*) malloc ( sizeof(u_char) * query_len_ ); |
213 |
218 |
214 for (j=0; query_val_ != NULL && i < len && j < query_len_; i++, j++) |
219 for (j=0; query_val_ != NULL && i < len && j < query_len_; i++, j++) |
215 query_val_[j] = buf[i]; |
220 query_val_[j] = buf[i]; |
216 |
221 |
|
222 log_debug_p(LOG, "BPQBlock::initialise: query val = %s", query_val_); |
|
223 |
217 } else { |
224 } else { |
218 query_val_ = NULL; |
225 query_val_ = NULL; |
219 } |
226 } |
220 |
227 |
221 if ( i < len && |
228 if ( i < len && |
222 (decoding_len = SDNV::decode(&(buf[i]), len - i, &num_frags)) >= 0 ) |
229 (decoding_len = SDNV::decode(&(buf[i]), len - i, &num_frags)) >= 0 ) { |
223 i += decoding_len; |
230 i += decoding_len; |
|
231 log_debug_p(LOG, "BPQBlock::initialise: num frags = %u", num_frags); |
|
232 } |
224 else |
233 else |
225 log_err_p(LOG, "Error decoding BPQ fragment length"); |
234 log_err_p(LOG, "Error decoding BPQ fragment length"); |
226 |
235 |
227 // todo: Still need to handle fragments |
236 // todo: Still need to handle fragments |
228 // test assert - to be removed once we start handling fragments |
237 // test assert - to be removed once we start handling fragments |