[svn] GpgOL - r322 - in trunk: doc src

svn author wk cvs at cvs.gnupg.org
Fri Nov 27 18:06:07 CET 2009


Author: wk
Date: 2009-11-27 18:06:07 +0100 (Fri, 27 Nov 2009)
New Revision: 322

Modified:
   trunk/doc/gpgol.texi
   trunk/src/ChangeLog
   trunk/src/common.h
   trunk/src/eventsink.h
   trunk/src/ext-commands.cpp
   trunk/src/inspectors.cpp
   trunk/src/inspectors.h
   trunk/src/main.c
   trunk/src/message-events.cpp
   trunk/src/oomhelp.h
Log:
It seems that I solved the probelm with sending message in OL2007.
The solution was to find the corresponding inspector via the window
handles.


Modified: trunk/src/ChangeLog
===================================================================
--- trunk/src/ChangeLog	2009-11-20 12:10:42 UTC (rev 321)
+++ trunk/src/ChangeLog	2009-11-27 17:06:07 UTC (rev 322)
@@ -1,3 +1,20 @@
+2009-11-27  Werner Koch  <wk at g10code.com>
+
+	* message-events.cpp (get_crypto_flags): Replace EECB arg by HWND.
+	(OnRead): Pass HWND to get_crypto_flags. Change all callers.
+	(get_inspector): Remove.
+	(get_crypto_flags, OnReadComplete): Use get_inspector_from_hwnd.
+
+	* oomhelp.h (IID_IOleWindow): Define.
+	* inspectors.cpp (find_ole_window): New.
+	(struct inspector_info_s): Add field HWND.
+	(register_inspector): Store it..
+	(get_inspector_from_hwnd): New.
+
+	* common.h (DBG_OOM_EXTRA): New.
+	* main.c (read_options): Read new debug flag.
+	* eventsink.h (debug_oom_extra): Use it.
+
 2009-11-03  Werner Koch  <wk at g10code.com>
 
 	* inspectors.cpp (deregister_inspector): Delete the buttons.

Modified: trunk/doc/gpgol.texi
===================================================================
--- trunk/doc/gpgol.texi	2009-11-20 12:10:42 UTC (rev 321)
+++ trunk/doc/gpgol.texi	2009-11-27 17:06:07 UTC (rev 322)
@@ -310,7 +310,9 @@
 @item 256 (0x0100) (mime-data)
 Print data lines while parsing MIME.
 @item 512 (0x0200) (oom)
-Verbose object allocation reporting.
+Outlook Object Model reporting.
+ at item 1024 (0x0400) (oom-extra)
+Verbose OOM allocation and advising reporting.
 @end table
 You may use the regular C-syntax for entering the value.  As an
 alternative you may use the names of the flags, separated by space or

Modified: trunk/src/common.h
===================================================================
--- trunk/src/common.h	2009-11-20 12:10:42 UTC (rev 321)
+++ trunk/src/common.h	2009-11-27 17:06:07 UTC (rev 322)
@@ -170,6 +170,7 @@
 #define DBG_MIME_PARSER    (1<<7)
 #define DBG_MIME_DATA      (1<<8)
 #define DBG_OOM            (1<<9)
+#define DBG_OOM_EXTRA      (1<<10)
 
 /* Macros to used in conditionals to enable debug output.  */
 #define debug_commands    (opt.enable_debug & DBG_COMMANDS)

Modified: trunk/src/eventsink.h
===================================================================
--- trunk/src/eventsink.h	2009-11-20 12:10:42 UTC (rev 321)
+++ trunk/src/eventsink.h	2009-11-27 17:06:07 UTC (rev 322)
@@ -25,6 +25,7 @@
 #define EVENTSINK_H
 
 #define debug_oom        (opt.enable_debug & DBG_OOM)
+#define debug_oom_extra  (opt.enable_debug & DBG_OOM_EXTRA)
 
 
 #define BEGIN_EVENT_SINK(subcls,parentcls)                               \
@@ -43,7 +44,7 @@
   inline STDMETHODIMP_(ULONG) AddRef (void)                              \
     {                                                                    \
       ++m_ref;                                                           \
-      if (debug_oom)                                                     \
+      if (debug_oom_extra)                                               \
         log_debug ("%s:" #subcls ":%s: m_ref now %lu",                   \
                    SRCNAME,__func__, m_ref);                             \
       return m_ref;                                                      \
@@ -51,7 +52,7 @@
   inline STDMETHODIMP_(ULONG) Release (void)                             \
     {                                                                    \
       ULONG count = --m_ref;                                             \
-      if (debug_oom)                                                     \
+      if (debug_oom_extra)                                               \
         log_debug ("%s:" #subcls ":%s: mref now %lu",                    \
                    SRCNAME,__func__,count);                              \
       if (!count)                                                        \
@@ -200,7 +201,7 @@
   HRESULT hr;                                                            \
   subcls *sink;                                                          \
                                                                          \
-  if (debug_oom)                                                         \
+  if (debug_oom_extra)                                                   \
     log_debug ("%s:%s:%s: Called", SRCNAME, #subcls, __func__);          \
   hr = obj->QueryInterface (iidcls, (void**)&sink);                      \
   if (hr != S_OK || !sink)                                               \
@@ -211,13 +212,13 @@
     }                                                                    \
   if (sink->m_pCP)                                                       \
     {                                                                    \
-      if (debug_oom)                                                     \
+      if (debug_oom_extra)                                               \
         log_debug ("%s:%s:%s: Unadvising", SRCNAME, #subcls, __func__);  \
       hr = sink->m_pCP->Unadvise (sink->m_cookie);                       \
       if (hr != S_OK)                                                    \
         log_error ("%s:%s:%s: Unadvice failed: hr=%#lx",                 \
                    SRCNAME, #subcls, __func__, hr);                      \
-      if (debug_oom)                                                     \
+      if (debug_oom_extra)                                               \
         log_debug ("%s:%s:%s: Releasing connt point",                    \
                    SRCNAME, #subcls, __func__);                          \
       sink->m_pCP->Release ();                                           \
@@ -225,7 +226,7 @@
     }                                                                    \
   if (sink->m_object)                                                    \
     {                                                                    \
-      if (debug_oom)                                                     \
+      if (debug_oom_extra)                                               \
         log_debug ("%s:%s:%s: Releasing actual object",                  \
                    SRCNAME, #subcls, __func__);                          \
       sink->m_object->Release ();                                        \

Modified: trunk/src/ext-commands.cpp
===================================================================
--- trunk/src/ext-commands.cpp	2009-11-20 12:10:42 UTC (rev 321)
+++ trunk/src/ext-commands.cpp	2009-11-27 17:06:07 UTC (rev 322)
@@ -116,7 +116,13 @@
   if (obj)
     {
       /* This should be MailItem; use the getInspector method.  */
-      inspector = get_oom_object (obj, "GetInspector");
+      //inspector = get_oom_object (obj, "GetInspector");
+      char *tmp = get_object_name (obj);
+      
+      log_debug ("%s:%s: object is at %p (%s)",
+                 SRCNAME, __func__, obj, tmp? tmp:"");
+      xfree (tmp);
+        
       obj->Release ();
     }
   return inspector;

Modified: trunk/src/inspectors.cpp
===================================================================
--- trunk/src/inspectors.cpp	2009-11-20 12:10:42 UTC (rev 321)
+++ trunk/src/inspectors.cpp	2009-11-27 17:06:07 UTC (rev 322)
@@ -134,6 +134,9 @@
   /* The inspector object.  */
   LPOOMINSPECTOR inspector;
 
+  /* The Window handle of the inspector.  */
+  HWND hwnd;
+
   /* A list of all the buttons.  */
   button_list_t buttons;
 
@@ -223,14 +226,45 @@
 }
 
 
+static HWND
+find_ole_window (LPOOMINSPECTOR inspector)
+{
+  HRESULT hr;
+  LPOLEWINDOW olewndw = NULL;
+  HWND hwnd = NULL;
+
+  hr = inspector->QueryInterface (IID_IOleWindow, (void**)&olewndw);
+  if (hr != S_OK || !olewndw)
+    {
+      log_error ("%s:%s: IOleWindow not found: hr=%#lx", SRCNAME, __func__, hr);
+      return NULL;
+    }
+
+  hr = olewndw->GetWindow (&hwnd);
+  if (hr != S_OK || !hwnd)
+    {
+      log_error ("%s:%s: IOleWindow->GetWindow failed: hr=%#lx", 
+                 SRCNAME, __func__, hr);
+      hwnd = NULL;
+    }
+  olewndw->Release ();
+  log_debug ("%s:%s: inspector %p has hwnd=%p",
+             SRCNAME, __func__, inspector, hwnd);
+  return hwnd;
+}
+
+
+
 /* Register the inspector object INSPECTOR with its event SINK.  */
 static void
 register_inspector (LPGPGOLINSPECTOREVENTS sink, LPOOMINSPECTOR inspector)
 {
   inspector_info_t item;
+  HWND hwnd;
 
   log_debug ("%s:%s: Called (sink=%p, inspector=%p)",
              SRCNAME, __func__, sink, inspector);
+  hwnd = find_ole_window (inspector);
   item = (inspector_info_t)xcalloc (1, sizeof *item);
   lock_all_inspectors ();
 
@@ -240,6 +274,8 @@
   inspector->AddRef ();
   item->inspector = inspector;
 
+  item->hwnd = hwnd;
+
   item->next = all_inspectors;
   all_inspectors = item;
 
@@ -379,6 +415,30 @@
 }
 
 
+/* Search through all objects and find the inspector which has a
+   the window handle HWND.  Returns NULL if not found.  */
+LPDISPATCH
+get_inspector_from_hwnd (HWND hwnd)
+{
+  LPDISPATCH result = NULL;
+  inspector_info_t iinfo;
+
+  lock_all_inspectors ();
+
+  for (iinfo = all_inspectors; iinfo; iinfo = iinfo->next)
+    if (iinfo->hwnd == hwnd)
+        {
+          result = iinfo->inspector;
+          if (result)
+            result->AddRef ();
+          break;
+        }
+  
+  unlock_all_inspectors ();
+  return result;
+}
+
+
 /* The method called by outlook for each new inspector.  Note that
    Outlook sometimes reuses Inspectro objects thus this event is not
    an indication for a newly opened Inspector.  */
@@ -424,9 +484,10 @@
 GpgolInspectorEvents::Activate (void)
 {
   LPOOMINSPECTOR inspector;
-  LPDISPATCH obj, obj2;
+  LPDISPATCH obj;
 
-  log_debug ("%s:%s: Called (this=%p)", SRCNAME, __func__, this);
+  log_debug ("%s:%s: Called (this=%p, inspector=%p)", 
+             SRCNAME, __func__, this, m_object);
   
   /* Note: It is easier to use the registered inspector object than to
      find the inspector object in the ALL_INSPECTORS list.  The
@@ -451,9 +512,9 @@
       obj = get_oom_object (inspector, "get_CurrentItem");
       if (obj)
         {
-          obj2 = install_GpgolItemEvents_sink (obj);
-          if (obj2)
-            obj2->Release ();
+          // LPDISPATCH obj2 = install_GpgolItemEvents_sink (obj);
+          // if (obj2)
+          //   obj2->Release ();
           obj->Release ();
         }
     }

Modified: trunk/src/inspectors.h
===================================================================
--- trunk/src/inspectors.h	2009-11-20 12:10:42 UTC (rev 321)
+++ trunk/src/inspectors.h	2009-11-27 17:06:07 UTC (rev 322)
@@ -134,6 +134,7 @@
                                   bool sign, bool encrypt);
 
 
+LPDISPATCH get_inspector_from_hwnd (HWND hwnd);
 
 
 #endif /*INSPECTORS_H*/

Modified: trunk/src/main.c
===================================================================
--- trunk/src/main.c	2009-11-20 12:10:42 UTC (rev 321)
+++ trunk/src/main.c	2009-11-27 17:06:07 UTC (rev 322)
@@ -561,6 +561,8 @@
             opt.enable_debug |= DBG_MIME_DATA;
           else if (!strcmp (p, "oom"))
             opt.enable_debug |= DBG_OOM;
+          else if (!strcmp (p, "oom-extra"))
+            opt.enable_debug |= DBG_OOM_EXTRA;
           else
             log_debug ("invalid debug flag `%s' ignored", p);
         }
@@ -574,7 +576,7 @@
     }
   xfree (val); val = NULL;
   if (opt.enable_debug)
-    log_debug ("enabled debug flags:%s%s%s%s%s%s%s%s%s\n",
+    log_debug ("enabled debug flags:%s%s%s%s%s%s%s%s%s%s\n",
                (opt.enable_debug & DBG_IOWORKER)? " ioworker":"",
                (opt.enable_debug & DBG_IOWORKER_EXTRA)? " ioworker-extra":"",
                (opt.enable_debug & DBG_FILTER)? " filter":"",
@@ -583,7 +585,8 @@
                (opt.enable_debug & DBG_COMMANDS)? " commands":"",
                (opt.enable_debug & DBG_MIME_PARSER)? " mime-parser":"",
                (opt.enable_debug & DBG_MIME_DATA)? " mime-data":"",
-               (opt.enable_debug & DBG_OOM)? " oom":""
+               (opt.enable_debug & DBG_OOM)? " oom":"",
+               (opt.enable_debug & DBG_OOM_EXTRA)? " oom-extra":""
                );
 
 

Modified: trunk/src/message-events.cpp
===================================================================
--- trunk/src/message-events.cpp	2009-11-20 12:10:42 UTC (rev 321)
+++ trunk/src/message-events.cpp	2009-11-27 17:06:07 UTC (rev 322)
@@ -99,33 +99,13 @@
 }
 
 
-/* Return the inspector the the current Mailitem.  If the inspector
-   does not exists, an inspector object is created (but not
-   immediatley shown).  */
-static LPDISPATCH
-get_inspector (LPEXCHEXTCALLBACK eecb)
-{
-  LPDISPATCH obj;
-  LPDISPATCH inspector = NULL;
-  
-  obj = get_eecb_object (eecb);
-  if (obj)
-    {
-      /* This should be MailItem; use the getInspector method.  */
-      inspector = get_oom_object (obj, "GetInspector");
-      obj->Release ();
-    }
-  return inspector;
-}
-
-
 static int
-get_crypto_flags (LPEXCHEXTCALLBACK eecb, bool *r_sign, bool *r_encrypt)
+get_crypto_flags (HWND hwnd, bool *r_sign, bool *r_encrypt)
 {
   LPDISPATCH inspector;
   int rc;
 
-  inspector = get_inspector (eecb);
+  inspector = get_inspector_from_hwnd (hwnd);
   if (!inspector)
     {
       log_error ("%s:%s: inspector not found", SRCNAME, __func__);
@@ -223,7 +203,7 @@
                    SRCNAME, __func__, hr);
       else
         {
-          LPDISPATCH inspector = get_inspector (eecb);
+          LPDISPATCH inspector = get_inspector_from_hwnd (hwnd);
           message_display_handler (message, inspector, hwnd);
           if (inspector)
             inspector->Release ();
@@ -246,48 +226,48 @@
 GpgolMessageEvents::OnWrite (LPEXCHEXTCALLBACK eecb)
 {
   LPDISPATCH obj;
-  HWND hWnd = NULL;
+  HWND hwnd = NULL;
   bool sign, encrypt, need_crypto;
   int bodyfmt;
 
-  log_debug ("%s:%s: received\n", SRCNAME, __func__);
+  if (FAILED (eecb->GetWindow (&hwnd)))
+    hwnd = NULL;
+  log_debug ("%s:%s: received (hwnd=%p)", SRCNAME, __func__, hwnd);
 
-  // need_crypto = (!get_crypto_flags (eecb, &sign, &encrypt)
-  //                && (sign || encrypt));
+  need_crypto = (!get_crypto_flags (hwnd, &sign, &encrypt)
+                 && (sign || encrypt));
     
-  // /* If we are going to encrypt, check that the BodyFormat is
-  //    something we support.  This helps avoiding surprise by sending
-  //    out unencrypted messages. */
-  // if (need_crypto && !opt.disable_gpgol)
-  //   {
-  //     obj = get_eecb_object (eecb);
-  //     if (!obj)
-  //       bodyfmt = -1;
-  //     else
-  //       {
-  //         bodyfmt = get_oom_int (obj, "BodyFormat");
-  //         obj->Release ();
-  //       }
+  /* If we are going to encrypt, check that the BodyFormat is
+     something we support.  This helps avoiding surprise by sending
+     out unencrypted messages. */
+  if (need_crypto && !opt.disable_gpgol)
+    {
+      obj = get_eecb_object (eecb);
+      if (!obj)
+        bodyfmt = -1;
+      else
+        {
+          bodyfmt = get_oom_int (obj, "BodyFormat");
+          obj->Release ();
+        }
 
-  //     if (bodyfmt == 1)
-  //       m_want_html = 0;
-  //     else if (bodyfmt == 2)
-  //       m_want_html = 1;
-  //     else
-  //       {
-  //         log_debug ("%s:%s: BodyFormat is %d", SRCNAME, __func__, bodyfmt);
-  //         if (FAILED(eecb->GetWindow (&hWnd)))
-  //           hWnd = NULL;
-  //         MessageBox (hWnd,
-  //                     _("Sorry, we can only encrypt plain text messages and\n"
-  //                     "no RTF messages. Please make sure that only the text\n"
-  //                     "format has been selected."),
-  //                     "GpgOL", MB_ICONERROR|MB_OK);
+      if (bodyfmt == 1)
+        m_want_html = 0;
+      else if (bodyfmt == 2)
+        m_want_html = 1;
+      else
+        {
+          log_debug ("%s:%s: BodyFormat is %d", SRCNAME, __func__, bodyfmt);
+          MessageBox (hwnd,
+                      _("Sorry, we can only encrypt plain text messages and\n"
+                      "no RTF messages. Please make sure that only the text\n"
+                      "format has been selected."),
+                      "GpgOL", MB_ICONERROR|MB_OK);
 
-  //         m_bWriteFailed = TRUE;	
-  //         return E_FAIL;
-  //       }
-  //   }
+          m_bWriteFailed = TRUE;	
+          return E_FAIL;
+        }
+    }
   
   
   return S_FALSE;
@@ -310,64 +290,63 @@
   HRESULT hrReturn = S_FALSE;
   LPMESSAGE msg = NULL;
   LPMDB pMDB = NULL;
-  HWND hWnd = NULL;
+  HWND hwnd = NULL;
   int rc;
 
-  log_debug ("%s:%s: received\n", SRCNAME, __func__);
+  if (FAILED(eecb->GetWindow (&hwnd)))
+    hwnd = NULL;
+  log_debug ("%s:%s: received (hwnd=%p)", SRCNAME, __func__, hwnd);
 
 
-  // if (flags & (EEME_FAILED|EEME_COMPLETE_FAILED))
-  //   return S_FALSE; /* We don't need to rollback anything in case
-  //                      other extensions flagged a failure. */
+  if (flags & (EEME_FAILED|EEME_COMPLETE_FAILED))
+    return S_FALSE; /* We don't need to rollback anything in case
+                       other extensions flagged a failure. */
 
-  // if (opt.disable_gpgol)
-  //   return S_FALSE;
+  if (opt.disable_gpgol)
+    return S_FALSE;
           
-  // if (!m_bOnSubmitActive) /* The user is just saving the message. */
-  //   return S_FALSE;
+  if (!m_bOnSubmitActive) /* The user is just saving the message. */
+    return S_FALSE;
   
-  // if (m_bWriteFailed)     /* Operation failed already. */
-  //   return S_FALSE;
+  if (m_bWriteFailed)     /* Operation failed already. */
+    return S_FALSE;
 
-  // /* Try to get the current window. */
-  // if (FAILED(eecb->GetWindow (&hWnd)))
-  //   hWnd = NULL;
 
-  // /* Get the object and call the encryption or signing function.  */
-  // HRESULT hr = eecb->GetObject (&pMDB, (LPMAPIPROP *)&msg);
-  // if (SUCCEEDED (hr))
-  //   {
-  //     protocol_t proto = PROTOCOL_UNKNOWN; /* Let the UI server select
-  //                                             the protocol.  */
-  //     bool sign, encrypt;
+  /* Get the object and call the encryption or signing function.  */
+  HRESULT hr = eecb->GetObject (&pMDB, (LPMAPIPROP *)&msg);
+  if (SUCCEEDED (hr))
+    {
+      protocol_t proto = PROTOCOL_UNKNOWN; /* Let the UI server select
+                                              the protocol.  */
+      bool sign, encrypt;
 
-  //     if (get_crypto_flags (eecb, &sign, &encrypt))
-  //       rc = -1;
-  //     else if (encrypt && sign)
-  //       rc = message_sign_encrypt (msg, proto, hWnd);
-  //     else if (encrypt && !sign)
-  //       rc = message_encrypt (msg, proto, hWnd);
-  //     else if (!encrypt && sign)
-  //       rc = message_sign (msg, proto, hWnd);
-  //     else
-  //       {
-  //         /* In case this is a forward message which is not to be
-  //            signed or encrypted we need to remove a possible body
-  //            attachment.  */
-  //         if (mapi_delete_gpgol_body_attachment (msg))
-  //           mapi_save_changes (msg, KEEP_OPEN_READWRITE);
-  //         rc = 0;
-  //       }
+      if (get_crypto_flags (hwnd, &sign, &encrypt))
+        rc = -1;
+      else if (encrypt && sign)
+        rc = message_sign_encrypt (msg, proto, hwnd);
+      else if (encrypt && !sign)
+        rc = message_encrypt (msg, proto, hwnd);
+      else if (!encrypt && sign)
+        rc = message_sign (msg, proto, hwnd);
+      else
+        {
+          /* In case this is a forward message which is not to be
+             signed or encrypted we need to remove a possible body
+             attachment.  */
+          if (mapi_delete_gpgol_body_attachment (msg))
+            mapi_save_changes (msg, KEEP_OPEN_READWRITE);
+          rc = 0;
+        }
       
-  //     if (rc)
-  //       {
-  //         hrReturn = E_FAIL;
-  //         m_bWriteFailed = TRUE;	
-  //       }
-  //   }
+      if (rc)
+        {
+          hrReturn = E_FAIL;
+          m_bWriteFailed = TRUE;	
+        }
+    }
   
-  // ul_release (msg, __func__, __LINE__);
-  // ul_release (pMDB, __func__, __LINE__);
+  ul_release (msg, __func__, __LINE__);
+  ul_release (pMDB, __func__, __LINE__);
   
   return hrReturn;
 }

Modified: trunk/src/oomhelp.h
===================================================================
--- trunk/src/oomhelp.h	2009-11-20 12:10:42 UTC (rev 321)
+++ trunk/src/oomhelp.h	2009-11-27 17:06:07 UTC (rev 322)
@@ -63,6 +63,7 @@
 
 DEFINE_OLEGUID(IID_IUnknown,                  0x00000000, 0, 0);
 DEFINE_OLEGUID(IID_IDispatch,                 0x00020400, 0, 0);
+DEFINE_OLEGUID(IID_IOleWindow,                0x00000114, 0, 0);
 
 
 #ifdef __cplusplus




More information about the Gnupg-commits mailing list