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.

1267 lines
35 KiB

  1. /*++
  2. Copyright (c) 1997-1999 Microsoft Corporation
  3. Module Name:
  4. agenthand.cpp
  5. Abstract:
  6. Implementation of the CAll centre interface for TAPI 3.0.
  7. AgentHandler class
  8. Author:
  9. noela - 03/16/98
  10. Notes:
  11. optional-notes
  12. Revision History:
  13. --*/
  14. #define UNICODE
  15. #include "stdafx.h"
  16. #include "lmcons.h"
  17. extern CHashTable * gpAgentHandlerHashTable ;
  18. /////////////////////////////////////////////////////////////////////////////
  19. // ITAgentHandler
  20. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  21. // Class : CAgentHandler
  22. // Method : Initialize
  23. //
  24. //
  25. //
  26. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  27. STDMETHODIMP CAgentHandler::Initialize(PWSTR pszProxyName, GUID proxyGUID, CTAPI *tapiObj)
  28. {
  29. HRESULT hr = S_OK;
  30. LOG((TL_TRACE, "Initialize - enter" ));
  31. m_GUID = proxyGUID;
  32. m_tapiObj = tapiObj;
  33. m_pAddressLine = NULL;
  34. // copy the Name
  35. if (pszProxyName != NULL)
  36. {
  37. m_szName = (PWSTR) ClientAlloc((lstrlenW(pszProxyName) + 1) * sizeof (WCHAR));
  38. if (m_szName != NULL)
  39. {
  40. lstrcpyW(m_szName,pszProxyName);
  41. }
  42. else
  43. {
  44. LOG((TL_ERROR, "Initialize - Alloc m_szName failed" ));
  45. hr = E_OUTOFMEMORY;
  46. }
  47. }
  48. else
  49. {
  50. LOG((TL_ERROR, "Initialize - name is NULL" ));
  51. m_szName = NULL;
  52. }
  53. // Initialize our hash tables
  54. //
  55. m_AgentSessionHashtable.Initialize(1);
  56. m_QueueHashtable.Initialize(1);
  57. LOG((TL_TRACE, hr, "Initialize - exit" ));
  58. return hr;
  59. }
  60. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  61. // Class : CAgentHandler
  62. // Method : AddAddress
  63. //
  64. //
  65. //
  66. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  67. void CAgentHandler::AddAddress(CAddress *pAddress)
  68. {
  69. LOG((TL_TRACE, "AddAddress - enter"));
  70. //
  71. // good address?
  72. //
  73. if (IsBadReadPtr(pAddress, sizeof(CAddress) ))
  74. {
  75. LOG((TL_ERROR, "AddAddress - bad address pointer"));
  76. return;
  77. }
  78. //
  79. // get ITAddress out of the CAddress pointer
  80. //
  81. ITAddress *pITAddress = dynamic_cast<ITAddress *>(pAddress);
  82. if (NULL == pITAddress)
  83. {
  84. LOG((TL_ERROR, "AddAddress - pITAddress is NULL"));
  85. return;
  86. }
  87. //
  88. // log address' name
  89. //
  90. #if DBG
  91. {
  92. BSTR bstrName = NULL;
  93. HRESULT hr = pITAddress->get_AddressName(&bstrName);
  94. if (SUCCEEDED(hr))
  95. {
  96. LOG((TL_TRACE, "AddAddress - using address %ls ",bstrName));
  97. SysFreeString( bstrName );
  98. }
  99. }
  100. #endif
  101. //
  102. // first see if this ITAddress is in the array of my addresses
  103. //
  104. int nIndex = m_AddressArray.Find( pITAddress );
  105. if (nIndex >= 0)
  106. {
  107. LOG((TL_TRACE,
  108. "AddAddress - address already in the array. doing nothing"));
  109. return;
  110. }
  111. //
  112. // add address to the array of managed addresses
  113. //
  114. BOOL bAddSuccess = m_AddressArray.Add( pITAddress );
  115. //
  116. // log a message if the object failed to be added to the array
  117. //
  118. if ( !bAddSuccess )
  119. {
  120. LOG((TL_ERROR,
  121. "AddAddress - failed to add address to the array"));
  122. return;
  123. }
  124. LOG((TL_TRACE, "AddAddress - exit"));
  125. }
  126. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  127. // Class : CAgentHandler
  128. // Method : getHLine
  129. //
  130. //
  131. //
  132. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  133. HLINE CAgentHandler::getHLine()
  134. {
  135. CAddress * pAddress;
  136. HLINE hLine = 0;
  137. HRESULT hr = S_OK;
  138. LOG((TL_TRACE, "getHLine - enter"));
  139. if (m_pAddressLine != NULL)
  140. {
  141. hLine = m_pAddressLine->t3Line.hLine;
  142. }
  143. else
  144. {
  145. // If we don't have a line, find one
  146. pAddress = dynamic_cast<CAddress *>(m_AddressArray[0]);
  147. if ( NULL != pAddress )
  148. {
  149. #if DBG
  150. {
  151. BSTR bstrName;
  152. ((ITAddress *)(pAddress))->get_AddressName(&bstrName);
  153. LOG((TL_INFO, "getHLine - using address %ls ",bstrName));
  154. SysFreeString( bstrName );
  155. }
  156. #endif
  157. hr = pAddress->FindOrOpenALine (LINEMEDIAMODE_INTERACTIVEVOICE, &m_pAddressLine);
  158. if (SUCCEEDED(hr) )
  159. {
  160. hLine = m_pAddressLine->t3Line.hLine;
  161. // We've got a line open to the proxy, so lets add it to the AH hash table
  162. gpAgentHandlerHashTable->Lock();
  163. gpAgentHandlerHashTable->Insert( (ULONG_PTR)hLine, (ULONG_PTR)this );
  164. gpAgentHandlerHashTable->Unlock();
  165. }
  166. }
  167. }
  168. LOG((TL_TRACE,hr, "getHLine(%8x) - exit", hLine));
  169. return hLine;
  170. }
  171. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  172. // Class : CAgentHandler
  173. // Method : FinalRelease
  174. //
  175. //
  176. //
  177. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  178. void CAgentHandler::FinalRelease()
  179. {
  180. CAddress * pAddress;
  181. LOG((TL_TRACE, "FinalRelease AgentHandler - %S", m_szName ));
  182. if ( m_szName != NULL )
  183. {
  184. ClientFree(m_szName);
  185. }
  186. // If we have a line open close it
  187. if (m_pAddressLine != NULL)
  188. {
  189. // We've got a line open to the proxy, so lets remove it from the AH hash table
  190. gpAgentHandlerHashTable->Lock();
  191. gpAgentHandlerHashTable->Remove( (ULONG_PTR)(m_pAddressLine->t3Line.hLine) );
  192. gpAgentHandlerHashTable->Unlock();
  193. // And then close it
  194. pAddress = dynamic_cast<CAddress *>(m_AddressArray[0]);
  195. if ( NULL != pAddress )
  196. {
  197. pAddress->MaybeCloseALine (&m_pAddressLine);
  198. }
  199. }
  200. m_AddressArray.Shutdown();
  201. m_GroupArray.Shutdown();
  202. m_AgentArray.Shutdown();
  203. // Shutdown our hash tables
  204. //
  205. m_AgentSessionHashtable.Shutdown();
  206. m_QueueHashtable.Shutdown();
  207. LOG((TL_TRACE, "FinalRelease AgentHandler - exit" ));
  208. }
  209. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  210. // Class : CAgentHandler
  211. // Method : FindSessionObject
  212. //
  213. //
  214. //
  215. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  216. BOOL CAgentHandler::FindSessionObject(
  217. HAGENTSESSION hAgentSession,
  218. CAgentSession ** ppAgentSession
  219. )
  220. {
  221. BOOL bResult = FALSE;
  222. m_AgentSessionHashtable.Lock();
  223. if ( SUCCEEDED(m_AgentSessionHashtable.Find( (ULONG_PTR)hAgentSession, (ULONG_PTR *)ppAgentSession )) )
  224. {
  225. bResult = TRUE;
  226. }
  227. else
  228. {
  229. bResult = FALSE;
  230. }
  231. m_AgentSessionHashtable.Unlock();
  232. return bResult;
  233. }
  234. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  235. // Class : CAgentHandler
  236. // Method : FindSessionObject
  237. //
  238. //
  239. //
  240. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  241. BOOL CAgentHandler::FindQueueObject(
  242. DWORD dwQueueID,
  243. CQueue ** ppQueue
  244. )
  245. {
  246. BOOL bResult = FALSE;
  247. m_QueueHashtable.Lock();
  248. if ( SUCCEEDED(m_QueueHashtable.Find( (ULONG_PTR)dwQueueID, (ULONG_PTR *)ppQueue )) )
  249. {
  250. bResult = TRUE;
  251. }
  252. else
  253. {
  254. bResult = FALSE;
  255. }
  256. m_QueueHashtable.Unlock();
  257. return bResult;
  258. }
  259. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  260. // Class : CAgentHandler
  261. // Method : FindAgentObject
  262. //
  263. //
  264. //
  265. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  266. BOOL CAgentHandler::FindAgentObject(
  267. HAGENT hAgent,
  268. CAgent ** ppAgent
  269. )
  270. {
  271. HRESULT hr = FALSE;
  272. CAgent *pAgent;
  273. int iCount;
  274. LOG((TL_TRACE, "FindAgent %d", hAgent));
  275. for ( iCount = 0; iCount < m_AgentArray.GetSize(); iCount++ )
  276. {
  277. pAgent = dynamic_cast<CComObject<CAgent>*>(m_AgentArray[iCount]);
  278. if (pAgent !=NULL)
  279. {
  280. if (hAgent == pAgent->getHandle() )
  281. {
  282. // Found it
  283. *ppAgent = pAgent;
  284. hr = TRUE;
  285. break;
  286. }
  287. }
  288. }
  289. return hr;
  290. }
  291. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  292. // Class : CACDGroup
  293. // Method : UpdateAgentHandlerList
  294. //
  295. //
  296. //
  297. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  298. HRESULT CAgentHandler::UpdateGroupArray()
  299. {
  300. HRESULT hr = S_OK;
  301. DWORD dwNumberOfEntries;
  302. LPLINEAGENTGROUPLIST pGroupList = NULL;
  303. LPLINEAGENTGROUPENTRY pGroupEntry = NULL;
  304. PWSTR pszGroupName;
  305. DWORD dwCount;
  306. GUID * pGroupID;
  307. BOOL foundIt;
  308. CACDGroup * thisGroup = NULL;
  309. int iCount;
  310. LOG((TL_TRACE, "UpdateGroupArray - enter"));
  311. // Call lineGetGroupList to get list of Groups
  312. hr = LineGetGroupList( getHLine(), &pGroupList );
  313. if( SUCCEEDED(hr) )
  314. {
  315. dwNumberOfEntries = pGroupList->dwNumEntries;
  316. LOG((TL_INFO, "UpdateGroupArray - Number of entries: %d", dwNumberOfEntries));
  317. if ( dwNumberOfEntries !=0 )
  318. {
  319. // Run through the new list from the Proxy &see if any new groups have appeared
  320. // By Comparing IDs from the new list with those in TAPIs list
  321. // Find position of 1st LINEAGENTGROUPEENTRY structure in the LINEAGENTGROUPLIST
  322. pGroupEntry = (LPLINEAGENTGROUPENTRY) ((BYTE*)(pGroupList) + pGroupList->dwListOffset);
  323. // Run though the received list
  324. for (dwCount = 0; dwCount < dwNumberOfEntries; dwCount++)
  325. {
  326. pszGroupName= (PWSTR)( (PBYTE)pGroupList + pGroupEntry->dwNameOffset);
  327. pGroupID = (GUID*)&pGroupEntry->GroupID;
  328. #if DBG
  329. {
  330. WCHAR guidName[100];
  331. StringFromGUID2(*pGroupID, (LPOLESTR)&guidName, 100);
  332. LOG((TL_INFO, "UpdateGroupArray - Group Name : %S", pszGroupName));
  333. LOG((TL_INFO, "UpdateGroupArray - Group GUID : %S", guidName));
  334. }
  335. #endif
  336. // Run through the array of Groups & see if we already have this one in the list
  337. // by comparing IDs
  338. foundIt = FALSE;
  339. Lock();
  340. for (iCount = 0; iCount < m_GroupArray.GetSize(); iCount++)
  341. {
  342. thisGroup = dynamic_cast<CComObject<CACDGroup>*>(m_GroupArray[iCount]);
  343. if (thisGroup != NULL)
  344. {
  345. if ( IsEqualGUID(*pGroupID, thisGroup->getID() ) )
  346. {
  347. foundIt = TRUE;
  348. break;
  349. }
  350. }
  351. }
  352. Unlock();
  353. if (foundIt == FALSE)
  354. {
  355. // Didn't match so lets add this Group
  356. LOG((TL_INFO, "UpdateGroupArray - create new Group"));
  357. CComObject<CACDGroup> * pGroup;
  358. hr = CComObject<CACDGroup>::CreateInstance( &pGroup );
  359. if( SUCCEEDED(hr) )
  360. {
  361. ITACDGroup * pITGroup;
  362. hr = pGroup->QueryInterface(IID_ITACDGroup, (void **)&pITGroup);
  363. if ( SUCCEEDED(hr) )
  364. {
  365. // initialize the Group
  366. hr = pGroup->Initialize(pszGroupName, *pGroupID, this);
  367. if( SUCCEEDED(hr) )
  368. {
  369. LOG((TL_TRACE, "UpdateGroupArray - Initialize Group succeededed" ));
  370. //
  371. // add to Array of Groups
  372. //
  373. Lock();
  374. m_GroupArray.Add(pITGroup);
  375. Unlock();
  376. pITGroup->Release();
  377. LOG((TL_INFO, "UpdateGroupArray - Added Group to Array"));
  378. }
  379. else
  380. {
  381. LOG((TL_ERROR, "UpdateGroupArray - Initialize Group failed" ));
  382. delete pGroup;
  383. }
  384. }
  385. else
  386. {
  387. LOG((TL_ERROR, "UpdateGroupArray - QueryInterface failed" ));
  388. delete pGroup;
  389. }
  390. }
  391. else
  392. {
  393. LOG((TL_ERROR, "UpdateGroupArray - Create Group failed" ));
  394. }
  395. }
  396. else // foundIt == TRUE
  397. {
  398. LOG((TL_INFO, "UpdateGroupArray - Group Object exists for this entry" ));
  399. // Just in case is was previously inactive
  400. thisGroup->SetActive();
  401. }
  402. // next entry in list
  403. pGroupEntry ++;
  404. } //for(dwCount = 0......)
  405. // Run through the list of Groups & see if any groups have been removed by the Proxy
  406. // By comparing IDs of those in TAPIs list with the new list from the Proxy
  407. for (iCount = 0; iCount < m_GroupArray.GetSize(); iCount++)
  408. {
  409. thisGroup = dynamic_cast<CComObject<CACDGroup>*>( m_GroupArray[iCount] );
  410. if (thisGroup != NULL)
  411. {
  412. foundIt = FALSE;
  413. // Find position of 1st LINEAGENTGROUPEENTRY structure in the LINEAGENTGROUPLIST
  414. pGroupEntry = (LPLINEAGENTGROUPENTRY) ((BYTE*)(pGroupList) + pGroupList->dwListOffset);
  415. // Run though the list
  416. for (dwCount = 0; dwCount < dwNumberOfEntries; dwCount++)
  417. {
  418. pGroupID = (GUID*)&pGroupEntry->GroupID;
  419. if ( IsEqualGUID(*pGroupID, thisGroup->getID() ) )
  420. {
  421. foundIt = TRUE;
  422. break;
  423. }
  424. pGroupEntry ++; // next
  425. } // for (dwCount = 0......)
  426. if (foundIt == FALSE)
  427. {
  428. // Didn't match so it's no longer a valid group , according to the Proxy
  429. LOG((TL_INFO, "UpdateGroupArray - Group has gone from the proxy"));
  430. thisGroup->SetInactive();
  431. }
  432. }
  433. }
  434. }
  435. else
  436. {
  437. LOG((TL_ERROR, "UpdateGroupArray - lineGetGroupList failed - empty list"));
  438. hr = E_FAIL;
  439. }
  440. }
  441. else // lineGetGroupList failed
  442. {
  443. LOG((TL_ERROR, "UpdateGroupArray - lineGetGroupList failed"));
  444. }
  445. // finished with memory block so release
  446. if ( pGroupList != NULL )
  447. ClientFree( pGroupList );
  448. LOG((TL_TRACE, hr, "UpdateGroupArray - exit"));
  449. return hr;
  450. }
  451. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  452. // Class : CAgentHandler
  453. // Interface : ITAgentHandler
  454. // Method : get_Name
  455. //
  456. //
  457. //
  458. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  459. STDMETHODIMP CAgentHandler::get_Name(BSTR * Name)
  460. {
  461. HRESULT hr = S_OK;
  462. LOG((TL_TRACE, "Name - enter" ));
  463. Lock();
  464. if(!TAPIIsBadWritePtr( Name, sizeof(BSTR) ) )
  465. {
  466. *Name = SysAllocString(m_szName);
  467. if (*Name == NULL)
  468. {
  469. hr = E_OUTOFMEMORY;
  470. }
  471. }
  472. else
  473. {
  474. LOG((TL_ERROR, "Name - bad Name pointer" ));
  475. hr = E_POINTER;
  476. }
  477. Unlock();
  478. LOG((TL_TRACE, hr, "Name - exit" ));
  479. return hr;
  480. }
  481. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  482. // Class : CAgentHandler
  483. // Interface : ITAgentHandler
  484. // Method : CreateAgent
  485. //
  486. //
  487. //
  488. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  489. STDMETHODIMP CAgentHandler::CreateAgent(ITAgent **ppAgent)
  490. {
  491. HRESULT hr = S_OK;
  492. CAgent * pAgent;
  493. LOG((TL_TRACE, "CreateAgent - enter"));
  494. if(!TAPIIsBadWritePtr( ppAgent, sizeof(ITAgent *) ) )
  495. {
  496. hr = InternalCreateAgent(NULL, NULL, &pAgent);
  497. if ( SUCCEEDED(hr) )
  498. {
  499. //
  500. // put result in out pointer - also
  501. pAgent->QueryInterface(IID_ITAgent, (void **)ppAgent );
  502. }
  503. else
  504. {
  505. LOG((TL_ERROR, "CreateAgent - InternalCreateAgent failed" ));
  506. }
  507. }
  508. else
  509. {
  510. LOG((TL_ERROR, "CreateAgent - Bad ppAgent Pointer"));
  511. hr = E_POINTER;
  512. }
  513. LOG((TL_TRACE, hr, "CreateAgent - exit"));
  514. return hr;
  515. }
  516. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  517. // Class : CAgentHandler
  518. // Interface : ITAgentHandler
  519. // Method : CreateAgentWithID
  520. //
  521. //
  522. //
  523. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  524. STDMETHODIMP CAgentHandler::CreateAgentWithID(BSTR pID, BSTR pPIN, ITAgent **ppAgent)
  525. {
  526. HRESULT hr = S_OK;
  527. CAgent * pAgent;
  528. LOG((TL_TRACE, "CreateAgentWithID - enter"));
  529. if(!TAPIIsBadWritePtr( ppAgent, sizeof(ITAgent *) ) )
  530. {
  531. if (!IsBadStringPtrW( pID, -1 ))
  532. {
  533. // ID Pointer OK, is it empty ?
  534. if( *pID != NULL)
  535. {
  536. if (!IsBadStringPtrW( pPIN, -1 ))
  537. {
  538. // All OK so far, so try to create
  539. hr = InternalCreateAgent(pID, pPIN, &pAgent);
  540. if ( SUCCEEDED(hr) )
  541. {
  542. // put result in out pointer - also
  543. pAgent->QueryInterface(IID_ITAgent, (void **)ppAgent );
  544. }
  545. else // InternalCreateAgent failed
  546. {
  547. LOG((TL_ERROR, "CreateAgentWithID - InternalCreateAgent failed" ));
  548. }
  549. }
  550. else // bad PIN pointer
  551. {
  552. LOG((TL_ERROR, "CreateAgentWithID - Bad PIN pointer" ));
  553. hr = E_POINTER;
  554. }
  555. }
  556. else // NULL ID
  557. {
  558. LOG((TL_ERROR, "CreateAgentWithID - ID is Empty String" ));
  559. hr = E_INVALIDARG;
  560. }
  561. }
  562. else // bad ID pointer
  563. {
  564. LOG((TL_ERROR, "CreateAgentWithID - Bad ID pointer" ));
  565. hr = E_POINTER;
  566. }
  567. }
  568. else
  569. {
  570. LOG((TL_ERROR, "CreateAgentWithID - Bad ppAgent Pointer"));
  571. hr = E_POINTER;
  572. }
  573. LOG((TL_TRACE, hr, "CreateAgentWithID - exit"));
  574. return hr;
  575. }
  576. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  577. // Class : CAgentHandler
  578. // Method : InternalCreateAgent
  579. //
  580. //
  581. //
  582. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  583. HRESULT CAgentHandler::InternalCreateAgent(BSTR pID, BSTR pPIN, CAgent ** ppAgent)
  584. {
  585. HRESULT hr = S_OK;
  586. HAGENT hAgent;
  587. DWORD dwUserNameSize = (UNLEN + 1);
  588. PWSTR pszName = NULL;
  589. LOG((TL_TRACE, "InternalCreateAgent - enter"));
  590. hr = LineCreateAgent(getHLine(), pID, pPIN, &hAgent);
  591. if ( SUCCEEDED(hr) )
  592. {
  593. hr = WaitForReply( hr );
  594. if ( SUCCEEDED(hr) )
  595. {
  596. // Successs, so create agent
  597. LOG((TL_INFO, "InternalCreateAgent - create new Agent Handler" ));
  598. CComObject<CAgent> * pAgent;
  599. hr = CComObject<CAgent>::CreateInstance( &pAgent);
  600. if( SUCCEEDED(hr) )
  601. {
  602. // initialize the AgentHandler
  603. pszName = (PWSTR)ClientAlloc((dwUserNameSize + 1) * sizeof(WCHAR) );
  604. if (pszName != NULL)
  605. {
  606. if ( GetUserNameW( pszName, &dwUserNameSize) )
  607. {
  608. ITAgent *pITAgent;
  609. hr = pAgent->QueryInterface(IID_ITAgent, (void **)&pITAgent);
  610. if( SUCCEEDED(hr ))
  611. {
  612. hr = pAgent->Initialize(hAgent, pszName, pID, pPIN, this );
  613. if( SUCCEEDED(hr) )
  614. {
  615. //
  616. // add to list
  617. //
  618. Lock();
  619. m_AgentArray.Add(pITAgent);
  620. Unlock();
  621. pITAgent->Release();
  622. LOG((TL_INFO, "InternalCreateAgent - Added Agent to array"));
  623. // Return new Agent object
  624. *ppAgent = pAgent;
  625. }
  626. else
  627. {
  628. LOG((TL_ERROR, "InternalCreateAgent - Initialize Agent failed" ));
  629. delete pAgent;
  630. }
  631. }
  632. else
  633. {
  634. LOG((TL_ERROR, "InternalCreateAgent - QueryInterface failed" ));
  635. delete pAgent;
  636. }
  637. }
  638. else // GetUserName fail
  639. {
  640. LOG((TL_ERROR, "InternalCreateAgent - GetUserNameW failed" ));
  641. hr = TAPI_E_CALLCENTER_INVALAGENTID;
  642. }
  643. }
  644. else // pszName == NULL
  645. {
  646. LOG((TL_ERROR, "InternalCreateAgent - ClientAlloc pszName failed" ));
  647. hr = E_OUTOFMEMORY;
  648. }
  649. }
  650. else
  651. {
  652. LOG((TL_ERROR, "InternalCreateAgent - Create Agent failed" ));
  653. }
  654. }
  655. else // LineCreateAgent failed async
  656. {
  657. LOG((TL_ERROR, "InternalCreateAgent - LineCreateAgent failed async" ));
  658. }
  659. }
  660. else // LineCreateAgent failed
  661. {
  662. LOG((TL_ERROR, "InternalCreateAgent - LineCreateAgent failed" ));
  663. }
  664. if(pszName != NULL)
  665. ClientFree(pszName);
  666. LOG((TL_TRACE, hr, "InternalCreateAgent - exit"));
  667. return hr;
  668. }
  669. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  670. // Class : CAgentHandler
  671. // Interface : ITAgentHandler
  672. // Method : EnumerateACDGroups
  673. //
  674. //
  675. //
  676. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  677. STDMETHODIMP CAgentHandler::EnumerateACDGroups(IEnumACDGroup ** ppEnumACDGroup)
  678. {
  679. HRESULT hr = S_OK;
  680. LOG((TL_TRACE, "EnumerateACDGroups - enter"));
  681. if(!TAPIIsBadWritePtr( ppEnumACDGroup, sizeof(IEnumACDGroup *) ) )
  682. {
  683. UpdateGroupArray();
  684. //
  685. // create the enumerator
  686. //
  687. CComObject< CTapiEnum<IEnumACDGroup, ITACDGroup, &IID_IEnumACDGroup> > * pEnum;
  688. hr = CComObject< CTapiEnum<IEnumACDGroup, ITACDGroup, &IID_IEnumACDGroup> > ::CreateInstance( &pEnum );
  689. if (SUCCEEDED(hr) )
  690. {
  691. // initialize it with our group list
  692. Lock();
  693. hr = pEnum->Initialize( m_GroupArray );
  694. Unlock();
  695. if ( SUCCEEDED(hr) )
  696. {
  697. // return it
  698. *ppEnumACDGroup = pEnum;
  699. }
  700. else // failed to initialize
  701. {
  702. LOG((TL_ERROR, "EnumerateACDGroup - could not initialize enum" ));
  703. pEnum->Release();
  704. }
  705. }
  706. else // failed to create enum
  707. {
  708. LOG((TL_ERROR, "EnumerateACDGroups - could not create enum" ));
  709. }
  710. }
  711. else
  712. {
  713. LOG((TL_ERROR, "EnumerateACDGroups - bad ppEnumACDGroup ponter" ));
  714. hr = E_POINTER;
  715. }
  716. LOG((TL_TRACE, hr, "EnumerateACDGroups - exit"));
  717. return hr;
  718. }
  719. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  720. // Class : CAgentHandler
  721. // Interface : ITAgentHandler
  722. // Method : get_ACDGroups
  723. //
  724. // Return a collection of calls usable for this Agent Handler
  725. //
  726. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  727. STDMETHODIMP CAgentHandler::get_ACDGroups(VARIANT * pVariant)
  728. {
  729. HRESULT hr = S_OK;
  730. IDispatch * pDisp = NULL;
  731. LOG((TL_TRACE, "get_ACDGroups - enter"));
  732. if (!TAPIIsBadWritePtr( pVariant, sizeof(VARIANT) ) )
  733. {
  734. UpdateGroupArray();
  735. //
  736. // create the collection
  737. //
  738. CComObject< CTapiCollection< ITACDGroup > > * p;
  739. hr = CComObject< CTapiCollection< ITACDGroup > >::CreateInstance( &p );
  740. if (SUCCEEDED(hr) )
  741. {
  742. // initialize it with our address list
  743. Lock();
  744. hr = p->Initialize( m_GroupArray );
  745. Unlock();
  746. if ( SUCCEEDED(hr) )
  747. {
  748. // get the IDispatch interface
  749. hr = p->_InternalQueryInterface( IID_IDispatch, (void **) &pDisp );
  750. if ( SUCCEEDED(hr) )
  751. {
  752. // put it in the variant
  753. VariantInit(pVariant);
  754. pVariant->vt = VT_DISPATCH;
  755. pVariant->pdispVal = pDisp;
  756. }
  757. else
  758. {
  759. LOG((TL_ERROR, "get_ACDGroups - could not get IDispatch interface" ));
  760. delete p;
  761. }
  762. }
  763. else
  764. {
  765. LOG((TL_ERROR, "get_ACDGroups - could not initialize collection" ));
  766. delete p;
  767. }
  768. }
  769. else
  770. {
  771. LOG((TL_ERROR, "get_ACDGroups - could not create collection" ));
  772. }
  773. }
  774. else
  775. {
  776. LOG((TL_ERROR, "get_ACDGroups - bad pVariant pointer" ));
  777. hr = E_POINTER;
  778. }
  779. LOG((TL_TRACE, hr, "get_ACDGroups - exit"));
  780. return hr;
  781. }
  782. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  783. // Class : CAgentHandler
  784. // Interface : ITAgentHandler
  785. // Method : EnumerateUsableAddresses
  786. //
  787. //
  788. //
  789. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  790. STDMETHODIMP CAgentHandler::EnumerateUsableAddresses(IEnumAddress ** ppEnumAddress)
  791. {
  792. HRESULT hr = S_OK;
  793. LOG((TL_TRACE, "EnumerateUsableAddresses - enter"));
  794. if(!TAPIIsBadWritePtr( ppEnumAddress, sizeof(IEnumAddress *) ) )
  795. {
  796. //
  797. // create the enumerator
  798. //
  799. CComObject< CTapiEnum<IEnumAddress, ITAddress, &IID_IEnumAddress> > * pEnum;
  800. hr = CComObject< CTapiEnum<IEnumAddress, ITAddress, &IID_IEnumAddress> > ::CreateInstance( &pEnum );
  801. if ( SUCCEEDED(hr) )
  802. {
  803. //
  804. // initialize it with our address array
  805. //
  806. Lock();
  807. hr = pEnum->Initialize( m_AddressArray );
  808. Unlock();
  809. if ( SUCCEEDED(hr) )
  810. {
  811. // return it
  812. *ppEnumAddress = pEnum;
  813. }
  814. else // failed to initialize
  815. {
  816. LOG((TL_ERROR, "EnumerateUsableAddresses - could not initialize enum" ));
  817. pEnum->Release();
  818. }
  819. }
  820. else // failed to create enum
  821. {
  822. LOG((TL_ERROR, "EnumerateUsableAddresses - could not create enum" ));
  823. }
  824. }
  825. else
  826. {
  827. LOG((TL_ERROR, "EnumerateUsableAddresses - bad ppEnumAddress pointer" ));
  828. hr = E_POINTER;
  829. }
  830. LOG((TL_TRACE, hr, "EnumerateUsableAddresses - exit"));
  831. return hr;
  832. }
  833. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  834. // Class : CAgentHandler
  835. // Interface : ITAgentHandler
  836. // Method : get_UsableAddresses
  837. //
  838. // Return a collection of calls usable for this Agent Handler
  839. //
  840. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  841. STDMETHODIMP CAgentHandler::get_UsableAddresses(VARIANT * pVariant)
  842. {
  843. HRESULT hr = S_OK;
  844. IDispatch * pDisp = NULL;
  845. LOG((TL_TRACE, "get_UsableAddresses - enter"));
  846. if (!TAPIIsBadWritePtr( pVariant, sizeof(VARIANT) ) )
  847. {
  848. //
  849. // create the collection
  850. //
  851. CComObject< CTapiCollection< ITAddress > > * p;
  852. hr = CComObject< CTapiCollection< ITAddress > >::CreateInstance( &p );
  853. if (SUCCEEDED(hr) )
  854. {
  855. // initialize it with our address Array
  856. Lock();
  857. hr = p->Initialize( m_AddressArray );
  858. Unlock();
  859. if ( SUCCEEDED(hr) )
  860. {
  861. // get the IDispatch interface
  862. hr = p->_InternalQueryInterface( IID_IDispatch, (void **) &pDisp );
  863. if ( SUCCEEDED(hr) )
  864. {
  865. // put it in the variant
  866. VariantInit(pVariant);
  867. pVariant->vt = VT_DISPATCH;
  868. pVariant->pdispVal = pDisp;
  869. }
  870. else
  871. {
  872. LOG((TL_ERROR, "get_UsableAddresses - could not get IDispatch interface" ));
  873. delete p;
  874. }
  875. }
  876. else
  877. {
  878. LOG((TL_ERROR, "get_UsableAddresses - could not initialize collection" ));
  879. delete p;
  880. }
  881. }
  882. else
  883. {
  884. LOG((TL_ERROR, "get_UsableAddresses - could not create collection" ));
  885. }
  886. }
  887. else
  888. {
  889. LOG((TL_ERROR, "get_UsableAddresses - bad pVariant pointer" ));
  890. hr = E_POINTER;
  891. }
  892. LOG((TL_TRACE, hr, "get_UsableAddresses - exit"));
  893. return hr;
  894. }
  895. /////////////////////////////////////////////////////////////////////////////
  896. // CAgentEvent
  897. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  898. // Class : CAgentEvent
  899. // Method : FireEvent
  900. //
  901. //
  902. //
  903. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  904. HRESULT CAgentHandlerEvent::FireEvent(CAgentHandler* pAgentHandler, AGENTHANDLER_EVENT Event)
  905. {
  906. HRESULT hr = S_OK;
  907. CComObject<CAgentHandlerEvent> * pEvent;
  908. IDispatch * pIDispatch;
  909. if ( IsBadReadPtr(pAgentHandler, sizeof(CAgentHandler)) )
  910. {
  911. STATICLOG((TL_ERROR, "FireEvent - pAgentHandler is an invalid pointer"));
  912. return E_POINTER;
  913. }
  914. //
  915. // create event
  916. //
  917. hr = CComObject<CAgentHandlerEvent>::CreateInstance( &pEvent );
  918. if ( SUCCEEDED(hr) )
  919. {
  920. //
  921. // initialize
  922. //
  923. pEvent->m_AgentHandlerEvent = Event;
  924. pEvent->m_pAgentHandler= dynamic_cast<ITAgentHandler *>(pAgentHandler);
  925. pEvent->m_pAgentHandler->AddRef();
  926. //
  927. // get idisp interface
  928. //
  929. hr = pEvent->QueryInterface( IID_IDispatch, (void **)&pIDispatch );
  930. if ( SUCCEEDED(hr) )
  931. {
  932. //
  933. // get callback & fire event
  934. //
  935. CTAPI *pTapi = pAgentHandler->GetTapi();
  936. pTapi->Event( TE_AGENTHANDLER, pIDispatch );
  937. // release stuff
  938. //
  939. pIDispatch->Release();
  940. }
  941. else
  942. {
  943. STATICLOG((TL_ERROR, "FireEvent - Could not get disp interface of AgentHandlerEvent object"));
  944. delete pEvent;
  945. }
  946. }
  947. else
  948. {
  949. STATICLOG((TL_ERROR, "FireEvent - Could not create AgentHandlerEvent object"));
  950. }
  951. STATICLOG((TL_TRACE, hr, "FireEvent - exit"));
  952. return hr;
  953. }
  954. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  955. // Class : CAgentHandlerEvent
  956. // Method : FinalRelease
  957. //
  958. //
  959. //
  960. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  961. void CAgentHandlerEvent::FinalRelease()
  962. {
  963. m_pAgentHandler->Release();
  964. }
  965. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  966. // Class : CAgentEvent
  967. // Interface : ITAgentEvent
  968. // Method : Agent
  969. //
  970. //
  971. //
  972. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  973. STDMETHODIMP CAgentHandlerEvent::get_AgentHandler(ITAgentHandler ** ppAgentHandler)
  974. {
  975. HRESULT hr = S_OK;
  976. LOG((TL_TRACE, "(Event)AgentHandler - enter" ));
  977. if(!TAPIIsBadWritePtr( ppAgentHandler, sizeof(ITAgentHandler *) ) )
  978. {
  979. *ppAgentHandler = m_pAgentHandler;
  980. m_pAgentHandler->AddRef();
  981. }
  982. else
  983. {
  984. LOG((TL_ERROR, "(Event)AgentHandler - bad ppAgentHandler Pointer"));
  985. hr = E_POINTER;
  986. }
  987. LOG((TL_TRACE, hr, "(Event)AgentHandler - exit"));
  988. return hr;
  989. }
  990. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  991. // Class : CAgentEvent
  992. // Interface : ITAgentEvent
  993. // Method : Event
  994. //
  995. //
  996. //
  997. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  998. STDMETHODIMP CAgentHandlerEvent::get_Event(AGENTHANDLER_EVENT * pEvent)
  999. {
  1000. HRESULT hr = S_OK;
  1001. LOG((TL_TRACE, "Event - enter" ));
  1002. if(!TAPIIsBadWritePtr( pEvent, sizeof(AGENTHANDLER_EVENT) ) )
  1003. {
  1004. *pEvent = m_AgentHandlerEvent;
  1005. }
  1006. else
  1007. {
  1008. LOG((TL_ERROR, "Event - bad pEvent Pointer"));
  1009. hr = E_POINTER;
  1010. }
  1011. LOG((TL_TRACE, hr, "Event - exit"));
  1012. return hr;
  1013. }