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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
|
/*****************************************************************************
**
** Name: xml_parse.c
**
** File: XML Parser
**
** Copyright (c) 2000-2011, Broadcom Corp., All Rights Reserved.
** Broadcom Bluetooth Core. Proprietary and confidential.
**
*****************************************************************************/
#include "bt_target.h"
#include "xml_pars_api.h"
#include "data_types.h"
#include "bt_types.h"
/* The XML Parser is dependent on the Object Store. At present
** the object store resides in GOEP and hence the parser is
** dependent on GOEP. The parser only uses the Object Store
** in GOEP, so if the Object Store is separated from GOEP in the
** future, the parser will not be dependent on GOEP.
*/
#include <stdlib.h>
#include <string.h>
#ifndef BIP_TRACE_XML
#define BIP_TRACE_XML FALSE
#endif
#if (defined(BIP_TRACE_XML) && BIP_TRACE_XML == TRUE)
#define XML_TRACE_DEBUG0(m) {BT_TRACE_0(TRACE_LAYER_GOEP, TRACE_TYPE_DEBUG, m);}
#define XML_TRACE_DEBUG1(m,p1) {BT_TRACE_1(TRACE_LAYER_GOEP, TRACE_TYPE_DEBUG, m,p1);}
#define XML_TRACE_DEBUG2(m,p1,p2) {BT_TRACE_2(TRACE_LAYER_GOEP, TRACE_TYPE_DEBUG, m,p1,p2);}
#define XML_TRACE_DEBUG3(m,p1,p2,p3) {BT_TRACE_3(TRACE_LAYER_GOEP, TRACE_TYPE_DEBUG, m,p1,p2,p3);}
#define XML_TRACE_DEBUG4(m,p1,p2,p3,p4) {BT_TRACE_4(TRACE_LAYER_GOEP, TRACE_TYPE_DEBUG, m,p1,p2,p3,p4);}
#define XML_TRACE_DEBUG5(m,p1,p2,p3,p4,p5) {BT_TRACE_5(TRACE_LAYER_GOEP, TRACE_TYPE_DEBUG, m,p1,p2,p3,p4,p5);}
#define XML_TRACE_DEBUG6(m,p1,p2,p3,p4,p5,p6) {BT_TRACE_6(TRACE_LAYER_GOEP, TRACE_TYPE_DEBUG, m,p1,p2,p3,p4,p5,p6);}
#else
#define XML_TRACE_DEBUG0(m)
#define XML_TRACE_DEBUG1(m,p1)
#define XML_TRACE_DEBUG2(m,p1,p2)
#define XML_TRACE_DEBUG3(m,p1,p2,p3)
#define XML_TRACE_DEBUG4(m,p1,p2,p3,p4)
#define XML_TRACE_DEBUG5(m,p1,p2,p3,p4,p5)
#define XML_TRACE_DEBUG6(m,p1,p2,p3,p4,p5,p6)
#endif
/*****************************************************************************
** Constants
*****************************************************************************/
#define XML_ST '<'
#define XML_GT '>'
#define XML_QM '?'
#define XML_EX '!'
#define XML_EM '/' /* End Mark */
#define XML_CO ':'
#define XML_EQ '='
#define XML_SQ '\''
#define XML_DQ '"'
#define XML_AM '&'
#define XML_SC ';'
#define XML_PD '#'
#define XML_HX 'x'
#define XML_HY '-'
#define XML_LB '['
#define XML_LT_STR "lt"
#define XML_GT_STR "gt"
#define XML_AMP_STR "amp"
#define XML_APOS_STR "apos"
#define XML_QUOT_STR "quot"
#define XML_QTAG_END_STR "?>"
#define XML_COMM_STR "--"
#define XML_COMM_END_STR "-->"
#define XML_CDS_STR "[CDATA["
#define XML_CDS_END_STR "]]>"
#define XML_DOCT_STR "<'\""
static const UINT8 xml_name_srch[] = ":=/> \t\n\r";
/*****************************************************************************
** Type Definitions
*****************************************************************************/
enum
{
XML_PASS_WS,
XML_SKIP_WS,
XML_NORM_WS
};
typedef UINT16 tXML_WS_OP;
/*****************************************************************************
** Globals
**
** The global below is used as the buffer set (tXML_BFR_SET) in a local
** variable (of type tXML_MUL_STATE) in XML_Parse. The buffer set memory, is
** separated from the rest of tXML_MUL_STATE to make it easy to change the
** allocation of its memory if found necessary. See xml_alloc_bfr_set.
*****************************************************************************/
/*****************************************************************************
** Macro Functions
*****************************************************************************/
#define XML_EOS(p_st) ((p_st)->curr_res <= 0) /* End Of Store */
/* white space: " ", \t, \r, \n */
#define XML_IS_WS(c) (((c) == 0x20) || ((c) == 0x9) || \
((c) == 0xD) || ((c) == 0xA) || \
((c) == 0x00) )
/*****************************************************************************
** Function Prototypes
*****************************************************************************/
static BOOLEAN xml_get_next(tXML_MUL_STATE *, tXML_WS_OP);
static BOOLEAN xml_find_ch(tXML_MUL_STATE *, UINT8, tXML_WS_OP);
static void xml_incr_pars_res(tXML_MUL_STATE *, tXML_RESULT);
static void xml_set_bfr(tXML_MUL_STATE *, UINT8);
/* parsing static functions */
static BOOLEAN xml_elems(tXML_MUL_STATE *, BOOLEAN);
static BOOLEAN xml_qm_elem(tXML_MUL_STATE *);
static BOOLEAN xml_ex_elem(tXML_MUL_STATE *, BOOLEAN);
static BOOLEAN xml_tag_elem(tXML_MUL_STATE *);
static BOOLEAN xml_etag_elem(tXML_MUL_STATE *);
#define XML_SET_CLEAR 0
#define XML_SET_NAME 1
#define XML_SET_VALUE 2
/*****************************************************************************
** API Functions
*****************************************************************************/
void XML_InitPars(tXML_MUL_STATE *p_st, tXML_CBACK xml_cback, void *p_usr_data)
{
memset(p_st, 0, sizeof(tXML_MUL_STATE));
p_st->cback = xml_cback;
p_st->p_usr_data = p_usr_data;
/* by memset()
p_st->p_data_bfr = NULL;
p_st->next_token = 0;
p_st->curr_res = 0;
p_st->pars_res = XML_SUCCESS;
p_st->skip_next_nl = FALSE;
p_st->prefix.p = NULL;
p_st->name.p = NULL;
p_st->value.p = NULL;
p_st->prefix.len= 0;
p_st->name.len = 0;
p_st->value.len = 0;
p_st->status = XML_STS_INIT;
*/
}
/*****************************************************************************
**
** Function XML_MulParse
**
** Description
** The current implementation of the xml_pars_api supports only those
** XML-contructs needed in BPP SOAP-messages. The parser must have a
** small footprint and is therefore small and simple.
**
** According to SOAP a message must not contain the doctypedecl construct
** (production) and it must not contain Processing Instructions (PI
** production), i.e. these constructs are not supported. In addition,
** CDATA sections, any external or internal entities and the XML
** Declaration are not supported (not used in BPP). Should any of these
** be included in a message being parsed, they will be reported returning
** a warning code. The parser will then try to find the next tag.
** When the parser reports an XML-event using the callback it will always
** continue, even if the callback returns false. All strings in event
** data passed with the callback are limited to 64 bytes in size, except
** the prefix string which has 32 as max size. Consequtive XML_CHARDATA
** events are not supported. Leading and trailing white space is removed
** from the value string before sending the XML_CHARDATA event.
**
** This function and also all other helping static parsing functions use
** more than one return statement in a function. The reason is that
** a parse error has been found and to exit as soon as possible.
** If one had used only one return in each function, the path
** representing a correct xml syntax had been expressed with very deeply
** nested if-statements.
**
** Parameters
** see h-file
** Returns
** see h-file
*****************************************************************************/
tXML_RESULT XML_MulParse(tXML_MUL_STATE *p_st, tXML_OS *p_os)
{
BOOLEAN found;
BOOLEAN query, partial = FALSE;
BOOLEAN parse_ok = TRUE;
int keep_size;
tXML_RESULT res = XML_SUCCESS;
tXML_RESULT old_pars_res;
p_st->curr_res = 1; /* not EOS */
memcpy(&p_st->xml_os, p_os, sizeof(tXML_OS));
old_pars_res = p_st->pars_res;
p_st->pars_res = XML_SUCCESS;
p_st->prefix.len = 0;
p_st->name.len = 0;
p_st->value.len = 0;
p_st->p_last_stm = 0;
p_st->p_copy = 0;
#if ((defined (BIP_TRACE_XML) && BIP_TRACE_XML == TRUE) || (defined FOLDER_DEBUG_XML && FOLDER_DEBUG_XML== TRUE))
XML_TRACE_DEBUG4("XML_MulParse status:%d, pars_res: %d, begin:%x, end:x%x",
p_st->status, old_pars_res, p_os->p_begin, p_os->p_end);
#endif
/* this do-while(0) loop is to avoid too many return statements in this routine.
* it's easier to "cleanup" with only one return statement */
if(p_st->status == XML_STS_INIT)
{
p_st->p_cur = p_os->p_begin;
#if ((defined (BIP_TRACE_XML) && BIP_TRACE_XML == TRUE) || (defined FOLDER_DEBUG_XML && FOLDER_DEBUG_XML== TRUE))
XML_TRACE_DEBUG1("p_cur:x%x", p_st->p_cur);
#endif
do
{
if (!xml_get_next(p_st, XML_PASS_WS)) /* obj store empty or err */
{
res = XML_OBJ_ST_EMPTY;
break;
}
found = FALSE;
while (!XML_EOS(p_st) && !found)
{ /* skip all but top element */
if (!xml_find_ch(p_st, XML_ST, XML_PASS_WS) ||
!xml_get_next(p_st, XML_PASS_WS))
{
res = XML_ERR;
break;
}
if (p_st->next_token == XML_QM)
{
parse_ok = xml_qm_elem(p_st);
}
else if (p_st->next_token == XML_EX)
{
parse_ok = xml_ex_elem(p_st, TRUE);
}
else if (p_st->next_token == XML_EM)
{
parse_ok = FALSE;
if (!xml_get_next(p_st, XML_PASS_WS))
{
res = XML_ERR;
break;
}
}
else
{
found = TRUE;
parse_ok = TRUE;
}
if (!parse_ok)
xml_incr_pars_res(p_st, XML_ERR);
}
} while (0);
p_st->status = XML_STS_1STM;
}
else if(old_pars_res == XML_NO_PROP)
{
}
else
{
#if ((defined (BIP_TRACE_XML) && BIP_TRACE_XML == TRUE) || (defined FOLDER_DEBUG_XML && FOLDER_DEBUG_XML== TRUE))
XML_TRACE_DEBUG2("p_st->last_bfr.p:x%x, p_st->used_last_bfr:%d",
p_st->last_bfr.p, p_st->used_last_bfr);
#endif
/* if there was some data left, read it here. */
if(p_st->partial_st.last_bfr.p && p_st->partial_st.used_last_bfr )
{
memcpy(p_st->last_bfr.p, p_st->partial_st.last_bfr.p, p_st->partial_st.used_last_bfr);
p_st->used_last_bfr = p_st->partial_st.used_last_bfr;
p_st->last_bfr.p[p_st->partial_st.used_last_bfr] = 0;
p_st->event_data.part.parse = p_st->partial_st.event_data.part.parse;
/* set length to 0 */
p_st->partial_st.used_last_bfr = 0;
XML_TRACE_DEBUG1("retrieved PARTIAL data = [%s]\n", p_st->last_bfr.p);
p_st->p_cur = p_st->last_bfr.p;
/* continuation packet */
/* read a ch, setup xml_set_bfr */
xml_get_next(p_st, XML_PASS_WS);
p_st->event_data.copy.p_begin = p_st->xml_os.p_begin;
p_st->event_data.copy.last.p = p_st->last_bfr.p;
p_st->event_data.copy.last.len = p_st->used_last_bfr;
p_st->cback(XML_COPY, &(p_st->event_data), p_st->p_usr_data);
}
else
{
if(p_st->used_last_bfr == 0)
{
p_st->p_cur = p_os->p_begin;
xml_get_next(p_st, XML_PASS_WS);
}
else
return XML_NO_MEM;
}
#if ((defined (BIP_TRACE_XML) && BIP_TRACE_XML == TRUE) || (defined FOLDER_DEBUG_XML && FOLDER_DEBUG_XML== TRUE))
XML_TRACE_DEBUG1("p_st->p_cur:x%x", p_st->p_cur);
#endif
}
XML_TRACE_DEBUG0("XML_MulParse end while");
if(res == XML_SUCCESS)
{
/* here we found "<(a-z)" */
if (!XML_EOS(p_st))
{
if(p_st->status == XML_STS_1STM)
{
/* remeber the beginning position right after '<' in the first line */
/* if the first line can't be parsed at first round, save it to the second parse */
p_st->p_copy = p_st->p_cur - 1;
parse_ok = xml_tag_elem(p_st);
}
/* parsed the first line */
XML_TRACE_DEBUG0("XML_MulParse exit xml_tag_elem");
if (!parse_ok)
{
query = p_st->cback(XML_QUERY, &(p_st->event_data), p_st->p_usr_data);
/* if first line parsing is not completed while reach the end of stack, ERROR occurs */
if (query == TRUE)
xml_incr_pars_res(p_st, XML_ERR);
else /* first line parsing to be continued, copy partial data at later point*/
partial = TRUE;
}
else /* first line is parsed ok, change parsing status */
p_st->status = XML_STS_1TAG;
if (!XML_EOS(p_st) && parse_ok)
{
parse_ok = xml_elems(p_st, parse_ok);
query = p_st->cback(XML_QUERY, &(p_st->event_data), p_st->p_usr_data);
if (parse_ok == FALSE || query == FALSE)
{
partial = TRUE;
}
else
p_st->status = XML_STS_DONE;
}
/* copy partial data if any */
if (partial)
{
if(p_st->pars_res == XML_NO_PROP)
{
p_st->p_cur = p_st->p_copy;
p_st->event_data.part.parse = p_st->pars_res;
p_st->event_data.part.p_keep = p_st->p_cur;
XML_TRACE_DEBUG1("p_st->p_cur:x%x (last_stm)", p_st->p_cur);
p_st->cback(XML_PARTIAL, &(p_st->event_data), p_st->p_usr_data);
xml_incr_pars_res(p_st, XML_NO_END);
}
else
{
if( p_st->last_bfr.p &&
(p_st->p_copy > p_st->xml_os.p_begin) &&
(p_st->p_copy < p_st->xml_os.p_end) )
{
keep_size = p_st->xml_os.p_end - p_st->p_copy;
if(keep_size < p_st->last_bfr.len)
{
/* store the partial data to a temporary buffer,
NOT to the queue of buffers as it would overwrite current ones! */
if(p_st->partial_st.last_bfr.p )
{
XML_TRACE_DEBUG0("Store partial data\n");
BCM_STRNCPY_S((char *)p_st->partial_st.last_bfr.p, 512, (char *)p_st->p_copy, keep_size);
p_st->partial_st.used_last_bfr= keep_size;
p_st->partial_st.last_bfr.p[keep_size] = 0;
p_st->partial_st.event_data.part.parse = p_st->pars_res;
p_st->partial_st.event_data.part.p_keep= p_st->last_bfr.p;
}
else
XML_TRACE_DEBUG0("ERROR to store partial data");
p_st->cback(XML_PARTIAL, &(p_st->event_data), p_st->p_usr_data);
xml_incr_pars_res(p_st, XML_NO_END);
}
}
}/* else NO_PROP */
} /* end of partial */
} /* end of !XML_EOS(p_st) */
} /* end of res == XML_SUCCESS */
return p_st->pars_res;
}
/*****************************************************************************
** Static Functions
*****************************************************************************/
/*****************************************************************************
**
** Function xml_set_bfr
**
** Description
** Sets the buffer that is going to be used when tokens are pushed from
** p_st->next_token into some buffer in the buffer set.
**
** Parameters
** p_st (in/out) : the parser state
** p_bfr (in) : the buffer that will get all tokens (characters)
** NULL is allowed in which case no buffer is used.
** bfr_max_ind (in) : the max index into the buffer in which a non-null
** char may be stored
**
** Returns
** -
*****************************************************************************/
static void xml_set_bfr(tXML_MUL_STATE *p_st, UINT8 set)
{
switch(set)
{
case XML_SET_NAME:
p_st->name.p = p_st->p_cur - 1;
p_st->p_data_bfr = p_st->name.p;
p_st->name.len = 0;
break;
case XML_SET_VALUE:
p_st->value.p = p_st->p_cur - 1;
p_st->p_data_bfr = p_st->value.p;
p_st->value.len = 0;
break;
default:
p_st->p_data_bfr = NULL;
}
}
/*****************************************************************************
**
** Function xml_write_bfr
**
** Description
** Pushes (copies) the character from p_st->next_token to the buffer, if
** any, that has been set calling xml_set_bfr.
**
** Parameters
** p_st (in/out) : the parser state
**
** Returns
** -
*****************************************************************************/
static void xml_write_bfr(tXML_MUL_STATE *p_st)
{
if (p_st->p_data_bfr)
{
if(p_st->p_data_bfr == p_st->name.p)
p_st->name.len++;
else
p_st->value.len++;
}
}
/*****************************************************************************
**
** Function xml_incr_pars_res
**
** Description
** Sets the final parsing result if the new_res provided has
** higher rank than the current parsing result.
**
** Parameters
** p_st (in/out) : the parser state
** new_res (in) : the new parsing result
**
** Returns
** -
*****************************************************************************/
static void xml_incr_pars_res(tXML_MUL_STATE *p_st, tXML_RESULT new_res)
{
if (new_res > p_st->pars_res)
{
switch(p_st->pars_res)
{
/* preserve these error messages */
case XML_OBJ_ST_EMPTY:
case XML_NO_MEM: /* no last_bfr.p, and the tXML_MUL_STATE is not in init */
case XML_NO_PROP: /* run out of tXML_PROP */
break;
default:
/*
case XML_SUCCESS:
case XML_WARNING:
case XML_ERR:
*/
p_st->pars_res = new_res;
break;
}
}
}
/*****************************************************************************
**
** Function xml_read_char
**
** Description
*****************************************************************************/
static void xml_read_char(tXML_MUL_STATE *p_st)
{
BOOLEAN get_new = FALSE;
if (p_st->p_cur && p_st->p_cur >= p_st->last_bfr.p && p_st->p_cur < (p_st->last_bfr.p + p_st->used_last_bfr))
{
/* left over from previous parse */
p_st->next_token = *p_st->p_cur;
if(p_st->next_token == 0)
{
/* leftover is done, use the new one */
p_st->p_cur = p_st->xml_os.p_begin;
p_st->last_bfr.p[0] = 0;
p_st->used_last_bfr = 0;
get_new = TRUE;
}
else
{
p_st->p_cur++;
p_st->curr_res = 1;
}
}
else
{
if(p_st->p_cur == (p_st->last_bfr.p + p_st->used_last_bfr))
{
p_st->used_last_bfr = 0;
p_st->p_cur = p_st->xml_os.p_begin;
}
get_new = TRUE;
}
if(get_new)
{
if(p_st->p_cur && p_st->p_cur < p_st->xml_os.p_end)
{
/* use buffer given to XML_Parse */
p_st->next_token = *p_st->p_cur;
p_st->p_cur++;
p_st->curr_res = 1;
}
else
p_st->curr_res = 0;
}
/*
XML_TRACE_DEBUG4("xml_read_char p_cur: x%x, curr_res:%d, get_new:%d, token:%c",
p_st->p_cur, p_st->curr_res, get_new, p_st->next_token);
*/
}
/*****************************************************************************
**
** Function xml_get_next
**
** Description
** Writes the character in p_st->next_token to the current buffer if set.
** Then the next character is read from the Object Store into
** p_st->next_token. The first time get_next is called, the current
** buffer must be NULL, i.e p_st->data_bfr must be NULL.
**
** xml_get_next handles end-of-line as specified in the xml spec. It
** passes, skips or normalises (p.29 in XML spec) white spaces (ws)
** as specified in the ws_op param. Note, the ws_op applies when
** getting one (or many characters) from Object Store into the
** p_st->next_token. It does not apply when pushing the (initial)
** p_st->next_token to the current buffer.
**
** The characters are read one by one from the Object Store.
** Presently this is not anticipated to cause any problems
** regarding reading speed. Should it become a problem in the
** future, a new buffer could be introduced into which a chunk
** of characters could be put, using one Object Store read call.
** The get_next function would then get the next character from
** the new buffer.
**
** Parameters
** p_st (in/out) : the parser state
** ws_op (in) : the requested white space handling.
**
** Returns
** True if a character was successfully read into p_st->next_token.
** False otherwise.
*****************************************************************************/
static BOOLEAN xml_get_next(tXML_MUL_STATE *p_st, tXML_WS_OP ws_op)
{
xml_write_bfr(p_st);
do
{
xml_read_char(p_st);
} while ((ws_op == XML_SKIP_WS) && XML_IS_WS(p_st->next_token) &&
!XML_EOS(p_st));
/* handle end-of-line if any after the do-while above */
if (!XML_EOS(p_st) && (p_st->next_token == 0xA) && p_st->skip_next_nl)
{ /* we have previously found 0xD (cr) and have set the state var
** p_st->skip_next_nl,see below
*/
xml_read_char(p_st);
}
p_st->skip_next_nl = FALSE;
if (XML_EOS(p_st))
{
p_st->next_token = 0;
return FALSE;
}
if (p_st->next_token == 0xD)
{
p_st->next_token = 0xA;
p_st->skip_next_nl = TRUE;
}
if ((ws_op == XML_NORM_WS) &&
((p_st->next_token == 0xA) || (p_st->next_token == 0x9)))
{
p_st->next_token = 0x20;
}
return TRUE;
}
/*****************************************************************************
**
** Function xml_find_ch
**
** Description
** Searches for the character given in ch. It starts searching in
** p_st->next_token and if not found it gets characters from the Object
** Store until ch is in p_st->next_token.
**
** Parameters
** p_st (in/out) : the parser state
** ch (in) : the character to search for
** ws_op (in) : the requested white space handling when getting chars
**
** Returns
** True if the character was found.
** False otherwise.
*****************************************************************************/
static BOOLEAN xml_find_ch(tXML_MUL_STATE *p_st, UINT8 ch, tXML_WS_OP ws_op)
{
while (!XML_EOS(p_st) && (p_st->next_token != ch))
xml_get_next(p_st, ws_op);
return (BOOLEAN) !XML_EOS(p_st);
}
/*****************************************************************************
**
** Function xml_find_ch_n
**
** Description
** Same function as xml_find_ch, except that any character in p_str
** that is found will stop the search.
**
** Parameters
** p_st (in/out) : the parser state
** p_str (in) : the string containing the characters searched for.
** Must not be NULL or an empty string.
**
** Returns
** True if any of the characters in p_str was found.
** Fase otherwise.
*****************************************************************************/
static BOOLEAN xml_find_ch_n(tXML_MUL_STATE *p_st, const UINT8 *p_str)
{
const UINT8 *p_tmp;
while (!XML_EOS(p_st))
{
for (p_tmp = p_str; *p_tmp; p_tmp++)
{
if (p_st->next_token == *p_tmp)
return TRUE;
}
xml_get_next(p_st, XML_PASS_WS);
}
return FALSE;
}
/*****************************************************************************
**
** Function xml_find_str
**
** Description
** Searches for p_str (i.e the exact sequence of characters in p_str) in
** the input from Object Store. The function ends with the character
** succeeding p_str in the input, (i.e that char is in p_st->next_token
** upon return) or with XML_EOS.
**
** Parameters
** p_st (in/out) : the parser state
** p_str (in) : the string to search for and pass by.
** Must not be NULL or an empty string.
**
** Returns
** True if the string was found.
** False otherwise.
*****************************************************************************/
static BOOLEAN xml_find_str(tXML_MUL_STATE *p_st, const UINT8 *p_str)
{
const UINT8 *p_tmp;
p_tmp = p_str;
while (*p_tmp && !XML_EOS(p_st))
{
for (p_tmp = p_str; *p_tmp && !XML_EOS(p_st); p_tmp++)
{
if (p_st->next_token != *p_tmp)
break;
xml_get_next(p_st, XML_PASS_WS);
}
if ((p_tmp == p_str) && !XML_EOS(p_st))
{
xml_get_next(p_st, XML_PASS_WS);
}
}
return (BOOLEAN) (*p_tmp == 0);
}
/*****************************************************************************
**
** Function xml_consume_str
**
** Description
** Checks for p_str i.e that the first character from p_str is in
** p_st->next_token and that the successors immediately follows in the
** Object Store. The p_str must not be last in the Object Store.
**
** Parameters
** p_st (in/out) : the parser state
** p_str (in) : the string to check if present next and to pass by
** Must not be NULL.
**
** Returns
** True if the string was found and was not last in the Object Store.
** False otherwise.
*****************************************************************************/
static BOOLEAN xml_consume_str(tXML_MUL_STATE *p_st, const UINT8 *p_str)
{
do
{
if (p_st->next_token != *p_str)
return FALSE;
p_str++;
if (!xml_get_next(p_st, XML_PASS_WS))
return FALSE;
} while (*p_str);
return TRUE;
}
/*****************************************************************************
**
** Function xml_resolve_refs
**
** Description
** Resolves predefined entity references (sect. 4.6 in the XML spec)
** and character references (sect 4.1) that may be found in
** AttValue and content. (According to the XML spec it may also
** be in an EntityValue. However EntityValues are in the
** doctypedecl part which is not supported).
**
** The AttValue and content not beginning with a tag, must be
** stored in the p_st->p_bfr_set->value buffer.
**
** Parameters
** p_st (in/out) : the parser state
**
** Returns
** -
*****************************************************************************/
static void xml_resolve_refs(tXML_MUL_STATE *p_st)
{
UINT8 *p_srch; /* where next search for & starts */
UINT8 *p_am; /* points to found & */
UINT8 *p_sc; /* points to found ; and succeeding chars */
UINT8 *p_start;
UINT8 *p_tmp;
UINT32 ch_code;
UINT32 tmp_code;
INT8 i;
BOOLEAN resolved;
UINT16 len_left;
p_srch = p_st->value.p;
len_left = p_st->value.len;
do
{
p_start = p_srch;
p_am = (UINT8*) strchr((char*) p_srch, XML_AM);
p_sc = p_am ? (UINT8*) strchr((char*) p_am, XML_SC) : NULL;
/* make sure the ptr does not exceed the end of the value str */
if(p_sc > (len_left + p_start))
p_sc = NULL;
if (p_am && p_sc)
{
resolved = FALSE;
p_tmp = p_am + 1;
*p_sc = 0; /* terminate the ref by replacing ; with 0 */
if (*p_tmp == XML_PD) /* character ref */
{
if (p_tmp[1] == XML_HX)
*p_tmp = '0';
else
{
for(p_tmp++; *p_tmp == '0'; p_tmp++)
{
;
}
}
ch_code = strtoul((char*) p_tmp, NULL, 0);
/* skip leading zero bytes */
for (i = 3; (i >= 0) && !(ch_code >> i * 8); i--)
{
;
}
p_tmp = p_am;
while (i >= 0)
{
/* mask out one byte and shift it rightmost */
/* preceding bytes must be zero so shift left first */
tmp_code = ch_code << ((3-i) * 8);
*p_tmp = (UINT8) (tmp_code >> 24);
p_tmp++;
i--;
}
resolved = TRUE;
}
else if (p_tmp < p_sc) /* check if predefined ref */
{
resolved = TRUE;
if (strcmp((char*) p_tmp, XML_LT_STR) == 0)
{
*p_am = XML_ST;
p_st->value.len = p_st->value.len - 3; /* remove the length for lt; */
p_st->p_cur = p_st->p_cur - 3;
}
else if (strcmp((char*) p_tmp, XML_GT_STR) == 0)
{
*p_am = XML_GT;
p_st->value.len = p_st->value.len - 3; /* remove the length for gt; */
p_st->p_cur = p_st->p_cur - 3;
}
else if (strcmp((char*) p_tmp, XML_AMP_STR) == 0)
{
*p_am = XML_AM;
p_st->value.len = p_st->value.len - 4; /* remove the length for amp; */
p_st->p_cur = p_st->p_cur - 4;
}
else if (strcmp((char*) p_tmp, XML_APOS_STR) == 0)
{
*p_am = XML_SQ;
p_st->value.len = p_st->value.len - 5; /* remove the length for apos; */
p_st->p_cur = p_st->p_cur - 5;
}
else if (strcmp((char*) p_tmp, XML_QUOT_STR) == 0)
{
*p_am = XML_DQ;
p_st->value.len = p_st->value.len - 5; /* remove the length for quot; */
p_st->p_cur = p_st->p_cur - 5;
}
else
resolved = FALSE;
}
if (resolved)
{
p_srch = p_tmp; /* will contain char after ; */
p_sc++;
while(*p_sc)
{
*p_tmp++ = *p_sc++;
}
}
else
{
*p_sc = XML_SC; /* restore the ref end */
p_srch = p_sc + 1;
}
} /* end if */
} while (*p_srch && p_am && p_sc);
}
/*****************************************************************************
**
** Function xml_remove_trail_ws
**
** Description
** Removes trailing white space from the p_st->p_data_bfr buffer.
**
** Parameters
** p_st (in/out) : the parser state
**
** Returns
** -
*****************************************************************************/
static void xml_remove_trail_ws(tXML_MUL_STATE *p_st)
{
UINT16 xx;
if(p_st->value.p)
{
xx = p_st->value.len;
while(xx && XML_IS_WS(p_st->value.p[xx-1]))
xx--;
p_st->value.len = xx;
}
}
/*****************************************************************************
** Parsing Static Functions
*****************************************************************************/
/*****************************************************************************
**
** Function xml_name
**
** Description
** Parses a name and its prefix if any. The prefix and name buffers
** are set.
** The functions ends with either white space,
** XML_EQ, XML_EM or XML_GT in p_st->next_token or with XML_EOS.
**
** Parameters
** p_st (in/out) : the parser state
**
** Returns
** True if no error was found.
** False otherwise.
*****************************************************************************/
static BOOLEAN xml_name(tXML_MUL_STATE *p_st)
{
BOOLEAN found = FALSE;
p_st->prefix.p = NULL;
p_st->prefix.len = 0;
xml_set_bfr(p_st, XML_SET_NAME);
xml_find_ch_n(p_st, xml_name_srch);
if (!XML_EOS(p_st) && (p_st->next_token == XML_CO))
{
if (p_st->name.len)
{
found = TRUE;
/* p_st->name.len is string size in name buffer, \0 excl.
*/
p_st->prefix.p = p_st->name.p;
p_st->prefix.len = p_st->name.len;
}
xml_get_next(p_st, XML_PASS_WS);
xml_set_bfr(p_st, XML_SET_NAME);
if (!XML_EOS(p_st))
{
xml_find_ch_n(p_st, xml_name_srch + 1);
}
}
found = (BOOLEAN) (found || p_st->name.len);
if(found)
xml_set_bfr(p_st, XML_SET_CLEAR);
return found;
}
/*****************************************************************************
**
** Function xml_attributes
**
** Description
** Parses an attribute list.
** The functions ends with the XML_GT or XML_EM char or XML_EOS.
** Error is reported if the attribute list is last in the Object
** Store.
** Sends a XML_ATTRIBUTE event in the user callback for each
** attribute found.
**
** Parameters
** p_st (in/out) : the parser state
**
** Returns
** True if no error was found.
** False otherwise.
*****************************************************************************/
static BOOLEAN xml_attributes(tXML_MUL_STATE *p_st)
{
BOOLEAN cb_ret = TRUE;
UINT8 q_ch;
XML_TRACE_DEBUG1("[xml_parse] xml_attributes: res= %d", p_st->pars_res);
while ( cb_ret)
{
/* if this is a white space, then the next character is read from the
Object Store into p_st->next_token */
if( XML_IS_WS(p_st->next_token) )
{
if (!xml_get_next(p_st, XML_SKIP_WS))
return FALSE;
}
if (p_st->next_token == XML_EQ)
return FALSE;
if ((p_st->next_token == XML_GT) || (p_st->next_token == XML_EM))
return TRUE;
if (!xml_name(p_st) || XML_EOS(p_st))
{
return FALSE;
}
if(XML_IS_WS(p_st->next_token))
{
if (!xml_get_next(p_st, XML_SKIP_WS))
return FALSE;
}
if (p_st->next_token != XML_EQ)
return FALSE;
if (!xml_get_next(p_st, XML_SKIP_WS))
return FALSE;
if ((p_st->next_token != XML_SQ) && (p_st->next_token != XML_DQ))
return FALSE;
q_ch = p_st->next_token;
if (!xml_get_next(p_st, XML_PASS_WS))
return FALSE;
xml_set_bfr(p_st, XML_SET_VALUE);
if (!xml_find_ch(p_st, q_ch, XML_NORM_WS))
{
return FALSE;
}
xml_set_bfr(p_st, XML_SET_CLEAR);
xml_resolve_refs(p_st);
p_st->event_data.attr.prefix.p = p_st->prefix.p;
p_st->event_data.attr.prefix.len = p_st->prefix.len;
p_st->event_data.attr.name.p = p_st->name.p;
p_st->event_data.attr.name.len = p_st->name.len;
p_st->event_data.attr.value.p = p_st->value.p;
p_st->event_data.attr.value.len = p_st->value.len;
p_st->value.len = 0;
cb_ret = p_st->cback(XML_ATTRIBUTE, &(p_st->event_data), p_st->p_usr_data);
/* chk cback return */
if(cb_ret == FALSE)
{
xml_incr_pars_res(p_st, XML_NO_PROP);
return FALSE;
}
if (!xml_get_next(p_st, XML_PASS_WS))
return FALSE;
}
return (BOOLEAN)
((p_st->next_token == XML_GT) || (p_st->next_token == XML_EM));
}
/*****************************************************************************
**
** Function xml_elems
**
** Description
** Parses all elements with all their content.This function is not a
** one-to-one mapped implementation of one production from the XML spec.
** Instead it uses a simplified iterative (as opposed to recursive)
** approach when parsing both the element and content productions.
**
** When a parsing error is found, this function tries to recover by
** searching for the next element (tag).
**
** When char data is found, the function sends the XML_CHARDATA event in
** the user callback.
**
** Other static functions with production names, start their parsing
** from the first character in their production. They might check
** that the first character (token) in the production matches
** p_st->next_token, alternatively they can just get rid of the first
** char in the production by calling get_next_ch. The exceptions to this
** are the xml_qm_elem, xml_ex_elem, xml_etag_elem and the xml_tag_elem
** functions which starts with the XML_QM, XML_EX, XML_EM and the first
** char in the tag name, respectively.
**
** Parameters
** p_st (in/out) : the parser state
** prev_ok (in) : if parsing done before calling this function was
** ok. If not, the functions starts with recovering.
**
** Returns
** True if parsing was successful possibly with successful recoveries.
** False if an error was found from which recovery failed (XML_EOS).
*****************************************************************************/
static BOOLEAN xml_elems(tXML_MUL_STATE *p_st, BOOLEAN prev_ok)
{
BOOLEAN tag_found;
BOOLEAN cb_ret = TRUE;
while (!XML_EOS(p_st) && prev_ok)
{
/* remove leading ws even if char data */
if (XML_IS_WS(p_st->next_token))
{
if (!xml_get_next(p_st, XML_SKIP_WS))
return TRUE;
}
tag_found = (BOOLEAN) (p_st->next_token == XML_ST);
if (!tag_found)
{
xml_set_bfr(p_st, XML_SET_VALUE);
tag_found = xml_find_ch(p_st, XML_ST, XML_PASS_WS);
xml_remove_trail_ws(p_st);
if (p_st->value.len > 0)
{
xml_resolve_refs(p_st);
p_st->event_data.ch_data.value.p = p_st->value.p;
p_st->event_data.ch_data.value.len = p_st->value.len;
p_st->event_data.ch_data.last = TRUE;
p_st->value.len = 0;
cb_ret = p_st->cback(XML_CHARDATA, &(p_st->event_data), p_st->p_usr_data);
/* chk cback return */
if(cb_ret == FALSE)
{
xml_incr_pars_res(p_st, XML_NO_PROP);
return FALSE;
}
}
xml_set_bfr(p_st, XML_SET_CLEAR);
if (!tag_found)
return prev_ok;
}
else
{
p_st->p_last_stm = p_st->p_cur - 1;
if (p_st->p_cur)
p_st->p_copy = p_st->p_last_stm;
p_st->cback(XML_TOP, &(p_st->event_data), p_st->p_usr_data);
}
/* tag was found */
if (!xml_get_next(p_st, XML_PASS_WS))
return FALSE;
if (p_st->next_token == XML_QM)
prev_ok = xml_qm_elem(p_st);
else if (p_st->next_token == XML_EX)
{
prev_ok = xml_ex_elem(p_st, FALSE);
}
else if (p_st->next_token == XML_EM)
{
prev_ok = xml_etag_elem(p_st);
}
else
prev_ok = xml_tag_elem(p_st);
if (!prev_ok)
xml_incr_pars_res(p_st, XML_ERR);
}
XML_TRACE_DEBUG1("xml_elems prev_ok:%d", prev_ok);
return prev_ok;
}
/*****************************************************************************
**
** Function xml_qm_elem
**
** Description
** Recognises all productions starting with "<?". That is PI and XML decl.
** These productions are skipped and XML_WARNING is set.
** The function starts with the XML_QM as the first char (is in
** p_st->next_token).It ends with the XML_GT successor (is in
** p_st->next_token) or XML_EOS.
**
** Parameters
** p_st (in/out) : the parser state
**
** Returns
** True if no error was found trying to recognise the start and end of
** the productions. False otherwise.
*****************************************************************************/
static BOOLEAN xml_qm_elem(tXML_MUL_STATE *p_st)
{
if (!xml_get_next(p_st, XML_PASS_WS))
return FALSE;
if (!xml_find_str(p_st, (UINT8*) XML_QTAG_END_STR))
return FALSE;
xml_incr_pars_res(p_st, XML_WARNING);
return TRUE;
}
/*****************************************************************************
**
** Function xml_ex_elem
**
** Description
** Handles all productions starting with "<!". They are Comments, CDSect
** doctypedecl and markupdecl. All are skipped. However, the inpar
** prolog must be set for the function to try to detect the doctypedecl
** and markupdecl beginning.
**
** The function starts with the XML_EX as the first char.
** The function ends with XML_EOS or the char succeeding XML_GT,
** except for doctypedecl and marcupdecl which ends with the next XM_TAG.
**
** Parameters
** p_st (in/out) : the parser state
** prolog (in) : should be set if in prolog in which case the function
** tries to detect (allows) the beginning of doctypedecl
** and markupdecl.
** Returns
** True if no error was found trying to recognise the start and end of
** the productions. False otherwise.
*****************************************************************************/
static BOOLEAN xml_ex_elem(tXML_MUL_STATE *p_st, BOOLEAN prolog)
{
UINT8 q_ch;
if (!xml_get_next(p_st, XML_PASS_WS))
return FALSE;
if (p_st->next_token == XML_HY) /* comment */
{
if (!xml_consume_str(p_st, (UINT8*) XML_COMM_STR))
return FALSE;
if (!xml_find_str(p_st, (UINT8*) XML_COMM_END_STR))
return FALSE;
}
else if (p_st->next_token == XML_LB) /* CDSect */
{
if (!xml_consume_str(p_st, (UINT8*) XML_CDS_STR))
return FALSE;
if (!xml_find_str(p_st, (UINT8*) XML_CDS_END_STR))
return FALSE;
xml_incr_pars_res(p_st, XML_WARNING);
}
else if (prolog) /* doctypedecl or markupdecl */
{
do
{
if (!xml_find_ch_n(p_st, (UINT8*) XML_DOCT_STR))
return FALSE;
if ((p_st->next_token == XML_SQ) || (p_st->next_token == XML_DQ))
{
q_ch = p_st->next_token;
if (!xml_get_next(p_st, XML_PASS_WS))
return FALSE;
if (!xml_find_ch(p_st, q_ch, XML_PASS_WS))
return FALSE;
xml_get_next(p_st, XML_PASS_WS);
}
} while (!XML_EOS(p_st) && (p_st->next_token != XML_ST));
xml_incr_pars_res(p_st, XML_WARNING);
}
else /* error */
{
return FALSE;
}
return TRUE;
}
/*****************************************************************************
**
** Function xml_tag_elem
**
** Description
** Parses a tag element. The function starts with the char succeeding the
** XML_ST char.
** The functions ends with the char succeeding the XML_GT char or
** with XML_EOS.
** Sends the XML_TAG and the XML_TAG_END events in a callback each.
**
** Parameters
** p_st (in/out) : the parser state
**
** Returns
** True if no error was found.
** False otherwise.
*****************************************************************************/
static BOOLEAN xml_tag_elem(tXML_MUL_STATE *p_st)
{
BOOLEAN cb_ret = TRUE;
if (!xml_name(p_st))
return FALSE;
p_st->event_data.tag.prefix.p = p_st->prefix.p;
p_st->event_data.tag.name.p = p_st->name.p;
p_st->event_data.tag.prefix.len = p_st->prefix.len;
p_st->event_data.tag.name.len = p_st->name.len;
p_st->event_data.tag.p_last_stm = p_st->p_last_stm;
cb_ret = p_st->cback(XML_TAG, &(p_st->event_data), p_st->p_usr_data);
if(cb_ret == FALSE)
{
xml_incr_pars_res(p_st, XML_NO_PROP);
return FALSE;
}
/* chk cback return */
if (XML_EOS(p_st))
return FALSE;
if (XML_IS_WS(p_st->next_token))
{
if (!xml_attributes(p_st))
return FALSE;
}
p_st->event_data.empty_elem.end = (BOOLEAN) (p_st->next_token == XML_EM);
if (p_st->event_data.empty_elem.end)
{
if (!xml_get_next(p_st, XML_PASS_WS))
return FALSE;
}
if (p_st->next_token != XML_GT)
return FALSE;
xml_get_next(p_st, XML_PASS_WS);
cb_ret = p_st->cback(XML_TAG_END, &(p_st->event_data), p_st->p_usr_data);
if(cb_ret == FALSE)
{
xml_incr_pars_res(p_st, XML_NO_PROP);
return FALSE;
}
p_st->p_copy = p_st->p_cur - 1;
p_st->cback(XML_TOP, &(p_st->event_data), p_st->p_usr_data);
/* chk cback return */
return TRUE;
}
/*****************************************************************************
**
** Function xml_etag_elem
**
** Description
** Parses an end tag element. The function starts with the XML_EM char.
** The functions ends with the char succeeding the XML_GT char or
** with XML_EOS. Sends the XML_ETAG event in the user callback.
**
** Parameters
** p_st (in/out) : the parser state
**
** Returns
** True if no error was found.
** False otherwise.
*****************************************************************************/
static BOOLEAN xml_etag_elem(tXML_MUL_STATE *p_st)
{
BOOLEAN cb_ret = TRUE;
if (!xml_get_next(p_st, XML_PASS_WS))
return FALSE;
if (!xml_name(p_st))
return FALSE;
p_st->event_data.etag.prefix.p = p_st->prefix.p;
p_st->event_data.etag.name.p = p_st->name.p;
p_st->event_data.etag.name.len = p_st->name.len;
p_st->event_data.etag.prefix.len = p_st->prefix.len;
cb_ret = p_st->cback(XML_ETAG, &(p_st->event_data), p_st->p_usr_data);
if(cb_ret == FALSE)
{
xml_incr_pars_res(p_st, XML_NO_PROP);
return FALSE;
}
p_st->p_copy = (p_st->prefix.p) ? p_st->prefix.p - 2: p_st->name.p - 2;
p_st->cback(XML_TOP, &(p_st->event_data), p_st->p_usr_data);
/* chk cback return */
if (XML_EOS(p_st))
return FALSE;
if (XML_IS_WS(p_st->next_token))
if (!xml_get_next(p_st, XML_SKIP_WS))
return FALSE;
if (p_st->next_token != XML_GT)
return FALSE;
xml_get_next(p_st, XML_PASS_WS);
return TRUE;
}
|