-
Notifications
You must be signed in to change notification settings - Fork 6
/
boardtags.cpp
825 lines (767 loc) · 37.2 KB
/
boardtags.cpp
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
/***************************************************************************
boardtags.cpp - board tags support
-------------------
begin : Sun Apr 29 2001
copyright : (C) 2001 by Alexander Bilichenko
email : [email protected]
***************************************************************************/
#include "basetypes.h"
#include "boardtags.h"
#include "error.h"
#include "dbase.h"
STagConvert TagConvTable[BoardTagCount] = {
{"B", "<B>", WC_TAG_TYPE_1, "</B>", WC_TAG_TYPE_1, 1, NULL, NULL},
{"I", "<I>", WC_TAG_TYPE_1, "</I>", WC_TAG_TYPE_1, 1, NULL, NULL},
{"U", "<U>", WC_TAG_TYPE_1, "</U>", WC_TAG_TYPE_1, 1, NULL, NULL},
{"H", "<B><FONT SIZE=4>", WC_TAG_TYPE_1, "</FONT></B>", WC_TAG_TYPE_1, 0, NULL, NULL},
{"S", "<FONT SIZE=1>", WC_TAG_TYPE_1, "</FONT>", WC_TAG_TYPE_1, 1, NULL, NULL},
{"RED", "<span style=\"color:red\">", WC_TAG_TYPE_1, "</span>", WC_TAG_TYPE_1, 1, NULL, NULL},
{"COLOR", "<span style=\"color:%s\">", WC_TAG_TYPE_2, "</span>", WC_TAG_TYPE_1, 1, NULL, NULL},
{"URL", "<A HREF=\"%s\" STYLE=\"text-decoration:underline;\" TARGET=_blank>", WC_TAG_TYPE_2, "</A>", WC_TAG_TYPE_1, 0, NULL, NULL},
{"PIC", "<IMG class=\"imgtag\" src=\"", WC_TAG_TYPE_1, "\">", WC_TAG_TYPE_1, 0, NULL, NULL},
{"HR", "<HR SIZE=2>", WC_TAG_TYPE_ONLYOPEN, "", WC_TAG_TYPE_DISABLED, 0, NULL, NULL},
{"Q", "<blockquote class=\"quote\"><span class=\"inquote\">[q]</span><b>Öèòàòà:</b><br>",
WC_TAG_TYPE_12, "<span class=\"inquote\">[/q]</span></blockquote>", WC_TAG_TYPE_12, 0,
"<blockquote class=\"quote\"><span class=\"inquote\">[q]</span><b>Öèòàòà:</b><br>",
"<div align=\"right\"><i>%s</i><span class=\"inquote\"> [/q]</span></div></blockquote>"},
{"CENTER", "<CENTER>", WC_TAG_TYPE_1, "</CENTER>", WC_TAG_TYPE_1, 0, NULL, NULL},
{"PRE", "<PRE style=\"display:inline\">", WC_TAG_TYPE_1, "</PRE>", WC_TAG_TYPE_1, 0, NULL, NULL},
{"STRIKE", "<STRIKE>", WC_TAG_TYPE_1, "</STRIKE>", WC_TAG_TYPE_1, 1, NULL, NULL},
{"SUP", "<SUP>", WC_TAG_TYPE_1, "</SUP>", WC_TAG_TYPE_1, 0, NULL, NULL},
{"SUB", "<SUB>", WC_TAG_TYPE_1, "</SUB>", WC_TAG_TYPE_1, 0, NULL, NULL},
{"TEX", "<img src=\"https://latex.codecogs.com/gif.latex?", WC_TAG_TYPE_1, "\">", WC_TAG_TYPE_1, 0, NULL, NULL},
{"TUB", "<iframe class=\"youtube-player\" type=\"text/html\" src=\"https://www.youtube.com/embed/",
WC_TAG_TYPE_1, "?iv_load_policy=3&rel=0&fs=1\" frameborder=\"0\"></iframe>", WC_TAG_TYPE_1, 0, NULL, NULL},
{"SPOILER", "<span style=\"color:transparent; background-color:black;\">", WC_TAG_TYPE_1, "</span>", WC_TAG_TYPE_1, 1, NULL, NULL}
};
SPicConvert PicConvTable[BoardPicCount] = {
{":))", "bigsmile.gif" },
{":)", "smile.gif" },
{":(", "frown.gif" },
{";)", "wink.gif" },
{":!!", "lol.gif" },
{":\\", "smirk.gif" },
{":o", "redface.gif" },
{":MAD", "mad.gif" },
{":STOP", "stop.gif" },
{":APPL", "appl.gif" },
{":BAN", "ban.gif" },
{":BEE", "bee.gif" },
{":BIS", "bis.gif" },
{":ZLOBA", "blya.gif" },
{":BORED", "bored.gif" },
{":BOTAT", "botat.gif" },
{":COMP", "comp.gif" },
{":CRAZY", "crazy.gif" },
{":DEVIL", "devil.gif" },
{":DOWN", "down.gif" },
{":FIGA", "figa.gif" },
{":GIT", "git.gif" },
{":GYGY", "gy.gif" },
{":HEH", "heh.gif" },
{":CIQ", "iq.gif" },
{":KURIT", "kos.gif" },
{":LAM", "lam.gif" },
{":MNC", "mnc.gif" },
{":NO", "no.gif" },
{":SMOKE", "smoke.gif" },
{":SORRY", "sorry.gif" },
{":SUPER", "super.gif" },
{":UP", "up.gif" },
{":YES2", "yes2.gif" },
{":YES", "yes.gif" },
{":BASH", "bash.gif" },
{":CLAPPY", "clappy.gif" },
{":EWW", "eww.gif" },
{":ROTFL", "roflol.gif" },
{":SPOTMAN", "spotman.gif" },
{":WAVE", "wave.gif" },
{":COWARD", "coward.gif" },
{":DRAZNIT", "draznit.gif" },
{":ROLLEYES", "rolleyes.gif" },
{":PLOHO", "blevalyanaeto.gif"},
{":}", "icqbig.gif" },
};
/* parse string to nearest ';' or ':' */
size_t ParseToOpenSmileTagorHttp(const char *s)
{
size_t i = 0;
#if TRY_AUTO_URL_PREPARSE
// find smile, ftp or http start
while (s[i] != 0 && s[i] != ':' && s[i] != ';' && s[i] != 'h' && s[i] != 'f')
++i;
#else
while(s[i] != 0 && s[i] != ':' && s[i] != ';')
++i;
#endif
return i;
}
static int _isurlend(char c)
{
return isspace(c) || c == '\0';
}
static int _ispunct(char c)
{
return c == '.' || c == ',' || c == '?' || c == '!' || c == ':' || c == ';';
}
#if TRY_AUTO_URL_PREPARSE
/* return 1 if url was parsed, 0 otherwise */
static int ReparseUrl(char **ss, char **dd, int index, DWORD status)
{
int rf = 0;
char *d = *dd, *s = *ss;
size_t slen = strlen(s);
if( ( (slen > 7) && (strncmp(s, "http://", 7) == 0) ) ||
( (slen > 8) && (strncmp(s, "https://", 8) == 0) ) ||
( (slen > 6) && (strncmp(s, "ftp://", 6) == 0) ) )
{
if((status & 4)) {
// we have found http:// | https:// | ftp:// reference, so try to parse it
char *olds = s;
char oldcs;
char *dtmp;
if(*s == 'h') s++;
s+=6;
while (!_isurlend(*s) && !(_ispunct(*(s)) && _isurlend(*(s+1))))
++s;
oldcs = *s;
*s = 0;
dtmp = (char*)malloc(strlen(olds)*2+strlen(PARSED_URL_TMPL_IDX));
if (dtmp == NULL) {
abort();
}
if (index) {
static int id;
++id;
sprintf(dtmp, PARSED_URL_TMPL_IDX, olds, id, id, id, olds);
} else
sprintf(dtmp, PARSED_URL_TMPL, olds, olds);
strcpy(d, dtmp);
d+=strlen(dtmp);
free(dtmp);
*s = oldcs;
}
rf = 1;
}
*dd = d;
*ss = s;
return rf;
}
#endif
/* Smart strcat() function. It removes all duplicated spaces, char '\r' and all tabs.
* The behavior depends of status. If status nonzero it works as usual strcat except
* '\r' char removing.
* status meaning:
* 0x01 - spaces and tabs elimination (DISABLING)
* 0x02 - '\n' -> BR parsing
* 0x04 - url parsing
*/
int inline smartstrcat(char *d, char *s, int index, DWORD status, DWORD *flg)
{
char *od = d;
d += strlen(d);
*flg = 0;
if(status & 1) {
while(*s != 0) {
#if TRY_AUTO_URL_PREPARSE
if (ReparseUrl(&s, &d, index, status)) {
*flg = 1;
if (*s == 0) {
break;
}
}
#endif
if(*s != '\r') {
if(*s == '\n' && (status & 2)) {
// convert to <BR>
memcpy(d, "<BR>", 4);
d+=4;
}
else if(*s == '\n' && (status & 0x10)) {
// convert to <BR>
memcpy(d, "<BR>", 10);
d+=10;
}
else {
*d = *s;
d++;
}
}
s++;
}
*d = *s;
}
else {
int ws = 0; // was space or tab
while(*s != 0) {
#if TRY_AUTO_URL_PREPARSE
if (ReparseUrl(&s, &d, index, status)) {
*flg = 1;
ws = 0;
if (*s == 0) {
break;
}
}
#endif
if (*s != '\r' && !(ws && (*s == ' ' || *s == '\t'))) {
if(*s == ' ' || *s == '\t') {
ws = 1;
*d = ' ';
}
else {
ws = 0;
if(*s == '\n' && (status & 2)) {
// convert to <BR>
memcpy(d, "<BR>", 4);
d+=3;
}
else if(*s == '\n' && (status & 0x10)) {
// convert to <BR>
memcpy(d, "<BR>", 10);
d+=9;
}
else *d = *s;
}
d++;
}
s++;
}
*d = *s;
}
return d - od;
}
/* function for concatenation string s to d
* with converting smile-codes to images
*/
int ParseSmiles_smartstrcat(char *d, char *s, int index, DWORD status, DWORD *flg)
{
char *dd = d + strlen(d);
char *ss = s;
size_t i = 0;
int wassmile = 0;
*flg = 0;
while (*ss) {
i = ParseToOpenSmileTagorHttp(ss);
if (i) {
char si = ss[i];
ss[i] = 0;
dd += smartstrcat(dd, ss, index, status, flg);
ss[i] = si;
ss += i;
}
#if TRY_AUTO_URL_PREPARSE
if (ReparseUrl(&ss, &dd, index, status)) *flg = 1;
#endif
if (*ss == 0) break;
for(unsigned int j = 0; j < BoardPicCount; j++) {
if(strlen(PicConvTable[j].tag) <= strlen(ss) && !index &&
strncmp(ss, PicConvTable[j].tag, strlen(PicConvTable[j].tag)) == 0 && ((status & 1) == 0) ) {
wassmile = 1;
strcat(dd, "<IMG BORDER=0 SRC=\"" BOARD_PIC_URL);
strcat(dd, PicConvTable[j].url);
strcat(dd, "\" ALT=\"");
strcat(dd, PicConvTable[j].tag);
strcat(dd, "\">");
dd += strlen(dd);
ss += strlen(PicConvTable[j].tag);
goto next_sym;
}
}
if(*ss == '\n' && (status & 2)) {
if(*dd == 0) *(dd+4) = 0;
// convert to <BR>
memcpy(dd, "<BR>", 4);
dd+=4;
}
else {
if(*dd == 0) *(dd+1) = 0;
*dd = *ss;
dd++;
}
ss++;
next_sym: ;
}
*dd = 0;
return wassmile;
}
/* insert string 'src' into string 'dst' at position 'index'
* returns 'dst', DOES NOT CONTROL ANY ERRORS
*/
char* strins(char *dst, const char *src, size_t index)
{
char *insert_pos = dst + index;
size_t insert_len = strlen(src);
// move tail (including '\0' terminator) to the right:
memmove(insert_pos + insert_len, insert_pos, strlen(dst) + 1 - index);
// copy inserted bytes:
memcpy(insert_pos, src, insert_len);
return dst;
}
/* parse string up to nearest =, WC_TAG_OPEN/CLOSE */
size_t ParseRegExp(const char *s)
{
size_t i = 0;
while(s[i] != 0 && s[i] != '=' && s[i] != WC_TAG_CLOSE && s[i] != WC_TAG_OPEN) i++;
return i;
}
/* parse to nearest WC_TAG_OPEN */
size_t ParseToOpenWC_TAG(const char *s)
{
size_t i = 0;
while (s[i] && s[i] != WC_TAG_OPEN)
++i;
return i;
}
/* parse to nearest WC_TAG_CLOSE */
size_t ParseToCloseWC_TAG(const char *s)
{
size_t i = 0;
while(s[i] != 0 && s[i] != WC_TAG_CLOSE) i++;
return i;
}
/* input: s - parsing string with begining of tag (first symbol = WC_TAG_OPEN)
* oputput: function return length of parsed board tag or 0 if tag is not valid
* par1 - tag name, par2 - parameter after = in tag (NULL if not present)
*/
size_t ParseBoardTag(char *s, char **par1, char **par2)
{
char *ss = s;
size_t i, j;
*par1 = NULL;
*par2 = NULL;
// ignore WC_TAG_OPEN
if(*s != WC_TAG_OPEN) {
return 0;
}
s++;
// parse first arg
i = ParseRegExp(s);
if(i == 0) {
return 0;
}
*par1 = strndup(s, i);
toupperstr(*par1);
s += i;
if(*s == WC_TAG_CLOSE) {
return (size_t)(s - ss + 1);
}
if(*s == '=') {
// parse second arg
s++;
j = ParseToCloseWC_TAG(s);
if(j == 0) {
//goto ParseBoardTag_Faild;
}
if(s[j] == WC_TAG_CLOSE) {
*par2 = strndup(s, j);
return (size_t)(s - ss + 1) + j;
}
}
//ParseBoardTag_Faild:
free(*par1);
*par1 = NULL;
*par2 = NULL;
return 0;
}
/* check and expand board tags -> HTML tags
* return value: function return 1 if successfull, overwise 0
* tagtype - tag type (index in TagConvTable) and taglen = 1, 2
*/
static int ExpandTag(char *tag1, char *tag2, char **restag, int *tagnumber, int *tagtype, int index)
{
int tagdirection = 0; /* open by default */
if(tag1[0] == '/') {
tagdirection = 1;
tag1++;
}
*restag = NULL;
for (int tn = 0; tn < BoardTagCount; tn++) {
if (strcmp(tag1, TagConvTable[tn].tag) == 0) {
if (index && !TagConvTable[tn].index) {
return 0;
}
*tagnumber = tn;
int tagt;
if (tagdirection) {
tagt = TagConvTable[tn].typeclose;
} else {
tagt = TagConvTable[tn].typeopen;
}
*tagtype = tagt;
if (tagt == WC_TAG_TYPE_12) {
if (tag2)
tagt = WC_TAG_TYPE_2;
else
tagt = WC_TAG_TYPE_1;
}
switch(tagt) {
case WC_TAG_TYPE_1:
/* check for valid param count */
if (tag2) {
if (!tagdirection)
return 0;
else if (TagConvTable[tn].typeopen != WC_TAG_TYPE_12 && TagConvTable[tn].typeopen != WC_TAG_TYPE_2)
return 0;
}
//if(tag2 != NULL && tagdirection) return 0;
if(tagdirection) {
/* closing */
*restag = strdup(TagConvTable[tn].tclosetag);
}
else {
/* opening */
*restag = strdup(TagConvTable[tn].topentag);
}
return 1;
case WC_TAG_TYPE_2:
/* check for valid param count
*/
if(tag2 == NULL)
return 0;
if(!tagdirection) {
/* opening */
char *parsedtag2 = NULL;
if (tn == URL_TAG_TYPE) {
if(strncmp(tag2, "http:", 5) != 0 && strncmp(tag2, "ftp:", 4) != 0 &&
strncmp(tag2, "file:", 5) != 0 && strncmp(tag2, "https:", 6) != 0 &&
strncmp(tag2, "smb:", 4) != 0) {
parsedtag2 = (char*)malloc(strlen(tag2) + 10);
strcpy(parsedtag2, "http://");
strcat(parsedtag2, tag2);
}
} else if (tn == COLOR_TAG_TYPE) {
if (tag2[0] == '#') {
for (size_t i = 1; i < 7; ++i)
if (!((tag2[i] >= '0' && tag2[i] <= '9') ||
(tag2[i] >= 'A' && tag2[i] <= 'F') ||
(tag2[i] >= 'a' && tag2[i] <= 'f')))
return 0;
} else {
for (size_t i = 0; i < strlen(tag2); ++i)
if (!((tag2[i] >= 'A' && tag2[i] <= 'Z') ||
(tag2[i] >= 'a' && tag2[i] <= 'z')))
return 0; // only letters are allowed
}
}
if (!parsedtag2)
parsedtag2 = tag2;
*restag = (char*)malloc(strlen(TagConvTable[tn].topentag) + 1 + strlen(parsedtag2));
/* use sprintf() to insert tag2 into result
* (format of topentag as %s instead of tag2)
*/
sprintf(*restag, TagConvTable[tn].topentag, parsedtag2);
*restag = (char*)realloc(*restag, strlen(*restag) + 1);
if(parsedtag2 != tag2) free(parsedtag2);
} else {
/* closing */
const char *tclosetag;
if (TagConvTable[tn].typeclose == WC_TAG_TYPE_12)
tclosetag = TagConvTable[tn].tclosetag2;
else
tclosetag = TagConvTable[tn].tclosetag;
*restag = (char*)malloc(strlen(tclosetag) + 1 + strlen(tag2));
sprintf(*restag, tclosetag, tag2);
*restag = (char*)realloc(*restag, strlen(*restag) + 1);
return 1;
}
return 1;
case WC_TAG_TYPE_12:
/* temporary not used */
return 0;
case WC_TAG_TYPE_ONLYOPEN:
/* check for valid param count
*/
if(tag2 != NULL) return 0;
if(!tagdirection) {
/* opening */
*restag = strdup(TagConvTable[tn].topentag);
}
else {
/* closing - not valid (only opening) */
return 0;
}
return 1;
}
}
}
/* tag not found */
return 0;
}
/* filtering smile codes and board tags taking into account index flag
* and message flags MESSAGE_ENABLED_SMILES MESSAGE_ENABLED_TAGS
* return value 1 if all successfull, or 0 if string was cutted,
* because of ml limitation
* **** input : s - string, ml - max result string length, Flags - flags of message,
* index - whether text is a subject or an altname.
* level of msg (for tags conversion)
* **** output : r - resulting string
* Meaning of some flags
* 0x80 - set up flag HAVE_URL
* 0x04 - url autopreparse
*/
int FilterBoardTags(char *s, char **r, int index, DWORD ml, DWORD Flags, DWORD *RF)
{
DWORD beforePreStatus;
char *tag1 = NULL, *tag2 = NULL, *res = NULL, *st = NULL;
DWORD opentag, reff, status = 0x04, urldisable = 0; // http preparse
size_t i, StringTooLong = 0;
SSavedTag OldTag[MAX_NESTED_TAGS];
char *params[MAX_NESTED_TAGS + 1] = {NULL};
char *param = NULL;
// ignore starting newline
while(*s == '\r' || *s == '\n')
++s;
// ignore ending newline
{
size_t k = strlen(s);
for (; k > 0; k--) {
if(!(s[k - 1] == '\r' || s[k - 1] == '\n'))
break;
}
s[k] = 0;
}
*RF = 0;
*r = NULL;
if(Flags & BOARDTAGS_EXPAND_ENTER)
status |= 0x02; // '\n' -> <BR> conversion
if(Flags & BOARDTAGS_EXPAND_XMLEN)
status |= 0x10; // '\n' -> <BR> xml conversion
if((Flags & BOARDTAGS_CUT_TAGS) || (Flags & BOARDTAGS_TAG_PREPARSE) || ((Flags & BOARDTAGS_PURL_ENABLE) == 0)) {
status &= ~0x04u; // disable url parsing
urldisable = 1;
}
/* alloc memory for resulting string */
beforePreStatus = status;
if (ml < 32000)
st = (char*) malloc(32000);
else
st = (char*) malloc(3*ml);
if (st == NULL) {
abort();
}
st[0] = 0;
opentag = 0;
for(;;) {
if (strlen(st) >= ml) {
StringTooLong = 1;
break;
}
if (*s == 0)
break;
i = ParseToOpenWC_TAG(s);
if (i) {
char si = s[i];
s[i] = 0;
if ((Flags & MESSAGE_ENABLED_SMILES) && ((Flags & BOARDTAGS_TAG_PREPARSE) == 0)) {
if(ParseSmiles_smartstrcat(st, s, index, status, &reff))
*RF = *RF | MESSAGE_ENABLED_SMILES;
if (reff && ((status & 0x80) == 0))
*RF |= MESSAGE_HAVE_URL;
} else {
smartstrcat(st, s, index, status, &reff);
if (reff && ((status & 0x80) == 0))
*RF |= MESSAGE_HAVE_URL;
}
s[i] = si;
s += i;
}
if ( (i = ParseBoardTag(s, &tag1, &tag2))) {
if (tag1[0] == '/') {
if (tag2 || !opentag)
goto ignore_tag;
param = params[opentag - 1];
} else {
param = tag2;
params[opentag] = tag2 ? strdupa(tag2) : NULL;
}
}
if((Flags & MESSAGE_ENABLED_TAGS) == 0)
goto ignore_tag;
if(i) {
int tt = 0, tl = 0;
/* we have tag, parse it! */
if(!ExpandTag(tag1, param, &res, &tt, &tl, index)) {
/* invalid tag */
goto ignore_tag;
}
if(tl == WC_TAG_TYPE_ONLYOPEN) {
*RF = *RF | MESSAGE_ENABLED_TAGS;
if((status & 1) == 0 && ((Flags & BOARDTAGS_TAG_PREPARSE) == 0)) {
// only opened tag - so parse it at once
strcat(st, res);
s += i;
}
else goto ignore_tag;
}
else {
// if successfully expanded (exists)
// already have open tag - so try to interpret it as closing tag
if(tag1[0] == '/') {
if(opentag) {
/* closing tag */
if (tt == PRE_TAG_TYPE || tt == PIC_TAG_TYPE
|| tt == TEX_TAG_TYPE || tt == TUB_TAG_TYPE) // allow tag and space parsing again
status &= 0xFFFFFFFE;
if(tt == PRE_TAG_TYPE)
status = beforePreStatus;
/* set flags of message type */
if (tt == PIC_TAG_TYPE) { /* there was a picture tag */
if(!urldisable) {
status |= 0x04; // allow http parsing
}
status &= ~0x80u;
*RF = *RF | MESSAGE_HAVE_PICTURE;
}
if (tt == TEX_TAG_TYPE ) {
if(!urldisable) {
status |= 0x04;
}
status &= ~0x80u;
*RF = *RF | MESSAGE_HAVE_TEX;
}
if (tt == TUB_TAG_TYPE ) {
if(!urldisable) {
status |= 0x04;
}
status &= ~0x80u;
*RF = *RF | MESSAGE_HAVE_TUB;
}
if(tt == URL_TAG_TYPE) { /* there was a url tag */
if(!urldisable) {
status |= 0x04; // allow http parsing
}
*RF = *RF | MESSAGE_HAVE_URL;
}
/* have at least one tag */
*RF = *RF | MESSAGE_ENABLED_TAGS;
// what we will do with tags
if((Flags & BOARDTAGS_TAG_PREPARSE)) {
// do not change tags, just preparse spaces, etc.
strins(st, OldTag[opentag - 1].oldexp, OldTag[opentag - 1].index);
char os = s[i];
s[i] = 0;
strcat(st, s);
s[i] = os;
}
else {
// expand tags or ignore(cut) them
if((Flags & BOARDTAGS_CUT_TAGS) == 0 &&
!(index && currentdsm & CONFIGURE_clr && (tt == RED_TAG_TYPE || tt == COLOR_TAG_TYPE))) {
//
// PATCH for PIC tag
//
if(tt == PIC_TAG_TYPE ) { /* there was a picture tag */
char *ts = st + OldTag[opentag - 1].index;
if(strncmp(ts, "http:", 5) != 0 && strncmp(ts, "ftp:", 4) != 0 &&
strncmp(ts, "file:", 5) != 0 && strncmp(ts, "https:", 6) != 0 &&
strncmp(ts, "smb:", 4) != 0)
{
// add http
strins(ts, "http://", 0);
}
}
strins(st, OldTag[opentag - 1].tagexp, OldTag[opentag - 1].index);
strins(st, res, strlen(st));
}
else {} // tag will be cutted
}
free(OldTag[opentag - 1].tagexp);
free(OldTag[opentag - 1].oldexp);
opentag--; // dec tag count
s += i;
}
else {
/* ignore tags first elem of tag */
goto ignore_tag;
}
}
else {
if((status & 1) == 0) {
// opening tag
/* tag expanded successfully - set current tag struct */
if(opentag > MAX_NESTED_TAGS - 1) goto ignore_tag;
OldTag[opentag].tt = tt;
OldTag[opentag].tl = tl;
OldTag[opentag].tagexp = res;
res = NULL;
OldTag[opentag].index = strlen(st);
char os = s[i];
s[i] = 0;
OldTag[opentag].oldexp = (char*)malloc(strlen(s) + 1);
strcpy(OldTag[opentag].oldexp, s);
s[i] = os;
s += i;
opentag++; // inc tag count
// check if it was PRE or PIC tag
if(tt == PRE_TAG_TYPE) {
beforePreStatus = status;
status &= ~2u; //disable "\n" -> "<br>" conv
}
if(tt == PRE_TAG_TYPE || tt == PIC_TAG_TYPE || tt == TEX_TAG_TYPE) // disable tag parsing
status |= 0x01;
// check if it was PIC tag
if(tt == PIC_TAG_TYPE) {
if(!urldisable)
status &= ~4u; // disable http parsing
status |= 0x80;
}
// check if it was URL tag
if(tt == URL_TAG_TYPE) {
if(!urldisable)
status &= ~4u; // disable http parsing
}
}
else goto ignore_tag;
}
}
}
else {
/* ignore tags first elem of tag */
goto ignore_tag;
}
goto parse_next;
ignore_tag:
if((*s) != 0) {
char si;
si = *(s + 1);
*(s +1 ) = 0;
strcat(st, s);
*(s + 1) = si;
s++;
}
parse_next:
if(tag1) {
free(tag1);
tag1 = NULL;
}
if(tag2) {
free(tag2);
tag2 = NULL;
}
if(res) {
free(res);
res = NULL;
}
}
if(StringTooLong) {
/* too long string */
free(st);
for (DWORD ti = 0; ti < opentag; ti++) {
free(OldTag[ti].oldexp);
free(OldTag[ti].tagexp);
}
return 0;
}
if(opentag) {
DWORD k;
for(k = opentag; k > 0; k--)
strins(st, OldTag[k - 1].oldexp, OldTag[k - 1].index);
for(k = 0; k < opentag; k++) {
free(OldTag[k].oldexp);
free(OldTag[k].tagexp);
}
}
st = (char*)realloc(st, strlen(st) + 5);
*r = st;
return 1;
}