--- mstools/samples/rpc/dict/client.c 2018/08/09 18:22:05 1.1.1.3 +++ mstools/samples/rpc/dict/client.c 2018/08/09 18:24:20 1.1.1.4 @@ -8,14 +8,8 @@ /************************************************************************* * * - * * * 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/01/1991 * - * Revival for July 92 Preliminary Releaser Dov Harel 6/20/1992 * - * * * Description: * * This is the driver for the client side remote dictionary * * (splay trees based) demo. This works as follows: * @@ -33,31 +27,28 @@ ************************************************************************* */ -#define INCL_DOS - -#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) -RPC_BINDING_HANDLE 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); } @@ -65,26 +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 */ { - int i; -static char lspaces[] = + static char lspaces[] = " "; - if (np == NULL) return; - // prinTree(lmargin+indent, indent, np->right, print); - RevPrinTree(lmargin+indent, indent, np->left, print); + if (np == NULL) + return; + + RevPrinTree(lmargin+indent, indent, np->left, print); if (lmargin > sizeof(lspaces)) - lmargin = sizeof(lspaces);; + lmargin = sizeof(lspaces); lspaces[lmargin] = 0; printf(lspaces); @@ -92,9 +82,7 @@ static char lspaces[] = (*print)(np->item); - // prinTree(lmargin+indent, indent, np->left, print); - RevPrinTree(lmargin+indent, indent, np->right, print); - + RevPrinTree(lmargin+indent, indent, np->right, print); } void @@ -105,26 +93,25 @@ LinPrinTree( Record * global /* global iterator point */ ) { - int i; - 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 @@ -139,16 +126,23 @@ Clnt_Dict_Print( RDict *prd = &DictT; // 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); } @@ -176,12 +170,8 @@ Usage_Msg() } void -TestLoop( VDict * pvd ); - -void TestLoop( VDict * pvd ) { - int key; char currName[80]; char name[80]; char op = 0; @@ -193,6 +183,7 @@ TestLoop( VDict * pvd ) Record * pNullRecord = NULL; Dict_Status status; + pcurrRecord->name = currName; pr->name = name; @@ -211,12 +202,6 @@ 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); @@ -240,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; @@ -293,6 +287,7 @@ TestLoop( VDict * pvd ) case 'x': // Delete DICT_CURR_ITEM + status = VDict_Curr_Delete(*pvd, &pr); if (pr == NULL) { pr = &r; @@ -301,6 +296,7 @@ TestLoop( VDict * pvd ) case 'X': // Empty the dictionary + status = VDict_X_Dict(*pvd); break; @@ -308,6 +304,7 @@ TestLoop( VDict * pvd ) Usage_Msg(); break; } + if (op != '?' && op != 'q') Clnt_Dict_Print(pvd, TAB_STOPS, pcurrRecord, pr); } @@ -332,102 +329,86 @@ void main_dict (short SharedDict) TestLoop(pvdict); } -#define MAXPATH 300 // arbitrary large size for server, pipe path - -int _CRTAPI1 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; + 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"); - // initialize the default server path - // by default: - - strcpy(InterfaceAddress, "\\pipe\\dict"); - - 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]); - break; - - case 's': - case 'S': - Shared_Dictionary = 1; - break; - - case 'v': - case 'V': - view = &(argv[argscan][2]); - break; - - default: - Usage(); - } - } - else - Usage(); - } - - // Usage(); + 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: - */ - -#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("Cannot bind to %s -> %x", InterfaceAddress, status); - return(1); - } -#endif - - - RpcTryExcept - { + * 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("Exception - %u", RpcExceptionCode()); - } + } + 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 = RpcBindingFree(&dict_bhandle); - if (status) - printf("RpcUnbind = %u\n",status); + return(0); }