| 1 |
|
|---|
| 2 | #include "uni.h"
|
|---|
| 3 |
|
|---|
| 4 | #include <stdlib.h>
|
|---|
| 5 | #include <string.h>
|
|---|
| 6 | #include <ctype.h>
|
|---|
| 7 | #include <stdarg.h>
|
|---|
| 8 | #include <stdio.h>
|
|---|
| 9 | #include <stdlib.h>
|
|---|
| 10 | #include <process.h>
|
|---|
| 11 | #include "utils.h"
|
|---|
| 12 |
|
|---|
| 13 | //
|
|---|
| 14 | // If port driver is not defined in INI file yet
|
|---|
| 15 | // assume it exists in the boot drive's \OS2\DLL directory
|
|---|
| 16 | //
|
|---|
| 17 |
|
|---|
| 18 | CHAR szDefaultPortDrvPath[] = { PATH_UNI_PDR };
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 | APIRET APIENTRY SplPdEnumPort ( HAB hab,
|
|---|
| 22 | PVOID pBuf,
|
|---|
| 23 | ULONG cbBuf,
|
|---|
| 24 | PULONG pulReturned,
|
|---|
| 25 | PULONG pulTotal,
|
|---|
| 26 | PULONG pcbRequired )
|
|---|
| 27 |
|
|---|
| 28 | {
|
|---|
| 29 | HMODULE hModule;
|
|---|
| 30 | ULONG ulBootDrive;
|
|---|
| 31 | ULONG rcLoadMod;
|
|---|
| 32 | CHAR szPathName[260];
|
|---|
| 33 |
|
|---|
| 34 | if (!pulReturned ||
|
|---|
| 35 | !pulTotal ||
|
|---|
| 36 | !pcbRequired)
|
|---|
| 37 | {
|
|---|
| 38 | return(ERROR_INVALID_PARAMETER);
|
|---|
| 39 | }
|
|---|
| 40 |
|
|---|
| 41 | if (!pBuf && cbBuf)
|
|---|
| 42 | {
|
|---|
| 43 | return(ERROR_INVALID_PARAMETER);
|
|---|
| 44 | }
|
|---|
| 45 |
|
|---|
| 46 | DosQuerySysInfo (QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, &ulBootDrive,
|
|---|
| 47 | sizeof (ULONG));
|
|---|
| 48 | szDefaultPortDrvPath[0] = (CHAR)(ulBootDrive + 'A' - 1);
|
|---|
| 49 |
|
|---|
| 50 | PrfQueryProfileString (HINI_SYSTEMPROFILE,
|
|---|
| 51 | "PM_PORT_DRIVER",
|
|---|
| 52 | "UNI",
|
|---|
| 53 | szDefaultPortDrvPath,
|
|---|
| 54 | szPathName,
|
|---|
| 55 | 256 );
|
|---|
| 56 |
|
|---|
| 57 | rcLoadMod = DosLoadModule (NULL, 0, szPathName, &hModule);
|
|---|
| 58 |
|
|---|
| 59 | if (cbBuf == 0L)
|
|---|
| 60 | {
|
|---|
| 61 | *pulReturned = 0;
|
|---|
| 62 | *pcbRequired = CalcBufLength (hab, hModule);
|
|---|
| 63 | *pulTotal = MAX_PORTS;
|
|---|
| 64 | if (!rcLoadMod)
|
|---|
| 65 | DosFreeModule (hModule);
|
|---|
| 66 | return(ERROR_MORE_DATA);
|
|---|
| 67 | }
|
|---|
| 68 |
|
|---|
| 69 | /*
|
|---|
| 70 | ** check number of ports info we can fit in supplied buffer
|
|---|
| 71 | */
|
|---|
| 72 | *pulTotal = MAX_PORTS;
|
|---|
| 73 | *pcbRequired = CalcBufLength (hab, hModule);
|
|---|
| 74 | *pulReturned = NumPortsCanFit (hab, hModule, cbBuf);
|
|---|
| 75 |
|
|---|
| 76 | /*
|
|---|
| 77 | ** return error if we can not fit one port.
|
|---|
| 78 | */
|
|---|
| 79 | if (!(*pulReturned))
|
|---|
| 80 | {
|
|---|
| 81 | if (!rcLoadMod)
|
|---|
| 82 | DosFreeModule (hModule);
|
|---|
| 83 | return(ERROR_INSUFFICIENT_BUFFER);
|
|---|
| 84 | }
|
|---|
| 85 |
|
|---|
| 86 | /*
|
|---|
| 87 | ** copy all the ports which we can store in the pBuf
|
|---|
| 88 | */
|
|---|
| 89 | CopyNPorts (hab, hModule, (PCH)pBuf, *pulReturned);
|
|---|
| 90 |
|
|---|
| 91 | /*
|
|---|
| 92 | ** Free the module - we do not need it any more.
|
|---|
| 93 | */
|
|---|
| 94 | if (!rcLoadMod)
|
|---|
| 95 | DosFreeModule (hModule);
|
|---|
| 96 |
|
|---|
| 97 | /*
|
|---|
| 98 | ** copy all the ports which we can store in the pBuf
|
|---|
| 99 | */
|
|---|
| 100 | if (*pulReturned < *pulTotal)
|
|---|
| 101 | {
|
|---|
| 102 | return(ERROR_MORE_DATA);
|
|---|
| 103 | }
|
|---|
| 104 |
|
|---|
| 105 | return(NO_ERROR);
|
|---|
| 106 | }
|
|---|
| 107 | APIRET APIENTRY SplPdInstallPort ( HAB hab,
|
|---|
| 108 | PSZ pszPortName )
|
|---|
| 109 | {
|
|---|
| 110 | CHAR chBuf[STR_LEN_PORTNAME];
|
|---|
| 111 | CHAR chPortDesc[STR_LEN_PORTDESC];
|
|---|
| 112 | ULONG ulBootDrive;
|
|---|
| 113 | HMODULE hModule;
|
|---|
| 114 | CHAR szPathName[260]; /* will contain full path to this port driver */
|
|---|
| 115 |
|
|---|
| 116 | if (!pszPortName)
|
|---|
| 117 | {
|
|---|
| 118 | return(ERROR_INVALID_PARAMETER);
|
|---|
| 119 | }
|
|---|
| 120 | strcpy(szDefaultPortDrvPath,PATH_UNI_PDR);
|
|---|
| 121 | DosQuerySysInfo (QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, &ulBootDrive,
|
|---|
| 122 | sizeof (ULONG));
|
|---|
| 123 | szDefaultPortDrvPath[0] = (CHAR)(ulBootDrive + 'A' - 1);
|
|---|
| 124 | strcpy( szPathName, szDefaultPortDrvPath );
|
|---|
| 125 |
|
|---|
| 126 | /* Make sure the port driver itself is installed */
|
|---|
| 127 | PrfWriteProfileString (HINI_SYSTEMPROFILE,
|
|---|
| 128 | "PM_PORT_DRIVER",
|
|---|
| 129 | "UNI",
|
|---|
| 130 | szDefaultPortDrvPath);
|
|---|
| 131 |
|
|---|
| 132 | /* Generate appname for "PM_UNIx" */
|
|---|
| 133 | strcpy (chBuf, APPNAME_LEAD_STR);
|
|---|
| 134 | strcat (chBuf, pszPortName);
|
|---|
| 135 |
|
|---|
| 136 | /*
|
|---|
| 137 | ** Check for this being our default Port Name to install.
|
|---|
| 138 | ** If so (pszPortName == "UNI") then generate a unique
|
|---|
| 139 | ** port name so that we can install multiple UNI printers.
|
|---|
| 140 | */
|
|---|
| 141 | if (!strcmp(pszPortName, DEF_PORTNAME))
|
|---|
| 142 | {
|
|---|
| 143 | /*
|
|---|
| 144 | ** Use chBuf to store the new portname to install
|
|---|
| 145 | ** Must first increment past "PM_" in chBuf
|
|---|
| 146 | */
|
|---|
| 147 | pszPortName = chBuf + 3;
|
|---|
| 148 | GenerateUniquePortName( pszPortName );
|
|---|
| 149 | }
|
|---|
| 150 |
|
|---|
| 151 | /* Get initial port description (fall back to portname if unavailable) */
|
|---|
| 152 | hModule = 0L ; /* Init module handle to null */
|
|---|
| 153 | DosLoadModule (NULL, 0, szPathName, &hModule);
|
|---|
| 154 | if (!GetPortDescription (hab, hModule, pszPortName, chPortDesc))
|
|---|
| 155 | {
|
|---|
| 156 | strcpy( chPortDesc, pszPortName );
|
|---|
| 157 | }
|
|---|
| 158 | DosFreeModule (hModule);
|
|---|
| 159 |
|
|---|
| 160 | if (!PrfWriteProfileString (HINI_SYSTEMPROFILE,
|
|---|
| 161 | chBuf,
|
|---|
| 162 | KEY_DESCRIPTION,
|
|---|
| 163 | chPortDesc))
|
|---|
| 164 | {
|
|---|
| 165 | return (WinGetLastError (hab));
|
|---|
| 166 | }
|
|---|
| 167 |
|
|---|
| 168 | if (!PrfWriteProfileString (HINI_SYSTEMPROFILE,
|
|---|
| 169 | chBuf,
|
|---|
| 170 | KEY_INITIALIZATION,
|
|---|
| 171 | DEF_INITIALIZATION))
|
|---|
| 172 | {
|
|---|
| 173 | return (WinGetLastError (hab));
|
|---|
| 174 | }
|
|---|
| 175 |
|
|---|
| 176 | if (!PrfWriteProfileString (HINI_SYSTEMPROFILE,
|
|---|
| 177 | chBuf,
|
|---|
| 178 | KEY_TERMINATION,
|
|---|
| 179 | DEF_TERMINATION))
|
|---|
| 180 | {
|
|---|
| 181 | return (WinGetLastError (hab));
|
|---|
| 182 | }
|
|---|
| 183 |
|
|---|
| 184 | if (!PrfWriteProfileString (HINI_SYSTEMPROFILE,
|
|---|
| 185 | chBuf,
|
|---|
| 186 | KEY_PORTDRIVER,
|
|---|
| 187 | DEF_PORTDRIVER))
|
|---|
| 188 | {
|
|---|
| 189 | return (WinGetLastError (hab));
|
|---|
| 190 | }
|
|---|
| 191 |
|
|---|
| 192 | if (!PrfWriteProfileString (HINI_SYSTEMPROFILE,
|
|---|
| 193 | chBuf,
|
|---|
| 194 | KEY_TIMEOUT,
|
|---|
| 195 | DEF_TIMEOUT))
|
|---|
| 196 | {
|
|---|
| 197 | return (WinGetLastError (hab));
|
|---|
| 198 | }
|
|---|
| 199 | if (!PrfWriteProfileString (HINI_SYSTEMPROFILE,
|
|---|
| 200 | APPNAME_PM_SPOOLER_PORT,
|
|---|
| 201 | pszPortName,
|
|---|
| 202 | DEF_INITIALIZATION))
|
|---|
| 203 | {
|
|---|
| 204 | return (WinGetLastError (hab));
|
|---|
| 205 | }
|
|---|
| 206 | return(NO_ERROR);
|
|---|
| 207 | }
|
|---|
| 208 | BOOL APIENTRY SplPdGetPortIcon ( HAB hab,
|
|---|
| 209 | PULONG idIcon )
|
|---|
| 210 | {
|
|---|
| 211 | if (idIcon)
|
|---|
| 212 | {
|
|---|
| 213 | *idIcon = UNI_ICON;
|
|---|
| 214 | }
|
|---|
| 215 | return(TRUE);
|
|---|
| 216 | }
|
|---|
| 217 | APIRET APIENTRY SplPdQueryPort ( HAB hab,
|
|---|
| 218 | PSZ pszPortName,
|
|---|
| 219 | PVOID pBufIn,
|
|---|
| 220 | ULONG cbBuf,
|
|---|
| 221 | PULONG cItems )
|
|---|
| 222 | {
|
|---|
| 223 | HMODULE hModule;
|
|---|
| 224 | CHAR chString[STR_LEN_DESC];
|
|---|
| 225 | USHORT usNumLines;
|
|---|
| 226 | USHORT usLineID;
|
|---|
| 227 | USHORT usStrLength;
|
|---|
| 228 | ULONG ulBootDrive;
|
|---|
| 229 | PCH pBuf = pBufIn;
|
|---|
| 230 | CHAR szPathName[260]; /* will contain full path to this port driver */
|
|---|
| 231 |
|
|---|
| 232 | if (!cItems)
|
|---|
| 233 | {
|
|---|
| 234 | return(ERROR_INVALID_PARAMETER);
|
|---|
| 235 | }
|
|---|
| 236 |
|
|---|
| 237 | if (!pBuf || !cbBuf)
|
|---|
| 238 | {
|
|---|
| 239 | return(ERROR_INVALID_PARAMETER);
|
|---|
| 240 | }
|
|---|
| 241 |
|
|---|
| 242 |
|
|---|
| 243 | DosQuerySysInfo (QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, &ulBootDrive,
|
|---|
| 244 | sizeof (ULONG));
|
|---|
| 245 | szDefaultPortDrvPath[0] = (CHAR)(ulBootDrive + 'A' - 1);
|
|---|
| 246 |
|
|---|
| 247 | PrfQueryProfileString (HINI_SYSTEMPROFILE,
|
|---|
| 248 | "PM_PORT_DRIVER",
|
|---|
| 249 | "UNI",
|
|---|
| 250 | szDefaultPortDrvPath,
|
|---|
| 251 | szPathName,
|
|---|
| 252 | 256 );
|
|---|
| 253 |
|
|---|
| 254 | hModule = 0L ;
|
|---|
| 255 |
|
|---|
| 256 | DosLoadModule (NULL, 0, szPathName, &hModule);
|
|---|
| 257 |
|
|---|
| 258 | chString[0] = '\0' ;
|
|---|
| 259 |
|
|---|
| 260 | WinLoadString(hab, hModule, (USHORT)ID_NUMBER_OF_DESC_LINES, STR_LEN_DESC,
|
|---|
| 261 | chString);
|
|---|
| 262 | usNumLines = (USHORT)atoi (chString);
|
|---|
| 263 | usLineID = ID_FIRST_DESC_LINES;
|
|---|
| 264 | for (*cItems = 0; *cItems < usNumLines; *cItems++)
|
|---|
| 265 | {
|
|---|
| 266 | WinLoadString(hab, hModule, usLineID, STR_LEN_DESC, chString);
|
|---|
| 267 | if (cbBuf >= (usStrLength = (USHORT)(strlen (chString) + 1)))
|
|---|
| 268 | {
|
|---|
| 269 | strcpy (pBuf, chString);
|
|---|
| 270 | pBuf += usStrLength;
|
|---|
| 271 | cbBuf -= usStrLength;
|
|---|
| 272 | }
|
|---|
| 273 | else
|
|---|
| 274 | {
|
|---|
| 275 | DosFreeModule (hModule);
|
|---|
| 276 | return(ERROR_INSUFFICIENT_BUFFER);
|
|---|
| 277 | }
|
|---|
| 278 | }
|
|---|
| 279 | DosFreeModule (hModule);
|
|---|
| 280 | return(NO_ERROR);
|
|---|
| 281 | }
|
|---|
| 282 | APIRET APIENTRY SplPdSetPort ( HAB hab,
|
|---|
| 283 | PSZ pszPortName,
|
|---|
| 284 | PULONG flModified )
|
|---|
| 285 | {
|
|---|
| 286 | CHAR chBuf[STR_LEN_PORTNAME];
|
|---|
| 287 | CHAR chPortDriver[STR_LEN_PORTNAME];
|
|---|
| 288 | ULONG ulBootDrive;
|
|---|
| 289 | HMODULE hModule;
|
|---|
| 290 | CHAR szPathName[260]; /* will contain full path to this port driver */
|
|---|
| 291 |
|
|---|
| 292 | if (!pszPortName || !flModified)
|
|---|
| 293 | {
|
|---|
| 294 | return(ERROR_INVALID_PARAMETER);
|
|---|
| 295 | }
|
|---|
| 296 |
|
|---|
| 297 | strcpy (chBuf, APPNAME_LEAD_STR);
|
|---|
| 298 | strcat (chBuf, pszPortName);
|
|---|
| 299 |
|
|---|
| 300 | if (!(PrfQueryProfileString (HINI_SYSTEMPROFILE, chBuf,
|
|---|
| 301 | KEY_PORTDRIVER, NULL, chPortDriver,
|
|---|
| 302 | STR_LEN_PORTNAME)))
|
|---|
| 303 | {
|
|---|
| 304 | return(ERROR_INVALID_PARAMETER);
|
|---|
| 305 | }
|
|---|
| 306 |
|
|---|
| 307 | if (strcmp (chPortDriver, DEF_PORTDRIVER))
|
|---|
| 308 | {
|
|---|
| 309 | return(ERROR_INVALID_PARAMETER);
|
|---|
| 310 | }
|
|---|
| 311 |
|
|---|
| 312 | DosQuerySysInfo (QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, &ulBootDrive,
|
|---|
| 313 | sizeof (ULONG));
|
|---|
| 314 | szDefaultPortDrvPath[0] = (CHAR)(ulBootDrive + 'A' - 1);
|
|---|
| 315 |
|
|---|
| 316 | PrfQueryProfileString (HINI_SYSTEMPROFILE,
|
|---|
| 317 | "PM_PORT_DRIVER",
|
|---|
| 318 | "UNI",
|
|---|
| 319 | szDefaultPortDrvPath,
|
|---|
| 320 | szPathName,
|
|---|
| 321 | 256 );
|
|---|
| 322 |
|
|---|
| 323 | hModule = 0L ; /* Init module handle to null */
|
|---|
| 324 |
|
|---|
| 325 | DosLoadModule (NULL, 0, szPathName, &hModule);
|
|---|
| 326 |
|
|---|
| 327 | *flModified = OpenUniPortDlg (hab, hModule, pszPortName, chBuf);
|
|---|
| 328 |
|
|---|
| 329 | DosFreeModule (hModule);
|
|---|
| 330 | return(NO_ERROR);
|
|---|
| 331 | }
|
|---|
| 332 |
|
|---|
| 333 |
|
|---|
| 334 | APIRET APIENTRY SplPdRemovePort ( HAB hab,
|
|---|
| 335 | PSZ pszPortName )
|
|---|
| 336 | {
|
|---|
| 337 | CHAR chBuf[STR_LEN_PORTNAME];
|
|---|
| 338 | CHAR chPortDriver[STR_LEN_PORTNAME];
|
|---|
| 339 |
|
|---|
| 340 | if (!pszPortName)
|
|---|
| 341 | {
|
|---|
| 342 | return(ERROR_INVALID_PARAMETER);
|
|---|
| 343 | }
|
|---|
| 344 |
|
|---|
| 345 | strcpy (chBuf, APPNAME_LEAD_STR);
|
|---|
| 346 | strcat (chBuf, pszPortName);
|
|---|
| 347 |
|
|---|
| 348 | if (!(PrfQueryProfileString (HINI_SYSTEMPROFILE, chBuf,
|
|---|
| 349 | KEY_PORTDRIVER, NULL, chPortDriver,
|
|---|
| 350 | STR_LEN_PORTNAME)))
|
|---|
| 351 | {
|
|---|
| 352 | return(ERROR_INVALID_PARAMETER);
|
|---|
| 353 | }
|
|---|
| 354 |
|
|---|
| 355 | if (strcmp (chPortDriver, DEF_PORTDRIVER))
|
|---|
| 356 | {
|
|---|
| 357 | return(ERROR_INVALID_PARAMETER);
|
|---|
| 358 | }
|
|---|
| 359 |
|
|---|
| 360 | PrfWriteProfileString (HINI_SYSTEMPROFILE, chBuf, NULL, NULL);
|
|---|
| 361 |
|
|---|
| 362 | PrfWriteProfileString (HINI_SYSTEMPROFILE,
|
|---|
| 363 | APPNAME_PM_SPOOLER_PORT,
|
|---|
| 364 | pszPortName,
|
|---|
| 365 | NULL);
|
|---|
| 366 | return(NO_ERROR);
|
|---|
| 367 |
|
|---|
| 368 | }
|
|---|
| 369 | ULONG APIENTRY SplPdOpen( PSZ pszPortName,
|
|---|
| 370 | PHFILE phFile,
|
|---|
| 371 | PULONG pDeviceFlags,
|
|---|
| 372 | PVOID pPrtOpenStruct)
|
|---|
| 373 | {
|
|---|
| 374 | APIRET rc;
|
|---|
| 375 | ULONG ulAction = 0; /* Action taken by DosOpen */
|
|---|
| 376 | ULONG ulBytesRead = 0; /* Number of bytes read by DosRead */
|
|---|
| 377 | ULONG ulWrote = 0; /* Number of bytes written by DosWrite */
|
|---|
| 378 | ULONG ulLocal = 0; /* File pointer position after DosSetFilePtr */
|
|---|
| 379 | char szTemp[ 256];
|
|---|
| 380 | char tmp[256];
|
|---|
| 381 | ULONG pcbWritten ;
|
|---|
| 382 | USHORT i;
|
|---|
| 383 | USHORT j;
|
|---|
| 384 | USHORT pos;
|
|---|
| 385 | HFILE control;
|
|---|
| 386 | char pszPSHeader[] = "%!PS-Adobe-3.0\n";
|
|---|
| 387 | ULONG cbHeader;
|
|---|
| 388 | char filename[256];
|
|---|
| 389 | char binfile[256];
|
|---|
| 390 | char parameters[256];
|
|---|
| 391 | char workingdir[256];
|
|---|
| 392 | PUCHAR addpshdr;
|
|---|
| 393 | PUCHAR ON = "1";
|
|---|
| 394 | DATETIME dt;
|
|---|
| 395 | char spool_dir[256];
|
|---|
| 396 | PEAOP2 pEABuf = NULL;
|
|---|
| 397 |
|
|---|
| 398 |
|
|---|
| 399 | if (!phFile || !pDeviceFlags )
|
|---|
| 400 | {
|
|---|
| 401 | return(ERROR_INVALID_PARAMETER);
|
|---|
| 402 | }
|
|---|
| 403 | DosGetDateTime(&dt);
|
|---|
| 404 | rc = PrfQueryProfileString (HINI_SYSTEMPROFILE,
|
|---|
| 405 | "PM_SPOOLER",
|
|---|
| 406 | "DIR",
|
|---|
| 407 | NULL,
|
|---|
| 408 | (PSZ)spool_dir,
|
|---|
| 409 | sizeof(spool_dir));
|
|---|
| 410 | spool_dir[ strlen(spool_dir) - 1] = '\0';
|
|---|
| 411 | sprintf(tmp,"%s\\UNI",spool_dir);
|
|---|
| 412 | DosCreateDir( tmp,pEABuf );
|
|---|
| 413 | sprintf(filename,"%s\\UNI\\%02d_%02d_%02d_%02d_%s",spool_dir,dt.hours,dt.minutes,dt.seconds,dt.hundredths,pszPortName);
|
|---|
| 414 | rc = DosOpen(filename,
|
|---|
| 415 | phFile, /* File handle */
|
|---|
| 416 | &ulAction, /* Action taken */
|
|---|
| 417 | 100L, /* File primary allocation */
|
|---|
| 418 | FILE_ARCHIVED | FILE_NORMAL, /* File attribute */
|
|---|
| 419 | OPEN_ACTION_CREATE_IF_NEW |
|
|---|
| 420 | OPEN_ACTION_OPEN_IF_EXISTS, /* Open function type */
|
|---|
| 421 | OPEN_FLAGS_NOINHERIT |
|
|---|
| 422 | OPEN_SHARE_DENYNONE |
|
|---|
| 423 | OPEN_ACCESS_READWRITE, /* Open mode of the file */
|
|---|
| 424 | 0L); /* No extended attribute */
|
|---|
| 425 |
|
|---|
| 426 | sprintf(szTemp,"PM_%s",pszPortName);
|
|---|
| 427 | if (PrfQueryProfileString (HINI_SYSTEMPROFILE,
|
|---|
| 428 | szTemp,
|
|---|
| 429 | KEY_INITIALIZATION,
|
|---|
| 430 | NULL,
|
|---|
| 431 | szTemp,
|
|---|
| 432 | sizeof(szTemp)))
|
|---|
| 433 | {
|
|---|
| 434 | sprintf(tmp ,"%s\\UNI\\%d.control",spool_dir,*phFile);
|
|---|
| 435 | rc = DosOpen( tmp ,
|
|---|
| 436 | &control, /* File handle */
|
|---|
| 437 | &ulAction, /* Action taken */
|
|---|
| 438 | strlen(szTemp), /* File primary allocation */
|
|---|
| 439 | FILE_ARCHIVED | FILE_NORMAL, /* File attribute */
|
|---|
| 440 | OPEN_ACTION_CREATE_IF_NEW |
|
|---|
| 441 | OPEN_ACTION_OPEN_IF_EXISTS, /* Open function type */
|
|---|
| 442 | OPEN_FLAGS_NOINHERIT |
|
|---|
| 443 | OPEN_SHARE_DENYNONE |
|
|---|
| 444 | OPEN_ACCESS_READWRITE, /* Open mode of the file */
|
|---|
| 445 | 0L); /* No extended attribute */
|
|---|
| 446 |
|
|---|
| 447 | rc = DosWrite( control,szTemp,strlen(szTemp),&pcbWritten);
|
|---|
| 448 | rc = DosWrite( control,"#",1,&pcbWritten);
|
|---|
| 449 | rc = DosWrite( control,filename,strlen(filename),&pcbWritten);
|
|---|
| 450 | rc = DosWrite( control,"@",1,&pcbWritten);
|
|---|
| 451 | rc = DosClose(control);
|
|---|
| 452 |
|
|---|
| 453 | i = 0;
|
|---|
| 454 | j = 0;
|
|---|
| 455 | pos = 0;
|
|---|
| 456 | while (szTemp[i] != '@')
|
|---|
| 457 | {
|
|---|
| 458 | if (szTemp[i] == '#')
|
|---|
| 459 | {
|
|---|
| 460 | szTemp[i] = '\0';
|
|---|
| 461 | switch(j)
|
|---|
| 462 | {
|
|---|
| 463 | case 0:strcpy(binfile,&szTemp[pos]);
|
|---|
| 464 | break;
|
|---|
| 465 | case 1:strcpy(parameters,&szTemp[pos]);
|
|---|
| 466 | break;
|
|---|
| 467 | case 2:strcpy(workingdir,&szTemp[pos]);
|
|---|
| 468 | break;
|
|---|
| 469 | case 3:strcpy(addpshdr,&szTemp[pos]);
|
|---|
| 470 | break;
|
|---|
| 471 | /* case 4:strcpy(j_copies,&szTemp[pos]);
|
|---|
| 472 | break;
|
|---|
| 473 | case 5:strcpy(password_enc,&szTemp[pos]);
|
|---|
| 474 | break; */
|
|---|
| 475 | }
|
|---|
| 476 | pos = i+1;
|
|---|
| 477 | j++;
|
|---|
| 478 | }
|
|---|
| 479 | i++;
|
|---|
| 480 | }
|
|---|
| 481 |
|
|---|
| 482 | if (strncmp(addpshdr, ON ,1) == 0) {
|
|---|
| 483 | DosWrite(*phFile,pszPSHeader,strlen(pszPSHeader),&cbHeader);
|
|---|
| 484 | }
|
|---|
| 485 | }
|
|---|
| 486 | return rc;
|
|---|
| 487 |
|
|---|
| 488 | }
|
|---|
| 489 | ULONG APIENTRY SplPdQuery ( PSZ pszDeviceName,
|
|---|
| 490 | ULONG ulFlags,
|
|---|
| 491 | ULONG ulCommand,
|
|---|
| 492 | PVOID pInData,
|
|---|
| 493 | ULONG cbInData,
|
|---|
| 494 | PVOID pOutData,
|
|---|
| 495 | PULONG pcbOutData )
|
|---|
| 496 | {
|
|---|
| 497 | /* return ERROR_NOT_SUPPORTED; */
|
|---|
| 498 | return NO_ERROR;
|
|---|
| 499 | }
|
|---|
| 500 | ULONG APIENTRY SplPdSet ( PSZ pszDeviceName,
|
|---|
| 501 | ULONG ulFlags,
|
|---|
| 502 | ULONG ulCommand,
|
|---|
| 503 | PVOID pInData,
|
|---|
| 504 | ULONG cbInData )
|
|---|
| 505 | {
|
|---|
| 506 | /* return ERROR_NOT_SUPPORTED; */
|
|---|
| 507 | return NO_ERROR;
|
|---|
| 508 | }
|
|---|
| 509 | ULONG APIENTRY SplPdNewPage ( HFILE hFile, ULONG ulPageNumber )
|
|---|
| 510 | {
|
|---|
| 511 | return NO_ERROR;
|
|---|
| 512 | }
|
|---|
| 513 | ULONG APIENTRY SplPdAbortDoc( HFILE hFile,
|
|---|
| 514 | PVOID pchData,
|
|---|
| 515 | ULONG cbData,
|
|---|
| 516 | ULONG ulFlags )
|
|---|
| 517 | {
|
|---|
| 518 | return NO_ERROR;
|
|---|
| 519 | }
|
|---|
| 520 | ULONG APIENTRY SplPdClose( HFILE hFile )
|
|---|
| 521 | {
|
|---|
| 522 | APIRET rc;
|
|---|
| 523 | APIRET resp;
|
|---|
| 524 | USHORT i;
|
|---|
| 525 | USHORT j;
|
|---|
| 526 | RESULTCODES rc_child;
|
|---|
| 527 | ULONG nbr_lu;
|
|---|
| 528 | ULONG ulAction;
|
|---|
| 529 | char szTemp[256];
|
|---|
| 530 | HFILE control;
|
|---|
| 531 | char binfile[256];
|
|---|
| 532 | char arg[256];
|
|---|
| 533 | char *j_parms;
|
|---|
| 534 | int allocSize = 0;
|
|---|
| 535 | char j_id[3];
|
|---|
| 536 | char parameters[256];
|
|---|
| 537 | char workingdir[256] ;
|
|---|
| 538 | char addpshdr[1] ;
|
|---|
| 539 | char j_title[256];
|
|---|
| 540 | char j_copies[3];
|
|---|
| 541 | char j_options[8];
|
|---|
| 542 | char filename[256];
|
|---|
| 543 | char ip_add[256];
|
|---|
| 544 | char queue_name[256];
|
|---|
| 545 | char workgroup[256];
|
|---|
| 546 | char username[256];
|
|---|
| 547 | char password_enc[256];
|
|---|
| 548 | char password_dec[256];
|
|---|
| 549 | char errorstr[256];
|
|---|
| 550 | USHORT pos;
|
|---|
| 551 | char spool_dir[256];
|
|---|
| 552 | ULONG ulBootDrive;
|
|---|
| 553 | char *p_arg[10];
|
|---|
| 554 |
|
|---|
| 555 | rc = PrfQueryProfileString (HINI_SYSTEMPROFILE,
|
|---|
| 556 | "PM_SPOOLER",
|
|---|
| 557 | "DIR",
|
|---|
| 558 | NULL,
|
|---|
| 559 | (PSZ)spool_dir,
|
|---|
| 560 | sizeof(spool_dir));
|
|---|
| 561 | spool_dir[ strlen(spool_dir) - 1] = '\0';
|
|---|
| 562 | sprintf(szTemp,"%s\\UNI\\%d.control",spool_dir,hFile);
|
|---|
| 563 | rc = DosOpen(szTemp,
|
|---|
| 564 | &control,
|
|---|
| 565 | &ulAction,
|
|---|
| 566 | 0L,
|
|---|
| 567 | FILE_ARCHIVED | FILE_NORMAL,
|
|---|
| 568 | OPEN_ACTION_CREATE_IF_NEW |
|
|---|
| 569 | OPEN_ACTION_OPEN_IF_EXISTS,
|
|---|
| 570 | OPEN_FLAGS_NOINHERIT |
|
|---|
| 571 | OPEN_SHARE_DENYNONE |
|
|---|
| 572 | OPEN_ACCESS_READWRITE,
|
|---|
| 573 | 0L);
|
|---|
| 574 | rc = DosRead( control,szTemp,sizeof(szTemp),&nbr_lu);
|
|---|
| 575 | rc = DosClose( control );
|
|---|
| 576 | sprintf(filename,"%s\\UNI\\%d.control",spool_dir,hFile);
|
|---|
| 577 | DosDelete(filename);
|
|---|
| 578 |
|
|---|
| 579 | i = 0;
|
|---|
| 580 | j = 0;
|
|---|
| 581 | pos = 0;
|
|---|
| 582 | while (szTemp[i] != '@')
|
|---|
| 583 | {
|
|---|
| 584 | if (szTemp[i] == '#')
|
|---|
| 585 | {
|
|---|
| 586 | szTemp[i] = '\0';
|
|---|
| 587 | switch(j)
|
|---|
| 588 | {
|
|---|
| 589 | case 0:strcpy(binfile,&szTemp[pos]);
|
|---|
| 590 | break;
|
|---|
| 591 | case 1:strcpy(parameters,&szTemp[pos]);
|
|---|
| 592 | break;
|
|---|
| 593 | case 2:strcpy(workingdir,&szTemp[pos]);
|
|---|
| 594 | break;
|
|---|
| 595 | /* case 3:strcpy(username,&szTemp[pos]);
|
|---|
| 596 | break;
|
|---|
| 597 | case 4:strcpy(j_copies,&szTemp[pos]);
|
|---|
| 598 | break;
|
|---|
| 599 | case 5:strcpy(password_enc,&szTemp[pos]);
|
|---|
| 600 | break; */
|
|---|
| 601 | }
|
|---|
| 602 | pos = i+1;
|
|---|
| 603 | j++;
|
|---|
| 604 | }
|
|---|
| 605 | i++;
|
|---|
| 606 | }
|
|---|
| 607 | szTemp[i] = '\0';
|
|---|
| 608 | strcpy(filename,&szTemp[pos]);
|
|---|
| 609 |
|
|---|
| 610 | rc = DosClose( hFile );
|
|---|
| 611 | DosQuerySysInfo (QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, &ulBootDrive,
|
|---|
| 612 | sizeof (ULONG));
|
|---|
| 613 |
|
|---|
| 614 | // decryptPassword(password_enc,password_dec);
|
|---|
| 615 |
|
|---|
| 616 | // allocate needed space for the returning string +1 (for string terminator)
|
|---|
| 617 | allocSize = strlen(parameters) - strlen("%file%") + strlen(filename);
|
|---|
| 618 |
|
|---|
| 619 | j_parms = malloc((allocSize +1) * sizeof(char));
|
|---|
| 620 |
|
|---|
| 621 | // searchReplace(search, replace, string, replaced, allocSize);
|
|---|
| 622 | searchReplace("%file%", filename, parameters, j_parms, allocSize);
|
|---|
| 623 |
|
|---|
| 624 | // split into single paramters
|
|---|
| 625 | p_arg[0] = binfile;
|
|---|
| 626 | for (i=1; i < 10; i++) {
|
|---|
| 627 | if ( i == 1) {
|
|---|
| 628 | p_arg[i] = strtok(j_parms, " ");
|
|---|
| 629 | } else {
|
|---|
| 630 | p_arg[i] = strtok(NULL, " ");
|
|---|
| 631 | }
|
|---|
| 632 | };
|
|---|
| 633 | p_arg[10] = NULL;
|
|---|
| 634 |
|
|---|
| 635 | if (strlen(workingdir) > 0)
|
|---|
| 636 | {
|
|---|
| 637 | chdir(workingdir);
|
|---|
| 638 | };
|
|---|
| 639 |
|
|---|
| 640 | rc = spawnvp(P_WAIT,p_arg[0],p_arg);
|
|---|
| 641 |
|
|---|
| 642 | while (rc != 0)
|
|---|
| 643 | {
|
|---|
| 644 | sprintf(errorstr,"Error during spooling to %s %s ",binfile,j_parms,NULL);
|
|---|
| 645 |
|
|---|
| 646 | resp = WinMessageBox (HWND_DESKTOP,
|
|---|
| 647 | HWND_DESKTOP,
|
|---|
| 648 | errorstr,
|
|---|
| 649 | "Universal Port driver error",
|
|---|
| 650 | 0L, MB_RETRYCANCEL | MB_WARNING | MB_MOVEABLE);
|
|---|
| 651 | if (resp != MBID_CANCEL )
|
|---|
| 652 | {
|
|---|
| 653 | rc = spawnvp(P_WAIT,p_arg[0],p_arg);
|
|---|
| 654 | }
|
|---|
| 655 | else rc = 0;
|
|---|
| 656 | };
|
|---|
| 657 |
|
|---|
| 658 | free(j_parms);
|
|---|
| 659 |
|
|---|
| 660 | strcpy(filename,&szTemp[pos]);
|
|---|
| 661 | DosDelete(filename);
|
|---|
| 662 |
|
|---|
| 663 | /* We always have to return success to the spooler subsystem */
|
|---|
| 664 | rc = NO_ERROR;
|
|---|
| 665 | return rc;
|
|---|
| 666 | }
|
|---|
| 667 | ULONG APIENTRY SplPdWrite( HFILE hFile,
|
|---|
| 668 | PVOID pchData,
|
|---|
| 669 | ULONG cbData,
|
|---|
| 670 | PULONG pcbWritten )
|
|---|
| 671 | { APIRET rc;
|
|---|
| 672 |
|
|---|
| 673 | rc = DosWrite( hFile,pchData,cbData,pcbWritten);
|
|---|
| 674 | rc = DosSleep(0);
|
|---|
| 675 | return rc;
|
|---|
| 676 | }
|
|---|