Wed Oct 28 15:48:03 2009

Asterisk developer's documentation


app_dumpchan.c File Reference

Application to dump channel variables. More...

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "asterisk.h"
#include "asterisk/file.h"
#include "asterisk/logger.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/module.h"
#include "asterisk/options.h"
#include "asterisk/utils.h"
#include "asterisk/lock.h"

Include dependency graph for app_dumpchan.c:

Go to the source code of this file.

Functions

static int ast_serialize_showchan (struct ast_channel *c, char *buf, size_t size)
char * description (void)
 Provides a description of the module.
static int dumpchan_exec (struct ast_channel *chan, void *data)
char * key ()
 Returns the ASTERISK_GPL_KEY.
int load_module (void)
 Initialize the module.
int unload_module (void)
 Cleanup all module structures, sockets, etc.
int usecount (void)
 Provides a usecount.

Variables

static char * app = "DumpChan"
static char * desc
 LOCAL_USER_DECL
 STANDARD_LOCAL_USER
static char * synopsis = "Dump Info About The Calling Channel"
static char * tdesc = "Dump Info About The Calling Channel"


Detailed Description

Application to dump channel variables.

Definition in file app_dumpchan.c.


Function Documentation

static int ast_serialize_showchan ( struct ast_channel c,
char *  buf,
size_t  size 
) [static]

Definition at line 62 of file app_dumpchan.c.

References ast_channel::_state, ast_channel::appl, AST_FLAG_BLOCKING, ast_print_group(), ast_state2str(), ast_strlen_zero(), ast_test_flag, ast_channel::blockproc, ast_channel::callgroup, ast_channel::cdr, ast_channel::cid, ast_callerid::cid_dnid, ast_callerid::cid_name, ast_callerid::cid_num, ast_channel::context, ast_channel::data, ast_channel::exten, ast_channel::fds, ast_channel::fin, ast_channel::fout, ast_channel::name, ast_channel::nativeformats, ast_channel::pickupgroup, ast_channel::priority, ast_channel::readformat, ast_channel::rings, ast_cdr::start, ast_channel::type, ast_channel::uniqueid, ast_channel::whentohangup, and ast_channel::writeformat.

Referenced by dumpchan_exec().

00063 {
00064    struct timeval now;
00065    long elapsed_seconds=0;
00066    int hour=0, min=0, sec=0;
00067    char cgrp[256];
00068    char pgrp[256];
00069    
00070    now = ast_tvnow();
00071    memset(buf,0,size);
00072    if (!c)
00073       return 0;
00074 
00075    if (c->cdr) {
00076       elapsed_seconds = now.tv_sec - c->cdr->start.tv_sec;
00077       hour = elapsed_seconds / 3600;
00078       min = (elapsed_seconds % 3600) / 60;
00079       sec = elapsed_seconds % 60;
00080    }
00081 
00082    snprintf(buf,size, 
00083           "Name=               %s\n"
00084           "Type=               %s\n"
00085           "UniqueID=           %s\n"
00086           "CallerID=           %s\n"
00087           "CallerIDName=       %s\n"
00088           "DNIDDigits=         %s\n"
00089           "State=              %s (%d)\n"
00090           "Rings=              %d\n"
00091           "NativeFormat=       %d\n"
00092           "WriteFormat=        %d\n"
00093           "ReadFormat=         %d\n"
00094           "1stFileDescriptor=  %d\n"
00095           "Framesin=           %d %s\n"
00096           "Framesout=          %d %s\n"
00097           "TimetoHangup=       %ld\n"
00098           "ElapsedTime=        %dh%dm%ds\n"
00099           "Context=            %s\n"
00100           "Extension=          %s\n"
00101           "Priority=           %d\n"
00102           "CallGroup=          %s\n"
00103           "PickupGroup=        %s\n"
00104           "Application=        %s\n"
00105           "Data=               %s\n"
00106           "Blocking_in=        %s\n",
00107           c->name,
00108           c->type,
00109           c->uniqueid,
00110           (c->cid.cid_num ? c->cid.cid_num : "(N/A)"),
00111           (c->cid.cid_name ? c->cid.cid_name : "(N/A)"),
00112           (c->cid.cid_dnid ? c->cid.cid_dnid : "(N/A)" ),
00113           ast_state2str(c->_state),
00114           c->_state,
00115           c->rings,
00116           c->nativeformats,
00117           c->writeformat,
00118           c->readformat,
00119           c->fds[0], c->fin & 0x7fffffff, (c->fin & 0x80000000) ? " (DEBUGGED)" : "",
00120           c->fout & 0x7fffffff, (c->fout & 0x80000000) ? " (DEBUGGED)" : "", (long)c->whentohangup,
00121           hour,
00122           min,
00123           sec,
00124           c->context,
00125           c->exten,
00126           c->priority,
00127           ast_print_group(cgrp, sizeof(cgrp), c->callgroup),
00128           ast_print_group(pgrp, sizeof(pgrp), c->pickupgroup),
00129           ( c->appl ? c->appl : "(N/A)" ),
00130           ( c-> data ? (!ast_strlen_zero(c->data) ? c->data : "(Empty)") : "(None)"),
00131           (ast_test_flag(c, AST_FLAG_BLOCKING) ? c->blockproc : "(Not Blocking)"));
00132 
00133    return 0;
00134 }

char* description ( void   ) 

Provides a description of the module.

Returns:
a short description of your module

Definition at line 177 of file app_dumpchan.c.

00178 {
00179    return tdesc;
00180 }

static int dumpchan_exec ( struct ast_channel chan,
void *  data 
) [static]

Definition at line 136 of file app_dumpchan.c.

References ast_serialize_showchan(), ast_strlen_zero(), ast_verbose(), LOCAL_USER_ADD, LOCAL_USER_REMOVE, ast_channel::name, option_verbose, and pbx_builtin_serialize_variables().

Referenced by load_module().

00137 {
00138    int res=0;
00139    struct localuser *u;
00140    char vars[1024];
00141    char info[1024];
00142    int level = 0;
00143    static char *line = "================================================================================";
00144    
00145    LOCAL_USER_ADD(u);
00146 
00147    if (!ast_strlen_zero(data)) {
00148       level = atoi(data);
00149    }
00150 
00151    pbx_builtin_serialize_variables(chan, vars, sizeof(vars));
00152    ast_serialize_showchan(chan, info, sizeof(info));
00153    if (option_verbose >= level)
00154       ast_verbose("\nDumping Info For Channel: %s:\n%s\nInfo:\n%s\nVariables:\n%s%s\n",chan->name, line, info, vars, line);
00155 
00156    LOCAL_USER_REMOVE(u);
00157    
00158    return res;
00159 }

char* key ( void   ) 

Returns the ASTERISK_GPL_KEY.

This returns the ASTERISK_GPL_KEY, signifiying that you agree to the terms of the GPL stated in the ASTERISK_GPL_KEY. Your module will not load if it does not return the EXACT message:

 char *key(void) {
         return ASTERISK_GPL_KEY;
 }

Returns:
ASTERISK_GPL_KEY

Definition at line 189 of file app_dumpchan.c.

References ASTERISK_GPL_KEY.

00190 {
00191    return ASTERISK_GPL_KEY;
00192 }

int load_module ( void   ) 

Initialize the module.

This function is called at module load time. Put all code in here that needs to set up your module's hardware, software, registrations, etc.

Returns:
This function should return 0 on success and non-zero on failure. If the module is not loaded successfully, Asterisk will call its unload_module() function.
Initialize the Agents module. This function is being called by Asterisk when loading the module. Among other thing it registers applications, cli commands and reads the cofiguration file.

Returns:
int Always 0.
TE STUFF END

Definition at line 172 of file app_dumpchan.c.

References ast_register_application(), and dumpchan_exec().

00173 {
00174    return ast_register_application(app, dumpchan_exec, synopsis, desc);
00175 }

int unload_module ( void   ) 

Cleanup all module structures, sockets, etc.

This is called at exit. Any registrations and memory allocations need to be unregistered and free'd here. Nothing else will do these for you (until exit).

Returns:
Zero on success, or non-zero on error.

Definition at line 161 of file app_dumpchan.c.

References ast_unregister_application(), and STANDARD_HANGUP_LOCALUSERS.

00162 {
00163    int res;
00164 
00165    res = ast_unregister_application(app);
00166 
00167    STANDARD_HANGUP_LOCALUSERS;
00168 
00169    return res;
00170 }

int usecount ( void   ) 

Provides a usecount.

This function will be called by various parts of asterisk. Basically, all it has to do is to return a usecount when called. You will need to maintain your usecount within the module somewhere. The usecount should be how many channels provided by this module are in use.

Returns:
The module's usecount.

Definition at line 182 of file app_dumpchan.c.

References STANDARD_USECOUNT.

00183 {
00184    int res;
00185    STANDARD_USECOUNT(res);
00186    return res;
00187 }


Variable Documentation

char* app = "DumpChan" [static]

Definition at line 49 of file app_dumpchan.c.

char* desc [static]

Definition at line 51 of file app_dumpchan.c.

Definition at line 60 of file app_dumpchan.c.

Definition at line 58 of file app_dumpchan.c.

char* synopsis = "Dump Info About The Calling Channel" [static]

Definition at line 50 of file app_dumpchan.c.

char* tdesc = "Dump Info About The Calling Channel" [static]

Definition at line 48 of file app_dumpchan.c.


Generated on Wed Oct 28 15:48:03 2009 for Asterisk - the Open Source PBX by  doxygen 1.5.6