/* The software in this package is distributed under the GNU General Public License version 2 (with a special exception described below). A copy of GNU General Public License (GPL) is included in this distribution, in the file COPYING.GPL. As a special exception, if other files instantiate templates or use macros or inline functions from this file, or you compile this file and link it with other works to produce a work based on this file, this file does not by itself cause the resulting work to be covered by the GNU General Public License. However the source code for this file must still be made available in accordance with section (3) of the GNU General Public License. This exception does not invalidate any other reasons why a work based on this file might be covered by the GNU General Public License. */ #include "host/pingprotocol.h" #include #include #include "boost_assert_handler.h" using namespace std; static map protocol_string_map; /** * @brief Transform the @a protocol_string into a @c PingProtocol. * * @param protocol_string The string to be parsed. * * @return The @c PingProtocol corresponding to the @a protocol_string. */ PingProtocol get_ping_protocol_from_string( const string & protocol_string ) { BOOST_ASSERT( !protocol_string.empty() ); // convert to uppercase to allow the protocol to be case insensitive string protocol_uppercase_string( protocol_string ); transform( protocol_string.begin(), protocol_string.end(), protocol_uppercase_string.begin(), ::toupper ); //lint !e534 // TODO move to an init method protocol_string_map[ "ICMP" ] = PingProtocol_ICMP; protocol_string_map[ "ICMPV4" ] = PingProtocol_ICMP; protocol_string_map[ "ICMPV6" ] = PingProtocol_ICMPv6; protocol_string_map[ "TCP" ] = PingProtocol_TCP; protocol_string_map[ "TCP_IPV4" ] = PingProtocol_TCP; protocol_string_map[ "TCP_IPV6" ] = PingProtocol_TCP_IPv6; protocol_string_map[ "TCPV4" ] = PingProtocol_TCP; protocol_string_map[ "TCPV6" ] = PingProtocol_TCP_IPv6; PingProtocol protocol = protocol_string_map[ protocol_uppercase_string ]; return protocol; } std::string ping_protocol_to_string( const PingProtocol &protocol) { switch(protocol) { case PingProtocol_ICMP: return "ICMPv4"; break; case PingProtocol_ICMPv6: return "ICMPv6"; break; case PingProtocol_TCP: return "TCPv4"; break; case PingProtocol_TCP_IPv6: return "TCPv6"; break; default: BOOST_ASSERT( !"unexpected PingProtocol in ping_protocol_to_string!" ); break; } }