diff options
author | Denis Kenzior <denkenz@gmail.com> | 2009-10-30 15:52:29 -0500 |
---|---|---|
committer | Denis Kenzior <denkenz@gmail.com> | 2009-10-30 15:52:29 -0500 |
commit | ee92dc0b627ccbe6b33e27963c1fdf98aecc18b5 (patch) | |
tree | df1882da81b3646b15d419e670f52a477b215ec7 /src/common.c | |
parent | cc5701c76f51d3259dfadf8f55faf213925d4a98 (diff) | |
download | ofono-ee92dc0b627ccbe6b33e27963c1fdf98aecc18b5.tar.bz2 |
Add utility to test for valid APN names
Diffstat (limited to 'src/common.c')
-rw-r--r-- | src/common.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/common.c b/src/common.c index cb793347..500a8c1b 100644 --- a/src/common.c +++ b/src/common.c @@ -641,3 +641,29 @@ const char *registration_tech_to_string(int tech) return ""; } } + +gboolean is_valid_apn(const char *apn) +{ + int i; + int last_period = 0; + + if (apn[0] == '.' || apn[0] == '\0') + return FALSE; + + for (i = 0; apn[i] != '\0'; i++) { + if (g_ascii_isalnum(apn[i])) + continue; + + if (apn[i] == '-') + continue; + + if (apn[i] == '.' && (i - last_period) > 1) { + last_period = i; + continue; + } + + return FALSE; + } + + return TRUE; +} |