26 #ifndef CURL_DISABLE_TELNET
33 #include <sys/types.h>
42 #ifdef HAVE_SYS_SOCKET_H
43 #include <sys/socket.h>
45 #include <netinet/in.h>
51 #ifdef HAVE_ARPA_INET_H
52 #include <arpa/inet.h>
57 #include <sys/ioctl.h>
60 #ifdef HAVE_SYS_PARAM_H
61 #include <sys/param.h>
64 #ifdef HAVE_SYS_SELECT_H
65 #include <sys/select.h>
77 #define _MPRINTF_REPLACE
90 #define SUBBUFSIZE 512
92 #define CURL_SB_CLEAR(x) x->subpointer = x->subbuffer;
93 #define CURL_SB_TERM(x) { x->subend = x->subpointer; CURL_SB_CLEAR(x); }
94 #define CURL_SB_ACCUM(x,c) \
95 if (x->subpointer < (x->subbuffer+sizeof x->subbuffer)) { \
96 *x->subpointer++ = (c); \
99 #define CURL_SB_GET(x) ((*x->subpointer++)&0xff)
100 #define CURL_SB_PEEK(x) ((*x->subpointer)&0xff)
101 #define CURL_SB_EOF(x) (x->subpointer >= x->subend)
102 #define CURL_SB_LEN(x) (x->subend - x->subpointer)
105 typedef FARPROC WSOCK2_FUNC;
111 unsigned char *inbuf,
115 const char *direction,
116 int cmd,
int option);
119 static void send_negotiation(
struct connectdata *,
int cmd,
int option);
120 static void set_local_option(
struct connectdata *,
int cmd,
int option);
121 static void set_remote_option(
struct connectdata *,
int cmd,
int option);
130 #define CURL_WANTYES 2
131 #define CURL_WANTNO 3
134 #define CURL_OPPOSITE 1
177 WORD wVersionRequested;
183 wVersionRequested = MAKEWORD(2, 0);
185 err = WSAStartup(wVersionRequested, &wsaData);
190 failf(data,
"WSAStartup failed (%d)",err);
199 if (
LOBYTE(wsaData.wVersion) !=
LOBYTE(wVersionRequested) ||
200 HIBYTE(wsaData.wVersion) !=
HIBYTE(wVersionRequested)) {
202 failf(data,
"insufficient winsock version to support "
222 memset(tn, 0,
sizeof(
struct TELNET));
256 set_local_option(conn, i,
CURL_YES);
259 set_remote_option(conn, i,
CURL_YES);
264 const char *direction,
int cmd,
int option)
276 Curl_infof(data,
"%s IAC %d\n", direction, option);
292 Curl_infof(data,
"%s %s %s\n", direction, fmt, opt);
294 Curl_infof(data,
"%s %s %d\n", direction, fmt, option);
297 Curl_infof(data,
"%s %d %d\n", direction, cmd, option);
302 static void send_negotiation(
struct connectdata *conn,
int cmd,
int option)
304 unsigned char buf[3];
312 printoption(conn->
data,
"SENT", cmd, option);
316 void set_remote_option(
struct connectdata *conn,
int option,
int newstate)
321 switch(tn->
him[option])
325 send_negotiation(conn,
CURL_DO, option);
333 switch(tn->
himq[option])
346 switch(tn->
himq[option])
360 switch(tn->
him[option])
368 send_negotiation(conn,
CURL_DONT, option);
372 switch(tn->
himq[option])
384 switch(tn->
himq[option])
398 void rec_will(
struct connectdata *conn,
int option)
401 switch(tn->
him[option])
407 send_negotiation(conn,
CURL_DO, option);
411 send_negotiation(conn,
CURL_DONT, option);
420 switch(tn->
himq[option])
435 switch(tn->
himq[option])
443 send_negotiation(conn,
CURL_DONT, option);
451 void rec_wont(
struct connectdata *conn,
int option)
454 switch(tn->
him[option])
462 send_negotiation(conn,
CURL_DONT, option);
466 switch(tn->
himq[option])
475 send_negotiation(conn,
CURL_DO, option);
481 switch(tn->
himq[option])
496 set_local_option(
struct connectdata *conn,
int option,
int newstate)
501 switch(tn->
us[option])
505 send_negotiation(conn,
CURL_WILL, option);
513 switch(tn->
usq[option])
526 switch(tn->
usq[option])
540 switch(tn->
us[option])
548 send_negotiation(conn,
CURL_WONT, option);
552 switch(tn->
usq[option])
564 switch(tn->
usq[option])
581 switch(tn->
us[option])
587 send_negotiation(conn,
CURL_WILL, option);
591 send_negotiation(conn,
CURL_WONT, option);
600 switch(tn->
usq[option])
615 switch(tn->
usq[option])
623 send_negotiation(conn,
CURL_WONT, option);
631 void rec_dont(
struct connectdata *conn,
int option)
634 switch(tn->
us[option])
642 send_negotiation(conn,
CURL_WONT, option);
646 switch(tn->
usq[option])
655 send_negotiation(conn,
CURL_WILL, option);
661 switch(tn->
usq[option])
687 Curl_infof(data,
"%s IAC SB ", (direction ==
'<')?
"RCVD":
"SENT");
692 i = pointer[length-2];
693 j = pointer[length-1];
760 for(i = 3;i <
length;i++) {
776 for (i = 2; i <
length; i++)
791 char option_keyword[128];
792 char option_arg[256];
801 snprintf(option_arg,
sizeof(option_arg),
"USER,%s", conn->
user);
808 if(sscanf(head->
data,
"%127[^= ]%*[ =]%255s",
809 option_keyword, option_arg) == 2) {
837 failf(data,
"Unknown telnet option %s", head->
data);
840 failf(data,
"Syntax error in telnet option: %s", head->
data);
858 unsigned char temp[2048];
870 snprintf((
char *)temp,
sizeof(temp),
874 printsub(data,
'>', &temp[2], len-2);
878 snprintf((
char *)temp,
sizeof(temp),
882 printsub(data,
'>', &temp[2], len-2);
885 snprintf((
char *)temp,
sizeof(temp),
891 tmplen = (strlen(v->
data) + 1);
893 if(len + tmplen < (
int)
sizeof(temp)-6) {
894 sscanf(v->
data,
"%127[^,],%s", varname, varval);
895 snprintf((
char *)&temp[len],
sizeof(temp) - len,
901 snprintf((
char *)&temp[len],
sizeof(temp) - len,
905 printsub(data,
'>', &temp[2], len-2);
913 unsigned char *inbuf,
978 printoption(data,
"RCVD",
CURL_IAC, c);
999 printoption(data,
"RCVD",
CURL_DO, c);
1006 printoption(data,
"RCVD",
CURL_DONT, c);
1045 printoption(data,
"In SUBOPTION processing, RCVD",
CURL_IAC, c);
1085 WSOCK2_FUNC close_event_func;
1086 WSOCK2_FUNC create_event_func;
1087 WSOCK2_FUNC event_select_func;
1088 WSOCK2_FUNC enum_netevents_func;
1089 WSAEVENT event_handle;
1090 WSANETWORKEVENTS events;
1094 DWORD readfile_read;
1104 code = init_telnet(conn);
1110 code = check_telnet_options(conn);
1119 code = check_wsock2(data);
1125 wsock2 = LoadLibrary(
"WS2_32.DLL");
1126 if (wsock2 ==
NULL) {
1127 failf(data,
"failed to load WS2_32.DLL (%d)",GetLastError());
1132 create_event_func = GetProcAddress(wsock2,
"WSACreateEvent");
1133 if (create_event_func ==
NULL) {
1134 failf(data,
"failed to find WSACreateEvent function (%d)",
1136 FreeLibrary(wsock2);
1141 close_event_func = GetProcAddress(wsock2,
"WSACloseEvent");
1142 if (create_event_func ==
NULL) {
1143 failf(data,
"failed to find WSACloseEvent function (%d)",
1145 FreeLibrary(wsock2);
1150 event_select_func = GetProcAddress(wsock2,
"WSAEventSelect");
1151 if (event_select_func ==
NULL) {
1152 failf(data,
"failed to find WSAEventSelect function (%d)",
1154 FreeLibrary(wsock2);
1159 enum_netevents_func = GetProcAddress(wsock2,
"WSAEnumNetworkEvents");
1160 if (enum_netevents_func ==
NULL) {
1161 failf(data,
"failed to find WSAEnumNetworkEvents function (%d)",
1163 FreeLibrary(wsock2);
1173 event_handle = (WSAEVENT)create_event_func();
1174 if (event_handle == WSA_INVALID_EVENT) {
1175 failf(data,
"WSACreateEvent failed (%d)",WSAGetLastError());
1176 FreeLibrary(wsock2);
1181 stdin_handle = GetStdHandle(STD_INPUT_HANDLE);
1184 objs[0] = stdin_handle;
1185 objs[1] = event_handle;
1188 if(event_select_func(sockfd, event_handle, FD_READ|FD_CLOSE) == SOCKET_ERROR) {
1189 close_event_func(event_handle);
1190 FreeLibrary(wsock2);
1196 waitret = WaitForMultipleObjects(2, objs,
FALSE, INFINITE);
1197 switch(waitret - WAIT_OBJECT_0) {
1200 unsigned char outbuf[2];
1205 if(!ReadFile(stdin_handle, buf,
sizeof(data->
state.
buffer),
1206 &readfile_read,
NULL)) {
1210 nread = readfile_read;
1213 outbuf[0] = *buffer++;
1219 out_count, &bytes_written);
1225 if(enum_netevents_func(sockfd, event_handle, &events)
1227 if(events.lNetworkEvents & FD_READ) {
1231 telrcv(conn, (
unsigned char *)buf, nread);
1244 if(events.lNetworkEvents & FD_CLOSE) {
1253 if (close_event_func(event_handle) ==
FALSE) {
1254 infof(data,
"WSACloseEvent failed (%d)",WSAGetLastError());
1258 create_event_func =
NULL;
1259 close_event_func =
NULL;
1260 event_select_func =
NULL;
1261 enum_netevents_func =
NULL;
1264 if (!FreeLibrary(wsock2))
1265 infof(data,
"FreeLibrary(wsock2) failed (%d)",GetLastError());
1268 FD_SET (sockfd, &readfd);
1269 FD_SET (0, &readfd);
1287 if(FD_ISSET(0, &readfd)) {
1288 unsigned char outbuf[2];
1293 nread = read(0, buf, 255);
1296 outbuf[0] = *buffer++;
1302 out_count, &bytes_written);
1306 if(FD_ISSET(sockfd, &readfd)) {
1317 telrcv(conn, (
unsigned char *)buf, nread);
1332 failf(data,
"Time-out");
#define CURL_TELCMD_OK(x)
union connectdata::@11 proto
#define CURL_TELOPT_EXOPL
typedef HANDLE(WINAPI *PFNWGLCREATEBUFFERREGIONARBPROC)(HDC hDC
CURLcode Curl_client_write(struct SessionHandle *data, int type, char *ptr, size_t len)
CURLcode Curl_telnet(struct connectdata *conn)
#define CURL_TELOPT_BINARY
int Curl_read(struct connectdata *conn, curl_socket_t sockfd, char *buf, size_t buffersize, ssize_t *n)
char subopt_xdisploc[128]
CURLcode Curl_write(struct connectdata *conn, curl_socket_t sockfd, void *mem, size_t len, ssize_t *written)
GLsizei const GLvoid * pointer
GLuint GLuint GLsizei count
char subbuffer[SUBBUFSIZE]
GLsizei GLsizei GLenum GLenum const GLvoid * data
#define CURL_NEW_ENV_VALUE
CURLcode Curl_Transfer(struct connectdata *c_conn, int sockindex, curl_off_t size, bool getheader, curl_off_t *bytecountp, int writesockindex, curl_off_t *writecountp)
long Curl_tvdiff(struct timeval newer, struct timeval older)
struct SessionHandle * data
struct curl_slist * telnet_options
#define CURL_SB_ACCUM(x, c)
#define CURL_TELQUAL_INFO
#define CURL_TELOPT_OK(x)
static WindowRef ValidModeCallbackProc inCallback OSStatus err
void Curl_infof(struct SessionHandle *data, const char *fmt,...)
struct curl_slist * curl_slist_append(struct curl_slist *, const char *)
GLsizei const GLcharARB const GLint * length
typedef void(APIENTRYP PFNGLBLENDCOLORPROC)(GLclampf red
struct timeval Curl_tvnow(void)
CURLcode Curl_telnet_done(struct connectdata *conn)
void curl_slist_free_all(struct curl_slist *)
#define CURL_TELOPT_NEW_ENVIRON
#define CURL_TELQUAL_NAME
int() curl_strequal(const char *s1, const char *s2)
struct curl_slist * telnet_vars
#define CURL_TELOPT_TTYPE
#define CURL_TELQUAL_SEND
TelnetReceive telrcv_state
#define CURL_TELOPT_XDISPLOC