Skip to content

Commit 9335200

Browse files
ligurioTotktonada
authored andcommitted
client: add a field with Curl version
``` tarantool> require("smtp")._CURL_VERSION --- - 7.81.0 ... ``` Needed for #70
1 parent 8ff93f1 commit 9335200

File tree

4 files changed

+36
-1
lines changed

4 files changed

+36
-1
lines changed

smtp/init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ curl_mt = {
277277
--
278278
-- Export
279279
--
280-
local this_module = { new = smtp_new, }
280+
local this_module = { new = smtp_new, _CURL_VERSION = driver._CURL_VERSION }
281281

282282
package.loaded['smtp.client'] = this_module
283283
return this_module

smtp/lib.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,15 @@ luaT_smtpc_cleanup(lua_State *L)
255255
return 2;
256256
}
257257

258+
static int
259+
luaT_smtpc_version(lua_State *L)
260+
{
261+
unsigned int major, minor, patch;
262+
smtpc_get_curl_version(&major, &minor, &patch);
263+
lua_pushfstring(L, "%u.%u.%u", major, minor, patch);
264+
return 1;
265+
}
266+
258267
/*
259268
* }}}
260269
*/
@@ -292,6 +301,11 @@ luaopen_smtp_lib(lua_State *L)
292301
luaL_register(L, NULL, Client);
293302
lua_pop(L, 1);
294303
luaL_register(L, "smtp.client.driver", Module);
304+
305+
lua_pushliteral(L, "_CURL_VERSION");
306+
luaT_smtpc_version(L);
307+
lua_rawset(L, -3);
308+
295309
return 1;
296310
}
297311

smtp/smtpc.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,15 @@ bind_libcurl_functions(const char *libname, void *libcurl_handle)
150150

151151
#undef load_func
152152

153+
void
154+
smtpc_get_curl_version(unsigned int *major, unsigned int *minor, unsigned int *patch)
155+
{
156+
curl_version_info_data *info = curl_version_info(CURLVERSION_NOW);
157+
*major = (info->version_num >> 16) & 0xff;
158+
*minor = (info->version_num >> 8) & 0xff;
159+
*patch = info->version_num & 0xff;
160+
}
161+
153162
int
154163
smtpc_init(void)
155164
{

smtp/smtpc.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,4 +271,16 @@ smtpc_execute(struct smtpc_request *req, double timeout);
271271

272272
/** Request }}} */
273273

274+
/* {{{ Version */
275+
276+
/**
277+
* Get a Curl library version.
278+
*
279+
* @see https://curl.se/libcurl/c/curl_version_info.html
280+
*/
281+
void
282+
smtpc_get_curl_version(unsigned int *major, unsigned int *minor, unsigned int *patch);
283+
284+
/* Version }}} */
285+
274286
#endif /* TARANTOOL_SMTPC_H_INCLUDED */

0 commit comments

Comments
 (0)