]> andersk Git - moira.git/blobdiff - server/qsupport.qc
added name<->id cache; new incremental update scheme
[moira.git] / server / qsupport.qc
index a662e041cf26d9f67bd0962ad34873b0aa6b901c..ed429559f90d6591de50f6e7d9a7cf647bd3fb16 100644 (file)
@@ -690,22 +690,36 @@ setup_ufil(q, argv)
 ##{
     int mach_id, status;
     char *type, *name, *access;  
-##  int fid;
+##  int fid, total;
 
     type = argv[2];
     mach_id = *(int *)argv[3];
     name = argv[4];
     access = argv[6];
     var_phys_id = 0;
+    fid = *(int *)argv[0];
 
     if (!strcmp(type, "NFS")) {
        status = check_nfs(mach_id, name, access);
-       fid = *(int *)argv[0];
 ##     replace nfsquota (phys_id = var_phys_id) where nfsquota.filsys_id = fid
        if (ingres_errno) return(sms_errcode);
        return(status);
-    } else
-      return(SMS_SUCCESS);
+    } else if (!strcmp(type, "AFS")) {
+       total = 0;
+##     retrieve (total = sum(nfsquota.quota where nfsquota.filsys_id = fid))
+       if (ingres_errno) return(sms_errcode);
+       if (total != 0) {
+##         delete nfsquota where nfsquota.filsys_id = fid
+           if (ingres_errno) return(sms_errcode);
+##         append nfsquota (quota = total, filsys_id = fid,
+##                          phys_id = 0, users_id = 0)
+           if (ingres_errno) return(sms_errcode);
+       }
+    } else {
+##     replace nfsquota (phys_id = 0) where nfsquota.filsys_id = fid
+       if (ingres_errno) return(sms_errcode);
+    }
+    return(SMS_SUCCESS);
 ##}
 
 
@@ -727,7 +741,8 @@ setup_ufil(q, argv)
     register char *cp2;
 
     caccess = (isupper(*access)) ? tolower(*access) : *access;
-    if (caccess != 'r' && caccess != 'w') return(SMS_FILESYS_ACCESS);
+    if (caccess != 'r' && caccess != 'w' && caccess != 'n')
+      return(SMS_FILESYS_ACCESS);
 
     status = SMS_NFS;
 ##  range of np is nfsphys
@@ -1377,53 +1392,6 @@ followup_glin(q, sq, v, action, actarg, cl)
 ##}
 
 
-/** followup_amtl - followup for amtl and dmfl; when adding a list 
- **                 member to a maillist, make member list a maillist also
- **                 unless list is a user-group.
- **                 Then set_list_modtime_by_id.
- **
- ** Inputs:
- **   argv[0] - list_id
- **   argv[1] - member_type
- **   argv[2] - member_id
- **
- **/
-
-followup_amtl(q, argv, cl)
-    struct query *q;
-    char *argv[];
-    client *cl;
-##{
-##  int list_id;
-##  int member_id;
-##  int exists, who;
-##  char *entity;
-
-    list_id = *(int *)argv[0];
-    entity = cl->entity;
-    who = cl->client_id;
-
-##  range of l is list
-##  repeat replace l (modtime = "now", modby = @who, modwith = @entity)
-##      where l.#list_id = @list_id
-
-    /* if query is not amtl or if member_type is not LIST then return */
-    if (bcmp(q->shortname, "amtl", 4) || bcmp(argv[1], "LIST", 4)) 
-       return(SMS_SUCCESS);
-
-    member_id = *(int *)argv[2];
-
-    /* is parent list a mailing list? */
-##  repeat retrieve (exists = l.maillist) where l.#list_id=@list_id
-    if (!exists)
-       return(SMS_SUCCESS);
-
-    /* list is not a user-group; add list to maillist table */
-##  repeat replace l (maillist = 1) where l.#list_id = @member_id
-    return(SMS_SUCCESS);
-##}
-
-
 /* followup_gnfq: Fix the directory name & modby fields
  *   argv[0] = filsys_id
  *   argv[2] = ascii(quota)
@@ -1691,6 +1659,8 @@ int set_pobox(q, argv, cl)
 ##             where users.users_id = @user
        set_pop_usage(id, 1);
     } else if (!strcmp(argv[1], "SMTP")) {
+       if (index(box, '/') || index(box, '|'))
+         return(SMS_BAD_CHAR);
 ##      range of s is strings
 ##      repeat retrieve (id = s.string_id) where s.string = @box
 ##      inquire_equel (rowcount = "rowcount")
@@ -1729,7 +1699,7 @@ get_list_info(q, aargv, cl, action, actarg)
 ##{
     char *argv[13], *malloc(), *realloc();
 ##  char *name, acl_type[9], listname[33], active[5], public[5], hidden[5];
-##  char maillist[5], group[5], gid[6], acl_name[33], desc[256], modtime[27];
+##  char maillist[5], group[5], gid[6], acl_name[256], desc[256], modtime[27];
 ##  char modby[256], modwith[9];
 ##  int id, rowcount, acl_id, hid, modby_id;
     int returned;
@@ -1830,10 +1800,10 @@ int add_member_to_list(q, argv, cl)
     char **argv;
     client *cl;
 ##{
-##  int id, lid, mid, exists, error;
-##  char *mtype, dtype[9];
-    int ancestors[MAXLISTDEPTH], acount, a;
-    int descendants[MAXLISTDEPTH], dcount, d;
+##  int id, lid, mid, exists, error, who, ref;
+##  char *mtype, dtype[9], buf[256], *entity;
+    int ancestors[MAXLISTDEPTH], aref[MAXLISTDEPTH], acount, a;
+    int descendants[MAXLISTDEPTH], dref[MAXLISTDEPTH], dcount, d;
     char *dtypes[MAXLISTDEPTH];
     char *iargv[3];
 
@@ -1841,15 +1811,24 @@ int add_member_to_list(q, argv, cl)
     lid = *(int *)argv[0];
     mtype = argv[1];
     mid = *(int *)argv[2];
+    /* if the member is already a direct member of the list, punt */
 ##  repeat retrieve (exists = any(m.list_id where m.list_id=@lid and 
 ##                        m.member_id = @mid and m.member_type = @mtype
 ##                        and m.direct = 1))
     if (exists)
       return(SMS_EXISTS);
+    if (!strcasecmp(mtype, "STRING")) {
+##     repeat retrieve (buf = strings.string) where strings.string_id = @mid
+       if (index(buf, '/') || index(buf, '|'))
+         return(SMS_BAD_CHAR);
+    }
+
     ancestors[0] = lid;
+    aref[0] = 1;
     acount = 1;
-##  repeat retrieve (id = m.list_id)
+##  repeat retrieve (id = m.list_id, ref = m.ref_count)
 ##     where m.member_id = @lid and m.member_type = "LIST" {
+       aref[acount] = ref;
        ancestors[acount++] = id;
        if (acount >= MAXLISTDEPTH) {
 ##         endretrieve
@@ -1861,10 +1840,12 @@ int add_member_to_list(q, argv, cl)
     }
     descendants[0] = mid;
     dtypes[0] = mtype;
+    dref[0] = 1;
     dcount = 1;
     error = 0;
     if (!strcmp(mtype, "LIST")) {
-##     repeat retrieve (id = m.member_id, dtype = m.member_type)
+##     repeat retrieve (id = m.member_id, dtype = m.member_type,
+##                      ref = m.ref_count)
 ##       where m.list_id = @mid {
            switch (dtype[0]) {
            case 'L':
@@ -1883,6 +1864,7 @@ int add_member_to_list(q, argv, cl)
                error++;
 ##             endretrieve
            }
+           dref[dcount] = ref;
            descendants[dcount++] = id;
            if (dcount >= MAXLISTDEPTH) {
                error++;
@@ -1904,13 +1886,14 @@ int add_member_to_list(q, argv, cl)
 ##         repeat retrieve (exists = any(m.ref_count where m.list_id = @lid
 ##                                      and m.member_id = @mid
 ##                                      and m.member_type = @mtype))
+           ref = aref[a] * dref[d];
            if (exists) {
                if (a == 0 && d == 0)
-##               replace m (ref_count = m.ref_count+1, direct = 1)
+##               replace m (ref_count = m.ref_count+ref, direct = 1)
 ##                          where m.list_id = lid and m.member_id = mid and
 ##                          m.member_type = mtype
                else
-##               replace m (ref_count = m.ref_count+1)
+##               replace m (ref_count = m.ref_count+ref)
 ##                          where m.list_id = lid and m.member_id = mid and
 ##                          m.member_type = mtype
            } else {
@@ -1920,7 +1903,7 @@ int add_member_to_list(q, argv, cl)
 ##                                member_type=mtype, ref_count = 1)
                else
 ##               append imembers (list_id=lid, member_id = mid,
-##                                member_type=mtype, ref_count = 1)
+##                                member_type=mtype, ref_count = ref)
                iargv[0] = (char *)lid;
                iargv[1] = mtype;
                iargv[2] = (char *)mid;
@@ -1928,6 +1911,11 @@ int add_member_to_list(q, argv, cl)
            }
        }
     }
+    lid = *(int *)argv[0];
+    entity = cl->entity;
+    who = cl->client_id;
+##  repeat replace list (modtime = "now", modby = @who, modwith = @entity)
+##      where list.#list_id = @lid
     if (ingres_errno) return(sms_errcode);
     return(SMS_SUCCESS);
 ##}
@@ -1941,10 +1929,10 @@ int delete_member_from_list(q, argv, cl)
     char **argv;
     client *cl;
 ##{
-##  int id, lid, mid, cnt, exists, error;
-##  char *mtype, dtype[9];
-    int ancestors[MAXLISTDEPTH], acount, a;
-    int descendants[MAXLISTDEPTH], dcount, d;
+##  int id, lid, mid, cnt, exists, error, who, ref;
+##  char *mtype, dtype[9], *entity;
+    int ancestors[MAXLISTDEPTH], aref[MAXLISTDEPTH], acount, a;
+    int descendants[MAXLISTDEPTH], dref[MAXLISTDEPTH], dcount, d;
     char *dtypes[MAXLISTDEPTH];
     char *iargv[3];
 
@@ -1952,6 +1940,7 @@ int delete_member_from_list(q, argv, cl)
     lid = *(int *)argv[0];
     mtype = argv[1];
     mid = *(int *)argv[2];
+    /* if the member is not a direct member of the list, punt */
 ##  repeat retrieve (exists = any(m.list_id where m.list_id=@lid and 
 ##                        m.member_id = @mid and m.member_type = @mtype
 ##                        and m.direct = 1))
@@ -1959,9 +1948,11 @@ int delete_member_from_list(q, argv, cl)
     if (!exists)
       return(SMS_NO_MATCH);
     ancestors[0] = lid;
+    aref[0] = 1;
     acount = 1;
-##  repeat retrieve (id = m.list_id)
+##  repeat retrieve (id = m.list_id, ref = m.ref_count)
 ##     where m.member_id = @lid and m.member_type = "LIST" {
+       aref[acount] = ref;
        ancestors[acount++] = id;
        if (acount >= MAXLISTDEPTH)
 ##       endretrieve
@@ -1971,10 +1962,12 @@ int delete_member_from_list(q, argv, cl)
       return(SMS_INTERNAL);
     descendants[0] = mid;
     dtypes[0] = mtype;
+    dref[0] = 1;
     dcount = 1;
     error = 0;
     if (!strcmp(mtype, "LIST")) {
-##     repeat retrieve (id = m.member_id, dtype = m.member_type)
+##     repeat retrieve (id = m.member_id, dtype = m.member_type,
+##                      ref = m.ref_count)
 ##       where m.list_id = @mid {
            switch (dtype[0]) {
            case 'L':
@@ -1993,6 +1986,7 @@ int delete_member_from_list(q, argv, cl)
                error++;
 ##             endretrieve
            }
+           dref[dcount] = ref;
            descendants[dcount++] = id;
            if (dcount >= MAXLISTDEPTH)
 ##           endretrieve
@@ -2012,7 +2006,8 @@ int delete_member_from_list(q, argv, cl)
 ##         repeat retrieve (cnt = m.ref_count)
 ##             where m.list_id = @lid and m.member_id = @mid
 ##               and m.member_type = @mtype
-           if (cnt <= 1) {
+           ref = aref[a] * dref[d];
+           if (cnt <= ref) {
                iargv[0] = (char *)lid;
                iargv[1] = mtype;
                iargv[2] = (char *)mid;
@@ -2021,16 +2016,21 @@ int delete_member_from_list(q, argv, cl)
 ##                 m.member_type = mtype
                incremental_clear_after();
            } else if (a == 0 && d == 0) {
-##             replace m (ref_count = m.ref_count-1, direct = 0)
+##             replace m (ref_count = m.ref_count-ref, direct = 0)
 ##                 where m.list_id = lid and m.member_id = mid and
 ##                 m.member_type = mtype
            } else {
-##             replace m (ref_count = m.ref_count-1)
-##                 where m.list_id = lid and m.member_idn = mid and
+##             replace m (ref_count = m.ref_count-ref)
+##                 where m.list_id = lid and m.member_id = mid and
 ##                 m.member_type = mtype
            }
        }
     }
+    lid = *(int *)argv[0];
+    entity = cl->entity;
+    who = cl->client_id;
+##  repeat replace list (modtime = "now", modby = @who, modwith = @entity)
+##      where list.#list_id = @lid
     if (ingres_errno) return(sms_errcode);
     return(SMS_SUCCESS);
 ##}
@@ -2236,6 +2236,7 @@ int get_lists_of_member(q, argv, cl, action, actarg)
     rargv[3] = hidden;
     rargv[4] = maillist;
     rargv[5] = group;
+##  range of m is imembers
     if (direct) {
 ##    repeat retrieve (name = list.#name, active = text(list.#active), 
 ##                  public = text(list.#public), hidden = text(list.#hidden),
@@ -2608,7 +2609,7 @@ register_user(q, argv, cl)
 ##  inquire_equel(rowcount = "rowcount");
     if (rowcount != 1)
       return(SMS_INTERNAL);
-    incremental_after("members", 0, argv);
+    incremental_after("members", 0, aargv);
     com_err(whoami, 0, "group list created");
 
     /* decide where to put filesystem */
@@ -2677,7 +2678,7 @@ register_user(q, argv, cl)
     aargv[0] = login;
     aargv[1] = login;
     sprintf(buffer, "nq.users_id = %d and nq.filsys_id = values.value and values.name = \"filsys_id\"", users_id);
-    incremental_after("nfsquota", buffer, argv);
+    incremental_after("nfsquota", buffer, aargv);
     com_err(whoami, 0, "quota of %d assigned", quota);
     if (ingres_errno) return(sms_errcode);
 
@@ -3068,7 +3069,7 @@ validate_typedata(q, argv, vo)
 ##      repeat retrieve (id = s.string_id) where s.string = @name
 ##      inquire_equel (rowcount = "rowcount")
        if (rowcount == 0) {
-           if (q->type != APPEND) return(SMS_STRING);
+           if (q->type != APPEND && q->type != UPDATE) return(SMS_STRING);
 ##          range of v is values
 ##          retrieve (id = v.value) where v.#name = "strings_id"
            id++;
This page took 0.149144 seconds and 4 git commands to generate.