3.4.2 具体实现(7)
⑪定义函数RespondToOptions(),用于设置选项协议状态,具体代码如下:
- void CTelnetView::RespondToOptions()
- {
- CString strOption;
- while(!m_ListOptions.IsEmpty())
- {
- strOption = m_ListOptions.RemoveHead();
- ArrangeReply(strOption);
- }
- DispatchMessage(m_strResp);
- m_strResp.Empty();
- }
⑫定义函数ArrangeReply(),用于设置回应选项状态,具体代码如下:- void CTelnetView::ArrangeReply(CString strOption)
- {
- unsigned char Verb;
- unsigned char Option;
- unsigned char Modifier;
- unsigned char ch;
- BOOL bDefined = FALSE;
-
- if(strOption.GetLength() < 3) return;
-
- Verb = strOption.GetAt(1);
- Option = strOption.GetAt(2);
-
- switch(Option)
- {
- case 1: //回显
- case 3: // Suppress Go-Ahead
- bDefined = TRUE;
- break;
- }
-
- m_strResp += IAC;
-
- if(bDefined == TRUE)
- {
- switch(Verb)
- {
- case DO:
- ch = WILL;
- m_strResp += ch;
- m_strResp += Option;
- break;
- case DONT:
- ch = WONT;
- m_strResp += ch;
- m_strResp += Option;
- break;
- case WILL:
- ch = DO;
- m_strResp += ch;
- m_strResp += Option;
- break;
- case WONT:
- ch = DONT;
- m_strResp += ch;
- m_strResp += Option;
- break;
- case SB:
- Modifier = strOption.GetAt(3);
- if(Modifier == SEND)
- {
- ch = SB;
- m_strResp += ch;
- m_strResp += Option;
- m_strResp += IS;
- m_strResp += IAC;
- m_strResp += SE;
- }
- break;
- }
- }
- else
- {
- switch(Verb)
- {
- case DO:
- ch = WONT;
- m_strResp += ch;
- m_strResp += Option;
- break;
- case DONT:
- ch = WONT;
- m_strResp += ch;
- m_strResp += Option;
- break;
- case WILL:
- ch = DONT;
- m_strResp += ch;
- m_strResp += Option;
- break;
- case WONT:
- ch = DONT;
- m_strResp += ch;
- m_strResp += Option;
- break;
- }
- }
- }