|
|
1.1 root 1: /****************************************************************************
2: Microsoft RPC Version 1.0
3: Copyright Microsoft Corp. 1992
4: cxhndl Example
5:
6: FILE: cxhndlp.c
7: PURPOSE: Remote procedures used in server application cxhndls
8: FUNCTIONS: RemoteOpen() - Open the file
9: RemoteRead() - Read a buffer's worth of the file
10: RemoteClose() - Close the file and shutdown server
11: Shutdown() - Shutdown the server
12: COMMENTS:
13:
14: ****************************************************************************/
15:
16: #include <stdio.h>
17: #include <stdlib.h>
18: #include <string.h>
19: #include <rpc.h>
20: #include "cxhndl.h"
21:
22: #define BUFSIZE 1024
23:
24: typedef struct {
25: FILE * hFile;
26: char achFile[256];
27: } FILE_CONTEXT_TYPE;
28:
29: FILE_CONTEXT_TYPE FileContext;
30: FILE_CONTEXT_TYPE * pFileContext = &FileContext;
31:
32: //
33: // This remote procedure opens a file on the server.
34: //
35: short RemoteOpen(PPCONTEXT_HANDLE_TYPE pphContext, char * pszFileName)
36: {
37: *pphContext = pFileContext; // initialize the context handle
38: strcpy(pFileContext->achFile, pszFileName);
39: if ((pFileContext->hFile = fopen(pszFileName, "r")) == NULL)
40: return(-1);
41: else
42: return(0);
43: }
44:
45: //
46: // This remote procedure reads a file on the server.
47: //
48: short RemoteRead(PPCONTEXT_HANDLE_TYPE pphContext, char *pbBuf, short *pcbBuf)
49: {
50: FILE * fp;
51:
52: printf("in RemoteRead\n");
53:
54: pFileContext = (FILE_CONTEXT_TYPE *) *pphContext;
55: fp = (FILE *) pFileContext->hFile;
56: *pcbBuf = (short) fread(pbBuf,
57: sizeof(char),
58: BUFSIZE,
59: fp);
60: return(*pcbBuf);
61: }
62:
63: // The Shutdown procedure tells the server to stop listening
64: // for client requests
65: //
66: void Shutdown(void)
67: {
68: RPC_STATUS status;
69:
70: printf("Calling RpcMgmtStopServerListening\n");
71: status = RpcMgmtStopServerListening(NULL);
72: printf("RpcMgmtStopServerListening returned: 0x%x\n", status);
73: if (status) {
74: exit(2);
75: }
76:
77: printf("Calling RpcServerUnregisterIf\n");
78: status = RpcServerUnregisterIf(NULL, NULL, FALSE);
79: printf("RpcServerUnregisterIf returned 0x%x\n", status);
80: if (status) {
81: exit(2);
82: }
83: }
84:
85: //
86: // This remote procedure closes a file on the server and
87: // shuts down the server.
88: //
89: short RemoteClose(PPCONTEXT_HANDLE_TYPE pphContext)
90: {
91: printf("in RemoteClose\n");
92:
93: pFileContext = (FILE_CONTEXT_TYPE *) *pphContext;
94: if (fclose(pFileContext->hFile) == 0)
95: return(0);
96: else
97: return(-1);
98: }
99:
100: //
101: // The rundown routine is associated with the context handle
102: // type.
103:
104: void PCONTEXT_HANDLE_TYPE_rundown(PCONTEXT_HANDLE_TYPE phContext)
105: {
106: FILE_CONTEXT_TYPE *pFileContext;
107:
108: printf("Context rundown routine\n");
109: Shutdown();
110:
111: pFileContext = (FILE_CONTEXT_TYPE *) phContext;
112: if (pFileContext->hFile != NULL)
113: fclose(pFileContext->hFile);
114: phContext = NULL;
115: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.