public static final int BYE_SUCCESS = 7; public static final int BYE_FAILURE = 6; public static final int CALL_FAILURE = 8; public static final int CALL_SUCCESS = 9; public static final int PUBLISH_SUCCESSFUL = 5; public static final int PUBLISH_FAILURE = 4; public static final int REFER_FAILURE = 10; public static final int REFER_SUCCESS = 11; public static final int REGISTER_FAILURE = 0; public static final int REGISTER_SUCCESSFUL = 1; public static final int REGISTER_SIPEXCEPTION = 12; public static final int SUBSCRIBE_FAILURE = 2; public static final int SUBSCRIBE_SUCCESSFUL = 3; public class NebulaApplication extends Application implements
		NebulaEventHandler {

	private static NebulaApplication singleton;
	private MyIdentity myIdentity = null;

	private SIPHandler mySIPHandler = null;

	private boolean isRTPInitialized = false;
	private RTPSession myRTPClient = null;
	private RTPSender myRTPSender = null;
	private RTPReceiver myRTPReceiver = null;

	private NebulaLocalDB myLocalDB = null;

	private LocationManager mlocManager;
	private NebulaLocationListener mlocListener;
	private final long MILLIS_FREQUENCY_UPDATE = 5000;
	private final long METERS_DISTANCE_UPDATE = 10;

	public static NebulaApplication getInstance() {
		return singleton;
	}

	@Override
	public final void onCreate() {
		super.onCreate();
		singleton = this;

		myIdentity = new MyIdentity();
		myLocalDB = new NebulaLocalDB(this);

		try {
			myIdentity.loadConfiguration();
			mySIPHandler = new SIPHandler(this);

			bindService(new Intent(NebulaApplication.this, RTPSender.class),
					senderConnection, Context.BIND_AUTO_CREATE);
			Log.v("nebula", "nebulaAPP: " + "sender service started");
			startService(new Intent(NebulaApplication.this, RTPSender.class));

			// Instantiate RTP Client
			myRTPClient = new RTPSession(new DatagramSocket(myIdentity
					.getMyRTPPort()), new DatagramSocket(myIdentity
					.getMyRTPPort() + 1));
			myRTPClient.payloadType(8);

			myRTPReceiver = new RTPReceiver(myRTPClient);

			mlocManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
			mlocListener = new NebulaLocationListener(this
					.getApplicationContext());
			mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
					MILLIS_FREQUENCY_UPDATE, METERS_DISTANCE_UPDATE,
					mlocListener);
		} catch (Exception e) {
			// TODO Handle gracefully
			Log.e("nebula", "nebulaApp: " + e.getMessage());
			System.exit(-1);
		}
	}

	public void processEvent(Object... params) {
		String eventName = params[0].toString();
		if (eventName.equals(NebulaSIPConstants.NOTIFY_PRESENCE)) {
			sendBroadcast(new Intent(params[0].toString()).putExtra("params",
					params));
		} else if (eventName.equals(NebulaSIPConstants.NOTIFY_INVITE)) {
			String threadId = (String) params[3];
			String convId = (String) params[4];
			String requestRCL = (String) params[5];

			ConversationThread thread;
			boolean shouldEstablishRTP = false;

			if (myIdentity.existsThread(threadId)) {
				thread = myIdentity.getThreadById(threadId);

				if (!thread.existsConversation(convId)) {
					thread.addConversation(convId, requestRCL);
					shouldEstablishRTP = false;
				} else {
					shouldEstablishRTP = true;
				}
			} else {
				thread = myIdentity.createThread(threadId);
				thread.addConversation(convId, requestRCL);
				shouldEstablishRTP = true;
			}

			if (shouldEstablishRTP == true) {
				establishRTP(params[1].toString(), Integer.valueOf(
						params[2].toString()).intValue());
			}

			sendBroadcast(new Intent(params[0].toString()));
		} else if (eventName.equals(NebulaSIPConstants.NOTIFY_BYE)) {
			String callId = (String) params[1];
			mySIPHandler.removeCallById(callId);
			terminateRTP(callId);
		}
	}

	public void reloadMyGroups() {
		RESTGroupManager rG = new RESTGroupManager();
		try {
			myIdentity.setMyGroups(rG.retrieveAllGroupsMembers());
			renewMyPresenceSubscriptions();
		} catch (Exception e) {
			// do nothing here since the old group is preserved
			Log.e("nebula", e.getMessage());
		}
	}

	public void reloadConversation() {
		RESTConversationManager rC = new RESTConversationManager();

		try {
			myIdentity.setMyThreads(rC.retrieveAll());
		} catch (Exception e) {
			// do nothing here since the old conversation is preserved
			Log.e("nebula", e.getMessage());
		}
	}

	private void renewMyPresenceSubscriptions() {
		for (Group individualGroup : myIdentity.getMyGroups()) {
			for (Profile individualProfile : individualGroup.getContacts()) {
				SIPManager.doSubscribe(individualProfile.getUsername(),
						myIdentity.getMySIPDomain());
			}
		}
	}

	public void establishRTP(String destAddressRTP, int destPortRTP) {
		if (!isRTPInitialized) {
			isRTPInitialized = true;
			myRTPSender.setRtpSender(myRTPClient);
			myRTPSender.startRecordingAndSending();

			myRTPClient.RTPSessionRegister(myRTPReceiver, null, null);
			myRTPReceiver.startPlaying();
		}

		// Log.v("nebula", "nebulaApp: desc ip/prt = " + destAddressRTP + "/"
		// + destPortRTP);
		Participant p = new Participant(destAddressRTP, destPortRTP,
				destPortRTP + 1);
		int participants = myRTPSender.numberOfReceivers();
		myRTPClient.addParticipant(p);

		while (participants == myRTPSender.numberOfReceivers()) {
		}

		new Thread() {
			public void run() {
				try {
					MediaPlayer mp = MediaPlayer.create(singleton, R.raw.beep);
					for (int i = 0; i < 2; i++) {
						if (mp != null) {
							mp.start();
							mp.reset();
							mp = MediaPlayer.create(singleton, R.raw.beep);
						}
					}
					mp.release();
				} catch (Exception e) {
					// do nothing here :P
				}
			}
		}.start();
	}
	
	public void muteMe(){
		myRTPReceiver.stopPlaying();
	}
	
	public void unMuteMe(){
		myRTPReceiver.startPlaying();
	}

	private void terminateRTP(String callId) {
		// TODO:: handle this
	}

	private ServiceConnection senderConnection = new ServiceConnection() {
		public void onServiceConnected(ComponentName name, IBinder binder) {
			myRTPSender = ((SenderBinder) binder).getService();
			Log.v("nebula", "Sender Connected!");
		}

		public void onServiceDisconnected(ComponentName name) {
			myRTPSender = null;
			Log.v("nebula", "Sender Disconnected!");
		}
	};

	public NebulaLocalDB getMyLocalDB() {
		return myLocalDB;
	}

	public MyIdentity getMyIdentity() {
		return myIdentity;
	}

	public void setMyIdentity(MyIdentity myIdentity) {
		this.myIdentity = myIdentity;
	}

	public SIPHandler getMySIPHandler() {
		return mySIPHandler;
	}
}
 public class Conversation {
	private int id;
	private Date date;
	private List<String> callee;
	private String conversationName;
	private String callId = "";

	private ConversationThread thread;
	private MyIdentity myIdentity = NebulaApplication.getInstance()
			.getMyIdentity();

	public Conversation(JSONObject convObj, String conversationName)
			throws JSONException, ParseException {
		this.callee = new ArrayList<String>();
		this.id = convObj.getInt("id");
		this.conversationName = conversationName;
		this.setDate(convObj.getString("date"));

		JSONObject calleeElement = convObj.getJSONObject("callees");
		for (int i = 0; i < calleeElement.length(); i++) {
			JSONObject user = calleeElement.getJSONObject("" + i);
			callee.add(user.getString("username"));
		}
	}

	public Conversation(String conversationName) {
		this.conversationName = conversationName;
		this.date = new Date();
		this.callee = new ArrayList<String>();
	}

	public Conversation(String conversationName, String rcl) {
		this(conversationName);

		List<String> rclList = new ArrayList<String>();
		String[] splitArray = rcl.split(",");
		for (String split : splitArray) {
			rclList.add(split);
		}

		addAllCallee(rclList);
	}

	public Conversation(String conversationName, List<String> callee) {
		this(conversationName);
		addAllCallee(callee);
	}

	public void addAllCallee(List<String> callee) {
		for (String member : callee) {
			this.addCalle(member);
		}
	}

	public boolean addCalle(String member) {
		if (callee.contains(member)) {
			return false;
		}
		return callee.add(member);
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getConversationName() {
		return conversationName;
	}

	public List<String> getCallee() {
		return callee;
	}

	public void setConversationName(String conversationName) {
		this.conversationName = conversationName;
	}

	public Date getDate() {
		return date;
	}

	public String getRcl() {
		return getRcl(true);
	}

	public String getRcl(boolean appendDomain) {
		StringBuilder res = new StringBuilder("");
		for (String member : callee) {
			if (!res.toString().equals("")) {
				res.append(",");
			}

			res.append(member);

			if (appendDomain) {
				res.append("@" + myIdentity.getMySIPDomain());
			}
		}
		return res.toString();
	}

	public void setDate(Date date) {
		this.date = date;
	}

	public String getDateToString() {
		Format format = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
		return (String) format.format(date);
	}

	public void setDate(String dat) throws ParseException,
			java.text.ParseException {
		Format formatter = new SimpleDateFormat("yy-MM-dd HH:mm:ss");
		this.date = (Date) formatter.parseObject(dat);
	}

	public ConversationThread getThread() {
		return thread;
	}

	public void setThread(ConversationThread thread) {
		this.thread = thread;
	}

	public String getCallId() {
		return callId;
	}

	public void setCallId(String callId) {
		this.callId = callId;
	}

	public String toString() {
		return this.thread.getThreadName() + conversationName;
	}
} public class ConversationThread {
	private String threadName;	
	private List<Conversation> myConversations = new ArrayList<Conversation>();

	

	public ConversationThread() {
		this.threadName = NebulaApplication.getInstance().getMyIdentity().createNewThreadId();
	}

	public ConversationThread(String threadName) {
		this.threadName = threadName;
	}

	public ConversationThread(JSONObject keyObj, String key) throws JSONException, ParseException {
		this.threadName = key;
		this.myConversations = new ArrayList<Conversation>();

		for (Iterator iterator = keyObj.keys(); iterator.hasNext();) {
			String actualConv = "" + iterator.next();
			JSONObject conversationObj = keyObj.getJSONObject(actualConv);			
			addConversation(new Conversation(conversationObj, actualConv));
		}
	}

	public Conversation addConversation(String newConversationId, String rcl) {
		Conversation newConversation = new Conversation(newConversationId, rcl);
		newConversation.setThread(this);
		myConversations.add(newConversation);
		return newConversation;
	}
	
	public Conversation addConversation(List<String> members) {
		return addConversation(new Conversation(NebulaApplication.getInstance().getMyIdentity().createNewConversationId(),
				members));
	}

	public Conversation addConversation(Conversation conv) {
		conv.setThread(this);
		myConversations.add(conv);
		return conv;
	}

	public Conversation getConversationByName(String name) throws Exception {
		for (Conversation curConversation : myConversations) {
			if (curConversation.getConversationName().equals(name)) {
				return curConversation;
			}
		}
		return null;
	}

	public boolean existsConversation(String conversationName) {
		for (Conversation conv : myConversations) {
			if (conv.getConversationName().equals(conversationName)) {
				return true;
			}
		}
		return false;
	}

	public String getThreadName() {
		return threadName;
	}

	public List<Conversation> getMyConversations() {
		return myConversations;
	}
} public class MyIdentity {
	private String myIP;
	private int mySIPPort;
	private int myRTPPort;
	private String myUserName;
	private String myPassword;
	private String mySIPDomain;

	private String sipServerIP;
	private Integer sipServerPort;
	private String sipServerName;
	private String mcuName;

	private String restServerIP;

	private String myStatus = "Online";// TODO:: update this

	private boolean mute = false;
	private String sipETag = "";

	private int seqNo = 0;
	private Calendar calendar = Calendar.getInstance();
	private SimpleDateFormat simpleDateFormat = new SimpleDateFormat(
			"yyyyMMddhhmmss");

	private Conversation currentConversation = null;
	private List<Group> myGroups = new ArrayList<Group>();
	private List<ConversationThread> myThreads = new ArrayList<ConversationThread>();

	public void loadConfiguration() throws Exception {
		myIP = Utils.getLocalIpAddress();
		mySIPPort = Utils.getNextRandomPort();
		myRTPPort = Utils.getNextRandomPort();

		// TODO: externalize this
		mySIPDomain = "192.16.124.211";
		sipServerIP = "192.16.124.211";
		sipServerPort = 5060;
		sipServerName = "Opensips";
		mcuName = "plm";

		restServerIP = "http://192.16.124.211/REST";
	}

	/*
	 * contact nina
	 */
	public ConversationThread getThreadById(String threadId) {
		for (ConversationThread thread : myThreads) {
			if (thread.getThreadName().equals(threadId)) {
				return thread;
			}
		}
		return null;
	}

	public boolean existsThread(String threadId) {
		for (ConversationThread thread : myThreads) {
			if (thread.getThreadName().equals(threadId)) {
				return true;
			}
		}
		return false;
	}

	/*
	 * is used when creating thread in the process of invite
	 */
	public ConversationThread createThread() {
		ConversationThread newThread = new ConversationThread();
		myThreads.add(newThread);
		return newThread;
	}

	/*
	 * is used when importing thread created by the others
	 */
	public ConversationThread createThread(String threadId) {
		ConversationThread newThread = new ConversationThread(threadId);
		myThreads.add(newThread);
		return newThread;
	}

	public String createNewConversationId() {
		return myUserName + seqNo++;
	}

	public String createNewThreadId() {
		return myUserName + simpleDateFormat.format(calendar.getTime());
	}

	public String getMySIPURI() {
		return "sip:" + myUserName + "@" + mySIPDomain;
	}

	public String getMyIP() {
		return myIP;
	}

	public void setMyIP(String myIP) {
		this.myIP = myIP;
	}

	public int getMySIPPort() {
		return mySIPPort;
	}

	public void setMySIPPort(int mySIPPort) {
		this.mySIPPort = mySIPPort;
	}

	public int getMyRTPPort() {
		return myRTPPort;
	}

	public void setMyRTPPort(int myRTPPort) {
		this.myRTPPort = myRTPPort;
	}

	public String getMyUserName() {
		return myUserName;
	}

	public void setMyUserName(String myUserName) {
		this.myUserName = myUserName;
	}

	public String getMyPassword() {
		return myPassword;
	}

	public void setMyPassword(String myPassword) {
		this.myPassword = myPassword;
	}

	public String getMySIPDomain() {
		return mySIPDomain;
	}

	public void setMySIPDomain(String mySIPDomain) {
		this.mySIPDomain = mySIPDomain;
	}

	public String getSipServerIP() {
		return sipServerIP;
	}

	public void setSipServerIP(String sipServerIP) {
		this.sipServerIP = sipServerIP;
	}

	public Integer getSipServerPort() {
		return sipServerPort;
	}

	public void setSipServerPort(Integer sipServerPort) {
		this.sipServerPort = sipServerPort;
	}

	public String getSipServerName() {
		return sipServerName;
	}

	public void setSipServerName(String sipServerName) {
		this.sipServerName = sipServerName;
	}

	public String getMcuName() {
		return mcuName;
	}

	public void setMcuName(String mcuName) {
		this.mcuName = mcuName;
	}

	public List<Group> getMyGroups() {
		return myGroups;
	}

	public void setMyGroups(List<Group> myGroups) {
		this.myGroups = myGroups;
	}

	public String getRestServerIP() {
		return restServerIP;
	}

	public void setRestServerIP(String restServerIP) {
		this.restServerIP = restServerIP;
	}

	public String getMyStatus() {
		return myStatus;
	}

	public void setMyStatus(String myStatus) {
		this.myStatus = myStatus;
	}

	public String getSipETag() {
		return sipETag;
	}

	public void setSipETag(String sipETag) {
		this.sipETag = sipETag;
	}

	public int getSeqNo() {
		return seqNo;
	}

	public List<ConversationThread> getMyThreads() {
		return myThreads;
	}

	public void setMyThreads(List<ConversationThread> myThreads) {
		this.myThreads = myThreads;
	}

	public void setMute(boolean mute) {
		this.mute = mute;
	}

	public boolean isMute() {
		return mute;
	}

	public boolean threadExists(String threadName) {
		for (ConversationThread ct : myThreads) {
			if (ct.getThreadName().equals(threadName))
				return true;
		}
		return false;
	}

	public void setCurrentConversation(Conversation currentConversation) {
		this.currentConversation = currentConversation;
	}

	public Conversation getCurrentConversation() {
		return currentConversation;
	}

}
 public class Status {
	private boolean isSuccess;
	private String message;
	
	public Status(boolean isSuccess, String message) {
		super();
		this.isSuccess = isSuccess;
		this.message = message;
	}
	
	public boolean isSuccess() {
		return isSuccess;
	}

	public void setSuccess(boolean isSuccess) {
		this.isSuccess = isSuccess;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}
} public class SIPUtils {

	public static String getSDP(String content) throws Exception {
		Pattern p1 = Pattern.compile(
				"Content-type: application/sdp\r\n(.*?)--8Yards",
				Pattern.MULTILINE | Pattern.DOTALL);

		// Pattern p1 = Pattern.compile("\r\n\r\n(.*)", Pattern.MULTILINE
		// | Pattern.DOTALL);

		Matcher m1 = p1.matcher(content);
		if (m1.find()) {
			return m1.group(1).trim();
		} else {
			throw new Exception("No SDP found");
		}
	}

	public static String getRCL(String content) throws Exception {
		Pattern p1 = Pattern
				.compile(
						"Content-type: application/resource-lists\\+xml\r\n(.*?)--8Yards",
						Pattern.MULTILINE | Pattern.DOTALL);
		Matcher m1 = p1.matcher(content);
		if (m1.find()) {
			return m1.group(1).trim();
		} else {
			throw new Exception("No RCL found");
		}
	}

	public static String getMySDP() {
		MyIdentity myIdentity = NebulaApplication.getInstance().getMyIdentity();
		return "v=0\r\n" + "o=" + myIdentity.getMyUserName()
				+ " 122456 654221 IN IP4 " + myIdentity.getMyIP() + "\r\n"
				+ "s=A conversation\r\n" + "c=IN IP4 " + myIdentity.getMyIP()
				+ "\r\n" + "t=0 0\r\n" + "m=audio " + myIdentity.getMyRTPPort()
				+ " RTP/AVP 8\r\n" + "a=rtpmap:8 PCMA/8000/1" + "\r\n";
	}

	public static String retrieveIP(String sdp) throws Exception {
		Pattern p1 = Pattern.compile("c=[^ ]+ [^ ]+ (.*)");
		Matcher m1 = p1.matcher(sdp);
		if (m1.find()) {
			return m1.group(1).trim();
		} else {
			throw new Exception("No IP found");
		}
	}

	public static int retrievePort(String sdp) throws Exception {
		Pattern p2 = Pattern.compile("m=audio ([0-9]+) ");
		Matcher m2 = p2.matcher(sdp);
		if (m2.find()) {
			return Integer.parseInt(m2.group(1));
		} else {
			throw new Exception("No Port found");
		}
	}

	public static String[] parsePresenceXML(String inXML)
			throws ParserConfigurationException, FactoryConfigurationError,
			SAXException, IOException {

		DocumentBuilder builder = DocumentBuilderFactory.newInstance()
				.newDocumentBuilder();

		// TODO:: purpose of each instance ---- assinged to NINA
		Document doc = builder.parse(new InputSource(new StringReader(inXML)));

		// get presence element
		NodeList presList = doc.getElementsByTagNameNS(PIDF_NS_VALUE,
				PRESENCE_ELEMENT);

		if (presList.getLength() == 0) {
			presList = doc.getElementsByTagName(PRESENCE_ELEMENT);
			if (presList.getLength() == 0) {
				throw new SAXException("presList length is zero");
			}
		}

		// we only use the first presence list =)
		Node presNode = presList.item(0);
		Element presence = (Element) presNode;
		NodeList tupleList = presence.getElementsByTagName(TUPLE_ELEMENT);

		for (int i = 0; i < tupleList.getLength(); i++) {
			Node tupleNode = tupleList.item(i);

			if (tupleNode.getNodeType() != Node.ELEMENT_NODE) {
				continue;
			}

			Element tuple = (Element) tupleNode;
			NodeList noteList = tuple.getElementsByTagName(NOTE_ELEMENT);

			if (noteList.getLength() > 0) {
				return new String[] { presence.getAttribute(ENTITY_ATTRIBUTE),
						noteList.item(0).getFirstChild().getNodeValue() };
			}
		}

		return null;
	}
	
	public static byte[] getPidfPresenceStatus(String status, String entity, String contact) throws ParseException {
		String res = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>"
				+ "<presence xmlns=\"urn:ietf:params:xml:ns:pidf\" xmlns:dm=\"urn:ietf:params:xml:ns:pidf:data-model\" xmlns:rpid=\"urn:ietf:params:xml:ns:pidf:rpid\" "
				+ "entity=\""
				+ entity
				+ "\">"
				+ "<dm:person id=\"p9206\">";

		// TODO:: check and produce XML well :S
		if (status.equals(NebulaSIPConstants.PRESENCE_ONLINE)) {
			res += "<rpid:activities/>";
		} else {
			res += "<rpid:activities>" + "<rpid:busy/>" + "</rpid:activities>";
		}

		res += "</dm:person>" + "<tuple id=\"t6222\">" + "<status>"
				+ "<basic>open</basic>" + "</status>" + "<contact>"
				+ contact
				+ "</contact>" + "<note>" + status + "</note>" + "</tuple>"
				+ "</presence>";

		return res.getBytes();
	}
}
import static org.nebula.client.sip.NebulaSIPConstants.BYE_SUCCESS;
import static org.nebula.client.sip.NebulaSIPConstants.BYE_FAILURE;
import static org.nebula.client.sip.NebulaSIPConstants.CALL_FAILURE;
import static org.nebula.client.sip.NebulaSIPConstants.CALL_SUCCESS;
import static org.nebula.client.sip.NebulaSIPConstants.PUBLISH_SUCCESSFUL;
import static org.nebula.client.sip.NebulaSIPConstants.PUBLISH_FAILURE;
import static org.nebula.client.sip.NebulaSIPConstants.REFER_FAILURE;
import static org.nebula.client.sip.NebulaSIPConstants.REFER_SUCCESS;
import static org.nebula.client.sip.NebulaSIPConstants.REGISTER_FAILURE;
import static org.nebula.client.sip.NebulaSIPConstants.REGISTER_SUCCESSFUL;
import static org.nebula.client.sip.NebulaSIPConstants.REGISTER_SIPEXCEPTION;
import static org.nebula.client.sip.NebulaSIPConstants.SUBSCRIBE_FAILURE;
import static org.nebula.client.sip.NebulaSIPConstants.SUBSCRIBE_SUCCESSFUL;
import java.util.Iterator;
import java.util.concurrent.TimeoutException;
import javax.sip.SipException;
import org.nebula.main.NebulaApplication;
import org.nebula.models.Conversation;
import org.nebula.models.ConversationThread;
import org.nebula.models.MyIdentity;
import org.nebula.models.Status;
import org.nebula.utils.SIPUtils;
import android.util.Log;
/*
 * author: prajwol kumar nakarmi, michel hognerund, nina mulkijanyan
 */
package org.nebula.client.sip;






public class SIPManager {

	public static int doLogin(String userName, String password) {
		try {
			SIPHandler sip = NebulaApplication.getInstance().getMySIPHandler();
			MyIdentity myIdentity = NebulaApplication.getInstance()
					.getMyIdentity();
			myIdentity.setMyUserName(userName);
			myIdentity.setMyPassword(password);

			Status response = sip.sendRegister();
			if (response.isSuccess() == true) {
				return REGISTER_SUCCESSFUL;
			} else {
				myIdentity.setMyUserName("");
				myIdentity.setMyPassword("");
				throw new Exception(response.getMessage());
			}
		} catch (Exception e) {
			Log.e("nebula", "SIPManager: " + e.getMessage());
			if (e.getMessage().equals("12")) {// bite me :/
				return REGISTER_SIPEXCEPTION;
			}
			return REGISTER_FAILURE;
		}
	}

	public static int doSubscribe(String toUserName, String toDomain) {
		try {
			SIPHandler sip = NebulaApplication.getInstance().getMySIPHandler();
			Status response = sip.sendSubscribe(toUserName, toDomain);
			if (response.isSuccess() == true) {
				return SUBSCRIBE_SUCCESSFUL;
			} else {
				throw new Exception("Subscribe didn't succeed");
			}
		} catch (Exception e) {
			Log.e("nebula", "sipManager.doSubscribe:" + e.getMessage());
			return SUBSCRIBE_FAILURE;
		}
	}

	public static int doPublish(String status) {
		try {
			SIPHandler sip = NebulaApplication.getInstance().getMySIPHandler();
			Status response = sip.sendPublish(status, 3600);
			if (response.isSuccess() == true) {
				return PUBLISH_SUCCESSFUL;
			} else {
				throw new Exception("Publish didn't succeed");
			}
		} catch (Exception e) {
			Log.e("nebula", "sipManager.doPublish:" + e.getMessage());
			return PUBLISH_FAILURE;
		}
	}

	// contact- prajwol, michel
	public static int doCall(ConversationThread thread,
			Conversation conversation) {
		try {
			Log.e("nebula", "SIPManager.doCall:" + conversation.getRcl());
			SIPHandler sip = NebulaApplication.getInstance().getMySIPHandler();
			Status response = sip.sendInvite(thread, conversation);
			if (response.isSuccess() == true) {
				NebulaApplication.getInstance().establishRTP(
						SIPUtils.retrieveIP(response.getMessage()),