prot-a-output.c 29.6 KB
Newer Older
Linus Tolke's avatar
Linus Tolke committed
1
/*
2
 * $Id: prot-a-output.c,v 0.46 1999/05/20 06:52:44 ceder Exp $
Per Cederqvist's avatar
Per Cederqvist committed
3
 * Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996  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

37
static const char *
38
rcsid = "$Id: prot-a-output.c,v 0.46 1999/05/20 06:52:44 ceder Exp $";
39
40
#include "rcs.h"
USE(rcsid);
Per Cederqvist's avatar
Per Cederqvist committed
41

Per Cederqvist's avatar
Per Cederqvist committed
42
#include <time.h>
Per Cederqvist's avatar
Per Cederqvist committed
43
#include <setjmp.h>
44
45
46
47
48
#include <sys/types.h>
#include <sys/socket.h>
#ifdef HAVE_STDARG_H
#  include <stdarg.h>
#endif
49
#include <assert.h>
Per Cederqvist's avatar
Per Cederqvist committed
50

51
#include "s-string.h"
Per Cederqvist's avatar
Per Cederqvist committed
52
53
#include "kom-types.h"
#include "isc-interface.h"
Per Cederqvist's avatar
Per Cederqvist committed
54
#include "com.h"
55
#include "async.h"
Per Cederqvist's avatar
Per Cederqvist committed
56
#include "connections.h"
Per Cederqvist's avatar
Per Cederqvist committed
57
58
#include "prot-a-output.h"
#include "lyskomd.h"
59
#include "param.h"
60
#include "local-to-global.h"
Per Cederqvist's avatar
Per Cederqvist committed
61

62
63
64
65
66
67
68
69
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
70
71
void
prot_a_output_person (Connection *fp,
72
                      Person *person)
Per Cederqvist's avatar
Per Cederqvist committed
73
{
74
    Local_text_no first_created = l2g_next_key(&person->created_texts, 0);
75
    Local_text_no uncreated = l2g_first_appendable_key(&person->created_texts);
76
77
    Local_text_no num_created;

78
79
80
81
    if (first_created == 0)
	first_created = uncreated;

    num_created = uncreated - first_created;
82

Per Cederqvist's avatar
Per Cederqvist committed
83
84
85
86
87
88
    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);

89
90
91
92
93
94
95
96
97
98
99
100
101
    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
102
103
}

104
105
106
void prot_a_output_membership_type(Connection *fp,
                                   const Membership_type type)
{
107
108
109
110
111
112
113
114
115
    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);
116
117
118
119
120
}

void prot_a_output_membership(Connection *fp,
                              const Membership *mship)
{
121
    prot_a_output_ul(fp, mship->position);
122
    prot_a_output_membership_old(fp, mship);
123
    prot_a_output_ul(fp, mship->added_by);
124
125
126
127
    prot_a_output_time(fp, mship->added_at);
    prot_a_output_membership_type(fp, mship->type);
}

Per Cederqvist's avatar
Per Cederqvist committed
128
void
129
130
prot_a_output_membership_old(Connection *fp,
			     const Membership *mship)
Per Cederqvist's avatar
Per Cederqvist committed
131
132
133
134
135
{
    int i;
    
    prot_a_output_time(fp, mship->last_time_read );
    
136
137
138
139
    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
140
141
142
    
    if ( mship->read_texts != NULL && mship->no_of_read > 0)
    {
143
	isc_puts(" {", fp->isc_session);
Per Cederqvist's avatar
Per Cederqvist committed
144
	for ( i = 0; i < mship->no_of_read; i++)
145
	    prot_a_output_ul(fp, mship->read_texts[i]);
Per Cederqvist's avatar
Per Cederqvist committed
146
	
147
	isc_puts(" }", fp->isc_session);
Per Cederqvist's avatar
Per Cederqvist committed
148
149
    }
    else
150
	isc_puts(" *", fp->isc_session);
Per Cederqvist's avatar
Per Cederqvist committed
151
152
153
}

	
154
155
156
157
158
159
void
prot_a_output_membership_list_old (Connection	* fp,
                                   Membership_list	  mlist)
{
    int i;
    
160
    prot_a_output_ul(fp, mlist.no_of_confs);
161
162
163

    if ( mlist.confs != NULL && mlist.no_of_confs > 0 )
    {
164
	isc_puts(" {", fp->isc_session);
165
166
	for ( i = 0; i < mlist.no_of_confs; i++)
	    prot_a_output_membership_old(fp, mlist.confs + i);
167
	isc_puts(" }", fp->isc_session);
168
169
    }
    else
170
	isc_puts(" *", fp->isc_session);
171
172
}

Per Cederqvist's avatar
Per Cederqvist committed
173
174
void
prot_a_output_membership_list (Connection	* fp,
175
                               Membership_list	  mlist)
Per Cederqvist's avatar
Per Cederqvist committed
176
177
178
{
    int i;
    
179
    prot_a_output_ul(fp, mlist.no_of_confs);
Per Cederqvist's avatar
Per Cederqvist committed
180
181
182

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

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

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

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

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

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

void
prot_a_output_conference (Connection *fp,
241
242
                          Conference *conf_c)
{
243
    Local_text_no first_local_no = l2g_next_key(&conf_c->texts, 0);
244
    Local_text_no uncreated = l2g_first_appendable_key(&conf_c->texts);
245
246
    Local_text_no no_of_texts;

247
248
249
250
    if (first_local_no == 0)
	first_local_no = uncreated;

    no_of_texts = uncreated - first_local_no;
251

252
253
    prot_a_output_string(fp, conf_c->name);
    prot_a_output_extended_conf_type(fp, conf_c->type);
254
255
256
257
258
259
260
261
262
263
264
265
266
267
    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);
268
269
270
271
272
273
    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
274
{
275
    Local_text_no first_local_no = l2g_next_key(&conf_c->texts, 0);
276
    Local_text_no uncreated = l2g_first_appendable_key(&conf_c->texts);
277
278
    Local_text_no no_of_texts;

279
280
281
282
    if (first_local_no == 0)
	first_local_no = uncreated;

    no_of_texts = uncreated - first_local_no;
283

Per Cederqvist's avatar
Per Cederqvist committed
284
285
286
287
288
289
290
    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 );

291
292
293
294
295
296
297
298
299
300
    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
301
302
}

303
304
305
306
307
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);
308
309
    prot_a_output_ul(fp, conf_c->highest_local_no);
    prot_a_output_ul(fp, conf_c->nice);
310
311
}

Per Cederqvist's avatar
Per Cederqvist committed
312
313
314
315
316
317
318

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

319
    prot_a_output_ul(fp, mark_list.no_of_marks);
Per Cederqvist's avatar
Per Cederqvist committed
320
321
322

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

333
334
335
336
void
prot_a_output_aux_item_flags(Connection *fp,
                             Aux_item_flags flags)
{
337
338
339
340
341
342
343
344
345
    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);
346
}
Per Cederqvist's avatar
Per Cederqvist committed
347
348

void
349
350
351
prot_a_output_aux_item(Connection *fp,
                       Aux_item *item)
{
352
353
354
    prot_a_output_ul(fp, item->aux_no);
    prot_a_output_ul(fp, item->tag);
    prot_a_output_ul(fp, item->creator);
355
356
    prot_a_output_time(fp, item->sent_at);
    prot_a_output_aux_item_flags(fp, item->flags);
357
    prot_a_output_ul(fp, item->inherit_limit);
358
359
360
361
362
363
    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
364
365
366
367
368
{
    int i;

    prot_a_output_time(fp, t_stat->creation_time);
    
369
370
371
372
373
    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
374
375
376

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

386
387
388
389
390
391
void
prot_a_output_aux_item_list(Connection *fp,
			    Aux_item_list *aux)
{
  int i;

392
    prot_a_output_ul(fp, aux->length);
393
394
395

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

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
413

414
415
416
static void
prot_a_output_who_info_ident(Connection *fp,
			     Who_info_ident *info)
Per Cederqvist's avatar
Per Cederqvist committed
417
{
418
419
420
    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
421
422
423

    prot_a_output_string(fp, info->what_am_i_doing);
    prot_a_output_string(fp, info->username);
424
425
426
427
428
    prot_a_output_string(fp, info->hostname);
    prot_a_output_string(fp, info->ident_user);
}


429
void
430
431
432
prot_a_output_who_info(Connection *fp,
		       Who_info *info)
{
433
434
435
    prot_a_output_ul(fp, info->person);
    prot_a_output_ul(fp, info->working_conference);
    prot_a_output_ul(fp, info->session_no);
436
437

    prot_a_output_string(fp, info->what_am_i_doing); 
438
    prot_a_output_string(fp, info->username);
Per Cederqvist's avatar
Per Cederqvist committed
439
440
441
442
443
444
445
446
447
}


void
prot_a_output_who_info_list(Connection *fp,
			    Who_info_list info)
{
    int i;
    
448
    prot_a_output_ul(fp, info.no_of_persons);
Per Cederqvist's avatar
Per Cederqvist committed
449
450
451

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

void
prot_a_output_who_info_ident_list(Connection *fp,
				  Who_info_ident_list info)
{
    int i;
    
472
    prot_a_output_ul(fp, info.no_of_persons);
473
474
475

    if ( info.info != NULL && info.no_of_persons > 0 )
    {
476
	isc_puts(" {", fp->isc_session);
477
478
479
	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
480
	}
481
	isc_puts(" }", fp->isc_session);
Per Cederqvist's avatar
Per Cederqvist committed
482
483
    }
    else
484
	isc_puts(" *", fp->isc_session);
Per Cederqvist's avatar
Per Cederqvist committed
485
486
487
488
489
490
491
492
}

void
prot_a_output_who_info_list_old(Connection *fp,
				Who_info_list_old info)
{
    int i;
    
493
    prot_a_output_ul(fp, info.no_of_persons);
Per Cederqvist's avatar
Per Cederqvist committed
494
495
496

    if ( info.info != NULL && info.no_of_persons > 0 )
    {
497
	isc_puts(" {", fp->isc_session);
Per Cederqvist's avatar
Per Cederqvist committed
498
499
	for ( i = 0; i < info.no_of_persons; i++ )
	{
500
501
	    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
502
503
504
	    
	    prot_a_output_string(fp, info.info[ i ].what_am_i_doing);
	}
505
	isc_puts(" }", fp->isc_session);
Per Cederqvist's avatar
Per Cederqvist committed
506
507
    }
    else
508
	isc_puts(" *", fp->isc_session);
Per Cederqvist's avatar
Per Cederqvist committed
509
510
511
512
513
514
}

void
prot_a_output_session_info(Connection *fp,
			   Session_info *info)
{
515
516
517
    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
518
519
520
521

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

522
    prot_a_output_ul(fp, info->idle_time);
Per Cederqvist's avatar
Per Cederqvist committed
523
524
    prot_a_output_time(fp, info->connection_time);
}
525
526
527

void
prot_a_output_session_info_ident(Connection *fp,
528
				 Session_info_ident *info)
529
{
530
531
532
    prot_a_output_ul(fp, info->person);
    prot_a_output_ul(fp, info->working_conference);
    prot_a_output_ul(fp, info->session);
533
534
535
536
537
538

    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);

539
    prot_a_output_ul(fp, info->idle_time);
540
541
    prot_a_output_time(fp, info->connection_time);
}
Per Cederqvist's avatar
Per Cederqvist committed
542
543
544
    
void
prot_a_output_info(Connection *fp,
545
546
547
548
549
550
551
552
553
                   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
554
{
555
556
557
558
559
560
    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
561
562
563
564
565
566
567
}


extern void
prot_a_output_string(Connection *fp,
		     String str)
{
568
569
570
    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
571
572
573
574
575
576
577
}


extern void
prot_a_output_priv_bits(Connection *fp,
			Priv_bits bits)
{
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
    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);
    isc_putc(bits.extern_gw + '0', fp->isc_session);
    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
595
596
597
598
599
600
601
}


extern void
prot_a_output_personal_flags(Connection *fp,
			     Personal_flags flags)
{
602
603
604
605
606
607
608
609
610
    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
611
612
613
614
615
616
}	

extern void
prot_a_output_conf_type(Connection *fp,
			Conf_type type)
{
617
618
619
620
621
    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
622
623
}

624
625
626
627
extern void
prot_a_output_extended_conf_type(Connection *fp,
				 Conf_type type)
{
628
629
630
631
632
633
634
635
636
    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);
637
}
Per Cederqvist's avatar
Per Cederqvist committed
638
639
640

extern void
prot_a_output_member_list(Connection *fp,
641
                          Member_list m_list)
Per Cederqvist's avatar
Per Cederqvist committed
642
643
644
{
    int i;

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

657
658
659
660
661
662
extern void
prot_a_output_member_list_old(Connection *fp,
                              Member_list m_list)
{
    int i;

663
    prot_a_output_ul(fp, m_list.no_of_members);
664
665
    if ( m_list.members != NULL && m_list.no_of_members > 0 )
    {
666
	isc_puts(" {", fp->isc_session);
667
668
	for ( i = 0; i < m_list.no_of_members; i++ )
	    prot_a_output_member_old(fp, m_list.members[ i ]);
669
	isc_puts(" }", fp->isc_session);
670
671
    }
    else
672
	isc_puts(" *", fp->isc_session);
673
674
}

Per Cederqvist's avatar
Per Cederqvist committed
675
676
677
678

void
prot_a_output_member(Connection *fp,
		     Member member)
679
{
680
681
    prot_a_output_ul(fp, member.member);
    prot_a_output_ul(fp, member.added_by);
682
683
684
685
686
687
688
    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
689
{
690
    prot_a_output_ul(fp, member.member);
Per Cederqvist's avatar
Per Cederqvist committed
691
692
693
694
695
696
697
}

    
extern void
prot_a_output_mark(Connection *fp,
		   Mark mark)
{
698
699
    prot_a_output_ul(fp, mark.text_no);
    prot_a_output_ul(fp, mark.mark_type);
Per Cederqvist's avatar
Per Cederqvist committed
700
701
702
703
704
705
706
}


extern void
prot_a_output_misc_info(Connection *fp, 
			Misc_info misc)
{
707
    prot_a_output_ul(fp, misc.type);
Per Cederqvist's avatar
Per Cederqvist committed
708
709
710
711
    
    switch(misc.type)
    {
    case recpt:
712
	prot_a_output_ul(fp, misc.datum.recipient);
Per Cederqvist's avatar
Per Cederqvist committed
713
714
715
	break;
	
    case cc_recpt:
716
	prot_a_output_ul(fp, misc.datum.cc_recipient);
Per Cederqvist's avatar
Per Cederqvist committed
717
718
	break;
	
719
    case bcc_recpt:
720
	prot_a_output_ul(fp, misc.datum.bcc_recipient);
721
722
	break;
	
Per Cederqvist's avatar
Per Cederqvist committed
723
    case loc_no:
724
	prot_a_output_ul(fp, misc.datum.local_no);
Per Cederqvist's avatar
Per Cederqvist committed
725
726
727
728
729
730
731
	break;
	
    case rec_time:
	prot_a_output_time(fp, misc.datum.received_at);
	break;
	
    case comm_to:
732
	prot_a_output_ul(fp, misc.datum.comment_to);
Per Cederqvist's avatar
Per Cederqvist committed
733
734
735
	break;
	
    case comm_in:
736
	prot_a_output_ul(fp, misc.datum.commented_in);
Per Cederqvist's avatar
Per Cederqvist committed
737
738
739
	break;
	
    case footn_to:
740
	prot_a_output_ul(fp, misc.datum.footnote_to);
Per Cederqvist's avatar
Per Cederqvist committed
741
742
743
	break;
	
    case footn_in:
744
	prot_a_output_ul(fp, misc.datum.footnoted_in);
Per Cederqvist's avatar
Per Cederqvist committed
745
746
747
	break;
	
    case sent_by:
748
	prot_a_output_ul(fp, misc.datum.sender);
Per Cederqvist's avatar
Per Cederqvist committed
749
750
751
752
753
754
755
756
757
	break;
	
    case sent_at:
	prot_a_output_time(fp, misc.datum.sent_at);
	break;

#ifndef COMPILE_CHECKS
    default:
#endif
758
759
    case unknown_info:
	restart_kom("prot_a_output_misc_info: Illegal misc\n");
Per Cederqvist's avatar
Per Cederqvist committed
760
761
762
    }
}

David Byers's avatar
David Byers committed
763
/*
Per Cederqvist's avatar
Per Cederqvist committed
764
765
void
prot_a_output_time(Connection *fp,
766
		   time_t clk)
Per Cederqvist's avatar
Per Cederqvist committed
767
{
768
    struct tm *t;
Per Cederqvist's avatar
Per Cederqvist committed
769

770
    t = localtime( &clk );
Per Cederqvist's avatar
Per Cederqvist committed
771

772
773
774
    prot_a_output_ul(fp, t->tm_sec);
    prot_a_output_ul(fp, t->tm_min);
    prot_a_output_ul(fp, t->tm_hour);
David Byers's avatar
David Byers committed
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
    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);
}
*/

void
prot_a_output_time(Connection *fp,
                       time_t clk)
{
    struct tm *t;

    t = localtime( &clk );
791
792

    /* Please don't tell anyone that you saw this code.  It is fun,
David Byers's avatar
David Byers committed
793
794
795
796
797
798
       mostly harmless, and it only affects as many days as the
       server admin wants (default is two.)

       Don't spoil the fun */

    if (t->tm_year == 100 && t->tm_yday < param.y2k_compat)
799
    {
David Byers's avatar
David Byers committed
800
801
802
803
        t->tm_year -= 1;              /* Back to 1999 */
        t->tm_mday = t->tm_yday + 31; /* December 31+yday */
        t->tm_yday += 365;            /* yday includes all of 1999 */
        t->tm_mon = 11;               /* Always december */
804
805
    }

David Byers's avatar
David Byers committed
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
    prot_a_output_ul(fp, t->tm_sec);
    prot_a_output_ul(fp, t->tm_min);
    prot_a_output_ul(fp, t->tm_hour);
/* =======                                                                */ 
/*     / * Please don't tell anyone that you saw this code.  It is fun,   */ 
/*        mostly harmless, and it only affects a single day.  Don't spoil */ 
/*        the fun in advance!  * /                                        */ 
/*                                                                        */ 
/*     if (t->tm_year == 100 && t->tm_mday == 1 && t->tm_mon == 0         */ 
/*         && t->tm_wday == 6 && t->tm_yday == 1)                         */ 
/*     {                                                                  */ 
/*         isc_puts(" 32 11 99 6 366", fp->isc_session);                  */ 
/*         prot_a_output_ul(fp, t->tm_isdst);                             */ 
/*         return;                                                        */ 
/*     }                                                                  */ 
/*                                                                        */ 
/* >>>>>>> 0.44                                                           */ 
823
824
825
826
827
828
    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
829
830
831
832
833
834
835
}


void
prot_a_output_session_no(Connection *fp,
			 Session_no session_no)
{
836
    prot_a_output_ul(fp, session_no);
Per Cederqvist's avatar
Per Cederqvist committed
837
}
Linus Tolke's avatar
Linus Tolke committed
838
839
840
841
842

void
prot_a_output_text_no(Connection *fp,
		      Text_no text)
{
843
    prot_a_output_ul(fp, text);
Linus Tolke's avatar
Linus Tolke committed
844
}
845
846
847
848
849
850
851

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);
852
    prot_a_output_ul(fp,  conf_c->conf_no);
853
854
855
856
857
858
859
860
}

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

861
    prot_a_output_ul(fp, c_list.no_of_confs);
862
863
    if ( c_list.confs != NULL && c_list.no_of_confs > 0 )
    {
864
	isc_puts(" {", fp->isc_session);
865
866
	for ( i = 0; i < c_list.no_of_confs; i++ )
	    prot_a_output_conf_z_info(fp, &c_list.confs[ i ]);
867
	isc_puts(" }", fp->isc_session);
868
869
    }
    else
870
	isc_puts(" *", fp->isc_session);
871
872
873
874
875
876
}

void
prot_a_output_version_info (Connection  *fp,
			    Version_info *v_info)
{
877
    prot_a_output_ul(fp, v_info->protocol_version);
878
879
880
    prot_a_output_string(fp, v_info->server_name);
    prot_a_output_string(fp, v_info->server_version);
}
881
882
883
884
885
886
887

void
prot_a_output_num_list (Connection *fp,
                        Number_list *num_list)
{
    int i;
    
888
    prot_a_output_ul(fp, num_list->length);
889
    if (num_list->length == 0)
890
        isc_puts(" *", fp->isc_session);
891
892
    else
    {
893
        isc_puts(" {", fp->isc_session);
894
        for (i = 0; i < num_list->length; i++)
895
896
            prot_a_output_ul(fp, num_list->data[i]);
        isc_puts(" }", fp->isc_session);
897
898
    }
}
899

900
901
902
903
static void
prot_a_output_session_flags(Connection *fp,
			    Session_flags flags)
{
904
905
906
907
908
909
910
911
912
    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);
913
}	
914
915
916
917
static void
prot_a_output_dynamic_session_info (Connection *fp,
				    Dynamic_session_info *info)
{
918
919
920
921
    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);
922
    prot_a_output_session_flags(fp, info->flags);
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
    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;

942
    prot_a_output_ul(fp, list->no_of_sessions);
943
    if (list->no_of_sessions == 0)
944
	isc_puts(" *", fp->isc_session);
945
946
    else
    {
947
	isc_puts(" {", fp->isc_session);
948
949
	for (i = 0; i < list->no_of_sessions; i++)
	    prot_a_output_dynamic_session_info(fp, &list->sessions[i]);
950
	isc_puts(" }", fp->isc_session);
951
952
953
    }
}

954
955
void
prot_a_output_l2g_iterator_as_text_list(Connection *fp,
956
					L2g_iterator *iter)
957
958
959
960
{
    Local_text_no lno = l2gi_begin(iter);
    Local_text_no limit = l2gi_end(iter);

961
962
    prot_a_output_ul(fp, lno);
    prot_a_output_ul(fp, limit - lno);
963
964
965

    if (limit - lno > 0)
    {
966
	isc_puts(" {", fp->isc_session);
967
968
969
970
	for (; !iter->search_ended; l2gi_next(iter))
	{
	    /* Write the correct number of zeroes. */
	    for (; lno < iter->lno; ++lno)
971
		isc_puts(" 0", fp->isc_session);
972
	    /* Write this piece of data. */
973
	    prot_a_output_ul(fp, iter->tno);
974
975
	    ++lno;
	}
976
977
	/* Write any trailing zeroes */
	for (; lno < limit; ++lno)
978
979
	    isc_puts(" 0", fp->isc_session);
	isc_puts(" }", fp->isc_session);
980
981
    }
    else
982
	isc_puts(" *", fp->isc_session);
983
}
984
985
986
987
988
989
990

void
prot_a_output_text_mapping(Connection *fp,
			   Text_mapping *map)
{
    Local_text_no lowest;
    Local_text_no highest;
991
    Local_text_no limit;
992
993
994
995
    Local_text_no zeroes = 0;
    Local_text_no nonzeroes = 0;
    L2g_iterator iter;

David Byers's avatar
David Byers committed
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
    /* 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;
    
1008
1009
1010
1011
    /* 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),
1012
	     highest = (lowest = iter.search_ended?map->first:iter.lno) - 1;
1013
1014
1015
1016
1017
1018
1019
1020
	 !iter.search_ended && nonzeroes < map->no_of_texts;
	 l2gi_next(&iter))
    {
	zeroes += (iter.lno - highest) - 1;
	nonzeroes++;
	highest = iter.lno;
    }

1021
1022
    limit = highest + 1;

1023
    prot_a_output_ul(fp, map->first);
1024
    if (iter.search_ended)
1025
	prot_a_output_ul(fp, l2g_first_appendable_key(map->l2g));
1026
    else
1027
	prot_a_output_ul(fp, limit);
1028

1029
1030
    /* Emit the "later-texts-exists" flag. */

1031
    isc_puts(iter.search_ended ? " 0" : " 1", fp->isc_session);
1032
1033
1034
1035
1036
1037


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

    if (nonzeroes == 0)
    {
1038
	/* Special case: an empty array.  Use the sparse format so
1039
1040
	   that we don't have to philosophize about what the lower
	   limit in the text-list should be. */
1041
	isc_puts(" 0 0 *", fp->isc_session);
1042
1043
1044
1045
1046
1047
    }
    else if (zeroes >= nonzeroes)
    {
	/* There are at least as many zeroes as real mappings, so use
	   a sparse representation. */

1048
1049
1050
	isc_puts(" 0", fp->isc_session);
	prot_a_output_ul(fp, nonzeroes);
	isc_puts(" {", fp->isc_session);
1051

1052
	for (l2gi_searchsome(&iter, map->l2g, map->first, limit);
1053
1054
1055
	     !iter.search_ended;
	     l2gi_next(&iter))
	{
1056
1057
	    prot_a_output_ul(fp, iter.lno);
	    prot_a_output_ul(fp, iter.tno);
1058
	}
1059
	isc_puts(" }", fp->isc_session);
1060
1061
1062
1063
    }
    else
    {
	/* Emit a dense block. */
1064
1065
1066
1067
	isc_puts(" 1", fp->isc_session);
	prot_a_output_ul(fp, lowest);
	prot_a_output_ul(fp, zeroes + nonzeroes);
	isc_puts(" {", fp->isc_session);
1068
	highest = lowest;
1069
	for (l2gi_searchsome(&iter, map->l2g, map->first, limit);
1070
1071
1072
1073
	     !iter.search_ended;
	     l2gi_next(&iter))
	{
	    while (highest++ < iter.lno)
1074
1075
		isc_puts(" 0", fp->isc_session);
	    prot_a_output_ul(fp, iter.tno);
1076
	}
1077
	isc_puts(" }", fp->isc_session);
1078
1079
    }
}
1080
1081
1082
1083
1084
1085
1086


#ifdef DEBUG_CALLS
void
prot_a_output_memory_info(Connection *fp,
                          Memory_info *result)
{
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
    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);
1097
1098
}
#endif