source: branches/1.0/src/uni.c@ 23

Last change on this file since 23 was 23, checked in by diver, 15 years ago

reworked some stuff

File size: 26.0 KB
Line 
1#define LINT_ARGS /* argument checking enabled */
2
3#define INCL_DOS
4#define INCL_GPI
5#undef INCL_GPI
6#define INCL_DEV
7#define INCL_DOSMEMMGR /* Include standard OS/2 support */
8#define INCL_DOSMODULEMGR /* For DosLoadModule */
9#define INCL_DOSPROCESS
10#define INCL_GPILCIDS
11#define INCL_WINCOMMON /* Include Window Management support */
12#define INCL_WINDOWMGR
13#define INCL_WINSWITCHLIST
14#define INCL_WINPROGRAMLIST
15#define INCL_WINMENUS
16#define INCL_WINWINDOWMGR
17#define INCL_WINMESSAGEMGR
18#define INCL_WINDIALOGS
19#define INCL_WINSTATICS
20#define INCL_WINLISTBOXES
21#define INCL_WINMENUS
22#define INCL_WINSYS
23#define INCL_WINFRAMEMGR
24#define INCL_INCLWINACCELERATORS
25#define INCL_WINPOINTERS
26#define INCL_WINERRORS
27#define INCL_WINSHELLDATA
28
29#define INCL_WINTYPES
30#define INCL_WINACCELERATORS
31#define INCL_WINBUTTONS
32#define INCL_WINENTRYFIELDS
33#define INCL_WINRECTANGLES
34#define INCL_WINTIMER
35#define INCL_WINSCROLLBARS
36#define INCL_WINHEAP
37#define INCL_SHLERRORS
38#define INCL_WININPUT
39#define INCL_WINHELP
40#define INCL_WINSTDSPIN
41
42#define INCL_SPL
43#define INCL_SPLP
44#define INCL_SPLERRORS
45#define INCL_SHLERRORS
46#define INCL_DOSERRORS
47#define INCL_WINHOOKS
48
49int acrtused=1; /* Define variable to say this is a DLL */
50
51#include <os2.h>
52
53#include <stdlib.h>
54#include <string.h>
55#include <ctype.h>
56#include <stdarg.h>
57#include <stdio.h>
58#include <stdlib.h>
59#include <process.h>
60#include "uni.h"
61#include "utils.h"
62
63//
64// If port driver is not defined in INI file yet
65// assume it exists in the boot drive's \OS2\DLL directory
66//
67
68CHAR szDefaultPortDrvPath[] = { PATH_UNI_PDR };
69
70
71//
72// Below definition of PORTNAMES structure should be defined in
73// common header file pmspl.h.
74//
75
76typedef struct _PORTNAMES
77{
78 PSZ pszPortName; /* -> name of port(ie "LPT1) */
79 PSZ pszPortDesc; /* -> description of port(ie "Parallel Port 1") */
80} PORTNAMES, *PPORTNAMES;
81
82/* Alex Taylor's new version of lprtok() that can handle missing fields */
83char * lprtok (char *string,char *control)
84{
85 char *c;
86 static char *next;
87
88 if ( control == NULL ) return string;
89 if ( string == NULL ) string = next;
90 if ( string == NULL ) return NULL;
91
92 if (( c = strpbrk( string, control )) == NULL ) {
93 next = NULL;
94 }
95 else {
96 next = c+1;
97 *c = '\0';
98 }
99
100 return ( string );
101}
102MRESULT EXPENTRY CommDlg( HWND hDlg, USHORT msg, MPARAM mp1, MPARAM mp2 )
103{
104 PLPRDATA pLprData;
105 ULONG ulTimeOut = 0 ;
106 CHAR szDesc[ STR_LEN_PORTDESC ];
107 CHAR szShareName[ STR_LEN_PORTDESC ];
108 CHAR szTitle[ STR_LEN_TITLE + 1];
109 CHAR szTemp[ STR_LEN_PORTDESC ];
110 CHAR pwBuffer[256];
111 USHORT i;
112 ULONG rc = 0;
113 PUCHAR token;
114
115 switch (msg)
116 {
117 case WM_INITDLG:
118// WinSendDlgItemMsg(hDlg,ID_BINARY,BM_SETCHECK,MPFROM2SHORT(1,0),NULL);
119 pLprData = (PLPRDATA)mp2;
120 WinSetWindowULong (hDlg, QWL_USER, (ULONG)pLprData);
121 if (PrfQueryProfileString (HINI_SYSTEMPROFILE,
122 pLprData->pszAppName,
123 KEY_DESCRIPTION,
124 NULL,
125 (PSZ)szDesc,
126 STR_LEN_PORTDESC))
127 {
128 WinSetWindowText (WinWindowFromID (hDlg, (USHORT)IDD_UNI),szDesc);
129 rc = WinLoadString(pLprData->hAB,
130 pLprData->hModule,
131 PDR_ID_PROPERTIES,
132 STR_LEN_PORTDESC, szTemp);
133 if (rc) {
134 strcpy ( szTitle, pLprData->pszPortName );
135 strcat ( szTitle, " - " );
136 strcat ( szTitle, szTemp );
137 WinSetWindowText (hDlg, szTitle);
138 }
139 }
140 if (PrfQueryProfileString (HINI_SYSTEMPROFILE,
141 pLprData->pszAppName,
142 KEY_INITIALIZATION,
143 NULL,
144 szTemp,
145 sizeof(szTemp)))
146 {
147 i = 0;
148 token = lprtok(szTemp,"#");
149 while (token != NULL)
150 {
151 switch(i)
152 {
153 case 0:
154 WinSetDlgItemText(hDlg,ID_PROGRAM,token);
155 case 1:
156 if (token[ strlen(token) - 1 ] == ';')
157 token[ strlen(token)-1 ] = '\0';
158 WinSetDlgItemText(hDlg,ID_PARAMETERS,token);
159 break;
160 case 2:
161 if (token[ strlen(token) - 1 ] == ';')
162 token[ strlen(token)-1 ] = '\0';
163 WinSetDlgItemText(hDlg,ID_DIRECTORY,token);
164 break;
165 }
166 i++;
167 token = lprtok(NULL,"#");
168 }
169 }
170 break;
171
172 case WM_COMMAND:
173 pLprData = (PLPRDATA)WinQueryWindowULong (hDlg, QWL_USER);
174 switch (SHORT1FROMMP(mp1))
175 {
176 case DID_OK:
177 sprintf(szDesc," ");
178 /* Program */
179 WinQueryDlgItemText (hDlg, ID_PROGRAM, sizeof(szTemp), szTemp );
180 strcat(pLprData->szSaveLprSetting,szTemp);
181 strcat(pLprData->szSaveLprSetting,"#");
182
183 if (strlen(szTemp) > 0) {
184 strncat(szDesc, " ", STR_LEN_PORTDESC - 1);
185 strncat(szDesc, szTemp, STR_LEN_PORTDESC - 1);
186 }
187 /* strncat(szDesc, " ", STR_LEN_PORTDESC - 1);
188 strncat(szDesc, szShareName, STR_LEN_PORTDESC - 1); */
189
190 /* Parameters */
191 WinQueryDlgItemText (hDlg, ID_PARAMETERS, sizeof(szTemp), szTemp );
192 strcat(pLprData->szSaveLprSetting,szTemp);
193 strcat(pLprData->szSaveLprSetting,"#");
194
195 if (strlen(szTemp) > 0) {
196 strncat(szDesc, " ", STR_LEN_PORTDESC - 1);
197 strncat(szDesc, szTemp, STR_LEN_PORTDESC - 1);
198 }
199 /* strncat(szDesc, " ", STR_LEN_PORTDESC - 1);
200 strncat(szDesc, szShareName, STR_LEN_PORTDESC - 1); */
201
202 /* Working directory */
203 WinQueryDlgItemText (hDlg, ID_DIRECTORY, sizeof(szTemp), szTemp );
204 strcat(pLprData->szSaveLprSetting,szTemp);
205 /* strcat(pLprData->szSaveLprSetting,"#"); */
206
207 /* if (strlen(szTemp) > 0) {
208 strncat(szShareName, "\\", STR_LEN_PORTDESC - 1);
209 strncat(szShareName, szTemp, STR_LEN_PORTDESC - 1);
210 } */
211 /* Username */
212/* WinQueryDlgItemText (hDlg, ID_USER, sizeof(szTemp), szTemp );
213 strcat(pLprData->szSaveLprSetting,"#");
214 strcat(pLprData->szSaveLprSetting,szTemp); */
215 /* Number of copies */
216/* WinQueryDlgItemText (hDlg, ID_COPIES, sizeof(szTemp), szTemp );
217 strcat(pLprData->szSaveLprSetting,"#");
218 strcat(pLprData->szSaveLprSetting,szTemp); */
219 /* Password - must be the last item! */
220/* WinQueryDlgItemText (hDlg, ID_PASSWORD, sizeof(szTemp), szTemp );
221 strcat(pLprData->szSaveLprSetting,"#");
222 strcpy(pwBuffer,szTemp);
223 encryptPassword(pwBuffer,szTemp);
224 strcat(pLprData->szSaveLprSetting,szTemp);
225 */
226 if (!PrfWriteProfileString (HINI_SYSTEMPROFILE,
227 pLprData->pszAppName,
228 KEY_INITIALIZATION,
229 pLprData->szSaveLprSetting))
230 WinDismissDlg(hDlg, MBID_CANCEL);
231
232 if (!PrfWriteProfileString (HINI_SYSTEMPROFILE,
233 APPNAME_PM_SPOOLER_PORT,
234 pLprData->pszPortName,
235 pLprData->szSaveLprSetting))
236 WinDismissDlg(hDlg, MBID_CANCEL);
237
238 if (!PrfWriteProfileString (HINI_SYSTEMPROFILE,
239 pLprData->pszAppName,
240 KEY_DESCRIPTION,
241 szDesc ))
242 WinDismissDlg(hDlg, MBID_CANCEL);
243
244 WinDismissDlg(hDlg, TRUE);
245 break;
246 case DID_CANCEL:
247 WinDismissDlg(hDlg, MBID_CANCEL);
248 break;
249 }
250 break;
251 default:
252 return WinDefDlgProc(hDlg, msg, mp1, mp2) ;
253 break;
254 }
255return FALSE;
256}
257ULONG CalcStructLength ( HAB hab,
258 HMODULE hModule,
259 USHORT usID )
260{
261 ULONG cbRequired;
262 CHAR chString[STR_LEN_PORTDESC];
263
264 cbRequired = 0;
265
266 WinLoadString(hab, hModule, usID, STR_LEN_PORTDESC, chString);
267 cbRequired += strlen (chString) + 1;
268 WinLoadString(hab, hModule, (USHORT)(usID + 1), STR_LEN_PORTDESC, chString);
269 cbRequired += strlen (chString) + 1;
270 cbRequired += sizeof (PORTNAMES);
271 return(cbRequired);
272}
273
274ULONG CalcBufLength ( HAB hab,
275 HMODULE hModule )
276{
277 ULONG cbRequired;
278 USHORT usID;
279
280 cbRequired = 0;
281
282 /*
283 ** calculate length required to fit all the port info.
284 */
285 for (usID = PORT_ID_FIRST; usID <= PORT_ID_LAST; usID += 2)
286 {
287 cbRequired += CalcStructLength (hab, hModule, usID);
288 }
289
290 return(cbRequired);
291}
292
293ULONG NumPortsCanFit ( HAB hab,
294 HMODULE hModule,
295 ULONG cbBuf )
296{
297 ULONG cbRequired;
298 USHORT usID;
299 ULONG ulNumPort;
300
301 cbRequired = 0;
302 ulNumPort = 0;
303
304 /*
305 ** calculate how many ports we can fit in buf.
306 */
307 for (usID = PORT_ID_FIRST; usID <= PORT_ID_LAST; usID += 2)
308 {
309 cbRequired += CalcStructLength (hab, hModule, usID);
310 if (cbRequired > cbBuf)
311 {
312 return(ulNumPort);
313 }
314 ulNumPort++;
315 }
316
317 return(ulNumPort);
318}
319VOID CopyStruct ( HAB hab,
320 HMODULE hModule,
321 USHORT usID,
322 PCH pBuf,
323 PULONG pulBeginStruct,
324 PULONG pulBeginText )
325{
326 PPORTNAMES pPortNames;
327
328 pPortNames = (PPORTNAMES)(pBuf + *pulBeginStruct);
329 *pulBeginStruct += sizeof (PORTNAMES);
330
331 /*
332 ** copy port name in the structure
333 */
334 pPortNames->pszPortName = pBuf + *pulBeginText;
335 WinLoadString(hab, hModule, usID, STR_LEN_PORTDESC, pPortNames->pszPortName);
336 *pulBeginText += strlen (pPortNames->pszPortName) + 1;
337
338 /*
339 ** copy port description to the structure
340 */
341 pPortNames->pszPortDesc = pBuf + *pulBeginText;
342 WinLoadString(hab, hModule, usID, STR_LEN_PORTDESC, pPortNames->pszPortDesc);
343 *pulBeginText += strlen (pPortNames->pszPortDesc) + 1;
344}
345VOID CopyNPorts ( HAB hab,
346 HMODULE hModule,
347 PCH pBuf,
348 ULONG ulReturned )
349{
350 USHORT usID;
351 ULONG ulBeginText;
352 ULONG ulBeginStruct;
353
354 ulBeginText = ulReturned * sizeof (PORTNAMES);
355 ulBeginStruct = 0;
356
357 for (usID = PORT_ID_FIRST;
358 usID <= PORT_ID_LAST && ulReturned;
359 usID += 2, --ulReturned)
360 {
361 CopyStruct (hab, hModule, usID, pBuf, &ulBeginStruct, &ulBeginText);
362 }
363}
364
365ULONG OpenLprPortDlg ( HAB hab,
366 HMODULE hModule,
367 PSZ pszPortName,
368 PSZ pszAppName )
369{
370 LPRDATA LprData;
371
372 memset (&LprData, 0, sizeof (LPRDATA));
373 LprData.hAB = hab;
374 LprData.hModule = hModule;
375 LprData.pszPortName = pszPortName;
376 LprData.pszAppName = pszAppName;
377
378 WinDlgBox (HWND_DESKTOP,
379 HWND_DESKTOP,
380 (PFNWP)CommDlg,
381 (HMODULE)hModule,
382 IDD_UNI,
383 &LprData);
384
385 return LprData.lfModified;
386}
387BOOL GetPortDescription ( HAB hab,
388 HMODULE hModule,
389 PSZ pszPortName,
390 PSZ pszPortDesc )
391{
392 USHORT usID;
393 CHAR chBuf[STR_LEN_PORTDESC] = {0};
394
395 for (usID = PORT_ID_FIRST; usID <= PORT_ID_LAST; usID += 2)
396 {
397 WinLoadString(hab, hModule, usID, STR_LEN_PORTNAME, chBuf);
398 if (!strcmp (pszPortName, chBuf))
399 {
400 if ( WinLoadString(hab, hModule, usID+1, STR_LEN_PORTDESC, chBuf) ) {
401 strcpy (pszPortDesc, chBuf);
402 return(TRUE);
403 }
404 break;
405 }
406 }
407 return(FALSE);
408}
409BOOL GenerateUniquePortName( PSZ pszPortName )
410{
411 BOOL fPortExists;
412 PSZ pszEndPortName;
413 USHORT i;
414 CHAR chPortData[STR_LEN_PORTNAME];
415
416 /*
417 ** Generate a unique port name by adding numbers to the
418 ** end of pszPortName
419 */
420 pszEndPortName = pszPortName + strlen( pszPortName );
421 i = 1;
422 fPortExists = TRUE;
423 while ( (i < MAX_PORTS) && fPortExists )
424 {
425 _itoa( i, pszEndPortName, 4);
426 fPortExists = PrfQueryProfileString (HINI_SYSTEMPROFILE,
427 APPNAME_PM_SPOOLER_PORT,
428 pszPortName,
429 NULL,
430 chPortData,
431 sizeof(chPortData) - 1);
432 i++;
433 }
434 return(!fPortExists);
435}
436APIRET APIENTRY SplPdEnumPort ( HAB hab,
437 PVOID pBuf,
438 ULONG cbBuf,
439 PULONG pulReturned,
440 PULONG pulTotal,
441 PULONG pcbRequired )
442
443{
444 HMODULE hModule;
445 ULONG ulBootDrive;
446 ULONG rcLoadMod;
447 CHAR szPathName[260];
448
449 if (!pulReturned ||
450 !pulTotal ||
451 !pcbRequired)
452 {
453 return(ERROR_INVALID_PARAMETER);
454 }
455
456 if (!pBuf && cbBuf)
457 {
458 return(ERROR_INVALID_PARAMETER);
459 }
460
461 DosQuerySysInfo (QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, &ulBootDrive,
462 sizeof (ULONG));
463 szDefaultPortDrvPath[0] = (CHAR)(ulBootDrive + 'A' - 1);
464
465 PrfQueryProfileString (HINI_SYSTEMPROFILE,
466 "PM_PORT_DRIVER",
467 "UNI",
468 szDefaultPortDrvPath,
469 szPathName,
470 256 );
471
472 rcLoadMod = DosLoadModule (NULL, 0, szPathName, &hModule);
473
474 if (cbBuf == 0L)
475 {
476 *pulReturned = 0;
477 *pcbRequired = CalcBufLength (hab, hModule);
478 *pulTotal = MAX_PORTS;
479 if (!rcLoadMod)
480 DosFreeModule (hModule);
481 return(ERROR_MORE_DATA);
482 }
483
484 /*
485 ** check number of ports info we can fit in supplied buffer
486 */
487 *pulTotal = MAX_PORTS;
488 *pcbRequired = CalcBufLength (hab, hModule);
489 *pulReturned = NumPortsCanFit (hab, hModule, cbBuf);
490
491 /*
492 ** return error if we can not fit one port.
493 */
494 if (!(*pulReturned))
495 {
496 if (!rcLoadMod)
497 DosFreeModule (hModule);
498 return(ERROR_INSUFFICIENT_BUFFER);
499 }
500
501 /*
502 ** copy all the ports which we can store in the pBuf
503 */
504 CopyNPorts (hab, hModule, (PCH)pBuf, *pulReturned);
505
506 /*
507 ** Free the module - we do not need it any more.
508 */
509 if (!rcLoadMod)
510 DosFreeModule (hModule);
511
512 /*
513 ** copy all the ports which we can store in the pBuf
514 */
515 if (*pulReturned < *pulTotal)
516 {
517 return(ERROR_MORE_DATA);
518 }
519
520 return(NO_ERROR);
521}
522APIRET APIENTRY SplPdInstallPort ( HAB hab,
523 PSZ pszPortName )
524{
525 CHAR chBuf[STR_LEN_PORTNAME];
526 CHAR chPortDesc[STR_LEN_PORTDESC];
527 ULONG ulBootDrive;
528 HMODULE hModule;
529 CHAR szPathName[260]; /* will contain full path to this port driver */
530
531 if (!pszPortName)
532 {
533 return(ERROR_INVALID_PARAMETER);
534 }
535 strcpy(szDefaultPortDrvPath,PATH_UNI_PDR);
536 DosQuerySysInfo (QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, &ulBootDrive,
537 sizeof (ULONG));
538 szDefaultPortDrvPath[0] = (CHAR)(ulBootDrive + 'A' - 1);
539 strcpy( szPathName, szDefaultPortDrvPath );
540
541 /* Make sure the port driver itself is installed */
542 PrfWriteProfileString (HINI_SYSTEMPROFILE,
543 "PM_PORT_DRIVER",
544 "UNI",
545 szDefaultPortDrvPath);
546
547 /* Generate appname for "PM_UNIx" */
548 strcpy (chBuf, APPNAME_LEAD_STR);
549 strcat (chBuf, pszPortName);
550
551 /*
552 ** Check for this being our default Port Name to install.
553 ** If so (pszPortName == "UNI") then generate a unique
554 ** port name so that we can install multiple UNI printers.
555 */
556 if (!strcmp(pszPortName, DEF_PORTNAME))
557 {
558 /*
559 ** Use chBuf to store the new portname to install
560 ** Must first increment past "PM_" in chBuf
561 */
562 pszPortName = chBuf + 3;
563 GenerateUniquePortName( pszPortName );
564 }
565
566 /* Get initial port description (fall back to portname if unavailable) */
567 hModule = 0L ; /* Init module handle to null */
568 DosLoadModule (NULL, 0, szPathName, &hModule);
569 if (!GetPortDescription (hab, hModule, pszPortName, chPortDesc))
570 {
571 strcpy( chPortDesc, pszPortName );
572 }
573 DosFreeModule (hModule);
574
575 if (!PrfWriteProfileString (HINI_SYSTEMPROFILE,
576 chBuf,
577 KEY_DESCRIPTION,
578 chPortDesc))
579 {
580 return (WinGetLastError (hab));
581 }
582
583 if (!PrfWriteProfileString (HINI_SYSTEMPROFILE,
584 chBuf,
585 KEY_INITIALIZATION,
586 DEF_INITIALIZATION))
587 {
588 return (WinGetLastError (hab));
589 }
590
591 if (!PrfWriteProfileString (HINI_SYSTEMPROFILE,
592 chBuf,
593 KEY_TERMINATION,
594 DEF_TERMINATION))
595 {
596 return (WinGetLastError (hab));
597 }
598
599 if (!PrfWriteProfileString (HINI_SYSTEMPROFILE,
600 chBuf,
601 KEY_PORTDRIVER,
602 DEF_PORTDRIVER))
603 {
604 return (WinGetLastError (hab));
605 }
606
607 if (!PrfWriteProfileString (HINI_SYSTEMPROFILE,
608 chBuf,
609 KEY_TIMEOUT,
610 DEF_TIMEOUT))
611 {
612 return (WinGetLastError (hab));
613 }
614 if (!PrfWriteProfileString (HINI_SYSTEMPROFILE,
615 APPNAME_PM_SPOOLER_PORT,
616 pszPortName,
617 DEF_INITIALIZATION))
618 {
619 return (WinGetLastError (hab));
620 }
621 return(NO_ERROR);
622}
623BOOL APIENTRY SplPdGetPortIcon ( HAB hab,
624 PULONG idIcon )
625{
626 if (idIcon)
627 {
628 *idIcon = UNI_ICON;
629 }
630 return(TRUE);
631}
632APIRET APIENTRY SplPdQueryPort ( HAB hab,
633 PSZ pszPortName,
634 PVOID pBufIn,
635 ULONG cbBuf,
636 PULONG cItems )
637{
638 HMODULE hModule;
639 CHAR chString[STR_LEN_DESC];
640 USHORT usNumLines;
641 USHORT usLineID;
642 USHORT usStrLength;
643 ULONG ulBootDrive;
644 PCH pBuf = pBufIn;
645 CHAR szPathName[260]; /* will contain full path to this port driver */
646
647 if (!cItems)
648 {
649 return(ERROR_INVALID_PARAMETER);
650 }
651
652 if (!pBuf || !cbBuf)
653 {
654 return(ERROR_INVALID_PARAMETER);
655 }
656
657
658 DosQuerySysInfo (QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, &ulBootDrive,
659 sizeof (ULONG));
660 szDefaultPortDrvPath[0] = (CHAR)(ulBootDrive + 'A' - 1);
661
662 PrfQueryProfileString (HINI_SYSTEMPROFILE,
663 "PM_PORT_DRIVER",
664 "UNI",
665 szDefaultPortDrvPath,
666 szPathName,
667 256 );
668
669 hModule = 0L ;
670
671 DosLoadModule (NULL, 0, szPathName, &hModule);
672
673 chString[0] = '\0' ;
674
675 WinLoadString(hab, hModule, (USHORT)ID_NUMBER_OF_DESC_LINES, STR_LEN_DESC,
676 chString);
677 usNumLines = (USHORT)atoi (chString);
678 usLineID = ID_FIRST_DESC_LINES;
679 for (*cItems = 0; *cItems < usNumLines; *cItems++)
680 {
681 WinLoadString(hab, hModule, usLineID, STR_LEN_DESC, chString);
682 if (cbBuf >= (usStrLength = (USHORT)(strlen (chString) + 1)))
683 {
684 strcpy (pBuf, chString);
685 pBuf += usStrLength;
686 cbBuf -= usStrLength;
687 }
688 else
689 {
690 DosFreeModule (hModule);
691 return(ERROR_INSUFFICIENT_BUFFER);
692 }
693 }
694 DosFreeModule (hModule);
695 return(NO_ERROR);
696}
697APIRET APIENTRY SplPdSetPort ( HAB hab,
698 PSZ pszPortName,
699 PULONG flModified )
700{
701 CHAR chBuf[STR_LEN_PORTNAME];
702 CHAR chPortDriver[STR_LEN_PORTNAME];
703 ULONG ulBootDrive;
704 HMODULE hModule;
705 CHAR szPathName[260]; /* will contain full path to this port driver */
706
707 if (!pszPortName || !flModified)
708 {
709 return(ERROR_INVALID_PARAMETER);
710 }
711
712 strcpy (chBuf, APPNAME_LEAD_STR);
713 strcat (chBuf, pszPortName);
714
715 if (!(PrfQueryProfileString (HINI_SYSTEMPROFILE, chBuf,
716 KEY_PORTDRIVER, NULL, chPortDriver,
717 STR_LEN_PORTNAME)))
718 {
719 return(ERROR_INVALID_PARAMETER);
720 }
721
722 if (strcmp (chPortDriver, DEF_PORTDRIVER))
723 {
724 return(ERROR_INVALID_PARAMETER);
725 }
726
727 DosQuerySysInfo (QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, &ulBootDrive,
728 sizeof (ULONG));
729 szDefaultPortDrvPath[0] = (CHAR)(ulBootDrive + 'A' - 1);
730
731 PrfQueryProfileString (HINI_SYSTEMPROFILE,
732 "PM_PORT_DRIVER",
733 "UNI",
734 szDefaultPortDrvPath,
735 szPathName,
736 256 );
737
738 hModule = 0L ; /* Init module handle to null */
739
740 DosLoadModule (NULL, 0, szPathName, &hModule);
741
742 *flModified = OpenLprPortDlg (hab, hModule, pszPortName, chBuf);
743
744 DosFreeModule (hModule);
745 return(NO_ERROR);
746}
747
748
749APIRET APIENTRY SplPdRemovePort ( HAB hab,
750 PSZ pszPortName )
751{
752 CHAR chBuf[STR_LEN_PORTNAME];
753 CHAR chPortDriver[STR_LEN_PORTNAME];
754
755 if (!pszPortName)
756 {
757 return(ERROR_INVALID_PARAMETER);
758 }
759
760 strcpy (chBuf, APPNAME_LEAD_STR);
761 strcat (chBuf, pszPortName);
762
763 if (!(PrfQueryProfileString (HINI_SYSTEMPROFILE, chBuf,
764 KEY_PORTDRIVER, NULL, chPortDriver,
765 STR_LEN_PORTNAME)))
766 {
767 return(ERROR_INVALID_PARAMETER);
768 }
769
770 if (strcmp (chPortDriver, DEF_PORTDRIVER))
771 {
772 return(ERROR_INVALID_PARAMETER);
773 }
774
775 PrfWriteProfileString (HINI_SYSTEMPROFILE, chBuf, NULL, NULL);
776
777 PrfWriteProfileString (HINI_SYSTEMPROFILE,
778 APPNAME_PM_SPOOLER_PORT,
779 pszPortName,
780 NULL);
781 return(NO_ERROR);
782
783}
784ULONG APIENTRY SplPdOpen( PSZ pszPortName,
785 PHFILE phFile,
786 PULONG pDeviceFlags,
787 PVOID pPrtOpenStruct)
788{
789 APIRET rc;
790 ULONG ulAction = 0; /* Action taken by DosOpen */
791 ULONG ulBytesRead = 0; /* Number of bytes read by DosRead */
792 ULONG ulWrote = 0; /* Number of bytes written by DosWrite */
793 ULONG ulLocal = 0; /* File pointer position after DosSetFilePtr */
794 CHAR szTemp[ 256];
795 UCHAR tmp[256];
796 ULONG pcbWritten ;
797 USHORT i;
798 HFILE control;
799 UCHAR filename[256];
800 DATETIME dt;
801 UCHAR spool_dir[256];
802 PEAOP2 pEABuf = NULL;
803/* UCHAR pszPSHeader[] = "%!PS-Adobe-3.0\n";
804 ULONG cbHeader; */
805
806
807 if (!phFile || !pDeviceFlags )
808 {
809 return(ERROR_INVALID_PARAMETER);
810 }
811 DosGetDateTime(&dt);
812 rc = PrfQueryProfileString (HINI_SYSTEMPROFILE,
813 "PM_SPOOLER",
814 "DIR",
815 NULL,
816 (PSZ)spool_dir,
817 sizeof(spool_dir));
818 spool_dir[ strlen(spool_dir) - 1] = '\0';
819 sprintf(tmp,"%s\\UNI",spool_dir);
820 DosCreateDir( tmp,pEABuf );
821 sprintf(filename,"%s\\UNI\\%02d_%02d_%02d_%02d_%s",spool_dir,dt.hours,dt.minutes,dt.seconds,dt.hundredths,pszPortName);
822 rc = DosOpen(filename,
823 phFile, /* File handle */
824 &ulAction, /* Action taken */
825 100L, /* File primary allocation */
826 FILE_ARCHIVED | FILE_NORMAL, /* File attribute */
827 OPEN_ACTION_CREATE_IF_NEW |
828 OPEN_ACTION_OPEN_IF_EXISTS, /* Open function type */
829 OPEN_FLAGS_NOINHERIT |
830 OPEN_SHARE_DENYNONE |
831 OPEN_ACCESS_READWRITE, /* Open mode of the file */
832 0L); /* No extended attribute */
833/* DosWrite(*phFile,pszPSHeader,strlen(pszPSHeader),&cbHeader); */
834 sprintf(szTemp,"PM_%s",pszPortName);
835 if (PrfQueryProfileString (HINI_SYSTEMPROFILE,
836 szTemp,
837 KEY_INITIALIZATION,
838 NULL,
839 szTemp,
840 sizeof(szTemp)))
841 {
842 sprintf(tmp ,"%s\\UNI\\%d.control",spool_dir,*phFile);
843 rc = DosOpen( tmp ,
844 &control, /* File handle */
845 &ulAction, /* Action taken */
846 strlen(szTemp), /* File primary allocation */
847 FILE_ARCHIVED | FILE_NORMAL, /* File attribute */
848 OPEN_ACTION_CREATE_IF_NEW |
849 OPEN_ACTION_OPEN_IF_EXISTS, /* Open function type */
850 OPEN_FLAGS_NOINHERIT |
851 OPEN_SHARE_DENYNONE |
852 OPEN_ACCESS_READWRITE, /* Open mode of the file */
853 0L); /* No extended attribute */
854 rc = DosWrite( control,szTemp,strlen(szTemp),&pcbWritten);
855 rc = DosWrite( control,"#",1,&pcbWritten);
856 rc = DosWrite( control,filename,strlen(filename),&pcbWritten);
857 rc = DosWrite( control,"@",1,&pcbWritten);
858 rc = DosClose(control);
859 }
860return rc;
861
862}
863ULONG APIENTRY SplPdQuery ( PSZ pszDeviceName,
864 ULONG ulFlags,
865 ULONG ulCommand,
866 PVOID pInData,
867 ULONG cbInData,
868 PVOID pOutData,
869 PULONG pcbOutData )
870{
871/* return ERROR_NOT_SUPPORTED; */
872 return NO_ERROR;
873}
874ULONG APIENTRY SplPdSet ( PSZ pszDeviceName,
875 ULONG ulFlags,
876 ULONG ulCommand,
877 PVOID pInData,
878 ULONG cbInData )
879{
880/* return ERROR_NOT_SUPPORTED; */
881 return NO_ERROR;
882}
883ULONG APIENTRY SplPdNewPage ( HFILE hFile, ULONG ulPageNumber )
884{
885 return NO_ERROR;
886}
887ULONG APIENTRY SplPdAbortDoc( HFILE hFile,
888 PVOID pchData,
889 ULONG cbData,
890 ULONG ulFlags )
891{
892 return NO_ERROR;
893}
894ULONG APIENTRY SplPdClose( HFILE hFile )
895{
896 APIRET rc;
897 APIRET resp;
898 USHORT i;
899 USHORT j;
900 RESULTCODES rc_child;
901 ULONG nbr_lu;
902 ULONG ulAction;
903 UCHAR szTemp[256];
904 HFILE control;
905 UCHAR binfile[256];
906 UCHAR arg[256];
907 UCHAR j_parms[256] ;
908 char *f_parms;
909 UCHAR j_id[3];
910 UCHAR parameters[256];
911 UCHAR workingdir[256] ;
912 UCHAR j_title[256];
913 UCHAR j_copies[3];
914 UCHAR j_options[8];
915 UCHAR filename[256];
916 UCHAR ip_add[256];
917 UCHAR queue_name[256];
918 UCHAR workgroup[256];
919 UCHAR username[256];
920 UCHAR password_enc[256];
921 UCHAR password_dec[256];
922 UCHAR errorstr[256];
923 USHORT pos;
924 UCHAR spool_dir[256];
925 ULONG ulBootDrive;
926
927 rc = PrfQueryProfileString (HINI_SYSTEMPROFILE,
928 "PM_SPOOLER",
929 "DIR",
930 NULL,
931 (PSZ)spool_dir,
932 sizeof(spool_dir));
933 spool_dir[ strlen(spool_dir) - 1] = '\0';
934 sprintf(szTemp,"%s\\UNI\\%d.control",spool_dir,hFile);
935 rc = DosOpen(szTemp,
936 &control,
937 &ulAction,
938 0L,
939 FILE_ARCHIVED | FILE_NORMAL,
940 OPEN_ACTION_CREATE_IF_NEW |
941 OPEN_ACTION_OPEN_IF_EXISTS,
942 OPEN_FLAGS_NOINHERIT |
943 OPEN_SHARE_DENYNONE |
944 OPEN_ACCESS_READWRITE,
945 0L);
946 rc = DosRead( control,szTemp,sizeof(szTemp),&nbr_lu);
947 rc = DosClose( control );
948 sprintf(filename,"%s\\UNI\\%d.control",spool_dir,hFile);
949 DosDelete(filename);
950
951 i = 0;
952 j = 0;
953 pos = 0;
954 while (szTemp[i] != '@')
955 {
956 if (szTemp[i] == '#')
957 {
958 szTemp[i] = '\0';
959 switch(j)
960 {
961 case 0:strcpy(binfile,&szTemp[pos]);
962 break;
963 case 1:strcpy(parameters,&szTemp[pos]);
964 break;
965 case 2:strcpy(workingdir,&szTemp[pos]);
966 break;
967/* case 3:strcpy(username,&szTemp[pos]);
968 break;
969 case 4:strcpy(j_copies,&szTemp[pos]);
970 break;
971 case 5:strcpy(password_enc,&szTemp[pos]);
972 break; */
973 }
974 pos = i+1;
975 j++;
976 }
977 i++;
978 }
979 szTemp[i] = '\0';
980 strcpy(filename,&szTemp[pos]);
981
982 rc = DosClose( hFile );
983 DosQuerySysInfo (QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, &ulBootDrive,
984 sizeof (ULONG));
985
986 decryptPassword(password_enc,password_dec);
987
988// This is the soon to be obsolete description of smbspool
989// Usage: smbspool [DEVICE_URI] job-id user title copies options [file]
990
991
992 f_parms = malloc((strlen(parameters) - strlen("%file%") + strlen(filename)) * sizeof(char));
993
994 searchReplace("%file%", filename, parameters, f_parms);
995
996 sprintf(j_parms,f_parms);
997 free(f_parms);
998
999 rc = spawnlp(P_WAIT,binfile,binfile,j_parms,NULL);
1000
1001 while (rc != 0)
1002 {
1003 sprintf(errorstr,"Error during spooling %s to %s %s",queue_name,binfile,j_parms);
1004 resp = WinMessageBox (HWND_DESKTOP,
1005 HWND_DESKTOP,
1006 errorstr,
1007 "Universal Port driver error",
1008 0L, MB_RETRYCANCEL | MB_WARNING | MB_MOVEABLE);
1009 if (resp != MBID_CANCEL )
1010 {
1011 rc = spawnlp(P_WAIT,binfile,binfile,j_parms,NULL);
1012 }
1013 else rc = 0;
1014 };
1015
1016 strcpy(filename,&szTemp[pos]);
1017 DosDelete(filename);
1018
1019 /* We always have to return success to the spooler subsystem */
1020 rc = NO_ERROR;
1021 return rc;
1022}
1023ULONG APIENTRY SplPdWrite( HFILE hFile,
1024 PVOID pchData,
1025 ULONG cbData,
1026 PULONG pcbWritten )
1027{ APIRET rc;
1028
1029 rc = DosWrite( hFile,pchData,cbData,pcbWritten);
1030 rc = DosSleep(0);
1031 return rc;
1032}
1033
Note: See TracBrowser for help on using the repository browser.