diff --git a/src/cache.c b/src/cache.c index 8e81680..abbf2c3 100644 --- a/src/cache.c +++ b/src/cache.c @@ -234,7 +234,7 @@ int cache_update_entry(int entry_num, const char *filename, const char *webroot) char type_new[24]; sprintf(type_new, "%s", type); if (strcmp(type, "text/plain") == 0) { - if (strncmp(filename + strlen(filename) - 4, ".css", 4) == 0) { + if (strcmp(filename + strlen(filename) - 4, ".css") == 0) { sprintf(type_new, "text/css"); } else if (strcmp(filename + strlen(filename) - 3, ".js") == 0) { sprintf(type_new, "text/javascript"); diff --git a/src/client.c b/src/client.c index 9f624b5..222cb0b 100644 --- a/src/client.c +++ b/src/client.c @@ -99,7 +99,7 @@ int client_request_handler(sock *client, unsigned long client_num, unsigned int } hdr_connection = http_get_header_field(&req.hdr, "Connection"); - client_keep_alive = hdr_connection != NULL && strncmp(hdr_connection, "keep-alive", 10) == 0; + client_keep_alive = hdr_connection != NULL && strcmp(hdr_connection, "keep-alive") == 0; host = http_get_header_field(&req.hdr, "Host"); if (host == NULL || strchr(host, '/') != NULL) { res.status = http_get_status(400); @@ -193,7 +193,7 @@ int client_request_handler(sock *client, unsigned long client_num, unsigned int char *if_modified_since = http_get_header_field(&req.hdr, "If-Modified-Since"); char *if_none_match = http_get_header_field(&req.hdr, "If-None-Match"); if ((if_none_match != NULL && strstr(if_none_match, uri.meta->etag) == NULL) || (accept_if_modified_since && - if_modified_since != NULL && strncmp(if_modified_since, last_modified, strlen(last_modified)) == 0)) { + if_modified_since != NULL && strcmp(if_modified_since, last_modified) == 0)) { res.status = http_get_status(304); goto respond; } @@ -401,9 +401,9 @@ int client_request_handler(sock *client, unsigned long client_num, unsigned int } } else if (use_fastcgi) { char *transfer_encoding = http_get_header_field(&res.hdr, "Transfer-Encoding"); - int chunked = transfer_encoding != NULL && strncmp(transfer_encoding, "chunked", 7) == 0; + int chunked = transfer_encoding != NULL && strcmp(transfer_encoding, "chunked") == 0; char *content_encoding = http_get_header_field(&res.hdr, "Content-Encoding"); - int comp = content_encoding != NULL && strncmp(content_encoding, "deflate", 7) == 0; + int comp = content_encoding != NULL && strcmp(content_encoding, "deflate") == 0; int flags = (chunked ? FASTCGI_CHUNKED : 0) | (comp ? FASTCGI_COMPRESS : 0); fastcgi_send(&php_fpm, client, flags); } diff --git a/src/necronda-server.c b/src/necronda-server.c index 43dcd82..4634ba9 100644 --- a/src/necronda-server.c +++ b/src/necronda-server.c @@ -188,7 +188,7 @@ int main(int argc, const char *argv[]) { for (int i = 1; i < argc; i++) { const char *arg = argv[i]; unsigned long len = strlen(arg); - if ((len == 2 && strncmp(arg, "-h", 2) == 0) || (len == 6 && strncmp(arg, "--help", 6) == 0)) { + if (strcmp(arg, "-h") == 0 || strcmp(arg, "--help") == 0) { printf("Usage: necronda-server [-h] -w -c -p [-g ] [-d ]\n" "\n" "Options:\n" @@ -199,31 +199,31 @@ int main(int argc, const char *argv[]) { " -p, --privkey path to the private key file\n" " -w, --webroot path to the web root directory\n"); return 0; - } else if ((len == 2 && strncmp(arg, "-w", 2) == 0) || (len == 9 && strncmp(arg, "--webroot", 9) == 0)) { + } else if (strcmp(arg, "-w") == 0 || strcmp(arg, "--webroot") == 0) { if (i == argc - 1) { fprintf(stderr, ERR_STR "Unable to parse argument %s, usage: --webroot " CLR_STR "\n", arg); return 1; } webroot_base = argv[++i]; - } else if ((len == 2 && strncmp(arg, "-c", 2) == 0) || (len == 6 && strncmp(arg, "--cert", 6) == 0)) { + } else if (strcmp(arg, "-c") == 0 || strcmp(arg, "--cert") == 0) { if (i == argc - 1) { fprintf(stderr, ERR_STR "Unable to parse argument %s, usage: --cert " CLR_STR "\n", arg); return 1; } cert_file = argv[++i]; - } else if ((len == 2 && strncmp(arg, "-p", 2) == 0) || (len == 9 && strncmp(arg, "--privkey", 9) == 0)) { + } else if (strcmp(arg, "-p") == 0 || strcmp(arg, "--privkey") == 0) { if (i == argc - 1) { fprintf(stderr, ERR_STR "Unable to parse argument %s, usage: --privkey " CLR_STR "\n", arg); return 1; } key_file = argv[++i]; - } else if ((len == 2 && strncmp(arg, "-g", 2) == 0) || (len == 7 && strncmp(arg, "--geoip", 7) == 0)) { + } else if (strcmp(arg, "-g") == 0 || strcmp(arg, "--geoip") == 0) { if (i == argc - 1) { fprintf(stderr, ERR_STR "Unable to parse argument %s, usage: --geoip " CLR_STR "\n", arg); return 1; } geoip_file = argv[++i]; - } else if ((len == 2 && strncmp(arg, "-d", 2) == 0) || (len == 5 && strncmp(arg, "--dns", 5) == 0)) { + } else if (strcmp(arg, "-d") == 0 || strcmp(arg, "--dns") == 0) { if (i == argc - 1) { fprintf(stderr, ERR_STR "Unable to parse argument %s, usage: --dns " CLR_STR "\n", arg); return 1; diff --git a/src/uri.c b/src/uri.c index f31edac..c05b43e 100644 --- a/src/uri.c +++ b/src/uri.c @@ -101,9 +101,9 @@ int uri_init(http_uri *uri, const char *webroot, const char *uri_str, int dir_mo uri->filename = malloc(strlen(buf0) + 1); strcpy(uri->filename, buf0); ssize_t len = strlen(uri->path); - if (strncmp(uri->path + len - 5, ".html", 5) == 0) { + if (strcmp(uri->path + len - 5, ".html") == 0) { uri->path[len - 5] = 0; - } else if (strncmp(uri->path + len - 4, ".php", 4) == 0) { + } else if (strcmp(uri->path + len - 4, ".php") == 0) { uri->path[len - 4] = 0; uri->is_static = 0; }