1
1
package org.postgresql;
2
2
3
+ import java.io.*;
3
4
import java.sql.*;
4
5
import java.util.*;
5
6
@@ -66,15 +67,17 @@ public class Driver implements java.sql.Driver
66
67
*
67
68
* user - (optional) The user to connect as
68
69
* password - (optional) The password for the user
70
+ * ssl - (optional) Use SSL when connecting to the server
69
71
* charSet - (optional) The character set to be used for converting
70
72
* to/from the database to unicode. If multibyte is enabled on the
71
73
* server then the character set of the database is used as the default,
72
74
* otherwise the jvm character encoding is used as the default.
73
- * loglevel - (optional) Enable logging of messages from the driver.
74
- * The value is an integer from 1 to 2 where:
75
- * INFO = 1, DEBUG = 2
76
- * The output is sent to DriverManager.getPrintWriter() if set,
77
- * otherwise it is sent to System.out.
75
+ * This value is only used when connecting to a 7.2 or older server.
76
+ * loglevel - (optional) Enable logging of messages from the driver.
77
+ * The value is an integer from 1 to 2 where:
78
+ * INFO = 1, DEBUG = 2
79
+ * The output is sent to DriverManager.getPrintWriter() if set,
80
+ * otherwise it is sent to System.out.
78
81
* compatible - (optional) This is used to toggle
79
82
* between different functionality as it changes across different releases
80
83
* of the jdbc driver code. The values here are versions of the jdbc
@@ -136,8 +139,9 @@ public class Driver implements java.sql.Driver
136
139
}
137
140
catch (Exception ex2)
138
141
{
139
- if (Driver.logDebug)
142
+ if (Driver.logDebug) {
140
143
Driver.debug("error", ex2);
144
+ }
141
145
throw new PSQLException("postgresql.unusual", ex2);
142
146
}
143
147
}
@@ -211,7 +215,7 @@ public class Driver implements java.sql.Driver
211
215
*/
212
216
public static String getVersion()
213
217
{
214
- return "@VERSION@ jdbc driver build " + m_buildNumber;
218
+ return "@VERSION@ ( build " + m_buildNumber + ")" ;
215
219
}
216
220
217
221
/*
@@ -248,7 +252,17 @@ public class Driver implements java.sql.Driver
248
252
String key = "";
249
253
String value = "";
250
254
251
- StringTokenizer st = new StringTokenizer(url, ":/;=&?", true);
255
+ String l_urlServer = url;
256
+ String l_urlArgs = "";
257
+
258
+ int l_qPos = url.indexOf('?');
259
+ if (l_qPos != -1) {
260
+ l_urlServer = url.substring(0,l_qPos);
261
+ l_urlArgs = url.substring(l_qPos+1);
262
+ }
263
+
264
+ //parse the server part of the url
265
+ StringTokenizer st = new StringTokenizer(l_urlServer, ":/", true);
252
266
for (int count = 0; (st.hasMoreTokens()); count++)
253
267
{
254
268
String token = st.nextToken();
@@ -318,25 +332,19 @@ public class Driver implements java.sql.Driver
318
332
urlProps.put("PGDBNAME", token);
319
333
state = -2;
320
334
}
321
- else if (state <= -2 && (count % 2) == 1)
322
- {
323
- // PM Aug 2 1997 - added tests for ? and &
324
- if (token.equals(";") || token.equals("?") || token.equals("&") )
325
- state = -3;
326
- else if (token.equals("="))
327
- state = -5;
328
- }
329
- else if (state <= -2 && (count % 2) == 0)
330
- {
331
- if (state == -3)
332
- key = token;
333
- else if (state == -5)
334
- {
335
- value = token;
336
- urlProps.put(key, value);
337
- state = -2;
338
- }
339
- }
335
+ }
336
+ }
337
+
338
+ //parse the args part of the url
339
+ StringTokenizer qst = new StringTokenizer(l_urlArgs, "&");
340
+ for (int count = 0; (qst.hasMoreTokens()); count++)
341
+ {
342
+ String token = qst.nextToken();
343
+ int l_pos = token.indexOf('=');
344
+ if (l_pos == -1) {
345
+ urlProps.put(token, "");
346
+ } else {
347
+ urlProps.put(token.substring(0,l_pos), token.substring(l_pos+1));
340
348
}
341
349
}
342
350
@@ -419,7 +427,10 @@ public class Driver implements java.sql.Driver
419
427
{
420
428
if (logDebug)
421
429
{
422
- DriverManager.println(msg + ex != null ? ex.getMessage() : "null Exception");
430
+ DriverManager.println(msg);
431
+ if(ex != null) {
432
+ DriverManager.println(ex.toString());
433
+ }
423
434
}
424
435
}
425
436
/*
@@ -441,10 +452,30 @@ public class Driver implements java.sql.Driver
441
452
{
442
453
if (logInfo)
443
454
{
444
- DriverManager.println(msg + ex != null ? ex.getMessage() : "null Exception");
455
+ DriverManager.println(msg);
456
+ if(ex != null) {
457
+ DriverManager.println(ex.toString());
458
+ }
445
459
}
446
460
}
447
461
462
+
463
+ public static void makeSSL(PG_Stream p_stream) throws IOException {
464
+ @SSL@ if (logDebug)
465
+ @SSL@ debug("converting regular socket connection to ssl");
466
+ @SSL@ javax.net.ssl.SSLSocketFactory factory = (javax.net.ssl.SSLSocketFactory) javax.net.ssl.SSLSocketFactory.getDefault();
467
+ @SSL@ p_stream.connection = (javax.net.ssl.SSLSocket) factory.createSocket(p_stream.connection,p_stream.host,p_stream.port,true);
468
+ @SSL@ p_stream.pg_input = new BufferedInputStream(p_stream.connection.getInputStream(), 8192);
469
+ @SSL@ p_stream.pg_output = new BufferedOutputStream(p_stream.connection.getOutputStream(), 8192);
470
+ }
471
+
472
+ public static boolean sslEnabled() {
473
+ boolean l_return = false;
474
+ @SSL@ l_return = true;
475
+ return l_return;
476
+ }
477
+
478
+
448
479
//The build number should be incremented for every new build
449
480
private static int m_buildNumber = 201;
450
481
0 commit comments