|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T o
Length: 7168 (0x1c00) Types: TextFile Names: »ops.c«
└─⟦3d0c2be1b⟧ Bits:30001254 ISODE-5.0 Tape └─⟦eba4602b1⟧ »./isode-5.0.tar.Z« └─⟦d3ac74d73⟧ └─⟦this⟧ »isode-5.0/others/idist/ops.c«
/* idist.c - remote distribution - initiator */ #ifndef lint static char *rcsid = "$Header: /f/osi/others/idist/RCS/ops.c,v 6.0 89/03/18 23:36:58 mrose Rel $"; #endif /* * $Header: /f/osi/others/idist/RCS/ops.c,v 6.0 89/03/18 23:36:58 mrose Rel $ * * This file is entirely new, and handles the dispatching of the * remote operations to the server. It tries hard to remove all hint * of the ISODE parts and to hide the posy generated structures. * * Julian Onions <jpo@cs.nott.ac.uk> * Nottingham University Computer Science. * * $Log: ops.c,v $ * Revision 6.0 89/03/18 23:36:58 mrose * Release 5.0 * */ #include <stdio.h> #include "Idist-ops.h" /* operation definitions */ #include "Idist-types.h" /* type definitions */ #include "defs.h" extern struct type_Idist_FileSpec *makefs (); static void print_ia5list (); int basic_error (); int null_result (), ia5_result (), query_result (); int result_value; int initdir (flag, dest) int flag; char *dest; { struct qbuf *qb; struct type_Idist_InitDir *idp; qb = str2qb (dest, strlen(dest), 1); idp = (struct type_Idist_InitDir *) malloc (sizeof *idp); if (idp == (struct type_Idist_InitDir *)0) adios ("memory", "out of"); if (flag) { idp -> offset = type_Idist_InitDir_destdir; idp -> un.destdir = qb; } else { idp -> offset = type_Idist_InitDir_nodestdir; idp -> un.nodestdir = qb; } return invoke (operation_Idist_init, (caddr_t)idp, free_Idist_init_argument, null_result, basic_error); } int transfer (type, opts, mode, size, mtime, uname, group, name, lname) unsigned short type, mode; time_t mtime; off_t size; int opts; char *uname, *group, *name, *lname; { struct type_Idist_FileSpec *fs; fs = makefs (type, opts, mode, size, mtime, uname, group, name, lname); return invoke (operation_Idist_transfer, (caddr_t)fs, free_Idist_transfer_argument, ia5_result, basic_error); } terminate (type, status) int type; int status; { struct type_Idist_TermStatus *ts; struct type_Idist_FileType *makeftype (); if ((ts = (struct type_Idist_TermStatus *) malloc ( sizeof *ts)) == NULL) adios ("memory", "out of"); ts -> filetype = makeftype ((unsigned short)type); ts -> status = (status == OK) ? 1 : 0; return invoke (operation_Idist_terminate, (caddr_t)ts, free_Idist_terminate_argument, null_result, basic_error); } tran_data (data, len) char *data; int len; { struct type_Idist_Data *dat; dat = str2qb (data, len, 1); return invoke (operation_Idist_data, (caddr_t)dat, free_Idist_data_argument, null_result, basic_error); } int runspecial (cmd) char *cmd; { struct type_UNIV_IA5String *ia5; ia5 = str2qb (cmd, strlen(cmd), 1); return invoke (operation_Idist_special, (caddr_t)ia5, free_Idist_special_argument, ia5_result, basic_error); } static time_t cmtime; static off_t csize; static unsigned short cmode; int rquery (file, mtime, size, mode) char *file; time_t *mtime; off_t *size; unsigned short *mode; { struct type_UNIV_IA5String *ia5; int retval; ia5 = str2qb (file, strlen(file), 1); retval = invoke (operation_Idist_query, (caddr_t)ia5, free_Idist_query_argument, query_result, basic_error); if (retval == NOTOK) return NOTOK; if (result_value != OK) return result_value; else { *mtime = cmtime; *mode = cmode; *size = csize; return OK; } } /* ARGSUSED */ query_result (sd, id, error, qr, roi) int sd, id, error; struct type_Idist_QueryResult *qr; struct RoSAPindication *roi; { long convtime (); result_value = OK; if (qr -> offset == type_Idist_QueryResult_doesntExist) { result_value = DONE; return OK; } else { cmode = 0; switch (qr -> un.doesExist -> filetype -> parm) { case int_Idist_FileType_directory: cmode = S_IFDIR; case int_Idist_FileType_symlink: if (cmode == 0) cmode = S_IFLNK; case int_Idist_FileType_regular: if (cmode == 0) cmode = S_IFREG; cmtime = convtime (qr -> un.doesExist -> filemtime); csize = qr -> un.doesExist -> filesize; break; default: result_value = NOTOK; return OK; } result_value = OK; return OK; } } static int copts; rmchk (opts) int opts; { int listcdir_result (); copts = opts; return invoke (operation_Idist_listcdir, (caddr_t)NULL, free_Idist_listcdir_argument, listcdir_result, basic_error); } /* ARGSUSED */ int listcdir_result (sd, id, error, files, roi) int sd, id, error; struct type_Idist_FileList *files; struct RoSAPindication *roi; { struct type_Idist_FileList *fl; char buf[BUFSIZ]; char *name; extern char target[]; struct stat stb; extern char basename[]; for (fl = files; fl; fl = fl -> next) { name = qb2str (fl -> FileSpec -> filename); (void) sprintf (buf, "%s/%s", target, name); if (lstat (buf, &stb) < 0) { if (copts & VERIFY) printf ("need to remove: %s/%s\n", basename, name); else (void) deletefile (name, fl -> FileSpec -> filetype -> parm); } free (name); } return OK; } deletefile (str, mode) char *str; int mode; { struct type_UNIV_IA5String *ia5; char buffer[BUFSIZ]; switch (mode) { case int_Idist_FileType_regular: case int_Idist_FileType_hardlink: mode = S_IFREG; break; case int_Idist_FileType_directory: mode = S_IFDIR; break; case int_Idist_FileType_symlink: mode = S_IFLNK; break; default: mode = 0; break; } (void) sprintf (buffer, "%s/%s", basename, str); if ((copts & QUERYM) && !query ("Delete", mode, buffer)) return OK; ia5 = str2qb (str, strlen(str), 1); return invoke (operation_Idist_deletefile, (caddr_t) ia5, free_Idist_deletefile_argument, ia5_result, basic_error); } /* ARGSUSED */ static int basic_error (sd, id, error, parameter, roi) int sd, id, error; struct type_Idist_IA5List *parameter; struct RoSAPindication *roi; { struct RyError *rye; if (error == RY_REJECT) { advise (NULLCP, "%s", RoErrString ((int) parameter)); result_value = NOTOK; return OK; } if (rye = finderrbyerr (table_Idist_Errors, error)) advise (NULLCP, "%s", rye -> rye_name); else advise (NULLCP, "Error %d", error); if (parameter) print_ia5list (parameter); result_value = NOTOK; return OK; } /* ARGSUSED */ static null_result (sd, id, dummy, result, roi) int sd, id, dummy; caddr_t result; struct RoSAPindication *roi; { result_value = OK; return OK; } /* ARGSUSED */ static int ia5_result (sd, id, parameter, result, roi) int sd, id, parameter; caddr_t result; struct RoSAPindication *roi; { result_value = OK; print_ia5list ((struct type_Idist_IA5List *)result); return OK; } static void print_ia5list (ia5) register struct type_Idist_IA5List *ia5; { register struct qbuf *p, *q; for (; ia5; ia5 = ia5 -> next) { p = ia5 -> IA5String; for (q = p -> qb_forw; q != p ; q = q -> qb_forw) printf ("%*.*s", q -> qb_len, q -> qb_len, q -> qb_data); printf ("\n"); } }