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