]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/send-announce.cc
2 * DEBUG: section 27 Cache Announcer
3 * AUTHOR: Duane Wessels
5 * SQUID Web Proxy Cache http://www.squid-cache.org/
6 * ----------------------------------------------------------
8 * Squid is the result of efforts by numerous individuals from
9 * the Internet community; see the CONTRIBUTORS file for full
10 * details. Many organizations have provided support for Squid's
11 * development; see the SPONSORS file for full details. Squid is
12 * Copyrighted (C) 2001 by the Regents of the University of
13 * California; see the COPYRIGHT file for full details. Squid
14 * incorporates software developed and/or copyrighted by other
15 * sources; see the CREDITS file for full details.
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2 of the License, or
20 * (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
34 #include "comm/Connection.h"
42 #include "SquidConfig.h"
43 #include "SquidTime.h"
46 static IPH send_announce
;
49 start_announce(void *datanotused
)
51 if (0 == Config
.onoff
.announce
)
54 if (!Comm::IsConnOpen(icpOutgoingConn
))
57 ipcache_nbgethostbyname(Config
.Announce
.host
, send_announce
, NULL
);
59 eventAdd("send_announce", start_announce
, NULL
, (double) Config
.Announce
.period
, 1);
63 send_announce(const ipcache_addrs
*ia
, const DnsLookupDetails
&, void *junk
)
65 LOCAL_ARRAY(char, tbuf
, 256);
66 LOCAL_ARRAY(char, sndbuf
, BUFSIZ
);
68 char *host
= Config
.Announce
.host
;
70 unsigned short port
= Config
.Announce
.port
;
76 debugs(27, DBG_IMPORTANT
, "send_announce: Unknown host '" << host
<< "'");
80 debugs(27, DBG_IMPORTANT
, "Sending Announcement to " << host
);
82 snprintf(tbuf
, 256, "cache_version SQUID/%s\n", version_string
);
84 assert(Config
.Sockaddr
.http
);
85 snprintf(tbuf
, 256, "Running on %s %d %d\n",
88 (int) Config
.Port
.icp
);
91 if (Config
.adminEmail
) {
92 snprintf(tbuf
, 256, "cache_admin: %s\n", Config
.adminEmail
);
96 snprintf(tbuf
, 256, "generated %d [%s]\n",
98 Time::FormatHttpd(squid_curtime
));
102 if ((file
= Config
.Announce
.file
) != NULL
) {
103 fd
= file_open(file
, O_RDONLY
| O_TEXT
);
105 if (fd
> -1 && (n
= FD_READ_METHOD(fd
, sndbuf
+ l
, BUFSIZ
- l
- 1)) > 0) {
106 fd_bytes(fd
, n
, FD_READ
);
111 debugs(50, DBG_IMPORTANT
, "send_announce: " << file
<< ": " << xstrerror());
115 Ip::Address S
= ia
->in_addrs
[0];
117 assert(Comm::IsConnOpen(icpOutgoingConn
));
119 if (comm_udp_sendto(icpOutgoingConn
->fd
, S
, sndbuf
, strlen(sndbuf
) + 1) < 0)
120 debugs(27, DBG_IMPORTANT
, "ERROR: Failed to announce to " << S
<< " from " << icpOutgoingConn
->local
<< ": " << xstrerror());