]>
Commit | Line | Data |
---|---|---|
d2af9477 | 1 | |
7d49daab | 2 | /* |
79d39a72 | 3 | * $Id: send-announce.cc,v 1.45 1997/11/05 05:29:35 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 |
79d39a72 | 37 | start_announce(void *datanotused) |
e924600d | 38 | { |
17a0a4ee | 39 | if (!Config.onoff.announce) |
e924600d | 40 | return; |
8407afee | 41 | ipcache_nbgethostbyname(Config.Announce.host, send_announce, NULL); |
f1dc9b30 | 42 | eventAdd("send_announce", start_announce, NULL, Config.Announce.period); |
e924600d | 43 | } |
44 | ||
45 | static void | |
79d39a72 | 46 | send_announce(const ipcache_addrs * ia, void *datanotused) |
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; | |
03a1ee42 | 56 | int fd; |
e924600d | 57 | if (ia == NULL) { |
a3d5953d | 58 | debug(27, 1) ("send_announce: Unknown host '%s'\n", host); |
234967c9 | 59 | return; |
60 | } | |
a3d5953d | 61 | debug(27, 0) ("Sending Announcement to %s\n", host); |
234967c9 | 62 | sndbuf[0] = '\0'; |
56878878 | 63 | snprintf(tbuf, 256, "cache_version SQUID/%s\n", version_string); |
7d49daab | 64 | strcat(sndbuf, tbuf); |
270b86af | 65 | assert(Config.Port.http); |
56878878 | 66 | snprintf(tbuf, 256, "Running on %s %d %d\n", |
7d49daab | 67 | getMyHostname(), |
270b86af | 68 | (int) Config.Port.http->i, |
69 | (int) Config.Port.icp); | |
7d49daab | 70 | strcat(sndbuf, tbuf); |
b6f794d6 | 71 | if (Config.adminEmail) { |
56878878 | 72 | snprintf(tbuf, 256, "cache_admin: %s\n", Config.adminEmail); |
234967c9 | 73 | strcat(sndbuf, tbuf); |
74 | } | |
042461c3 | 75 | snprintf(tbuf, 256, "generated %d [%s]\n", |
b8de7ebe | 76 | (int) squid_curtime, |
77 | mkhttpdlogtime(&squid_curtime)); | |
7d49daab | 78 | strcat(sndbuf, tbuf); |
374b5a2d | 79 | l = strlen(sndbuf); |
79d39a72 | 80 | if ((file = Config.Announce.file) != NULL) { |
f17936ab | 81 | fd = file_open(file, O_RDONLY, NULL, NULL); |
7ba794f4 | 82 | if (fd > -1 && (n = read(fd, sndbuf + l, BUFSIZ - l - 1)) > 0) { |
4f92c80c | 83 | fd_bytes(fd, n, FD_READ); |
7ba794f4 | 84 | l += n; |
85 | sndbuf[l] = '\0'; | |
ea1f96b6 | 86 | file_close(fd); |
7d49daab | 87 | } else { |
a3d5953d | 88 | debug(50, 1) ("send_announce: %s: %s\n", file, xstrerror()); |
090089c4 | 89 | } |
90 | } | |
30a4f2a8 | 91 | qdata = xcalloc(1, sizeof(icpUdpData)); |
7d49daab | 92 | qdata->msg = xstrdup(sndbuf); |
7ba794f4 | 93 | qdata->len = strlen(sndbuf) + 1; |
7d49daab | 94 | qdata->address.sin_family = AF_INET; |
95 | qdata->address.sin_port = htons(port); | |
e5f6c5c2 | 96 | qdata->address.sin_addr = ia->in_addrs[0]; |
7d49daab | 97 | AppendUdp(qdata); |
b177367b | 98 | commSetSelect(theOutIcpConnection, |
7d49daab | 99 | COMM_SELECT_WRITE, |
cd1fb0eb | 100 | icpUdpReply, |
101 | qdata, 0); | |
090089c4 | 102 | } |