print.c revision 31978
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[] = 3931978Simp "$Id: print.c,v 1.6 1997/12/02 12:33:17 charnier Exp $"; 401592Srgrimes#endif /* not lint */ 411592Srgrimes 421592Srgrimes/* debug print routines */ 431592Srgrimes 441592Srgrimes#include <sys/types.h> 451592Srgrimes#include <sys/socket.h> 461592Srgrimes#include <protocols/talkd.h> 4731491Scharnier#include <stdio.h> 481592Srgrimes#include <syslog.h> 491592Srgrimes 501592Srgrimesstatic char *types[] = 511592Srgrimes { "leave_invite", "look_up", "delete", "announce" }; 521592Srgrimes#define NTYPES (sizeof (types) / sizeof (types[0])) 538870Srgrimesstatic char *answers[] = 541592Srgrimes { "success", "not_here", "failed", "machine_unknown", "permission_denied", 551592Srgrimes "unknown_request", "badversion", "badaddr", "badctladdr" }; 561592Srgrimes#define NANSWERS (sizeof (answers) / sizeof (answers[0])) 571592Srgrimes 5831491Scharniervoid 591592Srgrimesprint_request(cp, mp) 601592Srgrimes char *cp; 611592Srgrimes register CTL_MSG *mp; 621592Srgrimes{ 631592Srgrimes char tbuf[80], *tp; 648870Srgrimes 651592Srgrimes if (mp->type > NTYPES) { 6631978Simp (void)snprintf(tbuf, sizeof(tbuf), "type %d", mp->type); 671592Srgrimes tp = tbuf; 681592Srgrimes } else 691592Srgrimes tp = types[mp->type]; 701592Srgrimes syslog(LOG_DEBUG, "%s: %s: id %d, l_user %s, r_user %s, r_tty %s", 711592Srgrimes cp, tp, mp->id_num, mp->l_name, mp->r_name, mp->r_tty); 721592Srgrimes} 731592Srgrimes 7431491Scharniervoid 751592Srgrimesprint_response(cp, rp) 761592Srgrimes char *cp; 771592Srgrimes register CTL_RESPONSE *rp; 781592Srgrimes{ 791592Srgrimes char tbuf[80], *tp, abuf[80], *ap; 808870Srgrimes 811592Srgrimes if (rp->type > NTYPES) { 8231978Simp (void)snprintf(tbuf, sizeof(tbuf), "type %d", rp->type); 831592Srgrimes tp = tbuf; 841592Srgrimes } else 851592Srgrimes tp = types[rp->type]; 861592Srgrimes if (rp->answer > NANSWERS) { 8731978Simp (void)snprintf(abuf, sizeof(abuf), "answer %d", rp->answer); 881592Srgrimes ap = abuf; 891592Srgrimes } else 901592Srgrimes ap = answers[rp->answer]; 911592Srgrimes syslog(LOG_DEBUG, "%s: %s: %s, id %d", cp, tp, ap, ntohl(rp->id_num)); 921592Srgrimes} 93