coding.h

Go to the documentation of this file.
00001 /**
00002  * @file ccn/coding.h
00003  * 
00004  * Details of the ccn binary wire encoding.
00005  *
00006  * Part of the CCNx C Library.
00007  *
00008  * Copyright (C) 2008-2011 Palo Alto Research Center, Inc.
00009  *
00010  * This library is free software; you can redistribute it and/or modify it
00011  * under the terms of the GNU Lesser General Public License version 2.1
00012  * as published by the Free Software Foundation.
00013  * This library is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00016  * Lesser General Public License for more details. You should have received
00017  * a copy of the GNU Lesser General Public License along with this library;
00018  * if not, write to the Free Software Foundation, Inc., 51 Franklin Street,
00019  * Fifth Floor, Boston, MA 02110-1301 USA.
00020  */
00021 
00022 #ifndef CCN_CODING_DEFINED
00023 #define CCN_CODING_DEFINED
00024 
00025 #include <sys/types.h>
00026 #include <stddef.h>
00027 
00028 #define CCN_TT_BITS 3
00029 #define CCN_TT_MASK ((1 << CCN_TT_BITS) - 1)
00030 #define CCN_MAX_TINY ((1 << (7-CCN_TT_BITS)) - 1)
00031 #define CCN_TT_HBIT ((unsigned char)(1 << 7))
00032 
00033 /**
00034  * Type tag for a ccnb start marker.
00035  */
00036 enum ccn_tt {
00037     CCN_EXT,        /**< starts composite extension - numval is subtype */
00038     CCN_TAG,        /**< starts composite - numval is tagnamelen-1 */ 
00039     CCN_DTAG,       /**< starts composite - numval is tagdict index (enum ccn_dtag) */
00040     CCN_ATTR,       /**< attribute - numval is attrnamelen-1, value follows */
00041     CCN_DATTR,      /**< attribute numval is attrdict index */
00042     CCN_BLOB,       /**< opaque binary data - numval is byte count */
00043     CCN_UDATA,      /**< UTF-8 encoded character data - numval is byte count */
00044     CCN_NO_TOKEN    /**< should not occur in encoding */
00045 };
00046 
00047 /** CCN_CLOSE terminates composites */
00048 #define CCN_CLOSE ((unsigned char)(0))
00049 
00050 enum ccn_ext_subtype {
00051     /* skip smallest values for now */
00052     CCN_PROCESSING_INSTRUCTIONS = 16 /* <?name:U value:U?> */
00053 };
00054 
00055 /**
00056  * DTAG identifies ccnb-encoded elements.
00057  * c.f. tagname.csvdict
00058  * See the gen_enum_dtag script for help updating these.
00059  */
00060 enum ccn_dtag {
00061     CCN_DTAG_Any = 13,
00062     CCN_DTAG_Name = 14,
00063     CCN_DTAG_Component = 15,
00064     CCN_DTAG_Certificate = 16,
00065     CCN_DTAG_Collection = 17,
00066     CCN_DTAG_CompleteName = 18,
00067     CCN_DTAG_Content = 19,
00068     CCN_DTAG_SignedInfo = 20,
00069     CCN_DTAG_ContentDigest = 21,
00070     CCN_DTAG_ContentHash = 22,
00071     CCN_DTAG_Count = 24,
00072     CCN_DTAG_Header = 25,
00073     CCN_DTAG_Interest = 26,     /* 20090915 */
00074     CCN_DTAG_Key = 27,
00075     CCN_DTAG_KeyLocator = 28,
00076     CCN_DTAG_KeyName = 29,
00077     CCN_DTAG_Length = 30,
00078     CCN_DTAG_Link = 31,
00079     CCN_DTAG_LinkAuthenticator = 32,
00080     CCN_DTAG_NameComponentCount = 33,   /* DeprecatedInInterest */
00081     CCN_DTAG_RootDigest = 36,
00082     CCN_DTAG_Signature = 37,
00083     CCN_DTAG_Start = 38,
00084     CCN_DTAG_Timestamp = 39,
00085     CCN_DTAG_Type = 40,
00086     CCN_DTAG_Nonce = 41,
00087     CCN_DTAG_Scope = 42,
00088     CCN_DTAG_Exclude = 43,
00089     CCN_DTAG_Bloom = 44,
00090     CCN_DTAG_BloomSeed = 45,
00091     CCN_DTAG_AnswerOriginKind = 47,
00092     CCN_DTAG_InterestLifetime = 48,
00093     CCN_DTAG_Witness = 53,
00094     CCN_DTAG_SignatureBits = 54,
00095     CCN_DTAG_DigestAlgorithm = 55,
00096     CCN_DTAG_BlockSize = 56,
00097     CCN_DTAG_FreshnessSeconds = 58,
00098     CCN_DTAG_FinalBlockID = 59,
00099     CCN_DTAG_PublisherPublicKeyDigest = 60,
00100     CCN_DTAG_PublisherCertificateDigest = 61,
00101     CCN_DTAG_PublisherIssuerKeyDigest = 62,
00102     CCN_DTAG_PublisherIssuerCertificateDigest = 63,
00103     CCN_DTAG_ContentObject = 64,        /* 20090915 */
00104     CCN_DTAG_WrappedKey = 65,
00105     CCN_DTAG_WrappingKeyIdentifier = 66,
00106     CCN_DTAG_WrapAlgorithm = 67,
00107     CCN_DTAG_KeyAlgorithm = 68,
00108     CCN_DTAG_Label = 69,
00109     CCN_DTAG_EncryptedKey = 70,
00110     CCN_DTAG_EncryptedNonceKey = 71,
00111     CCN_DTAG_WrappingKeyName = 72,
00112     CCN_DTAG_Action = 73,
00113     CCN_DTAG_FaceID = 74,
00114     CCN_DTAG_IPProto = 75,
00115     CCN_DTAG_Host = 76,
00116     CCN_DTAG_Port = 77,
00117     CCN_DTAG_MulticastInterface = 78,
00118     CCN_DTAG_ForwardingFlags = 79,
00119     CCN_DTAG_FaceInstance = 80,
00120     CCN_DTAG_ForwardingEntry = 81,
00121     CCN_DTAG_MulticastTTL = 82,
00122     CCN_DTAG_MinSuffixComponents = 83,
00123     CCN_DTAG_MaxSuffixComponents = 84,
00124     CCN_DTAG_ChildSelector = 85,
00125     CCN_DTAG_RepositoryInfo = 86,
00126     CCN_DTAG_Version = 87,
00127     CCN_DTAG_RepositoryVersion = 88,
00128     CCN_DTAG_GlobalPrefix = 89,
00129     CCN_DTAG_LocalName = 90,
00130     CCN_DTAG_Policy = 91,
00131     CCN_DTAG_Namespace = 92,
00132     CCN_DTAG_GlobalPrefixName = 93,
00133     CCN_DTAG_PolicyVersion = 94,
00134     CCN_DTAG_KeyValueSet = 95,
00135     CCN_DTAG_KeyValuePair = 96,
00136     CCN_DTAG_IntegerValue = 97,
00137     CCN_DTAG_DecimalValue = 98,
00138     CCN_DTAG_StringValue = 99,
00139     CCN_DTAG_BinaryValue = 100,
00140     CCN_DTAG_NameValue = 101,
00141     CCN_DTAG_Entry = 102,
00142     CCN_DTAG_ACL = 103,
00143     CCN_DTAG_ParameterizedName = 104,
00144     CCN_DTAG_Prefix = 105,
00145     CCN_DTAG_Suffix = 106,
00146     CCN_DTAG_Root = 107,
00147     CCN_DTAG_ProfileName = 108,
00148     CCN_DTAG_Parameters = 109,
00149     CCN_DTAG_InfoString = 110,
00150     CCN_DTAG_StatusResponse = 112,
00151     CCN_DTAG_StatusCode = 113,
00152     CCN_DTAG_StatusText = 114,
00153     CCN_DTAG_SyncNode = 115,
00154     CCN_DTAG_SyncNodeKind = 116,
00155     CCN_DTAG_SyncNodeElement = 117,
00156     CCN_DTAG_SyncVersion = 118,
00157     CCN_DTAG_SyncNodeElements = 119,
00158     CCN_DTAG_SyncContentHash = 120,
00159     CCN_DTAG_SyncLeafCount = 121,
00160     CCN_DTAG_SyncTreeDepth = 122,
00161     CCN_DTAG_SyncByteCount = 123,
00162     CCN_DTAG_SyncConfigSlice = 124,
00163     CCN_DTAG_SyncConfigSliceList = 125,
00164     CCN_DTAG_SyncConfigSliceOp = 126,
00165     CCN_DTAG_SequenceNumber = 256,
00166     CCN_DTAG_CCNProtocolDataUnit = 17702112
00167 };
00168 
00169 struct ccn_dict_entry {
00170     int index;              /**< matches enum ccn_dtag above */
00171     const char *name;       /**< textual name of dtag */
00172 };
00173 
00174 struct ccn_dict {
00175     int count;              /**< Count of elements in the table */
00176     const struct ccn_dict_entry *dict; /**< the table entries */
00177 };
00178 
00179 /**
00180  * Table for translating from DTAGs to names and vice versa.
00181  */
00182 extern const struct ccn_dict ccn_dtag_dict; /* matches enum ccn_dtag above */
00183 
00184 struct ccn_skeleton_decoder { /* initialize to all 0 */
00185     ssize_t index;          /**< Number of bytes processed */
00186     int state;              /**< Decoder state */
00187     int nest;               /**< Element nesting */
00188     size_t numval;          /**< Current numval, meaning depends on state */
00189     size_t token_index;     /**< Starting index of most-recent token */
00190     size_t element_index;   /**< Starting index of most-recent element */
00191 };
00192 
00193 /**
00194  * The decoder state is one of these, possibly with some
00195  * additional bits set for internal use.  A complete parse
00196  * ends up in state 0 or an error state.  Not all possible
00197  * error states are listed here.
00198  */
00199 enum ccn_decoder_state {
00200     CCN_DSTATE_INITIAL = 0,
00201     CCN_DSTATE_NEWTOKEN,
00202     CCN_DSTATE_NUMVAL,
00203     CCN_DSTATE_UDATA,
00204     CCN_DSTATE_TAGNAME,
00205     CCN_DSTATE_ATTRNAME,
00206     CCN_DSTATE_BLOB,
00207     /* All error states are negative */
00208     CCN_DSTATE_ERR_OVERFLOW = -1,
00209     CCN_DSTATE_ERR_ATTR     = -2,       
00210     CCN_DSTATE_ERR_CODING   = -3,
00211     CCN_DSTATE_ERR_NEST     = -4, 
00212     CCN_DSTATE_ERR_BUG      = -5
00213 };
00214 
00215 /**
00216  * If the CCN_DSTATE_PAUSE bit is set in the decoder state,
00217  * the decoder will return just after recognizing each token.
00218  * In this instance, use CCN_GET_TT_FROM_DSTATE() to extract
00219  * the token type from the decoder state;
00220  * CCN_CLOSE will be reported as CCN_NO_TOKEN.
00221  * The pause bit persists, so the end test should take that into account
00222  * by using the CCN_FINAL_DSTATE macro instead of testing for state 0.
00223  */
00224 #define CCN_DSTATE_PAUSE (1 << 15)
00225 #define CCN_GET_TT_FROM_DSTATE(state) (CCN_TT_MASK & ((state) >> 16))
00226 #define CCN_FINAL_DSTATE(state) (((state) & (CCN_DSTATE_PAUSE-1)) == 0)
00227 
00228 ssize_t ccn_skeleton_decode(struct ccn_skeleton_decoder *d,
00229                             const unsigned char *p,
00230                             size_t n);
00231 
00232 #endif

Generated on Thu Feb 16 00:43:59 2012 for Content-Centric Networking in C by  doxygen 1.5.6