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

浏览器

开发平台:

Unix_Linux

  1. /*      HTProt.c
  2. ** ACCESS SCHEME MANAGER
  3. **
  4. ** (c) COPYRIGHT MIT 1995.
  5. ** Please first read the full copyright statement in the file COPYRIGH.
  6. **
  7. **
  8. ** HISTORY:
  9. ** 6 July 95  HFN Spawned off from HTAccess
  10. */
  11. /* Library Include files */
  12. #include "tcp.h"
  13. #include "HTUtils.h"
  14. #include "HTString.h"
  15. #include "HTParse.h"
  16. #include "HTString.h"
  17. #include "HTProt.h"  /* Implemented here */
  18. /* Variables and typedefs local to this module */
  19. struct _HTProtocol {
  20.     char * name;
  21.     BOOL preemptive;
  22.     HTEventCallback * client;
  23.     HTEventCallback * server;
  24. };
  25. PRIVATE HTList * protocols = NULL;           /* List of registered protocols */
  26. /* --------------------------------------------------------------------------*/
  27. /*       Management of the HTProtocol structure      */
  28. /* --------------------------------------------------------------------------*/
  29. /*
  30. ** Register a Protocol module as an active access method
  31. */
  32. PUBLIC BOOL HTProtocol_add (CONST char *        name,
  33.     BOOL preemptive,
  34.     HTEventCallback * client,
  35.     HTEventCallback * server)
  36. {
  37.     if (name && (client || server)) {
  38. HTProtocol *newProt;
  39. if ((newProt = (HTProtocol  *) HT_CALLOC(1, sizeof(HTProtocol))) == NULL)
  40.     HT_OUTOFMEM("HTProtocol_add");
  41. StrAllocCopy(newProt->name, name);
  42. {
  43.     char *ptr = newProt->name;
  44.     while ((*ptr = TOLOWER(*ptr))) ptr++;
  45. }
  46. newProt->preemptive = preemptive;
  47. newProt->client = client;
  48. newProt->server = server;
  49. if (!protocols) protocols = HTList_new();
  50. return HTList_addObject(protocols, (void *) newProt);
  51.     }
  52.     return NO;
  53. }
  54. /*
  55. ** Deletes a Protocol module as an active access method
  56. */
  57. PUBLIC BOOL HTProtocol_delete (CONST char * name)
  58. {
  59.     if (protocols) {
  60. HTList *cur = protocols;
  61. HTProtocol *pres;
  62. while ((pres = (HTProtocol *) HTList_nextObject(cur))) {
  63.     if (!strcmp(pres->name, name)) {
  64. HT_FREE(pres->name);
  65. return HTList_removeObject(protocols, (void *) pres);
  66.     }
  67. }
  68.     }
  69.     return NO;
  70. }
  71. /*
  72. ** Returns the client callback function
  73. */
  74. PUBLIC HTEventCallback * HTProtocol_client (HTProtocol * protocol)
  75. {
  76.     return protocol ? protocol->client : NULL;
  77. }
  78. /*
  79. ** Returns the server callback function
  80. */
  81. PUBLIC HTEventCallback * HTProtocol_server (HTProtocol * protocol)
  82. {
  83.     return protocol ? protocol->server : NULL;
  84. }
  85. /*
  86. ** Returns YES if preemptive else NO
  87. */
  88. PUBLIC BOOL HTProtocol_preemptive (HTProtocol * protocol)
  89. {
  90.     return protocol ? protocol->preemptive : NO;
  91. }
  92. /*
  93. ** Delete the list of registered access methods. This is called from
  94. ** within HTLibTerminate. Thanks to Eric Sink, eric@spyglass.com
  95. */
  96. PUBLIC BOOL HTProtocol_deleteAll (void)
  97. {
  98.     if (protocols) {
  99. HTList *cur = protocols;
  100. HTProtocol *pres;
  101. while ((pres = (HTProtocol *) HTList_nextObject(cur))) {
  102.     HT_FREE(pres->name);
  103.     HT_FREE(pres);
  104. }
  105. HTList_delete(protocols);
  106. protocols = NULL;
  107. return YES;
  108.     }
  109.     return NO;
  110. }
  111. /*
  112. ** Search registered protocols to find suitable protocol object.
  113. ** Return protocol object or NULL
  114. */
  115. PUBLIC HTProtocol * HTProtocol_find (HTRequest * request, CONST char * access)
  116. {
  117.     if (request && access) {
  118. HTList * cur = protocols;
  119. HTProtocol * pres;
  120. if (cur) {
  121.     while ((pres = (HTProtocol *) HTList_nextObject(cur))) {
  122. if (!strcmp(pres->name, access)) return pres;
  123.     }
  124. }
  125. HTRequest_addError(request, ERR_FATAL, NO, HTERR_CLASS, (char*) access,
  126.    (int) strlen(access), "HTProtocol_find");
  127.     }
  128.     return NULL;
  129. }