home *** CD-ROM | disk | FTP | other *** search
/ Chip: Windows 95 / WIN95_CD.ISO / sharewar / internet / alibaba / wcgitst.c_ / wcgitst.c
Encoding:
C/C++ Source or Header  |  1995-06-10  |  17.8 KB  |  402 lines

  1. /*****************************************************************************/
  2. /* wcgitst (c) Copyright 1995-1995 Michael Kofler                            */
  3. /*****************************************************************************/
  4. /* Win CGI Sample Program                                                    */
  5. /*****************************************************************************/
  6. #ifndef lint
  7. static char copyright[] =
  8. "@(#) Copyright (c) 1995 - 1995 Michael Kofler, Computer Software Manufaktur GmbH. Vienna.\n";
  9. #endif  /* not lint */
  10.  
  11.  
  12. /********************** Includes ****************************************/
  13. #include <windows.h>
  14. #include "winsock.h"
  15. #include <commdlg.h>
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <string.h>
  19. #include <malloc.h>
  20. #include <io.h>
  21. #include <fcntl.h>
  22. #include <sys/types.h>
  23. #include <sys/stat.h>
  24. #include <dos.h>
  25.  
  26. /* This must be included when using WINCGI.DLL  */
  27. #include "wincgi.h"
  28.  
  29. #define DO_WORK         WM_USER+1
  30.  
  31.  
  32. /********************** Globals *****************************************/
  33. char            szAppName[]="wcgitst";
  34. HMENU           hWndMainMenu;
  35. HANDLE          hInst;
  36. HDC             hdc;
  37. char            CGIFileName[WCGI_LONGSTR];
  38. char            ContentFileName[WCGI_LONGSTR];
  39. char            OutputFileName[WCGI_LONGSTR];
  40. char            Parameters[WCGI_MONSTERSTR];
  41.  
  42. long PASCAL WndProc(HWND, WORD, WORD, LONG);
  43.  
  44.  
  45. /************************************************************************/
  46. /* WinMain                                                              */
  47. /************************************************************************/
  48. int      PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance,
  49.                         LPSTR lpszCmdLine, int cmdShow)
  50. {
  51.         MSG             msg;
  52.         WNDCLASS        wndclass;
  53.         HWND            hwndmain;
  54.  
  55.         if (!hPrevInstance)
  56.         {
  57.                 /* Define the window class for this application.        */
  58.                 wndclass.style         = CS_HREDRAW;
  59.                 wndclass.lpfnWndProc   = WndProc;
  60.                 wndclass.cbClsExtra    = 0;
  61.                 wndclass.cbWndExtra    = 0;
  62.                 wndclass.hInstance     = hInstance;
  63.                 wndclass.hIcon         = LoadIcon(hInstance, szAppName);
  64.                 wndclass.hCursor       = LoadCursor(NULL, IDC_ARROW);
  65.                 wndclass.hbrBackground = GetStockObject(WHITE_BRUSH);
  66.                 wndclass.lpszMenuName  = NULL;
  67.                 wndclass.lpszClassName = szAppName;
  68.                 /* Register the class                                   */
  69.                 if (!RegisterClass(&wndclass))
  70.                 {
  71.                         return(FALSE);
  72.                 } /* endif */
  73.         }
  74.         else
  75.         {
  76.                 return(FALSE);
  77.         } /* endif */
  78.  
  79.  
  80.         CSM_ParseCmdLine(lpszCmdLine,CGIFileName,ContentFileName,OutputFileName,Parameters);
  81.  
  82.         hInst = hInstance;
  83.  
  84.         if ( (hwndmain = CreateWindow(szAppName,"WCGITST",
  85.                             WS_OVERLAPPEDWINDOW,
  86.                             CW_USEDEFAULT, CW_USEDEFAULT,
  87.                             CW_USEDEFAULT, CW_USEDEFAULT,
  88.                             NULL, NULL, hInstance, NULL)) == NULL)
  89.         {
  90.                 MessageBox(hwndmain,"Could not create Window",szAppName, MB_ICONEXCLAMATION | MB_OK);
  91.                 return(FALSE);
  92.         } /* endif */
  93.  
  94.  
  95.  
  96.         ShowWindow(hwndmain,SW_SHOWMINNOACTIVE);
  97.         UpdateWindow(hwndmain);
  98.  
  99.         while (GetMessage(&msg, NULL, 0, 0))
  100.         {
  101.                 TranslateMessage(&msg);
  102.                 DispatchMessage(&msg);
  103.         } /* endwhile */
  104.         return(msg.wParam);
  105. } /* end of WinMain */
  106.  
  107.  
  108.  
  109.  
  110.  
  111. /************************************************************************/
  112. /* WndProc - handles messages for this application                      */
  113. /*                                                                      */
  114. /* paramaters:                                                          */
  115. /*             hWnd          - The window handle for this message       */
  116. /*             message       - The message number                       */
  117. /*             wParam        - The WORD parameter for this message      */
  118. /*             lParam        - The LONG parameter for this message      */
  119. /*                                                                      */
  120. /* returns:                                                             */
  121. /*             depends on message.                                      */
  122. /*                                                                      */
  123. /************************************************************************/
  124. long FAR PASCAL WndProc(HWND hWnd, WORD message, WORD wParam, LONG lParam)
  125. {
  126.         HMENU            hMenu;
  127.         HICON            hIcon;
  128.         struct WinCGIEnv CGIPART;
  129.         struct ACCEPT    ACCEPT;
  130.         struct ExtraHeaders ExtraHeaders_1;
  131.         struct FormLiteral  FormLiteral;
  132.         struct FormExternal FormExternal;
  133.         struct FormHuge     FormHuge;
  134.         char hlp[4096];
  135.         int i;
  136.         int fh;
  137.  
  138.         switch (message)
  139.         {
  140.             case WM_CREATE:
  141.                 hInst = ((LPCREATESTRUCT) lParam)->hInstance;
  142.  
  143.  
  144.                 /* Usefull to do it like that                   */
  145.                 /* So the create is finished                    */
  146.                 SendMessage (hWnd, DO_WORK, 0, 0);
  147.                 return 0;
  148.                 break;
  149.  
  150.             case DO_WORK:
  151.                 /* Read the CGI Section of the INI File, and the ACCEPT Headers */
  152.                 CSM_ReadIniEntries(CGIFileName,&CGIPART,&ACCEPT);
  153.                 /* Now retrieve the Extra Headers, if there are any          */
  154.                 /* Be sure to call CSM_FreeExtraHeaders, at the end          */
  155.                 /* As the DLL is doing some mallocs for you                  */
  156.                 CSM_GetExtraHeaders(CGIFileName,&ExtraHeaders_1);
  157.  
  158.                 CSM_GetFormLiteral(CGIFileName,&FormLiteral);
  159.                 CSM_GetFormExternal(CGIFileName,&FormExternal);
  160.                 CSM_GetFormHuge(CGIFileName,&FormHuge);
  161.  
  162.                 fh = _open( OutputFileName, _O_RDWR | _O_CREAT | _O_BINARY |_O_APPEND, _S_IREAD | _S_IWRITE );
  163.                 wsprintf(hlp,"Content-type: text/html\r\n\r\n");
  164.                 write(fh,hlp,strlen(hlp));
  165.  
  166.                 wsprintf(hlp,"<HEAD><TITLE>WINCGI - Test</TITLE></HEAD>\r\n");
  167.                 write(fh,hlp,strlen(hlp));
  168.  
  169.                 wsprintf(hlp,"<H1>WINCGI Report</H1>\r\n");
  170.                 write(fh,hlp,strlen(hlp));
  171.  
  172.                 wsprintf(hlp,"<STRONG>Used Command :</STRONG> %s<P>\r\n",CGIPART.Request_Method);
  173.                 write(fh,hlp,strlen(hlp));
  174.  
  175.                 wsprintf(hlp,"<STRONG>Welcome to Alibaba - The WWW Server</STRONG>\r\n");
  176.                 write(fh,hlp,strlen(hlp));
  177.  
  178.                 wsprintf(hlp,"<H2>CGI Section</H2>\r\n");
  179.                 write(fh,hlp,strlen(hlp));
  180.  
  181.                 wsprintf(hlp,"<UL>\r\n");
  182.                 write(fh,hlp,strlen(hlp));
  183.  
  184.                 wsprintf(hlp,"<LI><STRONG>Request Protocol :</STRONG> %s\r\n",CGIPART.Request_Protocol);
  185.                 write(fh,hlp,strlen(hlp));
  186.                 wsprintf(hlp,"<LI><STRONG>Executable Path :</STRONG> %s\r\n",CGIPART.Executable_Path);
  187.                 write(fh,hlp,strlen(hlp));
  188.                 wsprintf(hlp,"<LI><STRONG>Logical Path :</STRONG> %s\r\n",CGIPART.Logical_Path);
  189.                 write(fh,hlp,strlen(hlp));
  190.                 wsprintf(hlp,"<LI><STRONG>Physical Path :</STRONG> %s\r\n",CGIPART.Physical_Path);
  191.                 write(fh,hlp,strlen(hlp));
  192.                 wsprintf(hlp,"<LI><STRONG>Query String :</STRONG> %s\r\n",CGIPART.Query_String);
  193.                 write(fh,hlp,strlen(hlp));
  194.                 wsprintf(hlp,"<LI><STRONG>Referer :</STRONG> %s\r\n",CGIPART.Referer);
  195.                 write(fh,hlp,strlen(hlp));
  196.                 wsprintf(hlp,"<LI><STRONG>From :</STRONG> %s\r\n",CGIPART.From);
  197.                 write(fh,hlp,strlen(hlp));
  198.                 wsprintf(hlp,"<LI><STRONG>Content Type :</STRONG> %s\r\n",CGIPART.Content_Type);
  199.                 write(fh,hlp,strlen(hlp));
  200.                 wsprintf(hlp,"<LI><STRONG>Content Length :</STRONG> %d\r\n",CGIPART.Content_Length);
  201.                 write(fh,hlp,strlen(hlp));
  202.                 wsprintf(hlp,"<LI><STRONG>Content File :</STRONG> %s\r\n",CGIPART.Content_File);
  203.                 write(fh,hlp,strlen(hlp));
  204.                 wsprintf(hlp,"<LI><STRONG>Server Software :</STRONG> %s\r\n",CGIPART.Server_Software);
  205.                 write(fh,hlp,strlen(hlp));
  206.                 wsprintf(hlp,"<LI><STRONG>Server Name :</STRONG> %s\r\n",CGIPART.Server_Name);
  207.                 write(fh,hlp,strlen(hlp));
  208.                 wsprintf(hlp,"<LI><STRONG>Server Port :</STRONG> %d\r\n",CGIPART.Server_Port);
  209.                 write(fh,hlp,strlen(hlp));
  210.                 wsprintf(hlp,"<LI><STRONG>Server Admin :</STRONG> %s\r\n",CGIPART.Server_Admin);
  211.                 write(fh,hlp,strlen(hlp));
  212.                 wsprintf(hlp,"<LI><STRONG>CGI Version :</STRONG> %s\r\n",CGIPART.CGI_Version);
  213.                 write(fh,hlp,strlen(hlp));
  214.                 wsprintf(hlp,"<LI><STRONG>Remote Host :</STRONG> %s\r\n",CGIPART.Remote_Host);
  215.                 write(fh,hlp,strlen(hlp));
  216.                 wsprintf(hlp,"<LI><STRONG>Remote Address :</STRONG> %s\r\n",CGIPART.Remote_Address);
  217.                 write(fh,hlp,strlen(hlp));
  218.                 wsprintf(hlp,"<LI><STRONG>Authentication Method :</STRONG> %s\r\n",CGIPART.Authentication_Method);
  219.                 write(fh,hlp,strlen(hlp));
  220.                 wsprintf(hlp,"<LI><STRONG>Authentication Realm :</STRONG> %s\r\n",CGIPART.Authentication_Realm);
  221.                 write(fh,hlp,strlen(hlp));
  222.                 wsprintf(hlp,"<LI><STRONG>Authenticated User :</STRONG> %s\r\n",CGIPART.Authenticated_Username);
  223.                 write(fh,hlp,strlen(hlp));
  224.                 wsprintf(hlp,"</UL>\r\n");
  225.                 write(fh,hlp,strlen(hlp));
  226.                 wsprintf(hlp,"<HR Size=4>\r\n");
  227.                 write(fh,hlp,strlen(hlp));
  228.  
  229.                 wsprintf(hlp,"<H2>System Section</H2>\r\n");
  230.                 write(fh,hlp,strlen(hlp));
  231.                 wsprintf(hlp,"<UL>\r\n");
  232.                 write(fh,hlp,strlen(hlp));
  233.                 wsprintf(hlp,"<LI><STRONG>GMT Offset :</STRONG> %d\r\n",CGIPART.GMT_Offset);
  234.                 write(fh,hlp,strlen(hlp));
  235.                 wsprintf(hlp,"<LI><STRONG>Debug Mode :</STRONG> %s\r\n",CGIPART.Debug_Mode);
  236.                 write(fh,hlp,strlen(hlp));
  237.                 wsprintf(hlp,"<LI><STRONG>Output File :</STRONG> %s\r\n",CGIPART.Output_File);
  238.                 write(fh,hlp,strlen(hlp));
  239.                 wsprintf(hlp,"<LI><STRONG>Content File :</STRONG> %s\r\n",CGIPART.Content_File);
  240.                 write(fh,hlp,strlen(hlp));
  241.  
  242.                 wsprintf(hlp,"</UL>\r\n");
  243.                 write(fh,hlp,strlen(hlp));
  244.                 wsprintf(hlp,"<HR Size=4>\r\n");
  245.                 write(fh,hlp,strlen(hlp));
  246.  
  247.  
  248.  
  249.                 wsprintf(hlp,"<H2>Accept Section</H2>\r\n");
  250.                 write(fh,hlp,strlen(hlp));
  251.                 wsprintf(hlp,"<UL>\r\n");
  252.                 write(fh,hlp,strlen(hlp));
  253.                 for ( i = 0; i < ACCEPT.MaxAcceptUsed; i++)
  254.                 {
  255.                         wsprintf(hlp,"<LI><STRONG>%s</STRONG>\r\n",ACCEPT.OneAccField[i].MimeType);
  256.                         write(fh,hlp,strlen(hlp));
  257.                 } /* endfor */
  258.                 wsprintf(hlp,"</UL>\r\n");
  259.                 write(fh,hlp,strlen(hlp));
  260.                 wsprintf(hlp,"<HR Size=4>\r\n");
  261.                 write(fh,hlp,strlen(hlp));
  262.  
  263.                 wsprintf(hlp,"<H2>Extra Headers Section</H2>\r\n");
  264.                 write(fh,hlp,strlen(hlp));
  265.                 if (ExtraHeaders_1.MaxUsed > 0)
  266.                 {
  267.                         wsprintf(hlp,"<UL>\r\n");
  268.                         write(fh,hlp,strlen(hlp));
  269.                         for (i = 0; i < ExtraHeaders_1.MaxUsed; i++)
  270.                         {
  271.                                 wsprintf(hlp,"<LI><STRONG>%s :</STRONG>%s\r\n",
  272.                                          ExtraHeaders_1.OneExtraHeader[i].Var,
  273.                                          ExtraHeaders_1.OneExtraHeader[i].Value);
  274.                                 write(fh,hlp,strlen(hlp));
  275.                         } /* endfor */
  276.                         wsprintf(hlp,"</UL>\r\n");
  277.                         write(fh,hlp,strlen(hlp));
  278.                 }
  279.                 else
  280.                 {
  281.                         wsprintf(hlp,"No Extra Headers existing\r\n<P>");
  282.                         write(fh,hlp,strlen(hlp));
  283.                 } /* endif */
  284.  
  285.                 wsprintf(hlp,"<HR Size=4>\r\n");
  286.                 write(fh,hlp,strlen(hlp));
  287.  
  288.                 wsprintf(hlp,"<H2>Form Literal Section</H2>\r\n");
  289.                 write(fh,hlp,strlen(hlp));
  290.                 if (FormLiteral.MaxUsed > 0)
  291.                 {
  292.                         wsprintf(hlp,"<UL>\r\n");
  293.                         write(fh,hlp,strlen(hlp));
  294.                         for (i = 0; i < FormLiteral.MaxUsed; i++)
  295.                         {
  296.                                 wsprintf(hlp,"<LI><STRONG>%s :</STRONG>%s\r\n",
  297.                                          FormLiteral.OneFormLiteral[i].Var,
  298.                                          FormLiteral.OneFormLiteral[i].Value);
  299.                                 write(fh,hlp,strlen(hlp));
  300.                         } /* endfor */
  301.                         wsprintf(hlp,"</UL>\r\n");
  302.                         write(fh,hlp,strlen(hlp));
  303.                 }
  304.                 else
  305.                 {
  306.                         wsprintf(hlp,"Nothing defined in Form Literal Section\r\n<P>");
  307.                         write(fh,hlp,strlen(hlp));
  308.                 } /* endif */
  309.  
  310.  
  311.                 wsprintf(hlp,"<HR Size=4>\r\n");
  312.                 write(fh,hlp,strlen(hlp));
  313.  
  314.                 wsprintf(hlp,"<H2>Form External Section</H2>\r\n");
  315.                 write(fh,hlp,strlen(hlp));
  316.                 if (FormExternal.MaxUsed > 0)
  317.                 {
  318.                         wsprintf(hlp,"<UL>\r\n");
  319.                         write(fh,hlp,strlen(hlp));
  320.                         for (i = 0; i < FormExternal.MaxUsed; i++)
  321.                         {
  322.                                 wsprintf(hlp,"<LI><STRONG>%s :</STRONG>%s %d\r\n",
  323.                                          FormExternal.OneFormExternal[i].Var,
  324.                                          FormExternal.OneFormExternal[i].FileName,
  325.                                          FormExternal.OneFormExternal[i].Size);
  326.                                 write(fh,hlp,strlen(hlp));
  327.                         } /* endfor */
  328.                         wsprintf(hlp,"</UL>\r\n");
  329.                         write(fh,hlp,strlen(hlp));
  330.                 }
  331.                 else
  332.                 {
  333.                         wsprintf(hlp,"Nothing defined in Form External Section\r\n<P>");
  334.                         write(fh,hlp,strlen(hlp));
  335.                 } /* endif */
  336.  
  337.                 wsprintf(hlp,"<HR Size=4>\r\n");
  338.                 write(fh,hlp,strlen(hlp));
  339.  
  340.                 wsprintf(hlp,"<H2>Form Huge Section</H2>\r\n");
  341.                 write(fh,hlp,strlen(hlp));
  342.                 if (FormHuge.MaxUsed > 0)
  343.                 {
  344.                         wsprintf(hlp,"<UL>\r\n");
  345.                         write(fh,hlp,strlen(hlp));
  346.                         for (i = 0; i < FormHuge.MaxUsed; i++)
  347.                         {
  348.                                 wsprintf(hlp,"<LI><STRONG>%s :</STRONG>%d %d\r\n",
  349.                                          FormHuge.OneFormHuge[i].Var,
  350.                                          FormHuge.OneFormHuge[i].Offset,
  351.                                          FormHuge.OneFormHuge[i].Size);
  352.                                 write(fh,hlp,strlen(hlp));
  353.                         } /* endfor */
  354.                         wsprintf(hlp,"</UL>\r\n");
  355.                         write(fh,hlp,strlen(hlp));
  356.                 }
  357.                 else
  358.                 {
  359.                         wsprintf(hlp,"Nothing defined in Form Huge Section\r\n<P>");
  360.                         write(fh,hlp,strlen(hlp));
  361.                 } /* endif */
  362.  
  363.                 wsprintf(hlp,"<HR Size=4>\r\n");
  364.                 write(fh,hlp,strlen(hlp));
  365.  
  366.                 wsprintf(hlp,"Please check out our homepage for <STRONG>Alibaba</STRONG> updates and latest product infos :");
  367.                 write(fh,hlp,strlen(hlp));
  368.                 wsprintf(hlp,"<A HREF=\"http://www.csm.co.at/csm/\">http://www.csm.co.at/csm/</A><P>\r\n");
  369.                 write(fh,hlp,strlen(hlp));
  370.                 wsprintf(hlp,"<UL>\r\n");
  371.                 write(fh,hlp,strlen(hlp));
  372.                 wsprintf(hlp,"<LI><A HREF=\"mailto:sales@csm.co.at\">Yes, I want sales information</A>\r\n");
  373.                 write(fh,hlp,strlen(hlp));
  374.                 wsprintf(hlp,"<LI><A HREF=\"mailto:support@csm.co.at\">I need help !</A>\r\n");
  375.                 write(fh,hlp,strlen(hlp));
  376.                 wsprintf(hlp,"</UL>\r\n");
  377.                 write(fh,hlp,strlen(hlp));
  378.                 wsprintf(hlp,"<HR Size=4>\r\n");
  379.                 write(fh,hlp,strlen(hlp));
  380.  
  381.                 _close(fh);
  382.                 /* Free the allocated Extra Headers Memory */
  383.                 CSM_FreeExtraHeaders(&ExtraHeaders_1);
  384.                 CSM_FreeFormLiteral(&FormLiteral);
  385.                 CSM_FreeFormExternal(&FormExternal);
  386.                 CSM_FreeFormHuge(&FormHuge);
  387.  
  388.                 SendMessage (hWnd, WM_CLOSE, 0, 0);
  389.                 return 0;
  390.                 break;
  391.  
  392.             case WM_DESTROY:
  393.             case WM_QUIT:
  394.                 PostQuitMessage(0);
  395.                 DestroyMenu(hWndMainMenu);
  396.                 break;
  397.             default:
  398.                 return(DefWindowProc(hWnd, message, wParam, lParam));
  399.         } /* endswitch */
  400.         return(0L);
  401. } /* end of WndProc */
  402.