|
|
1.1 ! root 1: #include "mail.h" ! 2: #include "string.h" ! 3: #include "dest.h" ! 4: ! 5: /* imports */ ! 6: extern char *malloc(); ! 7: extern void exit(); ! 8: ! 9: /* exports */ ! 10: dest *dlist; ! 11: ! 12: extern dest* ! 13: d_new(addr) ! 14: string *addr; ! 15: { ! 16: dest *dp; ! 17: ! 18: dp = (dest *)malloc(sizeof(dest)); ! 19: if (dp == NULL) { ! 20: perror("destnew"); ! 21: exit(1); ! 22: } ! 23: dp->same = dp; ! 24: dp->nsame = 1; ! 25: dp->nchar = 0; ! 26: dp->next = dp; ! 27: dp->addr = addr; ! 28: dp->parent = NULL; ! 29: dp->repl1 = dp->repl2 = NULL; ! 30: dp->status = d_undefined; ! 31: dp->uid = dp->gid = -1; ! 32: return dp; ! 33: } ! 34: ! 35: extern void ! 36: d_free(dp) ! 37: dest *dp; ! 38: { ! 39: if (dp != NULL) { ! 40: s_free(dp->addr); ! 41: s_free(dp->repl1); ! 42: s_free(dp->repl2); ! 43: free((char *)dp); ! 44: } ! 45: } ! 46: ! 47: /* The following routines manipulate an ordered list of items. Insertions ! 48: * are always to the end of the list. Deletions are from the beginning. ! 49: * ! 50: * The list are circular witht the `head' of the list being the last item ! 51: * added. ! 52: */ ! 53: ! 54: /* Get first element from a circular list linked via 'next'. */ ! 55: extern dest * ! 56: d_rm(listp) ! 57: dest **listp; ! 58: { ! 59: dest *dp; ! 60: ! 61: if (*listp == NULL) ! 62: return NULL; ! 63: dp = (*listp)->next; ! 64: if (dp == *listp) ! 65: *listp = NULL; ! 66: else ! 67: (*listp)->next = dp->next; ! 68: dp->next = dp; ! 69: return dp; ! 70: } ! 71: ! 72: /* Insert a new entry at the end of the list linked via 'next'. */ ! 73: extern void ! 74: d_insert(listp, new) ! 75: dest **listp; /* pointer to current list */ ! 76: dest *new; /* list to be added */ ! 77: { ! 78: dest *head; ! 79: ! 80: if (*listp == NULL) { ! 81: *listp = new; ! 82: return; ! 83: } ! 84: if (new == NULL) ! 85: return; ! 86: head = new->next; ! 87: new->next = (*listp)->next; ! 88: (*listp)->next = head; ! 89: return; ! 90: } ! 91: ! 92: /* Get first element from a circular list linked via 'same'. */ ! 93: extern dest * ! 94: d_rm_same(listp) ! 95: dest **listp; ! 96: { ! 97: dest *dp; ! 98: ! 99: if (*listp == NULL) ! 100: return NULL; ! 101: dp = (*listp)->same; ! 102: if (dp == *listp) ! 103: *listp = NULL; ! 104: else ! 105: (*listp)->same = dp->same; ! 106: dp->same = dp; ! 107: return dp; ! 108: } ! 109: ! 110: /* Insert an entry into the corresponding list linked by 'same'. Note that ! 111: * the basic structure is a list of lists. ! 112: */ ! 113: extern void ! 114: d_same_insert(listp, new) ! 115: dest **listp; /* pointer to current list */ ! 116: dest *new; /* new dest (or null terminated list of dests) */ ! 117: { ! 118: dest *dp; ! 119: int len; ! 120: ! 121: if(new->status == d_pipe) { ! 122: len = new->repl2 ? strlen(s_to_c(new->repl2)) : 0; ! 123: if(*listp != NULL){ ! 124: dp = (*listp)->next; ! 125: do { ! 126: if(dp->status == new->status ! 127: && dp->nsame < MAXSAME ! 128: && dp->nchar + len < MAXSAMECHAR ! 129: && strcmp(s_to_c(dp->repl1), s_to_c(new->repl1))==0 ! 130: && dp->uid == new->uid && dp->gid == new->gid){ ! 131: new->same = dp->same; ! 132: dp->same = new; ! 133: dp->nchar += len + 1; ! 134: dp->nsame++; ! 135: return; ! 136: } ! 137: dp = dp->next; ! 138: } while (dp != (*listp)->next); ! 139: } ! 140: new->nchar = strlen(s_to_c(new->repl1)) + len + 1; ! 141: } ! 142: new->next = new; ! 143: d_insert(listp, new); ! 144: } ! 145: ! 146: /* expand a string of destinations into a linked list of destiniations */ ! 147: extern dest * ! 148: s_to_dest(sp, parent) ! 149: string *sp; ! 150: dest *parent; /* parent of new destinations */ ! 151: { ! 152: string *addr; ! 153: dest *list=NULL; ! 154: dest *new; ! 155: ! 156: if (sp == NULL) ! 157: return NULL; ! 158: addr = s_new(); ! 159: while (s_parse(sp, addr)!=NULL) { ! 160: if(shellchars(s_to_c(addr))){ ! 161: while(new = d_rm(&list)) ! 162: d_free(new); ! 163: break; ! 164: } ! 165: new = d_new(addr); ! 166: new->parent = parent; ! 167: new->authorized = parent->authorized; ! 168: d_insert(&list, new); ! 169: addr = s_new(); ! 170: } ! 171: s_free(addr); ! 172: return list; ! 173: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.