print.c revision 112998
118334Speter/* 218334Speter * Copyright (c) 1983, 1993 318334Speter * The Regents of the University of California. All rights reserved. 418334Speter * 518334Speter * Redistribution and use in source and binary forms, with or without 618334Speter * modification, are permitted provided that the following conditions 718334Speter * are met: 818334Speter * 1. Redistributions of source code must retain the above copyright 918334Speter * notice, this list of conditions and the following disclaimer. 1018334Speter * 2. Redistributions in binary form must reproduce the above copyright 1118334Speter * notice, this list of conditions and the following disclaimer in the 1218334Speter * documentation and/or other materials provided with the distribution. 1318334Speter * 3. All advertising materials mentioning features or use of this software 1418334Speter * must display the following acknowledgement: 1518334Speter * This product includes software developed by the University of 1618334Speter * California, Berkeley and its contributors. 1718334Speter * 4. Neither the name of the University nor the names of its contributors 1818334Speter * may be used to endorse or promote products derived from this software 1918334Speter * without specific prior written permission. 2018334Speter * 2118334Speter * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2218334Speter * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2318334Speter * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2418334Speter * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2518334Speter * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2618334Speter * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2718334Speter * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2818334Speter * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2918334Speter * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3018334Speter * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3118334Speter * SUCH DAMAGE. 3218334Speter */ 3318334Speter 3418334Speter#ifndef lint 3518334Speter#if 0 3618334Speterstatic char sccsid[] = "@(#)print.c 8.1 (Berkeley) 6/4/93"; 3718334Speter#endif 3818334Speterstatic const char rcsid[] = 3918334Speter "$FreeBSD: head/libexec/talkd/print.c 112998 2003-04-03 05:13:27Z jmallett $"; 4018334Speter#endif /* not lint */ 4118334Speter 4218334Speter/* debug print routines */ 4318334Speter 4418334Speter#include <sys/types.h> 4518334Speter#include <sys/socket.h> 4618334Speter#include <arpa/inet.h> 4718334Speter#include <protocols/talkd.h> 4818334Speter#include <stdio.h> 4918334Speter#include <syslog.h> 5018334Speter 5118334Speter#include "extern.h" 5218334Speter 5318334Speterstatic const char *types[] = 5418334Speter { "leave_invite", "look_up", "delete", "announce" }; 5518334Speter#define NTYPES (sizeof (types) / sizeof (types[0])) 5618334Speterstatic const char *answers[] = 5718334Speter { "success", "not_here", "failed", "machine_unknown", "permission_denied", 5818334Speter "unknown_request", "badversion", "badaddr", "badctladdr" }; 5918334Speter#define NANSWERS (sizeof (answers) / sizeof (answers[0])) 6018334Speter 6118334Spetervoid 6218334Speterprint_request(const char *cp, CTL_MSG *mp) 6318334Speter{ 6418334Speter const char *tp; 6518334Speter char tbuf[80]; 6618334Speter 6718334Speter if (mp->type > NTYPES) { 6818334Speter (void)snprintf(tbuf, sizeof(tbuf), "type %d", mp->type); 6918334Speter tp = tbuf; 7018334Speter } else 7118334Speter tp = types[mp->type]; 7218334Speter syslog(LOG_DEBUG, "%s: %s: id %lu, l_user %s, r_user %s, r_tty %s", 7318334Speter cp, tp, (long)mp->id_num, mp->l_name, mp->r_name, mp->r_tty); 7418334Speter} 7518334Speter 7618334Spetervoid 7718334Speterprint_response(const char *cp, CTL_RESPONSE *rp) 7818334Speter{ 7918334Speter const char *tp, *ap; 8018334Speter char tbuf[80], abuf[80]; 8118334Speter 8218334Speter if (rp->type > NTYPES) { 8318334Speter (void)snprintf(tbuf, sizeof(tbuf), "type %d", rp->type); 8418334Speter tp = tbuf; 8518334Speter } else 8618334Speter tp = types[rp->type]; 8718334Speter if (rp->answer > NANSWERS) { 8818334Speter (void)snprintf(abuf, sizeof(abuf), "answer %d", rp->answer); 8918334Speter ap = abuf; 9018334Speter } else 9118334Speter ap = answers[rp->answer]; 9218334Speter syslog(LOG_DEBUG, "%s: %s: %s, id %d", cp, tp, ap, ntohl(rp->id_num)); 9318334Speter} 9418334Speter