#define fcntlsocket fcntl
#endif
-#define TIMEOUT 5
+#define TIMEOUT 15
static int newconn(struct ftp *ftp);
static int sendcmd(struct ftp *ftp, const char *fmt, ...);
{
struct ftp_op *fop;
- if(!ftp->qhead) {
+ if(!ftp->busy && !ftp->qhead) {
exec_op(ftp, op, arg);
return 0;
}
if(!(fop = malloc(sizeof *fop))) {
return -1;
}
- if(!(fop->arg = strdup(arg))) {
- free(fop);
- return -1;
+ if(arg) {
+ if(!(fop->arg = strdup(arg))) {
+ free(fop);
+ return -1;
+ }
+ } else {
+ fop->arg = 0;
}
fop->op = op;
fop->next = 0;
- ftp->qtail->next = fop;
- ftp->qtail = fop;
+ if(ftp->qhead) {
+ ftp->qtail->next = fop;
+ ftp->qtail = fop;
+ } else {
+ ftp->qhead = ftp->qtail = fop;
+ }
return 0;
}
return -1;
}
+ ftp->busy = 1;
+
va_start(ap, fmt);
vsprintf(buf, fmt, ap);
va_end(ap);
if(ftp->cproc) {
if(ftp->cproc(ftp, code, buf, ftp->cproc_cls) <= 0) {
ftp->cproc = 0;
+ ftp->busy = 0;
/* execute next operation if there's one queued */
exec_queued(ftp);
errmsg("login failed\n");
break;
}
+ ftp->busy = 0;
}
static int newconn(struct ftp *ftp)
memcpy(ent->name, ptr, len);
ent->name[len] = 0;
- infomsg("name: %s\n", ent->name);
return 0;
}
tail = ent;
}
}
- while(*ptr && *ptr != '\n' && *ptr != '\r') ptr++;
- while(*ptr && (*ptr == '\r' || *ptr == '\n')) ptr++;
+ while(ptr < end && *ptr != '\n' && *ptr != '\r') ptr++;
+ while(ptr < end && (*ptr == '\r' || *ptr == '\n')) ptr++;
}
ftp->modified |= FTP_MOD_REMDIR;