void validate(connection_ptr con) { // The key validation step we need to do is on the subprotocols the // client requested. This should include "sip", in which case we'll // select "sip" too. If "sip" was not offered, we offer nothing and the // connection will probably fail. LOG_DEBUG("Validating incoming web socket connection"); const std::vector<std::string>& subprotocols = con->get_subprotocols(); if (std::find(subprotocols.begin(), subprotocols.end(), SUBPROTOCOL) != subprotocols.end()) { LOG_DEBUG("Client requested subprotocol sip - agreeing"); con->select_subprotocol("sip"); } else { // Build a comma-separated list of subprotocols ready to log. std::stringstream ss; std::copy(subprotocols.begin(), subprotocols.end(), std::ostream_iterator<std::string>(ss, ",")); std::string str = ss.str(); if (!str.empty()) { // The above added a trailing comma. Strip it. str = str.substr(0, str.length() - 1); } LOG_INFO("Client requested subprotocols %s - connection will probably fail", str.c_str()); } }