xref: /csrg-svn/libexec/talkd/print.c (revision 26839)
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.2 (Berkeley) 03/13/86";
9 #endif not lint
10 
11 /* debug print routines */
12 
13 #include <stdio.h>
14 #include <syslog.h>
15 
16 #include <protocols/talkd.h>
17 
18 static	char *types[] =
19     { "leave_invite", "look_up", "delete", "announce" };
20 #define	NTYPES	(sizeof (types) / sizeof (types[0]))
21 static	char *answers[] =
22     { "success", "not_here", "failed", "machine_unknown", "permission_denied",
23       "unknown_request", "badversion", "badaddr", "badctladdr" };
24 #define	NANSWERS	(sizeof (answers) / sizeof (answers[0]))
25 
26 print_request(cp, mp)
27 	char *cp;
28 	register CTL_MSG *mp;
29 {
30 	char tbuf[80], *tp;
31 
32 	if (mp->type > NTYPES) {
33 		sprintf(tbuf, "type %d", mp->type);
34 		tp = tbuf;
35 	} else
36 		tp = types[mp->type];
37 	syslog(LOG_DEBUG, "%s: %s: id %d, l_user %s, r_user %s, r_tty %s",
38 	    cp, tp, mp->id_num, mp->l_name, mp->r_name, mp->r_tty);
39 }
40 
41 print_response(cp, rp)
42 	char *cp;
43 	register CTL_RESPONSE *rp;
44 {
45 	char tbuf[80], *tp, abuf[80], *ap;
46 
47 	if (rp->type > NTYPES) {
48 		sprintf(tbuf, "type %d", rp->type);
49 		tp = tbuf;
50 	} else
51 		tp = types[rp->type];
52 	if (rp->answer > NANSWERS) {
53 		sprintf(abuf, "answer %d", rp->answer);
54 		ap = abuf;
55 	} else
56 		ap = answers[rp->answer];
57 	syslog(LOG_DEBUG, "%s: %s: %s, id %d", cp, tp, ap, ntohl(rp->id_num));
58 }
59