blob: 6a4aebb62f7dc7410c4a59d0025f1e7635b2bdf1 [file] [log] [blame]
Jeff Thompson333c4462013-06-28 14:04:22 -07001/*
2 * Author: Jeff Thompson
3 *
4 * BSD license, See the LICENSE file for more information.
5 */
6
7#include "BinaryXMLDecoder.h"
8#include "BinaryXML.h"
9#include "BinaryXMLName.h"
10
11char *ndn_decodeBinaryXMLName(struct ndn_Name *name, unsigned char *input, unsigned int inputLength)
12{
13 struct ndn_BinaryXMLDecoder decoder;
14 ndn_BinaryXMLDecoder_init(&decoder, input, inputLength);
15
16 char *error;
17 if (error = ndn_BinaryXMLDecoder_readDTag(&decoder, ndn_BinaryXML_DTag_Name))
18 return error;
19
20 while (1) {
21 int gotExpectedTag;
22 if (error = ndn_BinaryXMLDecoder_peekDTag(&decoder, ndn_BinaryXML_DTag_Component, &gotExpectedTag))
23 return error;
24
25 if (!gotExpectedTag)
26 // No more components.
27 break;
28
29 unsigned char *component;
30 unsigned int componentLen;
31 if (error = ndn_BinaryXMLDecoder_readBinaryDTagElement(&decoder, ndn_BinaryXML_DTag_Component, 0, &component, &componentLen))
32 return error;
33
34 // Add the component to the name.
35 if (name->nComponents >= name->maxComponents)
36 return "ndn_decodeBinaryXMLName: read a component past the maximum number of components allowed in the name";
37 ndn_NameComponent_init(name->components + name->nComponents, component, componentLen);
38 ++name->nComponents;
39 }
40
41 if (error = ndn_BinaryXMLDecoder_readElementClose(&decoder))
42 return error;
43
44 return 0;
45}