Chinaunix首页 | 论坛 | 博客

分类: LINUX

2011-10-12 22:11:19

  1. <------------_____________
  2. 回到src/cookie.c文件
  3. 1134 void
  4. 1135 cookie_jar_load (struct cookie_jar *jar, const char *file)
  5. . . . . . .
  6. 1211       expiry = (double)cookies_now - 1;  /*是个时间*/
  7. 1215       *expires_e = '\0';
  8. 1216       sscanf (expires_b, "%lf", &expiry); /*将时间初始化为expires_b*/
  9. /*........这里有些是检测时间是否出现了错误*/
  10. 1233       store_cookie (jar, cookie);  /*1、___________----------->
复制代码
  1. 1、____________------------->
  2. 206 static void
  3. 207 store_cookie (struct cookie_jar *jar, struct cookie *cookie) /*jar中存储的是hash_table的数组和cookie数目*/
  4. 208 {
  5. 209   struct cookie *chain_head;
  6. 210   char *chain_key;
  7. 211                 
  8. 212   if (hash_table_get_pair (jar->chains, cookie->domain,
  9. 213                            &chain_key, &chain_head)) 2、________---------->
  10. 214     {
  11.         
  12. 218       struct cookie *prev;
  13. 219       struct cookie *victim = find_matching_cookie (jar, cookie, &prev);
  14. 220
  15. 221       if (victim)
  16. 222         {
  17. 223           /* Remove VICTIM from the chain.  COOKIE will be placed at
  18. 224              the head. */
  19. 225           if (prev)
  20. 226             {
  21. 227               prev->next = victim->next;
  22. 228               cookie->next = chain_head;
  23. 229             }
  24. 230           else
  25. 235               cookie->next = victim->next;
  26. 236             }
  27. 237           delete_cookie (victim);
  28. 238           --jar->cookie_count;
  29. 239           DEBUGP (("Deleted old cookie (to be replaced.)\n"));
  30. 240         }
  31. 241       else
  32. 242         cookie->next = chain_head;
  33. 243     }
  34. 244   else
  35. 251       cookie->next = NULL;
  36. 252       chain_key = xstrdup (cookie->domain);
  37. 253     }
  38. 254
  39. 255   hash_table_put (jar->chains, chain_key, cookie);
  40. 256   ++jar->cookie_count;
  41. 257
  42. 258   IF_DEBUG
  43. 259     {
  44. 260       time_t exptime = cookie->expiry_time;
  45. 261       DEBUGP (("\nStored cookie %s %d%s %s <%s> <%s> [expiry %s] %s %s\n",
  46. 262                cookie->domain, cookie->port,
  47. 263                cookie->port == PORT_ANY ? " (ANY)" : "",
  48. 264                cookie->path,
  49. 265                cookie->permanent ? "permanent" : "session",
  50. 266                cookie->secure ? "secure" : "insecure",
  51. 267                cookie->expiry_time ? datetime_str (exptime) : "none",
  52. 268                cookie->attr, cookie->value));
  53. 269     }
  54. 270 }
复制代码
  1. 2、_______________----------->
  2. 353 int
  3. 354 hash_table_get_pair (const struct hash_table *ht, const void *lookup_key,
  4. 355                      void *orig_key, void *value)
  5. 356 {  
  6. 357   struct cell *c = find_cell (ht, lookup_key); 3、__________--------->
  7. 358   if (CELL_OCCUPIED (c))
  8. 359     {
  9. 360       if (orig_key)
  10. 361         *(void **)orig_key = c->key;
  11. 362       if (value)
  12. 363         *(void **)value = c->value;
  13. 364       return 1;
  14. 365     }  
  15. 366   else
  16. 367     return 0;
  17. 368 }
复制代码
  1. 3、_____________----------->
  2. 319 static inline struct cell *
  3. 320 find_cell (const struct hash_table *ht, const void *key)
  4. 321 {
  5. 322   struct cell *cells = ht->cells;
  6. 323   int size = ht->size;
  7. 324   struct cell *c = cells + HASH_POSITION (key, ht->hash_function, size);4、________--------->
  8. 325   testfun_t equals = ht->test_function;
  9. 326
  10. 327   FOREACH_OCCUPIED_ADJACENT (c, cells, size)
  11. 328     if (equals (key, c->key))
  12. 329       break;
  13. 330   return c;
  14. 331 }
复制代码
  1. 204 #define HASH_POSITION(key, hashfun, size) ((hashfun) (key) % size)
  2. /*这个函数hashfun是在分配jar时3488     
  3. wget_cookie_jar = cookie_jar_new ();时初始化的.
  4. /*这里初始化*/  return hash_table_new (items,hash_string_nocase , string_cmp_nocase);

  5. 在函数中:
  6. [code]
  7. 272 struct hash_table *
  8. 273 hash_table_new (int items,
  9. 274                 unsigned long (*hash_function) (const void *),
  10. 275                 int (*test_function) (const void *, const void *))
  11. 280   ht->hash_function = hash_function ? hash_function : hash_pointer;
  12. 281   ht->test_function = test_function ? test_function : cmp_pointer;
复制代码
这个函数hash_sting_nocawe和hash_string一样,下面是比较*/
  1. 679 static unsigned long
  2. 680 hash_string_nocase (const void *key)
  3. 681 {
  4. 682   const char *p = key;
  5. 683   unsigned int h = c_tolower (*p);
  6. 684
  7. 685   if (h)
  8. 686     for (p += 1; *p != '\0'; p++)
  9. 687       h = (h << 5) - h + c_tolower (*p);
  10. 688
  11. 689   return h;
  12. 690 }
复制代码
  1. 641 static unsigned long
  2. 642 hash_string (const void *key)
  3. 643 {
  4. 644   const char *p = key;
  5. 645   unsigned int h = *p;
  6. 646
  7. 647   if (h)
  8. 648     for (p += 1; *p != '\0'; p++)
  9. 649       h = (h << 5) - h + *p;
  10. 650
  11. 651   return h;
  12. 652 }
复制代码
所以hash值经过hashfunction()得到的结果是一样的*/
阅读(1596) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~