當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。