|
|
1.1 root 1: /* sbbsexec.c */
2:
3: /* Synchronet Windows NT/2000 VDD for FOSSIL and DOS I/O Interrupts */
4:
5: /* $Id: sbbsexec.c,v 1.1.1.1 2000/10/10 11:26:22 rswindell Exp $ */
6:
7: /****************************************************************************
8: * @format.tab-size 4 (Plain Text/Source Code File Header) *
9: * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
10: * *
11: * Copyright 2000 Rob Swindell - http://www.synchro.net/copyright.html *
12: * *
13: * This program is free software; you can redistribute it and/or *
14: * modify it under the terms of the GNU General Public License *
15: * as published by the Free Software Foundation; either version 2 *
16: * of the License, or (at your option) any later version. *
17: * See the GNU General Public License for more details: gpl.txt or *
18: * http://www.fsf.org/copyleft/gpl.html *
19: * *
20: * Anonymous FTP access to the most recent released source is available at *
21: * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net *
22: * *
23: * Anonymous CVS access to the development source and modification history *
24: * is available at cvs.synchro.net:/cvsroot/sbbs, example: *
25: * cvs -d :pserver:[email protected]:/cvsroot/sbbs login *
26: * (just hit return, no password is necessary) *
27: * cvs -d :pserver:[email protected]:/cvsroot/sbbs checkout src *
28: * *
29: * For Synchronet coding style and modification guidelines, see *
30: * http://www.synchro.net/source.html *
31: * *
32: * You are encouraged to submit any modifications (preferably in Unix diff *
33: * format) via e-mail to [email protected] *
34: * *
35: * Note: If this box doesn't appear square, then you need to fix your tabs. *
36: ****************************************************************************/
37:
38: #include <windows.h>
39: #include <stdio.h>
40: #include <vddsvc.h>
41: #include "vdd_func.h"
42: #include "ringbuf.h"
43:
44: #define RINGBUF_SIZE_IN 10000
45:
46:
47: __declspec(dllexport) void __cdecl VDDDispatch(void)
48: {
49: char str[512];
50: char buf[5000];
51: DWORD count;
52: int retval;
53: int node_num;
54: BYTE* p;
55: vdd_status_t* status;
56: static DWORD inbuf_poll;
57: static DWORD online_poll;
58: static DWORD status_poll;
59: static HANDLE hungup_event;
60: static HANDLE rdslot=INVALID_HANDLE_VALUE;
61: static HANDLE wrslot=INVALID_HANDLE_VALUE;
62: static RingBuf rdbuf;
63: static FILE* fp;
64:
65: node_num=getBH();
66:
67: switch(getBL()) {
68:
69: case VDD_OPEN:
70: sprintf(str,"sbbsexec%d.log",node_num);
71: fp=fopen(str,"wb");
72:
73: sprintf(str,"\\\\.\\mailslot\\sbbsexec\\wr%d",node_num);
74: rdslot=CreateMailslot(str
75: ,sizeof(buf) // Max message size (0=any)
76: ,MAILSLOT_WAIT_FOREVER // Read timeout
77: ,NULL);
78: if(rdslot==INVALID_HANDLE_VALUE) {
79: if(fp!=NULL)
80: fprintf(fp,"!VDD_OPEN: Error %d opening %s\r\n"
81: ,GetLastError(),str);
82: retval=1;
83: break;
84: }
85:
86: sprintf(str,"\\\\.\\mailslot\\sbbsexec\\rd%d",node_num);
87: wrslot=CreateFile(str
88: ,GENERIC_WRITE
89: ,FILE_SHARE_READ
90: ,NULL
91: ,OPEN_EXISTING
92: ,FILE_ATTRIBUTE_NORMAL
93: ,(HANDLE) NULL);
94: if(wrslot==INVALID_HANDLE_VALUE) {
95: if(fp!=NULL)
96: fprintf(fp,"!VDD_OPEN: Error %d opening %s\r\n"
97: ,GetLastError(),str);
98: retval=2;
99: break;
100: }
101:
102: if(RingBufInit(&rdbuf, RINGBUF_SIZE_IN)!=0) {
103: retval=3;
104: break;
105: }
106:
107: sprintf(str,"sbbsexec_hungup%d",node_num);
108: hungup_event=OpenEvent(
109: EVENT_ALL_ACCESS, // access flag
110: FALSE, // inherit flag
111: str); // pointer to event-object name
112: if(hungup_event==NULL) {
113: if(fp!=NULL)
114: fprintf(fp,"!VDD_OPEN: Error %d opening %s\r\n"
115: ,GetLastError(),str);
116: retval=4;
117: break;
118: }
119:
120: status_poll=0;
121: inbuf_poll=0;
122: online_poll=0;
123:
124: retval=0;
125: break;
126:
127: case VDD_CLOSE:
128: if(fp!=NULL) {
129: fprintf(fp,"VDD_CLOSE: rdbuf=%d "
130: "status_poll=%d inbuf_poll=%d online_poll=%d\r\n"
131: ,RingBufFull(&rdbuf),status_poll,inbuf_poll,online_poll);
132: fclose(fp);
133: }
134: CloseHandle(rdslot);
135: CloseHandle(wrslot);
136: CloseHandle(hungup_event);
137: RingBufDispose(&rdbuf);
138: status_poll=0;
139: retval=0;
140:
141: break;
142:
143: case VDD_READ:
144: count = getCX();
145: if(count != 1 && fp!=NULL)
146: fprintf(fp,"VDD_READ of %d\r\n",count);
147:
148: p = (BYTE*) GetVDMPointer((ULONG)((getES() << 16)|getDI())
149: ,count,FALSE);
150: if(RingBufFull(&rdbuf)) {
151: retval=RingBufRead(&rdbuf,p,count);
152: if(retval==0 && fp!=NULL)
153: fprintf(fp,"!VDD_READ: RingBufRead read 0\r\n");
154: break;
155: }
156: if(!ReadFile(rdslot,buf,sizeof(buf),&retval,NULL)) {
157: if(fp!=NULL)
158: fprintf(fp,"!VDD_READ: ReadFile Error %d (size=%d)\r\n"
159: ,GetLastError(),retval);
160: retval=0;
161: break;
162: }
163: if(retval==0) {
164: if(fp!=NULL)
165: fprintf(fp,"!VDD_READ: ReadFile read 0\r\n");
166: break;
167: }
168: RingBufWrite(&rdbuf,buf,retval);
169: retval=RingBufRead(&rdbuf,p,count);
170: if(retval==0 && fp!=NULL)
171: fprintf(fp,"!VDD_READ: RingBufRead read 0 after write\r\n");
172: break;
173:
174: case VDD_PEEK:
175: count = getCX();
176: if(count != 1 && fp!=NULL)
177: fprintf(fp,"VDD_PEEK of %d\r\n",count);
178:
179: p = (BYTE*) GetVDMPointer((ULONG)((getES() << 16)|getDI())
180: ,count,FALSE);
181: if(RingBufFull(&rdbuf)) {
182: retval=RingBufPeek(&rdbuf,p,count);
183: break;
184: }
185: if(!ReadFile(rdslot,buf,sizeof(buf),&retval,NULL)) {
186: if(fp!=NULL)
187: fprintf(fp,"!VDD_PEEK: ReadFile Error %d\r\n"
188: ,GetLastError());
189: retval=0;
190: break;
191: }
192: if(retval==0) {
193: if(fp!=NULL)
194: fprintf(fp,"!VDD_PEEK: ReadFile read 0\r\n");
195: break;
196: }
197: RingBufWrite(&rdbuf,buf,retval);
198: retval=RingBufPeek(&rdbuf,p,count);
199: break;
200:
201: case VDD_WRITE:
202: count = getCX();
203: if(count != 1 && fp!=NULL)
204: fprintf(fp,"VDD_WRITE of %d\r\n",count);
205: p = (BYTE*) GetVDMPointer((ULONG)((getES() << 16)|getDI())
206: ,count,FALSE);
207: // if(fp!=NULL)
208: // fwrite(p,count,1,fp);
209: if(!WriteFile(wrslot,p,count,&retval,NULL)) {
210: if(fp!=NULL)
211: fprintf(fp,"!VDD_WRITE: WriteFile Error %d (size=%d)\r\n"
212: ,GetLastError(),retval);
213: retval=0;
214: }
215: break;
216:
217: case VDD_STATUS:
218:
219: status_poll++;
220: count = getCX();
221: if(count != sizeof(vdd_status_t)) {
222: if(fp!=NULL)
223: fprintf(fp,"!VDD_STATUS: wrong size (%d!=%d)\r\n",count,sizeof(vdd_status_t));
224: retval=sizeof(vdd_status_t);
225: break;
226: }
227: status = (vdd_status_t*) GetVDMPointer((ULONG)((getES() << 16)|getDI())
228: ,count,FALSE);
229:
230: /* INBUF FULL/SIZE */
231: if(!GetMailslotInfo(
232: rdslot, // mailslot handle
233: &status->inbuf_size, // address of maximum message size
234: &status->inbuf_full, // address of size of next message
235: NULL, // address of number of messages
236: NULL // address of read time-out
237: )) {
238: status->inbuf_full=0;
239: status->inbuf_size=4000;
240: }
241: if(status->inbuf_full==MAILSLOT_NO_MESSAGE)
242: status->inbuf_full=0;
243: status->inbuf_full+=RingBufFull(&rdbuf);
244:
245:
246: /* OUTBUF FULL/SIZZE */
247: if(!GetMailslotInfo(
248: wrslot, // mailslot handle
249: &status->outbuf_size, // address of maximum message size
250: &status->outbuf_full, // address of size of next message
251: NULL, // address of number of messages
252: NULL // address of read time-out
253: )) {
254: status->outbuf_full=0;
255: status->outbuf_size=4000;
256: }
257: if(status->outbuf_full==MAILSLOT_NO_MESSAGE)
258: status->outbuf_full=0;
259:
260:
261: /* ONLINE */
262: if(WaitForSingleObject(hungup_event,0)==WAIT_OBJECT_0)
263: status->online=0;
264: else
265: status->online=1;
266:
267: retval=0; /* success */
268: break;
269:
270:
271: case VDD_INBUF_PURGE:
272: if(fp!=NULL)
273: fprintf(fp,"!VDD_INBUF_PURGE: NOT IMPLEMENTED\r\n");
274: retval=0;
275: break;
276:
277: case VDD_OUTBUF_PURGE:
278: if(fp!=NULL)
279: fprintf(fp,"!VDD_OUTBUF_PURGE: NOT IMPLEMENTED\r\n");
280: retval=0;
281: break;
282:
283: #if 1
284: case VDD_INBUF_FULL:
285: if(!GetMailslotInfo(
286: rdslot, // mailslot handle
287: NULL, // address of maximum message size
288: &retval, // address of size of next message
289: &count, // address of number of messages
290: NULL // address of read time-out
291: ))
292: retval=0;
293: if(retval==MAILSLOT_NO_MESSAGE)
294: retval=0;
295: retval+=RingBufFull(&rdbuf);
296: inbuf_poll++;
297: break;
298:
299: case VDD_INBUF_SIZE:
300: if(!GetMailslotInfo(
301: rdslot, // mailslot handle
302: &retval, // address of maximum message size
303: NULL, // address of size of next message
304: NULL, // address of number of messages
305: NULL // address of read time-out
306: ))
307: retval=4000;
308: break;
309:
310: case VDD_OUTBUF_FULL:
311: if(!GetMailslotInfo(
312: wrslot, // mailslot handle
313: NULL, // address of maximum message size
314: &retval, // address of size of next message
315: NULL, // address of number of messages
316: NULL // address of read time-out
317: ))
318: retval=0;
319: if(retval==MAILSLOT_NO_MESSAGE)
320: retval=0;
321: break;
322:
323: case VDD_OUTBUF_SIZE:
324: if(!GetMailslotInfo(
325: wrslot, // mailslot handle
326: &retval, // address of maximum message size
327: NULL, // address of size of next message
328: NULL, // address of number of messages
329: NULL // address of read time-out
330: ))
331: retval=4000;
332: break;
333:
334: case VDD_ONLINE:
335: if(WaitForSingleObject(hungup_event,0)==WAIT_OBJECT_0)
336: retval=0;
337: else
338: retval=1;
339: online_poll++;
340: break;
341: #endif
342: default:
343: if(fp!=NULL)
344: fprintf(fp,"!UNKNOWN VDD_OP: %d\r\n",getBL());
345: break;
346: }
347: setAX((WORD)retval);
348: }
349:
350: __declspec(dllexport) BOOL __cdecl VDDInitialize(IN PVOID DllHandle, IN ULONG Reason,
351: IN PCONTEXT Context OPTIONAL)
352: {
353: return TRUE;
354: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.