Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.8</version>
<version>1.2.17</version>
</dependency>

<dependency>
Expand Down Expand Up @@ -279,7 +279,7 @@
</classpath>
</taskdef>
<xjc extension="true" schema="${basedir}/conf/presence-pidf.xsd"
binding="${basedir}/conf/jaxb-bindings.xsd" target="${project.build.sourceDirectory}"
binding="${basedir}/conf/jaxb-bindings.xsd" destdir="${project.build.sourceDirectory}"
package="org.cafesip.sipunit.presenceparser.pidf" />
</target>
</configuration>
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/org/cafesip/sipunit/PresenceSubscriber.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Calendar;

import javax.sip.header.AcceptHeader;
import javax.sip.header.ContentTypeHeader;
Expand All @@ -33,6 +34,7 @@
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.ValidationEvent;
import javax.xml.bind.ValidationEventHandler;
import javax.xml.datatype.XMLGregorianCalendar;

import org.cafesip.sipunit.presenceparser.pidf.Contact;
import org.cafesip.sipunit.presenceparser.pidf.Note;
Expand Down Expand Up @@ -210,9 +212,11 @@ public boolean handleEvent(ValidationEvent arg0)
while (i.hasNext())
{
Tuple t = (Tuple) i.next();
XMLGregorianCalendar gregCal = t.getTimestamp();
Calendar cvtTs = gregCal.toGregorianCalendar();

PresenceDeviceInfo dev = new PresenceDeviceInfo();
dev.setBasicStatus(t.getStatus().getBasic());
dev.setBasicStatus(t.getStatus().getBasic().toString());

Contact contact = t.getContact();
if (contact != null)
Expand All @@ -228,7 +232,7 @@ public boolean handleEvent(ValidationEvent arg0)
dev.setDeviceExtensions(t.getAny());
dev.setId(t.getId());
dev.setStatusExtensions(t.getStatus().getAny());
dev.setTimestamp(t.getTimestamp());
dev.setTimestamp(cvtTs);

ArrayList<PresenceNote> notes = new ArrayList<PresenceNote>();
if (t.getNote() != null)
Expand Down
115 changes: 104 additions & 11 deletions src/main/java/org/cafesip/sipunit/SipCall.java
Original file line number Diff line number Diff line change
Expand Up @@ -2850,6 +2850,14 @@ public boolean waitReinviteResponse(SipTransaction siptrans, long timeout)
return true;
}

public boolean disconnect()
{
if (sendDisconnect() == null) {
return false;
}
return true;
}

/**
* This method sends a basic BYE message. It incorporates required
* authorization headers that have previously been accumulated during the
Expand All @@ -2858,9 +2866,9 @@ public boolean waitReinviteResponse(SipTransaction siptrans, long timeout)
*
* @return true if the message was successfully sent, false otherwise.
*/
public boolean disconnect()
public SipTransaction sendDisconnect()
{
return disconnect(null, null, null);
return sendDisconnect(null, null, null);
}

/**
Expand Down Expand Up @@ -2895,7 +2903,7 @@ public boolean disconnect()
* for this body to be included in the message. Use null for no
* body bytes.
*/
public boolean disconnect(ArrayList<Header> additionalHeaders,
public SipTransaction sendDisconnect(ArrayList<Header> additionalHeaders,
ArrayList<Header> replaceHeaders, String body)
{
initErrorInfo();
Expand All @@ -2907,7 +2915,7 @@ public boolean disconnect(ArrayList<Header> additionalHeaders,
.get(new Integer(returnCode))
+ " - dialog hasn't been established";

return false;
return null;
}

try
Expand All @@ -2924,14 +2932,14 @@ public boolean disconnect(ArrayList<Header> additionalHeaders,

if (transaction != null)
{
return true;
return transaction;
}

setReturnCode(parent.getReturnCode());
setErrorMessage(parent.getErrorMessage());
setException(parent.getException());

return false;
return null;

}
catch (Exception ex)
Expand All @@ -2941,10 +2949,24 @@ public boolean disconnect(ArrayList<Header> additionalHeaders,
setErrorMessage("Exception: " + ex.getClass().getName() + ": "
+ ex.getMessage());

return null;
}
}

public boolean disconnect(String body, String contentType,
String contentSubType, ArrayList<String> additionalHeaders,
ArrayList<String> replaceHeaders)
{
SipTransaction siptrans = sendDisconnect(body, contentType, contentSubType,
additionalHeaders, replaceHeaders);

if (siptrans == null) {
return false;
}

return true;
}

/**
* This method is the same as the basic disconnect() method except that it
* allows the caller to specify a message body and/or additional message
Expand Down Expand Up @@ -2993,13 +3015,14 @@ public boolean disconnect(ArrayList<Header> additionalHeaders,
* null for no replacement of message headers.
*
*/
public boolean disconnect(String body, String contentType,
public SipTransaction sendDisconnect(String body, String contentType,
String contentSubType, ArrayList<String> additionalHeaders,
ArrayList<String> replaceHeaders)
{
SipTransaction ret = null;
try
{
return disconnect(parent.toHeader(additionalHeaders, contentType,
ret = sendDisconnect(parent.toHeader(additionalHeaders, contentType,
contentSubType), parent.toHeader(replaceHeaders), body);
}
catch (Exception ex)
Expand All @@ -3008,8 +3031,8 @@ public boolean disconnect(String body, String contentType,
setErrorMessage("Exception: " + ex.getClass().getName() + ": "
+ ex.getMessage());
setReturnCode(SipSession.EXCEPTION_ENCOUNTERED);
return false;
}
return ret;
}

/**
Expand Down Expand Up @@ -4278,6 +4301,76 @@ public boolean waitForCancelResponse(SipTransaction siptrans, long timeout)
return true;
}

/**
* The waitForDisconnectResponse() method waits for a response to be received
* from the network for a sent BYE. Call this method after calling
* sendDisconnect().
* <p>
* This method blocks until one of the following occurs: 1) A response
* message has been received. In this case, a value of true is returned.
* Call the getLastReceivedResponse() method to get the response details. 2)
* A timeout occurs. A false value is returned in this case. 3) An error
* occurs. False is returned in this case.
* <p>
* Regardless of the outcome, getReturnCode() can be called after this
* method returns to get the status code: IE, the SIP response code received
* from the network (defined in SipResponse, along with the corresponding
* textual equivalent) or a SipUnit internal status/error code (defined in
* SipSession, along with the corresponding textual equivalent). SipUnit
* internal codes are in a specially designated range
* (SipSession.SIPUNIT_INTERNAL_RETURNCODE_MIN and upward).
* <p>
*
* @param siptrans
* This is the object that was returned by method sendDisconnect().
* It identifies a specific Disconnect transaction.
* @param timeout
* The maximum amount of time to wait, in milliseconds. Use a
* value of 0 to wait indefinitely.
* @return true if a response was received - in that case, call
* getReturnCode() to get the status code that was contained in the
* received response, and/or call getLastReceivedResponse() to see
* the response details. Returns false if timeout or error.
*/
public boolean waitForDisconnectResponse(SipTransaction siptrans, long timeout)
{
initErrorInfo();

if (siptrans == null)
{
returnCode = SipSession.INVALID_OPERATION;
errorMessage = (String) SipSession.statusCodeDescription
.get(new Integer(returnCode))
+ " - no transaction object given";
return false;
}

EventObject response_event = parent.waitResponse(siptrans, timeout);

if (response_event == null)
{
setErrorMessage(parent.getErrorMessage());
setException(parent.getException());
setReturnCode(parent.getReturnCode());
return false;
}

if (response_event instanceof TimeoutEvent == true)
{
setReturnCode(SipPhone.TIMEOUT_OCCURRED);
setErrorMessage("A Timeout Event was received");
return false;
}

Response resp = ((ResponseEvent) response_event).getResponse();
receivedResponses.add(new SipResponse((ResponseEvent) response_event));
SipStack.trace("BYE response received: " + resp.toString());

setReturnCode(resp.getStatusCode());

return true;
}

/**
* Gets the SIP Call ID for this incoming or outgoing call.
*
Expand All @@ -4292,4 +4385,4 @@ public String getCallId()

return callId.getCallId();
}
}
}
13 changes: 7 additions & 6 deletions src/main/java/org/cafesip/sipunit/SipSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -448,13 +448,14 @@ public void processRequest(RequestEvent request)
{
SipStack
.trace(" skipping 'To' check, we're not loopback (see setLoopback())");
return;
}

// check 'To' for a match
if (to.getAddress().getURI().toString().equals(me) == false)
else
{
return;
// check 'To' for a match
if (to.getAddress().getURI().toString().equals(me) == false)
{
return;
}
}
}

Expand Down Expand Up @@ -2460,4 +2461,4 @@ public void processDialogTerminated(DialogTerminatedEvent arg0)
// TODO Auto-generated method stub

}
}
}
22 changes: 20 additions & 2 deletions src/main/java/org/cafesip/sipunit/SipStack.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
import javax.sip.header.RouteHeader;
import javax.sip.message.MessageFactory;

import org.apache.log4j.Logger;

/**
* This class is the starting point for a SipUnit test. Before establishing any
* SIP sessions, the test program must instantiate this class. Each SipStack
Expand All @@ -63,6 +65,8 @@
*/
public class SipStack implements SipListener
{
static Logger log = null;

private static boolean traceEnabled = false;

private static SipFactory sipFactory = null;
Expand Down Expand Up @@ -135,6 +139,16 @@ public class SipStack implements SipListener

public static final String DEFAULT_PROTOCOL = PROTOCOL_UDP;

/**
* This constructor is a wrapper around the usual constructor,
* which allows an additional logging object to be passed.
*/
public SipStack(String proto, int port, Properties props, Logger log) throws Exception
{
this(proto, port, props);
SipStack.log = log;
}

/**
* A constructor for this class. Before establishing any SIP sessions,
* instantiate this class. You may provide the parameters for SIP protocol
Expand Down Expand Up @@ -529,8 +543,12 @@ public synchronized static void trace(String msg) // grossly simplified
{
if (traceEnabled)
{
System.out.println("SIPUNIT TRACE: " + System.currentTimeMillis()
if (log == null) {
System.out.println("SIPUNIT TRACE: " + System.currentTimeMillis()
+ " " + msg);
} else {
log.trace("SIPUNIT TRACE\t" + msg);
}
}
}

Expand Down Expand Up @@ -606,4 +624,4 @@ public void processDialogTerminated(DialogTerminatedEvent arg0)
public int getRetransmissions() {
return retransmissions;
}
}
}