Ignore:
Timestamp:
Apr 18, 2009, 12:09:06 PM (16 years ago)
Author:
Herwig Bauernfeind
Message:

Alex Taylors fixes for Tickets #79/#80/#81/#82/#83/#84

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/smbpdr-1.0/smb.c

    r175 r177  
    6666        if ('0' <= c && c <= '9')
    6767        {
    68                  return c - '0';
     68                return c - '0';
    6969        }
    7070       
    7171        if ('A' <= c && c <= 'F')
    7272        {
    73                  return c - 'A' + 0xA;
     73                return c - 'A' + 0xA;
    7474        }
    7575       
    7676        if ('a' <= c && c <= 'f')
    7777        {
    78                  return c - 'a' + 0xA;
     78                return c - 'a' + 0xA;
    7979        }
    8080       
     
    143143} PORTNAMES, *PPORTNAMES;
    144144
     145/* Alex Taylor's new version of lprtok() that can handle missing fields */
    145146char * lprtok (char *string,char *control)
    146147{
    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 );
    185164}
    186165MRESULT EXPENTRY CommDlg( HWND hDlg, USHORT msg, MPARAM mp1, MPARAM mp2 )
     
    188167        PLPRDATA    pLprData;
    189168        ULONG       ulTimeOut = 0 ;
    190         CHAR        szDesc[ STR_LEN_PORTDESC];
     169        CHAR        szDesc[ STR_LEN_PORTDESC ];
     170        CHAR        szShareName[ STR_LEN_PORTDESC ];
    191171        CHAR        szTitle[ STR_LEN_TITLE + 1];
    192172        CHAR        szTemp[ STR_LEN_PORTDESC ];
     
    276256                        {
    277257                                case DID_OK:
     258                                        sprintf(szDesc,"\\");
    278259                                        /* Servername | IP */
    279260                                        WinQueryDlgItemText (hDlg, ID_IP, sizeof(szTemp), szTemp );
    280261                                        sprintf(pLprData->szSaveLprSetting,"%s",szTemp);
     262                                        strncpy(szShareName, szTemp, STR_LEN_PORTDESC - 1);
    281263                                        /* Printername | Queue */
    282264                                        WinQueryDlgItemText (hDlg, ID_SMBQUEUE, sizeof(szTemp), szTemp );
    283265                                        strcat(pLprData->szSaveLprSetting,"#");
    284266                                        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                                        }
    285271                                        /* Workgroup */
    286272                                        WinQueryDlgItemText (hDlg, ID_WORKGROUP, sizeof(szTemp), szTemp );
    287273                                        strcat(pLprData->szSaveLprSetting,"#");
    288274                                        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);
    289281                                        /* Username */
    290282                                        WinQueryDlgItemText (hDlg, ID_USER, sizeof(szTemp), szTemp );
     
    301293                                        encryptPassword(pwBuffer,szTemp);
    302294                                        strcat(pLprData->szSaveLprSetting,szTemp);
    303                                        
     295
    304296                                        if (!PrfWriteProfileString (HINI_SYSTEMPROFILE,
    305297                                                                                                pLprData->pszAppName,
     
    312304                                                                                                pLprData->pszPortName,
    313305                                                                                                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
    315314                                        WinDismissDlg(hDlg, TRUE);
    316315                                        break;
     
    321320                        break;
    322321                default:
    323                     return WinDefDlgProc(hDlg, msg, mp1, mp2) ;
    324                     break;
    325      }
    326  return FALSE;
     322                        return WinDefDlgProc(hDlg, msg, mp1, mp2) ;
     323                        break;
     324        }
     325return FALSE;
    327326}
    328327ULONG CalcStructLength ( HAB hab,
    329                                                  HMODULE hModule,
    330                                                  USHORT usID )
    331 {
    332    ULONG cbRequired;
    333    CHAR  chString[STR_LEN_PORTDESC];
    334 
    335    cbRequired = 0;
    336 
    337    WinLoadString(hab, hModule, usID, STR_LEN_PORTDESC, chString);
    338    cbRequired += strlen (chString) + 1;
    339    WinLoadString(hab, hModule, (USHORT)(usID + 1), STR_LEN_PORTDESC, chString);
    340    cbRequired += strlen (chString) + 1;
    341    cbRequired += sizeof (PORTNAMES);
    342    return(cbRequired);
     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);
    343342}
    344343
     
    346345                                                HMODULE hModule )
    347346{
    348    ULONG  cbRequired;
    349    USHORT usID;
    350 
    351    cbRequired = 0;
     347        ULONG  cbRequired;
     348        USHORT usID;
     349
     350        cbRequired = 0;
    352351
    353352                /*
    354353                ** calculate length required to fit all the port info.
    355354                */
    356    for (usID = PORT_ID_FIRST; usID <= PORT_ID_LAST; usID += 2)
    357    {
     355        for (usID = PORT_ID_FIRST; usID <= PORT_ID_LAST; usID += 2)
     356        {
    358357                cbRequired += CalcStructLength (hab, hModule, usID);
    359    }
    360 
    361    return(cbRequired);
     358        }
     359
     360        return(cbRequired);
    362361}
    363362
     
    366365                                                ULONG cbBuf )
    367366{
    368    ULONG  cbRequired;
    369    USHORT usID;
    370    ULONG  ulNumPort;
    371 
    372    cbRequired = 0;
    373    ulNumPort = 0;
     367        ULONG  cbRequired;
     368        USHORT usID;
     369        ULONG  ulNumPort;
     370
     371        cbRequired = 0;
     372        ulNumPort = 0;
    374373
    375374                /*
    376375                ** calculate how many ports we can fit in buf.
    377376                */
    378    for (usID = PORT_ID_FIRST; usID <= PORT_ID_LAST; usID += 2)
    379    {
     377        for (usID = PORT_ID_FIRST; usID <= PORT_ID_LAST; usID += 2)
     378        {
    380379                cbRequired += CalcStructLength (hab, hModule, usID);
    381380                if (cbRequired > cbBuf)
    382381                {
    383                  return(ulNumPort);
     382                return(ulNumPort);
    384383                }
    385384                ulNumPort++;
    386    }
    387 
    388    return(ulNumPort);
     385        }
     386
     387        return(ulNumPort);
    389388}
    390389VOID CopyStruct ( HAB hab,
    391                                   HMODULE hModule,
    392                                   USHORT usID,
    393                                   PCH pBuf,
    394                                   PULONG pulBeginStruct,
    395                                   PULONG pulBeginText )
    396 {
    397    PPORTNAMES pPortNames;
    398 
    399    pPortNames = (PPORTNAMES)(pBuf + *pulBeginStruct);
    400    *pulBeginStruct += sizeof (PORTNAMES);
     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);
    401400
    402401                /*
    403402                ** copy port name in the structure
    404403                */
    405    pPortNames->pszPortName = pBuf + *pulBeginText;
    406    WinLoadString(hab, hModule, usID, STR_LEN_PORTDESC, pPortNames->pszPortName);
    407    *pulBeginText += strlen (pPortNames->pszPortName) + 1;
     404        pPortNames->pszPortName = pBuf + *pulBeginText;
     405        WinLoadString(hab, hModule, usID, STR_LEN_PORTDESC, pPortNames->pszPortName);
     406        *pulBeginText += strlen (pPortNames->pszPortName) + 1;
    408407
    409408                /*
    410409                ** copy port description to the structure
    411410                */
    412    pPortNames->pszPortDesc = pBuf + *pulBeginText;
    413    WinLoadString(hab, hModule, usID, STR_LEN_PORTDESC, pPortNames->pszPortDesc);
    414    *pulBeginText += strlen (pPortNames->pszPortDesc) + 1;
     411        pPortNames->pszPortDesc = pBuf + *pulBeginText;
     412        WinLoadString(hab, hModule, usID, STR_LEN_PORTDESC, pPortNames->pszPortDesc);
     413        *pulBeginText += strlen (pPortNames->pszPortDesc) + 1;
    415414}
    416415VOID  CopyNPorts ( HAB hab,
    417                                    HMODULE hModule,
    418                                    PCH pBuf,
    419                                    ULONG ulReturned )
    420 {
    421    USHORT usID;
    422    ULONG  ulBeginText;
    423    ULONG  ulBeginStruct;
    424 
    425    ulBeginText = ulReturned * sizeof (PORTNAMES);
    426    ulBeginStruct = 0;
    427 
    428    for (usID = PORT_ID_FIRST;
     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;
    429428                usID <= PORT_ID_LAST && ulReturned;
    430429                usID += 2, --ulReturned)
    431    {
     430        {
    432431                CopyStruct (hab, hModule, usID, pBuf, &ulBeginStruct, &ulBeginText);
    433    }
     432        }
    434433}
    435434
     
    439438                                                PSZ pszAppName )
    440439{
    441    LPRDATA LprData;
    442 
    443    memset (&LprData, 0, sizeof (LPRDATA));
    444    LprData.hAB = hab;
    445    LprData.hModule = hModule;
    446    LprData.pszPortName = pszPortName;
    447    LprData.pszAppName = pszAppName;
    448 
    449    WinDlgBox  (HWND_DESKTOP,
     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,
    450449                                HWND_DESKTOP,
    451450                                (PFNWP)CommDlg,
     
    454453                                &LprData);
    455454
    456    return LprData.lfModified;
     455        return LprData.lfModified;
    457456}
    458457BOOL GetPortDescription ( HAB hab,
    459                                                   HMODULE hModule,
    460                                                   PSZ pszPortName,
    461                                                   PSZ pszPortDesc )
     458                                                        HMODULE hModule,
     459                                                        PSZ pszPortName,
     460                                                        PSZ pszPortDesc )
    462461{
    463462        USHORT usID;
    464         CHAR    chBuf[STR_LEN_PORTDESC];
     463        CHAR   chBuf[STR_LEN_PORTDESC] = {0};
    465464
    466465        for (usID = PORT_ID_FIRST; usID <= PORT_ID_LAST; usID += 2)
    467466        {
    468                 WinLoadString(hab, hModule, usID, STR_LEN_PORTDESC, chBuf);
     467                WinLoadString(hab, hModule, usID, STR_LEN_PORTNAME, chBuf);
    469468                if (!strcmp (pszPortName, chBuf))
    470469                {
     470                if ( WinLoadString(hab, hModule, usID+1, STR_LEN_PORTDESC, chBuf) ) {
    471471                        strcpy (pszPortDesc, chBuf);
    472472                        return(TRUE);
    473473                }
     474                break;
     475                }
    474476        }
    475477        return(FALSE);
     478}
     479BOOL  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);
    476505}
    477506APIRET APIENTRY SplPdEnumPort ( HAB hab,
     
    484513{
    485514        HMODULE hModule;
    486         ULONG   ulBootDrive;
    487         ULONG   rcLoadMod;
    488         CHAR    szPathName[260];
     515        ULONG   ulBootDrive;
     516        ULONG   rcLoadMod;
     517        CHAR    szPathName[260];
    489518
    490519        if (!pulReturned ||
     
    501530
    502531        DosQuerySysInfo (QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, &ulBootDrive,
    503                                          sizeof (ULONG));
     532                                        sizeof (ULONG));
    504533        szDefaultPortDrvPath[0] = (CHAR)(ulBootDrive + 'A' - 1);
    505534
    506535        PrfQueryProfileString (HINI_SYSTEMPROFILE,
    507                                                   "PM_PORT_DRIVER",
    508                                                   "SMB",
    509                                                   szDefaultPortDrvPath,
    510                                                   szPathName,
    511                                                   256 );
     536                                                        "PM_PORT_DRIVER",
     537                                                        "SMB",
     538                                                        szDefaultPortDrvPath,
     539                                                        szPathName,
     540                                                        256 );
    512541
    513542        rcLoadMod = DosLoadModule (NULL, 0, szPathName, &hModule);
     
    517546                *pulReturned = 0;
    518547                *pcbRequired = CalcBufLength (hab, hModule);
    519                 *pulTotal = 64;                         /* Currently support LPRx x = 1 .. 9     */
     548                *pulTotal = MAX_PORTS;
    520549                if (!rcLoadMod)
    521550                DosFreeModule (hModule);
     
    526555                ** check number of ports info we can fit in supplied buffer
    527556                */
    528         *pulTotal    = 64;                              /* Currently support LPRx x= 1 .. 9      */
     557        *pulTotal    = MAX_PORTS;
    529558        *pcbRequired = CalcBufLength (hab, hModule);
    530559        *pulReturned = NumPortsCanFit (hab, hModule, cbBuf);
     
    536565        {
    537566                if (!rcLoadMod)
    538                  DosFreeModule (hModule);
     567                DosFreeModule (hModule);
    539568                return(ERROR_INSUFFICIENT_BUFFER);
    540569        }
     
    549578                */
    550579        if (!rcLoadMod)
    551           DosFreeModule (hModule);
     580                DosFreeModule (hModule);
    552581
    553582                /*
     
    562591}
    563592APIRET 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        {
    589641                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,
    595646                                                                chBuf,
    596647                                                                KEY_DESCRIPTION,
    597648                                                                chPortDesc))
    598    {
     649        {
    599650                return (WinGetLastError (hab));
    600    }
    601 
    602    if (!PrfWriteProfileString (HINI_SYSTEMPROFILE,
     651        }
     652
     653        if (!PrfWriteProfileString (HINI_SYSTEMPROFILE,
    603654                                                                chBuf,
    604655                                                                KEY_INITIALIZATION,
    605656                                                                DEF_INITIALIZATION))
    606    {
     657        {
    607658                return (WinGetLastError (hab));
    608    }
    609 
    610    if (!PrfWriteProfileString (HINI_SYSTEMPROFILE,
     659        }
     660
     661        if (!PrfWriteProfileString (HINI_SYSTEMPROFILE,
    611662                                                                chBuf,
    612663                                                                KEY_TERMINATION,
    613664                                                                DEF_TERMINATION))
    614    {
     665        {
    615666                return (WinGetLastError (hab));
    616    }
    617 
    618    if (!PrfWriteProfileString (HINI_SYSTEMPROFILE,
     667        }
     668
     669        if (!PrfWriteProfileString (HINI_SYSTEMPROFILE,
    619670                                                                chBuf,
    620671                                                                KEY_PORTDRIVER,
    621672                                                                DEF_PORTDRIVER))
    622    {
     673        {
    623674                return (WinGetLastError (hab));
    624    }
    625 
    626    if (!PrfWriteProfileString (HINI_SYSTEMPROFILE,
     675        }
     676
     677        if (!PrfWriteProfileString (HINI_SYSTEMPROFILE,
    627678                                                                chBuf,
    628679                                                                KEY_TIMEOUT,
    629680                                                                DEF_TIMEOUT))
    630    {
     681        {
    631682                return (WinGetLastError (hab));
    632    }
    633    if (!PrfWriteProfileString (HINI_SYSTEMPROFILE,
     683        }
     684        if (!PrfWriteProfileString (HINI_SYSTEMPROFILE,
    634685                                                                APPNAME_PM_SPOOLER_PORT,
    635686                                                                pszPortName,
    636687                                                                DEF_INITIALIZATION))
    637    {
     688        {
    638689                return (WinGetLastError (hab));
    639    }
    640    return(NO_ERROR);
     690        }
     691        return(NO_ERROR);
    641692}
    642693BOOL   APIENTRY SplPdGetPortIcon ( HAB hab,
    643                                                                    PULONG idIcon )
    644 {
    645    if (idIcon)
    646    {
     694                                                                        PULONG idIcon )
     695{
     696        if (idIcon)
     697        {
    647698                *idIcon = SMB_ICON;
    648    }
    649    return(TRUE);
     699        }
     700        return(TRUE);
    650701}
    651702APIRET APIENTRY SplPdQueryPort ( HAB hab,
    652                                                                  PSZ pszPortName,
    653                                                                  PVOID pBufIn,
    654                                                                  ULONG cbBuf,
    655                                                                  PULONG cItems )
    656 {
    657    HMODULE hModule;
    658    CHAR    chString[STR_LEN_DESC];
    659    USHORT  usNumLines;
    660    USHORT  usLineID;
    661    USHORT  usStrLength;
    662    ULONG   ulBootDrive;
    663    PCH     pBuf = pBufIn;
    664    CHAR    szPathName[260];    /* will contain full path to this port driver */
    665 
    666    if (!cItems)
    667    {
    668                 return(ERROR_INVALID_PARAMETER);
    669    }
    670 
    671    if (!pBuf || !cbBuf)
    672    {
    673                 return(ERROR_INVALID_PARAMETER);
    674    }
    675 
    676 
    677    DosQuerySysInfo (QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, &ulBootDrive,
    678                                     sizeof (ULONG));
    679    szDefaultPortDrvPath[0] = (CHAR)(ulBootDrive + 'A' - 1);
    680 
    681    PrfQueryProfileString (HINI_SYSTEMPROFILE,
    682                                                   "PM_PORT_DRIVER",
    683                                                   "SMB",
    684                                                   szDefaultPortDrvPath,
    685                                                   szPathName,
    686                                                   256 );
    687 
    688    hModule = 0L ;
    689 
    690    DosLoadModule (NULL, 0, szPathName, &hModule);
    691 
    692    chString[0] = '\0' ;
    693 
    694    WinLoadString(hab, hModule, (USHORT)ID_NUMBER_OF_DESC_LINES, STR_LEN_DESC,
    695                                  chString);
    696    usNumLines = (USHORT)atoi (chString);
    697    usLineID = ID_FIRST_DESC_LINES;
    698    for (*cItems = 0; *cItems < usNumLines; *cItems++)
    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        {
    700751                WinLoadString(hab, hModule, usLineID, STR_LEN_DESC, chString);
    701752                if (cbBuf >= (usStrLength = (USHORT)(strlen (chString) + 1)))
    702753                {
    703                  strcpy (pBuf, chString);
    704                  pBuf += usStrLength;
    705                  cbBuf -= usStrLength;
     754                strcpy (pBuf, chString);
     755                pBuf += usStrLength;
     756                cbBuf -= usStrLength;
    706757                }
    707758                else
    708759                {
    709                  DosFreeModule (hModule);
    710                  return(ERROR_INSUFFICIENT_BUFFER);
     760                DosFreeModule (hModule);
     761                return(ERROR_INSUFFICIENT_BUFFER);
    711762                }
    712    }
    713    DosFreeModule (hModule);
    714    return(NO_ERROR);
     763        }
     764        DosFreeModule (hModule);
     765        return(NO_ERROR);
    715766}
    716767APIRET APIENTRY SplPdSetPort ( HAB hab,
     
    718769                                                                PULONG flModified )
    719770{
    720     CHAR    chBuf[STR_LEN_PORTNAME];
    721     CHAR    chPortDriver[STR_LEN_PORTNAME];
    722     ULONG   ulBootDrive;
    723     HMODULE hModule;
    724     CHAR    szPathName[260];   /* will contain full path to this port driver */
    725 
    726    if (!pszPortName || !flModified)
    727    {
    728                 return(ERROR_INVALID_PARAMETER);
    729    }
    730 
    731    strcpy (chBuf, APPNAME_LEAD_STR);
    732    strcat (chBuf, pszPortName);
    733 
    734    if (!(PrfQueryProfileString (HINI_SYSTEMPROFILE, chBuf,
     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,
    735786                                                                KEY_PORTDRIVER, NULL, chPortDriver,
    736787                                                                STR_LEN_PORTNAME)))
    737    {
    738                 return(ERROR_INVALID_PARAMETER);
    739    }
    740 
    741    if (strcmp (chPortDriver, DEF_PORTDRIVER))
    742    {
    743                 return(ERROR_INVALID_PARAMETER);
    744    }
    745 
    746    DosQuerySysInfo (QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, &ulBootDrive,
    747                                     sizeof (ULONG));
    748    szDefaultPortDrvPath[0] = (CHAR)(ulBootDrive + 'A' - 1);
    749 
    750    PrfQueryProfileString (HINI_SYSTEMPROFILE,
    751                                                   "PM_PORT_DRIVER",
    752                                                   "SMB",
    753                                                   szDefaultPortDrvPath,
    754                                                   szPathName,
    755                                                   256 );
    756 
    757    hModule = 0L ;                                                               /* Init module handle to null */
    758 
    759    DosLoadModule (NULL, 0, szPathName, &hModule);
    760 
    761    *flModified = OpenLprPortDlg (hab, hModule, pszPortName, chBuf);
    762 
    763    DosFreeModule (hModule);
    764    return(NO_ERROR);
     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);
    765816}
    766817
    767818
    768819APIRET APIENTRY SplPdRemovePort ( HAB hab,
    769                                                                   PSZ pszPortName )
    770 {
    771     CHAR chBuf[STR_LEN_PORTNAME];
    772     CHAR chPortDriver[STR_LEN_PORTNAME];
    773 
    774    if (!pszPortName)
    775    {
    776                 return(ERROR_INVALID_PARAMETER);
    777    }
    778 
    779    strcpy (chBuf, APPNAME_LEAD_STR);
    780    strcat (chBuf, pszPortName);
    781 
    782    if (!(PrfQueryProfileString (HINI_SYSTEMPROFILE, chBuf,
     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,
    783834                                                                KEY_PORTDRIVER, NULL, chPortDriver,
    784835                                                                STR_LEN_PORTNAME)))
    785    {
    786                 return(ERROR_INVALID_PARAMETER);
    787    }
    788 
    789    if (strcmp (chPortDriver, DEF_PORTDRIVER))
    790    {
    791                 return(ERROR_INVALID_PARAMETER);
    792    }
    793 
    794    PrfWriteProfileString (HINI_SYSTEMPROFILE, chBuf, NULL, NULL);
    795 
    796    PrfWriteProfileString (HINI_SYSTEMPROFILE,
    797                                                   APPNAME_PM_SPOOLER_PORT,
    798                                                   pszPortName,
    799                                                   NULL);
    800    return(NO_ERROR);
     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);
    801852
    802853}
    803854ULONG APIENTRY SplPdOpen( PSZ     pszPortName,
    804                                                   PHFILE  phFile,
    805                                                   PULONG  pDeviceFlags,
    806                                                   PVOID   pPrtOpenStruct)
    807 {
    808    APIRET rc;
    809    ULONG  ulAction       = 0;      /* Action taken by DosOpen */
    810    ULONG  ulBytesRead    = 0;      /* Number of bytes read by DosRead */
    811    ULONG  ulWrote               = 0;      /* Number of bytes written by DosWrite */
    812    ULONG  ulLocal               = 0;      /* File pointer position after DosSetFilePtr */
    813    CHAR   szTemp[ 256];
    814    UCHAR  tmp[256];
    815    ULONG  pcbWritten ;
    816    USHORT  i;
    817    HFILE   control;
    818    UCHAR  filename[256];
    819    DATETIME dt;
    820    UCHAR  spool_dir[256];
    821    PEAOP2 pEABuf = NULL;
    822    UCHAR           pszPSHeader[] = "%!PS-Adobe-3.0\n";
    823    ULONG                   cbHeader;
    824 
    825 
    826   if (!phFile || !pDeviceFlags )
    827   {
    828       return(ERROR_INVALID_PARAMETER);
    829   }
    830   DosGetDateTime(&dt);
    831   rc = PrfQueryProfileString (HINI_SYSTEMPROFILE,
    832                                                       "PM_SPOOLER",
    833                                                       "DIR",
    834                                                       NULL,
    835                                                       (PSZ)spool_dir,
    836                                                       sizeof(spool_dir));
    837   spool_dir[ strlen(spool_dir) - 1] = '\0';
    838   sprintf(tmp,"%s\\SMB",spool_dir);
    839   DosCreateDir( tmp,pEABuf );
    840   sprintf(filename,"%s\\SMB\\%02d_%02d_%02d_%02d_%s",spool_dir,dt.hours,dt.minutes,dt.seconds,dt.hundredths,pszPortName);
    841   rc = DosOpen(filename,
    842                        phFile,                                          /* File handle */
    843                        &ulAction,                                     /* Action taken */
    844                        100L,                                               /* File primary allocation */
    845                        FILE_ARCHIVED | FILE_NORMAL,    /* File attribute */
    846                        OPEN_ACTION_CREATE_IF_NEW |
    847                        OPEN_ACTION_OPEN_IF_EXISTS,     /* Open function type */
    848                        OPEN_FLAGS_NOINHERIT |
    849                        OPEN_SHARE_DENYNONE  |
    850                        OPEN_ACCESS_READWRITE,             /* Open mode of the file */
    851                        0L);                                                 /* No extended attribute */
    852   DosWrite(*phFile,pszPSHeader,strlen(pszPSHeader),&cbHeader);
    853   sprintf(szTemp,"PM_%s",pszPortName);
    854   if (PrfQueryProfileString (HINI_SYSTEMPROFILE,
    855                                                      szTemp,
    856                                                      KEY_INITIALIZATION,
    857                                                      NULL,
    858                                                      szTemp,
    859                                                      sizeof(szTemp)))
    860    {
    861       sprintf(tmp   ,"%s\\SMB\\%d.control",spool_dir,*phFile);
    862       rc = DosOpen( tmp    ,
    863                                    &control,                                            /* File handle */
    864                                    &ulAction,                                 /* Action taken */
    865                                    strlen(szTemp),                              /* File primary allocation */
    866                                    FILE_ARCHIVED | FILE_NORMAL,    /* File attribute */
    867                                    OPEN_ACTION_CREATE_IF_NEW |
    868                                    OPEN_ACTION_OPEN_IF_EXISTS,     /* Open function type */
    869                                    OPEN_FLAGS_NOINHERIT |
    870                                    OPEN_SHARE_DENYNONE  |
    871                                    OPEN_ACCESS_READWRITE,                 /* Open mode of the file */
    872                                    0L);                                             /* No extended attribute */
    873      rc = DosWrite( control,szTemp,strlen(szTemp),&pcbWritten);
    874      rc = DosWrite( control,"#",1,&pcbWritten);
    875      rc = DosWrite( control,filename,strlen(filename),&pcbWritten);
    876      rc = DosWrite( control,"@",1,&pcbWritten);
    877      rc = DosClose(control);
    878    }
    879  return rc;
     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        }
     930return rc;
    880931
    881932}
    882933ULONG  APIENTRY SplPdQuery ( PSZ    pszDeviceName,
    883                                                      ULONG  ulFlags,
    884                                                      ULONG  ulCommand,
    885                                                      PVOID  pInData,
    886                                                      ULONG  cbInData,
    887                                                      PVOID  pOutData,
    888                                                      PULONG pcbOutData )
    889 {
    890 /*      return ERROR_NOT_SUPPORTED; */
     934                                                        ULONG  ulFlags,
     935                                                        ULONG  ulCommand,
     936                                                        PVOID  pInData,
     937                                                        ULONG  cbInData,
     938                                                        PVOID  pOutData,
     939                                                        PULONG pcbOutData )
     940{
     941/*  return ERROR_NOT_SUPPORTED; */
    891942        return NO_ERROR;
    892943}
     
    9961047        szTemp[i] = '\0';
    9971048        strcpy(filename,&szTemp[pos]);
    998        
     1049
    9991050        rc = DosClose( hFile );
    10001051        DosQuerySysInfo (QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, &ulBootDrive,
     
    10021053
    10031054        decryptPassword(password_enc,password_dec);
    1004        
     1055
    10051056// Usage: smbspool [DEVICE_URI] job-id user title copies options [file]
    10061057
     
    10111062        sprintf(j_title,"from %s",getenv("HOSTNAME"));
    10121063        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
    10151066        while (rc != 0)
    10161067        {
    10171068                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,
    10211072                                                        "CIFS/SMB Port driver error",
    10221073                                                        0L, MB_RETRYCANCEL | MB_WARNING | MB_MOVEABLE);
    1023                 if (resp != MBID_CANCEL ) 
     1074                if (resp != MBID_CANCEL )
    10241075                {
    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);
    10261077                }
    10271078                else rc = 0;
    10281079        };
    1029        
     1080
    10301081        strcpy(filename,&szTemp[pos]);
    10311082        DosDelete(filename);
     
    10351086        return rc;
    10361087}
    1037 ULONG APIENTRY SplPdWrite( HFILE        hFile,
    1038                                                         PVOID   pchData,
    1039                                                         ULONG   cbData,
     1088ULONG APIENTRY SplPdWrite( HFILE    hFile,
     1089                                                        PVOID   pchData,
     1090                                                        ULONG   cbData,
    10401091                                                        PULONG  pcbWritten )
    10411092{  APIRET rc;
Note: See TracChangeset for help on using the changeset viewer.