You are viewing a plain text version of this content. The canonical link for it is here.
Posted to site-cvs@tcl.apache.org by mx...@apache.org on 2014/06/02 20:57:21 UTC

svn commit: r1599307 - in /tcl/rivet/trunk: ChangeLog doc/xml/internals.xml src/rivet.h src/rivetcmds/rivetCore.c

Author: mxmanghi
Date: Mon Jun  2 18:57:20 2014
New Revision: 1599307

URL: http://svn.apache.org/r1599307
Log:
    * src/rivet.h,src/rivetcmds/rivetCore.c: macro CHECK_REQUEST_REC moved from rivetCore.c to rivet.h
    * doc/xml/internals.xml: New section documenting how to extend mod_rivet with new commands written in C


Modified:
    tcl/rivet/trunk/ChangeLog
    tcl/rivet/trunk/doc/xml/internals.xml
    tcl/rivet/trunk/src/rivet.h
    tcl/rivet/trunk/src/rivetcmds/rivetCore.c

Modified: tcl/rivet/trunk/ChangeLog
URL: http://svn.apache.org/viewvc/tcl/rivet/trunk/ChangeLog?rev=1599307&r1=1599306&r2=1599307&view=diff
==============================================================================
--- tcl/rivet/trunk/ChangeLog (original)
+++ tcl/rivet/trunk/ChangeLog Mon Jun  2 18:57:20 2014
@@ -1,5 +1,9 @@
+2014-06-02 Massimo Manghi <mx...@apache.org>
+    * src/rivet.h,src/rivetcmds/rivetCore.c: macro CHECK_REQUEST_REC moved from rivetCore.c to rivet.h
+    * doc/xml/internals.xml: New section documenting how to extend mod_rivet with new commands written in C
+
 2014-05-22 Massimo Manghi <mx...@apache.org>
-    * rive/packages/dio/aida.sql: redifining responsability of class Aida (not to be officially released)
+    * rivet/packages/dio/aida.sql: redifining responsability of class Aida (not to be officially released)
 
 2014-04-17 Massimo Manghi <mx...@apache.org>
     * src/: reintegrating modularization branch. Now every subsystem mod_rivet is made of (module, 

Modified: tcl/rivet/trunk/doc/xml/internals.xml
URL: http://svn.apache.org/viewvc/tcl/rivet/trunk/doc/xml/internals.xml?rev=1599307&r1=1599306&r2=1599307&view=diff
==============================================================================
--- tcl/rivet/trunk/doc/xml/internals.xml (original)
+++ tcl/rivet/trunk/doc/xml/internals.xml Mon Jun  2 18:57:20 2014
@@ -83,14 +83,82 @@
       </note>
       </para>
       <para>
-	After a script has been loaded and parsed into it's "pure Tcl"
-	form, it is also cached, so that it may be used in the future
-	without having to reload it (and re-parse it) from the disk.
-	The number of scripts stored in memory is configurable.  This
-	feature can significantly improve performance.
+    	After a script has been loaded and parsed into it's "pure Tcl"
+    	form, it is also cached, so that it may be used in the future
+    	without having to reload it (and re-parse it) from the disk.
+    	The number of scripts stored in memory is configurable.  This
+    	feature can significantly improve performance.
       </para>
     </section>
-
+    <section>
+        <title>Extending Rivet by developing C procedures implementing new commands</title>
+        <para>
+            Rivet endows the Tcl interpreter with new commands
+            to provide an interface from the application layer to the
+            Apache web server internal data. Many of these commands
+            are meaningful only when HTTP request are being processed
+            and a fundamental data structure has been allocated and
+            intialized by the Apache framework: the request_rec object. 
+            In case commands have to be written that have to gain access 
+            to a valid request_rec object pointer they must check if such 
+            a pointer exists and it's initialized
+            with valid data. 
+        </para>
+        <para>            
+            For this purpose in <option>src/rivet.h</option> the macro
+            CHECK_REQUEST_REC was defined accepting to arguments: the pointer
+            to the request_rec object (stored in the 
+            <structname>rivet_interp_globals</structname>
+            structure) and the command name. If the pointer is NULL
+            the macro calls Tcl_NoRequestRec and returns TCL_ERROR
+            causing the command to fail. These are the step to follow
+            to implement a new C language command for mod_rivet 
+        </para>
+        <itemizedlist>
+            <listitem>
+                Define the command and associated C language procedure
+                in src/rivetcmds/rivetCore.c using the macro
+                <option>RIVET_OBJ_CMD</option>
+                <programlisting>RIVET_OBJ_CMD("mycmd",Rivet_MyCmd)</programlisting>
+                This macro ensures the command is defined as <command>::rivet::mycmd</command>
+            </listitem>
+            <listitem>
+                Add the code of Rivet_MyCmd to src/rivetcmd/rivetCore.c (in case
+                the code resides in a different file also src/Makefile.am should be
+                changed to tell the build system how to compile the code and
+                link it into mod_rivet.so)
+            </listitem>
+            <listitem>
+                If the code must gain access to <command>globals->r</command>
+                put add the macro testing for the pointer
+                <programlisting>TCL_CMD_HEADER( Rivet_MyCmd )
+{
+    rivet_interp_globals *globals = Tcl_GetAssocData( interp, "rivet", NULL );
+    ....
+    CHECK_REQUEST_REC(globals->r,"::rivet::mycmd");
+    ...   
+}</programlisting>
+            </listitem>
+            <listitem>
+                Add a test for this command in <option>tests/checkfails.tcl</option>. For 
+                instance
+                <programlisting>...
+check_fail no_body
+check_fail virtual_filename unkn
+check_fail my_cmd &lt;arg1&gt; &lt;arg2&gt;
+....</programlisting>
+                Where <option>&lt;arg1&gt; &lt;arg2&gt;</option> are optional 
+                arguments in case the command needs to check for <command>globals->r</command>
+                in special cases. Then, if <command>::rivet::mycmd</command> must fail also
+                <option>tests/failtest.tcl</option> should modified as
+                <programlisting>virtual_filename->1
+mycmd->1</programlisting>
+                The value associated to the test must be <option>0</option> in case the
+                command doesn't need to test the <command>globals->r</command> pointer.
+            </listitem>
+            
+        </itemizedlist>
+    </section>
     <section>
       <title>Debugging Rivet and Apache</title>
       <para>

Modified: tcl/rivet/trunk/src/rivet.h
URL: http://svn.apache.org/viewvc/tcl/rivet/trunk/src/rivet.h?rev=1599307&r1=1599306&r2=1599307&view=diff
==============================================================================
--- tcl/rivet/trunk/src/rivet.h (original)
+++ tcl/rivet/trunk/src/rivet.h Mon Jun  2 18:57:20 2014
@@ -54,6 +54,21 @@ Tcl_CreateObjCommand( interp, /* Tcl int
 		      NULL,   /* Client Data */\
 		      (Tcl_CmdDeleteProc *)NULL /* Tcl Delete Prov */); 
 
+/* 
+ * Pointer in r is checked and in case Rivet_NoRequestRec is
+ * called returning TCL_ERROR. This macro is used (and often
+ * is the first code like) in commands that must ascertain
+ * the request_rec object pointer in globals is valid 
+ * (when a request processing ends it's set to NULL)
+ */
+
+#define CHECK_REQUEST_REC(r,cmd_name) \
+if (r == NULL)\
+{\
+    Rivet_NoRequestRec(interp,Tcl_NewStringObj(cmd_name,-1));\
+    return TCL_ERROR;\
+}
+
 EXTERN int Rivet_Init(Tcl_Interp *interp);
 EXTERN int Rivet_InitList(Tcl_Interp *interp);
 EXTERN int Rivet_InitCrypt(Tcl_Interp *interp);

Modified: tcl/rivet/trunk/src/rivetcmds/rivetCore.c
URL: http://svn.apache.org/viewvc/tcl/rivet/trunk/src/rivetcmds/rivetCore.c?rev=1599307&r1=1599306&r2=1599307&view=diff
==============================================================================
--- tcl/rivet/trunk/src/rivetcmds/rivetCore.c (original)
+++ tcl/rivet/trunk/src/rivetcmds/rivetCore.c Mon Jun  2 18:57:20 2014
@@ -56,12 +56,6 @@ extern char* TclWeb_GetRawPost (TclWebRe
 
 #define POOL (globals->r->pool)
 
-#define CHECK_REQUEST_REC(r,cmd_name) \
-if (r == NULL)\
-{\
-    Rivet_NoRequestRec(interp,Tcl_NewStringObj(cmd_name,-1));\
-    return TCL_ERROR;\
-}
    
 
 /*



---------------------------------------------------------------------
To unsubscribe, e-mail: site-cvs-unsubscribe@tcl.apache.org
For additional commands, e-mail: site-cvs-help@tcl.apache.org