Skip to content

Commit

Permalink
fix for the NULL in DG_CONTROL/DAT_IDENTITY/MSG_GET
Browse files Browse the repository at this point in the history
  • Loading branch information
mlmcl62 committed Jan 17, 2018
1 parent 0d6daf0 commit 66f2912
Show file tree
Hide file tree
Showing 24 changed files with 196 additions and 65 deletions.
15 changes: 15 additions & 0 deletions Releases/dsm_020402/README.txt
@@ -0,0 +1,15 @@
This is release 2.4.2 of the TWAIN Data Source Manager.

Releases accompany updates to the TWAIN Specification, even when there are no
actual code changes in the DSM. We do this to reduce confusion even though all
DSMs must interoperate with any application or data source, regardless of their
supported TWAIN Protocol.

Release Notes:

- The Windows DMS sends a NULL for the origin on the DG_CONTROL / DAT_IDENTITY
/ MSG_GET call. Linux and Mac send the application identity. This behavior
can be overridden using the TWAINDSM_USEAPPID environment variable, where a
value of 1 uses the application id, and 0 sends a NULL. This fix does not
change the default behavior for Windows, but addresses crashes on Mac.

Binary file added Releases/dsm_020402/macosx/twaindsm-2.4.2.dmg.gz
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
10 changes: 10 additions & 0 deletions Releases/dsm_020402/ubuntu_0804/twaindsm_2.4.2-1.dsc
@@ -0,0 +1,10 @@
Format: 1.0
Source: twaindsm
Binary: twaindsm
Architecture: any
Version: 2.4.2-1
Maintainer: TWAIN Working Group <twaindsm@twain.org>
Standards-Version: 3.6.2
Build-Depends: cmake (>= 2.4), debhelper (>= 4.0.0)
Files:
8f9c9b9a13a3225c6e5828a0561a826f 396622 twaindsm_2.4.2-1.tar.gz
20 changes: 20 additions & 0 deletions Releases/dsm_020402/ubuntu_0804/twaindsm_2.4.2-1_amd64.changes
@@ -0,0 +1,20 @@
Format: 1.7
Date: Wed, 17 Jan 2018 10:47:02 -0500
Source: twaindsm
Binary: twaindsm
Architecture: source amd64
Version: 2.4.2-1
Distribution: unstable
Urgency: low
Maintainer: TWAIN Working Group <twaindsm@twain.org>
Changed-By: TWAIN Working Group <twaindsm@twain.org>
Description:
twaindsm - TWAIN Data Source Manager
Changes:
twaindsm (2.4.2-1) unstable; urgency=low
.
* use _pAppId for DAT_IDENTITY/MSG_GET for Linux and Mac
Files:
5a372f0a33c3aa7209531eafd65d6c0d 284 libdevel optional twaindsm_2.4.2-1.dsc
8f9c9b9a13a3225c6e5828a0561a826f 396622 libdevel optional twaindsm_2.4.2-1.tar.gz
ae0019053b033d7309eabf126011bb05 54572 libdevel optional twaindsm_2.4.2-1_amd64.deb
Binary file not shown.
20 changes: 20 additions & 0 deletions Releases/dsm_020402/ubuntu_0804/twaindsm_2.4.2-1_i386.changes
@@ -0,0 +1,20 @@
Format: 1.7
Date: Wed, 17 Jan 2018 10:47:02 -0500
Source: twaindsm
Binary: twaindsm
Architecture: source i386
Version: 2.4.2-1
Distribution: unstable
Urgency: low
Maintainer: TWAIN Working Group <twaindsm@twain.org>
Changed-By: TWAIN Working Group <twaindsm@twain.org>
Description:
twaindsm - TWAIN Data Source Manager
Changes:
twaindsm (2.4.2-1) unstable; urgency=low
.
* use _pAppId for DAT_IDENTITY/MSG_GET for Linux and Mac
Files:
6fba684ffcbf54528530143f0b065bcb 284 libdevel optional twaindsm_2.4.2-1.dsc
066d7ccebcfe86325a05109b4d5fe0b7 395198 libdevel optional twaindsm_2.4.2-1.tar.gz
345f7c99863076066be45479c098932d 53214 libdevel optional twaindsm_2.4.2-1_i386.deb
Binary file not shown.
Binary file added Releases/dsm_020402/windows/32/TWAINDSM.dll
Binary file not shown.
Binary file added Releases/dsm_020402/windows/64/TWAINDSM.dll
Binary file not shown.
65 changes: 37 additions & 28 deletions TWAIN DSM Linux Build Procedure.rtf

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions TWAIN_DSM/Info.plist
Expand Up @@ -17,11 +17,11 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>2.4.1</string>
<string>2.4.2</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>2.4.1</string>
<string>2.4.2</string>
<key>NSPrincipalClass</key>
<string></string>
</dict>
Expand Down
6 changes: 6 additions & 0 deletions TWAIN_DSM/debian/changelog
@@ -1,3 +1,9 @@
twaindsm (2.4.2-1) unstable; urgency=low

* use _pAppId for DAT_IDENTITY/MSG_GET for Linux and Mac

-- TWAIN Working Group <twaindsm@twain.org> Wed, 17 Jan 2018 10:47:02 -0500

twaindsm (2.4.0-1) unstable; urgency=low

* macOS support and Linux 64-bit fix
Expand Down
2 changes: 1 addition & 1 deletion TWAIN_DSM/src/CMakeLists.txt
Expand Up @@ -32,7 +32,7 @@ PROJECT(twaindsm)
#project version
SET(${PROJECT_NAME}_MAJOR_VERSION 2)
SET(${PROJECT_NAME}_MINOR_VERSION 4)
SET(${PROJECT_NAME}_PATCH_LEVEL 0)
SET(${PROJECT_NAME}_PATCH_LEVEL 2)

#build a shared library
ADD_LIBRARY(twaindsm SHARED dsm.cpp apps.cpp log.cpp)
Expand Down
99 changes: 73 additions & 26 deletions TWAIN_DSM/src/apps.cpp
Expand Up @@ -1452,6 +1452,7 @@ TW_INT16 CTwnDsmAppsImpl::LoadDS(TW_IDENTITY *_pAppId,
DS_INFO *pDSInfo;
bool hook;
TW_IDENTITY_LINUX64SAFE twidentitylinux64safe;
char szUseAppid[8];

// Validate...
if ( 0 == _pPath )
Expand Down Expand Up @@ -1583,51 +1584,97 @@ TW_INT16 CTwnDsmAppsImpl::LoadDS(TW_IDENTITY *_pAppId,
if (pDSInfo->DS_Entry == 0)
{
#if (TWNDSM_CMP == TWNDSM_CMP_VISUALCPP)
// The WIATwain.ds does not have an entry point
if(0 != strstr(_pPath, "wiatwain.ds"))
{
kLOG((kLOGERR,"We're deliberately skipping this file: %s",_pPath));
}
else
{
pDSInfo->DS_Entry = (DSENTRYPROC)GetProcAddress((HMODULE)pDSInfo->pHandle, MAKEINTRESOURCE(1));
if (pDSInfo->DS_Entry == 0)
{
kLOG((kLOGINFO,"Could not find Entry 1 in DS: %s",_pPath));
}
}
// The WIATwain.ds does not have an entry point
if (0 != strstr(_pPath, "wiatwain.ds"))
{
kLOG((kLOGERR, "We're deliberately skipping this file: %s", _pPath));
}
else
{
pDSInfo->DS_Entry = (DSENTRYPROC)GetProcAddress((HMODULE)pDSInfo->pHandle, MAKEINTRESOURCE(1));

if (pDSInfo->DS_Entry == 0)
{
kLOG((kLOGINFO, "Could not find Entry 1 in DS: %s", _pPath));
}
}
#else
kLOG((kLOGERR,"Could not find DS_Entry function in DS: %s",_pPath));
kLOG((kLOGERR, "Could not find DS_Entry function in DS: %s", _pPath));
#endif
if (pDSInfo->DS_Entry == 0)
{
(void)UNLOADLIBRARY(pDSInfo->pHandle,false,0);
pDSInfo->pHandle = NULL;
AppSetConditionCode(_pAppId,TWCC_OPERATIONERROR);
return TWRC_FAILURE;
}
if (pDSInfo->DS_Entry == 0)
{
(void)UNLOADLIBRARY(pDSInfo->pHandle, false, 0);
pDSInfo->pHandle = NULL;
AppSetConditionCode(_pAppId, TWCC_OPERATIONERROR);
return TWRC_FAILURE;
}
}

// Allllrighty then! So the original TWAIN_32.DLL passes in
// a value of NULL for the origin. This is not documented
// anywhere in the TWAIN Spec. It was decided to maintain this
// behavior in TWAINDSM.DLL. All fine and well for Window and
// Linux. But Mac had it's own DSM, and it didn't pass in a
// NULL. So now we have a conundrum.
//
// I'm adding an event variable so that an application can
// override stuff, but the default behavior is going to be:
// Windows - NULL
// Linux - _pAppId
// Mac - _pAppId
memset(&szUseAppid, 0, sizeof(szUseAppid));
SGETENV(szUseAppid, NCHARS(szUseAppid), "TWAINDSM_USEAPPID");
// No data received, set the default based on the platform...
if (szUseAppid[0] != 0)
{
#if (TWNDSM_OS == TWNDSM_OS_WINDOWS)
szUseAppid[0] = '0'; // Windows is NULL
#elif (TWNDSM_OS == TWNDSM_OS_LINUX)
szUseAppid[0] = '1'; // Linux is _pAppId
#elif (TWNDSM_OS == TWNDSM_OS_MACOSX)
szUseAppid[0] = '1'; // Linux is _pAppId
#else
Unsupported...
#endif
}
// Otherwise, force the value to be '0' or '1'...
else if (szUseAppid[0] != '0')
{
szUseAppid[0] = '1';
}

// Report success and squirrel away the index...
kLOG((kLOGINFO,"Loaded library: %s",_pPath));
kLOG((kLOGINFO, "Loaded library: %s (TWAINDSM_USEAPPID:%c)", _pPath, szUseAppid[0]));
pDSInfo->Identity.Id = (TWIDDEST_T)_DsId;

// Get the source to fill in the identity structure
// This operation should never fail on any DS
//
// We need the NULL to be backwards compatible with the
// older DSM. This is the only way a driver can tell if
// it's being talked to directly by the DSM instead of
// by the application (with the DSM as a passthru)...
// by the application (with the DSM as a passthru).
//
// Okay, this is where we make the actual call. I left
// the original comments in place...
memset(&twidentitylinux64safe, 0, sizeof(twidentitylinux64safe));
twidentitylinux64safe.twidentity.Id = (TWIDDEST_T)_DsId;
result = pDSInfo->DS_Entry(NULL,DG_CONTROL,DAT_IDENTITY,MSG_GET,(TW_MEMREF)&twidentitylinux64safe);
if (szUseAppid[0] == '1')
{
// this is what the spec calls for
result = pDSInfo->DS_Entry(_pAppId, DG_CONTROL, DAT_IDENTITY, MSG_GET, (TW_MEMREF)&twidentitylinux64safe);
}
else
{
// this is out of spec, but we need it for Windows
result = pDSInfo->DS_Entry(NULL, DG_CONTROL, DAT_IDENTITY, MSG_GET, (TW_MEMREF)&twidentitylinux64safe);
}
if (result != TWRC_SUCCESS)
{
(void)UNLOADLIBRARY(pDSInfo->pHandle,false,0);
pDSInfo->pHandle = NULL;
pDSInfo->DS_Entry = NULL;
kLOG((kLOGINFO,"DG_CONTROL,DAT_IDENTITY,MSG_GET failed"));
kLOG((kLOGINFO, "DG_CONTROL,DAT_IDENTITY,MSG_GET failed"));
AppSetConditionCode(_pAppId,TWCC_OPERATIONERROR);
return TWRC_FAILURE;
}
Expand Down
4 changes: 2 additions & 2 deletions TWAIN_DSM/src/resource.h
Expand Up @@ -14,8 +14,8 @@
//
#define TWNDSM_ORGANIZATION "TWAIN Working Group"
#define TWNDSM_DESCRIPTION "TWAIN " TWNDSM_OS_BIT_STR " Source Manager (Image Acquisition Interface)"
#define TWNDSM_VERSION_NUM 2, 4, 1, 0
#define TWNDSM_VERSION_STR "2, 4, 1, 0"
#define TWNDSM_VERSION_NUM 2, 4, 2, 0
#define TWNDSM_VERSION_STR "2, 4, 2, 0"
#define ID_LST_SOURCES 10
#define IDC_STATIC 11
#define IDD_DLG_SOURCE 101
Expand Down
4 changes: 3 additions & 1 deletion TWAIN_DSM/twaindsm.spec
@@ -1,6 +1,6 @@
Summary: TWAIN Data Source Manager
Name: twaindsm
Version: 2.3.1
Version: 2.4.2
Release: 1
Vendor: TWAIN Working Group
License: LGPL
Expand Down Expand Up @@ -44,6 +44,8 @@ rm -rf $RPM_BUILD_ROOT
%doc doc/*

%changelog
* Wed Jan 17 2018 TWAIN Working Group <twaindsm@twain.org>
- use _pAppId for DAT_IDENTITY/MSG_GET for Linux and Mac
* Thu May 22 2014 TWAIN Working Group <twaindsm@twain.org>
- added support for 64-bit Linux
* Mon Mar 5 2012 TWAIN Working Group <twaindsm@twain.org>
Expand Down
8 changes: 5 additions & 3 deletions TWAIN_DSM/visual_studio/TWAIN_DSM_VS2015.sln
@@ -1,7 +1,9 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2015
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TWAINDSM", "TWAIN_DSM_VS2015.vcxproj", "{5F73EBC7-6A0E-4CBF-A37C-CB167E4CC379}"
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TWAIN_DSM_VS2015", "TWAIN_DSM_VS2015.vcxproj", "{5F73EBC7-6A0E-4CBF-A37C-CB167E4CC379}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
4 changes: 2 additions & 2 deletions mkdsm.sh
Expand Up @@ -31,8 +31,8 @@
#
export DSMMAJOR=2
export DSMMINOR=4
export DSMBUILD=1
export DSMREASON="fix signing and version for macOS"
export DSMBUILD=2
export DSMREASON="use _pAppId for DAT_IDENTITY/MSG_GET for Linux and Mac"

# Don't touch these lines...
export DSMBUILDER="good"
Expand Down

0 comments on commit 66f2912

Please sign in to comment.