|
|
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: //
1.1.1.2 ! root 35: short RemoteOpen(PPCONTEXT_HANDLE_TYPE pphContext,
! 36: unsigned char * pszFileName)
1.1 root 37: {
38: *pphContext = pFileContext; // initialize the context handle
39: strcpy(pFileContext->achFile, pszFileName);
40: if ((pFileContext->hFile = fopen(pszFileName, "r")) == NULL)
41: return(-1);
42: else
43: return(0);
44: }
45:
46: //
47: // This remote procedure reads a file on the server.
48: //
1.1.1.2 ! root 49: short RemoteRead(PPCONTEXT_HANDLE_TYPE pphContext,
! 50: unsigned char *pbBuf,
! 51: short *pcbBuf)
1.1 root 52: {
53: FILE * fp;
54:
55: printf("in RemoteRead\n");
56:
57: pFileContext = (FILE_CONTEXT_TYPE *) *pphContext;
58: fp = (FILE *) pFileContext->hFile;
59: *pcbBuf = (short) fread(pbBuf,
60: sizeof(char),
61: BUFSIZE,
62: fp);
63: return(*pcbBuf);
64: }
65:
66: // The Shutdown procedure tells the server to stop listening
67: // for client requests
68: //
69: void Shutdown(void)
70: {
71: RPC_STATUS status;
72:
73: printf("Calling RpcMgmtStopServerListening\n");
74: status = RpcMgmtStopServerListening(NULL);
75: printf("RpcMgmtStopServerListening returned: 0x%x\n", status);
76: if (status) {
77: exit(2);
78: }
79:
80: printf("Calling RpcServerUnregisterIf\n");
81: status = RpcServerUnregisterIf(NULL, NULL, FALSE);
82: printf("RpcServerUnregisterIf returned 0x%x\n", status);
83: if (status) {
84: exit(2);
85: }
86: }
87:
88: //
89: // This remote procedure closes a file on the server and
90: // shuts down the server.
91: //
92: short RemoteClose(PPCONTEXT_HANDLE_TYPE pphContext)
93: {
94: printf("in RemoteClose\n");
95:
96: pFileContext = (FILE_CONTEXT_TYPE *) *pphContext;
97: if (fclose(pFileContext->hFile) == 0)
98: return(0);
99: else
100: return(-1);
101: }
102:
103: //
104: // The rundown routine is associated with the context handle
105: // type.
106:
107: void PCONTEXT_HANDLE_TYPE_rundown(PCONTEXT_HANDLE_TYPE phContext)
108: {
109: FILE_CONTEXT_TYPE *pFileContext;
110:
111: printf("Context rundown routine\n");
112: Shutdown();
113:
114: pFileContext = (FILE_CONTEXT_TYPE *) phContext;
115: if (pFileContext->hFile != NULL)
116: fclose(pFileContext->hFile);
117: phContext = NULL;
118: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.