announce.c (9c6077500415e049d1458d89bfe54e111281f485) | announce.c (a846453c5ebbf21be4af27ac1e1679a3c00d8103) |
---|---|
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 --- 18 unchanged lines hidden (view full) --- 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 */ 33 34#ifndef lint | 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 --- 18 unchanged lines hidden (view full) --- 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 */ 33 34#ifndef lint |
35#if 0 |
|
35static char sccsid[] = "@(#)announce.c 8.3 (Berkeley) 4/28/95"; | 36static char sccsid[] = "@(#)announce.c 8.3 (Berkeley) 4/28/95"; |
37#endif 38static const char rcsid[] = 39 "$Id$"; |
|
36#endif /* not lint */ 37 38#include <sys/types.h> 39#include <sys/uio.h> 40#include <sys/stat.h> 41#include <sys/time.h> 42#include <sys/wait.h> 43#include <sys/socket.h> | 40#endif /* not lint */ 41 42#include <sys/types.h> 43#include <sys/uio.h> 44#include <sys/stat.h> 45#include <sys/time.h> 46#include <sys/wait.h> 47#include <sys/socket.h> |
48 |
|
44#include <protocols/talkd.h> | 49#include <protocols/talkd.h> |
45#include <sgtty.h> | 50 |
46#include <errno.h> | 51#include <errno.h> |
47#include <syslog.h> 48#include <unistd.h> | 52#include <paths.h> |
49#include <stdio.h> | 53#include <stdio.h> |
54#include <stdlib.h> |
|
50#include <string.h> | 55#include <string.h> |
56#include <syslog.h> 57#include <unistd.h> |
|
51#include <vis.h> | 58#include <vis.h> |
52#include <paths.h> | |
53 54extern char hostname[]; 55 | 59 60extern char hostname[]; 61 |
62int print_mesg __P((char *, FILE *, CTL_MSG *, char *)); 63char *ttymsg __P((struct iovec *, int, char *, int)); 64 |
|
56/* 57 * Announce an invitation to talk. 58 */ | 65/* 66 * Announce an invitation to talk. 67 */ |
59 | 68 |
60/* | 69/* |
61 * See if the user is accepting messages. If so, announce that | 70 * See if the user is accepting messages. If so, announce that |
62 * a talk is requested. 63 */ | 71 * a talk is requested. 72 */ |
73int |
|
64announce(request, remote_machine) 65 CTL_MSG *request; 66 char *remote_machine; 67{ 68 char full_tty[32]; 69 FILE *tf; 70 struct stat stbuf; 71 --- 4 unchanged lines hidden (view full) --- 76 return (print_mesg(request->r_tty, tf, request, remote_machine)); 77} 78 79#define max(a,b) ( (a) > (b) ? (a) : (b) ) 80#define N_LINES 5 81#define N_CHARS 256 82 83/* | 74announce(request, remote_machine) 75 CTL_MSG *request; 76 char *remote_machine; 77{ 78 char full_tty[32]; 79 FILE *tf; 80 struct stat stbuf; 81 --- 4 unchanged lines hidden (view full) --- 86 return (print_mesg(request->r_tty, tf, request, remote_machine)); 87} 88 89#define max(a,b) ( (a) > (b) ? (a) : (b) ) 90#define N_LINES 5 91#define N_CHARS 256 92 93/* |
84 * Build a block of characters containing the message. | 94 * Build a block of characters containing the message. |
85 * It is sent blank filled and in a single block to 86 * try to keep the message in one piece if the recipient 87 * in in vi at the time 88 */ | 95 * It is sent blank filled and in a single block to 96 * try to keep the message in one piece if the recipient 97 * in in vi at the time 98 */ |
99int |
|
89print_mesg(tty, tf, request, remote_machine) 90 char *tty; 91 FILE *tf; 92 CTL_MSG *request; 93 char *remote_machine; 94{ 95 struct timeval clock; 96 struct timezone zone; --- 5 unchanged lines hidden (view full) --- 102 char big_buf[N_LINES*N_CHARS]; 103 char *bptr, *lptr, *vis_user; 104 int i, j, max_size; 105 106 i = 0; 107 max_size = 0; 108 gettimeofday(&clock, &zone); 109 localclock = localtime( &clock.tv_sec ); | 100print_mesg(tty, tf, request, remote_machine) 101 char *tty; 102 FILE *tf; 103 CTL_MSG *request; 104 char *remote_machine; 105{ 106 struct timeval clock; 107 struct timezone zone; --- 5 unchanged lines hidden (view full) --- 113 char big_buf[N_LINES*N_CHARS]; 114 char *bptr, *lptr, *vis_user; 115 int i, j, max_size; 116 117 i = 0; 118 max_size = 0; 119 gettimeofday(&clock, &zone); 120 localclock = localtime( &clock.tv_sec ); |
110 (void)sprintf(line_buf[i], " "); | 121 (void)snprintf(line_buf[i], N_CHARS, " "); |
111 sizes[i] = strlen(line_buf[i]); 112 max_size = max(max_size, sizes[i]); 113 i++; | 122 sizes[i] = strlen(line_buf[i]); 123 max_size = max(max_size, sizes[i]); 124 i++; |
114 (void)sprintf(line_buf[i], "Message from Talk_Daemon@%s at %d:%02d ...", 115 hostname, localclock->tm_hour , localclock->tm_min ); | 125 (void)snprintf(line_buf[i], N_CHARS, 126 "Message from Talk_Daemon@%s at %d:%02d ...", 127 hostname, localclock->tm_hour , localclock->tm_min ); |
116 sizes[i] = strlen(line_buf[i]); 117 max_size = max(max_size, sizes[i]); 118 i++; | 128 sizes[i] = strlen(line_buf[i]); 129 max_size = max(max_size, sizes[i]); 130 i++; |
119 vis_user = (char *) malloc(strlen(request->l_name) * 4 + 1); | 131 132 vis_user = malloc(strlen(request->l_name) * 4 + 1); |
120 strvis(vis_user, request->l_name, VIS_CSTYLE); | 133 strvis(vis_user, request->l_name, VIS_CSTYLE); |
121 (void)sprintf(line_buf[i], "talk: connection requested by %s@%s", 122 vis_user, remote_machine); | 134 (void)snprintf(line_buf[i], N_CHARS, 135 "talk: connection requested by %s@%s", vis_user, remote_machine); |
123 sizes[i] = strlen(line_buf[i]); 124 max_size = max(max_size, sizes[i]); 125 i++; | 136 sizes[i] = strlen(line_buf[i]); 137 max_size = max(max_size, sizes[i]); 138 i++; |
126 (void)sprintf(line_buf[i], "talk: respond with: talk %s@%s", 127 vis_user, remote_machine); | 139 (void)snprintf(line_buf[i], N_CHARS, "talk: respond with: talk %s@%s", 140 vis_user, remote_machine); |
128 sizes[i] = strlen(line_buf[i]); 129 max_size = max(max_size, sizes[i]); 130 i++; | 141 sizes[i] = strlen(line_buf[i]); 142 max_size = max(max_size, sizes[i]); 143 i++; |
131 (void)sprintf(line_buf[i], " "); | 144 (void)snprintf(line_buf[i], N_CHARS, " "); |
132 sizes[i] = strlen(line_buf[i]); 133 max_size = max(max_size, sizes[i]); 134 i++; 135 bptr = big_buf; | 145 sizes[i] = strlen(line_buf[i]); 146 max_size = max(max_size, sizes[i]); 147 i++; 148 bptr = big_buf; |
136 *bptr++ = ''; /* send something to wake them up */ | 149 *bptr++ = '\007'; /* send something to wake them up */ |
137 *bptr++ = '\r'; /* add a \r in case of raw mode */ 138 *bptr++ = '\n'; 139 for (i = 0; i < N_LINES; i++) { 140 /* copy the line into the big buffer */ 141 lptr = line_buf[i]; 142 while (*lptr != '\0') 143 *(bptr++) = *(lptr++); 144 /* pad out the rest of the lines with blanks */ --- 18 unchanged lines hidden --- | 150 *bptr++ = '\r'; /* add a \r in case of raw mode */ 151 *bptr++ = '\n'; 152 for (i = 0; i < N_LINES; i++) { 153 /* copy the line into the big buffer */ 154 lptr = line_buf[i]; 155 while (*lptr != '\0') 156 *(bptr++) = *(lptr++); 157 /* pad out the rest of the lines with blanks */ --- 18 unchanged lines hidden --- |