home *** CD-ROM | disk | FTP | other *** search
/ PC World 2003 February / PCWorld_2003-02_cd.bin / Komunik / sambar / sambar53b3.exe / samples / source / WINMAIN.C < prev    next >
Encoding:
C/C++ Source or Header  |  2002-08-31  |  16.7 KB  |  735 lines

  1. /*
  2. ** WINMAIN
  3. **
  4. **      This is the main driver for the Windows driver of the Sambar
  5. **        Server. 
  6. **
  7. **        Confidential Property of Tod Sambar
  8. **        (c) Copyright Tod Sambar 1995-2001
  9. **        All rights reserved.
  10. **
  11. **
  12. ** Syntax:
  13. **
  14. **      server    [-bnst] [-c <configdir>]
  15. **
  16. **            -b        Start a browser and load the home page.
  17. **            -c        Path to the config directory for use.
  18. **            -n        Don't check for an existing server instance.
  19. **            -s        Show the GUI on startup.
  20. **            -t        Don't trace to GUI display when in icon tray 
  21. **                    (performance optimization).
  22. **
  23. **
  24. ** History:
  25. ** Chg#    Date    Description                                                Resp
  26. ** ----    -------    -------------------------------------------------------    ----
  27. **        9MAR97     Created                                                    sambar
  28. **        5NOV97     Simplified interface                                    sambar
  29. **        18FEB98    Added real-time log display.                            sambar
  30. */
  31.  
  32. #include    <windows.h>
  33. #include    <stdio.h>
  34. #include    <io.h>
  35. #include    <fcntl.h>
  36. #include    <sys/types.h>
  37. #include    <sys/stat.h>
  38. #include    <share.h>
  39. #include    <process.h>
  40. #include    <sambar.h>
  41. #include    <resource.h>
  42.  
  43. /*
  44. ** Local Defines
  45. */
  46. #define SERVER_ID         1001
  47. #define SERVER_MSG         WM_USER + 69
  48. #define NAME            "Sambar Server"
  49.  
  50. static int                LogCount = 0;
  51. static int                MainX = 20;
  52. static int                MainY = 135;
  53. static HWND                MainWindow = NULL;
  54. static HWND                MainList = NULL;
  55. static HWND                PauseButton = NULL;
  56. static HWND                ClearButton = NULL;
  57. static HWND                ConnStats = NULL;
  58. static HWND                HConnStats = NULL;
  59. static HWND                ThreadStats = NULL;
  60. static HINSTANCE        MainInstance;
  61. static BOOL                DebugStatus = FALSE;
  62. static BOOL                ShellTray = FALSE;
  63. static BOOL                Showing = FALSE;
  64. static BOOL                Paused = FALSE;
  65. static BOOL                AlwaysTrace = TRUE;
  66. static BOOL                StartBrowser = FALSE;
  67. static BOOL                CheckExisting = TRUE;
  68. static char                ConfigDir[256];
  69. static NOTIFYICONDATA    IconData;
  70.  
  71.  
  72. /*
  73. ** Local Prototypes
  74. */
  75. long __stdcall         WndProc(
  76.                     HWND         hWnd, 
  77.                     UINT         message, 
  78.                     WPARAM         wParam,
  79.                     LPARAM         lParam
  80.                     );
  81. void                WndShutdown(
  82.                     void
  83.                     );
  84. void                DisplayMenu(
  85.                     HWND         hWnd
  86.                     );
  87. void                RestartServer(
  88.                     HWND         hWnd
  89.                     );
  90. void                ShutdownServer(
  91.                     HWND         hWnd
  92.                     );
  93. void                 StatusPopup(
  94.                     SA_CTX         *ctx,
  95.                     char         *msg
  96.                     );
  97. BOOL                 DisplayLoglines(
  98.                     HWND         hWnd
  99.                     );
  100. void                 HTTPLog(
  101.                     SA_CTX         *ctx,
  102.                     SA_HTTPLOG    *httplog
  103.                     );
  104. void                 GetArgs(
  105.                     LPSTR         cmdline,
  106.                     SA_INIT        *sainit
  107.                     );
  108.  
  109. int     __stdcall
  110. WinMain(HINSTANCE Instance, HINSTANCE PrevInstance, LPSTR CmdLine, int CmdShow)
  111. {
  112.     unsigned long    thread;
  113.     SA_BOOL            ver3;
  114.     SA_BOOL            stopped;
  115.     SA_INT            count;
  116.     SA_INT            maxcount;
  117.     SA_CTX            *ctx;
  118.     DWORD            dwVersion;        // To hold return value from GetVersion
  119.     MSG                message;
  120.     HWND            hWnd;
  121.     WNDCLASS        MainClass;
  122.     HICON            ServerIcon;
  123.     SA_INT            len;
  124.     SA_INT            port;
  125.     char            tmp[256];
  126.     char            name[256];
  127.     char            homedir[1024];
  128.     char            buffer[2048];
  129.     SA_INIT            sainit;
  130.  
  131.     /* Initialization                                                    */
  132.     memset(&sainit, 0, sizeof(SA_INIT));
  133.  
  134.     /* Save the application Instance                                    */
  135.     MainInstance = Instance;
  136.  
  137.     /* Process any command line arguments.                                */
  138.     GetArgs(CmdLine, &sainit);
  139.  
  140.     /* If a Server is running, show it                                    */
  141.     if (CheckExisting)
  142.     {
  143.         hWnd = FindWindow(NAME, NULL);
  144.         if (hWnd)
  145.         {
  146.             if (IsIconic(hWnd))
  147.                 ShowWindow(hWnd, SW_RESTORE);
  148.  
  149.             SetForegroundWindow(hWnd);
  150.             return (0);
  151.         } 
  152.     }
  153.  
  154. #if (_WIN32_WINNT >= 0x400)
  155.     CoInitializeEx(NULL, COINIT_MULTITHREADED);
  156. #endif
  157.  
  158.     SetErrorMode(SEM_FAILCRITICALERRORS |
  159.                  SEM_NOGPFAULTERRORBOX |
  160.                  SEM_NOOPENFILEERRORBOX);
  161.  
  162.     /* Create the tray Icon resource                                    */
  163.     ServerIcon = LoadIcon(Instance, "SERVER_ICON");
  164.  
  165.     /* Create a window class                                            */
  166.     MainClass.style =             CS_HREDRAW | CS_VREDRAW;
  167.     MainClass.lpfnWndProc =        WndProc;
  168.     MainClass.cbClsExtra =         0;
  169.     MainClass.cbWndExtra =         0;
  170.     MainClass.hInstance =         Instance;
  171.     MainClass.hIcon =             ServerIcon;
  172.     MainClass.hCursor =         LoadCursor(NULL, IDC_ARROW);
  173.     MainClass.hbrBackground =     GetStockObject(LTGRAY_BRUSH);
  174.     MainClass.lpszMenuName =     NULL;
  175.     MainClass.lpszClassName =     NAME;
  176.  
  177.     if (!RegisterClass(&MainClass))
  178.         return (0);
  179.  
  180.     /* Determine if this is windows 3.51 -- change the window type        */
  181.     ver3 = 0;
  182.     dwVersion = GetVersion();
  183.     if (dwVersion < 0x80000000) 
  184.     {
  185.         if ((DWORD)(LOBYTE(LOWORD(dwVersion))) == 3)
  186.             ver3 = 1;
  187.     }
  188.  
  189.     /*
  190.     ** Start the Sambar Server.
  191.     ** On failure, the server will shutdown and destroy the MainWindow.
  192.     */
  193.     sainit.i_hWnd = (SA_VOID *)&MainWindow;
  194.     sainit.i_build = 1;
  195.  
  196.     maxcount = 30;
  197.     if (DebugStatus)
  198.     {
  199.         sainit.i_statusfunc = StatusPopup;
  200.         maxcount = 200;
  201.     }
  202.  
  203.     thread = _beginthread(sa_server2, 0, (SA_VOID *)&sainit);
  204.     if (thread == -1)
  205.         return (0);
  206.  
  207.     /*
  208.     ** Wait for the server context to start up...
  209.     */
  210.     count = 0;
  211.     stopped = FALSE;
  212.     ctx = (SA_CTX *)NULL;
  213.     while ((!stopped) && (count < maxcount) && (ctx == (SA_CTX *)NULL))
  214.     {
  215.         if (sa_ctx_global(&ctx) != SA_SUCCEED)
  216.         {
  217.             Sleep(2000);
  218.  
  219.             /* Determine if the server has prematurely shut down        */
  220.             stopped = sa_stopped();
  221.         }
  222.  
  223.         count++;
  224.     }
  225.  
  226.     if (ctx == (SA_CTX *)NULL)
  227.     {
  228.         MessageBox(NULL, "Failure initializing server, see server.log", 
  229.             NAME, MB_OK | MB_ICONSTOP );
  230.         return (0);
  231.     }
  232.  
  233.     /* Create the main window                                            */
  234.     MainWindow = CreateWindowEx(WS_EX_OVERLAPPEDWINDOW, NAME, NAME, 
  235.         (WS_THICKFRAME | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX),
  236.         CW_USEDEFAULT, 0, 600, 470, NULL, NULL, Instance, NULL);
  237.  
  238.     if (!MainWindow)
  239.     {
  240.         (SA_VOID)sa_shutdown(0);
  241.         return (0);
  242.     }
  243.  
  244.     /*
  245.     ** Display the Sambar Server machine/port
  246.     */
  247.     name[0] = '\0';
  248.     (SA_VOID)sa_ctx_props(ctx, SA_GET, SA_CTXPROP_SERVERSW, 
  249.         (SA_BYTE *)name, 255, &len);
  250.     hWnd = CreateWindow("STATIC", "Version", WS_CHILD | WS_VISIBLE, 
  251.         20, 15, 300, 20, MainWindow, NULL, Instance, NULL);
  252.     SetWindowText(hWnd, name);
  253.  
  254.     (SA_VOID)sa_ctx_props(ctx, SA_GET, SA_CTXPROP_BUILDID, 
  255.         (SA_BYTE *)tmp, 255, &len);
  256.     wsprintf(buffer, "Build: %s", tmp);
  257.     hWnd = CreateWindow("STATIC", "Build", WS_CHILD | WS_VISIBLE, 
  258.         350, 15, 300, 20, MainWindow, NULL, Instance, NULL);
  259.     SetWindowText(hWnd, buffer);
  260.  
  261.     /* Setup the "real-time" statistics windows...                        */
  262.     ThreadStats = CreateWindow("STATIC", "Threads", WS_CHILD | WS_VISIBLE, 
  263.         350, 40, 300, 20, MainWindow, NULL, Instance, NULL);
  264.     SetWindowText(ThreadStats, "Server Threads: 0");
  265.  
  266.     HConnStats = CreateWindow("STATIC", "HConnections", WS_CHILD | WS_VISIBLE, 
  267.         350, 60, 300, 20, MainWindow, NULL, Instance, NULL);
  268.     SetWindowText(HConnStats, "HTTP Connections: 0");
  269.  
  270.     ConnStats = CreateWindow("STATIC", "Connections", WS_CHILD | WS_VISIBLE, 
  271.         350, 80, 300, 20, MainWindow, NULL, Instance, NULL);
  272.     SetWindowText(ConnStats, "Network Connections: 0");
  273.  
  274.     name[0] = '\0';
  275.     (SA_VOID)sa_ctx_props(ctx, SA_GET, SA_CTXPROP_SERVERNAME, 
  276.         (SA_BYTE *)name, 255, &len);
  277.     tmp[0] = '\0';
  278.     (SA_VOID)sa_ctx_props(ctx, SA_GET, SA_CTXPROP_SERVERIP, 
  279.         (SA_BYTE *)tmp, 64, &len);
  280.     (SA_VOID)sa_ctx_props(ctx, SA_GET, SA_CTXPROP_SERVERPORT, 
  281.         (SA_BYTE *)&port, sizeof(SA_INT), &len);
  282.     homedir[0] = '\0';
  283.     (SA_VOID)sa_ctx_props(ctx, SA_GET, SA_CTXPROP_HOMEDIR, 
  284.         (SA_BYTE *)homedir, 1024, &len);
  285.  
  286.     hWnd = CreateWindow("STATIC", "Server", WS_CHILD | WS_VISIBLE, 
  287.         20, 40, 300, 20, MainWindow, NULL, Instance, NULL);
  288.     wsprintf(buffer, "Sambar Server  '%s:%d'", name, port);
  289.     SetWindowText(hWnd, buffer);
  290.  
  291.     hWnd = CreateWindow("STATIC", "ipaddress", WS_CHILD | WS_VISIBLE, 
  292.         20, 60, 300, 20, MainWindow, NULL, Instance, NULL);
  293.     wsprintf(buffer, "IP Address: %s", tmp);
  294.     SetWindowText(hWnd, buffer);
  295.  
  296.     hWnd = CreateWindow("STATIC", "homedir", WS_CHILD | WS_VISIBLE, 
  297.         20, 80, 300, 20, MainWindow, NULL, Instance, NULL);
  298.     wsprintf(buffer, "Server Dir: %s", homedir);
  299.     SetWindowText(hWnd, buffer);
  300.  
  301.     /*
  302.     ** Put the buttons in.
  303.     */
  304.     ClearButton = CreateWindow("BUTTON", "Clear", WS_CHILD | WS_VISIBLE, 
  305.         MainX, MainY - 30, 50, 25, MainWindow, NULL, Instance, NULL);
  306.     SetWindowText(ClearButton, "Clear");
  307.     if (!ClearButton)
  308.     {
  309.         MessageBox(NULL, "Failure creating clear button.", 
  310.             NAME, MB_OK | MB_ICONSTOP );
  311.         (SA_VOID)sa_shutdown(0);
  312.         return (0);
  313.     }
  314.  
  315.     PauseButton = CreateWindow("BUTTON", "Pause", WS_CHILD | WS_VISIBLE, 
  316.         MainX + 85, MainY - 30, 90, 25, MainWindow, NULL, Instance, NULL);
  317.     SetWindowText(PauseButton, "Pause");
  318.     if (!PauseButton)
  319.     {
  320.         MessageBox(NULL, "Failure creating pause button.", 
  321.             NAME, MB_OK | MB_ICONSTOP );
  322.         (SA_VOID)sa_shutdown(0);
  323.         return (0);
  324.     }
  325.  
  326.     /* Create a list box for the log display                            */
  327.     MainList = CreateWindow("LISTBOX", NULL, 
  328.                     WS_CHILD|WS_BORDER|WS_VISIBLE|WS_VSCROLL|WS_HSCROLL, 
  329.                     MainX, MainY, 550, 240, MainWindow, (HMENU)1000, 
  330.                     Instance, NULL);
  331.  
  332.     if (!MainList)
  333.     {
  334.         MessageBox(NULL, "Failure creating list box.", 
  335.             NAME, MB_OK | MB_ICONSTOP );
  336.         (SA_VOID)sa_shutdown(0);
  337.         return (0);
  338.     }
  339.  
  340.     SendMessage(MainList, LB_SETHORIZONTALEXTENT, 2048, 0L);
  341.  
  342.     /* Add tray icon to system tray                                        */
  343.     IconData.cbSize             = sizeof(NOTIFYICONDATA);
  344.     IconData.hWnd                 = MainWindow;
  345.     IconData.uID                 = SERVER_ID;
  346.     IconData.uFlags             = NIF_MESSAGE | NIF_ICON | NIF_TIP;
  347.     IconData.uCallbackMessage    = SERVER_MSG;
  348.     IconData.hIcon                = ServerIcon;
  349.     strcpy(IconData.szTip, "Sambar Server is Active");
  350.  
  351.     /* Win95 and NT4.0 only                                                */
  352.     if (!Shell_NotifyIcon(NIM_ADD, &IconData))
  353.     {
  354.         ShowWindow(MainWindow, CmdShow);
  355.         UpdateWindow(MainWindow);
  356.     }
  357.     else
  358.     {
  359.         ShellTray = TRUE;
  360.         ShowWindow(MainWindow, Showing ? SW_SHOW : SW_HIDE);
  361.     }
  362.  
  363.     /* Register the HTTP Log callback.                                    */
  364.     (SA_VOID)sa_ctx_props(ctx, SA_SET, SA_CTXPROP_HTTPLOGFUNC, 
  365.         (SA_BYTE *)HTTPLog, sizeof(SA_VOID *), (SA_INT *)NULL);
  366.  
  367.     /* Start the Web Browser to the home page                             */
  368.     if (StartBrowser)
  369.     {
  370.         if (port != 80)
  371.             wsprintf(buffer, "http://localhost:%d/", port);
  372.         else
  373.             strcpy(buffer, "http://localhost/");
  374.  
  375.         ShellExecute(GetTopWindow(NULL), "open", buffer, NULL, NULL, 
  376.             SW_SHOWNORMAL);
  377.     }
  378.  
  379.     atexit(WndShutdown);
  380.  
  381.     /* Message loop                                                        */
  382.     while (GetMessage(&message, NULL, 0, 0))
  383.     {
  384.         TranslateMessage(&message);
  385.         DispatchMessage(&message);
  386.     }
  387.  
  388.     /* Shutdown the Sambar Server                                        */
  389.     (SA_VOID)sa_shutdown(0);
  390.  
  391.     Shell_NotifyIcon(NIM_DELETE, &IconData);
  392.     UnregisterClass(NAME, Instance);
  393.  
  394. #if (_WIN32_WINNT >= 0x400)
  395.     CoUninitialize();
  396. #endif
  397.  
  398.     return (message.wParam);
  399. }
  400.  
  401. void WndShutdown()
  402. {
  403.     Shell_NotifyIcon(NIM_DELETE, &IconData);
  404. }
  405.  
  406. long __stdcall 
  407. WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  408. {
  409.     int    hi;
  410.     int    lo;
  411.     RECT    rect;
  412.  
  413.     switch (message) 
  414.     {
  415.     case SERVER_MSG:
  416.         if ((wParam == SERVER_ID) && (lParam == WM_RBUTTONDOWN))
  417.         {
  418.             DisplayMenu(hWnd);
  419.         }
  420.         else if ((wParam == SERVER_ID) && (lParam == WM_LBUTTONDBLCLK))
  421.         {
  422.             Showing = TRUE;
  423.             ShowWindow(hWnd, SW_SHOW);
  424.         }
  425.         break;
  426.  
  427.     case WM_CLOSE:
  428.         if (ShellTray)
  429.         {
  430.             ShowWindow(MainWindow, SW_HIDE);
  431.             Showing = FALSE;
  432.         }
  433.         else
  434.         {
  435.             return DefWindowProc(hWnd, message, wParam, lParam);
  436.         }
  437.         break;
  438.  
  439.     case WM_COMMAND:
  440.         if ((HWND)lParam == PauseButton)
  441.         {
  442.             if (Paused)
  443.             {
  444.                 Paused = FALSE;
  445.                 sa_pause(TRUE);
  446.                 SetWindowText(PauseButton, "Pause");
  447.             }
  448.             else
  449.             {
  450.                 Paused = TRUE;
  451.                 sa_pause(FALSE);
  452.                 SetWindowText(PauseButton, "Un-Pause");
  453.             }
  454.         }
  455.         else if ((HWND)lParam == ClearButton)
  456.         {
  457.             /* Clear the list box                                        */
  458.             LogCount = 1;
  459.             SendMessage(MainList, LB_RESETCONTENT, 0, 0);
  460.         }
  461.         else
  462.         {
  463.             /* Unhandled message                                        */
  464.             return DefWindowProc(hWnd, message, wParam, lParam);
  465.         }
  466.         break;
  467.  
  468.     case WM_SIZE:
  469.         hi = HIWORD(lParam);
  470.         lo = LOWORD(lParam);
  471.         GetClientRect(MainList, &rect);
  472.         if ((LOWORD(lParam) - 40 == rect.right) &&
  473.             (HIWORD(lParam) - 140 == rect.bottom))
  474.         {
  475.             return 0;
  476.         }
  477.  
  478.         /* Adjust the log box's window                                    */
  479.         MoveWindow(MainList, MainX, MainY, LOWORD(lParam) - 40, 
  480.             HIWORD(lParam) - 140, TRUE);
  481.         break;
  482.  
  483.     case WM_QUERYENDSESSION:
  484.         return((long)TRUE);
  485.  
  486.     case WM_ENDSESSION:
  487.         if (wParam)
  488.         {
  489.             (SA_VOID)sa_shutdown(0);
  490.             PostQuitMessage(0);
  491.         }
  492.         break;
  493.  
  494.     case WM_DESTROY:
  495.         /* Shutdown the main window                                        */
  496.         PostQuitMessage(0);
  497.         break;
  498.  
  499.     default:
  500.         /* Unhandled Messages end up here (DefWindowProc)                */
  501.         return DefWindowProc(hWnd, message, wParam, lParam);
  502.     }
  503.  
  504.     return(0);
  505. }
  506.  
  507. void
  508. DisplayMenu(HWND hWnd)
  509. {
  510.     HMENU     MenuHnd;
  511.     POINT     MousePos;
  512.     int     ScreenWidth;
  513.     int     ScreenHeight;
  514.     int     SelItem;
  515.  
  516.     MenuHnd = CreatePopupMenu();
  517.     AppendMenu(MenuHnd, MF_ENABLED, 1, "Open");
  518.     AppendMenu(MenuHnd, MF_SEPARATOR, 0, NULL);
  519.     AppendMenu(MenuHnd, MF_ENABLED, 2, "Restart");
  520.     AppendMenu(MenuHnd, MF_ENABLED, 3, "Shutdown");
  521.  
  522.     //Get Mouse Pos
  523.     GetCursorPos(&MousePos);
  524.  
  525.     //Get Screen Metrics
  526.     ScreenWidth = GetSystemMetrics(SM_CXSCREEN);
  527.     ScreenHeight = GetSystemMetrics(SM_CYSCREEN);
  528.  
  529.     SetForegroundWindow(MainWindow);
  530.  
  531.     //Handle the different possible task bar locations
  532.     if ((MousePos.x >= (ScreenWidth / 2)) && (MousePos.y >= (ScreenHeight / 2)))
  533.     {
  534.         //Bottom or Right
  535.         SelItem = TrackPopupMenu(MenuHnd,
  536.             TPM_BOTTOMALIGN | TPM_RIGHTALIGN | TPM_RETURNCMD | TPM_LEFTBUTTON,
  537.             MousePos.x, ScreenHeight, 0, MainWindow, NULL);
  538.     }
  539.     else if (MousePos.y < (ScreenHeight / 2)) 
  540.     {
  541.         //Top
  542.         SelItem = TrackPopupMenu(MenuHnd,
  543.             TPM_TOPALIGN | TPM_RIGHTALIGN | TPM_RETURNCMD | TPM_LEFTBUTTON,
  544.             MousePos.x, MousePos.y, 0, MainWindow, NULL);
  545.     }
  546.     else 
  547.     {
  548.         //Left
  549.         SelItem = TrackPopupMenu(MenuHnd,
  550.             TPM_BOTTOMALIGN | TPM_LEFTALIGN | TPM_RETURNCMD | TPM_LEFTBUTTON,
  551.             MousePos.x, ScreenHeight, 0, MainWindow, NULL);
  552.     }
  553.  
  554.     SetForegroundWindow(MainWindow);
  555.     DestroyMenu(MenuHnd);
  556.  
  557.     switch (SelItem)
  558.     {
  559.     case 1:
  560.         Showing = TRUE;
  561.         ShowWindow(MainWindow, SW_SHOW);
  562.         break;
  563.     case 2:
  564.         RestartServer(MainWindow);
  565.         break;
  566.     case 3:
  567.         ShutdownServer(MainWindow);
  568.         break;
  569.     default:
  570.         break;
  571.     }
  572. }
  573.  
  574. void
  575. ShutdownServer(HWND MainWindow)
  576. {
  577.     int Answer;
  578.  
  579.     Answer = MessageBox(MainWindow, 
  580.                 "Are you sure you want to shutdown the Sambar Server?",
  581.                 NAME, MB_YESNO | MB_ICONQUESTION);
  582.  
  583.     // If they do destroy the main window and let the the rest fall in place...
  584.     if (Answer == IDYES)
  585.         DestroyWindow(MainWindow);
  586. }
  587.  
  588. void
  589. RestartServer(HWND MainWindow)
  590. {
  591.     int Answer;
  592.  
  593.     Answer = MessageBox(MainWindow, 
  594.                 "Are you sure you want to restart the Sambar Server?",
  595.                 NAME, MB_YESNO | MB_ICONQUESTION);
  596.  
  597.     // If they do destroy the main window and let the the rest fall in place...
  598.     if (Answer == IDYES)
  599.         sa_shutdown(1);
  600. }
  601.  
  602. void
  603. StatusPopup(SA_CTX *ctx, char *msg)
  604. {
  605.     (void)MessageBox(MainWindow, msg, NAME, MB_OK | MB_ICONSTOP );
  606. }
  607.  
  608.  
  609. void
  610. HTTPLog(SA_CTX *ctx, SA_HTTPLOG    *httplog)
  611. {
  612.     int        i;
  613.     int        n;
  614.     int        len;
  615.     char    timestr[32];
  616.     char    str[2048];
  617.  
  618.     if (!MainList)
  619.         return;
  620.  
  621.     if ((!Showing) && (!AlwaysTrace))
  622.         return;
  623.  
  624.     LogCount++;
  625.     if (LogCount > 200)
  626.     {
  627.         LogCount = 1;
  628.         SendMessage(MainList, LB_RESETCONTENT, 0, 0);
  629.     }
  630.  
  631.     i = 0;
  632.     while ((httplog->timestamp[i] != '\0') && (httplog->timestamp[i] != ':'))
  633.         i++;
  634.  
  635.     n = 0;
  636.     while ((httplog->timestamp[i] != '\0') && 
  637.         (httplog->timestamp[i] != ' ') &&
  638.         (n < 16))
  639.     {
  640.         timestr[n] = httplog->timestamp[i];
  641.         n++;
  642.         i++;
  643.     }
  644.  
  645.     timestr[0] = '[';
  646.     timestr[n] = ']';
  647.     timestr[n+1] = '\0';
  648.  
  649.     len = strlen(httplog->request);
  650.     if (len > 1024)
  651.         return;
  652.  
  653.     sprintf(str, "[%s]  %s  %s  %ld  %s  %s    %ld", 
  654.         httplog->vhost, timestr, httplog->user, httplog->status, 
  655.         httplog->method, httplog->request, httplog->size);
  656.     SendMessage(MainList, LB_ADDSTRING, 0, (LPARAM)(LPSTR)str);
  657.     
  658.     n = SendMessage(MainList, LB_GETCOUNT, 0, 0);
  659.     SendMessage(MainList, LB_SETCURSEL, (unsigned int)n - 1, 0);
  660.  
  661.     sprintf(str, "Server Threads: %ld", httplog->threads);
  662.     SetWindowText(ThreadStats, str);
  663.     sprintf(str, "HTTP Connections: %ld", httplog->httpconns);
  664.     SetWindowText(HConnStats, str);
  665.     sprintf(str, "Network Connections: %ld", httplog->allconns);
  666.     SetWindowText(ConnStats, str);
  667.             
  668.     return;
  669. }
  670.  
  671. void
  672. GetArgs(LPSTR CmdLine, SA_INIT *sainit)
  673. {
  674.     int        i;
  675.     char    *p;
  676.  
  677.     if (CmdLine == NULL)
  678.         return;
  679.  
  680.     p = CmdLine;
  681.     while (*p != '\0')
  682.     {
  683.         switch ((int)*p)
  684.         {
  685.         case 'd':
  686.         case 'D':
  687.             DebugStatus = TRUE;
  688.             break;
  689.         case 'b':
  690.         case 'B':
  691.             StartBrowser = TRUE;
  692.             break;
  693.         case 'n':
  694.         case 'N':
  695.             CheckExisting = FALSE;
  696.             break;
  697.         case 's':
  698.         case 'S':
  699.             Showing = TRUE;
  700.             break;
  701.         case 't':
  702.         case 'T':
  703.             AlwaysTrace = FALSE;
  704.             break;
  705.         case 'c':
  706.         case 'C':
  707.             p++;
  708.             while ((*p != '\0') && (isspace(*p)))
  709.                 p++;
  710.  
  711.             i = 0;
  712.             while ((i < 250) && (*p != '\0') && (!isspace(*p)))
  713.             {
  714.                 ConfigDir[i] = *p;
  715.                 p++;
  716.                 i++;
  717.             }
  718.  
  719.             if (i > 0)
  720.             {
  721.                 ConfigDir[i] = '\0';
  722.                 sainit->i_configdir = ConfigDir;
  723.             }
  724.             break;
  725.         case '-':
  726.         default:
  727.             break;
  728.         }
  729.  
  730.         p++;
  731.     }
  732.  
  733.     return;
  734. }
  735.