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

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

unix.superglobalmegacorp.com

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