/// <summary> /// Processes json with discussion info that is loaded when user joins discussion /// </summary> /// <param name="strippedContent">Json decoded from base64-frpc format</param> /// <param name="exportObject">For referencing LideSnooperExport from Lide object</param> /// <param name="discussion">Object with discussion info</param> /// <param name="discussionMsgs">List where loaded discussion messages are stored after parsing</param> /// <param name="users">List where loaded discussion users are stored after parsing</param> /// <param name="photos">List where loaded users photos are stored after parsing</param> private static void ProcessLideDiscussionInfo(string strippedContent, SnooperExportBase exportObject, ref LideDiscussion discussion, List <LideDiscussionMessage> discussionMsgs, List <LideUser> users, List <LidePhoto> photos) { int temp; var o = JObject.Parse(strippedContent); discussion = new LideDiscussion(exportObject) //Parsing of discussion info { Name = o.SelectToken("$.data.discussion.name")?.ToString(), Description = o.SelectToken("$.data.discussion.description")?.ToString(), DiscussionId = Int32.TryParse(o.SelectToken("$.data.discussion.id")?.ToString(), out temp) ? temp : (int?)null }; if (o.SelectToken("$.data.contributions") is JArray) //Parsing messages that already were in discussion when user joined { var messageArray = (JArray)o.SelectToken("$.data.contributions"); foreach (var message in messageArray) { GetLideLoadedDiscussionMessage(message, discussionMsgs, exportObject); if (!(message.SelectToken("$.contributions") is JArray)) //If message contains nested messages { continue; } var nestedMessageArray = (JArray)message.SelectToken("$.contributions"); foreach (var nestedMessage in nestedMessageArray) { GetLideLoadedDiscussionMessage(nestedMessage, discussionMsgs, exportObject); } } } if (string.IsNullOrEmpty(o.SelectToken("$.data.contributing_users")?.ToString())) //If Json does not contain informations about users { return; } var contributingUsers = o.SelectToken("$.data.contributing_users"); foreach (var user in contributingUsers.Children()) { if (!(user is JProperty)) { continue; } var usrProperty = (JProperty)user; GetLideUser(usrProperty.Value, users, exportObject); GetLidePhoto(usrProperty.Value, photos, users[users.Count - 1].Nickname, exportObject); } }
protected override void ProcessConversation() { //Lists used for storing data before export LideDiscussion discussion = null; var discussionMsgs = new List <LideDiscussionMessage>(); var users = new List <LideUser>(); var photos = new List <LidePhoto>(); var prvtMsgs = new List <LidePrivateMessage>(); var parsedJsons = new List <string>(); foreach (var snooperExportBase in this.SourceExports) { foreach (var exportedObject in snooperExportBase.ExportObjects) { this.OnBeforeProtocolParsing(); var httpObject = exportedObject as SnooperExportedDataObjectHTTP; if (httpObject == null) // skip exports from invalid snooper { break; } var httpMsg = httpObject.Message; var httpContent = httpMsg.HTTPContent; // every message from Lide.cz has content if (httpContent?.Content == null) { continue; } var httpRequestHeader = httpMsg.HTTPHeader as HttpRequestHeader; if (httpRequestHeader != null) //skip HTTP requests { continue; } var strippedContent = Encoding.Default.GetString(httpContent.Content); var type = GetMessageType(httpMsg.HTTPHeader, ref strippedContent, parsedJsons); switch (type) { case "discussionLoadedCnt": //Parses info about discussion, messages that were loaded when user joined, etc. this.OnAfterProtocolParsing(); this.OnBeforeDataExporting(); ProcessLideDiscussionInfo(strippedContent, this.SnooperExport, ref discussion, discussionMsgs, users, photos); //Export discussion object: discussion.ExportSources.Add(exportedObject.ExportSource); this.SnooperExport.AddExportObject(discussion); foreach (var discussionMessage in discussionMsgs) //Loop through discussion messages { discussionMessage.ExportSources.Add(exportedObject.ExportSource); //Export of discussion message: this.SnooperExport.AddExportObject(discussionMessage); } foreach (var user in users) { user.ExportSources.Add(exportedObject.ExportSource); //Export of users in discussion: this.SnooperExport.AddExportObject(user); } foreach (var photo in photos) { photo.ExportSources.Add(exportedObject.ExportSource); //Export photos of users in discussions: this.SnooperExport.AddExportObject(photo); } this.OnAfterDataExporting(); LideClearLists(discussionMsgs, users, photos, ref discussion, null); //Clear used lists a variables break; case "prvtMsgLoadedCnt": //Messages that were already in conversation, when user joined (messages sent in past) this.OnAfterProtocolParsing(); this.OnBeforeDataExporting(); GetLideLoadedPrivateMessage(strippedContent, this.SnooperExport, prvtMsgs); //Parse decoded json foreach (var privateMessage in prvtMsgs) //Export all objects that were deserialized { privateMessage.ExportSources.Add(exportedObject.ExportSource); this.SnooperExport.AddExportObject(privateMessage); } this.OnAfterDataExporting(); LideClearLists(null, null, null, ref discussion, prvtMsgs); //Clear all used lists and variables break; case "userInfo": //Informations about user this.OnAfterProtocolParsing(); this.OnBeforeDataExporting(); var userInfo = JObject.Parse(strippedContent); var tokenUser = userInfo.SelectToken("$.data.user"); GetLideUser(tokenUser, users, this.SnooperExport); GetLidePhoto(tokenUser, photos, users[0].Nickname, this.SnooperExport); foreach (var user in users) { user.ExportSources.Add(exportedObject.ExportSource); this.SnooperExport.AddExportObject(user); } foreach (var photo in photos) { photo.ExportSources.Add(exportedObject.ExportSource); this.SnooperExport.AddExportObject(photo); } this.OnAfterDataExporting(); LideClearLists(null, users, photos, ref discussion, null); //Clear used lists a variables break; case "contactInfo": //Informations about person that user chatted with this.OnAfterProtocolParsing(); this.OnBeforeDataExporting(); var contactInfo = JObject.Parse(strippedContent); var tokenContact = contactInfo.SelectToken("$.data.contact"); GetLideUser(tokenContact, users, this.SnooperExport); GetLidePhoto(tokenContact, photos, users[0].Nickname, this.SnooperExport); foreach (var user in users) { user.ExportSources.Add(exportedObject.ExportSource); this.SnooperExport.AddExportObject(user); } foreach (var photo in photos) { photo.ExportSources.Add(exportedObject.ExportSource); this.SnooperExport.AddExportObject(photo); } this.OnAfterDataExporting(); LideClearLists(null, users, photos, ref discussion, null); //Clear used lists a variables break; case "realTimePrivateMessage": //Messages that were sent between two users while capturing network traffic this.OnAfterProtocolParsing(); this.OnBeforeDataExporting(); GetLideRealTimePrivateMessages(parsedJsons, this.SnooperExport, prvtMsgs, users, photos); foreach (var msg in prvtMsgs) { msg.ExportSources.Add(exportedObject.ExportSource); this.SnooperExport.AddExportObject(msg); } foreach (var user in users) { user.ExportSources.Add(exportedObject.ExportSource); this.SnooperExport.AddExportObject(user); } foreach (var photo in photos) { photo.ExportSources.Add(exportedObject.ExportSource); this.SnooperExport.AddExportObject(photo); } this.OnAfterDataExporting(); LideClearLists(null, users, photos, ref discussion, prvtMsgs); //Clear used lists a variables break; case "realTimeDiscussionMessage": //Messages that were sent in discussion while caprturing network traffic this.OnAfterProtocolParsing(); this.OnBeforeDataExporting(); GetLideRealTimeDiscussionMessage(parsedJsons, this.SnooperExport, discussionMsgs, photos, users); foreach (var msg in discussionMsgs) { msg.ExportSources.Add(exportedObject.ExportSource); this.SnooperExport.AddExportObject(msg); } foreach (var user in users) { user.ExportSources.Add(exportedObject.ExportSource); this.SnooperExport.AddExportObject(user); } foreach (var photo in photos) { photo.ExportSources.Add(exportedObject.ExportSource); this.SnooperExport.AddExportObject(photo); } this.OnAfterDataExporting(); LideClearLists(discussionMsgs, users, photos, ref discussion, null); break; default: //Not object from Lide.cz continue; } } } }
/// <summary> /// Clears all lists that were used for storing data /// </summary> /// <param name="discussionMsgs">List that contains messages sent in discussion</param> /// <param name="users">List that contains informations about users</param> /// <param name="photos">List that contains profile photos of users</param> /// <param name="discussion">Stores informations about discussion</param> /// <param name="prvtMsgs">List that cointains messages sent in private chat</param> private static void LideClearLists(List <LideDiscussionMessage> discussionMsgs, List <LideUser> users, List <LidePhoto> photos, ref LideDiscussion discussion, List <LidePrivateMessage> prvtMsgs) { discussionMsgs?.Clear(); users?.Clear(); photos?.Clear(); prvtMsgs?.Clear(); discussion = null; }