Annotation of 43BSD/contrib/courier/lib/bind.c, revision 1.1.1.1

1.1       root        1: #ifndef lint
                      2: static char sccsid[] = "@(#)bind.c     4.2 (Berkeley) 7/7/83";
                      3: #endif
                      4: 
                      5: /*
                      6:  * Courier connection management.
                      7:  */
                      8: #include <stdio.h>
                      9: #include "courier.h"
                     10: 
                     11: #if DEBUG
                     12: extern int CourierClientDebuggingFlag;
                     13: #endif
                     14: 
                     15: #define NBINDINGS      10
                     16: 
                     17: struct binding {
                     18:        char *program;          /* Courier program name or 0 */
                     19:        char *machine;          /* machine name */
                     20:        int connection;         /* open connection descriptor */
                     21: } btab[NBINDINGS];
                     22: 
                     23: CourierProgram(program, machine)
                     24:        char *program, *machine;
                     25: {
                     26:        register struct binding *bp, *x;
                     27:        extern char *malloc();
                     28: 
                     29:        x = 0;
                     30:        for (bp = &btab[0]; bp < &btab[NBINDINGS]; bp++)
                     31:                if (bp->program != 0) {
                     32:                        if (strcmp(bp->program, program) == 0 &&
                     33:                            strcmp(bp->machine, machine) == 0)
                     34:                                if (bp->connection >= 0)
                     35:                                        return (bp->connection);
                     36:                                else
                     37:                                        goto connect;
                     38:                } else
                     39:                        x = bp;
                     40:        if (x == 0) {
                     41:                fprintf(stderr, "Too many active Courier programs.\n");
                     42:                exit(1);
                     43:        }
                     44:        bp = x;
                     45:        bp->program = malloc(strlen(program)+1);
                     46:        strcpy(bp->program, program);
                     47:        bp->machine = malloc(strlen(machine)+1);
                     48:        strcpy(bp->machine, machine);
                     49: connect:
                     50:        bp->connection = CourierActivate(bp->program, bp->machine);
                     51:        if (bp->connection >= 0)
                     52:                return (bp->connection);
                     53: }
                     54: 
                     55: CourierDeactivate(program, machine)
                     56:        char *program, *machine;
                     57: {
                     58:        register struct binding *bp;
                     59: 
                     60:        for (bp = &btab[0]; bp < &btab[NBINDINGS]; bp++)
                     61:                if (bp->program != 0 &&
                     62:                    strcmp(bp->program, program) == 0 &&
                     63:                    strcmp(bp->machine, machine) == 0) {
                     64:                        free(bp->program);
                     65:                        free(bp->machine);
                     66:                        close(bp->connection);
                     67:                        bp->program = 0;
                     68:                        bp->machine = 0;
                     69:                        bp->connection = -1;
                     70:                        return;
                     71:                }
                     72: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.