Menu

[r40]: / trunk / WhatsappClient / WhatsAppProtocol / Response / WhatsParser.cs  Maximize  Restore  History

Download this file

154 lines (149 with data), 6.1 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
public class WhatsParser
{
public WhatsSendHandler WhatsSendHandler { get; private set; }
private WhatsNetwork whatsNetwork;
private MessageRecvResponse messResponseHandler;
private BinTreeNodeWriter _binWriter;
internal WhatsParser(WhatsNetwork whatsNet, BinTreeNodeWriter writer)
{
this.WhatsSendHandler = new WhatsSendHandler(whatsNet, writer);
this.whatsNetwork = whatsNet;
this.messResponseHandler = new MessageRecvResponse(this.WhatsSendHandler);
this._binWriter = writer;
}
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))
{
}
}
internal static Dictionary<string, long> ParseCategories(ProtocolTreeNode dirtyNode)
{
var dictionary = new Dictionary<string, long>();
if (dirtyNode.children != null)
{
for (int i = 0; i < dirtyNode.children.Count(); i++)
{
ProtocolTreeNode node = dirtyNode.children.ElementAt(i);
if (ProtocolTreeNode.TagEquals(node, "category"))
{
long num2;
string attributeValue = node.GetAttribute("name");
if (long.TryParse(node.GetAttribute("timestamp"), WhatsConstants.WhatsAppNumberStyle,
CultureInfo.InvariantCulture, out num2))
{
dictionary[attributeValue] = num2;
}
}
}
}
return dictionary;
}
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.