- <------------_____________
- 回到src/cookie.c文件
- 1134 void
- 1135 cookie_jar_load (struct cookie_jar *jar, const char *file)
- . . . . . .
- 1211 expiry = (double)cookies_now - 1; /*是个时间*/
- 1215 *expires_e = '\0';
- 1216 sscanf (expires_b, "%lf", &expiry); /*将时间初始化为expires_b*/
- /*........这里有些是检测时间是否出现了错误*/
- 1233 store_cookie (jar, cookie); /*1、___________----------->
复制代码- 1、____________------------->
- 206 static void
- 207 store_cookie (struct cookie_jar *jar, struct cookie *cookie) /*jar中存储的是hash_table的数组和cookie数目*/
- 208 {
- 209 struct cookie *chain_head;
- 210 char *chain_key;
- 211
- 212 if (hash_table_get_pair (jar->chains, cookie->domain,
- 213 &chain_key, &chain_head)) 2、________---------->
- 214 {
-
- 218 struct cookie *prev;
- 219 struct cookie *victim = find_matching_cookie (jar, cookie, &prev);
- 220
- 221 if (victim)
- 222 {
- 223 /* Remove VICTIM from the chain. COOKIE will be placed at
- 224 the head. */
- 225 if (prev)
- 226 {
- 227 prev->next = victim->next;
- 228 cookie->next = chain_head;
- 229 }
- 230 else
- 235 cookie->next = victim->next;
- 236 }
- 237 delete_cookie (victim);
- 238 --jar->cookie_count;
- 239 DEBUGP (("Deleted old cookie (to be replaced.)\n"));
- 240 }
- 241 else
- 242 cookie->next = chain_head;
- 243 }
- 244 else
- 251 cookie->next = NULL;
- 252 chain_key = xstrdup (cookie->domain);
- 253 }
- 254
- 255 hash_table_put (jar->chains, chain_key, cookie);
- 256 ++jar->cookie_count;
- 257
- 258 IF_DEBUG
- 259 {
- 260 time_t exptime = cookie->expiry_time;
- 261 DEBUGP (("\nStored cookie %s %d%s %s <%s> <%s> [expiry %s] %s %s\n",
- 262 cookie->domain, cookie->port,
- 263 cookie->port == PORT_ANY ? " (ANY)" : "",
- 264 cookie->path,
- 265 cookie->permanent ? "permanent" : "session",
- 266 cookie->secure ? "secure" : "insecure",
- 267 cookie->expiry_time ? datetime_str (exptime) : "none",
- 268 cookie->attr, cookie->value));
- 269 }
- 270 }
复制代码- 2、_______________----------->
- 353 int
- 354 hash_table_get_pair (const struct hash_table *ht, const void *lookup_key,
- 355 void *orig_key, void *value)
- 356 {
- 357 struct cell *c = find_cell (ht, lookup_key); 3、__________--------->
- 358 if (CELL_OCCUPIED (c))
- 359 {
- 360 if (orig_key)
- 361 *(void **)orig_key = c->key;
- 362 if (value)
- 363 *(void **)value = c->value;
- 364 return 1;
- 365 }
- 366 else
- 367 return 0;
- 368 }
复制代码- 3、_____________----------->
- 319 static inline struct cell *
- 320 find_cell (const struct hash_table *ht, const void *key)
- 321 {
- 322 struct cell *cells = ht->cells;
- 323 int size = ht->size;
- 324 struct cell *c = cells + HASH_POSITION (key, ht->hash_function, size);4、________--------->
- 325 testfun_t equals = ht->test_function;
- 326
- 327 FOREACH_OCCUPIED_ADJACENT (c, cells, size)
- 328 if (equals (key, c->key))
- 329 break;
- 330 return c;
- 331 }
复制代码- 204 #define HASH_POSITION(key, hashfun, size) ((hashfun) (key) % size)
- /*这个函数hashfun是在分配jar时3488
- wget_cookie_jar = cookie_jar_new ();时初始化的.
- /*这里初始化*/ return hash_table_new (items,hash_string_nocase , string_cmp_nocase);
- 在函数中:
- [code]
- 272 struct hash_table *
- 273 hash_table_new (int items,
- 274 unsigned long (*hash_function) (const void *),
- 275 int (*test_function) (const void *, const void *))
- 280 ht->hash_function = hash_function ? hash_function : hash_pointer;
- 281 ht->test_function = test_function ? test_function : cmp_pointer;
复制代码这个函数hash_sting_nocawe和hash_string一样,下面是比较*/
- 679 static unsigned long
- 680 hash_string_nocase (const void *key)
- 681 {
- 682 const char *p = key;
- 683 unsigned int h = c_tolower (*p);
- 684
- 685 if (h)
- 686 for (p += 1; *p != '\0'; p++)
- 687 h = (h << 5) - h + c_tolower (*p);
- 688
- 689 return h;
- 690 }
复制代码- 641 static unsigned long
- 642 hash_string (const void *key)
- 643 {
- 644 const char *p = key;
- 645 unsigned int h = *p;
- 646
- 647 if (h)
- 648 for (p += 1; *p != '\0'; p++)
- 649 h = (h << 5) - h + *p;
- 650
- 651 return h;
- 652 }
复制代码所以hash值经过hashfunction()得到的结果是一样的*/
阅读(1631) | 评论(0) | 转发(0) |