summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorGerald Carter <jerry@samba.org>2002-10-25 15:32:51 +0000
committerGerald Carter <jerry@samba.org>2002-10-25 15:32:51 +0000
commit19889a016d33a5fe80bedfd5e97f0c0bb63151a7 (patch)
treece8a06c9263a65bbf6034a9c609d9ddaf2f1fd74 /source3
parentfe959cb156b9e904c796e5eb939590368f0c1292 (diff)
downloadsamba-19889a016d33a5fe80bedfd5e97f0c0bb63151a7.tar.gz
samba-19889a016d33a5fe80bedfd5e97f0c0bb63151a7.tar.bz2
samba-19889a016d33a5fe80bedfd5e97f0c0bb63151a7.zip
sync with HEAD some more....
(This used to be commit 6cb494d34e54aa551deaed1175bf038b027b8f1d)
Diffstat (limited to 'source3')
-rw-r--r--source3/CodingSuggestions160
-rw-r--r--source3/parsing.doc363
2 files changed, 0 insertions, 523 deletions
diff --git a/source3/CodingSuggestions b/source3/CodingSuggestions
deleted file mode 100644
index 5e99bc54ca..0000000000
--- a/source3/CodingSuggestions
+++ /dev/null
@@ -1,160 +0,0 @@
-/**
-
-@page CodingSuggestions Coding suggestions
-
-So you want to add code to Samba ...
-
-One of the daunting tasks facing a programmer attempting to write code for
-Samba is understanding the various coding conventions used by those most
-active in the project. These conventions were mostly unwritten and helped
-improve either the portability, stability or consistency of the code. This
-document will attempt to document a few of the more important coding
-practices used at this time on the Samba project. The coding practices are
-expected to change slightly over time, and even to grow as more is learned
-about obscure portability considerations. Two existing documents
-samba/source/internals.doc and samba/source/architecture.doc provide
-additional information.
-
-The loosely related question of coding style is very personal and this
-document does not attempt to address that subject, except to say that I
-have observed that eight character tabs seem to be preferred in Samba
-source. If you are interested in the topic of coding style, two oft-quoted
-documents are:
-
- http://lxr.linux.no/source/Documentation/CodingStyle
- http://www.fsf.org/prep/standards_toc.html
-
-but note that coding style in Samba varies due to the many different
-programmers who have contributed.
-
-The indent utility can be used to format C files in the general
-samba coding style. The arguments you should give to indent are:
--bad -bap -br -ce -cdw -nbc -brs -bbb -nbc -npsl -ut -i8
-
-Following are some considerations you should use when adding new code to
-Samba. First and foremost remember that:
-
-Portability is a primary consideration in adding function, as is network
-compatability with de facto, existing, real world CIFS/SMB implementations.
-There are lots of platforms that Samba builds on so use caution when adding
-a call to a library function that is not invoked in existing Samba code.
-Also note that there are many quite different SMB/CIFS clients that Samba
-tries to support, not all of which follow the SNIA CIFS Technical Reference
-(or the earlier Microsoft reference documents or the X/Open book on the SMB
-Standard) perfectly.
-
-Here are some other suggestions:
-
-1) use d_printf instead of printf for display text
- reason: enable auto-substitution of translated language text
-
-2) use SAFE_FREE instead of free
- reason: reduce traps due to null pointers
-
-3) don't use bzero use memset, or ZERO_STRUCT and ZERO_STRUCTP macros
- reason: not POSIX
-
-4) don't use strcpy and strlen (use safe_* equivalents)
- reason: to avoid traps due to buffer overruns
-
-5) don't use getopt_long, use popt functions instead
- reason: portability
-
-6) explicitly add const qualifiers on parm passing in functions where parm
- is input only (somewhat controversial but const can be #defined away)
-
-7) when passing a va_list as an arg, or assigning one to another
- please use the VA_COPY() macro
- reason: on some platforms, va_list is a struct that must be
- initialized in each function...can SEGV if you don't.
-
-8) discourage use of threads
- reason: portability (also see architecture.doc)
-
-9) don't explicitly include new header files in C files - new h files
- should be included by adding them once to includes.h
- reason: consistency
-
-10) don't explicitly extern functions (they are autogenerated by
- "make proto" into proto.h)
- reason: consistency
-
-11) use endian safe macros when unpacking SMBs (see byteorder.h and
- internals.doc)
- reason: not everyone uses Intel
-
-12) Note Unicode implications of charset handling (see internals.doc). See
- pull_* and push_* and convert_string functions.
- reason: Internationalization
-
-13) Don't assume English only
- reason: See above
-
-14) Try to avoid using in/out parameters (functions that return data which
- overwrites input parameters)
- reason: Can cause stability problems
-
-15) Ensure copyright notices are correct, don't append Tridge's name to code
- that he didn't write. If you did not write the code, make sure that it
- can coexist with the rest of the Samba GPLed code.
-
-16) Consider usage of DATA_BLOBs for length specified byte-data.
- reason: stability
-
-17) Take advantage of tdbs for database like function
- reason: consistency
-
-18) Don't access the SAM_ACCOUNT structure directly, they should be accessed
- via pdb_get...() and pdb_set...() functions.
- reason: stability, consistency
-
-19) Don't check a password directly against the passdb, always use the
- check_password() interface.
- reason: long term pluggability
-
-20) Try to use asprintf rather than pstrings and fstrings where possible
-
-21) Use normal C comments / * instead of C++ comments // like
- this. Although the C++ comment format is part of the C99
- standard, some older vendor C compilers do not accept it.
-
-22) Try to write documentation for API functions and structures
- explaining the point of the code, the way it should be used, and
- any special conditions or results. Mark these with a double-star
- comment start / ** so that they can be picked up by Doxygen, as in
- this file.
-
-23) Keep the scope narrow. This means making functions/variables
- static whenever possible. We don't want our namespace
- polluted. Each module should have a minimal number of externally
- visible functions or variables.
-
-24) Use function pointers to keep knowledge about particular pieces of
- code isolated in one place. We don't want a particular piece of
- functionality to be spread out across lots of places - that makes
- for fragile, hand to maintain code. Instead, design an interface
- and use tables containing function pointers to implement specific
- functionality. This is particularly important for command
- interpreters.
-
-25) Think carefully about what it will be like for someone else to add
- to and maintain your code. If it would be hard for someone else to
- maintain then do it another way.
-
-26) Always keep the declaration of a function on one line. The autoprototyper
- doesn't catch declarations spread over multiple lines.
- Use:
-static char foo(int bar)
- and not:
-static char
-foo(int bar)
-
-The suggestions above are simply that, suggestions, but the information may
-help in reducing the routine rework done on new code. The preceeding list
-is expected to change routinely as new support routines and macros are
-added.
-
-Written by Steve French, with contributions from Simo Sorce, Andrew
-Bartlett, Tim Potter, Martin Pool and Jelmer Vernooij.
-
-**/
diff --git a/source3/parsing.doc b/source3/parsing.doc
deleted file mode 100644
index d26a64ae4e..0000000000
--- a/source3/parsing.doc
+++ /dev/null
@@ -1,363 +0,0 @@
-Chris Hertel, Samba Team
-November 1997
-
-This is a quick overview of the lexical analysis, syntax, and semantics
-of the smb.conf file.
-
-Lexical Analysis:
-
- Basically, the file is processed on a line by line basis. There are
- four types of lines that are recognized by the lexical analyzer
- (params.c):
-
- Blank lines - Lines containing only whitespace.
- Comment lines - Lines beginning with either a semi-colon or a
- pound sign (';' or '#').
- Section header lines - Lines beginning with an open square bracket
- ('[').
- Parameter lines - Lines beginning with any other character.
- (The default line type.)
-
- The first two are handled exclusively by the lexical analyzer, which
- ignores them. The latter two line types are scanned for
-
- - Section names
- - Parameter names
- - Parameter values
-
- These are the only tokens passed to the parameter loader
- (loadparm.c). Parameter names and values are divided from one
- another by an equal sign: '='.
-
-
- Handling of Whitespace:
-
- Whitespace is defined as all characters recognized by the isspace()
- function (see ctype(3C)) except for the newline character ('\n')
- The newline is excluded because it identifies the end of the line.
-
- - The lexical analyzer scans past white space at the beginning of a
- line.
-
- - Section and parameter names may contain internal white space. All
- whitespace within a name is compressed to a single space character.
-
- - Internal whitespace within a parameter value is kept verbatim with
- the exception of carriage return characters ('\r'), all of which
- are removed.
-
- - Leading and trailing whitespace is removed from names and values.
-
-
- Handling of Line Continuation:
-
- Long section header and parameter lines may be extended across
- multiple lines by use of the backslash character ('\\'). Line
- continuation is ignored for blank and comment lines.
-
- If the last (non-whitespace) character within a section header or on
- a parameter line is a backslash, then the next line will be
- (logically) concatonated with the current line by the lexical
- analyzer. For example:
-
- param name = parameter value string \
- with line continuation.
-
- Would be read as
-
- param name = parameter value string with line continuation.
-
- Note that there are five spaces following the word 'string',
- representing the one space between 'string' and '\\' in the top
- line, plus the four preceeding the word 'with' in the second line.
- (Yes, I'm counting the indentation.)
-
- Line continuation characters are ignored on blank lines and at the end
- of comments. They are *only* recognized within section and parameter
- lines.
-
-
- Line Continuation Quirks:
-
- Note the following example:
-
- param name = parameter value string \
- \
- with line continuation.
-
- The middle line is *not* parsed as a blank line because it is first
- concatonated with the top line. The result is
-
- param name = parameter value string with line continuation.
-
- The same is true for comment lines.
-
- param name = parameter value string \
- ; comment \
- with a comment.
-
- This becomes:
-
- param name = parameter value string ; comment with a comment.
-
- On a section header line, the closing bracket (']') is considered a
- terminating character, and the rest of the line is ignored. The lines
-
- [ section name ] garbage \
- param name = value
-
- are read as
-
- [section name]
- param name = value
-
-
-
-Syntax:
-
- The syntax of the smb.conf file is as follows:
-
- <file> :== { <section> } EOF
-
- <section> :== <section header> { <parameter line> }
-
- <section header> :== '[' NAME ']'
-
- <parameter line> :== NAME '=' VALUE NL
-
-
- Basically, this means that
-
- - a file is made up of zero or more sections, and is terminated by
- an EOF (we knew that).
-
- - A section is made up of a section header followed by zero or more
- parameter lines.
-
- - A section header is identified by an opening bracket and
- terminated by the closing bracket. The enclosed NAME identifies
- the section.
-
- - A parameter line is divided into a NAME and a VALUE. The *first*
- equal sign on the line separates the NAME from the VALUE. The
- VALUE is terminated by a newline character (NL = '\n').
-
-
-About params.c:
-
- The parsing of the config file is a bit unusual if you are used to
- lex, yacc, bison, etc. Both lexical analysis (scanning) and parsing
- are performed by params.c. Values are loaded via callbacks to
- loadparm.c.
-
---------------------------------------------------------------------------
-
- Samba DEBUG
-
-Chris Hertel, Samba Team
-July, 1998
-
- Here's the scoop on the update to the DEBUG() system.
-
- First, my goals are:
- * Backward compatibility (ie., I don't want to break any Samba code
- that already works).
- * Debug output should be timestamped and easy to read (format-wise).
- * Debug output should be parsable by software.
- * There should be convenient tools for composing debug messages.
-
- NOTE: the Debug functionality has been moved from util.c to the new
- debug.c module.
-
-New Output Syntax
-
- The syntax of a debugging log file is represented as:
- <debugfile> :== { <debugmsg> }
-
- <debugmsg> :== <debughdr> '\n' <debugtext>
-
- <debughdr> :== '[' TIME ',' LEVEL ']' FILE ':' [FUNCTION] '(' LINE ')'
-
- <debugtext> :== { <debugline> }
-
- <debugline> :== TEXT '\n'
-
- TEXT is a string of characters excluding the newline character.
- LEVEL is the DEBUG level of the message (an integer in the range
- 0..10).
- TIME is a timestamp.
- FILE is the name of the file from which the debug message was
- generated.
- FUNCTION is the function from which the debug message was generated.
- LINE is the line number of the debug statement that generated the
- message.
-
- Basically, what that all means is:
- * A debugging log file is made up of debug messages.
- * Each debug message is made up of a header and text. The header is
- separated from the text by a newline.
- * The header begins with the timestamp and debug level of the
- message enclosed in brackets. The filename, function, and line
- number at which the message was generated follow. The filename is
- terminated by a colon, and the function name is terminated by the
- parenthesis which contain the line number. Depending upon the
- compiler, the function name may be missing (it is generated by the
- __FUNCTION__ macro, which is not universally implemented, dangit).
- * The message text is made up of zero or more lines, each terminated
- by a newline.
-
- Here's some example output:
-
- [1998/08/03 12:55:25, 1] nmbd.c:(659)
- Netbios nameserver version 1.9.19-prealpha started.
- Copyright Andrew Tridgell 1994-1997
- [1998/08/03 12:55:25, 3] loadparm.c:(763)
- Initializing global parameters
-
- Note that in the above example the function names are not listed on
- the header line. That's because the example above was generated on an
- SGI Indy, and the SGI compiler doesn't support the __FUNCTION__ macro.
-
-The DEBUG() Macro
-
- Use of the DEBUG() macro is unchanged. DEBUG() takes two parameters.
- The first is the message level, the second is the body of a function
- call to the Debug1() function.
-
- That's confusing.
-
- Here's an example which may help a bit. If you would write
-
- printf( "This is a %s message.\n", "debug" );
-
- to send the output to stdout, then you would write
-
- DEBUG( 0, ( "This is a %s message.\n", "debug" ) );
-
- to send the output to the debug file. All of the normal printf()
- formatting escapes work.
-
- Note that in the above example the DEBUG message level is set to 0.
- Messages at level 0 always print. Basically, if the message level is
- less than or equal to the global value DEBUGLEVEL, then the DEBUG
- statement is processed.
-
- The output of the above example would be something like:
-
- [1998/07/30 16:00:51, 0] file.c:function(128)
- This is a debug message.
-
- Each call to DEBUG() creates a new header *unless* the output produced
- by the previous call to DEBUG() did not end with a '\n'. Output to the
- debug file is passed through a formatting buffer which is flushed
- every time a newline is encountered. If the buffer is not empty when
- DEBUG() is called, the new input is simply appended.
-
- ...but that's really just a Kludge. It was put in place because
- DEBUG() has been used to write partial lines. Here's a simple (dumb)
- example of the kind of thing I'm talking about:
-
- DEBUG( 0, ("The test returned " ) );
- if( test() )
- DEBUG(0, ("True") );
- else
- DEBUG(0, ("False") );
- DEBUG(0, (".\n") );
-
- Without the format buffer, the output (assuming test() returned true)
- would look like this:
-
- [1998/07/30 16:00:51, 0] file.c:function(256)
- The test returned
- [1998/07/30 16:00:51, 0] file.c:function(258)
- True
- [1998/07/30 16:00:51, 0] file.c:function(261)
- .
-
- Which isn't much use. The format buffer kludge fixes this problem.
-
-The DEBUGADD() Macro
-
- In addition to the kludgey solution to the broken line problem
- described above, there is a clean solution. The DEBUGADD() macro never
- generates a header. It will append new text to the current debug
- message even if the format buffer is empty. The syntax of the
- DEBUGADD() macro is the same as that of the DEBUG() macro.
-
- DEBUG( 0, ("This is the first line.\n" ) );
- DEBUGADD( 0, ("This is the second line.\nThis is the third line.\n" ) );
-
- Produces
- [1998/07/30 16:00:51, 0] file.c:function(512)
- This is the first line.
- This is the second line.
- This is the third line.
-
-The DEBUGLVL() Macro
-
- One of the problems with the DEBUG() macro was that DEBUG() lines
- tended to get a bit long. Consider this example from
- nmbd_sendannounce.c:
-
- DEBUG(3,("send_local_master_announcement: type %x for name %s on subnet %s for workgroup %s\n",
- type, global_myname, subrec->subnet_name, work->work_group));
-
- One solution to this is to break it down using DEBUG() and DEBUGADD(),
- as follows:
-
- DEBUG( 3, ( "send_local_master_announcement: " ) );
- DEBUGADD( 3, ( "type %x for name %s ", type, global_myname ) );
- DEBUGADD( 3, ( "on subnet %s ", subrec->subnet_name ) );
- DEBUGADD( 3, ( "for workgroup %s\n", work->work_group ) );
-
- A similar, but arguably nicer approach is to use the DEBUGLVL() macro.
- This macro returns True if the message level is less than or equal to
- the global DEBUGLEVEL value, so:
-
- if( DEBUGLVL( 3 ) )
- {
- dbgtext( "send_local_master_announcement: " );
- dbgtext( "type %x for name %s ", type, global_myname );
- dbgtext( "on subnet %s ", subrec->subnet_name );
- dbgtext( "for workgroup %s\n", work->work_group );
- }
-
- (The dbgtext() function is explained below.)
-
- There are a few advantages to this scheme:
- * The test is performed only once.
- * You can allocate variables off of the stack that will only be used
- within the DEBUGLVL() block.
- * Processing that is only relevant to debug output can be contained
- within the DEBUGLVL() block.
-
-New Functions
-
- dbgtext()
- This function prints debug message text to the debug file (and
- possibly to syslog) via the format buffer. The function uses a
- variable argument list just like printf() or Debug1(). The
- input is printed into a buffer using the vslprintf() function,
- and then passed to format_debug_text().
-
- If you use DEBUGLVL() you will probably print the body of the
- message using dbgtext().
-
- dbghdr()
- This is the function that writes a debug message header.
- Headers are not processed via the format buffer. Also note that
- if the format buffer is not empty, a call to dbghdr() will not
- produce any output. See the comments in dbghdr() for more info.
-
- It is not likely that this function will be called directly. It
- is used by DEBUG() and DEBUGADD().
-
- format_debug_text()
- This is a static function in debug.c. It stores the output text
- for the body of the message in a buffer until it encounters a
- newline. When the newline character is found, the buffer is
- written to the debug file via the Debug1() function, and the
- buffer is reset. This allows us to add the indentation at the
- beginning of each line of the message body, and also ensures
- that the output is written a line at a time (which cleans up
- syslog output).