Wed Oct 28 15:48:02 2009

Asterisk developer's documentation


app_directed_pickup.c File Reference

Directed Call Pickup Support. 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/lock.h"
#include "asterisk/app.h"

Include dependency graph for app_directed_pickup.c:

Go to the source code of this file.

Functions

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

Variables

static const char * app = "Pickup"
static const char * descrip
 LOCAL_USER_DECL
 STANDARD_LOCAL_USER
static const char * synopsis = "Directed Call Pickup"
static const char * tdesc = "Directed Call Pickup Application"


Detailed Description

Directed Call Pickup Support.

Definition in file app_directed_pickup.c.


Function Documentation

char* description ( void   ) 

Provides a description of the module.

Returns:
a short description of your module

Definition at line 152 of file app_directed_pickup.c.

00153 {
00154    return (char *) tdesc;
00155 }

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 166 of file app_directed_pickup.c.

References ASTERISK_GPL_KEY.

00167 {
00168    return ASTERISK_GPL_KEY;
00169 }

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 147 of file app_directed_pickup.c.

References ast_register_application(), and pickup_exec().

00148 {
00149    return ast_register_application(app, pickup_exec, synopsis, descrip);
00150 }

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

Definition at line 55 of file app_directed_pickup.c.

References ast_answer(), ast_cdr_getvar(), ast_channel_masquerade(), AST_CONTROL_ANSWER, ast_get_channel_by_exten_locked(), ast_get_channel_by_name_locked(), ast_log(), ast_mutex_unlock(), ast_queue_control(), AST_STATE_RING, AST_STATE_RINGING, ast_strlen_zero(), ast_channel::cdr, context, exten, LOCAL_USER_ADD, LOCAL_USER_REMOVE, ast_channel::lock, LOG_DEBUG, LOG_WARNING, and ast_channel::name.

Referenced by load_module().

00056 {
00057    int res = 0;
00058    struct localuser *u = NULL;
00059    struct ast_channel *origin = NULL, *target = NULL;
00060    char *tmp = NULL, *exten = NULL, *context = NULL;
00061    char workspace[256] = "";
00062 
00063    if (ast_strlen_zero(data)) {
00064       ast_log(LOG_WARNING, "Pickup requires an argument (extension) !\n");
00065       return -1;  
00066    }
00067 
00068    LOCAL_USER_ADD(u);
00069    
00070    /* Get the extension and context if present */
00071    exten = data;
00072    context = strchr(data, '@');
00073    if (context) {
00074       *context = '\0';
00075       context++;
00076    }
00077 
00078    /* Find a channel to pickup */
00079    origin = ast_get_channel_by_exten_locked(exten, context);
00080    if (origin && origin->cdr) {
00081       ast_cdr_getvar(origin->cdr, "dstchannel", &tmp, workspace,
00082                 sizeof(workspace), 0);
00083       if (tmp) {
00084          /* We have a possible channel... now we need to find it! */
00085          target = ast_get_channel_by_name_locked(tmp);
00086       } else {
00087          ast_log(LOG_DEBUG, "No target channel found.\n");
00088          res = -1;
00089       }
00090       ast_mutex_unlock(&origin->lock);
00091    } else {
00092       if (origin)
00093          ast_mutex_unlock(&origin->lock);
00094       ast_log(LOG_DEBUG, "No originating channel found.\n");
00095    }
00096    
00097    if (res)
00098       goto out;
00099 
00100    if (target && (!target->pbx) && ((target->_state == AST_STATE_RINGING) || (target->_state == AST_STATE_RING))) {
00101       ast_log(LOG_DEBUG, "Call pickup on chan '%s' by '%s'\n", target->name,
00102          chan->name);
00103       res = ast_answer(chan);
00104       if (res) {
00105          ast_log(LOG_WARNING, "Unable to answer '%s'\n", chan->name);
00106          res = -1;
00107          goto out;
00108       }
00109       res = ast_queue_control(chan, AST_CONTROL_ANSWER);
00110       if (res) {
00111          ast_log(LOG_WARNING, "Unable to queue answer on '%s'\n",
00112             chan->name);
00113          res = -1;
00114          goto out;
00115       }
00116       res = ast_channel_masquerade(target, chan);
00117       if (res) {
00118          ast_log(LOG_WARNING, "Unable to masquerade '%s' into '%s'\n", chan->name, target->name);
00119          res = -1;
00120          goto out;
00121       }
00122    } else {
00123       ast_log(LOG_DEBUG, "No call pickup possible...\n");
00124       res = -1;
00125    }
00126    /* Done */
00127  out:
00128    if (target) 
00129       ast_mutex_unlock(&target->lock);
00130    
00131    LOCAL_USER_REMOVE(u);
00132 
00133    return res;
00134 }

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 136 of file app_directed_pickup.c.

References ast_unregister_application(), and STANDARD_HANGUP_LOCALUSERS.

00137 {
00138    int res;
00139 
00140    res = ast_unregister_application(app);
00141    
00142    STANDARD_HANGUP_LOCALUSERS;
00143 
00144    return res;
00145 }

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 157 of file app_directed_pickup.c.

References STANDARD_USECOUNT.

00158 {
00159    int res;
00160 
00161    STANDARD_USECOUNT(res);
00162 
00163    return res;
00164 }


Variable Documentation

const char* app = "Pickup" [static]

Definition at line 44 of file app_directed_pickup.c.

const char* descrip [static]

Initial value:

"  Pickup(extension[@context]): This application can pickup any ringing channel\n"
"that is calling the specified extension. If no context is specified, the current\n"
"context will be used.\n"

Definition at line 46 of file app_directed_pickup.c.

Definition at line 53 of file app_directed_pickup.c.

Definition at line 51 of file app_directed_pickup.c.

const char* synopsis = "Directed Call Pickup" [static]

Definition at line 45 of file app_directed_pickup.c.

const char* tdesc = "Directed Call Pickup Application" [static]

Definition at line 43 of file app_directed_pickup.c.


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