https.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/// $Id: http.h,v 1.12 2002/04/18 05:09:38 jgg Exp $
  3. // $Id: http.h,v 1.12 2002/04/18 05:09:38 jgg Exp $
  4. /* ######################################################################
  5. HTTP Acquire Method - This is the HTTP acquire method for APT.
  6. ##################################################################### */
  7. /*}}}*/
  8. #ifndef APT_HTTPS_H
  9. #define APT_HTTPS_H
  10. #include <curl/curl.h>
  11. #include <iostream>
  12. #include <stddef.h>
  13. #include <string>
  14. #include <memory>
  15. #include "server.h"
  16. using std::cout;
  17. using std::endl;
  18. class Hashes;
  19. class HttpsMethod;
  20. class FileFd;
  21. class HttpsServerState : public ServerState
  22. {
  23. Hashes * Hash;
  24. protected:
  25. virtual bool ReadHeaderLines(std::string &/*Data*/) APT_OVERRIDE { return false; }
  26. virtual bool LoadNextResponse(bool const /*ToFile*/, FileFd * const /*File*/) APT_OVERRIDE { return false; }
  27. public:
  28. virtual bool WriteResponse(std::string const &/*Data*/) APT_OVERRIDE { return false; }
  29. /** \brief Transfer the data from the socket */
  30. virtual bool RunData(FileFd * const /*File*/) APT_OVERRIDE { return false; }
  31. virtual bool Open() APT_OVERRIDE { return false; }
  32. virtual bool IsOpen() APT_OVERRIDE { return false; }
  33. virtual bool Close() APT_OVERRIDE { return false; }
  34. virtual bool InitHashes(HashStringList const &ExpectedHashes) APT_OVERRIDE;
  35. virtual Hashes * GetHashes() APT_OVERRIDE;
  36. virtual bool Die(FileFd &/*File*/) APT_OVERRIDE { return false; }
  37. virtual bool Flush(FileFd * const /*File*/) APT_OVERRIDE { return false; }
  38. virtual bool Go(bool /*ToFile*/, FileFd * const /*File*/) APT_OVERRIDE { return false; }
  39. HttpsServerState(URI Srv, HttpsMethod *Owner);
  40. virtual ~HttpsServerState() {Close();};
  41. };
  42. class HttpsMethod : public ServerMethod
  43. {
  44. // minimum speed in bytes/se that triggers download timeout handling
  45. static const int DL_MIN_SPEED = 10;
  46. virtual bool Fetch(FetchItem *) APT_OVERRIDE;
  47. static size_t parse_header(void *buffer, size_t size, size_t nmemb, void *userp);
  48. static size_t write_data(void *buffer, size_t size, size_t nmemb, void *userp);
  49. static int progress_callback(void *clientp, double dltotal, double dlnow,
  50. double ultotal, double ulnow);
  51. void SetupProxy();
  52. CURL *curl;
  53. // Used by ServerMethods unused by https
  54. virtual void SendReq(FetchItem *) APT_OVERRIDE { exit(42); }
  55. virtual void RotateDNS() APT_OVERRIDE { exit(42); }
  56. public:
  57. virtual bool Configuration(std::string Message) APT_OVERRIDE;
  58. virtual std::unique_ptr<ServerState> CreateServerState(URI const &uri) APT_OVERRIDE;
  59. using pkgAcqMethod::FetchResult;
  60. using pkgAcqMethod::FetchItem;
  61. HttpsMethod() : ServerMethod("https","1.2",Pipeline | SendConfig)
  62. {
  63. curl_global_init(CURL_GLOBAL_SSL);
  64. curl = curl_easy_init();
  65. };
  66. ~HttpsMethod()
  67. {
  68. curl_easy_cleanup(curl);
  69. };
  70. };
  71. #include <apt-pkg/strutl.h>
  72. URI Proxy;
  73. #endif