1 | /**************************************************************************
|
---|
2 | *
|
---|
3 | * SOURCE FILE NAME = ECUP.C
|
---|
4 | *
|
---|
5 | * DESCRIPTIVE NAME = Portdriver to redirect PS to a CUPS Queue
|
---|
6 | *
|
---|
7 | * Copyright : Bart van Leeuwen, netlabs 2006
|
---|
8 | *
|
---|
9 | * VERSION = M1
|
---|
10 | *
|
---|
11 | * DATE = 29-10-2006
|
---|
12 | *
|
---|
13 | ****************************************************************************/
|
---|
14 |
|
---|
15 |
|
---|
16 | int acrtused=1; /* Define variable to say this is a DLL */
|
---|
17 |
|
---|
18 | #include <stdlib.h>
|
---|
19 | #include <stdio.h>
|
---|
20 | #include <string.h>
|
---|
21 | #include <sys/types.h>
|
---|
22 | #include <sys/stat.h>
|
---|
23 | #include <time.h>
|
---|
24 |
|
---|
25 | #include "ecups.h"
|
---|
26 |
|
---|
27 | #include "ecdebug.h"
|
---|
28 |
|
---|
29 | extern ECUPSSESSIONDATA eCUPSSession;
|
---|
30 |
|
---|
31 | /*
|
---|
32 | ** If port driver is not defined in INI file yet
|
---|
33 | ** assume it exists in the boot drive's \OS2\DLL directory
|
---|
34 | */
|
---|
35 | CHAR szDefaultPortDrvPath[] = PATH_ECUPS_PDR;
|
---|
36 |
|
---|
37 |
|
---|
38 | /*
|
---|
39 | ** Below definition of PORTNAMES structure should be defined in
|
---|
40 | ** common header file pmspl.h.
|
---|
41 | */
|
---|
42 | /*typedef struct _PORTNAMES
|
---|
43 | {
|
---|
44 | PSZ pszPortName; // -> name of port(ie "LPT1)
|
---|
45 | PSZ pszPortDesc; // -> description of port(ie "Parallel Port 1")
|
---|
46 | } PORTNAMES, *PPORTNAMES;*/
|
---|
47 |
|
---|
48 |
|
---|
49 |
|
---|
50 | /****************************************************************************
|
---|
51 | *
|
---|
52 | * FUNCTION NAME = SplPdEnumPort
|
---|
53 | *
|
---|
54 | * DESCRIPTION = Return ports supported by this port driver
|
---|
55 | * Currently this will return those ports this port
|
---|
56 | * driver supports by default.
|
---|
57 | * Future enhancement might be to also return any
|
---|
58 | * ports that have been added that now use this
|
---|
59 | * port driver.
|
---|
60 | *
|
---|
61 | * INPUT = hab - anchor block handle
|
---|
62 | * pBuf - buffer to get enumerated PORTNAMES structures
|
---|
63 | * cbBuf - size(in bytes) of pBuf passed in
|
---|
64 | *
|
---|
65 | * OUTPUT = *pulReturned - number of PORTNAMES structures stored in pBuf
|
---|
66 | * *pulTotal - total ports supported by this port driver
|
---|
67 | * *pcbRequired - size(in bytes) of buffer needed to store
|
---|
68 | * all enumerated PORTNAMES entries.
|
---|
69 | * pBuf - gets an array(number elements is *pulReturned) of
|
---|
70 | * PORTNAMES structures.
|
---|
71 | * Each psz in PORTNAMES structure points to a string
|
---|
72 | * copied into the end of pBuf.
|
---|
73 | *
|
---|
74 | * typedef struct _PORTNAMES {
|
---|
75 | * PSZ pszPortName; // Name of port, example: LPT1
|
---|
76 | * PSZ pszPortDesc; // Port description
|
---|
77 | * } PORTNAMES;
|
---|
78 | *
|
---|
79 | * RETURN-NORMAL = 0 - if all portnames and descriptions fit in pBuf
|
---|
80 | *
|
---|
81 | * RETURN-ERROR = ERROR_INSUFFICIENT_BUFFER - if no PORTNAMES structs
|
---|
82 | * could fit in buffer. Caller
|
---|
83 | * uses *pcbRequired to allocate
|
---|
84 | * a buffer big enough to store all
|
---|
85 | * port names.
|
---|
86 | * ERROR_MORE_DATA - if some, but not all, PORTNAMES structs
|
---|
87 | * could fit in buffer. Caller
|
---|
88 | * uses *pcbRequired to allocate
|
---|
89 | * a buffer big enough to store all
|
---|
90 | * port names.
|
---|
91 | *
|
---|
92 | * NOTE: early versions of the print object expected ERROR_MORE_DATA
|
---|
93 | * to be returned, even when no PORTNAMES structures would fit.
|
---|
94 | * For this reason, we do not return ERROR_INSUFFICIENT_BUFFER
|
---|
95 | *
|
---|
96 | ****************************************************************************/
|
---|
97 |
|
---|
98 | APIRET APIENTRY SplPdEnumPort ( HAB hab,
|
---|
99 | PVOID pBuf,
|
---|
100 | ULONG cbBuf,
|
---|
101 | PULONG pulReturned,
|
---|
102 | PULONG pulTotal,
|
---|
103 | PULONG pcbRequired )
|
---|
104 |
|
---|
105 | {
|
---|
106 | HMODULE hModule;
|
---|
107 | ULONG ulBootDrive;
|
---|
108 | ULONG rcLoadMod;
|
---|
109 | CHAR szPathName[260]; /* will contain full path to this port driver */
|
---|
110 | char temp[25];
|
---|
111 | PPORTNAMES InitPort;
|
---|
112 | _PmpfF(("Entering "));
|
---|
113 | /*
|
---|
114 | ** ensure pointers not null
|
---|
115 | */
|
---|
116 | if (!pulReturned ||
|
---|
117 | !pulTotal ||
|
---|
118 | !pcbRequired)
|
---|
119 | {
|
---|
120 | return(ERROR_INVALID_PARAMETER);
|
---|
121 | }
|
---|
122 | /*
|
---|
123 | ** if buffer length is supplied then there should be pBuf
|
---|
124 | */
|
---|
125 | if (!pBuf && cbBuf)
|
---|
126 | {
|
---|
127 | return(ERROR_INVALID_PARAMETER);
|
---|
128 | }
|
---|
129 | /*
|
---|
130 | ** We need our module handle.
|
---|
131 | ** Easiest way to do this is to find the path to our port driver
|
---|
132 | ** from the system INI file.
|
---|
133 | ** If not found in the INI file
|
---|
134 | ** assume it is in the boot drive's \OS2\DLL directory
|
---|
135 | */
|
---|
136 |
|
---|
137 | /* change ? in szDefaultPortDrvPath to boot drive */
|
---|
138 | DosQuerySysInfo (QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, &ulBootDrive,
|
---|
139 | sizeof (ULONG));
|
---|
140 | szDefaultPortDrvPath[0] = (CHAR)(ulBootDrive + 'A' - 1);
|
---|
141 |
|
---|
142 | PrfQueryProfileString (HINI_SYSTEMPROFILE,
|
---|
143 | "PM_PORT_DRIVER",
|
---|
144 | "ECUPS",
|
---|
145 | szDefaultPortDrvPath,
|
---|
146 | szPathName,
|
---|
147 | 256 );
|
---|
148 | /*
|
---|
149 | ** get module handle for our dll
|
---|
150 | */
|
---|
151 | rcLoadMod = DosLoadModule (NULL, 0, szPathName, &hModule);
|
---|
152 | _PmpfF(("rc: %u",rcLoadMod));
|
---|
153 | if(rcLoadMod!=NULL)
|
---|
154 | {
|
---|
155 | // We are beeing started from another directory ( then OS2\DLL )
|
---|
156 | // And have no way of obtaining our current module handle to get text resources.
|
---|
157 | // We have to create a temp structure, since multiple ports will not be shown anyway.
|
---|
158 |
|
---|
159 |
|
---|
160 | _PmpfF(("No module handle doing the default, bufsize= %d",cbBuf));
|
---|
161 | if( cbBuf == 0L)
|
---|
162 | {
|
---|
163 | *pcbRequired = 25;
|
---|
164 | *pulReturned = 0;
|
---|
165 | *pulTotal =1;
|
---|
166 |
|
---|
167 | return(ERROR_MORE_DATA);
|
---|
168 | }
|
---|
169 |
|
---|
170 | // check if we fit now
|
---|
171 | if(cbBuf < 25)
|
---|
172 | return(ERROR_INSUFFICIENT_BUFFER);
|
---|
173 |
|
---|
174 | InitPort = (PPORTNAMES)pBuf;
|
---|
175 | InitPort->pszPortName = (PCH)pBuf + sizeof(PORTNAMES);
|
---|
176 | strcpy(InitPort->pszPortName,"ECUPS");
|
---|
177 | InitPort->pszPortDesc = (PCH)pBuf + sizeof(PORTNAMES) + strlen(InitPort->pszPortName) + 1;
|
---|
178 | strcpy(InitPort->pszPortDesc,"eCUPS Port");
|
---|
179 | *pulReturned = 1;
|
---|
180 | _PmpfF(("result: %s,%s",InitPort->pszPortName,InitPort->pszPortDesc));
|
---|
181 |
|
---|
182 | }
|
---|
183 | else
|
---|
184 | {
|
---|
185 | /*
|
---|
186 | ** check if cbBuf is 0 - then return number of ports in pulTotal
|
---|
187 | ** and number of bytes required in pcbRequired
|
---|
188 | */
|
---|
189 | if (cbBuf == 0L)
|
---|
190 | {
|
---|
191 | *pulReturned = 0;
|
---|
192 | *pcbRequired = CalcBufLength (hab, hModule);
|
---|
193 | *pulTotal = 1; /* Currently support COM1 COM2 COM3 COM4 */
|
---|
194 | if (!rcLoadMod)
|
---|
195 | DosFreeModule (hModule);
|
---|
196 |
|
---|
197 | /*
|
---|
198 | ** NOTE: early version of the print object checked for
|
---|
199 | ** ERROR_MORE_DATA instead of ERROR_INSUFFICIENT_BUFFER
|
---|
200 | ** For this reason we return ERROR_MORE_DATA here.
|
---|
201 | */
|
---|
202 | return(ERROR_MORE_DATA);
|
---|
203 | }
|
---|
204 |
|
---|
205 |
|
---|
206 | /*
|
---|
207 | ** check number of ports info we can fit in supplied buffer
|
---|
208 | */
|
---|
209 | *pulTotal =1; /* Currently support COM1 COM2 COM3 COM4 */
|
---|
210 | *pcbRequired = CalcBufLength (hab, hModule);
|
---|
211 | *pulReturned = NumPortsCanFit (hab, hModule, cbBuf);
|
---|
212 |
|
---|
213 | /*
|
---|
214 | ** return error if we can not fit one port.
|
---|
215 | */
|
---|
216 | if (!(*pulReturned))
|
---|
217 | {
|
---|
218 | if (!rcLoadMod)
|
---|
219 | DosFreeModule (hModule);
|
---|
220 | return(ERROR_INSUFFICIENT_BUFFER);
|
---|
221 | }
|
---|
222 |
|
---|
223 | /*
|
---|
224 | ** copy all the ports which we can store in the pBuf
|
---|
225 | */
|
---|
226 |
|
---|
227 |
|
---|
228 | CopyNPorts (hab, hModule, (PCH)pBuf, *pulReturned);
|
---|
229 |
|
---|
230 | /*
|
---|
231 | ** Free the module - we do not need it any more.
|
---|
232 | */
|
---|
233 | if (!rcLoadMod)
|
---|
234 | DosFreeModule (hModule);
|
---|
235 |
|
---|
236 | /*
|
---|
237 | ** copy all the ports which we can store in the pBuf
|
---|
238 | */
|
---|
239 | if (*pulReturned < *pulTotal)
|
---|
240 | {
|
---|
241 | return(ERROR_MORE_DATA);
|
---|
242 | }
|
---|
243 |
|
---|
244 | }
|
---|
245 | _PmpfF(("out"));
|
---|
246 | return(NO_ERROR);
|
---|
247 | }
|
---|
248 |
|
---|
249 | /****************************************************************************
|
---|
250 | *
|
---|
251 | * FUNCTION NAME = SplPdInitPort
|
---|
252 | *
|
---|
253 | * DESCRIPTION = Initialize port on behalf of the spooler
|
---|
254 | *
|
---|
255 | * INPUT = hFile - File handle to port
|
---|
256 | * pszPortName - name of port to initialize
|
---|
257 | *
|
---|
258 | * OUTPUT = Sets Serial communications port settings
|
---|
259 | *
|
---|
260 | * RETURN-NORMAL = 0
|
---|
261 | *
|
---|
262 | * RETURN-ERROR = ERROR_INVALID_PARAMETER - if bad port name given
|
---|
263 | *
|
---|
264 | ****************************************************************************/
|
---|
265 |
|
---|
266 | APIRET APIENTRY SplPdInitPort ( HFILE hFile,
|
---|
267 | PSZ pszPortName )
|
---|
268 | {
|
---|
269 | CHAR chBuf[STR_LEN_PORTNAME];
|
---|
270 | CHAR chInitVal[STR_LEN_PORTNAME];
|
---|
271 | PCH pchPortDriver = chInitVal;
|
---|
272 | _PmpfF(("Entering"));
|
---|
273 | /*
|
---|
274 | ** Check if port name string is NULL. This is an error.
|
---|
275 | */
|
---|
276 | if (!pszPortName)
|
---|
277 | {
|
---|
278 | return(ERROR_INVALID_PARAMETER);
|
---|
279 | }
|
---|
280 |
|
---|
281 | /*
|
---|
282 | ** Make Application name string( "PM_PortName" )
|
---|
283 | */
|
---|
284 |
|
---|
285 |
|
---|
286 | /*
|
---|
287 | ** Check if this port is a serial port.
|
---|
288 | ** (See if port driver for this port is "ECUPS")
|
---|
289 | */
|
---|
290 | if (!(PrfQueryProfileString (HINI_SYSTEMPROFILE, APPNAME,
|
---|
291 | KEY_PORTDRIVER, NULL, pchPortDriver,
|
---|
292 | STR_LEN_PORTNAME)))
|
---|
293 | {
|
---|
294 | return(ERROR_INVALID_PARAMETER);
|
---|
295 | }
|
---|
296 |
|
---|
297 | if (strcmp (pchPortDriver, DEF_PORTDRIVER))
|
---|
298 | {
|
---|
299 | return(ERROR_INVALID_PARAMETER);
|
---|
300 | }
|
---|
301 |
|
---|
302 | /*
|
---|
303 | ** Check if this port is installed.
|
---|
304 | */
|
---|
305 | if (!(PrfQueryProfileString (HINI_SYSTEMPROFILE, APPNAME,
|
---|
306 | KEY_INITIALIZATION, NULL, chInitVal,
|
---|
307 | STR_LEN_PORTNAME)))
|
---|
308 | {
|
---|
309 | return(ERROR_INVALID_PARAMETER);
|
---|
310 | }
|
---|
311 |
|
---|
312 | /*
|
---|
313 | ** Initialize this serial port.
|
---|
314 | */
|
---|
315 | _PmpfF(("out"));
|
---|
316 | return(NO_ERROR);
|
---|
317 |
|
---|
318 | }
|
---|
319 |
|
---|
320 | /****************************************************************************
|
---|
321 | *
|
---|
322 | * FUNCTION NAME = SplPdInstallPort
|
---|
323 | *
|
---|
324 | * DESCRIPTION = Tells port driver the name of a port that needs to be
|
---|
325 | * installed.
|
---|
326 | * Port driver should write Initialization/Termination
|
---|
327 | * strings to the INI file.
|
---|
328 | * Typically SplPdSetPort will be called after this.
|
---|
329 | * This should allow any port to be added for this port driver.
|
---|
330 | * (ie: if it is not a port we returned in SplPdEnumPort,
|
---|
331 | * still allow the port to use this port driver).
|
---|
332 | *
|
---|
333 | * INPUT = hab - Anchor block handle
|
---|
334 | * pszPortName - name of port to be installed
|
---|
335 | *
|
---|
336 | * OUTPUT =
|
---|
337 | *
|
---|
338 | * RETURN-NORMAL = 0
|
---|
339 | *
|
---|
340 | * RETURN-ERROR = ERROR_INVALID_PARAMETER - if bad port name given
|
---|
341 | *
|
---|
342 | ****************************************************************************/
|
---|
343 |
|
---|
344 | APIRET APIENTRY SplPdInstallPort ( HAB hab,
|
---|
345 | PSZ pszPortName )
|
---|
346 | {
|
---|
347 | CHAR chBuf[STR_LEN_PORTNAME];
|
---|
348 | CHAR chPortDesc[STR_LEN_PORTDESC];
|
---|
349 | ULONG ulBootDrive,err;
|
---|
350 | HMODULE hModule;
|
---|
351 | CHAR szPathName[260]; /* will contain full path to this port driver */
|
---|
352 | _PmpfF(("Entering for port: %s",pszPortName));
|
---|
353 | // DE ("SplPdInstallPort-in");
|
---|
354 |
|
---|
355 | /*
|
---|
356 | ** Check if port name string is NULL. This is an error.
|
---|
357 | */
|
---|
358 | if (!pszPortName)
|
---|
359 | {
|
---|
360 | return(ERROR_INVALID_PARAMETER);
|
---|
361 | }
|
---|
362 | /*
|
---|
363 | ** We need our module handle.
|
---|
364 | ** Easiest way to do this is to find the path to our port driver
|
---|
365 | ** from the system INI file.
|
---|
366 | ** If not found in the INI file
|
---|
367 | ** assume it is in the boot drive's \OS2\DLL directory
|
---|
368 | */
|
---|
369 |
|
---|
370 | /* change ? in szDefaultPortDrvPath to boot drive */
|
---|
371 | DosQuerySysInfo (QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, &ulBootDrive,
|
---|
372 | sizeof (ULONG));
|
---|
373 | szDefaultPortDrvPath[0] = (CHAR)(ulBootDrive + 'A' - 1);
|
---|
374 |
|
---|
375 | PrfQueryProfileString (HINI_SYSTEMPROFILE,
|
---|
376 | "PM_PORT_DRIVER",
|
---|
377 | "ECUPS",
|
---|
378 | szDefaultPortDrvPath,
|
---|
379 | szPathName,
|
---|
380 | 256 );
|
---|
381 |
|
---|
382 | hModule = 0L ; /* Init module handle to null */
|
---|
383 |
|
---|
384 |
|
---|
385 | /*
|
---|
386 | ** get module handle for our dll
|
---|
387 | */
|
---|
388 | DosLoadModule (NULL, 0, szPathName, &hModule);
|
---|
389 |
|
---|
390 | /*
|
---|
391 | ** Check if we have description for port
|
---|
392 | */
|
---|
393 | if (!GetPortDescription (hab, hModule, pszPortName, chPortDesc))
|
---|
394 | {
|
---|
395 | /*
|
---|
396 | ** Port description not found, use port name
|
---|
397 | */
|
---|
398 | strcpy( chPortDesc, pszPortName );
|
---|
399 | }
|
---|
400 |
|
---|
401 | /*
|
---|
402 | ** Free the module
|
---|
403 | */
|
---|
404 | DosFreeModule (hModule);
|
---|
405 |
|
---|
406 | /*
|
---|
407 | ** Make Application name string.
|
---|
408 | */
|
---|
409 |
|
---|
410 |
|
---|
411 | /*
|
---|
412 | ** Write data for this port in ini file with new format.
|
---|
413 | */
|
---|
414 | if (!PrfWriteProfileString (HINI_SYSTEMPROFILE,
|
---|
415 | APPNAME,
|
---|
416 | KEY_DESCRIPTION,
|
---|
417 | chPortDesc))
|
---|
418 | {
|
---|
419 | return (WinGetLastError (hab));
|
---|
420 | }
|
---|
421 | if (!PrfWriteProfileString (HINI_SYSTEMPROFILE,
|
---|
422 | APPNAME,
|
---|
423 | KEY_INITIALIZATION,
|
---|
424 | DEF_INITIALIZATION))
|
---|
425 | {
|
---|
426 | return (WinGetLastError (hab));
|
---|
427 | }
|
---|
428 | if (!PrfWriteProfileString (HINI_SYSTEMPROFILE,
|
---|
429 | APPNAME,
|
---|
430 | KEY_PORTDRIVER,
|
---|
431 | DEF_PORTDRIVER))
|
---|
432 | {
|
---|
433 | return (WinGetLastError (hab));
|
---|
434 | }
|
---|
435 | /*
|
---|
436 | ** Write data for this port in ini file with old format.
|
---|
437 | */
|
---|
438 |
|
---|
439 | // bvl: this old format apparently requires a trailing semicolon (;) to function correctly
|
---|
440 | // so we add it only on this place to prevent the installation from working at once.
|
---|
441 |
|
---|
442 | sprintf(szPathName,"%s;",DEF_INITIALIZATION);
|
---|
443 |
|
---|
444 | if (!PrfWriteProfileString (HINI_SYSTEMPROFILE,
|
---|
445 | APPNAME_PM_SPOOLER_PORT,
|
---|
446 | pszPortName,
|
---|
447 | szPathName))
|
---|
448 | {
|
---|
449 | return (WinGetLastError (hab));
|
---|
450 | }
|
---|
451 | _PmpfF(("out"));
|
---|
452 | return(NO_ERROR);
|
---|
453 | }
|
---|
454 |
|
---|
455 | /****************************************************************************
|
---|
456 | *
|
---|
457 | * FUNCTION NAME = SplPdGetPortIcon
|
---|
458 | *
|
---|
459 | * DESCRIPTION = Return Resource ID of icon representing this port.
|
---|
460 | * Note: only one icon will represent all ports supported
|
---|
461 | * by a port driver.
|
---|
462 | *
|
---|
463 | * INPUT = hab - Anchor block handle
|
---|
464 | * idIcon - gets Resource ID of icon bit map
|
---|
465 | *
|
---|
466 | * OUTPUT =
|
---|
467 | *
|
---|
468 | * RETURN-NORMAL = TRUE
|
---|
469 | *
|
---|
470 | * RETURN-ERROR = FALSE - if unable to return icon Resource ID
|
---|
471 | *
|
---|
472 | ****************************************************************************/
|
---|
473 |
|
---|
474 | BOOL APIENTRY SplPdGetPortIcon ( HAB hab,
|
---|
475 | PULONG idIcon )
|
---|
476 | {
|
---|
477 | /*
|
---|
478 | ** Check for our global port icon ID(is always set)
|
---|
479 | */
|
---|
480 | _PmpfF(("Enter"));
|
---|
481 | if (idIcon)
|
---|
482 | {
|
---|
483 | *idIcon = ECUPS_ICON;
|
---|
484 | }
|
---|
485 | _PmpfF(("out"));
|
---|
486 | return(TRUE);
|
---|
487 | }
|
---|
488 |
|
---|
489 | /****************************************************************************
|
---|
490 | *
|
---|
491 | * FUNCTION NAME = SplPdQueryPort
|
---|
492 | *
|
---|
493 | * DESCRIPTION = Returns textual data that describes the port configuration.
|
---|
494 | *
|
---|
495 | * INPUT = hab - Anchor block handle
|
---|
496 | * pszPortName - name of port to get configuration for
|
---|
497 | * pBufIn - pointer to buffer of returned data structures
|
---|
498 | * cbBuf - Size of pBufIn in bytes
|
---|
499 | * cItems - Count of number of strings of descriptions
|
---|
500 | * returned
|
---|
501 | *
|
---|
502 | * OUTPUT =
|
---|
503 | *
|
---|
504 | * RETURN-NORMAL = 0
|
---|
505 | *
|
---|
506 | * RETURN-ERROR = ERROR_INSUFFICIENT_BUFFER - if buffer is too small
|
---|
507 | * ERROR_INVALID_PARAMETER - if bad port name given
|
---|
508 | *
|
---|
509 | ****************************************************************************/
|
---|
510 |
|
---|
511 | APIRET APIENTRY SplPdQueryPort ( HAB hab,
|
---|
512 | PSZ pszPortName,
|
---|
513 | PVOID pBufIn,
|
---|
514 | ULONG cbBuf,
|
---|
515 | PULONG cItems )
|
---|
516 | {
|
---|
517 | HMODULE hModule;
|
---|
518 | CHAR chString[STR_LEN_DESC];
|
---|
519 | USHORT usNumLines;
|
---|
520 | USHORT usLineID;
|
---|
521 | USHORT usStrLength;
|
---|
522 | ULONG ulBootDrive;
|
---|
523 | PCH pBuf = pBufIn;
|
---|
524 | CHAR szPathName[260]; /* will contain full path to this port driver */
|
---|
525 |
|
---|
526 | /*
|
---|
527 | ** check pointer to all the return variables is not null
|
---|
528 | */
|
---|
529 | //DE ("splpdqueryportin");
|
---|
530 | if (!cItems)
|
---|
531 | {
|
---|
532 | return(ERROR_INVALID_PARAMETER);
|
---|
533 | }
|
---|
534 |
|
---|
535 | /*
|
---|
536 | ** if pBuf or cbBuf is NULL - it is an error.
|
---|
537 | */
|
---|
538 | if (!pBuf || !cbBuf)
|
---|
539 | {
|
---|
540 | return(ERROR_INVALID_PARAMETER);
|
---|
541 | }
|
---|
542 |
|
---|
543 | /*
|
---|
544 | ** We need our module handle.
|
---|
545 | ** Easiest way to do this is to find the path to our port driver
|
---|
546 | ** from the system INI file.
|
---|
547 | ** If not found in the INI file
|
---|
548 | ** assume it is in the boot drive's \OS2\DLL directory
|
---|
549 | */
|
---|
550 |
|
---|
551 | /* change ? in szDefaultPortDrvPath to boot drive */
|
---|
552 | DosQuerySysInfo (QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, &ulBootDrive,
|
---|
553 | sizeof (ULONG));
|
---|
554 | szDefaultPortDrvPath[0] = (CHAR)(ulBootDrive + 'A' - 1);
|
---|
555 |
|
---|
556 | PrfQueryProfileString (HINI_SYSTEMPROFILE,
|
---|
557 | "PM_PORT_DRIVER",
|
---|
558 | "ECUPS",
|
---|
559 | szDefaultPortDrvPath,
|
---|
560 | szPathName,
|
---|
561 | 256 );
|
---|
562 |
|
---|
563 | hModule = 0L ; /* Init module handle to null */
|
---|
564 |
|
---|
565 | /*
|
---|
566 | ** get module handle for our dll
|
---|
567 | */
|
---|
568 | DosLoadModule (NULL, 0, szPathName, &hModule);
|
---|
569 |
|
---|
570 | chString[0] = '\0' ;
|
---|
571 |
|
---|
572 | /*
|
---|
573 | ** get number of lines.
|
---|
574 | */
|
---|
575 | WinLoadString(hab, hModule, (USHORT)ID_NUMBER_OF_DESC_LINES, STR_LEN_DESC,
|
---|
576 | chString);
|
---|
577 | usNumLines = (USHORT)atoi (chString);
|
---|
578 | usLineID = ID_FIRST_DESC_LINES;
|
---|
579 | for (*cItems = 0; *cItems < usNumLines; *cItems++)
|
---|
580 | {
|
---|
581 | WinLoadString(hab, hModule, usLineID, STR_LEN_DESC, chString);
|
---|
582 | if (cbBuf >= (usStrLength = (USHORT)(strlen (chString) + 1)))
|
---|
583 | {
|
---|
584 | strcpy (pBuf, chString);
|
---|
585 | pBuf += usStrLength;
|
---|
586 | cbBuf -= usStrLength;
|
---|
587 | }
|
---|
588 | else
|
---|
589 | {
|
---|
590 | DosFreeModule (hModule);
|
---|
591 | return(ERROR_INSUFFICIENT_BUFFER);
|
---|
592 | }
|
---|
593 | }
|
---|
594 | DosFreeModule (hModule);
|
---|
595 | _PmpfF(("out"));
|
---|
596 | return(NO_ERROR);
|
---|
597 | }
|
---|
598 |
|
---|
599 | /****************************************************************************
|
---|
600 | *
|
---|
601 | * FUNCTION NAME = SplPdSetPort
|
---|
602 | *
|
---|
603 | * DESCRIPTION = Display a dialog to allow the user to browse and modify
|
---|
604 | * port configurations.
|
---|
605 | *
|
---|
606 | * INPUT = hab - Anchor block handle
|
---|
607 | * pszPortName - name of port to configure
|
---|
608 | * flModified - Flag to indicate that the configuration
|
---|
609 | * has been modified.(TRUE if modified).
|
---|
610 | *
|
---|
611 | * OUTPUT =
|
---|
612 | *
|
---|
613 | * RETURN-NORMAL = 0
|
---|
614 | *
|
---|
615 | * RETURN-ERROR = ERROR_INVALID_PARAMETER - if bad portname given
|
---|
616 | *
|
---|
617 | ****************************************************************************/
|
---|
618 |
|
---|
619 | APIRET APIENTRY SplPdSetPort ( HAB hab,
|
---|
620 | PSZ pszPortName,
|
---|
621 | PULONG flModified )
|
---|
622 | {
|
---|
623 | CHAR chBuf[STR_LEN_PORTNAME];
|
---|
624 | CHAR chPortDriver[STR_LEN_PORTNAME];
|
---|
625 | ULONG ulBootDrive;
|
---|
626 | HMODULE hModule;
|
---|
627 | CHAR szPathName[260]; /* will contain full path to this port driver */
|
---|
628 |
|
---|
629 | eCUPSSession.hab = hab;
|
---|
630 | /*
|
---|
631 | ** Check if port name string is NULL. This is an error.
|
---|
632 | */
|
---|
633 | if (!pszPortName || !flModified)
|
---|
634 | {
|
---|
635 | return(ERROR_INVALID_PARAMETER);
|
---|
636 | }
|
---|
637 | /*
|
---|
638 | ** Make Application name string( "PM_PortName" ).
|
---|
639 | */
|
---|
640 |
|
---|
641 |
|
---|
642 | /*
|
---|
643 | ** Check if this port is a serial port.
|
---|
644 | */
|
---|
645 | if (!(PrfQueryProfileString (HINI_SYSTEMPROFILE, APPNAME,
|
---|
646 | KEY_PORTDRIVER, NULL, chPortDriver,
|
---|
647 | STR_LEN_PORTNAME)))
|
---|
648 | {
|
---|
649 | return(ERROR_INVALID_PARAMETER);
|
---|
650 | }
|
---|
651 | if (strcmp (chPortDriver, DEF_PORTDRIVER))
|
---|
652 | {
|
---|
653 | return(ERROR_INVALID_PARAMETER);
|
---|
654 | }
|
---|
655 | /*
|
---|
656 | ** We need our module handle.
|
---|
657 | ** Easiest way to do this is to find the path to our port driver
|
---|
658 | ** from the system INI file.
|
---|
659 | ** If not found in the INI file
|
---|
660 | ** assume it is in the boot drive's \OS2\DLL directory
|
---|
661 | */
|
---|
662 |
|
---|
663 | /* change ? in szDefaultPortDrvPath to boot drive */
|
---|
664 | DosQuerySysInfo (QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, &ulBootDrive,
|
---|
665 | sizeof (ULONG));
|
---|
666 | szDefaultPortDrvPath[0] = (CHAR)(ulBootDrive + 'A' - 1);
|
---|
667 |
|
---|
668 | PrfQueryProfileString (HINI_SYSTEMPROFILE,
|
---|
669 | "PM_PORT_DRIVER",
|
---|
670 | "ECUPS",
|
---|
671 | szDefaultPortDrvPath,
|
---|
672 | szPathName,
|
---|
673 | 256 );
|
---|
674 |
|
---|
675 | hModule = 0L ; /* Init module handle to null */
|
---|
676 | /*
|
---|
677 | ** get module handle for our dll
|
---|
678 | */
|
---|
679 | DosLoadModule (NULL, 0, szPathName, &eCUPSSession.hModule);
|
---|
680 | /*
|
---|
681 | ** Load the dialog for user to change.
|
---|
682 | */
|
---|
683 | GetPortSettings();
|
---|
684 | *flModified = OpenSerialPortDlg (hab, eCUPSSession.hModule, pszPortName, APPNAME);
|
---|
685 | /*
|
---|
686 | ** free the module
|
---|
687 | */
|
---|
688 | DosFreeModule (eCUPSSession.hModule);
|
---|
689 |
|
---|
690 | _PmpfF(("out"));
|
---|
691 | return(NO_ERROR);
|
---|
692 | }
|
---|
693 |
|
---|
694 | /****************************************************************************
|
---|
695 | *
|
---|
696 | * FUNCTION NAME = SplPdRemovePort
|
---|
697 | *
|
---|
698 | * DESCRIPTION = Tells port driver the name of a port that needs to be removed.
|
---|
699 | * Port driver should remove its data from the INI file.
|
---|
700 | *
|
---|
701 | * INPUT = hab - Anchor block handle
|
---|
702 | * pszPortName - name of port to be removed
|
---|
703 | *
|
---|
704 | * OUTPUT =
|
---|
705 | *
|
---|
706 | * RETURN-NORMAL = 0
|
---|
707 | *
|
---|
708 | * RETURN-ERROR = ERROR_INVALID_PARAMETER - if bad port name given
|
---|
709 | *
|
---|
710 | ****************************************************************************/
|
---|
711 |
|
---|
712 | APIRET APIENTRY SplPdRemovePort ( HAB hab,
|
---|
713 | PSZ pszPortName )
|
---|
714 | {
|
---|
715 | CHAR chBuf[STR_LEN_PORTNAME];
|
---|
716 | CHAR chPortDriver[STR_LEN_PORTNAME];
|
---|
717 |
|
---|
718 | if (!pszPortName)
|
---|
719 | /*
|
---|
720 | ** Check if port name string is NULL. This is an error.
|
---|
721 | */
|
---|
722 | {
|
---|
723 | return(ERROR_INVALID_PARAMETER);
|
---|
724 | }
|
---|
725 |
|
---|
726 | /*
|
---|
727 | ** Make Application name string.
|
---|
728 | */
|
---|
729 |
|
---|
730 |
|
---|
731 | /*
|
---|
732 | ** Check if this port is a serial port.
|
---|
733 | */
|
---|
734 | if (!(PrfQueryProfileString (HINI_SYSTEMPROFILE, APPNAME,
|
---|
735 | KEY_PORTDRIVER, NULL, chPortDriver,
|
---|
736 | STR_LEN_PORTNAME)))
|
---|
737 | {
|
---|
738 | return(ERROR_INVALID_PARAMETER);
|
---|
739 | }
|
---|
740 |
|
---|
741 | if (strcmp (chPortDriver, DEF_PORTDRIVER))
|
---|
742 | {
|
---|
743 | return(ERROR_INVALID_PARAMETER);
|
---|
744 | }
|
---|
745 |
|
---|
746 | /*
|
---|
747 | ** We found port to be removed.
|
---|
748 | ** Remove it from new format "PM_portname"
|
---|
749 | */
|
---|
750 | PrfWriteProfileString (HINI_SYSTEMPROFILE, chBuf, NULL, NULL);
|
---|
751 |
|
---|
752 | /*
|
---|
753 | ** remove this port from old format.
|
---|
754 | */
|
---|
755 | PrfWriteProfileString (HINI_SYSTEMPROFILE,
|
---|
756 | APPNAME_PM_SPOOLER_PORT,
|
---|
757 | pszPortName,
|
---|
758 | NULL);
|
---|
759 | _PmpfF(("out"));
|
---|
760 | return(NO_ERROR);
|
---|
761 |
|
---|
762 | }
|
---|
763 |
|
---|
764 | /****************************************************************************
|
---|
765 | *
|
---|
766 | * FUNCTION NAME = SplPdTermPort
|
---|
767 | *
|
---|
768 | * DESCRIPTION = Terminate port on behalf of the spooler
|
---|
769 | *
|
---|
770 | * INPUT = hFile - File handle to port
|
---|
771 | * pszPortName - name of port whose job is completing
|
---|
772 | *
|
---|
773 | * OUTPUT = None currently
|
---|
774 | *
|
---|
775 | * RETURN-NORMAL = 0
|
---|
776 | *
|
---|
777 | * RETURN-ERROR = ERROR_INVALID_PARAMETER - if bad port name given
|
---|
778 | *
|
---|
779 | * NOTE: Currently there is nothing done when terminating a print
|
---|
780 | * job sent to a communications port.
|
---|
781 | *
|
---|
782 | ****************************************************************************/
|
---|
783 |
|
---|
784 | APIRET APIENTRY SplPdOpen(PSZ pszPortName,
|
---|
785 | PHFILE phDevice,
|
---|
786 | PULONG pDeviceFlags,
|
---|
787 | PVOID pPortOpenStruct)
|
---|
788 | {
|
---|
789 | APIRET rc,splerr;
|
---|
790 | ULONG action,cbNeeded,cbHeader;
|
---|
791 | char Version[256];
|
---|
792 | char cBootDrive;
|
---|
793 | PSZ pszBootDrive;
|
---|
794 | UCHAR pszClientPipeName[256];
|
---|
795 | UCHAR pszPSHeader[] = "%!PS-Adobe-3.0\n";
|
---|
796 | PSZ pszNPStartString;
|
---|
797 | FILE *phlog;
|
---|
798 |
|
---|
799 |
|
---|
800 | phlog = fopen("c:\\ecups.log","w");
|
---|
801 | if(phlog)
|
---|
802 | _set_crt_msg_handle(fileno(phlog));
|
---|
803 |
|
---|
804 | GetPortSettings();
|
---|
805 |
|
---|
806 | // query Boot drive
|
---|
807 | // value is number of drive letter adding 64 gives ascii name (3+64) = C in ascii
|
---|
808 | pszBootDrive = malloc(5);
|
---|
809 | rc = DosQuerySysInfo(5,5,&pszBootDrive,5);
|
---|
810 | pszBootDrive += 64;
|
---|
811 | cBootDrive=pszBootDrive;
|
---|
812 |
|
---|
813 |
|
---|
814 |
|
---|
815 |
|
---|
816 |
|
---|
817 |
|
---|
818 |
|
---|
819 |
|
---|
820 | // create full filespecs for both PS and log file
|
---|
821 | // bvl: store ecups.msg also in temporary path
|
---|
822 | // but first allocate some space
|
---|
823 | eCUPSSession.pszTempPath = malloc(256);
|
---|
824 | eCUPSSession.pszPSOutputFile = malloc(256);
|
---|
825 | eCUPSSession.pszPSFonts = malloc(256);
|
---|
826 | eCUPSSession.pszLogFile = malloc(256);
|
---|
827 | eCUPSSession.ulPSBufSize=0;
|
---|
828 | eCUPSSession.pszPSBuffer=NULL;
|
---|
829 |
|
---|
830 | // get TMP or TEMP path from environment to store temporay data
|
---|
831 | // if TMP or TEMP doesn't exist either pick root of boot drive
|
---|
832 |
|
---|
833 | if (DosScanEnv("TMP",&eCUPSSession.pszTempPath)==NO_ERROR)
|
---|
834 | eCUPSSession.bGeneratedTemp=FALSE;
|
---|
835 | else if (DosScanEnv("TEMP",&eCUPSSession.pszTempPath)==NO_ERROR)
|
---|
836 | eCUPSSession.bGeneratedTemp=FALSE;
|
---|
837 | else
|
---|
838 | {
|
---|
839 | eCUPSSession.pszTempPath = malloc(256);
|
---|
840 | eCUPSSession.bGeneratedTemp=TRUE;
|
---|
841 | sprintf(eCUPSSession.pszTempPath,"%c:\\",cBootDrive);
|
---|
842 | }
|
---|
843 |
|
---|
844 | sprintf(eCUPSSession.pszPSFonts,"%c:\\psfonts",cBootDrive);
|
---|
845 | sprintf(eCUPSSession.pszPSOutputFile,"%s\\ecups.ps",eCUPSSession.pszTempPath);
|
---|
846 | sprintf(eCUPSSession.pszLogFile,"%s\\ecups.msg",eCUPSSession.pszTempPath);
|
---|
847 |
|
---|
848 |
|
---|
849 | *phDevice=100;
|
---|
850 | *pDeviceFlags =0;
|
---|
851 | sprintf(Version,"eCUPS %s, created on: %s, %s\n",ECUPSVERSION,__TIME__,__DATE__);
|
---|
852 |
|
---|
853 | //retrieve all kind of information from the spooler
|
---|
854 | splerr = SplQueryJob(NULL,"ECUPS",((PPRTOPENSTRUCT0)pPortOpenStruct)->ulSpoolerJobID,3, (PVOID)NULL, 0L, &cbNeeded );
|
---|
855 | if (splerr == 2123 || splerr == ERROR_MORE_DATA )
|
---|
856 | {
|
---|
857 | _PmpfF(("not enough room for data"));
|
---|
858 | if (eCUPSSession.pJobInfo = malloc(cbNeeded) )
|
---|
859 | {
|
---|
860 | SplQueryJob(NULL,"ECUPS",((PPRTOPENSTRUCT0)pPortOpenStruct)->ulSpoolerJobID,3, eCUPSSession.pJobInfo, cbNeeded, &cbNeeded) ;
|
---|
861 | _PmpfF(("data retrieved"));
|
---|
862 | }
|
---|
863 | }
|
---|
864 |
|
---|
865 | // open both of the files
|
---|
866 |
|
---|
867 |
|
---|
868 |
|
---|
869 | _PmpfF(("Temppath: %s",eCUPSSession.pszTempPath));
|
---|
870 | _PmpfF(("uJobId: %d", eCUPSSession.pJobInfo->uJobId));
|
---|
871 | _PmpfF(("uPriority: %d", eCUPSSession.pJobInfo->uPriority));
|
---|
872 | _PmpfF(("pszUserName %s", eCUPSSession.pJobInfo->pszUserName));
|
---|
873 | _PmpfF(("uPosition %d", eCUPSSession.pJobInfo->uPosition));
|
---|
874 | _PmpfF(("fsStatus %d", eCUPSSession.pJobInfo->fsStatus));
|
---|
875 | _PmpfF(("ulSubmitted %d", eCUPSSession.pJobInfo->ulSubmitted));
|
---|
876 | _PmpfF(("ulSize %d", eCUPSSession.pJobInfo->ulSize));
|
---|
877 | _PmpfF(("pszComment %s", eCUPSSession.pJobInfo->pszComment));
|
---|
878 | _PmpfF(("pszDocument %s", eCUPSSession.pJobInfo->pszDocument));
|
---|
879 | _PmpfF(("pszNotifyName %s", eCUPSSession.pJobInfo->pszNotifyName));
|
---|
880 | _PmpfF(("pszDataType %s", eCUPSSession.pJobInfo->pszDataType));
|
---|
881 | _PmpfF(("pszParms %s", eCUPSSession.pJobInfo->pszParms));
|
---|
882 | _PmpfF(("pszStatus %s", eCUPSSession.pJobInfo->pszStatus));
|
---|
883 | _PmpfF(("pszQueue %s", eCUPSSession.pJobInfo->pszQueue));
|
---|
884 | _PmpfF(("pszQProcName %s", eCUPSSession.pJobInfo->pszQProcName));
|
---|
885 | _PmpfF(("pszQProcParms %s", eCUPSSession.pJobInfo->pszQProcParms));
|
---|
886 | _PmpfF(("pszDriverName %s", eCUPSSession.pJobInfo->pszDriverName));
|
---|
887 | _PmpfF(("pDriverData %s", eCUPSSession.pJobInfo->pDriverData));
|
---|
888 | _PmpfF(("pszPrinterName %s",eCUPSSession.pJobInfo->pszPrinterName));
|
---|
889 |
|
---|
890 |
|
---|
891 | _PmpfF(("jobname: %s",eCUPSSession.pJobInfo->pszDocument));
|
---|
892 |
|
---|
893 | DosOpen(eCUPSSession.pszLogFile,&eCUPSSession.hLogFile,&action,0,0,OPEN_ACTION_CREATE_IF_NEW|OPEN_ACTION_REPLACE_IF_EXISTS,OPEN_FLAGS_NOINHERIT|OPEN_SHARE_DENYNONE|OPEN_ACCESS_READWRITE,0);
|
---|
894 | DosWrite(eCUPSSession.hLogFile,Version,strlen(Version),&action);
|
---|
895 |
|
---|
896 | DosOpen(eCUPSSession.pszPSOutputFile,&eCUPSSession.hPSFile,&action,0,0,OPEN_ACTION_CREATE_IF_NEW|OPEN_ACTION_REPLACE_IF_EXISTS,OPEN_FLAGS_NOINHERIT|OPEN_SHARE_DENYNONE|OPEN_ACCESS_READWRITE,0);
|
---|
897 |
|
---|
898 | DosWrite(eCUPSSession.hPSFile,pszPSHeader,strlen(pszPSHeader),&cbHeader);
|
---|
899 |
|
---|
900 | _PmpfF(("out"));
|
---|
901 | return 0;
|
---|
902 | }
|
---|
903 |
|
---|
904 | APIRET APIENTRY SplPdWrite(HFILE phDevice,
|
---|
905 | PVOID pchData,
|
---|
906 | ULONG cbData,
|
---|
907 | PULONG pcbWritten)
|
---|
908 | {
|
---|
909 | PSZ pszPSIndex;
|
---|
910 |
|
---|
911 | eCUPSSession.ulPSBufSize += cbData;
|
---|
912 |
|
---|
913 | DosWrite(eCUPSSession.hPSFile,pchData,cbData,pcbWritten);
|
---|
914 |
|
---|
915 | _PmpfF(("out "));
|
---|
916 | return 0;
|
---|
917 | }
|
---|
918 |
|
---|
919 |
|
---|
920 |
|
---|
921 | APIRET APIENTRY SplPdClose(HFILE phDevice)
|
---|
922 | {
|
---|
923 | UCHAR Command[1024] ="\0";
|
---|
924 | UCHAR Prog[256] = "\0";
|
---|
925 |
|
---|
926 | HWND hwndFile;
|
---|
927 | FILEDLG fileDlg;
|
---|
928 | FILE *fpPS;
|
---|
929 | char *Parameters[1];
|
---|
930 | PSZ pszPSIndex;
|
---|
931 | int i;
|
---|
932 | char curDate[20];
|
---|
933 | time_t temptime;
|
---|
934 | struct tm *timeptr;
|
---|
935 | ULONG action;
|
---|
936 |
|
---|
937 |
|
---|
938 | _PmpfF(("Entering"));
|
---|
939 |
|
---|
940 | DosClose(eCUPSSession.hPSFile);
|
---|
941 |
|
---|
942 |
|
---|
943 | _PmpfF(("Program: %s",eCUPSSession.pszPDFOutputPath));
|
---|
944 |
|
---|
945 | DosClose(eCUPSSession.hLogFile);
|
---|
946 |
|
---|
947 | CallCups(&eCUPSSession);
|
---|
948 |
|
---|
949 | if(eCUPSSession.bGeneratedTemp)
|
---|
950 | free(eCUPSSession.pszTempPath);
|
---|
951 |
|
---|
952 | if(eCUPSSession.pszPSFonts)
|
---|
953 | free(eCUPSSession.pszPSFonts);
|
---|
954 | free(eCUPSSession.pszPSBuffer);
|
---|
955 | if(eCUPSSession.pszPSOutputFile)
|
---|
956 | free(eCUPSSession.pszPSOutputFile);
|
---|
957 | if(eCUPSSession.pszLogFile)
|
---|
958 | free(eCUPSSession.pszLogFile);
|
---|
959 | if(eCUPSSession.pJobInfo)
|
---|
960 | free(eCUPSSession.pJobInfo);
|
---|
961 |
|
---|
962 | DosBeep(1400,100);
|
---|
963 | _PmpfF(("out"));
|
---|
964 |
|
---|
965 | /* }
|
---|
966 | CATCH(excpt1)
|
---|
967 | {
|
---|
968 | }
|
---|
969 | END_CATCH();*/
|
---|
970 | return 0;
|
---|
971 | }
|
---|
972 |
|
---|
973 | APIRET APIENTRY SplPdAbortDoc(HFILE phDevice,
|
---|
974 | PVOID pchData,
|
---|
975 | ULONG cbData,
|
---|
976 | ULONG ulFlags)
|
---|
977 | {
|
---|
978 | _PmpfF(("out"));
|
---|
979 | return 0;
|
---|
980 | }
|
---|
981 |
|
---|
982 | APIRET APIENTRY SplPdNewPage(HFILE phDevice,
|
---|
983 | ULONG ulPageNumber)
|
---|
984 | {
|
---|
985 | _PmpfF(("out"));
|
---|
986 | return 0;
|
---|
987 | }
|
---|
988 |
|
---|
989 | APIRET APIENTRY SplPdQuery(PSZ pszPortName,
|
---|
990 | ULONG ulType,
|
---|
991 | ULONG ulCommand,
|
---|
992 | PVOID pInData,
|
---|
993 | ULONG cbInData,
|
---|
994 | PVOID pOutData,
|
---|
995 | PULONG pcbOutData)
|
---|
996 | {
|
---|
997 | PPRTPORT pPrtPort;
|
---|
998 | ULONG cbNeeded;
|
---|
999 | PSZ pszConnectName;
|
---|
1000 | ULONG rc;
|
---|
1001 |
|
---|
1002 | rc=0;
|
---|
1003 | // _PmpfF(("pszPortName %s, ulType %d, ulCommand %X, cbInData %d,pcbOutData %d",pszPortName,ulType,ulCommand,cbInData,*pcbOutData));
|
---|
1004 |
|
---|
1005 | switch(ulCommand)
|
---|
1006 | {
|
---|
1007 | case BIDI_Q_PORT:
|
---|
1008 | cbNeeded = sizeof (PRTPORT) + 18;
|
---|
1009 | if (*pcbOutData >= sizeof(PRTPORT) ) {
|
---|
1010 | pPrtPort = (PPRTPORT) pOutData;
|
---|
1011 | memset ( pPrtPort, 0, sizeof (PRTPORT));
|
---|
1012 | pPrtPort->flBidiCapabilities = 0;
|
---|
1013 | pPrtPort->flBidiProtocol = PRTPORT_TYPE_NO_CNV;
|
---|
1014 | pPrtPort->ulPortType = PRTPORT_PORT_TYPE_LPT;
|
---|
1015 | pPrtPort->ulBidiLevel = 0;
|
---|
1016 | pPrtPort->ulMaxSendSize = 4096;
|
---|
1017 | pPrtPort->ulMaxReceiveSize = 4096;
|
---|
1018 | pPrtPort->ulMaxHeldResponses = 0;
|
---|
1019 | pPrtPort->ulpszDeviceID = sizeof(PRTPORT);
|
---|
1020 | if (*pcbOutData >= cbNeeded) {
|
---|
1021 | pszConnectName = (PSZ)pPrtPort + pPrtPort->ulpszDeviceID;
|
---|
1022 | strcpy( pszConnectName, "Lexmark Optra E310");
|
---|
1023 | } else {
|
---|
1024 |
|
---|
1025 | rc = ERROR_MORE_DATA;
|
---|
1026 | }
|
---|
1027 | }
|
---|
1028 | /*strcpy(pOutData,"Lexmark Optra E310");
|
---|
1029 | *pcbOutData=strlen(pOutData);*/
|
---|
1030 | break;
|
---|
1031 | case BIDI_WAIT_ALERT:
|
---|
1032 | *pcbOutData=0;
|
---|
1033 | break;
|
---|
1034 | default:
|
---|
1035 | return(ERROR_NOT_SUPPORTED);
|
---|
1036 |
|
---|
1037 | }
|
---|
1038 | // _PmpfF(("out"));
|
---|
1039 | return(rc);
|
---|
1040 | }
|
---|
1041 |
|
---|
1042 | APIRET APIENTRY SplPdSet(PSZ pszPortName,
|
---|
1043 | ULONG ulType,
|
---|
1044 | ULONG ulCommand,
|
---|
1045 | PVOID pInData,
|
---|
1046 | ULONG pcbOutData)
|
---|
1047 | {
|
---|
1048 | _PmpfF(("pszPortName %s, ulType %d, ulCommand %X, pInData %s,pcbOutData %d",pszPortName,ulType,ulCommand,pInData,pcbOutData));
|
---|
1049 | _PmpfF(("out"));
|
---|
1050 | return 0;
|
---|
1051 | }
|
---|
1052 |
|
---|
1053 | /****************************************************************************
|
---|
1054 | *
|
---|
1055 | * FUNCTION NAME = SplPdTermPort
|
---|
1056 | *
|
---|
1057 | * DESCRIPTION = Terminate port on behalf of the spooler
|
---|
1058 | *
|
---|
1059 | * INPUT = hFile - File handle to port
|
---|
1060 | * pszPortName - name of port whose job is completing
|
---|
1061 | *
|
---|
1062 | * OUTPUT = None currently
|
---|
1063 | *
|
---|
1064 | * RETURN-NORMAL = 0
|
---|
1065 | *
|
---|
1066 | * RETURN-ERROR = ERROR_INVALID_PARAMETER - if bad port name given
|
---|
1067 | *
|
---|
1068 | * NOTE: Currently there is nothing done when terminating a print
|
---|
1069 | * job sent to a communications port.
|
---|
1070 | *
|
---|
1071 | ****************************************************************************/
|
---|
1072 |
|
---|
1073 | APIRET APIENTRY SplPdTermPort ( HFILE hFile,
|
---|
1074 | PSZ pszPortName )
|
---|
1075 | {
|
---|
1076 | #ifdef TERM_ACTION_NEEDED /* @WPOS */
|
---|
1077 | CHAR chBuf[STR_LEN_PORTNAME];
|
---|
1078 | PCH chPortDriver[STR_LEN_PORTNAME];
|
---|
1079 | #endif
|
---|
1080 |
|
---|
1081 | /*
|
---|
1082 | ** We do not have to take any action. Return NO_ERROR
|
---|
1083 | */
|
---|
1084 | return(NO_ERROR);
|
---|
1085 |
|
---|
1086 | #ifdef TERM_ACTION_NEEDED
|
---|
1087 | /*
|
---|
1088 | ** Check if port name string is NULL. This is an error.
|
---|
1089 | */
|
---|
1090 | if (!pszPortName)
|
---|
1091 | {
|
---|
1092 | return(ERROR_INVALID_PARAMETER);
|
---|
1093 | }
|
---|
1094 |
|
---|
1095 | strcpy (chBuf, APPNAME_LEAD_STR);
|
---|
1096 | /*
|
---|
1097 | ** Make Application name string.
|
---|
1098 | */
|
---|
1099 | strcat (chBuf, pszPortName);
|
---|
1100 |
|
---|
1101 | /*
|
---|
1102 | ** Check if this port is a serial port.
|
---|
1103 | */
|
---|
1104 | if (!(PrfQueryProfileString (HINI_SYSTEMPROFILE, chBuf,
|
---|
1105 | KEY_PORTDRIVER, NULL, chPortDriver, 64)))
|
---|
1106 | {
|
---|
1107 | return(ERROR_INVALID_PARAMETER);
|
---|
1108 | }
|
---|
1109 |
|
---|
1110 | if (strcmp ((PSZ)chPortDriver, DEF_PORTDRIVER))
|
---|
1111 | {
|
---|
1112 | return(ERROR_INVALID_PARAMETER);
|
---|
1113 | }
|
---|
1114 |
|
---|
1115 | /*
|
---|
1116 | ** We do not have to take any action - return NO_ERROR
|
---|
1117 | */
|
---|
1118 | _PmpfF(("out"));
|
---|
1119 | return(NO_ERROR);
|
---|
1120 |
|
---|
1121 | #endif
|
---|
1122 |
|
---|
1123 | }
|
---|
1124 |
|
---|
1125 | /****************************************************************************
|
---|
1126 | *
|
---|
1127 | * FUNCTION NAME = CalcBufLength
|
---|
1128 | *
|
---|
1129 | * DESCRIPTION = Determine how big buffer is needed to store all PORTNAMES
|
---|
1130 | * structures
|
---|
1131 | *
|
---|
1132 | * INPUT = hab - anchor block handle
|
---|
1133 | * hModule - this port driver's module handle
|
---|
1134 | *
|
---|
1135 | * OUTPUT = length of buffer necessary to store all default port names
|
---|
1136 | * supported by this port driver.
|
---|
1137 | *
|
---|
1138 | * RETURN-NORMAL =
|
---|
1139 | * RETURN-ERROR =
|
---|
1140 | *
|
---|
1141 | ****************************************************************************/
|
---|
1142 |
|
---|
1143 | ULONG CalcBufLength ( HAB hab,
|
---|
1144 | HMODULE hModule )
|
---|
1145 | {
|
---|
1146 | ULONG cbRequired;
|
---|
1147 | USHORT usID;
|
---|
1148 |
|
---|
1149 | cbRequired = 0;
|
---|
1150 |
|
---|
1151 | /*
|
---|
1152 | ** calculate length required to fit all the port info.
|
---|
1153 | */
|
---|
1154 | for (usID = PORT_ID_FIRST; usID <= PORT_ID_LAST; usID += 2)
|
---|
1155 | {
|
---|
1156 | cbRequired += CalcStructLength (hab, hModule, usID);
|
---|
1157 | }
|
---|
1158 |
|
---|
1159 | return(cbRequired);
|
---|
1160 | }
|
---|
1161 |
|
---|
1162 | /****************************************************************************
|
---|
1163 | *
|
---|
1164 | * FUNCTION NAME = CalcStructLength
|
---|
1165 | *
|
---|
1166 | * DESCRIPTION = Determine size of buffer needed to store PORTNAMES structure
|
---|
1167 | * for given string ID.
|
---|
1168 | *
|
---|
1169 | * INPUT = hab - anchor block handle
|
---|
1170 | * hModule - this port driver's module handle
|
---|
1171 | * usID - string ID for port name
|
---|
1172 | *
|
---|
1173 | * OUTPUT = length of buffer necessary to store this port name
|
---|
1174 | *
|
---|
1175 | * RETURN-NORMAL =
|
---|
1176 | * RETURN-ERROR =
|
---|
1177 | *
|
---|
1178 | ****************************************************************************/
|
---|
1179 |
|
---|
1180 | ULONG CalcStructLength ( HAB hab,
|
---|
1181 | HMODULE hModule,
|
---|
1182 | USHORT usID )
|
---|
1183 | {
|
---|
1184 | ULONG cbRequired;
|
---|
1185 | CHAR chString[STR_LEN_PORTDESC];
|
---|
1186 |
|
---|
1187 | cbRequired = 0;
|
---|
1188 |
|
---|
1189 | WinLoadString(hab, hModule, usID, STR_LEN_PORTDESC, chString);
|
---|
1190 | cbRequired += strlen (chString) + 1;
|
---|
1191 | WinLoadString(hab, hModule, (USHORT)(usID + 1), STR_LEN_PORTDESC, chString);
|
---|
1192 | cbRequired += strlen (chString) + 1;
|
---|
1193 | cbRequired += sizeof (PORTNAMES);
|
---|
1194 | return(cbRequired);
|
---|
1195 | }
|
---|
1196 |
|
---|
1197 | /****************************************************************************
|
---|
1198 | *
|
---|
1199 | * FUNCTION NAME = NumPortsCanFit
|
---|
1200 | *
|
---|
1201 | * DESCRIPTION = Determine how many ports can fit in buffer
|
---|
1202 | *
|
---|
1203 | * INPUT = hab - anchor block handle
|
---|
1204 | * hModule - this port driver's module handle
|
---|
1205 | * cbBuf - size in bytes of buffer to hold PORTNAMES
|
---|
1206 | *
|
---|
1207 | * OUTPUT = count of PORTNAMES structures that can fit in buffer
|
---|
1208 | *
|
---|
1209 | * RETURN-NORMAL =
|
---|
1210 | * RETURN-ERROR =
|
---|
1211 | *
|
---|
1212 | ****************************************************************************/
|
---|
1213 |
|
---|
1214 | ULONG NumPortsCanFit ( HAB hab,
|
---|
1215 | HMODULE hModule,
|
---|
1216 | ULONG cbBuf )
|
---|
1217 | {
|
---|
1218 | volatile ULONG cbRequired;
|
---|
1219 | USHORT usID;
|
---|
1220 | ULONG ulNumPort;
|
---|
1221 | char temp[25];
|
---|
1222 |
|
---|
1223 |
|
---|
1224 | cbRequired = 0;
|
---|
1225 | ulNumPort = 0;
|
---|
1226 |
|
---|
1227 | /*
|
---|
1228 | ** calculate how many ports we can fit in buf.
|
---|
1229 | */
|
---|
1230 | for (usID = PORT_ID_FIRST; usID <= PORT_ID_LAST; usID += 2)
|
---|
1231 | {
|
---|
1232 | cbRequired += CalcStructLength (hab, hModule, usID);
|
---|
1233 | //DE ("cbuf");
|
---|
1234 | //DE (itoa(cbBuf,temp,10));
|
---|
1235 | //DE ("cbreq");
|
---|
1236 | itoa(cbRequired,temp,10);
|
---|
1237 | if (cbRequired > cbBuf)
|
---|
1238 | {
|
---|
1239 | return(ulNumPort);
|
---|
1240 | }
|
---|
1241 | ulNumPort++;
|
---|
1242 | }
|
---|
1243 | return(ulNumPort);
|
---|
1244 | }
|
---|
1245 |
|
---|
1246 | /****************************************************************************
|
---|
1247 | *
|
---|
1248 | * FUNCTION NAME = CopyNPorts
|
---|
1249 | *
|
---|
1250 | * DESCRIPTION = Copy given number of ports into buffer
|
---|
1251 | *
|
---|
1252 | * INPUT = hab - anchor block handle
|
---|
1253 | * hModule - this port driver's module handle
|
---|
1254 | * pBuf - buffer to get PORTNAMES structures
|
---|
1255 | * ulReturned - number of ports to return
|
---|
1256 | *
|
---|
1257 | * OUTPUT = pBuf is updated
|
---|
1258 | *
|
---|
1259 | * RETURN-NORMAL =
|
---|
1260 | * RETURN-ERROR =
|
---|
1261 | *
|
---|
1262 | ****************************************************************************/
|
---|
1263 |
|
---|
1264 | VOID CopyNPorts ( HAB hab,
|
---|
1265 | HMODULE hModule,
|
---|
1266 | PCH pBuf,
|
---|
1267 | ULONG ulReturned )
|
---|
1268 | {
|
---|
1269 | USHORT usID;
|
---|
1270 | ULONG ulBeginText;
|
---|
1271 | ULONG ulBeginStruct;
|
---|
1272 |
|
---|
1273 | ulBeginText = ulReturned * sizeof (PORTNAMES);
|
---|
1274 | ulBeginStruct = 0;
|
---|
1275 |
|
---|
1276 | for (usID = PORT_ID_FIRST;
|
---|
1277 | usID <= PORT_ID_LAST && ulReturned;
|
---|
1278 | usID += 2, --ulReturned)
|
---|
1279 | {
|
---|
1280 | CopyStruct (hab, hModule, usID, pBuf, &ulBeginStruct, &ulBeginText);
|
---|
1281 | }
|
---|
1282 | }
|
---|
1283 |
|
---|
1284 | /****************************************************************************
|
---|
1285 | *
|
---|
1286 | * FUNCTION NAME = CopyStruct
|
---|
1287 | *
|
---|
1288 | * DESCRIPTION = Copy single PORTNAMES structure to buffer
|
---|
1289 | *
|
---|
1290 | * INPUT = hab - anchor block handle
|
---|
1291 | * hModule - this port driver's module handle
|
---|
1292 | * usID - string ID for port to return
|
---|
1293 | * pBuf - buffer to get PORTNAMES structures
|
---|
1294 | * pulBeginStruct - offset from begin of pBuf to store next
|
---|
1295 | * PORTNAMES
|
---|
1296 | * pulBeginText - offset from pBuf to store next string
|
---|
1297 | *
|
---|
1298 | * OUTPUT = pBuf is updated
|
---|
1299 | *
|
---|
1300 | * RETURN-NORMAL =
|
---|
1301 | * RETURN-ERROR =
|
---|
1302 | *
|
---|
1303 | ****************************************************************************/
|
---|
1304 |
|
---|
1305 | VOID CopyStruct ( HAB hab,
|
---|
1306 | HMODULE hModule,
|
---|
1307 | USHORT usID,
|
---|
1308 | PCH pBuf,
|
---|
1309 | PULONG pulBeginStruct,
|
---|
1310 | PULONG pulBeginText )
|
---|
1311 | {
|
---|
1312 | PPORTNAMES pPortNames;
|
---|
1313 |
|
---|
1314 | pPortNames = (PPORTNAMES)(pBuf + *pulBeginStruct);
|
---|
1315 | *pulBeginStruct += sizeof (PORTNAMES);
|
---|
1316 |
|
---|
1317 | /*
|
---|
1318 | ** copy port name in the structure
|
---|
1319 | */
|
---|
1320 | pPortNames->pszPortName = pBuf + *pulBeginText;
|
---|
1321 | WinLoadString(hab, hModule, usID, STR_LEN_PORTDESC, pPortNames->pszPortName);
|
---|
1322 | *pulBeginText += strlen (pPortNames->pszPortName) + 1;
|
---|
1323 | _PmpfF(("Portname: in module: %d on id %d %s",hModule,usID,pPortNames->pszPortName));
|
---|
1324 | /*
|
---|
1325 | ** copy port description to the structure
|
---|
1326 | */
|
---|
1327 | pPortNames->pszPortDesc = pBuf + *pulBeginText;
|
---|
1328 | WinLoadString(hab, hModule, usID+1, STR_LEN_PORTDESC, pPortNames->pszPortDesc);
|
---|
1329 | *pulBeginText += strlen (pPortNames->pszPortDesc) + 1;
|
---|
1330 | _PmpfF(("PortDesc: %s",pPortNames->pszPortDesc));
|
---|
1331 | }
|
---|
1332 |
|
---|
1333 | /****************************************************************************
|
---|
1334 | *
|
---|
1335 | * FUNCTION NAME = GetPortDescription
|
---|
1336 | *
|
---|
1337 | * DESCRIPTION = Get port description from our string resources.
|
---|
1338 | *
|
---|
1339 | * INPUT = hab - anchor block handle
|
---|
1340 | * hModule - this port driver's module handle
|
---|
1341 | * pszPortName - name of port to get description for
|
---|
1342 | * pszPortDesc - gets port description
|
---|
1343 | *
|
---|
1344 | * OUTPUT = TRUE - if portname description is found
|
---|
1345 | * FALSE - if not
|
---|
1346 | *
|
---|
1347 | * RETURN-NORMAL =
|
---|
1348 | * RETURN-ERROR =
|
---|
1349 | *
|
---|
1350 | ****************************************************************************/
|
---|
1351 |
|
---|
1352 | BOOL GetPortDescription ( HAB hab,
|
---|
1353 | HMODULE hModule,
|
---|
1354 | PSZ pszPortName,
|
---|
1355 | PSZ pszPortDesc )
|
---|
1356 | {
|
---|
1357 | USHORT usID;
|
---|
1358 | CHAR chBuf[STR_LEN_PORTDESC];
|
---|
1359 | //DE ("getportdescription");
|
---|
1360 | for (usID = PORT_ID_FIRST; usID <= PORT_ID_LAST; usID += 2)
|
---|
1361 | {
|
---|
1362 | WinLoadString(hab, hModule, usID, STR_LEN_PORTDESC, chBuf);
|
---|
1363 | if (!strcmp (pszPortName, chBuf))
|
---|
1364 | {
|
---|
1365 | strcpy (pszPortDesc, chBuf);
|
---|
1366 | return(TRUE);
|
---|
1367 | }
|
---|
1368 | }
|
---|
1369 | return(FALSE);
|
---|
1370 | }
|
---|
1371 |
|
---|
1372 |
|
---|
1373 |
|
---|
1374 | /****************************************************************************
|
---|
1375 | *
|
---|
1376 | * FUNCTION NAME = DE
|
---|
1377 | *
|
---|
1378 | * DESCRIPTION = Display Error message
|
---|
1379 | *
|
---|
1380 | * INPUT = str - error message string to display
|
---|
1381 | *
|
---|
1382 | * OUTPUT = None
|
---|
1383 | *
|
---|
1384 | * RETURN-NORMAL =
|
---|
1385 | * RETURN-ERROR =
|
---|
1386 | *
|
---|
1387 | ****************************************************************************/
|
---|
1388 |
|
---|
1389 | VOID DE (PCH str)
|
---|
1390 | {
|
---|
1391 | WinMessageBox( HWND_DESKTOP, HWND_DESKTOP,
|
---|
1392 | (PCH)str,
|
---|
1393 | (PCH)"eCUPS Error",
|
---|
1394 | 1,
|
---|
1395 | MB_OKCANCEL | MB_APPLMODAL |
|
---|
1396 | MB_MOVEABLE | MB_ICONASTERISK);
|
---|
1397 |
|
---|
1398 | }
|
---|
1399 |
|
---|
1400 | /****************************************************************************
|
---|
1401 | *
|
---|
1402 | * FUNCTION NAME = DisplayError
|
---|
1403 | *
|
---|
1404 | * DESCRIPTION = Display error having string from the resource file.
|
---|
1405 | *
|
---|
1406 | * INPUT = hwndOwner - Owner of message box.
|
---|
1407 | * if NULL, default is last active window.
|
---|
1408 | * usStringID - ID of string in resource file.
|
---|
1409 | * usWinStyle - Window style of message box.
|
---|
1410 | * if NULL, default is MB_OK.
|
---|
1411 | *
|
---|
1412 | * OUTPUT = User-response value returned by WimMessageBox API.
|
---|
1413 | *
|
---|
1414 | * RETURN-NORMAL =
|
---|
1415 | * RETURN-ERROR =
|
---|
1416 | *
|
---|
1417 | ****************************************************************************/
|
---|
1418 |
|
---|
1419 | USHORT DisplayError (HWND hwndOwner,
|
---|
1420 | HMODULE hModule,
|
---|
1421 | USHORT usStringID,
|
---|
1422 | USHORT usWinStyle )
|
---|
1423 | {
|
---|
1424 | CHAR pszTitle[256]; /* Message-box window title */
|
---|
1425 | CHAR pszText[256]; /* Message-box window message */
|
---|
1426 | USHORT usResponse;
|
---|
1427 | HAB hAB;
|
---|
1428 |
|
---|
1429 | hAB = WinQueryAnchorBlock (HWND_DESKTOP);
|
---|
1430 | WinLoadString (hAB, hModule, PORT_ERR_TITLE, 255, (PSZ)pszTitle);
|
---|
1431 | WinLoadString (hAB, hModule, usStringID, 255, (PSZ)pszText);
|
---|
1432 | if (!hwndOwner)
|
---|
1433 | {
|
---|
1434 | hwndOwner = WinQueryActiveWindow (HWND_DESKTOP);
|
---|
1435 | }
|
---|
1436 | if (!usWinStyle)
|
---|
1437 | {
|
---|
1438 | usWinStyle = MB_OK;
|
---|
1439 | }
|
---|
1440 | usResponse = WinMessageBox (HWND_DESKTOP, hwndOwner, pszText, pszTitle, 1,
|
---|
1441 | (ULONG)usWinStyle);
|
---|
1442 | return (usResponse);
|
---|
1443 |
|
---|
1444 | }
|
---|
1445 |
|
---|