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

Last change on this file since 22 was 20, checked in by herwigb, 15 years ago

Several fixes/enhancements over 1.0 alpha 1

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