? curl.vpj
? curl.vpw
? curl.vpwhistu
? curl.vtg
Index: lib/tftp.c
===================================================================
RCS file: /cvsroot/curl/curl/lib/tftp.c,v
retrieving revision 1.94
diff -r1.94 tftp.c
72a73
> #include "multiif.h"
79c80
< #include "curl_memory.h"
---
> #include "memory.h"
106c107,108
<   TFTP_EVENT_INIT=0,
---
>   TFTP_EVENT_NONE = -1,
>   TFTP_EVENT_INIT = 0,
139a142
>   tftp_event_t    event;
143,144c146,147
<   time_t          retry_time;
<   time_t          retry_max;
---
>   int             retry_time;
>   int             retry_max;
146a150
>   time_t	  rx_time;
150,153c154,157
<   curl_socklen_t  remote_addrlen;
<   ssize_t         rbytes;
<   size_t          sbytes;
<   size_t          blksize;
---
>   socklen_t       remote_addrlen;
>   int             rbytes;
>   int             sbytes;
>   int             blksize;
168a173,177
> static CURLcode tftp_multi_statemach(struct connectdata *conn, bool *done);
> static CURLcode tftp_doing(struct connectdata *conn, bool *dophase_done);
> static int tftp_getsock(struct connectdata *conn, curl_socket_t *socks,
>                         int numsocks);
> CURLcode tftp_translate_code(tftp_error_t error);
182,185c191,194
<   ZERO_NULL,                            /* connecting */
<   ZERO_NULL,                            /* doing */
<   ZERO_NULL,                            /* proto_getsock */
<   ZERO_NULL,                            /* doing_getsock */
---
>   tftp_multi_statemach,                 /* connecting */
>   tftp_doing,                           /* doing */
>   tftp_getsock,                         /* proto_getsock */
>   tftp_getsock,                         /* doing_getsock */
192d200
< 
229c237
<     state->retry_max = timeout/5;
---
>     state->retry_max = (int)timeout/5;
236c244
<     state->retry_time = timeout/state->retry_max;
---
>     state->retry_time = (int)timeout/state->retry_max;
253c261
<     state->retry_max = timeout/15;
---
>     state->retry_max = (int)timeout/15;
255c263
<   /* But bound the total number  */
---
>   /* But bound the total number */
262c270
<   /* Compute the re-ACK interval to suit the timeout */
---
>   /* Compute the re-ACK interval to suit the timeout 
265a274
>   */
271a281,283
>   /* init RX time */
>   time(&state->rx_time);
> 
355c367
<       int blksize;
---
>       long int blksize;
357c369
<       blksize = (int)strtol( value, NULL, 10 );
---
>       blksize = strtol( value, NULL, 10 );
382c394
<       state->blksize = blksize;
---
>       state->blksize = (int)blksize;
405c417
<   if( ( strlen(option) + csize + 1U ) > state->blksize )
---
>   if( ( strlen(option) + csize + 1 ) > (size_t)state->blksize )
414d425
< #ifndef CURL_DISABLE_VERBOSE_STRINGS
418d428
< #endif
429d438
< #ifndef CURL_DISABLE_VERBOSE_STRINGS
433d441
< #endif
443a452
>   ssize_t senddata;
509,510c518,519
<     /* add timeout option */
<     snprintf( buf, sizeof(buf), "%d", state->retry_time );
---
>     /* add timeout option, this is the max time the session may live */
>     snprintf( buf, sizeof(buf), "%d", state->retry_time*state->retry_max );
517,520c526,530
<     if (sendto(state->sockfd, (void *)state->spacket.data,
<                sbytes, 0,
<                state->conn->ip_addr->ai_addr,
<                state->conn->ip_addr->ai_addrlen) < 0) {
---
>     senddata = sendto(state->sockfd, (void *)state->spacket.data,
>                     sbytes, 0,
>                     state->conn->ip_addr->ai_addr,
>                     state->conn->ip_addr->ai_addrlen);
>     if(senddata != (ssize_t)sbytes) {
562a573
>   ssize_t sbytes;
587,590c598,602
<     if(sendto(state->sockfd, (void *)state->spacket.data,
<               4, SEND_4TH_ARG,
<               (struct sockaddr *)&state->remote_addr,
<               state->remote_addrlen) < 0) {
---
>     sbytes = sendto(state->sockfd, (void *)state->spacket.data,
>                     4, SEND_4TH_ARG,
>                     (struct sockaddr *)&state->remote_addr,
>                     state->remote_addrlen);
>     if(sbytes < 0) {
601a614
>     time(&state->rx_time);
610,613c623,627
<     if(sendto(state->sockfd, (void *)state->spacket.data,
<               4, SEND_4TH_ARG,
<               (struct sockaddr *)&state->remote_addr,
<               state->remote_addrlen) < 0) {
---
>     sbytes = sendto(state->sockfd, (void *)state->spacket.data,
>                     4, SEND_4TH_ARG,
>                     (struct sockaddr *)&state->remote_addr,
>                     state->remote_addrlen);
>     if(sbytes < 0) {
619a634
>     time(&state->rx_time);
632,636c647,653
<       /* Resend the previous ACK and check all sbytes were sent */
<       if(sendto(state->sockfd, (void *)state->spacket.data,
<                 4, SEND_4TH_ARG,
<                 (struct sockaddr *)&state->remote_addr,
<                 state->remote_addrlen) < 0) {
---
>       /* Resend the previous ACK */
>       sbytes = sendto(state->sockfd, (void *)state->spacket.data,
>                       4, SEND_4TH_ARG,
>                       (struct sockaddr *)&state->remote_addr,
>                       state->remote_addrlen);
>       /* Check all sbytes were sent */
>       if(sbytes<0) {
643a661,668
>     setpacketevent(&state->spacket, TFTP_EVENT_ERROR);
>     setpacketblock(&state->spacket, state->block);
>     sbytes = sendto(state->sockfd, (void *)state->spacket.data,
>                     4, SEND_4TH_ARG,
>                     (struct sockaddr *)&state->remote_addr,
>                     state->remote_addrlen);
>     /* don't bother with the return code, but if the socket is still up we
>      * should be a good TFTP client and let the server know we're done */
664a690
>   ssize_t sbytes;
666d691
<   int readcount;
688,692c713,719
<         /* Re-send the data packet and check all sbytes were sent */
<         if(sendto(state->sockfd, (void *)&state->spacket,
<                   4+state->sbytes, SEND_4TH_ARG,
<                   (struct sockaddr *)&state->remote_addr,
<                   state->remote_addrlen) < 0) {
---
>         /* Re-send the data packet */
>         sbytes = sendto(state->sockfd, (void *)&state->spacket,
>                         4+state->sbytes, SEND_4TH_ARG,
>                         (struct sockaddr *)&state->remote_addr,
>                         state->remote_addrlen);
>         /* Check all sbytes were sent */
>         if(sbytes<0) {
699,700d725
<     /* fall-through */
<   case TFTP_EVENT_OACK:
702a728
>     time(&state->rx_time);
707c733
<     if(state->block > 1 && state->sbytes < state->blksize) {
---
>     if(state->block > 1 && state->sbytes < (int)state->blksize) {
711,712c737,738
<     res = Curl_fillreadbuffer(state->conn, (int)state->blksize, &readcount);
<     state->sbytes = readcount;
---
>     res = Curl_fillreadbuffer(state->conn, (size_t)state->blksize,
>                               &state->sbytes);
715,719c741,746
<     /* Send the data packet and check all sbytes were sent */
<     if(sendto(state->sockfd, (void *)state->spacket.data,
<               4+state->sbytes, SEND_4TH_ARG,
<               (struct sockaddr *)&state->remote_addr,
<               state->remote_addrlen) < 0) {
---
>     sbytes = sendto(state->sockfd, (void *)state->spacket.data,
>                     4+state->sbytes, SEND_4TH_ARG,
>                     (struct sockaddr *)&state->remote_addr,
>                     state->remote_addrlen);
>     /* Check all sbytes were sent */
>     if(sbytes<0) {
739,743c766,772
<       /* Re-send the data packet and check all sbytes were sent */
<       if(sendto(state->sockfd, (void *)state->spacket.data,
<                 4+state->sbytes, SEND_4TH_ARG,
<                 (struct sockaddr *)&state->remote_addr,
<                 state->remote_addrlen) < 0) {
---
>       /* Re-send the data packet */
>       sbytes = sendto(state->sockfd, (void *)state->spacket.data,
>                       4+state->sbytes, SEND_4TH_ARG,
>                       (struct sockaddr *)&state->remote_addr,
>                       state->remote_addrlen);
>       /* Check all sbytes were sent */
>       if(sbytes<0) {
753a783,791
>     setpacketevent(&state->spacket, TFTP_EVENT_ERROR);
>     setpacketblock(&state->spacket, state->block);
>     sbytes = sendto(state->sockfd, (void *)state->spacket.data,
>                     4, SEND_4TH_ARG,
>                     (struct sockaddr *)&state->remote_addr,
>                     state->remote_addrlen);
>     /* don't bother with the return code, but if the socket is still up we
>      * should be a good TFTP client and let the server know we're done */
>     state->state = TFTP_STATE_FIN;
765a804,856
>  * tftp_translate_code
>  *
>  * Translate internal error codes to CURL error codes 
>  *
>  **********************************************************/
> CURLcode tftp_translate_code(tftp_error_t error)
> {
>   CURLcode code = CURLE_OK;
> 
>   if(error != TFTP_ERR_NONE) {
>     switch(error) {
>     case TFTP_ERR_NOTFOUND:
>       code = CURLE_TFTP_NOTFOUND;
>       break;
>     case TFTP_ERR_PERM:
>       code = CURLE_TFTP_PERM;
>       break;
>     case TFTP_ERR_DISKFULL:
>       code = CURLE_REMOTE_DISK_FULL;
>       break;
>     case TFTP_ERR_UNDEF:
>     case TFTP_ERR_ILLEGAL:
>       code = CURLE_TFTP_ILLEGAL;
>       break;
>     case TFTP_ERR_UNKNOWNID:
>       code = CURLE_TFTP_UNKNOWNID;
>       break;
>     case TFTP_ERR_EXISTS:
>       code = CURLE_REMOTE_FILE_EXISTS;
>       break;
>     case TFTP_ERR_NOSUCHUSER:
>       code = CURLE_TFTP_NOSUCHUSER;
>       break;
>     case TFTP_ERR_TIMEOUT:
>       code = CURLE_OPERATION_TIMEDOUT;
>       break;
>     case TFTP_ERR_NORESPONSE:
>       code = CURLE_COULDNT_CONNECT;
>       break;
>     default:
>       code= CURLE_ABORTED_BY_CALLBACK;
>       break;
>     }
>   }
>   else {
>     code = CURLE_OK;
>   }
> 
>   return(code);
> }
> 
> /**********************************************************
>  *
866,868c957
<   conn->bits.close = TRUE; /* we don't keep TFTP connections up bascially
<                               because there's none or very little gain for UDP
<                            */
---
>   conn->bits.close = TRUE; /* always close */
922a1012,1014
>   CURLcode code = CURLE_OK;
>   tftp_state_data_t *state = (tftp_state_data_t *)conn->proto.tftpc;
> 
928,929c1020,1021
<   return CURLE_OK;
< }
---
>   /* If we have encountered an error */
>   code = tftp_translate_code(state->error);
930a1023,1024
>   return code;
> }
934,936c1028
<  * tftp
<  *
<  * The do callback
---
>  * tftp_getsock
938c1030
<  * This callback handles the entire TFTP transfer
---
>  * The getsock callback
940a1033,1037
> static int tftp_getsock(struct connectdata *conn, curl_socket_t *socks,
>                        int numsocks)
> {
>   if(!numsocks)
>     return GETSOCK_BLANK;
942c1039,1051
< static CURLcode tftp_do(struct connectdata *conn, bool *done)
---
>   socks[0] = conn->sock[FIRSTSOCKET];
> 
>   return GETSOCK_READSOCK(0);
> }
> 
> /**********************************************************
>  *
>  * tftp_receive_packet
>  *
>  * Called once select fires and data is ready on the socket 
>  *
>  **********************************************************/
> static CURLcode tftp_receive_packet(struct connectdata *conn) 
944,948d1052
<   struct SessionHandle  *data = conn->data;
<   tftp_state_data_t     *state;
<   tftp_event_t          event;
<   CURLcode              code;
<   int                   rc;
950,952c1054,1058
<   curl_socklen_t        fromlen;
<   int                   check_time = 0;
<   struct SingleRequest *k = &data->req;
---
>   socklen_t             fromlen;
>   CURLcode 		result = CURLE_OK;
>   struct SessionHandle  *data = conn->data;
>   tftp_state_data_t	*state = (tftp_state_data_t *)conn->proto.tftpc;
>   struct SingleRequest	*k = &data->req;
954c1060,1071
<   *done = TRUE;
---
>   /* Receive the packet */
>   fromlen = sizeof(fromaddr);
>   state->rbytes = (int)recvfrom(state->sockfd,
>                                    (void *)state->rpacket.data,
>                                    state->blksize+4,
>                                    0,
>                                    (struct sockaddr *)&fromaddr,
>                                    &fromlen);
>   if(state->remote_addrlen==0) {
>     memcpy(&state->remote_addr, &fromaddr, fromlen);
>     state->remote_addrlen = fromlen;
>   }
956,962c1073,1081
<   /*
<     Since connections can be re-used between SessionHandles, this might be a
<     connection already existing but on a fresh SessionHandle struct so we must
<     make sure we have a good 'struct TFTP' to play with. For new connections,
<     the struct TFTP is allocated and setup in the tftp_connect() function.
<   */
<   Curl_reset_reqproto(conn);
---
>   /* Sanity check packet length */
>   if(state->rbytes < 4) {
>     failf(data, "Received too short packet");
>     /* Not a timeout, but how best to handle it? */
>     state->event = TFTP_EVENT_TIMEOUT;
>   }
>   else {
>     /* The event is given by the TFTP packet time */
>     state->event = (tftp_event_t)getrpacketevent(&state->rpacket);
964,967c1083,1123
<   if(!conn->proto.tftpc) {
<     code = tftp_connect(conn, done);
<     if(code)
<       return code;
---
>     switch(state->event) {
>     case TFTP_EVENT_DATA:
>       /* Don't pass to the client empty or retransmitted packets */
>       if(state->rbytes > 4 &&
>           ((state->block+1) == getrpacketblock(&state->rpacket))) {
>         result = Curl_client_write(conn, CLIENTWRITE_BODY,
>                                  (char *)state->rpacket.data+4,
>                                  state->rbytes-4);
>         if(result) {
>           tftp_state_machine(state, TFTP_EVENT_ERROR);
>           return result;
> 	}
>         k->bytecount += state->rbytes-4;
>         Curl_pgrsSetDownloadCounter(data, (curl_off_t) k->bytecount);
>       }
>       break;
>     case TFTP_EVENT_ERROR:
>       state->error = (tftp_error_t)getrpacketblock(&state->rpacket);
>       infof(data, "%s\n", (const char *)state->rpacket.data+4);
>       break;
>     case TFTP_EVENT_ACK:
>       break;
>     case TFTP_EVENT_OACK:
>       result = tftp_parse_option_ack(state,
>                                    (const char *)state->rpacket.data+2,
>                                    state->rbytes-2);
>       if(result)
>         return result;
>       break;
>     case TFTP_EVENT_RRQ:
>     case TFTP_EVENT_WRQ:
>     default:
>       failf(data, "%s", "Internal error: Unexpected packet");
>       break;
>     }
> 
>     /* Update the progress meter */
>     if(Curl_pgrsUpdate(conn)) {
>       tftp_state_machine(state, TFTP_EVENT_ERROR);
>       return CURLE_ABORTED_BY_CALLBACK;
>     }
969c1125,1176
<   state = (tftp_state_data_t *)conn->proto.tftpc;
---
>   return result;
> }
> 
> /**********************************************************
>  *
>  * tftp_state_timeout 
>  *
>  * Check if timeouts have been reached 
>  *
>  **********************************************************/
> static long tftp_state_timeout(struct connectdata *conn, tftp_event_t *event)
> {
>   time_t 		current;
>   struct SessionHandle  *data = conn->data;
>   tftp_state_data_t	*state = (tftp_state_data_t *)conn->proto.tftpc;
> 
>   if (event)
>     *event = TFTP_EVENT_NONE;
> 
>   time(&current);
>   if(current > state->max_time) {
>     DEBUGF(infof(data, "timeout: %d > %d\n",
>                  current, state->max_time));
>     state->error = TFTP_ERR_TIMEOUT;
>     state->state = TFTP_STATE_FIN;
>     return(0);
>   } 
>   else if (current > state->rx_time+state->retry_time) {
>     if (event)
>       *event = TFTP_EVENT_TIMEOUT;
>     time(&state->rx_time); /* update even though we received nothing */
>     return(state->max_time-current);
>   }
>   else {
>     return(state->max_time-current);
>   }
> }
> 
> /**********************************************************
>  *
>  * tftp_easy_statemach 
>  *
>  * Handle easy request until completion 
>  *
>  **********************************************************/
> static CURLcode tftp_easy_statemach(struct connectdata *conn)
> {
>   int			rc;
>   int			check_time = 0;
>   CURLcode		result = CURLE_OK;
>   struct SessionHandle  *data = conn->data;
>   tftp_state_data_t	*state = (tftp_state_data_t *)conn->proto.tftpc;
972,974c1179,1181
<   for(code=tftp_state_machine(state, TFTP_EVENT_INIT);
<       (state->state != TFTP_STATE_FIN) && (code == CURLE_OK);
<       code=tftp_state_machine(state, event) ) {
---
>   for(;
>       (state->state != TFTP_STATE_FIN) && (result == CURLE_OK);
>       result=tftp_state_machine(state, state->event) ) {
978c1185
<                          (int)(state->retry_time * 1000));
---
>                          state->retry_time * 1000);
984c1191
<       event = TFTP_EVENT_ERROR;
---
>       state->event = TFTP_EVENT_ERROR;
988c1195
<       event = TFTP_EVENT_TIMEOUT;
---
>       state->event = TFTP_EVENT_TIMEOUT;
995,1057c1202
< 
<       /* Receive the packet */
<       fromlen = sizeof(fromaddr);
<       state->rbytes = (ssize_t)recvfrom(state->sockfd,
<                                         (void *)state->rpacket.data,
<                                         state->blksize+4,
<                                         0,
<                                         (struct sockaddr *)&fromaddr,
<                                         &fromlen);
<       if(state->remote_addrlen==0) {
<         memcpy(&state->remote_addr, &fromaddr, fromlen);
<         state->remote_addrlen = fromlen;
<       }
< 
<       /* Sanity check packet length */
<       if(state->rbytes < 4) {
<         failf(data, "Received too short packet");
<         /* Not a timeout, but how best to handle it? */
<         event = TFTP_EVENT_TIMEOUT;
<       }
<       else {
< 
<         /* The event is given by the TFTP packet time */
<         event = (tftp_event_t)getrpacketevent(&state->rpacket);
< 
<         switch(event) {
<         case TFTP_EVENT_DATA:
<           /* Don't pass to the client empty or retransmitted packets */
<           if(state->rbytes > 4 &&
<               ((state->block+1) == getrpacketblock(&state->rpacket))) {
<             code = Curl_client_write(conn, CLIENTWRITE_BODY,
<                                      (char *)state->rpacket.data+4,
<                                      state->rbytes-4);
<             if(code)
<               return code;
<             k->bytecount += state->rbytes-4;
<             Curl_pgrsSetDownloadCounter(data, (curl_off_t) k->bytecount);
<           }
<           break;
<         case TFTP_EVENT_ERROR:
<           state->error = (tftp_error_t)getrpacketblock(&state->rpacket);
<           infof(data, "%s\n", (const char *)state->rpacket.data+4);
<           break;
<         case TFTP_EVENT_ACK:
<           break;
<         case TFTP_EVENT_OACK:
<           code = tftp_parse_option_ack(state,
<                                        (const char *)state->rpacket.data+2,
<                                        (int)state->rbytes-2);
<           if(code)
<             return code;
<           break;
<         case TFTP_EVENT_RRQ:
<         case TFTP_EVENT_WRQ:
<         default:
<           failf(data, "%s", "Internal error: Unexpected packet");
<           break;
<         }
< 
<         /* Update the progress meter */
<         if(Curl_pgrsUpdate(conn))
<           return CURLE_ABORTED_BY_CALLBACK;
<       }
---
>         result = tftp_receive_packet(conn);
1062,1069c1207,1209
<       time_t current;
<       time(&current);
<       if(current>state->max_time) {
<         DEBUGF(infof(data, "timeout: %d > %d\n",
<                      current, state->max_time));
<         state->error = TFTP_ERR_TIMEOUT;
<         state->state = TFTP_STATE_FIN;
<       }
---
>       /* ignore the event here as Curl_socket_ready() handles
>        * retransmission timeouts inside the easy state mach */
>       tftp_state_timeout(conn, NULL);
1071a1212,1213
>     if(result)
>       return(result);
1073,1074d1214
<   if(code)
<     return code;
1077,1079c1217
<   code = Curl_setup_transfer(conn, -1, -1, FALSE, NULL, -1, NULL);
<   if(code)
<     return code;
---
>   result = Curl_setup_transfer(conn, -1, -1, FALSE, NULL, -1, NULL);
1081,1082c1219,1220
<   /* If we have encountered an error */
<   if(state->error != TFTP_ERR_NONE) {
---
>   return(result);
> }
1084,1116c1222,1261
<     /* Translate internal error codes to curl error codes */
<     switch(state->error) {
<     case TFTP_ERR_NOTFOUND:
<       code = CURLE_TFTP_NOTFOUND;
<       break;
<     case TFTP_ERR_PERM:
<       code = CURLE_TFTP_PERM;
<       break;
<     case TFTP_ERR_DISKFULL:
<       code = CURLE_REMOTE_DISK_FULL;
<       break;
<     case TFTP_ERR_UNDEF:
<     case TFTP_ERR_ILLEGAL:
<       code = CURLE_TFTP_ILLEGAL;
<       break;
<     case TFTP_ERR_UNKNOWNID:
<       code = CURLE_TFTP_UNKNOWNID;
<       break;
<     case TFTP_ERR_EXISTS:
<       code = CURLE_REMOTE_FILE_EXISTS;
<       break;
<     case TFTP_ERR_NOSUCHUSER:
<       code = CURLE_TFTP_NOSUCHUSER;
<       break;
<     case TFTP_ERR_TIMEOUT:
<       code = CURLE_OPERATION_TIMEDOUT;
<       break;
<     case TFTP_ERR_NORESPONSE:
<       code = CURLE_COULDNT_CONNECT;
<       break;
<     default:
<       code= CURLE_ABORTED_BY_CALLBACK;
<       break;
---
> /**********************************************************
>  *
>  * tftp_multi_statemach 
>  *
>  * Handle single RX socket event and return 
>  *
>  **********************************************************/
> static CURLcode tftp_multi_statemach(struct connectdata *conn, bool *done)
> {
>   int			rc;
>   tftp_event_t		event;
>   CURLcode		result = CURLE_OK;
>   struct SessionHandle  *data = conn->data;
>   tftp_state_data_t	*state = (tftp_state_data_t *)conn->proto.tftpc;
>   long 			timeout_ms = tftp_state_timeout(conn, &event);
> 
>   *done = FALSE;
> 
>   if(timeout_ms <= 0) {
>     failf(data, "TFTP response timeout");
>     return CURLE_OPERATION_TIMEDOUT;
>   }
>   else if (event != TFTP_EVENT_NONE) {
>     result = tftp_state_machine(state, event);
>     if(result != CURLE_OK)
>       return(result);
>     *done = (bool)(state->state == TFTP_STATE_FIN);
>     if(*done)
>       /* Tell curl we're done */
>       result = Curl_setup_transfer(conn, -1, -1, FALSE, NULL, -1, NULL);
>   }
>   else {
>     /* no timeouts to handle, check our socket */	
>     rc = Curl_socket_ready(state->sockfd, CURL_SOCKET_BAD, 0);
> 
>     if(rc == -1) {
>       /* bail out */
>       int error = SOCKERRNO;
>       failf(data, "%s", Curl_strerror(conn, error));
>       state->event = TFTP_EVENT_ERROR;
1117a1263,1275
>     else if(rc != 0) {
>       result = tftp_receive_packet(conn); 
>       if(result != CURLE_OK)
>         return(result);
>       result = tftp_state_machine(state, state->event);
>       if(result != CURLE_OK)
>         return(result);
>       *done = (bool)(state->state == TFTP_STATE_FIN);
>       if(*done)
>         /* Tell curl we're done */
>         result = Curl_setup_transfer(conn, -1, -1, FALSE, NULL, -1, NULL);
>     }
>     /* if rc == 0, then select() timed out */
1119,1120c1277,1368
<   else
<     code = CURLE_OK;
---
> 
>   return result;
> }
> 
> /**********************************************************
>  *
>  * tftp_doing 
>  *
>  * Called from multi.c while DOing 
>  *
>  **********************************************************/
> static CURLcode tftp_doing(struct connectdata *conn, bool *dophase_done)
> {
>   CURLcode result;
>   result = tftp_multi_statemach(conn, dophase_done);
> 
>   if(*dophase_done) {
>     DEBUGF(infof(conn->data, "DO phase is complete\n"));
>   }
>   return result;
> }
> 
> /**********************************************************
>  *
>  * tftp_peform 
>  *
>  * Entry point for transfer from tftp_do, sarts state mach 
>  *
>  **********************************************************/
> static CURLcode tftp_perform(struct connectdata *conn, bool *dophase_done)
> {
>   CURLcode 		result = CURLE_OK;
>   tftp_state_data_t	*state = (tftp_state_data_t *)conn->proto.tftpc;
> 
>   *dophase_done = FALSE;
> 
>   result = tftp_state_machine(state, TFTP_EVENT_INIT);
> 
>   if(state->state == TFTP_STATE_FIN || result != CURLE_OK)
>     return(result);
> 
>   if(conn->data->state.used_interface == Curl_if_multi)
>     tftp_multi_statemach(conn, dophase_done);
>   else {
>     result = tftp_easy_statemach(conn);
>     *dophase_done = TRUE; /* with the easy interface we are done here */
>   }
> 
>   if(*dophase_done)
>     DEBUGF(infof(conn->data, "DO phase is complete\n"));
> 
>   return result;
> }
> 
> 
> /**********************************************************
>  *
>  * tftp_do
>  *
>  * The do callback
>  *
>  * This callback initiates the TFTP transfer 
>  *
>  **********************************************************/
> 
> static CURLcode tftp_do(struct connectdata *conn, bool *done)
> {
>   tftp_state_data_t     *state;
>   CURLcode              code;
> 
>   *done = FALSE;
> 
>   /*
>     Since connections can be re-used between SessionHandles, this might be a
>     connection already existing but on a fresh SessionHandle struct so we must
>     make sure we have a good 'struct TFTP' to play with. For new connections,
>     the struct TFTP is allocated and setup in the tftp_connect() function.
>   */
>   Curl_reset_reqproto(conn);
> 
>   if(!conn->proto.tftpc) {
>     code = tftp_connect(conn, done);
>     if(code)
>       return code;
>   }
>   state = (tftp_state_data_t *)conn->proto.tftpc;
> 
>   code = tftp_perform(conn, done);
> 
>   /* If we have encountered an error */
>   code = tftp_translate_code(state->error);
> 
1141c1389,1390
<     command = Curl_raw_toupper(type[6]);
---
>     command = (char) toupper((int) type[6]);
>     /* command = Curl_raw_toupper(type[6]); */
Index: lib/urldata.h
===================================================================
RCS file: /cvsroot/curl/curl/lib/urldata.h,v
retrieving revision 1.422
diff -r1.422 urldata.h
935,936c935,936
< #define PROT_CLOSEACTION PROT_FTP /* these ones need action before socket
<                                      close */
---
> /* these ones need action before socket close */
> #define PROT_CLOSEACTION (PROT_FTP | PROT_TFTP) 
Index: src/main.c
===================================================================
RCS file: /cvsroot/curl/curl/src/main.c,v
retrieving revision 1.542
diff -r1.542 main.c
605c605
< 
---
>   long tftp_blksize; /* TFTP BLKSIZE option */
879a880
>     "    --tftp-blksize <value> Set TFTP BLKSIZE option (must be >512)",
1734a1736
> 
1740c1742
< 
---
>     {"$9", "tftp-blksize", TRUE},
2266a2269,2271
>       case '9': /* --tftp-blksize */
>         str2num(&config->tftp_blksize, nextarg);
>         break;
5002a5008,5011
>         if(config->tftp_blksize != 0) {
>           my_setopt(curl, CURLOPT_TFTP_BLKSIZE, config->tftp_blksize);
>         }
> 

