with GNATCOM.IInterface;

with GNATCOM.Errors;

package body MSHTML.IHTMLXMLHttpRequest_Interface is

   procedure Initialize (This : in out IHTMLXMLHttpRequest_Type) is
   begin
      Set_IID (This, IID_IHTMLXMLHttpRequest);
   end Initialize;

   function Pointer (This : IHTMLXMLHttpRequest_Type)
     return Pointer_To_IHTMLXMLHttpRequest
   is
   begin
      return To_Pointer_To_IHTMLXMLHttpRequest (Address (This));
   end Pointer;

   procedure Attach (This    : in out IHTMLXMLHttpRequest_Type;
                     Pointer : in     Pointer_To_IHTMLXMLHttpRequest)
   is
   begin
      Attach (This, GNATCOM.IInterface.To_Pointer_To_IUnknown
              (Pointer.all'Address));
   end Attach;

   function Get_readyState
     (This : IHTMLXMLHttpRequest_Type)
     return Interfaces.C.long
   is
       RetVal : aliased Interfaces.C.long;
   begin
      GNATCOM.Errors.Error_Check
        (Pointer (This).Vtbl.Get_readyState
         (Pointer (This),
          RetVal'Unchecked_Access));

      return RetVal;
   end Get_readyState;

   function Get_responseBody
     (This : IHTMLXMLHttpRequest_Type)
     return GNATCOM.Types.VARIANT
   is
       RetVal : aliased GNATCOM.Types.VARIANT;
   begin
      GNATCOM.Errors.Error_Check
        (Pointer (This).Vtbl.Get_responseBody
         (Pointer (This),
          RetVal'Unchecked_Access));

      return RetVal;
   end Get_responseBody;

   function Get_responseText
     (This : IHTMLXMLHttpRequest_Type)
     return GNATCOM.Types.BSTR
   is
       RetVal : aliased GNATCOM.Types.BSTR;
   begin
      GNATCOM.Errors.Error_Check
        (Pointer (This).Vtbl.Get_responseText
         (Pointer (This),
          RetVal'Unchecked_Access));

      return RetVal;
   end Get_responseText;

   function Get_responseXML
     (This : IHTMLXMLHttpRequest_Type)
     return GNATCOM.Types.Pointer_To_IDispatch
   is
       RetVal : aliased GNATCOM.Types.Pointer_To_IDispatch;
   begin
      GNATCOM.Errors.Error_Check
        (Pointer (This).Vtbl.Get_responseXML
         (Pointer (This),
          RetVal'Unchecked_Access));

      return RetVal;
   end Get_responseXML;

   function Get_status
     (This : IHTMLXMLHttpRequest_Type)
     return Interfaces.C.long
   is
       RetVal : aliased Interfaces.C.long;
   begin
      GNATCOM.Errors.Error_Check
        (Pointer (This).Vtbl.Get_status
         (Pointer (This),
          RetVal'Unchecked_Access));

      return RetVal;
   end Get_status;

   function Get_statusText
     (This : IHTMLXMLHttpRequest_Type)
     return GNATCOM.Types.BSTR
   is
       RetVal : aliased GNATCOM.Types.BSTR;
   begin
      GNATCOM.Errors.Error_Check
        (Pointer (This).Vtbl.Get_statusText
         (Pointer (This),
          RetVal'Unchecked_Access));

      return RetVal;
   end Get_statusText;

   procedure Put_onreadystatechange
     (This : IHTMLXMLHttpRequest_Type;
      p    : GNATCOM.Types.VARIANT;
      Free : Boolean := True)
   is
   begin
      GNATCOM.Errors.Error_Check
        (Pointer (This).Vtbl.Put_onreadystatechange
         (Pointer (This),
          p));

      if Free then
               GNATCOM.IInterface.Free (p);
      
      end if;

   end Put_onreadystatechange;

   function Get_onreadystatechange
     (This : IHTMLXMLHttpRequest_Type)
     return GNATCOM.Types.VARIANT
   is
       RetVal : aliased GNATCOM.Types.VARIANT;
   begin
      GNATCOM.Errors.Error_Check
        (Pointer (This).Vtbl.Get_onreadystatechange
         (Pointer (This),
          RetVal'Unchecked_Access));

      return RetVal;
   end Get_onreadystatechange;

   procedure uabort
     (This : IHTMLXMLHttpRequest_Type)
   is
   begin
      GNATCOM.Errors.Error_Check
        (Pointer (This).Vtbl.uabort
         (Pointer (This)));

   end uabort;

   procedure open
     (This        : IHTMLXMLHttpRequest_Type;
      bstrMethod  : GNATCOM.Types.BSTR;
      bstrURL     : GNATCOM.Types.BSTR;
      varAsync    : GNATCOM.Types.VARIANT;
      varUser     : GNATCOM.Types.VARIANT  := GNATCOM.Types.VARIANT_MISSING;
      varPassword : GNATCOM.Types.VARIANT  := GNATCOM.Types.VARIANT_MISSING;
      Free        : Boolean := True)
   is
   begin
      GNATCOM.Errors.Error_Check
        (Pointer (This).Vtbl.open
         (Pointer (This),
          bstrMethod,
          bstrURL,
          varAsync,
          varUser,
          varPassword));

      if Free then
               GNATCOM.IInterface.Free (bstrMethod);
               GNATCOM.IInterface.Free (bstrURL);
               GNATCOM.IInterface.Free (varAsync);
               GNATCOM.IInterface.Free (varUser);
               GNATCOM.IInterface.Free (varPassword);
      
      end if;

   end open;

   procedure send
     (This    : IHTMLXMLHttpRequest_Type;
      varBody : GNATCOM.Types.VARIANT  := GNATCOM.Types.VARIANT_MISSING;
      Free    : Boolean := True)
   is
   begin
      GNATCOM.Errors.Error_Check
        (Pointer (This).Vtbl.send
         (Pointer (This),
          varBody));

      if Free then
               GNATCOM.IInterface.Free (varBody);
      
      end if;

   end send;

   function getAllResponseHeaders
     (This                            : IHTMLXMLHttpRequest_Type)
     return GNATCOM.Types.BSTR
   is
       RetVal : aliased GNATCOM.Types.BSTR;
   begin
      GNATCOM.Errors.Error_Check
        (Pointer (This).Vtbl.getAllResponseHeaders
         (Pointer (This),
          RetVal'Unchecked_Access));

      return RetVal;
   end getAllResponseHeaders;

   function getResponseHeader
     (This                            : IHTMLXMLHttpRequest_Type;
      bstrHeader                      : GNATCOM.Types.BSTR;
      Free                            : Boolean := True)
     return GNATCOM.Types.BSTR
   is
       RetVal : aliased GNATCOM.Types.BSTR;
   begin
      GNATCOM.Errors.Error_Check
        (Pointer (This).Vtbl.getResponseHeader
         (Pointer (This),
          bstrHeader,
          RetVal'Unchecked_Access));

      if Free then
               GNATCOM.IInterface.Free (bstrHeader);
      
      end if;

      return RetVal;
   end getResponseHeader;

   procedure setRequestHeader
     (This       : IHTMLXMLHttpRequest_Type;
      bstrHeader : GNATCOM.Types.BSTR;
      bstrValue  : GNATCOM.Types.BSTR;
      Free       : Boolean := True)
   is
   begin
      GNATCOM.Errors.Error_Check
        (Pointer (This).Vtbl.setRequestHeader
         (Pointer (This),
          bstrHeader,
          bstrValue));

      if Free then
               GNATCOM.IInterface.Free (bstrHeader);
               GNATCOM.IInterface.Free (bstrValue);
      
      end if;

   end setRequestHeader;

end MSHTML.IHTMLXMLHttpRequest_Interface;

