home *** CD-ROM | disk | FTP | other *** search
- /*
- * OS/2 Lan Manager using named pipes version of c-tree server
- *
- * This program is the CONFIDENTIAL and PROPRIETARY property
- * of FairCom(R) Corporation. Any unauthorized use, reproduction or
- * transfer of this program is strictly prohibited.
- *
- * Copyright (c) 1987, 1988, 1989 FairCom Corporation
- * (Subject to limited distribution and
- * restricted disclosure only.)
- * *** ALL RIGHTS RESERVED ***
- *
- * 4006 West Broadway
- * Columbia, MO 65203
- *
- *
- * c-tree(R) Version 4.3
- * Release C
- * February 7, 1989 17:30
- *
- */
-
- #define INCL_DOS
- #define INCL_DOSERRORS
- #include <os2def.h> /* Common definitions */
- #include <bsedos.h> /* Base definitions */
- #include <bseerr.h> /* Base error code definitions */
-
- #include <net\netcons.h>
- #include <net\neterr.h>
- #ifndef INCL_DOSNMPIPES /* This define i set if MS SDK 1.06 include files */
- #include <net\nmpipe.h>
- #endif
-
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #include <malloc.h>
-
- #include "ctpipes.h"
-
-
- /*
- * Receive buffer for call DosTransactNmPipe
- * in and out buffer could not be the same ??????!!!!!!?????
- */
- /* char P_outp_buffer[PIPESIZE];
- * char far *P_outp = (char far*)P_outp_buffer;
- ***********************/
- char far *P_outp = 0L;
-
- unsigned pipe_errcode;
-
- /*
- * values for type_of_named_pipe_call:
- * 0 = OS/2 1.0 with device=NAMPIPES.SYS from 3Com 3+Open is working
- * GOOD with DosCallNmPipe
- * 1 = OS/2 1.1 with device=NAMPIPES.SYS from 3Com 3+Open is working
- * 0xFF = init value to test for version;
- */
- static int type_of_named_pipe_call = 0xFF;
-
- /*
- * PC-SERVER variable:
- *----------------------
- * en int for hver server prosses, med folgende verdi:
- * - 0 for local use (running as background task) "\PIPE\pipename"
- * - 1 for LAN-server is to be used "\\SERVER\PIPE\pipename"
- */
- int ps_srv_isam_use = 0;
- int ps_srv_print_use = 0;
- char ps_servname[NAMESIZE] = SRV_NETNAME; /* server network name */
-
-
- unsigned startusepipe(char *pipename, char *prog, char *prog_param,
- int local)
- {
- int i;
- long are_you_there = PIPE_TEST, yes_i_am;
-
- if (!dopipe(pipename, (char far *)&are_you_there, sizeof(long),
- (char far *)&yes_i_am)) {
- /*
- * Pipe is not started, we will then start it localy in a
- * background task.
- */
- if (!local)
- return (PIPE_ERR_COULD_NOT_START);
-
- if (startpipe(prog,prog_param))
- return (PIPE_ERR_COULD_NOT_START);
- /* try to access pipe for a while until server is properly loaded */
- for (i = 0 ; i < 50 ; i++ ) {
- if (dopipe(pipename, (char far *)&are_you_there, sizeof(long),
- (char far *)&yes_i_am))
- return(PIPE_STARTED_LOCAL); /* pipe is startet, go on */
- DosSleep(500L);
- } /* end waiting for pipe to start */
- }
- else
- /* test if server answered correctly */
- if (yes_i_am != PIPE_ANSW)
- pipe_errcode = PIPE_ERR_NO_ANSW; /* no answer */
-
- return(pipe_errcode);
- }
-
- unsigned dopipe(char *PipeName, char far *pipe_inp,
- unsigned ilen, char far *pipe_outp)
- {
- unsigned short bytes;
- HFILE handle;
- unsigned action;
- unsigned short status;
- char dummy[4];
-
- if (P_outp == 0L) /* no buffer allocated */
- P_outp = (char far *)_fmalloc(PIPESIZE);
-
- if (type_of_named_pipe_call == 0xFF) { /* Init type of Pipe Call ? */
- /* Get type of OS/2 operating system:
- * 0 = OS/2 1.0 med 3Com Named Pipes
- * 1 = OS/2 1.1 Standard or Extended Edition
- * 9 = newer versions not supported
- */
- type_of_named_pipe_call = get_os2_version();
- if (type_of_named_pipe_call == 9) {
- DosBeep(800,6);
- DosBeep(2000,10);
- DosBeep(800,6);
- type_of_named_pipe_call = 1; /* we then try use TransactNmPipe */
- }
- }
-
- /*
- * OS/2 1.1 Standard or Extended Edition is not working with
- * DosCallNmPipe.
- * We then use DosOpen - DosTransactNmPipe - DosClose instead
- */
- if (type_of_named_pipe_call) {
- while ((pipe_errcode = DosOpen(PipeName, &handle, &action, 0L, 0,
- CLI_OPENFLAG, CLI_DOSOPENMODE, 0L))
- == ERROR_PIPE_BUSY) {
- /* wait until pipe is ready to be opened
- * Wait for default time for pipe to be ready
- */
- pipe_errcode = DosWaitNmPipe(PipeName,0L);
- } /* end while DosOpen */
- if (!pipe_errcode) {
- for (;;) {
- if (pipe_errcode = DosPeekNmPipe(handle, dummy, 0,
- &bytes, &bytes, &status)) {
- break;
- }
- if (status == NP_CONNECTED) {
- bytes = 0;
- if (pipe_errcode =
- DosTransactNmPipe(handle,
- (char far *) pipe_inp, (unsigned short) ilen,
- (char far *) P_outp,
- PIPESIZE, &bytes) ) {
- break;
- }
- break;
- }
- } /* end waiting for pipe to be ready */
- DosClose(handle);
- }
- }
-
- else
-
- /*
- * OS/2 1.0 with device=NAMPIPES.SYS from 3Com 3+Open is working
- * GOOD with DosCallNmPipe
- */
- {
- do {
-
- pipe_errcode = DosCallNmPipe(PipeName,
- (char far *) pipe_inp, (unsigned short) ilen,
- (char far *) P_outp, PIPESIZE, &bytes, 10000L);
-
- } while(pipe_errcode == ERROR_PIPE_BUSY ||
- pipe_errcode == ERROR_SEM_TIMEOUT);
- }
- /*
- * ERROR_FILE_NOT_FOUND Specified pipe does not exist.
- * ERROR_PIPE_BUSY All available instances are in use.
- * ERROR_PIPE_NOT_CONNECTED Pipe disconnected during transaction.
- * ERROR_BROKEN_PIPE Write to single-ended pipe.
- * ERROR_MORE_DATA More data exists in message. All
- * data requested has been transferred.
- * ERROR_SEM_TIMEOUT Wait timed out.
- * ERROR_INTERRUPT Interrupted wait.
- */
-
- if (!pipe_errcode) {
- movedata (SELECTOROF(P_outp),
- OFFSETOF(P_outp),
- SELECTOROF(pipe_outp), OFFSETOF(pipe_outp), bytes);
- }
-
- return(pipe_errcode ? 0 : bytes);
- }
-
-
- unsigned startpipe(char *pname, char *pargs)
- {
- char tbuf[128];
- RESULTCODES rc;
- PID pidWait;
- USHORT wc, prio;
-
- pipe_errcode = DosExecPgm(tbuf, sizeof(tbuf), EXEC_BACKGROUND,
- pargs, 0, &rc, pname);
- pidWait = rc.codeTerminate;
- DosSleep(500L);
- /* see if Process still is running */
- wc = DosGetPrty(PRTYS_PROCESS, &prio, pidWait);
- switch (wc) {
- case ERROR_INVALID_SCOPE:
- /* The parameter must indicate either a thread or process.*/
- case ERROR_INVALID_PROCID:
- /* The process identifier is invalid or nonexistent.*/
- case ERROR_NO_CHILD_PROCESS:
- default:
- pipe_errcode = wc;
- }
- return(pipe_errcode);
- }
-