https.h 3.0 KB

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