public ClamWinScanRequest(ClamWinScanner.ActionID id) { Action = id; if (Action == ClamWinScanner.ActionID.GetInfo) { UpdateRequestText(); } }
/// <summary> /// Figure out action name by id /// </summary> /// <param name="Action">Action id</param> /// <returns>Action name</returns> public static string GetActionName(ClamWinScanner.ActionID Action) { switch (Action) { case ActionID.GetInfo: return("getinfo"); case ActionID.ReloadDB: return("reloaddb"); case ActionID.Scan: return("scan"); case ActionID.FsFilterControl: return("fsfiltercontrol"); case ActionID.AsyncScan: return("asynscan"); case ActionID.AsyncResult: return("asynresult"); case ActionID.AsyncAbortScan: return("asynabortscan"); case ActionID.RegisterGui: return("registergui"); case ActionID.UnregisterGui: return("unregistergui"); case ActionID.GetFilterJob: return("getfilterjob"); default: return("notdefined"); } }
public ClamWinScanResponse(string text) { XmlDocument document = new XmlDocument(); XmlNode root; XmlNode action; try { document.LoadXml(text); root = document.SelectSingleNode("clamwinreply"); action = root.SelectSingleNode("action"); } catch { Action = ClamWinScanner.ActionID.NotDefined; return; } Action = ClamWinScanner.GetActionID(action.InnerText); switch (Action) { case ClamWinScanner.ActionID.GetInfo: { try { XmlNode core = root.SelectSingleNode("core"); XmlNode libclamav = root.SelectSingleNode("libclamav"); XmlNode main = root.SelectSingleNode("main"); XmlNode daily = root.SelectSingleNode("daily"); XmlNode fsfilter = root.SelectSingleNode("fsfilter"); Core = core.InnerText; LibClamav = libclamav.InnerText; Main = main.InnerText; Daily = daily.InnerText; FsFilter = Convert.ToByte(fsfilter.InnerText) == 1 ? true : false; } catch { Action = ClamWinScanner.ActionID.NotDefined; return; } break; } case ClamWinScanner.ActionID.ReloadDB: { try { XmlNode status = root.SelectSingleNode("status"); Status = ClamWinScanner.StringToStatus(status.InnerText); } catch { Action = ClamWinScanner.ActionID.NotDefined; return; } break; } case ClamWinScanner.ActionID.Scan: { try { XmlNode status = root.SelectSingleNode("status"); Status = ClamWinScanner.StringToStatus(status.InnerText); try { XmlNode code = status.SelectSingleNode("@code"); if (code != null) { Code = Convert.ToInt32(code.InnerText); } } catch { } try { XmlNode virusname = root.SelectSingleNode("virusname"); if (VirusName != null) { VirusName = virusname.InnerText; } } catch { } XmlNode filename = root.SelectSingleNode("filename"); FileName = filename.InnerText; } catch { Action = ClamWinScanner.ActionID.NotDefined; return; } break; } case ClamWinScanner.ActionID.FsFilterControl: { try { XmlNode status = root.SelectSingleNode("status"); Status = ClamWinScanner.StringToStatus(status.InnerText); } catch { Action = ClamWinScanner.ActionID.NotDefined; return; } break; } case ClamWinScanner.ActionID.AsyncScan: { try { XmlNode filename = root.SelectSingleNode("filename"); FileName = filename.InnerText; try { XmlNode jobid = root.SelectSingleNode("jobid"); if (jobid != null) { JobID = int.Parse(jobid.InnerText); } else { JobID = -1; } } catch { JobID = -1; } try { XmlNode status = root.SelectSingleNode("status"); if (status != null) { Status = ClamWinScanner.StringToStatus(status.InnerText); try { XmlNode code = status.SelectSingleNode("@code"); if (code != null) { Code = Convert.ToInt32(code.InnerText); } } catch { } } else { Status = ClamWinScanner.ResponseStatus.Ok; } } catch { Status = ClamWinScanner.ResponseStatus.Ok; } } catch { Action = ClamWinScanner.ActionID.NotDefined; return; } break; } case ClamWinScanner.ActionID.AsyncResult: { try { XmlNode status = root.SelectSingleNode("status"); Status = ClamWinScanner.StringToStatus(status.InnerText); try { XmlNode code = status.SelectSingleNode("@code"); if (code != null) { Code = Convert.ToInt32(code.InnerText); } } catch { } try { XmlNode progress = root.SelectSingleNode("progress"); if (progress != null) { Progress = Convert.ToInt32(progress.InnerText); } } catch { Progress = -1; } try { XmlNode message = root.SelectSingleNode("message"); if (message != null) { Message = message.InnerText; } } catch { Message = ""; } try { XmlNode virusname = root.SelectSingleNode("virusname"); if (VirusName != null) { VirusName = virusname.InnerText; } } catch { } XmlNode jobid = root.SelectSingleNode("jobid"); JobID = int.Parse(jobid.InnerText); } catch { Action = ClamWinScanner.ActionID.NotDefined; return; } break; } case ClamWinScanner.ActionID.AsyncAbortScan: { try { XmlNode jobid = root.SelectSingleNode("jobid"); JobID = int.Parse(jobid.InnerText); XmlNode status = root.SelectSingleNode("status"); Status = ClamWinScanner.StringToStatus(status.InnerText); try { XmlNode code = status.SelectSingleNode("@code"); if (code != null) { Code = Convert.ToInt32(code.InnerText); } } catch { } } catch { Action = ClamWinScanner.ActionID.NotDefined; return; } break; } case ClamWinScanner.ActionID.RegisterGui: case ClamWinScanner.ActionID.UnregisterGui: { try { XmlNode status = root.SelectSingleNode("status"); Status = ClamWinScanner.StringToStatus(status.InnerText); try { XmlNode code = status.SelectSingleNode("@code"); if (code != null) { Code = Convert.ToInt32(code.InnerText); } } catch { } } catch { Action = ClamWinScanner.ActionID.NotDefined; return; } break; } case ClamWinScanner.ActionID.GetFilterJob: { #region try { XmlNode status = root.SelectSingleNode("status"); Status = ClamWinScanner.StringToStatus(status.InnerText); try { XmlNode code = status.SelectSingleNode("@code"); if (code != null) { Code = Convert.ToInt32(code.InnerText); } } catch { } } catch { Action = ClamWinScanner.ActionID.NotDefined; return; } try { XmlNode message = root.SelectSingleNode("message"); if (message != null) { Message = message.InnerText; } } catch { Message = ""; } try { XmlNode filename = root.SelectSingleNode("filename"); if (filename != null) { FileName = filename.InnerText; } } catch { FileName = ""; } #endregion break; } default: { Core = ""; LibClamav = ""; Main = ""; Daily = ""; FsFilter = false; Status = ClamWinScanner.ResponseStatus.NotDefined; FileName = ""; Code = 0; VirusName = ""; JobID = 0; break; } } }