]>
git.saurik.com Git - apple/network_cmds.git/blob - talkd.tproj/announce.c
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.0 (the 'License'). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
14 * The Original Code and all software distributed under the License are
15 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
22 * @APPLE_LICENSE_HEADER_END@
25 * Copyright (c) 1983, 1993
26 * The Regents of the University of California. All rights reserved.
28 * Redistribution and use in source and binary forms, with or without
29 * modification, are permitted provided that the following conditions
31 * 1. Redistributions of source code must retain the above copyright
32 * notice, this list of conditions and the following disclaimer.
33 * 2. Redistributions in binary form must reproduce the above copyright
34 * notice, this list of conditions and the following disclaimer in the
35 * documentation and/or other materials provided with the distribution.
36 * 3. All advertising materials mentioning features or use of this software
37 * must display the following acknowledgement:
38 * This product includes software developed by the University of
39 * California, Berkeley and its contributors.
40 * 4. Neither the name of the University nor the names of its contributors
41 * may be used to endorse or promote products derived from this software
42 * without specific prior written permission.
44 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
45 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
46 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
47 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
48 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
49 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
50 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
51 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
52 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
53 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58 static char sccsid
[] = "@(#)announce.c 8.3 (Berkeley) 1/7/94";
61 #include <sys/types.h>
66 #include <sys/socket.h>
67 #include <protocols/talkd.h>
79 extern char hostname
[];
81 int print_mesg
__P((char *tty
, CTL_MSG
*request
, char *remote_machine
));
84 * Announce an invitation to talk.
88 * See if the user is accepting messages. If so, announce that
89 * a talk is requested.
92 announce(request
, remote_machine
)
99 (void)snprintf(full_tty
, sizeof(full_tty
),
100 "%s%s", _PATH_DEV
, request
->r_tty
);
101 if (stat(full_tty
, &stbuf
) < 0 || (stbuf
.st_mode
&020) == 0)
102 return (PERMISSION_DENIED
);
103 return (print_mesg(request
->r_tty
, request
, remote_machine
));
106 #define max(a,b) ( (a) > (b) ? (a) : (b) )
111 * Build a block of characters containing the message.
112 * It is sent blank filled and in a single block to
113 * try to keep the message in one piece if the recipient
114 * in in vi at the time
117 print_mesg(tty
, request
, remote_machine
)
120 char *remote_machine
;
122 struct timeval clock
;
123 struct timezone zone
;
124 struct tm
*localtime();
125 struct tm
*localclock
;
127 char line_buf
[N_LINES
][N_CHARS
];
129 char big_buf
[N_LINES
*N_CHARS
];
130 char *bptr
, *lptr
, *vis_user
;
135 gettimeofday(&clock
, &zone
);
136 localclock
= localtime( &clock
.tv_sec
);
137 (void)snprintf(line_buf
[i
], N_CHARS
, " ");
138 sizes
[i
] = strlen(line_buf
[i
]);
139 max_size
= max(max_size
, sizes
[i
]);
141 (void)snprintf(line_buf
[i
], N_CHARS
,
142 "Message from Talk_Daemon@%s at %d:%02d ...",
143 hostname
, localclock
->tm_hour
, localclock
->tm_min
);
144 sizes
[i
] = strlen(line_buf
[i
]);
145 max_size
= max(max_size
, sizes
[i
]);
148 vis_user
= malloc(strlen(request
->l_name
) * 4 + 1);
149 strvis(vis_user
, request
->l_name
, VIS_CSTYLE
);
150 (void)snprintf(line_buf
[i
], N_CHARS
,
151 "talk: connection requested by %s@%s", vis_user
, remote_machine
);
152 sizes
[i
] = strlen(line_buf
[i
]);
153 max_size
= max(max_size
, sizes
[i
]);
155 (void)snprintf(line_buf
[i
], N_CHARS
, "talk: respond with: talk %s@%s",
156 vis_user
, remote_machine
);
157 sizes
[i
] = strlen(line_buf
[i
]);
158 max_size
= max(max_size
, sizes
[i
]);
160 (void)snprintf(line_buf
[i
], N_CHARS
, " ");
161 sizes
[i
] = strlen(line_buf
[i
]);
162 max_size
= max(max_size
, sizes
[i
]);
165 *bptr
++ = '\a'; /* send something to wake them up */
166 *bptr
++ = '\r'; /* add a \r in case of raw mode */
168 for (i
= 0; i
< N_LINES
; i
++) {
169 /* copy the line into the big buffer */
171 while (*lptr
!= '\0')
172 *(bptr
++) = *(lptr
++);
173 /* pad out the rest of the lines with blanks */
174 for (j
= sizes
[i
]; j
< max_size
+ 2; j
++)
176 *(bptr
++) = '\r'; /* add a \r in case of raw mode */
180 iovec
.iov_base
= big_buf
;
181 iovec
.iov_len
= bptr
- big_buf
;
183 * we choose a timeout of RING_WAIT-5 seconds so that we don't
184 * stack up processes trying to write messages to a tty
185 * that is permanently blocked.
187 if (ttymsg(&iovec
, 1, tty
, RING_WAIT
- 5) != NULL
)