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

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

Some more changes

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