GetAllChildren() public méthode

public GetAllChildren ( ) : IEnumerable
Résultat IEnumerable
Exemple #1
0
        private void TypeError(ProtocolTreeNode messageNode, string tmpAttrbId, string tmpAttrFrom)
        {
            int num2 = 0;

            foreach (ProtocolTreeNode node in messageNode.GetAllChildren("error"))
            {
                string tmpCode = node.GetAttribute("code");
                try
                {
                    num2 = int.Parse(tmpCode, CultureInfo.InvariantCulture);
                }
                catch (Exception)
                {
                }
            }
            if ((tmpAttrFrom != null) && (tmpAttrbId != null))
            {
                FMessage.Key key = new FMessage.Key(tmpAttrFrom, true, tmpAttrbId);
                //ErrorHandler handler = null;
                //if (trackedMessages.TryGetValue(key, out handler))
                //{
                //    trackedMessages.Remove(key);
                //    handler.OnError(num2);
                //}
                //else
                //{
                //    this.EventHandler.OnMessageError(key, num2);
                //}
            }
        }
 private void TypeNotification(ProtocolTreeNode messageNode, string tmpAttrFrom, string tmpAttrbId)
 {
     foreach (ProtocolTreeNode tmpChild in (messageNode.GetAllChildren() ?? new ProtocolTreeNode[0]))
     {
         if (ProtocolTreeNode.TagEquals(tmpChild, "notification"))
         {
             string tmpChildType = tmpChild.GetAttribute("type");
             if (StringComparer.Ordinal.Equals(tmpChildType, "picture"))
             {
                 TypeNotificationPicture(tmpChild, tmpAttrFrom);
             }
         }
         else if (ProtocolTreeNode.TagEquals(tmpChild, "request"))
         {
             this.sendHandler.SendNotificationReceived(tmpAttrFrom, tmpAttrbId);
         }
     }
 }
 private static void TypeNotificationPicture(ProtocolTreeNode tmpChild, string tmpFrom)
 {
     foreach (ProtocolTreeNode item in (tmpChild.GetAllChildren() ?? new ProtocolTreeNode[0]))
     {
         if (ProtocolTreeNode.TagEquals(item, "set"))
         {
             string photoId = item.GetAttribute("id");
             if (photoId != null)
             {
                 WhatsEventHandler.OnPhotoChangedEventHandler(tmpFrom, item.GetAttribute("author"), photoId);
             }
         }
         else if (ProtocolTreeNode.TagEquals(item, "delete"))
         {
             WhatsEventHandler.OnPhotoChangedEventHandler(tmpFrom, item.GetAttribute("author"), null);
         }
     }
 }
 private static void TypeNotificationPicture(ProtocolTreeNode tmpChild, string tmpFrom)
 {
     foreach (ProtocolTreeNode item in (tmpChild.GetAllChildren() ?? new ProtocolTreeNode[0]))
     {
         if (ProtocolTreeNode.TagEquals(item, "set"))
         {
             string photoId = item.GetAttribute("id");
             if (photoId != null)
             {
                 WhatsEventHandler.OnPhotoChangedEventHandler(tmpFrom, item.GetAttribute("author"), photoId);
             }
         }
         else if (ProtocolTreeNode.TagEquals(item, "delete"))
         {
             WhatsEventHandler.OnPhotoChangedEventHandler(tmpFrom, item.GetAttribute("author"), null);
         }
     }
 }
    private void TypeError(ProtocolTreeNode messageNode, string tmpAttrbId, string tmpAttrFrom)
    {
        int num2 = 0;

        foreach (ProtocolTreeNode node in messageNode.GetAllChildren("error"))
        {
            string tmpCode = node.GetAttribute("code");
            try
            {
                num2 = int.Parse(tmpCode, CultureInfo.InvariantCulture);
            }
            catch (Exception)
            {
            }
        }
        if ((tmpAttrFrom != null) && (tmpAttrbId != null))
        {
            FMessage.Key key = new FMessage.Key(tmpAttrFrom, true, tmpAttrbId);
        }
    }
Exemple #6
0
        private void TypeSubject(ProtocolTreeNode messageNode, string tmpFrom, string uJid, string tmpId, string tmpT)
        {
            bool flag = false;

            foreach (ProtocolTreeNode item in messageNode.GetAllChildren("request"))
            {
                if (item.GetAttribute("xmlns").Equals("urn:xmpp:receipts"))
                {
                    flag = true;
                }
            }
            ProtocolTreeNode child   = messageNode.GetChild("body");
            string           subject = (child == null) ? null : child.GetDataString();

            if (subject != null)
            {
                WhatsEventHandler.OnGroupNewSubjectEventHandler(tmpFrom, uJid, subject, int.Parse(tmpT, CultureInfo.InvariantCulture));
            }
            if (flag)
            {
                this.sendHandler.SendSubjectReceived(tmpFrom, tmpId);
            }
        }
 public void ParseProtocolNode(ProtocolTreeNode protNode)
 {
     if (ProtocolTreeNode.TagEquals(protNode, "iq"))
     {
         string attributeValue = protNode.GetAttribute("type");
         string id             = protNode.GetAttribute("id");
         string str3           = protNode.GetAttribute("from");
         if (attributeValue == null)
         {
             throw new Exception("Message-Corrupt: missing 'type' attribute in iq stanza");
         }
         if (!attributeValue.Equals("result"))
         {
             if (attributeValue.Equals("error"))
             {
             }
             else if (!attributeValue.Equals("get"))
             {
                 if (!attributeValue.Equals("set"))
                 {
                     throw new Exception("Message-Corrupt: unknown iq type attribute: " + attributeValue);
                 }
                 ProtocolTreeNode child = protNode.GetChild("query");
                 if (child != null)
                 {
                     string str8 = child.GetAttribute("xmlns");
                     if ("jabber:iq:roster" == str8)
                     {
                         foreach (ProtocolTreeNode node5 in child.GetAllChildren("item"))
                         {
                             node5.GetAttribute("jid");
                             node5.GetAttribute("subscription");
                             node5.GetAttribute("ask");
                         }
                     }
                 }
             }
             else
             {
                 ProtocolTreeNode node3 = protNode.GetChild("ping");
                 if (node3 != null)
                 {
                     // this.EventHandler.OnPing(id);
                 }
                 else if ((!ProtocolTreeNode.TagEquals(node3, "query") ||
                           (str3 == null)) &&
                          (ProtocolTreeNode.TagEquals(node3, "relay") &&
                           (str3 != null)))
                 {
                     int    num;
                     string pin        = node3.GetAttribute("pin");
                     string tmpTimeout = node3.GetAttribute("timeout");
                     if (
                         !int.TryParse(tmpTimeout ?? "0", WhatsConstants.WhatsAppNumberStyle, CultureInfo.InvariantCulture,
                                       out num))
                     {
                         throw new CorruptStreamException("relay-iq exception parsing timeout attribute: " + tmpTimeout);
                     }
                     if (pin != null)
                     {
                     }
                 }
             }
         }
         else
         {
             // todo: implent
         }
     }
     else if (ProtocolTreeNode.TagEquals(protNode, "presence"))
     {
         string str9 = protNode.GetAttribute("xmlns");
         string jid  = protNode.GetAttribute("from");
         if (((str9 == null) || "urn:xmpp".Equals(str9)) && (jid != null))
         {
             string str11 = protNode.GetAttribute("type");
             if ("unavailable".Equals(str11))
             {
             }
             else if ((str11 == null) || "available".Equals(str11))
             {
             }
         }
         else if ("w".Equals(str9) && (jid != null))
         {
             string str12 = protNode.GetAttribute("add");
             string str13 = protNode.GetAttribute("remove");
             string str14 = protNode.GetAttribute("status");
             if (str12 == null)
             {
                 if (str13 == null)
                 {
                     if ("dirty".Equals(str14))
                     {
                         Dictionary <string, long> categories = ParseCategories(protNode);
                     }
                 }
             }
         }
     }
     else if (ProtocolTreeNode.TagEquals(protNode, "message"))
     {
         this.messResponseHandler.ParseMessageRecv(protNode);
     }
     else if ((ProtocolTreeNode.TagEquals(protNode, "ib") /*&& (this.EventHandler != null)*/) &&
              (protNode.GetChild("offline") != null))
     {
     }
 }
Exemple #8
0
 protected void handleIq(ProtocolTreeNode node)
 {
     if (node.GetAttribute("type") == "error")
     {
         this.fireOnError(node.GetAttribute("id"), node.GetAttribute("from"), Int32.Parse(node.GetChild("error").GetAttribute("code")), node.GetChild("error").GetAttribute("text"));
     }
     if (node.GetChild("sync") != null)
     {
         //sync result
         ProtocolTreeNode sync        = node.GetChild("sync");
         ProtocolTreeNode existing    = sync.GetChild("in");
         ProtocolTreeNode nonexisting = sync.GetChild("out");
         //process existing first
         Dictionary <string, string> existingUsers = new Dictionary <string, string>();
         foreach (ProtocolTreeNode child in existing.GetAllChildren())
         {
             existingUsers.Add(System.Text.Encoding.UTF8.GetString(child.GetData()), child.GetAttribute("jid"));
         }
         //now process failed numbers
         List <string> failedNumbers = new List <string>();
         foreach (ProtocolTreeNode child in nonexisting.GetAllChildren())
         {
             failedNumbers.Add(System.Text.Encoding.UTF8.GetString(child.GetData()));
         }
         int index = 0;
         Int32.TryParse(sync.GetAttribute("index"), out index);
         this.fireOnGetSyncResult(index, sync.GetAttribute("sid"), existingUsers, failedNumbers.ToArray());
     }
     if (node.GetAttribute("type").Equals("result", StringComparison.OrdinalIgnoreCase) &&
         node.children.FirstOrDefault().tag == "query" &&
         node.children.FirstOrDefault().GetAttribute("xmlns") == "jabber:iq:last"
         )
     {
         //last seen
         DateTime lastSeen = DateTime.Now.AddSeconds(double.Parse(node.children.FirstOrDefault().GetAttribute("seconds")) * -1);
         this.fireOnGetLastSeen(node.GetAttribute("from"), lastSeen);
     }
     if (node.GetAttribute("type").Equals("result", StringComparison.OrdinalIgnoreCase) &&
         (ProtocolTreeNode.TagEquals(node.children.FirstOrDefault(), "media") || ProtocolTreeNode.TagEquals(node.children.FirstOrDefault(), "duplicate"))
         )
     {
         //media upload
         this.uploadResponse = node;
     }
     if (node.GetAttribute("type").Equals("result", StringComparison.OrdinalIgnoreCase) &&
         ProtocolTreeNode.TagEquals(node.children.FirstOrDefault(), "picture")
         )
     {
         //profile picture
         string from = node.GetAttribute("from");
         string id   = node.GetChild("picture").GetAttribute("id");
         byte[] dat  = node.GetChild("picture").GetData();
         string type = node.GetChild("picture").GetAttribute("type");
         if (type == "preview")
         {
             this.fireOnGetPhotoPreview(from, id, dat);
         }
         else
         {
             this.fireOnGetPhoto(from, id, dat);
         }
     }
     if (node.GetAttribute("type").Equals("get", StringComparison.OrdinalIgnoreCase) &&
         ProtocolTreeNode.TagEquals(node.children.FirstOrDefault(), "ping"))
     {
         this.SendPong(node.GetAttribute("id"));
     }
     if (node.GetAttribute("type").Equals("result", StringComparison.OrdinalIgnoreCase) &&
         ProtocolTreeNode.TagEquals(node.children.FirstOrDefault(), "group"))
     {
         //group(s) info
         List <WaGroupInfo> groups = new List <WaGroupInfo>();
         foreach (ProtocolTreeNode group in node.children)
         {
             groups.Add(new WaGroupInfo(
                            group.GetAttribute("id"),
                            group.GetAttribute("owner"),
                            long.Parse(group.GetAttribute("creation")),
                            group.GetAttribute("subject"),
                            long.Parse(group.GetAttribute("s_t")),
                            group.GetAttribute("s_o")
                            ));
         }
         this.fireOnGetGroups(groups.ToArray());
     }
     if (node.GetAttribute("type").Equals("result", StringComparison.OrdinalIgnoreCase) &&
         ProtocolTreeNode.TagEquals(node.children.FirstOrDefault(), "participant"))
     {
         //group participants
         List <string> participants = new List <string>();
         foreach (ProtocolTreeNode part in node.GetAllChildren())
         {
             if (part.tag == "participant" && !string.IsNullOrEmpty(part.GetAttribute("jid")))
             {
                 participants.Add(part.GetAttribute("jid"));
             }
         }
         this.fireOnGetGroupParticipants(node.GetAttribute("from"), participants.ToArray());
     }
     if (node.GetAttribute("type") == "result" && node.GetChild("status") != null)
     {
         foreach (ProtocolTreeNode status in node.GetChild("status").GetAllChildren())
         {
             this.fireOnGetStatus(status.GetAttribute("jid"),
                                  "result",
                                  null,
                                  WhatsApp.SYSEncoding.GetString(status.GetData()));
         }
     }
 }
Exemple #9
0
        private void TypeChat(ProtocolTreeNode messageNode, string tmpAttrFrom, string tmpAttrbId, FMessage.Builder builder,
                              string tmpAttrFromJid)
        {
            //bool duplicate = false;
            foreach (ProtocolTreeNode itemNode in (messageNode.GetAllChildren() ?? new ProtocolTreeNode[0]))
            {
                if (ProtocolTreeNode.TagEquals(itemNode, "composing"))
                {
                    WhatsEventHandler.OnIsTypingEventHandler(tmpAttrFrom, true);
                }
                else if (ProtocolTreeNode.TagEquals(itemNode, "paused"))
                {
                    WhatsEventHandler.OnIsTypingEventHandler(tmpAttrFrom, false);
                }
                else if (ProtocolTreeNode.TagEquals(itemNode, "body") && (tmpAttrbId != null))
                {
                    string dataString = itemNode.GetDataString();
                    var    tmpMessKey = new FMessage.Key(tmpAttrFrom, false, tmpAttrbId);
                    builder.Key(tmpMessKey).Remote_resource(tmpAttrFromJid).NewIncomingInstance().Data(dataString);
                }
                else if (ProtocolTreeNode.TagEquals(itemNode, "media") && (tmpAttrbId != null))
                {
                    long tmpMediaSize;
                    int  tmpMediaDuration;

                    builder.Media_wa_type(FMessage.GetMessage_WA_Type(itemNode.GetAttribute("type"))).Media_url(
                        itemNode.GetAttribute("url")).Media_name(itemNode.GetAttribute("file"));

                    if (long.TryParse(itemNode.GetAttribute("size"), WhatsConstants.WhatsAppNumberStyle,
                                      CultureInfo.InvariantCulture, out tmpMediaSize))
                    {
                        builder.Media_size(tmpMediaSize);
                    }
                    string tmpAttrSeconds = itemNode.GetAttribute("seconds");
                    if ((tmpAttrSeconds != null) &&
                        int.TryParse(tmpAttrSeconds, WhatsConstants.WhatsAppNumberStyle, CultureInfo.InvariantCulture, out tmpMediaDuration))
                    {
                        builder.Media_duration_seconds(tmpMediaDuration);
                    }

                    if (builder.Media_wa_type().HasValue&& (builder.Media_wa_type().Value == FMessage.Type.Location))
                    {
                        double tmpLatitude      = 0;
                        double tmpLongitude     = 0;
                        string tmpAttrLatitude  = itemNode.GetAttribute("latitude");
                        string tmpAttrLongitude = itemNode.GetAttribute("longitude");
                        if ((tmpAttrLatitude == null) || (tmpAttrLongitude == null))
                        {
                            tmpAttrLatitude  = "0";
                            tmpAttrLongitude = "0";
                        }
                        else if (!double.TryParse(tmpAttrLatitude, WhatsConstants.WhatsAppNumberStyle, CultureInfo.InvariantCulture, out tmpLatitude) ||
                                 !double.TryParse(tmpAttrLongitude, WhatsConstants.WhatsAppNumberStyle, CultureInfo.InvariantCulture, out tmpLongitude))
                        {
                            throw new CorruptStreamException("location message exception parsing lat or long attribute: " + tmpAttrLatitude + " " + tmpAttrLongitude);
                        }

                        builder.Latitude(tmpLatitude).Longitude(tmpLongitude);

                        string tmpAttrName = itemNode.GetAttribute("name");
                        string tmpAttrUrl  = itemNode.GetAttribute("url");
                        if (tmpAttrName != null)
                        {
                            builder.Location_details(tmpAttrName);
                        }
                        if (tmpAttrUrl != null)
                        {
                            builder.Location_url(tmpAttrUrl);
                        }
                    }

                    if (builder.Media_wa_type().HasValue&& (builder.Media_wa_type().Value) == FMessage.Type.Contact)
                    {
                        ProtocolTreeNode tmpChildMedia = itemNode.GetChild("media");
                        if (tmpChildMedia != null)
                        {
                            builder.Media_name(tmpChildMedia.GetAttribute("name")).Data(tmpChildMedia.GetDataString());
                        }
                    }
                    else
                    {
                        string tmpAttrEncoding = itemNode.GetAttribute("encoding") ?? "text";
                        if (tmpAttrEncoding == "text")
                        {
                            builder.Data(itemNode.GetDataString());
                        }
                        //else
                        //{
                        //    builder.BinaryData(messageNode.data);
                        //}
                    }
                    var tmpMessageKey = new FMessage.Key(tmpAttrFrom, false, tmpAttrbId);
                    builder.Key(tmpMessageKey).Remote_resource(tmpAttrFromJid).NewIncomingInstance();
                }
                else if (ProtocolTreeNode.TagEquals(itemNode, "request"))
                {
                    builder.Wants_receipt(true);
                }
                else if (ProtocolTreeNode.TagEquals(itemNode, "x"))
                {
                    string str16 = itemNode.GetAttribute("xmlns");
                    if ("jabber:x:event".Equals(str16) && (tmpAttrbId != null))
                    {
                        var tmpMessageKey = new FMessage.Key(tmpAttrFrom, true, tmpAttrbId);
                        //if (this.EventHandler != null)
                        //{
                        //    ErrorHandler handler2 = null;
                        //    if (trackedMessages.TryGetValue(key4, out handler2))
                        //    {
                        //        trackedMessages.Remove(key4);
                        //        handler2.OnCompleted();
                        //    }
                        //    else
                        //    {
                        //        this.EventHandler.OnMessageStatusUpdate(key4, FMessage.Status.ReceivedByServer);
                        //    }
                        //}
                    }
                }
                else if (ProtocolTreeNode.TagEquals(itemNode, "received"))
                {
                    if (tmpAttrbId != null)
                    {
                        var tmpMessageKey = new FMessage.Key(tmpAttrFrom, true, tmpAttrbId);
                        //if (this.EventHandler != null)
                        //{
                        //    this.EventHandler.OnMessageStatusUpdate(key5, FMessage.Status.ReceivedByTarget);
                        //}
                        if (true) //this.SupportsReceiptAcks)
                        {
                            string tmpAttrType = itemNode.GetAttribute("type");
                            if ((tmpAttrType != null) && !tmpAttrType.Equals("delivered"))
                            {
                                if (tmpAttrType.Equals("visible"))
                                {
                                    this.sendHandler.SendVisibleReceiptAck(tmpAttrFrom, tmpAttrbId);
                                }
                            }
                            else
                            {
                                this.sendHandler.SendDeliveredReceiptAck(tmpAttrFrom, tmpAttrbId);
                            }
                        }
                    }
                }
                else if (ProtocolTreeNode.TagEquals(itemNode, "offline"))
                {
                    builder.Offline(true);
                }
                else if (ProtocolTreeNode.TagEquals(itemNode, "notify"))
                {
                    var tmpAttrName = itemNode.GetAttribute("name");
                    if (tmpAttrName != null)
                    {
                        builder.Key().serverNickname = tmpAttrName;
                    }
                }
            }
            if (!builder.Timestamp().HasValue)
            {
                builder.Timestamp(new DateTime?(DateTime.Now));
            }
            FMessage message = builder.Build();

            if (message != null)
            {
                WhatsEventHandler.OnMessageRecievedEventHandler(message);
            }
        }
Exemple #10
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(), 0, child2.GetData().Length));
                break;

            case "subject":
                //fire username notify
                this.fireOnGetContactName(node.GetAttribute("participant"),
                                          node.GetAttribute("notify"));
                //fire subject notify
                this.fireOnGetGroupSubject(node.GetAttribute("from"),
                                           node.GetAttribute("participant"),
                                           node.GetAttribute("notify"),
                                           System.Text.Encoding.UTF8.GetString(node.GetChild("body").GetData(), 0, node.GetChild("body").GetData().Length),
                                           Helpers.GetDateTimeFromTimestamp(node.GetAttribute("t")));
                break;

            case "contacts":
                //TODO
                break;

            case "participant":
                string gjid = node.GetAttribute("from");
                string t    = node.GetAttribute("t");
                foreach (ProtocolTreeNode child3 in node.GetAllChildren())
                {
                    if (child3.tag == "add")
                    {
                        this.fireOnGetParticipantAdded(gjid,
                                                       child3.GetAttribute("jid"),
                                                       Helpers.GetDateTimeFromTimestamp(t));
                    }
                    else if (child3.tag == "remove")
                    {
                        this.fireOnGetParticipantRemoved(gjid,
                                                         child3.GetAttribute("jid"),
                                                         child3.GetAttribute("author"),
                                                         Helpers.GetDateTimeFromTimestamp(t));
                    }
                    else if (child3.tag == "modify")
                    {
                        this.fireOnGetParticipantRenamed(gjid,
                                                         child3.GetAttribute("remove"),
                                                         child3.GetAttribute("add"),
                                                         Helpers.GetDateTimeFromTimestamp(t));
                    }
                }
                break;
            }
            this.SendNotificationAck(node);
        }
Exemple #11
0
        protected void handleIq(ProtocolTreeNode node)
        {
            #region error iq
            if (node.GetAttribute("type") == "error")
            {
                this.fireOnError(node.GetAttribute("id"), node.GetAttribute("from"), node.GetChild("error").GetAttribute("code"), node.GetChild("error").GetAttribute("text"));
            }
            #endregion

            #region sync iq
            if (node.GetChild("sync") != null)
            {
                //sync result
                ProtocolTreeNode sync        = node.GetChild("sync");
                ProtocolTreeNode existing    = sync.GetChild("in");
                ProtocolTreeNode nonexisting = sync.GetChild("out");
                //process existing first
                Dictionary <string, string> existingUsers = new Dictionary <string, string>();
                if (existing != null)
                {
                    foreach (ProtocolTreeNode child in existing.GetAllChildren())
                    {
                        existingUsers.Add(System.Text.Encoding.UTF8.GetString(child.GetData()), child.GetAttribute("jid"));
                    }
                }
                //now process failed numbers
                List <string> failedNumbers = new List <string>();
                if (nonexisting != null)
                {
                    foreach (ProtocolTreeNode child in nonexisting.GetAllChildren())
                    {
                        failedNumbers.Add(System.Text.Encoding.UTF8.GetString(child.GetData()));
                    }
                }
                int index = 0;
                Int32.TryParse(sync.GetAttribute("index"), out index);
                this.fireOnGetSyncResult(index, sync.GetAttribute("sid"), existingUsers, failedNumbers.ToArray());
            }
            #endregion

            #region type iq
            if (node.GetAttribute("type").Equals("result", StringComparison.OrdinalIgnoreCase) &&
                node.GetChild("query") != null)
            {
                //last seen
                DateTime lastSeen = DateTime.Now.AddSeconds(double.Parse(node.children.FirstOrDefault().GetAttribute("seconds")) * -1);
                this.fireOnGetLastSeen(node.GetAttribute("from"), lastSeen);
            }
            if (node.GetAttribute("type").Equals("result", StringComparison.OrdinalIgnoreCase) &&
                (node.GetChild("media") != null || node.GetChild("duplicate") != null))
            {
                //media upload
                this.uploadResponse = node;
            }

            if (node.GetAttribute("type").Equals("result", StringComparison.OrdinalIgnoreCase) &&
                node.GetChild("picture") != null)
            {
                //profile picture
                string from = node.GetAttribute("from");
                string id   = node.GetChild("picture").GetAttribute("id");
                byte[] dat  = node.GetChild("picture").GetData();
                string type = node.GetChild("picture").GetAttribute("type");
                if (type == "preview")
                {
                    this.fireOnGetPhotoPreview(from, id, dat);
                }
                else
                {
                    this.fireOnGetPhoto(from, id, dat);
                }
            }
            #endregion

            #region ping iq
            if (node.GetAttribute("type").Equals("get", StringComparison.OrdinalIgnoreCase) &&
                node.GetChild("ping") != null)
            {
                this.SendPong(node.GetAttribute("id"));
            }
            #endregion

            #region group result iq
            if (node.GetAttribute("type").Equals("result", StringComparison.OrdinalIgnoreCase) &&
                node.GetChild("group") != null)
            {
                //group(s) info
                List <WaGroupInfo> groups = new List <WaGroupInfo>();
                foreach (ProtocolTreeNode group in node.children)
                {
                    groups.Add(new WaGroupInfo(
                                   group.GetAttribute("id"),
                                   group.GetAttribute("owner"),
                                   group.GetAttribute("creation"),
                                   group.GetAttribute("subject"),
                                   group.GetAttribute("s_t"),
                                   group.GetAttribute("s_o")
                                   ));
                }
                this.fireOnGetGroups(groups.ToArray());
            }
            #endregion

            #region participant result iq
            if (node.GetAttribute("type").Equals("result", StringComparison.OrdinalIgnoreCase) &&
                node.GetChild("participant") != null)
            {
                //group participants
                List <string> participants = new List <string>();
                foreach (ProtocolTreeNode part in node.GetAllChildren())
                {
                    if (part.tag == "participant" && !string.IsNullOrEmpty(part.GetAttribute("jid")))
                    {
                        participants.Add(part.GetAttribute("jid"));
                    }
                }
                this.fireOnGetGroupParticipants(node.GetAttribute("from"), participants.ToArray());
            }
            #endregion

            #region status result iq
            if (node.GetAttribute("type") == "result" && node.GetChild("status") != null)
            {
                foreach (ProtocolTreeNode status in node.GetChild("status").GetAllChildren())
                {
                    this.fireOnGetStatus(status.GetAttribute("jid"),
                                         "result",
                                         null,
                                         WhatsApp.SYSEncoding.GetString(status.GetData()));
                }
            }
            #endregion

            #region privacy result iq
            if (node.GetAttribute("type") == "result" && node.GetChild("privacy") != null)
            {
                Dictionary <VisibilityCategory, VisibilitySetting> settings = new Dictionary <VisibilityCategory, VisibilitySetting>();
                foreach (ProtocolTreeNode child in node.GetChild("privacy").GetAllChildren("category"))
                {
                    settings.Add(this.parsePrivacyCategory(
                                     child.GetAttribute("name")),
                                 this.parsePrivacySetting(child.GetAttribute("value"))
                                 );
                }
                this.fireOnGetPrivacySettings(settings);
            }
            #endregion

            #region cipherKeys iq BRIAN
            ProtocolTreeNode[] pnodes = ProcessIqTreeNode(node);
            if (pnodes != null)
            {
                foreach (ProtocolTreeNode pnode in pnodes)
                {
                    this.handleMessage(pnode, true);
                }
            }
            #endregion
        }
    private void TypeChat(ProtocolTreeNode messageNode, string tmpAttrFrom, string tmpAttrbId, FMessage.Builder builder,
                                    string tmpAttrFromJid)
    {
        foreach (ProtocolTreeNode itemNode in (messageNode.GetAllChildren() ?? new ProtocolTreeNode[0]))
        {
            if (ProtocolTreeNode.TagEquals(itemNode, "composing"))
            {
                WhatsEventHandler.OnIsTypingEventHandler(tmpAttrFrom, true);
            }
            else if (ProtocolTreeNode.TagEquals(itemNode, "paused"))
            {
                WhatsEventHandler.OnIsTypingEventHandler(tmpAttrFrom, false);
            }
            else if (ProtocolTreeNode.TagEquals(itemNode, "body") && (tmpAttrbId != null))
            {
                string dataString = Encoding.UTF8.GetString(itemNode.GetData());
                var tmpMessKey = new FMessage.Key(tmpAttrFrom, false, tmpAttrbId);
                builder.Key(tmpMessKey).Remote_resource(tmpAttrFromJid).NewIncomingInstance().Data(dataString);
            }
            else if (ProtocolTreeNode.TagEquals(itemNode, "media") && (tmpAttrbId != null))
            {
                long tmpMediaSize;
                int tmpMediaDuration;

                builder.Media_wa_type(FMessage.GetMessage_WA_Type(itemNode.GetAttribute("type"))).Media_url(
                    itemNode.GetAttribute("url")).Media_name(itemNode.GetAttribute("file"));

                if (long.TryParse(itemNode.GetAttribute("size"), WhatsConstants.WhatsAppNumberStyle,
                                    CultureInfo.InvariantCulture, out tmpMediaSize))
                {
                    builder.Media_size(tmpMediaSize);
                }
                string tmpAttrSeconds = itemNode.GetAttribute("seconds");
                if ((tmpAttrSeconds != null) &&
                    int.TryParse(tmpAttrSeconds, WhatsConstants.WhatsAppNumberStyle, CultureInfo.InvariantCulture, out tmpMediaDuration))
                {
                    builder.Media_duration_seconds(tmpMediaDuration);
                }

                if (builder.Media_wa_type().HasValue && (builder.Media_wa_type().Value == FMessage.Type.Location))
                {
                    double tmpLatitude = 0;
                    double tmpLongitude = 0;
                    string tmpAttrLatitude = itemNode.GetAttribute("latitude");
                    string tmpAttrLongitude = itemNode.GetAttribute("longitude");
                    if ((tmpAttrLatitude == null) || (tmpAttrLongitude == null))
                    {
                        tmpAttrLatitude = "0";
                        tmpAttrLongitude = "0";
                    }
                    else if (!double.TryParse(tmpAttrLatitude, WhatsConstants.WhatsAppNumberStyle, CultureInfo.InvariantCulture, out tmpLatitude) ||
                        !double.TryParse(tmpAttrLongitude, WhatsConstants.WhatsAppNumberStyle, CultureInfo.InvariantCulture, out tmpLongitude))
                    {
                        throw new CorruptStreamException("location message exception parsing lat or long attribute: " + tmpAttrLatitude + " " + tmpAttrLongitude);
                    }

                    builder.Latitude(tmpLatitude).Longitude(tmpLongitude);

                    string tmpAttrName = itemNode.GetAttribute("name");
                    string tmpAttrUrl = itemNode.GetAttribute("url");
                    if (tmpAttrName != null)
                    {
                        builder.Location_details(tmpAttrName);
                    }
                    if (tmpAttrUrl != null)
                    {
                        builder.Location_url(tmpAttrUrl);
                    }
                }

                if (builder.Media_wa_type().HasValue && (builder.Media_wa_type().Value) == FMessage.Type.Contact)
                {
                    ProtocolTreeNode tmpChildMedia = itemNode.GetChild("media");
                    if (tmpChildMedia != null)
                    {
                        builder.Media_name(tmpChildMedia.GetAttribute("name")).Data(Encoding.UTF8.GetString(tmpChildMedia.GetData()));
                    }
                }
                else
                {
                    string tmpAttrEncoding = itemNode.GetAttribute("encoding") ?? "text";
                    if (tmpAttrEncoding == "text")
                    {
                        builder.Data(Encoding.UTF8.GetString(itemNode.GetData()));
                    }
                }
                var tmpMessageKey = new FMessage.Key(tmpAttrFrom, false, tmpAttrbId);
                builder.Key(tmpMessageKey).Remote_resource(tmpAttrFromJid).NewIncomingInstance();
            }
            else if (ProtocolTreeNode.TagEquals(itemNode, "request"))
            {
                builder.Wants_receipt(true);
            }
            else if (ProtocolTreeNode.TagEquals(itemNode, "x"))
            {
                string str16 = itemNode.GetAttribute("xmlns");
                if ("jabber:x:event".Equals(str16) && (tmpAttrbId != null))
                {
                    var tmpMessageKey = new FMessage.Key(tmpAttrFrom, true, tmpAttrbId);
                }
            }
            else if (ProtocolTreeNode.TagEquals(itemNode, "received"))
            {
                if (tmpAttrbId != null)
                {
                    var tmpMessageKey = new FMessage.Key(tmpAttrFrom, true, tmpAttrbId);
                    if (true)
                    {
                        string tmpAttrType = itemNode.GetAttribute("type");
                        if ((tmpAttrType != null) && !tmpAttrType.Equals("delivered"))
                        {
                            if (tmpAttrType.Equals("visible"))
                            {
                                this.sendHandler.SendVisibleReceiptAck(tmpAttrFrom, tmpAttrbId);
                            }
                        }
                        else
                        {
                            this.sendHandler.SendDeliveredReceiptAck(tmpAttrFrom, tmpAttrbId);
                        }
                    }
                }
            }
            else if (ProtocolTreeNode.TagEquals(itemNode, "offline"))
            {
                builder.Offline(true);
            }
            else if (ProtocolTreeNode.TagEquals(itemNode, "notify"))
            {
                var tmpAttrName = itemNode.GetAttribute("name");
                if (tmpAttrName != null)
                {
                    builder.from_me = false;
                    builder.id = tmpAttrbId;
                    builder.remote_jid = tmpAttrFromJid;
                    builder.Key().serverNickname = tmpAttrName;
                }
            }
        }
        if (!builder.Timestamp().HasValue)
        {
            builder.Timestamp(new DateTime?(DateTime.Now));
        }
        FMessage message = builder.Build();
        if (message != null)
        {
            WhatsEventHandler.OnMessageRecievedEventHandler(message);
        }
    }
 private void TypeSubject(ProtocolTreeNode messageNode, string tmpFrom, string uJid, string tmpId, string tmpT)
 {
     bool flag = false;
     foreach (ProtocolTreeNode item in messageNode.GetAllChildren("request"))
     {
         if (item.GetAttribute("xmlns").Equals("urn:xmpp:receipts"))
         {
             flag = true;
         }
     }
     ProtocolTreeNode child = messageNode.GetChild("body");
     //string subject = (child == null) ? null : child.GetDataString();
     string subject = (child == null) ? null : WhatsAppProtocol.SYSEncoding.GetString(child.GetData());
     if (subject != null)
     {
         WhatsEventHandler.OnGroupNewSubjectEventHandler(tmpFrom, uJid, subject, int.Parse(tmpT, CultureInfo.InvariantCulture));
     }
     if (flag)
     {
         this.sendHandler.SendSubjectReceived(tmpFrom, tmpId);
     }
 }
 private void TypeNotification(ProtocolTreeNode messageNode, string tmpAttrFrom, string tmpAttrbId)
 {
     foreach (ProtocolTreeNode tmpChild in (messageNode.GetAllChildren() ?? new ProtocolTreeNode[0]))
     {
         if (ProtocolTreeNode.TagEquals(tmpChild, "notification"))
         {
             string tmpChildType = tmpChild.GetAttribute("type");
             if (StringComparer.Ordinal.Equals(tmpChildType, "picture"))
             {
                 TypeNotificationPicture(tmpChild, tmpAttrFrom);
             }
         }
         else if (ProtocolTreeNode.TagEquals(tmpChild, "request"))
         {
             this.sendHandler.SendNotificationReceived(tmpAttrFrom, tmpAttrbId);
         }
     }
 }
 private void TypeError(ProtocolTreeNode messageNode, string tmpAttrbId, string tmpAttrFrom)
 {
     int num2 = 0;
     foreach (ProtocolTreeNode node in messageNode.GetAllChildren("error"))
     {
         string tmpCode = node.GetAttribute("code");
         try
         {
             num2 = int.Parse(tmpCode, CultureInfo.InvariantCulture);
         }
         catch (Exception)
         {
         }
     }
     if ((tmpAttrFrom != null) && (tmpAttrbId != null))
     {
         FMessage.Key key = new FMessage.Key(tmpAttrFrom, true, tmpAttrbId);
     }
 }
 public void ParseProtocolNode(ProtocolTreeNode protNode)
 {
     if (ProtocolTreeNode.TagEquals(protNode, "iq"))
     {
         string attributeValue = protNode.GetAttribute("type");
         string id             = protNode.GetAttribute("id");
         string str3           = protNode.GetAttribute("from");
         if (attributeValue == null)
         {
             throw new Exception("Message-Corrupt: missing 'type' attribute in iq stanza");
         }
         if (!attributeValue.Equals("result"))
         {
             if (attributeValue.Equals("error"))
             {
                 //IqResultHandler handler2 = this.PopIqHandler(id);
                 //if (handler2 != null)
                 //{
                 //    handler2.ErrorNode(node);
                 //}
             }
             else if (!attributeValue.Equals("get"))
             {
                 if (!attributeValue.Equals("set"))
                 {
                     throw new Exception("Message-Corrupt: unknown iq type attribute: " + attributeValue);
                 }
                 ProtocolTreeNode child = protNode.GetChild("query");
                 if (child != null)
                 {
                     string str8 = child.GetAttribute("xmlns");
                     if ("jabber:iq:roster" == str8)
                     {
                         foreach (ProtocolTreeNode node5 in child.GetAllChildren("item"))
                         {
                             node5.GetAttribute("jid");
                             node5.GetAttribute("subscription");
                             node5.GetAttribute("ask");
                         }
                     }
                 }
             }
             else
             {
                 ProtocolTreeNode node3 = protNode.GetChild("ping");
                 if (node3 != null)
                 {
                     //this.EventHandler.OnPing(id);
                 }
                 else if ((!ProtocolTreeNode.TagEquals(node3, "query") ||
                           (str3 == null)) &&
                          (ProtocolTreeNode.TagEquals(node3, "relay") &&
                           (str3 != null)))
                 {
                     int    num;
                     string pin        = node3.GetAttribute("pin");
                     string tmpTimeout = node3.GetAttribute("timeout");
                     if (
                         !int.TryParse(tmpTimeout ?? "0", WhatsConstants.WhatsAppNumberStyle, CultureInfo.InvariantCulture,
                                       out num))
                     {
                         //throw new CorruptStreamException(
                         //    "relay-iq exception parsing timeout attribute: " + tmpTimeout);
                     }
                     if (pin != null)
                     {
                         //this.EventHandler.OnRelayRequest(pin, num, id);
                     }
                 }
             }
         }
         else
         {
             //IqResultHandler handler = this.PopIqHandler(id);
             //if (handler != null)
             //{
             //    handler.Parse(node, str3);
             //}
             //else if (id.StartsWith(this.Login.User))
             //{
             //    ProtocolNode node2 = node.GetChild(0);
             //    ProtocolNode.Require(node2, "account");
             //    string str4 = node2.GetAttribute("kind");
             //    if ("paid".Equals(str4))
             //    {
             //        this.account_kind = AccountKind.Paid;
             //    }
             //    else if ("free".Equals(str4))
             //    {
             //        this.account_kind = AccountKind.Free;
             //    }
             //    else
             //    {
             //        this.account_kind = AccountKind.Unknown;
             //    }
             //    string s = node2.GetAttribute("expiration");
             //    if (s == null)
             //    {
             //        throw new IOException("no expiration");
             //    }
             //    try
             //    {
             //        this.expire_date = long.Parse(s, CultureInfo.InvariantCulture);
             //    }
             //    catch (FormatException)
             //    {
             //        throw new IOException("invalid expire date: " + s);
             //    }
             //    this.EventHandler.OnAccountChange(this.account_kind, this.expire_date);
             //}
         }
     }
     else if (ProtocolTreeNode.TagEquals(protNode, "presence"))
     {
         string str9 = protNode.GetAttribute("xmlns");
         string jid  = protNode.GetAttribute("from");
         if (((str9 == null) || "urn:xmpp".Equals(str9)) && (jid != null))
         {
             string str11 = protNode.GetAttribute("type");
             if ("unavailable".Equals(str11))
             {
                 //this.EventHandler.OnAvailable(jid, false);
             }
             else if ((str11 == null) || "available".Equals(str11))
             {
                 //this.EventHandler.OnAvailable(jid, true);
             }
         }
         else if ("w".Equals(str9) && (jid != null))
         {
             string str12 = protNode.GetAttribute("add");
             string str13 = protNode.GetAttribute("remove");
             string str14 = protNode.GetAttribute("status");
             if (str12 == null)
             {
                 if (str13 == null)
                 {
                     if ("dirty".Equals(str14))
                     {
                         Dictionary <string, long> categories = ParseCategories(protNode);
                         //this.EventHandler.OnDirty(categories);
                     }
                 }
                 //else if (this.GroupEventHandler != null)
                 //{
                 //    this.GroupEventHandler.OnGroupRemoveUser(jid, str13);
                 //}
             }
             //else if (this.GroupEventHandler != null)
             //{
             //    this.GroupEventHandler.OnGroupAddUser(jid, str12);
             //}
         }
     }
     else if (ProtocolTreeNode.TagEquals(protNode, "message"))
     {
         this.messResponseHandler.ParseMessageRecv(protNode);
     }
     else if ((ProtocolTreeNode.TagEquals(protNode, "ib") /*&& (this.EventHandler != null)*/) &&
              (protNode.GetChild("offline") != null))
     {
         //this.EventHandler.OnOfflineMessagesCompleted();
     }
 }