/*## (c) SECURITY EXPLORATIONS    2018 poland                                #*/
/*##     http://www.security-explorations.com                                #*/

/* THIS SOFTWARE IS PROTECTED BY DOMESTIC AND INTERNATIONAL COPYRIGHT LAWS    */
/* UNAUTHORISED COPYING OF THIS SOFTWARE IN EITHER SOURCE OR BINARY FORM IS   */
/* EXPRESSLY FORBIDDEN. ANY USE, INCLUDING THE REPRODUCTION, MODIFICATION,    */
/* DISTRIBUTION, TRANSMISSION, RE-PUBLICATION, STORAGE OR DISPLAY OF ANY      */
/* PART OF THE SOFTWARE, FOR COMMERCIAL OR ANY OTHER PURPOSES REQUIRES A      */
/* VALID LICENSE FROM THE COPYRIGHT HOLDER.                                   */

/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS    */
/* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,*/
/* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL    */
/* SECURITY EXPLORATIONS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, */
/* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF  */
/* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE     */
/* SOFTWARE.                                                                  */

import java.lang.*;
import java.io.*;
import java.lang.reflect.*;
import com.adb.xion.net.*;
import tv.osmosys.net.*;
import tv.osmosys.net.ssl.*;
import com.adb.xion.net.www.content.*;

public class ProxyHTTPConnection extends com.adb.xion.net.nativehttp.URIConnection {
 private static Field fhttpreq;
 ProxyOutputStream proxyoutput;

 static {
  try {
   Class c=Class.forName("com.adb.xion.net.nativehttp.URIConnection");
   fhttpreq=c.getDeclaredField("request");
   fhttpreq.setAccessible(true);
  } catch(Throwable t) {}
 }

 public ProxyHTTPConnection(URI uri,long l,int i) throws URIConnectionException {
  super(uri);
 }

 public ProxyHTTPConnection(URI uri,long l,int i,SSLContext sslcontext) throws URIConnectionException {
  super(uri);
 }

 public ProxyHTTPConnection(URI uri) throws URIConnectionException {
  super(uri);
 }

 public void internalConnect() {  
  try {
   String serial="BZZxxxxxxxxxxxxxx";
 
   setRequestProperty("nBoxSerialNumber",serial);
   setRequestProperty("X-nBox-SerialNumber",serial);

   super.internalConnect();

   HTTPSniffer.log(getURI(),get_request(),proxyoutput!=null ? proxyoutput.get_output_data():null);
  } catch(Throwable t) {}
 }

 public HttpRequest get_request() {
  HttpRequest req=null;

  try {
   req=(HttpRequest)fhttpreq.get(this);
  } catch(Throwable t) {}

  return req;
 }

 public OutputStream openOutputStream() {
  proxyoutput=new ProxyOutputStream();

  return proxyoutput;
 }
}
