11592Srgrimes/*
21592Srgrimes * Copyright (c) 1983, 1993
31592Srgrimes *	The Regents of the University of California.  All rights reserved.
41592Srgrimes *
51592Srgrimes * Redistribution and use in source and binary forms, with or without
61592Srgrimes * modification, are permitted provided that the following conditions
71592Srgrimes * are met:
81592Srgrimes * 1. Redistributions of source code must retain the above copyright
91592Srgrimes *    notice, this list of conditions and the following disclaimer.
101592Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
111592Srgrimes *    notice, this list of conditions and the following disclaimer in the
121592Srgrimes *    documentation and/or other materials provided with the distribution.
131592Srgrimes * 3. All advertising materials mentioning features or use of this software
141592Srgrimes *    must display the following acknowledgement:
151592Srgrimes *	This product includes software developed by the University of
161592Srgrimes *	California, Berkeley and its contributors.
171592Srgrimes * 4. Neither the name of the University nor the names of its contributors
181592Srgrimes *    may be used to endorse or promote products derived from this software
191592Srgrimes *    without specific prior written permission.
201592Srgrimes *
211592Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
221592Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
231592Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
241592Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
251592Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
261592Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
271592Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
281592Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
291592Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
301592Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
311592Srgrimes * SUCH DAMAGE.
321592Srgrimes */
331592Srgrimes
341592Srgrimes#ifndef lint
3531491Scharnier#if 0
361592Srgrimesstatic char sccsid[] = "@(#)print.c	8.1 (Berkeley) 6/4/93";
3731491Scharnier#endif
3831491Scharnierstatic const char rcsid[] =
3950476Speter  "$FreeBSD$";
401592Srgrimes#endif /* not lint */
411592Srgrimes
421592Srgrimes/* debug print routines */
431592Srgrimes
441592Srgrimes#include <sys/types.h>
451592Srgrimes#include <sys/socket.h>
4690868Smike#include <arpa/inet.h>
471592Srgrimes#include <protocols/talkd.h>
4831491Scharnier#include <stdio.h>
491592Srgrimes#include <syslog.h>
501592Srgrimes
5190261Simp#include "extern.h"
5290261Simp
53112998Sjmallettstatic	const char *types[] =
541592Srgrimes    { "leave_invite", "look_up", "delete", "announce" };
551592Srgrimes#define	NTYPES	(sizeof (types) / sizeof (types[0]))
56112998Sjmallettstatic	const char *answers[] =
571592Srgrimes    { "success", "not_here", "failed", "machine_unknown", "permission_denied",
581592Srgrimes      "unknown_request", "badversion", "badaddr", "badctladdr" };
591592Srgrimes#define	NANSWERS	(sizeof (answers) / sizeof (answers[0]))
601592Srgrimes
6131491Scharniervoid
6290261Simpprint_request(const char *cp, CTL_MSG *mp)
631592Srgrimes{
64112998Sjmallett	const char *tp;
65112998Sjmallett	char tbuf[80];
668870Srgrimes
671592Srgrimes	if (mp->type > NTYPES) {
6831978Simp		(void)snprintf(tbuf, sizeof(tbuf), "type %d", mp->type);
691592Srgrimes		tp = tbuf;
701592Srgrimes	} else
711592Srgrimes		tp = types[mp->type];
7238024Sbde	syslog(LOG_DEBUG, "%s: %s: id %lu, l_user %s, r_user %s, r_tty %s",
73112998Sjmallett	    cp, tp, (long)mp->id_num, mp->l_name, mp->r_name, mp->r_tty);
741592Srgrimes}
751592Srgrimes
7631491Scharniervoid
7790261Simpprint_response(const char *cp, CTL_RESPONSE *rp)
781592Srgrimes{
79112998Sjmallett	const char *tp, *ap;
80112998Sjmallett	char tbuf[80], abuf[80];
818870Srgrimes
821592Srgrimes	if (rp->type > NTYPES) {
8331978Simp		(void)snprintf(tbuf, sizeof(tbuf), "type %d", rp->type);
841592Srgrimes		tp = tbuf;
851592Srgrimes	} else
861592Srgrimes		tp = types[rp->type];
871592Srgrimes	if (rp->answer > NANSWERS) {
8831978Simp		(void)snprintf(abuf, sizeof(abuf), "answer %d", rp->answer);
891592Srgrimes		ap = abuf;
901592Srgrimes	} else
911592Srgrimes		ap = answers[rp->answer];
921592Srgrimes	syslog(LOG_DEBUG, "%s: %s: %s, id %d", cp, tp, ap, ntohl(rp->id_num));
931592Srgrimes}
94