diff --git a/Makefile b/Makefile index 2b20426..90eed6b 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ -CC = gcc -CFLAGS = -g -Wall -Werror -I../iniparser/src -L../iniparser +CC ?= gcc +CFLAGS += -g -Wall -I../iniparser/src -L../iniparser LIBS = -liniparser OBJ := cproxy diff --git a/conf.c b/conf.c index 3a0c9d7..328e389 100644 --- a/conf.c +++ b/conf.c @@ -2,6 +2,11 @@ void read_conf(char *file, conf *p) { + if(access(file, F_OK)) { + printf("%s DOESN'T EXISIT!\n", file); + exit(1); + } + dictionary *ini = iniparser_load(file); // server module diff --git a/conf.h b/conf.h index 27dcd01..5a59a52 100644 --- a/conf.h +++ b/conf.h @@ -3,6 +3,7 @@ #include "iniparser.h" #include "cproxy.h" +#include char *strncpy_(char *dest, const char *src, size_t n); void read_conf(char *file, conf *p); void free_conf(conf *p); diff --git a/conf/cproxy.ini b/conf/cproxy.ini index b7d466a..c767782 100644 --- a/conf/cproxy.ini +++ b/conf/cproxy.ini @@ -14,7 +14,6 @@ strrep = "Mi MIX 2->Linux"; https_ip=10.0.0.172; https_port=80; https_del=",Host"; -;https_first="[M] [U] [V]\r\nHost: [host]:[port]\r\n"; -https_first="[M] iread.wo.cn//https://[host]:[port]:iread.wo.cn [V]\r\nHost: iread.wo.cn\r\n"; +https_first="[M] iread.wo.cn//https://[host]:[port]#iread.wo.cn [V]\r\nhost: iread.wo.cn:443\r\n"; strrep = "Mi MIX 2->Linux"; -regrep = "Host*.+?->Host: iread.wo.cn:443"; \ No newline at end of file +regrep = "Host*.+?->Host: iread.wo.cn:443"; diff --git a/conf/cproxy.ini.explain b/conf/cproxy.ini.explain index ddcab46..7c9226a 100644 --- a/conf/cproxy.ini.explain +++ b/conf/cproxy.ini.explain @@ -1,4 +1,7 @@ 模块: [server], [http], [https] +[server]模块: +PORT 端口 +PID_FILE pid文件 [http]、[https]模块关键字: [M], [U], [V], [host], [port], \r, \n, \v, \f, \b, \t, \a. 如果原本请求头含有关键字也会被替换. [M] 原请求方法 diff --git a/cproxy.c b/cproxy.c index 4f8cb37..75cc0e3 100644 --- a/cproxy.c +++ b/cproxy.c @@ -63,7 +63,8 @@ void handle_client(int client_sock, struct sockaddr_in client_addr, conf *config forward_header(remote_sock); //普通的http请求先转发header forward_data(client_sock, remote_sock); } - exit(0); + _exit(0); + } if (fork() == 0) { @@ -72,7 +73,7 @@ void handle_client(int client_sock, struct sockaddr_in client_addr, conf *config } else if (SIGN == HTTP_OTHERS || SIGN == HTTP) { forward_data(remote_sock, client_sock); } - exit(0); + _exit(0); } close(client_sock); @@ -104,7 +105,7 @@ void forward_data(int source_sock, int destination_sock) int create_connection(conf *configure, int SIGN) { struct sockaddr_in server_addr; - struct hostent *server; + struct hostent *server = NULL; int sock; if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) { @@ -133,6 +134,11 @@ int create_connection(conf *configure, int SIGN) server_addr.sin_port = htons(configure->http_port); } + struct linger so_linger; + so_linger.l_onoff = 1; + so_linger.l_linger = 0; + setsockopt(sock, SOL_SOCKET, SO_LINGER, &so_linger,sizeof so_linger); + if (connect(sock, (struct sockaddr *)&server_addr, sizeof(server_addr)) < 0) { return CLIENT_CONNECT_ERROR; } @@ -142,16 +148,22 @@ int create_connection(conf *configure, int SIGN) int create_server_socket(int port) { - int server_sock, optval; + int server_sock; + //int optval; struct sockaddr_in server_addr; if ((server_sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) { return SERVER_SOCKET_ERROR; } - +/* if (setsockopt(server_sock, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval)) < 0) { return SERVER_SETSOCKOPT_ERROR; } +*/ + struct linger so_linger; + so_linger.l_onoff = 1; + so_linger.l_linger = 0; + setsockopt(server_sock, SOL_SOCKET, SO_LINGER, &so_linger,sizeof so_linger); memset(&server_addr, 0, sizeof(server_addr)); server_addr.sin_family = AF_INET; @@ -232,6 +244,7 @@ void server_loop(conf * configure) } close(client_sock); } + close(server_sock); } void start_server(conf *configure) diff --git a/cproxy_help.c b/cproxy_help.c index 3e961f9..dc22618 100644 --- a/cproxy_help.c +++ b/cproxy_help.c @@ -19,9 +19,10 @@ char help_information(void) 0 }; + + //fprintf(stderr, "%s %s\n", author.c, author.b); + fprintf(stderr, "%s %s\n", author.c, author.a); fprintf(stderr, "%s %s\n", name, subject); - fprintf(stderr, "%s %s\n", author.c, author.b); - fprintf(stderr, "%s %s\n", author.d, author.a); fprintf(stderr, "%s %s\n", name, usage); int l; diff --git a/cproxy_request.c b/cproxy_request.c index 133e430..4a90e16 100644 --- a/cproxy_request.c +++ b/cproxy_request.c @@ -429,7 +429,7 @@ int replacement_http_head(char *header_buffer, char *remote_host, int *remote_po new_header_buffer = replace(new_header_buffer, &len, "[V]", 3, V, len_v); new_header_buffer = replace(new_header_buffer, &len, "[host]", 6, remote_host, len_remote_host); - char port_copy[numbin(*remote_port) + 1]; + char port_copy[(numbin(*remote_port) + 1)]; sprintf(port_copy, "%d", *remote_port); int len_remote_port = strlen(port_copy); new_header_buffer = replace(new_header_buffer, &len, "[port]", 6, port_copy, len_remote_port); @@ -540,7 +540,7 @@ int replacement_http_head(char *header_buffer, char *remote_host, int *remote_po new_header_buffer = replace(new_header_buffer, &len, "[V]", 3, V, len_v); new_header_buffer = replace(new_header_buffer, &len, "[host]", 6, remote_host, len_remote_host); - char port_copy[numbin(*remote_port) + 1]; + char port_copy[(numbin(*remote_port) + 1)]; sprintf(port_copy, "%d", *remote_port); int len_remote_port = strlen(port_copy); new_header_buffer = replace(new_header_buffer, &len, "[port]", 6, port_copy, len_remote_port);