Copyright © 2001 - 2005 SILC Project
SILC Project Website
SILC Toolkit Reference Manual
Index

SILC Toolkit Reference Manual
SILC Core Library
    SILC Authentication Interface
    SILC Message Interface
    SILC Channel Interface
    SILC Command Interface
    SILC Notify Interface
    SILC Status Types
    SILC Modes
    SILC ID Interface
    SILC ID Cache Interface
    SILC Argument Interface
    SILC Attributes Interface
    Packet Protocol Interface
SILC Utility Library
    Basic SILC Types
    SILC Buffer Interface
    SILC Buffer Format Interface
    SILC Hash Table Interface
    SILC Logging Interface
    SILC Memory Interface
    SILC Mutex Interface
    SILC Thread Interface
    SILC Network Interface
    SILC Schedule Interface
    SILC Socket Interface
    SILC Protocol Interface
    SILC Config Interface
    SILC File Util Interface
    SILC String Util Interface
    SILC UTF-8 Interface
    SILC Stringprep Interface
    SILC Util Interface
    SILC List Interface
    SILC Dynamic List Interface
    SILC VCard Interface
    SILC Application Utilities
    SILC MIME Interface
SILC Crypto Library
    Introduction to SILC RNG
    SILC RNG Interface
    SILC Cipher API
    SILC PKCS API
    SILC PKCS#1 API
    SILC Hash Interface
    SILC HMAC Interface
SILC SFTP Library
    SILC SFTP Interface
    SFTP Filesystems Interface
SILC Client Library
    Using SILC Client Library Tutorial
    Arguments for command_reply Client Operation
    SilcStatus Error Arguments in command_reply Client Operation
    Arguments for notify Client Operation
    Unicode and UTF-8 Strings in Client Library
    Client Library Interface Reference
SILC Key Exchange Library
    SILC SKE Interface
    SKE Status Types
    SKE Diffie Hellman Groups
    SKE Payloads
SILC Math Library
    SILC MP Interface
    SILC Math Interface

Resource Links
SILC Project Website
SILC Protocol Documentation
SILC White Paper
SILC FAQs





Programming Conventions
 
The SILC Toolkit has been programmed with a specific programming style that is consistent across all libraries and interfaces. The programming style defines for example naming conventions for functions, structures, macros, enumerations, and other constants.
 
 
Naming Conventions
 
Macros and Defines
 
Macros are always capitalised and include underscores to separate words in the name. All macros start with the "SILC_" prefix. Example:
 
#define SILC_PACKET_PADLEN(__packetlen, __blocklen) \
  SILC_PACKET_DEFAULT_PADLEN - (__packetlen) % \
    ((__blocklen) ? (__blocklen) : SILC_PACKET_DEFAULT_PADLEN)

 
Also other defines (#define) are always capitalised and include underscores to separate words in the name. Also all defines start with the "SILC_" prefix.
 
Structures
 
All structure names begin with "Silc" prefix, and the name is mixed-case, for example: SilcClientConnection, SilcCommandPayload. Many of the structures used in SILC are actually private structures, and application cannot access them directly. In these cases the structures are forward declared in the public header, and the implementation of the structure is in the source file. In these case application does not need to know the contents of the structure, and is usually provided with a helper API to access the structure when needed.
 
In the most of the cases the forward declaration for a structure is pointer, for example:
 
typedef struct SilcClientStruct *SilcClient;
 
Application should always use the type defined pointer instead of the actual structure.
 
Functions
 
Function naming uses the common naming convention used in Toolkit. All functions are always lowercase and they use underscores. The name of the function always starts with prefix "silc_". The name tells what the function do. The name of a function is constructed from following parts:
 
silc_(module)_(function)
 
The (module) is the library, or interface this functions is part of. For example: "cipher", "config", "command", "packet", etc.
 
The (function) is the description of the functionality of the function. For example: "read", "new_id", "register", "find_by_name", etc. Examples:
 
silc_server_packet_send
silc_server_packet_send_to_channel
silc_idcache_del_by_id
silc_schedule_init
silc_protocol_excute_final
silc_buffer_alloc

 
When function registers something the name of the function generally is "silc_function_register" and unregistering is done with "silc_function_unregister". When function allocates something it is "silc_function_alloc" and when freeing it is "silc_function_free". Respectively, with init/uninit functions.
 
Enumerations
 
Enumerations are always capitalised and include underscores to separate words in the name. All enumerations start with the "SILC_" prefix. Also, usually all enumerations are type defined to a specific name which can be used as type for the enumeration. Example:
 
typedef enum {
  SILC_EXAMPLE_ENUM_NONE,
  SILC_EXAMPLE_ENUM_LIST,
  SILC_EXAMPLE_ENUM_STATUS,
} SilcExampleEnum;

 
The naming for the type definition for the enumerations follow the normal naming convention; the name starts with "Silc" prefix and the name is mixed-case.
 
 
Layout
 
Indentation
 
The indendation in the source code is 2 characters, and tabulators are not used. Example piece of code:
 
void silc_client_free(SilcClient client)
{
  if (client) {
    if (client->rng)
      silc_rng_free(client->rng);
    silc_free(client);
  }
}

 
Placing Braces
 
Generally the braces placing the SILC code follows the K&R style; the opening of the brace is put to the last on the line, and the closing brace is on first on its own line, except for functions. Examples:
 
if (condition) {
  silc_something();
  silc_something_more();
}

 
int silc_client_function()
{
  return 0;
}

 
if (condition) {
  something;
  silc_something_more();
} else {
  something_else;
}

 
if (condition) {
  something;
  silc_something_more();
} else if (other_condition) {
  something;
  silc_something_more();
} else {
  something_else;
}

 
Header Files
 
Standard anti-nesting method is used in the header files to avoid multiple inclusion of the header file. Example:
 
#ifndef SILCHEADER_H
#define SILCHEADER_H
...
#endif /* SILCHEADER_H */

 
All public header files have the "silc" prefix in the filename, for example: silcclient.h, silcprivate.h, silcutil.h. There are other header files in the Toolkit as well. Application should not directly include these headers, however if needed it may access them.
 
Every header file also includes a copyright notice.








Copyright © 2001 - 2005 SILC Project
SILC Project Website
SILC Toolkit Reference Manual
Index