[Winpt-commits] r261 - trunk/PTD

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Sat Sep 30 12:24:23 CEST 2006


Author: twoaday
Date: 2006-09-30 12:24:23 +0200 (Sat, 30 Sep 2006)
New Revision: 261

Modified:
   trunk/PTD/ChangeLog
   trunk/PTD/PTD.cpp
   trunk/PTD/wptDNSKeys.cpp
   trunk/PTD/wptDNSKeys.h
   trunk/PTD/wptJPG.cpp
   trunk/PTD/wptJPG.h
Log:


Modified: trunk/PTD/ChangeLog
===================================================================
--- trunk/PTD/ChangeLog	2006-08-16 10:01:30 UTC (rev 260)
+++ trunk/PTD/ChangeLog	2006-09-30 10:24:23 UTC (rev 261)
@@ -1,3 +1,8 @@
+2006-08-30  Timo Schulz  <twoaday at freakmail.de>
+
+	* wptJPG.cpp (load): Improved error checking.
+	(loadPictureData): Cleanups.
+	
 2006-07-30  Timo Schulz  <ts at g10code.de>
 	
 	* wptDNSKeys.h: New.

Modified: trunk/PTD/PTD.cpp
===================================================================
--- trunk/PTD/PTD.cpp	2006-08-16 10:01:30 UTC (rev 260)
+++ trunk/PTD/PTD.cpp	2006-09-30 10:24:23 UTC (rev 261)
@@ -32,7 +32,7 @@
 HINSTANCE glob_hinst;
 
 /* We need a special section in the DLL for storing our shared data.
-   This shared data is required by the hook function becuase theat
+   This shared data is required by the hook function because that
    function is called in the context of the actual thread running the
    hook and thus we need a way to communicate the result of our hook
    function back to us.  We use a shared data segment for this. */

Modified: trunk/PTD/wptDNSKeys.cpp
===================================================================
--- trunk/PTD/wptDNSKeys.cpp	2006-08-16 10:01:30 UTC (rev 260)
+++ trunk/PTD/wptDNSKeys.cpp	2006-09-30 10:24:23 UTC (rev 261)
@@ -101,7 +101,7 @@
     while (uid && *uid != '@')
 	pka[pos++] = *uid++;
     uid++;
-    strcat (pka, "._pka."); pos += strlen (fmt);
+    strcat (pka, fmt); pos += strlen (fmt);
     while (uid && *uid && *uid != '>')
 	pka[pos++] = *uid++;
     return pka;
@@ -183,7 +183,9 @@
 {
     if (pka->fpr)
 	free (pka->fpr);
+    pka->fpr = NULL;
     if (pka->uri)
 	free (pka->uri);
+    pka->uri = NULL;
     free (pka);
 }

Modified: trunk/PTD/wptDNSKeys.h
===================================================================
--- trunk/PTD/wptDNSKeys.h	2006-08-16 10:01:30 UTC (rev 260)
+++ trunk/PTD/wptDNSKeys.h	2006-09-30 10:24:23 UTC (rev 261)
@@ -23,16 +23,16 @@
 #ifdef __cplusplus
 extern "C" {
 #endif
-    
+
 struct pka_info_s {
-    int ver;
-    char *fpr;
-    char *uri;
+    int  ver;	/* version */
+    char *fpr;	/* key fingerprint */
+    char *uri;	/* if != NULL URL to fetch the key. */
 };
 typedef struct pka_info_s *pka_info_t;
 
+int  dns_get_pka_record (const char *userid, pka_info_t *r_pka);
 void dns_free_pka_record (pka_info_t pka);
-int  dns_get_pka_record (const char *userid, pka_info_t *r_pka);
 
 #ifdef __cplusplus
 }

Modified: trunk/PTD/wptJPG.cpp
===================================================================
--- trunk/PTD/wptJPG.cpp	2006-08-16 10:01:30 UTC (rev 260)
+++ trunk/PTD/wptJPG.cpp	2006-09-30 10:24:23 UTC (rev 261)
@@ -1,6 +1,6 @@
-/* wptJPG.cpp : JPG picture class
- *	Copyright (C) 2001 Dr.Yovav Gad <Sources at SuperMain.com>
- *	Copyright (C) 2005 Timo Schulz
+/* wptJPG.cpp - Routines for showing JPG pictures
+ *	Copyright (C) 2001 Dr.Yovav Gad
+ *	Copyright (C) 2005, 2006 Timo Schulz
  *
  * This file is part of WinPT.
  *
@@ -21,12 +21,11 @@
 
 /*-----------------------------------------------------------------------------
  * Picture (Implementations) Version 1.00
- *
- * Routinges for showing JPG pictur files
- *
- * Author: Dr. Yovav Gad, EMail: Sources at SuperMain.com ,Web: www.SuperMain.com
+ * Author: Dr. Yovav Gad, EMail: Sources at SuperMain.com
+ * Web: www.SuperMain.com
  * 
- * This version uses a stripped down version of Picture.cpp and Picture.h.
+ * This version uses a stripped down and heavily modified version of 
+ * Picture.cpp and Picture.h.
  */
 #ifdef HAVE_CONFIG_H
 #include <config.h>
@@ -44,7 +43,7 @@
 #include "wptJPG.h"
 
 #define HIMETRIC_INCH	2540
-#define ERROR_TITLE	"CJPG Error"
+#define ERROR_TITLE	"WinPT - CJPG Error"
 
 #define out_of_core() do { \
 	MessageBox (NULL, "Can not allocate memory", ERROR_TITLE, MB_OK|MB_ICONSTOP); \
@@ -52,15 +51,17 @@
     } while (0)
 
 
+/* Constructor to create an empty JPG container. */
 CJPG::CJPG (void)
 {
     m_IPicture = NULL;
     m_Height = 0;
     m_Weight = 0;
-    m_Width = 0;
+    m_Width = 0;    
 }
 
 
+/* Deconstructor. Free all internal data. */
 CJPG::~CJPG (void)
 {
     if (m_IPicture != NULL)
@@ -77,10 +78,10 @@
     if (m_IPicture != NULL) {
 	m_IPicture->Release();
 	m_IPicture = NULL;
-	m_Height = 0;
-	m_Weight = 0;
-	m_Width = 0;	
     }
+    m_Height = 0;
+    m_Weight = 0;
+    m_Width = 0;
 }
 
 
@@ -88,52 +89,56 @@
 BOOL 
 CJPG::load (LPCSTR sFilePathName)
 {
-    BOOL bResult = FALSE;
-    FILE * f;
-    int nSize = 0;
+    struct stat st;
+    FILE *fp;    
+    BYTE *pBuffer;
+    int n;
 
     if (m_IPicture != NULL) 
 	freePictureData ();
 
-    f = fopen (sFilePathName, "rb");
-    if (f) {
-	struct stat st;
-	fstat (fileno (f), &st);
-	nSize = st.st_size;
-	BYTE *pBuffer = new BYTE[nSize];
-	if  (!pBuffer) {
-	    fclose (f);
-	    out_of_core ();
-	}
-	memset (pBuffer, 0, nSize);
-	if (fread(pBuffer, 1, nSize, f) > 0) {
-	    if (loadPictureData (pBuffer, nSize))
-		bResult = TRUE;
-	}
-	fclose (f);
-	delete [] pBuffer;
-    }
-    else {
+    fp = fopen (sFilePathName, "rb");
+    if (!fp) {
 	MessageBox (NULL, strerror (errno), ERROR_TITLE, MB_OK|MB_ICONSTOP);
-	bResult = FALSE;
+	return FALSE;
     }
 
-    m_Weight = nSize; /* Update Picture Size Info... */
+    /* avoid to load empty JPG files and make sure we still can
+       access the file handle. */
+    if (fstat (fileno (fp), &st) || st.st_size == 0) {
+	fclose (fp);
+	return FALSE;
+    }
+    pBuffer = new BYTE[st.st_size];
+    if  (!pBuffer)
+	out_of_core ();
+    memset (pBuffer, 0, st.st_size);
+    n = fread (pBuffer, 1, st.st_size, fp);
+    fclose (fp);
 
-    if(m_IPicture != NULL) {
-	m_IPicture->get_Height (&m_Height);
-	m_IPicture->get_Width (&m_Width);
-	/* Calculate Its Size On a "Standard" (96 DPI) Device Context */
-	m_Height = MulDiv (m_Height, 96, HIMETRIC_INCH);
-	m_Width  = MulDiv (m_Width,  96, HIMETRIC_INCH);	
+    /* not the entire file were read in, so abort here. */
+    if (n != st.st_size) {
+	delete []pBuffer;
+	return FALSE;
     }
-    else {
-	/* Picture data is not a known picture type */
+    if (!loadPictureData (pBuffer, st.st_size)) {
+	delete []pBuffer;
+	return FALSE;
+    }
+    delete [] pBuffer;
+
+    m_Weight = st.st_size; /* Update Picture Size Info... */
+    if (m_IPicture == NULL) {
 	m_Height = 0;
 	m_Width = 0;
-	bResult = FALSE;	
+	return FALSE;
     }
-    return bResult;
+    m_IPicture->get_Height (&m_Height);
+    m_IPicture->get_Width (&m_Width);
+    /* Calculate Its Size On a "Standard" (96 DPI) Device Context */
+    m_Height = MulDiv (m_Height, 96, HIMETRIC_INCH);
+    m_Width  = MulDiv (m_Width,  96, HIMETRIC_INCH);	
+    return TRUE;
 }
 
 
@@ -144,16 +149,14 @@
 CJPG::loadPictureData (BYTE *pBuffer, int nSize)
 
 {
+    HGLOBAL hGlobal;    
+    IStream* pStream = NULL;
+    void* pData;
     BOOL bResult = FALSE;
-    HGLOBAL hGlobal;
-    void* pData;
-    IStream* pStream = NULL;
     
     hGlobal = GlobalAlloc (GMEM_MOVEABLE, nSize);
-    if (hGlobal == NULL) {
+    if (hGlobal == NULL)
 	out_of_core ();
-	return FALSE;
-    }
 
     pData = GlobalLock (hGlobal);
     memcpy (pData, pBuffer, nSize);
@@ -163,11 +166,9 @@
 	HRESULT hr;
 	hr = OleLoadPicture (pStream, nSize, FALSE, IID_IPicture, 
 			     (LPVOID *)&m_IPicture);
-	if (hr == E_NOINTERFACE) {
+	if (hr == E_NOINTERFACE)
 	    MessageBox (NULL, "IPicture interface is not supported", 
 			ERROR_TITLE, MB_OK|MB_ICONSTOP);
-	    return FALSE;
-	}
 	else { /* S_OK */
 	    pStream->Release ();
 	    pStream = NULL;
@@ -176,7 +177,7 @@
     }
 
     GlobalFree (hGlobal);
-    return (bResult);
+    return bResult;
 }
 
 
@@ -187,9 +188,9 @@
 
 {
     RECT drawRect;
+    HRESULT hr = 0;
     long width  = 0;
-    long height = 0;
-    HRESULT hrP = 0;
+    long height = 0;    
 
     if (pDC == NULL || m_IPicture == NULL) 
 	return FALSE;
@@ -209,7 +210,7 @@
     drawRect.right = magnifyX;
     drawRect.bottom = magnifyY;
 
-    hrP = m_IPicture->Render (pDC,
+    hr = m_IPicture->Render (pDC,
                       leftTop->x,               // Left
                       leftTop->y,               // Top
                       widthHeight->x +magnifyX, // Width
@@ -220,10 +221,11 @@
                       -height,
                       &drawRect);
 
-    if (SUCCEEDED (hrP)) 
-	return (TRUE);
+    if (SUCCEEDED (hr)) 
+	return TRUE;
 
-    out_of_core ();}
+    return FALSE;
+}
 
 
 /* Get the original picture pixel size (ignore what current DC is using)
@@ -235,7 +237,7 @@
     if(pDC == NULL || m_IPicture == NULL) { 
 	m_Height = 0; 
 	m_Width = 0; 
-	return (FALSE); 
+	return FALSE;
     }
 
     m_IPicture->get_Height (&m_Height);
@@ -248,7 +250,7 @@
     m_Height = MulDiv (m_Height, CurrentDPI_Y, HIMETRIC_INCH);
     m_Width  = MulDiv (m_Width,  CurrentDPI_X, HIMETRIC_INCH);
 
-    return (TRUE);
+    return TRUE;
 }
 
 /* Return height of the current image. */

Modified: trunk/PTD/wptJPG.h
===================================================================
--- trunk/PTD/wptJPG.h	2006-08-16 10:01:30 UTC (rev 260)
+++ trunk/PTD/wptJPG.h	2006-09-30 10:24:23 UTC (rev 261)
@@ -25,7 +25,7 @@
 {
 private:
     LONG m_Height; /* height (in pixels ignore what current device context uses) */
-    LONG m_Weight; /* size of the image object in bytes (file OR resource) */
+    LONG m_Weight; /* size of the image object in bytes */
     LONG m_Width;  /* width (in pixels ignore what current device context uses) */
 
     IPicture* m_IPicture; /* Same As LPPICTURE (typedef IPicture __RPC_FAR *LPPICTURE)*/



More information about the Winpt-commits mailing list