Changeset 11
- Timestamp:
- Apr 21, 2013, 9:15:05 PM (12 years ago)
- Location:
- rxprtutl/trunk
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified rxprtutl/trunk/rxprtutl.c ¶
r10 r11 60 60 #define SZ_LIBRARY_NAME "RXPRTUTL" // Name of this library 61 61 #define SZ_ERROR_NAME "RPUERROR" // REXX variable used to store error codes 62 #define SZ_VERSION "0.2. 0" // Current version of this library62 #define SZ_VERSION "0.2.1" // Current version of this library 63 63 64 64 #define APPNAME_LEAD_STR "PM_" … … 66 66 #define APPNAME_PM_SPOOLER_PORT "PM_SPOOLER_PORT" 67 67 #define APPNAME_PM_PRINT_OBJECT "PM_PrintObject" 68 #define APPNAME_PM_ABS_OBJECTS "PM_Abstract:Objects" 68 69 #define APPNAME_PM_WPS_LOCATION "PM_Workplace:Location" 70 71 #define ID_OBJINFO_QUEUENAME 3 72 #define ID_OBJINFO_RPQUEUENAME 13 69 73 70 74 // Values that should be defined in pmsplb.h if it actually existed … … 89 93 #define US_PORT_MAXZ 64 // ...of a port name 90 94 #define US_PRTDEV_MAXZ 9 // ...of a print device name 95 96 97 // DATA TYPES 98 99 /* Structures needed used to parse PM_Abstract:Object data 100 */ 101 #pragma pack(1) 102 typedef struct _Object_Info 103 { 104 USHORT cbName; // Size of szName, including terminator 105 USHORT cbData; // Number of additional data bytes following szName 106 CHAR szName[1]; // Name of object type 107 } OBJINFO, *POBJINFO; 108 109 typedef struct _Object_Tag_Info 110 { 111 USHORT usTagFormat; // Tag data format 112 USHORT usTag; // Tag ID 113 USHORT cbTag; // Size of tag data 114 } OITAG, *POITAG; 115 #pragma pack() 116 117 118 // GLOBALS 91 119 92 120 // List of functions to be registered by RPULoadFuncs … … 592 620 * of the print device(s) connected to it. 593 621 */ 594 rc = SplQueryQueue( NULL, pPInfo->pszPrintDestinationName, 622 623 #if 0 624 if ( pPInfo->pszComputerName ) { 625 /* Network printer. Just display the local information and 626 * don't try to query the remote queue. 627 */ 628 sprintf( szStemNode, "%s.%u", szStem, ++ulCount ); 629 WriteCompoundVariable( szStemNode, "!name", 630 pPInfo->pszPrintDestinationName ); 631 WriteCompoundVariable( szStemNode, "!description", 632 pPInfo->pszDescription ); 633 WriteCompoundVariable( szStemNode, "!queue", ""); 634 WriteCompoundVariable( szStemNode, "!flags", ""); 635 WriteCompoundVariable( szStemNode, "!handle", ""); 636 637 WriteCompoundVariable( szStemNode, "!host", 638 pPInfo->pszComputerName ); 639 continue; 640 } 641 #endif 642 643 rc = SplQueryQueue( pPInfo->pszComputerName, 644 pPInfo->pszPrintDestinationName, 595 645 6L, NULL, 0L, &cbNeeded ); 596 646 if (( rc != NO_ERROR ) && ( rc != NERR_BufTooSmall )) { 597 647 WriteErrorCode( rc, "SplQueryQueue"); 598 648 MAKERXSTRING( *prsResult, "0", 1 ); 599 goto cleanup; 649 //goto cleanup; 650 continue; 600 651 } 601 652 pbQueue = malloc( cbNeeded ); … … 603 654 WriteErrorCode( ERROR_NOT_ENOUGH_MEMORY, "malloc"); 604 655 MAKERXSTRING( *prsResult, "0", 1 ); 605 goto cleanup; 656 //goto cleanup; 657 continue; 606 658 } 607 659 cbBuf = cbNeeded; 608 rc = SplQueryQueue( NULL, pPInfo->pszPrintDestinationName,660 rc = SplQueryQueue( pPInfo->pszComputerName, pPInfo->pszPrintDestinationName, 609 661 6L, pbQueue, cbBuf, &cbNeeded ); 610 662 if ( rc != NO_ERROR ) { … … 612 664 MAKERXSTRING( *prsResult, "0", 1 ); 613 665 free( pbQueue ); 614 goto cleanup; 666 //goto cleanup; 667 continue; 615 668 } 616 669 pQInfo = (PPRQINFO6) pbQueue; … … 713 766 714 767 hObj = PrinterObjectHandle( pszName ); 715 if ( !hObj ) return ( 40 ); 768 if ( !hObj ) { 769 MAKERXSTRING( *prsResult, "0", 1 ); 770 return ( 0 ); 771 } 716 772 717 773 fRC = WinOpenObject( hObj, ulView, TRUE ); … … 1414 1470 HOBJECT PrinterObjectHandle( PSZ pszQueueName ) 1415 1471 { 1416 PVOID pbuf = NULL; 1417 PSZ psz; 1418 CHAR szValue[ 256 ]; 1472 PVOID pbuf = NULL, 1473 pdata = NULL; 1474 PBYTE pb, 1475 pbEnd, 1476 pbGrpEnd; 1477 POBJINFO pInfo = NULL; 1478 POITAG pTag = NULL; 1479 PSZ psz, 1480 pszName; 1481 CHAR szValue[ 256 ], 1482 szObject[ 5 ]; 1419 1483 ULONG cbTotal = 0, 1420 cbActual = 0; 1421 HOBJECT hObj = 0; 1422 BOOL fRC; 1484 cbActual = 0, 1485 ulHandle; 1486 HOBJECT hObj = 0; 1487 BOOL fFound, 1488 fRC; 1423 1489 1424 1490 … … 1442 1508 } 1443 1509 1510 fFound = FALSE; 1444 1511 psz = (PSZ) pbuf; 1445 while ( *psz ) { 1512 while ( *psz && !fFound ) { 1513 #if 1 1514 1515 /* Just checking the queue names associated with the handle in 1516 * PM_PrintObject is not reliable, because remote (LAN) printers 1517 * will store the name of the _remote_ queue there (which is not 1518 * only impossible to map to a local queue name, it may actually 1519 * be the same AS a local queue name... for a different printer). 1520 * 1521 * So what we do here is parse the queue name out of the object 1522 * settings (from PM_Abstract:Objects). We also have to handle 1523 * remote printers slightly differently from local ones. 1524 * 1525 * I am indebted to Henk Kelder's WPTOOLS source code for providing 1526 * the basic logic, although the code below is largely original. 1527 */ 1528 1529 if ( sscanf( psz, "%u", &ulHandle ) && LOUSHORT( ulHandle )) { 1530 sprintf( szObject, "%X", LOUSHORT( ulHandle )); 1531 fRC = PrfQueryProfileSize( HINI_USERPROFILE, APPNAME_PM_ABS_OBJECTS, 1532 szObject, &cbTotal ); 1533 if ( !fRC || ( cbTotal < 25 ) || ((pdata = malloc( cbTotal )) == NULL )) { 1534 psz += strlen( psz ) + 1; 1535 continue; 1536 } 1537 if ( PrfQueryProfileData( HINI_USERPROFILE, APPNAME_PM_ABS_OBJECTS, 1538 szObject, (PVOID) pdata, &cbTotal )) 1539 { 1540 BOOL fRemote; 1541 pbEnd = (PBYTE) pdata + cbTotal; 1542 pszName = (PSZ) pdata + sizeof( ULONG ); 1543 fRemote = strcmp( pszName, "WPRPrinter") ? FALSE : TRUE; 1544 pb = (PBYTE) pszName + strlen( pszName ) + 17; 1545 while (( pb < pbEnd ) && !fFound ) { 1546 pInfo = (POBJINFO) pb; 1547 pb += sizeof( OBJINFO ) + strlen( pInfo->szName ); 1548 pbGrpEnd = pb + pInfo->cbData; 1549 if ( pbGrpEnd > pbEnd ) pbGrpEnd = pbEnd; 1550 while (( pb < pbGrpEnd ) && !fFound ) { 1551 pTag = (POITAG) pb; 1552 pb += sizeof( OITAG ); 1553 /* For network printers, tag ID 3 indicates the name of 1554 * the queue on the remote server. We want the local 1555 * queue name, which has tag ID 13. 1556 */ 1557 if ( fRemote && ( pTag->usTag == ID_OBJINFO_RPQUEUENAME )) { 1558 memcpy( szValue, pb, pTag->cbTag ); 1559 if ( !strcmp( szValue, pszQueueName )) { 1560 hObj = (HOBJECT) ulHandle; 1561 fFound = TRUE; 1562 } 1563 } 1564 // For local printers, just look for tag ID 3 1565 else if ( pTag->usTag == ID_OBJINFO_QUEUENAME ) { 1566 memcpy( szValue, pb, pTag->cbTag ); 1567 if ( !strcmp( szValue, pszQueueName )) { 1568 hObj = (HOBJECT) ulHandle; 1569 fFound = TRUE; 1570 } 1571 } 1572 pb += pTag->cbTag; 1573 } 1574 } 1575 } 1576 free( pdata ); 1577 } 1578 #else 1579 /* Old method, do not use (unreliable for the reasons noted above). 1580 */ 1446 1581 if ( !PrfQueryProfileString( HINI_USERPROFILE, APPNAME_PM_PRINT_OBJECT, 1447 1582 psz, NULL, szValue, 255 )) … … 1453 1588 ( sscanf( psz, "%u", (PULONG) &hObj ) == 1 )) 1454 1589 { 1590 fFound = TRUE; 1455 1591 break; 1456 1592 } 1593 #endif 1457 1594 psz += strlen( psz ) + 1; 1458 1595 } -
TabularUnified rxprtutl/trunk/rxprtutl.def ¶
r10 r11 1 1 LIBRARY RXPRTUTL INITINSTANCE TERMINSTANCE 2 2 DATA MULTIPLE NONSHARED 3 DESCRIPTION '@#Alex Taylor:0.2. 0#@##1## 13 Apr 2013 23:17:20REINFORCE::::::@@REXX Printer Management Utilities'3 DESCRIPTION '@#Alex Taylor:0.2.1#@##1## 21 Apr 2013 15:09:29 REINFORCE::::::@@REXX Printer Management Utilities' 4 4 5 5 EXPORTS RPULoadFuncs
Note:
See TracChangeset
for help on using the changeset viewer.