This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Sophos SAV-DI ICAP code sample

Hi everyone,

I was wondering if someone had a working example of using Sophos SAV-DI ICAP protocol to scan a file.

What I have so far is as follows (in C#):

            byte[] buffer = new byte[1024];
            int iRx;
            
            byte[] filestream = ReadFileToArray(@"C:\SophosCLI\testFile.txt");

            string retDesc = String.Empty;
            var soc = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            var remoteEndPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 1344);

            soc.Connect(remoteEndPoint);

            



            

            if (soc.Connected) {

                Console.WriteLine("Success connecting");

                string cmd = "RESPMOD icap://localhost:1344/AVSCAN?action=SCAN ICAP/1.0\n";
                cmd += "Host: localhost:1344\n";
                cmd += "Preview: 4\n";
                cmd += "Allow: 204\n";
                cmd += "Encapsulated: req-hdr=0, res-hdr=83, res-body=130\n";
                cmd = cmd + "\n";
                cmd += "GET http://localhost/testFile.txt HTTP/1.1\n";
                cmd += "Host: localhost\n\n";
                cmd += "HTTP/1.1 200 OK\n";
                cmd += "Transfer-Encoding: chunked\n";
                cmd += String.Format("{0:X2}", filestream.Length);
                Console.WriteLine(cmd);
                soc.Send(System.Text.Encoding.ASCII.GetBytes(cmd));
                soc.Send(filestream);
                cmd = "\n";
                cmd += "\n";
                cmd += "0\n";
                cmd += "\n";
                Console.WriteLine(cmd);
                soc.Send(System.Text.Encoding.ASCII.GetBytes(cmd));
             


                while ((soc.Connected) && ((iRx = soc.Receive(buffer)) > 0)) {
                    char[] chars = new char[iRx];

                    System.Text.Decoder d = System.Text.Encoding.UTF8.GetDecoder();
                    int charLen = d.GetChars(buffer, 0, iRx, chars, 0);
                    System.String szData = new System.String(chars);

                    retDesc = retDesc + szData;
                }

            }
            Console.WriteLine(retDesc);

            
            Console.Read();
            Environment.Exit(0);

 As you can see, I am positive that I have many errors especially in my request headers.

If I can see a working example I might have something to work with or a starting point but as you can see from my code above I am lost without it so it'll be so helpful to see something that works. 

What I want to get: I want to be able to either send a file to the sophos engine and get a response OR send a bite array to the sophos engine. I just cant figure out how to attach either.

Any help will be much appreciated!!!

:46237


This thread was automatically locked due to age.
Parents
  • Thanks for the file, unfortunately it is using the Sophos SSSP which I was hoping to avoid for portability into other engines later. Any change someone can help me out with some code examples in ANY language for scanning ANYTHING using Sophos's ICAP protocol? 

    I really cannot find a single example online.

    Thanks in advance!

    :46261
Reply
  • Thanks for the file, unfortunately it is using the Sophos SSSP which I was hoping to avoid for portability into other engines later. Any change someone can help me out with some code examples in ANY language for scanning ANYTHING using Sophos's ICAP protocol? 

    I really cannot find a single example online.

    Thanks in advance!

    :46261
Children
No Data