memory.c 16.1 KB
Newer Older
Linus Tolke Y's avatar
Linus Tolke Y committed
1
/*
2 3
 * $Id: memory.c,v 0.48 2003/08/23 16:38:15 ceder Exp $
 * Copyright (C) 1991-1994, 1996-1999, 2001-2003  Lysator Academic Computer Association.
Linus Tolke Y's avatar
Linus Tolke Y committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
 *
 * 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.
 *
Per Cederqvist's avatar
Per Cederqvist committed
23
 * Please report bugs at http://bugzilla.lysator.liu.se/. 
Linus Tolke Y's avatar
Linus Tolke Y committed
24
 */
Per Cederqvist's avatar
Per Cederqvist committed
25
/*
26
 * Memory allocators/deallocators/initializers.
Per Cederqvist's avatar
Per Cederqvist committed
27 28 29 30
 *
 * These functions should be used instead of smalloc/srealloc.
 */

David Byers's avatar
David Byers committed
31 32 33 34
#if HAVE_CONFIG_H
#  include <config.h>
#endif

Per Cederqvist's avatar
Per Cederqvist committed
35
#include <stdio.h>
Per Cederqvist's avatar
Per Cederqvist committed
36 37 38
#ifdef HAVE_STRING_H
#  include <string.h>
#endif
39
#include <sys/types.h>
40
#include "timewrap.h"
Per Cederqvist's avatar
Per Cederqvist committed
41

42
#include "s-string.h"
Per Cederqvist's avatar
Per Cederqvist committed
43 44 45
#include "kom-types.h"
#include "kom-memory.h"
#include "server/smalloc.h"
46
#include "log.h"
Per Cederqvist's avatar
Per Cederqvist committed
47
#include "lyskomd.h"
48
#include "ram-io.h"
Per Cederqvist's avatar
Per Cederqvist committed
49
#include "local-to-global.h"
Per Cederqvist's avatar
Per Cederqvist committed
50 51 52 53 54

static int person_cnt = 0;
static int conference_cnt = 0;
static int text_stat_cnt = 0;

55
/* Forward declarations */
Per Cederqvist's avatar
Per Cederqvist committed
56

57 58 59 60 61 62 63 64
static void            clear_mark_list (Mark_list *mark_list);
static Mark_list       copy_mark_list  (Mark_list ml);
static void            clear_member_list (Member_list *m);
static Member_list     copy_member_list  (Member_list ml);
static void            clear_membership (Membership *mship);
static Membership      copy_membership  (Membership m);
static void            clear_membership_list (Membership_list *mlist);
static Membership_list copy_membership_list  (Membership_list ml);
65 66
static void            copy_aux_item_list(Aux_item_list *dest,
					  const Aux_item_list *src);
67 68 69 70 71 72 73 74 75 76

/* Conf_type */

void
init_conf_type(Conf_type *ct)
{
    ct->rd_prot = 0;
    ct->original = 0;
    ct->secret = 0;
    ct->letter_box = 0;
77
    ct->allow_anon = 1;
David Byers's avatar
David Byers committed
78
    ct->forbid_secret = 0;
79 80
    ct->reserved2 = 0;
    ct->reserved3 = 0;
Per Cederqvist's avatar
Per Cederqvist committed
81 82
}

83
/* Conference */
Per Cederqvist's avatar
Per Cederqvist committed
84

85
Conference *
Per Cederqvist's avatar
Per Cederqvist committed
86 87 88 89 90 91 92
alloc_conference(void)
{
    Conference *c;

    conference_cnt++;
    
    c = smalloc(sizeof(Conference));
93
    init_conference(c);
Per Cederqvist's avatar
Per Cederqvist committed
94 95 96
    return c;
}

97 98
void
free_conference(Conference *confp)
Per Cederqvist's avatar
Per Cederqvist committed
99
{
100 101
    if ( confp == NULL )
	return;
Per Cederqvist's avatar
Per Cederqvist committed
102

103 104
    conference_cnt--;
    clear_conference(confp);
105
    l2g_destruct(&confp->texts);
106
    sfree(confp);
Per Cederqvist's avatar
Per Cederqvist committed
107 108
}

109 110
void
clear_conference(Conference *confp)
Per Cederqvist's avatar
Per Cederqvist committed
111
{
112 113
    s_clear(&confp->name);
    clear_member_list(&confp->members);
Per Cederqvist's avatar
Per Cederqvist committed
114
    l2g_clear(&confp->texts);
David Byers's avatar
David Byers committed
115
    free_aux_item_list(&confp->aux_item_list);
116 117
    init_conference(confp);
}
Per Cederqvist's avatar
Per Cederqvist committed
118

119
Conference *
Per Cederqvist's avatar
Per Cederqvist committed
120
copy_conference (const Conference *o)
121 122 123 124
{
    Conference *c;

    c = alloc_conference();
125 126 127 128 129 130 131 132 133 134
    c->type = o->type;
    c->creator = o->creator;
    c->supervisor = o->supervisor;
    c->permitted_submitters = o->permitted_submitters;
    c->super_conf = o->super_conf;
    c->creation_time = o->creation_time;
    c->presentation = o->presentation;
    c->last_written = o->last_written;
    c->msg_of_day = o->msg_of_day;
    c->nice = o->nice;
135
    c->keep_commented = o->keep_commented;
136
    c->expire = o->expire;
137
    s_strcpy(&c->name, o->name);
138
    c->highest_aux = o->highest_aux;
David Byers's avatar
David Byers committed
139 140
    copy_aux_item_list(&c->aux_item_list,
                       &o->aux_item_list);
141 142
    c->members = copy_member_list(o->members);
    l2g_copy(&c->texts, &o->texts);
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
    return c;
}

void
init_conference  (Conference *c)
{
    init_conf_type(&c->type);
    c->creator = 0;
    c->supervisor = 0;
    c->permitted_submitters = 0;
    c->super_conf = 0;
    c->creation_time = NO_TIME;
    c->presentation = 0;
    c->last_written = NO_TIME;
    c->msg_of_day = 0;
    c->nice = 0;
159
    c->keep_commented = 0;
160 161
    c->highest_aux = 0;
    c->expire = 0;
162 163
    c->name = EMPTY_STRING;
    init_member_list(&c->members);
Per Cederqvist's avatar
Per Cederqvist committed
164
    l2g_init(&c->texts);
David Byers's avatar
David Byers committed
165
    init_aux_item_list(&c->aux_item_list);
Per Cederqvist's avatar
Per Cederqvist committed
166 167
}

168 169 170 171 172 173 174 175 176
/* Dynamic_session_info */

void
init_dynamic_session_info (Dynamic_session_info *d)
{
    d->session = 0;
    d->person = 0;
    d->working_conference = 0;
    d->idle_time = 0;
177 178 179 180 181 182 183 184
    d->flags.invisible = FALSE;
    d->flags.user_active_used = FALSE;
    d->flags.user_absent = FALSE;
    d->flags.reserved3 = FALSE;
    d->flags.reserved4 = FALSE;
    d->flags.reserved5 = FALSE;
    d->flags.reserved6 = FALSE;
    d->flags.reserved7 = FALSE;
185 186 187
    d->what_am_i_doing = EMPTY_STRING;
}

188

189 190
/* Mark_list */

191 192
static  void
clear_mark_list(Mark_list *mark_list)
Per Cederqvist's avatar
Per Cederqvist committed
193 194
{
    if ( mark_list == NULL )
195
    {
David Byers's avatar
David Byers committed
196
	kom_log("clear_mark_list(): mark_list == NULL.\n");
Per Cederqvist's avatar
Per Cederqvist committed
197
	return;
198
    }
Per Cederqvist's avatar
Per Cederqvist committed
199 200

    sfree(mark_list->marks);
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
    init_mark_list(mark_list);
}

static  Mark_list
copy_mark_list(Mark_list ml)
{
    Mark_list r;

    r.no_of_marks = ml.no_of_marks;
    r.marks = smalloc(r.no_of_marks * sizeof(Mark));
    memcpy(r.marks, ml.marks, r.no_of_marks * sizeof(Mark));
    return r;
}

void
init_mark_list (Mark_list *ml)
{
    ml->no_of_marks = 0;
    ml->marks = NULL;
}

/* Member_list */

static void 
clear_member_list(Member_list *m)
{
    if ( m == NULL )
	return;

    sfree(m->members);
    init_member_list(m);
}

static  Member_list
copy_member_list(Member_list ml)
{
    Member_list res;

    res.no_of_members = ml.no_of_members;
    res.members = smalloc(res.no_of_members * sizeof ( Member ));
    memcpy(res.members, ml.members, res.no_of_members * sizeof ( Member ));
    return res;
Per Cederqvist's avatar
Per Cederqvist committed
243 244
}

245 246 247 248 249 250 251
void
init_member_list (Member_list *ml)
{
    ml->no_of_members = 0;
    ml->members = NULL;
}

252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
/* Member */

void
init_member(Member *mem)
{
    if (mem == NULL)
    {
        kom_log("init_member(): mem == NULL.\n");
        return;
    }
    mem->member = 0;
    mem->added_by = 0;
    mem->added_at = NO_TIME;
    init_membership_type(&mem->type);
}

268
/* Membership */
Per Cederqvist's avatar
Per Cederqvist committed
269

270 271 272 273
static  void
clear_membership(Membership *mship)
{
    if ( mship == NULL )
Per Cederqvist's avatar
Per Cederqvist committed
274
    {
David Byers's avatar
David Byers committed
275
	kom_log("clear_membership(): mship == NULL.\n");
276
	return;
Per Cederqvist's avatar
Per Cederqvist committed
277 278
    }

279
    sfree(mship->read_ranges);
280 281 282 283 284 285 286 287 288
    init_membership(mship);
}

static Membership
copy_membership(Membership m)
{
    Membership res;

    res = m;
289 290 291 292 293 294 295 296 297 298 299 300 301
    if (m.no_of_read_ranges != 0)
    {
	res.read_ranges = smalloc(m.no_of_read_ranges
				  * sizeof(res.read_ranges[0]));
	memcpy(res.read_ranges, m.read_ranges,
	       m.no_of_read_ranges * sizeof(res.read_ranges[0]));
    }
    else if (m.read_ranges != NULL)
    {
	kom_log("copy_membership(): "
		"read_ranges != NULL but no_of_read_ranges == 0\n");
	res.read_ranges = NULL;
    }
302 303 304
    return res;
}

David Byers's avatar
David Byers committed
305 306 307 308 309 310
void
init_membership_type(Membership_type *m)
{
    m->invitation = 0;
    m->passive = 0;
    m->secret = 0;
311
    m->passive_message_invert = 0;
David Byers's avatar
David Byers committed
312 313 314 315 316 317
    m->reserved2 = 0;
    m->reserved3 = 0;
    m->reserved4 = 0;
    m->reserved5 = 0;
}

318 319 320 321 322
void
init_membership(Membership *m)
{
    m->conf_no = 0;
    m->priority = 0;
323 324
    m->no_of_read_ranges = 0;
    m->read_ranges = NULL;
325
    m->last_time_read = NO_TIME;
326
    m->added_by = 0;
327
    m->position = 0;
328
    m->added_at = NO_TIME;
David Byers's avatar
David Byers committed
329
    init_membership_type(&m->type);
330
    m->skip_read_texts = FALSE;
Per Cederqvist's avatar
Per Cederqvist committed
331 332
}

333 334
/* Membership_list */

Per Cederqvist's avatar
Per Cederqvist committed
335
static void
336
clear_membership_list(Membership_list *mlist)
Per Cederqvist's avatar
Per Cederqvist committed
337
{
338 339 340 341
    int i;

    if ( mlist == NULL )
    {
David Byers's avatar
David Byers committed
342
	kom_log("clear_membership_list(): membership_list == NULL.\n");
Per Cederqvist's avatar
Per Cederqvist committed
343
	return;
344
    }
Per Cederqvist's avatar
Per Cederqvist committed
345

346 347 348 349
    for ( i = 0; i < mlist->no_of_confs; i++ )
    {
	clear_membership(&mlist->confs[i]);
    }
Per Cederqvist's avatar
Per Cederqvist committed
350

351
    sfree(mlist->confs);
352
    init_membership_list(mlist);
Per Cederqvist's avatar
Per Cederqvist committed
353 354
}

355 356 357 358 359 360 361 362
static  Membership_list
copy_membership_list(Membership_list ml)
{
    Membership_list r;
    int i;

    r.no_of_confs = ml.no_of_confs;
    r.confs = smalloc(ml.no_of_confs * sizeof(Membership));
363

364 365 366 367 368 369 370 371 372 373
    for ( i = 0; i < r.no_of_confs; i++ )
    {
	r.confs[i] = copy_membership(ml.confs[i]);
    }

    return r;
}

void
init_membership_list (Membership_list *m)
Per Cederqvist's avatar
Per Cederqvist committed
374
{
375 376 377 378
    m->no_of_confs = 0;
    m->confs = NULL;
}

379 380 381 382 383 384 385 386 387 388 389
/* Static_session_info */

void
init_static_session_info (Static_session_info *d)
{
    d->username = EMPTY_STRING;
    d->hostname = EMPTY_STRING;
    d->ident_user = EMPTY_STRING;
    d->connection_time = NO_TIME;
}

390 391 392 393 394 395 396 397 398 399 400
/* Person */
Person *
alloc_person(void)
{
    Person *p;

    person_cnt++;
    
    p = smalloc(sizeof(Person));
    init_person(p);
    return p;
Per Cederqvist's avatar
Per Cederqvist committed
401 402
}

403
void
Per Cederqvist's avatar
Per Cederqvist committed
404 405 406 407 408 409 410
free_person(Person *person)
{
    if ( person == NULL )
	return;

    person_cnt--;
    clear_person(person);
411
    l2g_destruct(&person->created_texts);
Per Cederqvist's avatar
Per Cederqvist committed
412 413 414
    sfree(person);
}

415 416 417 418
void
clear_person(Person *person)
{
    s_clear(&person->username);
Per Cederqvist's avatar
Per Cederqvist committed
419
    l2g_clear(&person->created_texts);
420 421 422 423
    clear_mark_list(&person->marks);
    clear_membership_list(&person->conferences);
    init_person(person);
}
Per Cederqvist's avatar
Per Cederqvist committed
424

425
Person *
426
copy_person(const Person *p)
Per Cederqvist's avatar
Per Cederqvist committed
427
{
428
    Person *c;
Per Cederqvist's avatar
Per Cederqvist committed
429

430
    c = alloc_person();
431 432 433 434 435 436 437 438 439 440 441 442
    c->user_area = p->user_area;
    c->privileges = p->privileges;
    c->flags = p->flags;
    c->last_login = p->last_login;
    c->total_time_present = p->total_time_present;
    c->sessions = p->sessions;
    c->created_lines = p->created_lines;
    c->created_bytes = p->created_bytes;
    c->read_texts = p->read_texts;
    c->no_of_text_fetches = p->no_of_text_fetches;
    c->created_persons = p->created_persons;
    c->created_confs = p->created_confs;
443
    s_strcpy(&c->username, p->username);
Per Cederqvist's avatar
Per Cederqvist committed
444
    l2g_copy(&c->created_texts, &p->created_texts);
445 446
    c->marks = copy_mark_list(p->marks);
    c->conferences = copy_membership_list(p->conferences);
447
    memcpy(&c->pwd, &p->pwd, sizeof(Password));
448
    return c;
Per Cederqvist's avatar
Per Cederqvist committed
449 450
}

451 452
void
init_person  (Person *p)
Per Cederqvist's avatar
Per Cederqvist committed
453
{
454 455 456 457 458 459 460 461 462 463 464 465 466 467
    p->user_area = 0;
    p->total_time_present = 0;
    p->sessions = 0;
    p->created_lines = 0;
    p->created_bytes = 0;
    p->read_texts = 0;
    p->no_of_text_fetches = 0;
    p->created_persons = 0;
    p->created_confs = 0;
    p->username = EMPTY_STRING;
    p->last_login = NO_TIME;

    init_priv_bits(&p->privileges);
    init_personal_flags(&p->flags);
Per Cederqvist's avatar
Per Cederqvist committed
468
    l2g_init(&p->created_texts);
469 470 471
    init_mark_list(&p->marks);
    init_membership_list(&p->conferences);

472 473 474
    /* No initialization of pwd is really needed,
       but this shuts up valgrind. */
    memset(p->pwd, 0, PASSWD_LEN);
Per Cederqvist's avatar
Per Cederqvist committed
475 476
}

477
/* Personal_flags */
Per Cederqvist's avatar
Per Cederqvist committed
478

479 480 481 482 483 484 485 486 487 488 489
void
init_personal_flags (Personal_flags *p)
{
    p->unread_is_secret = 0;
    p->flg2 = 0;
    p->flg3 = 0;
    p->flg4 = 0;
    p->flg5 = 0;
    p->flg6 = 0;
    p->flg7 = 0;
    p->flg8 = 0;
Per Cederqvist's avatar
Per Cederqvist committed
490 491
}

492 493 494 495
/* Priv_bits */

void
init_priv_bits (Priv_bits *pb)
Per Cederqvist's avatar
Per Cederqvist committed
496
{
497 498 499 500 501 502
    pb->wheel = 0;
    pb->admin = 0;
    pb->statistic = 0;
    pb->create_pers = 0;
    pb->create_conf = 0;
    pb->change_name = 0;
503
    pb->flg7 = 0;
504 505 506 507 508 509 510 511 512 513
    pb->flg8 = 0;
    pb->flg9 = 0;
    pb->flg10 = 0;
    pb->flg11 = 0;
    pb->flg12 = 0;
    pb->flg13 = 0;
    pb->flg14 = 0;
    pb->flg15 = 0;
    pb->flg16 = 0;
}
Per Cederqvist's avatar
Per Cederqvist committed
514

515
/* Session_info */
Per Cederqvist's avatar
Per Cederqvist committed
516

517 518 519 520 521 522 523 524 525 526 527
void
init_session_info (Session_info *s)
{
    s->person = 0;
    s->what_am_i_doing = EMPTY_STRING;
    s->username = EMPTY_STRING;
    s->working_conference = 0;
    s->session = 0;
    s->connection_time = NO_TIME;
    s->idle_time = 0;
}
Per Cederqvist's avatar
Per Cederqvist committed
528

529 530 531 532 533 534 535 536 537 538 539 540 541 542
/* Session_info_ident */

void
init_session_info_ident (Session_info_ident *s)
{
    s->person = 0;
    s->what_am_i_doing = EMPTY_STRING;
    s->username = EMPTY_STRING;
    s->ident_user = EMPTY_STRING;
    s->hostname = EMPTY_STRING;
    s->working_conference = 0;
    s->session = 0;
    s->connection_time = NO_TIME;
    s->idle_time = 0;
Per Cederqvist's avatar
Per Cederqvist committed
543 544
}

545
/* Text_stat */
546

547 548
Text_stat *
alloc_text_stat(void)
Per Cederqvist's avatar
Per Cederqvist committed
549
{
550
    Text_stat *t;
Per Cederqvist's avatar
Per Cederqvist committed
551

552 553 554 555 556
    text_stat_cnt++;
    
    t = smalloc(sizeof(Text_stat));
    init_text_stat(t);
    return t;
Per Cederqvist's avatar
Per Cederqvist committed
557 558
}

559 560 561 562 563
void
free_text_stat(Text_stat *t)
{
    if ( t == NULL )
	return;
564

565 566 567 568 569 570 571
    text_stat_cnt--;
    clear_text_stat(t);
    sfree(t);
}

void
clear_text_stat(Text_stat *t)
Per Cederqvist's avatar
Per Cederqvist committed
572 573 574
{
    int i;

575
    for ( i = 0; i < t->no_of_misc; i++ )
Per Cederqvist's avatar
Per Cederqvist committed
576
    {
577 578 579 580
	switch ( t->misc_items[ i ].type )
	{
	case recpt:
	case cc_recpt:
581
	case bcc_recpt:
582 583 584 585 586 587 588 589 590 591 592 593
	case comm_to:
	case comm_in:
	case footn_to:
	case footn_in:
	case loc_no:
	case rec_time:
	case sent_by:
	case sent_at:
	    /* No need to free anything for these. */
	    break;

	default:
594 595
	    restart_kom("clear_text_stat(): unknown enum info_type %d.",
			t->misc_items[ i ].type);
596
	}
Per Cederqvist's avatar
Per Cederqvist committed
597 598
    }

599
    sfree(t->misc_items);
David Byers's avatar
David Byers committed
600
    free_aux_item_list(&t->aux_item_list);
601
    init_text_stat(t);
Per Cederqvist's avatar
Per Cederqvist committed
602 603
}

604
Text_stat *
605
copy_text_stat(const Text_stat *t)
606
{
607
    Text_stat *c;
608

609
    c = alloc_text_stat();
610
    c->creation_time = t->creation_time;
611
    c->generation = t->generation;
612 613 614 615 616 617 618
    c->file_pos = t->file_pos;
    c->author = t->author;
    c->no_of_lines = t->no_of_lines;
    c->no_of_chars = t->no_of_chars;
    c->no_of_marks = t->no_of_marks;
    c->no_of_misc = t->no_of_misc;
    c->highest_aux = t->highest_aux;
619 620
    c->misc_items = smalloc(c->no_of_misc * sizeof(Misc_info));
    memcpy(c->misc_items, t->misc_items, c->no_of_misc * sizeof(Misc_info));
David Byers's avatar
David Byers committed
621 622
    copy_aux_item_list(&c->aux_item_list,
                       &t->aux_item_list);
623 624 625
    return c;
}

626 627
void
init_text_stat  (Text_stat *t)
Per Cederqvist's avatar
Per Cederqvist committed
628
{
629
    t->creation_time = NO_TIME;
630
    t->generation = 0;
631 632 633 634 635 636
    t->file_pos = 0;
    t->author = 0;
    t->no_of_lines = 0;
    t->no_of_chars = 0;
    t->no_of_marks = 0;
    t->no_of_misc = 0;
637
    t->highest_aux = 0;
638
    t->misc_items = NULL;
David Byers's avatar
David Byers committed
639
    init_aux_item_list(&t->aux_item_list);
Per Cederqvist's avatar
Per Cederqvist committed
640 641
}

642
/* struct tm */
643

644 645 646 647 648 649 650 651 652 653 654 655
void
init_struct_tm (struct tm *t)
{
    t->tm_sec = 0;
    t->tm_min = 0;
    t->tm_hour = 0;
    t->tm_mday = 0;
    t->tm_mon = 0;
    t->tm_year = 0;
    t->tm_wday = 0;
    t->tm_yday = 0;
    t->tm_isdst = 0;
656 657
}

658 659 660 661
/* Who_info */

void
init_who_info (Who_info *w)
662
{
663 664 665 666 667 668
    w->person = 0;
    w->what_am_i_doing = EMPTY_STRING;
    w->username = EMPTY_STRING;
    w->working_conference = 0;
    w->session_no = 0;
}
669

670 671 672 673 674 675 676 677 678 679 680 681
/* Who_info_ident */

void
init_who_info_ident (Who_info_ident *w)
{
    w->person = 0;
    w->what_am_i_doing = EMPTY_STRING;
    w->username = EMPTY_STRING;
    w->ident_user = EMPTY_STRING;
    w->hostname = EMPTY_STRING;
    w->working_conference = 0;
    w->session_no = 0;
682 683
}

684
/* Who_info_old */
685

686 687 688 689 690 691 692 693
void
init_who_info_old (Who_info_old *w)
{
    w->person = 0;
    w->what_am_i_doing = EMPTY_STRING;
    w->working_conference = 0;
}

694 695 696 697 698 699 700 701 702
/* Kom_info */

void
clear_info(Info *i)
{
    free_aux_item_list(&i->aux_item_list);
}


703 704 705 706 707 708 709 710 711 712
/* Aux_item_list */

void
free_aux_item_list(Aux_item_list *list)
{
    unsigned long i;

    if (list->items != NULL)
    {
        for (i = 0; i < list->length; i++)
David Byers's avatar
David Byers committed
713
            clear_aux_item(&list->items[i]);
714 715 716 717 718 719
    }
    list->length = 0;
    sfree(list->items);
    list->items = NULL;
}

720
static void
Per Cederqvist's avatar
Per Cederqvist committed
721 722
copy_aux_item_list(Aux_item_list *dest,
		   const Aux_item_list *src)
David Byers's avatar
David Byers committed
723 724 725
{
    unsigned long   i;

726
    dest->length = src->length;
David Byers's avatar
David Byers committed
727 728 729 730 731 732 733 734 735 736 737 738 739 740
    dest->items = smalloc(sizeof(Aux_item) * src->length);
    for (i = 0; i < src->length; i++)
    {
        copy_aux_item(&dest->items[i], &src->items[i]);
    }
}

void
init_aux_item_list(Aux_item_list *list)
{
    list->length = 0;
    list->items = NULL;
}

David Byers's avatar
David Byers committed
741 742 743 744 745 746 747 748 749
void
init_aux_item_link(Aux_item_link *dest)
{
    dest->target_type = NO_OBJECT_TYPE;
    dest->target_item = 0;
    dest->target_object.conf = 0;
    dest->target_object.text = 0;
}

David Byers's avatar
David Byers committed
750 751 752 753 754 755 756 757 758 759 760 761 762 763
void
init_aux_item_flags(Aux_item_flags *dest)
{
    dest->deleted = 0;
    dest->inherit = 0;
    dest->secret = 0;
    dest->hide_creator = 0;
    dest->dont_garb = 0;
    dest->reserved3 = 0;
    dest->reserved4 = 0;
    dest->reserved5 = 0;
}


David Byers's avatar
David Byers committed
764 765 766 767 768 769 770 771 772
void
init_aux_item(Aux_item *dest)
{
    dest->aux_no = 0;
    dest->creator = 0;
    dest->sent_at = 0;
    dest->inherit_limit = 0;
    dest->tag = 0;
    dest->data = EMPTY_STRING;
David Byers's avatar
David Byers committed
773
    init_aux_item_flags(&dest->flags);
David Byers's avatar
David Byers committed
774 775 776
    init_aux_item_link(&dest->linked_item);
}

David Byers's avatar
David Byers committed
777 778 779 780 781 782 783
void
clear_aux_item(Aux_item *item)
{
    s_clear(&item->data);
    init_aux_item(item);
}

David Byers's avatar
David Byers committed
784
void
785 786 787 788 789 790 791 792
copy_aux_item(Aux_item *dest, const Aux_item *src)
{
    dest->aux_no = src->aux_no;
    dest->creator = src->creator;
    dest->sent_at = src->sent_at;
    dest->flags = src->flags;
    dest->inherit_limit = src->inherit_limit;
    dest->tag = src->tag;
David Byers's avatar
David Byers committed
793 794
    dest->data = EMPTY_STRING;
    s_strcpy(&dest->data, src->data);
David Byers's avatar
David Byers committed
795
    dest->linked_item = src->linked_item;
David Byers's avatar
David Byers committed
796 797 798
}


799 800 801 802
/*
 * Other kind of functions 
 */
void
Per Cederqvist's avatar
Per Cederqvist committed
803 804
dump_alloc_counts(FILE *fp)
{
Per Cederqvist's avatar
Per Cederqvist committed
805 806 807
    fprintf(fp, "---memory.c:\n\tperson:          %d\n\tconference:      %d\n",
	    person_cnt, conference_cnt);
    fprintf(fp, "\ttext_stat:       %d\n", text_stat_cnt);
Per Cederqvist's avatar
Per Cederqvist committed
808
}