Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Author: Jeff Thompson |
| 3 | * |
| 4 | * BSD license, See the LICENSE file for more information. |
| 5 | */ |
| 6 | |
| 7 | #include "BinaryXMLEncoder.h" |
| 8 | #include "BinaryXMLDecoder.h" |
Jeff Thompson | 2255290 | 2013-07-07 21:26:20 -0700 | [diff] [blame] | 9 | #include "BinaryXMLName.h" |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 10 | #include "BinaryXMLInterest.h" |
| 11 | |
Jeff Thompson | 2255290 | 2013-07-07 21:26:20 -0700 | [diff] [blame] | 12 | char *ndn_decodeBinaryXMLInterest(struct ndn_Interest *interest, struct ndn_BinaryXMLDecoder *decoder) |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 13 | { |
Jeff Thompson | 2255290 | 2013-07-07 21:26:20 -0700 | [diff] [blame] | 14 | char *error; |
| 15 | if (error = ndn_BinaryXMLDecoder_readElementStartDTag(decoder, ndn_BinaryXML_DTag_Interest)) |
| 16 | return error; |
| 17 | |
| 18 | if (error = ndn_decodeBinaryXMLName(&interest->name, decoder)) |
| 19 | return error; |
| 20 | |
| 21 | if (error = ndn_BinaryXMLDecoder_readOptionalUnsignedIntegerDTagElement |
| 22 | (decoder, ndn_BinaryXML_DTag_MinSuffixComponents, &interest->minSuffixComponents)) |
| 23 | return error; |
| 24 | if (error = ndn_BinaryXMLDecoder_readOptionalUnsignedIntegerDTagElement |
| 25 | (decoder, ndn_BinaryXML_DTag_MaxSuffixComponents, &interest->maxSuffixComponents)) |
| 26 | return error; |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 27 | |
Jeff Thompson | 2255290 | 2013-07-07 21:26:20 -0700 | [diff] [blame] | 28 | int gotExpectedTag; |
| 29 | if (error = ndn_BinaryXMLDecoder_peekDTag(decoder, ndn_BinaryXML_DTag_PublisherPublicKeyDigest, &gotExpectedTag)) |
| 30 | return error; |
| 31 | if (gotExpectedTag) { |
| 32 | if (error = ndn_BinaryXMLDecoder_readBinaryDTagElement |
| 33 | (decoder, ndn_BinaryXML_DTag_PublisherPublicKeyDigest, 0, &interest->publisherPublicKeyDigest, |
| 34 | &interest->publisherPublicKeyDigestLength)) |
| 35 | return error; |
| 36 | } |
| 37 | else { |
| 38 | interest->publisherPublicKeyDigest = 0; |
| 39 | interest->publisherPublicKeyDigestLength = 0; |
| 40 | } |
| 41 | |
| 42 | // TODO: Implement exclude |
| 43 | |
| 44 | if (error = ndn_BinaryXMLDecoder_readOptionalUnsignedIntegerDTagElement |
| 45 | (decoder, ndn_BinaryXML_DTag_ChildSelector, &interest->childSelector)) |
| 46 | return error; |
| 47 | if (error = ndn_BinaryXMLDecoder_readOptionalUnsignedIntegerDTagElement |
| 48 | (decoder, ndn_BinaryXML_DTag_AnswerOriginKind, &interest->answerOriginKind)) |
| 49 | return error; |
| 50 | if (error = ndn_BinaryXMLDecoder_readOptionalUnsignedIntegerDTagElement |
| 51 | (decoder, ndn_BinaryXML_DTag_Scope, &interest->scope)) |
| 52 | return error; |
| 53 | |
| 54 | if (error = ndn_BinaryXMLDecoder_peekDTag(decoder, ndn_BinaryXML_DTag_InterestLifetime, &gotExpectedTag)) |
| 55 | return error; |
| 56 | if (gotExpectedTag) { |
| 57 | unsigned char *interestLifetime; |
| 58 | unsigned int interestLifetimeLength; |
| 59 | if (error = ndn_BinaryXMLDecoder_readBinaryDTagElement |
| 60 | (decoder, ndn_BinaryXML_DTag_InterestLifetime, 0, &interestLifetime, &interestLifetimeLength)) |
| 61 | return error; |
| 62 | |
| 63 | interest->interestLifetime = 1000 * |
| 64 | ndn_BinaryXMLDecoder_bigEndianToUnsignedInt(interestLifetime, interestLifetimeLength) / 4096; |
| 65 | } |
| 66 | else |
| 67 | interest->interestLifetime = -1; |
| 68 | |
| 69 | if (error = ndn_BinaryXMLDecoder_peekDTag(decoder, ndn_BinaryXML_DTag_Nonce, &gotExpectedTag)) |
| 70 | return error; |
| 71 | if (gotExpectedTag) { |
| 72 | if (error = ndn_BinaryXMLDecoder_readBinaryDTagElement |
| 73 | (decoder, ndn_BinaryXML_DTag_Nonce, 0, &interest->nonce, &interest->nonceLength)) |
| 74 | return error; |
| 75 | } |
| 76 | else { |
| 77 | interest->nonce = 0; |
| 78 | interest->nonceLength = 0; |
| 79 | } |
| 80 | |
| 81 | if (error = ndn_BinaryXMLDecoder_readElementClose(decoder)) |
| 82 | return error; |
| 83 | |
| 84 | return 0; |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 85 | } |