]>
Commit | Line | Data |
---|---|---|
d2af9477 | 1 | |
7d49daab | 2 | /* |
a3d5953d | 3 | * $Id: send-announce.cc,v 1.36 1997/06/04 06:16:08 wessels Exp $ |
30a4f2a8 | 4 | * |
5 | * DEBUG: section 27 Cache Announcer | |
6 | * AUTHOR: Duane Wessels | |
7 | * | |
42c04c16 | 8 | * SQUID Internet Object Cache http://squid.nlanr.net/Squid/ |
30a4f2a8 | 9 | * -------------------------------------------------------- |
10 | * | |
11 | * Squid is the result of efforts by numerous individuals from the | |
12 | * Internet community. Development is led by Duane Wessels of the | |
13 | * National Laboratory for Applied Network Research and funded by | |
14 | * the National Science Foundation. | |
15 | * | |
16 | * This program is free software; you can redistribute it and/or modify | |
17 | * it under the terms of the GNU General Public License as published by | |
18 | * the Free Software Foundation; either version 2 of the License, or | |
19 | * (at your option) any later version. | |
20 | * | |
21 | * This program is distributed in the hope that it will be useful, | |
22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
24 | * GNU General Public License for more details. | |
25 | * | |
26 | * You should have received a copy of the GNU General Public License | |
27 | * along with this program; if not, write to the Free Software | |
28 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
29 | * | |
7d49daab | 30 | */ |
090089c4 | 31 | |
7d49daab | 32 | #include "squid.h" |
090089c4 | 33 | |
b69f7771 | 34 | static IPH send_announce; |
e924600d | 35 | |
b8d8561b | 36 | void |
e924600d | 37 | start_announce(void *unused) |
38 | { | |
39 | if (!Config.Announce.on) | |
40 | return; | |
41 | ipcache_nbgethostbyname(Config.Announce.host, 0, send_announce, NULL); | |
42 | eventAdd("send_announce", start_announce, NULL, Config.Announce.rate); | |
43 | } | |
44 | ||
45 | static void | |
46 | send_announce(int fd, const ipcache_addrs * ia, void *data) | |
090089c4 | 47 | { |
95d659f0 | 48 | LOCAL_ARRAY(char, tbuf, 256); |
49 | LOCAL_ARRAY(char, sndbuf, BUFSIZ); | |
7d49daab | 50 | icpUdpData *qdata = NULL; |
48f44632 | 51 | char *host = Config.Announce.host; |
7d49daab | 52 | char *file = NULL; |
48f44632 | 53 | u_short port = Config.Announce.port; |
7d49daab | 54 | int l; |
55 | int n; | |
e924600d | 56 | if (ia == NULL) { |
a3d5953d | 57 | debug(27, 1) ("send_announce: Unknown host '%s'\n", host); |
234967c9 | 58 | return; |
59 | } | |
a3d5953d | 60 | debug(27, 0) ("Sending Announcement to %s\n", host); |
234967c9 | 61 | sndbuf[0] = '\0'; |
c5c666ab | 62 | sprintf(tbuf, "cache_version SQUID/%s\n", version_string); |
7d49daab | 63 | strcat(sndbuf, tbuf); |
64 | sprintf(tbuf, "Running on %s %d %d\n", | |
65 | getMyHostname(), | |
812ed90c | 66 | Config.Port.http[0], |
b6f794d6 | 67 | Config.Port.icp); |
7d49daab | 68 | strcat(sndbuf, tbuf); |
b6f794d6 | 69 | if (Config.adminEmail) { |
70 | sprintf(tbuf, "cache_admin: %s\n", Config.adminEmail); | |
234967c9 | 71 | strcat(sndbuf, tbuf); |
72 | } | |
7d49daab | 73 | sprintf(tbuf, "generated %d [%s]\n", |
b8de7ebe | 74 | (int) squid_curtime, |
75 | mkhttpdlogtime(&squid_curtime)); | |
7d49daab | 76 | strcat(sndbuf, tbuf); |
374b5a2d | 77 | l = strlen(sndbuf); |
b6f794d6 | 78 | if ((file = Config.Announce.file)) { |
f17936ab | 79 | fd = file_open(file, O_RDONLY, NULL, NULL); |
7ba794f4 | 80 | if (fd > -1 && (n = read(fd, sndbuf + l, BUFSIZ - l - 1)) > 0) { |
4f92c80c | 81 | fd_bytes(fd, n, FD_READ); |
7ba794f4 | 82 | l += n; |
83 | sndbuf[l] = '\0'; | |
ea1f96b6 | 84 | file_close(fd); |
7d49daab | 85 | } else { |
a3d5953d | 86 | debug(50, 1) ("send_announce: %s: %s\n", file, xstrerror()); |
090089c4 | 87 | } |
88 | } | |
30a4f2a8 | 89 | qdata = xcalloc(1, sizeof(icpUdpData)); |
7d49daab | 90 | qdata->msg = xstrdup(sndbuf); |
7ba794f4 | 91 | qdata->len = strlen(sndbuf) + 1; |
7d49daab | 92 | qdata->address.sin_family = AF_INET; |
93 | qdata->address.sin_port = htons(port); | |
e5f6c5c2 | 94 | qdata->address.sin_addr = ia->in_addrs[0]; |
7d49daab | 95 | AppendUdp(qdata); |
b177367b | 96 | commSetSelect(theOutIcpConnection, |
7d49daab | 97 | COMM_SELECT_WRITE, |
cd1fb0eb | 98 | icpUdpReply, |
99 | qdata, 0); | |
090089c4 | 100 | } |