ftp.h 2.2 KB

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