Mon Mar 31 07:42:19 2008

Asterisk developer's documentation


res_clioriginate.c File Reference

Originate calls via the CLI. More...

#include "asterisk.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/logger.h"
#include "asterisk/module.h"
#include "asterisk/cli.h"
#include "asterisk/utils.h"
#include "asterisk/frame.h"

Include dependency graph for res_clioriginate.c:

Go to the source code of this file.

Defines

#define TIMEOUT   30

Functions

 AST_MODULE_INFO_STANDARD (ASTERISK_GPL_KEY,"Call origination from the CLI")
 ASTERISK_FILE_VERSION (__FILE__,"$Revision$")
static char * complete_orig (const char *line, const char *word, int pos, int state)
static int handle_orig (int fd, int argc, char *argv[])
static int load_module (void)
static int orig_app (int fd, const char *chan, const char *app, const char *appdata)
static int orig_exten (int fd, const char *chan, const char *data)
static int unload_module (void)

Variables

ast_cli_entry cli_cliorig []
static char orig_help []


Detailed Description

Originate calls via the CLI.

Author:
Russell Bryant <russell@digium.com>

Definition in file res_clioriginate.c.


Define Documentation

#define TIMEOUT   30

The timeout for originated calls, in seconds

Definition at line 44 of file res_clioriginate.c.

Referenced by orig_app(), orig_exten(), rpt(), and rpt_tele_thread().


Function Documentation

AST_MODULE_INFO_STANDARD ( ASTERISK_GPL_KEY  ,
"Call origination from the CLI"   
)

ASTERISK_FILE_VERSION ( __FILE__  ,
"$Revision$"   
)

static char * complete_orig ( const char *  line,
const char *  word,
int  pos,
int  state 
) [static]

Definition at line 147 of file res_clioriginate.c.

References ast_cli_complete(), ast_module_ref(), and ast_module_unref().

00148 {
00149    static char *choices[] = { "application", "extension", NULL };
00150    char *ret;
00151 
00152    if (pos != 2)
00153       return NULL;
00154 
00155    /* ugly, can be removed when CLI entries have ast_module pointers */
00156    ast_module_ref(ast_module_info->self);
00157    ret = ast_cli_complete(word, choices, state);
00158    ast_module_unref(ast_module_info->self);
00159 
00160    return ret;
00161 }

static int handle_orig ( int  fd,
int  argc,
char *  argv[] 
) [static]

Definition at line 125 of file res_clioriginate.c.

References ast_module_ref(), ast_module_unref(), ast_strlen_zero(), orig_app(), orig_exten(), and RESULT_SHOWUSAGE.

00126 {
00127    int res;
00128 
00129    if (ast_strlen_zero(argv[1]) || ast_strlen_zero(argv[2]))
00130       return RESULT_SHOWUSAGE;
00131 
00132    /* ugly, can be removed when CLI entries have ast_module pointers */
00133    ast_module_ref(ast_module_info->self);
00134 
00135    if (!strcasecmp("application", argv[2])) {
00136       res = orig_app(fd, argv[1], argv[3], argv[4]);  
00137    } else if (!strcasecmp("extension", argv[2])) {
00138       res = orig_exten(fd, argv[1], argv[3]);
00139    } else
00140       res = RESULT_SHOWUSAGE;
00141 
00142    ast_module_unref(ast_module_info->self);
00143 
00144    return res;
00145 }

static int load_module ( void   )  [static]

Definition at line 169 of file res_clioriginate.c.

References ast_cli_register_multiple(), and cli_cliorig.

00170 {
00171    ast_cli_register_multiple(cli_cliorig, sizeof(cli_cliorig) / sizeof(struct ast_cli_entry));
00172    return 0;
00173 }

static int orig_app ( int  fd,
const char *  chan,
const char *  app,
const char *  appdata 
) [static]

Definition at line 72 of file res_clioriginate.c.

References ast_cli(), AST_FORMAT_SLINEAR, ast_pbx_outgoing_app(), ast_strdupa, ast_strlen_zero(), RESULT_SHOWUSAGE, RESULT_SUCCESS, strsep(), and TIMEOUT.

Referenced by handle_orig().

00073 {
00074    char *chantech;
00075    char *chandata;
00076    int reason = 0;
00077    
00078    if (ast_strlen_zero(app))
00079       return RESULT_SHOWUSAGE;
00080 
00081    chandata = ast_strdupa(chan);
00082    
00083    chantech = strsep(&chandata, "/");
00084    if (!chandata) {
00085       ast_cli(fd, "*** No data provided after channel type! ***\n");
00086       return RESULT_SHOWUSAGE;
00087    }
00088 
00089    ast_pbx_outgoing_app(chantech, AST_FORMAT_SLINEAR, chandata, TIMEOUT * 1000, app, appdata, &reason, 0, NULL, NULL, NULL, NULL, NULL);
00090 
00091    return RESULT_SUCCESS;
00092 }

static int orig_exten ( int  fd,
const char *  chan,
const char *  data 
) [static]

Definition at line 94 of file res_clioriginate.c.

References ast_cli(), AST_FORMAT_SLINEAR, ast_pbx_outgoing_exten(), ast_strdupa, ast_strlen_zero(), context, exten, RESULT_SHOWUSAGE, RESULT_SUCCESS, strsep(), and TIMEOUT.

Referenced by handle_orig(), and park_call_exec().

00095 {
00096    char *chantech;
00097    char *chandata;
00098    char *exten = NULL;
00099    char *context = NULL;
00100    int reason = 0;
00101 
00102    chandata = ast_strdupa(chan);
00103    
00104    chantech = strsep(&chandata, "/");
00105    if (!chandata) {
00106       ast_cli(fd, "*** No data provided after channel type! ***\n");
00107       return RESULT_SHOWUSAGE;
00108    }
00109 
00110    if (!ast_strlen_zero(data)) {
00111       context = ast_strdupa(data);
00112       exten = strsep(&context, "@");
00113    }
00114 
00115    if (ast_strlen_zero(exten))
00116       exten = "s";
00117    if (ast_strlen_zero(context))
00118       context = "default";
00119    
00120    ast_pbx_outgoing_exten(chantech, AST_FORMAT_SLINEAR, chandata, TIMEOUT * 1000, context, exten, 1, &reason, 0, NULL, NULL, NULL, NULL, NULL);
00121 
00122    return RESULT_SUCCESS;
00123 }

static int unload_module ( void   )  [static]

Definition at line 163 of file res_clioriginate.c.

References ast_cli_unregister_multiple(), and cli_cliorig.

00164 {
00165    ast_cli_unregister_multiple(cli_cliorig, sizeof(cli_cliorig) / sizeof(struct ast_cli_entry));
00166    return 0;
00167 }


Variable Documentation

struct ast_cli_entry cli_cliorig[]

Initial value:

 {
   { { "originate", NULL },
   handle_orig, "Originate a call",
   orig_help, complete_orig },
}

Definition at line 66 of file res_clioriginate.c.

Referenced by load_module(), and unload_module().

char orig_help[] [static]

Definition at line 46 of file res_clioriginate.c.


Generated on Mon Mar 31 07:42:19 2008 for Asterisk - the Open Source PBX by  doxygen 1.5.1