https.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. static size_t parse_header(void *buffer, size_t size, size_t nmemb, void *userp);
  47. static size_t write_data(void *buffer, size_t size, size_t nmemb, void *userp);
  48. static int progress_callback(void *clientp, double dltotal, double dlnow,
  49. double ultotal, double ulnow);
  50. void SetupProxy();
  51. CURL *curl;
  52. FetchResult Res;
  53. HttpsServerState *Server;
  54. bool ReceivedData;
  55. public:
  56. FileFd *File;
  57. HttpsMethod() : pkgAcqMethod("1.2",Pipeline | SendConfig), File(NULL)
  58. {
  59. File = 0;
  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