diff --git a/cURL.ecf b/cURL.ecf index cc834e7a..f0f10ec9 100644 --- a/cURL.ecf +++ b/cURL.ecf @@ -1,6 +1,6 @@ - - + + cURL: libcURL wrapper library for Eiffel. Copyright (c) 1984-2006, Eiffel Software and others. Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt). @@ -23,7 +23,6 @@ - @@ -38,7 +37,7 @@ - + + - diff --git a/curl_easy_externals.e b/curl_easy_externals.e index 85307cb4..11c5daa1 100644 --- a/curl_easy_externals.e +++ b/curl_easy_externals.e @@ -12,18 +12,17 @@ indexing class CURL_EASY_EXTERNALS -feature -- Externals +feature -- Command init: POINTER is -- Declared as curl_easy_init(). - external - "C inline use " - alias - "[ - { - return curl_easy_init(); - } - ]" + local + l_api: POINTER + do + l_api := api_loader.safe_load_api (module_name, "curl_easy_init") + if l_api /= default_pointer then + Result := c_init (l_api) + end ensure exists: Result /= default_pointer end @@ -35,10 +34,14 @@ feature -- Externals valid: (create {CURL_OPT_CONSTANTS}).is_valid (a_opt) not_void: a_string /= Void local + l_api: POINTER l_c_str: C_STRING do - create l_c_str.make (a_string) - c_setopt_string (a_curl_handle, a_opt, l_c_str.item) + l_api := api_loader.safe_load_api (module_name, "curl_easy_setopt") + if l_api /= default_pointer then + create l_c_str.make (a_string) + c_setopt (l_api, a_curl_handle, a_opt, l_c_str.item) + end end setopt_form (a_curl_handle: POINTER; a_opt: INTEGER; a_form: CURL_FORM) is @@ -57,8 +60,13 @@ feature -- Externals exists: a_curl_handle /= default_pointer valid: (create {CURL_OPT_CONSTANTS}).is_valid (a_opt) not_void: a_memory_struct /= Void + local + l_api: POINTER do - c_setopt_void_star (a_curl_handle, a_opt, a_memory_struct.item) + l_api := api_loader.safe_load_api (module_name, "curl_easy_setopt") + if l_api /= default_pointer then + c_setopt (l_api, a_curl_handle, a_opt, a_memory_struct.item) + end end setopt_integer (a_curl_handle: POINTER; a_opt: INTEGER; a_integer: INTEGER) is @@ -66,31 +74,26 @@ feature -- Externals require exists: a_curl_handle /= default_pointer valid: (create {CURL_OPT_CONSTANTS}).is_valid (a_opt) - external - "C inline use " - alias - "[ - { - size_t l_int; - l_int = $a_integer; - - curl_easy_setopt($a_curl_handle, $a_opt, l_int); - } - ]" + local + l_api: POINTER + do + l_api := api_loader.safe_load_api (module_name, "curl_easy_setopt") + if l_api /= default_pointer then + c_setopt_int (l_api, a_curl_handle, a_opt, a_integer) + end end perform (a_curl_handle: POINTER): INTEGER is -- Declared as curl_easy_perform(). require exists: a_curl_handle /= default_pointer - external - "C inline use " - alias - "[ - { - return curl_easy_perform ($a_curl_handle); - } - ]" + local + l_api: POINTER + do + l_api := api_loader.safe_load_api (module_name, "curl_easy_perform") + if l_api /= default_pointer then + Result := c_perform (l_api, a_curl_handle) + end ensure valid: end @@ -99,31 +102,115 @@ feature -- Externals -- Declared as curl_easy_cleanup(). require exists: a_curl_handle /= default_pointer - external - "C inline use " - alias - "[ - { - curl_easy_cleanup($a_curl_handle); - - } - ]" + local + l_api: POINTER + do + l_api := api_loader.safe_load_api (module_name, "curl_easy_cleanup") + if l_api /= default_pointer then + c_cleanup (l_api, a_curl_handle) + end + end + +feature -- Special setting + + set_write_function (a_curl_handle: POINTER) is + -- Set cURL write function + require + exists: a_curl_handle /= default_pointer + local + l_api: POINTER + do + l_api := api_loader.safe_load_api (module_name, "curl_easy_setopt") + if l_api /= default_pointer then + c_set_write_function (l_api, a_curl_handle) + end + end + + set_debug_function (a_curl_handle: POINTER) is + -- Set cURL debug function + require + exists: a_curl_handle /= default_pointer + local + l_api: POINTER + do + l_api := api_loader.safe_load_api (module_name, "curl_easy_setopt") + if l_api /= default_pointer then + c_debug_function (l_api, a_curl_handle) + end end feature {NONE} -- Implementation + api_loader: API_LOADER is + -- API dynamic loader + once + create Result + ensure + not_void: Result /= Void + end + + module_name: STRING is "libcurl.dll" + -- Module name. + setopt_void_star (a_curl_handle: POINTER; a_opt: INTEGER; a_data:POINTER) is -- Declared as curl_easy_setopt(). require exists: a_curl_handle /= default_pointer valid: (create {CURL_OPT_CONSTANTS}).is_valid (a_opt) + local + l_api: POINTER do - c_setopt_void_star (a_curl_handle, a_opt, a_data) + l_api := api_loader.safe_load_api (module_name, "curl_easy_setopt") + if l_api /= default_pointer then + c_setopt (l_api, a_curl_handle, a_opt, a_data) + end end - c_setopt_void_star (a_curl_handle: POINTER; a_opt: INTEGER; a_data:POINTER) is - -- C implementation of `setopt_void_star'. +feature {NONE} -- C externals + + c_init (a_api: POINTER): POINTER is + -- Declared curl_easy_init (). require + exists: a_api /= default_pointer + external + "C inline use " + alias + "[ + return (FUNCTION_CAST(CURL *, ()) $a_api)(); + ]" + end + + c_cleanup (a_api: POINTER; a_curl_handle: POINTER) is + -- Decalred as curl_easy_cleanup (). + require + exists: a_api /= default_pointer + exists: a_curl_handle /= default_pointer + external + "C inline use " + alias + "[ + (FUNCTION_CAST(void, (CURL *)) $a_api)((CURL *)$a_curl_handle); + ]" + end + + c_perform (a_api: POINTER; a_curl_handle: POINTER): INTEGER is + -- Declared as curl_easy_perform(). + require + exists: a_api /= default_pointer + exists: a_curl_handle /= default_pointer + external + "C inline use " + alias + "[ + return (FUNCTION_CAST(CURLcode, (CURL *)) $a_api) + ((CURL *) $a_curl_handle); + ]" + end + + c_setopt_int (a_api: POINTER; a_curl_handle: POINTER; a_opt: INTEGER; a_data: INTEGER) is + -- Same as `c_setopt' except we can pass `a_data' as integer. + require + exists: a_api /= default_pointer exists: a_curl_handle /= default_pointer valid: (create {CURL_OPT_CONSTANTS}).is_valid (a_opt) external @@ -131,23 +218,71 @@ feature {NONE} -- Implementation alias "[ { - curl_easy_setopt($a_curl_handle, $a_opt, (void *)$a_data); + (FUNCTION_CAST(void, (CURL *, CURLoption, CURLoption)) $a_api) + ((CURL *) $a_curl_handle, + (CURLoption)$a_opt, + (CURLoption)$a_data); } ]" end - c_setopt_string (a_curl_handle: POINTER; a_opt: INTEGER; a_c_string: POINTER) is - -- C implementation of `setopt_string'. + c_setopt (a_api: POINTER; a_curl_handle: POINTER; a_opt: INTEGER; a_data:POINTER) is + -- C implementation of `setopt_void_star'. + -- Declared as curl_easy_setopt (). require + exists: a_api /= default_pointer exists: a_curl_handle /= default_pointer valid: (create {CURL_OPT_CONSTANTS}).is_valid (a_opt) - exists: a_c_string /= default_pointer external "C inline use " alias "[ { - curl_easy_setopt($a_curl_handle, $a_opt, (char *)$a_c_string); + (FUNCTION_CAST(void, (CURL *, CURLoption, CURLoption)) $a_api) + ((CURL *) $a_curl_handle, + (CURLoption)$a_opt, + (CURLoption)$a_data); + } + ]" + end + + c_set_write_function (a_setopt_api: POINTER; a_curl_handle: POINTER) is + -- Setting CURLOPT_WRITEFUNCTION option of `a_curl_handle'. + -- We need this function since cURL need a static c function pointer as value. + require + exists: a_setopt_api /= default_pointer + external + "C inline use " + alias + "[ + { + (FUNCTION_CAST(void, (CURL *, CURLoption, CURLoption)) $a_setopt_api) + ((CURL *) $a_curl_handle, + (CURLoption)CURLOPT_WRITEFUNCTION, + (CURLoption)WriteMemoryCallback); + } + ]" + end + + c_debug_function (a_setopt_api: POINTER; a_curl_handle: POINTER) is + -- Setting CURLOPT_DEBUGFUNCTION option of `a_curl_handle'. + -- We need this function since cURL need a static c function pointer as value. + require + exists: a_curl_handle /= default_pointer + external + "C inline use " + alias + "[ + { + (FUNCTION_CAST(void, (CURL *, CURLoption, CURLoption)) $a_setopt_api) + ((CURL *) $a_curl_handle, + (CURLoption)CURLOPT_DEBUGFUNCTION, + (CURLoption)curl_trace); + + (FUNCTION_CAST(void, (CURL *, CURLoption, CURLoption)) $a_setopt_api) + ((CURL *) $a_curl_handle, + (CURLoption)CURLOPT_VERBOSE, + (CURLoption)TRUE); } ]" end diff --git a/curl_externals.e b/curl_externals.e index f3a7558d..912e2175 100644 --- a/curl_externals.e +++ b/curl_externals.e @@ -12,18 +12,17 @@ indexing class CURL_EXTERNALS -feature -- Externals +feature -- Command global_init is -- Declared as curl_global_init(). - external - "C inline use " - alias - "[ - { - curl_global_init (CURL_GLOBAL_ALL); - } - ]" + local + l_ptr: POINTER + do + l_ptr := api_loader.safe_load_api (module_name, "curl_global_init") + if l_ptr /= default_pointer then + c_curl_global_init (l_ptr, {CURL_GLOBAL_CONSTANTS}.curl_global_all); + end end formadd_string_string (a_form: CURL_FORM; a_last_pointer: CURL_FORM; a_arg_1: INTEGER; a_arg_1_value: STRING_GENERAL; a_arg_2: INTEGER; a_arg_2_value: STRING_GENERAL; a_arg_3: INTEGER) is @@ -53,35 +52,12 @@ feature -- Externals end end - set_write_function (a_curl_handle: POINTER) is - -- Setting CURLOPT_WRITEFUNCTION option of `a_curl_handle'. - -- We need this function since cURL need a static c function pointer as value. - require - exists: a_curl_handle /= default_pointer - external - "C inline use " - alias - "[ - { - curl_easy_setopt ($a_curl_handle, CURLOPT_WRITEFUNCTION, WriteMemoryCallback); - } - ]" - end +feature -- Query - set_debug_function (a_curl_handle: POINTER) is - -- Setting CURLOPT_DEBUGFUNCTION option of `a_curl_handle'. - -- We need this function since cURL need a static c function pointer as value. - require - exists: a_curl_handle /= default_pointer - external - "C inline use " - alias - "[ - { - curl_easy_setopt($a_curl_handle, CURLOPT_DEBUGFUNCTION, my_trace); - curl_easy_setopt($a_curl_handle, CURLOPT_VERBOSE, TRUE); - } - ]" + is_dynamic_library_exists: BOOLEAN is + -- If dll/so files exist? + do + Result := (api_loader.module_pointer (module_name) /= default_pointer) end feature {CURL_FORM} -- Internal command @@ -90,48 +66,104 @@ feature {CURL_FORM} -- Internal command -- Declared as curl_formfree (). require exists: a_curl_form /= default_pointer - external - "C inline use " - alias - "[ - { - curl_formfree($a_curl_form); - } - ]" + local + l_api: POINTER + do + l_api := api_loader.safe_load_api (module_name, "curl_formfree") + if l_api /= default_pointer then + c_formfree (l_api, a_curl_form) + end end feature {NONE} -- Implementation - c_slist_append (a_list_pointer: POINTER; a_string: POINTER): POINTER is - -- Declared as curl_slist_append (). - external - "C inline use " - alias - "[ - { - return curl_slist_append ((struct curl_slist *)$a_list_pointer, (char *)$a_string); - } - ]" + api_loader: API_LOADER is + -- API dynamic loader + once + create Result + ensure + not_void: Result /= Void end + module_name: STRING is "libcurl.dll" + -- Module name. + internal_formadd_string_string (a_form: TYPED_POINTER [POINTER]; a_last_pointer: TYPED_POINTER [POINTER]; a_arg_1: INTEGER; a_arg_1_value: STRING_GENERAL; a_arg_2: INTEGER; a_arg_2_value: STRING_GENERAL; a_arg_3: INTEGER) is -- Declared as curl_formadd (). local l_c_string_1, l_c_string_2: C_STRING + l_api: POINTER do - create l_c_string_1.make (a_arg_1_value) - create l_c_string_2.make (a_arg_2_value) - c_formadd_string_string (a_form, a_last_pointer, a_arg_1, l_c_string_1.item, a_arg_2, l_c_string_2.item, a_arg_3) + l_api := api_loader.safe_load_api (module_name, "curl_formadd"); + if l_api /= default_pointer then + create l_c_string_1.make (a_arg_1_value) + create l_c_string_2.make (a_arg_2_value) + c_formadd_string_string (l_api, a_form, a_last_pointer, a_arg_1, l_c_string_1.item, a_arg_2, l_c_string_2.item, a_arg_3) + end end - c_formadd_string_string (a_form: TYPED_POINTER [POINTER]; a_last_pointer: TYPED_POINTER [POINTER]; a_arg_1: INTEGER; a_arg_1_value: POINTER; a_arg_2: INTEGER; a_arg_2_value: POINTER; a_arg_3: INTEGER) is +feature {NONE} -- C externals + + c_formadd_string_string (a_api: POINTER; a_form: TYPED_POINTER [POINTER]; a_last_pointer: TYPED_POINTER [POINTER]; a_arg_1: INTEGER; a_arg_1_value: POINTER; a_arg_2: INTEGER; a_arg_2_value: POINTER; a_arg_3: INTEGER) is -- C implementation of formadd_string_string (). + require + exists: a_api /= default_pointer external "C inline use " alias "[ { - curl_formadd ((struct curl_httppost *)$a_form, (struct curl_httppost *)$a_last_pointer, (int)$a_arg_1, (char *)$a_arg_1_value, (int)$a_arg_2, (char *)$a_arg_2_value, (int)$a_arg_3); + (FUNCTION_CAST(void, (struct curl_httppost **, struct curl_httppost **, int, char *, int, char *, int)) $a_api) + ((struct curl_httppost *)$a_form, + (struct curl_httppost *)$a_last_pointer, + (int)$a_arg_1, + (char *)$a_arg_1_value, + (int)$a_arg_2, + (char *)$a_arg_2_value, + (int)$a_arg_3); + } + ]" + end + + c_formfree (a_api: POINTER; a_curl_form: POINTER) is + -- Declared as curl_formfree (). + require + exists: a_api /= default_pointer + exists: a_curl_form /= default_pointer + external + "C inline use " + alias + "[ + (FUNCTION_CAST(void, (struct curl_httppost *)) $a_api) + ((struct curl_httppost *) $a_curl_form); + ]" + end + + c_curl_global_init (a_api: POINTER; a_opt: NATURAL_64) is + -- `a_api' point to AIP curl_global_init () + -- `a_opt' is intialization option. + require + exists: a_api /= default_pointer + external + "C inline use " + alias + "[ + (FUNCTION_CAST(void, (long)) $a_api)((long) $a_opt); + ]" + end + + c_slist_append (a_api: POINTER; a_list_pointer: POINTER; a_string: POINTER): POINTER is + -- Declared as curl_slist_append (). + require + exists: a_api /= default_pointer + external + "C inline use " + alias + "[ + { + return (FUNCTION_CAST(void *, (struct curl_slist *, const char *)) $a_api) + ((struct curl_slist *)$a_list_pointer, + (const char *)$a_string); } ]" end diff --git a/curl_global_constants.e b/curl_global_constants.e new file mode 100644 index 00000000..da466828 --- /dev/null +++ b/curl_global_constants.e @@ -0,0 +1,78 @@ +indexing + description: "[ + cURL library constants used by curl_global_init () + ]" + status: "See notice at end of class." + legal: "See notice at end of class." + date: "$Date$" + revision: "$Revision$" + +class + CURL_GLOBAL_CONSTANTS + +feature -- Query + + curl_global_ssl: NATURAL_64 is + -- Delcared as CURL_GLOBAL_SSL + external + "C inline use " + alias + "[ + return CURL_GLOBAL_SSL; + ]" + end + + curl_global_win32: NATURAL_64 is + -- Delcared as CURL_GLOBAL_WIN32 + external + "C inline use " + alias + "[ + return CURL_GLOBAL_WIN32; + ]" + end + + curl_global_all: NATURAL_64 is + -- Delcared as CURL_GLOBAL_ALL + external + "C inline use " + alias + "[ + return CURL_GLOBAL_ALL; + ]" + end + + curl_global_nothing: NATURAL_64 is + -- Delcared as CURL_GLOBAL_NOTHING + external + "C inline use " + alias + "[ + return CURL_GLOBAL_NOTHING; + ]" + end + + curl_global_default: NATURAL_64 is + -- Delcared as CURL_GLOBAL_DEFAULT + external + "C inline use " + alias + "[ + return CURL_GLOBAL_DEFAULT; + ]" + end + +indexing + library: "cURL: Library of reusable components for Eiffel." + copyright: "Copyright (c) 1984-2006, Eiffel Software and others" + license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" + source: "[ + Eiffel Software + 356 Storke Road, Goleta, CA 93117 USA + Telephone 805-685-1006, Fax 805-685-6869 + Website http://www.eiffel.com + Customer support http://support.eiffel.com + ]" + +end + diff --git a/spec/include/eiffel_curl.h b/spec/include/eiffel_curl.h index e803f0d2..69161def 100644 --- a/spec/include/eiffel_curl.h +++ b/spec/include/eiffel_curl.h @@ -65,7 +65,7 @@ static void dump(const char *text, FILE *stream, unsigned char *ptr, size_t size fflush(stream); } -static int my_trace(CURL *handle, curl_infotype type, unsigned char *data, size_t size, void *userp) +static int curl_trace(CURL *handle, curl_infotype type, unsigned char *data, size_t size, void *userp) { const char *text;