prot-a-output.c 27 KB
Newer Older
Linus Tolke's avatar
Linus Tolke committed
1
/*
2
 * $Id: prot-a-output.c,v 0.41 1999/04/05 00:43:32 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
27
28
29
30
/*
 * prot-a-output.c  -  write objects through a mux connection.
 *
 * 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.41 1999/04/05 00:43:32 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
57
#include "connections.h"
#include "mux.h"
Per Cederqvist's avatar
Per Cederqvist committed
58
59
#include "prot-a-output.h"
#include "lyskomd.h"
60
#include "param.h"
61
#include "local-to-global.h"
Per Cederqvist's avatar
Per Cederqvist committed
62
63
64

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

71
72
73
74
    if (first_created == 0)
	first_created = uncreated;

    num_created = uncreated - first_created;
75

Per Cederqvist's avatar
Per Cederqvist committed
76
77
78
79
80
81
82
    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);

    mux_printf (fp, " %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu",
83
84
	     (unsigned long) person -> user_area,
	     (unsigned long) person -> total_time_present, /* This is not a time,
Per Cederqvist's avatar
Per Cederqvist committed
85
86
						     * but a number of seconds.
						     */
87
88
89
90
91
92
93
	     (unsigned long) person -> sessions,
	     (unsigned long) person -> created_lines,
	     (unsigned long) person -> created_bytes,
	     (unsigned long) person -> read_texts,
	     (unsigned long) person -> no_of_text_fetches,
	     (unsigned long) person -> created_persons,
	     (unsigned long) person -> created_confs,
94
95
	     (unsigned long) first_created,
	     (unsigned long) num_created,
96
97
	     (unsigned long) person -> marks.no_of_marks,
	     (unsigned long) person -> conferences.no_of_confs);
Per Cederqvist's avatar
Per Cederqvist committed
98
99
}

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

void prot_a_output_membership(Connection *fp,
                              const Membership *mship)
{
117
    mux_printf(fp, " %lu", mship->position);
118
119
120
121
122
123
    prot_a_output_membership_old(fp, mship);
    mux_printf(fp, " %lu", (unsigned long)mship->added_by);
    prot_a_output_time(fp, mship->added_at);
    prot_a_output_membership_type(fp, mship->type);
}

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

	
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
void
prot_a_output_membership_list_old (Connection	* fp,
                                   Membership_list	  mlist)
{
    int i;
    
    mux_printf(fp, " %lu", (unsigned long)mlist.no_of_confs);

    if ( mlist.confs != NULL && mlist.no_of_confs > 0 )
    {
	mux_printf(fp, " {");
	for ( i = 0; i < mlist.no_of_confs; i++)
	    prot_a_output_membership_old(fp, mlist.confs + i);
	mux_printf(fp, " }");
    }
    else
	mux_printf(fp, " *");
}

Per Cederqvist's avatar
Per Cederqvist committed
170
171
void
prot_a_output_membership_list (Connection	* fp,
172
                               Membership_list	  mlist)
Per Cederqvist's avatar
Per Cederqvist committed
173
174
175
{
    int i;
    
176
    mux_printf(fp, " %lu", (unsigned long)mlist.no_of_confs);
Per Cederqvist's avatar
Per Cederqvist committed
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192

    if ( mlist.confs != NULL && mlist.no_of_confs > 0 )
    {
	mux_printf(fp, " {");
	for ( i = 0; i < mlist.no_of_confs; i++)
	    prot_a_output_membership(fp, mlist.confs + i);
	mux_printf(fp, " }");
    }
    else
	mux_printf(fp, " *");
}

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

195
    mux_printf(fp, " %lu", (unsigned long)conf_list.no_of_conf_nos);
Per Cederqvist's avatar
Per Cederqvist committed
196
197
198
199
    if ( conf_list.conf_nos != NULL && conf_list.no_of_conf_nos > 0 )
    {
	mux_printf(fp, " {");
	for ( i = 0; i < conf_list.no_of_conf_nos; i++ )
200
	    mux_printf(fp, " %lu", (unsigned long)conf_list.conf_nos[ i ]);
Per Cederqvist's avatar
Per Cederqvist committed
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
	mux_printf(fp, " }");
    }
    else
	mux_printf(fp, " *");

    if ( conf_list.type_of_conf != NULL && conf_list.no_of_conf_nos > 0 )
    {
	mux_printf(fp, " {");
	for ( i = 0; i < conf_list.no_of_conf_nos; i++ )
	    prot_a_output_conf_type(fp, conf_list.type_of_conf[ i ]);
	mux_printf(fp, " }");
    }
    else
	mux_printf(fp, " *");
}

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

223
    mux_printf(fp, " %lu", (unsigned long)conf_no_list.no_of_confs);
Per Cederqvist's avatar
Per Cederqvist committed
224
225
226
227
    if ( conf_no_list.conf_nos != NULL && conf_no_list.no_of_confs > 0 )
    {
	mux_printf(fp, " {");
	for ( i = 0; i < conf_no_list.no_of_confs; i++ )
228
	    mux_printf(fp, " %lu", (unsigned long)conf_no_list.conf_nos[ i ]);
Per Cederqvist's avatar
Per Cederqvist committed
229
230
231
232
233
234
235
236
237
	mux_printf(fp, " }");
    }
    else
	mux_printf(fp, " *");
}
    

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

244
245
246
247
    if (first_local_no == 0)
	first_local_no = uncreated;

    no_of_texts = uncreated - first_local_no;
248

249
250
251
252
    prot_a_output_string(fp, conf_c->name);
    prot_a_output_extended_conf_type(fp, conf_c->type);
    prot_a_output_time(fp, conf_c -> creation_time );
    prot_a_output_time(fp, conf_c -> last_written );
253
    mux_printf (fp, " %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu",
254
255
256
257
258
259
260
                (unsigned long) conf_c -> creator,
                (unsigned long) conf_c -> presentation,
                (unsigned long) conf_c -> supervisor,
                (unsigned long) conf_c -> permitted_submitters,
                (unsigned long) conf_c -> super_conf,
                (unsigned long) conf_c -> msg_of_day,
                (unsigned long) conf_c -> nice,
261
                (unsigned long) conf_c -> keep_commented,
262
                (unsigned long) conf_c -> members.no_of_members,
263
264
                (unsigned long) first_local_no,
                (unsigned long) no_of_texts,
265
266
267
268
269
270
271
                (unsigned long) conf_c -> expire);
    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
272
{
273
    Local_text_no first_local_no = l2g_next_key(&conf_c->texts, 0);
274
    Local_text_no uncreated = l2g_first_appendable_key(&conf_c->texts);
275
276
    Local_text_no no_of_texts;

277
278
279
280
    if (first_local_no == 0)
	first_local_no = uncreated;

    no_of_texts = uncreated - first_local_no;
281

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

    mux_printf (fp, " %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu",
290
291
292
293
294
295
296
297
	     (unsigned long) conf_c -> creator,
	     (unsigned long) conf_c -> presentation,
	     (unsigned long) conf_c -> supervisor,
	     (unsigned long) conf_c -> permitted_submitters,
	     (unsigned long) conf_c -> super_conf,
	     (unsigned long) conf_c -> msg_of_day,
	     (unsigned long) conf_c -> nice,
	     (unsigned long) conf_c -> members.no_of_members,
298
299
	     (unsigned long) first_local_no,
	     (unsigned long) no_of_texts);
Per Cederqvist's avatar
Per Cederqvist committed
300
301
}

302
303
304
305
306
307
308
309
310
311
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);
    mux_printf(fp, " %lu %lu",
	       (unsigned long) conf_c -> highest_local_no,
	       (unsigned long) conf_c -> nice);
}

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
    mux_printf(fp, " %lu", (unsigned long)mark_list.no_of_marks);
Per Cederqvist's avatar
Per Cederqvist committed
320
321
322
323
324
325
326
327
328
329
330
331
332

    if ( mark_list.marks != NULL && mark_list.no_of_marks > 0 )
    {
	mux_printf(fp, " {");
	for ( i = 0; i < mark_list.no_of_marks; i++ )
	    prot_a_output_mark(fp, mark_list.marks[ i ]);
	mux_printf(fp, " }");
    }
    else
	mux_printf(fp, " *");
    
}

333
334
335
336
337
338
339
340
341
void
prot_a_output_aux_item_flags(Connection *fp,
                             Aux_item_flags flags)
{
    mux_putc(' ', fp);
    mux_putc(flags.deleted + '0', fp);
    mux_putc(flags.inherit + '0', fp);
    mux_putc(flags.secret + '0', fp);
    mux_putc(flags.hide_creator + '0', fp);
342
    mux_putc(flags.dont_garb + '0', fp);
343
344
345
346
    mux_putc(flags.reserved3 + '0', fp);
    mux_putc(flags.reserved4 + '0', fp);
    mux_putc(flags.reserved5 + '0', fp);
}
Per Cederqvist's avatar
Per Cederqvist committed
347
348

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

    prot_a_output_time(fp, t_stat->creation_time);
    
    mux_printf(fp, " %lu %lu %lu %lu %lu",
371
372
373
374
375
	    (unsigned long)t_stat->author,
	    (unsigned long)t_stat->no_of_lines,
	    (unsigned long)t_stat->no_of_chars,
	    (unsigned long)t_stat->no_of_marks,
	    (unsigned long)t_stat->no_of_misc);
Per Cederqvist's avatar
Per Cederqvist committed
376
377
378
379
380
381
382
383
384
385
386
387

    if ( t_stat->misc_items != NULL && t_stat->no_of_misc > 0 )
    {
	mux_printf(fp, " {");
	for ( i = 0; i < t_stat->no_of_misc; i++ )
	    prot_a_output_misc_info(fp, t_stat->misc_items[ i ]);
	mux_printf(fp, " }");
    }
    else
	mux_printf(fp, " *");
}	

388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
void
prot_a_output_aux_item_list(Connection *fp,
			    Aux_item_list *aux)
{
  int i;

    mux_printf(fp, " %lu",
               (unsigned long)aux->length);

    if ( aux->items != NULL && aux->length > 0 )
    {
        mux_printf(fp, " {");
        for (i = 0; i < aux->length; i++)
            prot_a_output_aux_item(fp, &aux->items[i]);
        mux_printf(fp, " }");
    }
    else
	mux_printf(fp, " *");
}

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
416

417
418
419
static void
prot_a_output_who_info_ident(Connection *fp,
			     Who_info_ident *info)
Per Cederqvist's avatar
Per Cederqvist committed
420
421
{
    mux_printf(fp, " %lu %lu %lu",
422
423
424
	    (unsigned long)info->person,
	    (unsigned long)info->working_conference,
	    (unsigned long)info->session_no);
Per Cederqvist's avatar
Per Cederqvist committed
425
426
427

    prot_a_output_string(fp, info->what_am_i_doing);
    prot_a_output_string(fp, info->username);
428
429
430
431
432
    prot_a_output_string(fp, info->hostname);
    prot_a_output_string(fp, info->ident_user);
}


433
void
434
435
436
437
prot_a_output_who_info(Connection *fp,
		       Who_info *info)
{
    mux_printf(fp, " %lu %lu %lu",
438
439
440
	    (unsigned long)info->person,
	    (unsigned long)info->working_conference,
	    (unsigned long)info->session_no);
441
442

    prot_a_output_string(fp, info->what_am_i_doing); 
443
    prot_a_output_string(fp, info->username);
Per Cederqvist's avatar
Per Cederqvist committed
444
445
446
447
448
449
450
451
452
}


void
prot_a_output_who_info_list(Connection *fp,
			    Who_info_list info)
{
    int i;
    
453
    mux_printf(fp, " %lu", (unsigned long)info.no_of_persons);
Per Cederqvist's avatar
Per Cederqvist committed
454
455
456
457
458
459
460

    if ( info.info != NULL && info.no_of_persons > 0 )
    {
	mux_printf(fp, " {");
	for ( i = 0; i < info.no_of_persons; i++ )
	{
	    prot_a_output_who_info(fp, &info.info[ i ]);
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
	    /* The username is specially alloced in who_is_on() in
	       session.c. */
	    s_clear(&info.info[i].username);
	}
	mux_printf(fp, " }");
    }
    else
	mux_printf(fp, " *");
}

void
prot_a_output_who_info_ident_list(Connection *fp,
				  Who_info_ident_list info)
{
    int i;
    
477
    mux_printf(fp, " %lu", (unsigned long)info.no_of_persons);
478
479
480
481
482
483
484

    if ( info.info != NULL && info.no_of_persons > 0 )
    {
	mux_printf(fp, " {");
	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
485
486
487
488
489
490
491
492
493
494
495
496
497
	}
	mux_printf(fp, " }");
    }
    else
	mux_printf(fp, " *");
}

void
prot_a_output_who_info_list_old(Connection *fp,
				Who_info_list_old info)
{
    int i;
    
498
    mux_printf(fp, " %lu", (unsigned long)info.no_of_persons);
Per Cederqvist's avatar
Per Cederqvist committed
499
500
501
502
503
504
505

    if ( info.info != NULL && info.no_of_persons > 0 )
    {
	mux_printf(fp, " {");
	for ( i = 0; i < info.no_of_persons; i++ )
	{
	    mux_printf(fp, " %lu %lu",
506
507
		    (unsigned long)info.info[ i ].person,
		    (unsigned long)info.info[ i ].working_conference);
Per Cederqvist's avatar
Per Cederqvist committed
508
509
510
511
512
513
514
515
516
517
518
519
520
521
	    
	    prot_a_output_string(fp, info.info[ i ].what_am_i_doing);
	}
	mux_printf(fp, " }");
    }
    else
	mux_printf(fp, " *");
}

void
prot_a_output_session_info(Connection *fp,
			   Session_info *info)
{
    mux_printf(fp, " %lu %lu %lu",
522
523
524
	    (unsigned long)info->person,
	    (unsigned long)info->working_conference,
	    (unsigned long)info->session);
Per Cederqvist's avatar
Per Cederqvist committed
525
526
527
528

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

529
    mux_printf(fp, " %lu", (unsigned long)info->idle_time);
Per Cederqvist's avatar
Per Cederqvist committed
530
531
    prot_a_output_time(fp, info->connection_time);
}
532
533
534

void
prot_a_output_session_info_ident(Connection *fp,
535
				 Session_info_ident *info)
536
537
{
    mux_printf(fp, " %lu %lu %lu",
538
539
540
	    (unsigned long)info->person,
	    (unsigned long)info->working_conference,
	    (unsigned long)info->session);
541
542
543
544
545
546

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

547
    mux_printf(fp, " %lu", (unsigned long)info->idle_time);
548
549
    prot_a_output_time(fp, info->connection_time);
}
Per Cederqvist's avatar
Per Cederqvist committed
550
551
552
    
void
prot_a_output_info(Connection *fp,
553
554
555
556
557
558
559
560
561
                   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
562
563
{
    mux_printf(fp, " %lu %lu %lu %lu %lu %lu",
564
565
566
567
568
569
	    (unsigned long)info->version,
	    (unsigned long)info->conf_pres_conf,
	    (unsigned long)info->pers_pres_conf,
	    (unsigned long)info->motd_conf,
	    (unsigned long)info->kom_news_conf,
	    (unsigned long)info->motd_of_lyskom);
Per Cederqvist's avatar
Per Cederqvist committed
570
571
572
573
574
575
576
}


extern void
prot_a_output_string(Connection *fp,
		     String str)
{
577
    mux_printf(fp, " %luH", (unsigned long)str.len);
Per Cederqvist's avatar
Per Cederqvist committed
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
    mux_write(fp, str.string, str.len);
}


extern void
prot_a_output_priv_bits(Connection *fp,
			Priv_bits bits)
{
    mux_putc(' ', fp);
    mux_putc(bits.wheel + '0', fp);
    mux_putc(bits.admin + '0', fp);
    mux_putc(bits.statistic + '0', fp);
    mux_putc(bits.create_pers + '0', fp);
    mux_putc(bits.create_conf + '0', fp);
    mux_putc(bits.change_name + '0', fp);
593
    mux_putc(bits.extern_gw + '0', fp);
Per Cederqvist's avatar
Per Cederqvist committed
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
    mux_putc(bits.flg8 + '0', fp);
    mux_putc(bits.flg9 + '0', fp);
    mux_putc(bits.flg10 + '0', fp);
    mux_putc(bits.flg11 + '0', fp);
    mux_putc(bits.flg12 + '0', fp);
    mux_putc(bits.flg13 + '0', fp);
    mux_putc(bits.flg14 + '0', fp);
    mux_putc(bits.flg15 + '0', fp);
    mux_putc(bits.flg16 + '0', fp);
}


extern void
prot_a_output_personal_flags(Connection *fp,
			     Personal_flags flags)
{
    mux_putc(' ', fp);
    mux_putc(flags.unread_is_secret + '0', fp);
    mux_putc(flags.flg2 + '0', fp);
    mux_putc(flags.flg3 + '0', fp);
    mux_putc(flags.flg4 + '0', fp);
    mux_putc(flags.flg5 + '0', fp);
    mux_putc(flags.flg6 + '0', fp);
    mux_putc(flags.flg7 + '0', fp);
    mux_putc(flags.flg8 + '0', fp);
}	

extern void
prot_a_output_conf_type(Connection *fp,
			Conf_type type)
{
    mux_putc(' ', fp);
    mux_putc(type.rd_prot + '0', fp);
    mux_putc(type.original + '0', fp);
    mux_putc(type.secret + '0', fp);
    mux_putc(type.letter_box + '0', fp);
}

632
633
634
635
636
637
638
639
640
extern void
prot_a_output_extended_conf_type(Connection *fp,
				 Conf_type type)
{
    mux_putc(' ', fp);
    mux_putc(type.rd_prot + '0', fp);
    mux_putc(type.original + '0', fp);
    mux_putc(type.secret + '0', fp);
    mux_putc(type.letter_box + '0', fp);
641
    mux_putc(type.allow_anon + '0', fp);
David Byers's avatar
David Byers committed
642
    mux_putc(type.forbid_secret + '0', fp);
643
644
645
    mux_putc(type.reserved2 + '0', fp);
    mux_putc(type.reserved3 + '0', fp);
}
Per Cederqvist's avatar
Per Cederqvist committed
646
647
648

extern void
prot_a_output_member_list(Connection *fp,
649
                          Member_list m_list)
Per Cederqvist's avatar
Per Cederqvist committed
650
651
652
{
    int i;

653
    mux_printf(fp, " %lu", (unsigned long)m_list.no_of_members);
Per Cederqvist's avatar
Per Cederqvist committed
654
655
656
657
658
659
660
661
662
663
664
    if ( m_list.members != NULL && m_list.no_of_members > 0 )
    {
	mux_printf(fp, " {");
	for ( i = 0; i < m_list.no_of_members; i++ )
	    prot_a_output_member(fp, m_list.members[ i ]);
	mux_printf(fp, " }");
    }
    else
	mux_printf(fp, " *");
}

665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
extern void
prot_a_output_member_list_old(Connection *fp,
                              Member_list m_list)
{
    int i;

    mux_printf(fp, " %lu", (unsigned long)m_list.no_of_members);
    if ( m_list.members != NULL && m_list.no_of_members > 0 )
    {
	mux_printf(fp, " {");
	for ( i = 0; i < m_list.no_of_members; i++ )
	    prot_a_output_member_old(fp, m_list.members[ i ]);
	mux_printf(fp, " }");
    }
    else
	mux_printf(fp, " *");
}

Per Cederqvist's avatar
Per Cederqvist committed
683
684
685
686

void
prot_a_output_member(Connection *fp,
		     Member member)
687
688
689
690
691
692
693
694
695
696
{
    mux_printf(fp, " %lu", (unsigned long)member.member);
    mux_printf(fp, " %lu", (unsigned long)member.added_by);
    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
697
{
698
    mux_printf(fp, " %lu", (unsigned long)member.member);
Per Cederqvist's avatar
Per Cederqvist committed
699
700
701
702
703
704
705
}

    
extern void
prot_a_output_mark(Connection *fp,
		   Mark mark)
{
706
    mux_printf(fp, " %lu %lu", (unsigned long)mark.text_no, (unsigned long)mark.mark_type);
Per Cederqvist's avatar
Per Cederqvist committed
707
708
709
710
711
712
713
}


extern void
prot_a_output_misc_info(Connection *fp, 
			Misc_info misc)
{
714
    mux_printf(fp, " %lu", (unsigned long)misc.type);
Per Cederqvist's avatar
Per Cederqvist committed
715
716
717
718
    
    switch(misc.type)
    {
    case recpt:
719
	mux_printf(fp, " %lu", (unsigned long)misc.datum.recipient);
Per Cederqvist's avatar
Per Cederqvist committed
720
721
722
	break;
	
    case cc_recpt:
723
	mux_printf(fp, " %lu", (unsigned long)misc.datum.cc_recipient);
Per Cederqvist's avatar
Per Cederqvist committed
724
725
	break;
	
726
727
728
729
    case bcc_recpt:
	mux_printf(fp, " %lu", (unsigned long)misc.datum.bcc_recipient);
	break;
	
Per Cederqvist's avatar
Per Cederqvist committed
730
    case loc_no:
731
	mux_printf(fp, " %lu", (unsigned long)misc.datum.local_no);
Per Cederqvist's avatar
Per Cederqvist committed
732
733
734
735
736
737
738
	break;
	
    case rec_time:
	prot_a_output_time(fp, misc.datum.received_at);
	break;
	
    case comm_to:
739
	mux_printf(fp, " %lu", (unsigned long)misc.datum.comment_to);
Per Cederqvist's avatar
Per Cederqvist committed
740
741
742
	break;
	
    case comm_in:
743
	mux_printf(fp, " %lu", (unsigned long)misc.datum.commented_in);
Per Cederqvist's avatar
Per Cederqvist committed
744
745
746
	break;
	
    case footn_to:
747
	mux_printf(fp, " %lu", (unsigned long)misc.datum.footnote_to);
Per Cederqvist's avatar
Per Cederqvist committed
748
749
750
	break;
	
    case footn_in:
751
	mux_printf(fp, " %lu", (unsigned long)misc.datum.footnoted_in);
Per Cederqvist's avatar
Per Cederqvist committed
752
753
754
	break;
	
    case sent_by:
755
	mux_printf(fp, " %lu", (unsigned long)misc.datum.sender);
Per Cederqvist's avatar
Per Cederqvist committed
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
	break;
	
    case sent_at:
	prot_a_output_time(fp, misc.datum.sent_at);
	break;

#ifndef COMPILE_CHECKS
    default:
	restart_kom("prot_a_output_misc_info: Illegal misc\n");
#endif
    }
}


void
prot_a_output_time(Connection *fp,
772
		   time_t clk)
Per Cederqvist's avatar
Per Cederqvist committed
773
{
774
    struct tm *t;
Per Cederqvist's avatar
Per Cederqvist committed
775

776
    t = localtime( &clk );
Per Cederqvist's avatar
Per Cederqvist committed
777
778

    mux_printf(fp, " %lu %lu %lu %lu %lu %lu %lu %lu %lu",
779
780
781
782
783
784
785
786
787
               (unsigned long) t -> tm_sec,
               (unsigned long) t -> tm_min,
               (unsigned long) t -> tm_hour,
               (unsigned long) t -> tm_mday,
               (unsigned long) t -> tm_mon,
               (unsigned long) t -> tm_year,
               (unsigned long) t -> tm_wday,
               (unsigned long) t -> tm_yday,
               (unsigned long) t -> tm_isdst);
Per Cederqvist's avatar
Per Cederqvist committed
788
789
790
791
792
793
794
}


void
prot_a_output_session_no(Connection *fp,
			 Session_no session_no)
{
795
    mux_printf(fp, " %lu", (unsigned long) session_no);
Per Cederqvist's avatar
Per Cederqvist committed
796
}
Linus Tolke's avatar
Linus Tolke committed
797
798
799
800
801

void
prot_a_output_text_no(Connection *fp,
		      Text_no text)
{
802
    mux_printf(fp, " %lu", (unsigned long) text);
Linus Tolke's avatar
Linus Tolke committed
803
}
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839

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);
    mux_printf (fp, " %lu", (unsigned long) conf_c -> conf_no);
}

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

    mux_printf(fp, " %lu", (unsigned long)c_list.no_of_confs);
    if ( c_list.confs != NULL && c_list.no_of_confs > 0 )
    {
	mux_printf(fp, " {");
	for ( i = 0; i < c_list.no_of_confs; i++ )
	    prot_a_output_conf_z_info(fp, &c_list.confs[ i ]);
	mux_printf(fp, " }");
    }
    else
	mux_printf(fp, " *");
}

void
prot_a_output_version_info (Connection  *fp,
			    Version_info *v_info)
{
    mux_printf (fp, " %lu", (unsigned long) v_info->protocol_version);
    prot_a_output_string(fp, v_info->server_name);
    prot_a_output_string(fp, v_info->server_version);
}
840
841
842
843
844
845
846
847
848
849
850
851

void
prot_a_output_num_list (Connection *fp,
                        Number_list *num_list)
{
    int i;
    
    mux_printf(fp, " %lu", (unsigned long) num_list->length);
    if (num_list->length == 0)
        mux_printf(fp, " *");
    else
    {
852
        mux_printf(fp, " {");
853
        for (i = 0; i < num_list->length; i++)
854
            mux_printf(fp, " %lu", (unsigned long)num_list->data[i]);
855
856
857
        mux_printf(fp, " }");
    }
}
858

859
860
861
862
863
864
865
866
867
868
869
870
871
872
static void
prot_a_output_session_flags(Connection *fp,
			    Session_flags flags)
{
    mux_putc(' ', fp);
    mux_putc(flags.invisible + '0', fp);
    mux_putc(flags.user_active_used + '0', fp);
    mux_putc(flags.user_absent + '0', fp);
    mux_putc(flags.reserved3 + '0', fp);
    mux_putc(flags.reserved4 + '0', fp);
    mux_putc(flags.reserved5 + '0', fp);
    mux_putc(flags.reserved6 + '0', fp);
    mux_putc(flags.reserved7 + '0', fp);
}	
873
874
875
876
static void
prot_a_output_dynamic_session_info (Connection *fp,
				    Dynamic_session_info *info)
{
877
    mux_printf(fp, " %lu %lu %lu %lu",
878
879
880
	       (unsigned long)info->session,
	       (unsigned long)info->person,
	       (unsigned long)info->working_conference,
881
882
	       (unsigned long)info->idle_time);
    prot_a_output_session_flags(fp, info->flags);
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
    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;

    mux_printf(fp, " %lu", (unsigned long) list->no_of_sessions);
    if (list->no_of_sessions == 0)
	mux_printf(fp, " *");
    else
    {
	mux_printf(fp, " {");
	for (i = 0; i < list->no_of_sessions; i++)
	    prot_a_output_dynamic_session_info(fp, &list->sessions[i]);
	mux_printf(fp, " }");
    }
}

914
915
void
prot_a_output_l2g_iterator_as_text_list(Connection *fp,
916
					L2g_iterator *iter)
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
{
    Local_text_no lno = l2gi_begin(iter);
    Local_text_no limit = l2gi_end(iter);

    mux_printf(fp, " %lu %lu",
	       (unsigned long)lno,
	       (unsigned long)(limit - lno));

    if (limit - lno > 0)
    {
	mux_printf(fp, " {");
	for (; !iter->search_ended; l2gi_next(iter))
	{
	    /* Write the correct number of zeroes. */
	    for (; lno < iter->lno; ++lno)
		mux_printf(fp, " 0");
	    /* Write this piece of data. */
	    mux_printf(fp, " %lu", (unsigned long)iter->tno);
	    ++lno;
	}
937
938
939
	/* Write any trailing zeroes */
	for (; lno < limit; ++lno)
	    mux_printf(fp, " 0");
940
941
942
943
944
	mux_printf(fp, " }");
    }
    else
	mux_printf(fp, " *");
}
945
946
947
948
949
950
951

void
prot_a_output_text_mapping(Connection *fp,
			   Text_mapping *map)
{
    Local_text_no lowest;
    Local_text_no highest;
952
    Local_text_no limit;
953
954
955
956
957
958
959
960
    Local_text_no zeroes = 0;
    Local_text_no nonzeroes = 0;
    L2g_iterator iter;

    /* 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),
961
	     highest = (lowest = iter.search_ended?map->first:iter.lno) - 1;
962
963
964
965
966
967
968
969
	 !iter.search_ended && nonzeroes < map->no_of_texts;
	 l2gi_next(&iter))
    {
	zeroes += (iter.lno - highest) - 1;
	nonzeroes++;
	highest = iter.lno;
    }

970
971
    limit = highest + 1;

972
973
974
975
976
977
978
    mux_printf(fp, " %lu", (unsigned long)map->first);
    if (iter.search_ended)
	mux_printf(fp, " %lu",
		   (unsigned long)l2g_first_appendable_key(map->l2g));
    else
	mux_printf(fp, " %lu", (unsigned long)limit);

979
980
    /* Emit the "later-texts-exists" flag. */

981
    mux_printf(fp, " %c", iter.search_ended ? '0' : '1');
982
983
984
985
986
987


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

    if (nonzeroes == 0)
    {
988
	/* Special case: an empty array.  Use the sparse format so
989
990
991
992
993
994
995
996
997
998
999
	   that we don't have to philosophize about what the lower
	   limit in the text-list should be. */
	mux_printf(fp, " 0 0 *");
    }
    else if (zeroes >= nonzeroes)
    {
	/* There are at least as many zeroes as real mappings, so use
	   a sparse representation. */

	mux_printf(fp, " 0 %lu {", (unsigned long)nonzeroes);

1000
	for (l2gi_searchsome(&iter, map->l2g, map->first, limit);
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
	     !iter.search_ended;
	     l2gi_next(&iter))
	{
	    mux_printf(fp, " %lu %lu",
		       (unsigned long)iter.lno,
		       (unsigned long)iter.tno);
	}
	mux_printf(fp, " }");
    }
    else
    {
	/* Emit a dense block. */
	mux_printf(fp, " 1 %lu %lu {",
		   (unsigned long)lowest,
		   (unsigned long)(zeroes + nonzeroes));
	highest = lowest;
1017
	for (l2gi_searchsome(&iter, map->l2g, map->first, limit);
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
	     !iter.search_ended;
	     l2gi_next(&iter))
	{
	    while (highest++ < iter.lno)
		mux_printf(fp, " 0");
	    mux_printf(fp, " %lu", (unsigned long)iter.tno);
	}
	mux_printf(fp, " }");
    }
}
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047


#ifdef DEBUG_CALLS
void
prot_a_output_memory_info(Connection *fp,
                          Memory_info *result)
{
    mux_printf(fp, " %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu",
               (unsigned long)result->arena,
               (unsigned long)result->ordblks,
               (unsigned long)result->smblks,
               (unsigned long)result->hblks,
               (unsigned long)result->hblkhd,
               (unsigned long)result->usmblks,
               (unsigned long)result->fsmblks,
               (unsigned long)result->uordblks,
               (unsigned long)result->fordblks,
               (unsigned long)result->keepcost);
}
#endif