]> Nishi Git Mirror - libw3.git/commitdiff
format
authornishi <nishi@d27a3e52-49c5-7645-884c-6793ebffc270>
Wed, 24 Jan 2024 11:42:23 +0000 (11:42 +0000)
committernishi <nishi@d27a3e52-49c5-7645-884c-6793ebffc270>
Wed, 24 Jan 2024 11:42:23 +0000 (11:42 +0000)
git-svn-id: file:///raid/svn-main/nishi-libw3/trunk@57 d27a3e52-49c5-7645-884c-6793ebffc270

.clang-format [new file with mode: 0644]
Example/fetch.c
Library/Core.c
Library/DNS.c
Library/File.c
Library/HTTP.c
Library/Util.c
Library/W3Core.h
Library/W3DNS.h
Library/W3File.h
Makefile

diff --git a/.clang-format b/.clang-format
new file mode 100644 (file)
index 0000000..4fbff0c
--- /dev/null
@@ -0,0 +1,11 @@
+---
+# $Id$
+Language: Cpp
+UseTab: Always
+TabWidth: 8
+IndentWidth: 8
+PointerAlignment: Left
+ColumnLimit: 1024
+AllowShortIfStatementsOnASingleLine: Always
+AllowShortLoopsOnASingleLine: True
+SpaceBeforeParens: Never
index f8a60a31095dec22df01eaa5bf86b358c5b9ea25..393ff29c54ba31993002010f97177d50871fc842 100644 (file)
 
 FILE* f;
 
-void fetch_data(struct W3* w3, char* data, size_t size){
-       fwrite(data, size, 1, f);
-}
+void fetch_data(struct W3* w3, char* data, size_t size) { fwrite(data, size, 1, f); }
 
-void status(struct W3* w3, int status){
-       fprintf(stderr, "Response code is %d\n", status);
-}
+void status(struct W3* w3, int status) { fprintf(stderr, "Response code is %d\n", status); }
 
-void header(struct W3* w3, char* key, char* value){
+void header(struct W3* w3, char* key, char* value) {
        fprintf(stderr, "Header: %s is `%s'\n", key, value);
-       if(strcasecmp(key, "Server") == 0){
+       if(strcasecmp(key, "Server") == 0) {
                /* For the example - We get the server software */
                fprintf(stderr, "Server is using `%s'\n", value);
        }
 }
 
-int main(int argc, char** argv){
-       if(argv[1] != NULL && strcmp(argv[1], "--version") == 0){
+int main(int argc, char** argv) {
+       if(argv[1] != NULL && strcmp(argv[1], "--version") == 0) {
                printf("LibW3 %s\n", LIBW3_VERSION);
                return 0;
        }
-       if(argc < 3){
+       if(argc < 3) {
                fprintf(stderr, "Usage: %s URL Path [method [data]]\n", argv[0]);
                return 1;
        }
        W3_Library_Init();
        struct W3* w3 = W3_Create("http", argv[1], 80);
-       if(w3 != NULL){
+       if(w3 != NULL) {
                W3_Set_Read_Size(w3, 1024);
                W3_Set_Method(w3, argv[3] == NULL ? "GET" : argv[3]);
                W3_Set_Path(w3, argv[2]);
@@ -47,13 +43,13 @@ int main(int argc, char** argv){
                W3_On(w3, "data", (void*)fetch_data);
                W3_On(w3, "header", (void*)header);
                f = fopen("example.bin", "wb");
-               if(argv[3] != NULL && strcmp(argv[3], "POST") == 0 && argv[4] != NULL){
+               if(argv[3] != NULL && strcmp(argv[3], "POST") == 0 && argv[4] != NULL) {
                        W3_Set_Data(w3, argv[4], strlen(argv[4]));
                }
                W3_Send_Request(w3);
                fclose(f);
                W3_Free(w3);
-       }else{
+       } else {
                fprintf(stderr, "Failed to fetch\n");
                return 1;
        }
index 1f34525f7685b54117a83c0a73f42d635b108ac0..527ac62def5a38d5fd02b0a4a7e60e2c93bc3453 100644 (file)
@@ -4,14 +4,14 @@
 #include "W3DNS.h"
 #include "W3Util.h"
 
-#include "W3HTTP.h"
 #include "W3File.h"
+#include "W3HTTP.h"
 
-#include <stdio.h>
-#include <string.h>
+#include <ctype.h>
 #include <stdbool.h>
+#include <stdio.h>
 #include <stdlib.h>
-#include <ctype.h>
+#include <string.h>
 
 #ifdef __MINGW32__
 #include <windows.h>
 #include <openssl/ssl.h>
 #endif
 
-int W3_Library_Init(void){
+int W3_Library_Init(void) {
        __W3_Debug("LibW3", "Initializing");
 #ifdef SSL_SUPPORT
-       if(SSL_library_init() >= 0){
+       if(SSL_library_init() >= 0) {
                __W3_Debug("LibW3-SSL", "Initialized");
-       }else{
+       } else {
                return 1;
        }
 #endif
@@ -43,13 +43,11 @@ int W3_Library_Init(void){
        return 0;
 }
 
-struct W3* W3_Create(const char* protocol, const char* hostname, int port){
+struct W3* W3_Create(const char* protocol, const char* hostname, int port) {
        __W3_Debug("Create", "Creating a struct");
        struct W3* w3 = malloc(sizeof(*w3));
        bool ssl = false;
-       if(
-               strcmp(protocol, "https") == 0
-       ){
+       if(strcmp(protocol, "https") == 0) {
                ssl = true;
        }
        w3->method = NULL;
@@ -64,17 +62,16 @@ struct W3* W3_Create(const char* protocol, const char* hostname, int port){
        w3->ssl = NULL;
        w3->ssl_ctx = NULL;
 #endif
-       if(strcmp(protocol, "file") != 0){
+       if(strcmp(protocol, "file") != 0) {
                w3->hostname = __W3_Strdup(hostname);
                if(ssl) __W3_Debug("Protocol", "Enabled SSL");
                w3->sock = __W3_DNS_Connect(hostname, ssl, port
 #ifdef SSL_SUPPORT
-               ,
-               &w3->ssl,
-               &w3->ssl_ctx
+                                           ,
+                                           &w3->ssl, &w3->ssl_ctx
 #endif
                );
-               if(w3->sock == -1){
+               if(w3->sock == -1) {
                        W3_Free(w3);
                        w3 = NULL;
                }
@@ -82,108 +79,108 @@ struct W3* W3_Create(const char* protocol, const char* hostname, int port){
        return w3;
 }
 
-void W3_Set_Read_Size(struct W3* w3, size_t size){
-       w3->readsize = size;
-}
+void W3_Set_Read_Size(struct W3* w3, size_t size) { w3->readsize = size; }
 
-void W3_Set_Method(struct W3* w3, const char* method){
+void W3_Set_Method(struct W3* w3, const char* method) {
        if(w3->method != NULL) free(w3->method);
        w3->method = __W3_Strdup(method);
 }
 
-void W3_Set_Path(struct W3* w3, const char* path){
+void W3_Set_Path(struct W3* w3, const char* path) {
        if(w3->path != NULL) free(w3->path);
        w3->path = __W3_Strdup(path);
 }
 
-void W3_Send_Request(struct W3* w3){
-       if(strcmp(w3->protocol, "http") == 0 || strcmp(w3->protocol, "https") == 0){
+void W3_Send_Request(struct W3* w3) {
+       if(strcmp(w3->protocol, "http") == 0 || strcmp(w3->protocol, "https") == 0) {
                __W3_HTTP_Request(w3);
-       }else if(strcmp(w3->protocol, "file") == 0){
+       } else if(strcmp(w3->protocol, "file") == 0) {
                __W3_File_Request(w3);
        }
 }
 
-void W3_Set_Data(struct W3* w3, char* data, size_t size){
+void W3_Set_Data(struct W3* w3, char* data, size_t size) {
        w3->data = data;
        w3->size = size;
 }
 
-void W3_Set_Header(struct W3* w3, const char* key, const char* value){
+void W3_Set_Header(struct W3* w3, const char* key, const char* value) {
        char* tmp = __W3_Concat3("Setting the header `", key, "` to `");
        char* str = __W3_Concat3(tmp, value, "`");
        free(tmp);
        __W3_Debug("Header", str);
        free(str);
        int len = 0;
-       if(w3->headers == NULL){
+       if(w3->headers == NULL) {
                w3->headers = malloc(sizeof(*w3->headers) * (len + 3));
                w3->headers[len] = __W3_Strdup(key);
                w3->headers[len + 1] = __W3_Strdup(value);
                int i;
-               for(i = 0; w3->headers[len][i] != 0; i++){
+               for(i = 0; w3->headers[len][i] != 0; i++) {
                        w3->headers[len][i] = tolower(w3->headers[len][i]);
                }
                w3->headers[len + 2] = NULL;
-       }else{
-               for(len = 0; w3->headers[len] != NULL; len++);
+       } else {
+               for(len = 0; w3->headers[len] != NULL; len++)
+                       ;
                char** headers = w3->headers;
                w3->headers = malloc(sizeof(*w3->headers) * (len + 3));
-               for(len = 0; headers[len] != NULL; len++){
+               for(len = 0; headers[len] != NULL; len++) {
                        w3->headers[len] = headers[len];
                }
                w3->headers[len] = __W3_Strdup(key);
                w3->headers[len + 1] = __W3_Strdup(value);
                w3->headers[len + 2] = NULL;
                int i;
-               for(i = 0; w3->headers[len][i] != 0; i++){
+               for(i = 0; w3->headers[len][i] != 0; i++) {
                        w3->headers[len][i] = tolower(w3->headers[len][i]);
                }
                free(headers);
        }
 }
 
-void W3_On(struct W3* w3, const char* eventname, void* func){
+void W3_On(struct W3* w3, const char* eventname, void* func) {
        int len = 0;
-       if(w3->events == NULL){
+       if(w3->events == NULL) {
                w3->events = malloc(sizeof(*w3->events) * (len + 3));
                w3->events[len] = __W3_Strdup(eventname);
                w3->events[len + 1] = func;
                int i;
-               for(i = 0; ((char*)w3->events[len])[i] != 0; i++){
+               for(i = 0; ((char*)w3->events[len])[i] != 0; i++) {
                        ((char*)w3->events[len])[i] = tolower(((char*)w3->events[len])[i]);
                }
                w3->events[len + 2] = NULL;
-       }else{
-               for(len = 0; w3->events[len] != NULL; len++);
+       } else {
+               for(len = 0; w3->events[len] != NULL; len++)
+                       ;
                void** events = w3->events;
                w3->events = malloc(sizeof(*w3->events) * (len + 3));
-               for(len = 0; events[len] != NULL; len++){
+               for(len = 0; events[len] != NULL; len++) {
                        w3->events[len] = events[len];
                }
                w3->events[len] = __W3_Strdup(eventname);
                w3->events[len + 1] = func;
                w3->events[len + 2] = NULL;
                int i;
-               for(i = 0; ((char*)w3->events[len])[i] != 0; i += 2){
+               for(i = 0; ((char*)w3->events[len])[i] != 0; i += 2) {
                        ((char*)w3->events[len])[i] = tolower(((char*)w3->events[len])[i]);
                }
                free(events);
        }
 }
 
-void W3_Free(struct W3* w3){
+void W3_Free(struct W3* w3) {
        __W3_Debug("LibW3", "Freeing");
        if(w3->method != NULL) free(w3->method);
        if(w3->path != NULL) free(w3->path);
        if(w3->protocol != NULL) free(w3->protocol);
        if(w3->hostname != NULL) free(w3->hostname);
-       if(w3->headers != NULL){
+       if(w3->headers != NULL) {
                int i;
                for(i = 0; w3->headers[i] != 0; i++) free(w3->headers[i]);
                free(w3->headers);
        }
-       if(w3->events != NULL){
+       if(w3->events != NULL) {
                int i;
                for(i = 0; w3->events[i] != 0; i += 2) free(w3->events[i]);
                free(w3->events);
index ed29f21894d5388e9af24e4ebd077abdb50d7f6f..4efabfbc0092f86337213d7ffc5a8edb168750f6 100644 (file)
@@ -7,17 +7,17 @@
 #include <string.h>
 
 #ifdef __MINGW32__
+#include <windows.h>
 #include <winsock2.h>
 #include <ws2tcpip.h>
-#include <windows.h>
 #else
-#include <sys/socket.h>
 #include <netdb.h>
+#include <sys/socket.h>
 #endif
 
+#include <stdbool.h>
 #include <stdint.h>
 #include <stdio.h>
-#include <stdbool.h>
 #include <unistd.h>
 
 #ifdef SSL_SUPPORT
 
 int __W3_DNS_Connect(const char* hostname, bool ssl, uint16_t port
 #ifdef SSL_SUPPORT
-       ,
-       void** o_ssl,
-       void** o_ctx
+                    ,
+                    void** o_ssl, void** o_ctx
 #endif
-){
+) {
        __W3_Debug("DNS-Connect", "Resolving");
        ADDRINFO hints;
        ADDRINFO* result;
@@ -50,13 +49,13 @@ int __W3_DNS_Connect(const char* hostname, bool ssl, uint16_t port
        memset(strport, 0, 6);
        sprintf(strport, "%d", port);
        s = getaddrinfo(hostname, strport, &hints, &result);
-       if(s != 0){
+       if(s != 0) {
                free(strport);
                __W3_Debug("Resolve", "Failed");
-               return -1;      /* Failed to resolve */
+               return -1; /* Failed to resolve */
        }
        int sock;
-       for(rp = result; rp != NULL; rp = rp->ai_next){
+       for(rp = result; rp != NULL; rp = rp->ai_next) {
                sock = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
                if(sock == -1) continue;
                int nzero = 0;
@@ -66,26 +65,26 @@ int __W3_DNS_Connect(const char* hostname, bool ssl, uint16_t port
        }
        freeaddrinfo(result);
        free(strport);
-       if(rp == NULL){
+       if(rp == NULL) {
                __W3_Debug("Connect", "Failed to connect");
-               return -1;      /* Failed to connect */
+               return -1; /* Failed to connect */
        }
        __W3_Debug("Connect", "Conencted");
 #ifdef SSL_SUPPORT
-       if(ssl){
+       if(ssl) {
                __W3_Debug("SSL", "Initializing");
                const SSL_METHOD* method = TLSv1_2_client_method();
                *o_ctx = SSL_CTX_new(method);
                *o_ssl = SSL_new(*o_ctx);
                SSL_set_fd(*o_ssl, sock);
-               if(SSL_connect(*o_ssl) != 1){
+               if(SSL_connect(*o_ssl) != 1) {
                        SSL_CTX_free(*o_ctx);
                        SSL_free(*o_ssl);
                        *o_ctx = NULL;
                        *o_ssl = NULL;
                        close(sock);
                        sock = -1;
-               }else{
+               } else {
                        __W3_Debug("SSL", "Connected");
                }
        }
index be0e9f6773f4fc04ee0c938936f6ed80e5d03e4f..98a2ce994ea618186b6c91195e5799e7be7e8e95 100644 (file)
@@ -4,32 +4,32 @@
 #include "W3Core.h"
 #include "W3Util.h"
 
-#include <stdlib.h>
 #include <stdbool.h>
-#include <string.h>
 #include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
 
-void __W3_File_Request(struct W3* w3){
+void __W3_File_Request(struct W3* w3) {
        __W3_Debug("LibW3-File", "Sending the request");
        FILE* f = fopen(w3->path, "r");
-       if(f == NULL){
+       if(f == NULL) {
                void* funcptr = __W3_Get_Event(w3, "status");
-               if(funcptr != NULL){
-                       void(*func)(struct W3*, int) = (void(*)(struct W3*, int))funcptr;
+               if(funcptr != NULL) {
+                       void (*func)(struct W3*, int) = (void (*)(struct W3*, int))funcptr;
                        func(w3, LIBW3_FILE_NOT_FOUND);
                }
-       }else{
+       } else {
                void* funcptr = __W3_Get_Event(w3, "status");
-               if(funcptr != NULL){
-                       void(*func)(struct W3*, int) = (void(*)(struct W3*, int))funcptr;
+               if(funcptr != NULL) {
+                       void (*func)(struct W3*, int) = (void (*)(struct W3*, int))funcptr;
                        func(w3, LIBW3_FILE_FOUND);
                }
                char* buf = malloc(w3->readsize);
-               while(true){
+               while(true) {
                        int len = fread(buf, 1, w3->readsize, f);
                        void* funcptr = __W3_Get_Event(w3, "data");
-                       if(funcptr != NULL){
-                               void(*func)(struct W3*, char*, size_t) = (void(*)(struct W3*, char*, size_t))funcptr;
+                       if(funcptr != NULL) {
+                               void (*func)(struct W3*, char*, size_t) = (void (*)(struct W3*, char*, size_t))funcptr;
                                char* buffer = malloc(len);
                                memcpy(buffer, buf, len);
                                func(w3, buffer, len);
index 3d722b51de13bb61c1eb8231166f82246950ace7..75e0b1952633e6ddded8aa8638ede9e9649f8203 100644 (file)
@@ -4,12 +4,12 @@
 #include "W3Core.h"
 #include "W3Util.h"
 
-#include <string.h>
-#include <stdlib.h>
-#include <stdio.h>
 #include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
 
-void __W3_HTTP_Request(struct W3* w3){
+void __W3_HTTP_Request(struct W3* w3) {
        __W3_Debug("LibW3-HTTP", "Sending the request");
        __W3_Auto_Write(w3, w3->method, strlen(w3->method));
        __W3_Auto_Write(w3, " ", 1);
@@ -20,7 +20,7 @@ void __W3_HTTP_Request(struct W3* w3){
        __W3_Auto_Write(w3, "Host: ", 6);
        __W3_Auto_Write(w3, w3->hostname, strlen(w3->hostname));
        __W3_Auto_Write(w3, "\r\n", 2);
-       if(!__W3_Have_Header(w3, "user-agent")){
+       if(!__W3_Have_Header(w3, "user-agent")) {
                __W3_Auto_Write(w3, "User-Agent: ", 12);
                __W3_Auto_Write(w3, "LibW3/", 6);
                __W3_Auto_Write(w3, LIBW3_VERSION, strlen(LIBW3_VERSION));
@@ -34,9 +34,9 @@ void __W3_HTTP_Request(struct W3* w3){
        __W3_Auto_Write(w3, "Connection: ", 12);
        __W3_Auto_Write(w3, "closed", 6);
        __W3_Auto_Write(w3, "\r\n", 2);
-       if(w3->headers != NULL){
+       if(w3->headers != NULL) {
                int i;
-               for(i = 0; w3->headers[i] != NULL; i += 2){
+               for(i = 0; w3->headers[i] != NULL; i += 2) {
                        if(strcmp(w3->headers[i], "connection") == 0) continue;
                        if(strcmp(w3->headers[i], "content-length") == 0) continue;
                        __W3_Auto_Write(w3, w3->headers[i], strlen(w3->headers[i]));
@@ -45,7 +45,7 @@ void __W3_HTTP_Request(struct W3* w3){
                        __W3_Auto_Write(w3, "\r\n", 2);
                }
        }
-       if(w3->data != NULL){
+       if(w3->data != NULL) {
                char* len = malloc(129);
                memset(len, 0, 129);
                sprintf(len, "%d", w3->size);
@@ -55,7 +55,7 @@ void __W3_HTTP_Request(struct W3* w3){
                free(len);
        }
        __W3_Auto_Write(w3, "\r\n", 2);
-       if(w3->data != NULL){
+       if(w3->data != NULL) {
                __W3_Auto_Write(w3, w3->data, w3->size);
        }
        char* buf = malloc(w3->readsize);
@@ -64,31 +64,31 @@ void __W3_HTTP_Request(struct W3* w3){
        char* headerbuf = malloc(1);
        headerbuf[0] = 0;
        int phase = 0;
-       while(true){
+       while(true) {
                int l = __W3_Auto_Read(w3, buf, w3->readsize);
                if(l <= 0) break;
                int i;
-               for(i = 0; i < l; i++){
-                       if(phase == 0){
-                               if(buf[i] == '\r'){
+               for(i = 0; i < l; i++) {
+                       if(phase == 0) {
+                               if(buf[i] == '\r') {
                                        int phase2 = 0;
                                        int j = 0;
                                        int start_status = 0;
-                                       for(j = 0; statusbuf[j] != 0; j++){
-                                               if(phase2 == 0){
-                                                       if(statusbuf[j] == ' '){
+                                       for(j = 0; statusbuf[j] != 0; j++) {
+                                               if(phase2 == 0) {
+                                                       if(statusbuf[j] == ' ') {
                                                                phase2++;
                                                                start_status = j + 1;
                                                        }
-                                               }else if(phase2 == 1){
-                                                       if(statusbuf[j] == ' '){
+                                               } else if(phase2 == 1) {
+                                                       if(statusbuf[j] == ' ') {
                                                                char* code = malloc(j - start_status + 1);
                                                                code[j - start_status] = 0;
                                                                memcpy(code, statusbuf + start_status, j - start_status);
                                                                w3->status = atoi(code);
                                                                void* funcptr = __W3_Get_Event(w3, "status");
-                                                               if(funcptr != NULL){
-                                                                       void(*func)(struct W3*, int) = (void(*)(struct W3*, int))funcptr;
+                                                               if(funcptr != NULL) {
+                                                                       void (*func)(struct W3*, int) = (void (*)(struct W3*, int))funcptr;
                                                                        func(w3, w3->status);
                                                                }
                                                                free(code);
@@ -97,7 +97,7 @@ void __W3_HTTP_Request(struct W3* w3){
                                                }
                                        }
                                        phase++;
-                               }else{
+                               } else {
                                        char* oldbuf = statusbuf;
                                        statusbuf = malloc(strlen(oldbuf) + 2);
                                        strcpy(statusbuf, oldbuf);
@@ -105,7 +105,7 @@ void __W3_HTTP_Request(struct W3* w3){
                                        statusbuf[strlen(oldbuf) + 1] = 0;
                                        free(oldbuf);
                                }
-                       }else if(phase == 1){
+                       } else if(phase == 1) {
                                char* oldbuf = headerbuf;
                                headerbuf = malloc(strlen(oldbuf) + 2);
                                strcpy(headerbuf, oldbuf);
@@ -113,29 +113,29 @@ void __W3_HTTP_Request(struct W3* w3){
                                headerbuf[strlen(oldbuf) + 1] = 0;
                                free(oldbuf);
                                int len = strlen(headerbuf);
-                               if(len >= 4){
-                                       if(headerbuf[len - 1] == '\n' && headerbuf[len - 2] == '\r' && headerbuf[len - 3] == '\n' && headerbuf[len - 4] == '\r'){
+                               if(len >= 4) {
+                                       if(headerbuf[len - 1] == '\n' && headerbuf[len - 2] == '\r' && headerbuf[len - 3] == '\n' && headerbuf[len - 4] == '\r') {
                                                headerbuf[len - 4] = 0;
                                                char* headers = malloc(strlen(headerbuf) + 1);
                                                int j;
                                                int incr = 0;
                                                int start = 0;
-                                               for(j = 1; headerbuf[j] != 0; j++){
+                                               for(j = 1; headerbuf[j] != 0; j++) {
                                                        char c = headerbuf[j];
-                                                       if(c == '\r'){
+                                                       if(c == '\r') {
                                                                headers[incr] = 0;
                                                                headers[incr + 1] = 0;
                                                                char* data = __W3_Strdup(headers + start);
                                                                int k;
-                                                               for(k = 0; data[k] != 0; k++){
-                                                                       if(data[k] == ':'){
+                                                               for(k = 0; data[k] != 0; k++) {
+                                                                       if(data[k] == ':') {
                                                                                data[k] = 0;
                                                                                k++;
                                                                                for(; data[k] != 0 && data[k] != ' ' && data[k] != '\t'; k++) data[k] = 0;
-                                                                               if(data[k] == ' ' || data[k] == '\t'){
+                                                                               if(data[k] == ' ' || data[k] == '\t') {
                                                                                        void* funcptr = __W3_Get_Event(w3, "header");
-                                                                                       if(funcptr != NULL){
-                                                                                               void(*func)(struct W3*, char*, char*) = (void(*)(struct W3*, char*, char*))funcptr;
+                                                                                       if(funcptr != NULL) {
+                                                                                               void (*func)(struct W3*, char*, char*) = (void (*)(struct W3*, char*, char*))funcptr;
                                                                                                func(w3, data, data + k + 1);
                                                                                        }
                                                                                }
@@ -146,7 +146,7 @@ void __W3_HTTP_Request(struct W3* w3){
                                                                start = incr + 1;
                                                                incr++;
                                                                j++;
-                                                       }else{
+                                                       } else {
                                                                headers[incr] = c;
                                                                headers[incr + 1] = 0;
                                                                incr++;
@@ -156,10 +156,10 @@ void __W3_HTTP_Request(struct W3* w3){
                                                phase++;
                                        }
                                }
-                       }else if(phase == 2){
+                       } else if(phase == 2) {
                                void* funcptr = __W3_Get_Event(w3, "data");
-                               if(funcptr != NULL){
-                                       void(*func)(struct W3* w3, char*, size_t) = (void(*)(struct W3* w3, char*, size_t))funcptr;
+                               if(funcptr != NULL) {
+                                       void (*func)(struct W3*, char*, size_t) = (void (*)(struct W3*, char*, size_t))funcptr;
                                        char* buffer = malloc(l - i);
                                        memcpy(buffer, buf + i, l - i);
                                        func(w3, buffer, l - i);
index 04869878794e21ea71abe2b0eaa47a287be15405..4d0e92facef2a5ee0c43b91a10afa8cb2727f533 100644 (file)
@@ -3,18 +3,18 @@
 
 #include "W3Core.h"
 
+#include <stdbool.h>
 #include <stdio.h>
-#include <string.h>
 #include <stdlib.h>
-#include <stdbool.h>
+#include <string.h>
 
 #ifdef __MINGW32__
 #include <windows.h>
 #include <winsock.h>
 #else
 #include <netdb.h>
-#include <sys/socket.h>
 #include <netinet/in.h>
+#include <sys/socket.h>
 #include <sys/utsname.h>
 #endif
 
@@ -24,7 +24,7 @@
 
 #define __DEBUG_LEN 12
 
-void __W3_Debug(const char* title, const char* message){
+void __W3_Debug(const char* title, const char* message) {
 #ifdef __DEBUG__
        char* periods = malloc(__DEBUG_LEN - strlen(title) + 1);
        periods[__DEBUG_LEN - strlen(title)] = 0;
@@ -33,7 +33,7 @@ void __W3_Debug(const char* title, const char* message){
 #endif
 }
 
-char* __W3_Concat(const char* str1, const char* str2){
+char* __W3_Concat(const char* str1, const char* str2) {
        char* str = malloc(strlen(str1) + strlen(str2) + 1);
        strcpy(str, str1);
        strcpy(str + strlen(str1), str2);
@@ -41,24 +41,24 @@ char* __W3_Concat(const char* str1, const char* str2){
        return str;
 }
 
-char* __W3_Concat3(const char* str1, const char* str2, const char* str3){
+char* __W3_Concat3(const char* str1, const char* str2, const char* str3) {
        char* tmp = __W3_Concat(str1, str2);
        char* str = __W3_Concat(tmp, str3);
        free(tmp);
        return str;
 }
 
-char* __W3_Strdup(const char* str){
+char* __W3_Strdup(const char* str) {
        char* result = malloc(strlen(str) + 1);
        memcpy(result, str, strlen(str) + 1);
        return result;
 }
 
-unsigned long __W3_Auto_Write(struct W3* w3, char* data, unsigned long length){
+unsigned long __W3_Auto_Write(struct W3* w3, char* data, unsigned long length) {
 #ifdef SSL_SUPPORT
-       if(w3->ssl != NULL){
+       if(w3->ssl != NULL) {
                return SSL_write(w3->ssl, data, length);
-       }else{
+       } else {
                return send(w3->sock, data, length, 0);
        }
 #else
@@ -66,11 +66,11 @@ unsigned long __W3_Auto_Write(struct W3* w3, char* data, unsigned long length){
 #endif
 }
 
-unsigned long __W3_Auto_Read(struct W3* w3, char* data, unsigned long length){
+unsigned long __W3_Auto_Read(struct W3* w3, char* data, unsigned long length) {
 #ifdef SSL_SUPPORT
-       if(w3->ssl != NULL){
+       if(w3->ssl != NULL) {
                return SSL_read(w3->ssl, data, length);
-       }else{
+       } else {
                return recv(w3->sock, data, length, 0);
        }
 #else
@@ -78,29 +78,29 @@ unsigned long __W3_Auto_Read(struct W3* w3, char* data, unsigned long length){
 #endif
 }
 
-void* __W3_Get_Event(struct W3* w3, const char* eventname){
+void* __W3_Get_Event(struct W3* w3, const char* eventname) {
        if(w3->events == NULL) return NULL;
        int i;
-       for(i = 0; w3->events[i] != NULL; i += 2){
-               if(strcmp(w3->events[i], eventname) == 0){
+       for(i = 0; w3->events[i] != NULL; i += 2) {
+               if(strcmp(w3->events[i], eventname) == 0) {
                        return w3->events[i + 1];
                }
        }
        return NULL;
 }
 
-bool __W3_Have_Header(struct W3* w3, const char* name){
+bool __W3_Have_Header(struct W3* w3, const char* name) {
        if(w3->headers == NULL) return false;
        int i;
-       for(i = 0; w3->headers[i] != NULL; i += 2){
-               if(strcmp(w3->headers[i], name) == 0){
+       for(i = 0; w3->headers[i] != NULL; i += 2) {
+               if(strcmp(w3->headers[i], name) == 0) {
                        return true;
                }
        }
        return false;
 }
 
-char* __W3_Get_Platform(void){
+char* __W3_Get_Platform(void) {
 #ifdef __MINGW32__
        return __W3_Strdup("Windows");
 #else
index 305fb6c1b2871cd495027b1de6b5962a7d566719..338fc7d265deef8528ddcb420e6170f1499f6c6e 100644 (file)
@@ -6,40 +6,40 @@
 extern "C" {
 #endif
 
-#include <stddef.h>
 #include <stdbool.h>
+#include <stddef.h>
 
 #include "W3Version.h"
 
 struct W3 {
-       int sock;               /* Socket */
-       char* protocol;         /* As you can read from its name */
-       char* method;           /* Used in HTTP */
-       char* path;             /* As you can read from its name */
-       char* hostname;         /* As you can read from its name */
-       char** headers;         /* As you can read from its name */
-       void** events;          /* As you can read from its name */ 
-       int status;             /* As you can read from its name */ 
-       char* data;             /* As you can read from its name */
-       size_t size;            /* Size of the data */
-       size_t readsize;        /* Read buffer size, default is 512 */
+       int sock;        /* Socket */
+       char* protocol;  /* As you can read from its name */
+       char* method;    /* Used in HTTP        */
+       char* path;      /* As you can read from its name */
+       char* hostname;  /* As you can read from its name */
+       char** headers;  /* As you can read from its name */
+       void** events;   /* As you can read from its name */
+       int status;      /* As you can read from its name */
+       char* data;      /* As you can read from its name */
+       size_t size;     /* Size of the data */
+       size_t readsize; /* Read buffer size, default is 512 */
 #ifdef SSL_SUPPORT
-       void* ssl;              /* Actually SSL*, NULL if no SSL */
-       void* ssl_ctx;          /* Actually SSL_CTX* */
+       void* ssl;     /* Actually SSL*, NULL if no SSL */
+       void* ssl_ctx; /* Actually SSL_CTX* */
 #endif
 };
 
-int W3_Library_Init(void);                                                     /* Initialize the Library */
-struct W3* W3_Create(const char* protocol, const char* hostname, int port);    /* Create the struct */
-
-void W3_Set_Method(struct W3* w3, const char* method);                         /* Set the method */
-void W3_Set_Path(struct W3* w3, const char* path);                             /* Set the path */
-void W3_Send_Request(struct W3* w3);                                           /* Send the request */
-void W3_Set_Header(struct W3* w3, const char* key, const char* value);         /* Set the header */
-void W3_Free(struct W3* w3);                                                   /* Free the struct */
-void W3_On(struct W3* w3, const char* eventname, void* func);                  /* Set Handlers */
-void W3_Set_Data(struct W3* w3, char* data, size_t size);                      /* Send the data - LibW3 won't free the data */
-void W3_Set_Read_Size(struct W3* w3, size_t size);                             /* Change the read buffer size */
+int W3_Library_Init(void);                                                 /* Initialize the Library */
+struct W3* W3_Create(const char* protocol, const char* hostname, int port); /* Create the struct */
+
+void W3_Set_Method(struct W3* w3, const char* method);                /* Set the method */
+void W3_Set_Path(struct W3* w3, const char* path);                    /* Set the path */
+void W3_Send_Request(struct W3* w3);                                  /* Send the request */
+void W3_Set_Header(struct W3* w3, const char* key, const char* value); /* Set the header */
+void W3_Free(struct W3* w3);                                          /* Free the struct */
+void W3_On(struct W3* w3, const char* eventname, void* func);         /* Set Handlers */
+void W3_Set_Data(struct W3* w3, char* data, size_t size);             /* Send the data - LibW3 won't free the data */
+void W3_Set_Read_Size(struct W3* w3, size_t size);                    /* Change the read buffer size */
 
 #ifdef __cplusplus
 }
index e53e2ee57835367d62cef5a1f1c80be0fd6bc0e3..dbc304fafaa109c85e9424adb2440b9dc11651be 100644 (file)
@@ -6,14 +6,13 @@
 extern "C" {
 #endif
 
-#include <stdint.h>
 #include <stdbool.h>
+#include <stdint.h>
 
 int __W3_DNS_Connect(const char* hostname, bool ssl, uint16_t port
 #ifdef SSL_SUPPORT
-       ,
-       void** o_ssl,
-       void** o_ctx
+                    ,
+                    void** o_ssl, void** o_ctx
 #endif
 );
 
index 370745e6f45fd106c5a0faefe71ca84477f795ef..41e1658e7ae9d6508aaf60a37e1e78a3e82daf33 100644 (file)
@@ -9,8 +9,8 @@ extern "C" {
 #include "W3Core.h"
 void __W3_File_Request(struct W3* w3);
 
-#define LIBW3_FILE_FOUND       0
-#define LIBW3_FILE_NOT_FOUND   1
+#define LIBW3_FILE_FOUND 0
+#define LIBW3_FILE_NOT_FOUND 1
 
 #ifdef __cplusplus
 }
index 6233a50abbb90a609a800d7612c3e26c2fb84beb..c10ce5c759135c5060989a85afb5247d4e4c4935 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -35,7 +35,7 @@ CFLAGS += -g -D__DEBUG__
 endif
 
 ifeq ($(WINDOWS),YES)
-.PHONY: all clean ./Library/w3.dll ./Example/fetch
+.PHONY: all clean ./Library/w3.dll ./Example/fetch format
 
 ALL := ./Library/w3.dll ./Example/fetch.exe
 
@@ -52,7 +52,7 @@ all: ./w3.pc ./Library/W3Version.h $(ALL)
 
 else
 
-.PHONY: all clean ./Library/libw3.so ./Library/libw3.a ./Example/fetch
+.PHONY: all clean ./Library/libw3.so ./Library/libw3.a ./Example/fetch format
 
 ALL := ./Library/libw3.so ./Library/libw3.a ./Example/fetch
 
@@ -113,3 +113,6 @@ endif
        zip -rv w3-$(VERSION).zip w3-$(VERSION)
        -/usr/lha/bin/lha a w3-$(VERSION).lzh w3-$(VERSION)
        rm -rf w3-$(VERSION)
+
+format:
+       clang-format -i `find Library Example -name "*.h" -or -name "*.c"`