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.

117 lines
2.4 KiB

  1. /*++
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. tapi.c
  5. Abstract:
  6. This file implements common TAPI functionality
  7. Author:
  8. Mooly Beery (moolyb) 04-Jan-2001
  9. Environment:
  10. User Mode
  11. --*/
  12. #include <windows.h>
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <tchar.h>
  16. #include <WinSpool.h>
  17. #include <faxutil.h>
  18. #include <faxreg.h>
  19. BOOL
  20. GetCallerIDFromCall(
  21. HCALL hCall,
  22. LPTSTR lptstrCallerID,
  23. DWORD dwCallerIDSize
  24. )
  25. /*++
  26. Routine Description:
  27. This function will attempt to retrieve Caller ID data
  28. from the specified call handle.
  29. Arguments:
  30. hCall - TAPI call handle
  31. lptstrCallerID - pointer to buffer for Caller ID string
  32. dwCallerIDSize - size of the string pointed to by lptstrCallerID in TCHARs
  33. Return Values:
  34. TRUE for success
  35. FALSE for failure
  36. --*/
  37. {
  38. BOOL success = FALSE;
  39. LONG tapiStatus;
  40. DWORD dwCallInfoSize = sizeof(LINECALLINFO) + 2048;
  41. LINECALLINFO *pci = NULL;
  42. DEBUG_FUNCTION_NAME(TEXT("GetCallerIDFromCall"));
  43. Retry:
  44. pci = (LINECALLINFO *)MemAlloc(dwCallInfoSize);
  45. if(pci == NULL)
  46. {
  47. DebugPrintEx(
  48. DEBUG_ERR,
  49. TEXT("faled to allocate LINECALLINFO structure"));
  50. goto Cleanup;
  51. }
  52. ZeroMemory(pci, dwCallInfoSize);
  53. pci->dwTotalSize = dwCallInfoSize;
  54. tapiStatus = lineGetCallInfo(hCall, pci);
  55. if(tapiStatus == LINEERR_STRUCTURETOOSMALL)
  56. {
  57. dwCallInfoSize = pci->dwNeededSize;
  58. MemFree(pci);
  59. goto Retry;
  60. }
  61. if(tapiStatus != 0)
  62. {
  63. DebugPrintEx(
  64. DEBUG_ERR,
  65. TEXT("lineGetCallInfo() failed for offered call (error %x)"),
  66. tapiStatus);
  67. goto Cleanup;
  68. };
  69. // make sure we have enough space for caller ID and terminator
  70. if(pci->dwCallerIDSize + sizeof(TCHAR) > (dwCallerIDSize * sizeof(TCHAR)))
  71. {
  72. SetLastError(ERROR_INSUFFICIENT_BUFFER);
  73. goto Cleanup;
  74. }
  75. if(pci->dwCallerIDSize != 0)
  76. {
  77. memcpy((BYTE *)lptstrCallerID, (BYTE *)pci + pci->dwCallerIDOffset, pci->dwCallerIDSize);
  78. }
  79. // make sure it is zero terminated
  80. lptstrCallerID[(pci->dwCallerIDSize / sizeof(TCHAR))] = TEXT('\0');
  81. success = TRUE;
  82. Cleanup:
  83. if(pci)
  84. {
  85. MemFree(pci);
  86. }
  87. return success;
  88. }