public void process(Packet packet) {
   // Check that the requested packet can be processed
   if (canProcess(packet)) {
     // Perform the actual processing of the packet. This usually implies sending
     // the packet to the entity
     try {
       // Invoke the interceptors before we send the packet
       InterceptorManager.getInstance().invokeInterceptors(packet, this, false, false);
       deliver(packet);
       // Invoke the interceptors after we have sent the packet
       InterceptorManager.getInstance().invokeInterceptors(packet, this, false, true);
     } catch (PacketRejectedException e) {
       // An interceptor rejected the packet so do nothing
     } catch (Exception e) {
       Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
     }
   } else {
     // http://xmpp.org/extensions/xep-0016.html#protocol-error
     if (packet instanceof Message) {
       // For message stanzas, the server SHOULD return an error, which SHOULD be
       // <service-unavailable/>.
       Message message = (Message) packet;
       Message result = message.createCopy();
       result.setTo(message.getFrom());
       result.setError(PacketError.Condition.service_unavailable);
       XMPPServer.getInstance().getRoutingTable().routePacket(message.getFrom(), result, true);
     } else if (packet instanceof IQ) {
       // For IQ stanzas of type "get" or "set", the server MUST return an error, which SHOULD be
       // <service-unavailable/>.
       // IQ stanzas of other types MUST be silently dropped by the server.
       IQ iq = (IQ) packet;
       if (iq.getType() == IQ.Type.get || iq.getType() == IQ.Type.set) {
         IQ result = IQ.createResultIQ(iq);
         result.setError(PacketError.Condition.service_unavailable);
         XMPPServer.getInstance().getRoutingTable().routePacket(iq.getFrom(), result, true);
       }
     }
   }
 }
示例#2
0
  @Override
  public void destroyPlugin() {
    // Degister HistoryPacketInterceptor
    final HistoryPacketInterceptor historyPacketInterceptor = HistoryPacketInterceptor.singleton();
    final InterceptorManager interceptorManager = InterceptorManager.getInstance();
    interceptorManager.removeInterceptor(historyPacketInterceptor);

    // Deregister PredictionIQHandler
    final XMPPServer xmppServer = XMPPServer.getInstance();
    final IQRouter iqRouter = xmppServer.getIQRouter();
    final PredictionIQHandler predictionIQHandler = PredictionIQHandler.singleton();
    iqRouter.removeHandler(predictionIQHandler);

    // Deregister LocationRepository
    final LocationRepository locationRepo = LocationRepository.singleton();
    iqRouter.removeHandler(locationRepo);
  }
示例#3
0
  /** Remove all registered statistics. */
  public void stop() {

    // Remove Server to Server Statistic
    statisticsManager.removeStatistic(SERVER_2_SERVER_SESSIONS_KEY);

    // Remove Active Session Statistic
    statisticsManager.removeStatistic(SESSIONS_KEY);

    // Remove Packet Traffic Statistic
    statisticsManager.removeStatistic(TRAFFIC_KEY);

    statisticsManager = null;

    // Remove the packet listener.
    InterceptorManager.getInstance().removeInterceptor(packetInterceptor);
    packetInterceptor = null;
    packetCount = null;
  }
示例#4
0
  @Override
  public void initializePlugin(final PluginManager pluginManager, final File pluginDirectory) {
    initialize();

    // Register HistoryPacketInterceptor
    final HistoryPacketInterceptor historyPacketInterceptor = HistoryPacketInterceptor.singleton();
    InterceptorManager.getInstance().addInterceptor(historyPacketInterceptor);

    // Register PredictionIQHandler
    final XMPPServer xmppServer = XMPPServer.getInstance();
    final IQRouter iqRouter = xmppServer.getIQRouter();
    final PredictionIQHandler predictionIQHandler = PredictionIQHandler.singleton();
    iqRouter.addHandler(predictionIQHandler);

    // Register LocationRepository
    final LocationRepository locationRepo = LocationRepository.singleton();
    iqRouter.addHandler(locationRepo);
  }
示例#5
0
  public void start() {
    // Retrieve instance of StatisticsManager
    statisticsManager = StatisticsManager.getInstance();

    // Register a packet listener so that we can track packet traffic.
    packetInterceptor =
        new PacketInterceptor() {
          public void interceptPacket(
              Packet packet, Session session, boolean incoming, boolean processed) {
            // Only track processed packets so that we don't count them twice.
            if (processed) {
              packetCount.incrementAndGet();
            }
          }
        };
    InterceptorManager.getInstance().addInterceptor(packetInterceptor);

    // Register all statistics.
    addServerToServerStatistic();
    addActiveSessionsStatistic();
    addPacketStatistic();
  }
 /** Default constructor creates the cache. */
 public DefaultFileTransferManager() {
   super("File Transfer Manager");
   fileTransferMap = CacheFactory.createCache(CACHE_NAME);
   InterceptorManager.getInstance().addInterceptor(new MetaFileTransferInterceptor());
 }
 public MessageHookPlugin() {
   mInterceptorManager = InterceptorManager.getInstance();
 }
示例#8
0
  public void initializePlugin(PluginManager manager, File pluginDirectory) {
    SipXOpenfirePlugin.instance = this;

    InputStream in = getClass().getResourceAsStream("/config.properties");
    Properties properties = new Properties();
    componentManager = ComponentManagerFactory.getComponentManager();

    try {
      properties.load(in);
    } catch (IOException ex) {
      componentManager.getLog().error(ex);
    }

    try {
      if (new File("/tmp/sipx.properties").exists()) {
        System.getProperties().load(new FileInputStream(new File("/tmp/sipx.properties")));
      }
    } catch (Exception ex) {
      componentManager.getLog().error(ex);
      throw new SipXOpenfirePluginException("Error reading config file ", ex);
    }

    pluginManager = manager;
    ClassLoader classLoader = pluginManager.getPluginClassloader(this);
    classLoader.setPackageAssertionStatus("org.sipfoundry", true);
    Thread.currentThread().setContextClassLoader(classLoader);
    configurationPath = System.getProperty("conf.dir", "/etc/sipxpbx");
    parseConfigurationFile();
    initializeLogging();
    CallWatcher.setWatcherConfig(watcherConfig);
    /*
     * This initializes the SIP side of the show.
     */
    try {
      CallWatcher.pluginInit();
      log.info("completed init");
      ResourceStateChangeListener resourceStateChangeListener =
          new ResourceStateChangeListenerImpl(this);
      CallWatcher.getSubscriber().setResourceStateChangeListener(resourceStateChangeListener);
    } catch (Exception e) {
      log.error("Error initializing CallWatcher");
      throw new SipXOpenfirePluginException("Init error", e);
    }

    server = XMPPServer.getInstance();

    userManager = server.getUserManager();
    presenceManager = server.getPresenceManager();

    hostname = server.getServerInfo().getXMPPDomain();
    log.info("HostName = " + hostname);

    probedPresence = new ConcurrentHashMap<String, Presence>();
    componentJID = new JID(subdomain + "." + hostname);

    groupManager = GroupManager.getInstance();

    multiUserChatManager = server.getMultiUserChatManager();
    /*
     * Load up the database.
     */
    multiUserChatManager.start();
    log.info("hostname " + hostname);
    try {
      componentManager.addComponent(subdomain, this);
    } catch (Exception e) {
      componentManager.getLog().error(e);
      log.error(e);
      throw new SipXOpenfirePluginException("Init error", e);
    }

    String accountConfigurationFile = configurationPath + "/xmpp-account-info.xml";
    if (!new File(accountConfigurationFile).exists()) {
      System.err.println("User account file not found");
      throw new SipXOpenfirePluginException("Cannot find user accounts file");
    } else {
      this.accountsParser = new AccountsParser(accountConfigurationFile);
      this.accountsParser.startScanner();
    }
    // config and instantiate and the presence unifier used to gather all presence info

    PresenceUnifier.setPlugin(this);
    PresenceUnifier.getInstance();
    // add packet interceptor

    InterceptorManager.getInstance().addInterceptor(new MessagePacketInterceptor(this));
    log.info("plugin initializaton completed");
    log.info("DONE");
  }
 /** Remove this interceptor from the interceptor manager. */
 public void stop() {
   InterceptorManager.getInstance().removeInterceptor(this);
 }
示例#10
0
 /** Add this interceptor to the interceptor manager. */
 public void start() {
   InterceptorManager.getInstance().addInterceptor(this);
 }