HTTPS.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #include "HTTPS.h"
  2. #include "config.h"
  3. #include "ConnectionClient.h"
  4. #include "LibraryLoader.h"
  5. #include <stdexcept>
  6. #ifdef HTTPS_BACKEND_CURL
  7. # include "../generic/CurlClient.h"
  8. #endif
  9. #ifdef HTTPS_BACKEND_OPENSSL
  10. # include "../generic/OpenSSLConnection.h"
  11. #endif
  12. #ifdef HTTPS_BACKEND_SCHANNEL
  13. # include "../windows/SChannelConnection.h"
  14. #endif
  15. #ifdef HTTPS_BACKEND_NSURL
  16. # include "../apple/NSURLClient.h"
  17. #endif
  18. #ifdef HTTPS_BACKEND_ANDROID
  19. # include "../android/AndroidClient.h"
  20. #endif
  21. #ifdef HTTPS_BACKEND_WININET
  22. # include "../windows/WinINetClient.h"
  23. #endif
  24. #ifdef HTTPS_BACKEND_CURL
  25. static CurlClient curlclient;
  26. #endif
  27. #ifdef HTTPS_BACKEND_OPENSSL
  28. static ConnectionClient<OpenSSLConnection> opensslclient;
  29. #endif
  30. #ifdef HTTPS_BACKEND_SCHANNEL
  31. static ConnectionClient<SChannelConnection> schannelclient;
  32. #endif
  33. #ifdef HTTPS_BACKEND_NSURL
  34. static NSURLClient nsurlclient;
  35. #endif
  36. #ifdef HTTPS_BACKEND_ANDROID
  37. static AndroidClient androidclient;
  38. #endif
  39. #ifdef HTTPS_BACKEND_WININET
  40. static WinINetClient wininetclient;
  41. #endif
  42. static HTTPSClient *clients[] = {
  43. #ifdef HTTPS_BACKEND_CURL
  44. &curlclient,
  45. #endif
  46. #ifdef HTTPS_BACKEND_OPENSSL
  47. &opensslclient,
  48. #endif
  49. // WinINet must be above SChannel
  50. #ifdef HTTPS_BACKEND_WININET
  51. &wininetclient,
  52. #endif
  53. #ifdef HTTPS_BACKEND_SCHANNEL
  54. &schannelclient,
  55. #endif
  56. #ifdef HTTPS_BACKEND_NSURL
  57. &nsurlclient,
  58. #endif
  59. #ifdef HTTPS_BACKEND_ANDROID
  60. &androidclient,
  61. #endif
  62. nullptr,
  63. };
  64. // Call into the library loader to make sure it is linked in
  65. static LibraryLoader::handle* dummyProcessHandle = LibraryLoader::GetCurrentProcessHandle();
  66. HTTPSClient::Reply request(const HTTPSClient::Request &req)
  67. {
  68. for (size_t i = 0; clients[i]; ++i)
  69. {
  70. HTTPSClient &client = *clients[i];
  71. if (client.valid())
  72. return client.request(req);
  73. }
  74. throw std::runtime_error("No applicable HTTPS implementation found");
  75. }