home *** CD-ROM | disk | FTP | other *** search
/ Network Support Encyclopedia 96-1 / novell-nsepro-1996-1-cd2.iso / download / netware / tranfr.exe / TRANSFER.C < prev   
C/C++ Source or Header  |  1994-08-17  |  10KB  |  357 lines

  1. /****************************************************************************
  2. **    File:    TRANSFER.C
  3. **
  4. **    Desc:    Sample telephony program
  5. **
  6. **        This NetWare Telephony Services program opens a stream,
  7. **        makes a call, transfers the call, and closes the stream.
  8. **
  9. **        This program is written for Borland C 4.0 for Windows 3.1. It
  10. **        is compiled as an EASYWIN program, so that I didn't have to
  11. **        include all the Windows "overhead" code but can just get to
  12. **        the good stuff.
  13. **
  14. **
  15. **        DISCLAIMER
  16. **
  17. **    Novell, Inc. makes no representations or warranties with respect to
  18. **    any NetWare software, and specifically disclaims any express or
  19. **    implied warranties of merchantability, title, or fitness for a
  20. **    particular purpose.
  21. **
  22. **    Distribution of any NetWare software is forbidden without the
  23. **    express written consent of Novell, Inc.  Further, Novell reserves
  24. **    the right to discontinue distribution of any NetWare software.
  25. **
  26. **    Novell is not responsible for lost profits or revenue, loss of use
  27. **    of the software, loss of data, costs of re-creating lost data, the
  28. **    cost of any substitute equipment or program, or claims by any party
  29. **    other than you.  Novell strongly recommends a backup be made before
  30. **    any software is installed.   Technical support for this software
  31. **    may be provided at the discretion of Novell.
  32. **
  33. **    Programmers:
  34. **
  35. **        Ini    Who                        Firm
  36. **        -----------------------------------------------------------------------
  37. **        KVW    Kevin V White                Novell Developer Support.
  38. **
  39. **    History:
  40. **
  41. **        When        Who    What
  42. **        -----------------------------------------------------------------------
  43. **        08-17-94    kvw    First code.
  44. */
  45.  
  46. /****************************************************************************
  47. **    Include headers, macros, function prototypes, etc.
  48. */
  49.  
  50.     /*------------------------------------------------------------------------
  51.     **    ANSI
  52.     */
  53.     #include <stdio.h>
  54.     #include <string.h>
  55.  
  56.     /*------------------------------------------------------------------------
  57.     **    Windows
  58.     */
  59.     #include <windows.h>
  60.  
  61.     /*------------------------------------------------------------------------
  62.     **    Telephony
  63.     */
  64.     #include <acs.h>
  65.     #include <csta.h>
  66.  
  67. /****************************************************************************
  68. **    This function is the entire program, as it is very simple.
  69. **    Prompt user for input, open a stream, make a call, close the stream.
  70. */
  71. void main(void)
  72. {
  73.  
  74.     /*------------------------------------------------------------------
  75.     ** The following are defined for the first call, acsOpenStream
  76.     */
  77.     ACSHandle_t         acsHandle;
  78.     InvokeIDType_t        invokeIDType;
  79.     InvokeID_t        invokeID;
  80.     StreamType_t        streamType;
  81.     ServerID_t        serverID;
  82.     LoginID_t        loginID;
  83.     Passwd_t        passwd;
  84.     AppName_t        applicationName;
  85.     Level_t            acsLevelReq;
  86.     Version_t        apiVer;
  87.     unsigned short        sendQSize;
  88.     unsigned short        sendExtraBufs;
  89.     unsigned short        recvQSize;
  90.     unsigned short        recvExtraBufs;
  91.     PrivateData_t        *privateData;
  92.     RetCode_t        rCode;
  93.  
  94.     /*------------------------------------------------------------------
  95.     ** The following are additional variables necessary for
  96.     ** acsGetEventBlock
  97.     */
  98.     CSTAEvent_t            eventBuffer;
  99.     unsigned short        eventBufferSize;
  100.     unsigned short        numEvents;
  101.  
  102.     /*------------------------------------------------------------------
  103.     ** The following are for the cstaMakeCall
  104.     */
  105.     DeviceID_t            caller,callee,callee2;
  106.     ConnectionID_t        callID;
  107.  
  108.     /*------------------------------------------------------------------
  109.     ** The following are for the second cstaMakeCall
  110.     */
  111.     ConnectionID_t        secondCallID;
  112.  
  113.     /*------------------------------------------------------------------
  114.     ** Miscellaneous variables
  115.     */
  116.     short done=0;
  117.  
  118.  
  119.     /*------------------------------------------------------------------
  120.     ** Setup parameters for call to open stream.  Also, prompt user for
  121.     ** input.
  122.     */
  123.     invokeIDType=LIB_GEN_ID;
  124.     invokeID=0;          /* don't need it, but set to zero anyway */
  125.     streamType=ST_CSTA;     /* want to use csta functions */
  126.  
  127.     strcpy(serverID,"ATT#G3_SWITCH#CSTA#PRV-NMS");
  128.  
  129.     printf("\nEnter your user name:");
  130.     scanf("%s",loginID);
  131.     printf("\nEnter your password:");
  132.     scanf("%s",passwd);
  133.     printf("\nEnter your extension:");
  134.     scanf("%s",caller);
  135.     printf("\nEnter the extension you want to call:");
  136.     scanf("%s",callee);
  137.     printf("\nEnter a third extension, for the transfer:");
  138.     scanf("%s",callee2);
  139.  
  140.     strcpy(applicationName,"Simple App");
  141.     acsLevelReq=ACS_LEVEL1;
  142.     strcpy(apiVer,CSTA_API_VERSION);
  143.     sendQSize=0;         /* default size queue*/
  144.     sendExtraBufs=0;     /* use default number */
  145.     recvQSize=0;         /* use default size */
  146.     recvExtraBufs=0;     /* use default number */
  147.     privateData=NULL;     /* no private data */
  148.  
  149.     /*------------------------------------------------------------------
  150.     ** Open the stream with above parameters
  151.     */
  152.     rCode=acsOpenStream(&acsHandle,invokeIDType,invokeID,streamType,
  153.             serverID,loginID,passwd,applicationName,acsLevelReq,
  154.             apiVer,sendQSize,sendExtraBufs,recvQSize,recvExtraBufs,
  155.             privateData);
  156.  
  157.     if (rCode < 0)
  158.     {
  159.         printf("acsOpenStream failure...");
  160.         return;
  161.     }
  162.     else
  163.     {
  164.         printf("acsOpenStream success\n");
  165.         invokeID=rCode;
  166.     }
  167.  
  168.     /*------------------------------------------------------------------
  169.     ** Block until the confirmation has been received that the stream
  170.     ** was successfully opened.  Just because NetWare returned the function
  171.     ** code doesn't mean the stream has been opened yet.
  172.     */
  173.     eventBufferSize=sizeof(CSTAEvent_t);
  174.     rCode=acsGetEventBlock(acsHandle,&eventBuffer,&eventBufferSize,
  175.             privateData,&numEvents);
  176.     if(rCode==ACSPOSITIVE_ACK)
  177.     {
  178.         if(eventBuffer.eventHeader.eventType == ACS_OPEN_STREAM_CONF)
  179.         {
  180.             printf("ACS_OPEN_STREAM_CONF message has been received\n");
  181.         }
  182.         else
  183.         {
  184.             printf("event type is incorrect...");
  185.             return;
  186.         }
  187.     }
  188.     else
  189.     {
  190.         printf("acsGetEventBlock failure...");
  191.         return;
  192.     }
  193.  
  194.     /*------------------------------------------------------------------
  195.     ** Now that the stream has been successfully opened, go ahead and
  196.     ** issue the make call function.
  197.     */
  198.     rCode=cstaMakeCall(acsHandle,invokeID,caller,callee,
  199.     privateData);
  200.  
  201.     /*------------------------------------------------------------------
  202.     ** Now we need to poll for events until a confirmation has been
  203.     ** received that the PBX has been able to make the call.  Note that
  204.     ** if something is invalid, the program will enter an infinite loop,
  205.     ** as this simple program just sits and waits until a confirmation
  206.     ** returns that is successful.
  207.     */
  208.     while (!done)
  209.     {
  210.         rCode=acsGetEventPoll(acsHandle,&eventBuffer,&eventBufferSize,
  211.                 privateData,&numEvents);
  212.  
  213.         if(rCode==ACSPOSITIVE_ACK)
  214.         {
  215.             if(eventBuffer.eventHeader.eventType == CSTA_MAKE_CALL_CONF)
  216.             {
  217.                 printf("CSTA_MAKE_CALL_CONF message has been received\n");
  218.                 callID=eventBuffer.event.cstaConfirmation.u.makeCall.newCall;
  219.                 done=1;
  220.             }
  221.             else
  222.             {
  223.                 printf("event type is incorrect...");
  224.             }
  225.         }
  226.     }
  227.  
  228.     /*------------------------------------------------------------------
  229.     ** Do a cstaHoldCall, which puts the first call on hold, so we can
  230.     ** make the second call.
  231.     */
  232.     printf("press a key when you're ready to put the call on hold...\n");
  233.     getch();
  234.     rCode=cstaHoldCall(acsHandle,invokeID,&callID,FALSE,privateData);
  235.  
  236.     if (rCode<=0)
  237.     {
  238.         printf("cstaHoldCall failed\n");
  239.         return;
  240.     }
  241.  
  242.     /*------------------------------------------------------------------
  243.     ** Now we need to poll for events until a confirmation has been
  244.     ** received that the PBX has been able to put the call on hold.
  245.     */
  246.     done=0;
  247.     while (!done)
  248.     {
  249.         rCode=acsGetEventPoll(acsHandle,&eventBuffer,&eventBufferSize,
  250.                 privateData,&numEvents);
  251.  
  252.         if(rCode==ACSPOSITIVE_ACK)
  253.         {
  254.             if(eventBuffer.eventHeader.eventType == CSTA_HOLD_CALL_CONF)
  255.             {
  256.                 printf("CSTA_HOLD_CALL_CONF message has been received\n");
  257.                 done=1;
  258.             }
  259.             else
  260.             {
  261.                 printf("event type is incorrect...");
  262.             }
  263.         }
  264.     }
  265.  
  266.     /*------------------------------------------------------------------
  267.     ** Now that the first call has been put on hold, we can go ahead and
  268.     ** make the second call.
  269.     */
  270.     printf("press a key when you're ready to make the second call...\n");
  271.     getch();
  272.     rCode=cstaMakeCall(acsHandle,invokeID,caller,callee2,
  273.     privateData);
  274.  
  275.     /*------------------------------------------------------------------
  276.     ** Now we need to poll for events until a confirmation has been
  277.     ** received that the PBX has been able to make the call.
  278.     */
  279.     done=0;
  280.     while (!done)
  281.     {
  282.         rCode=acsGetEventPoll(acsHandle,&eventBuffer,&eventBufferSize,
  283.                 privateData,&numEvents);
  284.  
  285.         if(rCode==ACSPOSITIVE_ACK)
  286.         {
  287.             if(eventBuffer.eventHeader.eventType == CSTA_MAKE_CALL_CONF)
  288.             {
  289.                 printf("CSTA_MAKE_CALL_CONF message has been received\n");
  290.                 secondCallID=eventBuffer.event.cstaConfirmation.u.makeCall.newCall;
  291.                 done=1;
  292.             }
  293.             else
  294.             {
  295.                 printf("event type is incorrect...");
  296.             }
  297.         }
  298.     }
  299.  
  300.     /*------------------------------------------------------------------
  301.     ** Well, now we can transfer the call.
  302.     */
  303.     printf("press a key when you're ready to transfer the calls...\n");
  304.     getch();
  305.     rCode=cstaTransferCall(acsHandle,invokeID,&callID,
  306.                         &secondCallID,privateData);
  307.  
  308.     if(rCode<=0)
  309.     {
  310.         printf("cstaTransferCall() failed\n");
  311.         return;
  312.     }
  313.  
  314.     /*------------------------------------------------------------------
  315.     ** Now we can get the confirmation event to make sure it worked ok.
  316.     */
  317.     done=0;
  318.     while (!done)
  319.     {
  320.         rCode=acsGetEventPoll(acsHandle,&eventBuffer,&eventBufferSize,
  321.                 privateData,&numEvents);
  322.  
  323.         if(rCode==ACSPOSITIVE_ACK)
  324.         {
  325.             if(eventBuffer.eventHeader.eventType == CSTA_TRANSFER_CALL_CONF)
  326.             {
  327.                 printf("CSTA_TRANSFER_CALL_CONF message has been received\n");
  328.                 done=1;
  329.             }
  330.             else
  331.             {
  332.                 printf("event type is incorrect...");
  333.             }
  334.         }
  335.     }
  336.  
  337.  
  338.     /*------------------------------------------------------------------
  339.     ** All done! Time to close the stream now.
  340.     */
  341.     printf("press a key to close the stream...\n");
  342.     getch();
  343.     rCode=acsCloseStream(acsHandle,invokeID,privateData);
  344.  
  345.     if (rCode < 0)
  346.     {
  347.         printf("acsCloseStream failure...");
  348.         return;
  349.     }
  350.     else
  351.     {
  352.         printf("acsCloseStream success\n");
  353.     }
  354.  
  355.     return;
  356. }
  357.