--- /dev/null
+---
+# $Id$
+Language: Cpp
+UseTab: Always
+TabWidth: 8
+IndentWidth: 8
+PointerAlignment: Left
+ColumnLimit: 1024
+AllowShortIfStatementsOnASingleLine: Always
+AllowShortLoopsOnASingleLine: True
+SpaceBeforeParens: Never
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]);
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;
}
#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
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;
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;
}
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);
#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;
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;
}
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");
}
}
#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);
#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);
__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));
__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]));
__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);
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);
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);
}
}
phase++;
- }else{
+ } else {
char* oldbuf = statusbuf;
statusbuf = malloc(strlen(oldbuf) + 2);
strcpy(statusbuf, oldbuf);
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);
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);
}
}
start = incr + 1;
incr++;
j++;
- }else{
+ } else {
headers[incr] = c;
headers[incr + 1] = 0;
incr++;
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);
#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
#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;
#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);
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
#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
#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
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
}
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
);
#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
}
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
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
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"`