httpfsm.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #pragma once
  2. #include "httpheader.h"
  3. #include <util/system/maxlen.h>
  4. #include <util/datetime/parser.h>
  5. #include <time.h>
  6. struct THttpHeaderParser {
  7. static constexpr int ErrFirstlineTypeMismatch = -3;
  8. static constexpr int ErrHeader = -2;
  9. static constexpr int Err = -1;
  10. static constexpr int Final = 0;
  11. static constexpr int NeedMore = 1;
  12. static constexpr int Accepted = 2;
  13. int Execute(const void* inBuf, size_t len) {
  14. return execute((unsigned char*)inBuf, (int)len);
  15. }
  16. int Execute(TStringBuf str) {
  17. return Execute(str.data(), str.size());
  18. }
  19. int Init(THttpHeader* h) {
  20. int ret = Init((THttpBaseHeader*)(h));
  21. hd = h;
  22. hd->Init();
  23. hreflangpos = hd->hreflangs;
  24. hreflangspace = HREFLANG_MAX;
  25. return ret;
  26. }
  27. int Init(THttpAuthHeader* h) {
  28. int ret = Init((THttpHeader*)(h));
  29. auth_hd = h;
  30. return ret;
  31. }
  32. int Init(THttpRequestHeader* h) {
  33. int ret = Init((THttpBaseHeader*)(h));
  34. request_hd = h;
  35. request_hd->Init();
  36. return ret;
  37. }
  38. THttpHeader* hd;
  39. long I;
  40. int Dc;
  41. TDateTimeFieldsDeprecated DateTimeFields;
  42. char buf[FETCHER_URL_MAX];
  43. size_t buflen;
  44. char* lastchar;
  45. const unsigned char* langstart;
  46. size_t langlen;
  47. char* hreflangpos;
  48. size_t hreflangspace;
  49. bool AcceptingXRobots;
  50. THttpAuthHeader* auth_hd;
  51. THttpRequestHeader* request_hd;
  52. private:
  53. THttpBaseHeader* base_hd;
  54. int cs;
  55. private:
  56. int Init(THttpBaseHeader* header) {
  57. base_hd = header;
  58. auth_hd = nullptr;
  59. request_hd = nullptr;
  60. hd = nullptr;
  61. init();
  62. return 0;
  63. }
  64. int execute(unsigned char* inBuf, int len);
  65. void init();
  66. };
  67. struct THttpChunkParser {
  68. int Execute(const void* inBuf, int len) {
  69. return execute((unsigned char*)inBuf, len);
  70. }
  71. int Init() {
  72. init();
  73. return 0;
  74. }
  75. int chunk_length;
  76. char* lastchar;
  77. long I;
  78. int Dc;
  79. i64 cnt64;
  80. private:
  81. int cs;
  82. int execute(unsigned char* inBuf, int len);
  83. void init();
  84. };