[svn-commits] tilghman: branch tilghman/adaptive_realtime r120374 - in /team/tilghman/adapt...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Wed Jun 4 11:52:12 CDT 2008


Author: tilghman
Date: Wed Jun  4 11:52:12 2008
New Revision: 120374

URL: http://svn.digium.com/view/asterisk?view=rev&rev=120374
Log:
Add require API for curl configuration backend

Modified:
    team/tilghman/adaptive_realtime/contrib/scripts/dbsep.cgi
    team/tilghman/adaptive_realtime/res/res_config_curl.c

Modified: team/tilghman/adaptive_realtime/contrib/scripts/dbsep.cgi
URL: http://svn.digium.com/view/asterisk/team/tilghman/adaptive_realtime/contrib/scripts/dbsep.cgi?view=diff&rev=120374&r1=120373&r2=120374
==============================================================================
--- team/tilghman/adaptive_realtime/contrib/scripts/dbsep.cgi (original)
+++ team/tilghman/adaptive_realtime/contrib/scripts/dbsep.cgi Wed Jun  4 11:52:12 2008
@@ -28,6 +28,7 @@
 # dsn=<some valid dsn>
 # dbuser=<user>
 # dbpass=<passwd>
+# dbschema=<dbname>
 # backslash_is_escape={yes|no}
 #
 open CFG, "</etc/asterisk/dbsep.conf";
@@ -120,6 +121,43 @@
 	$affected = $dbh->do($sql);
 	$dbh->disconnect();
 	print "Content-type: text/html\n\n$affected\n";
+} elsif ($ENV{PATH_INFO} =~ m/require$/) {
+	my $result = 0;
+	my $dbh = DBI->connect($cfg{dsn}, $cfg{dbuser}, $cfg{dbpass});
+	my $sql = "SELECT data_type, character_maximum_length FROM information_schema.tables AS t " .
+			"JOIN information_schema.columns AS c " .
+			"ON t.table_catalog=c.table_catalog AND " .
+			"t.table_schema=c.table_schema AND " .
+			"t.table_name=c.table_name " .
+			"WHERE c.table_schema='$cfg{dbschema}' AND " .
+			"c.table_name=? AND c.column_name=?";
+	my $sth = $dbh->prepare($sql);
+	foreach my $param (cgi_to_where_clause($cgi, \%cfg)) {
+		my ($colname, $value) = split /=/, $param;
+		my ($type, $size) = split /:/, $value;
+		$sth->execute($table, $colname);
+		my ($dbtype, $dblen) = $sth->fetchrow_array();
+		$sth->finish();
+		if ($type eq 'char') {
+			if ($dbtype !~ m#char#i) {
+				print STDERR "REQUIRE: $table: Type of column $colname requires char($size), but column is of type $dbtype instead!\n";
+				$result = -1;
+			} elsif ($dblen < $size) {
+				print STDERR "REQUIRE: $table: Size of column $colname requires $size, but column is only $dblen long!\n";
+				$result = -1;
+			}
+		} elsif ($type eq 'integer') {
+			if ($dbtype =~ m#char#i and $dblen < $size) {
+				print STDERR "REQUIRE: $table: Size of column $colname requires $size, but column is only $dblen long!\n";
+				$result = -1;
+			} elsif ($dbtype !~ m#int|float|double|dec|num#i) {
+				print STDERR "REQUIRE: $table: Type of column $colname requires integer($size), but column is of type $dbtype instead!\n";
+				$result = -1;
+			}
+		} # TODO More type checks
+	}
+	$dbh->disconnect();
+	print "Content-type: text/html\n\n$result\n";
 } elsif ($ENV{PATH_INFO} =~ m/static$/) {
 	# file parameter in GET, no POST
 	my (@get, $filename, $sql, $sth);

Modified: team/tilghman/adaptive_realtime/res/res_config_curl.c
URL: http://svn.digium.com/view/asterisk/team/tilghman/adaptive_realtime/res/res_config_curl.c?view=diff&rev=120374&r1=120373&r2=120374
==============================================================================
--- team/tilghman/adaptive_realtime/res/res_config_curl.c (original)
+++ team/tilghman/adaptive_realtime/res/res_config_curl.c Wed Jun  4 11:52:12 2008
@@ -406,6 +406,42 @@
 	return -1;
 }
 
+static int require_curl(const char *url, const char *unused, va_list ap)
+{
+	struct ast_str *query;
+	char *elm, field[256], buffer[128];
+	int type, size;
+	const int EncodeSpecialChars = 1;
+
+	if (!ast_custom_function_find("CURL")) {
+		ast_log(LOG_ERROR, "func_curl.so must be loaded in order to use res_config_curl.so!!\n");
+		return -1;
+	}
+
+	if (!(query = ast_str_create(100))) {
+		return -1;
+	}
+
+	ast_str_set(&query, 0, "${CURL(%s/require,", url);
+
+	while ((elm = va_arg(ap, char *))) {
+		type = va_arg(ap, require_type);
+		size = va_arg(ap, int);
+		ast_uri_encode(elm, field, sizeof(field), EncodeSpecialChars);
+		ast_str_append(&query, 0, "%s=%s%%3A%d", field,
+			type == RQ_CHAR ? "char" :
+			type == RQ_INTEGER ? "integer" :
+			type == RQ_DATE ? "date" :
+			type == RQ_DATETIME ? "datetime" :
+			type == RQ_FLOAT ? "float" :
+			"unknown", size);
+	}
+	va_end(ap);
+
+	ast_str_append(&query, 0, ")}");
+	pbx_substitute_variables_helper(NULL, query->str, buffer, sizeof(buffer));
+	return atoi(buffer);
+}
 
 static struct ast_config *config_curl(const char *url, const char *unused, const char *file, struct ast_config *cfg, struct ast_flags flags, const char *sugg_incl, const char *who_asked)
 {
@@ -489,7 +525,8 @@
 	.realtime_multi_func = realtime_multi_curl,
 	.store_func = store_curl,
 	.destroy_func = destroy_curl,
-	.update_func = update_curl
+	.update_func = update_curl,
+	.require_func = require_curl,
 };
 
 static int unload_module (void)




More information about the svn-commits mailing list