Esempio n. 1
0
 @Override
 void sendPacketInternal(Packet packet) {
   if (DEBUG_ENABLED) {
     System.out.println("[SEND]: " + packet.toXML());
   }
   queue.add(packet);
 }
Esempio n. 2
0
  public static PubSubEvent getPubSubEvent(Packet packet) {
    if (log.isTraceEnabled()) log.trace("Getting pubsub from " + packet.toXML());

    PacketExtension ext = packet.getExtension("event", PubSubEventProvider.NS);
    if (ext == null) ext = packet.getExtension("x", PubSubEventProvider.NS);

    if (log.isTraceEnabled()) log.trace("Got " + (ext == null ? "nothing" : ext.toXML()));

    return (PubSubEvent) ext;
  }
 @Test
 public void verifyForm() throws Exception {
   FileTransferNegotiator fileNeg = FileTransferNegotiator.getInstanceFor(connection);
   try {
     fileNeg.negotiateOutgoingTransfer("me", "streamid", "file", 1024, null, 10);
   } catch (NoResponseException e) {
     // Ignore
   }
   Packet packet = connection.getSentPacket();
   String xml = packet.toXML().toString();
   assertTrue(xml.indexOf("var='stream-method' type='list-single'") != -1);
 }
Esempio n. 4
0
  /**
   * @see org.jivesoftware.smack.PacketListener#processPacket(org.jivesoftware.smack.packet.Packet)
   */
  public void processPacket(Packet packet) {
    if (logger.isDebugEnabled()) {
      logger.debug("processing packet: " + packet.toXML());
    }

    Work work = createWork(packet);
    try {
      getWorkManager().scheduleWork(work, WorkManager.INDEFINITE, null, connector);
    } catch (WorkException e) {
      logger.error("Xmpp Server receiver work failed: " + e.getMessage(), e);
    }
  }
 private static void sendToIndividualRecipients(
     Connection connection, Packet packet, List<String> to, List<String> cc, List<String> bcc) {
   if (to != null) {
     for (Iterator<String> it = to.iterator(); it.hasNext(); ) {
       String jid = it.next();
       packet.setTo(jid);
       connection.sendPacket(new PacketCopy(packet.toXML()));
     }
   }
   if (cc != null) {
     for (Iterator<String> it = cc.iterator(); it.hasNext(); ) {
       String jid = it.next();
       packet.setTo(jid);
       connection.sendPacket(new PacketCopy(packet.toXML()));
     }
   }
   if (bcc != null) {
     for (Iterator<String> it = bcc.iterator(); it.hasNext(); ) {
       String jid = it.next();
       packet.setTo(jid);
       connection.sendPacket(new PacketCopy(packet.toXML()));
     }
   }
 }
Esempio n. 6
0
  @Override
  public void processPacket(Packet packet) {
    if (smackXmpp == null) {
      logger.error("Not initialized");
      return;
    }

    if (packet instanceof ColibriConferenceIQ) {
      handleColibriIq((ColibriConferenceIQ) packet);
    } else if (packet instanceof MuteIq) {
      handleMuteIq((MuteIq) packet);
    } else if (packet instanceof RayoIqProvider.DialIq) {
      handleRayoIQ((RayoIqProvider.DialIq) packet);
    } else if (packet instanceof Message) {
      handleMessage((Message) packet);
    } else if (packet instanceof Presence) {
      handlePresence((Presence) packet);
    } else {
      logger.error("Unexpected packet: " + packet.toXML());
    }
  }
  public void processPacket(Packet packet) {
    Log.d(LOGTAG, "NotificationPacketListener.processPacket()...");
    Log.d(LOGTAG, "packet.toXML()=" + packet.toXML());

    if (packet instanceof NotificationIQ) {
      NotificationIQ notification = (NotificationIQ) packet;

      if (notification.getChildElementXML().contains("androidpn:iq:notification")) {
        Log.d(LOGTAG, "ChildElementXML=" + notification.getChildElementXML());

        String configID = notification.getConfigID();
        String devID = notification.getDeviceID();
        ArrayList<Resource> lists = notification.getResources();

        String notificationFrom = notification.getFrom();
        String packetId = notification.getPacketID();

        Intent intent = new Intent(Constants.ACTION_SHOW_NOTIFICATION);

        intent.putExtra(Constants.NOTIFICATION_CONFIGURATION, configID);
        intent.putExtra(Constants.NOTIFICATION_DEVICEID, devID);

        /*将resource list 放入bundle中,将bundle放入Intent中,进行传输*/
        Bundle bundle = new Bundle();
        bundle.putParcelableArrayList(Constants.NOTIFICATION_RESOURCES_LIST, lists);

        Log.d("NPListener", "put the lists to the bundle then to the intent~~");
        intent.putExtras(bundle);

        intent.putExtra(Constants.NOTIFICATION_FROM, notificationFrom);
        intent.putExtra(Constants.PACKET_ID, packetId);

        IQ result = NotificationIQ.createResultIQ(notification);
        xmppManager.getConnection().sendPacket(result);
        xmppManager.getContext().sendBroadcast(intent);
      }
    }
  }
Esempio n. 8
0
  /**
   * Processes a packet through the installed packet collectors and listeners and letting them
   * examine the packet to see if they are a match with the filter.
   *
   * @param packet the packet to process.
   */
  public void processPacket(Packet packet) {
    if (packet == null) {
      return;
    }

    // Loop through all collectors and notify the appropriate ones.
    for (PacketCollector collector : getPacketCollectors()) {
      collector.processPacket(packet);
    }

    if (DEBUG_ENABLED) {
      System.out.println("[RECV]: " + packet.toXML());
    }

    // Deliver the incoming packet to listeners.
    for (ListenerWrapper listenerWrapper : recvListeners.values()) {
      try {
        listenerWrapper.notifyListener(packet);
      } catch (NotConnectedException e) {
        e.printStackTrace();
      }
    }
  }
  @Override
  public void processPacket(Packet packet) {
    Log.d(LOGTAG, "NotificationPacketListener.processPacket()...");
    Log.d(LOGTAG, "packet.toXML()=" + packet.toXML());

    if (packet instanceof NotificationIQ) {
      NotificationIQ notification = (NotificationIQ) packet;

      if (notification.getChildElementXML().contains("pushserver:iq:notification")) {
        String notificationId = notification.getId();
        String notificationApiKey = notification.getApiKey();
        String notificationTitle = notification.getTitle();
        String notificationMessage = notification.getMessage();
        //                String notificationTicker = notification.getTicker();
        String notificationUri = notification.getUri();

        Intent intent = new Intent(Constants.ACTION_SHOW_NOTIFICATION);
        intent.putExtra(Constants.NOTIFICATION_ID, notificationId);
        intent.putExtra(Constants.NOTIFICATION_API_KEY, notificationApiKey);
        intent.putExtra(Constants.NOTIFICATION_TITLE, notificationTitle);
        intent.putExtra(Constants.NOTIFICATION_MESSAGE, notificationMessage);
        intent.putExtra(Constants.NOTIFICATION_URI, notificationUri);
        //                intent.setData(Uri.parse((new StringBuilder(
        //                        "notif://notification.androidpn.org/")).append(
        //                        notificationApiKey).append("/").append(
        //                        System.currentTimeMillis()).toString()));

        xmppManager.getContext().sendBroadcast(intent);

        NotificationReceivedIQ notificationReceivedIQ = new NotificationReceivedIQ();
        notificationReceivedIQ.setUuid(notificationId);
        notificationReceivedIQ.setType(IQ.Type.SET);
        xmppManager.getConnection().sendPacket(notificationReceivedIQ);
      }
    }
  }
  /*
   * Handle a single smack packet, discarding anything but Message.
   * @param packet The smack packet.
   * (non-Javadoc)
   * @see org.jivesoftware.smack.PacketListener#processPacket(org.jivesoftware.smack.packet.Packet)
   */
  @Override
  public void processPacket(Packet packet) {

    Log.i("processPacket", packet.toXML());
    if (packet instanceof Presence) {

      double inLat = 0, inLong = 0;
      boolean isMUC = false, isGEO = false;

      Presence presence = (Presence) packet;

      // In a MUC, the "FROM" is the Resource
      String presenceFrom = StringUtils.parseResource(presence.getFrom());
      String presenceTo = StringUtils.parseName(presence.getTo());

      // if presence packet is from yourself, just bail
      if (presenceFrom.equals(presenceTo)) return;

      for (PacketExtension extension : presence.getExtensions()) {
        if (extension instanceof GeoLoc) {
          GeoLoc loc = (GeoLoc) extension;

          inLat = loc.getLat();
          inLong = loc.getLon();

          isGEO = true;

          Log.d("CNL", "ERIK: GEOLOC EXTENSION FOUND, LAT: " + inLat);
        }
        if (extension instanceof MUCUser) {
          // MUCUser muc = (MUCUser) extension;   no need to create this object
          isMUC = true;

          Log.d("CNL", "ERIK: MUC EXTENSION FOUND, presence type=" + presence.getType());
        }
      }

      //  If a MUC available presence packet comes in, add/update database
      if (isMUC == true && presence.getType().toString().equals("available") && isGEO == true) {

        updateDatabase(presenceFrom, inLat, inLong, null);
      }

      // if a MUC Unavailable presence packet comes in, remove user from database
      else if (isMUC == true && presence.getType().toString().equals("unavailable")) {

        if (this.database.delete("user_info", "name='" + presenceFrom + "'", null) > 0) {
          Log.d("CNL", "ERIK: DATABASE UPDATED, USER " + presenceFrom + " DELETED");
        } else Log.d("CNL", "ERIK: DATABASE SEARCHED, USER " + presenceFrom + " NOT FOUND");
      }
    }

    if (packet instanceof IQ) {
      IQ iq = (IQ) packet;
      Log.d("CNL", "ERIK: IQ PACKET RECEIVED: " + iq.getExtensions());
    }

    if (packet instanceof Message) {
      Message msg = (Message) packet;
      String text = msg.getBody();

      if (text == null || text.trim().length() == 0) {
        Log.d("CNL", "ERIK: MESSAGE PACKET LACKS A MESSAGE!!!");
        return;
      }

      // Extract name
      String messageFrom = StringUtils.parseResource(msg.getFrom());

      // Extract lat and lon from message
      double inLat = getLat(msg);
      double inLon = getLon(msg);
      Boolean isEmergency = null;
      if (text.startsWith(this.context.getString(R.string.emergency_message))) {
        isEmergency = Boolean.TRUE;
      } else if (text.startsWith(this.context.getString(R.string.cancel_message))) {
        isEmergency = Boolean.FALSE;
      }

      Log.i("CNL", "recovered name=[" + messageFrom + "], lat/lon=" + inLat + "," + inLon);

      updateDatabase(messageFrom, inLat, inLon, isEmergency);

      String bareFrom = XMPPUtils.getBareJid(msg.getFrom());
      String msgFrom = StringUtils.parseResource(msg.getFrom());
      String bareTo = XMPPUtils.getBareJid(msg.getTo());
      String msgTo = StringUtils.parseName(msg.getTo());

      if (msg.getType().toString().equals("groupchat")) {
        Log.d(
            "CNL",
            "ERIK: MUC MESSAGE PACKET RECEIVED, CONTAINS EXTENSIONS: " + msg.getExtensions());
        if (msgFrom.equals(msgTo)) return;

        // Picture receiving code here.............................!!!!!!!!!!

        for (PacketExtension extension : msg.getExtensions()) {
          if (extension instanceof DataPacketExtension) {
            DataPacketExtension data = (DataPacketExtension) extension;

            byte[] imageBytes = data.getDecodedData();
            String imagePath = Environment.getExternalStorageDirectory() + "/mmmc/";

            // String imageName = text;
            File f = new File(imagePath, text);
            OutputStream out = null;

            try {
              out = new BufferedOutputStream(new FileOutputStream(f));
              out.write(imageBytes);
            } catch (IOException ioe) {
              ioe.printStackTrace();
            } finally {
              if (out != null) {
                try {
                  out.close();
                } catch (IOException e) {
                  e.printStackTrace();
                }
              }
            }

            // Log.d("CNL", "ERIK: MUC EXTENSION FOUND");
            ContentValues values = new ContentValues();
            values.put("ts", System.currentTimeMillis());
            values.put("jid", bareFrom);

            // don't put who it's from, put the resource it came from (user in a MUC)
            values.put("src", msgFrom);

            values.put("dst", msg.getTo());
            values.put("via", bareTo);
            values.put("msg", "Picture received: " + text.trim());
            this.database.insert("msg", "_id", values);

            Log.d("CNL", "ERIK: DATA EXTENSION FOUND, IMAGE SAVED");
            return;
          }
        }

        // Log.d("CNL", "ERIK: MUC EXTENSION FOUND");

        // Insert new message into database
        ContentValues values = new ContentValues();
        values.put("ts", System.currentTimeMillis());
        values.put("jid", bareFrom);

        // don't put who it's from, put the resource it came from (user in a MUC)
        values.put("src", msgFrom);

        values.put("dst", msg.getTo());
        values.put("via", bareTo);
        values.put("msg", text.trim());
        this.database.insert("msg", "_id", values);
      } else Log.d("CNL", "ERIK: NON-MUC MESSAGE PACKET RECEIVED: " + bareFrom);

      Builder builder = new Uri.Builder();
      builder.scheme("content");
      builder.authority("jabber-chat-db");
      builder.appendPath(bareTo);
      builder.appendPath(bareFrom);
      this.context.getContentResolver().notifyChange(builder.build(), null);
      setNotification(bareFrom, bareTo);
    }
  }