1 /************************************************************************
2 * IRC - Internet Relay Chat, servlink/servlink.c
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 1, or (at your option)
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 * $Id: control.c 1285 2006-05-05 15:03:53Z nenolod $
23 #include <sys/types.h>
37 static cmd_handler cmd_set_zip_out_level
;
38 static cmd_handler cmd_start_zip_out
;
39 static cmd_handler cmd_start_zip_in
;
40 static cmd_handler cmd_init
;
42 struct command_def command_table
[] = {
43 {CMD_SET_ZIP_OUT_LEVEL
, cmd_set_zip_out_level
, COMMAND_FLAG_DATA
},
44 {CMD_START_ZIP_OUT
, cmd_start_zip_out
, 0},
45 {CMD_START_ZIP_IN
, cmd_start_zip_in
, 0},
46 {CMD_INJECT_RECVQ
, process_recvq
, COMMAND_FLAG_DATA
},
47 {CMD_INJECT_SENDQ
, process_sendq
, COMMAND_FLAG_DATA
},
48 {CMD_INIT
, cmd_init
, 0},
49 {CMD_ZIPSTATS
, send_zipstats
, 0},
54 cmd_set_zip_out_level(struct ctrl_command
*cmd
)
57 out_state
.zip_state
.level
= *cmd
->data
;
58 if((out_state
.zip_state
.level
< -1) || (out_state
.zip_state
.level
> 9))
59 send_error("invalid compression level %d", out_state
.zip_state
.level
);
61 send_error("can't set compression level - no libz support!");
66 cmd_start_zip_out(struct ctrl_command
*cmd
)
72 send_error("can't start compression - already started!");
74 out_state
.zip_state
.z_stream
.total_in
= 0;
75 out_state
.zip_state
.z_stream
.total_out
= 0;
76 out_state
.zip_state
.z_stream
.zalloc
= (alloc_func
) 0;
77 out_state
.zip_state
.z_stream
.zfree
= (free_func
) 0;
78 out_state
.zip_state
.z_stream
.data_type
= Z_ASCII
;
80 if(out_state
.zip_state
.level
<= 0)
81 out_state
.zip_state
.level
= Z_DEFAULT_COMPRESSION
;
83 if((ret
= deflateInit(&out_state
.zip_state
.z_stream
, out_state
.zip_state
.level
)) != Z_OK
)
84 send_error("deflateInit failed: %s", zError(ret
));
88 send_error("can't start compression - no libz support!");
93 cmd_start_zip_in(struct ctrl_command
*cmd
)
99 send_error("can't start decompression - already started!");
101 in_state
.zip_state
.z_stream
.total_in
= 0;
102 in_state
.zip_state
.z_stream
.total_out
= 0;
103 in_state
.zip_state
.z_stream
.zalloc
= (alloc_func
) 0;
104 in_state
.zip_state
.z_stream
.zfree
= (free_func
) 0;
105 in_state
.zip_state
.z_stream
.data_type
= Z_ASCII
;
106 if((ret
= inflateInit(&in_state
.zip_state
.z_stream
)) != Z_OK
)
107 send_error("inflateInit failed: %s", zError(ret
));
110 send_error("can't start decompression - no libz support!");
116 cmd_init(struct ctrl_command
*cmd
)
118 if(in_state
.active
|| out_state
.active
)
119 send_error("CMD_INIT sent twice!");
122 out_state
.active
= 1;
123 CONTROL
.read_cb
= read_ctrl
;
124 CONTROL
.write_cb
= NULL
;
125 LOCAL
.read_cb
= read_data
;
126 LOCAL
.write_cb
= NULL
;
127 REMOTE
.read_cb
= read_net
;
128 REMOTE
.write_cb
= NULL
;