diff --git a/common.c b/common.c index 7d5a3cd9159504daa016957a57a212ceef640b6c..2a1260356eb343c0c81359be97aaaef6084e17e3 100644 --- a/common.c +++ b/common.c @@ -127,10 +127,10 @@ fail_doc_ptr: } -int isdigits(const char *pin) +int isdigits(const char *str) { - while (*pin) { - if (isdigit(*pin++) == 0) + while (*str) { + if (isdigit(*str++) == 0) return false; } @@ -220,3 +220,14 @@ int check_response(struct json_object *response) fail: return -1; } + +void remove_newline(char *input) +{ + char *pos; + + pos = strchr(input, '\n'); + if (!pos) + return; + + *pos = '\0'; +} diff --git a/common.h b/common.h index 2bb6c43b3a22864c24c7048acffe3136e34c4862..54b4e5dc0899b79285e9a4212edb1e0509a6addd 100644 --- a/common.h +++ b/common.h @@ -75,8 +75,34 @@ void json_to_blob(struct json_object *response, struct blob_buf *bb); char *xml_parser(struct write_result *result, char *tag); struct json_object *xml_to_json_converter(struct write_result *result); -int isdigits(const char *pin); + +/** + * Function: isdigits + * + * Checks if a string is made up entirely out of digits. + * + * Parameters: + * str - the string to check for digits. + * + * Returns: + * true if the string is made up entirely out of digits. + * false if the string contains any non-digit character. + */ +int isdigits(const char *str); int validate_puk_format(char *puk); + +/** + * Function: validate_pin_format + * + * Checks whether a given PIN code is of valid format or not. + * + * Parameters: + * pin - the string to check for structure validity + * + * Returns: + * 0 if the string is of valid format. + * -1 on invalid format. + */ int validate_pin_format(char *pin); int pin_status(struct blob_buf *bb, struct device *dev); int check_response(struct json_object *response);