* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2014, 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 "telnet.h"
#include "connect.h"
#include "progress.h"
-#include "curl_printf.h"
+
+#define _MPRINTF_REPLACE /* use our functions only */
+#include <curl/mprintf.h>
#define TELOPTS
#define TELCMDS
#include "arpa_telnet.h"
+#include "curl_memory.h"
#include "select.h"
#include "strequal.h"
#include "rawstr.h"
#include "warnless.h"
-/* The last #include files should be: */
-#include "curl_memory.h"
+/* The last #include file should be: */
#include "memdebug.h"
#define SUBBUFSIZE 512
if(LOBYTE(wsaData.wVersion) != LOBYTE(wVersionRequested) ||
HIBYTE(wsaData.wVersion) != HIBYTE(wVersionRequested)) {
/* Our version isn't supported */
- failf(data, "insufficient winsock version to support "
- "telnet");
- return CURLE_FAILED_INIT;
+ failf(data,"insufficient winsock version to support "
+ "telnet");
+ return CURLE_FAILED_INIT;
}
/* Our version is supported */
if(c == CURL_IAC)
tn->telrcv_state = CURL_TS_SE;
else
- CURL_SB_ACCUM(tn, c);
+ CURL_SB_ACCUM(tn,c);
break;
case CURL_TS_SE:
tn->telrcv_state = CURL_TS_IAC;
goto process_iac;
}
- CURL_SB_ACCUM(tn, c);
+ CURL_SB_ACCUM(tn,c);
tn->telrcv_state = CURL_TS_SB;
}
else
static CURLcode telnet_do(struct connectdata *conn, bool *done)
{
- CURLcode result;
+ CURLcode code;
struct SessionHandle *data = conn->data;
curl_socket_t sockfd = conn->sock[FIRSTSOCKET];
#ifdef USE_WINSOCK
*done = TRUE; /* unconditionally */
- result = init_telnet(conn);
- if(result)
- return result;
+ code = init_telnet(conn);
+ if(code)
+ return code;
tn = (struct TELNET *)data->req.protop;
- result = check_telnet_options(conn);
- if(result)
- return result;
+ code = check_telnet_options(conn);
+ if(code)
+ return code;
#ifdef USE_WINSOCK
/*
** This functionality only works with WinSock >= 2.0. So,
** make sure have it.
*/
- result = check_wsock2(data);
- if(result)
- return result;
+ code = check_wsock2(data);
+ if(code)
+ return code;
/* OK, so we have WinSock 2.0. We need to dynamically */
/* load ws2_32.dll and get the function pointers we need. */
wsock2 = LoadLibrary(TEXT("WS2_32.DLL"));
if(wsock2 == NULL) {
- failf(data, "failed to load WS2_32.DLL (%d)", ERRNO);
+ failf(data,"failed to load WS2_32.DLL (%d)", ERRNO);
return CURLE_FAILED_INIT;
}
/* Grab a pointer to WSACreateEvent */
- create_event_func = GetProcAddress(wsock2, "WSACreateEvent");
+ create_event_func = GetProcAddress(wsock2,"WSACreateEvent");
if(create_event_func == NULL) {
- failf(data, "failed to find WSACreateEvent function (%d)", ERRNO);
+ failf(data,"failed to find WSACreateEvent function (%d)",
+ ERRNO);
FreeLibrary(wsock2);
return CURLE_FAILED_INIT;
}
/* And WSACloseEvent */
- close_event_func = GetProcAddress(wsock2, "WSACloseEvent");
+ close_event_func = GetProcAddress(wsock2,"WSACloseEvent");
if(close_event_func == NULL) {
- failf(data, "failed to find WSACloseEvent function (%d)", ERRNO);
+ failf(data,"failed to find WSACloseEvent function (%d)",
+ ERRNO);
FreeLibrary(wsock2);
return CURLE_FAILED_INIT;
}
/* And WSAEventSelect */
- event_select_func = GetProcAddress(wsock2, "WSAEventSelect");
+ event_select_func = GetProcAddress(wsock2,"WSAEventSelect");
if(event_select_func == NULL) {
- failf(data, "failed to find WSAEventSelect function (%d)", ERRNO);
+ failf(data,"failed to find WSAEventSelect function (%d)",
+ ERRNO);
FreeLibrary(wsock2);
return CURLE_FAILED_INIT;
}
/* And WSAEnumNetworkEvents */
- enum_netevents_func = GetProcAddress(wsock2, "WSAEnumNetworkEvents");
+ enum_netevents_func = GetProcAddress(wsock2,"WSAEnumNetworkEvents");
if(enum_netevents_func == NULL) {
- failf(data, "failed to find WSAEnumNetworkEvents function (%d)", ERRNO);
+ failf(data,"failed to find WSAEnumNetworkEvents function (%d)",
+ ERRNO);
FreeLibrary(wsock2);
return CURLE_FAILED_INIT;
}
/* First, create a sockets event object */
event_handle = (WSAEVENT)create_event_func();
if(event_handle == WSA_INVALID_EVENT) {
- failf(data, "WSACreateEvent failed (%d)", SOCKERRNO);
+ failf(data,"WSACreateEvent failed (%d)", SOCKERRNO);
FreeLibrary(wsock2);
return CURLE_FAILED_INIT;
}
case WAIT_TIMEOUT:
{
for(;;) {
- if(data->set.is_fread_set) {
+ if(obj_count == 1) {
/* read from user-supplied method */
- result = (int)data->set.fread_func(buf, 1, BUFSIZE - 1,
- data->set.in);
- if(result == CURL_READFUNC_ABORT) {
+ code = (int)conn->fread_func(buf, 1, BUFSIZE - 1, conn->fread_in);
+ if(code == CURL_READFUNC_ABORT) {
keepon = FALSE;
- result = CURLE_READ_ERROR;
+ code = CURLE_READ_ERROR;
break;
}
- if(result == CURL_READFUNC_PAUSE)
+ if(code == CURL_READFUNC_PAUSE)
break;
- if(result == 0) /* no bytes */
+ if(code == 0) /* no bytes */
break;
- readfile_read = result; /* fall thru with number of bytes read */
+ readfile_read = code; /* fall thru with number of bytes read */
}
else {
/* read from stdin */
if(!PeekNamedPipe(stdin_handle, NULL, 0, NULL,
&readfile_read, NULL)) {
keepon = FALSE;
- result = CURLE_READ_ERROR;
+ code = CURLE_READ_ERROR;
break;
}
if(!ReadFile(stdin_handle, buf, sizeof(data->state.buffer),
&readfile_read, NULL)) {
keepon = FALSE;
- result = CURLE_READ_ERROR;
+ code = CURLE_READ_ERROR;
break;
}
}
- result = send_telnet_data(conn, buf, readfile_read);
- if(result) {
+ code = send_telnet_data(conn, buf, readfile_read);
+ if(code) {
keepon = FALSE;
break;
}
if(!ReadFile(stdin_handle, buf, sizeof(data->state.buffer),
&readfile_read, NULL)) {
keepon = FALSE;
- result = CURLE_READ_ERROR;
+ code = CURLE_READ_ERROR;
break;
}
- result = send_telnet_data(conn, buf, readfile_read);
- if(result) {
+ code = send_telnet_data(conn, buf, readfile_read);
+ if(code) {
keepon = FALSE;
break;
}
events.lNetworkEvents = 0;
if(SOCKET_ERROR == enum_netevents_func(sockfd, event_handle, &events)) {
if((err = SOCKERRNO) != EINPROGRESS) {
- infof(data, "WSAEnumNetworkEvents failed (%d)", err);
+ infof(data,"WSAEnumNetworkEvents failed (%d)", err);
keepon = FALSE;
- result = CURLE_READ_ERROR;
+ code = CURLE_READ_ERROR;
}
break;
}
if(events.lNetworkEvents & FD_READ) {
/* read data from network */
- result = Curl_read(conn, sockfd, buf, BUFSIZE - 1, &nread);
+ code = Curl_read(conn, sockfd, buf, BUFSIZE - 1, &nread);
/* read would've blocked. Loop again */
- if(result == CURLE_AGAIN)
+ if(code == CURLE_AGAIN)
break;
/* returned not-zero, this an error */
- else if(result) {
+ else if(code) {
keepon = FALSE;
break;
}
break;
}
- result = telrcv(conn, (unsigned char *) buf, nread);
- if(result) {
+ code = telrcv(conn, (unsigned char *)buf, nread);
+ if(code) {
keepon = FALSE;
break;
}
now = Curl_tvnow();
if(Curl_tvdiff(now, conn->created) >= data->set.timeout) {
failf(data, "Time-out");
- result = CURLE_OPERATION_TIMEDOUT;
+ code = CURLE_OPERATION_TIMEDOUT;
keepon = FALSE;
}
}
/* We called WSACreateEvent, so call WSACloseEvent */
if(!close_event_func(event_handle)) {
- infof(data, "WSACloseEvent failed (%d)", SOCKERRNO);
+ infof(data,"WSACloseEvent failed (%d)", SOCKERRNO);
}
/* "Forget" pointers into the library we're about to free */
/* We called LoadLibrary, so call FreeLibrary */
if(!FreeLibrary(wsock2))
- infof(data, "FreeLibrary(wsock2) failed (%d)", ERRNO);
+ infof(data,"FreeLibrary(wsock2) failed (%d)", ERRNO);
#else
pfd[0].fd = sockfd;
pfd[0].events = POLLIN;
- if(data->set.fread_func != (curl_read_callback)fread) {
+ if(conn->fread_func != (curl_read_callback)fread) {
poll_cnt = 1;
interval_ms = 100; /* poll user-supplied read function */
}
else {
/* really using fread, so infile is a FILE* */
- pfd[1].fd = fileno((FILE *)data->set.in);
+ pfd[1].fd = fileno((FILE *)conn->fread_in);
pfd[1].events = POLLIN;
poll_cnt = 2;
interval_ms = 1 * 1000;
default: /* read! */
if(pfd[0].revents & POLLIN) {
/* read data from network */
- result = Curl_read(conn, sockfd, buf, BUFSIZE - 1, &nread);
+ code = Curl_read(conn, sockfd, buf, BUFSIZE - 1, &nread);
/* read would've blocked. Loop again */
- if(result == CURLE_AGAIN)
+ if(code == CURLE_AGAIN)
break;
/* returned not-zero, this an error */
- else if(result) {
+ else if(code) {
keepon = FALSE;
break;
}
total_dl += nread;
Curl_pgrsSetDownloadCounter(data, total_dl);
- result = telrcv(conn, (unsigned char *)buf, nread);
- if(result) {
+ code = telrcv(conn, (unsigned char *)buf, nread);
+ if(code) {
keepon = FALSE;
break;
}
}
else {
/* read from user-supplied method */
- nread = (int)data->set.fread_func(buf, 1, BUFSIZE - 1, data->set.in);
+ nread = (int)conn->fread_func(buf, 1, BUFSIZE - 1, conn->fread_in);
if(nread == CURL_READFUNC_ABORT) {
keepon = FALSE;
break;
}
if(nread > 0) {
- result = send_telnet_data(conn, buf, nread);
- if(result) {
+ code = send_telnet_data(conn, buf, nread);
+ if(code) {
keepon = FALSE;
break;
}
now = Curl_tvnow();
if(Curl_tvdiff(now, conn->created) >= data->set.timeout) {
failf(data, "Time-out");
- result = CURLE_OPERATION_TIMEDOUT;
+ code = CURLE_OPERATION_TIMEDOUT;
keepon = FALSE;
}
}
if(Curl_pgrsUpdate(conn)) {
- result = CURLE_ABORTED_BY_CALLBACK;
+ code = CURLE_ABORTED_BY_CALLBACK;
break;
}
}
/* mark this as "no further transfer wanted" */
Curl_setup_transfer(conn, -1, -1, FALSE, NULL, -1, NULL);
- return result;
+ return code;
}
#endif