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.

136 lines
2.6 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 = NULL;
  33. BSTR tmpBufPtr = NULL;
  34. WCHAR *nextTok;
  35. WCHAR *port;
  36. DWORD result = ERROR_SUCCESS;
  37. ServerAddress address;
  38. // clear entire list
  39. addressList.clear();
  40. tmp = SysAllocString( addressListString );
  41. if( NULL == tmp ) {
  42. result = ERROR_OUTOFMEMORY;
  43. goto CLEANUPANDEXIT;
  44. }
  45. tmpBufPtr = tmp;
  46. while (tmp && *tmp) {
  47. nextTok = wcschr( tmp, L';' );
  48. if( NULL != nextTok ) {
  49. *nextTok = NULL;
  50. nextTok++;
  51. }
  52. //
  53. // ICS library might return us ;;
  54. //
  55. if( 0 != lstrlen(tmp) ) {
  56. port = wcschr( tmp, L':' );
  57. if( NULL != port ) {
  58. *port = NULL;
  59. port++;
  60. address.portNumber = _wtoi(port);
  61. }
  62. else {
  63. address.portNumber = 0;
  64. }
  65. //
  66. // Make sure we have server name/ipaddress
  67. //
  68. if( 0 != lstrlen(tmp) ) {
  69. // ICS might return ;;
  70. address.ServerName = tmp;
  71. if( address.ServerName.Length() == 0 ) {
  72. result = ERROR_OUTOFMEMORY;
  73. goto CLEANUPANDEXIT;
  74. }
  75. try {
  76. addressList.push_back( address );
  77. }
  78. catch(CRemoteDesktopException x) {
  79. result = ERROR_OUTOFMEMORY;
  80. }
  81. if( ERROR_SUCCESS != result ) {
  82. goto CLEANUPANDEXIT;
  83. }
  84. }
  85. }
  86. tmp = nextTok;
  87. }
  88. CLEANUPANDEXIT:
  89. if( NULL != tmpBufPtr ) {
  90. SysFreeString(tmpBufPtr);
  91. }
  92. if( ERROR_SUCCESS != result ) {
  93. addressList.clear();
  94. }
  95. return result;
  96. }