1 /*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
23 /* All Rights Reserved */
24
25 /* from OpenSolaris "pushlist.c 1.8 05/06/08 SMI" */
26
27 /*
28 * Portions Copyright (c) 2005 Gunnar Ritter, Freiburg i. Br., Germany
29 *
30 * Sccsid @(#)pushlist.c 1.4 (gritter) 6/18/05
31 */
32
33 #include "mail.h"
34 /*
35 * link new entry into list of headerlines encountered of this type.
36 * If contflg == TRUE, link this line to the end of the continuation lines
37 * for the headerline specified (head or tail of type hdrtype).
38 */
39 void
pushlist(register int hdrtype,register int where,register char * s,int contflg)40 pushlist(register int hdrtype, register int where, register char *s, int contflg)
41 {
42 static char pn[] = "pushlist";
43 char *p;
44 struct hdrs *nhp, *ohp, *nextcont;
45
46 /* Keep track of total bytes added to message due to */
47 /* certain lines in case non-delivery */
48 /* notification needs to be sent. (See also copylet()) */
49 if (hdrtype == H_AFWDFROM) {
50 affbytecnt += (strlen(s) + ((contflg == TRUE) ?
51 1 :
52 (strlen(header[H_AFWDFROM].tag) + 2)) );
53 if (contflg == FALSE) {
54 affcnt++;
55 }
56 }
57 if (hdrtype == H_RECEIVED) {
58 rcvbytecnt += (strlen(s) + ((contflg == TRUE) ?
59 1 :
60 (strlen(header[H_RECEIVED].tag) + 2)) );
61 }
62 if ((p = malloc(sizeof(struct hdrs))) == (char *)NULL) {
63 errmsg(E_MEM,"malloc failed in pushlist()");
64 done(1);
65 }
66 memset(p, 0, sizeof(struct hdrs));
67
68 ohp = (where == HEAD ? hdrlines[hdrtype].head : hdrlines[hdrtype].tail);
69 nhp = (struct hdrs *)p;
70
71 snprintf(nhp->value, sizeof nhp->value, "%s", s);
72
73 Dout(pn, 0, "hdrtype = %d/%s, contflg = %d, saved value = '%s'\n",
74 hdrtype, header[hdrtype].tag, contflg, s);
75
76 if (contflg) {
77 if (ohp == (struct hdrs *)NULL) {
78 /* This shouldn't happen.....? */
79 /* No headline of this type found so far. How */
80 /* did we think this is a continuation of something? */
81 if (debug > 0) {
82 Dout(pn, 0, "H_CONT with no hdr yet\n");
83 abort();
84 }
85 /* Throw it on the floor... (!) */
86 /**/
87 /* Subtract anything that might have been added above */
88 if (hdrtype == H_AFWDFROM) {
89 affbytecnt -= (strlen(s) + ((contflg == TRUE) ?
90 1 :
91 (strlen(header[H_AFWDFROM].tag) + 2)) );
92 }
93 if (hdrtype == H_RECEIVED) {
94 rcvbytecnt -= (strlen(s) + ((contflg == TRUE) ?
95 1 :
96 (strlen(header[H_RECEIVED].tag) + 2)) );
97 }
98 free ((char *)nhp);
99 return;
100 }
101 /* Since we ONLY walk down 'cont' chains, */
102 /* we only need forward links */
103 nextcont = ohp;
104 while (nextcont->cont != (struct hdrs *)NULL) {
105 nextcont = nextcont->cont;
106 }
107 /* Add this one to end of list... */
108 nextcont->cont = nhp;
109 return;
110 }
111
112 /* link value from this header line to end of list for */
113 /* all header lines of the same type */
114
115 if (ohp == (struct hdrs *)NULL) {
116 /* Empty list so far. New element goes first */
117 hdrlines[hdrtype].head = hdrlines[hdrtype].tail = nhp;
118 } else {
119 if (where == HEAD) {
120 /* Add new element to head of list */
121 nhp->next = ohp;
122 hdrlines[hdrtype].head = ohp->prev = nhp;
123 } else {
124 /* Add new element to tail of list */
125 nhp->prev = ohp;
126 hdrlines[hdrtype].tail = ohp->next = nhp;
127 }
128 }
129 }
130