PostgreSQL Source Code: src/interfaces/libpq/libpq-int.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20#ifndef LIBPQ_INT_H

21#define LIBPQ_INT_H

22

23

25

29

30#ifndef _MSC_VER

32#endif

33

34#ifdef WIN32

36#else

37#include <pthread.h>

38#endif

39#include <signal.h>

40

41

43

46

48

49#ifdef ENABLE_SSPI

50#define SECURITY_WIN32

51#if defined(WIN32) && !defined(_MSC_VER)

52#include <ntsecapi.h>

53#endif

54#include <security.h>

55#undef SECURITY_WIN32

56

57#ifndef ENABLE_GSS

58

59

60

61typedef struct

62{

64 int length;

65} gss_buffer_desc;

66#endif

67#endif

68

69#ifdef USE_OPENSSL

70#include <openssl/ssl.h>

71#include <openssl/err.h>

72

73#ifndef OPENSSL_NO_ENGINE

74#define USE_SSL_ENGINE

75#endif

76#endif

77

79

80

81

82

83#define CMDSTATUS_LEN 64

84

85

86

87

88

89

90

91

92

93

94

95

96

97

99

101{

103 char space[1];

104};

105

106

108{

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130#define NULL_LEN (-1)

131

133{

134 int len;

135 char *value;

137

138

140{

142 char code;

145

146

147typedef struct

148{

154

156{

158 char *name;

159 void *passThrough;

160 void *data;

163

165{

170

171 int tupArrSize;

176 int binary;

177

178

179

180

181

182

187

188

189

190

191

192

193 char *errMsg;

195 char *errQuery;

196

197

199

200

201

202

203

204

206 int curOffset;

207 int spaceLeft;

208

209 size_t memorySize;

210};

211

212

213typedef enum

214{

218

220

221

227

228

229#define ENC_ERROR 0

230#define ENC_PLAINTEXT 0x01

231#define ENC_GSSAPI 0x02

232#define ENC_SSL 0x04

233

234

235typedef enum

236{

245

246

247typedef enum

248{

252

253

254typedef enum

255{

260

261

263{

264 const char *envName,

265 *pgName;

267

268

270{

272 char *name;

273 char *value;

274

276

277

279{

294

295

296

297

298

299

301{

302 int len;

303 const char *value;

305

306

308{

313

314

315

316

317

318typedef enum

319{

327

328

329

330

331

332

333

334

335#define AUTH_RESPONSE_GSS 'G'

336#define AUTH_RESPONSE_PASSWORD 'P'

337#define AUTH_RESPONSE_SASL_INITIAL 'I'

338#define AUTH_RESPONSE_SASL 'S'

339

340

341

342

344{

346 char *query;

349

350

351

352

353

354

356{

358 char *host;

359 char *hostaddr;

360 char *port;

361 char *password;

362

363

365

366

367

368

369

371{

372

373 char *pghost;

374

375

376

377 char *pghostaddr;

378

379

380

381 char *pgport;

382

386 char *pgoptions;

387 char *appname;

388 char *fbappname;

389 char *dbName;

390 char *replication;

391 char *pgservice;

392 char *pguser;

394 char *pgpassfile;

396

400

402

403 char *sslmode;

404 char *sslnegotiation;

406 char *sslkey;

407 char *sslcert;

409 char *sslcertmode;

411 char *sslcrl;

412 char *sslcrldir;

413 char *sslsni;

414 char *requirepeer;

415 char *gssencmode;

417 char *gsslib;

418

419 char *gssdelegation;

425 char *require_auth;

429 char *sslkeylogfile;

430

431 bool cancelRequest;

432

433

434

435

439

445

446

449

450

452

453

455 int nEvents;

457

458

464 bool nonblocking;

465

468 bool singleRowMode;

469 int maxChunkSize;

470

475

476

477 int nconnhost;

478 int whichhost;

480 char *connip;

481

482

483

484

485

488

489

490

491

492

494

495

497

501 int sversion;

503

506 bool gssapi_used;

507 bool sigpipe_so;

508 bool sigpipe_flag;

509 bool write_failed;

510 char *write_err_msg;

511

512 bool auth_required;

513

515

517

519

521

522

523

524

528

529

530

533

534 bool try_next_addr;

535 bool try_next_host;

536 int naddr;

537 int whichaddr;

538 AddrInfo *addr;

539

547

548

549 int be_pid;

561

562

563

564 char *inBuffer;

565 int inBufSize;

566 int inStart;

567 int inCursor;

568 int inEnd;

569

570

571 char *outBuffer;

573 int outCount;

574

575

576 int outMsgStart;

577

578 int outMsgEnd;

579

580

582 int rowBufLen;

583

584

585

586

587

588

589

590

591

592

593

595 bool error_result;

597

598

602

606

607

613

614#ifdef USE_SSL

615#ifdef USE_OPENSSL

616 SSL *ssl;

617 X509 *peer;

618#ifdef USE_SSL_ENGINE

619 ENGINE *engine;

620#else

621 void *engine;

622

623#endif

624#endif

625#endif

626

627#ifdef ENABLE_GSS

628 gss_ctx_id_t gctx;

629 gss_name_t gtarg_nam;

630

631

632 bool gssenc;

633 gss_cred_id_t gcred;

634

635

636 char *gss_SendBuffer;

637 int gss_SendLength;

638 int gss_SendNext;

639

640 int gss_SendConsumed;

641

642 char *gss_RecvBuffer;

643 int gss_RecvLength;

644 char *gss_ResultBuffer;

645 int gss_ResultLength;

646

647 int gss_ResultNext;

648

649 uint32 gss_MaxPktSize;

650

651#endif

652

653#ifdef ENABLE_SSPI

654 CredHandle *sspicred;

655 CtxtHandle *sspictx;

656 char *sspitarget;

657 int usesspi;

658

659#endif

660

661

662

663

664

665

666

667

668

669

670

673

674

676};

677

678

679

680

681

683

684

685#ifdef USE_SSL

686

687#ifndef WIN32

688#define USER_CERT_FILE ".postgresql/postgresql.crt"

689#define USER_KEY_FILE ".postgresql/postgresql.key"

690#define ROOT_CERT_FILE ".postgresql/root.crt"

691#define ROOT_CRL_FILE ".postgresql/root.crl"

692#else

693

694#define USER_CERT_FILE "postgresql.crt"

695#define USER_KEY_FILE "postgresql.key"

696#define ROOT_CERT_FILE "root.crt"

697#define ROOT_CRL_FILE "root.crl"

698#endif

699

700#endif

701

702

703

704

705

706

707

708

709

710

711

712

715#if defined(WIN32) && defined(SIO_KEEPALIVE_VALS)

716extern int pqSetKeepalivesWin32(pgsocket sock, int idle, int interval);

717#endif

724 const void *buf, size_t buf_len);

728 const char *context);

729

731

732#define pglock_thread() pg_g_threadlock(true)

733#define pgunlock_thread() pg_g_threadlock(false)

734

735

736

745 const char *value);

747 const char *value);

750 bool gotSync);

752

753

754

767 int *result_buf, int *actual_result_len,

768 int result_is_int,

770

771

772

774

775

776

777

778

779

780

781

804

805

806

813

814#if !defined(WIN32)

815extern int pq_block_sigpipe(sigset_t *osigset, bool *sigpipe_pending);

816extern void pq_reset_sigpipe(sigset_t *osigset, bool sigpipe_pending,

817 bool got_epipe);

818#endif

819

820

821

822

823

824

825

826

827

828

830

831

832

833

835

836

837

838

839

840

841

842

844

845

846

847

849

850

851

852

853

854

855

856

858

859

860

861

862

863

864

865

867

868

869

870

871

872

873

874

875

876

878 int *names_examined,

879 char **first_name);

880

881

882

883#ifdef ENABLE_GSS

884

885

886

887

889

890

891

892

893

896#endif

897

898

899

901 bool toServer);

904 char response);

905

906

907

908

909

910

911#define pqClearConnErrorState(conn) \

912 (resetPQExpBuffer(&(conn)->errorMessage), \

913 (conn)->errorReported = 0)

914

915

916

917

918

919

920#define pgHavePendingResult(conn) \

921 ((conn)->result != NULL || (conn)->error_result)

922

923

924

925

926

927#define pqIsnonblocking(conn) ((conn)->nonblocking)

928

929

930

931

932#define OUTBUFFER_THRESHOLD 65536

933

934#ifdef ENABLE_NLS

937#else

938#define libpq_gettext(x) (x)

939#define libpq_ngettext(s, p, n) ((n) == 1 ? (s) : (p))

940#endif

941

942

943

944

945#undef _

946

949

950

951

952

953

954#ifdef WIN32

955#define SOCK_ERRNO (WSAGetLastError())

956#define SOCK_STRERROR winsock_strerror

957#define SOCK_ERRNO_SET(e) WSASetLastError(e)

958#else

959#define SOCK_ERRNO errno

960#define SOCK_STRERROR strerror_r

961#define SOCK_ERRNO_SET(e) (errno = (e))

962#endif

963

964#endif

#define pg_attribute_format_arg(a)

#define pg_attribute_printf(f, a)

#define FLEXIBLE_ARRAY_MEMBER

static PGcancel *volatile cancelConn

ssize_t pg_GSS_read(PGconn *conn, void *ptr, size_t len)

ssize_t pg_GSS_write(PGconn *conn, const void *ptr, size_t len)

PostgresPollingStatusType pqsecure_open_gss(PGconn *conn)

int(* PGEventProc)(PGEventId evtId, void *evtInfo, void *passThrough)

void(* pgthreadlock_t)(int acquire)

void(* PQnoticeReceiver)(void *arg, const PGresult *res)

void(* PQnoticeProcessor)(void *arg, const char *message)

PostgresPollingStatusType

int pqPutc(char c, PGconn *conn)

int pqReadData(PGconn *conn)

void pqDropConnection(PGconn *conn, bool flushInput)

int PQsendQueryContinue(PGconn *conn, const char *query)

int pqPutInt(int value, size_t bytes, PGconn *conn)

void pq_reset_sigpipe(sigset_t *osigset, bool sigpipe_pending, bool got_epipe)

bool pqConnectOptions2(PGconn *conn)

int pqCheckOutBufferSpace(size_t bytes_needed, PGconn *conn)

ssize_t pqsecure_raw_write(PGconn *, const void *ptr, size_t len)

int pqFlush(PGconn *conn)

void * pqResultAlloc(PGresult *res, size_t nBytes, bool isBinary)

void pqBuildErrorMessage3(PQExpBuffer msg, const PGresult *res, PGVerbosity verbosity, PGContextVisibility show_context)

void pqParseDone(PGconn *conn, int newInStart)

void pqParseInput3(PGconn *conn)

ssize_t pqsecure_raw_read(PGconn *, void *ptr, size_t len)

char * pqBuildStartupPacket3(PGconn *conn, int *packetlen, const PQEnvironmentOption *options)

int PQsendCancelRequest(PGconn *cancelConn)

int pqReadReady(PGconn *conn)

ssize_t pqsecure_write(PGconn *, const void *ptr, size_t len)

int pqPutMsgStart(char msg_type, PGconn *conn)

int pqSkipnchar(size_t len, PGconn *conn)

int pqEndcopy3(PGconn *conn)

void pqClosePGconn(PGconn *conn)

PGresult * pqPrepareAsyncResult(PGconn *conn)

bool pqGetHomeDirectory(char *buf, int bufsize)

void libpq_append_error(PQExpBuffer errorMessage, const char *fmt,...) pg_attribute_printf(2

int pgtls_verify_peer_name_matches_certificate_guts(PGconn *conn, int *names_examined, char **first_name)

int pq_block_sigpipe(sigset_t *osigset, bool *sigpipe_pending)

void pqCommandQueueAdvance(PGconn *conn, bool isReadyForQuery, bool gotSync)

void pqSetResultError(PGresult *res, PQExpBuffer errorMessage, int offset)

struct pg_conn_host pg_conn_host

void pqSaveErrorResult(PGconn *conn)

char *const pgresStatus[]

PostgresPollingStatusType pgtls_open_client(PGconn *conn)

bool pgtls_read_pending(PGconn *conn)

PGresult * pqFunctionCall3(PGconn *conn, Oid fnid, int *result_buf, int *actual_result_len, int result_is_int, const PQArgBlock *args, int nargs)

int pqGetlineAsync3(PGconn *conn, char *buffer, int bufsize)

int pqGetCopyData3(PGconn *conn, char **buffer, int async)

int pqRowProcessor(PGconn *conn, const char **errmsgp)

struct pgresParamDesc PGresParamDesc

int pqGetc(char *result, PGconn *conn)

struct PGcmdQueueEntry PGcmdQueueEntry

int pqGetNegotiateProtocolVersion3(PGconn *conn)

int pqGetInt(int *result, size_t bytes, PGconn *conn)

bool pqParseIntParam(const char *value, int *result, PGconn *conn, const char *context)

ssize_t pgtls_read(PGconn *conn, void *ptr, size_t len)

void pqsecure_close(PGconn *)

void void libpq_append_conn_error(PGconn *conn, const char *fmt,...) pg_attribute_printf(2

void void pqSaveMessageField(PGresult *res, char code, const char *value)

ssize_t pgtls_write(PGconn *conn, const void *ptr, size_t len)

int pqWait(int forRead, int forWrite, PGconn *conn)

PostgresPollingStatusType pqsecure_open_client(PGconn *)

char * pgtls_get_peer_certificate_hash(PGconn *conn, size_t *len)

struct pgParameterStatus pgParameterStatus

void pqReleaseConnHosts(PGconn *conn)

pgthreadlock_t pg_g_threadlock

int pqGets(PQExpBuffer buf, PGconn *conn)

struct pgMessageField PGMessageField

void pqSaveParameterStatus(PGconn *conn, const char *name, const char *value)

PGconn * pqMakeEmptyPGconn(void)

void pqClearAsyncResult(PGconn *conn)

int pqPutnchar(const void *s, size_t len, PGconn *conn)

void pqTraceOutputMessage(PGconn *conn, const char *message, bool toServer)

int pqCheckInBufferSpace(size_t bytes_needed, PGconn *conn)

struct pgDataValue PGdataValue

int pqConnectDBStart(PGconn *conn)

void pqInternalNotice(const PGNoticeHooks *hooks, const char *fmt,...) pg_attribute_printf(2

#define libpq_ngettext(s, p, n)

bool pqCopyPGconn(PGconn *srcConn, PGconn *dstConn)

int pqPuts(const char *s, PGconn *conn)

char * pqResultStrdup(PGresult *res, const char *str)

ssize_t pqsecure_read(PGconn *, void *ptr, size_t len)

struct PQEnvironmentOption PQEnvironmentOption

int pqGetnchar(void *s, size_t len, PGconn *conn)

@ SERVER_TYPE_PREFER_STANDBY_PASS2

@ SERVER_TYPE_PREFER_STANDBY

int pqGetline3(PGconn *conn, char *s, int maxlen)

int pqWaitTimed(int forRead, int forWrite, PGconn *conn, pg_usec_time_t end_time)

int pqGetErrorNotice3(PGconn *conn, bool isError)

void pgtls_close(PGconn *conn)

struct pgLobjfuncs PGlobjfuncs

void pqTraceOutputNoTypeByteMessage(PGconn *conn, const char *message)

void pqTraceOutputCharResponse(PGconn *conn, const char *responseType, char response)

int pqGets_append(PQExpBuffer buf, PGconn *conn)

int pqWriteReady(PGconn *conn)

int pqPutMsgEnd(PGconn *conn)

int pqConnectDBComplete(PGconn *conn)

struct pgresAttValue PGresAttValue

int pqPacketSend(PGconn *conn, char pack_type, const void *buf, size_t buf_len)

PQnoticeReceiver noticeRec

PQnoticeProcessor noticeProc

struct PGcmdQueueEntry * next

struct pgMessageField * next

char contents[FLEXIBLE_ARRAY_MEMBER]

struct pgParameterStatus * next

uint8 * scram_client_key_binary

char * oauth_discovery_uri

char current_auth_response

PGTransactionStatusType xactStatus

const pg_fe_sasl_mech * sasl

size_t scram_client_key_len

char * ssl_max_protocol_version

PGTernaryBool in_hot_standby

uint8 * scram_server_key_binary

void(* cleanup_async_auth)(PGconn *conn)

bool client_finished_auth

PGcmdQueueEntry * cmd_queue_recycle

ProtocolVersion min_pversion

uint32 allowed_auth_methods

char * target_session_attrs

PGcmdQueueEntry * cmd_queue_tail

PQExpBufferData workBuffer

char * oauth_client_secret

char * max_protocol_version

char * load_balance_hosts

PGTernaryBool default_transaction_read_only

pgParameterStatus * pstatus

char * min_protocol_version

char * client_encoding_initial

char * keepalives_interval

char * pgtcp_user_timeout

char * ssl_min_protocol_version

PQExpBufferData errorMessage

ProtocolVersion max_pversion

PostgresPollingStatusType(* async_auth)(PGconn *conn)

PGAsyncStatusType asyncStatus

PGLoadBalanceType load_balance_type

int scram_sha_256_iterations

PGpipelineStatus pipelineStatus

uint8 allowed_enc_methods

PGNoticeHooks noticeHooks

PGTargetServerType target_server_type

size_t scram_server_key_len

PGcmdQueueEntry * cmd_queue_head

bool ssl_handshake_started

const pg_fe_sasl_mech * allowed_sasl_mechs[2]

PGContextVisibility show_context

PGNoticeHooks noticeHooks

char cmdStatus[CMDSTATUS_LEN]

PGMessageField * errFields

PGresParamDesc * paramDescs

ExecStatusType resultStatus