File: pop_msg.c

package info (click to toggle)
heimdal 1.6~git20120403%2Bdfsg1-2
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 34,428 kB
  • sloc: ansic: 338,234; sh: 7,993; makefile: 4,671; yacc: 3,036; perl: 1,888; python: 748; lex: 731; awk: 465; java: 119; asm: 30; lisp: 29
file content (57 lines) | stat: -rw-r--r-- 1,432 bytes parent folder | download | duplicates (2)
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
/*
 * Copyright (c) 1989 Regents of the University of California.
 * All rights reserved.  The Berkeley software License Agreement
 * specifies the terms and conditions for redistribution.
 */

#include <popper.h>
RCSID("$Id$");

/*
 *  msg:    Send a formatted line to the POP client
 */

int
pop_msg(POP *p, int stat, const char *format, ...)
{
    char	       *mp;
    char                message[MAXLINELEN];
    va_list             ap;

    va_start(ap, format);

    /*  Point to the message buffer */
    mp = message;

    /*  Format the POP status code at the beginning of the message */
    snprintf (mp, sizeof(message), "%s ",
	      (stat == POP_SUCCESS) ? POP_OK : POP_ERR);

    /*  Point past the POP status indicator in the message message */
    mp += strlen(mp);

    /*  Append the message (formatted, if necessary) */
    if (format)
	vsnprintf (mp, sizeof(message) - strlen(message),
		   format, ap);

    /*  Log the message if debugging is turned on */
#ifdef DEBUG
    if (p->debug && stat == POP_SUCCESS)
        pop_log(p,POP_DEBUG,"%s",message);
#endif /* DEBUG */

    /*  Log the message if a failure occurred */
    if (stat != POP_SUCCESS)
        pop_log(p,POP_PRIORITY,"%s",message);

    /*  Append the <CR><LF> */
    strlcat(message, "\r\n", sizeof(message));

    /*  Send the message to the client */
    fputs(message, p->output);
    fflush(p->output);

    va_end(ap);
    return(stat);
}