summaryrefslogtreecommitdiff
path: root/src/JsonParser.cc
blob: bae752866433b64e4525c70b0b0909404c4a2aab (plain)
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
/* <!-- copyright */
/*
 * aria2 - The high speed download utility
 *
 * Copyright (C) 2012 Tatsuhiro Tsujikawa
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 *
 * In addition, as a special exception, the copyright holders give
 * permission to link the code of portions of this program with the
 * OpenSSL library under certain conditions as described in each
 * individual source file, and distribute linked combinations
 * including the two.
 * You must obey the GNU General Public License in all respects
 * for all of the code used other than OpenSSL.  If you modify
 * file(s) with this exception, you may extend this exception to your
 * version of the file(s), but you are not obligated to do so.  If you
 * do not wish to do so, delete this exception statement from your
 * version.  If you delete this exception statement from all source
 * files in the program, then also delete it here.
 */
/* copyright --> */
#include "JsonParser.h"
#include "StructParserStateMachine.h"

#include "util.h"

namespace aria2 {

namespace json {

namespace {
enum {
  JSON_FINISH,
  JSON_ERROR,
  JSON_VALUE,
  JSON_OBJECT_KEY,
  JSON_OBJECT_VAL,
  JSON_OBJECT_SEP,
  JSON_ARRAY,
  JSON_ARRAY_SEP,
  JSON_STRING,
  JSON_STRING_ESCAPE,
  JSON_STRING_UNICODE,
  JSON_STRING_LOW_SURROGATE_ESCAPE,
  JSON_STRING_LOW_SURROGATE_U,
  JSON_STRING_LOW_SURROGATE,
  JSON_NUMBER,
  JSON_NUMBER_FRAC,
  JSON_NUMBER_EXP_SIGN,
  JSON_NUMBER_EXP,
  JSON_TRUE,
  JSON_FALSE,
  JSON_NULL
};
} // namespace

namespace {
const char JSON_TRUE_STR[] = "true";
const char JSON_FALSE_STR[] = "false";
const char JSON_NULL_STR[] = "null";
} // namespace

JsonParser::JsonParser(StructParserStateMachine* psm)
  : psm_(psm),
    currentState_(JSON_VALUE),
    codepoint_(0),
    codepoint2_(0),
    numberSign_(1),
    number_(0),
    frac_(0),
    expSign_(1),
    exp_(0),
    numConsumed_(0),
    lastError_(0)
{
  stateStack_.push(JSON_FINISH);
}

JsonParser::~JsonParser()
{}

namespace {
bool isSpace(char c)
{
  return util::isLws(c) || util::isCRLF(c);
}
} // namespace

ssize_t JsonParser::parseUpdate(const char* data, size_t size)
{
  size_t i;
  if(currentState_ == JSON_FINISH) {
    return 0;
  } else if(currentState_ == JSON_ERROR) {
    return lastError_;
  }
  for(i = 0; i < size && currentState_ != JSON_FINISH; ++i) {
    char c = data[i];
    switch(currentState_) {
    case JSON_ARRAY:
      if(c == ']') {
        onArrayEnd();
        break;
      } else if(isSpace(c)) {
        break;
      } else {
        int rv = pushState(currentState_);
        if(rv < 0) {
          return rv;
        }
        currentState_ = JSON_VALUE;
        runBeginCallback(STRUCT_ARRAY_DATA_T);
      }
      // Fall through
    case JSON_VALUE:
      switch(c) {
      case '{':
        currentState_ = JSON_OBJECT_KEY;
        runBeginCallback(STRUCT_DICT_T);
        break;
      case'[':
        currentState_ = JSON_ARRAY;
        runBeginCallback(STRUCT_ARRAY_T);
        break;
      case '"':
        currentState_ = JSON_STRING;
        runBeginCallback(STRUCT_STRING_T);
        break;
      case '-':
        number_ = 0;
        numberSign_ = -1;
        numConsumed_ = 0;
        currentState_ = JSON_NUMBER;
        runBeginCallback(STRUCT_NUMBER_T);
        break;
      case 't':
        numConsumed_ = 1;
        currentState_ = JSON_TRUE;
        runBeginCallback(STRUCT_BOOL_T);
        break;
      case 'f':
        numConsumed_ = 1;
        currentState_ = JSON_FALSE;
        runBeginCallback(STRUCT_BOOL_T);
        break;
      case 'n':
        numConsumed_ = 1;
        currentState_ = JSON_NULL;
        runBeginCallback(STRUCT_NULL_T);
        break;
      default:
        if(util::isDigit(c)) {
          number_ = c - '0';
          numberSign_ = 1;
          numConsumed_ = 1;
          currentState_ = JSON_NUMBER;
          runBeginCallback(STRUCT_NUMBER_T);
        } else if(!isSpace(c)) {
          currentState_ = JSON_ERROR;
          return lastError_ = ERR_UNEXPECTED_CHAR_BEFORE_VAL;
        }
      }
      break;
    case JSON_TRUE:
      if(JSON_TRUE_STR[numConsumed_] == c) {
        ++numConsumed_;
        if(numConsumed_ == sizeof(JSON_TRUE_STR)-1) {
          runBoolCallback(true);
          onBoolEnd();
        }
      } else {
        currentState_ = JSON_ERROR;
        return lastError_ = ERR_UNEXPECTED_LITERAL;
      }
      break;
    case JSON_FALSE:
      if(JSON_FALSE_STR[numConsumed_] == c) {
        ++numConsumed_;
        if(numConsumed_ == sizeof(JSON_FALSE_STR)-1) {
          runBoolCallback(false);
          onBoolEnd();
        }
      } else {
        currentState_ = JSON_ERROR;
        return lastError_ = ERR_UNEXPECTED_LITERAL;
      }
      break;
    case JSON_NULL:
      if(JSON_NULL_STR[numConsumed_] == c) {
        ++numConsumed_;
        if(numConsumed_ == sizeof(JSON_NULL_STR)-1) {
          onNullEnd();
        }
      } else {
        currentState_ = JSON_ERROR;
        return lastError_ = ERR_UNEXPECTED_LITERAL;
      }
      break;
    case JSON_OBJECT_KEY:
      switch(c) {
      case '"': {
        int rv = pushState(currentState_);
        if(rv < 0) {
          return rv;
        }
        currentState_ = JSON_STRING;
        runBeginCallback(STRUCT_DICT_KEY_T);
        break;
      }
      case '}':
        onObjectEnd();
        break;
      default:
        if(!isSpace(c)) {
          currentState_ = JSON_ERROR;
          return lastError_ = ERR_UNEXPECTED_CHAR_BEFORE_OBJ_KEY;
        }
      }
      break;

    case JSON_OBJECT_VAL:
      switch(c) {
      case ':':
        pushState(currentState_);
        currentState_ = JSON_VALUE;
        runBeginCallback(STRUCT_DICT_DATA_T);
        break;
      default:
        if(!isSpace(c)) {
          currentState_ = JSON_ERROR;
          return lastError_ = ERR_UNEXPECTED_CHAR_BEFORE_OBJ_VAL;
        }
      }
      break;
    case JSON_OBJECT_SEP:
      switch(c) {
      case ',':
        currentState_ = JSON_OBJECT_KEY;
        break;
      case '}':
        onObjectEnd();
        break;
      default:
        if(!isSpace(c)) {
          currentState_ = JSON_ERROR;
          return lastError_ = ERR_UNEXPECTED_CHAR_BEFORE_OBJ_SEP;
        }
      }
      break;
    case JSON_ARRAY_SEP:
      switch(c) {
      case ',':
        pushState(JSON_ARRAY);
        currentState_ = JSON_VALUE;
        runBeginCallback(STRUCT_ARRAY_DATA_T);
        break;
      case ']':
        onArrayEnd();
        break;
      default:
        if(!isSpace(c)) {
          currentState_ = JSON_ERROR;
          return lastError_ = ERR_UNEXPECTED_CHAR_BEFORE_ARRAY_SEP;
        }
      }
      break;
    case JSON_STRING:
      switch(c) {
      case '"':
        onStringEnd();
        break;
      case '\\':
        currentState_ = JSON_STRING_ESCAPE;
        break;
      default: {
        size_t j;
        for(j = i; j < size && data[j] != '\\' && data[j] != '"'; ++j);
        if(j - i >= 1) {
          runCharactersCallback(&data[i], j - i);
        }
        i = j - 1;
        break;
      }
      }
      break;
    case JSON_STRING_ESCAPE:
      switch(c) {
      case 'u':
        codepoint_ = 0;
        numConsumed_ = 0;
        currentState_ = JSON_STRING_UNICODE;
        break;
      default:
        switch(c) {
        case 'b':
          runCharactersCallback("\b", 1);
          break;
        case 'f':
          runCharactersCallback("\f", 1);
          break;
        case 'n':
          runCharactersCallback("\n", 1);
          break;
        case 'r':
          runCharactersCallback("\r", 1);
          break;
        case 't':
          runCharactersCallback("\t", 1);
          break;
        default: {
          char temp[1];
          temp[0] = c;
          runCharactersCallback(temp, 1);
          break;
        }
        }
        currentState_ = JSON_STRING;
      }
      break;
    case JSON_STRING_UNICODE: {
      size_t j;
      for(j = i; j < size && currentState_ == JSON_STRING_UNICODE; ++j) {
        if(util::isHexDigit(data[j])) {
          consumeUnicode(data[j]);
        } else {
          currentState_ = JSON_ERROR;
          return lastError_ = ERR_INVALID_UNICODE_POINT;
        }
      }
      i = j - 1;
      break;
    }
    case JSON_STRING_LOW_SURROGATE_ESCAPE:
      switch(c) {
      case '\\':
        currentState_ = JSON_STRING_LOW_SURROGATE_U;
        break;
      default:
        currentState_ = JSON_ERROR;
        return lastError_ = ERR_INVALID_UNICODE_POINT;
      }
      break;
    case JSON_STRING_LOW_SURROGATE_U:
      switch(c) {
      case 'u':
        codepoint2_ = 0;
        numConsumed_ = 0;
        currentState_ = JSON_STRING_LOW_SURROGATE;
        break;
      default:
        currentState_ = JSON_ERROR;
        return lastError_ = ERR_INVALID_UNICODE_POINT;
      }
      break;
    case JSON_STRING_LOW_SURROGATE: {
      size_t j;
      for(j = i; j < size && currentState_ == JSON_STRING_LOW_SURROGATE; ++j) {
        if(util::isHexDigit(data[j])) {
          int rv = consumeLowSurrogate(data[j]);
          if(rv != 0) {
            currentState_ = JSON_ERROR;
            lastError_ = rv;
            return rv;
          }
        } else {
          currentState_ = JSON_ERROR;
          return lastError_ = ERR_INVALID_UNICODE_POINT;
        }
      }
      i = j - 1;
      break;
    }
    case JSON_NUMBER: {
      size_t j;
      for(j = i; j < size && in(data[j], '0', '9'); ++j) {
        if((INT64_MAX - (data[j] - '0'))/ 10 < number_) {
          currentState_ = JSON_ERROR;
          return lastError_ = ERR_NUMBER_OUT_OF_RANGE;
        }
        number_ *= 10;
        number_ += data[j] - '0';
      }
      numConsumed_ += j - i;
      if(j != size) {
        if(numConsumed_ == 0) {
          currentState_ = JSON_ERROR;
          return lastError_ = ERR_INVALID_NUMBER;
        }
        switch(data[j]) {
        case '.':
          frac_ = 0;
          numConsumed_ = 0;
          currentState_ = JSON_NUMBER_FRAC;
          i = j;
          break;
        case 'e':
        case 'E':
          expSign_ = 1;
          exp_ = 0;
          numConsumed_ = 0;
          currentState_ = JSON_NUMBER_EXP_SIGN;
          i = j;
          break;
        default:
          onNumberEnd();
          i = j - 1;
        }
      } else {
        i = j - 1;
      }
      break;
    }
    case JSON_NUMBER_FRAC: {
      size_t j;
      for(j = i; j < size && in(data[j], '0', '9'); ++j) {
        // Take into account at most 8 digits
        if(frac_ < 100000000) {
          frac_ *= 10;
          frac_ += data[j] - '0';
        }
      }
      numConsumed_ += j - i;
      if(j != size) {
        if(numConsumed_ == 0) {
          currentState_ = JSON_ERROR;
          return lastError_ = ERR_INVALID_NUMBER;
        }
        switch(data[j]) {
        case 'e':
        case 'E':
          exp_ = 0;
          numConsumed_ = 0;
          currentState_ = JSON_NUMBER_EXP_SIGN;
          i = j;
          break;
        default:
          i = j - 1;
          onNumberEnd();
        }
      } else {
        i = j - 1;
      }
      break;
    }
    case JSON_NUMBER_EXP_SIGN:
      switch(c) {
      case '+':
        currentState_ = JSON_NUMBER_EXP;
        break;
      case '-':
        expSign_ = -1;
        currentState_ = JSON_NUMBER_EXP;
        break;
      default:
        break;
      }
      if(currentState_ == JSON_NUMBER_EXP) {
        break;
      } else {
        currentState_ = JSON_NUMBER_EXP;
        // Fall through
      }
    case JSON_NUMBER_EXP: {
      size_t j;
      for(j = i; j < size && in(data[j], '0', '9'); ++j) {
        // Take into account at most 8 digits
        exp_ *= 10;
        exp_ += data[j] - '0';
        if(exp_ > 18) {
          currentState_ = JSON_ERROR;
          return lastError_ = ERR_NUMBER_OUT_OF_RANGE;
        }
      }
      numConsumed_ += j - i;
      if(j != size) {
        if(numConsumed_ == 0) {
          currentState_ = JSON_ERROR;
          return lastError_ = ERR_INVALID_NUMBER;
        }
        switch(data[j]) {
        default:
          onNumberEnd();
        }
      }
      i = j - 1;
      break;
    }
    }
  }
  return i;
}

ssize_t JsonParser::parseFinal(const char* data, size_t len)
{
  ssize_t rv;
  rv = parseUpdate(data, len);
  if(rv >= 0) {
    if(currentState_ != JSON_FINISH) {
      rv = ERR_PREMATURE_DATA;
    }
  }
  return rv;
}

void JsonParser::reset()
{
  psm_->reset();
  currentState_ = JSON_VALUE;
  lastError_ = 0;
  while(!stateStack_.empty()) {
    stateStack_.pop();
  }
  stateStack_.push(JSON_FINISH);
}

void JsonParser::onStringEnd()
{
  runEndCallback(stateTop() == JSON_OBJECT_KEY ?
                 STRUCT_DICT_KEY_T : STRUCT_STRING_T);
  onValueEnd();
}

void JsonParser::onNumberEnd()
{
  runNumberCallback(numberSign_ * number_, frac_, expSign_ * exp_);
  runEndCallback(STRUCT_NUMBER_T);
  onValueEnd();
}

void JsonParser::onObjectEnd()
{
  runEndCallback(STRUCT_DICT_T);
  onValueEnd();
}

void JsonParser::onArrayEnd()
{
  runEndCallback(STRUCT_ARRAY_T);
  onValueEnd();
}

void JsonParser::onBoolEnd()
{
  runEndCallback(STRUCT_BOOL_T);
  onValueEnd();
}

void JsonParser::onNullEnd()
{
  runEndCallback(STRUCT_NULL_T);
  onValueEnd();
}

void JsonParser::onValueEnd()
{
  switch(stateTop()) {
  case JSON_OBJECT_KEY:
    popState();
    currentState_ = JSON_OBJECT_VAL;
    break;
  case JSON_OBJECT_VAL:
    runEndCallback(STRUCT_DICT_DATA_T);
    popState();
    currentState_ = JSON_OBJECT_SEP;
    break;
  case JSON_ARRAY:
    runEndCallback(STRUCT_ARRAY_DATA_T);
    popState();
    currentState_ = JSON_ARRAY_SEP;
    break;
  default:
    assert(stateTop() == JSON_FINISH);
    currentState_ = stateTop();
    break;
  }
}

int JsonParser::pushState(int state)
{
  if(stateStack_.size() >= 50) {
    return ERR_STRUCTURE_TOO_DEEP;
  } else {
    stateStack_.push(state);
    return 0;
  }
}

int JsonParser::stateTop() const
{
  return stateStack_.top();
}

int JsonParser::popState()
{
  int state = stateStack_.top();
  stateStack_.pop();
  return state;
}

void JsonParser::consumeUnicode(char c)
{
  codepoint_ *= 16;
  codepoint_ += util::hexCharToUInt(c);
  ++numConsumed_;
  if(numConsumed_ == 4) {
    if(in(codepoint_, 0xD800u, 0xDBFFu)) {
      // This is high-surrogate codepoint
      currentState_ = JSON_STRING_LOW_SURROGATE_ESCAPE;
    } else {
      char temp[3];
      size_t len;
      if(codepoint_ <= 0x007fu) {
        temp[0] = static_cast<char>(codepoint_);
        len = 1;
      } else if(codepoint_ <= 0x07ffu) {
        temp[0] = 0xC0u | (codepoint_ >> 6);
        temp[1] = 0x80u | (codepoint_ & 0x003fu);
        len = 2;
      } else {
        temp[0] = 0xE0u | (codepoint_ >> 12);
        temp[1] = 0x80u | ((codepoint_ >> 6) & 0x003Fu);
        temp[2] = 0x80u | (codepoint_ & 0x003Fu);
        len = 3;
      }
      runCharactersCallback(temp, len);
      currentState_ = JSON_STRING;
    }
  }
}

int JsonParser::consumeLowSurrogate(char c)
{
  codepoint2_ *= 16;
  codepoint2_ += util::hexCharToUInt(c);
  ++numConsumed_;
  if(numConsumed_ == 4) {
    if(!in(codepoint2_, 0xDC00u, 0xDFFFu)) {
      return ERR_INVALID_UNICODE_POINT;
    }
    uint32_t fullcodepoint = 0x010000u;
    fullcodepoint += (codepoint_ & 0x03FFu) << 10;
    fullcodepoint += (codepoint2_ & 0x03FFu);
    char temp[4];
    temp[0] = 0xf0u | (fullcodepoint >> 18);
    temp[1] = 0x80u | ((fullcodepoint >> 12) & 0x003Fu);
    temp[2] = 0x80u | ((fullcodepoint >> 6) & 0x003Fu);
    temp[3] = 0x80u | (fullcodepoint & 0x003Fu);
    runCharactersCallback(temp, sizeof(temp));
    currentState_ = JSON_STRING;
  }
  return 0;
}

void JsonParser::runBeginCallback(int elementType)
{
  // switch(elementType) {
  // case STRUCT_DICT_T:
  //   std::cout << "object start" << std::endl;
  //   break;
  // case STRUCT_DICT_KEY_T:
  //   std::cout << "object key start" << std::endl;
  //   break;
  // case STRUCT_DICT_DATA_T:
  //   std::cout << "object data start" << std::endl;
  //   break;
  // case STRUCT_ARRAY_T:
  //   std::cout << "array start" << std::endl;
  //   break;
  // case STRUCT_ARRAY_DATA_T:
  //   std::cout << "array data start" << std::endl;
  //   break;
  // case STRUCT_STRING_T:
  //   std::cout << "string start" << std::endl;
  //   break;
  // case STRUCT_NUMBER_T:
  //   std::cout << "number start" << std::endl;
  //   break;
  // case STRUCT_BOOL_T:
  //   std::cout << "bool start" << std::endl;
  //   break;
  // case STRUCT_NULL_T:
  //   std::cout << "null start" << std::endl;
  //   break;
  // default:
  //   break;
  // };
  psm_->beginElement(elementType);
}

void JsonParser::runEndCallback(int elementType)
{
  // switch(elementType) {
  // case STRUCT_DICT_T:
  //   std::cout << "object end" << std::endl;
  //   break;
  // case STRUCT_DICT_KEY_T:
  //   std::cout << "object key end" << std::endl;
  //   break;
  // case STRUCT_DICT_DATA_T:
  //   std::cout << "object data end" << std::endl;
  //   break;
  // case STRUCT_ARRAY_T:
  //   std::cout << "array end" << std::endl;
  //   break;
  // case STRUCT_ARRAY_DATA_T:
  //   std::cout << "array data end" << std::endl;
  //   break;
  // case STRUCT_STRING_T:
  //   std::cout << "string end" << std::endl;
  //   break;
  // case STRUCT_NUMBER_T:
  //   std::cout << "number end" << std::endl;
  //   break;
  // case STRUCT_BOOL_T:
  //   std::cout << "bool end" << std::endl;
  //   break;
  // case STRUCT_NULL_T:
  //   std::cout << "null end" << std::endl;
  //   break;
  // default:
  //   break;
  // };
  psm_->endElement(elementType);
}

void JsonParser::runCharactersCallback(const char* data, size_t len)
{
  psm_->charactersCallback(data, len);
}

void JsonParser::runNumberCallback(int64_t number, int frac, int exp)
{
  psm_->numberCallback(number, frac, exp);
}

void JsonParser::runBoolCallback(bool bval)
{
  psm_->boolCallback(bval);
}

} // namespace json

} // namespace aria2