home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 May / Pcwk5b98.iso / WEBSERVE / PI3 / PI3WEB.EXE / DEVEL / Plugins / Dummy.c < prev    next >
C/C++ Source or Header  |  1997-10-19  |  8KB  |  320 lines

  1. /*____________________________________________________________________________*\
  2.  
  3.  Copyright (c) 1997 John Roy. All rights reserved.
  4.  
  5.  These sources, libraries and applications are
  6.  FREE FOR COMMERCIAL AND NON-COMMERCIAL USE
  7.  as long as the following conditions are adhered to.
  8.  
  9.  Redistribution and use in source and binary forms, with or without
  10.  modification, are permitted provided that the following conditions
  11.  are met:
  12.  
  13.  1. Redistributions of source code must retain the above copyright
  14.     notice, this list of conditions and the following disclaimer. 
  15.  
  16.  2. Redistributions in binary form must reproduce the above copyright
  17.     notice, this list of conditions and the following disclaimer in
  18.     the documentation and/or other materials provided with the
  19.     distribution.
  20.  
  21.  3. Redistributions of any form whatsoever and all advertising materials 
  22.     mentioning features must contain the following
  23.     acknowledgment:
  24.     "This product includes software developed by John Roy
  25.     (http://www.johnroy.com/pi3/)."
  26.  
  27.  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  28.  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  29.  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  30.  IN NO EVENT SHALL THE AUTHORS OR ITS CONTRIBUTORS BE LIABLE FOR ANY
  31.  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  32.  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  33.  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  34.  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  35.  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  36.  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  37.  OF THE POSSIBILITY OF SUCH DAMAGE.
  38.  
  39.  *____________________________________________________________________________*|
  40.  *
  41.  * $Source: Dummy.c$
  42.  * $Date: Sun Aug 10 06:37:32 1997$
  43.  *
  44.  Description:
  45.     Dummy handler module.
  46.  
  47. \*____________________________________________________________________________*/
  48. /* $SourceTop:$ */
  49.  
  50. #include <assert.h>
  51.  
  52. #include "Pi3API.h"
  53.  
  54.  
  55. /*____________________________________________________________________________*\
  56.  *
  57.  Description:
  58.     Documentation
  59. \*____________________________________________________________________________*/
  60. #if 0
  61.     /*
  62.     ** HTML documentation for this handler
  63.     */
  64. /*___+++HTMLDOC_BEGIN+++___*/
  65. Name:
  66.     Dummy
  67.  
  68. Description:
  69.     This handler does not do anything. It is useful as a template and
  70.     as a substitute for handlers that are removed from distribution.
  71.  
  72. Options:
  73. <!--
  74. <H5>Overview</H5>
  75. <TABLE BORDER=1>
  76. <TH>Option
  77. <TH>Default
  78. <TH>Values
  79. <TH>Short Description
  80. <TH>Example(s)
  81.  
  82. <TR>
  83. <TD>Pi3Expression
  84. <TD>+
  85. <TD>A Pi3Expression
  86. <TD>Expression to place in debug log
  87. <TD>Pi3Expression="$c/* value of Content-Type */"
  88.  
  89. </TABLE>
  90. <STRONG>-</STRONG> in the <IT>default</IT> indicates no default<BR>
  91. <STRONG>+</STRONG> in the <IT>default</IT> indicates the field is mandatory<BR>
  92.  
  93. <H4>Description of Options</H4>
  94. <H5>
  95.     Pi3Expression
  96. </H5>
  97. Pi3Expression to write in the debug log.
  98. -->
  99.  
  100. Phase:
  101.     All phases
  102.  
  103. Returns:
  104.     PIAPI_COMPLETED
  105.  
  106. Note:
  107. Example:
  108.     <PRE>
  109.     <Object>
  110.         Name Dummy
  111.         Class DummyClass
  112.         Variable3 "Value3"
  113.     </Object>
  114.  
  115.     <Object>
  116.         ...
  117.         Handle Dummy Variable1="Value1" Variable2="Value2"
  118.         ...
  119.     </Object>
  120.     </PRE>
  121. /*___+++HTMLDOC_END+++___*/
  122. #endif
  123.  
  124. /*____________________________________________________________________________*\
  125.  *
  126.  Description:
  127. \*____________________________________________________________________________*/
  128. struct _Dummy
  129. {
  130.     int xxx;
  131. };
  132. typedef struct _Dummy Dummy;
  133.  
  134. /*____________________________________________________________________________*\
  135.  *
  136.  Function:
  137.  Synopsis:
  138.  Description:
  139. \*____________________________________________________________________________*/
  140. int Dummy_fnParameter( void *pData, const char *pVar, const char *pVal,
  141.     const char *pWhere )
  142. {
  143.     PIObject *pObject = (PIObject *)pData;
  144.     Dummy *pDummy = (Dummy *)PIObject_getUserData( pObject );
  145.     (void)pDummy;
  146.     assert( pVar );
  147.     assert( pVal );
  148.  
  149. #if 0
  150.     if ( !PIUtil_stricmp( pVar, "Variable1" ) )
  151.         {
  152.         xxx = pVal;
  153.         }
  154. #endif
  155.     if ( 1 )
  156.         {
  157.         }
  158.     else
  159.         {
  160.         /* ---
  161.         Configuration error
  162.         --- */
  163.         PILog_addMessage(
  164.             PIObject_getDB( pObject ),
  165.             PIObject_getConfigurationDB( pObject ),
  166.             PILOG_ERROR, "Dummy: %sUnknown directive '%s'.", pWhere, pVar );
  167.         return 0;
  168.         };
  169.     return 1;
  170. }
  171.  
  172. /*____________________________________________________________________________*\
  173.  *
  174.  Function:
  175.  Synopsis:
  176.  Description:
  177. \*____________________________________________________________________________*/
  178. int Dummy_init( Dummy *pDummy, PIObject *pObject, int iArgc,
  179.     const char *ppArgv[] )
  180. {
  181.     int iRet = PIObject_readParameters( pObject, iArgc, ppArgv,
  182.         Dummy_fnParameter, pObject );
  183.  
  184.     /* --- set defaults --- */
  185.     if ( iRet )
  186.         {
  187. #if 0
  188.         pDummy->xxx = "yyy"
  189. #endif
  190.         };
  191.  
  192.     return iRet;
  193. }
  194.  
  195. /*____________________________________________________________________________*\
  196.  *
  197.  Function:
  198.  Synopsis:
  199.  Description:
  200. \*____________________________________________________________________________*/
  201. PUBLIC_PIAPI int Dummy_onClassLoad( PIClass_LoadAction eLoad, int i,
  202.     const char *a[] )
  203. {
  204.     return PIAPI_COMPLETED;
  205. }
  206.  
  207. /*____________________________________________________________________________*\
  208.  *
  209.  Function:
  210.  Synopsis:
  211.  Description:
  212. \*____________________________________________________________________________*/
  213. PUBLIC_PIAPI int Dummy_constructor( PIObject *pObj,
  214.     int iArgc, const char *ppArgv[] )
  215. {
  216.     Dummy *pDummy = PIUtil_malloc( sizeof( Dummy ) );
  217.     PIObject_setUserData( pObj, pDummy );
  218.     if ( !Dummy_init( pDummy, pObj, iArgc, ppArgv ) )
  219.         {
  220.         return PIAPI_ERROR;
  221.         };
  222.     return PIAPI_COMPLETED;
  223. }
  224.  
  225. /*____________________________________________________________________________*\
  226.  *
  227.  Function:
  228.  Synopsis:
  229.  Description:
  230. \*____________________________________________________________________________*/
  231. PUBLIC_PIAPI int Dummy_copyConstructor( PIObject *o, int i, const char *a[] )
  232. {
  233.     return PIAPI_ERROR;
  234. }
  235.  
  236. /*____________________________________________________________________________*\
  237.  *
  238.  Function:
  239.  Synopsis:
  240.  Description:
  241. \*____________________________________________________________________________*/
  242. #define MSG "\
  243. <HTML>\
  244. <BODY BACKGROUND=\"/icons/Pi3Tile.gif\" BGCOLOR=\"#FFFFFF\">\
  245. <TITLE>Stub Handler</TITLE>\
  246. <H1>Stub Handler</H1>\
  247. This requested handler service has not been added loaded into this server.<BR>\
  248. </BODY></HTML>\
  249. "
  250. PUBLIC_PIAPI int Dummy_execute( PIObject *pObj,
  251.     int iArgc, const char *ppArgv[] )
  252. {
  253.     PIHTTP *pPIHTTP;
  254.  
  255.     if ( iArgc<1 )
  256.         { return PIAPI_ERROR; };
  257.  
  258.     pPIHTTP = (PIHTTP *)*ppArgv;
  259.  
  260.     /* ---
  261.     If this is a handler phase then send a message
  262.     --- */
  263.     if ( pPIHTTP->ciPhase==PH_HANDLE )
  264.         {
  265.         PIDB *pR = pPIHTTP->pResponseDB;
  266. /*        PIDB *pQ = pPIHTTP->pRequestDB; */
  267.         PIIOBuffer *pB = pPIHTTP->pBuffer;
  268.  
  269.         /* ---
  270.         Send headers
  271.         -- */
  272.         if (    HTTPCore_sendGeneralHeaders( pPIHTTP ) ||
  273.                 HTTPCore_sendEntityHeaders( pPIHTTP, pR ) )
  274.             {
  275.             return PIAPI_ERROR;
  276.             };
  277.  
  278.         /* ---
  279.         Send a brief message
  280.         --- */
  281.         PIIOBuffer_writeLn( pB, MSG, sizeof(MSG), PIIOBUF_NONE );
  282.         };
  283.  
  284.     return PIAPI_COMPLETED;
  285. }
  286.  
  287. /*____________________________________________________________________________*\
  288.  *
  289.  Function:
  290.  Synopsis:
  291.  Description:
  292. \*____________________________________________________________________________*/
  293. PUBLIC_PIAPI int Dummy_destructor( PIObject *pObj, int i, const char *a[] )
  294. {
  295.     PIUtil_free( PIObject_getUserData( pObj ) );
  296.     return PIAPI_COMPLETED;
  297. }
  298.  
  299. #if 0
  300. /*___+++CNF_BEGIN+++___*/
  301.     <Class>
  302.         Name DummyClass
  303.         Type LogicExtension
  304.         Library Plugins
  305.         OnClassLoad Dummy_onClassLoad
  306.         Constructor Dummy_constructor
  307.         CopyConstructor Dummy_copyConstructor
  308.         Destructor Dummy_destructor
  309.         Execute Dummy_execute
  310.     </Class>
  311.  
  312.     <Object>
  313.         Name Dummy
  314.         Class DummyClass
  315.     </Object>
  316.  
  317. /*___+++CNF_END+++___*/
  318. #endif
  319.  
  320.