w3->method = NULL;
w3->path = NULL;
w3->protocol = __W3_Strdup(protocol);
+ w3->hostname = __W3_Strdup(hostname);
if(ssl) __W3_Debug("Protocol", "Enabled SSL");
w3->sock = __W3_DNS_Connect(hostname, ssl, port
#ifdef SSL_SUPPORT
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);
free(w3);
}
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;
+ setsockopt(sock, SOL_SOCKET, SO_SNDBUF, &nzero, sizeof(nzero));
if(connect(sock, rp->ai_addr, rp->ai_addrlen) != -1) break;
close(sock);
}
#include "W3Core.h"
#include "W3Util.h"
+#include <string.h>
+
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, w3->path, strlen(w3->path));
+ __W3_Auto_Write(w3, " ", 1);
+ __W3_Auto_Write(w3, "HTTP/1.1", 8);
+ __W3_Auto_Write(w3, "\r\n", 2);
+ __W3_Auto_Write(w3, "Host: ", 6);
+ __W3_Auto_Write(w3, w3->hostname, strlen(w3->hostname));
+ __W3_Auto_Write(w3, "\r\n", 2);
+ __W3_Auto_Write(w3, "\r\n", 2);
}
/* $Id$ */
#include "W3Util.h"
+#include "W3Core.h"
+
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <netinet/in.h>
#endif
+#ifdef SSL_SUPPORT
+#include <openssl/ssl.h>
+#endif
+
#define __DEBUG_LEN 12
void __W3_Debug(const char* title, const char* message){
memcpy(result, str, strlen(str) + 1);
return result;
}
+
+unsigned long __W3_Auto_Write(struct W3* w3, char* data, unsigned long length){
+#ifdef SSL_SUPPORT
+ if(w3->ssl != NULL){
+ return SSL_write(w3->ssl, data, length);
+ }else{
+ return send(w3->sock, data, length, 0);
+ }
+#else
+ return send(w3->sock, data, length, 0);
+#endif
+}
+
+unsigned long __W3_Auto_Read(struct W3* w3, char* data, unsigned long length){
+#ifdef SSL_SUPPORT
+ if(w3->ssl != NULL){
+ return SSL_read(w3->ssl, data, length);
+ }else{
+ return recv(w3->sock, data, length, 0);
+ }
+#else
+ return recv(w3->sock, data, length, 0);
+#endif
+}
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 */
#ifdef SSL_SUPPORT
void* ssl; /* Actually SSL*, NULL if no SSL */
void* ssl_ctx; /* Actually SSL_CTX* */
#ifndef __W3UTIL_H__
#define __W3UTIL_H__
+#include "W3Core.h"
+
void __W3_Debug(const char* title, const char* message);
char* __W3_Concat(const char* str1, const char* str2);
char* __W3_Concat3(const char* str1, const char* str2, const char* str3);
char* __W3_Strdup(const char* str);
+unsigned long __W3_Auto_Write(struct W3* w3, char* data, unsigned long length);
+unsigned long __W3_Auto_Read(struct W3* w3, char* data, unsigned long length);
#endif