Esempio n. 1
0
        public MessageMessage(XmlNode node, CarbonCopyType ccType) : base(node.Attributes["from"]?.Value, node.Attributes["to"]?.Value, loadMessageId(node))
        {
            CC_TYPE = ccType;
            if (!node.HasChildNodes)
            {
                MESSAGE = "invalid message: " + node.ToString();
                TYPE    = "error";
                return;
            }

            XmlAttribute typeAttribute = XMLUtils.getAttribute(node, "type");

            if (typeAttribute != null)
            {
                TYPE = typeAttribute.Value;
                switch (TYPE)
                {
                case TYPE_ERROR:
                    XmlNode error = XMLUtils.getChildNode(node, "error");
                    if (error != null)
                    {
                        XmlNode text = XMLUtils.getChildNode(error, "text");
                        MESSAGE = text != null ? text.InnerText : error.InnerXml;
                    }
                    else
                    {
                        MESSAGE = node.InnerXml;
                    }
                    return;

                case TYPE_GROUPCHAT:
                    FROM_NICK = Utils.getJidResourcePart(FROM);
                    break;
                }
            }

            XmlNode body = XMLUtils.getChildNode(node, "body");

            if (body != null)
            {
                MESSAGE = body.InnerText;
            }

            // XEP-0203 (Delayed Delivery):
            XmlNode delayNode = XMLUtils.getChildNode(node, "delay", Consts.XML_XMLNS, Consts.XML_XEP_0203_NAMESPACE);

            if (delayNode != null)
            {
                parseDelay(delayNode);
            }
            else
            {
                delay = DateTime.Now;
            }

            // XEP-0184 (Message Delivery Receipts):
            XmlNode requestNode = XMLUtils.getChildNode(node, "request", Consts.XML_XMLNS, Consts.XML_XEP_0184_NAMESPACE);

            RECIPT_REQUESTED = requestNode != null;
        }
        public OmemoEncryptedMessage(XmlNode node, CarbonCopyType ccType) : base(node, ccType)
        {
            XmlNode encryptedNode = XMLUtils.getChildNode(node, "encrypted", Consts.XML_XMLNS, Consts.XML_XEP_0384_NAMESPACE);

            Debug.Assert(!(encryptedNode is null));
            XmlNode headerNode = XMLUtils.getChildNode(encryptedNode, "header");

            Debug.Assert(!(headerNode is null));
            SID  = uint.Parse(headerNode.Attributes["sid"]?.Value);
            keys = new List <OmemoKeys>();
            foreach (XmlNode keysNode in headerNode.ChildNodes)
            {
                if (string.Equals(keysNode.Name, "keys"))
                {
                    keys.Add(new OmemoKeys(keysNode));
                }
            }

            // Can be null for empty messages:
            XmlNode payloadNode = XMLUtils.getChildNode(encryptedNode, "payload");

            if (payloadNode is null)
            {
                MESSAGE = null;
            }
            else
            {
                BASE_64_PAYLOAD = payloadNode.InnerText;
            }
            ENCRYPTED = true;
        }
Esempio n. 3
0
 public MessageMessage(string from, string to, string message, string type, string from_nick, bool reciptRequested) : base(from, to)
 {
     MESSAGE          = message;
     TYPE             = type;
     cacheUntilSend   = true;
     delay            = DateTime.MinValue;
     FROM_NICK        = from_nick;
     RECIPT_REQUESTED = reciptRequested;
     CC_TYPE          = CarbonCopyType.NONE;
     includeBody      = true;
 }
Esempio n. 4
0
 public MessageMessage(string from, string to, string message, string type, string from_nick, bool reciptRequested) : base(from, to)
 {
     this.MESSAGE          = message;
     this.TYPE             = type;
     this.toasted          = false;
     this.cacheUntilSend   = true;
     this.delay            = DateTime.MinValue;
     this.FROM_NICK        = from_nick;
     this.RECIPT_REQUESTED = reciptRequested;
     this.CC_TYPE          = CarbonCopyType.NONE;
     this.includeBody      = true;
 }
Esempio n. 5
0
        public OmemoMessageMessage(XmlNode node, CarbonCopyType ccType) : base(node, ccType)
        {
            this.KEYS = new List <OmemoKey>();
            XmlNode encryptedNode = XMLUtils.getChildNode(node, "encrypted", Consts.XML_XMLNS, Consts.XML_XEP_0384_NAMESPACE);

            if (encryptedNode != null)
            {
                this.ENCRYPTED = true;
                XmlNode headerNode = XMLUtils.getChildNode(encryptedNode, "header");
                if (headerNode != null)
                {
                    if (uint.TryParse(headerNode.Attributes["sid"]?.Value, out uint sid))
                    {
                        this.SOURCE_DEVICE_ID = sid;
                    }

                    foreach (XmlNode n in headerNode.ChildNodes)
                    {
                        switch (n.Name)
                        {
                        case "key":
                            this.KEYS.Add(new OmemoKey(n));
                            break;

                        case "iv":
                            this.BASE_64_IV = n.InnerText;
                            break;

                        default:
                            break;
                        }
                    }
                }

                XmlNode payloadNode = XMLUtils.getChildNode(encryptedNode, "payload");
                if (payloadNode != null)
                {
                    this.BASE_64_PAYLOAD = payloadNode.InnerText;
                }
            }
        }
Esempio n. 6
0
        private void parseMessageMessage(List <AbstractMessage> messages, XmlNode n, CarbonCopyType ccType)
        {
            // XEP-0085 (chat state):
            if (XMLUtils.getChildNode(n, Consts.XML_XMLNS, Consts.XML_XEP_0085_NAMESPACE) != null)
            {
                messages.Add(new ChatStateMessage(n));

                // Chat state messages can contain a body:
                if (XMLUtils.getChildNode(n, "body") != null)
                {
                    messages.Add(new MessageMessage(n, ccType));
                }
            }
            // XEP-0384 (OMEMO Encryption):
            else if (XMLUtils.getChildNode(n, "encrypted", Consts.XML_XMLNS, Consts.XML_XEP_0384_NAMESPACE) != null)
            {
                messages.Add(new OmemoMessageMessage(n, ccType));
            }
            // XEP-0184 (Message Delivery Receipts):
            else if (XMLUtils.getChildNode(n, "received", Consts.XML_XMLNS, Consts.XML_XEP_0184_NAMESPACE) != null)
            {
                messages.Add(new DeliveryReceiptMessage(n));
            }
            // XEP-0249 (Direct MUC Invitations):
            else if (XMLUtils.getChildNode(n, "x", Consts.XML_XMLNS, Consts.XML_XEP_0249_NAMESPACE) != null)
            {
                messages.Add(new DirectMUCInvitationMessage(n));
            }
            // Message:
            else if (XMLUtils.getChildNode(n, "body") != null)
            {
                messages.Add(new MessageMessage(n, ccType));
            }
            // XEP-0045 (MUC room subject):
            else if (XMLUtils.getChildNode(n, "subject") != null)
            {
                messages.Add(new MUCRoomSubjectMessage(n));
            }
            else
            {
                // XEP-0280 (Message Carbons):
                bool    sendCC   = false;
                XmlNode carbNode = XMLUtils.getChildNode(n, "received", Consts.XML_XMLNS, Consts.XML_XEP_0280_NAMESPACE);
                if (carbNode == null)
                {
                    sendCC   = true;
                    carbNode = XMLUtils.getChildNode(n, "sent", Consts.XML_XMLNS, Consts.XML_XEP_0280_NAMESPACE);
                }
                if (carbNode != null)
                {
                    XmlNode forwardedNode = XMLUtils.getChildNode(carbNode, "forwarded", Consts.XML_XMLNS, Consts.XML_XEP_0280_NAMESPACE_FORWARDED);
                    if (forwardedNode != null)
                    {
                        XmlNode messageNode = XMLUtils.getChildNode(forwardedNode, "message");
                        if (messageNode != null)
                        {
                            parseMessageMessage(messages, messageNode, sendCC ? CarbonCopyType.SENT : CarbonCopyType.RECEIVED);
                        }
                    }
                }

                // XEP-0060 (Publish-Subscribe) events:
                XmlNode eventNode = XMLUtils.getChildNode(n, "event", Consts.XML_XMLNS, Consts.XML_XEP_0060_NAMESPACE_EVENT);
                if (eventNode != null)
                {
                    // XEP-0384 (OMEMO Encryption) device list:
                    if (XMLUtils.getChildNode(eventNode, "items", "node", Consts.XML_XEP_0384_DEVICE_LIST_NODE) != null)
                    {
                        messages.Add(new OmemoDeviceListEventMessage(n));
                    }
                }
            }
        }
Esempio n. 7
0
 //--------------------------------------------------------Constructor:----------------------------------------------------------------\\
 #region --Constructors--
 public EncryptedMessage(XmlNode node, CarbonCopyType ccType) : base(node, ccType)
 {
 }