home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 8 Other / 08-Other.zip / pmvnc100.zip / sess.c < prev    next >
C/C++ Source or Header  |  1999-08-03  |  22KB  |  852 lines

  1. /*
  2.  * sess.c - PM VNC Viewer, Session Setup
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8.  
  9. #define INCL_PM
  10. #include <os2.h>
  11.  
  12. #include "pmvncdef.h"
  13. #include "pmvncres.h"
  14.  
  15. /*
  16.  * VNC Session Parameters
  17.  */
  18.  
  19. UCHAR   SessServerName[128] ;       /* as host:port */
  20.  
  21. SHORT   SessPixelFormat       = PIXFMT_32          ;
  22. CARD32  SessPreferredEncoding = rfbEncodingHextile ;
  23.  
  24. BOOL    SessOptShared    = FALSE ;
  25. BOOL    SessOptViewonly  = FALSE ;
  26. BOOL    SessOptDeiconify = FALSE ;
  27.  
  28. BOOL    SessDlgCenter = FALSE ;     /* Place Dialog at Center or    */
  29.                                     /* near mouse pointer           */
  30.  
  31. PUCHAR  SessPasswdFile = NULL ;     /* Given passwd file name       */
  32.                                     
  33. SIZEL   SessSavedRfb = { 0, 0 } ;   /* RFB size   on last session   */
  34. POINTL  SessSavedPos = { 0, 0 } ;   /* Frame pos  on last session   */
  35. SIZEL   SessSavedSiz = { 0, 0 } ;   /* Frame size on last session   */
  36. POINTL  SessSavedOff = { 0, 0 } ;   /* RFB offset on last session   */
  37.  
  38. /*
  39.  * options from Command Line Arguments
  40.  *      later, marged to session parameters
  41.  */
  42.  
  43. static  PUCHAR  argServer       = NULL  ;
  44. static  BOOL    argFormat32     = FALSE ;
  45. static  BOOL    argFormat8      = FALSE ;
  46. static  BOOL    argFormatTiny   = FALSE ;
  47. static  BOOL    argFormatGray   = FALSE ;
  48. static  BOOL    argEncodeRaw    = FALSE ;
  49. static  BOOL    argEncodeRre    = FALSE ;
  50. static  BOOL    argEncodeCor    = FALSE ;
  51. static  BOOL    argEncodeHex    = FALSE ;
  52. static  BOOL    argOptShared    = FALSE ;
  53. static  BOOL    argOptViewonly  = FALSE ;
  54. static  BOOL    argOptDeiconify = FALSE ;
  55.  
  56. #define rstFormat() argFormat32=argFormat8=argFormatTiny=argFormatGray=FALSE
  57. #define rstEncode() argEncodeRaw=argEncodeRre=argEncodeCor=argEncodeHex=FALSE
  58.  
  59. void    sessParse(int ac, char *av[])
  60. {
  61.     int     i ;
  62.  
  63.     TRACE("SessParse\n") ;
  64.     
  65.     for (i = 1 ; i < ac ; i++) {
  66.         if (av[i][0] != '-') {
  67.         argServer = av[i] ;
  68.         } else if (stricmp(&av[i][1], "true") == 0) {
  69.         rstFormat() ;
  70.         argFormat32 = TRUE ;
  71.         } else if (stricmp(&av[i][1], "32bits") == 0) {
  72.         rstFormat() ;
  73.         argFormat32 = TRUE ;
  74.     } else if (stricmp(&av[i][1], "bgr233") == 0) {
  75.             rstFormat() ;
  76.         argFormat8 = TRUE ;
  77.     } else if (stricmp(&av[i][1], "8bits") == 0) {
  78.         rstFormat() ;
  79.         argFormat8 = TRUE ;
  80.     } else if (stricmp(&av[i][1], "use8bits") == 0) {   /* compat. */
  81.             rstFormat() ;
  82.         argFormat8 = TRUE ;
  83.     } else if (stricmp(&av[i][1], "tiny") == 0) {
  84.             rstFormat() ;
  85.         argFormatTiny = TRUE ;
  86.     } else if (stricmp(&av[i][1], "gray") == 0) {
  87.             rstFormat() ;
  88.         argFormatGray = TRUE ;
  89.         } else if (stricmp(&av[i][1], "Raw") == 0) {
  90.             rstEncode() ;
  91.         argEncodeRaw = TRUE ;
  92.         } else if (stricmp(&av[i][1], "RRE") == 0) {
  93.         rstEncode() ;
  94.         argEncodeRre = TRUE ;
  95.         } else if (stricmp(&av[i][1], "CoRRE") == 0) {
  96.         rstEncode() ;
  97.         argEncodeCor = TRUE ;
  98.         } else if (stricmp(&av[i][1], "Hextile") == 0) {
  99.         rstEncode() ;
  100.         argEncodeHex = TRUE ;
  101.         } else if (stricmp(&av[i][1], "shared") == 0) {
  102.         argOptShared    = TRUE ;
  103.         } else if (stricmp(&av[i][1], "viewonly") == 0) {
  104.         argOptViewonly  = TRUE ;
  105.         } else if (stricmp(&av[i][1], "deiconify") == 0) {
  106.         argOptDeiconify = TRUE ;
  107.     } else if (stricmp(&av[i][1], "dialogatcenter") == 0) {
  108.         SessDlgCenter = TRUE  ;
  109.     } else if (stricmp(&av[i][1], "dialogatmouse") == 0) {
  110.         SessDlgCenter = FALSE ;
  111.     } else if (stricmp(&av[i][1], "passwd") == 0) {
  112.         if ((i + 1) < ac) {
  113.             SessPasswdFile = av[i+=1] ;
  114.         }
  115.     } else if (stricmp(&av[i][1], "keymap") == 0) {
  116.         if ((i + 1) < ac) {
  117.             kmapLoad(av[i+=1]) ;
  118.         }
  119.     }
  120.     }
  121.  
  122.     TRACE("SessParse ... done\n") ;
  123. }
  124.  
  125. /*
  126.  * Session Informations in Profile
  127.  */
  128.  
  129. typedef  struct _HOST {
  130.     UCHAR   name[128] ;
  131.     SHORT   format    ;
  132.     CARD32  encode    ;
  133.     BOOL    shared    ;
  134.     BOOL    viewonly  ;
  135.     BOOL    deiconify ;
  136.     SIZEL   rfb       ;
  137.     POINTL  pos       ;
  138.     SIZEL   siz       ;
  139.     POINTL  off       ;
  140. } HOSTREC, *HOSTPTR ;
  141.  
  142. #define MAXHOSTS    8
  143.  
  144. static  UCHAR   profOrder[MAXHOSTS] ;
  145. static  HOSTREC profHosts[MAXHOSTS] ;
  146.  
  147. /*
  148.  * loadProfile - load profile data, merging given arguments
  149.  */
  150.  
  151. static  BOOL    loadProfile(HAB hab)
  152. {
  153.     HINI    hini ;
  154.     BOOL    stat ;
  155.     LONG    len  ;
  156.     int     i, id ;
  157.     UCHAR   key[32] ;
  158.  
  159.     TRACE("loadProfile [%s]\n", ProfilePath) ;
  160.     
  161.     /*
  162.      * load host order
  163.      */
  164.      
  165.     if ((hini = PrfOpenProfile(hab, ProfilePath)) == NULLHANDLE) {
  166.         TRACE("loadProfile - failed to open %s\n", ProfilePath) ;
  167.         return FALSE ;
  168.     }
  169.     
  170.     len = sizeof(profOrder) ;
  171.     stat = PrfQueryProfileData(hini, ProgramName, "ORDER", profOrder, &len) ;
  172.  
  173.     if (stat != TRUE || len != sizeof(profOrder)) {
  174.         PrfCloseProfile(hini) ;
  175.     memset(profOrder, 0xff, sizeof(profOrder)) ;
  176.     TRACE("loadProfile - failed to read Order\n") ;
  177.     return FALSE ;
  178.     }
  179.     
  180.     /*
  181.      * load host informations
  182.      */
  183.      
  184.     for (i = 0 ; i < MAXHOSTS ; i++) {
  185.         if ((id = profOrder[i]) == 0xff) {
  186.         continue ;
  187.     }
  188.     sprintf(key, "HOST%02d", id) ;
  189.     len = sizeof(HOSTREC) ;
  190.     stat = PrfQueryProfileData(hini,
  191.                 ProgramName, key, &profHosts[id], &len) ;
  192.         if (stat != TRUE || len != sizeof(HOSTREC)) {
  193.         PrfCloseProfile(hini) ;
  194.             memset(profOrder, 0xff, sizeof(profOrder)) ;
  195.             TRACE("loadProfile - failed to read Host Data %d\n", id) ;
  196.         return FALSE ;
  197.     }
  198.     }
  199.     PrfCloseProfile(hini) ;
  200.  
  201.     /*
  202.      * modified with command line arguments
  203.      */
  204.      
  205.     for (i = 0 ; i < MAXHOSTS ; i++) {
  206.         if ((id = profOrder[i]) == 0xff) {
  207.         continue ;
  208.     }
  209.         if (argFormat32) {
  210.         profHosts[id].format = PIXFMT_32 ;
  211.     } 
  212.     if (argFormat8) {
  213.         profHosts[id].format = PIXFMT_8 ;
  214.     }
  215.     if (argFormatTiny) {
  216.         profHosts[id].format = PIXFMT_TINY ;
  217.     }
  218.     if (argFormatGray) {
  219.         profHosts[id].format = PIXFMT_GRAY ;
  220.         }
  221.     if (argEncodeRaw) {
  222.         profHosts[id].encode = rfbEncodingRaw ;
  223.     }
  224.     if (argEncodeRre) {
  225.         profHosts[id].encode = rfbEncodingRRE ;
  226.     }
  227.     if (argEncodeCor) {
  228.         profHosts[id].encode = rfbEncodingCoRRE ;
  229.     }
  230.     if (argEncodeHex) {
  231.         profHosts[id].encode = rfbEncodingHextile ;
  232.     }
  233.     if (argOptShared) {
  234.         profHosts[id].shared = TRUE ;
  235.     }
  236.     if (argOptViewonly) {
  237.         profHosts[id].viewonly = TRUE ;
  238.     }
  239.     if (argOptDeiconify) {
  240.         profHosts[id].deiconify = TRUE ;
  241.     }
  242.     }
  243.  
  244.     /*
  245.      * also modify current session parameters
  246.      */
  247.      
  248.     if (argServer) {
  249.         strcpy(SessServerName, argServer) ;
  250.     }
  251.     if (argFormat32) {
  252.         SessPixelFormat = PIXFMT_32 ;
  253.     }
  254.     if (argFormat8) {
  255.         SessPixelFormat = PIXFMT_8 ;
  256.     }
  257.     if (argFormatTiny) {
  258.         SessPixelFormat = PIXFMT_TINY ;
  259.     }
  260.     if (argFormatGray) {
  261.         SessPixelFormat = PIXFMT_GRAY ;
  262.     }
  263.     if (argEncodeRaw) {
  264.     SessPreferredEncoding = rfbEncodingRaw ;
  265.     }
  266.     if (argEncodeRre) {
  267.         SessPreferredEncoding = rfbEncodingRRE ;
  268.     }
  269.     if (argEncodeCor) {
  270.         SessPreferredEncoding = rfbEncodingCoRRE ;
  271.     }
  272.     if (argEncodeHex) {
  273.         SessPreferredEncoding = rfbEncodingHextile ;
  274.     }
  275.     if (argOptShared) {
  276.         SessOptShared = TRUE ;
  277.     }
  278.     if (argOptViewonly) {
  279.         SessOptViewonly = TRUE ;
  280.     }
  281.     if (argOptDeiconify) {
  282.         SessOptDeiconify = TRUE ;
  283.     }
  284.  
  285.     TRACE("loadProfile ... done\n") ;
  286.  
  287.     return TRUE ;
  288. }
  289.  
  290. /*
  291.  * loadParam - set paramaters for given server
  292.  */
  293.  
  294. static  int     loadParam(PUCHAR server)
  295. {
  296.     int     i, id ;
  297.     
  298.     TRACE("loadParam for server %s\n", server) ;
  299.  
  300.     for (i = 0 ; i < MAXHOSTS ; i++) {
  301.         if ((id = profOrder[i]) == 0xff) {
  302.         continue ;
  303.     }
  304.     if (stricmp(server, profHosts[id].name) != 0) {
  305.         continue ;
  306.     }
  307.     strcpy(SessServerName, server) ;
  308.         SessPixelFormat       = profHosts[id].format    ;
  309.     SessPreferredEncoding = profHosts[id].encode    ;
  310.     SessOptShared         = profHosts[id].shared    ;
  311.     SessOptViewonly       = profHosts[id].viewonly  ;
  312.     SessOptDeiconify      = profHosts[id].deiconify ;
  313.         SessSavedRfb          = profHosts[id].rfb       ;
  314.         SessSavedPos          = profHosts[id].pos       ;
  315.         SessSavedSiz          = profHosts[id].siz       ;
  316.         SessSavedOff          = profHosts[id].off       ;
  317.         TRACE("loadParam ... loaded %d data to host %s\n", id, server) ;
  318.     TRACE("  rfb %dx%d, pos %d,%d, siz %dx%d, off %d,%d\n", 
  319.                     SessSavedRfb.cx, SessSavedRfb.cy,
  320.                     SessSavedPos.x,  SessSavedPos.y,
  321.             SessSavedSiz.cx, SessSavedSiz.cy,
  322.                     SessSavedOff.x,  SessSavedOff.y) ;
  323.         return id ;
  324.     }
  325.     strcpy(SessServerName, server) ;
  326.     TRACE("loadParam ... host %s use current values\n", server) ;
  327.     return -1 ;
  328. }
  329.  
  330. /*
  331.  * saveParam - save parameter with host 'SessServerName'
  332.  */
  333.  
  334. static  int     saveParam(void)
  335. {
  336.     int     i, j, id, entry ;
  337.     UCHAR   newOrder[MAXHOSTS + 1] ;
  338.     
  339.     TRACE("saveParam for <%s>\n", SessServerName) ;
  340.     
  341.     if (strlen(SessServerName) == 0) {
  342.         return -1 ;
  343.     }
  344.     if (strchr(SessServerName, ':') == NULL) {
  345.         return -1 ;
  346.     }
  347.     
  348.     /*
  349.      * select HOST entry for 'SessServerName'
  350.      */
  351.      
  352.     entry = -1 ;
  353.     
  354.     if (entry == -1) {          /* already exist in list */
  355.         for (i = 0 ; i < MAXHOSTS ; i++) {
  356.             if (stricmp(profHosts[i].name, SessServerName) == 0) {
  357.             entry = i ;
  358.                 TRACE("saveParam - use existing entry %d\n", entry) ;
  359.             break ;
  360.         }
  361.         }
  362.  
  363.     }
  364.     if (entry == -1) {          /* use empty entry */
  365.         for (i = 0 ; i < MAXHOSTS ; i++) {
  366.             if (profOrder[i] == 0xff) {
  367.             entry = i ;
  368.             TRACE("saveParam - use empty entry %d\n", entry) ;
  369.             break ;
  370.         }
  371.         }
  372.     }
  373.     if (entry == -1) {          /* use last one */
  374.         entry = profOrder[MAXHOSTS - 1] ;
  375.     TRACE("saveParam - replace %d\n", entry) ;
  376.     }
  377.     
  378.     memset(newOrder, 0xff, sizeof(newOrder)) ;
  379.     newOrder[0] = entry ;
  380.  
  381.     for (i = 0, j = 1 ; i < MAXHOSTS ; i++) {
  382.         if ((id = profOrder[i]) == 0xff) {
  383.         continue ;
  384.     }
  385.     if (id == entry) {
  386.         continue ;
  387.     }
  388.         newOrder[j++] = id ;
  389.     }
  390.     
  391.     memcpy(profOrder, newOrder, sizeof(profOrder)) ;
  392.     
  393.     /*
  394.      * save to host entry
  395.      */
  396.      
  397.     strcpy(profHosts[entry].name, SessServerName)      ;
  398.     profHosts[entry].format    = SessPixelFormat       ;
  399.     profHosts[entry].encode    = SessPreferredEncoding ;
  400.     profHosts[entry].shared    = SessOptShared         ;
  401.     profHosts[entry].viewonly  = SessOptViewonly       ;
  402.     profHosts[entry].deiconify = SessOptDeiconify      ;
  403.     profHosts[entry].rfb       = SessSavedRfb          ;
  404.     profHosts[entry].pos       = SessSavedPos          ;
  405.     profHosts[entry].siz       = SessSavedSiz          ;
  406.     profHosts[entry].off       = SessSavedOff          ;
  407.  
  408.     TRACE("saveParam ... saved to %d entry\n", entry) ;
  409.     TRACE("  rfb %dx%d, pos %d,%d, siz %dx%d, off %d,%d\n", 
  410.         SessSavedRfb.cx, SessSavedRfb.cy,
  411.                 SessSavedPos.x,  SessSavedPos.y,
  412.         SessSavedSiz.cx, SessSavedSiz.cy,
  413.                 SessSavedOff.x,  SessSavedOff.y) ;
  414.     return entry ;
  415. }
  416.  
  417. /*
  418.  * saveProfile - save current parameter as profile data
  419.  */
  420.  
  421. static  BOOL    saveProfile(HAB hab)
  422. {
  423.     int     entry, i, id ;
  424.     HINI    hini  ;
  425.     BOOL    stat  ;
  426.     LONG    len   ;
  427.     UCHAR   key[32] ;
  428.     
  429.     TRACE("saveProfile\n") ;
  430.  
  431.     /*
  432.      * save to profile
  433.      */
  434.  
  435.     if ((hini = PrfOpenProfile(hab, ProfilePath)) == NULLHANDLE) {
  436.         TRACE("saveProfile - failed to open %s\n", ProfilePath) ;
  437.         return FALSE ;
  438.     }
  439.     
  440.     /*
  441.      * re-load new profile
  442.      */
  443.  
  444.     len = sizeof(profOrder) ;
  445.     stat = PrfQueryProfileData(hini, ProgramName, "ORDER", profOrder, &len) ;
  446.  
  447.     if (stat != TRUE || len != sizeof(profOrder)) {
  448.     memset(profOrder, 0xff, sizeof(profOrder)) ;
  449.     }
  450.  
  451.     for (i = 0 ; i < MAXHOSTS ; i++) {
  452.         if ((id = profOrder[i]) == 0xff) {
  453.         continue ;
  454.     }
  455.     sprintf(key, "HOST%02d", id) ;
  456.     len = sizeof(HOSTREC) ;
  457.     stat = PrfQueryProfileData(hini,
  458.                 ProgramName, key, &profHosts[id], &len) ;
  459.         if (stat != TRUE || len != sizeof(HOSTREC)) {
  460.             profOrder[i] = 0xff ;
  461.     }
  462.     }
  463.     
  464.     /*
  465.      * select new entry
  466.      */
  467.     
  468.     if ((entry = saveParam()) < 0) {
  469.         PrfCloseProfile(hini) ;
  470.         return FALSE ;
  471.     }
  472.     
  473.     /*
  474.      * save new order and host data
  475.      */
  476.      
  477.     sprintf(key, "HOST%02d", entry) ;
  478.     PrfWriteProfileData(hini, ProgramName,
  479.                 "ORDER", profOrder, sizeof(profOrder)) ;
  480.     PrfWriteProfileData(hini, ProgramName,
  481.                 key, &profHosts[entry], sizeof(HOSTREC)) ;
  482.  
  483.     PrfCloseProfile(hini) ;
  484.  
  485.     TRACE("saveProfile ... saved to %d\n", entry) ;
  486.  
  487.     return TRUE ;
  488. }
  489.  
  490. /*
  491.  * set/get Button State
  492.  */
  493.  
  494. static  void    setButton(HWND hwndDlg, USHORT id, BOOL state)
  495. {
  496.     HWND    hwnd = WinWindowFromID(hwndDlg, id) ;
  497.  
  498.     WinSendMsg(hwnd, BM_SETCHECK, MPFROMSHORT(state), NULL) ;
  499. }
  500.  
  501. static  BOOL    getButton(HWND hwndDlg, USHORT id)
  502. {
  503.     HWND    hwnd = WinWindowFromID(hwndDlg, id) ;
  504.     BOOL    state ;
  505.  
  506.     state = (BOOL) WinSendMsg(hwnd, BM_QUERYCHECK, NULL, NULL) ;
  507.     return state ;
  508. }
  509.  
  510. /*
  511.  * set/get Pixel Format
  512.  */
  513.  
  514. typedef struct _FORMAT {
  515.     PUCHAR  str ;
  516.     SHORT   fmt ;
  517. } FMTREC, *FMTPTR ;
  518.  
  519. static  FMTREC  tabFormat[] = {
  520.     { "True Color", PIXFMT_32   } ,
  521.     { "BGR233",     PIXFMT_8    } ,
  522.     { "Tiny Color", PIXFMT_TINY } ,
  523.     { "Gray Scale", PIXFMT_GRAY } ,
  524.     { NULL,     0         }
  525. } ;
  526.  
  527. static  void    setFormat(HWND hwndDlg)
  528. {
  529.     HWND    hwnd = WinWindowFromID(hwndDlg, IDD_OPT_FORMAT) ;
  530.     FMTPTR  p ;
  531.     
  532.     for (p = tabFormat ; p->str != NULL ; p++) {
  533.         WinSendMsg(hwnd, LM_INSERTITEM,
  534.         MPFROM2SHORT(LIT_END, 0), MPFROMP(p->str)) ;
  535.     }
  536.     for (p = tabFormat ; p->str != NULL ; p++) {
  537.         if (p->fmt == SessPixelFormat) {
  538.         WinSetWindowText(hwnd, p->str) ;
  539.         return ;
  540.     }
  541.     }
  542.     WinSetWindowText(hwnd, tabFormat[0].str) ;
  543. }
  544.  
  545. static  void    getFormat(HWND hwndDlg)
  546. {
  547.     HWND    hwnd = WinWindowFromID(hwndDlg, IDD_OPT_FORMAT) ;
  548.     UCHAR   name[64] ;
  549.     FMTPTR  p ;
  550.  
  551.     WinQueryWindowText(hwnd, 64, name) ;
  552.  
  553.     for (p = tabFormat ; p->str != NULL ; p++) {
  554.         if (strcmp(name, p->str) == 0) {
  555.         SessPixelFormat = p->fmt ;
  556.         return ;
  557.     }
  558.     }
  559. }
  560.  
  561. /*
  562.  * set/get Preferred Encoding
  563.  */
  564.  
  565. typedef struct _ENCODE {
  566.     PUCHAR  str ;
  567.     CARD32  enc ;
  568. } ENCREC, *ENCPTR ;
  569.  
  570. static  ENCREC  tabEncode[] = {
  571.     { "Hextile", rfbEncodingHextile } ,
  572.     { "RRE",     rfbEncodingRRE     } ,
  573.     { "CoRRE",   rfbEncodingCoRRE   } ,
  574.     { "Raw",     rfbEncodingRaw     } ,
  575.     { NULL,      0                  }
  576. } ;
  577.  
  578. static  void    setEncode(HWND hwndDlg)
  579. {
  580.     HWND    hwnd = WinWindowFromID(hwndDlg, IDD_OPT_ENCODE) ;
  581.     ENCPTR  p ;
  582.     
  583.     for (p = tabEncode ; p->str != NULL ; p++) {
  584.         WinSendMsg(hwnd, LM_INSERTITEM,
  585.         MPFROM2SHORT(LIT_END, 0), MPFROMP(p->str)) ;
  586.     }
  587.     for (p = tabEncode ; p->str != NULL ; p++) {
  588.         if (p->enc == SessPreferredEncoding) {
  589.         WinSetWindowText(hwnd, p->str) ;
  590.         return ;
  591.     }
  592.     }
  593.     WinSetWindowText(hwnd, tabEncode[0].str) ;
  594. }
  595.  
  596. static  void    getEncode(HWND hwndDlg)
  597. {
  598.     HWND    hwnd = WinWindowFromID(hwndDlg, IDD_OPT_ENCODE) ;
  599.     UCHAR   name[64] ;
  600.     ENCPTR  p ;
  601.  
  602.     WinQueryWindowText(hwnd, 64, name) ;
  603.  
  604.     for (p = tabEncode ; p->str != NULL ; p++) {
  605.         if (strcmp(name, p->str) == 0) {
  606.         SessPreferredEncoding = p->enc ;
  607.         return ;
  608.     }
  609.     }
  610. }
  611.  
  612. /*
  613.  * set/get Session Options
  614.  */
  615.  
  616. static  BOOL    initialSetup ;
  617.  
  618. static  void    setOptions(HWND hwndDlg)
  619. {
  620.     UCHAR   title[256] ;
  621.  
  622.     sprintf(title, "Session Options for <%s>", SessServerName) ;
  623.     WinSetWindowText(hwndDlg, title) ;
  624.     
  625.     setFormat(hwndDlg) ;
  626.     setEncode(hwndDlg) ;
  627.     
  628.     setButton(hwndDlg, IDD_OPT_SHARED, SessOptShared)    ;
  629.     setButton(hwndDlg, IDD_OPT_VONLY,  SessOptViewonly)  ;
  630.     setButton(hwndDlg, IDD_OPT_DEICON, SessOptDeiconify) ;
  631.  
  632.     if (! initialSetup) {
  633.         WinEnableWindow(WinWindowFromID(hwndDlg, IDD_OPT_FORMAT), FALSE) ;
  634.         WinEnableWindow(WinWindowFromID(hwndDlg, IDD_OPT_SHARED), FALSE) ;
  635.     }
  636. }
  637.  
  638. static  BOOL    getOptions(HWND hwndDlg)
  639. {
  640.     getFormat(hwndDlg) ;
  641.     getEncode(hwndDlg) ;
  642.  
  643.     SessOptShared    = getButton(hwndDlg, IDD_OPT_SHARED) ;    
  644.     SessOptViewonly  = getButton(hwndDlg, IDD_OPT_VONLY) ;
  645.     SessOptDeiconify = getButton(hwndDlg, IDD_OPT_DEICON) ;
  646.     
  647.     return TRUE ;
  648. }
  649.  
  650. /*
  651.  * procOpts - dialog proc. for Session Options
  652.  */
  653.  
  654. static MRESULT EXPENTRY procOpts(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  655. {
  656.     ULONG   ret ;
  657.  
  658.     switch (msg) {
  659.     
  660.     case WM_INITDLG :
  661.         if (SessDlgCenter) {
  662.         dialogAtCenter(hwnd) ;
  663.     } else {
  664.             dialogAtMouse(hwnd, DID_OK) ;
  665.         }
  666.     setOptions(hwnd)   ;
  667.     return (MRESULT) 0 ;
  668.  
  669.     case WM_COMMAND :
  670.         switch (ret = SHORT1FROMMP(mp1)) {
  671.         case DID_OK :
  672.         case DID_CANCEL :
  673.         if (getOptions(hwnd) != TRUE) {
  674.             return (MRESULT) 0 ;
  675.         }
  676.         saveParam() ;
  677.         WinDismissDlg(hwnd, ret) ;
  678.         return (MRESULT) 0 ;
  679.         default :
  680.         return (MRESULT) 0 ;
  681.     }
  682.     }
  683.     return WinDefDlgProc(hwnd, msg, mp1, mp2) ;
  684. }
  685.  
  686. /*
  687.  * set/getServer - set/get Server Spec.
  688.  */
  689.  
  690. static  void    setServer(HWND hwndDlg)
  691. {
  692.     HAB     hab  = WinQueryAnchorBlock(hwndDlg) ;
  693.     HWND    hwnd = WinWindowFromID(hwndDlg, IDD_SHOST) ;
  694.     int     i, id ;
  695.     PUCHAR  first = NULL ;
  696.     UCHAR   server[128] ;
  697.     
  698.     WinSendMsg(hwnd, EM_SETTEXTLIMIT, MPFROMSHORT(128), NULL) ;
  699.     
  700.     /*
  701.      * fill-in host list
  702.      */
  703.      
  704.     for (i = 0 ; i< MAXHOSTS ; i++) {
  705.         if ((id = profOrder[i]) == 0xff) {
  706.         continue ;
  707.     }
  708.  
  709.     TRACE("setServer - %d : %s\n", id, profHosts[id].name) ;
  710.     
  711.     if (first == NULL) {
  712.         first = profHosts[id].name ;
  713.     }
  714.     WinSendMsg(hwnd, LM_INSERTITEM,
  715.         MPFROM2SHORT(LIT_END, 0), MPFROMP(profHosts[id].name)) ;
  716.     }
  717.     
  718.     /*
  719.      * set host name (current selection)
  720.      */
  721.      
  722.     if (argServer != NULL) {
  723.         strcpy(server, argServer) ;
  724.     } else if (first != NULL) {
  725.         strcpy(server, first) ;
  726.     } else {
  727.         strcpy(server, "") ;
  728.     }
  729.  
  730.     TRACE("setServer - host %s\n", server) ;
  731.     
  732.     WinSetWindowText(hwnd, server) ;
  733. }
  734.  
  735. static  BOOL    getServer(HWND hwndDlg)
  736. {
  737.     HAB     hab  = WinQueryAnchorBlock(hwndDlg) ;
  738.     HWND    hwnd = WinWindowFromID(hwndDlg, IDD_SHOST) ;
  739.     UCHAR   server[128] ;
  740.     
  741.     WinQueryWindowText(hwnd, 128, server) ;
  742.  
  743.     if (strlen(server) == 0) {
  744.         return FALSE ;
  745.     }
  746.     if (strchr(server, ':') == NULL) {
  747.         return FALSE ;
  748.     }
  749.     loadParam(server) ;
  750.     
  751.     return TRUE ;
  752. }
  753.  
  754. /*
  755.  * procSess - dialog proc. for Session Setup
  756.  */
  757.  
  758. static MRESULT EXPENTRY procSess(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  759. {
  760.     ULONG   ret ;
  761.  
  762.     switch (msg) {
  763.     
  764.     case WM_INITDLG :
  765.         if (SessDlgCenter) {
  766.         dialogAtCenter(hwnd) ;
  767.     } else {
  768.             dialogAtMouse(hwnd, DID_OK) ;
  769.         }
  770.     setServer(hwnd)    ;
  771.     return (MRESULT) 0 ;
  772.  
  773.     case WM_COMMAND :
  774.         switch (SHORT1FROMMP(mp1)) {
  775.         case DID_OK :
  776.         if (getServer(hwnd) != TRUE) {
  777.             return (MRESULT) 0 ;
  778.         }
  779.         WinDismissDlg(hwnd, DID_OK) ;
  780.         return (MRESULT) 0 ;
  781.         case DID_CANCEL :
  782.         WinDismissDlg(hwnd, DID_CANCEL) ;
  783.         return (MRESULT) 0 ;
  784.         case IDD_SOPTS :
  785.             getServer(hwnd) ;
  786.             ret = WinDlgBox(HWND_DESKTOP, hwndClient,
  787.                         procOpts, NULLHANDLE, IDD_OPTS_INI, NULL) ;
  788.         if (ret == DID_OK && getServer(hwnd) == TRUE) {
  789.                 WinDismissDlg(hwnd, DID_OK) ;
  790.         }
  791.         return (MRESULT) 0 ;
  792.         default :
  793.         return (MRESULT) 0 ;
  794.     }
  795.     }
  796.     return WinDefDlgProc(hwnd, msg, mp1, mp2) ;
  797. }
  798.  
  799. /*
  800.  * sessSetup - Session Setup, entry
  801.  */
  802.  
  803. BOOL    sessSetup(HAB hab)
  804. {
  805.     ULONG   ret ;
  806.     
  807.     initialSetup = TRUE ;
  808.     
  809.     loadProfile(hab) ;
  810.     
  811.     ret = WinDlgBox(HWND_DESKTOP, HWND_DESKTOP,
  812.                 procSess, NULLHANDLE, IDD_SESS, NULL) ;
  813.  
  814.     if (ret == DID_OK) {
  815.         saveProfile(hab) ;
  816.     }
  817.     return (ret == DID_OK) ? TRUE : FALSE ;
  818. }
  819.  
  820. /*
  821.  * sessModify - Change Session option during a session
  822.  */
  823.  
  824. BOOL    sessModify(HAB hab)
  825. {
  826.     ULONG   ret ;
  827.     CARD32  lastEnc ;
  828.  
  829.     initialSetup = FALSE ;
  830.     lastEnc = SessPreferredEncoding ;
  831.     
  832.     ret = WinDlgBox(HWND_DESKTOP, HWND_DESKTOP,
  833.                 procOpts, NULLHANDLE, IDD_OPTS_MOD, NULL) ;
  834.     if (ret != DID_OK) {
  835.         return FALSE ;
  836.     }
  837.  
  838.     if (lastEnc != SessPreferredEncoding) {
  839.         protoSendFmtEnc() ;
  840.     }
  841.     return TRUE ;
  842. }
  843.  
  844. /*
  845.  * sessSaveProfile - external entry to save current profile
  846.  */
  847.  
  848. BOOL    sessSaveProfile(HAB hab)
  849. {
  850.     return saveProfile(hab) ;
  851. }
  852.