]> andersk Git - moira.git/blobdiff - server/cache.dc
missing SRCDIR; ifdef on GDSS
[moira.git] / server / cache.dc
index 23087adb38f05b4ac304eb7132f423bee75fcebe..85b0688be729c23c53e85a8e2681fd9c7e7ea3dc 100644 (file)
@@ -15,6 +15,8 @@ static char *rcsid_cache_dc = "$Header$";
 #include "mr_server.h"
 EXEC SQL INCLUDE sqlca;
 
+EXEC SQL WHENEVER SQLERROR CALL ingerr;
+
 extern char *whoami, *strsave();
 extern int ingres_errno, mr_errcode;
 
@@ -47,6 +49,7 @@ struct item {
     int id;
     struct item *next;
     struct item *prev;
+    struct item *trans;                /* keep track of transactions */
 };
 
 static struct item cachehead;
@@ -92,6 +95,7 @@ flush_cache()
     if (cachehead.prev != &cachehead)
       free(cachehead.prev);
     cachehead.next = cachehead.prev = &cachehead;
+    cachehead.trans = (struct item *)NULL;
 }
 
 
@@ -104,7 +108,7 @@ char *name;
 char *type;
 int *id;
 {
-    register struct item *i;
+    register struct item *i, *t;
     EXEC SQL BEGIN DECLARE SECTION;
     char *iname;
     int j, rowcount;
@@ -134,6 +138,10 @@ int *id;
     switch (*type) {
     case 'U':
     case 'u':
+       if (index(iname, '@') || (strlen(iname) > 8)) {
+           sqlca.sqlcode = 100;
+           break;
+       }
        EXEC SQL SELECT users_id INTO :j FROM users WHERE login=:iname;
        break;
     case 'L':
@@ -142,8 +150,7 @@ int *id;
        break;
     case 'M':
     case 'm':
-       uppercase(iname);
-       EXEC SQL SELECT mach_id INTO :j FROM machine WHERE name=:iname;
+       EXEC SQL SELECT mach_id INTO :j FROM machine WHERE name=UPPERCASE(:iname);
        break;
     case 'C':
     case 'c':
@@ -185,6 +192,12 @@ int *id;
     i->prev = &cachehead;
     cachehead.next->prev = i;
     cachehead.next = i;
+    /* find the end of the transaction chain & add this item */
+    for (t = &cachehead; t->trans && t != i; t = t->trans);
+    if (t != i) {
+       t->trans = i;
+       i->trans = (struct item *)NULL;
+    }
     return(MR_SUCCESS);
 }
 
@@ -199,7 +212,7 @@ int id;
 char *type;
 char **name;
 {
-    register struct item *i;
+    register struct item *i, *t;
     EXEC SQL BEGIN DECLARE SECTION;
     char iname[NAMESZ];
     int j, rowcount;
@@ -226,27 +239,27 @@ char **name;
     switch (*type) {
     case 'U':
     case 'u':
-       EXEC SQL SELECT login INTO :iname FROM users WHERE users_id=:j;
+       EXEC SQL SELECT CHAR(login) INTO :iname FROM users WHERE users_id=:j;
        break;
     case 'L':
     case 'l':
-       EXEC SQL SELECT name INTO :iname FROM list WHERE list_id=:j;
+       EXEC SQL SELECT CHAR(name) INTO :iname FROM list WHERE list_id=:j;
        break;
     case 'M':
     case 'm':
-       EXEC SQL SELECT name INTO :iname FROM machine WHERE mach_id=:j;
+       EXEC SQL SELECT CHAR(name) INTO :iname FROM machine WHERE mach_id=:j;
        break;
     case 'C':
     case 'c':
-       EXEC SQL SELECT name INTO :iname FROM cluster WHERE clu_id=:j;
+       EXEC SQL SELECT CHAR(name) INTO :iname FROM cluster WHERE clu_id=:j;
        break;
     case 'F':
     case 'f':
-       EXEC SQL SELECT label INTO :iname FROM filesys WHERE filsys_id=:j;
+       EXEC SQL SELECT CHAR(label) INTO :iname FROM filesys WHERE filsys_id=:j;
        break;
     case 'S':
     case 's':
-       EXEC SQL SELECT string INTO :iname FROM strings WHERE string_id=:j;
+       EXEC SQL SELECT CHAR(string) INTO :iname FROM strings WHERE string_id=:j;
        break;
     default:
        return(MR_INTERNAL);
@@ -281,6 +294,12 @@ char **name;
     i->prev = &cachehead;
     cachehead.next->prev = i;
     cachehead.next = i;
+    /* find the end of the transaction chain & add this item */
+    for (t = &cachehead; t->trans && t != i; t = t->trans);
+    if (t != i) {
+       t->trans = i;
+       i->trans = (struct item *)NULL;
+    }
     return(MR_SUCCESS);
 }
 
@@ -294,11 +313,16 @@ char *name;
 char *type;
 int id;
 {
-    register struct item *i;
+    register struct item *i, *t;
 
     for (i = cachehead.next; i != &cachehead; i = i->next)
-      if (i->id == id && !strcmp(i->type, type))
-       return(MR_SUCCESS);
+      if (i->id == id && !strcmp(i->type, type)) {
+         if (strcmp(i->name, name)) {
+             strcpy(i->name, name);
+             i->nhash = hashname(name, type);
+         }
+         return(MR_SUCCESS);
+      }
     if (cachesize < CACHESIZE) {
        i = (struct item *) malloc(sizeof(struct item));
        cachesize++;
@@ -315,6 +339,12 @@ int id;
     i->prev = &cachehead;
     cachehead.next->prev = i;
     cachehead.next = i;
+    /* find the end of the transaction chain & add this item */
+    for (t = &cachehead; t->trans && t != i; t = t->trans);
+    if (t != i) {
+       t->trans = i;
+       i->trans = (struct item *)NULL;
+    }
     return(MR_SUCCESS);
 }
 
@@ -340,3 +370,29 @@ char *type;
        }
     }
 }
+
+
+/* Called when a transaction is committed to also commit any cache changes.
+ * Just throws away the list of cache changes for this transaction.
+ */
+
+cache_commit()
+{
+    cachehead.trans = (struct item *)NULL;
+}
+
+
+/* Called whan a transaction is aborted to throw away any cache changes
+ * from that transaction.
+ */
+
+cache_abort()
+{
+    register struct item *i, *t;
+
+    for (i = cachehead.trans; i; i = t) {
+       t = i->trans;
+       flush_name(i->name, i->type);
+    }
+    cachehead.trans = (struct item *)NULL;
+}
This page took 0.04263 seconds and 4 git commands to generate.