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.

854 lines
23 KiB

  1. /*++
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. globals.h
  5. Abstract:
  6. Global definitions for H.323 TAPI Service Provider.
  7. Author:
  8. Nikhil Bobde (NikhilB)
  9. Revision History:
  10. --*/
  11. // build control defines
  12. #define STRICT
  13. #define UNICODE
  14. #define _UNICODE
  15. #define VC_EXTRALEAN
  16. #define H323_USE_PRIVATE_IO_THREAD 1
  17. //
  18. // Include files:SDK
  19. //
  20. #include <nt.h>
  21. #include <ntrtl.h>
  22. #include <nturtl.h>
  23. #include <winsock2.h>
  24. #include <mswsock.h>
  25. #include <tapi3.h>
  26. #include <tspi.h>
  27. #include <crtdbg.h>
  28. #include <stdio.h>
  29. #include <tchar.h>
  30. #include <rtutils.h>
  31. // Project
  32. #include <h225asn.h>
  33. #include <tspmspif.h>
  34. typedef class CH323Call* PH323_CALL;
  35. typedef class H323_CONFERENCE* PH323_CONFERENCE;
  36. #define CALL_ALERTING_TIMEOUT 180000
  37. #define Q931_CALL_PORT 1720 // Endpoint TCP Call Signalling Port
  38. //
  39. // String definitions
  40. //
  41. #define H323_MAXCALLSPERLINE 32768 //limited by 15 bit CRV sent to the Gatekeeper
  42. #define H323_MAXLINENAMELEN 16
  43. #define H323_MAXPORTNAMELEN 16
  44. #define H323_MAXADDRNAMELEN (H323_MAXLINENAMELEN + H323_MAXPORTNAMELEN)
  45. #define H323_MAXPATHNAMELEN 256
  46. #define H323_MAXDESTNAMELEN 256
  47. #define MAX_E164_ADDR_LEN 127
  48. #define MAX_H323_ADDR_LEN 255
  49. #define H323_UIDLL _T("H323.TSP")
  50. #define H323_TSPDLL _T("H323.TSP")
  51. #define H323_WINSOCKVERSION MAKEWORD(2,0)
  52. #define H221_COUNTRY_CODE_USA 0xB5
  53. #define H221_COUNTRY_EXT_USA 0x00
  54. #define H221_MFG_CODE_MICROSOFT 0x534C
  55. #define H323_PRODUCT_ID "Microsoft TAPI\0"
  56. #define H323_PRODUCT_VERSION "Version 3.1\0"
  57. #define MSP_HANDLE_UNKNOWN 0
  58. //
  59. // Registry key definitions
  60. //
  61. #define REGSTR_PATH_WINDOWS_CURRENTVERSION TEXT("Software\\Microsoft\\Windows\\CurrentVersion")
  62. #define TAPI_REGKEY_ROOT REGSTR_PATH_WINDOWS_CURRENTVERSION TEXT("\\Telephony")
  63. #define TAPI_REGKEY_PROVIDERS TAPI_REGKEY_ROOT TEXT("\\Providers")
  64. #define TAPI_REGVAL_NUMPROVIDERS TEXT("NumProviders")
  65. #define H323_SUBKEY TEXT("H323TSP")
  66. #define H323_REGKEY_ROOT REGSTR_PATH_WINDOWS_CURRENTVERSION TEXT("\\") H323_SUBKEY
  67. #define H323_REGVAL_Q931ALERTINGTIMEOUT TEXT("Q931AlertingTimeout")
  68. #define H323_REGVAL_Q931LISTENPORT TEXT("Q931ListenPort")
  69. #define H323_REGVAL_GATEWAYENABLED TEXT("H323GatewayEnabled")
  70. #define H323_REGVAL_GATEWAYADDR TEXT("H323GatewayAddress")
  71. #define H323_REGVAL_PROXYENABLED TEXT("H323ProxyEnabled")
  72. #define H323_REGVAL_PROXYADDR TEXT("H323ProxyAddress")
  73. #define H323_REGVAL_GKENABLED TEXT("H323GatekeeperEnabled")
  74. #define H323_REGVAL_GKLOGON_PHONEENABLED TEXT("H323GKLogOnPhoneNumberEnabled")
  75. #define H323_REGVAL_GKLOGON_ACCOUNTENABLED TEXT("H323GKLogOnAccountNameEnabled")
  76. #define H323_REGVAL_GKADDR TEXT("H323GatekeeperAddress")
  77. #define H323_REGVAL_GKLOGON_PHONE TEXT("H323GatekeeperLogOnPhoneNumber")
  78. #define H323_REGVAL_GKLOGON_ACCOUNT TEXT("H323GatekeeperLogOnAccountName")
  79. #define H323_REGVAL_DEBUGLEVEL TEXT("DebugLevel")
  80. //
  81. // Global Definitions
  82. //
  83. // CCRC_CALL_REJECTED reason codes (includes cause values)
  84. #define H323_REJECT_NO_BANDWIDTH 1
  85. #define H323_REJECT_GATEKEEPER_RESOURCES 2
  86. #define H323_REJECT_UNREACHABLE_DESTINATION 3
  87. #define H323_REJECT_DESTINATION_REJECTION 4
  88. #define H323_REJECT_INVALID_REVISION 5
  89. #define H323_REJECT_NO_PERMISSION 6
  90. #define H323_REJECT_UNREACHABLE_GATEKEEPER 7
  91. #define H323_REJECT_GATEWAY_RESOURCES 8
  92. #define H323_REJECT_BAD_FORMAT_ADDRESS 9
  93. #define H323_REJECT_ADAPTIVE_BUSY 10
  94. #define H323_REJECT_IN_CONF 11
  95. #define H323_REJECT_ROUTE_TO_GATEKEEPER 12
  96. #define H323_REJECT_CALL_FORWARDED 13
  97. #define H323_REJECT_ROUTE_TO_MC 14
  98. #define H323_REJECT_UNDEFINED_REASON 15
  99. #define H323_REJECT_INTERNAL_ERROR 16 // Internal error occured in peer CS stack.
  100. #define H323_REJECT_NORMAL_CALL_CLEARING 17 // Normal call hangup
  101. #define H323_REJECT_USER_BUSY 18 // User is busy with another call
  102. #define H323_REJECT_NO_ANSWER 19 // Callee does not answer
  103. #define H323_REJECT_NOT_IMPLEMENTED 20 // Service has not been implemented
  104. #define H323_REJECT_MANDATORY_IE_MISSING 21 // Pdu missing mandatory ie
  105. #define H323_REJECT_INVALID_IE_CONTENTS 22 // Pdu ie was incorrect
  106. #define H323_REJECT_TIMER_EXPIRED 23 // Own timer expired
  107. #define H323_REJECT_CALL_DEFLECTION 24 // You deflected the call, so lets quit.
  108. #define H323_REJECT_GATEKEEPER_TERMINATED 25 // Gatekeeper terminated call
  109. // unicode character mask contants
  110. #define H323_ALIAS_H323_PHONE_CHARS L"0123456789#*,"
  111. #define H323_ODOTTO_CHARS L".0123456789"
  112. //
  113. //H450 Operation types
  114. //
  115. enum H450_OPERATION_TYPE
  116. {
  117. H450_INVOKE = 0x00000100,
  118. H450_RETURNRESULT = 0x00000200,
  119. H450_RETURNERROR = 0x00000400,
  120. H450_REJECT = 0x00000800,
  121. };
  122. //
  123. //H450 APDU types
  124. //
  125. enum H450_OPCODE
  126. {
  127. NO_H450_APDU = 0,
  128. H4503_DUMMYTYPERETURNRESULT_APDU = 50,
  129. H4503_RETURNERROR_APDU = 51,
  130. H4503_REJECT_APDU = 52,
  131. CHECKRESTRICTION_OPCODE = 18,
  132. CALLREROUTING_OPCODE = 19,
  133. DIVERTINGLEGINFO1_OPCODE = 20,
  134. DIVERTINGLEGINFO2_OPCODE = 21,
  135. DIVERTINGLEGINFO3_OPCODE = 22,
  136. CTIDENTIFY_OPCODE = 7,
  137. CTINITIATE_OPCODE = 9,
  138. CTSETUP_OPCODE = 10,
  139. HOLDNOTIFIC_OPCODE = 101,
  140. RETRIEVENOTIFIC_OPCODE = 102,
  141. REMOTEHOLD_OPCODE = 103,
  142. REMOTERETRIEVE_OPCODE = 104,
  143. CPREQUEST_OPCODE = 106,
  144. CPSETUP_OPCODE = 107,
  145. GROUPINDON_OPCODE = 108,
  146. GROUPINDOFF_OPCODE = 109,
  147. PICKREQU_OPCODE = 110,
  148. PICKUP_OPCODE = 111,
  149. PICKEXE_OPCODE = 112,
  150. CPNOTIFY_OPCODE = 113,
  151. CPICKUPNOTIFY_OPCODE = 114,
  152. };
  153. #define NO_INVOKEID 0x00000000
  154. //
  155. // Global Data Structures
  156. //
  157. // IP address in conventional 'dot' notation
  158. typedef struct
  159. {
  160. WORD wPort; // UDP or TCP port (host byte order)
  161. WCHAR cAddr[16]; // UNICODE zstring
  162. } H323_IP_Dot_t;
  163. // IP address in binary format
  164. typedef struct
  165. {
  166. WORD wPort; // UDP or TCP port (host byte order)
  167. DWORD dwAddr; // binary address (host byte order)
  168. } H323_IP_Binary_t;
  169. typedef enum
  170. {
  171. H323_ADDR_NOT_DEFINED = 0,
  172. H323_IP_DOMAIN_NAME ,
  173. H323_IP_DOT ,
  174. H323_IP_BINARY
  175. } H323_ADDRTYPE;
  176. typedef struct _ADDR
  177. {
  178. H323_ADDRTYPE nAddrType;
  179. BOOL bMulticast;
  180. union
  181. {
  182. H323_IP_Dot_t IP_Dot;
  183. H323_IP_Binary_t IP_Binary;
  184. } Addr;
  185. } H323_ADDR, *PH323_ADDR;
  186. typedef struct
  187. {
  188. BYTE *pOctetString;
  189. WORD wOctetStringLength;
  190. } H323_OCTETSTRING, *PH323_OCTETSTRING;
  191. typedef struct ENDPOINT_ID
  192. {
  193. ASN1uint32_t length;
  194. ASN1char16_t value[H323_MAXPATHNAMELEN+ 1];
  195. } ENDPOINT_ID;
  196. typedef struct
  197. {
  198. H323_OCTETSTRING sData; // pointer to Octet data.
  199. BYTE bCountryCode;
  200. BYTE bExtension;
  201. WORD wManufacturerCode;
  202. } H323NonStandardData;
  203. #define H323_MAX_PRODUCT_LENGTH 256
  204. #define H323_MAX_VERSION_LENGTH 256
  205. #define H323_MAX_DISPLAY_LENGTH 82
  206. typedef struct
  207. {
  208. BYTE bCountryCode;
  209. BYTE bExtension;
  210. WORD wManufacturerCode;
  211. PH323_OCTETSTRING pProductNumber;
  212. PH323_OCTETSTRING pVersionNumber;
  213. } H323_VENDORINFO, *PH323_VENDORINFO;
  214. typedef struct
  215. {
  216. PH323_VENDORINFO pVendorInfo;
  217. BOOL bIsTerminal;
  218. BOOL bIsGateway; // for now, the H323 capability will be hard-coded.
  219. } H323_ENDPOINTTYPE, *PH323_ENDPOINTTYPE;
  220. typedef struct
  221. {
  222. WORD wType;
  223. WORD wPrefixLength;
  224. LPWSTR pPrefix;
  225. WORD wDataLength; // UNICODE character count
  226. LPWSTR pData; // UNICODE data.
  227. } H323_ALIASITEM, *PH323_ALIASITEM;
  228. typedef struct
  229. {
  230. WORD wCount;
  231. PH323_ALIASITEM pItems;
  232. } H323_ALIASNAMES, *PH323_ALIASNAMES;
  233. typedef struct _H323_FASTSTART
  234. {
  235. struct _H323_FASTSTART* next;
  236. DWORD length;
  237. BYTE* value;
  238. } H323_FASTSTART, *PH323_FASTSTART;
  239. struct H323_REGISTRY_SETTINGS
  240. {
  241. DWORD dwQ931AlertingTimeout; // q931 alerting timeout
  242. DWORD dwQ931ListenPort; // port to listen for incoming calls
  243. BOOL fIsGatewayEnabled; // if true, gateway enabled
  244. BOOL fIsProxyEnabled; // if true, proxy enabled
  245. BOOL fIsGKEnabled; // if true, GK enabled
  246. H323_ADDR gatewayAddr; // H.323 gateway address
  247. H323_ADDR proxyAddr; // H.323 proxy address
  248. SOCKADDR_IN saGKAddr; // H.323 gatekeeper address
  249. WCHAR wszGKLogOnPhone[H323_MAXDESTNAMELEN+1]; // phone number to register with the gatekeeper
  250. WCHAR wszGKLogOnAccount[H323_MAXDESTNAMELEN+1]; // account name to register with the gatekeeper
  251. BOOL fIsGKLogOnPhoneEnabled; // if true, gateway enabled
  252. BOOL fIsGKLogOnAccountEnabled; // if true, proxy enabled
  253. DWORD dwLogLevel; // debug log level
  254. //TCHAR szLogFile[MAX_PATH+1];
  255. };
  256. //
  257. // Global Variables
  258. //
  259. extern WCHAR g_pwszProviderInfo[];
  260. extern WCHAR g_pwszLineName[];
  261. extern LINEEVENT g_pfnLineEventProc;
  262. extern HINSTANCE g_hInstance;
  263. extern HANDLE g_hCanUnloadDll;
  264. extern HANDLE g_hEventLogSource;
  265. extern DWORD g_dwLineDeviceIDBase;
  266. extern DWORD g_dwPermanentProviderID;
  267. extern H323_REGISTRY_SETTINGS g_RegistrySettings;
  268. #define H323TimerQueue NULL // use default process timer queue
  269. //
  270. // I/O callback threaddeclarations.
  271. //
  272. #if H323_USE_PRIVATE_IO_THREAD
  273. BOOL H323BindIoCompletionCallback (
  274. IN HANDLE ObjectHandle,
  275. IN LPOVERLAPPED_COMPLETION_ROUTINE CompletionRoutine,
  276. IN ULONG Flags);
  277. HRESULT H323IoThreadStart(void);
  278. void H323IoThreadStop(void);
  279. #else
  280. #define H323BindIoCompletionCallback BindIoCompletionCallback
  281. #endif
  282. enum
  283. {
  284. DEBUG_LEVEL_FORCE = 0x00000000, // always emit, no matter what
  285. DEBUG_LEVEL_ERROR = 0x00020000, // significant errors only
  286. DEBUG_LEVEL_INFO = 0x00040000, // general information, but not too detailed
  287. DEBUG_LEVEL_TRACE = 0x00080000, // lotsa lotsa trace output
  288. };
  289. #define DEBUG_LEVEL_WARNING DEBUG_LEVEL_INFO
  290. #define DEBUG_LEVEL_FATAL DEBUG_LEVEL_FORCE // big, bad errors, always output
  291. #define DEBUG_LEVEL_VERBOSE DEBUG_LEVEL_INFO
  292. PSTR EventIDToString( DWORD eventID );
  293. PSTR H323CallStateToString( DWORD dwCallState );
  294. PSTR H323AddressTypeToString( DWORD dwAddressType );
  295. PSTR H323TSPMessageToString( DWORD dwMessageType );
  296. #define SOCKADDR_IN_PRINTF(SocketAddress) \
  297. ntohl ((SocketAddress) -> sin_addr.s_addr), \
  298. ntohs ((SocketAddress) -> sin_port)
  299. //
  300. //Debug Output declarations
  301. //
  302. #if DBG
  303. #define H323DBG(_x_) H323DbgPrint _x_
  304. void H323DUMPBUFFER( IN BYTE * pEncoded, IN DWORD cbEncodedSize );
  305. //
  306. // Public prototypes
  307. //
  308. VOID H323DbgPrint( DWORD dwLevel, LPSTR szFormat, ... );
  309. void DumpError( IN DWORD ErrorCode );
  310. BOOL TRACELogRegister(LPCTSTR szName);
  311. void TRACELogDeRegister();
  312. static __inline void DumpLastError (void) {
  313. DumpError (GetLastError());
  314. }
  315. static DWORD
  316. ProcessTAPICallRequest(
  317. IN PVOID ContextParameter
  318. );
  319. static DWORD
  320. ProcessSuppServiceWorkItem(
  321. IN PVOID ContextParameter
  322. );
  323. DWORD
  324. SendMSPMessageOnRelatedCall(
  325. IN PVOID ContextParameter
  326. );
  327. static DWORD
  328. ProcessTAPILineRequest(
  329. IN PVOID ContextParam
  330. );
  331. #else
  332. // retail build
  333. #define DumpError(ErrorCode) 0
  334. #define DumpLastError() 0
  335. #define H323DBG(_x_) if( 0 != g_RegistrySettings.dwLogLevel ) H323DbgPrintFre _x_
  336. #define H323DUMPBUFFER( x, y)
  337. VOID OpenLogFile();
  338. VOID CloseLogFile();
  339. VOID H323DbgPrintFre(DWORD dwLevel, LPSTR szFormat, ... );
  340. #define ProcessTAPICallRequest ProcessTAPICallRequestFre
  341. #define ProcessSuppServiceWorkItem ProcessSuppServiceWorkItemFre
  342. #define ProcessTAPILineRequest ProcessTAPILineRequestFre
  343. #define SendMSPMessageOnRelatedCall SendMSPMessageOnRelatedCallFre
  344. #endif // DBG
  345. //
  346. // Global Function Declarations
  347. //
  348. void ReportTSPEvent( LPCTSTR wszErrorMessage );
  349. #define H323TSP_EVENT_SOURCE_NAME _T("Microsoft H.323 Telephony Service Provider")
  350. static __inline BOOL IsGuidSet (
  351. IN const GUID * Guid)
  352. {
  353. return Guid -> Data1 || Guid -> Data2 || Guid -> Data3 || Guid -> Data4;
  354. }
  355. static __inline void CopyConferenceID (
  356. OUT GloballyUniqueID * Target,
  357. IN const GUID * Value)
  358. {
  359. CopyMemory (Target -> value, Value, sizeof (GUID));
  360. Target -> length = sizeof (GUID);
  361. }
  362. static __inline void CopyConferenceID (
  363. OUT GUID * Target,
  364. IN const GloballyUniqueID * Value)
  365. {
  366. if (Value -> length == sizeof (GUID))
  367. CopyMemory (Target, Value -> value, sizeof (GUID));
  368. else
  369. {
  370. H323DBG ((DEBUG_LEVEL_ERROR, "GloballyUniqueID was wrong length (%d)\n",
  371. Value -> length));
  372. ZeroMemory (Target, sizeof (GUID));
  373. }
  374. }
  375. extern ASYNC_COMPLETION g_pfnCompletionProc;
  376. #define H323CompleteRequest (*g_pfnCompletionProc)
  377. // notify TAPI of a line event.
  378. void H323PostLineEvent (
  379. IN HTAPILINE TapiLine,
  380. IN HTAPICALL TapiCall,
  381. IN DWORD MessageID,
  382. IN ULONG_PTR Parameter1,
  383. IN ULONG_PTR Parameter2,
  384. IN ULONG_PTR Parameter3);
  385. static __inline HRESULT GetLastResult (void) { return HRESULT_FROM_WIN32 (GetLastError()); }
  386. BOOL H323ValidateTSPIVersion( IN DWORD dwTSPIVersion );
  387. BOOL H323ValidateExtVersion ( IN DWORD dwExtVersion);
  388. HRESULT RegistryStart (void);
  389. void RegistryStop (void);
  390. HANDLE
  391. H323CreateEvent(
  392. LPSECURITY_ATTRIBUTES lpEventAttributes, // SD
  393. BOOL bManualReset, // reset type
  394. BOOL bInitialState, // initial state
  395. LPCTSTR lpName // object name
  396. );
  397. //
  398. // Macros
  399. //
  400. #define H323AddrToString(_dwAddr_) \
  401. (inet_ntoa(H323AddrToAddrIn(_dwAddr_)))
  402. #define H323AddrToAddrIn(_dwAddr_) \
  403. (*((struct in_addr *)&(_dwAddr_)))
  404. #define H323SizeOfWSZ(wsz) \
  405. (((wsz) == NULL) ? 0 : ((wcslen(wsz) + 1) * sizeof(WCHAR)))
  406. //
  407. // Table Class
  408. //
  409. template <class T, DWORD INITIAL = 8, DWORD DELTA = 8>
  410. class TSPTable
  411. {
  412. protected:
  413. T* m_aT;
  414. int m_nSize;
  415. int m_nAllocSize;
  416. CRITICAL_SECTION m_CriticalSection;
  417. public:
  418. // Construction/destruction
  419. TSPTable() : m_aT(NULL), m_nSize(0), m_nAllocSize(0)
  420. {
  421. // No need to check the result of this one since this object is
  422. // always allocated on static memory, right when the DLL is loaded.
  423. InitializeCriticalSectionAndSpinCount( &m_CriticalSection, 0x80000000 );
  424. }
  425. ~TSPTable()
  426. {
  427. if(m_nAllocSize > 0)
  428. {
  429. free(m_aT);
  430. m_aT = NULL;
  431. m_nSize = 0;
  432. m_nAllocSize = 0;
  433. }
  434. DeleteCriticalSection(&m_CriticalSection);
  435. }
  436. void Lock()
  437. {
  438. EnterCriticalSection( &m_CriticalSection );
  439. }
  440. void Unlock()
  441. {
  442. LeaveCriticalSection( &m_CriticalSection );
  443. }
  444. // Operations
  445. int GetSize() const
  446. {
  447. return m_nSize;
  448. }
  449. int GetAllocSize()
  450. {
  451. return m_nAllocSize;
  452. }
  453. int Add(T& t)
  454. {
  455. Lock();
  456. if(m_nSize == m_nAllocSize)
  457. {
  458. if (!Grow()) return -1;
  459. SetAtIndex(m_nSize, t);
  460. m_nSize++;
  461. Unlock();
  462. return m_nSize - 1;
  463. }
  464. else
  465. {
  466. for(int i=0; i<m_nAllocSize; i++)
  467. if(m_aT[i] == NULL )
  468. break;
  469. SetAtIndex(i, t);
  470. m_nSize++;
  471. Unlock();
  472. return i;
  473. }
  474. }
  475. void RemoveAt(int nIndex)
  476. {
  477. Lock();
  478. _ASSERTE( m_aT[nIndex] );
  479. m_aT[nIndex] = NULL;
  480. m_nSize--;
  481. Unlock();
  482. }
  483. T& operator[] (int nIndex) const
  484. {
  485. static T t1 = (T)NULL;
  486. _ASSERTE( (nIndex >= 0) && (nIndex < m_nAllocSize) );
  487. if( (nIndex >= 0) && (nIndex < m_nAllocSize) )
  488. return m_aT[nIndex];
  489. return t1;
  490. }
  491. // Implementation
  492. private:
  493. void SetAtIndex(int nIndex, T& t)
  494. {
  495. _ASSERTE(nIndex >= 0 && nIndex < m_nAllocSize);
  496. if( (nIndex >= 0) && (nIndex < m_nAllocSize) )
  497. m_aT[nIndex] = t;
  498. }
  499. BOOL Grow()
  500. {
  501. T* aT;
  502. int nNewAllocSize =
  503. (m_nAllocSize == 0) ? INITIAL : (m_nSize + DELTA);
  504. aT = (T*)realloc(m_aT, nNewAllocSize * sizeof(T));
  505. if(aT == NULL)
  506. return FALSE;
  507. ZeroMemory( (PVOID)&aT[m_nAllocSize], sizeof(T)*(nNewAllocSize-m_nAllocSize));
  508. m_nAllocSize = nNewAllocSize;
  509. m_aT = aT;
  510. return TRUE;
  511. }
  512. };
  513. /*++
  514. CTSPArray template Description:
  515. This array should only be used to store simple types. It doesn't call the
  516. constructor nor the destructor for each element in the array.
  517. --*/
  518. template <class T, DWORD INITIAL_SIZE = 8, DWORD DELTA_SIZE = 8>
  519. class CTSPArray
  520. {
  521. protected:
  522. T* m_aT;
  523. int m_nSize;
  524. int m_nAllocSize;
  525. public:
  526. // Construction/destruction
  527. CTSPArray() : m_aT(NULL), m_nSize(0), m_nAllocSize(0)
  528. { }
  529. ~CTSPArray()
  530. {
  531. RemoveAll();
  532. }
  533. // Operations
  534. int GetSize() const
  535. {
  536. return m_nSize;
  537. }
  538. BOOL Grow()
  539. {
  540. T* aT;
  541. int nNewAllocSize =
  542. (m_nAllocSize == 0) ? INITIAL_SIZE : (m_nSize + DELTA_SIZE);
  543. aT = (T*)realloc(m_aT, nNewAllocSize * sizeof(T));
  544. if(aT == NULL)
  545. return FALSE;
  546. m_nAllocSize = nNewAllocSize;
  547. m_aT = aT;
  548. return TRUE;
  549. }
  550. BOOL Add(T& t)
  551. {
  552. if(m_nSize == m_nAllocSize)
  553. {
  554. if (!Grow()) return FALSE;
  555. }
  556. m_nSize++;
  557. SetAtIndex(m_nSize - 1, t);
  558. return TRUE;
  559. }
  560. BOOL Remove(T& t)
  561. {
  562. int nIndex = Find(t);
  563. if(nIndex == -1)
  564. return FALSE;
  565. return RemoveAt(nIndex);
  566. }
  567. BOOL RemoveAt(int nIndex)
  568. {
  569. if(nIndex != (m_nSize - 1))
  570. memmove((void*)&m_aT[nIndex], (void*)&m_aT[nIndex + 1],
  571. (m_nSize - (nIndex + 1)) * sizeof(T));
  572. m_nSize--;
  573. return TRUE;
  574. }
  575. void RemoveAll()
  576. {
  577. if(m_nAllocSize > 0)
  578. {
  579. free(m_aT);
  580. m_aT = NULL;
  581. m_nSize = 0;
  582. m_nAllocSize = 0;
  583. }
  584. }
  585. T& operator[] (int nIndex) const
  586. {
  587. _ASSERTE(nIndex >= 0 && nIndex < m_nSize);
  588. return m_aT[nIndex];
  589. }
  590. T* GetData() const
  591. {
  592. return m_aT;
  593. }
  594. // Implementation
  595. void SetAtIndex(int nIndex, T& t)
  596. {
  597. _ASSERTE(nIndex >= 0 && nIndex < m_nSize);
  598. m_aT[nIndex] = t;
  599. }
  600. int Find(T& t) const
  601. {
  602. for(int i = 0; i < m_nSize; i++)
  603. {
  604. if(m_aT[i] == t)
  605. return i;
  606. }
  607. return -1; // not found
  608. }
  609. };
  610. //
  611. //Asynchronous I/O definitions.
  612. //
  613. class RAS_CLIENT;
  614. class CH323Call;
  615. #define IO_BUFFER_SIZE 0x2000
  616. enum OVERLAPPED_TYPE
  617. {
  618. OVERLAPPED_TYPE_SEND = 0,
  619. OVERLAPPED_TYPE_RECV,
  620. };
  621. typedef struct O_OVERLAPPED
  622. {
  623. LIST_ENTRY ListEntry;
  624. OVERLAPPED Overlapped;
  625. OVERLAPPED_TYPE Type;
  626. union {
  627. RAS_CLIENT* RasClient;
  628. CH323Call* pCall;
  629. };
  630. DWORD BytesTransferred;
  631. SOCKADDR_IN Address;
  632. } RAS_OVERLAPPED, CALL_OVERLAPPED;
  633. struct CALL_SEND_CONTEXT :
  634. public CALL_OVERLAPPED
  635. {
  636. WSABUF WSABuf;
  637. };
  638. struct RAS_SEND_CONTEXT :
  639. public RAS_OVERLAPPED
  640. {
  641. UCHAR arBuf[IO_BUFFER_SIZE];
  642. };
  643. struct RAS_RECV_CONTEXT :
  644. public RAS_OVERLAPPED
  645. {
  646. UCHAR arBuf[IO_BUFFER_SIZE];
  647. DWORD Flags;
  648. BOOL IsPending;
  649. INT AddressLength;
  650. };
  651. struct CALL_RECV_CONTEXT :
  652. public CALL_OVERLAPPED
  653. {
  654. char arBuf[IO_BUFFER_SIZE];
  655. WSABUF WSABuf;
  656. DWORD dwBytesCopied;
  657. DWORD dwPDULen;
  658. DWORD dwFlags;
  659. };
  660. //
  661. // Component Includes
  662. //
  663. #include "h4503pp.h"
  664. #include "q931pdu.h"