-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathparser.c
6343 lines (6193 loc) · 191 KB
/
parser.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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "sfuncs.h"
#include "dbexchange.h"
#include "extprgfuncs.h"
#include "main.h"
#include "parser.h"
chanpropnode *cproot = NULL, *cpptr = NULL;
itempropnode *iproot = NULL, *ipptr = NULL;
catnode *catroot = NULL, *catptr = NULL;
elementpnode *eproot = NULL, *epptr = NULL;
unsigned long nextitemid = 1;
unsigned long nextchanid = 1;
char *rssversion = NULL;
int parseday(char *dayname)
{
if (startswith_i(dayname, "Sun")) return 0;
if (startswith_i(dayname, "Mon")) return 1;
if (startswith_i(dayname, "Tue")) return 2;
if (startswith_i(dayname, "Wed")) return 3;
if (startswith_i(dayname, "Thu")) return 4;
if (startswith_i(dayname, "Fri")) return 5;
if (startswith_i(dayname, "Sat")) return 6;
if (startswith_i(dayname, "DiM")) return 0;
if (startswith_i(dayname, "Lun")) return 1;
if (startswith_i(dayname, "Mar")) return 2;
if (startswith_i(dayname, "Mec")) return 3;
if (startswith_i(dayname, "Jue")) return 4;
if (startswith_i(dayname, "Ven")) return 5;
if (startswith_i(dayname, "Sam")) return 6;
return -1;
}
int createcategory(enum categorytype ctype, unsigned long refid, char *domain,
char *category)
{
catnode *acat = (catnode *) malloc(sizeof(catnode));
if (acat == NULL) return 0; /* OoM! */
memset(acat, 0, sizeof(catnode));
acat->next = NULL;
acat->type = ctype;
if (ctype == channel_cat) acat->id.chanid = refid;
else if (ctype == item_cat) acat->id.itemid = refid;
if (domain != NULL)
{
acat->domain = (char *) malloc(sizeof(char)*(1+strlen(domain)));
if (acat->domain == NULL)
{
free(acat);
return 0; /* OoM! */
}
strcpy(acat->domain,domain);
}
else acat->domain = NULL;
if (category != NULL)
{
acat->category = (char *) malloc(sizeof(char)*(1+strlen(category)));
if (acat->category == NULL)
{
if (acat->domain != NULL) free(acat->domain);
free(acat);
return 0; /* OoM! */
}
strcpy(acat->category, category);
}
else acat->category = NULL;
if (catroot == NULL)
{
catroot = acat;
}
else
{
for (catptr = catroot; catptr->next != NULL; catptr = catptr->next) {}
catptr->next = acat;
}
return 1;
}
void freeacatn(catnode *acatn)
{
if (acatn == NULL) return;
if (acatn->domain != NULL) free(acatn->domain);
if (acatn->category != NULL) free(acatn->category);
free(acatn);
}
void destroycategories()
{
catnode *tcatn = NULL;
catptr = catroot;
while (catptr != NULL)
{
tcatn = catptr->next;
freeacatn(catptr);
catptr = tcatn;
}
catroot = NULL;
catptr = NULL;
}
chanpropnode *createchanpropnode(char *title, char *link, char *description)
/* Assign optional elements later */
{
chanpropnode *acpn = (chanpropnode *) malloc(sizeof(chanpropnode));
if (acpn == NULL) return NULL; /* OoM! */
memset(acpn, 0, sizeof(chanpropnode));
acpn->chanid = nextchanid;
nextchanid++;
acpn->next = NULL;
if (title != NULL)
{
acpn->title = (char *) malloc(sizeof(char)*(1+strlen(title)));
if (acpn->title == NULL)
{
free(acpn);
return NULL; /* OoM! */
}
strcpy(acpn->title, title);
}
else acpn->title = NULL;
if (link != NULL)
{
acpn->link = (char *) malloc(sizeof(char)*(1+strlen(link)));
if (acpn->link == NULL)
{
if (acpn->title!=NULL) free(acpn->title);
free(acpn);
return NULL; /* OoM! */
}
strcpy(acpn->link, link);
}
else acpn->link = NULL;
if (description != NULL)
{
acpn->description = (char *) malloc(sizeof(char)*(1+strlen(description)));
if (acpn->description == NULL)
{
if (acpn->title!=NULL) free(acpn->title);
if (acpn->link!=NULL) free(acpn->link);
free(acpn);
return NULL; /* OoM! */
}
strcpy(acpn->description, description);
}
else acpn->description = NULL;
if (cproot == NULL)
{
cproot = acpn;
}
else
{
for (cpptr = cproot; cpptr->next != NULL; cpptr = cpptr->next) {}
cpptr->next = acpn;
}
return acpn;
}
void freeacpn(chanpropnode *acpn)
{
if (acpn == NULL) return;
if (acpn->title != NULL) free(acpn->title);
if (acpn->link != NULL) free(acpn->link);
if (acpn->description != NULL) free(acpn->description);
if (acpn->language_main != NULL) free(acpn->language_main);
if (acpn->language_sub != NULL) free(acpn->language_sub);
if (acpn->copyright != NULL) free(acpn->copyright);
if (acpn->managingeditor != NULL) free(acpn->managingeditor);
if (acpn->webmaster != NULL) free(acpn->webmaster);
if (acpn->generator != NULL) free(acpn->generator);
if (acpn->docs != NULL) free(acpn->docs);
if (acpn->pubdate.fulldate != NULL) free(acpn->pubdate.fulldate);
if (acpn->lastbuilddate.fulldate != NULL) free(acpn->lastbuilddate.fulldate);
if (acpn->image.url != NULL) free(acpn->image.url);
if (acpn->image.title != NULL) free(acpn->image.title);
if (acpn->image.link != NULL) free(acpn->image.link);
if (acpn->image.description != NULL) free(acpn->image.description);
if (acpn->skiphours != NULL) free(acpn->skiphours);
if (acpn->skipdays != NULL) freentsa(acpn->skipdays);
free(acpn);
}
void destroychannels()
{
chanpropnode *tcpn = NULL;
cpptr = cproot;
while (cpptr != NULL)
{
tcpn = cpptr->next;
freeacpn(cpptr);
cpptr = tcpn;
}
cproot = NULL;
cpptr = NULL;
}
itempropnode *createitempropnode(char *title, char *link, char *description,
unsigned long chanid)
/* Assign optional elements later */
{
itempropnode *anipn = (itempropnode *) malloc(sizeof(itempropnode));
if (anipn == NULL) return NULL; /* OoM! */
memset(anipn, 0, sizeof(itempropnode));
anipn->next = NULL;
anipn->itemid = nextitemid;
anipn->chanid = chanid;
nextitemid++;
if (title == NULL) anipn->title = NULL;
else
{
anipn->title = (char *) malloc(sizeof(char) * (1+strlen(title)));
if (anipn->title == NULL)
{
free(anipn);
return NULL; /* OoM! */
}
strcpy(anipn->title,title);
}
if (link == NULL) anipn->link == NULL;
else
{
anipn->link = (char *) malloc(sizeof(char)*(1+strlen(link)));
if (anipn->link == NULL)
{
if (anipn->title != NULL) free(anipn->title);
free(anipn);
return NULL; /* OoM! */
}
strcpy(anipn->link, link);
}
if (description == NULL) anipn->description == NULL;
else
{
anipn->description = (char *) malloc(sizeof(char)*(1+strlen(description)));
if (anipn->description == NULL)
{
if (anipn->title != NULL) free(anipn->title);
if (anipn->link != NULL) free(anipn->link);
free(anipn);
return NULL; /* OoM! */
}
strcpy(anipn->description, description);
}
if (iproot == NULL)
{
iproot = anipn;
}
else
{
for (ipptr = iproot; ipptr->next != NULL; ipptr = ipptr->next) {}
ipptr->next = anipn;
}
return anipn;
}
void freeanipn(itempropnode *anipn)
{
if (anipn == NULL) return;
if (anipn->title != NULL) free(anipn->title);
if (anipn->link != NULL) free(anipn->link);
if (anipn->description != NULL) free(anipn->description);
if (anipn->author != NULL) free(anipn->author);
if (anipn->comments != NULL) free(anipn->comments);
if (anipn->enclosure.url != NULL) free(anipn->enclosure.url);
if (anipn->enclosure.type != NULL) free(anipn->enclosure.type);
if (anipn->guid.guid != NULL) free(anipn->guid.guid);
if (anipn->source.url != NULL) free(anipn->source.url);
if (anipn->source.name != NULL) free(anipn->source.name);
if (anipn->image.url != NULL) free(anipn->image.url);
if (anipn->image.title != NULL) free(anipn->image.title);
if (anipn->image.link != NULL) free(anipn->image.link);
if (anipn->image.description != NULL) free(anipn->image.description);
if (anipn->pubdate.fulldate != NULL) free(anipn->pubdate.fulldate);
free(anipn);
}
void destroyitems()
{
itempropnode *tipn = NULL;
ipptr = iproot;
while (ipptr != NULL)
{
tipn = ipptr->next;
freeanipn(ipptr);
ipptr = tipn;
}
iproot = NULL;
ipptr = NULL;
}
elementpnode *createelementpnode(char *name, char *data)
{
elementpnode *anepn = (elementpnode *) malloc(sizeof(elementpnode));
if (anepn == NULL) return NULL; /* OoM! */
memset(anepn, 0, sizeof(elementpnode));
anepn->next = NULL;
anepn->attlist = NULL;
anepn->isattribute = 0;
if (name == NULL) anepn->name = NULL;
else
{
anepn->name = (char *) malloc(sizeof(char) * (strlen(name)+1));
if (anepn->name == NULL)
{
free(anepn);
return NULL; /* OoM! */
}
strcpy(anepn->name, name);
}
if (data == NULL) anepn->data = NULL;
else
{
anepn->data = (char *) malloc(sizeof(char) * (strlen(data)+1));
if (anepn->data == NULL)
{
if (anepn->name != NULL) free(anepn->name);
free(anepn);
return NULL; /* OoM! */
}
strcpy(anepn->data, data);
}
if (eproot == NULL) eproot = anepn;
else
{
for (epptr = eproot; epptr->next != NULL; epptr = epptr->next) {}
epptr->next = anepn;
}
return anepn;
}
elementpnode *addatttoepn(char *name, char *data, elementpnode *epn)
{
if (epn == NULL) return NULL;
elementpnode *anepn = (elementpnode *) malloc(sizeof(elementpnode));
elementpnode *epnaptr;
if (anepn == NULL) return NULL; /* OoM! */
memset(anepn, 0, sizeof(elementpnode));
anepn->next = NULL;
anepn->attlist = NULL;
anepn->isattribute = 1;
if (name == NULL) anepn->name = NULL;
else
{
anepn->name = (char *) malloc(sizeof(char) * (strlen(name)+1));
if (anepn->name == NULL)
{
free(anepn);
return NULL; /* OoM! */
}
strcpy(anepn->name, name);
}
if (data == NULL) anepn->data = NULL;
else
{
anepn->data = (char *) malloc(sizeof(char) * (strlen(data)+1));
if (anepn->data == NULL)
{
if (anepn->name != NULL) free(anepn->name);
free(anepn);
return NULL; /* OoM! */
}
strcpy(anepn->data, data);
}
if (epn->attlist == NULL) epn->attlist = anepn;
else
{
for (epnaptr = epn->attlist; epnaptr->next != NULL; epnaptr = epnaptr->next) {}
epnaptr->next = anepn;
}
return anepn;
}
void freeepn(elementpnode *epn)
{
elementpnode *tepn = NULL;
if (epn == NULL) return;
if (epn->name != NULL) free(epn->name);
if (epn->data != NULL) free(epn->data);
if (epn->isattribute == 0)
{
epptr = epn->attlist;
while (epptr != NULL)
{
tepn = epptr->next;
freeepn(epptr);
epptr = tepn;
}
epn->attlist = NULL;
tepn = NULL;
for (epptr = eproot; epptr != NULL; epptr = epptr->next)
{
if (epptr == epn) break;
tepn = epptr;
}
if (epptr == NULL)
{
free(epn);
return;
}
if (tepn == NULL) eproot = epptr->next;
else tepn->next = epptr->next;
free(epn);
epptr = NULL;
}
else free(epn);
}
int parsersstoll(FILE *rf)
{
/* Returns: 1=worked, 0=File reading error, -1=Memory error, -2=Not RSS */
char curelementname[MAX_ELEN+1] = "", curattname[MAX_ATTN+1] = "", *curelementdata, *curattdata;
long ceni=0,cani=0,cedi=0,cadi=0;
char *title = NULL, *link = NULL, *desc = NULL;
char cchar = 0;
int inatt = 0, inelename = 0, ineletag = 0, inctag = 0, inattname = 0,
inattdata = 0, issingletag = 0, initem = 0, inchan = 0, inimage = 0,
intxtinp = 0, indq = 0;
elementpnode *curepn = NULL;
itempropnode *curitem = NULL;
chanpropnode *curchan = NULL;
curelementdata = (char *) malloc(sizeof(char)*(MAX_ELED+1));
if (curelementdata == NULL) return -1; /* OoM! */
curattdata = (char *) malloc(sizeof(char)*(MAX_ATTD+1));
if (curattdata == NULL)
{
free(curelementdata);
return -1; /* OoM! */
}
curelementdata[0] = 0;
curattdata[0] = 0;
/* Hopefully, this won't fall down on XML comments... */
#ifdef DEBUG
unsigned long epndepth = 0; /* Not sure this stays accurate all the way through... */
#endif
while ((cchar = (char) fgetc(rf)) != EOF)
{
if (cchar == '<')
{
if ((!ineletag))
{
inelename = 1;
ineletag = 1;
curelementdata[cedi] = 0;
cedi = 0;
indq = 0; /* Force indq to be off, as quotes outside the tag don't matter! */
}
} /* ENDIF '<' */
else if (cchar == '?' || cchar == '!')
{
if (inelename)
{
issingletag = 1;
}
else
{
/* Add to whatever... */
if (ineletag && inelename && ceni<MAX_ELEN)
{ /* Shouldn't occur */
curelementname[ceni] = cchar;
ceni++;
curelementname[ceni] = 0;
if (issingletag && (endwith_(curelementname,"[CDATA[") || endwith_(curelementname,"![CDATA[")))
{
issingletag = 0;
inelename = 0;
ineletag = 0;
ceni = 0;
cedi = strlen(curelementdata);
}
}
else if (ineletag && inattname && cani<MAX_ATTN)
{
curattname[cani] = cchar;
cani++;
}
else if (ineletag && inattdata && cadi<MAX_ATTD)
{
curattdata[cadi] = cchar;
cadi++;
}
else if ((!ineletag) && curepn != NULL && cedi<MAX_ELED)
{
curelementdata[cedi] = cchar;
cedi++;
curelementdata[cedi] = 0;
if (endwith_(curelementdata,"]]>"))
{ /* Shouldn't happen */
cedi -= (3*sizeof(char));
curelementdata[cedi] = 0;
}
}
}
} /* ENDIF '?' or '!' */
else if (cchar == '\r')
{
/* Ignore these */
} /* ENDIF '\r' */
else if (cchar == ' ' || cchar == '\t' || cchar == '\n')
{
if (ineletag && inelename && !inctag && ceni>0)
{
/* End of the name, going into an attribute. */
inelename = 0;
curelementname[ceni] = 0;
#ifdef DEBUG
printf("Found element \"%s\"",curelementname);
#endif
curepn = createelementpnode(curelementname,NULL);
#ifdef DEBUG
epndepth++;
printf("[%lu]\n",epndepth);
#endif
if (curepn == NULL)
{
/* Free everything and end */
goto OOMEMERROR;
}
inattname = 1;
ceni = 0;
if (streq_i(curepn->name,"item")) initem = 1;
else if (streq_i(curepn->name,"channel")) inchan = 1;
else if (streq_i(curepn->name,"image")) inimage = 1;
else if (streq_i(curepn->name,"textinput")) intxtinp = 1;
}
else if (ineletag && inattname)
{
/* Do Nothing. Attribute names shouldn't contain spaces, so let's assume it's a typo */
}
else if (ineletag && inattdata)
{
if (indq)
{ /* Inside attribute data quoted text */
/* Add to whatever... */
if (ineletag && inelename && ceni<MAX_ELEN)
{ /* Shouldn't happen? */
curelementname[ceni] = cchar;
ceni++;
curelementname[ceni] = 0;
if (issingletag && (endwith_(curelementname,"[CDATA[") || endwith_(curelementname,"![CDATA[")))
{
issingletag = 0;
inelename = 0;
ineletag = 0;
ceni = 0;
cedi = strlen(curelementdata);
}
}
else if (ineletag && inattname && cani<MAX_ATTN)
{ /* Also shouldn't happen? */
curattname[cani] = cchar;
cani++;
}
else if (ineletag && inattdata && cadi<MAX_ATTD)
{
curattdata[cadi] = cchar;
cadi++;
}
else if ((!ineletag) && curepn != NULL && cedi<MAX_ELED)
{ /* Also shouldn't happen? */
curelementdata[cedi] = cchar;
cedi++;
curelementdata[cedi] = 0;
if (endwith_(curelementdata,"]]>"))
{
cedi -= (3*sizeof(char));
curelementdata[cedi] = 0;
}
}
}
else
{ /* Outside double quotes - end of attribute data */
inattname = 1;
inattdata = 0;
curattdata[cadi] = 0;
cadi = 0;
if (addatttoepn(curattname, curattdata, curepn) == NULL)
{
/* Free everything and end! */
goto OOMEMERROR;
}
#ifdef DEBUG
printf("Attribute [of '%s'] '%s' = '%s'\n",curepn->name,curattname, curattdata);
#endif
}
}
else
{ /* !ineletag || (inctag && !(inattname || inattdata)) || ceni==0 */
/* Add to whatever... */
if (ineletag && inelename && !inctag && ceni>0 && ceni<MAX_ELEN) /* Warning: non-standard! */
{ /* Shouldn't happen if my boolean algebra is correct. */
curelementname[ceni] = cchar;
ceni++;
curelementname[ceni] = 0;
if (issingletag && (endwith_(curelementname,"[CDATA[") || endwith_(curelementname,"![CDATA[")))
{
issingletag = 0;
inelename = 0;
ineletag = 0;
ceni = 0;
cedi = strlen(curelementdata);
}
}
else if (ineletag && inattname && cani<MAX_ATTN)
{ /* Shouldn't really happen either?! */
curattname[cani] = cchar;
cani++;
}
else if (ineletag && inattdata && cadi<MAX_ATTD)
{ /* Shouldn't really happen either */
curattdata[cadi] = cchar;
cadi++;
}
else if ((!ineletag) && curepn != NULL && cedi<MAX_ELED)
{
curelementdata[cedi] = cchar;
cedi++;
curelementdata[cedi] = 0;
if (endwith_(curelementdata,"]]>"))
{
cedi -= (3*sizeof(char));
curelementdata[cedi] = 0;
}
}
/* else would be ((!ineletag && curepn==NULL) || (!ineletag && edi>=MAX_ELED) || (inctag && !(inattname || inattdata) && (ineletag || curepn==NULL || cedi>=MAX_ELED))
|| ((ceni==0) && ineletag) || ((ceni==0) && curepn==NULL) || ((ceni==0) && cedi>=MAX_ELED))
i.e.: text on the feed outside any tags at all, tag data out of range, in a closing tag name, in a closing tag while element data is at/out of range, at the start of a tag, Outside everything, at the start of the first element, OR element data is out of range.
I don't think we need to account for these cases, but I could be wrong. */
}
} /* ENDIF '\n' or ' ' or '\t' */
else if (cchar == '"')
{
indq = 1 - indq;
#ifdef DEBUG
printf("Double Quotes turned to %d\n", indq);
#endif
/* Add to whatever... */
if (ineletag && inelename && ceni<MAX_ELEN)
{ /* In the name of the tag and in range so add it to name. Not sure why I do this? */
curelementname[ceni] = cchar;
ceni++;
curelementname[ceni] = 0;
if (issingletag && (endwith_(curelementname,"[CDATA[") || endwith_(curelementname,"![CDATA[")))
{ /* This shouldn't happen. */
issingletag = 0;
inelename = 0;
ineletag = 0;
ceni = 0;
cedi = strlen(curelementdata);
}
}
else if (ineletag && inattname && cani<MAX_ATTN)
{ /* In the attribute name of a tag and there's space, so add it to the name. I wonder if this combined with the inverting of indq is causing problems? */
curattname[cani] = cchar;
cani++;
}
else if (ineletag && inattdata && cadi<MAX_ATTD)
{ /* ERK! I don't think I should be doing this!!! TODO: Check that they're being taken out or insq is on! */
/* ---Possibly remove?!--- */
curattdata[cadi] = cchar;
cadi++;
}
else if ((!ineletag) && curepn != NULL && cedi<MAX_ELED)
{
curelementdata[cedi] = cchar;
cedi++;
curelementdata[cedi] = 0;
if (endwith_(curelementdata,"]]>"))
{
cedi -= (3*sizeof(char));
curelementdata[cedi] = 0;
}
}
/* Else conditions: (Analysis was logic684.txt)
(!ineletag && curepn==NULL) || (cedi>=MAX_ELED && !ineletag) ||
(!inelename && ineletag && !inattdata && !inattname) || (!inelename && ineletag && !inattdata && cani>=MAX_ATTN) ||
(!inelename && ineletag && cadi>=MAX_ATTD && !inattname) || (!inelename && ineletag && cadi>=MAX_ATTD && cani>=MAX_ATTN) ||
(!inelename && curepn==NULL && !inattdata && !inattname )|| (!inelename && curepn==NULL && !inattdata && cani>=MAX_ATTN) ||
(!inelename && curepn==NULL && cadi>=MAX_ATTD && !inattname) || (!inelename && curepn==NULL && cadi>=MAX_ATTD && cani>=MAX_ATTN) ||
(!inelename && cedi>=MAX_ELED && !inattdata && !inattname) || (!inelename && cedi>=MAX_ELED && !inattdata && cani>=MAX_ATTN) ||
(!inelename && cedi>=MAX_ELED && cadi>=MAX_ATTD && !inattname) || (!inelename && cedi>=MAX_ELED && cadi>=MAX_ATTD && cani>=MAX_ATTN) ||
(ceni>=MAX_ELEN && ineletag && !inattdata && !inattname) || (ceni>=MAX_ELEN && ineletag && !inattdata && cani>=MAX_ATTN) ||
(ceni>=MAX_ELEN && ineletag && cadi>=MAX_ATTD && !inattname) || (ceni>=MAX_ELEN && ineletag && cadi>=MAX_ATTD && cani>=MAX_ATTN) ||
(ceni>=MAX_ELEN && curepn==NULL && !inattdata && !inattname) || (ceni>=MAX_ELEN && curepn==NULL && !inattdata && cani>=MAX_ATTN) ||
(ceni>=MAX_ELEN && curepn==NULL && cadi>=MAX_ATTD && !inattname) || (ceni>=MAX_ELEN && curepn==NULL && cadi>=MAX_ATTD && cani>=MAX_ATTN) ||
(ceni>=MAX_ELEN && cedi>=MAX_ELED && !inattdata && !inattname) || (ceni>=MAX_ELEN && cedi>=MAX_ELED && !inattdata && cani>=MAX_ATTN) ||
(ceni>=MAX_ELEN && cedi>=MAX_ELED && cadi>=MAX_ATTD && !inattname) || (ceni>=MAX_ELEN && cedi>=MAX_ELED && cadi>=MAX_ATTD && cani>=MAX_ATTN)
i.e.: Not in a tag and outside the RSS feed,
> Not in a tag and data is at/out of range,
In a tag but not in the name or attribute (impossible),
> In a tag's attribute name when the name is at/out of range,
> In a tag's arttribute data when the data is at/out of range,
> In a tag's attribute (name or data) when the name and data are at/out of range,
Outside the RSS feed and not in any tag field (functionally equivalent to first of these conditions),
> Outside the RSS feed and maybe in an attribute name but the attribute name is at/out of range,
> Outside the RSS feed and maybe in an attribute's data but the attribute data is at/out of range,
> Outside the RSS feed and maybe in an attribute but the attribute's name and data are at/out of range,
> In the data of a tag but it's at/out of range,
> In the attribute's name or the tag's data but both are at/out of range,
> In the attribute's or tag's data but both are at/out of range,
> At some point after the tag name but everything else is at/out of range,
> In the tag name but it's at/out of range,
> In tag's or attribute's name but they're both at/out of range,
> In the tag's name or attribute's data but both are at/out of range,
> In the tag but all tag fields are at/out of range,
The RSS feed's first tag name is at/out of range,
The RSS feed's first tag's and tag's attribute name is at/out of range,
The RSS feed's first tag name and attribuute data are at/out of range,
The RSS feed's first tag's fields are all att/out of range,
> In a tag's name or (more likely) data and they're both at/out of range,
> In a tag's or attribute's name or (more likely) data and they're all at/out of range,
> In a tag's name or attribute's or (most likely) tag's data and they're all at/out of range,
> All a tag's fields and data are out of range.
Result: I need to add some conditions... */
else if ((inelename && ceni>=MAX_ELEN) || (inattname && cani>=MAX_ATTN) ||
(inattdata && cadi>=MAX_ATTD) || (!ineletag && cedi>=MAX_ELED))
{
/* Ensure double quotes are OFF (fix for lines marked with '>'). */
/* Wait! This could cause problems with a '>' or a '=' that has been quoted but is out of range! To be safe, I'm commenting this out. */
/*indq = 0;*/
}
} /* ENDIF '"' */
else if (cchar == '=')
{
if (inattname && ineletag)
{
/* Should we REALLY be ignoring Double Quotes here? I'm not sure... */
inattname = 0;
inattdata = 1;
curattname[cani] = 0;
cani = 0;
#ifdef DEBUG
/* printf("(Att='%s')\t",curattname);*/
#endif
}
else
{
/* Add to whatever... */
if (ineletag && inelename && ceni<MAX_ELEN)
{
curelementname[ceni] = cchar;
ceni++;
curelementname[ceni] = 0;
if (issingletag && (endwith_(curelementname,"[CDATA[") || endwith_(curelementname,"![CDATA[")))
{
issingletag = 0;
inelename = 0;
ineletag = 0;
ceni = 0;
cedi = strlen(curelementdata);
}
}
else if (ineletag && inattname && cani<MAX_ATTN) /* Shouldn't occur */
{
curattname[cani] = cchar;
cani++;
#ifdef DEBUG
fprintf(stderr, "This is an error you should never see: something has gone VERY wrong!\n");
#endif
}
else if (ineletag && inattdata && cadi<MAX_ATTD)
{
curattdata[cadi] = cchar;
cadi++;
}
else if ((!ineletag) && curepn != NULL && cedi<MAX_ELED)
{
curelementdata[cedi] = cchar;
cedi++;
curelementdata[cedi] = 0;
if (endwith_(curelementdata,"]]>"))
{
cedi -= (3*sizeof(char));
curelementdata[cedi] = 0;
}
}
/* I ought to do some logical analysis checking here - TODO: Check this and fix any problems! */
}
}
else if (cchar == '/')
{
if (ineletag && inelename)
{
if (ceni==0 || (ceni==1 && curelementname[0]==' '))
{
/* Closing tag */
inctag = 1;
}
else if (indq == 0)
{
issingletag = 1;
}
}
else if (ineletag && inattname)
{
issingletag = 1;
}
else if (inattname)
{
/* Should never trigger */
issingletag = 1;
#ifdef DEBUG
printf("Belt & Braces for inattname was triggered!\n");
#endif
}
else if (ineletag != 0 && inattdata != 0 && indq == 0)
{
issingletag = 1;
}
else
{
/* Add to whatever... */
if (ineletag && inelename && ceni<MAX_ELEN)
{ /* Only occurs if quoted! */
curelementname[ceni] = cchar;
ceni++;
curelementname[ceni] = 0;
if (issingletag && (endwith_(curelementname,"[CDATA[") || endwith_(curelementname,"![CDATA[")))
{
issingletag = 0;
inelename = 0;
ineletag = 0;
ceni = 0;
cedi = strlen(curelementdata); /* !? Might need +1 added?! <--- NOPE! */
}
}
else if (ineletag && inattname && cani<MAX_ATTN)
{ /* Shouldn't occur! */
curattname[cani] = cchar;
cani++;
}
else if (ineletag && inattdata && cadi<MAX_ATTD)
{ /* Should only occur if quoted */
curattdata[cadi] = cchar;
cadi++;
}
else if (!ineletag && curepn != NULL && cedi<MAX_ELED)
{
curelementdata[cedi] = cchar;
cedi++;
curelementdata[cedi] = 0;
if (endwith_(curelementdata,"]]>"))
{
cedi -= (3*sizeof(char));
curelementdata[cedi] = 0;
}
}
/* Probably ought to do more logical analysis checks here. TODO: Do it and fix anything it flags up! */
}
}
else if (cchar == '>' && ineletag == 0)
{
/* Add to whatever... */
if (ineletag && inelename && ceni<MAX_ELEN)
{ /* Shouldn't happen! */
curelementname[ceni] = cchar;
ceni++;
curelementname[ceni] = 0;
if (issingletag && (endwith_(curelementname,"[CDATA[") || endwith_(curelementname,"![CDATA[")))
{
issingletag = 0;
inelename = 0;
ineletag = 0;
ceni = 0;
cedi = strlen(curelementdata);
}
}
else if (ineletag && inattname && cani<MAX_ATTN)
{ /* Shouldn't happen! */
curattname[cani] = cchar;
cani++;
}
else if (ineletag && inattdata && cadi<MAX_ATTD)
{ /* Shouldn't happen! */
curattdata[cadi] = cchar;
cadi++;
}
else if (!ineletag && curepn != NULL && cedi<MAX_ELED)
{
curelementdata[cedi] = cchar;
cedi++;
curelementdata[cedi] = 0;
if (endwith_(curelementdata,"]]>"))
{
#ifdef DEBUG
printf("Fixing ']]>'\t'%s'\t",curelementdata);
/* This is the most likely time for it to occur! */
#endif
cedi -= (3*sizeof(char));
curelementdata[cedi] = 0;
}
}
}
else if (cchar == '>' && ineletag != 0)
{ /* Ending the tag */
if (inelename || (inattname && cani==0)) /* Changed to account for "<tag >". */
{
inelename = 0;
curelementname[ceni] = 0;
if (streq_i(curelementname, "br"))
{ /* BRs are always single tags! */
issingletag = 1;
}
if (streq_i(curelementname, "itunes:image"))
{ /* Always single tags! If this bodge gets used it's indicative of a wider problem though... */
issingletag = 1;
#ifdef DEBUG
printf("Bodge used to avoid issue - check parser code!\n");
#endif
}
if (!inctag)
{
curepn = createelementpnode(curelementname,NULL);
#ifdef DEBUG
epndepth++;
printf("[%lu]",epndepth);
#endif
if (curepn == NULL)
{
/* Free everything and end */
goto OOMEMERROR;
}
#ifdef DEBUG
printf("Found element \"%s\"\n",curelementname);
#endif
}
ceni = 0;
if (streq_i(curepn->name,"item")) initem = 1;
else if (streq_i(curepn->name,"channel")) inchan = 1;
else if (streq_i(curepn->name,"image")) inimage = 1;
else if (streq_i(curepn->name,"textinput")) intxtinp = 1;
ineletag = 0;
}
else if (inattdata && !indq)
{
inattdata = 0;
inattname = 0;
curattdata[cadi] = 0;
cadi = 0;
if (addatttoepn(curattname, curattdata, curepn) == NULL)
{
/* Free everything and end! */
goto OOMEMERROR;
}
#ifdef DEBUG
printf("Attribute [of '%s'] '%s' = '%s'\n",curepn->name,curattname, curattdata);
/*printf("Attribute '%s' = '%s'\n", curattname, curattdata);*/
#endif
}
else if (inattname && cani>0)
{
inattname = 0;
curattname[cani] = 0;
cani = 0;
#ifdef DEBUG
printf("Attribute '%s' specified!\n", curattname);
#endif
}
if (inattdata != 0 && indq != 0 && inelename == 0)
{
/* Add to whatever... (Non-Standard) */
if (inattname && cani<MAX_ATTN)
{ /* Shouldn't happen! */
curattname[cani] = cchar;
cani++;
}
else if (inattdata && cadi<MAX_ATTD)
{
curattdata[cadi] = cchar;
cadi++;
}
else if ((!ineletag) && curepn != NULL && cedi<MAX_ELED)
{ /* Ought not to occur, but could if inattdata is not reset going into tag data! */
curelementdata[cedi] = cchar;
cedi++;
curelementdata[cedi] = 0;
if (endwith_(curelementdata,"]]>"))
{
#ifdef DEBUG
printf("Fixing ']]>'");
#endif
cedi -= (3*sizeof(char));
curelementdata[cedi] = 0;
}