package org.fourthline.cling.l.d; import com.bytedance.sdk.openadsdk.mediation.MediationConstant; import java.io.StringReader; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.FactoryConfigurationError; import org.fourthline.cling.h.i; import org.fourthline.cling.h.m; import org.fourthline.cling.h.n.a; import org.fourthline.cling.h.n.e; import org.fourthline.cling.h.p.k.b; import org.fourthline.cling.h.p.k.c; import org.fourthline.cling.h.u.n; import org.fourthline.cling.h.u.r; import org.fourthline.cling.l.e.j; import org.w3c.dom.Attr; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.xml.sax.ErrorHandler; import org.xml.sax.InputSource; import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; /* compiled from: SOAPActionProcessorImpl */ public class o implements j, ErrorHandler { /* renamed from: ʻ reason: contains not printable characters */ private static Logger f10921 = Logger.getLogger(j.class.getName()); @Override // org.xml.sax.ErrorHandler public void error(SAXParseException sAXParseException) throws SAXException { throw sAXParseException; } @Override // org.xml.sax.ErrorHandler public void fatalError(SAXParseException sAXParseException) throws SAXException { throw sAXParseException; } @Override // org.xml.sax.ErrorHandler public void warning(SAXParseException sAXParseException) throws SAXException { f10921.warning(sAXParseException.toString()); } /* access modifiers changed from: protected */ /* renamed from: ʻ reason: contains not printable characters */ public DocumentBuilderFactory m13951() throws FactoryConfigurationError { return DocumentBuilderFactory.newInstance(); } @Override // org.fourthline.cling.l.e.j /* renamed from: ʼ reason: contains not printable characters */ public void m13967(b bVar, e eVar) throws i { Logger logger = f10921; logger.fine("Writing body of " + bVar + " for: " + eVar); try { DocumentBuilderFactory newInstance = DocumentBuilderFactory.newInstance(); newInstance.setNamespaceAware(true); Document newDocument = newInstance.newDocumentBuilder().newDocument(); m13975(newDocument, m13972(newDocument), bVar, eVar); if (f10921.isLoggable(Level.FINER)) { f10921.finer("===================================== SOAP BODY BEGIN ============================================"); f10921.finer(bVar.m13185()); f10921.finer("-===================================== SOAP BODY END ============================================"); } } catch (Exception e2) { throw new i("Can't transform message payload: " + e2, e2); } } /* access modifiers changed from: protected */ /* renamed from: ʽ reason: contains not printable characters */ public void m13976(Document document, Element element, c cVar, e eVar) throws Exception { m13974(document, element, eVar); cVar.m13183(m13964(document)); } /* access modifiers changed from: protected */ /* renamed from: ʾ reason: contains not printable characters */ public void m13977(Document document, Element element, c cVar, e eVar) throws Exception { m13969(document, m13966(document, element, cVar, eVar), eVar); cVar.m13183(m13964(document)); } @Override // org.fourthline.cling.l.e.j /* renamed from: ʻ reason: contains not printable characters */ public void m13958(b bVar, e eVar) throws i { Logger logger = f10921; logger.fine("Reading body of " + bVar + " for: " + eVar); if (f10921.isLoggable(Level.FINER)) { f10921.finer("===================================== SOAP BODY BEGIN ============================================"); f10921.finer(bVar.m13185()); f10921.finer("-===================================== SOAP BODY END ============================================"); } String r0 = m13948(bVar); try { DocumentBuilderFactory r1 = m13951(); r1.setNamespaceAware(true); DocumentBuilder newDocumentBuilder = r1.newDocumentBuilder(); newDocumentBuilder.setErrorHandler(this); Document parse = newDocumentBuilder.parse(new InputSource(new StringReader(r0))); m13961(parse, m13955(parse), bVar, eVar); } catch (Exception e2) { throw new i("Can't transform message payload: " + e2, e2, r0); } } /* access modifiers changed from: protected */ /* renamed from: ʽ reason: contains not printable characters */ public void m13975(Document document, Element element, b bVar, e eVar) throws Exception { m13960(document, m13965(document, element, bVar, eVar), eVar); bVar.m13183(m13964(document)); } /* access modifiers changed from: protected */ /* renamed from: ʽ reason: contains not printable characters */ public Element m13972(Document document) { Element createElementNS = document.createElementNS("http://schemas.xmlsoap.org/soap/envelope/", "s:Envelope"); Attr createAttributeNS = document.createAttributeNS("http://schemas.xmlsoap.org/soap/envelope/", "s:encodingStyle"); createAttributeNS.setValue("http://schemas.xmlsoap.org/soap/encoding/"); createElementNS.setAttributeNode(createAttributeNS); document.appendChild(createElementNS); Element createElementNS2 = document.createElementNS("http://schemas.xmlsoap.org/soap/envelope/", "s:Body"); createElementNS.appendChild(createElementNS2); return createElementNS2; } @Override // org.fourthline.cling.l.e.j /* renamed from: ʼ reason: contains not printable characters */ public void m13968(c cVar, e eVar) throws i { Logger logger = f10921; logger.fine("Writing body of " + cVar + " for: " + eVar); try { DocumentBuilderFactory newInstance = DocumentBuilderFactory.newInstance(); newInstance.setNamespaceAware(true); Document newDocument = newInstance.newDocumentBuilder().newDocument(); Element r1 = m13972(newDocument); if (eVar.m13102() != null) { m13976(newDocument, r1, cVar, eVar); } else { m13977(newDocument, r1, cVar, eVar); } if (f10921.isLoggable(Level.FINER)) { f10921.finer("===================================== SOAP BODY BEGIN ============================================"); f10921.finer(cVar.m13185()); f10921.finer("-===================================== SOAP BODY END ============================================"); } } catch (Exception e2) { throw new i("Can't transform message payload: " + e2, e2); } } /* access modifiers changed from: protected */ /* renamed from: ʽ reason: contains not printable characters */ public Element m13973(Element element, e eVar) { NodeList childNodes = element.getChildNodes(); for (int i2 = 0; i2 < childNodes.getLength(); i2++) { Node item = childNodes.item(i2); if (item.getNodeType() == 1) { String r2 = m13949(item); if (r2.equals(eVar.m13093().m13301() + "Response")) { Logger logger = f10921; logger.fine("Reading action response element: " + m13949(item)); return (Element) item; } } } f10921.fine("Could not read action response element"); return null; } @Override // org.fourthline.cling.l.e.j /* renamed from: ʻ reason: contains not printable characters */ public void m13959(c cVar, e eVar) throws i { Logger logger = f10921; logger.fine("Reading body of " + cVar + " for: " + eVar); if (f10921.isLoggable(Level.FINER)) { f10921.finer("===================================== SOAP BODY BEGIN ============================================"); f10921.finer(cVar.m13185()); f10921.finer("-===================================== SOAP BODY END ============================================"); } String r0 = m13948(cVar); try { DocumentBuilderFactory r1 = m13951(); r1.setNamespaceAware(true); DocumentBuilder newDocumentBuilder = r1.newDocumentBuilder(); newDocumentBuilder.setErrorHandler(this); Document parse = newDocumentBuilder.parse(new InputSource(new StringReader(r0))); Element r2 = m13955(parse); org.fourthline.cling.h.n.c r3 = m13953(parse, r2); if (r3 == null) { m13962(parse, r2, cVar, eVar); } else { eVar.m13097(r3); } } catch (Exception e2) { throw new i("Can't transform message payload: " + e2, e2, r0); } } /* access modifiers changed from: protected */ /* renamed from: ʽ reason: contains not printable characters */ public void m13974(Document document, Element element, e eVar) { Element createElementNS = document.createElementNS("http://schemas.xmlsoap.org/soap/envelope/", "s:Fault"); element.appendChild(createElementNS); m.m13086(document, createElementNS, "faultcode", "s:Client"); m.m13086(document, createElementNS, "faultstring", "UPnPError"); Element createElement = document.createElement("detail"); createElementNS.appendChild(createElement); Element createElementNS2 = document.createElementNS("urn:schemas-upnp-org:control-1-0", "UPnPError"); createElement.appendChild(createElementNS2); int r0 = eVar.m13102().m13090(); String message = eVar.m13102().getMessage(); Logger logger = f10921; logger.fine("Writing fault element: " + r0 + " - " + message); m.m13086(document, createElementNS2, MediationConstant.KEY_ERROR_CODE, Integer.toString(r0)); m.m13086(document, createElementNS2, "errorDescription", message); } /* access modifiers changed from: protected */ /* renamed from: ʼ reason: contains not printable characters */ public Element m13965(Document document, Element element, b bVar, e eVar) { Logger logger = f10921; logger.fine("Writing action request element: " + eVar.m13093().m13301()); String r6 = bVar.m13186(); Element createElementNS = document.createElementNS(r6, "u:" + eVar.m13093().m13301()); element.appendChild(createElementNS); return createElementNS; } /* access modifiers changed from: protected */ /* renamed from: ʼ reason: contains not printable characters */ public Element m13966(Document document, Element element, c cVar, e eVar) { Logger logger = f10921; logger.fine("Writing action response element: " + eVar.m13093().m13301()); String r6 = cVar.m13186(); Element createElementNS = document.createElementNS(r6, "u:" + eVar.m13093().m13301() + "Response"); element.appendChild(createElementNS); return createElementNS; } /* access modifiers changed from: protected */ /* renamed from: ʻ reason: contains not printable characters */ public org.fourthline.cling.h.n.c m13953(Document document, Element element) throws Exception { return m13954(element); } /* access modifiers changed from: protected */ /* renamed from: ʻ reason: contains not printable characters */ public void m13961(Document document, Element element, b bVar, e eVar) throws Exception { m13963(m13956(element, bVar, eVar), eVar); } /* access modifiers changed from: protected */ /* renamed from: ʻ reason: contains not printable characters */ public void m13962(Document document, Element element, c cVar, e eVar) throws Exception { m13970(m13973(element, eVar), eVar); } /* access modifiers changed from: protected */ /* renamed from: ʼ reason: contains not printable characters */ public void m13969(Document document, Element element, e eVar) { org.fourthline.cling.h.q.b[] r0 = eVar.m13093().m13302(); for (org.fourthline.cling.h.q.b bVar : r0) { f10921.fine("Writing action output argument: " + bVar.m13312()); m.m13086(document, element, bVar.m13312(), eVar.m13099(bVar) != null ? eVar.m13099(bVar).toString() : ""); } } /* access modifiers changed from: protected */ /* renamed from: ʻ reason: contains not printable characters */ public Element m13955(Document document) { Element documentElement = document.getDocumentElement(); if (documentElement == null || !m13949((Node) documentElement).equals("Envelope")) { throw new RuntimeException("Response root element was not 'Envelope'"); } NodeList childNodes = documentElement.getChildNodes(); for (int i2 = 0; i2 < childNodes.getLength(); i2++) { Node item = childNodes.item(i2); if (item.getNodeType() == 1 && m13949(item).equals("Body")) { return (Element) item; } } throw new RuntimeException("Response envelope did not contain 'Body' child element"); } /* access modifiers changed from: protected */ /* renamed from: ʼ reason: contains not printable characters */ public void m13970(Element element, e eVar) throws org.fourthline.cling.h.n.c { eVar.m13101(m13971(element.getChildNodes(), eVar.m13093().m13302())); } /* access modifiers changed from: protected */ /* renamed from: ʼ reason: contains not printable characters */ public String m13964(Document document) throws Exception { String r3 = m.m13078(document); while (true) { if (!r3.endsWith("\n") && !r3.endsWith("\r")) { return r3; } r3 = r3.substring(0, r3.length() - 1); } } /* access modifiers changed from: protected */ /* renamed from: ʼ reason: contains not printable characters */ public a[] m13971(NodeList nodeList, org.fourthline.cling.h.q.b[] bVarArr) throws org.fourthline.cling.h.n.c { List<Node> r8 = m13950(nodeList, bVarArr); a[] aVarArr = new a[bVarArr.length]; for (int i2 = 0; i2 < bVarArr.length; i2++) { org.fourthline.cling.h.q.b bVar = bVarArr[i2]; Node r3 = m13957(r8, bVar); if (r3 != null) { Logger logger = f10921; logger.fine("Reading action argument: " + bVar.m13312()); aVarArr[i2] = m13952(bVar, m.m13080(r3)); } else { n nVar = n.ARGUMENT_VALUE_INVALID; throw new org.fourthline.cling.h.n.c(nVar, "Could not find argument '" + bVar.m13312() + "' node"); } } return aVarArr; } /* access modifiers changed from: protected */ /* renamed from: ʻ reason: contains not printable characters */ public Element m13956(Element element, b bVar, e eVar) { NodeList childNodes = element.getChildNodes(); Logger logger = f10921; logger.fine("Looking for action request element matching namespace:" + bVar.m13186()); for (int i2 = 0; i2 < childNodes.getLength(); i2++) { Node item = childNodes.item(i2); if (item.getNodeType() == 1) { String r2 = m13949(item); if (r2.equals(eVar.m13093().m13301())) { if (item.getNamespaceURI() == null || !item.getNamespaceURI().equals(bVar.m13186())) { throw new i("Illegal or missing namespace on action request element: " + item); } Logger logger2 = f10921; logger2.fine("Reading action request element: " + r2); return (Element) item; } } } throw new i("Could not read action request element matching namespace: " + bVar.m13186()); } /* access modifiers changed from: protected */ /* renamed from: ʻ reason: contains not printable characters */ public void m13960(Document document, Element element, e eVar) { org.fourthline.cling.h.q.b[] r0 = eVar.m13093().m13300(); for (org.fourthline.cling.h.q.b bVar : r0) { f10921.fine("Writing action input argument: " + bVar.m13312()); m.m13086(document, element, bVar.m13312(), eVar.m13092(bVar) != null ? eVar.m13092(bVar).toString() : ""); } } /* renamed from: ʻ reason: contains not printable characters */ public void m13963(Element element, e eVar) throws org.fourthline.cling.h.n.c { eVar.m13098(m13971(element.getChildNodes(), eVar.m13093().m13300())); } /* access modifiers changed from: protected */ /* renamed from: ʻ reason: contains not printable characters */ public org.fourthline.cling.h.n.c m13954(Element element) { NodeList childNodes = element.getChildNodes(); String str = null; String str2 = null; boolean z = false; for (int i2 = 0; i2 < childNodes.getLength(); i2++) { Node item = childNodes.item(i2); short s = 1; if (item.getNodeType() == 1 && m13949(item).equals("Fault")) { NodeList childNodes2 = item.getChildNodes(); int i3 = 0; while (i3 < childNodes2.getLength()) { Node item2 = childNodes2.item(i3); if (item2.getNodeType() == s && m13949(item2).equals("detail")) { NodeList childNodes3 = item2.getChildNodes(); int i4 = 0; while (i4 < childNodes3.getLength()) { Node item3 = childNodes3.item(i4); if (item3.getNodeType() == s && m13949(item3).equals("UPnPError")) { NodeList childNodes4 = item3.getChildNodes(); int i5 = 0; while (i5 < childNodes4.getLength()) { Node item4 = childNodes4.item(i5); if (item4.getNodeType() == s) { if (m13949(item4).equals(MediationConstant.KEY_ERROR_CODE)) { str = m.m13080(item4); } if (m13949(item4).equals("errorDescription")) { str2 = m.m13080(item4); } } i5++; s = 1; } } i4++; s = 1; } } i3++; s = 1; } z = true; } } if (str != null) { try { int intValue = Integer.valueOf(str).intValue(); n r2 = n.m13557(intValue); if (r2 != null) { f10921.fine("Reading fault element: " + r2.m13558() + " - " + str2); return new org.fourthline.cling.h.n.c(r2, str2, false); } f10921.fine("Reading fault element: " + intValue + " - " + str2); return new org.fourthline.cling.h.n.c(intValue, str2); } catch (NumberFormatException unused) { throw new RuntimeException("Error code was not a number"); } } else if (!z) { return null; } else { throw new RuntimeException("Received fault element but no error code"); } } /* access modifiers changed from: protected */ /* renamed from: ʻ reason: contains not printable characters */ public String m13948(org.fourthline.cling.h.p.k.a aVar) throws i { if (aVar.m13184()) { return aVar.m13185().trim(); } throw new i("Can't transform null or non-string/zero-length body of: " + aVar); } /* access modifiers changed from: protected */ /* renamed from: ʻ reason: contains not printable characters */ public String m13949(Node node) { if (node.getPrefix() != null) { return node.getNodeName().substring(node.getPrefix().length() + 1); } return node.getNodeName(); } /* access modifiers changed from: protected */ /* renamed from: ʻ reason: contains not printable characters */ public List<Node> m13950(NodeList nodeList, org.fourthline.cling.h.q.b[] bVarArr) throws org.fourthline.cling.h.n.c { ArrayList arrayList = new ArrayList(); for (org.fourthline.cling.h.q.b bVar : bVarArr) { arrayList.add(bVar.m13312()); arrayList.addAll(Arrays.asList(bVar.m13309())); } ArrayList arrayList2 = new ArrayList(); for (int i2 = 0; i2 < nodeList.getLength(); i2++) { Node item = nodeList.item(i2); if (item.getNodeType() == 1 && arrayList.contains(m13949(item))) { arrayList2.add(item); } } if (arrayList2.size() >= bVarArr.length) { return arrayList2; } throw new org.fourthline.cling.h.n.c(n.ARGUMENT_VALUE_INVALID, "Invalid number of input or output arguments in XML message, expected " + bVarArr.length + " but found " + arrayList2.size()); } /* access modifiers changed from: protected */ /* renamed from: ʻ reason: contains not printable characters */ public a m13952(org.fourthline.cling.h.q.b bVar, String str) throws org.fourthline.cling.h.n.c { try { return new a(bVar, str); } catch (r e2) { n nVar = n.ARGUMENT_VALUE_INVALID; throw new org.fourthline.cling.h.n.c(nVar, "Wrong type or invalid value for '" + bVar.m13312() + "': " + e2.getMessage(), e2); } } /* access modifiers changed from: protected */ /* renamed from: ʻ reason: contains not printable characters */ public Node m13957(List<Node> list, org.fourthline.cling.h.q.b bVar) { for (Node node : list) { if (bVar.m13308(m13949(node))) { return node; } } return null; } }