📄 telnet.c
字号:
switch(tn->him[option]) { case CURL_NO: /* Already disabled */ break; case CURL_YES: tn->him[option] = CURL_NO; send_negotiation(conn, CURL_DONT, option); break; case CURL_WANTNO: switch(tn->himq[option]) { case CURL_EMPTY: tn->him[option] = CURL_NO; break; case CURL_OPPOSITE: tn->him[option] = CURL_WANTYES; tn->himq[option] = CURL_EMPTY; send_negotiation(conn, CURL_DO, option); break; } break; case CURL_WANTYES: switch(tn->himq[option]) { case CURL_EMPTY: tn->him[option] = CURL_NO; break; case CURL_OPPOSITE: tn->him[option] = CURL_NO; tn->himq[option] = CURL_EMPTY; break; } break; }} static voidset_local_option(struct connectdata *conn, int option, int newstate){ struct TELNET *tn = (struct TELNET *)conn->proto.telnet; if(newstate == CURL_YES) { switch(tn->us[option]) { case CURL_NO: tn->us[option] = CURL_WANTYES; send_negotiation(conn, CURL_WILL, option); break; case CURL_YES: /* Already enabled */ break; case CURL_WANTNO: switch(tn->usq[option]) { case CURL_EMPTY: /* Already negotiating for CURL_YES, queue the request */ tn->usq[option] = CURL_OPPOSITE; break; case CURL_OPPOSITE: /* Error: already queued an enable request */ break; } break; case CURL_WANTYES: switch(tn->usq[option]) { case CURL_EMPTY: /* Error: already negotiating for enable */ break; case CURL_OPPOSITE: tn->usq[option] = CURL_EMPTY; break; } break; } } else /* NO */ { switch(tn->us[option]) { case CURL_NO: /* Already disabled */ break; case CURL_YES: tn->us[option] = CURL_WANTNO; send_negotiation(conn, CURL_WONT, option); break; case CURL_WANTNO: switch(tn->usq[option]) { case CURL_EMPTY: /* Already negotiating for NO */ break; case CURL_OPPOSITE: tn->usq[option] = CURL_EMPTY; break; } break; case CURL_WANTYES: switch(tn->usq[option]) { case CURL_EMPTY: tn->usq[option] = CURL_OPPOSITE; break; case CURL_OPPOSITE: break; } break; } }}staticvoid rec_do(struct connectdata *conn, int option){ struct TELNET *tn = (struct TELNET *)conn->proto.telnet; switch(tn->us[option]) { case CURL_NO: if(tn->us_preferred[option] == CURL_YES) { tn->us[option] = CURL_YES; send_negotiation(conn, CURL_WILL, option); } else { send_negotiation(conn, CURL_WONT, option); } break; case CURL_YES: /* Already enabled */ break; case CURL_WANTNO: switch(tn->usq[option]) { case CURL_EMPTY: /* Error: DONT answered by WILL */ tn->us[option] = CURL_NO; break; case CURL_OPPOSITE: /* Error: DONT answered by WILL */ tn->us[option] = CURL_YES; tn->usq[option] = CURL_EMPTY; break; } break; case CURL_WANTYES: switch(tn->usq[option]) { case CURL_EMPTY: tn->us[option] = CURL_YES; break; case CURL_OPPOSITE: tn->us[option] = CURL_WANTNO; tn->himq[option] = CURL_EMPTY; send_negotiation(conn, CURL_WONT, option); break; } break; }}static void rec_dont(struct connectdata *conn, int option){ struct TELNET *tn = (struct TELNET *)conn->proto.telnet; switch(tn->us[option]) { case CURL_NO: /* Already disabled */ break; case CURL_YES: tn->us[option] = CURL_NO; send_negotiation(conn, CURL_WONT, option); break; case CURL_WANTNO: switch(tn->usq[option]) { case CURL_EMPTY: tn->us[option] = CURL_NO; break; case CURL_OPPOSITE: tn->us[option] = CURL_WANTYES; tn->usq[option] = CURL_EMPTY; send_negotiation(conn, CURL_WILL, option); break; } break; case CURL_WANTYES: switch(tn->usq[option]) { case CURL_EMPTY: tn->us[option] = CURL_NO; break; case CURL_OPPOSITE: tn->us[option] = CURL_NO; tn->usq[option] = CURL_EMPTY; break; } break; }}static void printsub(struct SessionHandle *data, int direction, /* '<' or '>' */ unsigned char *pointer, /* where suboption data is */ int length) /* length of suboption data */{ int i = 0; if (data->set.verbose) { if (direction) { Curl_infof(data, "%s IAC SB ", (direction == '<')? "RCVD":"SENT"); if (length >= 3) { int j; i = pointer[length-2]; j = pointer[length-1]; if (i != CURL_IAC || j != CURL_SE) { Curl_infof(data, "(terminated by "); if (CURL_TELOPT_OK(i)) Curl_infof(data, "%s ", CURL_TELOPT(i)); else if (CURL_TELCMD_OK(i)) Curl_infof(data, "%s ", CURL_TELCMD(i)); else Curl_infof(data, "%d ", i); if (CURL_TELOPT_OK(j)) Curl_infof(data, "%s", CURL_TELOPT(j)); else if (CURL_TELCMD_OK(j)) Curl_infof(data, "%s", CURL_TELCMD(j)); else Curl_infof(data, "%d", j); Curl_infof(data, ", not IAC SE!) "); } } length -= 2; } if (length < 1) { Curl_infof(data, "(Empty suboption?)"); return; } if (CURL_TELOPT_OK(pointer[0])) { switch(pointer[0]) { case CURL_TELOPT_TTYPE: case CURL_TELOPT_XDISPLOC: case CURL_TELOPT_NEW_ENVIRON: Curl_infof(data, "%s", CURL_TELOPT(pointer[0])); break; default: Curl_infof(data, "%s (unsupported)", CURL_TELOPT(pointer[0])); break; } } else Curl_infof(data, "%d (unknown)", pointer[i]); switch(pointer[1]) { case CURL_TELQUAL_IS: Curl_infof(data, " IS"); break; case CURL_TELQUAL_SEND: Curl_infof(data, " SEND"); break; case CURL_TELQUAL_INFO: Curl_infof(data, " INFO/REPLY"); break; case CURL_TELQUAL_NAME: Curl_infof(data, " NAME"); break; } switch(pointer[0]) { case CURL_TELOPT_TTYPE: case CURL_TELOPT_XDISPLOC: pointer[length] = 0; Curl_infof(data, " \"%s\"", &pointer[2]); break; case CURL_TELOPT_NEW_ENVIRON: if(pointer[1] == CURL_TELQUAL_IS) { Curl_infof(data, " "); for(i = 3;i < length;i++) { switch(pointer[i]) { case CURL_NEW_ENV_VAR: Curl_infof(data, ", "); break; case CURL_NEW_ENV_VALUE: Curl_infof(data, " = "); break; default: Curl_infof(data, "%c", pointer[i]); break; } } } break; default: for (i = 2; i < length; i++) Curl_infof(data, " %.2x", pointer[i]); break; } if (direction) { Curl_infof(data, "\n"); } }}static int check_telnet_options(struct connectdata *conn){ struct curl_slist *head; char option_keyword[128]; char option_arg[256]; char *buf; struct SessionHandle *data = conn->data; struct TELNET *tn = (struct TELNET *)conn->proto.telnet; /* Add the user name as an environment variable if it was given on the command line */ if(conn->bits.user_passwd) { snprintf(option_arg, sizeof(option_arg), "USER,%s", conn->user); tn->telnet_vars = curl_slist_append(tn->telnet_vars, option_arg); tn->us_preferred[CURL_TELOPT_NEW_ENVIRON] = CURL_YES; } for(head = data->set.telnet_options; head; head=head->next) { if(sscanf(head->data, "%127[^= ]%*[ =]%255s", option_keyword, option_arg) == 2) { /* Terminal type */ if(curl_strequal(option_keyword, "TTYPE")) { strncpy(tn->subopt_ttype, option_arg, 31); tn->subopt_ttype[31] = 0; /* String termination */ tn->us_preferred[CURL_TELOPT_TTYPE] = CURL_YES; continue; } /* Display variable */ if(curl_strequal(option_keyword, "XDISPLOC")) { strncpy(tn->subopt_xdisploc, option_arg, 127); tn->subopt_xdisploc[127] = 0; /* String termination */ tn->us_preferred[CURL_TELOPT_XDISPLOC] = CURL_YES; continue; } /* Environment variable */ if(curl_strequal(option_keyword, "NEW_ENV")) { buf = strdup(option_arg); if(!buf) return CURLE_OUT_OF_MEMORY; tn->telnet_vars = curl_slist_append(tn->telnet_vars, buf); tn->us_preferred[CURL_TELOPT_NEW_ENVIRON] = CURL_YES; continue; } failf(data, "Unknown telnet option %s", head->data); return CURLE_UNKNOWN_TELNET_OPTION; } else { failf(data, "Syntax error in telnet option: %s", head->data); return CURLE_TELNET_OPTION_SYNTAX; } } return CURLE_OK;}/* * suboption() * * Look at the sub-option buffer, and try to be helpful to the other * side. */static void suboption(struct connectdata *conn){ struct curl_slist *v; unsigned char subchar; unsigned char temp[2048]; int len; int tmplen;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -