Changeset 177 for branches/smbpdr-1.0/smb.c
- Timestamp:
- Apr 18, 2009, 12:09:06 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/smbpdr-1.0/smb.c
r175 r177 66 66 if ('0' <= c && c <= '9') 67 67 { 68 68 return c - '0'; 69 69 } 70 70 71 71 if ('A' <= c && c <= 'F') 72 72 { 73 73 return c - 'A' + 0xA; 74 74 } 75 75 76 76 if ('a' <= c && c <= 'f') 77 77 { 78 78 return c - 'a' + 0xA; 79 79 } 80 80 … … 143 143 } PORTNAMES, *PPORTNAMES; 144 144 145 /* Alex Taylor's new version of lprtok() that can handle missing fields */ 145 146 char * lprtok (char *string,char *control) 146 147 { 147 unsigned char *str; 148 const unsigned char *ctrl = control; 149 150 unsigned char map[32]; 151 int count; 152 153 static char *nextoken; 154 155 for (count = 0; count < 32; count++) 156 map[count] = 0; 157 158 do { 159 map[*ctrl >> 3] |= (1 << (*ctrl & 7)); 160 } while (*ctrl++); 161 162 if (string) 163 str = string; 164 else 165 str = nextoken; 166 167 while ( (map[*str >> 3] & (1 << (*str & 7))) && *str ) 168 str++; 169 170 string = str; 171 172 for ( ; *str ; str++ ) 173 if ( map[*str >> 3] & (1 << (*str & 7)) ) { 174 *str++ = '\0'; 175 break; 176 } 177 178 nextoken = str; 179 180 /* Determine if a token has been found. */ 181 if ( string == str ) 182 return NULL; 183 else 184 return string; 148 char *c; 149 static char *next; 150 151 if ( control == NULL ) return string; 152 if ( string == NULL ) string = next; 153 if ( string == NULL ) return NULL; 154 155 if (( c = strpbrk( string, control )) == NULL ) { 156 next = NULL; 157 } 158 else { 159 next = c+1; 160 *c = '\0'; 161 } 162 163 return ( string ); 185 164 } 186 165 MRESULT EXPENTRY CommDlg( HWND hDlg, USHORT msg, MPARAM mp1, MPARAM mp2 ) … … 188 167 PLPRDATA pLprData; 189 168 ULONG ulTimeOut = 0 ; 190 CHAR szDesc[ STR_LEN_PORTDESC]; 169 CHAR szDesc[ STR_LEN_PORTDESC ]; 170 CHAR szShareName[ STR_LEN_PORTDESC ]; 191 171 CHAR szTitle[ STR_LEN_TITLE + 1]; 192 172 CHAR szTemp[ STR_LEN_PORTDESC ]; … … 276 256 { 277 257 case DID_OK: 258 sprintf(szDesc,"\\"); 278 259 /* Servername | IP */ 279 260 WinQueryDlgItemText (hDlg, ID_IP, sizeof(szTemp), szTemp ); 280 261 sprintf(pLprData->szSaveLprSetting,"%s",szTemp); 262 strncpy(szShareName, szTemp, STR_LEN_PORTDESC - 1); 281 263 /* Printername | Queue */ 282 264 WinQueryDlgItemText (hDlg, ID_SMBQUEUE, sizeof(szTemp), szTemp ); 283 265 strcat(pLprData->szSaveLprSetting,"#"); 284 266 strcat(pLprData->szSaveLprSetting,szTemp); 267 if (strlen(szTemp) > 0) { 268 strncat(szShareName, "\\", STR_LEN_PORTDESC - 1); 269 strncat(szShareName, szTemp, STR_LEN_PORTDESC - 1); 270 } 285 271 /* Workgroup */ 286 272 WinQueryDlgItemText (hDlg, ID_WORKGROUP, sizeof(szTemp), szTemp ); 287 273 strcat(pLprData->szSaveLprSetting,"#"); 288 274 strcat(pLprData->szSaveLprSetting,szTemp); 275 if (strlen(szTemp) > 0) { 276 strncat(szDesc, "\\", STR_LEN_PORTDESC - 1); 277 strncat(szDesc, szTemp, STR_LEN_PORTDESC - 1); 278 } 279 strncat(szDesc, "\\", STR_LEN_PORTDESC - 1); 280 strncat(szDesc, szShareName, STR_LEN_PORTDESC - 1); 289 281 /* Username */ 290 282 WinQueryDlgItemText (hDlg, ID_USER, sizeof(szTemp), szTemp ); … … 301 293 encryptPassword(pwBuffer,szTemp); 302 294 strcat(pLprData->szSaveLprSetting,szTemp); 303 295 304 296 if (!PrfWriteProfileString (HINI_SYSTEMPROFILE, 305 297 pLprData->pszAppName, … … 312 304 pLprData->pszPortName, 313 305 pLprData->szSaveLprSetting)) 314 WinDismissDlg(hDlg, MBID_CANCEL); 306 WinDismissDlg(hDlg, MBID_CANCEL); 307 308 if (!PrfWriteProfileString (HINI_SYSTEMPROFILE, 309 pLprData->pszAppName, 310 KEY_DESCRIPTION, 311 szDesc )) 312 WinDismissDlg(hDlg, MBID_CANCEL); 313 315 314 WinDismissDlg(hDlg, TRUE); 316 315 break; … … 321 320 break; 322 321 default: 323 324 325 326 322 return WinDefDlgProc(hDlg, msg, mp1, mp2) ; 323 break; 324 } 325 return FALSE; 327 326 } 328 327 ULONG CalcStructLength ( HAB hab, 329 330 331 { 332 333 334 335 336 337 338 339 340 341 342 328 HMODULE hModule, 329 USHORT usID ) 330 { 331 ULONG cbRequired; 332 CHAR chString[STR_LEN_PORTDESC]; 333 334 cbRequired = 0; 335 336 WinLoadString(hab, hModule, usID, STR_LEN_PORTDESC, chString); 337 cbRequired += strlen (chString) + 1; 338 WinLoadString(hab, hModule, (USHORT)(usID + 1), STR_LEN_PORTDESC, chString); 339 cbRequired += strlen (chString) + 1; 340 cbRequired += sizeof (PORTNAMES); 341 return(cbRequired); 343 342 } 344 343 … … 346 345 HMODULE hModule ) 347 346 { 348 349 350 351 347 ULONG cbRequired; 348 USHORT usID; 349 350 cbRequired = 0; 352 351 353 352 /* 354 353 ** calculate length required to fit all the port info. 355 354 */ 356 357 355 for (usID = PORT_ID_FIRST; usID <= PORT_ID_LAST; usID += 2) 356 { 358 357 cbRequired += CalcStructLength (hab, hModule, usID); 359 360 361 358 } 359 360 return(cbRequired); 362 361 } 363 362 … … 366 365 ULONG cbBuf ) 367 366 { 368 369 370 371 372 373 367 ULONG cbRequired; 368 USHORT usID; 369 ULONG ulNumPort; 370 371 cbRequired = 0; 372 ulNumPort = 0; 374 373 375 374 /* 376 375 ** calculate how many ports we can fit in buf. 377 376 */ 378 379 377 for (usID = PORT_ID_FIRST; usID <= PORT_ID_LAST; usID += 2) 378 { 380 379 cbRequired += CalcStructLength (hab, hModule, usID); 381 380 if (cbRequired > cbBuf) 382 381 { 383 382 return(ulNumPort); 384 383 } 385 384 ulNumPort++; 386 387 388 385 } 386 387 return(ulNumPort); 389 388 } 390 389 VOID CopyStruct ( HAB hab, 391 392 393 394 395 396 { 397 398 399 400 390 HMODULE hModule, 391 USHORT usID, 392 PCH pBuf, 393 PULONG pulBeginStruct, 394 PULONG pulBeginText ) 395 { 396 PPORTNAMES pPortNames; 397 398 pPortNames = (PPORTNAMES)(pBuf + *pulBeginStruct); 399 *pulBeginStruct += sizeof (PORTNAMES); 401 400 402 401 /* 403 402 ** copy port name in the structure 404 403 */ 405 406 407 404 pPortNames->pszPortName = pBuf + *pulBeginText; 405 WinLoadString(hab, hModule, usID, STR_LEN_PORTDESC, pPortNames->pszPortName); 406 *pulBeginText += strlen (pPortNames->pszPortName) + 1; 408 407 409 408 /* 410 409 ** copy port description to the structure 411 410 */ 412 413 414 411 pPortNames->pszPortDesc = pBuf + *pulBeginText; 412 WinLoadString(hab, hModule, usID, STR_LEN_PORTDESC, pPortNames->pszPortDesc); 413 *pulBeginText += strlen (pPortNames->pszPortDesc) + 1; 415 414 } 416 415 VOID CopyNPorts ( HAB hab, 417 418 419 420 { 421 422 423 424 425 426 427 428 416 HMODULE hModule, 417 PCH pBuf, 418 ULONG ulReturned ) 419 { 420 USHORT usID; 421 ULONG ulBeginText; 422 ULONG ulBeginStruct; 423 424 ulBeginText = ulReturned * sizeof (PORTNAMES); 425 ulBeginStruct = 0; 426 427 for (usID = PORT_ID_FIRST; 429 428 usID <= PORT_ID_LAST && ulReturned; 430 429 usID += 2, --ulReturned) 431 430 { 432 431 CopyStruct (hab, hModule, usID, pBuf, &ulBeginStruct, &ulBeginText); 433 432 } 434 433 } 435 434 … … 439 438 PSZ pszAppName ) 440 439 { 441 442 443 444 445 446 447 448 449 440 LPRDATA LprData; 441 442 memset (&LprData, 0, sizeof (LPRDATA)); 443 LprData.hAB = hab; 444 LprData.hModule = hModule; 445 LprData.pszPortName = pszPortName; 446 LprData.pszAppName = pszAppName; 447 448 WinDlgBox (HWND_DESKTOP, 450 449 HWND_DESKTOP, 451 450 (PFNWP)CommDlg, … … 454 453 &LprData); 455 454 456 455 return LprData.lfModified; 457 456 } 458 457 BOOL GetPortDescription ( HAB hab, 459 460 461 458 HMODULE hModule, 459 PSZ pszPortName, 460 PSZ pszPortDesc ) 462 461 { 463 462 USHORT usID; 464 CHAR chBuf[STR_LEN_PORTDESC];463 CHAR chBuf[STR_LEN_PORTDESC] = {0}; 465 464 466 465 for (usID = PORT_ID_FIRST; usID <= PORT_ID_LAST; usID += 2) 467 466 { 468 WinLoadString(hab, hModule, usID, STR_LEN_PORT DESC, chBuf);467 WinLoadString(hab, hModule, usID, STR_LEN_PORTNAME, chBuf); 469 468 if (!strcmp (pszPortName, chBuf)) 470 469 { 470 if ( WinLoadString(hab, hModule, usID+1, STR_LEN_PORTDESC, chBuf) ) { 471 471 strcpy (pszPortDesc, chBuf); 472 472 return(TRUE); 473 473 } 474 break; 475 } 474 476 } 475 477 return(FALSE); 478 } 479 BOOL GenerateUniquePortName( PSZ pszPortName ) 480 { 481 BOOL fPortExists; 482 PSZ pszEndPortName; 483 USHORT i; 484 CHAR chPortData[STR_LEN_PORTNAME]; 485 486 /* 487 ** Generate a unique port name by adding numbers to the 488 ** end of pszPortName 489 */ 490 pszEndPortName = pszPortName + strlen( pszPortName ); 491 i = 1; 492 fPortExists = TRUE; 493 while ( (i < MAX_PORTS) && fPortExists ) 494 { 495 _itoa( i, pszEndPortName, 4); 496 fPortExists = PrfQueryProfileString (HINI_SYSTEMPROFILE, 497 APPNAME_PM_SPOOLER_PORT, 498 pszPortName, 499 NULL, 500 chPortData, 501 sizeof(chPortData) - 1); 502 i++; 503 } 504 return(!fPortExists); 476 505 } 477 506 APIRET APIENTRY SplPdEnumPort ( HAB hab, … … 484 513 { 485 514 HMODULE hModule; 486 ULONG 487 ULONG 488 CHAR 515 ULONG ulBootDrive; 516 ULONG rcLoadMod; 517 CHAR szPathName[260]; 489 518 490 519 if (!pulReturned || … … 501 530 502 531 DosQuerySysInfo (QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, &ulBootDrive, 503 532 sizeof (ULONG)); 504 533 szDefaultPortDrvPath[0] = (CHAR)(ulBootDrive + 'A' - 1); 505 534 506 535 PrfQueryProfileString (HINI_SYSTEMPROFILE, 507 508 509 510 511 536 "PM_PORT_DRIVER", 537 "SMB", 538 szDefaultPortDrvPath, 539 szPathName, 540 256 ); 512 541 513 542 rcLoadMod = DosLoadModule (NULL, 0, szPathName, &hModule); … … 517 546 *pulReturned = 0; 518 547 *pcbRequired = CalcBufLength (hab, hModule); 519 *pulTotal = 64; /* Currently support LPRx x = 1 .. 9 */548 *pulTotal = MAX_PORTS; 520 549 if (!rcLoadMod) 521 550 DosFreeModule (hModule); … … 526 555 ** check number of ports info we can fit in supplied buffer 527 556 */ 528 *pulTotal = 64; /* Currently support LPRx x= 1 .. 9 */557 *pulTotal = MAX_PORTS; 529 558 *pcbRequired = CalcBufLength (hab, hModule); 530 559 *pulReturned = NumPortsCanFit (hab, hModule, cbBuf); … … 536 565 { 537 566 if (!rcLoadMod) 538 567 DosFreeModule (hModule); 539 568 return(ERROR_INSUFFICIENT_BUFFER); 540 569 } … … 549 578 */ 550 579 if (!rcLoadMod) 551 580 DosFreeModule (hModule); 552 581 553 582 /* … … 562 591 } 563 592 APIRET APIENTRY SplPdInstallPort ( HAB hab, 564 PSZ pszPortName ) 565 { 566 CHAR chBuf[STR_LEN_PORTNAME]; 567 CHAR chPortDesc[STR_LEN_PORTDESC]; 568 ULONG ulBootDrive; 569 HMODULE hModule; 570 CHAR szPathName[260]; /* will contain full path to this port driver */ 571 572 if (!pszPortName) 573 { 574 return(ERROR_INVALID_PARAMETER); 575 } 576 strcpy(szDefaultPortDrvPath,PATH_SMB_PDR); 577 DosQuerySysInfo (QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, &ulBootDrive, 578 sizeof (ULONG)); 579 szDefaultPortDrvPath[0] = (CHAR)(ulBootDrive + 'A' - 1); 580 581 PrfWriteProfileString (HINI_SYSTEMPROFILE, 582 "PM_PORT_DRIVER", 583 "SMB", 584 szDefaultPortDrvPath); 585 hModule = 0L ; /* Init module handle to null */ 586 DosLoadModule (NULL, 0, szPathName, &hModule); 587 if (!GetPortDescription (hab, hModule, pszPortName, chPortDesc)) 588 { 593 PSZ pszPortName ) 594 { 595 CHAR chBuf[STR_LEN_PORTNAME]; 596 CHAR chPortDesc[STR_LEN_PORTDESC]; 597 ULONG ulBootDrive; 598 HMODULE hModule; 599 CHAR szPathName[260]; /* will contain full path to this port driver */ 600 601 if (!pszPortName) 602 { 603 return(ERROR_INVALID_PARAMETER); 604 } 605 strcpy(szDefaultPortDrvPath,PATH_SMB_PDR); 606 DosQuerySysInfo (QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, &ulBootDrive, 607 sizeof (ULONG)); 608 szDefaultPortDrvPath[0] = (CHAR)(ulBootDrive + 'A' - 1); 609 strcpy( szPathName, szDefaultPortDrvPath ); 610 611 /* Make sure the port driver itself is installed */ 612 PrfWriteProfileString (HINI_SYSTEMPROFILE, 613 "PM_PORT_DRIVER", 614 "SMB", 615 szDefaultPortDrvPath); 616 617 /* Generate appname for "PM_SMBx" */ 618 strcpy (chBuf, APPNAME_LEAD_STR); 619 strcat (chBuf, pszPortName); 620 621 /* 622 ** Check for this being our default Port Name to install. 623 ** If so (pszPortName == "SMB") then generate a unique 624 ** port name so that we can install multiple SMB printers. 625 */ 626 if (!strcmp(pszPortName, DEF_PORTNAME)) 627 { 628 /* 629 ** Use chBuf to store the new portname to install 630 ** Must first increment past "PM_" in chBuf 631 */ 632 pszPortName = chBuf + 3; 633 GenerateUniquePortName( pszPortName ); 634 } 635 636 /* Get initial port description (fall back to portname if unavailable) */ 637 hModule = 0L ; /* Init module handle to null */ 638 DosLoadModule (NULL, 0, szPathName, &hModule); 639 if (!GetPortDescription (hab, hModule, pszPortName, chPortDesc)) 640 { 589 641 strcpy( chPortDesc, pszPortName ); 590 } 591 DosFreeModule (hModule); 592 strcpy (chBuf, APPNAME_LEAD_STR); 593 strcat (chBuf, pszPortName); 594 if (!PrfWriteProfileString (HINI_SYSTEMPROFILE, 642 } 643 DosFreeModule (hModule); 644 645 if (!PrfWriteProfileString (HINI_SYSTEMPROFILE, 595 646 chBuf, 596 647 KEY_DESCRIPTION, 597 648 chPortDesc)) 598 649 { 599 650 return (WinGetLastError (hab)); 600 601 602 651 } 652 653 if (!PrfWriteProfileString (HINI_SYSTEMPROFILE, 603 654 chBuf, 604 655 KEY_INITIALIZATION, 605 656 DEF_INITIALIZATION)) 606 657 { 607 658 return (WinGetLastError (hab)); 608 609 610 659 } 660 661 if (!PrfWriteProfileString (HINI_SYSTEMPROFILE, 611 662 chBuf, 612 663 KEY_TERMINATION, 613 664 DEF_TERMINATION)) 614 665 { 615 666 return (WinGetLastError (hab)); 616 617 618 667 } 668 669 if (!PrfWriteProfileString (HINI_SYSTEMPROFILE, 619 670 chBuf, 620 671 KEY_PORTDRIVER, 621 672 DEF_PORTDRIVER)) 622 673 { 623 674 return (WinGetLastError (hab)); 624 625 626 675 } 676 677 if (!PrfWriteProfileString (HINI_SYSTEMPROFILE, 627 678 chBuf, 628 679 KEY_TIMEOUT, 629 680 DEF_TIMEOUT)) 630 681 { 631 682 return (WinGetLastError (hab)); 632 633 683 } 684 if (!PrfWriteProfileString (HINI_SYSTEMPROFILE, 634 685 APPNAME_PM_SPOOLER_PORT, 635 686 pszPortName, 636 687 DEF_INITIALIZATION)) 637 688 { 638 689 return (WinGetLastError (hab)); 639 640 690 } 691 return(NO_ERROR); 641 692 } 642 693 BOOL APIENTRY SplPdGetPortIcon ( HAB hab, 643 644 { 645 646 694 PULONG idIcon ) 695 { 696 if (idIcon) 697 { 647 698 *idIcon = SMB_ICON; 648 649 699 } 700 return(TRUE); 650 701 } 651 702 APIRET APIENTRY SplPdQueryPort ( HAB hab, 652 653 654 655 656 { 657 658 659 660 661 662 663 664 665 666 667 668 return(ERROR_INVALID_PARAMETER); 669 670 671 672 673 return(ERROR_INVALID_PARAMETER); 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 703 PSZ pszPortName, 704 PVOID pBufIn, 705 ULONG cbBuf, 706 PULONG cItems ) 707 { 708 HMODULE hModule; 709 CHAR chString[STR_LEN_DESC]; 710 USHORT usNumLines; 711 USHORT usLineID; 712 USHORT usStrLength; 713 ULONG ulBootDrive; 714 PCH pBuf = pBufIn; 715 CHAR szPathName[260]; /* will contain full path to this port driver */ 716 717 if (!cItems) 718 { 719 return(ERROR_INVALID_PARAMETER); 720 } 721 722 if (!pBuf || !cbBuf) 723 { 724 return(ERROR_INVALID_PARAMETER); 725 } 726 727 728 DosQuerySysInfo (QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, &ulBootDrive, 729 sizeof (ULONG)); 730 szDefaultPortDrvPath[0] = (CHAR)(ulBootDrive + 'A' - 1); 731 732 PrfQueryProfileString (HINI_SYSTEMPROFILE, 733 "PM_PORT_DRIVER", 734 "SMB", 735 szDefaultPortDrvPath, 736 szPathName, 737 256 ); 738 739 hModule = 0L ; 740 741 DosLoadModule (NULL, 0, szPathName, &hModule); 742 743 chString[0] = '\0' ; 744 745 WinLoadString(hab, hModule, (USHORT)ID_NUMBER_OF_DESC_LINES, STR_LEN_DESC, 746 chString); 747 usNumLines = (USHORT)atoi (chString); 748 usLineID = ID_FIRST_DESC_LINES; 749 for (*cItems = 0; *cItems < usNumLines; *cItems++) 750 { 700 751 WinLoadString(hab, hModule, usLineID, STR_LEN_DESC, chString); 701 752 if (cbBuf >= (usStrLength = (USHORT)(strlen (chString) + 1))) 702 753 { 703 704 705 754 strcpy (pBuf, chString); 755 pBuf += usStrLength; 756 cbBuf -= usStrLength; 706 757 } 707 758 else 708 759 { 709 710 760 DosFreeModule (hModule); 761 return(ERROR_INSUFFICIENT_BUFFER); 711 762 } 712 713 714 763 } 764 DosFreeModule (hModule); 765 return(NO_ERROR); 715 766 } 716 767 APIRET APIENTRY SplPdSetPort ( HAB hab, … … 718 769 PULONG flModified ) 719 770 { 720 721 722 723 724 725 726 727 728 return(ERROR_INVALID_PARAMETER); 729 730 731 732 733 734 771 CHAR chBuf[STR_LEN_PORTNAME]; 772 CHAR chPortDriver[STR_LEN_PORTNAME]; 773 ULONG ulBootDrive; 774 HMODULE hModule; 775 CHAR szPathName[260]; /* will contain full path to this port driver */ 776 777 if (!pszPortName || !flModified) 778 { 779 return(ERROR_INVALID_PARAMETER); 780 } 781 782 strcpy (chBuf, APPNAME_LEAD_STR); 783 strcat (chBuf, pszPortName); 784 785 if (!(PrfQueryProfileString (HINI_SYSTEMPROFILE, chBuf, 735 786 KEY_PORTDRIVER, NULL, chPortDriver, 736 787 STR_LEN_PORTNAME))) 737 738 return(ERROR_INVALID_PARAMETER); 739 740 741 742 743 return(ERROR_INVALID_PARAMETER); 744 745 746 747 748 749 750 751 752 753 754 755 756 757 hModule = 0L ;/* Init module handle to null */758 759 760 761 762 763 764 788 { 789 return(ERROR_INVALID_PARAMETER); 790 } 791 792 if (strcmp (chPortDriver, DEF_PORTDRIVER)) 793 { 794 return(ERROR_INVALID_PARAMETER); 795 } 796 797 DosQuerySysInfo (QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, &ulBootDrive, 798 sizeof (ULONG)); 799 szDefaultPortDrvPath[0] = (CHAR)(ulBootDrive + 'A' - 1); 800 801 PrfQueryProfileString (HINI_SYSTEMPROFILE, 802 "PM_PORT_DRIVER", 803 "SMB", 804 szDefaultPortDrvPath, 805 szPathName, 806 256 ); 807 808 hModule = 0L ; /* Init module handle to null */ 809 810 DosLoadModule (NULL, 0, szPathName, &hModule); 811 812 *flModified = OpenLprPortDlg (hab, hModule, pszPortName, chBuf); 813 814 DosFreeModule (hModule); 815 return(NO_ERROR); 765 816 } 766 817 767 818 768 819 APIRET APIENTRY SplPdRemovePort ( HAB hab, 769 770 { 771 772 773 774 775 776 return(ERROR_INVALID_PARAMETER); 777 778 779 780 781 782 820 PSZ pszPortName ) 821 { 822 CHAR chBuf[STR_LEN_PORTNAME]; 823 CHAR chPortDriver[STR_LEN_PORTNAME]; 824 825 if (!pszPortName) 826 { 827 return(ERROR_INVALID_PARAMETER); 828 } 829 830 strcpy (chBuf, APPNAME_LEAD_STR); 831 strcat (chBuf, pszPortName); 832 833 if (!(PrfQueryProfileString (HINI_SYSTEMPROFILE, chBuf, 783 834 KEY_PORTDRIVER, NULL, chPortDriver, 784 835 STR_LEN_PORTNAME))) 785 786 return(ERROR_INVALID_PARAMETER); 787 788 789 790 791 return(ERROR_INVALID_PARAMETER); 792 793 794 795 796 797 798 799 800 836 { 837 return(ERROR_INVALID_PARAMETER); 838 } 839 840 if (strcmp (chPortDriver, DEF_PORTDRIVER)) 841 { 842 return(ERROR_INVALID_PARAMETER); 843 } 844 845 PrfWriteProfileString (HINI_SYSTEMPROFILE, chBuf, NULL, NULL); 846 847 PrfWriteProfileString (HINI_SYSTEMPROFILE, 848 APPNAME_PM_SPOOLER_PORT, 849 pszPortName, 850 NULL); 851 return(NO_ERROR); 801 852 802 853 } 803 854 ULONG APIENTRY SplPdOpen( PSZ pszPortName, 804 805 806 807 { 808 809 810 811 ULONG ulWrote= 0; /* Number of bytes written by DosWrite */812 ULONG ulLocal= 0; /* File pointer position after DosSetFilePtr */813 814 815 816 817 818 819 820 821 822 UCHARpszPSHeader[] = "%!PS-Adobe-3.0\n";823 ULONG cbHeader; 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 phFile,/* File handle */843 &ulAction,/* Action taken */844 100L,/* File primary allocation */845 846 847 848 849 850 OPEN_ACCESS_READWRITE,/* Open mode of the file */851 0L);/* No extended attribute */852 DosWrite(*phFile,pszPSHeader,strlen(pszPSHeader),&cbHeader); 853 854 855 856 857 858 859 860 861 862 863 &control,/* File handle */864 &ulAction,/* Action taken */865 strlen(szTemp),/* File primary allocation */866 867 868 869 870 871 OPEN_ACCESS_READWRITE,/* Open mode of the file */872 0L);/* No extended attribute */873 874 875 876 877 878 879 855 PHFILE phFile, 856 PULONG pDeviceFlags, 857 PVOID pPrtOpenStruct) 858 { 859 APIRET rc; 860 ULONG ulAction = 0; /* Action taken by DosOpen */ 861 ULONG ulBytesRead = 0; /* Number of bytes read by DosRead */ 862 ULONG ulWrote = 0; /* Number of bytes written by DosWrite */ 863 ULONG ulLocal = 0; /* File pointer position after DosSetFilePtr */ 864 CHAR szTemp[ 256]; 865 UCHAR tmp[256]; 866 ULONG pcbWritten ; 867 USHORT i; 868 HFILE control; 869 UCHAR filename[256]; 870 DATETIME dt; 871 UCHAR spool_dir[256]; 872 PEAOP2 pEABuf = NULL; 873 /* UCHAR pszPSHeader[] = "%!PS-Adobe-3.0\n"; 874 ULONG cbHeader; */ 875 876 877 if (!phFile || !pDeviceFlags ) 878 { 879 return(ERROR_INVALID_PARAMETER); 880 } 881 DosGetDateTime(&dt); 882 rc = PrfQueryProfileString (HINI_SYSTEMPROFILE, 883 "PM_SPOOLER", 884 "DIR", 885 NULL, 886 (PSZ)spool_dir, 887 sizeof(spool_dir)); 888 spool_dir[ strlen(spool_dir) - 1] = '\0'; 889 sprintf(tmp,"%s\\SMB",spool_dir); 890 DosCreateDir( tmp,pEABuf ); 891 sprintf(filename,"%s\\SMB\\%02d_%02d_%02d_%02d_%s",spool_dir,dt.hours,dt.minutes,dt.seconds,dt.hundredths,pszPortName); 892 rc = DosOpen(filename, 893 phFile, /* File handle */ 894 &ulAction, /* Action taken */ 895 100L, /* File primary allocation */ 896 FILE_ARCHIVED | FILE_NORMAL, /* File attribute */ 897 OPEN_ACTION_CREATE_IF_NEW | 898 OPEN_ACTION_OPEN_IF_EXISTS, /* Open function type */ 899 OPEN_FLAGS_NOINHERIT | 900 OPEN_SHARE_DENYNONE | 901 OPEN_ACCESS_READWRITE, /* Open mode of the file */ 902 0L); /* No extended attribute */ 903 /* DosWrite(*phFile,pszPSHeader,strlen(pszPSHeader),&cbHeader); */ 904 sprintf(szTemp,"PM_%s",pszPortName); 905 if (PrfQueryProfileString (HINI_SYSTEMPROFILE, 906 szTemp, 907 KEY_INITIALIZATION, 908 NULL, 909 szTemp, 910 sizeof(szTemp))) 911 { 912 sprintf(tmp ,"%s\\SMB\\%d.control",spool_dir,*phFile); 913 rc = DosOpen( tmp , 914 &control, /* File handle */ 915 &ulAction, /* Action taken */ 916 strlen(szTemp), /* File primary allocation */ 917 FILE_ARCHIVED | FILE_NORMAL, /* File attribute */ 918 OPEN_ACTION_CREATE_IF_NEW | 919 OPEN_ACTION_OPEN_IF_EXISTS, /* Open function type */ 920 OPEN_FLAGS_NOINHERIT | 921 OPEN_SHARE_DENYNONE | 922 OPEN_ACCESS_READWRITE, /* Open mode of the file */ 923 0L); /* No extended attribute */ 924 rc = DosWrite( control,szTemp,strlen(szTemp),&pcbWritten); 925 rc = DosWrite( control,"#",1,&pcbWritten); 926 rc = DosWrite( control,filename,strlen(filename),&pcbWritten); 927 rc = DosWrite( control,"@",1,&pcbWritten); 928 rc = DosClose(control); 929 } 930 return rc; 880 931 881 932 } 882 933 ULONG APIENTRY SplPdQuery ( PSZ pszDeviceName, 883 884 885 886 887 888 889 { 890 /* 934 ULONG ulFlags, 935 ULONG ulCommand, 936 PVOID pInData, 937 ULONG cbInData, 938 PVOID pOutData, 939 PULONG pcbOutData ) 940 { 941 /* return ERROR_NOT_SUPPORTED; */ 891 942 return NO_ERROR; 892 943 } … … 996 1047 szTemp[i] = '\0'; 997 1048 strcpy(filename,&szTemp[pos]); 998 1049 999 1050 rc = DosClose( hFile ); 1000 1051 DosQuerySysInfo (QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, &ulBootDrive, … … 1002 1053 1003 1054 decryptPassword(password_enc,password_dec); 1004 1055 1005 1056 // Usage: smbspool [DEVICE_URI] job-id user title copies options [file] 1006 1057 … … 1011 1062 sprintf(j_title,"from %s",getenv("HOSTNAME")); 1012 1063 sprintf(j_options,"opt"); 1013 rc = spawnlp(P_WAIT,binfile,binfile,j_url,j_id,j_user,j_title,j_copies,j_options,filename,NULL); 1014 1064 rc = spawnlp(P_WAIT,binfile,binfile,j_url,j_id,j_user,j_title,j_copies,j_options,filename,NULL); 1065 1015 1066 while (rc != 0) 1016 1067 { 1017 1068 sprintf(errorstr,"Error during spooling to smb://%s:****@%s/%s/%s",username,workgroup,ip_add,queue_name); 1018 resp = WinMessageBox (HWND_DESKTOP, 1019 HWND_DESKTOP, 1020 errorstr, 1069 resp = WinMessageBox (HWND_DESKTOP, 1070 HWND_DESKTOP, 1071 errorstr, 1021 1072 "CIFS/SMB Port driver error", 1022 1073 0L, MB_RETRYCANCEL | MB_WARNING | MB_MOVEABLE); 1023 if (resp != MBID_CANCEL ) 1074 if (resp != MBID_CANCEL ) 1024 1075 { 1025 rc = spawnlp(P_WAIT,binfile,binfile,j_url,j_id,j_user,j_title,j_copies,j_options,filename,NULL); 1076 rc = spawnlp(P_WAIT,binfile,binfile,j_url,j_id,j_user,j_title,j_copies,j_options,filename,NULL); 1026 1077 } 1027 1078 else rc = 0; 1028 1079 }; 1029 1080 1030 1081 strcpy(filename,&szTemp[pos]); 1031 1082 DosDelete(filename); … … 1035 1086 return rc; 1036 1087 } 1037 ULONG APIENTRY SplPdWrite( HFILE 1038 PVOID 1039 ULONG 1088 ULONG APIENTRY SplPdWrite( HFILE hFile, 1089 PVOID pchData, 1090 ULONG cbData, 1040 1091 PULONG pcbWritten ) 1041 1092 { APIRET rc;
Note:
See TracChangeset
for help on using the changeset viewer.