Hi,
On Thu, 2012-04-12 at 17:16 +0000, Julien Massot wrote:
> -void __connman_service_set_passphrase(struct connman_service *service,
> +int __connman_service_set_passphrase(struct connman_service *service,
> const char* passphrase)
Is the int return value used anywhere?
> {
> + int err = 0;
> + guint i;
> + gsize length;
> +
> if (service->immutable == TRUE || service->hidden == TRUE)
> - return;
> + return -EINVAL;
>
> - g_free(service->passphrase);
> - service->passphrase = g_strdup(passphrase);
> + if (passphrase != NULL) {
> + length = strlen(passphrase);
> + if (service->security == CONNMAN_SERVICE_SECURITY_PSK) {
> + /* A raw key is always 64 bytes length,
> + * its content is in hex representation.
> + * A PSK key must be between [8..63].
> + */
> + if (length == 64) {
> + for (i = 0; i < 64; i++)
> + if (!isxdigit((unsigned char)
> + passphrase[i]))
> + err = -ENOKEY;
> + } else if (length < 8 || length > 63)
> + err = -ENOKEY;
> +
> + } else if (service->security == CONNMAN_SERVICE_SECURITY_WEP) {
> + /* length of WEP key is 10 or 26
> + * length of WEP passphrase is 5 or 13
> + */
> + if (length == 10 || length == 26) {
> + for (i = 0; i < length; i++)
> + if (!isxdigit((unsigned char)
> + passphrase[i]))
> + err = -ENOKEY;
> + } else if (length != 5 && length != 13)
> + err = -ENOKEY;
> + }
> + }
This would be easier to read if you could factor out passphrase length
checking into a function of its own and in that function use a switch
statement to do the checking according to security. And then you would
not need to pass the whole service struct either.
Cheers,
Patrik
_______________________________________________
connman mailing list
[email protected]
http://lists.connman.net/listinfo/connman