Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

filetransfer.h

Go to the documentation of this file.
00001 #ifndef __msn_filetransfer_h__
00002 #define __msn_filetransfer_h__
00003 
00004 /*
00005  * filetransfer.h
00006  * libmsn
00007  *
00008  * Created by Mark Rowe on Wed Mar 17 2004.
00009  * Copyright (c) 2004 Mark Rowe. All rights reserved.
00010  *
00011  * This program is free software; you can redistribute it and/or modify
00012  * it under the terms of the GNU General Public License as published by
00013  * the Free Software Foundation; either version 2 of the License, or
00014  * (at your option) any later version.
00015  *
00016  * This program is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU General Public License
00022  * along with this program; if not, write to the Free Software
00023  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00024  */
00025 
00026 #include <msn/util.h>
00027 #include <msn/switchboardserver.h>
00028 #include <msn/invitation.h>
00029 #include <msn/passport.h>
00030 
00031 #include <string>
00032 #include <stdio.h>
00033 
00034 namespace MSN 
00035 {
00039     class FileTransferInvitation : public Invitation
00040     {
00041 public:
00044         std::string fileName;
00045         
00048         long unsigned fileSize;
00049         
00053         void * userData;
00054         
00059         FileTransferInvitation(Invitation::ApplicationType application_, std::string cookie_,
00060                        Passport otherUser_, SwitchboardServerConnection * switchboardConnection_,
00061                        std::string fileName_, long unsigned fileSize_, void *userData_ = NULL) :
00062             Invitation(application_, cookie_, otherUser_, switchboardConnection_),
00063             fileName(fileName_), fileSize(fileSize_), userData(userData_) {};
00064 
00067         virtual void invitationWasAccepted(const std::string & body);
00068         
00071         virtual void invitationWasCanceled(const std::string & body);
00072         
00080         void acceptTransfer(const std::string & destinationFile);
00081         
00084         void rejectTransfer();
00085         
00088         void cancelTransfer();
00089 private:        
00090         void sendFile(const std::string & msg_body);
00091         void receiveFile(const std::string & msg_body);
00092     };    
00093     
00094     
00101     class FileTransferConnection : public Connection
00102     {
00103 public:
00104         
00107         typedef enum 
00108         {
00109             MSNFTP_SEND,
00110             MSNFTP_RECV
00111         } Direction;
00112         
00115         typedef enum
00116         {
00117             MSNFTP_SERVER,
00118             MSNFTP_CLIENT
00119         } Perspective;
00120         
00123         typedef enum
00124         {
00125             WAITING_FOR_CONNECTION,
00126             NEGOTIATING,
00127             TRANSFERRING
00128         } Progress;
00129         
00133         class AuthData : public ::MSN::AuthData
00134         {
00135 public:
00136             std::string cookie;
00137             Direction direction;
00138             Perspective perspective;
00139             FileTransferInvitation *inv;
00140             FILE *fd;
00141             bool connected;
00142             unsigned long bytes_done;
00143             int num_ignore;
00144             
00145             AuthData(Passport username_, std::string cookie_, Direction direction_, 
00146                                  FileTransferInvitation *inv_=NULL, FILE *fd_=NULL, bool connected_=false,
00147                                  unsigned long bytes_done_=0) :
00148                 ::MSN::AuthData(username_), cookie(cookie_), direction(direction_),
00149                 perspective((direction == MSNFTP_RECV ? MSNFTP_CLIENT : MSNFTP_SERVER)), inv(inv_), 
00150                 fd(fd_), connected(connected_), bytes_done(bytes_done_), num_ignore(0) {};
00151             virtual ~AuthData() { if (fd) fclose(fd); };
00152         };
00153         
00154         FileTransferConnection::AuthData auth;
00155         
00156         FileTransferConnection(AuthData & auth_) : Connection(), auth(auth_) {};
00157         virtual ~FileTransferConnection();
00158         
00160         virtual void connect(const std::string & hostname, unsigned int port) {};
00161         virtual void disconnect();
00162         virtual void dispatchCommand(std::vector<std::string> & args) {};
00163 
00164         virtual void socketIsWritable();
00165         virtual void socketConnectionCompleted();
00166         virtual void dataArrivedOnSocket();
00167         virtual NotificationServerConnection *myNotificationServer() { return switchboardConnection()->myNotificationServer(); };        
00168 protected:
00169         virtual void handleIncomingData();
00170 private:
00171         void handleSend();
00172         void handleReceive();
00173         
00174         void handleSend_WaitingForConnection();
00175         void handleSend_Negotiating();
00176         void handleSend_Transferring();
00177         void handleSend_Bye();
00178         
00179         void handleReceive_Negotiating();
00180         void handleReceive_Transferring();
00181         
00182         SwitchboardServerConnection *switchboardConnection() { return this->auth.inv->switchboardConnection; };
00183     };
00184 }
00185 #endif

Generated on Sun Feb 6 19:59:40 2005 for libmsn by  doxygen 1.4.1