/// <summary> /// a line was received, this method parses it and calls methods /// in the management logic. /// </summary> /// <param name="sender">ignored</param> /// <param name="e">information about the received line</param> /// <remarks> /// This method is not thread save! /// But there is no need to call it from more than one thread. /// Only the thread which holds the management connection calls this event. /// </remarks> private void oc_gotLine(object sender, GotLineEventArgs e) { // drop a line m_logs.logDebugLine(10, "Got: " + e.line); string s = e.line; // some lines start with a ">" (see link above) // they come asynchron and are parsed imediately if (s.StartsWith(">")) { string type = s.Substring(1, s.IndexOf(":") - 1); string msg = s.Substring(type.Length + 2); string[] infos = null; AsyncEventDetail.EventType et = AsyncEventDetail.EventType.UNKNOWN; switch (type) { case "ECHO": et = AsyncEventDetail.EventType.ECHO; break; case "FATAL": et = AsyncEventDetail.EventType.FATAL; break; case "HOLD": et = AsyncEventDetail.EventType.HOLD; break; case "INFO": et = AsyncEventDetail.EventType.INFO; break; case "LOG": et = AsyncEventDetail.EventType.LOG; break; case "NEED-STR": et = AsyncEventDetail.EventType.NEEDSTR; string tmp = msg.Substring(msg.IndexOf('\'') + 1); infos = new string[] { tmp.Substring(0, tmp.IndexOf('\'')) }; break; case "STATE": et = AsyncEventDetail.EventType.STATE; infos = msg.Split(new char[] { ',' }); break; case "PASSWORD": et = AsyncEventDetail.EventType.PASSWORD; // Several messages format are possible // * first is a request for a passwd // >PASSWORD:Need 'Auth' username/password // or // >PASSWORD:Need 'Private Key' password // // * second is a notification // >PASSWORD:Verification Failed: 'Auth' // or // >PASSWORD:Verification Failed: 'Private Key' // Let's first determine the PASSWORD message type and thus format string messType = msg.Substring(0, msg.IndexOf(' ')); // "Need" or "Verification" if (messType.CompareTo("Need") == 0) { string tmp2 = msg.Substring(msg.IndexOf('\'') + 1); string loginProfile = tmp2.Substring(0, tmp2.IndexOf('\'')); // 'Auth' or 'Private Key' or ... string loginInfo = tmp2.Substring(tmp2.IndexOf('\'') + 2); // "password" or "username/password" infos = new string[] { loginProfile, loginInfo, messType }; } else if (messType.CompareTo("Verification") == 0) { string verifMsg = msg.Substring(0, msg.IndexOf(':')); // "Verification Failed" if (verifMsg.CompareTo("Verification Failed") == 0) { string tmp2 = msg.Substring(msg.IndexOf('\'') + 1); string loginProfile = tmp2.Substring(0, tmp2.IndexOf('\'')); // 'Auth' or 'Private Key' or ... infos = new string[] { loginProfile, null, verifMsg }; } } break; } if (et != AsyncEventDetail.EventType.UNKNOWN) { m_ol.got_asyncEvent(new AsyncEventDetail(et, msg, infos)); return; } } m_received.Append(s + Environment.NewLine); s = m_received.ToString(); if (s.StartsWith("SUCCESS: ") || s.StartsWith("ERROR: ") || s.StartsWith(">") || s.EndsWith("END" + Environment.NewLine)) { m_received.Remove(0, m_received.Length); m_ol.cb_syncEvent(s); } }
/// <summary> /// a line was received, this method parses it and calls methods /// in the management logic. /// </summary> /// <param name="sender">ignored</param> /// <param name="e">information about the received line</param> /// <remarks> /// This method is not thread save! /// But there is no need to call it from more than one thread. /// Only the thread which holds the management connection calls this event. /// </remarks> private void oc_gotLine(object sender, GotLineEventArgs e) { string s = e.line; // some lines start with a ">" (see link above) // they come asynchron and are parsed imediately if (s.StartsWith(">", StringComparison.OrdinalIgnoreCase)) { string type = s.Substring(1, s.IndexOf(":", StringComparison.OrdinalIgnoreCase) - 1); string msg = s.Substring(type.Length + 2); string[] infos = null; AsyncEventDetail.EventType et = AsyncEventDetail.EventType.UNKNOWN; switch (type) { case "ECHO": et = AsyncEventDetail.EventType.ECHO; break; case "FATAL": et = AsyncEventDetail.EventType.FATAL; break; case "HOLD": et = AsyncEventDetail.EventType.HOLD; break; case "INFO": et = AsyncEventDetail.EventType.INFO; break; case "LOG": et = AsyncEventDetail.EventType.LOG; break; case "NEED-STR": et = AsyncEventDetail.EventType.NEEDSTR; string tmp = msg.Substring(msg.IndexOf('\'') + 1); infos = new string[] {tmp.Substring(0,tmp.IndexOf('\''))}; break; case "STATE": et = AsyncEventDetail.EventType.STATE; infos = msg.Split(new char[] { ',' }); break; case "PASSWORD": et = AsyncEventDetail.EventType.PASSWORD; // Several messages format are possible // * first is a request for a passwd // >PASSWORD:Need 'Auth' username/password // or // >PASSWORD:Need 'Private Key' password // // * second is a notification // >PASSWORD:Verification Failed: 'Auth' // or // >PASSWORD:Verification Failed: 'Private Key' // Let's first determine the PASSWORD message type and thus format // "Need" or "Verification" if(msg.StartsWith("Need", StringComparison.OrdinalIgnoreCase)) { string tmp2 = msg.Substring(msg.IndexOf('\'') + 1); string loginProfile = tmp2.Substring(0, tmp2.IndexOf('\'')); // 'Auth' or 'Private Key' or ... string loginInfo = tmp2.Substring(tmp2.IndexOf('\'') + 2); // "password" or "username/password" infos = new string[] { loginProfile, loginInfo, "Need" }; } // "Verification Failed" else if(msg.StartsWith("Verification Failed:", StringComparison.OrdinalIgnoreCase)) { string tmp2 = msg.Substring(msg.IndexOf('\'') + 1); string loginProfile = tmp2.Substring(0, tmp2.IndexOf('\'')); // 'Auth' or 'Private Key' or ... infos = new string[] { loginProfile, null, "Verification" }; } break; } if (et != AsyncEventDetail.EventType.UNKNOWN) { m_logic.got_asyncEvent(new AsyncEventDetail(et, msg, infos)); return; } } m_received.Append(s + Environment.NewLine); s = m_received.ToString(); if (s.StartsWith("SUCCESS: ", StringComparison.OrdinalIgnoreCase) || s.StartsWith("ERROR: ", StringComparison.OrdinalIgnoreCase) || s.StartsWith(">", StringComparison.OrdinalIgnoreCase) || s.EndsWith("END" + Environment.NewLine, StringComparison.OrdinalIgnoreCase)) { m_received.Remove(0, m_received.Length); m_logic.cb_syncEvent(s); } }