| 871 | } |
| 872 | |
| 873 | void SAMSocket::ProcessSessionAdd (std::string_view buf) |
| 874 | { |
| 875 | if (m_Version < SAM_VERSION_33) // < SAM 3.3 |
| 876 | { |
| 877 | SendSessionI2PError("SESSION ADD is not supported"); |
| 878 | return; |
| 879 | } |
| 880 | auto session = m_Owner.FindSession(m_ID); |
| 881 | if (session && session->Type == SAMSessionType::eSAMSessionTypeMaster) |
| 882 | { |
| 883 | LogPrint (eLogDebug, "SAM: Subsession add: ", buf); |
| 884 | auto masterSession = std::static_pointer_cast<SAMMasterSession>(session); |
| 885 | auto params = ExtractParams (buf); |
| 886 | std::string_view id = params[SAM_PARAM_ID]; |
| 887 | if (masterSession->subsessions.count (id) > 1) |
| 888 | { |
| 889 | // session exists |
| 890 | SendMessageReply (SAM_SESSION_CREATE_DUPLICATED_ID, false); |
| 891 | return; |
| 892 | } |
| 893 | std::string_view style = params[SAM_PARAM_STYLE]; |
| 894 | SAMSessionType type = SAMSessionType::eSAMSessionTypeUnknown; |
| 895 | if (style == SAM_VALUE_STREAM) type = SAMSessionType::eSAMSessionTypeStream; |
| 896 | // TODO: implement other styles |
| 897 | if (type == SAMSessionType::eSAMSessionTypeUnknown) |
| 898 | { |
| 899 | // unknown style |
| 900 | SendSessionI2PError("Unsupported STYLE"); |
| 901 | return; |
| 902 | } |
| 903 | uint16_t fromPort = 0; |
| 904 | params.Get (SAM_PARAM_FROM_PORT, fromPort); |
| 905 | |
| 906 | auto subsession = std::make_shared<SAMSubSession>(masterSession, id, type, fromPort); |
| 907 | if (m_Owner.AddSession (subsession)) |
| 908 | { |
| 909 | masterSession->subsessions.insert (std::string (id)); |
| 910 | SendSessionCreateReplyOk (); |
| 911 | } |
| 912 | else |
| 913 | SendMessageReply (SAM_SESSION_CREATE_DUPLICATED_ID, false); |
| 914 | } |
| 915 | else |
| 916 | SendSessionI2PError ("Wrong session type"); |
| 917 | } |
| 918 | |
| 919 | void SAMSocket::ProcessSessionRemove (std::string_view buf) |
| 920 | { |
nothing calls this directly
no test coverage detected