From ee92dc0b627ccbe6b33e27963c1fdf98aecc18b5 Mon Sep 17 00:00:00 2001 From: Denis Kenzior Date: Fri, 30 Oct 2009 15:52:29 -0500 Subject: [PATCH] Add utility to test for valid APN names --- src/common.c | 26 ++++++++++++++++++++++++++ src/common.h | 2 ++ 2 files changed, 28 insertions(+) diff --git a/src/common.c b/src/common.c index cb79334..500a8c1 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; +} diff --git a/src/common.h b/src/common.h index 1a5c9ed..f60b592 100644 --- a/src/common.h +++ b/src/common.h @@ -138,3 +138,5 @@ gboolean is_valid_pin(const char *pin); const char *registration_status_to_string(int status); const char *registration_tech_to_string(int tech); + +gboolean is_valid_apn(const char *apn); -- 2.7.4