scanimage: Improve readability of auth_callback implementation

Rather than repeatedly calling `strchr`, use descriptive variables to
hold the result.
merge-requests/213/head
Olaf Meeuwissen 2019-12-28 18:26:43 +09:00
rodzic 5e6a111ffa
commit 6682223b26
1 zmienionych plików z 12 dodań i 11 usunięć

Wyświetl plik

@ -205,27 +205,28 @@ auth_callback (SANE_String_Const resource,
if ((strlen (tmp) > 0) && (tmp[strlen (tmp) - 1] == '\r'))
tmp[strlen (tmp) - 1] = 0;
if (strchr (tmp, ':') != NULL)
char *colon1 = strchr (tmp, ':');
if (colon1 != NULL)
{
if (strchr (strchr (tmp, ':') + 1, ':') != NULL)
char *colon2 = strchr (colon1 + 1, ':');
if (colon2 != NULL)
{
if ((strncmp (strchr (strchr (tmp, ':') + 1, ':') + 1, resource, len) == 0)
&& ((int) strlen (strchr (strchr (tmp, ':') + 1, ':') + 1) == len))
if ((strncmp (colon2 + 1, resource, len) == 0)
&& ((int) strlen (colon2 + 1) == len))
{
if ((strchr (tmp, ':') - tmp) < SANE_MAX_USERNAME_LEN)
if ((colon1 - tmp) < SANE_MAX_USERNAME_LEN)
{
if ((strchr (strchr (tmp, ':') + 1, ':') - (strchr (tmp, ':') + 1)) < SANE_MAX_PASSWORD_LEN)
if ((colon2 - (colon1 + 1)) < SANE_MAX_PASSWORD_LEN)
{
strncpy (username, tmp, strchr (tmp, ':') - tmp);
username[strchr (tmp, ':') - tmp] = 0;
strncpy (username, tmp, colon1 - tmp);
username[colon1 - tmp] = 0;
strncpy (password, strchr (tmp, ':') + 1, strchr (strchr (tmp, ':') + 1, ':') - (strchr (tmp, ':') + 1));
password[strchr (strchr (tmp, ':') + 1, ':') - (strchr (tmp, ':') + 1)] = 0;
strncpy (password, colon1 + 1, colon2 - (colon1 + 1));
password[colon2 - (colon1 + 1)] = 0;
query_user = 0;
break;