Wed Jul 14 06:28:03 2010

Asterisk developer's documentation


func_redirecting.c File Reference

Redirecting data 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_redirecting.c:

Go to the source code of this file.

Enumerations

enum  ID_FIELD_STATUS { ID_FIELD_VALID, ID_FIELD_INVALID, ID_FIELD_UNKNOWN }

Functions

static void __reg_module (void)
static void __unreg_module (void)
static int load_module (void)
static enum ID_FIELD_STATUS redirecting_id_read (char *buf, size_t len, char *data, const struct ast_party_id *id)
static enum ID_FIELD_STATUS redirecting_id_write (struct ast_party_id *id, char *data, const char *value)
static int redirecting_read (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
static int redirecting_write (struct ast_channel *chan, const char *cmd, char *data, const char *value)
static int unload_module (void)

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Redirecting data 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 redirecting_function


Detailed Description

Redirecting data dialplan function.

Author:
Richard Mudgett <rmudgett@digium.com>
See Also:

Definition in file func_redirecting.c.


Enumeration Type Documentation

Enumerator:
ID_FIELD_VALID 
ID_FIELD_INVALID 
ID_FIELD_UNKNOWN 

Definition at line 110 of file func_redirecting.c.

00110                      {
00111    ID_FIELD_VALID,
00112    ID_FIELD_INVALID,
00113    ID_FIELD_UNKNOWN
00114 };


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 483 of file func_redirecting.c.

static void __unreg_module ( void   )  [static]

Definition at line 483 of file func_redirecting.c.

static int load_module ( void   )  [static]

static enum ID_FIELD_STATUS redirecting_id_read ( char *  buf,
size_t  len,
char *  data,
const struct ast_party_id id 
) [static]

Definition at line 131 of file func_redirecting.c.

References ast_copy_string(), ast_named_caller_presentation(), ID_FIELD_UNKNOWN, ID_FIELD_VALID, ast_party_id::name, ast_party_id::number, ast_party_id::number_presentation, ast_party_id::number_type, S_OR, status, and ast_party_id::tag.

Referenced by redirecting_read().

00132 {
00133    enum ID_FIELD_STATUS status;
00134 
00135    status = ID_FIELD_VALID;
00136 
00137    if (!strncasecmp("all", data, 3)) {
00138       snprintf(buf, len, "\"%s\" <%s>",
00139           S_OR(id->name, ""),
00140           S_OR(id->number, ""));
00141    } else if (!strncasecmp("name", data, 4)) {
00142       if (id->name) {
00143          ast_copy_string(buf, id->name, len);
00144       }
00145    } else if (!strncasecmp("num", data, 3)) {
00146       if (id->number) {
00147          ast_copy_string(buf, id->number, len);
00148       }
00149    } else if (!strncasecmp("tag", data, 3)) {
00150       if (id->tag) {
00151          ast_copy_string(buf, id->tag, len);
00152       }
00153    } else if (!strncasecmp("ton", data, 3)) {
00154       snprintf(buf, len, "%d", id->number_type);
00155    } else if (!strncasecmp("pres", data, 4)) {
00156       ast_copy_string(buf, ast_named_caller_presentation(id->number_presentation), len);
00157    } else {
00158       status = ID_FIELD_UNKNOWN;
00159    }
00160 
00161    return status;
00162 }

static enum ID_FIELD_STATUS redirecting_id_write ( struct ast_party_id id,
char *  data,
const char *  value 
) [static]

Definition at line 242 of file func_redirecting.c.

References ast_callerid_split(), ast_log(), ast_parse_caller_presentation(), ast_strdup, ast_strdupa, ast_trim_blanks(), ID_FIELD_INVALID, ID_FIELD_UNKNOWN, ID_FIELD_VALID, LOG_ERROR, ast_party_id::name, name, num, ast_party_id::number, status, and ast_party_id::tag.

Referenced by redirecting_write().

00243 {
00244    char *val;
00245    enum ID_FIELD_STATUS status;
00246 
00247    status = ID_FIELD_VALID;
00248 
00249    if (!strncasecmp("all", data, 3)) {
00250       char name[256];
00251       char num[256];
00252 
00253       ast_callerid_split(value, name, sizeof(name), num, sizeof(num));
00254       if (!(id->name = ast_strdup(name))) {
00255          return ID_FIELD_INVALID;
00256       }
00257       if (!(id->number = ast_strdup(num))) {
00258          return ID_FIELD_INVALID;
00259       }
00260    } else if (!strncasecmp("name", data, 4)) {
00261       id->name = ast_strdup(value);
00262       ast_trim_blanks(id->name);
00263    } else if (!strncasecmp("num", data, 3)) {
00264       id->number = ast_strdup(value);
00265       ast_trim_blanks(id->number);
00266    } else if (!strncasecmp("tag", data, 3)) {
00267       id->tag = ast_strdup(value);
00268       ast_trim_blanks(id->tag);
00269    } else if (!strncasecmp("ton", data, 3)) {
00270       val = ast_strdupa(value);
00271       ast_trim_blanks(val);
00272 
00273       if (('0' <= val[0]) && (val[0] <= '9')) {
00274          id->number_type = atoi(val);
00275       } else {
00276          ast_log(LOG_ERROR, "Unknown redirecting type of number '%s', value unchanged\n", val);
00277          status = ID_FIELD_INVALID;
00278       }
00279    } else if (!strncasecmp("pres", data, 4)) {
00280       int pres;
00281 
00282       val = ast_strdupa(value);
00283       ast_trim_blanks(val);
00284 
00285       if (('0' <= val[0]) && (val[0] <= '9')) {
00286          pres = atoi(val);
00287       } else {
00288          pres = ast_parse_caller_presentation(val);
00289       }
00290 
00291       if (pres < 0) {
00292          ast_log(LOG_ERROR, "Unknown redirecting number presentation '%s', value unchanged\n", val);
00293          status = ID_FIELD_INVALID;
00294       } else {
00295          id->number_presentation = pres;
00296       }
00297    } else {
00298       status = ID_FIELD_UNKNOWN;
00299    }
00300 
00301    return status;
00302 }

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

Definition at line 181 of file func_redirecting.c.

References ast_channel_lock, ast_channel_unlock, ast_copy_string(), ast_log(), ast_named_caller_presentation(), ast_redirecting_reason_name(), ast_party_redirecting::count, ast_party_redirecting::from, ID_FIELD_INVALID, ID_FIELD_VALID, LOG_ERROR, ast_party_id::number_presentation, ast_party_redirecting::reason, ast_channel::redirecting, redirecting_id_read(), and ast_party_redirecting::to.

00182 {
00183    /* Ensure that the buffer is empty */
00184    *buf = 0;
00185 
00186    if (!chan)
00187       return -1;
00188 
00189    ast_channel_lock(chan);
00190 
00191    if (!strncasecmp("from-", data, 5)) {
00192       switch (redirecting_id_read(buf, len, data + 5, &chan->redirecting.from)) {
00193       case ID_FIELD_VALID:
00194       case ID_FIELD_INVALID:
00195          break;
00196 
00197       default:
00198          ast_log(LOG_ERROR, "Unknown redirecting data type '%s'.\n", data);
00199          break;
00200       }
00201    } else if (!strncasecmp("to-", data, 3)) {
00202       switch (redirecting_id_read(buf, len, data + 3, &chan->redirecting.to)) {
00203       case ID_FIELD_VALID:
00204       case ID_FIELD_INVALID:
00205          break;
00206 
00207       default:
00208          ast_log(LOG_ERROR, "Unknown redirecting data type '%s'.\n", data);
00209          break;
00210       }
00211    } else if (!strncasecmp("pres", data, 4)) {
00212       ast_copy_string(buf, ast_named_caller_presentation(chan->redirecting.from.number_presentation), len);
00213    } else if (!strncasecmp("reason", data, 6)) {
00214       ast_copy_string(buf, ast_redirecting_reason_name(chan->redirecting.reason), len);
00215    } else if (!strncasecmp("count", data, 5)) {
00216       snprintf(buf, len, "%d", chan->redirecting.count);
00217    } else {
00218       ast_log(LOG_ERROR, "Unknown redirecting data type '%s'.\n", data);
00219    }
00220 
00221    ast_channel_unlock(chan);
00222 
00223    return 0;
00224 }

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

Definition at line 320 of file func_redirecting.c.

References ast_channel_lock, ast_channel_set_redirecting(), ast_channel_unlock, ast_channel_update_redirecting(), ast_log(), ast_parse_caller_presentation(), ast_party_redirecting_free(), ast_party_redirecting_set_init(), ast_redirecting_reason_parse(), ast_skip_blanks(), ast_strdupa, ast_trim_blanks(), ast_party_redirecting::count, ast_party_redirecting::from, ID_FIELD_INVALID, ID_FIELD_VALID, LOG_ERROR, ast_party_id::number_presentation, ast_party_redirecting::reason, ast_channel::redirecting, redirecting_id_write(), and ast_party_redirecting::to.

00321 {
00322    struct ast_party_redirecting redirecting;
00323    char *val;
00324    char *option;
00325    void (*set_it)(struct ast_channel *chan, const struct ast_party_redirecting *redirecting);
00326 
00327    if (!value || !chan) {
00328       return -1;
00329    }
00330 
00331    /* Determine if the update indication inhibit option is present */
00332    option = strchr(data, ',');
00333    if (option) {
00334       option = ast_skip_blanks(option + 1);
00335       switch (*option) {
00336       case 'i':
00337          set_it = ast_channel_set_redirecting;
00338          break;
00339 
00340       default:
00341          ast_log(LOG_ERROR, "Unknown redirecting option '%s'.\n", option);
00342          return 0;
00343       }
00344    }
00345    else {
00346       set_it = ast_channel_update_redirecting;
00347    }
00348 
00349    ast_channel_lock(chan);
00350    ast_party_redirecting_set_init(&redirecting, &chan->redirecting);
00351    ast_channel_unlock(chan);
00352 
00353    value = ast_skip_blanks(value);
00354 
00355    if (!strncasecmp("from-", data, 5)) {
00356       switch (redirecting_id_write(&redirecting.from, data + 5, value)) {
00357       case ID_FIELD_VALID:
00358          set_it(chan, &redirecting);
00359          break;
00360 
00361       case ID_FIELD_INVALID:
00362          break;
00363 
00364       default:
00365          ast_log(LOG_ERROR, "Unknown redirecting data type '%s'.\n", data);
00366          break;
00367       }
00368       ast_party_redirecting_free(&redirecting);
00369    } else if (!strncasecmp("to-", data, 3)) {
00370       switch (redirecting_id_write(&redirecting.to, data + 3, value)) {
00371       case ID_FIELD_VALID:
00372          set_it(chan, &redirecting);
00373          break;
00374 
00375       case ID_FIELD_INVALID:
00376          break;
00377 
00378       default:
00379          ast_log(LOG_ERROR, "Unknown redirecting data type '%s'.\n", data);
00380          break;
00381       }
00382       ast_party_redirecting_free(&redirecting);
00383    } else if (!strncasecmp("pres", data, 4)) {
00384       int pres;
00385 
00386       val = ast_strdupa(value);
00387       ast_trim_blanks(val);
00388 
00389       if (('0' <= val[0]) && (val[0] <= '9')) {
00390          pres = atoi(val);
00391       } else {
00392          pres = ast_parse_caller_presentation(val);
00393       }
00394 
00395       if (pres < 0) {
00396          ast_log(LOG_ERROR, "Unknown redirecting number presentation '%s', value unchanged\n", val);
00397       } else {
00398          redirecting.from.number_presentation = pres;
00399          redirecting.to.number_presentation = pres;
00400          set_it(chan, &redirecting);
00401       }
00402    } else if (!strncasecmp("reason", data, 6)) {
00403       int reason;
00404 
00405       val = ast_strdupa(value);
00406       ast_trim_blanks(val);
00407 
00408       if (('0' <= val[0]) && (val[0] <= '9')) {
00409          reason = atoi(val);
00410       } else {
00411          reason = ast_redirecting_reason_parse(val);
00412       }
00413 
00414       if (reason < 0) {
00415          ast_log(LOG_ERROR, "Unknown redirecting reason '%s', value unchanged\n", val);
00416       } else {
00417          redirecting.reason = reason;
00418          set_it(chan, &redirecting);
00419       }
00420    } else if (!strncasecmp("count", data, 5)) {
00421       val = ast_strdupa(value);
00422       ast_trim_blanks(val);
00423 
00424       if (('0' <= val[0]) && (val[0] <= '9')) {
00425          redirecting.count = atoi(val);
00426          set_it(chan, &redirecting);
00427       } else {
00428          ast_log(LOG_ERROR, "Unknown redirecting count '%s', value unchanged\n", val);
00429       }
00430    } else {
00431       ast_log(LOG_ERROR, "Unknown redirecting data type '%s'.\n", data);
00432    }
00433 
00434    return 0;
00435 }

static int unload_module ( void   )  [static]

Definition at line 457 of file func_redirecting.c.

References ast_custom_function_unregister().

00458 {
00459    return ast_custom_function_unregister(&redirecting_function);
00460 }


Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Redirecting data 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 483 of file func_redirecting.c.

Definition at line 483 of file func_redirecting.c.

Initial value:

 {
   .name = "REDIRECTING",
   .read = redirecting_read,
   .write = redirecting_write,
}

Definition at line 440 of file func_redirecting.c.


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