forked from g8bpq/OldLinBPQ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MailRouting.c
1754 lines (1365 loc) · 40.7 KB
/
MailRouting.c
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
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
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
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
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
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Copyright 2001-2015 John Wiseman G8BPQ
This file is part of LinBPQ/BPQ32.
LinBPQ/BPQ32 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 3 of the License, or
(at your option) any later version.
LinBPQ/BPQ32 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 LinBPQ/BPQ32. If not, see http://www.gnu.org/licenses
*/
// Mail and Chat Server for BPQ32 Packet Switch
//
// Message Routing Module
// This code decides where to send a message.
// Private messages are routed by TO and AT if possible, if not they follow the Bull Rules
// Bulls are routed on HA where possible
// Bulls should not be distributed outside their designated area.
#include "BPQMail.h"
char WW[] = "WW";
char * MyElements[20] = {WW}; // My HA in element format
char MyRouteElements[100];
int MyElementCount;
BOOL ReaddressLocal;
BOOL ReaddressReceived;
BOOL WarnNoRoute = TRUE;
BOOL Localtime = FALSE; // Use Local Time for Timebands and forward connect scripts
struct ALIAS * CheckForNTSAlias(struct MsgInfo * Msg, char * FirstDestElement);
struct UserInfo * FindAMPR();
struct Continent
{
char FourCharCode[5];
char TwoCharCode[3];
};
struct Country
{
char Country[5];
char Continent4[5];
char Continent2[3];
};
struct Continent Continents[] =
{
"EURO", "EU", // Europe
"MEDR", "EU", // Mediterranean
"ASIA", "AS", // The Orient
"INDI", "AS", // Indian Ocean including the Indian subcontinent
"MDLE", "EU", // Middle East
"SEAS", "EU", // South-East Asia
"NOAM", "NA", // North America (Canada, USA, Mexico)
"CEAM", "NA", // Central America
"CARB", "NA", // Caribbean
"SOAM", "SA", // South America
"AUNZ", "OC", // Australia/New Zealand
"EPAC", "OC", // Eastern Pacific
"NPAC", "OC", // Northern Pacific
"SPAC", "OC", // Southern Pacific
"WPAC", "OC", // Western Pacific
"NAFR", "AF", // Northern Africa
"CAFR", "AF", // Central Africa
"SAFR", "AF", // Southern Africa
"ANTR", "OC", // Antarctica
};
struct Country Countries[] =
{
"AFG", "****", "AS", // Afghanistan
"ALA", "EURO", "EU", // Åland Islands
"ALB", "EURO", "EU", // Albania
"DZA", "NAFR", "AF", // Algeria
"ASM", "****", "AS", // American Samoa
"AND", "EURO", "EU", // Andorra
"AGO", "CAFR", "AF", // Angola
"AIA", "CARB", "NA", // Anguilla
"ATG", "CARB", "NA", // Antigua and Barbuda
"ARG", "SOAM", "SA", // Argentina
"ARM", "****", "AS", // Armenia
"ABW", "CARB", "NA", // Aruba
"AUS", "AUNZ", "OC", // Australia
"AUT", "EURO", "EU", // Austria
"AZE", "****", "AS", // Azerbaijan
"BHS", "CARB", "NA", // Bahamas
"BHR", "MDLE", "AS", // Bahrain
"BGD", "INDE", "AS", // Bangladesh
"BRB", "CARB", "NA", // Barbados
"BLR", "EURO", "EU", // Belarus
"BEL", "EURO", "EU", // Belgium
"BLZ", "CEAM", "NA", // Belize
"BEN", "CAFR", "AF", // Benin
"BMU", "CARB", "NA", // Bermuda
"BTN", "ASIA", "AS", // Bhutan
"BOL", "SOAM", "SA", // Bolivia (Plurinational State of)
"BIH", "EURO", "EU", // Bosnia and Herzegovina
"BWA", "****", "AF", // Botswana
"BRA", "****", "SA", // Brazil
"VGB", "CARB", "NA", // British Virgin Islands
"BRN", "ASIA", "AS", // Brunei Darussalam
"BGR", "EURO", "EU", // Bulgaria
"BFA", "CAFR", "AF", // Burkina Faso
"BDI", "CAFR", "AF", // Burundi
"KHM", "****", "AS", // Cambodia
"CMR", "CAFR", "AF", // Cameroon
"CAN", "NOAM", "NA", // Canada
"CPV", "NAFR", "AF", // Cape Verde
"CYM", "CARB", "NA", // Cayman Islands
"CAF", "CAFR", "AF", // Central African Republic
"TCD", "CAFR", "AF", // Chad
"CHL", "SOAM", "SA", // Chile
"CHN", "****", "AS", // China
"HKG", "****", "AS", // Hong Kong Special Administrative Region of China
"MAC", "****", "AS", // Macao Special Administrative Region of China
"COL", "****", "SA", // Colombia
"COM", "SAFR", "AF", // Comoros
"COG", "****", "AF", // Congo
"COK", "SPAC", "OC", // Cook Islands
"CRI", "CEAM", "NA", // Costa Rica
"CIV", "CAFR", "AF", // Côte d'Ivoire
"HRV", "EURO", "EU", // Croatia
"CUB", "CARB", "NA", // Cuba
"CYP", "EURO", "EU", // Cyprus
"CZE", "EURO", "EU", // Czech Republic
"PRK", "****", "AS", // Democratic People's Republic of Korea
"COD", "****", "AF", // Democratic Republic of the Congo
"DNK", "EURO", "EU", // Denmark
"DJI", "NAFR", "AF", // Djibouti
"DMA", "CARB", "NA", // Dominica
"DOM", "CARB", "NA", // Dominican Republic
"ECU", "SOAM", "SA", // Ecuador
"EGY", "MDLE", "AF", // Egypt
"SLV", "CEAM", "NA", // El Salvador
"GNQ", "CAFR", "AF", // Equatorial Guinea
"ERI", "****", "AF", // Eritrea
"EST", "EURO", "EU", // Estonia
"ETH", "****", "AF", // Ethiopia
"FRO", "EURO", "EU", // Faeroe Islands
"FLK", "****", "SA", // Falkland Islands (Malvinas)
"FJI", "SPAC", "OC", // Fiji
"FIN", "EURO", "EU", // Finland
"FRA", "EURO", "EU", // France
"GUF", "SOAM", "SA", // French Guiana
"PYF", "SPAC", "OC", // French Polynesia
"GAB", "CAFR", "AF", // Gabon
"GMB", "CAFR", "AF", // Gambia
"GEO", "ASIA", "AS", // Georgia
"DEU", "EURO", "EU", // Germany
"GHA", "CAFR", "AF", // Ghana
"GIB", "EURO", "EU", // Gibraltar
"GRC", "EURO", "EU", // Greece
"GRL", "EURO", "EU", // Greenland
"GRD", "CARB", "NA", // Grenada
"GLP", "CARB", "NA", // Guadeloupe
"GUM", "SPAC", "OC", // Guam
"GTM", "CEAM", "NA", // Guatemala
"GGY", "EURO", "EU", // Guernsey
"GIN", "CAFR", "AF", // Guinea
"GNB", "CAFR", "AF", // Guinea-Bissau
"GUY", "SOAM", "SA", // Guyana
"HTI", "CARB", "NA", // Haiti
"VAT", "EURO", "EU", // Holy See
"HND", "CEAM", "NA", // Honduras
"HUN", "EURO", "EU", // Hungary
"ISL", "EURO", "EU", // Iceland
"IND", "INDI", "AS", // India
"IDN", "****", "AS", // Indonesia
"IRN", "MDLE", "AS", // Iran (Islamic Republic of)
"IRQ", "MDLE", "AS", // Iraq
"IRL", "EURO", "EU", // Ireland
"IMN", "EURO", "EU", // Isle of Man
"ISR", "MDLE", "AS", // Israel
"ITA", "EURO", "EU", // Italy
"JAM", "****", "NA", // Jamaica
"JPN", "****", "AS", // Japan
"JEY", "EURO", "EU", // Jersey
"JOR", "MDLE", "AS", // Jordan
"KAZ", "****", "AS", // Kazakhstan
"KEN", "****", "AF", // Kenya
"KIR", "EPAC", "OC", // Kiribati
"KWT", "MDLE", "AS", // Kuwait
"KGZ", "ASIA", "AS", // Kyrgyzstan
"LAO", "ASIA", "AS", // Lao People's Democratic Republic
"LVA", "EURO", "EU", // Latvia
"LBN", "MDLE", "AS", // Lebanon
"LSO", "SAFR", "AF", // Lesotho
"LBR", "CAFR", "AF", // Liberia
"LBY", "MDLE", "AS", // Libyan Arab Jamahiriya
"LIE", "EURO", "EU", // Liechtenstein
"LTU", "EURO", "EU", // Lithuania
"LUX", "EURO", "EU", // Luxembourg
"MDG", "SAFR", "AF", // Madagascar
"MWI", "SAFR", "AF", // Malawi
"MYS", "ASIA", "AS", // Malaysia
"MDV", "INDI", "AS", // Maldives
"MLI", "CAFR", "AF", // Mali
"MLT", "EURO", "EU", // Malta
"MHL", "WPAC", "OC", // Marshall Islands
"MTQ", "CARB", "NA", // Martinique
"MRT", "NAFR", "AF", // Mauritania
"MUS", "SAFR", "AF", // Mauritius
"MYT", "SAFR", "AF", // Mayotte
"MEX", "****", "NA", // Mexico
"FSM", "WPAC", "OC", // Micronesia (Federated States of)
"MCO", "EURO", "EU", // Monaco
"MNG", "****", "AS", // Mongolia
"MNE", "EURO", "EU", // Montenegro
"MSR", "CARB", "NA", // Montserrat
"MAR", "NAFR", "AF", // Morocco
"MOZ", "SAFR", "AF", // Mozambique
"MMR", "ASIA", "AS", // Myanmar
"NAM", "****", "AF", // Namibia
"NRU", "WPAC", "OC", // Nauru
"NPL", "****", "AS", // Nepal
"NLD", "EURO", "EU", // Netherlands
"ANT", "CARB", "NA", // Netherlands Antilles
"NCL", "SPAC", "OC", // New Caledonia
"NZL", "AUNZ", "OC", // New Zealand
"NIC", "****", "SA", // Nicaragua
"NER", "NAFR", "AF", // Niger
"NGA", "****", "AF", // Nigeria
"NIU", "SPAC", "OC", // Niue
"NFK", "SPAC", "OC", // Norfolk Island
"MNP", "WPAC", "OC", // Northern Mariana Islands
"NOR", "EURO", "EU", // Norway
"PSE", "MDLE", "AS", // Occupied Palestinian Territory
"OMN", "MDLE", "AS", // Oman
"PAK", "INDI", "AS", // Pakistan
"PLW", "SPAC", "OC", // Palau
"PAN", "CEAM", "SA", // Panama
"PNG", "SPAC", "OC", // Papua New Guinea
"PRY", "SOAM", "SA", // Paraguay
"PER", "SOAM", "SA", // Peru
"PHL", "ASIA", "AS", // Philippines
"PCN", "SPAC", "OC", // Pitcairn
"POL", "EURO", "EU", // Poland
"PRT", "EURO", "EU", // Portugal
"PRI", "CARB", "NA", // Puerto Rico
"QAT", "MDLE", "AS", // Qatar
"KOR", "ASIA", "AS", // Republic of Korea
"MDA", "EURO", "EU", // Republic of Moldova
"REU", "SAFR", "AF", // Réunion
"ROU", "EURO", "EU", // Romania
"RUS", "ASIA", "AS", // Russian Federation
"RWA", "****", "AF", // Rwanda
"BLM", "CARB", "NA", // Saint-Barthélemy
"SHN", "SOAM", "SA", // Saint Helena
"KNA", "CARB", "NA", // Saint Kitts and Nevis
"LCA", "CARB", "NA", // Saint Lucia
"MAF", "CARB", "NA", // Saint-Martin (French part)
"SPM", "NOAM", "NA", // Saint Pierre and Miquelon
"VCT", "CARB", "NA", // Saint Vincent and the Grenadines
"WSM", "SPAC", "OC", // Samoa
"SMR", "EURO", "EU", // San Marino
"STP", "CAFR", "AF", // Sao Tome and Principe
"SAU", "MDLE", "AS", // Saudi Arabia
"SEN", "CAFR", "AF", // Senegal
"SRB", "EURO", "EU", // Serbia
"SYC", "SAFR", "AF", // Seychelles
"SLE", "****", "AF", // Sierra Leone
"SGP", "****", "AS", // Singapore
"SVK", "EURO", "EU", // Slovakia
"SVN", "EURO", "EU", // Slovenia
"SLB", "SPAC", "OC", // Solomon Islands
"SOM", "****", "AF", // Somalia
"ZAF", "SAFR", "AF", // South Africa
"ESP", "EURO", "EU", // Spain
"LKA", "INDE", "AS", // Sri Lanka
"SDN", "****", "AF", // Sudan
"SUR", "SOAM", "SA", // Suriname
"SJM", "EURO", "EU", // Svalbard and Jan Mayen Islands
"SWZ", "****", "AF", // Swaziland
"SWE", "EURO", "EU", // Sweden
"CHE", "EURO", "EU", // Switzerland
"SYR", "MDLE", "AS", // Syrian Arab Republic
"TJK", "ASIA", "AS", // Tajikistan
"THA", "****", "AS", // Thailand
"MKD", "EURO", "EU", // The former Yugoslav Republic of Macedonia
"TLS", "ASIA", "AS", // Timor-Leste
"TGO", "CAFR", "AF", // Togo
"TKL", "AUNZ", "OC", // Tokelau
"TON", "SPAC", "OC", // Tonga
"TTO", "CARB", "NA", // Trinidad and Tobago
"TUN", "****", "AF", // Tunisia
"TUR", "EURO", "EU", // Turkey
"TKM", "****", "AS", // Turkmenistan
"TCA", "CARB", "NA", // Turks and Caicos Islands
"TUV", "SPAC", "OC", // Tuvalu
"UGA", "****", "AF", // Uganda
"UKR", "EURO", "EU", // Ukraine
"ARE", "MDLE", "AS", // United Arab Emirates
"GBR", "EURO", "EU", // United Kingdom of Great Britain and Northern Ireland
"TZA", "****", "AF", // United Republic of Tanzania
"USA", "NOAM", "NA", // United States of America
"VIR", "CARB", "NA", // United States Virgin Islands
"URY", "SOAM", "SA", // Uruguay
"UZB", "ASIA", "AS", // Uzbekistan
"VUT", "SPAC", "OC", // Vanuatu
"VEN", "SOAM", "SA", // Venezuela (Bolivarian Republic of)
"VNM", "****", "AS", // Viet Nam
"WLF", "SPAC", "OC", // Wallis and Futuna Islands
"ESH", "****", "AF", // Western Sahara
"YEM", "****", "AF", // Yemen
"ZMB", "SAFR", "AF", // Zambia
"ZWE", "SAFR", "AF" // Zimbabwe
};
char ** AliasText;
struct ALIAS ** Aliases;
struct ALIAS ** NTSAliases = NULL;
/*struct ALIAS Aliases[] =
{
"AMSAT", "WW",
"USBBS", "USA",
"ALLUS", "USA"};
*/
int NumberofContinents = sizeof(Continents)/sizeof(Continents[1]);
int NumberofCountries = sizeof(Countries)/sizeof(Countries[1]);
struct Continent * FindContinent(char * Name)
{
int i;
struct Continent * Cont;
for(i=0; i< NumberofContinents; i++)
{
Cont = &Continents[i];
if ((_stricmp(Name, Cont->FourCharCode) == 0) || (_stricmp(Name, Cont->TwoCharCode) == 0))
return Cont;
}
return NULL;
}
struct Country * FindCountry(char * Name)
{
int i;
struct Country * Cont;
for(i=0; i< NumberofCountries; i++)
{
Cont = &Countries[i];
if (_stricmp(Name, Cont->Country) == 0)
return Cont;
}
return NULL;
}
struct ALIAS * FindAlias(char * Name)
{
struct ALIAS ** Alias;
Alias = Aliases;
while(Alias[0])
{
if (_stricmp(Name, Alias[0]->Dest) == 0)
return Alias[0];
Alias++;
}
return NULL;
}
VOID SetupMyHA()
{
int Elements = 1; // Implied WW on front
char * ptr2;
struct Continent * Continent;
strcpy(MyRouteElements, HRoute);
// Split it up
ptr2 = MyRouteElements + strlen(MyRouteElements) - 1;
do
{
while ((*ptr2 != '.') && (ptr2 > MyRouteElements))
{
ptr2 --;
}
if (ptr2 == MyRouteElements)
{
// End
MyElements[Elements++] = _strdup(ptr2);
break;
}
MyElements[Elements++] = _strdup(ptr2+1);
*ptr2 = 0;
} while(Elements < 20); // Just in case!
MyElements[Elements++] = _strdup(BBSName);
MyElementCount = Elements;
if (MyElements[1])
{
if (strlen(MyElements[1]) == 4)
{
// Convert to 2 char Continent;
Continent = FindContinent(MyElements[1]);
if (Continent)
{
free(MyElements[1]);
MyElements[1] = _strdup(Continent->TwoCharCode);
}
}
}
}
VOID SetupNTSAliases(char * FN)
{
FILE *in;
char Buffer[2048];
char *buf = Buffer;
int Count = 0;
char seps[] = " ,:/\t";
char * Dest, * Alias, * Context;
NTSAliases = zalloc(sizeof(struct ALIAS));
in = fopen(FN, "r");
if (in)
{
while(fgets(buf, 128, in))
{
strlop(buf, '\n');
strlop(buf, '\r'); // in case Windows Format
Dest = _strdup(buf); // strtok changes it
Dest = strtok_s(Dest, seps, &Context);
if (Dest == NULL)
continue;
Alias = strtok_s(NULL, seps, &Context);
if (Alias == NULL)
continue;
if (strlen(Dest) < 3 && (strchr(Dest, '*') == 0))
continue;
NTSAliases = realloc(NTSAliases, (Count+2)* sizeof(struct ALIAS));
NTSAliases[Count] = zalloc(sizeof(struct ALIAS));
NTSAliases[Count]->Dest = Dest;
NTSAliases[Count]->Alias = Alias;
Count++;
}
NTSAliases[Count] = NULL;
fclose(in);
}
}
VOID SetupFwdAliases()
{
char ** Text = AliasText;
char * Dest, * Alias;
int Count = 0;
char seps[] = " ,:/";
Aliases = zalloc(sizeof(struct ALIAS));
if (Text)
{
while(Text[0])
{
Aliases = realloc(Aliases, (Count+2)* sizeof(struct ALIAS));
Aliases[Count] = zalloc(sizeof(struct ALIAS));
Dest = _strdup(Text[0]); // strtok changes it
Dest = strtok_s(Dest, seps, &Alias);
Aliases[Count]->Dest = Dest;
Aliases[Count]->Alias = Alias;
Count++;
Text++;
}
Aliases[Count] = NULL;
}
}
VOID SetupHAElements(struct BBSForwardingInfo * ForwardingInfo)
{
char * HText = ForwardingInfo->BBSHA;
char * SaveHText, * ptr2;
struct Continent * Continent;
int Elements = 1;
ForwardingInfo->BBSHAElements = zalloc(8); // always NULL entry on end even if no values
SaveHText = _strdup(HText);
ptr2 = SaveHText + strlen(SaveHText) -1;
ForwardingInfo->BBSHAElements[0] = _strdup(WW);
do
{
ForwardingInfo->BBSHAElements = realloc(ForwardingInfo->BBSHAElements, (Elements+2)*4);
while ((*ptr2 != '.') && (ptr2 > SaveHText))
{
ptr2 --;
}
if (ptr2 == SaveHText)
{
// End
ForwardingInfo->BBSHAElements[Elements++] = _strdup(ptr2);
break;
}
ForwardingInfo->BBSHAElements[Elements++] = _strdup(ptr2+1);
*ptr2 = 0;
} while(TRUE);
ForwardingInfo->BBSHAElements[Elements++] = NULL;
if (ForwardingInfo->BBSHAElements[1])
{
if (strlen(ForwardingInfo->BBSHAElements[1]) == 4)
{
// Convert to 2 char Continent;
Continent = FindContinent(ForwardingInfo->BBSHAElements[1]);
if (Continent)
{
free(ForwardingInfo->BBSHAElements[1]);
ForwardingInfo->BBSHAElements[1] = _strdup(Continent->TwoCharCode);
}
}
}
free(SaveHText);
}
VOID SetupHAddreses(struct BBSForwardingInfo * ForwardingInfo)
{
int Count=0;
char ** HText = ForwardingInfo->Haddresses;
char * SaveHText, * ptr2;
// char * TopElement;
char * Num;
struct Continent * Continent;
ForwardingInfo->HADDRS = zalloc(4); // always NULL entry on end even if no values
ForwardingInfo->HADDROffet = zalloc(4); // always NULL entry on end even if no values
while(HText[0])
{
int Elements = 1;
ForwardingInfo->HADDRS = realloc(ForwardingInfo->HADDRS, (Count+2)*4);
ForwardingInfo->HADDROffet = realloc(ForwardingInfo->HADDROffet, (Count+2)*4);
ForwardingInfo->HADDRS[Count] = zalloc(8); // Always at lesat WWW and NULL
SaveHText = _strdup(HText[0]);
Num = strlop(SaveHText, ',');
ptr2 = SaveHText + strlen(SaveHText) -1;
ForwardingInfo->HADDRS[Count][0] = _strdup(WW);
if (strcmp(HText[0], "WW") != 0)
{
do
{
ForwardingInfo->HADDRS[Count] = realloc(ForwardingInfo->HADDRS[Count], (Elements+2)*4);
while ((*ptr2 != '.') && (ptr2 > SaveHText))
{
ptr2 --;
}
if (ptr2 == SaveHText)
{
// End
ForwardingInfo->HADDRS[Count][Elements++] = _strdup(ptr2);
break;
}
ForwardingInfo->HADDRS[Count][Elements++] = _strdup(ptr2+1);
*ptr2 = 0;
} while(TRUE);
}
ForwardingInfo->HADDRS[Count][Elements++] = NULL;
// If the route is not a complete HR (ie starting with a continent)
// Add elemets from BBS HA to complete it.
// (How do we know how many??
// ?? Still ont sure about this ??
// What i was trying to do was end up with a full HR, but knowing how many elements to use.
// Far simpler to config it, but can users cope??
// Will config for testing. HA, N
/*
TopElement=ForwardingInfo->HADDRS[Count][0];
if (strcmp(TopElement, MyElements[0]) == 0)
goto FullHR;
if (FindContinent(TopElement))
goto FullHR;
// Need to add stuff from our HR
Elements--;
if (Elements < MyElementCount)
break;
FullHR:
*/
ForwardingInfo->HADDROffet[Count] = (Num)? atoi(Num): 0;
if (ForwardingInfo->HADDRS[Count][1])
{
if (strlen(ForwardingInfo->HADDRS[Count][1]) == 4)
{
// Convert to 2 char Continent;
Continent = FindContinent(ForwardingInfo->HADDRS[Count][1]);
if (Continent)
{
free(ForwardingInfo->HADDRS[Count][1]);
ForwardingInfo->HADDRS[Count][1] = _strdup(Continent->TwoCharCode);
}
}
}
free(SaveHText);
HText++;
Count++;
}
ForwardingInfo->HADDRS[Count] = NULL;
}
VOID SetupHAddresesP(struct BBSForwardingInfo * ForwardingInfo)
{
int Count=0;
char ** HText = ForwardingInfo->HaddressesP;
char * SaveHText, * ptr2;
// char * TopElement;
char * Num;
struct Continent * Continent;
ForwardingInfo->HADDRSP = zalloc(4); // always NULL entry on end even if no values
while(HText[0])
{
int Elements = 1;
ForwardingInfo->HADDRSP = realloc(ForwardingInfo->HADDRSP, (Count+2)*4);
ForwardingInfo->HADDRSP[Count] = zalloc(8); // Always at lesat WWW and NULL
SaveHText = _strdup(HText[0]);
Num = strlop(SaveHText, ',');
ptr2 = SaveHText + strlen(SaveHText) -1;
ForwardingInfo->HADDRSP[Count][0] = _strdup(WW);
if (strcmp(HText[0], "WW") != 0)
{
do
{
ForwardingInfo->HADDRSP[Count] = realloc(ForwardingInfo->HADDRSP[Count], (Elements+2)*4);
while ((*ptr2 != '.') && (ptr2 > SaveHText))
{
ptr2 --;
}
if (ptr2 == SaveHText)
{
// End
ForwardingInfo->HADDRSP[Count][Elements++] = _strdup(ptr2);
break;
}
ForwardingInfo->HADDRSP[Count][Elements++] = _strdup(ptr2+1);
*ptr2 = 0;
} while(TRUE);
}
ForwardingInfo->HADDRSP[Count][Elements++] = NULL;
if (ForwardingInfo->HADDRSP[Count][1])
{
if (strlen(ForwardingInfo->HADDRSP[Count][1]) == 4)
{
// Convert to 2 char Continent;
Continent = FindContinent(ForwardingInfo->HADDRSP[Count][1]);
if (Continent)
{
free(ForwardingInfo->HADDRSP[Count][1]);
ForwardingInfo->HADDRSP[Count][1] = _strdup(Continent->TwoCharCode);
}
}
}
free(SaveHText);
HText++;
Count++;
}
ForwardingInfo->HADDRSP[Count] = NULL;
}
VOID CheckAndSend(struct MsgInfo * Msg, CIRCUIT * conn, struct UserInfo * bbs)
{
struct BBSForwardingInfo * ForwardingInfo = bbs->ForwardingInfo;
if ((_stricmp(bbs->Call, BBSName) != 0) || ForwardToMe) // Dont forward to ourself - already here!
{
if ((conn == NULL) || (!(conn->BBSFlags & BBS) || (_stricmp(conn->UserPointer->Call, bbs->Call) != 0))) // Dont send back
{
set_fwd_bit(Msg->fbbs, bbs->BBSNumber);
ForwardingInfo->MsgCount++;
if (ForwardingInfo->SendNew)
ForwardingInfo->FwdTimer = ForwardingInfo->FwdInterval;
}
}
}
int MatchMessagetoBBSList(struct MsgInfo * Msg, CIRCUIT * conn)
{
struct UserInfo * bbs;
struct UserInfo * user;
struct BBSForwardingInfo * ForwardingInfo;
char ATBBS[41]="";
char RouteElements[41];
int Count = 0;
char * HElements[20] = {NULL};
int Elements = 0;
char * ptr2;
int MyElement = 0;
BOOL Flood = FALSE;
char FullRoute[100];
struct Continent * Continent;
struct Country * Country;
struct ALIAS * Alias;
struct UserInfo * RMS;
if (Msg->status == 'K')
return 1; // No point, but don't want no route warning
strcpy(RouteElements, Msg->via);
Logprintf(LOG_BBS, conn, '?', "Msg %d Routing Trace To %s Via %s", Msg->number, Msg->to, RouteElements);
// "NTS" Alias substitution is now done on P and T before any other processing
// No, Not a good idea to use same aliss file for NTS and other messages
// (What about OT 2*?)
// If we need to alias other types, add a new file
if (Msg->type == 'T')
{
strlop(RouteElements, '.');
Alias = CheckForNTSAlias(Msg, RouteElements);
if (Alias)
{
// Replace the AT in the message with the Alias
Logprintf(LOG_BBS, conn, '?', "Routing Trace @%s taken from Alias File", Alias->Alias);
strcpy(Msg->via, Alias->Alias);
SaveMessageDatabase();
}
strcpy(RouteElements, Msg->via); // May have changed
}
// See if sending @ winlink.org
if (_stricmp(Msg->to, "RMS") == 0)
{
// If a user of this bbs with Poll RMS set, leave it here - no point in sending to winlink
// To = RMS could come from RMS:EMAIL Address. If so, we only check user if @winlink.org, or
// we will hold g8bpq@g8bpq.org.uk
char * Call;
char * AT;
Call = _strupr(_strdup(Msg->via));
AT = strlop(Call, '@');
if (AT)
{
if (_stricmp(AT, "WINLINK.ORG") == 0)
{
user = LookupCall(Call);
if (user)
{
if (user->flags & F_POLLRMS)
{
Logprintf(LOG_BBS, conn, '?', "Message @ winlink.org, but local RMS user - leave here");
strcpy(Msg->to, Call);
strcpy(Msg->via, AT);
free(Call);
if (user->flags & F_BBS) // User is also a BBS, so set FWD bit so he can get it
set_fwd_bit(Msg->fbbs, user->BBSNumber);
return 1;
}
}
}
}
free(Call);
// To = RMS, but not winlink.org, or not local user.
RMS = FindRMS();
if (RMS)
{
Logprintf(LOG_BBS, conn, '?', "Routing Trace to RMS Matches BBS RMS");
set_fwd_bit(Msg->fbbs, RMS->BBSNumber);
RMS->ForwardingInfo->MsgCount++;
if (RMS->ForwardingInfo->SendNew)
RMS->ForwardingInfo->FwdTimer = RMS->ForwardingInfo->FwdInterval;
return 1;
}
// To RMS, but don't have a BBS called RMS - dropthrough in case we are forwarding RMS to another BBS
}
if (_stricmp(RouteElements, "WINLINK.ORG") == 0)
{
user = LookupCall(Msg->to);
if (user)
{
if (user->flags & F_POLLRMS)
{
Logprintf(LOG_BBS, conn, '?', "Routing Trace @ winlink.org, but local RMS user - leave here");
if (user->flags & F_BBS) // User is also a BBS, so set FWD bit so he can get it
set_fwd_bit(Msg->fbbs, user->BBSNumber);
return 1; // Route found
}
}
RMS = FindRMS();
if (RMS)
{
Logprintf(LOG_BBS, conn, '?', "Routing Trace @ winlink.org Matches BBS RMS");
set_fwd_bit(Msg->fbbs, RMS->BBSNumber);
RMS->ForwardingInfo->MsgCount++;
if (RMS->ForwardingInfo->SendNew)
RMS->ForwardingInfo->FwdTimer = RMS->ForwardingInfo->FwdInterval;
return 1;
}
Logprintf(LOG_BBS, conn, '?', "Routing Trace - @ winlink.org but no BBS RMS");
return 0;
}
// See if AMPR.ORG Mail
// If for our domain leave alone
if (AMPRDomain[0] && SendAMPRDirect && _stricmp(Msg->via, AMPRDomain) != 0)
{
int toLen = strlen(Msg->via);
if (_memicmp(&Msg->via[toLen - 8], "ampr.org", 8) == 0)
{
if (_stricmp(Msg->to, "AMPR") != 0) // Already set up?
{
// Put full name in VIA and AMPR in TO
char Full[80];
sprintf(Full, "%s@%s", Msg->to, Msg->via);
if (strlen(Full) > 40)
Full[40] = 0;
strcpy(Msg->via, Full);
strcpy(Msg->to, "AMPR");
}
}
if (_stricmp(Msg->to, "AMPR") == 0)
{
bbs = FindAMPR();
if (bbs)
{
Logprintf(LOG_BBS, conn, '?', "Routing Trace to ampr.org Matches BBS AMPR");
set_fwd_bit(Msg->fbbs, bbs->BBSNumber);
bbs->ForwardingInfo->MsgCount++;
if (bbs->ForwardingInfo->SendNew)
bbs->ForwardingInfo->FwdTimer = bbs->ForwardingInfo->FwdInterval;
return 1;
}
// To AMPR, but don't have a BBS called AMPR - dropthrough in case we are forwarding AMPR to another BBS
}
}
// See if a well-known alias
Alias = FindAlias(RouteElements);
if (Alias)
{
Logprintf(LOG_BBS, conn, '?', "Routing Trace Alias Substitution %s > %s",
RouteElements, Alias->Alias);
strcpy(RouteElements, Alias->Alias);
if (conn)
if ((ReaddressReceived && (conn->BBSFlags & BBS)) || (ReaddressLocal && ((conn->BBSFlags & BBS) == 0)))
strcpy(Msg->via, Alias->Alias);
}
// Make sure HA is complete (starting at WW)
if (RouteElements[0] == 0)
goto NOHA;
ptr2 = RouteElements + strlen(RouteElements) - 1;
while ((*ptr2 != '.') && (ptr2 > RouteElements))
{
ptr2 --;
}
if (ptr2 != RouteElements)
*ptr2++;
if ((strcmp(ptr2, "WW") == 0) || (strcmp(ptr2, "WWW") == 0))
{
strcpy(FullRoute, RouteElements);
goto FULLHA;