startup.c 14.8 KB
Newer Older
P
Peter Eisentraut 已提交
1 2 3
/*
 * psql - the PostgreSQL interactive terminal
 *
P
Peter Eisentraut 已提交
4
 * Copyright 2000 by PostgreSQL Global Development Group
P
Peter Eisentraut 已提交
5
 *
6
 * $Header: /cvsroot/pgsql/src/bin/psql/startup.c,v 1.49 2001/05/30 14:15:27 momjian Exp $
P
Peter Eisentraut 已提交
7
 */
8
#include "postgres_fe.h"
9 10 11

#include <sys/types.h>

12 13
#ifndef WIN32
#include <unistd.h>
14
#else							/* WIN32 */
15
#include <io.h>
B
Hi!  
Bruce Momjian 已提交
16
#include <windows.h>
17
#include <win32.h>
18
#endif	 /* WIN32 */
19 20 21 22 23

#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif

24
#include "libpq-fe.h"
25 26 27

#include "command.h"
#include "common.h"
28 29
#include "describe.h"
#include "help.h"
30
#include "input.h"
31
#include "mainloop.h"
32
#include "print.h"
33 34
#include "settings.h"
#include "variables.h"
35

36 37 38 39 40 41 42
#ifdef MULTIBYTE
#include "mb/pg_wchar.h"
#else
/* XXX Grand unified hard-coded badness; this should go into libpq */
#define pg_encoding_to_char(x) "SQL_ASCII"
#endif

43 44 45
/*
 * Global psql options
 */
46
PsqlSettings pset;
47 48


49 50
/*
 * Structures to pass information between the option parsing routine
51 52
 * and the main function
 */
B
Bruce Momjian 已提交
53 54 55 56 57 58 59
enum _actions
{
	ACT_NOTHING = 0,
	ACT_SINGLE_SLASH,
	ACT_LIST_DB,
	ACT_SINGLE_QUERY,
	ACT_FILE
60 61
};

B
Bruce Momjian 已提交
62 63 64 65 66 67 68 69 70
struct adhoc_opts
{
	char	   *dbname;
	char	   *host;
	char	   *port;
	char	   *username;
	enum _actions action;
	char	   *action_string;
	bool		no_readline;
71
	bool		no_psqlrc;
72 73 74
};

static void
75
			parse_psql_options(int argc, char *argv[], struct adhoc_opts * options);
76

77
static void
78
			process_psqlrc(void);
79 80

static void
81
			showVersion(void);
82

B
Bruce Momjian 已提交
83 84
#ifdef USE_SSL
static void
B
Bruce Momjian 已提交
85 86
			printSSLInfo(void);

B
Bruce Momjian 已提交
87
#endif
88

89 90 91

/*
 *
92
 * main
93 94 95
 *
 */
int
96
main(int argc, char *argv[])
97
{
B
Bruce Momjian 已提交
98 99
	struct adhoc_opts options;
	int			successResult;
100

B
Bruce Momjian 已提交
101 102 103
	char	   *username = NULL;
	char	   *password = NULL;
	bool		need_pass;
104

105
	if (!strrchr(argv[0], '/'))
106 107
		pset.progname = argv[0];
	else
108
		pset.progname = strrchr(argv[0], '/') + 1;
109

110 111
	if (argc > 1)
	{
B
Bruce Momjian 已提交
112
		if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
113 114 115 116
		{
			usage();
			exit(EXIT_SUCCESS);
		}
B
Bruce Momjian 已提交
117
		if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
118 119 120 121
		{
			showVersion();
			exit(EXIT_SUCCESS);
		}
B
Bruce Momjian 已提交
122
	}
123

124 125
	pset.cur_cmd_source = stdin;
	pset.cur_cmd_interactive = false;
126
	pset.encoding = PQenv2encoding();
127

128
	pset.vars = CreateVariableSpace();
129 130 131 132 133
	if (!pset.vars)
	{
		fprintf(stderr, "%s: out of memory\n", pset.progname);
		exit(EXIT_FAILURE);
	}
134 135 136
	pset.popt.topt.format = PRINT_ALIGNED;
	pset.queryFout = stdout;
	pset.popt.topt.border = 1;
P
Peter Eisentraut 已提交
137
	pset.popt.topt.pager = true;
138
	pset.popt.default_footer = true;
139

140
	SetVariable(pset.vars, "VERSION", PG_VERSION_STR);
141

142
	pset.notty = (!isatty(fileno(stdin)) || !isatty(fileno(stdout)));
143

144
	/* This is obsolete and should be removed sometime. */
145
#ifdef PSQL_ALWAYS_GET_PASSWORDS
146
	pset.getPassword = true;
147
#else
148
	pset.getPassword = false;
149 150
#endif

151
	parse_psql_options(argc, argv, &options);
152

153 154 155 156
	if (!pset.popt.topt.fieldSep)
		pset.popt.topt.fieldSep = xstrdup(DEFAULT_FIELD_SEP);
	if (!pset.popt.topt.recordSep)
		pset.popt.topt.recordSep = xstrdup(DEFAULT_RECORD_SEP);
157

B
Bruce Momjian 已提交
158 159
	if (options.username)
	{
160 161 162 163 164 165

		/*
		 * The \001 is a hack to support the deprecated -u option which
		 * issues a username prompt. The recommended option is -U followed
		 * by the name on the command line.
		 */
166
		if (strcmp(options.username, "\001") == 0)
B
Bruce Momjian 已提交
167 168 169
			username = simple_prompt("Username: ", 100, true);
		else
			username = strdup(options.username);
170 171
	}

172
	if (pset.getPassword)
B
Bruce Momjian 已提交
173
		password = simple_prompt("Password: ", 100, false);
174

B
Bruce Momjian 已提交
175 176 177 178
	/* loop until we have a password if requested by backend */
	do
	{
		need_pass = false;
179
		pset.db = PQsetdbLogin(options.host, options.port, NULL, NULL,
180 181
			options.action == ACT_LIST_DB ? "template1" : options.dbname,
							   username, password);
B
Bruce Momjian 已提交
182

183
		if (PQstatus(pset.db) == CONNECTION_BAD &&
184 185
			strcmp(PQerrorMessage(pset.db), "fe_sendauth: no password supplied\n") == 0 &&
			!feof(stdin))
B
Bruce Momjian 已提交
186
		{
187
			PQfinish(pset.db);
B
Bruce Momjian 已提交
188 189 190 191 192 193
			need_pass = true;
			free(password);
			password = NULL;
			password = simple_prompt("Password: ", 100, false);
		}
	} while (need_pass);
194

B
Bruce Momjian 已提交
195 196 197
	free(username);
	free(password);

198
	if (PQstatus(pset.db) == CONNECTION_BAD)
B
Bruce Momjian 已提交
199
	{
200
		fprintf(stderr, "%s: %s", pset.progname, PQerrorMessage(pset.db));
201
		PQfinish(pset.db);
B
Bruce Momjian 已提交
202 203 204
		exit(EXIT_BADCONN);
	}

205 206 207 208 209 210 211
	PQsetNoticeProcessor(pset.db, NoticeProcessor, NULL);

	/*
	 * We need to save the encoding because we want to have it available
	 * even if the database connection goes bad.
	 */
	pset.encoding = PQclientEncoding(pset.db);
P
Peter Eisentraut 已提交
212

B
Bruce Momjian 已提交
213 214
	if (options.action == ACT_LIST_DB)
	{
215
		int			success = listAllDbs(false);
B
Bruce Momjian 已提交
216

217
		PQfinish(pset.db);
218
		exit(success ? EXIT_SUCCESS : EXIT_FAILURE);
B
Bruce Momjian 已提交
219 220
	}

221 222 223 224 225
	SetVariable(pset.vars, "DBNAME", PQdb(pset.db));
	SetVariable(pset.vars, "USER", PQuser(pset.db));
	SetVariable(pset.vars, "HOST", PQhost(pset.db));
	SetVariable(pset.vars, "PORT", PQport(pset.db));
	SetVariable(pset.vars, "ENCODING", pg_encoding_to_char(pset.encoding));
226

227
	/*
228 229
	 * Now find something to do
	 */
B
Bruce Momjian 已提交
230

231
	/*
232 233
	 * process file given by -f
	 */
234
	if (options.action == ACT_FILE && strcmp(options.action_string, "-")!=0)
235 236 237
	{
		if (!options.no_psqlrc)
			process_psqlrc();
238

239
		successResult = process_file(options.action_string);
240 241
	}

242
	/*
243 244
	 * process slash command if one was given to -c
	 */
B
Bruce Momjian 已提交
245
	else if (options.action == ACT_SINGLE_SLASH)
246 247
	{
		const char *value;
248

249 250
		if ((value = GetVariable(pset.vars, "ECHO")) && strcmp(value, "all") == 0)
			puts(options.action_string);
251
		successResult = HandleSlashCmds(options.action_string, NULL, NULL) != CMD_ERROR
252 253 254
			? EXIT_SUCCESS : EXIT_FAILURE;
	}

255
	/*
256 257
	 * If the query given to -c was a normal one, send it
	 */
B
Bruce Momjian 已提交
258
	else if (options.action == ACT_SINGLE_QUERY)
259 260
	{
		const char *value;
261

262 263
		if ((value = GetVariable(pset.vars, "ECHO")) && strcmp(value, "all") == 0)
			puts(options.action_string);
264
		successResult = SendQuery(options.action_string)
265 266 267
			? EXIT_SUCCESS : EXIT_FAILURE;
	}

268
	/*
269 270
	 * or otherwise enter interactive main loop
	 */
B
Bruce Momjian 已提交
271
	else
272 273 274 275 276 277 278 279
	{
		pset.issuper = test_superuser(PQuser(pset.db));
		if (!QUIET() && !pset.notty)
		{
			printf("Welcome to %s, the PostgreSQL interactive terminal.\n\n"
				   "Type:  \\copyright for distribution terms\n"
				   "       \\h for help with SQL commands\n"
				   "       \\? for help on internal slash commands\n"
B
Bruce Momjian 已提交
280
			  "       \\g or terminate with semicolon to execute query\n"
281
				   "       \\q to quit\n\n", pset.progname);
B
Bruce Momjian 已提交
282
#ifdef USE_SSL
283
			printSSLInfo();
B
Bruce Momjian 已提交
284
#endif
285 286
		}

287 288 289 290 291 292 293
		SetVariable(pset.vars, "PROMPT1", DEFAULT_PROMPT1);
		SetVariable(pset.vars, "PROMPT2", DEFAULT_PROMPT2);
		SetVariable(pset.vars, "PROMPT3", DEFAULT_PROMPT3);
		if (!options.no_psqlrc)
			process_psqlrc();
		if (!pset.notty)
			initializeInput(options.no_readline ? 0 : 1);
294 295
		if (options.action_string) /* -f - was used */
			pset.inputfile = "<stdin>";
P
Peter Eisentraut 已提交
296
		successResult = MainLoop(stdin);
297
	}
B
Bruce Momjian 已提交
298 299

	/* clean up */
300 301
	PQfinish(pset.db);
	setQFout(NULL);
B
Bruce Momjian 已提交
302 303

	return successResult;
304 305 306 307 308 309 310 311 312 313
}



/*
 * Parse command line options
 */

#ifdef WIN32
/* getopt is not in the standard includes on Win32 */
B
Bruce Momjian 已提交
314
int			getopt(int, char *const[], const char *);
315

B
Hi!  
Bruce Momjian 已提交
316
/* And it requires progname to be set */
317 318
char	   *__progname = "psql";

319 320 321
#endif

static void
322
parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
323 324
{
#ifdef HAVE_GETOPT_LONG
325
	static struct option long_options[] =
326 327
	{
		{"echo-all", no_argument, NULL, 'a'},
B
Bruce Momjian 已提交
328 329 330
		{"no-align", no_argument, NULL, 'A'},
		{"command", required_argument, NULL, 'c'},
		{"dbname", required_argument, NULL, 'd'},
331
		{"echo-queries", no_argument, NULL, 'e'},
332
		{"echo-hidden", no_argument, NULL, 'E'},
B
Bruce Momjian 已提交
333
		{"file", required_argument, NULL, 'f'},
334
		{"field-separator", required_argument, NULL, 'F'},
B
Bruce Momjian 已提交
335 336 337
		{"host", required_argument, NULL, 'h'},
		{"html", no_argument, NULL, 'H'},
		{"list", no_argument, NULL, 'l'},
338
		{"no-readline", no_argument, NULL, 'n'},
339
		{"output", required_argument, NULL, 'o'},
B
Bruce Momjian 已提交
340 341 342
		{"port", required_argument, NULL, 'p'},
		{"pset", required_argument, NULL, 'P'},
		{"quiet", no_argument, NULL, 'q'},
343
		{"record-separator", required_argument, NULL, 'R'},
B
Bruce Momjian 已提交
344 345 346 347 348 349 350 351 352
		{"single-step", no_argument, NULL, 's'},
		{"single-line", no_argument, NULL, 'S'},
		{"tuples-only", no_argument, NULL, 't'},
		{"table-attr", required_argument, NULL, 'T'},
		{"username", required_argument, NULL, 'U'},
		{"set", required_argument, NULL, 'v'},
		{"variable", required_argument, NULL, 'v'},
		{"version", no_argument, NULL, 'V'},
		{"password", no_argument, NULL, 'W'},
353
		{"expanded", no_argument, NULL, 'x'},
354
		{"no-psqlrc", no_argument, NULL, 'X'},
B
Bruce Momjian 已提交
355 356 357 358
		{"help", no_argument, NULL, '?'},
	};

	int			optindex;
359 360

#endif	 /* HAVE_GETOPT_LONG */
361

B
Bruce Momjian 已提交
362 363 364
	extern char *optarg;
	extern int	optind;
	int			c;
365
	bool		used_old_u_option = false;
366

367
	memset(options, 0, sizeof *options);
368 369

#ifdef HAVE_GETOPT_LONG
370
	while ((c = getopt_long(argc, argv, "aAc:d:eEf:F:h:Hlno:p:P:qR:sStT:uU:v:VWxX?", long_options, &optindex)) != -1)
371 372
#else							/* not HAVE_GETOPT_LONG */

B
Bruce Momjian 已提交
373 374 375 376
	/*
	 * Be sure to leave the '-' in here, so we can catch accidental long
	 * options.
	 */
377
	while ((c = getopt(argc, argv, "aAc:d:eEf:F:h:Hlno:p:P:qR:sStT:uU:v:VWxX?-")) != -1)
378
#endif	 /* not HAVE_GETOPT_LONG */
379
	{
B
Bruce Momjian 已提交
380 381
		switch (c)
		{
382 383 384
			case 'a':
				SetVariable(pset.vars, "ECHO", "all");
				break;
B
Bruce Momjian 已提交
385
			case 'A':
386
				pset.popt.topt.format = PRINT_UNALIGNED;
B
Bruce Momjian 已提交
387 388 389 390
				break;
			case 'c':
				options->action_string = optarg;
				if (optarg[0] == '\\')
P
Peter Eisentraut 已提交
391
				{
B
Bruce Momjian 已提交
392
					options->action = ACT_SINGLE_SLASH;
P
Peter Eisentraut 已提交
393 394
					options->action_string++;
				}
B
Bruce Momjian 已提交
395 396 397 398 399 400 401
				else
					options->action = ACT_SINGLE_QUERY;
				break;
			case 'd':
				options->dbname = optarg;
				break;
			case 'e':
402
				SetVariable(pset.vars, "ECHO", "queries");
B
Bruce Momjian 已提交
403 404
				break;
			case 'E':
405
				SetVariableBool(pset.vars, "ECHO_HIDDEN");
B
Bruce Momjian 已提交
406 407 408 409 410 411
				break;
			case 'f':
				options->action = ACT_FILE;
				options->action_string = optarg;
				break;
			case 'F':
412
				pset.popt.topt.fieldSep = xstrdup(optarg);
B
Bruce Momjian 已提交
413 414 415 416 417
				break;
			case 'h':
				options->host = optarg;
				break;
			case 'H':
418
				pset.popt.topt.format = PRINT_HTML;
B
Bruce Momjian 已提交
419 420 421 422 423 424 425 426
				break;
			case 'l':
				options->action = ACT_LIST_DB;
				break;
			case 'n':
				options->no_readline = true;
				break;
			case 'o':
427
				setQFout(optarg);
B
Bruce Momjian 已提交
428 429 430 431 432 433 434 435 436 437 438 439 440
				break;
			case 'p':
				options->port = optarg;
				break;
			case 'P':
				{
					char	   *value;
					char	   *equal_loc;
					bool		result;

					value = xstrdup(optarg);
					equal_loc = strchr(value, '=');
					if (!equal_loc)
441
						result = do_pset(value, NULL, &pset.popt, true);
B
Bruce Momjian 已提交
442 443 444
					else
					{
						*equal_loc = '\0';
445
						result = do_pset(value, equal_loc + 1, &pset.popt, true);
B
Bruce Momjian 已提交
446 447 448 449
					}

					if (!result)
					{
450
						fprintf(stderr, "%s: couldn't set printing parameter %s\n", pset.progname, value);
B
Bruce Momjian 已提交
451 452 453 454 455 456 457
						exit(EXIT_FAILURE);
					}

					free(value);
					break;
				}
			case 'q':
458
				SetVariableBool(pset.vars, "QUIET");
B
Bruce Momjian 已提交
459
				break;
460 461 462
			case 'R':
				pset.popt.topt.recordSep = xstrdup(optarg);
				break;
B
Bruce Momjian 已提交
463
			case 's':
464
				SetVariableBool(pset.vars, "SINGLESTEP");
B
Bruce Momjian 已提交
465 466
				break;
			case 'S':
467
				SetVariableBool(pset.vars, "SINGLELINE");
B
Bruce Momjian 已提交
468 469
				break;
			case 't':
470
				pset.popt.topt.tuples_only = true;
B
Bruce Momjian 已提交
471 472
				break;
			case 'T':
473
				pset.popt.topt.tableAttr = xstrdup(optarg);
B
Bruce Momjian 已提交
474 475
				break;
			case 'u':
476
				pset.getPassword = true;
477 478 479 480
				options->username = "\001";		/* hopefully nobody has
												 * that username */
				/* this option is out */
				used_old_u_option = true;
B
Bruce Momjian 已提交
481 482 483 484 485 486 487 488 489 490 491 492 493
				break;
			case 'U':
				options->username = optarg;
				break;
			case 'v':
				{
					char	   *value;
					char	   *equal_loc;

					value = xstrdup(optarg);
					equal_loc = strchr(value, '=');
					if (!equal_loc)
					{
494
						if (!DeleteVariable(pset.vars, value))
B
Bruce Momjian 已提交
495
						{
496
							fprintf(stderr, "%s: could not delete variable %s\n",
497
									pset.progname, value);
B
Bruce Momjian 已提交
498 499 500 501 502 503
							exit(EXIT_FAILURE);
						}
					}
					else
					{
						*equal_loc = '\0';
504
						if (!SetVariable(pset.vars, value, equal_loc + 1))
B
Bruce Momjian 已提交
505
						{
506
							fprintf(stderr, "%s: could not set variable %s\n",
507
									pset.progname, value);
B
Bruce Momjian 已提交
508 509 510 511 512 513 514 515
							exit(EXIT_FAILURE);
						}
					}

					free(value);
					break;
				}
			case 'V':
516 517
				showVersion();
				exit(EXIT_SUCCESS);
B
Bruce Momjian 已提交
518
			case 'W':
519
				pset.getPassword = true;
B
Bruce Momjian 已提交
520
				break;
521 522 523
			case 'x':
				pset.popt.topt.expanded = true;
				break;
524 525 526
			case 'X':
				options->no_psqlrc = true;
				break;
B
Bruce Momjian 已提交
527
			case '?':
528 529 530 531 532 533 534 535 536
				/* Actual help option given */
				if (strcmp(argv[optind - 1], "-?") == 0 || strcmp(argv[optind - 1], "--help") == 0)
				{
					usage();
					exit(EXIT_SUCCESS);
				}
				/* unknown option reported by getopt */
				else
				{
537 538
					fprintf(stderr, "Try '%s --help' for more information.\n",
							pset.progname);
539
					exit(EXIT_FAILURE);
540
				}
B
Bruce Momjian 已提交
541
				break;
542
#ifndef HAVE_GETOPT_LONG
B
Bruce Momjian 已提交
543
			case '-':
544
				fprintf(stderr, "%s was compiled without support for long options.\n"
545
						"Use --help for help on invocation options.\n", pset.progname);
B
Bruce Momjian 已提交
546 547
				exit(EXIT_FAILURE);
				break;
548
#endif
B
Bruce Momjian 已提交
549
			default:
550 551
				fprintf(stderr, "Try '%s --help' for more information.\n",
						pset.progname);
552
				exit(EXIT_FAILURE);
B
Bruce Momjian 已提交
553 554
				break;
		}
555 556
	}

B
Bruce Momjian 已提交
557 558 559 560 561 562 563 564 565 566
	/*
	 * if we still have arguments, use it as the database name and
	 * username
	 */
	while (argc - optind >= 1)
	{
		if (!options->dbname)
			options->dbname = argv[optind];
		else if (!options->username)
			options->username = argv[optind];
567
		else if (!QUIET())
568
			fprintf(stderr, "%s: warning: extra option %s ignored\n",
569
					pset.progname, argv[optind]);
B
Bruce Momjian 已提交
570 571 572

		optind++;
	}
573

574 575
	if (used_old_u_option && !QUIET())
		fprintf(stderr, "%s: Warning: The -u option is deprecated. Use -U.\n", pset.progname);
576

577 578 579 580 581
}



/*
P
Peter Eisentraut 已提交
582
 * Load .psqlrc file, if found.
583 584
 */
static void
585
process_psqlrc(void)
586
{
B
Bruce Momjian 已提交
587 588
	char	   *psqlrc;
	char	   *home;
589 590 591 592 593

#ifdef WIN32
#define R_OK 0
#endif

B
Bruce Momjian 已提交
594 595
	/* Look for one in the home dir */
	home = getenv("HOME");
596

B
Bruce Momjian 已提交
597 598
	if (home)
	{
599
		psqlrc = malloc(strlen(home) + 20);
B
Bruce Momjian 已提交
600 601
		if (!psqlrc)
		{
602
			fprintf(stderr, "%s: out of memory\n", pset.progname);
B
Bruce Momjian 已提交
603 604
			exit(EXIT_FAILURE);
		}
605

606
		sprintf(psqlrc, "%s/.psqlrc-" PG_VERSION, home);
B
Bruce Momjian 已提交
607
		if (access(psqlrc, R_OK) == 0)
P
Peter Eisentraut 已提交
608
			process_file(psqlrc);
B
Bruce Momjian 已提交
609 610 611 612
		else
		{
			sprintf(psqlrc, "%s/.psqlrc", home);
			if (access(psqlrc, R_OK) == 0)
P
Peter Eisentraut 已提交
613
				process_file(psqlrc);
B
Bruce Momjian 已提交
614 615
		}
		free(psqlrc);
616 617 618 619 620 621 622
	}
}



/* showVersion
 *
623
 * This output format is intended to match GNU standards.
624 625
 */
static void
626
showVersion(void)
627
{
628
	puts("psql (PostgreSQL) " PG_VERSION);
629

630
#if defined(USE_READLINE) || defined (USE_HISTORY) || defined(MULTIBYTE)
631
	fputs("contains ", stdout);
632 633

#ifdef USE_READLINE
634
	fputs("readline", stdout);
635
#define _Feature
636
#endif
637

638
#ifdef USE_HISTORY
639
#ifdef _Feature
640
	fputs(", ", stdout);
641 642
#else
#define _Feature
643
#endif
644
	fputs("history", stdout);
645
#endif
646 647 648

#ifdef MULTIBYTE
#ifdef _Feature
649
	fputs(", ", stdout);
650 651
#else
#define _Feature
652
#endif
653
	fputs("multibyte", stdout);
654
#endif
655

656
#undef _Feature
657

658
	puts(" support");
659
#endif
660

661
	puts("Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group");
662 663 664
	puts("Portions Copyright (c) 1996 Regents of the University of California");
	puts("Read the file COPYRIGHT or use the command \\copyright to see the");
	puts("usage and distribution terms.");
665
}
B
Bruce Momjian 已提交
666 667 668 669 670 671 672 673 674



/*
 * printSSLInfo
 *
 * Prints information about the current SSL connection, if SSL is in use
 */
#ifdef USE_SSL
B
Bruce Momjian 已提交
675
static void
B
Bruce Momjian 已提交
676 677
printSSLInfo(void)
{
B
Bruce Momjian 已提交
678 679
	int			sslbits = -1;
	SSL		   *ssl;
B
Bruce Momjian 已提交
680 681 682

	ssl = PQgetssl(pset.db);
	if (!ssl)
B
Bruce Momjian 已提交
683
		return;					/* no SSL */
B
Bruce Momjian 已提交
684 685 686

	SSL_get_cipher_bits(ssl, &sslbits);
	printf("SSL enabled connection. Chiper: %s, bits: %i\n\n",
B
Bruce Momjian 已提交
687
		   SSL_get_cipher(ssl), sslbits);
B
Bruce Momjian 已提交
688
}
B
Bruce Momjian 已提交
689

B
Bruce Momjian 已提交
690
#endif