--- mstools/samples/rpc/dict/server.c 2018/08/09 18:20:01 1.1 +++ mstools/samples/rpc/dict/server.c 2018/08/09 18:24:22 1.1.1.4 @@ -2,17 +2,14 @@ /** **/ /** Microsoft RPC Examples **/ /** Dictionary Application **/ -/** Copyright(c) Microsoft Corp. 1991 **/ +/** Copyright(c) Microsoft Corp. 1992 **/ /** **/ /*************************************************************/ /* ************************************************************************* - * Remote dictionary example: server side * * * - * Created: Dov Harel 12/??/1990 * - * Modified to use context_handle Donna Liu 3/??/1991 * - * Further modifications / documentation Dov Harel 5/1/1991 * + * Remote dictionary example: server side * * * * Description: * * This is the driver for the server side remote dictionary * @@ -36,131 +33,76 @@ ************************************************************************* */ -#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" -// char *server = "\\pipe\\rpc\\replay"; -void exit(int); void Usage() { - printf("Usage : server -a
\n"); + printf("Usage : server -e \n"); exit(1); } -void +void _CRTAPI1 main(int argc, char *argv[]) { - int argscan; - char * InterfaceAddress = NULL; - RPC_HANDLE Server, Address, Interface; - RPC_STATUS status; - - - for (argscan = 1; argscan < argc; argscan++) - { - if (argv[argscan][0] == '-') - { - switch (argv[argscan][1]) - { - case 'a': - case 'A': - InterfaceAddress = &(argv[argscan][2]); + RPC_STATUS status; + unsigned char * pszProtocolSequence = "ncacn_np"; + unsigned char * pszSecurity = NULL; + unsigned char * pszEndpoint = "\\pipe\\dict"; + unsigned int cMinCalls = 1; + unsigned int cMaxCalls = 20; + unsigned int fDontWait = FALSE; + int i; + + printf ("Microsoft RPC demo Server - Splay (Binary) Tree DataBase\n"); + + /* allow the user to override settings with command line switches */ + for (i = 1; i < argc; i++) { + if ((*argv[i] == '-') || (*argv[i] == '/')) { + switch (tolower(*(argv[i]+1))) { + case 'e': + pszEndpoint = argv[++i]; break; - default: + case 'h': + case '?': + default: Usage(); } } - else - Usage(); - } - if (InterfaceAddress == NULL) -#ifndef OLDOS - InterfaceAddress = "\\device\\namedpipe\\dict"; -#else // OLDOS - InterfaceAddress = "\\pipe\\dict"; -#endif // OLDOS - - status = RpcCreateServer((RPC_EVENT_HANDLERS *) 0, &Server); - printf ("server created\n"); - if (status) - { - printf("RpcCreateServer = %lu\n",status); - exit(2); + else + Usage(); } - /* Initialize required protocol stack fields */ - dict_ProtocolStack.StackType = RPC_STACK_TYPE_V1; - dict_ProtocolStack.TransportType = RPC_TRANSPORT_NAMEPIPE; - dict_ProtocolStack.TransportInfo = InterfaceAddress; - dict_ProtocolStack.TransportInfoLength = strlen(InterfaceAddress)+1; - - status = RpcAddAddress( - Server, - &dict_ProtocolStack, - 0, // Do not prevent deadlock... - &Address, - (void *)0, // Reserved for security information... - RpcNormalResourceUsage, - 0L // No timeout... - ); - - printf ("server address added\n"); - - if (status) - { - printf("RpcAddAddress = %lu\n",status); - exit(2); - } - status = RpcAddInterface( - Server, - &dict_ProtocolStack, - &Interface, - (void *)0, // Reserved for security information... - &dict_DispatchTable - ); - - printf ("server interface added\n"); - - if (status) - { - printf("RpcAddInterface = %lu\n",status); - exit(2); + status = RpcServerUseProtseqEp(pszProtocolSequence, + cMaxCalls, + pszEndpoint, + pszSecurity); // Security descriptor + if (status) { + printf("RpcServerUseProtseqEp returned 0x%x\n", status); + exit(status); + } + + status = RpcServerRegisterIf(dict_ServerIfHandle, // interface to register + NULL, // MgrTypeUuid + NULL); // MgrEpv; null means use default + if (status) { + printf("RpcServerRegisterIf returned 0x%x\n", status); + exit(status); + } + + printf("Calling RpcServerListen\n"); + status = RpcServerListen(cMinCalls, + cMaxCalls, + fDontWait); + if (status) { + printf("RpcServerListen returned: 0x%x\n", status); + exit(status); } -/* - status = RpcExport(Server, 1, &dict_ProtocolStack); - printf ("server exported\n"); - - * The above is required for advertising that the server is serving - * a particular interface (using a locator or alternatively a - * directory service / name service). Strictly equired for clients - * using auto_handle. - -*/ - - if (status) - { - printf("RpcExport = %lu\n",status); - exit(2); - } - - while (1) - { -#ifndef OLDOS - Sleep(5000L); -#else // OLDOS - DosSleep(5000L); -#endif // OLDOS - - } }