修改: Makefile
修改: conf.c 修改: conf.h 修改: conf/cproxy.ini 修改: conf/cproxy.ini.explain 修改: cproxy.c 修改: cproxy_help.c 修改: cproxy_request.c
This commit is contained in:
parent
4072556043
commit
68aada0edd
4
Makefile
4
Makefile
@ -1,5 +1,5 @@
|
|||||||
CC = gcc
|
CC ?= gcc
|
||||||
CFLAGS = -g -Wall -Werror -I../iniparser/src -L../iniparser
|
CFLAGS += -g -Wall -I../iniparser/src -L../iniparser
|
||||||
LIBS = -liniparser
|
LIBS = -liniparser
|
||||||
OBJ := cproxy
|
OBJ := cproxy
|
||||||
|
|
||||||
|
5
conf.c
5
conf.c
@ -2,6 +2,11 @@
|
|||||||
|
|
||||||
void read_conf(char *file, conf *p)
|
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);
|
dictionary *ini = iniparser_load(file);
|
||||||
|
|
||||||
// server module
|
// server module
|
||||||
|
1
conf.h
1
conf.h
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include "iniparser.h"
|
#include "iniparser.h"
|
||||||
#include "cproxy.h"
|
#include "cproxy.h"
|
||||||
|
#include <unistd.h>
|
||||||
char *strncpy_(char *dest, const char *src, size_t n);
|
char *strncpy_(char *dest, const char *src, size_t n);
|
||||||
void read_conf(char *file, conf *p);
|
void read_conf(char *file, conf *p);
|
||||||
void free_conf(conf *p);
|
void free_conf(conf *p);
|
||||||
|
@ -14,7 +14,6 @@ strrep = "Mi MIX 2->Linux";
|
|||||||
https_ip=10.0.0.172;
|
https_ip=10.0.0.172;
|
||||||
https_port=80;
|
https_port=80;
|
||||||
https_del=",Host";
|
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:443\r\n";
|
||||||
https_first="[M] iread.wo.cn//https://[host]:[port]:iread.wo.cn [V]\r\nHost: iread.wo.cn\r\n";
|
|
||||||
strrep = "Mi MIX 2->Linux";
|
strrep = "Mi MIX 2->Linux";
|
||||||
regrep = "Host*.+?->Host: iread.wo.cn:443";
|
regrep = "Host*.+?->Host: iread.wo.cn:443";
|
@ -1,4 +1,7 @@
|
|||||||
模块: [server], [http], [https]
|
模块: [server], [http], [https]
|
||||||
|
[server]模块:
|
||||||
|
PORT 端口
|
||||||
|
PID_FILE pid文件
|
||||||
|
|
||||||
[http]、[https]模块关键字: [M], [U], [V], [host], [port], \r, \n, \v, \f, \b, \t, \a. 如果原本请求头含有关键字也会被替换.
|
[http]、[https]模块关键字: [M], [U], [V], [host], [port], \r, \n, \v, \f, \b, \t, \a. 如果原本请求头含有关键字也会被替换.
|
||||||
[M] 原请求方法
|
[M] 原请求方法
|
||||||
|
23
cproxy.c
23
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_header(remote_sock); //普通的http请求先转发header
|
||||||
forward_data(client_sock, remote_sock);
|
forward_data(client_sock, remote_sock);
|
||||||
}
|
}
|
||||||
exit(0);
|
_exit(0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fork() == 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) {
|
} else if (SIGN == HTTP_OTHERS || SIGN == HTTP) {
|
||||||
forward_data(remote_sock, client_sock);
|
forward_data(remote_sock, client_sock);
|
||||||
}
|
}
|
||||||
exit(0);
|
_exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
close(client_sock);
|
close(client_sock);
|
||||||
@ -104,7 +105,7 @@ void forward_data(int source_sock, int destination_sock)
|
|||||||
int create_connection(conf *configure, int SIGN)
|
int create_connection(conf *configure, int SIGN)
|
||||||
{
|
{
|
||||||
struct sockaddr_in server_addr;
|
struct sockaddr_in server_addr;
|
||||||
struct hostent *server;
|
struct hostent *server = NULL;
|
||||||
int sock;
|
int sock;
|
||||||
|
|
||||||
if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
|
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);
|
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) {
|
if (connect(sock, (struct sockaddr *)&server_addr, sizeof(server_addr)) < 0) {
|
||||||
return CLIENT_CONNECT_ERROR;
|
return CLIENT_CONNECT_ERROR;
|
||||||
}
|
}
|
||||||
@ -142,16 +148,22 @@ int create_connection(conf *configure, int SIGN)
|
|||||||
|
|
||||||
int create_server_socket(int port)
|
int create_server_socket(int port)
|
||||||
{
|
{
|
||||||
int server_sock, optval;
|
int server_sock;
|
||||||
|
//int optval;
|
||||||
struct sockaddr_in server_addr;
|
struct sockaddr_in server_addr;
|
||||||
|
|
||||||
if ((server_sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
|
if ((server_sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
|
||||||
return SERVER_SOCKET_ERROR;
|
return SERVER_SOCKET_ERROR;
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
if (setsockopt(server_sock, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval)) < 0) {
|
if (setsockopt(server_sock, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval)) < 0) {
|
||||||
return SERVER_SETSOCKOPT_ERROR;
|
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));
|
memset(&server_addr, 0, sizeof(server_addr));
|
||||||
server_addr.sin_family = AF_INET;
|
server_addr.sin_family = AF_INET;
|
||||||
@ -232,6 +244,7 @@ void server_loop(conf * configure)
|
|||||||
}
|
}
|
||||||
close(client_sock);
|
close(client_sock);
|
||||||
}
|
}
|
||||||
|
close(server_sock);
|
||||||
}
|
}
|
||||||
|
|
||||||
void start_server(conf *configure)
|
void start_server(conf *configure)
|
||||||
|
@ -19,9 +19,10 @@ char help_information(void)
|
|||||||
0
|
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", 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);
|
fprintf(stderr, "%s %s\n", name, usage);
|
||||||
|
|
||||||
int l;
|
int l;
|
||||||
|
@ -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, "[V]", 3, V, len_v);
|
||||||
new_header_buffer = replace(new_header_buffer, &len, "[host]", 6, remote_host, len_remote_host);
|
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);
|
sprintf(port_copy, "%d", *remote_port);
|
||||||
int len_remote_port = strlen(port_copy);
|
int len_remote_port = strlen(port_copy);
|
||||||
new_header_buffer = replace(new_header_buffer, &len, "[port]", 6, port_copy, len_remote_port);
|
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, "[V]", 3, V, len_v);
|
||||||
new_header_buffer = replace(new_header_buffer, &len, "[host]", 6, remote_host, len_remote_host);
|
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);
|
sprintf(port_copy, "%d", *remote_port);
|
||||||
int len_remote_port = strlen(port_copy);
|
int len_remote_port = strlen(port_copy);
|
||||||
new_header_buffer = replace(new_header_buffer, &len, "[port]", 6, port_copy, len_remote_port);
|
new_header_buffer = replace(new_header_buffer, &len, "[port]", 6, port_copy, len_remote_port);
|
||||||
|
Loading…
Reference in New Issue
Block a user