https.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 "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. protected:
  24. virtual bool ReadHeaderLines(std::string &/*Data*/) { return false; }
  25. virtual bool LoadNextResponse(bool const /*ToFile*/, FileFd * const /*File*/) { return false; }
  26. public:
  27. virtual bool WriteResponse(std::string const &/*Data*/) { return false; }
  28. /** \brief Transfer the data from the socket */
  29. virtual bool RunData(FileFd * const /*File*/) { return false; }
  30. virtual bool Open() { return false; }
  31. virtual bool IsOpen() { return false; }
  32. virtual bool Close() { return false; }
  33. virtual bool InitHashes(FileFd &/*File*/) { return false; }
  34. virtual Hashes * GetHashes() { return NULL; }
  35. virtual bool Die(FileFd &/*File*/) { return false; }
  36. virtual bool Flush(FileFd * const /*File*/) { return false; }
  37. virtual bool Go(bool /*ToFile*/, FileFd * const /*File*/) { return false; }
  38. HttpsServerState(URI Srv, HttpsMethod *Owner);
  39. virtual ~HttpsServerState() {Close();};
  40. };
  41. class HttpsMethod : public pkgAcqMethod
  42. {
  43. // minimum speed in bytes/se that triggers download timeout handling
  44. static const int DL_MIN_SPEED = 10;
  45. virtual bool Fetch(FetchItem *);
  46. virtual bool Configuration(std::string Message);
  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. FetchResult Res;
  54. HttpsServerState *Server;
  55. unsigned long long TotalWritten;
  56. public:
  57. FileFd *File;
  58. HttpsMethod() : pkgAcqMethod("1.2",Pipeline | SendConfig), Server(NULL), TotalWritten(0), File(NULL)
  59. {
  60. curl = curl_easy_init();
  61. };
  62. ~HttpsMethod()
  63. {
  64. curl_easy_cleanup(curl);
  65. };
  66. };
  67. #include <apt-pkg/strutl.h>
  68. URI Proxy;
  69. #endif