]> git.ipfire.org Git - thirdparty/squid.git/blob - src/LogTags.cc
Source Format Enforcement (#532)
[thirdparty/squid.git] / src / LogTags.cc
1 /*
2 * Copyright (C) 1996-2020 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9 #include "squid.h"
10 #include "Debug.h"
11 #include "LogTags.h"
12
13 // old deprecated tag strings
14 const char * LogTags::Str_[] = {
15 "TAG_NONE",
16 "TCP_HIT",
17 "TCP_MISS",
18 "TCP_REFRESH_UNMODIFIED",
19 "TCP_REFRESH_FAIL_OLD",
20 "TCP_REFRESH_FAIL_ERR",
21 "TCP_REFRESH_MODIFIED",
22 "TCP_REFRESH",
23 "TCP_CLIENT_REFRESH_MISS",
24 "TCP_IMS_HIT",
25 "TCP_INM_HIT",
26 "TCP_SWAPFAIL_MISS",
27 "TCP_NEGATIVE_HIT",
28 "TCP_MEM_HIT",
29 "TCP_DENIED",
30 "TCP_DENIED_REPLY",
31 "TCP_OFFLINE_HIT",
32 "TCP_REDIRECT",
33 "TCP_TUNNEL",
34 "UDP_HIT",
35 "UDP_MISS",
36 "UDP_DENIED",
37 "UDP_INVALID",
38 "UDP_MISS_NOFETCH",
39 "ICP_QUERY",
40 "TYPE_MAX"
41 };
42
43 void
44 LogTags::update(const LogTags_ot t)
45 {
46 assert(t < LOG_TYPE_MAX);
47 debugs(83, 7, Str_[oldType] << " to " << Str_[t]);
48 oldType = t;
49 }
50
51 /*
52 * This method is documented in http://wiki.squid-cache.org/SquidFaq/SquidLogs#Squid_result_codes
53 * Please keep the wiki up to date
54 */
55 const char *
56 LogTags::c_str() const
57 {
58 static char buf[1024];
59 *buf = 0;
60 int pos = 0;
61
62 // source tags
63 const int protoLen = 3;
64 if (oldType && oldType < LOG_TYPE_MAX) {
65 assert(Str_[oldType][protoLen] == '_');
66 snprintf(buf, protoLen + 1, "%s", Str_[oldType]);
67 pos += protoLen;
68 }
69 else
70 pos += snprintf(buf, sizeof(buf), "NONE");
71
72 if (collapsingHistory.collapsed())
73 pos += snprintf(buf + pos, sizeof(buf) - pos, "_CF");
74
75 const char *tag = Str_[oldType] + protoLen;
76 pos += snprintf(buf + pos, sizeof(buf) - pos, "%s", tag);
77
78 if (err.ignored)
79 pos += snprintf(buf+pos,sizeof(buf)-pos, "_IGNORED");
80
81 // error tags
82 if (err.timedout)
83 pos += snprintf(buf+pos,sizeof(buf)-pos, "_TIMEDOUT");
84 if (err.aborted)
85 pos += snprintf(buf+pos,sizeof(buf)-pos, "_ABORTED");
86
87 return buf;
88 }
89
90 bool
91 LogTags::isTcpHit() const
92 {
93 return
94 (oldType == LOG_TCP_HIT) ||
95 (oldType == LOG_TCP_IMS_HIT) ||
96 (oldType == LOG_TCP_INM_HIT) ||
97 (oldType == LOG_TCP_REFRESH_FAIL_OLD) ||
98 (oldType == LOG_TCP_REFRESH_UNMODIFIED) ||
99 (oldType == LOG_TCP_NEGATIVE_HIT) ||
100 (oldType == LOG_TCP_MEM_HIT) ||
101 (oldType == LOG_TCP_OFFLINE_HIT);
102 }
103