00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef CCN_SyncUtil
00021 #define CCN_SyncUtil
00022
00023 #include "IndexSorter.h"
00024 #include "SyncBase.h"
00025
00026 #include <ccn/ccn.h>
00027 #include <ccn/uri.h>
00028
00029 struct SyncLongHashStruct;
00030 struct SyncRootStruct;
00031
00032
00033 void
00034 SyncNoteErr(const char *msg);
00035
00036 int
00037 SyncSetDecodeErr(struct ccn_buf_decoder *d, int val);
00038
00039 int
00040 SyncCheckDecodeErr(struct ccn_buf_decoder *d);
00041
00042
00043
00044
00045 typedef int64_t sync_time;
00046
00047 sync_time
00048 SyncCurrentTime(void);
00049
00050
00051 int64_t
00052 SyncDeltaTime(sync_time mt1, sync_time mt2);
00053
00054
00055
00056 struct ccn_buf_decoder *
00057 SyncInitDecoderFromCharbufRange(struct ccn_buf_decoder *d,
00058 const struct ccn_charbuf *cb,
00059 ssize_t start, ssize_t stop);
00060
00061 struct ccn_buf_decoder *
00062 SyncInitDecoderFromCharbuf(struct ccn_buf_decoder *d,
00063 const struct ccn_charbuf *cb,
00064 ssize_t start);
00065
00066
00067
00068 int
00069 SyncDecodeHexDigit(char c);
00070
00071
00072
00073 int
00074 SyncDecodeUriChar(char c);
00075
00076 char *
00077 SyncHexStr(const unsigned char *cp, size_t sz);
00078
00079
00080
00081
00082
00083 int
00084 SyncNoteFailed(struct SyncRootStruct *root, char *where, char *why, int line);
00085
00086 void
00087 SyncNoteSimple(struct SyncRootStruct *root, char *where, char *s1);
00088
00089 void
00090 SyncNoteSimple2(struct SyncRootStruct *root, char *where, char *s1, char *s2);
00091
00092 void
00093 SyncNoteSimple3(struct SyncRootStruct *root, char *where, char *s1, char *s2, char *s3);
00094
00095 void
00096 SyncNoteUri(struct SyncRootStruct *root, char *where, char *why, struct ccn_charbuf *name);
00097
00098 void
00099 SyncNoteUriBase(struct SyncBaseStruct *base, char *where, char *why, struct ccn_charbuf *name);
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110 int
00111 SyncCmpNamesInner(struct ccn_buf_decoder *xx, struct ccn_buf_decoder *yy);
00112
00113
00114
00115
00116
00117
00118 #define SYNC_BAD_CMP (-2)
00119 int
00120 SyncCmpNames(const struct ccn_charbuf *cbx, const struct ccn_charbuf *cby);
00121
00122
00123
00124
00125
00126 int
00127 SyncIsName(const struct ccn_charbuf *cb);
00128
00129
00130
00131
00132 int
00133 SyncComponentCount(const struct ccn_charbuf *name);
00134
00135
00136
00137
00138
00139
00140
00141
00142 int
00143 SyncPatternMatch(const struct ccn_charbuf *pattern,
00144 const struct ccn_charbuf *name,
00145 int start);
00146
00147
00148
00149
00150
00151
00152 int
00153 SyncPrefixMatch(const struct ccn_charbuf *prefix,
00154 const struct ccn_charbuf *name,
00155 int start);
00156
00157
00158
00159
00160
00161 int
00162 SyncComponentMatch(const struct ccn_charbuf *x,
00163 const struct ccn_charbuf *y);
00164
00165
00166
00167
00168
00169
00170 int
00171 SyncGetComponentPtr(const struct ccn_charbuf *src, int comp,
00172 const unsigned char **xp, ssize_t *xs);
00173
00174
00175
00176
00177
00178
00179 int
00180 SyncAppendAllComponents(struct ccn_charbuf *dst,
00181 const struct ccn_charbuf *src);
00182
00183
00184
00185
00186
00187
00188 struct ccn_charbuf *
00189 SyncNameForIndexbuf(const unsigned char *buf, struct ccn_indexbuf *comps);
00190
00191
00192
00193
00194
00195
00196 struct ccn_charbuf *
00197 SyncUriForName(struct ccn_charbuf *name);
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211 void
00212 SyncGetHashPtr(const struct ccn_buf_decoder *hd,
00213 const unsigned char **xp, ssize_t *xs);
00214
00215 ssize_t
00216 SyncCmpHashesRaw(const unsigned char *xp, ssize_t xs,
00217 const unsigned char *yp, ssize_t ys);
00218
00219
00220
00221 void
00222 SyncAccumHashRaw(struct SyncLongHashStruct *hp,
00223 const unsigned char *xp, size_t xs);
00224
00225
00226
00227
00228 void
00229 SyncAccumHashInner(struct SyncLongHashStruct *hp,
00230 const struct ccn_buf_decoder *d);
00231
00232
00233
00234
00235 void
00236 SyncAccumHash(struct SyncLongHashStruct *hp, const struct ccn_charbuf *cb);
00237
00238
00239 extern struct ccn_charbuf *
00240 SyncLongHashToBuf(const struct SyncLongHashStruct *hp);
00241
00242
00243
00244 uint32_t
00245 SyncSmallHash(const unsigned char * xp, ssize_t xs);
00246
00247
00248
00249
00250
00251
00252
00253 int
00254 SyncAppendTaggedNumber(struct ccn_charbuf *cb,
00255 enum ccn_dtag dtag,
00256 unsigned val);
00257
00258
00259 int
00260 SyncAppendRandomBytes(struct ccn_charbuf *cb, int n);
00261
00262
00263 int
00264 SyncAppendRandomHash(struct ccn_charbuf *cb, int n);
00265
00266
00267 int
00268 SyncAppendRandomName(struct ccn_charbuf *cb, int nComp, int maxCompLen);
00269
00270
00271
00272
00273
00274 int
00275 SyncAppendElementInner(struct ccn_charbuf *cb, struct ccn_buf_decoder *d);
00276
00277
00278
00279
00280 int
00281 SyncAppendElement(struct ccn_charbuf *dst, const struct ccn_charbuf *src);
00282
00283 struct ccn_charbuf *
00284 SyncExtractName(struct ccn_buf_decoder *d);
00285
00286 struct ccn_charbuf *
00287 SyncCopyName(const struct ccn_charbuf *name);
00288
00289
00290
00291
00292
00293 unsigned
00294 SyncParseUnsigned(struct ccn_buf_decoder *d, enum ccn_dtag dtag);
00295
00296 ssize_t
00297 SyncParseHash(struct ccn_buf_decoder *d);
00298
00299 ssize_t
00300 SyncParseName(struct ccn_buf_decoder *d);
00301
00302
00303
00304
00305
00306 struct SyncNameAccumEntry {
00307 struct ccn_charbuf *name;
00308 intmax_t data;
00309 };
00310
00311 struct SyncNameAccum {
00312 int len;
00313 int lim;
00314 struct SyncNameAccumEntry *ents;
00315 };
00316
00317
00318
00319
00320 struct SyncNameAccum *
00321 SyncAllocNameAccum(int lim);
00322
00323
00324
00325
00326
00327 struct SyncNameAccum *
00328 SyncFreeNameAccum(struct SyncNameAccum *na);
00329
00330
00331
00332
00333
00334 struct SyncNameAccum *
00335 SyncFreeNameAccumAndNames(struct SyncNameAccum *na);
00336
00337
00338
00339
00340
00341 int
00342 SyncNameAccumSorter(IndexSorter_Base base,
00343 IndexSorter_Index x, IndexSorter_Index y);
00344
00345
00346
00347
00348
00349 int
00350 SyncNameAccumAppend(struct SyncNameAccum *na,
00351 struct ccn_charbuf *name,
00352 intmax_t data);
00353
00354
00355
00356
00357
00358
00359
00360 struct ccn_charbuf *
00361 SyncNameAccumCanon(struct SyncNameAccum *na,
00362 const struct ccn_charbuf *name);
00363
00364 struct SyncNodeAccum {
00365 int len;
00366 int lim;
00367 struct SyncNodeComposite **ents;
00368 };
00369
00370 struct SyncNodeAccum *
00371 SyncAllocNodeAccum(int lim);
00372
00373 struct SyncNodeAccum *
00374 SyncFreeNodeAccum(struct SyncNodeAccum *na);
00375
00376 void
00377 SyncAccumNode(struct SyncNodeAccum *na, struct SyncNodeComposite *nc);
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388 struct ccn_charbuf *
00389 SyncGenInterest(struct ccn_charbuf *name,
00390 int scope,
00391 int lifetime,
00392 int maxSuffix,
00393 int childPref,
00394 struct SyncNameAccum *excl);
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404 struct ccn_charbuf *
00405 SyncNameForLocalNode(struct SyncRootStruct *root, struct ccn_charbuf *hash);
00406
00407
00408
00409
00410
00411
00412 int
00413 SyncPointerToContent(struct ccn_charbuf *cb, struct ccn_parsed_ContentObject *pco,
00414 const unsigned char **xp, size_t *xs);
00415
00416
00417
00418
00419
00420
00421 struct ccn_charbuf *
00422 SyncSignBuf(struct SyncBaseStruct *base,
00423 struct ccn_charbuf *cb,
00424 struct ccn_charbuf *name,
00425 long fresh, int flags);
00426
00427
00428
00429
00430
00431
00432
00433
00434 int
00435 SyncLocalRepoFetch(struct SyncBaseStruct *base,
00436 struct ccn_charbuf *name,
00437 struct ccn_charbuf *cb,
00438 struct ccn_parsed_ContentObject *pco);
00439
00440
00441
00442
00443
00444
00445 int
00446 SyncLocalRepoStore(struct SyncBaseStruct *base,
00447 struct ccn_charbuf *name,
00448 struct ccn_charbuf *content,
00449 int flags);
00450
00451 #endif
00452