PostgreSQL Source Code  git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
fe-trace.c File Reference
#include "postgres_fe.h"
#include <ctype.h>
#include <limits.h>
#include <sys/time.h>
#include <unistd.h>
#include "libpq-fe.h"
#include "libpq-int.h"
#include "port/pg_bswap.h"
Include dependency graph for fe-trace.c:

Go to the source code of this file.

Functions

void PQtrace (PGconn *conn, FILE *debug_port)
 
void PQuntrace (PGconn *conn)
 
void PQsetTraceFlags (PGconn *conn, int flags)
 
static void pqTraceFormatTimestamp (char *timestr, size_t ts_len)
 
static void pqTraceOutputByte1 (FILE *pfdebug, const char *data, int *cursor)
 
static int pqTraceOutputInt16 (FILE *pfdebug, const char *data, int *cursor)
 
static int pqTraceOutputInt32 (FILE *pfdebug, const char *data, int *cursor, bool suppress)
 
static void pqTraceOutputString (FILE *pfdebug, const char *data, int *cursor, bool suppress)
 
static void pqTraceOutputNchar (FILE *pfdebug, int len, const char *data, int *cursor, bool suppress)
 
static void pqTraceOutput_NotificationResponse (FILE *f, const char *message, int *cursor, bool regress)
 
static void pqTraceOutput_Bind (FILE *f, const char *message, int *cursor)
 
static void pqTraceOutput_Close (FILE *f, const char *message, int *cursor)
 
static void pqTraceOutput_CommandComplete (FILE *f, const char *message, int *cursor)
 
static void pqTraceOutput_CopyData (FILE *f, const char *message, int *cursor, int length, bool suppress)
 
static void pqTraceOutput_DataRow (FILE *f, const char *message, int *cursor)
 
static void pqTraceOutput_Describe (FILE *f, const char *message, int *cursor)
 
static void pqTraceOutputNR (FILE *f, const char *type, const char *message, int *cursor, bool regress)
 
static void pqTraceOutput_ErrorResponse (FILE *f, const char *message, int *cursor, bool regress)
 
static void pqTraceOutput_NoticeResponse (FILE *f, const char *message, int *cursor, bool regress)
 
static void pqTraceOutput_Execute (FILE *f, const char *message, int *cursor, bool regress)
 
static void pqTraceOutput_CopyFail (FILE *f, const char *message, int *cursor)
 
static void pqTraceOutput_GSSResponse (FILE *f, const char *message, int *cursor, int length, bool regress)
 
static void pqTraceOutput_PasswordMessage (FILE *f, const char *message, int *cursor)
 
static void pqTraceOutput_SASLInitialResponse (FILE *f, const char *message, int *cursor, bool regress)
 
static void pqTraceOutput_SASLResponse (FILE *f, const char *message, int *cursor, int length, bool regress)
 
static void pqTraceOutput_FunctionCall (FILE *f, const char *message, int *cursor, bool regress)
 
static void pqTraceOutput_CopyInResponse (FILE *f, const char *message, int *cursor)
 
static void pqTraceOutput_CopyOutResponse (FILE *f, const char *message, int *cursor)
 
static void pqTraceOutput_BackendKeyData (FILE *f, const char *message, int *cursor, bool regress)
 
static void pqTraceOutput_Parse (FILE *f, const char *message, int *cursor, bool regress)
 
static void pqTraceOutput_Query (FILE *f, const char *message, int *cursor)
 
static void pqTraceOutput_Authentication (FILE *f, const char *message, int *cursor, int length, bool suppress)
 
static void pqTraceOutput_ParameterStatus (FILE *f, const char *message, int *cursor)
 
static void pqTraceOutput_ParameterDescription (FILE *f, const char *message, int *cursor, bool regress)
 
static void pqTraceOutput_RowDescription (FILE *f, const char *message, int *cursor, bool regress)
 
static void pqTraceOutput_NegotiateProtocolVersion (FILE *f, const char *message, int *cursor)
 
static void pqTraceOutput_FunctionCallResponse (FILE *f, const char *message, int *cursor)
 
static void pqTraceOutput_CopyBothResponse (FILE *f, const char *message, int *cursor, int length)
 
static void pqTraceOutput_ReadyForQuery (FILE *f, const char *message, int *cursor)
 
void pqTraceOutputMessage (PGconn *conn, const char *message, bool toServer)
 
void pqTraceOutputNoTypeByteMessage (PGconn *conn, const char *message)
 
void pqTraceOutputCharResponse (PGconn *conn, const char *responseType, char response)
 

Function Documentation

◆ PQsetTraceFlags()

void PQsetTraceFlags ( PGconn conn,
int  flags 
)

Definition at line 64 of file fe-trace.c.

65 {
66  if (conn == NULL)
67  return;
68  /* If PQtrace() failed, do nothing. */
69  if (conn->Pfdebug == NULL)
70  return;
71  conn->traceFlags = flags;
72 }
PGconn * conn
Definition: streamutil.c:53
FILE * Pfdebug
Definition: libpq-int.h:436
int traceFlags
Definition: libpq-int.h:437

References conn, pg_conn::Pfdebug, and pg_conn::traceFlags.

Referenced by main().

◆ PQtrace()

void PQtrace ( PGconn conn,
FILE *  debug_port 
)

Definition at line 35 of file fe-trace.c.

36 {
37  if (conn == NULL)
38  return;
39  PQuntrace(conn);
40  if (debug_port == NULL)
41  return;
42 
43  conn->Pfdebug = debug_port;
44  conn->traceFlags = 0;
45 }
void PQuntrace(PGconn *conn)
Definition: fe-trace.c:49

References conn, pg_conn::Pfdebug, PQuntrace(), and pg_conn::traceFlags.

Referenced by main().

◆ pqTraceFormatTimestamp()

static void pqTraceFormatTimestamp ( char *  timestr,
size_t  ts_len 
)
static

Definition at line 80 of file fe-trace.c.

81 {
82  struct timeval tval;
83  time_t now;
84  struct tm tmbuf;
85 
86  gettimeofday(&tval, NULL);
87 
88  /*
89  * MSVC's implementation of timeval uses a long for tv_sec, however,
90  * localtime() expects a time_t pointer. Here we'll assign tv_sec to a
91  * local time_t variable so that we pass localtime() the correct pointer
92  * type.
93  */
94  now = tval.tv_sec;
95  strftime(timestr, ts_len,
96  "%Y-%m-%d %H:%M:%S",
97  localtime_r(&now, &tmbuf));
98  /* append microseconds */
99  snprintf(timestr + strlen(timestr), ts_len - strlen(timestr),
100  ".%06u", (unsigned int) (tval.tv_usec));
101 }
Datum now(PG_FUNCTION_ARGS)
Definition: timestamp.c:1608
static struct pg_tm tm
Definition: localtime.c:104
#define snprintf
Definition: port.h:238
int gettimeofday(struct timeval *tp, void *tzp)

References gettimeofday(), now(), snprintf, and tm.

Referenced by pqTraceOutputCharResponse(), pqTraceOutputMessage(), and pqTraceOutputNoTypeByteMessage().

◆ pqTraceOutput_Authentication()

static void pqTraceOutput_Authentication ( FILE *  f,
const char *  message,
int *  cursor,
int  length,
bool  suppress 
)
static

Definition at line 484 of file fe-trace.c.

486 {
487  int authType = 0;
488 
489  memcpy(&authType, message + *cursor, 4);
490  authType = (int) pg_ntoh32(authType);
491  *cursor += 4;
492  switch (authType)
493  {
494  case AUTH_REQ_OK:
495  fprintf(f, "AuthenticationOk");
496  break;
497  /* AUTH_REQ_KRB4 not supported */
498  /* AUTH_REQ_KRB5 not supported */
499  case AUTH_REQ_PASSWORD:
500  fprintf(f, "AuthenticationCleartextPassword");
501  break;
502  /* AUTH_REQ_CRYPT not supported */
503  case AUTH_REQ_MD5:
504  fprintf(f, "AuthenticationMD5Password");
505  break;
506  case AUTH_REQ_GSS:
507  fprintf(f, "AuthenticationGSS");
508  break;
509  case AUTH_REQ_GSS_CONT:
510  fprintf(f, "AuthenticationGSSContinue\t");
511  pqTraceOutputNchar(f, length - *cursor + 1, message, cursor,
512  suppress);
513  break;
514  case AUTH_REQ_SSPI:
515  fprintf(f, "AuthenticationSSPI");
516  break;
517  case AUTH_REQ_SASL:
518  fprintf(f, "AuthenticationSASL\t");
519  while (message[*cursor] != '\0')
520  pqTraceOutputString(f, message, cursor, false);
521  pqTraceOutputString(f, message, cursor, false);
522  break;
523  case AUTH_REQ_SASL_CONT:
524  fprintf(f, "AuthenticationSASLContinue\t");
525  pqTraceOutputNchar(f, length - *cursor + 1, message, cursor,
526  suppress);
527  break;
528  case AUTH_REQ_SASL_FIN:
529  fprintf(f, "AuthenticationSASLFinal\t");
530  pqTraceOutputNchar(f, length - *cursor + 1, message, cursor,
531  suppress);
532  break;
533  default:
534  fprintf(f, "Unknown authentication message %d", authType);
535  }
536 }
static void pqTraceOutputString(FILE *pfdebug, const char *data, int *cursor, bool suppress)
Definition: fe-trace.c:166
static void pqTraceOutputNchar(FILE *pfdebug, int len, const char *data, int *cursor, bool suppress)
Definition: fe-trace.c:193
#define pg_ntoh32(x)
Definition: pg_bswap.h:125
#define fprintf
Definition: port.h:242
#define AUTH_REQ_SSPI
Definition: protocol.h:83
#define AUTH_REQ_SASL_CONT
Definition: protocol.h:85
#define AUTH_REQ_GSS
Definition: protocol.h:81
#define AUTH_REQ_MD5
Definition: protocol.h:79
#define AUTH_REQ_OK
Definition: protocol.h:74
#define AUTH_REQ_PASSWORD
Definition: protocol.h:77
#define AUTH_REQ_GSS_CONT
Definition: protocol.h:82
#define AUTH_REQ_SASL
Definition: protocol.h:84
#define AUTH_REQ_SASL_FIN
Definition: protocol.h:86
Definition: type.h:137

References AUTH_REQ_GSS, AUTH_REQ_GSS_CONT, AUTH_REQ_MD5, AUTH_REQ_OK, AUTH_REQ_PASSWORD, AUTH_REQ_SASL, AUTH_REQ_SASL_CONT, AUTH_REQ_SASL_FIN, AUTH_REQ_SSPI, fprintf, pg_ntoh32, pqTraceOutputNchar(), and pqTraceOutputString().

Referenced by pqTraceOutputMessage().

◆ pqTraceOutput_BackendKeyData()

static void pqTraceOutput_BackendKeyData ( FILE *  f,
const char *  message,
int *  cursor,
bool  regress 
)
static

Definition at line 455 of file fe-trace.c.

456 {
457  fprintf(f, "BackendKeyData\t");
458  pqTraceOutputInt32(f, message, cursor, regress);
459  pqTraceOutputInt32(f, message, cursor, regress);
460 }
static int pqTraceOutputInt32(FILE *pfdebug, const char *data, int *cursor, bool suppress)
Definition: fe-trace.c:145

References fprintf, and pqTraceOutputInt32().

Referenced by pqTraceOutputMessage().

◆ pqTraceOutput_Bind()

static void pqTraceOutput_Bind ( FILE *  f,
const char *  message,
int *  cursor 
)
static

Definition at line 240 of file fe-trace.c.

241 {
242  int nparams;
243 
244  fprintf(f, "Bind\t");
245  pqTraceOutputString(f, message, cursor, false);
246  pqTraceOutputString(f, message, cursor, false);
247  nparams = pqTraceOutputInt16(f, message, cursor);
248 
249  for (int i = 0; i < nparams; i++)
250  pqTraceOutputInt16(f, message, cursor);
251 
252  nparams = pqTraceOutputInt16(f, message, cursor);
253 
254  for (int i = 0; i < nparams; i++)
255  {
256  int nbytes;
257 
258  nbytes = pqTraceOutputInt32(f, message, cursor, false);
259  if (nbytes == -1)
260  continue;
261  pqTraceOutputNchar(f, nbytes, message, cursor, false);
262  }
263 
264  nparams = pqTraceOutputInt16(f, message, cursor);
265  for (int i = 0; i < nparams; i++)
266  pqTraceOutputInt16(f, message, cursor);
267 }
static int pqTraceOutputInt16(FILE *pfdebug, const char *data, int *cursor)
Definition: fe-trace.c:126
int i
Definition: isn.c:72

References fprintf, i, pqTraceOutputInt16(), pqTraceOutputInt32(), pqTraceOutputNchar(), and pqTraceOutputString().

Referenced by pqTraceOutputMessage().

◆ pqTraceOutput_Close()

static void pqTraceOutput_Close ( FILE *  f,
const char *  message,
int *  cursor 
)
static

Definition at line 270 of file fe-trace.c.

271 {
272  fprintf(f, "Close\t");
273  pqTraceOutputByte1(f, message, cursor);
274  pqTraceOutputString(f, message, cursor, false);
275 }
static void pqTraceOutputByte1(FILE *pfdebug, const char *data, int *cursor)
Definition: fe-trace.c:107

References fprintf, pqTraceOutputByte1(), and pqTraceOutputString().

Referenced by pqTraceOutputMessage().

◆ pqTraceOutput_CommandComplete()

static void pqTraceOutput_CommandComplete ( FILE *  f,
const char *  message,
int *  cursor 
)
static

Definition at line 278 of file fe-trace.c.

279 {
280  fprintf(f, "CommandComplete\t");
281  pqTraceOutputString(f, message, cursor, false);
282 }

References fprintf, and pqTraceOutputString().

Referenced by pqTraceOutputMessage().

◆ pqTraceOutput_CopyBothResponse()

static void pqTraceOutput_CopyBothResponse ( FILE *  f,
const char *  message,
int *  cursor,
int  length 
)
static

Definition at line 598 of file fe-trace.c.

599 {
600  fprintf(f, "CopyBothResponse\t");
601  pqTraceOutputByte1(f, message, cursor);
602 
603  while (length > *cursor)
604  pqTraceOutputInt16(f, message, cursor);
605 }

References fprintf, pqTraceOutputByte1(), and pqTraceOutputInt16().

Referenced by pqTraceOutputMessage().

◆ pqTraceOutput_CopyData()

static void pqTraceOutput_CopyData ( FILE *  f,
const char *  message,
int *  cursor,
int  length,
bool  suppress 
)
static

Definition at line 285 of file fe-trace.c.

287 {
288  fprintf(f, "CopyData\t");
289  pqTraceOutputNchar(f, length - *cursor + 1, message, cursor, suppress);
290 }

References fprintf, and pqTraceOutputNchar().

Referenced by pqTraceOutputMessage().

◆ pqTraceOutput_CopyFail()

static void pqTraceOutput_CopyFail ( FILE *  f,
const char *  message,
int *  cursor 
)
static

Definition at line 360 of file fe-trace.c.

361 {
362  fprintf(f, "CopyFail\t");
363  pqTraceOutputString(f, message, cursor, false);
364 }

References fprintf, and pqTraceOutputString().

Referenced by pqTraceOutputMessage().

◆ pqTraceOutput_CopyInResponse()

static void pqTraceOutput_CopyInResponse ( FILE *  f,
const char *  message,
int *  cursor 
)
static

Definition at line 429 of file fe-trace.c.

430 {
431  int nfields;
432 
433  fprintf(f, "CopyInResponse\t");
434  pqTraceOutputByte1(f, message, cursor);
435  nfields = pqTraceOutputInt16(f, message, cursor);
436 
437  for (int i = 0; i < nfields; i++)
438  pqTraceOutputInt16(f, message, cursor);
439 }

References fprintf, i, pqTraceOutputByte1(), and pqTraceOutputInt16().

Referenced by pqTraceOutputMessage().

◆ pqTraceOutput_CopyOutResponse()

static void pqTraceOutput_CopyOutResponse ( FILE *  f,
const char *  message,
int *  cursor 
)
static

Definition at line 442 of file fe-trace.c.

443 {
444  int nfields;
445 
446  fprintf(f, "CopyOutResponse\t");
447  pqTraceOutputByte1(f, message, cursor);
448  nfields = pqTraceOutputInt16(f, message, cursor);
449 
450  for (int i = 0; i < nfields; i++)
451  pqTraceOutputInt16(f, message, cursor);
452 }

References fprintf, i, pqTraceOutputByte1(), and pqTraceOutputInt16().

Referenced by pqTraceOutputMessage().

◆ pqTraceOutput_DataRow()

static void pqTraceOutput_DataRow ( FILE *  f,
const char *  message,
int *  cursor 
)
static

Definition at line 293 of file fe-trace.c.

294 {
295  int nfields;
296  int len;
297  int i;
298 
299  fprintf(f, "DataRow\t");
300  nfields = pqTraceOutputInt16(f, message, cursor);
301  for (i = 0; i < nfields; i++)
302  {
303  len = pqTraceOutputInt32(f, message, cursor, false);
304  if (len == -1)
305  continue;
306  pqTraceOutputNchar(f, len, message, cursor, false);
307  }
308 }
const void size_t len

References fprintf, i, len, pqTraceOutputInt16(), pqTraceOutputInt32(), and pqTraceOutputNchar().

Referenced by pqTraceOutputMessage().

◆ pqTraceOutput_Describe()

static void pqTraceOutput_Describe ( FILE *  f,
const char *  message,
int *  cursor 
)
static

Definition at line 311 of file fe-trace.c.

312 {
313  fprintf(f, "Describe\t");
314  pqTraceOutputByte1(f, message, cursor);
315  pqTraceOutputString(f, message, cursor, false);
316 }

References fprintf, pqTraceOutputByte1(), and pqTraceOutputString().

Referenced by pqTraceOutputMessage().

◆ pqTraceOutput_ErrorResponse()

static void pqTraceOutput_ErrorResponse ( FILE *  f,
const char *  message,
int *  cursor,
bool  regress 
)
static

Definition at line 340 of file fe-trace.c.

341 {
342  pqTraceOutputNR(f, "ErrorResponse", message, cursor, regress);
343 }
static void pqTraceOutputNR(FILE *f, const char *type, const char *message, int *cursor, bool regress)
Definition: fe-trace.c:320

References pqTraceOutputNR().

Referenced by pqTraceOutputMessage().

◆ pqTraceOutput_Execute()

static void pqTraceOutput_Execute ( FILE *  f,
const char *  message,
int *  cursor,
bool  regress 
)
static

Definition at line 352 of file fe-trace.c.

353 {
354  fprintf(f, "Execute\t");
355  pqTraceOutputString(f, message, cursor, false);
356  pqTraceOutputInt32(f, message, cursor, false);
357 }

References fprintf, pqTraceOutputInt32(), and pqTraceOutputString().

Referenced by pqTraceOutputMessage().

◆ pqTraceOutput_FunctionCall()

static void pqTraceOutput_FunctionCall ( FILE *  f,
const char *  message,
int *  cursor,
bool  regress 
)
static

Definition at line 403 of file fe-trace.c.

404 {
405  int nfields;
406  int nbytes;
407 
408  fprintf(f, "FunctionCall\t");
409  pqTraceOutputInt32(f, message, cursor, regress);
410  nfields = pqTraceOutputInt16(f, message, cursor);
411 
412  for (int i = 0; i < nfields; i++)
413  pqTraceOutputInt16(f, message, cursor);
414 
415  nfields = pqTraceOutputInt16(f, message, cursor);
416 
417  for (int i = 0; i < nfields; i++)
418  {
419  nbytes = pqTraceOutputInt32(f, message, cursor, false);
420  if (nbytes == -1)
421  continue;
422  pqTraceOutputNchar(f, nbytes, message, cursor, false);
423  }
424 
425  pqTraceOutputInt16(f, message, cursor);
426 }

References fprintf, i, pqTraceOutputInt16(), pqTraceOutputInt32(), and pqTraceOutputNchar().

Referenced by pqTraceOutputMessage().

◆ pqTraceOutput_FunctionCallResponse()

static void pqTraceOutput_FunctionCallResponse ( FILE *  f,
const char *  message,
int *  cursor 
)
static

Definition at line 587 of file fe-trace.c.

588 {
589  int len;
590 
591  fprintf(f, "FunctionCallResponse\t");
592  len = pqTraceOutputInt32(f, message, cursor, false);
593  if (len != -1)
594  pqTraceOutputNchar(f, len, message, cursor, false);
595 }

References fprintf, len, pqTraceOutputInt32(), and pqTraceOutputNchar().

Referenced by pqTraceOutputMessage().

◆ pqTraceOutput_GSSResponse()

static void pqTraceOutput_GSSResponse ( FILE *  f,
const char *  message,
int *  cursor,
int  length,
bool  regress 
)
static

Definition at line 367 of file fe-trace.c.

369 {
370  fprintf(f, "GSSResponse\t");
371  pqTraceOutputNchar(f, length - *cursor + 1, message, cursor, regress);
372 }

References fprintf, and pqTraceOutputNchar().

Referenced by pqTraceOutputMessage().

◆ pqTraceOutput_NegotiateProtocolVersion()

static void pqTraceOutput_NegotiateProtocolVersion ( FILE *  f,
const char *  message,
int *  cursor 
)
static

Definition at line 579 of file fe-trace.c.

580 {
581  fprintf(f, "NegotiateProtocolVersion\t");
582  pqTraceOutputInt32(f, message, cursor, false);
583  pqTraceOutputInt32(f, message, cursor, false);
584 }

References fprintf, and pqTraceOutputInt32().

Referenced by pqTraceOutputMessage().

◆ pqTraceOutput_NoticeResponse()

static void pqTraceOutput_NoticeResponse ( FILE *  f,
const char *  message,
int *  cursor,
bool  regress 
)
static

Definition at line 346 of file fe-trace.c.

347 {
348  pqTraceOutputNR(f, "NoticeResponse", message, cursor, regress);
349 }

References pqTraceOutputNR().

Referenced by pqTraceOutputMessage().

◆ pqTraceOutput_NotificationResponse()

static void pqTraceOutput_NotificationResponse ( FILE *  f,
const char *  message,
int *  cursor,
bool  regress 
)
static

Definition at line 231 of file fe-trace.c.

232 {
233  fprintf(f, "NotificationResponse\t");
234  pqTraceOutputInt32(f, message, cursor, regress);
235  pqTraceOutputString(f, message, cursor, false);
236  pqTraceOutputString(f, message, cursor, false);
237 }

References fprintf, pqTraceOutputInt32(), and pqTraceOutputString().

Referenced by pqTraceOutputMessage().

◆ pqTraceOutput_ParameterDescription()

static void pqTraceOutput_ParameterDescription ( FILE *  f,
const char *  message,
int *  cursor,
bool  regress 
)
static

Definition at line 547 of file fe-trace.c.

548 {
549  int nfields;
550 
551  fprintf(f, "ParameterDescription\t");
552  nfields = pqTraceOutputInt16(f, message, cursor);
553 
554  for (int i = 0; i < nfields; i++)
555  pqTraceOutputInt32(f, message, cursor, regress);
556 }

References fprintf, i, pqTraceOutputInt16(), and pqTraceOutputInt32().

Referenced by pqTraceOutputMessage().

◆ pqTraceOutput_ParameterStatus()

static void pqTraceOutput_ParameterStatus ( FILE *  f,
const char *  message,
int *  cursor 
)
static

Definition at line 539 of file fe-trace.c.

540 {
541  fprintf(f, "ParameterStatus\t");
542  pqTraceOutputString(f, message, cursor, false);
543  pqTraceOutputString(f, message, cursor, false);
544 }

References fprintf, and pqTraceOutputString().

Referenced by pqTraceOutputMessage().

◆ pqTraceOutput_Parse()

static void pqTraceOutput_Parse ( FILE *  f,
const char *  message,
int *  cursor,
bool  regress 
)
static

Definition at line 463 of file fe-trace.c.

464 {
465  int nparams;
466 
467  fprintf(f, "Parse\t");
468  pqTraceOutputString(f, message, cursor, false);
469  pqTraceOutputString(f, message, cursor, false);
470  nparams = pqTraceOutputInt16(f, message, cursor);
471 
472  for (int i = 0; i < nparams; i++)
473  pqTraceOutputInt32(f, message, cursor, regress);
474 }

References fprintf, i, pqTraceOutputInt16(), pqTraceOutputInt32(), and pqTraceOutputString().

Referenced by pqTraceOutputMessage().

◆ pqTraceOutput_PasswordMessage()

static void pqTraceOutput_PasswordMessage ( FILE *  f,
const char *  message,
int *  cursor 
)
static

Definition at line 375 of file fe-trace.c.

376 {
377  fprintf(f, "PasswordMessage\t");
378  pqTraceOutputString(f, message, cursor, false);
379 }

References fprintf, and pqTraceOutputString().

Referenced by pqTraceOutputMessage().

◆ pqTraceOutput_Query()

static void pqTraceOutput_Query ( FILE *  f,
const char *  message,
int *  cursor 
)
static

Definition at line 477 of file fe-trace.c.

478 {
479  fprintf(f, "Query\t");
480  pqTraceOutputString(f, message, cursor, false);
481 }

References fprintf, and pqTraceOutputString().

Referenced by pqTraceOutputMessage().

◆ pqTraceOutput_ReadyForQuery()

static void pqTraceOutput_ReadyForQuery ( FILE *  f,
const char *  message,
int *  cursor 
)
static

Definition at line 608 of file fe-trace.c.

609 {
610  fprintf(f, "ReadyForQuery\t");
611  pqTraceOutputByte1(f, message, cursor);
612 }

References fprintf, and pqTraceOutputByte1().

Referenced by pqTraceOutputMessage().

◆ pqTraceOutput_RowDescription()

static void pqTraceOutput_RowDescription ( FILE *  f,
const char *  message,
int *  cursor,
bool  regress 
)
static

Definition at line 559 of file fe-trace.c.

560 {
561  int nfields;
562 
563  fprintf(f, "RowDescription\t");
564  nfields = pqTraceOutputInt16(f, message, cursor);
565 
566  for (int i = 0; i < nfields; i++)
567  {
568  pqTraceOutputString(f, message, cursor, false);
569  pqTraceOutputInt32(f, message, cursor, regress);
570  pqTraceOutputInt16(f, message, cursor);
571  pqTraceOutputInt32(f, message, cursor, regress);
572  pqTraceOutputInt16(f, message, cursor);
573  pqTraceOutputInt32(f, message, cursor, false);
574  pqTraceOutputInt16(f, message, cursor);
575  }
576 }

References fprintf, i, pqTraceOutputInt16(), pqTraceOutputInt32(), and pqTraceOutputString().

Referenced by pqTraceOutputMessage().

◆ pqTraceOutput_SASLInitialResponse()

static void pqTraceOutput_SASLInitialResponse ( FILE *  f,
const char *  message,
int *  cursor,
bool  regress 
)
static

Definition at line 382 of file fe-trace.c.

384 {
385  int initialResponse;
386 
387  fprintf(f, "SASLInitialResponse\t");
388  pqTraceOutputString(f, message, cursor, false);
389  initialResponse = pqTraceOutputInt32(f, message, cursor, false);
390  if (initialResponse != -1)
391  pqTraceOutputNchar(f, initialResponse, message, cursor, regress);
392 }

References fprintf, pqTraceOutputInt32(), pqTraceOutputNchar(), and pqTraceOutputString().

Referenced by pqTraceOutputMessage().

◆ pqTraceOutput_SASLResponse()

static void pqTraceOutput_SASLResponse ( FILE *  f,
const char *  message,
int *  cursor,
int  length,
bool  regress 
)
static

Definition at line 395 of file fe-trace.c.

397 {
398  fprintf(f, "SASLResponse\t");
399  pqTraceOutputNchar(f, length - *cursor + 1, message, cursor, regress);
400 }

References fprintf, and pqTraceOutputNchar().

Referenced by pqTraceOutputMessage().

◆ pqTraceOutputByte1()

static void pqTraceOutputByte1 ( FILE *  pfdebug,
const char *  data,
int *  cursor 
)
static

Definition at line 107 of file fe-trace.c.

108 {
109  const char *v = data + *cursor;
110 
111  /*
112  * Show non-printable data in hex format, including the terminating \0
113  * that completes ErrorResponse and NoticeResponse messages.
114  */
115  if (!isprint((unsigned char) *v))
116  fprintf(pfdebug, " \\x%02x", *v);
117  else
118  fprintf(pfdebug, " %c", *v);
119  *cursor += 1;
120 }
const void * data

References data, and fprintf.

Referenced by pqTraceOutput_Close(), pqTraceOutput_CopyBothResponse(), pqTraceOutput_CopyInResponse(), pqTraceOutput_CopyOutResponse(), pqTraceOutput_Describe(), pqTraceOutput_ReadyForQuery(), and pqTraceOutputNR().

◆ pqTraceOutputCharResponse()

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

Definition at line 909 of file fe-trace.c.

911 {
913  {
914  char timestr[128];
915 
916  pqTraceFormatTimestamp(timestr, sizeof(timestr));
917  fprintf(conn->Pfdebug, "%s\t", timestr);
918  }
919 
920  fprintf(conn->Pfdebug, "B\t1\t%s\t %c\n", responseType, response);
921 }
static void pqTraceFormatTimestamp(char *timestr, size_t ts_len)
Definition: fe-trace.c:80
#define PQTRACE_SUPPRESS_TIMESTAMPS
Definition: libpq-fe.h:466

References conn, fprintf, pg_conn::Pfdebug, PQTRACE_SUPPRESS_TIMESTAMPS, pqTraceFormatTimestamp(), and pg_conn::traceFlags.

Referenced by PQconnectPoll().

◆ pqTraceOutputInt16()

static int pqTraceOutputInt16 ( FILE *  pfdebug,
const char *  data,
int *  cursor 
)
static

Definition at line 126 of file fe-trace.c.

127 {
128  uint16 tmp;
129  int result;
130 
131  memcpy(&tmp, data + *cursor, 2);
132  *cursor += 2;
133  result = (int) pg_ntoh16(tmp);
134  fprintf(pfdebug, " %d", result);
135 
136  return result;
137 }
unsigned short uint16
Definition: c.h:517
#define pg_ntoh16(x)
Definition: pg_bswap.h:124

References data, fprintf, and pg_ntoh16.

Referenced by pqTraceOutput_Bind(), pqTraceOutput_CopyBothResponse(), pqTraceOutput_CopyInResponse(), pqTraceOutput_CopyOutResponse(), pqTraceOutput_DataRow(), pqTraceOutput_FunctionCall(), pqTraceOutput_ParameterDescription(), pqTraceOutput_Parse(), pqTraceOutput_RowDescription(), and pqTraceOutputNoTypeByteMessage().

◆ pqTraceOutputInt32()

static int pqTraceOutputInt32 ( FILE *  pfdebug,
const char *  data,
int *  cursor,
bool  suppress 
)
static

Definition at line 145 of file fe-trace.c.

146 {
147  int result;
148 
149  memcpy(&result, data + *cursor, 4);
150  *cursor += 4;
151  result = (int) pg_ntoh32(result);
152  if (suppress)
153  fprintf(pfdebug, " NNNN");
154  else
155  fprintf(pfdebug, " %d", result);
156 
157  return result;
158 }

References data, fprintf, and pg_ntoh32.

Referenced by pqTraceOutput_BackendKeyData(), pqTraceOutput_Bind(), pqTraceOutput_DataRow(), pqTraceOutput_Execute(), pqTraceOutput_FunctionCall(), pqTraceOutput_FunctionCallResponse(), pqTraceOutput_NegotiateProtocolVersion(), pqTraceOutput_NotificationResponse(), pqTraceOutput_ParameterDescription(), pqTraceOutput_Parse(), pqTraceOutput_RowDescription(), pqTraceOutput_SASLInitialResponse(), and pqTraceOutputNoTypeByteMessage().

◆ pqTraceOutputMessage()

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

Definition at line 618 of file fe-trace.c.

619 {
620  char id;
621  int length;
622  char *prefix = toServer ? "F" : "B";
623  int logCursor = 0;
624  bool regress;
625 
627  {
628  char timestr[128];
629 
630  pqTraceFormatTimestamp(timestr, sizeof(timestr));
631  fprintf(conn->Pfdebug, "%s\t", timestr);
632  }
633  regress = (conn->traceFlags & PQTRACE_REGRESS_MODE) != 0;
634 
635  id = message[logCursor++];
636 
637  memcpy(&length, message + logCursor, 4);
638  length = (int) pg_ntoh32(length);
639  logCursor += 4;
640 
641  /*
642  * In regress mode, suppress the length of ErrorResponse and
643  * NoticeResponse. The F (file name), L (line number) and R (routine
644  * name) fields can change as server code is modified, and if their
645  * lengths differ from the originals, that would break tests.
646  */
647  if (regress && !toServer && (id == PqMsg_ErrorResponse || id == PqMsg_NoticeResponse))
648  fprintf(conn->Pfdebug, "%s\tNN\t", prefix);
649  else
650  fprintf(conn->Pfdebug, "%s\t%d\t", prefix, length);
651 
652  switch (id)
653  {
654  case PqMsg_ParseComplete:
655  fprintf(conn->Pfdebug, "ParseComplete");
656  /* No message content */
657  break;
658  case PqMsg_BindComplete:
659  fprintf(conn->Pfdebug, "BindComplete");
660  /* No message content */
661  break;
662  case PqMsg_CloseComplete:
663  fprintf(conn->Pfdebug, "CloseComplete");
664  /* No message content */
665  break;
667  pqTraceOutput_NotificationResponse(conn->Pfdebug, message, &logCursor, regress);
668  break;
669  case PqMsg_Bind:
670  pqTraceOutput_Bind(conn->Pfdebug, message, &logCursor);
671  break;
672  case PqMsg_CopyDone:
673  fprintf(conn->Pfdebug, "CopyDone");
674  /* No message content */
675  break;
677  /* Close(F) and CommandComplete(B) use the same identifier. */
679  if (toServer)
680  pqTraceOutput_Close(conn->Pfdebug, message, &logCursor);
681  else
682  pqTraceOutput_CommandComplete(conn->Pfdebug, message, &logCursor);
683  break;
684  case PqMsg_CopyData:
685  pqTraceOutput_CopyData(conn->Pfdebug, message, &logCursor,
686  length, regress);
687  break;
688  case PqMsg_Describe:
689  /* Describe(F) and DataRow(B) use the same identifier. */
691  if (toServer)
692  pqTraceOutput_Describe(conn->Pfdebug, message, &logCursor);
693  else
694  pqTraceOutput_DataRow(conn->Pfdebug, message, &logCursor);
695  break;
696  case PqMsg_Execute:
697  /* Execute(F) and ErrorResponse(B) use the same identifier. */
699  if (toServer)
700  pqTraceOutput_Execute(conn->Pfdebug, message, &logCursor, regress);
701  else
702  pqTraceOutput_ErrorResponse(conn->Pfdebug, message, &logCursor, regress);
703  break;
704  case PqMsg_CopyFail:
705  pqTraceOutput_CopyFail(conn->Pfdebug, message, &logCursor);
706  break;
707  case PqMsg_GSSResponse:
711 
712  /*
713  * These messages share a common type byte, so we discriminate by
714  * having the code store the auth type separately.
715  */
716  switch (conn->current_auth_response)
717  {
718  case AUTH_RESPONSE_GSS:
720  &logCursor, length, regress);
721  break;
724  &logCursor);
725  break;
728  &logCursor, regress);
729  break;
730  case AUTH_RESPONSE_SASL:
732  &logCursor, length, regress);
733  break;
734  default:
735  fprintf(conn->Pfdebug, "UnknownAuthenticationResponse");
736  break;
737  }
738  conn->current_auth_response = '\0';
739  break;
740  case PqMsg_FunctionCall:
741  pqTraceOutput_FunctionCall(conn->Pfdebug, message, &logCursor, regress);
742  break;
744  pqTraceOutput_CopyInResponse(conn->Pfdebug, message, &logCursor);
745  break;
746  case PqMsg_Flush:
747  /* Flush(F) and CopyOutResponse(B) use the same identifier */
749  if (toServer)
750  fprintf(conn->Pfdebug, "Flush"); /* no message content */
751  else
752  pqTraceOutput_CopyOutResponse(conn->Pfdebug, message, &logCursor);
753  break;
755  fprintf(conn->Pfdebug, "EmptyQueryResponse");
756  /* No message content */
757  break;
759  pqTraceOutput_BackendKeyData(conn->Pfdebug, message, &logCursor, regress);
760  break;
761  case PqMsg_NoData:
762  fprintf(conn->Pfdebug, "NoData");
763  /* No message content */
764  break;
766  pqTraceOutput_NoticeResponse(conn->Pfdebug, message, &logCursor, regress);
767  break;
768  case PqMsg_Parse:
769  pqTraceOutput_Parse(conn->Pfdebug, message, &logCursor, regress);
770  break;
771  case PqMsg_Query:
772  pqTraceOutput_Query(conn->Pfdebug, message, &logCursor);
773  break;
775  pqTraceOutput_Authentication(conn->Pfdebug, message, &logCursor,
776  length, regress);
777  break;
779  fprintf(conn->Pfdebug, "PortalSuspended");
780  /* No message content */
781  break;
782  case PqMsg_Sync:
783  /* ParameterStatus(B) and Sync(F) use the same identifier */
785  if (toServer)
786  fprintf(conn->Pfdebug, "Sync"); /* no message content */
787  else
788  pqTraceOutput_ParameterStatus(conn->Pfdebug, message, &logCursor);
789  break;
791  pqTraceOutput_ParameterDescription(conn->Pfdebug, message, &logCursor, regress);
792  break;
794  pqTraceOutput_RowDescription(conn->Pfdebug, message, &logCursor, regress);
795  break;
797  pqTraceOutput_NegotiateProtocolVersion(conn->Pfdebug, message, &logCursor);
798  break;
800  pqTraceOutput_FunctionCallResponse(conn->Pfdebug, message, &logCursor);
801  break;
803  pqTraceOutput_CopyBothResponse(conn->Pfdebug, message, &logCursor, length);
804  break;
805  case PqMsg_Terminate:
806  fprintf(conn->Pfdebug, "Terminate");
807  /* No message content */
808  break;
809  case PqMsg_ReadyForQuery:
810  pqTraceOutput_ReadyForQuery(conn->Pfdebug, message, &logCursor);
811  break;
812  default:
813  fprintf(conn->Pfdebug, "Unknown message: %02x", id);
814  break;
815  }
816 
817  fputc('\n', conn->Pfdebug);
818 
819  /*
820  * Verify the printing routine did it right. Note that the one-byte
821  * message identifier is not included in the length, but our cursor does
822  * include it.
823  */
824  if (logCursor - 1 != length)
826  "mismatched message length: consumed %d, expected %d\n",
827  logCursor - 1, length);
828 }
#define Assert(condition)
Definition: c.h:863
static void pqTraceOutput_RowDescription(FILE *f, const char *message, int *cursor, bool regress)
Definition: fe-trace.c:559
static void pqTraceOutput_GSSResponse(FILE *f, const char *message, int *cursor, int length, bool regress)
Definition: fe-trace.c:367
static void pqTraceOutput_FunctionCall(FILE *f, const char *message, int *cursor, bool regress)
Definition: fe-trace.c:403
static void pqTraceOutput_CopyInResponse(FILE *f, const char *message, int *cursor)
Definition: fe-trace.c:429
static void pqTraceOutput_BackendKeyData(FILE *f, const char *message, int *cursor, bool regress)
Definition: fe-trace.c:455
static void pqTraceOutput_Authentication(FILE *f, const char *message, int *cursor, int length, bool suppress)
Definition: fe-trace.c:484
static void pqTraceOutput_Parse(FILE *f, const char *message, int *cursor, bool regress)
Definition: fe-trace.c:463
static void pqTraceOutput_NoticeResponse(FILE *f, const char *message, int *cursor, bool regress)
Definition: fe-trace.c:346
static void pqTraceOutput_ParameterDescription(FILE *f, const char *message, int *cursor, bool regress)
Definition: fe-trace.c:547
static void pqTraceOutput_DataRow(FILE *f, const char *message, int *cursor)
Definition: fe-trace.c:293
static void pqTraceOutput_SASLResponse(FILE *f, const char *message, int *cursor, int length, bool regress)
Definition: fe-trace.c:395
static void pqTraceOutput_Query(FILE *f, const char *message, int *cursor)
Definition: fe-trace.c:477
static void pqTraceOutput_CopyData(FILE *f, const char *message, int *cursor, int length, bool suppress)
Definition: fe-trace.c:285
static void pqTraceOutput_SASLInitialResponse(FILE *f, const char *message, int *cursor, bool regress)
Definition: fe-trace.c:382
static void pqTraceOutput_NegotiateProtocolVersion(FILE *f, const char *message, int *cursor)
Definition: fe-trace.c:579
static void pqTraceOutput_CopyBothResponse(FILE *f, const char *message, int *cursor, int length)
Definition: fe-trace.c:598
static void pqTraceOutput_Bind(FILE *f, const char *message, int *cursor)
Definition: fe-trace.c:240
static void pqTraceOutput_ErrorResponse(FILE *f, const char *message, int *cursor, bool regress)
Definition: fe-trace.c:340
static void pqTraceOutput_Close(FILE *f, const char *message, int *cursor)
Definition: fe-trace.c:270
static void pqTraceOutput_Describe(FILE *f, const char *message, int *cursor)
Definition: fe-trace.c:311
static void pqTraceOutput_NotificationResponse(FILE *f, const char *message, int *cursor, bool regress)
Definition: fe-trace.c:231
static void pqTraceOutput_CommandComplete(FILE *f, const char *message, int *cursor)
Definition: fe-trace.c:278
static void pqTraceOutput_ParameterStatus(FILE *f, const char *message, int *cursor)
Definition: fe-trace.c:539
static void pqTraceOutput_Execute(FILE *f, const char *message, int *cursor, bool regress)
Definition: fe-trace.c:352
static void pqTraceOutput_CopyOutResponse(FILE *f, const char *message, int *cursor)
Definition: fe-trace.c:442
static void pqTraceOutput_ReadyForQuery(FILE *f, const char *message, int *cursor)
Definition: fe-trace.c:608
static void pqTraceOutput_CopyFail(FILE *f, const char *message, int *cursor)
Definition: fe-trace.c:360
static void pqTraceOutput_PasswordMessage(FILE *f, const char *message, int *cursor)
Definition: fe-trace.c:375
static void pqTraceOutput_FunctionCallResponse(FILE *f, const char *message, int *cursor)
Definition: fe-trace.c:587
#define PQTRACE_REGRESS_MODE
Definition: libpq-fe.h:468
#define AUTH_RESPONSE_PASSWORD
Definition: libpq-int.h:342
#define AUTH_RESPONSE_SASL
Definition: libpq-int.h:344
#define AUTH_RESPONSE_SASL_INITIAL
Definition: libpq-int.h:343
#define AUTH_RESPONSE_GSS
Definition: libpq-int.h:341
#define PqMsg_CloseComplete
Definition: protocol.h:40
#define PqMsg_CopyDone
Definition: protocol.h:64
#define PqMsg_NotificationResponse
Definition: protocol.h:41
#define PqMsg_BindComplete
Definition: protocol.h:39
#define PqMsg_CopyData
Definition: protocol.h:65
#define PqMsg_ParameterDescription
Definition: protocol.h:58
#define PqMsg_FunctionCall
Definition: protocol.h:23
#define PqMsg_GSSResponse
Definition: protocol.h:30
#define PqMsg_SASLResponse
Definition: protocol.h:33
#define PqMsg_Describe
Definition: protocol.h:21
#define PqMsg_FunctionCallResponse
Definition: protocol.h:53
#define PqMsg_SASLInitialResponse
Definition: protocol.h:32
#define PqMsg_ReadyForQuery
Definition: protocol.h:55
#define PqMsg_AuthenticationRequest
Definition: protocol.h:50
#define PqMsg_CopyInResponse
Definition: protocol.h:45
#define PqMsg_EmptyQueryResponse
Definition: protocol.h:47
#define PqMsg_RowDescription
Definition: protocol.h:52
#define PqMsg_CopyBothResponse
Definition: protocol.h:54
#define PqMsg_ParameterStatus
Definition: protocol.h:51
#define PqMsg_NoData
Definition: protocol.h:56
#define PqMsg_NegotiateProtocolVersion
Definition: protocol.h:59
#define PqMsg_PortalSuspended
Definition: protocol.h:57
#define PqMsg_Parse
Definition: protocol.h:25
#define PqMsg_Bind
Definition: protocol.h:19
#define PqMsg_PasswordMessage
Definition: protocol.h:31
#define PqMsg_Sync
Definition: protocol.h:27
#define PqMsg_CopyFail
Definition: protocol.h:29
#define PqMsg_Flush
Definition: protocol.h:24
#define PqMsg_BackendKeyData
Definition: protocol.h:48
#define PqMsg_CommandComplete
Definition: protocol.h:42
#define PqMsg_Query
Definition: protocol.h:26
#define PqMsg_ErrorResponse
Definition: protocol.h:44
#define PqMsg_DataRow
Definition: protocol.h:43
#define PqMsg_NoticeResponse
Definition: protocol.h:49
#define PqMsg_Terminate
Definition: protocol.h:28
#define PqMsg_Execute
Definition: protocol.h:22
#define PqMsg_Close
Definition: protocol.h:20
#define PqMsg_CopyOutResponse
Definition: protocol.h:46
#define PqMsg_ParseComplete
Definition: protocol.h:38
char current_auth_response
Definition: libpq-int.h:505

References Assert, AUTH_RESPONSE_GSS, AUTH_RESPONSE_PASSWORD, AUTH_RESPONSE_SASL, AUTH_RESPONSE_SASL_INITIAL, conn, pg_conn::current_auth_response, fprintf, pg_conn::Pfdebug, pg_ntoh32, PqMsg_AuthenticationRequest, PqMsg_BackendKeyData, PqMsg_Bind, PqMsg_BindComplete, PqMsg_Close, PqMsg_CloseComplete, PqMsg_CommandComplete, PqMsg_CopyBothResponse, PqMsg_CopyData, PqMsg_CopyDone, PqMsg_CopyFail, PqMsg_CopyInResponse, PqMsg_CopyOutResponse, PqMsg_DataRow, PqMsg_Describe, PqMsg_EmptyQueryResponse, PqMsg_ErrorResponse, PqMsg_Execute, PqMsg_Flush, PqMsg_FunctionCall, PqMsg_FunctionCallResponse, PqMsg_GSSResponse, PqMsg_NegotiateProtocolVersion, PqMsg_NoData, PqMsg_NoticeResponse, PqMsg_NotificationResponse, PqMsg_ParameterDescription, PqMsg_ParameterStatus, PqMsg_Parse, PqMsg_ParseComplete, PqMsg_PasswordMessage, PqMsg_PortalSuspended, PqMsg_Query, PqMsg_ReadyForQuery, PqMsg_RowDescription, PqMsg_SASLInitialResponse, PqMsg_SASLResponse, PqMsg_Sync, PqMsg_Terminate, PQTRACE_REGRESS_MODE, PQTRACE_SUPPRESS_TIMESTAMPS, pqTraceFormatTimestamp(), pqTraceOutput_Authentication(), pqTraceOutput_BackendKeyData(), pqTraceOutput_Bind(), pqTraceOutput_Close(), pqTraceOutput_CommandComplete(), pqTraceOutput_CopyBothResponse(), pqTraceOutput_CopyData(), pqTraceOutput_CopyFail(), pqTraceOutput_CopyInResponse(), pqTraceOutput_CopyOutResponse(), pqTraceOutput_DataRow(), pqTraceOutput_Describe(), pqTraceOutput_ErrorResponse(), pqTraceOutput_Execute(), pqTraceOutput_FunctionCall(), pqTraceOutput_FunctionCallResponse(), pqTraceOutput_GSSResponse(), pqTraceOutput_NegotiateProtocolVersion(), pqTraceOutput_NoticeResponse(), pqTraceOutput_NotificationResponse(), pqTraceOutput_ParameterDescription(), pqTraceOutput_ParameterStatus(), pqTraceOutput_Parse(), pqTraceOutput_PasswordMessage(), pqTraceOutput_Query(), pqTraceOutput_ReadyForQuery(), pqTraceOutput_RowDescription(), pqTraceOutput_SASLInitialResponse(), pqTraceOutput_SASLResponse(), and pg_conn::traceFlags.

Referenced by pg_password_sendauth(), pg_SASL_continue(), pg_SASL_init(), pqParseDone(), and pqPutMsgEnd().

◆ pqTraceOutputNchar()

static void pqTraceOutputNchar ( FILE *  pfdebug,
int  len,
const char *  data,
int *  cursor,
bool  suppress 
)
static

Definition at line 193 of file fe-trace.c.

194 {
195  int i,
196  next; /* first char not yet printed */
197  const char *v = data + *cursor;
198 
199  if (suppress)
200  {
201  fprintf(pfdebug, " 'BBBB'");
202  *cursor += len;
203  return;
204  }
205 
206  fprintf(pfdebug, " \'");
207 
208  for (next = i = 0; i < len; ++i)
209  {
210  if (isprint((unsigned char) v[i]))
211  continue;
212  else
213  {
214  fwrite(v + next, 1, i - next, pfdebug);
215  fprintf(pfdebug, "\\x%02x", v[i]);
216  next = i + 1;
217  }
218  }
219  if (next < len)
220  fwrite(v + next, 1, len - next, pfdebug);
221 
222  fprintf(pfdebug, "\'");
223  *cursor += len;
224 }
static int32 next
Definition: blutils.c:219

References data, fprintf, i, len, and next.

Referenced by pqTraceOutput_Authentication(), pqTraceOutput_Bind(), pqTraceOutput_CopyData(), pqTraceOutput_DataRow(), pqTraceOutput_FunctionCall(), pqTraceOutput_FunctionCallResponse(), pqTraceOutput_GSSResponse(), pqTraceOutput_SASLInitialResponse(), and pqTraceOutput_SASLResponse().

◆ pqTraceOutputNoTypeByteMessage()

void pqTraceOutputNoTypeByteMessage ( PGconn conn,
const char *  message 
)

Definition at line 835 of file fe-trace.c.

836 {
837  int length;
838  int version;
839  bool regress;
840  int logCursor = 0;
841 
842  regress = (conn->traceFlags & PQTRACE_REGRESS_MODE) != 0;
843 
845  {
846  char timestr[128];
847 
848  pqTraceFormatTimestamp(timestr, sizeof(timestr));
849  fprintf(conn->Pfdebug, "%s\t", timestr);
850  }
851 
852  memcpy(&length, message + logCursor, 4);
853  length = (int) pg_ntoh32(length);
854  logCursor += 4;
855 
856  fprintf(conn->Pfdebug, "F\t%d\t", length);
857 
858  if (length < 8)
859  {
860  fprintf(conn->Pfdebug, "Unknown message\n");
861  return;
862  }
863 
864  memcpy(&version, message + logCursor, 4);
865  version = (int) pg_ntoh32(version);
866 
867  if (version == CANCEL_REQUEST_CODE && length >= 16)
868  {
869  fprintf(conn->Pfdebug, "CancelRequest\t");
870  pqTraceOutputInt16(conn->Pfdebug, message, &logCursor);
871  pqTraceOutputInt16(conn->Pfdebug, message, &logCursor);
872  pqTraceOutputInt32(conn->Pfdebug, message, &logCursor, regress);
873  pqTraceOutputInt32(conn->Pfdebug, message, &logCursor, regress);
874  }
875  else if (version == NEGOTIATE_SSL_CODE)
876  {
877  fprintf(conn->Pfdebug, "SSLRequest\t");
878  pqTraceOutputInt16(conn->Pfdebug, message, &logCursor);
879  pqTraceOutputInt16(conn->Pfdebug, message, &logCursor);
880  }
881  else if (version == NEGOTIATE_GSS_CODE)
882  {
883  fprintf(conn->Pfdebug, "GSSENCRequest\t");
884  pqTraceOutputInt16(conn->Pfdebug, message, &logCursor);
885  pqTraceOutputInt16(conn->Pfdebug, message, &logCursor);
886  }
887  else
888  {
889  fprintf(conn->Pfdebug, "StartupMessage\t");
890  pqTraceOutputInt16(conn->Pfdebug, message, &logCursor);
891  pqTraceOutputInt16(conn->Pfdebug, message, &logCursor);
892  while (message[logCursor] != '\0')
893  {
894  /* XXX should we suppress anything in regress mode? */
895  pqTraceOutputString(conn->Pfdebug, message, &logCursor, false);
896  pqTraceOutputString(conn->Pfdebug, message, &logCursor, false);
897  }
898  }
899 
900  fputc('\n', conn->Pfdebug);
901 }
#define CANCEL_REQUEST_CODE
Definition: pqcomm.h:133
#define NEGOTIATE_GSS_CODE
Definition: pqcomm.h:168
#define NEGOTIATE_SSL_CODE
Definition: pqcomm.h:167

References CANCEL_REQUEST_CODE, conn, fprintf, NEGOTIATE_GSS_CODE, NEGOTIATE_SSL_CODE, pg_conn::Pfdebug, pg_ntoh32, PQTRACE_REGRESS_MODE, PQTRACE_SUPPRESS_TIMESTAMPS, pqTraceFormatTimestamp(), pqTraceOutputInt16(), pqTraceOutputInt32(), pqTraceOutputString(), and pg_conn::traceFlags.

Referenced by pqPutMsgEnd().

◆ pqTraceOutputNR()

static void pqTraceOutputNR ( FILE *  f,
const char *  type,
const char *  message,
int *  cursor,
bool  regress 
)
static

Definition at line 320 of file fe-trace.c.

322 {
323  fprintf(f, "%s\t", type);
324  for (;;)
325  {
326  char field;
327  bool suppress;
328 
329  pqTraceOutputByte1(f, message, cursor);
330  field = message[*cursor - 1];
331  if (field == '\0')
332  break;
333 
334  suppress = regress && (field == 'L' || field == 'F' || field == 'R');
335  pqTraceOutputString(f, message, cursor, suppress);
336  }
337 }
const char * type

References fprintf, pqTraceOutputByte1(), pqTraceOutputString(), and type.

Referenced by pqTraceOutput_ErrorResponse(), and pqTraceOutput_NoticeResponse().

◆ pqTraceOutputString()

static void pqTraceOutputString ( FILE *  pfdebug,
const char *  data,
int *  cursor,
bool  suppress 
)
static

Definition at line 166 of file fe-trace.c.

167 {
168  int len;
169 
170  if (suppress)
171  {
172  fprintf(pfdebug, " \"SSSS\"");
173  *cursor += strlen(data + *cursor) + 1;
174  }
175  else
176  {
177  len = fprintf(pfdebug, " \"%s\"", data + *cursor);
178 
179  /*
180  * This is a null-terminated string. So add 1 after subtracting 3
181  * which is the double quotes and space length from len.
182  */
183  *cursor += (len - 3 + 1);
184  }
185 }

References data, fprintf, and len.

Referenced by pqTraceOutput_Authentication(), pqTraceOutput_Bind(), pqTraceOutput_Close(), pqTraceOutput_CommandComplete(), pqTraceOutput_CopyFail(), pqTraceOutput_Describe(), pqTraceOutput_Execute(), pqTraceOutput_NotificationResponse(), pqTraceOutput_ParameterStatus(), pqTraceOutput_Parse(), pqTraceOutput_PasswordMessage(), pqTraceOutput_Query(), pqTraceOutput_RowDescription(), pqTraceOutput_SASLInitialResponse(), pqTraceOutputNoTypeByteMessage(), and pqTraceOutputNR().

◆ PQuntrace()

void PQuntrace ( PGconn conn)

Definition at line 49 of file fe-trace.c.

50 {
51  if (conn == NULL)
52  return;
53  if (conn->Pfdebug)
54  {
56  conn->Pfdebug = NULL;
57  }
58 
59  conn->traceFlags = 0;
60 }
static void const char fflush(stdout)

References conn, fflush(), pg_conn::Pfdebug, and pg_conn::traceFlags.

Referenced by PQtrace().