private void handleRayoIQ(RayoIqProvider.DialIq dialIq) { String from = dialIq.getFrom(); JitsiMeetConference conference = getConferenceForMucJid(from); if (conference == null) { logger.debug("Mute error: room not found for JID: " + from); return; } ChatRoomMemberRole role = conference.getRoleForMucJid(from); if (role == null) { // Only room members are allowed to send requests IQ error = createErrorResponse(dialIq, new XMPPError(XMPPError.Condition.forbidden)); smackXmpp.getXmppConnection().sendPacket(error); return; } if (ChatRoomMemberRole.MODERATOR.compareTo(role) < 0) { // Moderator permission is required IQ error = createErrorResponse(dialIq, new XMPPError(XMPPError.Condition.not_allowed)); smackXmpp.getXmppConnection().sendPacket(error); return; } // Check if Jigasi is available String jigasiJid = conference.getServices().getSipGateway(); if (StringUtils.isNullOrEmpty(jigasiJid)) { // Not available IQ error = createErrorResponse(dialIq, new XMPPError(XMPPError.Condition.service_unavailable)); smackXmpp.getXmppConnection().sendPacket(error); return; } // Redirect original request to Jigasi component String originalPacketId = dialIq.getPacketID(); dialIq.setFrom(null); dialIq.setTo(jigasiJid); dialIq.setPacketID(IQ.nextID()); IQ reply = (IQ) smackXmpp.getXmppConnection().sendPacketAndGetReply(dialIq); // Send Jigasi response back to the client reply.setFrom(null); reply.setTo(from); reply.setPacketID(originalPacketId); smackXmpp.getXmppConnection().sendPacket(reply); }
/** * A convenience method to create an IQ packet. * * @param ID The packet ID of the * @param to To whom the packet is addressed. * @param from From whom the packet is sent. * @param type The IQ type of the packet. * @return The created IQ packet. */ public static IQ createIQ( final String ID, final String to, final String from, final IQ.Type type) { final IQ iqPacket = new IQ() { @Override public String getChildElementXML() { return null; } }; iqPacket.setPacketID(ID); iqPacket.setTo(to); iqPacket.setFrom(from); iqPacket.setType(type); return iqPacket; }
/** * Convenience method to create a new empty {@link Type#RESULT IQ.Type.RESULT} IQ based on a * {@link Type#GET IQ.Type.GET} or {@link Type#SET IQ.Type.SET} IQ. The new packet will be * initialized with: * * <ul> * <li>The sender set to the recipient of the originating IQ. * <li>The recipient set to the sender of the originating IQ. * <li>The type set to {@link Type#RESULT IQ.Type.RESULT}. * <li>The id set to the id of the originating IQ. * <li>No child element of the IQ element. * </ul> * * @param iq the {@link Type#GET IQ.Type.GET} or {@link Type#SET IQ.Type.SET} IQ packet. * @throws IllegalArgumentException if the IQ packet does not have a type of {@link Type#GET * IQ.Type.GET} or {@link Type#SET IQ.Type.SET}. * @return a new {@link Type#RESULT IQ.Type.RESULT} IQ based on the originating IQ. */ public static IQ createResultIQ(final IQ request) { if (!(request.getType() == Type.GET || request.getType() == Type.SET)) { throw new IllegalArgumentException( "IQ must be of type 'set' or 'get'. Original IQ: " + request.toXML()); } final IQ result = new IQ() { public String getChildElementXML() { return null; } }; result.setType(Type.RESULT); result.setPacketID(request.getPacketID()); result.setFrom(request.getTo()); result.setTo(request.getFrom()); return result; }
/** * Convenience method to create a new {@link Type#ERROR IQ.Type.ERROR} IQ based on a {@link * Type#GET IQ.Type.GET} or {@link Type#SET IQ.Type.SET} IQ. The new packet will be initialized * with: * * <ul> * <li>The sender set to the recipient of the originating IQ. * <li>The recipient set to the sender of the originating IQ. * <li>The type set to {@link Type#ERROR IQ.Type.ERROR}. * <li>The id set to the id of the originating IQ. * <li>The child element contained in the associated originating IQ. * <li>The provided {@link XMPPError XMPPError}. * </ul> * * @param iq the {@link Type#GET IQ.Type.GET} or {@link Type#SET IQ.Type.SET} IQ packet. * @param error the error to associate with the created IQ packet. * @throws IllegalArgumentException if the IQ packet does not have a type of {@link Type#GET * IQ.Type.GET} or {@link Type#SET IQ.Type.SET}. * @return a new {@link Type#ERROR IQ.Type.ERROR} IQ based on the originating IQ. */ public static IQ createErrorResponse(final IQ request, final XMPPError error) { if (!(request.getType() == Type.GET || request.getType() == Type.SET)) { throw new IllegalArgumentException( "IQ must be of type 'set' or 'get'. Original IQ: " + request.toXML()); } final IQ result = new IQ() { public String getChildElementXML() { return request.getChildElementXML(); } }; result.setType(Type.ERROR); result.setPacketID(request.getPacketID()); result.setFrom(request.getTo()); result.setTo(request.getFrom()); result.setError(error); return result; }
/** * FIXME: replace with IQ.createErrorResponse Prosody does not allow to include request body in * error response. Replace this method with IQ.createErrorResponse once fixed. */ private IQ createErrorResponse(IQ request, XMPPError error) { IQ.Type requestType = request.getType(); if (!(requestType == IQ.Type.GET || requestType == IQ.Type.SET)) { throw new IllegalArgumentException( "IQ must be of type 'set' or 'get'. Original IQ: " + request.toXML()); } final IQ result = new IQ() { @Override public String getChildElementXML() { return ""; } }; result.setType(IQ.Type.ERROR); result.setPacketID(request.getPacketID()); result.setFrom(request.getTo()); result.setTo(request.getFrom()); result.setError(error); return result; }
/** * Parses an IQ packet. * * @param parser the XML parser, positioned at the start of an IQ packet. * @return an IQ object. * @throws Exception if an exception occurs while parsing the packet. */ public static IQ parseIQ(XmlPullParser parser, Connection connection) throws Exception { IQ iqPacket = null; String id = parser.getAttributeValue("", "id"); String to = parser.getAttributeValue("", "to"); String from = parser.getAttributeValue("", "from"); IQ.Type type = IQ.Type.fromString(parser.getAttributeValue("", "type")); XMPPError error = null; boolean done = false; while (!done) { int eventType = parser.next(); if (eventType == XmlPullParser.START_TAG) { String elementName = parser.getName(); String namespace = parser.getNamespace(); if (elementName.equals("error")) { error = PacketParserUtils.parseError(parser); } else if (elementName.equals("query") && namespace.equals("jabber:iq:auth")) { iqPacket = parseAuthentication(parser); } else if (elementName.equals("query") && namespace.equals("jabber:iq:roster")) { iqPacket = parseRoster(parser); } else if (elementName.equals("query") && namespace.equals("jabber:iq:register")) { iqPacket = parseRegistration(parser); } else if (elementName.equals("bind") && namespace.equals("urn:ietf:params:xml:ns:xmpp-bind")) { iqPacket = parseResourceBinding(parser); } // Otherwise, see if there is a registered provider for // this element name and namespace. else { Object provider = ProviderManager.getInstance().getIQProvider(elementName, namespace); if (provider != null) { if (provider instanceof IQProvider) { iqPacket = ((IQProvider) provider).parseIQ(parser); } else if (provider instanceof Class) { iqPacket = (IQ) PacketParserUtils.parseWithIntrospection( elementName, (Class<?>) provider, parser); } } // Only handle unknown IQs of type result. Types of 'get' and 'set' which are not // understood // have to be answered with an IQ error response. See the code a few lines below else if (IQ.Type.RESULT == type) { // No Provider found for the IQ stanza, parse it to an UnparsedIQ instance // so that the content of the IQ can be examined later on iqPacket = new UnparsedResultIQ(parseContent(parser)); } } } else if (eventType == XmlPullParser.END_TAG) { if (parser.getName().equals("iq")) { done = true; } } } // Decide what to do when an IQ packet was not understood if (iqPacket == null) { if (IQ.Type.GET == type || IQ.Type.SET == type) { // If the IQ stanza is of type "get" or "set" containing a child element // qualified by a namespace it does not understand, then answer an IQ of // type "error" with code 501 ("feature-not-implemented") iqPacket = new IQ() { @Override public String getChildElementXML() { return null; } }; iqPacket.setPacketID(id); iqPacket.setTo(from); iqPacket.setFrom(to); iqPacket.setType(IQ.Type.ERROR); iqPacket.setError(new XMPPError(XMPPError.Condition.feature_not_implemented)); connection.sendPacket(iqPacket); return null; } else { // If an IQ packet wasn't created above, create an empty IQ packet. iqPacket = new IQ() { @Override public String getChildElementXML() { return null; } }; } } // Set basic values on the iq packet. iqPacket.setPacketID(id); iqPacket.setTo(to); iqPacket.setFrom(from); iqPacket.setType(type); iqPacket.setError(error); return iqPacket; }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); originSharedPrefs = this.getSharedPreferences(Constants.SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE); DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm); // 屏幕宽 mobileWidthPix = dm.widthPixels; // 屏幕高 mobileHeightPix = dm.heightPixels; density = dm.density; // 屏幕密度(0.75/1.0/1.5) Log.i("xiaobingo", "density是:" + density); // densityDPI = dm.densityDpi; //屏幕密度DPI (120/160/240) mobileWidth = (int) (mobileWidthPix / density + 0.5f); mobileHeight = (int) (mobileHeightPix / density + 0.5f); Log.i("xiaobingo", "屏幕宽:" + mobileWidth); Log.i("xiaobingo", "屏幕高:" + mobileHeight); SharedPreferences sharedPrefs = this.getSharedPreferences(Constants.SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE); callbackActivityPackageName = sharedPrefs.getString(Constants.CALLBACK_ACTIVITY_PACKAGE_NAME, ""); callbackActivityClassName = sharedPrefs.getString(Constants.CALLBACK_ACTIVITY_CLASS_NAME, ""); Log.i(LOGTAG, "callbackActivity是:" + callbackActivityClassName); context = Constants.xmppManager.getContext(); Intent intent = getIntent(); if (intent.getStringExtra("ItemTitle") != null) { // 来自主页面DemoAppActivity点击单项的intent,不是通知页面Notifier转过来的intent Bundle bundle = this.getIntent().getExtras(); notificationTitle = bundle.getString("ItemTitle"); notificationMessage = bundle.getString("ItemMessage"); notificationUri = bundle.getString("ItemUri"); } else { // 来自通知页面Notifier传来的intent,需要增加userInfo内容 notificationId = intent.getStringExtra(Constants.NOTIFICATION_ID); notificationApiKey = intent.getStringExtra(Constants.NOTIFICATION_API_KEY); notificationTitle = intent.getStringExtra(Constants.NOTIFICATION_TITLE); notificationMessage = intent.getStringExtra(Constants.NOTIFICATION_MESSAGE); notificationUri = intent.getStringExtra(Constants.NOTIFICATION_URI); notificationFrom = intent.getStringExtra(Constants.NOTIFICATION_FROM); packetId = intent.getStringExtra(Constants.PACKET_ID); Log.d(LOGTAG, "notificationId=" + notificationId); Log.d(LOGTAG, "notificationApiKey=" + notificationApiKey); Log.d(LOGTAG, "notificationTitle=" + notificationTitle); Log.d(LOGTAG, "notificationMessage=" + notificationMessage); Log.d(LOGTAG, "notificationUri=" + notificationUri); Log.d(LOGTAG, "notificationFrom=" + notificationFrom); // TODO FIXME 发送查看回执 IQ result = new IQ() { @Override public String getChildElementXML() { return null; } }; result.setType(Type.RESULT); result.setPacketID(packetId); result.setTo(notificationFrom); try { Constants.xmppManager.getConnection().sendPacket(result); } catch (Exception e) { } // 保存通知标题和信息到userInfo中,以便保存在DemoAppActivity的浏览历史记录里 UserInfo userInfo = (UserInfo) context.getApplicationContext(); // userInfo.setMyNotifierTitle(title); // userInfo.setMyNotifierMessage(message); // userInfo.setMyNotifierUri(uri); HashMap<String, String> addMap = new HashMap<String, String>(); addMap.put("ItemTitle", notificationTitle); addMap.put("ItemMessage", notificationMessage); addMap.put("ItemUri", notificationUri); userInfo.addMyNotifier(addMap); } View rootView = createView(notificationTitle, notificationMessage, notificationUri); setContentView(rootView); }