blob: a00d3be97f667961785c61929b86813eb73ae754 [file] [log] [blame]
Jeff Thompson47eecfc2013-07-07 22:56:46 -07001/**
2 * @author: Jeff Thompson
3 * See COPYING for copyright and distribution information.
Jeff Thompsonb7f95562013-07-03 18:36:42 -07004 */
5
6#include "BinaryXMLEncoder.h"
7#include "BinaryXMLDecoder.h"
Jeff Thompson22552902013-07-07 21:26:20 -07008#include "BinaryXMLName.h"
Jeff Thompsonb7f95562013-07-03 18:36:42 -07009#include "BinaryXMLInterest.h"
10
Jeff Thompson22552902013-07-07 21:26:20 -070011char *ndn_decodeBinaryXMLInterest(struct ndn_Interest *interest, struct ndn_BinaryXMLDecoder *decoder)
Jeff Thompsonb7f95562013-07-03 18:36:42 -070012{
Jeff Thompson22552902013-07-07 21:26:20 -070013 char *error;
14 if (error = ndn_BinaryXMLDecoder_readElementStartDTag(decoder, ndn_BinaryXML_DTag_Interest))
15 return error;
16
17 if (error = ndn_decodeBinaryXMLName(&interest->name, decoder))
18 return error;
19
20 if (error = ndn_BinaryXMLDecoder_readOptionalUnsignedIntegerDTagElement
21 (decoder, ndn_BinaryXML_DTag_MinSuffixComponents, &interest->minSuffixComponents))
22 return error;
23 if (error = ndn_BinaryXMLDecoder_readOptionalUnsignedIntegerDTagElement
24 (decoder, ndn_BinaryXML_DTag_MaxSuffixComponents, &interest->maxSuffixComponents))
25 return error;
Jeff Thompsonb7f95562013-07-03 18:36:42 -070026
Jeff Thompson22552902013-07-07 21:26:20 -070027 int gotExpectedTag;
28 if (error = ndn_BinaryXMLDecoder_peekDTag(decoder, ndn_BinaryXML_DTag_PublisherPublicKeyDigest, &gotExpectedTag))
29 return error;
30 if (gotExpectedTag) {
31 if (error = ndn_BinaryXMLDecoder_readBinaryDTagElement
32 (decoder, ndn_BinaryXML_DTag_PublisherPublicKeyDigest, 0, &interest->publisherPublicKeyDigest,
33 &interest->publisherPublicKeyDigestLength))
34 return error;
35 }
36 else {
37 interest->publisherPublicKeyDigest = 0;
38 interest->publisherPublicKeyDigestLength = 0;
39 }
40
41 // TODO: Implement exclude
42
43 if (error = ndn_BinaryXMLDecoder_readOptionalUnsignedIntegerDTagElement
44 (decoder, ndn_BinaryXML_DTag_ChildSelector, &interest->childSelector))
45 return error;
46 if (error = ndn_BinaryXMLDecoder_readOptionalUnsignedIntegerDTagElement
47 (decoder, ndn_BinaryXML_DTag_AnswerOriginKind, &interest->answerOriginKind))
48 return error;
49 if (error = ndn_BinaryXMLDecoder_readOptionalUnsignedIntegerDTagElement
50 (decoder, ndn_BinaryXML_DTag_Scope, &interest->scope))
51 return error;
52
53 if (error = ndn_BinaryXMLDecoder_peekDTag(decoder, ndn_BinaryXML_DTag_InterestLifetime, &gotExpectedTag))
54 return error;
55 if (gotExpectedTag) {
56 unsigned char *interestLifetime;
57 unsigned int interestLifetimeLength;
58 if (error = ndn_BinaryXMLDecoder_readBinaryDTagElement
59 (decoder, ndn_BinaryXML_DTag_InterestLifetime, 0, &interestLifetime, &interestLifetimeLength))
60 return error;
61
62 interest->interestLifetime = 1000 *
63 ndn_BinaryXMLDecoder_bigEndianToUnsignedInt(interestLifetime, interestLifetimeLength) / 4096;
64 }
65 else
66 interest->interestLifetime = -1;
67
68 if (error = ndn_BinaryXMLDecoder_peekDTag(decoder, ndn_BinaryXML_DTag_Nonce, &gotExpectedTag))
69 return error;
70 if (gotExpectedTag) {
71 if (error = ndn_BinaryXMLDecoder_readBinaryDTagElement
72 (decoder, ndn_BinaryXML_DTag_Nonce, 0, &interest->nonce, &interest->nonceLength))
73 return error;
74 }
75 else {
76 interest->nonce = 0;
77 interest->nonceLength = 0;
78 }
79
80 if (error = ndn_BinaryXMLDecoder_readElementClose(decoder))
81 return error;
82
83 return 0;
Jeff Thompsonb7f95562013-07-03 18:36:42 -070084}