File: mbl_rev.c

package info (click to toggle)
fbb 7.07-3
  • links: PTS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 5,244 kB
  • ctags: 8,123
  • sloc: ansic: 87,810; sh: 2,324; makefile: 297
file content (638 lines) | stat: -rw-r--r-- 10,563 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
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
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
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
632
633
634
635
636
637
638
   /****************************************************************
    Copyright (C) 1986-2000 by

    F6FBB - Jean-Paul ROUBELAT
    6, rue George Sand
    31120 - Roquettes - France
	jpr@f6fbb.org

    This program 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 2 of the License, or
    (at your option) any later version.

    This program 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 this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

    Parts of code have been taken from many other softwares.
    Thanks for the help.
    ****************************************************************/

#include <serv.h>

/*
 * Module MBL_REV.C
 */

#include "aff_stat.c"

#define REV_HOLD 100
typedef struct rev_list
{
	long hold[REV_HOLD];
	struct rev_list *next;
}
RevList;

static RevList *hold_list = NULL;
static int off_hlist = REV_HOLD;

static int longcmp (const void *a, const void *b)
{
	long la = *((long *) a);
	long lb = *((long *) b);

	if (la == lb)
		return (0);
	return (la < lb) ? -1 : 1;
}

static int exist_hold (long numero)
{
	char holdname[130];
	struct stat stat;

	hold_name (numero, holdname);
	return (stat (holdname, &stat) == 0);
}

void end_hold (void)
{
	int i;
	RevList *rptr = hold_list;
	RevList *prev = NULL;

	while (rptr)
	{
		for (i = 0; i < REV_HOLD; i++)
		{
			if (!exist_hold (rptr->hold[i]))
				rptr->hold[i] = 0L;
			if (rptr->hold[i] != 0L)
				break;
		}

		if (i == REV_HOLD)
		{
			/* Le bloc est vide, on relie les chainons valides et on le libere */
			if (prev)
			{
				/* Il y a un chainon avant */
				prev->next = rptr->next;
			}
			else
			{
				/* C'etait la tete de liste */
				hold_list = rptr->next;
			}

			/* Si le dernier bloc est libere, on prepare l'allocation d'un nouveau bloc */
			if (rptr->next == NULL)
				off_hlist = REV_HOLD;

			m_libere (rptr, sizeof (RevList));

			if (prev)
				rptr = prev->next;
			else
				rptr = hold_list;

		}
		else
		{
			prev = rptr;
			rptr = rptr->next;
		}
	}
}

int already_held (long numero)
{
	int i;
	RevList *rptr = hold_list;

	while (rptr)
	{
		for (i = 0; i < REV_HOLD; i++)
			if (rptr->hold[i] == numero)
				return 1;

		rptr = rptr->next;
	}
	return 0;
}

int delete_hold (long numero)
{
	int i;
	RevList *rptr = hold_list;

	while (rptr)
	{
		for (i = 0; i < REV_HOLD; i++)
		{
			if (rptr->hold[i] == numero)
			{
				rptr->hold[i] = 0L;
				return 1;
			}
		}
		rptr = rptr->next;
	}
	return 0;
}

void ajoute_hold (long numero)
{
	RevList *rptr = hold_list;

	if (already_held (numero))
		return;

	if (rptr)
	{
		/* Avance jusqu'au dernier maillon */
		while (rptr->next)
		{
			rptr = rptr->next;
		}
	}

	if (off_hlist == REV_HOLD)
	{
		RevList *ptmp;

		/* Ajoute un maillon a la liste */
		ptmp = m_alloue (sizeof (RevList));
		memset (ptmp, 0, sizeof (RevList));
		off_hlist = 0;
		if (rptr)
		{
			rptr->next = ptmp;
		}
		else
			hold_list = rptr = ptmp;
	}

	rptr->hold[off_hlist++] = numero;
}

void init_hold (void)
{
	int done;
	long num;
	int i;
	int nb;
	long *hold_nb;
	char path[130];
	struct ffblk ffblk;

	/* Cree ou remet la liste a jour. Les entrees non valides sont a 0 */
	end_hold ();

	sprintf (path, "%s*.HLD", MESSDIR);

	/* Chercher le nombre de messages held */
	nb = 0;
	done = findfirst (path, &ffblk, 0);
	while (!done)
	{
		++nb;
		done = findnext (&ffblk);
	}

	if (nb)
	{
		hold_nb = (long *) malloc (nb * sizeof (long));

		i = 0;

		/* Lire les noms de messages held */
		done = findfirst (path, &ffblk, 0);
		while (!done)
		{
			sscanf (ffblk.ff_name, "%lx", &num);
			hold_nb[i] = num;
			if (++i > nb)
				break;
			done = findnext (&ffblk);
		}

		/* Tri de la liste */
		qsort (hold_nb, nb, sizeof (long), longcmp);

		/* Insere les numeros tries dans la liste */
		for (i = 0; i < nb; i++)
			ajoute_hold (hold_nb[i]);

		free (hold_nb);
	}

	nb_hold = nb;
}

static int next_hold (void)
{
	int fd;
	int retour = 1;
	bullist lbul;
	char holdname[130];

	int i=0;
	RevList *rptr = hold_list;

	while (rptr)
	{
		for (i = 0; i < REV_HOLD; i++)
		{
			if (rptr->hold[i] > pvoie->l_hold)
			{
				pvoie->l_hold = rptr->hold[i];
				break;
			}
		}

		if (i != REV_HOLD)
			break;

		rptr = rptr->next;
	}

	if ((rptr == NULL) || (i == REV_HOLD))
	{
		/* Pas de message suivant */
		texte (T_MBL + 3);
		return retour;
	}

	hold_name (pvoie->l_hold, holdname);

	fd = open (holdname, O_RDONLY | O_BINARY);
	read (fd, &lbul, sizeof (bullist));
	close (fd);

	cr ();
	*ptmes = lbul;
	ptmes->numero = ++pvoie->temp1;

	entete_liste ();
	aff_status (ptmes);
	retour = 2;
	pvoie->messdate = ptmes->datesd;

	return (retour);
}


static int read_hold (int verbose)
{
	int nb;
	FILE *fptr;
	char chaine[256];
	char holdname[130];

	nb = 0;

	hold_name (pvoie->l_hold, holdname);

	if ((fptr = fopen (holdname, "rt")) != NULL)
	{
		fseek (fptr, pvoie->enrcur, 0);
		if (!verbose)
		{
			pvoie->enrcur = supp_header (fptr, 1);
			fseek (fptr, pvoie->enrcur, 0);
		}
		fflush (fptr);
		while ((nb = read (fileno (fptr), chaine, 250)) > 0)
		{
			outs (chaine, nb);
			if (pvoie->memoc >= MAXMEM)
			{
				/*        if (!getvoie(CONSOLE]->connect) cprintf("Max atteint\r\n") ; */
				pvoie->enrcur = ftell (fptr);
				break;
			}
		}
		ferme (fptr, 45);
	}
	else
		return (-1);

	return (nb);
}

void list_held (void)
{
	char holdname[130];
	int fd;
	bullist lbul;
	int premier = 1;
	int i;
	RevList *rptr;

	init_hold ();

	rptr = hold_list;

	while (rptr)
	{
		for (i = 0; i < REV_HOLD; i++)
		{
			if (rptr->hold[i])
			{
				hold_name (rptr->hold[i], holdname);

				fd = open (holdname, O_RDONLY | O_BINARY);
				read (fd, &lbul, sizeof (bullist));
				close (fd);

				*ptmes = lbul;
				ptmes->numero = pvoie->temp1 + 1;

				if (premier)
				{
					premier = 0;
					entete_liste ();
				}
				aff_status (ptmes);

				++pvoie->temp1;
			}
		}
		rptr = rptr->next;
	}

	if (premier)
		texte (T_MBL + 3);
}

static void hold_question (void)
{
	texte (T_MBL + 58);
}

int review (void)
{
	int orig;
	int dest;
	int local = 0;
	int verbose = 0;

	int error = 0;
	long numess;
	char holdname[130];
	char messname[130];

	switch (pvoie->niv3)
	{
	case 0:
		init_hold ();
		pvoie->l_hold = 0L;
		pvoie->temp1 = 0;
		switch (next_hold ())
		{
		case 0:
			ch_niv3 (1);
			break;
		case 1:
			retour_mbl ();
			break;
		case 2:
			hold_question ();
			ch_niv3 (2);
			break;
		}
		break;
	case 1:
		switch (next_hold ())
		{
		case 0:
			break;
		case 1:
			retour_mbl ();
			break;
		case 2:
			hold_question ();
			ch_niv3 (2);
			break;
		}
		break;
	case 2:
		while_space ();

		switch (toupper (*indd))
		{
		case 'V':
			verbose = 1;
		case 'R':
			/* Lire le message held */
			pvoie->sr_mem = 0;
			pvoie->enrcur = 256L;

			switch (read_hold (verbose))
			{
			case 0:
				pvoie->sr_mem = 0;
				hold_question ();
				ch_niv3 (2);
				break;
			case -1:
				retour_mbl ();
				break;
			default:
				ch_niv3 (3);
				break;
			}

			/*
			   indd = data;
			   sprintf(data, "%ld", ptmes->numero);
			   list_read(verbose);
			   if (mbl_mess_read() == 0) {
			   pvoie->sr_mem = 0;
			   hold_question();
			   ch_niv3(2);
			   }
			   else
			   ch_niv3(3);
			 */
			break;
		case 'A':
		case 'K':
		case 'D':
			unlink (hold_name (pvoie->l_hold, holdname));
			delete_hold (pvoie->l_hold);
			--nb_hold;
			aff_msg_cons ();
			switch (next_hold ())
			{
			case 0:
				ch_niv3 (1);
				break;
			case 1:
				retour_mbl ();
				break;
			case 2:
				hold_question ();
				ch_niv3 (2);
				break;
			}
			break;
		case 'L':
			local = 1;
		case 'U':
			/* Unhold */

			*(pvoie->appendf) = '\0';
			*(pvoie->mess_bid) = '\0';

			ptmes->numero = 0L;
			ptmes->theme = 0;

			pvoie->chck = 0;
			pvoie->m_ack = 0;
			pvoie->messdate = time (NULL);
			pvoie->mess_num = -1;

			if ((ptmes->type == 'B') || ((ptmes->type == 'P') && (strcmp (ptmes->desti, "SYSOP") == 0)))
			{
				if (*(ptmes->bbsv))
					ptmes->status = '$';
				else
					ptmes->status = 'N';
			}
			else
				ptmes->status = 'N';

			/* Copier le fichier avec un nouveau No de message */
			hold_name (pvoie->l_hold, holdname);

			orig = open (holdname, O_RDONLY | O_BINARY);
			if (orig < 0)
			{
				retour_mbl ();
				break;
			}

			/* Saute le header */
			lseek (orig, (long) sizeof (bullist), SEEK_SET);

			/* Lit le home-bbs */
			fbb_read (orig, pvoie->mess_home, sizeof (pvoie->mess_home));
			pvoie->mess_home[sizeof (pvoie->mess_home) - 1] = '\0';

			/* Debut du texte */
			lseek (orig, 256L, SEEK_SET);

			/* Cree un nouveau message */
			numess = ptmes->numero = next_num ();
			mess_name (MESSDIR, ptmes->numero, messname);
			dest = open (messname, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, S_IREAD | S_IWRITE);
			if (dest < 0)
			{
				close (orig);
				retour_mbl ();
				break;
			}

			copy_fic (orig, dest, NULL);

			close (orig);
			close (dest);

			unlink (holdname);
			delete_hold (pvoie->l_hold);
			--nb_hold;

			put_mess_fwd ('H');
			if (local)
			{
				/* Pas de forwarding ... */
				int i;

				for (i = 0; i < NBMASK; i++)
				{
					ptmes->forw[i] = 0xff;
					ptmes->fbbs[i] = '\0';
				}
				maj_rec (ptmes->numero, ptmes);
				clear_fwd (ptmes->numero);
				/* Supprimer le via */
				ptmes->bbsv[0] = '\0';
			}

			tst_sysop (ptmes->desti, numess);
			tst_serveur (ptmes);
			tst_ack (ptmes);
			tst_warning (ptmes);


			aff_msg_cons ();
			cr ();


			switch (next_hold ())
			{
			case 0:
				ch_niv3 (1);
				break;
			case 1:
				retour_mbl ();
				break;
			case 2:
				hold_question ();
				ch_niv3 (2);
				break;
			default:
				break;
			}
			break;
		case '\0':
			switch (next_hold ())
			{
			case 0:
				ch_niv3 (1);
				break;
			case 1:
				retour_mbl ();
				break;
			case 2:
				hold_question ();
				ch_niv3 (2);
				break;
			}
			break;
		case 'Q':
			retour_mbl ();
			break;
		default:
			hold_question ();
			break;
		}
		break;
	case 3:
		switch (read_hold (1))
		{
		case 0:
			pvoie->sr_mem = 0;
			hold_question ();
			ch_niv3 (2);
			break;
		case -1:
			retour_mbl ();
			break;
		}
		break;
	default:
		fbb_error (ERR_NIVEAU, "REVIEW", pvoie->niv3);
	}

	return (error);
}