* Print the given message to the trace output stream. */
| 526 | * Print the given message to the trace output stream. |
| 527 | */ |
| 528 | void |
| 529 | pqTraceOutputMessage(PGconn *conn, const char *message, bool toServer) |
| 530 | { |
| 531 | char id; |
| 532 | int length; |
| 533 | char *prefix = toServer ? "F" : "B"; |
| 534 | int logCursor = 0; |
| 535 | bool regress; |
| 536 | |
| 537 | if ((conn->traceFlags & PQTRACE_SUPPRESS_TIMESTAMPS) == 0) |
| 538 | { |
| 539 | char timestr[128]; |
| 540 | |
| 541 | pqTraceFormatTimestamp(timestr, sizeof(timestr)); |
| 542 | fprintf(conn->Pfdebug, "%s\t", timestr); |
| 543 | } |
| 544 | regress = (conn->traceFlags & PQTRACE_REGRESS_MODE) != 0; |
| 545 | |
| 546 | id = message[logCursor++]; |
| 547 | |
| 548 | memcpy(&length, message + logCursor, 4); |
| 549 | length = (int) pg_ntoh32(length); |
| 550 | logCursor += 4; |
| 551 | |
| 552 | /* |
| 553 | * In regress mode, suppress the length of ErrorResponse and |
| 554 | * NoticeResponse. The F (file name), L (line number) and R (routine |
| 555 | * name) fields can change as server code is modified, and if their |
| 556 | * lengths differ from the originals, that would break tests. |
| 557 | */ |
| 558 | if (regress && !toServer && (id == 'E' || id == 'N')) |
| 559 | fprintf(conn->Pfdebug, "%s\tNN\t", prefix); |
| 560 | else |
| 561 | fprintf(conn->Pfdebug, "%s\t%d\t", prefix, length); |
| 562 | |
| 563 | switch (id) |
| 564 | { |
| 565 | case '1': |
| 566 | fprintf(conn->Pfdebug, "ParseComplete"); |
| 567 | /* No message content */ |
| 568 | break; |
| 569 | case '2': |
| 570 | fprintf(conn->Pfdebug, "BindComplete"); |
| 571 | /* No message content */ |
| 572 | break; |
| 573 | case '3': |
| 574 | fprintf(conn->Pfdebug, "CloseComplete"); |
| 575 | /* No message content */ |
| 576 | break; |
| 577 | case 'A': /* Notification Response */ |
| 578 | pqTraceOutputA(conn->Pfdebug, message, &logCursor, regress); |
| 579 | break; |
| 580 | case 'B': /* Bind */ |
| 581 | pqTraceOutputB(conn->Pfdebug, message, &logCursor); |
| 582 | break; |
| 583 | case 'c': |
| 584 | fprintf(conn->Pfdebug, "CopyDone"); |
| 585 | /* No message content */ |
no test coverage detected