Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "ink_config.h"
00025 #include <string.h>
00026 #include "P_Cache.h"
00027
00028
00029
00030
00031
00032 static vec_info default_vec_info;
00033
00034 #ifdef HTTP_CACHE
00035 static CacheHTTPInfo default_http_info;
00036
00037 CacheHTTPInfoVector::CacheHTTPInfoVector()
00038 :magic(NULL), data(&default_vec_info, 4), xcount(0)
00039 {
00040 }
00041
00042
00043
00044
00045 CacheHTTPInfoVector::~CacheHTTPInfoVector()
00046 {
00047 int i;
00048
00049 for (i = 0; i < xcount; i++) {
00050 data[i].alternate.destroy();
00051 }
00052 vector_buf.clear();
00053 magic = NULL;
00054 }
00055
00056
00057
00058
00059 int
00060 CacheHTTPInfoVector::insert(CacheHTTPInfo * info, int index)
00061 {
00062 if (index == CACHE_ALT_INDEX_DEFAULT)
00063 index = xcount++;
00064
00065 data(index).alternate.copy_shallow(info);
00066 return index;
00067 }
00068
00069
00070
00071
00072
00073 void
00074 CacheHTTPInfoVector::detach(int idx, CacheHTTPInfo * r)
00075 {
00076 int i;
00077
00078 ink_assert(idx >= 0);
00079 ink_assert(idx < xcount);
00080
00081 r->copy_shallow(&data[idx].alternate);
00082 data[idx].alternate.destroy();
00083
00084 for (i = idx; i < (xcount - 1); i++) {
00085 data[i] = data[i + i];
00086 }
00087
00088 xcount -= 1;
00089 }
00090
00091
00092
00093
00094 void
00095 CacheHTTPInfoVector::remove(int idx, bool destroy)
00096 {
00097 if (destroy)
00098 data[idx].alternate.destroy();
00099
00100 for (; idx < (xcount - 1); idx++)
00101 data[idx] = data[idx + 1];
00102
00103 xcount--;
00104 }
00105
00106
00107
00108
00109 void
00110 CacheHTTPInfoVector::clear(bool destroy)
00111 {
00112 int i;
00113
00114 if (destroy) {
00115 for (i = 0; i < xcount; i++) {
00116 data[i].alternate.destroy();
00117 }
00118 }
00119 xcount = 0;
00120 data.clear();
00121 vector_buf.clear();
00122 }
00123
00124
00125
00126
00127 void
00128 CacheHTTPInfoVector::print(char *buffer, size_t buf_size, bool temps)
00129 {
00130 char buf[33], *p;
00131 int purl;
00132 int i, tmp;
00133
00134 p = buffer;
00135 purl = 1;
00136
00137 for (i = 0; i < xcount; i++) {
00138 if (data[i].alternate.valid()) {
00139 if (purl) {
00140 Arena arena;
00141 char *url;
00142
00143 purl = 0;
00144 URL u;
00145 data[i].alternate.request_url_get(&u);
00146 url = u.string_get(&arena);
00147 if (url) {
00148 snprintf(p, buf_size, "[%s] ", url);
00149 tmp = strlen(p);
00150 p += tmp;
00151 buf_size -= tmp;
00152 }
00153 }
00154
00155 if (temps || !(data[i].alternate.object_key_get() == zero_key)) {
00156 snprintf(p, buf_size, "[%d %s]", data[i].alternate.id_get(),
00157 CacheKey(data[i].alternate.object_key_get()).toHexStr(buf));
00158 tmp = strlen(p);
00159 p += tmp;
00160 buf_size -= tmp;
00161 }
00162 }
00163 }
00164 }
00165
00166
00167
00168
00169 int
00170 CacheHTTPInfoVector::marshal_length()
00171 {
00172 int length = 0;
00173
00174 for (int i = 0; i < xcount; i++) {
00175 length += data[i].alternate.marshal_length();
00176 }
00177
00178 return length;
00179 }
00180
00181
00182
00183 int
00184 CacheHTTPInfoVector::marshal(char *buf, int length)
00185 {
00186 char *start = buf;
00187 int count = 0;
00188
00189 ink_assert(!(((intptr_t) buf) & 3));
00190
00191 for (int i = 0; i < xcount; i++) {
00192 int tmp = data[i].alternate.marshal(buf, length);
00193 length -= tmp;
00194 buf += tmp;
00195 count++;
00196 }
00197
00198 GLOBAL_CACHE_SUM_GLOBAL_DYN_STAT(cache_hdr_vector_marshal_stat, 1);
00199 GLOBAL_CACHE_SUM_GLOBAL_DYN_STAT(cache_hdr_marshal_stat, count);
00200 GLOBAL_CACHE_SUM_GLOBAL_DYN_STAT(cache_hdr_marshal_bytes_stat, buf - start);
00201 return buf - start;
00202 }
00203
00204 int
00205 CacheHTTPInfoVector::unmarshal(const char *buf, int length, RefCountObj * block_ptr)
00206 {
00207 ink_assert(!(((intptr_t) buf) & 3));
00208
00209 const char *start = buf;
00210 CacheHTTPInfo info;
00211 xcount = 0;
00212
00213 while (length - (buf - start) > (int) sizeof(HTTPCacheAlt)) {
00214
00215 int tmp = HTTPInfo::unmarshal((char *) buf, length - (buf - start), block_ptr);
00216 if (tmp < 0) {
00217 return -1;
00218 }
00219 info.m_alt = (HTTPCacheAlt *) buf;
00220 buf += tmp;
00221
00222 data(xcount).alternate = info;
00223 xcount++;
00224 }
00225
00226 return ((caddr_t) buf - (caddr_t) start);
00227 }
00228
00229
00230
00231
00232 uint32_t
00233 CacheHTTPInfoVector::get_handles(const char *buf, int length, RefCountObj * block_ptr)
00234 {
00235 ink_assert(!(((intptr_t) buf) & 3));
00236
00237 const char *start = buf;
00238 CacheHTTPInfo info;
00239 xcount = 0;
00240
00241 vector_buf = block_ptr;
00242
00243 while (length - (buf - start) > (int) sizeof(HTTPCacheAlt)) {
00244
00245 int tmp = info.get_handle((char *) buf, length - (buf - start));
00246 if (tmp < 0) {
00247 ink_assert(!"CacheHTTPInfoVector::unmarshal get_handle() failed");
00248 return (uint32_t) -1;
00249 }
00250 buf += tmp;
00251
00252 data(xcount).alternate = info;
00253 xcount++;
00254 }
00255
00256 return ((caddr_t) buf - (caddr_t) start);
00257 }
00258
00259 #else //HTTP_CACHE
00260
00261 CacheHTTPInfoVector::CacheHTTPInfoVector()
00262 :data(&default_vec_info, 4), xcount(0)
00263 {
00264 }
00265
00266
00267
00268
00269 CacheHTTPInfoVector::~CacheHTTPInfoVector()
00270 {
00271 }
00272
00273
00274
00275
00276 int
00277 CacheHTTPInfoVector::insert(CacheHTTPInfo *, int index)
00278 {
00279 ink_assert(0);
00280 return index;
00281 }
00282
00283
00284
00285
00286
00287 void
00288 CacheHTTPInfoVector::detach(int , CacheHTTPInfo *)
00289 {
00290 ink_assert(0);
00291 }
00292
00293
00294
00295
00296 void
00297 CacheHTTPInfoVector::remove(int , bool )
00298 {
00299 ink_assert(0);
00300 }
00301
00302
00303
00304
00305 void
00306 CacheHTTPInfoVector::clear(bool )
00307 {
00308 }
00309
00310
00311
00312
00313 void
00314 CacheHTTPInfoVector::print(char *, size_t , bool )
00315 {
00316 ink_assert(0);
00317 }
00318
00319
00320
00321
00322 int
00323 CacheHTTPInfoVector::marshal_length()
00324 {
00325 ink_assert(0);
00326 return 0;
00327 }
00328
00329
00330
00331 int
00332 CacheHTTPInfoVector::marshal(char *, int length)
00333 {
00334 ink_assert(0);
00335 return length;
00336 }
00337
00338 int
00339 CacheHTTPInfoVector::unmarshal(const char *, int , RefCountObj *)
00340 {
00341 ink_assert(0);
00342 return 0;
00343 }
00344
00345
00346
00347
00348 uint32_t
00349 CacheHTTPInfoVector::get_handles(const char *, int , RefCountObj *)
00350 {
00351 ink_assert(0);
00352 return 0;
00353 }
00354
00355 #endif //HTTP_CACHE