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

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

Some more changes

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