home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 1999 January / dppcpro0199a.iso / January / Fp98 / SDK / WebBot / wbtest2 / wbtest2.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-09-18  |  2.6 KB  |  114 lines

  1. //
  2. // Copyright (c) 1996 Vermeer Technologies, Inc., a wholly owned
  3. //               subsidiary of Microsoft Corp.  All Rights Reserved
  4. //
  5. // File: wbtest2.cpp
  6. // DLL Custom WebBot Component Example
  7. //
  8.  
  9. #include "stdio.h"
  10. #include "../webbot.h"
  11.  
  12. // private utility to display a dictionary in HTML
  13.  
  14. void DumpDict(
  15.     CWebBotDict&   dict,
  16.     CWebBotString& ret)
  17. {
  18.     const char* key;
  19.  
  20.     ret.Append("<UL>");
  21.     while (key = dict.NextKey())
  22.     {
  23.         ret.Append("<LI><B>");
  24.         ret.Append(key);
  25.         ret.Append("</B> = ");
  26.         long values = dict.NumValues(key);
  27.         if (values > 1)
  28.         {
  29.             ret.Append("<UL>");
  30.             for (short i = 0;  i < values;  i++)
  31.             {
  32.                 char nbuf[12];
  33.                 sprintf(nbuf, "%d", i);
  34.                 ret.Append("<LI><B>[");
  35.                 ret.Append(nbuf);
  36.                 ret.Append("]</B> = ");
  37.                 ret.Append(dict.GetValueN(key, i));
  38.                 ret.Append("</LI>");
  39.             }
  40.             ret.Append("</UL>");
  41.         }
  42.         else
  43.             ret.Append(dict.GetValue(key));
  44.         ret.Append("</LI>");
  45.     }
  46.     ret.Append("</UL>");
  47. }
  48.  
  49. ///////////////////
  50. // BOT: Hello2
  51.  
  52. BeginWebBotExpand(Hello2,ret,bot,cgi,form)
  53. {
  54.     ret.Append("\n<b>Hello World!</b>");
  55. }
  56. EndWebBotExpand
  57.  
  58. ////////////////////
  59. // BOT: Form1
  60.  
  61. BeginWebBotExpand(Form1,ret,bot,cgi,form)
  62. {
  63.     ret.Append("\n<H3>Form Test 1 Input Dump</H3>");
  64.  
  65.     ret.Append("<H4>Bot Attributes</H4>");
  66.     DumpDict(bot, ret);
  67.  
  68.     ret.Append("<H4>Form Data</H4>");
  69.     DumpDict(form, ret);
  70.  
  71.     ret.Append("<H4>CGI Environment</H4>");
  72.     DumpDict(cgi, ret);
  73. }
  74. EndWebBotExpand
  75.  
  76. /////////////////////
  77. // BOT: Mime1
  78.  
  79. BeginWebBotExpand(Mime1,ret,bot,cgi,form)
  80. {
  81.     const char* value;
  82.     if (value = bot.GetValue("S-Links"))
  83.     {
  84.         ret.Append("Links: ");
  85.         ret.Append(value);
  86.         ret.Append("\n");
  87.     }
  88.  
  89.     if ((value = form.GetValue("Content-Type")) && *value)
  90.     {
  91.         ret.Append("Content-Type: ");
  92.         ret.Append(value);
  93.         ret.Append("\n\n");
  94.         if (value = form.GetValue("Content"))
  95.             ret.Append(value);
  96.     }
  97.     else if ((value = form.GetValue("Location")) && *value)
  98.     {
  99.         ret.Append("Location: ");
  100.         ret.Append(value);
  101.         ret.Append("\n\n");
  102.     }
  103.     else if ((value = form.GetValue("Redirect")) && *value)
  104.     {
  105.         ret.Append("Redirect: ");
  106.         ret.Append(value);
  107.         ret.Append("\n\n");
  108.     }
  109.     else
  110.         ret.Append("\n<b>Hello from Mime Test 1!</b>\n");
  111. }
  112. EndWebBotExpand
  113.  
  114.