From: Simon Ruderich Date: Sun, 28 Jul 2013 04:14:41 +0000 (+0200) Subject: tests: Use better readable order of arguments in if. X-Git-Url: https://ruderich.org/simon/gitweb/?p=tlsproxy%2Ftlsproxy.git;a=commitdiff_plain;h=058678e898268c214fa135a3f6fb7b049f912fc2 tests: Use better readable order of arguments in if. Also simplify strcmp() condition in ifs. --- diff --git a/tests/client.c b/tests/client.c index 9bf13b5..f98711f 100644 --- a/tests/client.c +++ b/tests/client.c @@ -53,7 +53,7 @@ int main (int argc, char *argv[]) { const gnutls_datum_t *cert_list; unsigned int cert_list_size; - if (5 != argc) { + if (argc != 5) { fprintf(stderr, "Usage: %s \n", argv[0]); @@ -71,11 +71,11 @@ int main (int argc, char *argv[]) { gnutls_credentials_set(session, GNUTLS_CRD_CERTIFICATE, xcred); server = connect_to_host("localhost", "4711"); - if (-1 == server) { + if (server == -1) { return EXIT_FAILURE; } fd = fdopen(server, "a+"); - if (NULL == fd) { + if (fd == NULL) { perror("fdopen()"); return EXIT_FAILURE; } @@ -84,19 +84,19 @@ int main (int argc, char *argv[]) { fprintf(fd, "CONNECT %s:%s HTTP/1.0\r\n", argv[2], argv[3]); fprintf(fd, "\r\n"); fflush(fd); - if (-1 == read_http_request(fd, buffer, sizeof(buffer))) { + if (read_http_request(fd, buffer, sizeof(buffer)) == -1) { fprintf(stderr, "invalid proxy response\n"); return EXIT_FAILURE; } printf("response: %s\n", buffer); - if (1 != sscanf(buffer, "HTTP/1.0 %d", &response)) { + if (sscanf(buffer, "HTTP/1.0 %d", &response) != 1) { fprintf(stderr, "invalid proxy response: %s\n", buffer); return EXIT_FAILURE; } - if (200 != response) { + if (response != 200) { fprintf(stderr, "proxy failure\n"); return EXIT_FAILURE; } @@ -104,7 +104,7 @@ int main (int argc, char *argv[]) { gnutls_transport_set_ptr(session, (gnutls_transport_ptr_t)server); result = gnutls_handshake(session); - if (GNUTLS_E_SUCCESS != result) { + if (result != GNUTLS_E_SUCCESS) { fprintf(stderr, "gnutls_handshake() failed\n"); gnutls_perror(result); return EXIT_FAILURE; @@ -112,7 +112,7 @@ int main (int argc, char *argv[]) { /* Verify the proxy certificate. */ result = gnutls_certificate_verify_peers2(session, &status); - if (0 > result) { + if (result < 0) { fprintf(stderr, "gnutls_certificate_verify_peers2() failed\n"); gnutls_perror(result); return EXIT_FAILURE; @@ -123,20 +123,20 @@ int main (int argc, char *argv[]) { } /* Get proxy certificate. */ - if (0 > (result = gnutls_x509_crt_init(&cert))) { + if ((result = gnutls_x509_crt_init(&cert)) < 0) { fprintf(stderr, "gnutls_x509_crt_init() failed"); gnutls_perror(result); return EXIT_FAILURE; } cert_list = gnutls_certificate_get_peers(session, &cert_list_size); - if (NULL == cert_list) { + if (cert_list == NULL) { fprintf(stderr, "gnutls_certificate_get_peers() failed"); return EXIT_FAILURE; } - if (0 > (result = gnutls_x509_crt_import(cert, &cert_list[0], - GNUTLS_X509_FMT_DER))) { + if ((result = gnutls_x509_crt_import(cert, &cert_list[0], + GNUTLS_X509_FMT_DER)) < 0) { fprintf(stderr, "gnutls_x509_crt_import() failed"); gnutls_perror(result); return EXIT_FAILURE; @@ -171,7 +171,7 @@ static int connect_to_host(const char *hostname, const char *port) { int server_socket; struct addrinfo *server; - if (NULL == hostname || NULL == port) { + if (hostname == NULL || port == NULL) { return -1; } @@ -184,24 +184,23 @@ static int connect_to_host(const char *hostname, const char *port) { | AI_ADDRCONFIG /* supported by this computer */ | AI_V4MAPPED; /* support IPv4 through IPv6 */ gai_return = getaddrinfo(hostname, port, &gai_hints, &gai_result); - if (0 != gai_return) { + if (gai_return != 0) { perror("connect_to_host(): getaddrinfo()"); return -1; } /* Now try to connect to each server returned by getaddrinfo(), use the * first successful connect. */ - for (server = gai_result; NULL != server; server = server->ai_next) { + for (server = gai_result; server != NULL; server = server->ai_next) { server_socket = socket(server->ai_family, server->ai_socktype, server->ai_protocol); - if (-1 == server_socket) { + if (server_socket == -1) { perror("connect_to_host(): socket(), trying next"); continue; } - if (-1 != connect(server_socket, server->ai_addr, - server->ai_addrlen)) { + if (connect(server_socket, server->ai_addr, server->ai_addrlen) != -1) { break; } perror("connect_to_host(): connect(), trying next"); @@ -211,7 +210,7 @@ static int connect_to_host(const char *hostname, const char *port) { /* Make sure we free the result from getaddrinfo(). */ freeaddrinfo(gai_result); - if (NULL == server) { + if (server == NULL) { perror("connect_to_host(): no server found, abort"); return -1; } @@ -222,7 +221,7 @@ static int connect_to_host(const char *hostname, const char *port) { static int read_http_request(FILE *client_fd, char *request, size_t length) { char buffer[MAX_REQUEST_LINE]; - if (NULL == fgets(request, (int)length, client_fd)) { + if (fgets(request, (int)length, client_fd) == NULL) { if (ferror(client_fd)) { perror("read_http_request(): fgets()"); return -1; @@ -231,9 +230,9 @@ static int read_http_request(FILE *client_fd, char *request, size_t length) { return -2; } - while (NULL != fgets(buffer, MAX_REQUEST_LINE, client_fd)) { + while (fgets(buffer, MAX_REQUEST_LINE, client_fd) != NULL) { /* End of header. */ - if (0 == strcmp(buffer, "\n") || 0 == strcmp(buffer, "\r\n")) { + if (!strcmp(buffer, "\n") || !strcmp(buffer, "\r\n")) { break; } }