Wed Jul 14 06:27:55 2010

Asterisk developer's documentation


func_connectedline.c File Reference

Connected Line dialplan function. More...

#include "asterisk.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include "asterisk/module.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/logger.h"
#include "asterisk/utils.h"
#include "asterisk/app.h"
#include "asterisk/options.h"
#include "asterisk/callerid.h"

Include dependency graph for func_connectedline.c:

Go to the source code of this file.

Functions

static void __reg_module (void)
static void __unreg_module (void)
static int connectedline_read (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
static int connectedline_write (struct ast_channel *chan, const char *cmd, char *data, const char *value)
static int load_module (void)
static int unload_module (void)

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Connected Line dialplan function" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, }
static struct ast_module_infoast_module_info = &__mod_info
static struct ast_custom_function connectedline_function


Detailed Description

Connected Line dialplan function.

Definition in file func_connectedline.c.


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 275 of file func_connectedline.c.

static void __unreg_module ( void   )  [static]

Definition at line 275 of file func_connectedline.c.

static int connectedline_read ( struct ast_channel chan,
const char *  cmd,
char *  data,
char *  buf,
size_t  len 
) [static]

Definition at line 80 of file func_connectedline.c.

References ast_channel_lock, ast_channel_unlock, ast_connected_line_source_name(), ast_copy_string(), ast_log(), ast_named_caller_presentation(), ast_channel::connected, ast_party_connected_line::id, LOG_ERROR, ast_party_id::name, ast_party_id::number, ast_party_id::number_presentation, ast_party_id::number_type, ast_party_subaddress::odd_even_indicator, S_OR, ast_party_connected_line::source, ast_party_subaddress::str, ast_party_id::subaddress, ast_party_id::tag, ast_party_subaddress::type, and ast_party_subaddress::valid.

00082 {
00083    /* Ensure that the buffer is empty */
00084    *buf = 0;
00085 
00086    if (!chan)
00087       return -1;
00088 
00089    ast_channel_lock(chan);
00090 
00091    if (!strncasecmp("all", data, 3)) {
00092       snprintf(buf, len, "\"%s\" <%s>",
00093           S_OR(chan->connected.id.name, ""),
00094           S_OR(chan->connected.id.number, ""));
00095    } else if (!strncasecmp("name", data, 4)) {
00096       if (chan->connected.id.name) {
00097          ast_copy_string(buf, chan->connected.id.name, len);
00098       }
00099    } else if (!strncasecmp("num", data, 3)) {
00100       if (chan->connected.id.number) {
00101          ast_copy_string(buf, chan->connected.id.number, len);
00102       }
00103    } else if (!strncasecmp("tag", data, 3)) {
00104       if (chan->connected.id.tag) {
00105          ast_copy_string(buf, chan->connected.id.tag, len);
00106       }
00107    } else if (!strncasecmp("ton", data, 3)) {
00108       snprintf(buf, len, "%d", chan->connected.id.number_type);
00109    } else if (!strncasecmp("pres", data, 4)) {
00110       ast_copy_string(buf, ast_named_caller_presentation(chan->connected.id.number_presentation), len);
00111    } else if (!strncasecmp("source", data, 6)) {
00112       ast_copy_string(buf, ast_connected_line_source_name(chan->connected.source), len);
00113    } else if (!strncasecmp("subaddr", data, 7)) {
00114       /* also matches subaddr-valid, subaddr-type, subaddr-odd, subaddr */
00115       if (!strncasecmp(data + 7 ,"-valid", 6)) {      /* subaddr-valid */
00116          snprintf(buf, len, "%d", chan->connected.id.subaddress.valid);
00117       } else if (!strncasecmp(data + 7 ,"-type", 5)) {   /* subaddr-type */
00118          snprintf(buf, len, "%d", chan->connected.id.subaddress.type);
00119       } else if (!strncasecmp(data + 7 ,"-odd", 4)) {    /* subaddr-odd */
00120          snprintf(buf, len, "%d", chan->connected.id.subaddress.odd_even_indicator);
00121       } else {                /* subaddr */
00122          if (chan->connected.id.subaddress.str) {
00123             ast_copy_string(buf, chan->connected.id.subaddress.str, len);
00124          }
00125       }
00126    } else {
00127       ast_log(LOG_ERROR, "Unknown connectedline data type '%s'.\n", data);
00128    }
00129 
00130    ast_channel_unlock(chan);
00131 
00132    return 0;
00133 }

static int connectedline_write ( struct ast_channel chan,
const char *  cmd,
char *  data,
const char *  value 
) [static]

Definition at line 135 of file func_connectedline.c.

References ast_callerid_split(), ast_channel_lock, ast_channel_set_connected_line(), ast_channel_unlock, ast_channel_update_connected_line(), ast_connected_line_source_parse(), ast_log(), ast_parse_caller_presentation(), ast_party_connected_line_set_init(), ast_skip_blanks(), ast_strdupa, ast_trim_blanks(), ast_channel::connected, ast_party_connected_line::id, LOG_ERROR, ast_party_id::name, name, num, ast_party_id::number, ast_party_id::number_presentation, ast_party_id::number_type, ast_party_subaddress::odd_even_indicator, ast_party_connected_line::source, ast_party_subaddress::str, ast_party_id::subaddress, ast_party_id::tag, ast_party_subaddress::type, and ast_party_subaddress::valid.

00137 {
00138    struct ast_party_connected_line connected;
00139    char *val;
00140    char *option;
00141    void (*set_it)(struct ast_channel *chan, const struct ast_party_connected_line *connected);
00142 
00143    if (!value || !chan) {
00144       return -1;
00145    }
00146 
00147    /* Determine if the update indication inhibit option is present */
00148    option = strchr(data, ',');
00149    if (option) {
00150       option = ast_skip_blanks(option + 1);
00151       switch (*option) {
00152       case 'i':
00153          set_it = ast_channel_set_connected_line;
00154          break;
00155 
00156       default:
00157          ast_log(LOG_ERROR, "Unknown connectedline option '%s'.\n", option);
00158          return 0;
00159       }
00160    }
00161    else {
00162       set_it = ast_channel_update_connected_line;
00163    }
00164 
00165    ast_channel_lock(chan);
00166    ast_party_connected_line_set_init(&connected, &chan->connected);
00167    ast_channel_unlock(chan);
00168 
00169    value = ast_skip_blanks(value);
00170 
00171    if (!strncasecmp("all", data, 3)) {
00172       char name[256];
00173       char num[256];
00174 
00175       ast_callerid_split(value, name, sizeof(name), num, sizeof(num));
00176       connected.id.name = name;
00177       connected.id.number = num;
00178       set_it(chan, &connected);
00179    } else if (!strncasecmp("name", data, 4)) {
00180       connected.id.name = ast_strdupa(value);
00181       ast_trim_blanks(connected.id.name);
00182       set_it(chan, &connected);
00183    } else if (!strncasecmp("num", data, 3)) {
00184       connected.id.number = ast_strdupa(value);
00185       ast_trim_blanks(connected.id.number);
00186       set_it(chan, &connected);
00187    } else if (!strncasecmp("tag", data, 3)) {
00188       connected.id.tag = ast_strdupa(value);
00189       ast_trim_blanks(connected.id.tag);
00190       set_it(chan, &connected);
00191    } else if (!strncasecmp("ton", data, 3)) {
00192       val = ast_strdupa(value);
00193       ast_trim_blanks(val);
00194 
00195       if (('0' <= val[0]) && (val[0] <= '9')) {
00196          connected.id.number_type = atoi(val);
00197          set_it(chan, &connected);
00198       } else {
00199          ast_log(LOG_ERROR, "Unknown connectedline type of number '%s', value unchanged\n", val);
00200       }
00201    } else if (!strncasecmp("pres", data, 4)) {
00202       int pres;
00203 
00204       val = ast_strdupa(value);
00205       ast_trim_blanks(val);
00206 
00207       if (('0' <= val[0]) && (val[0] <= '9')) {
00208          pres = atoi(val);
00209       } else {
00210          pres = ast_parse_caller_presentation(val);
00211       }
00212 
00213       if (pres < 0) {
00214          ast_log(LOG_ERROR, "Unknown connectedline number presentation '%s', value unchanged\n", val);
00215       } else {
00216          connected.id.number_presentation = pres;
00217          set_it(chan, &connected);
00218       }
00219    } else if (!strncasecmp("source", data, 6)) {
00220       int source;
00221 
00222       val = ast_strdupa(value);
00223       ast_trim_blanks(val);
00224 
00225       if (('0' <= val[0]) && (val[0] <= '9')) {
00226          source = atoi(val);
00227       } else {
00228          source = ast_connected_line_source_parse(val);
00229       }
00230 
00231       if (source < 0) {
00232          ast_log(LOG_ERROR, "Unknown connectedline source '%s', value unchanged\n", val);
00233       } else {
00234          connected.source = source;
00235          set_it(chan, &connected);
00236       }
00237    } else if (!strncasecmp("subaddr", data, 7)) { /* outbound: set calling subaddress */
00238       /* also matches subaddr-valid, subaddr-type, subaddr-odd, subaddr */
00239       if (!strncasecmp(data + 7 ,"-valid", 6)) {      /* subaddr-valid */
00240          connected.id.subaddress.valid = atoi(value) ? 1 : 0;
00241       } else if (!strncasecmp(data + 7 ,"-type", 5)) {   /* subaddr-type */
00242          connected.id.subaddress.type = atoi(value) ? 2 : 0;
00243       } else if (!strncasecmp(data + 7 ,"-odd", 4)) {    /* subaddr-odd */
00244          connected.id.subaddress.odd_even_indicator = atoi(value) ? 1 : 0;
00245       } else {                /* subaddr */
00246          connected.id.subaddress.str = ast_strdupa(value);
00247          ast_trim_blanks(connected.id.subaddress.str);
00248       }
00249       set_it(chan, &connected);
00250    } else {
00251       ast_log(LOG_ERROR, "Unknown connectedline data type '%s'.\n", data);
00252    }
00253 
00254    return 0;
00255 }

static int load_module ( void   )  [static]

static int unload_module ( void   )  [static]

Definition at line 263 of file func_connectedline.c.

References ast_custom_function_unregister().


Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Connected Line dialplan function" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, } [static]

Definition at line 275 of file func_connectedline.c.

Definition at line 275 of file func_connectedline.c.

Initial value:

 {
   .name = "CONNECTEDLINE",
   .read = connectedline_read,
   .write = connectedline_write,
}

Definition at line 257 of file func_connectedline.c.


Generated on Wed Jul 14 06:27:55 2010 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6