]> andersk Git - moira.git/blobdiff - server/cache.dc
Diane Delgado's changes for a fixed table-locking order
[moira.git] / server / cache.dc
index 5a294e71558b5c50a3ad97d1069d34f426b2410d..6ee13326251aab7a76a2e0a32c40c96b75394bd2 100644 (file)
@@ -30,6 +30,7 @@ extern int ingres_errno, mr_errcode;
  *             List
  *             String
  *             Machine
+ *             Subnet
  *             Cluster
  *             Filesystem
  *    then we will have to rework the code that only looks at the first
@@ -110,17 +111,16 @@ int *id;
 {
     register struct item *i, *t;
     EXEC SQL BEGIN DECLARE SECTION;
-    char iname[128];
+    char *iname;
     int j, rowcount;
     EXEC SQL END DECLARE SECTION;
+    char key;
     int h, ctr;
 
-    undouble_single_quotes(iname,name);
-
-    h = hashname(iname, type);
+    h = hashname(name, type);
     for (i = cachehead.next; i != &cachehead; i = i->next) {
        if (i->nhash != h ||
-           strcmp(iname, i->name) ||
+           strcmp(name, i->name) ||
            strcasecmp(type, i->type))
          continue;
        *id = i->id;
@@ -135,11 +135,16 @@ int *id;
     }
 
     cachemisses++;
+    iname = name;
+    key = *type;
+
+    if (!strcasecmp(type, "subnet"))
+      key = 'N';
 
-    switch (*type) {
+    switch (key) {
     case 'U':
     case 'u':
-       if (index(iname, '@')) {
+       if (index(iname, '@') || (strlen(iname) > 8)) {
            sqlca.sqlcode = 100;
            break;
        }
@@ -153,6 +158,10 @@ int *id;
     case 'm':
        EXEC SQL SELECT mach_id INTO :j FROM machine WHERE name=UPPERCASE(:iname);
        break;
+    case 'N':
+    case 'n':
+       EXEC SQL SELECT snet_id INTO :j FROM subnet WHERE name=UPPERCASE(:iname);
+       break;
     case 'C':
     case 'c':
        EXEC SQL SELECT clu_id INTO :j FROM cluster WHERE name=:iname;
@@ -175,7 +184,7 @@ int *id;
     if (sqlca.sqlcode != 0)
       return(MR_INGRES_ERR);
     *id = j;
-    if (iname[0] == '#' && !strcasecmp(type, "USER"))
+    if (name[0] == '#' && !strcasecmp(type, "USER"))
       return(MR_SUCCESS);
     if (cachesize < CACHESIZE) {
        i = (struct item *) malloc(sizeof(struct item));
@@ -185,7 +194,7 @@ int *id;
        cachehead.prev = i->prev;
        i->prev->next = &cachehead;
     }
-    strcpy(i->name, iname);
+    strcpy(i->name, name);
     strcpy(i->type, type);
     i->nhash = h;
     i->id = j;
@@ -203,20 +212,6 @@ int *id;
 }
 
 
-undouble_single_quotes(to, from)
-char *to;
-char *from;
-{
-    register char *t,*f;
-
-    for(t=to,f=from; *f; ) {
-       if(*f=='\'' && f[1]=='\'') f++;
-       *t++ = *f++;
-    }
-    *t='\0';
-}
-
-
 /* Perform an ID to name mapping.  name should be a pointer to a pointer to
  * malloc'ed data.  The buffer it refers to will be freed, and a new buffer
  * allocated with the answer.
@@ -232,6 +227,7 @@ char **name;
     char iname[NAMESZ];
     int j, rowcount;
     EXEC SQL END DECLARE SECTION;
+    char key;
     int ctr;
 
     for (i = cachehead.next; i != &cachehead; i = i->next) {
@@ -250,8 +246,11 @@ char **name;
 
     cachemisses++;
     j = id;
+    key = *type;
+    if (!strcasecmp(type, "subnet"))
+      key = 'N';
 
-    switch (*type) {
+    switch (key) {
     case 'U':
     case 'u':
        EXEC SQL SELECT CHAR(login) INTO :iname FROM users WHERE users_id=:j;
@@ -264,6 +263,10 @@ char **name;
     case 'm':
        EXEC SQL SELECT CHAR(name) INTO :iname FROM machine WHERE mach_id=:j;
        break;
+    case 'N':
+    case 'n':
+       EXEC SQL SELECT CHAR(name) INTO :iname FROM subnet WHERE snet_id=:j;
+       break;
     case 'C':
     case 'c':
        EXEC SQL SELECT CHAR(name) INTO :iname FROM cluster WHERE clu_id=:j;
This page took 0.042375 seconds and 4 git commands to generate.