00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef CCN_CCN_DEFINED
00023 #define CCN_CCN_DEFINED
00024
00025 #include <stdint.h>
00026 #include <ccn/coding.h>
00027 #include <ccn/charbuf.h>
00028 #include <ccn/indexbuf.h>
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #define CCN_API_VERSION 4000
00041
00042
00043
00044
00045
00046
00047 #define CCN_INTEREST_LIFETIME_SEC 4
00048 #define CCN_INTEREST_LIFETIME_MICROSEC (CCN_INTEREST_LIFETIME_SEC * 1000000)
00049
00050
00051 struct ccn;
00052 struct ccn_pkey;
00053
00054
00055 struct ccn_closure;
00056 struct ccn_upcall_info;
00057 struct ccn_parsed_interest;
00058 struct ccn_parsed_ContentObject;
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069 enum ccn_upcall_kind {
00070 CCN_UPCALL_FINAL,
00071 CCN_UPCALL_INTEREST,
00072 CCN_UPCALL_CONSUMED_INTEREST,
00073 CCN_UPCALL_CONTENT,
00074 CCN_UPCALL_INTEREST_TIMED_OUT,
00075 CCN_UPCALL_CONTENT_UNVERIFIED,
00076 CCN_UPCALL_CONTENT_BAD
00077 };
00078
00079
00080
00081
00082 enum ccn_upcall_res {
00083 CCN_UPCALL_RESULT_ERR = -1,
00084 CCN_UPCALL_RESULT_OK = 0,
00085 CCN_UPCALL_RESULT_REEXPRESS = 1,
00086 CCN_UPCALL_RESULT_INTEREST_CONSUMED = 2,
00087 CCN_UPCALL_RESULT_VERIFY = 3
00088 };
00089
00090
00091
00092
00093
00094 typedef enum ccn_upcall_res (*ccn_handler)(
00095 struct ccn_closure *selfp,
00096 enum ccn_upcall_kind kind,
00097 struct ccn_upcall_info *info
00098 );
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109 struct ccn_closure {
00110 ccn_handler p;
00111 void *data;
00112 intptr_t intdata;
00113 int refcount;
00114 };
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124 struct ccn_upcall_info {
00125 struct ccn *h;
00126
00127 const unsigned char *interest_ccnb;
00128 struct ccn_parsed_interest *pi;
00129 struct ccn_indexbuf *interest_comps;
00130 int matched_comps;
00131
00132 const unsigned char *content_ccnb;
00133 struct ccn_parsed_ContentObject *pco;
00134 struct ccn_indexbuf *content_comps;
00135 };
00136
00137
00138
00139
00140
00141
00142
00143 struct ccn *ccn_create(void);
00144
00145
00146
00147
00148
00149
00150
00151 int ccn_connect(struct ccn *h, const char *name);
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161 int ccn_get_connection_fd(struct ccn *h);
00162
00163
00164
00165
00166
00167
00168 int ccn_disconnect(struct ccn *h);
00169
00170
00171
00172
00173
00174 void ccn_destroy(struct ccn **hp);
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186 int ccn_name_init(struct ccn_charbuf *c);
00187
00188
00189
00190
00191
00192
00193 int ccn_name_append(struct ccn_charbuf *c, const void *component, size_t n);
00194
00195
00196
00197
00198
00199
00200
00201
00202 int ccn_name_append_str(struct ccn_charbuf *c, const char *s);
00203
00204
00205
00206
00207
00208
00209
00210 int ccn_name_append_components(struct ccn_charbuf *c,
00211 const unsigned char *ccnb,
00212 size_t start, size_t stop);
00213
00214 enum ccn_marker {
00215 CCN_MARKER_NONE = -1,
00216 CCN_MARKER_SEQNUM = 0x00,
00217 CCN_MARKER_CONTROL = 0xC1,
00218 CCN_MARKER_OSEQNUM = 0xF8,
00219 CCN_MARKER_BLKID = 0xFB,
00220 CCN_MARKER_VERSION = 0xFD
00221 };
00222
00223
00224
00225
00226
00227
00228
00229 int ccn_name_append_numeric(struct ccn_charbuf *c,
00230 enum ccn_marker tag, uintmax_t value);
00231
00232
00233
00234
00235
00236
00237 int ccn_name_append_nonce(struct ccn_charbuf *c);
00238
00239
00240
00241
00242
00243
00244
00245 int ccn_name_split(const struct ccn_charbuf *c,
00246 struct ccn_indexbuf* components);
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256 int ccn_name_chop(struct ccn_charbuf *c,
00257 struct ccn_indexbuf* components, int n);
00258
00259
00260
00261
00262
00263
00264
00265 enum ccn_content_type {
00266 CCN_CONTENT_DATA = 0x0C04C0,
00267 CCN_CONTENT_ENCR = 0x10D091,
00268 CCN_CONTENT_GONE = 0x18E344,
00269 CCN_CONTENT_KEY = 0x28463F,
00270 CCN_CONTENT_LINK = 0x2C834A,
00271 CCN_CONTENT_NACK = 0x34008A
00272 };
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292 int ccn_express_interest(struct ccn *h,
00293 struct ccn_charbuf *namebuf,
00294 struct ccn_closure *action,
00295 struct ccn_charbuf *interest_template);
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308 int ccn_set_interest_filter(struct ccn *h, struct ccn_charbuf *namebuf,
00309 struct ccn_closure *action);
00310
00311
00312
00313
00314 int ccn_set_interest_filter_with_flags(struct ccn *h,
00315 struct ccn_charbuf *namebuf,
00316 struct ccn_closure *action,
00317 int forw_flags);
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327 int ccn_put(struct ccn *h, const void *p, size_t length);
00328
00329
00330
00331
00332
00333
00334 int ccn_output_is_pending(struct ccn *h);
00335
00336
00337
00338
00339
00340
00341
00342 int ccn_run(struct ccn *h, int timeout);
00343
00344
00345
00346
00347
00348
00349 int ccn_set_run_timeout(struct ccn *h, int timeout);
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364 int ccn_get(struct ccn *h,
00365 struct ccn_charbuf *name,
00366 struct ccn_charbuf *interest_template,
00367 int timeout_ms,
00368 struct ccn_charbuf *resultbuf,
00369 struct ccn_parsed_ContentObject *pcobuf,
00370 struct ccn_indexbuf *compsbuf,
00371 int flags);
00372
00373 #define CCN_GET_NOKEYWAIT 1
00374
00375
00376 int ccn_verify_content(struct ccn *h,
00377 const unsigned char *msg,
00378 struct ccn_parsed_ContentObject *pco);
00379
00380
00381
00382
00383
00384
00385 struct ccn_buf_decoder {
00386 struct ccn_skeleton_decoder decoder;
00387 const unsigned char *buf;
00388 size_t size;
00389 };
00390
00391 struct ccn_buf_decoder *ccn_buf_decoder_start(struct ccn_buf_decoder *d,
00392 const unsigned char *buf, size_t size);
00393
00394 void ccn_buf_advance(struct ccn_buf_decoder *d);
00395 int ccn_buf_advance_past_element(struct ccn_buf_decoder *d);
00396
00397
00398 int ccn_buf_match_dtag(struct ccn_buf_decoder *d, enum ccn_dtag dtag);
00399
00400 int ccn_buf_match_some_dtag(struct ccn_buf_decoder *d);
00401
00402 int ccn_buf_match_some_blob(struct ccn_buf_decoder *d);
00403 int ccn_buf_match_blob(struct ccn_buf_decoder *d,
00404 const unsigned char **bufp, size_t *sizep);
00405
00406 int ccn_buf_match_udata(struct ccn_buf_decoder *d, const char *s);
00407
00408 int ccn_buf_match_attr(struct ccn_buf_decoder *d, const char *s);
00409
00410
00411 int ccn_parse_required_tagged_BLOB(struct ccn_buf_decoder *d,
00412 enum ccn_dtag dtag,
00413 int minlen, int maxlen);
00414 int ccn_parse_optional_tagged_BLOB(struct ccn_buf_decoder *d,
00415 enum ccn_dtag dtag,
00416 int minlen, int maxlen);
00417 int ccn_parse_nonNegativeInteger(struct ccn_buf_decoder *d);
00418 int ccn_parse_optional_tagged_nonNegativeInteger(struct ccn_buf_decoder *d,
00419 enum ccn_dtag dtag);
00420 int ccn_parse_uintmax(struct ccn_buf_decoder *d, uintmax_t *result);
00421 int ccn_parse_tagged_string(struct ccn_buf_decoder *d,
00422 enum ccn_dtag dtag, struct ccn_charbuf *store);
00423
00424 uintmax_t ccn_parse_required_tagged_binary_number(struct ccn_buf_decoder *d,
00425 enum ccn_dtag dtag,
00426 int minlen, int maxlen);
00427 uintmax_t ccn_parse_optional_tagged_binary_number(struct ccn_buf_decoder *d,
00428 enum ccn_dtag dtag,
00429 int minlen, int maxlen,
00430 uintmax_t default_value);
00431
00432
00433
00434 void ccn_buf_check_close(struct ccn_buf_decoder *d);
00435
00436
00437
00438
00439
00440 int ccn_ref_tagged_BLOB(enum ccn_dtag tt,
00441 const unsigned char *buf,
00442 size_t start, size_t stop,
00443 const unsigned char **presult, size_t *psize);
00444
00445 int ccn_fetch_tagged_nonNegativeInteger(enum ccn_dtag tt,
00446 const unsigned char *buf, size_t start, size_t stop);
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466 enum ccn_parsed_interest_offsetid {
00467 CCN_PI_B_Name,
00468 CCN_PI_B_Component0,
00469 CCN_PI_B_LastPrefixComponent,
00470 CCN_PI_E_LastPrefixComponent,
00471 CCN_PI_E_ComponentLast = CCN_PI_E_LastPrefixComponent,
00472 CCN_PI_E_Name,
00473 CCN_PI_B_MinSuffixComponents,
00474 CCN_PI_E_MinSuffixComponents,
00475 CCN_PI_B_MaxSuffixComponents,
00476 CCN_PI_E_MaxSuffixComponents,
00477 CCN_PI_B_PublisherID,
00478 CCN_PI_B_PublisherIDKeyDigest,
00479 CCN_PI_E_PublisherIDKeyDigest,
00480 CCN_PI_E_PublisherID,
00481 CCN_PI_B_Exclude,
00482 CCN_PI_E_Exclude,
00483 CCN_PI_B_ChildSelector,
00484 CCN_PI_E_ChildSelector,
00485 CCN_PI_B_AnswerOriginKind,
00486 CCN_PI_E_AnswerOriginKind,
00487 CCN_PI_B_Scope,
00488 CCN_PI_E_Scope,
00489 CCN_PI_B_InterestLifetime,
00490 CCN_PI_E_InterestLifetime,
00491 CCN_PI_B_Nonce,
00492 CCN_PI_E_Nonce,
00493 CCN_PI_B_OTHER,
00494 CCN_PI_E_OTHER,
00495 CCN_PI_E
00496 };
00497
00498 struct ccn_parsed_interest {
00499 int magic;
00500 int prefix_comps;
00501 int min_suffix_comps;
00502 int max_suffix_comps;
00503 int orderpref;
00504 int answerfrom;
00505 int scope;
00506 unsigned short offset[CCN_PI_E+1];
00507 };
00508
00509
00510
00511
00512 #define CCN_AOK_CS 0x1
00513 #define CCN_AOK_NEW 0x2
00514 #define CCN_AOK_DEFAULT (CCN_AOK_CS | CCN_AOK_NEW)
00515 #define CCN_AOK_STALE 0x4
00516 #define CCN_AOK_EXPIRE 0x10
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526 int
00527 ccn_parse_interest(const unsigned char *msg, size_t size,
00528 struct ccn_parsed_interest *interest,
00529 struct ccn_indexbuf *components);
00530
00531
00532
00533
00534
00535 intmax_t ccn_interest_lifetime(const unsigned char *msg,
00536 const struct ccn_parsed_interest *pi);
00537
00538
00539
00540
00541 int ccn_interest_lifetime_seconds(const unsigned char *msg,
00542 const struct ccn_parsed_interest *pi);
00543
00544
00545
00546 enum ccn_parsed_content_object_offsetid {
00547 CCN_PCO_B_Signature,
00548 CCN_PCO_B_DigestAlgorithm,
00549 CCN_PCO_E_DigestAlgorithm,
00550 CCN_PCO_B_Witness,
00551 CCN_PCO_E_Witness,
00552 CCN_PCO_B_SignatureBits,
00553 CCN_PCO_E_SignatureBits,
00554 CCN_PCO_E_Signature,
00555 CCN_PCO_B_Name,
00556 CCN_PCO_B_Component0,
00557 CCN_PCO_E_ComponentN,
00558 CCN_PCO_E_ComponentLast = CCN_PCO_E_ComponentN,
00559 CCN_PCO_E_Name,
00560 CCN_PCO_B_SignedInfo,
00561 CCN_PCO_B_PublisherPublicKeyDigest,
00562 CCN_PCO_E_PublisherPublicKeyDigest,
00563 CCN_PCO_B_Timestamp,
00564 CCN_PCO_E_Timestamp,
00565 CCN_PCO_B_Type,
00566 CCN_PCO_E_Type,
00567 CCN_PCO_B_FreshnessSeconds,
00568 CCN_PCO_E_FreshnessSeconds,
00569 CCN_PCO_B_FinalBlockID,
00570 CCN_PCO_E_FinalBlockID,
00571 CCN_PCO_B_KeyLocator,
00572
00573 CCN_PCO_B_Key_Certificate_KeyName,
00574 CCN_PCO_B_KeyName_Name,
00575 CCN_PCO_E_KeyName_Name,
00576 CCN_PCO_B_KeyName_Pub,
00577 CCN_PCO_E_KeyName_Pub,
00578 CCN_PCO_E_Key_Certificate_KeyName,
00579 CCN_PCO_E_KeyLocator,
00580 CCN_PCO_E_SignedInfo,
00581 CCN_PCO_B_Content,
00582 CCN_PCO_E_Content,
00583 CCN_PCO_E
00584 };
00585
00586 struct ccn_parsed_ContentObject {
00587 int magic;
00588 enum ccn_content_type type;
00589 int name_ncomps;
00590 unsigned short offset[CCN_PCO_E+1];
00591 unsigned char digest[32];
00592 int digest_bytes;
00593 };
00594
00595
00596
00597
00598
00599
00600
00601
00602
00603
00604
00605 int ccn_parse_ContentObject(const unsigned char *msg, size_t size,
00606 struct ccn_parsed_ContentObject *x,
00607 struct ccn_indexbuf *components);
00608
00609 void ccn_digest_ContentObject(const unsigned char *msg,
00610 struct ccn_parsed_ContentObject *pc);
00611
00612
00613
00614
00615
00616
00617 int ccn_parse_Name(struct ccn_buf_decoder *d, struct ccn_indexbuf *components);
00618
00619
00620
00621
00622
00623
00624
00625
00626
00627
00628 int ccn_compare_names(const unsigned char *a, size_t asize,
00629 const unsigned char *b, size_t bsize);
00630
00631
00632
00633
00634
00635
00636
00637
00638
00639
00640
00641
00642
00643
00644
00645
00646
00647 int ccn_name_comp_strcmp(const unsigned char *data,
00648 const struct ccn_indexbuf *indexbuf,
00649 unsigned int i,
00650 const char *val);
00651
00652
00653
00654
00655
00656 int ccn_name_comp_get(const unsigned char *data,
00657 const struct ccn_indexbuf *indexbuf,
00658 unsigned int i,
00659 const unsigned char **comp, size_t *size);
00660
00661 int ccn_name_next_sibling(struct ccn_charbuf *c);
00662
00663
00664
00665
00666
00667 int ccn_content_get_value(const unsigned char *data, size_t data_size,
00668 const struct ccn_parsed_ContentObject *content,
00669 const unsigned char **value, size_t *size);
00670
00671
00672
00673
00674
00675
00676
00677
00678
00679
00680
00681
00682
00683
00684
00685
00686
00687
00688
00689
00690
00691
00692
00693
00694
00695
00696
00697
00698
00699
00700
00701 struct ccn_signing_params {
00702 int api_version;
00703 int sp_flags;
00704 struct ccn_charbuf *template_ccnb;
00705 unsigned char pubid[32];
00706 enum ccn_content_type type;
00707 int freshness;
00708
00709 };
00710
00711 #define CCN_SIGNING_PARAMS_INIT \
00712 { CCN_API_VERSION, 0, NULL, {0}, CCN_CONTENT_DATA, -1 }
00713
00714 #define CCN_SP_TEMPL_TIMESTAMP 0x0001
00715 #define CCN_SP_TEMPL_FINAL_BLOCK_ID 0x0002
00716 #define CCN_SP_TEMPL_FRESHNESS 0x0004
00717 #define CCN_SP_TEMPL_KEY_LOCATOR 0x0008
00718 #define CCN_SP_FINAL_BLOCK 0x0010
00719 #define CCN_SP_OMIT_KEY_LOCATOR 0x0020
00720
00721 int ccn_sign_content(struct ccn *h,
00722 struct ccn_charbuf *resultbuf,
00723 const struct ccn_charbuf *name_prefix,
00724 const struct ccn_signing_params *params,
00725 const void *data, size_t size);
00726
00727 int ccn_load_private_key(struct ccn *h,
00728 const char *keystore_path,
00729 const char *keystore_passphrase,
00730 struct ccn_charbuf *pubid_out);
00731
00732 int ccn_load_default_key(struct ccn *h,
00733 const char *keystore_path,
00734 const char *keystore_passphrase);
00735
00736 int ccn_get_public_key(struct ccn *h,
00737 const struct ccn_signing_params *params,
00738 struct ccn_charbuf *digest_result,
00739 struct ccn_charbuf *result);
00740
00741 int ccn_chk_signing_params(struct ccn *h,
00742 const struct ccn_signing_params *params,
00743 struct ccn_signing_params *result,
00744 struct ccn_charbuf **ptimestamp,
00745 struct ccn_charbuf **pfinalblockid,
00746 struct ccn_charbuf **pkeylocator);
00747
00748 int ccn_signed_info_create(
00749 struct ccn_charbuf *c,
00750 const void *publisher_key_id,
00751 size_t publisher_key_id_size,
00752 const struct ccn_charbuf *timestamp,
00753 enum ccn_content_type type,
00754 int freshness,
00755 const struct ccn_charbuf *finalblockid,
00756 const struct ccn_charbuf *key_locator);
00757
00758 int ccn_encode_ContentObject(struct ccn_charbuf *buf,
00759 const struct ccn_charbuf *Name,
00760 const struct ccn_charbuf *SignedInfo,
00761 const void *data,
00762 size_t size,
00763 const char *digest_algorithm,
00764 const struct ccn_pkey *private_key);
00765
00766
00767
00768
00769
00770
00771
00772
00773
00774
00775
00776
00777
00778
00779
00780 int ccn_content_matches_interest(const unsigned char *content_object,
00781 size_t content_object_size,
00782 int implicit_content_digest,
00783 struct ccn_parsed_ContentObject *pc,
00784 const unsigned char *interest_msg,
00785 size_t interest_msg_size,
00786 const struct ccn_parsed_interest *pi);
00787
00788
00789
00790
00791 int ccn_encode_StatusResponse(struct ccn_charbuf *buf,
00792 int errcode, const char *errtext);
00793
00794
00795
00796
00797
00798
00799
00800
00801
00802
00803 void ccn_perror(struct ccn *h, const char *s);
00804 int ccn_seterror(struct ccn *h, int error_code);
00805 int ccn_geterror(struct ccn *h);
00806
00807
00808
00809
00810
00811
00812
00813
00814
00815
00816
00817
00818 int ccn_charbuf_append_tt(struct ccn_charbuf *c, size_t val, enum ccn_tt tt);
00819
00820
00821
00822
00823
00824
00825
00826
00827 int ccn_charbuf_append_closer(struct ccn_charbuf *c);
00828
00829
00830
00831
00832
00833
00834
00835
00836 int ccnb_append_number(struct ccn_charbuf *c, int nni);
00837
00838
00839
00840
00841
00842 int ccnb_append_timestamp_blob(struct ccn_charbuf *c,
00843 enum ccn_marker marker,
00844 intmax_t secs, int nsecs);
00845
00846
00847
00848
00849 int ccnb_append_now_blob(struct ccn_charbuf *c, enum ccn_marker marker);
00850
00851
00852
00853
00854 int ccnb_element_begin(struct ccn_charbuf *c, enum ccn_dtag dtag);
00855
00856
00857
00858
00859
00860 int ccnb_element_end(struct ccn_charbuf *c);
00861
00862
00863
00864
00865 int ccnb_append_tagged_blob(struct ccn_charbuf *c, enum ccn_dtag dtag,
00866 const void *data, size_t size);
00867
00868
00869
00870
00871 int ccnb_tagged_putf(struct ccn_charbuf *c, enum ccn_dtag dtag,
00872 const char *fmt, ...);
00873
00874
00875
00876
00877
00878
00879 #define CCN_V_REPLACE 1
00880 #define CCN_V_LOW 2
00881 #define CCN_V_HIGH 4
00882 #define CCN_V_EST 8
00883 #define CCN_V_LOWEST (2|8)
00884 #define CCN_V_HIGHEST (4|8)
00885 #define CCN_V_NEXT (4|1)
00886 #define CCN_V_PREV (2|1)
00887 #define CCN_V_NOW 16
00888 #define CCN_V_NESTOK 32
00889
00890 int ccn_resolve_version(struct ccn *h,
00891 struct ccn_charbuf *name,
00892 int versioning_flags,
00893 int timeout_ms);
00894
00895 int ccn_create_version(struct ccn *h,
00896 struct ccn_charbuf *name,
00897 int versioning_flags,
00898 intmax_t secs, int nsecs);
00899
00900 #endif