@Override public Queue<Packet> processSocketData(XMPPIOService<Object> srv) { BoshIOService serv = (BoshIOService) srv; Packet p = null; while ((p = serv.getReceivedPackets().poll()) != null) { Queue<Packet> out_results = new ArrayDeque<Packet>(2); BoshSession bs = null; String sid_str = null; synchronized (sessions) { if (log.isLoggable(Level.FINER)) { log.log( Level.FINER, "Processing packet: {0}, type: {1}", new Object[] {p.getElemName(), p.getType()}); } if (log.isLoggable(Level.FINEST)) { log.log(Level.FINEST, "Processing socket data: {0}", p); } sid_str = p.getAttributeStaticStr(SID_ATTR); UUID sid = null; if (sid_str == null) { String hostname = p.getAttributeStaticStr(Packet.TO_ATT); if ((hostname != null) && isLocalDomain(hostname)) { if (!isAllowed(srv, hostname)) { if (log.isLoggable(Level.FINE)) { log.log(Level.FINE, "Policy violation. Closing connection: {0}", p); } try { serv.sendErrorAndStop(Authorization.NOT_ALLOWED, p, "Policy violation."); } catch (IOException e) { log.log( Level.WARNING, "Problem sending invalid hostname error for sid = " + sid, e); } } else { bs = new BoshSession( getDefVHostItem().getDomain(), JID.jidInstanceNS(routings.computeRouting(hostname)), this, sendNodeHostname ? getDefHostName().getDomain() : null, maxSessionWaitingPackets); sid = bs.getSid(); sessions.put(sid, bs); if (log.isLoggable(Level.FINE)) { log.log( Level.FINE, "{0} : {1} ({2})", new Object[] {BOSH_OPERATION_TYPE.CREATE, sid, "Socket bosh session"}); } } } else { try { serv.sendErrorAndStop(Authorization.NOT_ALLOWED, p, "Invalid hostname."); } catch (IOException e) { log.log(Level.WARNING, "Problem sending invalid hostname error for sid = " + sid, e); } } } else { try { sid = UUID.fromString(sid_str); bs = sessions.get(sid); } catch (IllegalArgumentException e) { log.log( Level.WARNING, "Problem processing socket data, sid = " + sid_str + " does not conform to the UUID string representation.", e); } } } try { if (bs != null) { synchronized (bs) { if (sid_str == null) { bs.init( p, serv, max_wait, min_polling, max_inactivity, concurrent_requests, hold_requests, max_pause, max_batch_size, batch_queue_timeout, out_results); } else { bs.processSocketPacket(p, serv, out_results); } } } else { if (log.isLoggable(Level.FINE)) { log.log( Level.FINE, "{0} : {1} ({2})", new Object[] {BOSH_OPERATION_TYPE.INVALID_SID, sid_str, "Invalid SID"}); } serv.sendErrorAndStop(Authorization.ITEM_NOT_FOUND, p, "Invalid SID"); } addOutPackets(out_results, bs); } catch (IOException e) { log.log(Level.WARNING, "Problem processing socket data for sid = " + sid_str, e); } // addOutPackets(out_results); } // end of while () return null; }
protected Map<String, String> preBindSession(Map<String, String> attr) { String hostname = attr.get(TO_ATTR); Queue<Packet> out_results = new ArrayDeque<Packet>(2); BoshSession bs = new BoshSession( getDefVHostItem().getDomain(), JID.jidInstanceNS(routings.computeRouting(hostname)), this, sendNodeHostname ? getDefHostName().getDomain() : null, maxSessionWaitingPackets); String jid = attr.get(FROM_ATTR); String uuid = UUID.randomUUID().toString(); JID userId = JID.jidInstanceNS(jid); if (null == userId.getResource()) { userId = userId.copyWithResourceNS(uuid); attr.put(FROM_ATTR, userId.toString()); bs.setUserJid(jid); } long rid = (long) (Math.random() * 10000000); attr.put(RID_ATTR, Long.toString(rid)); UUID sid = bs.getSid(); sessions.put(sid, bs); if (log.isLoggable(Level.FINE)) { log.log( Level.FINE, "{0} : {1} ({2})", new Object[] {BOSH_OPERATION_TYPE.CREATE, bs.getSid(), "Pre-bind"}); } attr.put(SID_ATTR, sid.toString()); Packet p = null; try { Element el = new Element("body"); el.setAttributes(attr); p = Packet.packetInstance(el); } catch (TigaseStringprepException ex) { Logger.getLogger(BoshConnectionManager.class.getName()).log(Level.SEVERE, null, ex); } bs.init( p, null, max_wait, min_polling, max_inactivity, concurrent_requests, hold_requests, max_pause, max_batch_size, batch_queue_timeout, out_results, true); addOutPackets(out_results, bs); attr.put("hostname", getDefHostName().toString()); return attr; }