Changeset 217 for trunk


Ignore:
Timestamp:
Aug 4, 2007, 5:45:12 PM (14 years ago)
Author:
Eugene Romanenko
Message:

better solution for ticket #43

Location:
trunk/Lucide/SOURCE
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/Lucide/SOURCE/gui/pluginman.cpp

    r216 r217  
    5959
    6060    // enum plugins, (LU*.DLL) except for LUDOC.DLL, which is 'null' plugin
    61     // and Lucide.dll, which isn't plugin.
     61    // and Lucide.dll, which is not a plugin.
    6262    struct find_t ffblk;
    6363    unsigned done = _dos_findfirst( buffer, _A_RDONLY | _A_NORMAL, &ffblk );
     
    8989{
    9090    // Function pointer variables
    91     LuDocument * APIENTRY (*pCreateObject)()      = NULL;
    92     char * APIENTRY (*pGetSupportedExtensions)() = NULL;
    93     char * APIENTRY (*pGetDescription)()          = NULL;
    94     LuCheckStruct * APIENTRY (*pGetCheckStruct)() = NULL;
     91    LuDocument       * APIENTRY (*pCreateObject)()           = NULL;
     92    char             * APIENTRY (*pGetSupportedExtensions)() = NULL;
     93    char             * APIENTRY (*pGetDescription)()         = NULL;
     94    LuSignatureCheck * APIENTRY (*pGetSignatureCheck)()      = NULL;
    9595
    9696    std::string fulldllname = path;
     
    116116
    117117        // optional
    118         if ( DosQueryProcAddr( h, 0, "getCheckStruct", (PFN *)&pGetCheckStruct ) != 0 ) {
    119             pGetCheckStruct = NULL;
     118        if ( DosQueryProcAddr( h, 0, "getSignatureCheck", (PFN *)&pGetSignatureCheck ) != 0 ) {
     119            pGetSignatureCheck = NULL;
    120120        }
    121121
     
    126126    {
    127127        PluginInfo pi;
    128         pi.handle = h;
    129         pi.name = dllname;
    130         pi.extensions = pGetSupportedExtensions();
     128        pi.handle      = h;
     129        pi.name        = dllname;
     130        pi.extensions  = pGetSupportedExtensions();
    131131        pi.description = pGetDescription();
    132         pi.checkStruct = ( pGetCheckStruct == NULL ) ? NULL : pGetCheckStruct();
     132        pi.signatures  = ( pGetSignatureCheck == NULL ) ? NULL : pGetSignatureCheck();
    133133
    134134        plugins->push_back( pi );
     
    136136}
    137137
     138static LuDocument *createDocFromDll( HMODULE handle, bool checkOnly )
     139{
     140    LuDocument * APIENTRY (*pCreateObject)() = NULL;
     141
     142    if ( DosQueryProcAddr( handle, 0, "createObject", (PFN *)&pCreateObject ) == 0 )
     143    {
     144        if ( checkOnly ) {
     145            return (LuDocument *)TRUE;
     146        }
     147        else {
     148            return pCreateObject();
     149        }
     150    }
     151
     152    return NULL;
     153}
    138154
    139155// returns NULL if no suitable plugin found
     
    144160        return NULL;
    145161    }
    146 
    147     LuDocument * APIENTRY (*pCreateObject)() = NULL;
    148162
    149163    for ( int i = 0; i < plugins->size(); i++ )
     
    165179        if ( strstr( cExts, cExt ) != NULL )
    166180        {
    167             if ( DosQueryProcAddr( pi->handle, 0, "createObject",
    168                                    (PFN *)&pCreateObject ) == 0 )
     181            LuDocument *d = createDocFromDll( pi->handle, checkOnly );
     182            if ( d != NULL )
    169183            {
    170184                delete cExt;
    171185                delete cExts;
    172 
    173                 if ( checkOnly ) {
    174                     return (LuDocument *)TRUE;
    175                 }
    176                 else {
    177                     return pCreateObject();
    178                 }
     186                return d;
    179187            }
    180188        }
     
    187195}
    188196
    189 static bool checkDataEntry( LuCheckData *data, int h )
    190 {
    191     lseek( h, data->offset, SEEK_SET );
    192     unsigned char *buf = new char[ data->length ];
    193     read( h, buf, data->length );
    194     bool result = ( memcmp( data->data, buf, data->length ) == 0 );
     197static bool checkSignature( LuSignature *signature, int h )
     198{
     199    lseek( h, signature->offset, ( signature->origin == 0 ) ? SEEK_SET : SEEK_END );
     200    unsigned char *buf = new char[ signature->length ];
     201    read( h, buf, signature->length );
     202    bool result = ( memcmp( signature->data, buf, signature->length ) == 0 );
    195203    delete buf;
    196204    return result;
    197205}
    198206
    199 static bool checkData( LuCheckStruct *checkStruct, const char *file )
     207static bool checkSignatureList( LuSignatureList *siglist, int h )
     208{
     209    bool result = true;
     210
     211    // all signatures must be checked for positive result
     212    for ( unsigned long i = 0; i < siglist->count; i++ )
     213    {
     214        if ( !checkSignature( &(siglist->signatures[ i ]), h ) ) {
     215            result = false;
     216            break;
     217        }
     218    }
     219
     220    return result;
     221}
     222
     223static bool checkSignatures( LuSignatureCheck *signatures, const char *file )
    200224{
    201225    int h = open( file, O_RDONLY | O_BINARY );
    202226
    203     if ( h != -1 )
    204     {
    205         bool result = true;
    206 
    207         for ( unsigned long i = 0; i < checkStruct->count; i++ )
    208         {
    209             if ( !checkDataEntry( &(checkStruct->cdata[ i ]), h ) ) {
    210                 result = false;
    211                 break;
    212             }
    213         }
    214 
    215         close( h );
    216         return result;
    217     }
    218 
    219     return false;
     227    if ( h == -1 ) {
     228        return false;
     229    }
     230
     231    bool result = false;
     232
     233    // if one signature list checked - result is positive
     234    for ( unsigned long i = 0; i < signatures->count; i++ )
     235    {
     236        if ( result = checkSignatureList( &(signatures->slists[ i ]), h ) ) {
     237            break;
     238        }
     239    }
     240    close( h );
     241
     242    return result;
    220243}
    221244
     
    237260
    238261    // Search by checkstruct
    239     LuDocument * APIENTRY (*pCreateObject)() = NULL;
    240 
    241     for ( int i = 0; i < plugins->size(); i++ )
    242     {
    243         PluginInfo *pi = &(*plugins)[ i ];
    244 
    245         if ( pi->checkStruct != NULL )
     262    for ( int i = 0; i < plugins->size(); i++ )
     263    {
     264        PluginInfo *pi = &(*plugins)[ i ];
     265
     266        if ( pi->signatures != NULL )
    246267        {
    247             if ( checkData( pi->checkStruct, file ) )
     268            if ( checkSignatures( pi->signatures, file ) )
    248269            {
    249                 if ( DosQueryProcAddr( pi->handle, 0, "createObject",
    250                                        (PFN *)&pCreateObject ) == 0 )
    251                 {
    252                     if ( checkOnly ) {
    253                         return (LuDocument *)TRUE;
    254                     }
    255                     else {
    256                         return pCreateObject();
    257                     }
     270                LuDocument *d = createDocFromDll( pi->handle, checkOnly );
     271                if ( d != NULL ) {
     272                    return d;
     273                }
     274            }
     275        }
     276    }
     277
     278
     279    // Search by isFileSupported()
     280    BOOL APIENTRY (*pIsFileSupported)(PCSZ) = NULL;
     281
     282    for ( int i = 0; i < plugins->size(); i++ )
     283    {
     284        PluginInfo *pi = &(*plugins)[ i ];
     285
     286        if ( DosQueryProcAddr( pi->handle, 0, "isFileSupported",
     287                               (PFN *)&pIsFileSupported ) == 0 )
     288        {
     289            if ( pIsFileSupported( file ) )
     290            {
     291                LuDocument *d = createDocFromDll( pi->handle, checkOnly );
     292                if ( d != NULL ) {
     293                    return d;
    258294                }
    259295            }
  • trunk/Lucide/SOURCE/gui/pluginman.h

    r215 r217  
    5050    std::string extensions;
    5151    std::string description;
    52     LuCheckStruct *checkStruct;
     52    LuSignatureCheck *signatures;
    5353};
    5454
  • trunk/Lucide/SOURCE/plugins/ludjvu/ludjvu.cpp

    r215 r217  
    5858
    5959
    60 unsigned _System LibMain( unsigned hmod, unsigned termination )
     60unsigned EXPENTRY LibMain( unsigned hmod, unsigned termination )
    6161{
    6262    if ( termination ) {
     
    6868}
    6969
    70 extern "C" LuDocument * _System createObject()
     70extern "C" LuDocument * EXPENTRY createObject()
    7171{
    7272    return new LuDjvuDocument;
    7373}
    7474
    75 extern "C" char * _System getSupportedExtensions()
     75extern "C" char * EXPENTRY getSupportedExtensions()
    7676{
    7777    return "DJVU;DJV";
    7878}
    7979
    80 LuCheckData   lcd = { 0, 8, (void *)"AT&TFORM" };
    81 LuCheckStruct lcs = { 1, &lcd };
    82 
    83 extern "C" LuCheckStruct * _System getCheckStruct()
    84 {
    85         return &lcs;
    86 }
    87 
    88 
    89 extern "C" char * _System getDescription()
     80static LuSignature      lsig = { 0, 0, 8, (void *)"AT&TFORM" };
     81static LuSignatureList  lsl  = { 1, &lsig };
     82static LuSignatureCheck lsc  = { 1, &lsl };
     83
     84extern "C" LuSignatureCheck * EXPENTRY getSignatureCheck()
     85{
     86        return &lsc;
     87}
     88
     89
     90extern "C" char * EXPENTRY getDescription()
    9091{
    9192    return "DjVu plugin, based on DjVuLibre v3.5.19";
  • trunk/Lucide/SOURCE/plugins/ludjvu/ludjvu.def

    r215 r217  
    44IMPORTS
    55        _LuDocumentNewClass=ludoc.LuDocumentNewClass
    6     _LuDocumentCClassData=ludoc.LuDocumentCClassData
    7     _LuDocumentClassData=ludoc.LuDocumentClassData
     6;    _LuDocumentCClassData=ludoc.LuDocumentCClassData
     7;    _LuDocumentClassData=ludoc.LuDocumentClassData
    88        _LuPixbufNewClass=ludoc.LuPixbufNewClass
    9     _LuPixbufClassData=ludoc.LuPixbufClassData
     9;    _LuPixbufClassData=ludoc.LuPixbufClassData
    1010        _somParentNumResolve=som.somParentNumResolve
    1111        _somBuildClass=som.somBuildClass
    12         _somPrintf=som.somPrintf
     12;       _somPrintf=som.somPrintf
    1313
    1414EXPORTS
     
    1616  getSupportedExtensions
    1717  getDescription
    18   getCheckStruct
     18  getSignatureCheck
  • trunk/Lucide/SOURCE/plugins/ludjvu/makefile

    r215 r217  
    4141export getSupportedExtensions
    4242export getDescription
    43 export getCheckStruct
     43export getSignatureCheck
    4444| tmpmake.lnk >NUL
    4545    wlink @tmpmake.lnk
  • trunk/Lucide/SOURCE/plugins/ludoc/ludoc.cpp

    r215 r217  
    5656
    5757
    58 unsigned _System LibMain( unsigned hmod, unsigned termination )
     58unsigned EXPENTRY LibMain( unsigned hmod, unsigned termination )
    5959{
    6060    if ( termination ) {
     
    6767
    6868
    69 extern "C" LuDocument * _System createObject()
     69extern "C" LuDocument * EXPENTRY createObject()
    7070{
    7171    return new LuDocument;
    7272}
    7373
    74 extern "C" char * _System getSupportedExtensions()
     74extern "C" char * EXPENTRY getSupportedExtensions()
    7575{
    7676    return "";
    7777}
    7878
    79 extern "C" LuCheckStruct * _System getCheckStruct()
     79extern "C" LuSignatureCheck * EXPENTRY getSignatureCheck()
    8080{
    8181        return NULL;
    8282}
    8383
    84 extern "C" char * _System getDescription()
     84extern "C" char * EXPENTRY getDescription()
    8585{
    8686    return "NULL plugin, abstract base class for Lucide plugins.";
  • trunk/Lucide/SOURCE/plugins/ludoc/lutypes.h

    r215 r217  
    3535#ifndef lutypes_h
    3636#define lutypes_h
     37
     38#include <os2.h>
    3739
    3840
     
    156158
    157159#ifndef __SOMIDL__
    158 typedef long (_System *_asynchCallbackFn)( void *data );
     160typedef long (EXPENTRY *_asynchCallbackFn)( void *data );
    159161//typedef _asynchCallbackFn *asynchCallbackFn;
    160162#endif
     
    177179#define LU_RERR_FONT_NOT_FOUND        4
    178180
    179 
    180 // structs to detect type of file by it's content
    181 
    182 struct LuCheckData
    183 {
    184     unsigned long  offset;  // from beginning of file
    185     unsigned long  length;  // length of data bytes to check
    186     void          *data;    // pointer to data bytes
    187 };
    188 
    189 struct LuCheckStruct
    190 {
    191     unsigned long  count;    // number of LuCheckData structures
    192     LuCheckData   *cdata;    //
     181//
     182// ***  Structs to detect type of file by it's content ***
     183//
     184
     185// one signature to check
     186struct LuSignature
     187{
     188    unsigned long  offset; // offset to read data
     189    unsigned long  origin; // offset: 0 - from beginning of file, 1 - from end
     190    unsigned long  length; // length of data bytes to check
     191    void          *data;   // pointer to data bytes
     192};
     193
     194// list of signatures to check
     195// all signatures must be checked for positive result
     196struct LuSignatureList
     197{
     198    unsigned long  count;       // number of LuSignature structures
     199    LuSignature   *signatures;  // array of LuSignature structures
     200};
     201
     202// list of checklists
     203// at least one checklist must be checked for positive result
     204struct LuSignatureCheck
     205{
     206    unsigned long    count;   // number of LuSignatureList structures
     207    LuSignatureList *slists;  // array of LuSignatureList structures
    193208};
    194209
  • trunk/Lucide/SOURCE/plugins/ludoc/makefile

    r215 r217  
    5252export getSupportedExtensions
    5353export getDescription
    54 export getCheckStruct
     54export getSignatureCheck
    5555export uniConvertSpChars
    5656export uniLigaturesLength
  • trunk/Lucide/SOURCE/plugins/lujpeg/lujpeg.cpp

    r215 r217  
    6868               LuPixbuf *in, float in_x0, float in_y0, float in_x1, float in_y1 );
    6969
    70 unsigned _System LibMain( unsigned hmod, unsigned termination )
     70unsigned EXPENTRY LibMain( unsigned hmod, unsigned termination )
    7171{
    7272    if ( termination ) {
     
    7979
    8080
    81 extern "C" LuDocument * _System createObject()
     81extern "C" LuDocument * EXPENTRY createObject()
    8282{
    8383    return new LuJpegDocument;
    8484}
    8585
    86 extern "C" char * _System getSupportedExtensions()
     86extern "C" char * EXPENTRY getSupportedExtensions()
    8787{
    8888    return "JPG;JPEG;JPE";
    8989}
    9090
    91 LuCheckData   lcd = { 0, 2, (void *)"\xff\xd8" };
    92 LuCheckStruct lcs = { 1, &lcd };
    93 
    94 extern "C" LuCheckStruct * _System getCheckStruct()
    95 {
    96         return &lcs;
    97 }
    98 
    99 
    100 extern "C" char * _System getDescription()
     91static LuSignature      lsig = { 0, 0, 2, (void *)"\xff\xd8" };
     92static LuSignatureList  lsl  = { 1, &lsig };
     93static LuSignatureCheck lsc  = { 1, &lsl };
     94
     95extern "C" LuSignatureCheck * EXPENTRY getSignatureCheck()
     96{
     97        return &lsc;
     98}
     99
     100
     101extern "C" char * EXPENTRY getDescription()
    101102{
    102103    return "Jpeg plugin, based on IJG JPEG Library v6b";
  • trunk/Lucide/SOURCE/plugins/lujpeg/makefile

    r215 r217  
    4040export getSupportedExtensions
    4141export getDescription
    42 export getCheckStruct
     42export getSignatureCheck
    4343| tmpmake.lnk >NUL
    4444    wlink @tmpmake.lnk
  • trunk/Lucide/SOURCE/plugins/lupoppler/lupoppler.cpp

    r215 r217  
    3636#define LuPopplerDocument_Class_Source
    3737
    38 #include "lupoppler.xih"
     38#define INCL_DOS
     39#include <os2.h>
     40
     41#include <vector>
     42#include <time.h>
     43#include <uconv.h>
    3944
    4045#include <goo\GooString.h>
     
    5459#include <Link.h>
    5560
    56 #define INCL_DOS
    57 #include <os2.h>
    58 
    59 #include <vector>
    60 using namespace std;
    61 #include <time.h>
    62 #include <uconv.h>
     61#include "lupoppler.xih"
    6362#include "cpconv.h"
    6463
    65 typedef vector<LuRectangle> RectList;
    66 
    67 
    68 unsigned _System LibMain( unsigned hmod, unsigned termination )
     64typedef std::vector<LuRectangle> RectList;
     65
     66
     67unsigned EXPENTRY LibMain( unsigned hmod, unsigned termination )
    6968{
    7069    if ( termination ) {
     
    7776
    7877
    79 extern "C" LuDocument * _System createObject()
     78extern "C" LuDocument * EXPENTRY createObject()
    8079{
    8180    return new LuPopplerDocument;
    8281}
    8382
    84 extern "C" char * _System getSupportedExtensions()
     83extern "C" char * EXPENTRY getSupportedExtensions()
    8584{
    8685    return "PDF";
    8786}
    8887
    89 LuCheckData   lcd = { 0, 5, (void *)"%PDF-" };
    90 LuCheckStruct lcs = { 1, &lcd };
    91 
    92 extern "C" LuCheckStruct * _System getCheckStruct()
    93 {
    94         return &lcs;
    95 }
    96 
    97 extern "C" char * _System getDescription()
     88static LuSignature      lsig = { 0, 0, 5, (void *)"%PDF-" };
     89static LuSignatureList  lsl  = { 1, &lsig };
     90static LuSignatureCheck lsc  = { 1, &lsl };
     91
     92extern "C" LuSignatureCheck * EXPENTRY getSignatureCheck()
     93{
     94        return &lsc;
     95}
     96
     97extern "C" char * EXPENTRY getDescription()
    9898{
    9999    return "PDF plugin, based on poppler library v0.5.4";
  • trunk/Lucide/SOURCE/plugins/lupoppler/makefile

    r215 r217  
    4141export getSupportedExtensions
    4242export getDescription
    43 export getCheckStruct
     43export getSignatureCheck
    4444| tmpmake.lnk >NUL
    4545    wlink @tmpmake.lnk
Note: See TracChangeset for help on using the changeset viewer.