protected Channel getNonSerializedChannel(Channel serChannel) {

    for (IdentityMediationUnit idu : idauRegistry.getIdentityMediationUnits()) {
      for (Channel c : idu.getChannels()) {
        if (c.getName().equals(serChannel.getName())) return c;
      }
    }

    return null;
  }
예제 #2
0
 public void renameChannel(Channel channel, String newName) throws Exception {
   synchronized (channelStatus) {
     luceneUpdater.renameChannel(channel.getName(), newName);
     new File(configFilesDir, channel.getName() + ".config").delete();
     ChannelStatus cStatus = channelStatus.remove(channel.getName());
     if (cStatus != null) {
       channel.setName(newName);
       cStatus.channel(channel);
       channelStatus.put(newName, cStatus);
       saveChannel(channel);
     }
   }
 }
예제 #3
0
  protected void onStop() {
    log.info("Closing all active channels");

    try {
      Channel channel;

      for (Iterator x = activeChannels.values().iterator(); x.hasNext(); ) {
        channel = (Channel) x.next();

        if (channel != null) {
          if (log.isDebugEnabled()) {
            log.debug(
                "Closing "
                    + channel.getName()
                    + " id="
                    + String.valueOf(channel.getLocalChannelId()));
          }

          channel.close();
        }
      }
    } catch (Throwable t) {
    }

    activeChannels.clear();
  }
예제 #4
0
  /**
   * @param channel
   * @param eventListener
   * @return
   * @throws IOException
   * @throws SshException
   */
  public synchronized boolean openChannel(Channel channel, ChannelEventListener eventListener)
      throws IOException {
    synchronized (activeChannels) {
      Long channelId = getChannelId();

      // Create the message
      SshMsgChannelOpen msg =
          new SshMsgChannelOpen(
              channel.getChannelType(),
              channelId.longValue(),
              channel.getLocalWindow().getWindowSpace(),
              channel.getLocalPacketSize(),
              channel.getChannelOpenData());

      // Send the message
      transport.sendMessage(msg, this);

      // Wait for the next message to confirm the open channel (or not)
      int[] messageIdFilter = new int[2];
      messageIdFilter[0] = SshMsgChannelOpenConfirmation.SSH_MSG_CHANNEL_OPEN_CONFIRMATION;
      messageIdFilter[1] = SshMsgChannelOpenFailure.SSH_MSG_CHANNEL_OPEN_FAILURE;

      try {
        SshMessage result = messageStore.getMessage(messageIdFilter);

        if (result.getMessageId()
            == SshMsgChannelOpenConfirmation.SSH_MSG_CHANNEL_OPEN_CONFIRMATION) {
          SshMsgChannelOpenConfirmation conf = (SshMsgChannelOpenConfirmation) result;
          activeChannels.put(channelId, channel);
          log.debug("Initiating channel");
          channel.init(
              this,
              channelId.longValue(),
              conf.getSenderChannel(),
              conf.getInitialWindowSize(),
              conf.getMaximumPacketSize(),
              eventListener);
          channel.open();
          log.info(
              "Channel "
                  + String.valueOf(channel.getLocalChannelId())
                  + " is open ["
                  + channel.getName()
                  + "]");

          return true;
        } else {
          // Make sure the channels state is closed
          channel.getState().setValue(ChannelState.CHANNEL_CLOSED);

          return false;
        }
      } catch (MessageStoreEOFException mse) {
        throw new IOException(mse.getMessage());
      } catch (InterruptedException ex) {
        throw new SshException(
            "The thread was interrupted whilst waiting for a connection protocol message");
      }
    }
  }
예제 #5
0
 /**
  * Returns channel with given name
  *
  * @param name Name of the wanted channel
  * @return Channel with given name
  */
 public Channel getChannel(String name) {
   Iterator<Channel> i = channels.iterator();
   while (i.hasNext()) {
     Channel c = i.next();
     if (name.equals(c.getName())) return c;
   }
   return null;
 }
예제 #6
0
 public void saveChannel(Channel channel) throws Exception {
   synchronized (channelStatus) {
     FileOutputStream out =
         new FileOutputStream(
             new File(Config.getInstance().configFilesDir, channel.getName() + ".config"));
     try {
       saveChannel(channel, out);
       if (!channelStatus.containsKey(channel.getName())) {
         ChannelStatus cStatus = new ChannelStatus();
         cStatus.channel(channel);
         channelStatus.put(channel.getName(), cStatus);
       }
     } finally {
       IOUtils.closeQuietly(out);
     }
   }
 }
예제 #7
0
 public ChannelOrderLog(MerchantOrder order, Channel channel, String content) {
   this.orderId = order.getId();
   this.content = content;
   this.creatorId = channel.getId();
   this.createdDate = new Date();
   this.creatorName = channel.getName();
   this.creatorType = MerchantOrder.UserType.CHANNEL;
 }
예제 #8
0
  public void handleMessage(IrcMessage message) {
    try {
      SQLiteDatabase database = getWritableDatabase();

      String channelName = message.getLogicalChannel();
      List<Channel> channels = getChannels(database);

      int biggestOrder = 0;
      Channel found = null;
      for (Channel ch : channels) {
        biggestOrder = Math.max(biggestOrder, ch.getOrder() + 1);
        if (ch.getName().equals(channelName)) {
          found = ch;
          break;
        }
      }

      long channelId;
      if (found == null) {
        ContentValues values = new ContentValues();
        values.put("name", channelName);
        values.put("orderIndex", biggestOrder);
        channelId = database.insert("Channel", null, values);
      } else {
        channelId = found.getId();
      }

      ContentValues messageValues = new ContentValues();
      messageValues.put("channelId", channelId);
      messageValues.put("message", message.getMessage());
      messageValues.put("nick", message.getNick());
      messageValues.put("serverTimestamp", message.getServerTimestamp().getTime());
      messageValues.put("externalId", message.getExternalId());

      Cursor cur =
          database.query(
              "IrcMessage",
              new String[] {"externalId", "message"},
              "externalId = ?",
              new String[] {message.getExternalId()},
              null,
              null,
              null,
              "1");
      if (cur.isAfterLast()) {
        messageValues.put("shown", 0);
        database.insert("IrcMessage", null, messageValues);
      } else {
        // already in database, update if necessary
        database.update(
            "IrcMessage", messageValues, "externalId = ?", new String[] {message.getExternalId()});
      }
      cur.close();
      database.close();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
예제 #9
0
  public void updateChannel(Channel channel) {
    SQLiteDatabase database = getWritableDatabase();

    ContentValues values = new ContentValues();
    values.put("name", channel.getName());
    values.put("orderIndex", channel.getOrder());

    database.update("Channel", values, "id = ?", new String[] {Long.toString(channel.getId())});
    database.close();
  }
예제 #10
0
 /**
  * @param channel
  * @throws IOException
  */
 protected void closeChannel(Channel channel) throws IOException {
   SshMsgChannelClose msg = new SshMsgChannelClose(channel.getRemoteChannelId());
   log.info(
       "Local computer has closed channel "
           + String.valueOf(channel.getLocalChannelId())
           + "["
           + channel.getName()
           + "]");
   transport.sendMessage(msg, this);
 }
예제 #11
0
  public void initialize() throws Exception {
    configFilesDir.mkdirs();
    luceneFilesDirectory.mkdirs();
    tempDirectory.mkdirs();

    luceneUpdater.open(luceneFilesDirectory);
    List<Channel> channels = loadChannels();
    for (Channel channel : channels) {
      ChannelStatus cStatus = new ChannelStatus();
      cStatus.channel(channel);
      channelStatus.put(channel.getName(), cStatus);
    }
  }
예제 #12
0
  /** @param channel */
  protected void freeChannel(Channel channel) {
    synchronized (activeChannels) {
      log.info(
          "Freeing channel "
              + String.valueOf(channel.getLocalChannelId())
              + " ["
              + channel.getName()
              + "]");

      Long channelId = new Long(channel.getLocalChannelId());
      activeChannels.remove(channelId);

      // reusableChannels.add(channelId);
    }
  }
예제 #13
0
  private void onMsgChannelEOF(SshMsgChannelEOF msg) throws IOException {
    Channel channel = getChannel(msg.getRecipientChannel());

    try {
      log.info(
          "Remote computer has set channel "
              + String.valueOf(msg.getRecipientChannel())
              + " to EOF ["
              + channel.getName()
              + "]");
      channel.setRemoteEOF();
    } catch (IOException ioe) {
      log.info("Failed to close the ChannelInputStream after EOF event");
    }
  }
예제 #14
0
  private List<IrcMessage> getMessagesForChannel(SQLiteDatabase database, Channel channel) {
    Cursor cursor =
        database.query(
            "IrcMessage",
            new String[] {
              "message", "nick", "serverTimestamp", "shown", "externalId", "clearedFromFeed", "id"
            },
            "channelId = ?",
            new String[] {Long.toString(channel.getId())},
            null,
            null,
            "serverTimestamp DESC",
            "100");
    cursor.moveToFirst();
    List<IrcMessage> list = new ArrayList<IrcMessage>();

    int colMessage = cursor.getColumnIndex("message");
    int colNick = cursor.getColumnIndex("nick");
    int colServerTimestamp = cursor.getColumnIndex("serverTimestamp");
    int colExternalId = cursor.getColumnIndex("externalId");
    int colShown = cursor.getColumnIndex("shown");
    int colClearedFromFeed = cursor.getColumnIndex("clearedFromFeed");
    int colId = cursor.getColumnIndex("id");

    while (!cursor.isAfterLast()) {
      IrcMessage message = new IrcMessage();
      message.setMessage(cursor.getString(colMessage));
      message.setNick(cursor.getString(colNick));
      message.setServerTimestamp(cursor.getLong(colServerTimestamp));
      message.setExternalId(cursor.getString(colExternalId));
      message.setChannel(channel.getName());
      message.setShown(cursor.getInt(colShown) == 0 ? false : true);
      message.setClearedFromFeed(cursor.getInt(colClearedFromFeed) == 0 ? false : true);
      message.setId(cursor.getLong(colId));

      list.add(message);
      cursor.moveToNext();
    }

    cursor.close();
    Collections.reverse(list);
    return list;
  }
예제 #15
0
  /**
   * @param channel
   * @throws IOException
   */
  public void sendChannelEOF(Channel channel) throws IOException {
    synchronized (activeChannels) {
      if (!activeChannels.containsValue(channel)) {
        throw new IOException(
            "Attempt to send EOF for a non existent channel "
                + String.valueOf(channel.getLocalChannelId()));
      }

      log.info(
          "Local computer has set channel "
              + String.valueOf(channel.getLocalChannelId())
              + " to EOF ["
              + channel.getName()
              + "]");

      SshMsgChannelEOF msg = new SshMsgChannelEOF(channel.getRemoteChannelId());
      transport.sendMessage(msg, this);
    }
  }
예제 #16
0
 private void joinLeave(MessageContext context, String args) {
   if (args.isEmpty()) {
     return;
   }
   args = args.toLowerCase();
   String[] split = args.split(" ");
   String cid = split[0];
   JoinLeave target = JoinLeave.BOTH;
   if (split.length != 1) {
     String jlStr = split[1].toLowerCase();
     for (JoinLeave joinLeave : JoinLeave.values()) {
       if (joinLeave.name().toLowerCase().startsWith(jlStr)) {
         target = joinLeave;
         break;
       }
     }
   }
   if ("default".equals(cid)) {
     cid = context.getServer().getId();
   } else if ("this".equals(cid)) {
     cid = context.getChannel().getId();
   }
   Channel channel = apiClient.getChannelById(cid);
   if (channel != NO_CHANNEL) {
     if (target == JoinLeave.JOIN) {
       bot.getEventListener().joinMessageRedirect.put(context.getServer().getId(), cid);
     }
     if (target == JoinLeave.LEAVE) {
       bot.getEventListener().leaveMessageRedirect.put(context.getServer().getId(), cid);
     }
     if (target == JoinLeave.BOTH) {
       bot.getEventListener().joinMessageRedirect.put(context.getServer().getId(), cid);
       bot.getEventListener().leaveMessageRedirect.put(context.getServer().getId(), cid);
     }
     apiClient.sendMessage(
         loc.localize("commands.mod.jl.response", channel.getName(), channel.getId()),
         context.getChannel());
   } else {
     apiClient.sendMessage(loc.localize("commands.mod.jl.response.invalid"), context.getChannel());
   }
 }
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.menu_irssi_connectbot) {
      IrssiConnectbotLauncher.launchIrssiConnectbot(this);
      // MessageGenerator.Flood(this);
    } else if (item.getItemId() == R.id.menu_settings) {
      Intent settingsActivity = new Intent(this, SettingsActivity.class);
      startActivity(settingsActivity);
    } else if (item.getItemId() == R.id.menu_clear_channel) {
      DataAccess da = new DataAccess(this);
      List<Channel> channels = da.getChannels();
      Channel channelToClear = null;

      if (channelToView == null) return true;

      if (channelToView.equals(FEED)) {
        da.clearAllMessagesFromFeed();
        startMainApp(true);
        return true;
      }

      for (Channel ch : channels) {
        if (ch.getName().equalsIgnoreCase(channelToView)) {
          channelToClear = ch;
          break;
        }
      }
      if (channelToClear != null) {
        da.clearChannel(channelToClear);
        startMainApp(true);
      }
    } else if (item.getItemId() == R.id.menu_remove_all_channels) {
      DataAccess da = new DataAccess(this);
      da.clearAll();
      startMainApp(true);
    }
    return true;
  }
예제 #18
0
  private void onMsgChannelClose(SshMsgChannelClose msg) throws IOException {
    Channel channel = getChannel(msg.getRecipientChannel());

    // If we have not already closed it then inform the subclasses
    if (channel == null) {
      throw new IOException(
          "Remote computer tried to close a "
              + "non existent channel "
              + String.valueOf(msg.getRecipientChannel()));
    }

    log.info(
        "Remote computer has closed channel "
            + String.valueOf(channel.getLocalChannelId())
            + "["
            + channel.getName()
            + "]");

    // If the channel is not already closed then close it
    if (channel.getState().getValue() != ChannelState.CHANNEL_CLOSED) {
      channel.remoteClose();
    }
  }
예제 #19
0
 public void part(Channel c) {
   if (auto_join.contains(c.getName())) {
     sendMessage(c.getColoredName() + " removed from Auto-Join list.");
   }
   auto_join.remove(c.getName());
 }
예제 #20
0
 public void join(Channel c) {
   if (!auto_join.contains(c.getName())) {
     sendMessage(c.getColoredName() + " added to Auto-Join list.");
   }
   auto_join.add(c.getName());
 }
예제 #21
0
  public BrokerHost addChannel(Channel channel) {
    lock.lock();
    try {
      // add the channel and return the broker host
      Manageable manageable;
      if (channel.getDirection() == Direction.OUT) {
        BrokerHost host = brokerHosts.get(brokerIndex);
        List<Channel> producerChannels = brokerHostToProducerChannelMap.get(host);
        BlockingQueue<MessageContext> channelOutQueue = producerQueues.get(host);

        if (!producers.containsKey(host)) {
          manageable =
              transport.registerProducer(
                  host, prefix, channel.getProperties(), producerQueues.get(host));
          producers.put(host, manageable);

          manageable.start();
        }

        // now register the channel with the brokers map
        // check weather you have a sender consumer for this host
        channel.setOutQueue(channelOutQueue);
        producerChannels.add(channel);
        producerChannels.add(new Channel("", Direction.OUT));

        LOG.info(
            "Registering channel {} with group {} and host {}",
            channel.getName(),
            name,
            host.toString());
        incrementProducerIndex();

        return host;

      } else if (channel.getDirection() == Direction.IN) {
        BrokerHost host = brokerHosts.get(brokerIndex);
        List<Channel> consumerChannels = brokerHostToConsumerChannelMap.get(host);
        if (!consumers.containsKey(host)) {
          BlockingQueue<MessageContext> channelInQueue = consumerQueues.get(host);
          manageable =
              transport.registerConsumer(host, prefix, channel.getProperties(), channelInQueue);
          consumers.put(host, manageable);

          ConsumingWorker worker;
          if (channel.isGrouped()) {
            worker = new ConsumingWorker(consumerChannels, channelInQueue);
          } else {
            worker = new ConsumingWorker(consumerChannels, channelInQueue, true);
          }
          Thread thread = new Thread(worker);
          thread.start();

          manageable.start();

          consumingWorkers.put(host, worker);
        }

        // now register the channel with the brokers map
        // check weather you have a sender consumer for this host
        consumerChannels.add(channel);

        LOG.info(
            "Registering channel {} with group {} and host {}",
            channel.getName(),
            name,
            host.toString());
        incrementConsumerIndex();

        return host;
      }
    } finally {
      lock.unlock();
    }
    return null;
  }
예제 #22
0
 public int foo() {
   System.out.println("<< foo method invoked on " + ch.getName());
   return i;
 }