]> jfr.im git - irc/quakenet/newserv.git/blame - helpmod2/hconf.c
Small changes to parser/parser.c and Makefile.
[irc/quakenet/newserv.git] / helpmod2 / hconf.c
CommitLineData
c86edd1d
Q
1
2#include <stdio.h>
3#include <ctype.h>
4#include <string.h>
5#include <time.h>
6#include <unistd.h>
7
8#include "hconf.h"
9#include "helpmod.h"
10#include "hterm.h"
11
3a839281 12static int hconf_version;
c86edd1d
Q
13
14static void helpmod_line_fix(char **ptr)
15{
16 while (isspace(**ptr))
17 (*ptr)++;
18
19 if (strchr(*ptr, '\n') != NULL)
20 *strchr(*ptr, '\n') = '\0';
21
22 if (strchr(*ptr, '\r') != NULL)
23 *strchr(*ptr, '\r') = '\0';
24}
25
26
27int helpmod_config_read(const char *fname)
28{
29 FILE *in;
30 char buf[512], *ptr;
31
3a839281 32 /* Assume G 2.0 configuration */
33 hconf_version = HELPMOD_VERSION_2_0;
34
c86edd1d
Q
35 if ((in = fopen(fname,"rt")) == NULL)
36 return -1;
37
38 while (!feof(in))
39 {
40 ptr = (char*)buf;
41
42 fgets(buf, 512, in);
43 if (feof(in))
44 break;
45
46 helpmod_line_fix(&ptr);
47
48 /* support comments */
49 if (*ptr == '%')
50 continue;
51 if (!*ptr)
52 continue;
53
54 /* check what kind of a line it was */
3a839281 55 if (!strcmp(ptr, "version"))
56 { /* If no version is present, then the assumed G 2.0 version is used */
57 if (helpmod_config_read_version(in))
58 Error("helpmod", ERR_WARNING, "Reading of database entry 'version' failed");
59
60 if (hconf_version > HELPMOD_VERSION_INTERNAL)
61 Error("helpmod", ERR_WARNING, "Database version is higher than the current version");
62 }
63 else if (!strcmp(ptr, "channel"))
c86edd1d
Q
64 {
65 if (helpmod_config_read_channel(in))
66 Error("helpmod", ERR_WARNING, "Reading of database entry 'channel' failed");
67 }
68 else if (!strcmp(ptr, "account"))
69 {
70 if (helpmod_config_read_account(in))
71 Error("helpmod", ERR_WARNING, "Reading of database entry 'account' failed");
72 }
73 else if (!strcmp(ptr, "ban"))
74 {
75 if (helpmod_config_read_ban(in))
76 Error("helpmod", ERR_WARNING, "Reading of database entry 'ban' failed");
77 }
78 else if (!strcmp(ptr, "lamercontrol profile"))
79 {
80 if (helpmod_config_read_hlc_profile(in))
81 Error("helpmod", ERR_WARNING, "Reading of database entry 'lamercontrol_profile' failed");
82 }
83 else if (!strcmp(ptr, "term"))
84 {
85 if (helpmod_config_read_term(in, NULL))
86 Error("helpmod", ERR_WARNING, "Reading of database entry 'term' failed");
87 }
88 else if (!strcmp(ptr, "globals"))
89 {
90 if (helpmod_config_read_globals(in))
91 Error("helpmod", ERR_WARNING, "Reading of database entry 'globals' failed");
92 }
93 else if (!strcmp(ptr, "report"))
94 {
95 if (helpmod_config_read_report(in))
96 Error("helpmod", ERR_WARNING, "Reading of database entry 'report' failed");
97 }
98 else if (!strcmp(ptr, "ticket"))
99 {
100 if (helpmod_config_read_ticket(in))
101 Error("helpmod", ERR_WARNING, "Reading of database entry 'ticket' failed");
102 }
3a839281 103 else
c86edd1d
Q
104 Error("helpmod", ERR_WARNING, "Unknown database entry '%s'", ptr);
105 }
106
107 hchannels_match_accounts();
108
109 fclose(in);
110 return 0;
111}
112
113int helpmod_config_write(const char *fname)
114{
115 FILE *out;
c86edd1d
Q
116 time_t timer = time(NULL);
117
118 if ((out = fopen(fname,"wt")) == NULL)
119 return -1;
120
3a839281 121 fprintf(out, "%% G2 version %s database\n", HELPMOD_VERSION);
c86edd1d
Q
122 fprintf(out, "%% %s\n\n", asctime(localtime(&timer)));
123
124
3a839281 125 { /* version */
126 fprintf(out, "%% G internal version\n");
127 fprintf(out, "version\n");
128 helpmod_config_write_version(out);
129 }
130
131 { /* globals */
132
133 fprintf(out,"\n%% global variables\n");
134 fprintf(out,"%% hstat_cycle\n");
135 fprintf(out,"globals\n");
136 helpmod_config_write_globals(out);
137 }
138
c86edd1d
Q
139 { /* lamercontrol profiles */
140 hlc_profile *ptr = hlc_profiles;
141
142 fprintf(out,"%% lamercontrol profile structure:\n");
143 fprintf(out,"%% X (string):\n");
144 fprintf(out,"%% Y (string):\n");
145 fprintf(out,"%% Z (int):\n");
146
147 for(;ptr;ptr=ptr->next)
148 {
149 fprintf(out, "lamercontrol profile\n");
150 helpmod_config_write_hlc_profile(out, ptr);
151 }
152 }
153
154 { /* channels */
155 hchannel *ptr = hchannels;
156
157 fprintf(out,"\n%% channel structure:\n");
158 fprintf(out,"%% name (string):\n");
159 fprintf(out,"%% flags (integer):\n");
160 fprintf(out,"%% welcome message (string):\n");
161 fprintf(out,"%% lamercontrol profile (string):\n");
162
163 for(;ptr;ptr=ptr->next)
164 {
165 fprintf(out, "channel\n");
166 helpmod_config_write_channel(out, ptr);
167 }
168 }
169
170 fprintf(out,"\n");
171
172 { /* accounts */
173 haccount *ptr = haccounts;
174
175 fprintf(out,"\n%% account structure:\n");
176 fprintf(out,"%% name (string):\n");
177 fprintf(out,"%% level (integer):\n");
178
179 for(;ptr;ptr=ptr->next)
180 {
181 fprintf(out, "account\n");
182 helpmod_config_write_account(out, ptr);
183 }
184 }
185
186 fprintf(out,"\n");
187
188 { /* bans */
189 hban *ptr = hbans;
190
191 fprintf(out,"\n%% ban structure:\n");
192 fprintf(out,"%% banmask (string):\n");
193 fprintf(out,"%% reason (string):\n");
194 fprintf(out,"%% expiration (int):\n");
195
196 for(;ptr;ptr=ptr->next)
197 {
198 fprintf(out, "ban\n");
199 helpmod_config_write_ban(out, ptr);
200 }
201 }
202
203 { /* global terms */
204 hterm *ptr = hterms;
205
206 fprintf(out,"\n%% term structure:\n");
207 fprintf(out,"%% name (string):\n");
208 fprintf(out,"%% description (string):\n");
209
210 for(;ptr;ptr=ptr->next)
211 {
212 fprintf(out, "term\n");
213 helpmod_config_write_term(out, ptr);
214 }
215 }
216
217 { /* tickets */
218 hchannel *hchan;
219 hticket *htick;
220
221 fprintf(out, "\n%% ticket structure:\n");
222 fprintf(out, "%% channel (string)\n");
223 fprintf(out, "%% authname (string)\n");
224 fprintf(out, "%% expiration time (int)\n");
225
226 for (hchan = hchannels;hchan;hchan = hchan->next)
227 for (htick = hchan->htickets;htick;htick = htick->next)
228 {
229 fprintf(out, "ticket\n");
230 helpmod_config_write_ticket(out, htick, hchan);
231 }
232 }
233
234 { /* reports */
235 hchannel *hchan;
236
237 fprintf(out, "\n%% report structure:\n");
238 fprintf(out, "%% channel reported\n");
239 fprintf(out, "%% channel reported to\n");
240
241 for (hchan = hchannels;hchan;hchan = hchan->next)
242 {
243 if ((hchan->flags & H_REPORT) && hchannel_is_valid(hchan->report_to))
244 {
245 fprintf(out, "report\n");
246 helpmod_config_write_report(out, hchan);
247 }
248 }
249 }
250
c86edd1d
Q
251 fclose(out);
252
253 return 0;
254}
255
256int helpmod_config_read_channel(FILE *in)
257{
258 hchannel *hchan;
259
260 char buf[256],*ptr=(char*)buf;
261 int flags, entries, i;
262 /* name */
263 fgets(buf, 256, in);
264 if (feof(in))
265 return -1;
266 helpmod_line_fix(&ptr);
267
268 hchan = hchannel_add(ptr);
269 /* flags */
270 fgets((ptr = buf), 256, in);
271 if (feof(in))
272 return -1;
273 helpmod_line_fix(&ptr);
274
275 if (sscanf(ptr, "%x", (unsigned int*)&flags) != 1)
276 return -1;
277
278 hchan->flags = flags;
279 /* welcome message */
280 fgets((ptr = buf), 256, in);
281 if (feof(in))
282 return -1;
283 helpmod_line_fix(&ptr);
284
285 strcpy(hchan->welcome, ptr);
286
287 /* lamercontrol profile */
288 fgets((ptr = buf), 256, in);
289 if (feof(in))
290 return -1;
291 helpmod_line_fix(&ptr);
292
293 hchan->lc_profile = hlc_get(ptr);
294
295 /* censor entries for channel, a bit complex */
296 fgets((ptr = buf), 256, in);
297 if (feof(in))
298 return -1;
299
300 helpmod_line_fix(&ptr);
301
302 if (sscanf(ptr, "%d", &entries) != 1)
303 return -1;
304 for (i = 0;i<entries;i++)
305 {
3a839281 306 char buf2[512], *ptr2;
307 int type;
c86edd1d
Q
308
309 fgets((ptr = buf), 256, in);
3a839281 310 if (feof(in))
c86edd1d
Q
311 return -1;
312 helpmod_line_fix(&ptr);
313
3a839281 314 if (hconf_version >= HELPMOD_VERSION_2_10)
315 {
316 if (!sscanf(ptr, "%d", &type))
317 return -1;
318
319 fgets((ptr = buf), 256, in);
320 if (feof(in))
321 return -1;
322 helpmod_line_fix(&ptr);
323 }
324 else
325 type = HCENSOR_KICK;
326
c86edd1d
Q
327 fgets((ptr2 = buf2), 256, in);
328 if (feof(in))
329 return -1;
330 helpmod_line_fix(&ptr2);
331
3a839281 332 if (ptr2[0] == '\0')
333 ptr2 = NULL;
334
335 hcensor_add(&hchan->censor, ptr, ptr2, type);
c86edd1d
Q
336 }
337 /* channel specific hterms */
338 fgets((ptr = buf), 256, in);
339 if (feof(in))
340 return -1;
341
342 helpmod_line_fix(&ptr);
343
344 if (sscanf(ptr, "%d", &entries) != 1)
345 return -1;
346 for (i=0;i<entries;i++)
347 helpmod_config_read_term(in, &hchan->channel_hterms);
348
349 helpmod_config_read_chanstats(in, hchan->stats);
350
351 /* needs to be done here */
352 hchannel_mode_check(hchan);
353
354 return 0;
355}
356
357int helpmod_config_write_channel(FILE *out, hchannel *target)
358{
359 fprintf(out, "\t%s\n", hchannel_get_name(target));
360 fprintf(out, "\t%x\n", target->flags & 0x0FFFFFF);
361 fprintf(out, "\t%s\n", target->welcome);
362 if (target->lc_profile == NULL)
363 fprintf(out, "\t(null)\n");
364 else
365 fprintf(out, "\t%s\n", target->lc_profile->name->content);
366
367 fprintf(out, "\t%d %% censor\n", hcensor_count(target->censor));
368 {
369 hcensor *hcens = target->censor;
370 for (;hcens;hcens = hcens->next)
3a839281 371 {
372 fprintf(out, "\t\t%d\n", hcens->type);
c86edd1d 373 fprintf(out, "\t\t%s\n", hcens->pattern->content);
3a839281 374 fprintf(out, "\t\t%s\n", hcens->reason?hcens->reason->content:"");
c86edd1d
Q
375 }
376 }
377
378 fprintf(out, "\t%d %% terms\n", hterm_count(target->channel_hterms));
379 {
380 hterm *tmp = target->channel_hterms;
381 for (;tmp;tmp = tmp->next)
382 {
383 helpmod_config_write_term(out, tmp);
384 }
385 }
386
387 helpmod_config_write_chanstats(out, target->stats);
388
389 return 0;
390}
391
392
393int helpmod_config_read_account(FILE *in)
394{
395 haccount *hack;
396 int nstats;
397
398 char buf[256],*ptr=(char*)buf;
399 int flags, level;
400
401 fgets(ptr = buf, 256, in);
402 if (feof(in))
403 return -1;
404 helpmod_line_fix(&ptr);
405
406 hack = haccount_add(ptr, H_PEON);
407
408 fgets(ptr = buf, 256, in);
409 if (feof(in))
410 return -1;
411 helpmod_line_fix(&ptr);
412
413 if (sscanf(ptr, "%x %x", (unsigned int*)&level, (unsigned int*)&flags) != 2)
414 return -1;
415
416 hack->level = level;
417 hack->flags = flags;
418
419 fgets(ptr = buf, 256, in);
420 if (feof(in))
421 return -1;
422 helpmod_line_fix(&ptr);
423
424 if (sscanf(ptr, "%d", &nstats) != 1)
425 return -1;
426
427 while (nstats)
428 {
429 hstat_account *tmp = hack->stats;
430 hack->stats = (hstat_account*)malloc(sizeof(hstat_account));
431 hack->stats->next = tmp;
432 if (helpmod_config_read_stats(in, hack->stats) == -1)
433 return -1;
434 nstats--;
435 }
436
437 return 0;
438}
439
440int helpmod_config_write_account(FILE *out, haccount *target)
441{
442 hstat_account *tmp;
443 fprintf(out, "\t%s\n", target->name->content);
444 fprintf(out, "\t%x\t%x\n", target->level, target->flags);
445
446 fprintf(out, "\t%d %% statistics for this channel\n", hstat_account_count(target->stats));
447 for (tmp = target->stats;tmp;tmp = tmp->next)
448 helpmod_config_write_stats(out, tmp);
449
450 return 0;
451}
452
453int helpmod_config_read_ban(FILE *in)
454{
455 char buf1[512], buf2[512], buf3[512], *ptr1, *ptr2, *ptr3;
456 int tmp;
457
458 fgets(ptr1 = buf1, 256, in);
459 if (feof(in))
460 return -1;
461 helpmod_line_fix(&ptr1);
462
463 fgets(ptr2 = buf2, 256, in);
464 if (feof(in))
465 return -1;
466 helpmod_line_fix(&ptr2);
467
468 fgets(ptr3 = buf3, 256, in);
469 if (feof(in))
470 return -1;
471 helpmod_line_fix(&ptr3);
472
473 if (sscanf(ptr3, "%d", &tmp) != 1)
474 return -1;
475
476 hban_add(ptr1, ptr2, tmp, 0);
477
478 return 0;
479}
480
481int helpmod_config_write_ban(FILE *out, hban *hb)
482{
483 fprintf(out, "\t%s\n", bantostring(hb->real_ban));
484 fprintf(out, "\t%s\n", hb->reason?hb->reason->content:NULL);
3a839281 485 fprintf(out, "\t%u\n", (unsigned int)hb->expiration);
c86edd1d
Q
486 return 0;
487}
488
489int helpmod_config_read_hlc_profile(FILE *in)
490{
491 hlc_profile *hlc_prof;
492 int tmp[3];
493 float tmp_float;
494 char buf[256],*ptr=(char*)buf;
495
496 /* name */
497 fgets(ptr = buf, 256, in);
498 if (feof(in))
499 return -1;
500 helpmod_line_fix(&ptr);
501
502 if ((hlc_prof = hlc_add(ptr)) == NULL)
503 return -1;
504
505 /* caps */
506 fgets(ptr = buf, 256, in);
507 if (feof(in))
508 return -1;
509 helpmod_line_fix(&ptr);
510
511 if (sscanf(ptr, "%d %d", &tmp[0], &tmp[1]) != 2)
512 return -1;
513
514 hlc_prof->caps_max_percentage = tmp[0];
515 hlc_prof->caps_min_count = tmp[1];
516
517 /* repeating */
518 fgets(ptr = buf, 256, in);
519 if (feof(in))
520 return -1;
521 helpmod_line_fix(&ptr);
522
523 if (sscanf(ptr, "%d %d", &tmp[0], &tmp[1]) != 2)
524 return -1;
525
526 hlc_prof->repeats_max_count = tmp[0];
527 hlc_prof->repeats_min_length = tmp[1];
528
529 /* character / symbol repeat */
530 fgets(ptr = buf, 256, in);
531 if (feof(in))
532 return -1;
533 helpmod_line_fix(&ptr);
534
535 if (sscanf(ptr, "%d %d %d", &tmp[0], &tmp[1], &tmp[2]) != 3)
536 return -1;
537
538 hlc_prof->symbol_repeat_max_count = tmp[0];
539 hlc_prof->character_repeat_max_count = tmp[1];
540 hlc_prof->symbol_max_count = tmp[1];
541
542 /* flood, spam const, spam */
543 fgets(ptr = buf, 256, in);
544 if (feof(in))
545 return -1;
546 helpmod_line_fix(&ptr);
547
548 if (sscanf(ptr, "%d %f %d", &tmp[0], &tmp_float, &tmp[1]) != 3)
549 return -1;
550
551 hlc_prof->tolerance_flood = tmp[0];
552 hlc_prof->constant_spam = tmp_float;
553 hlc_prof->tolerance_spam = tmp[1];
554
555 /* tolerances */
556 fgets(ptr = buf, 256, in);
557 if (feof(in))
558 return -1;
559 helpmod_line_fix(&ptr);
560
561 if (sscanf(ptr, "%d %d %d", &tmp[0], &tmp[1], &tmp[2]) != 3)
562 return -1;
563
564 hlc_prof->tolerance_warn = tmp[0];
565 hlc_prof->tolerance_kick = tmp[1];
566 hlc_prof->tolerance_remove = tmp[2];
567
568 return 0;
569}
570
571/* we use extended buffers here */
572int helpmod_config_read_term(FILE *in, hterm** target)
573{
574 char buf1[2048], buf2[2048], *ptr1 = buf1, *ptr2 = buf2;
575
576 /* name */
577 fgets(buf1, 2048, in);
578 if (feof(in))
579 return -1;
580 helpmod_line_fix(&ptr1);
581
582 /* description */
583 fgets(buf2, 2048, in);
584 if (feof(in))
585 return -1;
586 helpmod_line_fix(&ptr2);
587
588 /* add to public domain */
589 hterm_add(target, ptr1, ptr2);
590
591 return 0;
592}
593
594int helpmod_config_write_term(FILE *out, hterm *htrm)
595{
596 fprintf(out, "\t%s\n", htrm->name->content);
597 fprintf(out, "\t%s\n", htrm->description->content);
598 return 0;
599}
600
601int helpmod_config_write_hlc_profile(FILE *out, hlc_profile *hlc_prof)
602{
603 fprintf(out, "\t%s\n", hlc_prof->name->content);
604 fprintf(out, "\t%d %d\n", hlc_prof->caps_max_percentage, hlc_prof->caps_min_count);
605 fprintf(out, "\t%d %d\n", hlc_prof->repeats_max_count, hlc_prof->repeats_min_length);
606 fprintf(out, "\t%d %d %d\n", hlc_prof->symbol_repeat_max_count, hlc_prof->character_repeat_max_count, hlc_prof->symbol_max_count);
607 fprintf(out, "\t%d %.3f %d\n", hlc_prof->tolerance_flood, hlc_prof->constant_spam, hlc_prof->tolerance_spam);
608 fprintf(out, "\t%d %d %d\n", hlc_prof->tolerance_warn, hlc_prof->tolerance_kick, hlc_prof->tolerance_remove);
609 return 0;
610}
611
612int helpmod_config_read_chanstats(FILE *in, hstat_channel *hs_chan)
613{
614 char buf[256],*ptr=(char*)buf;
615 int i;
616 hstat_channel_entry *entry;
617
618 for (i=0;i<17;i++)
619 {
620 fgets(ptr = buf, 256, in);
621 if (feof(in))
622 return -1;
623 helpmod_line_fix(&ptr);
624
625 if (i < 7) /* days */
626 entry = &hs_chan->week[(hstat_day() + i) % 7];
627 else /* weeks */
e908ecfa 628 entry = &hs_chan->longterm[(hstat_week() + (i-7)) % 10];
c86edd1d 629
3a839281 630 if (hconf_version < HELPMOD_VERSION_2_10)
631 {
632 if (sscanf(buf, "%d %d %d %d %d %d", &entry->time_spent, &entry->prime_time_spent, &entry->joins, &entry->queue_use, &entry->lines, &entry->words) != 6)
c86edd1d 633 return -1;
3a839281 634 }
635 else
636 {
637 if (sscanf(buf, "%d %d %d %d %d %d %d %d", &entry->active_time, &entry->staff_active_time, &entry->time_spent, &entry->prime_time_spent, &entry->joins, &entry->queue_use, &entry->lines, &entry->words) != 8)
638 return -1;
639 }
c86edd1d
Q
640 }
641 return 0;
642}
643
644int helpmod_config_write_chanstats(FILE *out, hstat_channel *hs_chan)
645{
646 int i;
647 hstat_channel_entry *entry;
648
649 for (i=0;i<17;i++)
650 {
651 if (i < 7) /* days */
652 entry = &hs_chan->week[(hstat_day() + i) % 7];
653 else /* weeks */
e908ecfa 654 entry = &hs_chan->longterm[(hstat_week() + (i-7)) % 10];
c86edd1d 655
3a839281 656 fprintf(out, "\t%d %d %d %d %d %d %d %d\n", entry->active_time, entry->staff_active_time, entry->time_spent, entry->prime_time_spent, entry->joins, entry->queue_use, entry->lines, entry->words);
c86edd1d
Q
657 }
658 return 0;
659}
660
661int helpmod_config_read_stats(FILE *in, hstat_account *hs_acc)
662{
663 char buf[256],*ptr=(char*)buf;
664 int i;
665 hstat_account_entry *entry;
666
667 fgets(ptr = buf, 256, in);
668 if (feof(in))
669 return -1;
670 helpmod_line_fix(&ptr);
671
672 hs_acc->hchan = hchannel_get_by_name(ptr);
673
674 if (hs_acc->hchan == NULL)
675 return -1;
676
677 for (i=0;i<17;i++)
678 {
679 fgets(ptr = buf, 256, in);
680 if (feof(in))
681 return -1;
682 helpmod_line_fix(&ptr);
683
684 if (i < 7) /* days */
685 entry = &hs_acc->week[(hstat_day() + i) % 7];
686 else /* weeks */
e908ecfa 687 entry = &hs_acc->longterm[(hstat_week() + (i-7)) % 10];
c86edd1d
Q
688
689 if (sscanf(buf, "%d %d %d %d", &entry->time_spent, &entry->prime_time_spent, &entry->lines, &entry->words) != 4)
690 return -1;
691 }
692 return 0;
693}
694
695int helpmod_config_write_stats(FILE *out, hstat_account *hs_acc)
696{
697 int i;
698 hstat_account_entry *entry;
699
700 fprintf(out, "\t%s\n", hchannel_get_name(hs_acc->hchan));
701
702 for (i=0;i<17;i++)
703 {
704 if (i < 7) /* days */
705 entry = &hs_acc->week[(hstat_day() + i) % 7];
706 else /* weeks */
e908ecfa 707 entry = &hs_acc->longterm[(hstat_week() + (i-7)) % 10];
c86edd1d
Q
708
709 fprintf(out, "\t%d %d %d %d\n", entry->time_spent, entry->prime_time_spent, entry->lines, entry->words);
710 }
711 return 0;
712}
713
714int helpmod_config_read_globals(FILE *in)
715{
716 char buf[256],*ptr=(char*)buf;
717
718 fgets(ptr = buf, 256, in);
719 if (feof(in))
720 return -1;
721 helpmod_line_fix(&ptr);
722
723 if (sscanf(ptr, "%d", &hstat_cycle) != 1)
724 return -1;
725
726 return 0;
727}
728
729int helpmod_config_write_globals(FILE *out)
730{
731 fprintf(out, "\t%d\n", hstat_cycle);
732 return 0;
733}
734
735int helpmod_config_read_report(FILE *in)
736{
737 char buf[256], *ptr=(char*)buf;
738 hchannel *tmp1, *tmp2;
739
740 fgets(ptr = buf, 256, in);
741 if (feof(in))
742 return -1;
743 helpmod_line_fix(&ptr);
744
745 tmp1 = hchannel_get_by_name(ptr);
746
747 fgets(ptr = buf, 256, in);
748 if (feof(in))
749 return -1;
750 helpmod_line_fix(&ptr);
751
752 tmp2 = hchannel_get_by_name(ptr);
753
754 if (hchannel_is_valid(tmp1) && hchannel_is_valid(tmp2))
755 tmp1->report_to = tmp2;
756
757 return 0;
758}
759
760int helpmod_config_write_report(FILE *out, hchannel *hchan)
761{
762 fprintf(out, "\t%s\n", hchannel_get_name(hchan));
763 fprintf(out, "\t%s\n", hchannel_get_name(hchan->report_to));
764 return 0;
765}
766
767int helpmod_config_read_ticket(FILE *in)
768{
769 char buf[256], buf2[256], buf3[64], *ptr=(char*)buf;
770 unsigned int tmp;
771
772 fgets(ptr = buf, 256, in);
773 if (feof(in))
774 return -1;
775 helpmod_line_fix(&ptr);
776
777 strcpy(buf2, ptr);
778
779 fgets(ptr = buf, 64, in);
780 if (feof(in))
781 return -1;
782 helpmod_line_fix(&ptr);
783
784 strcpy(buf3, ptr);
785
786 fgets(ptr = buf, 256, in);
787 if (feof(in))
788 return -1;
789 helpmod_line_fix(&ptr);
790
791 if (!sscanf(ptr, "%u", &tmp))
792 return -1;
793
794 if (tmp > time(NULL))
795 hticket_add(buf3, tmp, hchannel_get_by_name(buf2));
796
797 return 0;
798}
799
800int helpmod_config_write_ticket(FILE *out, hticket *htick, hchannel *hchan)
801{
802 fprintf(out, "\t%s\n", hchannel_get_name(hchan));
803 fprintf(out, "\t%s\n", htick->authname);
3a839281 804 fprintf(out, "\t%u\n", (unsigned int)htick->time_expiration);
805
806 return 0;
807}
808
809int helpmod_config_read_version(FILE *in)
810{
811 char buf[256], *ptr=(char*)buf;
812
813 fgets(ptr = buf, 256, in);
814 if (feof(in))
815 return -1;
816 helpmod_line_fix(&ptr);
817
818 if (sscanf(ptr, "%d", &hconf_version) != 1)
819 return -1;
820
821 return 0;
822}
823
824int helpmod_config_write_version(FILE *out)
825{
826 fprintf(out, "\t%d\n", HELPMOD_VERSION_INTERNAL);
c86edd1d
Q
827
828 return 0;
829}
830
831void helpmod_config_scheduled_events(void)
832{
833 rename(HELPMOD_DEFAULT_DB, HELPMOD_DEFAULT_DB".old");
834 helpmod_config_write(HELPMOD_DEFAULT_DB);
835}