ql_http_client.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. /*============================================================================
  2. Copyright (c) 2020 Quectel Wireless Solution, Co., Ltd. All Rights Reserved.
  3. Quectel Wireless Solution Proprietary and Confidential.
  4. =============================================================================*/
  5. /*===========================================================================
  6. EDIT HISTORY FOR MODULE
  7. This section contains comments describing changes made to the module.
  8. Notice that changes are listed in reverse chronological order.
  9. WHEN WHO WHAT, WHERE, WHY
  10. ---------- ------------ ----------------------------------------------------
  11. =============================================================================*/
  12. #ifndef QL_HTTPLCLIENT_H
  13. #define QL_HTTPLCLIENT_H
  14. #define QL_HTTP_ERRCODE_BASE (QL_COMPONENT_LWIP_HTTP << 16)
  15. typedef int http_client_t;
  16. typedef void(*http_client_event_cb_t)(http_client_t *client, int evt, int evt_code, void *arg);
  17. typedef int(*http_client_write_data_cb_t)(http_client_t *client, void *arg, char *data, int size, unsigned char end);
  18. typedef int(*http_client_read_data_cb_t)(http_client_t *client, void *arg, char *data, int size);
  19. typedef enum{
  20. HTTPS_VERIFY_NONE = 0,
  21. HTTPS_VERIFY_SERVER = 1,
  22. HTTPS_VERIFY_SERVER_CLIENT = 2,
  23. }https_verify_level_e;
  24. typedef enum{
  25. HTTP_EVENT_SESSION_ESTABLISH = 0,
  26. HTTP_EVENT_RESPONE_STATE_LINE = 1,
  27. HTTP_EVENT_SESSION_DISCONNECT = 2,
  28. }http_event_id_e;
  29. typedef enum{
  30. QL_HTTP_OK = 0,
  31. QL_HTTP_ERROR_UNKNOWN = 701 | QL_HTTP_ERRCODE_BASE,
  32. QL_HTTP_ERROR_TIMEOUT = 702 | QL_HTTP_ERRCODE_BASE,
  33. QL_HTTP_ERROR_HTTP_BUSY = 703 | QL_HTTP_ERRCODE_BASE,
  34. QL_HTTP_ERROR_UART_BUSY = 704 | QL_HTTP_ERRCODE_BASE,
  35. QL_HTTP_ERROR_NOGETED = 705 | QL_HTTP_ERRCODE_BASE,
  36. QL_HTTP_ERROR_NETWORK_BUSY = 706 | QL_HTTP_ERRCODE_BASE,
  37. QL_HTTP_ERROR_NETWORK_OPENFAILED = 707 | QL_HTTP_ERRCODE_BASE,
  38. QL_HTTP_ERROR_NETWORK_NOCFG = 708 | QL_HTTP_ERRCODE_BASE,
  39. QL_HTTP_ERROR_NETWORK_DEACTIVE = 709 | QL_HTTP_ERRCODE_BASE,
  40. QL_HTTP_ERROR_NETWORK_ERROR = 710 | QL_HTTP_ERRCODE_BASE,
  41. QL_HTTP_ERROR_URL_ERROR = 711 | QL_HTTP_ERRCODE_BASE,
  42. QL_HTTP_ERROR_EMPTY_URL = 712 | QL_HTTP_ERRCODE_BASE,
  43. QL_HTTP_ERROR_IP_ERROR = 713 | QL_HTTP_ERRCODE_BASE,
  44. QL_HTTP_ERROR_DNS_ERROR = 714 | QL_HTTP_ERRCODE_BASE,
  45. QL_HTTP_ERROR_SOC_CREATEFAILED = 715 | QL_HTTP_ERRCODE_BASE,
  46. QL_HTTP_ERROR_SOC_CONNECTFAILED = 716 | QL_HTTP_ERRCODE_BASE,
  47. QL_HTTP_ERROR_SOC_READFAILED = 717 | QL_HTTP_ERRCODE_BASE,
  48. QL_HTTP_ERROR_SOC_WRITEFAILED = 718 | QL_HTTP_ERRCODE_BASE,
  49. QL_HTTP_ERROR_SOC_CLOSE = 719 | QL_HTTP_ERRCODE_BASE,
  50. QL_HTTP_ERROR_ENCODEERROR = 720 | QL_HTTP_ERRCODE_BASE,
  51. QL_HTTP_ERROR_DECODEERROR = 721 | QL_HTTP_ERRCODE_BASE,
  52. QL_HTTP_ERROR_TIMEOUT_TOREAD = 722 | QL_HTTP_ERRCODE_BASE,
  53. QL_HTTP_ERROR_HTTP_RESPONSE_FAILED = 723 | QL_HTTP_ERRCODE_BASE,
  54. QL_HTTP_ERROR_RINGBUSY = 724 | QL_HTTP_ERRCODE_BASE,
  55. QL_HTTP_ERROR_VOICEBUSY = 725 | QL_HTTP_ERRCODE_BASE,
  56. QL_HTTP_ERROR_TIMEOUT_INPUT = 726 | QL_HTTP_ERRCODE_BASE,
  57. QL_HTTP_ERROR_TIMEOUT_WAITDATA = 727 | QL_HTTP_ERRCODE_BASE,
  58. QL_HTTP_ERROR_TIMEOUT_WAITRESPONSE = 728 | QL_HTTP_ERRCODE_BASE,
  59. QL_HTTP_ERROR_MEMORYALLOC = 729 | QL_HTTP_ERRCODE_BASE,
  60. QL_HTTP_ERROR_PARAMETER = 730 | QL_HTTP_ERRCODE_BASE,
  61. QL_HTTP_ERROR_WONDBLOCK = 731 | QL_HTTP_ERRCODE_BASE,
  62. QL_HTTP_ERROR_SSL_HS_FAILED = 732 | QL_HTTP_ERRCODE_BASE,
  63. QL_HTTP_ERROR_FS_READFAILED = 733 | QL_HTTP_ERRCODE_BASE,
  64. }http_error_code_e;
  65. typedef enum {
  66. HTTP_METHOD_NONE,
  67. HTTP_METHOD_GET,
  68. HTTP_METHOD_POST,
  69. HTTP_METHOD_PUT,
  70. HTTP_METHOD_HEAD,
  71. HTTP_METHOD_LAST
  72. } http_method_e;
  73. typedef enum{
  74. HTTP_CLIENT_OPT_PDPCID = 1,
  75. HTTP_CLIENT_OPT_SSLCTXID = 2,
  76. HTTP_CLIENT_OPT_BASIC_AUTH = 3,
  77. HTTP_CLIENT_OPT_REQUEST_HEADER = 4,
  78. HTTP_CLIENT_OPT_WRITE_HEADER = 5,
  79. HTTP_CLIENT_OPT_INTERVAL_TIME = 6,
  80. HTTP_CLIENT_OPT_METHOD = 7,
  81. HTTP_CLIENT_OPT_WRITE_FUNC = 8,
  82. HTTP_CLIENT_OPT_WRITE_DATA = 9,
  83. HTTP_CLIENT_OPT_READ_FUNC = 10,
  84. HTTP_CLIENT_OPT_READ_DATA = 11,
  85. HTTP_CLIENT_OPT_UPLOAD_LEN = 12,
  86. HTTP_CLIENT_OPT_URL = 13,
  87. HTTP_CLIENT_OPT_SSL_VERIFY_LEVEL = 14,
  88. HTTP_CLIENT_OPT_SSL_CACERT_PATH = 15,
  89. HTTP_CLIENT_OPT_SSL_OWNCERT_PATH = 16,
  90. HTTP_CLIENT_OPT_URI = 17,
  91. HTTP_CLIENT_OPT_SIM_ID = 18,
  92. HTTP_CLIENT_OPT_SSL_SNI = 19,
  93. HTTP_CLIENT_OPT_SSL_VERSION = 20,
  94. HTTP_CLIENT_OPT_SSL_HS_TIMEOUT = 21,
  95. HTTP_CLIENT_OPT_SSL_IGNORE_LOCALTM = 22,
  96. HTTP_CLIENT_OPT_SSL_IGNORE_INVALID_CERT_SIGN = 23,
  97. HTTP_CLIENT_OPT_SSL_IGNORE_CERT_ITEM = 24,
  98. HTTP_CLIENT_OPT_SSL_IGNORE_MULTI_CERTCHAIN_VERIFY= 25,
  99. HTTP_CLIENT_OPT_RAW_REQUEST =26,
  100. HTTP_CLIENT_OPT_RAW_FILE =27,
  101. }http_option_e;
  102. typedef enum{
  103. HTTP_INFO_RESPONSE_CODE = 0,
  104. HTTP_INFO_LOCATION = 1,
  105. HTTP_INFO_DATE = 2,
  106. HTTP_INFO_CONTENT_LEN = 3,
  107. HTTP_INFO_CHUNK_ENCODE = 4,
  108. HTTP_INFO_ACCEPT_RANGES = 5,
  109. HTTP_INFO_PARTION_LEN = 6,
  110. }http_info_e;
  111. typedef enum{
  112. HTTP_FORM_NAME = 1,
  113. HTTP_FORM_FILENAME = 2,
  114. HTTP_FORM_CONTENT_TYPE = 3,
  115. }http_formopt_e;
  116. /*****************************************************************
  117. * Function: ql_httpc_new
  118. *
  119. * Description: 创建并初始化http_client上下文结构
  120. *
  121. * Parameters:
  122. * client [out] 用于回传http client上下文指针.
  123. * cb [in] 该http client上下文事件回调处理函数.
  124. * arg [in] 回调处理函数的自变量参数.
  125. *
  126. * Return:
  127. * 0 成功
  128. * other 错误码
  129. *
  130. *****************************************************************/
  131. int ql_httpc_new(http_client_t *client, http_client_event_cb_t cb, void *arg);
  132. /*****************************************************************
  133. * Function: ql_httpc_setopt
  134. *
  135. * Description: 通过opt_tag类型信息,配置http client上下文
  136. *
  137. * Parameters:
  138. * client [in] http client上下文指针.
  139. * opt_tag [in] http client上下文中配置的参数处理类型
  140. *
  141. * Return:
  142. * 0 成功
  143. * other 错误码
  144. *
  145. *****************************************************************/
  146. int ql_httpc_setopt(http_client_t *client, int opt_tag, ...);
  147. /*****************************************************************
  148. * Function: ql_httpc_continue_dload
  149. *
  150. * Description: 恢复client对应的http下载响应
  151. *
  152. * Parameters:
  153. * client [in] http client上下文指针.
  154. *
  155. * Return:
  156. * 0 成功
  157. * other 错误码
  158. *
  159. *****************************************************************/
  160. int ql_httpc_continue_dload(http_client_t *client);
  161. /*****************************************************************
  162. * Function: ql_httpc_formadd
  163. *
  164. * Description: 添加http的头部字段
  165. *
  166. * Parameters:
  167. * client [in] http client上下文指针.
  168. * opt_tag [in] http client上下文中配置添加http头部字段类型参数的处理.
  169. *
  170. * Return:
  171. * 0 成功
  172. * other 错误码
  173. *
  174. *****************************************************************/
  175. int ql_httpc_formadd(http_client_t *client, int opt_tag, ...);
  176. /*****************************************************************
  177. * Function: ql_httpc_perform
  178. *
  179. * Description: 关联http client此上下文和http的读写回调函数
  180. *
  181. * Parameters:
  182. * client [in] http client上下文指针.
  183. *
  184. * Return:
  185. * 0 成功
  186. * other 错误码
  187. *
  188. *****************************************************************/
  189. int ql_httpc_perform(http_client_t *client);
  190. /*****************************************************************
  191. * Function: ql_httpc_getinfo
  192. *
  193. * Description: 获取已配置的http client上下文的配置信息
  194. *
  195. * Parameters:
  196. * client [in] http client上下文指针.
  197. * info [in] http client上下文中配置的参数类型.
  198. *
  199. * Return:
  200. * 0 成功
  201. * other 错误码
  202. *
  203. *****************************************************************/
  204. int ql_httpc_getinfo(http_client_t *client, int info,...);
  205. /*****************************************************************
  206. * Function: ql_httpc_release
  207. *
  208. * Description: 释放http client上下文,以及http client上下文所占用内存块
  209. *
  210. * Parameters:
  211. * client [in] http client上下文指针.
  212. *
  213. * Return:
  214. * 0 成功
  215. * other 错误码
  216. *
  217. *****************************************************************/
  218. int ql_httpc_release(http_client_t *client);
  219. #endif