xref: /csrg-svn/libexec/talkd/print.c (revision 34360)
1 /*
2  * Copyright (c) 1983 Regents of the University of California.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms are permitted
6  * provided that this notice is preserved and that due credit is given
7  * to the University of California at Berkeley. The name of the University
8  * may not be used to endorse or promote products derived from this
9  * software without specific prior written permission. This software
10  * is provided ``as is'' without express or implied warranty.
11  */
12 
13 #ifndef lint
14 static char sccsid[] = "@(#)print.c	5.5 (Berkeley) 05/20/88";
15 #endif /* not lint */
16 
17 /* debug print routines */
18 
19 #include <stdio.h>
20 #include <syslog.h>
21 #include <sys/param.h>
22 
23 #include <protocols/talkd.h>
24 
25 static	char *types[] =
26     { "leave_invite", "look_up", "delete", "announce" };
27 #define	NTYPES	(sizeof (types) / sizeof (types[0]))
28 static	char *answers[] =
29     { "success", "not_here", "failed", "machine_unknown", "permission_denied",
30       "unknown_request", "badversion", "badaddr", "badctladdr" };
31 #define	NANSWERS	(sizeof (answers) / sizeof (answers[0]))
32 
33 print_request(cp, mp)
34 	char *cp;
35 	register CTL_MSG *mp;
36 {
37 	char tbuf[80], *tp;
38 
39 	if (mp->type > NTYPES) {
40 		(void)sprintf(tbuf, "type %d", mp->type);
41 		tp = tbuf;
42 	} else
43 		tp = types[mp->type];
44 	syslog(LOG_DEBUG, "%s: %s: id %d, l_user %s, r_user %s, r_tty %s",
45 	    cp, tp, mp->id_num, mp->l_name, mp->r_name, mp->r_tty);
46 }
47 
48 print_response(cp, rp)
49 	char *cp;
50 	register CTL_RESPONSE *rp;
51 {
52 	char tbuf[80], *tp, abuf[80], *ap;
53 
54 	if (rp->type > NTYPES) {
55 		(void)sprintf(tbuf, "type %d", rp->type);
56 		tp = tbuf;
57 	} else
58 		tp = types[rp->type];
59 	if (rp->answer > NANSWERS) {
60 		(void)sprintf(abuf, "answer %d", rp->answer);
61 		ap = abuf;
62 	} else
63 		ap = answers[rp->answer];
64 	syslog(LOG_DEBUG, "%s: %s: %s, id %d", cp, tp, ap, ntohl(rp->id_num));
65 }
66