--- mstools/samples/rpc/dict/client.c 2018/08/09 18:20:01 1.1 +++ mstools/samples/rpc/dict/client.c 2018/08/09 18:24:20 1.1.1.4 @@ -2,19 +2,14 @@ /** **/ /** Microsoft RPC Examples **/ /** Dictionary Application **/ -/** Copyright(c) Microsoft Corp. 1991 **/ +/** Copyright(c) Microsoft Corp. 1992 **/ /** **/ /*************************************************************/ /************************************************************************* * * - * * * Remote dictionary example: client side * * * - * Created: Dov Harel 12/??/1990 * - * Modified to use context_handle Donna Liu 3/??/1991 * - * Further modifications / documentation Dov Harel 5/1/1991 * - * * * Description: * * This is the driver for the client side remote dictionary * * (splay trees based) demo. This works as follows: * @@ -32,29 +27,28 @@ ************************************************************************* */ -#include -#include #include +#include #include #include -#include -#include +#include "replay.h" // header file generated by MIDL compiler #include "dict0.h" -#include "replay.h" #include "util0.h" #define TAB_STOPS 4 #define RDICT_CURR_RECORD(dict) (((DictState*)dict->state)->curr_record) -handle_t dict_bhandle; char * view = "normal"; + void Usage() { - printf("Usage : client [-s] [-m] [-v]\n"); + printf("Usage : client -s\n"); + printf(" -n \n"); + printf(" -v \n"); exit(1); } @@ -62,25 +56,25 @@ void Usage() /*** Remote Dictionary Print ***/ /*************************************************************************/ -extern char spaces[]; - void -RevPrinTree(int lmargin, /* indentation of the root of the tree */ +RevPrinTree( + int lmargin, /* indentation of the root of the tree */ int indent, /* indentation of subsequent levels */ TreeNode *np, /* pointer to the root node */ PrintFun print) /* short, one line, record print routine */ { -static char lspaces[] = + static char lspaces[] = " "; - if (np == NULL) return; + if (np == NULL) + return; - RevPrinTree(lmargin+indent, indent, np->left, print); + RevPrinTree(lmargin+indent, indent, np->left, print); if (lmargin > sizeof(lspaces)) - lmargin = sizeof(lspaces);; + lmargin = sizeof(lspaces); lspaces[lmargin] = 0; printf(lspaces); @@ -88,8 +82,7 @@ static char lspaces[] = (*print)(np->item); - RevPrinTree(lmargin+indent, indent, np->right, print); - + RevPrinTree(lmargin+indent, indent, np->right, print); } void @@ -100,25 +93,25 @@ LinPrinTree( Record * global /* global iterator point */ ) { - if (np == NULL) return; + if (np == NULL) + return; LinPrinTree(np->left, print, local, global); - if ( comp(np->item, local) == 0 ) { - if ( comp(np->item, global) == 0 ) + if (comp(np->item, local) == 0) { + if (comp(np->item, global) == 0) printf(" ==>> "); else printf(" >> "); - } - else if ( comp(np->item, global) == 0 ) - printf(" == "); - else - printf(" "); + } + else if (comp(np->item, global) == 0) + printf(" == "); + else + printf(" "); (*print)(np->item); LinPrinTree(np->right, print, local, global); - } void @@ -129,24 +122,27 @@ 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); if ( !strcmp(view, "normal") ) - prinTree(0, TAB_STOPS, (TreeNode *) prd->root, printRecord); + prinTree(0, + TAB_STOPS, + (TreeNode *) prd->root, + printRecord); else if ( !strcmp(view, "reverse") || !strcmp(view, "rev") ) - RevPrinTree(0, TAB_STOPS, (TreeNode *) prd->root, printRecord); + RevPrinTree(0, + TAB_STOPS, + (TreeNode *) prd->root, + printRecord); else if ( !strcmp(view, "flat") ) - LinPrinTree( (TreeNode *) prd->root, printRecord, local, - RDICT_CURR_RECORD(prd)); + LinPrinTree((TreeNode *) prd->root, + printRecord, + local, + RDICT_CURR_RECORD(prd)); RDict_Free_Dict(prd); } @@ -158,25 +154,22 @@ 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 -TestLoop( VDict * pvd ); - -void TestLoop( VDict * pvd ) { char currName[80]; @@ -190,6 +183,7 @@ TestLoop( VDict * pvd ) Record * pNullRecord = NULL; Dict_Status status; + pcurrRecord->name = currName; pr->name = name; @@ -231,51 +225,60 @@ TestLoop( VDict * pvd ) } break; - case 'f': - // Find - status = VDict_Find(*pvd, &pr); - pr = &r; - break; - case 'n': // get next record (advance private (local) iterator) + status = VDict_Next(*pvd, &pcurrRecord); break; case 'p': // get previous record (retreat private (local) iterator) + status = VDict_Prev(*pvd, &pcurrRecord); break; case 'r': // Reset local iterator to global "current item" + status = VDict_Curr_Item(*pvd, &pcurrRecord); break; case 'N': // get Next record (advance global iterator) + status = VDict_Curr_Next(*pvd, &pr); pr = &r; break; case 'P': // get Previous record (retreat global iterator) + status = VDict_Curr_Prev(*pvd, &pr); pr = &r; break; + case 'f': + // Find + + status = VDict_Find(*pvd, &pr); + pr = &r; + break; + case 'i': // Insert + status = VDict_Insert(*pvd, pr); break; case 'I': // Insert (,"") for all num' s.t. 3 < num' < num + status = VDict_I_Dict(*pvd, pr->key); break; case 'd': // Delete + status = VDict_Delete(*pvd, &pr); if (status != ITEM_NOT_FOUND && status != EMPTY_DICTIONARY) { pr = &r; @@ -284,6 +287,7 @@ TestLoop( VDict * pvd ) case 'x': // Delete DICT_CURR_ITEM + status = VDict_Curr_Delete(*pvd, &pr); if (pr == NULL) { pr = &r; @@ -292,6 +296,7 @@ TestLoop( VDict * pvd ) case 'X': // Empty the dictionary + status = VDict_X_Dict(*pvd); break; @@ -299,6 +304,7 @@ TestLoop( VDict * pvd ) Usage_Msg(); break; } + if (op != '?' && op != 'q') Clnt_Dict_Print(pvd, TAB_STOPS, pcurrRecord, pr); } @@ -316,99 +322,93 @@ 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 - +int _CRTAPI1 main(int argc, char *argv[]) { - int argscan; - char * pszSvrName = NULL; - char InterfaceAddress[MAXPATH]; // complete path RPC_STATUS status; - short Shared_Dictionary = 0; // Share an existing dictionary? - - // initialize the default server path - // by default: -#ifndef OLDOS - strcpy(InterfaceAddress, "\\device\\namedpipe\\dict"); -#else // OLDOS - strcpy(InterfaceAddress, "\\pipe\\dict"); -#endif // OLDOS - - if (argc > 1) - for (argscan = 1; argscan < argc; argscan++) - { - if (argv[argscan][0] == '-') - { - switch (argv[argscan][1]) - { - 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': - case 'S': - Shared_Dictionary = 1; - break; - - case 'v': - case 'V': - view = &(argv[argscan][2]); - break; - - default: - Usage(); - } - } - else - Usage(); - } - - // Usage(); + unsigned char * pszUuid = NULL; + unsigned char * pszProtocolSequence = "ncacn_np"; + unsigned char * pszNetworkAddress = NULL; + unsigned char * pszEndpoint = "\\pipe\\dict"; + unsigned char * pszOptions = NULL; + unsigned char * pszStringBinding = NULL; + short Shared_Dictionary = 0; // Share an existing dictionary? + int i; + + printf ("Microsoft RPC demo Client - Splay (Binary) Tree DataBase\n"); + + for (i = 1; i < argc; i++) { + if ((*argv[i] == '-') || (*argv[i] == '/')) { + switch (tolower(*(argv[i]+1))) { + case 'n': // network address + pszNetworkAddress = argv[++i]; + break; + case 's': + Shared_Dictionary = 1; + break; + case 'v': + view = argv[++i]; + break; + case 'h': + case '?': + default: + Usage(); + } + } + else + Usage(); + } /* The dict_ProtocolStack contains a partially initialized - * 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 - ); - - if (status) - { - printf("RpcBindToInterface = %u\n",status); - return(1); - } - - main_dict(Shared_Dictionary); + * protocol stack for the dict interface. Fill in the + * remaining fields: + */ + + status = RpcStringBindingCompose(pszUuid, + pszProtocolSequence, + pszNetworkAddress, + pszEndpoint, + pszOptions, + &pszStringBinding); + if (status) { + printf("RpcStringBindingCompose returned 0x%x\n", status); + return(status); + } + + status = RpcBindingFromStringBinding(pszStringBinding, + &dict_IfHandle); + if (status) { + printf("RpcBindingFromStringBinding returned 0x%x\n", status); + return(status); + } + + status = RpcStringFree(&pszStringBinding); // remote calls done; unbind + if (status) { + printf("RpcStringFree returned 0x%x\n", status); + return(status); + } + + RpcTryExcept { + main_dict(Shared_Dictionary); + } + RpcExcept(1) { + printf("RPC runtime raised exception 0x%x\n", RpcExceptionCode()); + } + RpcEndExcept + + status = RpcBindingFree(&dict_IfHandle); // remote calls done; unbind + if (status) { + printf("RpcBindingFree returned 0x%x\n", status); + return(status); + } - status = RpcUnbind(dict_bhandle); - if (status) - printf("RpcUnbind = %u\n",status); + return(0); }