| 122 | } |
| 123 | |
| 124 | ServerProxy::ConnectionResult ServerProxy::parseHandshakeMessage(const uint8_t *code) |
| 125 | { |
| 126 | using enum ConnectionResult; |
| 127 | |
| 128 | if (memcmp(code, kMsgQInfo, 4) == 0) { |
| 129 | queryInfo(); |
| 130 | } |
| 131 | |
| 132 | else if (memcmp(code, kMsgCInfoAck, 4) == 0) { |
| 133 | infoAcknowledgment(); |
| 134 | } |
| 135 | |
| 136 | else if (memcmp(code, kMsgDSetOptions, 4) == 0) { |
| 137 | setOptions(); |
| 138 | |
| 139 | // handshake is complete |
| 140 | m_parser = &ServerProxy::parseMessage; |
| 141 | checkMissedLanguages(); |
| 142 | m_client->handshakeComplete(); |
| 143 | } |
| 144 | |
| 145 | else if (memcmp(code, kMsgCResetOptions, 4) == 0) { |
| 146 | resetOptions(); |
| 147 | } |
| 148 | |
| 149 | else if (memcmp(code, kMsgCKeepAlive, 4) == 0) { |
| 150 | // echo keep alives and reset alarm |
| 151 | ProtocolUtil::writef(m_stream, kMsgCKeepAlive); |
| 152 | resetKeepAliveAlarm(); |
| 153 | } |
| 154 | |
| 155 | else if (memcmp(code, kMsgCNoop, 4) == 0) { |
| 156 | // accept and discard no-op |
| 157 | } |
| 158 | |
| 159 | else if (memcmp(code, kMsgCClose, 4) == 0) { |
| 160 | // server wants us to hangup |
| 161 | LOG_DEBUG1("recv close"); |
| 162 | m_client->disconnect(nullptr); |
| 163 | return Disconnect; |
| 164 | } |
| 165 | |
| 166 | else if (memcmp(code, kMsgEIncompatible, 4) == 0) { |
| 167 | int32_t major; |
| 168 | int32_t minor; |
| 169 | ProtocolUtil::readf(m_stream, kMsgEIncompatible + 4, &major, &minor); |
| 170 | LOG_ERR("server has incompatible version %d.%d", major, minor); |
| 171 | m_client->refuseConnection("server has incompatible version"); |
| 172 | return Disconnect; |
| 173 | } |
| 174 | |
| 175 | else if (memcmp(code, kMsgEBusy, 4) == 0) { |
| 176 | LOG_ERR("server already has a connected client with name \"%s\"", m_client->getName().c_str()); |
| 177 | m_client->refuseConnection("server already has a connected client with our name"); |
| 178 | return Disconnect; |
| 179 | } |
| 180 | |
| 181 | else if (memcmp(code, kMsgEUnknown, 4) == 0) { |
nothing calls this directly
no test coverage detected