Update of /cvsroot/monetdb/MonetDB5/src/mal
In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv15852
Modified Files:
mal_session.mx
Log Message:
Greatly simplify && cleanup the code by replacing this pre-Sabaoth code
with some Sabaoth-call. It's questionable if this M5 built-in
redirection feature is of any use with Merovingian, but it's better
maintainable if it uses Sabaoth for sure.
Index: mal_session.mx
===================================================================
RCS file: /cvsroot/monetdb/MonetDB5/src/mal/mal_session.mx,v
retrieving revision 1.138
retrieving revision 1.139
diff -u -d -r1.138 -r1.139
--- mal_session.mx 16 Aug 2007 07:00:45 -0000 1.138
+++ mal_session.mx 16 Aug 2007 20:00:48 -0000 1.139
@@ -60,6 +60,7 @@
#include "mal_namespace.h"
#include "mal_readline.h"
#include "mal_authorize.h"
+#include "mal_sabaoth.h"
#include <gdk.h> /* for opendir and friends */
int
@@ -242,92 +243,43 @@
if (database && database[0] != '\0' &&
strcmp(database, GDKgetenv("gdk_dbname")) != 0)
{
- DIR *d;
- struct dirent *e;
- int found = 0;
- str buf = alloca(sizeof(char) * (PATHLENGTH + 1));
- str p;
- int len;
- FILE *f;
- str err = NULL;
- str redir;
+ sabdb *stats;
+ str err;
- buf[PATHLENGTH] = '\0';
- /* scan the parent for directories */
- d = opendir("..");
- while ((e = readdir(d)) != NULL) {
- /* skip if not the database we're looking for */
- if (strcmp(e->d_name, database) != 0)
- continue;
+ err = SABAOTHgetStatus(&stats, database);
+ if (err != MAL_SUCCEED) {
+ /* this is kind of awful, but we need to get rid of this
+ * message */
+ fprintf(stderr, "!SABAOTHgetStatus: %s\n", err);
+ GDKfree(err);
+ return;
+ }
- /* ok, look for some files we're interested in, start
- * checking if the server is connectable */
- snprintf(buf, PATHLENGTH, "../%s/.conn", e->d_name);
- if ((f = fopen(buf, "r")) == NULL) {
- err = "database not available or cannot be
connected to";
- break; /* we don't have to look further any
more */
- }
- if ((len = fread(buf, 1, PATHLENGTH, f)) <= 0) {
- /* ok, won't work */
- fclose(f);
- err = "database cannot be connected to";
- break;
- }
- buf[len] = '\0';
- /* note: in theory, multiple addresses can be in this
file.
- * We ignore this for now, and just connect to the
first one */
- if ((p = strchr(buf, '\n')) == NULL) {
- /* somehow doesn't work */
- fclose(f);
- err = "database cannot be connected to";
+ if (stats != NULL &&
+ stats->conns != NULL &&
+ stats->conns->val != NULL)
+ {
+ switch (stats->state) {
+ case SABdbRunning:
+ stream_printf(fout, "^%s%s\n",
+ stats->conns->val,
stats->dbname);
+ stream_flush(fout);
break;
- }
- *p = '\0';
- fclose(f);
-
- /* alloc some space */
- redir = alloca(sizeof(char) * (strlen(buf) + 2));
- sprintf(redir, "^%s", buf);
-
- /* see if the server supports the language we're asking
for */
- snprintf(buf, PATHLENGTH, "../%s/.scen", e->d_name);
- if ((f = fopen(buf, "r")) == NULL) {
- err = "language not supported";
+ case SABdbCrashed:
+ case SABdbInactive:
+ stream_printf(fout, "!database %s
currently "
+ "not available\n",
stats->dbname);
+ stream_flush(fout);
break;
- }
- if ((len = fread(buf, 1, PATHLENGTH, f)) <= 0) {
- /* ok, won't work */
- fclose(f);
- err = "database cannot be connected to";
+ default:
+ fprintf(stderr, "!missing case
statement for SABsbState\n");
break;
}
- buf[len] = '\0';
- while ((p = strchr(buf, '\n')) != NULL) {
- *p = '\0';
- if (strcmp(buf, lang) == 0) {
- found = 1;
- break;
- }
- buf = p + 1;
- }
- fclose(f);
+ SABAOTHfreeStatus(&stats);
+ return;
+ }
- if (found == 1) {
- stream_printf(fout, "%s%s?lang=%s&user=%s\n",
- redir, database, buf, user);
- /* flush redirect and return */
- stream_flush(fout);
- closedir(d);
- GDKfree(command);
- return;
- } else {
- err = "language not supported";
- break;
- }
- }
- (void) closedir(d);
- if (err == NULL) err = "database does not exist";
- stream_printf(fout, "!redirect to database '%s': %s\n",
database, err);
+ stream_printf(fout, "!database '%s' does not exist\n",
database);
/* flush the error to the client, and abort further execution */
stream_flush(fout);
GDKfree(command);
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Monetdb-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-checkins