# Binding of C libCurl which allow us to interact with network.
module curl_c is pkgconfig("libcurl")
-import pipeline
-
in "C header" `{
#include <stdio.h>
#include <stdlib.h>
`}
# CURL Extern Type, reproduce CURL low level behaviors
-extern CCurl `{ CURL * `}
+extern class CCurl `{ CURL * `}
# Constructor, CURL low level initializer
new easy_init `{ return curl_easy_init(); `}
# Check for correct initialization
CURLcode e;
switch(cbtype){
case CURLcallbackTypeHeader:
- e = curl_easy_setopt( recv, CURLOPT_HEADERFUNCTION, &nit_curl_callback_func);
+ e = curl_easy_setopt( recv, CURLOPT_HEADERFUNCTION, (curl_write_callback)&nit_curl_callback_func);
if(e != CURLE_OK) return e;
e = curl_easy_setopt( recv, CURLOPT_WRITEHEADER, d);
break;
case CURLcallbackTypeBody:
case CURLcallbackTypeStream:
- e = curl_easy_setopt( recv, CURLOPT_WRITEFUNCTION, &nit_curl_callback_func);
+ e = curl_easy_setopt( recv, CURLOPT_WRITEFUNCTION, (curl_write_callback)&nit_curl_callback_func);
if(e != CURLE_OK) return e;
e = curl_easy_setopt( recv, CURLOPT_WRITEDATA, d);
break;
case CURLcallbackTypeRead:
- e = curl_easy_setopt( recv, CURLOPT_READFUNCTION, &nit_curl_callback_read_func);
+ e = curl_easy_setopt( recv, CURLOPT_READFUNCTION, (curl_write_callback)&nit_curl_callback_read_func);
default:
break;
}
end
# FILE Extern type, reproduce basic FILE I/O
-extern OFile `{ FILE* `}
+extern class OFile `{ FILE* `}
# Open / Create a file from given name
new open(str: NativeString) `{ return fopen(str, "wb"); `}
# Check for File validity
end
# Extern Type to reproduce Enum of available Callback type
-extern CURLCallbackType `{ CURLcallbackType `}
+extern class CURLCallbackType `{ CURLcallbackType `}
new header `{ return CURLcallbackTypeHeader; `}
new body `{ return CURLcallbackTypeBody; `}
new stream `{ return CURLcallbackTypeStream; `}
end
# CURL Code binding and helpers
-extern CURLCode `{ CURLcode `}
+extern class CURLCode `{ CURLcode `}
new unknown_option `{ return CURLE_UNKNOWN_OPTION; `}
new unsupported_protocol `{ return CURLE_UNSUPPORTED_PROTOCOL; `}
new ok `{ return CURLE_OK; `}
end
# Extern Type of the Linked list type of CURL
-extern CURLSList `{ struct curl_slist * `}
+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.
print "Collection item must be strings."
end
var primList = new CURLSList.with_str(self.first)
- for s in self.skip_head(1) do primList.append(s)
+ var is_first = true
+ for s in self do
+ if not is_first then primList.append(s)
+ is_first = false
+ end
return primList
end
end
end
# Reproduce Enum of available CURL SList information, used for CCurl.easy_getinfo
-extern CURLInfoSList `{ CURLINFO `}
+extern class CURLInfoSList `{ CURLINFO `}
new ssl_engines `{ return CURLINFO_SSL_ENGINES; `}
new cookielist `{ return CURLINFO_COOKIELIST; `}
end
# Reproduce Enum of available CURL Long information, used for CCurl.easy_getinfo
-extern CURLInfoLong `{ CURLINFO `}
+extern class CURLInfoLong `{ CURLINFO `}
new response_code `{ return CURLINFO_RESPONSE_CODE; `}
new header_size `{ return CURLINFO_HEADER_SIZE; `}
new http_connectcode `{ return CURLINFO_HTTP_CONNECTCODE; `}
end
# Reproduce Enum of available CURL Double information, used for CCurl.easy_getinfo
-extern CURLInfoDouble `{ CURLINFO `}
+extern class CURLInfoDouble `{ CURLINFO `}
new total_time `{ return CURLINFO_TOTAL_TIME; `}
new namelookup_time `{ return CURLINFO_NAMELOOKUP_TIME; `}
new connect_time `{ return CURLINFO_CONNECT_TIME; `}
end
# Reproduce Enum of available CURL Chars information, used for CCurl.easy_getinfo
-extern CURLInfoChars `{ CURLINFO `}
+extern class CURLInfoChars `{ CURLINFO `}
new content_type `{ return CURLINFO_CONTENT_TYPE; `}
new effective_url `{ return CURLINFO_EFFECTIVE_URL; `}
new redirect_url `{ return CURLINFO_REDIRECT_URL; `}
end
# Reproduce Enum of HTTP Status Code
-extern CURLStatusCode `{ int `}
+extern class CURLStatusCode `{ int `}
new proceed `{ return 100; `}
new switching_protocols `{ return 101; `}
new ok `{ return 200; `}
end
# Reproduce Enum of CURL Options usable, used for CCurl.easy_setopt
-extern CURLOption `{ CURLoption `}
+extern class CURLOption `{ CURLoption `}
new write_function `{ return CURLOPT_WRITEFUNCTION; `}
new write_data `{ return CURLOPT_WRITEDATA; `}
# new `{ return CURLOPT_FILE; `}
new postfields `{ return CURLOPT_POSTFIELDS; `}
# new `{ return CURLOPT_REFERER; `}
# new `{ return CURLOPT_FTPPORT; `}
-# new `{ return CURLOPT_USERAGENT; `}
+ new user_agent `{ return CURLOPT_USERAGENT; `}
# new `{ return CURLOPT_LOW_SPEED_LIMIT; `}
# new `{ return CURLOPT_LOW_SPEED_TIME; `}
# new `{ return CURLOPT_RESUME_FROM; `}