Jeff Thompson | 47eecfc | 2013-07-07 22:56:46 -0700 | [diff] [blame] | 1 | /** |
| 2 | * @author: Jeff Thompson |
| 3 | * See COPYING for copyright and distribution information. |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include "BinaryXMLEncoder.h" |
| 7 | #include "BinaryXMLDecoder.h" |
Jeff Thompson | 2255290 | 2013-07-07 21:26:20 -0700 | [diff] [blame] | 8 | #include "BinaryXMLName.h" |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 9 | #include "BinaryXMLInterest.h" |
| 10 | |
Jeff Thompson | 2255290 | 2013-07-07 21:26:20 -0700 | [diff] [blame] | 11 | char *ndn_decodeBinaryXMLInterest(struct ndn_Interest *interest, struct ndn_BinaryXMLDecoder *decoder) |
Jeff Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 12 | { |
Jeff Thompson | 2255290 | 2013-07-07 21:26:20 -0700 | [diff] [blame] | 13 | 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 Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 26 | |
Jeff Thompson | 2255290 | 2013-07-07 21:26:20 -0700 | [diff] [blame] | 27 | 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 Thompson | b7f9556 | 2013-07-03 18:36:42 -0700 | [diff] [blame] | 84 | } |