1b17e4d000599d5caf286d9599cc5244410e1f313sergeyu@chromium.org/* 2b17e4d000599d5caf286d9599cc5244410e1f313sergeyu@chromium.org * libjingle 3b17e4d000599d5caf286d9599cc5244410e1f313sergeyu@chromium.org * Copyright 2013 Google Inc. All rights reserved. 4b17e4d000599d5caf286d9599cc5244410e1f313sergeyu@chromium.org * 5b17e4d000599d5caf286d9599cc5244410e1f313sergeyu@chromium.org * Redistribution and use in source and binary forms, with or without 6b17e4d000599d5caf286d9599cc5244410e1f313sergeyu@chromium.org * modification, are permitted provided that the following conditions are met: 7b17e4d000599d5caf286d9599cc5244410e1f313sergeyu@chromium.org * 8b17e4d000599d5caf286d9599cc5244410e1f313sergeyu@chromium.org * 1. Redistributions of source code must retain the above copyright notice, 9b17e4d000599d5caf286d9599cc5244410e1f313sergeyu@chromium.org * this list of conditions and the following disclaimer. 10b17e4d000599d5caf286d9599cc5244410e1f313sergeyu@chromium.org * 2. Redistributions in binary form must reproduce the above copyright notice, 11b17e4d000599d5caf286d9599cc5244410e1f313sergeyu@chromium.org * this list of conditions and the following disclaimer in the documentation 12b17e4d000599d5caf286d9599cc5244410e1f313sergeyu@chromium.org * and/or other materials provided with the distribution. 13b17e4d000599d5caf286d9599cc5244410e1f313sergeyu@chromium.org * 3. The name of the author may not be used to endorse or promote products 14b17e4d000599d5caf286d9599cc5244410e1f313sergeyu@chromium.org * derived from this software without specific prior written permission. 15b17e4d000599d5caf286d9599cc5244410e1f313sergeyu@chromium.org * 16b17e4d000599d5caf286d9599cc5244410e1f313sergeyu@chromium.org * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17b17e4d000599d5caf286d9599cc5244410e1f313sergeyu@chromium.org * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18b17e4d000599d5caf286d9599cc5244410e1f313sergeyu@chromium.org * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19b17e4d000599d5caf286d9599cc5244410e1f313sergeyu@chromium.org * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20b17e4d000599d5caf286d9599cc5244410e1f313sergeyu@chromium.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21b17e4d000599d5caf286d9599cc5244410e1f313sergeyu@chromium.org * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22b17e4d000599d5caf286d9599cc5244410e1f313sergeyu@chromium.org * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23b17e4d000599d5caf286d9599cc5244410e1f313sergeyu@chromium.org * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24b17e4d000599d5caf286d9599cc5244410e1f313sergeyu@chromium.org * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25b17e4d000599d5caf286d9599cc5244410e1f313sergeyu@chromium.org * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26b17e4d000599d5caf286d9599cc5244410e1f313sergeyu@chromium.org */ 27b17e4d000599d5caf286d9599cc5244410e1f313sergeyu@chromium.org 28b17e4d000599d5caf286d9599cc5244410e1f313sergeyu@chromium.org#include "talk/p2p/base/transportdescription.h" 29b17e4d000599d5caf286d9599cc5244410e1f313sergeyu@chromium.org 30b17e4d000599d5caf286d9599cc5244410e1f313sergeyu@chromium.org#include "talk/p2p/base/constants.h" 31b17e4d000599d5caf286d9599cc5244410e1f313sergeyu@chromium.org 32b17e4d000599d5caf286d9599cc5244410e1f313sergeyu@chromium.orgnamespace cricket { 33b17e4d000599d5caf286d9599cc5244410e1f313sergeyu@chromium.org 34b17e4d000599d5caf286d9599cc5244410e1f313sergeyu@chromium.orgbool StringToConnectionRole(const std::string& role_str, ConnectionRole* role) { 35b17e4d000599d5caf286d9599cc5244410e1f313sergeyu@chromium.org const char* const roles[] = { 36b17e4d000599d5caf286d9599cc5244410e1f313sergeyu@chromium.org CONNECTIONROLE_ACTIVE_STR, 37b17e4d000599d5caf286d9599cc5244410e1f313sergeyu@chromium.org CONNECTIONROLE_PASSIVE_STR, 38b17e4d000599d5caf286d9599cc5244410e1f313sergeyu@chromium.org CONNECTIONROLE_ACTPASS_STR, 39b17e4d000599d5caf286d9599cc5244410e1f313sergeyu@chromium.org CONNECTIONROLE_HOLDCONN_STR 40b17e4d000599d5caf286d9599cc5244410e1f313sergeyu@chromium.org }; 41b17e4d000599d5caf286d9599cc5244410e1f313sergeyu@chromium.org 42b17e4d000599d5caf286d9599cc5244410e1f313sergeyu@chromium.org for (size_t i = 0; i < ARRAY_SIZE(roles); ++i) { 43b17e4d000599d5caf286d9599cc5244410e1f313sergeyu@chromium.org if (stricmp(roles[i], role_str.c_str()) == 0) { 44b17e4d000599d5caf286d9599cc5244410e1f313sergeyu@chromium.org *role = static_cast<ConnectionRole>(CONNECTIONROLE_ACTIVE + i); 45b17e4d000599d5caf286d9599cc5244410e1f313sergeyu@chromium.org return true; 46b17e4d000599d5caf286d9599cc5244410e1f313sergeyu@chromium.org } 47b17e4d000599d5caf286d9599cc5244410e1f313sergeyu@chromium.org } 48b17e4d000599d5caf286d9599cc5244410e1f313sergeyu@chromium.org return false; 49b17e4d000599d5caf286d9599cc5244410e1f313sergeyu@chromium.org} 50b17e4d000599d5caf286d9599cc5244410e1f313sergeyu@chromium.org 51bc7581abbe24c0f45fd04ec30099198670c92512mallinath@webrtc.orgbool ConnectionRoleToString(const ConnectionRole& role, std::string* role_str) { 52bc7581abbe24c0f45fd04ec30099198670c92512mallinath@webrtc.org switch (role) { 53bc7581abbe24c0f45fd04ec30099198670c92512mallinath@webrtc.org case cricket::CONNECTIONROLE_ACTIVE: 54bc7581abbe24c0f45fd04ec30099198670c92512mallinath@webrtc.org *role_str = cricket::CONNECTIONROLE_ACTIVE_STR; 55bc7581abbe24c0f45fd04ec30099198670c92512mallinath@webrtc.org break; 56bc7581abbe24c0f45fd04ec30099198670c92512mallinath@webrtc.org case cricket::CONNECTIONROLE_ACTPASS: 57bc7581abbe24c0f45fd04ec30099198670c92512mallinath@webrtc.org *role_str = cricket::CONNECTIONROLE_ACTPASS_STR; 58bc7581abbe24c0f45fd04ec30099198670c92512mallinath@webrtc.org break; 59bc7581abbe24c0f45fd04ec30099198670c92512mallinath@webrtc.org case cricket::CONNECTIONROLE_PASSIVE: 60bc7581abbe24c0f45fd04ec30099198670c92512mallinath@webrtc.org *role_str = cricket::CONNECTIONROLE_PASSIVE_STR; 61bc7581abbe24c0f45fd04ec30099198670c92512mallinath@webrtc.org break; 62bc7581abbe24c0f45fd04ec30099198670c92512mallinath@webrtc.org case cricket::CONNECTIONROLE_HOLDCONN: 63bc7581abbe24c0f45fd04ec30099198670c92512mallinath@webrtc.org *role_str = cricket::CONNECTIONROLE_HOLDCONN_STR; 64bc7581abbe24c0f45fd04ec30099198670c92512mallinath@webrtc.org break; 65bc7581abbe24c0f45fd04ec30099198670c92512mallinath@webrtc.org default: 66bc7581abbe24c0f45fd04ec30099198670c92512mallinath@webrtc.org return false; 67bc7581abbe24c0f45fd04ec30099198670c92512mallinath@webrtc.org } 68bc7581abbe24c0f45fd04ec30099198670c92512mallinath@webrtc.org return true; 69bc7581abbe24c0f45fd04ec30099198670c92512mallinath@webrtc.org} 70bc7581abbe24c0f45fd04ec30099198670c92512mallinath@webrtc.org 71b17e4d000599d5caf286d9599cc5244410e1f313sergeyu@chromium.org} // namespace cricket 72b17e4d000599d5caf286d9599cc5244410e1f313sergeyu@chromium.org 73