[asterisk-commits] russell: branch russell/chan_console r81422 - /team/russell/chan_console/chan...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Fri Aug 31 23:48:40 CDT 2007
Author: russell
Date: Fri Aug 31 23:48:37 2007
New Revision: 81422
URL: http://svn.digium.com/view/asterisk?view=rev&rev=81422
Log:
convert the pvt struct to use stringfields
Modified:
team/russell/chan_console/channels/chan_console.c
Modified: team/russell/chan_console/channels/chan_console.c
URL: http://svn.digium.com/view/asterisk/team/russell/chan_console/channels/chan_console.c?view=diff&rev=81422&r1=81421&r2=81422
==============================================================================
--- team/russell/chan_console/channels/chan_console.c (original)
+++ team/russell/chan_console/channels/chan_console.c Fri Aug 31 23:48:37 2007
@@ -134,26 +134,28 @@
};
static struct console_pvt {
+ AST_DECLARE_STRING_FIELDS(
+ /*! Name of the device */
+ AST_STRING_FIELD(name);
+ /*! Default context for outgoing calls */
+ AST_STRING_FIELD(context);
+ /*! Default extension for outgoing calls */
+ AST_STRING_FIELD(exten);
+ /*! Default CallerID number */
+ AST_STRING_FIELD(cid_num);
+ /*! Default CallerID name */
+ AST_STRING_FIELD(cid_name);
+ /*! Default MOH class to listen to, if:
+ * - No MOH class set on the channel
+ * - Peer channel putting this device on hold did not suggest a class */
+ AST_STRING_FIELD(mohinterpret);
+ /*! Default language */
+ AST_STRING_FIELD(language);
+ );
/*! Current channel for this device */
struct ast_channel *owner;
/*! Current PortAudio stream for this device */
PaStream *stream;
- /*! Name of the device */
- const char *name;
- /*! Default context for outgoing calls */
- char context[AST_MAX_CONTEXT];
- /*! Default extension for outgoing calls */
- char exten[AST_MAX_EXTENSION];
- /*! Default CallerID number */
- char cid_num[256];
- /*! Default CallerID name */
- char cid_name[256];
- /*! Default MOH class to listen to, if:
- * - No MOH class set on the channel
- * - Peer channel putting this device on hold did not suggest a class */
- char mohinterpret[MAX_MUSICCLASS];
- /*! Default language */
- char language[MAX_LANGUAGE];
/*! A frame for preparing to queue on to the channel */
struct ast_frame fr;
/*! Buffer to hold outgoing audio with the standard offset */
@@ -187,7 +189,6 @@
/*! List of frames to be written out to the device */
AST_LIST_HEAD_NOLOCK(, ast_frame) frames;
} console_pvt = {
- .name = "default",
.lock = AST_MUTEX_INIT_VALUE,
.cursound = -1,
};
@@ -708,7 +709,9 @@
static char *cli_console_dial(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
- char *s = NULL, *mye = NULL, *myc = NULL;
+ char *s = NULL;
+ const char *mye = NULL, *myc = NULL;
+
struct console_pvt *pvt = &console_pvt;
if (cmd == CLI_INIT) {
@@ -740,8 +743,11 @@
}
/* if we have an argument split it into extension and context */
if (a->argc == e->args + 1) {
- s = ast_ext_ctx(pvt, a->argv[e->args], &mye, &myc);
+ char *ext = NULL, *con = NULL;
+ s = ast_ext_ctx(pvt, a->argv[e->args], &ext, &con);
ast_log(LOG_DEBUG, "provided '%s', exten '%s' context '%s'\n", a->argv[e->args], mye, myc);
+ mye = ext;
+ myc = con;
}
/* supply default values if needed */
if (mye == NULL)
@@ -947,38 +953,55 @@
struct ast_variable *v;
struct console_pvt *pvt = &console_pvt;
struct ast_flags config_flags = { 0 };
+ int res = -1;
/* default values */
memcpy(&global_jbconf, &default_jbconf, sizeof(global_jbconf));
- strcpy(pvt->mohinterpret, "default");
- strcpy(pvt->context, "default");
- strcpy(pvt->exten, "s");
- pvt->language[0] = '\0';
- pvt->cid_num[0] = '\0';
- pvt->cid_name[0] = '\0';
+
+ ast_mutex_lock(&pvt->lock);
+
+ if (!reload) {
+ if (ast_string_field_init(pvt, 32))
+ goto return_unlock;
+ ast_string_field_set(pvt, name, "default");
+ }
+
+ /* Set pvt struct defaults */
+ ast_string_field_set(pvt, mohinterpret, "default");
+ ast_string_field_set(pvt, context, "default");
+ ast_string_field_set(pvt, exten, "s");
+ ast_string_field_free(pvt, language);
+ ast_string_field_free(pvt, cid_num);
+ ast_string_field_free(pvt, cid_name);
+
pvt->overridecontext = 0;
pvt->autoanswer = 0;
+ /* End defaults */
if (!(cfg = ast_config_load(config_file, config_flags))) {
ast_log(LOG_NOTICE, "Unable to open configuration file %s!\n", config_file);
- return -1;
+ goto return_unlock;
}
v = ast_variable_browse(cfg, "general");
for (; v; v = v->next) {
if (!ast_jb_read_conf(&global_jbconf, v->name, v->value))
continue;
else if (!strcasecmp(v->name, "context"))
- ast_copy_string(pvt->context, v->value, sizeof(pvt->context));
+ ast_string_field_set(pvt, context, v->value);
else if (!strcasecmp(v->name, "extension"))
- ast_copy_string(pvt->exten, v->value, sizeof(pvt->exten));
+ ast_string_field_set(pvt, exten, v->value);
else if (!strcasecmp(v->name, "mohinterpret"))
- ast_copy_string(pvt->mohinterpret, v->value, sizeof(pvt->mohinterpret));
+ ast_string_field_set(pvt, mohinterpret, v->value);
else if (!strcasecmp(v->name, "language"))
- ast_copy_string(pvt->language, v->value, sizeof(pvt->language));
- else if (!strcasecmp(v->name, "callerid"))
- ast_callerid_split(v->value, pvt->cid_name, sizeof(pvt->cid_name),
- pvt->cid_num, sizeof(pvt->cid_num));
- else if (!strcasecmp(v->name, "overridecontext"))
+ ast_string_field_set(pvt, language, v->value);
+ else if (!strcasecmp(v->name, "callerid")) {
+ char cid_name[256];
+ char cid_num[256];
+ ast_callerid_split(v->value, cid_name, sizeof(cid_name),
+ cid_num, sizeof(cid_num));
+ ast_string_field_set(pvt, cid_name, cid_name);
+ ast_string_field_set(pvt, cid_num, cid_num);
+ } else if (!strcasecmp(v->name, "overridecontext"))
pvt->overridecontext = ast_true(v->value) ? 1 : 0;
else if (!strcasecmp(v->name, "autoanswer"))
pvt->autoanswer = ast_true(v->value) ? 1 : 0;
@@ -988,7 +1011,11 @@
}
ast_config_destroy(cfg);
- return 0;
+ res = 0;
+
+return_unlock:
+ ast_mutex_unlock(&pvt->lock);
+ return res;
}
static int unload_module(void)
@@ -1002,6 +1029,7 @@
ast_channel_unregister(&console_tech);
ast_cli_unregister_multiple(cli_console, sizeof(cli_console) / sizeof(cli_console[0]));
+ ast_string_field_free_pools(pvt);
ast_cond_destroy(&pvt->cond);
return 0;
More information about the asterisk-commits
mailing list