mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-13 16:21:01 +00:00
simplify ast_strings_to_mask
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@45505 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -775,10 +775,10 @@ void astman_send_ack(struct mansession *s, struct message *m, char *msg)
|
|||||||
|
|
||||||
/*! Tells you if smallstr exists inside bigstr
|
/*! Tells you if smallstr exists inside bigstr
|
||||||
which is delim by delim and uses no buf or stringsep
|
which is delim by delim and uses no buf or stringsep
|
||||||
ast_instring("this|that|more","this",',') == 1;
|
ast_instring("this|that|more","this",'|') == 1;
|
||||||
|
|
||||||
feel free to move this to app.c -anthm */
|
feel free to move this to app.c -anthm */
|
||||||
static int ast_instring(const char *bigstr, const char *smallstr, char delim)
|
static int ast_instring(const char *bigstr, const char *smallstr, const char delim)
|
||||||
{
|
{
|
||||||
const char *val = bigstr, *next;
|
const char *val = bigstr, *next;
|
||||||
|
|
||||||
@@ -811,36 +811,26 @@ static int get_perm(const char *instr)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ast_is_number(char *string)
|
/*
|
||||||
{
|
* A number returns itself, false returns 0, true returns all flags,
|
||||||
int ret = 1, x = 0;
|
* other strings return the flags that are set.
|
||||||
|
*/
|
||||||
if (!string)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
for (x = 0; x < strlen(string); x++) {
|
|
||||||
if (!(string[x] >= 48 && string[x] <= 57)) {
|
|
||||||
ret = 0;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret ? atoi(string) : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int ast_strings_to_mask(char *string)
|
static int ast_strings_to_mask(char *string)
|
||||||
{
|
{
|
||||||
int x, ret = -1;
|
int x, ret = 0;
|
||||||
|
char *p;
|
||||||
x = ast_is_number(string);
|
|
||||||
|
|
||||||
if (x)
|
if (ast_strlen_zero(string))
|
||||||
ret = x;
|
return -1;
|
||||||
else if (ast_strlen_zero(string))
|
|
||||||
ret = -1;
|
for (p = string; *p; p++)
|
||||||
else if (ast_false(string))
|
if (*p < '0' || *p > '9')
|
||||||
ret = 0;
|
break;
|
||||||
else if (ast_true(string)) {
|
if (!p)
|
||||||
|
return atoi(string);
|
||||||
|
if (ast_false(string))
|
||||||
|
return 0;
|
||||||
|
if (ast_true(string)) { /* all permissions */
|
||||||
ret = 0;
|
ret = 0;
|
||||||
for (x=0; x<sizeof(perms) / sizeof(perms[0]); x++)
|
for (x=0; x<sizeof(perms) / sizeof(perms[0]); x++)
|
||||||
ret |= perms[x].num;
|
ret |= perms[x].num;
|
||||||
|
Reference in New Issue
Block a user