HTAssoc.c
上传用户:zlh9724
上传日期:2007-01-04
资源大小:1991k
文件大小:2k
源码类别:

浏览器

开发平台:

Unix_Linux

  1. /*                HTAssoc.c
  2. ** ASSOCIATION LIST FOR STORING NAME-VALUE PAIRS.
  3. **
  4. ** (c) COPYRIGHT MIT 1995.
  5. ** Please first read the full copyright statement in the file COPYRIGH.
  6. **
  7. ** NAMES NOT CASE SENSITIVE, AND ONLY COMMON LENGTH
  8. ** IS CHECKED (allows abbreviations; well, length is
  9. ** taken from lookup-up name, so if table contains
  10. ** a shorter abbrev it is not found).
  11. ** AUTHORS:
  12. ** AL Ari Luotonen luotonen@dxcern.cern.ch
  13. **
  14. ** HISTORY:
  15. **
  16. **
  17. ** BUGS:
  18. **
  19. **
  20. */
  21. /* Library include files */
  22. #include "tcp.h"
  23. #include "HTUtils.h"
  24. #include "HTString.h"
  25. #include "HTAssoc.h"  /* Implemented here */
  26. PUBLIC HTAssocList *HTAssocList_new (void)
  27. {
  28.     return HTList_new();
  29. }
  30. PUBLIC BOOL HTAssocList_delete (HTAssocList * alist)
  31. {
  32.     if (alist) {
  33. HTAssocList *cur = alist;
  34. HTAssoc *assoc;
  35. while (NULL != (assoc = (HTAssoc*)HTList_nextObject(cur))) {
  36.     if (assoc->name) HT_FREE(assoc->name);
  37.     if (assoc->value) HT_FREE(assoc->value);
  38.     HT_FREE(assoc);
  39. }
  40. return HTList_delete(alist);
  41.     }
  42.     return NO;
  43. }
  44. PUBLIC BOOL HTAssocList_add (HTAssocList * alist,
  45.      CONST char * name, CONST char * value)
  46. {
  47.     HTAssoc *assoc;
  48.     if (alist) {
  49. if ((assoc = (HTAssoc *) HT_CALLOC(1, sizeof(HTAssoc))) == NULL)
  50.     HT_OUTOFMEM("HTAssoc_add");
  51. if (name) StrAllocCopy(assoc->name, name);
  52. if (value) StrAllocCopy(assoc->value, value);
  53. return HTList_addObject(alist, (void *) assoc);
  54.     } else {
  55. if (WWWTRACE)
  56.     TTYPrint(TDEST, "HTAssoc_add: ERROR: assoc list NULL!!n");
  57.     }
  58.     return NO;
  59. }
  60. PUBLIC char *HTAssocList_lookup (HTAssocList * alist, CONST char * name)
  61. {
  62.     HTAssocList *cur = alist;
  63.     HTAssoc *assoc;
  64.     while ((assoc = (HTAssoc *) HTList_nextObject(cur))) {
  65. if (!strncasecomp(assoc->name, name, strlen(name)))
  66.     return assoc->value;
  67.     }
  68.     return NULL;
  69. }