xref: /csrg-svn/libexec/talkd/print.c (revision 32103)
1 /*
2  * Copyright (c) 1983 Regents of the University of California.
3  * All rights reserved.  The Berkeley software License Agreement
4  * specifies the terms and conditions for redistribution.
5  */
6 
7 #ifndef lint
8 static char sccsid[] = "@(#)print.c	5.3 (Berkeley) 09/04/87";
9 #endif not lint
10 
11 /* debug print routines */
12 
13 #include <stdio.h>
14 #include <syslog.h>
15 #include <sys/param.h>
16 
17 #include <protocols/talkd.h>
18 
19 static	char *types[] =
20     { "leave_invite", "look_up", "delete", "announce" };
21 #define	NTYPES	(sizeof (types) / sizeof (types[0]))
22 static	char *answers[] =
23     { "success", "not_here", "failed", "machine_unknown", "permission_denied",
24       "unknown_request", "badversion", "badaddr", "badctladdr" };
25 #define	NANSWERS	(sizeof (answers) / sizeof (answers[0]))
26 
27 print_request(cp, mp)
28 	char *cp;
29 	register CTL_MSG *mp;
30 {
31 	char tbuf[80], *tp;
32 
33 	if (mp->type > NTYPES) {
34 		sprintf(tbuf, "type %d", mp->type);
35 		tp = tbuf;
36 	} else
37 		tp = types[mp->type];
38 	syslog(LOG_DEBUG, "%s: %s: id %d, l_user %s, r_user %s, r_tty %s",
39 	    cp, tp, mp->id_num, mp->l_name, mp->r_name, mp->r_tty);
40 }
41 
42 print_response(cp, rp)
43 	char *cp;
44 	register CTL_RESPONSE *rp;
45 {
46 	char tbuf[80], *tp, abuf[80], *ap;
47 
48 	if (rp->type > NTYPES) {
49 		sprintf(tbuf, "type %d", rp->type);
50 		tp = tbuf;
51 	} else
52 		tp = types[rp->type];
53 	if (rp->answer > NANSWERS) {
54 		sprintf(abuf, "answer %d", rp->answer);
55 		ap = abuf;
56 	} else
57 		ap = answers[rp->answer];
58 	syslog(LOG_DEBUG, "%s: %s: %s, id %d", cp, tp, ap, ntohl(rp->id_num));
59 }
60