enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
+ InetAddress inetAddress = enumIpAddr.nextElement();
+
+ if (!inetAddress.isLoopbackAddress()) {
+ if (inetAddress.getHostAddress().toString().contains(":"))
+ continue;
+ if (!PreferenceManager.getDefaultSharedPreferences(getUIContext()).getBoolean(Settings.PREF_STUN, Settings.DEFAULT_STUN)) {
+ localIpAddress = inetAddress.getHostAddress().toString();
+ } else {
+ try {
+ String StunServer = PreferenceManager.getDefaultSharedPreferences(getUIContext()).getString(Settings.PREF_STUN_SERVER, Settings.DEFAULT_STUN_SERVER);
+ int StunServerPort = Integer.valueOf(PreferenceManager.getDefaultSharedPreferences(getUIContext()).getString(Settings.PREF_STUN_SERVER_PORT, Settings.DEFAULT_STUN_SERVER_PORT));
+
+ DiscoveryTest StunDiscover = new DiscoveryTest(inetAddress, StunServer, StunServerPort);
+
+ // call out to stun server
+ StunDiscover.test();
+ //System.out.println("Public ip is:" + StunDiscover.di.getPublicIP().getHostAddress());
+ localIpAddress = StunDiscover.di.getPublicIP().getHostAddress();
+ } catch (BindException be) {
+ if (!Sipdroid.release)
+ System.out.println(inetAddress.toString() + ": " + be.getMessage());
+ } catch (Exception e) {
+ if (!Sipdroid.release) {
+ System.out.println(e.getMessage());
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+ }
+ }
+ } catch (Exception ex) {
+ // do nothing
+ }
+ }
+}
diff --git a/src/org/zoolu/net/SocketAddress.java b/app/src/main/java/org/zoolu/net/SocketAddress.java
similarity index 95%
rename from src/org/zoolu/net/SocketAddress.java
rename to app/src/main/java/org/zoolu/net/SocketAddress.java
index e1da310..8e639d1 100644
--- a/src/org/zoolu/net/SocketAddress.java
+++ b/app/src/main/java/org/zoolu/net/SocketAddress.java
@@ -1,108 +1,108 @@
-/*
- * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
- *
- * This file is part of MjSip (http://www.mjsip.org)
- *
- * MjSip is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * MjSip is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with MjSip; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author(s):
- * Luca Veltri (luca.veltri@unipr.it)
- */
-
-package org.zoolu.net;
-
-/**
- * A SocketAddress is a pair { address, port }.
- */
-public class SocketAddress {
- /** The InetAddress */
- IpAddress ipaddr;
-
- /** The port */
- int port;
-
- /** Creates a SocketAddress. */
- public SocketAddress(IpAddress ipaddr, int port) {
- init(ipaddr, port);
- }
-
- /** Creates a SocketAddress. */
- public SocketAddress(String addr, int port) {
- init(new IpAddress(addr), port);
- }
-
- /** Creates a SocketAddress. */
- public SocketAddress(String soaddr) {
- String addr = null;
- int port = -1;
- int colon = soaddr.indexOf(':');
- if (colon < 0)
- addr = soaddr;
- else {
- addr = soaddr.substring(0, colon);
- try {
- port = Integer.parseInt(soaddr.substring(colon + 1));
- } catch (Exception e) {
- }
- }
- init(new IpAddress(addr), port);
- }
-
- /** Creates a SocketAddress. */
- public SocketAddress(SocketAddress soaddr) {
- init(soaddr.ipaddr, soaddr.port);
- }
-
- /** Inits the SocketAddress. */
- private void init(IpAddress ipaddr, int port) {
- this.ipaddr = ipaddr;
- this.port = port;
- }
-
- /** Gets the host address. */
- public IpAddress getAddress() {
- return ipaddr;
- }
-
- /** Gets the port. */
- public int getPort() {
- return port;
- }
-
- /** Makes a copy. */
- public Object clone() {
- return new SocketAddress(this);
- }
-
- /** Wthether it is equal to Object obj. */
- public boolean equals(Object obj) {
- try {
- SocketAddress saddr = (SocketAddress) obj;
- if (port != saddr.port)
- return false;
- if (!ipaddr.equals(saddr.ipaddr))
- return false;
- return true;
- } catch (Exception e) {
- return false;
- }
- }
-
- /** Gets a String representation of the Object. */
- public String toString() {
- return (ipaddr.toString() + ":" + port);
- }
-
-}
+/*
+ * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
+ *
+ * This file is part of MjSip (http://www.mjsip.org)
+ *
+ * MjSip is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * MjSip is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MjSip; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author(s):
+ * Luca Veltri (luca.veltri@unipr.it)
+ */
+
+package org.zoolu.net;
+
+/**
+ * A SocketAddress is a pair { address, port }.
+ */
+public class SocketAddress {
+ /** The InetAddress */
+ IpAddress ipaddr;
+
+ /** The port */
+ int port;
+
+ /** Creates a SocketAddress. */
+ public SocketAddress(IpAddress ipaddr, int port) {
+ init(ipaddr, port);
+ }
+
+ /** Creates a SocketAddress. */
+ public SocketAddress(String addr, int port) {
+ init(new IpAddress(addr), port);
+ }
+
+ /** Creates a SocketAddress. */
+ public SocketAddress(String soaddr) {
+ String addr = null;
+ int port = -1;
+ int colon = soaddr.indexOf(':');
+ if (colon < 0)
+ addr = soaddr;
+ else {
+ addr = soaddr.substring(0, colon);
+ try {
+ port = Integer.parseInt(soaddr.substring(colon + 1));
+ } catch (Exception e) {
+ }
+ }
+ init(new IpAddress(addr), port);
+ }
+
+ /** Creates a SocketAddress. */
+ public SocketAddress(SocketAddress soaddr) {
+ init(soaddr.ipaddr, soaddr.port);
+ }
+
+ /** Inits the SocketAddress. */
+ private void init(IpAddress ipaddr, int port) {
+ this.ipaddr = ipaddr;
+ this.port = port;
+ }
+
+ /** Gets the host address. */
+ public IpAddress getAddress() {
+ return ipaddr;
+ }
+
+ /** Gets the port. */
+ public int getPort() {
+ return port;
+ }
+
+ /** Makes a copy. */
+ public Object clone() {
+ return new SocketAddress(this);
+ }
+
+ /** Wthether it is equal to Object obj. */
+ public boolean equals(Object obj) {
+ try {
+ SocketAddress saddr = (SocketAddress) obj;
+ if (port != saddr.port)
+ return false;
+ if (!ipaddr.equals(saddr.ipaddr))
+ return false;
+ return true;
+ } catch (Exception e) {
+ return false;
+ }
+ }
+
+ /** Gets a String representation of the Object. */
+ public String toString() {
+ return (ipaddr.toString() + ":" + port);
+ }
+
+}
diff --git a/src/org/zoolu/net/TcpConnection.java b/app/src/main/java/org/zoolu/net/TcpConnection.java
similarity index 96%
rename from src/org/zoolu/net/TcpConnection.java
rename to app/src/main/java/org/zoolu/net/TcpConnection.java
index 56b57d8..59f54b9 100644
--- a/src/org/zoolu/net/TcpConnection.java
+++ b/app/src/main/java/org/zoolu/net/TcpConnection.java
@@ -1,207 +1,207 @@
-/*
- * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
- * Copyright (C) 2009 The Sipdroid Open Source Project
- *
- * This file is part of MjSip (http://www.mjsip.org)
- *
- * MjSip is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * MjSip is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with MjSip; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author(s):
- * Luca Veltri (luca.veltri@unipr.it)
- */
-
-package org.zoolu.net;
-
-// import java.net.InetAddress;
-import java.io.*;
-
-/**
- * TcpConnection provides a TCP connection oriented transport service.
- */
-public class TcpConnection extends Thread {
- /** The reading buffer size */
- static final int BUFFER_SIZE = 65535;
-
- /**
- * Default value for the maximum time that the tcp connection can remain
- * active after been halted (in milliseconds)
- */
- public static final int DEFAULT_SOCKET_TIMEOUT = 2000; // 2sec
-
- /** The TCP socket */
- TcpSocket socket;
-
- /**
- * Maximum time that the connection can remain active after been halted (in
- * milliseconds)
- */
- int socket_timeout;
-
- /**
- * Maximum time that the connection remains active without receiving data
- * (in milliseconds)
- */
- long alive_time;
-
- /** The InputStream */
- InputStream istream;
-
- /** The OutputStream */
- OutputStream ostream;
-
- /** InputStream/OutputStream error */
- Exception error;
-
- /** Whether it has been halted */
- boolean stop;
-
- /** Whether it is running */
- boolean is_running;
-
- /** TcpConnection listener */
- TcpConnectionListener listener;
-
- /** Costructs a new TcpConnection */
- public TcpConnection(TcpSocket socket, TcpConnectionListener listener) {
- init(socket, 0, listener);
- start();
- }
-
- /** Costructs a new TcpConnection */
- public TcpConnection(TcpSocket socket, long alive_time,
- TcpConnectionListener listener) {
- init(socket, alive_time, listener);
- start();
- }
-
- /** Inits the TcpConnection */
- private void init(TcpSocket socket, long alive_time,
- TcpConnectionListener listener) {
- this.listener = listener;
- this.socket = socket;
- this.socket_timeout = DEFAULT_SOCKET_TIMEOUT;
- this.alive_time = alive_time;
- this.stop = false;
- this.is_running = true;
-
- this.istream = null;
- this.ostream = null;
- this.error = null;
- try {
- istream = new BufferedInputStream(socket.getInputStream());
- ostream = new BufferedOutputStream(socket.getOutputStream());
- } catch (Exception e) {
- error = e;
- }
- }
-
- /** Whether the service is running */
- public boolean isRunning() {
- return is_running;
- }
-
- /** Gets the TcpSocket */
- public TcpSocket getSocket() {
- return socket;
- }
-
- /** Gets the remote IP address */
- public IpAddress getRemoteAddress() {
- return socket.getAddress();
- }
-
- /** Gets the remote port */
- public int getRemotePort() {
- return socket.getPort();
- }
-
- /** Stops running */
- public void halt() {
- stop = true;
- }
-
- /** Sends data */
- public void send(byte[] buff, int offset, int len) throws IOException {
- if (!stop && ostream != null) {
- ostream.write(buff, offset, len);
- ostream.flush();
- }
- }
-
- /** Sends data */
- public void send(byte[] buff) throws IOException {
- send(buff, 0, buff.length);
- }
-
- /** Runs the tcp receiver */
- public void run() {
- byte[] buff = new byte[BUFFER_SIZE];
- long expire = 0;
- if (alive_time > 0)
- expire = System.currentTimeMillis() + alive_time;
- try {
- if (error != null)
- throw error;
-// socket.setSoTimeout(socket_timeout); modified
- // loop
- while (!stop) {
- int len = 0;
- if (istream != null) {
- try {
- len = istream.read(buff);
- } catch (InterruptedIOException ie) {
- if (alive_time > 0
- && System.currentTimeMillis() > expire)
- halt();
- continue;
- }
- }
- if (len < 0) { // error=new Exception("TCP connection closed");
- stop = true;
- } else if (len > 0) {
- if (listener != null)
- listener.onReceivedData(this, buff, len);
- if (alive_time > 0)
- expire = System.currentTimeMillis() + alive_time;
- }
- }
- } catch (Exception e) {
- error = e;
- stop = true;
- }
- is_running = false;
- if (istream != null)
- try {
- istream.close();
- } catch (Exception e) {
- }
- if (ostream != null)
- try {
- ostream.close();
- } catch (Exception e) {
- }
- if (listener != null)
- listener.onConnectionTerminated(this, error);
- listener = null;
- }
-
- /** Gets a String representation of the Object */
- public String toString() {
- return "tcp:" // modified + socket.getLocalAddress() + ":" + socket.getLocalPort()
-// + "<->" + socket.getAddress() + ":" + socket.getPort();
- ;
- }
-
-}
+/*
+ * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
+ * Copyright (C) 2009 The Sipdroid Open Source Project
+ *
+ * This file is part of MjSip (http://www.mjsip.org)
+ *
+ * MjSip is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * MjSip is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MjSip; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author(s):
+ * Luca Veltri (luca.veltri@unipr.it)
+ */
+
+package org.zoolu.net;
+
+// import java.net.InetAddress;
+import java.io.*;
+
+/**
+ * TcpConnection provides a TCP connection oriented transport service.
+ */
+public class TcpConnection extends Thread {
+ /** The reading buffer size */
+ static final int BUFFER_SIZE = 65535;
+
+ /**
+ * Default value for the maximum time that the tcp connection can remain
+ * active after been halted (in milliseconds)
+ */
+ public static final int DEFAULT_SOCKET_TIMEOUT = 2000; // 2sec
+
+ /** The TCP socket */
+ TcpSocket socket;
+
+ /**
+ * Maximum time that the connection can remain active after been halted (in
+ * milliseconds)
+ */
+ int socket_timeout;
+
+ /**
+ * Maximum time that the connection remains active without receiving data
+ * (in milliseconds)
+ */
+ long alive_time;
+
+ /** The InputStream */
+ InputStream istream;
+
+ /** The OutputStream */
+ OutputStream ostream;
+
+ /** InputStream/OutputStream error */
+ Exception error;
+
+ /** Whether it has been halted */
+ boolean stop;
+
+ /** Whether it is running */
+ boolean is_running;
+
+ /** TcpConnection listener */
+ TcpConnectionListener listener;
+
+ /** Costructs a new TcpConnection */
+ public TcpConnection(TcpSocket socket, TcpConnectionListener listener) {
+ init(socket, 0, listener);
+ start();
+ }
+
+ /** Costructs a new TcpConnection */
+ public TcpConnection(TcpSocket socket, long alive_time,
+ TcpConnectionListener listener) {
+ init(socket, alive_time, listener);
+ start();
+ }
+
+ /** Inits the TcpConnection */
+ private void init(TcpSocket socket, long alive_time,
+ TcpConnectionListener listener) {
+ this.listener = listener;
+ this.socket = socket;
+ this.socket_timeout = DEFAULT_SOCKET_TIMEOUT;
+ this.alive_time = alive_time;
+ this.stop = false;
+ this.is_running = true;
+
+ this.istream = null;
+ this.ostream = null;
+ this.error = null;
+ try {
+ istream = new BufferedInputStream(socket.getInputStream());
+ ostream = new BufferedOutputStream(socket.getOutputStream());
+ } catch (Exception e) {
+ error = e;
+ }
+ }
+
+ /** Whether the service is running */
+ public boolean isRunning() {
+ return is_running;
+ }
+
+ /** Gets the TcpSocket */
+ public TcpSocket getSocket() {
+ return socket;
+ }
+
+ /** Gets the remote IP address */
+ public IpAddress getRemoteAddress() {
+ return socket.getAddress();
+ }
+
+ /** Gets the remote port */
+ public int getRemotePort() {
+ return socket.getPort();
+ }
+
+ /** Stops running */
+ public void halt() {
+ stop = true;
+ }
+
+ /** Sends data */
+ public void send(byte[] buff, int offset, int len) throws IOException {
+ if (!stop && ostream != null) {
+ ostream.write(buff, offset, len);
+ ostream.flush();
+ }
+ }
+
+ /** Sends data */
+ public void send(byte[] buff) throws IOException {
+ send(buff, 0, buff.length);
+ }
+
+ /** Runs the tcp receiver */
+ public void run() {
+ byte[] buff = new byte[BUFFER_SIZE];
+ long expire = 0;
+ if (alive_time > 0)
+ expire = System.currentTimeMillis() + alive_time;
+ try {
+ if (error != null)
+ throw error;
+// socket.setSoTimeout(socket_timeout); modified
+ // loop
+ while (!stop) {
+ int len = 0;
+ if (istream != null) {
+ try {
+ len = istream.read(buff);
+ } catch (InterruptedIOException ie) {
+ if (alive_time > 0
+ && System.currentTimeMillis() > expire)
+ halt();
+ continue;
+ }
+ }
+ if (len < 0) { // error=new Exception("TCP connection closed");
+ stop = true;
+ } else if (len > 0) {
+ if (listener != null)
+ listener.onReceivedData(this, buff, len);
+ if (alive_time > 0)
+ expire = System.currentTimeMillis() + alive_time;
+ }
+ }
+ } catch (Exception e) {
+ error = e;
+ stop = true;
+ }
+ is_running = false;
+ if (istream != null)
+ try {
+ istream.close();
+ } catch (Exception e) {
+ }
+ if (ostream != null)
+ try {
+ ostream.close();
+ } catch (Exception e) {
+ }
+ if (listener != null)
+ listener.onConnectionTerminated(this, error);
+ listener = null;
+ }
+
+ /** Gets a String representation of the Object */
+ public String toString() {
+ return "tcp:" // modified + socket.getLocalAddress() + ":" + socket.getLocalPort()
+// + "<->" + socket.getAddress() + ":" + socket.getPort();
+ ;
+ }
+
+}
diff --git a/src/org/zoolu/net/TcpConnectionListener.java b/app/src/main/java/org/zoolu/net/TcpConnectionListener.java
similarity index 97%
rename from src/org/zoolu/net/TcpConnectionListener.java
rename to app/src/main/java/org/zoolu/net/TcpConnectionListener.java
index 6a75a68..d4c08bb 100644
--- a/src/org/zoolu/net/TcpConnectionListener.java
+++ b/app/src/main/java/org/zoolu/net/TcpConnectionListener.java
@@ -1,35 +1,35 @@
-/*
- * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
- *
- * This file is part of MjSip (http://www.mjsip.org)
- *
- * MjSip is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * MjSip is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with MjSip; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author(s):
- * Luca Veltri (luca.veltri@unipr.it)
- */
-
-package org.zoolu.net;
-
-/**
- * Listener for TcpConnection events.
- */
-public interface TcpConnectionListener {
- /** When new data is received through the TcpConnection. */
- public void onReceivedData(TcpConnection tcp_conn, byte[] data, int len);
-
- /** When TcpConnection terminates. */
- public void onConnectionTerminated(TcpConnection tcp_conn, Exception error);
-}
+/*
+ * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
+ *
+ * This file is part of MjSip (http://www.mjsip.org)
+ *
+ * MjSip is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * MjSip is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MjSip; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author(s):
+ * Luca Veltri (luca.veltri@unipr.it)
+ */
+
+package org.zoolu.net;
+
+/**
+ * Listener for TcpConnection events.
+ */
+public interface TcpConnectionListener {
+ /** When new data is received through the TcpConnection. */
+ public void onReceivedData(TcpConnection tcp_conn, byte[] data, int len);
+
+ /** When TcpConnection terminates. */
+ public void onConnectionTerminated(TcpConnection tcp_conn, Exception error);
+}
diff --git a/src/org/zoolu/net/TcpServer.java b/app/src/main/java/org/zoolu/net/TcpServer.java
similarity index 96%
rename from src/org/zoolu/net/TcpServer.java
rename to app/src/main/java/org/zoolu/net/TcpServer.java
index 56033ee..da6fb29 100644
--- a/src/org/zoolu/net/TcpServer.java
+++ b/app/src/main/java/org/zoolu/net/TcpServer.java
@@ -1,171 +1,171 @@
-/*
- * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
- * Copyright (C) 2009 The Sipdroid Open Source Project
- *
- * This file is part of MjSip (http://www.mjsip.org)
- *
- * MjSip is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * MjSip is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with MjSip; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author(s):
- * Luca Veltri (luca.veltri@unipr.it)
- */
-
-package org.zoolu.net;
-
-import java.net.ServerSocket;
-import java.io.IOException;
-import java.io.InterruptedIOException;
-
-/**
- * TcpServer implements a TCP server wainting for incoming connection.
- */
-public class TcpServer extends Thread {
- /**
- * Default value for the maximum time that the tcp server can remain active
- * after been halted (in milliseconds)
- */
- public static final int DEFAULT_SOCKET_TIMEOUT = 5000; // 5sec
-
- /** Default ServerSocket backlog value */
- static int socket_backlog = 50;
-
- /** The protocol type */
- // protected static final String PROTO="tcp";
- /** The TCP server socket */
- ServerSocket server_socket;
-
- /**
- * Maximum time that the connection can remain active after been halted (in
- * milliseconds)
- */
- int socket_timeout;
-
- /**
- * Maximum time that the server remains active without incoming connections
- * (in milliseconds)
- */
- long alive_time;
-
- /** Whether it has been halted */
- boolean stop;
-
- /** Whether it is running */
- boolean is_running;
-
- /** TcpServer listener */
- TcpServerListener listener;
-
- /** Costructs a new TcpServer */
- public TcpServer(int port, TcpServerListener listener)
- throws java.io.IOException {
- init(port, null, 0, listener);
- start();
- }
-
- /** Costructs a new TcpServer */
- public TcpServer(int port, IpAddress bind_ipaddr, TcpServerListener listener)
- throws java.io.IOException {
- init(port, bind_ipaddr, 0, listener);
- start();
- }
-
- /** Costructs a new TcpServer */
- public TcpServer(int port, IpAddress bind_ipaddr, long alive_time,
- TcpServerListener listener) throws java.io.IOException {
- init(port, bind_ipaddr, alive_time, listener);
- start();
- }
-
- /** Inits the TcpServer */
- private void init(int port, IpAddress bind_ipaddr, long alive_time,
- TcpServerListener listener) throws java.io.IOException {
- this.listener = listener;
- if (bind_ipaddr == null)
- server_socket = new ServerSocket(port);
- else
- server_socket = new ServerSocket(port, socket_backlog, bind_ipaddr
- .getInetAddress());
- this.socket_timeout = DEFAULT_SOCKET_TIMEOUT;
- this.alive_time = alive_time;
- this.stop = false;
- this.is_running = true;
- }
-
- public int getPort() {
- return server_socket.getLocalPort();
- }
-
- /** Whether the service is running */
- public boolean isRunning() {
- return is_running;
- }
-
- /** Stops running */
- public void halt() {
- stop = true;
- try {
- server_socket.close(); // modified
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-
- /** Runs the server */
- public void run() {
- Exception error = null;
- try {
-// server_socket.setSoTimeout(socket_timeout); modified
- long expire = 0;
- if (alive_time > 0)
- expire = System.currentTimeMillis() + alive_time;
- // loop
- while (!stop) {
- TcpSocket socket = null;
- try {
- socket = new TcpSocket(server_socket.accept());
- } catch (InterruptedIOException ie) {
- if (alive_time > 0 && System.currentTimeMillis() > expire)
- halt();
- continue;
- }
- if (listener != null)
- listener.onIncomingConnection(this, socket);
- if (alive_time > 0)
- expire = System.currentTimeMillis() + alive_time;
- }
- } catch (Exception e) {
- error = e;
- stop = true;
- }
- is_running = false;
- try {
- server_socket.close();
- } catch (java.io.IOException e) {
- }
- server_socket = null;
-
- if (listener != null)
- listener.onServerTerminated(this, error);
- listener = null;
- }
-
- /** Gets a String representation of the Object */
- public String toString() {
- return "tcp:" // modified + server_socket.getInetAddress() + ":"
- //+ server_socket.getLocalPort();
- ;
- }
-
-}
+/*
+ * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
+ * Copyright (C) 2009 The Sipdroid Open Source Project
+ *
+ * This file is part of MjSip (http://www.mjsip.org)
+ *
+ * MjSip is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * MjSip is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MjSip; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author(s):
+ * Luca Veltri (luca.veltri@unipr.it)
+ */
+
+package org.zoolu.net;
+
+import java.net.ServerSocket;
+import java.io.IOException;
+import java.io.InterruptedIOException;
+
+/**
+ * TcpServer implements a TCP server wainting for incoming connection.
+ */
+public class TcpServer extends Thread {
+ /**
+ * Default value for the maximum time that the tcp server can remain active
+ * after been halted (in milliseconds)
+ */
+ public static final int DEFAULT_SOCKET_TIMEOUT = 5000; // 5sec
+
+ /** Default ServerSocket backlog value */
+ static int socket_backlog = 50;
+
+ /** The protocol type */
+ // protected static final String PROTO="tcp";
+ /** The TCP server socket */
+ ServerSocket server_socket;
+
+ /**
+ * Maximum time that the connection can remain active after been halted (in
+ * milliseconds)
+ */
+ int socket_timeout;
+
+ /**
+ * Maximum time that the server remains active without incoming connections
+ * (in milliseconds)
+ */
+ long alive_time;
+
+ /** Whether it has been halted */
+ boolean stop;
+
+ /** Whether it is running */
+ boolean is_running;
+
+ /** TcpServer listener */
+ TcpServerListener listener;
+
+ /** Costructs a new TcpServer */
+ public TcpServer(int port, TcpServerListener listener)
+ throws java.io.IOException {
+ init(port, null, 0, listener);
+ start();
+ }
+
+ /** Costructs a new TcpServer */
+ public TcpServer(int port, IpAddress bind_ipaddr, TcpServerListener listener)
+ throws java.io.IOException {
+ init(port, bind_ipaddr, 0, listener);
+ start();
+ }
+
+ /** Costructs a new TcpServer */
+ public TcpServer(int port, IpAddress bind_ipaddr, long alive_time,
+ TcpServerListener listener) throws java.io.IOException {
+ init(port, bind_ipaddr, alive_time, listener);
+ start();
+ }
+
+ /** Inits the TcpServer */
+ private void init(int port, IpAddress bind_ipaddr, long alive_time,
+ TcpServerListener listener) throws java.io.IOException {
+ this.listener = listener;
+ if (bind_ipaddr == null)
+ server_socket = new ServerSocket(port);
+ else
+ server_socket = new ServerSocket(port, socket_backlog, bind_ipaddr
+ .getInetAddress());
+ this.socket_timeout = DEFAULT_SOCKET_TIMEOUT;
+ this.alive_time = alive_time;
+ this.stop = false;
+ this.is_running = true;
+ }
+
+ public int getPort() {
+ return server_socket.getLocalPort();
+ }
+
+ /** Whether the service is running */
+ public boolean isRunning() {
+ return is_running;
+ }
+
+ /** Stops running */
+ public void halt() {
+ stop = true;
+ try {
+ server_socket.close(); // modified
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /** Runs the server */
+ public void run() {
+ Exception error = null;
+ try {
+// server_socket.setSoTimeout(socket_timeout); modified
+ long expire = 0;
+ if (alive_time > 0)
+ expire = System.currentTimeMillis() + alive_time;
+ // loop
+ while (!stop) {
+ TcpSocket socket = null;
+ try {
+ socket = new TcpSocket(server_socket.accept());
+ } catch (InterruptedIOException ie) {
+ if (alive_time > 0 && System.currentTimeMillis() > expire)
+ halt();
+ continue;
+ }
+ if (listener != null)
+ listener.onIncomingConnection(this, socket);
+ if (alive_time > 0)
+ expire = System.currentTimeMillis() + alive_time;
+ }
+ } catch (Exception e) {
+ error = e;
+ stop = true;
+ }
+ is_running = false;
+ try {
+ server_socket.close();
+ } catch (java.io.IOException e) {
+ }
+ server_socket = null;
+
+ if (listener != null)
+ listener.onServerTerminated(this, error);
+ listener = null;
+ }
+
+ /** Gets a String representation of the Object */
+ public String toString() {
+ return "tcp:" // modified + server_socket.getInetAddress() + ":"
+ //+ server_socket.getLocalPort();
+ ;
+ }
+
+}
diff --git a/src/org/zoolu/net/TcpServerListener.java b/app/src/main/java/org/zoolu/net/TcpServerListener.java
similarity index 97%
rename from src/org/zoolu/net/TcpServerListener.java
rename to app/src/main/java/org/zoolu/net/TcpServerListener.java
index ba7f536..7652e07 100644
--- a/src/org/zoolu/net/TcpServerListener.java
+++ b/app/src/main/java/org/zoolu/net/TcpServerListener.java
@@ -1,35 +1,35 @@
-/*
- * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
- *
- * This file is part of MjSip (http://www.mjsip.org)
- *
- * MjSip is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * MjSip is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with MjSip; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author(s):
- * Luca Veltri (luca.veltri@unipr.it)
- */
-
-package org.zoolu.net;
-
-/**
- * Listener for TcpServer events.
- */
-public interface TcpServerListener {
- /** When a new incoming connection is established */
- public void onIncomingConnection(TcpServer tcp_server, TcpSocket socket);
-
- /** When ConnectionServer terminates. */
- public void onServerTerminated(TcpServer tcp_server, Exception error);
-}
+/*
+ * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
+ *
+ * This file is part of MjSip (http://www.mjsip.org)
+ *
+ * MjSip is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * MjSip is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MjSip; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author(s):
+ * Luca Veltri (luca.veltri@unipr.it)
+ */
+
+package org.zoolu.net;
+
+/**
+ * Listener for TcpServer events.
+ */
+public interface TcpServerListener {
+ /** When a new incoming connection is established */
+ public void onIncomingConnection(TcpServer tcp_server, TcpSocket socket);
+
+ /** When ConnectionServer terminates. */
+ public void onServerTerminated(TcpServer tcp_server, Exception error);
+}
diff --git a/src/org/zoolu/net/TcpSocket.java b/app/src/main/java/org/zoolu/net/TcpSocket.java
similarity index 96%
rename from src/org/zoolu/net/TcpSocket.java
rename to app/src/main/java/org/zoolu/net/TcpSocket.java
index 4055b6f..038ecce 100644
--- a/src/org/zoolu/net/TcpSocket.java
+++ b/app/src/main/java/org/zoolu/net/TcpSocket.java
@@ -1,138 +1,138 @@
-/*
- * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
- * Copyright (C) 2009 The Sipdroid Open Source Project
- *
- * This file is part of MjSip (http://www.mjsip.org)
- *
- * MjSip is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * MjSip is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with MjSip; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author(s):
- * Luca Veltri (luca.veltri@unipr.it)
- */
-
-package org.zoolu.net;
-
-import java.net.InetSocketAddress;
-import java.net.Socket; // import java.net.InetAddress;
-import java.io.InputStream;
-import java.io.OutputStream;
-
-import javax.net.ssl.HostnameVerifier;
-import javax.net.ssl.HttpsURLConnection;
-import javax.net.ssl.SSLSession;
-import javax.net.ssl.SSLSocket;
-
-import org.apache.http.conn.ssl.SSLSocketFactory;
-
-/**
- * TcpSocket provides a uniform interface to TCP transport protocol, regardless
- * J2SE or J2ME is used.
- */
-public class TcpSocket {
- /** Socket */
- Socket socket;
-
- /** Creates a new TcpSocket */
- TcpSocket() {
- socket = null;
- }
-
- /** Creates a new TcpSocket */
- TcpSocket(Socket sock) {
- socket = sock;
- }
-
- static boolean lock;
-
- /** Creates a new UdpSocket */
- public TcpSocket(IpAddress ipaddr, int port, String host) throws java.io.IOException {
-// socket = new Socket(ipaddr.getInetAddress(), port); modified
- SSLSocketFactory f =
- (SSLSocketFactory) SSLSocketFactory.getSocketFactory();
- if (host == null)
- socket = new Socket();
- else
- socket = f.createSocket();
- if (lock) throw new java.io.IOException();
- lock = true;
- try {
- socket.connect(new InetSocketAddress(ipaddr.toString(), port),
- Thread.currentThread().getName().equals("main")?1000:10000);
- } catch (java.io.IOException e) {
- lock = false;
- throw e;
- }
- if (host != null && !host.equals(ipaddr.toString())) {
- HostnameVerifier hv = HttpsURLConnection.getDefaultHostnameVerifier();
- SSLSession s = ((SSLSocket)socket).getSession();
- if (!hv.verify(host, s)) {
- lock = false;
- throw new java.io.IOException();
- }
- }
- lock = false;
- }
-
- /** Closes this socket. */
- public void close() throws java.io.IOException {
- socket.close();
- }
-
- /** Gets the address to which the socket is connected. */
- public IpAddress getAddress() {
- return new IpAddress(socket.getInetAddress());
- }
-
- /** Gets an input stream for this socket. */
- public InputStream getInputStream() throws java.io.IOException {
- return socket.getInputStream();
- }
-
- /** Gets the local address to which the socket is bound. */
- public IpAddress getLocalAddress() {
- return new IpAddress(socket.getLocalAddress());
- }
-
- /** Gets the local port to which this socket is bound. */
- public int getLocalPort() {
- return socket.getLocalPort();
- }
-
- /** Gets an output stream for this socket. */
- public OutputStream getOutputStream() throws java.io.IOException {
- return socket.getOutputStream();
- }
-
- /** Gets the remote port to which this socket is connected. */
- public int getPort() {
- return socket.getPort();
- }
-
- /** Gets the socket timeout. */
- public int getSoTimeout() throws java.net.SocketException {
- return socket.getSoTimeout();
- }
-
- /** Enables/disables the socket timeou, in milliseconds. */
- public void setSoTimeout(int timeout) throws java.net.SocketException {
- socket.setSoTimeout(timeout);
- }
-
- /** Converts this object to a String. */
- public String toString() {
- return socket.toString();
- }
-
-}
+/*
+ * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
+ * Copyright (C) 2009 The Sipdroid Open Source Project
+ *
+ * This file is part of MjSip (http://www.mjsip.org)
+ *
+ * MjSip is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * MjSip is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MjSip; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author(s):
+ * Luca Veltri (luca.veltri@unipr.it)
+ */
+
+package org.zoolu.net;
+
+import java.net.InetSocketAddress;
+import java.net.Socket; // import java.net.InetAddress;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import javax.net.ssl.HostnameVerifier;
+import javax.net.ssl.HttpsURLConnection;
+import javax.net.ssl.SSLSession;
+import javax.net.ssl.SSLSocket;
+
+import org.apache.http.conn.ssl.SSLSocketFactory;
+
+/**
+ * TcpSocket provides a uniform interface to TCP transport protocol, regardless
+ * J2SE or J2ME is used.
+ */
+public class TcpSocket {
+ /** Socket */
+ Socket socket;
+
+ /** Creates a new TcpSocket */
+ TcpSocket() {
+ socket = null;
+ }
+
+ /** Creates a new TcpSocket */
+ TcpSocket(Socket sock) {
+ socket = sock;
+ }
+
+ static boolean lock;
+
+ /** Creates a new UdpSocket */
+ public TcpSocket(IpAddress ipaddr, int port, String host) throws java.io.IOException {
+// socket = new Socket(ipaddr.getInetAddress(), port); modified
+ SSLSocketFactory f =
+ (SSLSocketFactory) SSLSocketFactory.getSocketFactory();
+ if (host == null)
+ socket = new Socket();
+ else
+ socket = f.createSocket();
+ if (lock) throw new java.io.IOException();
+ lock = true;
+ try {
+ socket.connect(new InetSocketAddress(ipaddr.toString(), port),
+ Thread.currentThread().getName().equals("main")?1000:10000);
+ } catch (java.io.IOException e) {
+ lock = false;
+ throw e;
+ }
+ if (host != null && !host.equals(ipaddr.toString())) {
+ HostnameVerifier hv = HttpsURLConnection.getDefaultHostnameVerifier();
+ SSLSession s = ((SSLSocket)socket).getSession();
+ if (!hv.verify(host, s)) {
+ lock = false;
+ throw new java.io.IOException();
+ }
+ }
+ lock = false;
+ }
+
+ /** Closes this socket. */
+ public void close() throws java.io.IOException {
+ socket.close();
+ }
+
+ /** Gets the address to which the socket is connected. */
+ public IpAddress getAddress() {
+ return new IpAddress(socket.getInetAddress());
+ }
+
+ /** Gets an input stream for this socket. */
+ public InputStream getInputStream() throws java.io.IOException {
+ return socket.getInputStream();
+ }
+
+ /** Gets the local address to which the socket is bound. */
+ public IpAddress getLocalAddress() {
+ return new IpAddress(socket.getLocalAddress());
+ }
+
+ /** Gets the local port to which this socket is bound. */
+ public int getLocalPort() {
+ return socket.getLocalPort();
+ }
+
+ /** Gets an output stream for this socket. */
+ public OutputStream getOutputStream() throws java.io.IOException {
+ return socket.getOutputStream();
+ }
+
+ /** Gets the remote port to which this socket is connected. */
+ public int getPort() {
+ return socket.getPort();
+ }
+
+ /** Gets the socket timeout. */
+ public int getSoTimeout() throws java.net.SocketException {
+ return socket.getSoTimeout();
+ }
+
+ /** Enables/disables the socket timeou, in milliseconds. */
+ public void setSoTimeout(int timeout) throws java.net.SocketException {
+ socket.setSoTimeout(timeout);
+ }
+
+ /** Converts this object to a String. */
+ public String toString() {
+ return socket.toString();
+ }
+
+}
diff --git a/src/org/zoolu/net/UdpPacket.java b/app/src/main/java/org/zoolu/net/UdpPacket.java
similarity index 96%
rename from src/org/zoolu/net/UdpPacket.java
rename to app/src/main/java/org/zoolu/net/UdpPacket.java
index 96f7828..9e14eab 100644
--- a/src/org/zoolu/net/UdpPacket.java
+++ b/app/src/main/java/org/zoolu/net/UdpPacket.java
@@ -1,140 +1,140 @@
-/*
- * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
- *
- * This file is part of MjSip (http://www.mjsip.org)
- *
- * MjSip is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * MjSip is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with MjSip; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author(s):
- * Luca Veltri (luca.veltri@unipr.it)
- */
-
-package org.zoolu.net;
-
-import java.net.DatagramPacket;
-
-// import java.net.InetAddress;
-
-/**
- * UdpPacket provides a uniform interface to UDP packets, regardless J2SE or
- * J2ME is used.
- */
-public class UdpPacket {
- /** The DatagramPacket */
- DatagramPacket packet;
-
- /** Creates a new UdpPacket */
- UdpPacket(DatagramPacket packet) {
- this.packet = packet;
- }
-
- /** Gets the DatagramPacket */
- DatagramPacket getDatagramPacket() {
- return packet;
- }
-
- /** Sets the DatagramPacket */
- void setDatagramPacket(DatagramPacket packet) {
- this.packet = packet;
- }
-
- /** Creates a new UdpPacket */
- public UdpPacket(byte[] buf, int length) {
- packet = new DatagramPacket(buf, length);
- }
-
- /** Creates a new UdpPacket */
- public UdpPacket(byte[] buf, int length, IpAddress ipaddr, int port) {
- packet = new DatagramPacket(buf, length, ipaddr.getInetAddress(), port);
- }
-
- /** Creates a new UdpPacket */
- public UdpPacket(byte[] buf, int offset, int length) {
- packet = new DatagramPacket(buf, offset, length);
- }
-
- /** Creates a new UdpPacket */
- public UdpPacket(byte[] buf, int offset, int length, IpAddress ipaddr,
- int port) {
- packet = new DatagramPacket(buf, offset, length, ipaddr
- .getInetAddress(), port);
- }
-
- /**
- * Gets the IP address of the machine to which this datagram is being sent
- * or from which the datagram was received.
- */
- public IpAddress getIpAddress() {
- return new IpAddress(packet.getAddress());
- }
-
- /** Gets the data received or the data to be sent. */
- public byte[] getData() {
- return packet.getData();
- }
-
- /**
- * Gets the length of the data to be sent or the length of the data
- * received.
- */
- public int getLength() {
- return packet.getLength();
- }
-
- /**
- * Gets the offset of the data to be sent or the offset of the data
- * received.
- */
- public int getOffset() {
- return packet.getOffset();
- }
-
- /**
- * Gets the port number on the remote host to which this datagram is being
- * sent or from which the datagram was received.
- */
- public int getPort() {
- return packet.getPort();
- }
-
- /** Sets the IP address of the machine to which this datagram is being sent. */
- public void setIpAddress(IpAddress ipaddr) {
- packet.setAddress(ipaddr.getInetAddress());
- }
-
- /** Sets the data buffer for this packet. */
- public void setData(byte[] buf) {
- packet.setData(buf);
- }
-
- /** Sets the data buffer for this packet. */
- public void setData(byte[] buf, int offset, int length) {
- packet.setData(buf, offset, length);
- }
-
- /** Sets the length for this packet. */
- public void setLength(int length) {
- packet.setLength(length);
- }
-
- /**
- * Sets the port number on the remote host to which this datagram is being
- * sent.
- */
- public void setPort(int iport) {
- packet.setPort(iport);
- }
-
-}
+/*
+ * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
+ *
+ * This file is part of MjSip (http://www.mjsip.org)
+ *
+ * MjSip is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * MjSip is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MjSip; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author(s):
+ * Luca Veltri (luca.veltri@unipr.it)
+ */
+
+package org.zoolu.net;
+
+import java.net.DatagramPacket;
+
+// import java.net.InetAddress;
+
+/**
+ * UdpPacket provides a uniform interface to UDP packets, regardless J2SE or
+ * J2ME is used.
+ */
+public class UdpPacket {
+ /** The DatagramPacket */
+ DatagramPacket packet;
+
+ /** Creates a new UdpPacket */
+ UdpPacket(DatagramPacket packet) {
+ this.packet = packet;
+ }
+
+ /** Gets the DatagramPacket */
+ DatagramPacket getDatagramPacket() {
+ return packet;
+ }
+
+ /** Sets the DatagramPacket */
+ void setDatagramPacket(DatagramPacket packet) {
+ this.packet = packet;
+ }
+
+ /** Creates a new UdpPacket */
+ public UdpPacket(byte[] buf, int length) {
+ packet = new DatagramPacket(buf, length);
+ }
+
+ /** Creates a new UdpPacket */
+ public UdpPacket(byte[] buf, int length, IpAddress ipaddr, int port) {
+ packet = new DatagramPacket(buf, length, ipaddr.getInetAddress(), port);
+ }
+
+ /** Creates a new UdpPacket */
+ public UdpPacket(byte[] buf, int offset, int length) {
+ packet = new DatagramPacket(buf, offset, length);
+ }
+
+ /** Creates a new UdpPacket */
+ public UdpPacket(byte[] buf, int offset, int length, IpAddress ipaddr,
+ int port) {
+ packet = new DatagramPacket(buf, offset, length, ipaddr
+ .getInetAddress(), port);
+ }
+
+ /**
+ * Gets the IP address of the machine to which this datagram is being sent
+ * or from which the datagram was received.
+ */
+ public IpAddress getIpAddress() {
+ return new IpAddress(packet.getAddress());
+ }
+
+ /** Gets the data received or the data to be sent. */
+ public byte[] getData() {
+ return packet.getData();
+ }
+
+ /**
+ * Gets the length of the data to be sent or the length of the data
+ * received.
+ */
+ public int getLength() {
+ return packet.getLength();
+ }
+
+ /**
+ * Gets the offset of the data to be sent or the offset of the data
+ * received.
+ */
+ public int getOffset() {
+ return packet.getOffset();
+ }
+
+ /**
+ * Gets the port number on the remote host to which this datagram is being
+ * sent or from which the datagram was received.
+ */
+ public int getPort() {
+ return packet.getPort();
+ }
+
+ /** Sets the IP address of the machine to which this datagram is being sent. */
+ public void setIpAddress(IpAddress ipaddr) {
+ packet.setAddress(ipaddr.getInetAddress());
+ }
+
+ /** Sets the data buffer for this packet. */
+ public void setData(byte[] buf) {
+ packet.setData(buf);
+ }
+
+ /** Sets the data buffer for this packet. */
+ public void setData(byte[] buf, int offset, int length) {
+ packet.setData(buf, offset, length);
+ }
+
+ /** Sets the length for this packet. */
+ public void setLength(int length) {
+ packet.setLength(length);
+ }
+
+ /**
+ * Sets the port number on the remote host to which this datagram is being
+ * sent.
+ */
+ public void setPort(int iport) {
+ packet.setPort(iport);
+ }
+
+}
diff --git a/src/org/zoolu/net/UdpProvider.java b/app/src/main/java/org/zoolu/net/UdpProvider.java
similarity index 96%
rename from src/org/zoolu/net/UdpProvider.java
rename to app/src/main/java/org/zoolu/net/UdpProvider.java
index ca8de0d..f227d7d 100644
--- a/src/org/zoolu/net/UdpProvider.java
+++ b/app/src/main/java/org/zoolu/net/UdpProvider.java
@@ -1,210 +1,210 @@
-/*
- * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
- * Copyright (C) 2009 The Sipdroid Open Source Project
- *
- * This file is part of MjSip (http://www.mjsip.org)
- *
- * MjSip is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * MjSip is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with MjSip; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author(s):
- * Luca Veltri (luca.veltri@unipr.it)
- */
-
-package org.zoolu.net;
-
-import java.io.IOException;
-import java.io.InterruptedIOException;
-
-/**
- * UdpProvider provides an UDP send/receive service. On the receiver side it
- * waits for UDP datagrams and passes them to the UdpProviderListener.
- *
- * If the attribute alive_time has a non-zero value, the UdpProvider
- * stops after alive_time milliseconds of inactivity.
- *
- * When a new packet is received, the
- * onReceivedPacket(UdpProvider,DatagramPacket) method is fired.
- *
- * Method onServiceTerminated(UdpProvider) is fired when the the UdpProvider
- * stops receiving packets.
- */
-public class UdpProvider extends Thread {
- /** The reading buffer size */
- public static final int BUFFER_SIZE = 65535;
-
- /**
- * Default value for the maximum time that the UDP receiver can remain
- * active after been halted (in milliseconds)
- */
- public static final int DEFAULT_SOCKET_TIMEOUT = 2000; // 2sec
-
- /** UDP socket */
- UdpSocket socket;
-
- /**
- * Maximum time that the UDP receiver can remain active after been halted
- * (in milliseconds)
- */
- int socket_timeout;
-
- /**
- * Maximum time that the UDP receiver remains active without receiving UDP
- * datagrams (in milliseconds)
- */
- long alive_time;
-
- /**
- * Minimum size for received packets. Shorter packets are silently
- * discarded.
- */
- int minimum_length;
-
- /** Whether it has been halted */
- boolean stop;
-
- /** Whether it is running */
- boolean is_running;
-
- /** UdpProvider listener */
- UdpProviderListener listener;
-
- /** Creates a new UdpProvider */
- public UdpProvider(UdpSocket socket, UdpProviderListener listener) {
- init(socket, 0, listener);
- start();
- }
-
- /** Creates a new UdpProvider */
- public UdpProvider(UdpSocket socket, long alive_time,
- UdpProviderListener listener) {
- init(socket, alive_time, listener);
- start();
- }
-
- /** Inits the UdpProvider */
- private void init(UdpSocket socket, long alive_time,
- UdpProviderListener listener) {
- this.listener = listener;
- this.socket = socket;
- this.socket_timeout = DEFAULT_SOCKET_TIMEOUT;
- this.alive_time = alive_time;
- this.minimum_length = 0;
- this.stop = false;
- this.is_running = true;
- }
-
- /** Gets the UdpSocket */
- public UdpSocket getUdpSocket() {
- return socket;
- }
-
- /** Sets a new UdpSocket */
- /*
- * public void setUdpSocket(UdpSocket socket) { this.socket=socket; }
- */
-
- /** Whether the service is running */
- public boolean isRunning() {
- return is_running;
- }
-
- /**
- * Sets the maximum time that the UDP service can remain active after been
- * halted
- */
- public void setSoTimeout(int timeout) {
- socket_timeout = timeout;
- }
-
- /**
- * Gets the maximum time that the UDP service can remain active after been
- * halted
- */
- public int getSoTimeout() {
- return socket_timeout;
- }
-
- /**
- * Sets the minimum size for received packets. Packets shorter than that are
- * silently discarded.
- */
- public void setMinimumReceivedDataLength(int len) {
- minimum_length = len;
- }
-
- /**
- * Gets the minimum size for received packets. Packets shorter than that are
- * silently discarded.
- */
- public int getMinimumReceivedDataLength() {
- return minimum_length;
- }
-
- /** Sends a UdpPacket */
- public void send(UdpPacket packet) throws IOException {
- if (!stop)
- socket.send(packet);
- }
-
- /** Stops running */
- public void halt() {
- stop = true;
- socket.close(); // modified
- }
-
- /** The main thread */
- public void run() {
- byte[] buf = new byte[BUFFER_SIZE];
- UdpPacket packet = new UdpPacket(buf, buf.length);
-
- Exception error = null;
- long expire = 0;
- if (alive_time > 0)
- expire = System.currentTimeMillis() + alive_time;
- try {
-// socket.setSoTimeout(socket_timeout); modified
- // loop
- while (!stop) {
- try {
- socket.receive(packet);
- } catch (InterruptedIOException ie) {
- if (alive_time > 0 && System.currentTimeMillis() > expire)
- halt();
- continue;
- }
- if (packet.getLength() >= minimum_length) {
- if (listener != null)
- listener.onReceivedPacket(this, packet);
- if (alive_time > 0)
- expire = System.currentTimeMillis() + alive_time;
- }
- packet = new UdpPacket(buf, buf.length);
- }
- } catch (Exception e) {
- error = e;
- stop = true;
- }
- is_running = false;
- if (listener != null)
- listener.onServiceTerminated(this, error);
- listener = null;
- }
-
- /** Gets a String representation of the Object */
- public String toString() {
- return "udp:" + socket.getLocalAddress() + ":" + socket.getLocalPort();
- }
-
-}
+/*
+ * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
+ * Copyright (C) 2009 The Sipdroid Open Source Project
+ *
+ * This file is part of MjSip (http://www.mjsip.org)
+ *
+ * MjSip is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * MjSip is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MjSip; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author(s):
+ * Luca Veltri (luca.veltri@unipr.it)
+ */
+
+package org.zoolu.net;
+
+import java.io.IOException;
+import java.io.InterruptedIOException;
+
+/**
+ * UdpProvider provides an UDP send/receive service. On the receiver side it
+ * waits for UDP datagrams and passes them to the UdpProviderListener.
+ *
+ * If the attribute alive_time has a non-zero value, the UdpProvider
+ * stops after alive_time milliseconds of inactivity.
+ *
+ * When a new packet is received, the
+ * onReceivedPacket(UdpProvider,DatagramPacket) method is fired.
+ *
+ * Method onServiceTerminated(UdpProvider) is fired when the the UdpProvider
+ * stops receiving packets.
+ */
+public class UdpProvider extends Thread {
+ /** The reading buffer size */
+ public static final int BUFFER_SIZE = 65535;
+
+ /**
+ * Default value for the maximum time that the UDP receiver can remain
+ * active after been halted (in milliseconds)
+ */
+ public static final int DEFAULT_SOCKET_TIMEOUT = 2000; // 2sec
+
+ /** UDP socket */
+ UdpSocket socket;
+
+ /**
+ * Maximum time that the UDP receiver can remain active after been halted
+ * (in milliseconds)
+ */
+ int socket_timeout;
+
+ /**
+ * Maximum time that the UDP receiver remains active without receiving UDP
+ * datagrams (in milliseconds)
+ */
+ long alive_time;
+
+ /**
+ * Minimum size for received packets. Shorter packets are silently
+ * discarded.
+ */
+ int minimum_length;
+
+ /** Whether it has been halted */
+ boolean stop;
+
+ /** Whether it is running */
+ boolean is_running;
+
+ /** UdpProvider listener */
+ UdpProviderListener listener;
+
+ /** Creates a new UdpProvider */
+ public UdpProvider(UdpSocket socket, UdpProviderListener listener) {
+ init(socket, 0, listener);
+ start();
+ }
+
+ /** Creates a new UdpProvider */
+ public UdpProvider(UdpSocket socket, long alive_time,
+ UdpProviderListener listener) {
+ init(socket, alive_time, listener);
+ start();
+ }
+
+ /** Inits the UdpProvider */
+ private void init(UdpSocket socket, long alive_time,
+ UdpProviderListener listener) {
+ this.listener = listener;
+ this.socket = socket;
+ this.socket_timeout = DEFAULT_SOCKET_TIMEOUT;
+ this.alive_time = alive_time;
+ this.minimum_length = 0;
+ this.stop = false;
+ this.is_running = true;
+ }
+
+ /** Gets the UdpSocket */
+ public UdpSocket getUdpSocket() {
+ return socket;
+ }
+
+ /** Sets a new UdpSocket */
+ /*
+ * public void setUdpSocket(UdpSocket socket) { this.socket=socket; }
+ */
+
+ /** Whether the service is running */
+ public boolean isRunning() {
+ return is_running;
+ }
+
+ /**
+ * Sets the maximum time that the UDP service can remain active after been
+ * halted
+ */
+ public void setSoTimeout(int timeout) {
+ socket_timeout = timeout;
+ }
+
+ /**
+ * Gets the maximum time that the UDP service can remain active after been
+ * halted
+ */
+ public int getSoTimeout() {
+ return socket_timeout;
+ }
+
+ /**
+ * Sets the minimum size for received packets. Packets shorter than that are
+ * silently discarded.
+ */
+ public void setMinimumReceivedDataLength(int len) {
+ minimum_length = len;
+ }
+
+ /**
+ * Gets the minimum size for received packets. Packets shorter than that are
+ * silently discarded.
+ */
+ public int getMinimumReceivedDataLength() {
+ return minimum_length;
+ }
+
+ /** Sends a UdpPacket */
+ public void send(UdpPacket packet) throws IOException {
+ if (!stop)
+ socket.send(packet);
+ }
+
+ /** Stops running */
+ public void halt() {
+ stop = true;
+ socket.close(); // modified
+ }
+
+ /** The main thread */
+ public void run() {
+ byte[] buf = new byte[BUFFER_SIZE];
+ UdpPacket packet = new UdpPacket(buf, buf.length);
+
+ Exception error = null;
+ long expire = 0;
+ if (alive_time > 0)
+ expire = System.currentTimeMillis() + alive_time;
+ try {
+// socket.setSoTimeout(socket_timeout); modified
+ // loop
+ while (!stop) {
+ try {
+ socket.receive(packet);
+ } catch (InterruptedIOException ie) {
+ if (alive_time > 0 && System.currentTimeMillis() > expire)
+ halt();
+ continue;
+ }
+ if (packet.getLength() >= minimum_length) {
+ if (listener != null)
+ listener.onReceivedPacket(this, packet);
+ if (alive_time > 0)
+ expire = System.currentTimeMillis() + alive_time;
+ }
+ packet = new UdpPacket(buf, buf.length);
+ }
+ } catch (Exception e) {
+ error = e;
+ stop = true;
+ }
+ is_running = false;
+ if (listener != null)
+ listener.onServiceTerminated(this, error);
+ listener = null;
+ }
+
+ /** Gets a String representation of the Object */
+ public String toString() {
+ return "udp:" + socket.getLocalAddress() + ":" + socket.getLocalPort();
+ }
+
+}
diff --git a/src/org/zoolu/net/UdpProviderListener.java b/app/src/main/java/org/zoolu/net/UdpProviderListener.java
similarity index 97%
rename from src/org/zoolu/net/UdpProviderListener.java
rename to app/src/main/java/org/zoolu/net/UdpProviderListener.java
index 337f750..1e6ae37 100644
--- a/src/org/zoolu/net/UdpProviderListener.java
+++ b/app/src/main/java/org/zoolu/net/UdpProviderListener.java
@@ -1,35 +1,35 @@
-/*
- * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
- *
- * This file is part of MjSip (http://www.mjsip.org)
- *
- * MjSip is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * MjSip is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with MjSip; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author(s):
- * Luca Veltri (luca.veltri@unipr.it)
- */
-
-package org.zoolu.net;
-
-/**
- * Listener for UdpProvider events.
- */
-public interface UdpProviderListener {
- /** When a new UDP datagram is received. */
- public void onReceivedPacket(UdpProvider udp, UdpPacket packet);
-
- /** When UdpProvider terminates. */
- public void onServiceTerminated(UdpProvider udp, Exception error);
-}
+/*
+ * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
+ *
+ * This file is part of MjSip (http://www.mjsip.org)
+ *
+ * MjSip is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * MjSip is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MjSip; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author(s):
+ * Luca Veltri (luca.veltri@unipr.it)
+ */
+
+package org.zoolu.net;
+
+/**
+ * Listener for UdpProvider events.
+ */
+public interface UdpProviderListener {
+ /** When a new UDP datagram is received. */
+ public void onReceivedPacket(UdpProvider udp, UdpPacket packet);
+
+ /** When UdpProvider terminates. */
+ public void onServiceTerminated(UdpProvider udp, Exception error);
+}
diff --git a/src/org/zoolu/net/UdpSocket.java b/app/src/main/java/org/zoolu/net/UdpSocket.java
similarity index 96%
rename from src/org/zoolu/net/UdpSocket.java
rename to app/src/main/java/org/zoolu/net/UdpSocket.java
index 31fafb8..3914d4d 100644
--- a/src/org/zoolu/net/UdpSocket.java
+++ b/app/src/main/java/org/zoolu/net/UdpSocket.java
@@ -1,104 +1,104 @@
-/*
- * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
- *
- * This file is part of MjSip (http://www.mjsip.org)
- *
- * MjSip is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * MjSip is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with MjSip; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author(s):
- * Luca Veltri (luca.veltri@unipr.it)
- */
-
-package org.zoolu.net;
-
-import java.net.DatagramSocket;
-import java.net.DatagramPacket;
-
-/**
- * UdpSocket provides a uniform interface to UDP transport protocol, regardless
- * J2SE or J2ME is used.
- */
-public class UdpSocket {
-
- /** DatagramSocket */
- DatagramSocket socket;
-
- /** Creates a new UdpSocket */
- public UdpSocket() throws java.net.SocketException {
- socket = new DatagramSocket();
- }
-
- /** Creates a new UdpSocket */
- public UdpSocket(int port) throws java.net.SocketException {
- socket = new DatagramSocket(port);
- }
-
- /** Creates a new UdpSocket */
- UdpSocket(DatagramSocket sock) {
- socket = sock;
- }
-
- /** Creates a new UdpSocket */
- public UdpSocket(int port, IpAddress ipaddr)
- throws java.net.SocketException {
- socket = new DatagramSocket(port, ipaddr.getInetAddress());
- }
-
- /** Closes this datagram socket. */
- public void close() {
- socket.close();
- }
-
- /** Gets the local address to which the socket is bound. */
- public IpAddress getLocalAddress() {
- return new IpAddress(socket.getInetAddress());
- }
-
- /** Gets the port number on the local host to which this socket is bound. */
- public int getLocalPort() {
- return socket.getLocalPort();
- }
-
- /** Gets the socket timeout. */
- public int getSoTimeout() throws java.net.SocketException {
- return socket.getSoTimeout();
- }
-
- /**
- * Enables/disables socket timeout with the specified timeout, in
- * milliseconds.
- */
- public void setSoTimeout(int timeout) throws java.net.SocketException {
- socket.setSoTimeout(timeout);
- }
-
- /** Receives a datagram packet from this socket. */
- public void receive(UdpPacket pkt) throws java.io.IOException {
- DatagramPacket dgram = pkt.getDatagramPacket();
- socket.receive(dgram);
- pkt.setDatagramPacket(dgram);
- }
-
- /** Sends an UDP packet from this socket. */
- public void send(UdpPacket pkt) throws java.io.IOException {
- socket.send(pkt.getDatagramPacket());
- }
-
- /** Converts this object to a String. */
- public String toString() {
- return socket.toString();
- }
-
-}
+/*
+ * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
+ *
+ * This file is part of MjSip (http://www.mjsip.org)
+ *
+ * MjSip is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * MjSip is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MjSip; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author(s):
+ * Luca Veltri (luca.veltri@unipr.it)
+ */
+
+package org.zoolu.net;
+
+import java.net.DatagramSocket;
+import java.net.DatagramPacket;
+
+/**
+ * UdpSocket provides a uniform interface to UDP transport protocol, regardless
+ * J2SE or J2ME is used.
+ */
+public class UdpSocket {
+
+ /** DatagramSocket */
+ DatagramSocket socket;
+
+ /** Creates a new UdpSocket */
+ public UdpSocket() throws java.net.SocketException {
+ socket = new DatagramSocket();
+ }
+
+ /** Creates a new UdpSocket */
+ public UdpSocket(int port) throws java.net.SocketException {
+ socket = new DatagramSocket(port);
+ }
+
+ /** Creates a new UdpSocket */
+ UdpSocket(DatagramSocket sock) {
+ socket = sock;
+ }
+
+ /** Creates a new UdpSocket */
+ public UdpSocket(int port, IpAddress ipaddr)
+ throws java.net.SocketException {
+ socket = new DatagramSocket(port, ipaddr.getInetAddress());
+ }
+
+ /** Closes this datagram socket. */
+ public void close() {
+ socket.close();
+ }
+
+ /** Gets the local address to which the socket is bound. */
+ public IpAddress getLocalAddress() {
+ return new IpAddress(socket.getInetAddress());
+ }
+
+ /** Gets the port number on the local host to which this socket is bound. */
+ public int getLocalPort() {
+ return socket.getLocalPort();
+ }
+
+ /** Gets the socket timeout. */
+ public int getSoTimeout() throws java.net.SocketException {
+ return socket.getSoTimeout();
+ }
+
+ /**
+ * Enables/disables socket timeout with the specified timeout, in
+ * milliseconds.
+ */
+ public void setSoTimeout(int timeout) throws java.net.SocketException {
+ socket.setSoTimeout(timeout);
+ }
+
+ /** Receives a datagram packet from this socket. */
+ public void receive(UdpPacket pkt) throws java.io.IOException {
+ DatagramPacket dgram = pkt.getDatagramPacket();
+ socket.receive(dgram);
+ pkt.setDatagramPacket(dgram);
+ }
+
+ /** Sends an UDP packet from this socket. */
+ public void send(UdpPacket pkt) throws java.io.IOException {
+ socket.send(pkt.getDatagramPacket());
+ }
+
+ /** Converts this object to a String. */
+ public String toString() {
+ return socket.toString();
+ }
+
+}
diff --git a/src/org/zoolu/sdp/AttributeField.java b/app/src/main/java/org/zoolu/sdp/AttributeField.java
similarity index 96%
rename from src/org/zoolu/sdp/AttributeField.java
rename to app/src/main/java/org/zoolu/sdp/AttributeField.java
index 173ec4b..e6a643a 100644
--- a/src/org/zoolu/sdp/AttributeField.java
+++ b/app/src/main/java/org/zoolu/sdp/AttributeField.java
@@ -1,76 +1,76 @@
-/*
- * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
- *
- * This file is part of MjSip (http://www.mjsip.org)
- *
- * MjSip is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * MjSip is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with MjSip; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author(s):
- * Luca Veltri (luca.veltri@unipr.it)
- * Nitin Khanna, Hughes Systique Corp. (Reason: Android specific change, optmization, bug fix)
- */
-
-package org.zoolu.sdp;
-
-/* HSC CHANGE START */
-/* import org.zoolu.tools.Parser; */
-/* HSC CHANGE END */
-
-/**
- * SDP attribute field.
- *
- *
- *
- *
- * attribute-fields = "a=" (att-field ":" att-value) | att-field CRLF
- *
- *
- *
- */
-public class AttributeField extends SdpField {
- /** Creates a new AttributeField. */
- public AttributeField(String attribute) {
- super('a', attribute);
- }
-
- /** Creates a new AttributeField. */
- public AttributeField(String attribute, String a_value) {
- super('a', attribute + ":" + a_value);
- }
-
- /** Creates a new AttributeField. */
- public AttributeField(SdpField sf) {
- super(sf);
- }
-
- /** Gets the attribute name. */
- public String getAttributeName() {
- int i = value.indexOf(":");
- if (i < 0)
- return value;
- else
- return value.substring(0, i);
- }
-
- /** Gets the attribute value. */
- public String getAttributeValue() {
- int i = value.indexOf(":");
- if (i < 0)
- return null;
- else
- return value.substring(i + 1);
- }
-
-}
+/*
+ * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
+ *
+ * This file is part of MjSip (http://www.mjsip.org)
+ *
+ * MjSip is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * MjSip is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MjSip; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author(s):
+ * Luca Veltri (luca.veltri@unipr.it)
+ * Nitin Khanna, Hughes Systique Corp. (Reason: Android specific change, optmization, bug fix)
+ */
+
+package org.zoolu.sdp;
+
+/* HSC CHANGE START */
+/* import org.zoolu.tools.Parser; */
+/* HSC CHANGE END */
+
+/**
+ * SDP attribute field.
+ *
+ *
+ *
+ *
+ * attribute-fields = "a=" (att-field ":" att-value) | att-field CRLF
+ *
+ *
+ *
+ */
+public class AttributeField extends SdpField {
+ /** Creates a new AttributeField. */
+ public AttributeField(String attribute) {
+ super('a', attribute);
+ }
+
+ /** Creates a new AttributeField. */
+ public AttributeField(String attribute, String a_value) {
+ super('a', attribute + ":" + a_value);
+ }
+
+ /** Creates a new AttributeField. */
+ public AttributeField(SdpField sf) {
+ super(sf);
+ }
+
+ /** Gets the attribute name. */
+ public String getAttributeName() {
+ int i = value.indexOf(":");
+ if (i < 0)
+ return value;
+ else
+ return value.substring(0, i);
+ }
+
+ /** Gets the attribute value. */
+ public String getAttributeValue() {
+ int i = value.indexOf(":");
+ if (i < 0)
+ return null;
+ else
+ return value.substring(i + 1);
+ }
+
+}
diff --git a/src/org/zoolu/sdp/ConnectionField.java b/app/src/main/java/org/zoolu/sdp/ConnectionField.java
similarity index 96%
rename from src/org/zoolu/sdp/ConnectionField.java
rename to app/src/main/java/org/zoolu/sdp/ConnectionField.java
index 18c59a7..0e53da3 100644
--- a/src/org/zoolu/sdp/ConnectionField.java
+++ b/app/src/main/java/org/zoolu/sdp/ConnectionField.java
@@ -1,112 +1,112 @@
-/*
- * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
- *
- * This file is part of MjSip (http://www.mjsip.org)
- *
- * MjSip is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * MjSip is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with MjSip; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author(s):
- * Luca Veltri (luca.veltri@unipr.it)
- */
-
-package org.zoolu.sdp;
-
-import org.zoolu.tools.Parser;
-
-/**
- * SDP connection field.
- *
- *
- *
- *
- * connection-field = "c=" nettype SP addrtype SP connection-address CRLF
- * ;a connection field must be present
- * ;in every media description or at the
- * ;session-level
- *
- *
- *
- */
-public class ConnectionField extends SdpField {
- /** Creates a new ConnectionField. */
- public ConnectionField(String connection_field) {
- super('c', connection_field);
- }
-
- /** Creates a new ConnectionField. */
- public ConnectionField(String address_type, String address, int ttl, int num) {
- super('c', null);
- value = "IN " + address_type + " " + address;
- if (ttl > 0)
- value += "/" + ttl;
- if (num > 0)
- value += "/" + num;
- }
-
- /** Creates a new ConnectionField. */
- public ConnectionField(String address_type, String address) {
- super('c', "IN " + address_type + " " + address);
- }
-
- /** Creates a new ConnectionField. */
- public ConnectionField(SdpField sf) {
- super(sf);
- }
-
- /** Gets the connection address. */
- public String getAddressType() {
- String type = (new Parser(value)).skipString().getString();
- return type;
- }
-
- /** Gets the connection address. */
- public String getAddress() {
- String address = (new Parser(value)).skipString().skipString()
- .getString();
- int i = address.indexOf("/");
- if (i < 0)
- return address;
- else
- return address.substring(0, i);
- }
-
- /** Gets the TTL. */
- public int getTTL() {
- String address = (new Parser(value)).skipString().skipString()
- .getString();
- int i = address.indexOf("/");
- if (i < 0)
- return 0;
- int j = address.indexOf("/", i);
- if (j < 0)
- return Integer.parseInt(address.substring(i));
- else
- return Integer.parseInt(address.substring(i, j));
- }
-
- /** Gets the number of addresses. */
- public int getNum() {
- String address = (new Parser(value)).skipString().skipString()
- .getString();
- int i = address.indexOf("/");
- if (i < 0)
- return 0;
- int j = address.indexOf("/", i);
- if (j < 0)
- return 0;
- return Integer.parseInt(address.substring(j));
- }
-
-}
+/*
+ * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
+ *
+ * This file is part of MjSip (http://www.mjsip.org)
+ *
+ * MjSip is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * MjSip is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MjSip; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author(s):
+ * Luca Veltri (luca.veltri@unipr.it)
+ */
+
+package org.zoolu.sdp;
+
+import org.zoolu.tools.Parser;
+
+/**
+ * SDP connection field.
+ *
+ *
+ *
+ *
+ * connection-field = "c=" nettype SP addrtype SP connection-address CRLF
+ * ;a connection field must be present
+ * ;in every media description or at the
+ * ;session-level
+ *
+ *
+ *
+ */
+public class ConnectionField extends SdpField {
+ /** Creates a new ConnectionField. */
+ public ConnectionField(String connection_field) {
+ super('c', connection_field);
+ }
+
+ /** Creates a new ConnectionField. */
+ public ConnectionField(String address_type, String address, int ttl, int num) {
+ super('c', null);
+ value = "IN " + address_type + " " + address;
+ if (ttl > 0)
+ value += "/" + ttl;
+ if (num > 0)
+ value += "/" + num;
+ }
+
+ /** Creates a new ConnectionField. */
+ public ConnectionField(String address_type, String address) {
+ super('c', "IN " + address_type + " " + address);
+ }
+
+ /** Creates a new ConnectionField. */
+ public ConnectionField(SdpField sf) {
+ super(sf);
+ }
+
+ /** Gets the connection address. */
+ public String getAddressType() {
+ String type = (new Parser(value)).skipString().getString();
+ return type;
+ }
+
+ /** Gets the connection address. */
+ public String getAddress() {
+ String address = (new Parser(value)).skipString().skipString()
+ .getString();
+ int i = address.indexOf("/");
+ if (i < 0)
+ return address;
+ else
+ return address.substring(0, i);
+ }
+
+ /** Gets the TTL. */
+ public int getTTL() {
+ String address = (new Parser(value)).skipString().skipString()
+ .getString();
+ int i = address.indexOf("/");
+ if (i < 0)
+ return 0;
+ int j = address.indexOf("/", i);
+ if (j < 0)
+ return Integer.parseInt(address.substring(i));
+ else
+ return Integer.parseInt(address.substring(i, j));
+ }
+
+ /** Gets the number of addresses. */
+ public int getNum() {
+ String address = (new Parser(value)).skipString().skipString()
+ .getString();
+ int i = address.indexOf("/");
+ if (i < 0)
+ return 0;
+ int j = address.indexOf("/", i);
+ if (j < 0)
+ return 0;
+ return Integer.parseInt(address.substring(j));
+ }
+
+}
diff --git a/src/org/zoolu/sdp/MediaDescriptor.java b/app/src/main/java/org/zoolu/sdp/MediaDescriptor.java
similarity index 96%
rename from src/org/zoolu/sdp/MediaDescriptor.java
rename to app/src/main/java/org/zoolu/sdp/MediaDescriptor.java
index f28dd8e..f2795db 100644
--- a/src/org/zoolu/sdp/MediaDescriptor.java
+++ b/app/src/main/java/org/zoolu/sdp/MediaDescriptor.java
@@ -1,308 +1,308 @@
-/*
- * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
- * Copyright (C) 2010 The Sipdroid Open Source Project
- *
- * This file is part of MjSip (http://www.mjsip.org)
- *
- * MjSip is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * MjSip is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with MjSip; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author(s):
- * Luca Veltri (luca.veltri@unipr.it)
- * Nitin Khanna, Hughes Systique Corp. (Reason: Android specific change, optmization, bug fix)
- */
-
-package org.zoolu.sdp;
-
-import java.util.Vector;
-
-/**
- * Class MediaDescriptor handles SDP media descpriptions.
- *
- * A MediaDescriptor can be part of a SessionDescriptor, and contains details
- * that apply onto to a single media stream.
- *
- * A single SessionDescriptor may convey zero or more MediaDescriptors.
- *
- * In the current implementation, the MediaDescriptor consists of the m (media)
- * and c (connection information) fields, followed by zero or more a (attribute)
- * fields. The m field is mandatory for a MediaDescriptor.
- */
-public class MediaDescriptor {
- /** Media field ('m'). */
- MediaField m;
- /** Connection field ('c') */
- ConnectionField c;
- /** Vector of attribute fileds ('a') */
- /* HSC CHANGE STARTS */
- Vector av;
-
- /* HSC CHANGE ENDS */
-
- /**
- * Creates a new MediaDescriptor.
- *
- * @param md
- * the cloned MediaDescriptor
- */
- public MediaDescriptor(MediaDescriptor md) {
- m = new MediaField(md.m);
- if (md.c != null)
- c = new ConnectionField(md.c);
- else
- c = null;
- /* HSC CHANGE STARTS */
- av = new Vector();
- /* HSC CHANGE ENDS */
- for (int i = 0; i < md.av.size(); i++) {
- av.addElement(new AttributeField((AttributeField) md.av
- .elementAt(i)));
- }
- }
-
- /**
- * Creates a new MediaDescriptor with m media and c connection.
- * No attribute is set by default.
- *
- * @param media
- * the MediaField
- * @param connection
- * the ConnectionField, or null if no ConnectionField is present
- * in the MediaDescriptor
- */
- public MediaDescriptor(MediaField media, ConnectionField connection) {
- m = media;
- c = connection;
- /* HSC CHANGE BEGINS */
- av = new Vector();
- /* HSC CHANGE ENDS */
- }
-
- /**
- * Creates a new MediaDescriptor with m media, c connection,
- * and a attribute.
- *
- * @param media
- * the MediaField
- * @param connection
- * the ConnectionField, or null if no ConnectionField is present
- * in the MediaDescriptor
- * @param attribute
- * the first AttributeField
- */
- public MediaDescriptor(MediaField media, ConnectionField connection,
- AttributeField attribute) {
- m = media;
- c = connection;
- /* HSC CHANGE BEGINS */
- av = new Vector();
- /* HSC CHANGE ENDS */
- if (attribute != null)
- av.addElement(attribute);
- }
-
- /**
- * Creates a new MediaDescriptor with m=media and c=connection,
- * with attributes 'a' equals to attributes (Vector of
- * AttributeField).
- *
- * @param media
- * the MediaField
- * @param connection
- * the ConnectionField, or null if no ConnectionField is present
- * in the MediaDescriptor
- * @param attributes
- * the Vector of AttributeField
- */
- /* HSC CHANGE BEGINS */
- public MediaDescriptor(MediaField media, ConnectionField connection,
- Vector attributes) {
- m = media;
- c = connection;
- av = new Vector(attributes.size());
- av.setSize(attributes.size());
- for (int i = 0; i < attributes.size(); i++)
- av.setElementAt((AttributeField) attributes.elementAt(i), i);
- }
-
- /* HSC CHANGE ENDS */
-
- /**
- * Creates a new MediaDescriptor with m media, c connection,
- * and a attribute.
- *
- * @param media
- * the media field vaule
- * @param connection
- * the connection field vaule, or null if no connection field is
- * present in the MediaDescriptor
- * @param attribute
- * the first media attribute alue
- */
- public MediaDescriptor(String media, String connection, String attribute) {
- m = new MediaField(media);
- if (connection != null)
- c = new ConnectionField(connection);
- /* HSC CHANGE BEGINS */
- av = new Vector();
- /* HSC CHANGE ENDS */
- if (attribute != null)
- av.addElement(new AttributeField(attribute));
- }
-
- /**
- * Creates a new MediaDescriptor from String str.
- *
- * @param str
- * the media field line
- */
- /*
- * public MediaDescriptor(String str) { SdpParser par=new SdpParser(str);
- * m=par.parseMediaField(); c=par.parseConnectionField(); av=new Vector();
- * AttributeField a=par.parseAttributeField(); while (a!=null) {
- * av.addElement(a); a=par.parseAttributeField(); } }
- */
-
- /**
- * Gets media.
- *
- * @return the MediaField
- */
- public MediaField getMedia() {
- return m;
- }
-
- /**
- * Gets connection information.
- *
- * @return the ConnectionField
- */
- public ConnectionField getConnection() {
- return c;
- }
-
- /**
- * Gets a Vector of attribute values.
- *
- * @return a Vector of AttributeField
- */
- /* HSC CHANGE BEGINS */
- public Vector getAttributes() {
- Vector v = new Vector(av.size());
- /* HSC CHANGE ENDS */
- for (int i = 0; i < av.size(); i++)
- v.addElement((AttributeField) av.elementAt(i));
- return v;
- }
-
- /**
- * Adds a new attribute
- *
- * @param attribute
- * the new AttributeField
- * @return this MediaDescriptor
- */
- public MediaDescriptor addAttribute(AttributeField attribute) {
- av.addElement(new AttributeField(attribute));
- return this;
- }
-
- /**
- * Whether it has a particular attribute
- *
- * @param a_name
- * the attribute name
- * @return true if found, otherwise returns null
- */
- public boolean hasAttribute(String a_name) {
- for (int i = 0; i < av.size(); i++) {
- if (((AttributeField) av.elementAt(i)).getAttributeName().equals(
- a_name))
- return true;
- }
- return false;
- }
-
- /**
- * Gets a particular attribute
- *
- * @param a_name
- * the attribute name
- * @return the AttributeField, or null if not found
- */
- public AttributeField getAttribute(String a_name) {
- for (int i = 0; i < av.size(); i++) {
- AttributeField a = (AttributeField) av.elementAt(i);
- if (a.getAttributeName().equals(a_name))
- return a;
- }
- return null;
- }
-
- /**
- * Gets a Vector of attribute values of a particular attribute name.
- *
- * @param a_name
- * the attribute name
- * @return a Vector of AttributeFields
- */
- /* HSC CHANGE BEGINS */
- public Vector getAttributes(String a_name) {
- Vector v = new Vector(av.size());
- /* HSC CHANGE ENDS */
- for (int i = 0; i < av.size(); i++) {
- AttributeField a = (AttributeField) av.elementAt(i);
- if (a.getAttributeName().equals(a_name))
- v.addElement(a);
- }
- return v;
- }
-
- /**
- * Returns whether a particular codec is included in the media descriptor.
- *
- * @param codec
- * the codec name (e.g. "GSM", "PCMA/8000")
- * @return a String of the matched codec (e.g. "GSM/8000"),
- * or null when the codec is not included.
- */
- public String hasCodec(String codec) {
- for (int i = 0; i < av.size(); i++) {
- AttributeField a = (AttributeField) av.elementAt(i);
- if (a.getAttributeName().equalsIgnoreCase("rtpmap")) {
- String[] ar = a.getAttributeValue().split(" +", 2);
- if (ar.length==2 && ar[1].toLowerCase().startsWith(codec.toLowerCase())) {
- return ar[1];
- }
- }
- }
- return null;
- }
-
- /**
- * Gets a String rapresentation of the MediaDescriptor.
- *
- * @return the string representation
- */
- public String toString() {
- String str = "";
- str += m;
- if (c != null)
- str += c;
- for (int i = 0; i < av.size(); i++)
- str += (AttributeField) av.elementAt(i);
- return str;
- }
-
-}
+/*
+ * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
+ * Copyright (C) 2010 The Sipdroid Open Source Project
+ *
+ * This file is part of MjSip (http://www.mjsip.org)
+ *
+ * MjSip is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * MjSip is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MjSip; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author(s):
+ * Luca Veltri (luca.veltri@unipr.it)
+ * Nitin Khanna, Hughes Systique Corp. (Reason: Android specific change, optmization, bug fix)
+ */
+
+package org.zoolu.sdp;
+
+import java.util.Vector;
+
+/**
+ * Class MediaDescriptor handles SDP media descpriptions.
+ *
+ * A MediaDescriptor can be part of a SessionDescriptor, and contains details
+ * that apply onto to a single media stream.
+ *
+ * A single SessionDescriptor may convey zero or more MediaDescriptors.
+ *
+ * In the current implementation, the MediaDescriptor consists of the m (media)
+ * and c (connection information) fields, followed by zero or more a (attribute)
+ * fields. The m field is mandatory for a MediaDescriptor.
+ */
+public class MediaDescriptor {
+ /** Media field ('m'). */
+ MediaField m;
+ /** Connection field ('c') */
+ ConnectionField c;
+ /** Vector of attribute fileds ('a') */
+ /* HSC CHANGE STARTS */
+ Vector av;
+
+ /* HSC CHANGE ENDS */
+
+ /**
+ * Creates a new MediaDescriptor.
+ *
+ * @param md
+ * the cloned MediaDescriptor
+ */
+ public MediaDescriptor(MediaDescriptor md) {
+ m = new MediaField(md.m);
+ if (md.c != null)
+ c = new ConnectionField(md.c);
+ else
+ c = null;
+ /* HSC CHANGE STARTS */
+ av = new Vector();
+ /* HSC CHANGE ENDS */
+ for (int i = 0; i < md.av.size(); i++) {
+ av.addElement(new AttributeField((AttributeField) md.av
+ .elementAt(i)));
+ }
+ }
+
+ /**
+ * Creates a new MediaDescriptor with m media and c connection.
+ * No attribute is set by default.
+ *
+ * @param media
+ * the MediaField
+ * @param connection
+ * the ConnectionField, or null if no ConnectionField is present
+ * in the MediaDescriptor
+ */
+ public MediaDescriptor(MediaField media, ConnectionField connection) {
+ m = media;
+ c = connection;
+ /* HSC CHANGE BEGINS */
+ av = new Vector();
+ /* HSC CHANGE ENDS */
+ }
+
+ /**
+ * Creates a new MediaDescriptor with m media, c connection,
+ * and a attribute.
+ *
+ * @param media
+ * the MediaField
+ * @param connection
+ * the ConnectionField, or null if no ConnectionField is present
+ * in the MediaDescriptor
+ * @param attribute
+ * the first AttributeField
+ */
+ public MediaDescriptor(MediaField media, ConnectionField connection,
+ AttributeField attribute) {
+ m = media;
+ c = connection;
+ /* HSC CHANGE BEGINS */
+ av = new Vector();
+ /* HSC CHANGE ENDS */
+ if (attribute != null)
+ av.addElement(attribute);
+ }
+
+ /**
+ * Creates a new MediaDescriptor with m=media and c=connection,
+ * with attributes 'a' equals to attributes (Vector of
+ * AttributeField).
+ *
+ * @param media
+ * the MediaField
+ * @param connection
+ * the ConnectionField, or null if no ConnectionField is present
+ * in the MediaDescriptor
+ * @param attributes
+ * the Vector of AttributeField
+ */
+ /* HSC CHANGE BEGINS */
+ public MediaDescriptor(MediaField media, ConnectionField connection,
+ Vector attributes) {
+ m = media;
+ c = connection;
+ av = new Vector(attributes.size());
+ av.setSize(attributes.size());
+ for (int i = 0; i < attributes.size(); i++)
+ av.setElementAt((AttributeField) attributes.elementAt(i), i);
+ }
+
+ /* HSC CHANGE ENDS */
+
+ /**
+ * Creates a new MediaDescriptor with m media, c connection,
+ * and a attribute.
+ *
+ * @param media
+ * the media field vaule
+ * @param connection
+ * the connection field vaule, or null if no connection field is
+ * present in the MediaDescriptor
+ * @param attribute
+ * the first media attribute alue
+ */
+ public MediaDescriptor(String media, String connection, String attribute) {
+ m = new MediaField(media);
+ if (connection != null)
+ c = new ConnectionField(connection);
+ /* HSC CHANGE BEGINS */
+ av = new Vector();
+ /* HSC CHANGE ENDS */
+ if (attribute != null)
+ av.addElement(new AttributeField(attribute));
+ }
+
+ /**
+ * Creates a new MediaDescriptor from String str.
+ *
+ * @param str
+ * the media field line
+ */
+ /*
+ * public MediaDescriptor(String str) { SdpParser par=new SdpParser(str);
+ * m=par.parseMediaField(); c=par.parseConnectionField(); av=new Vector();
+ * AttributeField a=par.parseAttributeField(); while (a!=null) {
+ * av.addElement(a); a=par.parseAttributeField(); } }
+ */
+
+ /**
+ * Gets media.
+ *
+ * @return the MediaField
+ */
+ public MediaField getMedia() {
+ return m;
+ }
+
+ /**
+ * Gets connection information.
+ *
+ * @return the ConnectionField
+ */
+ public ConnectionField getConnection() {
+ return c;
+ }
+
+ /**
+ * Gets a Vector of attribute values.
+ *
+ * @return a Vector of AttributeField
+ */
+ /* HSC CHANGE BEGINS */
+ public Vector getAttributes() {
+ Vector v = new Vector(av.size());
+ /* HSC CHANGE ENDS */
+ for (int i = 0; i < av.size(); i++)
+ v.addElement((AttributeField) av.elementAt(i));
+ return v;
+ }
+
+ /**
+ * Adds a new attribute
+ *
+ * @param attribute
+ * the new AttributeField
+ * @return this MediaDescriptor
+ */
+ public MediaDescriptor addAttribute(AttributeField attribute) {
+ av.addElement(new AttributeField(attribute));
+ return this;
+ }
+
+ /**
+ * Whether it has a particular attribute
+ *
+ * @param a_name
+ * the attribute name
+ * @return true if found, otherwise returns null
+ */
+ public boolean hasAttribute(String a_name) {
+ for (int i = 0; i < av.size(); i++) {
+ if (((AttributeField) av.elementAt(i)).getAttributeName().equals(
+ a_name))
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Gets a particular attribute
+ *
+ * @param a_name
+ * the attribute name
+ * @return the AttributeField, or null if not found
+ */
+ public AttributeField getAttribute(String a_name) {
+ for (int i = 0; i < av.size(); i++) {
+ AttributeField a = (AttributeField) av.elementAt(i);
+ if (a.getAttributeName().equals(a_name))
+ return a;
+ }
+ return null;
+ }
+
+ /**
+ * Gets a Vector of attribute values of a particular attribute name.
+ *
+ * @param a_name
+ * the attribute name
+ * @return a Vector of AttributeFields
+ */
+ /* HSC CHANGE BEGINS */
+ public Vector getAttributes(String a_name) {
+ Vector v = new Vector(av.size());
+ /* HSC CHANGE ENDS */
+ for (int i = 0; i < av.size(); i++) {
+ AttributeField a = (AttributeField) av.elementAt(i);
+ if (a.getAttributeName().equals(a_name))
+ v.addElement(a);
+ }
+ return v;
+ }
+
+ /**
+ * Returns whether a particular codec is included in the media descriptor.
+ *
+ * @param codec
+ * the codec name (e.g. "GSM", "PCMA/8000")
+ * @return a String of the matched codec (e.g. "GSM/8000"),
+ * or null when the codec is not included.
+ */
+ public String hasCodec(String codec) {
+ for (int i = 0; i < av.size(); i++) {
+ AttributeField a = (AttributeField) av.elementAt(i);
+ if (a.getAttributeName().equalsIgnoreCase("rtpmap")) {
+ String[] ar = a.getAttributeValue().split(" +", 2);
+ if (ar.length==2 && ar[1].toLowerCase().startsWith(codec.toLowerCase())) {
+ return ar[1];
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Gets a String rapresentation of the MediaDescriptor.
+ *
+ * @return the string representation
+ */
+ public String toString() {
+ String str = "";
+ str += m;
+ if (c != null)
+ str += c;
+ for (int i = 0; i < av.size(); i++)
+ str += (AttributeField) av.elementAt(i);
+ return str;
+ }
+
+}
diff --git a/src/org/zoolu/sdp/MediaField.java b/app/src/main/java/org/zoolu/sdp/MediaField.java
similarity index 96%
rename from src/org/zoolu/sdp/MediaField.java
rename to app/src/main/java/org/zoolu/sdp/MediaField.java
index b0fe17d..f613be2 100644
--- a/src/org/zoolu/sdp/MediaField.java
+++ b/app/src/main/java/org/zoolu/sdp/MediaField.java
@@ -1,122 +1,122 @@
-/*
- * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
- *
- * This file is part of MjSip (http://www.mjsip.org)
- *
- * MjSip is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * MjSip is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with MjSip; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author(s):
- * Luca Veltri (luca.veltri@unipr.it)
- * Nitin Khanna, Hughes Systique Corp. (Reason: Android specific change, optmization, bug fix)
- */
-
-package org.zoolu.sdp;
-
-import org.zoolu.tools.Parser;
-import java.util.Vector;
-
-/**
- * SDP media field.
- *
- *
- *
- *
- * media-field = "m=" media SP port ["/" integer] SP proto 1*(SP fmt) CRLF
- *
- *
- *
- */
-public class MediaField extends SdpField {
- /** Creates a new MediaField. */
- public MediaField(String media_field) {
- super('m', media_field);
- }
-
- /** Creates a new MediaField. */
- public MediaField(String media, int port, int num, String transport,
- String formats) {
- super('m', null);
- value = media + " " + port;
- if (num > 0)
- value += "/" + num;
- value += " " + transport + " " + formats;
- }
-
- /**
- * Creates a new MediaField.
- *
- * @param formatlist
- * a Vector of media formats (properly a Vector of Strings)
- */
- public MediaField(String media, int port, int num, String transport,
- /* HSC CHANGE BEGINS */
- Vector formatlist) {
- /* HSC CHANGE ENDS */
- super('m', null);
- value = media + " " + port;
- if (num > 0)
- value += "/" + num;
- value += " " + transport;
- for (int i = 0; i < formatlist.size(); i++)
- value += " " + formatlist.elementAt(i);
- }
-
- /** Creates a new SdpField. */
- public MediaField(SdpField sf) {
- super(sf);
- }
-
- /** Gets the media type. */
- public String getMedia() {
- return new Parser(value).getString();
- }
-
- /** Gets the media port. */
- public int getPort() {
- String port = (new Parser(value)).skipString().getString();
- int i = port.indexOf('/');
- if (i < 0)
- return Integer.parseInt(port);
- else
- return Integer.parseInt(port.substring(0, i));
- }
-
- /** Gets the transport protocol. */
- public String getTransport() {
- return (new Parser(value)).skipString().skipString().getString();
- }
-
- /** Gets the media formats. */
- public String getFormats() {
- return (new Parser(value)).skipString().skipString().skipString()
- .skipWSP().getRemainingString();
- }
-
- /** Gets the media formats as a Vector of String. */
- /* HSC CHANGE BEGINS */
- public Vector getFormatList() {
- Vector formatlist = new Vector();
- /* HSC CHANGE ENDS */
- Parser par = new Parser(value);
- par.skipString().skipString().skipString();
- while (par.hasMore()) {
- String fmt = par.getString();
- if (fmt != null && fmt.length() > 0)
- formatlist.addElement(fmt);
- }
- return formatlist;
- }
-
-}
+/*
+ * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
+ *
+ * This file is part of MjSip (http://www.mjsip.org)
+ *
+ * MjSip is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * MjSip is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MjSip; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author(s):
+ * Luca Veltri (luca.veltri@unipr.it)
+ * Nitin Khanna, Hughes Systique Corp. (Reason: Android specific change, optmization, bug fix)
+ */
+
+package org.zoolu.sdp;
+
+import org.zoolu.tools.Parser;
+import java.util.Vector;
+
+/**
+ * SDP media field.
+ *
+ *
+ *
+ *
+ * media-field = "m=" media SP port ["/" integer] SP proto 1*(SP fmt) CRLF
+ *
+ *
+ *
+ */
+public class MediaField extends SdpField {
+ /** Creates a new MediaField. */
+ public MediaField(String media_field) {
+ super('m', media_field);
+ }
+
+ /** Creates a new MediaField. */
+ public MediaField(String media, int port, int num, String transport,
+ String formats) {
+ super('m', null);
+ value = media + " " + port;
+ if (num > 0)
+ value += "/" + num;
+ value += " " + transport + " " + formats;
+ }
+
+ /**
+ * Creates a new MediaField.
+ *
+ * @param formatlist
+ * a Vector of media formats (properly a Vector of Strings)
+ */
+ public MediaField(String media, int port, int num, String transport,
+ /* HSC CHANGE BEGINS */
+ Vector formatlist) {
+ /* HSC CHANGE ENDS */
+ super('m', null);
+ value = media + " " + port;
+ if (num > 0)
+ value += "/" + num;
+ value += " " + transport;
+ for (int i = 0; i < formatlist.size(); i++)
+ value += " " + formatlist.elementAt(i);
+ }
+
+ /** Creates a new SdpField. */
+ public MediaField(SdpField sf) {
+ super(sf);
+ }
+
+ /** Gets the media type. */
+ public String getMedia() {
+ return new Parser(value).getString();
+ }
+
+ /** Gets the media port. */
+ public int getPort() {
+ String port = (new Parser(value)).skipString().getString();
+ int i = port.indexOf('/');
+ if (i < 0)
+ return Integer.parseInt(port);
+ else
+ return Integer.parseInt(port.substring(0, i));
+ }
+
+ /** Gets the transport protocol. */
+ public String getTransport() {
+ return (new Parser(value)).skipString().skipString().getString();
+ }
+
+ /** Gets the media formats. */
+ public String getFormats() {
+ return (new Parser(value)).skipString().skipString().skipString()
+ .skipWSP().getRemainingString();
+ }
+
+ /** Gets the media formats as a Vector of String. */
+ /* HSC CHANGE BEGINS */
+ public Vector getFormatList() {
+ Vector formatlist = new Vector();
+ /* HSC CHANGE ENDS */
+ Parser par = new Parser(value);
+ par.skipString().skipString().skipString();
+ while (par.hasMore()) {
+ String fmt = par.getString();
+ if (fmt != null && fmt.length() > 0)
+ formatlist.addElement(fmt);
+ }
+ return formatlist;
+ }
+
+}
diff --git a/src/org/zoolu/sdp/OriginField.java b/app/src/main/java/org/zoolu/sdp/OriginField.java
similarity index 96%
rename from src/org/zoolu/sdp/OriginField.java
rename to app/src/main/java/org/zoolu/sdp/OriginField.java
index 9f0d2e9..2164510 100644
--- a/src/org/zoolu/sdp/OriginField.java
+++ b/app/src/main/java/org/zoolu/sdp/OriginField.java
@@ -1,92 +1,92 @@
-/*
- * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
- *
- * This file is part of MjSip (http://www.mjsip.org)
- *
- * MjSip is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * MjSip is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with MjSip; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author(s):
- * Luca Veltri (luca.veltri@unipr.it)
- */
-
-package org.zoolu.sdp;
-
-import org.zoolu.tools.Parser;
-
-/**
- * SDP origin field.
- *
- *
- *
- *
- * origin-field = "o=" username SP sess-id SP sess-version SP
- * nettype SP addrtype SP unicast-address CRLF
- *
- *
- *
- */
-public class OriginField extends SdpField {
- /** Creates a new OriginField. */
- public OriginField(String origin) {
- super('o', origin);
- }
-
- /** Creates a new OriginField. */
- public OriginField(String username, String sess_id, String sess_version,
- String addrtype, String address) {
- super('o', username + " " + sess_id + " " + sess_version + " IN "
- + addrtype + " " + address);
- }
-
- /** Creates a new OriginField. */
- public OriginField(String username, String sess_id, String sess_version,
- String address) {
- super('o', username + " " + sess_id + " " + sess_version + " IN IP4 "
- + address);
- }
-
- /** Creates a new OriginField. */
- public OriginField(SdpField sf) {
- super(sf);
- }
-
- /** Gets the user name. */
- public String getUserName() {
- return (new Parser(value)).getString();
- }
-
- /** Gets the session id. */
- public String getSessionId() {
- return (new Parser(value)).skipString().getString();
- }
-
- /** Gets the session version. */
- public String getSessionVersion() {
- return (new Parser(value)).skipString().skipString().getString();
- }
-
- /** Gets the address type. */
- public String getAddressType() {
- return (new Parser(value)).skipString().skipString().skipString()
- .skipString().getString();
- }
-
- /** Gets the address. */
- public String getAddress() {
- return (new Parser(value)).skipString().skipString().skipString()
- .skipString().skipString().getString();
- }
-
-}
+/*
+ * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
+ *
+ * This file is part of MjSip (http://www.mjsip.org)
+ *
+ * MjSip is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * MjSip is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MjSip; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author(s):
+ * Luca Veltri (luca.veltri@unipr.it)
+ */
+
+package org.zoolu.sdp;
+
+import org.zoolu.tools.Parser;
+
+/**
+ * SDP origin field.
+ *
+ *
+ *
+ *
+ * origin-field = "o=" username SP sess-id SP sess-version SP
+ * nettype SP addrtype SP unicast-address CRLF
+ *
+ *
+ *
+ */
+public class OriginField extends SdpField {
+ /** Creates a new OriginField. */
+ public OriginField(String origin) {
+ super('o', origin);
+ }
+
+ /** Creates a new OriginField. */
+ public OriginField(String username, String sess_id, String sess_version,
+ String addrtype, String address) {
+ super('o', username + " " + sess_id + " " + sess_version + " IN "
+ + addrtype + " " + address);
+ }
+
+ /** Creates a new OriginField. */
+ public OriginField(String username, String sess_id, String sess_version,
+ String address) {
+ super('o', username + " " + sess_id + " " + sess_version + " IN IP4 "
+ + address);
+ }
+
+ /** Creates a new OriginField. */
+ public OriginField(SdpField sf) {
+ super(sf);
+ }
+
+ /** Gets the user name. */
+ public String getUserName() {
+ return (new Parser(value)).getString();
+ }
+
+ /** Gets the session id. */
+ public String getSessionId() {
+ return (new Parser(value)).skipString().getString();
+ }
+
+ /** Gets the session version. */
+ public String getSessionVersion() {
+ return (new Parser(value)).skipString().skipString().getString();
+ }
+
+ /** Gets the address type. */
+ public String getAddressType() {
+ return (new Parser(value)).skipString().skipString().skipString()
+ .skipString().getString();
+ }
+
+ /** Gets the address. */
+ public String getAddress() {
+ return (new Parser(value)).skipString().skipString().skipString()
+ .skipString().skipString().getString();
+ }
+
+}
diff --git a/src/org/zoolu/sdp/SdpField.java b/app/src/main/java/org/zoolu/sdp/SdpField.java
similarity index 95%
rename from src/org/zoolu/sdp/SdpField.java
rename to app/src/main/java/org/zoolu/sdp/SdpField.java
index 56eb8f0..a853464 100644
--- a/src/org/zoolu/sdp/SdpField.java
+++ b/app/src/main/java/org/zoolu/sdp/SdpField.java
@@ -1,129 +1,129 @@
-/*
- * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
- *
- * This file is part of MjSip (http://www.mjsip.org)
- *
- * MjSip is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * MjSip is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with MjSip; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author(s):
- * Luca Veltri (luca.veltri@unipr.it)
- */
-
-package org.zoolu.sdp;
-
-/**
- * SdpField rapresents a SDP line field. It is formed by a 'type' (char) and a
- * 'value' (String).
- *
- * A SDP line field is of the form <type> = <value>
- */
-public class SdpField {
- char type;
- String value;
-
- /**
- * Creates a new SdpField.
- *
- * @param s_type
- * the field type
- * @param s_value
- * the field value
- */
- public SdpField(char s_type, String s_value) {
- type = s_type;
- value = s_value;
- }
-
- /**
- * Creates a new SdpField.
- *
- * @param sf
- * the SdpField clone
- */
- public SdpField(SdpField sf) {
- type = sf.type;
- value = sf.value;
- }
-
- /**
- * Creates a new SdpField based on a SDP line of the form =.
- * The SDP value terminats with the end of the String or with the first CR
- * or LF char.
- *
- * @param str
- * the <type> = <value> line
- */
- public SdpField(String str) {
- SdpParser par = new SdpParser(str);
- SdpField sf = par.parseSdpField();
- type = sf.type;
- value = sf.value;
- }
-
- /**
- * Creates and returns a copy of the SdpField.
- *
- * @return a SdpField clone
- */
- public Object clone() {
- return new SdpField(this);
- }
-
- /**
- * Whether the SdpField is equal to Object obj
- *
- * @return true if equal
- */
- public boolean equals(Object obj) {
- try {
- SdpField sf = (SdpField) obj;
- if (type != sf.type)
- return false;
- if (value != sf.value)
- return false;
- return true;
- } catch (Exception e) {
- return false;
- }
- }
-
- /**
- * Gets the type of field
- *
- * @return the field type
- */
- public char getType() {
- return type;
- }
-
- /**
- * Gets the value
- *
- * @return the field value
- */
- public String getValue() {
- return value;
- }
-
- /**
- * Gets string representation of the SdpField
- *
- * @return the string representation
- */
- public String toString() {
- return type + "=" + value + "\r\n";
- }
-
-}
+/*
+ * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
+ *
+ * This file is part of MjSip (http://www.mjsip.org)
+ *
+ * MjSip is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * MjSip is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MjSip; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author(s):
+ * Luca Veltri (luca.veltri@unipr.it)
+ */
+
+package org.zoolu.sdp;
+
+/**
+ * SdpField rapresents a SDP line field. It is formed by a 'type' (char) and a
+ * 'value' (String).
+ *
+ * A SDP line field is of the form <type> = <value>
+ */
+public class SdpField {
+ char type;
+ String value;
+
+ /**
+ * Creates a new SdpField.
+ *
+ * @param s_type
+ * the field type
+ * @param s_value
+ * the field value
+ */
+ public SdpField(char s_type, String s_value) {
+ type = s_type;
+ value = s_value;
+ }
+
+ /**
+ * Creates a new SdpField.
+ *
+ * @param sf
+ * the SdpField clone
+ */
+ public SdpField(SdpField sf) {
+ type = sf.type;
+ value = sf.value;
+ }
+
+ /**
+ * Creates a new SdpField based on a SDP line of the form =.
+ * The SDP value terminats with the end of the String or with the first CR
+ * or LF char.
+ *
+ * @param str
+ * the <type> = <value> line
+ */
+ public SdpField(String str) {
+ SdpParser par = new SdpParser(str);
+ SdpField sf = par.parseSdpField();
+ type = sf.type;
+ value = sf.value;
+ }
+
+ /**
+ * Creates and returns a copy of the SdpField.
+ *
+ * @return a SdpField clone
+ */
+ public Object clone() {
+ return new SdpField(this);
+ }
+
+ /**
+ * Whether the SdpField is equal to Object obj
+ *
+ * @return true if equal
+ */
+ public boolean equals(Object obj) {
+ try {
+ SdpField sf = (SdpField) obj;
+ if (type != sf.type)
+ return false;
+ if (value != sf.value)
+ return false;
+ return true;
+ } catch (Exception e) {
+ return false;
+ }
+ }
+
+ /**
+ * Gets the type of field
+ *
+ * @return the field type
+ */
+ public char getType() {
+ return type;
+ }
+
+ /**
+ * Gets the value
+ *
+ * @return the field value
+ */
+ public String getValue() {
+ return value;
+ }
+
+ /**
+ * Gets string representation of the SdpField
+ *
+ * @return the string representation
+ */
+ public String toString() {
+ return type + "=" + value + "\r\n";
+ }
+
+}
diff --git a/src/org/zoolu/sdp/SdpParser.java b/app/src/main/java/org/zoolu/sdp/SdpParser.java
similarity index 96%
rename from src/org/zoolu/sdp/SdpParser.java
rename to app/src/main/java/org/zoolu/sdp/SdpParser.java
index e541cc0..7b8a7ae 100644
--- a/src/org/zoolu/sdp/SdpParser.java
+++ b/app/src/main/java/org/zoolu/sdp/SdpParser.java
@@ -1,227 +1,227 @@
-/*
- * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
- *
- * This file is part of MjSip (http://www.mjsip.org)
- *
- * MjSip is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * MjSip is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with MjSip; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author(s):
- * Luca Veltri (luca.veltri@unipr.it)
- * Nitin Khanna, Hughes Systique Corp. (Reason: Android specific change, optmization, bug fix)
- */
-
-package org.zoolu.sdp;
-
-/* HSC CHANGE STARTS */
-// import org.zoolu.sdp.*;
-/* HSC CHANGE ENDS */
-import org.zoolu.tools.Parser;
-import java.util.Vector;
-
-/**
- * Class SdpParser extends class Parser for parsing of SDP strings.
- */
-class SdpParser extends Parser {
- /** Creates a SdpParser based on String s */
- public SdpParser(String s) {
- super(s);
- }
-
- /**
- * Creates a SdpParser based on String s and starting from position
- * i
- */
- public SdpParser(String s, int i) {
- super(s, i);
- }
-
- /**
- * Returns the SdpField at the current position. The SDP value terminates
- * with the end of the String or with the first CR or LF char.
- *
- * Returns null if no SdpField is recognized.
- */
- /*
- * public SdpField parseSdpField() { Parser par=new Parser(str,index); while
- * (par.length()>1 && par.charAt(1)!='=') par.goToNextLine(); if
- * (!par.hasMore()) return null; char type=par.getChar(); par.skipChar();
- * String value=par.skipChar().getLine(); if (value==null) return null;
- * index=par.getPos(); // for DEBUG //System.out.println("DEBUG:
- * "+type+"="+value); return new SdpField(type,value); }
- */
-
- /**
- * Returns the first SdpField. The SDP value terminates with the end of the
- * String or with the first CR or LF char.
- *
- * @return the first SdpField, or null if no SdpField is recognized.
- */
- public SdpField parseSdpField() {
- int begin = index;
- while (begin >= 0 && begin < str.length() - 1
- && str.charAt(begin + 1) != '=')
- begin = str.indexOf("\n", begin);
- if (begin < 0)
- return null;
- char type = str.charAt(begin);
- begin += 2;
- int end = str.length();
- int CR = str.indexOf('\r', begin);
- if (CR > 0 && CR < end)
- end = CR;
- int LF = str.indexOf('\n', begin);
- if (LF > 0 && LF < end)
- end = LF;
- String value = str.substring(begin, end).trim();
- if (value == null)
- return null;
- setPos(end);
- goToNextLine();
- // for DEBUG
- // System.out.println("DEBUG: "+type+"="+value);
- return new SdpField(type, value);
- }
-
- /**
- * Returns the first SdpField of type type. The SDP value terminates
- * with the end of the String or with the first CR or LF char.
- *
- * @return the first SdpField, or null if no type SdpField is found.
- */
- public SdpField parseSdpField(char type) {
- int begin = 0;
- if (!str.startsWith(type + "=", index)) {
- begin = str.indexOf("\n" + type + "=", index);
- // if (begin<0) begin=str.indexOf("\r"+type+"=",index);
- if (begin < 0) { // return null if no type SdpField has been
- // found
- return null;
- }
- index = begin + 1;
- }
- return parseSdpField();
- }
-
- /**
- * Returns the first OriginField.
- *
- * @return the first OriginField, or null if no OriginField is found.
- */
- public OriginField parseOriginField() {
- SdpField sf = parseSdpField('o');
- if (sf != null)
- return new OriginField(sf);
- else
- return null;
- }
-
- /**
- * Returns the first MediaField.
- *
- * @return the first MediaField, or null if no MediaField is found.
- */
- public MediaField parseMediaField() {
- SdpField sf = parseSdpField('m');
- if (sf != null)
- return new MediaField(sf);
- else
- return null;
- }
-
- /**
- * Returns the first ConnectionField.
- *
- * @return the first ConnectionField, or null if no ConnectionField is
- * found.
- */
- public ConnectionField parseConnectionField() {
- SdpField sf = parseSdpField('c');
- if (sf != null)
- return new ConnectionField(sf);
- else
- return null;
- }
-
- /**
- * Returns the first SessionNameField.
- *
- * @return the first SessionNameField, or null if no SessionNameField is
- * found.
- */
- public SessionNameField parseSessionNameField() {
- SdpField sf = parseSdpField('s');
- if (sf != null)
- return new SessionNameField(sf);
- else
- return null;
- }
-
- /**
- * Returns the first TimeField.
- *
- * @return the first TimeField, or null if no TimeField is found.
- */
- public TimeField parseTimeField() {
- SdpField sf = parseSdpField('t');
- if (sf != null)
- return new TimeField(sf);
- else
- return null;
- }
-
- /**
- * Returns the first AttributeField.
- *
- * @return the first AttributeField, or null if no AttributeField is found.
- */
- public AttributeField parseAttributeField() {
- SdpField sf = parseSdpField('a');
- if (sf != null)
- return new AttributeField(sf);
- else
- return null;
- }
-
- /**
- * Returns the first MediaDescriptor.
- *
- * @return the first MediaDescriptor, or null if no MediaDescriptor is
- * found.
- */
- public MediaDescriptor parseMediaDescriptor() {
- MediaField m = parseMediaField();
- if (m == null)
- return null;
- int begin = index;
- int end = str.indexOf("\nm", begin);
- if (end < 0)
- end = str.length();
- else
- end++;
- index = end;
- SdpParser par = new SdpParser(str.substring(begin, end));
- ConnectionField c = par.parseConnectionField();
- /* HSC CHANGE BEGINS */
- Vector av = new Vector();
- /* HSC CHANGE ENDS */
- AttributeField a = par.parseAttributeField();
- while (a != null) {
- av.addElement(a);
- a = par.parseAttributeField();
- }
- return new MediaDescriptor(m, c, av);
- }
-
-}
+/*
+ * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
+ *
+ * This file is part of MjSip (http://www.mjsip.org)
+ *
+ * MjSip is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * MjSip is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MjSip; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author(s):
+ * Luca Veltri (luca.veltri@unipr.it)
+ * Nitin Khanna, Hughes Systique Corp. (Reason: Android specific change, optmization, bug fix)
+ */
+
+package org.zoolu.sdp;
+
+/* HSC CHANGE STARTS */
+// import org.zoolu.sdp.*;
+/* HSC CHANGE ENDS */
+import org.zoolu.tools.Parser;
+import java.util.Vector;
+
+/**
+ * Class SdpParser extends class Parser for parsing of SDP strings.
+ */
+class SdpParser extends Parser {
+ /** Creates a SdpParser based on String s */
+ public SdpParser(String s) {
+ super(s);
+ }
+
+ /**
+ * Creates a SdpParser based on String s and starting from position
+ * i
+ */
+ public SdpParser(String s, int i) {
+ super(s, i);
+ }
+
+ /**
+ * Returns the SdpField at the current position. The SDP value terminates
+ * with the end of the String or with the first CR or LF char.
+ *
+ * Returns null if no SdpField is recognized.
+ */
+ /*
+ * public SdpField parseSdpField() { Parser par=new Parser(str,index); while
+ * (par.length()>1 && par.charAt(1)!='=') par.goToNextLine(); if
+ * (!par.hasMore()) return null; char type=par.getChar(); par.skipChar();
+ * String value=par.skipChar().getLine(); if (value==null) return null;
+ * index=par.getPos(); // for DEBUG //System.out.println("DEBUG:
+ * "+type+"="+value); return new SdpField(type,value); }
+ */
+
+ /**
+ * Returns the first SdpField. The SDP value terminates with the end of the
+ * String or with the first CR or LF char.
+ *
+ * @return the first SdpField, or null if no SdpField is recognized.
+ */
+ public SdpField parseSdpField() {
+ int begin = index;
+ while (begin >= 0 && begin < str.length() - 1
+ && str.charAt(begin + 1) != '=')
+ begin = str.indexOf("\n", begin);
+ if (begin < 0)
+ return null;
+ char type = str.charAt(begin);
+ begin += 2;
+ int end = str.length();
+ int CR = str.indexOf('\r', begin);
+ if (CR > 0 && CR < end)
+ end = CR;
+ int LF = str.indexOf('\n', begin);
+ if (LF > 0 && LF < end)
+ end = LF;
+ String value = str.substring(begin, end).trim();
+ if (value == null)
+ return null;
+ setPos(end);
+ goToNextLine();
+ // for DEBUG
+ // System.out.println("DEBUG: "+type+"="+value);
+ return new SdpField(type, value);
+ }
+
+ /**
+ * Returns the first SdpField of type type. The SDP value terminates
+ * with the end of the String or with the first CR or LF char.
+ *
+ * @return the first SdpField, or null if no type SdpField is found.
+ */
+ public SdpField parseSdpField(char type) {
+ int begin = 0;
+ if (!str.startsWith(type + "=", index)) {
+ begin = str.indexOf("\n" + type + "=", index);
+ // if (begin<0) begin=str.indexOf("\r"+type+"=",index);
+ if (begin < 0) { // return null if no type SdpField has been
+ // found
+ return null;
+ }
+ index = begin + 1;
+ }
+ return parseSdpField();
+ }
+
+ /**
+ * Returns the first OriginField.
+ *
+ * @return the first OriginField, or null if no OriginField is found.
+ */
+ public OriginField parseOriginField() {
+ SdpField sf = parseSdpField('o');
+ if (sf != null)
+ return new OriginField(sf);
+ else
+ return null;
+ }
+
+ /**
+ * Returns the first MediaField.
+ *
+ * @return the first MediaField, or null if no MediaField is found.
+ */
+ public MediaField parseMediaField() {
+ SdpField sf = parseSdpField('m');
+ if (sf != null)
+ return new MediaField(sf);
+ else
+ return null;
+ }
+
+ /**
+ * Returns the first ConnectionField.
+ *
+ * @return the first ConnectionField, or null if no ConnectionField is
+ * found.
+ */
+ public ConnectionField parseConnectionField() {
+ SdpField sf = parseSdpField('c');
+ if (sf != null)
+ return new ConnectionField(sf);
+ else
+ return null;
+ }
+
+ /**
+ * Returns the first SessionNameField.
+ *
+ * @return the first SessionNameField, or null if no SessionNameField is
+ * found.
+ */
+ public SessionNameField parseSessionNameField() {
+ SdpField sf = parseSdpField('s');
+ if (sf != null)
+ return new SessionNameField(sf);
+ else
+ return null;
+ }
+
+ /**
+ * Returns the first TimeField.
+ *
+ * @return the first TimeField, or null if no TimeField is found.
+ */
+ public TimeField parseTimeField() {
+ SdpField sf = parseSdpField('t');
+ if (sf != null)
+ return new TimeField(sf);
+ else
+ return null;
+ }
+
+ /**
+ * Returns the first AttributeField.
+ *
+ * @return the first AttributeField, or null if no AttributeField is found.
+ */
+ public AttributeField parseAttributeField() {
+ SdpField sf = parseSdpField('a');
+ if (sf != null)
+ return new AttributeField(sf);
+ else
+ return null;
+ }
+
+ /**
+ * Returns the first MediaDescriptor.
+ *
+ * @return the first MediaDescriptor, or null if no MediaDescriptor is
+ * found.
+ */
+ public MediaDescriptor parseMediaDescriptor() {
+ MediaField m = parseMediaField();
+ if (m == null)
+ return null;
+ int begin = index;
+ int end = str.indexOf("\nm", begin);
+ if (end < 0)
+ end = str.length();
+ else
+ end++;
+ index = end;
+ SdpParser par = new SdpParser(str.substring(begin, end));
+ ConnectionField c = par.parseConnectionField();
+ /* HSC CHANGE BEGINS */
+ Vector av = new Vector();
+ /* HSC CHANGE ENDS */
+ AttributeField a = par.parseAttributeField();
+ while (a != null) {
+ av.addElement(a);
+ a = par.parseAttributeField();
+ }
+ return new MediaDescriptor(m, c, av);
+ }
+
+}
diff --git a/src/org/zoolu/sdp/SessionDescriptor.java b/app/src/main/java/org/zoolu/sdp/SessionDescriptor.java
similarity index 96%
rename from src/org/zoolu/sdp/SessionDescriptor.java
rename to app/src/main/java/org/zoolu/sdp/SessionDescriptor.java
index f152da6..9f15d39 100644
--- a/src/org/zoolu/sdp/SessionDescriptor.java
+++ b/app/src/main/java/org/zoolu/sdp/SessionDescriptor.java
@@ -1,526 +1,526 @@
-/*
- * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
- * Copyright (C) 2009 The Sipdroid Open Source Project
- *
- * This file is part of MjSip (http://www.mjsip.org)
- *
- * MjSip is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * MjSip is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with MjSip; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author(s):
- * Luca Veltri (luca.veltri@unipr.it)
- * Nitin Khanna, Hughes Systique Corp. (Reason: Android specific change, optmization, bug fix)
- */
-
-package org.zoolu.sdp;
-
-import java.util.Vector;
-
-import org.zoolu.net.IpAddress;
-
-/* HSC CHANGE STARTS */
-// import java.util.Enumeration;
-// PersonalJava
-// import java.util.HashSet;
-// import java.util.Iterator;
-// import org.zoolu.tools.HashSet;
-// import org.zoolu.tools.Iterator;
-/* HSC CHANGE ENDS */
-
-/**
- * Class SessionDescriptor handles SIP message bodys formatted according to the
- * Session Description Protocol (SDP).
- *
- * A session description consists of a session-level description (details that
- * apply to the whole session and all media streams) and zero or more
- * media-level descriptions (details that apply onto to a single media stream).
- *
- * The session-level part starts with a `v=' line and continues to the first
- * media-level section. The media description starts with an `m=' line and
- * continues to the next media description or end of the whole session
- * description. In general, session-level values are the default for all media
- * unless overridden by an equivalent media-level value.
- *
- * In the current implementation, the session-level description consists of the
- * v, o, s, c, and t SDP fields (lines).
- */
-public class SessionDescriptor {
- /** Version filed. */
- SdpField v;
- /** Origin filed. */
- OriginField o;
- /** Session-name filed. */
- SessionNameField s;
- /** Connection filed. */
- ConnectionField c;
- /** Time filed. */
- TimeField t;
-
- /** Vector of session attributes (as Vector of SdpFields). */
- /* HSC CHANGE STARTS */
- Vector av;
- /* HSC CHANGE ENDS */
-
- /** Vector of MediaDescriptors. */
- /* HSC CHANGE STARTS */
- Vector media;
-
- /* HSC CHANGE ENDS */
-
- /*
- * private void init(String owner, String session, String connection, String
- * time) { v=new SdpField('v',"0"); o=new SdpField('o',owner); s=new
- * SdpField('s',session); c=new SdpField('c',connection); t=new
- * SdpField('t',time); media=new HashSet(); }
- */
-
- /** Inits the SessionDescriptor. */
- private void init(OriginField origin, SessionNameField session,
- ConnectionField connection, TimeField time) {
- v = new SdpField('v', "0");
- o = origin;
- s = session;
- c = connection;
- t = time;
- /* HSC CHANGE STARTS */
- av = new Vector();
- media = new Vector();
- /* HSC CHANGE ENDS */
- }
-
- /**
- * Creates a new SessionDescriptor.
- *
- * @param sd
- * the SessionDescriptor clone
- */
- public SessionDescriptor(SessionDescriptor sd) {
- init(new OriginField(sd.o), new SessionNameField(sd.s),
- new ConnectionField(sd.c), new TimeField(sd.t));
- for (int i = 0; i < sd.media.size(); i++)
- media.addElement(new MediaDescriptor((MediaDescriptor) sd.media
- .elementAt(i)));
- }
-
- /**
- * Creates a new SessionDescriptor specifing o, s, c, and t fields.
- *
- * @param origin
- * the OriginField
- * @param session
- * the SessionNameField
- * @param connection
- * the ConnectionField
- * @param time
- * the TimeField
- */
- public SessionDescriptor(OriginField origin, SessionNameField session,
- ConnectionField connection, TimeField time) {
- init(origin, session, connection, time);
- }
-
- /**
- * Creates a new SessionDescriptor specifing o, s, c, and t fields.
- *
- * @param origin
- * the origin value
- * @param session
- * the session value
- * @param connection
- * the connection value
- * @param time
- * the time value
- */
- public SessionDescriptor(String origin, String session, String connection,
- String time) {
- init(new OriginField(origin), new SessionNameField(session),
- new ConnectionField(connection), new TimeField(time));
- }
-
- public void IncrementOLine()
- {
- String str = o.getSessionVersion();
- Integer intObj2 = Integer.valueOf(str);
- intObj2++;
- o = new OriginField(o.getUserName(), o.getSessionId(), Integer.toString(intObj2),o.getAddress());
- }
- /**
- * Creates a new SessionDescriptor.
- *
- * with:
- * o=owner
- * s=Session SIP/SDP
- * c=IP4 address
- * t=0 0
- *
- * if address==null, '127.0.0.1' is used
- * if owner==null, 'user@'address is used
- *
- * @param owner
- * the owner
- * @param address
- * the IPv4 address
- */
- public SessionDescriptor(String owner, String address) {
- if (address == null)
- address = IpAddress.localIpAddress;
- if (owner == null)
- owner = "user@" + address;
- init(new OriginField(owner, "0", "0", address), new SessionNameField(
- "Session SIP/SDP"), new ConnectionField("IP4", address),
- new TimeField());
- }
-
- /**
- * Creates a default SessionDescriptor.
- *
- * o=user@127.0.0.1 s=Session SIP/SDP c=127.0.0.1 t=0 0
- */
- public SessionDescriptor() {
- String address = IpAddress.localIpAddress;
- String owner = "user@" + address;
- init(new OriginField(owner, "0", "0", address), new SessionNameField(
- "Session SIP/SDP"), new ConnectionField("IP4", address),
- new TimeField());
- }
-
- /**
- * Creates a new SessionDescriptor from String sdp
- *
- * @param sdp
- * the entire SDP
- */
- public SessionDescriptor(String sdp) {
- SdpParser par = new SdpParser(sdp);
- // parse mandatory fields
- v = par.parseSdpField('v');
- if (v == null)
- v = new SdpField('v', "0");
- o = par.parseOriginField();
- if (o == null)
- o = new OriginField("unknown");
- s = par.parseSessionNameField();
- if (s == null)
- s = new SessionNameField();
- c = par.parseConnectionField();
- if (c == null)
- c = new ConnectionField("IP4", "0.0.0.0");
- t = par.parseTimeField();
- if (t == null)
- t = new TimeField();
- while (par.hasMore()
- && (!par.startsWith("a=") && !par.startsWith("m="))) { // skip
- // unknown
- // lines..
- par.goToNextLine();
- }
- // parse session attributes
- av = new Vector();
- while (par.hasMore() && par.startsWith("a=")) {
- AttributeField attribute = par.parseAttributeField();
- av.addElement(attribute);
- }
- // parse media descriptors
- media = new Vector();
- MediaDescriptor md;
- while ((md = par.parseMediaDescriptor()) != null) {
- addMediaDescriptor(md);
- }
- }
-
- /**
- * Sets the origin 'o' field.
- *
- * @param origin
- * the OriginField
- * @return this SessionDescriptor
- */
- public SessionDescriptor setOrigin(OriginField origin) {
- o = origin;
- return this;
- }
-
- /** Gets the origin 'o' field */
- public OriginField getOrigin() { // System.out.println("DEBUG: inside
- // SessionDescriptor.getOwner():
- // sdp=\n"+toString());
- return o;
- }
-
- /**
- * Sets the session-name 's' field.
- *
- * @param session
- * the SessionNameField
- * @return this SessionDescriptor
- */
- public SessionDescriptor setSessionName(SessionNameField session) {
- s = session;
- return this;
- }
-
- /** Gets the session-name 's' field */
- public SessionNameField getSessionName() {
- return s;
- }
-
- /**
- * Sets the connection-information 'c' field.
- *
- * @param connection
- * the ConnectionField
- * @return this SessionDescriptor
- */
- public SessionDescriptor setConnection(ConnectionField connection) {
- c = connection;
- return this;
- }
-
- /** Gets the connection-information 'c' field */
- public ConnectionField getConnection() {
- return c;
- }
-
- /**
- * Sets the time 't' field.
- *
- * @param time
- * the TimeField
- * @return this SessionDescriptor
- */
- public SessionDescriptor setTime(TimeField time) {
- t = time;
- return this;
- }
-
- /** Gets the time 't' field */
- public TimeField getTime() {
- return t;
- }
-
- /**
- * Adds a new attribute for a particular media
- *
- * @param media
- * the MediaField
- * @param attribute
- * an AttributeField
- * @return this SessionDescriptor
- */
- public SessionDescriptor addMedia(MediaField media, AttributeField attribute) { // printlog("DEBUG:
- // media:
- // "+media,5);
- // printlog("DEBUG: attribute: "+attribute,5);
- addMediaDescriptor(new MediaDescriptor(media, null, attribute));
- return this;
- }
-
- /**
- * Adds a new media.
- *
- * @param media
- * the MediaField
- * @param attributes
- * Vector of AttributeField
- * @return this SessionDescriptor
- */
- public SessionDescriptor addMedia(MediaField media,
- Vector attributes) {
- // printlog("DEBUG:
- // printlog("DEBUG: attribute: "+attributes,5);
- addMediaDescriptor(new MediaDescriptor(media, null, attributes));
- return this;
- }
-
- /**
- * Adds a new MediaDescriptor
- *
- * @param media_desc
- * a MediaDescriptor
- * @return this SessionDescriptor
- */
- public SessionDescriptor addMediaDescriptor(MediaDescriptor media_desc) { // printlog("DEBUG:
- // media
- // desc:
- // "+media_desc,5);
- media.addElement(media_desc);
- return this;
- }
-
- /**
- * Adds a Vector of MediaDescriptors
- *
- * @param media_descs
- * Vector if MediaDescriptor
- * @return this SessionDescriptor
- */
- public SessionDescriptor addMediaDescriptors(
- Vector media_descs) {
- // media.addAll(media_descs);
- for (int i = 0; i < media_descs.size(); i++)
- media.addElement(media_descs.elementAt(i));
- return this;
- }
-
- /** Gets all MediaDescriptors */
- public Vector getMediaDescriptors() {
- return media;
- }
-
- /** Removes all MediaDescriptors */
- public SessionDescriptor removeMediaDescriptor(String media_type) {
- for (int i = media.size() - 1; i >= 0; i--)
- if (((MediaDescriptor) media.elementAt(i)).getMedia().getMedia()
- .equals(media_type))
- media.removeElementAt(i);
- return this;
- }
-
- /** Removes all MediaDescriptors */
- public SessionDescriptor removeMediaDescriptors() { // media.clear(); // not
- // supported by J2ME..
- media.setSize(0);
- return this;
- }
-
- /**
- * Gets the first MediaDescriptor of a particular media.
- *
- * @param media_type
- * the media type
- * @return the MediaDescriptor
- */
- public MediaDescriptor getMediaDescriptor(String media_type) {
- for (int i = 0; i < media.size(); i++) {
- MediaDescriptor md = (MediaDescriptor) media.elementAt(i);
- if (md.getMedia().getMedia().equals(media_type))
- return md;
- }
- return null;
- }
-
- /**
- * Adds a Vector of session attributes.
- *
- * @param attribute_fields
- * Vector of AttributeFields
- * @return this SessionDescriptor
- */
- public SessionDescriptor addAttributes(
- Vector attribute_fields) {
- for (int i = 0; i < attribute_fields.size(); i++)
- addAttribute(attribute_fields.elementAt(i));
- return this;
- }
-
- /**
- * Adds a new attribute
- *
- * @param attribute
- * the new AttributeField
- * @return this MediaDescriptor
- */
- public SessionDescriptor addAttribute(AttributeField attribute) {
- av.addElement(new AttributeField(attribute));
- return this;
- }
-
- /** Removes all session attributes. */
- public SessionDescriptor removeAttributes() {
- av.setSize(0);
- return this;
- }
-
- /**
- * Gets a Vector of attribute values.
- *
- * @return a Vector of AttributeField
- */
- public Vector getAttributes() {
- Vector v = new Vector(av.size());
- for (int i = 0; i < av.size(); i++)
- v.addElement((AttributeField) av.elementAt(i));
- return v;
- }
-
- /**
- * Whether it has a particular attribute
- *
- * @param a_name
- * the attribute name
- * @return true if found, otherwise returns null
- */
- public boolean hasAttribute(String attribute_name) {
- for (int i = 0; i < av.size(); i++) {
- if (((AttributeField) av.elementAt(i)).getAttributeName().equals(
- attribute_name))
- return true;
- }
- return false;
- }
-
- /**
- * Gets the first AttributeField of a particular attribute name.
- *
- * @param attribute_name
- * the attribute name
- * @return the AttributeField, or null if not found
- */
- public AttributeField getAttribute(String attribute_name) {
- for (int i = 0; i < av.size(); i++) {
- AttributeField af = (AttributeField) av.elementAt(i);
- if (af.getAttributeName().equals(attribute_name))
- return af;
- }
- return null;
- }
-
- /**
- * Gets a Vector of attribute values of a particular attribute name.
- *
- * @param a_name
- * the attribute name
- * @return a Vector of AttributeField
- */
- public Vector getAttributes(String attribute_name) {
- Vector v = new Vector(av.size());
- for (int i = 0; i < av.size(); i++) {
- AttributeField a = (AttributeField) av.elementAt(i);
- if (a.getAttributeName().equals(attribute_name))
- v.addElement(a);
- }
- return v;
- }
-
- /** Gets a String rapresentation */
- public String toString() {
- StringBuffer sb = new StringBuffer();
- if (v != null)
- sb.append(v.toString());
- if (o != null)
- sb.append(o.toString());
- if (s != null)
- sb.append(s.toString());
- if (c != null)
- sb.append(c.toString());
- if (t != null)
- sb.append(t.toString());
- for (int i = 0; i < av.size(); i++)
- sb.append(((AttributeField) av.elementAt(i)).toString());
- for (int i = 0; i < media.size(); i++)
- sb.append(((MediaDescriptor) media.elementAt(i)).toString());
- return sb.toString();
- }
-
-}
+/*
+ * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
+ * Copyright (C) 2009 The Sipdroid Open Source Project
+ *
+ * This file is part of MjSip (http://www.mjsip.org)
+ *
+ * MjSip is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * MjSip is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MjSip; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author(s):
+ * Luca Veltri (luca.veltri@unipr.it)
+ * Nitin Khanna, Hughes Systique Corp. (Reason: Android specific change, optmization, bug fix)
+ */
+
+package org.zoolu.sdp;
+
+import java.util.Vector;
+
+import org.zoolu.net.IpAddress;
+
+/* HSC CHANGE STARTS */
+// import java.util.Enumeration;
+// PersonalJava
+// import java.util.HashSet;
+// import java.util.Iterator;
+// import org.zoolu.tools.HashSet;
+// import org.zoolu.tools.Iterator;
+/* HSC CHANGE ENDS */
+
+/**
+ * Class SessionDescriptor handles SIP message bodys formatted according to the
+ * Session Description Protocol (SDP).
+ *
+ * A session description consists of a session-level description (details that
+ * apply to the whole session and all media streams) and zero or more
+ * media-level descriptions (details that apply onto to a single media stream).
+ *
+ * The session-level part starts with a `v=' line and continues to the first
+ * media-level section. The media description starts with an `m=' line and
+ * continues to the next media description or end of the whole session
+ * description. In general, session-level values are the default for all media
+ * unless overridden by an equivalent media-level value.
+ *
+ * In the current implementation, the session-level description consists of the
+ * v, o, s, c, and t SDP fields (lines).
+ */
+public class SessionDescriptor {
+ /** Version filed. */
+ SdpField v;
+ /** Origin filed. */
+ OriginField o;
+ /** Session-name filed. */
+ SessionNameField s;
+ /** Connection filed. */
+ ConnectionField c;
+ /** Time filed. */
+ TimeField t;
+
+ /** Vector of session attributes (as Vector of SdpFields). */
+ /* HSC CHANGE STARTS */
+ Vector av;
+ /* HSC CHANGE ENDS */
+
+ /** Vector of MediaDescriptors. */
+ /* HSC CHANGE STARTS */
+ Vector media;
+
+ /* HSC CHANGE ENDS */
+
+ /*
+ * private void init(String owner, String session, String connection, String
+ * time) { v=new SdpField('v',"0"); o=new SdpField('o',owner); s=new
+ * SdpField('s',session); c=new SdpField('c',connection); t=new
+ * SdpField('t',time); media=new HashSet(); }
+ */
+
+ /** Inits the SessionDescriptor. */
+ private void init(OriginField origin, SessionNameField session,
+ ConnectionField connection, TimeField time) {
+ v = new SdpField('v', "0");
+ o = origin;
+ s = session;
+ c = connection;
+ t = time;
+ /* HSC CHANGE STARTS */
+ av = new Vector();
+ media = new Vector();
+ /* HSC CHANGE ENDS */
+ }
+
+ /**
+ * Creates a new SessionDescriptor.
+ *
+ * @param sd
+ * the SessionDescriptor clone
+ */
+ public SessionDescriptor(SessionDescriptor sd) {
+ init(new OriginField(sd.o), new SessionNameField(sd.s),
+ new ConnectionField(sd.c), new TimeField(sd.t));
+ for (int i = 0; i < sd.media.size(); i++)
+ media.addElement(new MediaDescriptor((MediaDescriptor) sd.media
+ .elementAt(i)));
+ }
+
+ /**
+ * Creates a new SessionDescriptor specifing o, s, c, and t fields.
+ *
+ * @param origin
+ * the OriginField
+ * @param session
+ * the SessionNameField
+ * @param connection
+ * the ConnectionField
+ * @param time
+ * the TimeField
+ */
+ public SessionDescriptor(OriginField origin, SessionNameField session,
+ ConnectionField connection, TimeField time) {
+ init(origin, session, connection, time);
+ }
+
+ /**
+ * Creates a new SessionDescriptor specifing o, s, c, and t fields.
+ *
+ * @param origin
+ * the origin value
+ * @param session
+ * the session value
+ * @param connection
+ * the connection value
+ * @param time
+ * the time value
+ */
+ public SessionDescriptor(String origin, String session, String connection,
+ String time) {
+ init(new OriginField(origin), new SessionNameField(session),
+ new ConnectionField(connection), new TimeField(time));
+ }
+
+ public void IncrementOLine()
+ {
+ String str = o.getSessionVersion();
+ Integer intObj2 = Integer.valueOf(str);
+ intObj2++;
+ o = new OriginField(o.getUserName(), o.getSessionId(), Integer.toString(intObj2),o.getAddress());
+ }
+ /**
+ * Creates a new SessionDescriptor.
+ *
+ * with:
+ * o=owner
+ * s=Session SIP/SDP
+ * c=IP4 address
+ * t=0 0
+ *
+ * if address==null, '127.0.0.1' is used
+ * if owner==null, 'user@'address is used
+ *
+ * @param owner
+ * the owner
+ * @param address
+ * the IPv4 address
+ */
+ public SessionDescriptor(String owner, String address) {
+ if (address == null)
+ address = IpAddress.localIpAddress;
+ if (owner == null)
+ owner = "user@" + address;
+ init(new OriginField(owner, "0", "0", address), new SessionNameField(
+ "Session SIP/SDP"), new ConnectionField("IP4", address),
+ new TimeField());
+ }
+
+ /**
+ * Creates a default SessionDescriptor.
+ *
+ * o=user@127.0.0.1 s=Session SIP/SDP c=127.0.0.1 t=0 0
+ */
+ public SessionDescriptor() {
+ String address = IpAddress.localIpAddress;
+ String owner = "user@" + address;
+ init(new OriginField(owner, "0", "0", address), new SessionNameField(
+ "Session SIP/SDP"), new ConnectionField("IP4", address),
+ new TimeField());
+ }
+
+ /**
+ * Creates a new SessionDescriptor from String sdp
+ *
+ * @param sdp
+ * the entire SDP
+ */
+ public SessionDescriptor(String sdp) {
+ SdpParser par = new SdpParser(sdp);
+ // parse mandatory fields
+ v = par.parseSdpField('v');
+ if (v == null)
+ v = new SdpField('v', "0");
+ o = par.parseOriginField();
+ if (o == null)
+ o = new OriginField("unknown");
+ s = par.parseSessionNameField();
+ if (s == null)
+ s = new SessionNameField();
+ c = par.parseConnectionField();
+ if (c == null)
+ c = new ConnectionField("IP4", "0.0.0.0");
+ t = par.parseTimeField();
+ if (t == null)
+ t = new TimeField();
+ while (par.hasMore()
+ && (!par.startsWith("a=") && !par.startsWith("m="))) { // skip
+ // unknown
+ // lines..
+ par.goToNextLine();
+ }
+ // parse session attributes
+ av = new Vector();
+ while (par.hasMore() && par.startsWith("a=")) {
+ AttributeField attribute = par.parseAttributeField();
+ av.addElement(attribute);
+ }
+ // parse media descriptors
+ media = new Vector();
+ MediaDescriptor md;
+ while ((md = par.parseMediaDescriptor()) != null) {
+ addMediaDescriptor(md);
+ }
+ }
+
+ /**
+ * Sets the origin 'o' field.
+ *
+ * @param origin
+ * the OriginField
+ * @return this SessionDescriptor
+ */
+ public SessionDescriptor setOrigin(OriginField origin) {
+ o = origin;
+ return this;
+ }
+
+ /** Gets the origin 'o' field */
+ public OriginField getOrigin() { // System.out.println("DEBUG: inside
+ // SessionDescriptor.getOwner():
+ // sdp=\n"+toString());
+ return o;
+ }
+
+ /**
+ * Sets the session-name 's' field.
+ *
+ * @param session
+ * the SessionNameField
+ * @return this SessionDescriptor
+ */
+ public SessionDescriptor setSessionName(SessionNameField session) {
+ s = session;
+ return this;
+ }
+
+ /** Gets the session-name 's' field */
+ public SessionNameField getSessionName() {
+ return s;
+ }
+
+ /**
+ * Sets the connection-information 'c' field.
+ *
+ * @param connection
+ * the ConnectionField
+ * @return this SessionDescriptor
+ */
+ public SessionDescriptor setConnection(ConnectionField connection) {
+ c = connection;
+ return this;
+ }
+
+ /** Gets the connection-information 'c' field */
+ public ConnectionField getConnection() {
+ return c;
+ }
+
+ /**
+ * Sets the time 't' field.
+ *
+ * @param time
+ * the TimeField
+ * @return this SessionDescriptor
+ */
+ public SessionDescriptor setTime(TimeField time) {
+ t = time;
+ return this;
+ }
+
+ /** Gets the time 't' field */
+ public TimeField getTime() {
+ return t;
+ }
+
+ /**
+ * Adds a new attribute for a particular media
+ *
+ * @param media
+ * the MediaField
+ * @param attribute
+ * an AttributeField
+ * @return this SessionDescriptor
+ */
+ public SessionDescriptor addMedia(MediaField media, AttributeField attribute) { // printlog("DEBUG:
+ // media:
+ // "+media,5);
+ // printlog("DEBUG: attribute: "+attribute,5);
+ addMediaDescriptor(new MediaDescriptor(media, null, attribute));
+ return this;
+ }
+
+ /**
+ * Adds a new media.
+ *
+ * @param media
+ * the MediaField
+ * @param attributes
+ * Vector of AttributeField
+ * @return this SessionDescriptor
+ */
+ public SessionDescriptor addMedia(MediaField media,
+ Vector attributes) {
+ // printlog("DEBUG:
+ // printlog("DEBUG: attribute: "+attributes,5);
+ addMediaDescriptor(new MediaDescriptor(media, null, attributes));
+ return this;
+ }
+
+ /**
+ * Adds a new MediaDescriptor
+ *
+ * @param media_desc
+ * a MediaDescriptor
+ * @return this SessionDescriptor
+ */
+ public SessionDescriptor addMediaDescriptor(MediaDescriptor media_desc) { // printlog("DEBUG:
+ // media
+ // desc:
+ // "+media_desc,5);
+ media.addElement(media_desc);
+ return this;
+ }
+
+ /**
+ * Adds a Vector of MediaDescriptors
+ *
+ * @param media_descs
+ * Vector if MediaDescriptor
+ * @return this SessionDescriptor
+ */
+ public SessionDescriptor addMediaDescriptors(
+ Vector media_descs) {
+ // media.addAll(media_descs);
+ for (int i = 0; i < media_descs.size(); i++)
+ media.addElement(media_descs.elementAt(i));
+ return this;
+ }
+
+ /** Gets all MediaDescriptors */
+ public Vector getMediaDescriptors() {
+ return media;
+ }
+
+ /** Removes all MediaDescriptors */
+ public SessionDescriptor removeMediaDescriptor(String media_type) {
+ for (int i = media.size() - 1; i >= 0; i--)
+ if (((MediaDescriptor) media.elementAt(i)).getMedia().getMedia()
+ .equals(media_type))
+ media.removeElementAt(i);
+ return this;
+ }
+
+ /** Removes all MediaDescriptors */
+ public SessionDescriptor removeMediaDescriptors() { // media.clear(); // not
+ // supported by J2ME..
+ media.setSize(0);
+ return this;
+ }
+
+ /**
+ * Gets the first MediaDescriptor of a particular media.
+ *
+ * @param media_type
+ * the media type
+ * @return the MediaDescriptor
+ */
+ public MediaDescriptor getMediaDescriptor(String media_type) {
+ for (int i = 0; i < media.size(); i++) {
+ MediaDescriptor md = (MediaDescriptor) media.elementAt(i);
+ if (md.getMedia().getMedia().equals(media_type))
+ return md;
+ }
+ return null;
+ }
+
+ /**
+ * Adds a Vector of session attributes.
+ *
+ * @param attribute_fields
+ * Vector of AttributeFields
+ * @return this SessionDescriptor
+ */
+ public SessionDescriptor addAttributes(
+ Vector attribute_fields) {
+ for (int i = 0; i < attribute_fields.size(); i++)
+ addAttribute(attribute_fields.elementAt(i));
+ return this;
+ }
+
+ /**
+ * Adds a new attribute
+ *
+ * @param attribute
+ * the new AttributeField
+ * @return this MediaDescriptor
+ */
+ public SessionDescriptor addAttribute(AttributeField attribute) {
+ av.addElement(new AttributeField(attribute));
+ return this;
+ }
+
+ /** Removes all session attributes. */
+ public SessionDescriptor removeAttributes() {
+ av.setSize(0);
+ return this;
+ }
+
+ /**
+ * Gets a Vector of attribute values.
+ *
+ * @return a Vector of AttributeField
+ */
+ public Vector getAttributes() {
+ Vector v = new Vector(av.size());
+ for (int i = 0; i < av.size(); i++)
+ v.addElement((AttributeField) av.elementAt(i));
+ return v;
+ }
+
+ /**
+ * Whether it has a particular attribute
+ *
+ * @param a_name
+ * the attribute name
+ * @return true if found, otherwise returns null
+ */
+ public boolean hasAttribute(String attribute_name) {
+ for (int i = 0; i < av.size(); i++) {
+ if (((AttributeField) av.elementAt(i)).getAttributeName().equals(
+ attribute_name))
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Gets the first AttributeField of a particular attribute name.
+ *
+ * @param attribute_name
+ * the attribute name
+ * @return the AttributeField, or null if not found
+ */
+ public AttributeField getAttribute(String attribute_name) {
+ for (int i = 0; i < av.size(); i++) {
+ AttributeField af = (AttributeField) av.elementAt(i);
+ if (af.getAttributeName().equals(attribute_name))
+ return af;
+ }
+ return null;
+ }
+
+ /**
+ * Gets a Vector of attribute values of a particular attribute name.
+ *
+ * @param a_name
+ * the attribute name
+ * @return a Vector of AttributeField
+ */
+ public Vector getAttributes(String attribute_name) {
+ Vector v = new Vector(av.size());
+ for (int i = 0; i < av.size(); i++) {
+ AttributeField a = (AttributeField) av.elementAt(i);
+ if (a.getAttributeName().equals(attribute_name))
+ v.addElement(a);
+ }
+ return v;
+ }
+
+ /** Gets a String rapresentation */
+ public String toString() {
+ StringBuffer sb = new StringBuffer();
+ if (v != null)
+ sb.append(v.toString());
+ if (o != null)
+ sb.append(o.toString());
+ if (s != null)
+ sb.append(s.toString());
+ if (c != null)
+ sb.append(c.toString());
+ if (t != null)
+ sb.append(t.toString());
+ for (int i = 0; i < av.size(); i++)
+ sb.append(((AttributeField) av.elementAt(i)).toString());
+ for (int i = 0; i < media.size(); i++)
+ sb.append(((MediaDescriptor) media.elementAt(i)).toString());
+ return sb.toString();
+ }
+
+}
diff --git a/src/org/zoolu/sdp/SessionNameField.java b/app/src/main/java/org/zoolu/sdp/SessionNameField.java
similarity index 96%
rename from src/org/zoolu/sdp/SessionNameField.java
rename to app/src/main/java/org/zoolu/sdp/SessionNameField.java
index 4c7ac69..cadecc2 100644
--- a/src/org/zoolu/sdp/SessionNameField.java
+++ b/app/src/main/java/org/zoolu/sdp/SessionNameField.java
@@ -1,63 +1,63 @@
-/*
- * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
- *
- * This file is part of MjSip (http://www.mjsip.org)
- *
- * MjSip is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * MjSip is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with MjSip; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author(s):
- * Luca Veltri (luca.veltri@unipr.it)
- * Nitin Khanna, Hughes Systique Corp. (Reason: Android specific change, optmization, bug fix)
- */
-
-package org.zoolu.sdp;
-
-/* HSC CHANGE STARTS */
-// import org.zoolu.tools.Parser;
-/* HSC CHANGES END */
-
-/**
- * SDP session name field.
- *
- *
- *
- *
- * session-name-field = "s=" text CRLF
- *
- *
- *
- */
-public class SessionNameField extends SdpField {
- /** Creates a new SessionNameField. */
- public SessionNameField(String session_name) {
- super('s', session_name);
- }
-
- /** Creates a new void SessionNameField. */
- public SessionNameField() {
- super('s', " ");
- }
-
- /** Creates a new SessionNameField. */
- public SessionNameField(SdpField sf) {
- super(sf);
- }
-
- /** Gets the session name. */
- public String getSession() {
- return value;
- }
-
-}
+/*
+ * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
+ *
+ * This file is part of MjSip (http://www.mjsip.org)
+ *
+ * MjSip is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * MjSip is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MjSip; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author(s):
+ * Luca Veltri (luca.veltri@unipr.it)
+ * Nitin Khanna, Hughes Systique Corp. (Reason: Android specific change, optmization, bug fix)
+ */
+
+package org.zoolu.sdp;
+
+/* HSC CHANGE STARTS */
+// import org.zoolu.tools.Parser;
+/* HSC CHANGES END */
+
+/**
+ * SDP session name field.
+ *
+ *
+ *
+ *
+ * session-name-field = "s=" text CRLF
+ *
+ *
+ *
+ */
+public class SessionNameField extends SdpField {
+ /** Creates a new SessionNameField. */
+ public SessionNameField(String session_name) {
+ super('s', session_name);
+ }
+
+ /** Creates a new void SessionNameField. */
+ public SessionNameField() {
+ super('s', " ");
+ }
+
+ /** Creates a new SessionNameField. */
+ public SessionNameField(SdpField sf) {
+ super(sf);
+ }
+
+ /** Gets the session name. */
+ public String getSession() {
+ return value;
+ }
+
+}
diff --git a/src/org/zoolu/sdp/TimeField.java b/app/src/main/java/org/zoolu/sdp/TimeField.java
similarity index 96%
rename from src/org/zoolu/sdp/TimeField.java
rename to app/src/main/java/org/zoolu/sdp/TimeField.java
index 0016df2..80d58b8 100644
--- a/src/org/zoolu/sdp/TimeField.java
+++ b/app/src/main/java/org/zoolu/sdp/TimeField.java
@@ -1,70 +1,70 @@
-/*
- * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
- *
- * This file is part of MjSip (http://www.mjsip.org)
- *
- * MjSip is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * MjSip is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with MjSip; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author(s):
- * Luca Veltri (luca.veltri@unipr.it)
- */
-
-package org.zoolu.sdp;
-
-import org.zoolu.tools.Parser;
-
-/**
- * SDP attribute field.
- *
- *
- *
- *
- * time-fields = 1*( "t=" start-time SP stop-time *(CRLF repeat-fields) CRLF) [zone-adjustments CRLF]
- *
- *
- *
- */
-public class TimeField extends SdpField {
- /** Creates a new TimeField. */
- public TimeField(String time_field) {
- super('t', time_field);
- }
-
- /** Creates a new TimeField. */
- public TimeField(String start, String stop) {
- super('t', start + " " + stop);
- }
-
- /** Creates a new void TimeField. */
- public TimeField() {
- super('t', "0 0");
- }
-
- /** Creates a new TimeField. */
- public TimeField(SdpField sf) {
- super(sf);
- }
-
- /** Gets the start time. */
- public String getStartTime() {
- return (new Parser(value)).getString();
- }
-
- /** Gets the stop time. */
- public String getStopTime() {
- return (new Parser(value)).skipString().getString();
- }
-
-}
+/*
+ * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
+ *
+ * This file is part of MjSip (http://www.mjsip.org)
+ *
+ * MjSip is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * MjSip is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MjSip; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author(s):
+ * Luca Veltri (luca.veltri@unipr.it)
+ */
+
+package org.zoolu.sdp;
+
+import org.zoolu.tools.Parser;
+
+/**
+ * SDP attribute field.
+ *
+ *
+ *
+ *
+ * time-fields = 1*( "t=" start-time SP stop-time *(CRLF repeat-fields) CRLF) [zone-adjustments CRLF]
+ *
+ *
+ *
+ */
+public class TimeField extends SdpField {
+ /** Creates a new TimeField. */
+ public TimeField(String time_field) {
+ super('t', time_field);
+ }
+
+ /** Creates a new TimeField. */
+ public TimeField(String start, String stop) {
+ super('t', start + " " + stop);
+ }
+
+ /** Creates a new void TimeField. */
+ public TimeField() {
+ super('t', "0 0");
+ }
+
+ /** Creates a new TimeField. */
+ public TimeField(SdpField sf) {
+ super(sf);
+ }
+
+ /** Gets the start time. */
+ public String getStartTime() {
+ return (new Parser(value)).getString();
+ }
+
+ /** Gets the stop time. */
+ public String getStopTime() {
+ return (new Parser(value)).skipString().getString();
+ }
+
+}
diff --git a/src/org/zoolu/sip/address/NameAddress.java b/app/src/main/java/org/zoolu/sip/address/NameAddress.java
similarity index 96%
rename from src/org/zoolu/sip/address/NameAddress.java
rename to app/src/main/java/org/zoolu/sip/address/NameAddress.java
index 3da080d..0fd452d 100644
--- a/src/org/zoolu/sip/address/NameAddress.java
+++ b/app/src/main/java/org/zoolu/sip/address/NameAddress.java
@@ -1,134 +1,134 @@
-/*
- * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
- *
- * This file is part of MjSip (http://www.mjsip.org)
- *
- * MjSip is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * MjSip is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with MjSip; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author(s):
- * Luca Veltri (luca.veltri@unipr.it)
- */
-
-package org.zoolu.sip.address;
-
-import org.zoolu.sip.provider.SipParser;
-
-/**
- * Class NameAddress is used to rapresent any valid SIP Name Address. It
- * contains a SIP URI and optionally a display name.
- * A SIP Name Address is a string of the form of:
- *
- *
- *
- *    [ display-name ] address
- *
- *    where address can be a valid SIP URL
- *
- *
- *
- */
-public class NameAddress {
- String name;
- SipURL url;
-
- public NameAddress(String displayname, SipURL sipurl) {
- name = displayname;
- url = sipurl;
- }
-
- public NameAddress(SipURL sipurl) {
- name = null;
- url = sipurl;
- }
-
- public NameAddress(NameAddress name_address) {
- name = name_address.getDisplayName();
- url = name_address.getAddress();
- }
-
- public NameAddress(String naddr) {
- SipParser par = new SipParser(naddr);
- NameAddress na = par.getNameAddress();
- // DEBUG
- // if (na==null)
- // { System.out.println("DEBUG: NameAddress:
- // par:\r\n"+par.getWholeString());
- // System.exit(0);
- // }
- name = na.name;
- url = na.url;
- }
-
- /** Creates and returns a copy of NameAddress */
- public Object clone() {
- return new NameAddress(this);
- }
-
- /** Indicates whether some other Object is "equal to" this NameAddress */
- public boolean equals(Object obj) {
- NameAddress naddr = (NameAddress) obj;
- return url.equals(naddr.getAddress());
- }
-
- /** Gets address of NameAddress */
- public SipURL getAddress() {
- return url;
- }
-
- /**
- * Gets display name of NameAddress (Returns null id display name does not
- * exist)
- */
- public String getDisplayName() {
- return name;
- }
-
- /** Gets boolean value to indicate if NameAddress has display name */
- public boolean hasDisplayName() {
- return name != null;
- }
-
- /** Removes display name from NameAddress (if it exists) */
- public void removeDisplayName() {
- name = null;
- }
-
- /** Sets address of NameAddress */
- public void setAddress(SipURL address) {
- url = address;
- }
-
- /** Sets display name of Header */
- public void setDisplayName(String displayName) {
- name = displayName;
- }
-
- /** Whether two NameAddresses are equals */
- public boolean equals(NameAddress naddr) {
- return (name == naddr.name && url == naddr.url);
- }
-
- /** Gets string representation of NameAddress */
- public String toString() {
- String str;
- if (hasDisplayName())
- str = "\"" + name + "\" <" + url + ">";
- else
- str = "<" + url + ">";
-
- return str;
- }
-
-}
+/*
+ * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
+ *
+ * This file is part of MjSip (http://www.mjsip.org)
+ *
+ * MjSip is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * MjSip is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MjSip; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author(s):
+ * Luca Veltri (luca.veltri@unipr.it)
+ */
+
+package org.zoolu.sip.address;
+
+import org.zoolu.sip.provider.SipParser;
+
+/**
+ * Class NameAddress is used to rapresent any valid SIP Name Address. It
+ * contains a SIP URI and optionally a display name.
+ * A SIP Name Address is a string of the form of:
+ *
+ *
+ *
+ *    [ display-name ] address
+ *
+ *    where address can be a valid SIP URL
+ *
+ *
+ *
+ */
+public class NameAddress {
+ String name;
+ SipURL url;
+
+ public NameAddress(String displayname, SipURL sipurl) {
+ name = displayname;
+ url = sipurl;
+ }
+
+ public NameAddress(SipURL sipurl) {
+ name = null;
+ url = sipurl;
+ }
+
+ public NameAddress(NameAddress name_address) {
+ name = name_address.getDisplayName();
+ url = name_address.getAddress();
+ }
+
+ public NameAddress(String naddr) {
+ SipParser par = new SipParser(naddr);
+ NameAddress na = par.getNameAddress();
+ // DEBUG
+ // if (na==null)
+ // { System.out.println("DEBUG: NameAddress:
+ // par:\r\n"+par.getWholeString());
+ // System.exit(0);
+ // }
+ name = na.name;
+ url = na.url;
+ }
+
+ /** Creates and returns a copy of NameAddress */
+ public Object clone() {
+ return new NameAddress(this);
+ }
+
+ /** Indicates whether some other Object is "equal to" this NameAddress */
+ public boolean equals(Object obj) {
+ NameAddress naddr = (NameAddress) obj;
+ return url.equals(naddr.getAddress());
+ }
+
+ /** Gets address of NameAddress */
+ public SipURL getAddress() {
+ return url;
+ }
+
+ /**
+ * Gets display name of NameAddress (Returns null id display name does not
+ * exist)
+ */
+ public String getDisplayName() {
+ return name;
+ }
+
+ /** Gets boolean value to indicate if NameAddress has display name */
+ public boolean hasDisplayName() {
+ return name != null;
+ }
+
+ /** Removes display name from NameAddress (if it exists) */
+ public void removeDisplayName() {
+ name = null;
+ }
+
+ /** Sets address of NameAddress */
+ public void setAddress(SipURL address) {
+ url = address;
+ }
+
+ /** Sets display name of Header */
+ public void setDisplayName(String displayName) {
+ name = displayName;
+ }
+
+ /** Whether two NameAddresses are equals */
+ public boolean equals(NameAddress naddr) {
+ return (name == naddr.name && url == naddr.url);
+ }
+
+ /** Gets string representation of NameAddress */
+ public String toString() {
+ String str;
+ if (hasDisplayName())
+ str = "\"" + name + "\" <" + url + ">";
+ else
+ str = "<" + url + ">";
+
+ return str;
+ }
+
+}
diff --git a/src/org/zoolu/sip/address/SipURL.java b/app/src/main/java/org/zoolu/sip/address/SipURL.java
similarity index 96%
rename from src/org/zoolu/sip/address/SipURL.java
rename to app/src/main/java/org/zoolu/sip/address/SipURL.java
index 85ae548..6a8aa82 100644
--- a/src/org/zoolu/sip/address/SipURL.java
+++ b/app/src/main/java/org/zoolu/sip/address/SipURL.java
@@ -1,326 +1,326 @@
-/*
- * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
- * Copyright (C) 2009 The Sipdroid Open Source Project
- *
- * This file is part of MjSip (http://www.mjsip.org)
- *
- * MjSip is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * MjSip is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with MjSip; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author(s):
- * Luca Veltri (luca.veltri@unipr.it)
- * Nitin Khanna, Hughes Systique Corp. (Reason: Android specific change, optmization, bug fix)
- */
-
-package org.zoolu.sip.address;
-
-import org.zoolu.sip.provider.SipParser;
-import org.zoolu.tools.Parser;
-import java.util.Vector;
-
-/**
- *
- * Class SipURL implements SIP URLs.
- *
- * A SIP URL is a string of the form of:
- *
- *
- *
- *    sip:[user@]hostname[:port][;parameters]
- *
- *
- *
- *
- * If port number is ommitted, -1 is returned
- */
-public class SipURL {
- protected String url;
-
- protected static final String transport_param = "transport";
- protected static final String maddr_param = "maddr";
- protected static final String ttl_param = "ttl";
- protected static final String lr_param = "lr";
-
- /**
- * Creates a new SipURL based on a hostname or on a sip url as
- * sip:[user@]hostname[:port][;param1=value1]..
- */
- public SipURL(String sipurl) {
- if (sipurl.startsWith("sip:"))
- url = new String(sipurl);
- else
- url = "sip:" + sipurl;
- }
-
- /** Creates a new SipURL */
- public SipURL(String username, String hostname) {
- init(username, hostname, -1);
- }
-
- /** Creates a new SipURL */
- public SipURL(String hostname, int portnumber) {
- init(null, hostname, portnumber);
- }
-
- /** Creates a new SipURL */
- public SipURL(String username, String hostname, int portnumber) {
- init(username, hostname, portnumber);
- }
-
- /** Inits the SipURL */
- private void init(String username, String hostname, int portnumber) {
- StringBuffer sb = new StringBuffer("sip:");
- if (username != null){
- sb.append(username);
- if(username.indexOf('@') < 0){
- sb.append('@');
- sb.append(hostname);
- }
- } else
- sb.append(hostname);
-
- if (portnumber > 0)
- if(username == null || username.indexOf(':') < 0)
- sb.append(":" + portnumber);
-
- url = sb.toString();
- }
-
- /** Creates and returns a copy of the URL */
- public Object clone() {
- return new SipURL(url);
- }
-
- /** Indicates whether some other Object is "equal to" this URL */
- public boolean equals(Object obj) {
- SipURL newurl = (SipURL) obj;
- return url.toString().equals(newurl.toString());
- }
-
- /** Gets user name of SipURL (Returns null if user name does not exist) */
- public String getUserName() {
- int begin = 4; // skip "sip:"
- int end = url.indexOf('@', begin);
- if (end < 0)
- return null;
- else
- return url.substring(begin, end);
- }
-
- /** Gets host of SipURL */
- public String getHost() {
- char[] host_terminators = { ':', ';', '?' };
- Parser par = new Parser(url);
- int begin = par.indexOf('@'); // skip "sip:user@"
- if (begin < 0)
- begin = 4; // skip "sip:"
- else
- begin++; // skip "@"
- par.setPos(begin);
- int end = par.indexOf(host_terminators);
- if (end < 0)
- return url.substring(begin);
- else
- return url.substring(begin, end);
- }
-
- /** Gets port of SipURL; returns -1 if port is not specidfied */
- public int getPort() {
- char[] port_terminators = { ';', '?' };
- Parser par = new Parser(url, 4); // skip "sip:"
- int begin = par.indexOf(':');
- if (begin < 0)
- return -1;
- else {
- begin++;
- par.setPos(begin);
- int end = par.indexOf(port_terminators);
- if (end < 0)
- return Integer.parseInt(url.substring(begin));
- else
- return Integer.parseInt(url.substring(begin, end));
- }
- }
-
- /** Gets boolean value to indicate if SipURL has user name */
- public boolean hasUserName() {
- return getUserName() != null;
- }
-
- /** Gets boolean value to indicate if SipURL has port */
- public boolean hasPort() {
- return getPort() >= 0;
- }
-
- /** Whether two SipURLs are equals */
- public boolean equals(SipURL sip_url) {
- return (url == sip_url.url);
- }
-
- /** Gets string representation of URL */
- public String toString() {
- return url;
- }
-
- /**
- * Gets the value of specified parameter.
- *
- * @return null if parameter does not exist.
- */
- public String getParameter(String name) {
- SipParser par = new SipParser(url);
- return ((SipParser) par.goTo(';').skipChar()).getParameter(name);
- }
-
- /**
- * Gets a String Vector of parameter names.
- *
- * @return null if no parameter is present
- */
- /* HSC CHANGES START */
- public Vector getParameters() {
- SipParser par = new SipParser(url);
- Vector result = ((SipParser) par.goTo(';').skipChar())
- .getParameters();
- /* HSC CHANGES END */
- return result;
- }
-
- /** Whether there is the specified parameter */
- public boolean hasParameter(String name) {
- SipParser par = new SipParser(url);
- return ((SipParser) par.goTo(';').skipChar()).hasParameter(name);
- }
-
- /** Whether there are any parameters */
- public boolean hasParameters() {
- if (url != null && url.indexOf(';') >= 0)
- return true;
- else
- return false;
- }
-
- /** Adds a new parameter without a value */
- public void addParameter(String name) {
- url = url + ";" + name;
- }
-
- /** Adds a new parameter with value */
- public void addParameter(String name, String value) {
- if (value != null)
- url = url + ";" + name + "=" + value;
- else
- url = url + ";" + name;
- }
-
- /** Removes all parameters (if any) */
- public void removeParameters() {
- int index = url.indexOf(';');
- if (index >= 0)
- url = url.substring(0, index);
- }
-
- /** Removes specified parameter (if present) */
- public void removeParameter(String name) {
- int index = url.indexOf(';');
- if (index < 0)
- return;
- Parser par = new Parser(url, index);
- while (par.hasMore()) {
- int begin_param = par.getPos();
- par.skipChar();
- if (par.getWord(SipParser.param_separators).equals(name)) {
- String top = url.substring(0, begin_param);
- par.goToSkippingQuoted(';');
- String bottom = "";
- if (par.hasMore())
- bottom = url.substring(par.getPos());
- url = top.concat(bottom);
- return;
- }
- par.goTo(';');
- }
- }
-
- /**
- * Gets the value of transport parameter.
- *
- * @return null if no transport parameter is present.
- */
- public String getTransport() {
- return getParameter(transport_param);
- }
-
- /** Whether transport parameter is present */
- public boolean hasTransport() {
- return hasParameter(transport_param);
- }
-
- /** Adds transport parameter */
- public void addTransport(String proto) {
- addParameter(transport_param, proto.toLowerCase());
- }
-
- /**
- * Gets the value of maddr parameter.
- *
- * @return null if no maddr parameter is present.
- */
- public String getMaddr() {
- return getParameter(maddr_param);
- }
-
- /** Whether maddr parameter is present */
- public boolean hasMaddr() {
- return hasParameter(maddr_param);
- }
-
- /** Adds maddr parameter */
- public void addMaddr(String maddr) {
- addParameter(maddr_param, maddr);
- }
-
- /**
- * Gets the value of ttl parameter.
- *
- * @return 1 if no ttl parameter is present.
- */
- public int getTtl() {
- try {
- return Integer.parseInt(getParameter(ttl_param));
- } catch (Exception e) {
- return 1;
- }
- }
-
- /** Whether ttl parameter is present */
- public boolean hasTtl() {
- return hasParameter(ttl_param);
- }
-
- /** Adds ttl parameter */
- public void addTtl(int ttl) {
- addParameter(ttl_param, Integer.toString(ttl));
- }
-
- /** Whether lr (loose-route) parameter is present */
- public boolean hasLr() {
- return hasParameter(lr_param);
- }
-
- /** Adds lr parameter */
- public void addLr() {
- addParameter(lr_param);
- }
-}
+/*
+ * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
+ * Copyright (C) 2009 The Sipdroid Open Source Project
+ *
+ * This file is part of MjSip (http://www.mjsip.org)
+ *
+ * MjSip is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * MjSip is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MjSip; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author(s):
+ * Luca Veltri (luca.veltri@unipr.it)
+ * Nitin Khanna, Hughes Systique Corp. (Reason: Android specific change, optmization, bug fix)
+ */
+
+package org.zoolu.sip.address;
+
+import org.zoolu.sip.provider.SipParser;
+import org.zoolu.tools.Parser;
+import java.util.Vector;
+
+/**
+ *
+ * Class SipURL implements SIP URLs.
+ *
+ * A SIP URL is a string of the form of:
+ *
+ *
+ *
+ *    sip:[user@]hostname[:port][;parameters]
+ *
+ *
+ *
+ *
+ * If port number is ommitted, -1 is returned
+ */
+public class SipURL {
+ protected String url;
+
+ protected static final String transport_param = "transport";
+ protected static final String maddr_param = "maddr";
+ protected static final String ttl_param = "ttl";
+ protected static final String lr_param = "lr";
+
+ /**
+ * Creates a new SipURL based on a hostname or on a sip url as
+ * sip:[user@]hostname[:port][;param1=value1]..
+ */
+ public SipURL(String sipurl) {
+ if (sipurl.startsWith("sip:"))
+ url = new String(sipurl);
+ else
+ url = "sip:" + sipurl;
+ }
+
+ /** Creates a new SipURL */
+ public SipURL(String username, String hostname) {
+ init(username, hostname, -1);
+ }
+
+ /** Creates a new SipURL */
+ public SipURL(String hostname, int portnumber) {
+ init(null, hostname, portnumber);
+ }
+
+ /** Creates a new SipURL */
+ public SipURL(String username, String hostname, int portnumber) {
+ init(username, hostname, portnumber);
+ }
+
+ /** Inits the SipURL */
+ private void init(String username, String hostname, int portnumber) {
+ StringBuffer sb = new StringBuffer("sip:");
+ if (username != null){
+ sb.append(username);
+ if(username.indexOf('@') < 0){
+ sb.append('@');
+ sb.append(hostname);
+ }
+ } else
+ sb.append(hostname);
+
+ if (portnumber > 0)
+ if(username == null || username.indexOf(':') < 0)
+ sb.append(":" + portnumber);
+
+ url = sb.toString();
+ }
+
+ /** Creates and returns a copy of the URL */
+ public Object clone() {
+ return new SipURL(url);
+ }
+
+ /** Indicates whether some other Object is "equal to" this URL */
+ public boolean equals(Object obj) {
+ SipURL newurl = (SipURL) obj;
+ return url.toString().equals(newurl.toString());
+ }
+
+ /** Gets user name of SipURL (Returns null if user name does not exist) */
+ public String getUserName() {
+ int begin = 4; // skip "sip:"
+ int end = url.indexOf('@', begin);
+ if (end < 0)
+ return null;
+ else
+ return url.substring(begin, end);
+ }
+
+ /** Gets host of SipURL */
+ public String getHost() {
+ char[] host_terminators = { ':', ';', '?' };
+ Parser par = new Parser(url);
+ int begin = par.indexOf('@'); // skip "sip:user@"
+ if (begin < 0)
+ begin = 4; // skip "sip:"
+ else
+ begin++; // skip "@"
+ par.setPos(begin);
+ int end = par.indexOf(host_terminators);
+ if (end < 0)
+ return url.substring(begin);
+ else
+ return url.substring(begin, end);
+ }
+
+ /** Gets port of SipURL; returns -1 if port is not specidfied */
+ public int getPort() {
+ char[] port_terminators = { ';', '?' };
+ Parser par = new Parser(url, 4); // skip "sip:"
+ int begin = par.indexOf(':');
+ if (begin < 0)
+ return -1;
+ else {
+ begin++;
+ par.setPos(begin);
+ int end = par.indexOf(port_terminators);
+ if (end < 0)
+ return Integer.parseInt(url.substring(begin));
+ else
+ return Integer.parseInt(url.substring(begin, end));
+ }
+ }
+
+ /** Gets boolean value to indicate if SipURL has user name */
+ public boolean hasUserName() {
+ return getUserName() != null;
+ }
+
+ /** Gets boolean value to indicate if SipURL has port */
+ public boolean hasPort() {
+ return getPort() >= 0;
+ }
+
+ /** Whether two SipURLs are equals */
+ public boolean equals(SipURL sip_url) {
+ return (url == sip_url.url);
+ }
+
+ /** Gets string representation of URL */
+ public String toString() {
+ return url;
+ }
+
+ /**
+ * Gets the value of specified parameter.
+ *
+ * @return null if parameter does not exist.
+ */
+ public String getParameter(String name) {
+ SipParser par = new SipParser(url);
+ return ((SipParser) par.goTo(';').skipChar()).getParameter(name);
+ }
+
+ /**
+ * Gets a String Vector of parameter names.
+ *
+ * @return null if no parameter is present
+ */
+ /* HSC CHANGES START */
+ public Vector getParameters() {
+ SipParser par = new SipParser(url);
+ Vector result = ((SipParser) par.goTo(';').skipChar())
+ .getParameters();
+ /* HSC CHANGES END */
+ return result;
+ }
+
+ /** Whether there is the specified parameter */
+ public boolean hasParameter(String name) {
+ SipParser par = new SipParser(url);
+ return ((SipParser) par.goTo(';').skipChar()).hasParameter(name);
+ }
+
+ /** Whether there are any parameters */
+ public boolean hasParameters() {
+ if (url != null && url.indexOf(';') >= 0)
+ return true;
+ else
+ return false;
+ }
+
+ /** Adds a new parameter without a value */
+ public void addParameter(String name) {
+ url = url + ";" + name;
+ }
+
+ /** Adds a new parameter with value */
+ public void addParameter(String name, String value) {
+ if (value != null)
+ url = url + ";" + name + "=" + value;
+ else
+ url = url + ";" + name;
+ }
+
+ /** Removes all parameters (if any) */
+ public void removeParameters() {
+ int index = url.indexOf(';');
+ if (index >= 0)
+ url = url.substring(0, index);
+ }
+
+ /** Removes specified parameter (if present) */
+ public void removeParameter(String name) {
+ int index = url.indexOf(';');
+ if (index < 0)
+ return;
+ Parser par = new Parser(url, index);
+ while (par.hasMore()) {
+ int begin_param = par.getPos();
+ par.skipChar();
+ if (par.getWord(SipParser.param_separators).equals(name)) {
+ String top = url.substring(0, begin_param);
+ par.goToSkippingQuoted(';');
+ String bottom = "";
+ if (par.hasMore())
+ bottom = url.substring(par.getPos());
+ url = top.concat(bottom);
+ return;
+ }
+ par.goTo(';');
+ }
+ }
+
+ /**
+ * Gets the value of transport parameter.
+ *
+ * @return null if no transport parameter is present.
+ */
+ public String getTransport() {
+ return getParameter(transport_param);
+ }
+
+ /** Whether transport parameter is present */
+ public boolean hasTransport() {
+ return hasParameter(transport_param);
+ }
+
+ /** Adds transport parameter */
+ public void addTransport(String proto) {
+ addParameter(transport_param, proto.toLowerCase());
+ }
+
+ /**
+ * Gets the value of maddr parameter.
+ *
+ * @return null if no maddr parameter is present.
+ */
+ public String getMaddr() {
+ return getParameter(maddr_param);
+ }
+
+ /** Whether maddr parameter is present */
+ public boolean hasMaddr() {
+ return hasParameter(maddr_param);
+ }
+
+ /** Adds maddr parameter */
+ public void addMaddr(String maddr) {
+ addParameter(maddr_param, maddr);
+ }
+
+ /**
+ * Gets the value of ttl parameter.
+ *
+ * @return 1 if no ttl parameter is present.
+ */
+ public int getTtl() {
+ try {
+ return Integer.parseInt(getParameter(ttl_param));
+ } catch (Exception e) {
+ return 1;
+ }
+ }
+
+ /** Whether ttl parameter is present */
+ public boolean hasTtl() {
+ return hasParameter(ttl_param);
+ }
+
+ /** Adds ttl parameter */
+ public void addTtl(int ttl) {
+ addParameter(ttl_param, Integer.toString(ttl));
+ }
+
+ /** Whether lr (loose-route) parameter is present */
+ public boolean hasLr() {
+ return hasParameter(lr_param);
+ }
+
+ /** Adds lr parameter */
+ public void addLr() {
+ addParameter(lr_param);
+ }
+}
diff --git a/src/org/zoolu/sip/authentication/DigestAuthentication.java b/app/src/main/java/org/zoolu/sip/authentication/DigestAuthentication.java
similarity index 96%
rename from src/org/zoolu/sip/authentication/DigestAuthentication.java
rename to app/src/main/java/org/zoolu/sip/authentication/DigestAuthentication.java
index 80e5298..f129e74 100644
--- a/src/org/zoolu/sip/authentication/DigestAuthentication.java
+++ b/app/src/main/java/org/zoolu/sip/authentication/DigestAuthentication.java
@@ -1,319 +1,319 @@
-package org.zoolu.sip.authentication;
-
-import org.zoolu.sip.header.AuthenticationHeader;
-import org.zoolu.sip.header.AuthorizationHeader;
-import org.zoolu.sip.header.ProxyAuthorizationHeader;
-import org.zoolu.sip.header.WwwAuthenticateHeader;
-import org.zoolu.tools.MD5;
-import org.zoolu.tools.Random;
-
-/**
- * The HTTP Digest Authentication as defined in RFC2617. It can be used to i)
- * calculate an authentication response from an authentication request, or ii)
- * validate an authentication response.
in the former case the
- * DigestAuthentication is created based on a WwwAuthenticationHeader (or
- * ProxyAuthenticationHeader), while in the latter case it is created based on
- * an AuthorizationHeader (or ProxyAuthorizationHeader).
- */
-public class DigestAuthentication {
- protected String method;
- protected String username;
- protected String passwd;
-
- protected String realm;
- protected String nonce; // e.g. base 64 encoding of time-stamp H(time-stamp
- // ":" ETag ":" private-key)
- // protected String[] domain;
- protected String opaque;
- // protected boolean stale; // "true" | "false"
- protected String algorithm; // "MD5" | "MD5-sess" | token
-
- protected String qop; // "auth" | "auth-int" | token
-
- protected String uri;
- protected String cnonce;
- protected String nc;
- protected String response;
-
- protected String body;
-
- /** Costructs a new DigestAuthentication. */
- protected DigestAuthentication() {
- }
-
- /** Costructs a new DigestAuthentication. */
- public DigestAuthentication(String method, AuthorizationHeader ah,
- String body, String passwd) {
- init(method, ah, body, passwd);
- }
-
- /** Costructs a new DigestAuthentication. */
- public DigestAuthentication(String method, String uri,
- WwwAuthenticateHeader ah, String qop, String body, String username,
- String passwd) {
- init(method, ah, body, passwd);
- this.uri = uri;
- this.qop = qop;
- if (qop != null && cnonce == null) {
- this.cnonce = Random.nextHexString(16);
- /*
- * A new cnonce is generated for every new instance so
- * no need to keep track of the nc value.
- */
- this.nc = "00000001";
- }
- this.username = username;
- }
-
- /** Costructs a new DigestAuthentication. */
- private void init(String method, AuthenticationHeader ah, String body,
- String passwd) {
- this.method = method;
- this.username = ah.getUsernameParam();
- this.passwd = passwd;
- this.realm = ah.getRealmParam();
- this.opaque = ah.getOpaqueParam();
- this.nonce = ah.getNonceParam();
- this.algorithm = ah.getAlgorithParam();
- this.qop = ah.getQopParam();
- this.uri = ah.getUriParam();
- this.cnonce = ah.getCnonceParam();
- this.nc = ah.getNcParam();
- this.response = ah.getResponseParam();
- this.body = body;
- }
-
- /** Gets a String representation of the object. */
- public String toString() {
- StringBuffer sb = new StringBuffer();
- sb.append("method=").append(method).append("\n");
- sb.append("username=").append(username).append("\n");
- sb.append("passwd=").append(passwd).append("\n");
- sb.append("realm=").append(realm).append("\n");
- sb.append("nonce=").append(nonce).append("\n");
- sb.append("opaque=").append(opaque).append("\n");
- sb.append("algorithm=").append(algorithm).append("\n");
- sb.append("qop=").append(qop).append("\n");
- sb.append("uri=").append(uri).append("\n");
- sb.append("cnonce=").append(cnonce).append("\n");
- sb.append("nc=").append(nc).append("\n");
- sb.append("response=").append(response).append("\n");
- sb.append("body=").append(body).append("\n");
- return sb.toString();
- }
-
- /** Whether the digest-response in the 'response' parameter in correct. */
- public boolean checkResponse() {
- if (response == null)
- return false;
- else
- return response.equals(getResponse());
- }
-
- /**
- * Gets a new AuthorizationHeader based on current authentication
- * attributes.
- */
- public AuthorizationHeader getAuthorizationHeader() {
- AuthorizationHeader ah = new AuthorizationHeader("Digest");
- ah.addUsernameParam(username);
- ah.addRealmParam(realm);
- ah.addNonceParam(nonce);
- ah.addUriParam(uri);
- if (algorithm != null)
- ah.addAlgorithParam(algorithm);
- if (opaque != null)
- ah.addOpaqueParam(opaque);
- if (qop != null)
- ah.addQopParam(qop);
- if (nc != null)
- ah.addNcParam(nc);
- if (cnonce != null)
- ah.addCnonceParam(cnonce);
- String response = getResponse();
- ah.addResponseParam(response);
- return ah;
- }
-
- /**
- * Gets a new ProxyAuthorizationHeader based on current authentication
- * attributes.
- */
- public ProxyAuthorizationHeader getProxyAuthorizationHeader() {
- return new ProxyAuthorizationHeader(getAuthorizationHeader().getValue());
- }
-
- /**
- * Calculates the digest-response.
- *
- * If the "qop" value is "auth" or "auth-int":
- * KD ( H(A1), unq(nonce) ":" nc ":" unq(cnonce) ":" unq(qop) ":" H(A2) )
- *
- *
- * If the "qop" directive is not present:
- * KD ( H(A1), unq(nonce) ":" H(A2) )
- */
- public String getResponse() {
- String secret = HEX(MD5(A1()));
- StringBuffer sb = new StringBuffer();
- if (nonce != null)
- sb.append(nonce);
- sb.append(":");
- if (qop != null) {
- if (nc != null)
- sb.append(nc);
- sb.append(":");
- if (cnonce != null)
- sb.append(cnonce);
- sb.append(":");
- sb.append(qop);
- sb.append(":");
- }
- sb.append(HEX(MD5(A2())));
- String data = sb.toString();
- return HEX(KD(secret, data));
- }
-
- /**
- * Calculates KD() value.
- *
- * KD(secret, data) = H(concat(secret, ":", data))
- */
- private byte[] KD(String secret, String data) {
- StringBuffer sb = new StringBuffer();
- sb.append(secret).append(":").append(data);
- return MD5(sb.toString());
- }
-
- /**
- * Calculates A1 value.
- *
- * If the "algorithm" directive's value is "MD5" or is unspecified:
- * A1 = unq(username) ":" unq(realm) ":" passwd
- *
- *
- * If the "algorithm" directive's value is "MD5-sess":
- * A1 = H( unq(username) ":" unq(realm) ":" passwd ) ":" unq(nonce) ":"
- * unq(cnonce)
- */
- private byte[] A1() {
- StringBuffer sb = new StringBuffer();
- if (username != null)
- sb.append(username);
- sb.append(":");
- if (realm != null)
- sb.append(realm);
- sb.append(":");
- if (passwd != null)
- sb.append(passwd);
-
- if (algorithm == null || !algorithm.equalsIgnoreCase("MD5-sess")) {
- return sb.toString().getBytes();
- } else {
- StringBuffer sb2 = new StringBuffer();
- sb2.append(":");
- if (nonce != null)
- sb2.append(nonce);
- sb2.append(":");
- if (cnonce != null)
- sb2.append(cnonce);
- return cat(MD5(sb.toString()), sb2.toString().getBytes());
- }
- }
-
- /**
- * Calculates A2 value.
- *
- * If the "qop" directive's value is "auth" or is unspecified:
- * A2 = Method ":" digest-uri
- *
- *
- * If the "qop" value is "auth-int":
- * A2 = Method ":" digest-uri ":" H(entity-body)
- */
- private String A2() {
- StringBuffer sb = new StringBuffer();
- sb.append(method);
- sb.append(":");
- if (uri != null)
- sb.append(uri);
-
- if (qop != null && qop.equalsIgnoreCase("auth-int")) {
- sb.append(":");
- if (body == null)
- sb.append(HEX(MD5("")));
- else
- sb.append(HEX(MD5(body)));
- }
- return sb.toString();
- }
-
- /** Concatenates two arrays of bytes. */
- private static byte[] cat(byte[] a, byte[] b) {
- int len = a.length + b.length;
- byte[] c = new byte[len];
- for (int i = 0; i < a.length; i++)
- c[i] = a[i];
- for (int i = 0; i < b.length; i++)
- c[i + a.length] = b[i];
- return c;
- }
-
- /** Calculates the MD5 of a String. */
- private static byte[] MD5(String str) {
- return MD5.digest(str);
- }
-
- /** Calculates the MD5 of an array of bytes. */
- private static byte[] MD5(byte[] bb) {
- return MD5.digest(bb);
- }
-
- /** Calculates the HEX of an array of bytes. */
- private static String HEX(byte[] bb) {
- return MD5.asHex(bb);
- }
-
- /**
- * Main method. It tests DigestAuthentication with the example provided in
- * the RFC2617.
- */
- public static void main(String[] args) {
- /*
- * Authorization: Digest username="Mufasa", realm="testrealm@host.com",
- * nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093", uri="/dir/index.html",
- * qop=auth, nc=00000001, cnonce="0a4f113b",
- * response="6629fae49393a05397450978507c4ef1",
- * opaque="5ccc069c403ebaf9f0171e9517f40e41"
- */
- DigestAuthentication a = new DigestAuthentication();
- a.method = "GET";
- a.passwd = "Circle Of Life";
- a.realm = "testrealm@host.com";
- a.nonce = "dcd98b7102dd2f0e8b11d0f600bfb0c093";
- a.uri = "/dir/index.html";
- a.qop = "auth";
- a.nc = "00000001";
- a.cnonce = "0a4f113b";
- a.username = "Mufasa";
-
- String response1 = a.getResponse();
- String response2 = "6629fae49393a05397450978507c4ef1";
- System.out.println(response1);
- System.out.println(response2);
-
- System.out.println(" ");
-
- String ah_str = "Digest username=\"Mufasa\", realm=\"testrealm@host.com\", nonce=\"dcd98b7102dd2f0e8b11d0f600bfb0c093\", uri=\"/dir/index.html\", qop=auth, nc=00000001, cnonce=\"0a4f113b\", response=\"6629fae49393a05397450978507c4ef1\", opaque=\"5ccc069c403ebaf9f0171e9517f40e41\"\n";
-
- AuthorizationHeader ah = new AuthorizationHeader(ah_str);
- a = new DigestAuthentication("GET", ah, null, "Circle Of Life");
- response1 = a.getResponse();
- response2 = "6629fae49393a05397450978507c4ef1";
- System.out.println(response1);
- System.out.println(response2);
-
- System.out.println(a.checkResponse());
-
- }
-}
+package org.zoolu.sip.authentication;
+
+import org.zoolu.sip.header.AuthenticationHeader;
+import org.zoolu.sip.header.AuthorizationHeader;
+import org.zoolu.sip.header.ProxyAuthorizationHeader;
+import org.zoolu.sip.header.WwwAuthenticateHeader;
+import org.zoolu.tools.MD5;
+import org.zoolu.tools.Random;
+
+/**
+ * The HTTP Digest Authentication as defined in RFC2617. It can be used to i)
+ * calculate an authentication response from an authentication request, or ii)
+ * validate an authentication response.
in the former case the
+ * DigestAuthentication is created based on a WwwAuthenticationHeader (or
+ * ProxyAuthenticationHeader), while in the latter case it is created based on
+ * an AuthorizationHeader (or ProxyAuthorizationHeader).
+ */
+public class DigestAuthentication {
+ protected String method;
+ protected String username;
+ protected String passwd;
+
+ protected String realm;
+ protected String nonce; // e.g. base 64 encoding of time-stamp H(time-stamp
+ // ":" ETag ":" private-key)
+ // protected String[] domain;
+ protected String opaque;
+ // protected boolean stale; // "true" | "false"
+ protected String algorithm; // "MD5" | "MD5-sess" | token
+
+ protected String qop; // "auth" | "auth-int" | token
+
+ protected String uri;
+ protected String cnonce;
+ protected String nc;
+ protected String response;
+
+ protected String body;
+
+ /** Costructs a new DigestAuthentication. */
+ protected DigestAuthentication() {
+ }
+
+ /** Costructs a new DigestAuthentication. */
+ public DigestAuthentication(String method, AuthorizationHeader ah,
+ String body, String passwd) {
+ init(method, ah, body, passwd);
+ }
+
+ /** Costructs a new DigestAuthentication. */
+ public DigestAuthentication(String method, String uri,
+ WwwAuthenticateHeader ah, String qop, String body, String username,
+ String passwd) {
+ init(method, ah, body, passwd);
+ this.uri = uri;
+ this.qop = qop;
+ if (qop != null && cnonce == null) {
+ this.cnonce = Random.nextHexString(16);
+ /*
+ * A new cnonce is generated for every new instance so
+ * no need to keep track of the nc value.
+ */
+ this.nc = "00000001";
+ }
+ this.username = username;
+ }
+
+ /** Costructs a new DigestAuthentication. */
+ private void init(String method, AuthenticationHeader ah, String body,
+ String passwd) {
+ this.method = method;
+ this.username = ah.getUsernameParam();
+ this.passwd = passwd;
+ this.realm = ah.getRealmParam();
+ this.opaque = ah.getOpaqueParam();
+ this.nonce = ah.getNonceParam();
+ this.algorithm = ah.getAlgorithParam();
+ this.qop = ah.getQopParam();
+ this.uri = ah.getUriParam();
+ this.cnonce = ah.getCnonceParam();
+ this.nc = ah.getNcParam();
+ this.response = ah.getResponseParam();
+ this.body = body;
+ }
+
+ /** Gets a String representation of the object. */
+ public String toString() {
+ StringBuffer sb = new StringBuffer();
+ sb.append("method=").append(method).append("\n");
+ sb.append("username=").append(username).append("\n");
+ sb.append("passwd=").append(passwd).append("\n");
+ sb.append("realm=").append(realm).append("\n");
+ sb.append("nonce=").append(nonce).append("\n");
+ sb.append("opaque=").append(opaque).append("\n");
+ sb.append("algorithm=").append(algorithm).append("\n");
+ sb.append("qop=").append(qop).append("\n");
+ sb.append("uri=").append(uri).append("\n");
+ sb.append("cnonce=").append(cnonce).append("\n");
+ sb.append("nc=").append(nc).append("\n");
+ sb.append("response=").append(response).append("\n");
+ sb.append("body=").append(body).append("\n");
+ return sb.toString();
+ }
+
+ /** Whether the digest-response in the 'response' parameter in correct. */
+ public boolean checkResponse() {
+ if (response == null)
+ return false;
+ else
+ return response.equals(getResponse());
+ }
+
+ /**
+ * Gets a new AuthorizationHeader based on current authentication
+ * attributes.
+ */
+ public AuthorizationHeader getAuthorizationHeader() {
+ AuthorizationHeader ah = new AuthorizationHeader("Digest");
+ ah.addUsernameParam(username);
+ ah.addRealmParam(realm);
+ ah.addNonceParam(nonce);
+ ah.addUriParam(uri);
+ if (algorithm != null)
+ ah.addAlgorithParam(algorithm);
+ if (opaque != null)
+ ah.addOpaqueParam(opaque);
+ if (qop != null)
+ ah.addQopParam(qop);
+ if (nc != null)
+ ah.addNcParam(nc);
+ if (cnonce != null)
+ ah.addCnonceParam(cnonce);
+ String response = getResponse();
+ ah.addResponseParam(response);
+ return ah;
+ }
+
+ /**
+ * Gets a new ProxyAuthorizationHeader based on current authentication
+ * attributes.
+ */
+ public ProxyAuthorizationHeader getProxyAuthorizationHeader() {
+ return new ProxyAuthorizationHeader(getAuthorizationHeader().getValue());
+ }
+
+ /**
+ * Calculates the digest-response.
+ *
+ * If the "qop" value is "auth" or "auth-int":
+ * KD ( H(A1), unq(nonce) ":" nc ":" unq(cnonce) ":" unq(qop) ":" H(A2) )
+ *
+ *
+ * If the "qop" directive is not present:
+ * KD ( H(A1), unq(nonce) ":" H(A2) )
+ */
+ public String getResponse() {
+ String secret = HEX(MD5(A1()));
+ StringBuffer sb = new StringBuffer();
+ if (nonce != null)
+ sb.append(nonce);
+ sb.append(":");
+ if (qop != null) {
+ if (nc != null)
+ sb.append(nc);
+ sb.append(":");
+ if (cnonce != null)
+ sb.append(cnonce);
+ sb.append(":");
+ sb.append(qop);
+ sb.append(":");
+ }
+ sb.append(HEX(MD5(A2())));
+ String data = sb.toString();
+ return HEX(KD(secret, data));
+ }
+
+ /**
+ * Calculates KD() value.
+ *
+ * KD(secret, data) = H(concat(secret, ":", data))
+ */
+ private byte[] KD(String secret, String data) {
+ StringBuffer sb = new StringBuffer();
+ sb.append(secret).append(":").append(data);
+ return MD5(sb.toString());
+ }
+
+ /**
+ * Calculates A1 value.
+ *
+ * If the "algorithm" directive's value is "MD5" or is unspecified:
+ * A1 = unq(username) ":" unq(realm) ":" passwd
+ *
+ *
+ * If the "algorithm" directive's value is "MD5-sess":
+ * A1 = H( unq(username) ":" unq(realm) ":" passwd ) ":" unq(nonce) ":"
+ * unq(cnonce)
+ */
+ private byte[] A1() {
+ StringBuffer sb = new StringBuffer();
+ if (username != null)
+ sb.append(username);
+ sb.append(":");
+ if (realm != null)
+ sb.append(realm);
+ sb.append(":");
+ if (passwd != null)
+ sb.append(passwd);
+
+ if (algorithm == null || !algorithm.equalsIgnoreCase("MD5-sess")) {
+ return sb.toString().getBytes();
+ } else {
+ StringBuffer sb2 = new StringBuffer();
+ sb2.append(":");
+ if (nonce != null)
+ sb2.append(nonce);
+ sb2.append(":");
+ if (cnonce != null)
+ sb2.append(cnonce);
+ return cat(MD5(sb.toString()), sb2.toString().getBytes());
+ }
+ }
+
+ /**
+ * Calculates A2 value.
+ *
+ * If the "qop" directive's value is "auth" or is unspecified:
+ * A2 = Method ":" digest-uri
+ *
+ *
+ * If the "qop" value is "auth-int":
+ * A2 = Method ":" digest-uri ":" H(entity-body)
+ */
+ private String A2() {
+ StringBuffer sb = new StringBuffer();
+ sb.append(method);
+ sb.append(":");
+ if (uri != null)
+ sb.append(uri);
+
+ if (qop != null && qop.equalsIgnoreCase("auth-int")) {
+ sb.append(":");
+ if (body == null)
+ sb.append(HEX(MD5("")));
+ else
+ sb.append(HEX(MD5(body)));
+ }
+ return sb.toString();
+ }
+
+ /** Concatenates two arrays of bytes. */
+ private static byte[] cat(byte[] a, byte[] b) {
+ int len = a.length + b.length;
+ byte[] c = new byte[len];
+ for (int i = 0; i < a.length; i++)
+ c[i] = a[i];
+ for (int i = 0; i < b.length; i++)
+ c[i + a.length] = b[i];
+ return c;
+ }
+
+ /** Calculates the MD5 of a String. */
+ private static byte[] MD5(String str) {
+ return MD5.digest(str);
+ }
+
+ /** Calculates the MD5 of an array of bytes. */
+ private static byte[] MD5(byte[] bb) {
+ return MD5.digest(bb);
+ }
+
+ /** Calculates the HEX of an array of bytes. */
+ private static String HEX(byte[] bb) {
+ return MD5.asHex(bb);
+ }
+
+ /**
+ * Main method. It tests DigestAuthentication with the example provided in
+ * the RFC2617.
+ */
+ public static void main(String[] args) {
+ /*
+ * Authorization: Digest username="Mufasa", realm="testrealm@host.com",
+ * nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093", uri="/dir/index.html",
+ * qop=auth, nc=00000001, cnonce="0a4f113b",
+ * response="6629fae49393a05397450978507c4ef1",
+ * opaque="5ccc069c403ebaf9f0171e9517f40e41"
+ */
+ DigestAuthentication a = new DigestAuthentication();
+ a.method = "GET";
+ a.passwd = "Circle Of Life";
+ a.realm = "testrealm@host.com";
+ a.nonce = "dcd98b7102dd2f0e8b11d0f600bfb0c093";
+ a.uri = "/dir/index.html";
+ a.qop = "auth";
+ a.nc = "00000001";
+ a.cnonce = "0a4f113b";
+ a.username = "Mufasa";
+
+ String response1 = a.getResponse();
+ String response2 = "6629fae49393a05397450978507c4ef1";
+ System.out.println(response1);
+ System.out.println(response2);
+
+ System.out.println(" ");
+
+ String ah_str = "Digest username=\"Mufasa\", realm=\"testrealm@host.com\", nonce=\"dcd98b7102dd2f0e8b11d0f600bfb0c093\", uri=\"/dir/index.html\", qop=auth, nc=00000001, cnonce=\"0a4f113b\", response=\"6629fae49393a05397450978507c4ef1\", opaque=\"5ccc069c403ebaf9f0171e9517f40e41\"\n";
+
+ AuthorizationHeader ah = new AuthorizationHeader(ah_str);
+ a = new DigestAuthentication("GET", ah, null, "Circle Of Life");
+ response1 = a.getResponse();
+ response2 = "6629fae49393a05397450978507c4ef1";
+ System.out.println(response1);
+ System.out.println(response2);
+
+ System.out.println(a.checkResponse());
+
+ }
+}
diff --git a/src/org/zoolu/sip/call/Call.java b/app/src/main/java/org/zoolu/sip/call/Call.java
similarity index 96%
rename from src/org/zoolu/sip/call/Call.java
rename to app/src/main/java/org/zoolu/sip/call/Call.java
index 446163e..54b19c9 100644
--- a/src/org/zoolu/sip/call/Call.java
+++ b/app/src/main/java/org/zoolu/sip/call/Call.java
@@ -1,532 +1,532 @@
-/*
- * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
- * Copyright (C) 2009 The Sipdroid Open Source Project
- *
- * This file is part of MjSip (http://www.mjsip.org)
- *
- * MjSip is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * MjSip is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with MjSip; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author(s):
- * Luca Veltri (luca.veltri@unipr.it)
- * Nitin Khanna, Hughes Systique Corp. (Reason: Android specific change, optmization, bug fix)
- */
-
-package org.zoolu.sip.call;
-
-import org.zoolu.sip.dialog.*;
-import org.zoolu.sip.provider.*;
-import org.zoolu.sip.message.*;
-import org.zoolu.sip.address.NameAddress;
-import org.zoolu.sip.header.MultipleHeader;
-import org.zoolu.tools.Log;
-import org.zoolu.tools.LogLevel;
-
-/* HSC CHANGES START */
-// import org.zoolu.sdp.*;
-// import java.util.Vector;
-/* HSC CHANGES END */
-
-/**
- * Class Call implements SIP calls.
- *
- * It handles both outgoing or incoming calls.
- *
- * Both offer/answer models are supported, that is:
- * i) offer/answer in invite/2xx, or
- * ii) offer/answer in 2xx/ack
- */
-public class Call implements InviteDialogListener {
- /** Event logger. */
- Log log;
-
- /** The SipProvider used for the call */
- protected SipProvider sip_provider;
-
- /** The invite dialog (sip.dialog.InviteDialog) */
- protected InviteDialog dialog;
-
- /** The user url */
- protected String from_url;
-
- /** The user contact url */
- protected String contact_url;
-
- /** The local sdp */
- protected String local_sdp;
-
- /** The remote sdp */
- protected String remote_sdp;
-
- /** The call listener (sipx.call.CallListener) */
- CallListener listener;
-
- /** Creates a new Call. */
- public Call(SipProvider sip_provider, String from_url, String contact_url,
- CallListener call_listener) {
- this.sip_provider = sip_provider;
- this.log = sip_provider.getLog();
- this.listener = call_listener;
- this.from_url = from_url;
- this.contact_url = contact_url;
- this.dialog = null;
- this.local_sdp = null;
- this.remote_sdp = null;
- }
-
- /** Creates a new Call specifing the sdp */
- /*
- * public Call(SipProvider sip_provider, String from_url, String
- * contact_url, String sdp, CallListener call_listener) {
- * this.sip_provider=sip_provider; this.log=sip_provider.getLog();
- * this.listener=call_listener; this.from_url=from_url;
- * this.contact_url=contact_url; local_sdp=sdp; }
- */
-
- /** Gets the current invite dialog */
- /*
- * public InviteDialog getInviteDialog() { return dialog; }
- */
-
- /** Gets the current local session descriptor */
- public String getLocalSessionDescriptor() {
- return local_sdp;
- }
-
- /** Sets a new local session descriptor */
- public void setLocalSessionDescriptor(String sdp) {
- local_sdp = sdp;
- }
-
- /** Gets the current remote session descriptor */
- public String getRemoteSessionDescriptor() {
- return remote_sdp;
- }
-
- /** Whether the call is on (active). */
- public boolean isOnCall() {
- return dialog.isSessionActive();
- }
-
- /** Waits for an incoming call */
- public void listen() {
- dialog = new InviteDialog(sip_provider, this);
- dialog.listen();
- }
-
- /** Starts a new call, inviting a remote user (callee) */
- public void call(String callee) {
- call(callee, null, null, null, null); // modified by mandrajg
- }
-
- /** Starts a new call, inviting a remote user (callee) */
- public void call(String callee, String sdp, String icsi) { // modified by mandrajg
- call(callee, null, null, sdp, icsi);
- }
-
- /** Starts a new call, inviting a remote user (callee) */
- public void call(String callee, String from, String contact, String sdp, String icsi) { // modified by mandrajg
- printLog("calling " + callee, LogLevel.HIGH);
- if (from == null)
- from = from_url;
- if (contact == null)
- contact = contact_url;
- if (sdp != null)
- local_sdp = sdp;
- dialog = new InviteDialog(sip_provider, this);
- if (local_sdp != null)
- dialog.invite(callee, from, contact, local_sdp, icsi); // modified by mandrajg
- else
- dialog.inviteWithoutOffer(callee, from, contact);
- }
-
- /** Starts a new call with the invite message request */
- public void call(Message invite) {
- dialog = new InviteDialog(sip_provider, this);
- local_sdp = invite.getBody();
- if (local_sdp != null)
- dialog.invite(invite);
- else
- dialog.inviteWithoutOffer(invite);
- }
-
- /** Answers at the 2xx/offer (in the ack message) */
- public void ackWithAnswer(String sdp) {
- local_sdp = sdp;
- dialog.ackWithAnswer(contact_url, sdp);
- }
-
- /** Rings back for the incoming call */
- public void ring(String sdp) { // modified
- local_sdp = sdp;
- if (dialog != null)
- dialog.ring(sdp);
- }
-
- /** Respond to a incoming call (invite) with resp */
- public void respond(Message resp) {
- if (dialog != null)
- dialog.respond(resp);
- }
-
- /** Accepts the incoming call */
- /*
- * public void accept() { accept(local_sdp); }
- */
-
- /** Accepts the incoming call */
- public void accept(String sdp) {
- local_sdp = sdp;
- if (dialog != null)
- dialog.accept(contact_url, local_sdp);
- }
-
- /** Redirects the incoming call */
- public void redirect(String redirect_url) {
- if (dialog != null)
- dialog.redirect(302, "Moved Temporarily", redirect_url);
- }
-
- /** Refuses the incoming call */
- public void refuse() {
- if (dialog != null)
- dialog.refuse();
- }
-
- /** Cancels the outgoing call */
- public void cancel() {
- if (dialog != null)
- dialog.cancel();
- }
-
- /** Close the ongoing call */
- public void bye() {
- if (dialog != null)
- dialog.bye();
- }
-
- /** Modify the current call */
- public void modify(String contact, String sdp) {
- local_sdp = sdp;
- if (dialog != null)
- dialog.reInvite(contact, local_sdp);
- }
-
- /**
- * Closes an ongoing or incoming/outgoing call
- *
- * It trys to fires refuse(), cancel(), and bye() methods
- */
- public void hangup() {
- if (dialog != null) { // try dialog.refuse(), cancel(), and bye()
- // methods..
- dialog.busy();
- dialog.cancel();
- dialog.bye();
- }
- }
-
- public void busy() {
- if (dialog != null)
- dialog.busy(); // modified
- }
-
- // ************** Inherited from InviteDialogListener **************
-
- /**
- * Inherited from class InviteDialogListener and called by an InviteDialag.
- * Normally you should not use it. Use specific callback methods instead
- * (e.g. onCallIncoming()).
- */
- public void onDlgInvite(InviteDialog d, NameAddress callee,
- NameAddress caller, String sdp, Message msg) {
- if (d != dialog) {
- printLog("NOT the current dialog", LogLevel.HIGH);
- return;
- }
- if (sdp != null && sdp.length() != 0)
- remote_sdp = sdp;
- if (listener != null)
- listener.onCallIncoming(this, callee, caller, sdp, msg);
- }
-
- /**
- * Inherited from class InviteDialogListener and called by an InviteDialag.
- * Normally you should not use it. Use specific callback methods instead
- * (e.g. onCallModifying()).
- */
- public void onDlgReInvite(InviteDialog d, String sdp, Message msg) {
- if (d != dialog) {
- printLog("NOT the current dialog", LogLevel.HIGH);
- return;
- }
- if (sdp != null && sdp.length() != 0)
- remote_sdp = sdp;
- if (listener != null)
- listener.onCallModifying(this, sdp, msg);
- }
-
- /**
- * Inherited from class InviteDialogListener and called by an InviteDialag.
- * Normally you should not use it. Use specific callback methods instead
- * (e.g. onCallRinging()).
- */
- public void onDlgInviteProvisionalResponse(InviteDialog d, int code,
- String reason, String sdp, Message msg) {
- if (d != dialog) {
- printLog("NOT the current dialog", LogLevel.HIGH);
- return;
- }
- if (sdp != null && sdp.length() != 0)
- remote_sdp = sdp;
- if (code == 180 || code == 183) // modified
- if (listener != null)
- listener.onCallRinging(this, msg);
- }
-
- /**
- * Inherited from class InviteDialogListener and called by an InviteDialag.
- * Normally you should not use it. Use specific callback methods instead
- * (e.g. onCallAccepted()).
- */
- public void onDlgInviteSuccessResponse(InviteDialog d, int code,
- String reason, String sdp, Message msg) {
- if (d != dialog) {
- printLog("NOT the current dialog", LogLevel.HIGH);
- return;
- }
- if (sdp != null && sdp.length() != 0)
- remote_sdp = sdp;
- if (listener != null)
- listener.onCallAccepted(this, sdp, msg);
- }
-
- /**
- * Inherited from class InviteDialogListener and called by an InviteDialag.
- * Normally you should not use it. Use specific callback methods instead
- * (e.g. onCallRedirection()).
- */
- public void onDlgInviteRedirectResponse(InviteDialog d, int code,
- String reason, MultipleHeader contacts, Message msg) {
- if (d != dialog) {
- printLog("NOT the current dialog", LogLevel.HIGH);
- return;
- }
- if (listener != null)
- listener.onCallRedirection(this, reason, contacts.getValues(), msg);
- }
-
- /**
- * Inherited from class InviteDialogListener and called by an InviteDialag.
- * Normally you should not use it. Use specific callback methods instead
- * (e.g. onCallRefused()).
- */
- public void onDlgInviteFailureResponse(InviteDialog d, int code,
- String reason, Message msg) {
- if (d != dialog) {
- printLog("NOT the current dialog", LogLevel.HIGH);
- return;
- }
- if (listener != null)
- listener.onCallRefused(this, reason, msg);
- }
-
- /**
- * Inherited from class InviteDialogListener and called by an InviteDialag.
- * Normally you should not use it. Use specific callback methods instead
- * (e.g. onCallTimeout()).
- */
- public void onDlgTimeout(InviteDialog d) {
- if (d != dialog) {
- printLog("NOT the current dialog", LogLevel.HIGH);
- return;
- }
- if (listener != null)
- listener.onCallTimeout(this);
- }
-
- /**
- * Inherited from class InviteDialogListener and called by an InviteDialag.
- * Normally you should not use it.
- */
- public void onDlgReInviteProvisionalResponse(InviteDialog d, int code,
- String reason, String sdp, Message msg) {
- if (d != dialog) {
- printLog("NOT the current dialog", LogLevel.HIGH);
- return;
- }
- if (sdp != null && sdp.length() != 0)
- remote_sdp = sdp;
- }
-
- /**
- * Inherited from class InviteDialogListener and called by an InviteDialag.
- * Normally you should not use it. Use specific callback methods instead
- * (e.g. onCallReInviteAccepted()).
- */
- public void onDlgReInviteSuccessResponse(InviteDialog d, int code,
- String reason, String sdp, Message msg) {
- if (d != dialog) {
- printLog("NOT the current dialog", LogLevel.HIGH);
- return;
- }
- if (sdp != null && sdp.length() != 0)
- remote_sdp = sdp;
- if (listener != null)
- listener.onCallReInviteAccepted(this, sdp, msg);
- }
-
- /**
- * Inherited from class InviteDialogListener and called by an InviteDialag.
- * Normally you should not use it. Use specific callback methods instead
- * (e.g. onCallReInviteRedirection()).
- */
- // public void onDlgReInviteRedirectResponse(InviteDialog d, int code,
- // String reason, MultipleHeader contacts, Message msg)
- // { if (d!=dialog) { printLog("NOT the current dialog",LogLevel.HIGH);
- // return; }
- // if (listener!=null)
- // listener.onCallReInviteRedirection(this,reason,contacts.getValues(),msg);
- // }
- /**
- * Inherited from class InviteDialogListener and called by an InviteDialag.
- * Normally you should not use it. Use specific callback methods instead
- * (e.g. onCallReInviteRefused()).
- */
- public void onDlgReInviteFailureResponse(InviteDialog d, int code,
- String reason, Message msg) {
- if (d != dialog) {
- printLog("NOT the current dialog", LogLevel.HIGH);
- return;
- }
- if (listener != null)
- listener.onCallReInviteRefused(this, reason, msg);
- }
-
- /**
- * Inherited from class InviteDialogListener and called by an InviteDialag.
- * Normally you should not use it. Use specific callback methods instead
- * (e.g. onCallReInviteTimeout()).
- */
- public void onDlgReInviteTimeout(InviteDialog d) {
- if (d != dialog) {
- printLog("NOT the current dialog", LogLevel.HIGH);
- return;
- }
- if (listener != null)
- listener.onCallReInviteTimeout(this);
- }
-
- /**
- * Inherited from class InviteDialogListener and called by an InviteDialag.
- * Normally you should not use it. Use specific callback methods instead
- * (e.g. onCallConfirmed()).
- */
- public void onDlgAck(InviteDialog d, String sdp, Message msg) {
- if (d != dialog) {
- printLog("NOT the current dialog", LogLevel.HIGH);
- return;
- }
- if (sdp != null && sdp.length() != 0)
- remote_sdp = sdp;
- if (listener != null)
- listener.onCallConfirmed(this, sdp, msg);
- }
-
- /**
- * Inherited from class InviteDialogListener and called by an InviteDialag.
- * Normally you should not use it. Use specific callback methods instead
- * (e.g. onCallClosing()).
- */
- public void onDlgCancel(InviteDialog d, Message msg) {
- if (d != dialog) {
- printLog("NOT the current dialog", LogLevel.HIGH);
- return;
- }
- if (listener != null)
- listener.onCallCanceling(this, msg);
- }
-
- /**
- * Inherited from class InviteDialogListener and called by an InviteDialag.
- * Normally you should not use it. Use specific callback methods instead
- * (e.g. onClosing()).
- */
- public void onDlgBye(InviteDialog d, Message msg) {
- if (d != dialog) {
- printLog("NOT the current dialog", LogLevel.HIGH);
- return;
- }
- if (listener != null)
- listener.onCallClosing(this, msg);
- }
-
- /**
- * Inherited from class InviteDialogListener and called by an InviteDialag.
- * Normally you should not use it. Use specific callback methods instead
- * (e.g. onClosed()).
- */
- public void onDlgByeFailureResponse(InviteDialog d, int code,
- String reason, Message msg) {
- if (d != dialog) {
- printLog("NOT the current dialog", LogLevel.HIGH);
- return;
- }
- if (listener != null)
- listener.onCallClosed(this, msg);
- }
-
- /**
- * Inherited from class InviteDialogListener and called by an InviteDialag.
- * Normally you should not use it. Use specific callback methods instead
- * (e.g. onClosed()).
- */
- public void onDlgByeSuccessResponse(InviteDialog d, int code,
- String reason, Message msg) {
- if (d != dialog) {
- printLog("NOT the current dialog", LogLevel.HIGH);
- return;
- }
- if (listener != null)
- listener.onCallClosed(this, msg);
- }
-
- // -----------------------------------------------------
-
- /** When an incoming INVITE is accepted */
- // public void onDlgAccepted(InviteDialog dialog) {}
- /** When an incoming INVITE is refused */
- // public void onDlgRefused(InviteDialog dialog) {}
- /** When the INVITE handshake is successful terminated */
- public void onDlgCall(InviteDialog dialog) {
- }
-
- /** When an incoming Re-INVITE is accepted */
- // public void onDlgReInviteAccepted(InviteDialog dialog) {}
- /** When an incoming Re-INVITE is refused */
- // public void onDlgReInviteRefused(InviteDialog dialog) {}
- /** When a BYE request traqnsaction has been started */
- // public void onDlgByeing(InviteDialog dialog) {}
- /** When the dialog is finally closed */
- public void onDlgClose(InviteDialog dialog) {
- }
-
- // **************************** Logs ****************************/
-
- /** Adds a new string to the default Log */
- protected void printLog(String str, int level) {
- if (log != null)
- log.println("Call: " + str, level + SipStack.LOG_LEVEL_CALL);
- }
-}
+/*
+ * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
+ * Copyright (C) 2009 The Sipdroid Open Source Project
+ *
+ * This file is part of MjSip (http://www.mjsip.org)
+ *
+ * MjSip is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * MjSip is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MjSip; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author(s):
+ * Luca Veltri (luca.veltri@unipr.it)
+ * Nitin Khanna, Hughes Systique Corp. (Reason: Android specific change, optmization, bug fix)
+ */
+
+package org.zoolu.sip.call;
+
+import org.zoolu.sip.dialog.*;
+import org.zoolu.sip.provider.*;
+import org.zoolu.sip.message.*;
+import org.zoolu.sip.address.NameAddress;
+import org.zoolu.sip.header.MultipleHeader;
+import org.zoolu.tools.Log;
+import org.zoolu.tools.LogLevel;
+
+/* HSC CHANGES START */
+// import org.zoolu.sdp.*;
+// import java.util.Vector;
+/* HSC CHANGES END */
+
+/**
+ * Class Call implements SIP calls.
+ *
+ * It handles both outgoing or incoming calls.
+ *
+ * Both offer/answer models are supported, that is:
+ * i) offer/answer in invite/2xx, or
+ * ii) offer/answer in 2xx/ack
+ */
+public class Call implements InviteDialogListener {
+ /** Event logger. */
+ Log log;
+
+ /** The SipProvider used for the call */
+ protected SipProvider sip_provider;
+
+ /** The invite dialog (sip.dialog.InviteDialog) */
+ protected InviteDialog dialog;
+
+ /** The user url */
+ protected String from_url;
+
+ /** The user contact url */
+ protected String contact_url;
+
+ /** The local sdp */
+ protected String local_sdp;
+
+ /** The remote sdp */
+ protected String remote_sdp;
+
+ /** The call listener (sipx.call.CallListener) */
+ CallListener listener;
+
+ /** Creates a new Call. */
+ public Call(SipProvider sip_provider, String from_url, String contact_url,
+ CallListener call_listener) {
+ this.sip_provider = sip_provider;
+ this.log = sip_provider.getLog();
+ this.listener = call_listener;
+ this.from_url = from_url;
+ this.contact_url = contact_url;
+ this.dialog = null;
+ this.local_sdp = null;
+ this.remote_sdp = null;
+ }
+
+ /** Creates a new Call specifing the sdp */
+ /*
+ * public Call(SipProvider sip_provider, String from_url, String
+ * contact_url, String sdp, CallListener call_listener) {
+ * this.sip_provider=sip_provider; this.log=sip_provider.getLog();
+ * this.listener=call_listener; this.from_url=from_url;
+ * this.contact_url=contact_url; local_sdp=sdp; }
+ */
+
+ /** Gets the current invite dialog */
+ /*
+ * public InviteDialog getInviteDialog() { return dialog; }
+ */
+
+ /** Gets the current local session descriptor */
+ public String getLocalSessionDescriptor() {
+ return local_sdp;
+ }
+
+ /** Sets a new local session descriptor */
+ public void setLocalSessionDescriptor(String sdp) {
+ local_sdp = sdp;
+ }
+
+ /** Gets the current remote session descriptor */
+ public String getRemoteSessionDescriptor() {
+ return remote_sdp;
+ }
+
+ /** Whether the call is on (active). */
+ public boolean isOnCall() {
+ return dialog.isSessionActive();
+ }
+
+ /** Waits for an incoming call */
+ public void listen() {
+ dialog = new InviteDialog(sip_provider, this);
+ dialog.listen();
+ }
+
+ /** Starts a new call, inviting a remote user (callee) */
+ public void call(String callee) {
+ call(callee, null, null, null, null); // modified by mandrajg
+ }
+
+ /** Starts a new call, inviting a remote user (callee) */
+ public void call(String callee, String sdp, String icsi) { // modified by mandrajg
+ call(callee, null, null, sdp, icsi);
+ }
+
+ /** Starts a new call, inviting a remote user (callee) */
+ public void call(String callee, String from, String contact, String sdp, String icsi) { // modified by mandrajg
+ printLog("calling " + callee, LogLevel.HIGH);
+ if (from == null)
+ from = from_url;
+ if (contact == null)
+ contact = contact_url;
+ if (sdp != null)
+ local_sdp = sdp;
+ dialog = new InviteDialog(sip_provider, this);
+ if (local_sdp != null)
+ dialog.invite(callee, from, contact, local_sdp, icsi); // modified by mandrajg
+ else
+ dialog.inviteWithoutOffer(callee, from, contact);
+ }
+
+ /** Starts a new call with the invite message request */
+ public void call(Message invite) {
+ dialog = new InviteDialog(sip_provider, this);
+ local_sdp = invite.getBody();
+ if (local_sdp != null)
+ dialog.invite(invite);
+ else
+ dialog.inviteWithoutOffer(invite);
+ }
+
+ /** Answers at the 2xx/offer (in the ack message) */
+ public void ackWithAnswer(String sdp) {
+ local_sdp = sdp;
+ dialog.ackWithAnswer(contact_url, sdp);
+ }
+
+ /** Rings back for the incoming call */
+ public void ring(String sdp) { // modified
+ local_sdp = sdp;
+ if (dialog != null)
+ dialog.ring(sdp);
+ }
+
+ /** Respond to a incoming call (invite) with resp */
+ public void respond(Message resp) {
+ if (dialog != null)
+ dialog.respond(resp);
+ }
+
+ /** Accepts the incoming call */
+ /*
+ * public void accept() { accept(local_sdp); }
+ */
+
+ /** Accepts the incoming call */
+ public void accept(String sdp) {
+ local_sdp = sdp;
+ if (dialog != null)
+ dialog.accept(contact_url, local_sdp);
+ }
+
+ /** Redirects the incoming call */
+ public void redirect(String redirect_url) {
+ if (dialog != null)
+ dialog.redirect(302, "Moved Temporarily", redirect_url);
+ }
+
+ /** Refuses the incoming call */
+ public void refuse() {
+ if (dialog != null)
+ dialog.refuse();
+ }
+
+ /** Cancels the outgoing call */
+ public void cancel() {
+ if (dialog != null)
+ dialog.cancel();
+ }
+
+ /** Close the ongoing call */
+ public void bye() {
+ if (dialog != null)
+ dialog.bye();
+ }
+
+ /** Modify the current call */
+ public void modify(String contact, String sdp) {
+ local_sdp = sdp;
+ if (dialog != null)
+ dialog.reInvite(contact, local_sdp);
+ }
+
+ /**
+ * Closes an ongoing or incoming/outgoing call
+ *
+ * It trys to fires refuse(), cancel(), and bye() methods
+ */
+ public void hangup() {
+ if (dialog != null) { // try dialog.refuse(), cancel(), and bye()
+ // methods..
+ dialog.busy();
+ dialog.cancel();
+ dialog.bye();
+ }
+ }
+
+ public void busy() {
+ if (dialog != null)
+ dialog.busy(); // modified
+ }
+
+ // ************** Inherited from InviteDialogListener **************
+
+ /**
+ * Inherited from class InviteDialogListener and called by an InviteDialag.
+ * Normally you should not use it. Use specific callback methods instead
+ * (e.g. onCallIncoming()).
+ */
+ public void onDlgInvite(InviteDialog d, NameAddress callee,
+ NameAddress caller, String sdp, Message msg) {
+ if (d != dialog) {
+ printLog("NOT the current dialog", LogLevel.HIGH);
+ return;
+ }
+ if (sdp != null && sdp.length() != 0)
+ remote_sdp = sdp;
+ if (listener != null)
+ listener.onCallIncoming(this, callee, caller, sdp, msg);
+ }
+
+ /**
+ * Inherited from class InviteDialogListener and called by an InviteDialag.
+ * Normally you should not use it. Use specific callback methods instead
+ * (e.g. onCallModifying()).
+ */
+ public void onDlgReInvite(InviteDialog d, String sdp, Message msg) {
+ if (d != dialog) {
+ printLog("NOT the current dialog", LogLevel.HIGH);
+ return;
+ }
+ if (sdp != null && sdp.length() != 0)
+ remote_sdp = sdp;
+ if (listener != null)
+ listener.onCallModifying(this, sdp, msg);
+ }
+
+ /**
+ * Inherited from class InviteDialogListener and called by an InviteDialag.
+ * Normally you should not use it. Use specific callback methods instead
+ * (e.g. onCallRinging()).
+ */
+ public void onDlgInviteProvisionalResponse(InviteDialog d, int code,
+ String reason, String sdp, Message msg) {
+ if (d != dialog) {
+ printLog("NOT the current dialog", LogLevel.HIGH);
+ return;
+ }
+ if (sdp != null && sdp.length() != 0)
+ remote_sdp = sdp;
+ if (code == 180 || code == 183) // modified
+ if (listener != null)
+ listener.onCallRinging(this, msg);
+ }
+
+ /**
+ * Inherited from class InviteDialogListener and called by an InviteDialag.
+ * Normally you should not use it. Use specific callback methods instead
+ * (e.g. onCallAccepted()).
+ */
+ public void onDlgInviteSuccessResponse(InviteDialog d, int code,
+ String reason, String sdp, Message msg) {
+ if (d != dialog) {
+ printLog("NOT the current dialog", LogLevel.HIGH);
+ return;
+ }
+ if (sdp != null && sdp.length() != 0)
+ remote_sdp = sdp;
+ if (listener != null)
+ listener.onCallAccepted(this, sdp, msg);
+ }
+
+ /**
+ * Inherited from class InviteDialogListener and called by an InviteDialag.
+ * Normally you should not use it. Use specific callback methods instead
+ * (e.g. onCallRedirection()).
+ */
+ public void onDlgInviteRedirectResponse(InviteDialog d, int code,
+ String reason, MultipleHeader contacts, Message msg) {
+ if (d != dialog) {
+ printLog("NOT the current dialog", LogLevel.HIGH);
+ return;
+ }
+ if (listener != null)
+ listener.onCallRedirection(this, reason, contacts.getValues(), msg);
+ }
+
+ /**
+ * Inherited from class InviteDialogListener and called by an InviteDialag.
+ * Normally you should not use it. Use specific callback methods instead
+ * (e.g. onCallRefused()).
+ */
+ public void onDlgInviteFailureResponse(InviteDialog d, int code,
+ String reason, Message msg) {
+ if (d != dialog) {
+ printLog("NOT the current dialog", LogLevel.HIGH);
+ return;
+ }
+ if (listener != null)
+ listener.onCallRefused(this, reason, msg);
+ }
+
+ /**
+ * Inherited from class InviteDialogListener and called by an InviteDialag.
+ * Normally you should not use it. Use specific callback methods instead
+ * (e.g. onCallTimeout()).
+ */
+ public void onDlgTimeout(InviteDialog d) {
+ if (d != dialog) {
+ printLog("NOT the current dialog", LogLevel.HIGH);
+ return;
+ }
+ if (listener != null)
+ listener.onCallTimeout(this);
+ }
+
+ /**
+ * Inherited from class InviteDialogListener and called by an InviteDialag.
+ * Normally you should not use it.
+ */
+ public void onDlgReInviteProvisionalResponse(InviteDialog d, int code,
+ String reason, String sdp, Message msg) {
+ if (d != dialog) {
+ printLog("NOT the current dialog", LogLevel.HIGH);
+ return;
+ }
+ if (sdp != null && sdp.length() != 0)
+ remote_sdp = sdp;
+ }
+
+ /**
+ * Inherited from class InviteDialogListener and called by an InviteDialag.
+ * Normally you should not use it. Use specific callback methods instead
+ * (e.g. onCallReInviteAccepted()).
+ */
+ public void onDlgReInviteSuccessResponse(InviteDialog d, int code,
+ String reason, String sdp, Message msg) {
+ if (d != dialog) {
+ printLog("NOT the current dialog", LogLevel.HIGH);
+ return;
+ }
+ if (sdp != null && sdp.length() != 0)
+ remote_sdp = sdp;
+ if (listener != null)
+ listener.onCallReInviteAccepted(this, sdp, msg);
+ }
+
+ /**
+ * Inherited from class InviteDialogListener and called by an InviteDialag.
+ * Normally you should not use it. Use specific callback methods instead
+ * (e.g. onCallReInviteRedirection()).
+ */
+ // public void onDlgReInviteRedirectResponse(InviteDialog d, int code,
+ // String reason, MultipleHeader contacts, Message msg)
+ // { if (d!=dialog) { printLog("NOT the current dialog",LogLevel.HIGH);
+ // return; }
+ // if (listener!=null)
+ // listener.onCallReInviteRedirection(this,reason,contacts.getValues(),msg);
+ // }
+ /**
+ * Inherited from class InviteDialogListener and called by an InviteDialag.
+ * Normally you should not use it. Use specific callback methods instead
+ * (e.g. onCallReInviteRefused()).
+ */
+ public void onDlgReInviteFailureResponse(InviteDialog d, int code,
+ String reason, Message msg) {
+ if (d != dialog) {
+ printLog("NOT the current dialog", LogLevel.HIGH);
+ return;
+ }
+ if (listener != null)
+ listener.onCallReInviteRefused(this, reason, msg);
+ }
+
+ /**
+ * Inherited from class InviteDialogListener and called by an InviteDialag.
+ * Normally you should not use it. Use specific callback methods instead
+ * (e.g. onCallReInviteTimeout()).
+ */
+ public void onDlgReInviteTimeout(InviteDialog d) {
+ if (d != dialog) {
+ printLog("NOT the current dialog", LogLevel.HIGH);
+ return;
+ }
+ if (listener != null)
+ listener.onCallReInviteTimeout(this);
+ }
+
+ /**
+ * Inherited from class InviteDialogListener and called by an InviteDialag.
+ * Normally you should not use it. Use specific callback methods instead
+ * (e.g. onCallConfirmed()).
+ */
+ public void onDlgAck(InviteDialog d, String sdp, Message msg) {
+ if (d != dialog) {
+ printLog("NOT the current dialog", LogLevel.HIGH);
+ return;
+ }
+ if (sdp != null && sdp.length() != 0)
+ remote_sdp = sdp;
+ if (listener != null)
+ listener.onCallConfirmed(this, sdp, msg);
+ }
+
+ /**
+ * Inherited from class InviteDialogListener and called by an InviteDialag.
+ * Normally you should not use it. Use specific callback methods instead
+ * (e.g. onCallClosing()).
+ */
+ public void onDlgCancel(InviteDialog d, Message msg) {
+ if (d != dialog) {
+ printLog("NOT the current dialog", LogLevel.HIGH);
+ return;
+ }
+ if (listener != null)
+ listener.onCallCanceling(this, msg);
+ }
+
+ /**
+ * Inherited from class InviteDialogListener and called by an InviteDialag.
+ * Normally you should not use it. Use specific callback methods instead
+ * (e.g. onClosing()).
+ */
+ public void onDlgBye(InviteDialog d, Message msg) {
+ if (d != dialog) {
+ printLog("NOT the current dialog", LogLevel.HIGH);
+ return;
+ }
+ if (listener != null)
+ listener.onCallClosing(this, msg);
+ }
+
+ /**
+ * Inherited from class InviteDialogListener and called by an InviteDialag.
+ * Normally you should not use it. Use specific callback methods instead
+ * (e.g. onClosed()).
+ */
+ public void onDlgByeFailureResponse(InviteDialog d, int code,
+ String reason, Message msg) {
+ if (d != dialog) {
+ printLog("NOT the current dialog", LogLevel.HIGH);
+ return;
+ }
+ if (listener != null)
+ listener.onCallClosed(this, msg);
+ }
+
+ /**
+ * Inherited from class InviteDialogListener and called by an InviteDialag.
+ * Normally you should not use it. Use specific callback methods instead
+ * (e.g. onClosed()).
+ */
+ public void onDlgByeSuccessResponse(InviteDialog d, int code,
+ String reason, Message msg) {
+ if (d != dialog) {
+ printLog("NOT the current dialog", LogLevel.HIGH);
+ return;
+ }
+ if (listener != null)
+ listener.onCallClosed(this, msg);
+ }
+
+ // -----------------------------------------------------
+
+ /** When an incoming INVITE is accepted */
+ // public void onDlgAccepted(InviteDialog dialog) {}
+ /** When an incoming INVITE is refused */
+ // public void onDlgRefused(InviteDialog dialog) {}
+ /** When the INVITE handshake is successful terminated */
+ public void onDlgCall(InviteDialog dialog) {
+ }
+
+ /** When an incoming Re-INVITE is accepted */
+ // public void onDlgReInviteAccepted(InviteDialog dialog) {}
+ /** When an incoming Re-INVITE is refused */
+ // public void onDlgReInviteRefused(InviteDialog dialog) {}
+ /** When a BYE request traqnsaction has been started */
+ // public void onDlgByeing(InviteDialog dialog) {}
+ /** When the dialog is finally closed */
+ public void onDlgClose(InviteDialog dialog) {
+ }
+
+ // **************************** Logs ****************************/
+
+ /** Adds a new string to the default Log */
+ protected void printLog(String str, int level) {
+ if (log != null)
+ log.println("Call: " + str, level + SipStack.LOG_LEVEL_CALL);
+ }
+}
diff --git a/src/org/zoolu/sip/call/CallListener.java b/app/src/main/java/org/zoolu/sip/call/CallListener.java
similarity index 97%
rename from src/org/zoolu/sip/call/CallListener.java
rename to app/src/main/java/org/zoolu/sip/call/CallListener.java
index b8e8408..5dd48de 100644
--- a/src/org/zoolu/sip/call/CallListener.java
+++ b/app/src/main/java/org/zoolu/sip/call/CallListener.java
@@ -1,93 +1,93 @@
-/*
- * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
- *
- * This file is part of MjSip (http://www.mjsip.org)
- *
- * MjSip is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * MjSip is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with MjSip; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author(s):
- * Luca Veltri (luca.veltri@unipr.it)
- */
-
-package org.zoolu.sip.call;
-
-import org.zoolu.sip.message.*;
-import org.zoolu.sip.address.NameAddress;
-import java.util.Vector;
-
-/**
- * Interface CallListener can be implemented to manage SIP calls
- * (sipx.call.Call).
- *
- * Objects of class Call use CallListener callback methods to signal specific
- * call events.
- */
-public interface CallListener {
- /**
- * Callback function called when arriving a new INVITE method (incoming
- * call)
- */
- public void onCallIncoming(Call call, NameAddress callee,
- NameAddress caller, String sdp, Message invite);
-
- /**
- * Callback function called when arriving a new Re-INVITE method
- * (re-inviting/call modify)
- */
- public void onCallModifying(Call call, String sdp, Message invite);
-
- /** Callback function called when arriving a 180 Ringing */
- public void onCallRinging(Call call, Message resp);
-
- /** Callback function called when arriving a 2xx (call accepted) */
- public void onCallAccepted(Call call, String sdp, Message resp);
-
- /** Callback function called when arriving a 4xx (call failure) */
- public void onCallRefused(Call call, String reason, Message resp);
-
- /** Callback function called when arriving a 3xx (call redirection) */
- public void onCallRedirection(Call call, String reason,
- Vector contact_list, Message resp);
-
- /** Callback function called when arriving an ACK method (call confirmed) */
- public void onCallConfirmed(Call call, String sdp, Message ack);
-
- /** Callback function called when the invite expires */
- public void onCallTimeout(Call call);
-
- /** Callback function called when arriving a 2xx (re-invite/modify accepted) */
- public void onCallReInviteAccepted(Call call, String sdp, Message resp);
-
- /** Callback function called when arriving a 4xx (re-invite/modify failure) */
- public void onCallReInviteRefused(Call call, String reason, Message resp);
-
- /** Callback function called when a re-invite expires */
- public void onCallReInviteTimeout(Call call);
-
- /** Callback function called when arriving a 3xx (call redirection) */
- // public void onCallReInviteRedirection(Call call, String reason, Vector
- // contact_list, Message resp);
- /** Callback function called when arriving a CANCEL request */
- public void onCallCanceling(Call call, Message cancel);
-
- /** Callback function called when arriving a BYE request */
- public void onCallClosing(Call call, Message bye);
-
- /**
- * Callback function called when arriving a response for the BYE request
- * (call closed)
- */
- public void onCallClosed(Call call, Message resp);
-}
+/*
+ * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
+ *
+ * This file is part of MjSip (http://www.mjsip.org)
+ *
+ * MjSip is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * MjSip is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MjSip; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author(s):
+ * Luca Veltri (luca.veltri@unipr.it)
+ */
+
+package org.zoolu.sip.call;
+
+import org.zoolu.sip.message.*;
+import org.zoolu.sip.address.NameAddress;
+import java.util.Vector;
+
+/**
+ * Interface CallListener can be implemented to manage SIP calls
+ * (sipx.call.Call).
+ *
+ * Objects of class Call use CallListener callback methods to signal specific
+ * call events.
+ */
+public interface CallListener {
+ /**
+ * Callback function called when arriving a new INVITE method (incoming
+ * call)
+ */
+ public void onCallIncoming(Call call, NameAddress callee,
+ NameAddress caller, String sdp, Message invite);
+
+ /**
+ * Callback function called when arriving a new Re-INVITE method
+ * (re-inviting/call modify)
+ */
+ public void onCallModifying(Call call, String sdp, Message invite);
+
+ /** Callback function called when arriving a 180 Ringing */
+ public void onCallRinging(Call call, Message resp);
+
+ /** Callback function called when arriving a 2xx (call accepted) */
+ public void onCallAccepted(Call call, String sdp, Message resp);
+
+ /** Callback function called when arriving a 4xx (call failure) */
+ public void onCallRefused(Call call, String reason, Message resp);
+
+ /** Callback function called when arriving a 3xx (call redirection) */
+ public void onCallRedirection(Call call, String reason,
+ Vector contact_list, Message resp);
+
+ /** Callback function called when arriving an ACK method (call confirmed) */
+ public void onCallConfirmed(Call call, String sdp, Message ack);
+
+ /** Callback function called when the invite expires */
+ public void onCallTimeout(Call call);
+
+ /** Callback function called when arriving a 2xx (re-invite/modify accepted) */
+ public void onCallReInviteAccepted(Call call, String sdp, Message resp);
+
+ /** Callback function called when arriving a 4xx (re-invite/modify failure) */
+ public void onCallReInviteRefused(Call call, String reason, Message resp);
+
+ /** Callback function called when a re-invite expires */
+ public void onCallReInviteTimeout(Call call);
+
+ /** Callback function called when arriving a 3xx (call redirection) */
+ // public void onCallReInviteRedirection(Call call, String reason, Vector
+ // contact_list, Message resp);
+ /** Callback function called when arriving a CANCEL request */
+ public void onCallCanceling(Call call, Message cancel);
+
+ /** Callback function called when arriving a BYE request */
+ public void onCallClosing(Call call, Message bye);
+
+ /**
+ * Callback function called when arriving a response for the BYE request
+ * (call closed)
+ */
+ public void onCallClosed(Call call, Message resp);
+}
diff --git a/src/org/zoolu/sip/call/CallListenerAdapter.java b/app/src/main/java/org/zoolu/sip/call/CallListenerAdapter.java
similarity index 97%
rename from src/org/zoolu/sip/call/CallListenerAdapter.java
rename to app/src/main/java/org/zoolu/sip/call/CallListenerAdapter.java
index 4788194..414e7c9 100644
--- a/src/org/zoolu/sip/call/CallListenerAdapter.java
+++ b/app/src/main/java/org/zoolu/sip/call/CallListenerAdapter.java
@@ -1,260 +1,260 @@
-/*
- * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
- * Copyright (C) 2009 The Sipdroid Open Source Project
- *
- * This file is part of MjSip (http://www.mjsip.org)
- *
- * MjSip is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * MjSip is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with MjSip; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author(s):
- * Luca Veltri (luca.veltri@unipr.it)
- * Nitin Khanna, Hughes Systique Corp. (Reason: Android specific change, optmization, bug fix)
- */
-
-package org.zoolu.sip.call;
-
-/* HSC CHANGES START */
-// import org.zoolu.sip.call.*;
-// import org.zoolu.sip.provider.SipStack;
-/* HSC CHANGES END */
-import org.zoolu.sip.address.NameAddress;
-import org.zoolu.sip.message.Message; /* HSC CHANGES START */// import
- // org.zoolu.tools.Log;
-// import org.zoolu.tools.LogLevel;
-/* HSC CHANGES END */
-
-import org.zoolu.sdp.*; /* HSC CHANGES START */// import java.util.Iterator;
-// import java.util.Enumeration;
-/* HSC CHANGES END */
-
-import java.util.Vector;
-
-/**
- * Class CallListenerAdapter implements CallListener interface providing a dummy
- * implementation of all Call callback functions used to capture Call events.
- *
- * CallListenerAdapter can be extended to manage basic SIP calls. The callback
- * methods defined in this class have basically a void implementation. This
- * class exists as convenience for creating call listener objects.
- * You can extend this class overriding only methods corresponding to events you
- * want to handle.
- *
- * onCallIncoming(NameAddress,String) is the only non-empty method. It
- * signals the receiver the ring status (by using method Call.ring()), adapts
- * the sdp body and accepts the call (by using method Call.accept(sdp)).
- */
-public abstract class CallListenerAdapter implements ExtendedCallListener {
-
- // ************************** Costructors ***************************
-
- /** Creates a new dummy call listener */
- protected CallListenerAdapter() {
- }
-
- // ************************* Static methods *************************
-
- /**
- * Changes the current session descriptor specifing the receiving RTP/UDP
- * port number, the AVP format, the codec, and the clock rate
- */
- /*
- * public static String audioSession(int port, int avp, String codec, int
- * rate) { SessionDescriptor sdp=new SessionDescriptor(); sdp.addMedia(new
- * MediaField("audio ",port,0,"RTP/AVP",String.valueOf(avp)),new
- * AttributeField("rtpmap",avp+" "+codec+"/"+rate)); return sdp.toString(); }
- */
-
- /**
- * Changes the current session descriptor specifing the receiving RTP/UDP
- * port number, the AVP format, the codec, and the clock rate
- */
- /*
- * public static String audioSession(int port) { return
- * audioSession(port,0,"PCMU",8000); }
- */
-
- // *********************** Callback functions ***********************
- /**
- * Accepts an incoming call. Callback function called when arriving a new
- * INVITE method (incoming call)
- */
- public void onCallIncoming(Call call, NameAddress callee,
- NameAddress caller, String sdp, Message invite) { // printLog("INCOMING");
- String local_session;
- if (sdp != null && sdp.length() > 0) {
- SessionDescriptor remote_sdp = new SessionDescriptor(sdp);
- SessionDescriptor local_sdp = new SessionDescriptor(call
- .getLocalSessionDescriptor());
- SessionDescriptor new_sdp = new SessionDescriptor(remote_sdp
- .getOrigin(), remote_sdp.getSessionName(), local_sdp
- .getConnection(), local_sdp.getTime());
- new_sdp.addMediaDescriptors(local_sdp.getMediaDescriptors());
- new_sdp = SdpTools.sdpMediaProduct(new_sdp, remote_sdp
- .getMediaDescriptors());
- new_sdp = SdpTools.sdpAttirbuteSelection(new_sdp, "rtpmap");
- local_session = new_sdp.toString();
- } else
- local_session = call.getLocalSessionDescriptor();
- call.ring(local_session);
- // accept immediatly
- call.accept(local_session);
- }
-
- /**
- * Changes the call when remotly requested. Callback function called when
- * arriving a new Re-INVITE method (re-inviting/call modify)
- */
- public void onCallModifying(Call call, String sdp, Message invite) { // printLog("RE-INVITE/MODIFY");
- String local_session;
- if (sdp != null && sdp.length() > 0) {
- SessionDescriptor remote_sdp = new SessionDescriptor(sdp);
- SessionDescriptor local_sdp = new SessionDescriptor(call
- .getLocalSessionDescriptor());
- SessionDescriptor new_sdp = new SessionDescriptor(remote_sdp
- .getOrigin(), remote_sdp.getSessionName(), local_sdp
- .getConnection(), local_sdp.getTime());
- new_sdp.addMediaDescriptors(local_sdp.getMediaDescriptors());
- new_sdp = SdpTools.sdpMediaProduct(new_sdp, remote_sdp
- .getMediaDescriptors());
- new_sdp = SdpTools.sdpAttirbuteSelection(new_sdp, "rtpmap");
- local_session = new_sdp.toString();
- } else
- local_session = call.getLocalSessionDescriptor();
- // accept immediatly
- call.accept(local_session);
- }
-
- /**
- * Does nothing. Callback function called when arriving a 180 Ringing
- */
- public void onCallRinging(Call call, Message resp) { // printLog("RINGING");
- }
-
- /**
- * Does nothing. Callback function called when arriving a 2xx (call
- * accepted)
- */
- public void onCallAccepted(Call call, String sdp, Message resp) { // printLog("ACCEPTED/CALL");
- }
-
- /**
- * Does nothing. Callback function called when arriving a 4xx (call failure)
- */
- public void onCallRefused(Call call, String reason, Message resp) { // printLog("REFUSED
- // ("+reason+")");
- }
-
- /**
- * Redirects the call when remotly requested. Callback function called when
- * arriving a 3xx (call redirection)
- */
- public void onCallRedirection(Call call, String reason,
- Vector contact_list, Message resp) { // printLog("REDIRECTION
- // ("+reason+")");
- call.call(contact_list.elementAt(0));
- }
-
- /**
- * Does nothing. Callback function called when arriving an ACK method (call
- * confirmed)
- */
- public void onCallConfirmed(Call call, String sdp, Message ack) { // printLog("CONFIRMED/CALL");
- }
-
- /**
- * Does nothing. Callback function called when the invite expires
- */
- public void onCallTimeout(Call call) { // printLog("TIMEOUT/CLOSE");
- }
-
- /**
- * Does nothing. Callback function called when arriving a 2xx
- * (re-invite/modify accepted)
- */
- public void onCallReInviteAccepted(Call call, String sdp, Message resp) { // printLog("RE-INVITE-ACCEPTED/CALL");
- }
-
- /**
- * Does nothing. Callback function called when arriving a 4xx
- * (re-invite/modify failure)
- */
- public void onCallReInviteRefused(Call call, String reason, Message resp) { // printLog("RE-INVITE-REFUSED
- // ("+reason+")/CALL");
- }
-
- /**
- * Does nothing. Callback function called when a re-invite expires
- */
- public void onCallReInviteTimeout(Call call) { // printLog("RE-INVITE-TIMEOUT/CALL");
- }
-
- /**
- * Does nothing. Callback function called when arriving a CANCEL request
- */
- public void onCallCanceling(Call call, Message cancel) { // printLog("CANCELING");
- }
-
- /**
- * Does nothing. Callback function that may be overloaded (extended). Called
- * when arriving a BYE request
- */
- public void onCallClosing(Call call, Message bye) { // printLog("CLOSING");
- }
-
- /**
- * Does nothing. Callback function that may be overloaded (extended). Called
- * when arriving a response for a BYE request (call closed)
- */
- public void onCallClosed(Call call, Message resp) { // printLog("CLOSED");
- }
-
- /**
- * Does nothing. Callback function called when arriving a new REFER method
- * (transfer request)
- */
- public void onCallTransfer(ExtendedCall call, NameAddress refer_to,
- NameAddress refered_by, Message refer) { // printLog("REFER-TO/TRANSFER");
- }
-
- /**
- * Does nothing. Callback function called when a call transfer is accepted.
- */
- public void onCallTransferAccepted(ExtendedCall call, Message resp) {
- }
-
- /**
- * Does nothing. Callback function called when a call transfer is refused.
- */
- public void onCallTransferRefused(ExtendedCall call, String reason,
- Message resp) {
- }
-
- /**
- * Does nothing. Callback function called when a call transfer is
- * successfully completed
- */
- public void onCallTransferSuccess(ExtendedCall call, Message notify) { // printLog("TRANSFER
- // SUCCESS");
- }
-
- /**
- * Does nothing. Callback function called when a call transfer is NOT
- * sucessfully completed
- */
- public void onCallTransferFailure(ExtendedCall call, String reason,
- Message notify) { // printLog("TRANSFER FAILURE");
- }
-
-}
+/*
+ * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
+ * Copyright (C) 2009 The Sipdroid Open Source Project
+ *
+ * This file is part of MjSip (http://www.mjsip.org)
+ *
+ * MjSip is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * MjSip is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MjSip; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author(s):
+ * Luca Veltri (luca.veltri@unipr.it)
+ * Nitin Khanna, Hughes Systique Corp. (Reason: Android specific change, optmization, bug fix)
+ */
+
+package org.zoolu.sip.call;
+
+/* HSC CHANGES START */
+// import org.zoolu.sip.call.*;
+// import org.zoolu.sip.provider.SipStack;
+/* HSC CHANGES END */
+import org.zoolu.sip.address.NameAddress;
+import org.zoolu.sip.message.Message; /* HSC CHANGES START */// import
+ // org.zoolu.tools.Log;
+// import org.zoolu.tools.LogLevel;
+/* HSC CHANGES END */
+
+import org.zoolu.sdp.*; /* HSC CHANGES START */// import java.util.Iterator;
+// import java.util.Enumeration;
+/* HSC CHANGES END */
+
+import java.util.Vector;
+
+/**
+ * Class CallListenerAdapter implements CallListener interface providing a dummy
+ * implementation of all Call callback functions used to capture Call events.
+ *
+ * CallListenerAdapter can be extended to manage basic SIP calls. The callback
+ * methods defined in this class have basically a void implementation. This
+ * class exists as convenience for creating call listener objects.
+ * You can extend this class overriding only methods corresponding to events you
+ * want to handle.
+ *
+ * onCallIncoming(NameAddress,String) is the only non-empty method. It
+ * signals the receiver the ring status (by using method Call.ring()), adapts
+ * the sdp body and accepts the call (by using method Call.accept(sdp)).
+ */
+public abstract class CallListenerAdapter implements ExtendedCallListener {
+
+ // ************************** Costructors ***************************
+
+ /** Creates a new dummy call listener */
+ protected CallListenerAdapter() {
+ }
+
+ // ************************* Static methods *************************
+
+ /**
+ * Changes the current session descriptor specifing the receiving RTP/UDP
+ * port number, the AVP format, the codec, and the clock rate
+ */
+ /*
+ * public static String audioSession(int port, int avp, String codec, int
+ * rate) { SessionDescriptor sdp=new SessionDescriptor(); sdp.addMedia(new
+ * MediaField("audio ",port,0,"RTP/AVP",String.valueOf(avp)),new
+ * AttributeField("rtpmap",avp+" "+codec+"/"+rate)); return sdp.toString(); }
+ */
+
+ /**
+ * Changes the current session descriptor specifing the receiving RTP/UDP
+ * port number, the AVP format, the codec, and the clock rate
+ */
+ /*
+ * public static String audioSession(int port) { return
+ * audioSession(port,0,"PCMU",8000); }
+ */
+
+ // *********************** Callback functions ***********************
+ /**
+ * Accepts an incoming call. Callback function called when arriving a new
+ * INVITE method (incoming call)
+ */
+ public void onCallIncoming(Call call, NameAddress callee,
+ NameAddress caller, String sdp, Message invite) { // printLog("INCOMING");
+ String local_session;
+ if (sdp != null && sdp.length() > 0) {
+ SessionDescriptor remote_sdp = new SessionDescriptor(sdp);
+ SessionDescriptor local_sdp = new SessionDescriptor(call
+ .getLocalSessionDescriptor());
+ SessionDescriptor new_sdp = new SessionDescriptor(remote_sdp
+ .getOrigin(), remote_sdp.getSessionName(), local_sdp
+ .getConnection(), local_sdp.getTime());
+ new_sdp.addMediaDescriptors(local_sdp.getMediaDescriptors());
+ new_sdp = SdpTools.sdpMediaProduct(new_sdp, remote_sdp
+ .getMediaDescriptors());
+ new_sdp = SdpTools.sdpAttirbuteSelection(new_sdp, "rtpmap");
+ local_session = new_sdp.toString();
+ } else
+ local_session = call.getLocalSessionDescriptor();
+ call.ring(local_session);
+ // accept immediatly
+ call.accept(local_session);
+ }
+
+ /**
+ * Changes the call when remotly requested. Callback function called when
+ * arriving a new Re-INVITE method (re-inviting/call modify)
+ */
+ public void onCallModifying(Call call, String sdp, Message invite) { // printLog("RE-INVITE/MODIFY");
+ String local_session;
+ if (sdp != null && sdp.length() > 0) {
+ SessionDescriptor remote_sdp = new SessionDescriptor(sdp);
+ SessionDescriptor local_sdp = new SessionDescriptor(call
+ .getLocalSessionDescriptor());
+ SessionDescriptor new_sdp = new SessionDescriptor(remote_sdp
+ .getOrigin(), remote_sdp.getSessionName(), local_sdp
+ .getConnection(), local_sdp.getTime());
+ new_sdp.addMediaDescriptors(local_sdp.getMediaDescriptors());
+ new_sdp = SdpTools.sdpMediaProduct(new_sdp, remote_sdp
+ .getMediaDescriptors());
+ new_sdp = SdpTools.sdpAttirbuteSelection(new_sdp, "rtpmap");
+ local_session = new_sdp.toString();
+ } else
+ local_session = call.getLocalSessionDescriptor();
+ // accept immediatly
+ call.accept(local_session);
+ }
+
+ /**
+ * Does nothing. Callback function called when arriving a 180 Ringing
+ */
+ public void onCallRinging(Call call, Message resp) { // printLog("RINGING");
+ }
+
+ /**
+ * Does nothing. Callback function called when arriving a 2xx (call
+ * accepted)
+ */
+ public void onCallAccepted(Call call, String sdp, Message resp) { // printLog("ACCEPTED/CALL");
+ }
+
+ /**
+ * Does nothing. Callback function called when arriving a 4xx (call failure)
+ */
+ public void onCallRefused(Call call, String reason, Message resp) { // printLog("REFUSED
+ // ("+reason+")");
+ }
+
+ /**
+ * Redirects the call when remotly requested. Callback function called when
+ * arriving a 3xx (call redirection)
+ */
+ public void onCallRedirection(Call call, String reason,
+ Vector contact_list, Message resp) { // printLog("REDIRECTION
+ // ("+reason+")");
+ call.call(contact_list.elementAt(0));
+ }
+
+ /**
+ * Does nothing. Callback function called when arriving an ACK method (call
+ * confirmed)
+ */
+ public void onCallConfirmed(Call call, String sdp, Message ack) { // printLog("CONFIRMED/CALL");
+ }
+
+ /**
+ * Does nothing. Callback function called when the invite expires
+ */
+ public void onCallTimeout(Call call) { // printLog("TIMEOUT/CLOSE");
+ }
+
+ /**
+ * Does nothing. Callback function called when arriving a 2xx
+ * (re-invite/modify accepted)
+ */
+ public void onCallReInviteAccepted(Call call, String sdp, Message resp) { // printLog("RE-INVITE-ACCEPTED/CALL");
+ }
+
+ /**
+ * Does nothing. Callback function called when arriving a 4xx
+ * (re-invite/modify failure)
+ */
+ public void onCallReInviteRefused(Call call, String reason, Message resp) { // printLog("RE-INVITE-REFUSED
+ // ("+reason+")/CALL");
+ }
+
+ /**
+ * Does nothing. Callback function called when a re-invite expires
+ */
+ public void onCallReInviteTimeout(Call call) { // printLog("RE-INVITE-TIMEOUT/CALL");
+ }
+
+ /**
+ * Does nothing. Callback function called when arriving a CANCEL request
+ */
+ public void onCallCanceling(Call call, Message cancel) { // printLog("CANCELING");
+ }
+
+ /**
+ * Does nothing. Callback function that may be overloaded (extended). Called
+ * when arriving a BYE request
+ */
+ public void onCallClosing(Call call, Message bye) { // printLog("CLOSING");
+ }
+
+ /**
+ * Does nothing. Callback function that may be overloaded (extended). Called
+ * when arriving a response for a BYE request (call closed)
+ */
+ public void onCallClosed(Call call, Message resp) { // printLog("CLOSED");
+ }
+
+ /**
+ * Does nothing. Callback function called when arriving a new REFER method
+ * (transfer request)
+ */
+ public void onCallTransfer(ExtendedCall call, NameAddress refer_to,
+ NameAddress refered_by, Message refer) { // printLog("REFER-TO/TRANSFER");
+ }
+
+ /**
+ * Does nothing. Callback function called when a call transfer is accepted.
+ */
+ public void onCallTransferAccepted(ExtendedCall call, Message resp) {
+ }
+
+ /**
+ * Does nothing. Callback function called when a call transfer is refused.
+ */
+ public void onCallTransferRefused(ExtendedCall call, String reason,
+ Message resp) {
+ }
+
+ /**
+ * Does nothing. Callback function called when a call transfer is
+ * successfully completed
+ */
+ public void onCallTransferSuccess(ExtendedCall call, Message notify) { // printLog("TRANSFER
+ // SUCCESS");
+ }
+
+ /**
+ * Does nothing. Callback function called when a call transfer is NOT
+ * sucessfully completed
+ */
+ public void onCallTransferFailure(ExtendedCall call, String reason,
+ Message notify) { // printLog("TRANSFER FAILURE");
+ }
+
+}
diff --git a/src/org/zoolu/sip/call/ExtendedCall.java b/app/src/main/java/org/zoolu/sip/call/ExtendedCall.java
similarity index 96%
rename from src/org/zoolu/sip/call/ExtendedCall.java
rename to app/src/main/java/org/zoolu/sip/call/ExtendedCall.java
index 3d40780..3952f3c 100644
--- a/src/org/zoolu/sip/call/ExtendedCall.java
+++ b/app/src/main/java/org/zoolu/sip/call/ExtendedCall.java
@@ -1,251 +1,251 @@
-/*
- * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
- * Copyright (C) 2009 The Sipdroid Open Source Project
- *
- * This file is part of MjSip (http://www.mjsip.org)
- *
- * MjSip is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * MjSip is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with MjSip; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author(s):
- * Luca Veltri (luca.veltri@unipr.it)
- * Nitin Khanna, Hughes Systique Corp. (Reason: Android specific change, optmization, bug fix)
- */
-
-package org.zoolu.sip.call;
-
-/* HSC CHANGES BEGIN */
-// import org.zoolu.sip.call.*;
-/* HSC CHANGES END */
-import org.zoolu.sip.address.NameAddress;
-import org.zoolu.sip.dialog.ExtendedInviteDialog;
-import org.zoolu.sip.dialog.ExtendedInviteDialogListener;
-import org.zoolu.sip.header.StatusLine;
-import org.zoolu.sip.message.Message;
-import org.zoolu.sip.provider.SipProvider;
-import org.zoolu.sip.provider.SipStack;
-import org.zoolu.tools.LogLevel;
-
-/**
- * Class ExtendedCall extends basic SIP calls.
- *
- * It implements:
- call transfer (REFER/NOTIFY methods)
- */
-public class ExtendedCall extends Call implements ExtendedInviteDialogListener {
-
- ExtendedCallListener xcall_listener;
-
- Message refer;
-
- /** User name. */
- String username;
-
- /** User name. */
- String realm;
-
- /** User's passwd. */
- String passwd;
-
- /** Nonce for the next authentication. */
- String next_nonce;
-
- /** Qop for the next authentication. */
- String qop;
-
- /** Creates a new ExtendedCall. */
- public ExtendedCall(SipProvider sip_provider, String from_url,
- String contact_url, ExtendedCallListener call_listener) {
- super(sip_provider, from_url, contact_url, call_listener);
- this.xcall_listener = call_listener;
- this.refer = null;
- this.username = null;
- this.realm = null;
- this.passwd = null;
- this.next_nonce = null;
- this.qop = null;
- }
-
- /** Creates a new ExtendedCall specifing the sdp. */
- /*
- * public ExtendedCall(SipProvider sip_provider, String from_url, String
- * contact_url, String sdp, ExtendedCallListener call_listener) {
- * super(sip_provider,from_url,contact_url,sdp,call_listener);
- * xcall_listener=call_listener; }
- */
-
- /** Creates a new ExtendedCall. */
- public ExtendedCall(SipProvider sip_provider, String from_url,
- String contact_url, String username, String realm, String passwd,
- ExtendedCallListener call_listener) {
- super(sip_provider, from_url, contact_url, call_listener);
- this.xcall_listener = call_listener;
- this.refer = null;
- this.username = username;
- this.realm = realm;
- this.passwd = passwd;
- this.next_nonce = null;
- this.qop = null;
- }
-
- /** Waits for an incoming call */
- public void listen() {
- if (username != null)
- dialog = new ExtendedInviteDialog(sip_provider, username, realm,
- passwd, this);
- else
- dialog = new ExtendedInviteDialog(sip_provider, this);
- dialog.listen();
- }
-
- /** Starts a new call, inviting a remote user (r_user) */
- public void call(String r_user, String from, String contact, String sdp, String icsi) { // modified by mandrajg
- printLog("calling " + r_user, LogLevel.MEDIUM);
- if (username != null)
- dialog = new ExtendedInviteDialog(sip_provider, username, realm,
- passwd, this);
- else
- dialog = new ExtendedInviteDialog(sip_provider, this);
- if (from == null)
- from = from_url;
- if (contact == null)
- contact = contact_url;
- if (sdp != null)
- local_sdp = sdp;
- if (local_sdp != null)
- dialog.invite(r_user, from, contact, local_sdp, icsi); // modified by mandrajg
- else
- dialog.inviteWithoutOffer(r_user, from, contact);
- }
-
- /** Starts a new call with the invite message request */
- public void call(Message invite) {
- dialog = new ExtendedInviteDialog(sip_provider, this);
- local_sdp = invite.getBody();
- if (local_sdp != null)
- dialog.invite(invite);
- else
- dialog.inviteWithoutOffer(invite);
- }
-
- public void info(char c, int duration) {
- ((ExtendedInviteDialog) dialog).info(c, duration);
- }
-
- /** Requests a call transfer */
- public void transfer(String transfer_to) {
- ((ExtendedInviteDialog) dialog).refer(new NameAddress(transfer_to));
- }
-
- /** Accepts a call transfer request */
- public void acceptTransfer() {
- ((ExtendedInviteDialog) dialog).acceptRefer(refer);
- }
-
- /** Refuses a call transfer request */
- public void refuseTransfer() {
- ((ExtendedInviteDialog) dialog).refuseRefer(refer);
- }
-
- /** Notifies the satus of an other call */
- public void notify(int code, String reason) {
- ((ExtendedInviteDialog) dialog).notify(code, reason);
- }
-
- // ************** Inherited from InviteDialogListener **************
-
- /** When an incoming REFER request is received within the dialog */
- public void onDlgRefer(org.zoolu.sip.dialog.InviteDialog d,
- NameAddress refer_to, NameAddress referred_by, Message msg) {
- if (d != dialog) {
- printLog("NOT the current dialog", LogLevel.HIGH);
- return;
- }
- printLog("onDlgRefer(" + refer_to.toString() + ")", LogLevel.LOW);
- refer = msg;
- if (xcall_listener != null)
- xcall_listener.onCallTransfer(this, refer_to, referred_by, msg);
- }
-
- /** When a response is received for a REFER request within the dialog */
- public void onDlgReferResponse(org.zoolu.sip.dialog.InviteDialog d,
- int code, String reason, Message msg) {
- if (d != dialog) {
- printLog("NOT the current dialog", LogLevel.HIGH);
- return;
- }
- printLog("onDlgReferResponse(" + code + " " + reason + ")",
- LogLevel.LOW);
- if (code >= 200 && code < 300) {
- if (xcall_listener != null)
- xcall_listener.onCallTransferAccepted(this, msg);
- } else if (code >= 300) {
- if (xcall_listener != null)
- xcall_listener.onCallTransferRefused(this, reason, msg);
- }
- }
-
- /** When an incoming NOTIFY request is received within the dialog */
- public void onDlgNotify(org.zoolu.sip.dialog.InviteDialog d, String event,
- String sipfragment, Message msg) {
- if (d != dialog) {
- printLog("NOT the current dialog", LogLevel.HIGH);
- return;
- }
- printLog("onDlgNotify()", LogLevel.LOW);
- if (event.equals("refer")) {
- Message fragment = new Message(sipfragment);
- printLog("Notify: " + sipfragment, LogLevel.HIGH);
- if (fragment.isResponse()) {
- StatusLine status_line = fragment.getStatusLine();
- int code = status_line.getCode();
- String reason = status_line.getReason();
- if (code >= 200 && code < 300) {
- printLog("Call successfully transferred", LogLevel.MEDIUM);
- if (xcall_listener != null)
- xcall_listener.onCallTransferSuccess(this, msg);
- } else if (code >= 300) {
- printLog("Call NOT transferred", LogLevel.MEDIUM);
- if (xcall_listener != null)
- xcall_listener.onCallTransferFailure(this, reason, msg);
- }
- }
- }
- }
-
- /**
- * When an incoming request is received within the dialog different from
- * INVITE, CANCEL, ACK, BYE
- */
- public void onDlgAltRequest(org.zoolu.sip.dialog.InviteDialog d,
- String method, String body, Message msg) {
- }
-
- /**
- * When a response is received for a request within the dialog different
- * from INVITE, CANCEL, ACK, BYE
- */
- public void onDlgAltResponse(org.zoolu.sip.dialog.InviteDialog d,
- String method, int code, String reason, String body, Message msg) {
- }
-
- // **************************** Logs ****************************/
-
- /** Adds a new string to the default Log */
- protected void printLog(String str, int level) {
- if (log != null)
- log
- .println("ExtendedCall: " + str, level
- + SipStack.LOG_LEVEL_CALL);
- }
-}
+/*
+ * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
+ * Copyright (C) 2009 The Sipdroid Open Source Project
+ *
+ * This file is part of MjSip (http://www.mjsip.org)
+ *
+ * MjSip is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * MjSip is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MjSip; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author(s):
+ * Luca Veltri (luca.veltri@unipr.it)
+ * Nitin Khanna, Hughes Systique Corp. (Reason: Android specific change, optmization, bug fix)
+ */
+
+package org.zoolu.sip.call;
+
+/* HSC CHANGES BEGIN */
+// import org.zoolu.sip.call.*;
+/* HSC CHANGES END */
+import org.zoolu.sip.address.NameAddress;
+import org.zoolu.sip.dialog.ExtendedInviteDialog;
+import org.zoolu.sip.dialog.ExtendedInviteDialogListener;
+import org.zoolu.sip.header.StatusLine;
+import org.zoolu.sip.message.Message;
+import org.zoolu.sip.provider.SipProvider;
+import org.zoolu.sip.provider.SipStack;
+import org.zoolu.tools.LogLevel;
+
+/**
+ * Class ExtendedCall extends basic SIP calls.
+ *
+ * It implements:
- call transfer (REFER/NOTIFY methods)
+ */
+public class ExtendedCall extends Call implements ExtendedInviteDialogListener {
+
+ ExtendedCallListener xcall_listener;
+
+ Message refer;
+
+ /** User name. */
+ String username;
+
+ /** User name. */
+ String realm;
+
+ /** User's passwd. */
+ String passwd;
+
+ /** Nonce for the next authentication. */
+ String next_nonce;
+
+ /** Qop for the next authentication. */
+ String qop;
+
+ /** Creates a new ExtendedCall. */
+ public ExtendedCall(SipProvider sip_provider, String from_url,
+ String contact_url, ExtendedCallListener call_listener) {
+ super(sip_provider, from_url, contact_url, call_listener);
+ this.xcall_listener = call_listener;
+ this.refer = null;
+ this.username = null;
+ this.realm = null;
+ this.passwd = null;
+ this.next_nonce = null;
+ this.qop = null;
+ }
+
+ /** Creates a new ExtendedCall specifing the sdp. */
+ /*
+ * public ExtendedCall(SipProvider sip_provider, String from_url, String
+ * contact_url, String sdp, ExtendedCallListener call_listener) {
+ * super(sip_provider,from_url,contact_url,sdp,call_listener);
+ * xcall_listener=call_listener; }
+ */
+
+ /** Creates a new ExtendedCall. */
+ public ExtendedCall(SipProvider sip_provider, String from_url,
+ String contact_url, String username, String realm, String passwd,
+ ExtendedCallListener call_listener) {
+ super(sip_provider, from_url, contact_url, call_listener);
+ this.xcall_listener = call_listener;
+ this.refer = null;
+ this.username = username;
+ this.realm = realm;
+ this.passwd = passwd;
+ this.next_nonce = null;
+ this.qop = null;
+ }
+
+ /** Waits for an incoming call */
+ public void listen() {
+ if (username != null)
+ dialog = new ExtendedInviteDialog(sip_provider, username, realm,
+ passwd, this);
+ else
+ dialog = new ExtendedInviteDialog(sip_provider, this);
+ dialog.listen();
+ }
+
+ /** Starts a new call, inviting a remote user (r_user) */
+ public void call(String r_user, String from, String contact, String sdp, String icsi) { // modified by mandrajg
+ printLog("calling " + r_user, LogLevel.MEDIUM);
+ if (username != null)
+ dialog = new ExtendedInviteDialog(sip_provider, username, realm,
+ passwd, this);
+ else
+ dialog = new ExtendedInviteDialog(sip_provider, this);
+ if (from == null)
+ from = from_url;
+ if (contact == null)
+ contact = contact_url;
+ if (sdp != null)
+ local_sdp = sdp;
+ if (local_sdp != null)
+ dialog.invite(r_user, from, contact, local_sdp, icsi); // modified by mandrajg
+ else
+ dialog.inviteWithoutOffer(r_user, from, contact);
+ }
+
+ /** Starts a new call with the invite message request */
+ public void call(Message invite) {
+ dialog = new ExtendedInviteDialog(sip_provider, this);
+ local_sdp = invite.getBody();
+ if (local_sdp != null)
+ dialog.invite(invite);
+ else
+ dialog.inviteWithoutOffer(invite);
+ }
+
+ public void info(char c, int duration) {
+ ((ExtendedInviteDialog) dialog).info(c, duration);
+ }
+
+ /** Requests a call transfer */
+ public void transfer(String transfer_to) {
+ ((ExtendedInviteDialog) dialog).refer(new NameAddress(transfer_to));
+ }
+
+ /** Accepts a call transfer request */
+ public void acceptTransfer() {
+ ((ExtendedInviteDialog) dialog).acceptRefer(refer);
+ }
+
+ /** Refuses a call transfer request */
+ public void refuseTransfer() {
+ ((ExtendedInviteDialog) dialog).refuseRefer(refer);
+ }
+
+ /** Notifies the satus of an other call */
+ public void notify(int code, String reason) {
+ ((ExtendedInviteDialog) dialog).notify(code, reason);
+ }
+
+ // ************** Inherited from InviteDialogListener **************
+
+ /** When an incoming REFER request is received within the dialog */
+ public void onDlgRefer(org.zoolu.sip.dialog.InviteDialog d,
+ NameAddress refer_to, NameAddress referred_by, Message msg) {
+ if (d != dialog) {
+ printLog("NOT the current dialog", LogLevel.HIGH);
+ return;
+ }
+ printLog("onDlgRefer(" + refer_to.toString() + ")", LogLevel.LOW);
+ refer = msg;
+ if (xcall_listener != null)
+ xcall_listener.onCallTransfer(this, refer_to, referred_by, msg);
+ }
+
+ /** When a response is received for a REFER request within the dialog */
+ public void onDlgReferResponse(org.zoolu.sip.dialog.InviteDialog d,
+ int code, String reason, Message msg) {
+ if (d != dialog) {
+ printLog("NOT the current dialog", LogLevel.HIGH);
+ return;
+ }
+ printLog("onDlgReferResponse(" + code + " " + reason + ")",
+ LogLevel.LOW);
+ if (code >= 200 && code < 300) {
+ if (xcall_listener != null)
+ xcall_listener.onCallTransferAccepted(this, msg);
+ } else if (code >= 300) {
+ if (xcall_listener != null)
+ xcall_listener.onCallTransferRefused(this, reason, msg);
+ }
+ }
+
+ /** When an incoming NOTIFY request is received within the dialog */
+ public void onDlgNotify(org.zoolu.sip.dialog.InviteDialog d, String event,
+ String sipfragment, Message msg) {
+ if (d != dialog) {
+ printLog("NOT the current dialog", LogLevel.HIGH);
+ return;
+ }
+ printLog("onDlgNotify()", LogLevel.LOW);
+ if (event.equals("refer")) {
+ Message fragment = new Message(sipfragment);
+ printLog("Notify: " + sipfragment, LogLevel.HIGH);
+ if (fragment.isResponse()) {
+ StatusLine status_line = fragment.getStatusLine();
+ int code = status_line.getCode();
+ String reason = status_line.getReason();
+ if (code >= 200 && code < 300) {
+ printLog("Call successfully transferred", LogLevel.MEDIUM);
+ if (xcall_listener != null)
+ xcall_listener.onCallTransferSuccess(this, msg);
+ } else if (code >= 300) {
+ printLog("Call NOT transferred", LogLevel.MEDIUM);
+ if (xcall_listener != null)
+ xcall_listener.onCallTransferFailure(this, reason, msg);
+ }
+ }
+ }
+ }
+
+ /**
+ * When an incoming request is received within the dialog different from
+ * INVITE, CANCEL, ACK, BYE
+ */
+ public void onDlgAltRequest(org.zoolu.sip.dialog.InviteDialog d,
+ String method, String body, Message msg) {
+ }
+
+ /**
+ * When a response is received for a request within the dialog different
+ * from INVITE, CANCEL, ACK, BYE
+ */
+ public void onDlgAltResponse(org.zoolu.sip.dialog.InviteDialog d,
+ String method, int code, String reason, String body, Message msg) {
+ }
+
+ // **************************** Logs ****************************/
+
+ /** Adds a new string to the default Log */
+ protected void printLog(String str, int level) {
+ if (log != null)
+ log
+ .println("ExtendedCall: " + str, level
+ + SipStack.LOG_LEVEL_CALL);
+ }
+}
diff --git a/src/org/zoolu/sip/call/ExtendedCallListener.java b/app/src/main/java/org/zoolu/sip/call/ExtendedCallListener.java
similarity index 97%
rename from src/org/zoolu/sip/call/ExtendedCallListener.java
rename to app/src/main/java/org/zoolu/sip/call/ExtendedCallListener.java
index 2a7c114..91271ac 100644
--- a/src/org/zoolu/sip/call/ExtendedCallListener.java
+++ b/app/src/main/java/org/zoolu/sip/call/ExtendedCallListener.java
@@ -1,70 +1,70 @@
-/*
- * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
- *
- * This file is part of MjSip (http://www.mjsip.org)
- *
- * MjSip is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * MjSip is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with MjSip; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author(s):
- * Luca Veltri (luca.veltri@unipr.it)
- * Nitin Khanna, Hughes Systique Corp. (Reason: Android specific change, optmization, bug fix)
- */
-
-package org.zoolu.sip.call;
-
-/* HSC CHANGES START */
-// import org.zoolu.sip.call.*;
-/* HSC CHANGES END */
-import org.zoolu.sip.message.*;
-import org.zoolu.sip.address.NameAddress;
-
-/* HSC CHANGES START */
-// import org.zoolu.sdp.*;
-// import java.util.Vector;
-/* HSC CHANGES END */
-
-/**
- * Interface ExtendedCallListener can be implemented to manage exteded SIP calls
- * (sipx.call.ExtendedCall).
- *
- * Objects of class ExtendedCall use ExtendedCallListener callback methods to
- * signal specific call events.
- */
-public interface ExtendedCallListener extends CallListener {
- /**
- * Callback function called when arriving a new REFER method (transfer
- * request).
- */
- public void onCallTransfer(ExtendedCall call, NameAddress refer_to,
- NameAddress refered_by, Message refer);
-
- /** Callback function called when a call transfer is accepted. */
- public void onCallTransferAccepted(ExtendedCall call, Message resp);
-
- /** Callback function called when a call transfer is refused. */
- public void onCallTransferRefused(ExtendedCall call, String reason,
- Message resp);
-
- /** Callback function called when a call transfer is successfully completed. */
- public void onCallTransferSuccess(ExtendedCall call, Message notify);
-
- /**
- * Callback function called when a call transfer is NOT sucessfully
- * completed.
- */
- public void onCallTransferFailure(ExtendedCall call, String reason,
- Message notify);
-
-}
+/*
+ * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
+ *
+ * This file is part of MjSip (http://www.mjsip.org)
+ *
+ * MjSip is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * MjSip is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MjSip; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author(s):
+ * Luca Veltri (luca.veltri@unipr.it)
+ * Nitin Khanna, Hughes Systique Corp. (Reason: Android specific change, optmization, bug fix)
+ */
+
+package org.zoolu.sip.call;
+
+/* HSC CHANGES START */
+// import org.zoolu.sip.call.*;
+/* HSC CHANGES END */
+import org.zoolu.sip.message.*;
+import org.zoolu.sip.address.NameAddress;
+
+/* HSC CHANGES START */
+// import org.zoolu.sdp.*;
+// import java.util.Vector;
+/* HSC CHANGES END */
+
+/**
+ * Interface ExtendedCallListener can be implemented to manage exteded SIP calls
+ * (sipx.call.ExtendedCall).
+ *
+ * Objects of class ExtendedCall use ExtendedCallListener callback methods to
+ * signal specific call events.
+ */
+public interface ExtendedCallListener extends CallListener {
+ /**
+ * Callback function called when arriving a new REFER method (transfer
+ * request).
+ */
+ public void onCallTransfer(ExtendedCall call, NameAddress refer_to,
+ NameAddress refered_by, Message refer);
+
+ /** Callback function called when a call transfer is accepted. */
+ public void onCallTransferAccepted(ExtendedCall call, Message resp);
+
+ /** Callback function called when a call transfer is refused. */
+ public void onCallTransferRefused(ExtendedCall call, String reason,
+ Message resp);
+
+ /** Callback function called when a call transfer is successfully completed. */
+ public void onCallTransferSuccess(ExtendedCall call, Message notify);
+
+ /**
+ * Callback function called when a call transfer is NOT sucessfully
+ * completed.
+ */
+ public void onCallTransferFailure(ExtendedCall call, String reason,
+ Message notify);
+
+}
diff --git a/src/org/zoolu/sip/call/SdpTools.java b/app/src/main/java/org/zoolu/sip/call/SdpTools.java
similarity index 97%
rename from src/org/zoolu/sip/call/SdpTools.java
rename to app/src/main/java/org/zoolu/sip/call/SdpTools.java
index d11dbc5..caf4728 100644
--- a/src/org/zoolu/sip/call/SdpTools.java
+++ b/app/src/main/java/org/zoolu/sip/call/SdpTools.java
@@ -1,155 +1,155 @@
-/*
- * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
- * Copyright (C) 2009 The Sipdroid Open Source Project
- *
- * This file is part of MjSip (http://www.mjsip.org)
- *
- * MjSip is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * MjSip is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with MjSip; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author(s):
- * Luca Veltri (luca.veltri@unipr.it)
- * Nitin Khanna, Hughes Systique Corp. (Reason: Android specific change, optmization, bug fix)
- */
-
-package org.zoolu.sip.call;
-
-import org.zoolu.sdp.*;
-import java.util.Enumeration;
-import java.util.Vector;
-
-/**
- * Class SdpTools collects some static methods for managing SDP materials.
- */
-public class SdpTools {
- /**
- * Costructs a new SessionDescriptor from a given SessionDescriptor with
- * olny media types and attribute values specified by a MediaDescriptor
- * Vector.
- *
- * If no attribute is specified for a particular media, all present
- * attributes are kept.
- * If no attribute is present for a selected media, the media is kept
- * (regardless any sepcified attributes).
- *
- * @param sdp
- * the given SessionDescriptor
- * @param m_descs
- * Vector of MediaDescriptor with the selecting media types and
- * attributes
- * @return this SessionDescriptor
- */
- /* HSC CHANGES START */
- public static SessionDescriptor sdpMediaProduct(SessionDescriptor sdp,
- Vector m_descs) {
- Vector new_media = new Vector();
- if (m_descs != null) {
- for (Enumeration e = m_descs.elements(); e
- .hasMoreElements();) {
- MediaDescriptor spec_md = e.nextElement();
- // System.out.print("DEBUG: SDP: sdp_select:
- // "+spec_md.toString());
- MediaDescriptor prev_md = sdp.getMediaDescriptor(spec_md
- .getMedia().getMedia());
- // System.out.print("DEBUG: SDP: sdp_origin:
- // "+prev_md.toString());
- if (prev_md != null) {
- Vector spec_attributes = spec_md
- .getAttributes();
- Vector prev_attributes = prev_md
- .getAttributes();
- MediaField prev_mf = prev_md.getMedia();
- Vector new_formats = new Vector(prev_mf.getFormatList());
- new_formats.retainAll(spec_md.getMedia().getFormatList());
-
- if (spec_attributes.size() == 0
- || prev_attributes.size() == 0) {
- new_media.addElement(prev_md);
- } else {
- Vector new_attributes = new Vector();
- for (Enumeration i = spec_attributes
- .elements(); i.hasMoreElements();) {
- AttributeField spec_attr = i.nextElement();
- String spec_name = spec_attr.getAttributeName();
- String spec_value = spec_attr.getAttributeValue();
- for (Enumeration k = prev_attributes
- .elements(); k.hasMoreElements();) {
- AttributeField prev_attr = k.nextElement();
- String prev_name = prev_attr.getAttributeName();
- String prev_value = prev_attr
- .getAttributeValue();
- if (prev_name.equals(spec_name)
- && prev_value
- .equalsIgnoreCase(spec_value)) {
- new_attributes.addElement(prev_attr);
- break;
- }
- }
- }
- MediaField new_mf = new MediaField(prev_mf.getMedia(), prev_mf.getPort(), 0,
- prev_mf.getTransport(), new_formats);
- if (new_attributes.size() > 0)
- new_media.addElement(new MediaDescriptor(new_mf, prev_md.getConnection(),
- new_attributes));
- else {
- if(new_mf.getMedia().startsWith("audio") && new_formats.size() > 0) {
- new_media.addElement(new MediaDescriptor(new_mf, prev_md.getConnection(),
- new_attributes)); // new_attributes is empty but this is ok here.
- }
- }
- }
- }
- }
- }
- SessionDescriptor new_sdp = new SessionDescriptor(sdp);
- new_sdp.removeMediaDescriptors();
- new_sdp.addMediaDescriptors(new_media);
- return new_sdp;
- }
-
- /* HSC CHANGES END */
- /**
- * Costructs a new SessionDescriptor from a given SessionDescriptor with
- * olny the first specified media attribute. /** Keeps only the fisrt
- * attribute of the specified type for each media.
- *
- * If no attribute is present for a media, the media is dropped.
- *
- * @param sdp
- * the given SessionDescriptor
- * @param a_name
- * the attribute name
- * @return this SessionDescriptor
- */
- /* HSC CHANGES START */
- public static SessionDescriptor sdpAttirbuteSelection(
- SessionDescriptor sdp, String a_name) {
- Vector new_media = new Vector();
- for (Enumeration e = sdp.getMediaDescriptors()
- .elements(); e.hasMoreElements();) {
- /* HSC CHANGES END */
- MediaDescriptor md = e.nextElement();
- AttributeField attr = md.getAttribute(a_name);
- if (attr != null) {
- new_media.addElement(new MediaDescriptor(md.getMedia(), md
- .getConnection(), attr));
- }
- }
- SessionDescriptor new_sdp = new SessionDescriptor(sdp);
- new_sdp.removeMediaDescriptors();
- new_sdp.addMediaDescriptors(new_media);
- return new_sdp;
- }
-
-}
+/*
+ * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
+ * Copyright (C) 2009 The Sipdroid Open Source Project
+ *
+ * This file is part of MjSip (http://www.mjsip.org)
+ *
+ * MjSip is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * MjSip is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MjSip; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author(s):
+ * Luca Veltri (luca.veltri@unipr.it)
+ * Nitin Khanna, Hughes Systique Corp. (Reason: Android specific change, optmization, bug fix)
+ */
+
+package org.zoolu.sip.call;
+
+import org.zoolu.sdp.*;
+import java.util.Enumeration;
+import java.util.Vector;
+
+/**
+ * Class SdpTools collects some static methods for managing SDP materials.
+ */
+public class SdpTools {
+ /**
+ * Costructs a new SessionDescriptor from a given SessionDescriptor with
+ * olny media types and attribute values specified by a MediaDescriptor
+ * Vector.
+ *
+ * If no attribute is specified for a particular media, all present
+ * attributes are kept.
+ * If no attribute is present for a selected media, the media is kept
+ * (regardless any sepcified attributes).
+ *
+ * @param sdp
+ * the given SessionDescriptor
+ * @param m_descs
+ * Vector of MediaDescriptor with the selecting media types and
+ * attributes
+ * @return this SessionDescriptor
+ */
+ /* HSC CHANGES START */
+ public static SessionDescriptor sdpMediaProduct(SessionDescriptor sdp,
+ Vector m_descs) {
+ Vector new_media = new Vector();
+ if (m_descs != null) {
+ for (Enumeration e = m_descs.elements(); e
+ .hasMoreElements();) {
+ MediaDescriptor spec_md = e.nextElement();
+ // System.out.print("DEBUG: SDP: sdp_select:
+ // "+spec_md.toString());
+ MediaDescriptor prev_md = sdp.getMediaDescriptor(spec_md
+ .getMedia().getMedia());
+ // System.out.print("DEBUG: SDP: sdp_origin:
+ // "+prev_md.toString());
+ if (prev_md != null) {
+ Vector spec_attributes = spec_md
+ .getAttributes();
+ Vector prev_attributes = prev_md
+ .getAttributes();
+ MediaField prev_mf = prev_md.getMedia();
+ Vector new_formats = new Vector(prev_mf.getFormatList());
+ new_formats.retainAll(spec_md.getMedia().getFormatList());
+
+ if (spec_attributes.size() == 0
+ || prev_attributes.size() == 0) {
+ new_media.addElement(prev_md);
+ } else {
+ Vector new_attributes = new Vector();
+ for (Enumeration i = spec_attributes
+ .elements(); i.hasMoreElements();) {
+ AttributeField spec_attr = i.nextElement();
+ String spec_name = spec_attr.getAttributeName();
+ String spec_value = spec_attr.getAttributeValue();
+ for (Enumeration k = prev_attributes
+ .elements(); k.hasMoreElements();) {
+ AttributeField prev_attr = k.nextElement();
+ String prev_name = prev_attr.getAttributeName();
+ String prev_value = prev_attr
+ .getAttributeValue();
+ if (prev_name.equals(spec_name)
+ && prev_value
+ .equalsIgnoreCase(spec_value)) {
+ new_attributes.addElement(prev_attr);
+ break;
+ }
+ }
+ }
+ MediaField new_mf = new MediaField(prev_mf.getMedia(), prev_mf.getPort(), 0,
+ prev_mf.getTransport(), new_formats);
+ if (new_attributes.size() > 0)
+ new_media.addElement(new MediaDescriptor(new_mf, prev_md.getConnection(),
+ new_attributes));
+ else {
+ if(new_mf.getMedia().startsWith("audio") && new_formats.size() > 0) {
+ new_media.addElement(new MediaDescriptor(new_mf, prev_md.getConnection(),
+ new_attributes)); // new_attributes is empty but this is ok here.
+ }
+ }
+ }
+ }
+ }
+ }
+ SessionDescriptor new_sdp = new SessionDescriptor(sdp);
+ new_sdp.removeMediaDescriptors();
+ new_sdp.addMediaDescriptors(new_media);
+ return new_sdp;
+ }
+
+ /* HSC CHANGES END */
+ /**
+ * Costructs a new SessionDescriptor from a given SessionDescriptor with
+ * olny the first specified media attribute. /** Keeps only the fisrt
+ * attribute of the specified type for each media.
+ *
+ * If no attribute is present for a media, the media is dropped.
+ *
+ * @param sdp
+ * the given SessionDescriptor
+ * @param a_name
+ * the attribute name
+ * @return this SessionDescriptor
+ */
+ /* HSC CHANGES START */
+ public static SessionDescriptor sdpAttirbuteSelection(
+ SessionDescriptor sdp, String a_name) {
+ Vector new_media = new Vector();
+ for (Enumeration e = sdp.getMediaDescriptors()
+ .elements(); e.hasMoreElements();) {
+ /* HSC CHANGES END */
+ MediaDescriptor md = e.nextElement();
+ AttributeField attr = md.getAttribute(a_name);
+ if (attr != null) {
+ new_media.addElement(new MediaDescriptor(md.getMedia(), md
+ .getConnection(), attr));
+ }
+ }
+ SessionDescriptor new_sdp = new SessionDescriptor(sdp);
+ new_sdp.removeMediaDescriptors();
+ new_sdp.addMediaDescriptors(new_media);
+ return new_sdp;
+ }
+
+}
diff --git a/src/org/zoolu/sip/dialog/Dialog.java b/app/src/main/java/org/zoolu/sip/dialog/Dialog.java
similarity index 96%
rename from src/org/zoolu/sip/dialog/Dialog.java
rename to app/src/main/java/org/zoolu/sip/dialog/Dialog.java
index 4462a5d..66d6e3b 100644
--- a/src/org/zoolu/sip/dialog/Dialog.java
+++ b/app/src/main/java/org/zoolu/sip/dialog/Dialog.java
@@ -1,322 +1,322 @@
-/*
- * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
- *
- * This file is part of MjSip (http://www.mjsip.org)
- *
- * MjSip is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * MjSip is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with MjSip; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author(s):
- * Luca Veltri (luca.veltri@unipr.it)
- * Nitin Khanna, Hughes Systique Corp. (Reason: Android specific change, optmization, bug fix)
- */
-
-package org.zoolu.sip.dialog;
-
-import java.util.Vector; /* HSC CHANGES START */
-import org.zoolu.sip.address.NameAddress;
-import org.zoolu.sip.header.FromHeader;
-import org.zoolu.sip.header.Header;
-import org.zoolu.sip.header.RecordRouteHeader;
-import org.zoolu.sip.header.ToHeader;
-import org.zoolu.sip.message.Message;
-import org.zoolu.sip.provider.DialogIdentifier;
-import org.zoolu.sip.provider.SipProvider;
-import org.zoolu.sip.provider.SipProviderListener;
-import org.zoolu.sip.provider.SipStack;
-import org.zoolu.tools.Log;
-import org.zoolu.tools.LogLevel;
-
-/* HSC CHANGES END */
-
-/**
- * Class Dialog maintains a complete information status of a generic SIP dialog.
- * It has the following attributes:
- *
- * - sip-provider
- * - call-id
- * - local and remote URLs
- * - local and remote contact URLs
- * - local and remote cseqs
- * - local and remote tags
- * - dialog-id
- * - route set
- *
- */
-public abstract class Dialog extends DialogInfo implements SipProviderListener {
-
- // ************************ Static attributes *************************
-
- /** Dialogs counter */
- private static int dialog_counter = 0;
-
- /** Identifier for the transaction client side of a dialog (UAC). */
- public final static int UAC = 0;
- /** Identifier for the transaction server side of a dialog (UAS). */
- public final static int UAS = 1;
-
- // *********************** Protected attributes ***********************
-
- /** Dialog sequence number */
- protected int dialog_sqn;
-
- /** Event logger. */
- protected Log log;
-
- /** SipProvider */
- protected SipProvider sip_provider;
-
- /** Internal dialog state. */
- protected int status;
-
- /** Dialog identifier */
- protected DialogIdentifier dialog_id;
-
- // ************************* Abstract methods *************************
-
- /** Gets the dialog state */
- abstract protected String getStatusDescription();
-
- abstract protected int getStatus();
-
- /** Whether the dialog is in "early" state. */
- abstract public boolean isEarly();
-
- /** Whether the dialog is in "confirmed" state. */
- abstract public boolean isConfirmed();
-
- /** Whether the dialog is in "terminated" state. */
- abstract public boolean isTerminated();
-
- /** When a new Message is received by the SipProvider. */
- abstract public void onReceivedMessage(SipProvider provider, Message message);
-
- // **************************** Costructors ***************************
-
- /** Creates a new empty Dialog */
- protected Dialog(SipProvider provider) {
- super();
- this.sip_provider = provider;
- this.log = sip_provider.getLog();
- this.dialog_sqn = dialog_counter++;
- this.status = 0;
- this.dialog_id = null;
- }
-
- // ************************* Protected methods ************************
-
- /** Changes the internal dialog state */
- protected void changeStatus(int newstatus) {
- status = newstatus;
- printLog("changed dialog state: " + getStatus(), LogLevel.MEDIUM);
-
- // remove the sip_provider listener when going to "terminated" state
- if (isTerminated()) {
- if (dialog_id != null
- && sip_provider.getListeners().containsKey(dialog_id))
- sip_provider.removeSipProviderListener(dialog_id);
- } else
- // add sip_provider listener when going to "early" or "confirmed" state
- if (isEarly() || isConfirmed()) {
- if (dialog_id != null
- && !sip_provider.getListeners().containsKey(dialog_id))
- sip_provider.addSipProviderListener(dialog_id, this);
- }
- }
-
- /** Whether the dialog state is equal to st */
- protected boolean statusIs(int st) {
- return status == st;
- }
-
- // ************************** Public methods **************************
-
- /** Gets the SipProvider of this Dialog. */
- public SipProvider getSipProvider() {
- return sip_provider;
- }
-
- /** Gets the inique Dialog-ID */
- public DialogIdentifier getDialogID() {
- return dialog_id;
- }
-
- /**
- * Updates empty attributes (tags, route set) and mutable attributes (cseqs,
- * contacts), based on a new message.
- *
- * @param side
- * indicates whether the Dialog is acting as transaction client
- * or server for the current message (use constant values
- * Dialog.UAC or Dialog.UAS)
- * @param msg
- * the message that is used to update the Dialog state
- */
- public void update(int side, Message msg) {
- if (isTerminated()) {
- printWarning("trying to update a terminated dialog: do nothing.",
- LogLevel.HIGH);
- return;
- }
- // else
-
- // update call_id
- if (call_id == null)
- call_id = msg.getCallIdHeader().getCallId();
-
- // update names and tags
- if (side == UAC) {
- if (remote_name == null || remote_tag == null) {
- ToHeader to = msg.getToHeader();
- if (remote_name == null)
- remote_name = to.getNameAddress();
- if (remote_tag == null)
- remote_tag = to.getTag();
- }
- if (local_name == null || local_tag == null) {
- FromHeader from = msg.getFromHeader();
- if (local_name == null)
- local_name = from.getNameAddress();
- if (local_tag == null)
- local_tag = from.getTag();
- }
- local_cseq = msg.getCSeqHeader().getSequenceNumber();
- // if (remote_cseq==-1) remote_cseq=SipProvider.pickInitialCSeq()-1;
- } else {
- if (local_name == null || local_tag == null) {
- ToHeader to = msg.getToHeader();
- if (local_name == null)
- local_name = to.getNameAddress();
- if (local_tag == null)
- local_tag = to.getTag();
- }
- if (remote_name == null || remote_tag == null) {
- FromHeader from = msg.getFromHeader();
- if (remote_name == null)
- remote_name = from.getNameAddress();
- if (remote_tag == null)
- remote_tag = from.getTag();
- }
- remote_cseq = msg.getCSeqHeader().getSequenceNumber();
- if (local_cseq == -1)
- local_cseq = SipProvider.pickInitialCSeq() - 1;
- }
- // update contact
- if (msg.hasContactHeader()) {
- if ((side == UAC && msg.isRequest())
- || (side == UAS && msg.isResponse()))
- local_contact = msg.getContactHeader().getNameAddress();
- else
- remote_contact = msg.getContactHeader().getNameAddress();
- }
- // update route or record-route
- if (side == UAC) {
- if (msg.isRequest() && msg.hasRouteHeader() && route == null) {
- /* HSC CHANGES START */
- Vector route_s = msg.getRoutes().getValues();
- route = new Vector(route_s.size());
- int size = route_s.size();
- for (int i = 0; i < size; i++) {
- route.insertElementAt(
- new NameAddress(route_s.elementAt(i)), i);
- }
- /* HSC CHANGES END */
- }
- if (side == UAC && msg.isResponse() && msg.hasRecordRouteHeader()) {
- /* HSC CHANGES START */
- Vector rr = msg.getRecordRoutes().getHeaders();
- int size = rr.size();
- route = new Vector(size);
- /* HSC CHANGES END */
- for (int i = 0; i < size; i++) {
- route.insertElementAt((new RecordRouteHeader((Header) rr
- .elementAt(size - 1 - i))).getNameAddress(), i);
- }
- }
- } else {
- if (msg.isRequest() && msg.hasRouteHeader() && route == null) {
- /* HSC CHANGES START */
- Vector reverse_route = msg.getRoutes().getValues();
- int size = reverse_route.size();
- route = new Vector(size);
- for (int i = 0; i < size; i++) {
- route.insertElementAt(new NameAddress(reverse_route
- .elementAt(size - 1 - i)), i);
- }
- /* HSC CHANGES END */
- }
- if (msg.isRequest() && msg.hasRecordRouteHeader()) {
- /* HSC CHANGES START */
- Vector rr = msg.getRecordRoutes().getHeaders();
- int size = rr.size();
- route = new Vector(size);
- for (int i = 0; i < size; i++) {
- route.insertElementAt((new RecordRouteHeader((Header) rr
- .elementAt(i))).getNameAddress(), i);
- }
- /* HSC CHANGES END */
- }
- }
-
- // update dialog_id and sip_provider listener
- DialogIdentifier new_id = new DialogIdentifier(call_id, local_tag,
- remote_tag);
- if (dialog_id == null || !dialog_id.equals(new_id)) {
- if (dialog_id != null && sip_provider != null
- && sip_provider.getListeners().containsKey(dialog_id))
- sip_provider.removeSipProviderListener(dialog_id);
- dialog_id = new_id;
- printLog("new dialog id: " + dialog_id, LogLevel.HIGH);
- if (sip_provider != null)
- sip_provider.addSipProviderListener(dialog_id, this);
- }
- }
-
- // **************************** Logs ****************************/
-
- /** Adds a new string to the default Log */
- protected void printLog(String str, int level) {
- if (log != null)
- log.println("Dialog#" + dialog_sqn + ": " + str, level
- + SipStack.LOG_LEVEL_DIALOG);
- }
-
- /** Adds a Warning message to the default Log */
- protected final void printWarning(String str, int level) {
- printLog("WARNING: " + str, level);
- }
-
- /** Adds the Exception message to the default Log */
- protected final void printException(Exception e, int level) {
- if (log != null)
- log.printException(e, level + SipStack.LOG_LEVEL_DIALOG);
- }
-
- /** Verifies the correct status; if not logs the event. */
- protected final boolean verifyStatus(boolean expression) {
- return verifyThat(expression, "dialog state mismatching");
- }
-
- /** Verifies an event; if not logs it. */
- protected final boolean verifyThat(boolean expression, String str) {
- if (!expression) {
- if (str == null || str.length() == 0)
- printWarning("expression check failed. ", 1);
- else
- printWarning(str, 1);
- }
- return expression;
- }
-
-}
+/*
+ * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
+ *
+ * This file is part of MjSip (http://www.mjsip.org)
+ *
+ * MjSip is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * MjSip is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MjSip; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author(s):
+ * Luca Veltri (luca.veltri@unipr.it)
+ * Nitin Khanna, Hughes Systique Corp. (Reason: Android specific change, optmization, bug fix)
+ */
+
+package org.zoolu.sip.dialog;
+
+import java.util.Vector; /* HSC CHANGES START */
+import org.zoolu.sip.address.NameAddress;
+import org.zoolu.sip.header.FromHeader;
+import org.zoolu.sip.header.Header;
+import org.zoolu.sip.header.RecordRouteHeader;
+import org.zoolu.sip.header.ToHeader;
+import org.zoolu.sip.message.Message;
+import org.zoolu.sip.provider.DialogIdentifier;
+import org.zoolu.sip.provider.SipProvider;
+import org.zoolu.sip.provider.SipProviderListener;
+import org.zoolu.sip.provider.SipStack;
+import org.zoolu.tools.Log;
+import org.zoolu.tools.LogLevel;
+
+/* HSC CHANGES END */
+
+/**
+ * Class Dialog maintains a complete information status of a generic SIP dialog.
+ * It has the following attributes:
+ *
+ * - sip-provider
+ * - call-id
+ * - local and remote URLs
+ * - local and remote contact URLs
+ * - local and remote cseqs
+ * - local and remote tags
+ * - dialog-id
+ * - route set
+ *
+ */
+public abstract class Dialog extends DialogInfo implements SipProviderListener {
+
+ // ************************ Static attributes *************************
+
+ /** Dialogs counter */
+ private static int dialog_counter = 0;
+
+ /** Identifier for the transaction client side of a dialog (UAC). */
+ public final static int UAC = 0;
+ /** Identifier for the transaction server side of a dialog (UAS). */
+ public final static int UAS = 1;
+
+ // *********************** Protected attributes ***********************
+
+ /** Dialog sequence number */
+ protected int dialog_sqn;
+
+ /** Event logger. */
+ protected Log log;
+
+ /** SipProvider */
+ protected SipProvider sip_provider;
+
+ /** Internal dialog state. */
+ protected int status;
+
+ /** Dialog identifier */
+ protected DialogIdentifier dialog_id;
+
+ // ************************* Abstract methods *************************
+
+ /** Gets the dialog state */
+ abstract protected String getStatusDescription();
+
+ abstract protected int getStatus();
+
+ /** Whether the dialog is in "early" state. */
+ abstract public boolean isEarly();
+
+ /** Whether the dialog is in "confirmed" state. */
+ abstract public boolean isConfirmed();
+
+ /** Whether the dialog is in "terminated" state. */
+ abstract public boolean isTerminated();
+
+ /** When a new Message is received by the SipProvider. */
+ abstract public void onReceivedMessage(SipProvider provider, Message message);
+
+ // **************************** Costructors ***************************
+
+ /** Creates a new empty Dialog */
+ protected Dialog(SipProvider provider) {
+ super();
+ this.sip_provider = provider;
+ this.log = sip_provider.getLog();
+ this.dialog_sqn = dialog_counter++;
+ this.status = 0;
+ this.dialog_id = null;
+ }
+
+ // ************************* Protected methods ************************
+
+ /** Changes the internal dialog state */
+ protected void changeStatus(int newstatus) {
+ status = newstatus;
+ printLog("changed dialog state: " + getStatus(), LogLevel.MEDIUM);
+
+ // remove the sip_provider listener when going to "terminated" state
+ if (isTerminated()) {
+ if (dialog_id != null
+ && sip_provider.getListeners().containsKey(dialog_id))
+ sip_provider.removeSipProviderListener(dialog_id);
+ } else
+ // add sip_provider listener when going to "early" or "confirmed" state
+ if (isEarly() || isConfirmed()) {
+ if (dialog_id != null
+ && !sip_provider.getListeners().containsKey(dialog_id))
+ sip_provider.addSipProviderListener(dialog_id, this);
+ }
+ }
+
+ /** Whether the dialog state is equal to st */
+ protected boolean statusIs(int st) {
+ return status == st;
+ }
+
+ // ************************** Public methods **************************
+
+ /** Gets the SipProvider of this Dialog. */
+ public SipProvider getSipProvider() {
+ return sip_provider;
+ }
+
+ /** Gets the inique Dialog-ID */
+ public DialogIdentifier getDialogID() {
+ return dialog_id;
+ }
+
+ /**
+ * Updates empty attributes (tags, route set) and mutable attributes (cseqs,
+ * contacts), based on a new message.
+ *
+ * @param side
+ * indicates whether the Dialog is acting as transaction client
+ * or server for the current message (use constant values
+ * Dialog.UAC or Dialog.UAS)
+ * @param msg
+ * the message that is used to update the Dialog state
+ */
+ public void update(int side, Message msg) {
+ if (isTerminated()) {
+ printWarning("trying to update a terminated dialog: do nothing.",
+ LogLevel.HIGH);
+ return;
+ }
+ // else
+
+ // update call_id
+ if (call_id == null)
+ call_id = msg.getCallIdHeader().getCallId();
+
+ // update names and tags
+ if (side == UAC) {
+ if (remote_name == null || remote_tag == null) {
+ ToHeader to = msg.getToHeader();
+ if (remote_name == null)
+ remote_name = to.getNameAddress();
+ if (remote_tag == null)
+ remote_tag = to.getTag();
+ }
+ if (local_name == null || local_tag == null) {
+ FromHeader from = msg.getFromHeader();
+ if (local_name == null)
+ local_name = from.getNameAddress();
+ if (local_tag == null)
+ local_tag = from.getTag();
+ }
+ local_cseq = msg.getCSeqHeader().getSequenceNumber();
+ // if (remote_cseq==-1) remote_cseq=SipProvider.pickInitialCSeq()-1;
+ } else {
+ if (local_name == null || local_tag == null) {
+ ToHeader to = msg.getToHeader();
+ if (local_name == null)
+ local_name = to.getNameAddress();
+ if (local_tag == null)
+ local_tag = to.getTag();
+ }
+ if (remote_name == null || remote_tag == null) {
+ FromHeader from = msg.getFromHeader();
+ if (remote_name == null)
+ remote_name = from.getNameAddress();
+ if (remote_tag == null)
+ remote_tag = from.getTag();
+ }
+ remote_cseq = msg.getCSeqHeader().getSequenceNumber();
+ if (local_cseq == -1)
+ local_cseq = SipProvider.pickInitialCSeq() - 1;
+ }
+ // update contact
+ if (msg.hasContactHeader()) {
+ if ((side == UAC && msg.isRequest())
+ || (side == UAS && msg.isResponse()))
+ local_contact = msg.getContactHeader().getNameAddress();
+ else
+ remote_contact = msg.getContactHeader().getNameAddress();
+ }
+ // update route or record-route
+ if (side == UAC) {
+ if (msg.isRequest() && msg.hasRouteHeader() && route == null) {
+ /* HSC CHANGES START */
+ Vector route_s = msg.getRoutes().getValues();
+ route = new Vector(route_s.size());
+ int size = route_s.size();
+ for (int i = 0; i < size; i++) {
+ route.insertElementAt(
+ new NameAddress(route_s.elementAt(i)), i);
+ }
+ /* HSC CHANGES END */
+ }
+ if (side == UAC && msg.isResponse() && msg.hasRecordRouteHeader()) {
+ /* HSC CHANGES START */
+ Vector rr = msg.getRecordRoutes().getHeaders();
+ int size = rr.size();
+ route = new Vector(size);
+ /* HSC CHANGES END */
+ for (int i = 0; i < size; i++) {
+ route.insertElementAt((new RecordRouteHeader((Header) rr
+ .elementAt(size - 1 - i))).getNameAddress(), i);
+ }
+ }
+ } else {
+ if (msg.isRequest() && msg.hasRouteHeader() && route == null) {
+ /* HSC CHANGES START */
+ Vector reverse_route = msg.getRoutes().getValues();
+ int size = reverse_route.size();
+ route = new Vector(size);
+ for (int i = 0; i < size; i++) {
+ route.insertElementAt(new NameAddress(reverse_route
+ .elementAt(size - 1 - i)), i);
+ }
+ /* HSC CHANGES END */
+ }
+ if (msg.isRequest() && msg.hasRecordRouteHeader()) {
+ /* HSC CHANGES START */
+ Vector rr = msg.getRecordRoutes().getHeaders();
+ int size = rr.size();
+ route = new Vector(size);
+ for (int i = 0; i < size; i++) {
+ route.insertElementAt((new RecordRouteHeader((Header) rr
+ .elementAt(i))).getNameAddress(), i);
+ }
+ /* HSC CHANGES END */
+ }
+ }
+
+ // update dialog_id and sip_provider listener
+ DialogIdentifier new_id = new DialogIdentifier(call_id, local_tag,
+ remote_tag);
+ if (dialog_id == null || !dialog_id.equals(new_id)) {
+ if (dialog_id != null && sip_provider != null
+ && sip_provider.getListeners().containsKey(dialog_id))
+ sip_provider.removeSipProviderListener(dialog_id);
+ dialog_id = new_id;
+ printLog("new dialog id: " + dialog_id, LogLevel.HIGH);
+ if (sip_provider != null)
+ sip_provider.addSipProviderListener(dialog_id, this);
+ }
+ }
+
+ // **************************** Logs ****************************/
+
+ /** Adds a new string to the default Log */
+ protected void printLog(String str, int level) {
+ if (log != null)
+ log.println("Dialog#" + dialog_sqn + ": " + str, level
+ + SipStack.LOG_LEVEL_DIALOG);
+ }
+
+ /** Adds a Warning message to the default Log */
+ protected final void printWarning(String str, int level) {
+ printLog("WARNING: " + str, level);
+ }
+
+ /** Adds the Exception message to the default Log */
+ protected final void printException(Exception e, int level) {
+ if (log != null)
+ log.printException(e, level + SipStack.LOG_LEVEL_DIALOG);
+ }
+
+ /** Verifies the correct status; if not logs the event. */
+ protected final boolean verifyStatus(boolean expression) {
+ return verifyThat(expression, "dialog state mismatching");
+ }
+
+ /** Verifies an event; if not logs it. */
+ protected final boolean verifyThat(boolean expression, String str) {
+ if (!expression) {
+ if (str == null || str.length() == 0)
+ printWarning("expression check failed. ", 1);
+ else
+ printWarning(str, 1);
+ }
+ return expression;
+ }
+
+}
diff --git a/src/org/zoolu/sip/dialog/DialogInfo.java b/app/src/main/java/org/zoolu/sip/dialog/DialogInfo.java
similarity index 95%
rename from src/org/zoolu/sip/dialog/DialogInfo.java
rename to app/src/main/java/org/zoolu/sip/dialog/DialogInfo.java
index 49dbdc5..c4c29b8 100644
--- a/src/org/zoolu/sip/dialog/DialogInfo.java
+++ b/app/src/main/java/org/zoolu/sip/dialog/DialogInfo.java
@@ -1,216 +1,216 @@
-/*
- * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
- *
- * This file is part of MjSip (http://www.mjsip.org)
- *
- * MjSip is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * MjSip is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with MjSip; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author(s):
- * Luca Veltri (luca.veltri@unipr.it)
- * Nitin Khanna, Hughes Systique Corp. (Reason: Android specific change, optmization, bug fix)
- */
-
-package org.zoolu.sip.dialog;
-
-import org.zoolu.sip.address.*;
-/* HSC CHANGES BEGIN */
-//import org.zoolu.sip.message.*;
-//import org.zoolu.sip.header.*;
-//import org.zoolu.sip.provider.*;
-//import org.zoolu.tools.Log;
-//import org.zoolu.tools.LogLevel;
-//import org.zoolu.tools.AssertException;
-/* HSC CHANGES END */
-import java.util.Vector;
-
-/**
- * Class DialogInfo maintains a complete information status of a generic SIP
- * dialog. It has the following attributes:
- *
- * - sip-provider
- * - call-id
- * - local and remote URLs
- * - local and remote contact URLs
- * - local and remote cseqs
- * - local and remote tags
- * - dialog-id
- * - route set
- *
- */
-public class DialogInfo {
-
- // ************************ Private attributes ************************
-
- /** Local name */
- NameAddress local_name;
-
- /** Remote name */
- NameAddress remote_name;
-
- /** Local contact url */
- NameAddress local_contact;
-
- /** Remote contact url */
- NameAddress remote_contact;
-
- /** Call-id */
- String call_id;
-
- /** Local tag */
- String local_tag;
-
- /** Remote tag */
- String remote_tag;
- /** Sets the remote tag */
-
- /** Local CSeq number */
- long local_cseq;
-
- /** Remote CSeq number */
- long remote_cseq;
-
- /** Route set (Vector of NameAddresses) */
- /* HSC CHANGES START */
- Vector route;
-
- /* HSC CHANGES END */
- // **************************** Costructors ***************************
- /** Creates a new empty DialogInfo */
- public DialogInfo() {
- this.local_name = null;
- this.remote_name = null;
- this.local_contact = null;
- this.remote_contact = null;
- this.call_id = null;
- this.local_tag = null;
- this.remote_tag = null;
- this.local_cseq = -1;
- this.remote_cseq = -1;
- this.route = null;
- }
-
- // ************************** Public methods **************************
-
- /** Sets the local name */
- public void setLocalName(NameAddress url) {
- local_name = url;
- }
-
- /** Gets the local name */
- public NameAddress getLocalName() {
- return local_name;
- }
-
- /** Sets the remote name */
- public void setRemoteName(NameAddress url) {
- remote_name = url;
- }
-
- /** Gets the remote name */
- public NameAddress getRemoteName() {
- return remote_name;
- }
-
- /** Sets the local contact url */
- public void setLocalContact(NameAddress name_address) {
- local_contact = name_address;
- }
-
- /** Gets the local contact url */
- public NameAddress getLocalContact() {
- return local_contact;
- }
-
- /** Sets the remote contact url */
- public void setRemoteContact(NameAddress name_address) {
- remote_contact = name_address;
- }
-
- /** Gets the remote contact url */
- public NameAddress getRemoteContact() {
- return remote_contact;
- }
-
- /** Sets the call-id */
- public void setCallID(String id) {
- call_id = id;
- }
-
- /** Gets the call-id */
- public String getCallID() {
- return call_id;
- }
-
- /** Sets the local tag */
- public void setLocalTag(String tag) {
- local_tag = tag;
- }
-
- /** Gets the local tag */
- public String getLocalTag() {
- return local_tag;
- }
-
- public void setRemoteTag(String tag) {
- remote_tag = tag;
- }
-
- /** Gets the remote tag */
- public String getRemoteTag() {
- return remote_tag;
- }
-
- /** Sets the local CSeq number */
- public void setLocalCSeq(long cseq) {
- local_cseq = cseq;
- }
-
- /** Increments the local CSeq number */
- public void incLocalCSeq() {
- local_cseq++;
- }
-
- /** Gets the local CSeq number */
- public long getLocalCSeq() {
- return local_cseq;
- }
-
- /** Sets the remote CSeq number */
- public void setRemoteCSeq(long cseq) {
- remote_cseq = cseq;
- }
-
- /** Increments the remote CSeq number */
- public void incRemoteCSeq() {
- remote_cseq++;
- }
-
- /** Gets the remote CSeq number */
- public long getRemoteCSeq() {
- return remote_cseq;
- }
-
- /* HSC CHANGES BEGIN */
- /** Sets the route set */
- public void setRoute(Vector r) {
- route = r;
- }
-
- /** Gets the route set */
- public Vector getRoute() {
- return route;
- }
- /* HSC CHANGES END */
-}
+/*
+ * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
+ *
+ * This file is part of MjSip (http://www.mjsip.org)
+ *
+ * MjSip is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * MjSip is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MjSip; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author(s):
+ * Luca Veltri (luca.veltri@unipr.it)
+ * Nitin Khanna, Hughes Systique Corp. (Reason: Android specific change, optmization, bug fix)
+ */
+
+package org.zoolu.sip.dialog;
+
+import org.zoolu.sip.address.*;
+/* HSC CHANGES BEGIN */
+//import org.zoolu.sip.message.*;
+//import org.zoolu.sip.header.*;
+//import org.zoolu.sip.provider.*;
+//import org.zoolu.tools.Log;
+//import org.zoolu.tools.LogLevel;
+//import org.zoolu.tools.AssertException;
+/* HSC CHANGES END */
+import java.util.Vector;
+
+/**
+ * Class DialogInfo maintains a complete information status of a generic SIP
+ * dialog. It has the following attributes:
+ *
+ * - sip-provider
+ * - call-id
+ * - local and remote URLs
+ * - local and remote contact URLs
+ * - local and remote cseqs
+ * - local and remote tags
+ * - dialog-id
+ * - route set
+ *
+ */
+public class DialogInfo {
+
+ // ************************ Private attributes ************************
+
+ /** Local name */
+ NameAddress local_name;
+
+ /** Remote name */
+ NameAddress remote_name;
+
+ /** Local contact url */
+ NameAddress local_contact;
+
+ /** Remote contact url */
+ NameAddress remote_contact;
+
+ /** Call-id */
+ String call_id;
+
+ /** Local tag */
+ String local_tag;
+
+ /** Remote tag */
+ String remote_tag;
+ /** Sets the remote tag */
+
+ /** Local CSeq number */
+ long local_cseq;
+
+ /** Remote CSeq number */
+ long remote_cseq;
+
+ /** Route set (Vector of NameAddresses) */
+ /* HSC CHANGES START */
+ Vector route;
+
+ /* HSC CHANGES END */
+ // **************************** Costructors ***************************
+ /** Creates a new empty DialogInfo */
+ public DialogInfo() {
+ this.local_name = null;
+ this.remote_name = null;
+ this.local_contact = null;
+ this.remote_contact = null;
+ this.call_id = null;
+ this.local_tag = null;
+ this.remote_tag = null;
+ this.local_cseq = -1;
+ this.remote_cseq = -1;
+ this.route = null;
+ }
+
+ // ************************** Public methods **************************
+
+ /** Sets the local name */
+ public void setLocalName(NameAddress url) {
+ local_name = url;
+ }
+
+ /** Gets the local name */
+ public NameAddress getLocalName() {
+ return local_name;
+ }
+
+ /** Sets the remote name */
+ public void setRemoteName(NameAddress url) {
+ remote_name = url;
+ }
+
+ /** Gets the remote name */
+ public NameAddress getRemoteName() {
+ return remote_name;
+ }
+
+ /** Sets the local contact url */
+ public void setLocalContact(NameAddress name_address) {
+ local_contact = name_address;
+ }
+
+ /** Gets the local contact url */
+ public NameAddress getLocalContact() {
+ return local_contact;
+ }
+
+ /** Sets the remote contact url */
+ public void setRemoteContact(NameAddress name_address) {
+ remote_contact = name_address;
+ }
+
+ /** Gets the remote contact url */
+ public NameAddress getRemoteContact() {
+ return remote_contact;
+ }
+
+ /** Sets the call-id */
+ public void setCallID(String id) {
+ call_id = id;
+ }
+
+ /** Gets the call-id */
+ public String getCallID() {
+ return call_id;
+ }
+
+ /** Sets the local tag */
+ public void setLocalTag(String tag) {
+ local_tag = tag;
+ }
+
+ /** Gets the local tag */
+ public String getLocalTag() {
+ return local_tag;
+ }
+
+ public void setRemoteTag(String tag) {
+ remote_tag = tag;
+ }
+
+ /** Gets the remote tag */
+ public String getRemoteTag() {
+ return remote_tag;
+ }
+
+ /** Sets the local CSeq number */
+ public void setLocalCSeq(long cseq) {
+ local_cseq = cseq;
+ }
+
+ /** Increments the local CSeq number */
+ public void incLocalCSeq() {
+ local_cseq++;
+ }
+
+ /** Gets the local CSeq number */
+ public long getLocalCSeq() {
+ return local_cseq;
+ }
+
+ /** Sets the remote CSeq number */
+ public void setRemoteCSeq(long cseq) {
+ remote_cseq = cseq;
+ }
+
+ /** Increments the remote CSeq number */
+ public void incRemoteCSeq() {
+ remote_cseq++;
+ }
+
+ /** Gets the remote CSeq number */
+ public long getRemoteCSeq() {
+ return remote_cseq;
+ }
+
+ /* HSC CHANGES BEGIN */
+ /** Sets the route set */
+ public void setRoute(Vector r) {
+ route = r;
+ }
+
+ /** Gets the route set */
+ public Vector getRoute() {
+ return route;
+ }
+ /* HSC CHANGES END */
+}
diff --git a/src/org/zoolu/sip/dialog/ExtendedInviteDialog.java b/app/src/main/java/org/zoolu/sip/dialog/ExtendedInviteDialog.java
similarity index 97%
rename from src/org/zoolu/sip/dialog/ExtendedInviteDialog.java
rename to app/src/main/java/org/zoolu/sip/dialog/ExtendedInviteDialog.java
index 6c2a805..09878f2 100644
--- a/src/org/zoolu/sip/dialog/ExtendedInviteDialog.java
+++ b/app/src/main/java/org/zoolu/sip/dialog/ExtendedInviteDialog.java
@@ -1,241 +1,241 @@
-/*
- * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
- * Copyright (C) 2009 The Sipdroid Open Source Project
- *
- * This file is part of MjSip (http://www.mjsip.org)
- *
- * MjSip is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * MjSip is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with MjSip; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author(s):
- * Luca Veltri (luca.veltri@unipr.it)
- * Nitin Khanna, Hughes Systique Corp. (Reason: Android specific change, optmization, bug fix)
- */
-
-package org.zoolu.sip.dialog;
-
-import org.zoolu.sip.provider.*;
-import org.zoolu.sip.address.NameAddress;
-import org.zoolu.sip.header.StatusLine;
-import org.zoolu.sip.header.RequestLine;
-import org.zoolu.sip.header.AuthorizationHeader;
-import org.zoolu.sip.header.ViaHeader;
-import org.zoolu.sip.header.WwwAuthenticateHeader;
-import org.zoolu.sip.transaction.*;
-import org.zoolu.sip.message.*;
-import org.zoolu.sip.authentication.DigestAuthentication;
-import org.zoolu.tools.LogLevel;
-
-import java.util.Hashtable;
-
-/**
- * Class ExtendedInviteDialog can be used to manage extended invite dialogs.
- *
- * An ExtendedInviteDialog allows the user:
- to handle authentication
-
- * to handle refer/notify
- to capture all methods within the dialog
- */
-public class ExtendedInviteDialog extends org.zoolu.sip.dialog.InviteDialog {
- /** Max number of registration attempts. */
- static final int MAX_ATTEMPTS = 3;
-
- /** ExtendedInviteDialog listener. */
- ExtendedInviteDialogListener dialog_listener;
-
- /** Acive transactions. */
- /* HSC CHANGES START */
- Hashtable transactions;
- /* HSC CHANGES END */
- /** User name. */
- String username;
-
- /** User name. */
- String realm;
-
- /** User's passwd. */
- String passwd;
-
- /** Nonce for the next authentication. */
- String next_nonce;
-
- /** Qop for the next authentication. */
- String qop;
-
- /** Number of authentication attempts. */
- int attempts;
-
- /** Creates a new ExtendedInviteDialog. */
- public ExtendedInviteDialog(SipProvider provider,
- ExtendedInviteDialogListener listener) {
- super(provider, listener);
- init(listener);
- }
-
- /** Creates a new ExtendedInviteDialog. */
- public ExtendedInviteDialog(SipProvider provider, String username,
- String realm, String passwd, ExtendedInviteDialogListener listener) {
- super(provider, listener);
- init(listener);
- this.username = username;
- this.realm = realm;
- this.passwd = passwd;
- }
-
- /** Inits the ExtendedInviteDialog. */
- private void init(ExtendedInviteDialogListener listener) {
- this.dialog_listener = listener;
- this.transactions = new Hashtable();
- this.username = null;
- this.realm = null;
- this.passwd = null;
- this.next_nonce = null;
- this.qop = null;
- this.attempts = 0;
- }
-
- /** Sends a new request within the dialog */
- public void request(Message req) {
- TransactionClient t = new TransactionClient(sip_provider, req, this);
- transactions.put(t.getTransactionId(), t);
- t.request();
- }
-
- /** Sends a new REFER within the dialog */
- public void refer(NameAddress refer_to) {
- refer(refer_to, null);
- }
-
- public void info(char c, int duration) // modified (again by Matthew Monacelli)
- {
- Message req = BaseMessageFactory.createRequest(this, SipMethods.INFO, null);
- req.setBody("application/dtmf-relay","Signal="+c+"\r\n+Duration="+duration);
- request(req);
- }
-
- /** Sends a new REFER within the dialog */
- public void refer(NameAddress refer_to, NameAddress referred_by) {
- Message req = MessageFactory.createReferRequest(this, refer_to,
- referred_by);
- request(req);
- }
-
- /** Sends a new NOTIFY within the dialog */
- public void notify(int code, String reason) {
- notify((new StatusLine(code, reason)).toString());
- }
-
- /** Sends a new NOTIFY within the dialog */
- public void notify(String sipfragment) {
- Message req = MessageFactory.createNotifyRequest(this, "refer", null,
- sipfragment);
- request(req);
- }
-
- /** Responds with resp */
- public void respond(Message resp) {
- printLog("inside respond(resp)", LogLevel.MEDIUM);
- String method = resp.getCSeqHeader().getMethod();
- if (method.equals(SipMethods.INVITE)
- || method.equals(SipMethods.CANCEL)
- || method.equals(SipMethods.BYE)) {
- super.respond(resp);
- } else {
- TransactionIdentifier transaction_id = resp.getTransactionId();
- printLog("transaction-id=" + transaction_id, LogLevel.MEDIUM);
- if (transactions.containsKey(transaction_id)) {
- printLog("responding", LogLevel.LOW);
- TransactionServer t = (TransactionServer) transactions
- .get(transaction_id);
- t.respondWith(resp);
- } else
- printLog("transaction server not found; message discarded",
- LogLevel.MEDIUM);
- }
- }
-
- /** Accept a REFER */
- public void acceptRefer(Message req) {
- printLog("inside acceptRefer(refer)", LogLevel.MEDIUM);
- Message resp = MessageFactory.createResponse(req, 202, SipResponses
- .reasonOf(200), null);
- respond(resp);
- }
-
- /** Refuse a REFER */
- public void refuseRefer(Message req) {
- printLog("inside refuseRefer(refer)", LogLevel.MEDIUM);
- Message resp = MessageFactory.createResponse(req, 603, SipResponses
- .reasonOf(603), null);
- respond(resp);
- }
-
- /** Inherited from class SipProviderListener. */
- public void onReceivedMessage(SipProvider provider, Message msg) {
- printLog(
- "Message received: "
- + msg.getFirstLine().substring(0,
- msg.toString().indexOf('\r')), LogLevel.LOW);
- if (msg.isResponse()) {
- super.onReceivedMessage(provider, msg);
- } else if (msg.isInvite() || msg.isAck() || msg.isCancel()
- || msg.isBye()) {
- super.onReceivedMessage(provider, msg);
- } else {
- TransactionServer t = new TransactionServer(sip_provider, msg, this);
- transactions.put(t.getTransactionId(), t);
- // t.listen();
-
- if (msg.isRefer()) { // Message
- // resp=MessageFactory.createResponse(msg,202,"Accepted",null,null);
- // respond(resp);
- NameAddress refer_to = msg.getReferToHeader().getNameAddress();
- NameAddress referred_by = null;
- if (msg.hasReferredByHeader())
- referred_by = msg.getReferredByHeader().getNameAddress();
- dialog_listener.onDlgRefer(this, refer_to, referred_by, msg);
- } else if (msg.isNotify()) {
- Message resp = MessageFactory.createResponse(msg, 200,
- SipResponses.reasonOf(200), null);
- respond(resp);
- String event = msg.getEventHeader().getValue();
- String sipfragment = msg.getBody();
- dialog_listener.onDlgNotify(this, event, sipfragment, msg);
- } else {
- printLog("Received alternative request "
- + msg.getRequestLine().getMethod(), LogLevel.MEDIUM);
- dialog_listener.onDlgAltRequest(this, msg.getRequestLine()
- .getMethod(), msg.getBody(), msg);
- }
- }
- }
-
- /**
- * Inherited from TransactionClientListener. When the
- * TransactionClientListener goes into the "Completed" state, receiving a
- * failure response
- */
- public void onTransFailureResponse(TransactionClient tc, Message msg) {
- printLog("inside onTransFailureResponse(" + tc.getTransactionId()
- + ",msg)", LogLevel.LOW);
- String method = tc.getTransactionMethod();
- StatusLine status_line = msg.getStatusLine();
- int code = status_line.getCode();
- String reason = status_line.getReason();
+/*
+ * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
+ * Copyright (C) 2009 The Sipdroid Open Source Project
+ *
+ * This file is part of MjSip (http://www.mjsip.org)
+ *
+ * MjSip is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * MjSip is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MjSip; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author(s):
+ * Luca Veltri (luca.veltri@unipr.it)
+ * Nitin Khanna, Hughes Systique Corp. (Reason: Android specific change, optmization, bug fix)
+ */
+
+package org.zoolu.sip.dialog;
+
+import org.zoolu.sip.provider.*;
+import org.zoolu.sip.address.NameAddress;
+import org.zoolu.sip.header.StatusLine;
+import org.zoolu.sip.header.RequestLine;
+import org.zoolu.sip.header.AuthorizationHeader;
+import org.zoolu.sip.header.ViaHeader;
+import org.zoolu.sip.header.WwwAuthenticateHeader;
+import org.zoolu.sip.transaction.*;
+import org.zoolu.sip.message.*;
+import org.zoolu.sip.authentication.DigestAuthentication;
+import org.zoolu.tools.LogLevel;
+
+import java.util.Hashtable;
+
+/**
+ * Class ExtendedInviteDialog can be used to manage extended invite dialogs.
+ *
+ * An ExtendedInviteDialog allows the user:
- to handle authentication
-
+ * to handle refer/notify
- to capture all methods within the dialog
+ */
+public class ExtendedInviteDialog extends org.zoolu.sip.dialog.InviteDialog {
+ /** Max number of registration attempts. */
+ static final int MAX_ATTEMPTS = 3;
+
+ /** ExtendedInviteDialog listener. */
+ ExtendedInviteDialogListener dialog_listener;
+
+ /** Acive transactions. */
+ /* HSC CHANGES START */
+ Hashtable transactions;
+ /* HSC CHANGES END */
+ /** User name. */
+ String username;
+
+ /** User name. */
+ String realm;
+
+ /** User's passwd. */
+ String passwd;
+
+ /** Nonce for the next authentication. */
+ String next_nonce;
+
+ /** Qop for the next authentication. */
+ String qop;
+
+ /** Number of authentication attempts. */
+ int attempts;
+
+ /** Creates a new ExtendedInviteDialog. */
+ public ExtendedInviteDialog(SipProvider provider,
+ ExtendedInviteDialogListener listener) {
+ super(provider, listener);
+ init(listener);
+ }
+
+ /** Creates a new ExtendedInviteDialog. */
+ public ExtendedInviteDialog(SipProvider provider, String username,
+ String realm, String passwd, ExtendedInviteDialogListener listener) {
+ super(provider, listener);
+ init(listener);
+ this.username = username;
+ this.realm = realm;
+ this.passwd = passwd;
+ }
+
+ /** Inits the ExtendedInviteDialog. */
+ private void init(ExtendedInviteDialogListener listener) {
+ this.dialog_listener = listener;
+ this.transactions = new Hashtable();
+ this.username = null;
+ this.realm = null;
+ this.passwd = null;
+ this.next_nonce = null;
+ this.qop = null;
+ this.attempts = 0;
+ }
+
+ /** Sends a new request within the dialog */
+ public void request(Message req) {
+ TransactionClient t = new TransactionClient(sip_provider, req, this);
+ transactions.put(t.getTransactionId(), t);
+ t.request();
+ }
+
+ /** Sends a new REFER within the dialog */
+ public void refer(NameAddress refer_to) {
+ refer(refer_to, null);
+ }
+
+ public void info(char c, int duration) // modified (again by Matthew Monacelli)
+ {
+ Message req = BaseMessageFactory.createRequest(this, SipMethods.INFO, null);
+ req.setBody("application/dtmf-relay","Signal="+c+"\r\n+Duration="+duration);
+ request(req);
+ }
+
+ /** Sends a new REFER within the dialog */
+ public void refer(NameAddress refer_to, NameAddress referred_by) {
+ Message req = MessageFactory.createReferRequest(this, refer_to,
+ referred_by);
+ request(req);
+ }
+
+ /** Sends a new NOTIFY within the dialog */
+ public void notify(int code, String reason) {
+ notify((new StatusLine(code, reason)).toString());
+ }
+
+ /** Sends a new NOTIFY within the dialog */
+ public void notify(String sipfragment) {
+ Message req = MessageFactory.createNotifyRequest(this, "refer", null,
+ sipfragment);
+ request(req);
+ }
+
+ /** Responds with resp */
+ public void respond(Message resp) {
+ printLog("inside respond(resp)", LogLevel.MEDIUM);
+ String method = resp.getCSeqHeader().getMethod();
+ if (method.equals(SipMethods.INVITE)
+ || method.equals(SipMethods.CANCEL)
+ || method.equals(SipMethods.BYE)) {
+ super.respond(resp);
+ } else {
+ TransactionIdentifier transaction_id = resp.getTransactionId();
+ printLog("transaction-id=" + transaction_id, LogLevel.MEDIUM);
+ if (transactions.containsKey(transaction_id)) {
+ printLog("responding", LogLevel.LOW);
+ TransactionServer t = (TransactionServer) transactions
+ .get(transaction_id);
+ t.respondWith(resp);
+ } else
+ printLog("transaction server not found; message discarded",
+ LogLevel.MEDIUM);
+ }
+ }
+
+ /** Accept a REFER */
+ public void acceptRefer(Message req) {
+ printLog("inside acceptRefer(refer)", LogLevel.MEDIUM);
+ Message resp = MessageFactory.createResponse(req, 202, SipResponses
+ .reasonOf(200), null);
+ respond(resp);
+ }
+
+ /** Refuse a REFER */
+ public void refuseRefer(Message req) {
+ printLog("inside refuseRefer(refer)", LogLevel.MEDIUM);
+ Message resp = MessageFactory.createResponse(req, 603, SipResponses
+ .reasonOf(603), null);
+ respond(resp);
+ }
+
+ /** Inherited from class SipProviderListener. */
+ public void onReceivedMessage(SipProvider provider, Message msg) {
+ printLog(
+ "Message received: "
+ + msg.getFirstLine().substring(0,
+ msg.toString().indexOf('\r')), LogLevel.LOW);
+ if (msg.isResponse()) {
+ super.onReceivedMessage(provider, msg);
+ } else if (msg.isInvite() || msg.isAck() || msg.isCancel()
+ || msg.isBye()) {
+ super.onReceivedMessage(provider, msg);
+ } else {
+ TransactionServer t = new TransactionServer(sip_provider, msg, this);
+ transactions.put(t.getTransactionId(), t);
+ // t.listen();
+
+ if (msg.isRefer()) { // Message
+ // resp=MessageFactory.createResponse(msg,202,"Accepted",null,null);
+ // respond(resp);
+ NameAddress refer_to = msg.getReferToHeader().getNameAddress();
+ NameAddress referred_by = null;
+ if (msg.hasReferredByHeader())
+ referred_by = msg.getReferredByHeader().getNameAddress();
+ dialog_listener.onDlgRefer(this, refer_to, referred_by, msg);
+ } else if (msg.isNotify()) {
+ Message resp = MessageFactory.createResponse(msg, 200,
+ SipResponses.reasonOf(200), null);
+ respond(resp);
+ String event = msg.getEventHeader().getValue();
+ String sipfragment = msg.getBody();
+ dialog_listener.onDlgNotify(this, event, sipfragment, msg);
+ } else {
+ printLog("Received alternative request "
+ + msg.getRequestLine().getMethod(), LogLevel.MEDIUM);
+ dialog_listener.onDlgAltRequest(this, msg.getRequestLine()
+ .getMethod(), msg.getBody(), msg);
+ }
+ }
+ }
+
+ /**
+ * Inherited from TransactionClientListener. When the
+ * TransactionClientListener goes into the "Completed" state, receiving a
+ * failure response
+ */
+ public void onTransFailureResponse(TransactionClient tc, Message msg) {
+ printLog("inside onTransFailureResponse(" + tc.getTransactionId()
+ + ",msg)", LogLevel.LOW);
+ String method = tc.getTransactionMethod();
+ StatusLine status_line = msg.getStatusLine();
+ int code = status_line.getCode();
+ String reason = status_line.getReason();
boolean isErr401 = false;
boolean isErr407 = false;
-
- // AUTHENTICATION-BEGIN
+
+ // AUTHENTICATION-BEGIN
if (attempts < MAX_ATTEMPTS) {
switch (code) {
case 401:
@@ -254,105 +254,105 @@ public void onTransFailureResponse(TransactionClient tc, Message msg) {
}
if (isErr401 | isErr407) {
- attempts++;
- Message req = tc.getRequestMessage();
- req.setCSeqHeader(req.getCSeqHeader().incSequenceNumber());
- ViaHeader vh=req.getViaHeader();
- String newbranch = SipProvider.pickBranch();
- vh.setBranch(newbranch);
- req.removeViaHeader();
-
- req.addViaHeader(vh);
- WwwAuthenticateHeader wah;
- if (code == 401)
- wah = msg.getWwwAuthenticateHeader();
- else
- wah = msg.getProxyAuthenticateHeader();
- String qop_options = wah.getQopOptionsParam();
- qop = (qop_options != null) ? "auth" : null;
- RequestLine rl = req.getRequestLine();
- DigestAuthentication digest = new DigestAuthentication(rl
- .getMethod(), rl.getAddress().toString(), wah, qop, null,
- username, passwd);
- AuthorizationHeader ah;
- if (code == 401)
- ah = digest.getAuthorizationHeader();
- else
- ah = digest.getProxyAuthorizationHeader();
- req.setAuthorizationHeader(ah);
- transactions.remove(tc.getTransactionId());
- tc = new TransactionClient(sip_provider, req, this);
- transactions.put(tc.getTransactionId(), tc);
- tc.request();
- invite_req = req; // modified
- } else
- // AUTHENTICATION-END
- if (method.equals(SipMethods.INVITE)
- || method.equals(SipMethods.CANCEL)
- || method.equals(SipMethods.BYE)) {
- super.onTransFailureResponse(tc, msg);
- } else if (tc.getTransactionMethod().equals(SipMethods.REFER)) {
- transactions.remove(tc.getTransactionId());
- dialog_listener.onDlgReferResponse(this, code, reason, msg);
- } else {
- String body = msg.getBody();
- transactions.remove(tc.getTransactionId());
- dialog_listener.onDlgAltResponse(this, method, code, reason, body,
- msg);
- }
- }
-
- /**
- * Inherited from TransactionClientListener. When an
- * TransactionClientListener goes into the "Terminated" state, receiving a
- * 2xx response
- */
- public void onTransSuccessResponse(TransactionClient t, Message msg) {
- printLog("inside onTransSuccessResponse(" + t.getTransactionId()
- + ",msg)", LogLevel.LOW);
- attempts = 0;
- String method = t.getTransactionMethod();
- StatusLine status_line = msg.getStatusLine();
- int code = status_line.getCode();
- String reason = status_line.getReason();
-
- if (method.equals(SipMethods.INVITE)
- || method.equals(SipMethods.CANCEL)
- || method.equals(SipMethods.BYE)) {
- super.onTransSuccessResponse(t, msg);
- } else if (t.getTransactionMethod().equals(SipMethods.REFER)) {
- transactions.remove(t.getTransactionId());
- dialog_listener.onDlgReferResponse(this, code, reason, msg);
- } else {
- String body = msg.getBody();
- transactions.remove(t.getTransactionId());
- dialog_listener.onDlgAltResponse(this, method, code, reason, body,
- msg);
- }
- }
-
- /**
- * Inherited from TransactionClientListener. When the TransactionClient goes
- * into the "Terminated" state, caused by transaction timeout
- */
- public void onTransTimeout(TransactionClient t) {
- printLog("inside onTransTimeout(" + t.getTransactionId() + ",msg)",
- LogLevel.LOW);
- String method = t.getTransactionMethod();
- if (method.equals(SipMethods.INVITE) || method.equals(SipMethods.BYE)) {
- super.onTransTimeout(t);
- } else { // do something..
- transactions.remove(t.getTransactionId());
- }
- }
-
- // **************************** Logs ****************************/
-
- /** Adds a new string to the default Log */
- protected void printLog(String str, int level) {
- if (log != null)
- log.println("ExtendedInviteDialog#" + dialog_sqn + ": " + str,
- level + SipStack.LOG_LEVEL_DIALOG);
- }
-
-}
+ attempts++;
+ Message req = tc.getRequestMessage();
+ req.setCSeqHeader(req.getCSeqHeader().incSequenceNumber());
+ ViaHeader vh=req.getViaHeader();
+ String newbranch = SipProvider.pickBranch();
+ vh.setBranch(newbranch);
+ req.removeViaHeader();
+
+ req.addViaHeader(vh);
+ WwwAuthenticateHeader wah;
+ if (code == 401)
+ wah = msg.getWwwAuthenticateHeader();
+ else
+ wah = msg.getProxyAuthenticateHeader();
+ String qop_options = wah.getQopOptionsParam();
+ qop = (qop_options != null) ? "auth" : null;
+ RequestLine rl = req.getRequestLine();
+ DigestAuthentication digest = new DigestAuthentication(rl
+ .getMethod(), rl.getAddress().toString(), wah, qop, null,
+ username, passwd);
+ AuthorizationHeader ah;
+ if (code == 401)
+ ah = digest.getAuthorizationHeader();
+ else
+ ah = digest.getProxyAuthorizationHeader();
+ req.setAuthorizationHeader(ah);
+ transactions.remove(tc.getTransactionId());
+ tc = new TransactionClient(sip_provider, req, this);
+ transactions.put(tc.getTransactionId(), tc);
+ tc.request();
+ invite_req = req; // modified
+ } else
+ // AUTHENTICATION-END
+ if (method.equals(SipMethods.INVITE)
+ || method.equals(SipMethods.CANCEL)
+ || method.equals(SipMethods.BYE)) {
+ super.onTransFailureResponse(tc, msg);
+ } else if (tc.getTransactionMethod().equals(SipMethods.REFER)) {
+ transactions.remove(tc.getTransactionId());
+ dialog_listener.onDlgReferResponse(this, code, reason, msg);
+ } else {
+ String body = msg.getBody();
+ transactions.remove(tc.getTransactionId());
+ dialog_listener.onDlgAltResponse(this, method, code, reason, body,
+ msg);
+ }
+ }
+
+ /**
+ * Inherited from TransactionClientListener. When an
+ * TransactionClientListener goes into the "Terminated" state, receiving a
+ * 2xx response
+ */
+ public void onTransSuccessResponse(TransactionClient t, Message msg) {
+ printLog("inside onTransSuccessResponse(" + t.getTransactionId()
+ + ",msg)", LogLevel.LOW);
+ attempts = 0;
+ String method = t.getTransactionMethod();
+ StatusLine status_line = msg.getStatusLine();
+ int code = status_line.getCode();
+ String reason = status_line.getReason();
+
+ if (method.equals(SipMethods.INVITE)
+ || method.equals(SipMethods.CANCEL)
+ || method.equals(SipMethods.BYE)) {
+ super.onTransSuccessResponse(t, msg);
+ } else if (t.getTransactionMethod().equals(SipMethods.REFER)) {
+ transactions.remove(t.getTransactionId());
+ dialog_listener.onDlgReferResponse(this, code, reason, msg);
+ } else {
+ String body = msg.getBody();
+ transactions.remove(t.getTransactionId());
+ dialog_listener.onDlgAltResponse(this, method, code, reason, body,
+ msg);
+ }
+ }
+
+ /**
+ * Inherited from TransactionClientListener. When the TransactionClient goes
+ * into the "Terminated" state, caused by transaction timeout
+ */
+ public void onTransTimeout(TransactionClient t) {
+ printLog("inside onTransTimeout(" + t.getTransactionId() + ",msg)",
+ LogLevel.LOW);
+ String method = t.getTransactionMethod();
+ if (method.equals(SipMethods.INVITE) || method.equals(SipMethods.BYE)) {
+ super.onTransTimeout(t);
+ } else { // do something..
+ transactions.remove(t.getTransactionId());
+ }
+ }
+
+ // **************************** Logs ****************************/
+
+ /** Adds a new string to the default Log */
+ protected void printLog(String str, int level) {
+ if (log != null)
+ log.println("ExtendedInviteDialog#" + dialog_sqn + ": " + str,
+ level + SipStack.LOG_LEVEL_DIALOG);
+ }
+
+}
diff --git a/src/org/zoolu/sip/dialog/ExtendedInviteDialogListener.java b/app/src/main/java/org/zoolu/sip/dialog/ExtendedInviteDialogListener.java
similarity index 97%
rename from src/org/zoolu/sip/dialog/ExtendedInviteDialogListener.java
rename to app/src/main/java/org/zoolu/sip/dialog/ExtendedInviteDialogListener.java
index d5afcd3..ff4e706 100644
--- a/src/org/zoolu/sip/dialog/ExtendedInviteDialogListener.java
+++ b/app/src/main/java/org/zoolu/sip/dialog/ExtendedInviteDialogListener.java
@@ -1,72 +1,72 @@
-/*
- * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
- *
- * This file is part of MjSip (http://www.mjsip.org)
- *
- * MjSip is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * MjSip is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with MjSip; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author(s):
- * Luca Veltri (luca.veltri@unipr.it)
- */
-
-package org.zoolu.sip.dialog;
-
-import org.zoolu.sip.address.NameAddress;
-import org.zoolu.sip.message.Message;
-
-/**
- * An ExtendedInviteDialogListener listens for ExtendedInviteDialog events. It
- * extends InviteDialogListener by adding ExtendedInviteDialog-specific callback
- * functions.
- */
-public interface ExtendedInviteDialogListener extends
- org.zoolu.sip.dialog.InviteDialogListener {
-
- /** When an incoming REFER request is received within the dialog */
- public void onDlgRefer(org.zoolu.sip.dialog.InviteDialog dialog,
- NameAddress refer_to, NameAddress referred_by, Message msg);
-
- /** When a response is received for a REFER request within the dialog */
- public void onDlgReferResponse(org.zoolu.sip.dialog.InviteDialog dialog,
- int code, String reason, Message msg);
-
- /** When an incoming NOTIFY request is received within the dialog */
- public void onDlgNotify(org.zoolu.sip.dialog.InviteDialog dialog,
- String event, String sipfragment, Message msg);
-
- /** When a response is received for a NOTIFY request within the dialog */
- // public void onDlgNotifyResponse(org.zoolu.sip.dialog.InviteDialog dialog,
- // int code, String reason, Message msg);
- /**
- * When an incoming request is received within the dialog different from
- * INVITE, CANCEL, ACK, BYE, REFER, NOTIFY
- */
- public void onDlgAltRequest(org.zoolu.sip.dialog.InviteDialog dialog,
- String method, String body, Message msg);
-
- /**
- * When a response is received for a request within the dialog different
- * from INVITE, CANCEL, ACK, BYE, REFER, NOTIFY
- */
- public void onDlgAltResponse(org.zoolu.sip.dialog.InviteDialog dialog,
- String method, int code, String reason, String body, Message msg);
-
- /**
- * When a request timeout expires within the dialog different from INVITE,
- * CANCEL, ACK, BYE, REFER, NOTIFY
- */
- // public void onDlgAltTimeout(org.zoolu.sip.dialog.InviteDialog dialog,
- // String method);
-}
+/*
+ * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
+ *
+ * This file is part of MjSip (http://www.mjsip.org)
+ *
+ * MjSip is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * MjSip is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MjSip; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author(s):
+ * Luca Veltri (luca.veltri@unipr.it)
+ */
+
+package org.zoolu.sip.dialog;
+
+import org.zoolu.sip.address.NameAddress;
+import org.zoolu.sip.message.Message;
+
+/**
+ * An ExtendedInviteDialogListener listens for ExtendedInviteDialog events. It
+ * extends InviteDialogListener by adding ExtendedInviteDialog-specific callback
+ * functions.
+ */
+public interface ExtendedInviteDialogListener extends
+ org.zoolu.sip.dialog.InviteDialogListener {
+
+ /** When an incoming REFER request is received within the dialog */
+ public void onDlgRefer(org.zoolu.sip.dialog.InviteDialog dialog,
+ NameAddress refer_to, NameAddress referred_by, Message msg);
+
+ /** When a response is received for a REFER request within the dialog */
+ public void onDlgReferResponse(org.zoolu.sip.dialog.InviteDialog dialog,
+ int code, String reason, Message msg);
+
+ /** When an incoming NOTIFY request is received within the dialog */
+ public void onDlgNotify(org.zoolu.sip.dialog.InviteDialog dialog,
+ String event, String sipfragment, Message msg);
+
+ /** When a response is received for a NOTIFY request within the dialog */
+ // public void onDlgNotifyResponse(org.zoolu.sip.dialog.InviteDialog dialog,
+ // int code, String reason, Message msg);
+ /**
+ * When an incoming request is received within the dialog different from
+ * INVITE, CANCEL, ACK, BYE, REFER, NOTIFY
+ */
+ public void onDlgAltRequest(org.zoolu.sip.dialog.InviteDialog dialog,
+ String method, String body, Message msg);
+
+ /**
+ * When a response is received for a request within the dialog different
+ * from INVITE, CANCEL, ACK, BYE, REFER, NOTIFY
+ */
+ public void onDlgAltResponse(org.zoolu.sip.dialog.InviteDialog dialog,
+ String method, int code, String reason, String body, Message msg);
+
+ /**
+ * When a request timeout expires within the dialog different from INVITE,
+ * CANCEL, ACK, BYE, REFER, NOTIFY
+ */
+ // public void onDlgAltTimeout(org.zoolu.sip.dialog.InviteDialog dialog,
+ // String method);
+}
diff --git a/src/org/zoolu/sip/dialog/InviteDialog.java b/app/src/main/java/org/zoolu/sip/dialog/InviteDialog.java
similarity index 96%
rename from src/org/zoolu/sip/dialog/InviteDialog.java
rename to app/src/main/java/org/zoolu/sip/dialog/InviteDialog.java
index f1ef3d9..9484e0f 100644
--- a/src/org/zoolu/sip/dialog/InviteDialog.java
+++ b/app/src/main/java/org/zoolu/sip/dialog/InviteDialog.java
@@ -1,902 +1,902 @@
-/*
- * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
- * Copyright (C) 2009 The Sipdroid Open Source Project
- *
- * This file is part of MjSip (http://www.mjsip.org)
- *
- * MjSip is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * MjSip is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with MjSip; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author(s):
- * Luca Veltri (luca.veltri@unipr.it)
- */
-
-package org.zoolu.sip.dialog;
-
-import org.zoolu.sip.address.*;
-import org.zoolu.sip.transaction.*;
-import org.zoolu.sip.message.*;
-import org.zoolu.sip.header.*;
-import org.zoolu.sip.provider.*;
-import org.zoolu.tools.LogLevel;
-
-/**
- * Class InviteDialog can be used to manage invite dialogs. An InviteDialog can
- * be both client or server. (i.e. generating an INVITE request or responding to
- * an incoming INVITE request).
- *
- * An InviteDialog can be in state inviting/waiting/invited, accepted/refused,
- * call, byed/byeing, and close.
- *
- * InviteDialog supports the offer/answer model for the sip body, with the
- * following rules:
- both INVITE-offer/2xx-answer and 2xx-offer/ACK-answer
- * modes for incoming calls
- INVITE-offer/2xx-answer mode for outgoing
- * calls.
- */
-public class InviteDialog extends Dialog implements TransactionClientListener,
- InviteTransactionServerListener, AckTransactionServerListener,
- SipProviderListener {
- /** The last invite message */
- Message invite_req;
- /** The last ack message */
- Message ack_req;
-
- /** The InviteTransactionServer. */
- InviteTransactionServer invite_ts;
- /** The AckTransactionServer. */
- AckTransactionServer ack_ts;
- /** The BYE TransactionServer. */
- TransactionServer bye_ts;
-
- /** The InviteDialog listener */
- InviteDialogListener listener;
-
- /** Whether offer/answer are in INVITE/200_OK */
- boolean invite_offer;
-
- protected static final int D_INIT = 0;
- protected static final int D_WAITING = 1;
- protected static final int D_INVITING = 2;
- protected static final int D_INVITED = 3;
- protected static final int D_REFUSED = 4;
- protected static final int D_ACCEPTED = 5;
- protected static final int D_CALL = 6;
-
- protected static final int D_ReWAITING = 11;
- protected static final int D_ReINVITING = 12;
- protected static final int D_ReINVITED = 13;
- protected static final int D_ReREFUSED = 14;
- protected static final int D_ReACCEPTED = 15;
-
- protected static final int D_BYEING = 7;
- protected static final int D_BYED = 8;
- protected static final int D_CLOSE = 9;
-
- /** Gets the dialog state */
- protected String getStatusDescription() {
- switch (status) {
- case D_INIT:
- return "D_INIT";
- case D_WAITING:
- return "D_WAITING";
- case D_INVITING:
- return "D_INVITING";
- case D_INVITED:
- return "D_INVITED";
- case D_REFUSED:
- return "D_REFUSED";
- case D_ACCEPTED:
- return "D_ACCEPTED";
- case D_CALL:
- return "D_CALL";
- case D_ReWAITING:
- return "D_ReWAITING";
- case D_ReINVITING:
- return "D_ReINVITING";
- case D_ReINVITED:
- return "D_ReINVITED";
- case D_ReREFUSED:
- return "D_ReREFUSED";
- case D_ReACCEPTED:
- return "D_ReACCEPTED";
- case D_BYEING:
- return "D_BYEING";
- case D_BYED:
- return "D_BYED";
- case D_CLOSE:
- return "D_CLOSE";
- default:
- return null;
- }
- }
-
- protected int getStatus()
- {
- return status;
- }
-
- // ************************** Public methods **************************
-
- /** Whether the dialog is in "early" state. */
- public boolean isEarly() {
- return status < D_ACCEPTED;
- }
-
- /** Whether the dialog is in "confirmed" state. */
- public boolean isConfirmed() {
- return status >= D_ACCEPTED && status < D_CLOSE;
- }
-
- /** Whether the dialog is in "terminated" state. */
- public boolean isTerminated() {
- return status == D_CLOSE;
- }
-
- /** Whether the session is "active". */
- public boolean isSessionActive() {
- return (status == D_CALL);
- }
-
- /** Gets the invite message */
- public Message getInviteMessage() {
- return invite_req;
- }
-
- /** Creates a new InviteDialog. */
- public InviteDialog(SipProvider sip_provider, InviteDialogListener listener) {
- super(sip_provider);
- init(listener);
- }
-
- /**
- * Creates a new InviteDialog for the already received INVITE request
- * invite.
- */
- public InviteDialog(SipProvider sip_provider, Message invite,
- InviteDialogListener listener) {
- super(sip_provider);
- init(listener);
-
- changeStatus(D_INVITED);
- invite_req = invite;
- invite_ts = new InviteTransactionServer(sip_provider, invite_req, this);
- update(Dialog.UAS, invite_req);
- }
-
- /** Inits the InviteDialog. */
- private void init(InviteDialogListener listener) {
- log = sip_provider.getLog();
- this.listener = listener;
- this.invite_req = null;
- this.ack_req = null;
- this.invite_offer = true;
- changeStatus(D_INIT);
- }
-
- /** Starts a new InviteTransactionServer. */
- public void listen() {
- if (!statusIs(D_INIT))
- return;
- // else
- changeStatus(D_WAITING);
- invite_ts = new InviteTransactionServer(sip_provider, this);
- invite_ts.listen();
- }
-
- /**
- * Starts a new InviteTransactionClient and initializes the dialog state
- * information.
- *
- * @param callee
- * the callee url (and display name)
- * @param caller
- * the caller url (and display name)
- * @param contact
- * the contact url OR the contact username
- * @param session_descriptor
- * SDP body
- * @param icsi
- * the ICSI for this session
- *
- */
- public void invite(String callee, String caller, String contact,
- String session_descriptor, String icsi) { // modified by mandrajg
- printLog("inside invite(callee,caller,contact,sdp)", LogLevel.MEDIUM);
- if (!statusIs(D_INIT))
- return;
- // else
- NameAddress to_url = new NameAddress(callee);
- NameAddress from_url = new NameAddress(caller);
- SipURL request_uri = to_url.getAddress();
-
- NameAddress contact_url = null;
- if (contact != null) {
- if (contact.indexOf("sip:") >= 0)
- contact_url = new NameAddress(contact);
- else
- contact_url = new NameAddress(new SipURL(contact, sip_provider
- .getViaAddress(), sip_provider.getPort()));
- } else
- contact_url = from_url;
-
- Message invite = MessageFactory.createInviteRequest(sip_provider,
- request_uri, to_url, from_url, contact_url, session_descriptor, icsi); // modified by mandrajg
- // do invite
- invite(invite);
- }
-
- /**
- * Starts a new InviteTransactionClient and initializes the dialog state
- * information
- *
- * @param invite
- * the INVITE message
- */
- public void invite(Message invite) {
- printLog("inside invite(invite)", LogLevel.MEDIUM);
- if (!statusIs(D_INIT))
- return;
- // else
- changeStatus(D_INVITING);
- invite_req = invite;
- update(Dialog.UAC, invite_req);
- InviteTransactionClient invite_tc = new InviteTransactionClient(
- sip_provider, invite_req, this);
- invite_tc.request();
- }
-
- /**
- * Starts a new InviteTransactionClient with offer/answer in 2xx/ack and
- * initializes the dialog state information
- */
- public void inviteWithoutOffer(String callee, String caller, String contact) {
- invite_offer = false;
- invite(callee, caller, contact, null, null); // modified by mandrajg
- }
-
- /**
- * Starts a new InviteTransactionClient with offer/answer in 2xx/ack and
- * initializes the dialog state information
- */
- public void inviteWithoutOffer(Message invite) {
- invite_offer = false;
- invite(invite);
- }
-
- /**
- * Re-invites the remote user.
- *
- * Starts a new InviteTransactionClient and changes the dialog state
- * information
- *
- * Parameters:
- contact : the contact url OR the contact username; if
- * null, the previous contact is used
- session_descriptor : the
- * message body
- */
- public void reInvite(String contact, String session_descriptor) {
- printLog("inside reInvite(contact,sdp)", LogLevel.MEDIUM);
- if (!statusIs(D_CALL))
- return;
- // else
- Message invite = MessageFactory.createInviteRequest(this,
- session_descriptor);
- if (contact != null) {
- NameAddress contact_url;
- if (contact.indexOf("sip:") >= 0)
- contact_url = new NameAddress(contact);
- else
- contact_url = new NameAddress(new SipURL(contact, sip_provider
- .getViaAddress(), sip_provider.getPort()));
- invite.setContactHeader(new ContactHeader(contact_url));
- }
- reInvite(invite);
- }
-
- /**
- * Re-invites the remote user.
- *
- * Starts a new InviteTransactionClient and changes the dialog state
- * information
- */
- public void reInvite(Message invite) {
- printLog("inside reInvite(invite)", LogLevel.MEDIUM);
- if (!statusIs(D_CALL))
- return;
- // else
- changeStatus(D_ReINVITING);
- invite_req = invite;
- update(Dialog.UAC, invite_req);
- InviteTransactionClient invite_tc = new InviteTransactionClient(
- sip_provider, invite_req, this);
- invite_tc.request();
- }
-
- /**
- * Re-invites the remote user with offer/answer in 2xx/ack
- *
- * Starts a new InviteTransactionClient and changes the dialog state
- * information
- */
- public void reInviteWithoutOffer(Message invite) {
- invite_offer = false;
- reInvite(invite);
- }
-
- /**
- * Re-invites the remote user with offer/answer in 2xx/ack
- *
- * Starts a new InviteTransactionClient and changes the dialog state
- * information
- */
- public void reInviteWithoutOffer(String contact, String session_descriptor) {
- invite_offer = false;
- reInvite(contact, session_descriptor);
- }
-
- /** Sends the ack when offer/answer is in 2xx/ack */
- public void ackWithAnswer(String contact, String session_descriptor) {
- if (contact != null)
- setLocalContact(new NameAddress(contact));
- Message ack = MessageFactory.create2xxAckRequest(this,
- session_descriptor);
- ackWithAnswer(ack);
- }
-
- /** Sends the ack when offer/answer is in 2xx/ack */
- public void ackWithAnswer(Message ack) {
- ack_req = ack;
- // reset the offer/answer flag to the default value
- invite_offer = true;
- AckTransactionClient ack_tc = new AckTransactionClient(sip_provider,
- ack, null);
- ack_tc.request();
- }
-
- /**
- * Responds with resp. This method can be called when the
- * InviteDialog is in D_INVITED or D_BYED states.
- *
- * If the CSeq method is INVITE and the response is 2xx, it moves to state
- * D_ACCEPTED, adds a new listener to the SipProviderListener, and creates
- * new AckTransactionServer
- *
- * If the CSeq method is INVITE and the response is not 2xx, it moves to
- * state D_REFUSED, and sends the response.
- */
- public void respond(Message resp)
- // private void respond(Message resp)
- {
- printLog("inside respond(resp)", LogLevel.MEDIUM);
- String method = resp.getCSeqHeader().getMethod();
- if (method.equals(SipMethods.INVITE)) {
- if (!verifyStatus(statusIs(D_INVITED) || statusIs(D_ReINVITED))) {
- printLog(
- "respond(): InviteDialog not in (re)invited state: No response now",
- LogLevel.HIGH);
- return;
- }
-
- int code = resp.getStatusLine().getCode();
- // 1xx provisional responses
- if (code >= 100 && code < 200) {
- invite_ts.respondWith(resp);
- return;
- }
- // For all final responses establish the dialog
- if (code >= 200) { // changeStatus(D_ACCEPTED);
- update(Dialog.UAS, resp);
- }
- // 2xx success responses
- if (code >= 200 && code < 300) {
- if (statusIs(D_INVITED))
- changeStatus(D_ACCEPTED);
- else
- changeStatus(D_ReACCEPTED);
- // terminates the INVITE Transaction server and activates an ACK
- // Transaction server
- invite_ts.terminate();
- ConnectionIdentifier conn_id = invite_ts.getConnectionId();
- ack_ts = new AckTransactionServer(sip_provider, conn_id, resp,
- this);
- ack_ts.respond();
- // if (statusIs(D_ReACCEPTED))
- // listener.onDlgReInviteAccepted(this);
- // else listener.onDlgAccepted(this);
- return;
- } else
- // 300-699 failure responses
- // if (code>=300)
- {
- if (statusIs(D_INVITED))
- changeStatus(D_REFUSED);
- else
- changeStatus(D_ReREFUSED);
- invite_ts.respondWith(resp);
- // if (statusIs(D_ReREFUSED))
- // listener.onDlgReInviteRefused(this);
- // else listener.onDlgRefused(this);
- return;
- }
- }
- if (method.equals(SipMethods.BYE)) {
- if (!verifyStatus(statusIs(D_BYED)))
- return;
- bye_ts.respondWith(resp);
- }
- }
-
- /**
- * Responds with code and reason. This method can be called
- * when the InviteDialog is in D_INVITED, D_ReINVITED states
- */
- public void respond(int code, String reason, String contact, String sdp) {
- printLog("inside respond(" + code + "," + reason + ")", LogLevel.MEDIUM);
- if (statusIs(D_INVITED) || statusIs(D_ReINVITED)) {
- NameAddress contact_address = null;
- if (contact != null)
- contact_address = new NameAddress(contact);
- Message resp = MessageFactory.createResponse(invite_req, code,
- reason, contact_address);
- resp.setBody(sdp);
- respond(resp);
- } else
- printWarning("Dialog isn't in \"invited\" state: cannot respond ("
- + code + "/" + getStatus() + "/" + getDialogID() + ")",
- LogLevel.MEDIUM);
- }
-
- /**
- * Signals that the phone is ringing. This method should be called when the
- * InviteDialog is in D_INVITED or D_ReINVITED state
- */
- public void ring(String sdp) { // modified
- printLog("inside ring()", LogLevel.MEDIUM);
- respond(180, SipResponses.reasonOf(180), null, sdp);
- }
-
- /**
- * Accepts the incoming call. This method should be called when the
- * InviteDialog is in D_INVITED or D_ReINVITED state
- */
- public void accept(String contact, String sdp) {
- printLog("inside accept(sdp)", LogLevel.MEDIUM);
- respond(200, SipResponses.reasonOf(200), contact, sdp);
- }
-
- /**
- * Refuses the incoming call. This method should be called when the
- * InviteDialog is in D_INVITED or D_ReINVITED state
- */
- public void refuse(int code, String reason) {
- printLog("inside refuse(" + code + "," + reason + ")", LogLevel.MEDIUM);
- respond(code, reason, null, null);
- }
-
- /**
- * Refuses the incoming call. This method should be called when the
- * InviteDialog is in D_INVITED or D_ReINVITED state
- */
- public void refuse() {
- printLog("inside refuse()", LogLevel.MEDIUM);
- // refuse(480,"Temporarily Unavailable");
- // refuse(603,"Decline");
- refuse(403, SipResponses.reasonOf(403));
- }
-
- public void busy() {
- refuse(486, SipResponses.reasonOf(486)); // modified
- }
-
- /**
- * Termiante the call. This method should be called when the InviteDialog is
- * in D_CALL state
- *
- * Increments the Cseq, moves to state D_BYEING, and creates new BYE
- * TransactionClient
- */
- public void bye() {
- printLog("inside bye()", LogLevel.MEDIUM);
- if (statusIs(D_CALL)) {
- Message bye = MessageFactory.createByeRequest(this);
- bye(bye);
- }
- }
-
- /**
- * Termiante the call. This method should be called when the InviteDialog is
- * in D_CALL state
- *
- * Increments the Cseq, moves to state D_BYEING, and creates new BYE
- * TransactionClient
- */
- public void bye(Message bye) {
- printLog("inside bye(bye)", LogLevel.MEDIUM);
- if (statusIs(D_CALL)) {
- changeStatus(D_BYEING);
- // dialog_state.incLocalCSeq(); // done by
- // MessageFactory.createRequest()
- TransactionClient tc = new TransactionClient(sip_provider, bye,
- this);
- tc.request();
- // listener.onDlgByeing(this);
- }
- }
-
- /**
- * Cancel the ongoing call request or a call listening. This method should
- * be called when the InviteDialog is in D_INVITING or D_ReINVITING state or
- * in the D_WAITING state
- */
- public void cancel() {
- printLog("inside cancel()", LogLevel.MEDIUM);
- if (statusIs(D_INVITING) || statusIs(D_ReINVITING)) {
- Message cancel = MessageFactory.createCancelRequest(invite_req,this); // modified
- cancel(cancel);
- } else if (statusIs(D_WAITING) || statusIs(D_ReWAITING)) {
- invite_ts.terminate();
- }
- }
-
- /**
- * Cancel the ongoing call request or a call listening. This method should
- * be called when the InviteDialog is in D_INVITING or D_ReINVITING state or
- * in the D_WAITING state
- */
- public void cancel(Message cancel) {
- printLog("inside cancel(cancel)", LogLevel.MEDIUM);
- if (statusIs(D_INVITING) || statusIs(D_ReINVITING)) { // changeStatus(D_CANCELING);
- TransactionClient tc = new TransactionClient(sip_provider, cancel,
- null);
- tc.request();
- } else if (statusIs(D_WAITING) || statusIs(D_ReWAITING)) {
- invite_ts.terminate();
- }
- }
-
- /**
- * Redirects the incoming call , specifing the code and reason.
- * This method can be called when the InviteDialog is in D_INVITED or
- * D_ReINVITED state
- */
- public void redirect(int code, String reason, String contact) {
- printLog(
- "inside redirect(" + code + "," + reason + "," + contact + ")",
- LogLevel.MEDIUM);
- respond(code, reason, contact, null);
- }
-
- // ************** Inherited from SipProviderListener **************
-
- /**
- * Inherited from class SipProviderListener. Called when a new message is
- * received (out of any ongoing transaction) for the current InviteDialog.
- * Always checks for out-of-date methods (CSeq header sequence number).
- *
- * If the message is ACK(2xx/INVITE) request, it moves to D_CALL state, and
- * fires onDlgAck(this,body,msg).
- *
- * If the message is 2xx(INVITE) response, it create a new
- * AckTransactionClient
- *
- * If the message is BYE, it moves to D_BYED state, removes the listener
- * from SipProvider, fires onDlgBye(this,msg) then it responds with 200 OK,
- * moves to D_CLOSE state and fires onDlgClose(this)
- */
- public void onReceivedMessage(SipProvider sip_provider, Message msg) {
- printLog("inside onReceivedMessage(sip_provider,message)",
- LogLevel.MEDIUM);
- if (msg.isRequest() && !(msg.isAck() || msg.isCancel())
- && msg.getCSeqHeader().getSequenceNumber() <= getRemoteCSeq()) {
- printLog(
- "Request message is too late (CSeq too small): Message discarded",
- LogLevel.HIGH);
- return;
- }
- // invite received
- if (msg.isRequest() && msg.isInvite()) {
- verifyStatus(statusIs(D_INIT) || statusIs(D_CALL));
- // NOTE: if the invite_ts.listen() is used, you should not arrive
- // here with the D_INIT state..
- // however state D_INIT has been included for robustness against
- // further changes.
- if (statusIs(D_INIT))
- changeStatus(D_INVITED);
- else
- changeStatus(D_ReINVITED);
- invite_req = msg;
- invite_ts = new InviteTransactionServer(sip_provider, invite_req,
- this);
- // ((TransactionServer)transaction).listen();
- update(Dialog.UAS, invite_req);
- if (statusIs(D_INVITED))
- listener.onDlgInvite(this, invite_req.getToHeader()
- .getNameAddress(), invite_req.getFromHeader()
- .getNameAddress(), invite_req.getBody(), invite_req);
- else
- listener.onDlgReInvite(this, invite_req.getBody(), invite_req);
- } else
- // ack (of 2xx of INVITE)
- if (msg.isRequest() && msg.isAck()) {
- if (!verifyStatus(statusIs(D_ACCEPTED) || statusIs(D_ReACCEPTED)))
- return;
- changeStatus(D_CALL);
- // terminates the AckTransactionServer
- ack_ts.terminate();
- listener.onDlgAck(this, msg.getBody(), msg);
- listener.onDlgCall(this);
- } else
- // keep sending ACK (if already sent) for any "200 OK" received
- if (msg.isResponse()) {
- if (!verifyStatus(statusIs(D_CALL)))
- return;
- int code = msg.getStatusLine().getCode();
- verifyThat(code >= 200 && code < 300, "code 2xx was expected");
- if (ack_req != null) {
- AckTransactionClient ack_tc = new AckTransactionClient(
- sip_provider, ack_req, null);
- ack_tc.request();
- }
- } else
- // bye received
- if (msg.isRequest() && msg.isBye()) {
- if (!verifyStatus(statusIs(D_CALL) || statusIs(D_BYEING)))
- return;
- changeStatus(D_BYED);
- bye_ts = new TransactionServer(sip_provider, msg, this);
- // automatically sends a 200 OK
- Message resp = MessageFactory.createResponse(msg, 200, SipResponses
- .reasonOf(200), null);
- respond(resp);
- listener.onDlgBye(this, msg);
- changeStatus(D_CLOSE);
- listener.onDlgClose(this);
- } else
- // cancel received
- if (msg.isRequest() && msg.isCancel()) {
- if (!verifyStatus(statusIs(D_INVITED) || statusIs(D_ReINVITED)))
- return;
- // create a CANCEL TransactionServer and send a 200 OK (CANCEL)
- TransactionServer ts = new TransactionServer(sip_provider, msg,
- null);
- // ts.listen();
- ts.respondWith(MessageFactory.createResponse(msg, 200, SipResponses
- .reasonOf(200), null));
- // automatically sends a 487 Cancelled
- Message resp = MessageFactory.createResponse(invite_req, 487,
- SipResponses.reasonOf(487), null);
- respond(resp);
- listener.onDlgCancel(this, msg);
- } else
- // any other request received
- if (msg.isRequest()) {
- TransactionServer ts = new TransactionServer(sip_provider, msg,
- null);
- // ts.listen();
- ts.respondWith(MessageFactory.createResponse(msg, 405, SipResponses
- .reasonOf(405), null));
- }
- }
-
- // ************** Inherited from InviteTransactionClientListener
- // **************
-
- /**
- * Inherited from TransactionClientListener. When the
- * TransactionClientListener is in "Proceeding" state and receives a new 1xx
- * response
- *
- * For INVITE transaction it fires
- * onFailureResponse(this,code,reason,body,msg).
- */
- public void onTransProvisionalResponse(TransactionClient tc, Message msg) {
- printLog("inside onTransProvisionalResponse(tc,mdg)", LogLevel.LOW);
- if (tc.getTransactionMethod().equals(SipMethods.INVITE)) {
- StatusLine statusline = msg.getStatusLine();
- listener.onDlgInviteProvisionalResponse(this, statusline.getCode(),
- statusline.getReason(), msg.getBody(), msg);
- }
- }
-
- /**
- * Inherited from TransactionClientListener. When the
- * TransactionClientListener goes into the "Completed" state, receiving a
- * failure response
- *
- * If called for a INVITE transaction, it moves to D_CLOSE state, removes
- * the listener from SipProvider.
- *
- * If called for a BYE transaction, it moves to D_CLOSE state, removes the
- * listener from SipProvider, and fires onClose(this,msg).
- */
- public void onTransFailureResponse(TransactionClient tc, Message msg) {
- printLog("inside onTransFailureResponse(" + tc.getTransactionId()
- + ",msg)", LogLevel.LOW);
- if (tc.getTransactionMethod().equals(SipMethods.INVITE)) {
- if (!verifyStatus(statusIs(D_INVITING) || statusIs(D_ReINVITING)))
- return;
- StatusLine statusline = msg.getStatusLine();
- int code = statusline.getCode();
- verifyThat(code >= 300 && code < 700, "error code was expected");
- if (statusIs(D_ReINVITING)) {
- changeStatus(D_CALL);
- listener.onDlgReInviteFailureResponse(this, code, statusline
- .getReason(), msg);
- } else {
- changeStatus(D_CLOSE);
- if (code >= 300 && code < 400)
- listener.onDlgInviteRedirectResponse(this, code, statusline
- .getReason(), msg.getContacts(), msg);
- else
- listener.onDlgInviteFailureResponse(this, code, statusline
- .getReason(), msg);
- listener.onDlgClose(this);
- }
- } else if (tc.getTransactionMethod().equals(SipMethods.BYE)) {
- if (!verifyStatus(statusIs(D_BYEING)))
- return;
- StatusLine statusline = msg.getStatusLine();
- int code = statusline.getCode();
- verifyThat(code >= 300 && code < 700, "error code was expected");
- changeStatus(InviteDialog.D_CALL);
- listener.onDlgByeFailureResponse(this, code,
- statusline.getReason(), msg);
- }
- }
-
- /**
- * Inherited from TransactionClientListener. When an
- * TransactionClientListener goes into the "Terminated" state, receiving a
- * 2xx response
- *
- * If called for a INVITE transaction, it updates the dialog information,
- * moves to D_CALL state, add a listener to the SipProvider, creates a new
- * AckTransactionClient(ack,this), and fires
- * onSuccessResponse(this,code,body,msg).
- *
- * If called for a BYE transaction, it moves to D_CLOSE state, removes the
- * listener from SipProvider, and fires onClose(this,msg).
- */
- public void onTransSuccessResponse(TransactionClient tc, Message msg) {
- printLog("inside onTransSuccessResponse(tc,msg)", LogLevel.LOW);
- if (tc.getTransactionMethod().equals(SipMethods.INVITE)) {
- if (!verifyStatus(statusIs(D_INVITING) || statusIs(D_ReINVITING)))
- return;
- StatusLine statusline = msg.getStatusLine();
- int code = statusline.getCode();
- if (!verifyThat(code >= 200 && code < 300
- && msg.getTransactionMethod().equals(SipMethods.INVITE),
- "2xx for invite was expected"))
- return;
- boolean re_inviting = statusIs(D_ReINVITING);
- changeStatus(D_CALL);
- update(Dialog.UAC, msg);
- if (invite_offer) { // invite_req=MessageFactory.createRequest(SipMethods.ACK,dialog_state,sdp.toString());
- // ack=MessageFactory.createRequest(this,SipMethods.ACK,null);
- ack_req = MessageFactory.create2xxAckRequest(this, null);
- AckTransactionClient ack_tc = new AckTransactionClient(
- sip_provider, ack_req, null);
- ack_tc.request();
- }
- if (!re_inviting) {
- listener.onDlgInviteSuccessResponse(this, code, statusline
- .getReason(), msg.getBody(), msg);
- listener.onDlgCall(this);
- } else
- listener.onDlgReInviteSuccessResponse(this, code, statusline
- .getReason(), msg.getBody(), msg);
- } else if (tc.getTransactionMethod().equals(SipMethods.BYE)) {
- if (!verifyStatus(statusIs(D_BYEING)))
- return;
- StatusLine statusline = msg.getStatusLine();
- int code = statusline.getCode();
- verifyThat(code >= 200 && code < 300, "2xx for bye was expected");
- changeStatus(D_CLOSE);
- listener.onDlgByeSuccessResponse(this, code,
- statusline.getReason(), msg);
- listener.onDlgClose(this);
- }
- }
-
- /**
- * Inherited from TransactionClientListener. When the TransactionClient goes
- * into the "Terminated" state, caused by transaction timeout
- */
- public void onTransTimeout(TransactionClient tc) {
- printLog("inside onTransTimeout(tc,msg)", LogLevel.LOW);
- if (tc.getTransactionMethod().equals(SipMethods.INVITE)) {
- if (!verifyStatus(statusIs(D_INVITING) || statusIs(D_ReINVITING)))
- return;
- cancel(); //modified
- changeStatus(D_CLOSE);
- listener.onDlgTimeout(this);
- listener.onDlgClose(this);
- } else if (tc.getTransactionMethod().equals(SipMethods.BYE)) {
- if (!verifyStatus(statusIs(D_BYEING)))
- return;
- changeStatus(D_CLOSE);
- listener.onDlgClose(this);
- }
- }
-
- // ************** Inherited from InviteTransactionServerListener
- // **************
-
- /**
- * Inherited from TransactionServerListener. When the TransactionServer goes
- * into the "Trying" state receiving a request
- *
- * If called for a INVITE transaction, it initializes the dialog
- * information,
- * moves to D_INVITED state, and add a listener to the SipProvider,
- * and fires onInvite(caller,body,msg).
- */
- public void onTransRequest(TransactionServer ts, Message req) {
- printLog("inside onTransRequest(ts,msg)", LogLevel.LOW);
- if (ts.getTransactionMethod().equals(SipMethods.INVITE)) {
- if (!verifyStatus(statusIs(D_WAITING)))
- return;
- changeStatus(D_INVITED);
- invite_req = req;
- update(Dialog.UAS, invite_req);
- listener.onDlgInvite(this, invite_req.getToHeader()
- .getNameAddress(), invite_req.getFromHeader()
- .getNameAddress(), invite_req.getBody(), invite_req);
- }
- }
-
- /**
- * Inherited from InviteTransactionServerListener. When an
- * InviteTransactionServer goes into the "Confirmed" state receining an ACK
- * for NON-2xx response
- *
- * It moves to D_CLOSE state and removes the listener from SipProvider.
- */
- public void onTransFailureAck(InviteTransactionServer ts, Message msg) {
- printLog("inside onTransFailureAck(ts,msg)", LogLevel.LOW);
- if (!verifyStatus(statusIs(D_REFUSED) || statusIs(D_ReREFUSED)))
- return;
- if (statusIs(D_ReREFUSED)) {
- changeStatus(D_CALL);
- } else {
- changeStatus(D_CLOSE);
- listener.onDlgClose(this);
- }
- }
-
- // ************ Inherited from AckTransactionServerListener ************
-
- /**
- * When the AckTransactionServer goes into the "Terminated" state, caused by
- * transaction timeout
- */
- public void onTransAckTimeout(AckTransactionServer ts) {
- printLog("inside onAckSrvTimeout(ts)", LogLevel.LOW);
- if (!verifyStatus(statusIs(D_ACCEPTED) || statusIs(D_ReACCEPTED)
- || statusIs(D_REFUSED) || statusIs(D_ReREFUSED)))
- return;
- printLog("No ACK received..", LogLevel.HIGH);
- changeStatus(D_CLOSE);
- listener.onDlgClose(this);
- }
-
- // **************************** Logs ****************************/
-
- /** Adds a new string to the default Log */
- protected void printLog(String str, int level) {
- if (log != null)
- log.println("InviteDialog#" + dialog_sqn + ": " + str, level
- + SipStack.LOG_LEVEL_DIALOG);
- }
-
-}
+/*
+ * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
+ * Copyright (C) 2009 The Sipdroid Open Source Project
+ *
+ * This file is part of MjSip (http://www.mjsip.org)
+ *
+ * MjSip is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * MjSip is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MjSip; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author(s):
+ * Luca Veltri (luca.veltri@unipr.it)
+ */
+
+package org.zoolu.sip.dialog;
+
+import org.zoolu.sip.address.*;
+import org.zoolu.sip.transaction.*;
+import org.zoolu.sip.message.*;
+import org.zoolu.sip.header.*;
+import org.zoolu.sip.provider.*;
+import org.zoolu.tools.LogLevel;
+
+/**
+ * Class InviteDialog can be used to manage invite dialogs. An InviteDialog can
+ * be both client or server. (i.e. generating an INVITE request or responding to
+ * an incoming INVITE request).
+ *
+ * An InviteDialog can be in state inviting/waiting/invited, accepted/refused,
+ * call, byed/byeing, and close.
+ *
+ * InviteDialog supports the offer/answer model for the sip body, with the
+ * following rules:
- both INVITE-offer/2xx-answer and 2xx-offer/ACK-answer
+ * modes for incoming calls
- INVITE-offer/2xx-answer mode for outgoing
+ * calls.
+ */
+public class InviteDialog extends Dialog implements TransactionClientListener,
+ InviteTransactionServerListener, AckTransactionServerListener,
+ SipProviderListener {
+ /** The last invite message */
+ Message invite_req;
+ /** The last ack message */
+ Message ack_req;
+
+ /** The InviteTransactionServer. */
+ InviteTransactionServer invite_ts;
+ /** The AckTransactionServer. */
+ AckTransactionServer ack_ts;
+ /** The BYE TransactionServer. */
+ TransactionServer bye_ts;
+
+ /** The InviteDialog listener */
+ InviteDialogListener listener;
+
+ /** Whether offer/answer are in INVITE/200_OK */
+ boolean invite_offer;
+
+ protected static final int D_INIT = 0;
+ protected static final int D_WAITING = 1;
+ protected static final int D_INVITING = 2;
+ protected static final int D_INVITED = 3;
+ protected static final int D_REFUSED = 4;
+ protected static final int D_ACCEPTED = 5;
+ protected static final int D_CALL = 6;
+
+ protected static final int D_ReWAITING = 11;
+ protected static final int D_ReINVITING = 12;
+ protected static final int D_ReINVITED = 13;
+ protected static final int D_ReREFUSED = 14;
+ protected static final int D_ReACCEPTED = 15;
+
+ protected static final int D_BYEING = 7;
+ protected static final int D_BYED = 8;
+ protected static final int D_CLOSE = 9;
+
+ /** Gets the dialog state */
+ protected String getStatusDescription() {
+ switch (status) {
+ case D_INIT:
+ return "D_INIT";
+ case D_WAITING:
+ return "D_WAITING";
+ case D_INVITING:
+ return "D_INVITING";
+ case D_INVITED:
+ return "D_INVITED";
+ case D_REFUSED:
+ return "D_REFUSED";
+ case D_ACCEPTED:
+ return "D_ACCEPTED";
+ case D_CALL:
+ return "D_CALL";
+ case D_ReWAITING:
+ return "D_ReWAITING";
+ case D_ReINVITING:
+ return "D_ReINVITING";
+ case D_ReINVITED:
+ return "D_ReINVITED";
+ case D_ReREFUSED:
+ return "D_ReREFUSED";
+ case D_ReACCEPTED:
+ return "D_ReACCEPTED";
+ case D_BYEING:
+ return "D_BYEING";
+ case D_BYED:
+ return "D_BYED";
+ case D_CLOSE:
+ return "D_CLOSE";
+ default:
+ return null;
+ }
+ }
+
+ protected int getStatus()
+ {
+ return status;
+ }
+
+ // ************************** Public methods **************************
+
+ /** Whether the dialog is in "early" state. */
+ public boolean isEarly() {
+ return status < D_ACCEPTED;
+ }
+
+ /** Whether the dialog is in "confirmed" state. */
+ public boolean isConfirmed() {
+ return status >= D_ACCEPTED && status < D_CLOSE;
+ }
+
+ /** Whether the dialog is in "terminated" state. */
+ public boolean isTerminated() {
+ return status == D_CLOSE;
+ }
+
+ /** Whether the session is "active". */
+ public boolean isSessionActive() {
+ return (status == D_CALL);
+ }
+
+ /** Gets the invite message */
+ public Message getInviteMessage() {
+ return invite_req;
+ }
+
+ /** Creates a new InviteDialog. */
+ public InviteDialog(SipProvider sip_provider, InviteDialogListener listener) {
+ super(sip_provider);
+ init(listener);
+ }
+
+ /**
+ * Creates a new InviteDialog for the already received INVITE request
+ * invite.
+ */
+ public InviteDialog(SipProvider sip_provider, Message invite,
+ InviteDialogListener listener) {
+ super(sip_provider);
+ init(listener);
+
+ changeStatus(D_INVITED);
+ invite_req = invite;
+ invite_ts = new InviteTransactionServer(sip_provider, invite_req, this);
+ update(Dialog.UAS, invite_req);
+ }
+
+ /** Inits the InviteDialog. */
+ private void init(InviteDialogListener listener) {
+ log = sip_provider.getLog();
+ this.listener = listener;
+ this.invite_req = null;
+ this.ack_req = null;
+ this.invite_offer = true;
+ changeStatus(D_INIT);
+ }
+
+ /** Starts a new InviteTransactionServer. */
+ public void listen() {
+ if (!statusIs(D_INIT))
+ return;
+ // else
+ changeStatus(D_WAITING);
+ invite_ts = new InviteTransactionServer(sip_provider, this);
+ invite_ts.listen();
+ }
+
+ /**
+ * Starts a new InviteTransactionClient and initializes the dialog state
+ * information.
+ *
+ * @param callee
+ * the callee url (and display name)
+ * @param caller
+ * the caller url (and display name)
+ * @param contact
+ * the contact url OR the contact username
+ * @param session_descriptor
+ * SDP body
+ * @param icsi
+ * the ICSI for this session
+ *
+ */
+ public void invite(String callee, String caller, String contact,
+ String session_descriptor, String icsi) { // modified by mandrajg
+ printLog("inside invite(callee,caller,contact,sdp)", LogLevel.MEDIUM);
+ if (!statusIs(D_INIT))
+ return;
+ // else
+ NameAddress to_url = new NameAddress(callee);
+ NameAddress from_url = new NameAddress(caller);
+ SipURL request_uri = to_url.getAddress();
+
+ NameAddress contact_url = null;
+ if (contact != null) {
+ if (contact.indexOf("sip:") >= 0)
+ contact_url = new NameAddress(contact);
+ else
+ contact_url = new NameAddress(new SipURL(contact, sip_provider
+ .getViaAddress(), sip_provider.getPort()));
+ } else
+ contact_url = from_url;
+
+ Message invite = MessageFactory.createInviteRequest(sip_provider,
+ request_uri, to_url, from_url, contact_url, session_descriptor, icsi); // modified by mandrajg
+ // do invite
+ invite(invite);
+ }
+
+ /**
+ * Starts a new InviteTransactionClient and initializes the dialog state
+ * information
+ *
+ * @param invite
+ * the INVITE message
+ */
+ public void invite(Message invite) {
+ printLog("inside invite(invite)", LogLevel.MEDIUM);
+ if (!statusIs(D_INIT))
+ return;
+ // else
+ changeStatus(D_INVITING);
+ invite_req = invite;
+ update(Dialog.UAC, invite_req);
+ InviteTransactionClient invite_tc = new InviteTransactionClient(
+ sip_provider, invite_req, this);
+ invite_tc.request();
+ }
+
+ /**
+ * Starts a new InviteTransactionClient with offer/answer in 2xx/ack and
+ * initializes the dialog state information
+ */
+ public void inviteWithoutOffer(String callee, String caller, String contact) {
+ invite_offer = false;
+ invite(callee, caller, contact, null, null); // modified by mandrajg
+ }
+
+ /**
+ * Starts a new InviteTransactionClient with offer/answer in 2xx/ack and
+ * initializes the dialog state information
+ */
+ public void inviteWithoutOffer(Message invite) {
+ invite_offer = false;
+ invite(invite);
+ }
+
+ /**
+ * Re-invites the remote user.
+ *
+ * Starts a new InviteTransactionClient and changes the dialog state
+ * information
+ *
+ * Parameters:
- contact : the contact url OR the contact username; if
+ * null, the previous contact is used
- session_descriptor : the
+ * message body
+ */
+ public void reInvite(String contact, String session_descriptor) {
+ printLog("inside reInvite(contact,sdp)", LogLevel.MEDIUM);
+ if (!statusIs(D_CALL))
+ return;
+ // else
+ Message invite = MessageFactory.createInviteRequest(this,
+ session_descriptor);
+ if (contact != null) {
+ NameAddress contact_url;
+ if (contact.indexOf("sip:") >= 0)
+ contact_url = new NameAddress(contact);
+ else
+ contact_url = new NameAddress(new SipURL(contact, sip_provider
+ .getViaAddress(), sip_provider.getPort()));
+ invite.setContactHeader(new ContactHeader(contact_url));
+ }
+ reInvite(invite);
+ }
+
+ /**
+ * Re-invites the remote user.
+ *
+ * Starts a new InviteTransactionClient and changes the dialog state
+ * information
+ */
+ public void reInvite(Message invite) {
+ printLog("inside reInvite(invite)", LogLevel.MEDIUM);
+ if (!statusIs(D_CALL))
+ return;
+ // else
+ changeStatus(D_ReINVITING);
+ invite_req = invite;
+ update(Dialog.UAC, invite_req);
+ InviteTransactionClient invite_tc = new InviteTransactionClient(
+ sip_provider, invite_req, this);
+ invite_tc.request();
+ }
+
+ /**
+ * Re-invites the remote user with offer/answer in 2xx/ack
+ *
+ * Starts a new InviteTransactionClient and changes the dialog state
+ * information
+ */
+ public void reInviteWithoutOffer(Message invite) {
+ invite_offer = false;
+ reInvite(invite);
+ }
+
+ /**
+ * Re-invites the remote user with offer/answer in 2xx/ack
+ *
+ * Starts a new InviteTransactionClient and changes the dialog state
+ * information
+ */
+ public void reInviteWithoutOffer(String contact, String session_descriptor) {
+ invite_offer = false;
+ reInvite(contact, session_descriptor);
+ }
+
+ /** Sends the ack when offer/answer is in 2xx/ack */
+ public void ackWithAnswer(String contact, String session_descriptor) {
+ if (contact != null)
+ setLocalContact(new NameAddress(contact));
+ Message ack = MessageFactory.create2xxAckRequest(this,
+ session_descriptor);
+ ackWithAnswer(ack);
+ }
+
+ /** Sends the ack when offer/answer is in 2xx/ack */
+ public void ackWithAnswer(Message ack) {
+ ack_req = ack;
+ // reset the offer/answer flag to the default value
+ invite_offer = true;
+ AckTransactionClient ack_tc = new AckTransactionClient(sip_provider,
+ ack, null);
+ ack_tc.request();
+ }
+
+ /**
+ * Responds with resp. This method can be called when the
+ * InviteDialog is in D_INVITED or D_BYED states.
+ *
+ * If the CSeq method is INVITE and the response is 2xx, it moves to state
+ * D_ACCEPTED, adds a new listener to the SipProviderListener, and creates
+ * new AckTransactionServer
+ *
+ * If the CSeq method is INVITE and the response is not 2xx, it moves to
+ * state D_REFUSED, and sends the response.
+ */
+ public void respond(Message resp)
+ // private void respond(Message resp)
+ {
+ printLog("inside respond(resp)", LogLevel.MEDIUM);
+ String method = resp.getCSeqHeader().getMethod();
+ if (method.equals(SipMethods.INVITE)) {
+ if (!verifyStatus(statusIs(D_INVITED) || statusIs(D_ReINVITED))) {
+ printLog(
+ "respond(): InviteDialog not in (re)invited state: No response now",
+ LogLevel.HIGH);
+ return;
+ }
+
+ int code = resp.getStatusLine().getCode();
+ // 1xx provisional responses
+ if (code >= 100 && code < 200) {
+ invite_ts.respondWith(resp);
+ return;
+ }
+ // For all final responses establish the dialog
+ if (code >= 200) { // changeStatus(D_ACCEPTED);
+ update(Dialog.UAS, resp);
+ }
+ // 2xx success responses
+ if (code >= 200 && code < 300) {
+ if (statusIs(D_INVITED))
+ changeStatus(D_ACCEPTED);
+ else
+ changeStatus(D_ReACCEPTED);
+ // terminates the INVITE Transaction server and activates an ACK
+ // Transaction server
+ invite_ts.terminate();
+ ConnectionIdentifier conn_id = invite_ts.getConnectionId();
+ ack_ts = new AckTransactionServer(sip_provider, conn_id, resp,
+ this);
+ ack_ts.respond();
+ // if (statusIs(D_ReACCEPTED))
+ // listener.onDlgReInviteAccepted(this);
+ // else listener.onDlgAccepted(this);
+ return;
+ } else
+ // 300-699 failure responses
+ // if (code>=300)
+ {
+ if (statusIs(D_INVITED))
+ changeStatus(D_REFUSED);
+ else
+ changeStatus(D_ReREFUSED);
+ invite_ts.respondWith(resp);
+ // if (statusIs(D_ReREFUSED))
+ // listener.onDlgReInviteRefused(this);
+ // else listener.onDlgRefused(this);
+ return;
+ }
+ }
+ if (method.equals(SipMethods.BYE)) {
+ if (!verifyStatus(statusIs(D_BYED)))
+ return;
+ bye_ts.respondWith(resp);
+ }
+ }
+
+ /**
+ * Responds with code and reason. This method can be called
+ * when the InviteDialog is in D_INVITED, D_ReINVITED states
+ */
+ public void respond(int code, String reason, String contact, String sdp) {
+ printLog("inside respond(" + code + "," + reason + ")", LogLevel.MEDIUM);
+ if (statusIs(D_INVITED) || statusIs(D_ReINVITED)) {
+ NameAddress contact_address = null;
+ if (contact != null)
+ contact_address = new NameAddress(contact);
+ Message resp = MessageFactory.createResponse(invite_req, code,
+ reason, contact_address);
+ resp.setBody(sdp);
+ respond(resp);
+ } else
+ printWarning("Dialog isn't in \"invited\" state: cannot respond ("
+ + code + "/" + getStatus() + "/" + getDialogID() + ")",
+ LogLevel.MEDIUM);
+ }
+
+ /**
+ * Signals that the phone is ringing. This method should be called when the
+ * InviteDialog is in D_INVITED or D_ReINVITED state
+ */
+ public void ring(String sdp) { // modified
+ printLog("inside ring()", LogLevel.MEDIUM);
+ respond(180, SipResponses.reasonOf(180), null, sdp);
+ }
+
+ /**
+ * Accepts the incoming call. This method should be called when the
+ * InviteDialog is in D_INVITED or D_ReINVITED state
+ */
+ public void accept(String contact, String sdp) {
+ printLog("inside accept(sdp)", LogLevel.MEDIUM);
+ respond(200, SipResponses.reasonOf(200), contact, sdp);
+ }
+
+ /**
+ * Refuses the incoming call. This method should be called when the
+ * InviteDialog is in D_INVITED or D_ReINVITED state
+ */
+ public void refuse(int code, String reason) {
+ printLog("inside refuse(" + code + "," + reason + ")", LogLevel.MEDIUM);
+ respond(code, reason, null, null);
+ }
+
+ /**
+ * Refuses the incoming call. This method should be called when the
+ * InviteDialog is in D_INVITED or D_ReINVITED state
+ */
+ public void refuse() {
+ printLog("inside refuse()", LogLevel.MEDIUM);
+ // refuse(480,"Temporarily Unavailable");
+ // refuse(603,"Decline");
+ refuse(403, SipResponses.reasonOf(403));
+ }
+
+ public void busy() {
+ refuse(486, SipResponses.reasonOf(486)); // modified
+ }
+
+ /**
+ * Termiante the call. This method should be called when the InviteDialog is
+ * in D_CALL state
+ *
+ * Increments the Cseq, moves to state D_BYEING, and creates new BYE
+ * TransactionClient
+ */
+ public void bye() {
+ printLog("inside bye()", LogLevel.MEDIUM);
+ if (statusIs(D_CALL)) {
+ Message bye = MessageFactory.createByeRequest(this);
+ bye(bye);
+ }
+ }
+
+ /**
+ * Termiante the call. This method should be called when the InviteDialog is
+ * in D_CALL state
+ *
+ * Increments the Cseq, moves to state D_BYEING, and creates new BYE
+ * TransactionClient
+ */
+ public void bye(Message bye) {
+ printLog("inside bye(bye)", LogLevel.MEDIUM);
+ if (statusIs(D_CALL)) {
+ changeStatus(D_BYEING);
+ // dialog_state.incLocalCSeq(); // done by
+ // MessageFactory.createRequest()
+ TransactionClient tc = new TransactionClient(sip_provider, bye,
+ this);
+ tc.request();
+ // listener.onDlgByeing(this);
+ }
+ }
+
+ /**
+ * Cancel the ongoing call request or a call listening. This method should
+ * be called when the InviteDialog is in D_INVITING or D_ReINVITING state or
+ * in the D_WAITING state
+ */
+ public void cancel() {
+ printLog("inside cancel()", LogLevel.MEDIUM);
+ if (statusIs(D_INVITING) || statusIs(D_ReINVITING)) {
+ Message cancel = MessageFactory.createCancelRequest(invite_req,this); // modified
+ cancel(cancel);
+ } else if (statusIs(D_WAITING) || statusIs(D_ReWAITING)) {
+ invite_ts.terminate();
+ }
+ }
+
+ /**
+ * Cancel the ongoing call request or a call listening. This method should
+ * be called when the InviteDialog is in D_INVITING or D_ReINVITING state or
+ * in the D_WAITING state
+ */
+ public void cancel(Message cancel) {
+ printLog("inside cancel(cancel)", LogLevel.MEDIUM);
+ if (statusIs(D_INVITING) || statusIs(D_ReINVITING)) { // changeStatus(D_CANCELING);
+ TransactionClient tc = new TransactionClient(sip_provider, cancel,
+ null);
+ tc.request();
+ } else if (statusIs(D_WAITING) || statusIs(D_ReWAITING)) {
+ invite_ts.terminate();
+ }
+ }
+
+ /**
+ * Redirects the incoming call , specifing the code and reason.
+ * This method can be called when the InviteDialog is in D_INVITED or
+ * D_ReINVITED state
+ */
+ public void redirect(int code, String reason, String contact) {
+ printLog(
+ "inside redirect(" + code + "," + reason + "," + contact + ")",
+ LogLevel.MEDIUM);
+ respond(code, reason, contact, null);
+ }
+
+ // ************** Inherited from SipProviderListener **************
+
+ /**
+ * Inherited from class SipProviderListener. Called when a new message is
+ * received (out of any ongoing transaction) for the current InviteDialog.
+ * Always checks for out-of-date methods (CSeq header sequence number).
+ *
+ * If the message is ACK(2xx/INVITE) request, it moves to D_CALL state, and
+ * fires onDlgAck(this,body,msg).
+ *
+ * If the message is 2xx(INVITE) response, it create a new
+ * AckTransactionClient
+ *
+ * If the message is BYE, it moves to D_BYED state, removes the listener
+ * from SipProvider, fires onDlgBye(this,msg) then it responds with 200 OK,
+ * moves to D_CLOSE state and fires onDlgClose(this)
+ */
+ public void onReceivedMessage(SipProvider sip_provider, Message msg) {
+ printLog("inside onReceivedMessage(sip_provider,message)",
+ LogLevel.MEDIUM);
+ if (msg.isRequest() && !(msg.isAck() || msg.isCancel())
+ && msg.getCSeqHeader().getSequenceNumber() <= getRemoteCSeq()) {
+ printLog(
+ "Request message is too late (CSeq too small): Message discarded",
+ LogLevel.HIGH);
+ return;
+ }
+ // invite received
+ if (msg.isRequest() && msg.isInvite()) {
+ verifyStatus(statusIs(D_INIT) || statusIs(D_CALL));
+ // NOTE: if the invite_ts.listen() is used, you should not arrive
+ // here with the D_INIT state..
+ // however state D_INIT has been included for robustness against
+ // further changes.
+ if (statusIs(D_INIT))
+ changeStatus(D_INVITED);
+ else
+ changeStatus(D_ReINVITED);
+ invite_req = msg;
+ invite_ts = new InviteTransactionServer(sip_provider, invite_req,
+ this);
+ // ((TransactionServer)transaction).listen();
+ update(Dialog.UAS, invite_req);
+ if (statusIs(D_INVITED))
+ listener.onDlgInvite(this, invite_req.getToHeader()
+ .getNameAddress(), invite_req.getFromHeader()
+ .getNameAddress(), invite_req.getBody(), invite_req);
+ else
+ listener.onDlgReInvite(this, invite_req.getBody(), invite_req);
+ } else
+ // ack (of 2xx of INVITE)
+ if (msg.isRequest() && msg.isAck()) {
+ if (!verifyStatus(statusIs(D_ACCEPTED) || statusIs(D_ReACCEPTED)))
+ return;
+ changeStatus(D_CALL);
+ // terminates the AckTransactionServer
+ ack_ts.terminate();
+ listener.onDlgAck(this, msg.getBody(), msg);
+ listener.onDlgCall(this);
+ } else
+ // keep sending ACK (if already sent) for any "200 OK" received
+ if (msg.isResponse()) {
+ if (!verifyStatus(statusIs(D_CALL)))
+ return;
+ int code = msg.getStatusLine().getCode();
+ verifyThat(code >= 200 && code < 300, "code 2xx was expected");
+ if (ack_req != null) {
+ AckTransactionClient ack_tc = new AckTransactionClient(
+ sip_provider, ack_req, null);
+ ack_tc.request();
+ }
+ } else
+ // bye received
+ if (msg.isRequest() && msg.isBye()) {
+ if (!verifyStatus(statusIs(D_CALL) || statusIs(D_BYEING)))
+ return;
+ changeStatus(D_BYED);
+ bye_ts = new TransactionServer(sip_provider, msg, this);
+ // automatically sends a 200 OK
+ Message resp = MessageFactory.createResponse(msg, 200, SipResponses
+ .reasonOf(200), null);
+ respond(resp);
+ listener.onDlgBye(this, msg);
+ changeStatus(D_CLOSE);
+ listener.onDlgClose(this);
+ } else
+ // cancel received
+ if (msg.isRequest() && msg.isCancel()) {
+ if (!verifyStatus(statusIs(D_INVITED) || statusIs(D_ReINVITED)))
+ return;
+ // create a CANCEL TransactionServer and send a 200 OK (CANCEL)
+ TransactionServer ts = new TransactionServer(sip_provider, msg,
+ null);
+ // ts.listen();
+ ts.respondWith(MessageFactory.createResponse(msg, 200, SipResponses
+ .reasonOf(200), null));
+ // automatically sends a 487 Cancelled
+ Message resp = MessageFactory.createResponse(invite_req, 487,
+ SipResponses.reasonOf(487), null);
+ respond(resp);
+ listener.onDlgCancel(this, msg);
+ } else
+ // any other request received
+ if (msg.isRequest()) {
+ TransactionServer ts = new TransactionServer(sip_provider, msg,
+ null);
+ // ts.listen();
+ ts.respondWith(MessageFactory.createResponse(msg, 405, SipResponses
+ .reasonOf(405), null));
+ }
+ }
+
+ // ************** Inherited from InviteTransactionClientListener
+ // **************
+
+ /**
+ * Inherited from TransactionClientListener. When the
+ * TransactionClientListener is in "Proceeding" state and receives a new 1xx
+ * response
+ *
+ * For INVITE transaction it fires
+ * onFailureResponse(this,code,reason,body,msg).
+ */
+ public void onTransProvisionalResponse(TransactionClient tc, Message msg) {
+ printLog("inside onTransProvisionalResponse(tc,mdg)", LogLevel.LOW);
+ if (tc.getTransactionMethod().equals(SipMethods.INVITE)) {
+ StatusLine statusline = msg.getStatusLine();
+ listener.onDlgInviteProvisionalResponse(this, statusline.getCode(),
+ statusline.getReason(), msg.getBody(), msg);
+ }
+ }
+
+ /**
+ * Inherited from TransactionClientListener. When the
+ * TransactionClientListener goes into the "Completed" state, receiving a
+ * failure response
+ *
+ * If called for a INVITE transaction, it moves to D_CLOSE state, removes
+ * the listener from SipProvider.
+ *
+ * If called for a BYE transaction, it moves to D_CLOSE state, removes the
+ * listener from SipProvider, and fires onClose(this,msg).
+ */
+ public void onTransFailureResponse(TransactionClient tc, Message msg) {
+ printLog("inside onTransFailureResponse(" + tc.getTransactionId()
+ + ",msg)", LogLevel.LOW);
+ if (tc.getTransactionMethod().equals(SipMethods.INVITE)) {
+ if (!verifyStatus(statusIs(D_INVITING) || statusIs(D_ReINVITING)))
+ return;
+ StatusLine statusline = msg.getStatusLine();
+ int code = statusline.getCode();
+ verifyThat(code >= 300 && code < 700, "error code was expected");
+ if (statusIs(D_ReINVITING)) {
+ changeStatus(D_CALL);
+ listener.onDlgReInviteFailureResponse(this, code, statusline
+ .getReason(), msg);
+ } else {
+ changeStatus(D_CLOSE);
+ if (code >= 300 && code < 400)
+ listener.onDlgInviteRedirectResponse(this, code, statusline
+ .getReason(), msg.getContacts(), msg);
+ else
+ listener.onDlgInviteFailureResponse(this, code, statusline
+ .getReason(), msg);
+ listener.onDlgClose(this);
+ }
+ } else if (tc.getTransactionMethod().equals(SipMethods.BYE)) {
+ if (!verifyStatus(statusIs(D_BYEING)))
+ return;
+ StatusLine statusline = msg.getStatusLine();
+ int code = statusline.getCode();
+ verifyThat(code >= 300 && code < 700, "error code was expected");
+ changeStatus(InviteDialog.D_CALL);
+ listener.onDlgByeFailureResponse(this, code,
+ statusline.getReason(), msg);
+ }
+ }
+
+ /**
+ * Inherited from TransactionClientListener. When an
+ * TransactionClientListener goes into the "Terminated" state, receiving a
+ * 2xx response
+ *
+ * If called for a INVITE transaction, it updates the dialog information,
+ * moves to D_CALL state, add a listener to the SipProvider, creates a new
+ * AckTransactionClient(ack,this), and fires
+ * onSuccessResponse(this,code,body,msg).
+ *
+ * If called for a BYE transaction, it moves to D_CLOSE state, removes the
+ * listener from SipProvider, and fires onClose(this,msg).
+ */
+ public void onTransSuccessResponse(TransactionClient tc, Message msg) {
+ printLog("inside onTransSuccessResponse(tc,msg)", LogLevel.LOW);
+ if (tc.getTransactionMethod().equals(SipMethods.INVITE)) {
+ if (!verifyStatus(statusIs(D_INVITING) || statusIs(D_ReINVITING)))
+ return;
+ StatusLine statusline = msg.getStatusLine();
+ int code = statusline.getCode();
+ if (!verifyThat(code >= 200 && code < 300
+ && msg.getTransactionMethod().equals(SipMethods.INVITE),
+ "2xx for invite was expected"))
+ return;
+ boolean re_inviting = statusIs(D_ReINVITING);
+ changeStatus(D_CALL);
+ update(Dialog.UAC, msg);
+ if (invite_offer) { // invite_req=MessageFactory.createRequest(SipMethods.ACK,dialog_state,sdp.toString());
+ // ack=MessageFactory.createRequest(this,SipMethods.ACK,null);
+ ack_req = MessageFactory.create2xxAckRequest(this, null);
+ AckTransactionClient ack_tc = new AckTransactionClient(
+ sip_provider, ack_req, null);
+ ack_tc.request();
+ }
+ if (!re_inviting) {
+ listener.onDlgInviteSuccessResponse(this, code, statusline
+ .getReason(), msg.getBody(), msg);
+ listener.onDlgCall(this);
+ } else
+ listener.onDlgReInviteSuccessResponse(this, code, statusline
+ .getReason(), msg.getBody(), msg);
+ } else if (tc.getTransactionMethod().equals(SipMethods.BYE)) {
+ if (!verifyStatus(statusIs(D_BYEING)))
+ return;
+ StatusLine statusline = msg.getStatusLine();
+ int code = statusline.getCode();
+ verifyThat(code >= 200 && code < 300, "2xx for bye was expected");
+ changeStatus(D_CLOSE);
+ listener.onDlgByeSuccessResponse(this, code,
+ statusline.getReason(), msg);
+ listener.onDlgClose(this);
+ }
+ }
+
+ /**
+ * Inherited from TransactionClientListener. When the TransactionClient goes
+ * into the "Terminated" state, caused by transaction timeout
+ */
+ public void onTransTimeout(TransactionClient tc) {
+ printLog("inside onTransTimeout(tc,msg)", LogLevel.LOW);
+ if (tc.getTransactionMethod().equals(SipMethods.INVITE)) {
+ if (!verifyStatus(statusIs(D_INVITING) || statusIs(D_ReINVITING)))
+ return;
+ cancel(); //modified
+ changeStatus(D_CLOSE);
+ listener.onDlgTimeout(this);
+ listener.onDlgClose(this);
+ } else if (tc.getTransactionMethod().equals(SipMethods.BYE)) {
+ if (!verifyStatus(statusIs(D_BYEING)))
+ return;
+ changeStatus(D_CLOSE);
+ listener.onDlgClose(this);
+ }
+ }
+
+ // ************** Inherited from InviteTransactionServerListener
+ // **************
+
+ /**
+ * Inherited from TransactionServerListener. When the TransactionServer goes
+ * into the "Trying" state receiving a request
+ *
+ * If called for a INVITE transaction, it initializes the dialog
+ * information,
+ * moves to D_INVITED state, and add a listener to the SipProvider,
+ * and fires onInvite(caller,body,msg).
+ */
+ public void onTransRequest(TransactionServer ts, Message req) {
+ printLog("inside onTransRequest(ts,msg)", LogLevel.LOW);
+ if (ts.getTransactionMethod().equals(SipMethods.INVITE)) {
+ if (!verifyStatus(statusIs(D_WAITING)))
+ return;
+ changeStatus(D_INVITED);
+ invite_req = req;
+ update(Dialog.UAS, invite_req);
+ listener.onDlgInvite(this, invite_req.getToHeader()
+ .getNameAddress(), invite_req.getFromHeader()
+ .getNameAddress(), invite_req.getBody(), invite_req);
+ }
+ }
+
+ /**
+ * Inherited from InviteTransactionServerListener. When an
+ * InviteTransactionServer goes into the "Confirmed" state receining an ACK
+ * for NON-2xx response
+ *
+ * It moves to D_CLOSE state and removes the listener from SipProvider.
+ */
+ public void onTransFailureAck(InviteTransactionServer ts, Message msg) {
+ printLog("inside onTransFailureAck(ts,msg)", LogLevel.LOW);
+ if (!verifyStatus(statusIs(D_REFUSED) || statusIs(D_ReREFUSED)))
+ return;
+ if (statusIs(D_ReREFUSED)) {
+ changeStatus(D_CALL);
+ } else {
+ changeStatus(D_CLOSE);
+ listener.onDlgClose(this);
+ }
+ }
+
+ // ************ Inherited from AckTransactionServerListener ************
+
+ /**
+ * When the AckTransactionServer goes into the "Terminated" state, caused by
+ * transaction timeout
+ */
+ public void onTransAckTimeout(AckTransactionServer ts) {
+ printLog("inside onAckSrvTimeout(ts)", LogLevel.LOW);
+ if (!verifyStatus(statusIs(D_ACCEPTED) || statusIs(D_ReACCEPTED)
+ || statusIs(D_REFUSED) || statusIs(D_ReREFUSED)))
+ return;
+ printLog("No ACK received..", LogLevel.HIGH);
+ changeStatus(D_CLOSE);
+ listener.onDlgClose(this);
+ }
+
+ // **************************** Logs ****************************/
+
+ /** Adds a new string to the default Log */
+ protected void printLog(String str, int level) {
+ if (log != null)
+ log.println("InviteDialog#" + dialog_sqn + ": " + str, level
+ + SipStack.LOG_LEVEL_DIALOG);
+ }
+
+}
diff --git a/src/org/zoolu/sip/dialog/InviteDialogListener.java b/app/src/main/java/org/zoolu/sip/dialog/InviteDialogListener.java
similarity index 97%
rename from src/org/zoolu/sip/dialog/InviteDialogListener.java
rename to app/src/main/java/org/zoolu/sip/dialog/InviteDialogListener.java
index 467e796..7c2ff10 100644
--- a/src/org/zoolu/sip/dialog/InviteDialogListener.java
+++ b/app/src/main/java/org/zoolu/sip/dialog/InviteDialogListener.java
@@ -1,117 +1,117 @@
-/*
- * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
- *
- * This file is part of MjSip (http://www.mjsip.org)
- *
- * MjSip is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * MjSip is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with MjSip; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author(s):
- * Luca Veltri (luca.veltri@unipr.it)
- */
-
-package org.zoolu.sip.dialog;
-
-import org.zoolu.sip.address.NameAddress;
-import org.zoolu.sip.message.Message;
-import org.zoolu.sip.header.MultipleHeader;
-
-/**
- * An InviteDialogListener listens for InviteDialog events. It collects all
- * InviteDialog callback functions.
- */
-public interface InviteDialogListener {
- /** When an incoming INVITE is received */
- public void onDlgInvite(InviteDialog dialog, NameAddress callee,
- NameAddress caller, String body, Message msg);
-
- /** When an incoming Re-INVITE is received */
- public void onDlgReInvite(InviteDialog dialog, String body, Message msg);
-
- /** When a 1xx response response is received for an INVITE transaction */
- public void onDlgInviteProvisionalResponse(InviteDialog dialog, int code,
- String reason, String body, Message msg);
-
- /**
- * When a 2xx successfull final response is received for an INVITE
- * transaction
- */
- public void onDlgInviteSuccessResponse(InviteDialog dialog, int code,
- String reason, String body, Message msg);
-
- /** When a 3xx redirection response is received for an INVITE transaction */
- public void onDlgInviteRedirectResponse(InviteDialog dialog, int code,
- String reason, MultipleHeader contacts, Message msg);
-
- /** When a 400-699 failure response is received for an INVITE transaction */
- public void onDlgInviteFailureResponse(InviteDialog dialog, int code,
- String reason, Message msg);
-
- /** When INVITE transaction expires */
- public void onDlgTimeout(InviteDialog dialog);
-
- /** When a 1xx response response is received for a Re-INVITE transaction */
- public void onDlgReInviteProvisionalResponse(InviteDialog dialog, int code,
- String reason, String body, Message msg);
-
- /**
- * When a 2xx successfull final response is received for a Re-INVITE
- * transaction
- */
- public void onDlgReInviteSuccessResponse(InviteDialog dialog, int code,
- String reason, String body, Message msg);
-
- /** When a 3xx redirection response is received for a Re-INVITE transaction */
- // public void onDlgReInviteRedirectResponse(InviteDialog dialog, int code,
- // String reason, MultipleHeader contacts, Message msg);
- /** When a 400-699 failure response is received for a Re-INVITE transaction */
- public void onDlgReInviteFailureResponse(InviteDialog dialog, int code,
- String reason, Message msg);
-
- /** When a Re-INVITE transaction expires */
- public void onDlgReInviteTimeout(InviteDialog dialog);
-
- /** When an incoming INVITE is accepted */
- // public void onDlgAccepted(InviteDialog dialog);
- /** When an incoming INVITE is refused */
- // public void onDlgRefused(InviteDialog dialog);
- /** When an incoming Re-INVITE is accepted */
- // public void onDlgReInviteAccepted(InviteDialog dialog);
- /** When an incoming Re-INVITE is refused */
- // public void onDlgReInviteRefused(InviteDialog dialog);
- /** When an incoming ACK is received for an INVITE transaction */
- public void onDlgAck(InviteDialog dialog, String body, Message msg);
-
- /** When the INVITE handshake is successful terminated */
- public void onDlgCall(InviteDialog dialog);
-
- /** When an incoming CANCEL is received for an INVITE transaction */
- public void onDlgCancel(InviteDialog dialog, Message msg);
-
- /** When an incoming BYE is received */
- public void onDlgBye(InviteDialog dialog, Message msg);
-
- /** When a BYE request traqnsaction has been started */
- // public void onDlgByeing(InviteDialog dialog);
- /** When a success response is received for a Bye request */
- public void onDlgByeSuccessResponse(InviteDialog dialog, int code,
- String reason, Message msg);
-
- /** When a failure response is received for a Bye request */
- public void onDlgByeFailureResponse(InviteDialog dialog, int code,
- String reason, Message msg);
-
- /** When the dialog is finally closed */
- public void onDlgClose(InviteDialog dialog);
-}
+/*
+ * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
+ *
+ * This file is part of MjSip (http://www.mjsip.org)
+ *
+ * MjSip is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * MjSip is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MjSip; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author(s):
+ * Luca Veltri (luca.veltri@unipr.it)
+ */
+
+package org.zoolu.sip.dialog;
+
+import org.zoolu.sip.address.NameAddress;
+import org.zoolu.sip.message.Message;
+import org.zoolu.sip.header.MultipleHeader;
+
+/**
+ * An InviteDialogListener listens for InviteDialog events. It collects all
+ * InviteDialog callback functions.
+ */
+public interface InviteDialogListener {
+ /** When an incoming INVITE is received */
+ public void onDlgInvite(InviteDialog dialog, NameAddress callee,
+ NameAddress caller, String body, Message msg);
+
+ /** When an incoming Re-INVITE is received */
+ public void onDlgReInvite(InviteDialog dialog, String body, Message msg);
+
+ /** When a 1xx response response is received for an INVITE transaction */
+ public void onDlgInviteProvisionalResponse(InviteDialog dialog, int code,
+ String reason, String body, Message msg);
+
+ /**
+ * When a 2xx successfull final response is received for an INVITE
+ * transaction
+ */
+ public void onDlgInviteSuccessResponse(InviteDialog dialog, int code,
+ String reason, String body, Message msg);
+
+ /** When a 3xx redirection response is received for an INVITE transaction */
+ public void onDlgInviteRedirectResponse(InviteDialog dialog, int code,
+ String reason, MultipleHeader contacts, Message msg);
+
+ /** When a 400-699 failure response is received for an INVITE transaction */
+ public void onDlgInviteFailureResponse(InviteDialog dialog, int code,
+ String reason, Message msg);
+
+ /** When INVITE transaction expires */
+ public void onDlgTimeout(InviteDialog dialog);
+
+ /** When a 1xx response response is received for a Re-INVITE transaction */
+ public void onDlgReInviteProvisionalResponse(InviteDialog dialog, int code,
+ String reason, String body, Message msg);
+
+ /**
+ * When a 2xx successfull final response is received for a Re-INVITE
+ * transaction
+ */
+ public void onDlgReInviteSuccessResponse(InviteDialog dialog, int code,
+ String reason, String body, Message msg);
+
+ /** When a 3xx redirection response is received for a Re-INVITE transaction */
+ // public void onDlgReInviteRedirectResponse(InviteDialog dialog, int code,
+ // String reason, MultipleHeader contacts, Message msg);
+ /** When a 400-699 failure response is received for a Re-INVITE transaction */
+ public void onDlgReInviteFailureResponse(InviteDialog dialog, int code,
+ String reason, Message msg);
+
+ /** When a Re-INVITE transaction expires */
+ public void onDlgReInviteTimeout(InviteDialog dialog);
+
+ /** When an incoming INVITE is accepted */
+ // public void onDlgAccepted(InviteDialog dialog);
+ /** When an incoming INVITE is refused */
+ // public void onDlgRefused(InviteDialog dialog);
+ /** When an incoming Re-INVITE is accepted */
+ // public void onDlgReInviteAccepted(InviteDialog dialog);
+ /** When an incoming Re-INVITE is refused */
+ // public void onDlgReInviteRefused(InviteDialog dialog);
+ /** When an incoming ACK is received for an INVITE transaction */
+ public void onDlgAck(InviteDialog dialog, String body, Message msg);
+
+ /** When the INVITE handshake is successful terminated */
+ public void onDlgCall(InviteDialog dialog);
+
+ /** When an incoming CANCEL is received for an INVITE transaction */
+ public void onDlgCancel(InviteDialog dialog, Message msg);
+
+ /** When an incoming BYE is received */
+ public void onDlgBye(InviteDialog dialog, Message msg);
+
+ /** When a BYE request traqnsaction has been started */
+ // public void onDlgByeing(InviteDialog dialog);
+ /** When a success response is received for a Bye request */
+ public void onDlgByeSuccessResponse(InviteDialog dialog, int code,
+ String reason, Message msg);
+
+ /** When a failure response is received for a Bye request */
+ public void onDlgByeFailureResponse(InviteDialog dialog, int code,
+ String reason, Message msg);
+
+ /** When the dialog is finally closed */
+ public void onDlgClose(InviteDialog dialog);
+}
diff --git a/src/org/zoolu/sip/dialog/NotifierDialog.java b/app/src/main/java/org/zoolu/sip/dialog/NotifierDialog.java
similarity index 96%
rename from src/org/zoolu/sip/dialog/NotifierDialog.java
rename to app/src/main/java/org/zoolu/sip/dialog/NotifierDialog.java
index 139f9ef..4e9341d 100644
--- a/src/org/zoolu/sip/dialog/NotifierDialog.java
+++ b/app/src/main/java/org/zoolu/sip/dialog/NotifierDialog.java
@@ -1,415 +1,415 @@
-/*
- * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
- *
- * This file is part of MjSip (http://www.mjsip.org)
- *
- * MjSip is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * MjSip is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with MjSip; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author(s):
- * Luca Veltri (luca.veltri@unipr.it)
- * Nitin Khanna, Hughes Systique Corp. (Reason: Android specific change, optmization, bug fix)
- */
-
-/* Modified by:
- * Daina Interrante (daina.interrante@studenti.unipr.it)
- */
-
-package org.zoolu.sip.dialog;
-
-import org.zoolu.sip.address.*;
-import org.zoolu.sip.transaction.*;
-import org.zoolu.sip.message.*;
-import org.zoolu.sip.header.*;
-import org.zoolu.sip.provider.*;
-import org.zoolu.tools.LogLevel;
-
-/**
- * NotifierDialog.
- */
-public class NotifierDialog extends Dialog implements TransactionClientListener/*
- * ,
- * TransactionServerListener
- */
-{
- /** String "active" */
- protected static final String ACTIVE = "active";
- /** String "pending" */
- protected static final String PENDING = "pending";
- /** String "terminated" */
- protected static final String TERMINATED = "terminated";
-
- /** The SubscriberDialog listener */
- NotifierDialogListener listener;
-
- /** The current subscribe method */
- Message subscribe_req;
-
- /** The current subscribe transaction */
- TransactionServer subscribe_transaction;
-
- /** The current notify transaction */
- TransactionClient notify_transaction;
-
- /** The event name */
- String event;
-
- /** The subscription id */
- String id;
-
- /** Internal state D_INIT (the starting point) */
- protected static final int D_INIT = 0;
- /** Internal state D_WAITING (listening for the first subscription request) */
- protected static final int D_WAITING = 1;
- /** Internal state D_SUBSCRIBED (first subscription request arrived) */
- protected static final int D_SUBSCRIBED = 2;
- /** Internal state D_PENDING (first subscription request has been accepted) */
- protected static final int D_PENDING = 3;
- /** Internal state D_ACTIVE (subscription has been activated) */
- protected static final int D_ACTIVE = 4;
- /**
- * Internal state D_TERMINATED (first subscription request has been refused
- * or subscription has been terminated)
- */
- protected static final int D_TERMINATED = 9;
-
- // ************************* Protected methods ************************
-
- /** Gets the dialog state */
- protected String getStatusDescription() {
- switch (status) {
- case D_INIT:
- return "D_INIT";
- case D_WAITING:
- return "D_WAITING";
- case D_SUBSCRIBED:
- return "D_SUBSCRIBED";
- case D_PENDING:
- return "D_PENDING";
- case D_ACTIVE:
- return "D_ACTIVE";
- case D_TERMINATED:
- return "D_TERMINATED";
- default:
- return null;
- }
- }
-
- protected int getStatus() {
- return status;
- }
-
- // ************************** Public methods **************************
-
- /** Whether the dialog is in "early" state. */
- public boolean isEarly() {
- return (status < D_PENDING);
- }
-
- /** Whether the dialog is in "confirmed" state. */
- public boolean isConfirmed() {
- return (status >= D_PENDING && status < D_TERMINATED);
- }
-
- /** Whether the dialog is in "active" state. */
- public boolean isTerminated() {
- return (status == D_TERMINATED);
- }
-
- /** Whether the subscription is "pending". */
- public boolean isSubscriptionPending() {
- return (status >= D_SUBSCRIBED && status < D_ACTIVE);
- }
-
- /** Whether the subscription is "active". */
- public boolean isSubscriptionActive() {
- return (status == D_ACTIVE);
- }
-
- /** Whether the subscription is "terminated". */
- public boolean isSubscriptionTerminated() {
- return (status == D_TERMINATED);
- }
-
- /** Gets event type. */
- public String getEvent() {
- return event;
- }
-
- /** Gets the event "id" parameter. */
- public String getId() {
- return id;
- }
-
- // **************************** Costructors ****************************
-
- /** Creates a new NotifierDialog. */
- public NotifierDialog(SipProvider sip_provider,
- NotifierDialogListener listener) {
- super(sip_provider);
- init(listener);
- }
-
- /**
- * Creates a new NotifierDialog for the already received SUBSCRIBE request
- * subscribe.
- */
- public NotifierDialog(SipProvider sip_provider, Message subscribe,
- NotifierDialogListener listener) {
- super(sip_provider);
- init(listener);
-
- changeStatus(D_SUBSCRIBED);
- subscribe_req = subscribe;
- subscribe_transaction = new TransactionServer(sip_provider, subscribe,
- null);
- update(Dialog.UAS, subscribe);
- EventHeader eh = subscribe.getEventHeader();
- if (eh != null) {
- event = eh.getEvent();
- id = eh.getId();
- }
- }
-
- /** Inits the NotifierDialog. */
- private void init(NotifierDialogListener listener) {
- this.listener = listener;
- this.subscribe_transaction = null;
- this.notify_transaction = null;
- this.subscribe_req = null;
- this.event = null;
- this.id = null;
- changeStatus(D_INIT);
- }
-
- // *************************** Public methods **************************
-
- /** Listen for the first subscription request. */
- public void listen() {
- printLog("inside method listen()", LogLevel.MEDIUM);
- if (!statusIs(D_INIT)) {
- printLog("first subscription already received", LogLevel.MEDIUM);
- return;
- }
- // else
- changeStatus(D_WAITING);
- // listen for the first SUBSCRIBE request
- sip_provider.addSipProviderListener(new MethodIdentifier(
- SipMethods.SUBSCRIBE), this);
- }
-
- /** Accepts the subscription request (sends a "202 Accepted" response). */
- public void accept(int expires, String contact) {
- printLog("inside accept()", LogLevel.MEDIUM);
- respond(202, SipResponses.reasonOf(202), expires, contact, null, null);
- }
-
- /** Refuses the subscription request. */
- public void refuse() {
- printLog("inside refuse()", LogLevel.MEDIUM);
- respond(403, SipResponses.reasonOf(403), -1, null, null, null);
- }
-
- /**
- * Responds with code and reason. This method can be called
- * when the InviteDialog is in D_INVITED, D_ReINVITED states
- */
- public void respond(int code, String reason, int expires, String contact,
- String content_type, String body) {
- printLog("inside respond(" + code + "," + reason + ")", LogLevel.MEDIUM);
- NameAddress contact_url = null;
- if (contact != null)
- contact_url = new NameAddress(contact);
- Message resp = MessageFactory.createResponse(subscribe_req, code,
- SipResponses.reasonOf(code), contact_url);
- if (expires >= 0)
- resp.setExpiresHeader(new ExpiresHeader(expires));
- if (body != null)
- resp.setBody(content_type, body);
- respond(resp);
- }
-
- /** Responds with resp. */
- public void respond(Message resp) {
- printLog("inside respond(resp)", LogLevel.MEDIUM);
- if (resp.getStatusLine().getCode() >= 200)
- update(UAS, resp);
- subscribe_transaction.respondWith(resp);
- }
-
- /** Activates the subscription (subscription goes into 'active' state). */
- public void activate() {
- activate(SipStack.default_expires);
- }
-
- /** Activates the subscription (subscription goes into 'active' state). */
- public void activate(int expires) {
- notify(ACTIVE, expires, null, null);
- }
-
- /** Makes the subscription pending (subscription goes into 'pending' state). */
- public void pending() {
- pending(SipStack.default_expires);
- }
-
- /** Makes the subscription pending (subscription goes into 'pending' state). */
- public void pending(int expires) {
- notify(PENDING, expires, null, null);
- }
-
- /** Terminates the subscription (subscription goes into 'terminated' state). */
- public void terminate() {
- terminate(null);
- }
-
- /** Terminates the subscription (subscription goes into 'terminated' state). */
- public void terminate(String reason) {
- Message req = MessageFactory.createNotifyRequest(this, event, id, null,
- null);
- SubscriptionStateHeader sh = new SubscriptionStateHeader(TERMINATED);
- if (reason != null)
- sh.setReason(reason);
- // sh.setExpires(0);
- req.setSubscriptionStateHeader(sh);
- notify(req);
- }
-
- /** Sends a NOTIFY. */
- public void notify(String state, int expires, String content_type,
- String body) {
- Message req = MessageFactory.createNotifyRequest(this, event, id,
- content_type, body);
- if (state != null) {
- SubscriptionStateHeader sh = new SubscriptionStateHeader(state);
- if (expires >= 0)
- sh.setExpires(expires);
- req.setSubscriptionStateHeader(sh);
- }
- notify(req);
- }
-
- /** Sends a NOTIFY. */
- public void notify(Message req) {
- String subscription_state = req.getSubscriptionStateHeader().getState();
- if (subscription_state.equalsIgnoreCase(ACTIVE)
- && (statusIs(D_SUBSCRIBED) || statusIs(D_PENDING)))
- changeStatus(D_ACTIVE);
- else if (subscription_state.equalsIgnoreCase(PENDING)
- && statusIs(D_SUBSCRIBED))
- changeStatus(D_PENDING);
- else if (subscription_state.equalsIgnoreCase(TERMINATED)
- && !statusIs(D_TERMINATED))
- changeStatus(D_TERMINATED);
-
- TransactionClient notify_transaction = new TransactionClient(
- sip_provider, req, this);
- notify_transaction.request();
- }
-
- // ************** Inherited from TransactionClientListener **************
-
- /**
- * When the TransactionClient is (or goes) in "Proceeding" state and
- * receives a new 1xx provisional response
- */
- public void onTransProvisionalResponse(TransactionClient tc, Message resp) {
- printLog("onTransProvisionalResponse()", LogLevel.MEDIUM);
- // do nothing.
- }
-
- /**
- * When the TransactionClient goes into the "Completed" state receiving a
- * 2xx response
- */
- public void onTransSuccessResponse(TransactionClient tc, Message resp) {
- printLog("onTransSuccessResponse()", LogLevel.MEDIUM);
- StatusLine status_line = resp.getStatusLine();
- if (listener != null)
- listener.onDlgNotificationSuccess(this, status_line.getCode(),
- status_line.getReason(), resp);
- }
-
- /**
- * When the TransactionClient goes into the "Completed" state receiving a
- * 300-699 response
- */
- public void onTransFailureResponse(TransactionClient tc, Message resp) {
- printLog("onTransFailureResponse()", LogLevel.MEDIUM);
- StatusLine status_line = resp.getStatusLine();
- if (listener != null)
- listener.onDlgNotificationFailure(this, status_line.getCode(),
- status_line.getReason(), resp);
- }
-
- /**
- * When the TransactionClient goes into the "Terminated" state, caused by
- * transaction timeout
- */
- public void onTransTimeout(TransactionClient tc) {
- printLog("onTransTimeout()", LogLevel.MEDIUM);
- if (!statusIs(D_TERMINATED)) {
- changeStatus(D_TERMINATED);
- if (listener != null)
- listener.onDlgNotifyTimeout(this);
- }
- }
-
- // ************** Inherited from SipProviderListener **************
-
- /** When a new Message is received by the SipProvider. */
- public void onReceivedMessage(SipProvider provider, Message msg) {
- printLog("onReceivedMessage()", LogLevel.MEDIUM);
- if (statusIs(D_TERMINATED)) {
- printLog("subscription already terminated: message discarded",
- LogLevel.MEDIUM);
- return;
- }
- // else
- if (msg.isRequest() && msg.isSubscribe()) {
- if (statusIs(NotifierDialog.D_WAITING)) { // the first SUBSCRIBE
- // request
- changeStatus(D_SUBSCRIBED);
- sip_provider.removeSipProviderListener(new MethodIdentifier(
- SipMethods.SUBSCRIBE));
- }
- subscribe_req = msg;
- NameAddress target = msg.getToHeader().getNameAddress();
- NameAddress subscriber = msg.getFromHeader().getNameAddress();
- EventHeader eh = msg.getEventHeader();
- if (eh != null) {
- event = eh.getEvent();
- id = eh.getId();
- }
- update(UAS, msg);
- subscribe_transaction = new TransactionServer(sip_provider, msg,
- null);
- if (listener != null)
- listener.onDlgSubscribe(this, target, subscriber, event, id,
- msg);
- } else {
- printLog("message is not a SUBSCRIBE: message discarded",
- LogLevel.HIGH);
- }
- }
-
- // **************************** Logs ****************************/
-
- /** Adds a new string to the default Log */
- protected void printLog(String str, int level) {
- if (log != null)
- log.println("NotifierDialog#" + dialog_sqn + ": " + str, level
- + SipStack.LOG_LEVEL_DIALOG);
- }
-
-}
+/*
+ * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
+ *
+ * This file is part of MjSip (http://www.mjsip.org)
+ *
+ * MjSip is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * MjSip is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MjSip; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author(s):
+ * Luca Veltri (luca.veltri@unipr.it)
+ * Nitin Khanna, Hughes Systique Corp. (Reason: Android specific change, optmization, bug fix)
+ */
+
+/* Modified by:
+ * Daina Interrante (daina.interrante@studenti.unipr.it)
+ */
+
+package org.zoolu.sip.dialog;
+
+import org.zoolu.sip.address.*;
+import org.zoolu.sip.transaction.*;
+import org.zoolu.sip.message.*;
+import org.zoolu.sip.header.*;
+import org.zoolu.sip.provider.*;
+import org.zoolu.tools.LogLevel;
+
+/**
+ * NotifierDialog.
+ */
+public class NotifierDialog extends Dialog implements TransactionClientListener/*
+ * ,
+ * TransactionServerListener
+ */
+{
+ /** String "active" */
+ protected static final String ACTIVE = "active";
+ /** String "pending" */
+ protected static final String PENDING = "pending";
+ /** String "terminated" */
+ protected static final String TERMINATED = "terminated";
+
+ /** The SubscriberDialog listener */
+ NotifierDialogListener listener;
+
+ /** The current subscribe method */
+ Message subscribe_req;
+
+ /** The current subscribe transaction */
+ TransactionServer subscribe_transaction;
+
+ /** The current notify transaction */
+ TransactionClient notify_transaction;
+
+ /** The event name */
+ String event;
+
+ /** The subscription id */
+ String id;
+
+ /** Internal state D_INIT (the starting point) */
+ protected static final int D_INIT = 0;
+ /** Internal state D_WAITING (listening for the first subscription request) */
+ protected static final int D_WAITING = 1;
+ /** Internal state D_SUBSCRIBED (first subscription request arrived) */
+ protected static final int D_SUBSCRIBED = 2;
+ /** Internal state D_PENDING (first subscription request has been accepted) */
+ protected static final int D_PENDING = 3;
+ /** Internal state D_ACTIVE (subscription has been activated) */
+ protected static final int D_ACTIVE = 4;
+ /**
+ * Internal state D_TERMINATED (first subscription request has been refused
+ * or subscription has been terminated)
+ */
+ protected static final int D_TERMINATED = 9;
+
+ // ************************* Protected methods ************************
+
+ /** Gets the dialog state */
+ protected String getStatusDescription() {
+ switch (status) {
+ case D_INIT:
+ return "D_INIT";
+ case D_WAITING:
+ return "D_WAITING";
+ case D_SUBSCRIBED:
+ return "D_SUBSCRIBED";
+ case D_PENDING:
+ return "D_PENDING";
+ case D_ACTIVE:
+ return "D_ACTIVE";
+ case D_TERMINATED:
+ return "D_TERMINATED";
+ default:
+ return null;
+ }
+ }
+
+ protected int getStatus() {
+ return status;
+ }
+
+ // ************************** Public methods **************************
+
+ /** Whether the dialog is in "early" state. */
+ public boolean isEarly() {
+ return (status < D_PENDING);
+ }
+
+ /** Whether the dialog is in "confirmed" state. */
+ public boolean isConfirmed() {
+ return (status >= D_PENDING && status < D_TERMINATED);
+ }
+
+ /** Whether the dialog is in "active" state. */
+ public boolean isTerminated() {
+ return (status == D_TERMINATED);
+ }
+
+ /** Whether the subscription is "pending". */
+ public boolean isSubscriptionPending() {
+ return (status >= D_SUBSCRIBED && status < D_ACTIVE);
+ }
+
+ /** Whether the subscription is "active". */
+ public boolean isSubscriptionActive() {
+ return (status == D_ACTIVE);
+ }
+
+ /** Whether the subscription is "terminated". */
+ public boolean isSubscriptionTerminated() {
+ return (status == D_TERMINATED);
+ }
+
+ /** Gets event type. */
+ public String getEvent() {
+ return event;
+ }
+
+ /** Gets the event "id" parameter. */
+ public String getId() {
+ return id;
+ }
+
+ // **************************** Costructors ****************************
+
+ /** Creates a new NotifierDialog. */
+ public NotifierDialog(SipProvider sip_provider,
+ NotifierDialogListener listener) {
+ super(sip_provider);
+ init(listener);
+ }
+
+ /**
+ * Creates a new NotifierDialog for the already received SUBSCRIBE request
+ * subscribe.
+ */
+ public NotifierDialog(SipProvider sip_provider, Message subscribe,
+ NotifierDialogListener listener) {
+ super(sip_provider);
+ init(listener);
+
+ changeStatus(D_SUBSCRIBED);
+ subscribe_req = subscribe;
+ subscribe_transaction = new TransactionServer(sip_provider, subscribe,
+ null);
+ update(Dialog.UAS, subscribe);
+ EventHeader eh = subscribe.getEventHeader();
+ if (eh != null) {
+ event = eh.getEvent();
+ id = eh.getId();
+ }
+ }
+
+ /** Inits the NotifierDialog. */
+ private void init(NotifierDialogListener listener) {
+ this.listener = listener;
+ this.subscribe_transaction = null;
+ this.notify_transaction = null;
+ this.subscribe_req = null;
+ this.event = null;
+ this.id = null;
+ changeStatus(D_INIT);
+ }
+
+ // *************************** Public methods **************************
+
+ /** Listen for the first subscription request. */
+ public void listen() {
+ printLog("inside method listen()", LogLevel.MEDIUM);
+ if (!statusIs(D_INIT)) {
+ printLog("first subscription already received", LogLevel.MEDIUM);
+ return;
+ }
+ // else
+ changeStatus(D_WAITING);
+ // listen for the first SUBSCRIBE request
+ sip_provider.addSipProviderListener(new MethodIdentifier(
+ SipMethods.SUBSCRIBE), this);
+ }
+
+ /** Accepts the subscription request (sends a "202 Accepted" response). */
+ public void accept(int expires, String contact) {
+ printLog("inside accept()", LogLevel.MEDIUM);
+ respond(202, SipResponses.reasonOf(202), expires, contact, null, null);
+ }
+
+ /** Refuses the subscription request. */
+ public void refuse() {
+ printLog("inside refuse()", LogLevel.MEDIUM);
+ respond(403, SipResponses.reasonOf(403), -1, null, null, null);
+ }
+
+ /**
+ * Responds with code and reason. This method can be called
+ * when the InviteDialog is in D_INVITED, D_ReINVITED states
+ */
+ public void respond(int code, String reason, int expires, String contact,
+ String content_type, String body) {
+ printLog("inside respond(" + code + "," + reason + ")", LogLevel.MEDIUM);
+ NameAddress contact_url = null;
+ if (contact != null)
+ contact_url = new NameAddress(contact);
+ Message resp = MessageFactory.createResponse(subscribe_req, code,
+ SipResponses.reasonOf(code), contact_url);
+ if (expires >= 0)
+ resp.setExpiresHeader(new ExpiresHeader(expires));
+ if (body != null)
+ resp.setBody(content_type, body);
+ respond(resp);
+ }
+
+ /** Responds with resp. */
+ public void respond(Message resp) {
+ printLog("inside respond(resp)", LogLevel.MEDIUM);
+ if (resp.getStatusLine().getCode() >= 200)
+ update(UAS, resp);
+ subscribe_transaction.respondWith(resp);
+ }
+
+ /** Activates the subscription (subscription goes into 'active' state). */
+ public void activate() {
+ activate(SipStack.default_expires);
+ }
+
+ /** Activates the subscription (subscription goes into 'active' state). */
+ public void activate(int expires) {
+ notify(ACTIVE, expires, null, null);
+ }
+
+ /** Makes the subscription pending (subscription goes into 'pending' state). */
+ public void pending() {
+ pending(SipStack.default_expires);
+ }
+
+ /** Makes the subscription pending (subscription goes into 'pending' state). */
+ public void pending(int expires) {
+ notify(PENDING, expires, null, null);
+ }
+
+ /** Terminates the subscription (subscription goes into 'terminated' state). */
+ public void terminate() {
+ terminate(null);
+ }
+
+ /** Terminates the subscription (subscription goes into 'terminated' state). */
+ public void terminate(String reason) {
+ Message req = MessageFactory.createNotifyRequest(this, event, id, null,
+ null);
+ SubscriptionStateHeader sh = new SubscriptionStateHeader(TERMINATED);
+ if (reason != null)
+ sh.setReason(reason);
+ // sh.setExpires(0);
+ req.setSubscriptionStateHeader(sh);
+ notify(req);
+ }
+
+ /** Sends a NOTIFY. */
+ public void notify(String state, int expires, String content_type,
+ String body) {
+ Message req = MessageFactory.createNotifyRequest(this, event, id,
+ content_type, body);
+ if (state != null) {
+ SubscriptionStateHeader sh = new SubscriptionStateHeader(state);
+ if (expires >= 0)
+ sh.setExpires(expires);
+ req.setSubscriptionStateHeader(sh);
+ }
+ notify(req);
+ }
+
+ /** Sends a NOTIFY. */
+ public void notify(Message req) {
+ String subscription_state = req.getSubscriptionStateHeader().getState();
+ if (subscription_state.equalsIgnoreCase(ACTIVE)
+ && (statusIs(D_SUBSCRIBED) || statusIs(D_PENDING)))
+ changeStatus(D_ACTIVE);
+ else if (subscription_state.equalsIgnoreCase(PENDING)
+ && statusIs(D_SUBSCRIBED))
+ changeStatus(D_PENDING);
+ else if (subscription_state.equalsIgnoreCase(TERMINATED)
+ && !statusIs(D_TERMINATED))
+ changeStatus(D_TERMINATED);
+
+ TransactionClient notify_transaction = new TransactionClient(
+ sip_provider, req, this);
+ notify_transaction.request();
+ }
+
+ // ************** Inherited from TransactionClientListener **************
+
+ /**
+ * When the TransactionClient is (or goes) in "Proceeding" state and
+ * receives a new 1xx provisional response
+ */
+ public void onTransProvisionalResponse(TransactionClient tc, Message resp) {
+ printLog("onTransProvisionalResponse()", LogLevel.MEDIUM);
+ // do nothing.
+ }
+
+ /**
+ * When the TransactionClient goes into the "Completed" state receiving a
+ * 2xx response
+ */
+ public void onTransSuccessResponse(TransactionClient tc, Message resp) {
+ printLog("onTransSuccessResponse()", LogLevel.MEDIUM);
+ StatusLine status_line = resp.getStatusLine();
+ if (listener != null)
+ listener.onDlgNotificationSuccess(this, status_line.getCode(),
+ status_line.getReason(), resp);
+ }
+
+ /**
+ * When the TransactionClient goes into the "Completed" state receiving a
+ * 300-699 response
+ */
+ public void onTransFailureResponse(TransactionClient tc, Message resp) {
+ printLog("onTransFailureResponse()", LogLevel.MEDIUM);
+ StatusLine status_line = resp.getStatusLine();
+ if (listener != null)
+ listener.onDlgNotificationFailure(this, status_line.getCode(),
+ status_line.getReason(), resp);
+ }
+
+ /**
+ * When the TransactionClient goes into the "Terminated" state, caused by
+ * transaction timeout
+ */
+ public void onTransTimeout(TransactionClient tc) {
+ printLog("onTransTimeout()", LogLevel.MEDIUM);
+ if (!statusIs(D_TERMINATED)) {
+ changeStatus(D_TERMINATED);
+ if (listener != null)
+ listener.onDlgNotifyTimeout(this);
+ }
+ }
+
+ // ************** Inherited from SipProviderListener **************
+
+ /** When a new Message is received by the SipProvider. */
+ public void onReceivedMessage(SipProvider provider, Message msg) {
+ printLog("onReceivedMessage()", LogLevel.MEDIUM);
+ if (statusIs(D_TERMINATED)) {
+ printLog("subscription already terminated: message discarded",
+ LogLevel.MEDIUM);
+ return;
+ }
+ // else
+ if (msg.isRequest() && msg.isSubscribe()) {
+ if (statusIs(NotifierDialog.D_WAITING)) { // the first SUBSCRIBE
+ // request
+ changeStatus(D_SUBSCRIBED);
+ sip_provider.removeSipProviderListener(new MethodIdentifier(
+ SipMethods.SUBSCRIBE));
+ }
+ subscribe_req = msg;
+ NameAddress target = msg.getToHeader().getNameAddress();
+ NameAddress subscriber = msg.getFromHeader().getNameAddress();
+ EventHeader eh = msg.getEventHeader();
+ if (eh != null) {
+ event = eh.getEvent();
+ id = eh.getId();
+ }
+ update(UAS, msg);
+ subscribe_transaction = new TransactionServer(sip_provider, msg,
+ null);
+ if (listener != null)
+ listener.onDlgSubscribe(this, target, subscriber, event, id,
+ msg);
+ } else {
+ printLog("message is not a SUBSCRIBE: message discarded",
+ LogLevel.HIGH);
+ }
+ }
+
+ // **************************** Logs ****************************/
+
+ /** Adds a new string to the default Log */
+ protected void printLog(String str, int level) {
+ if (log != null)
+ log.println("NotifierDialog#" + dialog_sqn + ": " + str, level
+ + SipStack.LOG_LEVEL_DIALOG);
+ }
+
+}
diff --git a/src/org/zoolu/sip/dialog/NotifierDialogListener.java b/app/src/main/java/org/zoolu/sip/dialog/NotifierDialogListener.java
similarity index 97%
rename from src/org/zoolu/sip/dialog/NotifierDialogListener.java
rename to app/src/main/java/org/zoolu/sip/dialog/NotifierDialogListener.java
index 4bcb8e3..18421e4 100644
--- a/src/org/zoolu/sip/dialog/NotifierDialogListener.java
+++ b/app/src/main/java/org/zoolu/sip/dialog/NotifierDialogListener.java
@@ -1,55 +1,55 @@
-/*
- * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
- *
- * This file is part of MjSip (http://www.mjsip.org)
- *
- * MjSip is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * MjSip is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with MjSip; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author(s):
- * Luca Veltri (luca.veltri@unipr.it)
- * Nitin Khanna, Hughes Systique Corp. (Reason: Android specific change, optmization, bug fix)
- */
-
-package org.zoolu.sip.dialog;
-
-import org.zoolu.sip.message.Message;
-import org.zoolu.sip.address.NameAddress;
-
-/**
- * A NotifierDialogListener listens for NotifierDialog events. It collects all
- * NOTIFY callback functions.
- */
-public interface NotifierDialogListener {
- /** When an incoming SUBSCRIBE is received. */
- public void onDlgSubscribe(NotifierDialog dialog, NameAddress target,
- NameAddress subscriber, String event, String id, Message msg);
-
- /** When a re-SUBSCRIBE is received. */
- // public void onDlgReSubscribe(NotifierDialog dialog, Message msg);
- /** When NOTIFY transaction expires without a final response. */
- public void onDlgNotifyTimeout(NotifierDialog dialog);
-
- /** When a 300-699 response is received for a NOTIFY transaction. */
- public void onDlgNotificationFailure(NotifierDialog dialog, int code,
- String reason, Message msg);
-
- /**
- * When a 2xx successfull final response is received for a NOTIFY
- * transaction.
- */
- public void onDlgNotificationSuccess(NotifierDialog dialog, int code,
- String reason, Message msg);
-
-}
+/*
+ * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
+ *
+ * This file is part of MjSip (http://www.mjsip.org)
+ *
+ * MjSip is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * MjSip is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MjSip; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author(s):
+ * Luca Veltri (luca.veltri@unipr.it)
+ * Nitin Khanna, Hughes Systique Corp. (Reason: Android specific change, optmization, bug fix)
+ */
+
+package org.zoolu.sip.dialog;
+
+import org.zoolu.sip.message.Message;
+import org.zoolu.sip.address.NameAddress;
+
+/**
+ * A NotifierDialogListener listens for NotifierDialog events. It collects all
+ * NOTIFY callback functions.
+ */
+public interface NotifierDialogListener {
+ /** When an incoming SUBSCRIBE is received. */
+ public void onDlgSubscribe(NotifierDialog dialog, NameAddress target,
+ NameAddress subscriber, String event, String id, Message msg);
+
+ /** When a re-SUBSCRIBE is received. */
+ // public void onDlgReSubscribe(NotifierDialog dialog, Message msg);
+ /** When NOTIFY transaction expires without a final response. */
+ public void onDlgNotifyTimeout(NotifierDialog dialog);
+
+ /** When a 300-699 response is received for a NOTIFY transaction. */
+ public void onDlgNotificationFailure(NotifierDialog dialog, int code,
+ String reason, Message msg);
+
+ /**
+ * When a 2xx successfull final response is received for a NOTIFY
+ * transaction.
+ */
+ public void onDlgNotificationSuccess(NotifierDialog dialog, int code,
+ String reason, Message msg);
+
+}
diff --git a/src/org/zoolu/sip/dialog/SubscriberDialog.java b/app/src/main/java/org/zoolu/sip/dialog/SubscriberDialog.java
similarity index 96%
rename from src/org/zoolu/sip/dialog/SubscriberDialog.java
rename to app/src/main/java/org/zoolu/sip/dialog/SubscriberDialog.java
index 937d0f5..0a28f8a 100644
--- a/src/org/zoolu/sip/dialog/SubscriberDialog.java
+++ b/app/src/main/java/org/zoolu/sip/dialog/SubscriberDialog.java
@@ -1,351 +1,351 @@
-/*
- * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
- *
- * This file is part of MjSip (http://www.mjsip.org)
- *
- * MjSip is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * MjSip is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with MjSip; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author(s):
- * Luca Veltri (luca.veltri@unipr.it)
- * Nitin Khanna, Hughes Systique Corp. (Reason: Android specific change, optmization, bug fix)
- */
-
-/* Modified by:
- * Daina Interrante (daina.interrante@studenti.unipr.it)
- */
-
-package org.zoolu.sip.dialog;
-
-import org.zoolu.sip.address.*;
-import org.zoolu.sip.transaction.*;
-import org.zoolu.sip.message.*;
-import org.zoolu.sip.header.*;
-import org.zoolu.sip.provider.*;
-import org.zoolu.tools.LogLevel;
-
-/**
- * SubscriberDialog.
- */
-public class SubscriberDialog extends Dialog implements
- TransactionClientListener {
- /** String "active" */
- protected static final String ACTIVE = "active";
- /** String "pending" */
- protected static final String PENDING = "pending";
- /** String "terminated" */
- protected static final String TERMINATED = "terminated";
-
- /** The current subscribe method */
- // Message subscribe=null;
- /** The subscribe transaction */
- TransactionClient subscribe_transaction;
-
- /** The notify transaction */
- // TransactionServer notify_transaction=null;
- /** The SubscriberDialog listener */
- SubscriberDialogListener listener;
-
- /** The event package name */
- String event;
-
- /** The subscription id */
- String id;
-
- /** Internal state D_INIT */
- protected static final int D_INIT = 0;
- /** Internal state D_SUBSCRIBING */
- protected static final int D_SUBSCRIBING = 1;
- /** Internal state D_SUBSCRIBED */
- protected static final int D_ACCEPTED = 2;
- /** Internal state D_PENDING */
- protected static final int D_PENDING = 3;
- /** Internal state D_ACTIVE */
- protected static final int D_ACTIVE = 4;
- /** Internal state D_TERMINATED */
- protected static final int D_TERMINATED = 9;
-
- /** Gets the dialog state */
- protected String getStatusDescription() {
- switch (status) {
- case D_INIT:
- return "D_INIT";
- case D_SUBSCRIBING:
- return "D_SUBSCRIBING";
- case D_ACCEPTED:
- return "D_ACCEPTED";
- case D_PENDING:
- return "D_PENDING";
- case D_ACTIVE:
- return "D_ACTIVE";
- case D_TERMINATED:
- return "D_TERMINATED";
- default:
- return null;
- }
- }
-
- protected int getStatus()
- {
- return status;
- }
-
- // *************************** Public methods **************************
-
- /** Whether the dialog is in "early" state. */
- public boolean isEarly() {
- return (status < D_ACCEPTED);
- }
-
- /** Whether the dialog is in "confirmed" state. */
- public boolean isConfirmed() {
- return (status >= D_ACCEPTED && status < D_TERMINATED);
- }
-
- /** Whether the dialog is in "active" state. */
- public boolean isTerminated() {
- return (status == D_TERMINATED);
- }
-
- /** Whether the subscription is "pending". */
- public boolean isSubscriptionPending() {
- return (status >= D_ACCEPTED && status < D_ACTIVE);
- }
-
- /** Whether the subscription is "active". */
- public boolean isSubscriptionActive() {
- return (status == D_ACTIVE);
- }
-
- /** Whether the subscription is "terminated". */
- public boolean isSubscriptionTerminated() {
- return (status == D_TERMINATED);
- }
-
- /** Gets event type. */
- public String getEvent() {
- return event;
- }
-
- /** Gets the event "id" parameter. */
- public String getId() {
- return id;
- }
-
- // **************************** Costructors ****************************
-
- /** Creates a new SubscriberDialog. */
- public SubscriberDialog(SipProvider sip_provider, /*
- * String subscriber,
- * String contact,
- */
- String event, String id, SubscriberDialogListener listener) {
- super(sip_provider);
- this.listener = listener;
- this.subscribe_transaction = null;
- // this.from_url=new NameAddress(subscriber);
- // if (contact!=null) this.contact_url=new NameAddress(contact);
- // else this.contact_url=from_url;
- this.event = event;
- this.id = null;
- changeStatus(D_INIT);
- }
-
- // *************************** Public methods **************************
-
- /**
- * Sends a new SUBSCRIBE request (starts a new subscription). It also
- * initializes the dialog state information.
- *
- * @param target
- * the target url (and display name)
- * @param subscriber
- * the subscriber url (and display name)
- * @param contact
- * the contact url OR the contact user-name
- */
- public void subscribe(String target, String subscriber, String contact,
- int expires) {
- printLog("inside subscribe(target=" + target + ",subscriber="
- + subscriber + ",contact=" + contact + ",id=" + id
- + ",expires=" + expires + ")", LogLevel.MEDIUM);
- SipURL request_uri = new SipURL(target);
- NameAddress to_url = new NameAddress(target);
- NameAddress from_url = new NameAddress(subscriber);
- NameAddress contact_url;
- if (contact != null)
- contact_url = new NameAddress(contact);
- else
- contact_url = from_url;
- String content_type = null;
- String body = null;
- Message req = MessageFactory.createSubscribeRequest(sip_provider,
- request_uri, to_url, from_url, contact_url, event, id,
- content_type, body);
- req.setHeader(new AcceptHeader("application/pidf+xml"));
- req.setExpiresHeader(new ExpiresHeader(expires));
- subscribe(req);
- }
-
- /**
- * Sends a new SUBSCRIBE request (starts a new subscription). It also
- * initializes the dialog state information.
- *
- * @param req
- * the SUBSCRIBE message
- */
- public void subscribe(Message req) {
- printLog("inside subscribe(req)", LogLevel.MEDIUM);
- if (statusIs(D_TERMINATED)) {
- printLog("subscription already terminated: request aborted",
- LogLevel.MEDIUM);
- return;
- }
- // else
- if (statusIs(D_INIT)) {
- changeStatus(D_SUBSCRIBING);
- }
- update(UAC, req);
- // start client transaction
- subscribe_transaction = new TransactionClient(sip_provider, req, this);
- subscribe_transaction.request();
- }
-
- /** Sends a new SUBSCRIBE request (starts a new subscription). */
- public void reSubscribe(String target, String subscriber, String contact,
- int expires) {
- subscribe(target, subscriber, contact, expires);
- }
-
- // ************** Inherited from TransactionClientListener **************
-
- /**
- * When the TransactionClient is (or goes) in "Proceeding" state and
- * receives a new 1xx provisional response
- */
- public void onTransProvisionalResponse(TransactionClient tc, Message resp) {
- printLog("onTransProvisionalResponse()", LogLevel.MEDIUM);
- // do nothing.
- }
-
- /**
- * When the TransactionClient goes into the "Completed" state receiving a
- * 2xx response
- */
- public void onTransSuccessResponse(TransactionClient tc, Message resp) {
- printLog("onTransSuccessResponse()", LogLevel.MEDIUM);
- if (!statusIs(D_ACTIVE)) {
- changeStatus(D_ACCEPTED);
- update(UAC, resp);
- StatusLine status_line = resp.getStatusLine();
- if (listener != null)
- listener.onDlgSubscriptionSuccess(this, status_line.getCode(),
- status_line.getReason(), resp);
- } else if (statusIs(D_ACTIVE)) {
- StatusLine status_line = resp.getStatusLine();
- if (listener != null)
- listener.onDlgSubscriptionSuccess(this, status_line.getCode(),
- status_line.getReason(), resp);
- }
- }
-
- /**
- * When the TransactionClient goes into the "Completed" state receiving a
- * 300-699 response
- */
- public void onTransFailureResponse(TransactionClient tc, Message resp) {
- printLog("onTransFailureResponse()", LogLevel.MEDIUM);
- changeStatus(D_TERMINATED);
- StatusLine status_line = resp.getStatusLine();
- if (listener != null)
- listener.onDlgSubscriptionFailure(this, status_line.getCode(),
- status_line.getReason(), resp);
- }
-
- /**
- * When the TransactionClient goes into the "Terminated" state, caused by
- * transaction timeout
- */
- public void onTransTimeout(TransactionClient tc) {
- printLog("onTransTimeout()", LogLevel.MEDIUM);
- changeStatus(D_TERMINATED);
- if (listener != null)
- listener.onDlgSubscribeTimeout(this);
- }
-
- // ***************** Inherited from SipProviderListener *****************
-
- /** When a new Message is received by the SipProvider. */
- public void onReceivedMessage(SipProvider sip_provider, Message msg) {
- printLog("onReceivedMessage()", LogLevel.MEDIUM);
- if (statusIs(D_TERMINATED)) {
- printLog("subscription already terminated: message discarded",
- LogLevel.MEDIUM);
- return;
- }
- // else
- if (msg.isRequest() && msg.isNotify()) {
- TransactionServer ts = new TransactionServer(sip_provider, msg,
- null);
- ts.respondWith(MessageFactory.createResponse(msg, 200, SipResponses
- .reasonOf(200), null));
-
- NameAddress to = msg.getToHeader().getNameAddress();
- NameAddress from = msg.getFromHeader().getNameAddress();
- NameAddress contact = null;
- if (msg.hasContactHeader())
- contact = msg.getContactHeader().getNameAddress();
- String state = null;
- if (msg.hasSubscriptionStateHeader())
- state = msg.getSubscriptionStateHeader().getState();
- String content_type = null;
- if (msg.hasContentTypeHeader())
- content_type = msg.getContentTypeHeader().getContentType();
- String body = null;
- if (msg.hasBody())
- body = msg.getBody();
-
- if (listener != null)
- listener.onDlgNotify(this, to, from, contact, state,
- content_type, body, msg);
-
- if (state != null) {
- if (state.equalsIgnoreCase(ACTIVE) && !statusIs(D_TERMINATED)) {
- changeStatus(D_ACTIVE);
- } else if (state.equalsIgnoreCase(PENDING)
- && statusIs(D_ACCEPTED)) {
- changeStatus(D_PENDING);
- } else if (state.equalsIgnoreCase(TERMINATED)
- && !statusIs(D_TERMINATED)) {
- changeStatus(D_TERMINATED);
- if (listener != null)
- listener.onDlgSubscriptionTerminated(this);
- }
- }
- } else {
- printLog("message is not a NOTIFY: message discarded",
- LogLevel.HIGH);
- }
- }
-
- // **************************** Logs ****************************/
-
- /** Adds a new string to the default Log */
- protected void printLog(String str, int level) {
- if (log != null)
- log.println("SubscriberDialog#" + dialog_sqn + ": " + str, level
- + SipStack.LOG_LEVEL_DIALOG);
- }
-
-}
+/*
+ * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
+ *
+ * This file is part of MjSip (http://www.mjsip.org)
+ *
+ * MjSip is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * MjSip is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MjSip; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author(s):
+ * Luca Veltri (luca.veltri@unipr.it)
+ * Nitin Khanna, Hughes Systique Corp. (Reason: Android specific change, optmization, bug fix)
+ */
+
+/* Modified by:
+ * Daina Interrante (daina.interrante@studenti.unipr.it)
+ */
+
+package org.zoolu.sip.dialog;
+
+import org.zoolu.sip.address.*;
+import org.zoolu.sip.transaction.*;
+import org.zoolu.sip.message.*;
+import org.zoolu.sip.header.*;
+import org.zoolu.sip.provider.*;
+import org.zoolu.tools.LogLevel;
+
+/**
+ * SubscriberDialog.
+ */
+public class SubscriberDialog extends Dialog implements
+ TransactionClientListener {
+ /** String "active" */
+ protected static final String ACTIVE = "active";
+ /** String "pending" */
+ protected static final String PENDING = "pending";
+ /** String "terminated" */
+ protected static final String TERMINATED = "terminated";
+
+ /** The current subscribe method */
+ // Message subscribe=null;
+ /** The subscribe transaction */
+ TransactionClient subscribe_transaction;
+
+ /** The notify transaction */
+ // TransactionServer notify_transaction=null;
+ /** The SubscriberDialog listener */
+ SubscriberDialogListener listener;
+
+ /** The event package name */
+ String event;
+
+ /** The subscription id */
+ String id;
+
+ /** Internal state D_INIT */
+ protected static final int D_INIT = 0;
+ /** Internal state D_SUBSCRIBING */
+ protected static final int D_SUBSCRIBING = 1;
+ /** Internal state D_SUBSCRIBED */
+ protected static final int D_ACCEPTED = 2;
+ /** Internal state D_PENDING */
+ protected static final int D_PENDING = 3;
+ /** Internal state D_ACTIVE */
+ protected static final int D_ACTIVE = 4;
+ /** Internal state D_TERMINATED */
+ protected static final int D_TERMINATED = 9;
+
+ /** Gets the dialog state */
+ protected String getStatusDescription() {
+ switch (status) {
+ case D_INIT:
+ return "D_INIT";
+ case D_SUBSCRIBING:
+ return "D_SUBSCRIBING";
+ case D_ACCEPTED:
+ return "D_ACCEPTED";
+ case D_PENDING:
+ return "D_PENDING";
+ case D_ACTIVE:
+ return "D_ACTIVE";
+ case D_TERMINATED:
+ return "D_TERMINATED";
+ default:
+ return null;
+ }
+ }
+
+ protected int getStatus()
+ {
+ return status;
+ }
+
+ // *************************** Public methods **************************
+
+ /** Whether the dialog is in "early" state. */
+ public boolean isEarly() {
+ return (status < D_ACCEPTED);
+ }
+
+ /** Whether the dialog is in "confirmed" state. */
+ public boolean isConfirmed() {
+ return (status >= D_ACCEPTED && status < D_TERMINATED);
+ }
+
+ /** Whether the dialog is in "active" state. */
+ public boolean isTerminated() {
+ return (status == D_TERMINATED);
+ }
+
+ /** Whether the subscription is "pending". */
+ public boolean isSubscriptionPending() {
+ return (status >= D_ACCEPTED && status < D_ACTIVE);
+ }
+
+ /** Whether the subscription is "active". */
+ public boolean isSubscriptionActive() {
+ return (status == D_ACTIVE);
+ }
+
+ /** Whether the subscription is "terminated". */
+ public boolean isSubscriptionTerminated() {
+ return (status == D_TERMINATED);
+ }
+
+ /** Gets event type. */
+ public String getEvent() {
+ return event;
+ }
+
+ /** Gets the event "id" parameter. */
+ public String getId() {
+ return id;
+ }
+
+ // **************************** Costructors ****************************
+
+ /** Creates a new SubscriberDialog. */
+ public SubscriberDialog(SipProvider sip_provider, /*
+ * String subscriber,
+ * String contact,
+ */
+ String event, String id, SubscriberDialogListener listener) {
+ super(sip_provider);
+ this.listener = listener;
+ this.subscribe_transaction = null;
+ // this.from_url=new NameAddress(subscriber);
+ // if (contact!=null) this.contact_url=new NameAddress(contact);
+ // else this.contact_url=from_url;
+ this.event = event;
+ this.id = null;
+ changeStatus(D_INIT);
+ }
+
+ // *************************** Public methods **************************
+
+ /**
+ * Sends a new SUBSCRIBE request (starts a new subscription). It also
+ * initializes the dialog state information.
+ *
+ * @param target
+ * the target url (and display name)
+ * @param subscriber
+ * the subscriber url (and display name)
+ * @param contact
+ * the contact url OR the contact user-name
+ */
+ public void subscribe(String target, String subscriber, String contact,
+ int expires) {
+ printLog("inside subscribe(target=" + target + ",subscriber="
+ + subscriber + ",contact=" + contact + ",id=" + id
+ + ",expires=" + expires + ")", LogLevel.MEDIUM);
+ SipURL request_uri = new SipURL(target);
+ NameAddress to_url = new NameAddress(target);
+ NameAddress from_url = new NameAddress(subscriber);
+ NameAddress contact_url;
+ if (contact != null)
+ contact_url = new NameAddress(contact);
+ else
+ contact_url = from_url;
+ String content_type = null;
+ String body = null;
+ Message req = MessageFactory.createSubscribeRequest(sip_provider,
+ request_uri, to_url, from_url, contact_url, event, id,
+ content_type, body);
+ req.setHeader(new AcceptHeader("application/pidf+xml"));
+ req.setExpiresHeader(new ExpiresHeader(expires));
+ subscribe(req);
+ }
+
+ /**
+ * Sends a new SUBSCRIBE request (starts a new subscription). It also
+ * initializes the dialog state information.
+ *
+ * @param req
+ * the SUBSCRIBE message
+ */
+ public void subscribe(Message req) {
+ printLog("inside subscribe(req)", LogLevel.MEDIUM);
+ if (statusIs(D_TERMINATED)) {
+ printLog("subscription already terminated: request aborted",
+ LogLevel.MEDIUM);
+ return;
+ }
+ // else
+ if (statusIs(D_INIT)) {
+ changeStatus(D_SUBSCRIBING);
+ }
+ update(UAC, req);
+ // start client transaction
+ subscribe_transaction = new TransactionClient(sip_provider, req, this);
+ subscribe_transaction.request();
+ }
+
+ /** Sends a new SUBSCRIBE request (starts a new subscription). */
+ public void reSubscribe(String target, String subscriber, String contact,
+ int expires) {
+ subscribe(target, subscriber, contact, expires);
+ }
+
+ // ************** Inherited from TransactionClientListener **************
+
+ /**
+ * When the TransactionClient is (or goes) in "Proceeding" state and
+ * receives a new 1xx provisional response
+ */
+ public void onTransProvisionalResponse(TransactionClient tc, Message resp) {
+ printLog("onTransProvisionalResponse()", LogLevel.MEDIUM);
+ // do nothing.
+ }
+
+ /**
+ * When the TransactionClient goes into the "Completed" state receiving a
+ * 2xx response
+ */
+ public void onTransSuccessResponse(TransactionClient tc, Message resp) {
+ printLog("onTransSuccessResponse()", LogLevel.MEDIUM);
+ if (!statusIs(D_ACTIVE)) {
+ changeStatus(D_ACCEPTED);
+ update(UAC, resp);
+ StatusLine status_line = resp.getStatusLine();
+ if (listener != null)
+ listener.onDlgSubscriptionSuccess(this, status_line.getCode(),
+ status_line.getReason(), resp);
+ } else if (statusIs(D_ACTIVE)) {
+ StatusLine status_line = resp.getStatusLine();
+ if (listener != null)
+ listener.onDlgSubscriptionSuccess(this, status_line.getCode(),
+ status_line.getReason(), resp);
+ }
+ }
+
+ /**
+ * When the TransactionClient goes into the "Completed" state receiving a
+ * 300-699 response
+ */
+ public void onTransFailureResponse(TransactionClient tc, Message resp) {
+ printLog("onTransFailureResponse()", LogLevel.MEDIUM);
+ changeStatus(D_TERMINATED);
+ StatusLine status_line = resp.getStatusLine();
+ if (listener != null)
+ listener.onDlgSubscriptionFailure(this, status_line.getCode(),
+ status_line.getReason(), resp);
+ }
+
+ /**
+ * When the TransactionClient goes into the "Terminated" state, caused by
+ * transaction timeout
+ */
+ public void onTransTimeout(TransactionClient tc) {
+ printLog("onTransTimeout()", LogLevel.MEDIUM);
+ changeStatus(D_TERMINATED);
+ if (listener != null)
+ listener.onDlgSubscribeTimeout(this);
+ }
+
+ // ***************** Inherited from SipProviderListener *****************
+
+ /** When a new Message is received by the SipProvider. */
+ public void onReceivedMessage(SipProvider sip_provider, Message msg) {
+ printLog("onReceivedMessage()", LogLevel.MEDIUM);
+ if (statusIs(D_TERMINATED)) {
+ printLog("subscription already terminated: message discarded",
+ LogLevel.MEDIUM);
+ return;
+ }
+ // else
+ if (msg.isRequest() && msg.isNotify()) {
+ TransactionServer ts = new TransactionServer(sip_provider, msg,
+ null);
+ ts.respondWith(MessageFactory.createResponse(msg, 200, SipResponses
+ .reasonOf(200), null));
+
+ NameAddress to = msg.getToHeader().getNameAddress();
+ NameAddress from = msg.getFromHeader().getNameAddress();
+ NameAddress contact = null;
+ if (msg.hasContactHeader())
+ contact = msg.getContactHeader().getNameAddress();
+ String state = null;
+ if (msg.hasSubscriptionStateHeader())
+ state = msg.getSubscriptionStateHeader().getState();
+ String content_type = null;
+ if (msg.hasContentTypeHeader())
+ content_type = msg.getContentTypeHeader().getContentType();
+ String body = null;
+ if (msg.hasBody())
+ body = msg.getBody();
+
+ if (listener != null)
+ listener.onDlgNotify(this, to, from, contact, state,
+ content_type, body, msg);
+
+ if (state != null) {
+ if (state.equalsIgnoreCase(ACTIVE) && !statusIs(D_TERMINATED)) {
+ changeStatus(D_ACTIVE);
+ } else if (state.equalsIgnoreCase(PENDING)
+ && statusIs(D_ACCEPTED)) {
+ changeStatus(D_PENDING);
+ } else if (state.equalsIgnoreCase(TERMINATED)
+ && !statusIs(D_TERMINATED)) {
+ changeStatus(D_TERMINATED);
+ if (listener != null)
+ listener.onDlgSubscriptionTerminated(this);
+ }
+ }
+ } else {
+ printLog("message is not a NOTIFY: message discarded",
+ LogLevel.HIGH);
+ }
+ }
+
+ // **************************** Logs ****************************/
+
+ /** Adds a new string to the default Log */
+ protected void printLog(String str, int level) {
+ if (log != null)
+ log.println("SubscriberDialog#" + dialog_sqn + ": " + str, level
+ + SipStack.LOG_LEVEL_DIALOG);
+ }
+
+}
diff --git a/src/org/zoolu/sip/dialog/SubscriberDialogListener.java b/app/src/main/java/org/zoolu/sip/dialog/SubscriberDialogListener.java
similarity index 97%
rename from src/org/zoolu/sip/dialog/SubscriberDialogListener.java
rename to app/src/main/java/org/zoolu/sip/dialog/SubscriberDialogListener.java
index 9aa6e40..4cd35f8 100644
--- a/src/org/zoolu/sip/dialog/SubscriberDialogListener.java
+++ b/app/src/main/java/org/zoolu/sip/dialog/SubscriberDialogListener.java
@@ -1,56 +1,56 @@
-/*
- * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
- *
- * This file is part of MjSip (http://www.mjsip.org)
- *
- * MjSip is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * MjSip is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with MjSip; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author(s):
- * Luca Veltri (luca.veltri@unipr.it)
- */
-
-package org.zoolu.sip.dialog;
-
-import org.zoolu.sip.message.Message;
-import org.zoolu.sip.address.NameAddress;
-
-/**
- * A SubscriberDialogListener listens for SubscriberDialog events. It collects
- * all SubscriberDialog callback functions.
- */
-public interface SubscriberDialogListener {
- /**
- * When a 2xx successfull final response is received for an SUBSCRIBE
- * transaction.
- */
- public void onDlgSubscriptionSuccess(SubscriberDialog dialog, int code,
- String reason, Message msg);
-
- /** When a 300-699 response is received for an SUBSCRIBE transaction. */
- public void onDlgSubscriptionFailure(SubscriberDialog dialog, int code,
- String reason, Message msg);
-
- /** When SUBSCRIBE transaction expires without a final response. */
- public void onDlgSubscribeTimeout(SubscriberDialog dialog);
-
- /** When the dialog is terminated. */
- public void onDlgSubscriptionTerminated(SubscriberDialog dialog);
-
- /** When an incoming NOTIFY is received. */
- public void onDlgNotify(SubscriberDialog dialog, NameAddress target,
- NameAddress notifier, NameAddress contact, String state,
- String content_type, String body, Message msg);
-
-}
+/*
+ * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
+ *
+ * This file is part of MjSip (http://www.mjsip.org)
+ *
+ * MjSip is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * MjSip is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MjSip; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author(s):
+ * Luca Veltri (luca.veltri@unipr.it)
+ */
+
+package org.zoolu.sip.dialog;
+
+import org.zoolu.sip.message.Message;
+import org.zoolu.sip.address.NameAddress;
+
+/**
+ * A SubscriberDialogListener listens for SubscriberDialog events. It collects
+ * all SubscriberDialog callback functions.
+ */
+public interface SubscriberDialogListener {
+ /**
+ * When a 2xx successfull final response is received for an SUBSCRIBE
+ * transaction.
+ */
+ public void onDlgSubscriptionSuccess(SubscriberDialog dialog, int code,
+ String reason, Message msg);
+
+ /** When a 300-699 response is received for an SUBSCRIBE transaction. */
+ public void onDlgSubscriptionFailure(SubscriberDialog dialog, int code,
+ String reason, Message msg);
+
+ /** When SUBSCRIBE transaction expires without a final response. */
+ public void onDlgSubscribeTimeout(SubscriberDialog dialog);
+
+ /** When the dialog is terminated. */
+ public void onDlgSubscriptionTerminated(SubscriberDialog dialog);
+
+ /** When an incoming NOTIFY is received. */
+ public void onDlgNotify(SubscriberDialog dialog, NameAddress target,
+ NameAddress notifier, NameAddress contact, String state,
+ String content_type, String body, Message msg);
+
+}
diff --git a/src/org/zoolu/sip/header/AcceptContactHeader.java b/app/src/main/java/org/zoolu/sip/header/AcceptContactHeader.java
similarity index 94%
rename from src/org/zoolu/sip/header/AcceptContactHeader.java
rename to app/src/main/java/org/zoolu/sip/header/AcceptContactHeader.java
index 7373cdd..ccb844b 100644
--- a/src/org/zoolu/sip/header/AcceptContactHeader.java
+++ b/app/src/main/java/org/zoolu/sip/header/AcceptContactHeader.java
@@ -1,27 +1,27 @@
-
-package org.zoolu.sip.header;
-
-/**
- * SIP Header AcceptContact
- *
- * Added by mandrajg for Sipdroid open source project.
- * Used with MMTel/IMS.
- */
-
-public class AcceptContactHeader extends ParametricHeader {
- public AcceptContactHeader(String icsi) {
- super(SipHeaders.Accept_Contact, "*");
- if (icsi != null)
- this.setParameter("+g.3gpp.icsi-ref", icsi);
- }
-
- public AcceptContactHeader() {
- super(SipHeaders.Accept_Contact, "*");
- }
-
- public AcceptContactHeader(Header hd) {
- super(hd);
- }
-
-
-}
+
+package org.zoolu.sip.header;
+
+/**
+ * SIP Header AcceptContact
+ *
+ * Added by mandrajg for Sipdroid open source project.
+ * Used with MMTel/IMS.
+ */
+
+public class AcceptContactHeader extends ParametricHeader {
+ public AcceptContactHeader(String icsi) {
+ super(SipHeaders.Accept_Contact, "*");
+ if (icsi != null)
+ this.setParameter("+g.3gpp.icsi-ref", icsi);
+ }
+
+ public AcceptContactHeader() {
+ super(SipHeaders.Accept_Contact, "*");
+ }
+
+ public AcceptContactHeader(Header hd) {
+ super(hd);
+ }
+
+
+}
diff --git a/src/org/zoolu/sip/header/AcceptHeader.java b/app/src/main/java/org/zoolu/sip/header/AcceptHeader.java
similarity index 96%
rename from src/org/zoolu/sip/header/AcceptHeader.java
rename to app/src/main/java/org/zoolu/sip/header/AcceptHeader.java
index 4177ff9..ccf07ce 100644
--- a/src/org/zoolu/sip/header/AcceptHeader.java
+++ b/app/src/main/java/org/zoolu/sip/header/AcceptHeader.java
@@ -1,49 +1,49 @@
-/*
- * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
- *
- * This file is part of MjSip (http://www.mjsip.org)
- *
- * MjSip is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * MjSip is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with MjSip; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author(s):
- * Luca Veltri (luca.veltri@unipr.it)
- */
-
-package org.zoolu.sip.header;
-
-/** SIP Header Accept */
-public class AcceptHeader extends ParametricHeader {
- public AcceptHeader() {
- super(SipHeaders.Accept, "application/sdp");
- }
-
- public AcceptHeader(String hvalue) {
- super(SipHeaders.Accept, hvalue);
- }
-
- public AcceptHeader(Header hd) {
- super(hd);
- }
-
- /** Gets the accept-range */
- public String getAcceptRange() {
- return value;
- }
-
- /** Sets the accept-range */
- public void setAcceptRange(String range) {
- value = range;
- }
-}
+/*
+ * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
+ *
+ * This file is part of MjSip (http://www.mjsip.org)
+ *
+ * MjSip is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * MjSip is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MjSip; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author(s):
+ * Luca Veltri (luca.veltri@unipr.it)
+ */
+
+package org.zoolu.sip.header;
+
+/** SIP Header Accept */
+public class AcceptHeader extends ParametricHeader {
+ public AcceptHeader() {
+ super(SipHeaders.Accept, "application/sdp");
+ }
+
+ public AcceptHeader(String hvalue) {
+ super(SipHeaders.Accept, hvalue);
+ }
+
+ public AcceptHeader(Header hd) {
+ super(hd);
+ }
+
+ /** Gets the accept-range */
+ public String getAcceptRange() {
+ return value;
+ }
+
+ /** Sets the accept-range */
+ public void setAcceptRange(String range) {
+ value = range;
+ }
+}
diff --git a/src/org/zoolu/sip/header/AlertInfoHeader.java b/app/src/main/java/org/zoolu/sip/header/AlertInfoHeader.java
similarity index 96%
rename from src/org/zoolu/sip/header/AlertInfoHeader.java
rename to app/src/main/java/org/zoolu/sip/header/AlertInfoHeader.java
index c8d5bf8..711e50c 100644
--- a/src/org/zoolu/sip/header/AlertInfoHeader.java
+++ b/app/src/main/java/org/zoolu/sip/header/AlertInfoHeader.java
@@ -1,59 +1,59 @@
-/*
- * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
- *
- * This file is part of MjSip (http://www.mjsip.org)
- *
- * MjSip is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * MjSip is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with MjSip; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author(s):
- * Luca Veltri (luca.veltri@unipr.it)
- */
-
-package org.zoolu.sip.header;
-
-/** SIP Header Allert-Info */
-public class AlertInfoHeader extends ParametricHeader {
- public AlertInfoHeader(String absolute_uri) {
- super(SipHeaders.Alert_Info, null);
- setAbsoluteURI(absolute_uri);
- }
-
- public AlertInfoHeader(Header hd) {
- super(hd);
- }
-
- /** Gets the absoluteURI */
- public String getAbsoluteURI() {
- int begin = value.indexOf("<");
- int end = value.indexOf(">");
- if (begin < 0)
- begin = 0;
- else
- begin++;
- if (end < 0)
- end = value.length();
- return value.substring(begin, end);
- }
-
- /** Sets the absoluteURI */
- public void setAbsoluteURI(String absolute_uri) {
- absolute_uri = absolute_uri.trim();
- if (absolute_uri.indexOf("<") < 0)
- absolute_uri = "<" + absolute_uri;
- if (absolute_uri.indexOf(">") < 0)
- absolute_uri = absolute_uri + ">";
- value = absolute_uri;
- }
-}
+/*
+ * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
+ *
+ * This file is part of MjSip (http://www.mjsip.org)
+ *
+ * MjSip is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * MjSip is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MjSip; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author(s):
+ * Luca Veltri (luca.veltri@unipr.it)
+ */
+
+package org.zoolu.sip.header;
+
+/** SIP Header Allert-Info */
+public class AlertInfoHeader extends ParametricHeader {
+ public AlertInfoHeader(String absolute_uri) {
+ super(SipHeaders.Alert_Info, null);
+ setAbsoluteURI(absolute_uri);
+ }
+
+ public AlertInfoHeader(Header hd) {
+ super(hd);
+ }
+
+ /** Gets the absoluteURI */
+ public String getAbsoluteURI() {
+ int begin = value.indexOf("<");
+ int end = value.indexOf(">");
+ if (begin < 0)
+ begin = 0;
+ else
+ begin++;
+ if (end < 0)
+ end = value.length();
+ return value.substring(begin, end);
+ }
+
+ /** Sets the absoluteURI */
+ public void setAbsoluteURI(String absolute_uri) {
+ absolute_uri = absolute_uri.trim();
+ if (absolute_uri.indexOf("<") < 0)
+ absolute_uri = "<" + absolute_uri;
+ if (absolute_uri.indexOf(">") < 0)
+ absolute_uri = absolute_uri + ">";
+ value = absolute_uri;
+ }
+}
diff --git a/src/org/zoolu/sip/header/AllowEventsHeader.java b/app/src/main/java/org/zoolu/sip/header/AllowEventsHeader.java
similarity index 96%
rename from src/org/zoolu/sip/header/AllowEventsHeader.java
rename to app/src/main/java/org/zoolu/sip/header/AllowEventsHeader.java
index 467037c..7076059 100644
--- a/src/org/zoolu/sip/header/AllowEventsHeader.java
+++ b/app/src/main/java/org/zoolu/sip/header/AllowEventsHeader.java
@@ -1,57 +1,57 @@
-/*
- * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
- *
- * This file is part of MjSip (http://www.mjsip.org)
- *
- * MjSip is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * MjSip is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with MjSip; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author(s):
- * Luca Veltri (luca.veltri@unipr.it)
- * Nitin Khanna, Hughes Systique Corp. (Reason: Android specific change, optmization, bug fix)
- */
-
-package org.zoolu.sip.header;
-
-import java.util.Vector;
-
-/** SIP Header Allow-Events */
-public class AllowEventsHeader extends ListHeader {
- public AllowEventsHeader(String hvalue) {
- super(SipHeaders.Allow_Events, hvalue);
- }
-
- public AllowEventsHeader(Header hd) {
- super(hd);
- }
-
- /** Gets list of events (as Vector of Strings). */
- /* HSC CHANGES BEGIN */
- public Vector getEvents() {
- /* HSC CHANGES END */
- return super.getElements();
- }
-
- /** Sets the list of events. */
- /* HSC CHANGES BEGIN */
- public void setEvents(Vector events) {
- /* HSC CHANGES END */
- super.setElements(events);
- }
-
- /** Adds a new event to the event list. */
- public void addEvent(String event) {
- super.addElement(event);
- }
-}
+/*
+ * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
+ *
+ * This file is part of MjSip (http://www.mjsip.org)
+ *
+ * MjSip is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * MjSip is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MjSip; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author(s):
+ * Luca Veltri (luca.veltri@unipr.it)
+ * Nitin Khanna, Hughes Systique Corp. (Reason: Android specific change, optmization, bug fix)
+ */
+
+package org.zoolu.sip.header;
+
+import java.util.Vector;
+
+/** SIP Header Allow-Events */
+public class AllowEventsHeader extends ListHeader {
+ public AllowEventsHeader(String hvalue) {
+ super(SipHeaders.Allow_Events, hvalue);
+ }
+
+ public AllowEventsHeader(Header hd) {
+ super(hd);
+ }
+
+ /** Gets list of events (as Vector of Strings). */
+ /* HSC CHANGES BEGIN */
+ public Vector getEvents() {
+ /* HSC CHANGES END */
+ return super.getElements();
+ }
+
+ /** Sets the list of events. */
+ /* HSC CHANGES BEGIN */
+ public void setEvents(Vector events) {
+ /* HSC CHANGES END */
+ super.setElements(events);
+ }
+
+ /** Adds a new event to the event list. */
+ public void addEvent(String event) {
+ super.addElement(event);
+ }
+}
diff --git a/src/org/zoolu/sip/header/AllowHeader.java b/app/src/main/java/org/zoolu/sip/header/AllowHeader.java
similarity index 96%
rename from src/org/zoolu/sip/header/AllowHeader.java
rename to app/src/main/java/org/zoolu/sip/header/AllowHeader.java
index a82e850..0c1ea0a 100644
--- a/src/org/zoolu/sip/header/AllowHeader.java
+++ b/app/src/main/java/org/zoolu/sip/header/AllowHeader.java
@@ -1,56 +1,56 @@
-/*
- * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
- *
- * This file is part of MjSip (http://www.mjsip.org)
- *
- * MjSip is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * MjSip is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with MjSip; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author(s):
- * Luca Veltri (luca.veltri@unipr.it)
- * Nitin Khanna, Hughes Systique Corp. (Reason: Android specific change, optmization, bug fix)
- */
-
-package org.zoolu.sip.header;
-
-import java.util.Vector;
-
-/** SIP Header Allow */
-public class AllowHeader extends ListHeader {
- public AllowHeader(String hvalue) {
- super(SipHeaders.Allow, hvalue);
- }
-
- public AllowHeader(Header hd) {
- super(hd);
- }
-
- /** Gets list of methods (as Vector of Strings). */
- /* HSC CHANGES START */
- public Vector getMethods() {
- return super.getElements();
- }
-
- /** Sets the list of methods. */
- public void setMethod(Vector methods) {
- super.setElements(methods);
- }
-
- /* HSC CHANGES END */
-
- /** Adds a new method to the methods list. */
- public void addMethod(String method) {
- super.addElement(method);
- }
-}
+/*
+ * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
+ *
+ * This file is part of MjSip (http://www.mjsip.org)
+ *
+ * MjSip is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * MjSip is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MjSip; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author(s):
+ * Luca Veltri (luca.veltri@unipr.it)
+ * Nitin Khanna, Hughes Systique Corp. (Reason: Android specific change, optmization, bug fix)
+ */
+
+package org.zoolu.sip.header;
+
+import java.util.Vector;
+
+/** SIP Header Allow */
+public class AllowHeader extends ListHeader {
+ public AllowHeader(String hvalue) {
+ super(SipHeaders.Allow, hvalue);
+ }
+
+ public AllowHeader(Header hd) {
+ super(hd);
+ }
+
+ /** Gets list of methods (as Vector of Strings). */
+ /* HSC CHANGES START */
+ public Vector getMethods() {
+ return super.getElements();
+ }
+
+ /** Sets the list of methods. */
+ public void setMethod(Vector methods) {
+ super.setElements(methods);
+ }
+
+ /* HSC CHANGES END */
+
+ /** Adds a new method to the methods list. */
+ public void addMethod(String method) {
+ super.addElement(method);
+ }
+}
diff --git a/src/org/zoolu/sip/header/AuthenticationHeader.java b/app/src/main/java/org/zoolu/sip/header/AuthenticationHeader.java
similarity index 96%
rename from src/org/zoolu/sip/header/AuthenticationHeader.java
rename to app/src/main/java/org/zoolu/sip/header/AuthenticationHeader.java
index f250a3f..90f65dc 100644
--- a/src/org/zoolu/sip/header/AuthenticationHeader.java
+++ b/app/src/main/java/org/zoolu/sip/header/AuthenticationHeader.java
@@ -1,407 +1,407 @@
-/*
- * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
- *
- * This file is part of MjSip (http://www.mjsip.org)
- *
- * MjSip is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * MjSip is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with MjSip; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author(s):
- * Luca Veltri (luca.veltri@unipr.it)
- * Nitin Khanna, Hughes Systique Corp. (Reason: Android specific change, optmization, bug fix)
- */
-
-package org.zoolu.sip.header;
-
-import org.zoolu.sip.provider.SipParser;
-import java.util.Vector;
-
-/**
- * Abstract header for various authentication schemes
- *
- * It is inherited by WwwAuthenticateHeader, AuthorizationHeader, etc.
- */
-public abstract class AuthenticationHeader extends Header {
-
- /** Lienar white space separator inserted bethween parameters. */
- // public static String LWS_SEPARATOR="\r\n ";
- public static String LWS_SEPARATOR = " ";
-
- /** Array of parameters that are quoted. */
- public static String[] QUOTED_PARAMETERS = { "auts", "cnonce", "nextnonce",
- "nonce", "opaque", "realm", "response", "rspauth", "uri",
- "username" };
-
- /** Whether is a quoted parameter (i.e. belongs to QUOTED_PARAMETERS). */
- private static boolean isQuotedParameter(String param_name) {
- for (int i = 0; i < QUOTED_PARAMETERS.length; i++)
- if (param_name.equalsIgnoreCase(QUOTED_PARAMETERS[i]))
- return true;
- return false;
- }
-
- /** Creates a new AuthenticationHeader. */
- public AuthenticationHeader(String hname, String hvalue) {
- super(hname, hvalue);
- }
-
- /** Creates a new AuthenticationHeader. */
- public AuthenticationHeader(Header hd) {
- super(hd);
- }
-
- /**
- * Creates a new AuthenticationHeader. specifing the auth_scheme and
- * the vector of authentication parameters.
- *
- * auth_params is a vector of String of the form parm_name
- * "=" parm_value
- */
- public AuthenticationHeader(String hname, String auth_scheme,
- /* HSC CHANGES START */
- Vector auth_params) {
- /* HSC CHANGES END */
- super(hname, auth_scheme);
- if (auth_params.size() > 0)
- value += " " + (String) auth_params.elementAt(0);
- for (int i = 1; i < auth_params.size(); i++)
- value += "," + LWS_SEPARATOR + (String) auth_params.elementAt(i);
- }
-
- /**
- * Adds a parameter. If param_name belongs to QUOTED_PARAMETERS,
- * param_value is quoted (if already not).
- */
- public void addParameter(String param_name, String param_value) {
- if (param_value.indexOf('"') < 0 && isQuotedParameter(param_name))
- addQuotedParameter(param_name, param_value);
- else
- addUnquotedParameter(param_name, param_value);
- }
-
- /** Adds a parameter without inserting quotes. */
- public void addUnquotedParameter(String param_name, String param_value) {
- if (value.indexOf('=') < 0)
- value += " ";
- else
- value += "," + LWS_SEPARATOR;
- value += param_name + "=" + param_value;
- }
-
- /** Adds a parameter with quotes. */
- public void addQuotedParameter(String param_name, String param_value) {
- if (value.indexOf('=') < 0)
- value += " ";
- else
- value += "," + LWS_SEPARATOR;
- if (param_value.indexOf('"') >= 0)
- value += param_name + "=" + param_value;
- else
- value += param_name + "=\"" + param_value + "\"";
- }
-
- /** Whether has parameter param_name */
- public boolean hasParameter(String param_name) {
- char[] name_separators = { '=', ' ', '\t', '\r', '\n' };
- SipParser par = new SipParser(value);
- par.skipString(); // skip the auth_scheme
- par.skipWSPCRLF();
- while (par.hasMore()) {
- String name = par.getWord(name_separators);
- if (name.equals(param_name))
- return true;
- par.goToCommaHeaderSeparator().skipChar().skipWSPCRLF();
- }
- return false;
- }
-
- /** Returns the parameter param_name, without quotes. */
- public String getParameter(String param_name) {
- char[] name_separators = { '=', ' ', '\t' };
- SipParser par = new SipParser(value);
- par.skipString(); // skip the auth_scheme
- par.skipWSPCRLF();
- while (par.hasMore()) {
- String name = par.getWord(name_separators);
- if (name.equals(param_name)) {
- par.goTo('=').skipChar().skipWSP();
- int comma = par.indexOfCommaHeaderSeparator();
- if (comma >= 0)
- par = new SipParser(par.getString(comma - par.getPos()));
- return par.getStringUnquoted();
- } else
- par.goToCommaHeaderSeparator().skipChar().skipWSPCRLF();
- }
- return null;
- }
-
- /**
- * Gets a String Vector of parameter names.
- *
- * @returns a Vector of String.
- */
- /* HSC CHANGES START */
- public Vector getParameters() {
- char[] name_separators = { '=', ' ', '\t' };
- SipParser par = new SipParser(value);
- par.skipString(); // skip the auth_scheme
- par.skipWSPCRLF();
- Vector names = new Vector();
- while (par.hasMore()) {
- String name = par.getWord(name_separators);
- names.addElement(name);
- par.goToCommaHeaderSeparator().skipChar().skipWSPCRLF();
- }
- return names;
- }
-
- /* HSC CHANGES END */
-
- /** Gets the athentication scheme (i.e. the first token). */
- public String getAuthScheme() {
- SipParser par = new SipParser(value);
- return par.getString();
- }
-
- // ***************** quoted parameters *****************
-
- /** Whether has realm */
- public boolean hasRealmParam() {
- return hasParameter("realm");
- }
-
- /** Returns the realm (unquoted) */
- public String getRealmParam() {
- return getParameter("realm");
- }
-
- /** Adds the realm */
- public void addRealmParam(String unquoted_realm) {
- addQuotedParameter("realm", unquoted_realm);
- }
-
- /** Whether has nonce */
- public boolean hasNonceParam() {
- return hasParameter("nonce");
- }
-
- /** Returns the nonce (unquoted) */
- public String getNonceParam() {
- return getParameter("nonce");
- }
-
- /** Adds the nonce */
- public void addNonceParam(String unquoted_nonce) {
- addQuotedParameter("nonce", unquoted_nonce);
- }
-
- /** Whether has opaque */
- public boolean hasOpaqueParam() {
- return hasParameter("opaque");
- }
-
- /** Returns the opaque (unquoted) */
- public String getOpaqueParam() {
- return getParameter("opaque");
- }
-
- /** Adds the opaque */
- public void addOpaqueParam(String unquoted_opaque) {
- addQuotedParameter("opaque", unquoted_opaque);
- }
-
- /** Whether has username */
- public boolean hasUsernameParam() {
- return hasParameter("username");
- }
-
- /** Returns the username (unquoted) */
- public String getUsernameParam() {
- return getParameter("username");
- }
-
- /** Adds the username */
- public void addUsernameParam(String unquoted_username) {
- addQuotedParameter("username", unquoted_username);
- }
-
- /** Whether has uri */
- public boolean hasUriParam() {
- return hasParameter("uri");
- }
-
- /** Returns the uri (unquoted) */
- public String getUriParam() {
- return getParameter("uri");
- }
-
- /** Adds the uri */
- public void addUriParam(String unquoted_uri) {
- addQuotedParameter("uri", unquoted_uri);
- }
-
- /** Whether has response */
- public boolean hasResponseParam() {
- return hasParameter("response");
- }
-
- /** Returns the response (unquoted) */
- public String getResponseParam() {
- return getParameter("response");
- }
-
- /** Adds the response */
- public void addResponseParam(String unquoted_response) {
- addQuotedParameter("response", unquoted_response);
- }
-
- /** Whether has cnonce */
- public boolean hasCnonceParam() {
- return hasParameter("cnonce");
- }
-
- /** Returns the cnonce (unquoted) */
- public String getCnonceParam() {
- return getParameter("cnonce");
- }
-
- /** Adds the cnonce */
- public void addCnonceParam(String unquoted_cnonce) {
- addQuotedParameter("cnonce", unquoted_cnonce);
- }
-
- /** Whether has rspauth */
- public boolean hasRspauthParam() {
- return hasParameter("rspauth");
- }
-
- /** Returns the rspauth (unquoted) */
- public String getRspauthParam() {
- return getParameter("rspauth");
- }
-
- /** Adds the rspauth */
- public void addRspauthParam(String unquoted_rspauth) {
- addQuotedParameter("rspauth", unquoted_rspauth);
- }
-
- /** Whether has auts */
- public boolean hasAutsParam() {
- return hasParameter("auts");
- }
-
- /** Returns the auts */
- public String getAutsParam() {
- return getParameter("auts");
- }
-
- /** Adds the auts */
- public void addAutsParam(String unquoted_auts) {
- addQuotedParameter("auts", unquoted_auts);
- }
-
- /** Whether has nextnonce */
- public boolean hasNextnonceParam() {
- return hasParameter("nextnonce");
- }
-
- /** Returns the nextnonce */
- public String getNextnonceParam() {
- return getParameter("nextnonce");
- }
-
- /** Adds the nextnonce */
- public void addNextnonceParam(String unquoted_nextnonce) {
- addQuotedParameter("nextnonce", unquoted_nextnonce);
- }
-
- /** Whether has qop-options */
- public boolean hasQopOptionsParam() {
- return hasParameter("qop");
- }
-
- /** Gets the qop-options */
- /*
- * public String[] getQopOptionsParam() { Vector aux=new Vector(); Parser
- * par=new Parser(getParameter("qop")); char[] separators={','}; String
- * qop=null; while ((qop=par.getWord(separators))!=null)
- * aux.addElement(qop); if (aux.size()==0) return null; String[]
- * qop_options=new String[aux.size()]; for (int i=0; i0) sb.append(","); sb.append(qop_options[i]); }
- * addQuotedParameter("qop",sb.toString()); }
- */
- /** Adds the qop-options */
- public void addQopOptionsParam(String unquoted_qop_options) {
- addQuotedParameter("qop", unquoted_qop_options);
- }
-
- // **************** unquoted parameters ****************
-
- /** Whether has qop */
- public boolean hasQopParam() {
- return hasParameter("qop");
- }
-
- /** Returns the qop */
- public String getQopParam() {
- return getParameter("qop");
- }
-
- /** Adds the qop */
- public void addQopParam(String qop) {
- addUnquotedParameter("qop", qop);
- }
-
- /** Whether has nc */
- public boolean hasNcParam() {
- return hasParameter("nc");
- }
-
- /** Returns the nc */
- public String getNcParam() {
- return getParameter("nc");
- }
-
- /** Adds the nc */
- public void addNcParam(String nc) {
- addUnquotedParameter("nc", nc);
- }
-
- /** Whether has algorithm */
- public boolean hasAlgorithmParam() {
- return hasParameter("algorithm");
- }
-
- /** Returns the algorithm */
- public String getAlgorithParam() {
- return getParameter("algorithm");
- }
-
- /** Adds the algorithm */
- public void addAlgorithParam(String algorithm) {
- addUnquotedParameter("algorithm", algorithm);
- }
-
-}
+/*
+ * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
+ *
+ * This file is part of MjSip (http://www.mjsip.org)
+ *
+ * MjSip is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * MjSip is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MjSip; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author(s):
+ * Luca Veltri (luca.veltri@unipr.it)
+ * Nitin Khanna, Hughes Systique Corp. (Reason: Android specific change, optmization, bug fix)
+ */
+
+package org.zoolu.sip.header;
+
+import org.zoolu.sip.provider.SipParser;
+import java.util.Vector;
+
+/**
+ * Abstract header for various authentication schemes
+ *
+ * It is inherited by WwwAuthenticateHeader, AuthorizationHeader, etc.
+ */
+public abstract class AuthenticationHeader extends Header {
+
+ /** Lienar white space separator inserted bethween parameters. */
+ // public static String LWS_SEPARATOR="\r\n ";
+ public static String LWS_SEPARATOR = " ";
+
+ /** Array of parameters that are quoted. */
+ public static String[] QUOTED_PARAMETERS = { "auts", "cnonce", "nextnonce",
+ "nonce", "opaque", "realm", "response", "rspauth", "uri",
+ "username" };
+
+ /** Whether is a quoted parameter (i.e. belongs to QUOTED_PARAMETERS). */
+ private static boolean isQuotedParameter(String param_name) {
+ for (int i = 0; i < QUOTED_PARAMETERS.length; i++)
+ if (param_name.equalsIgnoreCase(QUOTED_PARAMETERS[i]))
+ return true;
+ return false;
+ }
+
+ /** Creates a new AuthenticationHeader. */
+ public AuthenticationHeader(String hname, String hvalue) {
+ super(hname, hvalue);
+ }
+
+ /** Creates a new AuthenticationHeader. */
+ public AuthenticationHeader(Header hd) {
+ super(hd);
+ }
+
+ /**
+ * Creates a new AuthenticationHeader. specifing the auth_scheme and
+ * the vector of authentication parameters.
+ *
+ * auth_params is a vector of String of the form parm_name
+ * "=" parm_value
+ */
+ public AuthenticationHeader(String hname, String auth_scheme,
+ /* HSC CHANGES START */
+ Vector auth_params) {
+ /* HSC CHANGES END */
+ super(hname, auth_scheme);
+ if (auth_params.size() > 0)
+ value += " " + (String) auth_params.elementAt(0);
+ for (int i = 1; i < auth_params.size(); i++)
+ value += "," + LWS_SEPARATOR + (String) auth_params.elementAt(i);
+ }
+
+ /**
+ * Adds a parameter. If param_name belongs to QUOTED_PARAMETERS,
+ * param_value is quoted (if already not).
+ */
+ public void addParameter(String param_name, String param_value) {
+ if (param_value.indexOf('"') < 0 && isQuotedParameter(param_name))
+ addQuotedParameter(param_name, param_value);
+ else
+ addUnquotedParameter(param_name, param_value);
+ }
+
+ /** Adds a parameter without inserting quotes. */
+ public void addUnquotedParameter(String param_name, String param_value) {
+ if (value.indexOf('=') < 0)
+ value += " ";
+ else
+ value += "," + LWS_SEPARATOR;
+ value += param_name + "=" + param_value;
+ }
+
+ /** Adds a parameter with quotes. */
+ public void addQuotedParameter(String param_name, String param_value) {
+ if (value.indexOf('=') < 0)
+ value += " ";
+ else
+ value += "," + LWS_SEPARATOR;
+ if (param_value.indexOf('"') >= 0)
+ value += param_name + "=" + param_value;
+ else
+ value += param_name + "=\"" + param_value + "\"";
+ }
+
+ /** Whether has parameter param_name */
+ public boolean hasParameter(String param_name) {
+ char[] name_separators = { '=', ' ', '\t', '\r', '\n' };
+ SipParser par = new SipParser(value);
+ par.skipString(); // skip the auth_scheme
+ par.skipWSPCRLF();
+ while (par.hasMore()) {
+ String name = par.getWord(name_separators);
+ if (name.equals(param_name))
+ return true;
+ par.goToCommaHeaderSeparator().skipChar().skipWSPCRLF();
+ }
+ return false;
+ }
+
+ /** Returns the parameter param_name, without quotes. */
+ public String getParameter(String param_name) {
+ char[] name_separators = { '=', ' ', '\t' };
+ SipParser par = new SipParser(value);
+ par.skipString(); // skip the auth_scheme
+ par.skipWSPCRLF();
+ while (par.hasMore()) {
+ String name = par.getWord(name_separators);
+ if (name.equals(param_name)) {
+ par.goTo('=').skipChar().skipWSP();
+ int comma = par.indexOfCommaHeaderSeparator();
+ if (comma >= 0)
+ par = new SipParser(par.getString(comma - par.getPos()));
+ return par.getStringUnquoted();
+ } else
+ par.goToCommaHeaderSeparator().skipChar().skipWSPCRLF();
+ }
+ return null;
+ }
+
+ /**
+ * Gets a String Vector of parameter names.
+ *
+ * @returns a Vector of String.
+ */
+ /* HSC CHANGES START */
+ public Vector getParameters() {
+ char[] name_separators = { '=', ' ', '\t' };
+ SipParser par = new SipParser(value);
+ par.skipString(); // skip the auth_scheme
+ par.skipWSPCRLF();
+ Vector names = new Vector();
+ while (par.hasMore()) {
+ String name = par.getWord(name_separators);
+ names.addElement(name);
+ par.goToCommaHeaderSeparator().skipChar().skipWSPCRLF();
+ }
+ return names;
+ }
+
+ /* HSC CHANGES END */
+
+ /** Gets the athentication scheme (i.e. the first token). */
+ public String getAuthScheme() {
+ SipParser par = new SipParser(value);
+ return par.getString();
+ }
+
+ // ***************** quoted parameters *****************
+
+ /** Whether has realm */
+ public boolean hasRealmParam() {
+ return hasParameter("realm");
+ }
+
+ /** Returns the realm (unquoted) */
+ public String getRealmParam() {
+ return getParameter("realm");
+ }
+
+ /** Adds the realm */
+ public void addRealmParam(String unquoted_realm) {
+ addQuotedParameter("realm", unquoted_realm);
+ }
+
+ /** Whether has nonce */
+ public boolean hasNonceParam() {
+ return hasParameter("nonce");
+ }
+
+ /** Returns the nonce (unquoted) */
+ public String getNonceParam() {
+ return getParameter("nonce");
+ }
+
+ /** Adds the nonce */
+ public void addNonceParam(String unquoted_nonce) {
+ addQuotedParameter("nonce", unquoted_nonce);
+ }
+
+ /** Whether has opaque */
+ public boolean hasOpaqueParam() {
+ return hasParameter("opaque");
+ }
+
+ /** Returns the opaque (unquoted) */
+ public String getOpaqueParam() {
+ return getParameter("opaque");
+ }
+
+ /** Adds the opaque */
+ public void addOpaqueParam(String unquoted_opaque) {
+ addQuotedParameter("opaque", unquoted_opaque);
+ }
+
+ /** Whether has username */
+ public boolean hasUsernameParam() {
+ return hasParameter("username");
+ }
+
+ /** Returns the username (unquoted) */
+ public String getUsernameParam() {
+ return getParameter("username");
+ }
+
+ /** Adds the username */
+ public void addUsernameParam(String unquoted_username) {
+ addQuotedParameter("username", unquoted_username);
+ }
+
+ /** Whether has uri */
+ public boolean hasUriParam() {
+ return hasParameter("uri");
+ }
+
+ /** Returns the uri (unquoted) */
+ public String getUriParam() {
+ return getParameter("uri");
+ }
+
+ /** Adds the uri */
+ public void addUriParam(String unquoted_uri) {
+ addQuotedParameter("uri", unquoted_uri);
+ }
+
+ /** Whether has response */
+ public boolean hasResponseParam() {
+ return hasParameter("response");
+ }
+
+ /** Returns the response (unquoted) */
+ public String getResponseParam() {
+ return getParameter("response");
+ }
+
+ /** Adds the response */
+ public void addResponseParam(String unquoted_response) {
+ addQuotedParameter("response", unquoted_response);
+ }
+
+ /** Whether has cnonce */
+ public boolean hasCnonceParam() {
+ return hasParameter("cnonce");
+ }
+
+ /** Returns the cnonce (unquoted) */
+ public String getCnonceParam() {
+ return getParameter("cnonce");
+ }
+
+ /** Adds the cnonce */
+ public void addCnonceParam(String unquoted_cnonce) {
+ addQuotedParameter("cnonce", unquoted_cnonce);
+ }
+
+ /** Whether has rspauth */
+ public boolean hasRspauthParam() {
+ return hasParameter("rspauth");
+ }
+
+ /** Returns the rspauth (unquoted) */
+ public String getRspauthParam() {
+ return getParameter("rspauth");
+ }
+
+ /** Adds the rspauth */
+ public void addRspauthParam(String unquoted_rspauth) {
+ addQuotedParameter("rspauth", unquoted_rspauth);
+ }
+
+ /** Whether has auts */
+ public boolean hasAutsParam() {
+ return hasParameter("auts");
+ }
+
+ /** Returns the auts */
+ public String getAutsParam() {
+ return getParameter("auts");
+ }
+
+ /** Adds the auts */
+ public void addAutsParam(String unquoted_auts) {
+ addQuotedParameter("auts", unquoted_auts);
+ }
+
+ /** Whether has nextnonce */
+ public boolean hasNextnonceParam() {
+ return hasParameter("nextnonce");
+ }
+
+ /** Returns the nextnonce */
+ public String getNextnonceParam() {
+ return getParameter("nextnonce");
+ }
+
+ /** Adds the nextnonce */
+ public void addNextnonceParam(String unquoted_nextnonce) {
+ addQuotedParameter("nextnonce", unquoted_nextnonce);
+ }
+
+ /** Whether has qop-options */
+ public boolean hasQopOptionsParam() {
+ return hasParameter("qop");
+ }
+
+ /** Gets the qop-options */
+ /*
+ * public String[] getQopOptionsParam() { Vector aux=new Vector(); Parser
+ * par=new Parser(getParameter("qop")); char[] separators={','}; String
+ * qop=null; while ((qop=par.getWord(separators))!=null)
+ * aux.addElement(qop); if (aux.size()==0) return null; String[]
+ * qop_options=new String[aux.size()]; for (int i=0; i0) sb.append(","); sb.append(qop_options[i]); }
+ * addQuotedParameter("qop",sb.toString()); }
+ */
+ /** Adds the qop-options */
+ public void addQopOptionsParam(String unquoted_qop_options) {
+ addQuotedParameter("qop", unquoted_qop_options);
+ }
+
+ // **************** unquoted parameters ****************
+
+ /** Whether has qop */
+ public boolean hasQopParam() {
+ return hasParameter("qop");
+ }
+
+ /** Returns the qop */
+ public String getQopParam() {
+ return getParameter("qop");
+ }
+
+ /** Adds the qop */
+ public void addQopParam(String qop) {
+ addUnquotedParameter("qop", qop);
+ }
+
+ /** Whether has nc */
+ public boolean hasNcParam() {
+ return hasParameter("nc");
+ }
+
+ /** Returns the nc */
+ public String getNcParam() {
+ return getParameter("nc");
+ }
+
+ /** Adds the nc */
+ public void addNcParam(String nc) {
+ addUnquotedParameter("nc", nc);
+ }
+
+ /** Whether has algorithm */
+ public boolean hasAlgorithmParam() {
+ return hasParameter("algorithm");
+ }
+
+ /** Returns the algorithm */
+ public String getAlgorithParam() {
+ return getParameter("algorithm");
+ }
+
+ /** Adds the algorithm */
+ public void addAlgorithParam(String algorithm) {
+ addUnquotedParameter("algorithm", algorithm);
+ }
+
+}
diff --git a/src/org/zoolu/sip/header/AuthenticationInfoHeader.java b/app/src/main/java/org/zoolu/sip/header/AuthenticationInfoHeader.java
similarity index 96%
rename from src/org/zoolu/sip/header/AuthenticationInfoHeader.java
rename to app/src/main/java/org/zoolu/sip/header/AuthenticationInfoHeader.java
index 455c4bc..4753805 100644
--- a/src/org/zoolu/sip/header/AuthenticationInfoHeader.java
+++ b/app/src/main/java/org/zoolu/sip/header/AuthenticationInfoHeader.java
@@ -1,124 +1,124 @@
-/*
- * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
- *
- * This file is part of MjSip (http://www.mjsip.org)
- *
- * MjSip is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * MjSip is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with MjSip; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author(s):
- * Luca Veltri (luca.veltri@unipr.it)
- * Nitin Khanna, Hughes Systique Corp. (Reason: Android specific change, optmization, bug fix)
- */
-
-package org.zoolu.sip.header;
-
-import org.zoolu.sip.provider.SipParser;
-import java.util.Vector;
-
-/** SIP AuthenticationInfo header */
-public class AuthenticationInfoHeader extends AuthenticationHeader {
- /** Creates a new AuthenticationInfoHeader */
- public AuthenticationInfoHeader() {
- super(SipHeaders.Authentication_Info, "");
- }
-
- /** Creates a new AuthenticationInfoHeader */
- public AuthenticationInfoHeader(String hvalue) {
- super(SipHeaders.Authentication_Info, hvalue);
- }
-
- /** Creates a new AuthenticationInfoHeader */
- public AuthenticationInfoHeader(Header hd) {
- super(hd);
- }
-
- /**
- * Creates a new AuthenticationInfoHeader specifing the auth_scheme
- * and the vector of authentication parameters.
- *
- * auth_param is a vector of String of the form parm_name
- * "=" parm_value
- */
- /* HSC CHANGES START */
- public AuthenticationInfoHeader(Vector auth_params) {
- /* HSC CHANGES END */
- super(SipHeaders.Authentication_Info, "", auth_params);
- }
-
- /** Whether has parameter