--- tftpd/src/srv.c 2014/02/14 15:38:37 1.1 +++ tftpd/src/srv.c 2014/02/18 12:46:39 1.3 @@ -1,4 +1,6 @@ #include "global.h" +#include "exec.h" +#include "srv.h" static void * @@ -30,16 +32,18 @@ txPkt(sched_task_t *task) else if (wlen != TASK_DATLEN(task)) { EERROR(EIO, "Sended %d bytes != packet %d bytes", wlen, TASK_DATLEN(task)); + schedEvent(TASK_ROOT(task), execProg, "error", 0, NULL, TFTP_OPC_ERROR); schedCancelby(TASK_ROOT(task), taskTIMER, CRITERIA_CALL, timeoutSession, NULL); - memset(&cli, 0, sizeof(sockaddr_t)); + schedEvent(TASK_ROOT(task), timeoutSession, NULL, 0, NULL, 0); } else EVERBOSE(2, "Sended %d bytes", wlen); /* on error or argument, drop session */ if (TASK_ARG(task) == (void*) -1 || ntohs(tftp->tftp_opc) == TFTP_OPC_ERROR) { + schedEvent(TASK_ROOT(task), execProg, "error", 0, NULL, TFTP_OPC_ERROR); schedCancelby(TASK_ROOT(task), taskTIMER, CRITERIA_CALL, timeoutSession, NULL); - memset(&cli, 0, sizeof cli); + schedEvent(TASK_ROOT(task), timeoutSession, NULL, 0, NULL, 0); } taskExit(task, NULL); @@ -104,6 +108,7 @@ txAck(sched_task_t *task) TASK_DATA(task), RPACK_OFF(pkt)); if (cli.close) { + schedEvent(TASK_ROOT(task), execProg, "complete", 0, NULL, TFTP_OPC_WRQ); schedCancelby(TASK_ROOT(task), taskTIMER, CRITERIA_CALL, timeoutSession, NULL); schedEvent(TASK_ROOT(task), timeoutSession, NULL, 0, NULL, 0); EVERBOSE(2, "Finish WRQ request"); @@ -111,13 +116,22 @@ txAck(sched_task_t *task) taskExit(task, NULL); } +static int +getOpts(const char *opts, int rlen) +{ + if (!opts) + return -1; + + return 0; +} + static void * RQ(sched_task_t *task) { rpack_t *pkt = TASK_DATA(task); struct tftp_hdr *tftp = (struct tftp_hdr*) RPACK_BUF(pkt); int len, rlen = TASK_DATLEN(task) - 2; - char *str; + char *str, *opts; u_short code = 0; ETRACE(); @@ -130,7 +144,7 @@ RQ(sched_task_t *task) rlen -= len; strlcpy(cli.file, (char*) tftp->tftp_data, sizeof cli.file); } - len = str_getString((const u_char*) str, rlen, NULL); + len = str_getString((const u_char*) str, rlen, &opts); if (len == -1) goto end; else { @@ -149,6 +163,10 @@ RQ(sched_task_t *task) } } + /* tftp extended options */ + if (!RPACK_ISEND(pkt) && !getOpts(opts, rlen)) + cli.opts = 42; /* we have options */ + cli.opc = ntohs(tftp->tftp_opc); switch (cli.opc) { case TFTP_OPC_RRQ: @@ -178,6 +196,8 @@ RQ(sched_task_t *task) } else cli.seq = 0; + schedEvent(TASK_ROOT(task), execProg, "request", 0, NULL, cli.opc); + if (cli.opc == TFTP_OPC_WRQ) { /* ack */ tftp->tftp_opc = htons(TFTP_OPC_ACK); @@ -234,6 +254,7 @@ ACK(sched_task_t *task) schedEvent(TASK_ROOT(task), txData, NULL, TASK_FD(task), TASK_DATA(task), 0); else { + schedEvent(TASK_ROOT(task), execProg, "complete", 0, NULL, TFTP_OPC_RRQ); schedCancelby(TASK_ROOT(task), taskTIMER, CRITERIA_CALL, timeoutSession, NULL); schedEvent(TASK_ROOT(task), timeoutSession, NULL, 0, NULL, 0); EVERBOSE(2, "Finish RRQ request");