Back to index

nordugrid-arc-nox  1.1.0~rc6
Lister.h
Go to the documentation of this file.
00001 // -*- indent-tabs-mode: nil -*-
00002 
00003 #ifndef __ARC_LISTER_H__
00004 #define __ARC_LISTER_H__
00005 
00006 #include <list>
00007 #include <string>
00008 
00009 #include <arc/data/FileInfo.h>
00010 
00011 #include <globus_ftp_control.h>
00012 
00013 #define LISTER_MAX_RESPONSES 3
00014 
00015 namespace Arc {
00016 
00017   class GSSCredential;
00018   class URL;
00019 
00020   class Lister {
00021   private:
00022     bool inited;
00023     bool facts;
00024     char readbuf[4096];
00025     globus_cond_t cond;
00026     globus_mutex_t mutex;
00027     globus_ftp_control_handle_t *handle;
00028     std::list<FileInfo> fnames;
00029     globus_ftp_control_response_t resp[LISTER_MAX_RESPONSES];
00030     int resp_n;
00031     enum callback_status_t {
00032       CALLBACK_NOTREADY = 0,
00033       CALLBACK_DONE = 1,
00034       CALLBACK_ERROR = 2
00035     };
00036     callback_status_t callback_status;
00037     callback_status_t data_callback_status;
00038     globus_off_t list_shift;
00039     bool connected;
00040     bool pasv_set;
00041     bool data_activated;
00042     bool free_format;
00043     unsigned short int port;
00044     std::string host;
00045     std::string username;
00046     std::string userpass;
00047     std::string path;
00048     std::string scheme;
00049     GSSCredential& credential;
00050 
00051     callback_status_t wait_for_callback();
00052     callback_status_t wait_for_data_callback();
00053     void resp_destroy();
00054     static void resp_callback(void *arg, globus_ftp_control_handle_t *h,
00055                               globus_object_t *error,
00056                               globus_ftp_control_response_t *response);
00057     static void list_read_callback(void *arg,
00058                                    globus_ftp_control_handle_t *hctrl,
00059                                    globus_object_t *error,
00060                                    globus_byte_t *buffer, globus_size_t length,
00061                                    globus_off_t offset, globus_bool_t eof);
00062     static void list_conn_callback(void *arg,
00063                                    globus_ftp_control_handle_t *hctrl,
00064                                    unsigned int stripe_ndx,
00065                                    globus_bool_t reused,
00066                                    globus_object_t *error);
00067     globus_ftp_control_response_class_t
00068     send_command(const char *command, const char *arg, bool wait_for_response,
00069                  char **sresp, char delim = 0);
00070     int setup_pasv(globus_ftp_control_host_port_t& pasv_addr);
00071     int handle_connect(const URL& url);
00072     int transfer_list(void);
00073 
00074   public:
00075     Lister(GSSCredential& credential);
00076     ~Lister();
00077     int retrieve_dir_info(const URL& url,bool names_only = false);
00078     int retrieve_file_info(const URL& url,bool names_only = false);
00079     operator bool() {
00080       return inited;
00081     }
00082     std::list<FileInfo>::iterator begin() {
00083       return fnames.begin();
00084     }
00085     std::list<FileInfo>::iterator end() {
00086       return fnames.end();
00087     }
00088     int size() const {
00089       return fnames.size();
00090     }
00091     int close_connection();
00092   };
00093 
00094 } // namespace Arc
00095 
00096 #endif // __ARC_LISTER_H__