print.c revision 256281
1336817Sdim/* 2336817Sdim * Copyright (c) 1983, 1993 3353358Sdim * The Regents of the University of California. All rights reserved. 4353358Sdim * 5353358Sdim * Redistribution and use in source and binary forms, with or without 6336817Sdim * modification, are permitted provided that the following conditions 7336817Sdim * are met: 8336817Sdim * 1. Redistributions of source code must retain the above copyright 9336817Sdim * notice, this list of conditions and the following disclaimer. 10336817Sdim * 2. Redistributions in binary form must reproduce the above copyright 11336817Sdim * notice, this list of conditions and the following disclaimer in the 12336817Sdim * documentation and/or other materials provided with the distribution. 13336817Sdim * 3. All advertising materials mentioning features or use of this software 14336817Sdim * must display the following acknowledgement: 15336817Sdim * This product includes software developed by the University of 16336817Sdim * California, Berkeley and its contributors. 17336817Sdim * 4. Neither the name of the University nor the names of its contributors 18336817Sdim * may be used to endorse or promote products derived from this software 19336817Sdim * without specific prior written permission. 20336817Sdim * 21336817Sdim * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22336817Sdim * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23336817Sdim * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24336817Sdim * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25336817Sdim * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26336817Sdim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27336817Sdim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28336817Sdim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29336817Sdim * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30336817Sdim * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31336817Sdim * SUCH DAMAGE. 32353358Sdim */ 33336817Sdim 34336817Sdim#ifndef lint 35353358Sdim#if 0 36336817Sdimstatic char sccsid[] = "@(#)print.c 8.1 (Berkeley) 6/4/93"; 37336817Sdim#endif 38336817Sdimstatic const char rcsid[] = 39336817Sdim "$FreeBSD: stable/10/libexec/talkd/print.c 112998 2003-04-03 05:13:27Z jmallett $"; 40353358Sdim#endif /* not lint */ 41353358Sdim 42353358Sdim/* debug print routines */ 43353358Sdim 44353358Sdim#include <sys/types.h> 45353358Sdim#include <sys/socket.h> 46353358Sdim#include <arpa/inet.h> 47353358Sdim#include <protocols/talkd.h> 48353358Sdim#include <stdio.h> 49353358Sdim#include <syslog.h> 50353358Sdim 51353358Sdim#include "extern.h" 52353358Sdim 53353358Sdimstatic const char *types[] = 54353358Sdim { "leave_invite", "look_up", "delete", "announce" }; 55353358Sdim#define NTYPES (sizeof (types) / sizeof (types[0])) 56353358Sdimstatic const char *answers[] = 57353358Sdim { "success", "not_here", "failed", "machine_unknown", "permission_denied", 58353358Sdim "unknown_request", "badversion", "badaddr", "badctladdr" }; 59353358Sdim#define NANSWERS (sizeof (answers) / sizeof (answers[0])) 60353358Sdim 61353358Sdimvoid 62353358Sdimprint_request(const char *cp, CTL_MSG *mp) 63353358Sdim{ 64353358Sdim const char *tp; 65353358Sdim char tbuf[80]; 66353358Sdim 67353358Sdim if (mp->type > NTYPES) { 68353358Sdim (void)snprintf(tbuf, sizeof(tbuf), "type %d", mp->type); 69353358Sdim tp = tbuf; 70353358Sdim } else 71353358Sdim tp = types[mp->type]; 72353358Sdim syslog(LOG_DEBUG, "%s: %s: id %lu, l_user %s, r_user %s, r_tty %s", 73353358Sdim cp, tp, (long)mp->id_num, mp->l_name, mp->r_name, mp->r_tty); 74353358Sdim} 75353358Sdim 76353358Sdimvoid 77353358Sdimprint_response(const char *cp, CTL_RESPONSE *rp) 78353358Sdim{ 79353358Sdim const char *tp, *ap; 80353358Sdim char tbuf[80], abuf[80]; 81353358Sdim 82353358Sdim if (rp->type > NTYPES) { 83353358Sdim (void)snprintf(tbuf, sizeof(tbuf), "type %d", rp->type); 84353358Sdim tp = tbuf; 85353358Sdim } else 86353358Sdim tp = types[rp->type]; 87353358Sdim if (rp->answer > NANSWERS) { 88353358Sdim (void)snprintf(abuf, sizeof(abuf), "answer %d", rp->answer); 89353358Sdim ap = abuf; 90353358Sdim } else 91353358Sdim ap = answers[rp->answer]; 92353358Sdim syslog(LOG_DEBUG, "%s: %s: %s, id %d", cp, tp, ap, ntohl(rp->id_num)); 93353358Sdim} 94353358Sdim