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