home *** CD-ROM | disk | FTP | other *** search
/ Australian Personal Computer 1999 May / APC452.ISO / netkit / xitami / xitami.exe / TESTLRWP.C < prev    next >
Encoding:
C/C++ Source or Header  |  1998-01-20  |  3.3 KB  |  111 lines

  1. /************************************************************************
  2.                Copyright (c) 1997 by Total Control Software
  3.                          All Rights Reserved
  4. ------------------------------------------------------------------------
  5.  
  6. Module Name:    testlrwp.c
  7.  
  8. Description:    Simple example of an LRWP Peer application.
  9.  
  10. Creation Date:  1/5/98 9:47:50PM
  11.  
  12. # License:      This is free software.  You may use this software for any
  13. #               purpose including modification/redistribution, so long as
  14. #               this header remains intact and that you do not claim any
  15. #               rights of ownership or authorship of this software.  This
  16. #               software has been tested, but no warranty is expressed or
  17. #               implied.
  18.  
  19. ************************************************************************/
  20.  
  21.  
  22. #include "lrwplib.h"
  23.  
  24. #include <stdio.h>
  25.  
  26. //---------------------------------------------------------------------------
  27.  
  28. void usage(void)
  29. {
  30.     printf("Usage:\n\ttestlrwp appname host port [vhost]\n");
  31. }
  32.  
  33. //---------------------------------------------------------------------------
  34.  
  35. void main(int argc, char* argv[])
  36. {
  37.     LRWP    lrwp;
  38.     int     count = 0;
  39.     int     err;
  40.     char*   errMsg;
  41.     char*   appname;
  42.     char*   host;
  43.     char*   port;
  44.     char*   vhost = NULL;
  45.     char    buf[1024];
  46.     SYMBOL* symbol;
  47.  
  48.     if (argc < 4) {
  49.         usage();
  50.         exit(1);
  51.     }
  52.  
  53.     appname = argv[1];
  54.     host    = argv[2];
  55.     port    = argv[3];
  56.     if (argc > 4)
  57.         vhost = argv[4];
  58.  
  59.     sock_init();
  60.  
  61.     errMsg = lrwp_connect(&lrwp, appname, host, port, vhost);
  62.     if (errMsg) {
  63.         fprintf(stderr, "%s\n", errMsg);
  64.         exit(1);
  65.     }
  66.  
  67.     printf("Waiting for requests from %s:%s\n", host, port);
  68.     printf("Try hitting http://%s/%s with your browser...\n",
  69.            vhost ? vhost : host, appname);
  70.  
  71.         /* only handle 5 reqests, then exit */
  72.     while (count < 5 && lrwp_accept_request(&lrwp) != -1) {
  73.         count += 1;
  74.  
  75.         err = lrwp_send_string(&lrwp, "Content-type: text/html\r\n\r\n");
  76.         sprintf(buf, "<HTML><HEAD><TITLE>LRWP TestApp (%s)</TITLE></HEAD>\n<BODY>\n",
  77.                 appname);
  78.         err = lrwp_send_string(&lrwp, buf);
  79.  
  80.         sprintf(buf, "<H2>LRWP test app (%s)</H2><P>", appname);
  81.         err = lrwp_send_string(&lrwp, buf);
  82.  
  83.         sprintf(buf, "<b>request count</b> = %d<br>", count);
  84.         err = lrwp_send_string(&lrwp, buf);
  85.  
  86.         err = lrwp_send_string(&lrwp, "<br><b>post data:</b> ");
  87.         if (strlen(lrwp.post_data)) {
  88.             err = lrwp_send_string(&lrwp, "<pre>");
  89.             err = lrwp_send_string(&lrwp, lrwp.post_data);
  90.             err = lrwp_send_string(&lrwp, "</pre><br>");
  91.         }
  92.  
  93.         err = lrwp_send_string(&lrwp, "<P><HR><P><pre>");
  94.         for (symbol=lrwp.cgi->symbols; symbol; symbol=symbol->next) {
  95.             sprintf(buf, "<b>%-20s :</b>  %s\n", symbol->name, symbol->value);
  96.             err = lrwp_send_string(&lrwp, buf);
  97.         }
  98.  
  99.         err = lrwp_send_string(&lrwp, "\n</pre><P><HR>\n</BODY></HTML>\n");
  100.         err = lrwp_finish_request(&lrwp);
  101.     }
  102.  
  103.     err = lrwp_close(&lrwp);
  104.     sock_term();
  105. }
  106.  
  107. //---------------------------------------------------------------------------
  108.  
  109.  
  110.  
  111.