Skip to content

Commit

Permalink
Remove CURL library from NME_LOCAL_TOOLKIT
Browse files Browse the repository at this point in the history
  • Loading branch information
hughsando committed Jun 4, 2024
1 parent a580905 commit d8b4115
Show file tree
Hide file tree
Showing 10 changed files with 187 additions and 164 deletions.
6 changes: 4 additions & 2 deletions project/ToolkitBuild.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@

<!-- Do we need to implement curl in NME -->
<set name="NME_CURL" value="1" />
<unset name="NME_CURL" if="emscripten||winrt||gcw0" />
<unset name="NME_CURL" if="emscripten||winrt||gcw0||NME_LOCAL_TOOLKIT" />

<!-- And allow https ? -->
<set name="NME_SSL" value="1" />
Expand Down Expand Up @@ -168,11 +168,12 @@
<include name="${NME_MODPLUG}/files.xml" if="modplug" />
<set name="NME_LIBSDL_MIXER" value="${NATIVE_TOOLKIT_PATH}/sdl-mixer/" />
<include name="${NME_LIBSDL_MIXER}files.xml" if="NME_MIXER" />

<include name="${NATIVE_TOOLKIT_PATH}/curl/files.xml" if="NME_CURL" />
</section>



<include name="${NATIVE_TOOLKIT_PATH}/curl/files.xml" if="NME_CURL" />

<include name="${NATIVE_TOOLKIT_PATH}/angle/files.xml" if="NME_ANGLE" unless="ANGLE_DIR" />
<include name="${ANGLE_DIR}/files.xml" if="NME_ANGLE ANGLE_DIR" />
Expand Down Expand Up @@ -402,6 +403,7 @@
<depend files="native-toolkit-sdl-mixer-depends" if="NME_MIXER"/>
</section>

<compilerflag value="-DNME_CURL" if="NME_CURL"/>
<section if="NME_CURL">
<compilerflag value="-DNME_CURL_SSL" if="NME_SSL"/>
</section>
Expand Down
19 changes: 9 additions & 10 deletions project/src/common/ExternalInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#endif

#if defined(EMSCRIPTEN) || defined(HX_WINRT)
#define NME_NO_CURL
#define NME_NO_CAMERA
#endif
#if defined(HXCPP_JS_PRIME) || defined(HX_WINRT)
Expand Down Expand Up @@ -5491,7 +5490,7 @@ DEFINE_PRIME3v(nme_tilesheet_get_rect);
// --- URL ----------------------------------------------------------
value nme_curl_initialize(value inCACertFilePath)
{
#ifndef NME_NO_CURL
#ifdef NME_CURL
URLLoader::initialize(val_string(inCACertFilePath));
#endif
return alloc_null();
Expand All @@ -5501,7 +5500,7 @@ DEFINE_PRIM(nme_curl_initialize,1);

value nme_curl_create(value inURLRequest)
{
#ifndef NME_NO_CURL
#ifdef NME_CURL
URLRequest request;
FromValue(inURLRequest,request);
URLLoader *loader = URLLoader::create(request);
Expand All @@ -5514,7 +5513,7 @@ DEFINE_PRIM(nme_curl_create,1);

value nme_curl_process_loaders()
{
#ifndef NME_NO_CURL
#ifdef NME_CURL
return alloc_bool(URLLoader::processAll());
#endif
return alloc_bool(true);
Expand All @@ -5524,7 +5523,7 @@ DEFINE_PRIM(nme_curl_process_loaders,0);

value nme_curl_update_loader(value inLoader,value outHaxeObj)
{
#ifndef NME_NO_CURL
#ifdef NME_CURL
URLLoader *loader;
if (AbstractToObject(inLoader,loader))
{
Expand All @@ -5540,7 +5539,7 @@ DEFINE_PRIM(nme_curl_update_loader,2);

value nme_curl_get_error_message(value inLoader)
{
#ifndef NME_NO_CURL
#ifdef NME_CURL
URLLoader *loader;
if (AbstractToObject(inLoader,loader))
{
Expand All @@ -5554,7 +5553,7 @@ DEFINE_PRIM(nme_curl_get_error_message,1);

value nme_curl_get_code(value inLoader)
{
#ifndef NME_NO_CURL
#ifdef NME_CURL
URLLoader *loader;
if (AbstractToObject(inLoader,loader))
{
Expand All @@ -5568,7 +5567,7 @@ DEFINE_PRIM(nme_curl_get_code,1);

value nme_curl_get_data(value inLoader)
{
#ifndef NME_NO_CURL
#ifdef NME_CURL
URLLoader *loader;
if (AbstractToObject(inLoader,loader))
{
Expand All @@ -5584,7 +5583,7 @@ DEFINE_PRIM(nme_curl_get_data,1);

value nme_curl_get_cookies(value inLoader)
{
#ifndef NME_NO_CURL
#ifdef NME_CURL
URLLoader *loader;
if (AbstractToObject(inLoader,loader))
{
Expand All @@ -5603,7 +5602,7 @@ DEFINE_PRIM(nme_curl_get_cookies,1);

value nme_curl_get_headers(value inLoader)
{
#ifndef NME_NO_CURL
#ifdef NME_CURL
URLLoader *loader;
if (AbstractToObject(inLoader,loader))
{
Expand Down
108 changes: 64 additions & 44 deletions samples/13-URLLoader/Sample.hx
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,36 @@ import nme.errors.SecurityError;
import nme.errors.TypeError;
import nme.net.URLVariables;
import nme.net.URLRequestMethod;
import nme.display.*;


class Sample extends Sprite {
class Sample extends Sprite
{
private var postTextField:TextField;
private var xmlTextField:TextField;
private var externalXML:Xml;
private var externalXML:Xml;
private var loader:URLLoader;

public function new()
{
super();
flash.Lib.current.addChild(this);

//var request:URLRequest = new URLRequest("http://www.w3schools.com/xml/cd_catalog.xml");
var request:URLRequest = new URLRequest("https://twitter.com/");
#if !flash
request.basicAuth("basic","basic");
request.cookieString = "name=value";
{
super();
//nme.Lib.current.addChild(this);

var request:URLRequest = new URLRequest("http://help.websiteos.com/websiteos/example_of_a_simple_html_page.htm");
request.userAgent = "haxe test";
//request.basicAuth("basic","basic");
//request.cookieString = "name=value";
//request.verbose = true;
#end

loader = new URLLoader();
loader.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);
loader.addEventListener(Event.COMPLETE, loaderCompleteHandler);
loader.addEventListener(ProgressEvent.PROGRESS, onProgress);
trace('Request:$request');

try {
loader.load(request);
trace('Loader:$loader');
}
catch (error:SecurityError)
{
Expand All @@ -48,37 +51,51 @@ class Sample extends Sprite {
postTextField.x = 10;
postTextField.y = 10;
postTextField.background = true;
postTextField.autoSize = TextFieldAutoSize.LEFT;
postTextField.border = true;
postTextField.width = 400;
postTextField.height = 240;
//postTextField.autoSize = TextFieldAutoSize.LEFT;
postTextField.text = "post ...";

addChild(postTextField);


xmlTextField = new TextField();
xmlTextField.x = 10;
xmlTextField.y = 100;
xmlTextField.y = 260;
xmlTextField.background = true;
xmlTextField.autoSize = TextFieldAutoSize.LEFT;
xmlTextField.border = true;
xmlTextField.width = 400;
xmlTextField.height = 240;
//xmlTextField.autoSize = TextFieldAutoSize.LEFT;
xmlTextField.text = "xml data...";

addChild(xmlTextField);

//var t0 = haxe.Timer.stamp();
//addEventListener( Event.ENTER_FRAME, function(_) trace( haxe.Timer.stamp()-t0 ) );

var image_loader = new flash.display.Loader();
image_loader.contentLoaderInfo.addEventListener(flash.events.Event.COMPLETE, function(_) {
var bmp:flash.display.Bitmap = cast image_loader.content;
trace("Loaded image " + bmp.bitmapData.width + "x" + bmp.bitmapData.height);
var image_loader = new nme.display.Loader();
image_loader.contentLoaderInfo.addEventListener(nme.events.Event.COMPLETE, function(_) {
var bmp:nme.display.Bitmap = cast image_loader.content;
trace("Loaded image " + bmp.bitmapData);
});

var request:URLRequest = new URLRequest("http://upload.wikimedia.org/wikipedia/en/7/72/Example-serious.jpg");
image_loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, e -> {
var tf = new TextField();
tf.text = "Error:" + e;
image_loader.scaleX = image_loader.scaleY = 1.0;
image_loader.addChild(tf);
});

var request:URLRequest = new URLRequest("https://avatars.githubusercontent.com/u/2187351",{s:200,v:4} );
image_loader.load(request);
image_loader.x = 10;
image_loader.y = 180;
image_loader.scaleX = 0.5;
image_loader.scaleY = 0.5;
image_loader.y = 510;
image_loader.scaleX = 0.25;
image_loader.scaleY = 0.25;
addChild(image_loader);

var post = new URLRequest("http://www.snee.com/xml/crud/posttest.cgi");
var post = new URLRequest("https://httpbin.org/anything");
var vars = new URLVariables();
vars.fname = "Milla";
vars.lname = "Jovovich";
Expand All @@ -87,11 +104,13 @@ class Sample extends Sprite {
post.data = vars;
//post.verbose = true;
var postLoad = new URLLoader();
postLoad.addEventListener(IOErrorEvent.IO_ERROR, e -> postTextField.htmlText = "Error:" + e );
postLoad.addEventListener(Event.COMPLETE, function(_) {
postTextField.htmlText = postLoad.data.toString();
} );

try {
try
{
postLoad.load(post);
}
catch (error:SecurityError)
Expand All @@ -101,28 +120,29 @@ class Sample extends Sprite {

}

function onProgress(event:ProgressEvent)
{
trace("Loaded " + event.bytesLoaded + "/" + event.bytesTotal );
}

private function loaderCompleteHandler(event:Event):Void {
function onProgress(event:ProgressEvent)
{
trace("Loaded " + event.bytesLoaded + "/" + event.bytesTotal );
}

try {
xmlTextField.text = loader.data;
} catch (e:TypeError) {
trace("Could not load the XML file.");
}
private function loaderCompleteHandler(event:Event):Void
{
trace("loaderCompleteHandler!");
try
{
xmlTextField.text = loader.data;
}
catch (e:TypeError)
{
trace("Could not load the XML file.");
}
}


private function errorHandler(e:IOErrorEvent):Void {
xmlTextField.text = "Error:" + e.text;
private function errorHandler(e:IOErrorEvent):Void
{
trace("error " + e);
xmlTextField.text = "Error:" + e.text;
}

public static function main()
{
new Sample();
}
}

4 changes: 2 additions & 2 deletions samples/13-URLLoader/Sample.nmml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
/>

<window
width="320"
height="480"
width="480"
height="640"
fps="60"
background="0xffffff"
resizable="true"
Expand Down
17 changes: 10 additions & 7 deletions src/nme/display/Loader.hx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Loader extends Sprite
{
if (inBytes == null)
return false;

try
{
nmeImage = BitmapData.loadFromBytes(inBytes);
Expand Down Expand Up @@ -68,13 +68,16 @@ class Loader extends Sprite
public function loadBytes(bytes:ByteArray, context:LoaderContext = null)
{
// No "loader context" in nme
if (doLoad(bytes)) {
var event = new Event(Event.COMPLETE);
event.currentTarget = this;
if (doLoad(bytes))
{
var event = new Event(Event.COMPLETE);
event.currentTarget = this;
contentLoaderInfo.dispatchEvent(event);
} else {
}
else
{
contentLoaderInfo.DispatchIOErrorEvent();
}
}
}

public function unload()
Expand All @@ -96,7 +99,7 @@ class Loader extends Sprite
contentLoaderInfo.height = 0;
}
var event = new Event(Event.UNLOAD);
event.currentTarget = this;
event.currentTarget = this;
dispatchEvent(event);
}
}
Expand Down
22 changes: 12 additions & 10 deletions src/nme/display/LoaderInfo.hx
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,19 @@ class LoaderInfo extends URLLoader
var dot = pendingURL.lastIndexOf(".");
var extension = dot > 0 ? pendingURL.substr(dot + 1).toLowerCase() : "";

if(request.contentType == null ||
request.contentType.length == 0 ||
request.contentType == "application/x-www-form-urlencoded")
contentType = switch(extension)
if (request.contentType == null ||
request.contentType.length == 0 ||
request.contentType == "application/x-www-form-urlencoded")
{
case "swf": "application/x-shockwave-flash";
case "jpg","jpeg": "image/jpeg";
case "png": "image/png";
case "gif": "image/gif";
default:
throw "Unrecognized file " + pendingURL;
contentType = switch(extension)
{
case "swf": "application/x-shockwave-flash";
case "jpg","jpeg": "image/jpeg";
case "png": "image/png";
case "gif": "image/gif";
default: null;
//throw "Unrecognized file " + pendingURL;
}
}


Expand Down
5 changes: 0 additions & 5 deletions src/nme/net/HttpLoader.hx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ class HttpLoader

http = new Http(inRequest.url);
http.onError = onError;

http.onStatus = onStatus;

for(header in urlRequest.requestHeaders)
Expand All @@ -81,11 +80,7 @@ class HttpLoader

var isPost = urlRequest.method==URLRequestMethod.POST;
if (isPost)
#if haxe4
http.setPostBytes(urlRequest.nmeBytes);
#else
http.setPostData(urlRequest.nmeBytes.toString());
#end

runAsync(run);
}
Expand Down
Loading

0 comments on commit d8b4115

Please sign in to comment.