/** * Creates and sends a SUBSCRIBE request to the subscription <tt>Address</tt>/Request URI of a * specific <tt>Subscription</tt> in order to request receiving event notifications and adds the * specified <tt>Subscription</tt> to the list of subscriptions managed by this instance. The * added <tt>Subscription</tt> may later receive notifications to process the <tt>Request</tt>s * and/or <tt>Response</tt>s which constitute the signaling session associated with it. If the * attempt to create and send the SUBSCRIBE request fails, the specified <tt>Subscription</tt> is * not added to the list of subscriptions managed by this instance. * * @param subscription a <tt>Subscription</tt> which specifies the properties of the SUBSCRIBE * request to be created and sent, to be added to the list of subscriptions managed by this * instance * @throws OperationFailedException if we fail constructing or sending the subscription request. */ public void subscribe(Subscription subscription) throws OperationFailedException { Dialog dialog = subscription.getDialog(); if ((dialog != null) && DialogState.TERMINATED.equals(dialog.getState())) dialog = null; // create the subscription ClientTransaction subscribeTransaction = null; try { subscribeTransaction = (dialog == null) ? createSubscription(subscription, subscriptionDuration) : createSubscription(subscription, dialog, subscriptionDuration); } catch (OperationFailedException ex) { ProtocolProviderServiceSipImpl.throwOperationFailedException( "Failed to create the subscription", OperationFailedException.INTERNAL_ERROR, ex, logger); } // we register the contact to find him when the OK will arrive CallIdHeader callIdHeader = (CallIdHeader) subscribeTransaction.getRequest().getHeader(CallIdHeader.NAME); String callId = callIdHeader.getCallId(); addSubscription(callId, subscription); // send the message try { if (dialog == null) subscribeTransaction.sendRequest(); else dialog.sendRequest(subscribeTransaction); } catch (SipException ex) { // this contact will never been accepted or rejected removeSubscription(callId, subscription); ProtocolProviderServiceSipImpl.throwOperationFailedException( "Failed to send the subscription", OperationFailedException.NETWORK_FAILURE, ex, logger); } }
/** * Creates a new instance of this class using the specified parent <tt>protocolProvider</tt>. * * @param protocolProvider a reference to the <tt>ProtocolProviderServiceSipImpl</tt> instance * that created us. */ public ClientCapabilities(ProtocolProviderServiceSipImpl protocolProvider) { this.provider = protocolProvider; provider.registerMethodProcessor(Request.OPTIONS, this); registrationListener = new RegistrationListener(); provider.addRegistrationStateChangeListener(registrationListener); }
/** Fire event that connection has failed and we had to unregister the protocol provider. */ private void disconnect() { // don't alert the user if we're already off if (provider.getRegistrationState().equals(RegistrationState.UNREGISTERED)) { return; } provider .getRegistrarConnection() .setRegistrationState( RegistrationState.CONNECTION_FAILED, RegistrationStateChangeEvent.REASON_NOT_SPECIFIED, "A timeout occurred while trying to connect to the server."); }
/** * Creates an instance of this operation set. * * @param provider a ref to the <tt>ProtocolProviderServiceImpl</tt> that created us and that * we'll use for retrieving the underlying aim connection. */ OperationSetBasicInstantMessagingSipImpl(ProtocolProviderServiceSipImpl provider) { this.sipProvider = provider; provider.addRegistrationStateChangeListener(new RegistrationStateListener()); offlineMessageSupported = provider.getAccountID().getAccountPropertyBoolean("OFFLINE_MSG_SUPPORTED", false); sipProvider.registerMethodProcessor( Request.MESSAGE, new BasicInstantMessagingMethodProcessor()); this.sipStatusEnum = sipProvider.getSipStatusEnum(); }
/** * Receives options requests and replies with an OK response containing methods that we support. * * @param requestEvent the incoming options request. * @return <tt>true</tt> if request has been successfully processed, <tt>false</tt> otherwise */ @Override public boolean processRequest(RequestEvent requestEvent) { Response optionsOK = null; try { optionsOK = provider.getMessageFactory().createResponse(Response.OK, requestEvent.getRequest()); // add to the allows header all methods that we support for (String method : provider.getSupportedMethods()) { // don't support REGISTERs if (!method.equals(Request.REGISTER)) optionsOK.addHeader(provider.getHeaderFactory().createAllowHeader(method)); } Iterable<String> knownEventsList = provider.getKnownEventsList(); synchronized (knownEventsList) { for (String event : knownEventsList) optionsOK.addHeader(provider.getHeaderFactory().createAllowEventsHeader(event)); } } catch (ParseException ex) { // What else could we do apart from logging? logger.warn("Failed to create an incoming OPTIONS request", ex); return false; } try { SipStackSharing.getOrCreateServerTransaction(requestEvent).sendResponse(optionsOK); } catch (TransactionUnavailableException ex) { // this means that we received an OPTIONS request outside the scope // of a transaction which could mean that someone is simply sending // us b****hit to keep a NAT connection alive, so let's not get too // excited. if (logger.isInfoEnabled()) logger.info("Failed to respond to an incoming " + "transactionless OPTIONS request"); if (logger.isTraceEnabled()) logger.trace("Exception was:", ex); return false; } catch (InvalidArgumentException ex) { // What else could we do apart from logging? logger.warn("Failed to send an incoming OPTIONS request", ex); return false; } catch (SipException ex) { // What else could we do apart from logging? logger.warn("Failed to send an incoming OPTIONS request", ex); return false; } return true; }
/** * Initializes a new <tt>EventPackageSubscriber</tt> instance which is to provide subscriber * support according to RFC 3265 to a specific SIP <tt>ProtocolProviderService</tt> implementation * for a specific event package. * * @param protocolProvider the SIP <tt>ProtocolProviderService</tt> implementation for which the * new instance is to provide subscriber support for a specific event package * @param eventPackage the name of the event package the new instance is to implement and carry in * the Event and Allow-Events headers * @param subscriptionDuration the duration of each subscription to be managed by the new instance * and to be carried in the Expires headers * @param contentSubType the sub-type of the content type of the NOTIFY bodies to be announced, * expected and supported by the subscriptions to be managed by the new instance * @param timer the <tt>Timer</tt> support which is to refresh the subscriptions to be managed by * the new instance * @param refreshMargin the number of seconds before a subscription to be managed by the new * instance expires that the new instance should attempt to refresh it */ public EventPackageSubscriber( ProtocolProviderServiceSipImpl protocolProvider, String eventPackage, int subscriptionDuration, String contentSubType, TimerScheduler timer, int refreshMargin) { super(protocolProvider, eventPackage, subscriptionDuration, contentSubType, timer); this.refreshMargin = refreshMargin; this.messageFactory = protocolProvider.getMessageFactory(); }
/** Frees allocated resources. */ void shutdown() { provider.removeRegistrationStateChangeListener(registrationListener); }
/** * Construct a <tt>Request</tt> represent a new message. * * @param to the <tt>Contact</tt> to send <tt>message</tt> to * @param message the <tt>Message</tt> to send. * @return a Message Request destined to the contact * @throws OperationFailedException if an error occurred during the creation of the request */ Request createMessageRequest(Contact to, Message message) throws OperationFailedException { Address toAddress = null; try { toAddress = sipProvider.parseAddressString(to.getAddress()); } catch (ParseException exc) { // Shouldn't happen logger.error("An unexpected error occurred while" + "constructing the address", exc); throw new OperationFailedException( "An unexpected error occurred while" + "constructing the address", OperationFailedException.INTERNAL_ERROR, exc); } // Call ID CallIdHeader callIdHeader = this.sipProvider.getDefaultJainSipProvider().getNewCallId(); // CSeq CSeqHeader cSeqHeader = null; try { // protect seqN synchronized (this) { cSeqHeader = this.sipProvider.getHeaderFactory().createCSeqHeader(seqN++, Request.MESSAGE); } } catch (InvalidArgumentException ex) { // Shouldn't happen logger.error("An unexpected error occurred while" + "constructing the CSeqHeadder", ex); throw new OperationFailedException( "An unexpected error occurred while" + "constructing the CSeqHeadder", OperationFailedException.INTERNAL_ERROR, ex); } catch (ParseException exc) { // shouldn't happen logger.error("An unexpected error occurred while" + "constructing the CSeqHeadder", exc); throw new OperationFailedException( "An unexpected error occurred while" + "constructing the CSeqHeadder", OperationFailedException.INTERNAL_ERROR, exc); } // FromHeader and ToHeader String localTag = SipMessageFactory.generateLocalTag(); FromHeader fromHeader = null; ToHeader toHeader = null; try { // FromHeader fromHeader = this.sipProvider .getHeaderFactory() .createFromHeader(sipProvider.getOurSipAddress(toAddress), localTag); // ToHeader toHeader = this.sipProvider.getHeaderFactory().createToHeader(toAddress, null); } catch (ParseException ex) { // these two should never happen. logger.error( "An unexpected error occurred while" + "constructing the FromHeader or ToHeader", ex); throw new OperationFailedException( "An unexpected error occurred while" + "constructing the FromHeader or ToHeader", OperationFailedException.INTERNAL_ERROR, ex); } // ViaHeaders ArrayList<ViaHeader> viaHeaders = this.sipProvider.getLocalViaHeaders(toAddress); // MaxForwards MaxForwardsHeader maxForwards = this.sipProvider.getMaxForwardsHeader(); // Content params ContentTypeHeader contTypeHeader; ContentLengthHeader contLengthHeader; try { contTypeHeader = this.sipProvider .getHeaderFactory() .createContentTypeHeader(getType(message), getSubType(message)); if (!DEFAULT_MIME_ENCODING.equalsIgnoreCase(message.getEncoding())) contTypeHeader.setParameter("charset", message.getEncoding()); contLengthHeader = this.sipProvider.getHeaderFactory().createContentLengthHeader(message.getSize()); } catch (ParseException ex) { // these two should never happen. logger.error("An unexpected error occurred while" + "constructing the content headers", ex); throw new OperationFailedException( "An unexpected error occurred while" + "constructing the content headers", OperationFailedException.INTERNAL_ERROR, ex); } catch (InvalidArgumentException exc) { // these two should never happen. logger.error( "An unexpected error occurred while" + "constructing the content length header", exc); throw new OperationFailedException( "An unexpected error occurred while" + "constructing the content length header", OperationFailedException.INTERNAL_ERROR, exc); } Request req; try { req = this.sipProvider .getMessageFactory() .createRequest( toHeader.getAddress().getURI(), Request.MESSAGE, callIdHeader, cSeqHeader, fromHeader, toHeader, viaHeaders, maxForwards, contTypeHeader, message.getRawData()); } catch (ParseException ex) { // shouldn't happen logger.error("Failed to create message Request!", ex); throw new OperationFailedException( "Failed to create message Request!", OperationFailedException.INTERNAL_ERROR, ex); } req.addHeader(contLengthHeader); return req; }