Esempio n. 1
0
        private static string GetLogString(
            SafeFields.MessageType type, Hashtable table)
        {
            if (table == null || table.Count == 0) return( String.Empty );

            StringBuilder sb = new StringBuilder();

            foreach (string key in table.Keys) {
                if (sb.Length > 0) sb.Append(NVP_SEPARATOR);
                sb.Append(key);
                sb.Append(NV_SEPARATOR);
                sb.Append(
                    SafeFields.IsSafe( type, key )
                        ? (string) table[key]
                        : MaskedValue( key, (string) table[key] ) );
            }

            return (sb.ToString());
        }
Esempio n. 2
0
        // parentName must be null.  This is a recursive method.
        // The recursive calls will pass non-NULL strings to said
        // parameter.
        private static void MaskXml(
            SafeFields.MessageType type, XmlNode node,
            string parentName)
        {
            if (node == null) return;

            XmlNodeType nodeType = node.NodeType;
            if (nodeType == XmlNodeType.Text)
            {
                if (!SafeFields.IsSafe(type, parentName))
                {
                    string origVal = node.Value;
                    if (origVal != null) origVal = origVal.Trim();
                    if (origVal != null && origVal.Length > 0)
                    {
                        node.Value = MaskedValue(parentName, origVal);
                    }
                }
            }
            else if (nodeType == XmlNodeType.Element ||
                     nodeType == XmlNodeType.Document)
            {
                if (!node.HasChildNodes) return;

                String localName = node.LocalName;
                if (localName == null) localName = String.Empty;

                String fieldFullName = null;
                if (parentName == null)
                {
                    // we have not encountered any of the fields in
                    // CYBS_ROOT_FIELDS, in which case, we check if
                    // the current node's local name is one of them.
                    // If so, then we set fieldFullName to "".
                    // Otherwise, fieldFullName remains null.
                    if (localName.Length > 0 &&
                        CYBS_ROOT_FIELDS.IndexOf(localName) != -1)
                    {
                        fieldFullName = "";
                    }
                }
                else if (parentName.Length == 0)
                {
                    // the immediate parent of this node is one of
                    // those in CYBS_ROOT_FIELDS, in which case, we
                    // use its local name as the field name so far.
                    fieldFullName = localName;
                }
                else
                {
                    // this is a node that is at least two levels
                    // down from one of the CYBS_ROOT_FIELDS, in which
                    // case, we append its local name to the parent's name.
                    fieldFullName = parentName + "_" + localName;
                }

                // call this method recursively on each of the child nodes
                XmlNodeList children = node.ChildNodes;
                foreach (XmlNode child in children)
                {
                    MaskXml(type, child, fieldFullName);
                }
            }
        }