MCPcopy Create free account
hub / github.com/apache/trafficserver / classifyUserAgent

Function classifyUserAgent

plugins/cachekey/cachekey.cc:148–174  ·  view source on GitHub ↗

* @brief Iterates through all User-Agent headers and fields and classifies them using provided classifier. * @param c classifier * @param buf marshal buffer from the request * @param hdrs headers handle from the request * @param classname reference to the string where the class name will be returned */

Source from the content-addressed store, hash-verified

146 * @param classname reference to the string where the class name will be returned
147 */
148static bool
149classifyUserAgent(const Classifier &c, TSMBuffer buf, TSMLoc hdrs, String &classname)
150{
151 TSMLoc field;
152 bool matched = false;
153
154 field = TSMimeHdrFieldFind(buf, hdrs, TS_MIME_FIELD_USER_AGENT, TS_MIME_LEN_USER_AGENT);
155 while (field != TS_NULL_MLOC && !matched) {
156 const char *value;
157 int len;
158 int count = TSMimeHdrFieldValuesCount(buf, hdrs, field);
159
160 for (int i = 0; i < count; ++i) {
161 value = TSMimeHdrFieldValueStringGet(buf, hdrs, field, i, &len);
162 const String val(value, len);
163 if (c.classify(val, classname)) {
164 matched = true;
165 break;
166 }
167 }
168
169 field = ::nextDuplicate(buf, hdrs, field);
170 }
171
172 TSHandleMLocRelease(buf, hdrs, field);
173 return matched;
174}
175
176static String
177getUri(TSMBuffer buf, TSMLoc url)

Callers 1

appendUaClassMethod · 0.85

Calls 6

TSMimeHdrFieldFindFunction · 0.85
TSHandleMLocReleaseFunction · 0.85
nextDuplicateFunction · 0.70
classifyMethod · 0.45

Tested by

no test coverage detected