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