author | llornkcor <llornkcor> | 2002-11-09 15:27:29 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-11-09 15:27:29 (UTC) |
commit | fee37fd9a7c038dbf5cce74172721ca3cdc8745b (patch) (side-by-side diff) | |
tree | dc9ed0da618d4ef6e96777e992cfc88fa619656c | |
parent | d5d079c5bfaa10c310628d1ef7905d98b64dfa81 (diff) | |
download | opie-fee37fd9a7c038dbf5cce74172721ca3cdc8745b.zip opie-fee37fd9a7c038dbf5cce74172721ca3cdc8745b.tar.gz opie-fee37fd9a7c038dbf5cce74172721ca3cdc8745b.tar.bz2 |
move ftp stuff from opieftp to shared lib
-rw-r--r-- | noncore/net/ftplib/ftplib.c (renamed from noncore/net/opieftp/ftplib.c) | 60 | ||||
-rw-r--r-- | noncore/net/ftplib/ftplib.control | 9 | ||||
-rw-r--r-- | noncore/net/ftplib/ftplib.h (renamed from noncore/net/opieftp/ftplib.h) | 0 | ||||
-rw-r--r-- | noncore/net/ftplib/ftplib.pro | 6 | ||||
-rw-r--r-- | noncore/net/opieftp/opieftp.control | 2 | ||||
-rw-r--r-- | noncore/net/opieftp/opieftp.cpp | 6 | ||||
-rw-r--r-- | noncore/net/opieftp/opieftp.h | 2 | ||||
-rw-r--r-- | noncore/net/opieftp/opieftp.pro | 4 |
8 files changed, 81 insertions, 8 deletions
diff --git a/noncore/net/opieftp/ftplib.c b/noncore/net/ftplib/ftplib.c index 5116170..421f855 100644 --- a/noncore/net/opieftp/ftplib.c +++ b/noncore/net/ftplib/ftplib.c @@ -16,52 +16,64 @@ /* You should have received a copy of the GNU Library General Public */ /* License along with this progam; if not, write to the */ /* Free Software Foundation, Inc., 59 Temple Place - Suite 330, */ /* Boston, MA 02111-1307, USA. */ /* */ /***************************************************************************/ - +// changes made by Lorn Potter <llornkcor@handhelds.org> +// #if defined(__unix__) || defined(__VMS) #include <unistd.h> #endif #if defined(_WIN32) #include <windows.h> #endif + #include <stdio.h> #include <stdlib.h> #include <string.h> #include <errno.h> #include <ctype.h> + #if defined(__unix__) + +#include <sys/types.h> +#include <unistd.h> +#include <fcntl.h> #include <sys/time.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <netdb.h> #include <arpa/inet.h> + #elif defined(VMS) + #include <types.h> #include <socket.h> #include <in.h> #include <netdb.h> #include <inet.h> + #elif defined(_WIN32) + #include <winsock.h> + #endif #define BUILDING_LIBRARY #include "ftplib.h" #if defined(_WIN32) #define SETSOCKOPT_OPTVAL_TYPE (const char *) #else #define SETSOCKOPT_OPTVAL_TYPE (void *) #endif #define FTPLIB_BUFSIZ 8192 -#define ACCEPT_TIMEOUT 15 +#define ACCEPT_TIMEOUT 10 #define FTPLIB_CONTROL 0 #define FTPLIB_READ 1 #define FTPLIB_WRITE 2 #if !defined FTPLIB_DEFMODE @@ -379,20 +391,22 @@ GLOBALDEF char *FtpLastResponse(netbuf *nControl) * FtpConnect - connect to remote server * * return 1 if connected, 0 if not */ GLOBALDEF int FtpConnect(const char *host, netbuf **nControl) { - int sControl; + int sControl, stat, flags, oldflags; struct sockaddr_in sin; struct hostent *phe; struct servent *pse; int on=1; netbuf *ctrl; char *lhost; char *pnum; + struct timeval tv; + fd_set wr; memset(&sin,0,sizeof(sin)); sin.sin_family = AF_INET; lhost = strdup(host); pnum = strchr(lhost,':'); if (pnum == NULL) @@ -423,34 +437,71 @@ GLOBALDEF int FtpConnect(const char *host, netbuf **nControl) { if ((phe = gethostbyname(lhost)) == NULL) { perror("gethostbyname"); return 0; } + memcpy((char *)&sin.sin_addr, phe->h_addr, phe->h_length); + } free(lhost); + sControl = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); if (sControl == -1) { perror("socket"); return 0; } + if (setsockopt(sControl,SOL_SOCKET,SO_REUSEADDR, SETSOCKOPT_OPTVAL_TYPE &on, sizeof(on)) == -1) { perror("setsockopt"); net_close(sControl); return 0; } - if (connect(sControl, (struct sockaddr *)&sin, sizeof(sin)) == -1) + + //set nonblocking for connection timeout + flags = fcntl( sControl, F_GETFL,0); + oldflags=flags; + fcntl( sControl, F_SETFL, O_NONBLOCK|flags); + + stat=connect( sControl, (struct sockaddr *)&sin, sizeof(sin)); + if (stat < 0) + { + if (errno != EWOULDBLOCK && errno != EINPROGRESS) { perror("connect"); net_close(sControl); return 0; } + } + + FD_ZERO(&wr); + FD_SET( sControl, &wr); + + tv.tv_sec = ACCEPT_TIMEOUT; + tv.tv_usec = 0; + + stat = select(sControl+1, 0, &wr, 0, &tv); + + if (stat < 1) + { + // time out has expired, + // or an error has ocurred + perror("timeout"); + net_close(sControl); + return 0; + } + + printf("connected\n"); + + //set original flags + fcntl( sControl, F_SETFL, oldflags); + ctrl = calloc(1,sizeof(netbuf)); if (ctrl == NULL) { perror("calloc"); net_close(sControl); return 0; @@ -734,12 +785,13 @@ static int FtpAcceptConnection(netbuf *nData, netbuf *nControl) FD_ZERO(&mask); FD_SET(nControl->handle, &mask); FD_SET(nData->handle, &mask); tv.tv_usec = 0; tv.tv_sec = ACCEPT_TIMEOUT; + printf("<<<<<<<<<<<<<<<<%d\n",ACCEPT_TIMEOUT); i = nControl->handle; if (i < nData->handle) i = nData->handle; i = select(i+1, &mask, NULL, NULL, &tv); if (i == -1) { diff --git a/noncore/net/ftplib/ftplib.control b/noncore/net/ftplib/ftplib.control new file mode 100644 index 0000000..67765ad --- a/dev/null +++ b/noncore/net/ftplib/ftplib.control @@ -0,0 +1,9 @@ +Files: $QTDIR/lib/libftplib.* +Priority: optional +Section: Communications +Maintainer: L.J. Potter <ljp@llornkcor.com> +Architecture: arm +Version: $QPE_VERSION-$SUB_VERSION +Depends: opie-base ($QPE_VERSION) +Description: Libftp + The ftp library for the Opie environment. diff --git a/noncore/net/opieftp/ftplib.h b/noncore/net/ftplib/ftplib.h index 75a90ae..75a90ae 100644 --- a/noncore/net/opieftp/ftplib.h +++ b/noncore/net/ftplib/ftplib.h diff --git a/noncore/net/ftplib/ftplib.pro b/noncore/net/ftplib/ftplib.pro new file mode 100644 index 0000000..9ee3605 --- a/dev/null +++ b/noncore/net/ftplib/ftplib.pro @@ -0,0 +1,6 @@ +TEMPLATE = lib +CONFIG = qt warn_on release +HEADERS = ftplib.h +SOURCES = ftplib.c +DESTDIR = $(QTDIR)/lib$(PROJMAK) +INTERFACES = diff --git a/noncore/net/opieftp/opieftp.control b/noncore/net/opieftp/opieftp.control index 18ec80f..42590bd 100644 --- a/noncore/net/opieftp/opieftp.control +++ b/noncore/net/opieftp/opieftp.control @@ -1,9 +1,9 @@ Files: bin/opieftp pics/opieftp apps/Applications/opieftp.desktop Priority: optional Section: Communications Maintainer: L.J. Potter <ljp@llornkcor.com> Architecture: arm Version: $QPE_VERSION-$SUB_VERSION -Depends: opie-base ($QPE_VERSION) +Depends: opie-base ($QPE_VERSION), ftplib Description: OpieFtp The ftp client for the Opie environment. diff --git a/noncore/net/opieftp/opieftp.cpp b/noncore/net/opieftp/opieftp.cpp index 292cc9d..7c83223 100644 --- a/noncore/net/opieftp/opieftp.cpp +++ b/noncore/net/opieftp/opieftp.cpp @@ -11,13 +11,13 @@ ***************************************************************************/ //#define DEVELOPERS_VERSION #include "opieftp.h" extern "C" { -#include "ftplib.h" +#include "../ftplib/ftplib.h" } #include "inputDialog.h" #include <qpe/qpemenubar.h> #include <qpe/qpetoolbar.h> @@ -1507,6 +1507,10 @@ void OpieFtp::serverListClicked( const QString &item) { for (int i = 1; i <= numberOfEntries; i++) { cfg.setGroup(QString::number(i)); if(cfg.readEntry( "ServerName").find(item) != -1 && !fuckeduphack) serverComboSelected(i-1); } } + +void OpieFtp::timerOut() { + +} diff --git a/noncore/net/opieftp/opieftp.h b/noncore/net/opieftp/opieftp.h index 2aa691a..109b5f8 100644 --- a/noncore/net/opieftp/opieftp.h +++ b/noncore/net/opieftp/opieftp.h @@ -36,12 +36,13 @@ class QPopupMenu; class QFile; class QLineEdit; class QPushButton; class QToolButton; class QStringList; class QListBox; +class QTimer; class OpieFtp : public QMainWindow { Q_OBJECT public: @@ -64,12 +65,13 @@ public: QListViewItem * item; QPushButton *connectServerBtn, *newServerButton;// QToolButton *cdUpButton, *homeButton, *docButton; bool b; int currentServerConfig; protected slots: + void timerOut(); void upDir(); void homeButtonPushed(); void docButtonPushed(); void doAbout(); void serverComboEdited(const QString & ); diff --git a/noncore/net/opieftp/opieftp.pro b/noncore/net/opieftp/opieftp.pro index 6d88530..ae72ff3 100644 --- a/noncore/net/opieftp/opieftp.pro +++ b/noncore/net/opieftp/opieftp.pro @@ -1,15 +1,15 @@ TEMPLATE = app CONFIG += qt warn_on release HEADERS = opieftp.h inputDialog.h ftplib.h -SOURCES = opieftp.cpp inputDialog.cpp ftplib.c main.cpp +SOURCES = opieftp.cpp inputDialog.cpp main.cpp TARGET = opieftp DESTDIR = $(OPIEDIR)/bin INCLUDEPATH += $(OPIEDIR)/include DEPENDPATH += $(OPIEDIR)/include -LIBS += -lqpe +LIBS += -lqpe -lftplib TRANSLATIONS = ../../../i18n/de/opieftp.ts \ ../../../i18n/en/opieftp.ts \ ../../../i18n/es/opieftp.ts \ ../../../i18n/fr/opieftp.ts \ ../../../i18n/hu/opieftp.ts \ |