Annotation of 43BSDReno/contrib/isode-beta/others/idist/ops.c, revision 1.1.1.1

1.1       root        1: /* idist.c - remote distribution - initiator */
                      2: 
                      3: #ifndef        lint
                      4: static char *rcsid = "$Header: /f/osi/others/idist/RCS/ops.c,v 7.1 90/07/01 21:04:17 mrose Exp $";
                      5: #endif
                      6: 
                      7: /* 
                      8:  * $Header: /f/osi/others/idist/RCS/ops.c,v 7.1 90/07/01 21:04:17 mrose Exp $
                      9:  *
                     10:  * This file is entirely new, and handles the dispatching of the
                     11:  * remote operations to the server. It tries hard to remove all hint
                     12:  * of the ISODE parts and to hide the posy generated structures.
                     13:  *
                     14:  * Julian Onions <[email protected]>
                     15:  * Nottingham University Computer Science.
                     16:  * 
                     17:  *
                     18:  * $Log:       ops.c,v $
                     19:  * Revision 7.1  90/07/01  21:04:17  mrose
                     20:  * pepsy
                     21:  * 
                     22:  * Revision 7.0  89/11/23  21:58:40  mrose
                     23:  * Release 6.0
                     24:  * 
                     25:  */
                     26: 
                     27: 
                     28: #include <stdio.h>
                     29: #include "Idist-ops.h"         /* operation definitions */
                     30: #include "Idist-types.h"       /* type definitions */
                     31: #include "defs.h"
                     32: 
                     33: extern struct type_Idist_FileSpec *makefs ();
                     34: static void print_ia5list ();
                     35: 
                     36: int    basic_error ();
                     37: int    null_result (), ia5_result (), query_result ();
                     38: 
                     39: int    result_value;
                     40: 
                     41: int  initdir (flag, dest)
                     42: int    flag;
                     43: char   *dest;
                     44: {
                     45:     struct qbuf *qb;
                     46:     struct type_Idist_InitDir *idp;
                     47: 
                     48:     qb = str2qb (dest, strlen(dest), 1);
                     49:     idp = (struct type_Idist_InitDir *) malloc (sizeof *idp);
                     50:     if (idp == (struct type_Idist_InitDir *)0)
                     51:            adios ("memory", "out of");
                     52:     if (flag) {
                     53:            idp -> offset = type_Idist_InitDir_destdir;
                     54:            idp -> un.destdir = qb;
                     55:     }
                     56:     else {
                     57:            idp -> offset = type_Idist_InitDir_nodestdir;
                     58:            idp -> un.nodestdir = qb;
                     59:     }
                     60:     return invoke (operation_Idist_init, (caddr_t)idp,
                     61:                   &_ZIdist_mod, _ZInitDirIdist,
                     62:                   null_result,
                     63:                   basic_error);
                     64: }
                     65: 
                     66: int    transfer (type, opts, mode, size, mtime, uname, group, name, lname)
                     67: unsigned short type, mode;
                     68: time_t mtime;
                     69: off_t  size;
                     70: int    opts;
                     71: char   *uname, *group, *name, *lname;
                     72: {
                     73:        struct type_Idist_FileSpec *fs;
                     74: 
                     75:        fs = makefs (type, opts, mode, size, mtime, 
                     76:                     uname, group, name, lname);
                     77: 
                     78:        return invoke (operation_Idist_transfer, (caddr_t)fs,
                     79:                       &_ZIdist_mod, _ZFileSpecIdist,
                     80:                       ia5_result,
                     81:                       basic_error);
                     82: }
                     83: 
                     84: 
                     85: terminate (type, status)
                     86: int    type;
                     87: int    status;
                     88: {
                     89:        struct type_Idist_TermStatus *ts;
                     90:        struct type_Idist_FileType      *makeftype ();
                     91: 
                     92:        if ((ts = (struct type_Idist_TermStatus *) malloc ( sizeof *ts)) == NULL)
                     93:                adios ("memory", "out of");
                     94:        ts -> filetype = makeftype ((unsigned short)type);
                     95:        ts -> status = (status == OK) ? 1 : 0;
                     96:        return invoke (operation_Idist_terminate, (caddr_t)ts,
                     97:                        &_ZIdist_mod, _ZTermStatusIdist,
                     98:                       null_result,
                     99:                       basic_error);
                    100: }
                    101: 
                    102: tran_data (data, len)
                    103: char   *data;
                    104: int    len;
                    105: {
                    106:        struct type_Idist_Data *dat;
                    107: 
                    108:        dat = str2qb (data, len, 1);
                    109: 
                    110:        return invoke (operation_Idist_data, (caddr_t)dat,
                    111:                       &_ZIdist_mod,_ZDataIdist,
                    112:                       null_result,
                    113:                       basic_error);
                    114: }
                    115: 
                    116: int    runspecial (cmd)
                    117: char   *cmd;
                    118: {
                    119:        struct type_UNIV_IA5String *ia5;
                    120: 
                    121:        ia5 = str2qb (cmd, strlen(cmd), 1);
                    122: 
                    123:        return invoke (operation_Idist_special, (caddr_t)ia5,
                    124:                       &_ZUNIV_mod, _ZIA5StringUNIV,
                    125:                       ia5_result,
                    126:                       basic_error);
                    127: }
                    128: 
                    129: static time_t  cmtime;
                    130: static off_t   csize;
                    131: static unsigned short cmode;
                    132: 
                    133: int    rquery (file, mtime, size, mode)
                    134: char   *file;
                    135: time_t *mtime;
                    136: off_t  *size;
                    137: unsigned short *mode;
                    138: {
                    139:        struct type_UNIV_IA5String *ia5;
                    140:        int     retval;
                    141: 
                    142:        ia5 = str2qb (file, strlen(file), 1);
                    143: 
                    144:        retval = invoke (operation_Idist_query, (caddr_t)ia5,
                    145:                         &_ZUNIV_mod, _ZIA5StringUNIV,
                    146:                         query_result,
                    147:                         basic_error);
                    148:        if (retval == NOTOK)
                    149:                return NOTOK;
                    150:        if (result_value != OK)
                    151:                return result_value;
                    152:        else {
                    153:                *mtime = cmtime;
                    154:                *mode = cmode;
                    155:                *size = csize;
                    156:                return OK;
                    157:        }
                    158: }
                    159: 
                    160: /* ARGSUSED */
                    161: query_result (sd, id, error, qr, roi)
                    162: int    sd, id, error;
                    163: struct type_Idist_QueryResult *qr;
                    164: struct RoSAPindication *roi;
                    165: {
                    166:        long    convtime ();
                    167: 
                    168:        result_value = OK;
                    169:        if (qr -> offset == type_Idist_QueryResult_doesntExist) {
                    170:                result_value = DONE;
                    171:                return OK;
                    172:        }
                    173:        else {
                    174:                cmode = 0;
                    175:                switch (qr -> un.doesExist -> filetype -> parm) {
                    176:                    case int_Idist_FileType_directory:
                    177:                        cmode = S_IFDIR;
                    178:                    case int_Idist_FileType_symlink:
                    179:                        if (cmode == 0)
                    180:                                cmode = S_IFLNK;
                    181:                    case int_Idist_FileType_regular:
                    182:                        if (cmode == 0)
                    183:                                cmode = S_IFREG;
                    184:                        cmtime = convtime (qr -> un.doesExist -> filemtime);
                    185:                        csize = qr -> un.doesExist -> filesize;
                    186:                        break;
                    187: 
                    188:                    default:
                    189:                        result_value = NOTOK;
                    190:                        return OK;
                    191:                }
                    192:                result_value = OK;
                    193:                return OK;
                    194:        }
                    195: }
                    196: 
                    197: static int copts;
                    198: rmchk (opts)
                    199: int    opts;
                    200: {
                    201:        int     listcdir_result ();
                    202: 
                    203:        copts = opts;
                    204:        return invoke (operation_Idist_listcdir, (caddr_t)NULL,
                    205:                    (modtyp *) 0, -1,
                    206:                    listcdir_result,
                    207:                    basic_error);
                    208: }
                    209: 
                    210: /* ARGSUSED */
                    211: int    listcdir_result (sd, id, error, files, roi)
                    212: int    sd, id, error;
                    213: struct type_Idist_FileList *files;
                    214: struct RoSAPindication *roi;
                    215: {
                    216:        struct type_Idist_FileList *fl;
                    217:        char    buf[BUFSIZ];
                    218:        char    *name;
                    219:        extern  char target[];
                    220:        struct stat stb;
                    221:        extern char basename[];
                    222: 
                    223:        for (fl = files; fl; fl = fl -> next) {
                    224:                name = qb2str (fl -> FileSpec -> filename);
                    225:                (void) sprintf (buf, "%s/%s", target, name);
                    226:                if (lstat (buf, &stb) < 0) {
                    227:                        if (copts & VERIFY)
                    228:                                printf ("need to remove: %s/%s\n",
                    229:                                        target, name);
                    230:                        else
                    231:                                (void) deletefile (name,
                    232:                                                   fl -> FileSpec -> filetype -> parm);
                    233:                }
                    234:                free (name);
                    235:        }
                    236:        return OK;
                    237: }
                    238: 
                    239: deletefile (str, mode)
                    240: char   *str;
                    241: int    mode;
                    242: {
                    243:        struct type_UNIV_IA5String *ia5;
                    244:        char    buffer[BUFSIZ];
                    245: 
                    246:        switch (mode) {
                    247:            case int_Idist_FileType_regular:
                    248:            case int_Idist_FileType_hardlink:
                    249:                mode = S_IFREG;
                    250:                break;
                    251:            case int_Idist_FileType_directory:
                    252:                mode = S_IFDIR;
                    253:                break;
                    254:            case int_Idist_FileType_symlink:
                    255:                mode = S_IFLNK;
                    256:                break;
                    257:            default:
                    258:                mode = 0;
                    259:                break;
                    260:        }
                    261: 
                    262:        (void) sprintf (buffer, "%s/%s", target, str);
                    263:        if ((copts & QUERYM) && !query ("Delete", mode, buffer))
                    264:                return OK;
                    265: 
                    266:        ia5 = str2qb (str, strlen(str), 1);
                    267: 
                    268:        return invoke (operation_Idist_deletefile, (caddr_t) ia5,
                    269:                        &_ZUNIV_mod, _ZIA5StringUNIV,
                    270:                       ia5_result,
                    271:                       basic_error);
                    272: }
                    273: 
                    274: 
                    275: /* ARGSUSED */
                    276: static int     basic_error (sd, id, error, parameter, roi)
                    277: int    sd, id, error;
                    278: struct type_Idist_IA5List *parameter;
                    279: struct RoSAPindication *roi;
                    280: {
                    281:        struct RyError *rye;
                    282: 
                    283:        if (error == RY_REJECT) {
                    284:                advise (NULLCP, "%s", RoErrString ((int) parameter));
                    285:                result_value = NOTOK;
                    286:                return OK;
                    287:        }
                    288: 
                    289:        if (rye = finderrbyerr (table_Idist_Errors, error))
                    290:                advise (NULLCP, "%s", rye -> rye_name);
                    291:        else
                    292:                advise (NULLCP, "Error %d", error);
                    293:        
                    294:        if (parameter)
                    295:                print_ia5list (parameter);
                    296: 
                    297:        result_value = NOTOK;
                    298:        return OK;
                    299: }
                    300: 
                    301: /* ARGSUSED */
                    302: 
                    303: static null_result (sd, id, dummy, result, roi)
                    304: int     sd,
                    305:         id,
                    306:         dummy;
                    307: caddr_t result;
                    308: struct RoSAPindication *roi;
                    309: {
                    310:        result_value = OK;
                    311:        return OK;
                    312: }
                    313: 
                    314: /* ARGSUSED */
                    315: static int ia5_result (sd, id, parameter, result, roi)
                    316: int     sd,
                    317:         id,
                    318:         parameter;
                    319: caddr_t result;
                    320: struct RoSAPindication *roi;
                    321: {
                    322:        result_value = OK;
                    323:        print_ia5list ((struct type_Idist_IA5List *)result);
                    324:        return OK;
                    325: }
                    326: 
                    327: static  void print_ia5list (ia5)
                    328: register struct type_Idist_IA5List *ia5;
                    329: {
                    330:     register struct qbuf *p,
                    331:                          *q;
                    332:     
                    333:     for (; ia5; ia5 = ia5 -> next) {
                    334:         p = ia5 -> IA5String;
                    335:         for (q = p -> qb_forw; q != p ; q = q -> qb_forw)
                    336:             printf ("%*.*s", q -> qb_len, q -> qb_len, q -> qb_data);
                    337:         printf ("\n");
                    338:     }
                    339: }

unix.superglobalmegacorp.com

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