prot-a-output.c 27.1 KB
Newer Older
Linus Tolke's avatar
Linus Tolke committed
1
/*
2
 * $Id: prot-a-output.c,v 0.53 2002/01/01 09:30:52 ceder Exp $
Per Cederqvist's avatar
Per Cederqvist committed
3
 * Copyright (C) 1991-2001  Lysator Academic Computer Association.
Linus Tolke's avatar
Linus Tolke 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
 * prot-a-output.c  -  write objects through an ISC connection.
Per Cederqvist's avatar
Per Cederqvist committed
27
28
29
30
 *
 * Written by ceder 1990-07-13
 */

David Byers's avatar
David Byers committed
31
32
33
34
35
36


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

Per Cederqvist's avatar
Per Cederqvist committed
37
#include <time.h>
Per Cederqvist's avatar
Per Cederqvist committed
38
#include <setjmp.h>
39
40
41
42
43
#include <sys/types.h>
#include <sys/socket.h>
#ifdef HAVE_STDARG_H
#  include <stdarg.h>
#endif
44
#include <assert.h>
Per Cederqvist's avatar
Per Cederqvist committed
45

46
#include "s-string.h"
Per Cederqvist's avatar
Per Cederqvist committed
47
48
#include "kom-types.h"
#include "isc-interface.h"
Per Cederqvist's avatar
Per Cederqvist committed
49
#include "com.h"
50
#include "async.h"
Per Cederqvist's avatar
Per Cederqvist committed
51
#include "connections.h"
Per Cederqvist's avatar
Per Cederqvist committed
52
53
#include "prot-a-output.h"
#include "lyskomd.h"
54
#include "param.h"
55
#include "local-to-global.h"
Per Cederqvist's avatar
Per Cederqvist committed
56

57
58
59
60
61
62
63
64
void
prot_a_output_ul(Connection *fp,
		 unsigned long ul)
{
    isc_putc(' ', fp->isc_session);
    isc_putul(ul, fp->isc_session);
}

Per Cederqvist's avatar
Per Cederqvist committed
65
66
void
prot_a_output_person (Connection *fp,
67
                      Person *person)
Per Cederqvist's avatar
Per Cederqvist committed
68
{
69
    Local_text_no first_created = l2g_next_key(&person->created_texts, 0);
70
    Local_text_no uncreated = l2g_first_appendable_key(&person->created_texts);
71
72
    Local_text_no num_created;

73
74
75
76
    if (first_created == 0)
	first_created = uncreated;

    num_created = uncreated - first_created;
77

Per Cederqvist's avatar
Per Cederqvist committed
78
79
80
81
82
83
    prot_a_output_string (fp, person->username);
    prot_a_output_priv_bits (fp, person->privileges);
    prot_a_output_personal_flags (fp, person->flags);

    prot_a_output_time(fp, person->last_login);

84
85
86
87
88
89
90
91
92
93
94
95
96
    prot_a_output_ul(fp, person->user_area);
    prot_a_output_ul(fp, person->total_time_present);
    prot_a_output_ul(fp, person->sessions);
    prot_a_output_ul(fp, person->created_lines);
    prot_a_output_ul(fp, person->created_bytes);
    prot_a_output_ul(fp, person->read_texts);
    prot_a_output_ul(fp, person->no_of_text_fetches);
    prot_a_output_ul(fp, person->created_persons);
    prot_a_output_ul(fp, person->created_confs);
    prot_a_output_ul(fp, first_created);
    prot_a_output_ul(fp, num_created);
    prot_a_output_ul(fp, person->marks.no_of_marks);
    prot_a_output_ul(fp, person->conferences.no_of_confs);
Per Cederqvist's avatar
Per Cederqvist committed
97
98
}

99
100
101
void prot_a_output_membership_type(Connection *fp,
                                   const Membership_type type)
{
102
103
104
105
106
107
108
109
110
    isc_putc(' ', fp->isc_session);
    isc_putc(type.invitation + '0', fp->isc_session);
    isc_putc(type.passive    + '0', fp->isc_session);
    isc_putc(type.secret     + '0', fp->isc_session);
    isc_putc(type.reserved1  + '0', fp->isc_session);
    isc_putc(type.reserved2  + '0', fp->isc_session);
    isc_putc(type.reserved3  + '0', fp->isc_session);
    isc_putc(type.reserved4  + '0', fp->isc_session);
    isc_putc(type.reserved5  + '0', fp->isc_session);
111
112
113
114
115
}

void prot_a_output_membership(Connection *fp,
                              const Membership *mship)
{
116
    prot_a_output_ul(fp, mship->position);
117
    prot_a_output_membership_old(fp, mship);
118
    prot_a_output_ul(fp, mship->added_by);
119
120
121
122
    prot_a_output_time(fp, mship->added_at);
    prot_a_output_membership_type(fp, mship->type);
}

Per Cederqvist's avatar
Per Cederqvist committed
123
void
124
125
prot_a_output_membership_old(Connection *fp,
			     const Membership *mship)
Per Cederqvist's avatar
Per Cederqvist committed
126
127
128
129
130
{
    int i;
    
    prot_a_output_time(fp, mship->last_time_read );
    
131
132
133
134
    prot_a_output_ul(fp, mship->conf_no);
    prot_a_output_ul(fp, mship->priority);
    prot_a_output_ul(fp, mship->last_text_read);
    prot_a_output_ul(fp, mship->no_of_read);
Per Cederqvist's avatar
Per Cederqvist committed
135
136
137
    
    if ( mship->read_texts != NULL && mship->no_of_read > 0)
    {
138
	isc_puts(" {", fp->isc_session);
Per Cederqvist's avatar
Per Cederqvist committed
139
	for ( i = 0; i < mship->no_of_read; i++)
140
	    prot_a_output_ul(fp, mship->read_texts[i]);
Per Cederqvist's avatar
Per Cederqvist committed
141
	
142
	isc_puts(" }", fp->isc_session);
Per Cederqvist's avatar
Per Cederqvist committed
143
144
    }
    else
145
	isc_puts(" *", fp->isc_session);
Per Cederqvist's avatar
Per Cederqvist committed
146
147
148
}

	
149
150
151
152
153
154
void
prot_a_output_membership_list_old (Connection	* fp,
                                   Membership_list	  mlist)
{
    int i;
    
155
    prot_a_output_ul(fp, mlist.no_of_confs);
156
157
158

    if ( mlist.confs != NULL && mlist.no_of_confs > 0 )
    {
159
	isc_puts(" {", fp->isc_session);
160
161
	for ( i = 0; i < mlist.no_of_confs; i++)
	    prot_a_output_membership_old(fp, mlist.confs + i);
162
	isc_puts(" }", fp->isc_session);
163
164
    }
    else
165
	isc_puts(" *", fp->isc_session);
166
167
}

Per Cederqvist's avatar
Per Cederqvist committed
168
169
void
prot_a_output_membership_list (Connection	* fp,
170
                               Membership_list	  mlist)
Per Cederqvist's avatar
Per Cederqvist committed
171
172
173
{
    int i;
    
174
    prot_a_output_ul(fp, mlist.no_of_confs);
Per Cederqvist's avatar
Per Cederqvist committed
175
176
177

    if ( mlist.confs != NULL && mlist.no_of_confs > 0 )
    {
178
	isc_puts(" {", fp->isc_session);
Per Cederqvist's avatar
Per Cederqvist committed
179
180
	for ( i = 0; i < mlist.no_of_confs; i++)
	    prot_a_output_membership(fp, mlist.confs + i);
181
	isc_puts(" }", fp->isc_session);
Per Cederqvist's avatar
Per Cederqvist committed
182
183
    }
    else
184
	isc_puts(" *", fp->isc_session);
Per Cederqvist's avatar
Per Cederqvist committed
185
186
187
188
189
190
}

void
prot_a_output_conf_list(Connection *fp,
			Conf_list_old conf_list)
{
191
    unsigned long i;
Per Cederqvist's avatar
Per Cederqvist committed
192

193
    prot_a_output_ul(fp, conf_list.no_of_conf_nos);
Per Cederqvist's avatar
Per Cederqvist committed
194
195
    if ( conf_list.conf_nos != NULL && conf_list.no_of_conf_nos > 0 )
    {
196
	isc_puts(" {", fp->isc_session);
Per Cederqvist's avatar
Per Cederqvist committed
197
	for ( i = 0; i < conf_list.no_of_conf_nos; i++ )
198
199
	    prot_a_output_ul(fp, conf_list.conf_nos[i]);
	isc_puts(" }", fp->isc_session);
Per Cederqvist's avatar
Per Cederqvist committed
200
201
    }
    else
202
	isc_puts(" *", fp->isc_session);
Per Cederqvist's avatar
Per Cederqvist committed
203
204
205

    if ( conf_list.type_of_conf != NULL && conf_list.no_of_conf_nos > 0 )
    {
206
	isc_puts(" {", fp->isc_session);
Per Cederqvist's avatar
Per Cederqvist committed
207
208
	for ( i = 0; i < conf_list.no_of_conf_nos; i++ )
	    prot_a_output_conf_type(fp, conf_list.type_of_conf[ i ]);
209
	isc_puts(" }", fp->isc_session);
Per Cederqvist's avatar
Per Cederqvist committed
210
211
    }
    else
212
	isc_puts(" *", fp->isc_session);
Per Cederqvist's avatar
Per Cederqvist committed
213
214
215
216
217
218
219
220
}

void
prot_a_output_conf_no_list(Connection *fp,
			   Conf_no_list conf_no_list)
{
    int i;

221
    prot_a_output_ul(fp, conf_no_list.no_of_confs);
Per Cederqvist's avatar
Per Cederqvist committed
222
223
    if ( conf_no_list.conf_nos != NULL && conf_no_list.no_of_confs > 0 )
    {
224
	isc_puts(" {", fp->isc_session);
Per Cederqvist's avatar
Per Cederqvist committed
225
	for ( i = 0; i < conf_no_list.no_of_confs; i++ )
226
227
	    prot_a_output_ul(fp, conf_no_list.conf_nos[i]);
	isc_puts(" }", fp->isc_session);
Per Cederqvist's avatar
Per Cederqvist committed
228
229
    }
    else
230
	isc_puts(" *", fp->isc_session);
Per Cederqvist's avatar
Per Cederqvist committed
231
232
233
234
235
}
    

void
prot_a_output_conference (Connection *fp,
236
237
                          Conference *conf_c)
{
238
    Local_text_no first_local_no = l2g_next_key(&conf_c->texts, 0);
239
    Local_text_no uncreated = l2g_first_appendable_key(&conf_c->texts);
240
241
    Local_text_no no_of_texts;

242
243
244
245
    if (first_local_no == 0)
	first_local_no = uncreated;

    no_of_texts = uncreated - first_local_no;
246

247
248
    prot_a_output_string(fp, conf_c->name);
    prot_a_output_extended_conf_type(fp, conf_c->type);
249
250
251
252
253
254
255
256
257
258
259
260
261
262
    prot_a_output_time(fp, conf_c->creation_time );
    prot_a_output_time(fp, conf_c->last_written );
    prot_a_output_ul(fp, conf_c->creator);
    prot_a_output_ul(fp, conf_c->presentation);
    prot_a_output_ul(fp, conf_c->supervisor);
    prot_a_output_ul(fp, conf_c->permitted_submitters);
    prot_a_output_ul(fp, conf_c->super_conf);
    prot_a_output_ul(fp, conf_c->msg_of_day);
    prot_a_output_ul(fp, conf_c->nice);
    prot_a_output_ul(fp, conf_c->keep_commented);
    prot_a_output_ul(fp, conf_c->members.no_of_members);
    prot_a_output_ul(fp, first_local_no);
    prot_a_output_ul(fp, no_of_texts);
    prot_a_output_ul(fp, conf_c->expire);
263
264
265
266
267
268
    prot_a_output_aux_item_list (fp, &conf_c->aux_item_list);
}

void
prot_a_output_conference_old (Connection *fp,
                              Conference *conf_c)
Per Cederqvist's avatar
Per Cederqvist committed
269
{
270
    Local_text_no first_local_no = l2g_next_key(&conf_c->texts, 0);
271
    Local_text_no uncreated = l2g_first_appendable_key(&conf_c->texts);
272
273
    Local_text_no no_of_texts;

274
275
276
277
    if (first_local_no == 0)
	first_local_no = uncreated;

    no_of_texts = uncreated - first_local_no;
278

Per Cederqvist's avatar
Per Cederqvist committed
279
280
281
282
283
284
285
    prot_a_output_string(fp, conf_c->name);

    prot_a_output_conf_type(fp, conf_c->type);

    prot_a_output_time(fp, conf_c -> creation_time );
    prot_a_output_time(fp, conf_c -> last_written );

286
287
288
289
290
291
292
293
294
295
    prot_a_output_ul(fp, conf_c->creator);
    prot_a_output_ul(fp, conf_c->presentation);
    prot_a_output_ul(fp, conf_c->supervisor);
    prot_a_output_ul(fp, conf_c->permitted_submitters);
    prot_a_output_ul(fp, conf_c->super_conf);
    prot_a_output_ul(fp, conf_c->msg_of_day);
    prot_a_output_ul(fp, conf_c->nice);
    prot_a_output_ul(fp, conf_c->members.no_of_members);
    prot_a_output_ul(fp, first_local_no);
    prot_a_output_ul(fp, no_of_texts);
Per Cederqvist's avatar
Per Cederqvist committed
296
297
}

298
299
300
301
302
void prot_a_output_uconference(Connection *fp,
			       Small_conf *conf_c)
{
    prot_a_output_string(fp, conf_c -> name);
    prot_a_output_extended_conf_type(fp, conf_c -> type);
303
304
    prot_a_output_ul(fp, conf_c->highest_local_no);
    prot_a_output_ul(fp, conf_c->nice);
305
306
}

Per Cederqvist's avatar
Per Cederqvist committed
307
308
309
310
311
312
313

void
prot_a_output_mark_list(Connection *fp,
			Mark_list mark_list)
{
    int i;

314
    prot_a_output_ul(fp, mark_list.no_of_marks);
Per Cederqvist's avatar
Per Cederqvist committed
315
316
317

    if ( mark_list.marks != NULL && mark_list.no_of_marks > 0 )
    {
318
	isc_puts(" {", fp->isc_session);
Per Cederqvist's avatar
Per Cederqvist committed
319
320
	for ( i = 0; i < mark_list.no_of_marks; i++ )
	    prot_a_output_mark(fp, mark_list.marks[ i ]);
321
	isc_puts(" }", fp->isc_session);
Per Cederqvist's avatar
Per Cederqvist committed
322
323
    }
    else
324
	isc_puts(" *", fp->isc_session);
Per Cederqvist's avatar
Per Cederqvist committed
325
326
327
    
}

328
329
330
331
void
prot_a_output_aux_item_flags(Connection *fp,
                             Aux_item_flags flags)
{
332
333
334
335
336
337
338
339
340
    isc_putc(' ', fp->isc_session);
    isc_putc(flags.deleted + '0', fp->isc_session);
    isc_putc(flags.inherit + '0', fp->isc_session);
    isc_putc(flags.secret + '0', fp->isc_session);
    isc_putc(flags.hide_creator + '0', fp->isc_session);
    isc_putc(flags.dont_garb + '0', fp->isc_session);
    isc_putc(flags.reserved3 + '0', fp->isc_session);
    isc_putc(flags.reserved4 + '0', fp->isc_session);
    isc_putc(flags.reserved5 + '0', fp->isc_session);
341
}
Per Cederqvist's avatar
Per Cederqvist committed
342
343

void
344
345
346
prot_a_output_aux_item(Connection *fp,
                       Aux_item *item)
{
347
348
349
    prot_a_output_ul(fp, item->aux_no);
    prot_a_output_ul(fp, item->tag);
    prot_a_output_ul(fp, item->creator);
350
351
    prot_a_output_time(fp, item->sent_at);
    prot_a_output_aux_item_flags(fp, item->flags);
352
    prot_a_output_ul(fp, item->inherit_limit);
353
354
355
356
357
358
    prot_a_output_string(fp, item->data);
}

void
prot_a_output_text_stat_old(Connection *fp,
                            Text_stat *t_stat)
Per Cederqvist's avatar
Per Cederqvist committed
359
360
361
362
363
{
    int i;

    prot_a_output_time(fp, t_stat->creation_time);
    
364
365
366
367
368
    prot_a_output_ul(fp, t_stat->author);
    prot_a_output_ul(fp, t_stat->no_of_lines);
    prot_a_output_ul(fp, t_stat->no_of_chars);
    prot_a_output_ul(fp, t_stat->no_of_marks);
    prot_a_output_ul(fp, t_stat->no_of_misc);
Per Cederqvist's avatar
Per Cederqvist committed
369
370
371

    if ( t_stat->misc_items != NULL && t_stat->no_of_misc > 0 )
    {
372
	isc_puts(" {", fp->isc_session);
Per Cederqvist's avatar
Per Cederqvist committed
373
374
	for ( i = 0; i < t_stat->no_of_misc; i++ )
	    prot_a_output_misc_info(fp, t_stat->misc_items[ i ]);
375
	isc_puts(" }", fp->isc_session);
Per Cederqvist's avatar
Per Cederqvist committed
376
377
    }
    else
378
	isc_puts(" *", fp->isc_session);
Per Cederqvist's avatar
Per Cederqvist committed
379
380
}	

381
382
383
384
385
386
void
prot_a_output_aux_item_list(Connection *fp,
			    Aux_item_list *aux)
{
  int i;

387
    prot_a_output_ul(fp, aux->length);
388
389
390

    if ( aux->items != NULL && aux->length > 0 )
    {
391
        isc_puts(" {", fp->isc_session);
392
393
        for (i = 0; i < aux->length; i++)
            prot_a_output_aux_item(fp, &aux->items[i]);
394
        isc_puts(" }", fp->isc_session);
395
396
    }
    else
397
	isc_puts(" *", fp->isc_session);
398
399
400
401
402
403
404
405
406
407
}

void
prot_a_output_text_stat(Connection *fp,
                        Text_stat *t_stat)
{
    prot_a_output_text_stat_old(fp, t_stat);
    prot_a_output_aux_item_list(fp, &t_stat->aux_item_list);
}	

Per Cederqvist's avatar
Per Cederqvist committed
408

409
410
411
static void
prot_a_output_who_info_ident(Connection *fp,
			     Who_info_ident *info)
Per Cederqvist's avatar
Per Cederqvist committed
412
{
413
414
415
    prot_a_output_ul(fp, info->person);
    prot_a_output_ul(fp, info->working_conference);
    prot_a_output_ul(fp, info->session_no);
Per Cederqvist's avatar
Per Cederqvist committed
416
417
418

    prot_a_output_string(fp, info->what_am_i_doing);
    prot_a_output_string(fp, info->username);
419
420
421
422
423
    prot_a_output_string(fp, info->hostname);
    prot_a_output_string(fp, info->ident_user);
}


424
void
425
426
427
prot_a_output_who_info(Connection *fp,
		       Who_info *info)
{
428
429
430
    prot_a_output_ul(fp, info->person);
    prot_a_output_ul(fp, info->working_conference);
    prot_a_output_ul(fp, info->session_no);
431
432

    prot_a_output_string(fp, info->what_am_i_doing); 
433
    prot_a_output_string(fp, info->username);
Per Cederqvist's avatar
Per Cederqvist committed
434
435
436
437
438
439
440
441
442
}


void
prot_a_output_who_info_list(Connection *fp,
			    Who_info_list info)
{
    int i;
    
443
    prot_a_output_ul(fp, info.no_of_persons);
Per Cederqvist's avatar
Per Cederqvist committed
444
445
446

    if ( info.info != NULL && info.no_of_persons > 0 )
    {
447
	isc_puts(" {", fp->isc_session);
Per Cederqvist's avatar
Per Cederqvist committed
448
449
450
	for ( i = 0; i < info.no_of_persons; i++ )
	{
	    prot_a_output_who_info(fp, &info.info[ i ]);
451
452
453
454
	    /* The username is specially alloced in who_is_on() in
	       session.c. */
	    s_clear(&info.info[i].username);
	}
455
	isc_puts(" }", fp->isc_session);
456
457
    }
    else
458
	isc_puts(" *", fp->isc_session);
459
460
461
462
463
464
465
466
}

void
prot_a_output_who_info_ident_list(Connection *fp,
				  Who_info_ident_list info)
{
    int i;
    
467
    prot_a_output_ul(fp, info.no_of_persons);
468
469
470

    if ( info.info != NULL && info.no_of_persons > 0 )
    {
471
	isc_puts(" {", fp->isc_session);
472
473
474
	for ( i = 0; i < info.no_of_persons; i++ )
	{
	    prot_a_output_who_info_ident(fp, &info.info[ i ]);
Per Cederqvist's avatar
Per Cederqvist committed
475
	}
476
	isc_puts(" }", fp->isc_session);
Per Cederqvist's avatar
Per Cederqvist committed
477
478
    }
    else
479
	isc_puts(" *", fp->isc_session);
Per Cederqvist's avatar
Per Cederqvist committed
480
481
482
483
484
485
486
487
}

void
prot_a_output_who_info_list_old(Connection *fp,
				Who_info_list_old info)
{
    int i;
    
488
    prot_a_output_ul(fp, info.no_of_persons);
Per Cederqvist's avatar
Per Cederqvist committed
489
490
491

    if ( info.info != NULL && info.no_of_persons > 0 )
    {
492
	isc_puts(" {", fp->isc_session);
Per Cederqvist's avatar
Per Cederqvist committed
493
494
	for ( i = 0; i < info.no_of_persons; i++ )
	{
495
496
	    prot_a_output_ul(fp, info.info[i].person);
	    prot_a_output_ul(fp, info.info[i].working_conference);
Per Cederqvist's avatar
Per Cederqvist committed
497
498
499
	    
	    prot_a_output_string(fp, info.info[ i ].what_am_i_doing);
	}
500
	isc_puts(" }", fp->isc_session);
Per Cederqvist's avatar
Per Cederqvist committed
501
502
    }
    else
503
	isc_puts(" *", fp->isc_session);
Per Cederqvist's avatar
Per Cederqvist committed
504
505
506
507
508
509
}

void
prot_a_output_session_info(Connection *fp,
			   Session_info *info)
{
510
511
512
    prot_a_output_ul(fp, info->person);
    prot_a_output_ul(fp, info->working_conference);
    prot_a_output_ul(fp, info->session);
Per Cederqvist's avatar
Per Cederqvist committed
513
514
515
516

    prot_a_output_string(fp, info->what_am_i_doing);
    prot_a_output_string(fp, info->username);

517
    prot_a_output_ul(fp, info->idle_time);
Per Cederqvist's avatar
Per Cederqvist committed
518
519
    prot_a_output_time(fp, info->connection_time);
}
520
521
522

void
prot_a_output_session_info_ident(Connection *fp,
523
				 Session_info_ident *info)
524
{
525
526
527
    prot_a_output_ul(fp, info->person);
    prot_a_output_ul(fp, info->working_conference);
    prot_a_output_ul(fp, info->session);
528
529
530
531
532
533

    prot_a_output_string(fp, info->what_am_i_doing);
    prot_a_output_string(fp, info->username);
    prot_a_output_string(fp, info->hostname);
    prot_a_output_string(fp, info->ident_user);

534
    prot_a_output_ul(fp, info->idle_time);
535
536
    prot_a_output_time(fp, info->connection_time);
}
Per Cederqvist's avatar
Per Cederqvist committed
537
538
539
    
void
prot_a_output_info(Connection *fp,
540
541
542
543
544
545
546
547
548
                   Info *info)
{
    prot_a_output_info_old(fp, info);
    prot_a_output_aux_item_list(fp, &info->aux_item_list);
}

void
prot_a_output_info_old(Connection *fp,
                       Info *info)
Per Cederqvist's avatar
Per Cederqvist committed
549
{
550
551
552
553
554
555
    prot_a_output_ul(fp, info->version);
    prot_a_output_ul(fp, info->conf_pres_conf);
    prot_a_output_ul(fp, info->pers_pres_conf);
    prot_a_output_ul(fp, info->motd_conf);
    prot_a_output_ul(fp, info->kom_news_conf);
    prot_a_output_ul(fp, info->motd_of_lyskom);
Per Cederqvist's avatar
Per Cederqvist committed
556
557
558
559
560
561
562
}


extern void
prot_a_output_string(Connection *fp,
		     String str)
{
563
564
565
    prot_a_output_ul(fp, str.len);
    isc_putc('H', fp->isc_session);
    isc_write(fp->isc_session, str.string, str.len);
Per Cederqvist's avatar
Per Cederqvist committed
566
567
568
569
570
571
572
}


extern void
prot_a_output_priv_bits(Connection *fp,
			Priv_bits bits)
{
573
574
575
576
577
578
579
    isc_putc(' ', fp->isc_session);
    isc_putc(bits.wheel + '0', fp->isc_session);
    isc_putc(bits.admin + '0', fp->isc_session);
    isc_putc(bits.statistic + '0', fp->isc_session);
    isc_putc(bits.create_pers + '0', fp->isc_session);
    isc_putc(bits.create_conf + '0', fp->isc_session);
    isc_putc(bits.change_name + '0', fp->isc_session);
580
    isc_putc(bits.flg7 + '0', fp->isc_session);
581
582
583
584
585
586
587
588
589
    isc_putc(bits.flg8 + '0', fp->isc_session);
    isc_putc(bits.flg9 + '0', fp->isc_session);
    isc_putc(bits.flg10 + '0', fp->isc_session);
    isc_putc(bits.flg11 + '0', fp->isc_session);
    isc_putc(bits.flg12 + '0', fp->isc_session);
    isc_putc(bits.flg13 + '0', fp->isc_session);
    isc_putc(bits.flg14 + '0', fp->isc_session);
    isc_putc(bits.flg15 + '0', fp->isc_session);
    isc_putc(bits.flg16 + '0', fp->isc_session);
Per Cederqvist's avatar
Per Cederqvist committed
590
591
592
593
594
595
596
}


extern void
prot_a_output_personal_flags(Connection *fp,
			     Personal_flags flags)
{
597
598
599
600
601
602
603
604
605
    isc_putc(' ', fp->isc_session);
    isc_putc(flags.unread_is_secret + '0', fp->isc_session);
    isc_putc(flags.flg2 + '0', fp->isc_session);
    isc_putc(flags.flg3 + '0', fp->isc_session);
    isc_putc(flags.flg4 + '0', fp->isc_session);
    isc_putc(flags.flg5 + '0', fp->isc_session);
    isc_putc(flags.flg6 + '0', fp->isc_session);
    isc_putc(flags.flg7 + '0', fp->isc_session);
    isc_putc(flags.flg8 + '0', fp->isc_session);
Per Cederqvist's avatar
Per Cederqvist committed
606
607
608
609
610
611
}	

extern void
prot_a_output_conf_type(Connection *fp,
			Conf_type type)
{
612
613
614
615
616
    isc_putc(' ', fp->isc_session);
    isc_putc(type.rd_prot + '0', fp->isc_session);
    isc_putc(type.original + '0', fp->isc_session);
    isc_putc(type.secret + '0', fp->isc_session);
    isc_putc(type.letter_box + '0', fp->isc_session);
Per Cederqvist's avatar
Per Cederqvist committed
617
618
}

619
620
621
622
extern void
prot_a_output_extended_conf_type(Connection *fp,
				 Conf_type type)
{
623
624
625
626
627
628
629
630
631
    isc_putc(' ', fp->isc_session);
    isc_putc(type.rd_prot + '0', fp->isc_session);
    isc_putc(type.original + '0', fp->isc_session);
    isc_putc(type.secret + '0', fp->isc_session);
    isc_putc(type.letter_box + '0', fp->isc_session);
    isc_putc(type.allow_anon + '0', fp->isc_session);
    isc_putc(type.forbid_secret + '0', fp->isc_session);
    isc_putc(type.reserved2 + '0', fp->isc_session);
    isc_putc(type.reserved3 + '0', fp->isc_session);
632
}
Per Cederqvist's avatar
Per Cederqvist committed
633
634
635

extern void
prot_a_output_member_list(Connection *fp,
636
                          Member_list m_list)
Per Cederqvist's avatar
Per Cederqvist committed
637
638
639
{
    int i;

640
    prot_a_output_ul(fp, m_list.no_of_members);
Per Cederqvist's avatar
Per Cederqvist committed
641
642
    if ( m_list.members != NULL && m_list.no_of_members > 0 )
    {
643
	isc_puts(" {", fp->isc_session);
Per Cederqvist's avatar
Per Cederqvist committed
644
645
	for ( i = 0; i < m_list.no_of_members; i++ )
	    prot_a_output_member(fp, m_list.members[ i ]);
646
	isc_puts(" }", fp->isc_session);
Per Cederqvist's avatar
Per Cederqvist committed
647
648
    }
    else
649
	isc_puts(" *", fp->isc_session);
Per Cederqvist's avatar
Per Cederqvist committed
650
651
}

652
653
654
655
656
657
extern void
prot_a_output_member_list_old(Connection *fp,
                              Member_list m_list)
{
    int i;

658
    prot_a_output_ul(fp, m_list.no_of_members);
659
660
    if ( m_list.members != NULL && m_list.no_of_members > 0 )
    {
661
	isc_puts(" {", fp->isc_session);
662
663
	for ( i = 0; i < m_list.no_of_members; i++ )
	    prot_a_output_member_old(fp, m_list.members[ i ]);
664
	isc_puts(" }", fp->isc_session);
665
666
    }
    else
667
	isc_puts(" *", fp->isc_session);
668
669
}

Per Cederqvist's avatar
Per Cederqvist committed
670
671
672
673

void
prot_a_output_member(Connection *fp,
		     Member member)
674
{
675
676
    prot_a_output_ul(fp, member.member);
    prot_a_output_ul(fp, member.added_by);
677
678
679
680
681
682
683
    prot_a_output_time(fp, member.added_at);
    prot_a_output_membership_type(fp, member.type);
}

void
prot_a_output_member_old(Connection *fp,
		     Member member)
Per Cederqvist's avatar
Per Cederqvist committed
684
{
685
    prot_a_output_ul(fp, member.member);
Per Cederqvist's avatar
Per Cederqvist committed
686
687
688
689
690
691
692
}

    
extern void
prot_a_output_mark(Connection *fp,
		   Mark mark)
{
693
694
    prot_a_output_ul(fp, mark.text_no);
    prot_a_output_ul(fp, mark.mark_type);
Per Cederqvist's avatar
Per Cederqvist committed
695
696
697
698
699
700
701
}


extern void
prot_a_output_misc_info(Connection *fp, 
			Misc_info misc)
{
702
    prot_a_output_ul(fp, misc.type);
Per Cederqvist's avatar
Per Cederqvist committed
703
704
705
706
707
    
    switch(misc.type)
    {
    case recpt:
    case cc_recpt:
708
    case bcc_recpt:
709
	prot_a_output_ul(fp, misc.datum.recipient);
710
711
	break;
	
Per Cederqvist's avatar
Per Cederqvist committed
712
    case loc_no:
713
	prot_a_output_ul(fp, misc.datum.local_no);
Per Cederqvist's avatar
Per Cederqvist committed
714
715
716
717
718
719
720
721
722
723
	break;
	
    case rec_time:
	prot_a_output_time(fp, misc.datum.received_at);
	break;
	
    case comm_to:
    case comm_in:
    case footn_to:
    case footn_in:
724
	prot_a_output_ul(fp, misc.datum.text_link);
Per Cederqvist's avatar
Per Cederqvist committed
725
726
727
	break;
	
    case sent_by:
728
	prot_a_output_ul(fp, misc.datum.sender);
Per Cederqvist's avatar
Per Cederqvist committed
729
730
731
732
733
734
735
736
737
	break;
	
    case sent_at:
	prot_a_output_time(fp, misc.datum.sent_at);
	break;

#ifndef COMPILE_CHECKS
    default:
#endif
738
739
    case unknown_info:
	restart_kom("prot_a_output_misc_info: Illegal misc\n");
Per Cederqvist's avatar
Per Cederqvist committed
740
741
742
    }
}

David Byers's avatar
David Byers committed
743
744
745

void
prot_a_output_time(Connection *fp,
746
		   time_t clk)
David Byers's avatar
David Byers committed
747
748
749
750
{
    struct tm *t;

    t = localtime( &clk );
751

David Byers's avatar
David Byers committed
752
753
754
    prot_a_output_ul(fp, t->tm_sec);
    prot_a_output_ul(fp, t->tm_min);
    prot_a_output_ul(fp, t->tm_hour);
755
756
757
758
759
760
    prot_a_output_ul(fp, t->tm_mday);
    prot_a_output_ul(fp, t->tm_mon);
    prot_a_output_ul(fp, t->tm_year);
    prot_a_output_ul(fp, t->tm_wday);
    prot_a_output_ul(fp, t->tm_yday);
    prot_a_output_ul(fp, t->tm_isdst);
Per Cederqvist's avatar
Per Cederqvist committed
761
762
763
764
765
766
767
}


void
prot_a_output_session_no(Connection *fp,
			 Session_no session_no)
{
768
    prot_a_output_ul(fp, session_no);
Per Cederqvist's avatar
Per Cederqvist committed
769
}
Linus Tolke's avatar
Linus Tolke committed
770
771
772
773
774

void
prot_a_output_text_no(Connection *fp,
		      Text_no text)
{
775
    prot_a_output_ul(fp, text);
Linus Tolke's avatar
Linus Tolke committed
776
}
777
778
779
780
781
782
783

static void
prot_a_output_conf_z_info (Connection  *fp,
			   Conf_z_info *conf_c)
{
    prot_a_output_string(fp, conf_c->name);
    prot_a_output_conf_type(fp, conf_c->type);
784
    prot_a_output_ul(fp,  conf_c->conf_no);
785
786
787
788
789
790
791
792
}

extern void
prot_a_output_conf_z_info_list(Connection *fp,
			       Conf_z_info_list c_list)
{
    int i;

793
    prot_a_output_ul(fp, c_list.no_of_confs);
794
795
    if ( c_list.confs != NULL && c_list.no_of_confs > 0 )
    {
796
	isc_puts(" {", fp->isc_session);
797
798
	for ( i = 0; i < c_list.no_of_confs; i++ )
	    prot_a_output_conf_z_info(fp, &c_list.confs[ i ]);
799
	isc_puts(" }", fp->isc_session);
800
801
    }
    else
802
	isc_puts(" *", fp->isc_session);
803
804
805
806
807
808
}

void
prot_a_output_version_info (Connection  *fp,
			    Version_info *v_info)
{
809
    prot_a_output_ul(fp, v_info->protocol_version);
810
811
812
    prot_a_output_string(fp, v_info->server_name);
    prot_a_output_string(fp, v_info->server_version);
}
813
814
815
816
817
818
819

void
prot_a_output_num_list (Connection *fp,
                        Number_list *num_list)
{
    int i;
    
820
    prot_a_output_ul(fp, num_list->length);
821
    if (num_list->length == 0)
822
        isc_puts(" *", fp->isc_session);
823
824
    else
    {
825
        isc_puts(" {", fp->isc_session);
826
        for (i = 0; i < num_list->length; i++)
827
828
            prot_a_output_ul(fp, num_list->data[i]);
        isc_puts(" }", fp->isc_session);
829
830
    }
}
831

832
833
834
835
static void
prot_a_output_session_flags(Connection *fp,
			    Session_flags flags)
{
836
837
838
839
840
841
842
843
844
    isc_putc(' ', fp->isc_session);
    isc_putc(flags.invisible + '0', fp->isc_session);
    isc_putc(flags.user_active_used + '0', fp->isc_session);
    isc_putc(flags.user_absent + '0', fp->isc_session);
    isc_putc(flags.reserved3 + '0', fp->isc_session);
    isc_putc(flags.reserved4 + '0', fp->isc_session);
    isc_putc(flags.reserved5 + '0', fp->isc_session);
    isc_putc(flags.reserved6 + '0', fp->isc_session);
    isc_putc(flags.reserved7 + '0', fp->isc_session);
845
}	
846
847
848
849
static void
prot_a_output_dynamic_session_info (Connection *fp,
				    Dynamic_session_info *info)
{
850
851
852
853
    prot_a_output_ul(fp, info->session);
    prot_a_output_ul(fp, info->person);
    prot_a_output_ul(fp, info->working_conference);
    prot_a_output_ul(fp, info->idle_time);
854
    prot_a_output_session_flags(fp, info->flags);
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
    prot_a_output_string(fp, info->what_am_i_doing);
}

void
prot_a_output_static_session_info (Connection *fp,
				   Static_session_info *info)
{
    prot_a_output_string(fp, info->username);
    prot_a_output_string(fp, info->hostname);
    prot_a_output_string(fp, info->ident_user);
    prot_a_output_time(fp, info->connection_time);
}

void
prot_a_output_dynamic_session_info_list (Connection *fp,
					 Dynamic_session_info_list *list)
{
    long i;

874
    prot_a_output_ul(fp, list->no_of_sessions);
875
    if (list->no_of_sessions == 0)
876
	isc_puts(" *", fp->isc_session);
877
878
    else
    {
879
	isc_puts(" {", fp->isc_session);
880
881
	for (i = 0; i < list->no_of_sessions; i++)
	    prot_a_output_dynamic_session_info(fp, &list->sessions[i]);
882
	isc_puts(" }", fp->isc_session);
883
884
885
    }
}

886
887
void
prot_a_output_l2g_iterator_as_text_list(Connection *fp,
888
					L2g_iterator *iter)
889
890
891
892
{
    Local_text_no lno = l2gi_begin(iter);
    Local_text_no limit = l2gi_end(iter);

893
894
    prot_a_output_ul(fp, lno);
    prot_a_output_ul(fp, limit - lno);
895
896
897

    if (limit - lno > 0)
    {
898
	isc_puts(" {", fp->isc_session);
899
900
901
902
	for (; !iter->search_ended; l2gi_next(iter))
	{
	    /* Write the correct number of zeroes. */
	    for (; lno < iter->lno; ++lno)
903
		isc_puts(" 0", fp->isc_session);
904
	    /* Write this piece of data. */
905
	    prot_a_output_ul(fp, iter->tno);
906
907
	    ++lno;
	}
908
909
	/* Write any trailing zeroes */
	for (; lno < limit; ++lno)
910
911
	    isc_puts(" 0", fp->isc_session);
	isc_puts(" }", fp->isc_session);
912
913
    }
    else
914
	isc_puts(" *", fp->isc_session);
915
}
916
917
918
919
920
921
922

void
prot_a_output_text_mapping(Connection *fp,
			   Text_mapping *map)
{
    Local_text_no lowest;
    Local_text_no highest;
923
    Local_text_no limit;
924
925
926
927
    Local_text_no zeroes = 0;
    Local_text_no nonzeroes = 0;
    L2g_iterator iter;

David Byers's avatar
David Byers committed
928
929
930
931
932
933
934
935
936
937
938
939
    /* Initialize iter to something. Otherwise some tools will flag
       a read uninitialized memory in the for initializer. */

    iter.l2g = NULL;
    iter.binfo = NULL;
    iter.arrindex = 0;
    iter.beginval = 0;
    iter.endval = 0;
    iter.search_ended = 0;
    iter.lno = 0;
    iter.tno = 0;
    
940
941
942
943
    /* Count the number of internal zeroes to determine if we should
       use a dense or sparse representation. */

    for (l2gi_searchsome(&iter, map->l2g, map->first, 0),
944
	     highest = (lowest = iter.search_ended?map->first:iter.lno) - 1;
945
946
947
948
949
950
951
952
	 !iter.search_ended && nonzeroes < map->no_of_texts;
	 l2gi_next(&iter))
    {
	zeroes += (iter.lno - highest) - 1;
	nonzeroes++;
	highest = iter.lno;
    }

953
954
    limit = highest + 1;

955
    prot_a_output_ul(fp, map->first);
956
    if (iter.search_ended)
957
	prot_a_output_ul(fp, l2g_first_appendable_key(map->l2g));
958
    else
959
	prot_a_output_ul(fp, limit);
960

961
962
    /* Emit the "later-texts-exists" flag. */

963
    isc_puts(iter.search_ended ? " 0" : " 1", fp->isc_session);
964
965
966
967
968
969


    /* Emit the block, either a sparse or a dense one. */

    if (nonzeroes == 0)
    {
970
	/* Special case: an empty array.  Use the sparse format so
971
972
	   that we don't have to philosophize about what the lower
	   limit in the text-list should be. */
973
	isc_puts(" 0 0 *", fp->isc_session);
974
975
976
977
978
979
    }
    else if (zeroes >= nonzeroes)
    {
	/* There are at least as many zeroes as real mappings, so use
	   a sparse representation. */

980
981
982
	isc_puts(" 0", fp->isc_session);
	prot_a_output_ul(fp, nonzeroes);
	isc_puts(" {", fp->isc_session);
983

984
	for (l2gi_searchsome(&iter, map->l2g, map->first, limit);
985
986
987
	     !iter.search_ended;
	     l2gi_next(&iter))
	{
988
989
	    prot_a_output_ul(fp, iter.lno);
	    prot_a_output_ul(fp, iter.tno);
990
	}
991
	isc_puts(" }", fp->isc_session);
992
993
994
995
    }
    else
    {
	/* Emit a dense block. */
996
997
998
999
	isc_puts(" 1", fp->isc_session);
	prot_a_output_ul(fp, lowest);
	prot_a_output_ul(fp, zeroes + nonzeroes);
	isc_puts(" {", fp->isc_session);
1000
	highest = lowest;
1001
	for (l2gi_searchsome(&iter, map->l2g, map->first, limit);
1002
1003
1004
1005
	     !iter.search_ended;
	     l2gi_next(&iter))
	{
	    while (highest++ < iter.lno)
1006
1007
		isc_puts(" 0", fp->isc_session);
	    prot_a_output_ul(fp, iter.tno);
1008
	}
1009
	isc_puts(" }", fp->isc_session);
1010
1011
    }
}
1012
1013
1014
1015
1016
1017
1018


#ifdef DEBUG_CALLS
void
prot_a_output_memory_info(Connection *fp,
                          Memory_info *result)
{
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
    prot_a_output_ul(fp, result->arena);
    prot_a_output_ul(fp, result->ordblks);
    prot_a_output_ul(fp, result->smblks);
    prot_a_output_ul(fp, result->hblks);
    prot_a_output_ul(fp, result->hblkhd);
    prot_a_output_ul(fp, result->usmblks);
    prot_a_output_ul(fp, result->fsmblks);
    prot_a_output_ul(fp, result->uordblks);
    prot_a_output_ul(fp, result->fordblks);
    prot_a_output_ul(fp, result->keepcost);
1029
1030
}
#endif