Annotation of mstools/samples/rpc/handles/auto/autos.c, revision 1.1.1.2

1.1       root        1: /****************************************************************************
                      2:                          Microsoft RPC Version 1.0
                      3:                         Copyright Microsoft Corp. 1992
                      4:                                Auto Example
                      5: 
                      6:     FILE:      autos.c
1.1.1.2 ! root        7:     USAGE:     autos
1.1       root        8:     PURPOSE:   Server side of RPC distributed application Auto
                      9:     FUNCTIONS:  main() - registers server as RPC server
                     10:     COMMENTS:  Server side of auto handle example program.
                     11: 
                     12: ****************************************************************************/
                     13: #include <stdlib.h>
                     14: #include <string.h>
                     15: #include <stdio.h>
                     16: #include <rpc.h>    // RPC data structures and APIs
                     17: #include "auto.h"   // header file generated by MIDL compiler
                     18: 
                     19: void Usage(char * pszProgramName)
                     20: {
                     21:     fprintf(stderr, "Usage:  %s\n", pszProgramName);
                     22:     fprintf(stderr, " -p protocol_sequence\n");
                     23:     fprintf(stderr, " -e endpoint\n");
1.1.1.2 ! root       24:     fprintf(stderr, " -m maxcalls\n");
        !            25:     fprintf(stderr, " -n mincalls\n");
        !            26:     fprintf(stderr, " -f flag for RpcServerListen wait\n");
        !            27:     fprintf(stderr, " -s security_descriptor\n");
        !            28:     fprintf(stderr, " -a auto_sample_nsi_entry_name\n");
        !            29:     fprintf(stderr, " -t name_syntax_type\n");
1.1       root       30:     exit(1);
                     31: }
                     32: 
1.1.1.2 ! root       33: void _CRTAPI1 main(int argc, char * argv[])
1.1       root       34: {
                     35:     RPC_STATUS status;
                     36:     RPC_BINDING_VECTOR * pBindingVector;
                     37: 
1.1.1.2 ! root       38:     unsigned char * pszAutoEntryName   = "/.:/Autohandle_sample";
1.1       root       39:     unsigned char * pszEndpoint        = "\\pipe\\auto";
                     40:     unsigned char * pszProtocolSequence = "ncacn_np";
1.1.1.2 ! root       41:     unsigned char * pszSecurity        = NULL;
        !            42:     unsigned int    cMinCalls          = 1;
        !            43:     unsigned int    cMaxCalls          = 20;
        !            44:     unsigned int    fDontWait          = FALSE;
        !            45:     unsigned int    fNameSyntaxType    = RPC_C_NS_SYNTAX_DEFAULT;
1.1       root       46:     int i;
                     47: 
                     48:     // allow the user to override settings with command line switches
                     49:     for (i = 1; i < argc; i++) {
                     50:        if ((*argv[i] == '-') || (*argv[i] == '/')) {
                     51:            switch (tolower(*(argv[i]+1))) {
                     52:                case 'p':  // protocol sequence
                     53:                    pszProtocolSequence = argv[++i];
                     54:                    break;
                     55:                case 'e':
                     56:                    pszEndpoint = argv[++i];
                     57:                    break;
1.1.1.2 ! root       58:                case 'm':
        !            59:                    cMaxCalls = (unsigned int) atoi(argv[++i]);
        !            60:                    break;
        !            61:                case 'n':
        !            62:                    cMinCalls = (unsigned int) atoi(argv[++i]);
        !            63:                    break;
        !            64:                case 'f':
        !            65:                    fDontWait = (unsigned int) atoi(argv[++i]);
        !            66:                    break;
        !            67:                case 's':
        !            68:                    pszSecurity = argv[++i];
        !            69:                    break;
        !            70:                case 'a':
        !            71:                    pszAutoEntryName = argv[++i];
        !            72:                    break;
        !            73:                case 't':
        !            74:                    fNameSyntaxType = (unsigned int) atoi(argv[++i]);
        !            75:                    break;
1.1       root       76:                case 'h':
                     77:                case '?':
                     78:                default:
                     79:                    Usage(argv[0]);
                     80:            }
                     81:        }
                     82:        else
                     83:            Usage(argv[0]);
                     84:     }
                     85: 
                     86:     status = RpcServerUseProtseqEp(pszProtocolSequence,
1.1.1.2 ! root       87:                                   cMaxCalls, // max concurrent calls
1.1       root       88:                                    pszEndpoint,
1.1.1.2 ! root       89:                                   pszSecurity);  // Security descriptor
1.1       root       90:     printf("RpcServerUseProtseqEp returned 0x%x\n", status);
                     91:     if (status) {
1.1.1.2 ! root       92:        exit(status);
1.1       root       93:     }
                     94: 
1.1.1.2 ! root       95:     status = RpcServerRegisterIf(
        !            96:                 autoh_ServerIfHandle, // interface to register
        !            97:                 NULL,                // MgrTypeUuid
        !            98:                 NULL);               // MgrEpv; null means use default
1.1       root       99:     printf("RpcServerRegisterIf returned 0x%x\n", status);
                    100:     if (status) {
1.1.1.2 ! root      101:         exit(status);
1.1       root      102:     }
                    103: 
                    104:     status = RpcServerInqBindings(&pBindingVector);
                    105:     printf("RpcServerInqBindings returned 0x%x\n", status);
                    106:     if (status) {
1.1.1.2 ! root      107:        exit(status);
1.1       root      108:     }
                    109: 
1.1.1.2 ! root      110:     status = RpcNsBindingExport(fNameSyntaxType, /* name syntax type */
        !           111:                                pszAutoEntryName, /* nsi entry name */
1.1       root      112:                                autoh_ServerIfHandle,
1.1.1.2 ! root      113:                                pBindingVector, /* set in previous call */
1.1       root      114:                                NULL);  /* UUID vector */
                    115:     printf("RpcNsBindingExport returned 0x%x\n", status);
                    116:     if (status) {
1.1.1.2 ! root      117:        exit(status);
1.1       root      118:     }
                    119:     printf("Calling RpcServerListen\n");
1.1.1.2 ! root      120:     status = RpcServerListen(cMinCalls,
        !           121:                             cMaxCalls,
        !           122:                             fDontWait); /* wait flag */
1.1       root      123:     printf("RpcServerListen returned: 0x%x\n", status);
                    124:     if (status) {
1.1.1.2 ! root      125:        exit(status);
1.1       root      126:     }
                    127: 
1.1.1.2 ! root      128:     if (fDontWait) {
        !           129:        printf("Calling RpcMgmtWaitServerListen\n");
        !           130:        status = RpcMgmtWaitServerListen();  //  wait operation
        !           131:        printf("RpcMgmtWaitServerListen returned: 0x%x\n", status);
        !           132:        if (status) {
        !           133:            exit(status);
        !           134:        }
        !           135:     }
1.1       root      136: } /* end main() */
                    137: 
                    138: // ====================================================================
                    139: //                MIDL allocate and free
                    140: // ====================================================================
                    141: 
                    142: 
                    143: void * MIDL_user_allocate(size_t len)
                    144: {
                    145:     return(malloc(len));
                    146: }
                    147: 
                    148: void MIDL_user_free(void * ptr)
                    149: {
                    150:     free(ptr);
                    151: }
                    152: 
                    153: /* end autos.c */

unix.superglobalmegacorp.com

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