Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

200 lines
6.8 KiB

  1. /****************************************************************************/
  2. /* */
  3. /* ERNCGLBL.CPP */
  4. /* */
  5. /* RNC global functions. */
  6. /* */
  7. /* Copyright Data Connection Ltd. 1995 */
  8. /* */
  9. /****************************************************************************/
  10. /* Changes: */
  11. /* */
  12. /* 11Sep95 NFC Created. */
  13. /* 21Sep95 NFC Initialize all combo boxes. */
  14. /* 11Oct95 PM Remove GCC_BAD_PASSWORD */
  15. /* */
  16. /****************************************************************************/
  17. #include "precomp.h"
  18. #include "ms_util.h"
  19. #include "ernccons.h"
  20. #include "nccglbl.hpp"
  21. #include "erncvrsn.hpp"
  22. #include <cuserdta.hpp>
  23. #include "erncconf.hpp"
  24. #include "ernctrc.h"
  25. /****************************************************************************/
  26. /* GCC error table. This must macth exactly the enumeration in NCUI.H */
  27. /****************************************************************************/
  28. const GCCResult rcGCCTable[] =
  29. {
  30. GCC_RESULT_SUCCESSFUL, // NO_ERROR
  31. GCC_RESULT_ENTRY_ALREADY_EXISTS, // UI_RC_ALREADY_IN_CONFERENCE
  32. GCC_RESULT_ENTRY_ALREADY_EXISTS, // UI_RC_CONFERENCE_ALREADY_EXISTS
  33. GCC_RESULT_INVALID_PASSWORD, // UI_RC_INVALID_PASSWORD,
  34. GCC_RESULT_INVALID_CONFERENCE, // UI_RC_NO_CONFERENCE_NAME,
  35. GCC_RESULT_UNSPECIFIED_FAILURE, // UI_RC_T120_FAILURE,
  36. GCC_RESULT_INVALID_CONFERENCE, // UI_RC_UNKNOWN_CONFERENCE,
  37. GCC_RESULT_INCOMPATIBLE_PROTOCOL, // UI_RC_BAD_TRANSPORT_NAME
  38. GCC_RESULT_USER_REJECTED, // UI_RC_USER_REJECTED,
  39. GCC_RESULT_UNSPECIFIED_FAILURE // UI_RC_ERROR > LAST_RC_GCC_MAPPED_ERROR
  40. };
  41. /****************************************************************************/
  42. /* GCC error table. This must macth exactly the enumeration in GCC.H */
  43. /****************************************************************************/
  44. typedef struct
  45. {
  46. GCCError rc;
  47. HRESULT hr;
  48. }
  49. RC2HR;
  50. const RC2HR c_aRc2Hr[] =
  51. {
  52. { GCC_ALREADY_INITIALIZED, UI_RC_T120_ALREADY_INITIALIZED },
  53. { GCC_INVALID_CONFERENCE, UI_RC_UNKNOWN_CONFERENCE },
  54. { GCC_CONFERENCE_ALREADY_EXISTS, UI_RC_CONFERENCE_ALREADY_EXISTS },
  55. { GCC_SECURITY_FAILED, UI_RC_T120_SECURITY_FAILED },
  56. };
  57. /****************************************************************************/
  58. /* GCC result table.This must macth exactly the enumeration in GCC.H */
  59. /****************************************************************************/
  60. typedef struct
  61. {
  62. GCCResult result;
  63. HRESULT hr;
  64. }
  65. RESULT2HR;
  66. const RESULT2HR c_aResult2Hr[] =
  67. {
  68. { GCC_RESULT_INVALID_CONFERENCE, UI_RC_UNKNOWN_CONFERENCE },
  69. { GCC_RESULT_INVALID_PASSWORD, UI_RC_INVALID_PASSWORD },
  70. { GCC_RESULT_USER_REJECTED, UI_RC_USER_REJECTED },
  71. { GCC_RESULT_ENTRY_ALREADY_EXISTS, UI_RC_CONFERENCE_ALREADY_EXISTS },
  72. { GCC_RESULT_CANCELED, UI_RC_T120_FAILURE },
  73. { GCC_RESULT_CONNECT_PROVIDER_REMOTE_NO_SECURITY, UI_RC_T120_REMOTE_NO_SECURITY },
  74. { GCC_RESULT_CONNECT_PROVIDER_REMOTE_DOWNLEVEL_SECURITY, UI_RC_T120_REMOTE_DOWNLEVEL_SECURITY },
  75. { GCC_RESULT_CONNECT_PROVIDER_REMOTE_REQUIRE_SECURITY, UI_RC_T120_REMOTE_REQUIRE_SECURITY },
  76. { GCC_RESULT_CONNECT_PROVIDER_AUTHENTICATION_FAILED, UI_RC_T120_AUTHENTICATION_FAILED },
  77. };
  78. HRESULT GetGCCRCDetails(GCCError rc)
  79. {
  80. if (GCC_NO_ERROR == rc)
  81. {
  82. return NO_ERROR;
  83. }
  84. for (int i = 0; i < sizeof(c_aRc2Hr) / sizeof(c_aRc2Hr[0]); i++)
  85. {
  86. if (c_aRc2Hr[i].rc == rc)
  87. {
  88. return c_aRc2Hr[i].hr;
  89. }
  90. }
  91. return UI_RC_T120_FAILURE;
  92. }
  93. HRESULT GetGCCResultDetails(GCCResult result)
  94. {
  95. if (GCC_RESULT_SUCCESSFUL == result)
  96. {
  97. return NO_ERROR;
  98. }
  99. for (int i = 0; i < sizeof(c_aResult2Hr) / sizeof(c_aResult2Hr[0]); i++)
  100. {
  101. if (c_aResult2Hr[i].result == result)
  102. {
  103. return c_aResult2Hr[i].hr;
  104. }
  105. }
  106. return UI_RC_T120_FAILURE;
  107. }
  108. GCCResult MapRCToGCCResult(HRESULT rc)
  109. {
  110. // Called to map an error code to a GCC result to give to GCC.
  111. TRACE_FN("MapRCToGCCResult");
  112. ASSERT(sizeof(rcGCCTable)/sizeof(rcGCCTable[0]) - (LAST_RC_GCC_MAPPED_ERROR & 0x00ff) - 2 == 0);
  113. return (rcGCCTable[(UINT) rc > (UINT) LAST_RC_GCC_MAPPED_ERROR ? (LAST_RC_GCC_MAPPED_ERROR & 0x00ff) + 1 : (rc & 0x00ff)]);
  114. }
  115. HRESULT GetUnicodeFromGCC(PCSTR szGCCNumeric,
  116. PCWSTR wszGCCUnicode,
  117. PWSTR * pwszText)
  118. {
  119. // Obtain a Unicode string from a funky GCCString that may be
  120. // ANSI numeric or Unicode text. Note that a new Unicode
  121. // string is always allocated or NULL returned.
  122. LPWSTR wszText;
  123. HRESULT Status = NO_ERROR;
  124. ASSERT(pwszText);
  125. if (! ::IsEmptyStringW(wszGCCUnicode))
  126. {
  127. wszText = ::My_strdupW(wszGCCUnicode);
  128. }
  129. else if (! ::IsEmptyStringA(szGCCNumeric))
  130. {
  131. wszText = ::AnsiToUnicode(szGCCNumeric);
  132. }
  133. else
  134. {
  135. *pwszText = NULL;
  136. return(Status);
  137. }
  138. if (!wszText)
  139. {
  140. Status = UI_RC_OUT_OF_MEMORY;
  141. }
  142. *pwszText = wszText;
  143. return(Status);
  144. }
  145. HRESULT GetGCCFromUnicode
  146. (
  147. LPCWSTR pcwszText,
  148. GCCNumericString * pGCCNumeric,
  149. LPWSTR * pGCCUnicode
  150. )
  151. {
  152. // Construct a funky GCCString that may be ANSI numeric or Unicode text
  153. // from a Unicode string. Note that only a new ANSI numeric string may
  154. // be constructed - the Unicode string passed is is used.
  155. HRESULT hr = NO_ERROR;
  156. if (! ::IsEmptyStringW(pcwszText) && ::UnicodeIsNumber(pcwszText))
  157. {
  158. *pGCCUnicode = NULL;
  159. if (NULL == (*pGCCNumeric = (GCCNumericString) ::UnicodeToAnsi(pcwszText)))
  160. {
  161. hr = UI_RC_OUT_OF_MEMORY;
  162. }
  163. }
  164. else
  165. {
  166. *pGCCUnicode = (LPWSTR) pcwszText;
  167. *pGCCNumeric = NULL;
  168. }
  169. return hr;
  170. }