Skip to content

Commit

Permalink
New Logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Ortmann committed Jan 6, 2024
1 parent ecc4024 commit 32cf2d7
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 17 deletions.
4 changes: 3 additions & 1 deletion doc/sphinx_source/using/tcl-commands.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.. highlight:: text

Eggdrop Tcl Commands
Last revised: November 29, 2023
Last revised: January 6, 2024

====================
Eggdrop Tcl Commands
Expand Down Expand Up @@ -2011,6 +2011,8 @@ dccsend <filename> <ircnick>
| 4 | the file was queued for later transfer, which means that person has |
| | too many file transfers going right now |
+-------+---------------------------------------------------------------------+
| 5 | the file could not be opened or temporary file could not be created |
+-------+---------------------------------------------------------------------+

Module: transfer

Expand Down
14 changes: 14 additions & 0 deletions src/dccutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -311,11 +311,25 @@ void dcc_chatter(int idx)
/* Closes an open FD for transfer sockets. */
void killtransfer(int n)
{
int i, ok = 1;

if (dcc[n].type->flags & DCT_FILETRAN) {
if (dcc[n].u.xfer->f) {
fclose(dcc[n].u.xfer->f);
dcc[n].u.xfer->f = NULL;
}
if (dcc[n].u.xfer->filename) {
for (i = 0; i < dcc_total; i++) {
if ((i != n) && (dcc[i].type->flags & DCT_FILETRAN) &&
(dcc[i].u.xfer->filename) &&
(!strcmp(dcc[i].u.xfer->filename, dcc[n].u.xfer->filename))) {
ok = 0;
break;
}
}
if (ok)
unlink(dcc[n].u.xfer->filename);
}
}
}

Expand Down
8 changes: 8 additions & 0 deletions src/mod/filesys.mod/filesys.c
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,13 @@ static int _dcc_send(int idx, char *filename, char *nick, int resend)
dcc[idx].nick);
return 0;
}
if (x == DCCSEND_FCOPY) {
dprintf(idx, "Can't make temporary copy of file!\n");
putlog(LOG_FILES | LOG_MISC, "*",
"Refused dcc %sget %s: copy to temporary location FAILED!",
resend ? "re" : "", filename);
return 0;
}
nfn = strrchr(filename, '/');
if (nfn == NULL)
nfn = filename;
Expand Down Expand Up @@ -784,6 +791,7 @@ static void filesys_dcc_send_hostresolved(int i)
/* Put uploads in a temp file first */
dcc[i].u.xfer->f = tmpfile();
if (dcc[i].u.xfer->f == NULL) {
debug1("filesys: filesys_dcc_send_hostresolved(): tmpfile(): error: %s", strerror(errno));
dprintf(DP_HELP,
"NOTICE %s :Can't create file `%s' (temp dir error)\n",
dcc[i].nick, dcc[i].u.xfer->origname);
Expand Down
6 changes: 4 additions & 2 deletions src/mod/share.mod/share.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#define MODULE_NAME "share"
#define MAKING_SHARE

#include <errno.h>
#include "src/mod/module.h"

#include <netinet/in.h>
Expand Down Expand Up @@ -1242,8 +1243,9 @@ static void share_ufsend(int idx, char *par)
putlog(LOG_MISC, "*", "NO MORE DCC CONNECTIONS -- can't grab userfile");
dprintf(idx, "s e I can't open a DCC to you; I'm full.\n");
zapfbot(idx);
} else if (!(f = fopen(s, "wb"))) {
putlog(LOG_MISC, "*", "CAN'T WRITE USERFILE DOWNLOAD FILE!");
} else if (!(f = tmpfile())) {
debug1("share: share_ufsend(): tmpfile(): error: %s", strerror(errno));
putlog(LOG_MISC, "*", "CAN'T WRITE TEMPORARY USERFILE DOWNLOAD FILE!");
zapfbot(idx);
} else {
/* Ignore longip and use botaddr, arg kept for backward compat for pre 1.8.3 */
Expand Down
37 changes: 25 additions & 12 deletions src/mod/transfer.mod/transfer.c
Original file line number Diff line number Diff line change
Expand Up @@ -291,24 +291,28 @@ static void eof_dcc_send(int idx)
+ strlen(dcc[idx].u.xfer->origname) + 1);
sprintf(nfn, "%s%s", dcc[idx].u.xfer->dir, dcc[idx].u.xfer->origname);

/* Only close now in case it was a tmpfile, as it's deleted upon close
* TODO: This comment could be checked after copy-to-tmp was removed
*/
if ((l = fcopyfile(dcc[idx].u.xfer->f, nfn))) {
putlog(LOG_MISC | LOG_FILES, "*", TRANSFER_FAILED_MOVE, nfn);
}
/* Only close now in case it was a tmpfile, as it's deleted upon close */
fclose(dcc[idx].u.xfer->f);

/* lookup handle */
egg_snprintf(s, sizeof s, "%s!%s", dcc[idx].nick, dcc[idx].host);
u = get_user_by_host(s);
hand = u ? u->handle : "*";

/* Add to file database */
module_entry *fs = module_find("filesys", 0, 0);
if (fs != NULL) {
Function f = fs->funcs[FILESYS_ADDFILE];
f(dcc[idx].u.xfer->dir, dcc[idx].u.xfer->origname, hand);
/* Add to file database if copyfile succeeded */
if (!l) {
module_entry *fs = module_find("filesys", 0, 0);

if (fs != NULL) {
Function f = fs->funcs[FILESYS_ADDFILE];
f(dcc[idx].u.xfer->dir, dcc[idx].u.xfer->origname, hand);
}
stats_add_upload(u, dcc[idx].u.xfer->length);
check_tcl_sentrcvd(u, dcc[idx].nick, nfn, H_rcvd);
}
stats_add_upload(u, dcc[idx].u.xfer->length);
check_tcl_sentrcvd(u, dcc[idx].nick, nfn, H_rcvd);
nfree(nfn);

ok = 0;
Expand Down Expand Up @@ -957,8 +961,10 @@ static int raw_dcc_resend_send(char *filename, char *nick, char *from,

zz = -1;
f = fopen(filename, "r");
if (!f)
if (!f) {
debug2("transfer: raw_dcc_resend_send(): fopen(%s): error: %s", filename, strerror(errno));
return DCCSEND_BADFN;
}
fseeko(f, 0, SEEK_END);
dccfilesize = ftello(f);
fclose(f);
Expand All @@ -984,8 +990,15 @@ static int raw_dcc_resend_send(char *filename, char *nick, char *from,
else
nfn++;

if (!(f = fopen(filename, "r")))
f = tmpfile();
if (!f) {
debug1("transfer: raw_dcc_resend_send(): tmpfile(): error: %s", strerror(errno));
return DCCSEND_BADFN;
}
if (copyfilef(filename, f)) {
fclose(f);
return DCCSEND_FCOPY;
}

if ((i = new_dcc(&DCC_GET_PENDING, sizeof(struct xfer_info))) == -1) {
fclose(f);
Expand Down
5 changes: 3 additions & 2 deletions src/mod/transfer.mod/transfer.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ enum dccsend_types {
DCCSEND_FULL, /* DCC table is full */
DCCSEND_NOSOCK, /* Can not open a listening socket */
DCCSEND_BADFN, /* No such file */
DCCSEND_FEMPTY /* File is empty */
DCCSEND_FEMPTY, /* File is empty */
DCCSEND_FCOPY /* File failed to copy to tmpfile */
};

/* File matching */
Expand Down Expand Up @@ -64,7 +65,7 @@ enum dccsend_types {
#define TRANSFER_NOTICE_FNTOOLONG get_language(0xf17)
#define TRANSFER_TOO_BAD get_language(0xf18)
#define TRANSFER_NOTICE_TOOBAD get_language(0xf19)
/* #define TRANSFER_FAILED_MOVE get_language(0xf1a) */
#define TRANSFER_FAILED_MOVE get_language(0xf1a)
#define TRANSFER_THANKS get_language(0xf1b)
#define TRANSFER_NOTICE_THANKS get_language(0xf1c)
#define TRANSFER_USERFILE_LOST get_language(0xf1d)
Expand Down
5 changes: 5 additions & 0 deletions src/mod/transfer.mod/transferqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ static void send_next_file(char *to)
dprintf(DP_HELP, TRANSFER_NOTICE_SOCKERR, this->to);
strcpy(s, this->to);
flush_fileq(s);
} else if (x == DCCSEND_FCOPY) {
putlog(LOG_FILES | LOG_MISC, "*", TRANSFER_COPY_FAILED, this->file);
dprintf(DP_HELP, TRANSFER_FILESYS_BROKEN, this->to);
strcpy(s, this->to);
flush_fileq(s);
} else {
if (x == DCCSEND_FEMPTY) {
putlog(LOG_FILES, "*", TRANSFER_LOG_FILEEMPTY, this->file);
Expand Down

0 comments on commit 32cf2d7

Please sign in to comment.