Home | History | Annotate | Line # | Download | only in talkd
print.c revision 1.8.28.1
      1  1.8.28.1       jym /*	$NetBSD: print.c,v 1.8.28.1 2009/05/13 19:18:43 jym 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.28.1       jym __RCSID("$NetBSD: print.c,v 1.8.28.1 2009/05/13 19:18:43 jym 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.8.28.1       jym #include <inttypes.h>
     47       1.1       cgd #include <syslog.h>
     48       1.1       cgd #include <stdio.h>
     49       1.4  christos #include "extern.h"
     50       1.1       cgd 
     51  1.8.28.1       jym static	const char *types[] = {
     52       1.5       mrg 	"leave_invite",
     53       1.5       mrg 	"look_up",
     54       1.5       mrg 	"delete",
     55       1.5       mrg 	"announce"
     56       1.5       mrg };
     57       1.1       cgd #define	NTYPES	(sizeof (types) / sizeof (types[0]))
     58       1.5       mrg 
     59  1.8.28.1       jym static	const char *answers[] = {
     60       1.5       mrg 	"success",
     61       1.5       mrg 	"not_here",
     62       1.5       mrg 	"failed",
     63       1.5       mrg 	"machine_unknown",
     64       1.5       mrg 	"permission_denied",
     65       1.5       mrg 	"unknown_request",
     66       1.5       mrg 	"badversion",
     67       1.5       mrg 	"badaddr",
     68       1.5       mrg 	"badctladdr"
     69       1.5       mrg };
     70       1.1       cgd #define	NANSWERS	(sizeof (answers) / sizeof (answers[0]))
     71       1.1       cgd 
     72       1.4  christos void
     73  1.8.28.1       jym print_request(const char *cp, CTL_MSG *mp)
     74       1.1       cgd {
     75  1.8.28.1       jym 	char tbuf[80];
     76  1.8.28.1       jym 	const char *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.8.28.1       jym 	    "%s: %s: id %"PRIu32", 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.8.28.1       jym print_response(const char *cp, CTL_RESPONSE *rp)
     90       1.1       cgd {
     91  1.8.28.1       jym 	char tbuf[80], abuf[80];
     92  1.8.28.1       jym 	const char *tp, *ap;
     93       1.1       cgd 
     94       1.8      elad 	if (rp->type >= NTYPES) {
     95       1.5       mrg 		(void)snprintf(tbuf, sizeof tbuf, "type %d", rp->type);
     96       1.1       cgd 		tp = tbuf;
     97       1.1       cgd 	} else
     98       1.1       cgd 		tp = types[rp->type];
     99       1.8      elad 	if (rp->answer >= NANSWERS) {
    100       1.5       mrg 		(void)snprintf(abuf, sizeof abuf, "answer %d", rp->answer);
    101       1.1       cgd 		ap = abuf;
    102       1.1       cgd 	} else
    103       1.1       cgd 		ap = answers[rp->answer];
    104  1.8.28.1       jym 	syslog(debug ? LOG_DEBUG : LOG_INFO, "%s: %s: %s, id %"PRIu32,
    105       1.6       mrg 	    cp, tp, ap, ntohl(rp->id_num));
    106       1.1       cgd }
    107