home *** CD-ROM | disk | FTP | other *** search
/ Network Support Encyclopedia 96-1 / novell-nsepro-1996-1-cd2.iso / download / netware / kvfon2.exe / LOGINDLG.H < prev    next >
C/C++ Source or Header  |  1994-11-02  |  9KB  |  270 lines

  1. /****************************************************************************
  2. **    File:    LOGINDLG.H
  3. **
  4. **    Desc:    Header file containing the login dialog source code.
  5. **
  6. **    This file contains the login dialog source code for opening a stream, and
  7. **    getting ready for the rest of the csta calls.
  8. **
  9. **    It is written for OWL 2.0 with Borland C++ 4.x.  To compile this program,
  10. **    create a project in BC4.x, similar to the .IDE project file included.
  11. **
  12. **        DISCLAIMER
  13. **
  14. **    Novell, Inc. makes no representations or warranties with respect to
  15. **    any NetWare software, and specifically disclaims any express or
  16. **    implied warranties of merchantability, title, or fitness for a
  17. **    particular purpose.
  18. **
  19. **    You may use this sample code in your own programs.
  20. **
  21. **    Distribution of any NetWare software is forbidden without the
  22. **    express written consent of Novell, Inc.  Further, Novell reserves
  23. **    the right to discontinue distribution of any NetWare software.
  24. **
  25. **    Novell is not responsible for lost profits or revenue, loss of use
  26. **    of the software, loss of data, costs of re-creating lost data, the
  27. **    cost of any substitute equipment or program, or claims by any party
  28. **    other than you.  Novell strongly recommends a backup be made before
  29. **    any software is installed.   Technical support for this software
  30. **    may be provided at the discretion of Novell.
  31. **
  32. **    Programmers:
  33. **
  34. **        Ini    Who                        Firm
  35. **        -----------------------------------------------------------------------
  36. **        KVW    Kevin V White        Novell Developer Support.
  37. **
  38. **    History:
  39. **
  40. **        When        Who    What
  41. **        -----------------------------------------------------------------------
  42. **        11-2        KVW    First code release
  43. */
  44.  
  45. /****************************************************************************
  46. **    Declare a callback function for doing the acsEnumServers().
  47. */
  48. Boolean FAR PASCAL _export ListTServers(char *serverName,unsigned long lParam);
  49.  
  50.  
  51. /****************************************************************************
  52. **    This is the login dialog class.
  53. */
  54. class TLoginDlg:public TDialog
  55. {
  56.     public:
  57.         TLoginDlg(TWindow *parent, TResId resId,ACSHandle_t *acsHandle,
  58.             DeviceID_t *device);
  59.         void CmOk();
  60.         void SetupWindow();
  61.         void CleanupWindow();
  62.  
  63.         ACSHandle_t *globalACSHandle;
  64.         DeviceID_t *usersExt;
  65.         TEdit *userNameField;
  66.         TEdit *passwordField;
  67.         TComboBox *tServersField;
  68.         TEdit *phoneExt;
  69.  
  70.     DECLARE_RESPONSE_TABLE(TLoginDlg);
  71. };
  72.  
  73. /****************************************************************************
  74. **    OWL uses this code to setup its windows message loop.
  75. */
  76. DEFINE_RESPONSE_TABLE1(TLoginDlg,TDialog)
  77.     EV_COMMAND(IDOK,CmOk),
  78. END_RESPONSE_TABLE;
  79.  
  80. /****************************************************************************
  81. **    login dialog constructor.  We are just setting our member variables to
  82. ** the pointers that were passed to the constructor for the acsHandle and
  83. ** the device (the user's phone extension).  This way, other objects in
  84. ** our program have access to these same values.
  85. */
  86. TLoginDlg::TLoginDlg(TWindow *parent, TResId resId,ACSHandle_t *acsHandle,
  87.     DeviceID_t *device)
  88.     :TDialog(parent, resId),TWindow(parent)
  89. {
  90.     globalACSHandle=acsHandle;
  91.     usersExt=device;
  92. }
  93.  
  94. /****************************************************************************
  95. **    SetupWindow is called by OWL.  We override it, first calling the parent's
  96. ** SetupWindow function.
  97. */
  98. void TLoginDlg::SetupWindow()
  99. {
  100.     EnumServerNamesCB serversList;
  101.  
  102.     TDialog::SetupWindow();
  103.  
  104.     /*------------------------------------------------------------------------
  105.     **    We do the acsEnumServerNames here, to fill our combobox (drop down list
  106.     ** box) with the names of the available telephony servers
  107.     */
  108.     serversList=(EnumServerNamesCB) MakeProcInstance((FARPROC)ListTServers,NULL);
  109.     acsEnumServerNames(ST_CSTA,serversList,(unsigned long)this);
  110.  
  111.     /*------------------------------------------------------------------------
  112.     **    We created a dialog resource, which was already displayed.  Now, in order
  113.     ** to simplify getting the data out of the controls, we create new TEdit
  114.     ** and TComboBox elements which point to the controls on the dialog that have
  115.     ** already been created with the dialog.
  116.     */
  117.     userNameField=new TEdit(this,IDC_USERNAME,100);
  118.     userNameField->Create();
  119.     passwordField=new TEdit(this,IDC_PASSWORD,100);
  120.     passwordField->Create();
  121.     tServersField=new TComboBox(this,IDC_COMBOBOX1,100);
  122.     tServersField->Create();
  123.     phoneExt=new TEdit(this,IDC_PHONEEXT,65);
  124.     phoneExt->Create();
  125. }
  126.  
  127. /****************************************************************************
  128. **    CleanupWindow is called when the window is to be destroyed.
  129. */
  130. void TLoginDlg::CleanupWindow()
  131. {
  132.     /*------------------------------------------------------------------------
  133.     ** delete the memory allocated in SetupWindow.
  134.     */
  135.     delete userNameField;
  136.     delete passwordField;
  137.     delete tServersField;
  138.     delete phoneExt;
  139.  
  140.     /*------------------------------------------------------------------------
  141.     **    call the parent's CleanupWindow so we can be sure we get all the
  142.     ** necessary functionality.
  143.     */
  144.     TDialog::CleanupWindow();
  145. }
  146.  
  147. /****************************************************************************
  148. **    CmOk is called when the user presses the OK button, to login.
  149. */
  150. void TLoginDlg::CmOk()
  151. {
  152.     /*------------------------------------------------------------------------
  153.     **    necessary variables for the acsOpenStream() call, and a couple of
  154.     ** miscellaneous data variables.
  155.     */
  156.     ServerID_t    serverID;
  157.     LoginID_t    loginID;
  158.     Passwd_t        password;
  159.     int            textLen;
  160.  
  161.     RetCode_t    rCode;
  162.     InvokeID_t    invokeID=0;
  163.     AppName_t    appName;
  164.     Level_t        acsLevelReq=ACS_LEVEL1;
  165.     Version_t    apiVer;
  166.     unsigned short    sendQSize=15;
  167.     unsigned short    sendExtraBufs=0;
  168.     unsigned short    recvQSize=15;
  169.     unsigned short recvExtraBufs=0;
  170.     PrivateData_t    *privateData=NULL;
  171.  
  172.     CSTAEvent_t        eventBuffer;
  173.     unsigned short    eventBufferSize;
  174.     unsigned short numEvents;
  175.  
  176.     /*------------------------------------------------------------------------
  177.     **    fill all of our variables with the data to open the acs stream
  178.     */
  179.     strcpy(apiVer,CSTA_API_VERSION);
  180.     strcpy(appName,"KVPhone");
  181.  
  182.     /*------------------------------------------------------------------------
  183.     **    Did the user select a TServer?
  184.     */
  185.     textLen=tServersField->GetStringLen(tServersField->GetSelIndex());
  186.     if(textLen>0)
  187.     {
  188.         /*---------------------------------------------------------------------
  189.         **    get the data out of the edit boxes and the list box
  190.         */
  191.         tServersField->GetText(serverID,textLen+1);
  192.         userNameField->GetLine(loginID,100,0);
  193.         passwordField->GetLine(password,100,0);
  194.         phoneExt->GetLine(*usersExt,65,0);
  195.  
  196.         /*---------------------------------------------------------------------
  197.         **    open the stream
  198.         */
  199.         rCode=acsOpenStream(globalACSHandle,LIB_GEN_ID,invokeID,ST_CSTA,&serverID,
  200.             &loginID,&password,&appName,acsLevelReq,&apiVer,sendQSize,
  201.             sendExtraBufs,recvQSize,recvExtraBufs,privateData);
  202.  
  203.         /*---------------------------------------------------------------------
  204.         **    check to make sure it was opened correctly.  If it was, we'll keep
  205.         **    the acsHandle that was returned.
  206.         */
  207.         if(rCode>0)
  208.         {
  209.             eventBufferSize=sizeof(CSTAEvent_t);
  210.             rCode=acsGetEventBlock(*globalACSHandle,&eventBuffer,&eventBufferSize,
  211.                 privateData,&numEvents);
  212.             if(rCode==ACSPOSITIVE_ACK)
  213.             {
  214.                 if(eventBuffer.eventHeader.eventType == ACS_OPEN_STREAM_CONF)
  215.                 {
  216.                     MessageBox("Stream Opened...","TS Success!");
  217.                 }
  218.                 else
  219.                 {
  220.                     MessageBox("Stream not opened","TS Error!");
  221.                     /*------------------------------------------------------------
  222.                     **    stream not opened, set the acsHandle to 0
  223.                     */
  224.                     *globalACSHandle=0;
  225.                 }
  226.             }
  227.             else
  228.             {
  229.                 MessageBox("Can't get event","TS Error!");
  230.                 /*---------------------------------------------------------------
  231.                 **    stream not opened, set the acsHandle to 0
  232.                 */
  233.                 *globalACSHandle=0;
  234.             }
  235.         }
  236.         else
  237.         {
  238.             MessageBox("Login Unsuccessful","TS Error!");
  239.             /*------------------------------------------------------------------
  240.             **    stream not opened, set the acsHandle to 0
  241.             */
  242.             *globalACSHandle=0;
  243.         }
  244.     }
  245.     /*------------------------------------------------------------------------
  246.     **    call the parent's ok function for default processing.
  247.     */
  248.     TDialog::CmOk();
  249. }
  250.  
  251. /****************************************************************************
  252. **    this is the callback function.  When we call acsEnumServerNames, from the
  253. **    login dialog, csta.dll will call this function for each telephony server
  254. **    that it can find, or until we return FALSE here.  That is, if we return
  255. **    FALSE, we will not be notified of any more TServers.  We return TRUE so
  256. **    we are notified of all TServers available.
  257. */
  258. Boolean FAR PASCAL _export ListTServers(char *serverName,unsigned long lParam)
  259. {
  260.     /*------------------------------------------------------------------------
  261.     **    all we want to do is add the server name to the combobox on our dialog.
  262.     **    we don't worry about saving the data in an array or anything.  We are
  263.     **    going to use the GetText() function to get the text of whatever item
  264.     **    the user selected, so we don't have any reason to save these into an
  265.     **    array.
  266.     */
  267.     ((TLoginDlg *)lParam)->SendDlgItemMessage(IDC_COMBOBOX1,CB_ADDSTRING,0,(LPARAM)serverName);
  268.     return TRUE;
  269. }
  270.