more coverage more fixes Daniel

* gentest.py testapi.c: more coverage
* nanoftp.c tree.c: more fixes
Daniel
diff --git a/nanoftp.c b/nanoftp.c
index 5870936..83a23b0 100644
--- a/nanoftp.c
+++ b/nanoftp.c
@@ -783,6 +783,8 @@
     int len;
     int size;
 
+    if ((ctxt == NULL) || (ctxt->controlFd < 0)) return(-1);
+
     if ((ctxt->controlBufIndex < 0) || (ctxt->controlBufIndex > FTP_BUF_SIZE)) {
 #ifdef DEBUG_FTP
         xmlGenericError(xmlGenericErrorContext,
@@ -862,6 +864,8 @@
     int len;
     int res = -1, cur = -1;
 
+    if ((ctxt == NULL) || (ctxt->controlFd < 0)) return(-1);
+
 get_more:
     /*
      * Assumes everything up to controlBuf[controlBufIndex] has been read
@@ -949,6 +953,7 @@
     fd_set rfd;
     struct timeval tv;
 
+    if ((ctxt == NULL) || (ctxt->controlFd < 0)) return(-1);
     tv.tv_sec = 0;
     tv.tv_usec = 0;
     FD_ZERO(&rfd);
@@ -1037,6 +1042,8 @@
     char buf[200];
     int len, res;
 
+    if ((ctxt == NULL) || (ctxt->controlFd < 0)) return(-1);
+
     snprintf(buf, sizeof(buf), "QUIT\r\n");
     len = strlen(buf);
 #ifdef DEBUG_FTP
@@ -1448,6 +1455,8 @@
     xmlNanoFTPInit();
     if (server == NULL) 
 	return(NULL);
+    if (port <= 0)
+	return(NULL);
     ctxt = (xmlNanoFTPCtxtPtr) xmlNanoFTPNewCtxt(NULL);
     ctxt->hostname = xmlMemStrdup(server);
     if (port != 0)
@@ -1477,6 +1486,8 @@
     int len;
     int res;
 
+    if ((ctxt == NULL) || (ctxt->controlFd < 0)) return(-1);
+
     /*
      * Expected response code for CWD:
      *
@@ -1523,6 +1534,8 @@
     int len;
     int res;
 
+    if ((ctxt == NULL) || (ctxt->controlFd < 0) || (file == NULL)) return(-1);
+
     /*
      * Expected response code for DELE:
      *
@@ -1578,6 +1591,8 @@
 #endif
     SOCKLEN_T dataAddrLen;
 
+    if (ctxt == NULL) return(-1);
+
     memset (&dataAddr, 0, sizeof(dataAddr));
 #ifdef SUPPORT_IP6
     if ((ctxt->ftpAddr).ss_family == AF_INET6) {
@@ -1741,6 +1756,8 @@
     fd_set rfd, efd;
     struct timeval tv;
 
+    if ((ctxt == NULL) || (ctxt->controlFd < 0)) return(-1);
+
     closesocket(ctxt->dataFd); ctxt->dataFd = -1;
     tv.tv_sec = 15;
     tv.tv_usec = 0;
@@ -2025,6 +2042,8 @@
     xmlNanoFTPCtxtPtr ctxt = (xmlNanoFTPCtxtPtr) ctx;
     char buf[300];
     int res, len;
+    if (ctx == NULL)
+	return(-1);
     if ((filename == NULL) && (ctxt->path == NULL))
 	return(-1);
     ctxt->dataFd = xmlNanoFTPGetConnection(ctxt);