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.

914 lines
24 KiB

  1. /**********************************************************
  2. (C) 2001 Microsoft Corp.
  3. File : utils.cpp
  4. ***********************************************************/
  5. #include "stdafx.h"
  6. #include "utils.h"
  7. #include "mdispid.h"
  8. #include <crtdbg.h>
  9. #include <winreg.h>
  10. #define STRING_CASE(val) case val: pcsz = _T(#val); break
  11. LPCTSTR GetStringFromCOMError(HRESULT hr)
  12. {
  13. LPCTSTR pcsz;
  14. static TCHAR sz[MAX_PATH];
  15. switch (hr)
  16. {
  17. STRING_CASE(REGDB_E_CLASSNOTREG);
  18. STRING_CASE(CLASS_E_NOAGGREGATION);
  19. STRING_CASE(E_NOINTERFACE);
  20. default:
  21. wsprintf(sz, _T("(unknown) [0x%08X]"), hr);
  22. pcsz = sz;
  23. break;
  24. }
  25. return pcsz;
  26. }
  27. LPCTSTR GetStringFromSessionState(SESSION_STATE ss)
  28. {
  29. LPCTSTR pcsz=NULL;
  30. static TCHAR sz[MAX_PATH];
  31. switch (ss)
  32. {
  33. STRING_CASE(SS_UNKNOWN);
  34. STRING_CASE(SS_READY);
  35. STRING_CASE(SS_INVITATION);
  36. STRING_CASE(SS_CONNECTED);
  37. STRING_CASE(SS_CANCELLED);
  38. STRING_CASE(SS_DECLINED);
  39. STRING_CASE(SS_TERMINATED);
  40. default:
  41. wsprintf(sz, _T("(unknown) [0x%08X]"), ss);
  42. pcsz = sz;
  43. break;
  44. }
  45. return pcsz;
  46. }
  47. LPCTSTR GetStringFromServiceStatus(MSVCSTATUS bs)
  48. {
  49. LPCTSTR pcsz;
  50. static TCHAR sz[MAX_PATH];
  51. switch (bs)
  52. {
  53. STRING_CASE(MSS_LOGGED_ON);
  54. STRING_CASE(MSS_NOT_LOGGED_ON);
  55. STRING_CASE(MSS_LOGGING_ON);
  56. STRING_CASE(MSS_LOGGING_OFF);
  57. default:
  58. wsprintf(sz, _T("(unknown) [0x%08X]"), bs);
  59. pcsz = sz;
  60. break;
  61. }
  62. return pcsz;
  63. }
  64. LPCTSTR GetStringFromUserProperty(MUSERPROPERTY ps)
  65. {
  66. LPCTSTR pcsz;
  67. static TCHAR sz[MAX_PATH];
  68. switch (ps)
  69. {
  70. STRING_CASE(MUSERPROP_INVALID_PROPERTY);
  71. STRING_CASE(MUSERPROP_HOME_PHONE_NUMBER);
  72. STRING_CASE(MUSERPROP_WORK_PHONE_NUMBER);
  73. STRING_CASE(MUSERPROP_MOBILE_PHONE_NUMBER);
  74. STRING_CASE(MUSERPROP_PAGES_ALLOWED);
  75. // STRING_CASE(MUSERPROP_NUMBER_OF_PUBLIC_PROPERTIES);
  76. STRING_CASE(MUSERPROP_PAGES_ENABLED);
  77. default:
  78. wsprintf(sz, _T("(unknown) [0x%08X]"), ps);
  79. pcsz = sz;
  80. break;
  81. }
  82. return pcsz;
  83. }
  84. LPCTSTR GetStringFromProfileField(MPFLFIELD fl)
  85. {
  86. LPCTSTR pcsz;
  87. static TCHAR sz[MAX_PATH];
  88. switch (fl)
  89. {
  90. STRING_CASE(MPFLFIELD_COUNTRY);
  91. STRING_CASE(MPFLFIELD_POSTALCODE);
  92. STRING_CASE(MPFLFIELD_LANG_PREFERENCE);
  93. STRING_CASE(MPFLFIELD_GENDER);
  94. STRING_CASE(MPFLFIELD_PREFERRED_EMAIL);
  95. STRING_CASE(MPFLFIELD_NICKNAME);
  96. STRING_CASE(MPFLFIELD_ACCESSIBILITY);
  97. STRING_CASE(MPFLFIELD_WALLET);
  98. STRING_CASE(MPFLFIELD_DIRECTORY);
  99. STRING_CASE(MPFLFIELD_INETACCESS);
  100. default:
  101. wsprintf(sz, _T("(unknown) [0x%08X]"), fl);
  102. pcsz = sz;
  103. break;
  104. }
  105. return pcsz;
  106. }
  107. LPCTSTR GetStringFromVoiceSessionState(VOICESESSIONSTATE vs)
  108. {
  109. LPCTSTR pcsz;
  110. static TCHAR sz[MAX_PATH];
  111. switch (vs)
  112. {
  113. STRING_CASE(VOICESESSIONSTATE_DISABLED);
  114. STRING_CASE(VOICESESSIONSTATE_INACTIVE);
  115. STRING_CASE(VOICESESSIONSTATE_ACTIVE);
  116. default:
  117. wsprintf(sz, _T("(unknown) [0x%08X]"), vs);
  118. pcsz = sz;
  119. break;
  120. }
  121. return pcsz;
  122. }
  123. LPCTSTR GetStringFromMURLType(MURLTYPE mt)
  124. {
  125. LPCTSTR pcsz;
  126. static TCHAR sz[MAX_PATH];
  127. switch (mt)
  128. {
  129. STRING_CASE(MURLTYPE_CHANGE_PASSWORD);
  130. STRING_CASE(MURLTYPE_CHANGE_INFO);
  131. STRING_CASE(MURLTYPE_COMPOSE_EMAIL);
  132. STRING_CASE(MURLTYPE_GO_TO_EMAIL_INBOX);
  133. STRING_CASE(MURLTYPE_GO_TO_EMAIL_FOLDERS);
  134. STRING_CASE(MURLTYPE_CHANGE_MOBILE_INFO);
  135. STRING_CASE(MURLTYPE_MOBILE_SIGNUP);
  136. default:
  137. wsprintf(sz, _T("(unknown) [0x%08X]"), mt);
  138. pcsz = sz;
  139. break;
  140. }
  141. return pcsz;
  142. }
  143. LPCTSTR GetStringFromEventId(long dispid)
  144. {
  145. LPCTSTR pcsz;
  146. static TCHAR sz[MAX_PATH];
  147. switch (dispid)
  148. {
  149. STRING_CASE(DISPID_ONLOGONRESULT);
  150. STRING_CASE(DISPID_ONLOGOFF);
  151. STRING_CASE(DISPID_ONLISTADDRESULT);
  152. STRING_CASE(DISPID_ONLISTREMOVERESULT);
  153. STRING_CASE(DISPID_ONMESSAGEPRIVACYCHANGERESULT);
  154. STRING_CASE(DISPID_ONPROMPTCHANGERESULT);
  155. STRING_CASE(DISPID_ONUSERSTATECHANGED);
  156. STRING_CASE(DISPID_ONTEXTRECEIVED);
  157. STRING_CASE(DISPID_ONLOCALSTATECHANGERESULT);
  158. STRING_CASE(DISPID_ONAPPINVITERECEIVED);
  159. STRING_CASE(DISPID_ONAPPINVITEACCEPTED);
  160. STRING_CASE(DISPID_ONAPPINVITECANCELLED);
  161. STRING_CASE(DISPID_ONPRIMARYSERVICECHANGED);
  162. STRING_CASE(DISPID_ONSERVICELOGOFF);
  163. STRING_CASE(DISPID_ONFINDRESULT);
  164. STRING_CASE(DISPID_ONLOCALFRIENDLYNAMECHANGERESULT);
  165. STRING_CASE(DISPID_ONFILETRANSFERINVITERECEIVED);
  166. STRING_CASE(DISPID_ONFILETRANSFERINVITEACCEPTED);
  167. STRING_CASE(DISPID_ONFILETRANSFERINVITECANCELLED);
  168. STRING_CASE(DISPID_ONFILETRANSFERCANCELLED);
  169. STRING_CASE(DISPID_ONFILETRANSFERSTATUSCHANGE);
  170. STRING_CASE(DISPID_ONSENDRESULT);
  171. STRING_CASE(DISPID_ONUSERJOIN);
  172. STRING_CASE(DISPID_ONUNREADEMAILCHANGED);
  173. STRING_CASE(DISPID_ONUSERDROPPED);
  174. STRING_CASE(DISPID_ONREQUESTURLPOSTRESULT);
  175. STRING_CASE(DISPID_ONUSERFRIENDLYNAMECHANGERESULT);
  176. STRING_CASE(DISPID_ONNEWERCLIENTAVAILABLE);
  177. STRING_CASE(DISPID_ONINVITEMAILRESULT);
  178. STRING_CASE(DISPID_ONREQUESTURLRESULT);
  179. STRING_CASE(DISPID_ONSESSIONSTATECHANGE);
  180. STRING_CASE(DISPID_ONUSERLEAVE);
  181. STRING_CASE(DISPID_ONNEWSESSIONREQUEST);
  182. STRING_CASE(DISPID_ONINVITEUSER);
  183. STRING_CASE(DISPID_ONAPPSHUTDOWN);
  184. // Commented out since Voice API has been removed
  185. /* STRING_CASE(DISPID_ONVOICEIMINVITERECEIVED);
  186. STRING_CASE(DISPID_ONVOICEIMINVITEACCEPTED);
  187. STRING_CASE(DISPID_ONVOICEIMINVITECANCELLED);*/
  188. STRING_CASE(DISPID_ONSPMESSAGERECEIVED);
  189. STRING_CASE(DISPID_ONNEWERSITESAVAILABLE);
  190. STRING_CASE(DISPID_ONLOCALPROPERTYCHANGERESULT);
  191. STRING_CASE(DISPID_ONBUDDYPROPERTYCHANGERESULT);
  192. STRING_CASE(DISPID_ONBEFORELAUNCHIMUI);
  193. STRING_CASE(DISPID_ONSHOWIMUI);
  194. STRING_CASE(DISPID_ONDESTROYIMUI);
  195. STRING_CASE(DISPID_ONINDICATEMESSAGERECEIVED);
  196. STRING_CASE(DISPID_ONSTATUSTEXT);
  197. STRING_CASE(DISPID_ONTITLEBARTEXT);
  198. STRING_CASE(DISPID_ONINFOBARTEXT);
  199. STRING_CASE(DISPID_ONSENDENABLED);
  200. STRING_CASE(DISPID_ONTRANSLATEACCELERATOR);
  201. STRING_CASE(DISPID_ONFILETRANSFER);
  202. STRING_CASE(DISPID_ONVOICESESSIONSTATE);
  203. STRING_CASE(DISPID_ONVOICEVOLUMECHANGED);
  204. STRING_CASE(DISPID_ONMICROPHONEMUTE);
  205. default:
  206. wsprintf(sz, _T("(unknown) [0x%08X]"), dispid);
  207. pcsz = sz;
  208. break;
  209. }
  210. return pcsz;
  211. }
  212. LPCTSTR GetStringFromSessionEventId(long dispid)
  213. {
  214. LPCTSTR pcsz;
  215. static TCHAR sz[MAX_PATH];
  216. switch (dispid)
  217. {
  218. STRING_CASE(DISPID_ONINVITATION);
  219. STRING_CASE(DISPID_ONAPPREGISTERED);
  220. STRING_CASE(DISPID_ONAPPUNREGISTERED);
  221. STRING_CASE(DISPID_ONLOCKCHALLENGE);
  222. STRING_CASE(DISPID_ONLOCKRESULT);
  223. STRING_CASE(DISPID_ONLOCKENABLE);
  224. STRING_CASE(DISPID_ONAPPSHUTDOWN);
  225. default:
  226. wsprintf(sz, _T("(unknown) [0x%08X]"), dispid);
  227. pcsz = sz;
  228. break;
  229. }
  230. return pcsz;
  231. }
  232. LPCTSTR GetStringFromError(HRESULT hr)
  233. {
  234. LPCTSTR pcsz = NULL;
  235. static TCHAR sz[MAX_PATH];
  236. switch (hr)
  237. {
  238. // non-Error codes
  239. STRING_CASE(S_OK);
  240. STRING_CASE(S_FALSE);
  241. // STRING_CASE(E_FILE_NOT_FOUND);
  242. STRING_CASE(HRESULT_FROM_WIN32(ERROR_INVALID_NAME));
  243. STRING_CASE(HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND));
  244. // Registration database stuff
  245. STRING_CASE(REGDB_E_CLASSNOTREG);
  246. STRING_CASE(REGDB_E_READREGDB);
  247. STRING_CASE(REGDB_E_WRITEREGDB);
  248. STRING_CASE(REGDB_E_KEYMISSING);
  249. STRING_CASE(REGDB_E_INVALIDVALUE);
  250. STRING_CASE(REGDB_E_IIDNOTREG);
  251. // COM error codes
  252. STRING_CASE(E_UNEXPECTED);
  253. STRING_CASE(E_NOTIMPL);
  254. STRING_CASE(E_OUTOFMEMORY);
  255. STRING_CASE(E_INVALIDARG);
  256. STRING_CASE(E_NOINTERFACE);
  257. STRING_CASE(E_POINTER);
  258. STRING_CASE(E_HANDLE);
  259. STRING_CASE(E_ABORT);
  260. STRING_CASE(E_FAIL);
  261. STRING_CASE(E_ACCESSDENIED);
  262. // MSGR Error codes
  263. STRING_CASE(MSGR_E_CONNECT);
  264. STRING_CASE(MSGR_E_INVALID_SERVER_NAME);
  265. STRING_CASE(MSGR_E_INVALID_PASSWORD);
  266. STRING_CASE(MSGR_E_ALREADY_LOGGED_ON);
  267. STRING_CASE(MSGR_E_SERVER_VERSION);
  268. STRING_CASE(MSGR_E_LOGON_TIMEOUT);
  269. STRING_CASE(MSGR_E_LIST_FULL);
  270. STRING_CASE(MSGR_E_AI_REJECT);
  271. STRING_CASE(MSGR_E_AI_REJECT_NOT_INST);
  272. STRING_CASE(MSGR_E_USER_NOT_FOUND);
  273. STRING_CASE(MSGR_E_ALREADY_IN_LIST);
  274. STRING_CASE(MSGR_E_DISCONNECTED);
  275. STRING_CASE(MSGR_E_UNEXPECTED);
  276. STRING_CASE(MSGR_E_SERVER_TOO_BUSY);
  277. STRING_CASE(MSGR_E_INVALID_AUTH_PACKAGES);
  278. STRING_CASE(MSGR_E_NEWER_CLIENT_AVAILABLE);
  279. STRING_CASE(MSGR_E_AI_TIMEOUT);
  280. STRING_CASE(MSGR_E_CANCEL);
  281. STRING_CASE(MSGR_E_TOO_MANY_MATCHES);
  282. STRING_CASE(MSGR_E_SERVER_UNAVAILABLE);
  283. STRING_CASE(MSGR_E_LOGON_UI_ACTIVE);
  284. STRING_CASE(MSGR_E_OPTION_UI_ACTIVE);
  285. STRING_CASE(MSGR_E_CONTACT_UI_ACTIVE);
  286. STRING_CASE(MSGR_E_PRIMARY_SERVICE_NOT_LOGGED_ON);
  287. STRING_CASE(MSGR_E_LOGGED_ON);
  288. STRING_CASE(MSGR_E_CONNECT_PROXY);
  289. STRING_CASE(MSGR_E_PROXY_AUTH);
  290. STRING_CASE(MSGR_E_PROXY_AUTH_TYPE);
  291. STRING_CASE(MSGR_E_INVALID_PROXY_NAME);
  292. STRING_CASE(MSGR_E_NOT_PRIMARY_SERVICE);
  293. STRING_CASE(MSGR_E_TOO_MANY_SESSIONS);
  294. STRING_CASE(MSGR_E_TOO_MANY_MESSAGES);
  295. STRING_CASE(MSGR_E_REMOTE_LOGIN);
  296. STRING_CASE(MSGR_E_INVALID_FRIENDLY_NAME);
  297. STRING_CASE(MSGR_E_SESSION_FULL);
  298. STRING_CASE(MSGR_E_NOT_ALLOWING_NEW_USERS);
  299. STRING_CASE(MSGR_E_INVALID_DOMAIN);
  300. STRING_CASE(MSGR_E_TCP_ERROR);
  301. STRING_CASE(MSGR_E_SESSION_TIMEOUT);
  302. STRING_CASE(MSGR_E_MULTIPOINT_SESSION_BEGIN_TIMEOUT);
  303. STRING_CASE(MSGR_E_MULTIPOINT_SESSION_END_TIMEOUT);
  304. STRING_CASE(MSGR_E_REVERSE_LIST_FULL);
  305. STRING_CASE(MSGR_E_SERVER_ERROR);
  306. STRING_CASE(MSGR_E_SYSTEM_CONFIG);
  307. STRING_CASE(MSGR_E_NO_DIRECTORY);
  308. STRING_CASE(MSGR_E_RETRY_SET);
  309. STRING_CASE(MSGR_E_CHILD_WITHOUT_CONSENT);
  310. STRING_CASE(MSGR_E_USER_CANCELLED);
  311. STRING_CASE(MSGR_E_CANCEL_BEFORE_CONNECT);
  312. STRING_CASE(MSGR_E_VOICE_IM_TIMEOUT);
  313. STRING_CASE(MSGR_E_NOT_ACCEPTING_PAGES);
  314. STRING_CASE(MSGR_E_EMAIL_PASSPORT_NOT_VALIDATED);
  315. STRING_CASE(MSGR_S_ALREADY_IN_THE_MODE);
  316. STRING_CASE(MSGR_S_TRANSFER_SEND_BEGUN);
  317. STRING_CASE(MSGR_S_TRANSFER_SEND_FINISHED);
  318. STRING_CASE(MSGR_S_TRANSFER_RECEIVE_BEGUN);
  319. STRING_CASE(MSGR_S_TRANSFER_RECEIVE_FINISHED);
  320. STRING_CASE(MSGR_E_MESSAGE_TOO_LONG);
  321. //STRING_CASE(CONNECT_E_NOCONNECTION);
  322. STRING_CASE(SR_APPLICATION_LAUNCH_FAILED);
  323. STRING_CASE(SR_INVITATION_DECLINED);
  324. STRING_CASE(SR_CONNECTION_FAILURE);
  325. STRING_CASE(SR_AUTHENTICATION_FAILED);
  326. STRING_CASE(SR_SESSION_NOT_READY);
  327. STRING_CASE(SR_SESSION_CANCELLED_LOCAL);
  328. STRING_CASE(SR_SESSION_CANCELLED_REMOTE);
  329. STRING_CASE(SR_SESSION_PROTOCOL_ERROR);
  330. STRING_CASE(SR_SESSION_TIMEOUT);
  331. STRING_CASE(SR_CANCEL_BEFORE_CONNECT);
  332. STRING_CASE(SR_NOT_INVITEE);
  333. STRING_CASE(SR_NOT_INVITER);
  334. STRING_CASE(SR_APP_ALREADY_REGISTERED);
  335. STRING_CASE(SR_APP_NOT_REGISTERED);
  336. STRING_CASE(SR_NOT_VALID_FOR_APP_INVITE);
  337. STRING_CASE(MSGR_E_API_NOTINITIALIZED);
  338. STRING_CASE(MSGR_E_API_LOCKED);
  339. STRING_CASE(MSGR_E_API_UNLOCK_FAILED);
  340. STRING_CASE(MSGR_E_API_ALREADY_UNLOCKED);
  341. STRING_CASE(MSGR_E_API_PENDING_UNLOCK);
  342. default:
  343. if( HRESULT_FACILITY(hr) == FACILITY_WIN32 )
  344. {
  345. switch( HRESULT_CODE(hr) )
  346. {
  347. STRING_CASE(RPC_X_NULL_REF_POINTER);
  348. STRING_CASE(RPC_X_ENUM_VALUE_OUT_OF_RANGE);
  349. STRING_CASE(RPC_S_SERVER_UNAVAILABLE);
  350. STRING_CASE(RPC_E_SERVERFAULT);
  351. }
  352. }
  353. if( !pcsz )
  354. {
  355. wsprintf(sz, _T("(unknown) [0x%08X]"), hr);
  356. pcsz = sz;
  357. }
  358. }
  359. return pcsz;
  360. }
  361. LPCTSTR GetStringFromBasicIMError(HRESULT hr)
  362. {
  363. LPCTSTR pcsz = NULL;
  364. static TCHAR sz[MAX_PATH];
  365. switch (hr)
  366. {
  367. // non-Error codes
  368. STRING_CASE(S_OK);
  369. STRING_CASE(S_FALSE);
  370. // STRING_CASE(E_FILE_NOT_FOUND);
  371. // Registration database stuff
  372. STRING_CASE(REGDB_E_CLASSNOTREG);
  373. STRING_CASE(REGDB_E_READREGDB);
  374. STRING_CASE(REGDB_E_WRITEREGDB);
  375. STRING_CASE(REGDB_E_KEYMISSING);
  376. STRING_CASE(REGDB_E_INVALIDVALUE);
  377. STRING_CASE(REGDB_E_IIDNOTREG);
  378. // COM error codes
  379. STRING_CASE(E_UNEXPECTED);
  380. STRING_CASE(E_NOTIMPL);
  381. STRING_CASE(E_OUTOFMEMORY);
  382. STRING_CASE(E_INVALIDARG);
  383. STRING_CASE(E_NOINTERFACE);
  384. STRING_CASE(E_POINTER);
  385. STRING_CASE(E_HANDLE);
  386. STRING_CASE(E_ABORT);
  387. STRING_CASE(E_FAIL);
  388. STRING_CASE(E_ACCESSDENIED);
  389. // Basic IM error codes
  390. STRING_CASE(BASICIM_E_CONNECT);
  391. STRING_CASE(BASICIM_E_INVALID_SERVER_NAME);
  392. STRING_CASE(BASICIM_E_INVALID_PASSWORD);
  393. STRING_CASE(BASICIM_E_ALREADY_LOGGED_ON);
  394. STRING_CASE(BASICIM_E_SERVER_VERSION);
  395. STRING_CASE(BASICIM_E_LOGON_TIMEOUT);
  396. STRING_CASE(BASICIM_E_LIST_FULL);
  397. STRING_CASE(BASICIM_E_AI_REJECT);
  398. STRING_CASE(BASICIM_E_AI_REJECT_NOT_INST);
  399. STRING_CASE(BASICIM_E_USER_NOT_FOUND);
  400. STRING_CASE(BASICIM_E_ALREADY_IN_LIST);
  401. STRING_CASE(BASICIM_E_DISCONNECTED);
  402. STRING_CASE(BASICIM_E_UNEXPECTED);
  403. STRING_CASE(BASICIM_E_SERVER_TOO_BUSY);
  404. STRING_CASE(BASICIM_E_INVALID_AUTH_PACKAGES);
  405. STRING_CASE(BASICIM_E_NEWER_CLIENT_AVAILABLE);
  406. STRING_CASE(BASICIM_E_AI_TIMEOUT);
  407. STRING_CASE(BASICIM_E_CANCEL);
  408. STRING_CASE(BASICIM_E_TOO_MANY_MATCHES);
  409. STRING_CASE(BASICIM_E_SERVER_UNAVAILABLE);
  410. STRING_CASE(BASICIM_E_LOGON_UI_ACTIVE);
  411. STRING_CASE(BASICIM_E_OPTION_UI_ACTIVE);
  412. STRING_CASE(BASICIM_E_CONTACT_UI_ACTIVE);
  413. STRING_CASE(BASICIM_E_PRIMARY_SERVICE_NOT_LOGGED_ON);
  414. STRING_CASE(BASICIM_S_ASYNCRESULT);
  415. //STRING_CASE(CONNECT_E_NOCONNECTION);
  416. default:
  417. if( HRESULT_FACILITY(hr) == FACILITY_WIN32 )
  418. {
  419. switch( HRESULT_CODE(hr) )
  420. {
  421. STRING_CASE(RPC_X_NULL_REF_POINTER);
  422. STRING_CASE(RPC_X_ENUM_VALUE_OUT_OF_RANGE);
  423. STRING_CASE(RPC_S_SERVER_UNAVAILABLE);
  424. STRING_CASE(RPC_E_SERVERFAULT);
  425. }
  426. }
  427. if( !pcsz )
  428. {
  429. wsprintf(sz, _T("(unknown) [0x%08X]"), hr);
  430. pcsz = sz;
  431. }
  432. }
  433. return pcsz;
  434. }
  435. LPCTSTR GetStringFromContactStatus(MISTATUS ms)
  436. {
  437. LPCTSTR pcsz;
  438. static TCHAR sz[MAX_PATH];
  439. switch (ms)
  440. {
  441. // MISTATUS
  442. STRING_CASE(MISTATUS_UNKNOWN);
  443. STRING_CASE(MISTATUS_OFFLINE);
  444. STRING_CASE(MISTATUS_ONLINE);
  445. STRING_CASE(MISTATUS_INVISIBLE);
  446. STRING_CASE(MISTATUS_BUSY);
  447. STRING_CASE(MISTATUS_IDLE);
  448. STRING_CASE(MISTATUS_BE_RIGHT_BACK);
  449. STRING_CASE(MISTATUS_AWAY);
  450. STRING_CASE(MISTATUS_ON_THE_PHONE);
  451. STRING_CASE(MISTATUS_OUT_TO_LUNCH);
  452. STRING_CASE(MISTATUS_LOCAL_FINDING_SERVER);
  453. STRING_CASE(MISTATUS_LOCAL_CONNECTING_TO_SERVER);
  454. STRING_CASE(MISTATUS_LOCAL_SYNCHRONIZING_WITH_SERVER);
  455. STRING_CASE(MISTATUS_LOCAL_DISCONNECTING_FROM_SERVER);
  456. default:
  457. wsprintf(sz, _T("(unknown) %i"), ms);
  458. pcsz = sz;
  459. break;
  460. }
  461. return pcsz;
  462. }
  463. LPCTSTR GetStringFromBasicIMState(long lK)
  464. {
  465. LPCTSTR pcsz;
  466. static TCHAR sz[MAX_PATH];
  467. switch (lK)
  468. {
  469. STRING_CASE(BIMSTATE_ONLINE);
  470. STRING_CASE(BIMSTATE_OFFLINE);
  471. STRING_CASE(BIMSTATE_INVISIBLE);
  472. STRING_CASE(BIMSTATE_BUSY);
  473. STRING_CASE(BIMSTATE_UNKNOWN);
  474. STRING_CASE(BIMSTATE_BE_RIGHT_BACK);
  475. STRING_CASE(BIMSTATE_IDLE);
  476. STRING_CASE(BIMSTATE_AWAY);
  477. STRING_CASE(BIMSTATE_ON_THE_PHONE);
  478. STRING_CASE(BIMSTATE_OUT_TO_LUNCH);
  479. STRING_CASE(BIMSTATE_LOCAL_FINDING_SERVER);
  480. STRING_CASE(BIMSTATE_LOCAL_CONNECTING_TO_SERVER);
  481. STRING_CASE(BIMSTATE_LOCAL_SYNCHRONIZING_WITH_SERVER);
  482. STRING_CASE(BIMSTATE_LOCAL_DISCONNECTING_FROM_SERVER);
  483. default:
  484. wsprintf(sz, _T("(unknown) [0x%08X]"), lK);
  485. pcsz = sz;
  486. break;
  487. }
  488. return pcsz;
  489. }
  490. LPCTSTR GetStringFromLockAndKeyStatus(long lK)
  491. {
  492. LPCTSTR pcsz;
  493. static TCHAR sz[MAX_PATH];
  494. switch (lK)
  495. {
  496. STRING_CASE(LOCK_NOTINITIALIZED);
  497. STRING_CASE(LOCK_INITIALIZED);
  498. STRING_CASE(LOCK_PENDINGRESULT);
  499. STRING_CASE(LOCK_UNLOCKED);
  500. STRING_CASE(LOCK_UNLOCKFAILED);
  501. default:
  502. wsprintf(sz, _T("(unknown) [0x%08X]"), lK);
  503. pcsz = sz;
  504. break;
  505. }
  506. return pcsz;
  507. }
  508. LPCTSTR GetStringFromMessagePrivacy(long lK)
  509. {
  510. LPCTSTR pcsz;
  511. static TCHAR sz[MAX_PATH];
  512. switch (lK)
  513. {
  514. STRING_CASE(MMSGPRIVACY_BLOCK_LIST_EXCLUDED);
  515. STRING_CASE(MMSGPRIVACY_ALLOW_LIST_ONLY);
  516. default:
  517. wsprintf(sz, _T("(unknown) %i"), lK);
  518. pcsz = sz;
  519. break;
  520. }
  521. return pcsz;
  522. }
  523. LPCTSTR GetStringFromPrompt(long lK)
  524. {
  525. LPCTSTR pcsz;
  526. static TCHAR sz[MAX_PATH];
  527. switch (lK)
  528. {
  529. STRING_CASE(MPROMPT_YES_IF_NOT_ALLOWED_OR_BLOCKED);
  530. STRING_CASE(MPROMPT_NO_ADD_TO_ALLOW);
  531. default:
  532. wsprintf(sz, _T("(unknown) %i"), lK);
  533. pcsz = sz;
  534. break;
  535. }
  536. return pcsz;
  537. }
  538. LPCTSTR GetStringFromLocalOption(long lK)
  539. {
  540. LPCTSTR pcsz;
  541. static TCHAR sz[MAX_PATH];
  542. switch (lK)
  543. {
  544. STRING_CASE(MLOPT_PROXY_STATE);
  545. STRING_CASE(MLOPT_PROXY_TYPE);
  546. STRING_CASE(MLOPT_SOCKS4_SERVER);
  547. STRING_CASE(MLOPT_SOCKS5_SERVER);
  548. STRING_CASE(MLOPT_HTTPS_SERVER);
  549. STRING_CASE(MLOPT_SOCKS4_PORT);
  550. STRING_CASE(MLOPT_SOCKS5_PORT);
  551. STRING_CASE(MLOPT_HTTPS_PORT);
  552. STRING_CASE(MLOPT_SOCKS5_USERNAME);
  553. STRING_CASE(MLOPT_SOCKS5_PASSWORD);
  554. STRING_CASE(MLOPT_SERVER_NAME);
  555. STRING_CASE(MLOPT_ENABLE_IDLE_DETECT);
  556. STRING_CASE(MLOPT_IDLE_THRESHOLD);
  557. STRING_CASE(MLOPT_IDLE_DETECTABLE);
  558. STRING_CASE(MLOPT_SS_DETECTABLE);
  559. default:
  560. wsprintf(sz, _T("(unknown) %i"), lK);
  561. pcsz = sz;
  562. break;
  563. }
  564. return pcsz;
  565. }
  566. LPCTSTR GetStringFromInboxFolder(long lK)
  567. {
  568. LPCTSTR pcsz;
  569. static TCHAR sz[MAX_PATH];
  570. switch (lK)
  571. {
  572. STRING_CASE(MFOLDER_INBOX);
  573. STRING_CASE(MFOLDER_ALL_OTHER_FOLDERS);
  574. default:
  575. wsprintf(sz, _T("(unknown) %i"), lK);
  576. pcsz = sz;
  577. break;
  578. }
  579. return pcsz;
  580. }
  581. LPCTSTR GetStringFromProxyType(long lK)
  582. {
  583. LPCTSTR pcsz;
  584. static TCHAR sz[MAX_PATH];
  585. switch (lK)
  586. {
  587. STRING_CASE(MPROXYTYPE_NO_PROXY);
  588. STRING_CASE(MPROXYTYPE_SOCKS4);
  589. STRING_CASE(MPROXYTYPE_SOCKS5);
  590. STRING_CASE(MPROXYTYPE_HTTPS);
  591. default:
  592. wsprintf(sz, _T("(unknown) %i"), lK);
  593. pcsz = sz;
  594. break;
  595. }
  596. return pcsz;
  597. }
  598. // =====================================================================================
  599. // HrEncode64
  600. // =====================================================================================
  601. static char Ebase_64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/ ";
  602. HRESULT HrEncode64 (LPSTR lpszTextIn, LPSTR lpszTextOut, DWORD dwOutLen)
  603. {
  604. //DebugEntry (CSignOnDlg::HrEncode64);
  605. _ASSERTE(lpszTextIn && lpszTextOut);
  606. HRESULT hr = S_OK;
  607. ULONG cbTextIn, i, cbTextOut = 0;
  608. cbTextIn = lstrlenA(lpszTextIn);
  609. if (dwOutLen < (cbTextIn * 4/3 + 5)) // 5 for 3 extra chars max + \0 + 1 for round down on 4/3
  610. {
  611. //ALMLogPrint (LOGERROR,_T("CSignOnDlg::HrEncode64--lpszTextOut not long enough"));
  612. hr = E_FAIL;
  613. }
  614. if (SUCCEEDED(hr))
  615. {
  616. // Encodes 3 characters at a time
  617. for (i=0; i<cbTextIn; i+=3)
  618. {
  619. UCHAR ch[3];
  620. ch[0] = lpszTextIn[i];
  621. ch[1] = (i+1 < cbTextIn) ? lpszTextIn[i+1] : '\0';
  622. ch[2] = (i+2 < cbTextIn) ? lpszTextIn[i+2] : '\0';
  623. lpszTextOut[cbTextOut++] = Ebase_64[ ( ch[0] >> 2 ) & 0x3F ];
  624. lpszTextOut[cbTextOut++] = Ebase_64[ ( ch[0] << 4 | ch[1] >> 4 ) & 0x3F ];
  625. if (i+1 < cbTextIn)
  626. lpszTextOut[cbTextOut++] = Ebase_64[ ( ch[1] << 2 | ch[2] >> 6 ) & 0x3F ];
  627. else
  628. lpszTextOut[cbTextOut++] = '=';
  629. if (i+2 < cbTextIn)
  630. lpszTextOut[cbTextOut++] = Ebase_64[ ( ch[2] ) & 0x3F ];
  631. else
  632. lpszTextOut[cbTextOut++] = '=';
  633. }
  634. // Null terminate so we know when to stop.
  635. lpszTextOut[cbTextOut++] = '\0';
  636. }
  637. //DebugExitHRESULT (CSignOnDlg::HrEncode64, hr);
  638. return hr;
  639. }
  640. //****************************************************************************
  641. // LPTSTR AllocLPTSTR (ULONG cb)
  642. //
  643. // History:
  644. // Wed 17-Apr-1996 11:14:08 -by- Viroon Touranachun [viroont]
  645. // Created.
  646. //****************************************************************************
  647. LPTSTR AllocLPTSTR (ULONG cb)
  648. {
  649. LPTSTR psz = NULL;
  650. psz = (LPTSTR)LocalAlloc(LMEM_FIXED, cb*sizeof(TCHAR));
  651. return psz;
  652. }
  653. //////////////////////////////////////////////////////////////////////
  654. // History: Stolen from...
  655. // Wed 17-Apr-1996 11:14:08 -by- Viroon Touranachun [viroont]
  656. // Created.
  657. //////////////////////////////////////////////////////////////////////
  658. HRESULT LPTSTR_to_BSTR (BSTR *pbstr, LPCTSTR psz)
  659. {
  660. #ifndef UNICODE
  661. BSTR bstr = NULL;
  662. int i = 0;
  663. HRESULT hr;
  664. // compute the length of the required BSTR
  665. //
  666. i = MultiByteToWideChar(CP_ACP, 0, psz, -1, NULL, 0);
  667. if (i <= 0)
  668. {
  669. return E_UNEXPECTED;
  670. };
  671. // allocate the widestr, +1 for terminating null
  672. //
  673. bstr = SysAllocStringLen(NULL, i-1); // SysAllocStringLen adds 1
  674. if (bstr != NULL)
  675. {
  676. MultiByteToWideChar(CP_ACP, 0, psz, -1, (LPWSTR)bstr, i);
  677. ((LPWSTR)bstr)[i - 1] = 0;
  678. *pbstr = bstr;
  679. hr = S_OK;
  680. }
  681. else
  682. {
  683. hr = E_OUTOFMEMORY;
  684. };
  685. return hr;
  686. #else
  687. BSTR bstr = NULL;
  688. bstr = SysAllocString(psz);
  689. if (bstr != NULL)
  690. {
  691. *pbstr = bstr;
  692. return S_OK;
  693. }
  694. else
  695. {
  696. return E_OUTOFMEMORY;
  697. };
  698. #endif // UNICODE
  699. }
  700. //
  701. // FUNCTION: OutMessageBox(LPCTSTR sFormat, ...)
  702. //
  703. // PURPOSE: Pop up a message box with the error message.
  704. //
  705. BOOL _cdecl OutMessageBox(LPCTSTR sFormat, ...)
  706. {
  707. va_list VarArg;
  708. TCHAR sText[MAXBUFSIZE];
  709. DWORD nBytesToWrite;
  710. va_start(VarArg,sFormat);
  711. nBytesToWrite = wvsprintf(sText, sFormat, VarArg);
  712. MessageBox(NULL, sText, TEXT("RA Debug"), MB_OK);
  713. return TRUE;
  714. }
  715. BOOL TraceInit()
  716. {
  717. static BOOL bInit = FALSE;
  718. static BOOL bTrace = FALSE;
  719. if (!bInit)
  720. {
  721. DWORD dwValue = 0, dwSize=sizeof(DWORD);
  722. HKEY hKey = NULL;
  723. bInit = TRUE;
  724. if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  725. _T("SOFTWARE\\Microsoft\\PCHealth\\HelpCtr\\SAFSessionResolver"),
  726. 0,
  727. KEY_READ,
  728. &hKey))
  729. {
  730. if (ERROR_SUCCESS == RegQueryValueEx(hKey, _T("DebugSpew"), NULL, NULL, (BYTE*)&dwValue, &dwSize))
  731. bTrace = !!dwValue;
  732. RegCloseKey(hKey);
  733. }
  734. }
  735. return bTrace;
  736. }
  737. BOOL TraceSpewA(LPCSTR sFormat, ...)
  738. {
  739. OutputDebugStringW(L"TraceSpewA: Not implemented yet");
  740. return TRUE;
  741. }
  742. BOOL TraceSpewW(WCHAR* sFormat, ...)
  743. {
  744. va_list VarArg;
  745. WCHAR sText[MAXBUFSIZE];
  746. DWORD nBytesToWrite;
  747. if (TraceInit())
  748. {
  749. va_start(VarArg,sFormat);
  750. swprintf(sText, L"\nRA:\r");
  751. nBytesToWrite = vswprintf(&sText[5], sFormat, VarArg);
  752. OutputDebugStringW(sText);
  753. }
  754. return TRUE;
  755. }
  756. int GetDigit(int iLen)
  757. {
  758. int iRet = 0;
  759. while (iLen >= 1)
  760. {
  761. iRet ++;
  762. iLen /= 10;
  763. }
  764. return iRet;
  765. }