--- include/types.h | 2 +- src/common.c | 38 +++++++++++++++++++++++++++++++++----- src/common.h | 1 + 3 files changed, 35 insertions(+), 6 deletions(-)
diff --git a/include/types.h b/include/types.h index ba2481f..b3d2247 100644 --- a/include/types.h +++ b/include/types.h @@ -76,7 +76,7 @@ struct ofono_error { int error; }; -#define OFONO_MAX_PHONE_NUMBER_LENGTH 20 +#define OFONO_MAX_PHONE_NUMBER_LENGTH 120 struct ofono_phone_number { char number[OFONO_MAX_PHONE_NUMBER_LENGTH + 1]; diff --git a/src/common.c b/src/common.c index b5b9a6f..56a6aa8 100644 --- a/src/common.c +++ b/src/common.c @@ -262,6 +262,34 @@ gboolean valid_phone_number_format(const char *number) return TRUE; } +gboolean valid_dial_string(const char *number) +{ + int len = strlen(number); + int begin = 0; + int i; + + if (!len) + return FALSE; + + if (number[0] == '+') + begin = 1; + + if ((len - begin) > OFONO_MAX_PHONE_NUMBER_LENGTH) + return FALSE; + + for (i = begin; i < len; i++) { + if (number[i] >= '0' && number[i] <= '9') + continue; + + if (number[i] == '*' || number[i] == '#' || number[i] == 'p') + continue; + + return FALSE; + } + + return TRUE; +} + const char *telephony_error_to_str(const struct ofono_error *error) { struct error_entry *e; @@ -379,18 +407,18 @@ int mmi_service_code_to_bearer_class(int code) const char *phone_number_to_string(const struct ofono_phone_number *ph) { - static char buffer[64]; + static char buffer[(OFONO_MAX_PHONE_NUMBER_LENGTH + 1) + 1]; if (ph->type == 145 && (strlen(ph->number) > 0) && ph->number[0] != '+') { buffer[0] = '+'; - strncpy(buffer + 1, ph->number, 62); - buffer[63] = '\0'; + strncpy(buffer + 1, ph->number, sizeof(buffer) - 2); } else { - strncpy(buffer, ph->number, 63); - buffer[63] = '\0'; + strncpy(buffer, ph->number, sizeof(buffer) - 1); } + buffer[sizeof(buffer) - 1] = '\0'; + return buffer; } diff --git a/src/common.h b/src/common.h index 8b5798a..c7bfe26 100644 --- a/src/common.h +++ b/src/common.h @@ -125,6 +125,7 @@ enum pin_type { const char *telephony_error_to_str(const struct ofono_error *error); gboolean valid_phone_number_format(const char *number); +gboolean valid_dial_string(const char *number); const char *phone_number_to_string(const struct ofono_phone_number *ph); void string_to_phone_number(const char *str, struct ofono_phone_number *ph); -- 1.7.0.4 _______________________________________________ ofono mailing list ofono@ofono.org http://lists.ofono.org/listinfo/ofono