original_string: public function scan_data_execute_unixsocket($data) {
          $socket = stream_socket_client('unix://' . $this->get_config('pathtounixsocket'), $errno, $errstr, ANTIVIRUS_CLAMAV_SOCKET_TIMEOUT);
          if (!$socket) {
              // Can't open socket for some reason, notify admins.
              $notice = get_string('errorcantopensocket', 'antivirus_clamav', "$errstr ($errno)");
              $this->set_scanning_notice($notice);
              return self::SCAN_RESULT_ERROR;
          } else {
              // Initiate data stream scanning.
              // Using 'n' as command prefix is forcing clamav to only treat \n as newline delimeter,
              // this is to avoid unexpected newline characters on different systems.
              fwrite($socket, "nINSTREAM\n");
              // Send data in chunks of ANTIVIRUS_CLAMAV_SOCKET_CHUNKSIZE size.
              while (strlen($data) > 0) {
                  $chunk = substr($data, 0, ANTIVIRUS_CLAMAV_SOCKET_CHUNKSIZE);
                  $data = substr($data, ANTIVIRUS_CLAMAV_SOCKET_CHUNKSIZE);
                  $size = pack('N', strlen($chunk));
                  fwrite($socket, $size);
                  fwrite($socket, $chunk);
              }
              // Terminate streaming.
              fwrite($socket, pack('N', 0));
  
              $output = stream_get_line($socket, 4096);
              fclose($socket);
  
              // Parse the output.
              return $this->parse_unixsocket_response($output);
          }
      }
code: public function scan_data_execute_unixsocket($data) {
          $socket = stream_socket_client('unix://' . $this->get_config('pathtounixsocket'), $errno, $errstr, ANTIVIRUS_CLAMAV_SOCKET_TIMEOUT);
          if (!$socket) {
              // Can't open socket for some reason, notify admins.
              $notice = get_string('errorcantopensocket', 'antivirus_clamav', "$errstr ($errno)");
              $this->set_scanning_notice($notice);
              return self::SCAN_RESULT_ERROR;
          } else {
              // Initiate data stream scanning.
              // Using 'n' as command prefix is forcing clamav to only treat \n as newline delimeter,
              // this is to avoid unexpected newline characters on different systems.
              fwrite($socket, "nINSTREAM\n");
              // Send data in chunks of ANTIVIRUS_CLAMAV_SOCKET_CHUNKSIZE size.
              while (strlen($data) > 0) {
                  $chunk = substr($data, 0, ANTIVIRUS_CLAMAV_SOCKET_CHUNKSIZE);
                  $data = substr($data, ANTIVIRUS_CLAMAV_SOCKET_CHUNKSIZE);
                  $size = pack('N', strlen($chunk));
                  fwrite($socket, $size);
                  fwrite($socket, $chunk);
              }
              // Terminate streaming.
              fwrite($socket, pack('N', 0));
  
              $output = stream_get_line($socket, 4096);
              fclose($socket);
  
              // Parse the output.
              return $this->parse_unixsocket_response($output);
          }
      }
code_tokens: public function scan_data_execute_unixsocket ( $ data ) { $ socket = stream_socket_client ( 'unix://' . $ this -> get_config ( 'pathtounixsocket' ) , $ errno , $ errstr , ANTIVIRUS_CLAMAV_SOCKET_TIMEOUT ) ; if ( ! $ socket ) { // Can't open socket for some reason, notify admins. $ notice = get_string ( 'errorcantopensocket' , 'antivirus_clamav' , "$errstr ($errno)" ) ; $ this -> set_scanning_notice ( $ notice ) ; return self :: SCAN_RESULT_ERROR ; } else { // Initiate data stream scanning. // Using 'n' as command prefix is forcing clamav to only treat \n as newline delimeter, // this is to avoid unexpected newline characters on different systems. fwrite ( $ socket , "nINSTREAM\n" ) ; // Send data in chunks of ANTIVIRUS_CLAMAV_SOCKET_CHUNKSIZE size. while ( strlen ( $ data ) > 0 ) { $ chunk = substr ( $ data , 0 , ANTIVIRUS_CLAMAV_SOCKET_CHUNKSIZE ) ; $ data = substr ( $ data , ANTIVIRUS_CLAMAV_SOCKET_CHUNKSIZE ) ; $ size = pack ( 'N' , strlen ( $ chunk ) ) ; fwrite ( $ socket , $ size ) ; fwrite ( $ socket , $ chunk ) ; } // Terminate streaming. fwrite ( $ socket , pack ( 'N' , 0 ) ) ; $ output = stream_get_line ( $ socket , 4096 ) ; fclose ( $ socket ) ; // Parse the output. return $ this -> parse_unixsocket_response ( $ output ) ; } }
docstring: Scan data using unix socket.
  
  We are running INSTREAM command and passing data stream in chunks.
  The format of the chunk is: <length><data> where <length> is the size of the following
  data in bytes expressed as a 4 byte unsigned integer in network byte order and <data>
  is the actual chunk. Streaming is terminated by sending a zero-length chunk.
  Do not exceed StreamMaxLength as defined in clamd.conf, otherwise clamd will
  reply with INSTREAM size limit exceeded and close the connection.
  
  @param string $data The varaible containing the data to scan.
  @return int Scanning result constant.
docstring_tokens: Scan data using unix socket .