https.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. public:
  55. FileFd *File;
  56. HttpsMethod() : pkgAcqMethod("1.2",Pipeline | SendConfig), Server(NULL), File(NULL)
  57. {
  58. curl = curl_easy_init();
  59. };
  60. ~HttpsMethod()
  61. {
  62. curl_easy_cleanup(curl);
  63. };
  64. };
  65. #include <apt-pkg/strutl.h>
  66. URI Proxy;
  67. #endif