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.

221 lines
6.4 KiB

  1. /*----------------------------------------------------------------------------
  2. * File: RTP_HASH.C
  3. * Product: RTP/RTCP implementation
  4. * Description: Associate sockets/streams with their RTP Session in a hash table
  5. *
  6. *
  7. * INTEL Corporation Proprietary Information
  8. * This listing is supplied under the terms of a license agreement with
  9. * Intel Corporation and may not be copied nor disclosed except in
  10. * accordance with the terms of that agreement.
  11. * Copyright (c) 1995 Intel Corporation.
  12. *--------------------------------------------------------------------------*/
  13. #include "rrcm.h"
  14. /*---------------------------------------------------------------------------
  15. / Global Variables
  16. /--------------------------------------------------------------------------*/
  17. extern PRTP_CONTEXT pRTPContext;
  18. /*---------------------------------------------------------------------------
  19. / External Variables
  20. /--------------------------------------------------------------------------*/
  21. /*----------------------------------------------------------------------------
  22. * Function : createHashEntry
  23. * Description: Adds stream unique socket ID to hash table.
  24. *
  25. * Input : pSession : RTP Session containing the stream
  26. * socket : unique socket ID for stream
  27. *
  28. * Return: RRCM_NoError = OK.
  29. * Otherwise(!=0) = Initialization Error.
  30. ---------------------------------------------------------------------------*/
  31. DWORD createHashEntry (PRTP_SESSION pSession,
  32. SOCKET socket)
  33. {
  34. PRTP_HASH_LIST pNewCell;
  35. WORD hashEntry;
  36. DWORD dwStatus = RRCM_NoError;
  37. DWORD hashTableEntries = NUM_RTP_HASH_SESS;
  38. IN_OUT_STR ("RTP : Enter createHashEntry()\n");
  39. // Get a PRTP Buffer from the free list and assign the values
  40. pNewCell = (PRTP_HASH_LIST)removePcktFromTail(
  41. (PLINK_LIST)&pRTPContext->pRTPHashList,
  42. &pRTPContext->critSect);
  43. if (pNewCell == NULL)
  44. {
  45. if ( allocateLinkedList (&pRTPContext->pRTPHashList,
  46. pRTPContext->hHashFreeList,
  47. &hashTableEntries,
  48. sizeof(RTP_HASH_LIST),
  49. &pRTPContext->critSect) == RRCM_NoError)
  50. {
  51. pNewCell = (PRTP_HASH_LIST)removePcktFromTail (
  52. (PLINK_LIST)&pRTPContext->pRTPHashList,
  53. &pRTPContext->critSect);
  54. }
  55. }
  56. if (pNewCell != NULL)
  57. {
  58. pNewCell->RTPsocket = socket;
  59. pNewCell->pSession = pSession;
  60. // Get entry in table
  61. hashEntry = socket & HASH_MODULO;
  62. // Just insert the entry at the head of list
  63. addToHeadOfList (
  64. (PLINK_LIST)&pRTPContext->RTPHashTable[hashEntry].RTPHashLink,
  65. (PLINK_LIST)pNewCell,
  66. &pRTPContext->critSect);
  67. }
  68. else
  69. dwStatus = RRCMError_RTPResources;
  70. IN_OUT_STR ("RTP : Exit createHashEntry()\n");
  71. return (dwStatus);
  72. }
  73. /*----------------------------------------------------------------------------
  74. * Function : deleteHashEntry
  75. * Description: Searches hash table based on unique socket. Deletes session from
  76. * hash table and returns buffer to free list
  77. *
  78. * Input : socket: unique socket ID for stream
  79. *
  80. *
  81. * Return: RRCM_NoError = OK.
  82. * Otherwise(!=0) = Deletion Error.
  83. ---------------------------------------------------------------------------*/
  84. DWORD deleteHashEntry (SOCKET socket)
  85. {
  86. PRTP_HASH_LIST pNewCell;
  87. WORD hashEntry;
  88. DWORD dwStatus = RRCMError_RTPStreamNotFound;
  89. IN_OUT_STR ("RTP : Enter deleteHashEntry()\n");
  90. // Get entry in table
  91. hashEntry = socket & HASH_MODULO;
  92. // Search for entry in table. if found, remove from RTPHashTable and insert
  93. // back in free list
  94. for (pNewCell = (PRTP_HASH_LIST)pRTPContext->RTPHashTable[hashEntry].RTPHashLink.prev;
  95. pNewCell != NULL;
  96. pNewCell = (PRTP_HASH_LIST)pNewCell->RTPHashLink.next)
  97. {
  98. if (pNewCell->RTPsocket == socket)
  99. {
  100. EnterCriticalSection (&pRTPContext->critSect);
  101. if (pNewCell->RTPHashLink.prev == NULL)
  102. {
  103. // first entry in the queue - update the tail pointer
  104. pRTPContext->RTPHashTable[hashEntry].RTPHashLink.prev =
  105. pNewCell->RTPHashLink.next;
  106. // check if only one entry in the list
  107. if (pNewCell->RTPHashLink.next == NULL)
  108. pRTPContext->RTPHashTable[hashEntry].RTPHashLink.next = NULL;
  109. else
  110. (pNewCell->RTPHashLink.next)->prev = NULL;
  111. }
  112. else if (pNewCell->RTPHashLink.next == NULL)
  113. {
  114. // last entry in the queue - update the head pointer
  115. // this was the last entry in the queue
  116. pRTPContext->RTPHashTable[hashEntry].RTPHashLink.next =
  117. pNewCell->RTPHashLink.prev;
  118. (pNewCell->RTPHashLink.prev)->next = NULL;
  119. }
  120. else
  121. {
  122. // in the middle of the list - link around it
  123. (pNewCell->RTPHashLink.prev)->next = pNewCell->RTPHashLink.next;
  124. (pNewCell->RTPHashLink.next)->prev = pNewCell->RTPHashLink.prev;
  125. }
  126. LeaveCriticalSection (&pRTPContext->critSect);
  127. addToHeadOfList ((PLINK_LIST)&pRTPContext->pRTPHashList,
  128. (PLINK_LIST)pNewCell,
  129. &pRTPContext->critSect);
  130. dwStatus = RRCM_NoError;
  131. break;
  132. }
  133. }
  134. if (dwStatus != RRCM_NoError)
  135. {
  136. RRCM_DBG_MSG ("RTP : ERROR - DeleteHashEntry()", 0,
  137. __FILE__, __LINE__, DBG_ERROR);
  138. }
  139. IN_OUT_STR ("RTP : Exit deleteHashEntry()\n");
  140. return (dwStatus);
  141. }
  142. /*----------------------------------------------------------------------------
  143. * Function : findSessionID
  144. * Description: Searches hash table based on unique socket to identify session ID
  145. *
  146. * Input : socket: unique socket ID for stream
  147. *
  148. *
  149. * Return: Session ptr = OK.
  150. * NULL = Search Error.
  151. ---------------------------------------------------------------------------*/
  152. PRTP_SESSION findSessionID (SOCKET socket)
  153. {
  154. PRTP_HASH_LIST pNewCell;
  155. WORD hashEntry;
  156. PRTP_SESSION pSession = NULL;
  157. IN_OUT_STR ("RTP : Enter findSessionID()\n");
  158. // Get entry in table
  159. hashEntry = socket & HASH_MODULO;
  160. // Search for entry in table.
  161. // If found, remove from RTPHashTable and insert back in free list
  162. for (pNewCell = (PRTP_HASH_LIST)pRTPContext->RTPHashTable[hashEntry].RTPHashLink.prev;
  163. pNewCell != NULL;
  164. pNewCell = (PRTP_HASH_LIST)pNewCell->RTPHashLink.next)
  165. {
  166. if (pNewCell->RTPsocket == socket)
  167. {
  168. pSession = pNewCell->pSession;
  169. break;
  170. }
  171. }
  172. IN_OUT_STR ("RTP : Exit findSessionID()\n");
  173. return (pSession);
  174. }
  175. // [EOF]