Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 1 | /** |
Jeff Thompson | 7687dc0 | 2013-09-13 11:54:07 -0700 | [diff] [blame] | 2 | * Copyright (C) 2013 Regents of the University of California. |
| 3 | * @author: Jeff Thompson <jefft0@remap.ucla.edu> |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 4 | * Derived from ForwardingEntry.js by Meki Cheraoui. |
| 5 | * See COPYING for copyright and distribution information. |
| 6 | */ |
| 7 | |
| 8 | #include "binary-xml.h" |
| 9 | #include "binary-xml-forwarding-entry.h" |
Jeff Thompson | 3c16603 | 2013-11-20 15:12:19 -0800 | [diff] [blame] | 10 | #include "binary-xml-name.h" |
| 11 | #include "binary-xml-key.h" |
| 12 | #include "binary-xml-publisher-public-key-digest.h" |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 13 | |
| 14 | ndn_Error ndn_encodeBinaryXmlForwardingEntry(struct ndn_ForwardingEntry *forwardingEntry, struct ndn_BinaryXmlEncoder *encoder) |
| 15 | { |
| 16 | ndn_Error error; |
| 17 | if ((error = ndn_BinaryXmlEncoder_writeElementStartDTag(encoder, ndn_BinaryXml_DTag_ForwardingEntry))) |
| 18 | return error; |
| 19 | |
| 20 | if ((error = ndn_BinaryXmlEncoder_writeOptionalUDataDTagElement |
Jeff Thompson | 9303453 | 2013-10-08 11:52:43 -0700 | [diff] [blame] | 21 | (encoder, ndn_BinaryXml_DTag_Action, &forwardingEntry->action))) |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 22 | return error; |
| 23 | if ((error = ndn_encodeBinaryXmlName(&forwardingEntry->prefix, encoder))) |
| 24 | return error; |
| 25 | // This will skip encoding if there is no publisherPublicKeyDigest. |
| 26 | if ((error = ndn_encodeBinaryXmlPublisherPublicKeyDigest(&forwardingEntry->publisherPublicKeyDigest, encoder))) |
| 27 | return error; |
| 28 | if ((error = ndn_BinaryXmlEncoder_writeOptionalUnsignedDecimalIntDTagElement |
| 29 | (encoder, ndn_BinaryXml_DTag_FaceID, forwardingEntry->faceId))) |
| 30 | return error; |
Jeff Thompson | 1f8a31a | 2013-09-30 16:18:47 -0700 | [diff] [blame] | 31 | if ((error = ndn_BinaryXmlEncoder_writeUnsignedDecimalIntDTagElement |
| 32 | (encoder, ndn_BinaryXml_DTag_ForwardingFlags, |
| 33 | ndn_ForwardingFlags_getForwardingEntryFlags(&forwardingEntry->forwardingFlags)))) |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 34 | return error; |
| 35 | if ((error = ndn_BinaryXmlEncoder_writeOptionalUnsignedDecimalIntDTagElement |
| 36 | (encoder, ndn_BinaryXml_DTag_FreshnessSeconds, forwardingEntry->freshnessSeconds))) |
| 37 | return error; |
| 38 | |
| 39 | if ((error = ndn_BinaryXmlEncoder_writeElementClose(encoder))) |
| 40 | return error; |
| 41 | |
| 42 | return NDN_ERROR_success; |
| 43 | } |
| 44 | |
| 45 | ndn_Error ndn_decodeBinaryXmlForwardingEntry(struct ndn_ForwardingEntry *forwardingEntry, struct ndn_BinaryXmlDecoder *decoder) |
| 46 | { |
| 47 | ndn_Error error; |
| 48 | if ((error = ndn_BinaryXmlDecoder_readElementStartDTag(decoder, ndn_BinaryXml_DTag_ForwardingEntry))) |
| 49 | return error; |
| 50 | |
| 51 | if ((error = ndn_BinaryXmlDecoder_readOptionalUDataDTagElement |
Jeff Thompson | 9303453 | 2013-10-08 11:52:43 -0700 | [diff] [blame] | 52 | (decoder, ndn_BinaryXml_DTag_Action, &forwardingEntry->action))) |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 53 | return error; |
| 54 | if ((error = ndn_decodeBinaryXmlName(&forwardingEntry->prefix, decoder))) |
| 55 | return error; |
| 56 | if ((error = ndn_decodeOptionalBinaryXmlPublisherPublicKeyDigest(&forwardingEntry->publisherPublicKeyDigest, decoder))) |
| 57 | return error; |
| 58 | if ((error = ndn_BinaryXmlDecoder_readOptionalUnsignedIntegerDTagElement |
| 59 | (decoder, ndn_BinaryXml_DTag_FaceID, &forwardingEntry->faceId))) |
| 60 | return error; |
Jeff Thompson | 1f8a31a | 2013-09-30 16:18:47 -0700 | [diff] [blame] | 61 | |
| 62 | int forwardingEntryFlags; |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 63 | if ((error = ndn_BinaryXmlDecoder_readOptionalUnsignedIntegerDTagElement |
Jeff Thompson | 1f8a31a | 2013-09-30 16:18:47 -0700 | [diff] [blame] | 64 | (decoder, ndn_BinaryXml_DTag_ForwardingFlags, &forwardingEntryFlags))) |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 65 | return error; |
Jeff Thompson | 1f8a31a | 2013-09-30 16:18:47 -0700 | [diff] [blame] | 66 | if (forwardingEntryFlags >= 0) |
| 67 | ndn_ForwardingFlags_setForwardingEntryFlags(&forwardingEntry->forwardingFlags, forwardingEntryFlags); |
| 68 | else |
| 69 | // This sets the default flags. |
| 70 | ndn_ForwardingFlags_initialize(&forwardingEntry->forwardingFlags); |
| 71 | |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 72 | if ((error = ndn_BinaryXmlDecoder_readOptionalUnsignedIntegerDTagElement |
| 73 | (decoder, ndn_BinaryXml_DTag_FreshnessSeconds, &forwardingEntry->freshnessSeconds))) |
| 74 | return error; |
| 75 | |
| 76 | if ((error = ndn_BinaryXmlDecoder_readElementClose(decoder))) |
| 77 | return error; |
| 78 | |
| 79 | return NDN_ERROR_success; |
| 80 | } |