--- mstools/samples/rpc/dict/client.c 2018/08/09 18:20:01 1.1 +++ mstools/samples/rpc/dict/client.c 2018/08/09 18:22:05 1.1.1.3 @@ -2,7 +2,7 @@ /** **/ /** Microsoft RPC Examples **/ /** Dictionary Application **/ -/** Copyright(c) Microsoft Corp. 1991 **/ +/** Copyright(c) Microsoft Corp. 1992 **/ /** **/ /*************************************************************/ @@ -13,7 +13,8 @@ * * * Created: Dov Harel 12/??/1990 * * Modified to use context_handle Donna Liu 3/??/1991 * - * Further modifications / documentation Dov Harel 5/1/1991 * + * Further modifications / documentation Dov Harel 5/01/1991 * + * Revival for July 92 Preliminary Releaser Dov Harel 6/20/1992 * * * * Description: * * This is the driver for the client side remote dictionary * @@ -32,14 +33,16 @@ ************************************************************************* */ +#define INCL_DOS + #include #include #include #include #include -#include #include + #include "dict0.h" #include "replay.h" #include "util0.h" @@ -48,7 +51,7 @@ #define RDICT_CURR_RECORD(dict) (((DictState*)dict->state)->curr_record) -handle_t dict_bhandle; +RPC_BINDING_HANDLE dict_bhandle; char * view = "normal"; @@ -70,13 +73,14 @@ RevPrinTree(int lmargin, /* indentat TreeNode *np, /* pointer to the root node */ PrintFun print) /* short, one line, record print routine */ { + int i; static char lspaces[] = " "; - if (np == NULL) return; + // prinTree(lmargin+indent, indent, np->right, print); RevPrinTree(lmargin+indent, indent, np->left, print); if (lmargin > sizeof(lspaces)) @@ -88,6 +92,7 @@ static char lspaces[] = (*print)(np->item); + // prinTree(lmargin+indent, indent, np->left, print); RevPrinTree(lmargin+indent, indent, np->right, print); } @@ -100,6 +105,7 @@ LinPrinTree( Record * global /* global iterator point */ ) { + int i; if (np == NULL) return; LinPrinTree(np->left, print, local, global); @@ -129,13 +135,9 @@ Clnt_Dict_Print( Record * global ) { - RDict DictT = {0, 0}; RDict *prd = &DictT; - UNREFERENCED_PARAMETER(indent); - UNREFERENCED_PARAMETER(global); - // first: get a new copy a from the server VDict_Get_Dict(*pvd, &prd); @@ -158,19 +160,19 @@ Clnt_Dict_Print( void Usage_Msg() { - printf("Usage: \nType a single character, followed by an optional key as follows:\n\n"); - printf("i :: Insert into dictionary\n"); - printf("d :: Delete from dictionary\n"); - printf("f :: Find in dictionary\n"); - printf("N :: next of current item in dictionary\n"); - printf("P :: previous of current item in dictionary\n"); - printf("n :: Next of local current item in dictionary\n"); - printf("p :: Previous of local current item in dictionary\n"); - printf("h :: Head (first item) of dictionary\n"); - printf("t :: Tail (last item) of dictionary\n"); - printf("? :: Print this message\n"); - printf("q :: Quit\n\n"); - printf(" is "); + printf("\nUsage: \nType a single character, followed by an optional key as follows:\n\n"); + printf(" i :: Insert into dictionary\n"); + printf(" d :: Delete from dictionary\n"); + printf(" f :: Find in dictionary\n"); + printf(" N :: next of current item in dictionary\n"); + printf(" P :: previous of current item in dictionary\n"); + printf(" n :: Next of local current item in dictionary\n"); + printf(" p :: Previous of local current item in dictionary\n"); + printf(" h :: Head (first item) of dictionary\n"); + printf(" t :: Tail (last item) of dictionary\n"); + printf(" ? :: Print this message\n"); + printf(" q :: Quit\n\n"); + printf("where is \n"); } void @@ -179,6 +181,7 @@ TestLoop( VDict * pvd ); void TestLoop( VDict * pvd ) { + int key; char currName[80]; char name[80]; char op = 0; @@ -208,6 +211,12 @@ TestLoop( VDict * pvd ) if (op == 'i' || op == 'd' || op == 'f' || op == 'I') sscanf(buffer+1, "%d %s", &pr->key, pr->name); + // Obsolete Debug Prints: + // + // printf("\npr:: Key : %d, Name : %s \n", pr->key, pr->name); + // printf("\npcurrRecord:: Key : %d, Name : %s \n", pcurrRecord->key, pcurrRecord->name); + // printf("%c %d\n\n", (int)op, key); + switch (op) { case 'h': // get Head of list (first record); @@ -316,29 +325,31 @@ void main_dict (short SharedDict) pvdict = &v_dict; - printf ("getting a new dict\n"); + printf ("Getting a new dict..."); VDict_New( SharedDict, pvdict ); - printf ("gotten a new dict in main_dict\n"); + + printf ("Done.\n"); TestLoop(pvdict); } #define MAXPATH 300 // arbitrary large size for server, pipe path -main(int argc, char *argv[]) +int _CRTAPI1 main(int argc, char *argv[]) { int argscan; char * pszSvrName = NULL; + char * pszSvrNetAddress = NULL; char InterfaceAddress[MAXPATH]; // complete path RPC_STATUS status; short Shared_Dictionary = 0; // Share an existing dictionary? + unsigned char * StringBinding; + + printf ("Microsoft RPC demo Client - Splay (Binary) Tree DataBase\n"); // initialize the default server path // by default: -#ifndef OLDOS - strcpy(InterfaceAddress, "\\device\\namedpipe\\dict"); -#else // OLDOS - strcpy(InterfaceAddress, "\\pipe\\dict"); -#endif // OLDOS + + strcpy(InterfaceAddress, "\\pipe\\dict"); if (argc > 1) for (argscan = 1; argscan < argc; argscan++) @@ -350,13 +361,6 @@ main(int argc, char *argv[]) case 'm': case 'M': pszSvrName = &(argv[argscan][2]); -#ifndef OLDOS - strcpy(InterfaceAddress, "\\device\\lanmanredirector\\"); -#else // OLDOS - strcpy(InterfaceAddress, "\\\\"); -#endif // OLDOS - strcat(InterfaceAddress, pszSvrName ); - strcat(InterfaceAddress, "\\pipe\\dict"); break; case 's': @@ -383,31 +387,46 @@ main(int argc, char *argv[]) * protocol stack for the dict interface. Fill in the remaining * fields: */ - dict_ProtocolStack.TransportType = RPC_TRANSPORT_NAMEPIPE; - /* - * The TransportInfoLength takes into account space for the - * terminating zero of the address. - */ - dict_ProtocolStack.TransportInfoLength = - strlen(InterfaceAddress) + 1; - dict_ProtocolStack.TransportInfo = InterfaceAddress; - - status = RpcBindToInterface( - &dict_ProtocolStack, - &dict_DispatchTable, - &dict_bhandle - ); +#ifndef AUTOHANDLE + + if (pszSvrName != NULL) + { + pszSvrNetAddress = (char *)malloc(strlen(pszSvrName) + 5); + strcpy(pszSvrNetAddress, "\\\\"); + strcat(pszSvrNetAddress, pszSvrName); + } + + status = RpcStringBindingCompose(0, (unsigned char *) "ncacn_np", + (unsigned char *)pszSvrNetAddress, + (unsigned char *) InterfaceAddress, 0, + &StringBinding); + + // printf("StringBinding: %s \n\n", StringBinding); + + status = RpcBindingFromStringBinding(StringBinding, &dict_bhandle); + + RpcStringFree(&StringBinding); if (status) { - printf("RpcBindToInterface = %u\n",status); + printf("Cannot bind to %s -> %x", InterfaceAddress, status); return(1); } +#endif + - main_dict(Shared_Dictionary); + RpcTryExcept + { + main_dict(Shared_Dictionary); + } + RpcExcept(1) + { + printf("Exception - %u", RpcExceptionCode()); + } + RpcEndExcept - status = RpcUnbind(dict_bhandle); + status = RpcBindingFree(&dict_bhandle); if (status) printf("RpcUnbind = %u\n",status);