doubango/trunk/bindings/csharp/test/Program.cs

137 lines
4.4 KiB
C#
Raw Normal View History

2010-05-14 02:05:29 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace test
{
class Program
{
const String REALM = "ericsson.com";
const String USER = "mamadou";
const String PROXY_CSCF_IP = "192.168.0.13";
const uint PROXY_CSCF_PORT = 5081;
2010-05-16 22:24:06 +00:00
const String PASSWORD = "";
/*
const String REALM = "sip2sip.info";
const String USER = "2233392625";
const String PASSWORD = "d3sb7j4fb8";
const String PROXY_CSCF_IP = "192.168.0.13";
const uint PROXY_CSCF_PORT = 5081;
*/
2010-05-14 02:05:29 +00:00
static void Main(string[] args)
{
Boolean success;
/* Create call back */
callback = new MyCallback();
/* Create and configure the IMS/LTE stack */
stack = new SipStack(callback, String.Format("sip:{0}", REALM), String.Format("{0}@{1}", USER, REALM), String.Format("sip:{0}@{1}", USER, REALM));
2010-05-16 22:24:06 +00:00
stack.addHeader("Allow", "INVITE, ACK, CANCEL, BYE, MESSAGE, OPTIONS, NOTIFY, PRACK, UPDATE, REFER");
stack.addHeader("Privacy", "header; id");
2010-05-14 02:05:29 +00:00
stack.addHeader("P-Access-Network-Info", "ADSL;utran-cell-id-3gpp=00000000");
2010-05-16 22:24:06 +00:00
stack.addHeader("User-Agent", "IM-client/OMA1.0 doubango/v1.0.0");
2010-05-14 02:05:29 +00:00
/* Sets Proxy-CSCF */
success = stack.setProxyCSCF(PROXY_CSCF_IP, PROXY_CSCF_PORT, "tcp", "ipv4");
/* Starts the stack */
2010-05-16 22:24:06 +00:00
success = stack.start();
/* Set Password */
stack.setPassword(PASSWORD);
2010-05-14 02:05:29 +00:00
/* Send REGISTER */
regSession = new RegistrationSession(stack);
regSession.addCaps("+g.oma.sip-im");
regSession.addCaps("+g.3gpp.smsip");
regSession.addCaps("language", "\"en,fr\"");
2010-05-16 22:24:06 +00:00
regSession.setExpires(35);
//regSession.Register();
/* Send SUBSCRIBE(reg) */
subSession = new SubscriptionSession(stack);
subSession.addHeader("Event", "reg");
subSession.addHeader("Accept", "application/reginfo+xml");
subSession.addHeader("Allow-Events", "refer, presence, presence.winfo, xcap-diff, conference");
subSession.setExpires(35);
//String s = "H\x00\x15eg\x09\x20mamadou";
//subSession.setPayload(s, (uint)s.Length);
subSession.Subscribe();
2010-05-14 02:05:29 +00:00
Console.Read();
2010-05-16 22:24:06 +00:00
stack.stop();
2010-05-14 02:05:29 +00:00
}
static RegistrationSession regSession;
2010-05-16 22:24:06 +00:00
static SubscriptionSession subSession;
2010-05-14 02:05:29 +00:00
static MyCallback callback;
static SipStack stack;
}
public class MyCallback : SipCallback
{
public MyCallback()
: base()
{
}
2010-05-16 22:24:06 +00:00
private static bool isSipCode(short code)
{
return (code <=699 && code >=100);
}
private static bool is2xxCode(short code)
{
return (code <= 299 && code >= 200);
}
private static bool is1xxCode(short code)
{
return (code <= 199 && code >= 100);
}
2010-05-14 02:05:29 +00:00
public override int OnRegistrationChanged(RegistrationEvent e)
{
short code = e.getCode();
2010-05-16 22:24:06 +00:00
tsip_register_event_type_t type = e.getType();
RegistrationSession session = e.getSession();
2010-05-14 02:05:29 +00:00
2010-05-16 22:24:06 +00:00
switch (type)
{
case tsip_register_event_type_t.tsip_ao_register:
case tsip_register_event_type_t.tsip_ao_unregister:
break;
}
2010-05-14 02:05:29 +00:00
Console.WriteLine("OnRegistrationChanged() ==> {0}:{1}", code, e.getPhrase());
return 0;
}
2010-05-16 22:24:06 +00:00
public override int OnSubscriptionChanged(SubscriptionEvent e)
{
short code = e.getCode();
tsip_subscribe_event_type_t type = e.getType();
SubscriptionSession session = e.getSession();
switch (type)
{
case tsip_subscribe_event_type_t.tsip_ao_subscribe:
case tsip_subscribe_event_type_t.tsip_ao_unsubscribe:
case tsip_subscribe_event_type_t.tsip_i_notify:
break;
}
Console.WriteLine("OnSubscriptioChanged() ==> {0}:{1}", code, e.getPhrase());
return 0;
}
2010-05-14 02:05:29 +00:00
}
}