prot-a-send-async.c 6.69 KB
Newer Older
Linus Tolke Y's avatar
Linus Tolke Y committed
1
/*
2
 * $Id: prot-a-send-async.c,v 0.32 2003/07/12 22:26:34 ceder Exp $
Per Cederqvist's avatar
Per Cederqvist committed
3
 * Copyright (C) 1991, 1993-1999, 2001-2002  Lysator Academic Computer Association.
Linus Tolke Y's avatar
Linus Tolke Y committed
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 *
 * This file is part of the LysKOM server.
 * 
 * LysKOM is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by 
 * the Free Software Foundation; either version 1, or (at your option) 
 * any later version.
 * 
 * LysKOM is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with LysKOM; see the file COPYING.  If not, write to
 * Lysator, c/o ISY, Linkoping University, S-581 83 Linkoping, SWEDEN,
 * or the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, 
 * MA 02139, USA.
 *
 * Please mail bug reports to bug-lyskom@lysator.liu.se. 
 */
Per Cederqvist's avatar
Per Cederqvist committed
25
26
27
28
/*
 * Asynchronous messages in protocol A.
 */

David Byers's avatar
David Byers committed
29
30
31
32
33

#ifdef HAVE_CONFIG_H
#  include <config.h>
#endif

Per Cederqvist's avatar
Per Cederqvist committed
34
#include <setjmp.h>
35
#include "timewrap.h"
36
37
38
39
40
#include <sys/types.h>
#include <sys/socket.h>
#ifdef HAVE_STDARG_H
#  include <stdarg.h>
#endif
Per Cederqvist's avatar
Per Cederqvist committed
41

Per Cederqvist's avatar
Per Cederqvist committed
42
43
#include "oop.h"

Per Cederqvist's avatar
Per Cederqvist committed
44
#include "misc-types.h"
45
#include "s-string.h"
Per Cederqvist's avatar
Per Cederqvist committed
46
#include "kom-types.h"
Per Cederqvist's avatar
Per Cederqvist committed
47
#include "com.h"
48
#include "async.h"
Per Cederqvist's avatar
Per Cederqvist committed
49
50
#include "connections.h"
#include "prot-a-send-async.h"
Per Cederqvist's avatar
Per Cederqvist committed
51
#include "async.h"
52
#include "isc-interface.h"
Per Cederqvist's avatar
Per Cederqvist committed
53
#include "prot-a-output.h"
Per Cederqvist's avatar
Per Cederqvist committed
54

55

Per Cederqvist's avatar
Per Cederqvist committed
56
57
58
static void
async_header(Connection *fp,
	     int   no_of_tokens,
59
	     enum async fnc)
Per Cederqvist's avatar
Per Cederqvist committed
60
{
61
62
63
    isc_putc(':', fp->isc_session);
    isc_putul(no_of_tokens, fp->isc_session);
    prot_a_output_ul(fp, fnc);
Per Cederqvist's avatar
Per Cederqvist committed
64
65
66
67
68
69
70
71
}



    
static void
async_trailer(Connection *fp)
{
72
73
    isc_putc('\n', fp->isc_session);
    isc_flush(fp->isc_session);
Per Cederqvist's avatar
Per Cederqvist committed
74
75
76
}


77
78
79
80
81
82
83
void
prot_a_async_new_text_old(Connection *cptr,
                          Text_no	      text_no,
                          Text_stat      *text_s)
{
    ASYNC_CHECK_ACCEPT(cptr, ay_new_text_old);
    async_header(cptr, 16, ay_new_text_old);
84
    prot_a_output_ul(cptr, text_no);
85
86
87
88
    prot_a_output_text_stat_old(cptr, text_s);
    async_trailer(cptr);
}

Per Cederqvist's avatar
Per Cederqvist committed
89
90
void
prot_a_async_new_text(Connection *cptr,
91
92
                      Text_no	      text_no,
                      Text_stat      *text_s)
Per Cederqvist's avatar
Per Cederqvist committed
93
{
94
    ASYNC_CHECK_ACCEPT(cptr, ay_new_text);
David Byers's avatar
David Byers committed
95
    async_header(cptr, 18, ay_new_text);
96
    prot_a_output_ul(cptr, text_no);
David Byers's avatar
David Byers committed
97
    prot_a_output_text_stat(cptr, text_s);
Per Cederqvist's avatar
Per Cederqvist committed
98
99
100
101
102
103
104
105
    async_trailer(cptr);
}


void
prot_a_async_i_am_on(Connection *cptr,
		     Who_info info)
{
106
    ASYNC_CHECK_ACCEPT(cptr, ay_i_am_on);
Per Cederqvist's avatar
Per Cederqvist committed
107
108
109
110
111
112
113
114
115
116
    async_header(cptr, 5, ay_i_am_on);
    prot_a_output_who_info(cptr, &info);
    async_trailer(cptr);
}

void
prot_a_async_logout(Connection *cptr,
		    Pers_no pers_no,
		    Session_no session_no)
{
117
    ASYNC_CHECK_ACCEPT(cptr, ay_logout);
Per Cederqvist's avatar
Per Cederqvist committed
118
    async_header(cptr, 2, ay_logout);
119
120
    prot_a_output_ul(cptr, pers_no);
    prot_a_output_ul(cptr, session_no);
Per Cederqvist's avatar
Per Cederqvist committed
121
122
123
124
125
126
127
128
129
    async_trailer(cptr);
}

void
prot_a_async_new_name(Connection *cptr,
		      Conf_no conf_no,
		      String old_name,
		      String new_name)
{
130
    ASYNC_CHECK_ACCEPT(cptr, ay_new_name);
Per Cederqvist's avatar
Per Cederqvist committed
131
    async_header(cptr, 3, ay_new_name);
132
    prot_a_output_ul(cptr, conf_no);
Per Cederqvist's avatar
Per Cederqvist committed
133
134
135
136
137
138
139
140
    prot_a_output_string(cptr, old_name);
    prot_a_output_string(cptr, new_name);
    async_trailer(cptr);
}

void
prot_a_async_sync_db(Connection *cptr)
{
141
    ASYNC_CHECK_ACCEPT(cptr, ay_sync_db);
Per Cederqvist's avatar
Per Cederqvist committed
142
143
144
145
146
147
148
149
    async_header(cptr, 0, ay_sync_db);
    async_trailer(cptr);
}

void
prot_a_async_forced_leave_conf(Connection *cptr,
			       Conf_no         conf_no)
{
150
    ASYNC_CHECK_ACCEPT(cptr, ay_leave_conf);
Per Cederqvist's avatar
Per Cederqvist committed
151
    async_header(cptr, 1, ay_leave_conf);
152
    prot_a_output_ul(cptr, conf_no);
Per Cederqvist's avatar
Per Cederqvist committed
153
154
155
156
157
158
159
160
    async_trailer(cptr);
}

void
prot_a_async_login(Connection *cptr,
		   Pers_no	   pers_no,
		   int		   session_no)
{
161
    ASYNC_CHECK_ACCEPT(cptr, ay_login);
Per Cederqvist's avatar
Per Cederqvist committed
162
    async_header(cptr, 2, ay_login);
163
164
    prot_a_output_ul(cptr, pers_no);
    prot_a_output_ul(cptr, session_no);
Per Cederqvist's avatar
Per Cederqvist committed
165
166
    async_trailer(cptr);
}
167

Per Cederqvist's avatar
Per Cederqvist committed
168
169
170
void
prot_a_async_rejected_connection(Connection *cptr)
{
171
    ASYNC_CHECK_ACCEPT(cptr, ay_rejected_connection);
Per Cederqvist's avatar
Per Cederqvist committed
172
173
174
175
176
177
    async_header(cptr, 0, ay_rejected_connection);
    async_trailer(cptr);
}
    
void
prot_a_async_send_message(Connection *cptr,
178
			  Conf_no     recipient,
Per Cederqvist's avatar
Per Cederqvist committed
179
180
181
			  Pers_no     sender,
			  String      message)
{
182
    ASYNC_CHECK_ACCEPT(cptr, ay_send_message);
Per Cederqvist's avatar
Per Cederqvist committed
183
    async_header(cptr, 3, ay_send_message);
184
185
    prot_a_output_ul(cptr, recipient);
    prot_a_output_ul(cptr, sender);
Per Cederqvist's avatar
Per Cederqvist committed
186
187
188
    prot_a_output_string(cptr, message);
    async_trailer(cptr);
}
189
190
191
192
193
194
195

void
prot_a_async_deleted_text(Connection *cptr,
                         Text_no	      text_no,
                         Text_stat      *text_s)
{
    ASYNC_CHECK_ACCEPT(cptr, ay_deleted_text);
196
    async_header(cptr, 18, ay_deleted_text);
197
    prot_a_output_ul(cptr, text_no);
198
199
200
201
    prot_a_output_text_stat(cptr, text_s);
    async_trailer(cptr);
}

David Byers's avatar
David Byers committed
202
void
203
204
205
206
prot_a_async_new_recipient(Connection     *cptr,
                           Text_no        text_no,
                           Conf_no        conf_no,
                           enum info_type type)
David Byers's avatar
David Byers committed
207
208
209
{
    ASYNC_CHECK_ACCEPT(cptr, ay_new_recipient);
    async_header(cptr, 3, ay_new_recipient);
210
211
212
    prot_a_output_ul(cptr, text_no);
    prot_a_output_ul(cptr, conf_no);
    prot_a_output_ul(cptr, type);
David Byers's avatar
David Byers committed
213
214
215
216
    async_trailer(cptr);
}

void
217
218
219
220
prot_a_async_sub_recipient(Connection     *cptr,
                           Text_no        text_no,
                           Conf_no        conf_no,
                           enum info_type type)
David Byers's avatar
David Byers committed
221
222
223
{
    ASYNC_CHECK_ACCEPT(cptr, ay_sub_recipient);
    async_header(cptr, 3, ay_sub_recipient);
224
225
226
    prot_a_output_ul(cptr, text_no);
    prot_a_output_ul(cptr, conf_no);
    prot_a_output_ul(cptr, type);
David Byers's avatar
David Byers committed
227
228
229
230
231
232
233
234
235
236
    async_trailer(cptr);
}


void
prot_a_async_new_membership(Connection   *cptr,
                            Pers_no pers_no,
                            Conf_no conf_no)
{
    ASYNC_CHECK_ACCEPT(cptr, ay_new_membership);
237
    async_header(cptr, 2, ay_new_membership);
238
239
    prot_a_output_ul(cptr, pers_no);
    prot_a_output_ul(cptr, conf_no);
David Byers's avatar
David Byers committed
240
241
    async_trailer(cptr);
}
242

243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
void
prot_a_async_new_user_area(Connection   *cptr,
			   Pers_no       pers_no,
			   Text_no       old_user_area,
			   Text_no       new_user_area)
{
    ASYNC_CHECK_ACCEPT(cptr, ay_new_user_area);
    async_header(cptr, 3, ay_new_user_area);
    prot_a_output_ul(cptr, pers_no);
    prot_a_output_ul(cptr, old_user_area);
    prot_a_output_ul(cptr, new_user_area);
    async_trailer(cptr);
}


258
259
260
261
262
263
264
265
266
267
268
269
270
#ifdef DEBUG_CALLS

void
prot_a_async_garb_ended(Connection *cptr,
			int deleted_texts)
{
    ASYNC_CHECK_ACCEPT(cptr, ay_garb_ended);
    async_header(cptr, 1, ay_garb_ended);
    prot_a_output_ul(cptr, deleted_texts);
    async_trailer(cptr);
}

#endif