]> rtime.felk.cvut.cz Git - frescor/fwp.git/blob - fwp/libfwp/src/fwp_ctable.c
79316d256763c3bd1535c3781c508e869cbc49bd
[frescor/fwp.git] / fwp / libfwp / src / fwp_ctable.c
1 #include "fwp_ctable.h"
2 #include <string.h>
3
4 void fwp_ctable_init(struct fwp_ctable* ctable)
5 {
6         unsigned int i;
7         
8         for (i = 0; i < FWP_CONTRACT_MAX; i++)
9                 ctable->entry[i].status = FWP_CTENTRY_EMPTY;
10
11 }
12
13 int fwp_ctable_put(struct fwp_ctable* ctable, struct fwp_ctable_entry* entry)
14 {
15         unsigned int id;
16         /* obtain fwp ctable mutex */
17         /* find free contract */
18         id = 0;
19         while ((ctable->entry[id].status != FWP_CTENTRY_EMPTY) && 
20                (id < FWP_CONTRACT_MAX))  id++;
21         
22         if (id == FWP_CONTRACT_MAX) {
23                 /* release fwp_contract_table mutex */
24                 return -1;
25         }
26         
27         memcpy(&ctable->entry[id], entry, sizeof(struct fwp_ctable_entry));
28         ctable->entry[id].status = FWP_CTENTRY_FULL;    
29         /* release fwp_contract_table mutex */
30         
31         return id;
32 }
33
34 struct fwp_ctable_entry* fwp_ctable_get(struct fwp_ctable* ctable, unsigned int id)
35 {
36         return (&ctable->entry[id]);
37 }
38
39 inline void fwp_ctable_remove(struct fwp_ctable* ctable, unsigned int id)
40 {
41         ctable->entry[id].status = FWP_CTENTRY_EMPTY;   
42 }
43