diff --git a/flash/3.4/src/org/httpclient/events/HttpDataEvent.as b/flash/3.4/src/org/httpclient/events/HttpDataEvent.as deleted file mode 100644 index d55b1a81..00000000 --- a/flash/3.4/src/org/httpclient/events/HttpDataEvent.as +++ /dev/null @@ -1,23 +0,0 @@ -package org.httpclient.events { - - import flash.events.Event; - import flash.utils.ByteArray; - - public class HttpDataEvent extends Event { - - public static const DATA:String = "httpData"; - - private var _bytes:ByteArray; - - public function HttpDataEvent(bytes:ByteArray, type:String = DATA, bubbles:Boolean = false, cancelable:Boolean = false):void { - super(type, bubbles, cancelable); - _bytes = bytes; - } - - public function get bytes():ByteArray { return _bytes; } - - public function readUTFBytes():String { - return _bytes.readUTFBytes(_bytes.length); - } - } -} \ No newline at end of file diff --git a/flash/3.4/src/org/httpclient/events/HttpDataListener.as b/flash/3.4/src/org/httpclient/events/HttpDataListener.as deleted file mode 100644 index 0482829a..00000000 --- a/flash/3.4/src/org/httpclient/events/HttpDataListener.as +++ /dev/null @@ -1,39 +0,0 @@ -package org.httpclient.events { - - import org.httpclient.Log; - import flash.utils.ByteArray; - - - /** - * Same as HttpListener but stores data. - * You may want to use the regular HttpListener to handle the data as it becomes - * available instead of storing it in memory. - */ - public class HttpDataListener extends HttpListener { - - public var onDataComplete:Function = null; - - private var _data:ByteArray = null; - - /** - * In addition to HttpListener listeners, we have: - * - onDataComplete(e:HttpResponseEvent, data:ByteArray) - */ - public function HttpDataListener(listeners:Object = null) { - super(listeners); - if (listeners && listeners["onDataComplete"] != undefined) onDataComplete = listeners.onDataComplete; - _data = new ByteArray(); - } - - override protected function onInternalData(e:HttpDataEvent):void { - if (_data != null) _data.writeBytes(e.bytes, 0, e.bytes.length); - super.onInternalData(e); - } - - override protected function onInternalComplete(e:HttpResponseEvent):void { - if (onDataComplete != null) onDataComplete(e, _data); - _data = null; - super.onInternalComplete(e); - } - } -} \ No newline at end of file diff --git a/flash/3.4/src/org/httpclient/events/HttpErrorEvent.as b/flash/3.4/src/org/httpclient/events/HttpErrorEvent.as deleted file mode 100644 index 21da72a0..00000000 --- a/flash/3.4/src/org/httpclient/events/HttpErrorEvent.as +++ /dev/null @@ -1,17 +0,0 @@ -package org.httpclient.events { - - import flash.events.ErrorEvent; - - public class HttpErrorEvent extends ErrorEvent { - - public static const ERROR:String = "httpError"; - public static const TIMEOUT_ERROR:String = "httpTimeoutError"; - - public function HttpErrorEvent(type:String = ERROR, bubbles:Boolean = false, - cancelable:Boolean = false, text:String = "", id:int = 0):void { - - super(type, bubbles, cancelable, text); - } - - } -} \ No newline at end of file diff --git a/flash/3.4/src/org/httpclient/events/HttpListener.as b/flash/3.4/src/org/httpclient/events/HttpListener.as deleted file mode 100644 index 12a123b9..00000000 --- a/flash/3.4/src/org/httpclient/events/HttpListener.as +++ /dev/null @@ -1,104 +0,0 @@ -package org.httpclient.events { - - import flash.events.Event; - import flash.events.EventDispatcher; - import flash.events.ErrorEvent; - import flash.events.SecurityErrorEvent; - import flash.events.IOErrorEvent; - - /** - * Registers for events and forwards notifications to specified listeners - * if they are set. - */ - public class HttpListener extends EventDispatcher { - - public var onClose:Function = null; - public var onComplete:Function = null; - public var onConnect:Function = null; - public var onData:Function = null; - public var onError:Function = null; - public var onStatus:Function = null; - public var onRequest:Function = null; - - /** - * Listeners: - * - onClose(e:Event) - * - onComplete(e:HttpResponseEvent) - * - onConnect(e:HttpRequestEvent) - * - onData(e:HttpDataEvent) - * - onError(e:ErrorEvent) - * - onStatus(e:HttpStatusEvent) - * - onRequest(e:HttpRequestEvent) - */ - public function HttpListener(listeners:Object = null) { - if (listeners) { - if (listeners["onClose"] != undefined) onClose = listeners.onClose; - if (listeners["onComplete"] != undefined) onComplete = listeners.onComplete; - if (listeners["onConnect"] != undefined) onConnect = listeners.onConnect; - if (listeners["onData"] != undefined) onData = listeners.onData; - if (listeners["onError"] != undefined) onError = listeners.onError; - if (listeners["onStatus"] != undefined) onStatus = listeners.onStatus; - if (listeners["onRequest"] != undefined) onRequest = listeners.onRequest; - } - } - - public function register(dispatcher:EventDispatcher = null):HttpListener { - if (dispatcher == null) dispatcher = this; - dispatcher.addEventListener(Event.CLOSE, onInternalClose); - dispatcher.addEventListener(HttpResponseEvent.COMPLETE, onInternalComplete); - dispatcher.addEventListener(HttpRequestEvent.CONNECT, onInternalConnect); - dispatcher.addEventListener(HttpDataEvent.DATA, onInternalData); - dispatcher.addEventListener(HttpErrorEvent.ERROR, onInternalError); - dispatcher.addEventListener(HttpErrorEvent.TIMEOUT_ERROR, onInternalError); - dispatcher.addEventListener(HttpStatusEvent.STATUS, onInternalStatus); - dispatcher.addEventListener(HttpRequestEvent.COMPLETE, onInternalRequest); - dispatcher.addEventListener(IOErrorEvent.IO_ERROR, onInternalError); - dispatcher.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onInternalError); - return this; - } - - public function unregister(dispatcher:EventDispatcher = null):HttpListener { - if (dispatcher == null) dispatcher = this; - dispatcher.removeEventListener(Event.CLOSE, onInternalClose); - dispatcher.removeEventListener(HttpResponseEvent.COMPLETE, onInternalComplete); - dispatcher.removeEventListener(HttpRequestEvent.CONNECT, onInternalConnect); - dispatcher.removeEventListener(HttpDataEvent.DATA, onInternalData); - dispatcher.removeEventListener(HttpErrorEvent.ERROR, onInternalError); - dispatcher.removeEventListener(HttpErrorEvent.TIMEOUT_ERROR, onInternalError); - dispatcher.removeEventListener(HttpStatusEvent.STATUS, onInternalStatus); - dispatcher.removeEventListener(HttpRequestEvent.COMPLETE, onInternalRequest); - dispatcher.removeEventListener(IOErrorEvent.IO_ERROR, onInternalError); - dispatcher.removeEventListener(SecurityErrorEvent.SECURITY_ERROR, onInternalError); - return this; - } - - protected function onInternalClose(e:Event):void { - if (onClose != null) onClose(e); - } - - protected function onInternalComplete(e:HttpResponseEvent):void { - if (onComplete != null) onComplete(e); - } - - protected function onInternalConnect(e:HttpRequestEvent):void { - if (onConnect != null) onConnect(e); - } - - protected function onInternalRequest(e:HttpRequestEvent):void { - if (onRequest != null) onRequest(e); - } - - protected function onInternalData(e:HttpDataEvent):void { - if (onData != null) onData(e); - } - - protected function onInternalError(e:ErrorEvent):void { - if (onError != null) onError(e); - } - - protected function onInternalStatus(e:HttpStatusEvent):void { - if (onStatus != null) onStatus(e); - } - - } -} \ No newline at end of file diff --git a/flash/3.4/src/org/httpclient/events/HttpRequestEvent.as b/flash/3.4/src/org/httpclient/events/HttpRequestEvent.as deleted file mode 100644 index 81328824..00000000 --- a/flash/3.4/src/org/httpclient/events/HttpRequestEvent.as +++ /dev/null @@ -1,30 +0,0 @@ -package org.httpclient.events { - - import flash.events.Event; - - import org.httpclient.HttpRequest; - - public class HttpRequestEvent extends Event { - - public static const CONNECT:String = "requestConnect"; - public static const COMPLETE:String = "requestComplete"; - - private var _request:HttpRequest; - private var _header:String; - - public function HttpRequestEvent(request:HttpRequest, header:String, type:String = COMPLETE, bubbles:Boolean = false, cancelable:Boolean = false):void { - super(type, bubbles, cancelable); - _request = request; - _header = header; - } - - public function get request():HttpRequest { - return _request; - } - - public function get header():String { - return _header; - } - - } -} \ No newline at end of file diff --git a/flash/3.4/src/org/httpclient/events/HttpResponseEvent.as b/flash/3.4/src/org/httpclient/events/HttpResponseEvent.as deleted file mode 100644 index 5178e97a..00000000 --- a/flash/3.4/src/org/httpclient/events/HttpResponseEvent.as +++ /dev/null @@ -1,23 +0,0 @@ -package org.httpclient.events { - - import flash.events.Event; - - import org.httpclient.HttpResponse; - - public class HttpResponseEvent extends Event { - - public static const COMPLETE:String = "responseComplete"; - - private var _response:HttpResponse; - - public function HttpResponseEvent(response:HttpResponse, type:String = COMPLETE, bubbles:Boolean = false, cancelable:Boolean = false):void { - super(type, bubbles, cancelable); - _response = response; - } - - public function get response():HttpResponse { - return _response; - } - - } -} \ No newline at end of file diff --git a/flash/3.4/src/org/httpclient/events/HttpStatusEvent.as b/flash/3.4/src/org/httpclient/events/HttpStatusEvent.as deleted file mode 100644 index 66890b4e..00000000 --- a/flash/3.4/src/org/httpclient/events/HttpStatusEvent.as +++ /dev/null @@ -1,32 +0,0 @@ -package org.httpclient.events { - - import flash.events.Event; - - import org.httpclient.HttpResponse; - import org.httpclient.HttpHeader; - - public class HttpStatusEvent extends Event { - - public static const STATUS:String = "httpStatus"; - - private var _response:HttpResponse; - - public function HttpStatusEvent(response:HttpResponse, type:String = STATUS, bubbles:Boolean = false, cancelable:Boolean = false):void { - super(type, bubbles, cancelable); - _response = response; - } - - public function get response():HttpResponse { - return _response; - } - - public function get code():String { - return _response.code; - } - - public function get header():HttpHeader - { - return _response.header; - } - } -} \ No newline at end of file diff --git a/flash/3.4/src/org/httpclient/io/HttpBuffer.as b/flash/3.4/src/org/httpclient/io/HttpBuffer.as deleted file mode 100644 index 89bb877c..00000000 --- a/flash/3.4/src/org/httpclient/io/HttpBuffer.as +++ /dev/null @@ -1,150 +0,0 @@ -/** - * Copyright (c) 2007 Gabriel Handford - * See LICENSE.txt for full license information. - */ -package org.httpclient.io { - - import com.adobe.utils.StringUtil; - import flash.utils.ByteArray; - import org.httpclient.Log; - - public class HttpBuffer { - - protected var _data:ByteArray = new ByteArray(); - protected var _cursor:uint = 0; // Read position - - protected var _chunkLength:uint = 0; // Last chunk length - - public function HttpBuffer() { - super(); - } - - /** - * Write bytes to this buffer. Appends data, does not rely on current position. - */ - public function write(bytes:ByteArray):void { - _data.position = _data.length; - _data.writeBytes(bytes); - _data.position = _cursor; - } - - /** - * Read all data from the current position into the specified byte array. - */ - public function read(bytes:ByteArray):void { - _data.readBytes(bytes); - _cursor = _data.position; - } - - /** - * Get number of bytes available for reading. - */ - public function get bytesAvailable():uint { - return _data.bytesAvailable; - } - - /** - * Read all available bytes. - */ - public function readAvailable():ByteArray { - var bytes:ByteArray = new ByteArray(); - read(bytes); - bytes.position = 0; - return bytes; - } - - /** - * Read a line from the buffer. - * @return Next line, or null if there was no newline character found. - */ - public function readLine(trim:Boolean = false):String { - if (_data.bytesAvailable == 0) return null; - - var start:uint = _data.position; - var bytes:ByteArray = new ByteArray(); - var foundLine:Boolean = false; - - while(_data.bytesAvailable > 0) { - var char:int = _data.readByte(); - bytes.writeByte(char); - // Char code 10 == '\n' - if (char == 10) { - foundLine = true; - break; - } - } - - var line:String = null; - if (foundLine) { - bytes.position = 0; - line = bytes.readUTFBytes(bytes.length); - _cursor = _data.position; - return trim ? StringUtil.rtrim(line) : line; - } else { - // If no newline, then set the position to the original cursor position - _data.position = _cursor; - return null; - } - - } - - /** - * Take bytes from current position to the end, and put them into new byte array. - */ - public function truncate():void { - var nextData:ByteArray = new ByteArray(); - if (_data.bytesAvailable) _data.readBytes(nextData); - _data = nextData; - _cursor = 0; - } - - /** - * Read chunked encoding. - * @param onData For each chunk, call function(bytes:ByteArray) - * @return True if done, and no more chunks, false if there is more data to expect. - * - * TODO: Footers... - */ - public function readChunks(onData:Function):Boolean { - - while(_data.bytesAvailable > 0) { - - if (_chunkLength == 0) { - var line:String = readLine(); - if (!line) - throw new Error("No data available"); - - var match:Array = line.match(/\A([0-9a-fA-F]+).*/); - if (!match) { - throw new Error("Invalid chunk; trying to find chunk length at line: " + line); - } - - var hexlen:String = match[1]; - //Log.debug("Found hex length: " + hexlen); - var length:Number = parseInt(hexlen, 16); - Log.debug("Chunk size: " + length); - if (length <= 0) return true; - _chunkLength = length; - } - - if (_data.bytesAvailable >= (_chunkLength + 2)) { - var bytes:ByteArray = new ByteArray(); - _data.readBytes(bytes, 0, _chunkLength); - Log.debug("Read chunk size: " + _chunkLength); - _data.position += 2; // Skip CRLF - _cursor = _data.position; - _chunkLength = 0; - onData(bytes); - } else { - // Back it up, copy the bytes subset into new array (to save memory) and break out - truncate(); - return false; - } - } - - return false; - } - - } - -} \ No newline at end of file diff --git a/flash/3.4/src/org/httpclient/io/HttpFileStream.as b/flash/3.4/src/org/httpclient/io/HttpFileStream.as deleted file mode 100644 index 61524dd8..00000000 --- a/flash/3.4/src/org/httpclient/io/HttpFileStream.as +++ /dev/null @@ -1,36 +0,0 @@ -/** - * Copyright (c) 2007 Gabriel Handford - * See LICENSE.txt for full license information. - */ -package org.httpclient.io { - - import flash.filesystem.FileStream; - import flash.filesystem.File; - import flash.filesystem.FileMode; - - public class HttpFileStream extends FileStream { - - private var _length:uint; // File size - - public function HttpFileStream(length:uint) { - super(); - _length = length; - } - - public function get length():uint { - return _length; - } - - /** - * Create filestream for reading file. - * @param file (Should be flash.filesystem.File; Not typed for compatibility with Flash) - */ - public static function readFile(file:*):HttpFileStream { - var stream:HttpFileStream = new HttpFileStream(file.size); - stream.open(file, FileMode.READ); - return stream; - } - - } - -} \ No newline at end of file diff --git a/flash/3.4/src/org/httpclient/io/HttpRequestBuffer.as b/flash/3.4/src/org/httpclient/io/HttpRequestBuffer.as deleted file mode 100644 index b1883248..00000000 --- a/flash/3.4/src/org/httpclient/io/HttpRequestBuffer.as +++ /dev/null @@ -1,50 +0,0 @@ -/** - * Copyright (c) 2007 Gabriel Handford - * See LICENSE.txt for full license information. - */ -package org.httpclient.io { - - import com.adobe.utils.StringUtil; - import flash.utils.ByteArray; - - public class HttpRequestBuffer { - - private var _body:*; - - private var _bytesSent:uint = 0; - - private static const BLOCK_SIZE:uint = 16 * 1024; - - /** - * Create request buffer. - */ - public function HttpRequestBuffer(body:*) { - _body = body; - } - - public function get bytesSent():uint { return _bytesSent; } - - public function get hasData():Boolean { - if (!_body) return false; - return _bytesSent < _body.length; - } - - /** - * Get data for request body. - * @return Bytes, or null if end was reached. - */ - public function read():ByteArray { - var bytes:ByteArray = new ByteArray(); - if (_body.bytesAvailable > 0) { - var length:uint = Math.min(BLOCK_SIZE, _body.bytesAvailable); - _body.readBytes(bytes, 0, length); - bytes.position = 0; - _bytesSent += bytes.length; - } - - return bytes; - } - - - } -} \ No newline at end of file diff --git a/flash/3.4/src/org/httpclient/io/HttpResponseBuffer.as b/flash/3.4/src/org/httpclient/io/HttpResponseBuffer.as deleted file mode 100644 index c74b0511..00000000 --- a/flash/3.4/src/org/httpclient/io/HttpResponseBuffer.as +++ /dev/null @@ -1,202 +0,0 @@ -/** - * Copyright (c) 2007 Gabriel Handford - * See LICENSE.txt for full license information. - */ -package org.httpclient.io { - - import com.adobe.utils.StringUtil; - import flash.utils.ByteArray; - - import org.httpclient.HttpResponse; - import org.httpclient.HttpHeader; - import org.httpclient.Log; - - import flash.errors.*; - - /** - * Bytes from response are placed in this buffer, and parsed according to transfer encoding. - */ - public class HttpResponseBuffer { - - // Data buffer - private var _buffer:HttpBuffer = new HttpBuffer(); - - // Bytes read of body content - private var _bodyBytesRead:Number = 0; - - // Response header data parsed from bytes - private var _headerData:Array = []; - - // The response header, after we parsed it - private var _responseHeader:HttpResponse; - - // For special transfer encodings (like Chunks); Typically data is streamed directly - private var _responseBody:HttpBuffer = new HttpBuffer(); - - // Notified of response header: function(response:HttpResponse):void { } - private var _onResponseHeader:Function; - - // Notified of response body data: function(bytes:ByteArray):void { } - private var _onResponseData:Function; - - // Notified when response is complete: function(bytesRead:Number):void { } - private var _onResponseComplete:Function - - // If we expect response body - private var _hasResponseBody:Boolean; - - // If response buffer is done - private var _isPayloadDone:Boolean = false; - - /** - * Create response buffer. - * @param hasResponseBody Whether there is a response body - * @param onResponseHeader(response:HttpResponse) - * @param onResponseData(bytes:ByteArray) - * @param onResponseComplete(response:HttpResponse) - */ - public function HttpResponseBuffer(hasResponseBody:Boolean, onResponseHeader:Function, onResponseData:Function, onResponseComplete:Function) { - super(); - _hasResponseBody = hasResponseBody; - _onResponseHeader = onResponseHeader; - _onResponseData = onResponseData; - _onResponseComplete = onResponseComplete; - } - - /** - * Write bytes to the buffer. - * Parse lines for header, or send to onPayload. - * - * @param bytes Data - */ - public function writeBytes(bytes:ByteArray):void { - //if (_isPayloadDone) throw new IllegalOperationError("Response is finished; can't accept more bytes"); - if (_isPayloadDone) return; // TODO: Figure out why on some TLS chunked encoding this happens (oh maybe chunked encoding footer?) - //trace('_responseHeader : ' + _responseHeader); - //trace('---------------------------------------'); - // If we don't have the full header yet - if (!_responseHeader) { - _buffer.write(bytes); - - var line:String = _buffer.readLine(true); - //trace(line); - while (line != null) { - - // If empty line, then we reached the end of the header - if (line == "") { - _responseHeader = parseHeader(_headerData); - Log.debug("Response header:\n" + _responseHeader); - //trace("Response header:\n" + _responseHeader); - //trace("Response header:\n" + _responseHeader.code); - - // Notify - _onResponseHeader(_responseHeader); - - // On information responses, get next response header - if (_responseHeader.isInformation) { - _buffer.truncate(); - _responseHeader = null; - _isPayloadDone = false; - } else if (_responseHeader.code == "204") { - // A 204 is a successful response with No Content - _hasResponseBody = false; - } else { - // Pass any extra as payload - var payload:ByteArray = _buffer.readAvailable(); - Log.debug("Response payload (from parsing header): " + payload.length); - //trace("Response payload (from parsing header): " + payload.length, payload.readUTFBytes(payload.bytesAvailable)); - - _isPayloadDone = handlePayload(payload); - - break; - } - - } else { - _headerData.push(line); - } - - line = _buffer.readLine(true); - //trace(line); - } - - } else { - Log.debug("Response payload: " + bytes.length); - _isPayloadDone = handlePayload(bytes); - //trace("Response payload (from parsing header): " + _isPayloadDone,bytes.bytesAvailable, (bytes.readUTFBytes(bytes.bytesAvailable)) ); - } - - // Check if complete - Log.debug("Has response body? " + _hasResponseBody + "; Payload done? " + _isPayloadDone); - if (!_hasResponseBody || _isPayloadDone) { - //var ba:ByteArray = _responseBody.readAvailable() - //trace(ba.readUTFBytes(ba.bytesAvailable), ba.bytesAvailable); - _onResponseComplete(_responseHeader); - } - } - - /** - * Get header, if its been reached. - */ - public function get header():HttpResponse { return _responseHeader; } - - /** - * Notify with response data. - * Check for transfer encodings, otherwise stream it direct. - * @param bytes The data - * @return True if we don't expect any more data, false otherwise - */ - private function handlePayload(bytes:ByteArray):Boolean { - if (_responseHeader.isChunked) { - _responseBody.write(bytes); - _bodyBytesRead += bytes.length; - return _responseBody.readChunks(_onResponseData); - } else { - if (bytes.bytesAvailable > 0) { - _onResponseData(bytes); - _bodyBytesRead += bytes.length; - } - Log.debug("Bytes read (body): " + _bodyBytesRead + ", content length: " + _responseHeader.contentLength); - //trace("Bytes read (body): " + _bodyBytesRead + ", content length: " + _responseHeader.contentLength); - return (_responseHeader.contentLength != -1 && _bodyBytesRead >= _responseHeader.contentLength); - } - } - - /** - * Parse HTTP response header. - * @param lines Lines in header - * @return The HTTP response so far - */ - protected function parseHeader(lines:Array):HttpResponse { - var line:String = lines[0]; - - // Regex courtesy of ruby 1.8 Net::HTTP - // Example, HTTP/1.1 200 OK - var matches:Array = line.match(/\AHTTP(?:\/(\d+\.\d+))?\s+(\d\d\d)\s*(.*)\z/); - - if (!matches) - throw new Error("Invalid header: " + line + ", matches: " + matches); - - var version:String = matches[1]; - var code:String = matches[2]; - var message:String = matches[3]; - var headers:Array = []; - - for(var i:Number = 1; i < lines.length; i++) { - line = lines[i]; - - var index:int = line.indexOf(":"); - if (index != -1) { - var name:String = line.substring(0, index); - var value:String = line.substring(index + 1, line.length); - headers.push({ name: name, value: value }); - } else { - Log.warn("Invalid header: " + line); - } - } - - return new HttpResponse(version, code, message, new HttpHeader(headers)); - } - - } - -} \ No newline at end of file diff --git a/php/3.4/noise.php b/php/3.4/noise.php new file mode 100644 index 00000000..ffe796fe --- /dev/null +++ b/php/3.4/noise.php @@ -0,0 +1,68 @@ +publish(array( + 'channel' => $channel, + #'message' => $t + ' Hello from PHP!' + 'message' => serialize($message) +)); +echo($t . " " . $publish_success[0] . " " . $publish_success[1]); +echo "\r\n"; + +#sleep(1); +} + +?> +