Skip to content

Commit

Permalink
pgsql recorder: the connection to the server was not established if p…
Browse files Browse the repository at this point in the history
…gsql client didn't try ssl first. Fix bug TSUN-18

SVN Revision: 673
  • Loading branch information
nniclausse committed Jun 13, 2006
1 parent eff2fce commit a31ccbc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
3 changes: 3 additions & 0 deletions src/tsung_recorder/ts_client_proxy.erl
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ send({sslsocket,A,B},String, Plugin) ->
{ok, RealString } = Plugin:rewrite_ssl({request,String}),
?LOGF("Sending data to ssl socket ~p ~p (~p)~n", [A, B, RealString],?DEB),
ssl:send({sslsocket,A,B}, RealString);
send(undefined,_,_) ->
?LOG("No socket ! Error ~n",?CRIT),
erlang:error(error_no_socket_open);
send(Socket,String,_) ->
gen_tcp:send(Socket,String).

Expand Down
21 changes: 13 additions & 8 deletions src/tsung_recorder/ts_proxy_pgsql.erl
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,7 @@ rewrite_ssl(Data)->{ok, Data}.
%%--------------------------------------------------------------------
parse(State=#proxy{parse_status=Status},_,_SSocket,String=[0,0,0,8,4,210,22,47]) when Status==new ->
?LOG("SSL req: ~n",?DEB),
{ok, Socket} = gen_tcp:connect(?config(pgsql_server),?config(pgsql_port),
[{active, once},
{recbuf, ?tcp_buffer},
{sndbuf, ?tcp_buffer}
]),
?LOGF("ok, connected ~p~n",[Socket],?DEB),
Socket = connect(undefined),
ts_client_proxy:send(Socket, String, ?MODULE),
{ok, State#proxy{buffer=[],serversock = Socket }};
parse(State=#proxy{parse_status=Status},_,ServerSocket,String) when Status==new ->
Expand All @@ -78,8 +73,9 @@ parse(State=#proxy{parse_status=Status},_,ServerSocket,String) when Status==new
Req = get_db_user(Res),
?LOGF("Received data from client: split = ~p~n",[Res],?DEB),
ts_proxy_recorder:dorecord({Req#pgsql_request{type=connect}}),
ts_client_proxy:send(ServerSocket, Data, ?MODULE),
{ok, State#proxy{parse_status=open, buffer=[]} };
Socket = connect(ServerSocket),
ts_client_proxy:send(Socket, Data, ?MODULE),
{ok, State#proxy{parse_status=open, buffer=[], serversock = Socket} };
parse(State=#proxy{},_,ServerSocket,String) ->
NewString = lists:append(State#proxy.buffer, String),
Data = list_to_binary(NewString),
Expand Down Expand Up @@ -166,3 +162,12 @@ record_request(State=#state_rec{logfd=Fd},
{ok,State}.


connect(undefined) ->
{ok, Socket} = gen_tcp:connect(?config(pgsql_server),?config(pgsql_port),
[{active, once},
{recbuf, ?tcp_buffer},
{sndbuf, ?tcp_buffer}
]),
?LOGF("ok, connected ~p~n",[Socket],?DEB),
Socket;
connect(Socket) -> Socket.

0 comments on commit a31ccbc

Please sign in to comment.