Asterisk.org: Developer Documentation (28 Oct 2009)

Wed Oct 28 15:48:13 2009

## Asterisk developer's documentation

# app_sendtext.c File Reference

App to transmit a text message. More...

`#include <stdlib.h>`
`#include <stdio.h>`
`#include <string.h>`
`#include "asterisk.h"`
`#include "asterisk/lock.h"`
`#include "asterisk/file.h"`
`#include "asterisk/logger.h"`
`#include "asterisk/channel.h"`
`#include "asterisk/pbx.h"`
`#include "asterisk/module.h"`
`#include "asterisk/translate.h"`
`#include "asterisk/image.h"`
`#include "asterisk/options.h"`
`#include "asterisk/app.h"`

Include dependency graph for app_sendtext.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 | sendtext_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 = "SendText"
static const char * | descrip
| LOCAL_USER_DECL
| STANDARD_LOCAL_USER
static const char * | synopsis = "Send a Text Message"
static const char * | tdesc = "Send Text Applications"

## Detailed Description

App to transmit a text message.

Requires support of sending text messages from channel driver

Definition in file app_sendtext.c.

## Function Documentation

char* description | ( | void |  | ) |

Provides a description of the module.

Returns:
  a short description of your module

Definition at line 139 of file app_sendtext.c.

    00140 {
    00141    return (char *) tdesc;
    00142 }

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 153 of file app_sendtext.c.

References ASTERISK_GPL_KEY.

    00154 {
    00155    return ASTERISK_GPL_KEY;
    00156 }

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 134 of file app_sendtext.c.

References ast_register_application(), and sendtext_exec().

    00135 {
    00136    return ast_register_application(app, sendtext_exec, synopsis, descrip);
    00137 }

static int sendtext_exec | ( | struct ast_channel * | chan,
|  | void * | data |
| ) |  |  | `[static]`

Definition at line 70 of file app_sendtext.c.

References AST_APP_ARG, AST_DECLARE_APP_ARGS, ast_goto_if_exists(), ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_sendtext(), AST_STANDARD_APP_ARGS, ast_strdupa, ast_strlen_zero(), ast_channel::context, ast_channel::exten, LOCAL_USER_ADD, LOCAL_USER_REMOVE, ast_channel::lock, LOG_ERROR, LOG_WARNING, option_priority_jumping, parse(), pbx_builtin_setvar_helper(), ast_channel::priority, ast_channel_tech::send_text, ast_channel::tech, and text.

Referenced by load_module().

    00071 {
    00072    int res = 0;
    00073    struct localuser *u;
    00074    char *status = "UNSUPPORTED";
    00075    char *parse = NULL;
    00076    int priority_jump = 0;
    00077    AST_DECLARE_APP_ARGS(args,
    00078       AST_APP_ARG(text);
    00079       AST_APP_ARG(options);
    00080    );
    00081
    00082    LOCAL_USER_ADD(u);
    00083
    00084    if (ast_strlen_zero(data)) {
    00085       ast_log(LOG_WARNING, "SendText requires an argument (text[|options])\n");
    00086       LOCAL_USER_REMOVE(u);
    00087       return -1;
    00088    } else {
    00089       parse = ast_strdupa(data);
    00090       if (!parse) {
    00091          ast_log(LOG_ERROR, "Out of memory!\n");
    00092          LOCAL_USER_REMOVE(u);
    00093          return -1;
    00094       }
    00095    }
    00096
    00097    AST_STANDARD_APP_ARGS(args, parse);
    00098
    00099    if (args.options) {
    00100       if (strchr(args.options, 'j'))
    00101          priority_jump = 1;
    00102    }
    00103
    00104    ast_mutex_lock(&chan->lock);
    00105    if (!chan->tech->send_text) {
    00106       ast_mutex_unlock(&chan->lock);
    00107       /* Does not support transport */
    00108       if (priority_jump || option_priority_jumping)
    00109          ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
    00110       LOCAL_USER_REMOVE(u);
    00111       return 0;
    00112    }
    00113    status = "FAILURE";
    00114    ast_mutex_unlock(&chan->lock);
    00115    res = ast_sendtext(chan, args.text);
    00116    if (!res)
    00117       status = "SUCCESS";
    00118    pbx_builtin_setvar_helper(chan, "SENDTEXTSTATUS", status);
    00119    LOCAL_USER_REMOVE(u);
    00120    return 0;
    00121 }

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 123 of file app_sendtext.c.

References ast_unregister_application(), and STANDARD_HANGUP_LOCALUSERS.

    00124 {
    00125    int res;
    00126
    00127    res = ast_unregister_application(app);
    00128
    00129    STANDARD_HANGUP_LOCALUSERS;
    00130
    00131    return res;
    00132 }

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 144 of file app_sendtext.c.

References STANDARD_USECOUNT.

    00145 {
    00146    int res;
    00147
    00148    STANDARD_USECOUNT(res);
    00149
    00150    return res;
    00151 }

## Variable Documentation

const char* app = "SendText"`[static]`

Definition at line 49 of file app_sendtext.c.

const char* descrip`[static]`

Definition at line 53 of file app_sendtext.c.

LOCAL_USER_DECL

Definition at line 68 of file app_sendtext.c.

STANDARD_LOCAL_USER

Definition at line 66 of file app_sendtext.c.

const char* synopsis = "Send a Text Message"`[static]`

Definition at line 51 of file app_sendtext.c.

const char* tdesc = "Send Text Applications"`[static]`

Definition at line 47 of file app_sendtext.c.