/* !++TITLE: ORANGE_REQ.C ! ! AUTHOR: Ruslan R. Laishev ! Copyright © 2000, Ruslan R. Laishev ! ! BUILDING: ! $CC ORANGE_REQ.C ! $SET COMMAND ORANGE_REQ_CLD.CLD/OBJ ! LINK ORANGE_REQ.OBJ,ORANGE_REQ_CLD.OBJ,SYS$INPUT /OPT ! NETLIB_SHRXFR/SHARE ! ^Z ! ORANGE_REQ :==$dev:[dir]ORANGE_REQ.EXE ! ! MODIFICATION HISTORY: ! ! 14-JUN-2000 RRL Initial coding. ! ! !-- */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "netlib_dir:netlibdef.h" /* ** ** NETLIB CONSTANT ** */ unsigned level = NETLIB_K_LEVEL_SOCKET, opt = NETLIB_K_OPTION_KEEPALIVE, ON = 1, szON = sizeof(ON), adrsize = sizeof(struct INADDRDEF), sinsize = sizeof(struct SINDEF); /* !++ ! MACROS !-- */ #define INIT_SDESC(dsc, len, ptr) {(dsc).dsc$b_dtype = DSC$K_DTYPE_T;\ (dsc).dsc$b_class = DSC$K_CLASS_S; (dsc).dsc$w_length = (short) (len);\ (dsc).dsc$a_pointer = (ptr);} #define INIT_ILE3(i,l,c,b,r) {(i).ile3$w_length = (l);\ (i).ile3$w_code = (c); (i).ile3$ps_bufaddr = (b);\ (i).ile3$ps_retlen_addr = (r);} /* !++ ! CLI$ Declaration stuff !-- */ extern void *ORANGE_REQ_CLD; $DESCRIPTOR(prompt,"ORANGE_REQ> "); $DESCRIPTOR(q_password, "PASSWORD"); $DESCRIPTOR(q_hostname, "HOSTNAME"); $DESCRIPTOR(q_domain, "DOMAIN"); $DESCRIPTOR(q_address, "ADDRESS"); $DESCRIPTOR(q_user, "USER"); $DESCRIPTOR(q_pwd, "PWD"); $DESCRIPTOR(q_platid, "PLATID"); $DESCRIPTOR(q_frontpage,"FRONTPAGE"); $DESCRIPTOR(using,"The ORANGE_HOST,ORANGE_PORT must be defined"); $DESCRIPTOR(tabname_dsc,"LNM$SYSTEM_TABLE"); $DESCRIPTOR(orange_host,"ORANGE_HOST"); $DESCRIPTOR(orange_port,"ORANGE_PORT"); $DESCRIPTOR(tmo_dsc,"0 00:00:30"); int tmo[2]; $DESCRIPTOR(ans_OK,"+OK"); $DESCRIPTOR(ans_ERR,"-ERR"); char buf[2048]; int buflen; struct _args { struct dsc$descriptor_s *argname; char argval[128]; short arglen; }; int get_args ( struct _args *list ) { int status,sz; struct dsc$descriptor junk; while (list->argname) { INIT_SDESC(junk,sizeof(list->argval),list->argval); if ( !(1 & (status = cli$get_value(list->argname,&junk,&sz))) ) return status; list->arglen = sz; list++; } return status; } void put_args ( char *cmd, struct _args *list ) { /* printf("%s",cmd); */ buflen = sprintf(buf, "%s",cmd); while (list->argname) { /* printf("\n\t\t/%.*s=%.*s",list->argname->dsc$w_length,list->argname->dsc$a_pointer, list->arglen,list->argval); */ buflen += sprintf(buf+buflen," %.*s",list->arglen,list->argval); list++; } /* printf("\n%.*s\n",buflen,buf); */ } /* *++ * *-- */ int addsite (void) { int status; struct _args args[] = { {&q_password,0,0}, {&q_hostname,0,0}, {&q_domain,0,0}, {&q_address,0,0}, {&q_user,0,0}, {&q_pwd,0,0}, {&q_platid,0,0}, {&q_frontpage,0,0}, {NULL,0,0}}; if (! (1 & (status = get_args (&args[0]))) ) return status; put_args("ADD",&args[0]); return status; } int delsite (void) { int status; struct _args args[] = { {&q_password,0,0}, {&q_hostname,0,0}, {NULL,0,0}}; if (! (1 & (status = get_args (&args[0]))) ) return status; put_args("DELETE",&args[0]); return status; } int listsite(void) { int status; struct _args args[] = { {&q_password,0,0}, {NULL,0,0}}; if (! (1 & (status = get_args (&args[0]))) ) return status; put_args("LIST",&args[0]); return status; } int shut (void) { int status; struct _args args[] = { {&q_password,0,0}, {NULL,0,0}}; if (! (1 & (status = get_args (&args[0]))) ) return status; put_args("SHUTDOWN",&args[0]); return status; } int restart (void) { int status; struct _args args[] = { {&q_password,0,0}, {NULL,0,0}}; if (! (1 & (status = get_args (&args[0]))) ) return status; put_args("RESTART",&args[0]); return status; } int start (void) { int status; struct _args args[] = { {&q_password,0,0}, {NULL,0,0}}; if (! (1 & (status = get_args (&args[0]))) ) return status; put_args("START",&args[0]); return status; } int frontpage (void) { int status; struct _args args[] = { {&q_password,0,0}, {&q_hostname,0,0}, {&q_user,0,0}, {&q_pwd,0,0}, {&q_frontpage,0,0}, {NULL,0,0}}; if (! (1 & (status = get_args (&args[0]))) ) return status; put_args("FRONTPAGE",&args[0]); return status; } int LNM_get ( struct dsc$descriptor_s *tabname, struct dsc$descriptor_s *logname, struct dsc$descriptor_s *equiv ) { ile3 itmlst[2]; INIT_ILE3 (itmlst[0], equiv->dsc$w_length, LNM$_STRING, equiv->dsc$a_pointer, &equiv->dsc$w_length); INIT_ILE3 (itmlst[1],0,0,0,0); return sys$trnlnm (0,tabname,logname,0,&itmlst); } int nconnect ( struct dsc$descriptor_s *host, unsigned short port, void *chan ) { int status; struct dsc$descriptor_s buf_dsc; if ( !(1 & (status = sys$bintim (&tmo_dsc,tmo))) ) return status; if ( !(1 & (status = netlib_socket(chan))) ) return status; if ( !(1 & (status = netlib_connect_by_name(chan, host, &port))) ) return status; INIT_SDESC(buf_dsc,sizeof(buf),buf); if ( !(1 & (status = netlib_readline (chan,&buf_dsc,&buf_dsc.dsc$w_length,0, tmo,0,0,0))) ) return status; lib$put_output(&buf_dsc); return status; } int nsend ( void **chan ) { int status; struct dsc$descriptor_s buf_dsc; INIT_SDESC(buf_dsc,buflen,buf); if ( !(1 & (status = netlib_writeline (chan,&buf_dsc,0,0,0,0,0))) ) return status; lib$put_output(&buf_dsc); INIT_SDESC(buf_dsc,sizeof(buf),buf); if ( !(1 & (status = netlib_readline (chan,&buf_dsc,&buf_dsc.dsc$w_length,0, tmo,0,0,0))) ) return status; lib$put_output(&buf_dsc); return status; } int ndisconnect ( void **chan ) { int status; $DESCRIPTOR(quit,"QUIT"); if ( !(1 & (status = netlib_writeline (chan,&quit,0,0,0,0,0))) ) return status; netlib_shutdown (chan); return netlib_close (chan); } /* !++ !--------------------------------------------------------------------------------- !-- */ int main (void) { int status,flag = 0,port = 0; void *chan; struct dsc$descriptor_s cmd_dsc; /* ** Get remote port number */ INIT_SDESC(cmd_dsc,sizeof(buf),buf); if ( !(1 & (status = LNM_get(&tabname_dsc,&orange_port,&cmd_dsc))) ) { lib$put_output(&using); return status; } buf[cmd_dsc.dsc$w_length] = '\0'; port = atoi(buf); /* ** Get remote host address */ INIT_SDESC(cmd_dsc,sizeof(buf),buf); if ( !(1 & (status = LNM_get(&tabname_dsc,&orange_host,&cmd_dsc))) ) { lib$put_output(&using); return status; } if ( !(1 & (status = nconnect(&cmd_dsc,port,&chan))) ) return status; /* ** Check the presence of the comand line agruments */ INIT_SDESC(cmd_dsc,sizeof(buf),buf); if ( !(1 & (status = lib$get_foreign(&cmd_dsc,0,&cmd_dsc.dsc$w_length,&flag))) ) return status; if ( cmd_dsc.dsc$w_length ) { if ( CLI$_NORMAL == (status = cli$dcl_parse (&cmd_dsc,&ORANGE_REQ_CLD,0,0,0)) ) { buflen = 0; if ( !(1 & (status = cli$dispatch())) ) return status; nsend(&chan); return ndisconnect(&chan); } else return status; } /* ** */ while ( RMS$_EOF != ( status=cli$dcl_parse (0,&ORANGE_REQ_CLD,lib$get_input,lib$get_input,&prompt)) ) { if ( status != CLI$_NORMAL ) continue; buflen = 0; if ( !(1 & (status = cli$dispatch())) ) break; if ( buflen ) nsend(&chan); } ndisconnect(&chan); return status; }