7 /* in-core recipient structures
9 /* #include <recipient_list.h>
21 /* struct QMGR_QUEUE *queue;
35 /* void recipient_list_init(list, variant)
36 /* RECIPIENT_LIST *list;
39 /* void recipient_list_add(list, offset, dsn_orcpt, dsn_notify,
40 /* orig_rcpt, recipient)
41 /* RECIPIENT_LIST *list;
43 /* const char *dsn_orcpt;
45 /* const char *orig_rcpt;
46 /* const char *recipient;
48 /* void recipient_list_swap(a, b)
52 /* void recipient_list_free(list)
53 /* RECIPIENT_LIST *list;
55 /* void RECIPIENT_ASSIGN(rcpt, offset, dsn_orcpt, dsn_notify,
56 /* orig_rcpt, recipient)
64 /* This module maintains lists of recipient structures. Each
65 /* recipient is characterized by a destination address and
66 /* by the queue file offset of its delivery status record.
67 /* The per-recipient status is initialized to zero, and exists
68 /* solely for the convenience of the application. It is not used
69 /* by the recipient_list module itself.
71 /* recipient_list_init() creates an empty recipient structure list.
72 /* The list argument is initialized such that it can be given to
73 /* recipient_list_add() and to recipient_list_free(). The variant
74 /* argument specifies how list elements should be initialized;
75 /* specify RCPT_LIST_INIT_STATUS to zero the status field, and
76 /* RCPT_LIST_INIT_QUEUE to zero the queue field.
78 /* recipient_list_add() adds a recipient to the specified list.
79 /* Recipient address information is copied with mystrdup().
81 /* recipient_list_swap() swaps the recipients between
82 /* the given two recipient lists.
84 /* recipient_list_free() releases memory for the specified list
85 /* of recipient structures.
87 /* RECIPIENT_ASSIGN() assigns the fields of a recipient structure
88 /* without making copies of its arguments.
92 /* Recipient list initialized by recipient_list_init().
94 /* Queue file offset of a recipient delivery status record.
96 /* DSN original recipient.
100 /* Recipient destination address.
102 /* recipient_list(3h) data structure
104 /* Fatal errors: memory allocation.
108 /* The Secure Mailer license must be distributed with this software.
111 /* IBM T.J. Watson Research
113 /* Yorktown Heights, NY 10598, USA
116 /* System library. */
118 #include <sys_defs.h>
120 /* Utility library. */
122 #include <mymalloc.h>
125 /* Global library. */
127 #include "recipient_list.h"
129 /* recipient_list_init - initialize */
131 void recipient_list_init(RECIPIENT_LIST
*list
, int variant
)
135 list
->info
= (RECIPIENT
*) mymalloc(sizeof(RECIPIENT
));
136 list
->variant
= variant
;
139 /* recipient_list_add - add rcpt to list */
141 void recipient_list_add(RECIPIENT_LIST
*list
, long offset
,
142 const char *dsn_orcpt
, int dsn_notify
,
143 const char *orig_rcpt
, const char *rcpt
)
147 if (list
->len
>= list
->avail
) {
148 new_avail
= list
->avail
* 2;
149 list
->info
= (RECIPIENT
*)
150 myrealloc((char *) list
->info
, new_avail
* sizeof(RECIPIENT
));
151 list
->avail
= new_avail
;
153 list
->info
[list
->len
].orig_addr
= mystrdup(orig_rcpt
);
154 list
->info
[list
->len
].address
= mystrdup(rcpt
);
155 list
->info
[list
->len
].offset
= offset
;
156 list
->info
[list
->len
].dsn_orcpt
= mystrdup(dsn_orcpt
);
157 list
->info
[list
->len
].dsn_notify
= dsn_notify
;
158 if (list
->variant
== RCPT_LIST_INIT_STATUS
)
159 list
->info
[list
->len
].u
.status
= 0;
160 else if (list
->variant
== RCPT_LIST_INIT_QUEUE
)
161 list
->info
[list
->len
].u
.queue
= 0;
162 else if (list
->variant
== RCPT_LIST_INIT_ADDR
)
163 list
->info
[list
->len
].u
.addr_type
= 0;
167 /* recipient_list_swap - swap recipients between the two recipient lists */
169 void recipient_list_swap(RECIPIENT_LIST
*a
, RECIPIENT_LIST
*b
)
171 if (b
->variant
!= a
->variant
)
172 msg_panic("recipient_lists_swap: incompatible recipient list variants");
174 #define SWAP(t, x) do { t x = b->x; b->x = a->x ; a->x = x; } while (0)
176 SWAP(RECIPIENT
*, info
);
181 /* recipient_list_free - release memory for in-core recipient structure */
183 void recipient_list_free(RECIPIENT_LIST
*list
)
187 for (rcpt
= list
->info
; rcpt
< list
->info
+ list
->len
; rcpt
++) {
188 myfree((char *) rcpt
->dsn_orcpt
);
189 myfree((char *) rcpt
->orig_addr
);
190 myfree((char *) rcpt
->address
);
192 myfree((char *) list
->info
);