/// <summary> /// This method extracts the sessionID value from the Session header /// of a response /// </summary> private string ExtractSessionID(HttpWebResponse resp) { // Transform the response into an XmlDocument Stream respStream = resp.GetResponseStream(); StreamReader respReader = new StreamReader(respStream); try { XmlDocument respXml = new XmlDocument(); try { respXml.Load(respReader); } catch (XmlException) { // The server didn't return well-formed XML to us throw new DsmlInvalidDocumentException(); } // Locate the SessionID attribute node XmlNamespaceManager ns = NamespaceUtils.GetDsmlNamespaceManager(); XmlAttribute node = (XmlAttribute)respXml.SelectSingleNode("se:Envelope/se:Header/ad:Session/@ad:SessionID", ns); if (node == null) { // try it without the namespace qualifier on the attribute, since default namespaces don't // apply to attributes node = (XmlAttribute)respXml.SelectSingleNode("se:Envelope/se:Header/ad:Session/@SessionID", ns); if (node == null) { throw new DsmlInvalidDocumentException(Res.GetString(Res.NoSessionIDReturned)); } } return(node.Value); } finally { respReader.Close(); } }
internal DsmlResponseDocument(StringBuilder responseString, string xpathToResponse) : this() { _dsmlDocument = new XmlDocument(); try { _dsmlDocument.LoadXml(responseString.ToString()); } catch (XmlException) { // The server didn't return well-formed XML to us throw new DsmlInvalidDocumentException(Res.GetString(Res.NotWellFormedResponse)); } // Locate the batchResponse element within the response document _dsmlNS = NamespaceUtils.GetDsmlNamespaceManager(); _dsmlBatchResponse = (XmlElement)_dsmlDocument.SelectSingleNode(xpathToResponse, _dsmlNS); if (_dsmlBatchResponse == null) { throw new DsmlInvalidDocumentException(Res.GetString(Res.NotWellFormedResponse)); } // parse the response and put it in our internal store XmlNodeList nodeList = _dsmlBatchResponse.ChildNodes; // Unfortunately, we can't just index into the XmlNodeList, // because it's a list of all the nodes, not just the elements. // We're interested in the Nth element, not the Nth node. foreach (XmlNode node in nodeList) { if (node.NodeType == XmlNodeType.Element) { Debug.Assert(node is XmlElement); DirectoryResponse el = ConstructElement((XmlElement)node); _dsmlResponse.Add(el); } } }
internal DsmlResponseDocument(HttpWebResponse resp, string xpathToResponse) : this() { Stream responseStream = resp.GetResponseStream(); StreamReader streamReader = new StreamReader(responseStream); try { this.dsmlDocument = new XmlDocument(); try { this.dsmlDocument.Load(streamReader); } catch (XmlException xmlException) { throw new DsmlInvalidDocumentException(Res.GetString("NotWellFormedResponse")); } this.dsmlNS = NamespaceUtils.GetDsmlNamespaceManager(); this.dsmlBatchResponse = (XmlElement)this.dsmlDocument.SelectSingleNode(xpathToResponse, this.dsmlNS); if (this.dsmlBatchResponse != null) { XmlNodeList childNodes = this.dsmlBatchResponse.ChildNodes; foreach (XmlNode childNode in childNodes) { if (childNode.NodeType != XmlNodeType.Element) { continue; } DirectoryResponse directoryResponse = this.ConstructElement((XmlElement)childNode); this.dsmlResponse.Add(directoryResponse); } } else { throw new DsmlInvalidDocumentException(Res.GetString("NotWellFormedResponse")); } } finally { streamReader.Close(); } }
internal SearchResultReference(XmlNode node) { this.dsmlNode = node; this.dsmlNS = NamespaceUtils.GetDsmlNamespaceManager(); this.dsmlRequest = true; }
internal DirectoryAttribute(XmlElement node) { // retrieve attribute name string primaryXPath = "@dsml:name"; string secondaryXPath = "@name"; XmlNamespaceManager dsmlNS = NamespaceUtils.GetDsmlNamespaceManager(); XmlAttribute attrName = (XmlAttribute)node.SelectSingleNode(primaryXPath, dsmlNS); if (attrName == null) { // try it without the namespace qualifier, in case the sender omitted it attrName = (XmlAttribute)node.SelectSingleNode(secondaryXPath, dsmlNS); if (attrName == null) { // the element doesn't have a associated dn throw new DsmlInvalidDocumentException(Res.GetString(Res.MissingSearchResultEntryAttributeName)); } _attributeName = attrName.Value; } else { _attributeName = attrName.Value; } // retrieve attribute value XmlNodeList nodeList = node.SelectNodes("dsml:value", dsmlNS); if (nodeList.Count != 0) { foreach (XmlNode valueNode in nodeList) { Debug.Assert(valueNode is XmlElement); XmlAttribute valueType = (XmlAttribute)valueNode.SelectSingleNode("@xsi:type", dsmlNS); if (valueType == null) { // value type is string Add(valueNode.InnerText); } else { // value type is string if (string.Compare(valueType.Value, "xsd:string", StringComparison.OrdinalIgnoreCase) == 0) { Add(valueNode.InnerText); } else if (string.Compare(valueType.Value, "xsd:base64Binary", StringComparison.OrdinalIgnoreCase) == 0) { string base64EncodedValue = valueNode.InnerText; byte[] binaryValue; try { binaryValue = System.Convert.FromBase64String(base64EncodedValue); } catch (FormatException) { // server returned invalid base64 throw new DsmlInvalidDocumentException(Res.GetString(Res.BadBase64Value)); } Add(binaryValue); } else if (string.Compare(valueType.Value, "xsd:anyURI", StringComparison.OrdinalIgnoreCase) == 0) { Uri uri = new Uri(valueNode.InnerText); Add(uri); } } } } }
internal DirectoryControl(XmlElement el) { this.directoryControlType = ""; this.directoryControlCriticality = true; this.directoryControlServerSide = true; XmlNamespaceManager dsmlNamespaceManager = NamespaceUtils.GetDsmlNamespaceManager(); XmlAttribute xmlAttribute = (XmlAttribute)el.SelectSingleNode("@dsml:criticality", dsmlNamespaceManager); if (xmlAttribute == null) { xmlAttribute = (XmlAttribute)el.SelectSingleNode("@criticality", dsmlNamespaceManager); } if (xmlAttribute != null) { string value = xmlAttribute.Value; if (value == "true" || value == "1") { this.directoryControlCriticality = true; } else { if (value == "false" || value == "0") { this.directoryControlCriticality = false; } else { throw new DsmlInvalidDocumentException(Res.GetString("BadControl")); } } } else { this.directoryControlCriticality = false; } XmlAttribute xmlAttribute1 = (XmlAttribute)el.SelectSingleNode("@dsml:type", dsmlNamespaceManager); if (xmlAttribute1 == null) { xmlAttribute1 = (XmlAttribute)el.SelectSingleNode("@type", dsmlNamespaceManager); } if (xmlAttribute1 != null) { this.directoryControlType = xmlAttribute1.Value; XmlElement xmlElement = (XmlElement)el.SelectSingleNode("dsml:controlValue", dsmlNamespaceManager); if (xmlElement != null) { try { this.directoryControlValue = Convert.FromBase64String(xmlElement.InnerText); } catch (FormatException formatException) { throw new DsmlInvalidDocumentException(Res.GetString("BadControl")); } } return; } else { throw new DsmlInvalidDocumentException(Res.GetString("BadControl")); } }
internal DirectoryAttribute(XmlElement node) { byte[] numArray; this.attributeName = ""; string str = "@dsml:name"; string str1 = "@name"; XmlNamespaceManager dsmlNamespaceManager = NamespaceUtils.GetDsmlNamespaceManager(); XmlAttribute xmlAttribute = (XmlAttribute)node.SelectSingleNode(str, dsmlNamespaceManager); if (xmlAttribute != null) { this.attributeName = xmlAttribute.Value; } else { xmlAttribute = (XmlAttribute)node.SelectSingleNode(str1, dsmlNamespaceManager); if (xmlAttribute != null) { this.attributeName = xmlAttribute.Value; } else { throw new DsmlInvalidDocumentException(Res.GetString("MissingSearchResultEntryAttributeName")); } } XmlNodeList xmlNodeLists = node.SelectNodes("dsml:value", dsmlNamespaceManager); if (xmlNodeLists.Count != 0) { foreach (XmlNode xmlNodes in xmlNodeLists) { XmlAttribute xmlAttribute1 = (XmlAttribute)xmlNodes.SelectSingleNode("@xsi:type", dsmlNamespaceManager); if (xmlAttribute1 != null) { if (string.Compare(xmlAttribute1.Value, "xsd:string", StringComparison.OrdinalIgnoreCase) != 0) { if (string.Compare(xmlAttribute1.Value, "xsd:base64Binary", StringComparison.OrdinalIgnoreCase) != 0) { if (string.Compare(xmlAttribute1.Value, "xsd:anyURI", StringComparison.OrdinalIgnoreCase) != 0) { continue; } Uri uri = new Uri(xmlNodes.InnerText); this.Add(uri); } else { string innerText = xmlNodes.InnerText; try { numArray = Convert.FromBase64String(innerText); } catch (FormatException formatException) { throw new DsmlInvalidDocumentException(Res.GetString("BadBase64Value")); } this.Add(numArray); } } else { this.Add(xmlNodes.InnerText); } } else { this.Add(xmlNodes.InnerText); } } } }
internal DirectoryControl(XmlElement el) { XmlNamespaceManager ns = NamespaceUtils.GetDsmlNamespaceManager(); // // Populate the control's criticality // XmlAttribute attrCriticality = (XmlAttribute)el.SelectSingleNode("@dsml:criticality", ns); if (attrCriticality == null) { // try it without the namespace qualifier, in case the sender omitted it attrCriticality = (XmlAttribute)el.SelectSingleNode("@criticality", ns); } if (attrCriticality == null) { // DSML v2 defaults criticality to false if not present in the XML _directoryControlCriticality = false; } else { string s = attrCriticality.Value; if ((s == "true") || (s == "1")) { _directoryControlCriticality = true; } else if ((s == "false") || (s == "0")) { _directoryControlCriticality = false; } else { Debug.WriteLine("Processing response, the control has wrong value of crticality specified"); throw new DsmlInvalidDocumentException(Res.GetString(Res.BadControl)); } } // // Populate the control's name (Type) // XmlAttribute attrType = (XmlAttribute)el.SelectSingleNode("@dsml:type", ns); if (attrType == null) { // try it without the namespace qualifier, in case the sender omitted it attrType = (XmlAttribute)el.SelectSingleNode("@type", ns); } if (attrType == null) { // DSML v2 requires the control to specify a type Debug.WriteLine("Processing response, the control does not have oid defined"); throw new DsmlInvalidDocumentException(Res.GetString(Res.BadControl)); } else { _directoryControlType = attrType.Value; } // // Populate the control's value // XmlElement elemValue = (XmlElement)el.SelectSingleNode("dsml:controlValue", ns); if (elemValue != null) { try { this.directoryControlValue = System.Convert.FromBase64String(elemValue.InnerText); } catch (FormatException) { Debug.WriteLine("Processing response, converting control value failed"); throw new DsmlInvalidDocumentException(Res.GetString(Res.BadControl)); } } }