* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
#include "url.h"
#include "rawstr.h"
#include "speedcheck.h"
-#include "curl_printf.h"
#include "select.h"
-/* The last #include files should be: */
+/* The last 3 #include files should be in this order */
+#include "curl_printf.h"
#include "curl_memory.h"
#include "memdebug.h"
{
size_t loc;
- loc = Curl_strnlen( buf, len );
+ loc = Curl_strnlen(buf, len);
loc++; /* NULL term */
if(loc >= len)
return NULL;
*option = buf;
- loc += Curl_strnlen( buf+loc, len-loc );
+ loc += Curl_strnlen(buf+loc, len-loc);
loc++; /* NULL term */
if(loc > len)
const char *ptr, int len)
{
const char *tmp = ptr;
- struct SessionHandle *data = state->conn->data;
+ struct Curl_easy *data = state->conn->data;
/* if OACK doesn't contain blksize option, the default (512) must be used */
state->blksize = TFTP_BLKSIZE_DEFAULT;
if(checkprefix(option, TFTP_OPTION_BLKSIZE)) {
long blksize;
- blksize = strtol( value, NULL, 10 );
+ blksize = strtol(value, NULL, 10);
if(!blksize) {
failf(data, "invalid blocksize value in OACK packet");
else if(checkprefix(option, TFTP_OPTION_TSIZE)) {
long tsize = 0;
- tsize = strtol( value, NULL, 10 );
+ tsize = strtol(value, NULL, 10);
infof(data, "%s (%ld)\n", "tsize parsed from OACK", tsize);
/* tsize should be ignored on upload: Who cares about the size of the
static size_t tftp_option_add(tftp_state_data_t *state, size_t csize,
char *buf, const char *option)
{
- if(( strlen(option) + csize + 1 ) > (size_t)state->blksize)
+ if(( strlen(option) + csize + 1) > (size_t)state->blksize)
return 0;
strcpy(buf, option);
return strlen(option) + 1;
{
CURLcode result;
#ifndef CURL_DISABLE_VERBOSE_STRINGS
- struct SessionHandle *data = state->conn->data;
+ struct Curl_easy *data = state->conn->data;
infof(data, "%s\n", "Connected for transmit");
#endif
{
CURLcode result;
#ifndef CURL_DISABLE_VERBOSE_STRINGS
- struct SessionHandle *data = state->conn->data;
+ struct Curl_easy *data = state->conn->data;
infof(data, "%s\n", "Connected for receive");
#endif
const char *mode = "octet";
char *filename;
char buf[64];
- struct SessionHandle *data = state->conn->data;
+ struct Curl_easy *data = state->conn->data;
CURLcode result = CURLE_OK;
/* Set ascii mode if -B flag was used */
(char *)state->spacket.data+sbytes,
TFTP_OPTION_BLKSIZE);
sbytes += tftp_option_add(state, sbytes,
- (char *)state->spacket.data+sbytes, buf );
+ (char *)state->spacket.data+sbytes, buf);
/* add timeout option */
snprintf(buf, sizeof(buf), "%d", state->retry_time);
(char *)state->spacket.data+sbytes,
TFTP_OPTION_INTERVAL);
sbytes += tftp_option_add(state, sbytes,
- (char *)state->spacket.data+sbytes, buf );
+ (char *)state->spacket.data+sbytes, buf);
}
/* the typecase for the 3rd argument is mostly for systems that do
{
ssize_t sbytes;
int rblock;
- struct SessionHandle *data = state->conn->data;
+ struct Curl_easy *data = state->conn->data;
switch(event) {
**********************************************************/
static CURLcode tftp_tx(tftp_state_data_t *state, tftp_event_t event)
{
- struct SessionHandle *data = state->conn->data;
+ struct Curl_easy *data = state->conn->data;
ssize_t sbytes;
int rblock;
CURLcode result = CURLE_OK;
struct SingleRequest *k = &data->req;
+ int cb; /* Bytes currently read */
switch(event) {
return CURLE_OK;
}
- result = Curl_fillreadbuffer(state->conn, state->blksize, &state->sbytes);
- if(result)
- return result;
+ /* TFTP considers data block size < 512 bytes as an end of session. So
+ * in some cases we must wait for additional data to build full (512 bytes)
+ * data block.
+ * */
+ state->sbytes = 0;
+ state->conn->data->req.upload_fromhere = (char *)state->spacket.data+4;
+ do {
+ result = Curl_fillreadbuffer(state->conn, state->blksize - state->sbytes,
+ &cb);
+ if(result)
+ return result;
+ state->sbytes += cb;
+ state->conn->data->req.upload_fromhere += cb;
+ } while(state->sbytes < state->blksize && cb != 0);
sbytes = sendto(state->sockfd, (void *) state->spacket.data,
4 + state->sbytes, SEND_4TH_ARG,
tftp_event_t event)
{
CURLcode result = CURLE_OK;
- struct SessionHandle *data = state->conn->data;
+ struct Curl_easy *data = state->conn->data;
switch(state->state) {
case TFTP_STATE_START:
/* alloc pkt buffers based on specified blksize */
if(conn->data->set.tftp_blksize) {
blksize = (int)conn->data->set.tftp_blksize;
- if(blksize > TFTP_BLKSIZE_MAX || blksize < TFTP_BLKSIZE_MIN )
+ if(blksize > TFTP_BLKSIZE_MAX || blksize < TFTP_BLKSIZE_MIN)
return CURLE_TFTP_ILLEGAL;
}
struct Curl_sockaddr_storage fromaddr;
curl_socklen_t fromlen;
CURLcode result = CURLE_OK;
- struct SessionHandle *data = conn->data;
+ struct Curl_easy *data = conn->data;
tftp_state_data_t *state = (tftp_state_data_t *)conn->proto.tftpc;
struct SingleRequest *k = &data->req;
int rc;
tftp_event_t event;
CURLcode result = CURLE_OK;
- struct SessionHandle *data = conn->data;
+ struct Curl_easy *data = conn->data;
tftp_state_data_t *state = (tftp_state_data_t *)conn->proto.tftpc;
long timeout_ms = tftp_state_timeout(conn, &event);
static CURLcode tftp_setup_connection(struct connectdata * conn)
{
- struct SessionHandle *data = conn->data;
+ struct Curl_easy *data = conn->data;
char * type;
char command;