add NO_SSL
git-svn-id: file:///raid/svn-personal/tewi/trunk@43 8739d7e6-ffea-ec47-b151-bdff447c6205
This commit is contained in:
parent
ce7c8c96bc
commit
4d8bc89134
10
Makefile
10
Makefile
|
@ -12,8 +12,11 @@ FLAGS = PWD=$(PWD) PLATFORM=$(PLATFORM) PREFIX=$(PREFIX)
|
||||||
|
|
||||||
all: ./Server ./Module ./Manpage
|
all: ./Server ./Module ./Manpage
|
||||||
|
|
||||||
./Server:: ./Common
|
./Server/option: ./Server/option.c
|
||||||
$(MAKE) -C $@ $(FLAGS)
|
cc -o $@ ./Server/option.c
|
||||||
|
|
||||||
|
./Server:: ./Common ./Server/option
|
||||||
|
$(MAKE) -C $@ $(FLAGS) EXTOBJS=`./Server/option objs ../` EXTLIBS=`./Server/option libs ../`
|
||||||
|
|
||||||
./Module:: ./Common
|
./Module:: ./Common
|
||||||
$(MAKE) -C $@ $(FLAGS)
|
$(MAKE) -C $@ $(FLAGS)
|
||||||
|
@ -25,10 +28,11 @@ all: ./Server ./Module ./Manpage
|
||||||
$(MAKE) -C $@ $(FLAGS)
|
$(MAKE) -C $@ $(FLAGS)
|
||||||
|
|
||||||
format:
|
format:
|
||||||
clang-format --verbose -i `find ./Server ./Common ./Module "(" -name "*.c" -or -name "*.h" ")" -and -not -name "strptime.*"`
|
clang-format --verbose -i `find ./Server ./Common ./Module "(" -name "*.c" -or -name "*.h" ")" -and -not -name "strptime.*"` config.h
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(MAKE) -C ./Server $(FLAGS) clean
|
$(MAKE) -C ./Server $(FLAGS) clean
|
||||||
$(MAKE) -C ./Module $(FLAGS) clean
|
$(MAKE) -C ./Module $(FLAGS) clean
|
||||||
$(MAKE) -C ./Common $(FLAGS) clean
|
$(MAKE) -C ./Common $(FLAGS) clean
|
||||||
$(MAKE) -C ./Manpage $(FLAGS) clean
|
$(MAKE) -C ./Manpage $(FLAGS) clean
|
||||||
|
rm -f ./Server/option
|
||||||
|
|
|
@ -4,8 +4,8 @@ PREFIX = C:/Tewi
|
||||||
|
|
||||||
CC = i686-w64-mingw32-gcc
|
CC = i686-w64-mingw32-gcc
|
||||||
AR = i686-w64-mingw32-ar
|
AR = i686-w64-mingw32-ar
|
||||||
CFLAGS = -g -std=c99 -DPREFIX=\"$(PREFIX)\" -I $(PWD)/Common -I $(PWD)/openssl/include -fPIC
|
CFLAGS = -g -std=c99 -DPREFIX=\"$(PREFIX)\" -I $(PWD)/Common -fPIC
|
||||||
LDFLAGS = -L $(PWD)/openssl/lib32
|
LDFLAGS =
|
||||||
LIBS = -lws2_32
|
LIBS = -lws2_32
|
||||||
EXEC = .exe
|
EXEC = .exe
|
||||||
LIB = .dll
|
LIB = .dll
|
||||||
|
|
|
@ -4,8 +4,8 @@ PREFIX = C:/Tewi
|
||||||
|
|
||||||
CC = x86_64-w64-mingw32-gcc
|
CC = x86_64-w64-mingw32-gcc
|
||||||
AR = x86_64-w64-mingw32-ar
|
AR = x86_64-w64-mingw32-ar
|
||||||
CFLAGS = -g -std=c99 -DPREFIX=\"$(PREFIX)\" -I $(PWD)/Common -I $(PWD)/openssl/include -fPIC
|
CFLAGS = -g -std=c99 -DPREFIX=\"$(PREFIX)\" -I $(PWD)/Common -fPIC
|
||||||
LDFLAGS = -L $(PWD)/openssl/lib64
|
LDFLAGS =
|
||||||
LIBS = -lws2_32
|
LIBS = -lws2_32
|
||||||
EXEC = .exe
|
EXEC = .exe
|
||||||
LIB = .dll
|
LIB = .dll
|
||||||
|
|
|
@ -5,12 +5,12 @@ include $(PWD)/Platform/$(PLATFORM).mk
|
||||||
.PHONY: all clean
|
.PHONY: all clean
|
||||||
.SUFFIXES: .c .o
|
.SUFFIXES: .c .o
|
||||||
|
|
||||||
OBJS = version.o main.o config.o server.o ssl.o http.o module.o strptime.o
|
OBJS = version.o main.o config.o server.o http.o module.o strptime.o $(EXTOBJS)
|
||||||
|
|
||||||
all: tewi$(EXEC)
|
all: tewi$(EXEC)
|
||||||
|
|
||||||
tewi$(EXEC): $(OBJS) ../Common/common.a
|
tewi$(EXEC): $(OBJS) ../Common/common.a
|
||||||
$(CC) $(LDFLAGS) -o $@ $(OBJS) -lssl -lcrypto $(LIBS) ../Common/common.a
|
$(CC) $(LDFLAGS) -o $@ $(OBJS) $(EXTLIBS) $(LIBS) ../Common/common.a
|
||||||
|
|
||||||
.c.o:
|
.c.o:
|
||||||
$(CC) $(CFLAGS) -c -o $@ $<
|
$(CC) $(CFLAGS) -c -o $@ $<
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
#define SOURCE
|
#define SOURCE
|
||||||
|
|
||||||
|
#include "../config.h"
|
||||||
|
|
||||||
#include "tw_http.h"
|
#include "tw_http.h"
|
||||||
|
|
||||||
#include "tw_server.h"
|
#include "tw_server.h"
|
||||||
|
@ -59,14 +61,18 @@ int tw_http_parse(SSL* ssl, int sock, struct tw_http_request* req) {
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
tv.tv_sec = 5;
|
tv.tv_sec = 5;
|
||||||
tv.tv_usec = 0;
|
tv.tv_usec = 0;
|
||||||
|
#ifndef NO_SSL
|
||||||
if(ssl == NULL || !SSL_has_pending(ssl)) {
|
if(ssl == NULL || !SSL_has_pending(ssl)) {
|
||||||
|
#endif
|
||||||
int n = select(FD_SETSIZE, &fds, NULL, NULL, &tv);
|
int n = select(FD_SETSIZE, &fds, NULL, NULL, &tv);
|
||||||
if(n <= 0) {
|
if(n <= 0) {
|
||||||
free(header);
|
free(header);
|
||||||
tw_free_request(req);
|
tw_free_request(req);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
#ifndef NO_SSL
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
int len = tw_read(ssl, sock, buffer, 512);
|
int len = tw_read(ssl, sock, buffer, 512);
|
||||||
if(len <= 0) break;
|
if(len <= 0) break;
|
||||||
int i;
|
int i;
|
||||||
|
|
|
@ -2,12 +2,16 @@
|
||||||
|
|
||||||
#define SOURCE
|
#define SOURCE
|
||||||
|
|
||||||
|
#include "../config.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
|
#ifndef NO_SSL
|
||||||
#include <openssl/opensslv.h>
|
#include <openssl/opensslv.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <cm_log.h>
|
#include <cm_log.h>
|
||||||
|
|
||||||
|
@ -28,7 +32,11 @@ int main(int argc, char** argv) {
|
||||||
if(strcmp(argv[i], "--verbose") == 0 || strcmp(argv[i], "-v") == 0) {
|
if(strcmp(argv[i], "--verbose") == 0 || strcmp(argv[i], "-v") == 0) {
|
||||||
if(!cm_do_log) {
|
if(!cm_do_log) {
|
||||||
cm_do_log = true;
|
cm_do_log = true;
|
||||||
|
#ifndef NO_SSL
|
||||||
cm_log("", "This is Tewi HTTPd, version %s, using %s", tw_get_version(), OPENSSL_VERSION_TEXT);
|
cm_log("", "This is Tewi HTTPd, version %s, using %s", tw_get_version(), OPENSSL_VERSION_TEXT);
|
||||||
|
#else
|
||||||
|
cm_log("", "This is Tewi HTTPd, version %s", tw_get_version());
|
||||||
|
#endif
|
||||||
} else {
|
} else {
|
||||||
cm_do_log = true;
|
cm_do_log = true;
|
||||||
}
|
}
|
||||||
|
|
31
Server/option.c
Normal file
31
Server/option.c
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
/* $Id$ */
|
||||||
|
/* This file is not intended to be in the server. */
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "../config.h"
|
||||||
|
|
||||||
|
int main(int argc, char** argv) {
|
||||||
|
if(argc < 3) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if(strcmp(argv[1], "cflags") == 0) {
|
||||||
|
#ifndef NO_SSL
|
||||||
|
printf("-I %s/openssl/include", argv[2]);
|
||||||
|
#endif
|
||||||
|
} else if(strcmp(argv[1], "ldflags") == 0) {
|
||||||
|
#ifndef NO_SSL
|
||||||
|
printf("-I %s/openssl/lib", argv[2]);
|
||||||
|
#endif
|
||||||
|
} else if(strcmp(argv[1], "objs") == 0) {
|
||||||
|
#ifndef NO_SSL
|
||||||
|
printf("ssl.o");
|
||||||
|
#endif
|
||||||
|
} else if(strcmp(argv[1], "libs") == 0) {
|
||||||
|
#ifndef NO_SSL
|
||||||
|
printf("-lssl -lcrypto");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
}
|
|
@ -2,9 +2,14 @@
|
||||||
|
|
||||||
#define SOURCE
|
#define SOURCE
|
||||||
|
|
||||||
|
#include "../config.h"
|
||||||
|
|
||||||
#include "tw_server.h"
|
#include "tw_server.h"
|
||||||
|
|
||||||
|
#ifndef NO_SSL
|
||||||
#include "tw_ssl.h"
|
#include "tw_ssl.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "tw_config.h"
|
#include "tw_config.h"
|
||||||
#include "tw_http.h"
|
#include "tw_http.h"
|
||||||
#include "tw_module.h"
|
#include "tw_module.h"
|
||||||
|
@ -14,6 +19,8 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
|
@ -142,19 +149,27 @@ int tw_server_init(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t tw_read(SSL* ssl, int s, void* data, size_t len) {
|
size_t tw_read(SSL* ssl, int s, void* data, size_t len) {
|
||||||
|
#ifndef NO_SSL
|
||||||
if(ssl == NULL) {
|
if(ssl == NULL) {
|
||||||
return recv(s, data, len, 0);
|
return recv(s, data, len, 0);
|
||||||
} else {
|
} else {
|
||||||
return SSL_read(ssl, data, len);
|
return SSL_read(ssl, data, len);
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
return recv(s, data, len, 0);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t tw_write(SSL* ssl, int s, void* data, size_t len) {
|
size_t tw_write(SSL* ssl, int s, void* data, size_t len) {
|
||||||
|
#ifndef NO_SSL
|
||||||
if(ssl == NULL) {
|
if(ssl == NULL) {
|
||||||
return send(s, data, len, 0);
|
return send(s, data, len, 0);
|
||||||
} else {
|
} else {
|
||||||
return SSL_write(ssl, data, len);
|
return SSL_write(ssl, data, len);
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
return send(s, data, len, 0);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#define ERROR_HTML \
|
#define ERROR_HTML \
|
||||||
|
@ -388,6 +403,7 @@ void tw_server_pass(int sock, bool ssl, int port, SOCKADDR addr) {
|
||||||
#endif
|
#endif
|
||||||
char* name = config.hostname;
|
char* name = config.hostname;
|
||||||
|
|
||||||
|
#ifndef NO_SSL
|
||||||
SSL_CTX* ctx = NULL;
|
SSL_CTX* ctx = NULL;
|
||||||
SSL* s = NULL;
|
SSL* s = NULL;
|
||||||
bool sslworks = false;
|
bool sslworks = false;
|
||||||
|
@ -398,6 +414,9 @@ void tw_server_pass(int sock, bool ssl, int port, SOCKADDR addr) {
|
||||||
if(SSL_accept(s) <= 0) goto cleanup;
|
if(SSL_accept(s) <= 0) goto cleanup;
|
||||||
sslworks = true;
|
sslworks = true;
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
void* s = NULL;
|
||||||
|
#endif
|
||||||
struct tw_http_request req;
|
struct tw_http_request req;
|
||||||
struct tw_http_response res;
|
struct tw_http_response res;
|
||||||
struct tw_tool tools;
|
struct tw_tool tools;
|
||||||
|
@ -660,14 +679,17 @@ void tw_server_pass(int sock, bool ssl, int port, SOCKADDR addr) {
|
||||||
tw_http_error(s, sock, 400, name, port);
|
tw_http_error(s, sock, 400, name, port);
|
||||||
}
|
}
|
||||||
cleanup:
|
cleanup:
|
||||||
|
#ifndef NO_SSL
|
||||||
if(sslworks) {
|
if(sslworks) {
|
||||||
SSL_shutdown(s);
|
SSL_shutdown(s);
|
||||||
}
|
}
|
||||||
SSL_free(s);
|
SSL_free(s);
|
||||||
close_socket(sock);
|
close_socket(sock);
|
||||||
|
#endif
|
||||||
#ifdef __MINGW32__
|
#ifdef __MINGW32__
|
||||||
_endthreadex(0);
|
_endthreadex(0);
|
||||||
#endif
|
#endif
|
||||||
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
void tw_server_loop(void) {
|
void tw_server_loop(void) {
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#include "../config.h"
|
||||||
|
|
||||||
struct tw_http_request {
|
struct tw_http_request {
|
||||||
char* method;
|
char* method;
|
||||||
char* path;
|
char* path;
|
||||||
|
@ -21,9 +23,15 @@ struct tw_http_response {
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef SOURCE
|
#ifdef SOURCE
|
||||||
|
#ifndef NO_SSL
|
||||||
#include <openssl/ssl.h>
|
#include <openssl/ssl.h>
|
||||||
|
#endif
|
||||||
void tw_free_request(struct tw_http_request* req);
|
void tw_free_request(struct tw_http_request* req);
|
||||||
|
#ifndef NO_SSL
|
||||||
int tw_http_parse(SSL* ssl, int sock, struct tw_http_request* req);
|
int tw_http_parse(SSL* ssl, int sock, struct tw_http_request* req);
|
||||||
|
#else
|
||||||
|
int tw_http_parse(void* ssl, int sock, struct tw_http_request* req);
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -3,11 +3,23 @@
|
||||||
#ifndef __TW_SERVER_H__
|
#ifndef __TW_SERVER_H__
|
||||||
#define __TW_SERVER_H__
|
#define __TW_SERVER_H__
|
||||||
|
|
||||||
|
#include "../config.h"
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
#ifndef NO_SSL
|
||||||
#include <openssl/ssl.h>
|
#include <openssl/ssl.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
int tw_server_init(void);
|
int tw_server_init(void);
|
||||||
void tw_server_loop(void);
|
void tw_server_loop(void);
|
||||||
|
|
||||||
|
#ifndef NO_SSL
|
||||||
size_t tw_read(SSL* ssl, int s, void* data, size_t len);
|
size_t tw_read(SSL* ssl, int s, void* data, size_t len);
|
||||||
size_t tw_write(SSL* ssl, int s, void* data, size_t len);
|
size_t tw_write(SSL* ssl, int s, void* data, size_t len);
|
||||||
|
#else
|
||||||
|
size_t tw_read(void* ssl, int s, void* data, size_t len);
|
||||||
|
size_t tw_write(void* ssl, int s, void* data, size_t len);
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue
Block a user