Annotation of mstools/samples/rpc/doctor/doctorc.c, revision 1.1.1.3

1.1       root        1: /****************************************************************************
1.1.1.3 ! root        2:                    Microsoft RPC Version 1.0
        !             3:                 Copyright Microsoft Corp. 1992
        !             4:                        Doctor Example
        !             5: 
        !             6:     FILE:       doctorc.c
        !             7:     
        !             8:     USAGE:      doctorc  -n network_address
        !             9:                          -p protocol_sequence
        !            10:                          -e endpoint
        !            11:                          -o options
        !            12: 
        !            13:     PURPOSE:    Client side of RPC distributed application
        !            14:     
        !            15:     FUNCTIONS:  main() - binds to server and calls remote procedure
        !            16:     
        !            17:     COMMENTS:   This version of the distributed application prints
        !            18:                 strings from the Doctor server.  Doctor is an Eliza-like
        !            19:                 personal therapist program that works by simple 
        !            20:                 pattern-matching.
        !            21: 
1.1       root       22: ****************************************************************************/
1.1.1.3 ! root       23: 
        !            24: #include <stdlib.h>                           
1.1       root       25: #include <stdio.h>
                     26: #include <string.h>
1.1.1.3 ! root       27: #include <ctype.h>
        !            28: #include "doctor.h"    // header file generated by MIDL compiler
1.1       root       29: 
                     30: #define PURPOSE \
                     31: "This Microsoft RPC Version 1.0 sample program demonstrates\n\
                     32: the use of the [string] and [size_is] attributes. For more\n\
                     33: information about attributes and RPC API functions, see the\n\
                     34: RPC programming guide and reference.\n\n"
                     35: 
                     36: #define GREETING \
                     37: "The doctor is in.\n\
                     38: I am at your service; just tell me anything that troubles\n\
                     39: or concerns you. Please end your sentences with a period,\n\
                     40: a question mark, or an exclamation point, and then press\n\
                     41: the RETURN or ENTER key.  When you are ready to quit our\n\
                     42: session, just enter \"bye\" and press RETURN or ENTER.\n\n\
                     43: What is your name? >"
                     44: 
                     45: #define FAREWELL \
                     46: "I hope I have been of some service to you.\n\
                     47: Let's get together again some time.\n\n"
                     48: 
1.1.1.3 ! root       49: 
1.1       root       50: void Usage(char * pszProgramName)
                     51: {
                     52:     fprintf(stderr, "%s", PURPOSE);
                     53:     fprintf(stderr, "Usage:  %s\n", pszProgramName);
                     54:     fprintf(stderr, " -p protocol_sequence\n");
                     55:     fprintf(stderr, " -n network_address\n");
                     56:     fprintf(stderr, " -e endpoint\n");
                     57:     fprintf(stderr, " -o options\n");
                     58:     exit(1);
                     59: }
                     60: 
1.1.1.2   root       61: void _CRTAPI1 main(int argc, char **argv)
1.1       root       62: {
1.1.1.3 ! root       63:     RPC_STATUS status;                 // returned by RPC API function
        !            64:     unsigned char pszName[STRSIZE];    // patient name
        !            65:     unsigned char achIn[STRSIZE];      // patient input
1.1       root       66: 
1.1.1.3 ! root       67:     unsigned char * pszUuid             = NULL;
1.1       root       68:     unsigned char * pszProtocolSequence = "ncacn_np";
                     69:     unsigned char * pszNetworkAddress   = NULL;
1.1.1.3 ! root       70:     unsigned char * pszEndpoint         = "\\pipe\\doctor";
1.1       root       71:     unsigned char * pszOptions          = NULL;
1.1.1.3 ! root       72:     unsigned char * pszStringBinding    = NULL;
1.1       root       73:     int i;
                     74: 
1.1.1.3 ! root       75:     /* allow the user to override settings with command line switches */
1.1       root       76:     for (i = 1; i < argc; i++) {
1.1.1.3 ! root       77:         if ((*argv[i] == '-') || (*argv[i] == '/')) {
        !            78:             switch (tolower(*(argv[i]+1))) {
        !            79:             case 'p':  // protocol sequence
        !            80:                 pszProtocolSequence = argv[++i];
        !            81:                 break;
        !            82:             case 'n':  // network address
        !            83:                 pszNetworkAddress = argv[++i];
        !            84:                 break;
        !            85:             case 'e':
        !            86:                 pszEndpoint = argv[++i];
        !            87:                 break;
        !            88:             case 'o':
        !            89:                 pszOptions = argv[++i];
        !            90:                 break;
        !            91:             case 'h':
        !            92:             case '?':
        !            93:             default:
        !            94:                 Usage(argv[0]);
        !            95:             }
        !            96:         }
        !            97:         else
        !            98:             Usage(argv[0]);
1.1       root       99:     }
                    100: 
1.1.1.3 ! root      101:     /* Use a convenience function to concatenate the elements of  */
        !           102:     /* the string binding into the proper sequence.               */
1.1       root      103:     status = RpcStringBindingCompose(pszUuid,
                    104:                                      pszProtocolSequence,
                    105:                                      pszNetworkAddress,
                    106:                                      pszEndpoint,
                    107:                                      pszOptions,
                    108:                                      &pszStringBinding);
                    109:     if (status) {
1.1.1.3 ! root      110:         printf("RpcStringBindingCompose returned 0x%x\n", status);
        !           111:         printf("pszStringBinding = %s\n", pszStringBinding);
        !           112:         exit(status);
1.1       root      113:     }
                    114: 
1.1.1.3 ! root      115:     /* Set the binding handle that will be used to bind to the server. */
1.1       root      116:     status = RpcBindingFromStringBinding(pszStringBinding,
1.1.1.3 ! root      117:                                          &doctor_IfHandle);
1.1       root      118:     if (status) {
1.1.1.3 ! root      119:         printf("RpcBindingFromStringBinding returned 0x%x\n", status);
        !           120:         exit(status);
1.1       root      121:     }
                    122: 
1.1.1.3 ! root      123:     /* RPC is now initialized.  Call remote procedures as if        */
        !           124:     /* they were local procedures.                                  */
1.1       root      125: 
1.1.1.3 ! root      126:     /* The doctor program consists of patient statements and doctor */
        !           127:     /* responses.  The patient string is transmitted to the server, */
        !           128:     /* and all processing is performed on the server.               */
        !           129:     
1.1       root      130:     printf("%s", GREETING);
                    131:     gets(pszName);
                    132:     printf("\n%s>", pszName);
                    133: 
1.1.1.3 ! root      134:     while (gets(achIn)) {
        !           135:         if (strncmp(achIn, "bye", 3) == 0)  // end of session?
        !           136:             break;
        !           137:         Analyze(&achIn[0]);
        !           138:         printf("%s%s>", achIn, pszName);    // no, continue
1.1       root      139:     }
                    140: 
1.1.1.3 ! root      141:     Shutdown();                             // yes, shutdown the server
1.1       root      142: 
1.1.1.3 ! root      143:     /*  The calls to the remote procedure are complete.  */
        !           144:     /*  Free the binding handle.                         */
        !           145:     status = RpcBindingFree(&doctor_IfHandle);  // remote calls done; unbind
1.1       root      146:     if (status) {
1.1.1.3 ! root      147:        printf("RpcBindingFree returned 0x%x\n", status);
        !           148:        exit(status);
1.1       root      149:     }
                    150: 
                    151:     printf("%s", FAREWELL);
1.1.1.3 ! root      152: 
1.1       root      153:     exit(0);
                    154: 
1.1.1.3 ! root      155: }  // end main()
        !           156: 
        !           157: 
        !           158: /*********************************************************************/
        !           159: /*                 MIDL allocate and free                            */
        !           160: /*********************************************************************/
1.1       root      161: 
1.1.1.3 ! root      162: void __RPC_FAR * __RPC_API midl_user_allocate(size_t len)
1.1       root      163: {
                    164:     return(malloc(len));
                    165: }
                    166: 
1.1.1.3 ! root      167: void __RPC_API midl_user_free(void __RPC_FAR * ptr)
1.1       root      168: {
                    169:     free(ptr);
                    170: }
                    171: 
1.1.1.3 ! root      172: /* end file doctorc.c */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.