[icinga-checkins] icinga.org: icinga-core/mfriedrich/ido: * idoutils: small changes in escape_string fuction

git at icinga.org git at icinga.org
Fri Jul 22 14:50:57 CEST 2011


Module: icinga-core
Branch: mfriedrich/ido
Commit: 7bb40c641e3204d5be00c779433f203c879e3adf
URL:    https://git.icinga.org/?p=icinga-core.git;a=commit;h=7bb40c641e3204d5be00c779433f203c879e3adf

Author: Thomas Dressler <tdressler at tdressler.net>
Date:   Sat Jun 18 21:17:38 2011 +0200

* idoutils: small changes in escape_string fuction
refs #1377

---

 module/idoutils/src/db.c |   34 ++++++++++------------------------
 1 files changed, 10 insertions(+), 24 deletions(-)

diff --git a/module/idoutils/src/db.c b/module/idoutils/src/db.c
index 53820c8..4ec4ac2 100644
--- a/module/idoutils/src/db.c
+++ b/module/idoutils/src/db.c
@@ -2270,16 +2270,19 @@ char *ido2db_db_escape_string(ido2db_idi *idi, char *buf) {
 	if (idi == NULL || buf == NULL)
 		return NULL;
 
-	ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_escape_string(%s) start\n", buf);
+	ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_escape_string('%s') start\n", buf);
 
 	z = strlen(buf);
+        if ((newbuf = (char *) malloc((z * 2) + 1)) == NULL) {
+        	ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_escape_string('%s') Error: memory allocation failed \n", buf);
+        	return NULL;
+        }
+
 
 	/* escape characters */
 #ifdef USE_LIBDBI /* everything else will be libdbi */
 	/* allocate space for the new string */
 
-        if ((newbuf = (char *) malloc((z * 2) + 1)) == NULL)
-                return NULL;
 
         for (x = 0, y = 0; x < z; x++) {
 
@@ -2306,21 +2309,10 @@ char *ido2db_db_escape_string(ido2db_idi *idi, char *buf) {
         /* terminate escape string */
         newbuf[y] = '\0';
 
-        ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_escape_string(%s) end\n", newbuf);
-        return newbuf;
-
-        //size_t res = dbi_conn_quote_string(idi->dbinfo.dbi_conn, &buf);
-
-        //ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_escape_string(%s) end\n", buf);
-        //return buf;
-
 #endif
 
 #ifdef USE_PGSQL /* pgsql */
 
-        if ((newbuf = (char *) malloc((z * 2) + 1)) == NULL)
-                return NULL;
-
         for (x = 0, y = 0; x < z; x++) {
 
                 if (buf[x] == '\'' || buf[x] == '[' || buf[x] == ']' || buf[x] == '(' || buf[x] == ')')
@@ -2332,18 +2324,10 @@ char *ido2db_db_escape_string(ido2db_idi *idi, char *buf) {
         /* terminate escape string */
         newbuf[y] = '\0';
 
-        ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_escape_string(%s) end\n", newbuf);
-        return newbuf;
-
 #endif
 
 #ifdef USE_ORACLE /* Oracle ocilib specific */
 
-	/* allocate space for the new string */
-	if ((newbuf = (char *) malloc((z * 2) + 1)) == NULL)
-		return NULL;
-
-
 	for (x = 0, y = 0; x < z; x++) {
 
                 if(buf[x]=='\'' )
@@ -2355,8 +2339,10 @@ char *ido2db_db_escape_string(ido2db_idi *idi, char *buf) {
 
 	/* terminate escape string */
 	newbuf[y] = '\0';
-
-	ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_escape_string(%s) end\n", newbuf);
+	if (strcmp(buf,newbuf)!=0) {
+		ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_escape_string changed string ('%s')\n", newbuf);
+	}
+	ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_escape_string end\n");
 	return newbuf;
 }
 





More information about the icinga-checkins mailing list