Commits

Tuukka Norri committed 6b5cb96

Connection status codes for libpq and generic authentication panels (references #3)
- BXDatabaseContext now has some basic support for Keychain. This hasn't been tested yet.
- libpq now has an enum for connection errors. Currently it may be checked for an authentication error. This is an estimate, however; it would be safer that the server would send the status code.
- Added a header which I wrote before.
- BXNetServiceConnector will be persistent with the authentication panel from now on.

  • Participants
  • Parent commits a19df35
  • Branches PGTS

Comments (0)

Files changed (4)

Framework/Sources/PGTSConnection.h

 - (NSString *) commandLineOptions;
 - (ConnStatusType) connectionStatus;
 - (PGTransactionStatusType) transactionStatus;
+- (PGConnectionErrorCode) errorCode;
 - (NSString *) statusOfParameter: (NSString *) parameterName;
 - (int) protocolVersion;
 - (int) serverVersion;

Framework/Sources/PGTSConnection.m

 #endif
 }
 
+- (PGConnectionErrorCode) errorCode
+{
+	return PQerrorCode (connection);
+}
+
 @end
 
 

Framework/Sources/PGTSConnectionPrivate.m

             FD_SET (bsdSocket, &mask);
             selectStatus = 0;
             pollingStatus = pollFunction (connection);
-
+			
+			log4Debug (@"Polling status: %d connection status: %d", pollingStatus, PQstatus (connection));
 #ifdef USE_SSL
 			if (NO == sslSetUp && CONNECTION_SSL_CONTINUE == PQstatus (connection))
 			{
                     break;
 					
 				case PGRES_POLLING_ACTIVE:
+					//Select returns 0 on timeout
+					selectStatus = 1;
 					break;
                     
                 case PGRES_POLLING_READING:
                 NS_ENDHANDLER
         }
             connectionStatus = tempStatus;
-            log4Debug (@"ConnectionStatus: %d", connectionStatus);
             if (YES == allowKVO) [self didChangeValueForKey: @"connectionStatus"];
     }
 }

Framework/libpq.patch

  /*
   * A client can also send a cancel-current-operation request to the postmaster.
   * This is uglier than sending it directly to the client's backend, but it
+Binary files postgresql-8.2.3/src/interfaces/libpq/.fe-connect.c.swp and postgresql-8.2.3-tsnorri/src/interfaces/libpq/.fe-connect.c.swp differ
 diff -urN postgresql-8.2.3/src/interfaces/libpq/blibpqdll.def postgresql-8.2.3-tsnorri/src/interfaces/libpq/blibpqdll.def
 --- postgresql-8.2.3/src/interfaces/libpq/blibpqdll.def	2007-02-07 06:44:09.000000000 +0200
-+++ postgresql-8.2.3-tsnorri/src/interfaces/libpq/blibpqdll.def	2007-02-27 12:30:58.000000000 +0200
-@@ -137,6 +137,7 @@
++++ postgresql-8.2.3-tsnorri/src/interfaces/libpq/blibpqdll.def	2007-03-01 16:16:22.000000000 +0200
+@@ -137,6 +137,8 @@
      _PQdescribePortal          @ 134
      _PQsendDescribePrepared    @ 135
      _PQsendDescribePortal      @ 136
 +    _PQauthRequest             @ 137
++    _PQerrorCode               @ 138
  
  ; Aliases for MS compatible names
      PQconnectdb               = _PQconnectdb
-@@ -275,3 +276,4 @@
+@@ -275,3 +277,5 @@
      PQdescribePortal          = _PQdescribePortal
      PQsendDescribePrepared    = _PQsendDescribePrepared
      PQsendDescribePortal      = _PQsendDescribePortal
 +    PQauthRequest             = _PQauthRequest
++    PQerrorCode               = _PQerrorCode
 diff -urN postgresql-8.2.3/src/interfaces/libpq/exports.txt postgresql-8.2.3-tsnorri/src/interfaces/libpq/exports.txt
 --- postgresql-8.2.3/src/interfaces/libpq/exports.txt	2006-08-18 22:52:39.000000000 +0300
-+++ postgresql-8.2.3-tsnorri/src/interfaces/libpq/exports.txt	2007-02-27 12:30:58.000000000 +0200
-@@ -136,3 +136,4 @@
++++ postgresql-8.2.3-tsnorri/src/interfaces/libpq/exports.txt	2007-03-01 16:15:46.000000000 +0200
+@@ -136,3 +136,5 @@
  PQdescribePortal          134
  PQsendDescribePrepared    135
  PQsendDescribePortal      136
 +PQauthRequest             137
++PQerrorCode               138
 diff -urN postgresql-8.2.3/src/interfaces/libpq/fe-connect.c postgresql-8.2.3-tsnorri/src/interfaces/libpq/fe-connect.c
 --- postgresql-8.2.3/src/interfaces/libpq/fe-connect.c	2006-11-21 18:28:00.000000000 +0200
-+++ postgresql-8.2.3-tsnorri/src/interfaces/libpq/fe-connect.c	2007-02-27 19:01:30.000000000 +0200
++++ postgresql-8.2.3-tsnorri/src/interfaces/libpq/fe-connect.c	2007-03-01 16:28:44.000000000 +0200
 @@ -998,6 +998,8 @@
  
  			/* Special cases: proceed without waiting. */
  				{
  					/* We are done with authentication exchange */
  					conn->status = CONNECTION_AUTH_OK;
-@@ -1857,6 +1883,7 @@
+@@ -1725,6 +1751,8 @@
+ 					if (res->resultStatus != PGRES_FATAL_ERROR)
+ 						printfPQExpBuffer(&conn->errorMessage,
+ 										  libpq_gettext("unexpected message from server during startup\n"));
++                    else
++                        conn->errorCode = PGCONN_AUTH_FAILURE;
+ 
+ 					/*
+ 					 * if the resultStatus is FATAL, then conn->errorMessage
+@@ -1857,6 +1885,8 @@
  	conn->std_strings = false;	/* unless server says differently */
  	conn->verbosity = PQERRORS_DEFAULT;
  	conn->sock = -1;
 +    conn->areq = '\0';
++    conn->errorCode = PGCONN_NO_ERROR;
  #ifdef USE_SSL
  	conn->allow_ssl_try = true;
  	conn->wait_ssl_try = false;
-@@ -3492,6 +3519,12 @@
+@@ -3305,6 +3335,14 @@
+ 	return conn->status;
+ }
+ 
++PGConnectionErrorCode
++PQerrorCode(const PGconn *conn)
++{
++    if (!conn)
++        return PGCONN_NO_ERROR;
++    return conn->errorCode;
++}
++
+ PGTransactionStatusType
+ PQtransactionStatus(const PGconn *conn)
+ {
+@@ -3492,6 +3530,12 @@
  	return old;
  }
  
  #else
 diff -urN postgresql-8.2.3/src/interfaces/libpq/libpq-fe.h postgresql-8.2.3-tsnorri/src/interfaces/libpq/libpq-fe.h
 --- postgresql-8.2.3/src/interfaces/libpq/libpq-fe.h	2006-10-04 03:30:13.000000000 +0300
-+++ postgresql-8.2.3-tsnorri/src/interfaces/libpq/libpq-fe.h	2007-02-27 12:30:58.000000000 +0200
-@@ -53,7 +53,10 @@
++++ postgresql-8.2.3-tsnorri/src/interfaces/libpq/libpq-fe.h	2007-03-01 16:41:25.000000000 +0200
+@@ -53,11 +53,19 @@
  								 * backend startup. */
  	CONNECTION_SETENV,			/* Negotiating environment. */
  	CONNECTION_SSL_STARTUP,		/* Negotiating SSL. */
 +	CONNECTION_NEEDED,			/* Internal state: connect() needed */
 +    CONNECTION_SSL_CONTINUE,
 +    CONNECTION_AUTH_START
-+
  } ConnStatusType;
  
  typedef enum
-@@ -99,6 +102,20 @@
+ {
++    PGCONN_NO_ERROR = 0,
++    PGCONN_AUTH_FAILURE
++} PGConnectionErrorCode;
++
++typedef enum
++{
+ 	PGRES_POLLING_FAILED = 0,
+ 	PGRES_POLLING_READING,		/* These two indicate that one may	  */
+ 	PGRES_POLLING_WRITING,		/* use select before polling again.   */
+@@ -99,6 +107,20 @@
  	PQERRORS_VERBOSE			/* all the facts, ma'am */
  } PGVerbosity;
  
  /* PGconn encapsulates a connection to the backend.
   * The contents of this struct are not supposed to be known to applications.
   */
-@@ -265,6 +282,7 @@
+@@ -265,6 +287,8 @@
  extern int	PQbackendPID(const PGconn *conn);
  extern int	PQclientEncoding(const PGconn *conn);
  extern int	PQsetClientEncoding(PGconn *conn, const char *encoding);
 +extern AuthRequest PQauthRequest(PGconn *conn);
++extern PGConnectionErrorCode PQerrorCode(const PGconn *conn);
  
  /* Get the OpenSSL structure associated with a connection. Returns NULL for
   * unencrypted connections or if any other TLS library is in use. */
 diff -urN postgresql-8.2.3/src/interfaces/libpq/libpq-int.h postgresql-8.2.3-tsnorri/src/interfaces/libpq/libpq-int.h
 --- postgresql-8.2.3/src/interfaces/libpq/libpq-int.h	2006-10-04 03:30:13.000000000 +0300
-+++ postgresql-8.2.3-tsnorri/src/interfaces/libpq/libpq-int.h	2007-02-27 12:30:58.000000000 +0200
-@@ -310,6 +310,7 @@
++++ postgresql-8.2.3-tsnorri/src/interfaces/libpq/libpq-int.h	2007-03-01 16:38:13.000000000 +0200
+@@ -284,6 +284,7 @@
+ 
+ 	/* Status indicators */
+ 	ConnStatusType status;
++    PGConnectionErrorCode errorCode;
+ 	PGAsyncStatusType asyncStatus;
+ 	PGTransactionStatusType xactStatus; /* never changes to ACTIVE */
+ 	PGQueryClass queryclass;
+@@ -310,6 +311,7 @@
  	int			addrlist_family;	/* needed to know how to free addrlist */
  	PGSetenvStatusType setenv_state;	/* for 2.0 protocol only */
  	const PQEnvironmentOption *next_eo;
  
  	/* Miscellaneous stuff */
  	int			be_pid;			/* PID of backend --- needed for cancels */
-@@ -485,6 +486,7 @@
+@@ -485,6 +487,7 @@
  
  extern int	pqsecure_initialize(PGconn *);
  extern void pqsecure_destroy(void);
  extern ssize_t pqsecure_read(PGconn *, void *ptr, size_t len);
 diff -urN postgresql-8.2.3/src/interfaces/libpq/libpqddll.def postgresql-8.2.3-tsnorri/src/interfaces/libpq/libpqddll.def
 --- postgresql-8.2.3/src/interfaces/libpq/libpqddll.def	2007-02-07 06:44:09.000000000 +0200
-+++ postgresql-8.2.3-tsnorri/src/interfaces/libpq/libpqddll.def	2007-02-27 12:30:58.000000000 +0200
-@@ -137,3 +137,4 @@
++++ postgresql-8.2.3-tsnorri/src/interfaces/libpq/libpqddll.def	2007-03-01 16:16:58.000000000 +0200
+@@ -137,3 +137,5 @@
      PQdescribePortal          @ 134
      PQsendDescribePrepared    @ 135
      PQsendDescribePortal      @ 136
 +    PQauthRequest             @ 137
++    PQerrorCode               @ 138
 diff -urN postgresql-8.2.3/src/interfaces/libpq/libpqdll.def postgresql-8.2.3-tsnorri/src/interfaces/libpq/libpqdll.def
 --- postgresql-8.2.3/src/interfaces/libpq/libpqdll.def	2007-02-07 06:44:09.000000000 +0200
-+++ postgresql-8.2.3-tsnorri/src/interfaces/libpq/libpqdll.def	2007-02-27 12:30:58.000000000 +0200
-@@ -137,3 +137,4 @@
++++ postgresql-8.2.3-tsnorri/src/interfaces/libpq/libpqdll.def	2007-03-01 16:17:11.000000000 +0200
+@@ -137,3 +137,5 @@
      PQdescribePortal          @ 134
      PQsendDescribePrepared    @ 135
      PQsendDescribePortal      @ 136
 +    PQauthRequest             @ 137
++    PQerrorCode               @ 138