public ProtocolTreeNode(string tag, IEnumerable<KeyValue> attributeHash, ProtocolTreeNode children = null) { this.tag = tag ?? ""; this.attributeHash = attributeHash ?? new KeyValue[0]; this.children = children != null ? new ProtocolTreeNode[] { children } : new ProtocolTreeNode[0]; this.data = new byte[0]; }
public void ParseMessageRecv(ProtocolTreeNode messageNode) { FMessage.Builder builder = new FMessage.Builder(); string tmpAttrbId = messageNode.GetAttribute("id"); string tmpAttrFrom = messageNode.GetAttribute("from"); string tmpAttrFromName = messageNode.GetAttribute(""); string tmpAttrFromJid = messageNode.GetAttribute("author") ?? ""; string tmpAttrType = messageNode.GetAttribute("type"); string tmpTAttribT = messageNode.GetAttribute("t"); long result = 0L; if (!string.IsNullOrEmpty(tmpTAttribT) && long.TryParse(tmpTAttribT, out result)) { builder.Timestamp(new DateTime?(WhatsConstants.UnixEpoch.AddSeconds((double)result))); } if ("error".Equals(tmpAttrType)) { TypeError(messageNode, tmpAttrbId, tmpAttrFrom); } else if ("subject".Equals(tmpAttrType)) { TypeSubject(messageNode, tmpAttrFrom, tmpAttrFromJid, tmpAttrbId, tmpTAttribT); } else if ("chat".Equals(tmpAttrType)) { TypeChat(messageNode, tmpAttrFrom, tmpAttrbId, builder, tmpAttrFromJid); } else if ("notification".Equals(tmpAttrType)) { TypeNotification(messageNode, tmpAttrFrom, tmpAttrbId); } }
public void AddMessage(ProtocolTreeNode node) { lock (messageLock) { this.messageQueue.Add(node); } }
public void SendClientConfig(string platform, string lg, string lc) { string v = TicketCounter.MakeId("config_"); var child = new ProtocolTreeNode("config", new[] { new KeyValue("xmlns", "urn:xmpp:whatsapp:push"), new KeyValue("platform", platform), new KeyValue("lg", lg), new KeyValue("lc", lc) }); var node = new ProtocolTreeNode("iq", new[] { new KeyValue("id", v), new KeyValue("type", "set"), new KeyValue("to", whatsAppRealm) }, new ProtocolTreeNode[] { child }); //this.whatsNetwork.SendNode(node); this.whatsNetwork.SendData(this._binWriter.Write(node)); }
public byte[] Write(ProtocolTreeNode node, bool encrypt = true) { if (node == null) { this.buffer.Add(0); } else { this.writeInternal(node); } return this.flushBuffer(encrypt); }
public void SendClearDirty(IEnumerable<string> categoryNames) { string id = TicketCounter.MakeId("clean_dirty_"); IEnumerable<ProtocolTreeNode> source = from category in categoryNames select new ProtocolTreeNode("category", new[] { new KeyValue("name", category) }); var child = new ProtocolTreeNode("clean", new[] { new KeyValue("xmlns", "urn:xmpp:whatsapp:dirty") }, source); var node = new ProtocolTreeNode("iq", new[] { new KeyValue("id", id), new KeyValue("type", "set"), new KeyValue("to", "s.whatsapp.net") }, child); this.whatsNetwork.SendData(this._binWriter.Write(node)); }
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); } } }
protected void SendPong(string id) { var node = new ProtocolTreeNode("iq", new[] { new KeyValue("type", "result"), new KeyValue("to", WhatsConstants.WhatsAppRealm), new KeyValue("id", id) }); this.SendNode(node); }
protected void sendMessageReceived(ProtocolTreeNode msg, string type = "read") { FMessage tmpMessage = new FMessage(new FMessage.FMessageIdentifierKey(msg.GetAttribute("from"), true, msg.GetAttribute("id"))); this.SendMessageReceived(tmpMessage, type); }
/// <summary> /// Sends a message to the Whatsapp server to tell that the user is 'online' / 'active' /// </summary> public void SendActive() { var node = new ProtocolTreeNode("presence", new[] { new KeyValue("type", "active") }); this.whatsNetwork.SendData(this._binWriter.Write(node)); }
/// <summary> /// Send a message with a body (Plain text); /// </summary> /// <param name="message">An instance of the FMessage class.</param> internal void SendMessageWithBody(FMessage message) { var child = new ProtocolTreeNode("body", null, null, WhatsApp.SYSEncoding.GetBytes(message.data)); this.whatsNetwork.SendData(this._binWriter.Write(GetMessageNode(message, child))); }
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 SendUnsubscribeMe(string jid) { var node = new ProtocolTreeNode("presence", new[] { new KeyValue("type", "unsubscribe"), new KeyValue("to", jid) }); this.SendNode(node); }
public void SendSetPrivacyBlockedList(IEnumerable<string> jidSet, Action onSuccess, Action<int> onError) { string id = TicketCounter.MakeId("privacy_"); ProtocolTreeNode[] nodeArray = Enumerable.Select<string, ProtocolTreeNode>(jidSet, (Func<string, int, ProtocolTreeNode>)((jid, index) => new ProtocolTreeNode("item", new KeyValue[] { new KeyValue("type", "jid"), new KeyValue("value", jid), new KeyValue("action", "deny"), new KeyValue("order", index.ToString(CultureInfo.InvariantCulture)) }))).ToArray<ProtocolTreeNode>(); var child = new ProtocolTreeNode("list", new KeyValue[] { new KeyValue("name", "default") }, (nodeArray.Length == 0) ? null : nodeArray); var node2 = new ProtocolTreeNode("query", new KeyValue[] { new KeyValue("xmlns", "jabber:iq:privacy") }, child); var node3 = new ProtocolTreeNode("iq", new KeyValue[] { new KeyValue("id", id), new KeyValue("type", "set") }, node2); this.whatsNetwork.SendData(this._binWriter.Write(node3)); }
public void SendSetPhoto(string jid, byte[] bytes, byte[] thumbnailBytes, Action onSuccess, Action<int> onError) { string id = TicketCounter.MakeId("set_photo_"); var list = new List<ProtocolTreeNode> { new ProtocolTreeNode("picture", new[] { new KeyValue("xmlns", "w:profile:picture") }, null, bytes) }; if (thumbnailBytes != null) { list.Add(new ProtocolTreeNode("picture", new[] { new KeyValue("type", "preview") }, null, thumbnailBytes)); } var node = new ProtocolTreeNode("iq", new[] { new KeyValue("id", id), new KeyValue("type", "set"), new KeyValue("to", jid) }, list.ToArray()); this.whatsNetwork.SendData(this._binWriter.Write(node)); }
static void wa_OnGetMessageAudio(ProtocolTreeNode mediaNode, string from, string id, string fileName, int fileSize, string url, byte[] preview) { Console.WriteLine("Got audio from {0}", from, fileName); OnGetMedia(fileName, url, preview); }
public void SendNode(ProtocolTreeNode node) { m_LastSentInfo = DateTime.UtcNow.ToFileTime(); this.SendData(this.BinWriter.Write(node)); }
/// <summary> /// Get the message node /// </summary> /// <param name="message">the message</param> /// <param name="pNode">The protocol tree node</param> /// <returns>An instance of the ProtocolTreeNode class.</returns> internal static ProtocolTreeNode GetMessageNode(FMessage message, ProtocolTreeNode pNode) { return(new ProtocolTreeNode("message", new[] { new KeyValue("to", message.key.remote_jid), new KeyValue("type", "chat"), new KeyValue("id", message.key.id) }, pNode)); }
public void SendNode(ProtocolTreeNode node) { this.whatsNetwork.SendData(this._binWriter.Write(node)); }
protected WaUploadResponse UploadFile(string b64hash, string type, long size, byte[] fileData, string to, string contenttype, string extension) { ProtocolTreeNode media = new ProtocolTreeNode("media", new KeyValue[] { new KeyValue("hash", b64hash), new KeyValue("type", type), new KeyValue("size", size.ToString()) }); string id = TicketManager.GenerateId(); ProtocolTreeNode node = new ProtocolTreeNode("iq", new KeyValue[] { new KeyValue("id", id), new KeyValue("to", WhatsConstants.WhatsAppServer), new KeyValue("type", "set"), new KeyValue("xmlns", "w:m") }, media); this.uploadResponse = null; this.SendNode(node); int i = 0; while (this.uploadResponse == null && i <= 10) { i++; this.pollMessage(); } if (this.uploadResponse != null && this.uploadResponse.GetChild("duplicate") != null) { WaUploadResponse res = new WaUploadResponse(this.uploadResponse); this.uploadResponse = null; return(res); } else { try { string uploadUrl = this.uploadResponse.GetChild("media").GetAttribute("url"); this.uploadResponse = null; Uri uri = new Uri(uploadUrl); string hashname = string.Empty; byte[] buff = MD5.Create().ComputeHash(System.Text.Encoding.Default.GetBytes(b64hash)); StringBuilder sb = new StringBuilder(); foreach (byte b in buff) { sb.Append(b.ToString("X2")); } hashname = String.Format("{0}.{1}", sb.ToString(), extension); string boundary = "zzXXzzYYzzXXzzQQ"; sb = new StringBuilder(); sb.AppendFormat("--{0}\r\n", boundary); sb.Append("Content-Disposition: form-data; name=\"to\"\r\n\r\n"); sb.AppendFormat("{0}\r\n", to); sb.AppendFormat("--{0}\r\n", boundary); sb.Append("Content-Disposition: form-data; name=\"from\"\r\n\r\n"); sb.AppendFormat("{0}\r\n", this.phoneNumber); sb.AppendFormat("--{0}\r\n", boundary); sb.AppendFormat("Content-Disposition: form-data; name=\"file\"; filename=\"{0}\"\r\n", hashname); sb.AppendFormat("Content-Type: {0}\r\n\r\n", contenttype); string header = sb.ToString(); sb = new StringBuilder(); sb.AppendFormat("\r\n--{0}--\r\n", boundary); string footer = sb.ToString(); long clength = size + header.Length + footer.Length; sb = new StringBuilder(); sb.AppendFormat("POST {0}\r\n", uploadUrl); sb.AppendFormat("Content-Type: multipart/form-data; boundary={0}\r\n", boundary); sb.AppendFormat("Host: {0}\r\n", uri.Host); sb.AppendFormat("User-Agent: {0}\r\n", WhatsConstants.UserAgent); sb.AppendFormat("Content-Length: {0}\r\n\r\n", clength); string post = sb.ToString(); TcpClient tc = new TcpClient(uri.Host, 443); SslStream ssl = new SslStream(tc.GetStream()); ssl.AuthenticateAsClient(uri.Host); List <byte> buf = new List <byte>(); buf.AddRange(Encoding.UTF8.GetBytes(post)); buf.AddRange(Encoding.UTF8.GetBytes(header)); buf.AddRange(fileData); buf.AddRange(Encoding.UTF8.GetBytes(footer)); ssl.Write(buf.ToArray(), 0, buf.ToArray().Length); //moment of truth... buff = new byte[1024]; ssl.Read(buff, 0, 1024); string result = Encoding.UTF8.GetString(buff); foreach (string line in result.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries)) { if (line.StartsWith("{")) { string fooo = line.TrimEnd(new char[] { (char)0 }); JavaScriptSerializer jss = new JavaScriptSerializer(); WaUploadResponse resp = jss.Deserialize <WaUploadResponse>(fooo); if (!String.IsNullOrEmpty(resp.url)) { return(resp); } } } } catch (Exception) { } } return(null); }
public void SendInactive() { var node = new ProtocolTreeNode("presence", new[] { new KeyValue("type", "inactive") }); this.SendNode(node); }
public void SendSubjectReceived(string to, string id) { var child = new ProtocolTreeNode("received", new[] { new KeyValue("xmlns", "urn:xmpp:receipts") }); var node = GetSubjectMessage(to, id, child); this.whatsNetwork.SendData(this._binWriter.Write(node)); }
static void wa_OnGetMessageVcard(ProtocolTreeNode vcardNode, string from, string id, string name, byte[] data) { Console.WriteLine("Got vcard \"{0}\" from {1}", name, from); File.WriteAllBytes(string.Format("{0}.vcf", name), data); }
public void SendUnsubscribeMe(string jid) { var node = new ProtocolTreeNode("presence", new[] { new KeyValue("type", "unsubscribe"), new KeyValue("to", jid) }); this.whatsNetwork.SendData(this._binWriter.Write(node)); }
/// <summary> /// Send a pong to a specific user /// </summary> /// <param name="id"></param> public void SendPong(string id) { var node = new ProtocolTreeNode("iq", new[] { new KeyValue("type", "result"), new KeyValue("to", this.whatsAppRealm), new KeyValue("id", id) }); this.whatsNetwork.SendData(this._binWriter.Write(node)); }
internal static ProtocolTreeNode GetMessageNode(FMessage message, ProtocolTreeNode pNode) { return new ProtocolTreeNode("message", new[] { new KeyValue("to", message.key.remote_jid), new KeyValue("type", "chat"), new KeyValue("id", message.key.id) }, pNode); }
protected void writeInternal(ProtocolTreeNode node) { int len = 1; if (node.attributeHash != null) { len += node.attributeHash.Count() * 2; } if (node.children.Any()) { len += 1; } if (node.data.Length > 0) { len += 1; } this.writeListStart(len); this.writeString(node.tag); this.writeAttributes(node.attributeHash); if (node.data.Length > 0) { this.writeBytes(node.data); } if (node.children != null && node.children.Any()) { this.writeListStart(node.children.Count()); foreach (var item in node.children) { this.writeInternal(item); } } }
internal void SendGetGroups(string id, string type) { var child = new ProtocolTreeNode("list", new[] { new KeyValue("xmlns", "w:g"), new KeyValue("type", type) }); var node = new ProtocolTreeNode("iq", new[] { new KeyValue("id", id), new KeyValue("type", "get"), new KeyValue("to", "g.us") }, child); this.whatsNetwork.SendData(this._binWriter.Write(node)); }
protected void sendMessageReceived(ProtocolTreeNode msg) { ProtocolTreeNode requestNode = msg.GetChild("request"); if (requestNode == null || !requestNode.GetAttribute("xmlns").Equals("urn:xmpp:receipts", StringComparison.OrdinalIgnoreCase)) return; FMessage tmpMessage = new FMessage(new FMessage.Key(msg.GetAttribute("from"), true, msg.GetAttribute("id"))); this.WhatsParser.WhatsSendHandler.SendMessageReceived(tmpMessage); }
internal void SendMessageWithBody(FMessage message) { var child = new ProtocolTreeNode("body", null, null, Encoding.UTF8.GetBytes(message.data)); this.whatsNetwork.SendData(this._binWriter.Write(GetMessageNode(message, child))); }
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": //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()), 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"), GetDateTimeFromTimestamp(t)); } else if (child3.tag == "remove") { this.fireOnGetParticipantRemoved(gjid, child3.GetAttribute("jid"), child3.GetAttribute("author"), GetDateTimeFromTimestamp(t)); } else if (child3.tag == "modify") { this.fireOnGetParticipantRenamed(gjid, child3.GetAttribute("remove"), child3.GetAttribute("add"), GetDateTimeFromTimestamp(t)); } } break; } this.SendNotificationAck(node); }
internal void SendMessageWithMedia(FMessage message) { ProtocolTreeNode node; if (FMessage.Type.System == message.media_wa_type) { throw new SystemException("Cannot send system message over the network"); } List<KeyValue> list = new List<KeyValue>(new KeyValue[] { new KeyValue("xmlns", "urn:xmpp:whatsapp:mms"), new KeyValue("type", FMessage.GetMessage_WA_Type_StrValue(message.media_wa_type)) }); if (FMessage.Type.Location == message.media_wa_type) { list.AddRange(new KeyValue[] { new KeyValue("latitude", message.latitude.ToString(CultureInfo.InvariantCulture)), new KeyValue("longitude", message.longitude.ToString(CultureInfo.InvariantCulture)) }); if (message.location_details != null) { list.Add(new KeyValue("name", message.location_details)); } if (message.location_url != null) { list.Add(new KeyValue("url", message.location_url)); } } else if (((FMessage.Type.Contact != message.media_wa_type) && (message.media_name != null)) && ((message.media_url != null) && (message.media_size > 0L))) { list.AddRange(new KeyValue[] { new KeyValue("file", message.media_name), new KeyValue("size", message.media_size.ToString(CultureInfo.InvariantCulture)), new KeyValue("url", message.media_url) }); if (message.media_duration_seconds > 0) { list.Add(new KeyValue("seconds", message.media_duration_seconds.ToString(CultureInfo.InvariantCulture))); } } if ((FMessage.Type.Contact == message.media_wa_type) && (message.media_name != null)) { node = new ProtocolTreeNode("media", list.ToArray(), new ProtocolTreeNode("vcard", new KeyValue[] { new KeyValue("name", message.media_name) }, WhatsAppProtocol.SYSEncoding.GetBytes(message.data))); } else { byte[] data = message.binary_data; if ((data == null) && !string.IsNullOrEmpty(message.data)) { try { data = Convert.FromBase64String(message.data); } catch (Exception) { } } if (data != null) { list.Add(new KeyValue("encoding", "raw")); } node = new ProtocolTreeNode("media", list.ToArray(), null, data); } this.whatsNetwork.SendData(this._binWriter.Write(node)); }
public void SendAvailableForChat(string nickName = null, bool isHidden = false) { var node = new ProtocolTreeNode("presence", new[] { new KeyValue("name", (!String.IsNullOrEmpty(nickName)?nickName:this.name)) }); this.SendNode(node); }
public void SendAvailableForChat(string nickName) { var node = new ProtocolTreeNode("presence", new[] { new KeyValue("name", nickName) }); this.whatsNetwork.SendData(this._binWriter.Write(node)); }
protected static ProtocolTreeNode GetSubjectMessage(string to, string id, ProtocolTreeNode child) { return(new ProtocolTreeNode("message", new[] { new KeyValue("to", to), new KeyValue("type", "subject"), new KeyValue("id", id) }, child)); }
internal void SendVerbParticipants(string gjid, IEnumerable<string> participants, string id, string inner_tag) { IEnumerable<ProtocolTreeNode> source = from jid in participants select new ProtocolTreeNode("participant", new[] { new KeyValue("jid", jid) }); var child = new ProtocolTreeNode(inner_tag, new[] { new KeyValue("xmlns", "w:g") }, source); var node = new ProtocolTreeNode("iq", new[] { new KeyValue("id", id), new KeyValue("type", "set"), new KeyValue("to", gjid) }, child); this.whatsNetwork.SendData(this._binWriter.Write(node)); }
public void SendClose() { var node = new ProtocolTreeNode("presence", new[] { new KeyValue("type", "unavailable") }); this.SendNode(node); }
private void SendReceiptAck(string to, string id, string receiptType) { var tmpChild = new ProtocolTreeNode("ack", new[] { new KeyValue("xmlns", "urn:xmpp:receipts"), new KeyValue("type", receiptType) }); var resultNode = new ProtocolTreeNode("message", new[] { new KeyValue("to", to), new KeyValue("type", "chat"), new KeyValue("id", id) }, tmpChild); this.whatsNetwork.SendData(this._binWriter.Write(resultNode)); }
public void SendPresenceSubscriptionRequest(string to) { var node = new ProtocolTreeNode("presence", new[] { new KeyValue("type", "subscribe"), new KeyValue("to", GetJID(to)) }); this.SendNode(node); }
/// <summary> /// Unsubscribe me /// </summary> /// <param name="jid">The jabber id</param> public void SendUnsubscribeMe(string jid) { var node = new ProtocolTreeNode("presence", new[] { new KeyValue("type", "unsubscribe"), new KeyValue("to", jid) }); this.whatsNetwork.SendData(this._binWriter.Write(node)); }
protected void SendMessageWithBody(FMessage message, bool hidden = false) { var child = new ProtocolTreeNode("body", null, null, WhatsApp.SYSEncoding.GetBytes(message.data)); this.SendNode(GetMessageNode(message, child, hidden)); }
public void SendClientConfig(string platform, string lg, string lc, Uri pushUri, bool preview, bool defaultSetting, bool groupsSetting, IEnumerable<GroupSetting> groups, Action onCompleted, Action<int> onError) { string id = TicketCounter.MakeId("config_"); var node = new ProtocolTreeNode("iq", new[] { new KeyValue("id", id), new KeyValue("type", "set"), new KeyValue("to", "") }, new ProtocolTreeNode[] { new ProtocolTreeNode("config", new[] { new KeyValue("xmlns","urn:xmpp:whatsapp:push"), new KeyValue("platform", platform), new KeyValue("lg", lg), new KeyValue("lc", lc), new KeyValue("clear", "0"), new KeyValue("id", pushUri.ToString()), new KeyValue("preview",preview ? "1" : "0"), new KeyValue("default",defaultSetting ? "1" : "0"), new KeyValue("groups",groupsSetting ? "1" : "0") }, this.ProcessGroupSettings(groups)) }); this.whatsNetwork.SendData(this._binWriter.Write(node)); }
// string name new static void wa_OnGetMessageImage(ProtocolTreeNode mediaNode, string from, string id, string fileName, int size, string url, byte[] preview, string name) { Console.WriteLine("Got image from {0}", from, fileName); OnGetMedia(fileName, url, preview); }
/// <summary> /// Notify typing chat /// </summary> /// <param name="messageNode"></param> /// <param name="tmpAttrFrom"></param> /// <param name="tmpAttrbId"></param> /// <param name="builder"></param> /// <param name="tmpAttrFromJid"></param> 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 = WhatsApp.SYSEncoding.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(WhatsApp.SYSEncoding.GetString(tmpChildMedia.GetData())); } } else { string tmpAttrEncoding = itemNode.GetAttribute("encoding") ?? "text"; if (tmpAttrEncoding == "text") { builder.Data(WhatsApp.SYSEncoding.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 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); } } }
/// <summary> /// Send a subscription request /// </summary> /// <param name="to"></param> public void SendPresenceSubscriptionRequest(string to) { var node = new ProtocolTreeNode("presence", new[] { new KeyValue("type", "subscribe"), new KeyValue("to", to) }); this.whatsNetwork.SendData(this._binWriter.Write(node)); }
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); } }
protected ProtocolTreeNode addAuth() { ProtocolTreeNode node = new ProtocolTreeNode("auth", new KeyValue[] { new KeyValue("xmlns", @"urn:ietf:params:xml:ns:xmpp-sasl"), new KeyValue("mechanism", "WAUTH-1"), new KeyValue("user", Acc.FullPhonenumber) }); return node; }
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); } }
protected ProtocolTreeNode addFeatures() { var child = new ProtocolTreeNode("receipt_acks", null); var childList = new List<ProtocolTreeNode>(); childList.Add(child); var parent = new ProtocolTreeNode("stream:features", null, childList, null); return parent; }
static void wa_OnGetMessage(ProtocolTreeNode node, string from, string id, string name, string message, bool receipt_sent) { Console.WriteLine("Message from {0} {1}: {2}", name, from, message); }
public void SendAvailableForChat(string nickName) { var node = new ProtocolTreeNode("presence", new[] { new KeyValue("name", nickName) }); this.whatsNetwork.SendData(this._binWriter.Write(node)); }
public static bool TagEquals(ProtocolTreeNode node, string _string) { return (((node != null) && (node.tag != null)) && node.tag.Equals(_string, StringComparison.OrdinalIgnoreCase)); }
protected void processChallenge(ProtocolTreeNode node) { _challengeBytes = node.data; }
protected ProtocolTreeNode addAuthResponse_v1_2() { while (this._challengeBytes == null) { this.PollMessages(); System.Threading.Thread.Sleep(500); } Rfc2898DeriveBytes r = new Rfc2898DeriveBytes(Acc.Password, _challengeBytes, 16); this._encryptionKey = r.GetBytes(20); this.reader.Encryptionkey = _encryptionKey; this.writer.Encryptionkey = _encryptionKey; List<byte> b = new List<byte>(); b.AddRange(WhatsAppProtocol.SYSEncoding.GetBytes(Acc.Phonenumber)); b.AddRange(this._challengeBytes); b.AddRange(WhatsAppProtocol.SYSEncoding.GetBytes(Func.GetNowUnixTimestamp().ToString())); byte[] data = b.ToArray(); byte[] response = Encryption.WhatsappEncrypt(_encryptionKey, data, false); var node = new ProtocolTreeNode("response", new KeyValue[] { new KeyValue("xmlns", "urn:ietf:params:xml:ns:xmpp-sasl") }, response); return node; }
protected bool processInboundData(byte[] msgdata, bool autoReceipt = true) { ProtocolTreeNode node = this.reader.nextTree(msgdata); if (node == null) { return(false); } if (ProtocolTreeNode.TagEquals(node, "challenge")) { this.processChallenge(node); } else if (ProtocolTreeNode.TagEquals(node, "success")) { this.loginStatus = CONNECTION_STATUS.LOGGEDIN; this.accountinfo = new AccountInfo(node.GetAttribute("status"), node.GetAttribute("kind"), node.GetAttribute("creation"), node.GetAttribute("expiration")); this.fireOnLoginSuccess(this.phoneNumber, node.GetData()); } else if (ProtocolTreeNode.TagEquals(node, "failure")) { this.loginStatus = CONNECTION_STATUS.UNAUTHORIZED; this.fireOnLoginFailed(node.children.FirstOrDefault().tag); } if (ProtocolTreeNode.TagEquals(node, "receipt")) { string from = node.GetAttribute("from"); string id = node.GetAttribute("id"); string type = node.GetAttribute("type") ?? "delivery"; switch (type) { case "delivery": //delivered to target this.fireOnGetMessageReceivedClient(from, id); break; case "read": //read by target //todo break; case "played": //played by target //todo break; } var list = node.GetChild("list"); if (list != null) { foreach (var receipt in list.GetAllChildren()) { this.fireOnGetMessageReceivedClient(from, receipt.GetAttribute("id")); } } //send ack SendNotificationAck(node, type); } if (ProtocolTreeNode.TagEquals(node, "message")) { this.handleMessage(node, autoReceipt); } if (ProtocolTreeNode.TagEquals(node, "iq")) { this.handleIq(node); } if (ProtocolTreeNode.TagEquals(node, "stream:error")) { var textNode = node.GetChild("text"); if (textNode != null) { string content = WhatsApp.SYSEncoding.GetString(textNode.GetData()); Helper.DebugAdapter.Instance.fireOnPrintDebug("Error : " + content); } this.Disconnect(); } if (ProtocolTreeNode.TagEquals(node, "presence")) { //presence node this.fireOnGetPresence(node.GetAttribute("from"), node.GetAttribute("type")); } if (node.tag == "ib") { foreach (ProtocolTreeNode child in node.children) { switch (child.tag) { case "dirty": this.SendClearDirty(child.GetAttribute("type")); break; case "offline": //this.SendQrSync(null); break; default: throw new NotImplementedException(node.NodeString()); } } } if (node.tag == "chatstate") { string state = node.children.FirstOrDefault().tag; switch (state) { case "composing": this.fireOnGetTyping(node.GetAttribute("from")); break; case "paused": this.fireOnGetPaused(node.GetAttribute("from")); break; default: throw new NotImplementedException(node.NodeString()); } } if (node.tag == "ack") { string cls = node.GetAttribute("class"); if (cls == "message") { //server receipt this.fireOnGetMessageReceivedServer(node.GetAttribute("from"), node.GetAttribute("id")); } } if (node.tag == "notification") { this.handleNotification(node); } return(true); }
protected void processChallenge(ProtocolTreeNode node) { _challengeBytes = node.data; }
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 || node.GetChild("enc") != null) { // text message // encrypted messages have no body node. Instead, the encrypted cipher text is provided within the enc node var contentNode = node.GetChild("body") ?? node.GetChild("enc"); if (contentNode != null) { this.fireOnGetMessage(node, node.GetAttribute("from"), node.GetAttribute("id"), node.GetAttribute("notify"), System.Text.Encoding.UTF8.GetString(contentNode.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); } }
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>(); 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()); } 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); } } if (node.GetAttribute("type").Equals("get", StringComparison.OrdinalIgnoreCase) && node.GetChild("ping") != null) { this.SendPong(node.GetAttribute("id")); } 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()); } 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()); } 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())); } } 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); } }
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(); } }