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

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

Some more changes

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