summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
d77539e)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>
// Callback method to read datas from buffer.
size_t nit_curl_callback_read_func(void *buffer, size_t size, size_t count, CURLCallbackReadDatas *datas){
int len = datas->len - datas->pos;
// Callback method to read datas from buffer.
size_t nit_curl_callback_read_func(void *buffer, size_t size, size_t count, CURLCallbackReadDatas *datas){
int len = datas->len - datas->pos;
extern class CCurl `{ CURL * `}
# Constructor, CURL low level initializer
new easy_init `{ return curl_easy_init(); `}
extern class CCurl `{ CURL * `}
# Constructor, CURL low level initializer
new easy_init `{ return curl_easy_init(); `}
# Check for correct initialization
# Check for correct initialization
- fun is_init:Bool `{ return (self != NULL); `}
+ fun is_init: Bool `{ return (self != NULL); `}
+
# Easy Clean / Release CURL instance
fun easy_clean `{ curl_easy_cleanup( self ); `}
# Easy Clean / Release CURL instance
fun easy_clean `{ curl_easy_cleanup( self ); `}
# Perform the transfer described by setted options
# Perform the transfer described by setted options
- fun easy_perform:CURLCode `{ return curl_easy_perform( self ); `}
# Set options to tell CURL how to behave. Obj parameter type can be Int, Bool, String, OFile, CURLSList.
# Set options to tell CURL how to behave. Obj parameter type can be Int, Bool, String, OFile, CURLSList.
- fun easy_setopt(opt: CURLOption, obj: Object):CURLCode
+ fun easy_perform: CURLCode `{ return curl_easy_perform( self ); `}
+ fun easy_setopt(opt: CURLOption, obj: Object): CURLCode
do
if obj isa Int then return i_setopt_int(opt, obj)
if obj isa Bool and obj == true then return i_setopt_int(opt, 1)
do
if obj isa Int then return i_setopt_int(opt, obj)
if obj isa Bool and obj == true then return i_setopt_int(opt, 1)
end
# Internal method to set options to CURL using OFile parameter.
private fun i_setopt_file(opt: CURLOption, fl: OFile):CURLCode `{ return curl_easy_setopt( self, opt, fl); `}
end
# Internal method to set options to CURL using OFile parameter.
private fun i_setopt_file(opt: CURLOption, fl: OFile):CURLCode `{ return curl_easy_setopt( self, opt, fl); `}
# Internal method to set options to CURL using Int parameter.
# Internal method to set options to CURL using Int parameter.
- private fun i_setopt_int(opt: CURLOption, num: Int):CURLCode `{ return curl_easy_setopt( self, opt, num); `}
+ private fun i_setopt_int(opt: CURLOption, num: Int): CURLCode `{ return curl_easy_setopt( self, opt, num); `}
+
# Internal method to set options to CURL using CURLSList parameter.
# Internal method to set options to CURL using CURLSList parameter.
- private fun i_setopt_slist(opt: CURLOption, list: CURLSList):CURLCode `{ return curl_easy_setopt( self, opt, list); `}
+ private fun i_setopt_slist(opt: CURLOption, list: CURLSList): CURLCode `{ return curl_easy_setopt( self, opt, list); `}
+
# Internal method to set options to CURL using String parameter.
# Internal method to set options to CURL using String parameter.
- private fun i_setopt_string(opt: CURLOption, str: String):CURLCode import String.to_cstring `{
+ private fun i_setopt_string(opt: CURLOption, str: String): CURLCode import String.to_cstring `{
char *rStr = String_to_cstring(str);
return curl_easy_setopt( self, opt, rStr);
`}
char *rStr = String_to_cstring(str);
return curl_easy_setopt( self, opt, rStr);
`}
# Request Chars internal information from the CURL session
# Request Chars internal information from the CURL session
- fun easy_getinfo_chars(opt: CURLInfoChars):nullable CURLInfoResponseString
+ fun easy_getinfo_chars(opt: CURLInfoChars): nullable CURLInfoResponseString
do
var answ = new CURLInfoResponseString
if not i_getinfo_chars(opt, answ).is_ok then return null
return answ
end
do
var answ = new CURLInfoResponseString
if not i_getinfo_chars(opt, answ).is_ok then return null
return answ
end
# Internal method used to get String object information initially knowns as C Chars type
# Internal method used to get String object information initially knowns as C Chars type
- private fun i_getinfo_chars(opt: CURLInfoChars, res: CURLInfoResponseString):CURLCode import CURLInfoResponseString.response=, NativeString.to_s_with_copy `{
+ private fun i_getinfo_chars(opt: CURLInfoChars, res: CURLInfoResponseString): CURLCode import CURLInfoResponseString.response=, NativeString.to_s_with_copy `{
char *r = NULL;
CURLcode c = curl_easy_getinfo( self, opt, &r);
if((c == CURLE_OK) && r != NULL){
char *r = NULL;
CURLcode c = curl_easy_getinfo( self, opt, &r);
if((c == CURLE_OK) && r != NULL){
# Request Long internal information from the CURL session
# Request Long internal information from the CURL session
- fun easy_getinfo_long(opt: CURLInfoLong):nullable CURLInfoResponseLong
+ fun easy_getinfo_long(opt: CURLInfoLong): nullable CURLInfoResponseLong
do
var answ = new CURLInfoResponseLong
if not i_getinfo_long(opt, answ).is_ok then return null
return answ
end
do
var answ = new CURLInfoResponseLong
if not i_getinfo_long(opt, answ).is_ok then return null
return answ
end
# Internal method used to get Int object information initially knowns as C Long type
# Internal method used to get Int object information initially knowns as C Long type
- private fun i_getinfo_long(opt: CURLInfoLong, res: CURLInfoResponseLong):CURLCode import CURLInfoResponseLong.response= `{
+ private fun i_getinfo_long(opt: CURLInfoLong, res: CURLInfoResponseLong): CURLCode import CURLInfoResponseLong.response= `{
long *r = NULL;
r = malloc(sizeof(long));
CURLcode c = curl_easy_getinfo( self, opt, r);
long *r = NULL;
r = malloc(sizeof(long));
CURLcode c = curl_easy_getinfo( self, opt, r);
# Request Double internal information from the CURL session
# Request Double internal information from the CURL session
- fun easy_getinfo_double(opt: CURLInfoDouble):nullable CURLInfoResponseDouble
+ fun easy_getinfo_double(opt: CURLInfoDouble): nullable CURLInfoResponseDouble
do
var answ = new CURLInfoResponseDouble
if not i_getinfo_double(opt, answ).is_ok then return null
return answ
end
do
var answ = new CURLInfoResponseDouble
if not i_getinfo_double(opt, answ).is_ok then return null
return answ
end
# Internal method used to get Int object information initially knowns as C Double type
# Internal method used to get Int object information initially knowns as C Double type
- private fun i_getinfo_double(opt: CURLInfoDouble, res: CURLInfoResponseDouble):CURLCode import CURLInfoResponseDouble.response= `{
+ private fun i_getinfo_double(opt: CURLInfoDouble, res: CURLInfoResponseDouble): CURLCode import CURLInfoResponseDouble.response= `{
double *r = NULL;
r = malloc(sizeof(double));
CURLcode c = curl_easy_getinfo( self, opt, r);
double *r = NULL;
r = malloc(sizeof(double));
CURLcode c = curl_easy_getinfo( self, opt, r);
# Request SList internal information from the CURL session
# Request SList internal information from the CURL session
- fun easy_getinfo_slist(opt: CURLInfoSList):nullable CURLInfoResponseArray
+ fun easy_getinfo_slist(opt: CURLInfoSList): nullable CURLInfoResponseArray
do
var answ = new CURLInfoResponseArray
if not i_getinfo_slist(opt, answ).is_ok then return null
do
var answ = new CURLInfoResponseArray
if not i_getinfo_slist(opt, answ).is_ok then return null
answ.prim_response.destroy
return answ
end
answ.prim_response.destroy
return answ
end
# Internal method used to get Array[String] object information initially knowns as C SList type
# Internal method used to get Array[String] object information initially knowns as C SList type
- private fun i_getinfo_slist(opt: CURLInfoSList, res: CURLInfoResponseArray):CURLCode import CURLInfoResponseArray.prim_response=`{
+ private fun i_getinfo_slist(opt: CURLInfoSList, res: CURLInfoResponseArray): CURLCode import CURLInfoResponseArray.prim_response= `{
struct curl_slist* csl = NULL;
CURLcode ce = curl_easy_getinfo( self, opt, &csl);
CURLInfoResponseArray_prim_response__assign(res, csl);
return ce;
`}
struct curl_slist* csl = NULL;
CURLcode ce = curl_easy_getinfo( self, opt, &csl);
CURLInfoResponseArray_prim_response__assign(res, csl);
return ce;
`}
# Register delegate to get callbacks about the CURL transfer performed
# Register delegate to get callbacks about the CURL transfer performed
- fun register_callback(delegate: CCurlCallbacks, cbtype: CURLCallbackType):CURLCode
+ fun register_callback(delegate: CCurlCallbacks, cbtype: CURLCallbackType): CURLCode
do
if once [new CURLCallbackType.header, new CURLCallbackType.body, new CURLCallbackType.stream, new CURLCallbackType.read].has(cbtype) then
return i_register_callback(delegate, cbtype)
end
return once new CURLCode.unknown_option
end
do
if once [new CURLCallbackType.header, new CURLCallbackType.body, new CURLCallbackType.stream, new CURLCallbackType.read].has(cbtype) then
return i_register_callback(delegate, cbtype)
end
return once new CURLCode.unknown_option
end
# Register delegate to read datas from given buffer
# Register delegate to read datas from given buffer
- fun register_read_datas_callback(delegate: CCurlCallbacks, datas: String):CURLCode
+ fun register_read_datas_callback(delegate: CCurlCallbacks, datas: String): CURLCode
do
if datas.length > 0 then return i_register_read_datas_callback(delegate, datas, datas.length)
return once new CURLCode.unknown_option
end
do
if datas.length > 0 then return i_register_read_datas_callback(delegate, datas, datas.length)
return once new CURLCode.unknown_option
end
# Internal method used to configure read callback
# Internal method used to configure read callback
- private fun i_register_read_datas_callback(delegate: CCurlCallbacks, datas: String, size: Int):CURLCode import String.to_cstring `{
+ private fun i_register_read_datas_callback(delegate: CCurlCallbacks, datas: String, size: Int): CURLCode import String.to_cstring `{
CURLCallbackReadDatas *d = NULL;
d = malloc(sizeof(CURLCallbackReadDatas));
d->data = (char*)String_to_cstring(datas);
CURLCallbackReadDatas *d = NULL;
d = malloc(sizeof(CURLCallbackReadDatas));
d->data = (char*)String_to_cstring(datas);
d->pos = 0;
return curl_easy_setopt( self, CURLOPT_READDATA, d);
`}
d->pos = 0;
return curl_easy_setopt( self, CURLOPT_READDATA, d);
`}
# Internal method used to configure callbacks in terms of given type
# Internal method used to configure callbacks in terms of given type
- private fun i_register_callback(delegate: CCurlCallbacks, cbtype: CURLCallbackType):CURLCode is extern import CCurlCallbacks.header_callback, CCurlCallbacks.body_callback, CCurlCallbacks.stream_callback, NativeString.to_s_with_copy, NativeString.to_s `{
+ private fun i_register_callback(delegate: CCurlCallbacks, cbtype: CURLCallbackType):CURLCode is extern import CCurlCallbacks.native_header_callback, CCurlCallbacks.native_body_callback, CCurlCallbacks.native_stream_callback `{
CURLCallbackDatas *d = malloc(sizeof(CURLCallbackDatas));
CCurlCallbacks_incr_ref(delegate);
d->type = cbtype;
CURLCallbackDatas *d = malloc(sizeof(CURLCallbackDatas));
CCurlCallbacks_incr_ref(delegate);
d->type = cbtype;
# Convert given string to URL encoded string
# Convert given string to URL encoded string
- fun escape(url: String):String import String.to_cstring, NativeString.to_s_with_copy `{
+ fun escape(url: String): String import String.to_cstring, NativeString.to_s_with_copy `{
char *orig_url, *encoded_url = NULL;
orig_url = String_to_cstring(url);
encoded_url = curl_easy_escape( self, orig_url, strlen(orig_url));
char *orig_url, *encoded_url = NULL;
orig_url = String_to_cstring(url);
encoded_url = curl_easy_escape( self, orig_url, strlen(orig_url));
new body `{ return CURLcallbackTypeBody; `}
new stream `{ return CURLcallbackTypeStream; `}
new read `{ return CURLcallbackTypeRead; `}
new body `{ return CURLcallbackTypeBody; `}
new stream `{ return CURLcallbackTypeStream; `}
new read `{ return CURLcallbackTypeRead; `}
- fun to_i:Int `{ return self; `}
+
+ fun to_i: Int `{ return self; `}
end
# CURL Code binding and helpers
end
# CURL Code binding and helpers
new unsupported_protocol `{ return CURLE_UNSUPPORTED_PROTOCOL; `}
new ok `{ return CURLE_OK; `}
new failed_init `{ return CURLE_FAILED_INIT; `}
new unsupported_protocol `{ return CURLE_UNSUPPORTED_PROTOCOL; `}
new ok `{ return CURLE_OK; `}
new failed_init `{ return CURLE_FAILED_INIT; `}
- fun code:Int `{ return self; `}
- fun is_ok:Bool `{ return self == CURLE_OK; `}
- fun is_valid_protocol:Bool `{ return self == CURLE_UNSUPPORTED_PROTOCOL; `}
- fun is_valid_init:Bool `{ return self == CURLE_FAILED_INIT; `}
- fun to_i:Int do return code end
+
+ fun code: Int `{ return self; `}
+ fun is_ok: Bool `{ return self == CURLE_OK; `}
+ fun is_valid_protocol: Bool `{ return self == CURLE_UNSUPPORTED_PROTOCOL; `}
+ fun is_valid_init: Bool `{ return self == CURLE_FAILED_INIT; `}
+ fun to_i: Int do return code end
redef fun to_s import NativeString.to_s_with_copy `{
char *c = (char*)curl_easy_strerror(self);
return NativeString_to_s_with_copy(c);
redef fun to_s import NativeString.to_s_with_copy `{
char *c = (char*)curl_easy_strerror(self);
return NativeString_to_s_with_copy(c);
extern class CURLSList `{ struct curl_slist * `}
# Empty constructor which allow us to avoid the use of Nit NULLABLE type
private new `{ return NULL; `}
extern class CURLSList `{ struct curl_slist * `}
# Empty constructor which allow us to avoid the use of Nit NULLABLE type
private new `{ return NULL; `}
# Constructor allow us to get list instancied by appending an element inside.
new with_str(s: String) import String.to_cstring `{
struct curl_slist *l = NULL;
l = curl_slist_append(l, String_to_cstring(s));
return l;
`}
# Constructor allow us to get list instancied by appending an element inside.
new with_str(s: String) import String.to_cstring `{
struct curl_slist *l = NULL;
l = curl_slist_append(l, String_to_cstring(s));
return l;
`}
# Check for initialization
# Check for initialization
- fun is_init:Bool `{ return (self != NULL); `}
+ fun is_init: Bool `{ return (self != NULL); `}
+
# Append an element in the linked list
fun append(key: String) import String.to_cstring `{
char *k = String_to_cstring(key);
curl_slist_append(self, (char*)k);
`}
# Append an element in the linked list
fun append(key: String) import String.to_cstring `{
char *k = String_to_cstring(key);
curl_slist_append(self, (char*)k);
`}
# Internal method to check for reachability of current data
# Internal method to check for reachability of current data
- private fun i_data_reachable(c: CURLSList):Bool `{ return (c != NULL && c->data != NULL); `}
+ private fun i_data_reachable(c: CURLSList): Bool `{ return (c != NULL && c->data != NULL); `}
+
# Internal method to check for reachability of next element
# Internal method to check for reachability of next element
- private fun i_next_reachable(c: CURLSList):Bool `{ return (c != NULL && c->next != NULL); `}
+ private fun i_next_reachable(c: CURLSList): Bool `{ return (c != NULL && c->next != NULL); `}
+
# Internal method to get current data
# Internal method to get current data
- private fun i_data(c: CURLSList):String import NativeString.to_s `{ return NativeString_to_s(c->data); `}
+ private fun i_data(c: CURLSList): String import NativeString.to_s `{ return NativeString_to_s(c->data); `}
+
# Internal method to get next element
# Internal method to get next element
- private fun i_next(c: CURLSList):CURLSList `{ return c->next; `}
+ private fun i_next(c: CURLSList): CURLSList `{ return c->next; `}
+
# Convert current low level List to an Array[String] object
# Convert current low level List to an Array[String] object
+ fun to_a: Array[String]
do
var r = new Array[String]
var cursor = self
do
var r = new Array[String]
var cursor = self
# Release allocated memory
fun destroy `{ curl_slist_free_all(self); `}
end
# Release allocated memory
fun destroy `{ curl_slist_free_all(self); `}
end
# Array Response type of CCurl.easy_getinfo method
class CURLInfoResponseArray
# Array Response type of CCurl.easy_getinfo method
class CURLInfoResponseArray
- var response:Array[String] = new Array[String]
- private var prim_response:CURLSList = new CURLSList
+ var response: Array[String] = new Array[String]
+ private var prim_response: CURLSList = new CURLSList
end
# Long Response type of CCurl.easy_getinfo method
class CURLInfoResponseLong
end
# Long Response type of CCurl.easy_getinfo method
class CURLInfoResponseLong
end
# Double Response type of CCurl.easy_getinfo method
class CURLInfoResponseDouble
end
# Double Response type of CCurl.easy_getinfo method
class CURLInfoResponseDouble
-# String Response type of CCurl:easy_getinfo method
+# String Response type of CCurl::easy_getinfo method
class CURLInfoResponseString
class CURLInfoResponseString
- var response:String = ""
end
# Reproduce Enum of available CURL SList information, used for CCurl.easy_getinfo
end
# Reproduce Enum of available CURL SList information, used for CCurl.easy_getinfo
new service_unavailable `{ return 503; `}
new gateway_timeout `{ return 504; `}
new http_version_not_supported `{ return 505; `}
new service_unavailable `{ return 503; `}
new gateway_timeout `{ return 504; `}
new http_version_not_supported `{ return 505; `}
- fun to_i:Int `{ return self; `}
+ fun to_i: Int `{ return self; `}
end
# Reproduce Enum of CURL Options usable, used for CCurl.easy_setopt
end
# Reproduce Enum of CURL Options usable, used for CCurl.easy_setopt
# Display verbose information.
new verbose `{ return CURLOPT_VERBOSE; `}
# Display verbose information.
new verbose `{ return CURLOPT_VERBOSE; `}
# Include the header in the body output.
new header `{ return CURLOPT_HEADER; `}
# Include the header in the body output.
new header `{ return CURLOPT_HEADER; `}
# Shut off the progress meter.
new no_progress `{ return CURLOPT_NOPROGRESS; `}
# Shut off the progress meter.
new no_progress `{ return CURLOPT_NOPROGRESS; `}
# Do not install signal handlers.
new no_signal `{ return CURLOPT_NOSIGNAL; `}
# Do not install signal handlers.
new no_signal `{ return CURLOPT_NOSIGNAL; `}
# Transfer multiple files according to a file name pattern.
new wild_card_match `{ return CURLOPT_WILDCARDMATCH; `}
# Transfer multiple files according to a file name pattern.
new wild_card_match `{ return CURLOPT_WILDCARDMATCH; `}
# Callback for writing data.
new write_function `{ return CURLOPT_WRITEFUNCTION; `}
# Callback for writing data.
new write_function `{ return CURLOPT_WRITEFUNCTION; `}
# Data pointer to pass to the write callback.
new write_data `{ return CURLOPT_WRITEDATA; `}
# Data pointer to pass to the write callback.
new write_data `{ return CURLOPT_WRITEDATA; `}
# Accept-Encoding and automatic decompressing data.
new accept_encoding `{ return CURLOPT_ACCEPT_ENCODING; `}
# Accept-Encoding and automatic decompressing data.
new accept_encoding `{ return CURLOPT_ACCEPT_ENCODING; `}
# Request Transfer-Encoding.
new transfert_encoding `{ return CURLOPT_TRANSFER_ENCODING; `}
# Request Transfer-Encoding.
new transfert_encoding `{ return CURLOPT_TRANSFER_ENCODING; `}
# Follow HTTP redirects.
new follow_location `{ return CURLOPT_FOLLOWLOCATION; `}
# Follow HTTP redirects.
new follow_location `{ return CURLOPT_FOLLOWLOCATION; `}
# Issue a HTTP PUT request.
new put `{ return CURLOPT_PUT; `}
# Issue a HTTP PUT request.
new put `{ return CURLOPT_PUT; `}
# Issue a HTTP POS request.
new post `{ return CURLOPT_POST; `}
# Issue a HTTP POS request.
new post `{ return CURLOPT_POST; `}
# Send a POST with this data.
new postfields `{ return CURLOPT_POSTFIELDS; `}
# Send a POST with this data.
new postfields `{ return CURLOPT_POSTFIELDS; `}
# User-Agent: header.
new user_agent `{ return CURLOPT_USERAGENT; `}
# User-Agent: header.
new user_agent `{ return CURLOPT_USERAGENT; `}
# Custom HTTP headers.
new httpheader `{ return CURLOPT_HTTPHEADER; `}
# Custom HTTP headers.
new httpheader `{ return CURLOPT_HTTPHEADER; `}
# Address of the sender.
new mail_from `{ return CURLOPT_MAIL_FROM; `}
# Address of the sender.
new mail_from `{ return CURLOPT_MAIL_FROM; `}
# Address of the recipients.
new mail_rcpt `{ return CURLOPT_MAIL_RCPT; `}
# Address of the recipients.
new mail_rcpt `{ return CURLOPT_MAIL_RCPT; `}
# List only.
new dir_list_only `{ return CURLOPT_DIRLISTONLY; `}
# List only.
new dir_list_only `{ return CURLOPT_DIRLISTONLY; `}
# Append to remote file.
new append `{ return CURLOPT_APPEND; `}
# Append to remote file.
new append `{ return CURLOPT_APPEND; `}