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

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

Create initial Universal Port Driver repository

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