Skip to Content.
Sympa Menu

freetds - [Fwd: [freetds] [patch] Add CS_SERVERADDR, CS_VER_STRING, CS_VERSION to ctlib]

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: Frediano Ziglio <freddyz77 AT tin.it>
  • To: FreeTDS <freetds AT lists.ibiblio.org>
  • Subject: [Fwd: [freetds] [patch] Add CS_SERVERADDR, CS_VER_STRING, CS_VERSION to ctlib]
  • Date: Sun, 06 Feb 2005 07:49:48 +0100

I found this patch on ML not applied...

------- Messaggio inoltrato -------
Da: Alex Kiesel <alex.kiesel AT document-root.de>
Rispondi-a: FreeTDS Development Group <freetds AT lists.ibiblio.org>
A: freetds AT lists.ibiblio.org
Oggetto: [freetds] [patch] Add CS_SERVERADDR, CS_VER_STRING, CS_VERSION
to ctlib
Data: Tue, 17 Aug 2004 14:23:20 +0200
Hi,

the attached patch includes the following changes:
* ct_config():
- implemented CS_VER_STRING (this returns the following format:
"freetds v0.63.dev.20040814 (non-threadsafe, default tds
version=5.0)"
- implemented CS_VERSION (this returns the following:
"freetds v0.63.dev.20040814"
(both are from tds_get_compiletime_settings())
- on failure return CS_FAIL instead of CS_FALSE to comply with
documentation. Both constants are of same value, so this is not a BC
break.

* ct_con_props():
- implemented CS_SERVERADDR property
this property can be used to override the servername and port from
the interfaces file; this was possible with "server:port" notation
with FreeTDS before, but this method is compatible to Sybase's one.
See also: <1088147142.2082.34.camel AT elanor.peppler.org> on this
list.

Furthermore, one question: shouldn't ct_config(), ct_con_props() and
similar function be changed to return CS_FAIL in case the given property
was unknown (not implemented) or ignored?

Regards,
-Alex

------- Messaggio inoltrato -------

freddy77



Index: include/cspublic.h
===================================================================
RCS file: /cvsroot/freetds/freetds/include/cspublic.h,v
retrieving revision 1.52
diff -u -r1.52 cspublic.h
--- include/cspublic.h	23 Mar 2004 12:05:30 -0000	1.52
+++ include/cspublic.h	17 Aug 2004 12:11:11 -0000
@@ -349,8 +349,10 @@
 #define CS_VER_STRING CS_VER_STRING
 	CS_SERVERNAME,
 #define CS_SERVERNAME CS_SERVERNAME
-	CS_PORT
+	CS_PORT,
 #define CS_PORT CS_PORT
+	CS_SERVERADDR
+#define CS_SERVERADDR CS_SERVERADDR
 };
 
 /* Arbitrary precision math operators */
Index: include/tds.h
===================================================================
RCS file: /cvsroot/freetds/freetds/include/tds.h,v
retrieving revision 1.186
diff -u -r1.186 tds.h
--- include/tds.h	6 Aug 2004 08:13:05 -0000	1.186
+++ include/tds.h	17 Aug 2004 12:11:12 -0000
@@ -662,6 +662,7 @@
 typedef struct tds_login
 {
 	DSTR server_name;
+	DSTR server_addr;
 	int port;
 	TDS_TINYINT major_version;	/* TDS version */
 	TDS_TINYINT minor_version;	/* TDS version */
@@ -1180,6 +1181,7 @@
 void tds_set_user(TDSLOGIN * tds_login, const char *username);
 void tds_set_app(TDSLOGIN * tds_login, const char *application);
 void tds_set_host(TDSLOGIN * tds_login, const char *hostname);
+void tds_set_server_addr(TDSLOGIN * tds_login, const char *server_addr);
 void tds_set_library(TDSLOGIN * tds_login, const char *library);
 void tds_set_server(TDSLOGIN * tds_login, const char *server);
 void tds_set_client_charset(TDSLOGIN * tds_login, const char *charset);
Index: src/ctlib/ct.c
===================================================================
RCS file: /cvsroot/freetds/freetds/src/ctlib/ct.c,v
retrieving revision 1.122
diff -u -r1.122 ct.c
--- src/ctlib/ct.c	29 Jul 2004 10:22:40 -0000	1.122
+++ src/ctlib/ct.c	17 Aug 2004 12:11:13 -0000
@@ -297,7 +297,7 @@
 	tds_login = con->tds_login;
 
 	if (action == CS_SET) {
-		if (property == CS_USERNAME || property == CS_PASSWORD || property == CS_APPNAME || property == CS_HOSTNAME) {
+		if (property == CS_USERNAME || property == CS_PASSWORD || property == CS_APPNAME || property == CS_HOSTNAME || property == CS_SERVERADDR) {
 			if (buflen == CS_NULLTERM) {
 				maxcp = strlen((char *) buffer);
 				set_buffer = (char *) malloc(maxcp + 1);
@@ -331,6 +331,20 @@
 		case CS_PORT:
 			tds_set_port(tds_login, *((int *) buffer));
 			break;
+        case CS_SERVERADDR: {
+			/* Format of this property: "[hostname] [port]" */
+			char *host, *port;
+			int portno;
+			host= strsep(&set_buffer, " ");
+			port= strsep(&set_buffer, " ");
+			if (!host || !port) 
+				return CS_FAIL;
+			
+			portno= (int)strtol(port, (char **)NULL, 10);
+			tds_set_server_addr(tds_login, host);
+			tds_set_port(tds_login, portno);
+			break;
+		}
 		case CS_LOC_PROP:
 			con->locale = (CS_LOCALE *) buffer;
 			break;
@@ -521,7 +535,9 @@
 
 	tdsdump_log(TDS_DBG_FUNC, "ct_connect() servername = %s\n", servername ? servername : "NULL");
 
-	if (snamelen == 0 || snamelen == CS_UNUSED) {
+	if (!tds_dstr_isempty(&con->tds_login->server_addr)) {
+		server = tds_dstr_cstr(&con->tds_login->server_addr);
+	} else if (snamelen == 0 || snamelen == CS_UNUSED) {
 		server = NULL;
 	} else if (snamelen == CS_NULLTERM) {
 		server = (char *) servername;
@@ -1896,7 +1912,7 @@
 			break;
 		case CS_SET:
 			if (*buf != CS_TRUE && *buf != CS_FALSE)
-				ret = CS_FALSE;
+				ret = CS_FAIL;
 			else
 				ctx->config.cs_expose_formats = *buf;
 			break;
@@ -1904,13 +1920,51 @@
 			if (buf)
 				*buf = ctx->config.cs_expose_formats;
 			else
-				ret = CS_FALSE;
+				ret = CS_FAIL;
 			break;
 		case CS_CLEAR:
 			ctx->config.cs_expose_formats = CS_FALSE;
 			break;
 		default:
-			ret = CS_FALSE;
+			ret = CS_FAIL;
+		}
+		break;
+	case CS_VER_STRING: {
+		ret = CS_FAIL;
+		switch (action) {
+			case CS_GET: {
+				if (buffer && buflen && outlen) {
+					const TDS_COMPILETIME_SETTINGS *settings= tds_get_compiletime_settings();
+					*outlen= snprintf((char*)buffer, buflen, "%s (%s, default tds version=%s)",
+						settings->freetds_version,
+						(settings->threadsafe ? "threadsafe" : "non-threadsafe"),
+                        settings->tdsver
+					);
+                    ((char*)buffer)[buflen]= 0;
+					ret = CS_SUCCEED;
+				}
+				break;
+				default:
+					ret = CS_FAIL;
+					break;
+				}
+			}
+		}
+		break;
+	case CS_VERSION:
+		ret = CS_FAIL;
+		switch (action) {
+			case CS_GET: {
+				if (buffer && buflen && outlen) {
+					const TDS_COMPILETIME_SETTINGS *settings= tds_get_compiletime_settings();
+					*outlen= snprintf(buffer, buflen, "%s", settings->freetds_version);
+					ret = CS_SUCCEED;
+				}
+				break;
+			default:
+				ret = CS_FAIL;
+				break;
+			}
 		}
 		break;
 	default:
Index: src/tds/login.c
===================================================================
RCS file: /cvsroot/freetds/freetds/src/tds/login.c,v
retrieving revision 1.126
diff -u -r1.126 login.c
--- src/tds/login.c	29 Jul 2004 10:22:41 -0000	1.126
+++ src/tds/login.c	17 Aug 2004 12:11:14 -0000
@@ -159,6 +159,14 @@
 }
 
 void
+tds_set_server_addr(TDSLOGIN * tds_login, const char *server_addr)
+{
+	if (server_addr) {
+		tds_dstr_copy(&tds_login->server_addr, server_addr);
+	}
+}
+
+void
 tds_set_library(TDSLOGIN * tds_login, const char *library)
 {
 	tds_dstr_copy(&tds_login->library, library);
@@ -256,7 +264,7 @@
 
 	/* verify that ip_addr is not NULL */
 	if (tds_dstr_isempty(&connection->ip_addr)) {
-		tdsdump_log(TDS_DBG_ERROR, "IP address pointer is NULL\n");
+		tdsdump_log(TDS_DBG_ERROR, "IP address pasdointer is NULL\n");
 		if (connection->server_name) {
 			tdsdump_log(TDS_DBG_ERROR, "Server %s not found!\n", tds_dstr_cstr(&connection->server_name));
 		} else {
Index: src/tds/mem.c
===================================================================
RCS file: /cvsroot/freetds/freetds/src/tds/mem.c,v
retrieving revision 1.114
diff -u -r1.114 mem.c
--- src/tds/mem.c	29 Jul 2004 10:22:41 -0000	1.114
+++ src/tds/mem.c	17 Aug 2004 12:11:14 -0000
@@ -680,6 +680,7 @@
 		return NULL;
 	memset(tds_login, '\0', sizeof(TDSLOGIN));
 	tds_dstr_init(&tds_login->server_name);
+	tds_dstr_init(&tds_login->server_addr);
 	tds_dstr_init(&tds_login->language);
 	tds_dstr_init(&tds_login->server_charset);
 	tds_dstr_init(&tds_login->host_name);
@@ -700,6 +701,7 @@
 		tds_dstr_zero(&login->password);
 		tds_dstr_free(&login->password);
 		tds_dstr_free(&login->server_name);
+		tds_dstr_free(&login->server_addr);
 		tds_dstr_free(&login->language);
 		tds_dstr_free(&login->server_charset);
 		tds_dstr_free(&login->host_name);


  • [Fwd: [freetds] [patch] Add CS_SERVERADDR, CS_VER_STRING, CS_VERSION to ctlib], Frediano Ziglio, 02/06/2005

Archive powered by MHonArc 2.6.24.

Top of Page