]> Nishi Git Mirror - libw3.git/commitdiff
formatting, and changed the url of git repo
authornishi <nishi@d27a3e52-49c5-7645-884c-6793ebffc270>
Fri, 1 Mar 2024 14:07:57 +0000 (14:07 +0000)
committernishi <nishi@d27a3e52-49c5-7645-884c-6793ebffc270>
Fri, 1 Mar 2024 14:07:57 +0000 (14:07 +0000)
git-svn-id: file:///raid/svn-main/nishi-libw3/trunk@259 d27a3e52-49c5-7645-884c-6793ebffc270

Example/httpd/httpd.c
README
W3Version.h.m4

index 73c4750ef400528e1203eaa5b7890e16d12bd743..bbaf8e7669265698836c2c0c52399cfd53360bb9 100644 (file)
@@ -8,18 +8,18 @@
 #include <W3HTTP.h>
 #include <W3Util.h>
 
+#include <arpa/inet.h>
 #include <dirent.h>
+#include <netinet/in.h>
+#include <netinet/tcp.h>
+#include <signal.h>
 #include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <sys/socket.h>
 #include <sys/stat.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
 #include <unistd.h>
-#include <netinet/tcp.h>
-#include <signal.h>
 
 char* root = NULL;
 
@@ -150,7 +150,7 @@ response : {
                        if(path[strlen(path) - 1] == '/') {
                                struct stat old_s = s;
                                char* index = __W3_Concat(path, "index.html");
-                               if(stat(index, &s)){
+                               if(stat(index, &s)) {
                                        send(sock, "HTTP/1.1 200 OK\r\n", 17, 0);
                                        send(sock, "Connection: close\r\n", 19, 0);
                                        char* length = malloc(1025);
@@ -328,7 +328,7 @@ response : {
                                send(sock, "\r\n", 2, 0);
                                if(strcasecmp(method, "HEAD") != 0) send(sock, html, strlen(html), 0);
                                free(html);
-out:;
+                       out:;
                        } else {
                                send(sock, "HTTP/1.1 308 Permanent Redirect\r\n", 33, 0);
                                send(sock, "Connection: close\r\n", 19, 0);
@@ -497,7 +497,7 @@ int main(int argc, char** argv) {
                                                }
                                                if(root != NULL) free(root);
                                                root = __W3_Strdup(line + j + 1);
-                                       }else if(strcasecmp(line, "Port") == 0) {
+                                       } else if(strcasecmp(line, "Port") == 0) {
                                                if(!hasparam) {
                                                        fprintf(stderr, "%s: config line %d, directive needs a parameter\n", argv[0], linenum);
                                                        err++;
@@ -561,50 +561,57 @@ int main(int argc, char** argv) {
        int exitcode = 0;
        int port = atoi(portstr);
        int server_socket;
-       if((server_socket = socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP)) < 0){
-               return -1;goto exitnow;
+       if((server_socket = socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP)) < 0) {
+               return -1;
+               goto exitnow;
        }
        struct sockaddr_in6 server_address;
-       if((server_socket = socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP)) < 0){
-               return -1;goto exitnow;
+       if((server_socket = socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP)) < 0) {
+               return -1;
+               goto exitnow;
        }
        int yes = 1;
-       if(setsockopt(server_socket, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)) < 0){
+       if(setsockopt(server_socket, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)) < 0) {
                close(server_socket);
-               return -1;goto exitnow;
+               return -1;
+               goto exitnow;
        }
-       if(setsockopt(server_socket, IPPROTO_TCP, TCP_NODELAY, &yes, sizeof(yes)) < 0){
+       if(setsockopt(server_socket, IPPROTO_TCP, TCP_NODELAY, &yes, sizeof(yes)) < 0) {
                close(server_socket);
-               return 1;goto exitnow;
+               return 1;
+               goto exitnow;
        }
        int no = 0;
-       if(setsockopt(server_socket, IPPROTO_IPV6, IPV6_V6ONLY, &no, sizeof(no)) < 0){
+       if(setsockopt(server_socket, IPPROTO_IPV6, IPV6_V6ONLY, &no, sizeof(no)) < 0) {
                close(server_socket);
-               return 1;goto exitnow;
+               return 1;
+               goto exitnow;
        }
        memset(&server_address, 0, sizeof(server_address));
        server_address.sin6_family = AF_INET6;
        server_address.sin6_addr = in6addr_any;
        server_address.sin6_port = htons(port);
-       if(bind(server_socket, (struct sockaddr*)&server_address, sizeof(server_address)) < 0){
+       if(bind(server_socket, (struct sockaddr*)&server_address, sizeof(server_address)) < 0) {
                close(server_socket);
-               return -1;goto exitnow;
+               return -1;
+               goto exitnow;
        }
-       if(listen(server_socket, 128) < 0){
+       if(listen(server_socket, 128) < 0) {
                close(server_socket);
-               return -1;goto exitnow;
+               return -1;
+               goto exitnow;
        }
        signal(SIGCHLD, SIG_IGN);
        __W3_Debug("HTTPd", "Ready");
-       while(1){
+       while(1) {
                struct sockaddr_in claddr;
                int clen = sizeof(claddr);
                int sock = accept(server_socket, (struct sockaddr*)&claddr, &clen);
                pid_t p = fork();
-               if(p == 0){
+               if(p == 0) {
                        http_handler(sock);
                        _exit(-1);
-               }else{
+               } else {
                        close(sock);
                }
        }
diff --git a/README b/README
index 64e0648e0b029f2083f5ada8c8b9809cb6a6d5ef..73402c2ae303fc5a8f93131a32ad9709e7c4fbe7 100644 (file)
--- a/README
+++ b/README
@@ -6,7 +6,7 @@ Main repository: http://sw.nishi.boats/sw/~nishi/libw3
 Website:         http://nishi.boats/libw3
 
 Mirrors at:
-1. https://github.com/j-eoeo/libw3
+1. https://github.com/nissmick/libw3
    Do not send the pull requests to this! Just send me email.
 
 Example applications:
index 301191d14ac008ffbd39517971f332d411503717..e7bd535249264194d6b735b15d631c7165121f39 100644 (file)
@@ -6,7 +6,7 @@
 extern "C" {
 #endif
 
-#define LIBW3_VERSION "2.20B" \
+#define LIBW3_VERSION "2.20C" \
 SUFFIX
 
 ifdef(`HTTP_SUPPORT', `#define LIBW3_HTTP_SUPPORT', `')