Add HL/AL bindings, other fixes
This commit is contained in:
@@ -181,6 +181,22 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
std::wstring* hxstring_to_wstring (hl_vstring* val) {
|
||||
|
||||
if (val) {
|
||||
|
||||
std::string _val = std::string (hl_to_utf8 (val->bytes));
|
||||
return new std::wstring (_val.begin (), _val.end ());
|
||||
|
||||
} else {
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
value lime_application_create () {
|
||||
|
||||
Application* application = CreateApplication ();
|
||||
@@ -563,12 +579,6 @@ namespace lime {
|
||||
if (Clipboard::HasText ()) {
|
||||
|
||||
const char* text = Clipboard::GetText ();
|
||||
// char* _text = malloc (strlen (text) + 1);
|
||||
// strpy (text, _text);
|
||||
|
||||
// // TODO: Should we free for all backends? (SDL requires it)
|
||||
|
||||
// free ((char*)text);
|
||||
return (vbyte*)text;
|
||||
|
||||
} else {
|
||||
@@ -702,7 +712,6 @@ namespace lime {
|
||||
|
||||
} else {
|
||||
|
||||
delete path;
|
||||
return alloc_null ();
|
||||
|
||||
}
|
||||
@@ -716,34 +725,36 @@ namespace lime {
|
||||
|
||||
HL_PRIM vbyte* hl_lime_file_dialog_open_directory (hl_vstring* title, hl_vstring* filter, hl_vstring* defaultPath) {
|
||||
|
||||
// #ifdef LIME_TINYFILEDIALOGS
|
||||
#ifdef LIME_TINYFILEDIALOGS
|
||||
|
||||
// std::wstring* _title = hxstring_to_wstring (title);
|
||||
// std::wstring* _filter = hxstring_to_wstring (filter);
|
||||
// std::wstring* _defaultPath = hxstring_to_wstring (defaultPath);
|
||||
std::wstring* _title = hxstring_to_wstring (title);
|
||||
std::wstring* _filter = hxstring_to_wstring (filter);
|
||||
std::wstring* _defaultPath = hxstring_to_wstring (defaultPath);
|
||||
|
||||
// std::wstring* path = FileDialog::OpenDirectory (_title, _filter, _defaultPath);
|
||||
std::wstring* path = FileDialog::OpenDirectory (_title, _filter, _defaultPath);
|
||||
|
||||
// if (_title) delete _title;
|
||||
// if (_filter) delete _filter;
|
||||
// if (_defaultPath) delete _defaultPath;
|
||||
if (_title) delete _title;
|
||||
if (_filter) delete _filter;
|
||||
if (_defaultPath) delete _defaultPath;
|
||||
|
||||
// if (path) {
|
||||
if (path) {
|
||||
|
||||
// value _path = alloc_wstring (path->c_str ());
|
||||
// delete path;
|
||||
// return _path;
|
||||
int size = std::wcslen (path->c_str ());
|
||||
char* result = (char*)malloc (size);
|
||||
std::wcstombs (result, path->c_str (), size);
|
||||
delete path;
|
||||
|
||||
// } else {
|
||||
return (vbyte*)result;
|
||||
|
||||
// delete path;
|
||||
// return alloc_null ();
|
||||
} else {
|
||||
|
||||
// }
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
||||
// #endif
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
||||
@@ -770,7 +781,6 @@ namespace lime {
|
||||
|
||||
} else {
|
||||
|
||||
delete path;
|
||||
return alloc_null ();
|
||||
|
||||
}
|
||||
@@ -784,34 +794,36 @@ namespace lime {
|
||||
|
||||
HL_PRIM vbyte* hl_lime_file_dialog_open_file (hl_vstring* title, hl_vstring* filter, hl_vstring* defaultPath) {
|
||||
|
||||
// #ifdef LIME_TINYFILEDIALOGS
|
||||
#ifdef LIME_TINYFILEDIALOGS
|
||||
|
||||
// std::wstring* _title = hxstring_to_wstring (title);
|
||||
// std::wstring* _filter = hxstring_to_wstring (filter);
|
||||
// std::wstring* _defaultPath = hxstring_to_wstring (defaultPath);
|
||||
std::wstring* _title = hxstring_to_wstring (title);
|
||||
std::wstring* _filter = hxstring_to_wstring (filter);
|
||||
std::wstring* _defaultPath = hxstring_to_wstring (defaultPath);
|
||||
|
||||
// std::wstring* path = FileDialog::OpenFile (_title, _filter, _defaultPath);
|
||||
std::wstring* path = FileDialog::OpenFile (_title, _filter, _defaultPath);
|
||||
|
||||
// if (_title) delete _title;
|
||||
// if (_filter) delete _filter;
|
||||
// if (_defaultPath) delete _defaultPath;
|
||||
if (_title) delete _title;
|
||||
if (_filter) delete _filter;
|
||||
if (_defaultPath) delete _defaultPath;
|
||||
|
||||
// if (path) {
|
||||
if (path) {
|
||||
|
||||
// value _path = alloc_wstring (path->c_str ());
|
||||
// delete path;
|
||||
// return _path;
|
||||
int size = std::wcslen (path->c_str ());
|
||||
char* result = (char*)malloc (size);
|
||||
std::wcstombs (result, path->c_str (), size);
|
||||
delete path;
|
||||
|
||||
// } else {
|
||||
return (vbyte*)result;
|
||||
|
||||
// delete path;
|
||||
// return alloc_null ();
|
||||
} else {
|
||||
|
||||
// }
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
||||
// #endif
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
||||
@@ -851,33 +863,38 @@ namespace lime {
|
||||
|
||||
HL_PRIM hl_varray* hl_lime_file_dialog_open_files (hl_vstring* title, hl_vstring* filter, hl_vstring* defaultPath) {
|
||||
|
||||
// #ifdef LIME_TINYFILEDIALOGS
|
||||
#ifdef LIME_TINYFILEDIALOGS
|
||||
|
||||
// std::wstring* _title = hxstring_to_wstring (title);
|
||||
// std::wstring* _filter = hxstring_to_wstring (filter);
|
||||
// std::wstring* _defaultPath = hxstring_to_wstring (defaultPath);
|
||||
std::wstring* _title = hxstring_to_wstring (title);
|
||||
std::wstring* _filter = hxstring_to_wstring (filter);
|
||||
std::wstring* _defaultPath = hxstring_to_wstring (defaultPath);
|
||||
|
||||
// std::vector<std::wstring*> files;
|
||||
std::vector<std::wstring*> files;
|
||||
|
||||
// FileDialog::OpenFiles (&files, _title, _filter, _defaultPath);
|
||||
// value result = alloc_array (files.size ());
|
||||
FileDialog::OpenFiles (&files, _title, _filter, _defaultPath);
|
||||
hl_varray* result = (hl_varray*)hl_alloc_array (&hlt_bytes, files.size ());
|
||||
vbyte** resultData = hl_aptr (result, vbyte*);
|
||||
|
||||
// if (_title) delete _title;
|
||||
// if (_filter) delete _filter;
|
||||
// if (_defaultPath) delete _defaultPath;
|
||||
if (_title) delete _title;
|
||||
if (_filter) delete _filter;
|
||||
if (_defaultPath) delete _defaultPath;
|
||||
|
||||
// for (int i = 0; i < files.size (); i++) {
|
||||
for (int i = 0; i < files.size (); i++) {
|
||||
|
||||
// val_array_set_i (result, i, alloc_wstring (files[i]->c_str ()));
|
||||
// delete files[i];
|
||||
int size = std::wcslen (files[i]->c_str ());
|
||||
char* _file = (char*)malloc (size);
|
||||
std::wcstombs (_file, files[i]->c_str (), size);
|
||||
|
||||
// }
|
||||
*resultData++ = (vbyte*)_file;
|
||||
delete files[i];
|
||||
|
||||
}
|
||||
|
||||
// #else
|
||||
// value result = alloc_array (0);
|
||||
// #endif
|
||||
#else
|
||||
hl_varray* result = hl_alloc_array (&hlt_bytes, 0);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
@@ -904,7 +921,6 @@ namespace lime {
|
||||
|
||||
} else {
|
||||
|
||||
delete path;
|
||||
return alloc_null ();
|
||||
|
||||
}
|
||||
@@ -918,34 +934,36 @@ namespace lime {
|
||||
|
||||
HL_PRIM vbyte* hl_lime_file_dialog_save_file (hl_vstring* title, hl_vstring* filter, hl_vstring* defaultPath) {
|
||||
|
||||
// #ifdef LIME_TINYFILEDIALOGS
|
||||
#ifdef LIME_TINYFILEDIALOGS
|
||||
|
||||
// std::wstring* _title = hxstring_to_wstring (title);
|
||||
// std::wstring* _filter = hxstring_to_wstring (filter);
|
||||
// std::wstring* _defaultPath = hxstring_to_wstring (defaultPath);
|
||||
std::wstring* _title = hxstring_to_wstring (title);
|
||||
std::wstring* _filter = hxstring_to_wstring (filter);
|
||||
std::wstring* _defaultPath = hxstring_to_wstring (defaultPath);
|
||||
|
||||
// std::wstring* path = FileDialog::SaveFile (_title, _filter, _defaultPath);
|
||||
std::wstring* path = FileDialog::SaveFile (_title, _filter, _defaultPath);
|
||||
|
||||
// if (_title) delete _title;
|
||||
// if (_filter) delete _filter;
|
||||
// if (_defaultPath) delete _defaultPath;
|
||||
if (_title) delete _title;
|
||||
if (_filter) delete _filter;
|
||||
if (_defaultPath) delete _defaultPath;
|
||||
|
||||
// if (path) {
|
||||
if (path) {
|
||||
|
||||
// value _path = alloc_wstring (path->c_str ());
|
||||
// delete path;
|
||||
// return _path;
|
||||
int size = std::wcslen (path->c_str ());
|
||||
char* result = (char*)malloc (size);
|
||||
std::wcstombs (result, path->c_str (), size);
|
||||
delete path;
|
||||
|
||||
// } else {
|
||||
return (vbyte*)result;
|
||||
|
||||
// delete path;
|
||||
// return alloc_null ();
|
||||
} else {
|
||||
|
||||
// }
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
||||
// #endif
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
||||
@@ -1595,9 +1613,6 @@ namespace lime {
|
||||
|
||||
if (guid) {
|
||||
|
||||
// value result = alloc_string (guid);
|
||||
// delete guid;
|
||||
// return result;
|
||||
return (vbyte*)guid;
|
||||
|
||||
} else {
|
||||
@@ -2412,12 +2427,13 @@ namespace lime {
|
||||
|
||||
} else {
|
||||
|
||||
// value result = alloc_string (locale->c_str ());
|
||||
// delete locale;
|
||||
int size = locale->size ();
|
||||
char* _locale = (char*)malloc (size + 1);
|
||||
strncpy (_locale, locale->c_str (), size);
|
||||
_locale[size] = '\0';
|
||||
delete locale;
|
||||
|
||||
// TODO: Copy string
|
||||
|
||||
return (vbyte*)locale->c_str ();
|
||||
return (vbyte*)_locale;
|
||||
|
||||
}
|
||||
|
||||
@@ -2894,12 +2910,12 @@ namespace lime {
|
||||
|
||||
if (model) {
|
||||
|
||||
// TODO: Copy string
|
||||
return (vbyte*)model->c_str ();
|
||||
int size = std::wcslen (model->c_str ());
|
||||
char* result = (char*)malloc (size);
|
||||
std::wcstombs (result, model->c_str (), size);
|
||||
delete model;
|
||||
|
||||
// value result = alloc_wstring (model->c_str ());
|
||||
// delete model;
|
||||
// return result;
|
||||
return (vbyte*)result;
|
||||
|
||||
} else {
|
||||
|
||||
@@ -2935,12 +2951,12 @@ namespace lime {
|
||||
|
||||
if (vendor) {
|
||||
|
||||
// TODO: Copy string
|
||||
return (vbyte*)vendor->c_str ();
|
||||
int size = std::wcslen (vendor->c_str ());
|
||||
char* result = (char*)malloc (size);
|
||||
std::wcstombs (result, vendor->c_str (), size);
|
||||
delete vendor;
|
||||
|
||||
// value result = alloc_wstring (vendor->c_str ());
|
||||
// delete vendor;
|
||||
// return result;
|
||||
return (vbyte*)result;
|
||||
|
||||
} else {
|
||||
|
||||
@@ -2976,12 +2992,12 @@ namespace lime {
|
||||
|
||||
if (path) {
|
||||
|
||||
// TODO: Copy string
|
||||
return (vbyte*)path->c_str ();
|
||||
int size = std::wcslen (path->c_str ());
|
||||
char* result = (char*)malloc (size);
|
||||
std::wcstombs (result, path->c_str (), size);
|
||||
delete path;
|
||||
|
||||
// value result = alloc_wstring (path->c_str ());
|
||||
// delete path;
|
||||
// return result;
|
||||
return (vbyte*)result;
|
||||
|
||||
} else {
|
||||
|
||||
@@ -3068,12 +3084,12 @@ namespace lime {
|
||||
|
||||
if (label) {
|
||||
|
||||
// TODO: Copy string
|
||||
return (vbyte*)label->c_str ();
|
||||
int size = std::wcslen (label->c_str ());
|
||||
char* result = (char*)malloc (size);
|
||||
std::wcstombs (result, label->c_str (), size);
|
||||
delete label;
|
||||
|
||||
// value result = alloc_wstring (label->c_str ());
|
||||
// delete label;
|
||||
// return result;
|
||||
return (vbyte*)result;
|
||||
|
||||
} else {
|
||||
|
||||
@@ -3109,12 +3125,12 @@ namespace lime {
|
||||
|
||||
if (name) {
|
||||
|
||||
// TODO: Copy string
|
||||
return (vbyte*)name->c_str ();
|
||||
int size = std::wcslen (name->c_str ());
|
||||
char* result = (char*)malloc (size);
|
||||
std::wcstombs (result, name->c_str (), size);
|
||||
delete name;
|
||||
|
||||
// value result = alloc_wstring (name->c_str ());
|
||||
// delete name;
|
||||
// return result;
|
||||
return (vbyte*)result;
|
||||
|
||||
} else {
|
||||
|
||||
@@ -3150,12 +3166,12 @@ namespace lime {
|
||||
|
||||
if (version) {
|
||||
|
||||
// TODO: Copy string
|
||||
return (vbyte*)version->c_str ();
|
||||
int size = std::wcslen (version->c_str ());
|
||||
char* result = (char*)malloc (size);
|
||||
std::wcstombs (result, version->c_str (), size);
|
||||
delete version;
|
||||
|
||||
// value result = alloc_wstring (version->c_str ());
|
||||
// delete version;
|
||||
// return result;
|
||||
return (vbyte*)result;
|
||||
|
||||
} else {
|
||||
|
||||
@@ -3845,16 +3861,6 @@ namespace lime {
|
||||
|
||||
if (result) {
|
||||
|
||||
// value _result = alloc_string (result);
|
||||
|
||||
// if (result != title.c_str ()) {
|
||||
|
||||
// free ((char*) result);
|
||||
|
||||
// }
|
||||
|
||||
// return _result;
|
||||
//return (vbyte*)result;
|
||||
return title;
|
||||
|
||||
} else {
|
||||
@@ -4085,7 +4091,6 @@ namespace lime {
|
||||
#define _ENUM "?"
|
||||
// #define _TCFFIPOINTER _ABSTRACT (HL_CFFIPointer)
|
||||
#define _TAPPLICATION_EVENT _OBJ (_I32 _I32)
|
||||
#define _TARRAYBUFFER _TBYTES
|
||||
#define _TBYTES _OBJ (_I32 _BYTES)
|
||||
#define _TCFFIPOINTER _DYN
|
||||
#define _TCLIPBOARD_EVENT _OBJ (_I32)
|
||||
@@ -4104,6 +4109,7 @@ namespace lime {
|
||||
#define _TVORBISFILE _OBJ (_I32 _DYN)
|
||||
#define _TWINDOW_EVENT _OBJ (_I32 _I32 _I32 _I32 _I32 _I32)
|
||||
|
||||
#define _TARRAYBUFFER _TBYTES
|
||||
#define _TARRAYBUFFERVIEW _OBJ (_I32 _TARRAYBUFFER _I32 _I32 _I32 _I32)
|
||||
#define _TAUDIOBUFFER _OBJ (_I32 _I32 _TARRAYBUFFERVIEW _I32 _DYN _DYN _DYN _DYN _DYN _DYN _TVORBISFILE)
|
||||
#define _TIMAGEBUFFER _OBJ (_I32 _TARRAYBUFFERVIEW _I32 _I32 _BOOL _BOOL _I32 _DYN _DYN _DYN _DYN _DYN _DYN)
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -11,18 +11,18 @@
|
||||
namespace lime {
|
||||
|
||||
|
||||
std::map<value, value> curlMultiHandles;
|
||||
std::map<value, int> curlMultiRunningHandles;
|
||||
std::map<value, bool> curlMultiValid;
|
||||
std::map<CURL*, value> curlObjects;
|
||||
std::map<value, bool> curlValid;
|
||||
std::map<value, AutoGCRoot*> headerCallbacks;
|
||||
std::map<value, curl_slist*> headerSLists;
|
||||
std::map<value, AutoGCRoot*> progressCallbacks;
|
||||
std::map<value, AutoGCRoot*> readCallbacks;
|
||||
std::map<void*, void*> curlMultiHandles;
|
||||
std::map<void*, int> curlMultiRunningHandles;
|
||||
std::map<void*, bool> curlMultiValid;
|
||||
std::map<CURL*, void*> curlObjects;
|
||||
std::map<void*, bool> curlValid;
|
||||
std::map<void*, AutoGCRoot*> headerCallbacks;
|
||||
std::map<void*, curl_slist*> headerSLists;
|
||||
std::map<void*, AutoGCRoot*> progressCallbacks;
|
||||
std::map<void*, AutoGCRoot*> readCallbacks;
|
||||
std::map<AutoGCRoot*, Bytes*> writeBytes;
|
||||
std::map<AutoGCRoot*, AutoGCRoot*> writeBytesRoot;
|
||||
std::map<value, AutoGCRoot*> writeCallbacks;
|
||||
std::map<void*, AutoGCRoot*> writeCallbacks;
|
||||
Mutex curl_gc_mutex;
|
||||
|
||||
|
||||
@@ -128,6 +128,108 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
void hl_gc_curl (HL_CFFIPointer* handle) {
|
||||
|
||||
if (handle) {
|
||||
|
||||
curl_gc_mutex.Lock ();
|
||||
|
||||
if (curlMultiHandles.find (handle) != curlMultiHandles.end ()) {
|
||||
|
||||
CURLM* multi = curlMultiHandles[handle];
|
||||
curl_multi_remove_handle (multi, handle);
|
||||
curlMultiHandles.erase (handle);
|
||||
|
||||
}
|
||||
|
||||
if (curlValid.find (handle) != curlValid.end ()) {
|
||||
|
||||
CURL* curl = (CURL*)handle->ptr;
|
||||
|
||||
curlValid.erase (handle);
|
||||
curlObjects.erase (curl);
|
||||
curl_easy_cleanup (curl);
|
||||
|
||||
}
|
||||
|
||||
AutoGCRoot* callback;
|
||||
|
||||
if (headerCallbacks.find (handle) != headerCallbacks.end ()) {
|
||||
|
||||
callback = headerCallbacks[handle];
|
||||
|
||||
if (writeBytes.find (callback) != writeBytes.end ()) {
|
||||
|
||||
Bytes* _writeBytes = writeBytes[callback];
|
||||
delete _writeBytes;
|
||||
writeBytes.erase (callback);
|
||||
|
||||
AutoGCRoot* _writeBytesRoot = writeBytesRoot[callback];
|
||||
delete _writeBytesRoot;
|
||||
writeBytesRoot.erase (callback);
|
||||
|
||||
}
|
||||
|
||||
headerCallbacks.erase (handle);
|
||||
delete callback;
|
||||
|
||||
}
|
||||
|
||||
if (headerSLists.find (handle) != headerSLists.end ()) {
|
||||
|
||||
curl_slist* chunk = headerSLists[handle];
|
||||
headerSLists.erase (handle);
|
||||
curl_slist_free_all (chunk);
|
||||
|
||||
}
|
||||
|
||||
if (progressCallbacks.find (handle) != progressCallbacks.end ()) {
|
||||
|
||||
callback = progressCallbacks[handle];
|
||||
progressCallbacks.erase (handle);
|
||||
delete callback;
|
||||
|
||||
}
|
||||
|
||||
if (readCallbacks.find (handle) != readCallbacks.end ()) {
|
||||
|
||||
callback = readCallbacks[handle];
|
||||
readCallbacks.erase (handle);
|
||||
delete callback;
|
||||
|
||||
}
|
||||
|
||||
if (writeCallbacks.find (handle) != writeCallbacks.end ()) {
|
||||
|
||||
callback = writeCallbacks[handle];
|
||||
|
||||
if (writeBytes.find (callback) != writeBytes.end ()) {
|
||||
|
||||
Bytes* _writeBytes = writeBytes[callback];
|
||||
delete _writeBytes;
|
||||
writeBytes.erase (callback);
|
||||
|
||||
AutoGCRoot* _writeBytesRoot = writeBytesRoot[callback];
|
||||
delete _writeBytesRoot;
|
||||
writeBytesRoot.erase (callback);
|
||||
|
||||
}
|
||||
|
||||
writeCallbacks.erase (handle);
|
||||
delete callback;
|
||||
|
||||
}
|
||||
|
||||
handle->finalizer = NULL;
|
||||
//handle = alloc_null ();
|
||||
|
||||
curl_gc_mutex.Unlock ();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void gc_curl_multi (value handle) {
|
||||
|
||||
if (!val_is_null (handle)) {
|
||||
@@ -141,11 +243,11 @@ namespace lime {
|
||||
|
||||
}
|
||||
|
||||
for (std::map<value, value>::iterator it = curlMultiHandles.begin (); it != curlMultiHandles.end (); ++it) {
|
||||
for (std::map<void*, void*>::iterator it = curlMultiHandles.begin (); it != curlMultiHandles.end (); ++it) {
|
||||
|
||||
if (curlMultiHandles[it->first] == handle) {
|
||||
|
||||
gc_curl (it->first);
|
||||
gc_curl ((value)it->first);
|
||||
|
||||
}
|
||||
|
||||
@@ -161,6 +263,39 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
void hl_gc_curl_multi (HL_CFFIPointer* handle) {
|
||||
|
||||
if (handle) {
|
||||
|
||||
curl_gc_mutex.Lock ();
|
||||
|
||||
if (curlMultiValid.find (handle) != curlMultiValid.end ()) {
|
||||
|
||||
curlMultiValid.erase (handle);
|
||||
curl_multi_cleanup ((CURL*)handle->ptr);
|
||||
|
||||
}
|
||||
|
||||
for (std::map<void*, void*>::iterator it = curlMultiHandles.begin (); it != curlMultiHandles.end (); ++it) {
|
||||
|
||||
if (curlMultiHandles[it->first] == handle) {
|
||||
|
||||
hl_gc_curl ((HL_CFFIPointer*)it->first);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
handle->finalizer = NULL;
|
||||
//handle = alloc_null ();
|
||||
|
||||
curl_gc_mutex.Unlock ();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void lime_curl_easy_cleanup (value handle) {
|
||||
|
||||
// Disabled due to collision with GC-based cleanup
|
||||
@@ -180,6 +315,25 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
HL_PRIM void hl_lime_curl_easy_cleanup (HL_CFFIPointer* handle) {
|
||||
|
||||
// Disabled due to collision with GC-based cleanup
|
||||
// when GC occurs on a different thread
|
||||
|
||||
// if (!val_is_null (handle)) {
|
||||
|
||||
// if (curlValid.find (handle) != curlValid.end ()) {
|
||||
|
||||
// curlValid.erase (handle);
|
||||
// curl_easy_cleanup ((CURL*)val_data(handle));
|
||||
|
||||
// }
|
||||
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
|
||||
value lime_curl_easy_duphandle (value handle) {
|
||||
|
||||
curl_gc_mutex.Lock ();
|
||||
@@ -223,6 +377,49 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
HL_PRIM HL_CFFIPointer* hl_lime_curl_easy_duphandle (HL_CFFIPointer* handle) {
|
||||
|
||||
curl_gc_mutex.Lock ();
|
||||
|
||||
CURL* dup = curl_easy_duphandle ((CURL*)handle->ptr);
|
||||
HL_CFFIPointer* duphandle = HLCFFIPointer (dup, (hl_finalizer)hl_gc_curl);
|
||||
curlValid[duphandle] = true;
|
||||
curlObjects[dup] = duphandle;
|
||||
|
||||
// AutoGCRoot* callback;
|
||||
// Bytes* _writeBytes;
|
||||
|
||||
// if (headerCallbacks.find (handle) != headerCallbacks.end ()) {
|
||||
// callback = headerCallbacks[handle];
|
||||
// // _writeBytes = new Bytes (1024);
|
||||
// writeBytes[callback] = _writeBytes;
|
||||
// writeBytesRoot[callback] = new AutoGCRoot ((value)_writeBytes->Value ());
|
||||
// headerCallbacks[duphandle] = new AutoGCRoot (headerCallbacks[handle]->get());
|
||||
// }
|
||||
|
||||
// if (progressCallbacks.find (handle) != progressCallbacks.end ()) {
|
||||
// progressCallbacks[duphandle] = new AutoGCRoot (progressCallbacks[handle]->get());
|
||||
// }
|
||||
|
||||
// if (readCallbacks.find (handle) != readCallbacks.end ()) {
|
||||
// readCallbacks[duphandle] = new AutoGCRoot (readCallbacks[handle]->get());
|
||||
// }
|
||||
|
||||
// if (writeCallbacks.find (handle) != writeCallbacks.end ()) {
|
||||
// callback = writeCallbacks[handle];
|
||||
// // _writeBytes = new Bytes (1024);
|
||||
// writeBytes[callback] = _writeBytes;
|
||||
// writeBytesRoot[callback] = new AutoGCRoot ((value)_writeBytes->Value ());
|
||||
// writeCallbacks[duphandle] = new AutoGCRoot (writeCallbacks[handle]->get());
|
||||
// }
|
||||
|
||||
curl_gc_mutex.Unlock ();
|
||||
|
||||
return duphandle;
|
||||
|
||||
}
|
||||
|
||||
|
||||
value lime_curl_easy_escape (value curl, HxString url, int length) {
|
||||
|
||||
char* result = curl_easy_escape ((CURL*)val_data(curl), url.__s, length);
|
||||
@@ -231,6 +428,14 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
HL_PRIM vbyte* hl_lime_curl_easy_escape (HL_CFFIPointer* curl, hl_vstring* url, int length) {
|
||||
|
||||
char* result = curl_easy_escape ((CURL*)curl->ptr, url ? hl_to_utf8 (url->bytes) : NULL, length);
|
||||
return (vbyte*)result;
|
||||
|
||||
}
|
||||
|
||||
|
||||
value lime_curl_easy_getinfo (value curl, int info) {
|
||||
|
||||
CURLcode code = CURLE_OK;
|
||||
@@ -332,6 +537,126 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
HL_PRIM vdynamic* hl_lime_curl_easy_getinfo (HL_CFFIPointer* curl, int info) {
|
||||
|
||||
CURLcode code = CURLE_OK;
|
||||
CURL* handle = (CURL*)curl->ptr;
|
||||
CURLINFO type = (CURLINFO)info;
|
||||
|
||||
int size;
|
||||
vdynamic* result = NULL;
|
||||
|
||||
switch (type) {
|
||||
|
||||
case CURLINFO_EFFECTIVE_URL:
|
||||
case CURLINFO_REDIRECT_URL:
|
||||
case CURLINFO_CONTENT_TYPE:
|
||||
case CURLINFO_PRIVATE:
|
||||
case CURLINFO_PRIMARY_IP:
|
||||
case CURLINFO_LOCAL_IP:
|
||||
case CURLINFO_FTP_ENTRY_PATH:
|
||||
case CURLINFO_RTSP_SESSION_ID:
|
||||
case CURLINFO_SCHEME:
|
||||
{
|
||||
char stringValue;
|
||||
code = curl_easy_getinfo (handle, type, &stringValue);
|
||||
|
||||
int size = strlen (&stringValue) + 1;
|
||||
char* val = (char*)malloc (size);
|
||||
memcpy (val, &stringValue, size);
|
||||
|
||||
result = hl_alloc_dynamic (&hlt_bytes);
|
||||
result->v.b = val;
|
||||
return result;
|
||||
break;
|
||||
}
|
||||
|
||||
case CURLINFO_RESPONSE_CODE:
|
||||
case CURLINFO_HTTP_CONNECTCODE:
|
||||
case CURLINFO_FILETIME:
|
||||
case CURLINFO_REDIRECT_COUNT:
|
||||
case CURLINFO_HEADER_SIZE:
|
||||
case CURLINFO_REQUEST_SIZE:
|
||||
case CURLINFO_SSL_VERIFYRESULT:
|
||||
case CURLINFO_HTTPAUTH_AVAIL:
|
||||
case CURLINFO_PROXYAUTH_AVAIL:
|
||||
case CURLINFO_OS_ERRNO:
|
||||
case CURLINFO_NUM_CONNECTS:
|
||||
case CURLINFO_PRIMARY_PORT:
|
||||
case CURLINFO_LOCAL_PORT:
|
||||
case CURLINFO_LASTSOCKET:
|
||||
case CURLINFO_CONDITION_UNMET:
|
||||
case CURLINFO_RTSP_CLIENT_CSEQ:
|
||||
case CURLINFO_RTSP_SERVER_CSEQ:
|
||||
case CURLINFO_RTSP_CSEQ_RECV:
|
||||
case CURLINFO_HTTP_VERSION:
|
||||
case CURLINFO_PROXY_SSL_VERIFYRESULT:
|
||||
case CURLINFO_PROTOCOL:
|
||||
case CURLINFO_SIZE_UPLOAD_T: // TODO: These should be larger
|
||||
case CURLINFO_SIZE_DOWNLOAD_T:
|
||||
case CURLINFO_SPEED_DOWNLOAD_T:
|
||||
case CURLINFO_SPEED_UPLOAD_T:
|
||||
case CURLINFO_CONTENT_LENGTH_DOWNLOAD_T:
|
||||
case CURLINFO_CONTENT_LENGTH_UPLOAD_T:
|
||||
{
|
||||
long intValue;
|
||||
code = curl_easy_getinfo (handle, type, &intValue);
|
||||
|
||||
result = hl_alloc_dynamic (&hlt_i32);
|
||||
result->v.i = intValue;
|
||||
return result;
|
||||
break;
|
||||
}
|
||||
|
||||
case CURLINFO_TOTAL_TIME:
|
||||
case CURLINFO_NAMELOOKUP_TIME:
|
||||
case CURLINFO_CONNECT_TIME:
|
||||
case CURLINFO_APPCONNECT_TIME:
|
||||
case CURLINFO_PRETRANSFER_TIME:
|
||||
case CURLINFO_STARTTRANSFER_TIME:
|
||||
case CURLINFO_REDIRECT_TIME:
|
||||
case CURLINFO_SIZE_UPLOAD:
|
||||
case CURLINFO_SIZE_DOWNLOAD:
|
||||
case CURLINFO_SPEED_DOWNLOAD:
|
||||
case CURLINFO_SPEED_UPLOAD:
|
||||
case CURLINFO_CONTENT_LENGTH_DOWNLOAD:
|
||||
case CURLINFO_CONTENT_LENGTH_UPLOAD:
|
||||
{
|
||||
double floatValue;
|
||||
code = curl_easy_getinfo (handle, type, &floatValue);
|
||||
|
||||
result = hl_alloc_dynamic (&hlt_f64);
|
||||
result->v.d = floatValue;
|
||||
return result;
|
||||
break;
|
||||
}
|
||||
|
||||
case CURLINFO_SSL_ENGINES:
|
||||
case CURLINFO_COOKIELIST:
|
||||
case CURLINFO_CERTINFO:
|
||||
case CURLINFO_TLS_SESSION:
|
||||
case CURLINFO_TLS_SSL_PTR:
|
||||
case CURLINFO_ACTIVESOCKET:
|
||||
|
||||
// TODO
|
||||
|
||||
break;
|
||||
|
||||
case CURLINFO_NONE:
|
||||
case CURLINFO_LASTONE:
|
||||
|
||||
// ignore
|
||||
|
||||
break;
|
||||
|
||||
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
||||
|
||||
value lime_curl_easy_init () {
|
||||
|
||||
curl_gc_mutex.Lock ();
|
||||
@@ -379,6 +704,53 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
HL_PRIM HL_CFFIPointer* hl_lime_curl_easy_init () {
|
||||
|
||||
curl_gc_mutex.Lock ();
|
||||
|
||||
CURL* curl = curl_easy_init ();
|
||||
HL_CFFIPointer* handle = HLCFFIPointer (curl, (hl_finalizer)hl_gc_curl);
|
||||
|
||||
if (curlValid.find (handle) != curlValid.end ()) {
|
||||
|
||||
printf ("Error: Duplicate cURL handle\n");
|
||||
|
||||
}
|
||||
|
||||
if (headerCallbacks.find (handle) != headerCallbacks.end ()) {
|
||||
|
||||
printf ("Error: cURL handle already has header callback\n");
|
||||
|
||||
}
|
||||
|
||||
if (progressCallbacks.find (handle) != progressCallbacks.end ()) {
|
||||
|
||||
printf ("Error: cURL handle already has progress callback\n");
|
||||
|
||||
}
|
||||
|
||||
if (readCallbacks.find (handle) != readCallbacks.end ()) {
|
||||
|
||||
printf ("Error: cURL handle already has read callback\n");
|
||||
|
||||
}
|
||||
|
||||
if (writeCallbacks.find (handle) != writeCallbacks.end ()) {
|
||||
|
||||
printf ("Error: cURL handle already has write callback\n");
|
||||
|
||||
}
|
||||
|
||||
curlValid[handle] = true;
|
||||
curlObjects[curl] = handle;
|
||||
|
||||
curl_gc_mutex.Unlock ();
|
||||
|
||||
return handle;
|
||||
|
||||
}
|
||||
|
||||
|
||||
int lime_curl_easy_pause (value handle, int bitmask) {
|
||||
|
||||
return curl_easy_pause ((CURL*)val_data(handle), bitmask);
|
||||
@@ -386,6 +758,13 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
HL_PRIM int hl_lime_curl_easy_pause (HL_CFFIPointer* handle, int bitmask) {
|
||||
|
||||
return curl_easy_pause ((CURL*)handle->ptr, bitmask);
|
||||
|
||||
}
|
||||
|
||||
|
||||
int lime_curl_easy_perform (value easy_handle) {
|
||||
|
||||
int code;
|
||||
@@ -399,6 +778,19 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
HL_PRIM int hl_lime_curl_easy_perform (HL_CFFIPointer* easy_handle) {
|
||||
|
||||
int code;
|
||||
System::GCEnterBlocking ();
|
||||
|
||||
code = curl_easy_perform ((CURL*)easy_handle->ptr);
|
||||
|
||||
System::GCExitBlocking ();
|
||||
return code;
|
||||
|
||||
}
|
||||
|
||||
|
||||
int lime_curl_easy_recv (value curl, value buffer, int buflen, int n) {
|
||||
|
||||
// TODO
|
||||
@@ -408,6 +800,15 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
HL_PRIM int hl_lime_curl_easy_recv (HL_CFFIPointer* curl, double buffer, int buflen, int n) {
|
||||
|
||||
// TODO
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void lime_curl_easy_reset (value curl) {
|
||||
|
||||
curl_easy_reset ((CURL*)val_data(curl));
|
||||
@@ -415,6 +816,13 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
HL_PRIM void hl_lime_curl_easy_reset (HL_CFFIPointer* curl) {
|
||||
|
||||
curl_easy_reset ((CURL*)curl->ptr);
|
||||
|
||||
}
|
||||
|
||||
|
||||
int lime_curl_easy_send (value curl, value buffer, int buflen, int n) {
|
||||
|
||||
// TODO
|
||||
@@ -424,6 +832,15 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
HL_PRIM int hl_lime_curl_easy_send (HL_CFFIPointer* curl, double buffer, int buflen, int n) {
|
||||
|
||||
// TODO
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
static size_t write_callback (void *ptr, size_t size, size_t nmemb, void *userp) {
|
||||
|
||||
AutoGCRoot* callback = (AutoGCRoot*)userp;
|
||||
@@ -978,7 +1395,7 @@ namespace lime {
|
||||
|
||||
if (curlObjects.find (curl) != curlObjects.end ()) {
|
||||
|
||||
alloc_field (result, easy_handle, curlObjects[curl]);
|
||||
alloc_field (result, easy_handle, (value)curlObjects[curl]);
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user