1 /** @file 2 3 A brief file description 4 5 @section license License 6 7 Licensed to the Apache Software Foundation (ASF) under one 8 or more contributor license agreements. See the NOTICE file 9 distributed with this work for additional information 10 regarding copyright ownership. The ASF licenses this file 11 to you under the Apache License, Version 2.0 (the 12 "License"); you may not use this file except in compliance 13 with the License. You may obtain a copy of the License at 14 15 http://www.apache.org/licenses/LICENSE-2.0 16 17 Unless required by applicable law or agreed to in writing, software 18 distributed under the License is distributed on an "AS IS" BASIS, 19 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 See the License for the specific language governing permissions and 21 limitations under the License. 22 */ 23 24 #pragma once 25 26 #include "tscore/CryptoHash.h" 27 28 #define CACHE_INIT_FAILED -1 29 #define CACHE_INITIALIZING 0 30 #define CACHE_INITIALIZED 1 31 32 #define CACHE_ALT_INDEX_DEFAULT -1 33 #define CACHE_ALT_REMOVED -2 34 35 static const uint8_t CACHE_DB_MAJOR_VERSION = 24; 36 static const uint8_t CACHE_DB_MINOR_VERSION = 2; 37 // This is used in various comparisons because otherwise if the minor version is 0, 38 // the compile fails because the condition is always true or false. Running it through 39 // VersionNumber prevents that. 40 extern const ts::VersionNumber CACHE_DB_VERSION; 41 42 static const uint8_t CACHE_DIR_MAJOR_VERSION = 18; 43 static const uint8_t CACHE_DIR_MINOR_VERSION = 0; 44 45 #define CACHE_DB_FDS 128 46 47 // opcodes 48 #define CACHE_OPEN_READ 1 49 #define CACHE_OPEN_READ_BUFFER 2 50 #define CACHE_OPEN_READ_LONG 3 51 #define CACHE_OPEN_READ_BUFFER_LONG 4 52 #define CACHE_OPEN_WRITE 5 53 #define CACHE_OPEN_WRITE_BUFFER 6 54 #define CACHE_OPEN_WRITE_LONG 7 55 #define CACHE_OPEN_WRITE_BUFFER_LONG 8 56 #define CACHE_UPDATE 9 57 #define CACHE_REMOVE 10 58 #define CACHE_LINK 11 59 #define CACHE_DEREF 12 60 #define CACHE_LOOKUP_OP 13 61 62 enum CacheType { 63 CACHE_NONE_TYPE = 0, // for empty disk fragments 64 CACHE_HTTP_TYPE = 1, 65 CACHE_RTSP_TYPE = 2 66 }; 67 68 // NOTE: All the failures are ODD, and one greater than the success 69 // Some of these must match those in <ts/ts.h> 70 enum CacheEventType { 71 CACHE_EVENT_LOOKUP = CACHE_EVENT_EVENTS_START + 0, 72 CACHE_EVENT_LOOKUP_FAILED = CACHE_EVENT_EVENTS_START + 1, 73 CACHE_EVENT_OPEN_READ = CACHE_EVENT_EVENTS_START + 2, 74 CACHE_EVENT_OPEN_READ_FAILED = CACHE_EVENT_EVENTS_START + 3, 75 // 4-7 unused 76 CACHE_EVENT_OPEN_WRITE = CACHE_EVENT_EVENTS_START + 8, 77 CACHE_EVENT_OPEN_WRITE_FAILED = CACHE_EVENT_EVENTS_START + 9, 78 CACHE_EVENT_REMOVE = CACHE_EVENT_EVENTS_START + 12, 79 CACHE_EVENT_REMOVE_FAILED = CACHE_EVENT_EVENTS_START + 13, 80 CACHE_EVENT_UPDATE, 81 CACHE_EVENT_UPDATE_FAILED, 82 CACHE_EVENT_LINK, 83 CACHE_EVENT_LINK_FAILED, 84 CACHE_EVENT_DEREF, 85 CACHE_EVENT_DEREF_FAILED, 86 CACHE_EVENT_SCAN = CACHE_EVENT_EVENTS_START + 20, 87 CACHE_EVENT_SCAN_FAILED = CACHE_EVENT_EVENTS_START + 21, 88 CACHE_EVENT_SCAN_OBJECT = CACHE_EVENT_EVENTS_START + 22, 89 CACHE_EVENT_SCAN_OPERATION_BLOCKED = CACHE_EVENT_EVENTS_START + 23, 90 CACHE_EVENT_SCAN_OPERATION_FAILED = CACHE_EVENT_EVENTS_START + 24, 91 CACHE_EVENT_SCAN_DONE = CACHE_EVENT_EVENTS_START + 25, 92 ////////////////////////// 93 // Internal error codes // 94 ////////////////////////// 95 CACHE_EVENT_RESPONSE = CACHE_EVENT_EVENTS_START + 50, 96 CACHE_EVENT_RESPONSE_MSG, 97 CACHE_EVENT_RESPONSE_RETRY 98 }; 99 100 enum CacheScanResult { 101 CACHE_SCAN_RESULT_CONTINUE = EVENT_CONT, 102 CACHE_SCAN_RESULT_DONE = EVENT_DONE, 103 CACHE_SCAN_RESULT_DELETE = 10, 104 CACHE_SCAN_RESULT_DELETE_ALL_ALTERNATES, 105 CACHE_SCAN_RESULT_UPDATE, 106 CACHE_SCAN_RESULT_RETRY 107 }; 108 109 enum CacheDataType { 110 CACHE_DATA_HTTP_INFO = VCONNECTION_CACHE_DATA_BASE, 111 CACHE_DATA_KEY, 112 CACHE_DATA_RAM_CACHE_HIT_FLAG, 113 }; 114 115 enum CacheFragType { 116 CACHE_FRAG_TYPE_NONE = 0, 117 CACHE_FRAG_TYPE_UNUSED_1 = 1, //. Because of the history we need to occupy a space 118 CACHE_FRAG_TYPE_RTSP = 2, ///< Should be removed once Cache Toolkit is implemented. 119 CACHE_FRAG_TYPE_HTTP = 3, 120 NUM_CACHE_FRAG_TYPES = 4 121 }; 122 123 typedef CryptoHash CacheKey; 124 125 struct HttpCacheKey { 126 int hostlen; 127 const char *hostname; 128 CacheKey hash; 129 CacheKey hash2; 130 }; 131 132 #define CACHE_ALLOW_MULTIPLE_WRITES 1 133 #define CACHE_EXPECTED_SIZE 32768 134 135 /* uses of the CacheKey 136 word(0) - cache partition segment 137 word(1) - cache partition bucket 138 word(2) - tag (lower bits), hosttable hash (upper bits) 139 word(3) - ram cache hash, lookaside cache 140 */ 141