Skip to content

Commit 241d020

Browse files
committed
Expose libpq's OAuth hooks
Async is not supported yet,
1 parent 87e9c71 commit 241d020

File tree

6 files changed

+496
-1
lines changed

6 files changed

+496
-1
lines changed

ext/extconf.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ module PG
316316
src + " int con(){ return PGRES_PIPELINE_SYNC; }"
317317
end
318318
have_func 'PQsetChunkedRowsMode', 'libpq-fe.h' # since PostgreSQL-17
319+
have_func 'PQsetAuthDataHook', 'libpq-fe.h' # since PostgreSQL-18
319320
have_func 'timegm'
320321
have_func 'rb_io_wait' # since ruby-3.0
321322
have_func 'rb_io_descriptor' # since ruby-3.1

ext/gvl_wrappers.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,17 +281,34 @@ FOR_EACH_BLOCKING_FUNCTION( DEFINE_GVL_STUB_DECL );
281281
* Definitions of callback functions and their parameters
282282
*/
283283

284+
#define FOR_EACH_PARAM_OF_auth_data_hook_proxy(param) \
285+
param(PGauthData, type) \
286+
param(PGconn *, conn)
287+
284288
#define FOR_EACH_PARAM_OF_notice_processor_proxy(param) \
285289
param(void *, arg)
286290

287291
#define FOR_EACH_PARAM_OF_notice_receiver_proxy(param) \
288292
param(void *, arg)
289293

294+
#ifdef HAVE_PQSETAUTHDATAHOOK
295+
290296
/* function( name, void_or_nonvoid, returntype, lastparamtype, lastparamname ) */
291297
#define FOR_EACH_CALLBACK_FUNCTION(function) \
298+
function(auth_data_hook_proxy, GVL_TYPE_NONVOID, int, void *, data) \
292299
function(notice_processor_proxy, GVL_TYPE_VOID, void, const char *, message) \
293300
function(notice_receiver_proxy, GVL_TYPE_VOID, void, const PGresult *, result) \
294301

302+
#else
303+
304+
/* function( name, void_or_nonvoid, returntype, lastparamtype, lastparamname ) */
305+
#define FOR_EACH_CALLBACK_FUNCTION(function) \
306+
function(notice_processor_proxy, GVL_TYPE_VOID, void, const char *, message) \
307+
function(notice_receiver_proxy, GVL_TYPE_VOID, void, const PGresult *, result) \
308+
309+
#endif
310+
295311
FOR_EACH_CALLBACK_FUNCTION( DEFINE_GVL_STUB_DECL );
296312

313+
297314
#endif /* end __gvl_wrappers_h */

ext/pg.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,7 @@ Init_pg_ext(void)
682682

683683
/* Initialize the main extension classes */
684684
init_pg_connection();
685+
init_pg_auth_hooks();
685686
init_pg_result();
686687
init_pg_errors();
687688
init_pg_type_map();

ext/pg.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ extern VALUE pg_typemap_all_strings;
289289
void Init_pg_ext _(( void ));
290290

291291
void init_pg_connection _(( void ));
292+
void init_pg_auth_hooks _(( void ));
292293
void init_pg_result _(( void ));
293294
void init_pg_errors _(( void ));
294295
void init_pg_type_map _(( void ));
@@ -375,6 +376,9 @@ rb_encoding * pg_get_pg_encname_as_rb_encoding _(( const char * ));
375376
const char * pg_get_rb_encoding_as_pg_encoding _(( rb_encoding * ));
376377
rb_encoding *pg_conn_enc_get _(( PGconn * ));
377378

379+
#ifdef HAVE_PQSETAUTHDATAHOOK
380+
int auth_data_hook_proxy(PGauthData type, PGconn *conn, void *data);
381+
#endif
378382
void notice_receiver_proxy(void *arg, const PGresult *result);
379383
void notice_processor_proxy(void *arg, const char *message);
380384

0 commit comments

Comments
 (0)