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.

194 lines
3.8 KiB

  1. /* ----------------------------------------------------------------------
  2. Module: ULS.DLL (Service Provider)
  3. File: splprot.cpp
  4. Content: This file contains the local protocol object.
  5. History:
  6. 10/15/96 Chu, Lon-Chan [lonchanc]
  7. Created.
  8. Copyright (c) Microsoft Corporation 1996-1997
  9. ---------------------------------------------------------------------- */
  10. #include "ulsp.h"
  11. #include "spinc.h"
  12. const TCHAR *c_apszProtStdAttrNames[COUNT_ENUM_PROTATTR] =
  13. {
  14. TEXT ("sprotid"),
  15. TEXT ("sprotmimetype"),
  16. TEXT ("sport"),
  17. };
  18. /* ---------- public methods ----------- */
  19. SP_CProtocol::
  20. SP_CProtocol ( SP_CClient *pClient )
  21. :
  22. m_cRefs (0), // Reference count
  23. m_uSignature (PROTOBJ_SIGNATURE) // Protocol object's signature
  24. {
  25. MyAssert (pClient != NULL);
  26. m_pClient = pClient;
  27. // Clean up the scratch buffer for caching pointers to attribute values
  28. //
  29. ::ZeroMemory (&m_ProtInfo, sizeof (m_ProtInfo));
  30. // Indicate this protocol is not registered yet
  31. //
  32. SetRegNone ();
  33. }
  34. SP_CProtocol::
  35. ~SP_CProtocol ( VOID )
  36. {
  37. // Invalidate the client object's signature
  38. //
  39. m_uSignature = (ULONG) -1;
  40. // Free cached strings
  41. //
  42. MemFree (m_ProtInfo.apszStdAttrValues[ENUM_PROTATTR_NAME]);
  43. MemFree (m_ProtInfo.apszStdAttrValues[ENUM_PROTATTR_MIME_TYPE]);
  44. }
  45. ULONG SP_CProtocol::
  46. AddRef ( VOID )
  47. {
  48. ::InterlockedIncrement (&m_cRefs);
  49. return m_cRefs;
  50. }
  51. ULONG SP_CProtocol::
  52. Release ( VOID )
  53. {
  54. MyAssert (m_cRefs != 0);
  55. ::InterlockedDecrement (&m_cRefs);
  56. ULONG cRefs = m_cRefs;
  57. if (cRefs == 0)
  58. delete this;
  59. return cRefs;
  60. }
  61. HRESULT SP_CProtocol::
  62. Register (
  63. ULONG uRespID,
  64. LDAP_PROTINFO *pInfo )
  65. {
  66. MyAssert (pInfo != NULL);
  67. // Cache protocol info
  68. //
  69. CacheProtInfo (pInfo);
  70. // Get protocol name
  71. //
  72. TCHAR *pszProtName = m_ProtInfo.apszStdAttrValues[ENUM_PROTATTR_NAME];
  73. if (! MyIsGoodString (pszProtName))
  74. {
  75. MyAssert (FALSE);
  76. return ILS_E_PARAMETER;
  77. }
  78. // Add the protocol object
  79. //
  80. return m_pClient->AddProtocol (WM_ILS_REGISTER_PROTOCOL, uRespID, this);
  81. }
  82. HRESULT SP_CProtocol::
  83. UnRegister ( ULONG uRespID )
  84. {
  85. // If it is not registered on the server,
  86. // the simply report success
  87. //
  88. if (! IsRegRemotely ())
  89. {
  90. SetRegNone ();
  91. PostMessage (g_hWndNotify, WM_ILS_UNREGISTER_PROTOCOL, uRespID, S_OK);
  92. return S_OK;
  93. }
  94. // Indicate that we are not registered at all
  95. //
  96. SetRegNone ();
  97. // remove the protocol object
  98. //
  99. return m_pClient->RemoveProtocol (WM_ILS_UNREGISTER_PROTOCOL, uRespID, this);
  100. }
  101. HRESULT SP_CProtocol::
  102. SetAttributes (
  103. ULONG uRespID,
  104. LDAP_PROTINFO *pInfo )
  105. {
  106. MyAssert (pInfo != NULL);
  107. // Cache protocol info
  108. //
  109. CacheProtInfo (pInfo);
  110. // remove the protocol object
  111. //
  112. return m_pClient->UpdateProtocols (WM_ILS_SET_PROTOCOL_INFO, uRespID, this);
  113. }
  114. /* ---------- protected methods ----------- */
  115. /* ---------- private methods ----------- */
  116. VOID SP_CProtocol::
  117. CacheProtInfo ( LDAP_PROTINFO *pInfo )
  118. {
  119. MyAssert (pInfo != NULL);
  120. // Free previous allocations
  121. //
  122. MemFree (m_ProtInfo.apszStdAttrValues[ENUM_PROTATTR_NAME]);
  123. MemFree (m_ProtInfo.apszStdAttrValues[ENUM_PROTATTR_MIME_TYPE]);
  124. // Clean up the buffer
  125. //
  126. ZeroMemory (&m_ProtInfo, sizeof (m_ProtInfo));
  127. // Start to cache protocol standard attributes
  128. //
  129. if (pInfo->uOffsetName != INVALID_OFFSET)
  130. {
  131. m_ProtInfo.apszStdAttrValues[ENUM_PROTATTR_NAME] =
  132. My_strdup ((TCHAR *) (((BYTE *) pInfo) + pInfo->uOffsetName));
  133. m_ProtInfo.dwFlags |= PROTOBJ_F_NAME;
  134. }
  135. if (pInfo->uPortNumber != INVALID_OFFSET)
  136. {
  137. m_ProtInfo.apszStdAttrValues[ENUM_PROTATTR_PORT_NUMBER] = &m_ProtInfo.szPortNumber[0];
  138. ::GetLongString (pInfo->uPortNumber, &m_ProtInfo.szPortNumber[0]);
  139. m_ProtInfo.dwFlags |= PROTOBJ_F_PORT_NUMBER;
  140. }
  141. if (pInfo->uOffsetMimeType != INVALID_OFFSET)
  142. {
  143. m_ProtInfo.apszStdAttrValues[ENUM_PROTATTR_MIME_TYPE] =
  144. My_strdup ((TCHAR *) (((BYTE *) pInfo) + pInfo->uOffsetMimeType));
  145. m_ProtInfo.dwFlags |= PROTOBJ_F_MIME_TYPE;
  146. }
  147. }