Asterisk - The Open Source Telephony Project  21.4.1
Data Structures | Enumerations | Functions | Variables
func_callerid.c File Reference

Party ID related dialplan functions (Caller-ID, Connected-line, Redirecting) More...

#include "asterisk.h"
#include "asterisk/module.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/utils.h"
#include "asterisk/app.h"
#include "asterisk/callerid.h"

Go to the source code of this file.

Data Structures

struct  __subtype_ast_party_func_args
 
struct  __subtype_ast_party_members
 
struct  ast_party_func_args
 
struct  ast_party_members
 

Enumerations

enum  CONNECTED_LINE_OPT_ARGS { CONNECTED_LINE_OPT_DUMMY, CONNECTED_LINE_OPT_ARG_ARRAY_SIZE }
 
enum  CONNECTED_LINE_OPT_FLAGS { CONNECTED_LINE_OPT_INHIBIT = (1 << 0) }
 
enum  ID_FIELD_STATUS { ID_FIELD_VALID, ID_FIELD_INVALID, ID_FIELD_UNKNOWN }
 
enum  REDIRECTING_OPT_ARGS { REDIRECTING_OPT_DUMMY, REDIRECTING_OPT_ARG_ARRAY_SIZE }
 
enum  REDIRECTING_OPT_FLAGS { REDIRECTING_OPT_INHIBIT = (1 << 0) }
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
static int callerid_read (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
 
static int callerid_write (struct ast_channel *chan, const char *cmd, char *data, const char *value)
 
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 enum ID_FIELD_STATUS party_id_read (char *buf, size_t len, int argc, char *argv[], const struct ast_party_id *id)
 
static enum ID_FIELD_STATUS party_id_write (struct ast_party_id *id, int argc, char *argv[], const char *value)
 
static enum ID_FIELD_STATUS party_name_read (char *buf, size_t len, int argc, char *argv[], const struct ast_party_name *name)
 
static enum ID_FIELD_STATUS party_name_write (struct ast_party_name *name, int argc, char *argv[], const char *value)
 
static enum ID_FIELD_STATUS party_number_read (char *buf, size_t len, int argc, char *argv[], const struct ast_party_number *number)
 
static enum ID_FIELD_STATUS party_number_write (struct ast_party_number *number, int argc, char *argv[], const char *value)
 
static enum ID_FIELD_STATUS party_subaddress_read (char *buf, size_t len, int argc, char *argv[], const struct ast_party_subaddress *subaddress)
 
static enum ID_FIELD_STATUS party_subaddress_write (struct ast_party_subaddress *subaddress, int argc, char *argv[], 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_LOAD_ORDER , .description = "Party ID related dialplan functions (Caller-ID, Connected-line, Redirecting)" , .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 = "da6642af068ee5e6490c5b1d2cc1d238" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
 
static const struct ast_module_infoast_module_info = &__mod_info
 
static struct ast_custom_function callerid_function
 
static struct ast_custom_function connectedline_function
 
static const struct ast_app_option connectedline_opts [128] = { [ 'i' ] = { .flag = CONNECTED_LINE_OPT_INHIBIT }, }
 
static struct ast_custom_function redirecting_function
 
static const struct ast_app_option redirecting_opts [128] = { [ 'i' ] = { .flag = REDIRECTING_OPT_INHIBIT }, }
 

Detailed Description

Party ID related dialplan functions (Caller-ID, Connected-line, Redirecting)

See Also:

Definition in file func_callerid.c.

Enumeration Type Documentation

Enumerator
CONNECTED_LINE_OPT_DUMMY 

Delete this if CONNECTED_LINE ever gets an option with parameters.

CONNECTED_LINE_OPT_ARG_ARRAY_SIZE 
Note
This entry MUST be the last one in the enum

Definition at line 471 of file func_callerid.c.

471  {
472  CONNECTED_LINE_OPT_DUMMY, /*!< Delete this if CONNECTED_LINE ever gets an option with parameters. */
473 
474  /*! \note This entry _MUST_ be the last one in the enum */
476 };
Enumerator
REDIRECTING_OPT_DUMMY 

Delete this if REDIRECTING ever gets an option with parameters.

REDIRECTING_OPT_ARG_ARRAY_SIZE 
Note
This entry MUST be the last one in the enum

Definition at line 485 of file func_callerid.c.

485  {
486  REDIRECTING_OPT_DUMMY, /*!< Delete this if REDIRECTING ever gets an option with parameters. */
487 
488  /*! \note This entry _MUST_ be the last one in the enum */
490 };

Function Documentation

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

< Member name

< Optional caller id to parse instead of from the channel.

< Member name

< Optional caller id to parse instead of from the channel.

Definition at line 947 of file func_callerid.c.

References AST_APP_ARG, ast_copy_string(), AST_DECLARE_APP_ARGS, AST_NONSTANDARD_APP_ARGS, AST_STANDARD_APP_ARGS, ast_strdupa, ast_party_number::plan, ast_party_number::str, and ast_party_members::subnames.

948 {
949  char *parms;
950  struct ast_party_members member = { 0, };
952  AST_APP_ARG(member); /*!< Member name */
953  AST_APP_ARG(cid); /*!< Optional caller id to parse instead of from the channel. */
954  );
955 
956  /* Ensure that the buffer is empty */
957  *buf = 0;
958 
959  if (!chan) {
960  return -1;
961  }
962 
963  parms = ast_strdupa(data);
964  AST_STANDARD_APP_ARGS(args, parms);
965  if (args.argc == 0) {
966  /* Must have at least one argument. */
967  return -1;
968  }
969 
970  AST_NONSTANDARD_APP_ARGS(member, args.member, '-');
971  if (member.argc == 0 || ARRAY_LEN(member.subnames) <= member.argc) {
972  /* Too few or too many subnames */
973  return -1;
974  }
975 
976  if (args.argc == 2) {
977  char name[80];
978  char num[80];
979 
980  ast_callerid_split(args.cid, name, sizeof(name), num, sizeof(num));
981 
982  if (member.argc == 1 && !strcasecmp("all", member.subnames[0])) {
983  snprintf(buf, len, "\"%s\" <%s>", name, num);
984  } else if (member.argc == 1 && !strcasecmp("name", member.subnames[0])) {
985  ast_copy_string(buf, name, len);
986  } else if (member.argc == 1 && !strncasecmp("num", member.subnames[0], 3)) {
987  /* Accept num[ber] */
988  ast_copy_string(buf, num, len);
989  } else {
990  ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data);
991  }
992  } else {
993  enum ID_FIELD_STATUS status;
994  ast_channel_lock(chan);
995 
996  if (member.argc == 1 && !strcasecmp("rdnis", member.subnames[0])) {
997  if (ast_channel_redirecting(chan)->from.number.valid
998  && ast_channel_redirecting(chan)->from.number.str) {
999  ast_copy_string(buf, ast_channel_redirecting(chan)->from.number.str, len);
1000  }
1001  } else if (!strcasecmp("dnid", member.subnames[0])) {
1002  if (member.argc == 1) {
1003  /* Setup as if user had given dnid-num instead. */
1004  member.argc = 2;
1005  member.subnames[1] = "num";
1006  }
1007  if (!strncasecmp("num", member.subnames[1], 3)) {
1008  /*
1009  * Accept num[ber]
1010  * dnid-num...
1011  */
1012  if (member.argc == 2) {
1013  /* dnid-num */
1014  if (ast_channel_dialed(chan)->number.str) {
1015  ast_copy_string(buf, ast_channel_dialed(chan)->number.str, len);
1016  }
1017  } else if (member.argc == 3 && !strcasecmp("plan", member.subnames[2])) {
1018  /* dnid-num-plan */
1019  snprintf(buf, len, "%d", ast_channel_dialed(chan)->number.plan);
1020  } else {
1021  ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data);
1022  }
1023  } else if (!strncasecmp("subaddr", member.subnames[1], 7)) {
1024  /*
1025  * Accept subaddr[ess]
1026  * dnid-subaddr...
1027  */
1028  status = party_subaddress_read(buf, len, member.argc - 2, member.subnames + 2,
1029  &ast_channel_dialed(chan)->subaddress);
1030  switch (status) {
1031  case ID_FIELD_VALID:
1032  case ID_FIELD_INVALID:
1033  break;
1034  default:
1035  ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data);
1036  break;
1037  }
1038  } else {
1039  ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data);
1040  }
1041  } else if (member.argc == 1 && !strcasecmp("ani2", member.subnames[0])) {
1042  snprintf(buf, len, "%d", ast_channel_caller(chan)->ani2);
1043  } else if (!strcasecmp("ani", member.subnames[0])) {
1044  if (member.argc == 1) {
1045  /* Setup as if user had given ani-num instead. */
1046  member.argc = 2;
1047  member.subnames[1] = "num";
1048  }
1049  status = party_id_read(buf, len, member.argc - 1, member.subnames + 1,
1050  &ast_channel_caller(chan)->ani);
1051  switch (status) {
1052  case ID_FIELD_VALID:
1053  case ID_FIELD_INVALID:
1054  break;
1055  default:
1056  ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data);
1057  break;
1058  }
1059  } else if (!strcasecmp("priv", member.subnames[0])) {
1060  status = party_id_read(buf, len, member.argc - 1, member.subnames + 1,
1061  &ast_channel_caller(chan)->priv);
1062  switch (status) {
1063  case ID_FIELD_VALID:
1064  case ID_FIELD_INVALID:
1065  break;
1066  default:
1067  ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data);
1068  break;
1069  }
1070  } else {
1071  status = party_id_read(buf, len, member.argc, member.subnames, &ast_channel_caller(chan)->id);
1072  switch (status) {
1073  case ID_FIELD_VALID:
1074  case ID_FIELD_INVALID:
1075  break;
1076  default:
1077  ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data);
1078  break;
1079  }
1080  }
1081 
1082  ast_channel_unlock(chan);
1083  }
1084 
1085  return 0;
1086 }
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the 'standard' argument separation process for an application.
char * subnames[10]
Number structure.
Definition: app_followme.c:154
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298
#define AST_NONSTANDARD_APP_ARGS(args, parse, sep)
Performs the 'nonstandard' argument separation process for an application.
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:425
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
#define AST_APP_ARG(name)
Define an application argument.

Variable Documentation

struct ast_custom_function connectedline_function
static
Initial value:
= {
.name = "CONNECTEDLINE",
.read = connectedline_read,
.write = connectedline_write,
}

Definition at line 1799 of file func_callerid.c.

struct ast_custom_function redirecting_function
static
Initial value:
= {
.name = "REDIRECTING",
.read = redirecting_read,
.write = redirecting_write,
}

Definition at line 1805 of file func_callerid.c.