Changeset 11


Ignore:
Timestamp:
Apr 21, 2013, 9:15:05 PM (12 years ago)
Author:
Alex Taylor
Message:

Rewrote PrinterObjectHandle function.

Location:
rxprtutl/trunk
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified rxprtutl/trunk/rxprtutl.c

    r10 r11  
    6060#define SZ_LIBRARY_NAME         "RXPRTUTL"  // Name of this library
    6161#define SZ_ERROR_NAME           "RPUERROR"  // REXX variable used to store error codes
    62 #define SZ_VERSION              "0.2.0"     // Current version of this library
     62#define SZ_VERSION              "0.2.1"     // Current version of this library
    6363
    6464#define APPNAME_LEAD_STR        "PM_"
     
    6666#define APPNAME_PM_SPOOLER_PORT "PM_SPOOLER_PORT"
    6767#define APPNAME_PM_PRINT_OBJECT "PM_PrintObject"
     68#define APPNAME_PM_ABS_OBJECTS  "PM_Abstract:Objects"
    6869#define APPNAME_PM_WPS_LOCATION "PM_Workplace:Location"
     70
     71#define ID_OBJINFO_QUEUENAME    3
     72#define ID_OBJINFO_RPQUEUENAME  13
    6973
    7074// Values that should be defined in pmsplb.h if it actually existed
     
    8993#define US_PORT_MAXZ            64                                   // ...of a port name
    9094#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)
     102typedef 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
     109typedef 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
    91119
    92120// List of functions to be registered by RPULoadFuncs
     
    592620             * of the print device(s) connected to it.
    593621             */
    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,
    595645                                6L, NULL, 0L, &cbNeeded );
    596646            if (( rc != NO_ERROR ) && ( rc != NERR_BufTooSmall )) {
    597647                WriteErrorCode( rc, "SplQueryQueue");
    598648                MAKERXSTRING( *prsResult, "0", 1 );
    599                 goto cleanup;
     649                //goto cleanup;
     650                continue;
    600651            }
    601652            pbQueue = malloc( cbNeeded );
     
    603654                WriteErrorCode( ERROR_NOT_ENOUGH_MEMORY, "malloc");
    604655                MAKERXSTRING( *prsResult, "0", 1 );
    605                 goto cleanup;
     656                //goto cleanup;
     657                continue;
    606658            }
    607659            cbBuf = cbNeeded;
    608             rc = SplQueryQueue( NULL, pPInfo->pszPrintDestinationName,
     660            rc = SplQueryQueue( pPInfo->pszComputerName, pPInfo->pszPrintDestinationName,
    609661                                6L, pbQueue, cbBuf, &cbNeeded );
    610662            if ( rc != NO_ERROR ) {
     
    612664                MAKERXSTRING( *prsResult, "0", 1 );
    613665                free( pbQueue );
    614                 goto cleanup;
     666                //goto cleanup;
     667                continue;
    615668            }
    616669            pQInfo = (PPRQINFO6) pbQueue;
     
    713766
    714767    hObj = PrinterObjectHandle( pszName );
    715     if ( !hObj ) return ( 40 );
     768    if ( !hObj ) {
     769        MAKERXSTRING( *prsResult, "0", 1 );
     770        return ( 0 );
     771    }
    716772
    717773    fRC = WinOpenObject( hObj, ulView, TRUE );
     
    14141470HOBJECT PrinterObjectHandle( PSZ pszQueueName )
    14151471{
    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 ];
    14191483    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;
    14231489
    14241490
     
    14421508    }
    14431509
     1510    fFound = FALSE;
    14441511    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         */
    14461581        if ( !PrfQueryProfileString( HINI_USERPROFILE, APPNAME_PM_PRINT_OBJECT,
    14471582                                     psz, NULL, szValue, 255 ))
     
    14531588            ( sscanf( psz, "%u", (PULONG) &hObj ) == 1 ))
    14541589        {
     1590            fFound = TRUE;
    14551591            break;
    14561592        }
     1593#endif
    14571594        psz += strlen( psz ) + 1;
    14581595    }
  • TabularUnified rxprtutl/trunk/rxprtutl.def

    r10 r11  
    11LIBRARY     RXPRTUTL INITINSTANCE TERMINSTANCE
    22DATA        MULTIPLE NONSHARED
    3 DESCRIPTION '@#Alex Taylor:0.2.0#@##1## 13 Apr 2013 23:17:20     REINFORCE::::::@@REXX Printer Management Utilities'
     3DESCRIPTION '@#Alex Taylor:0.2.1#@##1## 21 Apr 2013 15:09:29     REINFORCE::::::@@REXX Printer Management Utilities'
    44
    55EXPORTS     RPULoadFuncs
Note: See TracChangeset for help on using the changeset viewer.