JSAPI2_api_security.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #pragma once
  2. #include <bfc/dispatch.h>
  3. #include "JSAPI_Info.h"
  4. namespace JSAPI2
  5. {
  6. class api_security : public Dispatchable
  7. {
  8. public:
  9. enum
  10. {
  11. ACTION_UNDEFINED = -1,
  12. ACTION_DISALLOWED = 0,
  13. ACTION_ALLOWED = 1,
  14. ACTION_PROMPT = 2,
  15. };
  16. enum
  17. {
  18. SUCCESS = 0,
  19. FAILURE = 1,
  20. };
  21. struct AuthorizationData
  22. {
  23. GUID data_id;
  24. void *data;
  25. size_t data_len;
  26. };
  27. // returns one of JSAPI2::api_security::ACTION_DISALLOWED, etc.
  28. int GetActionAuthorization(const wchar_t *group, const wchar_t *action, const wchar_t *authorization_key, JSAPI::ifc_info *info, int default_authorization = ACTION_ALLOWED, AuthorizationData *data = 0);
  29. // returns JSAPI2_SUCCESS, etc.
  30. int SetActionAuthorization(const wchar_t *group, const wchar_t *action, const wchar_t *authorization_key, int authorization);
  31. // associates an HWND with a key.. used for prompting
  32. void Associate(const wchar_t *authorization_key, HWND hwnd);
  33. HWND GetAssociation(const wchar_t *authorization_key);
  34. // if you just want a simple security prompt, you can call this in your svc_apicreator::PromptForAuthorization implementation
  35. int SecurityPrompt(HWND hwnd, const wchar_t *title_string, const wchar_t *display_string, int flags=0);
  36. // associates a name (e.g. an online service name) with a key.. used for prompting
  37. void AssociateName(const wchar_t *authorization_key, const wchar_t *name);
  38. const wchar_t *GetAssociatedName(const wchar_t *authorization_key);
  39. // clears out all settings for a given key
  40. void ResetAuthorization(const wchar_t *authorization_key);
  41. void SetBypass(const wchar_t *authorization_key, bool enable_bypass);
  42. enum
  43. {
  44. JSAPI2_API_SECURITY_GETACTIONAUTHORIZATION = 0,
  45. JSAPI2_API_SECURITY_SETACTIONAUTHORIZATION = 1,
  46. JSAPI2_API_SECURITY_ASSOCIATE = 2,
  47. JSAPI2_API_SECURITY_GETASSOCIATION = 3,
  48. JSAPI2_API_SECURITY_SECURITYPROMPT = 4,
  49. JSAPI2_API_SECURITY_ASSOCIATENAME = 5,
  50. JSAPI2_API_SECURITY_GETASSOCIATEDNAME = 6,
  51. JSAPI2_API_SECURITY_RESETAUTHORIZATION = 7,
  52. JSAPI2_API_SECURITY_SETBYPASS = 8,
  53. };
  54. };
  55. inline int api_security::GetActionAuthorization(const wchar_t *group, const wchar_t *action, const wchar_t *authorization_key, JSAPI::ifc_info *info, int default_authorization, AuthorizationData *data)
  56. {
  57. return _call(JSAPI2_API_SECURITY_GETACTIONAUTHORIZATION, (int)default_authorization, group, action, authorization_key, info, default_authorization, data);
  58. }
  59. inline int api_security::SetActionAuthorization(const wchar_t *group, const wchar_t *action, const wchar_t *authorization_key, int authorization)
  60. {
  61. return _call(JSAPI2_API_SECURITY_SETACTIONAUTHORIZATION, (int)FAILURE, group, action, authorization_key, authorization);
  62. }
  63. inline void api_security::Associate(const wchar_t *authorization_key, HWND hwnd)
  64. {
  65. _voidcall(JSAPI2_API_SECURITY_ASSOCIATE, authorization_key, hwnd);
  66. }
  67. inline HWND api_security::GetAssociation(const wchar_t *authorization_key)
  68. {
  69. return _call(JSAPI2_API_SECURITY_GETASSOCIATION, (HWND)0, authorization_key);
  70. }
  71. inline int api_security::SecurityPrompt(HWND hwnd, const wchar_t *title_string, const wchar_t *display_string, int flags)
  72. {
  73. return _call(JSAPI2_API_SECURITY_SECURITYPROMPT, (int)0, hwnd, title_string, display_string, flags);
  74. }
  75. inline void api_security::AssociateName(const wchar_t *authorization_key, const wchar_t *name)
  76. {
  77. _voidcall(JSAPI2_API_SECURITY_ASSOCIATENAME, authorization_key, name);
  78. }
  79. inline const wchar_t *api_security::GetAssociatedName(const wchar_t *authorization_key)
  80. {
  81. return _call(JSAPI2_API_SECURITY_GETASSOCIATEDNAME, (const wchar_t *)0, authorization_key);
  82. }
  83. inline void api_security::ResetAuthorization(const wchar_t *authorization_key)
  84. {
  85. _voidcall(JSAPI2_API_SECURITY_RESETAUTHORIZATION, authorization_key);
  86. }
  87. inline void api_security::SetBypass(const wchar_t *authorization_key, bool enable_bypass)
  88. {
  89. _voidcall(JSAPI2_API_SECURITY_SETBYPASS, authorization_key, enable_bypass);
  90. }
  91. // {D8BA8766-E489-4cfc-8527-9F3206257FFC}
  92. static const GUID api_securityGUID =
  93. { 0xd8ba8766, 0xe489, 0x4cfc, { 0x85, 0x27, 0x9f, 0x32, 0x6, 0x25, 0x7f, 0xfc } };
  94. };