Initial import: Carteasy Shop (Dev-Stand)
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
Copyright (c) 2008, Adobe Systems Incorporated
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
* Neither the name of Adobe Systems Incorporated nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package com.adobe.net
|
||||
{
|
||||
import flash.net.URLLoader;
|
||||
|
||||
/**
|
||||
* Class that provides a dynamic implimentation of the URLLoader class.
|
||||
*
|
||||
* This class provides no API implimentations. However, since the class is
|
||||
* declared as dynamic, it can be used in place of URLLoader, and allow
|
||||
* you to dynamically attach properties to it (which URLLoader does not allow).
|
||||
*
|
||||
* @langversion ActionScript 3.0
|
||||
* @playerversion Flash 9.0
|
||||
* @tiptext
|
||||
*/
|
||||
public dynamic class DynamicURLLoader extends URLLoader
|
||||
{
|
||||
public function DynamicURLLoader()
|
||||
{
|
||||
super();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
Copyright (c) 2008, Adobe Systems Incorporated
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
* Neither the name of Adobe Systems Incorporated nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package com.adobe.net
|
||||
{
|
||||
/**
|
||||
* The URI class cannot know about DNS aliases, virtual hosts, or
|
||||
* symbolic links that may be involved. The application can provide
|
||||
* an implementation of this interface to resolve the URI before the
|
||||
* URI class makes any comparisons. For example, a web host has
|
||||
* two aliases:
|
||||
*
|
||||
* <p><code>
|
||||
* http://www.site.com/
|
||||
* http://www.site.net/
|
||||
* </code></p>
|
||||
*
|
||||
* <p>The application can provide an implementation that automatically
|
||||
* resolves site.net to site.com before URI compares two URI objects.
|
||||
* Only the application can know and understand the context in which
|
||||
* the URI's are being used.</p>
|
||||
*
|
||||
* <p>Use the URI.resolver accessor to assign a custom resolver to
|
||||
* the URI class. Any resolver specified is global to all instances
|
||||
* of URI.</p>
|
||||
*
|
||||
* <p>URI will call this before performing URI comparisons in the
|
||||
* URI.getRelation() and URI.getCommonParent() functions.
|
||||
*
|
||||
* @see URI.getRelation
|
||||
* @see URI.getCommonParent
|
||||
*
|
||||
* @langversion ActionScript 3.0
|
||||
* @playerversion Flash 9.0
|
||||
*/
|
||||
public interface IURIResolver
|
||||
{
|
||||
/**
|
||||
* Implement this method to provide custom URI resolution for
|
||||
* your application.
|
||||
*
|
||||
* @langversion ActionScript 3.0
|
||||
* @playerversion Flash 9.0
|
||||
*/
|
||||
function resolve(uri:URI) : URI;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,196 @@
|
||||
/*
|
||||
Copyright (c) 2008, Adobe Systems Incorporated
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
* Neither the name of Adobe Systems Incorporated nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package com.adobe.net
|
||||
{
|
||||
public class MimeTypeMap
|
||||
{
|
||||
private var types:Array =
|
||||
[["application/andrew-inset","ez"],
|
||||
["application/atom+xml","atom"],
|
||||
["application/mac-binhex40","hqx"],
|
||||
["application/mac-compactpro","cpt"],
|
||||
["application/mathml+xml","mathml"],
|
||||
["application/msword","doc"],
|
||||
["application/octet-stream","bin","dms","lha","lzh","exe","class","so","dll","dmg"],
|
||||
["application/oda","oda"],
|
||||
["application/ogg","ogg"],
|
||||
["application/pdf","pdf"],
|
||||
["application/postscript","ai","eps","ps"],
|
||||
["application/rdf+xml","rdf"],
|
||||
["application/smil","smi","smil"],
|
||||
["application/srgs","gram"],
|
||||
["application/srgs+xml","grxml"],
|
||||
["application/vnd.adobe.apollo-application-installer-package+zip","air"],
|
||||
["application/vnd.mif","mif"],
|
||||
["application/vnd.mozilla.xul+xml","xul"],
|
||||
["application/vnd.ms-excel","xls"],
|
||||
["application/vnd.ms-powerpoint","ppt"],
|
||||
["application/vnd.rn-realmedia","rm"],
|
||||
["application/vnd.wap.wbxml","wbxml"],
|
||||
["application/vnd.wap.wmlc","wmlc"],
|
||||
["application/vnd.wap.wmlscriptc","wmlsc"],
|
||||
["application/voicexml+xml","vxml"],
|
||||
["application/x-bcpio","bcpio"],
|
||||
["application/x-cdlink","vcd"],
|
||||
["application/x-chess-pgn","pgn"],
|
||||
["application/x-cpio","cpio"],
|
||||
["application/x-csh","csh"],
|
||||
["application/x-director","dcr","dir","dxr"],
|
||||
["application/x-dvi","dvi"],
|
||||
["application/x-futuresplash","spl"],
|
||||
["application/x-gtar","gtar"],
|
||||
["application/x-hdf","hdf"],
|
||||
["application/x-javascript","js"],
|
||||
["application/x-koan","skp","skd","skt","skm"],
|
||||
["application/x-latex","latex"],
|
||||
["application/x-netcdf","nc","cdf"],
|
||||
["application/x-sh","sh"],
|
||||
["application/x-shar","shar"],
|
||||
["application/x-shockwave-flash","swf"],
|
||||
["application/x-stuffit","sit"],
|
||||
["application/x-sv4cpio","sv4cpio"],
|
||||
["application/x-sv4crc","sv4crc"],
|
||||
["application/x-tar","tar"],
|
||||
["application/x-tcl","tcl"],
|
||||
["application/x-tex","tex"],
|
||||
["application/x-texinfo","texinfo","texi"],
|
||||
["application/x-troff","t","tr","roff"],
|
||||
["application/x-troff-man","man"],
|
||||
["application/x-troff-me","me"],
|
||||
["application/x-troff-ms","ms"],
|
||||
["application/x-ustar","ustar"],
|
||||
["application/x-wais-source","src"],
|
||||
["application/xhtml+xml","xhtml","xht"],
|
||||
["application/xml","xml","xsl"],
|
||||
["application/xml-dtd","dtd"],
|
||||
["application/xslt+xml","xslt"],
|
||||
["application/zip","zip"],
|
||||
["audio/basic","au","snd"],
|
||||
["audio/midi","mid","midi","kar"],
|
||||
["audio/mpeg","mp3","mpga","mp2"],
|
||||
["audio/x-aiff","aif","aiff","aifc"],
|
||||
["audio/x-mpegurl","m3u"],
|
||||
["audio/x-pn-realaudio","ram","ra"],
|
||||
["audio/x-wav","wav"],
|
||||
["chemical/x-pdb","pdb"],
|
||||
["chemical/x-xyz","xyz"],
|
||||
["image/bmp","bmp"],
|
||||
["image/cgm","cgm"],
|
||||
["image/gif","gif"],
|
||||
["image/ief","ief"],
|
||||
["image/jpeg","jpg","jpeg","jpe"],
|
||||
["image/png","png"],
|
||||
["image/svg+xml","svg"],
|
||||
["image/tiff","tiff","tif"],
|
||||
["image/vnd.djvu","djvu","djv"],
|
||||
["image/vnd.wap.wbmp","wbmp"],
|
||||
["image/x-cmu-raster","ras"],
|
||||
["image/x-icon","ico"],
|
||||
["image/x-portable-anymap","pnm"],
|
||||
["image/x-portable-bitmap","pbm"],
|
||||
["image/x-portable-graymap","pgm"],
|
||||
["image/x-portable-pixmap","ppm"],
|
||||
["image/x-rgb","rgb"],
|
||||
["image/x-xbitmap","xbm"],
|
||||
["image/x-xpixmap","xpm"],
|
||||
["image/x-xwindowdump","xwd"],
|
||||
["model/iges","igs","iges"],
|
||||
["model/mesh","msh","mesh","silo"],
|
||||
["model/vrml","wrl","vrml"],
|
||||
["text/calendar","ics","ifb"],
|
||||
["text/css","css"],
|
||||
["text/html","html","htm"],
|
||||
["text/plain","txt","asc"],
|
||||
["text/richtext","rtx"],
|
||||
["text/rtf","rtf"],
|
||||
["text/sgml","sgml","sgm"],
|
||||
["text/tab-separated-values","tsv"],
|
||||
["text/vnd.wap.wml","wml"],
|
||||
["text/vnd.wap.wmlscript","wmls"],
|
||||
["text/x-setext","etx"],
|
||||
["video/mpeg","mpg","mpeg","mpe"],
|
||||
["video/quicktime","mov","qt"],
|
||||
["video/vnd.mpegurl","m4u","mxu"],
|
||||
["video/x-flv","flv"],
|
||||
["video/x-msvideo","avi"],
|
||||
["video/x-sgi-movie","movie"],
|
||||
["x-conference/x-cooltalk","ice"]];
|
||||
|
||||
/**
|
||||
* Returns the mimetype for the given extension.
|
||||
*/
|
||||
public function getMimeType(extension:String):String
|
||||
{
|
||||
extension = extension.toLocaleLowerCase();
|
||||
for each (var a:Array in types)
|
||||
{
|
||||
for each (var b:String in a)
|
||||
{
|
||||
if (b == extension)
|
||||
{
|
||||
return a[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the prefered extension for the given mimetype.
|
||||
*/
|
||||
public function getExtension(mimetype:String):String
|
||||
{
|
||||
mimetype = mimetype.toLocaleLowerCase();
|
||||
for each (var a:Array in types)
|
||||
{
|
||||
if (a[0] == mimetype)
|
||||
{
|
||||
return a[1];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a mimetype to the map. The order of the extensions matters. The most preferred should come first.
|
||||
*/
|
||||
public function addMimeType(mimetype:String, extensions:Array):void
|
||||
{
|
||||
var newType:Array = [mimetype];
|
||||
for each (var a:String in extensions)
|
||||
{
|
||||
newType.push(a);
|
||||
}
|
||||
types.push(newType);
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,139 @@
|
||||
/*
|
||||
Copyright (c) 2008, Adobe Systems Incorporated
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
* Neither the name of Adobe Systems Incorporated nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package com.adobe.net
|
||||
{
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
/**
|
||||
* This class implements an efficient lookup table for URI
|
||||
* character escaping. This class is only needed if you
|
||||
* create a derived class of URI to handle custom URI
|
||||
* syntax. This class is used internally by URI.
|
||||
*
|
||||
* @langversion ActionScript 3.0
|
||||
* @playerversion Flash 9.0*
|
||||
*/
|
||||
public class URIEncodingBitmap extends ByteArray
|
||||
{
|
||||
/**
|
||||
* Constructor. Creates an encoding bitmap using the given
|
||||
* string of characters as the set of characters that need
|
||||
* to be URI escaped.
|
||||
*
|
||||
* @langversion ActionScript 3.0
|
||||
* @playerversion Flash 9.0
|
||||
*/
|
||||
public function URIEncodingBitmap(charsToEscape:String) : void
|
||||
{
|
||||
var i:int;
|
||||
var data:ByteArray = new ByteArray();
|
||||
|
||||
// Initialize our 128 bits (16 bytes) to zero
|
||||
for (i = 0; i < 16; i++)
|
||||
this.writeByte(0);
|
||||
|
||||
data.writeUTFBytes(charsToEscape);
|
||||
data.position = 0;
|
||||
|
||||
while (data.bytesAvailable)
|
||||
{
|
||||
var c:int = data.readByte();
|
||||
|
||||
if (c > 0x7f)
|
||||
continue; // only escape low bytes
|
||||
|
||||
var enc:int;
|
||||
this.position = (c >> 3);
|
||||
enc = this.readByte();
|
||||
enc |= 1 << (c & 0x7);
|
||||
this.position = (c >> 3);
|
||||
this.writeByte(enc);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Based on the data table contained in this object, check
|
||||
* if the given character should be escaped.
|
||||
*
|
||||
* @param char the character to be escaped. Only the first
|
||||
* character in the string is used. Any other characters
|
||||
* are ignored.
|
||||
*
|
||||
* @return the integer value of the raw UTF8 character. For
|
||||
* example, if '%' is given, the return value is 37 (0x25).
|
||||
* If the character given does not need to be escaped, the
|
||||
* return value is zero.
|
||||
*
|
||||
* @langversion ActionScript 3.0
|
||||
* @playerversion Flash 9.0
|
||||
*/
|
||||
public function ShouldEscape(char:String) : int
|
||||
{
|
||||
var data:ByteArray = new ByteArray();
|
||||
var c:int, mask:int;
|
||||
|
||||
// write the character into a ByteArray so
|
||||
// we can pull it out as a raw byte value.
|
||||
data.writeUTFBytes(char);
|
||||
data.position = 0;
|
||||
c = data.readByte();
|
||||
|
||||
if (c & 0x80)
|
||||
{
|
||||
// don't escape high byte characters. It can make international
|
||||
// URI's unreadable. We just want to escape characters that would
|
||||
// make URI syntax ambiguous.
|
||||
return 0;
|
||||
}
|
||||
else if ((c < 0x1f) || (c == 0x7f))
|
||||
{
|
||||
// control characters must be escaped.
|
||||
return c;
|
||||
}
|
||||
|
||||
this.position = (c >> 3);
|
||||
mask = this.readByte();
|
||||
|
||||
if (mask & (1 << (c & 0x7)))
|
||||
{
|
||||
// we need to escape this, return the numeric value
|
||||
// of the character
|
||||
return c;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,198 @@
|
||||
/*
|
||||
Copyright (c) 2008, Adobe Systems Incorporated
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
* Neither the name of Adobe Systems Incorporated nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package com.adobe.net.proxies
|
||||
{
|
||||
import flash.events.Event;
|
||||
import flash.events.IOErrorEvent;
|
||||
import flash.events.ProgressEvent;
|
||||
import flash.net.Socket;
|
||||
|
||||
/**
|
||||
* This class allows TCP socket connections through HTTP proxies in accordance with
|
||||
* RFC 2817:
|
||||
*
|
||||
* ftp://ftp.rfc-editor.org/in-notes/rfc2817.txt
|
||||
*
|
||||
* It can also be used to make direct connections to a destination, as well. If you
|
||||
* pass the host and port into the constructor, no proxy will be used. You can also
|
||||
* call connect, passing in the host and the port, and if you didn't set the proxy
|
||||
* info, a direct connection will be made. A proxy is only used after you have called
|
||||
* the setProxyInfo function.
|
||||
*
|
||||
* The connection to and negotiation with the proxy is completely hidden. All the
|
||||
* same events are thrown whether you are using a proxy or not, and the data you
|
||||
* receive from the target server will look exact as it would if you were connected
|
||||
* to it directly rather than through a proxy.
|
||||
*
|
||||
* @author Christian Cantrell
|
||||
*
|
||||
**/
|
||||
public class RFC2817Socket
|
||||
extends Socket
|
||||
{
|
||||
private var proxyHost:String = null;
|
||||
private var host:String = null;
|
||||
private var proxyPort:int = 0;
|
||||
private var port:int = 0;
|
||||
private var deferredEventHandlers:Object = new Object();
|
||||
private var buffer:String = new String();
|
||||
|
||||
/**
|
||||
* Construct a new RFC2817Socket object. If you pass in the host and the port,
|
||||
* no proxy will be used. If you want to use a proxy, instantiate with no
|
||||
* arguments, call setProxyInfo, then call connect.
|
||||
**/
|
||||
public function RFC2817Socket(host:String = null, port:int = 0)
|
||||
{
|
||||
super(host, port);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the proxy host and port number. Your connection will only proxied if
|
||||
* this function has been called.
|
||||
**/
|
||||
public function setProxyInfo(host:String, port:int):void
|
||||
{
|
||||
this.proxyHost = host;
|
||||
this.proxyPort = port;
|
||||
|
||||
var deferredSocketDataHandler:Object = this.deferredEventHandlers[ProgressEvent.SOCKET_DATA];
|
||||
var deferredConnectHandler:Object = this.deferredEventHandlers[Event.CONNECT];
|
||||
|
||||
if (deferredSocketDataHandler != null)
|
||||
{
|
||||
super.removeEventListener(ProgressEvent.SOCKET_DATA, deferredSocketDataHandler.listener, deferredSocketDataHandler.useCapture);
|
||||
}
|
||||
|
||||
if (deferredConnectHandler != null)
|
||||
{
|
||||
super.removeEventListener(Event.CONNECT, deferredConnectHandler.listener, deferredConnectHandler.useCapture);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Connect to the specified host over the specified port. If you want your
|
||||
* connection proxied, call the setProxyInfo function first.
|
||||
**/
|
||||
public override function connect(host:String, port:int):void
|
||||
{
|
||||
if (this.proxyHost == null)
|
||||
{
|
||||
this.redirectConnectEvent();
|
||||
this.redirectSocketDataEvent();
|
||||
super.connect(host, port);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.host = host;
|
||||
this.port = port;
|
||||
super.addEventListener(Event.CONNECT, this.onConnect);
|
||||
super.addEventListener(ProgressEvent.SOCKET_DATA, this.onSocketData);
|
||||
super.connect(this.proxyHost, this.proxyPort);
|
||||
}
|
||||
}
|
||||
|
||||
private function onConnect(event:Event):void
|
||||
{
|
||||
this.writeUTFBytes("CONNECT "+this.host+":"+this.port+" HTTP/1.1\n\n");
|
||||
this.flush();
|
||||
this.redirectConnectEvent();
|
||||
}
|
||||
|
||||
private function onSocketData(event:ProgressEvent):void
|
||||
{
|
||||
while (this.bytesAvailable != 0)
|
||||
{
|
||||
this.buffer += this.readUTFBytes(1);
|
||||
if (this.buffer.search(/\r?\n\r?\n$/) != -1)
|
||||
{
|
||||
this.checkResponse(event);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function checkResponse(event:ProgressEvent):void
|
||||
{
|
||||
var responseCode:String = this.buffer.substr(this.buffer.indexOf(" ")+1, 3);
|
||||
|
||||
if (responseCode.search(/^2/) == -1)
|
||||
{
|
||||
var ioError:IOErrorEvent = new IOErrorEvent(IOErrorEvent.IO_ERROR);
|
||||
ioError.text = "Error connecting to the proxy ["+this.proxyHost+"] on port ["+this.proxyPort+"]: " + this.buffer;
|
||||
this.dispatchEvent(ioError);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.redirectSocketDataEvent();
|
||||
this.dispatchEvent(new Event(Event.CONNECT));
|
||||
if (this.bytesAvailable > 0)
|
||||
{
|
||||
this.dispatchEvent(event);
|
||||
}
|
||||
}
|
||||
this.buffer = null;
|
||||
}
|
||||
|
||||
private function redirectConnectEvent():void
|
||||
{
|
||||
super.removeEventListener(Event.CONNECT, onConnect);
|
||||
var deferredEventHandler:Object = this.deferredEventHandlers[Event.CONNECT];
|
||||
if (deferredEventHandler != null)
|
||||
{
|
||||
super.addEventListener(Event.CONNECT, deferredEventHandler.listener, deferredEventHandler.useCapture, deferredEventHandler.priority, deferredEventHandler.useWeakReference);
|
||||
}
|
||||
}
|
||||
|
||||
private function redirectSocketDataEvent():void
|
||||
{
|
||||
super.removeEventListener(ProgressEvent.SOCKET_DATA, onSocketData);
|
||||
var deferredEventHandler:Object = this.deferredEventHandlers[ProgressEvent.SOCKET_DATA];
|
||||
if (deferredEventHandler != null)
|
||||
{
|
||||
super.addEventListener(ProgressEvent.SOCKET_DATA, deferredEventHandler.listener, deferredEventHandler.useCapture, deferredEventHandler.priority, deferredEventHandler.useWeakReference);
|
||||
}
|
||||
}
|
||||
|
||||
public override function addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int=0.0, useWeakReference:Boolean=false):void
|
||||
{
|
||||
if (type == Event.CONNECT || type == ProgressEvent.SOCKET_DATA)
|
||||
{
|
||||
this.deferredEventHandlers[type] = {listener:listener,useCapture:useCapture, priority:priority, useWeakReference:useWeakReference};
|
||||
}
|
||||
else
|
||||
{
|
||||
super.addEventListener(type, listener, useCapture, priority, useWeakReference);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user