ftp.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/// $Id: ftp.h,v 1.4 2001/03/06 07:15:29 jgg Exp $
  3. // $Id: ftp.h,v 1.4 2001/03/06 07:15:29 jgg Exp $
  4. /* ######################################################################
  5. FTP Acquire Method - This is the FTP acquire method for APT.
  6. ##################################################################### */
  7. /*}}}*/
  8. #ifndef APT_FTP_H
  9. #define APT_FTP_H
  10. #include <apt-pkg/acquire-method.h>
  11. #include <apt-pkg/strutl.h>
  12. #include "aptmethod.h"
  13. #include <sys/socket.h>
  14. #include <sys/types.h>
  15. #include <time.h>
  16. #include <string>
  17. class FTPConn
  18. {
  19. char Buffer[1024*10];
  20. unsigned long Len;
  21. int ServerFd;
  22. int DataFd;
  23. int DataListenFd;
  24. URI ServerName;
  25. bool ForceExtended;
  26. bool TryPassive;
  27. bool Debug;
  28. struct addrinfo *PasvAddr;
  29. // Generic Peer Address
  30. struct sockaddr_storage PeerAddr;
  31. socklen_t PeerAddrLen;
  32. // Generic Server Address (us)
  33. struct sockaddr_storage ServerAddr;
  34. socklen_t ServerAddrLen;
  35. // Private helper functions
  36. bool ReadLine(std::string &Text);
  37. bool Login();
  38. bool CreateDataFd();
  39. bool Finalize();
  40. public:
  41. bool Comp(URI Other) {return Other.Host == ServerName.Host && Other.Port == ServerName.Port && Other.User == ServerName.User && Other.Password == ServerName.Password; };
  42. // Raw connection IO
  43. bool ReadResp(unsigned int &Ret,std::string &Text);
  44. bool WriteMsg(unsigned int &Ret,std::string &Text,const char *Fmt,...);
  45. // Connection control
  46. bool Open(pkgAcqMethod *Owner);
  47. void Close();
  48. bool GoPasv();
  49. bool ExtGoPasv();
  50. // Query
  51. bool Size(const char *Path,unsigned long long &Size);
  52. bool ModTime(const char *Path, time_t &Time);
  53. bool Get(const char *Path,FileFd &To,unsigned long long Resume,
  54. Hashes &MD5,bool &Missing, unsigned long long MaximumSize,
  55. pkgAcqMethod *Owner);
  56. explicit FTPConn(URI Srv);
  57. ~FTPConn();
  58. };
  59. class FtpMethod : public aptMethod
  60. {
  61. virtual bool Fetch(FetchItem *Itm) APT_OVERRIDE;
  62. virtual bool Configuration(std::string Message) APT_OVERRIDE;
  63. FTPConn *Server;
  64. static std::string FailFile;
  65. static int FailFd;
  66. static time_t FailTime;
  67. static APT_NORETURN void SigTerm(int);
  68. public:
  69. FtpMethod();
  70. };
  71. #endif