rugged 0.1.2 → 0.16.0b1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +25 -36
- data/Rakefile +20 -98
- data/ext/rugged/extconf.rb +44 -4
- data/ext/rugged/remote.c +215 -0
- data/ext/rugged/rugged.c +171 -0
- data/ext/rugged/rugged.h +126 -0
- data/ext/rugged/rugged_blob.c +99 -0
- data/ext/rugged/rugged_commit.c +224 -0
- data/ext/rugged/rugged_config.c +238 -0
- data/ext/rugged/rugged_index.c +440 -0
- data/ext/rugged/rugged_object.c +203 -0
- data/ext/rugged/rugged_reference.c +401 -0
- data/ext/rugged/rugged_repo.c +482 -0
- data/ext/rugged/rugged_revwalk.c +138 -0
- data/ext/rugged/rugged_signature.c +80 -0
- data/ext/rugged/rugged_tag.c +216 -0
- data/ext/rugged/rugged_tree.c +322 -0
- data/ext/rugged/vendor/libgit2-dist.tar.gz +0 -0
- data/ext/rugged/vendor/libgit2-dist/deps/http-parser/http_parser.c +1778 -0
- data/ext/rugged/vendor/libgit2-dist/deps/http-parser/http_parser.h +267 -0
- data/ext/rugged/vendor/libgit2-dist/deps/zlib/adler32.c +169 -0
- data/ext/rugged/vendor/libgit2-dist/deps/zlib/crc32.c +442 -0
- data/ext/rugged/vendor/libgit2-dist/deps/zlib/crc32.h +441 -0
- data/ext/rugged/vendor/libgit2-dist/deps/zlib/deflate.c +1834 -0
- data/ext/rugged/vendor/libgit2-dist/deps/zlib/deflate.h +342 -0
- data/ext/rugged/vendor/libgit2-dist/deps/zlib/inffast.c +340 -0
- data/ext/rugged/vendor/libgit2-dist/deps/zlib/inffast.h +11 -0
- data/ext/rugged/vendor/libgit2-dist/deps/zlib/inffixed.h +94 -0
- data/ext/rugged/vendor/libgit2-dist/deps/zlib/inflate.c +1480 -0
- data/ext/rugged/vendor/libgit2-dist/deps/zlib/inflate.h +122 -0
- data/ext/rugged/vendor/libgit2-dist/deps/zlib/inftrees.c +330 -0
- data/ext/rugged/vendor/libgit2-dist/deps/zlib/inftrees.h +62 -0
- data/ext/rugged/vendor/libgit2-dist/deps/zlib/trees.c +1244 -0
- data/ext/rugged/vendor/libgit2-dist/deps/zlib/trees.h +128 -0
- data/ext/rugged/vendor/libgit2-dist/deps/zlib/zconf.h +54 -0
- data/ext/rugged/vendor/libgit2-dist/deps/zlib/zlib.h +1613 -0
- data/ext/rugged/vendor/libgit2-dist/deps/zlib/zutil.c +318 -0
- data/ext/rugged/vendor/libgit2-dist/deps/zlib/zutil.h +274 -0
- data/ext/rugged/vendor/libgit2-dist/examples/general.c +451 -0
- data/ext/rugged/vendor/libgit2-dist/examples/network/common.h +14 -0
- data/ext/rugged/vendor/libgit2-dist/examples/network/fetch.c +97 -0
- data/ext/rugged/vendor/libgit2-dist/examples/network/git2.c +58 -0
- data/ext/rugged/vendor/libgit2-dist/examples/network/index-pack.c +47 -0
- data/ext/rugged/vendor/libgit2-dist/examples/network/ls-remote.c +76 -0
- data/ext/rugged/vendor/libgit2-dist/examples/showindex.c +43 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2.h +44 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/blob.h +120 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/branch.h +15 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/commit.h +263 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/common.h +103 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/config.h +278 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/errors.h +144 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/index.h +306 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/indexer.h +76 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/inttypes.h +305 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/net.h +51 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/object.h +173 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/odb.h +331 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/odb_backend.h +100 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/oid.h +218 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/reflog.h +128 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/refs.h +309 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/refspec.h +60 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/remote.h +176 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/repository.h +290 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/revwalk.h +169 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/signature.h +65 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/status.h +63 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/stdint.h +247 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/tag.h +279 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/threads.h +48 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/tree.h +318 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/types.h +169 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/version.h +15 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/windows.h +59 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/zlib.h +40 -0
- data/ext/rugged/vendor/libgit2-dist/src/blob.c +135 -0
- data/ext/rugged/vendor/libgit2-dist/src/blob.h +23 -0
- data/ext/rugged/vendor/libgit2-dist/src/bswap.h +97 -0
- data/ext/rugged/vendor/libgit2-dist/src/buffer.c +113 -0
- data/ext/rugged/vendor/libgit2-dist/src/buffer.h +32 -0
- data/ext/rugged/vendor/libgit2-dist/src/cache.c +111 -0
- data/ext/rugged/vendor/libgit2-dist/src/cache.h +64 -0
- data/ext/rugged/vendor/libgit2-dist/src/cc-compat.h +67 -0
- data/ext/rugged/vendor/libgit2-dist/src/commit.c +299 -0
- data/ext/rugged/vendor/libgit2-dist/src/commit.h +34 -0
- data/ext/rugged/vendor/libgit2-dist/src/common.h +64 -0
- data/ext/rugged/vendor/libgit2-dist/src/config.c +418 -0
- data/ext/rugged/vendor/libgit2-dist/src/config.h +24 -0
- data/ext/rugged/vendor/libgit2-dist/src/config_file.c +1210 -0
- data/ext/rugged/vendor/libgit2-dist/src/delta-apply.c +115 -0
- data/ext/rugged/vendor/libgit2-dist/src/delta-apply.h +33 -0
- data/ext/rugged/vendor/libgit2-dist/src/dir.h +47 -0
- data/ext/rugged/vendor/libgit2-dist/src/errors.c +104 -0
- data/ext/rugged/vendor/libgit2-dist/src/fetch.c +172 -0
- data/ext/rugged/vendor/libgit2-dist/src/fetch.h +18 -0
- data/ext/rugged/vendor/libgit2-dist/src/filebuf.c +400 -0
- data/ext/rugged/vendor/libgit2-dist/src/filebuf.h +72 -0
- data/ext/rugged/vendor/libgit2-dist/src/fileops.c +358 -0
- data/ext/rugged/vendor/libgit2-dist/src/fileops.h +151 -0
- data/ext/rugged/vendor/libgit2-dist/src/global.c +134 -0
- data/ext/rugged/vendor/libgit2-dist/src/global.h +24 -0
- data/ext/rugged/vendor/libgit2-dist/src/hash.c +74 -0
- data/ext/rugged/vendor/libgit2-dist/src/hash.h +29 -0
- data/ext/rugged/vendor/libgit2-dist/src/hashtable.c +243 -0
- data/ext/rugged/vendor/libgit2-dist/src/hashtable.h +80 -0
- data/ext/rugged/vendor/libgit2-dist/src/index.c +918 -0
- data/ext/rugged/vendor/libgit2-dist/src/index.h +34 -0
- data/ext/rugged/vendor/libgit2-dist/src/indexer.c +401 -0
- data/ext/rugged/vendor/libgit2-dist/src/map.h +37 -0
- data/ext/rugged/vendor/libgit2-dist/src/mwindow.c +272 -0
- data/ext/rugged/vendor/libgit2-dist/src/mwindow.h +45 -0
- data/ext/rugged/vendor/libgit2-dist/src/netops.c +198 -0
- data/ext/rugged/vendor/libgit2-dist/src/netops.h +36 -0
- data/ext/rugged/vendor/libgit2-dist/src/object.c +295 -0
- data/ext/rugged/vendor/libgit2-dist/src/odb.c +672 -0
- data/ext/rugged/vendor/libgit2-dist/src/odb.h +43 -0
- data/ext/rugged/vendor/libgit2-dist/src/odb_loose.c +855 -0
- data/ext/rugged/vendor/libgit2-dist/src/odb_pack.c +485 -0
- data/ext/rugged/vendor/libgit2-dist/src/oid.c +388 -0
- data/ext/rugged/vendor/libgit2-dist/src/pack.c +788 -0
- data/ext/rugged/vendor/libgit2-dist/src/pack.h +99 -0
- data/ext/rugged/vendor/libgit2-dist/src/path.c +270 -0
- data/ext/rugged/vendor/libgit2-dist/src/path.h +84 -0
- data/ext/rugged/vendor/libgit2-dist/src/pkt.c +426 -0
- data/ext/rugged/vendor/libgit2-dist/src/pkt.h +77 -0
- data/ext/rugged/vendor/libgit2-dist/src/posix.c +94 -0
- data/ext/rugged/vendor/libgit2-dist/src/posix.h +69 -0
- data/ext/rugged/vendor/libgit2-dist/src/ppc/sha1.c +70 -0
- data/ext/rugged/vendor/libgit2-dist/src/ppc/sha1.h +26 -0
- data/ext/rugged/vendor/libgit2-dist/src/pqueue.c +141 -0
- data/ext/rugged/vendor/libgit2-dist/src/pqueue.h +81 -0
- data/ext/rugged/vendor/libgit2-dist/src/protocol.c +50 -0
- data/ext/rugged/vendor/libgit2-dist/src/protocol.h +23 -0
- data/ext/rugged/vendor/libgit2-dist/src/reflog.c +318 -0
- data/ext/rugged/vendor/libgit2-dist/src/reflog.h +34 -0
- data/ext/rugged/vendor/libgit2-dist/src/refs.c +1693 -0
- data/ext/rugged/vendor/libgit2-dist/src/refs.h +58 -0
- data/ext/rugged/vendor/libgit2-dist/src/refspec.c +95 -0
- data/ext/rugged/vendor/libgit2-dist/src/refspec.h +23 -0
- data/ext/rugged/vendor/libgit2-dist/src/remote.c +339 -0
- data/ext/rugged/vendor/libgit2-dist/src/remote.h +25 -0
- data/ext/rugged/vendor/libgit2-dist/src/repository.c +849 -0
- data/ext/rugged/vendor/libgit2-dist/src/repository.h +60 -0
- data/ext/rugged/vendor/libgit2-dist/src/revwalk.c +569 -0
- data/ext/rugged/vendor/libgit2-dist/src/sha1.c +280 -0
- data/ext/rugged/vendor/libgit2-dist/src/sha1.h +21 -0
- data/ext/rugged/vendor/libgit2-dist/src/sha1_lookup.c +177 -0
- data/ext/rugged/vendor/libgit2-dist/src/sha1_lookup.h +18 -0
- data/ext/rugged/vendor/libgit2-dist/src/signature.c +335 -0
- data/ext/rugged/vendor/libgit2-dist/src/signature.h +18 -0
- data/ext/rugged/vendor/libgit2-dist/src/status.c +696 -0
- data/ext/rugged/vendor/libgit2-dist/src/tag.c +446 -0
- data/ext/rugged/vendor/libgit2-dist/src/tag.h +28 -0
- data/ext/rugged/vendor/libgit2-dist/src/thread-utils.c +55 -0
- data/ext/rugged/vendor/libgit2-dist/src/thread-utils.h +108 -0
- data/ext/rugged/vendor/libgit2-dist/src/transport.c +85 -0
- data/ext/rugged/vendor/libgit2-dist/src/transport.h +110 -0
- data/ext/rugged/vendor/libgit2-dist/src/transports/git.c +502 -0
- data/ext/rugged/vendor/libgit2-dist/src/transports/http.c +756 -0
- data/ext/rugged/vendor/libgit2-dist/src/transports/local.c +235 -0
- data/ext/rugged/vendor/libgit2-dist/src/tree-cache.c +201 -0
- data/ext/rugged/vendor/libgit2-dist/src/tree-cache.h +31 -0
- data/ext/rugged/vendor/libgit2-dist/src/tree.c +758 -0
- data/ext/rugged/vendor/libgit2-dist/src/tree.h +37 -0
- data/ext/rugged/vendor/libgit2-dist/src/tsort.c +365 -0
- data/ext/rugged/vendor/libgit2-dist/src/unix/map.c +70 -0
- data/ext/rugged/vendor/libgit2-dist/src/unix/posix.h +25 -0
- data/ext/rugged/vendor/libgit2-dist/src/util.c +381 -0
- data/ext/rugged/vendor/libgit2-dist/src/util.h +137 -0
- data/ext/rugged/vendor/libgit2-dist/src/vector.c +174 -0
- data/ext/rugged/vendor/libgit2-dist/src/vector.h +45 -0
- data/ext/rugged/vendor/libgit2-dist/src/win32/dir.c +115 -0
- data/ext/rugged/vendor/libgit2-dist/src/win32/fnmatch.c +180 -0
- data/ext/rugged/vendor/libgit2-dist/src/win32/fnmatch.h +27 -0
- data/ext/rugged/vendor/libgit2-dist/src/win32/map.c +131 -0
- data/ext/rugged/vendor/libgit2-dist/src/win32/mingw-compat.h +24 -0
- data/ext/rugged/vendor/libgit2-dist/src/win32/msvc-compat.h +38 -0
- data/ext/rugged/vendor/libgit2-dist/src/win32/posix.h +53 -0
- data/ext/rugged/vendor/libgit2-dist/src/win32/posix_w32.c +404 -0
- data/ext/rugged/vendor/libgit2-dist/src/win32/pthread.c +65 -0
- data/ext/rugged/vendor/libgit2-dist/src/win32/pthread.h +40 -0
- data/ext/rugged/vendor/libgit2-dist/src/win32/utf-conv.c +88 -0
- data/ext/rugged/vendor/libgit2-dist/src/win32/utf-conv.h +17 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/buf/basic.c +29 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/clay.h +187 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/clay_libgit2.h +28 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/clay_main.c +1073 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/config/add.c +37 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/config/new.c +36 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/config/read.c +209 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/config/stress.c +39 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/config/write.c +77 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/core/dirent.c +222 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/core/filebuf.c +106 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/core/oid.c +18 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/core/path.c +139 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/core/rmdir.c +50 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/core/string.c +28 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/core/strtol.c +37 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/core/vector.c +66 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/index/rename.c +60 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/network/remotes.c +50 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/object/raw/chars.c +52 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/object/raw/compare.c +124 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/object/raw/convert.c +75 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/object/raw/data.h +323 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/object/raw/fromstr.c +30 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/object/raw/hash.c +162 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/object/raw/short.c +94 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/object/raw/size.c +13 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/object/raw/type2string.c +54 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/object/tree/frompath.c +75 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/odb/loose.c +84 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/odb/loose_data.h +522 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/odb/pack_data.h +151 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/odb/packed.c +78 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/odb/sorting.c +71 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/repo/getters.c +68 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/repo/init.c +104 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/repo/open.c +54 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/status/single.c +38 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/status/status_data.h +48 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/status/worktree.c +124 -0
- data/ext/rugged/vendor/libgit2-dist/tests/t00-core.c +628 -0
- data/ext/rugged/vendor/libgit2-dist/tests/t01-data.h +322 -0
- data/ext/rugged/vendor/libgit2-dist/tests/t01-rawobj.c +638 -0
- data/ext/rugged/vendor/libgit2-dist/tests/t03-data.h +344 -0
- data/ext/rugged/vendor/libgit2-dist/tests/t03-objwrite.c +255 -0
- data/ext/rugged/vendor/libgit2-dist/tests/t04-commit.c +788 -0
- data/ext/rugged/vendor/libgit2-dist/tests/t05-revwalk.c +140 -0
- data/ext/rugged/vendor/libgit2-dist/tests/t06-index.c +219 -0
- data/ext/rugged/vendor/libgit2-dist/tests/t07-hashtable.c +192 -0
- data/ext/rugged/vendor/libgit2-dist/tests/t08-tag.c +357 -0
- data/ext/rugged/vendor/libgit2-dist/tests/t09-tree.c +221 -0
- data/ext/rugged/vendor/libgit2-dist/tests/t10-refs.c +1294 -0
- data/ext/rugged/vendor/libgit2-dist/tests/t12-repo.c +174 -0
- data/ext/rugged/vendor/libgit2-dist/tests/t13-threads.c +41 -0
- data/ext/rugged/vendor/libgit2-dist/tests/t17-bufs.c +61 -0
- data/ext/rugged/vendor/libgit2-dist/tests/t18-status.c +448 -0
- data/ext/rugged/vendor/libgit2-dist/tests/test_helpers.c +310 -0
- data/ext/rugged/vendor/libgit2-dist/tests/test_helpers.h +83 -0
- data/ext/rugged/vendor/libgit2-dist/tests/test_lib.c +198 -0
- data/ext/rugged/vendor/libgit2-dist/tests/test_lib.h +54 -0
- data/ext/rugged/vendor/libgit2-dist/tests/test_main.c +89 -0
- data/lib/rugged.rb +4 -3
- data/lib/rugged/index.rb +0 -8
- data/lib/rugged/objects.rb +45 -0
- data/lib/rugged/repository.rb +29 -0
- data/lib/rugged/tree.rb +16 -6
- data/lib/rugged/version.rb +1 -1
- data/lib/rugged/walker.rb +5 -0
- data/test/blob_test.rb +18 -14
- data/test/commit_test.rb +28 -26
- data/test/coverage/HEAD.json +1 -0
- data/test/coverage/cover.rb +106 -0
- data/test/fixtures/testrepo.git/refs/heads/new_name +1 -0
- data/test/index_test.rb +101 -78
- data/test/lib_test.rb +4 -4
- data/test/object_test.rb +3 -3
- data/test/reference_test.rb +75 -0
- data/test/remote_test.rb +19 -0
- data/test/repo_pack_test.rb +4 -4
- data/test/repo_test.rb +44 -15
- data/test/tag_test.rb +7 -17
- data/test/test_helper.rb +24 -5
- data/test/tree_test.rb +30 -12
- data/test/walker_test.rb +40 -31
- metadata +273 -50
- data/lib/rugged/person.rb +0 -20
- data/lib/rugged/tree_entry.rb +0 -9
- data/test/fixtures/testrepo.git/objects/1d/83f106355e4309a293e42ad2a2c4b8bdbe77ae +0 -0
- data/test/fixtures/testrepo.git/objects/2f/3321418db5b2a841375b8b70880a8ab5a4148f +0 -0
- data/test/fixtures/testrepo.git/objects/36/9b00a7700cca3a506d79e301d6ad8bf735d9ee +0 -3
- data/test/fixtures/testrepo.git/objects/3d/b1b5ceace59ff65279757003763046fd4cbbe6 +0 -0
- data/test/fixtures/testrepo.git/objects/4c/d1604907792e2c43e03dcec1216f99d63e68c4 +0 -3
- data/test/fixtures/testrepo.git/objects/e0/f46d77041c149296549b01ed4a18b02c4b7400 +0 -0
@@ -0,0 +1,267 @@
|
|
1
|
+
/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
|
2
|
+
*
|
3
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
* of this software and associated documentation files (the "Software"), to
|
5
|
+
* deal in the Software without restriction, including without limitation the
|
6
|
+
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
7
|
+
* sell copies of the Software, and to permit persons to whom the Software is
|
8
|
+
* furnished to do so, subject to the following conditions:
|
9
|
+
*
|
10
|
+
* The above copyright notice and this permission notice shall be included in
|
11
|
+
* all copies or substantial portions of the Software.
|
12
|
+
*
|
13
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
18
|
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
19
|
+
* IN THE SOFTWARE.
|
20
|
+
*/
|
21
|
+
#ifndef http_parser_h
|
22
|
+
#define http_parser_h
|
23
|
+
#ifdef __cplusplus
|
24
|
+
extern "C" {
|
25
|
+
#endif
|
26
|
+
|
27
|
+
#define HTTP_PARSER_VERSION_MAJOR 1
|
28
|
+
#define HTTP_PARSER_VERSION_MINOR 0
|
29
|
+
|
30
|
+
#ifdef _MSC_VER
|
31
|
+
/* disable silly warnings */
|
32
|
+
# pragma warning(disable: 4127 4214)
|
33
|
+
#endif
|
34
|
+
|
35
|
+
#include <sys/types.h>
|
36
|
+
#include "git2/common.h"
|
37
|
+
|
38
|
+
/* Compile with -DHTTP_PARSER_STRICT=0 to make less checks, but run
|
39
|
+
* faster
|
40
|
+
*/
|
41
|
+
#ifndef HTTP_PARSER_STRICT
|
42
|
+
# define HTTP_PARSER_STRICT 1
|
43
|
+
#endif
|
44
|
+
|
45
|
+
/* Compile with -DHTTP_PARSER_DEBUG=1 to add extra debugging information to
|
46
|
+
* the error reporting facility.
|
47
|
+
*/
|
48
|
+
#ifndef HTTP_PARSER_DEBUG
|
49
|
+
# define HTTP_PARSER_DEBUG 0
|
50
|
+
#endif
|
51
|
+
|
52
|
+
|
53
|
+
/* Maximium header size allowed */
|
54
|
+
#define HTTP_MAX_HEADER_SIZE (80*1024)
|
55
|
+
|
56
|
+
|
57
|
+
typedef struct http_parser http_parser;
|
58
|
+
typedef struct http_parser_settings http_parser_settings;
|
59
|
+
typedef struct http_parser_result http_parser_result;
|
60
|
+
|
61
|
+
|
62
|
+
/* Callbacks should return non-zero to indicate an error. The parser will
|
63
|
+
* then halt execution.
|
64
|
+
*
|
65
|
+
* The one exception is on_headers_complete. In a HTTP_RESPONSE parser
|
66
|
+
* returning '1' from on_headers_complete will tell the parser that it
|
67
|
+
* should not expect a body. This is used when receiving a response to a
|
68
|
+
* HEAD request which may contain 'Content-Length' or 'Transfer-Encoding:
|
69
|
+
* chunked' headers that indicate the presence of a body.
|
70
|
+
*
|
71
|
+
* http_data_cb does not return data chunks. It will be call arbitrarally
|
72
|
+
* many times for each string. E.G. you might get 10 callbacks for "on_path"
|
73
|
+
* each providing just a few characters more data.
|
74
|
+
*/
|
75
|
+
typedef int (*http_data_cb) (http_parser*, const char *at, size_t length);
|
76
|
+
typedef int (*http_cb) (http_parser*);
|
77
|
+
|
78
|
+
|
79
|
+
/* Request Methods */
|
80
|
+
enum http_method
|
81
|
+
{ HTTP_DELETE = 0
|
82
|
+
, HTTP_GET
|
83
|
+
, HTTP_HEAD
|
84
|
+
, HTTP_POST
|
85
|
+
, HTTP_PUT
|
86
|
+
/* pathological */
|
87
|
+
, HTTP_CONNECT
|
88
|
+
, HTTP_OPTIONS
|
89
|
+
, HTTP_TRACE
|
90
|
+
/* webdav */
|
91
|
+
, HTTP_COPY
|
92
|
+
, HTTP_LOCK
|
93
|
+
, HTTP_MKCOL
|
94
|
+
, HTTP_MOVE
|
95
|
+
, HTTP_PROPFIND
|
96
|
+
, HTTP_PROPPATCH
|
97
|
+
, HTTP_UNLOCK
|
98
|
+
/* subversion */
|
99
|
+
, HTTP_REPORT
|
100
|
+
, HTTP_MKACTIVITY
|
101
|
+
, HTTP_CHECKOUT
|
102
|
+
, HTTP_MERGE
|
103
|
+
/* upnp */
|
104
|
+
, HTTP_MSEARCH
|
105
|
+
, HTTP_NOTIFY
|
106
|
+
, HTTP_SUBSCRIBE
|
107
|
+
, HTTP_UNSUBSCRIBE
|
108
|
+
/* RFC-5789 */
|
109
|
+
, HTTP_PATCH
|
110
|
+
};
|
111
|
+
|
112
|
+
|
113
|
+
enum http_parser_type { HTTP_REQUEST, HTTP_RESPONSE, HTTP_BOTH };
|
114
|
+
|
115
|
+
|
116
|
+
/* Flag values for http_parser.flags field */
|
117
|
+
enum flags
|
118
|
+
{ F_CHUNKED = 1 << 0
|
119
|
+
, F_CONNECTION_KEEP_ALIVE = 1 << 1
|
120
|
+
, F_CONNECTION_CLOSE = 1 << 2
|
121
|
+
, F_TRAILING = 1 << 3
|
122
|
+
, F_UPGRADE = 1 << 4
|
123
|
+
, F_SKIPBODY = 1 << 5
|
124
|
+
};
|
125
|
+
|
126
|
+
|
127
|
+
/* Map for errno-related constants
|
128
|
+
*
|
129
|
+
* The provided argument should be a macro that takes 2 arguments.
|
130
|
+
*/
|
131
|
+
#define HTTP_ERRNO_MAP(XX) \
|
132
|
+
/* No error */ \
|
133
|
+
XX(OK, "success") \
|
134
|
+
\
|
135
|
+
/* Callback-related errors */ \
|
136
|
+
XX(CB_message_begin, "the on_message_begin callback failed") \
|
137
|
+
XX(CB_path, "the on_path callback failed") \
|
138
|
+
XX(CB_query_string, "the on_query_string callback failed") \
|
139
|
+
XX(CB_url, "the on_url callback failed") \
|
140
|
+
XX(CB_fragment, "the on_fragment callback failed") \
|
141
|
+
XX(CB_header_field, "the on_header_field callback failed") \
|
142
|
+
XX(CB_header_value, "the on_header_value callback failed") \
|
143
|
+
XX(CB_headers_complete, "the on_headers_complete callback failed") \
|
144
|
+
XX(CB_body, "the on_body callback failed") \
|
145
|
+
XX(CB_message_complete, "the on_message_complete callback failed") \
|
146
|
+
\
|
147
|
+
/* Parsing-related errors */ \
|
148
|
+
XX(INVALID_EOF_STATE, "stream ended at an unexpected time") \
|
149
|
+
XX(HEADER_OVERFLOW, \
|
150
|
+
"too many header bytes seen; overflow detected") \
|
151
|
+
XX(CLOSED_CONNECTION, \
|
152
|
+
"data received after completed connection: close message") \
|
153
|
+
XX(INVALID_VERSION, "invalid HTTP version") \
|
154
|
+
XX(INVALID_STATUS, "invalid HTTP status code") \
|
155
|
+
XX(INVALID_METHOD, "invalid HTTP method") \
|
156
|
+
XX(INVALID_URL, "invalid URL") \
|
157
|
+
XX(INVALID_HOST, "invalid host") \
|
158
|
+
XX(INVALID_PORT, "invalid port") \
|
159
|
+
XX(INVALID_PATH, "invalid path") \
|
160
|
+
XX(INVALID_QUERY_STRING, "invalid query string") \
|
161
|
+
XX(INVALID_FRAGMENT, "invalid fragment") \
|
162
|
+
XX(LF_EXPECTED, "LF character expected") \
|
163
|
+
XX(INVALID_HEADER_TOKEN, "invalid character in header") \
|
164
|
+
XX(INVALID_CONTENT_LENGTH, \
|
165
|
+
"invalid character in content-length header") \
|
166
|
+
XX(INVALID_CHUNK_SIZE, \
|
167
|
+
"invalid character in chunk size header") \
|
168
|
+
XX(INVALID_CONSTANT, "invalid constant string") \
|
169
|
+
XX(INVALID_INTERNAL_STATE, "encountered unexpected internal state")\
|
170
|
+
XX(STRICT, "strict mode assertion failed") \
|
171
|
+
XX(UNKNOWN, "an unknown error occurred")
|
172
|
+
|
173
|
+
|
174
|
+
/* Define HPE_* values for each errno value above */
|
175
|
+
#define HTTP_ERRNO_GEN(n, s) HPE_##n,
|
176
|
+
enum http_errno {
|
177
|
+
HTTP_ERRNO_MAP(HTTP_ERRNO_GEN)
|
178
|
+
};
|
179
|
+
#undef HTTP_ERRNO_GEN
|
180
|
+
|
181
|
+
|
182
|
+
/* Get an http_errno value from an http_parser */
|
183
|
+
#define HTTP_PARSER_ERRNO(p) ((enum http_errno) (p)->http_errno)
|
184
|
+
|
185
|
+
/* Get the line number that generated the current error */
|
186
|
+
#if HTTP_PARSER_DEBUG
|
187
|
+
#define HTTP_PARSER_ERRNO_LINE(p) ((p)->error_lineno)
|
188
|
+
#else
|
189
|
+
#define HTTP_PARSER_ERRNO_LINE(p) 0
|
190
|
+
#endif
|
191
|
+
|
192
|
+
|
193
|
+
struct http_parser {
|
194
|
+
/** PRIVATE **/
|
195
|
+
unsigned char type : 2;
|
196
|
+
unsigned char flags : 6; /* F_* values from 'flags' enum; semi-public */
|
197
|
+
unsigned char state;
|
198
|
+
unsigned char header_state;
|
199
|
+
unsigned char index;
|
200
|
+
|
201
|
+
size_t nread;
|
202
|
+
int64_t content_length;
|
203
|
+
|
204
|
+
/** READ-ONLY **/
|
205
|
+
unsigned short http_major;
|
206
|
+
unsigned short http_minor;
|
207
|
+
unsigned short status_code; /* responses only */
|
208
|
+
unsigned char method; /* requests only */
|
209
|
+
unsigned char http_errno : 7;
|
210
|
+
|
211
|
+
/* 1 = Upgrade header was present and the parser has exited because of that.
|
212
|
+
* 0 = No upgrade header present.
|
213
|
+
* Should be checked when http_parser_execute() returns in addition to
|
214
|
+
* error checking.
|
215
|
+
*/
|
216
|
+
unsigned char upgrade : 1;
|
217
|
+
|
218
|
+
#if HTTP_PARSER_DEBUG
|
219
|
+
uint32_t error_lineno;
|
220
|
+
#endif
|
221
|
+
|
222
|
+
/** PUBLIC **/
|
223
|
+
void *data; /* A pointer to get hook to the "connection" or "socket" object */
|
224
|
+
};
|
225
|
+
|
226
|
+
|
227
|
+
struct http_parser_settings {
|
228
|
+
http_cb on_message_begin;
|
229
|
+
http_data_cb on_url;
|
230
|
+
http_data_cb on_header_field;
|
231
|
+
http_data_cb on_header_value;
|
232
|
+
http_cb on_headers_complete;
|
233
|
+
http_data_cb on_body;
|
234
|
+
http_cb on_message_complete;
|
235
|
+
};
|
236
|
+
|
237
|
+
|
238
|
+
void http_parser_init(http_parser *parser, enum http_parser_type type);
|
239
|
+
|
240
|
+
|
241
|
+
size_t http_parser_execute(http_parser *parser,
|
242
|
+
const http_parser_settings *settings,
|
243
|
+
const char *data,
|
244
|
+
size_t len);
|
245
|
+
|
246
|
+
|
247
|
+
/* If http_should_keep_alive() in the on_headers_complete or
|
248
|
+
* on_message_complete callback returns true, then this will be should be
|
249
|
+
* the last message on the connection.
|
250
|
+
* If you are the server, respond with the "Connection: close" header.
|
251
|
+
* If you are the client, close the connection.
|
252
|
+
*/
|
253
|
+
int http_should_keep_alive(http_parser *parser);
|
254
|
+
|
255
|
+
/* Returns a string version of the HTTP method. */
|
256
|
+
const char *http_method_str(enum http_method m);
|
257
|
+
|
258
|
+
/* Return a string name of the given error */
|
259
|
+
const char *http_errno_name(enum http_errno err);
|
260
|
+
|
261
|
+
/* Return a string description of the given error */
|
262
|
+
const char *http_errno_description(enum http_errno err);
|
263
|
+
|
264
|
+
#ifdef __cplusplus
|
265
|
+
}
|
266
|
+
#endif
|
267
|
+
#endif
|
@@ -0,0 +1,169 @@
|
|
1
|
+
/* adler32.c -- compute the Adler-32 checksum of a data stream
|
2
|
+
* Copyright (C) 1995-2007 Mark Adler
|
3
|
+
* For conditions of distribution and use, see copyright notice in zlib.h
|
4
|
+
*/
|
5
|
+
|
6
|
+
/* @(#) $Id$ */
|
7
|
+
|
8
|
+
#include "zutil.h"
|
9
|
+
|
10
|
+
#define local static
|
11
|
+
|
12
|
+
local uLong adler32_combine_(uLong adler1, uLong adler2, z_off64_t len2);
|
13
|
+
|
14
|
+
#define BASE 65521UL /* largest prime smaller than 65536 */
|
15
|
+
#define NMAX 5552
|
16
|
+
/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
|
17
|
+
|
18
|
+
#define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;}
|
19
|
+
#define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
|
20
|
+
#define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
|
21
|
+
#define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
|
22
|
+
#define DO16(buf) DO8(buf,0); DO8(buf,8);
|
23
|
+
|
24
|
+
/* use NO_DIVIDE if your processor does not do division in hardware */
|
25
|
+
#ifdef NO_DIVIDE
|
26
|
+
# define MOD(a) \
|
27
|
+
do { \
|
28
|
+
if (a >= (BASE << 16)) a -= (BASE << 16); \
|
29
|
+
if (a >= (BASE << 15)) a -= (BASE << 15); \
|
30
|
+
if (a >= (BASE << 14)) a -= (BASE << 14); \
|
31
|
+
if (a >= (BASE << 13)) a -= (BASE << 13); \
|
32
|
+
if (a >= (BASE << 12)) a -= (BASE << 12); \
|
33
|
+
if (a >= (BASE << 11)) a -= (BASE << 11); \
|
34
|
+
if (a >= (BASE << 10)) a -= (BASE << 10); \
|
35
|
+
if (a >= (BASE << 9)) a -= (BASE << 9); \
|
36
|
+
if (a >= (BASE << 8)) a -= (BASE << 8); \
|
37
|
+
if (a >= (BASE << 7)) a -= (BASE << 7); \
|
38
|
+
if (a >= (BASE << 6)) a -= (BASE << 6); \
|
39
|
+
if (a >= (BASE << 5)) a -= (BASE << 5); \
|
40
|
+
if (a >= (BASE << 4)) a -= (BASE << 4); \
|
41
|
+
if (a >= (BASE << 3)) a -= (BASE << 3); \
|
42
|
+
if (a >= (BASE << 2)) a -= (BASE << 2); \
|
43
|
+
if (a >= (BASE << 1)) a -= (BASE << 1); \
|
44
|
+
if (a >= BASE) a -= BASE; \
|
45
|
+
} while (0)
|
46
|
+
# define MOD4(a) \
|
47
|
+
do { \
|
48
|
+
if (a >= (BASE << 4)) a -= (BASE << 4); \
|
49
|
+
if (a >= (BASE << 3)) a -= (BASE << 3); \
|
50
|
+
if (a >= (BASE << 2)) a -= (BASE << 2); \
|
51
|
+
if (a >= (BASE << 1)) a -= (BASE << 1); \
|
52
|
+
if (a >= BASE) a -= BASE; \
|
53
|
+
} while (0)
|
54
|
+
#else
|
55
|
+
# define MOD(a) a %= BASE
|
56
|
+
# define MOD4(a) a %= BASE
|
57
|
+
#endif
|
58
|
+
|
59
|
+
/* ========================================================================= */
|
60
|
+
uLong ZEXPORT adler32(adler, buf, len)
|
61
|
+
uLong adler;
|
62
|
+
const Bytef *buf;
|
63
|
+
uInt len;
|
64
|
+
{
|
65
|
+
unsigned long sum2;
|
66
|
+
unsigned n;
|
67
|
+
|
68
|
+
/* split Adler-32 into component sums */
|
69
|
+
sum2 = (adler >> 16) & 0xffff;
|
70
|
+
adler &= 0xffff;
|
71
|
+
|
72
|
+
/* in case user likes doing a byte at a time, keep it fast */
|
73
|
+
if (len == 1) {
|
74
|
+
adler += buf[0];
|
75
|
+
if (adler >= BASE)
|
76
|
+
adler -= BASE;
|
77
|
+
sum2 += adler;
|
78
|
+
if (sum2 >= BASE)
|
79
|
+
sum2 -= BASE;
|
80
|
+
return adler | (sum2 << 16);
|
81
|
+
}
|
82
|
+
|
83
|
+
/* initial Adler-32 value (deferred check for len == 1 speed) */
|
84
|
+
if (buf == Z_NULL)
|
85
|
+
return 1L;
|
86
|
+
|
87
|
+
/* in case short lengths are provided, keep it somewhat fast */
|
88
|
+
if (len < 16) {
|
89
|
+
while (len--) {
|
90
|
+
adler += *buf++;
|
91
|
+
sum2 += adler;
|
92
|
+
}
|
93
|
+
if (adler >= BASE)
|
94
|
+
adler -= BASE;
|
95
|
+
MOD4(sum2); /* only added so many BASE's */
|
96
|
+
return adler | (sum2 << 16);
|
97
|
+
}
|
98
|
+
|
99
|
+
/* do length NMAX blocks -- requires just one modulo operation */
|
100
|
+
while (len >= NMAX) {
|
101
|
+
len -= NMAX;
|
102
|
+
n = NMAX / 16; /* NMAX is divisible by 16 */
|
103
|
+
do {
|
104
|
+
DO16(buf); /* 16 sums unrolled */
|
105
|
+
buf += 16;
|
106
|
+
} while (--n);
|
107
|
+
MOD(adler);
|
108
|
+
MOD(sum2);
|
109
|
+
}
|
110
|
+
|
111
|
+
/* do remaining bytes (less than NMAX, still just one modulo) */
|
112
|
+
if (len) { /* avoid modulos if none remaining */
|
113
|
+
while (len >= 16) {
|
114
|
+
len -= 16;
|
115
|
+
DO16(buf);
|
116
|
+
buf += 16;
|
117
|
+
}
|
118
|
+
while (len--) {
|
119
|
+
adler += *buf++;
|
120
|
+
sum2 += adler;
|
121
|
+
}
|
122
|
+
MOD(adler);
|
123
|
+
MOD(sum2);
|
124
|
+
}
|
125
|
+
|
126
|
+
/* return recombined sums */
|
127
|
+
return adler | (sum2 << 16);
|
128
|
+
}
|
129
|
+
|
130
|
+
/* ========================================================================= */
|
131
|
+
local uLong adler32_combine_(adler1, adler2, len2)
|
132
|
+
uLong adler1;
|
133
|
+
uLong adler2;
|
134
|
+
z_off64_t len2;
|
135
|
+
{
|
136
|
+
unsigned long sum1;
|
137
|
+
unsigned long sum2;
|
138
|
+
unsigned rem;
|
139
|
+
|
140
|
+
/* the derivation of this formula is left as an exercise for the reader */
|
141
|
+
rem = (unsigned)(len2 % BASE);
|
142
|
+
sum1 = adler1 & 0xffff;
|
143
|
+
sum2 = rem * sum1;
|
144
|
+
MOD(sum2);
|
145
|
+
sum1 += (adler2 & 0xffff) + BASE - 1;
|
146
|
+
sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem;
|
147
|
+
if (sum1 >= BASE) sum1 -= BASE;
|
148
|
+
if (sum1 >= BASE) sum1 -= BASE;
|
149
|
+
if (sum2 >= (BASE << 1)) sum2 -= (BASE << 1);
|
150
|
+
if (sum2 >= BASE) sum2 -= BASE;
|
151
|
+
return sum1 | (sum2 << 16);
|
152
|
+
}
|
153
|
+
|
154
|
+
/* ========================================================================= */
|
155
|
+
uLong ZEXPORT adler32_combine(adler1, adler2, len2)
|
156
|
+
uLong adler1;
|
157
|
+
uLong adler2;
|
158
|
+
z_off_t len2;
|
159
|
+
{
|
160
|
+
return adler32_combine_(adler1, adler2, len2);
|
161
|
+
}
|
162
|
+
|
163
|
+
uLong ZEXPORT adler32_combine64(adler1, adler2, len2)
|
164
|
+
uLong adler1;
|
165
|
+
uLong adler2;
|
166
|
+
z_off64_t len2;
|
167
|
+
{
|
168
|
+
return adler32_combine_(adler1, adler2, len2);
|
169
|
+
}
|
@@ -0,0 +1,442 @@
|
|
1
|
+
/* crc32.c -- compute the CRC-32 of a data stream
|
2
|
+
* Copyright (C) 1995-2006, 2010 Mark Adler
|
3
|
+
* For conditions of distribution and use, see copyright notice in zlib.h
|
4
|
+
*
|
5
|
+
* Thanks to Rodney Brown <rbrown64@csc.com.au> for his contribution of faster
|
6
|
+
* CRC methods: exclusive-oring 32 bits of data at a time, and pre-computing
|
7
|
+
* tables for updating the shift register in one step with three exclusive-ors
|
8
|
+
* instead of four steps with four exclusive-ors. This results in about a
|
9
|
+
* factor of two increase in speed on a Power PC G4 (PPC7455) using gcc -O3.
|
10
|
+
*/
|
11
|
+
|
12
|
+
/* @(#) $Id$ */
|
13
|
+
|
14
|
+
/*
|
15
|
+
Note on the use of DYNAMIC_CRC_TABLE: there is no mutex or semaphore
|
16
|
+
protection on the static variables used to control the first-use generation
|
17
|
+
of the crc tables. Therefore, if you #define DYNAMIC_CRC_TABLE, you should
|
18
|
+
first call get_crc_table() to initialize the tables before allowing more than
|
19
|
+
one thread to use crc32().
|
20
|
+
*/
|
21
|
+
|
22
|
+
#ifdef MAKECRCH
|
23
|
+
# include <stdio.h>
|
24
|
+
# ifndef DYNAMIC_CRC_TABLE
|
25
|
+
# define DYNAMIC_CRC_TABLE
|
26
|
+
# endif /* !DYNAMIC_CRC_TABLE */
|
27
|
+
#endif /* MAKECRCH */
|
28
|
+
|
29
|
+
#include "zutil.h" /* for STDC and FAR definitions */
|
30
|
+
|
31
|
+
#define local static
|
32
|
+
|
33
|
+
/* Find a four-byte integer type for crc32_little() and crc32_big(). */
|
34
|
+
#ifndef NOBYFOUR
|
35
|
+
# ifdef STDC /* need ANSI C limits.h to determine sizes */
|
36
|
+
# include <limits.h>
|
37
|
+
# define BYFOUR
|
38
|
+
# if (UINT_MAX == 0xffffffffUL)
|
39
|
+
typedef unsigned int u4;
|
40
|
+
# else
|
41
|
+
# if (ULONG_MAX == 0xffffffffUL)
|
42
|
+
typedef unsigned long u4;
|
43
|
+
# else
|
44
|
+
# if (USHRT_MAX == 0xffffffffUL)
|
45
|
+
typedef unsigned short u4;
|
46
|
+
# else
|
47
|
+
# undef BYFOUR /* can't find a four-byte integer type! */
|
48
|
+
# endif
|
49
|
+
# endif
|
50
|
+
# endif
|
51
|
+
# endif /* STDC */
|
52
|
+
#endif /* !NOBYFOUR */
|
53
|
+
|
54
|
+
/* Definitions for doing the crc four data bytes at a time. */
|
55
|
+
#ifdef BYFOUR
|
56
|
+
# define REV(w) ((((w)>>24)&0xff)+(((w)>>8)&0xff00)+ \
|
57
|
+
(((w)&0xff00)<<8)+(((w)&0xff)<<24))
|
58
|
+
local unsigned long crc32_little OF((unsigned long,
|
59
|
+
const unsigned char FAR *, unsigned));
|
60
|
+
local unsigned long crc32_big OF((unsigned long,
|
61
|
+
const unsigned char FAR *, unsigned));
|
62
|
+
# define TBLS 8
|
63
|
+
#else
|
64
|
+
# define TBLS 1
|
65
|
+
#endif /* BYFOUR */
|
66
|
+
|
67
|
+
/* Local functions for crc concatenation */
|
68
|
+
local unsigned long gf2_matrix_times OF((unsigned long *mat,
|
69
|
+
unsigned long vec));
|
70
|
+
local void gf2_matrix_square OF((unsigned long *square, unsigned long *mat));
|
71
|
+
local uLong crc32_combine_(uLong crc1, uLong crc2, z_off64_t len2);
|
72
|
+
|
73
|
+
|
74
|
+
#ifdef DYNAMIC_CRC_TABLE
|
75
|
+
|
76
|
+
local volatile int crc_table_empty = 1;
|
77
|
+
local unsigned long FAR crc_table[TBLS][256];
|
78
|
+
local void make_crc_table OF((void));
|
79
|
+
#ifdef MAKECRCH
|
80
|
+
local void write_table OF((FILE *, const unsigned long FAR *));
|
81
|
+
#endif /* MAKECRCH */
|
82
|
+
/*
|
83
|
+
Generate tables for a byte-wise 32-bit CRC calculation on the polynomial:
|
84
|
+
x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1.
|
85
|
+
|
86
|
+
Polynomials over GF(2) are represented in binary, one bit per coefficient,
|
87
|
+
with the lowest powers in the most significant bit. Then adding polynomials
|
88
|
+
is just exclusive-or, and multiplying a polynomial by x is a right shift by
|
89
|
+
one. If we call the above polynomial p, and represent a byte as the
|
90
|
+
polynomial q, also with the lowest power in the most significant bit (so the
|
91
|
+
byte 0xb1 is the polynomial x^7+x^3+x+1), then the CRC is (q*x^32) mod p,
|
92
|
+
where a mod b means the remainder after dividing a by b.
|
93
|
+
|
94
|
+
This calculation is done using the shift-register method of multiplying and
|
95
|
+
taking the remainder. The register is initialized to zero, and for each
|
96
|
+
incoming bit, x^32 is added mod p to the register if the bit is a one (where
|
97
|
+
x^32 mod p is p+x^32 = x^26+...+1), and the register is multiplied mod p by
|
98
|
+
x (which is shifting right by one and adding x^32 mod p if the bit shifted
|
99
|
+
out is a one). We start with the highest power (least significant bit) of
|
100
|
+
q and repeat for all eight bits of q.
|
101
|
+
|
102
|
+
The first table is simply the CRC of all possible eight bit values. This is
|
103
|
+
all the information needed to generate CRCs on data a byte at a time for all
|
104
|
+
combinations of CRC register values and incoming bytes. The remaining tables
|
105
|
+
allow for word-at-a-time CRC calculation for both big-endian and little-
|
106
|
+
endian machines, where a word is four bytes.
|
107
|
+
*/
|
108
|
+
local void make_crc_table()
|
109
|
+
{
|
110
|
+
unsigned long c;
|
111
|
+
int n, k;
|
112
|
+
unsigned long poly; /* polynomial exclusive-or pattern */
|
113
|
+
/* terms of polynomial defining this crc (except x^32): */
|
114
|
+
static volatile int first = 1; /* flag to limit concurrent making */
|
115
|
+
static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
|
116
|
+
|
117
|
+
/* See if another task is already doing this (not thread-safe, but better
|
118
|
+
than nothing -- significantly reduces duration of vulnerability in
|
119
|
+
case the advice about DYNAMIC_CRC_TABLE is ignored) */
|
120
|
+
if (first) {
|
121
|
+
first = 0;
|
122
|
+
|
123
|
+
/* make exclusive-or pattern from polynomial (0xedb88320UL) */
|
124
|
+
poly = 0UL;
|
125
|
+
for (n = 0; n < sizeof(p)/sizeof(unsigned char); n++)
|
126
|
+
poly |= 1UL << (31 - p[n]);
|
127
|
+
|
128
|
+
/* generate a crc for every 8-bit value */
|
129
|
+
for (n = 0; n < 256; n++) {
|
130
|
+
c = (unsigned long)n;
|
131
|
+
for (k = 0; k < 8; k++)
|
132
|
+
c = c & 1 ? poly ^ (c >> 1) : c >> 1;
|
133
|
+
crc_table[0][n] = c;
|
134
|
+
}
|
135
|
+
|
136
|
+
#ifdef BYFOUR
|
137
|
+
/* generate crc for each value followed by one, two, and three zeros,
|
138
|
+
and then the byte reversal of those as well as the first table */
|
139
|
+
for (n = 0; n < 256; n++) {
|
140
|
+
c = crc_table[0][n];
|
141
|
+
crc_table[4][n] = REV(c);
|
142
|
+
for (k = 1; k < 4; k++) {
|
143
|
+
c = crc_table[0][c & 0xff] ^ (c >> 8);
|
144
|
+
crc_table[k][n] = c;
|
145
|
+
crc_table[k + 4][n] = REV(c);
|
146
|
+
}
|
147
|
+
}
|
148
|
+
#endif /* BYFOUR */
|
149
|
+
|
150
|
+
crc_table_empty = 0;
|
151
|
+
}
|
152
|
+
else { /* not first */
|
153
|
+
/* wait for the other guy to finish (not efficient, but rare) */
|
154
|
+
while (crc_table_empty)
|
155
|
+
;
|
156
|
+
}
|
157
|
+
|
158
|
+
#ifdef MAKECRCH
|
159
|
+
/* write out CRC tables to crc32.h */
|
160
|
+
{
|
161
|
+
FILE *out;
|
162
|
+
|
163
|
+
out = fopen("crc32.h", "w");
|
164
|
+
if (out == NULL) return;
|
165
|
+
fprintf(out, "/* crc32.h -- tables for rapid CRC calculation\n");
|
166
|
+
fprintf(out, " * Generated automatically by crc32.c\n */\n\n");
|
167
|
+
fprintf(out, "local const unsigned long FAR ");
|
168
|
+
fprintf(out, "crc_table[TBLS][256] =\n{\n {\n");
|
169
|
+
write_table(out, crc_table[0]);
|
170
|
+
# ifdef BYFOUR
|
171
|
+
fprintf(out, "#ifdef BYFOUR\n");
|
172
|
+
for (k = 1; k < 8; k++) {
|
173
|
+
fprintf(out, " },\n {\n");
|
174
|
+
write_table(out, crc_table[k]);
|
175
|
+
}
|
176
|
+
fprintf(out, "#endif\n");
|
177
|
+
# endif /* BYFOUR */
|
178
|
+
fprintf(out, " }\n};\n");
|
179
|
+
fclose(out);
|
180
|
+
}
|
181
|
+
#endif /* MAKECRCH */
|
182
|
+
}
|
183
|
+
|
184
|
+
#ifdef MAKECRCH
|
185
|
+
local void write_table(out, table)
|
186
|
+
FILE *out;
|
187
|
+
const unsigned long FAR *table;
|
188
|
+
{
|
189
|
+
int n;
|
190
|
+
|
191
|
+
for (n = 0; n < 256; n++)
|
192
|
+
fprintf(out, "%s0x%08lxUL%s", n % 5 ? "" : " ", table[n],
|
193
|
+
n == 255 ? "\n" : (n % 5 == 4 ? ",\n" : ", "));
|
194
|
+
}
|
195
|
+
#endif /* MAKECRCH */
|
196
|
+
|
197
|
+
#else /* !DYNAMIC_CRC_TABLE */
|
198
|
+
/* ========================================================================
|
199
|
+
* Tables of CRC-32s of all single-byte values, made by make_crc_table().
|
200
|
+
*/
|
201
|
+
#include "crc32.h"
|
202
|
+
#endif /* DYNAMIC_CRC_TABLE */
|
203
|
+
|
204
|
+
/* =========================================================================
|
205
|
+
* This function can be used by asm versions of crc32()
|
206
|
+
*/
|
207
|
+
const unsigned long FAR * ZEXPORT get_crc_table()
|
208
|
+
{
|
209
|
+
#ifdef DYNAMIC_CRC_TABLE
|
210
|
+
if (crc_table_empty)
|
211
|
+
make_crc_table();
|
212
|
+
#endif /* DYNAMIC_CRC_TABLE */
|
213
|
+
return (const unsigned long FAR *)crc_table;
|
214
|
+
}
|
215
|
+
|
216
|
+
/* ========================================================================= */
|
217
|
+
#define DO1 crc = crc_table[0][((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8)
|
218
|
+
#define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1
|
219
|
+
|
220
|
+
/* ========================================================================= */
|
221
|
+
unsigned long ZEXPORT crc32(crc, buf, len)
|
222
|
+
unsigned long crc;
|
223
|
+
const unsigned char FAR *buf;
|
224
|
+
uInt len;
|
225
|
+
{
|
226
|
+
if (buf == Z_NULL) return 0UL;
|
227
|
+
|
228
|
+
#ifdef DYNAMIC_CRC_TABLE
|
229
|
+
if (crc_table_empty)
|
230
|
+
make_crc_table();
|
231
|
+
#endif /* DYNAMIC_CRC_TABLE */
|
232
|
+
|
233
|
+
#ifdef BYFOUR
|
234
|
+
if (sizeof(void *) == sizeof(ptrdiff_t)) {
|
235
|
+
u4 endian;
|
236
|
+
|
237
|
+
endian = 1;
|
238
|
+
if (*((unsigned char *)(&endian)))
|
239
|
+
return crc32_little(crc, buf, len);
|
240
|
+
else
|
241
|
+
return crc32_big(crc, buf, len);
|
242
|
+
}
|
243
|
+
#endif /* BYFOUR */
|
244
|
+
crc = crc ^ 0xffffffffUL;
|
245
|
+
while (len >= 8) {
|
246
|
+
DO8;
|
247
|
+
len -= 8;
|
248
|
+
}
|
249
|
+
if (len) do {
|
250
|
+
DO1;
|
251
|
+
} while (--len);
|
252
|
+
return crc ^ 0xffffffffUL;
|
253
|
+
}
|
254
|
+
|
255
|
+
#ifdef BYFOUR
|
256
|
+
|
257
|
+
/* ========================================================================= */
|
258
|
+
#define DOLIT4 c ^= *buf4++; \
|
259
|
+
c = crc_table[3][c & 0xff] ^ crc_table[2][(c >> 8) & 0xff] ^ \
|
260
|
+
crc_table[1][(c >> 16) & 0xff] ^ crc_table[0][c >> 24]
|
261
|
+
#define DOLIT32 DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4
|
262
|
+
|
263
|
+
/* ========================================================================= */
|
264
|
+
local unsigned long crc32_little(crc, buf, len)
|
265
|
+
unsigned long crc;
|
266
|
+
const unsigned char FAR *buf;
|
267
|
+
unsigned len;
|
268
|
+
{
|
269
|
+
register u4 c;
|
270
|
+
register const u4 FAR *buf4;
|
271
|
+
|
272
|
+
c = (u4)crc;
|
273
|
+
c = ~c;
|
274
|
+
while (len && ((ptrdiff_t)buf & 3)) {
|
275
|
+
c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
|
276
|
+
len--;
|
277
|
+
}
|
278
|
+
|
279
|
+
buf4 = (const u4 FAR *)(const void FAR *)buf;
|
280
|
+
while (len >= 32) {
|
281
|
+
DOLIT32;
|
282
|
+
len -= 32;
|
283
|
+
}
|
284
|
+
while (len >= 4) {
|
285
|
+
DOLIT4;
|
286
|
+
len -= 4;
|
287
|
+
}
|
288
|
+
buf = (const unsigned char FAR *)buf4;
|
289
|
+
|
290
|
+
if (len) do {
|
291
|
+
c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
|
292
|
+
} while (--len);
|
293
|
+
c = ~c;
|
294
|
+
return (unsigned long)c;
|
295
|
+
}
|
296
|
+
|
297
|
+
/* ========================================================================= */
|
298
|
+
#define DOBIG4 c ^= *++buf4; \
|
299
|
+
c = crc_table[4][c & 0xff] ^ crc_table[5][(c >> 8) & 0xff] ^ \
|
300
|
+
crc_table[6][(c >> 16) & 0xff] ^ crc_table[7][c >> 24]
|
301
|
+
#define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4
|
302
|
+
|
303
|
+
/* ========================================================================= */
|
304
|
+
local unsigned long crc32_big(crc, buf, len)
|
305
|
+
unsigned long crc;
|
306
|
+
const unsigned char FAR *buf;
|
307
|
+
unsigned len;
|
308
|
+
{
|
309
|
+
register u4 c;
|
310
|
+
register const u4 FAR *buf4;
|
311
|
+
|
312
|
+
c = REV((u4)crc);
|
313
|
+
c = ~c;
|
314
|
+
while (len && ((ptrdiff_t)buf & 3)) {
|
315
|
+
c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
|
316
|
+
len--;
|
317
|
+
}
|
318
|
+
|
319
|
+
buf4 = (const u4 FAR *)(const void FAR *)buf;
|
320
|
+
buf4--;
|
321
|
+
while (len >= 32) {
|
322
|
+
DOBIG32;
|
323
|
+
len -= 32;
|
324
|
+
}
|
325
|
+
while (len >= 4) {
|
326
|
+
DOBIG4;
|
327
|
+
len -= 4;
|
328
|
+
}
|
329
|
+
buf4++;
|
330
|
+
buf = (const unsigned char FAR *)buf4;
|
331
|
+
|
332
|
+
if (len) do {
|
333
|
+
c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
|
334
|
+
} while (--len);
|
335
|
+
c = ~c;
|
336
|
+
return (unsigned long)(REV(c));
|
337
|
+
}
|
338
|
+
|
339
|
+
#endif /* BYFOUR */
|
340
|
+
|
341
|
+
#define GF2_DIM 32 /* dimension of GF(2) vectors (length of CRC) */
|
342
|
+
|
343
|
+
/* ========================================================================= */
|
344
|
+
local unsigned long gf2_matrix_times(mat, vec)
|
345
|
+
unsigned long *mat;
|
346
|
+
unsigned long vec;
|
347
|
+
{
|
348
|
+
unsigned long sum;
|
349
|
+
|
350
|
+
sum = 0;
|
351
|
+
while (vec) {
|
352
|
+
if (vec & 1)
|
353
|
+
sum ^= *mat;
|
354
|
+
vec >>= 1;
|
355
|
+
mat++;
|
356
|
+
}
|
357
|
+
return sum;
|
358
|
+
}
|
359
|
+
|
360
|
+
/* ========================================================================= */
|
361
|
+
local void gf2_matrix_square(square, mat)
|
362
|
+
unsigned long *square;
|
363
|
+
unsigned long *mat;
|
364
|
+
{
|
365
|
+
int n;
|
366
|
+
|
367
|
+
for (n = 0; n < GF2_DIM; n++)
|
368
|
+
square[n] = gf2_matrix_times(mat, mat[n]);
|
369
|
+
}
|
370
|
+
|
371
|
+
/* ========================================================================= */
|
372
|
+
local uLong crc32_combine_(crc1, crc2, len2)
|
373
|
+
uLong crc1;
|
374
|
+
uLong crc2;
|
375
|
+
z_off64_t len2;
|
376
|
+
{
|
377
|
+
int n;
|
378
|
+
unsigned long row;
|
379
|
+
unsigned long even[GF2_DIM]; /* even-power-of-two zeros operator */
|
380
|
+
unsigned long odd[GF2_DIM]; /* odd-power-of-two zeros operator */
|
381
|
+
|
382
|
+
/* degenerate case (also disallow negative lengths) */
|
383
|
+
if (len2 <= 0)
|
384
|
+
return crc1;
|
385
|
+
|
386
|
+
/* put operator for one zero bit in odd */
|
387
|
+
odd[0] = 0xedb88320UL; /* CRC-32 polynomial */
|
388
|
+
row = 1;
|
389
|
+
for (n = 1; n < GF2_DIM; n++) {
|
390
|
+
odd[n] = row;
|
391
|
+
row <<= 1;
|
392
|
+
}
|
393
|
+
|
394
|
+
/* put operator for two zero bits in even */
|
395
|
+
gf2_matrix_square(even, odd);
|
396
|
+
|
397
|
+
/* put operator for four zero bits in odd */
|
398
|
+
gf2_matrix_square(odd, even);
|
399
|
+
|
400
|
+
/* apply len2 zeros to crc1 (first square will put the operator for one
|
401
|
+
zero byte, eight zero bits, in even) */
|
402
|
+
do {
|
403
|
+
/* apply zeros operator for this bit of len2 */
|
404
|
+
gf2_matrix_square(even, odd);
|
405
|
+
if (len2 & 1)
|
406
|
+
crc1 = gf2_matrix_times(even, crc1);
|
407
|
+
len2 >>= 1;
|
408
|
+
|
409
|
+
/* if no more bits set, then done */
|
410
|
+
if (len2 == 0)
|
411
|
+
break;
|
412
|
+
|
413
|
+
/* another iteration of the loop with odd and even swapped */
|
414
|
+
gf2_matrix_square(odd, even);
|
415
|
+
if (len2 & 1)
|
416
|
+
crc1 = gf2_matrix_times(odd, crc1);
|
417
|
+
len2 >>= 1;
|
418
|
+
|
419
|
+
/* if no more bits set, then done */
|
420
|
+
} while (len2 != 0);
|
421
|
+
|
422
|
+
/* return combined crc */
|
423
|
+
crc1 ^= crc2;
|
424
|
+
return crc1;
|
425
|
+
}
|
426
|
+
|
427
|
+
/* ========================================================================= */
|
428
|
+
uLong ZEXPORT crc32_combine(crc1, crc2, len2)
|
429
|
+
uLong crc1;
|
430
|
+
uLong crc2;
|
431
|
+
z_off_t len2;
|
432
|
+
{
|
433
|
+
return crc32_combine_(crc1, crc2, len2);
|
434
|
+
}
|
435
|
+
|
436
|
+
uLong ZEXPORT crc32_combine64(crc1, crc2, len2)
|
437
|
+
uLong crc1;
|
438
|
+
uLong crc2;
|
439
|
+
z_off64_t len2;
|
440
|
+
{
|
441
|
+
return crc32_combine_(crc1, crc2, len2);
|
442
|
+
}
|