diff --git a/src/net/java/sip/communicator/impl/protocol/sip/OperationSetBasicInstantMessagingSipImpl.java b/src/net/java/sip/communicator/impl/protocol/sip/OperationSetBasicInstantMessagingSipImpl.java index 9ce8fc17e..bf2c7e823 100644 --- a/src/net/java/sip/communicator/impl/protocol/sip/OperationSetBasicInstantMessagingSipImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/sip/OperationSetBasicInstantMessagingSipImpl.java @@ -33,10 +33,15 @@ public class OperationSetBasicInstantMessagingSipImpl Logger.getLogger(OperationSetBasicInstantMessagingSipImpl.class); /** - * A list of listeneres registered for message events. + * A list of listeners registered for message events. */ private Vector messageListeners = new Vector(); + /** + * A list of processors registered for incoming sip messages. + */ + private Vector messageProcessors = new Vector(); + /** * The provider that created us. */ @@ -77,7 +82,7 @@ public class OperationSetBasicInstantMessagingSipImpl } /** - * Registeres a MessageListener with this operation set so that it gets + * Registers a MessageListener with this operation set so that it gets * notifications of successful message delivery, failure or reception of * incoming messages.. * @@ -95,7 +100,7 @@ public void addMessageListener(MessageListener listener) } /** - * Unregisteres listener so that it won't receive any further + * Unregisters listener so that it won't receive any further * notifications upon successful message delivery, failure or reception of * incoming messages.. * @@ -108,6 +113,39 @@ public void removeMessageListener(MessageListener listener) this.messageListeners.remove(listener); } } + + /** + * Registers a SipMessageListener with this operation set so that it gets + * notifications of successful message delivery, failure or reception of + * incoming messages.. + * + * @param listener the SipMessageListener to register. + */ + void addMessageProcessor(SipMessageProcessor processor) + { + synchronized (this.messageProcessors) + { + if (!this.messageProcessors.contains(processor)) + { + this.messageProcessors.add(processor); + } + } + } + + /** + * Unregisters listener so that it won't receive any further + * notifications upon successful message delivery, failure or reception of + * incoming messages.. + * + * @param listener the SipMessageListener to unregister. + */ + void removeMessageProcessor(SipMessageProcessor processor) + { + synchronized (this.messageProcessors) + { + this.messageProcessors.remove(processor); + } + } /** * Create a Message instance for sending arbitrary MIME-encoding content. @@ -139,7 +177,7 @@ public Message createMessage(String messageText) } /** - * Determines wheter the protocol provider (or the protocol itself) support + * Determines whether the protocol provider (or the protocol itself) support * sending and receiving offline messages. Most often this method would * return true for protocols that support offline messages and false for * those that don't. It is however possible for a protocol to support these @@ -158,7 +196,7 @@ public boolean isOfflineMessagingSupported() } /** - * Determines wheter the protocol supports the supplied content type + * Determines whether the protocol supports the supplied content type * * @param contentType the type we want to check * @return true if the protocol supports it and @@ -228,7 +266,12 @@ public void sendInstantMessage(Contact to, Message message) fireMessageEvent(evt); return; } - + + sendRequestMessage(mes, to, message); + } + + void sendRequestMessage(Request mes, Contact to, Message message) + { //Transaction ClientTransaction messageTransaction; SipProvider jainSipProvider @@ -289,10 +332,10 @@ public void sendInstantMessage(Contact to, Message message) * @param to the Contact to send message to * @param message the Message to send. * @return a Message Request destinated to the contact - * @throws OperationFailedException if an error occured during + * @throws OperationFailedException if an error occurred during * the creation of the request */ - private Request createMessage(Contact to, Message message) + Request createMessage(Contact to, Message message) throws OperationFailedException { // Address @@ -560,7 +603,7 @@ private class RegistrationStateListener implements RegistrationStateChangeListener { /** - * The method is called by a ProtocolProvider implementation whenver + * The method is called by a ProtocolProvider implementation whenever * a change in the registration state of the corresponding provider had * occurred. * @param evt ProviderStatusChangeEvent the event describing the status @@ -584,7 +627,7 @@ public void registrationStateChanged(RegistrationStateChangeEvent evt) /** * Delivers the specified event to all registered message listeners. * @param evt the EventObject that we'd like delivered to all - * registered message listerners. + * registered message listeners. */ private void fireMessageEvent(EventObject evt) { @@ -726,6 +769,19 @@ public void processTimeout(TimeoutEvent timeoutEvent) */ public void processRequest(RequestEvent requestEvent) { + synchronized (messageProcessors) + { + Iterator iter = messageProcessors.iterator(); + while (iter.hasNext()) + { + SipMessageProcessor listener + = (SipMessageProcessor)iter.next(); + + if(!listener.processMessage(requestEvent)) + return; + } + } + // get the content String content = null; @@ -907,7 +963,7 @@ else if (status == 401 || status == 407) responseEvent.getSource(); try - { + { processAuthenticationChallenge(clientTransaction, responseEvent.getResponse(), sourceProvider); diff --git a/src/net/java/sip/communicator/impl/protocol/sip/OperationSetPresenceSipImpl.java b/src/net/java/sip/communicator/impl/protocol/sip/OperationSetPresenceSipImpl.java index 76433d7b8..87eec36e6 100644 --- a/src/net/java/sip/communicator/impl/protocol/sip/OperationSetPresenceSipImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/sip/OperationSetPresenceSipImpl.java @@ -85,7 +85,7 @@ public class OperationSetPresenceSipImpl /** * Hashtable which contains the contacts with which we want to subscribe - * or with which we successfuly subscribed + * or with which we successfully subscribed * Index : String, Content : ContactSipImpl */ private Hashtable subscribedContacts = new Hashtable(); @@ -187,7 +187,10 @@ public class OperationSetPresenceSipImpl * The id used in and elements * of pidf documents. */ - private static long tupleid = (long) Math.random(); + private static String tupleid = + String.valueOf("t" + (long)(Math.random() * 10000)); + private static String personid = + String.valueOf("p" + (long)(Math.random() * 10000)); // XML documents types private static final String PIDF_XML = "pidf+xml"; @@ -280,7 +283,7 @@ public OperationSetPresenceSipImpl(ProtocolProviderServiceSipImpl provider, * Returns a PresenceStatus instance representing the state this provider is * currently in. Note that PresenceStatus instances returned by this method * MUST adequately represent all possible states that a provider might - * enter duruing its lifecycle, includindg those that would not be visible + * enter during its lifecycle, including those that would not be visible * to others (e.g. Initializing, Connecting, etc ..) and those that will be * sent to contacts/buddies (On-Line, Eager to chat, etc.). * @@ -554,7 +557,7 @@ public void removeServerStoredContactGroup(ContactGroup group) /** * Requests the provider to enter into a status corresponding to the - * specified paramters. + * specified parameters. * * @param status the PresenceStatus as returned by * getRequestableStatusSet @@ -980,7 +983,7 @@ private Request createPublish(int expires, boolean insertPresDoc) /** * Returns the set of PresenceStatus objects that a user of this service * may request the provider to enter. Note that the provider would most - * probaby enter more states than those returned by this method as they + * probably enter more states than those returned by this method as they * only depict instances that users may request to enter. (e.g. a user * may not request a "Connecting..." state - it is a temporary state * that the provider enters while trying to enter the "Connected" state). @@ -1184,7 +1187,7 @@ public void subscribe(ContactGroup parentGroup, String contactIdentifier) * @param contact The contact concerned by this subscription * @param expires The expires value * - * @return a valid sip request reprensenting this message. + * @return a valid sip request representing this message. * * @throws OperationFailedException if the message can't be generated */ @@ -3116,7 +3119,7 @@ public void removeContactPresenceStatusListener( /** * Registers a listener that would get notifications any time a new - * subscription was succesfully added, has failed or was removed. + * subscription was successfully added, has failed or was removed. * * @param listener the SubscriptionListener to register */ @@ -3145,7 +3148,7 @@ public void removeSubscriptionListener(SubscriptionListener listener) { * stored groups. * * @param listener a ServerStoredGroupChangeListener impl that would - * receive events upong group changes. + * receive events upon group changes. */ public void addServerStoredGroupChangeListener(ServerStoredGroupListener listener) @@ -3486,7 +3489,7 @@ private String convertDocument(Document document) { * * @param document the document as a String * - * @return a Document reprensenting the document or null if an + * @return a Document representing the document or null if an * error occur */ private Document convertDocument(String document) { @@ -3555,7 +3558,7 @@ public byte[] getPidfPresenceStatus(ContactSipImpl contact) // Element person = doc.createElement(NS_PERSON_ELT); - person.setAttribute(ID_ATTRIBUTE, "p" + String.valueOf(tupleid++)); + person.setAttribute(ID_ATTRIBUTE, personid); presence.appendChild(person); // @@ -3578,8 +3581,7 @@ public byte[] getPidfPresenceStatus(ContactSipImpl contact) // Element tuple = doc.createElement(TUPLE_ELEMENT); - tuple.setAttribute(ID_ATTRIBUTE, String - .valueOf(tupleid++)); + tuple.setAttribute(ID_ATTRIBUTE, tupleid); presence.appendChild(tuple); // @@ -3670,10 +3672,10 @@ public void setPidfPresenceStatus(String presenceDoc) NodeList personList = presence.getElementsByTagNameNS(ANY_NS, PERSON_ELEMENT); - if (personList.getLength() > 1) { - logger.error("more than one person in this document"); - return; - } + //if (personList.getLength() > 1) { + // logger.error("more than one person in this document"); + // return; + //} if (personList.getLength() > 0) { Node personNode = personList.item(0); @@ -4314,7 +4316,7 @@ protected class watcherTimeoutTask extends TimerTask /** * Default constructor * - * @param contact The watcher conecerned by this timeout + * @param contact The watcher concerned by this timeout */ public watcherTimeoutTask(ContactSipImpl contact) { this.contact = contact; @@ -4424,7 +4426,7 @@ protected class RegistrationListener implements RegistrationStateChangeListener { /** - * The method is called by a ProtocolProvider implementation whenver + * The method is called by a ProtocolProvider implementation whenever * a change in the registration state of the corresponding provider had * occurred. The method is particularly interested in events stating * that the SIP provider has unregistered so that it would fire diff --git a/src/net/java/sip/communicator/impl/protocol/sip/SipMessageProcessor.java b/src/net/java/sip/communicator/impl/protocol/sip/SipMessageProcessor.java new file mode 100644 index 000000000..79e481576 --- /dev/null +++ b/src/net/java/sip/communicator/impl/protocol/sip/SipMessageProcessor.java @@ -0,0 +1,25 @@ +/* + * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. + * See terms of license at gnu.org. + */ +package net.java.sip.communicator.impl.protocol.sip; + +import javax.sip.*; + +/** + * Listener receiving events for incoming messages + * that need processing + * + * @author Damian Minkov + */ +public interface SipMessageProcessor +{ + /** + * Process the incoming message + * @param requestEvent the incoming event holding the message + * @return whether this message needs further processing(true) or no(false) + */ + public boolean processMessage(RequestEvent requestEvent); +} diff --git a/src/net/java/sip/communicator/impl/protocol/sip/SipRegistrarConnection.java b/src/net/java/sip/communicator/impl/protocol/sip/SipRegistrarConnection.java index acb9cc147..a3ca95fce 100644 --- a/src/net/java/sip/communicator/impl/protocol/sip/SipRegistrarConnection.java +++ b/src/net/java/sip/communicator/impl/protocol/sip/SipRegistrarConnection.java @@ -79,7 +79,7 @@ public class SipRegistrarConnection private Request registerRequest = null; /** - * The next long to use as a cseq header velue. + * The next long to use as a cseq header value. */ private long nextCSeqValue = 1; @@ -131,7 +131,7 @@ public SipRegistrarConnection(InetAddress registrarAddress, } /** - * Sends the REGISTER request to the server speciied in the constructor. + * Sends the REGISTER request to the server specified in the constructor. * * @throws OperationFailedException with the corresponding error code * if registration or construction of the Register request fail. @@ -384,7 +384,7 @@ void register() * notify listeners and (in the case of a new registration) schedule * reregistration. * - * @param clientTransatcion the ClientTransaction that we crated when + * @param clientTransatcion the ClientTransaction that we created when * sending the register request. * @param response the OK Response that we've just received. */ @@ -564,33 +564,33 @@ public void unregister() throws OperationFailedException } try { + //check whether there's a cached authorization header for this + //call id and if so - attach it to the request. + // add authorization header + CallIdHeader call = (CallIdHeader)unregisterRequest + .getHeader(CallIdHeader.NAME); + String callid = call.getCallId(); + + AuthorizationHeader authorization = sipProvider + .getSipSecurityManager() + .getCachedAuthorizationHeader(callid); + + if(authorization != null) + unregisterRequest.addHeader(authorization); + + unregisterTransaction.sendRequest(); - logger.debug("sent request: " + unregisterRequest); + logger.info("sent request: " + unregisterRequest); //if we're currently registered we'll wait for an ok response //before changing the status. otherwise we set it immediately. if(!getRegistrationState().equals(RegistrationState.REGISTERED)) { - logger.trace("Setting state to UNREGISTERED."); + logger.info("Setting state to UNREGISTERED."); setRegistrationState( RegistrationState.UNREGISTERED , RegistrationStateChangeEvent.REASON_USER_REQUEST, null); - //check whether there's a cached authorization header for this - //call id and if so - attach it to the request. - // add authorization header - CallIdHeader call = (CallIdHeader)unregisterRequest - .getHeader(CallIdHeader.NAME); - String callid = call.getCallId(); - - AuthorizationHeader authorization = sipProvider - .getSipSecurityManager() - .getCachedAuthorizationHeader(callid); - - if(authorization != null) - unregisterRequest.addHeader(authorization); - - //kill the registration tran in case it is still active if (regTrans != null && regTrans.getState().getValue() @@ -627,7 +627,7 @@ public RegistrationState getRegistrationState() } /** - * Sets our registraton state to newState and dispatches an event + * Sets our registration state to newState and dispatches an event * through the protocol provider service impl. *

* @param newState a reference to the RegistrationState that we're currently @@ -728,8 +728,8 @@ private void scheduleReRegistration(int expires) } /** - * Returns the next long to use as a cseq header velue. - * @return the next long to use as a cseq header velue. + * Returns the next long to use as a cseq header value. + * @return the next long to use as a cseq header value. */ private long getNextCSeqValue() { @@ -739,7 +739,7 @@ private long getNextCSeqValue() /** * Handles a NOT_IMPLEMENTED response sent in reply of our register request. * - * @param transatcion the transaction that our initial register reqeust + * @param transatcion the transaction that our initial register request * belongs to. * @param response our initial register request. */ @@ -765,10 +765,10 @@ public InetAddress getRegistrarAddress() } /** - * Returns the listening point that should be used for communiction with our + * Returns the listening point that should be used for communication with our * current registrar. * - * @return the listening point that should be used for communiction with our + * @return the listening point that should be used for communication with our * current registrar. */ ListeningPoint getRegistrarListeningPoint() @@ -854,12 +854,12 @@ else if ( response.getStatusCode() / 100 == 4 ) } /** - * Attempts to re-ogenerate the corresponding request with the proper + * Attempts to re-generate the corresponding request with the proper * credentials and terminates the call if it fails. * * @param clientTransaction the corresponding transaction * @param response the challenge - * @param jainSipProvider the provider that received the challende + * @param jainSipProvider the provider that received the challenge */ private void processAuthenticationChallenge( ClientTransaction clientTransaction, @@ -898,7 +898,7 @@ private void processAuthenticationChallenge( * * @param clientTransaction the corresponding transaction * @param response the challenge - * @param jainSipProvider the provider that received the challende + * @param jainSipProvider the provider that received the challenge */ private void processForbidden( ClientTransaction clientTransaction,