Skip to content

Commit 92dfd97

Browse files
committed
Use early return in snmp
This avoids the odd dangling elses.
1 parent 2237102 commit 92dfd97

File tree

1 file changed

+25
-22
lines changed

1 file changed

+25
-22
lines changed

ext/snmp/snmp.c

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -928,16 +928,18 @@ static bool netsnmp_session_set_auth_protocol(struct snmp_session *s, zend_strin
928928
if (zend_string_equals_literal_ci(prot, "MD5")) {
929929
s->securityAuthProto = usmHMACMD5AuthProtocol;
930930
s->securityAuthProtoLen = USM_AUTH_PROTO_MD5_LEN;
931-
} else
931+
return true;
932+
}
932933
#endif
934+
933935
if (zend_string_equals_literal_ci(prot, "SHA")) {
934936
s->securityAuthProto = usmHMACSHA1AuthProtocol;
935937
s->securityAuthProtoLen = USM_AUTH_PROTO_SHA_LEN;
936-
} else {
937-
zend_value_error("Authentication protocol must be either \"MD5\" or \"SHA\"");
938-
return false;
938+
return true;
939939
}
940-
return true;
940+
941+
zend_value_error("Authentication protocol must be either \"MD5\" or \"SHA\"");
942+
return false;
941943
}
942944
/* }}} */
943945

@@ -948,32 +950,33 @@ static bool netsnmp_session_set_sec_protocol(struct snmp_session *s, zend_string
948950
if (zend_string_equals_literal_ci(prot, "DES")) {
949951
s->securityPrivProto = usmDESPrivProtocol;
950952
s->securityPrivProtoLen = USM_PRIV_PROTO_DES_LEN;
951-
} else
953+
return true;
954+
}
952955
#endif
956+
953957
#ifdef HAVE_AES
954958
if (zend_string_equals_literal_ci(prot, "AES128")
955-
|| zend_string_equals_literal_ci(prot, "AES")
959+
|| zend_string_equals_literal_ci(prot, "AES")) {
956960
s->securityPrivProto = usmAESPrivProtocol;
957961
s->securityPrivProtoLen = USM_PRIV_PROTO_AES_LEN;
958-
} else
962+
return true;
963+
}
959964
#endif
960-
{
965+
961966
#ifdef HAVE_AES
962-
#ifndef NETSNMP_DISABLE_DES
963-
zend_value_error("Security protocol must be one of \"DES\", \"AES128\", or \"AES\"");
964-
#else
965-
zend_value_error("Security protocol must be one of \"AES128\", or \"AES\"");
966-
#endif
967-
#else
968-
#ifndef NETSNMP_DISABLE_DES
969-
zend_value_error("Security protocol must be \"DES\"");
967+
# ifndef NETSNMP_DISABLE_DES
968+
zend_value_error("Security protocol must be one of \"DES\", \"AES128\", or \"AES\"");
969+
# else
970+
zend_value_error("Security protocol must be one of \"AES128\", or \"AES\"");
971+
# endif
970972
#else
971-
zend_value_error("No security protocol supported");
973+
# ifndef NETSNMP_DISABLE_DES
974+
zend_value_error("Security protocol must be \"DES\"");
975+
# else
976+
zend_value_error("No security protocol supported");
977+
# endif
972978
#endif
973-
#endif
974-
return false;
975-
}
976-
return true;
979+
return false;
977980
}
978981
/* }}} */
979982

0 commit comments

Comments
 (0)