2010-10-24 22:57:03 +00:00
|
|
|
/* radare - LGPL - Copyright 2009-2010 pancake<nopcode.org> */
|
2009-02-05 21:08:46 +00:00
|
|
|
|
2010-10-24 22:57:03 +00:00
|
|
|
#include <r_util.h>
|
2009-02-05 21:08:46 +00:00
|
|
|
|
|
|
|
#define IS_PRINTABLE(x) (x>=' '&&x<='~')
|
|
|
|
|
2011-06-04 03:27:26 +00:00
|
|
|
static int r_name_validate_char(const char ch) {
|
2010-08-16 12:58:10 +00:00
|
|
|
switch (ch) {
|
2009-02-05 21:08:46 +00:00
|
|
|
case '*':
|
|
|
|
case '/':
|
|
|
|
case '+':
|
2010-06-20 22:48:06 +00:00
|
|
|
case '|':
|
|
|
|
case '&':
|
|
|
|
case ';':
|
2011-03-05 18:09:38 +00:00
|
|
|
case ':':
|
2010-06-20 22:48:06 +00:00
|
|
|
case '>':
|
|
|
|
case '<':
|
2010-08-16 12:58:10 +00:00
|
|
|
case '"':
|
|
|
|
case '#':
|
|
|
|
case '%':
|
|
|
|
case '(':
|
|
|
|
case ')':
|
2010-06-20 22:48:06 +00:00
|
|
|
case '`':
|
|
|
|
case '\'':
|
2009-02-05 21:08:46 +00:00
|
|
|
case '-':
|
|
|
|
case ' ':
|
|
|
|
case '\n':
|
|
|
|
case '\t':
|
|
|
|
case '[':
|
2010-08-16 12:58:10 +00:00
|
|
|
case ']':
|
2009-02-05 21:08:46 +00:00
|
|
|
case '@':
|
|
|
|
return 0;
|
|
|
|
default:
|
|
|
|
if (((ch >= '0') && (ch <= '9')))
|
2011-03-18 08:35:02 +00:00
|
|
|
return R_TRUE;
|
2010-03-08 11:45:22 +00:00
|
|
|
if (!IS_PRINTABLE (ch))
|
2011-03-18 08:35:02 +00:00
|
|
|
return R_FALSE;
|
2009-02-05 21:08:46 +00:00
|
|
|
}
|
2011-03-18 08:35:02 +00:00
|
|
|
return R_TRUE;
|
2009-02-05 21:08:46 +00:00
|
|
|
}
|
|
|
|
|
2011-06-04 03:27:26 +00:00
|
|
|
R_API int r_name_check(const char *name) {
|
2009-02-05 21:08:46 +00:00
|
|
|
if (name[0]=='\0')
|
2011-03-18 08:35:02 +00:00
|
|
|
return R_FALSE;
|
2010-04-09 11:24:40 +00:00
|
|
|
for (;*name!='\0'; name++)
|
2011-06-04 03:27:26 +00:00
|
|
|
if (!r_name_validate_char (*name))
|
2011-03-18 08:35:02 +00:00
|
|
|
return R_FALSE;
|
|
|
|
return R_TRUE;
|
2009-02-05 21:08:46 +00:00
|
|
|
}
|
|
|
|
|
2011-06-04 03:27:26 +00:00
|
|
|
R_API int r_name_filter(char *name, int maxlen) {
|
2009-02-05 21:08:46 +00:00
|
|
|
int i;
|
|
|
|
char *oname;
|
2010-10-23 12:27:13 +00:00
|
|
|
name = oname = r_str_trim (name);
|
2011-07-19 16:03:31 +00:00
|
|
|
for (i=0; *name!='\0'; name++, i++) {
|
|
|
|
if (maxlen && i>maxlen) {
|
2009-02-05 21:08:46 +00:00
|
|
|
name[0] = '\0';
|
|
|
|
break;
|
|
|
|
}
|
2011-06-04 03:27:26 +00:00
|
|
|
if (!r_name_validate_char (*name)) {
|
2011-04-06 09:35:18 +00:00
|
|
|
r_str_ccpy (name, name+1, 0);
|
2009-02-05 21:08:46 +00:00
|
|
|
name = name -1;
|
|
|
|
}
|
|
|
|
}
|
2011-06-04 03:27:26 +00:00
|
|
|
return r_name_check (oname);
|
2009-02-05 21:08:46 +00:00
|
|
|
}
|