NodeString() public method

public NodeString ( string indent = "" ) : string
indent string
return string
示例#1
0
        public ProtocolTreeNode nextTree(byte[] pInput = null, bool useDecrypt = true)
        {
            if (pInput != null && pInput.Length > 0)
            {
                this.buffer = new List <byte>();
                this.buffer.AddRange(pInput);
            }

            int firstByte  = this.peekInt8();
            int stanzaFlag = (firstByte & 0xF0) >> 4;
            int stanzaSize = this.peekInt16(1) | ((firstByte & 0x0F) << 16);

            int flags = stanzaFlag;
            int size  = stanzaSize;

            this.readInt24();

            bool isEncrypted = (stanzaFlag & 8) != 0;

            if (isEncrypted)
            {
                if (this.Key != null)
                {
                    var realStanzaSize = stanzaSize - 4;
                    var macOffset      = stanzaSize - 4;
                    var treeData       = this.buffer.ToArray();
                    try
                    {
                        this.Key.DecodeMessage(treeData, macOffset, 0, realStanzaSize);
                    }
                    catch (Exception e)
                    {
                        Helper.DebugAdapter.Instance.fireOnPrintDebug(e);
                    }
                    this.buffer.Clear();
                    this.buffer.AddRange(treeData.Take(realStanzaSize).ToArray());
                }
                else
                {
                    throw new Exception("Received encrypted message, encryption key not set");
                }
            }

            if (stanzaSize > 0)
            {
                ProtocolTreeNode node = this.nextTreeInternal();
                if (node != null)
                {
                    this.DebugPrint(node.NodeString("RECVD: "));
                }
                return(node);
            }

            return(null);
        }
示例#2
0
        public ProtocolTreeNode nextTree(byte[] pInput = null, bool useDecrypt = true)
        {
            if (pInput != null)
            {
                if (pInput.Length == 0)
                {
                    return(null);
                }
                this.buffer = new List <byte>();
                this.buffer.AddRange(pInput);
            }

            int stanzaFlag = (this.peekInt8() & 0xF0) >> 4;
            int stanzaSize = this.peekInt16(1);

            int flags = stanzaFlag;
            int size  = stanzaSize;

            if (stanzaSize > this.buffer.Count)
            {
                var exception = new IncompleteMessageException("Incomplete message");
                exception.setInput(this.buffer.ToArray());
                throw exception;
            }

            this.readInt24();

            bool isEncrypted = (stanzaFlag & 8) != 0;

            if (isEncrypted)
            {
                if (Encryptionkey != null)
                {
                    decode(size, useDecrypt);
                }
                else
                {
                    throw new Exception("Received encrypted message, encryption key not set");
                }
            }

            if (stanzaSize > 0)
            {
                ProtocolTreeNode node = this.nextTreeInternal();
                if (node != null)
                {
                    this.DebugPrint(node.NodeString("RECVD: "));
                }
                return(node);
            }
            return(null);
        }
示例#3
0
 public byte[] Write(ProtocolTreeNode node, bool encrypt = true)
 {
     if (node == null)
     {
         this.buffer.Add(0);
     }
     else
     {
         this.DebugPrint(node.NodeString("SENT: "));
         this.writeInternal(node);
     }
     return this.flushBuffer(encrypt);
 }
示例#4
0
 public byte[] Write(ProtocolTreeNode node, bool encrypt = true)
 {
     if (node == null)
     {
         this.buffer.Add(0);
     }
     else
     {
         this.DebugPrint(node.NodeString("SENT: "));
         this.writeInternal(node);
     }
     return(this.flushBuffer(encrypt));
 }
示例#5
0
 public byte[] Write(ProtocolTreeNode node, bool encrypt = true)
 {
     if (node == null)
     {
         this.buffer.Add(0);
     }
     else
     {
         if (WhatsApp.DEBUG && WhatsApp.DEBUGOutBound)
             this.DebugPrint(node.NodeString("tx "));
         this.writeInternal(node);
     }
     return this.flushBuffer(encrypt);
 }
 public byte[] Write(ProtocolTreeNode node, bool encrypt = true)
 {
     if (node == null)
     {
         this.buffer.Add(0);
     }
     else
     {
         if (WhatsApp.DEBUG && WhatsApp.DEBUGOutBound)
             this.DebugPrint(node.NodeString("tx "));
         this.writeInternal(node);
     }
     return this.flushBuffer(encrypt);
 }
示例#7
0
 public byte[] Write(ProtocolTreeNode node, bool encrypt = true)
 {
     if (node == null)
     {
         this.buffer.Add((byte)'\x00');
     }
     else
     {
         if (WhatsApp.Debug && WhatsApp.DebugOutBound)
         {
             this.DebugPrint(node.NodeString("tx "));
         }
         this.WriteInternal(node);
     }
     return(this.FlushBuffer(encrypt));
 }
示例#8
0
        protected void handleMessage(ProtocolTreeNode node, bool autoReceipt)
        {
            if (!string.IsNullOrEmpty(node.GetAttribute("notify")))
            {
                string name = node.GetAttribute("notify");
                this.fireOnGetContactName(node.GetAttribute("from"), name);
            }
            if (node.GetAttribute("type") == "error")
            {
                throw new NotImplementedException(node.NodeString());
            }
            if (node.GetChild("body") != null)
            {
                //text message
                this.fireOnGetMessage(node, node.GetAttribute("from"), node.GetAttribute("id"), node.GetAttribute("notify"), System.Text.Encoding.UTF8.GetString(node.GetChild("body").GetData()), autoReceipt);
                if (autoReceipt)
                {
                    this.sendMessageReceived(node);
                }
            }
            if (node.GetChild("media") != null)
            {
                ProtocolTreeNode media = node.GetChild("media");
                //media message

                //define variables in switch
                string file, url, from, id;
                int size;
                byte[] preview, dat;
                id = node.GetAttribute("id");
                from = node.GetAttribute("from");
                switch (media.GetAttribute("type"))
                {
                    case "image":
                        url = media.GetAttribute("url");
                        file = media.GetAttribute("file");
                        size = Int32.Parse(media.GetAttribute("size"));
                        preview = media.GetData();
                        this.fireOnGetMessageImage(node, from, id, file, size, url, preview);
                        break;
                    case "audio":
                        file = media.GetAttribute("file");
                        size = Int32.Parse(media.GetAttribute("size"));
                        url = media.GetAttribute("url");
                        preview = media.GetData();
                        this.fireOnGetMessageAudio(node, from, id, file, size, url, preview);
                        break;
                    case "video":
                        file = media.GetAttribute("file");
                        size = Int32.Parse(media.GetAttribute("size"));
                        url = media.GetAttribute("url");
                        preview = media.GetData();
                        this.fireOnGetMessageVideo(node, from, id, file, size, url, preview);
                        break;
                    case "location":
                        double lon = double.Parse(media.GetAttribute("longitude"), System.Globalization.CultureInfo.InvariantCulture);
                        double lat = double.Parse(media.GetAttribute("latitude"), System.Globalization.CultureInfo.InvariantCulture);
                        preview = media.GetData();
                        name = media.GetAttribute("name");
                        url = media.GetAttribute("url");
                        this.fireOnGetMessageLocation(node, from, id, lon, lat, url, name, preview);
                        break;
                    case "vcard":
                        ProtocolTreeNode vcard = media.GetChild("vcard");
                        name = vcard.GetAttribute("name");
                        dat = vcard.GetData();
                        this.fireOnGetMessageVcard(node, from, id, name, dat);
                        break;
                }
                this.sendMessageReceived(node);
            }
        }
示例#9
0
 protected void handleNotification(ProtocolTreeNode node)
 {
     if (!String.IsNullOrEmpty(node.GetAttribute("notify")))
     {
         this.fireOnGetContactName(node.GetAttribute("from"), node.GetAttribute("notify"));
     }
     string type = node.GetAttribute("type");
     switch (type)
     {
         case "picture":
             ProtocolTreeNode child = node.children.FirstOrDefault();
             this.fireOnNotificationPicture(child.tag, child.GetAttribute("jid"), child.GetAttribute("id"));
             break;
         case "status":
             ProtocolTreeNode child2 = node.children.FirstOrDefault();
             this.fireOnGetStatus(node.GetAttribute("from"), child2.tag, node.GetAttribute("notify"), System.Text.Encoding.UTF8.GetString(child2.GetData()));
             break;
         case "subject":
             //TODO
             break;
         case "contacts":
             //TODO
             break;
         default:
             throw new NotImplementedException(node.NodeString());
     }
     this.SendNotificationAck(node);
 }