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