http_parse.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*************************************************************************
  2. *
  3. * Copyright (C) 2018-2020 Ruilin Peng (Nick) <[email protected]>.
  4. *
  5. * smartdns is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * smartdns is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #ifndef HTTP_PARSER_H
  19. #define HTTP_PARSER_H
  20. #ifdef __cpluscplus
  21. extern "C" {
  22. #endif
  23. struct http_head;
  24. struct http_head_fields;
  25. typedef enum HTTP_METHOD {
  26. HTTP_METHOD_INVALID = 0,
  27. HTTP_METHOD_GET,
  28. HTTP_METHOD_HEAD,
  29. HTTP_METHOD_POST,
  30. HTTP_METHOD_PUT,
  31. HTTP_METHOD_DELETE,
  32. HTTP_METHOD_TRACE,
  33. HTTP_METHOD_CONNECT,
  34. } HTTP_METHOD;
  35. typedef enum HTTP_HEAD_TYPE {
  36. HTTP_HEAD_INVALID = 0,
  37. HTTP_HEAD_REQUEST = 1,
  38. HTTP_HEAD_RESPONSE = 2,
  39. } HTTP_HEAD_TYPE;
  40. struct http_head *http_head_init(int buffsize);
  41. HTTP_HEAD_TYPE http_head_get_head_type(struct http_head *http_head);
  42. HTTP_METHOD http_head_get_method(struct http_head *http_head);
  43. const char *http_head_get_url(struct http_head *http_head);
  44. const char *http_head_get_httpversion(struct http_head *http_head);
  45. int http_head_get_httpcode(struct http_head *http_head);
  46. char *http_head_get_httpcode_msg(struct http_head *http_head);
  47. char *http_head_get_data(struct http_head *http_head);
  48. int http_head_get_data_len(struct http_head *http_head);
  49. struct http_head_fields *http_head_first_fields(struct http_head *http_head);
  50. struct http_head_fields *http_head_next_fields(struct http_head_fields *fields);
  51. const char *http_head_get_fields_value(struct http_head *http_head, const char *name);
  52. int http_head_lookup_fields(struct http_head_fields *fields, const char **name, const char **value);
  53. /*
  54. * Returns:
  55. * >=0 - success http data len
  56. * -1 - Incomplete request
  57. * -2 - parse failed
  58. * -3 - buffer is small
  59. */
  60. int http_head_parse(struct http_head *http_head, const char *data, int data_len);
  61. void http_head_destroy(struct http_head *http_head);
  62. #ifdef __cpluscplus
  63. }
  64. #endif
  65. #endif // !HTTP_PARSER_H