|
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 d
Length: 10817 (0x2a41) Types: TextFile Names: »dish.c«
└─⟦2d1937cfd⟧ Bits:30007241 EUUGD22: P.P 5.0 └─⟦35176feda⟧ »EurOpenD22/isode/isode-6.tar.Z« └─⟦de7628f85⟧ └─⟦this⟧ »isode-6.0/quipu/dish/dish.c«
/* dish.c - */ #ifndef lint static char *rcsid = "$Header: /f/osi/quipu/dish/RCS/dish.c,v 7.1 89/12/19 16:21:01 mrose Exp $"; #endif /* * $Header: /f/osi/quipu/dish/RCS/dish.c,v 7.1 89/12/19 16:21:01 mrose Exp $ * * * $Log: dish.c,v $ * Revision 7.1 89/12/19 16:21:01 mrose * sync * * Revision 7.0 89/11/23 22:20:01 mrose * Release 6.0 * */ /* * NOTICE * * Acquisition, use, and distribution of this module and related * materials are subject to the restrictions of a license agreement. * Consult the Preface in the User's Manual for the full terms of * this agreement. * */ #include <stdio.h> #include <signal.h> #include "quipu/util.h" #include "quipu/name.h" #include <varargs.h> #ifdef SOCKETS #include "internet.h" #endif #define MAXARGS 50 extern LLog *log_dsap; DN dn = NULLDN; /* This actually stores the current position. */ #define OPT (!frompipe || rps -> ps_byteno == 0 ? opt : rps) #define RPS (!frompipe || opt -> ps_byteno == 0 ? rps : opt) char frompipe; PS opt, rps; DN savename; SFD dish_quit (); SFD dish_intr (); unsigned cache_time = 3600; /* time to keep process alive */ unsigned connect_time = 120; /* time to keep connection open */ char inbuf[LINESIZE]; char bound = FALSE; char remote_prob; char doneget; char *TidyString(); char search_result; /* another horrid global ! */ extern int call_list (), call_compare (), call_search (), call_add (), call_delete (), call_showentry (), call_showname (), call_showattribute (), call_unbind (), call_help (), call_ds (), unknown_cmd (), dsa_control (), call_modify (), call_modifyrdn (), call_quit (), call_bind (), call_moveto (), call_fred (); static struct { char *command; int (*handler) (); int unique; char defaults [LINESIZE]; } Commands[] = { {"list", call_list, 1,0}, {"compare", call_compare, 1,0}, {"search", call_search, 2,0}, {"add", call_add, 1,0}, {"delete", call_delete, 2,0}, {"modify", call_modify, 3,0}, {"modifyrdn", call_modifyrdn, 7,0}, {"showentry", call_showentry, 2,0}, {"showname", call_showname, 5,0}, {"bind", call_bind, 1,0}, {"unbind", call_unbind, 1,0}, {"moveto", call_moveto, 3,0}, {"dsacontrol", dsa_control, 2,0}, {"quit", call_quit, 1,0}, /* quick way out for interactive program */ {"squid", call_ds, 2,0}, {"?", call_help, 1,0}, {"help", call_help, 1,0}, {"fred", call_fred, 4,0}, {0, unknown_cmd, 0,0} }; static jmp_buf dish_env; #ifndef IDLE #define IDLE 0 #endif #ifndef BUSY #define BUSY 1 #endif static char dish_state; #ifndef NO_STATS extern LLog *log_stat; #endif extern LLog *log_dsap; char no_rcfile; main (argc, argv) int argc; char **argv; { int i; char *ttyname (), *getenv(); char *vec [1]; char **vecptr; (void) signal (SIGHUP, dish_quit); (void) signal (SIGQUIT, dish_quit); (void) signal (SIGILL, dish_quit); (void) signal (SIGBUS, dish_quit); (void) signal (SIGSEGV, dish_quit); (void) signal (SIGSYS, dish_quit); (void) signal (SIGTERM, dish_quit); no_rcfile = FALSE; for (i=1; i<argc; i++) { if (test_arg (argv[i],"-fast",1)) { no_rcfile = TRUE; shuffle_up (argc--, argv, i); continue; } if (test_arg (argv[i],"-help",1)) { help_arg ("dish"); exit (0); } } if ( (argc >1) && (test_arg (argv[1], "-pipe",3))) { if (init_pipe () != OK) exit (-61); frompipe = TRUE; opt = rps = NULLPS; } else { frompipe = FALSE; if ((opt = ps_alloc (std_open)) == NULLPS) fatal (-62, "ps_alloc failed"); if (std_setup (opt, stderr) == NOTOK) fatal (-63, "std_setup failed"); if ((rps = ps_alloc (std_open)) == NULLPS) fatal (-64, "ps_alloc 2 failed"); if (std_setup (rps, stdout) == NOTOK) fatal (-65, "std_setup 2 failed"); (void) printf ("Welcome to Dish (DIrectory SHell)\n"); (void) fflush (stdout); } i = 1; vec[0] = argv[0]; vecptr = vec; quipu_syntaxes (); want_oc_hierarchy (); /* for add/modify ! */ #ifndef NO_STATS log_stat -> ll_file = "dish.log"; log_stat -> ll_stat &= ~LLOGCRT; #endif log_dsap -> ll_stat &= ~LLOGCRT; dsap_init (&i, &vecptr); #ifndef NO_STATS ll_hdinit (log_stat,vec[0]); #endif check_known_oids(); if (user_tailor () != OK) { (void) fprintf (stderr, "Tailoring failed\n"); if (frompipe) exit_pipe (); exit (-66); } if (! frompipe) { #ifndef NO_STATS char buf [LINESIZE]; *buf = 0; for (i=0; i<argc; i++) { (void) strcat (buf,argv[i]); (void) strcat (buf," "); if (test_arg (argv[i], "-password",2) && ++i < argc) (void) strcat (buf, "????"); } LLOG (log_stat,LLOG_NOTICE,("%s",buf)); #endif if (call_bind (argc,argv) != OK) exit (-67); } main_loop (); } unknown_cmd () { if (frompipe) ps_print (opt,"Serious dish error\n"); else { if (print_arg_error (opt) != OK) ps_print (opt,"Unknown command --- type '?' for help\n"); } } main_loop () { char *command; char cmd_buf [LINESIZE]; char *ptr; char *vector[MAXARGS]; int no_of_args; int x; char noarg; extern int parse_line; extern int dsa_dead; extern int errno; (void) signal (SIGINT, dish_intr); (void) setjmp (dish_env); while (1) { dish_state = IDLE; if (dsa_dead) { (void) ds_unbind (); bound = FALSE; dsa_dead = FALSE; } parse_line = 0; reset_arg (); set_current_pos(); remote_prob = FALSE; doneget = FALSE; if (frompipe) { #ifdef SOCKETS extern int sd_current; #endif set_alarm (); if (read_pipe (inbuf,LINESIZE) == -1) continue; (void) signal (SIGALRM, SIG_IGN); /* unset alarm */ #ifdef SOCKETS command = inbuf; #else command = index (inbuf, ':'); *command++ = 0; #endif #ifdef SOCKETS if ((opt = ps_alloc (fdx_open)) == NULLPS) { exit_pipe (); fatal (-68, "ps_alloc failed"); } if (fdx_setup (opt, sd_current) == NOTOK) { exit_pipe (); fatal (-69, "fdx_setup failed"); } (void) (*opt -> ps_writeP) (opt, "2", 1, 0); if ((rps = ps_alloc (fdx_open)) == NULLPS) { exit_pipe (); fatal (-70, "ps_alloc 2 failed"); } if (fdx_setup (rps, sd_current) == NOTOK) { exit_pipe (); fatal (-71, "fdx_setup 2 failed"); } (void) (*rps -> ps_writeP) (rps, "1", 1, 0); #else if ((opt = ps_alloc (str_open)) == NULLPS) { exit_pipe (); fatal (-68, "ps_alloc failed"); } if (str_setup (opt, NULLCP, BUFSIZ, 0) == NOTOK) { exit_pipe (); fatal (-69, "str_setup failed"); } opt->ps_ptr++, opt->ps_cnt--; if ((rps = ps_alloc (str_open)) == NULLPS) { exit_pipe (); fatal (-70, "ps_alloc 2 failed"); } if (str_setup (rps, NULLCP , BUFSIZ, 0) == NOTOK) { exit_pipe (); fatal (-71, "str_setup 2 failed"); } rps->ps_ptr++, rps->ps_cnt--; #endif if (!no_rcfile) test_rc_file (opt); } else { do { set_alarm (); (void) printf ("Dish -> "); if (fgets (inbuf, sizeof inbuf, stdin) == 0) call_quit(); for (ptr = inbuf; isspace (*ptr); ptr++) continue; } while (*ptr == 0); (void) signal (SIGALRM, SIG_IGN); /* unset alarm */ command = TidyString(inbuf); } savename = dn_cpy (dn); hide_picture(); dish_state = BUSY; ptr = command; while (*ptr) if (isspace (*ptr)) break; else ptr++; if (*ptr == 0) { noarg = TRUE; } else { *ptr = 0; noarg = FALSE; } for (x = 0; Commands[x].command != 0; x++) if (test_arg (command, Commands[x].command, Commands[x].unique)) break; if (! noarg) *ptr++ = ' '; if (* Commands[x].defaults != 0) { if (noarg) { (void) sprintf (cmd_buf,"%s %s",Commands[x].command,Commands[x].defaults); } else { (void) sprintf (cmd_buf,"%s %s %s",Commands[x].command,Commands[x].defaults,ptr); } command = cmd_buf; } if ((no_of_args = sstr2arg (command, MAXARGS, vector, " \t")) == NOTOK) ps_printf (OPT, "Too many arguments... Can't cope.\n"); else { char help_flag = FALSE; int y; #ifndef NO_STATS char buf [LINESIZE]; #endif vector[0] = Commands[x].command; #ifndef NO_STATS if (vector[0] != NULLCP) { (void) strcpy (buf,vector[0]); (void) strcat (buf," "); } #endif for (y=1; y<no_of_args; y++) { #ifndef NO_STATS (void) strcat (buf,vector[y]); (void) strcat (buf," "); if (test_arg (vector[y], "-password",2) && y+1 < no_of_args) { (void) strcat (buf, "????"); y++; continue; } #endif if (test_arg (vector[y],"-help",1)) { if (vector[0] != NULLCP) help_arg (vector[0]); else unknown_cmd(); help_flag = TRUE; } } #ifndef NO_STATS LLOG (log_stat,LLOG_NOTICE,("%s",buf)); #endif if ( ! help_flag) (*Commands[x].handler) (no_of_args, vector); } /* if from pipe, return results */ if (frompipe && !remote_prob) { #ifdef SOCKETS if (rps -> ps_byteno > 0) { (void) ps_flush (rps); } else if (opt -> ps_byteno > 0) (void) ps_flush (opt); #else if (opt->ps_byteno == 0) { *rps->ps_ptr = 0; send_pipe (rps->ps_base); } else { *opt->ps_ptr = 0; if (search_result == OK) *opt->ps_base = '2'; else *opt->ps_base = '3'; /* Signal search ok but >1 hit, with -hitone option */ send_pipe (opt->ps_base); } #endif ps_free (opt); ps_free (rps); #ifdef SOCKETS (void) close_tcp_socket (sd_current); sd_current = NOTOK; #endif } else { (void) fflush (stdout); (void) ps_flush (opt); (void) ps_flush (rps); } } } call_quit () { /* can only get called if run interactively - dont worry about pipe */ (void) signal (SIGINT, SIG_DFL); DLOG (log_dsap, LLOG_DEBUG, ("Dish:- Exiting Dish successfully...")); if (bound) (void) ds_unbind (); bound = FALSE; ps_free (opt); ps_free (rps); hide_picture(); exit (0); } set_cmd_default (cmd, dflt) char * cmd; char * dflt; { int x; for (x = 0; Commands[x].command != 0; x++) if (strcmp (cmd, Commands[x].command) == 0) { if (* Commands[x].defaults != 0) (void) strcat (Commands[x].defaults, " "); (void) strcat (Commands[x].defaults, dflt); return (OK); } return (NOTOK); } SFD dish_intr () { #ifndef BSDSIGS (void) signal (SIGINT, dish_intr); #endif if (dish_state == IDLE) (void) fprintf (stderr,"\n"); else { (void) fprintf (stderr,"(Interrupted)\n"); dish_state = IDLE; } longjmp (dish_env,1); } void advise (va_alist) va_dcl { int code; va_list ap; extern LLog *log_dsap; va_start (ap); code = va_arg (ap, int); (void) _ll_log (log_dsap, code, ap); va_end (ap); }