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