1 #include "../../../burp.h"
2 #include "../../../alloc.h"
3 #include "incoming.h"
4 
incoming_alloc(void)5 struct incoming *incoming_alloc(void)
6 {
7 	return (struct incoming *)calloc_w(1,
8 		sizeof(struct incoming), __func__);
9 }
10 
incoming_free_content(struct incoming * in)11 static void incoming_free_content(struct incoming *in)
12 {
13 	free_v((void **)&in->fingerprints);
14 	free_v((void **)&in->found);
15 }
16 
incoming_free(struct incoming ** in)17 void incoming_free(struct incoming **in)
18 {
19 	if(!in || !*in) return;
20 	incoming_free_content(*in);
21 	free_v((void **)in);
22 }
23 
incoming_grow_maybe(struct incoming * in)24 int incoming_grow_maybe(struct incoming *in)
25 {
26 	if(++in->size<in->allocated) return 0;
27 	// Make the incoming array bigger.
28 	in->allocated+=32;
29 //printf("grow incoming to %d\n", in->allocated);
30 	if((in->fingerprints=(uint64_t *)
31 		realloc_w(in->fingerprints,
32 			in->allocated*sizeof(uint64_t), __func__))
33 	  && (in->found=(uint8_t *)
34 		realloc_w(in->found, in->allocated*sizeof(uint8_t), __func__)))
35 			return 0;
36 	return -1;
37 }
38 
incoming_found_reset(struct incoming * in)39 void incoming_found_reset(struct incoming *in)
40 {
41 	in->got=0;
42 	if(!in->found || !in->size) return;
43 	memset(in->found, 0, sizeof(in->found[0])*in->size);
44 }
45