Upgrade 3CX to v18 and get it hosted free!

Asterisk Developer Guidelines

Author image

Disclaimer

From the bug tracking page:

Patch format

The following are not official… These are place-holder suggestions! -JP

It is important that patches be easily applied and maintained so that people can test your code, and it can be easily merged into CVS once tested. Here are some suggestions:

  • Patches should be made against a current, clean CVS checkout.
  • Patches should be made recursively against the full CVS module that it patches.
    • For instance, a patch that affects asterisk/apps/app_queues, and several files in asterisk/sound should be made against the whole asterisk/ tree.

So, in the above example:

diff -Naur asterisk.old asterisk.new > asterisk-my_descriptive_patch_name-my.patch.version.patch

Assuming that a user has their Asterisk source in /usr/src, this would be applied by:

cp asterisk-my_descriptive_patch_name-my.patch.version.patch /usr/src
cd /usr/src/asterisk
patch -p1 <../asterisk-my_descriptive_patch_name-my.patch.version.patch

Coding Guidelines

NB For the latest info on this, check the file doc/CODING-GUIDELINES in the distribution

  • All code, filenames, function names and comments must be in ENGLISH.
  • Do not declare variables mid-function (e.g. like GNU lets you) since it is harder to read and not portable to GCC 2.95 and others.
  • Don’t annotate your changes with comments like “/* JMG 4/20/04 */”;
  • Comments should explain what the code does, not when something was changed or who changed it.
  • Don’t make unnecessary whitespace changes throughout the code.
  • Don’t use C++ type (//) comments.
  • Try to match the existing formatting of the file you are working on.
  • Functions and variables that are not intended to be global must be declared static.
  • Function calls and arguments should be spaced in a consistent way across the codebase.

Function Calls

 


GOOD: foo(arg1, arg2);
GOOD: foo(arg1,arg2);	/* Acceptable but not preferred */
BAD: foo (arg1, arg2);
BAD: foo( arg1, arg2 );
BAD: foo(arg1, arg2,arg3);

Examples of how code should be formatted

Functions


int foo(int a, char *s)
{
	return 0;
}

If statements


if (foo) {
	bar();
} else {
	blah();
}

Case statements


switch (foo) {
	case BAR:
		blah();
		break;
	case OTHER:
		other();
		break;
}

No nested statements without braces

e.g. no:


for (x=0;x<5;x++)
        if (foo) 
                if (bar)
                        baz();

instead do:


for (x=0;x<5;x++) {
        if (foo) {
                if (bar)
                        baz();
        }
}

Related Posts:

Get 3CX - Absolutely Free!
Link up your team and customers Phone System Live Chat Video Conferencing

Hosted or Self-managed. Up to 10 users free forever. No credit card. Try risk free.

3CX
A 3CX Account with that email already exists. You will be redirected to the Customer Portal to sign in or reset your password if you've forgotten it.