Ejemplo n.º 1
0
        /// <summary>
        /// Updates RequestText memeber corresponding to current parameters
        /// </summary>
        private void UpdateRequestText()
        {
            if (Action == ClamWinScanner.ActionID.NotDefined)
            {
                return;
            }

            RequestText  = "<?xml version=\"1.0\" ?><clamwinrequest>";
            RequestText += "<action>" + ClamWinScanner.GetActionName(Action) + "</action>";

            if (Action == ClamWinScanner.ActionID.ReloadDB)
            {
                RequestText += "<dbpath>";
                RequestText += DbPath;
                RequestText += "</dbpath>";
            }
            else if (Action == ClamWinScanner.ActionID.Scan)
            {
                RequestText += EscapeFilePath(FilePath);
                RequestText += "</filename>";
            }
            else if (Action == ClamWinScanner.ActionID.FsFilterControl)
            {
                RequestText += "<value>";
                RequestText += FsFilterEnabled ? "1" : "0";
                RequestText += "</value>";
            }
            else if (Action == ClamWinScanner.ActionID.AsyncScan)
            {
                RequestText += "<filename>";
                RequestText += EscapeFilePath(FilePath);
                RequestText += "</filename>";
            }
            else if (Action == ClamWinScanner.ActionID.AsyncResult)
            {
                RequestText += "<jobid>";
                RequestText += JobID.ToString();
                RequestText += "</jobid>";
            }
            else if (Action == ClamWinScanner.ActionID.AsyncAbortScan)
            {
                RequestText += "<jobid>";
                RequestText += JobID.ToString();
                RequestText += "</jobid>";
            }
            else if (Action == ClamWinScanner.ActionID.RegisterGui ||
                     Action == ClamWinScanner.ActionID.UnregisterGui)
            {
                RequestText += "<value>";
                RequestText += Value.ToString();
                RequestText += "</value>";
            }
            RequestText += "</clamwinrequest>";
        }
Ejemplo n.º 2
0
        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;
            }
            }
        }