1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
#ifndef SH_FIFO_H
#define SH_FIFO_H
/*****************************************************
*
* the maximum number of entries the fifo will hold
* - additional entries are simply not accepted -
*
*****************************************************/
#define SH_FIFO_MAX 16384
/*****************************************************
*
* the type definitions for the fifo
*
*****************************************************/
struct dlist {
struct dlist * next;
char * data;
char * s_xtra;
int i_xtra;
int transact;
struct dlist * prev;
};
typedef struct fifo_str {
struct dlist * head_ptr;
struct dlist * tail_ptr;
int fifo_cts;
} SH_FIFO;
#define SH_FIFO_INITIALIZER { NULL, NULL, 0 }
/*****************************************************
*
* fifo functions
*
*****************************************************/
/* Initialize the list.
*
*/
#define fifo_init(fifo_p) { (fifo_p)->fifo_cts = 0; (fifo_p)->head_ptr = NULL; \
(fifo_p)->tail_ptr = NULL; }
/* Push an item on the head of the list.
*
* Returns: -1 if the list is full, 0 on success
*/
int push_list (SH_FIFO * fifo, const char * indat, int in_i, const char * in_str);
#define sh_fifo_push(a, b) push_list((a), (b), 0, NULL)
/* Push an item on the tail of the list.
*
* Returns: -1 if the list is full, 0 on success
*/
int push_tail_list (SH_FIFO * fifo, const char * indat, int in_i, const char * in_str);
#define sh_fifo_push_tail(a, b) push_tail_list((a), (b), 0, NULL)
/* pop an item from the tail of the list
*
* Returns: NULL if the list is empty,
* freshly allocated memory on success (should be free'd by caller)
*/
char * pop_list (SH_FIFO * fifo);
#define sh_fifo_pop(a) pop_list((a))
/* ---- Special functions -------------------------------------------------*/
/* This is for eMail where different recipients may be eligible for *
* different subsets of messages. We need to delete all that were sent *
* to all intended recipients, and keep all with at least one failure. */
/* Iterate over list and check for each if it is valid for 'tag';
* i.e. (item->s_extra == tag). If yes, add to the returned string.
* If (okNull == False) then item->s_xtra must be defined
*/
sh_string * tag_list (SH_FIFO * fifo, char * tag,
int(*check)(int, const char*, const char*, const void*),
const void * info, int okNull);
/* Flag all tagged as candidate to keep */
void rollback_list (SH_FIFO * fifo);
/* Flag all tagged as candidate to delete */
void mark_list (SH_FIFO * fifo);
/* Remove all flags */
void reset_list (SH_FIFO * fifo);
/* Delete all marked for delete that are not flagged for keep */
int commit_list (SH_FIFO * fifo);
#endif
|