· KLDP.org · KLDP.net · KLDP Wiki · KLDP BBS ·
Asterisk Source

Asterisk makefile


* _all: all

* all: cleantest depend asterisk subdirs

* cleantest:
cleantest:
        if cmp -s .cleancount .lastclean ; then echo ; else \
                $(MAKE) clean; cp -f .cleancount .lastclean;\
        fi

* depend:
depend: include/asterisk/version.h .depend defaults.h
        for x in $(SUBDIRS); do $(MAKE) -C $$x depend || exit 1 ; done

* asterisk:
asterisk: $(CYGLOADER) editline/libedit.a db1-ast/libdb1.a stdtime/libtime.a $(OBJS)
        build_tools/make_build_h > include/asterisk/build.h.tmp
        if cmp -s include/asterisk/build.h.tmp include/asterisk/build.h ; then echo ; else \
                mv include/asterisk/build.h.tmp include/asterisk/build.h ; \
        fi
        rm -f include/asterisk/build.h.tmp
        $(CC) -c -o buildinfo.o $(CFLAGS) buildinfo.c
        $(CC) $(DEBUG) $(ASTOBJ) $(ASTLINK) $(OBJS) buildinfo.o $(LIBEDIT) db1-ast/libdb1.a stdtime/libtime.a $(LIBS)
ASTOBJ=-o asterisk
OBJS=io.o sched.o logger.o frame.o loader.o config.o channel.o \
        translate.o file.o say.o pbx.o cli.o md5.o term.o \
        ulaw.o alaw.o callerid.o fskmodem.o image.o app.o \
        cdr.o tdd.o acl.o rtp.o manager.o asterisk.o \
        dsp.o chanvars.o indications.o autoservice.o db.o privacy.o \
        astmm.o enum.o srv.o dns.o aescrypt.o aestab.o aeskey.o \
        utils.o plc.o jitterbuf.o dnsmgr.o devicestate.o \
        netsock.o slinfactory.o ast_expr2.o ast_expr2f.o \
        cryptostub.o

* subdirs:
subdirs:
        for x in $(SUBDIRS); do $(MAKE) -C $$x || exit 1 ; done
  • SUBDIRS=res channels pbx apps codecs formats agi cdr funcs utils stdtime

* 0.2.0
  • case 문에서 default: 에 관련 statement 가 없을 경우, ; 만이라도 넣어야 한다.
  • cli.c:736: error: label at end of compound statement
  • app_directory.c:115: error: label at end of compound statement
  • comma 가 빠졌음.
  • app_adsiprog.c:987: error: syntax error before string constant
  • 1010, 1025, 1065, 1103, 1118, 1135 adsi_process
* upgrade: all bininstall
  • Essentially the same as 'make && make install' but skips over copying certain files like all the sound clips for improved speed.
* mpg123:
  • Will install a version of mpg123 on your system that is tested to be compatible with Asterisk applications such as MP3Player().
* samples: adsi
  • Copies all the stuff from configs/ to /etc/asterisk.
* config:
  • This will copy init.d scripts if you are running a Red Hat or Fedora Core system. If you are using another distribution like Slackware, check asterisk-sources/contrib/init.d for a script that suits your system.
* rpm: __rpm
  • Makes a RPM file.

Asterisk Source


* acl.c
Various sorts of access control
* aescrypt.c
This file contains the code for implementing encryption and decryption
 for AES (Rijndael) for block and key sizes of 16, 24 and 32 bytes. It
 can optionally be replaced by code written in assembler using NASM. For
 further details see the file aesopt.h
* aeskey.c
This file contains the code for implementing the key schedule for AES
 (Rijndael) for block and key sizes of 16, 24, and 32 bytes. See aesopt.h
 for further details including optimisation.
* aestab.c

* alaw.c
u-Law to Signed linear conversion
* app.c
Convenient Application Routines
* ast_expr2.c
Written by Richard Stallman by simplifying the original so called
   ``semantic'' parser.
* ast_expr2f.c

asterisk.c



1.2.

Top level source file for Asterisk  - the Open Source PBX. Implementation
  of PBX core functions and CLI interface.

defaults.h:#define AST_CONFIG_FILE "/etc/asterisk/asterisk.conf"
* ast_readconfig();
  • cfg = ast_config_load(config);
  • files section
    • astctlpermissions, astctlowner, astctlgroup, astctl
  • directories section
    • astetcdir, astspooldir, astvarlibdir, astlogdir
    • astagidir, astrundir, astmoddir
  • options section
    • verbose, timestamp, execincludes, debug, nofork
    • quiet, console, highpriority, initcrypto, nocolor
    • dontwarn, dumpcore, cache_record_files,
    • record_cache_dir, transcode_via_sln,
    • transmit_silence_during_record, maxcalls,
    • maxuser, rungroup
[root@localhost asterisk]# asterisk -nvc
Asterisk 1.2.4, Copyright (C) 1999 - 2006 Digium, Inc. and others.
Created by Mark Spencer <markster@digium.com>
Asterisk comes with ABSOLUTELY NO WARRANTY; type 'show warranty' for details.
This is free software, with components licensed under the GNU General Public
License version 2 and other licenses; you are welcome to redistribute it under
certain conditions. Type 'show license' for details.
=========================================================================
Asterisk Event Logger Started /var/log/asterisk/event_log
Asterisk Dynamic Loader loading preload modules:
Nov 26 13:51:28 NOTICE[11455]: cdr.c:1188 do_reload: CDR simple logging enabled.Asterisk PBX Core Initializing
Registering builtin applications:
 [AbsoluteTimeout]
 [Answer]
 [BackGround]
 [Busy]
 [Congestion]

 [ImportVar]
 [Wait]
 [WaitExten]
Asterisk Dynamic Loader Starting:
 [res_musiconhold.so] => (Music On Hold Resource)
 [res_adsi.so] => (ADSI Resource)
 [res_features.so] => (Call Features Resource)

 [app_url.so] => (Send URL Applications)
 [app_echo.so] => (Simple Echo Application)
Asterisk Ready.
*CLI>
* init_logger()
  • logger.c
  • Asterisk Event Logger Started /var/log/asterisk/event_log
* dnsmgr_init()
  • dnsmgr.c
* load_modules(1)
  • loader.c
  • include/asterisk/module.h
    • #define AST_MODULE_CONFIG "modules.conf"
    • /etc/asterisk/modules.conf
    • modules section 안의 preload 인 module 을 load
  • Asterisk Dynamic Loader loading preload modules:
* ast_channels_init()
  • channel.c
  • ast_cli_register(&cli_show_channeltypes);

* init_manager()
  • manager.c
* ast_cdr_engine_init()
  • cdr.c
  • ast_log(LOG_NOTICE, "CDR simple logging enabled.\n");
* ast_device_state_engine_init()
  • devicestate.c
* ast_rtp_init()
  • rtp.c
* ast_image_init()
  • image.c
* ast_file_init()
  • file.c
* load_pbx()
  • pbx.c
  • Asterisk PBX Core Initializing
  • Registering builtin applications:
    • answer, goto, hangup, background, dtimeout, rtimeout,
    • atimeout, wait, waitexten, setlanguage, resetcdr,
    • setaccount, setamaflags, ringing, progress,
    • congestion, busy, setglobalvar, noop, gotoif,
    • gotoiftime, execiftime, saynumber, saydigits,
    • saycharacters, sayphonetic, setvar_old, importvar
* load_modules(0)
  • loader.c
  • Asterisk Dynamic Loader Starting:
    • /etc/asterisk/modules.conf
    • modules section 안의 load 인 module 을 load
    • autoload 가 yes 면 /usr/lib/asterisk/modules 밑의 모든 모듈을 load
    • 순서는 loadorder 에 의해 res_, pbx_, chan_, 순의 모듈을 먼저 load 함
    • load 되는 순서는 readdir 에 의해 read 되는 순서임.

* init_framer()
  • frame.c
* astdb_init()
  • db.c
* ast_enum_init()
  • enum.c
* dnsmgr_start_refresh()
  • dnsmgr.c
* Asterisk Ready.

astmm.c

Memory Management
* autoservice.c
Automatic channel service routines
* buildinfo.c
Build timestamp variables
* callerid.c
CallerID Generation support
* cdr.c
Call Detail Record API
* channel.c
Channel Management
* chanvers.c
Channel Variables
* cli.c
Standard Command Line Interface
* config.c
Configuration File Parser
* cryptostub.c

* db.c
ASTdb Management
* devicestate.c
Device state management
* dlfcn.c

* dns.c
DNS Support for Asterisk
* dnsmgr.c
Background DNS update manager
* dsp.c
Convenience Signal Processing routines
* enum.c
ENUM Support for Asterisk
* file.c
Generic File Format Support.
* frame.c
Frame manipulation routines
* fskmodem.c
FSK Modulator/Demodulator
* image.c
Image Management
* indications.c
Tone Management
* io.c
I/O Managment (Derived from Cheops-NG)
* jitterbuf.c
jitterbuf: an application-independent jitterbuffer
* loader.c
Module Loader
* logger.c
Asterisk Logger
* manager.c
The Asterisk Management Interface - AMI
* md5.c

* muted.c
Mute Daemon
Specially written for Malcolm Davenport, but I think I'll use it too
 * Connects to the Asterisk Manager Interface, AMI, and listens for events
 * on certain devices. If a phone call is connected to one of the devices (phones)
 * the local sound is muted to a lower volume during the call.
* netsock.c
Network socket handling
* pbx.c
Core PBX routines.
* plc.c
SpanDSP - a series of DSP components for telephony
* poll.c
select(2)-based poll() emulation function for BSD systems.
* privacy.c
Privacy Routines
* rtp.c
Supports RTP and RTCP with Symmetric RTP support for NAT traversal.
* say.c
Say numbers and dates (maybe words one day too)
* sched.c
Scheduler Routines (from cheops-NG)
* slinfactory.c
A machine to gather up arbitrary frames and convert them
to raw slinear on demand.
* srv.c
DNS SRV Record Lookup Support for Asterisk
* strcompat.c
Compatibility functions for strsep and strtoq missing on Solaris
* tdd.c
TTY/TDD Generation support
* term.c
Terminal Routines
* translate.c
Translate via the use of pseudo channels
* ulaw.c
u-Law to Signed linear conversion
* utils.c
Utility functions
These are important for portability and security,
so please use them in favour of other routines.
Please consult the CODING GUIDELINES for more information.

apps

* Where application modules are stored. This document will cover writing your own apps in a later section.
    *  int load_module(void) This function is called when the module is loaded by the Asterisk Core. In this function you need to call functions such as ast_custom_function_register() to let Asterisk know exactly what services your module provides. Return 0 on success and non-zero on failure.
    * int unload_module(void) This function will be called when Asterisk is getting ready to unload your module. In this function, you should unregister any of your modules services and send soft hangups to any channels that are using your module. Return 0 on success, and non-zero upon failure. A failure will indicate to Asterisk that it is not possible at the moment to unload your module.
    * int usecount(void) Returns the number of threads, channels, etc. that are using your module. This will be shown in the output of CLI commands such as show modules. It is your responsibility to keep track of this number and hangup anything using your module upon unload. Asterisk has helper macros for this that will be described later. In some cases, when your module only provides a service for a very short time, you shouldn't need to worry about user counting. For example, pbx_functions.c always returns 0 when usecount(). In modules such as app_dial.c, user counting is very important because channels will spend most of their time under the control the app_dial.so module.
    * char *description(void) Returns a short, description of what the module does. This will be shown in the output of CLI commands such as show modules.
    * int reload(void) *Optional* This is called if someone types reload your_module.so or reload on the command line. This will give you the opportunity to have your module reload and re-cache any external data such as a configuration file. This is a good alternative to unloading and loading a module because any channels using your module will not need to be hung up. Return 0 on success and non-zero on failure.
    * char *key(void) This function should be programmed to return the value of ASTERISK_GPL_KEY which forces you to state that your extension is licensed under the GNU General Public License. If you are using the free edition of Asterisk and your module does not return ASTERISK_GPL_KEY verbatim, the module will not load. This feature was implemented because Asterisk is dual-licensed and needs a safe-guard to ensure that non-free modules written for Business Edition are not linked against the free edition of Asterisk. There will be more about this in the legal section.
* app_voicemail.c
  • vm_exec
    • referenced by load_module(), play_record_review()
    • leave_voicemail(chan, argv0, &leave_options);
  • vm_execmain
    • referenced load_module()
  • vm_box_exists
    • referenced by load_module()
    • find_user(&svm, context, args.mbox)
  • vmauthenticate
    • referenced by load_module()
    • vm_authenticate(chan, mailbox, sizeof(mailbox), &vmus, context, NULL, skipuser, 3, silent)
static char charset[32] = "ISO-8859-1";
sendmail
get_folder
get_folder2
notify_new_message
forward_message
vm_intro_en
vm_instructions
vm_options
vm_authenticate
vm_execmain
load_config
play_record_review

* get_folder2
  • referenced by vm_execmain
  • ast_play_and_wait(chan,fn) 의 결과가 0 에서 9 사이면,
    get_folder(chan,0) 를 call 하는 것을 0 에서 2 사이로 축소시킴.

* int ast_play_and_wait(struct ast_channel *chan, const char *fn);
  • app.c, include/asterisk/app.h
  • Play a stream and wait for a digit,
    returning the digit that was pressed
  • ast_play_and_wait(chan, "vm-tocancel")
    vm_tocancel.gsm file in /var/lib/asterisk/sounds
* static char *mbox(int id)
  • return "INBOX", Old, Work, Family, Friends,
  • Cust1, Cust2, Cust3, Cust4, Cust5, Unknown

adsi_logo, adsi_load_vmail, adsi_begin, adsi_login
adsi_password, adsi_folders, adsi_message, adsi_delete
adsi_status, adsi_status2, adsi_clear, adsi_goodbye
res/res_adsi.c
include/asterisk/adsi.h

channels

* This is where the source lies for defining channel protocols such as SIP and IAX2. These modules register the channel protocol (known by Asterisk terminology as a "switch") with pbx.c by calling ast_register_switch().

* chan_zap.c
  • zapata.conf
  • ast_setstate(ast, AST_STATE_RINGING);

* channel.h
channel.h:#define AST_STATE_DOWN                0
channel.h:#define AST_STATE_RESERVED    1
channel.h:#define AST_STATE_OFFHOOK     2
channel.h:#define AST_STATE_DIALING     3
channel.h:#define AST_STATE_RING                4
channel.h:#define AST_STATE_RINGING     5
channel.h:#define AST_STATE_UP          6
channel.h:#define AST_STATE_BUSY        7
channel.h:#define AST_STATE_DIALING_OFFHOOK     8
channel.h:#define AST_STATE_PRERING       9
channel.h:#define AST_STATE_MUTE                (1 << 16)

* static int zt_call(struct ast_channel *ast, char *rdest, int timeout)
        if ((ast->_state == AST_STATE_BUSY)) {
                p->subs[SUB_REAL].needbusy = 1;
                ast_mutex_unlock(&p->lock);
                return 0;
        }
        if ((ast->_state != AST_STATE_DOWN) && (ast->_state != AST_STATE_RESERVED)) {
                ast_log(LOG_WARNING, "zt_call called on %s, neither down nor reserved\n", ast->name);
                ast_mutex_unlock(&p->lock);
                return -1;
        }

        switch(p->sig) {
        case SIG_FXOLS:
        case SIG_FXOGS:
        case SIG_FXOKS:

                ast_setstate(ast, AST_STATE_RINGING);

        case SIG_FXSLS:
        case SIG_FXSGS:
        case SIG_FXSKS:

                ast_setstate(ast, AST_STATE_DIALING);

        case 0:
                ast_setstate(ast, AST_STATE_UP);
  • FXO card
  • FXS card
* static int zt_answer(struct ast_channel *ast)
        ast_setstate(ast, AST_STATE_UP);

* static struct ast_frame *zt_handle_event(struct ast_channel *ast)

  • zaptel.h
zaptel.h:#define        ZT_EVENT_NONE   0
zaptel.h:#define        ZT_EVENT_ONHOOK 1
zaptel.h:#define        ZT_EVENT_RINGOFFHOOK 2
zaptel.h:#define        ZT_EVENT_WINKFLASH 3
zaptel.h:#define        ZT_EVENT_ALARM  4
zaptel.h:#define        ZT_EVENT_NOALARM 5
zaptel.h:#define ZT_EVENT_ABORT 6
zaptel.h:#define ZT_EVENT_OVERRUN 7
zaptel.h:#define ZT_EVENT_BADFCS 8
zaptel.h:#define ZT_EVENT_DIALCOMPLETE  9
zaptel.h:#define ZT_EVENT_RINGERON 10
zaptel.h:#define ZT_EVENT_RINGEROFF 11
zaptel.h:#define ZT_EVENT_HOOKCOMPLETE 12
zaptel.h:#define ZT_EVENT_BITSCHANGED 13
zaptel.h:#define ZT_EVENT_PULSE_START 14
zaptel.h:#define ZT_EVENT_TIMER_EXPIRED 15
zaptel.h:#define ZT_EVENT_TIMER_PING            16
zaptel.h:#define ZT_EVENT_RINGBEGIN  18
zaptel.h:#define ZT_EVENT_POLARITY  17
zaptel.h:#define ZT_EVENT_PULSEDIGIT (1 << 16)  /* This is OR'd with the digit received */
zaptel.h:#define ZT_EVENT_DTMFDOWN  (1 << 17)   /* Ditto for DTMF key down event */
zaptel.h:#define ZT_EVENT_DTMFUP (1 << 18)      /* Ditto for DTMF key up event */

* static struct ast_frame *__zt_exception(struct ast_channel *ast)


* struct ast_frame *zt_read(struct ast_channel *ast)


* static int zt_indicate(struct ast_channel *chan, int condition)


* static struct ast_channel *zt_new(struct zt_pvt *i, int state, int startpbx, int index, int law, int transfercapability)


* static void *ss_thread(void *data)

codecs

* This is where the source for codecs such as μ-law and GSM are stored. Codecs are encoding and compression algorithms utilized by switches. Although there are many types of switches, they all have the ability to use the same codecs. The core encoding method for Asterisk is AST_FORMAT_SLINEAR, in which non-compressed audio is sampled 8000 times a second, with 16-bit signed samples. Codecs call ast_register_translator() to provide Asterisk with callbacks to translate voice frames from SLINEAR (and others) to and from the codec. Constant IDs for codec formats are stored in asterisk/frame.h as well as a few other random places.

formats

* Formats are very similar to codecs, but they are used to read sound files. All formats register with the Asterisk core by calling ast_format_register().

funcs

* Where custom dial plan function modules are stored. Custom functions are registered with ast_custom_function_register().

res

* Used to store modules that provide core functionality, such as music on hold.

pbx

* Used to store modules that provide core functionality, such as dial-plan configuration.

zaptel

* fxo
  • accept ring signals
  • go on-hook and off-hook
  • send and receive voice signals
* fxs
  • supply power to the connected telephone
  • provide ring signals and dialtone
  • understand whene phne goes on-hook or off-hook
  • send and receive voice signals
* zaptel.c
  • zt_init
    • register_chrdev(ZT_MAJOR, "zaptel", &zt_fops)
  • zt_fops
    • zt_open
    • zt_release
    • zt_ioctl
    • zt_read
    • zt_write
    • zt_poll
* wctdm.c
  • static int __init wctdm_init(void)
    • res = zap_pci_module(&wctdm_driver);
  • wctdm_driver
    • probe: wctdm_init_one
    • remove: __devexit_p(wctdm_remove_one)
    • suspend: NULL
    • resume: NULL
*zaptel.h
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,10)
#define zap_pci_module pci_register_driver
#else
#define zap_pci_module pci_module_init
#endif
* Makefile
  • CONFIG_FILE=$(INSTALL_PREFIX)/etc/zaptel.conf
  • ztcfg
* ztcfg.h
  • #define CONFIG_FILENAME ZAPTEL_CONFIG
  • #define MASTER_DEVICE "/dev/zap/ctl"
* ztcfg
  • loads the contents of zaptel.conf into the zaptel driver
  • /etc/zaptel.conf 에 loadzone = kodefaultzone=ko 로
  • zonedata.c 에 ko 에 해당하는 부분 만들어야 함
  • loadzone, defaultzone 의 값을 찾아, ioctl 을 이용하여 설정함

* tonezone.h
struct tone_zone {
        int zone;                                       /* Zone number */
        char country[10];                       /* Country code */
        char description[40];           /* Description */
        int ringcadence[ZT_MAX_CADENCE];        /* Ring cadence */
        struct tone_zone_sound tones[ZT_TONE_MAX];
};
* zonedata.c
  • us
    • ringcadence 2000,4000
    • dialtone 350+440
    • busy 480+620/500,0/500
    • ring tone 440+480/2000,0/4000
    • congestion 480+620/250,0/250
    • callwait 440/300,0/10000
    • dialrecall
    • recordtone 1400/500,0/15000
    • info
    • stutter
http://www.itu.int/ITU-T/inr/forms/files/tones-0203.pdf

Korea (Republic of)
Busy tone -           480+620     0.5 on 0.5 off
Congestion tone -     480+620     0.3 on 0.2 off
Dial tone -           350+440     continuous
Recall dial tone - I  400//450    1.0 on 4.0 off
Recall dial tone - II 400//450    1.0 on 2.0 off
Intercept tone -      350+440     0.125 on 0.25 off 0.125 on 1.5 off
Annex to ITU OB 781-E          14
COUNTRY/TONE                        FREQUENCY in Hz CADENCE in seconds
Number unobtainable tone -          450             0.2 on 0.1 off 0.2 on 1.5 off
Ringing tone -                      440+480         1.0 on 2.0 off
Warning tone - operator intervening 392/494/587     2x(0.5 on 0.5 on 1.5 on)
Waiting tone -                      350+440         0.25 on 0.25 off 0.25 on 3.25 off

A "stuttered" or interrupted dial tone may mean that there is voice mail waiting, or may occur to confirm that a calling feature such as call forwarding has been activated.



chan_zap

* load_module(void)
  • setup_zap(0)
  • ast_channel_register(&zap_tech)
  • ast_cli_register_multiple(zap_cli, sizeof(zap_cli) / sizeof(zap_cli0));
  • ast_manager_register( "ZapTransfer", 0, action_transfer, "Transfer Zap Channel" );
    • ZapTransfer, ZapHangup, ZapDialOffhook, ZapDNDon
    • ZapDNDoff, ZapShowChannels

setup_zap(0)

  • static const char config[] = "zapata.conf";
  • cfg = ast_config_load(config);
struct ast_category {
        char name[80];
        int ignored;                    /* do not let user of the config see this category */
        struct ast_variable *root;
        struct ast_variable *last;
        struct ast_category *next;
};

struct ast_config {
        struct ast_category *root;
        struct ast_category *last;
        struct ast_category *current;
        struct ast_category *last_browse;               /* used to cache the last category supplied via category_browse */
        int include_level;
        int max_include_level;
};
  • struct ast_variable *v;
  • v = ast_variable_browse(cfg, "channels");
struct ast_variable {
        char *name;
        char *value;
        int lineno;
        int object;             /*!< 0 for variable, 1 for object */
        int blanklines;         /*!< Number of blanklines following entry */
        struct ast_comment *precomments;
        struct ast_comment *sameline;
        struct ast_variable *next;
        char stuff[0];
};


The [trunkgroups] section is for NFAS and GR-303
 connections, and it won’t be discussed in this book. 
If you require this type of functionality, see the
 zapata.conf.sample file for more information.
The [channels] section determines the signaling method 
for hardware channels and their options. Once an option 
is defined, it is inherited down through the rest of the
file. A channel is defined using channel =>, and each channel definition inherits all the options defined above
 that line. If you wish to configure different options for different channels, remember that the options should be
 configured before the channel=> definition.


        while(v) {
                /* Create the interface list */
                if (!strcasecmp(v->name, "channel")
                        c = v->value;
                        chan = strsep(&c, ",");
                        while(chan) {
                                set start, finish
                                for (x=start;x<=finish;x++) {
                                        tmp = mkintf(x, cur_signalling, cur_radio, NULL, reload);
                                chan = strsep(&c, ",");
                        }
                v = v->next;
        }

  • restart_monitor();







sponsored by andamiro
sponsored by cdnetworks
sponsored by HP

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2009-11-09 17:21:05
Processing time 0.0397 sec