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.
21 #include <sys/types.h>
35 static cmd_handler cmd_set_zip_out_level
;
36 static cmd_handler cmd_start_zip_out
;
37 static cmd_handler cmd_start_zip_in
;
38 static cmd_handler cmd_init
;
40 struct command_def command_table
[] = {
41 {CMD_SET_ZIP_OUT_LEVEL
, cmd_set_zip_out_level
, COMMAND_FLAG_DATA
},
42 {CMD_START_ZIP_OUT
, cmd_start_zip_out
, 0},
43 {CMD_START_ZIP_IN
, cmd_start_zip_in
, 0},
44 {CMD_INJECT_RECVQ
, process_recvq
, COMMAND_FLAG_DATA
},
45 {CMD_INJECT_SENDQ
, process_sendq
, COMMAND_FLAG_DATA
},
46 {CMD_INIT
, cmd_init
, 0},
47 {CMD_ZIPSTATS
, send_zipstats
, 0},
52 cmd_set_zip_out_level(struct ctrl_command
*cmd
)
55 out_state
.zip_state
.level
= *cmd
->data
;
56 if((out_state
.zip_state
.level
< -1) || (out_state
.zip_state
.level
> 9))
57 send_error("invalid compression level %d", out_state
.zip_state
.level
);
59 send_error("can't set compression level - no libz support!");
64 cmd_start_zip_out(struct ctrl_command
*cmd
)
70 send_error("can't start compression - already started!");
72 out_state
.zip_state
.z_stream
.total_in
= 0;
73 out_state
.zip_state
.z_stream
.total_out
= 0;
74 out_state
.zip_state
.z_stream
.zalloc
= (alloc_func
) 0;
75 out_state
.zip_state
.z_stream
.zfree
= (free_func
) 0;
76 out_state
.zip_state
.z_stream
.data_type
= Z_ASCII
;
78 if(out_state
.zip_state
.level
<= 0)
79 out_state
.zip_state
.level
= Z_DEFAULT_COMPRESSION
;
81 if((ret
= deflateInit(&out_state
.zip_state
.z_stream
, out_state
.zip_state
.level
)) != Z_OK
)
82 send_error("deflateInit failed: %s", zError(ret
));
86 send_error("can't start compression - no libz support!");
91 cmd_start_zip_in(struct ctrl_command
*cmd
)
97 send_error("can't start decompression - already started!");
99 in_state
.zip_state
.z_stream
.total_in
= 0;
100 in_state
.zip_state
.z_stream
.total_out
= 0;
101 in_state
.zip_state
.z_stream
.zalloc
= (alloc_func
) 0;
102 in_state
.zip_state
.z_stream
.zfree
= (free_func
) 0;
103 in_state
.zip_state
.z_stream
.data_type
= Z_ASCII
;
104 if((ret
= inflateInit(&in_state
.zip_state
.z_stream
)) != Z_OK
)
105 send_error("inflateInit failed: %s", zError(ret
));
108 send_error("can't start decompression - no libz support!");
114 cmd_init(struct ctrl_command
*cmd
)
116 if(in_state
.active
|| out_state
.active
)
117 send_error("CMD_INIT sent twice!");
120 out_state
.active
= 1;
121 CONTROL
.read_cb
= read_ctrl
;
122 CONTROL
.write_cb
= NULL
;
123 LOCAL
.read_cb
= read_data
;
124 LOCAL
.write_cb
= NULL
;
125 REMOTE
.read_cb
= read_net
;
126 REMOTE
.write_cb
= NULL
;