1 <!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook V3.1//EN">
3 File : $Source: /cvsroot/ijbswa/current/doc/source/developer-manual.sgml,v $
5 Purpose : developer manual
7 ijbswa.sourceforge.net:/home/groups/i/ij/ijbswa/htdocs/
9 $Id: developer-manual.sgml,v 1.14 2002/03/30 19:04:08 swa Exp $
11 Written by and Copyright (C) 2001 the SourceForge
12 Privoxy team. http://www.privoxy.org/
14 Based on the Internet Junkbuster originally written
15 by and Copyright (C) 1997 Anonymous Coders and
16 Junkbusters Corporation. http://www.junkbusters.com
21 <title>Privoxy Developer Manual</title>
23 <pubdate>$Id: developer-manual.sgml,v 1.14 2002/03/30 19:04:08 swa Exp $</pubdate>
28 <orgname>By: Privoxy Developers</orgname>
35 The developer manual gives the users information on how to help the developer
36 team. It provides guidance on coding, testing, documentation and other
41 <application>Privoxy</application> is a web proxy with advanced filtering
42 capabilities for protecting privacy, filtering web page content, managing
43 cookies, controlling access, and removing ads, banners, pop-ups and other
44 obnoxious Internet junk. <application>Privoxy</application> has a very
45 flexible configuration and can be customized to suit individual needs and
46 tastes. <application>Privoxy</application> has application for both
47 stand-alone systems and multi-user networks.
51 <application>Privoxy</application> is based on the code of the
52 <application>Internet Junkbuster</application>.
53 <application>Junkbuster</application> was originally written by JunkBusters
54 Corporation, and was released as free open-source software under the GNU GPL.
55 Stefan Waldherr made many improvements, and started the SourceForge project
56 to continue development. Other developers have since joined Stefan.
60 You can find the latest version of the user manual at <ulink
61 url="http://www.privoxy.org/developer-manual/">http://www.privoxy.org/developer-manual/</ulink>.
62 Please see the Contact section in the user-manual if you want to contact the
67 <!-- Feel free to send a note to the developers at <email>ijbswa-developers@lists.sourceforge.net</email>. -->
73 <!-- ~~~~~ New section ~~~~~ -->
74 <sect1 id="introduction"><title>Introduction</title>
79 <!-- ~~~~~ New section ~~~~~ -->
80 <sect1 id="quickstart"><title>Quickstart to Privoxy Development</title>
82 You'll need an account on Sourceforge to support our development. Mail you ID
83 to the list and wait until a project manager has added you.
85 For the time beeing (read, this section is under construction), please note the
86 following guidelines for changing stuff in the code. If it is
87 <orderedlist numeration="arabic">
89 A bugfix / clean-up / cosmetic thing: shoot
92 A new feature that can be turned off: shoot
95 A clear improvement w/o side effects on other parts of the code: shoot
98 A matter of taste: ask the list
101 A major redesign of some part of the code: ask the list
107 <!-- ~~~~~ New section ~~~~~ -->
108 <sect1 id="documentation"><title>Documentation Guidelines</title>
110 All docs are in SGML format and located in the <computeroutput>doc/source</computeroutput> directory.
113 How do you update the webserver (i.e. the pages on sourceforge)?
114 <orderedlist numeration="arabic">
116 Run <computeroutput>make dok</computeroutput> (which uses the documents in <computeroutput>doc/source</computeroutput> to update all
117 text files in <computeroutput>doc/text</computeroutput> and to update
118 all web documents in <computeroutput>doc/webserver</computeroutput>.
121 Run <computeroutput>make webserver</computeroutput> which copies all files from
122 <computeroutput>doc/webserver</computeroutput> to the sourceforge webserver
129 <!-- <listitem><para>be consistent with the redirect script (i.e. the <application>Privoxy</application> program -->
130 <!-- points via the redirect URL at sf to valid end-points in the document)</para></listitem> -->
132 <!-- ~~~~~ New section ~~~~~ -->
133 <sect1 id="coding"><title>Coding Guidelines</title>
135 <sect2 id="s1"><title>Introduction</title>
137 <para>This set of standards is designed to make our lives easier. It is
138 developed with the simple goal of helping us keep the "new and improved
139 <application>Privoxy</application>" consistent and reliable. Thus making
140 maintenance easier and increasing chances of success of the
143 <para>And that of course comes back to us as individuals. If we can
144 increase our development and product efficiencies then we can solve more
145 of the request for changes/improvements and in general feel good about
146 ourselves. ;-></para>
150 <sect2 id="s2"><title>Using Comments</title>
153 <sect3 id="s3"><title>Comment, Comment, Comment</title>
155 <para><emphasis>Explanation:</emphasis></para>
157 <para>Comment as much as possible without commenting the obvious.
158 For example do not comment "aVariable is equal to bVariable".
159 Instead explain why aVariable should be equal to the bVariable.
160 Just because a person can read code does not mean they will
161 understand why or what is being done. A reader may spend a lot
162 more time figuring out what is going on when a simple comment
163 or explanation would have prevented the extra research. Please
164 help your brother IJB'ers out!</para>
166 <para>The comments will also help justify the intent of the code.
167 If the comment describes something different than what the code
168 is doing then maybe a programming error is occurring.</para>
170 <para><emphasis>Example:</emphasis></para>
172 /* if page size greater than 1k ... */
173 if ( PageLength() > 1024 )
175 ... "block" the page up ...
178 /* if page size is small, send it in blocks */
179 if ( PageLength() > 1024 )
181 ... "block" the page up ...
184 This demonstrates 2 cases of "what not to do". The first is a
185 "syntax comment". The second is a comment that does not fit what
186 is actually being done.
192 <sect3 id="s4"><title>Use blocks for comments</title>
194 <para><emphasis>Explanation:</emphasis></para>
196 <para>Comments can help or they can clutter. They help when they
197 are differentiated from the code they describe. One line
198 comments do not offer effective separation between the comment
199 and the code. Block identifiers do, by surrounding the code
200 with a clear, definable pattern.</para>
202 <para><emphasis>Example:</emphasis></para>
204 /*********************************************************************
205 * This will stand out clearly in your code!
206 *********************************************************************/
207 if ( thisVariable == thatVariable )
209 DoSomethingVeryImportant();
213 /* unfortunately, this may not */
214 if ( thisVariable == thatVariable )
216 DoSomethingVeryImportant();
220 if ( thisVariable == thatVariable ) /* this may not either */
222 DoSomethingVeryImportant();
225 <para><emphasis>Exception:</emphasis></para>
227 <para>If you are trying to add a small logic comment and do not
228 wish to "disrubt" the flow of the code, feel free to use a 1
229 line comment which is NOT on the same line as the code.</para>
235 <sect3 id="s5"><title>Keep Comments on their own line</title>
237 <para><emphasis>Explanation:</emphasis></para>
239 <para>It goes back to the question of readability. If the comment
240 is on the same line as the code it will be harder to read than
241 the comment that is on its own line.</para>
243 <para>There are three exceptions to this rule, which should be
244 violated freely and often: during the definition of variables,
245 at the end of closing braces, when used to comment
248 <para><emphasis>Example:</emphasis></para>
250 /*********************************************************************
251 * This will stand out clearly in your code,
252 * But the second example won't.
253 *********************************************************************/
254 if ( thisVariable == thatVariable )
256 DoSomethingVeryImportant();
259 if ( thisVariable == thatVariable ) /*can you see me?*/
261 DoSomethingVeryImportant(); /*not easily*/
265 /*********************************************************************
266 * But, the encouraged exceptions:
267 *********************************************************************/
268 int urls_read = 0; /* # of urls read + rejected */
269 int urls_rejected = 0; /* # of urls rejected */
273 DoSomethingVeryImportant();
277 short DoSomethingVeryImportant(
278 short firstparam, /* represents something */
279 short nextparam /* represents something else */ )
283 } /* -END- DoSomethingVeryImportant */
288 <sect3 id="s6"><title>Comment each logical step</title>
290 <para><emphasis>Explanation:</emphasis></para>
292 <para>Logical steps should be commented to help others follow the
293 intent of the written code and comments will make the code more
296 <para>If you have 25 lines of code without a comment, you should
297 probably go back into it to see where you forgot to put
300 <para>Most "for", "while", "do", etc... loops _probably_ need a
301 comment. After all, these are usually major logic
308 <sect3 id="s7"><title>Comment All Functions Thoroughly</title>
310 <para><emphasis>Explanation:</emphasis></para>
312 <para>A reader of the code should be able to look at the comments
313 just prior to the beginning of a function and discern the
314 reason for its existence and the consequences of using it. The
315 reader should not have to read through the code to determine if
316 a given function is safe for a desired use. The proper
317 information thoroughly presented at the introduction of a
318 function not only saves time for subsequent maintenance or
319 debugging, it more importantly aids in code reuse by allowing a
320 user to determine the safety and applicability of any function
321 for the problem at hand. As a result of such benefits, all
322 functions should contain the information presented in the
323 addendum section of this document.</para>
329 <sect3 id="s8"><title>Comment at the end of braces if the
330 content is more than one screen length</title>
332 <para><emphasis>Explanation:</emphasis></para>
334 <para>Each closing brace should be followed on the same line by a
335 comment that describes the origination of the brace if the
336 original brace is off of the screen, or otherwise far away from
337 the closing brace. This will simplify the debugging,
338 maintenance, and readability of the code.</para>
340 <para>As a suggestion , use the following flags to make the
341 comment and its brace more readable:</para>
343 <para>use following a closing brace: } /* -END- if() or while ()
346 <para><emphasis>Example:</emphasis></para>
350 DoSomethingVeryImportant();
351 ...some long list of commands...
352 } /* -END- if x is 1 */
358 DoSomethingVeryImportant();
359 ...some long list of commands...
360 } /* -END- if ( 1 == X ) */
366 <sect2 id="s9"><title>Naming Conventions</title>
370 <sect3 id="s10"><title>Variable Names</title>
372 <para><emphasis>Explanation:</emphasis></para>
374 <para>Use all lowercase, and seperate words via an underscore
375 ('_'). Do not start an identifier with an underscore. (ANSI C
376 reserves these for use by the compiler and system headers.) Do
377 not use identifiers which are reserved in ANSI C++. (E.g.
378 template, class, true, false, ...). This is in case we ever
379 decide to port Privoxy to C++.</para>
381 <para><emphasis>Example:</emphasis></para>
383 int ms_iis5_hack = 0;</programlisting>
385 <para><emphasis>Instead of:</emphasis></para>
389 int msiis5hack = 0; int msIis5Hack = 0;
397 <sect3 id="s11"><title>Function Names</title>
399 <para><emphasis>Explanation:</emphasis></para>
401 <para>Use all lowercase, and seperate words via an underscore
402 ('_'). Do not start an identifier with an underscore. (ANSI C
403 reserves these for use by the compiler and system headers.) Do
404 not use identifiers which are reserved in ANSI C++. (E.g.
405 template, class, true, false, ...). This is in case we ever
406 decide to port Privoxy to C++.</para>
408 <para><emphasis>Example:</emphasis></para>
410 int load_some_file( struct client_state *csp )</programlisting>
412 <para><emphasis>Instead of:</emphasis></para>
416 int loadsomefile( struct client_state *csp )
417 int loadSomeFile( struct client_state *csp )
425 <sect3 id="s12"><title>Header file prototypes</title>
427 <para><emphasis>Explanation:</emphasis></para>
429 <para>Use a descriptive parameter name in the function prototype
430 in header files. Use the same parameter name in the header file
431 that you use in the c file.</para>
433 <para><emphasis>Example:</emphasis></para>
435 (.h) extern int load_aclfile( struct client_state *csp );
436 (.c) int load_aclfile( struct client_state *csp )</programlisting>
438 <para><emphasis>Instead of:</emphasis>
440 (.h) extern int load_aclfile( struct client_state * ); or
441 (.h) extern int load_aclfile();
442 (.c) int load_aclfile( struct client_state *csp )
450 <sect3 id="s13"><title>Enumerations, and #defines</title>
452 <para><emphasis>Explanation:</emphasis></para>
454 <para>Use all capital letters, with underscores between words. Do
455 not start an identifier with an underscore. (ANSI C reserves
456 these for use by the compiler and system headers.)</para>
458 <para><emphasis>Example:</emphasis></para>
460 (enumeration) : enum Boolean { FALSE, TRUE };
461 (#define) : #define DEFAULT_SIZE 100;</programlisting>
463 <para><emphasis>Note:</emphasis> We have a standard naming scheme for #defines
464 that toggle a feature in the preprocessor: FEATURE_>, where
465 > is a short (preferably 1 or 2 word) description.</para>
467 <para><emphasis>Example:</emphasis></para>
469 #define FEATURE_FORCE 1
472 #define FORCE_PREFIX blah
473 #endif /* def FEATURE_FORCE */
478 <sect3 id="s14"><title>Constants</title>
480 <para><emphasis>Explanation:</emphasis></para>
482 <para>Spell common words out entirely (do not remove vowels).</para>
484 <para>Use only widely-known domain acronyms and abbreviations.
485 Capitalize all letters of an acronym.</para>
487 <para>Use underscore (_) to separate adjacent acronyms and
488 abbreviations. Never terminate a name with an underscore.</para>
490 <para><emphasis>Example:</emphasis></para>
492 #define USE_IMAGE_LIST 1</programlisting>
494 <para><emphasis>Instead of:</emphasis></para>
498 #define USE_IMG_LST 1 or
499 #define _USE_IMAGE_LIST 1 or
500 #define USE_IMAGE_LIST_ 1 or
501 #define use_image_list 1 or
502 #define UseImageList 1
512 <sect2 id="s15"><title>Using Space</title>
516 <sect3 id="s16"><title>Put braces on a line by themselves.</title>
518 <para><emphasis>Explanation:</emphasis></para>
520 <para>The brace needs to be on a line all by itself, not at the
521 end of the statement. Curly braces should line up with the
522 construct that they're associated with. This practice makes it
523 easier to identify the opening and closing braces for a
526 <para><emphasis>Example:</emphasis></para>
533 <para><emphasis>Instead of:</emphasis></para>
535 <para>if ( this == that ) { ... }</para>
539 <para>if ( this == that ) { ... }</para>
541 <para><emphasis>Note:</emphasis> In the special case that the if-statement is
542 inside a loop, and it is trivial, i.e. it tests for a
543 condidtion that is obvious from the purpose of the block,
544 one-liners as above may optically preserve the loop structure
545 and make it easier to read.</para>
547 <para><emphasis>Status:</emphasis> developer-discrection.</para>
549 <para><emphasis>Example exception:</emphasis></para>
551 while ( more lines are read )
553 /* Please document what is/is not a comment line here */
554 if ( it's a comment ) continue;
556 do_something( line );
562 <sect3 id="s17"><title>ALL control statements should have a
565 <para><emphasis>Explanation:</emphasis></para>
567 <para>Using braces to make a block will make your code more
568 readable and less prone to error. All control statements should
569 have a block defined.</para>
571 <para><emphasis>Example:</emphasis></para>
579 <para><emphasis>Instead of:</emphasis></para>
581 <para>if ( this == that ) DoSomething(); DoSomethingElse();</para>
585 <para>if ( this == that ) DoSomething();</para>
587 <para><emphasis>Note:</emphasis> The first example in "Instead of" will execute
588 in a manner other than that which the developer desired (per
589 indentation). Using code braces would have prevented this
590 "feature". The "explanation" and "exception" from the point
591 above also applies.</para>
597 <sect3 id="s18"><title>Do not belabor/blow-up boolean
600 <para><emphasis>Example:</emphasis></para>
602 structure->flag = ( condition );</programlisting>
604 <para><emphasis>Instead of:</emphasis></para>
606 <para>if ( condition ) { structure->flag = 1; } else {
607 structure->flag = 0; }</para>
609 <para><emphasis>Note:</emphasis> The former is readable and consice. The later
610 is wordy and inefficient. Please assume that any developer new
611 to the project has at least a "good" knowledge of C/C++. (Hope
612 I do not offend by that last comment ... 8-)</para>
618 <sect3 id="s19"><title>Use white space freely because it is
621 <para><emphasis>Explanation:</emphasis></para>
623 <para>Make it readable. The notable exception to using white space
624 freely is listed in the next guideline.</para>
626 <para><emphasis>Example:</emphasis></para>
630 int anotherValue = 0;
631 int thisVariable = 0;
633 if ( thisVariable == thatVariable )
635 firstValue = oldValue + ( ( someValue - anotherValue ) - whatever )
640 <sect3 id="s20"><title>Don't use white space around structure
643 <para><emphasis>Explanation:</emphasis></para>
645 <para>- structure pointer operator ( "->" ) - member operator (
646 "." ) - functions and parentheses</para>
648 <para>It is a general coding practice to put pointers, references,
649 and function parentheses next to names. With spaces, the
650 connection between the object and variable/function name is not
653 <para><emphasis>Example:</emphasis></para>
657 FunctionName();</programlisting>
659 <para><emphasis>Instead of:</emphasis> aStruct -> aMember; aStruct . aMember;
660 FunctionName ();</para>
666 <sect3 id="s21"><title>Make the last brace of a function stand
669 <para><emphasis>Example:</emphasis></para>
676 } /* -END- function1 */
681 } /* -END- function2 */
684 <para><emphasis>Instead of:</emphasis></para>
686 <para>int function1( ... ) { ...code... return( retCode ); } int
687 function2( ... ) { }</para>
689 <para><emphasis>Note:</emphasis> Use 1 blank line before the closing brace and 2
690 lines afterwards. This makes the end of function standout to
691 the most casual viewer. Although function comments help
692 seperate functions, this is still a good coding practice. In
693 fact, I follow these rules when using blocks in "for", "while",
694 "do" loops, and long if {} statements too. After all whitespace
697 <para><emphasis>Status:</emphasis> developer-discrection on the number of blank
698 lines. Enforced is the end of function comments.</para>
704 <sect3 id="s22"><title>Use 3 character indentions</title>
706 <para><emphasis>Explanation:</emphasis></para>
708 <para>If some use 8 character TABs and some use 3 character TABs,
709 the code can look *very* ragged. So use 3 character indentions
710 only. If you like to use TABs, pass your code through a filter
711 such as "expand -t3" before checking in your code.</para>
713 <para><emphasis>Example:</emphasis></para>
715 static const char * const url_code_map[256] =
725 return( ALWAYS_TRUE );
729 return( HOW_DID_YOU_GET_HERE );
732 return( NEVER_GETS_HERE );
741 <sect2 id="s23"><title>Initializing</title>
745 <sect3 id="s24"><title>Initialize all variables</title>
747 <para><emphasis>Explanation:</emphasis></para>
749 <para>Do not assume that the variables declared will not be used
750 until after they have been assigned a value somewhere else in
751 the code. Remove the chance of accidentally using an unassigned
754 <para><emphasis>Example:</emphasis></para>
758 struct *ptr = NULL;</programlisting>
760 <para><emphasis>Note:</emphasis> It is much easier to debug a SIGSEGV if the
761 message says you are trying to access memory address 00000000
762 and not 129FA012; or arrayPtr[20] causes a SIGSEV vs.
765 <para><emphasis>Status:</emphasis> developer-discrection if and only if the
766 variable is assigned a value "shortly after" declaration.</para>
772 <sect2 id="s25"><title>Functions</title>
776 <sect3 id="s26"><title>Name functions that return a boolean as a
779 <para><emphasis>Explanation:</emphasis></para>
781 <para>Value should be phrased as a question that would logically
782 be answered as a true or false statement</para>
784 <para><emphasis>Example:</emphasis></para>
793 <sect3 id="s27"><title>Always specify a return type for a
796 <para><emphasis>Explanation:</emphasis></para>
798 <para>The default return for a function is an int. To avoid
799 ambiguity, create a return for a function when the return has a
800 purpose, and create a void return type if the function does not
801 need to return anything.</para>
807 <sect3 id="s28"><title>Minimize function calls when iterating by
808 using variables</title>
810 <para><emphasis>Explanation:</emphasis></para>
812 <para>It is easy to write the following code, and a clear argument
813 can be made that the code is easy to understand:</para>
815 <para><emphasis>Example:</emphasis></para>
817 for ( size_t cnt = 0; cnt < blockListLength(); cnt ++ )
822 <para><emphasis>Note:</emphasis> Unfortunately, this makes a function call for
823 each and every iteration. This increases the overhead in the
824 program, because the compiler has to look up the function each
825 time, call it, and return a value. Depending on what occurs in
826 the blockListLength() call, it might even be creating and
827 destroying structures with each iteration, even though in each
828 case it is comparing "cnt" to the same value, over and over.
829 Remember too - even a call to blockListLength() is a function
830 call, with the same overhead.</para>
832 <para>Instead of using a function call during the iterations,
833 assign the value to a variable, and evaluate using the
836 <para><emphasis>Example:</emphasis></para>
838 size_t len = blockListLength();
840 for ( size_t cnt = 0; cnt < len; cnt ++ )
845 <para><emphasis>Exceptions:</emphasis> if the value of blockListLength() *may*
846 change or could *potentially* change, then you must code the
847 function call in the for/while loop.</para>
853 <sect3 id="s29"><title>Pass and Return by Const Reference</title>
855 <para><emphasis>Explanation:</emphasis></para>
857 <para>This allows a developer to define a const pointer and call
858 your function. If your function does not have the const
859 keyword, we may not be able to use your function. Consider
860 strcmp, if it were defined as: extern int strcmp( char *s1,
863 <para>I could then not use it to compare argv's in main: int main(
864 int argc, const char *argv[] ) { strcmp( argv[0], "privoxy"
867 <para>Both these pointers are *const*! If the c runtime library
868 maintainers do it, we should too.</para>
874 <sect3 id="s30"><title>Pass and Return by Value</title>
876 <para><emphasis>Explanation:</emphasis></para>
878 <para>Most structures cannot fit onto a normal stack entry (i.e.
879 they are not 4 bytes or less). Aka, a function declaration
880 like: int load_aclfile( struct client_state csp )</para>
882 <para>would not work. So, to be consistent, we should declare all
883 prototypes with "pass by value": int load_aclfile( struct
884 client_state *csp )</para>
890 <sect3 id="s31"><title>Names of include files</title>
892 <para><emphasis>Explanation:</emphasis></para>
894 <para>Your include statements should contain the file name without
895 a path. The path should be listed in the Makefile, using -I as
896 processor directive to search the indicated paths. An exception
897 to this would be for some proprietary software that utilizes a
898 partial path to distinguish their header files from system or
899 other header files.</para>
901 <para><emphasis>Example:</emphasis></para>
903 #include <iostream.h> /* This is not a local include */
904 #include "config.h" /* This IS a local include */
907 <para><emphasis>Exception:</emphasis></para>
911 /* This is not a local include, but requires a path element. */
912 #include <sys/fileName.h>
916 <para><emphasis>Note:</emphasis> Please! do not add "-I." to the Makefile
917 without a _very_ good reason. This duplicates the #include
918 "file.h" behaviour.</para>
924 <sect3 id="s32"><title>Provide multiple inclusion
927 <para><emphasis>Explanation:</emphasis></para>
929 <para>Prevents compiler and linker errors resulting from
930 redefinition of items.</para>
932 <para>Wrap each header file with the following syntax to prevent
933 multiple inclusions of the file. Of course, replace PROJECT_H
934 with your file name, with "." Changed to "_", and make it
937 <para><emphasis>Example:</emphasis></para>
939 #ifndef PROJECT_H_INCLUDED
940 #define PROJECT_H_INCLUDED
942 #endif /* ndef PROJECT_H_INCLUDED */
947 <sect3 id="s33"><title>Use `extern "C"` when appropriate</title>
949 <para><emphasis>Explanation:</emphasis></para>
951 <para>If our headers are included from C++, they must declare our
952 functions as `extern "C"`. This has no cost in C, but increases
953 the potential re-usability of our code.</para>
955 <para><emphasis>Example:</emphasis></para>
960 #endif /* def __cplusplus */
962 ... function definitions here ...
966 #endif /* def __cplusplus */
971 <sect3 id="s34"><title>Where Possible, Use Forward Struct
972 Declaration Instead of Includes</title>
974 <para><emphasis>Explanation:</emphasis></para>
976 <para>Useful in headers that include pointers to other struct's.
977 Modifications to excess header files may cause needless
980 <para><emphasis>Example:</emphasis></para>
982 /*********************************************************************
983 * We're avoiding an include statement here!
984 *********************************************************************/
986 extern file_list *xyz;</programlisting>
988 <para><emphasis>Note:</emphasis> If you declare "file_list xyz;" (without the
989 pointer), then including the proper header file is necessary.
990 If you only want to prototype a pointer, however, the header
991 file is unneccessary.</para>
993 <para><emphasis>Status:</emphasis> Use with discrection.</para>
999 <sect2 id="s35"><title>General Coding Practices</title>
1003 <sect3 id="s36"><title>Turn on warnings</title>
1005 <para><emphasis>Explanation</emphasis></para>
1007 <para>Compiler warnings are meant to help you find bugs. You
1008 should turn on as many as possible. With GCC, the switch is
1009 "-Wall". Try and fix as many warnings as possible.</para>
1015 <sect3 id="s37"><title>Provide a default case for all switch
1018 <para><emphasis>Explanation:</emphasis></para>
1020 <para>What you think is guaranteed is never really guaranteed. The
1021 value that you don't think you need to check is the one that
1022 someday will be passed. So, to protect yourself from the
1023 unknown, always have a default step in a switch statement.</para>
1025 <para><emphasis>Example:</emphasis></para>
1027 switch( hash_string( cmd ) )
1029 case hash_actions_file :
1039 ... anomly code goes here ...
1040 continue; / break; / exit( 1 ); / etc ...
1042 } /* end switch( hash_string( cmd ) ) */</programlisting>
1044 <para><emphasis>Note:</emphasis> If you already have a default condition, you
1045 are obviously exempt from this point. Of note, most of the
1046 WIN32 code calls `DefWindowProc' after the switch statement.
1047 This API call *should* be included in a default statement.</para>
1049 <para><emphasis>Another Note:</emphasis> This is not so much a readability issue
1050 as a robust programming issue. The "anomly code goes here" may
1051 be no more than a print to the STDERR stream (as in
1052 load_config). Or it may really be an ABEND condition.</para>
1054 <para><emphasis>Status:</emphasis> Programmer discretion is advised.</para>
1060 <sect3 id="s38"><title>Try to avoid falling through cases in a
1061 switch statement.</title>
1063 <para><emphasis>Explanation:</emphasis></para>
1065 <para>In general, you will want to have a 'break' statement within
1066 each 'case' of a switch statement. This allows for the code to
1067 be more readable and understandable, and furthermore can
1068 prevent unwanted surprises if someone else later gets creative
1069 and moves the code around.</para>
1071 <para>The language allows you to plan the fall through from one
1072 case statement to another simply by omitting the break
1073 statement within the case statement. This feature does have
1074 benefits, but should only be used in rare cases. In general,
1075 use a break statement for each case statement.</para>
1077 <para>If you choose to allow fall through, you should comment both
1078 the fact of the fall through and reason why you felt it was
1085 <sect3 id="s39"><title>Use 'long' or 'short' Instead of
1088 <para><emphasis>Explanation:</emphasis></para>
1090 <para>On 32-bit platforms, int usually has the range of long. On
1091 16-bit platforms, int has the range of short.</para>
1093 <para><emphasis>Status:</emphasis> open-to-debate. In the case of most FSF
1094 projects (including X/GNU-Emacs), there are typedefs to int4,
1095 int8, int16, (or equivalence ... I forget the exact typedefs
1096 now). Should we add these to IJB now that we have a "configure"
1103 <sect3 id="s40"><title>Don't mix size_t and other types</title>
1105 <para><emphasis>Explanation:</emphasis></para>
1107 <para>The type of size_t varies across platforms. Do not make
1108 assumptions about whether it is signed or unsigned, or about
1109 how long it is. Do not compare a size_t against another
1110 variable of a different type (or even against a constant)
1111 without casting one of the values. Try to avoid using size_t if
1118 <sect3 id="s41"><title>Declare each variable and struct on its
1121 <para><emphasis>Explanation:</emphasis></para>
1123 <para>It can be tempting to declare a series of variables all on
1124 one line. Don't.</para>
1126 <para><emphasis>Example:</emphasis></para>
1130 long c = 0;</programlisting>
1132 <para><emphasis>Instead of:</emphasis></para>
1134 <para>long a, b, c;</para>
1136 <para><emphasis>Explanation:</emphasis> - there is more room for comments on the
1137 individual variables - easier to add new variables without
1138 messing up the original ones - when searching on a variable to
1139 find its type, there is less clutter to "visually"
1142 <para><emphasis>Exceptions:</emphasis> when you want to declare a bunch of loop
1143 variables or other trivial variables; feel free to declare them
1144 on 1 line. You should, although, provide a good comment on
1145 their functions.</para>
1147 <para><emphasis>Status:</emphasis> developer-discrection.</para>
1153 <sect3 id="s42"><title>Use malloc/zalloc sparingly</title>
1155 <para><emphasis>Explanation:</emphasis></para>
1157 <para>Create a local stuct (on the stack) if the variable will
1158 live and die within the context of one function call.</para>
1160 <para>Only "malloc" a struct (on the heap) if the variable's life
1161 will extend beyond the context of one function call.</para>
1163 <para><emphasis>Example:</emphasis></para>
1165 If a function creates a struct and stores a pointer to it in a
1166 list, then it should definately be allocated via `malloc'.
1171 <sect3 id="s43"><title>The Programmer Who Uses 'malloc' is
1172 Responsible for Ensuring 'free'</title>
1174 <para><emphasis>Explanation:</emphasis></para>
1176 <para>If you have to "malloc" an instance, you are responsible for
1177 insuring that the instance is `free'd, even if the deallocation
1178 event falls within some other programmer's code. You are also
1179 responsible for ensuring that deletion is timely (i.e. not too
1180 soon, not too late). This is known as "low-coupling" and is a
1181 "good thing (tm)". You may need to offer a
1182 free/unload/destuctor type function to accomodate this.</para>
1184 <para><emphasis>Example:</emphasis></para>
1186 int load_re_filterfile( struct client_state *csp ) { ... }
1187 static void unload_re_filterfile( void *f ) { ... }</programlisting>
1189 <para><emphasis>Exceptions:</emphasis></para>
1191 <para>The developer cannot be expected to provide `free'ing
1192 functions for C run-time library functions ... such as
1195 <para><emphasis>Status:</emphasis> developer-discrection. The "main" use of this
1196 standard is for allocating and freeing data structures (complex
1203 <sect3 id="s44"><title>Add loaders to the `file_list' structure
1204 and in order</title>
1206 <para><emphasis>Explanation:</emphasis></para>
1208 <para>I have ordered all of the "blocker" file code to be in alpha
1209 order. It is easier to add/read new blockers when you expect a
1210 certain order.</para>
1212 <para><emphasis>Note:</emphasis> It may appear that the alpha order is broken in
1213 places by POPUP tests coming before PCRS tests. But since
1214 POPUPs can also be referred to as KILLPOPUPs, it is clear that
1215 it should come first.</para>
1221 <sect3 id="s45"><title>"Uncertain" new code and/or changes to
1222 exitinst code, use FIXME</title>
1224 <para><emphasis>Explanation:</emphasis></para>
1226 <para>If you have enough confidence in new code or confidence in
1227 your changes, but are not *quite* sure of the reprocussions,
1230 <para>/* FIXME: this code has a logic error on platform XYZ, *
1231 attempthing to fix */ #ifdef PLATFORM ...changed code here...
1236 <para>/* FIXME: I think the original author really meant this...
1237 */ ...changed code here...</para>
1241 <para>/* FIXME: new code that *may* break something else... */
1242 ...new code here...</para>
1244 <para><emphasis>Note:</emphasis> If you make it clear that this may or may not
1245 be a "good thing (tm)", it will be easier to identify and
1246 include in the project (or conversly exclude from the
1254 <sect2 id="s46"><title>Addendum: Template for files and function
1255 comment blocks:</title>
1257 <para><emphasis>Example for file comments:</emphasis></para>
1259 const char FILENAME_rcs[] = "$Id: developer-manual.sgml,v 1.14 2002/03/30 19:04:08 swa Exp $";
1260 /*********************************************************************
1262 * File : $S<!-- Break CVS Substitution -->ource$
1264 * Purpose : (Fill me in with a good description!)
1266 * Copyright : Written by and Copyright (C) 2001 the SourceForge
1267 * Privoxy team. http://www.privoxy.org/
1269 * Based on the Internet Junkbuster originally written
1270 * by and Copyright (C) 1997 Anonymous Coders and
1271 * Junkbusters Corporation. http://www.junkbusters.com
1273 * This program is free software; you can redistribute it
1274 * and/or modify it under the terms of the GNU General
1275 * Public License as published by the Free Software
1276 * Foundation; either version 2 of the License, or (at
1277 * your option) any later version.
1279 * This program is distributed in the hope that it will
1280 * be useful, but WITHOUT ANY WARRANTY; without even the
1281 * implied warranty of MERCHANTABILITY or FITNESS FOR A
1282 * PARTICULAR PURPOSE. See the GNU General Public
1283 * License for more details.
1285 * The GNU General Public License should be included with
1286 * this file. If not, you can view it at
1287 * http://www.gnu.org/copyleft/gpl.html
1288 * or write to the Free Software Foundation, Inc., 59
1289 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
1292 * $L<!-- Break CVS Substitution -->og$
1294 *********************************************************************/
1299 ...necessary include files for us to do our work...
1301 const char FILENAME_h_rcs[] = FILENAME_H_VERSION;
1304 <para><emphasis>Note:</emphasis> This declares the rcs variables that should be
1305 added to the "show-proxy-args" page. If this is a brand new
1306 creation by you, you are free to change the "Copyright" section
1307 to represent the rights you wish to maintain.</para>
1309 <para><emphasis>Note:</emphasis> The formfeed character that is present right
1310 after the comment flower box is handy for (X|GNU)Emacs users to
1311 skip the verbige and get to the heart of the code (via
1312 `forward-page' and `backward-page'). Please include it if you
1315 <para><emphasis>Example for file header comments:</emphasis></para>
1319 #define FILENAME_H_VERSION "$Id: developer-manual.sgml,v 1.14 2002/03/30 19:04:08 swa Exp $"
1320 /*********************************************************************
1322 * File : $S<!-- Break CVS Substitution -->ource$
1324 * Purpose : (Fill me in with a good description!)
1326 * Copyright : Written by and Copyright (C) 2001 the SourceForge
1327 * Privoxy team. http://www.privoxy.org/
1329 * Based on the Internet Junkbuster originally written
1330 * by and Copyright (C) 1997 Anonymous Coders and
1331 * Junkbusters Corporation. http://www.junkbusters.com
1333 * This program is free software; you can redistribute it
1334 * and/or modify it under the terms of the GNU General
1335 * Public License as published by the Free Software
1336 * Foundation; either version 2 of the License, or (at
1337 * your option) any later version.
1339 * This program is distributed in the hope that it will
1340 * be useful, but WITHOUT ANY WARRANTY; without even the
1341 * implied warranty of MERCHANTABILITY or FITNESS FOR A
1342 * PARTICULAR PURPOSE. See the GNU General Public
1343 * License for more details.
1345 * The GNU General Public License should be included with
1346 * this file. If not, you can view it at
1347 * http://www.gnu.org/copyleft/gpl.html
1348 * or write to the Free Software Foundation, Inc., 59
1349 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
1352 * $L<!-- Break CVS Substitution -->og$
1354 *********************************************************************/
1357 #include "project.h"
1363 ... function headers here ...
1366 /* Revision control strings from this header and associated .c file */
1367 extern const char FILENAME_rcs[];
1368 extern const char FILENAME_h_rcs[];
1375 #endif /* ndef _FILENAME_H */
1384 <para><emphasis>Example for function comments:</emphasis></para>
1386 /*********************************************************************
1388 * Function : FUNCTION_NAME
1390 * Description : (Fill me in with a good description!)
1393 * 1 : param1 = pointer to an important thing
1394 * 2 : x = pointer to something else
1396 * Returns : 0 => Ok, everything else is an error.
1398 *********************************************************************/
1399 int FUNCTION_NAME( void *param1, const char *x )
1407 <para><emphasis>Note:</emphasis> If we all follow this practice, we should be
1408 able to parse our code to create a "self-documenting" web
1415 <!-- ~~~~~ New section ~~~~~ -->
1416 <sect1 id="cvs"><title>Version Control Guidelines</title>
1417 <para>To be filled. note on cvs comments. don't comment what you did, comment
1422 <!-- ~~~~~ New section ~~~~~ -->
1423 <sect1 id="testing"><title>Testing Guidelines</title>
1427 <!-- ~~~~~ New section ~~~~~ -->
1428 <sect2 id="testing-plan"><title>Testplan for releases</title>
1430 Explain release numbers. major, minor. developer releases. etc.
1432 <orderedlist numeration="arabic">
1434 Remove any existing rpm with rpm -e
1437 Remove any file that was left over. This includes (but is not limited to)
1439 <listitem><para>/var/log/privoxy</para></listitem>
1440 <listitem><para>/etc/privoxy</para></listitem>
1441 <listitem><para>/usr/sbin/privoxy</para></listitem>
1442 <listitem><para>/etc/init.d/privoxy</para></listitem>
1443 <listitem><para>/usr/doc/privoxy*</para></listitem>
1447 Install the rpm. Any error messages?
1449 <listitem><para>start,stop,status <application>Privoxy</application> with the specific script
1450 (e.g. /etc/rc.d/init/privoxy stop). Reboot your machine. Does
1451 autostart work?</para></listitem>
1452 <listitem><para>Start browsing. Does <application>Privoxy</application> work? Logfile written?</para></listitem>
1453 <listitem><para>Remove the rpm. Any error messages? All files removed?</para></listitem>
1458 <!-- ~~~~~ New section ~~~~~ -->
1459 <sect2 id="testing-report"><title>Test reports</title>
1461 Please submit test reports only with the <ulink url="http://sourceforge.net/tracker/?func=add&group_id=11118&atid=395005">test form</ulink>
1462 at sourceforge. Three simple steps:
1465 <listitem><para>Select category: the distribution you test on.</para></listitem>
1466 <listitem><para>Select group: the version of <application>Privoxy</application> that we are about to release.</para></listitem>
1467 <listitem><para>Fill the Summary and Detailed Description with something
1468 intelligent (keep it short and precise).</para>
1471 Do not mail to the mailinglist (we cannot keep track on issues there).
1477 <!-- ~~~~~ New section ~~~~~ -->
1478 <sect1 id="newrelease"><title>Releasing a new version</title>
1480 To minimize trouble with distribution contents, webpage
1481 errors and the like, I (Stefan) strongly encourage you
1482 to follow this section if you prepare a new release of
1483 code or new pages on the webserver.
1486 The following programs are required to follow this process:
1487 <filename>ncftpput</filename> (ncftp), <filename>scp</filename> (ssh),
1488 <filename>gmake</filename> (GNU's version of make), ???.
1490 <sect2 id="newrelease-web"><title>Update the webserver</title>
1492 All files must be group-readable and group-writable (or no one else
1493 will be able to change them). To update the webserver, create any
1494 pages locally in the <filename>doc/webserver</filename> directory (or
1495 create new directories under <filename>doc/webserver</filename>), then do
1503 Note that <filename>make dok</filename> creates
1504 <filename>doc/webserver/user-manual</filename>,
1505 <filename>doc/webserver/developer-manual</filename>,
1506 <filename>doc/webserver/faq</filename> and
1507 <filename>doc/webserver/man-page</filename> automatically.
1510 Verify on the webserver that the permissions are set correctly. Do
1511 NOT use any other means of transferring files to the webserver.
1515 <sect2 id="newrelease-rpm"><title>SuSE or RedHat</title>
1517 Ensure that you have the latest code version. Hence run
1525 first. If necessary, change the version number of
1526 <application>Privoxy</application> in the
1527 <filename>configure.in</filename> file. Update the release number
1528 directly in the specific spec file (particularly, set the release
1529 number to <filename>1</filename> if you have increased the version
1534 autoheader && autoconf && ./configure
1542 make suse-dist or make redhat-dist
1546 To upload the package to Sourceforge, simply issue
1550 make suse-upload or make redhat-upload
1554 Goto the displayed URL and release the file publically on Sourceforge.
1558 <sect2 id="newrelease-os2"><title>OS/2</title>
1560 Ensure that you have the latest code version. Hence run
1568 first. If necessary, change the version number of
1569 <application>Privoxy</application> in the
1570 <filename>configure.in</filename> file. Run
1574 autoheader && autoconf && ./configure
1582 <sect2 id="newrelease-solaris"><title>Solaris</title>
1584 Login to Sourceforge's compilefarm via ssh
1588 ssh cf.sourceforge.net
1592 Choose the right operating system (not the Debian one). If you have
1593 downloaded Privoxy before,
1597 cd current && cvs update .
1601 If not, please <ulink
1602 url="http://www.privoxy.org/user-manual/user-manual/installation.html#INSTALLATION-SOURCE">checkout
1603 Privoxy via CVS first</ulink>. Verify the version number in
1604 <filename>configure.in</filename>. If necessary, change the version
1609 autoheader && autoconf && ./configure
1621 which creates a gzip'ed tar archive. Sadly, you cannot use <filename>make
1622 solaris-upload</filename> on the Sourceforge machine (no ncftpput). You now have
1623 to manually upload the archive to Sourceforge's ftp server and release
1628 <sect2 id="newrelease-windows"><title>Windows</title>
1630 Ensure that you have the latest code version. Hence run
1638 first. If necessary, change the version number of
1639 <application>Privoxy</application> in the
1640 <filename>configure.in</filename> file. Run
1644 autoheader && autoconf && ./configure
1652 <sect2 id="newrelease-debian"><title>Debian</title>
1654 Ensure that you have the latest code version. Hence run
1662 first. If necessary, change the version number of
1663 <application>Privoxy</application> in the
1664 <filename>configure.in</filename> file. Run
1668 autoheader && autoconf && ./configure
1676 <sect2 id="newrelease-macosx"><title>Mac OSX</title>
1678 Login to Sourceforge's compilefarm via ssh
1682 ssh cf.sourceforge.net
1686 Choose the right operating system. If you have downloaded Privoxy
1691 cd current && cvs update .
1695 If not, please <ulink
1696 url="http://www.privoxy.org/user-manual/user-manual/installation.html#INSTALLATION-SOURCE">checkout
1697 Privoxy via CVS first</ulink>. Verify the version number in
1698 <filename>configure.in</filename>. If necessary, change the version
1703 autoheader && autoconf && ./configure
1715 which creates a gzip'ed tar archive. Sadly, you cannot use <filename>make
1716 macosx-upload</filename> on the Sourceforge machine (no ncftpput). You now have
1717 to manually upload the archive to Sourceforge's ftp server and release
1722 <sect2 id="newrelease-freebsd"><title>FreeBSD</title>
1724 Change the version number of <application>Privoxy</application> in the
1725 configure.in file. Run
1727 autoheader && autoconf && ./configure
1732 Login to Sourceforge's compilefarm via ssh
1736 ssh cf.sourceforge.net
1740 Choose the right operating system. If you have downloaded Privoxy
1745 cd current && cvs update .
1749 If not, please <ulink
1750 url="http://www.privoxy.org/user-manual/user-manual/installation.html#INSTALLATION-SOURCE">checkout
1751 Privoxy via CVS first</ulink>. Verify the version number in
1752 <filename>configure.in</filename>. If necessary, change the version
1757 autoheader && autoconf && ./configure
1769 which creates a gzip'ed tar archive. Sadly, you cannot use <filename>make
1770 freebsd-upload</filename> on the Sourceforge machine (no ncftpput). You now have
1771 to manually upload the archive to Sourceforge's ftp server and release
1776 <sect2 id="newrelease-tarball"><title>Tarball</title>
1778 Ensure that you have the latest code version. Hence run
1786 first. If necessary, change the version number of
1787 <application>Privoxy</application> in the
1788 <filename>configure.in</filename> file. Run
1793 autoheader && autoconf && ./configure
1805 To upload the package to Sourceforge, simply issue
1813 Goto the displayed URL and release the file publically on Sourceforge.
1817 <sect2 id="newrelease-hpux"><title>HP-UX 11</title>
1819 Ensure that you have the latest code version. Hence run
1827 first. If necessary, change the version number of
1828 <application>Privoxy</application> in the
1829 <filename>configure.in</filename> file. Run
1833 autoheader && autoconf && ./configure
1841 <sect2 id="newrelease-amiga"><title>Amiga OS</title>
1843 Ensure that you have the latest code version. Hence run
1851 first. If necessary, change the version number of
1852 <application>Privoxy</application> in the
1853 <filename>configure.in</filename> file. Run
1857 autoheader && autoconf && ./configure
1865 <sect2 id="newrelease-aix"><title>AIX</title>
1867 Login to Sourceforge's compilefarm via ssh
1871 ssh cf.sourceforge.net
1875 Choose the right operating system. If you have downloaded Privoxy
1880 cd current && cvs update .
1884 If not, please <ulink
1885 url="http://www.privoxy.org/user-manual/user-manual/installation.html#INSTALLATION-SOURCE">checkout
1886 Privoxy via CVS first</ulink>. Verify the version number in
1887 <filename>configure.in</filename>. If necessary, change the version
1892 autoheader && autoconf && ./configure
1904 which creates a gzip'ed tar archive. Sadly, you cannot use <filename>make
1905 aix-upload</filename> on the Sourceforge machine (no ncftpput). You now have
1906 to manually upload the archive to Sourceforge's ftp server and release
1913 <!-- ~~~~~ New section ~~~~~ -->
1914 <sect1 id="contact"><title>Contact the developers</title>
1915 <para>Please see the user manual for information on how to contact the developers.
1919 <!-- ~~~~~ New section ~~~~~ -->
1920 <sect1 id="copyright"><title>Copyright and History</title>
1921 <para>Please see the user manual for information on Copyright and History.
1925 <!-- ~~~~~ New section ~~~~~ -->
1926 <sect1 id="seealso"><title>See also</title>
1927 <para>Please see the user manual for information on references.
1933 This program is free software; you can redistribute it
1934 and/or modify it under the terms of the GNU General
1935 Public License as published by the Free Software
1936 Foundation; either version 2 of the License, or (at
1937 your option) any later version.
1939 This program is distributed in the hope that it will
1940 be useful, but WITHOUT ANY WARRANTY; without even the
1941 implied warranty of MERCHANTABILITY or FITNESS FOR A
1942 PARTICULAR PURPOSE. See the GNU General Public
1943 License for more details.
1945 The GNU General Public License should be included with
1946 this file. If not, you can view it at
1947 http://www.gnu.org/copyleft/gpl.html
1948 or write to the Free Software Foundation, Inc., 59
1949 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
1951 $Log: developer-manual.sgml,v $
1952 Revision 1.14 2002/03/30 19:04:08 swa
1953 people release differently. no good.
1954 I want to make parts of the docs only.
1956 Revision 1.13 2002/03/27 01:16:41 hal9
1959 Revision 1.12 2002/03/27 01:02:51 hal9
1960 Touch up on name change...
1962 Revision 1.11 2002/03/26 22:29:55 swa
1963 we have a new homepage!
1965 Revision 1.10 2002/03/24 12:33:01 swa
1968 Revision 1.9 2002/03/24 11:01:05 swa
1971 Revision 1.8 2002/03/23 15:13:11 swa
1972 renamed every reference to the old name with foobar.
1973 fixed "application foobar application" tag, fixed
1974 "the foobar" with "foobar". left junkbustser in cvs
1975 comments and remarks to history untouched.
1977 Revision 1.7 2002/03/11 13:13:27 swa
1978 correct feedback channels
1980 Revision 1.6 2002/02/24 14:25:06 jongfoster
1981 Formatting changes. Now changing the doctype to DocBook XML 4.1
1982 will work - no other changes are needed.
1984 Revision 1.5 2001/10/31 18:16:51 swa
1985 documentation added: howto generate docs in text and html
1986 format, howto move stuff to the webserver.
1988 Revision 1.4 2001/09/23 10:13:48 swa
1989 upload process established. run make webserver and
1990 the documentation is moved to the webserver. documents
1991 are now linked correctly.
1993 Revision 1.3 2001/09/13 15:27:40 swa
1996 Revision 1.2 2001/09/13 15:20:17 swa
1997 merged standards into developer manual
1999 Revision 1.1 2001/09/12 15:36:41 swa
2000 source files for junkbuster documentation
2002 Revision 1.3 2001/09/10 17:43:59 swa
2003 first proposal of a structure.
2005 Revision 1.2 2001/06/13 14:28:31 swa
2006 docs should have an author.
2008 Revision 1.1 2001/06/13 14:20:37 swa
2009 first import of project's documentation for the webserver.