aboutsummaryrefslogtreecommitdiffstats
path: root/channels/chan_oss.c
diff options
context:
space:
mode:
authorrizzo <rizzo@f38db490-d61c-443f-a65b-d21fe96a405b>2007-12-20 12:56:07 +0000
committerrizzo <rizzo@f38db490-d61c-443f-a65b-d21fe96a405b>2007-12-20 12:56:07 +0000
commit91f1b6959dd053e976e91f50254e2205fa35eb1e (patch)
tree9d693aab885404d655ae9ef42e0bc104756aef39 /channels/chan_oss.c
parent0a8518b7c882ee0c0e954fac34fb488d42a9fc00 (diff)
add some macros to simplify parsing the config file,
see description in config.h . They are a variant of the set of macros i used in chan_oss.c, structured in a way to be more robust to the presence of spurious ';' - basically, they define wrappers for 'do {' and '} while (0)', plus some helper functions to deal with simple cases such as ast_copy_string, ast_malloc, strtoul, ast_true ... The prefix (CV_ as 'Config Variable') tries to be easy to remember and has been chosen to not conflict with other existing macros in the tree. For the time being, I have only updated the three source files in the tree that used the old M_* macros. Hopefully, more files will be converted. NOTE: I understand that inventing my own dialect of C is generally wrong; however, the lack of adequate support in the language encourages lazy programming practices (such as ignoring errors, bounds, etc.) and this increases the chance of vulnerability in the code, especially because we are parsing user input here. Hopefully, these macros and the use of ast_parse_arg (in config.h) should encourage the programmer to write more robust code. git-svn-id: http://svn.digium.com/svn/asterisk/trunk@94191 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'channels/chan_oss.c')
-rw-r--r--channels/chan_oss.c62
1 files changed, 17 insertions, 45 deletions
diff --git a/channels/chan_oss.c b/channels/chan_oss.c
index 94c114f96..14e6cdcce 100644
--- a/channels/chan_oss.c
+++ b/channels/chan_oss.c
@@ -178,34 +178,6 @@ END_CONFIG
*/
/*
- * Helper macros to parse config arguments. They will go in a common
- * header file if their usage is globally accepted. In the meantime,
- * we define them here. Typical usage is as below.
- * Remember to open a block right before M_START (as it declares
- * some variables) and use the M_* macros WITHOUT A SEMICOLON:
- *
- * {
- * M_START(v->name, v->value)
- *
- * M_BOOL("dothis", x->flag1)
- * M_STR("name", x->somestring)
- * M_F("bar", some_c_code)
- * M_END(some_final_statement)
- * ... other code in the block
- * }
- *
- * XXX NOTE these macros should NOT be replicated in other parts of asterisk.
- * Likely we will come up with a better way of doing config file parsing.
- */
-#define M_START(var, val) \
- const char *__s = var; const char *__val = val;
-#define M_END(x) x;
-#define M_F(tag, f) if (!strcasecmp((__s), tag)) { f; } else
-#define M_BOOL(tag, dst) M_F(tag, (dst) = ast_true(__val) )
-#define M_UINT(tag, dst) M_F(tag, (dst) = strtoul(__val, NULL, 0) )
-#define M_STR(tag, dst) M_F(tag, ast_copy_string(dst, __val, sizeof(dst)))
-
-/*
* The following parameters are used in the driver:
*
* FRAME_SIZE the size of an audio frame, in samples.
@@ -1559,7 +1531,7 @@ static void store_callerid(struct chan_oss_pvt *o, const char *s)
static void store_config_core(struct chan_oss_pvt *o, const char *var, const char *value)
{
- M_START(var, value);
+ CV_START(var, value);
/* handle jb conf */
if (!ast_jb_read_conf(&global_jbconf, (char *)var,(char *) value))
@@ -1567,22 +1539,22 @@ static void store_config_core(struct chan_oss_pvt *o, const char *var, const cha
if (!console_video_config(&o->env, var, value))
return;
- M_BOOL("autoanswer", o->autoanswer)
- M_BOOL("autohangup", o->autohangup)
- M_BOOL("overridecontext", o->overridecontext)
- M_STR("device", o->device)
- M_UINT("frags", o->frags)
- M_UINT("debug", oss_debug)
- M_UINT("queuesize", o->queuesize)
- M_STR("context", o->ctx)
- M_STR("language", o->language)
- M_STR("mohinterpret", o->mohinterpret)
- M_STR("extension", o->ext)
- M_F("mixer", store_mixer(o, value))
- M_F("callerid", store_callerid(o, value))
- M_F("boost", store_boost(o, value))
-
- M_END(/* */);
+ CV_BOOL("autoanswer", o->autoanswer);
+ CV_BOOL("autohangup", o->autohangup);
+ CV_BOOL("overridecontext", o->overridecontext);
+ CV_STR("device", o->device);
+ CV_UINT("frags", o->frags);
+ CV_UINT("debug", oss_debug);
+ CV_UINT("queuesize", o->queuesize);
+ CV_STR("context", o->ctx);
+ CV_STR("language", o->language);
+ CV_STR("mohinterpret", o->mohinterpret);
+ CV_STR("extension", o->ext);
+ CV_F("mixer", store_mixer(o, value));
+ CV_F("callerid", store_callerid(o, value)) ;
+ CV_F("boost", store_boost(o, value));
+
+ CV_END;
}
/*!