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

浏览器

开发平台:

Unix_Linux

  1. /*      HTMethod.c
  2. ** MANAGES REQUEST METHODS
  3. **
  4. ** (c) COPYRIGHT MIT 1995.
  5. ** Please first read the full copyright statement in the file COPYRIGH.
  6. **
  7. **
  8. ** HISTORY:
  9. ** 6 June 95  HFN Spawned off from HTAccess. Can be extended to allow
  10. ** registration of new methods
  11. */
  12. /* Library Include files */
  13. #include "tcp.h"
  14. #include "HTUtils.h"
  15. #include "HTString.h"
  16. #include "HTMethod.h"  /* Implemented here */
  17. PRIVATE char *method_names[] =
  18. {
  19.     "INVALID-METHOD",
  20.     "GET",
  21.     "HEAD",
  22.     "POST",
  23.     "PUT",
  24.     "DELETE",
  25.     "LINK",
  26.     "UNLINK",
  27.     NULL
  28. };
  29. /* ------------------------------------------------------------------------- */
  30. /* Get method enum value
  31. ** ---------------------
  32. */
  33. PUBLIC HTMethod HTMethod_enum (CONST char * name)
  34. {
  35.     if (name) {
  36. if (!strcasecomp(name, *(method_names+1)))
  37.     return METHOD_GET;
  38. else if (!strcasecomp(name, *(method_names+2)))
  39.     return METHOD_HEAD;
  40. else if (!strcasecomp(name, *(method_names+3)))
  41.     return METHOD_POST;
  42. else if (!strcasecomp(name, *(method_names+4)))
  43.     return METHOD_PUT;
  44. else if (!strcasecomp(name, *(method_names+5)))
  45.     return METHOD_DELETE;
  46. else if (!strcasecomp(name, *(method_names+6)))
  47.     return METHOD_LINK;
  48. else if (!strcasecomp(name, *(method_names+7)))
  49.     return METHOD_UNLINK;
  50.     }
  51.     return METHOD_INVALID;
  52. }
  53. /* Get method name
  54. ** ---------------
  55. ** Returns pointer to entry in static table in memory
  56. */
  57. PUBLIC CONST char * HTMethod_name (HTMethod method)
  58. {
  59.     if (method & METHOD_GET)
  60. return *(method_names+1);
  61.     else if (method == METHOD_HEAD)
  62. return *(method_names+2);
  63.     else if (method == METHOD_POST)
  64. return *(method_names+3);
  65.     else if (method == METHOD_PUT)
  66. return *(method_names+4);
  67.     else if (method == METHOD_DELETE)
  68. return *(method_names+5);
  69.     else if (method == METHOD_LINK)
  70. return *(method_names+6);
  71.     else if (method == METHOD_UNLINK)
  72. return *(method_names+7);
  73.     else
  74. return *method_names;
  75. }