You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * Copyright 2000-2021 The OpenSSL Project Authors. All Rights Reserved.
  3. * Copyright Siemens AG 2018-2020
  4. *
  5. * Licensed under the Apache License 2.0 (the "License"). You may not use
  6. * this file except in compliance with the License. You can obtain a copy
  7. * in the file LICENSE in the source distribution or at
  8. * https://www.openssl.org/source/license.html
  9. */
  10. #ifndef OPENSSL_HTTP_H
  11. #define OPENSSL_HTTP_H
  12. #pragma once
  13. #include <openssl/opensslconf.h>
  14. #include <openssl/bio.h>
  15. #include <openssl/asn1.h>
  16. #include <openssl/conf.h>
  17. #ifdef __cplusplus
  18. extern "C"
  19. {
  20. #endif
  21. #define OSSL_HTTP_NAME "http"
  22. #define OSSL_HTTPS_NAME "https"
  23. #define OSSL_HTTP_PREFIX OSSL_HTTP_NAME "://"
  24. #define OSSL_HTTPS_PREFIX OSSL_HTTPS_NAME "://"
  25. #define OSSL_HTTP_PORT "80"
  26. #define OSSL_HTTPS_PORT "443"
  27. #define OPENSSL_NO_PROXY "NO_PROXY"
  28. #define OPENSSL_HTTP_PROXY "HTTP_PROXY"
  29. #define OPENSSL_HTTPS_PROXY "HTTPS_PROXY"
  30. #define OSSL_HTTP_DEFAULT_MAX_LINE_LEN (4 * 1024)
  31. #define OSSL_HTTP_DEFAULT_MAX_RESP_LEN (100 * 1024)
  32. /* Low-level HTTP API */
  33. OSSL_HTTP_REQ_CTX* OSSL_HTTP_REQ_CTX_new(BIO* wbio, BIO* rbio, int buf_size);
  34. void OSSL_HTTP_REQ_CTX_free(OSSL_HTTP_REQ_CTX* rctx);
  35. int OSSL_HTTP_REQ_CTX_set_request_line(OSSL_HTTP_REQ_CTX* rctx, int method_POST, const char* server, const char* port, const char* path);
  36. int OSSL_HTTP_REQ_CTX_add1_header(OSSL_HTTP_REQ_CTX* rctx, const char* name, const char* value);
  37. int OSSL_HTTP_REQ_CTX_set_expected(OSSL_HTTP_REQ_CTX* rctx, const char* content_type, int asn1, int timeout, int keep_alive);
  38. int OSSL_HTTP_REQ_CTX_set1_req(OSSL_HTTP_REQ_CTX* rctx, const char* content_type, const ASN1_ITEM* it, const ASN1_VALUE* req);
  39. int OSSL_HTTP_REQ_CTX_nbio(OSSL_HTTP_REQ_CTX* rctx);
  40. int OSSL_HTTP_REQ_CTX_nbio_d2i(OSSL_HTTP_REQ_CTX* rctx, ASN1_VALUE** pval, const ASN1_ITEM* it);
  41. BIO* OSSL_HTTP_REQ_CTX_exchange(OSSL_HTTP_REQ_CTX* rctx);
  42. BIO* OSSL_HTTP_REQ_CTX_get0_mem_bio(const OSSL_HTTP_REQ_CTX* rctx);
  43. size_t OSSL_HTTP_REQ_CTX_get_resp_len(const OSSL_HTTP_REQ_CTX* rctx);
  44. void OSSL_HTTP_REQ_CTX_set_max_response_length(OSSL_HTTP_REQ_CTX* rctx, unsigned long len);
  45. int OSSL_HTTP_is_alive(const OSSL_HTTP_REQ_CTX* rctx);
  46. /* High-level HTTP API */
  47. typedef BIO* (*OSSL_HTTP_bio_cb_t)(BIO* bio, void* arg, int connect, int detail);
  48. OSSL_HTTP_REQ_CTX* OSSL_HTTP_open(const char* server, const char* port, const char* proxy, const char* no_proxy, int use_ssl, BIO* bio, BIO* rbio, OSSL_HTTP_bio_cb_t bio_update_fn, void* arg, int buf_size, int overall_timeout);
  49. int OSSL_HTTP_proxy_connect(BIO* bio, const char* server, const char* port, const char* proxyuser, const char* proxypass, int timeout, BIO* bio_err, const char* prog);
  50. int OSSL_HTTP_set1_request(OSSL_HTTP_REQ_CTX* rctx, const char* path, const STACK_OF(CONF_VALUE) * headers, const char* content_type, BIO* req, const char* expected_content_type, int expect_asn1, size_t max_resp_len, int timeout, int keep_alive);
  51. BIO* OSSL_HTTP_exchange(OSSL_HTTP_REQ_CTX* rctx, char** redirection_url);
  52. BIO* OSSL_HTTP_get(const char* url, const char* proxy, const char* no_proxy, BIO* bio, BIO* rbio, OSSL_HTTP_bio_cb_t bio_update_fn, void* arg, int buf_size, const STACK_OF(CONF_VALUE) * headers, const char* expected_content_type, int expect_asn1, size_t max_resp_len, int timeout);
  53. BIO* OSSL_HTTP_transfer(OSSL_HTTP_REQ_CTX** prctx, const char* server, const char* port, const char* path, int use_ssl, const char* proxy, const char* no_proxy, BIO* bio, BIO* rbio, OSSL_HTTP_bio_cb_t bio_update_fn, void* arg, int buf_size, const STACK_OF(CONF_VALUE) * headers, const char* content_type, BIO* req, const char* expected_content_type, int expect_asn1, size_t max_resp_len, int timeout, int keep_alive);
  54. int OSSL_HTTP_close(OSSL_HTTP_REQ_CTX* rctx, int ok);
  55. /* Auxiliary functions */
  56. int OSSL_parse_url(const char* url, char** pscheme, char** puser, char** phost, char** pport, int* pport_num, char** ppath, char** pquery, char** pfrag);
  57. int OSSL_HTTP_parse_url(const char* url, int* pssl, char** puser, char** phost, char** pport, int* pport_num, char** ppath, char** pquery, char** pfrag);
  58. const char* OSSL_HTTP_adapt_proxy(const char* proxy, const char* no_proxy, const char* server, int use_ssl);
  59. #ifdef __cplusplus
  60. }
  61. #endif
  62. #endif /* !defined(OPENSSL_HTTP_H) */