[Asterisk-cvs] asterisk/res res_config_odbc.c,1.3,1.4

citats at lists.digium.com citats at lists.digium.com
Thu Jul 8 16:30:41 CDT 2004


Update of /usr/cvsroot/asterisk/res
In directory mongoose.digium.com:/home/citats/cvs/asterisk/res

Modified Files:
	res_config_odbc.c 
Log Message:
Massive res_config_odbc.c formatting cleanups from bkw_.  Thanks!!!

Index: res_config_odbc.c
===================================================================
RCS file: /usr/cvsroot/asterisk/res/res_config_odbc.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- res_config_odbc.c	8 Jul 2004 13:18:04 -0000	1.3
+++ res_config_odbc.c	8 Jul 2004 20:16:28 -0000	1.4
@@ -9,7 +9,6 @@
  * Copyright (C) 2004 Anthony Minessale II <anthmct at yahoo.com>
  */
 
-
 #include <asterisk/file.h>
 #include <asterisk/logger.h>
 #include <asterisk/channel.h>
@@ -23,231 +22,186 @@
 #include <string.h>
 #include <asterisk/res_odbc.h>
 
-
-
-static char *tdesc = "Odbc Configuration";
+static char *tdesc = "ODBC Configuration";
 static struct ast_config_reg reg1;
 
-
 STANDARD_LOCAL_USER;
 
 LOCAL_USER_DECL;
 
-
-static struct ast_config *config_odbc(char *file, struct ast_config *new_config_s,struct ast_category **new_cat_p,struct ast_variable **new_v_p,int recur
+static struct ast_config *config_odbc (char *file, struct ast_config *new_config_s, struct ast_category **new_cat_p, struct ast_variable **new_v_p, int recur
 #ifdef PRESERVE_COMMENTS
-				      ,struct ast_comment_struct *acs
+	, struct ast_comment_struct *acs
 #endif
+)
+{
+	struct ast_config *config, *new;
+	struct ast_variable *v, *cur_v, *new_v;
+	struct ast_category *cur_cat, *new_cat;
+	char table[128];
+	char connection[128];
+	int configured = 0, res = 0;
+	odbc_obj *obj;
+	SQLINTEGER err, commented, cat_metric, var_metric;
+	SQLBIGINT id;
+	char sql[255], filename[128], category[128], var_name[128], var_val[128];
+	SQLSMALLINT rowcount;
+	SQLHSTMT stmt;
+	char last[80];
+	int cat_started = 0;
+	int var_started = 0;
 
-				      ) {
-
-
-
-
-  struct ast_config *config,*new;
-  struct ast_variable *v,*cur_v,*new_v;
-  struct ast_category *cur_cat,*new_cat;
-  char table[128];
-  char connection[128];
-  int configured=0, res=0;
-  odbc_obj *obj;
-  SQLINTEGER err,commented,cat_metric,var_metric;
-  SQLBIGINT id;
-  char sql[255],filename[128],category[128],var_name[128],var_val[128];
-  SQLSMALLINT rowcount;
-  SQLHSTMT stmt;
-  char last[80];
-  int cat_started=0;
-  int var_started=0;
-
-
-  if(new_config_s) {
-    new = new_config_s;
-    cat_started++;
-  }
-  else 
-    new = ast_new_config();
-
-  last[0] = '\0';
-
-  if(!file || !strcmp(file,"res_config_odbc.conf"))
-    return NULL; // cant configure myself with myself !
+	if (new_config_s) {
+		new = new_config_s;
+		cat_started++;
+	} else {
+		new = ast_new_config ();
+	}
 
-  config = ast_load("res_config_odbc.conf");
+	last[0] = '\0';
 
-  if(config) {
-    for(v = ast_variable_browse(config,"settings");v;v=v->next) {
-      if(!strcmp(v->name,"table")) {
-	strncpy(table,v->value,sizeof(table));
-	configured++;
-      }
-      else if(!strcmp(v->name,"connection")) {
-	strncpy(connection,v->value,sizeof(connection));
-	configured++;
-      }
-    }
-    ast_destroy(config);
-  }
-	
-  if(configured < 2)
-    return NULL;
-	
-  obj = fetch_odbc_obj(connection);
-  if(!obj)
-    return NULL;
+	if (!file || !strcmp (file, "res_config_odbc.conf"))
+		return NULL;		// cant configure myself with myself !
 
+	config = ast_load ("res_config_odbc.conf");
 
+	if (config) {
+		for (v = ast_variable_browse (config, "settings"); v; v = v->next) {
+			if (!strcmp (v->name, "table")) {
+				strncpy (table, v->value, sizeof (table));
+				configured++;
+			} else if (!strcmp (v->name, "connection")) {
+				strncpy (connection, v->value, sizeof (connection));
+				configured++;
+			}
+		}
+	ast_destroy (config);
+	}
 
+	if (configured < 2)
+		return NULL;
 
+	obj = fetch_odbc_obj (connection);
+	if (!obj)
+		return NULL;
 
-  res=SQLAllocHandle(SQL_HANDLE_STMT,obj->con, &stmt);
+	res = SQLAllocHandle (SQL_HANDLE_STMT, obj->con, &stmt);
 
-  SQLBindCol(stmt,1,SQL_C_ULONG,&id,sizeof(id),&err);
-  SQLBindCol(stmt,2,SQL_C_ULONG,&cat_metric,sizeof(cat_metric),&err);
-  SQLBindCol(stmt,3,SQL_C_ULONG,&var_metric,sizeof(var_metric),&err);
-  SQLBindCol(stmt,4,SQL_C_ULONG,&commented,sizeof(commented),&err);
-  SQLBindCol(stmt,5,SQL_C_CHAR,&filename,sizeof(filename),&err);
-  SQLBindCol(stmt,6,SQL_C_CHAR,&category,sizeof(category),&err);
-  SQLBindCol(stmt,7,SQL_C_CHAR,&var_name,sizeof(var_name),&err);
-  SQLBindCol(stmt,8,SQL_C_CHAR,&var_val,sizeof(var_val),&err);
-	
-  sprintf(sql,"select * from %s where filename='%s' and commented=0 order by filename,cat_metric desc,var_metric asc,id",table,file);
-  res = SQLExecDirect(stmt,sql,SQL_NTS);
-	
-  if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
-    ast_log(LOG_WARNING,"SQL select error!\n[%s]\n\n",sql);
-    return NULL;
-  }
-	
-  res=SQLNumResultCols(stmt,&rowcount);
-	
-  if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
-    ast_log(LOG_WARNING,"SQL select error!\n[%s]\n\n",sql);
-    return NULL;
-  }
+	SQLBindCol (stmt, 1, SQL_C_ULONG, &id, sizeof (id), &err);
+	SQLBindCol (stmt, 2, SQL_C_ULONG, &cat_metric, sizeof (cat_metric), &err);
+	SQLBindCol (stmt, 3, SQL_C_ULONG, &var_metric, sizeof (var_metric), &err);
+	SQLBindCol (stmt, 4, SQL_C_ULONG, &commented, sizeof (commented), &err);
+	SQLBindCol (stmt, 5, SQL_C_CHAR, &filename, sizeof (filename), &err);
+	SQLBindCol (stmt, 6, SQL_C_CHAR, &category, sizeof (category), &err);
+	SQLBindCol (stmt, 7, SQL_C_CHAR, &var_name, sizeof (var_name), &err);
+	SQLBindCol (stmt, 8, SQL_C_CHAR, &var_val, sizeof (var_val), &err);
 
+	sprintf (sql, "select * from %s where filename='%s' and commented=0 order by filename,cat_metric desc,var_metric asc,id", table, file);
+	res = SQLExecDirect (stmt, sql, SQL_NTS);
 
-  if(rowcount) {
+	if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
+		ast_log (LOG_WARNING, "SQL select error!\n[%s]\n\n", sql);
+		return NULL;
+	}
 
-    res=SQLFetch(stmt);
-    cat_started=0;
+	res = SQLNumResultCols (stmt, &rowcount);
 
+	if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
+		ast_log (LOG_WARNING, "SQL select error!\n[%s]\n\n", sql);
+		return NULL;
+	}
 
-		
-    cur_cat = *new_cat_p;
-    cur_v = *new_v_p;
-		
-    if(cur_cat)
-      cat_started=1;
-    if(cur_v)
-      var_started=1;
+	if (rowcount) {
+		res = SQLFetch (stmt);
+		cat_started = 0;
 
+		cur_cat = *new_cat_p;
+		cur_v = *new_v_p;
 
+		if (cur_cat)
+			cat_started = 1;
+		if (cur_v)
+			var_started = 1;
 
-    while(res != SQL_NO_DATA) {
-      //ast_log(LOG_NOTICE,"found %s %s %s\n",filename,var_name,var_val);
-      // build the config sql table probably needs to be improved!
+		while (res != SQL_NO_DATA) {
+			if (!strcmp (var_name, "#include") && recur < MAX_INCLUDE_LEVEL) {
 
-      if(!strcmp(var_name,"#include") &&  recur < MAX_INCLUDE_LEVEL) {
-				
-	config_odbc(var_val,new,&cur_cat,&cur_v,recur + 1
+				config_odbc (var_val, new, &cur_cat, &cur_v, recur + 1
 #ifdef PRESERVE_COMMENTS
-		    ,acs
+							, acs
 #endif
-		    );
-
-      }
-      else {			
-
-				
+				);
+			} else {
+				if (strcmp (last, category)) {
+					strcpy (last, category);
+					new_cat = (struct ast_category *) ast_new_category (category);
 
-	if(strcmp(last,category)) {
-	  strcpy(last,category);
-	  new_cat = (struct ast_category *) ast_new_category(category);
-					
-	  if(!cat_started) {
-	    cat_started++;
-	    new->root = new_cat;
-	    cur_cat=new->root;
-	  }
-	  else {
-	    cur_cat->next = new_cat;
-	    cur_cat = cur_cat->next;
-	  }
-	  var_started=0;
-					
-	}
+					if (!cat_started) {
+						cat_started++;
+						new->root = new_cat;
+						cur_cat = new->root;
+					} else {
+						cur_cat->next = new_cat;
+						cur_cat = cur_cat->next;
+					}
+					var_started = 0;
 
-	new_v = ast_new_variable(var_name,var_val);
-				
-				
-	if(!var_started) {
-	  var_started++;
-	  cur_cat->root = new_v;
-	  cur_v = cur_cat->root;
-	}
-	else {
-	  cur_v->next = new_v;
-	  cur_v = cur_v->next;
-	}
-      }
-			
-      // next row 
-      res=SQLFetch(stmt);
-    }
+				}
 
-    SQLFreeHandle(SQL_HANDLE_STMT,stmt);
-  }
-  else 
-    ast_log(LOG_NOTICE,"found nothing\n");
+				new_v = ast_new_variable (var_name, var_val);
 
-	
+				if (!var_started) {
+					var_started++;
+					cur_cat->root = new_v;
+					cur_v = cur_cat->root;
+				} else {
+					cur_v->next = new_v;
+					cur_v = cur_v->next;
+				}
+			}
 
-	
-	
+		// next row 
+			res = SQLFetch (stmt);
+		}
 
+		SQLFreeHandle (SQL_HANDLE_STMT, stmt);
+	} else {
+		ast_log (LOG_NOTICE, "found nothing\n");
+	}
+	return new;
 
-	
-  return new;
-	
 }
 
-
-
-
-int unload_module(void)
+int unload_module (void)
 {
-    ast_cust_config_deregister(&reg1);
-	ast_log(LOG_NOTICE,"res_config_odbc unloaded.\n");
+	ast_cust_config_deregister (&reg1);
+	ast_log (LOG_NOTICE, "res_config_odbc unloaded.\n");
 	STANDARD_HANGUP_LOCALUSERS;
 	return 0;
 }
 
-int load_module(void)
+int load_module (void)
 {
-
-	memset(&reg1,0,sizeof(struct ast_config_reg));
-	strcpy(reg1.name,"odbc");
+	memset (&reg1, 0, sizeof (struct ast_config_reg));
+	strcpy (reg1.name, "odbc");
 	reg1.func = config_odbc;
-	ast_cust_config_register(&reg1);
-	ast_log(LOG_NOTICE,"res_config_odbc loaded.\n");
+	ast_cust_config_register (&reg1);
+	ast_log (LOG_NOTICE, "res_config_odbc loaded.\n");
 	return 0;
 }
 
-char *description(void)
+char *description (void)
 {
-  return tdesc;
+	return tdesc;
 }
 
-int usecount(void)
+int usecount (void)
 {
 	/* never unload a config module */
 	return 1;
 }
 
-char *key()
+char *key ()
 {
-  return ASTERISK_GPL_KEY;
+	return ASTERISK_GPL_KEY;
 }
-
-




More information about the svn-commits mailing list