/// <summary> /// Function used to determine how to handle a received response. /// </summary> /// <param name="ua">The ua.</param> /// <param name="response">The response.</param> /// <param name="stack">The stack.</param> public override void ReceivedResponse(UserAgent ua, Message response, SIPStack stack) { _log.Info("Received response with code " + response.ResponseCode + " " + response.ResponseText); _log.Debug("\n\n" + response.ToString()); switch (response.ResponseCode) { case 180: { break; } case 200: { break; } case 401: { _log.Error("Transaction layer did not handle registration - APP received 401"); //UserAgent ua = new UserAgent(this.stack, null, false); //ua.authenticate(response, transaction); break; } default: { _log.Info("Response code of " + response.ResponseCode + " is unhandled "); } break; } }
public override void Send(string data, string ip, int port, SIPStack stack) { IPAddress[] addresses = Dns.GetHostAddresses(ip); IPEndPoint dest = new IPEndPoint(addresses[0], port); EndPoint destEP = dest; byte[] sendData = Encoding.ASCII.GetBytes(data); string remoteHost = ((IPEndPoint)destEP).Address.ToString(); string remotePort = ((IPEndPoint)destEP).Port.ToString(); stack.Transport.Socket.BeginSendTo(sendData, 0, sendData.Length, SocketFlags.None, destEP, SendDataCB, destEP); ThreadPool.QueueUserWorkItem(delegate { if (RawSentEvent != null) { RawSentEvent(this, new RawEventArgs(data, new[] { remoteHost, remotePort }, true)); } if (SipSentEvent != null) { SipSentEvent(this, new SipMessageEventArgs(new Message(data))); } }, null); }
/// <summary> /// Defines the entry point of the application. /// </summary> /// <param name="args">Arguments not needed</param> static void Main(string[] args) { // Create transport object that will listen on the following port on the best guessed local address Random rnd = new Random(); int port = rnd.Next(5090, 6090); TransportInfo localTransport = CreateTransport("172.27.0.130", port); // Can also specify an IP if you know the IP to be used. //TransportInfo localTransport = CreateTransport("192.168.20.28", 8989); // Create an object of your SIP handling logic with the created transport SIPApp app = new SIPApp(localTransport); // Create a SIP stack with the proxy address if needed SIPStack stack = CreateStack(app, "alice", "172.30.0.161", 5060); // Register with the specified user URI app.Register("sip:[email protected]"); while (true) { app.Invite("sip:[email protected]"); } // Simple pause so you can test each function / watch the SIP signalling Console.ReadKey(); app.Invite("*****@*****.**"); // Simple pause so you can test each function / watch the SIP signalling Console.ReadKey(); // End the current call (presuming it was accepted) app.EndCurrentCall(); // Send an example IM app.Message("*****@*****.**", "Hello, this is alice testing the SIP library"); Console.ReadKey(); }
public override UserAgent CreateServer(Message request, SIPURI uri, SIPStack stack) { if (request.Method == "INVITE") { return(new UserAgent(Stack, request)); } return(null); }
/// <summary> /// Authenticates the specified ua, using the specified username and password. /// Your own method to retrieve the users username and password should be placed in this method. /// </summary> /// <param name="ua">The ua.</param> /// <param name="header">The header.</param> /// <param name="stack">The stack.</param> /// <returns>System.String[].</returns> public override string[] Authenticate(UserAgent ua, Header header, SIPStack stack) { string username = "******"; string realm = "open-ims.test"; string password = "******"; return(new string[] { username + "@" + realm, password }); }
public override void ReceivedResponse(UserAgent ua, Message response, SIPStack stack) { Log.Info("Received response with code " + response.ResponseCode + " " + response.ResponseText); Log.Debug("\n\n" + response); if (ResponseRecvEvent != null) { ResponseRecvEvent(this, new SipMessageEventArgs(response)); } }
public override void ReceivedRequest(UserAgent ua, Message request, SIPStack stack) { Log.Info("Received request with method " + request.Method.ToUpper()); Log.Debug("\n\n" + request); if (RequestRecvEvent != null) { RequestRecvEvent(this, new SipMessageEventArgs(request, ua)); } }
/// <summary> /// Function used to determine how to handle a received request. /// </summary> /// <param name="ua">The ua.</param> /// <param name="request">The request.</param> /// <param name="stack">The stack.</param> public override void ReceivedRequest(UserAgent ua, Message request, SIPStack stack) { _log.Info("Received request with method " + request.Method.ToUpper()); _log.Debug("\n\n" + request.ToString()); switch (request.Method.ToUpper()) { case "INVITE": { // Auto accepts any SIP INVITE request _log.Info("Generating 200 OK response for INVITE"); Message m = ua.CreateResponse(200, "OK"); ua.SendResponse(m); break; } case "CANCEL": { break; } case "ACK": { break; } case "BYE": { break; } case "MESSAGE": { // Logs any received request _log.Info("MESSAGE: " + request.Body); // Can also echo back any received message for testing purposes //Address from = (Address) request.first("From").value; //this.Message(from.uri.ToString(), request.body); break; } case "OPTIONS": case "REFER": case "SUBSCRIBE": case "NOTIFY": case "PUBLISH": case "INFO": default: { _log.Info("Request with method " + request.Method.ToUpper() + " is unhandled"); break; } } }
public static SIPStack CreateStack(SIPApp app, string proxyIp = null, int proxyPort = -1) { SIPStack myStack = new SIPStack(app); if (proxyIp != null) { myStack.ProxyHost = proxyIp; myStack.ProxyPort = (proxyPort == -1) ? 5060 : proxyPort; } return(myStack); }
public override UserAgent CreateServer(Message request, SIPURI uri, SIPStack stack) { if (request.Method != "CANCEL") { return(new Proxy(Stack, request, true)); } else { return(null); } }
public override void Sending(UserAgent ua, Message message, SIPStack stack) { if (Helpers.IsRequest(message)) { Log.Info("Sending request with method " + message.Method); } else { Log.Info("Sending response with code " + message.ResponseCode); } Log.Debug("\n\n" + message); //TODO: Allow App to modify message before it gets sent?; }
public void Start() { _lastupdate = DateTime.Now; _db = new SQLiteDatabase("|DataDirectory|app_data.sqlite;Version=3;"); TransportInfo localTransport = CreateTransport(Helpers.GetLocalIP(), 7202); _app = new SIPApp(localTransport); _app.RequestRecvEvent += AppRequestRecvEvent; _app.ResponseRecvEvent += AppResponseRecvEvent; const string scscfIP = "scscf.open-ims.test"; const int scscfPort = 6060; SIPStack stack = CreateStack(_app, scscfIP, scscfPort); stack.Uri = new SIPURI("*****@*****.**"); _localparty = new Address("<sip:[email protected]>"); StartTimer(); }
static void Main() { if (String.IsNullOrEmpty(_localIP)) { _localIP = Helpers.GetLocalIP(); } TransportInfo localTransport = CreateTransport(_localIP, LocalPort); _app = new SIPApp(localTransport); _app.RequestRecvEvent += AppRequestRecvEvent; _app.ResponseRecvEvent += AppResponseRecvEvent; const string scscfIP = "scscf.open-ims.test"; const int scscfPort = 6060; SIPStack stack = CreateStack(_app, scscfIP, scscfPort); stack.Uri = new SIPURI(ServerURI); //PublishService(true, LocalPort); //StartTimer(); Console.ReadKey(); }
static void Main(string[] args) { TransportInfo localTransport = CreateTransport(Helpers.GetLocalIP(), 7777); _app = new SIPApp(localTransport); _app.RequestRecvEvent += new EventHandler <SipMessageEventArgs>(AppRequestRecvEvent); _app.ResponseRecvEvent += new EventHandler <SipMessageEventArgs>(AppResponseRecvEvent); const string scscfIP = "scscf.open-ims.test"; const int scscfPort = 6060; SIPStack stack = CreateStack(_app, scscfIP, scscfPort); stack.Uri = new SIPURI("*****@*****.**"); _localparty = new Address("<sip:[email protected]>"); StartTimer(); Subscribe("<sip:[email protected]>"); Console.WriteLine("Press \'q\' to quit"); while (Console.Read() != 'q') { ; } }
private static void Main() { TransportInfo localTransport = CreateTransport(Helpers.GetLocalIP(), 7242); _app = new SIPApp(localTransport); _app.RequestRecvEvent += AppRequestRecvEvent; _app.ResponseRecvEvent += AppResponseRecvEvent; const string scscfIP = "scscf.open-ims.test"; const int scscfPort = 6060; InitKeyValueStore(); SIPStack stack = CreateStack(_app, scscfIP, scscfPort); stack.Uri = new SIPURI(ServerURI); StartTimer(); WebServer wb = new WebServer(_tree); wb.Start(); Console.WriteLine("Press \'q\' to quit"); while (Console.Read() != 'q') { } }
public override Timer CreateTimer(UserAgent app, SIPStack stack) { return(new Timer(app)); }
public override void DialogCreated(Dialog dialog, UserAgent ua, SIPStack stack) { Useragents.Remove(ua); Useragents.Add(dialog); Log.Info("New dialog created"); }
public override string[] Authenticate(UserAgent ua, Header header, SIPStack sipStack) { throw new NotImplementedException(); }
public override void Cancelled(UserAgent ua, Message request, SIPStack stack) { throw new NotImplementedException(); }
/// <summary> /// Stub to alert on cancellation. /// </summary> /// <param name="ua">The ua.</param> /// <param name="request">The request.</param> /// <param name="sipStack">The sip stack.</param> public abstract void Cancelled(UserAgent ua, Message request, SIPStack sipStack);
/// <summary> /// Sends the data to the destination host and destination port /// </summary> /// <param name="finalData">The final data.</param> /// <param name="destinationHost">The destination host.</param> /// <param name="destinationPort">The destination port.</param> /// <param name="stack">The stack.</param> public override void Send(string finalData, string destinationHost, int destinationPort, SIPStack stack) { IPAddress[] addresses = System.Net.Dns.GetHostAddresses(destinationHost); IPEndPoint dest = new IPEndPoint(addresses[0], destinationPort); EndPoint destEP = (EndPoint)dest; byte[] send_data = ASCIIEncoding.ASCII.GetBytes(finalData); stack.Transport.Socket.BeginSendTo(send_data, 0, send_data.Length, SocketFlags.None, destEP, new AsyncCallback(this.SendDataCB), destEP); }
/// <summary> /// Stub to handle the authentication of the specified ua. /// </summary> /// <param name="ua">The ua.</param> /// <param name="header">The header.</param> /// <param name="sipStack">The sip stack.</param> /// <returns>System.String[].</returns> public abstract string[] Authenticate(UserAgent ua, Header header, SIPStack sipStack);
/// <summary> /// Stub to alert on sending of a SIP message. /// </summary> /// <param name="ua">The ua.</param> /// <param name="message">The message.</param> /// <param name="sipStack">The sip stack.</param> public abstract void Sending(UserAgent ua, Message message, SIPStack sipStack);
/// <summary> /// Stub to receive a request. /// </summary> /// <param name="ua">The ua.</param> /// <param name="request">The request.</param> /// <param name="sipStack">The sip stack.</param> public abstract void ReceivedRequest(UserAgent ua, Message request, SIPStack sipStack);
/// <summary> /// Stub to receive a response. /// </summary> /// <param name="ua">The ua.</param> /// <param name="response">The response.</param> /// <param name="sipStack">The sip stack.</param> public abstract void ReceivedResponse(UserAgent ua, Message response, SIPStack sipStack);
/// <summary> /// Stub to create timers. /// </summary> /// <param name="obj">The obj.</param> /// <param name="sipStack">The sip stack.</param> /// <returns>Timer.</returns> public abstract Timer CreateTimer(UserAgent obj, SIPStack sipStack);
/// <summary> /// Allows logging / alerting on the creation of a dialog. /// </summary> /// <param name="dialog">The dialog.</param> /// <param name="ua">The ua.</param> /// <param name="stack">The stack.</param> public override void DialogCreated(Dialog dialog, UserAgent ua, SIPStack stack) { this.CallUA = dialog; _log.Info("New dialog created"); }
/// <summary> /// Stub to actually send data. /// </summary> /// <param name="finalData">The final data.</param> /// <param name="destinationHost">The destination host.</param> /// <param name="destinationPort">The destination port.</param> /// <param name="sipStack">The sip stack.</param> public abstract void Send(string finalData, string destinationHost, int destinationPort, SIPStack sipStack);
/// <summary> /// Stub to create a SIP server user agent. /// </summary> /// <param name="request">The request.</param> /// <param name="uri">The URI.</param> /// <param name="sipStack">The sip stack.</param> /// <returns>UserAgent.</returns> public abstract UserAgent CreateServer(Message request, SIPURI uri, SIPStack sipStack);
/// <summary> /// Stub to alert on creation of a dialog. /// </summary> /// <param name="dialog">The dialog.</param> /// <param name="ua">The ua.</param> /// <param name="sipStack">The sip stack.</param> public abstract void DialogCreated(Dialog dialog, UserAgent ua, SIPStack sipStack);