From dae6d64f8219193a384f2eea652995681cfa8ece Mon Sep 17 00:00:00 2001 From: jfiat Date: Thu, 19 Mar 2009 08:18:02 +0000 Subject: [PATCH] Added curl_easy_getinfo. Associated constants and also CURLOPT_USERPWD. Minor optimization and cosmetics. git-svn-id: https://svn.origo.ethz.ch/eiffelstudio/trunk/Src/library/cURL@77794 8089f293-4706-0410-a29e-feb5c42a2edf --- curl_easy_externals.e | 67 ++++++++++++++++++++++- curl_info_constants.e | 122 ++++++++++++++++++++++++++++++++++++++++++ curl_info_type.e | 21 +++++--- curl_opt_constants.e | 10 ++++ 4 files changed, 212 insertions(+), 8 deletions(-) create mode 100644 curl_info_constants.e diff --git a/curl_easy_externals.e b/curl_easy_externals.e index ea16da24..6245b219 100644 --- a/curl_easy_externals.e +++ b/curl_easy_externals.e @@ -100,7 +100,7 @@ feature -- Command require exists: a_curl_handle /= default_pointer valid: a_opt = {CURL_OPT_CONSTANTS}.curlopt_readdata - readable: a_file /= void and then a_file.file_readable + readable: a_file /= Void and then a_file.file_readable do setopt_void_star (a_curl_handle, a_opt, a_file.file_pointer) end @@ -136,6 +136,53 @@ feature -- Command feature -- Query + getinfo (a_curl_handle: POINTER; a_info: INTEGER; a_data: CELL [detachable ANY]): INTEGER + -- `curl_getinfo + --|* Request internal information from the curl session with this function. The + --|* third argument MUST be a pointer to a long, a pointer to a char * or a + --|* pointer to a double (as the documentation describes elsewhere). The data + --|* pointed to will be filled in accordingly and can be relied upon only if the + --|* function returns CURLE_OK. This function is intended to get used *AFTER* a + --|* performed transfer, all results from this function are undefined until the + --|* transfer is completed. + require + exists: a_curl_handle /= default_pointer + valid: (create {CURL_INFO_CONSTANTS}).is_valid (a_info) + local + l_api: POINTER + mp: detachable MANAGED_POINTER + l: INTEGER + cs: C_STRING + d: REAL_64 + do + a_data.replace (Void) + l_api := api_loader.safe_load_api (module_name, "curl_easy_getinfo") + if l_api /= default_pointer then + if a_info & {CURL_INFO_CONSTANTS}.curlinfo_long /= 0 then + create mp.make ({PLATFORM}.integer_32_bytes) + elseif a_info & {CURL_INFO_CONSTANTS}.curlinfo_string /= 0 then + create mp.make ({PLATFORM}.pointer_bytes) + elseif a_info & {CURL_INFO_CONSTANTS}.curlinfo_double /= 0 then + create mp.make ({PLATFORM}.real_64_bytes) + end + if mp /= Void then + Result := c_getinfo (l_api, a_curl_handle, a_info, mp.item) + if Result = {CURL_CODES}.curle_ok then + if a_info & {CURL_INFO_CONSTANTS}.curlinfo_long /= 0 then + l := mp.read_integer_32 (0) + a_data.put (l) + elseif a_info & {CURL_INFO_CONSTANTS}.curlinfo_string /= 0 then + create cs.make_shared_from_pointer (mp.read_pointer (0)) + a_data.put (cs.string) + elseif a_info & {CURL_INFO_CONSTANTS}.curlinfo_double /= 0 then + d := mp.read_real_64 (0) + a_data.put (d) + end + end + end + end + end + is_dynamic_library_exists: BOOLEAN -- If dll/so files exist? do @@ -337,6 +384,24 @@ feature {NONE} -- C externals ]" end + c_getinfo (a_api: POINTER; a_curl_handle: POINTER; a_opt: INTEGER; a_data: POINTER): INTEGER + -- C implementation of `curl_easy_getinfo'. + -- 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) + external + "C inline use " + alias + "[ + return (FUNCTION_CAST(CURLcode, (CURL *, CURLINFO info, ...)) $a_api) + ((CURL *) $a_curl_handle, + (CURLINFO)$a_opt, + $a_data); + ]" + end + note library: "cURL: Library of reusable components for Eiffel." copyright: "Copyright (c) 1984-2006, Eiffel Software and others" diff --git a/curl_info_constants.e b/curl_info_constants.e new file mode 100644 index 00000000..c8dfd480 --- /dev/null +++ b/curl_info_constants.e @@ -0,0 +1,122 @@ +note + description: "[ + cURL library info constants. + ]" + status: "See notice at end of class." + legal: "See notice at end of class." + date: "$Date$" + revision: "$Revision$" + +class + CURL_INFO_CONSTANTS + +feature -- Constants + + curlinfo_string: INTEGER = 0x100000 + -- Declared as CURLINFO_STRING + + curlinfo_long: INTEGER = 0x200000 + -- Declared as CURLINFO_LONG + + curlinfo_double: INTEGER = 0x300000 + -- Declared as CURLINFO_DOUBLE + + curlinfo_slist: INTEGER = 0x400000 + -- Declared as CURLINFO_SLIST + + curlinfo_mask: INTEGER = 0x0fffff + -- Declared as CURLINFO_MASK + + curlinfo_typemask: INTEGER = 0xf00000 + -- Declared as CURLINFO_TYPEMASK + +feature -- Info constants + + curlinfo_effective_url: INTEGER = 0x100001 -- CURLINFO_STRING + 1, + curlinfo_response_code: INTEGER = 0x200002 -- CURLINFO_LONG + 2, + curlinfo_total_time: INTEGER = 0x300003 -- CURLINFO_DOUBLE + 3, + curlinfo_namelookup_time: INTEGER = 0x300004 -- CURLINFO_DOUBLE + 4, + curlinfo_connect_time: INTEGER = 0x300005 -- CURLINFO_DOUBLE + 5, + curlinfo_pretransfer_time: INTEGER = 0x300006 -- CURLINFO_DOUBLE + 6, + curlinfo_size_upload: INTEGER = 0x300007 -- CURLINFO_DOUBLE + 7, + curlinfo_size_download: INTEGER = 0x300008 -- CURLINFO_DOUBLE + 8, + curlinfo_speed_download: INTEGER = 0x300009 -- CURLINFO_DOUBLE + 9, + curlinfo_speed_upload: INTEGER = 0x30000a -- CURLINFO_DOUBLE + 10, + curlinfo_header_size: INTEGER = 0x20000b -- CURLINFO_LONG + 11, + curlinfo_request_size: INTEGER = 0x20000c -- CURLINFO_LONG + 12, + curlinfo_ssl_verifyresult: INTEGER = 0x20000d -- CURLINFO_LONG + 13, + curlinfo_filetime: INTEGER = 0x20000e -- CURLINFO_LONG + 14, + curlinfo_content_length_download: INTEGER = 0x30000f -- CURLINFO_DOUBLE + 15, + curlinfo_content_length_upload: INTEGER = 0x300010 -- CURLINFO_DOUBLE + 16, + curlinfo_starttransfer_time: INTEGER = 0x300011 -- CURLINFO_DOUBLE + 17, + curlinfo_content_type: INTEGER = 0x100012 -- CURLINFO_STRING + 18, + curlinfo_redirect_time: INTEGER = 0x300013 -- CURLINFO_DOUBLE + 19, + curlinfo_redirect_count: INTEGER = 0x200014 -- CURLINFO_LONG + 20, + curlinfo_private: INTEGER = 0x100015 -- CURLINFO_STRING + 21, + curlinfo_http_connectcode: INTEGER = 0x200016 -- CURLINFO_LONG + 22, + curlinfo_httpauth_avail: INTEGER = 0x200017 -- CURLINFO_LONG + 23, + curlinfo_proxyauth_avail: INTEGER = 0x200018 -- CURLINFO_LONG + 24, + curlinfo_os_errno: INTEGER = 0x200019 -- CURLINFO_LONG + 25, + curlinfo_num_connects: INTEGER = 0x20001a -- CURLINFO_LONG + 26, + curlinfo_ssl_engines: INTEGER = 0x40001b -- CURLINFO_SLIST + 27, + curlinfo_cookielist: INTEGER = 0x40001c -- CURLINFO_SLIST + 28, + curlinfo_lastsocket: INTEGER = 0x20001d -- CURLINFO_LONG + 29, + curlinfo_ftp_entry_path: INTEGER = 0x10001e -- CURLINFO_STRING + 30, + +feature -- Contract support + + is_valid (a_code: INTEGER): BOOLEAN + -- Is `a_code' valid? + do + inspect a_code + when + curlinfo_effective_url, + curlinfo_response_code, + curlinfo_total_time, + curlinfo_namelookup_time, + curlinfo_connect_time, + curlinfo_pretransfer_time, + curlinfo_size_upload, + curlinfo_size_download, + curlinfo_speed_download, + curlinfo_speed_upload, + curlinfo_header_size, + curlinfo_request_size, + curlinfo_ssl_verifyresult, + curlinfo_filetime, + curlinfo_content_length_download, + curlinfo_content_length_upload, + curlinfo_starttransfer_time, + curlinfo_content_type, + curlinfo_redirect_time, + curlinfo_redirect_count, + curlinfo_private, + curlinfo_http_connectcode, + curlinfo_httpauth_avail, + curlinfo_proxyauth_avail, + curlinfo_os_errno, + curlinfo_num_connects, + curlinfo_ssl_engines, + curlinfo_cookielist, + curlinfo_lastsocket, + curlinfo_ftp_entry_path + then + Result := True + else + Result := False + end + end + +note + 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/curl_info_type.e b/curl_info_type.e index a3c9cb39..7137e97e 100644 --- a/curl_info_type.e +++ b/curl_info_type.e @@ -38,13 +38,20 @@ feature -- Contract support is_valid (a_type: INTEGER): BOOLEAN -- If `a_type' valid? do - Result := a_type = curlinfo_data_in or - a_type = curlinfo_data_out or - a_type = curlinfo_header_in or - a_type = curlinfo_header_out or - a_type = curlinfo_ssl_data_in or - a_type = curlinfo_ssl_data_out or - a_type = curlinfo_text + inspect a_type + when + curlinfo_data_in, + curlinfo_data_out, + curlinfo_header_in, + curlinfo_header_out, + curlinfo_ssl_data_in, + curlinfo_ssl_data_out, + curlinfo_text + then + Result := True + else + Result := False + end end note diff --git a/curl_opt_constants.e b/curl_opt_constants.e index 5fa9fee1..128d75da 100644 --- a/curl_opt_constants.e +++ b/curl_opt_constants.e @@ -84,6 +84,16 @@ feature -- Enumerations. ]" end + curlopt_userpwd: INTEGER + -- Declared as CURLOPT_USERPWD. + external + "C inline use " + alias + "[ + return CURLOPT_USERPWD; + ]" + end + curlopt_url: INTEGER -- Declared as CURLOPT_URL. external