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