xref: /freebsd/libexec/talkd/print.c (revision a6fe717c)
18a16b7a1SPedro F. Giffuni /*-
28a16b7a1SPedro F. Giffuni  * SPDX-License-Identifier: BSD-3-Clause
38a16b7a1SPedro F. Giffuni  *
4ea022d16SRodney W. Grimes  * Copyright (c) 1983, 1993
5ea022d16SRodney W. Grimes  *	The Regents of the University of California.  All rights reserved.
6ea022d16SRodney W. Grimes  *
7ea022d16SRodney W. Grimes  * Redistribution and use in source and binary forms, with or without
8ea022d16SRodney W. Grimes  * modification, are permitted provided that the following conditions
9ea022d16SRodney W. Grimes  * are met:
10ea022d16SRodney W. Grimes  * 1. Redistributions of source code must retain the above copyright
11ea022d16SRodney W. Grimes  *    notice, this list of conditions and the following disclaimer.
12ea022d16SRodney W. Grimes  * 2. Redistributions in binary form must reproduce the above copyright
13ea022d16SRodney W. Grimes  *    notice, this list of conditions and the following disclaimer in the
14ea022d16SRodney W. Grimes  *    documentation and/or other materials provided with the distribution.
155efaea4cSChristian Brueffer  * 3. Neither the name of the University nor the names of its contributors
16ea022d16SRodney W. Grimes  *    may be used to endorse or promote products derived from this software
17ea022d16SRodney W. Grimes  *    without specific prior written permission.
18ea022d16SRodney W. Grimes  *
19ea022d16SRodney W. Grimes  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20ea022d16SRodney W. Grimes  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21ea022d16SRodney W. Grimes  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22ea022d16SRodney W. Grimes  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23ea022d16SRodney W. Grimes  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24ea022d16SRodney W. Grimes  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25ea022d16SRodney W. Grimes  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26ea022d16SRodney W. Grimes  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27ea022d16SRodney W. Grimes  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28ea022d16SRodney W. Grimes  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29ea022d16SRodney W. Grimes  * SUCH DAMAGE.
30ea022d16SRodney W. Grimes  */
31ea022d16SRodney W. Grimes 
32ea022d16SRodney W. Grimes /* debug print routines */
33ea022d16SRodney W. Grimes 
34ea022d16SRodney W. Grimes #include <sys/types.h>
35ea022d16SRodney W. Grimes #include <sys/socket.h>
36fd8e4ebcSMike Barcroft #include <arpa/inet.h>
37ea022d16SRodney W. Grimes #include <protocols/talkd.h>
38ea022d16SRodney W. Grimes #include <stdio.h>
39a846453cSPhilippe Charnier #include <syslog.h>
40ea022d16SRodney W. Grimes 
410b67b493SWarner Losh #include "extern.h"
420b67b493SWarner Losh 
4302a0965eSJuli Mallett static	const char *types[] =
44ea022d16SRodney W. Grimes     { "leave_invite", "look_up", "delete", "announce" };
45ea022d16SRodney W. Grimes #define	NTYPES	(sizeof (types) / sizeof (types[0]))
4602a0965eSJuli Mallett static	const char *answers[] =
47ea022d16SRodney W. Grimes     { "success", "not_here", "failed", "machine_unknown", "permission_denied",
48ea022d16SRodney W. Grimes       "unknown_request", "badversion", "badaddr", "badctladdr" };
49ea022d16SRodney W. Grimes #define	NANSWERS	(sizeof (answers) / sizeof (answers[0]))
50ea022d16SRodney W. Grimes 
51a846453cSPhilippe Charnier void
print_request(const char * cp,CTL_MSG * mp)520b67b493SWarner Losh print_request(const char *cp, CTL_MSG *mp)
53ea022d16SRodney W. Grimes {
5402a0965eSJuli Mallett 	const char *tp;
5502a0965eSJuli Mallett 	char tbuf[80];
56ea022d16SRodney W. Grimes 
57ea022d16SRodney W. Grimes 	if (mp->type > NTYPES) {
58d8366258SWarner Losh 		(void)snprintf(tbuf, sizeof(tbuf), "type %d", mp->type);
59ea022d16SRodney W. Grimes 		tp = tbuf;
60ea022d16SRodney W. Grimes 	} else
61ea022d16SRodney W. Grimes 		tp = types[mp->type];
62bb6ae0a4SBruce Evans 	syslog(LOG_DEBUG, "%s: %s: id %lu, l_user %s, r_user %s, r_tty %s",
6302a0965eSJuli Mallett 	    cp, tp, (long)mp->id_num, mp->l_name, mp->r_name, mp->r_tty);
64ea022d16SRodney W. Grimes }
65ea022d16SRodney W. Grimes 
66a846453cSPhilippe Charnier void
print_response(const char * cp,CTL_RESPONSE * rp)670b67b493SWarner Losh print_response(const char *cp, CTL_RESPONSE *rp)
68ea022d16SRodney W. Grimes {
6902a0965eSJuli Mallett 	const char *tp, *ap;
7002a0965eSJuli Mallett 	char tbuf[80], abuf[80];
71ea022d16SRodney W. Grimes 
72ea022d16SRodney W. Grimes 	if (rp->type > NTYPES) {
73d8366258SWarner Losh 		(void)snprintf(tbuf, sizeof(tbuf), "type %d", rp->type);
74ea022d16SRodney W. Grimes 		tp = tbuf;
75ea022d16SRodney W. Grimes 	} else
76ea022d16SRodney W. Grimes 		tp = types[rp->type];
77ea022d16SRodney W. Grimes 	if (rp->answer > NANSWERS) {
78d8366258SWarner Losh 		(void)snprintf(abuf, sizeof(abuf), "answer %d", rp->answer);
79ea022d16SRodney W. Grimes 		ap = abuf;
80ea022d16SRodney W. Grimes 	} else
81ea022d16SRodney W. Grimes 		ap = answers[rp->answer];
82ea022d16SRodney W. Grimes 	syslog(LOG_DEBUG, "%s: %s: %s, id %d", cp, tp, ap, ntohl(rp->id_num));
83ea022d16SRodney W. Grimes }
84