<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal">Hi,<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I am having a third party VoIP client which exposes API in .NET to communicate with my application. I want to use this client as an endpoint in Freeswitch (like how it is implemented in “mod_skypopen” module), so that calls coming to this
client can be handled at Freeswitch and (if required) bridge calls to clients connected to Freeswitch.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">To implement this, I have written a managed module in which “ILoadNotificationPlugin” is implemented where config (client’s interface config) is loaded.
<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">When there is an incoming call (ringing state) to the client, I get handle in managed module and trying to establish a session at freeswitch. While doing this I am getting exception as “<b>Attempted to read or write protected memory. This
is often an indication that other memory is corrupt</b>.”<o:p></o:p></p>
<p class="MsoNormal">Here is the code that I am using… Could someone guide me if I am doing this correctly.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Note: I am following “mod_skypopen” as an example…<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">public static int new_inbound_channel(private_object pobject)<o:p></o:p></p>
<p class="MsoNormal"> {<o:p></o:p></p>
<p class="MsoNormal"> SWIGTYPE_p_switch_core_session session = null;<o:p></o:p></p>
<p class="MsoNormal"> SWIGTYPE_p_switch_channel channel = null;<o:p></o:p></p>
<p class="MsoNormal"> switch_endpoint_interface intf = new switch_endpoint_interface();<o:p></o:p></p>
<p class="MsoNormal"> intf.interface_name = "NET_interface";<o:p></o:p></p>
<p class="MsoNormal"> intf.io_routines = io_routines;<o:p></o:p></p>
<p class="MsoNormal"> intf.state_handler = state_handlers;<o:p></o:p></p>
<p class="MsoNormal"> freeswitch.switch_core_set_globals();<o:p></o:p></p>
<p class="MsoNormal"> Api fsApi = new Api();<o:p></o:p></p>
<p class="MsoNormal"> String uuid = fsApi.ExecuteString("create_uuid");<o:p></o:p></p>
<p class="MsoNormal"> try<o:p></o:p></p>
<p class="MsoNormal"> {<o:p></o:p></p>
<p class="MsoNormal"> session = freeswitch.switch_core_session_request_uuid(intf, switch_call_direction_t.SWITCH_CALL_DIRECTION_INBOUND, 0, null, uuid); //<b>I am getting the above issue here….</b><o:p></o:p></p>
<p class="MsoNormal"> if (session != null)<o:p></o:p></p>
<p class="MsoNormal"> {<o:p></o:p></p>
<p class="MsoNormal"> freeswitch.switch_core_session_add_stream(session, null);<o:p></o:p></p>
<p class="MsoNormal"> channel = freeswitch.switch_core_session_get_channel(session);<o:p></o:p></p>
<p class="MsoNormal"> if (channel == null)<o:p></o:p></p>
<p class="MsoNormal"> {<o:p></o:p></p>
<p class="MsoNormal"> freeswitch.switch_core_session_destroy_state(session);<o:p></o:p></p>
<p class="MsoNormal"> return 0;<o:p></o:p></p>
<p class="MsoNormal"> }<o:p></o:p></p>
<p class="MsoNormal"> freeswitch.switch_channel_set_variable_name_printf(channel, "waste", "false");<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"> pobject.caller_profile = freeswitch.switch_caller_profile_new(freeswitch.switch_core_session_get_pool(session), "NETClient", "dialplan", "callid_name", "callid_number", null,
null, null, null, "mod_netclient", "context", "destination");<o:p></o:p></p>
<p class="MsoNormal"> if (pobject.caller_profile != null)<o:p></o:p></p>
<p class="MsoNormal"> {<o:p></o:p></p>
<p class="MsoNormal"> freeswitch.switch_channel_set_name(channel, "name");<o:p></o:p></p>
<p class="MsoNormal"> freeswitch.switch_channel_set_caller_profile(channel, pobject.caller_profile);<o:p></o:p></p>
<p class="MsoNormal"> }<o:p></o:p></p>
<p class="MsoNormal"> freeswitch.switch_channel_set_state_flag(channel, switch_channel_flag_t.CF_GEN_RINGBACK);<o:p></o:p></p>
<p class="MsoNormal"> switch_status_t session_status = freeswitch.switch_core_session_thread_launch(session);<o:p></o:p></p>
<p class="MsoNormal"> if (session_status != switch_status_t.SWITCH_STATUS_SUCCESS)<o:p></o:p></p>
<p class="MsoNormal"> {<o:p></o:p></p>
<p class="MsoNormal"> freeswitch.switch_core_session_destroy_state(session);<o:p></o:p></p>
<p class="MsoNormal"> return 0;<o:p></o:p></p>
<p class="MsoNormal"> }<o:p></o:p></p>
<p class="MsoNormal"> }<o:p></o:p></p>
<p class="MsoNormal"> }<o:p></o:p></p>
<p class="MsoNormal"> catch (Exception exp)<o:p></o:p></p>
<p class="MsoNormal"> {<o:p></o:p></p>
<p class="MsoNormal"> string expstring = exp.Message;<o:p></o:p></p>
<p class="MsoNormal"> }<o:p></o:p></p>
<p class="MsoNormal"> return 0;<o:p></o:p></p>
<p class="MsoNormal"> }<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Thanks & Regards<o:p></o:p></p>
<p class="MsoNormal">Suneel<o:p></o:p></p>
</div>
</body>
</html>