tests.sh: soso are always detected as failed tests
[nit.git] / lib / curl / curl_c.nit
index 7dadbd5..b670cbe 100644 (file)
@@ -15,9 +15,7 @@
 # limitations under the License.
 
 # Binding of C libCurl which allow us to interact with network.
-module curl_c
-
-import pipeline
+module curl_c is pkgconfig("libcurl")
 
 in "C header" `{
        #include <stdio.h>
@@ -74,7 +72,7 @@ in "C body" `{
 `}
 
 # 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
@@ -194,7 +192,7 @@ extern CCurl `{ CURL * `}
                return curl_easy_setopt( recv, CURLOPT_READDATA, d);
        `}
        # 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    `{
+       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 `{
                CURLCallbackDatas *d = malloc(sizeof(CURLCallbackDatas));
                CCurlCallbacks_incr_ref(delegate);
                d->type = cbtype;
@@ -202,18 +200,18 @@ extern CCurl `{ CURL * `}
                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;
                }
@@ -231,7 +229,7 @@ extern CCurl `{ CURL * `}
 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
@@ -262,7 +260,7 @@ interface CCurlCallbacks
 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; `}
@@ -271,7 +269,7 @@ extern CURLCallbackType `{ CURLcallbackType `}
 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; `}
@@ -288,7 +286,7 @@ extern CURLCode `{ CURLcode `}
 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.
@@ -309,7 +307,7 @@ extern CURLSList `{ struct curl_slist * `}
        # Internal method to check for reachability of next element
        private fun i_next_reachable(c: CURLSList):Bool `{ return (c != NULL && c->next != NULL); `}
        # Internal method to get current data
-       private fun i_data(c: CURLSList):String `{ 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
        private fun i_next(c: CURLSList):CURLSList `{ return c->next; `}
        # Convert current low level List to an Array[String] object
@@ -336,7 +334,11 @@ redef class Collection[E]
                        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
@@ -363,13 +365,13 @@ class CURLInfoResponseString
 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; `}
@@ -391,7 +393,7 @@ extern CURLInfoLong `{ CURLINFO `}
 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; `}
@@ -408,7 +410,7 @@ extern CURLInfoDouble `{ CURLINFO `}
 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; `}
@@ -420,7 +422,7 @@ extern CURLInfoChars `{ CURLINFO `}
 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; `}
@@ -462,7 +464,7 @@ extern CURLStatusCode `{ int `}
 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; `}
@@ -481,7 +483,7 @@ extern CURLOption `{ CURLoption `}
        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; `}