HTTPS.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #include "HTTPS.h"
  2. #include "config.h"
  3. #include "ConnectionClient.h"
  4. #include <stdexcept>
  5. #ifdef HTTPS_BACKEND_CURL
  6. # include "../generic/CurlClient.h"
  7. #endif
  8. #ifdef HTTPS_BACKEND_OPENSSL
  9. # include "../generic/OpenSSLConnection.h"
  10. #endif
  11. #ifdef HTTPS_BACKEND_SCHANNEL
  12. # include "../windows/SChannelConnection.h"
  13. #endif
  14. #ifdef HTTPS_BACKEND_NSURL
  15. # include "../apple/NSURLClient.h"
  16. #endif
  17. #ifdef HTTPS_BACKEND_ANDROID
  18. # include "../android/AndroidClient.h"
  19. #endif
  20. #ifdef HTTPS_BACKEND_CURL
  21. static CurlClient curlclient;
  22. #endif
  23. #ifdef HTTPS_BACKEND_OPENSSL
  24. static ConnectionClient<OpenSSLConnection> opensslclient;
  25. #endif
  26. #ifdef HTTPS_BACKEND_SCHANNEL
  27. static ConnectionClient<SChannelConnection> schannelclient;
  28. #endif
  29. #ifdef HTTPS_BACKEND_NSURL
  30. static NSURLClient nsurlclient;
  31. #endif
  32. #ifdef HTTPS_BACKEND_ANDROID
  33. static AndroidClient androidclient;
  34. #endif
  35. static HTTPSClient *clients[] = {
  36. #ifdef HTTPS_BACKEND_CURL
  37. &curlclient,
  38. #endif
  39. #ifdef HTTPS_BACKEND_OPENSSL
  40. &opensslclient,
  41. #endif
  42. #ifdef HTTPS_BACKEND_SCHANNEL
  43. &schannelclient,
  44. #endif
  45. #ifdef HTTPS_BACKEND_NSURL
  46. &nsurlclient,
  47. #endif
  48. #ifdef HTTPS_BACKEND_ANDROID
  49. &androidclient,
  50. #endif
  51. nullptr,
  52. };
  53. HTTPSClient::Reply request(const HTTPSClient::Request &req)
  54. {
  55. for (size_t i = 0; clients[i]; ++i)
  56. {
  57. HTTPSClient &client = *clients[i];
  58. if (client.valid())
  59. return client.request(req);
  60. }
  61. throw std::runtime_error("No applicable HTTPS implementation found");
  62. }