]> git.michaelhowe.org Git - packages/o/openafs.git/commitdiff
windows-netidmgr-help-registration-20070215
authorAsanka Herath <asanka@secure-endpoints.com>
Thu, 15 Feb 2007 21:51:00 +0000 (21:51 +0000)
committerJeffrey Altman <jaltman@secure-endpoints.com>
Thu, 15 Feb 2007 21:51:00 +0000 (21:51 +0000)
In preparation for KFW 3.2, add conditional help registration.
When used with a version of NetIdMgr that supports the functionality
the OpenAFS plug-in will register its HtmlHelp on the NetIdMgr Help
menu.

src/WINNT/netidmgr_plugin/afsplugin.c
src/WINNT/netidmgr_plugin/lang/en_us/langres.rc
src/WINNT/netidmgr_plugin/langres.h

index 7080ef38c84b88e78ec1ebd975d481316600f13b..45256ad90abe2d811321d661baa68c46b8595a1e 100644 (file)
@@ -30,6 +30,7 @@
 #include<kherror.h>
 #include<khuidefs.h>
 #include<commctrl.h>
+#include<htmlhelp.h>
 #include<assert.h>
 
 static BOOL initialized = FALSE;
@@ -47,6 +48,8 @@ khm_int32 afs_attr_realm = -1;
 khm_handle afs_credset = NULL;
 khm_handle afs_sub = NULL;      /* AFS message subscription */
 
+khm_int32 action_id_afs_help = 0;
+
 /* forward dcls */
 khm_int32 KHMAPI 
 afs_msg_system(khm_int32 msg_subtype, khm_ui_4 uparam, void * vparam);
@@ -57,9 +60,48 @@ afs_msg_kcdb(khm_int32 msg_subtype, khm_ui_4 uparam, void * vparam);
 khm_int32 KHMAPI 
 afs_msg_cred(khm_int32 msg_subtype, khm_ui_4 uparam, void * vparam);
 
+khm_int32 KHMAPI
+afs_msg_act(khm_int32 msg_subtype, khm_ui_4 uparam, void * vparam);
+
 khm_int32 KHMAPI 
 afs_msg_ext(khm_int32 msg_subtype, khm_ui_4 uparam, void * vparam);
 
+/* AFS help menu extensions */
+
+/* some of the functions we will be calling are only available on API
+   version 7 and above of Network Identity Manager.  Since these
+   aren't critical, we allow building using API version 5 or above,
+   but conditionally use the newer functionality if the plug-in is
+   loaded by a newer version of Network Identity Manager. */
+
+#if KH_VERSION_API < 7
+
+HMODULE hm_netidmgr;
+
+/* declarations from version 7 of the API */
+KHMEXP void
+(KHMAPI * pkhui_action_lock)(void);
+
+KHMEXP void
+(KHMAPI * pkhui_action_unlock)(void);
+
+KHMEXP void
+(KHMAPI * pkhui_refresh_actions)(void);
+
+typedef khm_int32
+(KHMAPI * khm_ui_callback)(HWND hwnd_main_wnd, void * rock);
+
+KHMEXP khm_int32
+(KHMAPI * pkhui_request_UI_callback)(khm_ui_callback cb,
+                                     void * rock);
+
+#define khui_action_lock         (*pkhui_action_lock)
+#define khui_action_unlock       (*pkhui_action_unlock)
+#define khui_refresh_actions     (*pkhui_refresh_actions)
+#define khui_request_UI_callback (*pkhui_request_UI_callback)
+
+#endif
+
 /* AFS plugin callback */
 khm_int32 KHMAPI 
 afs_plugin_cb(khm_int32 msg_type,
@@ -73,6 +115,8 @@ afs_plugin_cb(khm_int32 msg_type,
         return afs_msg_kcdb(msg_subtype, uparam, vparam);
     if (msg_type == KMSG_CRED)
         return afs_msg_cred(msg_subtype, uparam, vparam);
+    if (msg_type == KMSG_ACT)
+        return afs_msg_act(msg_subtype, uparam, vparam);
     if (msg_type == afs_msg_type_id)
         return afs_msg_ext(msg_subtype, uparam, vparam);
 
@@ -494,6 +538,101 @@ afs_msg_system(khm_int32 msg_subtype,
                 khc_close_space(csp_afscred);
             }
 
+            /* try to register the "AFS Help" menu item, if
+               possible */
+            {
+                khm_handle h_sub = NULL;
+                wchar_t short_desc[KHUI_MAXCCH_SHORT_DESC];
+                wchar_t long_desc[KHUI_MAXCCH_LONG_DESC];
+
+#if KH_VERSION_API < 7
+
+                khm_version libver;
+                khm_ui_4 apiver;
+
+                khm_get_lib_version(&libver, &apiver);
+
+                if (apiver < 7)
+                    goto no_custom_help;
+
+                hm_netidmgr = LoadLibrary(L"nidmgr32.dll");
+
+                if (hm_netidmgr == NULL)
+                    goto no_custom_help;
+
+                pkhui_action_lock = (void (KHMAPI *)(void))
+                    GetProcAddress(hm_netidmgr, "_khui_action_lock@0");
+                pkhui_action_unlock = (void (KHMAPI *)(void))
+                    GetProcAddress(hm_netidmgr, "_khui_action_unlock@0");
+                pkhui_refresh_actions = (void (KHMAPI *)(void))
+                    GetProcAddress(hm_netidmgr, "_khui_refresh_actions@0");
+                pkhui_request_UI_callback = (khm_int32 (KHMAPI *)(khm_ui_callback, void *))
+                    GetProcAddress(hm_netidmgr, "_khui_request_UI_callback@8");
+
+                if (pkhui_action_lock == NULL ||
+                    pkhui_action_unlock == NULL ||
+                    pkhui_refresh_actions == NULL ||
+                    pkhui_request_UI_callback == NULL)
+
+                    goto no_custom_help;
+
+#endif
+                kmq_create_subscription(afs_plugin_cb, &h_sub);
+
+                LoadString(hResModule, IDS_ACTION_AFS_HELP,
+                           short_desc, ARRAYLENGTH(short_desc));
+                LoadString(hResModule, IDS_ACTION_AFS_HELP_TT,
+                           long_desc, ARRAYLENGTH(long_desc));
+
+                action_id_afs_help = khui_action_create(NULL,
+                                                        short_desc,
+                                                        long_desc,
+                                                        NULL,
+                                                        KHUI_ACTIONTYPE_TRIGGER,
+                                                        h_sub);
+
+                if (action_id_afs_help != 0) {
+                    khm_size s;
+                    khm_size i;
+                    khui_menu_def * help_menu;
+                    khm_boolean refresh = FALSE;
+
+                    khui_action_lock();
+
+                    help_menu = khui_find_menu(KHUI_MENU_HELP);
+                    if (help_menu) {
+                        s = khui_menu_get_size(help_menu);
+
+                        for (i=0; i < s; i++) {
+                            khui_action_ref * aref;
+
+                            aref = khui_menu_get_action(help_menu, i);
+
+                            if (aref && !(aref->flags & KHUI_ACTIONREF_PACTION) &&
+                                aref->action == KHUI_ACTION_HELP_INDEX) {
+
+                                khui_menu_insert_action(help_menu,
+                                                        i + 1,
+                                                        action_id_afs_help,
+                                                        0);
+                                refresh = TRUE;
+                                break;
+                            }
+                        }
+                    }
+
+                    khui_action_unlock();
+
+                    if (refresh)
+                        khui_refresh_actions();
+                }
+
+#if KH_VERSION_API < 7
+            no_custom_help:
+                ;
+#endif
+            }
+
         _exit_init:
             if(ct.short_desc)
                 PFREE(ct.short_desc);
@@ -518,6 +657,45 @@ afs_msg_system(khm_int32 msg_subtype,
         /* end of KMSG_SYSTEM_INIT */
 
     case KMSG_SYSTEM_EXIT:
+
+        /* Try to remove the AFS plug-in action from Help menu if it
+           was successfully registered.  Also, delete the action. */
+        if (action_id_afs_help != 0) {
+
+            khui_menu_def * help_menu;
+            khm_boolean menu_changed = FALSE;
+
+            khui_action_lock();
+
+            help_menu = khui_find_menu(KHUI_MENU_HELP);
+            if (help_menu) {
+                khm_size s;
+                khm_size i;
+
+                s = khui_menu_get_size(help_menu);
+                for (i=0; i < s; i++) {
+                    khui_action_ref * aref = khui_menu_get_action(help_menu, i);
+
+                    if (aref && !(aref->flags & KHUI_ACTIONREF_PACTION) &&
+                        aref->action == action_id_afs_help) {
+
+                        khui_menu_remove_action(help_menu, i);
+                        menu_changed = TRUE;
+                        break;
+                    }
+                }
+            }
+
+            khui_action_delete(action_id_afs_help);
+
+            khui_action_unlock();
+
+            if (menu_changed)
+                khui_refresh_actions();
+
+            action_id_afs_help = 0;
+        }
+
         if (afs_msg_type_id != -1) {
             kmq_unsubscribe(afs_msg_type_id, afs_plugin_cb);
             kmq_unregister_type(afs_msg_type_id);
@@ -559,6 +737,16 @@ afs_msg_system(khm_int32 msg_subtype,
            of when unregistering the afs cred type */
         afs_sub = NULL;
 
+#if KH_VERSION_API < 7
+        if (hm_netidmgr)
+            FreeLibrary(hm_netidmgr);
+
+        pkhui_action_lock = NULL;
+        pkhui_action_unlock = NULL;
+        pkhui_refresh_actions = NULL;
+        pkhui_request_UI_callback = NULL;
+#endif
+
         rv = KHM_ERROR_SUCCESS;
         break;
         /* end of KMSG_SYSTEM_EXIT */
@@ -640,3 +828,27 @@ afs_msg_cred(khm_int32 msg_subtype,
     return rv;
 }
 
+
+khm_int32 KHMAPI
+help_launcher(HWND hwnd_main, void * rock) {
+    afs_html_help(hwnd_main, NULL, HH_DISPLAY_TOC, 0);
+
+    return KHM_ERROR_SUCCESS;
+}
+
+khm_int32 KHMAPI 
+afs_msg_act(khm_int32 msg_subtype, 
+            khm_ui_4 uparam, 
+            void * vparam)
+{
+    khm_int32 rv = KHM_ERROR_SUCCESS;
+
+    if (msg_subtype == KMSG_ACT_ACTIVATE &&
+        uparam == action_id_afs_help) {
+
+        khui_request_UI_callback(help_launcher, NULL);
+
+    }
+
+    return rv;
+}
index 6827d60bf24ec0e47364ba18470578eeed827a33..ab13b14320fdf02fb62d101d43fd35804a30e8a0 100644 (file)
@@ -254,6 +254,8 @@ BEGIN
     IDS_ERR_NOSERVICE       "The AFS service is not running.  If OpenAFS is installed, you can start the service using the AFS configuration panel."
     IDS_ERR_CELLCONFIG_S    "The error code returned was %2!d!."
     IDS_ERR_GENERAL         "Credentials could not be obtained for cell %1!S!."
+    IDS_ACTION_AFS_HELP     "Help for OpenAFS plug-in"
+    IDS_ACTION_AFS_HELP_TT  "Display documentation for the OpenAFS plug-in"
 END
 
 #endif    // English (U.S.) resources
index f651825ec6334b94c39d49eb219d44c9a36d2172..c472b14533a9bf528fb5eaeaca3260784aa9a05f 100644 (file)
@@ -1,6 +1,6 @@
 //{{NO_DEPENDENCIES}}
 // Microsoft Visual C++ generated include file.
-// Used by C:\work\pismere\athena\auth\krb5\src\windows\identity\plugins\afs\lang\en_us\langres.rc
+// Used by C:\work\openafs.1.5\src\Winnt\netidmgr_plugin\lang\en_us\langres.rc
 //
 #define IDS_AFS_SHORT_DESC              101
 #define IDS_AFS_LONG_DESC               102
@@ -66,6 +66,8 @@
 #define IDS_ERR_NOSERVICE               152
 #define IDS_ERR_CELLCONFIG_S            153
 #define IDS_ERR_GENERAL                 154
+#define IDS_ACTION_AFS_HELP             155
+#define IDS_ACTION_AFS_HELP_TT          156
 #define IDC_NCAFS_OBTAIN                1001
 #define IDC_NCAFS_TOKENLIST             1002
 #define IDC_NCAFS_CELL                  1004