2010-05-14 02:05:29 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
2010-05-27 00:56:24 +00:00
|
|
|
|
using System.Threading;
|
2010-05-14 02:05:29 +00:00
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
2010-05-27 00:56:24 +00:00
|
|
|
|
String s = "mamadou";
|
|
|
|
|
byte[] b = Encoding.UTF8.GetBytes(s);
|
|
|
|
|
|
2010-05-24 22:59:22 +00:00
|
|
|
|
/* Create callbacks */
|
|
|
|
|
sipCallback = new MySipCallback();
|
2010-05-27 00:56:24 +00:00
|
|
|
|
//sipDebugCallback = new MySipDebugCallback();
|
2010-05-24 22:59:22 +00:00
|
|
|
|
|
2010-05-14 02:05:29 +00:00
|
|
|
|
/* Create and configure the IMS/LTE stack */
|
2010-05-24 22:59:22 +00:00
|
|
|
|
sipStack = new SipStack(sipCallback, String.Format("sip:{0}", REALM), String.Format("{0}@{1}", USER, REALM), String.Format("sip:{0}@{1}", USER, REALM));
|
|
|
|
|
sipStack.setDebugCallback(sipDebugCallback);
|
|
|
|
|
sipStack.addHeader("Allow", "INVITE, ACK, CANCEL, BYE, MESSAGE, OPTIONS, NOTIFY, PRACK, UPDATE, REFER");
|
|
|
|
|
sipStack.addHeader("Privacy", "header; id");
|
|
|
|
|
sipStack.addHeader("P-Access-Network-Info", "ADSL;utran-cell-id-3gpp=00000000");
|
|
|
|
|
sipStack.addHeader("User-Agent", "IM-client/OMA1.0 doubango/v1.0.0");
|
2010-05-16 22:24:06 +00:00
|
|
|
|
|
2010-05-14 02:05:29 +00:00
|
|
|
|
/* Sets Proxy-CSCF */
|
2010-05-24 22:59:22 +00:00
|
|
|
|
success = sipStack.setProxyCSCF(PROXY_CSCF_IP, PROXY_CSCF_PORT, "tcp", "ipv4");
|
2010-05-14 02:05:29 +00:00
|
|
|
|
/* Starts the stack */
|
2010-05-24 22:59:22 +00:00
|
|
|
|
success = sipStack.start();
|
2010-05-16 22:24:06 +00:00
|
|
|
|
|
|
|
|
|
/* Set Password */
|
2010-05-18 00:26:37 +00:00
|
|
|
|
//stack.setPassword(PASSWORD);
|
2010-05-14 02:05:29 +00:00
|
|
|
|
|
|
|
|
|
/* Send REGISTER */
|
2010-05-24 22:59:22 +00:00
|
|
|
|
regSession = new RegistrationSession(sipStack);
|
2010-05-14 02:05:29 +00:00
|
|
|
|
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);
|
2010-05-18 00:26:37 +00:00
|
|
|
|
regSession.Register();
|
2010-05-16 22:24:06 +00:00
|
|
|
|
|
2010-05-27 00:56:24 +00:00
|
|
|
|
Thread.Sleep(2000);
|
|
|
|
|
|
2010-05-16 22:24:06 +00:00
|
|
|
|
/* Send SUBSCRIBE(reg) */
|
2010-05-26 00:48:33 +00:00
|
|
|
|
subSession = new SubscriptionSession(sipStack);
|
2010-05-16 22:24:06 +00:00
|
|
|
|
subSession.addHeader("Event", "reg");
|
|
|
|
|
subSession.addHeader("Accept", "application/reginfo+xml");
|
|
|
|
|
subSession.addHeader("Allow-Events", "refer, presence, presence.winfo, xcap-diff, conference");
|
|
|
|
|
subSession.setExpires(35);
|
|
|
|
|
|
2010-05-27 00:56:24 +00:00
|
|
|
|
subSession.Subscribe();
|
2010-05-14 02:05:29 +00:00
|
|
|
|
|
|
|
|
|
Console.Read();
|
2010-05-16 22:24:06 +00:00
|
|
|
|
|
2010-05-24 22:59:22 +00:00
|
|
|
|
sipStack.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-24 22:59:22 +00:00
|
|
|
|
static MySipCallback sipCallback;
|
|
|
|
|
static SipStack sipStack;
|
|
|
|
|
static MySipDebugCallback sipDebugCallback;
|
2010-05-14 02:05:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-05-24 22:59:22 +00:00
|
|
|
|
public class MySipDebugCallback : SipDebugCallback
|
|
|
|
|
{
|
|
|
|
|
public override int OnDebugInfo(string message)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine(".NET____" + message);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override int OnDebugWarn(string message)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine(".NET____" + message);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override int OnDebugError(string message)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine(".NET____" + message);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override int OnDebugFatal(string message)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine(".NET____" + message);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-05-14 02:05:29 +00:00
|
|
|
|
|
2010-05-24 22:59:22 +00:00
|
|
|
|
public class MySipCallback : SipCallback
|
2010-05-14 02:05:29 +00:00
|
|
|
|
{
|
2010-05-24 22:59:22 +00:00
|
|
|
|
public MySipCallback()
|
2010-05-14 02:05:29 +00:00
|
|
|
|
: 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-26 00:48:33 +00:00
|
|
|
|
SipMessage message = e.getSipMessage();
|
|
|
|
|
|
|
|
|
|
if (message != null)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("call-id={0}", message.getSipHeaderValue("call-id"));
|
|
|
|
|
//byte[] bytes = message.getContent();
|
|
|
|
|
}
|
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();
|
2010-05-26 00:48:33 +00:00
|
|
|
|
SipMessage message = e.getSipMessage();
|
2010-05-16 22:24:06 +00:00
|
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
|
{
|
|
|
|
|
case tsip_subscribe_event_type_t.tsip_ao_subscribe:
|
|
|
|
|
case tsip_subscribe_event_type_t.tsip_ao_unsubscribe:
|
2010-05-27 00:56:24 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2010-05-16 22:24:06 +00:00
|
|
|
|
case tsip_subscribe_event_type_t.tsip_i_notify:
|
2010-05-27 00:56:24 +00:00
|
|
|
|
uint content_len = message.getSipContentLength();
|
|
|
|
|
if (content_len>0)
|
|
|
|
|
{
|
|
|
|
|
byte[] content = new byte[content_len];
|
|
|
|
|
uint read = message.getSipContent(content, (uint)content.Length);
|
|
|
|
|
Console.WriteLine("Notify Content ==> {0}", Encoding.UTF8.GetString(content, 0, (int)read));
|
|
|
|
|
}
|
2010-05-16 22:24:06 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Console.WriteLine("OnSubscriptioChanged() ==> {0}:{1}", code, e.getPhrase());
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-27 00:56:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const String PUBLISH_PAYLOAD = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
|
|
|
|
|
"<presence xmlns:cp=\"urn:ietf:params:xml:ns:pidf:cipid\" xmlns:caps=\"urn:ietf:params:xml:ns:pidf:caps\" xmlns:rpid=\"urn:ietf:params:xml:ns:pidf:rpid\" xmlns:pdm=\"urn:ietf:params:xml:ns:pidf:data-model\" xmlns:p=\"urn:ietf:params:xml:ns:pidf-diff\" xmlns:op=\"urn:oma:xml:prs:pidf:oma-pres\" entity=\"sip:bob@ims.inexbee.com\" xmlns=\"urn:ietf:params:xml:ns:pidf\">" +
|
|
|
|
|
"<pdm:person id=\"RPVRYNJH\">" +
|
|
|
|
|
"<op:overriding-willingness>" +
|
|
|
|
|
"<op:basic>open</op:basic>" +
|
|
|
|
|
"</op:overriding-willingness>" +
|
|
|
|
|
"<rpid:activities>" +
|
|
|
|
|
"<rpid:busy />" +
|
|
|
|
|
"</rpid:activities>" +
|
|
|
|
|
"<rpid:mood>" +
|
|
|
|
|
"<rpid:guilty />" +
|
|
|
|
|
"</rpid:mood>" +
|
|
|
|
|
"<cp:homepage>http://doubango.org</cp:homepage>" +
|
|
|
|
|
"<pdm:note>Come share with me RCS Experience</pdm:note>" +
|
|
|
|
|
"</pdm:person>" +
|
|
|
|
|
"<pdm:device id=\"d0001\">" +
|
|
|
|
|
"<status>" +
|
|
|
|
|
"<basic>open</basic>" +
|
|
|
|
|
"</status>" +
|
|
|
|
|
"<caps:devcaps>" +
|
|
|
|
|
"<caps:mobility>" +
|
|
|
|
|
"<caps:supported>" +
|
|
|
|
|
"<caps:fixed />" +
|
|
|
|
|
"</caps:supported>" +
|
|
|
|
|
"</caps:mobility>" +
|
|
|
|
|
"</caps:devcaps>" +
|
|
|
|
|
"<op:network-availability>" +
|
|
|
|
|
"<op:network id=\"IMS\">" +
|
|
|
|
|
"<op:active />" +
|
|
|
|
|
"</op:network>" +
|
|
|
|
|
"</op:network-availability>" +
|
|
|
|
|
"<pdm:deviceID>urn:uuid:3ca50bcb-7a67-44f1-afd0-994a55f930f4</pdm:deviceID>" +
|
|
|
|
|
"</pdm:device>" +
|
|
|
|
|
"</presence>";
|
2010-05-14 02:05:29 +00:00
|
|
|
|
}
|
|
|
|
|
}
|