当前位置: 首页>>代码示例>>Java>>正文


Java IQ.getTo方法代码示例

本文整理汇总了Java中org.jivesoftware.smack.packet.IQ.getTo方法的典型用法代码示例。如果您正苦于以下问题:Java IQ.getTo方法的具体用法?Java IQ.getTo怎么用?Java IQ.getTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.jivesoftware.smack.packet.IQ的用法示例。


在下文中一共展示了IQ.getTo方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: IQReplyFilter

import org.jivesoftware.smack.packet.IQ; //导入方法依赖的package包/类
/**
 * Filters for packets which are a valid reply to an IQ request.
 * <p>
 * Such a stanza(/packet) must have the same stanza(/packet) id and must be an IQ stanza(/packet) of type
 * <code>RESULT</code> or <code>ERROR</code>. Moreover, it is necessary to check
 * the <code>from</code> address to ignore forged replies.
 * <p>
 * We accept a <code>from</code> address if one of the following is true:
 * <ul>
 * <li>It matches the <code>to</code> address of the request.
 * <li>The <code>to</code> address of the request was empty and the
 * <code>from</code> address matches either the bare jid of the server or the
 * (bare or full jid) of the client.
 * <li>To <code>to</code> was our bare address and the <code>from</code> is empty.
 * </ul>
 * <p>
 * For a discussion of the issues, see the thread "Spoofing of iq ids and
 * misbehaving servers" from 2014-01 on the [email protected] mailing list
 * and following discussion in February and March.
 *
 * @param iqPacket An IQ request. Filter for replies to this packet.
 */
public IQReplyFilter(IQ iqPacket, XMPPConnection conn) {
    if (!iqPacket.isRequestIQ()) {
        throw new IllegalArgumentException("IQ must be a request IQ, i.e. of type 'get' or 'set'.");
    }
    if (iqPacket.getTo() != null) {
        to = iqPacket.getTo().toLowerCase(Locale.US);
    } else {
        to = null;
    }
    final String localJid = conn.getUser();
    if (localJid == null) {
        throw new IllegalArgumentException("Must have a local (user) JID set. Either you didn't configure one or you where not connected at least once");
    }
    local = localJid.toLowerCase(Locale.US);

    server = conn.getServiceName().toLowerCase(Locale.US);
    packetId = iqPacket.getStanzaId();

    StanzaFilter iqFilter = new OrFilter(IQTypeFilter.ERROR, IQTypeFilter.RESULT);
    StanzaFilter idFilter = new StanzaIdFilter(iqPacket);
    iqAndIdFilter = new AndFilter(iqFilter, idFilter);
    fromFilter = new OrFilter();
    fromFilter.addFilter(FromMatchesFilter.createFull(to));
    if (to == null) {
        fromFilter.addFilter(FromMatchesFilter.createBare(local));
        fromFilter.addFilter(FromMatchesFilter.createFull(server));
    }
    else if (to.equals(XmppStringUtils.parseBareJid(local))) {
        fromFilter.addFilter(FromMatchesFilter.createFull(null));
    }
}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:54,代码来源:IQReplyFilter.java


注:本文中的org.jivesoftware.smack.packet.IQ.getTo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。