mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-04 20:04:50 +00:00
re-implement ast_separate_app_args with clearer code and in a way that doesn't fail with certain combinations of array size and delimiter count
add doxygen docs for ast_separate_app_args git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@5566 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
29
app.c
29
app.c
@@ -1069,16 +1069,29 @@ int ast_app_group_match_get_count(char *groupmatch, char *category)
|
|||||||
|
|
||||||
int ast_separate_app_args(char *buf, char delim, char **array, int arraylen)
|
int ast_separate_app_args(char *buf, char delim, char **array, int arraylen)
|
||||||
{
|
{
|
||||||
int x = 0;
|
int x;
|
||||||
memset(array, 0, arraylen * sizeof(char *));
|
char *scan;
|
||||||
if (!buf)
|
char delims[2];
|
||||||
|
|
||||||
|
if (!buf || !array || !arraylen)
|
||||||
return 0;
|
return 0;
|
||||||
for (array[x] = buf ; x < arraylen && array[x]; x++) {
|
|
||||||
if ((array[x+1] = strchr(array[x], delim))) {
|
memset(array, 0, arraylen * sizeof(*array));
|
||||||
*array[x+1] = '\0';
|
|
||||||
array[x+1]++;
|
scan = buf;
|
||||||
}
|
delims[0] = delim;
|
||||||
|
delims[1] = '\0';
|
||||||
|
x = 0;
|
||||||
|
|
||||||
|
while (x < arraylen - 1) {
|
||||||
|
array[x] = strsep(&scan, delims);
|
||||||
|
x++;
|
||||||
|
if (!scan)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
array[x++] = scan;
|
||||||
|
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -162,7 +162,18 @@ int ast_app_group_get_count(char *group, char *category);
|
|||||||
/*! Get the current channel count of all groups that match the specified pattern and category. */
|
/*! Get the current channel count of all groups that match the specified pattern and category. */
|
||||||
int ast_app_group_match_get_count(char *groupmatch, char *category);
|
int ast_app_group_match_get_count(char *groupmatch, char *category);
|
||||||
|
|
||||||
/*! Create an argc argv type structure for app args */
|
/*!
|
||||||
|
\brief Separate a string into arguments in an array
|
||||||
|
\param buf The string to be parsed (this must be a writable copy, as it will be modified)
|
||||||
|
\param delim The character to be used to delimit arguments
|
||||||
|
\param array An array of 'char *' to be filled in with pointers to the found arguments
|
||||||
|
\param arraylen The number of elements in the array (i.e. the number of arguments you will accept)
|
||||||
|
|
||||||
|
Note: if there are more arguments in the string than the array will hold, the last element of
|
||||||
|
the array will contain the remaining arguments, not separated.
|
||||||
|
|
||||||
|
\return The number of arguments found, or zero if the function arguments are not valid.
|
||||||
|
*/
|
||||||
int ast_separate_app_args(char *buf, char delim, char **array, int arraylen);
|
int ast_separate_app_args(char *buf, char delim, char **array, int arraylen);
|
||||||
|
|
||||||
/*! Present a dialtone and collect a certain length extension. Returns 1 on valid extension entered, -1 on hangup, or 0 on invalid extension. Note that if 'collect' holds digits already, new digits will be appended, so be sure it's initialized properly */
|
/*! Present a dialtone and collect a certain length extension. Returns 1 on valid extension entered, -1 on hangup, or 0 on invalid extension. Note that if 'collect' holds digits already, new digits will be appended, so be sure it's initialized properly */
|
||||||
|
Reference in New Issue
Block a user