Source code of Windows XP (NT5)
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.

128 lines
2.2 KiB

  1. /*++
  2. Copyright (c) 1999-2000 Microsoft Corporation
  3. Module Name:
  4. parseaddr
  5. Abstract:
  6. Misc. RD Utils that require reremotedesktopchannelsObject.h
  7. Author:
  8. HueiWang
  9. Revision History:
  10. --*/
  11. #ifdef TRC_FILE
  12. #undef TRC_FILE
  13. #endif
  14. #define TRC_FILE "_parse"
  15. #include "parseaddr.h"
  16. HRESULT
  17. ParseAddressList(
  18. IN BSTR addressListString,
  19. OUT ServerAddressList& addressList
  20. )
  21. /*++
  22. Description:
  23. Parse address list string in the form of "172.31.254.130:3389;hueiwangsalem4"
  24. to ServerList structure.
  25. Parameters:
  26. addressString : Pointer to address list string.
  27. addressList : Return list of parsed address structure.
  28. Return:
  29. S_OK or error code.
  30. --*/
  31. {
  32. BSTR tmp;
  33. WCHAR *nextTok;
  34. WCHAR *port;
  35. DWORD result = ERROR_SUCCESS;
  36. ServerAddress address;
  37. // clear entire list
  38. addressList.clear();
  39. tmp = SysAllocString( addressListString );
  40. if( NULL == tmp ) {
  41. result = ERROR_OUTOFMEMORY;
  42. goto CLEANUPANDEXIT;
  43. }
  44. while (tmp && *tmp) {
  45. nextTok = wcschr( tmp, L';' );
  46. if( NULL != nextTok ) {
  47. *nextTok = NULL;
  48. nextTok++;
  49. }
  50. //
  51. // ICS library might return us ;;
  52. //
  53. if( 0 != lstrlen(tmp) ) {
  54. port = wcschr( tmp, L':' );
  55. if( NULL != port ) {
  56. *port = NULL;
  57. port++;
  58. address.portNumber = _wtoi(port);
  59. }
  60. else {
  61. address.portNumber = 0;
  62. }
  63. //
  64. // Make sure we have server name/ipaddress
  65. //
  66. if( 0 != lstrlen(tmp) ) {
  67. // ICS might return ;;
  68. address.ServerName = tmp;
  69. try {
  70. addressList.push_back( address );
  71. }
  72. catch(CRemoteDesktopException x) {
  73. result = ERROR_OUTOFMEMORY;
  74. }
  75. if( ERROR_SUCCESS != result ) {
  76. goto CLEANUPANDEXIT;
  77. }
  78. }
  79. }
  80. tmp = nextTok;
  81. }
  82. CLEANUPANDEXIT:
  83. if( NULL != tmp ) {
  84. SysFreeString(tmp);
  85. }
  86. if( ERROR_SUCCESS != result ) {
  87. addressList.clear();
  88. }
  89. return result;
  90. }