[asterisk-commits] tilghman: trunk r115157 - in /trunk: apps/ channels/ include/asterisk/ main/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu May 1 21:33:05 CDT 2008


Author: tilghman
Date: Thu May  1 21:33:04 2008
New Revision: 115157

URL: http://svn.digium.com/view/asterisk?view=rev&rev=115157
Log:
Add attributes to various API calls, to help track down bugs (and remove a deprecated function)

Modified:
    trunk/apps/app_voicemail.c
    trunk/channels/chan_sip.c
    trunk/include/asterisk/config.h
    trunk/include/asterisk/logger.h
    trunk/include/asterisk/sched.h
    trunk/main/asterisk.c
    trunk/main/config.c
    trunk/main/sched.c

Modified: trunk/apps/app_voicemail.c
URL: http://svn.digium.com/view/asterisk/trunk/apps/app_voicemail.c?view=diff&rev=115157&r1=115156&r2=115157
==============================================================================
--- trunk/apps/app_voicemail.c (original)
+++ trunk/apps/app_voicemail.c Thu May  1 21:33:04 2008
@@ -1621,6 +1621,59 @@
 	return;	
 }
 
+struct insert_data {
+	char *sql;
+	char *dir;
+	char *msgnums;
+	void *data;
+	SQLLEN datalen;
+	const char *context;
+	const char *macrocontext;
+	const char *callerid;
+	const char *origtime;
+	const char *duration;
+	char *mailboxuser;
+	char *mailboxcontext;
+	const char *category;
+};
+
+static SQLHSTMT insert_data_cb(struct odbc_obj *obj, void *vdata)
+{
+	struct insert_data *data = vdata;
+	int res;
+	SQLHSTMT stmt;
+	SQLLEN len = data->datalen;
+
+	res = SQLAllocHandle(SQL_HANDLE_STMT, obj->con, &stmt);
+	if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
+		ast_log(AST_LOG_WARNING, "SQL Alloc Handle failed!\n");
+		SQLFreeHandle(SQL_HANDLE_STMT, stmt);
+		return NULL;
+	}
+
+	SQLBindParameter(stmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(data->dir), 0, (void *)data->dir, 0, NULL);
+	SQLBindParameter(stmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(data->msgnums), 0, (void *)data->msgnums, 0, NULL);
+	SQLBindParameter(stmt, 3, SQL_PARAM_INPUT, SQL_C_BINARY, SQL_LONGVARBINARY, data->datalen, 0, (void *)data->data, data->datalen, &len);
+	SQLBindParameter(stmt, 4, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(data->context), 0, (void *)data->context, 0, NULL);
+	SQLBindParameter(stmt, 5, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(data->macrocontext), 0, (void *)data->macrocontext, 0, NULL);
+	SQLBindParameter(stmt, 6, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(data->callerid), 0, (void *)data->callerid, 0, NULL);
+	SQLBindParameter(stmt, 7, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(data->origtime), 0, (void *)data->origtime, 0, NULL);
+	SQLBindParameter(stmt, 8, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(data->duration), 0, (void *)data->duration, 0, NULL);
+	SQLBindParameter(stmt, 9, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(data->mailboxuser), 0, (void *)data->mailboxuser, 0, NULL);
+	SQLBindParameter(stmt, 10, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(data->mailboxcontext), 0, (void *)data->mailboxcontext, 0, NULL);
+	if (!ast_strlen_zero(data->category)) {
+		SQLBindParameter(stmt, 11, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(data->category), 0, (void *)data->category, 0, NULL);
+	}
+	res = SQLExecDirect(stmt, (unsigned char *)data->sql, SQL_NTS);
+	if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
+		ast_log(AST_LOG_WARNING, "SQL Direct Execute failed!\n");
+		SQLFreeHandle(SQL_HANDLE_STMT, stmt);
+		return NULL;
+	}
+
+	return stmt;
+}
+
 /*!
  * \brief Stores a voicemail into the database.
  * \param dir the folder the mailbox folder to store the message.
@@ -1636,32 +1689,29 @@
  */
 static int store_file(char *dir, char *mailboxuser, char *mailboxcontext, int msgnum)
 {
-	int x = 0;
-	int res;
+	int res = 0;
 	int fd = -1;
 	void *fdm = MAP_FAILED;
 	size_t fdlen = -1;
 	SQLHSTMT stmt;
-	SQLLEN len;
 	char sql[PATH_MAX];
 	char msgnums[20];
 	char fn[PATH_MAX];
 	char full_fn[PATH_MAX];
 	char fmt[80] = "";
 	char *c;
-	const char *context = "";
-	const char *macrocontext = "";
-	const char *callerid = "";
-	const char *origtime = ""; 
-	const char *duration = "";
-	const char *category = "";
 	struct ast_config *cfg = NULL;
 	struct odbc_obj *obj;
+	struct insert_data idata = { .sql = sql, .msgnums = msgnums, .dir = dir, .mailboxuser = mailboxuser, .mailboxcontext = mailboxcontext };
 	struct ast_flags config_flags = { CONFIG_FLAG_NOCACHE };
 
 	delete_file(dir, msgnum);
-	obj = ast_odbc_request_obj(odbc_database, 0);
-	if (obj) {
+	if (!(obj = ast_odbc_request_obj(odbc_database, 0))) {
+		ast_log(AST_LOG_WARNING, "Failed to obtain database object for '%s'!\n", odbc_database);
+		return -1;
+	}
+
+	do {
 		ast_copy_string(fmt, vmfmts, sizeof(fmt));
 		c = strchr(fmt, '|');
 		if (c)
@@ -1679,22 +1729,28 @@
 		fd = open(full_fn, O_RDWR);
 		if (fd < 0) {
 			ast_log(AST_LOG_WARNING, "Open of sound file '%s' failed: %s\n", full_fn, strerror(errno));
-			ast_odbc_release_obj(obj);
-			goto yuck;
+			res = -1;
+			break;
 		}
 		if (cfg) {
-			context = ast_variable_retrieve(cfg, "message", "context");
-			if (!context) context = "";
-			macrocontext = ast_variable_retrieve(cfg, "message", "macrocontext");
-			if (!macrocontext) macrocontext = "";
-			callerid = ast_variable_retrieve(cfg, "message", "callerid");
-			if (!callerid) callerid = "";
-			origtime = ast_variable_retrieve(cfg, "message", "origtime");
-			if (!origtime) origtime = "";
-			duration = ast_variable_retrieve(cfg, "message", "duration");
-			if (!duration) duration = "";
-			category = ast_variable_retrieve(cfg, "message", "category");
-			if (!category) category = "";
+			if (!(idata.context = ast_variable_retrieve(cfg, "message", "context"))) {
+				idata.context = "";
+			}
+			if (!(idata.macrocontext = ast_variable_retrieve(cfg, "message", "macrocontext"))) {
+				idata.macrocontext = "";
+			}
+			if (!(idata.callerid = ast_variable_retrieve(cfg, "message", "callerid"))) {
+				idata.callerid = "";
+			}
+			if (!(idata.origtime = ast_variable_retrieve(cfg, "message", "origtime"))) {
+				idata.origtime = "";
+			}
+			if (!(idata.duration = ast_variable_retrieve(cfg, "message", "duration"))) {
+				idata.duration = "";
+			}
+			if (!(idata.category = ast_variable_retrieve(cfg, "message", "category"))) {
+				idata.category = "";
+			}
 		}
 		fdlen = lseek(fd, 0, SEEK_END);
 		lseek(fd, 0, SEEK_SET);
@@ -1702,58 +1758,34 @@
 		fdm = mmap(NULL, fdlen, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
 		if (fdm == MAP_FAILED) {
 			ast_log(AST_LOG_WARNING, "Memory map failed!\n");
-			ast_odbc_release_obj(obj);
-			goto yuck;
+			res = -1;
+			break;
 		} 
-		res = SQLAllocHandle(SQL_HANDLE_STMT, obj->con, &stmt);
-		if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
-			ast_log(AST_LOG_WARNING, "SQL Alloc Handle failed!\n");
-			ast_odbc_release_obj(obj);
-			goto yuck;
-		}
-		if (!ast_strlen_zero(category)) 
+		idata.data = fdm;
+		idata.datalen = fdlen;
+
+		if (!ast_strlen_zero(idata.category)) 
 			snprintf(sql, sizeof(sql), "INSERT INTO %s (dir,msgnum,recording,context,macrocontext,callerid,origtime,duration,mailboxuser,mailboxcontext,category) VALUES (?,?,?,?,?,?,?,?,?,?,?)", odbc_table);
 		else
 			snprintf(sql, sizeof(sql), "INSERT INTO %s (dir,msgnum,recording,context,macrocontext,callerid,origtime,duration,mailboxuser,mailboxcontext) VALUES (?,?,?,?,?,?,?,?,?,?)", odbc_table);
-		res = SQLPrepare(stmt, (unsigned char *)sql, SQL_NTS);
-		if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
-			ast_log(AST_LOG_WARNING, "SQL Prepare failed![%s]\n", sql);
+
+		if ((stmt = ast_odbc_direct_execute(obj, insert_data_cb, &idata))) {
 			SQLFreeHandle (SQL_HANDLE_STMT, stmt);
-			ast_odbc_release_obj(obj);
-			goto yuck;
-		}
-		len = fdlen; /* SQL_LEN_DATA_AT_EXEC(fdlen); */
-		SQLBindParameter(stmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(dir), 0, (void *)dir, 0, NULL);
-		SQLBindParameter(stmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(msgnums), 0, (void *)msgnums, 0, NULL);
-		SQLBindParameter(stmt, 3, SQL_PARAM_INPUT, SQL_C_BINARY, SQL_LONGVARBINARY, fdlen, 0, (void *)fdm, fdlen, &len);
-		SQLBindParameter(stmt, 4, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(context), 0, (void *)context, 0, NULL);
-		SQLBindParameter(stmt, 5, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(macrocontext), 0, (void *)macrocontext, 0, NULL);
-		SQLBindParameter(stmt, 6, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(callerid), 0, (void *)callerid, 0, NULL);
-		SQLBindParameter(stmt, 7, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(origtime), 0, (void *)origtime, 0, NULL);
-		SQLBindParameter(stmt, 8, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(duration), 0, (void *)duration, 0, NULL);
-		SQLBindParameter(stmt, 9, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(mailboxuser), 0, (void *)mailboxuser, 0, NULL);
-		SQLBindParameter(stmt, 10, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(mailboxcontext), 0, (void *)mailboxcontext, 0, NULL);
-		if (!ast_strlen_zero(category))
-			SQLBindParameter(stmt, 11, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(category), 0, (void *)category, 0, NULL);
-		res = ast_odbc_smart_execute(obj, stmt);
-		if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
+		} else {
 			ast_log(AST_LOG_WARNING, "SQL Execute error!\n[%s]\n\n", sql);
-			SQLFreeHandle (SQL_HANDLE_STMT, stmt);
-			ast_odbc_release_obj(obj);
-			goto yuck;
-		}
-		SQLFreeHandle (SQL_HANDLE_STMT, stmt);
+			res = -1;
+		}
+	} while (0);
+	if (obj) {
 		ast_odbc_release_obj(obj);
-	} else
-		ast_log(AST_LOG_WARNING, "Failed to obtain database object for '%s'!\n", odbc_database);
-yuck:	
+	}
 	if (cfg)
 		ast_config_destroy(cfg);
 	if (fdm != MAP_FAILED)
 		munmap(fdm, fdlen);
 	if (fd > -1)
 		close(fd);
-	return x;
+	return res;
 }
 
 /*!

Modified: trunk/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_sip.c?view=diff&rev=115157&r1=115156&r2=115157
==============================================================================
--- trunk/channels/chan_sip.c (original)
+++ trunk/channels/chan_sip.c Thu May  1 21:33:04 2008
@@ -4607,7 +4607,7 @@
 	/* Destroy Session-Timers if allocated */
 	if (p->stimer) {
 		if (p->stimer->st_active == TRUE && p->stimer->st_schedid > -1)
-			ast_sched_del(sched, p->stimer->st_schedid);
+			AST_SCHED_DEL(sched, p->stimer->st_schedid);
 		ast_free(p->stimer);
 		p->stimer = NULL;
 	}
@@ -15978,7 +15978,7 @@
 	case 423:	/* Interval too brief */
 		r->expiry = atoi(get_header(req, "Min-Expires"));
 		ast_log(LOG_WARNING, "Got 423 Interval too brief for service %s@%s, minimum is %d seconds\n", p->registry->username, p->registry->hostname, r->expiry);
-		ast_sched_del(sched, r->timeout);
+		AST_SCHED_DEL(sched, r->timeout);
 		r->timeout = -1;
 		if (r->call) {
 			r->call = dialog_unref(r->call, "unsetting registry->call pointer-- case 423");

Modified: trunk/include/asterisk/config.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/config.h?view=diff&rev=115157&r1=115156&r2=115157
==============================================================================
--- trunk/include/asterisk/config.h (original)
+++ trunk/include/asterisk/config.h Thu May  1 21:33:04 2008
@@ -182,8 +182,8 @@
  * that unlike the variables in ast_config, the resulting list of variables
  * MUST be freed with ast_variables_destroy() as there is no container.
  */
-struct ast_variable *ast_load_realtime(const char *family, ...);
-struct ast_variable *ast_load_realtime_all(const char *family, ...);
+struct ast_variable *ast_load_realtime(const char *family, ...) __attribute__((sentinel));
+struct ast_variable *ast_load_realtime_all(const char *family, ...) __attribute__((sentinel));
 
 /*! 
  * \brief Retrieve realtime configuration 
@@ -194,7 +194,7 @@
  * is thus stored inside a taditional ast_config structure rather than 
  * just returning a linked list of variables.
  */
-struct ast_config *ast_load_realtime_multientry(const char *family, ...);
+struct ast_config *ast_load_realtime_multientry(const char *family, ...) __attribute__((sentinel));
 
 /*! 
  * \brief Update realtime configuration 
@@ -204,7 +204,7 @@
  * This function is used to update a parameter in realtime configuration space.
  *
  */
-int ast_update_realtime(const char *family, const char *keyfield, const char *lookup, ...);
+int ast_update_realtime(const char *family, const char *keyfield, const char *lookup, ...) __attribute__((sentinel));
 
 /*! 
  * \brief Create realtime configuration 
@@ -212,7 +212,7 @@
  * This function is used to create a parameter in realtime configuration space.
  *
  */
-int ast_store_realtime(const char *family, ...);
+int ast_store_realtime(const char *family, ...) __attribute__((sentinel));
 
 /*! 
  * \brief Destroy realtime configuration 
@@ -223,7 +223,7 @@
  * Additional params are used as keys.
  *
  */
-int ast_destroy_realtime(const char *family, const char *keyfield, const char *lookup, ...);
+int ast_destroy_realtime(const char *family, const char *keyfield, const char *lookup, ...) __attribute__((sentinel));
 
 /*! 
  * \brief Check if realtime engine is configured for family 

Modified: trunk/include/asterisk/logger.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/logger.h?view=diff&rev=115157&r1=115156&r2=115157
==============================================================================
--- trunk/include/asterisk/logger.h (original)
+++ trunk/include/asterisk/logger.h Thu May  1 21:33:04 2008
@@ -81,8 +81,8 @@
 void ast_child_verbose(int level, const char *fmt, ...)
 	__attribute__ ((format (printf, 2, 3)));
 
-int ast_register_verbose(void (*verboser)(const char *string));
-int ast_unregister_verbose(void (*verboser)(const char *string));
+int ast_register_verbose(void (*verboser)(const char *string)) __attribute__((warn_unused_result));
+int ast_unregister_verbose(void (*verboser)(const char *string)) __attribute__((warn_unused_result));
 
 void ast_console_puts(const char *string);
 

Modified: trunk/include/asterisk/sched.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/sched.h?view=diff&rev=115157&r1=115156&r2=115157
==============================================================================
--- trunk/include/asterisk/sched.h (original)
+++ trunk/include/asterisk/sched.h Thu May  1 21:33:04 2008
@@ -155,7 +155,7 @@
  * \param data data to pass to the callback
  * \return Returns a schedule item ID on success, -1 on failure
  */
-int ast_sched_add(struct sched_context *con, int when, ast_sched_cb callback, const void *data);
+int ast_sched_add(struct sched_context *con, int when, ast_sched_cb callback, const void *data) __attribute__((warn_unused_result));
 
 /*!
  * \brief replace a scheduler entry
@@ -168,7 +168,7 @@
  * \retval -1 failure
  * \retval otherwise, returns scheduled item ID
  */
-int ast_sched_replace(int old_id, struct sched_context *con, int when, ast_sched_cb callback, const void *data);
+int ast_sched_replace(int old_id, struct sched_context *con, int when, ast_sched_cb callback, const void *data) __attribute__((warn_unused_result));
 
 /*!Adds a scheduled event with rescheduling support
  * \param con Scheduler context to add
@@ -183,7 +183,7 @@
  * If callback returns 0, no further events will be re-scheduled
  * \return Returns a schedule item ID on success, -1 on failure
  */
-int ast_sched_add_variable(struct sched_context *con, int when, ast_sched_cb callback, const void *data, int variable);
+int ast_sched_add_variable(struct sched_context *con, int when, ast_sched_cb callback, const void *data, int variable) __attribute__((warn_unused_result));
 
 /*!
  * \brief replace a scheduler entry
@@ -196,7 +196,7 @@
  * \retval -1 failure
  * \retval otherwise, returns scheduled item ID
  */
-int ast_sched_replace_variable(int old_id, struct sched_context *con, int when, ast_sched_cb callback, const void *data, int variable);
+int ast_sched_replace_variable(int old_id, struct sched_context *con, int when, ast_sched_cb callback, const void *data, int variable) __attribute__((warn_unused_result));
 
 	
 /*! \brief Find a sched structure and return the data field associated with it. 
@@ -216,8 +216,7 @@
  * \param id ID of the scheduled item to delete
  * \return Returns 0 on success, -1 on failure
  */
-
-int ast_sched_del(struct sched_context *con, int id);
+int ast_sched_del(struct sched_context *con, int id) __attribute__((warn_unused_result));
 
 /*! \brief Determines number of seconds until the next outstanding event to take place
  * Determine the number of seconds until the next outstanding event
@@ -228,7 +227,7 @@
  * \return Returns "-1" if there is nothing there are no scheduled events
  * (and thus the poll should not timeout)
  */
-int ast_sched_wait(struct sched_context *con);
+int ast_sched_wait(struct sched_context *con) __attribute__((warn_unused_result));
 
 /*! \brief Runs the queue
  * \param con Scheduling context to run

Modified: trunk/main/asterisk.c
URL: http://svn.digium.com/view/asterisk/trunk/main/asterisk.c?view=diff&rev=115157&r1=115156&r2=115157
==============================================================================
--- trunk/main/asterisk.c (original)
+++ trunk/main/asterisk.c Thu May  1 21:33:04 2008
@@ -1117,7 +1117,10 @@
 		ast_socket = -1;
 		return -1;
 	}
-	ast_register_verbose(network_verboser);
+	if (ast_register_verbose(network_verboser)) {
+		ast_log(LOG_WARNING, "Unable to register network verboser?\n");
+	}
+
 	ast_pthread_create_background(&lthread, NULL, listener, NULL);
 
 	if (!ast_strlen_zero(ast_config_AST_CTL_OWNER)) {
@@ -2914,7 +2917,9 @@
 	}
 
 	if (ast_opt_console || option_verbose || (ast_opt_remote && !ast_opt_exec)) {
-		ast_register_verbose(console_verboser);
+		if (ast_register_verbose(console_verboser)) {
+			ast_log(LOG_WARNING, "Unable to register console verboser?\n");
+		}
 		WELCOME_MESSAGE;
 	}
 

Modified: trunk/main/config.c
URL: http://svn.digium.com/view/asterisk/trunk/main/config.c?view=diff&rev=115157&r1=115156&r2=115157
==============================================================================
--- trunk/main/config.c (original)
+++ trunk/main/config.c Thu May  1 21:33:04 2008
@@ -2130,7 +2130,8 @@
 	return res;
 }
 
-int ast_store_realtime(const char *family, ...) {
+int ast_store_realtime(const char *family, ...)
+{
 	struct ast_config_engine *eng;
 	int res = -1;
 	char db[256]="";
@@ -2146,7 +2147,8 @@
 	return res;
 }
 
-int ast_destroy_realtime(const char *family, const char *keyfield, const char *lookup, ...) {
+int ast_destroy_realtime(const char *family, const char *keyfield, const char *lookup, ...)
+{
 	struct ast_config_engine *eng;
 	int res = -1;
 	char db[256]="";

Modified: trunk/main/sched.c
URL: http://svn.digium.com/view/asterisk/trunk/main/sched.c?view=diff&rev=115157&r1=115156&r2=115157
==============================================================================
--- trunk/main/sched.c (original)
+++ trunk/main/sched.c Thu May  1 21:33:04 2008
@@ -252,8 +252,9 @@
 int ast_sched_replace_variable(int old_id, struct sched_context *con, int when, ast_sched_cb callback, const void *data, int variable)
 {
 	/* 0 means the schedule item is new; do not delete */
-	if (old_id > 0)
-		ast_sched_del(con, old_id);
+	if (old_id > 0) {
+		AST_SCHED_DEL(con, old_id);
+	}
 	return ast_sched_add_variable(con, when, callback, data, variable);
 }
 
@@ -295,8 +296,9 @@
 
 int ast_sched_replace(int old_id, struct sched_context *con, int when, ast_sched_cb callback, const void *data)
 {
-	if (old_id > -1)
-		ast_sched_del(con, old_id);
+	if (old_id > -1) {
+		AST_SCHED_DEL(con, old_id);
+	}
 	return ast_sched_add(con, when, callback, data);
 }
 




More information about the asterisk-commits mailing list