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

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

Starting transformation from smb.pdr to uni.pdr (not workable yet)

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