package com.xiaomi.push; import android.text.TextUtils; import com.igexin.push.core.b; import com.xiaomi.push.fj; import com.xiaomi.push.fn; import com.xiaomi.push.fp; import com.xiaomi.push.service.aj; import com.xiaomi.push.service.as; import com.xiaomi.push.service.cg; import java.io.ByteArrayInputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.HashMap; import jd.utils.UrlTools; import jd.view.skuview.BaseController; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlPullParserFactory; public final class ft { private static XmlPullParser a; public static fj a(XmlPullParser xmlPullParser, et etVar) { String attributeValue = xmlPullParser.getAttributeValue("", b.x); String attributeValue2 = xmlPullParser.getAttributeValue("", "to"); String attributeValue3 = xmlPullParser.getAttributeValue("", "from"); String attributeValue4 = xmlPullParser.getAttributeValue("", "chid"); fj.a a2 = fj.a.a(xmlPullParser.getAttributeValue("", "type")); HashMap hashMap = new HashMap(); boolean z = false; for (int i = 0; i < xmlPullParser.getAttributeCount(); i++) { String attributeName = xmlPullParser.getAttributeName(i); hashMap.put(attributeName, xmlPullParser.getAttributeValue("", attributeName)); } fj fjVar = null; fp fpVar = null; while (!z) { int next = xmlPullParser.next(); if (next == 2) { String name = xmlPullParser.getName(); xmlPullParser.getNamespace(); if (name.equals("error")) { fpVar = e(xmlPullParser); } else { fjVar = new fj(); fjVar.a(f(xmlPullParser)); } } else if (next == 3 && xmlPullParser.getName().equals("iq")) { z = true; } } if (fjVar == null) { if (fj.a.a == a2 || fj.a.b == a2) { fu fuVar = new fu(); fuVar.q = attributeValue; fuVar.r = attributeValue3; fuVar.s = attributeValue2; fuVar.a(fj.a.d); fuVar.t = attributeValue4; fuVar.v = new fp(fp.a.e); etVar.a(fuVar); com.xiaomi.channel.commonutils.logger.b.d("iq usage error. send packet in packet parser."); return null; } fjVar = new fv(); } fjVar.q = attributeValue; fjVar.r = attributeValue2; fjVar.t = attributeValue4; fjVar.s = attributeValue3; fjVar.a(a2); fjVar.v = fpVar; fjVar.a(hashMap); return fjVar; } public static fl a(XmlPullParser xmlPullParser) { String str; boolean z = false; String str2 = null; fl flVar = null; if ("1".equals(xmlPullParser.getAttributeValue("", "s"))) { String attributeValue = xmlPullParser.getAttributeValue("", "chid"); String attributeValue2 = xmlPullParser.getAttributeValue("", b.x); String attributeValue3 = xmlPullParser.getAttributeValue("", "from"); String attributeValue4 = xmlPullParser.getAttributeValue("", "to"); String attributeValue5 = xmlPullParser.getAttributeValue("", "type"); aj.b b = aj.a().b(attributeValue, attributeValue4); if (b == null) { b = aj.a().b(attributeValue, attributeValue3); } if (b != null) { while (!z) { int next = xmlPullParser.next(); if (next == 2) { if (!"s".equals(xmlPullParser.getName())) { throw new ff("error while receiving a encrypted message with wrong format"); } else if (xmlPullParser.next() == 4) { String text = xmlPullParser.getText(); if ("5".equals(attributeValue) || "6".equals(attributeValue)) { fk fkVar = new fk(); fkVar.t = attributeValue; fkVar.m = true; fkVar.s = attributeValue3; fkVar.r = attributeValue4; fkVar.q = attributeValue2; fkVar.a = attributeValue5; fi fiVar = new fi("s"); if (!TextUtils.isEmpty(text)) { fiVar.b = fw.a(text); } else { fiVar.b = text; } fkVar.a(fiVar); return fkVar; } byte[] a2 = as.a(as.a(b.i, attributeValue2), text); if (a == null) { try { XmlPullParser newPullParser = XmlPullParserFactory.newInstance().newPullParser(); a = newPullParser; newPullParser.setFeature("http://xmlpull.org/v1/doc/features.html#process-namespaces", true); } catch (XmlPullParserException e) { e.printStackTrace(); } } a.setInput(new InputStreamReader(new ByteArrayInputStream(a2))); a.next(); flVar = a(a); } else { throw new ff("error while receiving a encrypted message with wrong format"); } } else if (next == 3 && xmlPullParser.getName().equals("message")) { z = true; } } if (flVar != null) { return flVar; } throw new ff("error while receiving a encrypted message with wrong format"); } throw new ff("the channel id is wrong while receiving a encrypted message"); } fk fkVar2 = new fk(); String attributeValue6 = xmlPullParser.getAttributeValue("", b.x); if (attributeValue6 == null) { attributeValue6 = "ID_NOT_AVAILABLE"; } fkVar2.q = attributeValue6; fkVar2.r = xmlPullParser.getAttributeValue("", "to"); fkVar2.s = xmlPullParser.getAttributeValue("", "from"); fkVar2.t = xmlPullParser.getAttributeValue("", "chid"); fkVar2.h = xmlPullParser.getAttributeValue("", "appid"); try { str = xmlPullParser.getAttributeValue("", "transient"); } catch (Exception unused) { str = null; } try { String attributeValue7 = xmlPullParser.getAttributeValue("", "seq"); if (!TextUtils.isEmpty(attributeValue7)) { fkVar2.i = attributeValue7; } } catch (Exception unused2) { } try { String attributeValue8 = xmlPullParser.getAttributeValue("", "mseq"); if (!TextUtils.isEmpty(attributeValue8)) { fkVar2.j = attributeValue8; } } catch (Exception unused3) { } try { String attributeValue9 = xmlPullParser.getAttributeValue("", "fseq"); if (!TextUtils.isEmpty(attributeValue9)) { fkVar2.k = attributeValue9; } } catch (Exception unused4) { } try { String attributeValue10 = xmlPullParser.getAttributeValue("", "status"); if (!TextUtils.isEmpty(attributeValue10)) { fkVar2.l = attributeValue10; } } catch (Exception unused5) { } fkVar2.g = !TextUtils.isEmpty(str) && str.equalsIgnoreCase("true"); fkVar2.a = xmlPullParser.getAttributeValue("", "type"); String g = g(xmlPullParser); if (g == null || "".equals(g.trim())) { fl.f(); } else { fkVar2.f2728c = g; } while (!z) { int next2 = xmlPullParser.next(); if (next2 == 2) { String name = xmlPullParser.getName(); TextUtils.isEmpty(xmlPullParser.getNamespace()); if (name.equals("subject")) { g(xmlPullParser); fkVar2.d = d(xmlPullParser); } else if (name.equals(UrlTools.BODY)) { String attributeValue11 = xmlPullParser.getAttributeValue("", "encode"); String d = d(xmlPullParser); if (!TextUtils.isEmpty(attributeValue11)) { fkVar2.e = d; fkVar2.f = attributeValue11; } else { fkVar2.e = d; } } else if (name.equals("thread")) { if (str2 == null) { str2 = xmlPullParser.nextText(); } } else if (name.equals("error")) { fkVar2.v = e(xmlPullParser); } else { fkVar2.a(f(xmlPullParser)); } } else if (next2 == 3 && xmlPullParser.getName().equals("message")) { z = true; } } fkVar2.b = str2; return fkVar2; } public static fn b(XmlPullParser xmlPullParser) { fn.b bVar = fn.b.available; String attributeValue = xmlPullParser.getAttributeValue("", "type"); if (attributeValue != null && !attributeValue.equals("")) { try { bVar = fn.b.valueOf(attributeValue); } catch (IllegalArgumentException unused) { System.err.println("Found invalid presence type ".concat(String.valueOf(attributeValue))); } } fn fnVar = new fn(bVar); fnVar.r = xmlPullParser.getAttributeValue("", "to"); fnVar.s = xmlPullParser.getAttributeValue("", "from"); fnVar.t = xmlPullParser.getAttributeValue("", "chid"); String attributeValue2 = xmlPullParser.getAttributeValue("", b.x); if (attributeValue2 == null) { attributeValue2 = "ID_NOT_AVAILABLE"; } fnVar.q = attributeValue2; boolean z = false; while (!z) { int next = xmlPullParser.next(); if (next == 2) { String name = xmlPullParser.getName(); xmlPullParser.getNamespace(); if (name.equals("status")) { fnVar.a = xmlPullParser.nextText(); } else if (name.equals("priority")) { try { fnVar.a(Integer.parseInt(xmlPullParser.nextText())); } catch (NumberFormatException unused2) { } catch (IllegalArgumentException unused3) { fnVar.a(0); } } else if (name.equals("show")) { String nextText = xmlPullParser.nextText(); try { fnVar.b = fn.a.valueOf(nextText); } catch (IllegalArgumentException unused4) { System.err.println("Found invalid presence mode ".concat(String.valueOf(nextText))); } } else if (name.equals("error")) { fnVar.v = e(xmlPullParser); } else { fnVar.a(f(xmlPullParser)); } } else if (next == 3 && xmlPullParser.getName().equals("presence")) { z = true; } } return fnVar; } public static fo c(XmlPullParser xmlPullParser) { fo foVar = null; boolean z = false; while (!z) { int next = xmlPullParser.next(); if (next == 2) { foVar = new fo(xmlPullParser.getName()); } else if (next == 3 && xmlPullParser.getName().equals("error")) { z = true; } } return foVar; } private static String d(XmlPullParser xmlPullParser) { String str = ""; int depth = xmlPullParser.getDepth(); while (true) { if (xmlPullParser.next() == 3 && xmlPullParser.getDepth() == depth) { return str; } str = str + xmlPullParser.getText(); } } private static fp e(XmlPullParser xmlPullParser) { ArrayList arrayList = new ArrayList(); boolean z = false; String str = "-1"; String str2 = null; String str3 = null; for (int i = 0; i < xmlPullParser.getAttributeCount(); i++) { if (xmlPullParser.getAttributeName(i).equals("code")) { str = xmlPullParser.getAttributeValue("", "code"); } if (xmlPullParser.getAttributeName(i).equals("type")) { str2 = xmlPullParser.getAttributeValue("", "type"); } if (xmlPullParser.getAttributeName(i).equals("reason")) { str3 = xmlPullParser.getAttributeValue("", "reason"); } } String str4 = null; String str5 = null; while (!z) { int next = xmlPullParser.next(); if (next == 2) { if (xmlPullParser.getName().equals("text")) { str5 = xmlPullParser.nextText(); } else { String name = xmlPullParser.getName(); if ("urn:ietf:params:xml:ns:xmpp-stanzas".equals(xmlPullParser.getNamespace())) { str4 = name; } else { arrayList.add(f(xmlPullParser)); } } } else if (next == 3) { if (xmlPullParser.getName().equals("error")) { z = true; } } else if (next == 4) { str5 = xmlPullParser.getText(); } } return new fp(Integer.parseInt(str), str2 == null ? "cancel" : str2, str3, str4, str5, arrayList); } private static fi f(XmlPullParser xmlPullParser) { Object a2 = fs.a().a(BaseController.BG_ALL, "xm:chat"); if (a2 == null || !(a2 instanceof cg)) { return null; } return cg.a(xmlPullParser); } private static String g(XmlPullParser xmlPullParser) { for (int i = 0; i < xmlPullParser.getAttributeCount(); i++) { String attributeName = xmlPullParser.getAttributeName(i); if ("xml:lang".equals(attributeName) || ("lang".equals(attributeName) && "xml".equals(xmlPullParser.getAttributePrefix(i)))) { return xmlPullParser.getAttributeValue(i); } } return null; } }