Compare commits
1126 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6f9a7bb9fc | |||
| 466faceb39 | |||
| 05f6a4a9de | |||
| f6c82949af | |||
| d3433d8493 | |||
| 54a66623d6 | |||
| 1575f26d57 | |||
| cc9068e8cb | |||
| 0d56a5a5a8 | |||
| 5afd770e47 | |||
| 390e3b69b2 | |||
| c9d1922544 | |||
| 30d8cc0f1e | |||
| 13ac38a28e | |||
| fbd2e1aac2 | |||
| 31d2bf4219 | |||
| 5516d498a5 | |||
| fb2f6fc894 | |||
| 0ca45d51f0 | |||
| 5dd3744208 | |||
| 1e567d4338 | |||
| 5085ff1b95 | |||
| bc23e7d971 | |||
| 57589b382e | |||
| aabdd94b1f | |||
| d9c302e7f6 | |||
| 58a6b34961 | |||
| 7809447e79 | |||
| 064bb171ef | |||
| c542453715 | |||
| 2267325740 | |||
| cabac68195 | |||
| 535c7c9d2b | |||
| 3e62019509 | |||
| 5d6de5a235 | |||
| 8c23e763b1 | |||
| fff356750d | |||
| 5fd2674dcf | |||
| 2881f67a42 | |||
| 92346f618f | |||
| 4f9206b011 | |||
| de447bedce | |||
| 95e22bd161 | |||
| 94e12a649d | |||
| f8d8a9de40 | |||
| d796f9db56 | |||
| b1c9aff987 | |||
| d48d28409a | |||
| d5436a5196 | |||
| ff1d257dee | |||
| 083b317fb9 | |||
| c9d1972658 | |||
| 09d8dd20f3 | |||
| 138282679a | |||
| 2c95042226 | |||
| d2f0d44fbc | |||
| dd1bf9c9e2 | |||
| c529100581 | |||
| 750d8284c2 | |||
| 2ca7da4773 | |||
| 107b582554 | |||
| cf3bb97c5e | |||
| 6d7d75fac8 | |||
| 8d3bfe4891 | |||
| bd98c0c0ba | |||
| d82128dab3 | |||
| 09f5614990 | |||
| d314c922da | |||
| 91ff86f775 | |||
| dd457346eb | |||
| a0cb100bc9 | |||
| 037b5d20cb | |||
| a3470ec0d9 | |||
| d9873fe573 | |||
| 922dcdfa25 | |||
| 12f82d0a2b | |||
| 70e90e6f14 | |||
| a9d64cfe5e | |||
| c5879c30fb | |||
| 5b7592a612 | |||
| aae2368e9b | |||
| 6df9bf6d6b | |||
| 0c8ee4a16f | |||
| 67abff5f12 | |||
| 027ddc3bfc | |||
| afaf73f051 | |||
| de0b4bc1c5 | |||
| f6f33cd19e | |||
| a9c38fe963 | |||
| 89785df263 | |||
| 0cf960036e | |||
| 4dda826dd0 | |||
| 95744be465 | |||
| 4234b0220a | |||
| 6fe721ff5b | |||
| e409549586 | |||
| 4f595e2154 | |||
| 003953b12e | |||
| 5d0a70d01f | |||
| 4cc77b3d02 | |||
| 7525a01637 | |||
| fa5b44ad23 | |||
| ed608ae721 | |||
| 32a99d1c40 | |||
| afe1ca5621 | |||
| 8ee3926508 | |||
| edf3dc59e7 | |||
| 0b7220f465 | |||
| f4e3fa0705 | |||
| a99f41d753 | |||
| 2360996938 | |||
| 0ea58f71d7 | |||
| 755072a952 | |||
| 31aa1b440d | |||
| c8242676b8 | |||
| 75769abe24 | |||
| cfb0b46f35 | |||
| 08280ec0a5 | |||
| d02c9ed15c | |||
| 14b94031c8 | |||
| f03109c2c4 | |||
| ea98eb0cf5 | |||
| a4e9606a76 | |||
| 53e4b90900 | |||
| 969b9c965c | |||
| edbbf52704 | |||
| 3a13704fb4 | |||
| 4902b642e4 | |||
| 3bc7ce2b85 | |||
| 7b66f586e6 | |||
| 20e168dcc6 | |||
| 9cf10369bc | |||
| 26dee19bb0 | |||
| ddeeea67f3 | |||
| dfb8d5a335 | |||
| fb73ff6f0e | |||
| 1b9b95ea3c | |||
| d9ee74a218 | |||
| 0d6d745ce4 | |||
| fa4fb80d71 | |||
| 1e06f2971e | |||
| 529d25b1aa | |||
| 7056d6c975 | |||
| 7f7d92b94b | |||
| 58cada5b81 | |||
| 555b054ac9 | |||
| 59a8cda049 | |||
| 1fd50d100f | |||
| c5ebc9da42 | |||
| 16cd0fe0d5 | |||
| cc1b1b632c | |||
| a65bf9ca0a | |||
| a68906a2b3 | |||
| fb1a44e009 | |||
| 641b7fa69e | |||
| 1d11815629 | |||
| 8c59f2d59d | |||
| 12c4dd23c9 | |||
| 59bb81f169 | |||
| 8e72f73e99 | |||
| 9cd276646b | |||
| b9748c790f | |||
| b649bc8191 | |||
| 2d130223a5 | |||
| ba78f51835 | |||
| cf24682a67 | |||
| c5d7431fdf | |||
| 4242097cc1 | |||
| a12d72d01c | |||
| f352e1861d | |||
| fede624348 | |||
| 689c29b0ac | |||
| 1e793fcae3 | |||
| a89f9f2211 | |||
| b2b4232297 | |||
| 72eedf2c4b | |||
| 4be8953465 | |||
| ac7f96a9fa | |||
| 4f512d83bb | |||
| a364deb3f0 | |||
| 62ce457088 | |||
| db08a2850f | |||
| e3f4fcd52b | |||
| 058fa062e7 | |||
| 12be4f3c81 | |||
| 2d4106186f | |||
| 8beb6283ee | |||
| b7a74abb08 | |||
| 9718a4da97 | |||
| ad58e98678 | |||
| d461f0cf40 | |||
| 4814e0a03c | |||
| f59ce09eba | |||
| 68c57d774d | |||
| 5230061e2e | |||
| 6e5cf114d8 | |||
| 7d734e2b69 | |||
| f2779929ee | |||
| 8223912bf5 | |||
| c9ad1e5e6e | |||
| bcb7d62ff8 | |||
| 43c8d77167 | |||
| af35c8f9db | |||
| f1997f94a5 | |||
| b19c5e344d | |||
| 64af972345 | |||
| 27589d2f1b | |||
| 7f2c0b0426 | |||
| 1a97f95668 | |||
| 1416c1c52a | |||
| 25c50cfed1 | |||
| 8fbbde0da7 | |||
| 66203fe37a | |||
| 62ba998fcc | |||
| 0531ade8c5 | |||
| 1537dbf0c0 | |||
| 8eb12cd2a7 | |||
| 28ae540d47 | |||
| 53525aa353 | |||
| bdac066b2e | |||
| ed85fbe832 | |||
| 3caeaa4cf1 | |||
| 15b1f8b073 | |||
| 68896f7dd3 | |||
| bb819cb3e8 | |||
| 9ddbc67e62 | |||
| c3e39b746d | |||
| e6959cda85 | |||
| d2a3098213 | |||
| 9fa0baba83 | |||
| 086e291b39 | |||
| 78e748a744 | |||
| 67e63491ba | |||
| e0b07534c1 | |||
| 11d64e1adb | |||
| 4924028cb9 | |||
| 1761657031 | |||
| dc3be873ed | |||
| eda01dc270 | |||
| 44ca55b5f7 | |||
| 85b5928b87 | |||
| 245b23c198 | |||
| f8f30f53d3 | |||
| 7bf8bca83c | |||
| 8a4b75ff3b | |||
| 02765e5694 | |||
| ff7d85b395 | |||
| 3f731b7074 | |||
| 12455a518f | |||
| 3db06fc04f | |||
| 7068366f79 | |||
| bdc8e0e405 | |||
| e6fa13aeb0 | |||
| 2474f78eb6 | |||
| d2e10a6b55 | |||
| 97e5555949 | |||
| c2d3d6453e | |||
| 383eac9ac3 | |||
| 3be4c3eb9b | |||
| 26026e958d | |||
| 2c1c2b9cb2 | |||
| 3587a5ab96 | |||
| a3eb7bd11c | |||
| 7e8f72d08c | |||
| 0c6d6e2cb8 | |||
| ad4751f79f | |||
| bc5255c3b9 | |||
| 9e7b476cbb | |||
| e4152a7ed2 | |||
| 64bf9d69bf | |||
| 873bcc023c | |||
| 1a564ff521 | |||
| fa5a4f3fd4 | |||
| d5cd7adb9a | |||
| d984912529 | |||
| 909b1d4b53 | |||
| a4c143a2e4 | |||
| 0d8af7bb01 | |||
| a41652d55b | |||
| 233e874fd0 | |||
| 8df25dce8e | |||
| 18589ec280 | |||
| 9aa8d70de5 | |||
| 7f04b1acdb | |||
| ca11870a14 | |||
| 9cef41d4e9 | |||
| c36f9e2da8 | |||
| 4359e3afda | |||
| 5339981d53 | |||
| 1389181053 | |||
| 8ffda701dc | |||
| 28f1202335 | |||
| df91f86661 | |||
| 2551a82b2a | |||
| 0e4e48cca9 | |||
| 8d538a2e12 | |||
| 6994f166f0 | |||
| e8eaa85709 | |||
| 5160109b25 | |||
| aa1ecf5ffa | |||
| 1933bfec99 | |||
| 94a4b0c4ab | |||
| 665cb8b104 | |||
| 9ca30443c3 | |||
| 2e63fb0c40 | |||
| 850f3e21a2 | |||
| a7c4897295 | |||
| 9551d5d6ed | |||
| afe5fe75f1 | |||
| 3c9a163fcb | |||
| 3bd2db76d5 | |||
| 7ab22b602c | |||
| 353e9361a5 | |||
| 9eb63989f1 | |||
| 4de24ab14d | |||
| 58794f0435 | |||
| 3f130017b9 | |||
| 8e13206395 | |||
| 51d35bf016 | |||
| 62071b16d2 | |||
| 7b10495cc0 | |||
| ceea320bbd | |||
| d2060a7318 | |||
| 223dc6cc7d | |||
| 4c6a0a627a | |||
| c06b59dd20 | |||
| 78d0c18edc | |||
| 9fecb90e34 | |||
| a2a515e5b5 | |||
| f83e0afd5a | |||
| c18f9cdf82 | |||
| 4cfcf03287 | |||
| 3c83075609 | |||
| 36eea5cb96 | |||
| dfb53df307 | |||
| 9b37150de8 | |||
| a28ed76fa9 | |||
| cab16078f7 | |||
| 935c48daa0 | |||
| 388887a352 | |||
| adbadf33f5 | |||
| efbdad1dee | |||
| 495d804420 | |||
| 88a82a8d4c | |||
| 5dbaf33cbd | |||
| 768d0c4f44 | |||
| 05e60d18f4 | |||
| 756ad91368 | |||
| 0b3c596e1e | |||
| c36364b1ba | |||
| 92970291a6 | |||
| cbbf708358 | |||
| 581a095d50 | |||
| ade2570c4e | |||
| 5a8afb13ca | |||
| 46a761a40c | |||
| 85a22b451c | |||
| e3f8139c18 | |||
| 57510d8dd3 | |||
| a7b4c50703 | |||
| 108be5670c | |||
| c437e73442 | |||
| d97d0b1a5d | |||
| caefe8e180 | |||
| b78d3cea15 | |||
| 781853fd3e | |||
| c949931238 | |||
| dad382dc0e | |||
| 4e9893f926 | |||
| edd95fc5bd | |||
| 184c1cb677 | |||
| f62961f260 | |||
| 6d30346834 | |||
| 47dcde3ed7 | |||
| 0395785831 | |||
| 791c6c87df | |||
| ffcca0df78 | |||
| 2009605d69 | |||
| de3d0a178a | |||
| a43e48068c | |||
| 2cbf83a625 | |||
| 80e55f614a | |||
| 7a61ee5d4b | |||
| e2462cdafd | |||
| c2b426f713 | |||
| 66ed8686c7 | |||
| bdc0aabbbd | |||
| d2e7b93be8 | |||
| 78220a62b0 | |||
| ea57e4bf50 | |||
| b0818689e6 | |||
| 7765382bd9 | |||
| 40bad1f583 | |||
| 6c496178a6 | |||
| db2a08770b | |||
| 4d206b3ecd | |||
| 9db841db7c | |||
| 4b3f8015ed | |||
| bb25941e51 | |||
| 818b389260 | |||
| b6dce50e00 | |||
| 82d8bd50b0 | |||
| c2c0275abe | |||
| 58fe50409d | |||
| 536093c2cf | |||
| 9c2ebd0872 | |||
| be6b46310e | |||
| f8b036a2b0 | |||
| 87d77fb85f | |||
| eb38f83807 | |||
| f1ceac6ee7 | |||
| 532e2aa218 | |||
| ab778fc810 | |||
| f41d36a839 | |||
| aa5715b8e2 | |||
| b84cc027a0 | |||
| 9f5cbeab4a | |||
| 6a2d201af7 | |||
| 5f7e94c347 | |||
| a7b6f5cad7 | |||
| 92a5ac8935 | |||
| 0a98949741 | |||
| 141071fc82 | |||
| 1d1d11fd32 | |||
| cc278fc708 | |||
| 7c6c2a1b55 | |||
| 19eb68f08e | |||
| f390570e38 | |||
| f9c8e4b215 | |||
| afacd6c03a | |||
| 65461e2391 | |||
| a208e19493 | |||
| c1a75adc70 | |||
| c6c3f1d525 | |||
| 6e834c151a | |||
| ce82ee05fa | |||
| b6fd8742c3 | |||
| 12f4b8ecdd | |||
| 69aff08a98 | |||
| adcf17d984 | |||
| bbcb4ff286 | |||
| f4db8304ec | |||
| f9a3a0afca | |||
| e31125b98e | |||
| 0e71d0bbbd | |||
| 9f3f132608 | |||
| 41436335c8 | |||
| 51c38f94f0 | |||
| 99672b9f3d | |||
| 8606c66865 | |||
| 64f1aebeaa | |||
| 164703d2eb | |||
| caac56c8b9 | |||
| e3e1ec8002 | |||
| 05cb367f25 | |||
| 492571cd70 | |||
| 3481bf6327 | |||
| c5ed7ae167 | |||
| 9c9f9e4459 | |||
| a7e4500b3e | |||
| 260430f25e | |||
| 48fbcbbf91 | |||
| d202d1c7f9 | |||
| 1d49b32477 | |||
| 6cc445ef65 | |||
| 35becafe5c | |||
| bd2527a4bc | |||
| 4eac3bfeae | |||
| 31bc53135b | |||
| 07c99512ce | |||
| 87d7b2a3a6 | |||
| 37cd700e94 | |||
| b75bf53737 | |||
| 6b9ea3a4d3 | |||
| d2cb79fa15 | |||
| 8d029d2edf | |||
| 41a288dfbc | |||
| 6a7da81553 | |||
| e413cc4706 | |||
| 41009db26f | |||
| eed9047fa3 | |||
| b80975e20d | |||
| 89b17ce962 | |||
| 53f412b291 | |||
| 66a522b484 | |||
| 301125d31e | |||
| 5676703d92 | |||
| 1a1b6ebeb0 | |||
| 6e91985365 | |||
| ec065085ae | |||
| 514dee52c8 | |||
| c6440779ea | |||
| 025c70161e | |||
| 51bc7d3ed8 | |||
| 42befb9f32 | |||
| 6a01e81189 | |||
| bdddc6b1ce | |||
| f23180508e | |||
| ad2e1e0167 | |||
| 38a7d855c0 | |||
| 50e3d6ed3d | |||
| f0bb4cc47e | |||
| 20b47e5b55 | |||
| 714cc1679b | |||
| a1c5cb6f71 | |||
| a44193c7a2 | |||
| be9c02cc68 | |||
| 9a4f12c8f7 | |||
| 4fbe2f73d0 | |||
| 4c03736881 | |||
| 379b2c2dc8 | |||
| b9ee0789dd | |||
| f4cd5a25f8 | |||
| 3eb85366dc | |||
| f2e7f7501f | |||
| 10528c1ba0 | |||
| 7eb7f8afa7 | |||
| d60a528aa7 | |||
| e8ecd924c3 | |||
| 46e200072f | |||
| 5226b18821 | |||
| 6f4e27c084 | |||
| 6f5af1823a | |||
| 7c27b09a7c | |||
| 817530822b | |||
| 360596beff | |||
| e7a27faad6 | |||
| 2827dd2577 | |||
| 3ef3d1346c | |||
| c29a4088dd | |||
| 86ed553880 | |||
| a159ec6dd4 | |||
| b91f63ea6f | |||
| 18b2cb59d7 | |||
| 5cbd71200d | |||
| ab67d5cd1f | |||
| caa4b2e025 | |||
| effc9c0131 | |||
| e5573675da | |||
| 08ac80d043 | |||
| 4731bcd0b6 | |||
| c880e009bf | |||
| 53a818051b | |||
| 4ebd232745 | |||
| b1dd52b782 | |||
| e15b1dd08b | |||
| f2e9811864 | |||
| 547e87e77a | |||
| f0ee9134ba | |||
| 2d5da0dcdf | |||
| 2ca4db82b7 | |||
| dc7d66fa04 | |||
| e337166c56 | |||
| 5dd9a9d75d | |||
| 8d06c92b46 | |||
| 1a24fb04df | |||
| 2182c28688 | |||
| c8c67bab95 | |||
| b60b8373f5 | |||
| 5165750466 | |||
| d79aa5c7b5 | |||
| 56feeef2b6 | |||
| b7d4419cf6 | |||
| 88f72e7bf5 | |||
| 049c5f122c | |||
| 731a3fed38 | |||
| dd872bb91a | |||
| 83edb6418e | |||
| 5d3ceceeaf | |||
| 0bf4146012 | |||
| e9ca155e21 | |||
| 91fbe383f7 | |||
| 0afbafecbf | |||
| 78c4d5931c | |||
| 13d6c6f90f | |||
| efe7266c06 | |||
| 40d4708c38 | |||
| 17c4d15eb0 | |||
| 2606ad0a2b | |||
| 2c74ebb659 | |||
| 90f402831c | |||
| 7d1ed655a5 | |||
| 3b198f3ec2 | |||
| 273cb3c3b8 | |||
| bc46853849 | |||
| a2eb78db5c | |||
| 5763d342eb | |||
| 998d307d4d | |||
| 81a43f6436 | |||
| 48982dedc1 | |||
| 28742406c4 | |||
| 51c5c3a062 | |||
| 862001c0a1 | |||
| bd3c185fde | |||
| 1bf2016625 | |||
| 5e74e3e8eb | |||
| 4dead4e776 | |||
| d467556900 | |||
| c88581569e | |||
| ffd3ded986 | |||
| bdce2f37f7 | |||
| 8969344dc9 | |||
| c5e4dfc40f | |||
| 21fdda934c | |||
| 770625fb5a | |||
| 4fa62c7a4c | |||
| 9ae0cfd7dc | |||
| 77d885f4af | |||
| 3e042de906 | |||
| 9f48acf200 | |||
| d606da7437 | |||
| 9588433244 | |||
| 18672532da | |||
| e40fee3f63 | |||
| 49b9faeb6e | |||
| 038a58626f | |||
| db27a56f3f | |||
| 85f8fb182d | |||
| 7326e5c0f9 | |||
| 0b2bb08fe7 | |||
| 74a5a15d0b | |||
| d65f3bb02b | |||
| 0305af7c4c | |||
| 7e9e62c878 | |||
| 315d0b76d2 | |||
| cd765bd629 | |||
| 0019ff4d7c | |||
| 7c67eebf6d | |||
| 8f355c1a26 | |||
| c4d32a65bf | |||
| 8d2646d600 | |||
| 082c0b24f8 | |||
| 1046a3b463 | |||
| fa9a3a8b3b | |||
| b2197daf83 | |||
| aca7e26632 | |||
| fea5d62364 | |||
| 6f63f23120 | |||
| c0c48b8d92 | |||
| beb349ecc4 | |||
| 9330d1a0fe | |||
| 0c94cbafdf | |||
| 9e85f1f234 | |||
| 75068dc41c | |||
| 75c7efa57c | |||
| b280b1d7ab | |||
| a9f09b7af1 | |||
| 8cf81e0675 | |||
| fe68105ad9 | |||
| f8ac4c0f70 | |||
| 11430ec60d | |||
| 16e2af074e | |||
| 50ebe5416d | |||
| 9095b66157 | |||
| e0a4925a79 | |||
| 055cccce33 | |||
| 4b934c709e | |||
| 8903749f6e | |||
| ece900991a | |||
| 0def8adb6e | |||
| 9822f5f51c | |||
| 8ceeab2f80 | |||
| c551a48b84 | |||
| 41027ffdd7 | |||
| a841758975 | |||
| 7e3717c011 | |||
| c9a66fbe66 | |||
| 8cec56efe4 | |||
| 74dddc50e2 | |||
| fb8814eb26 | |||
| 4288800a5f | |||
| a50f3eeb7d | |||
| 091ec9f8f9 | |||
| ee0023f8a6 | |||
| 56375e5502 | |||
| 6b7591f437 | |||
| 021fdb28e4 | |||
| 77f5c8d5e1 | |||
| 65f045808a | |||
| 8592986330 | |||
| 9764e9ead1 | |||
| 336ca03fa9 | |||
| 1bea679797 | |||
| 3a7916b746 | |||
| 4789e6555b | |||
| 6bbc2ad158 | |||
| 29fc11e0e4 | |||
| ef01f576fe | |||
| d3198789ec | |||
| f9944beb07 | |||
| 5b8d32bde2 | |||
| c04dadb276 | |||
| c18d74194d | |||
| bdd8e2ecda | |||
| 4d46d4a0f7 | |||
| b75f07e47f | |||
| 79fee294d7 | |||
| beb73c1ecf | |||
| 068e3a10b7 | |||
| 33651c201b | |||
| cac9c19405 | |||
| 1cc346ed7b | |||
| 5cbcbc8a08 | |||
| 8d2ce084e5 | |||
| e53432eda6 | |||
| 5dac459fa2 | |||
| bae9b63a3b | |||
| fd2711f8bc | |||
| f4232f8055 | |||
| 40372dc80d | |||
| c24d2cd17a | |||
| 84f04a56d1 | |||
| 1308535c47 | |||
| 0b3ba015cd | |||
| 871d1ab7a6 | |||
| a6e8ede67d | |||
| 1c68650be9 | |||
| 3e9c2b2a4d | |||
| ab376065e4 | |||
| ede861c86f | |||
| 13605efc6a | |||
| 21dfb34fb2 | |||
| 8c5c483d0f | |||
| 1efd8c5778 | |||
| e76541f702 | |||
| 731e3ebf0b | |||
| cbc7248dbf | |||
| b240875e76 | |||
| 3146ffa38c | |||
| daaa6f8e82 | |||
| 8fd0f31c76 | |||
| 84778bc934 | |||
| da44eb90dd | |||
| fd62411dc9 | |||
| f7b6889f9d | |||
| 67ae120bbb | |||
| 2bb007b7de | |||
| 3a568c22e7 | |||
| 1db6569329 | |||
| 6a28bcf576 | |||
| a7cd9e56e7 | |||
| 61e0ea88af | |||
| c1988fdb2c | |||
| fdcb6a4089 | |||
| 2230f6bc2e | |||
| c93f5e203a | |||
| f3da59e3c2 | |||
| d322376e17 | |||
| c374cde0e5 | |||
| a3fdc8262a | |||
| 5cf54f0cbf | |||
| cf050ccb7b | |||
| 4fa2725d22 | |||
| 91b65112e6 | |||
| 8af10b32e4 | |||
| 6f9c04d7a9 | |||
| 7c5308c17c | |||
| f9d7ef43fd | |||
| 48ea337dfc | |||
| a5f9e27a85 | |||
| ebb29c3caf | |||
| 79a109441e | |||
| df3d0e5ea8 | |||
| 3f02e21868 | |||
| 7a6020226a | |||
| d466bedcea | |||
| 8c626e1cf0 | |||
| 34f607ba6a | |||
| 0520fb754c | |||
| 4916348824 | |||
| 803a046200 | |||
| c7cfea4ae5 | |||
| 4172a5dcee | |||
| a0c06d4e7f | |||
| 9a79c513ad | |||
| 39231e3991 | |||
| a36694a29f | |||
| 43bebe4632 | |||
| 8c1c0e4dd0 | |||
| 965eb4d545 | |||
| d66fc9d182 | |||
| 47ded454a1 | |||
| d0f3f71289 | |||
| 74820dfb3c | |||
| 3ba3500bf2 | |||
| b7c056bd95 | |||
| bcd9741d83 | |||
| cd0d5ae1b1 | |||
| cdb8f4d277 | |||
| 71e3b71d1e | |||
| 6be0300ff5 | |||
| 52174b8ad1 | |||
| 53b349d849 | |||
| a075baeb0c | |||
| 1367a8985d | |||
| 5ed68aae43 | |||
| 7e3ce74814 | |||
| 5de9c36e0f | |||
| 9299bbc799 | |||
| 9789bb2300 | |||
| 88cce35ea0 | |||
| 5fb4738b59 | |||
| be584a2d26 | |||
| 380496b7f7 | |||
| 878e53c066 | |||
| f5d45bdf68 | |||
| 6e0b5399d1 | |||
| f9b5322111 | |||
| cfaf50b1ba | |||
| 705b9473ff | |||
| ade37ec73e | |||
| 963166f472 | |||
| eb4932d233 | |||
| a2ac50def4 | |||
| d07bd9c5e5 | |||
| e7d4feff54 | |||
| b77b6b371f | |||
| e0c5233f55 | |||
| 1883f5f929 | |||
| 340b9830c2 | |||
| df1af9527e | |||
| 58bc6f307d | |||
| d00d4b7aa4 | |||
| 20770e00a2 | |||
| ee8eaacc04 | |||
| d2178433da | |||
| a7bf91b237 | |||
| 20a69e1003 | |||
| 22ec600191 | |||
| 8c022e409b | |||
| 0200edd35f | |||
| cfdb4ba761 | |||
| 5a1d3d8510 | |||
| d16b0aab69 | |||
| a6c9cd0eb4 | |||
| a498e1a80b | |||
| 081ef521bc | |||
| d088408dfa | |||
| bfc6192f31 | |||
| 8431361f52 | |||
| c137df4a1b | |||
| a80f25da1e | |||
| c08130d05f | |||
| b38e88881b | |||
| 23ebfe050a | |||
| 100935170c | |||
| a4db38c9b7 | |||
| 34353a2bcd | |||
| dcf2fe4f48 | |||
| 884982cf5b | |||
| 522dd3fe11 | |||
| 77d964c85c | |||
| f2d094470e | |||
| 2400949a78 | |||
| 6aca609103 | |||
| 738240a729 | |||
| 9d51b9a167 | |||
| 7b4c3f1c0c | |||
| ea1180629a | |||
| fe9b5d971e | |||
| 763c7dc6d0 | |||
| 96971374f8 | |||
| 51623ea917 | |||
| 53ff4ffa7c | |||
| 3809d9261c | |||
| c71c3d044b | |||
| 00f2b2f012 | |||
| a032fff071 | |||
| 83e2cb44a4 | |||
| e6150b6e89 | |||
| 688254832c | |||
| 0a179f7f76 | |||
| eecf4e10cc | |||
| 58c4878c4f | |||
| 6c6fd1d83b | |||
| f9b28194eb | |||
| 826fa98ecd | |||
| b7c907fcac | |||
| 89703f802f | |||
| 4d2cfad94d | |||
| 68db8a7947 | |||
| a734eb2718 | |||
| c39c52d575 | |||
| 2e02f74c3a | |||
| 0a32e3913b | |||
| f503dfa1da | |||
| d95499c25a | |||
| 3336585570 | |||
| b753ac26c4 | |||
| 5b4fbf4c95 | |||
| ab44cdeea8 | |||
| d4603ba725 | |||
| ac619a3466 | |||
| aa98836587 | |||
| 6d9f0684f2 | |||
| 7eeaf87eeb | |||
| 8fd58f779f | |||
| 6f7cd7ade9 | |||
| a3cb9993a4 | |||
| edb57606dc | |||
| 8eeec8f530 | |||
| 1019d31b14 | |||
| 6a06f39a13 | |||
| 22f89ae621 | |||
| dcb24b7bbc | |||
| 3312e14cd4 | |||
| c601b78a54 | |||
| ce4e503946 | |||
| d2441fa591 | |||
| 777d935e39 | |||
| 5ce788c88c | |||
| c9f247afd7 | |||
| 744d4212b8 | |||
| 3a368c977f | |||
| 0b3e1ca990 | |||
| 0b32d68ceb | |||
| 4ad7ea0cc3 | |||
| 34978f83c2 | |||
| e0bd743d8f | |||
| 6cd2c376bf | |||
| 3ff56d5dec | |||
| edd49ba180 | |||
| c25093577e | |||
| 3e34295926 | |||
| fd6219e480 | |||
| e96cd23a29 | |||
| 046166180d | |||
| dc45f86493 | |||
| ec3210b733 | |||
| f5d43484eb | |||
| 7b978ac042 | |||
| 3abc3d8da1 | |||
| a50aa3fc6f | |||
| 01d4c96ad4 | |||
| f918d211ec | |||
| 621008d477 | |||
| 966c5103c2 | |||
| fab43c996a | |||
| 0e9673de81 | |||
| fdd455fc59 | |||
| b372df81e4 | |||
| 7d80255ab2 | |||
| ffd64175d3 | |||
| b7cd8b830a | |||
| dbd6d13ce3 | |||
| ac79778ae6 | |||
| fa92d98544 | |||
| b5c04bb6dd | |||
| 2c6ec0bc34 | |||
| e7cbdfbe90 | |||
| 21f718c3ba | |||
| 364cad1dd2 | |||
| f251ec976e | |||
| 74f5335e45 | |||
| 700753a805 | |||
| e7fb56830d | |||
| 86fbc6a2b8 | |||
| 487ff48bae | |||
| 0204df7dda | |||
| 12431a5920 | |||
| 04a1cd9b67 | |||
| ad968de0f0 | |||
| c87f090f0b | |||
| 896013619e | |||
| 0528470e1b | |||
| 4add8c33ec | |||
| 74059eaf88 | |||
| 1438051a34 | |||
| 2f96703af2 | |||
| ba9c9022a9 | |||
| 626740a5de | |||
| 9cd9208cb7 | |||
| 56de8154bf | |||
| 3d4670158d | |||
| 386b379ad2 | |||
| fa1b926b82 | |||
| 31a61c7d03 | |||
| 6024672af7 | |||
| 7ad99d704a | |||
| fc295bc491 | |||
| 0b75fed17b | |||
| 6d1a4a8c98 | |||
| 7e7446b8fd | |||
| ba1cb5036d | |||
| f55e86591b | |||
| f27f8a7bc3 | |||
| 4902676db6 | |||
| 045dfc05c5 | |||
| ba0c0dce13 | |||
| 07e73f012f | |||
| 8919fa77c6 | |||
| 917e617df8 | |||
| 409dc8bd6a | |||
| 550d1dfeb2 | |||
| c3677de646 | |||
| d09727fca3 | |||
| 636fd721c7 | |||
| 2255a36d38 | |||
| 0c915621d2 | |||
| c82d9e72ac | |||
| f91a7b041f | |||
| 15ef549386 | |||
| 315df77d06 | |||
| f3b82066f6 | |||
| 5c49a0559f | |||
| 0091668625 | |||
| 59cd03e5d8 | |||
| 31219c0fa3 | |||
| 6fa297b2c4 | |||
| 50eef0ac3a | |||
| 30e7e0b864 | |||
| da517259e9 | |||
| e427efb2ed | |||
| a32719b4cd | |||
| 9e0d0e63ae | |||
| 1d393ac845 | |||
| c436544b52 | |||
| 45a52830dd | |||
| 584d420639 | |||
| 2afbe6fb56 | |||
| 65da7e14f4 | |||
| 3a3e54a07a | |||
| 3be6482fc3 | |||
| 2e7732d72d | |||
| 80263d9aa7 | |||
| aef5305f8d | |||
| 440f849f08 | |||
| a2e87ca11c | |||
| 19991dda62 | |||
| 1466895187 | |||
| 4abafc6b22 | |||
| 5b58057d4b | |||
| 4655a6406b | |||
| 6e54a64ee1 | |||
| 66f7864d35 | |||
| 6d272d3abd | |||
| c59d0861dc | |||
| 4008365f91 | |||
| 3ba8092476 | |||
| 2315f699fe | |||
| d1d7815379 | |||
| 4fb1c4b9f6 | |||
| d3e15c15e8 | |||
| 688f292c9f | |||
| 147691ea9c | |||
| 0b1a2bd4d3 | |||
| 891c47ff72 | |||
| 318977c1e2 | |||
| 5852422880 | |||
| 0ab0395743 | |||
| 661f29ce9d | |||
| 6f391b0d1c | |||
| 5896a05da4 | |||
| bcf34f0cde | |||
| 1e4505e3d4 | |||
| 6f25f4b4a7 | |||
| bb837af928 | |||
| 9c4a57af94 | |||
| 38de12c76b | |||
| e628f4c1c5 | |||
| 9c10504c97 | |||
| 47da2846ad | |||
| 6b2e0b8786 | |||
| 276b9636f9 | |||
| 95747aeef4 | |||
| 8d33e9eb67 | |||
| 3638bbc01f | |||
| 11c15e382e | |||
| 211dba76b8 | |||
| 1241891e7d | |||
| f8ae33478f | |||
| 59e22b540e | |||
| 694208a4e8 | |||
| a13df28aac | |||
| 008fb65d25 | |||
| c492c5aea0 | |||
| 7c7b30fc8a | |||
| 96f2db7f85 | |||
| f9a385fa76 | |||
| e5297cc252 | |||
| 1ef8515ff9 | |||
| 1add77c4a5 | |||
| 627d9b634a | |||
| 99ee1b435c | |||
| 1d7ee817a6 | |||
| 2bc1b621c3 | |||
| d525824a3e | |||
| d60f8c5991 | |||
| 9ec3eba6e0 | |||
| 16864a20d0 | |||
| 91ba2b5e05 | |||
| e3b9dad440 | |||
| 8010629390 | |||
| 547d2cf0d5 | |||
| 142c3e3ad9 | |||
| 378db1c754 | |||
| ce46eac262 | |||
| 43664fcb68 | |||
| edeaefd559 | |||
| 33ab272a10 | |||
| 7dad3afbbd | |||
| d0020da14d | |||
| 1fcc514c95 | |||
| 15a4df15c3 | |||
| 52668cbc9f | |||
| 46956673c4 | |||
| a0fbf45eb5 | |||
| b4246adfad | |||
| c98a8dabde | |||
| 3bdceb6f40 | |||
| cb0359b981 | |||
| 66948ff5ba | |||
| 6049731c6f | |||
| ee4fc88688 | |||
| f8ca1af762 | |||
| 4b51be8e3b | |||
| 11c41c967b | |||
| 89691977b5 | |||
| 0a84716f30 | |||
| 523351dce1 | |||
| 60b8506009 | |||
| 204cc8e60c | |||
| 88e7d319cf | |||
| f8ea433350 | |||
| 61254a1002 | |||
| 96425c91ae |
1
.gitattributes
vendored
Normal file
1
.gitattributes
vendored
Normal file
@ -0,0 +1 @@
|
||||
docker/dockerfiles/create_master_slave.sh text=auto
|
||||
@ -36,6 +36,15 @@ endif()
|
||||
if("${ENABLE_PRIVATEGAUSS}" STREQUAL "ON")
|
||||
MESSAGE(FATAL_ERROR " The option ENABLE_PRIVATEGAUSS is not supported thus should be turned off.")
|
||||
endif()
|
||||
if("${ENABLE_LITE_MODE}" STREQUAL "")
|
||||
set(ENABLE_LITE_MODE "OFF")
|
||||
endif()
|
||||
if("${ENABLE_MOT}" STREQUAL "")
|
||||
set(ENABLE_MOT "OFF")
|
||||
endif()
|
||||
if("${ENABLE_HTAP}" STREQUAL "")
|
||||
set(ENABLE_HTAP "ON")
|
||||
endif()
|
||||
|
||||
#FIXME: make it an argument
|
||||
set(openGauss ".")
|
||||
@ -107,11 +116,11 @@ install(DIRECTORY ${CMAKE_BINARY_DIR}/pg_plugin DESTINATION lib/postgresql)
|
||||
install(DIRECTORY ${CMAKE_BINARY_DIR}/libsimsearch DESTINATION lib)
|
||||
|
||||
if(EXISTS ${CMAKE_SOURCE_DIR}/contrib/dolphin)
|
||||
install(CODE "execute_process(COMMAND bash cmake.sh WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/contrib/dolphin)")
|
||||
install(CODE "execute_process(COMMAND bash cmake.sh ${BUILD_TUPLE} ${ENABLE_LITE_MODE} ${ENABLE_MOT} ${ENABLE_HTAP} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/contrib/dolphin)")
|
||||
install(FILES ${CMAKE_SOURCE_DIR}/contrib/dolphin/dolphin.control
|
||||
DESTINATION share/postgresql/extension/
|
||||
)
|
||||
install(FILES ${CMAKE_SOURCE_DIR}/contrib/dolphin/dolphin--4.0.sql
|
||||
install(FILES ${CMAKE_SOURCE_DIR}/contrib/dolphin/dolphin--5.0.sql
|
||||
DESTINATION share/postgresql/extension/
|
||||
)
|
||||
install(FILES ${CMAKE_SOURCE_DIR}/contrib/dolphin/dolphin--1.0--1.1.sql
|
||||
@ -138,12 +147,24 @@ if(EXISTS ${CMAKE_SOURCE_DIR}/contrib/dolphin)
|
||||
install(FILES ${CMAKE_SOURCE_DIR}/contrib/dolphin/dolphin--4.0--3.0.sql
|
||||
DESTINATION share/postgresql/extension/
|
||||
)
|
||||
install(FILES ${CMAKE_SOURCE_DIR}/contrib/dolphin/dolphin--4.0--5.0.sql
|
||||
DESTINATION share/postgresql/extension/
|
||||
)
|
||||
install(FILES ${CMAKE_SOURCE_DIR}/contrib/dolphin/dolphin--5.0--4.0.sql
|
||||
DESTINATION share/postgresql/extension/
|
||||
)
|
||||
install(FILES ${CMAKE_SOURCE_DIR}/contrib/dolphin/dolphin--2.0--2.0.1.sql
|
||||
DESTINATION share/postgresql/extension/
|
||||
)
|
||||
install(FILES ${CMAKE_SOURCE_DIR}/contrib/dolphin/dolphin--2.0.1--2.0.sql
|
||||
DESTINATION share/postgresql/extension/
|
||||
)
|
||||
install(FILES ${CMAKE_SOURCE_DIR}/contrib/dolphin/dolphin--4.0--4.0.1.sql
|
||||
DESTINATION share/postgresql/extension/
|
||||
)
|
||||
install(FILES ${CMAKE_SOURCE_DIR}/contrib/dolphin/dolphin--4.0.1--4.0.sql
|
||||
DESTINATION share/postgresql/extension/
|
||||
)
|
||||
install(FILES ${CMAKE_SOURCE_DIR}/contrib/dolphin/openGauss_expr_dolphin.ir
|
||||
DESTINATION share/postgresql/extension/
|
||||
)
|
||||
|
||||
@ -63,6 +63,7 @@ install:
|
||||
$(MAKE) -C $(root_builddir)/distribute/kernel/extension/dimsearch $@
|
||||
$(MAKE) -C contrib/security_plugin $@
|
||||
$(MAKE) -C $(root_builddir)/distribute/kernel/extension/tsdb $@
|
||||
$(MAKE) -C contrib/common_cipher $@
|
||||
+@echo "openGauss installation complete."
|
||||
else
|
||||
ifeq ($(enable_privategauss), yes)
|
||||
@ -75,6 +76,7 @@ install:
|
||||
$(MAKE) -C contrib/hstore $@
|
||||
$(MAKE) -C $(root_builddir)/privategauss/kernel/extension/packages $@
|
||||
$(MAKE) -C $(root_builddir)/contrib/gsredistribute $@
|
||||
$(MAKE) -C contrib/common_cipher $@
|
||||
+@echo "openGauss installation complete."
|
||||
else
|
||||
install:
|
||||
@ -84,6 +86,7 @@ install:
|
||||
$(MAKE) -C contrib/postgres_fdw $@
|
||||
$(MAKE) -C contrib/hstore $@
|
||||
$(MAKE) -C $(root_builddir)/privategauss/kernel/extension/packages $@
|
||||
$(MAKE) -C contrib/common_cipher $@
|
||||
+@echo "openGauss installation complete."
|
||||
endif
|
||||
else
|
||||
@ -95,13 +98,32 @@ install:
|
||||
$(MAKE) -C contrib/hstore $@
|
||||
$(MAKE) -C contrib/dblink $@
|
||||
$(MAKE) -C contrib/ndpplugin $@
|
||||
$(MAKE) -C contrib/common_cipher $@
|
||||
@if test -d contrib/spq_plugin; then $(MAKE) -C contrib/spq_plugin $@; fi
|
||||
@if test -d contrib/dolphin; then $(MAKE) -C contrib/dolphin $@; fi
|
||||
@if test -d contrib/age; then $(MAKE) -C contrib/age $@; fi
|
||||
@if test -d contrib/datavec; then $(MAKE) -C contrib/datavec clean; fi
|
||||
@if test -d contrib/datavec; then $(MAKE) -C contrib/datavec $@; fi
|
||||
@if test -d contrib/gms_compress; then $(MAKE) -C contrib/gms_compress $@; fi
|
||||
@if test -d contrib/gms_utility; then $(MAKE) -C contrib/gms_utility $@; fi
|
||||
@if test -d contrib/gms_stats; then $(MAKE) -C contrib/gms_stats $@; fi
|
||||
@if test -d contrib/gms_tcp; then $(MAKE) -C contrib/gms_tcp $@; fi
|
||||
@if test -d contrib/gms_profiler; then $(MAKE) -C contrib/gms_profiler $@; fi
|
||||
@if test -d contrib/gms_xmlgen; then $(MAKE) -C contrib/gms_xmlgen $@; fi
|
||||
@if test -d contrib/gms_output; then $(MAKE) -C contrib/gms_output $@; fi
|
||||
@if test -d contrib/gms_i18n; then $(MAKE) -C contrib/gms_i18n $@; fi
|
||||
@if test -d contrib/gms_inaddr; then $(MAKE) -C contrib/gms_inaddr $@; fi
|
||||
@if test -d contrib/timescaledb; then (./contrib/timescaledb/run_to_build.sh && $(MAKE) -C contrib/timescaledb/build $@); fi
|
||||
@if test -d contrib/chparser; then \
|
||||
if command -v scws &> /dev/null; then \
|
||||
$(MAKE) -C contrib/chparser $@; \
|
||||
else \
|
||||
echo "SCWS is not installed, skipping chparser build."; \
|
||||
fi \
|
||||
fi
|
||||
@if test -d contrib/gms_lob; then $(MAKE) -C contrib/gms_lob $@; fi
|
||||
@if test -d contrib/gms_sql; then $(MAKE) -C contrib/gms_sql $@; fi
|
||||
@if test -d contrib/gms_debug; then $(MAKE) -C contrib/gms_debug $@; fi
|
||||
+@echo "openGauss installation complete."
|
||||
endif
|
||||
endif
|
||||
|
||||
31
README.md
31
README.md
@ -498,17 +498,22 @@ https://opengauss.org/zh/
|
||||
<strong>openEuler 22.03 arm:</strong> <a href="https://opengauss.obs.cn-south-1.myhuaweicloud.com/5.1.0/binarylibs/gcc10.3/openGauss-third_party_binarylibs_openEuler_2203_arm.tar.gz">https://opengauss.obs.cn-south-1.myhuaweicloud.com/5.1.0/binarylibs/gcc10.3/openGauss-third_party_binarylibs_openEuler_2203_arm.tar.gz</a><br/>
|
||||
<strong>openEuler 22.03 x86:</strong> <a href="https://opengauss.obs.cn-south-1.myhuaweicloud.com/5.1.0/binarylibs/gcc10.3/openGauss-third_party_binarylibs_openEuler_2203_x86_64.tar.gz">https://opengauss.obs.cn-south-1.myhuaweicloud.com/5.1.0/binarylibs/gcc10.3/openGauss-third_party_binarylibs_openEuler_2203_x86_64.tar.gz</a></td>
|
||||
</tr>
|
||||
</tr>
|
||||
<tr>
|
||||
<td rowspan=2>master</td>
|
||||
<td rowspan=2></td>
|
||||
<td>gcc7.3</td>
|
||||
<td rowspan=1>6.0.0</td>
|
||||
<td rowspan=1></td>
|
||||
<td>gcc10.3</td>
|
||||
<td rowspan=1>
|
||||
<strong>openEuler_arm:</strong> <a href="https://opengauss.obs.cn-south-1.myhuaweicloud.com/latest/binarylibs/gcc7.3/openGauss-third_party_binarylibs_openEuler_arm.tar.gz">https://opengauss.obs.cn-south-1.myhuaweicloud.com/latest/binarylibs/gcc7.3/openGauss-third_party_binarylibs_openEuler_arm.tar.gz</a><br/>
|
||||
<strong>openEuler_x86:</strong> <a href="https://opengauss.obs.cn-south-1.myhuaweicloud.com/latest/binarylibs/gcc7.3/openGauss-third_party_binarylibs_openEuler_x86_64.tar.gz">https://opengauss.obs.cn-south-1.myhuaweicloud.com/latest/binarylibs/gcc7.3/openGauss-third_party_binarylibs_openEuler_x86_64.tar.gz</a><br/>
|
||||
<strong>Centos_x86:</strong> <a href="https://opengauss.obs.cn-south-1.myhuaweicloud.com/latest/binarylibs/gcc7.3/openGauss-third_party_binarylibs_Centos7.6_x86_64.tar.gz">https://opengauss.obs.cn-south-1.myhuaweicloud.com/latest/binarylibs/gcc7.3/openGauss-third_party_binarylibs_Centos7.6_x86_64.tar.gz</a><br/>
|
||||
<strong>openEuler 22.03 arm:</strong> <a href="https://opengauss.obs.cn-south-1.myhuaweicloud.com/latest/binarylibs/gcc7.3/openGauss-third_party_binarylibs_openEuler_arm.tar.gz">https://opengauss.obs.cn-south-1.myhuaweicloud.com/latest/binarylibs/gcc7.3/openGauss-third_party_binarylibs_openEuler_2203_arm.tar.gz</a><br/>
|
||||
<strong>openEuler 22.03 x86:</strong> <a href="https://opengauss.obs.cn-south-1.myhuaweicloud.com/latest/binarylibs/gcc7.3/openGauss-third_party_binarylibs_openEuler_2203_x86_64.tar.gz">https://opengauss.obs.cn-south-1.myhuaweicloud.com/latest/binarylibs/gcc7.3/openGauss-third_party_binarylibs_openEuler_2203_x86_64.tar.gz</a></td>
|
||||
<strong>openEuler_arm:</strong> <a href="https://opengauss.obs.cn-south-1.myhuaweicloud.com/6.0.0/binarylibs/gcc10.3/openGauss-third_party_binarylibs_openEuler_arm.tar.gz">https://opengauss.obs.cn-south-1.myhuaweicloud.com/6.0.0/binarylibs/gcc10.3/openGauss-third_party_binarylibs_openEuler_arm.tar.gz</a><br/>
|
||||
<strong>openEuler_x86:</strong> <a href="https://opengauss.obs.cn-south-1.myhuaweicloud.com/6.0.0/binarylibs/gcc10.3/openGauss-third_party_binarylibs_openEuler_x86_64.tar.gz">https://opengauss.obs.cn-south-1.myhuaweicloud.com/6.0.0/binarylibs/gcc10.3/openGauss-third_party_binarylibs_openEuler_x86_64.tar.gz</a><br/>
|
||||
<strong>Centos_x86:</strong> <a href="https://opengauss.obs.cn-south-1.myhuaweicloud.com/6.0.0/binarylibs/gcc10.3/openGauss-third_party_binarylibs_Centos7.6_x86_64.tar.gz">https://opengauss.obs.cn-south-1.myhuaweicloud.com/6.0.0/binarylibs/gcc10.3/openGauss-third_party_binarylibs_Centos7.6_x86_64.tar.gz</a><br/>
|
||||
<strong>openEuler 22.03 arm:</strong> <a href="https://opengauss.obs.cn-south-1.myhuaweicloud.com/6.0.0/binarylibs/gcc10.3/openGauss-third_party_binarylibs_openEuler_2203_arm.tar.gz">https://opengauss.obs.cn-south-1.myhuaweicloud.com/6.0.0/binarylibs/gcc10.3/openGauss-third_party_binarylibs_openEuler_2203_arm.tar.gz</a><br/>
|
||||
<strong>openEuler 22.03 x86:</strong> <a href="https://opengauss.obs.cn-south-1.myhuaweicloud.com/6.0.0/binarylibs/gcc10.3/openGauss-third_party_binarylibs_openEuler_2203_x86_64.tar.gz">https://opengauss.obs.cn-south-1.myhuaweicloud.com/6.0.0/binarylibs/gcc10.3/openGauss-third_party_binarylibs_openEuler_2203_x86_64.tar.gz</a></td>
|
||||
</tr>
|
||||
</tr>
|
||||
<tr>
|
||||
<td rowspan=1>master</td>
|
||||
<td rowspan=1></td>
|
||||
<td>gcc10.3</td>
|
||||
<td rowspan=1>
|
||||
<strong>openEuler_arm:</strong> <a href="https://opengauss.obs.cn-south-1.myhuaweicloud.com/latest/binarylibs/gcc10.3/openGauss-third_party_binarylibs_openEuler_arm.tar.gz">https://opengauss.obs.cn-south-1.myhuaweicloud.com/latest/binarylibs/gcc10.3/openGauss-third_party_binarylibs_openEuler_arm.tar.gz</a><br/>
|
||||
@ -520,6 +525,7 @@ https://opengauss.org/zh/
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
注:6.0.0及以后的版本请使用gcc10.3的三方库进行编译
|
||||
|
||||
现在我们已经拥有完整的openGauss代码,把它存储在以下目录中(以sda为例)。
|
||||
|
||||
@ -609,9 +615,6 @@ openGauss-server中的build.sh是编译过程中的重要脚本工具。该工
|
||||
**debug**版本:
|
||||
|
||||
```
|
||||
# gcc7.3.0版本
|
||||
./configure --gcc-version=7.3.0 CC=g++ CFLAGS='-O0' --prefix=$GAUSSHOME --3rd=$BINARYLIBS --enable-debug --enable-cassert --enable-thread-safety --with-readline --without-zlib
|
||||
|
||||
# gcc10.3.1版本(一般用于openEuler + ARM架构)
|
||||
./configure --gcc-version=10.3.1 CC=g++ CFLAGS='-O0' --prefix=$GAUSSHOME --3rd=$BINARYLIBS --enable-debug --enable-cassert --enable-thread-safety --with-readline --without-zlib
|
||||
|
||||
@ -623,9 +626,6 @@ openGauss-server中的build.sh是编译过程中的重要脚本工具。该工
|
||||
**release**版本:
|
||||
|
||||
```
|
||||
# gcc7.3.0版本
|
||||
./configure --gcc-version=7.3.0 CC=g++ CFLAGS="-O2 -g3" --prefix=$GAUSSHOME --3rd=$BINARYLIBS --enable-thread-safety --with-readline --without-zlib
|
||||
|
||||
# gcc10.3.1版本(一般用于openEuler + ARM架构)
|
||||
./configure --gcc-version=10.3.1 CC=g++ CFLAGS="-O2 -g3" --prefix=$GAUSSHOME --3rd=$BINARYLIBS --enable-thread-safety --with-readline --without-zlib
|
||||
|
||||
@ -637,9 +637,6 @@ openGauss-server中的build.sh是编译过程中的重要脚本工具。该工
|
||||
**memcheck**版本:
|
||||
|
||||
```
|
||||
# gcc7.3.0版本
|
||||
./configure --gcc-version=7.3.0 CC=g++ CFLAGS='-O0' --prefix=$GAUSSHOME --3rd=$BINARYLIBS --enable-debug --enable-cassert --enable-thread-safety --with-readline --without-zlib --enable-memory-check
|
||||
|
||||
# gcc10.3.1版本(一般用于openEuler + ARM架构)
|
||||
./configure --gcc-version=10.3.1 CC=g++ CFLAGS='-O0' --prefix=$GAUSSHOME --3rd=$BINARYLIBS --enable-debug --enable-cassert --enable-thread-safety --with-readline --without-zlib --enable-memory-check
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
7
build.sh
7
build.sh
@ -32,6 +32,7 @@ function print_help()
|
||||
-pm|--product_mode this values of paramenter is opengauss or lite or finance, the default value is opengauss.
|
||||
-nls|--enable_nls enable Native Language Support
|
||||
--relocation generate gaussdb.map with relocation(GCC >=10.3).
|
||||
--cmake use cmake to build openGauss, which is faster than traditional configure/autoconf
|
||||
"
|
||||
}
|
||||
|
||||
@ -90,6 +91,10 @@ while [ $# -gt 0 ]; do
|
||||
extra_config_opt="$extra_config_opt --config_opt --enable-relocation "
|
||||
shift 1
|
||||
;;
|
||||
-C|--cmake)
|
||||
build_by_cmake='--cmake'
|
||||
shift 1
|
||||
;;
|
||||
*)
|
||||
echo "Internal Error: option processing error: $1" 1>&2
|
||||
echo "please input right paramtenter, the following command may help you"
|
||||
@ -103,7 +108,7 @@ ROOT_DIR=$(cd $(dirname "${BASH_SOURCE[0]}") && pwd)
|
||||
echo "ROOT_DIR : $ROOT_DIR"
|
||||
cd build/script
|
||||
chmod a+x build_opengauss.sh
|
||||
./build_opengauss.sh -m ${build_version_mode} -3rd ${build_binarylib_dir} ${not_optimized} -pkg server ${build_with_tassl} -pm ${product_mode} ${extra_config_opt}
|
||||
./build_opengauss.sh -m ${build_version_mode} -3rd ${build_binarylib_dir} ${not_optimized} -pkg server ${build_with_tassl} -pm ${product_mode} ${extra_config_opt} ${build_by_cmake}
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "build_opengauss.sh failed, aborting."
|
||||
exit 1
|
||||
|
||||
3
build/.gitignore
vendored
Normal file
3
build/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
*
|
||||
!.gitignore
|
||||
!script/
|
||||
@ -1,6 +1,7 @@
|
||||
[server]
|
||||
./bin/dsscmd
|
||||
./bin/dssserver
|
||||
./bin/dsstbox
|
||||
./bin/perctrl
|
||||
./bin/dms_contrl.sh
|
||||
./bin/dss_clear.sh
|
||||
@ -47,6 +48,7 @@
|
||||
./bin/gs_plan_simulator.sh
|
||||
./bin/pg_xlogdump
|
||||
./bin/pagehack
|
||||
./bin/pg_archivecleanup
|
||||
./bin/gs_assessment
|
||||
./bin/gs_retrieve
|
||||
./etc/kerberos/kadm5.acl
|
||||
@ -75,7 +77,7 @@
|
||||
./share/postgresql/extension/spqplugin.control
|
||||
./share/postgresql/extension/spqplugin--1.0.sql
|
||||
./share/postgresql/extension/dolphin.control
|
||||
./share/postgresql/extension/dolphin--4.0.sql
|
||||
./share/postgresql/extension/dolphin--5.0.sql
|
||||
./share/postgresql/extension/dolphin--1.0--1.1.sql
|
||||
./share/postgresql/extension/dolphin--1.1--1.0.sql
|
||||
./share/postgresql/extension/dolphin--1.1--2.0.sql
|
||||
@ -84,8 +86,12 @@
|
||||
./share/postgresql/extension/dolphin--3.0--2.0.sql
|
||||
./share/postgresql/extension/dolphin--3.0--4.0.sql
|
||||
./share/postgresql/extension/dolphin--4.0--3.0.sql
|
||||
./share/postgresql/extension/dolphin--4.0--5.0.sql
|
||||
./share/postgresql/extension/dolphin--5.0--4.0.sql
|
||||
./share/postgresql/extension/dolphin--2.0--2.0.1.sql
|
||||
./share/postgresql/extension/dolphin--2.0.1--2.0.sql
|
||||
./share/postgresql/extension/dolphin--4.0--4.0.1.sql
|
||||
./share/postgresql/extension/dolphin--4.0.1--4.0.sql
|
||||
./share/postgresql/extension/whale.control
|
||||
./share/postgresql/extension/whale--1.0.sql
|
||||
./share/postgresql/extension/openGauss_expr_dolphin.ir
|
||||
|
||||
@ -34,7 +34,7 @@
|
||||
./share/postgresql/extension/security_plugin.control
|
||||
./share/postgresql/extension/security_plugin--1.0.sql
|
||||
./share/postgresql/extension/dolphin.control
|
||||
./share/postgresql/extension/dolphin--4.0.sql
|
||||
./share/postgresql/extension/dolphin--5.0.sql
|
||||
./share/postgresql/extension/dolphin--1.0--1.1.sql
|
||||
./share/postgresql/extension/dolphin--1.1--1.0.sql
|
||||
./share/postgresql/extension/dolphin--1.1--2.0.sql
|
||||
@ -43,8 +43,14 @@
|
||||
./share/postgresql/extension/dolphin--3.0--2.0.sql
|
||||
./share/postgresql/extension/dolphin--3.0--4.0.sql
|
||||
./share/postgresql/extension/dolphin--4.0--3.0.sql
|
||||
./share/postgresql/extension/dolphin--4.0--5.0.sql
|
||||
./share/postgresql/extension/dolphin--5.0--4.0.sql
|
||||
./share/postgresql/extension/dolphin--2.0--2.0.1.sql
|
||||
./share/postgresql/extension/dolphin--2.0.1--2.0.sql
|
||||
./share/postgresql/extension/dolphin--4.0--4.0.1.sql
|
||||
./share/postgresql/extension/dolphin--4.0.1--4.0.sql
|
||||
./share/postgresql/extension/gms_compress--1.0.sql
|
||||
./share/postgresql/extension/gms_compress.control
|
||||
./share/postgresql/extension/openGauss_expr_dolphin.ir
|
||||
./share/postgresql/extension/file_fdw--1.0.sql
|
||||
./share/postgresql/extension/plpgsql.control
|
||||
@ -57,6 +63,24 @@
|
||||
./share/postgresql/extension/hstore--1.0--1.1.sql
|
||||
./share/postgresql/extension/log_fdw--1.0.sql
|
||||
./share/postgresql/extension/log_fdw.control
|
||||
./share/postgresql/extension/gms_utility--1.0.sql
|
||||
./share/postgresql/extension/gms_utility.control
|
||||
./share/postgresql/extension/gms_output--1.0.sql
|
||||
./share/postgresql/extension/gms_output.control
|
||||
./share/postgresql/extension/gms_stats--1.0.sql
|
||||
./share/postgresql/extension/gms_stats.control
|
||||
./share/postgresql/extension/gms_profiler--1.0.sql
|
||||
./share/postgresql/extension/gms_profiler.control
|
||||
./share/postgresql/extension/gms_debug--1.0.sql
|
||||
./share/postgresql/extension/gms_debug.control
|
||||
./share/postgresql/extension/gms_lob--1.0.sql
|
||||
./share/postgresql/extension/gms_lob.control
|
||||
./share/postgresql/extension/gms_sql--1.0.sql
|
||||
./share/postgresql/extension/gms_sql.control
|
||||
./share/postgresql/extension/gms_i18n--1.0.sql
|
||||
./share/postgresql/extension/gms_i18n.control
|
||||
./share/postgresql/extension/gms_inaddr--1.0.sql
|
||||
./share/postgresql/extension/gms_inaddr.control
|
||||
./share/postgresql/timezone/GB-Eire
|
||||
./share/postgresql/timezone/Turkey
|
||||
./share/postgresql/timezone/Kwajalein
|
||||
@ -701,6 +725,8 @@
|
||||
./lib/libdcf.so
|
||||
./lib/libzstd.so*
|
||||
./lib/libcurl.so*
|
||||
./lib/libaws-cpp-sdk-core.so
|
||||
./lib/libaws-cpp-sdk-s3.so
|
||||
./lib/libxgboost.so
|
||||
./lib/libpagecompression.so*
|
||||
./lib/postgresql/latin2_and_win1250.so
|
||||
@ -739,10 +765,20 @@
|
||||
./lib/postgresql/proc_srclib
|
||||
./lib/postgresql/security_plugin.so
|
||||
./lib/postgresql/dolphin.so
|
||||
./lib/postgresql/gms_compress.so
|
||||
./lib/postgresql/pg_upgrade_support.so
|
||||
./lib/postgresql/latin2_and_win1250.so
|
||||
./lib/postgresql/euc2004_sjis2004.so
|
||||
./lib/postgresql/pgoutput.so
|
||||
./lib/postgresql/gms_utility.so
|
||||
./lib/postgresql/gms_output.so
|
||||
./lib/postgresql/gms_stats.so
|
||||
./lib/postgresql/gms_profiler.so
|
||||
./lib/postgresql/gms_lob.so
|
||||
./lib/postgresql/gms_sql.so
|
||||
./lib/postgresql/gms_i18n.so
|
||||
./lib/postgresql/gms_debug.so
|
||||
./lib/postgresql/gms_inaddr.so
|
||||
./include/postgresql/server/postgres_ext.h
|
||||
./include/postgresql/server/pg_config_os.h
|
||||
./include/postgresql/server/pgtime.h
|
||||
@ -919,4 +955,4 @@
|
||||
./include/pqcomm.h
|
||||
./include/pqexpbuffer.h
|
||||
[version]
|
||||
6.0.0
|
||||
7.0.0-RC1
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
[server]
|
||||
./bin/dsscmd
|
||||
./bin/dssserver
|
||||
./bin/dsstbox
|
||||
./bin/perctrl
|
||||
./bin/dms_contrl.sh
|
||||
./bin/dss_clear.sh
|
||||
@ -48,6 +49,7 @@
|
||||
./bin/gs_plan_simulator.sh
|
||||
./bin/pg_xlogdump
|
||||
./bin/pagehack
|
||||
./bin/pg_archivecleanup
|
||||
./bin/gs_assessment
|
||||
./bin/gs_retrieve
|
||||
./etc/kerberos/kadm5.acl
|
||||
@ -75,8 +77,10 @@
|
||||
./share/postgresql/extension/ndpplugin--1.0.sql
|
||||
./share/postgresql/extension/spqplugin.control
|
||||
./share/postgresql/extension/spqplugin--1.0.sql
|
||||
./share/postgresql/extension/timescaledb.control
|
||||
./share/postgresql/extension/timescaledb--1.7.4.sql
|
||||
./share/postgresql/extension/dolphin.control
|
||||
./share/postgresql/extension/dolphin--4.0.sql
|
||||
./share/postgresql/extension/dolphin--5.0.sql
|
||||
./share/postgresql/extension/dolphin--1.0--1.1.sql
|
||||
./share/postgresql/extension/dolphin--1.1--1.0.sql
|
||||
./share/postgresql/extension/dolphin--1.1--2.0.sql
|
||||
@ -85,13 +89,19 @@
|
||||
./share/postgresql/extension/dolphin--3.0--2.0.sql
|
||||
./share/postgresql/extension/dolphin--3.0--4.0.sql
|
||||
./share/postgresql/extension/dolphin--4.0--3.0.sql
|
||||
./share/postgresql/extension/dolphin--4.0--5.0.sql
|
||||
./share/postgresql/extension/dolphin--5.0--4.0.sql
|
||||
./share/postgresql/extension/dolphin--2.0--2.0.1.sql
|
||||
./share/postgresql/extension/dolphin--2.0.1--2.0.sql
|
||||
./share/postgresql/extension/dolphin--4.0--4.0.1.sql
|
||||
./share/postgresql/extension/dolphin--4.0.1--4.0.sql
|
||||
./share/postgresql/extension/openGauss_expr_dolphin.ir
|
||||
./share/postgresql/extension/age--1.0.0.sql
|
||||
./share/postgresql/extension/age.control
|
||||
./share/postgresql/extension/datavec--0.4.4.sql
|
||||
./share/postgresql/extension/datavec--1.0.sql
|
||||
./share/postgresql/extension/datavec.control
|
||||
./share/postgresql/extension/chparser--1.0.sql
|
||||
./share/postgresql/extension/chparser.control
|
||||
./share/postgresql/extension/assessment--1.0.sql
|
||||
./share/postgresql/extension/assessment.control
|
||||
./share/postgresql/extension/file_fdw--1.0.sql
|
||||
@ -112,12 +122,30 @@
|
||||
./share/postgresql/extension/dblink--1.0.sql
|
||||
./share/postgresql/extension/dblink--unpackaged--1.0.sql
|
||||
./share/postgresql/extension/dblink.control
|
||||
./share/postgresql/extension/gms_compress--1.0.sql
|
||||
./share/postgresql/extension/gms_compress.control
|
||||
./share/postgresql/extension/gms_utility--1.0.sql
|
||||
./share/postgresql/extension/gms_utility.control
|
||||
./share/postgresql/extension/gms_output--1.0.sql
|
||||
./share/postgresql/extension/gms_output.control
|
||||
./share/postgresql/extension/gms_inaddr--1.0.sql
|
||||
./share/postgresql/extension/gms_inaddr.control
|
||||
./share/postgresql/extension/gms_lob--1.0.sql
|
||||
./share/postgresql/extension/gms_lob.control
|
||||
./share/postgresql/extension/gms_stats--1.0.sql
|
||||
./share/postgresql/extension/gms_stats.control
|
||||
./share/postgresql/extension/gms_tcp--1.0.sql
|
||||
./share/postgresql/extension/gms_tcp.control
|
||||
./share/postgresql/extension/gms_profiler--1.0.sql
|
||||
./share/postgresql/extension/gms_profiler.control
|
||||
./share/postgresql/extension/gms_debug--1.0.sql
|
||||
./share/postgresql/extension/gms_debug.control
|
||||
./share/postgresql/extension/gms_sql--1.0.sql
|
||||
./share/postgresql/extension/gms_sql.control
|
||||
./share/postgresql/extension/gms_xmlgen--1.0.sql
|
||||
./share/postgresql/extension/gms_xmlgen.control
|
||||
./share/postgresql/extension/gms_i18n--1.0.sql
|
||||
./share/postgresql/extension/gms_i18n.control
|
||||
./share/postgresql/timezone/GB-Eire
|
||||
./share/postgresql/timezone/Turkey
|
||||
./share/postgresql/timezone/Kwajalein
|
||||
@ -730,6 +758,7 @@
|
||||
./share/postgresql/tsearch_data/swedish.stop
|
||||
./share/postgresql/tsearch_data/ispell_sample.dict
|
||||
./share/postgresql/tsearch_data/italian.stop
|
||||
./share/postgresql/tsearch_data/dict.utf8.xdb
|
||||
./share/postgresql/information_schema.sql
|
||||
./share/postgresql/timezonesets/Antarctica.txt
|
||||
./share/postgresql/timezonesets/Australia.txt
|
||||
@ -803,18 +832,31 @@
|
||||
./lib/postgresql/pg_plugin
|
||||
./lib/postgresql/proc_srclib
|
||||
./lib/postgresql/security_plugin.so
|
||||
./lib/postgresql/timescaledb-1.7.4.so
|
||||
./lib/postgresql/timescaledb.so
|
||||
./lib/postgresql/timescaledb-tsl-1.7.4.so
|
||||
./lib/postgresql/dolphin.so
|
||||
./lib/postgresql/age.so
|
||||
./lib/postgresql/datavec.so
|
||||
./lib/postgresql/chparser.so
|
||||
./lib/postgresql/pg_upgrade_support.so
|
||||
./lib/postgresql/java/pljava.jar
|
||||
./lib/postgresql/postgres_fdw.so
|
||||
./lib/postgresql/dblink.so
|
||||
./lib/postgresql/gms_utility.so
|
||||
./lib/postgresql/pgoutput.so
|
||||
./lib/postgresql/assessment.so
|
||||
./lib/postgresql/gms_compress.so
|
||||
./lib/postgresql/gms_output.so
|
||||
./lib/postgresql/gms_inaddr.so
|
||||
./lib/postgresql/gms_lob.so
|
||||
./lib/postgresql/gms_stats.so
|
||||
./lib/postgresql/gms_tcp.so
|
||||
./lib/postgresql/gms_profiler.so
|
||||
./lib/postgresql/gms_debug.so
|
||||
./lib/postgresql/gms_sql.so
|
||||
./lib/postgresql/gms_xmlgen.so
|
||||
./lib/postgresql/gms_i18n.so
|
||||
./lib/libpljava.so
|
||||
./lib/libpq.a
|
||||
./lib/libpq.so
|
||||
@ -832,9 +874,7 @@
|
||||
./lib/libecpg.a
|
||||
./lib/libecpg_compat.a
|
||||
./lib/libpgtypes.a
|
||||
./lib/libpgtypes.so
|
||||
./lib/libpgtypes.so.3
|
||||
./lib/libpgtypes.so.3.4
|
||||
./lib/libpgtypes.so*
|
||||
./lib/libgauss_cl_jni.so
|
||||
./lib/libnuma.so
|
||||
./lib/libnuma.so.1
|
||||
@ -871,6 +911,8 @@
|
||||
./lib/krb5/plugins/kdb/db2.so
|
||||
./lib/libverto.so*
|
||||
./lib/libcurl.so*
|
||||
./lib/libaws-cpp-sdk-core.so
|
||||
./lib/libaws-cpp-sdk-s3.so
|
||||
./lib/libcrypto.so*
|
||||
./lib/libssl.so*
|
||||
./lib/libgcc_s.so.1
|
||||
|
||||
@ -29,6 +29,7 @@ function print_help()
|
||||
-s|--symbol_mode whether separate symbol in debug mode, the default value is on.
|
||||
-co|--cmake_opt more cmake options
|
||||
-T|--tassl build with tassl
|
||||
--cmake build by cmake
|
||||
"
|
||||
}
|
||||
|
||||
@ -124,6 +125,10 @@ while [ $# -gt 0 ]; do
|
||||
build_with_tassl="YES"
|
||||
shift 1
|
||||
;;
|
||||
--cmake)
|
||||
CMAKE_PKG="Y"
|
||||
shift 1
|
||||
;;
|
||||
*)
|
||||
echo "Internal Error: option processing error: $1" 1>&2
|
||||
echo "please input right paramtenter, the following command may help you"
|
||||
|
||||
@ -43,7 +43,7 @@ else
|
||||
fi
|
||||
|
||||
if [ X"$kernel" == X"euleros" ]; then
|
||||
dist_version="EULER"
|
||||
dist_version="EulerOS"
|
||||
elif [ X"$kernel" == X"centos" ]; then
|
||||
dist_version="CentOS"
|
||||
elif [ X"$kernel" == X"openeuler" ]; then
|
||||
@ -54,6 +54,8 @@ else
|
||||
dist_version="Platform"
|
||||
fi
|
||||
|
||||
os_version=$(cat /etc/os-release | grep -w VERSION_ID | awk -F '"' '{print $2}')
|
||||
|
||||
show_package=false
|
||||
gcc_version="10.3.1"
|
||||
|
||||
@ -290,12 +292,11 @@ fi
|
||||
#######################################################################
|
||||
## declare all package name
|
||||
#######################################################################
|
||||
declare version_string="${mppdb_name_for_package}-${version_number}"
|
||||
declare package_pre_name="${version_string}-${dist_version}-${PLATFORM_ARCH}"
|
||||
declare server_package_name="${package_pre_name}.${install_package_format}.gz"
|
||||
declare package_version_name="${version_number}-${dist_version}${os_version}-${PLATFORM_ARCH}"
|
||||
declare server_package_name="${mppdb_name_for_package}-${package_version_name}.${install_package_format}.gz"
|
||||
|
||||
declare libpq_package_name="${package_pre_name}-Libpq.${install_package_format}.gz"
|
||||
declare symbol_package_name="${package_pre_name}-symbol.${install_package_format}.gz"
|
||||
declare libpq_package_name="${mppdb_name_for_package}-Libpq-${package_version_name}.${install_package_format}.gz"
|
||||
declare symbol_package_name="${mppdb_name_for_package}-symbol-${package_version_name}.${install_package_format}.gz"
|
||||
|
||||
echo "[makemppdb] $(date +%y-%m-%d' '%T): script dir : ${SCRIPT_DIR}"
|
||||
ROOT_DIR=$(dirname "$SCRIPT_DIR")
|
||||
@ -349,16 +350,9 @@ function read_mpp_number()
|
||||
version_num=$(echo $version_num1 | tr -d ";")
|
||||
#remove the blank
|
||||
version_num=$(echo $version_num)
|
||||
|
||||
if echo $version_num | grep -qE '^92[0-9]+$'
|
||||
then
|
||||
# get the last three number
|
||||
latter=${version_num:2}
|
||||
echo "92.${latter}" >>${SCRIPT_DIR}/version.cfg
|
||||
else
|
||||
echo "Cannot get the version number from globals.cpp."
|
||||
exit 1
|
||||
fi
|
||||
form=${version_num:0:2}
|
||||
latter=${version_num:2}
|
||||
echo "${form}.${latter}" >>${SCRIPT_DIR}/version.cfg
|
||||
}
|
||||
read_mpp_number
|
||||
|
||||
@ -472,6 +466,10 @@ function install_gaussdb()
|
||||
CMAKE_OPT="$CMAKE_OPT -DENABLE_OPENEULER_MAJOR=ON"
|
||||
fi
|
||||
|
||||
if [[ -e "/etc/openEuler-release" && "$(cat /etc/openEuler-release | awk '{print $3}')" == "24.03" ]]; then
|
||||
CMAKE_OPT="$CMAKE_OPT -DENABLE_OPENEULER_MAJOR=ON"
|
||||
fi
|
||||
|
||||
if [ "${PLATFORM_ARCH}"x == "loongarch64"x ]; then
|
||||
CMAKE_OPT="$CMAKE_OPT -DENABLE_BBOX=OFF -DENABLE_JEMALLOC=OFF"
|
||||
fi
|
||||
@ -529,6 +527,10 @@ function install_gaussdb()
|
||||
commitid=$(LD_PRELOAD='' ${BUILD_DIR}/bin/gaussdb -V | cut -d ")" -f 1 | awk '{print $NF}')
|
||||
echo "${commitid}" >>${SCRIPT_DIR}/version.cfg
|
||||
echo "End insert commitid into version.cfg" >> "$LOG_FILE" 2>&1
|
||||
|
||||
#insert the version mode to version.cfg
|
||||
echo "$version_mode" >> ${SCRIPT_DIR}/version.cfg
|
||||
echo "End insert version mode into version cfg" >> "$LOG_FILE" 2>&1
|
||||
}
|
||||
|
||||
#######################################################################
|
||||
@ -587,7 +589,7 @@ function target_file_copy_for_non_server()
|
||||
done
|
||||
}
|
||||
|
||||
declare bin_name="${package_pre_name}.bin"
|
||||
declare bin_name="${mppdb_name_for_package}-${package_version_name}.bin"
|
||||
declare sha256_name=''
|
||||
declare script_dir="${ROOT_DIR}/script"
|
||||
|
||||
@ -639,7 +641,7 @@ function target_file_copy()
|
||||
echo "End generate ${bin_name} bin file" >> "$LOG_FILE" 2>&1
|
||||
|
||||
#generate sha256 file
|
||||
sha256_name="${package_pre_name}.sha256"
|
||||
sha256_name="${mppdb_name_for_package}-${package_version_name}.sha256"
|
||||
echo "Begin generate ${sha256_name} sha256 file..." >> "$LOG_FILE" 2>&1
|
||||
sha256sum "${bin_name}" | awk -F" " '{print $1}' > "$sha256_name"
|
||||
if [ $? -ne 0 ]; then
|
||||
@ -811,4 +813,4 @@ mkdir ${ROOT_DIR}/output
|
||||
mv ${ROOT_DIR}/build/script/*.tar.gz ${ROOT_DIR}/output/
|
||||
test -e ${ROOT_DIR}/build/script/gaussdb.map && mv ${ROOT_DIR}/build/script/gaussdb.map ${ROOT_DIR}/output/
|
||||
echo "now, all packages has finished!"
|
||||
exit 0
|
||||
exit 0
|
||||
|
||||
@ -1,2 +1,2 @@
|
||||
PRODUCT=openGauss
|
||||
VERSION=6.0.0
|
||||
VERSION=7.0.0-RC1
|
||||
@ -45,6 +45,8 @@
|
||||
./share/postgresql/extension/plpgsql.control
|
||||
./share/postgresql/extension/dist_fdw.control
|
||||
./share/postgresql/extension/dist_fdw--1.0.sql
|
||||
./share/postgresql/extension/gms_compress--1.0.sql
|
||||
./share/postgresql/extension/gms_compress.control
|
||||
./share/postgresql/extension/hstore--1.1.sql
|
||||
./share/postgresql/extension/plpgsql--unpackaged--1.0.sql
|
||||
./share/postgresql/extension/file_fdw.control
|
||||
@ -52,6 +54,24 @@
|
||||
./share/postgresql/extension/hstore--1.0--1.1.sql
|
||||
./share/postgresql/extension/log_fdw--1.0.sql
|
||||
./share/postgresql/extension/log_fdw.control
|
||||
./share/postgresql/extension/gms_output--1.0.sql
|
||||
./share/postgresql/extension/gms_output.control
|
||||
./share/postgresql/extension/gms_inaddr--1.0.sql
|
||||
./share/postgresql/extension/gms_inaddr.control
|
||||
./share/postgresql/extension/gms_stats--1.0.sql
|
||||
./share/postgresql/extension/gms_stats.control
|
||||
./share/postgresql/extension/gms_profiler--1.0.sql
|
||||
./share/postgresql/extension/gms_profiler.control
|
||||
./share/postgresql/extension/gms_lob--1.0.sql
|
||||
./share/postgresql/extension/gms_lob.control
|
||||
./share/postgresql/extension/gms_sql--1.0.sql
|
||||
./share/postgresql/extension/gms_sql.control
|
||||
./share/postgresql/extension/gms_i18n--1.0.sql
|
||||
./share/postgresql/extension/gms_i18n.control
|
||||
./share/postgresql/extension/gms_utility--1.0.sql
|
||||
./share/postgresql/extension/gms_utility.control
|
||||
./share/postgresql/extension/gms_debug--1.0.sql
|
||||
./share/postgresql/extension/gms_debug.control
|
||||
./share/postgresql/timezone/GB-Eire
|
||||
./share/postgresql/timezone/Turkey
|
||||
./share/postgresql/timezone/Kwajalein
|
||||
@ -714,6 +734,7 @@
|
||||
./lib/postgresql/utf8_and_sjis.so
|
||||
./lib/postgresql/utf8_and_cyrillic.so
|
||||
./lib/postgresql/hstore.so
|
||||
./lib/postgresql/gms_compress.so
|
||||
./lib/postgresql/packages.so
|
||||
./lib/postgresql/utf8_and_euc_kr.so
|
||||
./lib/postgresql/ascii_and_mic.so
|
||||
@ -738,6 +759,15 @@
|
||||
./lib/postgresql/latin2_and_win1250.so
|
||||
./lib/postgresql/euc2004_sjis2004.so
|
||||
./lib/postgresql/pgoutput.so
|
||||
./lib/postgresql/gms_output.so
|
||||
./lib/postgresql/gms_inaddr.so
|
||||
./lib/postgresql/gms_stats.so
|
||||
./lib/postgresql/gms_profiler.so
|
||||
./lib/postgresql/gms_lob.so
|
||||
./lib/postgresql/gms_sql.so
|
||||
./lib/postgresql/gms_i18n.so
|
||||
./lib/postgresql/gms_utility.so
|
||||
./lib/postgresql/gms_debug.so
|
||||
./include/postgresql/server/postgres_ext.h
|
||||
./include/postgresql/server/pg_config_os.h
|
||||
./include/postgresql/server/pgtime.h
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
[server]
|
||||
./bin/dsscmd
|
||||
./bin/dssserver
|
||||
./bin/dsstbox
|
||||
./bin/perctrl
|
||||
./bin/dms_contrl.sh
|
||||
./bin/dss_clear.sh
|
||||
@ -97,6 +98,8 @@
|
||||
./share/postgresql/extension/mot_fdw.control
|
||||
./share/postgresql/extension/postgres_fdw--1.0.sql
|
||||
./share/postgresql/extension/postgres_fdw.control
|
||||
./share/postgresql/extension/gms_compress--1.0.sql
|
||||
./share/postgresql/extension/gms_compress.control
|
||||
./share/postgresql/extension/dblink--1.0.sql
|
||||
./share/postgresql/extension/dblink--unpackaged--1.0.sql
|
||||
./share/postgresql/extension/dblink.control
|
||||
@ -775,6 +778,7 @@
|
||||
./lib/postgresql/pg_upgrade_support.so
|
||||
./lib/postgresql/java/pljava.jar
|
||||
./lib/postgresql/postgres_fdw.so
|
||||
./lib/postgresql/gms_compress.so
|
||||
./lib/postgresql/dblink.so
|
||||
./lib/postgresql/pgoutput.so
|
||||
./lib/postgresql/assessment.so
|
||||
|
||||
@ -79,9 +79,29 @@
|
||||
./share/postgresql/extension/gsredistribute--unpackaged--1.0.sql
|
||||
./share/postgresql/extension/postgres_fdw--1.0.sql
|
||||
./share/postgresql/extension/postgres_fdw.control
|
||||
./share/postgresql/extension/gms_compress--1.0.sql
|
||||
./share/postgresql/extension/gms_compress.control
|
||||
./share/postgresql/extension/dblink--1.0.sql
|
||||
./share/postgresql/extension/dblink--unpackaged--1.0.sql
|
||||
./share/postgresql/extension/dblink.control
|
||||
./share/postgresql/extension/gms_output--1.0.sql
|
||||
./share/postgresql/extension/gms_output.control
|
||||
./share/postgresql/extension/gms_inaddr--1.0.sql
|
||||
./share/postgresql/extension/gms_inaddr.control
|
||||
./share/postgresql/extension/gms_stats--1.0.sql
|
||||
./share/postgresql/extension/gms_stats.control
|
||||
./share/postgresql/extension/gms_profiler--1.0.sql
|
||||
./share/postgresql/extension/gms_profiler.control
|
||||
./share/postgresql/extension/gms_lob--1.0.sql
|
||||
./share/postgresql/extension/gms_lob.control
|
||||
./share/postgresql/extension/gms_sql--1.0.sql
|
||||
./share/postgresql/extension/gms_sql.control
|
||||
./share/postgresql/extension/gms_i18n--1.0.sql
|
||||
./share/postgresql/extension/gms_i18n.control
|
||||
./share/postgresql/extension/gms_utility--1.0.sql
|
||||
./share/postgresql/extension/gms_utility.control
|
||||
./share/postgresql/extension/gms_debug--1.0.sql
|
||||
./share/postgresql/extension/gms_debug.control
|
||||
./share/postgresql/timezone/GB-Eire
|
||||
./share/postgresql/timezone/Turkey
|
||||
./share/postgresql/timezone/Kwajalein
|
||||
@ -755,7 +775,17 @@
|
||||
./lib/postgresql/pg_upgrade_support.so
|
||||
./lib/postgresql/java/pljava.jar
|
||||
./lib/postgresql/postgres_fdw.so
|
||||
./lib/postgresql/gms_compress.so
|
||||
./lib/postgresql/dblink.so
|
||||
./lib/postgresql/gms_output.so
|
||||
./lib/postgresql/gms_inaddr.so
|
||||
./lib/postgresql/gms_stats.so
|
||||
./lib/postgresql/gms_profiler.so
|
||||
./lib/postgresql/gms_lob.so
|
||||
./lib/postgresql/gms_sql.so
|
||||
./lib/postgresql/gms_i18n.so
|
||||
./lib/postgresql/gms_utility.so
|
||||
./lib/postgresql/gms_debug.so
|
||||
./lib/libpljava.so
|
||||
./lib/libpq.a
|
||||
./lib/libpq.so
|
||||
|
||||
@ -61,8 +61,10 @@
|
||||
./share/postgresql/extension/hstore.control
|
||||
./share/postgresql/extension/security_plugin.control
|
||||
./share/postgresql/extension/security_plugin--1.0.sql
|
||||
./share/postgresql/extension/timescaledb.control
|
||||
./share/postgresql/extension/timescaledb--1.7.4.sql
|
||||
./share/postgresql/extension/dolphin.control
|
||||
./share/postgresql/extension/dolphin--4.0.sql
|
||||
./share/postgresql/extension/dolphin--5.0.sql
|
||||
./share/postgresql/extension/dolphin--1.0--1.1.sql
|
||||
./share/postgresql/extension/dolphin--1.1--1.0.sql
|
||||
./share/postgresql/extension/dolphin--1.1--2.0.sql
|
||||
@ -71,13 +73,19 @@
|
||||
./share/postgresql/extension/dolphin--3.0--2.0.sql
|
||||
./share/postgresql/extension/dolphin--3.0--4.0.sql
|
||||
./share/postgresql/extension/dolphin--4.0--3.0.sql
|
||||
./share/postgresql/extension/dolphin--4.0--5.0.sql
|
||||
./share/postgresql/extension/dolphin--5.0--4.0.sql
|
||||
./share/postgresql/extension/dolphin--2.0--2.0.1.sql
|
||||
./share/postgresql/extension/dolphin--2.0.1--2.0.sql
|
||||
./share/postgresql/extension/dolphin--4.0--4.0.1.sql
|
||||
./share/postgresql/extension/dolphin--4.0.1--4.0.sql
|
||||
./share/postgresql/extension/openGauss_expr_dolphin.ir
|
||||
./share/postgresql/extension/age--1.0.0.sql
|
||||
./share/postgresql/extension/age.control
|
||||
./share/postgresql/extension/datavec--0.4.4.sql
|
||||
./share/postgresql/extension/datavec--1.0.sql
|
||||
./share/postgresql/extension/datavec.control
|
||||
./share/postgresql/extension/chparser--1.0.sql
|
||||
./share/postgresql/extension/chparser.control
|
||||
./share/postgresql/extension/file_fdw--1.0.sql
|
||||
./share/postgresql/extension/plpgsql.control
|
||||
./share/postgresql/extension/dist_fdw.control
|
||||
@ -101,12 +109,30 @@
|
||||
./share/postgresql/extension/dblink--1.0.sql
|
||||
./share/postgresql/extension/dblink--unpackaged--1.0.sql
|
||||
./share/postgresql/extension/dblink.control
|
||||
./share/postgresql/extension/gms_compress--1.0.sql
|
||||
./share/postgresql/extension/gms_compress.control
|
||||
./share/postgresql/extension/gms_output--1.0.sql
|
||||
./share/postgresql/extension/gms_output.control
|
||||
./share/postgresql/extension/gms_inaddr--1.0.sql
|
||||
./share/postgresql/extension/gms_inaddr.control
|
||||
./share/postgresql/extension/gms_lob--1.0.sql
|
||||
./share/postgresql/extension/gms_lob.control
|
||||
./share/postgresql/extension/gms_stats--1.0.sql
|
||||
./share/postgresql/extension/gms_stats.control
|
||||
./share/postgresql/extension/gms_utility--1.0.sql
|
||||
./share/postgresql/extension/gms_utility.control
|
||||
./share/postgresql/extension/gms_profiler--1.0.sql
|
||||
./share/postgresql/extension/gms_profiler.control
|
||||
./share/postgresql/extension/gms_debug--1.0.sql
|
||||
./share/postgresql/extension/gms_debug.control
|
||||
./share/postgresql/extension/gms_sql--1.0.sql
|
||||
./share/postgresql/extension/gms_sql.control
|
||||
./share/postgresql/extension/gms_tcp--1.0.sql
|
||||
./share/postgresql/extension/gms_tcp.control
|
||||
./share/postgresql/extension/gms_xmlgen--1.0.sql
|
||||
./share/postgresql/extension/gms_xmlgen.control
|
||||
./share/postgresql/extension/gms_i18n--1.0.sql
|
||||
./share/postgresql/extension/gms_i18n.control
|
||||
./share/postgresql/timezone/GB-Eire
|
||||
./share/postgresql/timezone/Turkey
|
||||
./share/postgresql/timezone/Kwajalein
|
||||
@ -718,6 +744,7 @@
|
||||
./share/postgresql/tsearch_data/swedish.stop
|
||||
./share/postgresql/tsearch_data/ispell_sample.dict
|
||||
./share/postgresql/tsearch_data/italian.stop
|
||||
./share/postgresql/tsearch_data/dict.utf8.xdb
|
||||
./share/postgresql/information_schema.sql
|
||||
./share/postgresql/timezonesets/Antarctica.txt
|
||||
./share/postgresql/timezonesets/Australia.txt
|
||||
@ -776,16 +803,29 @@
|
||||
./lib/postgresql/pg_plugin
|
||||
./lib/postgresql/proc_srclib
|
||||
./lib/postgresql/security_plugin.so
|
||||
./lib/postgresql/timescaledb-1.7.4.so
|
||||
./lib/postgresql/timescaledb.so
|
||||
./lib/postgresql/timescaledb-tsl-1.7.4.so
|
||||
./lib/postgresql/dolphin.so
|
||||
./lib/postgresql/age.so
|
||||
./lib/postgresql/datavec.so
|
||||
./lib/postgresql/chparser.so
|
||||
./lib/postgresql/pg_upgrade_support.so
|
||||
./lib/postgresql/java/pljava.jar
|
||||
./lib/postgresql/postgres_fdw.so
|
||||
./lib/postgresql/dblink.so
|
||||
./lib/postgresql/gms_compress.so
|
||||
./lib/postgresql/gms_output.so
|
||||
./lib/postgresql/gms_inaddr.so
|
||||
./lib/postgresql/gms_lob.so
|
||||
./lib/postgresql/gms_stats.so
|
||||
./lib/postgresql/gms_utility.so
|
||||
./lib/postgresql/gms_profiler.so
|
||||
./lib/postgresql/gms_debug.so
|
||||
./lib/postgresql/gms_sql.so
|
||||
./lib/postgresql/gms_tcp.so
|
||||
./lib/postgresql/gms_xmlgen.so
|
||||
./lib/postgresql/gms_i18n.so
|
||||
./lib/libpljava.so
|
||||
./lib/libpq.a
|
||||
./lib/libpq.so
|
||||
@ -864,6 +904,8 @@
|
||||
./lib/libcurl.so
|
||||
./lib/libcurl.so.4
|
||||
./lib/libcurl.so.4.6.0
|
||||
./lib/libaws-cpp-sdk-core.so
|
||||
./lib/libaws-cpp-sdk-s3.so
|
||||
./lib/libcrypto.so
|
||||
./lib/libcrypto.so.1.1
|
||||
./lib/libssl.so
|
||||
|
||||
@ -21,7 +21,7 @@ function gaussdb_pkg_pre_clean()
|
||||
function read_gaussdb_version()
|
||||
{
|
||||
cd ${SCRIPT_DIR}
|
||||
echo "${product_name}-${version_number}" > version.cfg
|
||||
echo "${product_name}-Server-${version_number}" > version.cfg
|
||||
#auto read the number from kernal globals.cpp, no need to change it here
|
||||
}
|
||||
|
||||
@ -39,16 +39,9 @@ function read_gaussdb_number()
|
||||
version_num=$(echo $version_num1 | tr -d ";")
|
||||
#remove the blank
|
||||
version_num=$(echo $version_num)
|
||||
|
||||
if echo $version_num | grep -qE '^92[0-9]+$'
|
||||
then
|
||||
# get the last three number
|
||||
latter=${version_num:2}
|
||||
echo "92.${latter}" >>${SCRIPT_DIR}/version.cfg
|
||||
else
|
||||
echo "Cannot get the version number from globals.cpp."
|
||||
exit 1
|
||||
fi
|
||||
form=${version_num:0:2}
|
||||
latter=${version_num:2}
|
||||
echo "${form}.${latter}" >>${SCRIPT_DIR}/version.cfg
|
||||
}
|
||||
|
||||
#######################################################################
|
||||
@ -63,6 +56,15 @@ function get_kernel_commitid()
|
||||
echo "End insert commitid into version.cfg" >> "$LOG_FILE" 2>&1
|
||||
}
|
||||
|
||||
#######################################################################
|
||||
##insert the version mode to version.cfg
|
||||
#######################################################################
|
||||
function get_version_mode()
|
||||
{
|
||||
echo "$version_mode" >> ${SCRIPT_DIR}/version.cfg
|
||||
echo "End insert version mode into version cfg" >> "$LOG_FILE" 2>&1
|
||||
}
|
||||
|
||||
#######################################################################
|
||||
## generate the version file.
|
||||
#######################################################################
|
||||
@ -157,6 +159,9 @@ function install_gaussdb()
|
||||
|
||||
#insert the commitid to version.cfg as the upgrade app path specification
|
||||
get_kernel_commitid
|
||||
|
||||
#insert the version mode to version.cfg
|
||||
get_version_mode
|
||||
}
|
||||
|
||||
#######################################################################
|
||||
@ -177,4 +182,4 @@ function gaussdb_build()
|
||||
echo "please input right paramenter values server or libpq "
|
||||
exit 1
|
||||
esac
|
||||
}
|
||||
}
|
||||
|
||||
@ -59,14 +59,13 @@ select_package_command
|
||||
#######################################################################
|
||||
##get os dist version
|
||||
#######################################################################
|
||||
os_name=$(cat /etc/os-release | grep -w NAME | awk -F '"' '{print $2}')
|
||||
if [[ -f "/etc/openEuler-release" ]]; then
|
||||
os_name="openEuler"
|
||||
elif [[ -f "/etc/euleros-release" ]]; then
|
||||
os_name="EulerOS"
|
||||
elif [[ -f "/etc/centos-release" ]]; then
|
||||
os_name="CentOS"
|
||||
elif [[ -f "/etc/openEuler-release" ]]; then
|
||||
os_name="openEuler"
|
||||
elif [[ -f "/etc/FusionOS-release" ]]; then
|
||||
os_name="FusionOS"
|
||||
elif [[ -f "/etc/kylin-release" ]]; then
|
||||
@ -78,13 +77,15 @@ elif [[ -f "/etc/CSIOS-release" ]]; then
|
||||
else
|
||||
os_name=$(lsb_release -d | awk -F ' ' '{print $2}'| tr A-Z a-z | sed 's/.*/\L&/; s/[a-z]*/\u&/g')
|
||||
fi
|
||||
os_version=$(cat /etc/os-release | grep -w VERSION_ID | awk -F '"' '{print $2}')
|
||||
|
||||
if [ "$os_name"X == ""X ]; then
|
||||
echo "os name is empty"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
##add platform architecture information
|
||||
if [ "$PLATFORM_ARCH"X == "aarch64"X ] ; then
|
||||
if [ "$os_name" != "openEuler" ] && [ "$os_name" != "EulerOS" ] && [ "$os_name" != "FusionOS" ] && [ "$os_name" != "Kylin" ] && [ "$dist_version" != "Asianux" ] && [ "$os_name" != "CSIOS" ]; then
|
||||
echo "We only support NUMA on openEuler(aarch64), EulerOS(aarch64), FusionOS(aarch64), Kylin(aarch64), Asianux, CSIOS(aarch64) platform."
|
||||
exit 1
|
||||
fi
|
||||
GAUSSDB_EXTRA_FLAGS=" -D__USE_NUMA"
|
||||
fi
|
||||
|
||||
@ -144,10 +145,9 @@ declare release_file_list="${PLATFORM_ARCH}_${product_mode}_list"
|
||||
#######################################################################
|
||||
## declare all package name
|
||||
#######################################################################
|
||||
declare version_string="${product_name}-${version_number}"
|
||||
declare package_pre_name="${version_string}-${os_name}-${PLATFORM}bit"
|
||||
declare libpq_package_name="${package_pre_name}-Libpq.tar.gz"
|
||||
declare tools_package_name="${package_pre_name}-tools.tar.gz"
|
||||
declare kernel_package_name="${package_pre_name}.tar.bz2"
|
||||
declare symbol_package_name="${package_pre_name}-symbol.tar.gz"
|
||||
declare sha256_name="${package_pre_name}.sha256"
|
||||
declare package_version_name="${version_number}-${os_name}${os_version}-${PLATFORM_ARCH}"
|
||||
declare libpq_package_name="${product_name}-Libpq-${package_version_name}.tar.gz"
|
||||
declare tools_package_name="${product_name}-Tools-${package_version_name}.tar.gz"
|
||||
declare kernel_package_name="${product_name}-Server-${package_version_name}.tar.bz2"
|
||||
declare symbol_package_name="${product_name}-Symbol-${package_version_name}.tar.gz"
|
||||
declare sha256_name="${product_name}-Server-${package_version_name}.sha256"
|
||||
|
||||
@ -71,7 +71,6 @@ function target_file_copy()
|
||||
echo "End generate ${kernel_package_name} tar file" >> "$LOG_FILE" 2>&1
|
||||
|
||||
#generate sha256 file
|
||||
sha256_name="${package_pre_name}.sha256"
|
||||
echo "Begin generate ${sha256_name} sha256 file..." >> "$LOG_FILE" 2>&1
|
||||
sha256sum "${kernel_package_name}" | awk -F" " '{print $1}' > "$sha256_name"
|
||||
if [ $? -ne 0 ]; then
|
||||
|
||||
@ -21,7 +21,7 @@ function gaussdb_pkg_pre_clean()
|
||||
function read_gaussdb_version()
|
||||
{
|
||||
cd ${SCRIPT_DIR}
|
||||
echo "${product_name}-${version_number}" > version.cfg
|
||||
echo "${product_name}-Server-${version_number}" > version.cfg
|
||||
#auto read the number from kernal globals.cpp, no need to change it here
|
||||
}
|
||||
|
||||
@ -30,6 +30,7 @@ ROACH_DIR="${ROOT_DIR}/distribute/bin/roach"
|
||||
MPPDB_DECODING_DIR="${ROOT_DIR}/contrib/mppdb_decoding"
|
||||
XLOG_DUMP_DIR="${ROOT_DIR}/contrib/pg_xlogdump"
|
||||
PAGE_HACK_DIR="${ROOT_DIR}/contrib/pagehack"
|
||||
ARCH_CLEAN_DIR="${ROOT_DIR}/contrib/pg_archivecleanup"
|
||||
|
||||
|
||||
###################################
|
||||
@ -46,16 +47,9 @@ function read_gaussdb_number()
|
||||
version_num=$(echo $version_num1 | tr -d ";")
|
||||
#remove the blank
|
||||
version_num=$(echo $version_num)
|
||||
|
||||
if echo $version_num | grep -qE '^92[0-9]+$'
|
||||
then
|
||||
# get the last three number
|
||||
latter=${version_num:2}
|
||||
echo "92.${latter}" >>${SCRIPT_DIR}/version.cfg
|
||||
else
|
||||
echo "Cannot get the version number from globals.cpp."
|
||||
exit 1
|
||||
fi
|
||||
form=${version_num:0:2}
|
||||
latter=${version_num:2}
|
||||
echo "${form}.${latter}" >>${SCRIPT_DIR}/version.cfg
|
||||
}
|
||||
|
||||
#######################################################################
|
||||
@ -70,6 +64,15 @@ function get_kernel_commitid()
|
||||
echo "End insert commitid into version.cfg" >> "$LOG_FILE" 2>&1
|
||||
}
|
||||
|
||||
#######################################################################
|
||||
##insert the version mode to version.cfg
|
||||
#######################################################################
|
||||
function get_version_mode()
|
||||
{
|
||||
echo "$version_mode" >> ${SCRIPT_DIR}/version.cfg
|
||||
echo "End insert version mode into version cfg" >> "$LOG_FILE" 2>&1
|
||||
}
|
||||
|
||||
#######################################################################
|
||||
## generate the version file.
|
||||
#######################################################################
|
||||
@ -161,7 +164,7 @@ function install_gaussdb()
|
||||
GAUSSDB_EXTRA_FLAGS=" "
|
||||
|
||||
if [[ "$PLATFORM_ARCH"x == "x86_64"x || "$PLATFORM_ARCH"x == "aarch64"x ]] ; then
|
||||
extra_config_opt+=" --enable-mot --enable-bbox "
|
||||
extra_config_opt+=" --enable-mot --enable-bbox --enable-htap"
|
||||
fi
|
||||
|
||||
if [ "$PLATFORM_ARCH"x = "loongarch64"x ] ; then
|
||||
@ -237,7 +240,7 @@ function install_gaussdb()
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
cd "$ROOT_DIR/contrib/pg_upgrade_support"
|
||||
make clean >> "$LOG_FILE" 2>&1
|
||||
make -sj >> "$LOG_FILE" 2>&1
|
||||
@ -312,9 +315,16 @@ function install_gaussdb()
|
||||
make install -sj >> "$LOG_FILE" 2>&1
|
||||
echo "End make install pagehack" >> "$LOG_FILE" 2>&1
|
||||
|
||||
cd "$ARCH_CLEAN_DIR"
|
||||
make clean >> "$LOG_FILE" 2>&1
|
||||
make -sj >> "$LOG_FILE" 2>&1
|
||||
make install -sj >> "$LOG_FILE" 2>&1
|
||||
echo "End make install archivecleanup" >> "$LOG_FILE" 2>&1
|
||||
|
||||
chmod 444 ${BUILD_DIR}/bin/cluster_guc.conf
|
||||
dos2unix ${BUILD_DIR}/bin/cluster_guc.conf > /dev/null 2>&1
|
||||
get_kernel_commitid
|
||||
get_version_mode
|
||||
}
|
||||
|
||||
#######################################################################
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
[server]
|
||||
./bin/dsscmd
|
||||
./bin/dssserver
|
||||
./bin/dsstbox
|
||||
./bin/perctrl
|
||||
./bin/dms_contrl.sh
|
||||
./bin/dss_clear.sh
|
||||
@ -47,6 +48,7 @@
|
||||
./bin/gs_plan_simulator.sh
|
||||
./bin/pg_xlogdump
|
||||
./bin/pagehack
|
||||
./bin/pg_archivecleanup
|
||||
./bin/gs_assessment
|
||||
./bin/gs_retrieve
|
||||
./etc/kerberos/kadm5.acl
|
||||
@ -75,7 +77,7 @@
|
||||
./share/postgresql/extension/spqplugin.control
|
||||
./share/postgresql/extension/spqplugin--1.0.sql
|
||||
./share/postgresql/extension/dolphin.control
|
||||
./share/postgresql/extension/dolphin--4.0.sql
|
||||
./share/postgresql/extension/dolphin--5.0.sql
|
||||
./share/postgresql/extension/dolphin--1.0--1.1.sql
|
||||
./share/postgresql/extension/dolphin--1.1--1.0.sql
|
||||
./share/postgresql/extension/dolphin--1.1--2.0.sql
|
||||
@ -84,8 +86,12 @@
|
||||
./share/postgresql/extension/dolphin--3.0--2.0.sql
|
||||
./share/postgresql/extension/dolphin--3.0--4.0.sql
|
||||
./share/postgresql/extension/dolphin--4.0--3.0.sql
|
||||
./share/postgresql/extension/dolphin--4.0--5.0.sql
|
||||
./share/postgresql/extension/dolphin--5.0--4.0.sql
|
||||
./share/postgresql/extension/dolphin--2.0--2.0.1.sql
|
||||
./share/postgresql/extension/dolphin--2.0.1--2.0.sql
|
||||
./share/postgresql/extension/dolphin--4.0--4.0.1.sql
|
||||
./share/postgresql/extension/dolphin--4.0.1--4.0.sql
|
||||
./share/postgresql/extension/whale.control
|
||||
./share/postgresql/extension/whale--1.0.sql
|
||||
./share/postgresql/extension/openGauss_expr_dolphin.ir
|
||||
|
||||
@ -34,7 +34,7 @@
|
||||
./share/postgresql/extension/security_plugin.control
|
||||
./share/postgresql/extension/security_plugin--1.0.sql
|
||||
./share/postgresql/extension/dolphin.control
|
||||
./share/postgresql/extension/dolphin--4.0.sql
|
||||
./share/postgresql/extension/dolphin--5.0.sql
|
||||
./share/postgresql/extension/dolphin--1.0--1.1.sql
|
||||
./share/postgresql/extension/dolphin--1.1--1.0.sql
|
||||
./share/postgresql/extension/dolphin--1.1--2.0.sql
|
||||
@ -43,8 +43,14 @@
|
||||
./share/postgresql/extension/dolphin--3.0--2.0.sql
|
||||
./share/postgresql/extension/dolphin--3.0--4.0.sql
|
||||
./share/postgresql/extension/dolphin--4.0--3.0.sql
|
||||
./share/postgresql/extension/dolphin--4.0--5.0.sql
|
||||
./share/postgresql/extension/dolphin--5.0--4.0.sql
|
||||
./share/postgresql/extension/dolphin--2.0--2.0.1.sql
|
||||
./share/postgresql/extension/dolphin--2.0.1--2.0.sql
|
||||
./share/postgresql/extension/dolphin--4.0--4.0.1.sql
|
||||
./share/postgresql/extension/dolphin--4.0.1--4.0.sql
|
||||
./share/postgresql/extension/gms_compress--1.0.sql
|
||||
./share/postgresql/extension/gms_compress.control
|
||||
./share/postgresql/extension/openGauss_expr_dolphin.ir
|
||||
./share/postgresql/extension/file_fdw--1.0.sql
|
||||
./share/postgresql/extension/plpgsql.control
|
||||
@ -57,6 +63,24 @@
|
||||
./share/postgresql/extension/hstore--1.0--1.1.sql
|
||||
./share/postgresql/extension/log_fdw--1.0.sql
|
||||
./share/postgresql/extension/log_fdw.control
|
||||
./share/postgresql/extension/gms_utility--1.0.sql
|
||||
./share/postgresql/extension/gms_utility.control
|
||||
./share/postgresql/extension/gms_output--1.0.sql
|
||||
./share/postgresql/extension/gms_output.control
|
||||
./share/postgresql/extension/gms_stats--1.0.sql
|
||||
./share/postgresql/extension/gms_stats.control
|
||||
./share/postgresql/extension/gms_profiler--1.0.sql
|
||||
./share/postgresql/extension/gms_profiler.control
|
||||
./share/postgresql/extension/gms_lob--1.0.sql
|
||||
./share/postgresql/extension/gms_lob.control
|
||||
./share/postgresql/extension/gms_sql--1.0.sql
|
||||
./share/postgresql/extension/gms_sql.control
|
||||
./share/postgresql/extension/gms_i18n--1.0.sql
|
||||
./share/postgresql/extension/gms_i18n.control
|
||||
./share/postgresql/extension/gms_inaddr--1.0.sql
|
||||
./share/postgresql/extension/gms_inaddr.control
|
||||
./share/postgresql/extension/gms_debug--1.0.sql
|
||||
./share/postgresql/extension/gms_debug.control
|
||||
./share/postgresql/timezone/GB-Eire
|
||||
./share/postgresql/timezone/Turkey
|
||||
./share/postgresql/timezone/Kwajalein
|
||||
@ -700,6 +724,8 @@
|
||||
./lib/libdcf.so
|
||||
./lib/libzstd.so*
|
||||
./lib/libcurl.so*
|
||||
./lib/libaws-cpp-sdk-core.so
|
||||
./lib/libaws-cpp-sdk-s3.so
|
||||
./lib/libxgboost.so
|
||||
./lib/libpagecompression.so*
|
||||
./lib/postgresql/latin2_and_win1250.so
|
||||
@ -738,10 +764,20 @@
|
||||
./lib/postgresql/proc_srclib
|
||||
./lib/postgresql/security_plugin.so
|
||||
./lib/postgresql/dolphin.so
|
||||
./lib/postgresql/gms_compress.so
|
||||
./lib/postgresql/pg_upgrade_support.so
|
||||
./lib/postgresql/latin2_and_win1250.so
|
||||
./lib/postgresql/euc2004_sjis2004.so
|
||||
./lib/postgresql/pgoutput.so
|
||||
./lib/postgresql/gms_utility.so
|
||||
./lib/postgresql/gms_output.so
|
||||
./lib/postgresql/gms_stats.so
|
||||
./lib/postgresql/gms_profiler.so
|
||||
./lib/postgresql/gms_lob.so
|
||||
./lib/postgresql/gms_sql.so
|
||||
./lib/postgresql/gms_i18n.so
|
||||
./lib/postgresql/gms_inaddr.so
|
||||
./lib/postgresql/gms_debug.so
|
||||
./lib/libxgboost.so
|
||||
./include/postgresql/server/postgres_ext.h
|
||||
./include/postgresql/server/pg_config_os.h
|
||||
@ -918,4 +954,4 @@
|
||||
./include/pqcomm.h
|
||||
./include/pqexpbuffer.h
|
||||
[version]
|
||||
6.0.0
|
||||
7.0.0-RC1
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
[server]
|
||||
./bin/dsscmd
|
||||
./bin/dssserver
|
||||
./bin/dsstbox
|
||||
./bin/perctrl
|
||||
./bin/dms_contrl.sh
|
||||
./bin/dss_clear.sh
|
||||
@ -48,6 +49,7 @@
|
||||
./bin/gs_plan_simulator.sh
|
||||
./bin/pg_xlogdump
|
||||
./bin/pagehack
|
||||
./bin/pg_archivecleanup
|
||||
./bin/gs_assessment
|
||||
./bin/gs_retrieve
|
||||
./etc/kerberos/kadm5.acl
|
||||
@ -76,7 +78,7 @@
|
||||
./share/postgresql/extension/spqplugin.control
|
||||
./share/postgresql/extension/spqplugin--1.0.sql
|
||||
./share/postgresql/extension/dolphin.control
|
||||
./share/postgresql/extension/dolphin--4.0.sql
|
||||
./share/postgresql/extension/dolphin--5.0.sql
|
||||
./share/postgresql/extension/dolphin--1.0--1.1.sql
|
||||
./share/postgresql/extension/dolphin--1.1--1.0.sql
|
||||
./share/postgresql/extension/dolphin--1.1--2.0.sql
|
||||
@ -85,13 +87,21 @@
|
||||
./share/postgresql/extension/dolphin--3.0--2.0.sql
|
||||
./share/postgresql/extension/dolphin--3.0--4.0.sql
|
||||
./share/postgresql/extension/dolphin--4.0--3.0.sql
|
||||
./share/postgresql/extension/dolphin--4.0--5.0.sql
|
||||
./share/postgresql/extension/dolphin--5.0--4.0.sql
|
||||
./share/postgresql/extension/dolphin--2.0--2.0.1.sql
|
||||
./share/postgresql/extension/dolphin--2.0.1--2.0.sql
|
||||
./share/postgresql/extension/dolphin--4.0--4.0.1.sql
|
||||
./share/postgresql/extension/dolphin--4.0.1--4.0.sql
|
||||
./share/postgresql/extension/openGauss_expr_dolphin.ir
|
||||
./share/postgresql/extension/age--1.0.0.sql
|
||||
./share/postgresql/extension/age.control
|
||||
./share/postgresql/extension/datavec--0.4.4.sql
|
||||
./share/postgresql/extension/timescaledb.control
|
||||
./share/postgresql/extension/timescaledb--1.7.4.sql
|
||||
./share/postgresql/extension/datavec--1.0.sql
|
||||
./share/postgresql/extension/datavec.control
|
||||
./share/postgresql/extension/chparser--1.0.sql
|
||||
./share/postgresql/extension/chparser.control
|
||||
./share/postgresql/extension/assessment--1.0.sql
|
||||
./share/postgresql/extension/assessment.control
|
||||
./share/postgresql/extension/file_fdw--1.0.sql
|
||||
@ -112,12 +122,30 @@
|
||||
./share/postgresql/extension/dblink--1.0.sql
|
||||
./share/postgresql/extension/dblink--unpackaged--1.0.sql
|
||||
./share/postgresql/extension/dblink.control
|
||||
./share/postgresql/extension/gms_compress--1.0.sql
|
||||
./share/postgresql/extension/gms_compress.control
|
||||
./share/postgresql/extension/gms_utility--1.0.sql
|
||||
./share/postgresql/extension/gms_utility.control
|
||||
./share/postgresql/extension/gms_output--1.0.sql
|
||||
./share/postgresql/extension/gms_output.control
|
||||
./share/postgresql/extension/gms_inaddr--1.0.sql
|
||||
./share/postgresql/extension/gms_inaddr.control
|
||||
./share/postgresql/extension/gms_lob--1.0.sql
|
||||
./share/postgresql/extension/gms_lob.control
|
||||
./share/postgresql/extension/gms_stats--1.0.sql
|
||||
./share/postgresql/extension/gms_stats.control
|
||||
./share/postgresql/extension/gms_tcp--1.0.sql
|
||||
./share/postgresql/extension/gms_tcp.control
|
||||
./share/postgresql/extension/gms_profiler--1.0.sql
|
||||
./share/postgresql/extension/gms_profiler.control
|
||||
./share/postgresql/extension/gms_debug--1.0.sql
|
||||
./share/postgresql/extension/gms_debug.control
|
||||
./share/postgresql/extension/gms_sql--1.0.sql
|
||||
./share/postgresql/extension/gms_sql.control
|
||||
./share/postgresql/extension/gms_xmlgen--1.0.sql
|
||||
./share/postgresql/extension/gms_xmlgen.control
|
||||
./share/postgresql/extension/gms_i18n--1.0.sql
|
||||
./share/postgresql/extension/gms_i18n.control
|
||||
./share/postgresql/timezone/GB-Eire
|
||||
./share/postgresql/timezone/Turkey
|
||||
./share/postgresql/timezone/Kwajalein
|
||||
@ -730,6 +758,7 @@
|
||||
./share/postgresql/tsearch_data/swedish.stop
|
||||
./share/postgresql/tsearch_data/ispell_sample.dict
|
||||
./share/postgresql/tsearch_data/italian.stop
|
||||
./share/postgresql/tsearch_data/dict.utf8.xdb
|
||||
./share/postgresql/information_schema.sql
|
||||
./share/postgresql/timezonesets/Antarctica.txt
|
||||
./share/postgresql/timezonesets/Australia.txt
|
||||
@ -803,18 +832,31 @@
|
||||
./lib/postgresql/pg_plugin
|
||||
./lib/postgresql/proc_srclib
|
||||
./lib/postgresql/security_plugin.so
|
||||
./lib/postgresql/timescaledb-1.7.4.so
|
||||
./lib/postgresql/timescaledb.so
|
||||
./lib/postgresql/timescaledb-tsl-1.7.4.so
|
||||
./lib/postgresql/dolphin.so
|
||||
./lib/postgresql/age.so
|
||||
./lib/postgresql/datavec.so
|
||||
./lib/postgresql/chparser.so
|
||||
./lib/postgresql/pg_upgrade_support.so
|
||||
./lib/postgresql/java/pljava.jar
|
||||
./lib/postgresql/postgres_fdw.so
|
||||
./lib/postgresql/dblink.so
|
||||
./lib/postgresql/gms_utility.so
|
||||
./lib/postgresql/gms_lob.so
|
||||
./lib/postgresql/gms_stats.so
|
||||
./lib/postgresql/gms_tcp.so
|
||||
./lib/postgresql/pgoutput.so
|
||||
./lib/postgresql/assessment.so
|
||||
./lib/postgresql/gms_compress.so
|
||||
./lib/postgresql/gms_output.so
|
||||
./lib/postgresql/gms_inaddr.so
|
||||
./lib/postgresql/gms_profiler.so
|
||||
./lib/postgresql/gms_sql.so
|
||||
./lib/postgresql/gms_xmlgen.so
|
||||
./lib/postgresql/gms_i18n.so
|
||||
./lib/postgresql/gms_debug.so
|
||||
./lib/libpljava.so
|
||||
./lib/libpq.a
|
||||
./lib/libpq.so
|
||||
@ -832,9 +874,7 @@
|
||||
./lib/libecpg.a
|
||||
./lib/libecpg_compat.a
|
||||
./lib/libpgtypes.a
|
||||
./lib/libpgtypes.so
|
||||
./lib/libpgtypes.so.3
|
||||
./lib/libpgtypes.so.3.4
|
||||
./lib/libpgtypes.so*
|
||||
./lib/libgauss_cl_jni.so
|
||||
./lib/libcgroup.so*
|
||||
./lib/libcom_err_gauss.so*
|
||||
@ -868,6 +908,8 @@
|
||||
./lib/krb5/plugins/kdb/db2.so
|
||||
./lib/libverto.so*
|
||||
./lib/libcurl.so*
|
||||
./lib/libaws-cpp-sdk-core.so
|
||||
./lib/libaws-cpp-sdk-s3.so
|
||||
./lib/libcrypto.so*
|
||||
./lib/libssl.so*
|
||||
./lib/libgcc_s.so.1
|
||||
|
||||
@ -198,7 +198,7 @@ ENDMACRO(CHECK_CC_ENABLE)
|
||||
|
||||
function(GET_VERSIONSTR_FROMGIT ret)
|
||||
set(PG_VERSION "9.2.4")
|
||||
set(OPENGAUSS_VERSION "6.0.0")
|
||||
set(OPENGAUSS_VERSION "7.0.0-RC1")
|
||||
execute_process(
|
||||
COMMAND ${CMAKE_SOURCE_DIR}/${openGauss}/cmake/src/buildfunction.sh --s ${PROJECT_TRUNK_DIR} OUTPUT_VARIABLE GS_VERSION_STR)
|
||||
set(PG_VERSION "${PG_VERSION}" PARENT_SCOPE)
|
||||
|
||||
@ -69,6 +69,7 @@ option(BUILD_BY_CMAKE "the BUILD_BY_CMAKE is new,used in distribute pg_regress.c
|
||||
option(DEBUG_UHEAP "collect USTORE statistics" OFF)
|
||||
option(MAX_ALLOC_SEGNUM "max alloc xlog seg num in extreme_rto" 4)
|
||||
option(USE_TASSL "build with tassl, the old is --with-tassl" OFF)#ON
|
||||
option(ENABLE_HTAP "enable HTAP in single/distribute mode,the old is --enable-htap" ON)
|
||||
|
||||
#No matter what to set, the old mppdb aways use ENABLE_THREAD_SAFETY=yes by default defined.
|
||||
option(ENABLE_THREAD_SAFETY "enable thread safety, the old is --enable-thread-safety" ON)
|
||||
@ -176,7 +177,7 @@ else()
|
||||
endif()
|
||||
|
||||
# libraries need secure options during compling
|
||||
set(LIB_SECURE_OPTIONS -fPIC -fno-common -fstack-protector)
|
||||
set(LIB_SECURE_OPTIONS -fPIC -fno-common -fstack-protector-strong)
|
||||
# libraries need link options during linking
|
||||
set(LIB_LINK_OPTIONS -pthread -std=c++14 -Wl,-z,noexecstack -Wl,-z,relro,-z,now)
|
||||
if(NOT "${ENABLE_UT}" STREQUAL "ON")
|
||||
@ -233,6 +234,10 @@ if(${USE_SPQ})
|
||||
set(GAUSSDB_CONFIGURE "${GAUSSDB_CONFIGURE} -DUSE_SPQ")
|
||||
endif()
|
||||
|
||||
if(${ENABLE_HTAP})
|
||||
set(GAUSSDB_CONFIGURE "${GAUSSDB_CONFIGURE} -DENABLE_HTAP")
|
||||
endif()
|
||||
|
||||
if(${USE_LDAP})
|
||||
set(HAVE_LIBLDAP 1)
|
||||
set(LIBS "${LIBS} -lldap")
|
||||
|
||||
@ -714,7 +714,7 @@
|
||||
#define PGXC_VERSION_NUM
|
||||
|
||||
/* openGauss version as a number string */
|
||||
#define OPENGAUSS_VERSION_NUM_STR "6.0.0"
|
||||
#define OPENGAUSS_VERSION_NUM_STR "7.0.0-RC1"
|
||||
|
||||
/* A string containing the version number, platform, and C compiler */
|
||||
#define PG_VERSION_STR "@PG_VERSION_STR@"
|
||||
@ -948,4 +948,8 @@
|
||||
|
||||
/* Define to 1 if you want to build opengauss rpm package on openeuler os.
|
||||
* (--with-openeuler-os) */
|
||||
#cmakedefine WITH_OPENEULER_OS
|
||||
#cmakedefine WITH_OPENEULER_OS
|
||||
|
||||
/* Define to 1 if you want to use htap
|
||||
* --enable-htap */
|
||||
#cmakedefine ENABLE_HTAP
|
||||
@ -695,7 +695,7 @@
|
||||
#define PG_VERSION "9.2.4"
|
||||
|
||||
/* openGauss version as a string */
|
||||
#define OPENGAUSS_VERSION "6.0.0"
|
||||
#define OPENGAUSS_VERSION "7.0.0-RC1"
|
||||
|
||||
/* Gaussdb version as a string*/
|
||||
#define DEF_GS_VERSION "(GaussDB A 8.0.0 build 21f07aff) compiled at 2020-03-17 10:59:07 commit 7431 last mr 12039 debug"
|
||||
|
||||
@ -61,6 +61,7 @@ set(LLVM_HOME ${DEPENDENCY_PATH}/llvm/${LIB_UNIFIED_SUPPORT})
|
||||
set(LZ4_HOME ${DEPENDENCY_PATH}/lz4/${SUPPORT_LLT})
|
||||
set(NANOMSG_HOME ${DEPENDENCY_PATH}/nng/${LIB_UNIFIED_SUPPORT})
|
||||
set(NCURSES_HOME ${DEPENDENCY_PATH}/ncurses/${SUPPORT_LLT})
|
||||
set(AWSSDK_HOME ${DEPENDENCY_PATH}/aws-sdk-cpp/${SUPPORT_LLT})
|
||||
if(($ENV{WITH_TASSL}) STREQUAL "YES")
|
||||
set(OPENSSL_HOME ${DEPENDENCY_PATH}/tassl/${LIB_UNIFIED_SUPPORT})
|
||||
else()
|
||||
@ -193,6 +194,12 @@ set(LIBCGROUP_LIB_PATH ${CGROUP_HOME}/lib)
|
||||
set(LIBCURL_INCLUDE_PATH ${CURL_HOME}/include)
|
||||
set(LIBCURL_LIB_PATH ${CURL_HOME}/lib)
|
||||
|
||||
#############################################################################
|
||||
# awssdk component
|
||||
#############################################################################
|
||||
set(AWSSDK_INCLUDE_PATH ${AWSSDK_HOME}/include)
|
||||
set(AWSSDK_LIB_PATH ${AWSSDK_HOME}/lib)
|
||||
|
||||
#############################################################################
|
||||
# edit component
|
||||
#############################################################################
|
||||
|
||||
43
configure
vendored
43
configure
vendored
@ -758,6 +758,7 @@ enable_lite_mode
|
||||
enable_relocation
|
||||
enable_finance_mode
|
||||
enable_mot
|
||||
enable_htap
|
||||
enable_bbox
|
||||
enable_memory_check
|
||||
enable_mysql_fdw
|
||||
@ -847,6 +848,7 @@ enable_lite_mode
|
||||
enable_relocation
|
||||
enable_finance_mode
|
||||
enable_mot
|
||||
enable_htap
|
||||
enable_bbox
|
||||
enable_memory_check
|
||||
enable_mysql_fdw
|
||||
@ -1560,6 +1562,7 @@ Optional Features:
|
||||
--enable-memory-check build with memory checking feature
|
||||
--disable-spinlocks do not use spinlocks
|
||||
--enable-debug build with debugging symbols (-g)
|
||||
--enable-htap enable htap feture
|
||||
--enable-qunit enable query driven unit test framework(QUnit)
|
||||
--enable-profiling build with profiling enabled
|
||||
--enable-coverage build with coverage testing instrumentation
|
||||
@ -2209,7 +2212,7 @@ PACKAGE_VERSION='9.2.4'
|
||||
# Postgres-XC 1.1devel is based on PostgreSQL 9.2.4
|
||||
PACKAGE_XC_VERSION='1.1'
|
||||
# openGauss is based on PostgreSQL 9.2.4 and it will be the Kernel of GaussDB database
|
||||
OPENGAUSS_VERSION='6.0.0'
|
||||
OPENGAUSS_VERSION='7.0.0-RC1'
|
||||
|
||||
cat >>confdefs.h <<_ACEOF
|
||||
#define PG_VERSION "$PACKAGE_VERSION"
|
||||
@ -3337,6 +3340,40 @@ else
|
||||
|
||||
fi
|
||||
|
||||
# Check whether --enable-htap was given.
|
||||
if test "${enable_htap+set}" = set; then
|
||||
enableval=$enable_htap;
|
||||
case $enableval in
|
||||
yes)
|
||||
|
||||
cat >>confdefs.h <<\_ACEOF
|
||||
#define ENABLE_HTAP 1
|
||||
_ACEOF
|
||||
|
||||
;;
|
||||
no)
|
||||
:
|
||||
;;
|
||||
*)
|
||||
{ { $as_echo "$as_me:$LINENO: error: no argument expected for --enable-htap option" >&5
|
||||
$as_echo "$as_me: error: no argument expected for --enable-htap option" >&2;}
|
||||
{ (exit 1); exit 1; }; }
|
||||
;;
|
||||
esac
|
||||
|
||||
else
|
||||
enable_htap=no
|
||||
|
||||
fi
|
||||
|
||||
if test "$enable_htap" = yes; then
|
||||
|
||||
cat >>confdefs.h <<\_ACEOF
|
||||
#define ENABLE_HTAP 1
|
||||
_ACEOF
|
||||
|
||||
fi
|
||||
|
||||
if test "$enable_bbox" = yes; then
|
||||
|
||||
cat >>confdefs.h <<\_ACEOF
|
||||
@ -3391,6 +3428,10 @@ if [[ "$(cat /etc/system-release)" =~ ^"openEuler release 22.03".* ]]; then
|
||||
with_openeuler_major=yes
|
||||
fi
|
||||
|
||||
if [[ "$(cat /etc/system-release)" =~ ^"openEuler release 24.03".* ]]; then
|
||||
with_openeuler_major=yes
|
||||
fi
|
||||
|
||||
if [[ "$(cat /etc/system-release)" =~ ^"CSIOS release 1.0".* ]]; then
|
||||
with_openeuler_major=yes
|
||||
fi
|
||||
|
||||
@ -16,6 +16,7 @@ set(CMAKE_MODULE_PATH
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/pg_upgrade_support
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/postgres_fdw
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/gms_output
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/gms_inaddr
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/security_plugin
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/dummy_seclabel
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/pagehack
|
||||
@ -25,10 +26,33 @@ set(CMAKE_MODULE_PATH
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/gc_fdw
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/ndpplugin
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/spq_plugin
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/datavec
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/chparser
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/gms_stats
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/gms_utility
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/gms_profiler
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/gms_lob
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/gms_sql
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/gms_tcp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/gms_i18n
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/gms_debug
|
||||
|
||||
)
|
||||
|
||||
if(NOT "${ENABLE_LITE_MODE}" STREQUAL "ON")
|
||||
INCLUDE_DIRECTORIES(${LIBODBC_INCLUDE_PATH})
|
||||
INCLUDE_DIRECTORIES(${LIBODBC_LIB_PATH})
|
||||
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/dblink)
|
||||
add_subdirectory(dblink)
|
||||
endif()
|
||||
|
||||
if("${USE_LIBXML}" STREQUAL "ON")
|
||||
INCLUDE_DIRECTORIES(${LIBXML_INCLUDE_PATH}/libxml2)
|
||||
INCLUDE_DIRECTORIES(${LIBXML_LIB_PATH})
|
||||
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/gms_xmlgen)
|
||||
add_subdirectory(gms_xmlgen)
|
||||
endif()
|
||||
|
||||
add_subdirectory(hstore)
|
||||
add_subdirectory(test_decoding)
|
||||
add_subdirectory(mppdb_decoding)
|
||||
@ -39,13 +63,18 @@ if("${ENABLE_MULTIPLE_NODES}" STREQUAL "ON" OR "${ENABLE_PRIVATEGAUSS}" STREQUAL
|
||||
endif()
|
||||
add_subdirectory(postgres_fdw)
|
||||
add_subdirectory(gms_output)
|
||||
add_subdirectory(gms_inaddr)
|
||||
add_subdirectory(security_plugin)
|
||||
add_subdirectory(dummy_seclabel)
|
||||
add_subdirectory(pagehack)
|
||||
add_subdirectory(pg_xlogdump)
|
||||
add_subdirectory(file_fdw)
|
||||
add_subdirectory(log_fdw)
|
||||
add_subdirectory(gms_utility)
|
||||
add_subdirectory(gms_stats)
|
||||
add_subdirectory(gms_sql)
|
||||
add_subdirectory(gms_tcp)
|
||||
add_subdirectory(gms_debug)
|
||||
if("${ENABLE_MULTIPLE_NODES}" STREQUAL "OFF")
|
||||
add_subdirectory(gc_fdw)
|
||||
endif()
|
||||
@ -53,4 +82,12 @@ add_subdirectory(ndpplugin)
|
||||
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/spq_plugin)
|
||||
add_subdirectory(spq_plugin)
|
||||
endif()
|
||||
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/datavec)
|
||||
add_subdirectory(datavec)
|
||||
endif()
|
||||
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/chparser)
|
||||
add_subdirectory(chparser)
|
||||
endif()
|
||||
add_subdirectory(gms_profiler)
|
||||
add_subdirectory(gms_lob)
|
||||
add_subdirectory(gms_i18n)
|
||||
|
||||
@ -57,8 +57,15 @@ SUBDIRS = \
|
||||
vacuumlo \
|
||||
security_plugin \
|
||||
ndpplugin \
|
||||
gms_utility \
|
||||
gms_profiler \
|
||||
gms_output
|
||||
gms_inaddr \
|
||||
gms_output \
|
||||
gms_stats \
|
||||
gms_lob \
|
||||
gms_sql \
|
||||
gms_i18n \
|
||||
gms_debug
|
||||
|
||||
ifeq ($(with_openssl),yes)
|
||||
SUBDIRS += sslinfo
|
||||
@ -68,8 +75,10 @@ endif
|
||||
|
||||
ifeq ($(with_libxml),yes)
|
||||
SUBDIRS += xml2
|
||||
SUBDIRS += gms_xmlgen
|
||||
else
|
||||
ALWAYS_SUBDIRS += xml2
|
||||
ALWAYS_SUBDIRS += gms_xmlgen
|
||||
endif
|
||||
|
||||
ifeq ($(with_selinux),yes)
|
||||
|
||||
14
contrib/common_cipher/Makefile
Executable file
14
contrib/common_cipher/Makefile
Executable file
@ -0,0 +1,14 @@
|
||||
# contrib/common_cipher/Makefile
|
||||
|
||||
SRCS = common_err.cpp common_utils.cpp common_algo.cpp common_internal_interfaces.cpp common_cipher.cpp
|
||||
|
||||
MODULE_big = common_cipher
|
||||
OBJS = $(SRCS:.cpp=.o)
|
||||
|
||||
subdir = contrib/common_cipher
|
||||
top_builddir = ../..
|
||||
include $(top_builddir)/src/Makefile.global
|
||||
include $(top_srcdir)/contrib/contrib-global.mk
|
||||
|
||||
override CPPFLAGS := -fPIC -shared
|
||||
override CFLAGS := -fPIC -shared
|
||||
18
contrib/common_cipher/README.md
Normal file
18
contrib/common_cipher/README.md
Normal file
@ -0,0 +1,18 @@
|
||||
动态库使用说明:
|
||||
a.硬件动态库中目前适配的三种硬件信息如下:
|
||||
三未信安密钥管理系统,型号SYT1306
|
||||
江南天安密钥管理系统,型号SJJ1988
|
||||
光电安辰PCI-E密码卡,型号TOEC-GMPCIE01
|
||||
|
||||
b.硬件动态库使用需要配置的入参
|
||||
指定所使用的硬件,必须项,取值范围["GDACCARD" "JNTAKMS" "SWXAKMS"]。
|
||||
指定具体硬件提供so所在路径,必须项。
|
||||
硬件配置文件所在路径:密钥管理系统需要配置此变量,指定kms的配置文件路径,可选项。
|
||||
江南天安配置文件只需要传入路径,三未信安需要带配置文件名称。
|
||||
配置示例:
|
||||
MODULE_TYPE=GDACCARD,MODULE_LIB_PATH=/home/lib/libsdf.so
|
||||
MODULE_TYPE=JNTAKMS,MODULE_LIB_PATH=/home/lib/libsdf.so,MODULE_CONFIG_FILE_PATH=/home/etc/
|
||||
MODULE_TYPE=SWXAKMS,MODULE_LIB_PATH=/home/lib/libsdf.so,MODULE_CONFIG_FILE_PATH=/home/etc/xxx.ini
|
||||
|
||||
使用具体的接口详见:common_cipher.h
|
||||
|
||||
300
contrib/common_cipher/common_algo.cpp
Executable file
300
contrib/common_cipher/common_algo.cpp
Executable file
@ -0,0 +1,300 @@
|
||||
#include "common_algo.h"
|
||||
#include "common_cipher.h"
|
||||
#include "common_err.h"
|
||||
#include "common_utils.h"
|
||||
|
||||
#define SUPPORTED 1
|
||||
#define UNSUPPORTED 0
|
||||
|
||||
|
||||
static void set_gdac_supported_feature(SupportedFeature *supported_feature)
|
||||
{
|
||||
memcpy(supported_feature->provider_name, MODULE_GDAC_CARD_STR, strlen(MODULE_GDAC_CARD_STR));
|
||||
|
||||
/*光电安辰提供了扩展的生成内部KEK接口,可以支持索引*/
|
||||
supported_feature->key_type = KEY_TYPE_NAMEORIDX;
|
||||
|
||||
supported_feature->supported_symm[MODULE_AES_128_CBC] = SUPPORTED;
|
||||
supported_feature->supported_symm[MODULE_AES_256_CBC] = SUPPORTED;
|
||||
supported_feature->supported_symm[MODULE_SM4_CBC] = SUPPORTED;
|
||||
supported_feature->supported_symm[MODULE_HMAC_SHA256] = SUPPORTED;
|
||||
supported_feature->supported_symm[MODULE_HMAC_SM3] = SUPPORTED;
|
||||
supported_feature->supported_symm[MODULE_DETERMINISTIC_KEY] = SUPPORTED;
|
||||
|
||||
supported_feature->supported_digest[MODULE_SHA256] = SUPPORTED;
|
||||
supported_feature->supported_digest[MODULE_SM3] = SUPPORTED;
|
||||
}
|
||||
|
||||
static void set_swxa_supported_feature(SupportedFeature *supported_feature)
|
||||
{
|
||||
memcpy(supported_feature->provider_name, MODULE_SWXA_KMS_STR, strlen(MODULE_SWXA_KMS_STR));
|
||||
|
||||
/*三未信安提供了生成密钥密文的接口,可以支持密钥密文。*/
|
||||
supported_feature->key_type = KEY_TYPE_CIPHERTEXT;
|
||||
|
||||
supported_feature->supported_symm[MODULE_AES_128_CBC] = SUPPORTED;
|
||||
supported_feature->supported_symm[MODULE_AES_256_CBC] = SUPPORTED;
|
||||
supported_feature->supported_symm[MODULE_SM4_CBC] = SUPPORTED;
|
||||
supported_feature->supported_symm[MODULE_AES_128_CTR] = SUPPORTED;
|
||||
supported_feature->supported_symm[MODULE_AES_256_CTR] = SUPPORTED;
|
||||
supported_feature->supported_symm[MODULE_SM4_CTR] = SUPPORTED;
|
||||
supported_feature->supported_symm[MODULE_HMAC_SHA256] = SUPPORTED;
|
||||
supported_feature->supported_symm[MODULE_HMAC_SM3] = SUPPORTED;
|
||||
supported_feature->supported_symm[MODULE_DETERMINISTIC_KEY] = SUPPORTED;
|
||||
|
||||
supported_feature->supported_digest[MODULE_SHA256] = SUPPORTED;
|
||||
supported_feature->supported_digest[MODULE_SM3] = SUPPORTED;
|
||||
}
|
||||
|
||||
|
||||
static void set_jnta_supported_feature(SupportedFeature *supported_feature)
|
||||
{
|
||||
memcpy(supported_feature->provider_name, MODULE_JNTA_KMS_STR, strlen(MODULE_JNTA_KMS_STR));
|
||||
|
||||
/*江南天安提供了生成密钥密文和导入密钥密文到指定索引的接口,可以支持密钥索引。*/
|
||||
supported_feature->key_type = KEY_TYPE_NAMEORIDX;
|
||||
|
||||
supported_feature->supported_symm[MODULE_AES_128_CBC] = SUPPORTED;
|
||||
supported_feature->supported_symm[MODULE_AES_256_CBC] = SUPPORTED;
|
||||
supported_feature->supported_symm[MODULE_SM4_CBC] = SUPPORTED;
|
||||
supported_feature->supported_symm[MODULE_HMAC_SHA256] = SUPPORTED;
|
||||
supported_feature->supported_symm[MODULE_HMAC_SM3] = SUPPORTED;
|
||||
supported_feature->supported_symm[MODULE_DETERMINISTIC_KEY] = SUPPORTED;
|
||||
|
||||
supported_feature->supported_digest[MODULE_SHA256] = SUPPORTED;
|
||||
supported_feature->supported_digest[MODULE_SM3] = SUPPORTED;
|
||||
}
|
||||
|
||||
int get_supported_feature(ModuleType type, SupportedFeature *supported_feature)
|
||||
{
|
||||
if (supported_feature == NULL) {
|
||||
return CRYPTO_MOD_PARAM_INVALID_ERR;
|
||||
}
|
||||
|
||||
memset(supported_feature->provider_name, 0x0, MAX_PROVIDER_NAME_LEN);
|
||||
memset(supported_feature->supported_symm, UNSUPPORTED, sizeof(supported_feature->supported_symm));
|
||||
memset(supported_feature->supported_digest, UNSUPPORTED, sizeof(supported_feature->supported_digest));
|
||||
supported_feature->key_type = KEY_TYPE_INVALID;
|
||||
|
||||
switch (type) {
|
||||
case MODULE_GDAC_CARD_TYPE:
|
||||
set_gdac_supported_feature(supported_feature);
|
||||
break;
|
||||
case MODULE_JNTA_KMS_TYPE:
|
||||
set_jnta_supported_feature(supported_feature);
|
||||
break;
|
||||
case MODULE_SWXA_KMS_TYPE:
|
||||
set_swxa_supported_feature(supported_feature);
|
||||
break;
|
||||
default:
|
||||
return CRYPTO_MOD_TYPE_INVALID_ERR;
|
||||
}
|
||||
|
||||
return CRYPT_MOD_OK;
|
||||
}
|
||||
|
||||
static int get_gdac_symm_algo_type(ModuleSymmKeyAlgo symmalgotype, unsigned int* realtype)
|
||||
{
|
||||
switch (symmalgotype) {
|
||||
case MODULE_AES_128_CBC:
|
||||
*realtype = GDAC_AES128_CBC;
|
||||
break;
|
||||
case MODULE_AES_256_CBC:
|
||||
*realtype = GDAC_AES256_CBC;
|
||||
break;
|
||||
case MODULE_SM4_CBC:
|
||||
*realtype = GDAC_SM4_CBC;
|
||||
break;
|
||||
case MODULE_HMAC_SHA256:
|
||||
*realtype = GDAC_HMAC_SHA256;
|
||||
break;
|
||||
case MODULE_HMAC_SM3:
|
||||
*realtype = GDAC_HMAC_SM3;
|
||||
break;
|
||||
default:
|
||||
return CRYPTO_MOD_UNSUPPORTED_SYMM_TYPE_ERR;
|
||||
}
|
||||
|
||||
return CRYPT_MOD_OK;
|
||||
}
|
||||
|
||||
static int get_swxa_symm_algo_type(ModuleSymmKeyAlgo symmalgotype, unsigned int* realtype)
|
||||
{
|
||||
switch (symmalgotype) {
|
||||
case MODULE_AES_128_CBC:
|
||||
case MODULE_AES_256_CBC:
|
||||
*realtype = SWXA_AES_CBC;
|
||||
break;
|
||||
case MODULE_AES_128_CTR:
|
||||
case MODULE_AES_256_CTR:
|
||||
*realtype = SWXA_AES_CTR;
|
||||
break;
|
||||
case MODULE_SM4_CBC:
|
||||
*realtype = SWXA_SMS4_CBC;
|
||||
break;
|
||||
case MODULE_SM4_CTR:
|
||||
*realtype = SWXA_SMS4_CTR;
|
||||
break;
|
||||
case MODULE_HMAC_SHA256:
|
||||
*realtype = SWXA_SHA256;
|
||||
break;
|
||||
case MODULE_HMAC_SM3:
|
||||
*realtype = SWXA_SM3;
|
||||
break;
|
||||
default:
|
||||
return CRYPTO_MOD_UNSUPPORTED_SYMM_TYPE_ERR;
|
||||
}
|
||||
|
||||
return CRYPT_MOD_OK;
|
||||
}
|
||||
|
||||
static int get_jnta_symm_algo_type(ModuleSymmKeyAlgo symmalgotype, unsigned int* realtype, unsigned int* realmode)
|
||||
{
|
||||
switch (symmalgotype) {
|
||||
case MODULE_AES_128_CBC:
|
||||
*realtype = TA_AES128;
|
||||
*realmode = TA_CBC;
|
||||
break;
|
||||
case MODULE_AES_256_CBC:
|
||||
*realtype = TA_AES256;
|
||||
*realmode = TA_CBC;
|
||||
break;
|
||||
case MODULE_SM4_CBC:
|
||||
*realtype = TA_SM4;
|
||||
*realmode = TA_CBC;
|
||||
break;
|
||||
case MODULE_HMAC_SHA256:
|
||||
*realtype = TA_HMAC_SHA256;
|
||||
break;
|
||||
case MODULE_HMAC_SM3:
|
||||
*realtype = TA_HMAC_SM3;
|
||||
break;
|
||||
default:
|
||||
return CRYPTO_MOD_UNSUPPORTED_SYMM_TYPE_ERR;
|
||||
}
|
||||
|
||||
return CRYPT_MOD_OK;
|
||||
}
|
||||
|
||||
int get_real_symm_algo_type(ModuleType moduletype, ModuleSymmKeyAlgo symmalgotype, unsigned int* realtype, unsigned int* realmode)
|
||||
{
|
||||
/*严格加解密,不属于硬件密码模块内部算法类型,在库中直接自行处理*/
|
||||
if (symmalgotype == MODULE_DETERMINISTIC_KEY) {
|
||||
*realtype = MODULE_DETERMINISTIC_KEY;
|
||||
|
||||
return CRYPT_MOD_OK;
|
||||
}
|
||||
|
||||
switch (moduletype) {
|
||||
case MODULE_GDAC_CARD_TYPE:
|
||||
return get_gdac_symm_algo_type(symmalgotype, realtype);
|
||||
case MODULE_JNTA_KMS_TYPE:
|
||||
return get_jnta_symm_algo_type(symmalgotype, realtype, realmode);
|
||||
case MODULE_SWXA_KMS_TYPE:
|
||||
return get_swxa_symm_algo_type(symmalgotype, realtype);
|
||||
default:
|
||||
return CRYPTO_MOD_TYPE_INVALID_ERR;
|
||||
}
|
||||
|
||||
return CRYPT_MOD_OK;
|
||||
}
|
||||
|
||||
void transform_jnta_algo_type(unsigned int type, unsigned int mode, unsigned int *standardtype)
|
||||
{
|
||||
switch (type) {
|
||||
case TA_AES128:
|
||||
case TA_AES256:
|
||||
if (mode == TA_CBC) {
|
||||
*standardtype = TA_AES_CBC;
|
||||
}
|
||||
break;
|
||||
case TA_SM4:
|
||||
if (mode == TA_CBC) {
|
||||
*standardtype = TA_SM4_CBC;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static int get_gdac_digest_algo_type(ModuleDigestAlgo type, unsigned int* realtype)
|
||||
{
|
||||
switch (type) {
|
||||
case MODULE_SHA256:
|
||||
*realtype = GDAC_SHA256;
|
||||
break;
|
||||
case MODULE_SM3:
|
||||
*realtype = GDAC_SM3;
|
||||
break;
|
||||
default:
|
||||
return CRYPTO_MOD_UNSUPPORTED_DIGEST_TYPE_ERR;
|
||||
}
|
||||
|
||||
return CRYPT_MOD_OK;
|
||||
}
|
||||
|
||||
static int get_swxa_digest_algo_type(ModuleDigestAlgo type, unsigned int* realtype)
|
||||
{
|
||||
switch (type) {
|
||||
case MODULE_SHA256:
|
||||
*realtype = SWXA_SHA256;
|
||||
break;
|
||||
case MODULE_SM3:
|
||||
*realtype = SWXA_SM3;
|
||||
break;
|
||||
default:
|
||||
return CRYPTO_MOD_UNSUPPORTED_DIGEST_TYPE_ERR;
|
||||
}
|
||||
|
||||
return CRYPT_MOD_OK;
|
||||
}
|
||||
|
||||
static int get_jnta_digest_algo_type(ModuleDigestAlgo type, unsigned int* realtype)
|
||||
{
|
||||
switch (type) {
|
||||
case MODULE_SHA256:
|
||||
*realtype = TA_SHA256;
|
||||
break;
|
||||
case MODULE_SM3:
|
||||
*realtype = TA_SM3;
|
||||
break;
|
||||
default:
|
||||
return CRYPTO_MOD_UNSUPPORTED_DIGEST_TYPE_ERR;
|
||||
}
|
||||
|
||||
return CRYPT_MOD_OK;
|
||||
}
|
||||
|
||||
int get_real_digest_algo_type(ModuleType moduletype, ModuleDigestAlgo type, unsigned int* realtype)
|
||||
{
|
||||
switch (moduletype) {
|
||||
case MODULE_GDAC_CARD_TYPE:
|
||||
return get_gdac_digest_algo_type(type, realtype);
|
||||
case MODULE_JNTA_KMS_TYPE:
|
||||
return get_jnta_digest_algo_type(type, realtype);
|
||||
case MODULE_SWXA_KMS_TYPE:
|
||||
return get_swxa_digest_algo_type(type, realtype);
|
||||
default:
|
||||
return CRYPTO_MOD_TYPE_INVALID_ERR;
|
||||
}
|
||||
|
||||
return CRYPT_MOD_OK;
|
||||
}
|
||||
|
||||
int get_key_len_by_algo_type(ModuleSymmKeyAlgo type)
|
||||
{
|
||||
switch (type) {
|
||||
case MODULE_AES_128_CBC:
|
||||
case MODULE_AES_128_CTR:
|
||||
case MODULE_SM4_CBC:
|
||||
case MODULE_SM4_CTR:
|
||||
return INTERNAL_KEY_128_BITS;
|
||||
case MODULE_AES_256_CBC:
|
||||
case MODULE_AES_256_CTR:
|
||||
return INTERNAL_KEY_256_BITS;
|
||||
default:
|
||||
return INTERNAL_KEY_128_BITS;
|
||||
}
|
||||
|
||||
}
|
||||
124
contrib/common_cipher/common_algo.h
Executable file
124
contrib/common_cipher/common_algo.h
Executable file
@ -0,0 +1,124 @@
|
||||
#ifndef COMMON_ALGO_H
|
||||
#define COMMON_ALGO_H
|
||||
|
||||
#include "common_cipher.h"
|
||||
#include "common_utils.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*密钥索引最大值1024,最小值1*/
|
||||
|
||||
#define INTERNAL_MIN_INDEX_NUM 1
|
||||
#define INTERNAL_MAX_INDEX_NUM 1024
|
||||
|
||||
/*光电安辰相关宏定义*/
|
||||
|
||||
/*光电安辰卡内密钥类型*/
|
||||
#define GDAC_KEK_TYPE 9
|
||||
|
||||
/*光电安辰卡内密钥状态*/
|
||||
#define GDAC_KEY_EXIST 0x100000
|
||||
#define GDAC_KEY_NOT_EXIST 0
|
||||
|
||||
|
||||
/*对称算法模式*/
|
||||
#define GDAC_MODE_CBC 0x00000002
|
||||
|
||||
/*对称算法类型*/
|
||||
#define GDAC_SM4 0x00000400
|
||||
#define GDAC_AES128 0x00004000
|
||||
#define GDAC_AES256 0x00008000
|
||||
|
||||
/*对称算法及模式*/
|
||||
#define GDAC_SM4_CBC (GDAC_SM4|GDAC_MODE_CBC)
|
||||
#define GDAC_AES128_CBC (GDAC_AES128|GDAC_MODE_CBC)
|
||||
#define GDAC_AES256_CBC (GDAC_AES256|GDAC_MODE_CBC)
|
||||
|
||||
/*摘要算法*/
|
||||
#define GDAC_SM3 0x00000001
|
||||
#define GDAC_SHA256 0x00000004
|
||||
|
||||
/*HMAC算法*/
|
||||
#define GDAC_HMAC_SM3 0x00100001
|
||||
#define GDAC_HMAC_SHA256 0x00100004
|
||||
|
||||
/*三未信安相关宏定义*/
|
||||
|
||||
/*对称算法及模式*/
|
||||
#define SWXA_SMS4_CBC 0x00000402
|
||||
#define SWXA_SMS4_CTR 0x00000420
|
||||
|
||||
#define SWXA_AES_CBC 0x00002002
|
||||
#define SWXA_AES_CTR 0x00002020
|
||||
|
||||
/*摘要算法,三未的hmac指定算法和摘要算法相同即可*/
|
||||
#define SWXA_SM3 0x00000001
|
||||
#define SWXA_SHA256 0x00000004
|
||||
|
||||
/*江南天安相关*/
|
||||
|
||||
typedef enum {
|
||||
TA_HMAC_SHA256 = 6,
|
||||
TA_HMAC_SM3 = 20,
|
||||
}TA_HMAC_ALG;
|
||||
|
||||
typedef enum {
|
||||
TA_AES128 = 3,
|
||||
TA_AES256 = 5,
|
||||
TA_SM4 = 7,
|
||||
}TA_SYMM_ALG;
|
||||
|
||||
typedef enum {
|
||||
TA_CBC = 1,
|
||||
}TA_SYMM_MODE;
|
||||
|
||||
typedef enum {
|
||||
TA_SM3 = 1,
|
||||
TA_SHA256 = 4,
|
||||
}TA_HASH_ALG;
|
||||
|
||||
|
||||
#define TA_SM4_CBC 0X00000402
|
||||
#define TA_AES_CBC 0x80000202
|
||||
|
||||
/*内部通用宏定义*/
|
||||
#define INTERNAL_DO_ENC 1
|
||||
#define INTERNAL_DO_DEC 0
|
||||
|
||||
#define INTERNAL_MAX_KEY_LEN 32
|
||||
|
||||
#define INTERNAL_BLOCK_LEN 16
|
||||
|
||||
#define INTERNAL_IV_LEN 16
|
||||
|
||||
#define INTERNAL_HMAC_LEN 32
|
||||
|
||||
#define INTERNAL_MSG_BLOCK_LEN 8192
|
||||
|
||||
#define INTERNAL_KEY_128_BITS 128
|
||||
#define INTERNAL_KEY_256_BITS 256
|
||||
|
||||
|
||||
typedef struct {
|
||||
void *session; /*和硬件建立的会话*/
|
||||
unsigned int algotype; /*算法类型*/
|
||||
unsigned int algomode; /*算法模式,江南天安使用;光电安辰和三未信安algotype已包含模式*/
|
||||
int enc; /*0表示解密,1表示加密*/
|
||||
unsigned int keysize; /*key的长度*/
|
||||
unsigned char key[INTERNAL_MAX_KEY_LEN]; /*存储密钥id/密钥密文值/密钥明文值,AES256密钥长度32*/
|
||||
}InternalKeyCtx;
|
||||
|
||||
|
||||
extern int get_supported_feature(ModuleType type, SupportedFeature *supported_feature);
|
||||
extern int get_real_symm_algo_type(ModuleType moduletype, ModuleSymmKeyAlgo symmalgotype, unsigned int* realtype, unsigned int* realmode);
|
||||
extern int get_real_digest_algo_type(ModuleType moduletype, ModuleDigestAlgo type, unsigned int* realtype);
|
||||
extern int get_key_len_by_algo_type(ModuleSymmKeyAlgo type);
|
||||
extern void transform_jnta_algo_type(unsigned int type, unsigned int mode, unsigned int *standardtype);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* COMMON_ALGO_H */
|
||||
538
contrib/common_cipher/common_cipher.cpp
Executable file
538
contrib/common_cipher/common_cipher.cpp
Executable file
@ -0,0 +1,538 @@
|
||||
#include "common_cipher.h"
|
||||
#include "common_err.h"
|
||||
#include "common_utils.h"
|
||||
#include "common_internal_interfaces.h"
|
||||
|
||||
/** 初始化密码模块
|
||||
*
|
||||
* @param[in]
|
||||
* load_info 密码模块相关信息(硬件设备口令,硬件设备、硬件库路径等),通过kv方式传入
|
||||
*
|
||||
* @param[out]
|
||||
* supported_feature 返回当前密码模块支持的加密方式,参考上述结构体
|
||||
* @return 成功返回CRYPT_MOD_OK,失败返回错误码
|
||||
*
|
||||
* 示例:
|
||||
* 用户设置GUC参数crypto_module_info = 'enable_crypto_module=on,module_third_msg=aaa'
|
||||
* 传入接口时load_info = 'aaa'
|
||||
*/
|
||||
int crypto_module_init(char *load_info, SupportedFeature *supported_feature)
|
||||
{
|
||||
int ret = CRYPT_MOD_OK;
|
||||
|
||||
ModuleParams moduleparams;
|
||||
|
||||
memset(&moduleparams, 0x0, sizeof(ModuleParams));
|
||||
|
||||
/* 1.解析load_info获取加载密码模块的参数*/
|
||||
ret = parse_module_params(load_info, &moduleparams);
|
||||
if (ret != CRYPT_MOD_OK) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* 2.根据密码模块类型填充supported_feature*/
|
||||
ret = get_supported_feature(moduleparams.moduletype, supported_feature);
|
||||
if (ret != CRYPT_MOD_OK) {
|
||||
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* 3.dlopen打开密码模块驱动库,并加载接口函数*/
|
||||
ret = load_module_driver(moduleparams);
|
||||
if (ret != CRYPT_MOD_OK) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* 4.打开设备*/
|
||||
ret = internal_open_device(moduleparams.cfgfilepath);
|
||||
if (ret != CRYPT_MOD_OK) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
return CRYPT_MOD_OK;
|
||||
err:
|
||||
/*可能已经打开/加载,尝试释放*/
|
||||
(void)internal_close_device();
|
||||
(void)unload_module_driver();
|
||||
set_thread_errno(ret);
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
/** 会话中连接密码模块
|
||||
*
|
||||
* @param[in]
|
||||
* key_info 密码相关信息(用户口令等信息),通过kv方式传入
|
||||
*
|
||||
* @param[out]
|
||||
* sess 会话信息
|
||||
* @return 成功返回CRYPT_MOD_OK,失败返回错误码
|
||||
*
|
||||
* 示例:
|
||||
* 用户设置GUC参数tde_key_info = 'keyType=third_kms, keyThirdMsg =bbb'
|
||||
* 传入接口时key_info = 'bbb'
|
||||
*/
|
||||
int crypto_module_sess_init(char *key_info, void **sess)
|
||||
{
|
||||
int ret = CRYPT_MOD_OK;
|
||||
|
||||
ret = internal_open_session(sess);
|
||||
if (ret != CRYPT_MOD_OK) {
|
||||
set_thread_errno(ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/** 会话中断开连接密码模块
|
||||
*
|
||||
* @param[in]
|
||||
* sess 会话信息
|
||||
*
|
||||
* @param[out]
|
||||
*
|
||||
* @return 成功返回CRYPT_MOD_OK,失败返回错误码
|
||||
*
|
||||
*/
|
||||
void crypto_module_sess_exit(void *sess)
|
||||
{
|
||||
int ret = CRYPT_MOD_OK;
|
||||
|
||||
ret = internal_close_session(sess);
|
||||
if (ret != CRYPT_MOD_OK) {
|
||||
set_thread_errno(ret);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/** 创建密钥
|
||||
*
|
||||
* @param[in]
|
||||
* sess 会话信息
|
||||
* algo 密钥使用场景的算法
|
||||
*
|
||||
* @param[out]
|
||||
* key_id 返回生成密钥/密钥ID/密钥密文
|
||||
* key_id_size 返回生成内容长度
|
||||
* @return 成功返回CRYPT_MOD_OK,失败返回错误码
|
||||
*
|
||||
*/
|
||||
int crypto_create_symm_key(void *sess, ModuleSymmKeyAlgo algo, unsigned char *key_id, size_t *key_id_size)
|
||||
{
|
||||
int ret = CRYPT_MOD_OK;
|
||||
|
||||
ret = internal_generate_symm_key(sess, algo, key_id, (unsigned int*)key_id_size);
|
||||
if (ret != CRYPT_MOD_OK) {
|
||||
set_thread_errno(ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/** 密钥上下文初始化,后续进行加解密可直接使用上下文
|
||||
*
|
||||
* @param[in]
|
||||
* sess 会话信息
|
||||
* algo 加密算法
|
||||
* enc 加密1、解密0
|
||||
* key_id 密码信息
|
||||
* key_id_size 密码信息长度
|
||||
* @param[out]
|
||||
* ctx 返回使用密钥信息
|
||||
* @return 成功返回CRYPT_MOD_OK,失败返回错误码
|
||||
*
|
||||
*/
|
||||
int crypto_ctx_init(void *sess, void **ctx, ModuleSymmKeyAlgo algo, int enc, unsigned char *key_id, size_t key_id_size)
|
||||
{
|
||||
InternalKeyCtx *keyctx = NULL;
|
||||
int ret = CRYPT_MOD_OK;
|
||||
|
||||
if (sess == NULL) {
|
||||
return CRYPTO_MOD_NOT_OPENSESSION_ERR;
|
||||
}
|
||||
|
||||
if (enc != INTERNAL_DO_DEC && enc != INTERNAL_DO_ENC) {
|
||||
return CRYPTO_MOD_INVALID_CRYPTO_TYPE_ERR;
|
||||
}
|
||||
|
||||
if (key_id == NULL || key_id[0] == '\0' || key_id_size <= 0 || key_id_size > INTERNAL_MAX_KEY_LEN) {
|
||||
return CRYPTO_MOD_INVALID_KEY_ERR;
|
||||
}
|
||||
|
||||
keyctx = (InternalKeyCtx*)malloc(sizeof(InternalKeyCtx));
|
||||
|
||||
keyctx->session = sess;
|
||||
|
||||
ret = get_real_symm_algo_type(get_current_module_type(), algo, &(keyctx->algotype), &(keyctx->algomode));
|
||||
if (ret != CRYPT_MOD_OK) {
|
||||
free(keyctx);
|
||||
return ret;
|
||||
}
|
||||
|
||||
keyctx->enc = enc;
|
||||
|
||||
memset(keyctx->key, 0x0, sizeof(keyctx->key));
|
||||
memcpy(keyctx->key, key_id, key_id_size);
|
||||
keyctx->keysize = key_id_size;
|
||||
|
||||
*ctx = keyctx;
|
||||
|
||||
return CRYPT_MOD_OK;
|
||||
}
|
||||
|
||||
/** 获取数据加解密后的数据长度
|
||||
*
|
||||
* @param[in]
|
||||
* ctx 加解密上下文信息
|
||||
* enc 加密1、解密0
|
||||
* data_size 返回加解密结果长度
|
||||
* @return 返回数据长度
|
||||
*
|
||||
*/
|
||||
int crypto_result_size(void *ctx, int enc, size_t data_size)
|
||||
{
|
||||
if (ctx == NULL) {
|
||||
return CRYPTO_MOD_INVALID_KEY_CTX_ERR;
|
||||
}
|
||||
|
||||
if (enc == INTERNAL_DO_DEC) {
|
||||
return data_size;
|
||||
} else if (enc == INTERNAL_DO_ENC) {
|
||||
return (data_size + INTERNAL_BLOCK_LEN);
|
||||
} else
|
||||
return CRYPTO_MOD_INVALID_CRYPTO_TYPE_ERR;
|
||||
}
|
||||
|
||||
/** 密钥上下文清理
|
||||
*
|
||||
* @param[in]
|
||||
* ctx 加解密上下文信息
|
||||
* @param[out]
|
||||
*
|
||||
* @return 成功返回CRYPT_MOD_OK,失败返回错误码
|
||||
*
|
||||
*/
|
||||
void crypto_ctx_clean(void *ctx)
|
||||
{
|
||||
if (ctx) {
|
||||
free(ctx);
|
||||
ctx = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/** 执行加解密
|
||||
*
|
||||
* @param[in]
|
||||
* ctx 加解密上下文信息
|
||||
* enc 加密1、解密0
|
||||
* data 原数据信息
|
||||
* data_size 原数据长度
|
||||
* iv iv信息
|
||||
* iv_size iv信息长度
|
||||
* tag GCM模式的校验值
|
||||
* @param[out]
|
||||
* result 返回结果信息
|
||||
* result_size 返回结果信息长度
|
||||
*
|
||||
* @return 成功返回CRYPT_MOD_OK,失败返回错误码
|
||||
*
|
||||
*/
|
||||
int crypto_encrypt_decrypt(void *ctx, int enc, unsigned char *data, size_t data_size, unsigned char *iv, size_t iv_size, unsigned char *result, size_t *result_size, unsigned char *tag)
|
||||
{
|
||||
int ret = CRYPT_MOD_OK;
|
||||
|
||||
if ((enc == INTERNAL_DO_ENC && *result_size < (data_size + INTERNAL_BLOCK_LEN))
|
||||
|| (enc == INTERNAL_DO_DEC && *result_size < data_size)) {
|
||||
set_thread_errno(CRYPTO_MOD_NOT_ENOUGH_SPACE_ERR);
|
||||
return CRYPTO_MOD_NOT_ENOUGH_SPACE_ERR;
|
||||
}
|
||||
|
||||
if (enc == INTERNAL_DO_ENC) {
|
||||
ret = internal_symm_encrypt(ctx, data, data_size, iv, iv_size, result, (unsigned int*)result_size, tag);
|
||||
} else if (enc == INTERNAL_DO_DEC) {
|
||||
ret = internal_symm_decrypt(ctx, data, data_size, iv, iv_size, result, (unsigned int*)result_size, tag);
|
||||
}
|
||||
|
||||
if (ret != CRYPT_MOD_OK) {
|
||||
set_thread_errno(ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
/** 计算摘要
|
||||
*
|
||||
* @param[in]
|
||||
* sess 会话信息
|
||||
* algo 摘要算法
|
||||
* data 原数据信息
|
||||
* data_size 原数据长度
|
||||
* @param[out]
|
||||
* result 返回结果信息
|
||||
* result_size 返回结果信息长度
|
||||
*
|
||||
* @return 成功返回CRYPT_MOD_OK,失败返回错误码
|
||||
*
|
||||
*/
|
||||
int crypto_digest(void *sess, ModuleDigestAlgo algo, unsigned char * data, size_t data_size,unsigned char *result, size_t *result_size)
|
||||
{
|
||||
int ret = CRYPT_MOD_OK;
|
||||
|
||||
ret = internal_digest(sess, algo, data, data_size, result, (unsigned int*)result_size);
|
||||
if (ret != CRYPT_MOD_OK) {
|
||||
set_thread_errno(ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/** hmac初始化
|
||||
*
|
||||
* @param[in]
|
||||
* sess 会话信息
|
||||
* algo 摘要算法
|
||||
* key_id 密码信息
|
||||
* key_id_size 密码信息长度
|
||||
* @param[out]
|
||||
* ctx 返回密钥上下文
|
||||
*
|
||||
* @return 成功返回CRYPT_MOD_OK,失败返回错误码
|
||||
*
|
||||
*/
|
||||
int crypto_hmac_init(void *sess, void **ctx, ModuleSymmKeyAlgo algo, unsigned char *key_id, size_t key_id_size)
|
||||
{
|
||||
InternalKeyCtx *keyctx = NULL;
|
||||
int ret = CRYPT_MOD_OK;
|
||||
|
||||
if (sess == NULL) {
|
||||
return CRYPTO_MOD_NOT_OPENSESSION_ERR;
|
||||
}
|
||||
|
||||
if (key_id == NULL || key_id[0] == '\0' || key_id_size <= 0 || key_id_size > INTERNAL_MAX_KEY_LEN) {
|
||||
return CRYPTO_MOD_INVALID_KEY_ERR;
|
||||
}
|
||||
|
||||
keyctx = (InternalKeyCtx*)malloc(sizeof(InternalKeyCtx));
|
||||
|
||||
|
||||
keyctx->session = sess;
|
||||
|
||||
ret = get_real_symm_algo_type(get_current_module_type(), algo, &(keyctx->algotype), &(keyctx->algomode));
|
||||
if (ret != CRYPT_MOD_OK) {
|
||||
free(keyctx);
|
||||
return ret;
|
||||
}
|
||||
|
||||
memcpy(keyctx->key, key_id, key_id_size);
|
||||
keyctx->keysize = key_id_size;
|
||||
|
||||
*ctx = keyctx;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/** hmac清理
|
||||
*
|
||||
* @param[in]
|
||||
* ctx 密钥上下文信息
|
||||
*
|
||||
* @param[out]
|
||||
*
|
||||
* @return 成功返回CRYPT_MOD_OK,失败返回错误码
|
||||
*
|
||||
*/
|
||||
void crypto_hmac_clean(void *ctx)
|
||||
{
|
||||
if (ctx) {
|
||||
free(ctx);
|
||||
ctx = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/** 执行hmac计算
|
||||
*
|
||||
* @param[in]
|
||||
* ctx 密钥上下文信息
|
||||
* data 原数据信息
|
||||
* data_size 原数据长度
|
||||
* @param[out]
|
||||
* result 返回结果信息
|
||||
* result_size 返回结果信息长度
|
||||
*
|
||||
* @return 成功返回CRYPT_MOD_OK,失败返回错误码
|
||||
*
|
||||
*/
|
||||
int crypto_hmac(void *ctx, unsigned char * data, size_t data_size, unsigned char *result, size_t *result_size)
|
||||
{
|
||||
int ret = CRYPT_MOD_OK;
|
||||
|
||||
ret = internal_hmac(ctx, data, data_size, result, result_size);
|
||||
if (ret != CRYPT_MOD_OK)
|
||||
set_thread_errno(ret);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/** 生成随机数
|
||||
*
|
||||
* @param[in]
|
||||
* sess 会话信息
|
||||
* size 申请的随机信息长度
|
||||
*
|
||||
* @param[out]
|
||||
* buffer 返回随机信息
|
||||
*
|
||||
* @return 成功返回CRYPT_MOD_OK,失败返回错误码
|
||||
*
|
||||
*/
|
||||
int crypto_gen_random(void *sess, char *buffer, size_t size)
|
||||
{
|
||||
int ret = CRYPT_MOD_OK;
|
||||
|
||||
ret = internal_generate_random(sess, buffer, size);
|
||||
if (ret != CRYPT_MOD_OK)
|
||||
set_thread_errno(ret);
|
||||
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
/** 执行确定性加解密
|
||||
*
|
||||
* @param[in]
|
||||
* sess 会话信息
|
||||
* enc 加密1、解密0
|
||||
* data 原数据信息
|
||||
* data_size 原数据长度
|
||||
* key_id 密钥信息
|
||||
* key_id_size 密钥信息长度
|
||||
* @param[out]
|
||||
* result 返回结果信息
|
||||
* result_size 返回结果信息长度
|
||||
*
|
||||
* @return 成功返回CRYPT_MOD_OK,失败返回错误码
|
||||
*
|
||||
*/
|
||||
int crypto_deterministic_enc_dec(void *sess, int enc, unsigned char *data, unsigned char *key_id, size_t key_id_size, size_t data_size, unsigned char *result, size_t *result_size)
|
||||
{
|
||||
int ret = CRYPT_MOD_OK;
|
||||
void *tmpkeyctx = NULL;
|
||||
unsigned char tmpiv[INTERNAL_IV_LEN + 1] = {0};
|
||||
|
||||
ret = crypto_ctx_init(sess, &tmpkeyctx, MODULE_SM4_CBC, enc, key_id, key_id_size);
|
||||
if (ret != CRYPT_MOD_OK) {
|
||||
set_thread_errno(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*加密:对明文计算hmac作为iv,并将hmac放到密文串头;
|
||||
*解密:从密文头获取iv和hmac,并对解密出的明文计算hmac进行校验*/
|
||||
|
||||
if (enc == INTERNAL_DO_ENC) {
|
||||
void *tmphmacctx = NULL;
|
||||
unsigned char tmphmac[INTERNAL_HMAC_LEN] = {0};
|
||||
long unsigned int hmaclen = 0;
|
||||
|
||||
/*计算iv */
|
||||
ret = crypto_hmac_init(sess, &tmphmacctx, MODULE_HMAC_SM3, key_id, key_id_size);
|
||||
if (ret != CRYPT_MOD_OK) {
|
||||
set_thread_errno(ret);
|
||||
crypto_ctx_clean(tmpkeyctx);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = crypto_hmac(tmphmacctx, data, data_size, tmphmac, &hmaclen);
|
||||
if (ret != CRYPT_MOD_OK) {
|
||||
set_thread_errno(ret);
|
||||
crypto_ctx_clean(tmphmacctx);
|
||||
crypto_ctx_clean(tmpkeyctx);
|
||||
return ret;
|
||||
}
|
||||
|
||||
memcpy(tmpiv, tmphmac, INTERNAL_IV_LEN);
|
||||
|
||||
/*把hmac放到密文头 */
|
||||
memcpy(result, tmphmac, INTERNAL_HMAC_LEN);
|
||||
|
||||
crypto_hmac_clean(tmphmacctx);
|
||||
|
||||
|
||||
ret = internal_symm_encrypt(tmpkeyctx, data, data_size, tmpiv, INTERNAL_IV_LEN, result + INTERNAL_HMAC_LEN, (unsigned int*)result_size, NULL);
|
||||
if (ret != CRYPT_MOD_OK) {
|
||||
set_thread_errno(ret);
|
||||
}
|
||||
|
||||
crypto_ctx_clean(tmpkeyctx);
|
||||
|
||||
*result_size += INTERNAL_HMAC_LEN;
|
||||
|
||||
return ret;
|
||||
|
||||
} else if (enc == INTERNAL_DO_DEC){
|
||||
void *tmphmacctx = NULL;
|
||||
unsigned char tmphmac[INTERNAL_HMAC_LEN] = {0};
|
||||
long unsigned int hmaclen = 0;
|
||||
unsigned char verifyhmac[INTERNAL_HMAC_LEN] = {0};
|
||||
/*获取iv */
|
||||
memcpy(tmpiv, data, INTERNAL_IV_LEN);
|
||||
|
||||
/*获取hmac*/
|
||||
memcpy(verifyhmac, data, INTERNAL_HMAC_LEN);
|
||||
|
||||
ret = internal_symm_decrypt(tmpkeyctx, data + INTERNAL_HMAC_LEN, data_size - INTERNAL_HMAC_LEN, tmpiv, INTERNAL_IV_LEN, result, (unsigned int*)result_size, NULL);
|
||||
if (ret != CRYPT_MOD_OK) {
|
||||
set_thread_errno(ret);
|
||||
crypto_ctx_clean(tmpkeyctx);
|
||||
return ret;
|
||||
}
|
||||
|
||||
crypto_ctx_clean(tmpkeyctx);
|
||||
|
||||
/*计算明文hmac */
|
||||
ret = crypto_hmac_init(sess, &tmphmacctx, MODULE_HMAC_SM3, key_id, key_id_size);
|
||||
if (ret != CRYPT_MOD_OK) {
|
||||
set_thread_errno(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = crypto_hmac(tmphmacctx, result, *result_size, tmphmac, &hmaclen);
|
||||
if (ret != CRYPT_MOD_OK) {
|
||||
set_thread_errno(ret);
|
||||
crypto_ctx_clean(tmphmacctx);
|
||||
return ret;
|
||||
}
|
||||
|
||||
crypto_hmac_clean(tmphmacctx);
|
||||
|
||||
/*校验明文hmac值 */
|
||||
if (strncmp((char*)tmphmac, (char*)verifyhmac, INTERNAL_HMAC_LEN)) {
|
||||
set_thread_errno(CRYPTO_MOD_DETERMINISTIC_DEC_VERIFY_ERR);
|
||||
return CRYPTO_MOD_DETERMINISTIC_DEC_VERIFY_ERR;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
/** 获取报错信息
|
||||
*
|
||||
* @param[in]
|
||||
* sess 会话信息
|
||||
* @param[out]
|
||||
* errmsg 返回结果信息,最长256字节
|
||||
*
|
||||
* @return 成功返回CRYPT_MOD_OK,失败返回错误码
|
||||
*
|
||||
*/
|
||||
int crypto_get_errmsg(void *sess, char *errmsg)
|
||||
{
|
||||
strcpy(errmsg, common_get_errmsg());
|
||||
|
||||
return CRYPT_MOD_OK;
|
||||
}
|
||||
|
||||
|
||||
275
contrib/common_cipher/common_cipher.h
Executable file
275
contrib/common_cipher/common_cipher.h
Executable file
@ -0,0 +1,275 @@
|
||||
#ifndef COMMON_CIPHER_H
|
||||
#define COMMON_CIPHER_H
|
||||
#include <pthread.h>
|
||||
#include <dlfcn.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define MAX_PROVIDER_NAME_LEN 128
|
||||
#define MAX_ERRMSG_LEN 256
|
||||
|
||||
typedef enum {
|
||||
MODULE_AES_128_CBC = 0,
|
||||
MODULE_AES_128_CTR,
|
||||
MODULE_AES_128_GCM,
|
||||
MODULE_AES_256_CBC,
|
||||
MODULE_AES_256_CTR,
|
||||
MODULE_AES_256_GCM,
|
||||
MODULE_SM4_CBC,
|
||||
MODULE_SM4_CTR,
|
||||
MODULE_HMAC_SHA256,
|
||||
MODULE_HMAC_SM3,
|
||||
MODULE_DETERMINISTIC_KEY,
|
||||
MODULE_ALGO_MAX = 1024
|
||||
} ModuleSymmKeyAlgo;
|
||||
|
||||
|
||||
typedef enum {
|
||||
MODULE_SHA256 = 0,
|
||||
MODULE_SM3,
|
||||
MODULE_DIGEST_MAX = 1024
|
||||
} ModuleDigestAlgo;
|
||||
|
||||
|
||||
typedef enum {
|
||||
KEY_TYPE_INVALID,
|
||||
KEY_TYPE_PLAINTEXT,
|
||||
KEY_TYPE_CIPHERTEXT,
|
||||
KEY_TYPE_NAMEORIDX,
|
||||
KEY_TYPE_MAX
|
||||
} KeyType;
|
||||
|
||||
|
||||
typedef struct {
|
||||
char provider_name[MAX_PROVIDER_NAME_LEN];
|
||||
KeyType key_type;
|
||||
int supported_symm[MODULE_ALGO_MAX]; // 不支持算法填入0或者支持算法填入1
|
||||
int supported_digest[MODULE_DIGEST_MAX]; // 不支持算法填入0或者支持算法填入1
|
||||
} SupportedFeature;
|
||||
|
||||
|
||||
/** 初始化密码模块
|
||||
*
|
||||
* @param[in]
|
||||
* load_info 密码模块相关信息(硬件设备口令,硬件设备、硬件库路径等),通过kv方式传入
|
||||
*
|
||||
* @param[out]
|
||||
* supported_feature 返回当前密码模块支持的加密方式,参考上述结构体
|
||||
* @return 成功返回CRYPT_MOD_OK,失败返回错误码
|
||||
*
|
||||
* 示例:
|
||||
* 用户设置GUC参数crypto_module_info = 'enable_crypto_module=on,module_third_msg=aaa'
|
||||
* 传入接口时load_info = 'aaa'
|
||||
*/
|
||||
int crypto_module_init(char *load_info, SupportedFeature *supported_feature);
|
||||
|
||||
/** 会话中连接密码模块
|
||||
*
|
||||
* @param[in]
|
||||
* key_info 密码相关信息(用户口令等信息),通过kv方式传入
|
||||
*
|
||||
* @param[out]
|
||||
* sess 会话信息
|
||||
* @return 成功返回CRYPT_MOD_OK,失败返回错误码
|
||||
*
|
||||
* 示例:
|
||||
* 用户设置GUC参数tde_key_info = 'keyType=third_kms, keyThirdMsg =bbb'
|
||||
* 传入接口时key_info = 'bbb'
|
||||
*/
|
||||
int crypto_module_sess_init(char *key_info, void **sess);
|
||||
|
||||
/** 会话中断开连接密码模块
|
||||
*
|
||||
* @param[in]
|
||||
* sess 会话信息
|
||||
*
|
||||
* @param[out]
|
||||
*
|
||||
* @return 成功返回CRYPT_MOD_OK,失败返回错误码
|
||||
*
|
||||
*/
|
||||
void crypto_module_sess_exit(void *sess);
|
||||
|
||||
/** 创建密钥
|
||||
*
|
||||
* @param[in]
|
||||
* sess 会话信息
|
||||
* algo 密钥使用场景的算法
|
||||
*
|
||||
* @param[out]
|
||||
* key_id 返回生成密钥/密钥ID/密钥密文
|
||||
* key_id_size 返回生成内容长度
|
||||
* @return 成功返回CRYPT_MOD_OK,失败返回错误码
|
||||
*
|
||||
*/
|
||||
int crypto_create_symm_key(void *sess, ModuleSymmKeyAlgo algo, unsigned char *key_id, size_t *key_id_size);
|
||||
|
||||
/** 密钥上下文初始化,后续进行加解密可直接使用上下文
|
||||
*
|
||||
* @param[in]
|
||||
* sess 会话信息
|
||||
* algo 加密算法
|
||||
* enc 加密1、解密0
|
||||
* key_id 密码信息
|
||||
* key_id_size 密码信息长度
|
||||
* @param[out]
|
||||
* ctx 返回使用密钥信息
|
||||
* @return 成功返回CRYPT_MOD_OK,失败返回错误码
|
||||
*
|
||||
*/
|
||||
int crypto_ctx_init(void *sess, void **ctx, ModuleSymmKeyAlgo algo, int enc, unsigned char *key_id, size_t key_id_size);
|
||||
|
||||
/** 获取数据加解密后的数据长度
|
||||
*
|
||||
* @param[in]
|
||||
* ctx 加解密上下文信息
|
||||
* enc 加密1、解密0
|
||||
* data_size 返回加解密结果长度
|
||||
* @return 返回数据长度
|
||||
*
|
||||
*/
|
||||
int crypto_result_size(void *ctx, int enc, size_t data_size);
|
||||
|
||||
/** 密钥上下文清理
|
||||
*
|
||||
* @param[in]
|
||||
* ctx 加解密上下文信息
|
||||
* @param[out]
|
||||
*
|
||||
* @return 成功返回CRYPT_MOD_OK,失败返回错误码
|
||||
*
|
||||
*/
|
||||
void crypto_ctx_clean(void *ctx);
|
||||
|
||||
/** 执行加解密
|
||||
*
|
||||
* @param[in]
|
||||
* ctx 加解密上下文信息
|
||||
* enc 加密1、解密0
|
||||
* data 原数据信息
|
||||
* data_size 原数据长度
|
||||
* iv iv信息
|
||||
* iv_size iv信息长度
|
||||
* tag GCM模式的校验值
|
||||
* @param[out]
|
||||
* result 返回结果信息
|
||||
* result_size 返回结果信息长度
|
||||
*
|
||||
* @return 成功返回CRYPT_MOD_OK,失败返回错误码
|
||||
*
|
||||
*/
|
||||
int crypto_encrypt_decrypt(void *ctx, int enc, unsigned char *data, size_t data_size, unsigned char *iv, size_t iv_size, unsigned char *result, size_t *result_size, unsigned char *tag);
|
||||
|
||||
/** 计算摘要
|
||||
*
|
||||
* @param[in]
|
||||
* sess 会话信息
|
||||
* algo 摘要算法
|
||||
* data 原数据信息
|
||||
* data_size 原数据长度
|
||||
* @param[out]
|
||||
* result 返回结果信息
|
||||
* result_size 返回结果信息长度
|
||||
*
|
||||
* @return 成功返回CRYPT_MOD_OK,失败返回错误码
|
||||
*
|
||||
*/
|
||||
int crypto_digest(void *sess, ModuleDigestAlgo algo, unsigned char * data, size_t data_size,unsigned char *result, size_t *result_size);
|
||||
|
||||
/** hmac初始化
|
||||
*
|
||||
* @param[in]
|
||||
* sess 会话信息
|
||||
* algo 摘要算法
|
||||
* key_id 密码信息
|
||||
* key_id_size 密码信息长度
|
||||
* @param[out]
|
||||
* ctx 返回密钥上下文
|
||||
*
|
||||
* @return 成功返回CRYPT_MOD_OK,失败返回错误码
|
||||
*
|
||||
*/
|
||||
int crypto_hmac_init(void *sess, void **ctx, ModuleSymmKeyAlgo algo, unsigned char *key_id, size_t key_id_size);
|
||||
|
||||
/** hmac清理
|
||||
*
|
||||
* @param[in]
|
||||
* ctx 密钥上下文信息
|
||||
*
|
||||
* @param[out]
|
||||
*
|
||||
* @return 成功返回CRYPT_MOD_OK,失败返回错误码
|
||||
*
|
||||
*/
|
||||
void crypto_hmac_clean(void *ctx);
|
||||
|
||||
/** 执行hmac计算
|
||||
*
|
||||
* @param[in]
|
||||
* ctx 密钥上下文信息
|
||||
* data 原数据信息
|
||||
* data_size 原数据长度
|
||||
* @param[out]
|
||||
* result 返回结果信息
|
||||
* result_size 返回结果信息长度
|
||||
*
|
||||
* @return 成功返回CRYPT_MOD_OK,失败返回错误码
|
||||
*
|
||||
*/
|
||||
int crypto_hmac(void *ctx, unsigned char * data, size_t data_size, unsigned char *result, size_t *result_size);
|
||||
|
||||
/** 生成随机数
|
||||
*
|
||||
* @param[in]
|
||||
* sess 会话信息
|
||||
* size 申请的随机信息长度
|
||||
*
|
||||
* @param[out]
|
||||
* buffer 返回随机信息
|
||||
*
|
||||
* @return 成功返回CRYPT_MOD_OK,失败返回错误码
|
||||
*
|
||||
*/
|
||||
int crypto_gen_random(void *sess, char *buffer, size_t size);
|
||||
|
||||
/** 执行确定性加解密
|
||||
*
|
||||
* @param[in]
|
||||
* sess 会话信息
|
||||
* enc 加密1、解密0
|
||||
* data 原数据信息
|
||||
* data_size 原数据长度
|
||||
* key_id 密钥信息
|
||||
* key_id_size 密钥信息长度
|
||||
* @param[out]
|
||||
* result 返回结果信息
|
||||
* result_size 返回结果信息长度
|
||||
*
|
||||
* @return 成功返回CRYPT_MOD_OK,失败返回错误码
|
||||
*
|
||||
*/
|
||||
int crypto_deterministic_enc_dec(void *sess, int enc, unsigned char *data, unsigned char *key_id, size_t key_id_size, size_t data_size, unsigned char *result, size_t *result_size);
|
||||
|
||||
/** 获取报错信息
|
||||
*
|
||||
* @param[in]
|
||||
* sess 会话信息
|
||||
* @param[out]
|
||||
* errmsg 返回结果信息,最长256字节
|
||||
*
|
||||
* @return 成功返回CRYPT_MOD_OK,失败返回错误码
|
||||
*
|
||||
*/
|
||||
int crypto_get_errmsg(void *sess, char *errmsg);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*COMMON_CIPHER_H*/
|
||||
126
contrib/common_cipher/common_err.cpp
Executable file
126
contrib/common_cipher/common_err.cpp
Executable file
@ -0,0 +1,126 @@
|
||||
#include "common_err.h"
|
||||
|
||||
#define MAX_ERRMSG_LEN 256
|
||||
|
||||
#define lengthof(array) (sizeof(array) / sizeof(array[0]))
|
||||
|
||||
static thread_local int internalthreaderrno = 0;
|
||||
|
||||
static void reset_thread_errno();
|
||||
|
||||
typedef struct {
|
||||
int errno;
|
||||
char errmsg[MAX_ERRMSG_LEN];
|
||||
}CommonErrInfo;
|
||||
|
||||
/*HSM:hardware security module,硬件安全模块。*/
|
||||
static const CommonErrInfo internal_err_info[] = {
|
||||
{INTERNAL_UNKNOWNERR, "HSM unknown error"},
|
||||
{INTERNAL_NOTSUPPORT, "HSM not support"},
|
||||
{INTERNAL_COMMFAIL, "HSM communication error"},
|
||||
{INTERNAL_HARDFAIL, "HSM hard error"},
|
||||
{INTERNAL_OPENDEVICE, "HSM open device error"},
|
||||
{INTERNAL_OPENSESSION, "HSM open session error"},
|
||||
{INTERNAL_PARDENY, "HSM permission error"},
|
||||
{INTERNAL_KEYNOTEXIST, "HSM key not exist"},
|
||||
{INTERNAL_ALGNOTSUPPORT, "HSM not support algorithm"},
|
||||
{INTERNAL_ALGMODNOTSUPPORT, "HSM not support algorithm mode"},
|
||||
{INTERNAL_PKOPERR, "HSM public key operation error"},
|
||||
{INTERNAL_SKOPERR, "HSM private key operation error"},
|
||||
{INTERNAL_SIGNERR, "HSM sign error"},
|
||||
{INTERNAL_VERIFYERR, "HSM verify error"},
|
||||
{INTERNAL_SYMOPERR, "HSM symmetry operation error"},
|
||||
{INTERNAL_STEPERR, "HSM step error"},
|
||||
{INTERNAL_FILESIZEERR, "HSM file size or data len error"},
|
||||
{INTERNAL_FILENOEXIST, "HSM file not exist"},
|
||||
{INTERNAL_FILEOFSERR, "HSM file offset operation error"},
|
||||
{INTERNAL_KEYTYPEERR, "HSM key type error"},
|
||||
{INTERNAL_KEYERR, "HSM key error"},
|
||||
{INTERNAL_ENCDATAERR, "HSM encrypt data error"},
|
||||
{INTERNAL_RANDERR, "HSM random error"},
|
||||
{INTERNAL_PRKRERR, "HSM private access right error"},
|
||||
{INTERNAL_MACERR, "HSM MAC error"},
|
||||
{INTERNAL_FILEEXISTS, "HSM file exists"},
|
||||
{INTERNAL_FILEWERR, "HSM write file error"},
|
||||
{INTERNAL_NOBUFFER, "HSM not enough storage"},
|
||||
{INTERNAL_INARGERR, "HSM input param error"},
|
||||
{INTERNAL_OUTARGERR, "HSM output param error"},
|
||||
{INTERNAL_UKEYERR, "HSM ukey error"},
|
||||
{INTERNAL_GENKEYERR, "HSM generate key error"},
|
||||
{INTERNAL_STATEERR, "HSM status error"},
|
||||
{INTERNAL_RETRYERR, "HSM retry exceeded"},
|
||||
{INTERNAL_DEVICE_BUSY, "HSM is busy"}
|
||||
};
|
||||
|
||||
static int internal_err_number = lengthof(internal_err_info);
|
||||
|
||||
static const CommonErrInfo common_err_info[] = {
|
||||
{CRYPTO_MOD_TYPE_REPEATED_ERR, "module type set repeated"},
|
||||
{CRYPTO_MOD_TYPE_INVALID_ERR, "invalid module type"},
|
||||
{CRYPTO_MOD_LIBPATH_REPEATED_ERR, "module lib path set repeated"},
|
||||
{CRYPTO_MOD_LIBPATH_INVALID_ERR, "invalid module lib path"},
|
||||
{CRYPTO_MOD_CFG_PATH_REPEATED_ERR, "module config file set repeated"},
|
||||
{CRYPTO_MOD_CFG_PATH_INVALID_ERR, "invalid module config file"},
|
||||
{CRYPTO_MOD_PARAM_TOO_MANY_ERR, "param is too many"},
|
||||
{CRYPTO_MOD_PARAM_INVALID_ERR, "invalid param"},
|
||||
{CRYPTO_MOD_UNSUPPORTED_SYMM_TYPE_ERR, "unsupported symm algo type"},
|
||||
{CRYPTO_MOD_UNSUPPORTED_DIGEST_TYPE_ERR, "unsupported digest algo type"},
|
||||
{CRYPTO_MOD_DLOPEN_ERR, "dlopen error"},
|
||||
{CRYPTO_MOD_DLSYM_ERR, "dlsym error"},
|
||||
{CRYPTO_MOD_UNLOAD_ERR, "unload error"},
|
||||
{CRYPTO_MOD_NOT_LOADED_ERR, "module not loaded"},
|
||||
{CRYPTO_MOD_NOT_OPENDEVICE_ERR, "device not opened"},
|
||||
{CRYPTO_MOD_NOT_OPENSESSION_ERR, "session not opened"},
|
||||
{CRYPTO_MOD_INVALID_KEY_ERR, "invalid key"},
|
||||
{CRYPTO_MOD_INVALID_CRYPTO_TYPE_ERR, "invalid crypto type"},
|
||||
{CRYPTO_MOD_INVALID_KEY_CTX_ERR, "invalid key ctx"},
|
||||
{CRYPTO_MOD_UNPADDING_ERR, "unpadding err"},
|
||||
{CRYPTO_MOD_NOT_ENOUGH_SPACE_ERR, "not enough space"},
|
||||
{CRYPTO_MOD_DETERMINISTIC_DEC_VERIFY_ERR, "deterministic dec verify error"},
|
||||
{CRYPTO_MOD_UNKNOWN_PARAM_ERR, "unknown module param"}
|
||||
};
|
||||
|
||||
static int common_err_number = lengthof(common_err_info);
|
||||
|
||||
static const char* unknown_err = "unknown err";
|
||||
|
||||
const char* common_get_errmsg()
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
if (internalthreaderrno & INTERNAL_BASE_ERR) {
|
||||
for (i = 0; i < internal_err_number; i++) {
|
||||
if (internalthreaderrno == internal_err_info[i].errno) {
|
||||
reset_thread_errno();
|
||||
return internal_err_info[i].errmsg;
|
||||
}
|
||||
}
|
||||
} else if (internalthreaderrno & CRYPTO_MOD_BASE_ERR) {
|
||||
for (i = 0; i < common_err_number; i++) {
|
||||
if (internalthreaderrno == common_err_info[i].errno) {
|
||||
reset_thread_errno();
|
||||
return common_err_info[i].errmsg;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
reset_thread_errno();
|
||||
return unknown_err;
|
||||
}
|
||||
|
||||
if (i != internal_err_number && i != common_err_number) {
|
||||
reset_thread_errno();
|
||||
return unknown_err;
|
||||
}
|
||||
|
||||
return unknown_err;
|
||||
}
|
||||
|
||||
void set_thread_errno(int errno)
|
||||
{
|
||||
internalthreaderrno = errno;
|
||||
}
|
||||
|
||||
static void reset_thread_errno()
|
||||
{
|
||||
internalthreaderrno = 0;
|
||||
}
|
||||
89
contrib/common_cipher/common_err.h
Executable file
89
contrib/common_cipher/common_err.h
Executable file
@ -0,0 +1,89 @@
|
||||
#ifndef COMMON_ERR_H
|
||||
#define COMMON_ERR_H
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*硬件内部错误码*/
|
||||
#define INTERNAL_OK 0
|
||||
|
||||
#define INTERNAL_BASE_ERR 0x01000000
|
||||
|
||||
#define INTERNAL_UNKNOWNERR (INTERNAL_BASE_ERR + 0x00000001) /* 未知错误 */
|
||||
#define INTERNAL_NOTSUPPORT (INTERNAL_BASE_ERR + 0x00000002) /* 不支持 */
|
||||
#define INTERNAL_COMMFAIL (INTERNAL_BASE_ERR + 0x00000003) /* 通信错误 */
|
||||
#define INTERNAL_HARDFAIL (INTERNAL_BASE_ERR + 0x00000004) /* 硬件错误 */
|
||||
#define INTERNAL_OPENDEVICE (INTERNAL_BASE_ERR + 0x00000005) /* 打开设备错误 */
|
||||
#define INTERNAL_OPENSESSION (INTERNAL_BASE_ERR + 0x00000006) /* 打开会话句柄错误 */
|
||||
#define INTERNAL_PARDENY (INTERNAL_BASE_ERR + 0x00000007) /* 权限不满足 */
|
||||
#define INTERNAL_KEYNOTEXIST (INTERNAL_BASE_ERR + 0x00000008) /* 密钥不存在 */
|
||||
#define INTERNAL_ALGNOTSUPPORT (INTERNAL_BASE_ERR + 0x00000009) /* 不支持的算法 */
|
||||
#define INTERNAL_ALGMODNOTSUPPORT (INTERNAL_BASE_ERR + 0x0000000A) /* 不支持的算法模式 */
|
||||
#define INTERNAL_PKOPERR (INTERNAL_BASE_ERR + 0x0000000B) /* 公钥运算错误 */
|
||||
#define INTERNAL_SKOPERR (INTERNAL_BASE_ERR + 0x0000000C) /* 私钥运算错误 */
|
||||
#define INTERNAL_SIGNERR (INTERNAL_BASE_ERR + 0x0000000D) /* 签名错误 */
|
||||
#define INTERNAL_VERIFYERR (INTERNAL_BASE_ERR + 0x0000000E) /* 验证错误 */
|
||||
#define INTERNAL_SYMOPERR (INTERNAL_BASE_ERR + 0x0000000F) /* 对称运算错误 */
|
||||
#define INTERNAL_STEPERR (INTERNAL_BASE_ERR + 0x00000010) /* 步骤错误 */
|
||||
#define INTERNAL_FILESIZEERR (INTERNAL_BASE_ERR + 0x00000011) /* 文件大小错误或输入数据长度非法 */
|
||||
#define INTERNAL_FILENOEXIST (INTERNAL_BASE_ERR + 0x00000012) /* 文件不存在 */
|
||||
#define INTERNAL_FILEOFSERR (INTERNAL_BASE_ERR + 0x00000013) /* 文件操作偏移量错误 */
|
||||
#define INTERNAL_KEYTYPEERR (INTERNAL_BASE_ERR + 0x00000014) /* 密钥类型错误 */
|
||||
#define INTERNAL_KEYERR (INTERNAL_BASE_ERR + 0x00000015) /* 密钥错误 */
|
||||
#define INTERNAL_ENCDATAERR (INTERNAL_BASE_ERR + 0x00000016) /* 加密数据错误 */
|
||||
#define INTERNAL_RANDERR (INTERNAL_BASE_ERR + 0x00000017) /* 随机数产生失败 */
|
||||
#define INTERNAL_PRKRERR (INTERNAL_BASE_ERR + 0x00000018) /* 私钥使用权限获取失败 */
|
||||
#define INTERNAL_MACERR (INTERNAL_BASE_ERR + 0x00000019) /* MAC 运算失败 */
|
||||
#define INTERNAL_FILEEXISTS (INTERNAL_BASE_ERR + 0x0000001A) /* 指定文件已存在 */
|
||||
#define INTERNAL_FILEWERR (INTERNAL_BASE_ERR + 0x0000001B) /* 文件写入失败 */
|
||||
#define INTERNAL_NOBUFFER (INTERNAL_BASE_ERR + 0x0000001C) /* 存储空间不足 */
|
||||
#define INTERNAL_INARGERR (INTERNAL_BASE_ERR + 0x0000001D) /* 输入参数错误 */
|
||||
#define INTERNAL_OUTARGERR (INTERNAL_BASE_ERR + 0x0000001E) /* 输出参数错误 */
|
||||
#define INTERNAL_UKEYERR (INTERNAL_BASE_ERR + 0x0000001F) /* Ukey错误 */
|
||||
#define INTERNAL_GENKEYERR (INTERNAL_BASE_ERR + 0x00000020) /* 密钥生成错误 */
|
||||
#define INTERNAL_STATEERR (INTERNAL_BASE_ERR + 0x00000021) /* 状态错误 */
|
||||
#define INTERNAL_RETRYERR (INTERNAL_BASE_ERR + 0x00000022) /* 重试超过次数 */
|
||||
#define INTERNAL_DEVICE_BUSY (INTERNAL_BASE_ERR + 0x00000023) /* 设备忙 */
|
||||
|
||||
|
||||
/*库中自定义错误码*/
|
||||
/*特别注意,硬件密码模块的返回值是0表示成功,非0表示失败(错误码),和库对外返回的不一样*/
|
||||
#define CRYPT_MOD_OK 1
|
||||
#define CRYPT_MOD_ERR 0
|
||||
|
||||
#define CRYPTO_MOD_BASE_ERR 0x01000
|
||||
|
||||
#define CRYPTO_MOD_TYPE_REPEATED_ERR (CRYPTO_MOD_BASE_ERR + 0x00001)/*密码模块类型重复设置*/
|
||||
#define CRYPTO_MOD_TYPE_INVALID_ERR (CRYPTO_MOD_BASE_ERR + 0x00002)/*无效的密码模块类型*/
|
||||
#define CRYPTO_MOD_LIBPATH_REPEATED_ERR (CRYPTO_MOD_BASE_ERR + 0x00003)/*密码模块库路径重复设置*/
|
||||
#define CRYPTO_MOD_LIBPATH_INVALID_ERR (CRYPTO_MOD_BASE_ERR + 0x00004)/*无效的密码模块库路径*/
|
||||
#define CRYPTO_MOD_CFG_PATH_REPEATED_ERR (CRYPTO_MOD_BASE_ERR + 0x00005)/*密码模块配置文件重复设置*/
|
||||
#define CRYPTO_MOD_CFG_PATH_INVALID_ERR (CRYPTO_MOD_BASE_ERR + 0x00006)/*无效的密码模块配置文件*/
|
||||
#define CRYPTO_MOD_PARAM_TOO_MANY_ERR (CRYPTO_MOD_BASE_ERR + 0x00007)/*密码卡参数配置过多*/
|
||||
#define CRYPTO_MOD_PARAM_INVALID_ERR (CRYPTO_MOD_BASE_ERR + 0x00008)/*无效的参数*/
|
||||
#define CRYPTO_MOD_UNSUPPORTED_SYMM_TYPE_ERR (CRYPTO_MOD_BASE_ERR + 0x00009)/*不支持的对称算法类型*/
|
||||
#define CRYPTO_MOD_UNSUPPORTED_DIGEST_TYPE_ERR (CRYPTO_MOD_BASE_ERR + 0x0000A)/*不支持的摘要算法类型*/
|
||||
#define CRYPTO_MOD_DLOPEN_ERR (CRYPTO_MOD_BASE_ERR + 0x0000B)/*dlopen失败*/
|
||||
#define CRYPTO_MOD_DLSYM_ERR (CRYPTO_MOD_BASE_ERR + 0x0000C)/*dlsym失败*/
|
||||
#define CRYPTO_MOD_UNLOAD_ERR (CRYPTO_MOD_BASE_ERR + 0x0000D)/*dlclose失败*/
|
||||
#define CRYPTO_MOD_NOT_LOADED_ERR (CRYPTO_MOD_BASE_ERR + 0x0000E)/*还未加载驱动库*/
|
||||
#define CRYPTO_MOD_NOT_OPENDEVICE_ERR (CRYPTO_MOD_BASE_ERR + 0x0000F)/*还未打开设备*/
|
||||
#define CRYPTO_MOD_NOT_OPENSESSION_ERR (CRYPTO_MOD_BASE_ERR + 0x00010)/*还未建立会话*/
|
||||
#define CRYPTO_MOD_INVALID_KEY_ERR (CRYPTO_MOD_BASE_ERR + 0x00011)/*无效的密钥*/
|
||||
#define CRYPTO_MOD_INVALID_CRYPTO_TYPE_ERR (CRYPTO_MOD_BASE_ERR + 0x00012)/*无效的加解密类型*/
|
||||
#define CRYPTO_MOD_INVALID_KEY_CTX_ERR (CRYPTO_MOD_BASE_ERR + 0x00013)/*无效密钥上下文*/
|
||||
#define CRYPTO_MOD_UNPADDING_ERR (CRYPTO_MOD_BASE_ERR + 0x00014)/*去pad失败*/
|
||||
#define CRYPTO_MOD_NOT_ENOUGH_SPACE_ERR (CRYPTO_MOD_BASE_ERR + 0x00015)/*分配的空间不足*/
|
||||
#define CRYPTO_MOD_DETERMINISTIC_DEC_VERIFY_ERR (CRYPTO_MOD_BASE_ERR + 0x00016)/*确定性解密校验失败*/
|
||||
#define CRYPTO_MOD_UNKNOWN_PARAM_ERR (CRYPTO_MOD_BASE_ERR + 0x00017)/*未知的参数*/
|
||||
|
||||
extern void set_thread_errno(int errno);
|
||||
extern const char* common_get_errmsg();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* COMMON_ERR_H */
|
||||
796
contrib/common_cipher/common_internal_interfaces.cpp
Executable file
796
contrib/common_cipher/common_internal_interfaces.cpp
Executable file
@ -0,0 +1,796 @@
|
||||
#include <pthread.h>
|
||||
#include <dlfcn.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "common_internal_interfaces.h"
|
||||
#include "common_err.h"
|
||||
#include "common_utils.h"
|
||||
|
||||
#define INTERNAL_SHARED_LOCK 0
|
||||
#define INTERNAL_EXCLUSIVE_LOCK 1
|
||||
|
||||
#define SET_JNTA_CFG_PATH(path) (setenv("TASS_GHVSM_CFG_PATH", path, 1))
|
||||
|
||||
#define INTERNAL_RETURN(ret) \
|
||||
{ \
|
||||
if (ret == INTERNAL_OK) \
|
||||
return CRYPT_MOD_OK; \
|
||||
else \
|
||||
return ret; \
|
||||
}while(0)
|
||||
|
||||
/*dlopen句柄*/
|
||||
static void *driverhandle = NULL;
|
||||
|
||||
/*密码模块接口*/
|
||||
static ModuleInterfaces *moduleinterfaces = NULL;
|
||||
|
||||
/*定义一个锁,对driverhandle和moduleinterfaces做读写保护*/
|
||||
static pthread_rwlock_t drivermutex;
|
||||
|
||||
/*设备句柄*/
|
||||
static void *devicehandle = NULL;
|
||||
|
||||
/*定义一个锁,对devicehandle做读写保护*/
|
||||
static pthread_rwlock_t devicehandlemutex;
|
||||
|
||||
/*记录当前空闲的最小索引号,在第一次生成密钥时获取并设置。这个需要保证密钥都是从该接口库生成*/
|
||||
static int currnetindex = 0;
|
||||
|
||||
/*定义一个锁,保证同一时刻只有一个线程在生成密钥*/
|
||||
static pthread_mutex_t genkeymutex;
|
||||
|
||||
|
||||
static int internal_padding(char *indata, int inlen, char *outdata, int *outlen);
|
||||
static int internal_unpadding(char *indata, int *inlen);
|
||||
|
||||
static void internal_lock(int loketype, pthread_rwlock_t *lock)
|
||||
{
|
||||
if (loketype == INTERNAL_SHARED_LOCK) {
|
||||
pthread_rwlock_rdlock(lock);
|
||||
} else if (loketype == INTERNAL_EXCLUSIVE_LOCK){
|
||||
pthread_rwlock_wrlock(lock);
|
||||
} else {
|
||||
/*do nothing*/
|
||||
}
|
||||
}
|
||||
|
||||
static void internal_unlock(pthread_rwlock_t *lock)
|
||||
{
|
||||
pthread_rwlock_unlock(lock);
|
||||
}
|
||||
|
||||
ModuleType get_current_module_type()
|
||||
{
|
||||
internal_lock(INTERNAL_SHARED_LOCK, &drivermutex);
|
||||
|
||||
if (moduleinterfaces) {
|
||||
internal_unlock(&drivermutex);
|
||||
return moduleinterfaces->type;
|
||||
}
|
||||
|
||||
internal_unlock(&drivermutex);
|
||||
|
||||
return MODULE_INVALID_TYPE;
|
||||
}
|
||||
|
||||
static int load_standard_interfaces(ModuleStandardInterfaces *standardinterfaces)
|
||||
{
|
||||
standardinterfaces->InternalOpenDevice = (StandardOpenDevice_type)dlsym(driverhandle, "SDF_OpenDevice");
|
||||
standardinterfaces->InternalCloseDevice = (StandardCloseDevice_type)dlsym(driverhandle, "SDF_CloseDevice");
|
||||
standardinterfaces->InternalOpenSession = (StandardOpenSession_type)dlsym(driverhandle, "SDF_OpenSession");
|
||||
standardinterfaces->InternalCloseSession = (StandardCloseSession_type)dlsym(driverhandle, "SDF_CloseSession");
|
||||
standardinterfaces->InternalGenerateRandom = (StandardGenerateRandom_type)dlsym(driverhandle, "SDF_GenerateRandom");
|
||||
standardinterfaces->InternalEncrypt = (StandardEncrypt_type)dlsym(driverhandle, "SDF_Encrypt");
|
||||
standardinterfaces->InternalDecrypt = (StandardDecrypt_type)dlsym(driverhandle, "SDF_Decrypt");
|
||||
standardinterfaces->InternalDestroyKey = (StandardDestroyKey_type)dlsym(driverhandle, "SDF_DestroyKey");
|
||||
standardinterfaces->InternalHashInit = (StandardHashInit_type)dlsym(driverhandle, "SDF_HashInit");
|
||||
standardinterfaces->InternalHashUpdate = (StandardHashUpdate_type)dlsym(driverhandle, "SDF_HashUpdate");
|
||||
standardinterfaces->InternalHashFinal = (StandardHashFinal_type)dlsym(driverhandle, "SDF_HashFinal");
|
||||
|
||||
if (standardinterfaces->InternalOpenDevice == NULL
|
||||
|| standardinterfaces->InternalCloseDevice == NULL
|
||||
|| standardinterfaces->InternalOpenSession == NULL
|
||||
|| standardinterfaces->InternalCloseSession == NULL
|
||||
|| standardinterfaces->InternalGenerateRandom == NULL
|
||||
|| standardinterfaces->InternalEncrypt == NULL
|
||||
|| standardinterfaces->InternalDecrypt == NULL
|
||||
|| standardinterfaces->InternalDestroyKey == NULL
|
||||
|| standardinterfaces->InternalHashInit == NULL
|
||||
|| standardinterfaces->InternalHashUpdate == NULL
|
||||
|| standardinterfaces->InternalHashFinal == NULL) {
|
||||
|
||||
return CRYPTO_MOD_DLSYM_ERR;
|
||||
}
|
||||
|
||||
return CRYPT_MOD_OK;
|
||||
}
|
||||
|
||||
static int load_gdac_interfaces(ModuleGdacInterfaces* gdacinterfaces)
|
||||
{
|
||||
gdacinterfaces->GDACGenerateKEK = (GDACGenerateKEK_type)dlsym(driverhandle, "SDFE_GenerateKEK");
|
||||
gdacinterfaces->GDACHMAC = (GDACHMAC_type)dlsym(driverhandle, "SDFE_Hmac");
|
||||
gdacinterfaces->GDACEncryptWithIndex = (GDACEncryptWithIndex_type)dlsym(driverhandle, "SDFE_Encrypt");
|
||||
gdacinterfaces->GDACDecryptWithIndex = (GDACDecryptWithIndex_type)dlsym(driverhandle, "SDFE_Decrypt");
|
||||
gdacinterfaces->GDACExportKEK = (GDACExportKEK_type)dlsym(driverhandle, "SDFE_ExportKEK");
|
||||
gdacinterfaces->GDACGetkeyState = (GDACGetkeyState_type)dlsym(driverhandle, "SDFE_GetkeyState");
|
||||
|
||||
if (gdacinterfaces->GDACGenerateKEK == NULL
|
||||
|| gdacinterfaces->GDACHMAC == NULL
|
||||
|| gdacinterfaces->GDACEncryptWithIndex == NULL
|
||||
|| gdacinterfaces->GDACDecryptWithIndex == NULL
|
||||
|| gdacinterfaces->GDACExportKEK == NULL
|
||||
|| gdacinterfaces->GDACGetkeyState == NULL) {
|
||||
|
||||
return CRYPTO_MOD_DLSYM_ERR;
|
||||
}
|
||||
|
||||
return CRYPT_MOD_OK;
|
||||
}
|
||||
|
||||
static int load_jnta_interfaces(ModuleJntaInterfaces* jntainterfaces)
|
||||
{
|
||||
jntainterfaces->JNTACalculateHmac = (JNTACalculateHmac_type)dlsym(driverhandle, "Tass_CalculateHmac");
|
||||
jntainterfaces->JNTAGenerateSymmKeyWithLMK = (JNTAGenerateSymmKeyWithLMK_type)dlsym(driverhandle, "Tass_GenerateSymmKeyWithLMK");
|
||||
jntainterfaces->JNTAImportKeyCipherByLMK = (JNTAImportKeyCipherByLMK_type)dlsym(driverhandle, "Tass_ImportKeyCipherByLMK");
|
||||
|
||||
if (jntainterfaces->JNTACalculateHmac == NULL
|
||||
|| jntainterfaces->JNTAGenerateSymmKeyWithLMK == NULL
|
||||
|| jntainterfaces->JNTAImportKeyCipherByLMK == NULL) {
|
||||
|
||||
return CRYPTO_MOD_DLSYM_ERR;
|
||||
}
|
||||
|
||||
return CRYPT_MOD_OK;
|
||||
}
|
||||
|
||||
static int load_swxa_interfaces(ModuleSwxaInterfaces* swxainterfaces)
|
||||
{
|
||||
swxainterfaces->SWXAGenerateKeyCipher = (SWXAGenerateKeyCipher_type)dlsym(driverhandle, "SDF_GenerateKey_Cipher");
|
||||
swxainterfaces->SWXAEncKeyEncrypt = (SWXAEncKeyEncrypt_type)dlsym(driverhandle, "SDF_EncKeyEncrypt");
|
||||
swxainterfaces->SWXAEncKeyDecrypt = (SWXAEncKeyDecrypt_type)dlsym(driverhandle, "SDF_EncKeyDecrypt");
|
||||
swxainterfaces->SWXAHMAC = (SWXAHMAC_type)dlsym(driverhandle, "SDF_EncKeyHMAC");
|
||||
swxainterfaces->SWXAOpenDeviceWithPathAndName = (SWXAOpenDeviceWithPathAndName_type)dlsym(driverhandle, "SDF_OpenDeviceWithPathAndName");
|
||||
|
||||
if (swxainterfaces->SWXAGenerateKeyCipher == NULL
|
||||
|| swxainterfaces->SWXAEncKeyEncrypt == NULL
|
||||
|| swxainterfaces->SWXAEncKeyDecrypt == NULL
|
||||
|| swxainterfaces->SWXAHMAC == NULL
|
||||
|| swxainterfaces->SWXAOpenDeviceWithPathAndName == NULL) {
|
||||
|
||||
return CRYPTO_MOD_DLSYM_ERR;
|
||||
}
|
||||
|
||||
return CRYPT_MOD_OK;
|
||||
}
|
||||
|
||||
/*加载驱动库*/
|
||||
int load_module_driver(ModuleParams moduleparams)
|
||||
{
|
||||
|
||||
int ret = CRYPT_MOD_OK;
|
||||
|
||||
/*加写锁*/
|
||||
internal_lock(INTERNAL_EXCLUSIVE_LOCK, &drivermutex);
|
||||
|
||||
/*检查是否已经加载,如果已经加载过,则直接返回*/
|
||||
if (driverhandle && moduleinterfaces) {
|
||||
internal_unlock(&drivermutex);
|
||||
return CRYPT_MOD_OK;
|
||||
}
|
||||
|
||||
/*dlopen动态库*/
|
||||
driverhandle = dlopen(moduleparams.libpath, RTLD_LAZY);
|
||||
if (driverhandle == NULL) {
|
||||
internal_unlock(&drivermutex);
|
||||
return CRYPTO_MOD_DLOPEN_ERR;
|
||||
}
|
||||
|
||||
/*为接口分配空间*/
|
||||
moduleinterfaces = (ModuleInterfaces*)malloc(sizeof(ModuleInterfaces));
|
||||
|
||||
moduleinterfaces->type = moduleparams.moduletype;
|
||||
|
||||
moduleinterfaces->standardInterfaces = (ModuleStandardInterfaces*)malloc(sizeof(ModuleStandardInterfaces));
|
||||
|
||||
/*加载标准接口*/
|
||||
ret = load_standard_interfaces(moduleinterfaces->standardInterfaces);
|
||||
if (ret != CRYPT_MOD_OK) {
|
||||
free(moduleinterfaces->standardInterfaces);
|
||||
free(moduleinterfaces);
|
||||
internal_unlock(&drivermutex);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*加载扩展接口*/
|
||||
switch (moduleparams.moduletype)
|
||||
{
|
||||
case MODULE_GDAC_CARD_TYPE:
|
||||
moduleinterfaces->extendInterfaces.gdacInterfaces = (ModuleGdacInterfaces*)malloc(sizeof(ModuleGdacInterfaces));
|
||||
ret = load_gdac_interfaces(moduleinterfaces->extendInterfaces.gdacInterfaces);
|
||||
break;
|
||||
case MODULE_JNTA_KMS_TYPE:
|
||||
moduleinterfaces->extendInterfaces.jntaInterfaces = (ModuleJntaInterfaces*)malloc(sizeof(ModuleJntaInterfaces));
|
||||
ret = load_jnta_interfaces(moduleinterfaces->extendInterfaces.jntaInterfaces);
|
||||
break;
|
||||
case MODULE_SWXA_KMS_TYPE:
|
||||
moduleinterfaces->extendInterfaces.swxaInterfaces = (ModuleSwxaInterfaces*)malloc(sizeof(ModuleSwxaInterfaces));
|
||||
ret = load_swxa_interfaces(moduleinterfaces->extendInterfaces.swxaInterfaces);
|
||||
break;
|
||||
default:
|
||||
free(moduleinterfaces->standardInterfaces);
|
||||
free(moduleinterfaces);
|
||||
internal_unlock(&drivermutex);
|
||||
return CRYPTO_MOD_TYPE_INVALID_ERR;
|
||||
}
|
||||
|
||||
if (ret != CRYPT_MOD_OK) {
|
||||
if (moduleinterfaces->extendInterfaces.gdacInterfaces)
|
||||
free(moduleinterfaces->extendInterfaces.gdacInterfaces);
|
||||
if (moduleinterfaces->extendInterfaces.jntaInterfaces)
|
||||
free(moduleinterfaces->extendInterfaces.jntaInterfaces);
|
||||
if (moduleinterfaces->extendInterfaces.swxaInterfaces)
|
||||
free(moduleinterfaces->extendInterfaces.swxaInterfaces);
|
||||
free(moduleinterfaces->standardInterfaces);
|
||||
free(moduleinterfaces);
|
||||
moduleinterfaces = NULL;
|
||||
internal_unlock(&drivermutex);
|
||||
return ret;
|
||||
}
|
||||
|
||||
internal_unlock(&drivermutex);
|
||||
return CRYPT_MOD_OK;
|
||||
|
||||
}
|
||||
|
||||
int unload_module_driver()
|
||||
{
|
||||
/*加写锁*/
|
||||
internal_lock(INTERNAL_EXCLUSIVE_LOCK, &drivermutex);
|
||||
if (driverhandle == NULL || moduleinterfaces) {
|
||||
|
||||
internal_unlock(&drivermutex);
|
||||
return CRYPTO_MOD_UNLOAD_ERR;
|
||||
}
|
||||
|
||||
/*释放接口空间*/
|
||||
|
||||
if (moduleinterfaces->extendInterfaces.gdacInterfaces) {
|
||||
free(moduleinterfaces->extendInterfaces.gdacInterfaces);
|
||||
moduleinterfaces->extendInterfaces.gdacInterfaces = NULL;
|
||||
}
|
||||
|
||||
if (moduleinterfaces->extendInterfaces.jntaInterfaces) {
|
||||
free(moduleinterfaces->extendInterfaces.jntaInterfaces);
|
||||
moduleinterfaces->extendInterfaces.jntaInterfaces = NULL;
|
||||
}
|
||||
|
||||
if (moduleinterfaces->extendInterfaces.swxaInterfaces) {
|
||||
free(moduleinterfaces->extendInterfaces.swxaInterfaces);
|
||||
moduleinterfaces->extendInterfaces.swxaInterfaces = NULL;
|
||||
}
|
||||
|
||||
free(moduleinterfaces->standardInterfaces);
|
||||
moduleinterfaces->standardInterfaces = NULL;
|
||||
|
||||
free(moduleinterfaces);
|
||||
moduleinterfaces = NULL;
|
||||
|
||||
dlclose(driverhandle);
|
||||
driverhandle = NULL;
|
||||
|
||||
internal_unlock(&drivermutex);
|
||||
|
||||
return CRYPT_MOD_OK;
|
||||
|
||||
}
|
||||
|
||||
int internal_open_device(char* cfg_path)
|
||||
{
|
||||
/*这里调用密码硬件的接口,需要注意硬件接口返回0表示成功。*/
|
||||
int ret = INTERNAL_OK;
|
||||
|
||||
/*判断是否已加载驱动并加载驱动接口*/
|
||||
internal_lock(INTERNAL_SHARED_LOCK, &drivermutex);
|
||||
|
||||
if (driverhandle == NULL || moduleinterfaces == NULL) {
|
||||
internal_unlock(&drivermutex);
|
||||
return CRYPTO_MOD_NOT_LOADED_ERR;
|
||||
}
|
||||
|
||||
/*大胆一些,在这里释放掉锁*/
|
||||
internal_unlock(&drivermutex);
|
||||
|
||||
/*对设备句柄加写锁*/
|
||||
internal_lock(INTERNAL_EXCLUSIVE_LOCK, &devicehandlemutex);
|
||||
|
||||
/*已经打开过,直接返回*/
|
||||
if (devicehandle != NULL) {
|
||||
internal_unlock(&devicehandlemutex);
|
||||
return CRYPT_MOD_OK;
|
||||
}
|
||||
|
||||
switch (moduleinterfaces->type)
|
||||
{
|
||||
case MODULE_GDAC_CARD_TYPE:
|
||||
ret = moduleinterfaces->standardInterfaces->InternalOpenDevice(&devicehandle);
|
||||
break;
|
||||
case MODULE_SWXA_KMS_TYPE:
|
||||
ret = moduleinterfaces->extendInterfaces.swxaInterfaces->SWXAOpenDeviceWithPathAndName((unsigned char*)cfg_path, &devicehandle);
|
||||
break;
|
||||
case MODULE_JNTA_KMS_TYPE:
|
||||
/*江南天安从环境变量获取配置文件路径,这里设置一下*/
|
||||
SET_JNTA_CFG_PATH(cfg_path);
|
||||
ret = moduleinterfaces->standardInterfaces->InternalOpenDevice(&devicehandle);
|
||||
break;
|
||||
default:
|
||||
internal_unlock(&devicehandlemutex);
|
||||
return CRYPTO_MOD_TYPE_INVALID_ERR;
|
||||
}
|
||||
|
||||
internal_unlock(&devicehandlemutex);
|
||||
|
||||
INTERNAL_RETURN(ret);
|
||||
|
||||
}
|
||||
|
||||
int internal_close_device()
|
||||
{
|
||||
int ret = INTERNAL_OK;
|
||||
|
||||
internal_lock(INTERNAL_EXCLUSIVE_LOCK, &devicehandlemutex);
|
||||
|
||||
if (devicehandle != NULL) {
|
||||
ret = moduleinterfaces->standardInterfaces->InternalCloseDevice(devicehandle);
|
||||
devicehandle = NULL;
|
||||
}
|
||||
|
||||
internal_unlock(&devicehandlemutex);
|
||||
|
||||
INTERNAL_RETURN(ret);
|
||||
}
|
||||
|
||||
int internal_open_session(void **sess)
|
||||
{
|
||||
int ret = INTERNAL_OK;
|
||||
|
||||
internal_lock(INTERNAL_SHARED_LOCK, &devicehandlemutex);
|
||||
|
||||
if (devicehandle == NULL) {
|
||||
internal_unlock(&devicehandlemutex);
|
||||
return CRYPTO_MOD_NOT_OPENDEVICE_ERR;
|
||||
}
|
||||
|
||||
ret = moduleinterfaces->standardInterfaces->InternalOpenSession(devicehandle, sess);
|
||||
|
||||
internal_unlock(&devicehandlemutex);
|
||||
|
||||
INTERNAL_RETURN(ret);
|
||||
}
|
||||
|
||||
int internal_close_session(void *sess)
|
||||
{
|
||||
int ret = INTERNAL_OK;
|
||||
|
||||
if (sess == NULL) {
|
||||
return CRYPTO_MOD_NOT_OPENSESSION_ERR;
|
||||
}
|
||||
|
||||
internal_lock(INTERNAL_SHARED_LOCK, &devicehandlemutex);
|
||||
|
||||
if (devicehandle == NULL) {
|
||||
internal_unlock(&devicehandlemutex);
|
||||
return CRYPTO_MOD_NOT_OPENDEVICE_ERR;
|
||||
}
|
||||
|
||||
ret = moduleinterfaces->standardInterfaces->InternalCloseSession(sess);
|
||||
|
||||
internal_unlock(&devicehandlemutex);
|
||||
|
||||
INTERNAL_RETURN(ret);
|
||||
}
|
||||
|
||||
static bool use_key_index()
|
||||
{
|
||||
switch (moduleinterfaces->type) {
|
||||
case MODULE_GDAC_CARD_TYPE:
|
||||
case MODULE_JNTA_KMS_TYPE:
|
||||
return true;
|
||||
case MODULE_SWXA_KMS_TYPE:
|
||||
return false;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static int init_gdac_key_index(void* sess)
|
||||
{
|
||||
int keystatus = 0;
|
||||
int i =0;
|
||||
int ret = INTERNAL_OK;
|
||||
|
||||
/*需要获取当前存在密钥的最大索引值*/
|
||||
for (i = INTERNAL_MIN_INDEX_NUM; i <= INTERNAL_MAX_INDEX_NUM; i++) {
|
||||
ret = moduleinterfaces->extendInterfaces.gdacInterfaces->GDACGetkeyState(sess, GDAC_KEK_TYPE, (unsigned int)i, (unsigned int*)&keystatus);
|
||||
if (ret != INTERNAL_OK) {
|
||||
return ret;
|
||||
}
|
||||
if (keystatus == GDAC_KEY_NOT_EXIST) {
|
||||
currnetindex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (i == (INTERNAL_MAX_INDEX_NUM + 1)) {
|
||||
return INTERNAL_NOBUFFER;
|
||||
}
|
||||
|
||||
return INTERNAL_OK;
|
||||
}
|
||||
|
||||
static int init_jnta_key_index(void* sess)
|
||||
{
|
||||
int ret = INTERNAL_OK;
|
||||
int i = 0;
|
||||
InternalKeyCtx *keyctx = NULL;
|
||||
|
||||
unsigned char tmpdata[] = {"12345678"};
|
||||
int tmplen = 8;
|
||||
|
||||
unsigned char tmpiv[] = {"1234567812345678"};
|
||||
int tmpivlen = 16;
|
||||
|
||||
unsigned char tmpout[32] = {0};
|
||||
unsigned int tmpoutlen = 0;
|
||||
keyctx = (InternalKeyCtx*)malloc(sizeof(InternalKeyCtx));
|
||||
|
||||
keyctx->session = sess;
|
||||
|
||||
keyctx->enc = INTERNAL_DO_ENC;
|
||||
|
||||
keyctx->algotype = TA_SM4;
|
||||
keyctx->algomode = TA_CBC;
|
||||
|
||||
/*需要获取当前存在密钥的最大索引值*/
|
||||
for (i = INTERNAL_MIN_INDEX_NUM; i <= INTERNAL_MAX_INDEX_NUM; i++) {
|
||||
sprintf((char *)(keyctx->key), "%d",i);
|
||||
keyctx->keysize = strlen((char*)(keyctx->key));
|
||||
/*没有获取密钥状态接口,通过做加密判断错误发为密钥不存在*/
|
||||
ret = internal_symm_encrypt(keyctx, tmpdata, tmplen, tmpiv, tmpivlen, tmpout, &tmpoutlen, NULL);
|
||||
if (ret == INTERNAL_KEYNOTEXIST) {
|
||||
currnetindex = i;
|
||||
break;
|
||||
}
|
||||
memset(keyctx->key, 0x0, INTERNAL_MAX_KEY_LEN);
|
||||
}
|
||||
|
||||
free(keyctx);
|
||||
|
||||
if (i == (INTERNAL_MAX_INDEX_NUM + 1)) {
|
||||
return INTERNAL_NOBUFFER;
|
||||
}
|
||||
|
||||
return INTERNAL_OK;
|
||||
|
||||
}
|
||||
static int init_current_key_index(void* sess)
|
||||
{
|
||||
int ret = INTERNAL_OK;
|
||||
|
||||
switch (moduleinterfaces->type) {
|
||||
case MODULE_GDAC_CARD_TYPE:
|
||||
ret = init_gdac_key_index(sess);
|
||||
break;
|
||||
case MODULE_JNTA_KMS_TYPE:
|
||||
ret = init_jnta_key_index(sess);
|
||||
break;
|
||||
case MODULE_SWXA_KMS_TYPE:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
|
||||
int internal_generate_symm_key(void* sess, ModuleSymmKeyAlgo algo, unsigned char* key, unsigned int* keylen)
|
||||
{
|
||||
int ret = INTERNAL_OK;
|
||||
bool useindex = use_key_index();
|
||||
|
||||
if (sess == NULL) {
|
||||
return CRYPTO_MOD_NOT_OPENSESSION_ERR;
|
||||
}
|
||||
|
||||
if (useindex) {
|
||||
pthread_mutex_lock(&genkeymutex);
|
||||
if (currnetindex == 0) {
|
||||
ret = init_current_key_index(sess);
|
||||
if (ret != INTERNAL_OK) {
|
||||
pthread_mutex_unlock(&genkeymutex);
|
||||
return ret;
|
||||
}
|
||||
} else if (currnetindex == (INTERNAL_MAX_INDEX_NUM + 1)) {
|
||||
pthread_mutex_unlock(&genkeymutex);
|
||||
return INTERNAL_NOBUFFER;
|
||||
}
|
||||
}
|
||||
|
||||
switch(moduleinterfaces->type) {
|
||||
case MODULE_GDAC_CARD_TYPE:
|
||||
ret = moduleinterfaces->extendInterfaces.gdacInterfaces->GDACGenerateKEK(sess, get_key_len_by_algo_type(algo), currnetindex);
|
||||
break;
|
||||
case MODULE_JNTA_KMS_TYPE: {
|
||||
unsigned int realalgo;
|
||||
unsigned int realmode;
|
||||
unsigned char tmpcipher[INTERNAL_MAX_KEY_LEN + 1] = {0};
|
||||
unsigned int tmpcipherlen = 0;
|
||||
unsigned char kcv[8] = {0};
|
||||
unsigned int kcvlen = 0;
|
||||
|
||||
ret = get_real_symm_algo_type(moduleinterfaces->type, algo, &realalgo, &realmode);
|
||||
if (ret != CRYPT_MOD_OK)
|
||||
break;
|
||||
ret = moduleinterfaces->extendInterfaces.jntaInterfaces->JNTAGenerateSymmKeyWithLMK(sess, (TA_SYMM_ALG)realalgo, tmpcipher, &tmpcipherlen, kcv, &kcvlen);
|
||||
if (ret != INTERNAL_OK)
|
||||
break;
|
||||
ret = moduleinterfaces->extendInterfaces.jntaInterfaces->JNTAImportKeyCipherByLMK(sess, currnetindex, 0, 0, (TA_SYMM_ALG)realalgo, 0, NULL, 0, NULL, 0, tmpcipher, tmpcipherlen, kcv, 0);
|
||||
if (ret != INTERNAL_OK)
|
||||
break;
|
||||
break;
|
||||
}
|
||||
case MODULE_SWXA_KMS_TYPE:
|
||||
ret = moduleinterfaces->extendInterfaces.swxaInterfaces->SWXAGenerateKeyCipher(sess, get_key_len_by_algo_type(algo), key, keylen);
|
||||
break;
|
||||
default:
|
||||
ret = CRYPTO_MOD_TYPE_INVALID_ERR;
|
||||
break;
|
||||
}
|
||||
|
||||
if (useindex) {
|
||||
if (ret != CRYPT_MOD_OK && ret != INTERNAL_OK) {
|
||||
pthread_mutex_unlock(&genkeymutex);
|
||||
return ret;
|
||||
} else {
|
||||
sprintf((char*)key, "%d",currnetindex);
|
||||
*keylen = strlen((char*)key);
|
||||
currnetindex++;
|
||||
pthread_mutex_unlock(&genkeymutex);
|
||||
return CRYPT_MOD_OK;
|
||||
}
|
||||
}
|
||||
|
||||
if (ret != CRYPT_MOD_OK && ret != INTERNAL_OK) {
|
||||
return ret;
|
||||
} else {
|
||||
return CRYPT_MOD_OK;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int internal_symm_encrypt(void *keyctx, unsigned char *indata, unsigned int inlen, unsigned char *iv, unsigned int ivlen, unsigned char *outdata, unsigned int *outlen, unsigned char *tag)
|
||||
{
|
||||
int ret = INTERNAL_OK;
|
||||
|
||||
InternalKeyCtx *tmpctx = (InternalKeyCtx *)keyctx;
|
||||
unsigned char *paddingdata = NULL;
|
||||
int paddinglen = 0;
|
||||
unsigned char tmpiv[INTERNAL_IV_LEN + 1] = {0};
|
||||
|
||||
memcpy(tmpiv, iv, ivlen);
|
||||
paddinglen = inlen + INTERNAL_BLOCK_LEN + 1;
|
||||
paddingdata = (unsigned char *)malloc(paddinglen);
|
||||
|
||||
memset(paddingdata, 0x0, paddinglen);
|
||||
internal_padding((char*)indata, inlen, (char*)paddingdata, &paddinglen);
|
||||
|
||||
switch (moduleinterfaces->type) {
|
||||
case MODULE_GDAC_CARD_TYPE: {
|
||||
unsigned char tmpkey[INTERNAL_MAX_KEY_LEN] = {0};
|
||||
unsigned int keylen = 0;
|
||||
ret = moduleinterfaces->extendInterfaces.gdacInterfaces->GDACExportKEK(tmpctx->session, atoi((char*)tmpctx->key), tmpkey, &keylen);
|
||||
if (ret != INTERNAL_OK)
|
||||
return ret;
|
||||
ret = moduleinterfaces->extendInterfaces.gdacInterfaces->GDACEncryptWithIndex(tmpctx->session, tmpkey, keylen, tmpctx->algotype, tmpiv, ivlen, paddingdata, paddinglen, outdata, outlen, NULL, 0, NULL);
|
||||
break;
|
||||
}
|
||||
case MODULE_JNTA_KMS_TYPE: {
|
||||
int tmpindex = atoi((char*)(tmpctx->key));
|
||||
unsigned int standardtype = 0;
|
||||
transform_jnta_algo_type(tmpctx->algotype, tmpctx->algomode, &standardtype);
|
||||
ret = moduleinterfaces->standardInterfaces->InternalEncrypt(tmpctx->session, (void*)&tmpindex, standardtype, tmpiv, paddingdata, paddinglen, outdata, outlen);
|
||||
break;
|
||||
}
|
||||
case MODULE_SWXA_KMS_TYPE:
|
||||
ret = moduleinterfaces->extendInterfaces.swxaInterfaces->SWXAEncKeyEncrypt(tmpctx->session, tmpctx->key, tmpctx->keysize, tmpctx->algotype, tmpiv, paddingdata, paddinglen, outdata, outlen);
|
||||
break;
|
||||
default:
|
||||
ret = CRYPTO_MOD_TYPE_INVALID_ERR;
|
||||
break;;
|
||||
}
|
||||
|
||||
free(paddingdata);
|
||||
|
||||
INTERNAL_RETURN(ret);
|
||||
|
||||
}
|
||||
|
||||
int internal_symm_decrypt(void *keyctx, unsigned char *indata, unsigned int inlen, unsigned char *iv, unsigned int ivlen, unsigned char *outdata, unsigned int *outlen, unsigned char *tag)
|
||||
{
|
||||
int ret = INTERNAL_OK;
|
||||
|
||||
InternalKeyCtx *tmpctx = (InternalKeyCtx *)keyctx;
|
||||
unsigned char tmpiv[INTERNAL_IV_LEN + 1] = {0};
|
||||
|
||||
memcpy(tmpiv, iv, ivlen);
|
||||
|
||||
switch (moduleinterfaces->type) {
|
||||
case MODULE_GDAC_CARD_TYPE: {
|
||||
unsigned char tmpkey[INTERNAL_MAX_KEY_LEN] = {0};
|
||||
unsigned int keylen = 0;
|
||||
ret = moduleinterfaces->extendInterfaces.gdacInterfaces->GDACExportKEK(tmpctx->session, atoi((char*)tmpctx->key), tmpkey, &keylen);
|
||||
if (ret != INTERNAL_OK)
|
||||
return ret;
|
||||
ret = moduleinterfaces->extendInterfaces.gdacInterfaces->GDACDecryptWithIndex(tmpctx->session, tmpkey, keylen, tmpctx->algotype, tmpiv, ivlen, indata, inlen, outdata, outlen, NULL, 0, NULL);
|
||||
break;
|
||||
}
|
||||
case MODULE_JNTA_KMS_TYPE: {
|
||||
int index = atoi((char *)(tmpctx->key));
|
||||
unsigned int standardtype = 0;
|
||||
transform_jnta_algo_type(tmpctx->algotype, tmpctx->algomode, &standardtype);
|
||||
ret = moduleinterfaces->standardInterfaces->InternalDecrypt(tmpctx->session, (void*)&index, standardtype, tmpiv, indata, inlen, outdata, outlen);
|
||||
break;
|
||||
}
|
||||
case MODULE_SWXA_KMS_TYPE:
|
||||
ret = moduleinterfaces->extendInterfaces.swxaInterfaces->SWXAEncKeyDecrypt(tmpctx->session, tmpctx->key, tmpctx->keysize, tmpctx->algotype, tmpiv, indata, inlen, outdata, outlen);
|
||||
break;
|
||||
default:
|
||||
ret = CRYPTO_MOD_TYPE_INVALID_ERR;
|
||||
break;
|
||||
}
|
||||
|
||||
if (ret == INTERNAL_OK) {
|
||||
return internal_unpadding((char*)outdata, (int*)outlen);
|
||||
}
|
||||
|
||||
INTERNAL_RETURN(ret);
|
||||
|
||||
}
|
||||
|
||||
int internal_digest(void *sess, ModuleDigestAlgo algo, unsigned char * indata, unsigned int inlen, unsigned char *outdata, unsigned int *outlen)
|
||||
{
|
||||
int ret = CRYPT_MOD_OK;
|
||||
unsigned int realtype = 0;
|
||||
int position = 0;
|
||||
int updatelen = 0;
|
||||
|
||||
ret = get_real_digest_algo_type(moduleinterfaces->type, algo, &realtype);
|
||||
if (ret != CRYPT_MOD_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = moduleinterfaces->standardInterfaces->InternalHashInit(sess, realtype, NULL, NULL, 0);
|
||||
if (ret != INTERNAL_OK)
|
||||
return ret;
|
||||
|
||||
while (inlen) {
|
||||
if (inlen >= INTERNAL_MSG_BLOCK_LEN) {
|
||||
updatelen = INTERNAL_MSG_BLOCK_LEN;
|
||||
inlen -= INTERNAL_MSG_BLOCK_LEN;
|
||||
} else {
|
||||
updatelen = inlen;
|
||||
inlen = 0;
|
||||
}
|
||||
|
||||
ret = moduleinterfaces->standardInterfaces->InternalHashUpdate(sess, indata + position, updatelen);
|
||||
if (ret != INTERNAL_OK)
|
||||
return ret;
|
||||
position += updatelen;
|
||||
}
|
||||
|
||||
ret = moduleinterfaces->standardInterfaces->InternalHashFinal(sess, outdata, outlen);
|
||||
|
||||
INTERNAL_RETURN(ret);
|
||||
}
|
||||
|
||||
/*如果传入的data为NULL,并且data_size为0,则对key自身做hmac*/
|
||||
int internal_hmac(void *ctx, unsigned char * data, unsigned int data_size, unsigned char *result, size_t *result_size)
|
||||
{
|
||||
int ret = INTERNAL_OK;
|
||||
|
||||
InternalKeyCtx *tmpctx = (InternalKeyCtx *)ctx;
|
||||
|
||||
switch (moduleinterfaces->type) {
|
||||
case MODULE_GDAC_CARD_TYPE:{
|
||||
unsigned char tmpkey[INTERNAL_MAX_KEY_LEN] = {0};
|
||||
unsigned int keylen = 0;
|
||||
ret = moduleinterfaces->extendInterfaces.gdacInterfaces->GDACExportKEK(tmpctx->session, atoi((char*)tmpctx->key), tmpkey, &keylen);
|
||||
if (ret != INTERNAL_OK)
|
||||
return ret;
|
||||
ret = moduleinterfaces->extendInterfaces.gdacInterfaces->GDACHMAC(tmpctx->session, tmpkey, keylen, tmpctx->algotype,
|
||||
(data != NULL) ? data : tmpkey, (data_size != 0) ? data_size : keylen, result, (unsigned int*)result_size);
|
||||
memset(tmpkey,0x0,INTERNAL_MAX_KEY_LEN);
|
||||
break;
|
||||
}
|
||||
case MODULE_JNTA_KMS_TYPE:{
|
||||
ret = moduleinterfaces->extendInterfaces.jntaInterfaces->JNTACalculateHmac(tmpctx->session, (TA_HMAC_ALG)tmpctx->algotype, atoi((char*)tmpctx->key),
|
||||
NULL, 0, (data != NULL) ? data : tmpctx->key, (data_size != 0) ? data_size : tmpctx->keysize, result, (unsigned int*)result_size);
|
||||
break;
|
||||
}
|
||||
case MODULE_SWXA_KMS_TYPE:{
|
||||
ret = moduleinterfaces->extendInterfaces.swxaInterfaces->SWXAHMAC(tmpctx->session, tmpctx->key, tmpctx->keysize, tmpctx->algotype,
|
||||
(data != NULL) ? data : tmpctx->key, (data_size != 0) ? data_size : tmpctx->keysize, result, (unsigned int*)result_size);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
ret = CRYPTO_MOD_TYPE_INVALID_ERR;
|
||||
break;
|
||||
}
|
||||
|
||||
INTERNAL_RETURN(ret);
|
||||
|
||||
}
|
||||
|
||||
int internal_generate_random(void *sess, char *buffer, size_t size)
|
||||
{
|
||||
int ret = INTERNAL_OK;
|
||||
|
||||
ret = moduleinterfaces->standardInterfaces->InternalGenerateRandom(sess, size, (unsigned char*)buffer);
|
||||
|
||||
INTERNAL_RETURN(ret);
|
||||
}
|
||||
|
||||
|
||||
/*第一位补0x80,后面补0x00,强补,即如果inlen正好是16的整数倍,则补一个0x80和15个0x00,如果只缺一,则只补一个0x80*/
|
||||
static int internal_padding(char *indata, int inlen, char *outdata, int *outlen)
|
||||
{
|
||||
int i = 0;
|
||||
int firstpad = 0x80;
|
||||
int secondpad = 0x00;
|
||||
|
||||
int paddlen = 0;
|
||||
|
||||
paddlen = INTERNAL_BLOCK_LEN - inlen%INTERNAL_BLOCK_LEN;
|
||||
|
||||
memcpy(outdata, indata, inlen);
|
||||
|
||||
|
||||
for (i = 0; i < paddlen; i++) {
|
||||
if (i == 0)
|
||||
outdata[inlen + i] = firstpad;
|
||||
else
|
||||
outdata[inlen + i] = secondpad;
|
||||
}
|
||||
|
||||
*outlen = inlen + paddlen;
|
||||
|
||||
return CRYPT_MOD_OK;
|
||||
}
|
||||
|
||||
static int internal_unpadding(char *indata, int *inlen)
|
||||
{
|
||||
int firstpad = 0x80;
|
||||
int secondpad = 0x00;
|
||||
int tmplen = 0;
|
||||
|
||||
tmplen = *inlen - 1;
|
||||
|
||||
while (*(indata + tmplen) == secondpad) {
|
||||
tmplen--;
|
||||
}
|
||||
|
||||
if (tmplen >= ((*inlen) - INTERNAL_BLOCK_LEN) && *(unsigned char*)(indata + tmplen) == firstpad) {
|
||||
*inlen = tmplen;
|
||||
} else {
|
||||
return CRYPTO_MOD_UNPADDING_ERR;
|
||||
}
|
||||
|
||||
indata[tmplen] = '\0';
|
||||
|
||||
return CRYPT_MOD_OK;
|
||||
}
|
||||
|
||||
|
||||
127
contrib/common_cipher/common_internal_interfaces.h
Executable file
127
contrib/common_cipher/common_internal_interfaces.h
Executable file
@ -0,0 +1,127 @@
|
||||
#ifndef COMMON_INTERNAL_INTERFACES_H
|
||||
#define COMMON_INTERNAL_INTERFACES_H
|
||||
|
||||
#include "common_algo.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define ECCref_MAX_BITS 512
|
||||
#define ECCref_MAX_LEN ((ECCref_MAX_BITS+7) / 8)
|
||||
|
||||
/* ECC key data public key structure definition */
|
||||
typedef struct ECCrefPublicKey_st
|
||||
{
|
||||
unsigned int bits;
|
||||
unsigned char x[ECCref_MAX_LEN];
|
||||
unsigned char y[ECCref_MAX_LEN];
|
||||
} ECCrefPublicKey;
|
||||
|
||||
typedef int (*StandardOpenDevice_type)(void**);
|
||||
typedef int (*StandardCloseDevice_type)(void*);
|
||||
typedef int (*StandardOpenSession_type)(void*, void**);
|
||||
typedef int (*StandardCloseSession_type)(void*);
|
||||
typedef int (*StandardGenerateRandom_type)(void*, unsigned int, unsigned char*);
|
||||
typedef int (*StandardHashInit_type)(void*, unsigned int, ECCrefPublicKey*, unsigned char*, unsigned int);
|
||||
typedef int (*StandardHashUpdate_type)(void*, unsigned char*, unsigned int);
|
||||
typedef int (*StandardHashFinal_type)(void*, unsigned char*, unsigned int*);
|
||||
typedef int (*StandardEncrypt_type)(void*, void*, unsigned int, unsigned char*, unsigned char*, unsigned int, unsigned char*, unsigned int*);
|
||||
typedef int (*StandardDecrypt_type)(void*, void*, unsigned int, unsigned char*, unsigned char*, unsigned int, unsigned char*, unsigned int*);
|
||||
typedef int (*StandardDestroyKey_type)(void*, void*);
|
||||
|
||||
|
||||
/*SDF标准接口*/
|
||||
typedef struct {
|
||||
StandardOpenDevice_type InternalOpenDevice; /*打开设备*/
|
||||
StandardCloseDevice_type InternalCloseDevice; /*关闭设备*/
|
||||
StandardOpenSession_type InternalOpenSession; /*打开会话*/
|
||||
StandardCloseSession_type InternalCloseSession; /*关闭会话*/
|
||||
StandardGenerateRandom_type InternalGenerateRandom; /*生成随机数*/
|
||||
StandardHashInit_type InternalHashInit; /*哈希初始化*/
|
||||
StandardHashUpdate_type InternalHashUpdate; /*哈希update*/
|
||||
StandardHashFinal_type InternalHashFinal; /*哈希结束*/
|
||||
StandardEncrypt_type InternalEncrypt; /*使用密钥句柄加密*/
|
||||
StandardDecrypt_type InternalDecrypt; /*使用密钥句柄解密*/
|
||||
StandardDestroyKey_type InternalDestroyKey; /*销毁密钥句柄*/
|
||||
}ModuleStandardInterfaces;
|
||||
|
||||
|
||||
typedef int (*GDACHMAC_type)(void*, unsigned char*, unsigned int, unsigned int, unsigned char*, unsigned int, unsigned char*, unsigned int*);
|
||||
typedef int (*GDACGenerateKEK_type)(void*, unsigned int, unsigned int);
|
||||
typedef int (*GDACEncryptWithIndex_type)(void*, unsigned char*, unsigned int, unsigned int, unsigned char*, unsigned int, unsigned char*, unsigned int, unsigned char*, unsigned int*, unsigned char*, unsigned int, unsigned char*);
|
||||
typedef int (*GDACDecryptWithIndex_type)(void*, unsigned char*, unsigned int, unsigned int, unsigned char*, unsigned int, unsigned char*, unsigned int, unsigned char*, unsigned int*, unsigned char*, unsigned int, unsigned char*);
|
||||
typedef int (*GDACExportKEK_type)(void*, unsigned int, void*, unsigned int*);
|
||||
typedef int (*GDACGetkeyState_type)(void*, unsigned int, unsigned int, unsigned int*);
|
||||
|
||||
/*光电安辰扩展接口*/
|
||||
typedef struct {
|
||||
GDACHMAC_type GDACHMAC; /*hmac*/
|
||||
GDACGenerateKEK_type GDACGenerateKEK; /*生成指定索引密钥*/
|
||||
GDACEncryptWithIndex_type GDACEncryptWithIndex; /*使用索引密钥加密*/
|
||||
GDACDecryptWithIndex_type GDACDecryptWithIndex; /*使用索引密钥解密*/
|
||||
GDACExportKEK_type GDACExportKEK; /*导出KEK,不对外提供,内做索引转密钥使用*/
|
||||
GDACGetkeyState_type GDACGetkeyState; /*获取密钥状态*/
|
||||
}ModuleGdacInterfaces;
|
||||
|
||||
|
||||
typedef int (*SWXAOpenDeviceWithPathAndName_type)(unsigned char*, void **);
|
||||
typedef int (*SWXAHMAC_type)(void *, unsigned char *, unsigned int, unsigned int, unsigned char *, unsigned int, unsigned char *,unsigned int*);
|
||||
typedef int (*SWXAGenerateKeyCipher_type)(void*, unsigned int, unsigned char*, unsigned int*);
|
||||
typedef int (*SWXAEncKeyEncrypt_type)(void*, unsigned char*, unsigned int, unsigned int, unsigned char*, unsigned char*, unsigned int, unsigned char*, unsigned int*);
|
||||
typedef int (*SWXAEncKeyDecrypt_type)(void*, unsigned char*, unsigned int, unsigned int, unsigned char*, unsigned char*, unsigned int, unsigned char*, unsigned int*);
|
||||
|
||||
/*三未信安扩展接口*/
|
||||
typedef struct {
|
||||
SWXAOpenDeviceWithPathAndName_type SWXAOpenDeviceWithPathAndName; /*指定配置文件路径和名称打开设备*/
|
||||
SWXAHMAC_type SWXAHMAC; /*hmac*/
|
||||
SWXAGenerateKeyCipher_type SWXAGenerateKeyCipher; /*生成密钥密文*/
|
||||
SWXAEncKeyEncrypt_type SWXAEncKeyEncrypt; /*使用密钥密文加密*/
|
||||
SWXAEncKeyDecrypt_type SWXAEncKeyDecrypt; /*使用密钥密文解密*/
|
||||
}ModuleSwxaInterfaces;
|
||||
|
||||
|
||||
typedef int (*JNTACalculateHmac_type)(void *, TA_HMAC_ALG, unsigned int, const unsigned char*, unsigned int, unsigned char*, unsigned int, unsigned char*, unsigned int*);
|
||||
typedef int (*JNTAGenerateSymmKeyWithLMK_type)(void *, TA_SYMM_ALG, unsigned char*, unsigned int*, unsigned char*,unsigned int*);
|
||||
typedef int (*JNTAImportKeyCipherByLMK_type)(void*, unsigned int, int, int, TA_SYMM_ALG, int, const unsigned char*, unsigned int, const unsigned char*, unsigned int,
|
||||
const unsigned char*, unsigned int, const unsigned char symmKcv[8], unsigned int);
|
||||
|
||||
|
||||
/*江南天安扩展接口*/
|
||||
typedef struct {
|
||||
JNTACalculateHmac_type JNTACalculateHmac; /*hmac*/
|
||||
JNTAGenerateSymmKeyWithLMK_type JNTAGenerateSymmKeyWithLMK; /*生成LMK加密的密钥密文*/
|
||||
JNTAImportKeyCipherByLMK_type JNTAImportKeyCipherByLMK; /*导入LMK加密的密钥密文到指定的索引位置*/
|
||||
}ModuleJntaInterfaces;
|
||||
|
||||
|
||||
/*硬件提供的所有接口*/
|
||||
typedef struct {
|
||||
ModuleType type;
|
||||
ModuleStandardInterfaces *standardInterfaces;
|
||||
union {
|
||||
ModuleGdacInterfaces *gdacInterfaces;
|
||||
ModuleSwxaInterfaces *swxaInterfaces;
|
||||
ModuleJntaInterfaces *jntaInterfaces;
|
||||
}extendInterfaces;
|
||||
}ModuleInterfaces;
|
||||
|
||||
extern int load_module_driver(ModuleParams moduleparams);
|
||||
extern int unload_module_driver();
|
||||
extern int internal_open_device(char* cfg_path);
|
||||
extern int internal_close_device();
|
||||
extern int internal_open_session(void **sess);
|
||||
extern int internal_close_session(void *sess);
|
||||
extern ModuleType get_current_module_type();
|
||||
extern int internal_generate_symm_key(void* sess, ModuleSymmKeyAlgo algo, unsigned char* key, unsigned int* keylen);
|
||||
extern int internal_symm_encrypt(void *keyctx, unsigned char *indata, unsigned int inlen, unsigned char *iv, unsigned int ivlen, unsigned char *outdata, unsigned int *outlen, unsigned char *tag);
|
||||
extern int internal_symm_decrypt(void *keyctx, unsigned char *indata, unsigned int inlen, unsigned char *iv, unsigned int ivlen, unsigned char *outdata, unsigned int *outlen, unsigned char *tag);
|
||||
extern int internal_digest(void *sess, ModuleDigestAlgo algo, unsigned char * indata, unsigned int inlen, unsigned char *outdata, unsigned int *outlen);
|
||||
extern int internal_hmac(void *ctx, unsigned char * data, unsigned int data_size, unsigned char *result, long unsigned int *result_size);
|
||||
extern int internal_generate_random(void *sess, char *buffer, long unsigned int size);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* COMMON_INTERNAL_INTERFACES_H */
|
||||
155
contrib/common_cipher/common_utils.cpp
Executable file
155
contrib/common_cipher/common_utils.cpp
Executable file
@ -0,0 +1,155 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include "common_utils.h"
|
||||
#include "common_err.h"
|
||||
#include "common_algo.h"
|
||||
|
||||
/*去掉字符串头和尾的空格*/
|
||||
static char* remove_space(char *input)
|
||||
{
|
||||
int header = 0;
|
||||
int end = 0;
|
||||
int inputlen = 0;
|
||||
const char filter = ' ';
|
||||
char *tmp = NULL;
|
||||
|
||||
if (input == NULL || input[0] == '\0') {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
inputlen = strlen(input);
|
||||
|
||||
/*去头部空格*/
|
||||
while(input[header++] == filter && header < inputlen) {
|
||||
/*do nothing*/
|
||||
}
|
||||
|
||||
end = inputlen - 1;
|
||||
|
||||
/*去尾部空格*/
|
||||
while(input[end--] == filter && end >= (header - 1)) {
|
||||
/*do nothing*/
|
||||
}
|
||||
|
||||
tmp = (char*)malloc(inputlen + 1);
|
||||
memset(tmp,0x0,inputlen + 1);
|
||||
|
||||
/*初始位置为header - 1,长度为(end + 1)- (header -1) + 1*/
|
||||
memcpy(tmp, input + header - 1, end - header + 3);
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
static int set_module_params(char* k, char* v, ModuleParams *moduleparams)
|
||||
{
|
||||
if (IS_MODULE_TYPE(k)) {
|
||||
if (moduleparams->moduletype != MODULE_INVALID_TYPE) {
|
||||
return CRYPTO_MOD_TYPE_REPEATED_ERR;
|
||||
}
|
||||
|
||||
moduleparams->moduletype = GET_MODULE_TYPE(v);
|
||||
|
||||
if (moduleparams->moduletype == MODULE_INVALID_TYPE) {
|
||||
return CRYPTO_MOD_TYPE_INVALID_ERR;
|
||||
}
|
||||
} else if (IS_MODULE_LIB_PATH(k)) {
|
||||
|
||||
if (moduleparams->libpath[0] != '\0') {
|
||||
return CRYPTO_MOD_LIBPATH_REPEATED_ERR;
|
||||
}
|
||||
|
||||
if (v[0] == '\0' || strlen(v) >= MODULE_MAX_PATH_LEN) {
|
||||
return CRYPTO_MOD_LIBPATH_INVALID_ERR;
|
||||
} else {
|
||||
memcpy(moduleparams->libpath, v, strlen(v));
|
||||
}
|
||||
} else if(IS_MODULE_CONFIG_FILE_PATH(k)) {
|
||||
|
||||
if (moduleparams->cfgfilepath[0] != '\0') {
|
||||
return CRYPTO_MOD_CFG_PATH_REPEATED_ERR;
|
||||
}
|
||||
|
||||
if (v[0] == '\0' || strlen(v) >= MODULE_MAX_PATH_LEN) {
|
||||
return CRYPTO_MOD_CFG_PATH_INVALID_ERR;
|
||||
} else {
|
||||
memcpy(moduleparams->cfgfilepath, v, strlen(v));
|
||||
}
|
||||
} else {
|
||||
return CRYPTO_MOD_UNKNOWN_PARAM_ERR;
|
||||
}
|
||||
|
||||
return CRYPT_MOD_OK;
|
||||
|
||||
}
|
||||
|
||||
static int check_module_params(ModuleParams *moduleparams)
|
||||
{
|
||||
if (moduleparams->libpath[0] == '\0') {
|
||||
return CRYPTO_MOD_LIBPATH_INVALID_ERR;
|
||||
}
|
||||
|
||||
switch (moduleparams->moduletype) {
|
||||
case MODULE_GDAC_CARD_TYPE:
|
||||
/*光电安辰密码卡不需要配置文件*/
|
||||
if (moduleparams->cfgfilepath[0] != '\0') {
|
||||
return CRYPTO_MOD_PARAM_TOO_MANY_ERR;
|
||||
}
|
||||
break;
|
||||
case MODULE_JNTA_KMS_TYPE:
|
||||
/*江南天安的配置文件,需要设置为环境变量使用"TASS_GHVSM_CFG_PATH",在后面加载时自己临时设置使用*/
|
||||
if (moduleparams->cfgfilepath[0] == '\0') {
|
||||
return CRYPTO_MOD_CFG_PATH_INVALID_ERR;
|
||||
}
|
||||
break;
|
||||
case MODULE_SWXA_KMS_TYPE:
|
||||
/*三未信安kms使用带配置文件路径名称的接口*/
|
||||
if (moduleparams->cfgfilepath[0] == '\0') {
|
||||
return CRYPTO_MOD_CFG_PATH_INVALID_ERR;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return CRYPTO_MOD_TYPE_INVALID_ERR;
|
||||
}
|
||||
|
||||
return CRYPT_MOD_OK;
|
||||
}
|
||||
|
||||
int parse_module_params(char *paramsstring, ModuleParams *moduleparams)
|
||||
{
|
||||
char *p = NULL;
|
||||
char *saveptr1 = NULL;
|
||||
const char *split1 = ",";
|
||||
const char *split2 = "=";
|
||||
int ret = 0;
|
||||
|
||||
p = strtok_r(paramsstring, split1, &saveptr1);
|
||||
|
||||
while (p != NULL) {
|
||||
char *q = NULL;
|
||||
char *saveptr2 = NULL;
|
||||
char *tmp_p = NULL;
|
||||
char *tmp_ptr2 = NULL;
|
||||
q = strtok_r(p, split2, &saveptr2);
|
||||
|
||||
tmp_p = remove_space(p);
|
||||
tmp_ptr2 = remove_space(saveptr2);
|
||||
|
||||
ret = set_module_params(tmp_p, tmp_ptr2, moduleparams);
|
||||
if (ret != CRYPT_MOD_OK) {
|
||||
free(tmp_p);
|
||||
free(tmp_ptr2);
|
||||
return ret;
|
||||
}
|
||||
|
||||
free(tmp_p);
|
||||
free(tmp_ptr2);
|
||||
|
||||
q = NULL;
|
||||
p = strtok_r(NULL, split1, &saveptr1);
|
||||
}
|
||||
|
||||
return check_module_params(moduleparams);
|
||||
|
||||
}
|
||||
|
||||
52
contrib/common_cipher/common_utils.h
Executable file
52
contrib/common_cipher/common_utils.h
Executable file
@ -0,0 +1,52 @@
|
||||
#ifndef COMMON_UTILS_H
|
||||
#define COMMON_UTILS_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
MODULE_INVALID_TYPE = 0,
|
||||
MODULE_GDAC_CARD_TYPE, /*光电安辰密码卡*/
|
||||
MODULE_JNTA_KMS_TYPE, /*江南天安KMS*/
|
||||
MODULE_SWXA_KMS_TYPE /*三未信安KMS*/
|
||||
} ModuleType;
|
||||
|
||||
/*定义以下字符串宏,用来对输入的kv结构字符串做解析,获取对应的value*/
|
||||
#define MODULE_TYPE "MODULE_TYPE"
|
||||
#define MODULE_LIB_PATH "MODULE_LIB_PATH"
|
||||
#define MODULE_CONFIG_FILE_PATH "MODULE_CONFIG_FILE_PATH"
|
||||
|
||||
/*支持的硬件类型字符串*/
|
||||
#define MODULE_GDAC_CARD_STR "GDACCARD"
|
||||
#define MODULE_JNTA_KMS_STR "JNTAKMS"
|
||||
#define MODULE_SWXA_KMS_STR "SWXAKMS"
|
||||
|
||||
#define IS_GDAC_CARD_TYPE(s) (strcmp(s, MODULE_GDAC_CARD_STR) == 0)
|
||||
#define IS_JNTA_KMS_TYPE(s) (strcmp(s, MODULE_JNTA_KMS_STR) == 0)
|
||||
#define IS_SWXA_KMS_TYPE(s) (strcmp(s, MODULE_SWXA_KMS_STR) == 0)
|
||||
|
||||
/*字符串转为枚举类型*/
|
||||
#define GET_MODULE_TYPE(s) (IS_GDAC_CARD_TYPE(s) ? MODULE_GDAC_CARD_TYPE \
|
||||
: IS_JNTA_KMS_TYPE(s) ? MODULE_JNTA_KMS_TYPE \
|
||||
: IS_SWXA_KMS_TYPE(s) ? MODULE_SWXA_KMS_TYPE : MODULE_INVALID_TYPE)
|
||||
|
||||
#define IS_MODULE_TYPE(s) (strcmp(s, MODULE_TYPE) == 0)
|
||||
#define IS_MODULE_LIB_PATH(s) (strcmp(s, MODULE_LIB_PATH) == 0)
|
||||
#define IS_MODULE_CONFIG_FILE_PATH(s) (strcmp(s, MODULE_CONFIG_FILE_PATH) == 0)
|
||||
|
||||
#define MODULE_MAX_PATH_LEN 1024
|
||||
|
||||
typedef struct {
|
||||
ModuleType moduletype;
|
||||
char libpath[MODULE_MAX_PATH_LEN];
|
||||
char cfgfilepath[MODULE_MAX_PATH_LEN];
|
||||
}ModuleParams;
|
||||
|
||||
extern int parse_module_params(char *paramsstring, ModuleParams *moduleparams);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* COMMON_UTILS_H */
|
||||
321
contrib/common_cipher/test.cpp
Executable file
321
contrib/common_cipher/test.cpp
Executable file
@ -0,0 +1,321 @@
|
||||
#include<pthread.h>
|
||||
#include<dlfcn.h>
|
||||
#include<stdlib.h>
|
||||
#include<stdio.h>
|
||||
#include<string.h>
|
||||
|
||||
#define MAX_PROVIDER_NAME_LEN 128
|
||||
#define MAX_ERRMSG_LEN 256
|
||||
|
||||
static pthread_rwlock_t drivermutex;
|
||||
|
||||
typedef enum {
|
||||
MODULE_AES_128_CBC = 0,
|
||||
MODULE_AES_128_CTR,
|
||||
MODULE_AES_128_GCM,
|
||||
MODULE_AES_256_CBC,
|
||||
MODULE_AES_256_CTR,
|
||||
MODULE_AES_256_GCM,
|
||||
MODULE_SM4_CBC,
|
||||
MODULE_SM4_CTR,
|
||||
MODULE_HMAC_SHA256,
|
||||
MODULE_HMAC_SM3,
|
||||
MODULE_DETERMINISTIC_KEY,
|
||||
MODULE_ALGO_MAX = 1024
|
||||
} ModuleSymmKeyAlgo;
|
||||
|
||||
|
||||
typedef enum {
|
||||
MODULE_SHA256 = 0,
|
||||
MODULE_SM3,
|
||||
MODULE_DIGEST_MAX = 1024
|
||||
} ModuleDigestAlgo;
|
||||
|
||||
|
||||
typedef enum {
|
||||
KEY_TYPE_INVALID,
|
||||
KEY_TYPE_PLAINTEXT,
|
||||
KEY_TYPE_CIPHERTEXT,
|
||||
KEY_TYPE_NAMEORIDX,
|
||||
KEY_TYPE_MAX
|
||||
} KeyType;
|
||||
|
||||
|
||||
typedef struct {
|
||||
char provider_name[MAX_PROVIDER_NAME_LEN];
|
||||
KeyType key_type;
|
||||
int supported_symm[MODULE_ALGO_MAX]; // 不支持算法填入0或者支持算法填入1
|
||||
int supported_digest[MODULE_DIGEST_MAX]; // 不支持算法填入0或者支持算法填入1
|
||||
} SupportedFeature;
|
||||
|
||||
|
||||
typedef int (*crypto_module_init_type)(char *load_info, SupportedFeature *supported_feature);
|
||||
typedef int (*crypto_module_sess_init_type)(char *key_info, void **sess);
|
||||
typedef void (*crypto_module_sess_exit_type)(void *sess);
|
||||
typedef int (*crypto_create_symm_key_type)(void *sess, ModuleSymmKeyAlgo algo, unsigned char *key_id, size_t *key_id_size);
|
||||
typedef int (*crypto_ctx_init_type)(void *sess, void **ctx, ModuleSymmKeyAlgo algo, int enc, unsigned char *key_id, size_t key_id_size);
|
||||
typedef int (*crypto_result_size_type)(void *ctx, int enc, size_t data_size);
|
||||
typedef void (*crypto_ctx_clean_type)(void *ctx);
|
||||
typedef int (*crypto_encrypt_decrypt_type)(void *ctx, int enc, unsigned char *data, size_t data_size, unsigned char *iv, size_t iv_size, unsigned char *result, size_t *result_size, unsigned char *tag);
|
||||
typedef int (*crypto_digest_type)(void *sess, ModuleDigestAlgo algo, unsigned char * data, size_t data_size,unsigned char *result, size_t *result_size);
|
||||
typedef int (*crypto_hmac_init_type)(void *sess, void **ctx, ModuleSymmKeyAlgo algo, unsigned char *key_id, size_t key_id_size);
|
||||
typedef void (*crypto_hmac_clean_type)(void *ctx);
|
||||
typedef int (*crypto_hmac_type)(void *ctx, unsigned char * data, size_t data_size, unsigned char *result, size_t *result_size);
|
||||
typedef int (*crypto_gen_random_type)(void *sess, char *buffer, size_t size);
|
||||
typedef int (*crypto_deterministic_enc_dec_type)(void *sess, int enc, unsigned char *data, unsigned char *key_id, size_t key_id_size, size_t data_size, unsigned char *result, size_t *result_size);
|
||||
typedef int (*crypto_get_errmsg_type)(void *sess, char *errmsg);
|
||||
|
||||
|
||||
void *libhandle = NULL;
|
||||
crypto_module_init_type crypto_module_init_use = NULL;
|
||||
crypto_module_sess_init_type crypto_module_sess_init_use = NULL;
|
||||
crypto_module_sess_exit_type crypto_module_sess_exit_use = NULL;
|
||||
crypto_create_symm_key_type crypto_create_symm_key_use = NULL;
|
||||
crypto_ctx_init_type crypto_ctx_init_use = NULL;
|
||||
crypto_result_size_type crypto_result_size_use = NULL;
|
||||
crypto_ctx_clean_type crypto_ctx_clean_use = NULL;
|
||||
crypto_encrypt_decrypt_type crypto_encrypt_decrypt_use = NULL;
|
||||
crypto_digest_type crypto_digest_use = NULL;
|
||||
crypto_hmac_init_type crypto_hmac_init_use = NULL;
|
||||
crypto_hmac_clean_type crypto_hmac_clean_use = NULL;
|
||||
crypto_hmac_type crypto_hmac_use = NULL;
|
||||
crypto_gen_random_type crypto_gen_random_use = NULL;
|
||||
crypto_deterministic_enc_dec_type crypto_deterministic_enc_dec_use = NULL;
|
||||
crypto_get_errmsg_type crypto_get_errmsg_use = NULL;
|
||||
|
||||
static void load_lib()
|
||||
{
|
||||
libhandle = dlopen("/home//vastbase/contrib/common_cipher/libcommoncipher.so", RTLD_LAZY);
|
||||
crypto_module_init_use = (crypto_module_init_type)dlsym(libhandle, "crypto_module_init");
|
||||
crypto_module_sess_init_use = (crypto_module_sess_init_type)dlsym(libhandle, "crypto_module_sess_init");
|
||||
crypto_module_sess_exit_use = (crypto_module_sess_exit_type)dlsym(libhandle, "crypto_module_sess_exit");
|
||||
crypto_create_symm_key_use = (crypto_create_symm_key_type)dlsym(libhandle, "crypto_create_symm_key");
|
||||
crypto_ctx_init_use = (crypto_ctx_init_type)dlsym(libhandle, "crypto_ctx_init");
|
||||
crypto_result_size_use = (crypto_result_size_type)dlsym(libhandle, "crypto_result_size");
|
||||
crypto_ctx_clean_use = (crypto_ctx_clean_type)dlsym(libhandle, "crypto_ctx_clean");
|
||||
crypto_encrypt_decrypt_use = (crypto_encrypt_decrypt_type)dlsym(libhandle, "crypto_encrypt_decrypt");
|
||||
crypto_digest_use = (crypto_digest_type)dlsym(libhandle, "crypto_digest");
|
||||
crypto_hmac_init_use = (crypto_hmac_init_type)dlsym(libhandle, "crypto_hmac_init");
|
||||
crypto_hmac_clean_use = (crypto_hmac_clean_type)dlsym(libhandle, "crypto_hmac_clean");
|
||||
crypto_hmac_use = (crypto_hmac_type)dlsym(libhandle, "crypto_hmac");
|
||||
crypto_gen_random_use = (crypto_gen_random_type)dlsym(libhandle, "crypto_gen_random");
|
||||
crypto_deterministic_enc_dec_use = (crypto_deterministic_enc_dec_type)dlsym(libhandle, "crypto_deterministic_enc_dec");
|
||||
crypto_get_errmsg_use = (crypto_get_errmsg_type)dlsym(libhandle, "crypto_get_errmsg");
|
||||
|
||||
}
|
||||
|
||||
static void* one_thread_func(void *data)
|
||||
{
|
||||
int ret = 1;
|
||||
int i = 0;
|
||||
char options[] = {"MODULE_TYPE=JNTAKMS,MODULE_LIB_PATH=/home//vastbase/contrib/common_cipher/libTassSDF4GHVSM.so,MODULE_CONFIG_FILE_PATH=/home//vastbase/contrib/common_cipher/"};
|
||||
SupportedFeature supportedfeature;
|
||||
char errmsg[MAX_ERRMSG_LEN] = {0};
|
||||
void *session = NULL;
|
||||
unsigned char key[32] = {0};
|
||||
long unsigned int keylen = 0;
|
||||
void *keyctx = NULL;
|
||||
unsigned char srcdata[] = {"12345678"};
|
||||
unsigned char plaint[32] = {0};
|
||||
long unsigned int plaintlen = 32;
|
||||
unsigned char encdata[32] = {0};
|
||||
long unsigned int enclen = 32;
|
||||
unsigned char encdata2[32] = {0};
|
||||
long unsigned int enclen2 = 32;
|
||||
unsigned char hashdata[32] = {0};
|
||||
long unsigned int hashlen = 0;
|
||||
unsigned char hmacdata[32] = {0};
|
||||
long unsigned int hmaclen = 0;
|
||||
long unsigned int needlen = 16;
|
||||
char random[32] = {0};
|
||||
unsigned char iv[] = {"1234567812345678"};
|
||||
|
||||
ret = crypto_module_init_use(options, &supportedfeature);
|
||||
if (ret != 1)
|
||||
{
|
||||
crypto_get_errmsg_use(NULL, errmsg);
|
||||
printf("crypto_module_init error,errmsg:%s\n", errmsg);
|
||||
return NULL;
|
||||
} else {
|
||||
printf("crypto_module_init success\n");
|
||||
printf("provider_name = %s,key_type = %d\n",supportedfeature.provider_name,supportedfeature.key_type);
|
||||
for (i = 0; i < MODULE_ALGO_MAX;i++) {
|
||||
if (supportedfeature.supported_symm[i] == 1)
|
||||
printf("supported_symm[%d]\n",i);
|
||||
}
|
||||
for (i = 0; i < MODULE_DIGEST_MAX;i++) {
|
||||
if (supportedfeature.supported_digest[i] == 1)
|
||||
printf("supported_digest[%d]\n",i);
|
||||
}
|
||||
}
|
||||
|
||||
ret = crypto_module_sess_init_use(NULL, &session);
|
||||
if (ret != 1)
|
||||
{
|
||||
crypto_get_errmsg_use(NULL, errmsg);
|
||||
printf("crypto_module_sess_init error,errmsg:%s\n", errmsg);
|
||||
return NULL;
|
||||
} else {
|
||||
printf("crypto_module_sess_init success\n");
|
||||
}
|
||||
|
||||
ret = crypto_create_symm_key_use(session, MODULE_SM4_CBC, key, &keylen);
|
||||
if (ret != 1)
|
||||
{
|
||||
crypto_get_errmsg_use(NULL, errmsg);
|
||||
printf("crypto_create_symm_key_use error,errmsg:%s\n", errmsg);
|
||||
crypto_module_sess_exit_use(session);
|
||||
return NULL;
|
||||
} else {
|
||||
printf("crypto_create_symm_key_use success\n");
|
||||
printf("key = %s\n",key);
|
||||
}
|
||||
|
||||
ret = crypto_ctx_init_use(session, &keyctx, MODULE_SM4_CBC, 1, key, keylen);
|
||||
if (ret != 1)
|
||||
{
|
||||
crypto_get_errmsg_use(NULL, errmsg);
|
||||
printf("crypto_ctx_init_use error,errmsg:%s\n", errmsg);
|
||||
crypto_module_sess_exit_use(session);
|
||||
return NULL;
|
||||
} else {
|
||||
printf("crypto_ctx_init_use success\n");
|
||||
}
|
||||
|
||||
ret = crypto_encrypt_decrypt_use(keyctx, 1, srcdata, 8, iv, 16, encdata, &enclen, NULL);
|
||||
if (ret != 1)
|
||||
{
|
||||
crypto_get_errmsg_use(NULL, errmsg);
|
||||
printf("crypto_encrypt_decrypt_use enc error,errmsg:%s\n", errmsg);
|
||||
crypto_ctx_clean_use(keyctx);
|
||||
crypto_module_sess_exit_use(session);
|
||||
return NULL;
|
||||
} else {
|
||||
printf("crypto_encrypt_decrypt_use enc success\n");
|
||||
}
|
||||
|
||||
ret = crypto_encrypt_decrypt_use(keyctx, 0, encdata, enclen, iv, 16, plaint, &plaintlen, NULL);
|
||||
if (ret != 1 || strcmp((char*)plaint, (char*)srcdata))
|
||||
{
|
||||
crypto_get_errmsg_use(NULL, errmsg);
|
||||
printf("crypto_encrypt_decrypt_use dec error,errmsg:%s\n", errmsg);
|
||||
crypto_ctx_clean_use(keyctx);
|
||||
crypto_module_sess_exit_use(session);
|
||||
return NULL;
|
||||
} else {
|
||||
printf("crypto_encrypt_decrypt_use dec success\n");
|
||||
}
|
||||
|
||||
printf("enc nedd len:%d\n",crypto_result_size_use(keyctx, 1, needlen));
|
||||
|
||||
printf("dec nedd len:%d\n",crypto_result_size_use(keyctx, 0, needlen));
|
||||
|
||||
crypto_ctx_clean_use(keyctx);
|
||||
|
||||
ret = crypto_digest_use(session, MODULE_SM3, plaint, plaintlen, hashdata, &hashlen);
|
||||
if (ret != 1)
|
||||
{
|
||||
crypto_get_errmsg_use(NULL, errmsg);
|
||||
printf("crypto_digest_use error,errmsg:%s\n", errmsg);
|
||||
crypto_module_sess_exit_use(session);
|
||||
return NULL;
|
||||
} else {
|
||||
printf("crypto_digest_use success\n");
|
||||
printf("hashlen = %ld\n", hashlen);
|
||||
}
|
||||
|
||||
ret = crypto_hmac_init_use(session, &keyctx, MODULE_HMAC_SM3, key, keylen);
|
||||
if (ret != 1)
|
||||
{
|
||||
crypto_get_errmsg_use(NULL, errmsg);
|
||||
printf("crypto_hmac_init_use error,errmsg:%s\n", errmsg);
|
||||
crypto_module_sess_exit_use(session);
|
||||
return NULL;
|
||||
} else {
|
||||
printf("crypto_hmac_init_use success\n");
|
||||
}
|
||||
|
||||
ret = crypto_hmac_use(keyctx, plaint, plaintlen, hmacdata, &hmaclen);
|
||||
if (ret != 1)
|
||||
{
|
||||
crypto_get_errmsg_use(NULL, errmsg);
|
||||
printf("crypto_hmac_use error,errmsg:%s\n", errmsg);
|
||||
crypto_hmac_clean_use(keyctx);
|
||||
crypto_module_sess_exit_use(session);
|
||||
return NULL;
|
||||
} else {
|
||||
printf("crypto_hmac_use success\n");
|
||||
printf("hmaclen = %ld\n", hmaclen);
|
||||
}
|
||||
|
||||
crypto_hmac_clean_use(keyctx);
|
||||
|
||||
ret = crypto_gen_random_use(session, random, 31);
|
||||
if (ret != 1)
|
||||
{
|
||||
crypto_get_errmsg_use(NULL, errmsg);
|
||||
printf("crypto_gen_random_use error,errmsg:%s\n", errmsg);
|
||||
crypto_module_sess_exit_use(session);
|
||||
return NULL;
|
||||
} else {
|
||||
printf("crypto_gen_random_use success\n");
|
||||
}
|
||||
|
||||
ret = crypto_deterministic_enc_dec_use(session, 1, plaint, key, keylen, plaintlen, encdata, &enclen);
|
||||
if (ret != 1)
|
||||
{
|
||||
crypto_get_errmsg_use(NULL, errmsg);
|
||||
printf("crypto_deterministic_enc_dec_use1 enc error,errmsg:%s\n", errmsg);
|
||||
crypto_module_sess_exit_use(session);
|
||||
return NULL;
|
||||
} else {
|
||||
printf("crypto_deterministic_enc_dec_use1 enc success\n");
|
||||
}
|
||||
|
||||
ret = crypto_deterministic_enc_dec_use(session, 1, plaint, key, keylen, plaintlen, encdata2, &enclen2);
|
||||
if (ret != 1 || strcmp((char*)encdata, (char*)encdata2))
|
||||
{
|
||||
crypto_get_errmsg_use(NULL, errmsg);
|
||||
printf("crypto_deterministic_enc_dec_use2 enc error,errmsg:%s\n", errmsg);
|
||||
crypto_module_sess_exit_use(session);
|
||||
return NULL;
|
||||
} else {
|
||||
printf("crypto_deterministic_enc_dec_use2 enc success\n");
|
||||
}
|
||||
|
||||
ret = crypto_deterministic_enc_dec_use(session, 0, encdata2, key, keylen, enclen2, plaint, &plaintlen);
|
||||
if (ret != 1 || strcmp((char*)plaint, (char*)srcdata))
|
||||
{
|
||||
crypto_get_errmsg_use(NULL, errmsg);
|
||||
printf("crypto_deterministic_enc_dec_use2 dec error,errmsg:%s\n", errmsg);
|
||||
crypto_module_sess_exit_use(session);
|
||||
return NULL;
|
||||
} else {
|
||||
printf("crypto_deterministic_enc_dec_use2 dec success\n");
|
||||
}
|
||||
|
||||
crypto_get_errmsg_use(NULL, errmsg);
|
||||
printf("crypto_get_errmsg_use errmsg:%s\n", errmsg);
|
||||
|
||||
crypto_module_sess_exit_use(session);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
pthread_t t1, t2, t3, t4;
|
||||
|
||||
load_lib();
|
||||
|
||||
pthread_create(&t1,0,one_thread_func,NULL);
|
||||
pthread_create(&t2,0,one_thread_func,NULL);
|
||||
pthread_create(&t3,0,one_thread_func,NULL);
|
||||
pthread_create(&t4,0,one_thread_func,NULL);
|
||||
pthread_join(t1,NULL);
|
||||
pthread_join(t2,NULL);
|
||||
pthread_join(t3,NULL);
|
||||
pthread_join(t4,NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
23
contrib/dblink/CMakeLists.txt
Normal file
23
contrib/dblink/CMakeLists.txt
Normal file
@ -0,0 +1,23 @@
|
||||
#This is the main CMAKE for build all gms_stats.
|
||||
# gms_stats
|
||||
AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} TGT_dblink_SRC)
|
||||
set(TGT_dblink_INC
|
||||
${PROJECT_OPENGS_DIR}/contrib/dblink
|
||||
${PROJECT_OPENGS_DIR}/contrib
|
||||
)
|
||||
|
||||
set(dblink_DEF_OPTIONS ${MACRO_OPTIONS})
|
||||
set(dblink_COMPILE_OPTIONS ${OPTIMIZE_OPTIONS} ${OS_OPTIONS} ${PROTECT_OPTIONS} ${WARNING_OPTIONS} ${LIB_SECURE_OPTIONS} ${CHECK_OPTIONS})
|
||||
set(dblink_LINK_OPTIONS ${LIB_LINK_OPTIONS})
|
||||
add_shared_libtarget(dblink TGT_dblink_SRC TGT_dblink_INC "${dblink_DEF_OPTIONS}" "${dblink_COMPILE_OPTIONS}" "${dblink_LINK_OPTIONS}")
|
||||
target_link_libraries(dblink PUBLIC -lodbc)
|
||||
target_link_directories(dblink PUBLIC ${ODBC_HOME}/lib)
|
||||
set_target_properties(dblink PROPERTIES PREFIX "")
|
||||
|
||||
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/dblink.control
|
||||
DESTINATION share/postgresql/extension/
|
||||
)
|
||||
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/dblink--1.0.sql
|
||||
DESTINATION share/postgresql/extension/
|
||||
)
|
||||
install(TARGETS dblink DESTINATION lib/postgresql)
|
||||
21
contrib/gms_compress/CMakeLists.txt
Normal file
21
contrib/gms_compress/CMakeLists.txt
Normal file
@ -0,0 +1,21 @@
|
||||
#This is the main CMAKE for build all gms_compress.
|
||||
# gms_compress
|
||||
AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} TGT_gms_compress_SRC)
|
||||
set(TGT_gms_compress_INC
|
||||
${PROJECT_OPENGS_DIR}/contrib/gms_compress
|
||||
${PROJECT_OPENGS_DIR}/contrib
|
||||
)
|
||||
|
||||
set(gms_compress_DEF_OPTIONS ${MACRO_OPTIONS})
|
||||
set(gms_compress_COMPILE_OPTIONS ${OPTIMIZE_OPTIONS} ${OS_OPTIONS} ${PROTECT_OPTIONS} ${WARNING_OPTIONS} ${LIB_SECURE_OPTIONS} ${CHECK_OPTIONS})
|
||||
set(gms_compress_LINK_OPTIONS ${LIB_LINK_OPTIONS})
|
||||
add_shared_libtarget(gms_compress TGT_gms_compress_SRC TGT_gms_compress_INC "${gms_compress_DEF_OPTIONS}" "${gms_compress_COMPILE_OPTIONS}" "${gms_compress_LINK_OPTIONS}")
|
||||
set_target_properties(gms_compress PROPERTIES PREFIX "")
|
||||
|
||||
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/gms_compress.control
|
||||
DESTINATION share/postgresql/extension/
|
||||
)
|
||||
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/gms_compress--1.0.sql
|
||||
DESTINATION share/postgresql/extension/
|
||||
)
|
||||
install(TARGETS gms_compress DESTINATION lib/postgresql)
|
||||
26
contrib/gms_compress/Makefile
Normal file
26
contrib/gms_compress/Makefile
Normal file
@ -0,0 +1,26 @@
|
||||
# contrib/gms_compress/Makefile
|
||||
MODULE_big = gms_compress
|
||||
OBJS = gms_compress.o
|
||||
|
||||
EXTENSION = gms_compress
|
||||
DATA = gms_compress--1.0.sql
|
||||
|
||||
exclude_option = -fPIE
|
||||
override CPPFLAGS := -fstack-protector-strong $(filter-out $(exclude_option),$(CPPFLAGS))
|
||||
|
||||
REGRESS = gms_compress
|
||||
|
||||
ifdef USE_PGXS
|
||||
PG_CONFIG = pg_config
|
||||
PGXS := $(shell $(PG_CONFIG) --pgxs)
|
||||
include $(PGXS)
|
||||
else
|
||||
subdir = contrib/gms_compress
|
||||
top_builddir = ../..
|
||||
include $(top_builddir)/src/Makefile.global
|
||||
regress_home = $(top_builddir)/src/test/regress
|
||||
REGRESS_OPTS = -c 0 -d 1 -r 1 -p 25632 --single_node -w --keep_last_data=false \
|
||||
--regconf=$(regress_home)/regress.conf \
|
||||
--temp-config=$(regress_home)/make_fastcheck_postgresql.conf
|
||||
include $(top_srcdir)/contrib/contrib-global.mk
|
||||
endif
|
||||
1
contrib/gms_compress/data/dummy.txt
Normal file
1
contrib/gms_compress/data/dummy.txt
Normal file
@ -0,0 +1 @@
|
||||
The openGauss regression needs this file to run.
|
||||
967
contrib/gms_compress/expected/gms_compress.out
Normal file
967
contrib/gms_compress/expected/gms_compress.out
Normal file
@ -0,0 +1,967 @@
|
||||
create extension gms_compress;
|
||||
create schema gms_compress_test;
|
||||
set search_path=gms_compress_test;
|
||||
-- test gms_compress.compress
|
||||
select gms_compress.lz_compress('123'::raw);
|
||||
lz_compress
|
||||
----------------------------------------------
|
||||
1F8B080000000000000363540600CC52A5FA02000000
|
||||
(1 row)
|
||||
|
||||
select gms_compress.lz_compress('df'::raw);
|
||||
lz_compress
|
||||
--------------------------------------------
|
||||
1F8B0800000000000003BB0F00C8206EC401000000
|
||||
(1 row)
|
||||
|
||||
select gms_compress.lz_compress('12ab56'::raw);
|
||||
lz_compress
|
||||
------------------------------------------------
|
||||
1F8B0800000000000003135A1D0600EF3F182F03000000
|
||||
(1 row)
|
||||
|
||||
select gms_compress.lz_compress('123'::raw, 1);
|
||||
lz_compress
|
||||
----------------------------------------------
|
||||
1F8B080000000000040363540600CC52A5FA02000000
|
||||
(1 row)
|
||||
|
||||
select gms_compress.lz_compress('df'::raw, 6);
|
||||
lz_compress
|
||||
--------------------------------------------
|
||||
1F8B0800000000000003BB0F00C8206EC401000000
|
||||
(1 row)
|
||||
|
||||
select gms_compress.lz_compress('12ab56'::raw, 9);
|
||||
lz_compress
|
||||
------------------------------------------------
|
||||
1F8B0800000000000203135A1D0600EF3F182F03000000
|
||||
(1 row)
|
||||
|
||||
select gms_compress.lz_compress('123'::blob);
|
||||
lz_compress
|
||||
----------------------------------------------
|
||||
1F8B080000000000000363540600CC52A5FA02000000
|
||||
(1 row)
|
||||
|
||||
select gms_compress.lz_compress('df'::blob);
|
||||
lz_compress
|
||||
--------------------------------------------
|
||||
1F8B0800000000000003BB0F00C8206EC401000000
|
||||
(1 row)
|
||||
|
||||
select gms_compress.lz_compress('12ab56'::blob);
|
||||
lz_compress
|
||||
------------------------------------------------
|
||||
1F8B0800000000000003135A1D0600EF3F182F03000000
|
||||
(1 row)
|
||||
|
||||
select gms_compress.lz_compress('123'::blob, 1);
|
||||
lz_compress
|
||||
----------------------------------------------
|
||||
1F8B080000000000040363540600CC52A5FA02000000
|
||||
(1 row)
|
||||
|
||||
select gms_compress.lz_compress('df'::blob, 6);
|
||||
lz_compress
|
||||
--------------------------------------------
|
||||
1F8B0800000000000003BB0F00C8206EC401000000
|
||||
(1 row)
|
||||
|
||||
select gms_compress.lz_compress('12ab56'::blob, 9);
|
||||
lz_compress
|
||||
------------------------------------------------
|
||||
1F8B0800000000000203135A1D0600EF3F182F03000000
|
||||
(1 row)
|
||||
|
||||
DECLARE
|
||||
content BLOB;
|
||||
r_content BLOB;
|
||||
v_handle int;
|
||||
v_raw raw;
|
||||
r_raw raw;
|
||||
v_bool boolean;
|
||||
BEGIN
|
||||
content := '123';
|
||||
v_raw := '12345';
|
||||
r_content := GMS_COMPRESS.LZ_COMPRESS(content);
|
||||
r_raw := GMS_COMPRESS.LZ_COMPRESS(v_raw);
|
||||
RAISE NOTICE 'r_content=%,r_raw=%', r_content, r_raw;
|
||||
r_content := '111';
|
||||
GMS_COMPRESS.LZ_COMPRESS(content, r_content);
|
||||
RAISE NOTICE 'r_content=%', r_content;
|
||||
END;
|
||||
/
|
||||
NOTICE: r_content=1F8B080000000000000363540600CC52A5FA02000000,r_raw=1F8B080000000000000363547605005B719C4603000000
|
||||
NOTICE: r_content=1F8B080000000000000363540600CC52A5FA02000000
|
||||
DECLARE
|
||||
content BLOB;
|
||||
r_content BLOB;
|
||||
v_handle int;
|
||||
v_raw raw;
|
||||
r_raw raw;
|
||||
v_bool boolean;
|
||||
BEGIN
|
||||
content := 'abc';
|
||||
v_raw := 'df';
|
||||
r_content := GMS_COMPRESS.LZ_COMPRESS(content, 1);
|
||||
r_raw := GMS_COMPRESS.LZ_COMPRESS(v_raw, 9);
|
||||
RAISE NOTICE 'r_content=%,r_raw=%', r_content, r_raw;
|
||||
r_content := '111';
|
||||
GMS_COMPRESS.LZ_COMPRESS(content, r_content, 5);
|
||||
RAISE NOTICE 'r_content=%', r_content;
|
||||
END;
|
||||
/
|
||||
NOTICE: r_content=1F8B0800000000000403E3DA0300D205E17902000000,r_raw=1F8B0800000000000203BB0F00C8206EC401000000
|
||||
NOTICE: r_content=1F8B0800000000000003E3DA0300D205E17902000000
|
||||
-- abnormal scenario
|
||||
select gms_compress.lz_compress(null::raw);
|
||||
ERROR: compressed data cannot be NULL
|
||||
CONTEXT: referenced column: lz_compress
|
||||
select gms_compress.lz_compress(''::raw);
|
||||
ERROR: compressed data cannot be NULL
|
||||
CONTEXT: referenced column: lz_compress
|
||||
select gms_compress.lz_compress('dfg'::raw);
|
||||
ERROR: invalid hexadecimal digit: "g"
|
||||
LINE 1: select gms_compress.lz_compress('dfg'::raw);
|
||||
^
|
||||
CONTEXT: referenced column: lz_compress
|
||||
select gms_compress.lz_compress('dfg'::raw, 5);
|
||||
ERROR: invalid hexadecimal digit: "g"
|
||||
LINE 1: select gms_compress.lz_compress('dfg'::raw, 5);
|
||||
^
|
||||
CONTEXT: referenced column: lz_compress
|
||||
select gms_compress.lz_compress('123'::raw, 0);
|
||||
ERROR: compression quality must be within the range of 1 to 9
|
||||
CONTEXT: referenced column: lz_compress
|
||||
select gms_compress.lz_compress('123'::raw, 10);
|
||||
ERROR: compression quality must be within the range of 1 to 9
|
||||
CONTEXT: referenced column: lz_compress
|
||||
select gms_compress.lz_compress(null::blob);
|
||||
ERROR: compressed data cannot be NULL
|
||||
CONTEXT: referenced column: lz_compress
|
||||
select gms_compress.lz_compress(''::blob);
|
||||
ERROR: compressed data cannot be NULL
|
||||
CONTEXT: referenced column: lz_compress
|
||||
select gms_compress.lz_compress('dfg'::blob);
|
||||
ERROR: invalid hexadecimal digit: "g"
|
||||
LINE 1: select gms_compress.lz_compress('dfg'::blob);
|
||||
^
|
||||
CONTEXT: referenced column: lz_compress
|
||||
select gms_compress.lz_compress('dfg'::blob, 5);
|
||||
ERROR: invalid hexadecimal digit: "g"
|
||||
LINE 1: select gms_compress.lz_compress('dfg'::blob, 5);
|
||||
^
|
||||
CONTEXT: referenced column: lz_compress
|
||||
select gms_compress.lz_compress('123'::blob, 0);
|
||||
ERROR: compression quality must be within the range of 1 to 9
|
||||
CONTEXT: referenced column: lz_compress
|
||||
select gms_compress.lz_compress('123'::blob, 10);
|
||||
ERROR: compression quality must be within the range of 1 to 9
|
||||
CONTEXT: referenced column: lz_compress
|
||||
DECLARE
|
||||
content BLOB;
|
||||
r_content BLOB;
|
||||
v_raw raw;
|
||||
r_raw raw;
|
||||
BEGIN
|
||||
content := '';
|
||||
v_raw := 'dfg';
|
||||
r_content := GMS_COMPRESS.LZ_COMPRESS(content);
|
||||
r_raw := GMS_COMPRESS.LZ_COMPRESS(v_raw);
|
||||
RAISE NOTICE 'r_content=%,r_raw=%', r_content, r_raw;
|
||||
r_content := '111';
|
||||
GMS_COMPRESS.LZ_COMPRESS(content, r_content);
|
||||
RAISE NOTICE 'r_content=%', r_content;
|
||||
END;
|
||||
/
|
||||
ERROR: invalid hexadecimal digit: "g"
|
||||
CONTEXT: PL/pgSQL function inline_code_block line 7 at assignment
|
||||
DECLARE
|
||||
content BLOB;
|
||||
r_content BLOB;
|
||||
v_raw raw;
|
||||
r_raw raw;
|
||||
BEGIN
|
||||
content := 'abc';
|
||||
v_raw := 'df';
|
||||
r_content := GMS_COMPRESS.LZ_COMPRESS(content, 0);
|
||||
r_raw := GMS_COMPRESS.LZ_COMPRESS(v_raw, 10);
|
||||
RAISE NOTICE 'r_content=%,r_raw=%', r_content, r_raw;
|
||||
r_content := '111';
|
||||
GMS_COMPRESS.LZ_COMPRESS(content, r_content, -1);
|
||||
RAISE NOTICE 'r_content=%', r_content;
|
||||
END;
|
||||
/
|
||||
ERROR: compression quality must be within the range of 1 to 9
|
||||
CONTEXT: PL/pgSQL function inline_code_block line 8 at assignment
|
||||
-- test gms_compress.lz_uncompress
|
||||
select gms_compress.lz_uncompress(gms_compress.lz_compress('123'::raw));
|
||||
lz_uncompress
|
||||
---------------
|
||||
0123
|
||||
(1 row)
|
||||
|
||||
select gms_compress.lz_uncompress(gms_compress.lz_compress('df'::raw));
|
||||
lz_uncompress
|
||||
---------------
|
||||
DF
|
||||
(1 row)
|
||||
|
||||
select gms_compress.lz_uncompress(gms_compress.lz_compress('12ab56'::raw));
|
||||
lz_uncompress
|
||||
---------------
|
||||
12AB56
|
||||
(1 row)
|
||||
|
||||
select gms_compress.lz_uncompress(gms_compress.lz_compress('123'::raw, 1));
|
||||
lz_uncompress
|
||||
---------------
|
||||
0123
|
||||
(1 row)
|
||||
|
||||
select gms_compress.lz_uncompress(gms_compress.lz_compress('df'::raw, 6));
|
||||
lz_uncompress
|
||||
---------------
|
||||
DF
|
||||
(1 row)
|
||||
|
||||
select gms_compress.lz_uncompress(gms_compress.lz_compress('12ab56'::raw, 9));
|
||||
lz_uncompress
|
||||
---------------
|
||||
12AB56
|
||||
(1 row)
|
||||
|
||||
select gms_compress.lz_uncompress(gms_compress.lz_compress('123'::blob));
|
||||
lz_uncompress
|
||||
---------------
|
||||
0123
|
||||
(1 row)
|
||||
|
||||
select gms_compress.lz_uncompress(gms_compress.lz_compress('df'::blob));
|
||||
lz_uncompress
|
||||
---------------
|
||||
DF
|
||||
(1 row)
|
||||
|
||||
select gms_compress.lz_uncompress(gms_compress.lz_compress('12ab56'::blob));
|
||||
lz_uncompress
|
||||
---------------
|
||||
12AB56
|
||||
(1 row)
|
||||
|
||||
select gms_compress.lz_uncompress(gms_compress.lz_compress('123'::blob, 1));
|
||||
lz_uncompress
|
||||
---------------
|
||||
0123
|
||||
(1 row)
|
||||
|
||||
select gms_compress.lz_uncompress(gms_compress.lz_compress('df'::blob, 6));
|
||||
lz_uncompress
|
||||
---------------
|
||||
DF
|
||||
(1 row)
|
||||
|
||||
select gms_compress.lz_uncompress(gms_compress.lz_compress('12ab56'::blob, 9));
|
||||
lz_uncompress
|
||||
---------------
|
||||
12AB56
|
||||
(1 row)
|
||||
|
||||
DECLARE
|
||||
content BLOB;
|
||||
r_content BLOB;
|
||||
v_content BLOB;
|
||||
v_bool boolean;
|
||||
BEGIN
|
||||
content := '123';
|
||||
v_content := '123';
|
||||
r_content := GMS_COMPRESS.LZ_COMPRESS(content);
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS(r_content, v_content);
|
||||
RAISE NOTICE 'content=%,r_content=%,v_content=%', content, r_content, v_content;
|
||||
END;
|
||||
/
|
||||
NOTICE: content=0123,r_content=1F8B080000000000000363540600CC52A5FA02000000,v_content=0123
|
||||
-- abnormal scenario
|
||||
select gms_compress.lz_uncompress(null::raw);
|
||||
ERROR: uncompressed data cannot be NULL
|
||||
CONTEXT: referenced column: lz_uncompress
|
||||
select gms_compress.lz_uncompress(''::raw);
|
||||
ERROR: uncompressed data cannot be NULL
|
||||
CONTEXT: referenced column: lz_uncompress
|
||||
select gms_compress.lz_uncompress('dfg'::raw);
|
||||
ERROR: invalid hexadecimal digit: "g"
|
||||
LINE 1: select gms_compress.lz_uncompress('dfg'::raw);
|
||||
^
|
||||
CONTEXT: referenced column: lz_uncompress
|
||||
select gms_compress.lz_uncompress('123'::raw);
|
||||
ERROR: too small, minimum length of gzip format is 14 bytes
|
||||
CONTEXT: referenced column: lz_uncompress
|
||||
select gms_compress.lz_uncompress(null::blob);
|
||||
ERROR: uncompressed data cannot be NULL
|
||||
CONTEXT: referenced column: lz_uncompress
|
||||
select gms_compress.lz_uncompress(''::blob);
|
||||
ERROR: uncompressed data cannot be NULL
|
||||
CONTEXT: referenced column: lz_uncompress
|
||||
select gms_compress.lz_uncompress('dfg'::blob);
|
||||
ERROR: invalid hexadecimal digit: "g"
|
||||
LINE 1: select gms_compress.lz_uncompress('dfg'::blob);
|
||||
^
|
||||
CONTEXT: referenced column: lz_uncompress
|
||||
select gms_compress.lz_uncompress('123'::blob);
|
||||
ERROR: too small, minimum length of gzip format is 14 bytes
|
||||
CONTEXT: referenced column: lz_uncompress
|
||||
DECLARE
|
||||
content BLOB;
|
||||
r_content BLOB;
|
||||
v_content BLOB;
|
||||
v_bool boolean;
|
||||
BEGIN
|
||||
r_content := NULL;
|
||||
v_content := '123';
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS(r_content, v_content);
|
||||
RAISE NOTICE 'content=%,r_content=%,v_content=%', content, r_content, v_content;
|
||||
END;
|
||||
/
|
||||
ERROR: parameter cannot be NULL
|
||||
CONTEXT: SQL statement "CALL gms_compress.lz_uncompress(r_content,v_content)"
|
||||
PL/pgSQL function inline_code_block line 8 at SQL statement
|
||||
DECLARE
|
||||
content BLOB;
|
||||
r_content BLOB;
|
||||
v_content BLOB;
|
||||
v_bool boolean;
|
||||
BEGIN
|
||||
r_content := '123';
|
||||
v_content := '123';
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS(r_content, v_content);
|
||||
RAISE NOTICE 'content=%,r_content=%,v_content=%', content, r_content, v_content;
|
||||
END;
|
||||
/
|
||||
ERROR: too small, minimum length of gzip format is 14 bytes
|
||||
CONTEXT: PL/pgSQL function gms_compress.lz_uncompress(blob,blob) line 5 at assignment
|
||||
SQL statement "CALL gms_compress.lz_uncompress(r_content,v_content)"
|
||||
PL/pgSQL function inline_code_block line 8 at SQL statement
|
||||
DECLARE
|
||||
content BLOB;
|
||||
r_content BLOB;
|
||||
v_content BLOB;
|
||||
v_bool boolean;
|
||||
BEGIN
|
||||
content := '123';
|
||||
r_content := GMS_COMPRESS.LZ_COMPRESS(content);
|
||||
v_content := NULL;
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS(r_content, v_content);
|
||||
RAISE NOTICE 'content=%,r_content=%,v_content=%', content, r_content, v_content;
|
||||
END;
|
||||
/
|
||||
ERROR: parameter cannot be NULL
|
||||
CONTEXT: SQL statement "CALL gms_compress.lz_uncompress(r_content,v_content)"
|
||||
PL/pgSQL function inline_code_block line 9 at SQL statement
|
||||
-- test gms_compress.lz_compress_open and ms_compress.lz_compress_close
|
||||
DECLARE
|
||||
content BLOB;
|
||||
v_handle int;
|
||||
BEGIN
|
||||
content := '123';
|
||||
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
|
||||
GMS_COMPRESS.LZ_COMPRESS_CLOSE(v_handle,content);
|
||||
RAISE NOTICE 'content=%', content;
|
||||
END;
|
||||
/
|
||||
NOTICE: content=<NULL>
|
||||
DECLARE
|
||||
content BLOB;
|
||||
v_handle int;
|
||||
BEGIN
|
||||
content := '123';
|
||||
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content,5);
|
||||
GMS_COMPRESS.LZ_COMPRESS_CLOSE(v_handle,content);
|
||||
RAISE NOTICE 'content=%', content;
|
||||
END;
|
||||
/
|
||||
NOTICE: content=<NULL>
|
||||
DECLARE
|
||||
content BLOB;
|
||||
v_handle int;
|
||||
BEGIN
|
||||
content := '123';
|
||||
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
|
||||
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
|
||||
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
|
||||
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
|
||||
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
|
||||
GMS_COMPRESS.LZ_COMPRESS_CLOSE(1,content);
|
||||
GMS_COMPRESS.LZ_COMPRESS_CLOSE(2,content);
|
||||
GMS_COMPRESS.LZ_COMPRESS_CLOSE(3,content);
|
||||
GMS_COMPRESS.LZ_COMPRESS_CLOSE(4,content);
|
||||
GMS_COMPRESS.LZ_COMPRESS_CLOSE(5,content);
|
||||
END;
|
||||
/
|
||||
-- abnormal scenario
|
||||
DECLARE
|
||||
content BLOB;
|
||||
v_handle int;
|
||||
BEGIN
|
||||
content := '';
|
||||
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
|
||||
GMS_COMPRESS.LZ_COMPRESS_CLOSE(v_handle,content);
|
||||
RAISE NOTICE 'content=%', content;
|
||||
END;
|
||||
/
|
||||
ERROR: NULL input for detoast datum packed
|
||||
CONTEXT: PL/pgSQL function inline_code_block line 5 at assignment
|
||||
DECLARE
|
||||
content BLOB;
|
||||
v_handle int;
|
||||
BEGIN
|
||||
content := '123';
|
||||
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content, 0);
|
||||
GMS_COMPRESS.LZ_COMPRESS_CLOSE(v_handle,content);
|
||||
RAISE NOTICE 'content=%', content;
|
||||
END;
|
||||
/
|
||||
ERROR: compression quality must be within the range of 1 to 9
|
||||
CONTEXT: PL/pgSQL function inline_code_block line 5 at assignment
|
||||
DECLARE
|
||||
content BLOB;
|
||||
v_handle int;
|
||||
BEGIN
|
||||
content := '123';
|
||||
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
|
||||
GMS_COMPRESS.LZ_COMPRESS_CLOSE(0,content);
|
||||
RAISE NOTICE 'content=%', content;
|
||||
END;
|
||||
/
|
||||
ERROR: invalid handle, it be within the range of 1 to 5
|
||||
CONTEXT: PL/pgSQL function gms_compress.lz_compress_close(integer,blob) line 2 at assignment
|
||||
SQL statement "CALL gms_compress.lz_compress_close(0,content)"
|
||||
PL/pgSQL function inline_code_block line 6 at SQL statement
|
||||
DECLARE
|
||||
content BLOB;
|
||||
BEGIN
|
||||
GMS_COMPRESS.LZ_COMPRESS_CLOSE(1,content);
|
||||
RAISE NOTICE 'content=%', content;
|
||||
END;
|
||||
/
|
||||
NOTICE: content=<NULL>
|
||||
DECLARE
|
||||
content BLOB;
|
||||
v_handle int;
|
||||
BEGIN
|
||||
content := '123';
|
||||
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
|
||||
GMS_COMPRESS.LZ_COMPRESS_CLOSE(v_handle+1,content);
|
||||
RAISE NOTICE 'content=%', content;
|
||||
END;
|
||||
/
|
||||
ERROR: handle 2 is not be used
|
||||
CONTEXT: PL/pgSQL function gms_compress.lz_compress_close(integer,blob) line 2 at assignment
|
||||
SQL statement "CALL gms_compress.lz_compress_close(v_handle+1,content)"
|
||||
PL/pgSQL function inline_code_block line 6 at SQL statement
|
||||
DECLARE
|
||||
content BLOB;
|
||||
BEGIN
|
||||
GMS_COMPRESS.LZ_COMPRESS_CLOSE(1,content);
|
||||
RAISE NOTICE 'content=%', content;
|
||||
END;
|
||||
/
|
||||
NOTICE: content=<NULL>
|
||||
DECLARE
|
||||
content BLOB;
|
||||
v_handle int;
|
||||
BEGIN
|
||||
content := '123';
|
||||
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
|
||||
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
|
||||
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
|
||||
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
|
||||
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
|
||||
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
|
||||
RAISE NOTICE 'content=%', content;
|
||||
END;
|
||||
/
|
||||
ERROR: no handle free, the maximum number of handles is 5
|
||||
CONTEXT: PL/pgSQL function inline_code_block line 10 at assignment
|
||||
DECLARE
|
||||
content BLOB;
|
||||
v_handle int;
|
||||
BEGIN
|
||||
content := '123';
|
||||
GMS_COMPRESS.LZ_COMPRESS_CLOSE(1,content);
|
||||
GMS_COMPRESS.LZ_COMPRESS_CLOSE(2,content);
|
||||
GMS_COMPRESS.LZ_COMPRESS_CLOSE(3,content);
|
||||
GMS_COMPRESS.LZ_COMPRESS_CLOSE(4,content);
|
||||
GMS_COMPRESS.LZ_COMPRESS_CLOSE(5,content);
|
||||
GMS_COMPRESS.LZ_COMPRESS_CLOSE(1,content);
|
||||
RAISE NOTICE 'content=%', content;
|
||||
END;
|
||||
/
|
||||
ERROR: handle 1 is not be used
|
||||
CONTEXT: PL/pgSQL function gms_compress.lz_compress_close(integer,blob) line 2 at assignment
|
||||
SQL statement "CALL gms_compress.lz_compress_close(1,content)"
|
||||
PL/pgSQL function inline_code_block line 10 at SQL statement
|
||||
-- test gms_compress.lz_compress_add
|
||||
DECLARE
|
||||
content BLOB;
|
||||
v_handle int;
|
||||
src raw;
|
||||
BEGIN
|
||||
content := '123';
|
||||
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
|
||||
src := '123';
|
||||
GMS_COMPRESS.LZ_COMPRESS_ADD(v_handle,content,src);
|
||||
GMS_COMPRESS.LZ_COMPRESS_CLOSE(v_handle,content);
|
||||
RAISE NOTICE 'content=%', content;
|
||||
END;
|
||||
/
|
||||
NOTICE: content=1F8B080000000000000363540600CC52A5FA02000000
|
||||
DECLARE
|
||||
content BLOB;
|
||||
v_handle int;
|
||||
src raw;
|
||||
BEGIN
|
||||
content := '123';
|
||||
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
|
||||
src := '123';
|
||||
GMS_COMPRESS.LZ_COMPRESS_ADD(v_handle,content,src);
|
||||
GMS_COMPRESS.LZ_COMPRESS_ADD(v_handle,content,src);
|
||||
GMS_COMPRESS.LZ_COMPRESS_CLOSE(v_handle,content);
|
||||
RAISE NOTICE 'content=%', content;
|
||||
END;
|
||||
/
|
||||
NOTICE: content=1F8B0800000000000003635466540600F3008F1804000000
|
||||
-- abnormal scenario
|
||||
DECLARE
|
||||
content BLOB;
|
||||
v_handle int;
|
||||
src raw;
|
||||
BEGIN
|
||||
content := '123';
|
||||
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
|
||||
src := '123';
|
||||
GMS_COMPRESS.LZ_COMPRESS_ADD(v_handle,content,NULL);
|
||||
GMS_COMPRESS.LZ_COMPRESS_CLOSE(v_handle,content);
|
||||
RAISE NOTICE 'content=%', content;
|
||||
END;
|
||||
/
|
||||
ERROR: parameter cannot be NULL
|
||||
CONTEXT: SQL statement "CALL gms_compress.lz_compress_add(v_handle,content,NULL)"
|
||||
PL/pgSQL function inline_code_block line 8 at SQL statement
|
||||
DECLARE
|
||||
content BLOB;
|
||||
BEGIN
|
||||
GMS_COMPRESS.LZ_COMPRESS_CLOSE(1,content);
|
||||
RAISE NOTICE 'content=%', content;
|
||||
END;
|
||||
/
|
||||
NOTICE: content=<NULL>
|
||||
DECLARE
|
||||
content BLOB;
|
||||
v_handle int;
|
||||
src raw;
|
||||
BEGIN
|
||||
content := '123';
|
||||
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
|
||||
src := '123';
|
||||
GMS_COMPRESS.LZ_COMPRESS_ADD(0,content,src);
|
||||
GMS_COMPRESS.LZ_COMPRESS_CLOSE(v_handle,content);
|
||||
RAISE NOTICE 'content=%', content;
|
||||
END;
|
||||
/
|
||||
ERROR: invalid handle, it be within the range of 1 to 5
|
||||
CONTEXT: SQL statement "CALL gms_compress.compress_add(handle,src)"
|
||||
PL/pgSQL function gms_compress.lz_compress_add(integer,blob,raw) line 5 at PERFORM
|
||||
SQL statement "CALL gms_compress.lz_compress_add(0,content,src)"
|
||||
PL/pgSQL function inline_code_block line 8 at SQL statement
|
||||
DECLARE
|
||||
content BLOB;
|
||||
BEGIN
|
||||
GMS_COMPRESS.LZ_COMPRESS_CLOSE(1,content);
|
||||
RAISE NOTICE 'content=%', content;
|
||||
END;
|
||||
/
|
||||
NOTICE: content=<NULL>
|
||||
DECLARE
|
||||
content BLOB;
|
||||
v_handle int;
|
||||
src raw;
|
||||
BEGIN
|
||||
content := '123';
|
||||
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
|
||||
src := '123';
|
||||
GMS_COMPRESS.LZ_COMPRESS_ADD(v_handle+1,content,src);
|
||||
GMS_COMPRESS.LZ_COMPRESS_CLOSE(v_handle,content);
|
||||
RAISE NOTICE 'content=%', content;
|
||||
END;
|
||||
/
|
||||
ERROR: handle 2 is not be used
|
||||
CONTEXT: SQL statement "CALL gms_compress.compress_add(handle,src)"
|
||||
PL/pgSQL function gms_compress.lz_compress_add(integer,blob,raw) line 5 at PERFORM
|
||||
SQL statement "CALL gms_compress.lz_compress_add(v_handle+1,content,src)"
|
||||
PL/pgSQL function inline_code_block line 8 at SQL statement
|
||||
DECLARE
|
||||
content BLOB;
|
||||
BEGIN
|
||||
GMS_COMPRESS.LZ_COMPRESS_CLOSE(1,content);
|
||||
RAISE NOTICE 'content=%', content;
|
||||
END;
|
||||
/
|
||||
NOTICE: content=<NULL>
|
||||
-- test gms_compress.lz_uncompress_open and ms_compress.lz_uncompress_close
|
||||
DECLARE
|
||||
content BLOB;
|
||||
v_handle int;
|
||||
BEGIN
|
||||
content := '123';
|
||||
content := GMS_COMPRESS.LZ_COMPRESS(content);
|
||||
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
|
||||
RAISE NOTICE 'v_handle=%', v_handle;
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(v_handle);
|
||||
RAISE NOTICE 'content=%', content;
|
||||
END;
|
||||
/
|
||||
NOTICE: v_handle=1
|
||||
NOTICE: content=1F8B080000000000000363540600CC52A5FA02000000
|
||||
DECLARE
|
||||
content BLOB;
|
||||
v_handle int;
|
||||
BEGIN
|
||||
content := '123';
|
||||
content := GMS_COMPRESS.LZ_COMPRESS(content);
|
||||
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
|
||||
RAISE NOTICE 'v_handle=%', v_handle;
|
||||
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
|
||||
RAISE NOTICE 'v_handle=%', v_handle;
|
||||
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
|
||||
RAISE NOTICE 'v_handle=%', v_handle;
|
||||
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
|
||||
RAISE NOTICE 'v_handle=%', v_handle;
|
||||
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
|
||||
RAISE NOTICE 'v_handle=%', v_handle;
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(1);
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(2);
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(3);
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(4);
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(5);
|
||||
END;
|
||||
/
|
||||
NOTICE: v_handle=1
|
||||
NOTICE: v_handle=2
|
||||
NOTICE: v_handle=3
|
||||
NOTICE: v_handle=4
|
||||
NOTICE: v_handle=5
|
||||
-- abnormal scenario
|
||||
DECLARE
|
||||
content BLOB;
|
||||
v_handle int;
|
||||
BEGIN
|
||||
content := '';
|
||||
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(v_handle);
|
||||
END;
|
||||
/
|
||||
ERROR: uncompress_data can not be NULL
|
||||
CONTEXT: PL/pgSQL function inline_code_block line 5 at assignment
|
||||
DECLARE
|
||||
content BLOB;
|
||||
v_handle int;
|
||||
BEGIN
|
||||
content := '123';
|
||||
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(v_handle);
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(v_handle);
|
||||
END;
|
||||
/
|
||||
ERROR: handle 1 is not be used
|
||||
CONTEXT: SQL statement "CALL gms_compress.uncompress_close(handle)"
|
||||
PL/pgSQL function gms_compress.lz_uncompress_close(integer) line 2 at PERFORM
|
||||
SQL statement "CALL gms_compress.lz_uncompress_close(v_handle)"
|
||||
PL/pgSQL function inline_code_block line 7 at PERFORM
|
||||
DECLARE
|
||||
content BLOB;
|
||||
v_handle int;
|
||||
BEGIN
|
||||
content := '123';
|
||||
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(v_handle);
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(0);
|
||||
END;
|
||||
/
|
||||
ERROR: invalid handle, it be within the range of 1 to 5
|
||||
CONTEXT: SQL statement "CALL gms_compress.uncompress_close(handle)"
|
||||
PL/pgSQL function gms_compress.lz_uncompress_close(integer) line 2 at PERFORM
|
||||
SQL statement "CALL gms_compress.lz_uncompress_close(0)"
|
||||
PL/pgSQL function inline_code_block line 7 at PERFORM
|
||||
DECLARE
|
||||
content BLOB;
|
||||
v_handle int;
|
||||
BEGIN
|
||||
content := '123';
|
||||
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(v_handle);
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(2);
|
||||
END;
|
||||
/
|
||||
ERROR: handle 2 is not be used
|
||||
CONTEXT: SQL statement "CALL gms_compress.uncompress_close(handle)"
|
||||
PL/pgSQL function gms_compress.lz_uncompress_close(integer) line 2 at PERFORM
|
||||
SQL statement "CALL gms_compress.lz_uncompress_close(2)"
|
||||
PL/pgSQL function inline_code_block line 7 at PERFORM
|
||||
DECLARE
|
||||
content BLOB;
|
||||
v_handle int;
|
||||
BEGIN
|
||||
content := '123';
|
||||
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(v_handle);
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(2);
|
||||
END;
|
||||
/
|
||||
ERROR: handle 1 is a compressed handle
|
||||
CONTEXT: SQL statement "CALL gms_compress.uncompress_close(handle)"
|
||||
PL/pgSQL function gms_compress.lz_uncompress_close(integer) line 2 at PERFORM
|
||||
SQL statement "CALL gms_compress.lz_uncompress_close(v_handle)"
|
||||
PL/pgSQL function inline_code_block line 6 at PERFORM
|
||||
DECLARE
|
||||
content BLOB;
|
||||
BEGIN
|
||||
GMS_COMPRESS.LZ_COMPRESS_CLOSE(1, content);
|
||||
END;
|
||||
/
|
||||
DECLARE
|
||||
content BLOB;
|
||||
v_handle int;
|
||||
BEGIN
|
||||
content := '123';
|
||||
content := GMS_COMPRESS.LZ_COMPRESS(content);
|
||||
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
|
||||
RAISE NOTICE 'v_handle=%', v_handle;
|
||||
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
|
||||
RAISE NOTICE 'v_handle=%', v_handle;
|
||||
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
|
||||
RAISE NOTICE 'v_handle=%', v_handle;
|
||||
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
|
||||
RAISE NOTICE 'v_handle=%', v_handle;
|
||||
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
|
||||
RAISE NOTICE 'v_handle=%', v_handle;
|
||||
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
|
||||
RAISE NOTICE 'v_handle=%', v_handle;
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(1);
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(2);
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(3);
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(4);
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(5);
|
||||
END;
|
||||
/
|
||||
NOTICE: v_handle=1
|
||||
NOTICE: v_handle=2
|
||||
NOTICE: v_handle=3
|
||||
NOTICE: v_handle=4
|
||||
NOTICE: v_handle=5
|
||||
ERROR: no handle free, the maximum number of handles is 5
|
||||
CONTEXT: PL/pgSQL function inline_code_block line 16 at assignment
|
||||
DECLARE
|
||||
content BLOB;
|
||||
v_handle int;
|
||||
BEGIN
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(1);
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(2);
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(3);
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(4);
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(5);
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(6);
|
||||
END;
|
||||
/
|
||||
ERROR: invalid handle, it be within the range of 1 to 5
|
||||
CONTEXT: SQL statement "CALL gms_compress.uncompress_close(handle)"
|
||||
PL/pgSQL function gms_compress.lz_uncompress_close(integer) line 2 at PERFORM
|
||||
SQL statement "CALL gms_compress.lz_uncompress_close(6)"
|
||||
PL/pgSQL function inline_code_block line 9 at PERFORM
|
||||
-- test gms_compress.lz_uncompress_extract
|
||||
DECLARE
|
||||
content BLOB;
|
||||
v_handle int;
|
||||
v_raw raw;
|
||||
BEGIN
|
||||
content := '123';
|
||||
content := GMS_COMPRESS.LZ_COMPRESS(content);
|
||||
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_EXTRACT(v_handle, v_raw);
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(v_handle);
|
||||
RAISE NOTICE 'content=%', content;
|
||||
RAISE NOTICE 'v_raw=%', v_raw;
|
||||
END;
|
||||
/
|
||||
NOTICE: content=1F8B080000000000000363540600CC52A5FA02000000
|
||||
NOTICE: v_raw=0123
|
||||
-- abnormal scenario
|
||||
DECLARE
|
||||
content BLOB;
|
||||
v_handle int;
|
||||
v_raw raw;
|
||||
BEGIN
|
||||
content := '123';
|
||||
content := GMS_COMPRESS.LZ_COMPRESS(content);
|
||||
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_EXTRACT(0, v_raw);
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(v_handle);
|
||||
RAISE NOTICE 'content=%', content;
|
||||
RAISE NOTICE 'v_raw=%', v_raw;
|
||||
END;
|
||||
/
|
||||
ERROR: invalid handle, it be within the range of 1 to 5
|
||||
CONTEXT: PL/pgSQL function gms_compress.lz_uncompress_extract(integer,raw) line 2 at assignment
|
||||
SQL statement "CALL gms_compress.lz_uncompress_extract(0,v_raw)"
|
||||
PL/pgSQL function inline_code_block line 8 at SQL statement
|
||||
DECLARE
|
||||
content BLOB;
|
||||
BEGIN
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(1);
|
||||
END;
|
||||
/
|
||||
DECLARE
|
||||
content BLOB;
|
||||
v_handle int;
|
||||
v_raw raw;
|
||||
BEGIN
|
||||
content := '123';
|
||||
content := GMS_COMPRESS.LZ_COMPRESS(content);
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_EXTRACT(1, v_raw);
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(v_handle);
|
||||
RAISE NOTICE 'content=%', content;
|
||||
RAISE NOTICE 'v_raw=%', v_raw;
|
||||
END;
|
||||
/
|
||||
ERROR: handle 1 is not be used
|
||||
CONTEXT: PL/pgSQL function gms_compress.lz_uncompress_extract(integer,raw) line 2 at assignment
|
||||
SQL statement "CALL gms_compress.lz_uncompress_extract(1,v_raw)"
|
||||
PL/pgSQL function inline_code_block line 7 at SQL statement
|
||||
DECLARE
|
||||
content BLOB;
|
||||
v_handle int;
|
||||
v_raw raw;
|
||||
BEGIN
|
||||
content := '123';
|
||||
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_EXTRACT(v_handle, v_raw);
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(v_handle);
|
||||
RAISE NOTICE 'content=%', content;
|
||||
RAISE NOTICE 'v_raw=%', v_raw;
|
||||
END;
|
||||
/
|
||||
ERROR: no compressed data found in handle 1
|
||||
CONTEXT: PL/pgSQL function gms_compress.lz_uncompress_extract(integer,raw) line 2 at assignment
|
||||
SQL statement "CALL gms_compress.lz_uncompress_extract(v_handle,v_raw)"
|
||||
PL/pgSQL function inline_code_block line 7 at SQL statement
|
||||
DECLARE
|
||||
content BLOB;
|
||||
BEGIN
|
||||
GMS_COMPRESS.LZ_COMPRESS_CLOSE(1);
|
||||
END;
|
||||
/
|
||||
DECLARE
|
||||
content BLOB;
|
||||
v_handle int;
|
||||
v_raw raw;
|
||||
BEGIN
|
||||
content := '123';
|
||||
content := GMS_COMPRESS.LZ_COMPRESS(content);
|
||||
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_EXTRACT(v_handle, v_raw);
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_EXTRACT(v_handle, v_raw);
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(v_handle);
|
||||
RAISE NOTICE 'content=%', content;
|
||||
RAISE NOTICE 'v_raw=%', v_raw;
|
||||
END;
|
||||
/
|
||||
ERROR: no compressed data found in handle 1
|
||||
CONTEXT: PL/pgSQL function gms_compress.lz_uncompress_extract(integer,raw) line 2 at assignment
|
||||
SQL statement "CALL gms_compress.lz_uncompress_extract(v_handle,v_raw)"
|
||||
PL/pgSQL function inline_code_block line 9 at SQL statement
|
||||
DECLARE
|
||||
content BLOB;
|
||||
BEGIN
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(1);
|
||||
END;
|
||||
/
|
||||
DECLARE
|
||||
content BLOB;
|
||||
v_handle int;
|
||||
v_raw raw;
|
||||
BEGIN
|
||||
content := '123';
|
||||
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_EXTRACT(v_handle, v_raw);
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(v_handle);
|
||||
RAISE NOTICE 'content=%', content;
|
||||
RAISE NOTICE 'v_raw=%', v_raw;
|
||||
END;
|
||||
/
|
||||
ERROR: too small, minimum length of gzip format is 14 bytes
|
||||
CONTEXT: PL/pgSQL function gms_compress.lz_uncompress_extract(integer,raw) line 2 at assignment
|
||||
SQL statement "CALL gms_compress.lz_uncompress_extract(v_handle,v_raw)"
|
||||
PL/pgSQL function inline_code_block line 7 at SQL statement
|
||||
DECLARE
|
||||
content BLOB;
|
||||
BEGIN
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(1);
|
||||
END;
|
||||
/
|
||||
-- test gms_compress.lz_isopen
|
||||
DECLARE
|
||||
content BLOB;
|
||||
v_handle int;
|
||||
v_bool boolean;
|
||||
BEGIN
|
||||
content := '123';
|
||||
v_bool := false;
|
||||
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
|
||||
v_bool := GMS_COMPRESS.ISOPEN(v_handle);
|
||||
RAISE NOTICE 'v_bool=%', v_bool;
|
||||
GMS_COMPRESS.LZ_COMPRESS_CLOSE(v_handle,content);
|
||||
v_bool := GMS_COMPRESS.ISOPEN(v_handle);
|
||||
RAISE NOTICE 'v_bool=%', v_bool;
|
||||
END;
|
||||
/
|
||||
NOTICE: v_bool=t
|
||||
NOTICE: v_bool=f
|
||||
DECLARE
|
||||
content BLOB;
|
||||
v_handle int;
|
||||
v_bool boolean;
|
||||
BEGIN
|
||||
content := '123';
|
||||
v_bool := false;
|
||||
content := GMS_COMPRESS.LZ_COMPRESS(content);
|
||||
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
|
||||
v_bool := GMS_COMPRESS.ISOPEN(v_handle);
|
||||
RAISE NOTICE 'v_bool=%', v_bool;
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(v_handle);
|
||||
v_bool := GMS_COMPRESS.ISOPEN(v_handle);
|
||||
RAISE NOTICE 'v_bool=%', v_bool;
|
||||
END;
|
||||
/
|
||||
NOTICE: v_bool=t
|
||||
NOTICE: v_bool=f
|
||||
-- abnormal scenario
|
||||
DECLARE
|
||||
v_bool boolean;
|
||||
BEGIN
|
||||
v_bool := true;
|
||||
v_bool := GMS_COMPRESS.ISOPEN(0);
|
||||
RAISE NOTICE 'v_bool=%', v_bool;
|
||||
END;
|
||||
/
|
||||
NOTICE: v_bool=f
|
||||
DECLARE
|
||||
v_bool boolean;
|
||||
BEGIN
|
||||
v_bool := true;
|
||||
v_bool := GMS_COMPRESS.ISOPEN(1);
|
||||
RAISE NOTICE 'v_bool=%', v_bool;
|
||||
END;
|
||||
/
|
||||
NOTICE: v_bool=f
|
||||
reset search_path;
|
||||
drop schema gms_compress_test cascade;
|
||||
102
contrib/gms_compress/gms_compress--1.0.sql
Normal file
102
contrib/gms_compress/gms_compress--1.0.sql
Normal file
@ -0,0 +1,102 @@
|
||||
/* contrib/gms_compress/gms_compress--1.0.sql */
|
||||
|
||||
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
|
||||
\echo Use "CREATE EXTENSION gms_compress" to load this file. \quit
|
||||
|
||||
CREATE SCHEMA gms_compress;
|
||||
GRANT USAGE ON SCHEMA gms_compress TO PUBLIC;
|
||||
|
||||
set behavior_compat_options='proc_outparam_override';
|
||||
--These functions and procedures compress data using Lempel-Ziv compression algorithm.
|
||||
CREATE OR REPLACE FUNCTION gms_compress.lz_compress(src IN raw, quality IN integer := 6)
|
||||
RETURNS raw PACKAGE
|
||||
AS 'MODULE_PATHNAME','gms_lz_compress'
|
||||
LANGUAGE C;
|
||||
|
||||
CREATE OR REPLACE FUNCTION gms_compress.lz_compress(src IN blob, quality IN integer := 6)
|
||||
RETURNS blob PACKAGE
|
||||
AS 'MODULE_PATHNAME','gms_lz_compress'
|
||||
LANGUAGE C;
|
||||
|
||||
CREATE OR REPLACE PROCEDURE gms_compress.lz_compress(src IN blob, dst INOUT blob, quality IN integer := 6) PACKAGE as
|
||||
begin
|
||||
dst := gms_compress.lz_compress(src, quality);
|
||||
end;
|
||||
|
||||
CREATE OR REPLACE FUNCTION gms_compress.lz_compress_open(src INOUT blob, quality IN integer := 6)
|
||||
RETURNS integer
|
||||
AS 'MODULE_PATHNAME','gms_lz_compress_open'
|
||||
LANGUAGE C;
|
||||
|
||||
CREATE OR REPLACE FUNCTION gms_compress.lz_compress_close(handle IN integer)
|
||||
RETURNS blob PACKAGE
|
||||
AS '$libdir/gms_compress', 'gms_lz_compress_close'
|
||||
LANGUAGE C;
|
||||
|
||||
CREATE OR REPLACE PROCEDURE gms_compress.lz_compress_close(handle IN integer, dst INOUT blob) PACKAGE AS
|
||||
begin
|
||||
dst := gms_compress.lz_compress_close(handle);
|
||||
end;
|
||||
|
||||
CREATE OR REPLACE FUNCTION gms_compress.lz_uncompress_open(src IN blob)
|
||||
RETURNS integer
|
||||
AS 'MODULE_PATHNAME','gms_lz_uncompress_open'
|
||||
LANGUAGE C;
|
||||
|
||||
CREATE OR REPLACE FUNCTION gms_compress.uncompress_close(handle IN integer)
|
||||
RETURNS void
|
||||
AS '$libdir/gms_compress', 'gms_lz_uncompress_close'
|
||||
LANGUAGE C;
|
||||
|
||||
CREATE OR REPLACE PROCEDURE gms_compress.lz_uncompress_close(handle IN integer) AS
|
||||
begin
|
||||
gms_compress.uncompress_close(handle);
|
||||
end;
|
||||
|
||||
CREATE OR REPLACE FUNCTION gms_compress.compress_add(handle IN integer, src IN raw)
|
||||
RETURNS void PACKAGE
|
||||
AS '$libdir/gms_compress', 'gms_lz_compress_add'
|
||||
LANGUAGE C;
|
||||
|
||||
CREATE OR REPLACE PROCEDURE gms_compress.lz_compress_add(handle IN integer, dst INOUT blob, src IN raw) PACKAGE AS
|
||||
begin
|
||||
IF src IS NULL THEN
|
||||
RAISE EXCEPTION 'parameter cannot be NULL';
|
||||
END IF;
|
||||
gms_compress.compress_add(handle, src);
|
||||
end;
|
||||
|
||||
CREATE OR REPLACE FUNCTION gms_compress.uncompress_extract(handle IN integer)
|
||||
RETURNS raw PACKAGE
|
||||
AS '$libdir/gms_compress', 'gms_lz_uncompress_extract'
|
||||
LANGUAGE C;
|
||||
|
||||
CREATE OR REPLACE PROCEDURE gms_compress.lz_uncompress_extract(handle IN integer, dst INOUT raw) PACKAGE AS
|
||||
begin
|
||||
dst := gms_compress.uncompress_extract(handle);
|
||||
end;
|
||||
|
||||
CREATE OR REPLACE FUNCTION gms_compress.isopen(handle IN integer)
|
||||
RETURNS boolean
|
||||
AS '$libdir/gms_compress', 'gms_isopen'
|
||||
LANGUAGE C;
|
||||
|
||||
----These functions and procedures decompress data using the Lempel-Ziv decompression algorithm.
|
||||
|
||||
CREATE OR REPLACE FUNCTION gms_compress.lz_uncompress(src IN raw)
|
||||
RETURNS raw PACKAGE
|
||||
AS 'MODULE_PATHNAME','gms_lz_uncompress'
|
||||
LANGUAGE C;
|
||||
|
||||
CREATE OR REPLACE FUNCTION gms_compress.lz_uncompress(src IN blob)
|
||||
RETURNS blob PACKAGE
|
||||
AS 'MODULE_PATHNAME','gms_lz_uncompress'
|
||||
LANGUAGE C;
|
||||
|
||||
CREATE OR REPLACE PROCEDURE gms_compress.lz_uncompress(src IN blob, dst INOUT blob) PACKAGE as
|
||||
begin
|
||||
IF src IS NULL OR dst IS NULL THEN
|
||||
RAISE EXCEPTION 'parameter cannot be NULL';
|
||||
END IF;
|
||||
dst := gms_compress.lz_uncompress(src);
|
||||
end;
|
||||
5
contrib/gms_compress/gms_compress.control
Normal file
5
contrib/gms_compress/gms_compress.control
Normal file
@ -0,0 +1,5 @@
|
||||
# gms_compress extension
|
||||
comment = 'provides a set of data compression utilities'
|
||||
default_version = '1.0'
|
||||
module_pathname = '$libdir/gms_compress'
|
||||
relocatable = true
|
||||
400
contrib/gms_compress/gms_compress.cpp
Normal file
400
contrib/gms_compress/gms_compress.cpp
Normal file
@ -0,0 +1,400 @@
|
||||
#include <cstdlib>
|
||||
#include <zlib.h>
|
||||
#include "postgres.h"
|
||||
#include "knl/knl_variable.h"
|
||||
#include "commands/extension.h"
|
||||
#include "utils/builtins.h"
|
||||
#include "utils/varbit.h"
|
||||
#include "utils/memutils.h"
|
||||
|
||||
#include "gms_compress.h"
|
||||
|
||||
PG_MODULE_MAGIC;
|
||||
|
||||
#define MIN_QUALITY 1
|
||||
#define MAX_QUALITY 9
|
||||
#define MIN_HANDLE 0
|
||||
#define MAX_HANDLE 4
|
||||
#define HANDLE_OFFSET 1
|
||||
#define UNCOMPRESS_LEVEL 0
|
||||
|
||||
PG_FUNCTION_INFO_V1(gms_lz_compress);
|
||||
PG_FUNCTION_INFO_V1(gms_lz_uncompress);
|
||||
PG_FUNCTION_INFO_V1(gms_lz_compress_open);
|
||||
PG_FUNCTION_INFO_V1(gms_lz_compress_close);
|
||||
PG_FUNCTION_INFO_V1(gms_lz_compress_add);
|
||||
PG_FUNCTION_INFO_V1(gms_lz_uncompress_open);
|
||||
PG_FUNCTION_INFO_V1(gms_lz_uncompress_close);
|
||||
PG_FUNCTION_INFO_V1(gms_lz_uncompress_extract);
|
||||
PG_FUNCTION_INFO_V1(gms_isopen);
|
||||
|
||||
static void gzip_compress(void* src, Size src_len, void** dst, Size* dst_len, int quality);
|
||||
static void gzip_uncompress(void* src, Size src_len, void** dst, Size* dst_len);
|
||||
static void free_context(int handle);
|
||||
static inline void Check_Invalid_Input(gms_compress_context* compress_cxt, int handle);
|
||||
|
||||
static uint32 compress_index;
|
||||
|
||||
void set_extension_index(uint32 index)
|
||||
{
|
||||
compress_index = index;
|
||||
}
|
||||
|
||||
void init_session_vars(void) {
|
||||
RepallocSessionVarsArrayIfNecessary();
|
||||
gms_compress_context* psc =
|
||||
(gms_compress_context*)MemoryContextAlloc(u_sess->self_mem_cxt, sizeof(gms_compress_context));
|
||||
u_sess->attr.attr_common.extension_session_vars_array[compress_index] = psc;
|
||||
|
||||
for (int i =0;i < UTLCOMP_MAX_HANDLE;i++) {
|
||||
psc->context[i].compress_level = -1;
|
||||
psc->context[i].compressed_data = NULL;
|
||||
psc->context[i].uncompressed_data = NULL;
|
||||
psc->context[i].used = false;
|
||||
}
|
||||
}
|
||||
|
||||
gms_compress_context* get_session_context() {
|
||||
if (u_sess->attr.attr_common.extension_session_vars_array[compress_index] == NULL) {
|
||||
init_session_vars();
|
||||
}
|
||||
return (gms_compress_context*)u_sess->attr.attr_common.extension_session_vars_array[compress_index];
|
||||
}
|
||||
|
||||
Datum gms_lz_compress(PG_FUNCTION_ARGS)
|
||||
{
|
||||
if (PG_ARGISNULL(0)) {
|
||||
ereport(ERROR, (errmsg("compressed data cannot be NULL")));
|
||||
}
|
||||
|
||||
bytea *input_bytea = PG_GETARG_BYTEA_PP(0);
|
||||
int quality = PG_GETARG_INT32(1);
|
||||
Size src_len = VARSIZE_ANY_EXHDR(input_bytea);
|
||||
bytea *dst = NULL;
|
||||
Size dst_len = 0;
|
||||
|
||||
/* Call gzip_compress function for compression */
|
||||
gzip_compress(input_bytea, src_len, (void**)&dst, &dst_len, quality);
|
||||
|
||||
SET_VARSIZE(dst, VARHDRSZ + dst_len);
|
||||
PG_RETURN_BYTEA_P(dst);
|
||||
}
|
||||
|
||||
Datum gms_lz_uncompress(PG_FUNCTION_ARGS)
|
||||
{
|
||||
if (PG_ARGISNULL(0)) {
|
||||
ereport(ERROR, (errmsg("uncompressed data cannot be NULL")));
|
||||
}
|
||||
|
||||
bytea *input_bytea = PG_GETARG_BYTEA_PP(0);
|
||||
Size src_len = VARSIZE_ANY_EXHDR(input_bytea);
|
||||
bytea *dst = NULL;
|
||||
Size dst_len = 0;
|
||||
|
||||
/* Call gzip_uncompress function for uncompression */
|
||||
gzip_uncompress(input_bytea, src_len, (void**)&dst, &dst_len);
|
||||
|
||||
SET_VARSIZE(dst, VARHDRSZ + dst_len);
|
||||
PG_RETURN_TEXT_P(dst);
|
||||
}
|
||||
|
||||
/* Open a handle and initialize it */
|
||||
Datum gms_lz_compress_open(PG_FUNCTION_ARGS)
|
||||
{
|
||||
bytea *input_bytea = PG_GETARG_BYTEA_PP(0);
|
||||
int quality = PG_GETARG_INT32(1);
|
||||
|
||||
if (quality < MIN_QUALITY || quality > MAX_QUALITY) {
|
||||
ereport(ERROR, (errmsg("compression quality must be within the range of %d to %d", MIN_QUALITY, MAX_QUALITY)));
|
||||
}
|
||||
|
||||
gms_compress_context *compress_cxt = get_session_context();
|
||||
for(int i = 0;i < UTLCOMP_MAX_HANDLE;i++) {
|
||||
if (!compress_cxt->context[i].used) {
|
||||
compress_cxt->context[i].compress_level = quality;
|
||||
compress_cxt->context[i].used = true;
|
||||
PG_RETURN_INT32(i + HANDLE_OFFSET);
|
||||
}
|
||||
}
|
||||
|
||||
ereport(ERROR, (errmsg("no handle free, the maximum number of handles is %d", MAX_HANDLE + HANDLE_OFFSET)));
|
||||
PG_RETURN_VOID();
|
||||
}
|
||||
|
||||
/* Close a handle and compress the data back */
|
||||
Datum gms_lz_compress_close(PG_FUNCTION_ARGS)
|
||||
{
|
||||
int handle = PG_GETARG_INT32(0) - HANDLE_OFFSET;
|
||||
gms_compress_context *compress_cxt = get_session_context();
|
||||
|
||||
Check_Invalid_Input(compress_cxt, handle);
|
||||
|
||||
if (compress_cxt->context[handle].uncompressed_data == NULL) {
|
||||
free_context(handle);
|
||||
PG_RETURN_NULL();
|
||||
}
|
||||
|
||||
if (compress_cxt->context[handle].compress_level == UNCOMPRESS_LEVEL) {
|
||||
ereport(ERROR, (errmsg("handle %d is a uncompressed handle", handle + HANDLE_OFFSET)));
|
||||
}
|
||||
|
||||
bytea *input_bytea = (bytea *)compress_cxt->context[handle].uncompressed_data;
|
||||
Assert((char*)input_bytea + VARHDRSZ == VARDATA_ANY(input_bytea));
|
||||
Size src_len = VARSIZE_ANY_EXHDR(input_bytea);
|
||||
if (src_len > MaxAllocSize - VARHDRSZ) {
|
||||
free_context(handle);
|
||||
ereport(ERROR, (errmsg("data too long, data size cannot exceed 1GB")));
|
||||
}
|
||||
|
||||
bytea *dst = NULL;
|
||||
Size dst_len = 0;
|
||||
int quality = compress_cxt->context[handle].compress_level;
|
||||
/* Call gzip_compress function for compression */
|
||||
gzip_compress(input_bytea, src_len, (void**)&dst, &dst_len, quality);
|
||||
|
||||
SET_VARSIZE(dst, VARHDRSZ + dst_len);
|
||||
|
||||
free_context(handle);
|
||||
PG_RETURN_BYTEA_P(dst);
|
||||
}
|
||||
|
||||
/* Open a handle and store data into it */
|
||||
Datum gms_lz_compress_add(PG_FUNCTION_ARGS)
|
||||
{
|
||||
int handle = PG_GETARG_INT32(0) - HANDLE_OFFSET;
|
||||
gms_compress_context *compress_cxt = get_session_context();
|
||||
bytea *input_bytea = PG_GETARG_BYTEA_PP(1);
|
||||
Size src_len = VARSIZE_ANY_EXHDR(input_bytea);
|
||||
|
||||
Check_Invalid_Input(compress_cxt, handle);
|
||||
|
||||
if (compress_cxt->context[handle].compress_level == UNCOMPRESS_LEVEL) {
|
||||
ereport(ERROR, (errmsg("handle %d is a uncompressed handle", handle + HANDLE_OFFSET)));
|
||||
}
|
||||
|
||||
if (src_len > MaxAllocSize - VARHDRSZ) {
|
||||
ereport(ERROR, (errmsg("data too long, data size cannot exceed 1GB")));
|
||||
}
|
||||
|
||||
bytea *new_data = (bytea *)compress_cxt->context[handle].uncompressed_data;
|
||||
if (new_data == NULL) {
|
||||
new_data = (bytea *)MemoryContextAlloc(u_sess->self_mem_cxt, src_len + VARHDRSZ);
|
||||
SET_VARSIZE(new_data, src_len + VARHDRSZ);
|
||||
Assert((char*)new_data + VARHDRSZ == VARDATA_ANY(new_data));
|
||||
errno_t rc = memcpy_s(VARDATA(new_data), src_len, VARDATA(input_bytea), src_len);
|
||||
securec_check(rc, "\0", "\0");
|
||||
compress_cxt->context[handle].uncompressed_data = new_data;
|
||||
} else {
|
||||
Size dst_len = VARSIZE_ANY_EXHDR(new_data);
|
||||
Size uncompressed_size = src_len + dst_len + VARHDRSZ;
|
||||
if (uncompressed_size > MaxAllocSize) {
|
||||
ereport(ERROR, (errmsg("data too long, data size cannot exceed 1GB")));
|
||||
}
|
||||
new_data = (bytea *)repalloc(new_data, uncompressed_size);
|
||||
SET_VARSIZE(new_data, uncompressed_size);
|
||||
Assert((char*)new_data + VARHDRSZ == VARDATA_ANY(new_data));
|
||||
errno_t rc = memcpy_s(VARDATA(new_data) + dst_len, src_len, VARDATA(input_bytea), src_len);
|
||||
securec_check(rc, "\0", "\0");
|
||||
compress_cxt->context[handle].uncompressed_data = new_data;
|
||||
}
|
||||
PG_RETURN_VOID();
|
||||
}
|
||||
|
||||
/* Open a handle and initialize it */
|
||||
Datum gms_lz_uncompress_open(PG_FUNCTION_ARGS)
|
||||
{
|
||||
if (PG_ARGISNULL(0)) {
|
||||
ereport(ERROR, (errmsg("uncompress_data can not be NULL")));
|
||||
}
|
||||
|
||||
bytea *input_bytea = PG_GETARG_BYTEA_PP(0);
|
||||
gms_compress_context *compress_cxt = get_session_context();
|
||||
|
||||
for(int i = 0;i < UTLCOMP_MAX_HANDLE;i++) {
|
||||
if (!compress_cxt->context[i].used) {
|
||||
compress_cxt->context[i].compressed_data = input_bytea;
|
||||
compress_cxt->context[i].compress_level = UNCOMPRESS_LEVEL;
|
||||
compress_cxt->context[i].used = true;
|
||||
|
||||
PG_RETURN_INT32(i + HANDLE_OFFSET);
|
||||
}
|
||||
}
|
||||
|
||||
ereport(ERROR, (errmsg("no handle free, the maximum number of handles is %d", MAX_HANDLE + HANDLE_OFFSET)));
|
||||
PG_RETURN_VOID();
|
||||
}
|
||||
|
||||
/* Close and free the handle */
|
||||
Datum gms_lz_uncompress_close(PG_FUNCTION_ARGS)
|
||||
{
|
||||
int handle = PG_GETARG_INT32(0) - HANDLE_OFFSET;
|
||||
gms_compress_context *compress_cxt = get_session_context();
|
||||
|
||||
Check_Invalid_Input(compress_cxt, handle);
|
||||
|
||||
if (compress_cxt->context[handle].compress_level != UNCOMPRESS_LEVEL) {
|
||||
ereport(ERROR, (errmsg("handle %d is a compressed handle", handle + HANDLE_OFFSET)));
|
||||
}
|
||||
|
||||
free_context(handle);
|
||||
PG_RETURN_VOID();
|
||||
}
|
||||
|
||||
/* Open a handle and uncompress the data back */
|
||||
Datum gms_lz_uncompress_extract(PG_FUNCTION_ARGS)
|
||||
{
|
||||
int handle = PG_GETARG_INT32(0) - HANDLE_OFFSET;
|
||||
gms_compress_context *compress_cxt = get_session_context();
|
||||
|
||||
Check_Invalid_Input(compress_cxt, handle);
|
||||
|
||||
if (compress_cxt->context[handle].compressed_data == NULL) {
|
||||
ereport(ERROR, (errmsg("no compressed data found in handle %d", handle + HANDLE_OFFSET)));
|
||||
}
|
||||
|
||||
if (compress_cxt->context[handle].compress_level != UNCOMPRESS_LEVEL) {
|
||||
ereport(ERROR, (errmsg("handle %d is a compressed handle", handle + HANDLE_OFFSET)));
|
||||
}
|
||||
|
||||
bytea *src = (bytea *)compress_cxt->context[handle].compressed_data;
|
||||
Size src_len = VARSIZE_ANY_EXHDR(src);
|
||||
Size dst_len = 0;
|
||||
bytea *dst = NULL;
|
||||
|
||||
compress_cxt->context[handle].compressed_data = NULL;
|
||||
gzip_uncompress(src, src_len, (void**)&dst, &dst_len);
|
||||
|
||||
SET_VARSIZE(dst, VARHDRSZ + dst_len);
|
||||
|
||||
PG_RETURN_BYTEA_P(dst);
|
||||
}
|
||||
|
||||
/* Check if a handle has been opened */
|
||||
Datum gms_isopen(PG_FUNCTION_ARGS)
|
||||
{
|
||||
int handle = PG_GETARG_INT32(0) - HANDLE_OFFSET;
|
||||
if (handle < MIN_HANDLE || handle > MAX_HANDLE) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return get_session_context()->context[handle].used;
|
||||
}
|
||||
|
||||
/* Using the zlib library and Lemoel Xiv algorithm to implement compression functionality */
|
||||
static void gzip_compress(void* src, Size src_len, void** dst, Size* dst_len, int quality)
|
||||
{
|
||||
/* The compression quality is limited between 1 and 9 */
|
||||
if (quality < MIN_QUALITY || quality > MAX_QUALITY) {
|
||||
ereport(ERROR, (errmsg("compression quality must be within the range of %d to %d", MIN_QUALITY, MAX_QUALITY)));
|
||||
}
|
||||
|
||||
bytea *input_bytea = (bytea*)src;
|
||||
Size compressed_size = compressBound(src_len) + GZIP_COMPRESS_EXTRA_LENGTH;
|
||||
bytea *result = (bytea*)palloc(VARHDRSZ + compressed_size);
|
||||
SET_VARSIZE(result, VARHDRSZ + compressed_size);
|
||||
|
||||
z_stream c_stream;
|
||||
c_stream.zalloc = NULL;
|
||||
c_stream.zfree = NULL;
|
||||
c_stream.opaque = NULL;
|
||||
// MAX_WBITS + 16 for gzip
|
||||
if (deflateInit2(&c_stream, quality, Z_DEFLATED, MAX_WBITS + 16, 8, Z_DEFAULT_STRATEGY) != Z_OK) {
|
||||
pfree_ext(result);
|
||||
ereport(ERROR, (errmsg("zlib compression initialization failed")));
|
||||
}
|
||||
|
||||
c_stream.avail_out = compressed_size; // output size
|
||||
c_stream.next_out = (Bytef*)VARDATA_ANY(result); // output buffer
|
||||
c_stream.avail_in = src_len; // input size
|
||||
c_stream.next_in = (Bytef*)VARDATA_ANY(input_bytea); // input buffer
|
||||
|
||||
if (deflate(&c_stream, Z_FINISH) != Z_STREAM_END) {
|
||||
pfree_ext(result);
|
||||
ereport(ERROR, (errmsg("zlib compression failed")));
|
||||
}
|
||||
|
||||
if (deflateEnd(&c_stream) != Z_OK) {
|
||||
pfree_ext(result);
|
||||
ereport(ERROR, (errmsg("zlib cleaning up compression stream failed")));
|
||||
}
|
||||
*dst_len = c_stream.total_out;
|
||||
*dst = result;
|
||||
}
|
||||
|
||||
/* Using the zlib library and Lemoel Xiv algorithm to implement uncompression functionality */
|
||||
static void gzip_uncompress(void* src, Size src_len, void** dst, Size* dst_len)
|
||||
{
|
||||
bytea *input_bytea = (bytea*)src;
|
||||
if (src_len < GZIP_MIN_LENGTH) {
|
||||
ereport(ERROR, (errmsg("too small, minimum length of gzip format is %d bytes", GZIP_MIN_LENGTH)));
|
||||
}
|
||||
unsigned char *gzip_content = (unsigned char*)VARDATA_ANY(input_bytea);
|
||||
if (gzip_content[0] != GZIP_HEADER_1 || gzip_content[1] != GZIP_HEADER_2) {
|
||||
ereport(ERROR, (errmsg("data corrupt, invalid compressed data head")));
|
||||
}
|
||||
uint4 uncompressed_size = *(uint4*)(gzip_content + src_len - sizeof(int));
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
uncompressed_size = BSWAP32(uncompressed_size);
|
||||
#endif
|
||||
if (uncompressed_size > MaxAllocSize - VARHDRSZ) {
|
||||
ereport(ERROR, (errmsg("data too long, data size cannot exceed 1GB")));
|
||||
}
|
||||
bytea *result = (bytea*)palloc(VARHDRSZ + uncompressed_size);
|
||||
SET_VARSIZE(result, VARHDRSZ + uncompressed_size);
|
||||
|
||||
z_stream d_stream = { 0 };
|
||||
d_stream.zalloc = NULL;
|
||||
d_stream.zfree = NULL;
|
||||
d_stream.opaque = NULL;
|
||||
d_stream.next_in = (Bytef*)VARDATA_ANY(input_bytea);
|
||||
d_stream.avail_in = src_len;
|
||||
d_stream.avail_out = VARSIZE_ANY_EXHDR(result);
|
||||
d_stream.next_out = (Bytef*)VARDATA_ANY(result);
|
||||
// MAX_WBITS + 16 for gzip
|
||||
if (inflateInit2(&d_stream, 16 + MAX_WBITS) != Z_OK) {
|
||||
pfree_ext(result);
|
||||
ereport(ERROR, (errmsg("zlib uncompression initialization failed")));
|
||||
}
|
||||
if (inflate(&d_stream, Z_FINISH) != Z_STREAM_END) {
|
||||
pfree_ext(result);
|
||||
ereport(ERROR, (errmsg("zlib uncompression failed")));
|
||||
}
|
||||
|
||||
if (inflateEnd(&d_stream) != Z_OK) {
|
||||
pfree_ext(result);
|
||||
ereport(ERROR, (errmsg("zlib cleaning up uncompression stream failed")));
|
||||
}
|
||||
*dst_len = d_stream.total_out;
|
||||
*dst = result;
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Because compressed_data is the data source address and
|
||||
* uncompressed_data is the newly created data address,
|
||||
* it is necessary to point compressed_data to null and release uncompressed_data
|
||||
*/
|
||||
static void free_context(int handle)
|
||||
{
|
||||
if (handle < MIN_HANDLE || handle > MAX_HANDLE)
|
||||
{
|
||||
return;
|
||||
}
|
||||
gms_compress_context *compress_cxt = get_session_context();
|
||||
compress_cxt->context[handle].compressed_data =NULL;
|
||||
pfree_ext(compress_cxt->context[handle].uncompressed_data);
|
||||
compress_cxt->context[handle].compress_level = -1;
|
||||
compress_cxt->context[handle].used = false;
|
||||
return;
|
||||
}
|
||||
|
||||
static inline void Check_Invalid_Input(gms_compress_context* compress_cxt, int handle) {
|
||||
if (handle < MIN_HANDLE || handle > MAX_HANDLE) {
|
||||
ereport(ERROR, (errmsg("invalid handle, it be within the range of %d to %d",
|
||||
MIN_HANDLE + HANDLE_OFFSET, MAX_HANDLE + HANDLE_OFFSET)));
|
||||
}
|
||||
|
||||
if (!compress_cxt->context[handle].used) {
|
||||
ereport(ERROR, (errmsg("handle %d is not be used", handle + HANDLE_OFFSET)));
|
||||
}
|
||||
}
|
||||
36
contrib/gms_compress/gms_compress.h
Normal file
36
contrib/gms_compress/gms_compress.h
Normal file
@ -0,0 +1,36 @@
|
||||
#ifndef __GMS_COMPRESS__
|
||||
#define __GMS_COMPRESS__
|
||||
|
||||
|
||||
#include "postgres.h"
|
||||
|
||||
#define GZIP_COMPRESS_EXTRA_LENGTH 18
|
||||
#define GZIP_MIN_LENGTH 14
|
||||
#define GZIP_HEADER_1 ((unsigned char)0x1f)
|
||||
#define GZIP_HEADER_2 ((unsigned char)0x8b)
|
||||
#define UTLCOMP_MAX_HANDLE 5
|
||||
|
||||
typedef struct gms_context {
|
||||
void *uncompressed_data; /* data to be compressed */
|
||||
void *compressed_data; /* data after compressed or data to be uncompressed */
|
||||
int2 compress_level; /* 0 for uncompress, 1~9 for compress */
|
||||
bool used;
|
||||
} gms_context;
|
||||
typedef struct gms_compress_context {
|
||||
gms_context context[UTLCOMP_MAX_HANDLE];
|
||||
} gms_compress_context;
|
||||
|
||||
extern "C" Datum gms_lz_compress(PG_FUNCTION_ARGS);
|
||||
extern "C" Datum gms_lz_uncompress(PG_FUNCTION_ARGS);
|
||||
extern "C" Datum gms_lz_compress_open(PG_FUNCTION_ARGS);
|
||||
extern "C" Datum gms_lz_compress_close(PG_FUNCTION_ARGS);
|
||||
extern "C" Datum gms_lz_compress_add(PG_FUNCTION_ARGS);
|
||||
extern "C" Datum gms_lz_uncompress_open(PG_FUNCTION_ARGS);
|
||||
extern "C" Datum gms_lz_uncompress_close(PG_FUNCTION_ARGS);
|
||||
extern "C" Datum gms_lz_uncompress_extract(PG_FUNCTION_ARGS);
|
||||
extern "C" Datum gms_isopen(PG_FUNCTION_ARGS);
|
||||
extern "C" void set_extension_index(uint32 index);
|
||||
extern "C" void init_session_vars(void);
|
||||
|
||||
|
||||
#endif // __GMS_COMPRESS__
|
||||
715
contrib/gms_compress/sql/gms_compress.sql
Normal file
715
contrib/gms_compress/sql/gms_compress.sql
Normal file
@ -0,0 +1,715 @@
|
||||
create extension gms_compress;
|
||||
create schema gms_compress_test;
|
||||
set search_path=gms_compress_test;
|
||||
|
||||
-- test gms_compress.compress
|
||||
select gms_compress.lz_compress('123'::raw);
|
||||
select gms_compress.lz_compress('df'::raw);
|
||||
select gms_compress.lz_compress('12ab56'::raw);
|
||||
select gms_compress.lz_compress('123'::raw, 1);
|
||||
select gms_compress.lz_compress('df'::raw, 6);
|
||||
select gms_compress.lz_compress('12ab56'::raw, 9);
|
||||
select gms_compress.lz_compress('123'::blob);
|
||||
select gms_compress.lz_compress('df'::blob);
|
||||
select gms_compress.lz_compress('12ab56'::blob);
|
||||
select gms_compress.lz_compress('123'::blob, 1);
|
||||
select gms_compress.lz_compress('df'::blob, 6);
|
||||
select gms_compress.lz_compress('12ab56'::blob, 9);
|
||||
|
||||
|
||||
DECLARE
|
||||
content BLOB;
|
||||
r_content BLOB;
|
||||
v_handle int;
|
||||
v_raw raw;
|
||||
r_raw raw;
|
||||
v_bool boolean;
|
||||
BEGIN
|
||||
content := '123';
|
||||
v_raw := '12345';
|
||||
r_content := GMS_COMPRESS.LZ_COMPRESS(content);
|
||||
r_raw := GMS_COMPRESS.LZ_COMPRESS(v_raw);
|
||||
RAISE NOTICE 'r_content=%,r_raw=%', r_content, r_raw;
|
||||
r_content := '111';
|
||||
GMS_COMPRESS.LZ_COMPRESS(content, r_content);
|
||||
RAISE NOTICE 'r_content=%', r_content;
|
||||
END;
|
||||
/
|
||||
|
||||
DECLARE
|
||||
content BLOB;
|
||||
r_content BLOB;
|
||||
v_handle int;
|
||||
v_raw raw;
|
||||
r_raw raw;
|
||||
v_bool boolean;
|
||||
BEGIN
|
||||
content := 'abc';
|
||||
v_raw := 'df';
|
||||
r_content := GMS_COMPRESS.LZ_COMPRESS(content, 1);
|
||||
r_raw := GMS_COMPRESS.LZ_COMPRESS(v_raw, 9);
|
||||
RAISE NOTICE 'r_content=%,r_raw=%', r_content, r_raw;
|
||||
r_content := '111';
|
||||
GMS_COMPRESS.LZ_COMPRESS(content, r_content, 5);
|
||||
RAISE NOTICE 'r_content=%', r_content;
|
||||
END;
|
||||
/
|
||||
|
||||
-- abnormal scenario
|
||||
select gms_compress.lz_compress(null::raw);
|
||||
select gms_compress.lz_compress(''::raw);
|
||||
select gms_compress.lz_compress('dfg'::raw);
|
||||
select gms_compress.lz_compress('dfg'::raw, 5);
|
||||
select gms_compress.lz_compress('123'::raw, 0);
|
||||
select gms_compress.lz_compress('123'::raw, 10);
|
||||
select gms_compress.lz_compress(null::blob);
|
||||
select gms_compress.lz_compress(''::blob);
|
||||
select gms_compress.lz_compress('dfg'::blob);
|
||||
select gms_compress.lz_compress('dfg'::blob, 5);
|
||||
select gms_compress.lz_compress('123'::blob, 0);
|
||||
select gms_compress.lz_compress('123'::blob, 10);
|
||||
|
||||
DECLARE
|
||||
content BLOB;
|
||||
r_content BLOB;
|
||||
v_raw raw;
|
||||
r_raw raw;
|
||||
BEGIN
|
||||
content := '';
|
||||
v_raw := 'dfg';
|
||||
r_content := GMS_COMPRESS.LZ_COMPRESS(content);
|
||||
r_raw := GMS_COMPRESS.LZ_COMPRESS(v_raw);
|
||||
RAISE NOTICE 'r_content=%,r_raw=%', r_content, r_raw;
|
||||
r_content := '111';
|
||||
GMS_COMPRESS.LZ_COMPRESS(content, r_content);
|
||||
RAISE NOTICE 'r_content=%', r_content;
|
||||
END;
|
||||
/
|
||||
|
||||
DECLARE
|
||||
content BLOB;
|
||||
r_content BLOB;
|
||||
v_raw raw;
|
||||
r_raw raw;
|
||||
BEGIN
|
||||
content := 'abc';
|
||||
v_raw := 'df';
|
||||
r_content := GMS_COMPRESS.LZ_COMPRESS(content, 0);
|
||||
r_raw := GMS_COMPRESS.LZ_COMPRESS(v_raw, 10);
|
||||
RAISE NOTICE 'r_content=%,r_raw=%', r_content, r_raw;
|
||||
r_content := '111';
|
||||
GMS_COMPRESS.LZ_COMPRESS(content, r_content, -1);
|
||||
RAISE NOTICE 'r_content=%', r_content;
|
||||
END;
|
||||
/
|
||||
|
||||
-- test gms_compress.lz_uncompress
|
||||
select gms_compress.lz_uncompress(gms_compress.lz_compress('123'::raw));
|
||||
select gms_compress.lz_uncompress(gms_compress.lz_compress('df'::raw));
|
||||
select gms_compress.lz_uncompress(gms_compress.lz_compress('12ab56'::raw));
|
||||
select gms_compress.lz_uncompress(gms_compress.lz_compress('123'::raw, 1));
|
||||
select gms_compress.lz_uncompress(gms_compress.lz_compress('df'::raw, 6));
|
||||
select gms_compress.lz_uncompress(gms_compress.lz_compress('12ab56'::raw, 9));
|
||||
select gms_compress.lz_uncompress(gms_compress.lz_compress('123'::blob));
|
||||
select gms_compress.lz_uncompress(gms_compress.lz_compress('df'::blob));
|
||||
select gms_compress.lz_uncompress(gms_compress.lz_compress('12ab56'::blob));
|
||||
select gms_compress.lz_uncompress(gms_compress.lz_compress('123'::blob, 1));
|
||||
select gms_compress.lz_uncompress(gms_compress.lz_compress('df'::blob, 6));
|
||||
select gms_compress.lz_uncompress(gms_compress.lz_compress('12ab56'::blob, 9));
|
||||
|
||||
DECLARE
|
||||
content BLOB;
|
||||
r_content BLOB;
|
||||
v_content BLOB;
|
||||
v_bool boolean;
|
||||
BEGIN
|
||||
content := '123';
|
||||
v_content := '123';
|
||||
r_content := GMS_COMPRESS.LZ_COMPRESS(content);
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS(r_content, v_content);
|
||||
RAISE NOTICE 'content=%,r_content=%,v_content=%', content, r_content, v_content;
|
||||
END;
|
||||
/
|
||||
|
||||
-- abnormal scenario
|
||||
select gms_compress.lz_uncompress(null::raw);
|
||||
select gms_compress.lz_uncompress(''::raw);
|
||||
select gms_compress.lz_uncompress('dfg'::raw);
|
||||
select gms_compress.lz_uncompress('123'::raw);
|
||||
select gms_compress.lz_uncompress(null::blob);
|
||||
select gms_compress.lz_uncompress(''::blob);
|
||||
select gms_compress.lz_uncompress('dfg'::blob);
|
||||
select gms_compress.lz_uncompress('123'::blob);
|
||||
|
||||
DECLARE
|
||||
content BLOB;
|
||||
r_content BLOB;
|
||||
v_content BLOB;
|
||||
v_bool boolean;
|
||||
BEGIN
|
||||
r_content := NULL;
|
||||
v_content := '123';
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS(r_content, v_content);
|
||||
RAISE NOTICE 'content=%,r_content=%,v_content=%', content, r_content, v_content;
|
||||
END;
|
||||
/
|
||||
|
||||
DECLARE
|
||||
content BLOB;
|
||||
r_content BLOB;
|
||||
v_content BLOB;
|
||||
v_bool boolean;
|
||||
BEGIN
|
||||
r_content := '123';
|
||||
v_content := '123';
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS(r_content, v_content);
|
||||
RAISE NOTICE 'content=%,r_content=%,v_content=%', content, r_content, v_content;
|
||||
END;
|
||||
/
|
||||
|
||||
DECLARE
|
||||
content BLOB;
|
||||
r_content BLOB;
|
||||
v_content BLOB;
|
||||
v_bool boolean;
|
||||
BEGIN
|
||||
content := '123';
|
||||
r_content := GMS_COMPRESS.LZ_COMPRESS(content);
|
||||
v_content := NULL;
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS(r_content, v_content);
|
||||
RAISE NOTICE 'content=%,r_content=%,v_content=%', content, r_content, v_content;
|
||||
END;
|
||||
/
|
||||
|
||||
-- test gms_compress.lz_compress_open and ms_compress.lz_compress_close
|
||||
DECLARE
|
||||
content BLOB;
|
||||
v_handle int;
|
||||
BEGIN
|
||||
content := '123';
|
||||
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
|
||||
GMS_COMPRESS.LZ_COMPRESS_CLOSE(v_handle,content);
|
||||
RAISE NOTICE 'content=%', content;
|
||||
END;
|
||||
/
|
||||
|
||||
DECLARE
|
||||
content BLOB;
|
||||
v_handle int;
|
||||
BEGIN
|
||||
content := '123';
|
||||
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content,5);
|
||||
GMS_COMPRESS.LZ_COMPRESS_CLOSE(v_handle,content);
|
||||
RAISE NOTICE 'content=%', content;
|
||||
END;
|
||||
/
|
||||
|
||||
DECLARE
|
||||
content BLOB;
|
||||
v_handle int;
|
||||
BEGIN
|
||||
content := '123';
|
||||
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
|
||||
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
|
||||
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
|
||||
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
|
||||
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
|
||||
GMS_COMPRESS.LZ_COMPRESS_CLOSE(1,content);
|
||||
GMS_COMPRESS.LZ_COMPRESS_CLOSE(2,content);
|
||||
GMS_COMPRESS.LZ_COMPRESS_CLOSE(3,content);
|
||||
GMS_COMPRESS.LZ_COMPRESS_CLOSE(4,content);
|
||||
GMS_COMPRESS.LZ_COMPRESS_CLOSE(5,content);
|
||||
END;
|
||||
/
|
||||
|
||||
-- abnormal scenario
|
||||
DECLARE
|
||||
content BLOB;
|
||||
v_handle int;
|
||||
BEGIN
|
||||
content := '';
|
||||
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
|
||||
GMS_COMPRESS.LZ_COMPRESS_CLOSE(v_handle,content);
|
||||
RAISE NOTICE 'content=%', content;
|
||||
END;
|
||||
/
|
||||
|
||||
DECLARE
|
||||
content BLOB;
|
||||
v_handle int;
|
||||
BEGIN
|
||||
content := '123';
|
||||
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content, 0);
|
||||
GMS_COMPRESS.LZ_COMPRESS_CLOSE(v_handle,content);
|
||||
RAISE NOTICE 'content=%', content;
|
||||
END;
|
||||
/
|
||||
|
||||
DECLARE
|
||||
content BLOB;
|
||||
v_handle int;
|
||||
BEGIN
|
||||
content := '123';
|
||||
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
|
||||
GMS_COMPRESS.LZ_COMPRESS_CLOSE(0,content);
|
||||
RAISE NOTICE 'content=%', content;
|
||||
END;
|
||||
/
|
||||
DECLARE
|
||||
content BLOB;
|
||||
BEGIN
|
||||
GMS_COMPRESS.LZ_COMPRESS_CLOSE(1,content);
|
||||
RAISE NOTICE 'content=%', content;
|
||||
END;
|
||||
/
|
||||
|
||||
DECLARE
|
||||
content BLOB;
|
||||
v_handle int;
|
||||
BEGIN
|
||||
content := '123';
|
||||
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
|
||||
GMS_COMPRESS.LZ_COMPRESS_CLOSE(v_handle+1,content);
|
||||
RAISE NOTICE 'content=%', content;
|
||||
END;
|
||||
/
|
||||
DECLARE
|
||||
content BLOB;
|
||||
BEGIN
|
||||
GMS_COMPRESS.LZ_COMPRESS_CLOSE(1,content);
|
||||
RAISE NOTICE 'content=%', content;
|
||||
END;
|
||||
/
|
||||
|
||||
DECLARE
|
||||
content BLOB;
|
||||
v_handle int;
|
||||
BEGIN
|
||||
content := '123';
|
||||
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
|
||||
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
|
||||
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
|
||||
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
|
||||
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
|
||||
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
|
||||
RAISE NOTICE 'content=%', content;
|
||||
END;
|
||||
/
|
||||
|
||||
DECLARE
|
||||
content BLOB;
|
||||
v_handle int;
|
||||
BEGIN
|
||||
content := '123';
|
||||
GMS_COMPRESS.LZ_COMPRESS_CLOSE(1,content);
|
||||
GMS_COMPRESS.LZ_COMPRESS_CLOSE(2,content);
|
||||
GMS_COMPRESS.LZ_COMPRESS_CLOSE(3,content);
|
||||
GMS_COMPRESS.LZ_COMPRESS_CLOSE(4,content);
|
||||
GMS_COMPRESS.LZ_COMPRESS_CLOSE(5,content);
|
||||
GMS_COMPRESS.LZ_COMPRESS_CLOSE(1,content);
|
||||
RAISE NOTICE 'content=%', content;
|
||||
END;
|
||||
/
|
||||
|
||||
|
||||
-- test gms_compress.lz_compress_add
|
||||
DECLARE
|
||||
content BLOB;
|
||||
v_handle int;
|
||||
src raw;
|
||||
BEGIN
|
||||
content := '123';
|
||||
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
|
||||
src := '123';
|
||||
GMS_COMPRESS.LZ_COMPRESS_ADD(v_handle,content,src);
|
||||
GMS_COMPRESS.LZ_COMPRESS_CLOSE(v_handle,content);
|
||||
RAISE NOTICE 'content=%', content;
|
||||
END;
|
||||
/
|
||||
|
||||
DECLARE
|
||||
content BLOB;
|
||||
v_handle int;
|
||||
src raw;
|
||||
BEGIN
|
||||
content := '123';
|
||||
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
|
||||
src := '123';
|
||||
GMS_COMPRESS.LZ_COMPRESS_ADD(v_handle,content,src);
|
||||
GMS_COMPRESS.LZ_COMPRESS_ADD(v_handle,content,src);
|
||||
GMS_COMPRESS.LZ_COMPRESS_CLOSE(v_handle,content);
|
||||
RAISE NOTICE 'content=%', content;
|
||||
END;
|
||||
/
|
||||
|
||||
-- abnormal scenario
|
||||
DECLARE
|
||||
content BLOB;
|
||||
v_handle int;
|
||||
src raw;
|
||||
BEGIN
|
||||
content := '123';
|
||||
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
|
||||
src := '123';
|
||||
GMS_COMPRESS.LZ_COMPRESS_ADD(v_handle,content,NULL);
|
||||
GMS_COMPRESS.LZ_COMPRESS_CLOSE(v_handle,content);
|
||||
RAISE NOTICE 'content=%', content;
|
||||
END;
|
||||
/
|
||||
DECLARE
|
||||
content BLOB;
|
||||
BEGIN
|
||||
GMS_COMPRESS.LZ_COMPRESS_CLOSE(1,content);
|
||||
RAISE NOTICE 'content=%', content;
|
||||
END;
|
||||
/
|
||||
|
||||
DECLARE
|
||||
content BLOB;
|
||||
v_handle int;
|
||||
src raw;
|
||||
BEGIN
|
||||
content := '123';
|
||||
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
|
||||
src := '123';
|
||||
GMS_COMPRESS.LZ_COMPRESS_ADD(0,content,src);
|
||||
GMS_COMPRESS.LZ_COMPRESS_CLOSE(v_handle,content);
|
||||
RAISE NOTICE 'content=%', content;
|
||||
END;
|
||||
/
|
||||
DECLARE
|
||||
content BLOB;
|
||||
BEGIN
|
||||
GMS_COMPRESS.LZ_COMPRESS_CLOSE(1,content);
|
||||
RAISE NOTICE 'content=%', content;
|
||||
END;
|
||||
/
|
||||
|
||||
DECLARE
|
||||
content BLOB;
|
||||
v_handle int;
|
||||
src raw;
|
||||
BEGIN
|
||||
content := '123';
|
||||
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
|
||||
src := '123';
|
||||
GMS_COMPRESS.LZ_COMPRESS_ADD(v_handle+1,content,src);
|
||||
GMS_COMPRESS.LZ_COMPRESS_CLOSE(v_handle,content);
|
||||
RAISE NOTICE 'content=%', content;
|
||||
END;
|
||||
/
|
||||
DECLARE
|
||||
content BLOB;
|
||||
BEGIN
|
||||
GMS_COMPRESS.LZ_COMPRESS_CLOSE(1,content);
|
||||
RAISE NOTICE 'content=%', content;
|
||||
END;
|
||||
/
|
||||
|
||||
-- test gms_compress.lz_uncompress_open and ms_compress.lz_uncompress_close
|
||||
DECLARE
|
||||
content BLOB;
|
||||
v_handle int;
|
||||
BEGIN
|
||||
content := '123';
|
||||
content := GMS_COMPRESS.LZ_COMPRESS(content);
|
||||
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
|
||||
RAISE NOTICE 'v_handle=%', v_handle;
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(v_handle);
|
||||
RAISE NOTICE 'content=%', content;
|
||||
END;
|
||||
/
|
||||
|
||||
DECLARE
|
||||
content BLOB;
|
||||
v_handle int;
|
||||
BEGIN
|
||||
content := '123';
|
||||
content := GMS_COMPRESS.LZ_COMPRESS(content);
|
||||
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
|
||||
RAISE NOTICE 'v_handle=%', v_handle;
|
||||
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
|
||||
RAISE NOTICE 'v_handle=%', v_handle;
|
||||
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
|
||||
RAISE NOTICE 'v_handle=%', v_handle;
|
||||
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
|
||||
RAISE NOTICE 'v_handle=%', v_handle;
|
||||
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
|
||||
RAISE NOTICE 'v_handle=%', v_handle;
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(1);
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(2);
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(3);
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(4);
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(5);
|
||||
END;
|
||||
/
|
||||
|
||||
-- abnormal scenario
|
||||
DECLARE
|
||||
content BLOB;
|
||||
v_handle int;
|
||||
BEGIN
|
||||
content := '';
|
||||
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(v_handle);
|
||||
END;
|
||||
/
|
||||
|
||||
DECLARE
|
||||
content BLOB;
|
||||
v_handle int;
|
||||
BEGIN
|
||||
content := '123';
|
||||
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(v_handle);
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(v_handle);
|
||||
END;
|
||||
/
|
||||
|
||||
DECLARE
|
||||
content BLOB;
|
||||
v_handle int;
|
||||
BEGIN
|
||||
content := '123';
|
||||
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(v_handle);
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(0);
|
||||
END;
|
||||
/
|
||||
|
||||
DECLARE
|
||||
content BLOB;
|
||||
v_handle int;
|
||||
BEGIN
|
||||
content := '123';
|
||||
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(v_handle);
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(2);
|
||||
END;
|
||||
/
|
||||
|
||||
DECLARE
|
||||
content BLOB;
|
||||
v_handle int;
|
||||
BEGIN
|
||||
content := '123';
|
||||
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(v_handle);
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(2);
|
||||
END;
|
||||
/
|
||||
DECLARE
|
||||
content BLOB;
|
||||
BEGIN
|
||||
GMS_COMPRESS.LZ_COMPRESS_CLOSE(1, content);
|
||||
END;
|
||||
/
|
||||
|
||||
DECLARE
|
||||
content BLOB;
|
||||
v_handle int;
|
||||
BEGIN
|
||||
content := '123';
|
||||
content := GMS_COMPRESS.LZ_COMPRESS(content);
|
||||
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
|
||||
RAISE NOTICE 'v_handle=%', v_handle;
|
||||
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
|
||||
RAISE NOTICE 'v_handle=%', v_handle;
|
||||
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
|
||||
RAISE NOTICE 'v_handle=%', v_handle;
|
||||
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
|
||||
RAISE NOTICE 'v_handle=%', v_handle;
|
||||
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
|
||||
RAISE NOTICE 'v_handle=%', v_handle;
|
||||
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
|
||||
RAISE NOTICE 'v_handle=%', v_handle;
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(1);
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(2);
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(3);
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(4);
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(5);
|
||||
END;
|
||||
/
|
||||
DECLARE
|
||||
content BLOB;
|
||||
v_handle int;
|
||||
BEGIN
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(1);
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(2);
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(3);
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(4);
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(5);
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(6);
|
||||
END;
|
||||
/
|
||||
|
||||
-- test gms_compress.lz_uncompress_extract
|
||||
DECLARE
|
||||
content BLOB;
|
||||
v_handle int;
|
||||
v_raw raw;
|
||||
BEGIN
|
||||
content := '123';
|
||||
content := GMS_COMPRESS.LZ_COMPRESS(content);
|
||||
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_EXTRACT(v_handle, v_raw);
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(v_handle);
|
||||
RAISE NOTICE 'content=%', content;
|
||||
RAISE NOTICE 'v_raw=%', v_raw;
|
||||
END;
|
||||
/
|
||||
|
||||
-- abnormal scenario
|
||||
DECLARE
|
||||
content BLOB;
|
||||
v_handle int;
|
||||
v_raw raw;
|
||||
BEGIN
|
||||
content := '123';
|
||||
content := GMS_COMPRESS.LZ_COMPRESS(content);
|
||||
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_EXTRACT(0, v_raw);
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(v_handle);
|
||||
RAISE NOTICE 'content=%', content;
|
||||
RAISE NOTICE 'v_raw=%', v_raw;
|
||||
END;
|
||||
/
|
||||
DECLARE
|
||||
content BLOB;
|
||||
BEGIN
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(1);
|
||||
END;
|
||||
/
|
||||
|
||||
DECLARE
|
||||
content BLOB;
|
||||
v_handle int;
|
||||
v_raw raw;
|
||||
BEGIN
|
||||
content := '123';
|
||||
content := GMS_COMPRESS.LZ_COMPRESS(content);
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_EXTRACT(1, v_raw);
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(v_handle);
|
||||
RAISE NOTICE 'content=%', content;
|
||||
RAISE NOTICE 'v_raw=%', v_raw;
|
||||
END;
|
||||
/
|
||||
|
||||
DECLARE
|
||||
content BLOB;
|
||||
v_handle int;
|
||||
v_raw raw;
|
||||
BEGIN
|
||||
content := '123';
|
||||
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_EXTRACT(v_handle, v_raw);
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(v_handle);
|
||||
RAISE NOTICE 'content=%', content;
|
||||
RAISE NOTICE 'v_raw=%', v_raw;
|
||||
END;
|
||||
/
|
||||
DECLARE
|
||||
content BLOB;
|
||||
BEGIN
|
||||
GMS_COMPRESS.LZ_COMPRESS_CLOSE(1);
|
||||
END;
|
||||
/
|
||||
|
||||
DECLARE
|
||||
content BLOB;
|
||||
v_handle int;
|
||||
v_raw raw;
|
||||
BEGIN
|
||||
content := '123';
|
||||
content := GMS_COMPRESS.LZ_COMPRESS(content);
|
||||
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_EXTRACT(v_handle, v_raw);
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_EXTRACT(v_handle, v_raw);
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(v_handle);
|
||||
RAISE NOTICE 'content=%', content;
|
||||
RAISE NOTICE 'v_raw=%', v_raw;
|
||||
END;
|
||||
/
|
||||
DECLARE
|
||||
content BLOB;
|
||||
BEGIN
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(1);
|
||||
END;
|
||||
/
|
||||
|
||||
DECLARE
|
||||
content BLOB;
|
||||
v_handle int;
|
||||
v_raw raw;
|
||||
BEGIN
|
||||
content := '123';
|
||||
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_EXTRACT(v_handle, v_raw);
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(v_handle);
|
||||
RAISE NOTICE 'content=%', content;
|
||||
RAISE NOTICE 'v_raw=%', v_raw;
|
||||
END;
|
||||
/
|
||||
DECLARE
|
||||
content BLOB;
|
||||
BEGIN
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(1);
|
||||
END;
|
||||
/
|
||||
|
||||
-- test gms_compress.lz_isopen
|
||||
DECLARE
|
||||
content BLOB;
|
||||
v_handle int;
|
||||
v_bool boolean;
|
||||
BEGIN
|
||||
content := '123';
|
||||
v_bool := false;
|
||||
v_handle := GMS_COMPRESS.LZ_COMPRESS_OPEN(content);
|
||||
v_bool := GMS_COMPRESS.ISOPEN(v_handle);
|
||||
RAISE NOTICE 'v_bool=%', v_bool;
|
||||
GMS_COMPRESS.LZ_COMPRESS_CLOSE(v_handle,content);
|
||||
v_bool := GMS_COMPRESS.ISOPEN(v_handle);
|
||||
RAISE NOTICE 'v_bool=%', v_bool;
|
||||
END;
|
||||
/
|
||||
|
||||
DECLARE
|
||||
content BLOB;
|
||||
v_handle int;
|
||||
v_bool boolean;
|
||||
BEGIN
|
||||
content := '123';
|
||||
v_bool := false;
|
||||
content := GMS_COMPRESS.LZ_COMPRESS(content);
|
||||
v_handle := GMS_COMPRESS.LZ_UNCOMPRESS_OPEN(content);
|
||||
v_bool := GMS_COMPRESS.ISOPEN(v_handle);
|
||||
RAISE NOTICE 'v_bool=%', v_bool;
|
||||
GMS_COMPRESS.LZ_UNCOMPRESS_CLOSE(v_handle);
|
||||
v_bool := GMS_COMPRESS.ISOPEN(v_handle);
|
||||
RAISE NOTICE 'v_bool=%', v_bool;
|
||||
END;
|
||||
/
|
||||
|
||||
-- abnormal scenario
|
||||
DECLARE
|
||||
v_bool boolean;
|
||||
BEGIN
|
||||
v_bool := true;
|
||||
v_bool := GMS_COMPRESS.ISOPEN(0);
|
||||
RAISE NOTICE 'v_bool=%', v_bool;
|
||||
END;
|
||||
/
|
||||
|
||||
DECLARE
|
||||
v_bool boolean;
|
||||
BEGIN
|
||||
v_bool := true;
|
||||
v_bool := GMS_COMPRESS.ISOPEN(1);
|
||||
RAISE NOTICE 'v_bool=%', v_bool;
|
||||
END;
|
||||
/
|
||||
|
||||
|
||||
reset search_path;
|
||||
drop schema gms_compress_test cascade;
|
||||
21
contrib/gms_debug/CMakeLists.txt
Normal file
21
contrib/gms_debug/CMakeLists.txt
Normal file
@ -0,0 +1,21 @@
|
||||
#This is the main CMAKE for build all gms_debug.
|
||||
# gms_debug
|
||||
AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} TGT_gms_debug_SRC)
|
||||
set(TGT_gms_debug_INC
|
||||
${PROJECT_OPENGS_DIR}/contrib/gms_debug
|
||||
${PROJECT_OPENGS_DIR}/contrib
|
||||
)
|
||||
|
||||
set(gms_debug_DEF_OPTIONS ${MACRO_OPTIONS})
|
||||
set(gms_debug_COMPILE_OPTIONS ${OPTIMIZE_OPTIONS} ${OS_OPTIONS} ${PROTECT_OPTIONS} ${WARNING_OPTIONS} ${LIB_SECURE_OPTIONS} ${CHECK_OPTIONS})
|
||||
set(gms_debug_LINK_OPTIONS ${LIB_LINK_OPTIONS})
|
||||
add_shared_libtarget(gms_debug TGT_gms_debug_SRC TGT_gms_debug_INC "${gms_debug_DEF_OPTIONS}" "${gms_debug_COMPILE_OPTIONS}" "${gms_debug_LINK_OPTIONS}")
|
||||
set_target_properties(gms_debug PROPERTIES PREFIX "")
|
||||
|
||||
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/gms_debug.control
|
||||
DESTINATION share/postgresql/extension/
|
||||
)
|
||||
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/gms_debug--1.0.sql
|
||||
DESTINATION share/postgresql/extension/
|
||||
)
|
||||
install(TARGETS gms_debug DESTINATION lib/postgresql)
|
||||
29
contrib/gms_debug/Makefile
Normal file
29
contrib/gms_debug/Makefile
Normal file
@ -0,0 +1,29 @@
|
||||
# contrib/gms_debug/Makefile
|
||||
MODULE_big = gms_debug
|
||||
OBJS = gms_debug.o
|
||||
|
||||
EXTENSION = gms_debug
|
||||
DATA = gms_debug--1.0.sql
|
||||
|
||||
exclude_option = -fPIE
|
||||
override CPPFLAGS := -fstack-protector-strong $(filter-out $(exclude_option),$(CPPFLAGS))
|
||||
|
||||
REGRESS = gms_debug
|
||||
|
||||
ifdef USE_PGXS
|
||||
PG_CONFIG = pg_config
|
||||
PGXS := $(shell $(PG_CONFIG) --pgxs)
|
||||
include $(PGXS)
|
||||
else
|
||||
subdir = contrib/gms_debug
|
||||
top_builddir = ../..
|
||||
include $(top_builddir)/src/Makefile.global
|
||||
regress_home = $(top_builddir)/src/test/regress
|
||||
REGRESS_OPTS = -c 0 -d 1 -r 1 -p 25632 --single_node -w --keep_last_data=false \
|
||||
--regconf=$(regress_home)/regress.conf \
|
||||
--temp-config=$(regress_home)/make_fastcheck_postgresql.conf
|
||||
include $(top_srcdir)/contrib/contrib-global.mk
|
||||
endif
|
||||
|
||||
gms_debug.o: gms_debug.cpp
|
||||
|
||||
1
contrib/gms_debug/data/dummy.txt
Normal file
1
contrib/gms_debug/data/dummy.txt
Normal file
@ -0,0 +1 @@
|
||||
The openGauss regression needs this file to run.
|
||||
269
contrib/gms_debug/expected/gms_debugger_client1.out
Normal file
269
contrib/gms_debug/expected/gms_debugger_client1.out
Normal file
@ -0,0 +1,269 @@
|
||||
-- wait for server establishment
|
||||
CREATE OR REPLACE FUNCTION wait_for_gms_debug_extension()
|
||||
RETURNS BOOLEAN AS $$
|
||||
DECLARE
|
||||
extension_exists BOOLEAN;
|
||||
BEGIN
|
||||
-- 初始化变量
|
||||
extension_exists := FALSE;
|
||||
|
||||
-- 循环查询扩展是否存在
|
||||
WHILE NOT extension_exists LOOP
|
||||
-- 查询扩展是否存在
|
||||
PERFORM 1 FROM pg_extension WHERE extname = 'gms_debug';
|
||||
IF FOUND THEN
|
||||
-- 如果扩展存在,则退出循环
|
||||
extension_exists := TRUE;
|
||||
ELSE
|
||||
-- 如果扩展不存在,则等待一段时间再重试
|
||||
PERFORM pg_sleep(1); -- 等待1秒
|
||||
END IF;
|
||||
END LOOP;
|
||||
|
||||
-- 返回扩展存在的标志
|
||||
RETURN extension_exists;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
DO $$
|
||||
BEGIN
|
||||
IF wait_for_gms_debug_extension() THEN
|
||||
-- 扩展存在,执行下一步操作
|
||||
END IF;
|
||||
END $$;
|
||||
set search_path = gms_debugger_test1;
|
||||
CREATE or REPLACE FUNCTION gms_breakpoint(funcname text, lineno int)
|
||||
returns void as $$
|
||||
declare
|
||||
pro_info gms_debug.program_info;
|
||||
bkline binary_integer;
|
||||
ret binary_integer;
|
||||
begin
|
||||
pro_info.name := funcname;
|
||||
ret := gms_debug.set_breakpoint(pro_info, lineno, bkline,1,1);
|
||||
RAISE NOTICE 'ret= %', ret;
|
||||
RAISE NOTICE 'ret= %', bkline;
|
||||
end;
|
||||
$$ LANGUAGE plpgsql;
|
||||
CREATE or REPLACE FUNCTION gms_continue()
|
||||
returns void as $$
|
||||
declare
|
||||
run_info gms_debug.runtime_info;
|
||||
ret binary_integer;
|
||||
begin
|
||||
ret := gms_debug.continue(run_info, 0, 2);
|
||||
RAISE NOTICE 'breakpoint= %', run_info.breakpoint;
|
||||
RAISE NOTICE 'stackdepth= %', run_info.stackdepth;
|
||||
RAISE NOTICE 'line= %', run_info.line#;
|
||||
RAISE NOTICE 'reason= %', run_info.reason;
|
||||
RAISE NOTICE 'ret= %',ret;
|
||||
end;
|
||||
$$ LANGUAGE plpgsql;
|
||||
CREATE or REPLACE FUNCTION gms_next()
|
||||
returns void as $$
|
||||
declare
|
||||
run_info gms_debug.runtime_info;
|
||||
ret binary_integer;
|
||||
begin
|
||||
ret := gms_debug.continue(run_info, 2, 2);
|
||||
RAISE NOTICE 'breakpoint= %', run_info.breakpoint;
|
||||
RAISE NOTICE 'stackdepth= %', run_info.stackdepth;
|
||||
RAISE NOTICE 'line= %', run_info.line#;
|
||||
RAISE NOTICE 'reason= %', run_info.reason;
|
||||
RAISE NOTICE 'ret= %',ret;
|
||||
end;
|
||||
$$ LANGUAGE plpgsql;
|
||||
CREATE or REPLACE FUNCTION gms_step()
|
||||
returns void as $$
|
||||
declare
|
||||
run_info gms_debug.runtime_info;
|
||||
ret binary_integer;
|
||||
begin
|
||||
ret := gms_debug.continue(run_info, 4, 2);
|
||||
RAISE NOTICE 'breakpoint= %', run_info.breakpoint;
|
||||
RAISE NOTICE 'stackdepth= %', run_info.stackdepth;
|
||||
RAISE NOTICE 'line= %', run_info.line#;
|
||||
RAISE NOTICE 'reason= %', run_info.reason;
|
||||
RAISE NOTICE 'ret= %',ret;
|
||||
end;
|
||||
$$ LANGUAGE plpgsql;
|
||||
CREATE or REPLACE FUNCTION gms_info()
|
||||
returns void as $$
|
||||
declare
|
||||
run_info gms_debug.runtime_info;
|
||||
ret binary_integer;
|
||||
begin
|
||||
ret := gms_debug.get_runtime_info(1, run_info);
|
||||
RAISE NOTICE 'breakpoint= %', run_info.breakpoint;
|
||||
RAISE NOTICE 'stackdepth= %', run_info.stackdepth;
|
||||
RAISE NOTICE 'line= %', run_info.line#;
|
||||
RAISE NOTICE 'reason= %', run_info.reason;
|
||||
RAISE NOTICE 'ret= %',ret;
|
||||
end;
|
||||
$$ LANGUAGE plpgsql;
|
||||
-- attach debug server
|
||||
select * from gms_debug.attach_session('datanode1-0');
|
||||
attach_session
|
||||
----------------
|
||||
|
||||
(1 row)
|
||||
|
||||
select pg_sleep(3);
|
||||
pg_sleep
|
||||
----------
|
||||
|
||||
(1 row)
|
||||
|
||||
select gms_breakpoint('test_debug', 0); -- negative
|
||||
NOTICE: ret= 0
|
||||
CONTEXT: referenced column: gms_breakpoint
|
||||
NOTICE: ret= 0
|
||||
CONTEXT: referenced column: gms_breakpoint
|
||||
gms_breakpoint
|
||||
----------------
|
||||
|
||||
(1 row)
|
||||
|
||||
select gms_breakpoint('test_debug', 15); -- ok
|
||||
NOTICE: ret= 1
|
||||
CONTEXT: referenced column: gms_breakpoint
|
||||
NOTICE: ret= 0
|
||||
CONTEXT: referenced column: gms_breakpoint
|
||||
gms_breakpoint
|
||||
----------------
|
||||
|
||||
(1 row)
|
||||
|
||||
select gms_breakpoint('test_debug', 17); -- invalid
|
||||
NOTICE: ret= 2
|
||||
CONTEXT: referenced column: gms_breakpoint
|
||||
NOTICE: ret= 0
|
||||
CONTEXT: referenced column: gms_breakpoint
|
||||
gms_breakpoint
|
||||
----------------
|
||||
|
||||
(1 row)
|
||||
|
||||
select gms_breakpoint('test_debug', 22); -- ok
|
||||
NOTICE: ret= 3
|
||||
CONTEXT: referenced column: gms_breakpoint
|
||||
NOTICE: ret= 0
|
||||
CONTEXT: referenced column: gms_breakpoint
|
||||
gms_breakpoint
|
||||
----------------
|
||||
|
||||
(1 row)
|
||||
|
||||
select gms_breakpoint('test_debug', 15); -- ok
|
||||
WARNING: the given line number already contains a valid breakpoint.
|
||||
CONTEXT: SQL statement "CALL gms_debug.add_breakpoint(proid,line#,breakpoint#,fuzzy,iterations,sts)"
|
||||
PL/pgSQL function gms_debug.set_breakpoint(gms_debug.program_info,integer,integer,integer) line 8 at SQL statement
|
||||
SQL statement "CALL gms_debug.set_breakpoint(pro_info,lineno,bkline,1,1)"
|
||||
PL/pgSQL function gms_breakpoint(text,integer) line 8 at assignment
|
||||
referenced column: gms_breakpoint
|
||||
NOTICE: ret= -1
|
||||
CONTEXT: referenced column: gms_breakpoint
|
||||
NOTICE: ret= -3
|
||||
CONTEXT: referenced column: gms_breakpoint
|
||||
gms_breakpoint
|
||||
----------------
|
||||
|
||||
(1 row)
|
||||
|
||||
select gms_next();
|
||||
NOTICE: breakpoint= -1
|
||||
CONTEXT: referenced column: gms_next
|
||||
NOTICE: stackdepth= 0
|
||||
CONTEXT: referenced column: gms_next
|
||||
NOTICE: line= 16
|
||||
CONTEXT: referenced column: gms_next
|
||||
NOTICE: reason= 6
|
||||
CONTEXT: referenced column: gms_next
|
||||
NOTICE: ret= 0
|
||||
CONTEXT: referenced column: gms_next
|
||||
gms_next
|
||||
----------
|
||||
|
||||
(1 row)
|
||||
|
||||
select gms_next();
|
||||
NOTICE: breakpoint= -1
|
||||
CONTEXT: referenced column: gms_next
|
||||
NOTICE: stackdepth= 0
|
||||
CONTEXT: referenced column: gms_next
|
||||
NOTICE: line= 19
|
||||
CONTEXT: referenced column: gms_next
|
||||
NOTICE: reason= 6
|
||||
CONTEXT: referenced column: gms_next
|
||||
NOTICE: ret= 0
|
||||
CONTEXT: referenced column: gms_next
|
||||
gms_next
|
||||
----------
|
||||
|
||||
(1 row)
|
||||
|
||||
select gms_next();
|
||||
NOTICE: breakpoint= -1
|
||||
CONTEXT: referenced column: gms_next
|
||||
NOTICE: stackdepth= 0
|
||||
CONTEXT: referenced column: gms_next
|
||||
NOTICE: line= 19
|
||||
CONTEXT: referenced column: gms_next
|
||||
NOTICE: reason= 6
|
||||
CONTEXT: referenced column: gms_next
|
||||
NOTICE: ret= 0
|
||||
CONTEXT: referenced column: gms_next
|
||||
gms_next
|
||||
----------
|
||||
|
||||
(1 row)
|
||||
|
||||
select gms_next();
|
||||
NOTICE: breakpoint= 3
|
||||
CONTEXT: referenced column: gms_next
|
||||
NOTICE: stackdepth= 0
|
||||
CONTEXT: referenced column: gms_next
|
||||
NOTICE: line= 22
|
||||
CONTEXT: referenced column: gms_next
|
||||
NOTICE: reason= 2
|
||||
CONTEXT: referenced column: gms_next
|
||||
NOTICE: ret= 0
|
||||
CONTEXT: referenced column: gms_next
|
||||
gms_next
|
||||
----------
|
||||
|
||||
(1 row)
|
||||
|
||||
select gms_continue();
|
||||
NOTICE: breakpoint= -1
|
||||
CONTEXT: referenced column: gms_continue
|
||||
NOTICE: stackdepth= 0
|
||||
CONTEXT: referenced column: gms_continue
|
||||
NOTICE: line= 46
|
||||
CONTEXT: referenced column: gms_continue
|
||||
NOTICE: reason= 0
|
||||
CONTEXT: referenced column: gms_continue
|
||||
NOTICE: ret= 0
|
||||
CONTEXT: referenced column: gms_continue
|
||||
gms_continue
|
||||
--------------
|
||||
|
||||
(1 row)
|
||||
|
||||
select gms_continue();
|
||||
NOTICE: breakpoint= -1
|
||||
CONTEXT: referenced column: gms_continue
|
||||
NOTICE: stackdepth= 0
|
||||
CONTEXT: referenced column: gms_continue
|
||||
NOTICE: line= 46
|
||||
CONTEXT: referenced column: gms_continue
|
||||
NOTICE: reason= 0
|
||||
CONTEXT: referenced column: gms_continue
|
||||
NOTICE: ret= 0
|
||||
CONTEXT: referenced column: gms_continue
|
||||
gms_continue
|
||||
--------------
|
||||
|
||||
(1 row)
|
||||
|
||||
select gms_debug.detach_session();
|
||||
connection to server was lost
|
||||
144
contrib/gms_debug/expected/gms_debugger_client2.out
Normal file
144
contrib/gms_debug/expected/gms_debugger_client2.out
Normal file
@ -0,0 +1,144 @@
|
||||
-- wait for server establishment
|
||||
CREATE OR REPLACE FUNCTION wait_for_gms_debug_extension()
|
||||
RETURNS BOOLEAN AS $$
|
||||
DECLARE
|
||||
extension_exists BOOLEAN;
|
||||
BEGIN
|
||||
-- 初始化变量
|
||||
extension_exists := FALSE;
|
||||
|
||||
-- 循环查询扩展是否存在
|
||||
WHILE NOT extension_exists LOOP
|
||||
-- 查询扩展是否存在
|
||||
PERFORM 1 FROM pg_extension WHERE extname = 'gms_debug';
|
||||
IF FOUND THEN
|
||||
-- 如果扩展存在,则退出循环
|
||||
extension_exists := TRUE;
|
||||
ELSE
|
||||
-- 如果扩展不存在,则等待一段时间再重试
|
||||
PERFORM pg_sleep(1); -- 等待1秒
|
||||
END IF;
|
||||
END LOOP;
|
||||
|
||||
-- 返回扩展存在的标志
|
||||
RETURN extension_exists;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
DO $$
|
||||
BEGIN
|
||||
IF wait_for_gms_debug_extension() THEN
|
||||
-- 扩展存在,执行下一步操作
|
||||
END IF;
|
||||
END $$;
|
||||
set search_path = gms_debugger_test2;
|
||||
CREATE or REPLACE FUNCTION gms_continue()
|
||||
returns void as $$
|
||||
declare
|
||||
run_info gms_debug.runtime_info;
|
||||
ret binary_integer;
|
||||
begin
|
||||
ret := gms_debug.continue(run_info, 0, 2);
|
||||
RAISE NOTICE 'breakpoint= %', run_info.breakpoint;
|
||||
RAISE NOTICE 'stackdepth= %', run_info.stackdepth;
|
||||
RAISE NOTICE 'line= %', run_info.line#;
|
||||
RAISE NOTICE 'reason= %', run_info.reason;
|
||||
RAISE NOTICE 'ret= %',ret;
|
||||
end;
|
||||
$$ LANGUAGE plpgsql;
|
||||
CREATE or REPLACE FUNCTION gms_next()
|
||||
returns void as $$
|
||||
declare
|
||||
run_info gms_debug.runtime_info;
|
||||
ret binary_integer;
|
||||
begin
|
||||
ret := gms_debug.continue(run_info, 2, 2);
|
||||
RAISE NOTICE 'breakpoint= %', run_info.breakpoint;
|
||||
RAISE NOTICE 'stackdepth= %', run_info.stackdepth;
|
||||
RAISE NOTICE 'line= %', run_info.line#;
|
||||
RAISE NOTICE 'reason= %', run_info.reason;
|
||||
RAISE NOTICE 'ret= %',ret;
|
||||
end;
|
||||
$$ LANGUAGE plpgsql;
|
||||
-- attach debug server
|
||||
select * from gms_debug.attach_session('datanode1-0');
|
||||
attach_session
|
||||
----------------
|
||||
|
||||
(1 row)
|
||||
|
||||
select pg_sleep(3);
|
||||
pg_sleep
|
||||
----------
|
||||
|
||||
(1 row)
|
||||
|
||||
select gms_next();
|
||||
NOTICE: breakpoint= -1
|
||||
CONTEXT: referenced column: gms_next
|
||||
NOTICE: stackdepth= 0
|
||||
CONTEXT: referenced column: gms_next
|
||||
NOTICE: line= 3
|
||||
CONTEXT: referenced column: gms_next
|
||||
NOTICE: reason= 6
|
||||
CONTEXT: referenced column: gms_next
|
||||
NOTICE: ret= 0
|
||||
CONTEXT: referenced column: gms_next
|
||||
gms_next
|
||||
----------
|
||||
|
||||
(1 row)
|
||||
|
||||
select gms_next();
|
||||
NOTICE: breakpoint= -1
|
||||
CONTEXT: referenced column: gms_next
|
||||
NOTICE: stackdepth= 0
|
||||
CONTEXT: referenced column: gms_next
|
||||
NOTICE: line= 4
|
||||
CONTEXT: referenced column: gms_next
|
||||
NOTICE: reason= 6
|
||||
CONTEXT: referenced column: gms_next
|
||||
NOTICE: ret= 0
|
||||
CONTEXT: referenced column: gms_next
|
||||
gms_next
|
||||
----------
|
||||
|
||||
(1 row)
|
||||
|
||||
select gms_next();
|
||||
NOTICE: breakpoint= -1
|
||||
CONTEXT: referenced column: gms_next
|
||||
NOTICE: stackdepth= 0
|
||||
CONTEXT: referenced column: gms_next
|
||||
NOTICE: line= 5
|
||||
CONTEXT: referenced column: gms_next
|
||||
NOTICE: reason= 6
|
||||
CONTEXT: referenced column: gms_next
|
||||
NOTICE: ret= 0
|
||||
CONTEXT: referenced column: gms_next
|
||||
gms_next
|
||||
----------
|
||||
|
||||
(1 row)
|
||||
|
||||
select gms_continue();
|
||||
NOTICE: breakpoint= -1
|
||||
CONTEXT: referenced column: gms_continue
|
||||
NOTICE: stackdepth= 0
|
||||
CONTEXT: referenced column: gms_continue
|
||||
NOTICE: line= 0
|
||||
CONTEXT: referenced column: gms_continue
|
||||
NOTICE: reason= 0
|
||||
CONTEXT: referenced column: gms_continue
|
||||
NOTICE: ret= 0
|
||||
CONTEXT: referenced column: gms_continue
|
||||
gms_continue
|
||||
--------------
|
||||
|
||||
(1 row)
|
||||
|
||||
select gms_debug.detach_session();
|
||||
detach_session
|
||||
----------------
|
||||
|
||||
(1 row)
|
||||
|
||||
144
contrib/gms_debug/expected/gms_debugger_client3.out
Normal file
144
contrib/gms_debug/expected/gms_debugger_client3.out
Normal file
@ -0,0 +1,144 @@
|
||||
-- wait for server establishment
|
||||
CREATE OR REPLACE FUNCTION wait_for_gms_debug_extension()
|
||||
RETURNS BOOLEAN AS $$
|
||||
DECLARE
|
||||
extension_exists BOOLEAN;
|
||||
BEGIN
|
||||
-- 初始化变量
|
||||
extension_exists := FALSE;
|
||||
|
||||
-- 循环查询扩展是否存在
|
||||
WHILE NOT extension_exists LOOP
|
||||
-- 查询扩展是否存在
|
||||
PERFORM 1 FROM pg_extension WHERE extname = 'gms_debug';
|
||||
IF FOUND THEN
|
||||
-- 如果扩展存在,则退出循环
|
||||
extension_exists := TRUE;
|
||||
ELSE
|
||||
-- 如果扩展不存在,则等待一段时间再重试
|
||||
PERFORM pg_sleep(1); -- 等待1秒
|
||||
END IF;
|
||||
END LOOP;
|
||||
|
||||
-- 返回扩展存在的标志
|
||||
RETURN extension_exists;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
DO $$
|
||||
BEGIN
|
||||
IF wait_for_gms_debug_extension() THEN
|
||||
-- 扩展存在,执行下一步操作
|
||||
END IF;
|
||||
END $$;
|
||||
set search_path = gms_debugger_test3;
|
||||
CREATE or REPLACE FUNCTION gms_next()
|
||||
returns void as $$
|
||||
declare
|
||||
run_info gms_debug.runtime_info;
|
||||
ret binary_integer;
|
||||
begin
|
||||
ret := gms_debug.continue(run_info, 2, 2);
|
||||
RAISE NOTICE 'breakpoint= %', run_info.breakpoint;
|
||||
RAISE NOTICE 'stackdepth= %', run_info.stackdepth;
|
||||
RAISE NOTICE 'line= %', run_info.line#;
|
||||
RAISE NOTICE 'reason= %', run_info.reason;
|
||||
RAISE NOTICE 'ret= %',ret;
|
||||
end;
|
||||
$$ LANGUAGE plpgsql;
|
||||
CREATE or REPLACE FUNCTION gms_continue()
|
||||
returns void as $$
|
||||
declare
|
||||
run_info gms_debug.runtime_info;
|
||||
ret binary_integer;
|
||||
begin
|
||||
ret := gms_debug.continue(run_info, 0, 2);
|
||||
RAISE NOTICE 'breakpoint= %', run_info.breakpoint;
|
||||
RAISE NOTICE 'stackdepth= %', run_info.stackdepth;
|
||||
RAISE NOTICE 'line= %', run_info.line#;
|
||||
RAISE NOTICE 'reason= %', run_info.reason;
|
||||
RAISE NOTICE 'ret= %',ret;
|
||||
end;
|
||||
$$ LANGUAGE plpgsql;
|
||||
-- attach debug server
|
||||
select * from gms_debug.attach_session('datanode1-0');
|
||||
attach_session
|
||||
----------------
|
||||
|
||||
(1 row)
|
||||
|
||||
select pg_sleep(3);
|
||||
pg_sleep
|
||||
----------
|
||||
|
||||
(1 row)
|
||||
|
||||
select gms_next();
|
||||
NOTICE: breakpoint= -1
|
||||
CONTEXT: referenced column: gms_next
|
||||
NOTICE: stackdepth= 0
|
||||
CONTEXT: referenced column: gms_next
|
||||
NOTICE: line= 6
|
||||
CONTEXT: referenced column: gms_next
|
||||
NOTICE: reason= 6
|
||||
CONTEXT: referenced column: gms_next
|
||||
NOTICE: ret= 0
|
||||
CONTEXT: referenced column: gms_next
|
||||
gms_next
|
||||
----------
|
||||
|
||||
(1 row)
|
||||
|
||||
select gms_next();
|
||||
NOTICE: breakpoint= -1
|
||||
CONTEXT: referenced column: gms_next
|
||||
NOTICE: stackdepth= 0
|
||||
CONTEXT: referenced column: gms_next
|
||||
NOTICE: line= 10
|
||||
CONTEXT: referenced column: gms_next
|
||||
NOTICE: reason= 6
|
||||
CONTEXT: referenced column: gms_next
|
||||
NOTICE: ret= 0
|
||||
CONTEXT: referenced column: gms_next
|
||||
gms_next
|
||||
----------
|
||||
|
||||
(1 row)
|
||||
|
||||
select gms_continue();
|
||||
NOTICE: breakpoint= -1
|
||||
CONTEXT: referenced column: gms_continue
|
||||
NOTICE: stackdepth= 0
|
||||
CONTEXT: referenced column: gms_continue
|
||||
NOTICE: line= 14
|
||||
CONTEXT: referenced column: gms_continue
|
||||
NOTICE: reason= 0
|
||||
CONTEXT: referenced column: gms_continue
|
||||
NOTICE: ret= 0
|
||||
CONTEXT: referenced column: gms_continue
|
||||
gms_continue
|
||||
--------------
|
||||
|
||||
(1 row)
|
||||
|
||||
select gms_next();
|
||||
NOTICE: breakpoint= -1
|
||||
CONTEXT: referenced column: gms_next
|
||||
NOTICE: stackdepth= 0
|
||||
CONTEXT: referenced column: gms_next
|
||||
NOTICE: line= 6
|
||||
CONTEXT: referenced column: gms_next
|
||||
NOTICE: reason= 6
|
||||
CONTEXT: referenced column: gms_next
|
||||
NOTICE: ret= 0
|
||||
CONTEXT: referenced column: gms_next
|
||||
gms_next
|
||||
----------
|
||||
|
||||
(1 row)
|
||||
|
||||
select gms_debug.detach_session();
|
||||
detach_session
|
||||
----------------
|
||||
|
||||
(1 row)
|
||||
|
||||
192
contrib/gms_debug/expected/gms_debugger_client4.out
Normal file
192
contrib/gms_debug/expected/gms_debugger_client4.out
Normal file
@ -0,0 +1,192 @@
|
||||
-- wait for server establishment
|
||||
CREATE OR REPLACE FUNCTION wait_for_gms_debug_extension()
|
||||
RETURNS BOOLEAN AS $$
|
||||
DECLARE
|
||||
extension_exists BOOLEAN;
|
||||
BEGIN
|
||||
-- 初始化变量
|
||||
extension_exists := FALSE;
|
||||
|
||||
-- 循环查询扩展是否存在
|
||||
WHILE NOT extension_exists LOOP
|
||||
-- 查询扩展是否存在
|
||||
PERFORM 1 FROM pg_extension WHERE extname = 'gms_debug';
|
||||
IF FOUND THEN
|
||||
-- 如果扩展存在,则退出循环
|
||||
extension_exists := TRUE;
|
||||
ELSE
|
||||
-- 如果扩展不存在,则等待一段时间再重试
|
||||
PERFORM pg_sleep(1); -- 等待1秒
|
||||
END IF;
|
||||
END LOOP;
|
||||
|
||||
-- 返回扩展存在的标志
|
||||
RETURN extension_exists;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
DO $$
|
||||
BEGIN
|
||||
IF wait_for_gms_debug_extension() THEN
|
||||
-- 扩展存在,执行下一步操作
|
||||
END IF;
|
||||
END $$;
|
||||
set search_path = gms_debugger_test4;
|
||||
CREATE or REPLACE FUNCTION gms_step()
|
||||
returns void as $$
|
||||
declare
|
||||
run_info gms_debug.runtime_info;
|
||||
ret binary_integer;
|
||||
begin
|
||||
ret := gms_debug.continue(run_info, 4, 2);
|
||||
RAISE NOTICE 'breakpoint= %', run_info.breakpoint;
|
||||
RAISE NOTICE 'stackdepth= %', run_info.stackdepth;
|
||||
RAISE NOTICE 'line= %', run_info.line#;
|
||||
RAISE NOTICE 'reason= %', run_info.reason;
|
||||
RAISE NOTICE 'ret= %',ret;
|
||||
end;
|
||||
$$ LANGUAGE plpgsql;
|
||||
CREATE or REPLACE FUNCTION gms_continue()
|
||||
returns void as $$
|
||||
declare
|
||||
run_info gms_debug.runtime_info;
|
||||
ret binary_integer;
|
||||
begin
|
||||
ret := gms_debug.continue(run_info, 0, 2);
|
||||
RAISE NOTICE 'breakpoint= %', run_info.breakpoint;
|
||||
RAISE NOTICE 'stackdepth= %', run_info.stackdepth;
|
||||
RAISE NOTICE 'line= %', run_info.line#;
|
||||
RAISE NOTICE 'reason= %', run_info.reason;
|
||||
RAISE NOTICE 'ret= %',ret;
|
||||
end;
|
||||
$$ LANGUAGE plpgsql;
|
||||
-- attach debug server
|
||||
select * from gms_debug.attach_session('datanode1-0');
|
||||
attach_session
|
||||
----------------
|
||||
|
||||
(1 row)
|
||||
|
||||
select pg_sleep(3);
|
||||
pg_sleep
|
||||
----------
|
||||
|
||||
(1 row)
|
||||
|
||||
select gms_step();
|
||||
NOTICE: breakpoint= -1
|
||||
CONTEXT: referenced column: gms_step
|
||||
NOTICE: stackdepth= 0
|
||||
CONTEXT: referenced column: gms_step
|
||||
NOTICE: line= 6
|
||||
CONTEXT: referenced column: gms_step
|
||||
NOTICE: reason= 3
|
||||
CONTEXT: referenced column: gms_step
|
||||
NOTICE: ret= 0
|
||||
CONTEXT: referenced column: gms_step
|
||||
gms_step
|
||||
----------
|
||||
|
||||
(1 row)
|
||||
|
||||
select gms_step();
|
||||
NOTICE: breakpoint= -1
|
||||
CONTEXT: referenced column: gms_step
|
||||
NOTICE: stackdepth= 0
|
||||
CONTEXT: referenced column: gms_step
|
||||
NOTICE: line= 7
|
||||
CONTEXT: referenced column: gms_step
|
||||
NOTICE: reason= 3
|
||||
CONTEXT: referenced column: gms_step
|
||||
NOTICE: ret= 0
|
||||
CONTEXT: referenced column: gms_step
|
||||
gms_step
|
||||
----------
|
||||
|
||||
(1 row)
|
||||
|
||||
select gms_step();
|
||||
NOTICE: breakpoint= -1
|
||||
CONTEXT: referenced column: gms_step
|
||||
NOTICE: stackdepth= 1
|
||||
CONTEXT: referenced column: gms_step
|
||||
NOTICE: line= 15
|
||||
CONTEXT: referenced column: gms_step
|
||||
NOTICE: reason= 3
|
||||
CONTEXT: referenced column: gms_step
|
||||
NOTICE: ret= 0
|
||||
CONTEXT: referenced column: gms_step
|
||||
gms_step
|
||||
----------
|
||||
|
||||
(1 row)
|
||||
|
||||
select gms_step();
|
||||
NOTICE: breakpoint= -1
|
||||
CONTEXT: referenced column: gms_step
|
||||
NOTICE: stackdepth= 1
|
||||
CONTEXT: referenced column: gms_step
|
||||
NOTICE: line= 16
|
||||
CONTEXT: referenced column: gms_step
|
||||
NOTICE: reason= 3
|
||||
CONTEXT: referenced column: gms_step
|
||||
NOTICE: ret= 0
|
||||
CONTEXT: referenced column: gms_step
|
||||
gms_step
|
||||
----------
|
||||
|
||||
(1 row)
|
||||
|
||||
select gms_step();
|
||||
NOTICE: breakpoint= -1
|
||||
CONTEXT: referenced column: gms_step
|
||||
NOTICE: stackdepth= 1
|
||||
CONTEXT: referenced column: gms_step
|
||||
NOTICE: line= 19
|
||||
CONTEXT: referenced column: gms_step
|
||||
NOTICE: reason= 3
|
||||
CONTEXT: referenced column: gms_step
|
||||
NOTICE: ret= 0
|
||||
CONTEXT: referenced column: gms_step
|
||||
gms_step
|
||||
----------
|
||||
|
||||
(1 row)
|
||||
|
||||
select gms_continue();
|
||||
NOTICE: breakpoint= -1
|
||||
CONTEXT: referenced column: gms_continue
|
||||
NOTICE: stackdepth= 0
|
||||
CONTEXT: referenced column: gms_continue
|
||||
NOTICE: line= 14
|
||||
CONTEXT: referenced column: gms_continue
|
||||
NOTICE: reason= 3
|
||||
CONTEXT: referenced column: gms_continue
|
||||
NOTICE: ret= 0
|
||||
CONTEXT: referenced column: gms_continue
|
||||
gms_continue
|
||||
--------------
|
||||
|
||||
(1 row)
|
||||
|
||||
select gms_continue();
|
||||
NOTICE: breakpoint= -1
|
||||
CONTEXT: referenced column: gms_continue
|
||||
NOTICE: stackdepth= 0
|
||||
CONTEXT: referenced column: gms_continue
|
||||
NOTICE: line= 15
|
||||
CONTEXT: referenced column: gms_continue
|
||||
NOTICE: reason= 0
|
||||
CONTEXT: referenced column: gms_continue
|
||||
NOTICE: ret= 0
|
||||
CONTEXT: referenced column: gms_continue
|
||||
gms_continue
|
||||
--------------
|
||||
|
||||
(1 row)
|
||||
|
||||
select gms_debug.detach_session();
|
||||
detach_session
|
||||
----------------
|
||||
|
||||
(1 row)
|
||||
|
||||
200
contrib/gms_debug/expected/gms_debugger_client5.out
Normal file
200
contrib/gms_debug/expected/gms_debugger_client5.out
Normal file
@ -0,0 +1,200 @@
|
||||
-- wait for server establishment
|
||||
CREATE OR REPLACE FUNCTION wait_for_gms_debug_extension()
|
||||
RETURNS BOOLEAN AS $$
|
||||
DECLARE
|
||||
extension_exists BOOLEAN;
|
||||
BEGIN
|
||||
-- 初始化变量
|
||||
extension_exists := FALSE;
|
||||
|
||||
-- 循环查询扩展是否存在
|
||||
WHILE NOT extension_exists LOOP
|
||||
-- 查询扩展是否存在
|
||||
PERFORM 1 FROM pg_extension WHERE extname = 'gms_debug';
|
||||
IF FOUND THEN
|
||||
-- 如果扩展存在,则退出循环
|
||||
extension_exists := TRUE;
|
||||
ELSE
|
||||
-- 如果扩展不存在,则等待一段时间再重试
|
||||
PERFORM pg_sleep(1); -- 等待1秒
|
||||
END IF;
|
||||
END LOOP;
|
||||
|
||||
-- 返回扩展存在的标志
|
||||
RETURN extension_exists;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
DO $$
|
||||
BEGIN
|
||||
IF wait_for_gms_debug_extension() THEN
|
||||
-- 扩展存在,执行下一步操作
|
||||
END IF;
|
||||
END $$;
|
||||
set search_path = gms_debugger_test5;
|
||||
CREATE or REPLACE FUNCTION gms_continue()
|
||||
returns void as $$
|
||||
declare
|
||||
run_info gms_debug.runtime_info;
|
||||
ret binary_integer;
|
||||
begin
|
||||
ret := gms_debug.continue(run_info, 0, 2);
|
||||
RAISE NOTICE 'breakpoint= %', run_info.breakpoint;
|
||||
RAISE NOTICE 'stackdepth= %', run_info.stackdepth;
|
||||
RAISE NOTICE 'line= %', run_info.line#;
|
||||
RAISE NOTICE 'reason= %', run_info.reason;
|
||||
RAISE NOTICE 'ret= %',ret;
|
||||
end;
|
||||
$$ LANGUAGE plpgsql;
|
||||
CREATE or REPLACE FUNCTION gms_step()
|
||||
returns void as $$
|
||||
declare
|
||||
run_info gms_debug.runtime_info;
|
||||
ret binary_integer;
|
||||
begin
|
||||
ret := gms_debug.continue(run_info, 4, 2);
|
||||
RAISE NOTICE 'breakpoint= %', run_info.breakpoint;
|
||||
RAISE NOTICE 'stackdepth= %', run_info.stackdepth;
|
||||
RAISE NOTICE 'line= %', run_info.line#;
|
||||
RAISE NOTICE 'reason= %', run_info.reason;
|
||||
RAISE NOTICE 'ret= %',ret;
|
||||
end;
|
||||
$$ LANGUAGE plpgsql;
|
||||
CREATE or REPLACE FUNCTION gms_next()
|
||||
returns void as $$
|
||||
declare
|
||||
run_info gms_debug.runtime_info;
|
||||
ret binary_integer;
|
||||
begin
|
||||
ret := gms_debug.continue(run_info, 2, 2);
|
||||
RAISE NOTICE 'breakpoint= %', run_info.breakpoint;
|
||||
RAISE NOTICE 'stackdepth= %', run_info.stackdepth;
|
||||
RAISE NOTICE 'line= %', run_info.line#;
|
||||
RAISE NOTICE 'reason= %', run_info.reason;
|
||||
RAISE NOTICE 'ret= %',ret;
|
||||
end;
|
||||
$$ LANGUAGE plpgsql;
|
||||
CREATE or REPLACE FUNCTION gms_finish()
|
||||
returns void as $$
|
||||
declare
|
||||
run_info gms_debug.runtime_info;
|
||||
ret binary_integer;
|
||||
begin
|
||||
ret := gms_debug.continue(run_info, 8, 2);
|
||||
RAISE NOTICE 'breakpoint= %', run_info.breakpoint;
|
||||
RAISE NOTICE 'stackdepth= %', run_info.stackdepth;
|
||||
RAISE NOTICE 'line= %', run_info.line#;
|
||||
RAISE NOTICE 'reason= %', run_info.reason;
|
||||
RAISE NOTICE 'ret= %',ret;
|
||||
end;
|
||||
$$ LANGUAGE plpgsql;
|
||||
-- attach debug server
|
||||
select * from gms_debug.attach_session('datanode1-0');
|
||||
attach_session
|
||||
----------------
|
||||
|
||||
(1 row)
|
||||
|
||||
select pg_sleep(3);
|
||||
pg_sleep
|
||||
----------
|
||||
|
||||
(1 row)
|
||||
|
||||
select gms_next();
|
||||
NOTICE: breakpoint= -1
|
||||
CONTEXT: referenced column: gms_next
|
||||
NOTICE: stackdepth= 0
|
||||
CONTEXT: referenced column: gms_next
|
||||
NOTICE: line= 6
|
||||
CONTEXT: referenced column: gms_next
|
||||
NOTICE: reason= 6
|
||||
CONTEXT: referenced column: gms_next
|
||||
NOTICE: ret= 0
|
||||
CONTEXT: referenced column: gms_next
|
||||
gms_next
|
||||
----------
|
||||
|
||||
(1 row)
|
||||
|
||||
select gms_next();
|
||||
NOTICE: breakpoint= -1
|
||||
CONTEXT: referenced column: gms_next
|
||||
NOTICE: stackdepth= 0
|
||||
CONTEXT: referenced column: gms_next
|
||||
NOTICE: line= 7
|
||||
CONTEXT: referenced column: gms_next
|
||||
NOTICE: reason= 6
|
||||
CONTEXT: referenced column: gms_next
|
||||
NOTICE: ret= 0
|
||||
CONTEXT: referenced column: gms_next
|
||||
gms_next
|
||||
----------
|
||||
|
||||
(1 row)
|
||||
|
||||
select gms_next();
|
||||
NOTICE: breakpoint= -1
|
||||
CONTEXT: referenced column: gms_next
|
||||
NOTICE: stackdepth= 0
|
||||
CONTEXT: referenced column: gms_next
|
||||
NOTICE: line= 14
|
||||
CONTEXT: referenced column: gms_next
|
||||
NOTICE: reason= 6
|
||||
CONTEXT: referenced column: gms_next
|
||||
NOTICE: ret= 0
|
||||
CONTEXT: referenced column: gms_next
|
||||
gms_next
|
||||
----------
|
||||
|
||||
(1 row)
|
||||
|
||||
select gms_step();
|
||||
NOTICE: breakpoint= -1
|
||||
CONTEXT: referenced column: gms_step
|
||||
NOTICE: stackdepth= 0
|
||||
CONTEXT: referenced column: gms_step
|
||||
NOTICE: line= 15
|
||||
CONTEXT: referenced column: gms_step
|
||||
NOTICE: reason= 3
|
||||
CONTEXT: referenced column: gms_step
|
||||
NOTICE: ret= 0
|
||||
CONTEXT: referenced column: gms_step
|
||||
gms_step
|
||||
----------
|
||||
|
||||
(1 row)
|
||||
|
||||
select gms_finish();
|
||||
NOTICE: breakpoint= -1
|
||||
CONTEXT: referenced column: gms_finish
|
||||
NOTICE: stackdepth= 0
|
||||
CONTEXT: referenced column: gms_finish
|
||||
NOTICE: line= 15
|
||||
CONTEXT: referenced column: gms_finish
|
||||
NOTICE: reason= 0
|
||||
CONTEXT: referenced column: gms_finish
|
||||
NOTICE: ret= 0
|
||||
CONTEXT: referenced column: gms_finish
|
||||
gms_finish
|
||||
------------
|
||||
|
||||
(1 row)
|
||||
|
||||
select gms_finish();
|
||||
NOTICE: breakpoint= -1
|
||||
CONTEXT: referenced column: gms_finish
|
||||
NOTICE: stackdepth= 0
|
||||
CONTEXT: referenced column: gms_finish
|
||||
NOTICE: line= 15
|
||||
CONTEXT: referenced column: gms_finish
|
||||
NOTICE: reason= 0
|
||||
CONTEXT: referenced column: gms_finish
|
||||
NOTICE: ret= 0
|
||||
CONTEXT: referenced column: gms_finish
|
||||
gms_finish
|
||||
------------
|
||||
|
||||
(1 row)
|
||||
|
||||
select gms_debug.detach_session();
|
||||
connection to server was lost
|
||||
177
contrib/gms_debug/expected/gms_debugger_client6.out
Normal file
177
contrib/gms_debug/expected/gms_debugger_client6.out
Normal file
@ -0,0 +1,177 @@
|
||||
-- wait for server establishment
|
||||
CREATE OR REPLACE FUNCTION wait_for_gms_debug_extension()
|
||||
RETURNS BOOLEAN AS $$
|
||||
DECLARE
|
||||
extension_exists BOOLEAN;
|
||||
BEGIN
|
||||
-- 初始化变量
|
||||
extension_exists := FALSE;
|
||||
|
||||
-- 循环查询扩展是否存在
|
||||
WHILE NOT extension_exists LOOP
|
||||
-- 查询扩展是否存在
|
||||
PERFORM 1 FROM pg_extension WHERE extname = 'gms_debug';
|
||||
IF FOUND THEN
|
||||
-- 如果扩展存在,则退出循环
|
||||
extension_exists := TRUE;
|
||||
ELSE
|
||||
-- 如果扩展不存在,则等待一段时间再重试
|
||||
PERFORM pg_sleep(1); -- 等待1秒
|
||||
END IF;
|
||||
END LOOP;
|
||||
|
||||
-- 返回扩展存在的标志
|
||||
RETURN extension_exists;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
DO $$
|
||||
BEGIN
|
||||
IF wait_for_gms_debug_extension() THEN
|
||||
-- 扩展存在,执行下一步操作
|
||||
END IF;
|
||||
END $$;
|
||||
set search_path = gms_debugger_test6;
|
||||
CREATE or REPLACE FUNCTION gms_continue()
|
||||
returns void as $$
|
||||
declare
|
||||
run_info gms_debug.runtime_info;
|
||||
ret binary_integer;
|
||||
begin
|
||||
ret := gms_debug.continue(run_info, 0, 2);
|
||||
RAISE NOTICE 'breakpoint= %', run_info.breakpoint;
|
||||
RAISE NOTICE 'stackdepth= %', run_info.stackdepth;
|
||||
RAISE NOTICE 'line= %', run_info.line#;
|
||||
RAISE NOTICE 'reason= %', run_info.reason;
|
||||
RAISE NOTICE 'ret= %',ret;
|
||||
end;
|
||||
$$ LANGUAGE plpgsql;
|
||||
CREATE or REPLACE FUNCTION gms_breakpoint(funcname text, lineno int)
|
||||
returns void as $$
|
||||
declare
|
||||
pro_info gms_debug.program_info;
|
||||
bkline binary_integer;
|
||||
ret binary_integer;
|
||||
begin
|
||||
pro_info.name := funcname;
|
||||
ret := gms_debug.set_breakpoint(pro_info, lineno, bkline,1,1);
|
||||
RAISE NOTICE 'ret= %', ret;
|
||||
RAISE NOTICE 'ret= %', bkline;
|
||||
end;
|
||||
$$ LANGUAGE plpgsql;
|
||||
CREATE or REPLACE FUNCTION gms_finish()
|
||||
returns void as $$
|
||||
declare
|
||||
run_info gms_debug.runtime_info;
|
||||
ret binary_integer;
|
||||
begin
|
||||
ret := gms_debug.continue(run_info, 8, 2);
|
||||
RAISE NOTICE 'breakpoint= %', run_info.breakpoint;
|
||||
RAISE NOTICE 'stackdepth= %', run_info.stackdepth;
|
||||
RAISE NOTICE 'line= %', run_info.line#;
|
||||
RAISE NOTICE 'reason= %', run_info.reason;
|
||||
RAISE NOTICE 'ret= %',ret;
|
||||
end;
|
||||
$$ LANGUAGE plpgsql;
|
||||
-- attach debug server
|
||||
select * from gms_debug.attach_session('datanode1-0');
|
||||
attach_session
|
||||
----------------
|
||||
|
||||
(1 row)
|
||||
|
||||
select pg_sleep(3);
|
||||
pg_sleep
|
||||
----------
|
||||
|
||||
(1 row)
|
||||
|
||||
select gms_breakpoint('test_debug', 31);
|
||||
NOTICE: ret= 0
|
||||
CONTEXT: referenced column: gms_breakpoint
|
||||
NOTICE: ret= 0
|
||||
CONTEXT: referenced column: gms_breakpoint
|
||||
gms_breakpoint
|
||||
----------------
|
||||
|
||||
(1 row)
|
||||
|
||||
select gms_breakpoint('test_debug', 44);
|
||||
NOTICE: ret= 1
|
||||
CONTEXT: referenced column: gms_breakpoint
|
||||
NOTICE: ret= 0
|
||||
CONTEXT: referenced column: gms_breakpoint
|
||||
gms_breakpoint
|
||||
----------------
|
||||
|
||||
(1 row)
|
||||
|
||||
select gms_finish();
|
||||
NOTICE: breakpoint= 0
|
||||
CONTEXT: referenced column: gms_finish
|
||||
NOTICE: stackdepth= 1
|
||||
CONTEXT: referenced column: gms_finish
|
||||
NOTICE: line= 31
|
||||
CONTEXT: referenced column: gms_finish
|
||||
NOTICE: reason= 2
|
||||
CONTEXT: referenced column: gms_finish
|
||||
NOTICE: ret= 0
|
||||
CONTEXT: referenced column: gms_finish
|
||||
gms_finish
|
||||
------------
|
||||
|
||||
(1 row)
|
||||
|
||||
select gms_finish();
|
||||
NOTICE: breakpoint= 1
|
||||
CONTEXT: referenced column: gms_finish
|
||||
NOTICE: stackdepth= 1
|
||||
CONTEXT: referenced column: gms_finish
|
||||
NOTICE: line= 44
|
||||
CONTEXT: referenced column: gms_finish
|
||||
NOTICE: reason= 2
|
||||
CONTEXT: referenced column: gms_finish
|
||||
NOTICE: ret= 0
|
||||
CONTEXT: referenced column: gms_finish
|
||||
gms_finish
|
||||
------------
|
||||
|
||||
(1 row)
|
||||
|
||||
select gms_finish();
|
||||
NOTICE: breakpoint= -1
|
||||
CONTEXT: referenced column: gms_finish
|
||||
NOTICE: stackdepth= 0
|
||||
CONTEXT: referenced column: gms_finish
|
||||
NOTICE: line= 14
|
||||
CONTEXT: referenced column: gms_finish
|
||||
NOTICE: reason= 3
|
||||
CONTEXT: referenced column: gms_finish
|
||||
NOTICE: ret= 0
|
||||
CONTEXT: referenced column: gms_finish
|
||||
gms_finish
|
||||
------------
|
||||
|
||||
(1 row)
|
||||
|
||||
select gms_continue();
|
||||
NOTICE: breakpoint= -1
|
||||
CONTEXT: referenced column: gms_continue
|
||||
NOTICE: stackdepth= 0
|
||||
CONTEXT: referenced column: gms_continue
|
||||
NOTICE: line= 15
|
||||
CONTEXT: referenced column: gms_continue
|
||||
NOTICE: reason= 0
|
||||
CONTEXT: referenced column: gms_continue
|
||||
NOTICE: ret= 0
|
||||
CONTEXT: referenced column: gms_continue
|
||||
gms_continue
|
||||
--------------
|
||||
|
||||
(1 row)
|
||||
|
||||
select gms_debug.detach_session();
|
||||
detach_session
|
||||
----------------
|
||||
|
||||
(1 row)
|
||||
|
||||
181
contrib/gms_debug/expected/gms_debugger_server1.out
Normal file
181
contrib/gms_debug/expected/gms_debugger_server1.out
Normal file
@ -0,0 +1,181 @@
|
||||
-- setups
|
||||
create extension if not exists gms_debug;
|
||||
drop schema if exists gms_debugger_test1 cascade;
|
||||
NOTICE: schema "gms_debugger_test1" does not exist, skipping
|
||||
create schema gms_debugger_test1;
|
||||
set search_path = gms_debugger_test1;
|
||||
create table test(a int, b varchar(40), c timestamp);
|
||||
insert into test values (2, 'Giving to the Needy', '2020-02-02');
|
||||
insert into test values (3, 'Prayer', '2021-12-02');
|
||||
insert into test values (5, 'Fasting', '2030-03-02');
|
||||
insert into test values (7, 'Treasures in Heaven', '2040-04-02');
|
||||
CREATE OR REPLACE FUNCTION test_debug(x int) RETURNS SETOF test AS
|
||||
$BODY$
|
||||
DECLARE
|
||||
sql_stmt VARCHAR2(500);
|
||||
r test%rowtype;
|
||||
rec record;
|
||||
b_tmp text;
|
||||
cnt int;
|
||||
a_tmp int;
|
||||
cur refcursor;
|
||||
n_tmp NUMERIC(24,6);
|
||||
t_tmp tsquery;
|
||||
CURSOR cur_arg(criterion INTEGER) IS
|
||||
SELECT * FROM test WHERE a < criterion;
|
||||
BEGIN
|
||||
cnt := 0;
|
||||
FOR r IN SELECT * FROM test
|
||||
WHERE a > x
|
||||
LOOP
|
||||
RETURN NEXT r;
|
||||
END LOOP;
|
||||
|
||||
FOR rec in SELECT * FROM test
|
||||
WHERE a < x
|
||||
LOOP
|
||||
RETURN NEXT rec;
|
||||
END LOOP;
|
||||
|
||||
FORALL index_1 IN 0..1
|
||||
INSERT INTO test VALUES (index_1, 'Happy Children''s Day!', '2021-6-1');
|
||||
|
||||
SELECT b FROM test where a = 7 INTO b_tmp;
|
||||
sql_stmt := 'select a from test where b = :1;';
|
||||
OPEN cur FOR sql_stmt USING b_tmp;
|
||||
IF cur%isopen then LOOP
|
||||
FETCH cur INTO a_tmp;
|
||||
EXIT WHEN cur%notfound;
|
||||
END LOOP;
|
||||
END IF;
|
||||
CLOSE cur;
|
||||
WHILE cnt < 3 LOOP
|
||||
cnt := cnt + 1;
|
||||
END LOOP;
|
||||
|
||||
RAISE INFO 'cnt is %', cnt;
|
||||
|
||||
RETURN;
|
||||
|
||||
END
|
||||
$BODY$
|
||||
LANGUAGE plpgsql;
|
||||
create table show_code_table(lineno int, code text, canBreak bool);
|
||||
do $$
|
||||
declare
|
||||
funcoid oid;
|
||||
begin
|
||||
select oid from pg_proc into funcoid where proname = 'test_debug';
|
||||
INSERT INTO show_code_table SELECT * FROM dbe_pldebugger.info_code(funcoid);
|
||||
end;
|
||||
$$;
|
||||
select * from show_code_table;
|
||||
lineno | code | canbreak
|
||||
--------+----------------------------------------------------------------------------------+----------
|
||||
| CREATE OR REPLACE FUNCTION gms_debugger_test1.test_debug(x integer) | f
|
||||
| RETURNS SETOF test | f
|
||||
| LANGUAGE plpgsql | f
|
||||
| NOT FENCED NOT SHIPPABLE | f
|
||||
1 | AS $function$ | f
|
||||
2 | DECLARE | f
|
||||
3 | sql_stmt VARCHAR2(500); | f
|
||||
4 | r test%rowtype; | f
|
||||
5 | rec record; | f
|
||||
6 | b_tmp text; | f
|
||||
7 | cnt int; | f
|
||||
8 | a_tmp int; | f
|
||||
9 | cur refcursor; | f
|
||||
10 | n_tmp NUMERIC(24,6); | f
|
||||
11 | t_tmp tsquery; | f
|
||||
12 | CURSOR cur_arg(criterion INTEGER) IS | f
|
||||
13 | SELECT * FROM test WHERE a < criterion; | f
|
||||
14 | BEGIN | f
|
||||
15 | cnt := 0; | t
|
||||
16 | FOR r IN SELECT * FROM test | t
|
||||
17 | WHERE a > x | f
|
||||
18 | LOOP | f
|
||||
19 | RETURN NEXT r; | t
|
||||
20 | END LOOP; | f
|
||||
21 | | f
|
||||
22 | FOR rec in SELECT * FROM test | t
|
||||
23 | WHERE a < x | f
|
||||
24 | LOOP | f
|
||||
25 | RETURN NEXT rec; | t
|
||||
26 | END LOOP; | f
|
||||
27 | | f
|
||||
28 | FORALL index_1 IN 0..1 | t
|
||||
29 | INSERT INTO test VALUES (index_1, 'Happy Children''s Day!', '2021-6-1'); | t
|
||||
30 | | f
|
||||
31 | SELECT b FROM test where a = 7 INTO b_tmp; | t
|
||||
32 | sql_stmt := 'select a from test where b = :1;'; | t
|
||||
33 | OPEN cur FOR sql_stmt USING b_tmp; | t
|
||||
34 | IF cur%isopen then LOOP | t
|
||||
35 | FETCH cur INTO a_tmp; | t
|
||||
36 | EXIT WHEN cur%notfound; | t
|
||||
37 | END LOOP; | f
|
||||
38 | END IF; | f
|
||||
39 | CLOSE cur; | t
|
||||
40 | WHILE cnt < 3 LOOP | t
|
||||
41 | cnt := cnt + 1; | t
|
||||
42 | END LOOP; | f
|
||||
43 | | f
|
||||
44 | RAISE INFO 'cnt is %', cnt; | t
|
||||
45 | | f
|
||||
46 | RETURN; | t
|
||||
47 | | f
|
||||
48 | END | f
|
||||
49 | $function$; | f
|
||||
(53 rows)
|
||||
|
||||
-- attach fail (target not turned on)
|
||||
select * from gms_debug.attach_session('datanode1-0');
|
||||
ERROR: target session should be init first.
|
||||
-- turn off without turn on
|
||||
select * from gms_debug.debug_off();
|
||||
ERROR: target session should be init first
|
||||
select * from gms_debug.initialize();
|
||||
initialize
|
||||
-------------
|
||||
datanode1-0
|
||||
(1 row)
|
||||
|
||||
select pg_sleep(1);
|
||||
pg_sleep
|
||||
----------
|
||||
|
||||
(1 row)
|
||||
|
||||
-- start debug - 1st run
|
||||
select * from test_debug(4);
|
||||
INFO: cnt is 3
|
||||
a | b | c
|
||||
---+---------------------+--------------------------
|
||||
5 | Fasting | Sat Mar 02 00:00:00 2030
|
||||
7 | Treasures in Heaven | Mon Apr 02 00:00:00 2040
|
||||
2 | Giving to the Needy | Sun Feb 02 00:00:00 2020
|
||||
3 | Prayer | Thu Dec 02 00:00:00 2021
|
||||
(4 rows)
|
||||
|
||||
-- start debug - 2nd run - to be aborted
|
||||
select * from test_debug(4);
|
||||
INFO: cnt is 3
|
||||
a | b | c
|
||||
---+-----------------------+--------------------------
|
||||
5 | Fasting | Sat Mar 02 00:00:00 2030
|
||||
7 | Treasures in Heaven | Mon Apr 02 00:00:00 2040
|
||||
2 | Giving to the Needy | Sun Feb 02 00:00:00 2020
|
||||
3 | Prayer | Thu Dec 02 00:00:00 2021
|
||||
0 | Happy Children's Day! | Tue Jun 01 00:00:00 2021
|
||||
1 | Happy Children's Day! | Tue Jun 01 00:00:00 2021
|
||||
(6 rows)
|
||||
|
||||
drop schema gms_debugger_test1 cascade;
|
||||
NOTICE: drop cascades to 8 other objects
|
||||
DETAIL: drop cascades to table test
|
||||
drop cascades to function test_debug(integer)
|
||||
drop cascades to table show_code_table
|
||||
drop cascades to function gms_breakpoint(text,integer)
|
||||
drop cascades to function gms_continue()
|
||||
drop cascades to function gms_next()
|
||||
drop cascades to function gms_step()
|
||||
drop cascades to function gms_info()
|
||||
46
contrib/gms_debug/expected/gms_debugger_server2.out
Normal file
46
contrib/gms_debug/expected/gms_debugger_server2.out
Normal file
@ -0,0 +1,46 @@
|
||||
-- setups
|
||||
create extension if not exists gms_debug;
|
||||
drop schema if exists gms_debugger_test2 cascade;
|
||||
NOTICE: schema "gms_debugger_test2" does not exist, skipping
|
||||
create schema gms_debugger_test2;
|
||||
set search_path = gms_debugger_test2;
|
||||
-- commit/rollback in procedure
|
||||
create table tb1(a int);
|
||||
create or replace procedure test_debug2 as
|
||||
begin
|
||||
insert into tb1 values (1000);
|
||||
commit;
|
||||
insert into tb1 values (2000);
|
||||
rollback;
|
||||
end;
|
||||
/
|
||||
-- start debug
|
||||
select * from gms_debug.initialize();
|
||||
initialize
|
||||
-------------
|
||||
datanode1-0
|
||||
(1 row)
|
||||
|
||||
select pg_sleep(1);
|
||||
pg_sleep
|
||||
----------
|
||||
|
||||
(1 row)
|
||||
|
||||
-- start debug - 1st run
|
||||
select * from test_debug2();
|
||||
test_debug2
|
||||
-------------
|
||||
|
||||
(1 row)
|
||||
|
||||
-- start debug - 2nd run - to be aborted
|
||||
select * from test_debug2();
|
||||
ERROR: receive abort message
|
||||
CONTEXT: PL/pgSQL function test_debug2() line 2 at SQL statement
|
||||
drop schema gms_debugger_test2 cascade;
|
||||
NOTICE: drop cascades to 4 other objects
|
||||
DETAIL: drop cascades to table tb1
|
||||
drop cascades to function test_debug2()
|
||||
drop cascades to function gms_continue()
|
||||
drop cascades to function gms_next()
|
||||
53
contrib/gms_debug/expected/gms_debugger_server3.out
Normal file
53
contrib/gms_debug/expected/gms_debugger_server3.out
Normal file
@ -0,0 +1,53 @@
|
||||
-- setups
|
||||
create extension if not exists gms_debug;
|
||||
drop schema if exists gms_debugger_test3 cascade;
|
||||
NOTICE: schema "gms_debugger_test3" does not exist, skipping
|
||||
create schema gms_debugger_test3;
|
||||
set search_path = gms_debugger_test3;
|
||||
-- test for implicit variables
|
||||
CREATE OR REPLACE function test_debug3(a in integer) return integer
|
||||
AS
|
||||
declare
|
||||
b int;
|
||||
BEGIN
|
||||
CASE a
|
||||
WHEN 1 THEN
|
||||
b := 111;
|
||||
ELSE
|
||||
b := 999;
|
||||
END CASE;
|
||||
raise info 'pi_return : %',pi_return ;
|
||||
return b;
|
||||
EXCEPTION WHEN others THEN
|
||||
b := 101;
|
||||
return b;
|
||||
END;
|
||||
/
|
||||
select * from gms_debug.initialize();
|
||||
initialize
|
||||
-------------
|
||||
datanode1-0
|
||||
(1 row)
|
||||
|
||||
select pg_sleep(1);
|
||||
pg_sleep
|
||||
----------
|
||||
|
||||
(1 row)
|
||||
|
||||
-- start debug - 1st run
|
||||
select * from test_debug3(1);
|
||||
test_debug3
|
||||
-------------
|
||||
101
|
||||
(1 row)
|
||||
|
||||
-- start debug - 2nd run - to be aborted
|
||||
select * from test_debug3(1);
|
||||
ERROR: receive abort message
|
||||
CONTEXT: PL/pgSQL function test_debug3(integer) line 13 at assignment
|
||||
drop schema gms_debugger_test3 cascade;
|
||||
NOTICE: drop cascades to 3 other objects
|
||||
DETAIL: drop cascades to function test_debug3(integer)
|
||||
drop cascades to function gms_next()
|
||||
drop cascades to function gms_continue()
|
||||
114
contrib/gms_debug/expected/gms_debugger_server4.out
Normal file
114
contrib/gms_debug/expected/gms_debugger_server4.out
Normal file
@ -0,0 +1,114 @@
|
||||
-- setups
|
||||
create extension if not exists gms_debug;
|
||||
drop schema if exists gms_debugger_test4 cascade;
|
||||
NOTICE: schema "gms_debugger_test4" does not exist, skipping
|
||||
create schema gms_debugger_test4;
|
||||
set search_path = gms_debugger_test4;
|
||||
create table test(a int, b varchar(40), c timestamp);
|
||||
insert into test values (2, 'Giving to the Needy', '2020-02-02');
|
||||
insert into test values (3, 'Prayer', '2021-12-02');
|
||||
insert into test values (5, 'Fasting', '2030-03-02');
|
||||
insert into test values (7, 'Treasures in Heaven', '2040-04-02');
|
||||
CREATE OR REPLACE FUNCTION test_debug(x int) RETURNS SETOF test AS
|
||||
$BODY$
|
||||
DECLARE
|
||||
sql_stmt VARCHAR2(500);
|
||||
r test%rowtype;
|
||||
rec record;
|
||||
b_tmp text;
|
||||
cnt int;
|
||||
a_tmp int;
|
||||
cur refcursor;
|
||||
n_tmp NUMERIC(24,6);
|
||||
t_tmp tsquery;
|
||||
CURSOR cur_arg(criterion INTEGER) IS
|
||||
SELECT * FROM test WHERE a < criterion;
|
||||
BEGIN
|
||||
cnt := 0;
|
||||
FOR r IN SELECT * FROM test
|
||||
WHERE a > x
|
||||
LOOP
|
||||
RETURN NEXT r;
|
||||
END LOOP;
|
||||
|
||||
FOR rec in SELECT * FROM test
|
||||
WHERE a < x
|
||||
LOOP
|
||||
RETURN NEXT rec;
|
||||
END LOOP;
|
||||
|
||||
FORALL index_1 IN 0..1
|
||||
INSERT INTO test VALUES (index_1, 'Happy Children''s Day!', '2021-6-1');
|
||||
|
||||
SELECT b FROM test where a = 7 INTO b_tmp;
|
||||
sql_stmt := 'select a from test where b = :1;';
|
||||
OPEN cur FOR sql_stmt USING b_tmp;
|
||||
IF cur%isopen then LOOP
|
||||
FETCH cur INTO a_tmp;
|
||||
EXIT WHEN cur%notfound;
|
||||
END LOOP;
|
||||
END IF;
|
||||
CLOSE cur;
|
||||
WHILE cnt < 3 LOOP
|
||||
cnt := cnt + 1;
|
||||
END LOOP;
|
||||
|
||||
RAISE INFO 'cnt is %', cnt;
|
||||
|
||||
RETURN;
|
||||
|
||||
END
|
||||
$BODY$
|
||||
LANGUAGE plpgsql;
|
||||
-- test for step into
|
||||
CREATE OR REPLACE FUNCTION test_debug4(a in integer) return integer
|
||||
AS
|
||||
declare
|
||||
b int;
|
||||
BEGIN
|
||||
CASE a
|
||||
WHEN 1 THEN
|
||||
b := 111;
|
||||
call test_debug(a);
|
||||
ELSE
|
||||
b := 999;
|
||||
END CASE;
|
||||
return b;
|
||||
raise info 'pi_return : %',pi_return ;
|
||||
EXCEPTION WHEN others THEN
|
||||
b := 101;
|
||||
return b;
|
||||
END;
|
||||
/
|
||||
select * from gms_debug.initialize();
|
||||
initialize
|
||||
-------------
|
||||
datanode1-0
|
||||
(1 row)
|
||||
|
||||
select pg_sleep(1);
|
||||
pg_sleep
|
||||
----------
|
||||
|
||||
(1 row)
|
||||
|
||||
select * from test_debug4(1);
|
||||
INFO: cnt is 3
|
||||
CONTEXT: SQL statement "call test_debug(a)"
|
||||
PL/pgSQL function test_debug4(integer) line 7 at SQL statement
|
||||
test_debug4
|
||||
-------------
|
||||
101
|
||||
(1 row)
|
||||
|
||||
-- test with client error in exception
|
||||
select * from test_debug4(1);
|
||||
ERROR: receive abort message
|
||||
CONTEXT: PL/pgSQL function test_debug4(integer) line 14 at assignment
|
||||
drop schema gms_debugger_test4 cascade;
|
||||
NOTICE: drop cascades to 5 other objects
|
||||
DETAIL: drop cascades to table test
|
||||
drop cascades to function test_debug(integer)
|
||||
drop cascades to function test_debug4(integer)
|
||||
drop cascades to function gms_step()
|
||||
drop cascades to function gms_continue()
|
||||
122
contrib/gms_debug/expected/gms_debugger_server5.out
Normal file
122
contrib/gms_debug/expected/gms_debugger_server5.out
Normal file
@ -0,0 +1,122 @@
|
||||
-- setups
|
||||
create extension if not exists gms_debug;
|
||||
drop schema if exists gms_debugger_test5 cascade;
|
||||
NOTICE: schema "gms_debugger_test5" does not exist, skipping
|
||||
create schema gms_debugger_test5;
|
||||
set search_path = gms_debugger_test5;
|
||||
create table test(a int, b varchar(40), c timestamp);
|
||||
insert into test values (2, 'Giving to the Needy', '2020-02-02');
|
||||
insert into test values (3, 'Prayer', '2021-12-02');
|
||||
insert into test values (5, 'Fasting', '2030-03-02');
|
||||
insert into test values (7, 'Treasures in Heaven', '2040-04-02');
|
||||
CREATE OR REPLACE FUNCTION test_debug(x int) RETURNS SETOF test AS
|
||||
$BODY$
|
||||
DECLARE
|
||||
sql_stmt VARCHAR2(500);
|
||||
r test%rowtype;
|
||||
rec record;
|
||||
b_tmp text;
|
||||
cnt int;
|
||||
a_tmp int;
|
||||
cur refcursor;
|
||||
n_tmp NUMERIC(24,6);
|
||||
t_tmp tsquery;
|
||||
CURSOR cur_arg(criterion INTEGER) IS
|
||||
SELECT * FROM test WHERE a < criterion;
|
||||
BEGIN
|
||||
cnt := 0;
|
||||
FOR r IN SELECT * FROM test
|
||||
WHERE a > x
|
||||
LOOP
|
||||
RETURN NEXT r;
|
||||
END LOOP;
|
||||
|
||||
FOR rec in SELECT * FROM test
|
||||
WHERE a < x
|
||||
LOOP
|
||||
RETURN NEXT rec;
|
||||
END LOOP;
|
||||
|
||||
FORALL index_1 IN 0..1
|
||||
INSERT INTO test VALUES (index_1, 'Happy Children''s Day!', '2021-6-1');
|
||||
|
||||
SELECT b FROM test where a = 7 INTO b_tmp;
|
||||
sql_stmt := 'select a from test where b = :1;';
|
||||
OPEN cur FOR sql_stmt USING b_tmp;
|
||||
IF cur%isopen then LOOP
|
||||
FETCH cur INTO a_tmp;
|
||||
EXIT WHEN cur%notfound;
|
||||
END LOOP;
|
||||
END IF;
|
||||
CLOSE cur;
|
||||
WHILE cnt < 3 LOOP
|
||||
cnt := cnt + 1;
|
||||
END LOOP;
|
||||
|
||||
RAISE INFO 'cnt is %', cnt;
|
||||
|
||||
RETURN;
|
||||
|
||||
END
|
||||
$BODY$
|
||||
LANGUAGE plpgsql;
|
||||
-- test for step into
|
||||
CREATE OR REPLACE FUNCTION test_debug4(a in integer) return integer
|
||||
AS
|
||||
declare
|
||||
b int;
|
||||
BEGIN
|
||||
CASE a
|
||||
WHEN 1 THEN
|
||||
b := 111;
|
||||
call test_debug(a);
|
||||
ELSE
|
||||
b := 999;
|
||||
END CASE;
|
||||
return b;
|
||||
raise info 'pi_return : %',pi_return ;
|
||||
EXCEPTION WHEN others THEN
|
||||
b := 101;
|
||||
return b;
|
||||
END;
|
||||
/
|
||||
select * from gms_debug.initialize();
|
||||
initialize
|
||||
-------------
|
||||
datanode1-0
|
||||
(1 row)
|
||||
|
||||
select pg_sleep(1);
|
||||
pg_sleep
|
||||
----------
|
||||
|
||||
(1 row)
|
||||
|
||||
select * from test_debug4(1);
|
||||
INFO: cnt is 3
|
||||
CONTEXT: SQL statement "call test_debug(a)"
|
||||
PL/pgSQL function test_debug4(integer) line 7 at SQL statement
|
||||
test_debug4
|
||||
-------------
|
||||
101
|
||||
(1 row)
|
||||
|
||||
-- test with client error in exception
|
||||
select * from test_debug4(1);
|
||||
INFO: cnt is 3
|
||||
CONTEXT: SQL statement "call test_debug(a)"
|
||||
PL/pgSQL function test_debug4(integer) line 7 at SQL statement
|
||||
test_debug4
|
||||
-------------
|
||||
101
|
||||
(1 row)
|
||||
|
||||
drop schema gms_debugger_test5 cascade;
|
||||
NOTICE: drop cascades to 7 other objects
|
||||
DETAIL: drop cascades to table test
|
||||
drop cascades to function test_debug(integer)
|
||||
drop cascades to function test_debug4(integer)
|
||||
drop cascades to function gms_continue()
|
||||
drop cascades to function gms_step()
|
||||
drop cascades to function gms_next()
|
||||
drop cascades to function gms_finish()
|
||||
114
contrib/gms_debug/expected/gms_debugger_server6.out
Normal file
114
contrib/gms_debug/expected/gms_debugger_server6.out
Normal file
@ -0,0 +1,114 @@
|
||||
-- setups
|
||||
create extension if not exists gms_debug;
|
||||
drop schema if exists gms_debugger_test6 cascade;
|
||||
NOTICE: schema "gms_debugger_test6" does not exist, skipping
|
||||
create schema gms_debugger_test6;
|
||||
set search_path = gms_debugger_test6;
|
||||
create table test(a int, b varchar(40), c timestamp);
|
||||
insert into test values (2, 'Giving to the Needy', '2020-02-02');
|
||||
insert into test values (3, 'Prayer', '2021-12-02');
|
||||
insert into test values (5, 'Fasting', '2030-03-02');
|
||||
insert into test values (7, 'Treasures in Heaven', '2040-04-02');
|
||||
CREATE OR REPLACE FUNCTION test_debug(x int) RETURNS SETOF test AS
|
||||
$BODY$
|
||||
DECLARE
|
||||
sql_stmt VARCHAR2(500);
|
||||
r test%rowtype;
|
||||
rec record;
|
||||
b_tmp text;
|
||||
cnt int;
|
||||
a_tmp int;
|
||||
cur refcursor;
|
||||
n_tmp NUMERIC(24,6);
|
||||
t_tmp tsquery;
|
||||
CURSOR cur_arg(criterion INTEGER) IS
|
||||
SELECT * FROM test WHERE a < criterion;
|
||||
BEGIN
|
||||
cnt := 0;
|
||||
FOR r IN SELECT * FROM test
|
||||
WHERE a > x
|
||||
LOOP
|
||||
RETURN NEXT r;
|
||||
END LOOP;
|
||||
|
||||
FOR rec in SELECT * FROM test
|
||||
WHERE a < x
|
||||
LOOP
|
||||
RETURN NEXT rec;
|
||||
END LOOP;
|
||||
|
||||
FORALL index_1 IN 0..1
|
||||
INSERT INTO test VALUES (index_1, 'Happy Children''s Day!', '2021-6-1');
|
||||
|
||||
SELECT b FROM test where a = 7 INTO b_tmp;
|
||||
sql_stmt := 'select a from test where b = :1;';
|
||||
OPEN cur FOR sql_stmt USING b_tmp;
|
||||
IF cur%isopen then LOOP
|
||||
FETCH cur INTO a_tmp;
|
||||
EXIT WHEN cur%notfound;
|
||||
END LOOP;
|
||||
END IF;
|
||||
CLOSE cur;
|
||||
WHILE cnt < 3 LOOP
|
||||
cnt := cnt + 1;
|
||||
END LOOP;
|
||||
|
||||
RAISE INFO 'cnt is %', cnt;
|
||||
|
||||
RETURN;
|
||||
|
||||
END
|
||||
$BODY$
|
||||
LANGUAGE plpgsql;
|
||||
-- test for step into
|
||||
CREATE OR REPLACE FUNCTION test_debug4(a in integer) return integer
|
||||
AS
|
||||
declare
|
||||
b int;
|
||||
BEGIN
|
||||
CASE a
|
||||
WHEN 1 THEN
|
||||
b := 111;
|
||||
call test_debug(a);
|
||||
ELSE
|
||||
b := 999;
|
||||
END CASE;
|
||||
return b;
|
||||
raise info 'pi_return : %',pi_return ;
|
||||
EXCEPTION WHEN others THEN
|
||||
b := 101;
|
||||
return b;
|
||||
END;
|
||||
/
|
||||
select * from gms_debug.initialize();
|
||||
initialize
|
||||
-------------
|
||||
datanode1-0
|
||||
(1 row)
|
||||
|
||||
select pg_sleep(1);
|
||||
pg_sleep
|
||||
----------
|
||||
|
||||
(1 row)
|
||||
|
||||
select * from test_debug4(1);
|
||||
INFO: cnt is 3
|
||||
CONTEXT: SQL statement "call test_debug(a)"
|
||||
PL/pgSQL function test_debug4(integer) line 7 at SQL statement
|
||||
test_debug4
|
||||
-------------
|
||||
101
|
||||
(1 row)
|
||||
|
||||
-- test with client error in exception
|
||||
select * from test_debug4(1);
|
||||
ERROR: Debug Comm 0 has been released or not turned on yet.
|
||||
drop schema gms_debugger_test6 cascade;
|
||||
NOTICE: drop cascades to 6 other objects
|
||||
DETAIL: drop cascades to table test
|
||||
drop cascades to function test_debug(integer)
|
||||
drop cascades to function test_debug4(integer)
|
||||
drop cascades to function gms_continue()
|
||||
drop cascades to function gms_breakpoint(text,integer)
|
||||
drop cascades to function gms_finish()
|
||||
387
contrib/gms_debug/gms_debug--1.0.sql
Normal file
387
contrib/gms_debug/gms_debug--1.0.sql
Normal file
@ -0,0 +1,387 @@
|
||||
/* contrib/gms_debug/gms_debug--1.0.sql */
|
||||
|
||||
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
|
||||
\echo Use "CREATE EXTENSION gms_debug" to load this file. \quit
|
||||
|
||||
-- gms_debug package begin
|
||||
set behavior_compat_options='proc_outparam_override';
|
||||
CREATE SCHEMA gms_debug;
|
||||
GRANT USAGE ON SCHEMA gms_debug TO PUBLIC;
|
||||
|
||||
CREATE TYPE gms_debug.program_info AS (
|
||||
namespace oid,
|
||||
name varchar2(30),
|
||||
owner varchar2(30),
|
||||
dblink varchar2(30),
|
||||
line# binary_integer,
|
||||
libunittype binary_integer,
|
||||
entrypointname varchar2(30));
|
||||
|
||||
CREATE TYPE gms_debug.runtime_info AS (
|
||||
line# binary_integer,
|
||||
terminated binary_integer,
|
||||
breakpoint binary_integer,
|
||||
stackdepth binary_integer,
|
||||
interpreterdepth binary_integer,
|
||||
reason binary_integer,
|
||||
program gms_debug.program_info);
|
||||
|
||||
CREATE or REPLACE FUNCTION gms_debug.initialize(
|
||||
IN debug_session_id varchar2(30) DEFAULT '' ,
|
||||
IN diagnostics binary_integer DEFAULT 0)
|
||||
returns varchar2
|
||||
AS 'MODULE_PATHNAME', 'gms_debug_initialize'
|
||||
LANGUAGE C VOLATILE NOT FENCED;
|
||||
|
||||
CREATE or REPLACE FUNCTION gms_debug.debug_on(
|
||||
IN no_client_side_plsql_engine BOOLEAN DEFAULT TRUE ,
|
||||
IN immediate BOOLEAN DEFAULT FALSE)
|
||||
returns void AS $$
|
||||
BEGIN
|
||||
return;
|
||||
END;
|
||||
$$ language plpgsql IMMUTABLE;
|
||||
|
||||
CREATE or REPLACE FUNCTION gms_debug.attach_session(
|
||||
IN debug_session_id varchar2(30) ,
|
||||
IN diagnostics binary_integer DEFAULT 0)
|
||||
returns void
|
||||
AS 'MODULE_PATHNAME', 'gms_debug_attach_session'
|
||||
LANGUAGE C VOLATILE NOT FENCED;
|
||||
|
||||
CREATE or REPLACE FUNCTION gms_debug.add_breakpoint(
|
||||
IN proid oid,
|
||||
IN line# binary_integer ,
|
||||
OUT breakpoint# binary_integer,
|
||||
IN fuzzy binary_integer,
|
||||
IN iterations binary_integer,
|
||||
OUT sts binary_integer)
|
||||
AS 'MODULE_PATHNAME', 'gms_debug_set_breakpoint'
|
||||
LANGUAGE C VOLATILE NOT FENCED;
|
||||
|
||||
CREATE or REPLACE FUNCTION gms_debug.set_breakpoint(
|
||||
IN program gms_debug.program_info,
|
||||
IN line# binary_integer,
|
||||
OUT breakpoint# binary_integer,
|
||||
IN fuzzy binary_integer,
|
||||
IN iterations binary_integer)
|
||||
returns binary_integer AS $$
|
||||
DECLARE
|
||||
proid oid;
|
||||
sts binary_integer;
|
||||
BEGIN
|
||||
select oid from pg_proc where proname = program.name limit 1 into proid;
|
||||
set behavior_compat_options='';
|
||||
gms_debug.add_breakpoint(proid, line#, breakpoint#, fuzzy, iterations, sts);
|
||||
set behavior_compat_options='proc_outparam_override';
|
||||
return sts;
|
||||
END;
|
||||
$$ language plpgsql;
|
||||
|
||||
CREATE or REPLACE FUNCTION gms_debug.call_continue(
|
||||
IN breakflags binary_integer ,
|
||||
IN info_requested binary_integer DEFAULT NULL,
|
||||
OUT err_code binary_integer,
|
||||
OUT run_line binary_integer,
|
||||
OUT run_breakpoint binary_integer,
|
||||
OUT run_stackdepth binary_integer,
|
||||
OUT run_reason binary_integer,
|
||||
OUT pro_namespace oid,
|
||||
OUT pro_name varchar2(30),
|
||||
OUT pro_owner oid)
|
||||
AS 'MODULE_PATHNAME', 'gms_debug_continue'
|
||||
LANGUAGE C VOLATILE NOT FENCED;
|
||||
|
||||
CREATE or REPLACE FUNCTION gms_debug.continue(
|
||||
OUT run_info gms_debug.runtime_info ,
|
||||
IN breakflags binary_integer ,
|
||||
IN info_requested binary_integer DEFAULT NULL)
|
||||
returns binary_integer AS $$
|
||||
DECLARE
|
||||
err_code binary_integer;
|
||||
run_line binary_integer;
|
||||
run_terminated binary_integer;
|
||||
run_breakpoint binary_integer;
|
||||
run_stackdepth binary_integer;
|
||||
run_interpreterdepth binary_integer;
|
||||
run_reason binary_integer;
|
||||
pro_namespace oid;
|
||||
pro_name varchar2(30);
|
||||
pro_owner oid;
|
||||
pro_ownername varchar2(30);
|
||||
pro gms_debug.program_info;
|
||||
BEGIN
|
||||
set behavior_compat_options='';
|
||||
gms_debug.call_continue(breakflags, info_requested, err_code, run_line,
|
||||
run_breakpoint, run_stackdepth, run_reason, pro_namespace,
|
||||
pro_name, pro_owner);
|
||||
set behavior_compat_options='proc_outparam_override';
|
||||
select usename from pg_user where usesysid = pro_owner into pro_ownername;
|
||||
run_info.line# = run_line;
|
||||
run_info.terminated = 0;
|
||||
run_info.breakpoint = run_breakpoint;
|
||||
run_info.stackdepth = run_stackdepth;
|
||||
run_info.interpreterdepth = -1;
|
||||
run_info.reason = run_reason;
|
||||
pro.namespace = pro_namespace;
|
||||
pro.name = pro_name;
|
||||
pro.owner = pro_ownername;
|
||||
pro.dblink = '';
|
||||
pro.line# = run_line;
|
||||
pro.libunittype = 0;
|
||||
pro.entrypointname = '';
|
||||
run_info.program = pro;
|
||||
return err_code;
|
||||
END;
|
||||
$$ language plpgsql;
|
||||
|
||||
CREATE or REPLACE FUNCTION gms_debug.get_debug_runtime_info(
|
||||
IN info_requested binary_integer,
|
||||
OUT err_code binary_integer,
|
||||
OUT run_line binary_integer,
|
||||
OUT run_breakpoint binary_integer,
|
||||
OUT run_stackdepth binary_integer,
|
||||
OUT run_reason binary_integer,
|
||||
OUT pro_namespace oid,
|
||||
OUT pro_name varchar2(30),
|
||||
OUT pro_owner oid)
|
||||
AS 'MODULE_PATHNAME', 'gms_debug_get_runtime_info'
|
||||
LANGUAGE C VOLATILE NOT FENCED;
|
||||
|
||||
CREATE or REPLACE FUNCTION gms_debug.get_runtime_info(
|
||||
IN info_requested binary_integer,
|
||||
OUT run_info gms_debug.runtime_info)
|
||||
returns binary_integer AS $$
|
||||
DECLARE
|
||||
err_code binary_integer;
|
||||
run_line binary_integer;
|
||||
run_terminated binary_integer;
|
||||
run_breakpoint binary_integer;
|
||||
run_stackdepth binary_integer;
|
||||
run_interpreterdepth binary_integer;
|
||||
run_reason binary_integer;
|
||||
pro_namespace oid;
|
||||
pro_name varchar2(30);
|
||||
pro_owner oid;
|
||||
pro_ownername varchar2(30);
|
||||
pro gms_debug.program_info;
|
||||
BEGIN
|
||||
set behavior_compat_options='';
|
||||
gms_debug.get_debug_runtime_info(info_requested, err_code, run_line,
|
||||
run_breakpoint, run_stackdepth, run_reason, pro_namespace,
|
||||
pro_name, pro_owner);
|
||||
set behavior_compat_options='proc_outparam_override';
|
||||
select usename from pg_user where usesysid = pro_owner into pro_ownername;
|
||||
run_info.line# = run_line;
|
||||
run_info.terminated = 0;
|
||||
run_info.breakpoint = run_breakpoint;
|
||||
run_info.stackdepth = run_stackdepth;
|
||||
run_info.interpreterdepth = -1;
|
||||
run_info.reason = run_reason;
|
||||
pro.namespace = pro_namespace;
|
||||
pro.name = pro_name;
|
||||
pro.owner = pro_ownername;
|
||||
pro.dblink = '';
|
||||
pro.line# = run_line;
|
||||
pro.libunittype = 0;
|
||||
pro.entrypointname = '';
|
||||
run_info.program = pro;
|
||||
return err_code;
|
||||
END;
|
||||
$$ language plpgsql;
|
||||
|
||||
CREATE or REPLACE FUNCTION gms_debug.debug_off()
|
||||
returns void
|
||||
AS 'MODULE_PATHNAME', 'gms_debug_off'
|
||||
LANGUAGE C VOLATILE NOT FENCED;
|
||||
|
||||
CREATE or REPLACE FUNCTION gms_debug.detach_session()
|
||||
returns void
|
||||
AS 'MODULE_PATHNAME', 'gms_debug_detach_session'
|
||||
LANGUAGE C VOLATILE NOT FENCED;
|
||||
|
||||
CREATE or REPLACE PROCEDURE gms_debug.probe_version(OUT major binary_integer, OUT minor binary_integer)
|
||||
AS
|
||||
BEGIN
|
||||
major := 1;
|
||||
minor := 0;
|
||||
END;
|
||||
|
||||
CREATE FUNCTION gms_debug.success() RETURNS int AS $$
|
||||
BEGIN
|
||||
return 0;
|
||||
END;
|
||||
$$ language plpgsql IMMUTABLE;
|
||||
|
||||
CREATE FUNCTION gms_debug.error_illegal_line() RETURNS int AS $$
|
||||
BEGIN
|
||||
return -1;
|
||||
END;
|
||||
$$ language plpgsql IMMUTABLE;
|
||||
|
||||
CREATE FUNCTION gms_debug.error_bad_handle() RETURNS int AS $$
|
||||
BEGIN
|
||||
return -2;
|
||||
END;
|
||||
$$ language plpgsql IMMUTABLE;
|
||||
|
||||
CREATE FUNCTION gms_debug.error_already_exists() RETURNS int AS $$
|
||||
BEGIN
|
||||
return -3;
|
||||
END;
|
||||
$$ language plpgsql IMMUTABLE;
|
||||
|
||||
CREATE FUNCTION gms_debug.error_communication() RETURNS int AS $$
|
||||
BEGIN
|
||||
return -4;
|
||||
END;
|
||||
$$ language plpgsql IMMUTABLE;
|
||||
|
||||
CREATE FUNCTION gms_debug.info_getstackdepth() RETURNS int AS $$
|
||||
BEGIN
|
||||
return 0;
|
||||
END;
|
||||
$$ language plpgsql IMMUTABLE;
|
||||
|
||||
CREATE FUNCTION gms_debug.info_getbreakpoint() RETURNS int AS $$
|
||||
BEGIN
|
||||
return 2;
|
||||
END;
|
||||
$$ language plpgsql IMMUTABLE;
|
||||
|
||||
CREATE FUNCTION gms_debug.info_getlineinfo() RETURNS int AS $$
|
||||
BEGIN
|
||||
return 4;
|
||||
END;
|
||||
$$ language plpgsql IMMUTABLE;
|
||||
|
||||
CREATE FUNCTION gms_debug.break_next_line() RETURNS int AS $$
|
||||
BEGIN
|
||||
return 2;
|
||||
END;
|
||||
$$ language plpgsql IMMUTABLE;
|
||||
|
||||
CREATE FUNCTION gms_debug.break_any_call() RETURNS int AS $$
|
||||
BEGIN
|
||||
return 4;
|
||||
END;
|
||||
$$ language plpgsql IMMUTABLE;
|
||||
|
||||
CREATE FUNCTION gms_debug.break_any_return() RETURNS int AS $$
|
||||
BEGIN
|
||||
return 8;
|
||||
END;
|
||||
$$ language plpgsql IMMUTABLE;
|
||||
|
||||
CREATE FUNCTION gms_debug.break_return() RETURNS int AS $$
|
||||
BEGIN
|
||||
return 16;
|
||||
END;
|
||||
$$ language plpgsql IMMUTABLE;
|
||||
|
||||
CREATE FUNCTION gms_debug.break_exception() RETURNS int AS $$
|
||||
BEGIN
|
||||
return 32;
|
||||
END;
|
||||
$$ language plpgsql IMMUTABLE;
|
||||
|
||||
CREATE FUNCTION gms_debug.break_handler() RETURNS int AS $$
|
||||
BEGIN
|
||||
return 64;
|
||||
END;
|
||||
$$ language plpgsql IMMUTABLE;
|
||||
|
||||
CREATE FUNCTION gms_debug.abort_execution() RETURNS int AS $$
|
||||
BEGIN
|
||||
return 128;
|
||||
END;
|
||||
$$ language plpgsql IMMUTABLE;
|
||||
|
||||
CREATE FUNCTION gms_debug.reason_none() RETURNS int AS $$
|
||||
BEGIN
|
||||
return 0;
|
||||
END;
|
||||
$$ language plpgsql IMMUTABLE;
|
||||
|
||||
CREATE FUNCTION gms_debug.reason_breakpoint() RETURNS int AS $$
|
||||
BEGIN
|
||||
return 1;
|
||||
END;
|
||||
$$ language plpgsql IMMUTABLE;
|
||||
|
||||
CREATE FUNCTION gms_debug.reason_enter() RETURNS int AS $$
|
||||
BEGIN
|
||||
return 2;
|
||||
END;
|
||||
$$ language plpgsql IMMUTABLE;
|
||||
|
||||
CREATE FUNCTION gms_debug.reason_return() RETURNS int AS $$
|
||||
BEGIN
|
||||
return 3;
|
||||
END;
|
||||
$$ language plpgsql IMMUTABLE;
|
||||
|
||||
CREATE FUNCTION gms_debug.reason_finish() RETURNS int AS $$
|
||||
BEGIN
|
||||
return 4;
|
||||
END;
|
||||
$$ language plpgsql IMMUTABLE;
|
||||
|
||||
CREATE FUNCTION gms_debug.reason_line() RETURNS int AS $$
|
||||
BEGIN
|
||||
return 5;
|
||||
END;
|
||||
$$ language plpgsql IMMUTABLE;
|
||||
|
||||
CREATE FUNCTION gms_debug.reason_interrupt() RETURNS int AS $$
|
||||
BEGIN
|
||||
return 6;
|
||||
END;
|
||||
$$ language plpgsql IMMUTABLE;
|
||||
|
||||
CREATE FUNCTION gms_debug.reason_exception() RETURNS int AS $$
|
||||
BEGIN
|
||||
return 7;
|
||||
END;
|
||||
$$ language plpgsql IMMUTABLE;
|
||||
|
||||
CREATE FUNCTION gms_debug.reason_exit() RETURNS int AS $$
|
||||
BEGIN
|
||||
return 8;
|
||||
END;
|
||||
$$ language plpgsql IMMUTABLE;
|
||||
|
||||
CREATE FUNCTION gms_debug.reason_knl_exit() RETURNS int AS $$
|
||||
BEGIN
|
||||
return 9;
|
||||
END;
|
||||
$$ language plpgsql IMMUTABLE;
|
||||
|
||||
CREATE FUNCTION gms_debug.reason_handler() RETURNS int AS $$
|
||||
BEGIN
|
||||
return 10;
|
||||
END;
|
||||
$$ language plpgsql IMMUTABLE;
|
||||
|
||||
CREATE FUNCTION gms_debug.reason_timeout() RETURNS int AS $$
|
||||
BEGIN
|
||||
return 11;
|
||||
END;
|
||||
$$ language plpgsql IMMUTABLE;
|
||||
|
||||
CREATE FUNCTION gms_debug.reason_instantiate() RETURNS int AS $$
|
||||
BEGIN
|
||||
return 12;
|
||||
END;
|
||||
$$ language plpgsql IMMUTABLE;
|
||||
|
||||
CREATE FUNCTION gms_debug.reason_abort() RETURNS int AS $$
|
||||
BEGIN
|
||||
return 13;
|
||||
END;
|
||||
$$ language plpgsql IMMUTABLE;
|
||||
|
||||
|
||||
|
||||
|
||||
-- gms_debug package end
|
||||
5
contrib/gms_debug/gms_debug.control
Normal file
5
contrib/gms_debug/gms_debug.control
Normal file
@ -0,0 +1,5 @@
|
||||
# gms_debug extension
|
||||
comment = 'provides the interface to initiate and control the debugging of PL/SQL applications'
|
||||
default_version = '1.0'
|
||||
module_pathname = '$libdir/gms_debug'
|
||||
relocatable = true
|
||||
519
contrib/gms_debug/gms_debug.cpp
Normal file
519
contrib/gms_debug/gms_debug.cpp
Normal file
@ -0,0 +1,519 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Technologies Co.,Ltd.
|
||||
*
|
||||
* openGauss is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
*
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
* --------------------------------------------------------------------------------------
|
||||
*
|
||||
* gms_debug.cpp
|
||||
* gms_debug can effectively estimate statistical data.
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* contrib/gms_debug/gms_debug.cpp
|
||||
*
|
||||
* --------------------------------------------------------------------------------------
|
||||
*/
|
||||
#include "postgres.h"
|
||||
#include "utils/plpgsql_domain.h"
|
||||
#include "commands/copy.h"
|
||||
#include "funcapi.h"
|
||||
#include "utils/plpgsql.h"
|
||||
#include <sys/socket.h>
|
||||
#include "utils/pl_debug.h"
|
||||
#include "lib/stringinfo.h"
|
||||
#include "utils/builtins.h"
|
||||
#include "utils/fmgroids.h"
|
||||
#include "utils/lsyscache.h"
|
||||
#include "catalog/pg_authid.h"
|
||||
#include "miscadmin.h"
|
||||
#include "gms_debug.h"
|
||||
|
||||
#include <bitset>
|
||||
|
||||
PG_MODULE_MAGIC;
|
||||
|
||||
PG_FUNCTION_INFO_V1(gms_debug_attach_session);
|
||||
PG_FUNCTION_INFO_V1(gms_debug_detach_session);
|
||||
PG_FUNCTION_INFO_V1(gms_debug_get_runtime_info);
|
||||
PG_FUNCTION_INFO_V1(gms_debug_initialize);
|
||||
PG_FUNCTION_INFO_V1(gms_debug_off);
|
||||
PG_FUNCTION_INFO_V1(gms_debug_continue);
|
||||
PG_FUNCTION_INFO_V1(gms_debug_set_breakpoint);
|
||||
|
||||
|
||||
static void gms_attach_session(int commidx, uint64 sid)
|
||||
{
|
||||
PlDebuggerComm* debug_comm = &g_instance.pldebug_cxt.debug_comm[commidx];
|
||||
AutoMutexLock debuglock(&debug_comm->mutex);
|
||||
debuglock.lock();
|
||||
if (debug_comm->Used()) {
|
||||
if (debug_comm->hasClient()) {
|
||||
debuglock.unLock();
|
||||
ereport(ERROR, (errmodule(MOD_PLDEBUGGER), errcode(ERRCODE_TARGET_SERVER_ALREADY_ATTACHED),
|
||||
(errmsg("target session already attached on other client."))));
|
||||
}
|
||||
if (debug_comm->hasClientErrorOccured || debug_comm->hasServerErrorOccured) {
|
||||
debuglock.unLock();
|
||||
ereport(ERROR, (errmodule(MOD_PLDEBUGGER), errcode(ERRCODE_INVALID_OPERATION),
|
||||
(errmsg("target function is not running in expected way."))));
|
||||
}
|
||||
debug_comm->clientId = sid;
|
||||
} else {
|
||||
debuglock.unLock();
|
||||
ereport(ERROR, (errmodule(MOD_PLDEBUGGER), errcode(ERRCODE_INVALID_OPERATION),
|
||||
(errmsg("target session should be init first."))));
|
||||
}
|
||||
debuglock.unLock();
|
||||
}
|
||||
|
||||
static bool GMSInterfaceCheck(const char* funcname, bool needAttach)
|
||||
{
|
||||
#ifdef ENABLE_MULTIPLE_NODES
|
||||
PLDEBUG_FEATURE_NOT_SUPPORT_IN_DISTRIBUTED();
|
||||
#endif
|
||||
if (!superuser() && !is_member_of_role(GetUserId(), DEFAULT_ROLE_PLDEBUGGER)) {
|
||||
ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
|
||||
(errmsg("must be system admin to execute", funcname))));
|
||||
return false;
|
||||
}
|
||||
if (u_sess->plsql_cxt.debug_client != NULL && needAttach){
|
||||
int commIdx = u_sess->plsql_cxt.debug_client->comm_idx;
|
||||
CHECK_DEBUG_COMM_VALID(commIdx);
|
||||
/* if current debug index is not myself during debug, clean up my self */
|
||||
PlDebuggerComm* debug_comm = &g_instance.pldebug_cxt.debug_comm[commIdx];
|
||||
DebugClientInfo* client = u_sess->plsql_cxt.debug_client;
|
||||
AutoMutexLock debuglock(&debug_comm->mutex);
|
||||
debuglock.lock();
|
||||
if (debug_comm == nullptr) {
|
||||
client->comm_idx = -1;
|
||||
MemoryContextDelete(client->context);
|
||||
u_sess->plsql_cxt.debug_client = NULL;
|
||||
debuglock.unLock();
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_TARGET_SERVER_NOT_ATTACHED),
|
||||
errmsg("must attach a execute func before execute", funcname),
|
||||
errhint("attach a execute func and retry")));
|
||||
return false;
|
||||
}
|
||||
if (!debug_comm->isRunning()) {
|
||||
debuglock.unLock();
|
||||
return false;
|
||||
}
|
||||
debuglock.unLock();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* This function initializes the target session for debugging.
|
||||
*/
|
||||
Datum gms_debug_initialize(PG_FUNCTION_ARGS)
|
||||
{
|
||||
StringInfoData buf;
|
||||
bool found = false;
|
||||
// TupleDesc tupdesc;
|
||||
int commIdx = -1;
|
||||
const int DEBUG_TURN_ON_ATTR_NUM = 1;
|
||||
GMSInterfaceCheck("gms_debug.initialize", false);
|
||||
if (unlikely(u_sess->plsql_cxt.debug_proc_htbl == NULL)) {
|
||||
init_pldebug_htcl();
|
||||
}
|
||||
/* return nodename & socket idx as port */
|
||||
if (!PG_ARGISNULL(0)) {
|
||||
// check if the debug_session_id valid
|
||||
char *debug_session_id = text_to_cstring(PG_GETARG_VARCHAR_PP(0));
|
||||
char *psave = NULL;
|
||||
char *nodename = strtok_r(debug_session_id, "-", &psave);
|
||||
char *fir = AssignStr(psave, false);
|
||||
char *new_fir = TrimStr(fir);
|
||||
if (new_fir == NULL) {
|
||||
ereport(ERROR, ( (errmsg("invalid debug_session_id %s", debug_session_id))));
|
||||
}
|
||||
commIdx = pg_strtoint32(new_fir);
|
||||
if (commIdx < 0 || commIdx >= PG_MAX_DEBUG_CONN) {
|
||||
ereport(ERROR, ( (errmsg("invalid debug_session_id %s", debug_session_id))));
|
||||
}
|
||||
if (!AcquireDebugCommIdx(commIdx)) {
|
||||
ereport(ERROR,
|
||||
( errmsg("debug_session_id %s has already been used", debug_session_id)));
|
||||
}
|
||||
} else {
|
||||
commIdx = GetValidDebugCommIdx();
|
||||
if (commIdx == -1) {
|
||||
ereport(ERROR, (
|
||||
(errmsg("max debug function is %d, turn_on function is out of range", PG_MAX_DEBUG_CONN))));
|
||||
}
|
||||
}
|
||||
|
||||
SetDebugCommGmsUsed(commIdx, true);
|
||||
// dms_debug indicates that session debugging functionality should be enabled.
|
||||
u_sess->plsql_cxt.gms_debug_idx = commIdx;
|
||||
initStringInfo(&buf);
|
||||
// simple concatenate node_name and port with an underscore
|
||||
appendStringInfo(&buf, "%s-%d", g_instance.attr.attr_common.PGXCNodeName, commIdx);
|
||||
PG_RETURN_VARCHAR_P(cstring_to_text(buf.data));
|
||||
}
|
||||
|
||||
/*
|
||||
* This procedure notifies the debug session about the target program.
|
||||
*/
|
||||
Datum gms_debug_attach_session(PG_FUNCTION_ARGS)
|
||||
{
|
||||
GMSInterfaceCheck("gms_debug.attach_session", false);
|
||||
char *debug_session_id = text_to_cstring(PG_GETARG_VARCHAR_PP(0));
|
||||
int32 diagnostics = PG_GETARG_INT32(1);
|
||||
char *psave = NULL;
|
||||
int commidx = -1;
|
||||
char *nodename = strtok_r(debug_session_id, "-", &psave);
|
||||
char *fir = AssignStr(psave, false);
|
||||
char *new_fir = TrimStr(fir);
|
||||
if (new_fir == NULL) {
|
||||
ereport(ERROR, ( (errmsg("invalid debug_session_id %s", debug_session_id))));
|
||||
}
|
||||
commidx = pg_strtoint32(new_fir);
|
||||
|
||||
/* if is attach to some other function, just clean up it */
|
||||
clean_up_debug_client(true);
|
||||
/* this nodename check is only for single node */
|
||||
nodename = TrimStr(nodename);
|
||||
if (nodename == NULL || strcasecmp(nodename, g_instance.attr.attr_common.PGXCNodeName) != 0) {
|
||||
ereport(ERROR, ( errcode(ERRCODE_AMBIGUOUS_PARAMETER),
|
||||
(errmsg("wrong debug nodename, should be %s.", g_instance.attr.attr_common.PGXCNodeName))));
|
||||
}
|
||||
if (commidx < 0 || commidx >= PG_MAX_DEBUG_CONN) {
|
||||
ereport(ERROR, ( errcode(ERRCODE_AMBIGUOUS_PARAMETER),
|
||||
(errmsg("invalid debug port id %d.", commidx))));
|
||||
}
|
||||
/* only can attach when comm satisfy contidion */
|
||||
gms_attach_session(commidx, u_sess->session_id);
|
||||
u_sess->plsql_cxt.debug_client = InitDebugClient(commidx);
|
||||
PG_RETURN_VOID();
|
||||
}
|
||||
|
||||
/**
|
||||
* This function sets a breakpoint in a program unit, which persists for the current session.
|
||||
*/
|
||||
Datum gms_debug_set_breakpoint(PG_FUNCTION_ARGS)
|
||||
{
|
||||
const int DEBUG_BREAK_TUPLE_ATTR_NUM = 2;
|
||||
Oid funcOid = PG_GETARG_OID(0);
|
||||
int32 lineno = PG_GETARG_INT32(1);
|
||||
int32 fuzzy = PG_GETARG_INT32(2);
|
||||
int32 iterations = PG_GETARG_INT32(3);
|
||||
int headerlines = 0;
|
||||
uint32 nLine = 0;
|
||||
CodeLine *lines = NULL;
|
||||
CodeLine cl;
|
||||
cl.code = NULL;
|
||||
bool found = false;
|
||||
DebugClientInfo *client = u_sess->plsql_cxt.debug_client;
|
||||
StringInfoData str;
|
||||
|
||||
if(client == nullptr) {
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_TARGET_SERVER_NOT_ATTACHED),
|
||||
errmsg("error happened in debug session, please reattach target session and try")));
|
||||
}
|
||||
|
||||
TupleDesc tupdesc;
|
||||
MemoryContext oldcontext = MemoryContextSwitchTo(client->context);
|
||||
|
||||
tupdesc = CreateTemplateTupleDesc(DEBUG_BREAK_TUPLE_ATTR_NUM, false);
|
||||
TupleDescInitEntry(tupdesc, (AttrNumber)1, "status", INT4OID, -1, 0);
|
||||
TupleDescInitEntry(tupdesc, (AttrNumber)2, "breakpoint", INT4OID, -1, 0);
|
||||
TupleDesc tuple_desc = BlessTupleDesc(tupdesc);
|
||||
|
||||
Datum values[DEBUG_BREAK_TUPLE_ATTR_NUM];
|
||||
bool nulls[DEBUG_BREAK_TUPLE_ATTR_NUM];
|
||||
HeapTuple tuple;
|
||||
errno_t rc = 0;
|
||||
|
||||
rc = memset_s(values, sizeof(values), 0, sizeof(values));
|
||||
securec_check(rc, "\0", "\0");
|
||||
rc = memset_s(nulls, sizeof(nulls), 0, sizeof(nulls));
|
||||
securec_check(rc, "\0", "\0");
|
||||
|
||||
(void)MemoryContextSwitchTo(oldcontext);
|
||||
|
||||
values[0] = Int32GetDatum(0);
|
||||
values[1] = Int32GetDatum(-1);
|
||||
if (OidIsValid(funcOid)) {
|
||||
bool checked = GMSInterfaceCheck("gms_debug.add_breakpoint", true);
|
||||
if(!checked) {
|
||||
ereport(WARNING,
|
||||
(errcode(ERRCODE_TARGET_SERVER_NOT_ATTACHED),
|
||||
errmsg("target func not attached")));
|
||||
values[0] = Int32GetDatum(ERROR_BAD_HANDLE);
|
||||
tuple = heap_form_tuple(tuple_desc, values, nulls);
|
||||
PG_RETURN_DATUM(HeapTupleGetDatum(tuple));
|
||||
}
|
||||
} else {
|
||||
ereport(WARNING, (errcode(ERRCODE_WRONG_OBJECT_TYPE),
|
||||
errmsg("pl debugger only support function with language plpgsql"),
|
||||
errdetail("the given function is %lu", funcOid),
|
||||
errcause("pl debugger do not support the given function"),
|
||||
erraction("use pl debugger with only plpgsql function")));
|
||||
values[0] = Int32GetDatum(ERROR_BAD_HANDLE);
|
||||
tuple = heap_form_tuple(tuple_desc, values, nulls);
|
||||
PG_RETURN_DATUM(HeapTupleGetDatum(tuple));
|
||||
}
|
||||
|
||||
if (unlikely(u_sess->plsql_cxt.debug_proc_htbl == NULL)) {
|
||||
init_pldebug_htcl();
|
||||
}
|
||||
|
||||
PlDebugEntry *entry =
|
||||
(PlDebugEntry *)hash_search(u_sess->plsql_cxt.debug_proc_htbl, (void *)(&funcOid), HASH_ENTER, &found);
|
||||
entry->key = funcOid;
|
||||
if (!found) {
|
||||
entry->commIdx = client->comm_idx;
|
||||
entry->func = NULL;
|
||||
}
|
||||
initStringInfo(&str);
|
||||
uint64 sid = ENABLE_THREAD_POOL ? u_sess->session_id : t_thrd.proc_cxt.MyProcPid;
|
||||
appendStringInfo(&str, "%lu:%u:%d:%s", sid, funcOid, lineno, cl.code == NULL ? "NULL" : cl.code);
|
||||
debug_client_send_msg(client, GMS_DEBUG_ADDBREAKPOINT_HEADER, str.data, str.len);
|
||||
debug_client_rec_msg(client);
|
||||
int32 ans = pg_strtoint32(client->rec_buffer);
|
||||
pfree_ext(lines);
|
||||
pfree_ext(str.data);
|
||||
|
||||
if (ans == ADD_BP_ERR_ALREADY_EXISTS) {
|
||||
ereport(WARNING, (errcode(ERRCODE_WARNING),
|
||||
errmsg("the given line number already contains a valid breakpoint.")));
|
||||
values[0] = Int32GetDatum(ERROR_ALREADY_EXISTS);
|
||||
tuple = heap_form_tuple(tuple_desc, values, nulls);
|
||||
PG_RETURN_DATUM(HeapTupleGetDatum(tuple));
|
||||
} else if (ans == ADD_BP_ERR_OUT_OF_RANGE) {
|
||||
ereport(WARNING, (errcode(ERRCODE_WARNING),
|
||||
errmsg("lineno must be within the range of [1, MaxLineNumber]." )));
|
||||
values[0] = Int32GetDatum(ERROR_ILLEGAL_LINE);
|
||||
tuple = heap_form_tuple(tuple_desc, values, nulls);
|
||||
PG_RETURN_DATUM(HeapTupleGetDatum(tuple));
|
||||
} else if (ans == ADD_BP_ERR_INVALID_BP_POS) {
|
||||
ereport(WARNING, (errcode(ERRCODE_WARNING),
|
||||
errmsg("the given line number does not name a valid breakpoint.")));
|
||||
values[0] = Int32GetDatum(ERROR_ILLEGAL_LINE);
|
||||
tuple = heap_form_tuple(tuple_desc, values, nulls);
|
||||
PG_RETURN_DATUM(HeapTupleGetDatum(tuple));
|
||||
}
|
||||
values[0] = Int32GetDatum(0);
|
||||
values[1] = Int32GetDatum(ans);
|
||||
tuple = heap_form_tuple(tuple_desc, values, nulls);
|
||||
PG_RETURN_DATUM(HeapTupleGetDatum(tuple));
|
||||
}
|
||||
|
||||
static char* parse_and_valid(char **psave, const char* rec_buf)
|
||||
{
|
||||
char *fir = strtok_r(NULL, ":", psave);
|
||||
char *new_fir = TrimStr(fir);
|
||||
if (new_fir == NULL) {
|
||||
ReportInvalidMsg(rec_buf);
|
||||
return NULL;
|
||||
}
|
||||
return new_fir;
|
||||
}
|
||||
|
||||
static Datum build_runtime_info(DebugClientInfo *client, int err_code)
|
||||
{
|
||||
const int DEBUG_RUNTIME_TUPLE_ATTR_NUM = 8;
|
||||
int i = 0;
|
||||
TupleDesc tupdesc;
|
||||
MemoryContext oldcontext = MemoryContextSwitchTo(client->context);
|
||||
|
||||
tupdesc = CreateTemplateTupleDesc(DEBUG_RUNTIME_TUPLE_ATTR_NUM, false);
|
||||
TupleDescInitEntry(tupdesc, (AttrNumber)++i, "err_code", INT4OID, -1, 0);
|
||||
TupleDescInitEntry(tupdesc, (AttrNumber)++i, "run_line", INT4OID, -1, 0);
|
||||
TupleDescInitEntry(tupdesc, (AttrNumber)++i, "run_breakpoint", INT4OID, -1, 0);
|
||||
TupleDescInitEntry(tupdesc, (AttrNumber)++i, "run_stackdepth", INT4OID, -1, 0);
|
||||
TupleDescInitEntry(tupdesc, (AttrNumber)++i, "run_reason", INT4OID, -1, 0);
|
||||
TupleDescInitEntry(tupdesc, (AttrNumber)++i, "pro_namespace", OIDOID, -1, 0);
|
||||
TupleDescInitEntry(tupdesc, (AttrNumber)++i, "pro_name", TEXTOID, -1, 0);
|
||||
TupleDescInitEntry(tupdesc, (AttrNumber)++i, "pro_owner", OIDOID, -1, 0);
|
||||
TupleDesc tuple_desc = BlessTupleDesc(tupdesc);
|
||||
|
||||
/* Received buffer will be in the form of <namespaceoid, owneroid, lineno, breakpoint, stackdepth, reason,
|
||||
* pkgfuncname> */
|
||||
char *psave = NULL;
|
||||
char *fir = strtok_r(client->rec_buffer, ":", &psave);
|
||||
const int int64Size = 10;
|
||||
Oid namespaceoid;
|
||||
Oid funcoid;
|
||||
Oid owneroid;
|
||||
int run_line = -1;
|
||||
int run_breakpoint = -1;
|
||||
int run_stackdepth = -1;
|
||||
int run_reason = 0;
|
||||
char *pro_name = NULL;
|
||||
Datum values[DEBUG_RUNTIME_TUPLE_ATTR_NUM];
|
||||
bool nulls[DEBUG_RUNTIME_TUPLE_ATTR_NUM];
|
||||
HeapTuple tuple;
|
||||
errno_t rc = 0;
|
||||
|
||||
if(err_code == 0) {
|
||||
char *new_fir = TrimStr(fir);
|
||||
if (new_fir == NULL) {
|
||||
ReportInvalidMsg(client->rec_buffer);
|
||||
PG_RETURN_DATUM(0);
|
||||
}
|
||||
funcoid = (Oid)pg_strtouint64(new_fir, NULL, int64Size);
|
||||
new_fir = parse_and_valid(&psave, client->rec_buffer);
|
||||
CHECK_RETURN_DATUM(new_fir);
|
||||
namespaceoid = (Oid)pg_strtouint64(new_fir, NULL, int64Size);
|
||||
new_fir = parse_and_valid(&psave, client->rec_buffer);
|
||||
CHECK_RETURN_DATUM(new_fir);
|
||||
owneroid = (Oid)pg_strtouint64(new_fir, NULL, int64Size);
|
||||
new_fir = parse_and_valid(&psave, client->rec_buffer);
|
||||
CHECK_RETURN_DATUM(new_fir);
|
||||
run_line = pg_strtoint32(new_fir);
|
||||
new_fir = parse_and_valid(&psave, client->rec_buffer);
|
||||
CHECK_RETURN_DATUM(new_fir);
|
||||
run_breakpoint = pg_strtoint32(new_fir);
|
||||
new_fir = parse_and_valid(&psave, client->rec_buffer);
|
||||
CHECK_RETURN_DATUM(new_fir);
|
||||
run_stackdepth = pg_strtoint32(new_fir);
|
||||
new_fir = parse_and_valid(&psave, client->rec_buffer);
|
||||
CHECK_RETURN_DATUM(new_fir);
|
||||
run_reason = pg_strtoint32(new_fir);
|
||||
pro_name = AssignStr(psave, false);
|
||||
}
|
||||
|
||||
(void)MemoryContextSwitchTo(oldcontext);
|
||||
|
||||
rc = memset_s(values, sizeof(values), 0, sizeof(values));
|
||||
securec_check(rc, "\0", "\0");
|
||||
rc = memset_s(nulls, sizeof(nulls), 0, sizeof(nulls));
|
||||
securec_check(rc, "\0", "\0");
|
||||
|
||||
i = 0;
|
||||
values[i++] = Int32GetDatum(err_code);
|
||||
values[i++] = Int32GetDatum(run_line);
|
||||
values[i++] = Int32GetDatum(run_breakpoint);
|
||||
values[i++] = Int32GetDatum(run_stackdepth);
|
||||
values[i++] = Int32GetDatum(run_reason);
|
||||
values[i++] = ObjectIdGetDatum(namespaceoid);
|
||||
values[i++] = CStringGetTextDatum(pro_name);
|
||||
values[i++] = ObjectIdGetDatum(owneroid);
|
||||
tuple = heap_form_tuple(tuple_desc, values, nulls);
|
||||
PG_RETURN_DATUM(HeapTupleGetDatum(tuple));
|
||||
}
|
||||
|
||||
/**
|
||||
* This function passes the given breakflags
|
||||
* (a mask of the events that are of interest) to Probe in the target process.
|
||||
* It tells Probe to continue execution of the target process,
|
||||
* and it waits until the target process runs to completion or signals an event.
|
||||
* If info_requested is not NULL, then calls GET_RUNTIME_INFO.
|
||||
*/
|
||||
Datum gms_debug_continue(PG_FUNCTION_ARGS)
|
||||
{
|
||||
DebugClientInfo *client = u_sess->plsql_cxt.debug_client;
|
||||
if(client == nullptr) {
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_TARGET_SERVER_NOT_ATTACHED),
|
||||
errmsg("error happened in debug session, please reattach target session and try")));
|
||||
}
|
||||
const int DEBUG_ACTION_ATTR_NUM = 5;
|
||||
const char actions[DEBUG_ACTION_ATTR_NUM] = {
|
||||
GMS_DEBUG_CONTINUE_HEADER,
|
||||
GMS_DEBUG_NEXT_HEADER,
|
||||
GMS_DEBUG_STEP_INTO_HEADER,
|
||||
GMS_DEBUG_FINISH_HEADER,
|
||||
GMS_DEBUG_ABORT_HEADER
|
||||
};
|
||||
int err_code = 0;
|
||||
bool checked = GMSInterfaceCheck("gms_debug.continue", true);
|
||||
if(!checked) {
|
||||
ereport(WARNING,
|
||||
(errcode(ERRCODE_TARGET_SERVER_NOT_ATTACHED),
|
||||
errmsg("target func not attached")));
|
||||
err_code = ERROR_FUNC_NOT_ATTACHED;
|
||||
return build_runtime_info(client,err_code);
|
||||
}
|
||||
int32 breakflags = PG_GETARG_INT32(0);
|
||||
int32 info_requested = PG_GETARG_INT32(1);
|
||||
char action;
|
||||
std::bitset<DEBUG_ACTION_ATTR_NUM> breakflags_bitset(breakflags);
|
||||
for (int i = 0; i < breakflags_bitset.size(); ++i) {
|
||||
if (breakflags_bitset.test(i)) {
|
||||
action = actions[i];
|
||||
}
|
||||
}
|
||||
debug_client_send_msg(client, action, NULL, 0);
|
||||
debug_client_rec_msg(client);
|
||||
return build_runtime_info(client,err_code);
|
||||
}
|
||||
|
||||
/***
|
||||
* This function returns information about the current program.
|
||||
* It is only needed if the info_requested parameter to SYNCHRONIZE
|
||||
* or CONTINUE was set to 0.
|
||||
*/
|
||||
Datum gms_debug_get_runtime_info(PG_FUNCTION_ARGS)
|
||||
{
|
||||
int err_code = 0;
|
||||
DebugClientInfo *client = u_sess->plsql_cxt.debug_client;
|
||||
if(client == nullptr) {
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_TARGET_SERVER_NOT_ATTACHED),
|
||||
errmsg("error happened in debug session, please reattach target session and try")));
|
||||
}
|
||||
bool checked = GMSInterfaceCheck("gms_debug.runtime_info",true);
|
||||
if(!checked) {
|
||||
ereport(WARNING,
|
||||
(errcode(ERRCODE_TARGET_SERVER_NOT_ATTACHED),
|
||||
errmsg("target func not attached")));
|
||||
err_code = ERROR_FUNC_NOT_ATTACHED;
|
||||
return build_runtime_info(client, err_code);
|
||||
}
|
||||
int32 info_requested = PG_GETARG_INT32(0);
|
||||
debug_client_send_msg(client, GMS_DEBUG_RUNTIMEINFO_HEADER, NULL, 0);
|
||||
debug_client_rec_msg(client);
|
||||
return build_runtime_info(client, err_code);
|
||||
}
|
||||
|
||||
/***
|
||||
* This procedure notifies the target session that
|
||||
* debugging should no longer take place in that session.
|
||||
* It is not necessary to call this function before ending the session.
|
||||
*/
|
||||
Datum gms_debug_off(PG_FUNCTION_ARGS)
|
||||
{
|
||||
GMSInterfaceCheck("gms_debug.debug_off",false);
|
||||
// dms_debug indicates that session debugging functionality should be enabled.
|
||||
SetDebugCommGmsUsed(u_sess->plsql_cxt.gms_debug_idx, false);
|
||||
u_sess->plsql_cxt.gms_debug_idx = -1;
|
||||
|
||||
PG_RETURN_VOID();
|
||||
}
|
||||
|
||||
/***
|
||||
* This procedure stops debugging the target program.
|
||||
* This procedure may be called at any time,
|
||||
* but it does not notify the target session that the debug session is detaching itself,
|
||||
* and it does not terminate execution of the target session.
|
||||
* Therefore, care should be taken to ensure that the target session does not hang itself.
|
||||
*/
|
||||
Datum gms_debug_detach_session(PG_FUNCTION_ARGS)
|
||||
{
|
||||
DebugClientInfo *client = u_sess->plsql_cxt.debug_client;
|
||||
if(client == nullptr) {
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_TARGET_SERVER_NOT_ATTACHED),
|
||||
errmsg("error happened in debug session, please reattach target session and try")));
|
||||
}
|
||||
GMSInterfaceCheck("gms_debug.detach_session",true);
|
||||
debug_client_send_msg(client, DEBUG_ABORT_HEADER, NULL, 0);
|
||||
debug_client_rec_msg(client);
|
||||
clean_up_debug_client();
|
||||
PG_RETURN_VOID();
|
||||
}
|
||||
46
contrib/gms_debug/gms_debug.h
Normal file
46
contrib/gms_debug/gms_debug.h
Normal file
@ -0,0 +1,46 @@
|
||||
/*---------------------------------------------------------------------------------------*
|
||||
* gms_debug.h
|
||||
*
|
||||
* Definition about gms_debug package.
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* contrib/gms_debug/gms_debug.h
|
||||
*
|
||||
* ---------------------------------------------------------------------------------------
|
||||
*/
|
||||
#ifndef GMS_DEBUG_H
|
||||
#define GMS_DEBUG_H
|
||||
|
||||
#define BREAK_NEXT_LINE 2
|
||||
#define BREAK_ANY_CALL 4
|
||||
#define BREAK_ANY_RETURN 8
|
||||
#define BREAK_RETURN 16
|
||||
#define BREAK_EXCEPTION 32
|
||||
#define BREAK_HANDLER 64
|
||||
#define BREAK_ABORT_EXECUTION 128
|
||||
|
||||
#define ERROR_ILLEGAL_LINE -1
|
||||
#define ERROR_BAD_HANDLE -2
|
||||
#define ERROR_ALREADY_EXISTS -3
|
||||
#define ERROR_COMMUNICATION -4
|
||||
#define ERROR_FUNC_NOT_ATTACHED -9
|
||||
|
||||
/* from gms_debug.cpp */
|
||||
extern "C" Datum gms_debug_attach_session(PG_FUNCTION_ARGS);
|
||||
extern "C" Datum gms_debug_detach_session(PG_FUNCTION_ARGS);
|
||||
extern "C" Datum gms_debug_get_runtime_info(PG_FUNCTION_ARGS);
|
||||
extern "C" Datum gms_debug_probe_version(PG_FUNCTION_ARGS);
|
||||
extern "C" Datum gms_debug_initialize(PG_FUNCTION_ARGS);
|
||||
extern "C" Datum gms_debug_on(PG_FUNCTION_ARGS);
|
||||
extern "C" Datum gms_debug_off(PG_FUNCTION_ARGS);
|
||||
extern "C" Datum gms_debug_continue(PG_FUNCTION_ARGS);
|
||||
extern "C" Datum gms_debug_set_breakpoint(PG_FUNCTION_ARGS);
|
||||
|
||||
|
||||
#define CHECK_RETURN_DATUM(mask_string) \
|
||||
do { \
|
||||
if (mask_string == NULL) \
|
||||
PG_RETURN_DATUM(0); \
|
||||
} while (0)
|
||||
|
||||
#endif
|
||||
138
contrib/gms_debug/sql/gms_debugger_client1.sql
Normal file
138
contrib/gms_debug/sql/gms_debugger_client1.sql
Normal file
@ -0,0 +1,138 @@
|
||||
-- wait for server establishment
|
||||
|
||||
CREATE OR REPLACE FUNCTION wait_for_gms_debug_extension()
|
||||
RETURNS BOOLEAN AS $$
|
||||
DECLARE
|
||||
extension_exists BOOLEAN;
|
||||
BEGIN
|
||||
-- 初始化变量
|
||||
extension_exists := FALSE;
|
||||
|
||||
-- 循环查询扩展是否存在
|
||||
WHILE NOT extension_exists LOOP
|
||||
-- 查询扩展是否存在
|
||||
PERFORM 1 FROM pg_extension WHERE extname = 'gms_debug';
|
||||
IF FOUND THEN
|
||||
-- 如果扩展存在,则退出循环
|
||||
extension_exists := TRUE;
|
||||
ELSE
|
||||
-- 如果扩展不存在,则等待一段时间再重试
|
||||
PERFORM pg_sleep(1); -- 等待1秒
|
||||
END IF;
|
||||
END LOOP;
|
||||
|
||||
-- 返回扩展存在的标志
|
||||
RETURN extension_exists;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
DO $$
|
||||
BEGIN
|
||||
IF wait_for_gms_debug_extension() THEN
|
||||
-- 扩展存在,执行下一步操作
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
set search_path = gms_debugger_test1;
|
||||
|
||||
CREATE or REPLACE FUNCTION gms_breakpoint(funcname text, lineno int)
|
||||
returns void as $$
|
||||
declare
|
||||
pro_info gms_debug.program_info;
|
||||
bkline binary_integer;
|
||||
ret binary_integer;
|
||||
begin
|
||||
pro_info.name := funcname;
|
||||
ret := gms_debug.set_breakpoint(pro_info, lineno, bkline,1,1);
|
||||
RAISE NOTICE 'ret= %', ret;
|
||||
RAISE NOTICE 'ret= %', bkline;
|
||||
end;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
CREATE or REPLACE FUNCTION gms_continue()
|
||||
returns void as $$
|
||||
declare
|
||||
run_info gms_debug.runtime_info;
|
||||
ret binary_integer;
|
||||
begin
|
||||
ret := gms_debug.continue(run_info, 0, 2);
|
||||
RAISE NOTICE 'breakpoint= %', run_info.breakpoint;
|
||||
RAISE NOTICE 'stackdepth= %', run_info.stackdepth;
|
||||
RAISE NOTICE 'line= %', run_info.line#;
|
||||
RAISE NOTICE 'reason= %', run_info.reason;
|
||||
RAISE NOTICE 'ret= %',ret;
|
||||
end;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
CREATE or REPLACE FUNCTION gms_next()
|
||||
returns void as $$
|
||||
declare
|
||||
run_info gms_debug.runtime_info;
|
||||
ret binary_integer;
|
||||
begin
|
||||
ret := gms_debug.continue(run_info, 2, 2);
|
||||
RAISE NOTICE 'breakpoint= %', run_info.breakpoint;
|
||||
RAISE NOTICE 'stackdepth= %', run_info.stackdepth;
|
||||
RAISE NOTICE 'line= %', run_info.line#;
|
||||
RAISE NOTICE 'reason= %', run_info.reason;
|
||||
RAISE NOTICE 'ret= %',ret;
|
||||
end;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
CREATE or REPLACE FUNCTION gms_step()
|
||||
returns void as $$
|
||||
declare
|
||||
run_info gms_debug.runtime_info;
|
||||
ret binary_integer;
|
||||
begin
|
||||
ret := gms_debug.continue(run_info, 4, 2);
|
||||
RAISE NOTICE 'breakpoint= %', run_info.breakpoint;
|
||||
RAISE NOTICE 'stackdepth= %', run_info.stackdepth;
|
||||
RAISE NOTICE 'line= %', run_info.line#;
|
||||
RAISE NOTICE 'reason= %', run_info.reason;
|
||||
RAISE NOTICE 'ret= %',ret;
|
||||
end;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
|
||||
CREATE or REPLACE FUNCTION gms_info()
|
||||
returns void as $$
|
||||
declare
|
||||
run_info gms_debug.runtime_info;
|
||||
ret binary_integer;
|
||||
begin
|
||||
ret := gms_debug.get_runtime_info(1, run_info);
|
||||
RAISE NOTICE 'breakpoint= %', run_info.breakpoint;
|
||||
RAISE NOTICE 'stackdepth= %', run_info.stackdepth;
|
||||
RAISE NOTICE 'line= %', run_info.line#;
|
||||
RAISE NOTICE 'reason= %', run_info.reason;
|
||||
RAISE NOTICE 'ret= %',ret;
|
||||
end;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
-- attach debug server
|
||||
select * from gms_debug.attach_session('datanode1-0');
|
||||
|
||||
select pg_sleep(3);
|
||||
|
||||
select gms_breakpoint('test_debug', 0); -- negative
|
||||
|
||||
select gms_breakpoint('test_debug', 15); -- ok
|
||||
|
||||
select gms_breakpoint('test_debug', 17); -- invalid
|
||||
select gms_breakpoint('test_debug', 22); -- ok
|
||||
select gms_breakpoint('test_debug', 15); -- ok
|
||||
|
||||
select gms_next();
|
||||
|
||||
select gms_next();
|
||||
|
||||
select gms_next();
|
||||
|
||||
select gms_next();
|
||||
|
||||
select gms_continue();
|
||||
|
||||
select gms_continue();
|
||||
|
||||
select gms_debug.detach_session();
|
||||
82
contrib/gms_debug/sql/gms_debugger_client2.sql
Normal file
82
contrib/gms_debug/sql/gms_debugger_client2.sql
Normal file
@ -0,0 +1,82 @@
|
||||
-- wait for server establishment
|
||||
|
||||
CREATE OR REPLACE FUNCTION wait_for_gms_debug_extension()
|
||||
RETURNS BOOLEAN AS $$
|
||||
DECLARE
|
||||
extension_exists BOOLEAN;
|
||||
BEGIN
|
||||
-- 初始化变量
|
||||
extension_exists := FALSE;
|
||||
|
||||
-- 循环查询扩展是否存在
|
||||
WHILE NOT extension_exists LOOP
|
||||
-- 查询扩展是否存在
|
||||
PERFORM 1 FROM pg_extension WHERE extname = 'gms_debug';
|
||||
IF FOUND THEN
|
||||
-- 如果扩展存在,则退出循环
|
||||
extension_exists := TRUE;
|
||||
ELSE
|
||||
-- 如果扩展不存在,则等待一段时间再重试
|
||||
PERFORM pg_sleep(1); -- 等待1秒
|
||||
END IF;
|
||||
END LOOP;
|
||||
|
||||
-- 返回扩展存在的标志
|
||||
RETURN extension_exists;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
DO $$
|
||||
BEGIN
|
||||
IF wait_for_gms_debug_extension() THEN
|
||||
-- 扩展存在,执行下一步操作
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
set search_path = gms_debugger_test2;
|
||||
|
||||
CREATE or REPLACE FUNCTION gms_continue()
|
||||
returns void as $$
|
||||
declare
|
||||
run_info gms_debug.runtime_info;
|
||||
ret binary_integer;
|
||||
begin
|
||||
ret := gms_debug.continue(run_info, 0, 2);
|
||||
RAISE NOTICE 'breakpoint= %', run_info.breakpoint;
|
||||
RAISE NOTICE 'stackdepth= %', run_info.stackdepth;
|
||||
RAISE NOTICE 'line= %', run_info.line#;
|
||||
RAISE NOTICE 'reason= %', run_info.reason;
|
||||
RAISE NOTICE 'ret= %',ret;
|
||||
end;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
CREATE or REPLACE FUNCTION gms_next()
|
||||
returns void as $$
|
||||
declare
|
||||
run_info gms_debug.runtime_info;
|
||||
ret binary_integer;
|
||||
begin
|
||||
ret := gms_debug.continue(run_info, 2, 2);
|
||||
RAISE NOTICE 'breakpoint= %', run_info.breakpoint;
|
||||
RAISE NOTICE 'stackdepth= %', run_info.stackdepth;
|
||||
RAISE NOTICE 'line= %', run_info.line#;
|
||||
RAISE NOTICE 'reason= %', run_info.reason;
|
||||
RAISE NOTICE 'ret= %',ret;
|
||||
end;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
|
||||
-- attach debug server
|
||||
select * from gms_debug.attach_session('datanode1-0');
|
||||
|
||||
select pg_sleep(3);
|
||||
|
||||
select gms_next();
|
||||
|
||||
select gms_next();
|
||||
|
||||
select gms_next();
|
||||
|
||||
select gms_continue();
|
||||
|
||||
select gms_debug.detach_session();
|
||||
82
contrib/gms_debug/sql/gms_debugger_client3.sql
Normal file
82
contrib/gms_debug/sql/gms_debugger_client3.sql
Normal file
@ -0,0 +1,82 @@
|
||||
-- wait for server establishment
|
||||
|
||||
CREATE OR REPLACE FUNCTION wait_for_gms_debug_extension()
|
||||
RETURNS BOOLEAN AS $$
|
||||
DECLARE
|
||||
extension_exists BOOLEAN;
|
||||
BEGIN
|
||||
-- 初始化变量
|
||||
extension_exists := FALSE;
|
||||
|
||||
-- 循环查询扩展是否存在
|
||||
WHILE NOT extension_exists LOOP
|
||||
-- 查询扩展是否存在
|
||||
PERFORM 1 FROM pg_extension WHERE extname = 'gms_debug';
|
||||
IF FOUND THEN
|
||||
-- 如果扩展存在,则退出循环
|
||||
extension_exists := TRUE;
|
||||
ELSE
|
||||
-- 如果扩展不存在,则等待一段时间再重试
|
||||
PERFORM pg_sleep(1); -- 等待1秒
|
||||
END IF;
|
||||
END LOOP;
|
||||
|
||||
-- 返回扩展存在的标志
|
||||
RETURN extension_exists;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
DO $$
|
||||
BEGIN
|
||||
IF wait_for_gms_debug_extension() THEN
|
||||
-- 扩展存在,执行下一步操作
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
set search_path = gms_debugger_test3;
|
||||
|
||||
CREATE or REPLACE FUNCTION gms_next()
|
||||
returns void as $$
|
||||
declare
|
||||
run_info gms_debug.runtime_info;
|
||||
ret binary_integer;
|
||||
begin
|
||||
ret := gms_debug.continue(run_info, 2, 2);
|
||||
RAISE NOTICE 'breakpoint= %', run_info.breakpoint;
|
||||
RAISE NOTICE 'stackdepth= %', run_info.stackdepth;
|
||||
RAISE NOTICE 'line= %', run_info.line#;
|
||||
RAISE NOTICE 'reason= %', run_info.reason;
|
||||
RAISE NOTICE 'ret= %',ret;
|
||||
end;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
CREATE or REPLACE FUNCTION gms_continue()
|
||||
returns void as $$
|
||||
declare
|
||||
run_info gms_debug.runtime_info;
|
||||
ret binary_integer;
|
||||
begin
|
||||
ret := gms_debug.continue(run_info, 0, 2);
|
||||
RAISE NOTICE 'breakpoint= %', run_info.breakpoint;
|
||||
RAISE NOTICE 'stackdepth= %', run_info.stackdepth;
|
||||
RAISE NOTICE 'line= %', run_info.line#;
|
||||
RAISE NOTICE 'reason= %', run_info.reason;
|
||||
RAISE NOTICE 'ret= %',ret;
|
||||
end;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
|
||||
-- attach debug server
|
||||
select * from gms_debug.attach_session('datanode1-0');
|
||||
|
||||
select pg_sleep(3);
|
||||
|
||||
select gms_next();
|
||||
|
||||
select gms_next();
|
||||
|
||||
select gms_continue();
|
||||
|
||||
select gms_next();
|
||||
|
||||
select gms_debug.detach_session();
|
||||
88
contrib/gms_debug/sql/gms_debugger_client4.sql
Normal file
88
contrib/gms_debug/sql/gms_debugger_client4.sql
Normal file
@ -0,0 +1,88 @@
|
||||
-- wait for server establishment
|
||||
|
||||
CREATE OR REPLACE FUNCTION wait_for_gms_debug_extension()
|
||||
RETURNS BOOLEAN AS $$
|
||||
DECLARE
|
||||
extension_exists BOOLEAN;
|
||||
BEGIN
|
||||
-- 初始化变量
|
||||
extension_exists := FALSE;
|
||||
|
||||
-- 循环查询扩展是否存在
|
||||
WHILE NOT extension_exists LOOP
|
||||
-- 查询扩展是否存在
|
||||
PERFORM 1 FROM pg_extension WHERE extname = 'gms_debug';
|
||||
IF FOUND THEN
|
||||
-- 如果扩展存在,则退出循环
|
||||
extension_exists := TRUE;
|
||||
ELSE
|
||||
-- 如果扩展不存在,则等待一段时间再重试
|
||||
PERFORM pg_sleep(1); -- 等待1秒
|
||||
END IF;
|
||||
END LOOP;
|
||||
|
||||
-- 返回扩展存在的标志
|
||||
RETURN extension_exists;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
DO $$
|
||||
BEGIN
|
||||
IF wait_for_gms_debug_extension() THEN
|
||||
-- 扩展存在,执行下一步操作
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
set search_path = gms_debugger_test4;
|
||||
|
||||
CREATE or REPLACE FUNCTION gms_step()
|
||||
returns void as $$
|
||||
declare
|
||||
run_info gms_debug.runtime_info;
|
||||
ret binary_integer;
|
||||
begin
|
||||
ret := gms_debug.continue(run_info, 4, 2);
|
||||
RAISE NOTICE 'breakpoint= %', run_info.breakpoint;
|
||||
RAISE NOTICE 'stackdepth= %', run_info.stackdepth;
|
||||
RAISE NOTICE 'line= %', run_info.line#;
|
||||
RAISE NOTICE 'reason= %', run_info.reason;
|
||||
RAISE NOTICE 'ret= %',ret;
|
||||
end;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
CREATE or REPLACE FUNCTION gms_continue()
|
||||
returns void as $$
|
||||
declare
|
||||
run_info gms_debug.runtime_info;
|
||||
ret binary_integer;
|
||||
begin
|
||||
ret := gms_debug.continue(run_info, 0, 2);
|
||||
RAISE NOTICE 'breakpoint= %', run_info.breakpoint;
|
||||
RAISE NOTICE 'stackdepth= %', run_info.stackdepth;
|
||||
RAISE NOTICE 'line= %', run_info.line#;
|
||||
RAISE NOTICE 'reason= %', run_info.reason;
|
||||
RAISE NOTICE 'ret= %',ret;
|
||||
end;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
|
||||
-- attach debug server
|
||||
select * from gms_debug.attach_session('datanode1-0');
|
||||
|
||||
select pg_sleep(3);
|
||||
|
||||
select gms_step();
|
||||
|
||||
select gms_step();
|
||||
|
||||
select gms_step();
|
||||
|
||||
select gms_step();
|
||||
|
||||
select gms_step();
|
||||
|
||||
select gms_continue();
|
||||
|
||||
select gms_continue();
|
||||
|
||||
select gms_debug.detach_session();
|
||||
116
contrib/gms_debug/sql/gms_debugger_client5.sql
Normal file
116
contrib/gms_debug/sql/gms_debugger_client5.sql
Normal file
@ -0,0 +1,116 @@
|
||||
-- wait for server establishment
|
||||
|
||||
CREATE OR REPLACE FUNCTION wait_for_gms_debug_extension()
|
||||
RETURNS BOOLEAN AS $$
|
||||
DECLARE
|
||||
extension_exists BOOLEAN;
|
||||
BEGIN
|
||||
-- 初始化变量
|
||||
extension_exists := FALSE;
|
||||
|
||||
-- 循环查询扩展是否存在
|
||||
WHILE NOT extension_exists LOOP
|
||||
-- 查询扩展是否存在
|
||||
PERFORM 1 FROM pg_extension WHERE extname = 'gms_debug';
|
||||
IF FOUND THEN
|
||||
-- 如果扩展存在,则退出循环
|
||||
extension_exists := TRUE;
|
||||
ELSE
|
||||
-- 如果扩展不存在,则等待一段时间再重试
|
||||
PERFORM pg_sleep(1); -- 等待1秒
|
||||
END IF;
|
||||
END LOOP;
|
||||
|
||||
-- 返回扩展存在的标志
|
||||
RETURN extension_exists;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
DO $$
|
||||
BEGIN
|
||||
IF wait_for_gms_debug_extension() THEN
|
||||
-- 扩展存在,执行下一步操作
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
set search_path = gms_debugger_test5;
|
||||
|
||||
CREATE or REPLACE FUNCTION gms_continue()
|
||||
returns void as $$
|
||||
declare
|
||||
run_info gms_debug.runtime_info;
|
||||
ret binary_integer;
|
||||
begin
|
||||
ret := gms_debug.continue(run_info, 0, 2);
|
||||
RAISE NOTICE 'breakpoint= %', run_info.breakpoint;
|
||||
RAISE NOTICE 'stackdepth= %', run_info.stackdepth;
|
||||
RAISE NOTICE 'line= %', run_info.line#;
|
||||
RAISE NOTICE 'reason= %', run_info.reason;
|
||||
RAISE NOTICE 'ret= %',ret;
|
||||
end;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
CREATE or REPLACE FUNCTION gms_step()
|
||||
returns void as $$
|
||||
declare
|
||||
run_info gms_debug.runtime_info;
|
||||
ret binary_integer;
|
||||
begin
|
||||
ret := gms_debug.continue(run_info, 4, 2);
|
||||
RAISE NOTICE 'breakpoint= %', run_info.breakpoint;
|
||||
RAISE NOTICE 'stackdepth= %', run_info.stackdepth;
|
||||
RAISE NOTICE 'line= %', run_info.line#;
|
||||
RAISE NOTICE 'reason= %', run_info.reason;
|
||||
RAISE NOTICE 'ret= %',ret;
|
||||
end;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
CREATE or REPLACE FUNCTION gms_next()
|
||||
returns void as $$
|
||||
declare
|
||||
run_info gms_debug.runtime_info;
|
||||
ret binary_integer;
|
||||
begin
|
||||
ret := gms_debug.continue(run_info, 2, 2);
|
||||
RAISE NOTICE 'breakpoint= %', run_info.breakpoint;
|
||||
RAISE NOTICE 'stackdepth= %', run_info.stackdepth;
|
||||
RAISE NOTICE 'line= %', run_info.line#;
|
||||
RAISE NOTICE 'reason= %', run_info.reason;
|
||||
RAISE NOTICE 'ret= %',ret;
|
||||
end;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
CREATE or REPLACE FUNCTION gms_finish()
|
||||
returns void as $$
|
||||
declare
|
||||
run_info gms_debug.runtime_info;
|
||||
ret binary_integer;
|
||||
begin
|
||||
ret := gms_debug.continue(run_info, 8, 2);
|
||||
RAISE NOTICE 'breakpoint= %', run_info.breakpoint;
|
||||
RAISE NOTICE 'stackdepth= %', run_info.stackdepth;
|
||||
RAISE NOTICE 'line= %', run_info.line#;
|
||||
RAISE NOTICE 'reason= %', run_info.reason;
|
||||
RAISE NOTICE 'ret= %',ret;
|
||||
end;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
|
||||
-- attach debug server
|
||||
select * from gms_debug.attach_session('datanode1-0');
|
||||
|
||||
select pg_sleep(3);
|
||||
|
||||
select gms_next();
|
||||
|
||||
select gms_next();
|
||||
|
||||
select gms_next();
|
||||
|
||||
select gms_step();
|
||||
|
||||
select gms_finish();
|
||||
|
||||
select gms_finish();
|
||||
|
||||
select gms_debug.detach_session();
|
||||
99
contrib/gms_debug/sql/gms_debugger_client6.sql
Normal file
99
contrib/gms_debug/sql/gms_debugger_client6.sql
Normal file
@ -0,0 +1,99 @@
|
||||
-- wait for server establishment
|
||||
|
||||
CREATE OR REPLACE FUNCTION wait_for_gms_debug_extension()
|
||||
RETURNS BOOLEAN AS $$
|
||||
DECLARE
|
||||
extension_exists BOOLEAN;
|
||||
BEGIN
|
||||
-- 初始化变量
|
||||
extension_exists := FALSE;
|
||||
|
||||
-- 循环查询扩展是否存在
|
||||
WHILE NOT extension_exists LOOP
|
||||
-- 查询扩展是否存在
|
||||
PERFORM 1 FROM pg_extension WHERE extname = 'gms_debug';
|
||||
IF FOUND THEN
|
||||
-- 如果扩展存在,则退出循环
|
||||
extension_exists := TRUE;
|
||||
ELSE
|
||||
-- 如果扩展不存在,则等待一段时间再重试
|
||||
PERFORM pg_sleep(1); -- 等待1秒
|
||||
END IF;
|
||||
END LOOP;
|
||||
|
||||
-- 返回扩展存在的标志
|
||||
RETURN extension_exists;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
DO $$
|
||||
BEGIN
|
||||
IF wait_for_gms_debug_extension() THEN
|
||||
-- 扩展存在,执行下一步操作
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
set search_path = gms_debugger_test6;
|
||||
|
||||
CREATE or REPLACE FUNCTION gms_continue()
|
||||
returns void as $$
|
||||
declare
|
||||
run_info gms_debug.runtime_info;
|
||||
ret binary_integer;
|
||||
begin
|
||||
ret := gms_debug.continue(run_info, 0, 2);
|
||||
RAISE NOTICE 'breakpoint= %', run_info.breakpoint;
|
||||
RAISE NOTICE 'stackdepth= %', run_info.stackdepth;
|
||||
RAISE NOTICE 'line= %', run_info.line#;
|
||||
RAISE NOTICE 'reason= %', run_info.reason;
|
||||
RAISE NOTICE 'ret= %',ret;
|
||||
end;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
CREATE or REPLACE FUNCTION gms_breakpoint(funcname text, lineno int)
|
||||
returns void as $$
|
||||
declare
|
||||
pro_info gms_debug.program_info;
|
||||
bkline binary_integer;
|
||||
ret binary_integer;
|
||||
begin
|
||||
pro_info.name := funcname;
|
||||
ret := gms_debug.set_breakpoint(pro_info, lineno, bkline,1,1);
|
||||
RAISE NOTICE 'ret= %', ret;
|
||||
RAISE NOTICE 'ret= %', bkline;
|
||||
end;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
CREATE or REPLACE FUNCTION gms_finish()
|
||||
returns void as $$
|
||||
declare
|
||||
run_info gms_debug.runtime_info;
|
||||
ret binary_integer;
|
||||
begin
|
||||
ret := gms_debug.continue(run_info, 8, 2);
|
||||
RAISE NOTICE 'breakpoint= %', run_info.breakpoint;
|
||||
RAISE NOTICE 'stackdepth= %', run_info.stackdepth;
|
||||
RAISE NOTICE 'line= %', run_info.line#;
|
||||
RAISE NOTICE 'reason= %', run_info.reason;
|
||||
RAISE NOTICE 'ret= %',ret;
|
||||
end;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
|
||||
-- attach debug server
|
||||
select * from gms_debug.attach_session('datanode1-0');
|
||||
|
||||
select pg_sleep(3);
|
||||
|
||||
select gms_breakpoint('test_debug', 31);
|
||||
select gms_breakpoint('test_debug', 44);
|
||||
|
||||
select gms_finish();
|
||||
|
||||
select gms_finish();
|
||||
|
||||
select gms_finish();
|
||||
|
||||
select gms_continue();
|
||||
|
||||
select gms_debug.detach_session();
|
||||
103
contrib/gms_debug/sql/gms_debugger_client7.sql
Normal file
103
contrib/gms_debug/sql/gms_debugger_client7.sql
Normal file
@ -0,0 +1,103 @@
|
||||
-- wait for server establishment
|
||||
|
||||
CREATE OR REPLACE FUNCTION wait_for_gms_debug_extension()
|
||||
RETURNS BOOLEAN AS $$
|
||||
DECLARE
|
||||
extension_exists BOOLEAN;
|
||||
BEGIN
|
||||
-- 初始化变量
|
||||
extension_exists := FALSE;
|
||||
|
||||
-- 循环查询扩展是否存在
|
||||
WHILE NOT extension_exists LOOP
|
||||
-- 查询扩展是否存在
|
||||
PERFORM 1 FROM pg_extension WHERE extname = 'gms_debug';
|
||||
IF FOUND THEN
|
||||
-- 如果扩展存在,则退出循环
|
||||
extension_exists := TRUE;
|
||||
ELSE
|
||||
-- 如果扩展不存在,则等待一段时间再重试
|
||||
PERFORM pg_sleep(1); -- 等待1秒
|
||||
END IF;
|
||||
END LOOP;
|
||||
|
||||
-- 返回扩展存在的标志
|
||||
RETURN extension_exists;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
DO $$
|
||||
BEGIN
|
||||
IF wait_for_gms_debug_extension() THEN
|
||||
-- 扩展存在,执行下一步操作
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
set search_path = gms_debugger_test7;
|
||||
|
||||
CREATE or REPLACE FUNCTION gms_step()
|
||||
returns void as $$
|
||||
declare
|
||||
run_info gms_debug.runtime_info;
|
||||
ret binary_integer;
|
||||
begin
|
||||
ret := gms_debug.continue(run_info, 4, 2);
|
||||
RAISE NOTICE 'breakpoint= %', run_info.breakpoint;
|
||||
RAISE NOTICE 'stackdepth= %', run_info.stackdepth;
|
||||
RAISE NOTICE 'line= %', run_info.line#;
|
||||
RAISE NOTICE 'reason= %', run_info.reason;
|
||||
RAISE NOTICE 'ret= %',ret;
|
||||
end;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
CREATE or REPLACE FUNCTION gms_continue()
|
||||
returns void as $$
|
||||
declare
|
||||
run_info gms_debug.runtime_info;
|
||||
ret binary_integer;
|
||||
begin
|
||||
ret := gms_debug.continue(run_info, 0, 2);
|
||||
RAISE NOTICE 'breakpoint= %', run_info.breakpoint;
|
||||
RAISE NOTICE 'stackdepth= %', run_info.stackdepth;
|
||||
RAISE NOTICE 'line= %', run_info.line#;
|
||||
RAISE NOTICE 'reason= %', run_info.reason;
|
||||
RAISE NOTICE 'ret= %',ret;
|
||||
end;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
CREATE or REPLACE FUNCTION gms_breakpoint(funcname text, lineno int)
|
||||
returns void as $$
|
||||
declare
|
||||
pro_info gms_debug.program_info;
|
||||
bkline binary_integer;
|
||||
ret binary_integer;
|
||||
begin
|
||||
pro_info.name := funcname;
|
||||
ret := gms_debug.set_breakpoint(pro_info, lineno, bkline,1,1);
|
||||
RAISE NOTICE 'ret= %', ret;
|
||||
RAISE NOTICE 'ret= %', bkline;
|
||||
end;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
-- attach debug server
|
||||
select * from gms_debug.attach_session('datanode1-0');
|
||||
|
||||
select pg_sleep(3);
|
||||
|
||||
select gms_breakpoint('test_debug_recursive', 5);
|
||||
|
||||
select gms_step();
|
||||
|
||||
select gms_step();
|
||||
|
||||
select gms_step();
|
||||
|
||||
select gms_step();
|
||||
|
||||
select gms_step();
|
||||
|
||||
select gms_continue();
|
||||
|
||||
select gms_continue();
|
||||
|
||||
select gms_debug.detach_session();
|
||||
95
contrib/gms_debug/sql/gms_debugger_server1.sql
Normal file
95
contrib/gms_debug/sql/gms_debugger_server1.sql
Normal file
@ -0,0 +1,95 @@
|
||||
-- setups
|
||||
create extension if not exists gms_debug;
|
||||
drop schema if exists gms_debugger_test1 cascade;
|
||||
create schema gms_debugger_test1;
|
||||
set search_path = gms_debugger_test1;
|
||||
create table test(a int, b varchar(40), c timestamp);
|
||||
insert into test values (2, 'Giving to the Needy', '2020-02-02');
|
||||
insert into test values (3, 'Prayer', '2021-12-02');
|
||||
insert into test values (5, 'Fasting', '2030-03-02');
|
||||
insert into test values (7, 'Treasures in Heaven', '2040-04-02');
|
||||
|
||||
CREATE OR REPLACE FUNCTION test_debug(x int) RETURNS SETOF test AS
|
||||
$BODY$
|
||||
DECLARE
|
||||
sql_stmt VARCHAR2(500);
|
||||
r test%rowtype;
|
||||
rec record;
|
||||
b_tmp text;
|
||||
cnt int;
|
||||
a_tmp int;
|
||||
cur refcursor;
|
||||
n_tmp NUMERIC(24,6);
|
||||
t_tmp tsquery;
|
||||
CURSOR cur_arg(criterion INTEGER) IS
|
||||
SELECT * FROM test WHERE a < criterion;
|
||||
BEGIN
|
||||
cnt := 0;
|
||||
FOR r IN SELECT * FROM test
|
||||
WHERE a > x
|
||||
LOOP
|
||||
RETURN NEXT r;
|
||||
END LOOP;
|
||||
|
||||
FOR rec in SELECT * FROM test
|
||||
WHERE a < x
|
||||
LOOP
|
||||
RETURN NEXT rec;
|
||||
END LOOP;
|
||||
|
||||
FORALL index_1 IN 0..1
|
||||
INSERT INTO test VALUES (index_1, 'Happy Children''s Day!', '2021-6-1');
|
||||
|
||||
SELECT b FROM test where a = 7 INTO b_tmp;
|
||||
sql_stmt := 'select a from test where b = :1;';
|
||||
OPEN cur FOR sql_stmt USING b_tmp;
|
||||
IF cur%isopen then LOOP
|
||||
FETCH cur INTO a_tmp;
|
||||
EXIT WHEN cur%notfound;
|
||||
END LOOP;
|
||||
END IF;
|
||||
CLOSE cur;
|
||||
WHILE cnt < 3 LOOP
|
||||
cnt := cnt + 1;
|
||||
END LOOP;
|
||||
|
||||
RAISE INFO 'cnt is %', cnt;
|
||||
|
||||
RETURN;
|
||||
|
||||
END
|
||||
$BODY$
|
||||
LANGUAGE plpgsql;
|
||||
|
||||
create table show_code_table(lineno int, code text, canBreak bool);
|
||||
|
||||
do $$
|
||||
declare
|
||||
funcoid oid;
|
||||
begin
|
||||
select oid from pg_proc into funcoid where proname = 'test_debug';
|
||||
INSERT INTO show_code_table SELECT * FROM dbe_pldebugger.info_code(funcoid);
|
||||
end;
|
||||
$$;
|
||||
|
||||
select * from show_code_table;
|
||||
|
||||
-- attach fail (target not turned on)
|
||||
select * from gms_debug.attach_session('datanode1-0');
|
||||
|
||||
-- turn off without turn on
|
||||
select * from gms_debug.debug_off();
|
||||
|
||||
select * from gms_debug.initialize();
|
||||
|
||||
select pg_sleep(1);
|
||||
|
||||
-- start debug - 1st run
|
||||
select * from test_debug(4);
|
||||
|
||||
-- start debug - 2nd run - to be aborted
|
||||
select * from test_debug(4);
|
||||
|
||||
select * from gms_debug.debug_off();
|
||||
|
||||
drop schema gms_debugger_test1 cascade;
|
||||
32
contrib/gms_debug/sql/gms_debugger_server2.sql
Normal file
32
contrib/gms_debug/sql/gms_debugger_server2.sql
Normal file
@ -0,0 +1,32 @@
|
||||
-- setups
|
||||
create extension if not exists gms_debug;
|
||||
drop schema if exists gms_debugger_test2 cascade;
|
||||
create schema gms_debugger_test2;
|
||||
set search_path = gms_debugger_test2;
|
||||
|
||||
-- commit/rollback in procedure
|
||||
create table tb1(a int);
|
||||
create or replace procedure test_debug2 as
|
||||
begin
|
||||
insert into tb1 values (1000);
|
||||
commit;
|
||||
insert into tb1 values (2000);
|
||||
rollback;
|
||||
end;
|
||||
/
|
||||
|
||||
|
||||
-- start debug
|
||||
select * from gms_debug.initialize();
|
||||
|
||||
select pg_sleep(1);
|
||||
|
||||
-- start debug - 1st run
|
||||
select * from test_debug2();
|
||||
|
||||
-- start debug - 2nd run - to be aborted
|
||||
select * from test_debug2();
|
||||
|
||||
select * from gms_debug.debug_off();
|
||||
|
||||
drop schema gms_debugger_test2 cascade;
|
||||
39
contrib/gms_debug/sql/gms_debugger_server3.sql
Normal file
39
contrib/gms_debug/sql/gms_debugger_server3.sql
Normal file
@ -0,0 +1,39 @@
|
||||
-- setups
|
||||
create extension if not exists gms_debug;
|
||||
drop schema if exists gms_debugger_test3 cascade;
|
||||
create schema gms_debugger_test3;
|
||||
set search_path = gms_debugger_test3;
|
||||
|
||||
-- test for implicit variables
|
||||
CREATE OR REPLACE function test_debug3(a in integer) return integer
|
||||
AS
|
||||
declare
|
||||
b int;
|
||||
BEGIN
|
||||
CASE a
|
||||
WHEN 1 THEN
|
||||
b := 111;
|
||||
ELSE
|
||||
b := 999;
|
||||
END CASE;
|
||||
raise info 'pi_return : %',pi_return ;
|
||||
return b;
|
||||
EXCEPTION WHEN others THEN
|
||||
b := 101;
|
||||
return b;
|
||||
END;
|
||||
/
|
||||
|
||||
select * from gms_debug.initialize();
|
||||
|
||||
select pg_sleep(1);
|
||||
|
||||
-- start debug - 1st run
|
||||
select * from test_debug3(1);
|
||||
|
||||
-- start debug - 2nd run - to be aborted
|
||||
select * from test_debug3(1);
|
||||
|
||||
select * from gms_debug.debug_off();
|
||||
|
||||
drop schema gms_debugger_test3 cascade;
|
||||
97
contrib/gms_debug/sql/gms_debugger_server4.sql
Normal file
97
contrib/gms_debug/sql/gms_debugger_server4.sql
Normal file
@ -0,0 +1,97 @@
|
||||
-- setups
|
||||
create extension if not exists gms_debug;
|
||||
drop schema if exists gms_debugger_test4 cascade;
|
||||
create schema gms_debugger_test4;
|
||||
set search_path = gms_debugger_test4;
|
||||
|
||||
create table test(a int, b varchar(40), c timestamp);
|
||||
insert into test values (2, 'Giving to the Needy', '2020-02-02');
|
||||
insert into test values (3, 'Prayer', '2021-12-02');
|
||||
insert into test values (5, 'Fasting', '2030-03-02');
|
||||
insert into test values (7, 'Treasures in Heaven', '2040-04-02');
|
||||
|
||||
CREATE OR REPLACE FUNCTION test_debug(x int) RETURNS SETOF test AS
|
||||
$BODY$
|
||||
DECLARE
|
||||
sql_stmt VARCHAR2(500);
|
||||
r test%rowtype;
|
||||
rec record;
|
||||
b_tmp text;
|
||||
cnt int;
|
||||
a_tmp int;
|
||||
cur refcursor;
|
||||
n_tmp NUMERIC(24,6);
|
||||
t_tmp tsquery;
|
||||
CURSOR cur_arg(criterion INTEGER) IS
|
||||
SELECT * FROM test WHERE a < criterion;
|
||||
BEGIN
|
||||
cnt := 0;
|
||||
FOR r IN SELECT * FROM test
|
||||
WHERE a > x
|
||||
LOOP
|
||||
RETURN NEXT r;
|
||||
END LOOP;
|
||||
|
||||
FOR rec in SELECT * FROM test
|
||||
WHERE a < x
|
||||
LOOP
|
||||
RETURN NEXT rec;
|
||||
END LOOP;
|
||||
|
||||
FORALL index_1 IN 0..1
|
||||
INSERT INTO test VALUES (index_1, 'Happy Children''s Day!', '2021-6-1');
|
||||
|
||||
SELECT b FROM test where a = 7 INTO b_tmp;
|
||||
sql_stmt := 'select a from test where b = :1;';
|
||||
OPEN cur FOR sql_stmt USING b_tmp;
|
||||
IF cur%isopen then LOOP
|
||||
FETCH cur INTO a_tmp;
|
||||
EXIT WHEN cur%notfound;
|
||||
END LOOP;
|
||||
END IF;
|
||||
CLOSE cur;
|
||||
WHILE cnt < 3 LOOP
|
||||
cnt := cnt + 1;
|
||||
END LOOP;
|
||||
|
||||
RAISE INFO 'cnt is %', cnt;
|
||||
|
||||
RETURN;
|
||||
|
||||
END
|
||||
$BODY$
|
||||
LANGUAGE plpgsql;
|
||||
|
||||
-- test for step into
|
||||
CREATE OR REPLACE FUNCTION test_debug4(a in integer) return integer
|
||||
AS
|
||||
declare
|
||||
b int;
|
||||
BEGIN
|
||||
CASE a
|
||||
WHEN 1 THEN
|
||||
b := 111;
|
||||
call test_debug(a);
|
||||
ELSE
|
||||
b := 999;
|
||||
END CASE;
|
||||
return b;
|
||||
raise info 'pi_return : %',pi_return ;
|
||||
EXCEPTION WHEN others THEN
|
||||
b := 101;
|
||||
return b;
|
||||
END;
|
||||
/
|
||||
|
||||
select * from gms_debug.initialize();
|
||||
|
||||
select pg_sleep(1);
|
||||
|
||||
select * from test_debug4(1);
|
||||
|
||||
-- test with client error in exception
|
||||
select * from test_debug4(1);
|
||||
|
||||
select * from gms_debug.debug_off();
|
||||
|
||||
drop schema gms_debugger_test4 cascade;
|
||||
97
contrib/gms_debug/sql/gms_debugger_server5.sql
Normal file
97
contrib/gms_debug/sql/gms_debugger_server5.sql
Normal file
@ -0,0 +1,97 @@
|
||||
-- setups
|
||||
create extension if not exists gms_debug;
|
||||
drop schema if exists gms_debugger_test5 cascade;
|
||||
create schema gms_debugger_test5;
|
||||
set search_path = gms_debugger_test5;
|
||||
|
||||
create table test(a int, b varchar(40), c timestamp);
|
||||
insert into test values (2, 'Giving to the Needy', '2020-02-02');
|
||||
insert into test values (3, 'Prayer', '2021-12-02');
|
||||
insert into test values (5, 'Fasting', '2030-03-02');
|
||||
insert into test values (7, 'Treasures in Heaven', '2040-04-02');
|
||||
|
||||
CREATE OR REPLACE FUNCTION test_debug(x int) RETURNS SETOF test AS
|
||||
$BODY$
|
||||
DECLARE
|
||||
sql_stmt VARCHAR2(500);
|
||||
r test%rowtype;
|
||||
rec record;
|
||||
b_tmp text;
|
||||
cnt int;
|
||||
a_tmp int;
|
||||
cur refcursor;
|
||||
n_tmp NUMERIC(24,6);
|
||||
t_tmp tsquery;
|
||||
CURSOR cur_arg(criterion INTEGER) IS
|
||||
SELECT * FROM test WHERE a < criterion;
|
||||
BEGIN
|
||||
cnt := 0;
|
||||
FOR r IN SELECT * FROM test
|
||||
WHERE a > x
|
||||
LOOP
|
||||
RETURN NEXT r;
|
||||
END LOOP;
|
||||
|
||||
FOR rec in SELECT * FROM test
|
||||
WHERE a < x
|
||||
LOOP
|
||||
RETURN NEXT rec;
|
||||
END LOOP;
|
||||
|
||||
FORALL index_1 IN 0..1
|
||||
INSERT INTO test VALUES (index_1, 'Happy Children''s Day!', '2021-6-1');
|
||||
|
||||
SELECT b FROM test where a = 7 INTO b_tmp;
|
||||
sql_stmt := 'select a from test where b = :1;';
|
||||
OPEN cur FOR sql_stmt USING b_tmp;
|
||||
IF cur%isopen then LOOP
|
||||
FETCH cur INTO a_tmp;
|
||||
EXIT WHEN cur%notfound;
|
||||
END LOOP;
|
||||
END IF;
|
||||
CLOSE cur;
|
||||
WHILE cnt < 3 LOOP
|
||||
cnt := cnt + 1;
|
||||
END LOOP;
|
||||
|
||||
RAISE INFO 'cnt is %', cnt;
|
||||
|
||||
RETURN;
|
||||
|
||||
END
|
||||
$BODY$
|
||||
LANGUAGE plpgsql;
|
||||
|
||||
-- test for step into
|
||||
CREATE OR REPLACE FUNCTION test_debug4(a in integer) return integer
|
||||
AS
|
||||
declare
|
||||
b int;
|
||||
BEGIN
|
||||
CASE a
|
||||
WHEN 1 THEN
|
||||
b := 111;
|
||||
call test_debug(a);
|
||||
ELSE
|
||||
b := 999;
|
||||
END CASE;
|
||||
return b;
|
||||
raise info 'pi_return : %',pi_return ;
|
||||
EXCEPTION WHEN others THEN
|
||||
b := 101;
|
||||
return b;
|
||||
END;
|
||||
/
|
||||
|
||||
select * from gms_debug.initialize();
|
||||
|
||||
select pg_sleep(1);
|
||||
|
||||
select * from test_debug4(1);
|
||||
|
||||
-- test with client error in exception
|
||||
select * from test_debug4(1);
|
||||
|
||||
select * from gms_debug.debug_off();
|
||||
|
||||
drop schema gms_debugger_test5 cascade;
|
||||
97
contrib/gms_debug/sql/gms_debugger_server6.sql
Normal file
97
contrib/gms_debug/sql/gms_debugger_server6.sql
Normal file
@ -0,0 +1,97 @@
|
||||
-- setups
|
||||
create extension if not exists gms_debug;
|
||||
drop schema if exists gms_debugger_test6 cascade;
|
||||
create schema gms_debugger_test6;
|
||||
set search_path = gms_debugger_test6;
|
||||
|
||||
create table test(a int, b varchar(40), c timestamp);
|
||||
insert into test values (2, 'Giving to the Needy', '2020-02-02');
|
||||
insert into test values (3, 'Prayer', '2021-12-02');
|
||||
insert into test values (5, 'Fasting', '2030-03-02');
|
||||
insert into test values (7, 'Treasures in Heaven', '2040-04-02');
|
||||
|
||||
CREATE OR REPLACE FUNCTION test_debug(x int) RETURNS SETOF test AS
|
||||
$BODY$
|
||||
DECLARE
|
||||
sql_stmt VARCHAR2(500);
|
||||
r test%rowtype;
|
||||
rec record;
|
||||
b_tmp text;
|
||||
cnt int;
|
||||
a_tmp int;
|
||||
cur refcursor;
|
||||
n_tmp NUMERIC(24,6);
|
||||
t_tmp tsquery;
|
||||
CURSOR cur_arg(criterion INTEGER) IS
|
||||
SELECT * FROM test WHERE a < criterion;
|
||||
BEGIN
|
||||
cnt := 0;
|
||||
FOR r IN SELECT * FROM test
|
||||
WHERE a > x
|
||||
LOOP
|
||||
RETURN NEXT r;
|
||||
END LOOP;
|
||||
|
||||
FOR rec in SELECT * FROM test
|
||||
WHERE a < x
|
||||
LOOP
|
||||
RETURN NEXT rec;
|
||||
END LOOP;
|
||||
|
||||
FORALL index_1 IN 0..1
|
||||
INSERT INTO test VALUES (index_1, 'Happy Children''s Day!', '2021-6-1');
|
||||
|
||||
SELECT b FROM test where a = 7 INTO b_tmp;
|
||||
sql_stmt := 'select a from test where b = :1;';
|
||||
OPEN cur FOR sql_stmt USING b_tmp;
|
||||
IF cur%isopen then LOOP
|
||||
FETCH cur INTO a_tmp;
|
||||
EXIT WHEN cur%notfound;
|
||||
END LOOP;
|
||||
END IF;
|
||||
CLOSE cur;
|
||||
WHILE cnt < 3 LOOP
|
||||
cnt := cnt + 1;
|
||||
END LOOP;
|
||||
|
||||
RAISE INFO 'cnt is %', cnt;
|
||||
|
||||
RETURN;
|
||||
|
||||
END
|
||||
$BODY$
|
||||
LANGUAGE plpgsql;
|
||||
|
||||
-- test for step into
|
||||
CREATE OR REPLACE FUNCTION test_debug4(a in integer) return integer
|
||||
AS
|
||||
declare
|
||||
b int;
|
||||
BEGIN
|
||||
CASE a
|
||||
WHEN 1 THEN
|
||||
b := 111;
|
||||
call test_debug(a);
|
||||
ELSE
|
||||
b := 999;
|
||||
END CASE;
|
||||
return b;
|
||||
raise info 'pi_return : %',pi_return ;
|
||||
EXCEPTION WHEN others THEN
|
||||
b := 101;
|
||||
return b;
|
||||
END;
|
||||
/
|
||||
|
||||
select * from gms_debug.initialize();
|
||||
|
||||
select pg_sleep(1);
|
||||
|
||||
select * from test_debug4(1);
|
||||
|
||||
-- test with client error in exception
|
||||
select * from test_debug4(1);
|
||||
|
||||
select * from gms_debug.debug_off();
|
||||
|
||||
drop schema gms_debugger_test6 cascade;
|
||||
29
contrib/gms_debug/sql/gms_debugger_server7.sql
Normal file
29
contrib/gms_debug/sql/gms_debugger_server7.sql
Normal file
@ -0,0 +1,29 @@
|
||||
-- setups
|
||||
create extension if not exists gms_debug;
|
||||
drop schema if exists gms_debugger_test7 cascade;
|
||||
create schema gms_debugger_test7;
|
||||
set search_path = gms_debugger_test7;
|
||||
|
||||
create or replace function test_debug_recursive (ct int, pr int)
|
||||
returns table (counter int, product int)
|
||||
language plpgsql
|
||||
as $$
|
||||
begin
|
||||
return query select ct, pr;
|
||||
if ct < 5 then
|
||||
return query select * from test_debug_recursive(ct+ 1, pr * (ct+ 1));
|
||||
end if;
|
||||
end $$;
|
||||
|
||||
select * from gms_debug.initialize();
|
||||
|
||||
select pg_sleep(1);
|
||||
|
||||
select * from test_debug_recursive (1, 1);
|
||||
|
||||
-- test with client error in exception
|
||||
select * from test_debug_recursive (1, 1);
|
||||
|
||||
select * from gms_debug.debug_off();
|
||||
|
||||
drop schema gms_debugger_test7 cascade;
|
||||
21
contrib/gms_i18n/CMakeLists.txt
Normal file
21
contrib/gms_i18n/CMakeLists.txt
Normal file
@ -0,0 +1,21 @@
|
||||
#This is the main CMAKE for build all gms_i18n.
|
||||
# gms_i18n
|
||||
AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} TGT_gms_i18n_SRC)
|
||||
set(TGT_gms_i18n_INC
|
||||
${PROJECT_OPENGS_DIR}/contrib/gms_i18n
|
||||
${PROJECT_OPENGS_DIR}/contrib
|
||||
)
|
||||
|
||||
set(gms_i18n_DEF_OPTIONS ${MACRO_OPTIONS})
|
||||
set(gms_i18n_COMPILE_OPTIONS ${OPTIMIZE_OPTIONS} ${OS_OPTIONS} ${PROTECT_OPTIONS} ${WARNING_OPTIONS} ${LIB_SECURE_OPTIONS} ${CHECK_OPTIONS})
|
||||
set(gms_i18n_LINK_OPTIONS ${LIB_LINK_OPTIONS})
|
||||
add_shared_libtarget(gms_i18n TGT_gms_i18n_SRC TGT_gms_i18n_INC "${gms_i18n_DEF_OPTIONS}" "${gms_i18n_COMPILE_OPTIONS}" "${gms_i18n_LINK_OPTIONS}")
|
||||
set_target_properties(gms_i18n PROPERTIES PREFIX "")
|
||||
|
||||
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/gms_i18n.control
|
||||
DESTINATION share/postgresql/extension/
|
||||
)
|
||||
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/gms_i18n--1.0.sql
|
||||
DESTINATION share/postgresql/extension/
|
||||
)
|
||||
install(TARGETS gms_i18n DESTINATION lib/postgresql)
|
||||
26
contrib/gms_i18n/Makefile
Normal file
26
contrib/gms_i18n/Makefile
Normal file
@ -0,0 +1,26 @@
|
||||
# contrib/gms_i18n/Makefile
|
||||
MODULE_big = gms_i18n
|
||||
OBJS = gms_i18n.o
|
||||
|
||||
EXTENSION = gms_i18n
|
||||
DATA = gms_i18n--1.0.sql
|
||||
|
||||
exclude_option = -fPIE
|
||||
override CPPFLAGS := $(filter-out $(exclude_option),$(CPPFLAGS))
|
||||
|
||||
REGRESS = gms_i18n
|
||||
|
||||
ifdef USE_PGXS
|
||||
PG_CONFIG = pg_config
|
||||
PGXS := $(shell $(PG_CONFIG) --pgxs)
|
||||
include $(PGXS)
|
||||
else
|
||||
subdir = contrib/gms_i18n
|
||||
top_builddir = ../..
|
||||
include $(top_builddir)/src/Makefile.global
|
||||
regress_home = $(top_builddir)/src/test/regress
|
||||
REGRESS_OPTS = -c 0 -d 1 -r 1 -p 25632 --single_node -w --keep_last_data=false \
|
||||
--regconf=$(regress_home)/regress.conf \
|
||||
--temp-config=$(regress_home)/make_fastcheck_postgresql.conf
|
||||
include $(top_srcdir)/contrib/contrib-global.mk
|
||||
endif
|
||||
1
contrib/gms_i18n/data/dummy.txt
Normal file
1
contrib/gms_i18n/data/dummy.txt
Normal file
@ -0,0 +1 @@
|
||||
The openGauss regression needs this file to run.
|
||||
145
contrib/gms_i18n/expected/gms_i18n.out
Normal file
145
contrib/gms_i18n/expected/gms_i18n.out
Normal file
@ -0,0 +1,145 @@
|
||||
create extension gms_i18n;
|
||||
create schema gms_i18n_test;
|
||||
set search_path=gms_i18n_test;
|
||||
-- test gms_i18n.raw_to_char
|
||||
select gms_i18n.raw_to_char(hextoraw('616263646566C2AA'), 'utf8');
|
||||
raw_to_char
|
||||
-------------
|
||||
abcdefª
|
||||
(1 row)
|
||||
|
||||
select gms_i18n.raw_to_char(hextoraw('e6b58be8af95'), 'utf8');
|
||||
raw_to_char
|
||||
-------------
|
||||
测试
|
||||
(1 row)
|
||||
|
||||
select gms_i18n.raw_to_char(hextoraw('e6b58be8af95'), '');
|
||||
raw_to_char
|
||||
-------------
|
||||
测试
|
||||
(1 row)
|
||||
|
||||
select gms_i18n.raw_to_char(hextoraw('e6b58be8af95'));
|
||||
raw_to_char
|
||||
-------------
|
||||
测试
|
||||
(1 row)
|
||||
|
||||
select gms_i18n.raw_to_char('', 'utf8');
|
||||
raw_to_char
|
||||
-------------
|
||||
|
||||
(1 row)
|
||||
|
||||
select gms_i18n.raw_to_char('', '');
|
||||
raw_to_char
|
||||
-------------
|
||||
|
||||
(1 row)
|
||||
|
||||
select gms_i18n.raw_to_char('');
|
||||
raw_to_char
|
||||
-------------
|
||||
|
||||
(1 row)
|
||||
|
||||
select gms_i18n.raw_to_char(hextoraw('e6b58be8af95'), 'unvalid_charset');
|
||||
ERROR: invalid source encoding name "unvalid_charset"
|
||||
CONTEXT: referenced column: raw_to_char
|
||||
select gms_i18n.raw_to_char(hextoraw('b2e2cad4'), 'gbk');
|
||||
raw_to_char
|
||||
-------------
|
||||
测试
|
||||
(1 row)
|
||||
|
||||
select gms_i18n.raw_to_char(hextoraw('b2e2cad4'), 'euc_cn');
|
||||
raw_to_char
|
||||
-------------
|
||||
测试
|
||||
(1 row)
|
||||
|
||||
select gms_i18n.raw_to_char(hextoraw('b4fab8d5'), 'big5');
|
||||
raw_to_char
|
||||
-------------
|
||||
測試
|
||||
(1 row)
|
||||
|
||||
select gms_i18n.raw_to_char();
|
||||
ERROR: function gms_i18n.raw_to_char() does not exist
|
||||
LINE 1: select gms_i18n.raw_to_char();
|
||||
^
|
||||
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
|
||||
CONTEXT: referenced column: raw_to_char
|
||||
-- test gms_i18n.string_to_raw
|
||||
select gms_i18n.string_to_raw('abcdefª', 'utf8');
|
||||
string_to_raw
|
||||
------------------
|
||||
616263646566C2AA
|
||||
(1 row)
|
||||
|
||||
select gms_i18n.string_to_raw('测试', 'utf8');
|
||||
string_to_raw
|
||||
---------------
|
||||
E6B58BE8AF95
|
||||
(1 row)
|
||||
|
||||
select gms_i18n.string_to_raw('测试', '');
|
||||
string_to_raw
|
||||
---------------
|
||||
E6B58BE8AF95
|
||||
(1 row)
|
||||
|
||||
select gms_i18n.string_to_raw('测试');
|
||||
string_to_raw
|
||||
---------------
|
||||
E6B58BE8AF95
|
||||
(1 row)
|
||||
|
||||
select gms_i18n.string_to_raw('', 'utf8');
|
||||
string_to_raw
|
||||
---------------
|
||||
|
||||
(1 row)
|
||||
|
||||
select gms_i18n.string_to_raw('', '');
|
||||
string_to_raw
|
||||
---------------
|
||||
|
||||
(1 row)
|
||||
|
||||
select gms_i18n.string_to_raw('');
|
||||
string_to_raw
|
||||
---------------
|
||||
|
||||
(1 row)
|
||||
|
||||
select gms_i18n.string_to_raw('测试', 'unvalid_charset');
|
||||
ERROR: invalid destination encoding name "unvalid_charset"
|
||||
CONTEXT: referenced column: string_to_raw
|
||||
select gms_i18n.string_to_raw('测试', 'gbk');
|
||||
string_to_raw
|
||||
---------------
|
||||
B2E2CAD4
|
||||
(1 row)
|
||||
|
||||
select gms_i18n.string_to_raw('测试', 'euc_cn');
|
||||
string_to_raw
|
||||
---------------
|
||||
B2E2CAD4
|
||||
(1 row)
|
||||
|
||||
select gms_i18n.string_to_raw('測試', 'big5');
|
||||
string_to_raw
|
||||
---------------
|
||||
B4FAB8D5
|
||||
(1 row)
|
||||
|
||||
select gms_i18n.string_to_raw();
|
||||
ERROR: function gms_i18n.string_to_raw() does not exist
|
||||
LINE 1: select gms_i18n.string_to_raw();
|
||||
^
|
||||
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
|
||||
CONTEXT: referenced column: string_to_raw
|
||||
reset search_path;
|
||||
drop schema gms_i18n_test cascade;
|
||||
17
contrib/gms_i18n/gms_i18n--1.0.sql
Normal file
17
contrib/gms_i18n/gms_i18n--1.0.sql
Normal file
@ -0,0 +1,17 @@
|
||||
/* contrib/gms_i18n/gms_i18n--1.0.sql */
|
||||
|
||||
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
|
||||
\echo Use "CREATE EXTENSION gms_i18n" to load this file. \quit
|
||||
|
||||
CREATE SCHEMA gms_i18n;
|
||||
GRANT USAGE ON SCHEMA gms_i18n TO PUBLIC;
|
||||
|
||||
CREATE OR REPLACE FUNCTION gms_i18n.raw_to_char(IN rawdata raw, IN charset varchar2 DEFAULT NULL)
|
||||
RETURNS varchar2
|
||||
AS 'MODULE_PATHNAME', 'gms_i18n_raw_to_char'
|
||||
LANGUAGE C IMMUTABLE;
|
||||
|
||||
CREATE OR REPLACE FUNCTION gms_i18n.string_to_raw(IN strdata varchar2, IN charset varchar2 DEFAULT NULL)
|
||||
RETURNS raw
|
||||
AS 'MODULE_PATHNAME', 'gms_i18n_string_to_raw'
|
||||
LANGUAGE C IMMUTABLE;
|
||||
5
contrib/gms_i18n/gms_i18n.control
Normal file
5
contrib/gms_i18n/gms_i18n.control
Normal file
@ -0,0 +1,5 @@
|
||||
# gms_i18n extension
|
||||
comment = 'collection of i18n for PL/SQL applications'
|
||||
default_version = '1.0'
|
||||
module_pathname = '$libdir/gms_i18n'
|
||||
relocatable = true
|
||||
91
contrib/gms_i18n/gms_i18n.cpp
Normal file
91
contrib/gms_i18n/gms_i18n.cpp
Normal file
@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Technologies Co.,Ltd.
|
||||
*
|
||||
* openGauss is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
*
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
* --------------------------------------------------------------------------------------
|
||||
*
|
||||
* gms_i18n.cpp
|
||||
* gms_i18n package
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* contrib/gms_i18n/gms_i18n.cpp
|
||||
*
|
||||
* --------------------------------------------------------------------------------------
|
||||
*/
|
||||
#include "postgres.h"
|
||||
#include "utils/builtins.h"
|
||||
|
||||
#include "gms_i18n.h"
|
||||
|
||||
PG_MODULE_MAGIC;
|
||||
|
||||
PG_FUNCTION_INFO_V1(gms_i18n_raw_to_char);
|
||||
PG_FUNCTION_INFO_V1(gms_i18n_string_to_raw);
|
||||
|
||||
Datum gms_i18n_raw_to_char(PG_FUNCTION_ARGS)
|
||||
{
|
||||
Datum raw = PG_GETARG_DATUM(0);
|
||||
Datum src_encoding_name;
|
||||
Datum dest_encoding_name;
|
||||
Datum result;
|
||||
|
||||
if (PG_ARGISNULL(0)) {
|
||||
PG_RETURN_NULL();
|
||||
}
|
||||
|
||||
dest_encoding_name = DirectFunctionCall1(namein, CStringGetDatum(u_sess->mb_cxt.DatabaseEncoding->name));
|
||||
|
||||
if (PG_ARGISNULL(1)) {
|
||||
src_encoding_name = dest_encoding_name;
|
||||
} else {
|
||||
src_encoding_name = DirectFunctionCall1(text_name, PG_GETARG_DATUM(1));
|
||||
}
|
||||
|
||||
/*
|
||||
* pg_convert expects a bytea as its first argument. We're passing it a
|
||||
* raw argument here, relying on the fact that they are both in fact
|
||||
* varlena types, and thus structurally identical.
|
||||
*/
|
||||
result = DirectFunctionCall3(pg_convert, raw, src_encoding_name, dest_encoding_name);
|
||||
|
||||
PG_RETURN_DATUM(result);
|
||||
}
|
||||
|
||||
Datum gms_i18n_string_to_raw(PG_FUNCTION_ARGS)
|
||||
{
|
||||
Datum string = PG_GETARG_DATUM(0);
|
||||
Datum dest_encoding_name;
|
||||
Datum src_encoding_name;
|
||||
Datum result;
|
||||
|
||||
if (PG_ARGISNULL(0)) {
|
||||
PG_RETURN_NULL();
|
||||
}
|
||||
|
||||
src_encoding_name = DirectFunctionCall1(namein, CStringGetDatum(u_sess->mb_cxt.DatabaseEncoding->name));
|
||||
|
||||
if (PG_ARGISNULL(1)) {
|
||||
dest_encoding_name = src_encoding_name;
|
||||
} else {
|
||||
dest_encoding_name = DirectFunctionCall1(text_name, PG_GETARG_DATUM(1));
|
||||
}
|
||||
|
||||
/*
|
||||
* pg_convert expects a bytea as its first argument. We're passing it a
|
||||
* varchar2 argument here, relying on the fact that they are both in fact
|
||||
* varlena types, and thus structurally identical.
|
||||
*/
|
||||
result = DirectFunctionCall3(pg_convert, string, src_encoding_name, dest_encoding_name);
|
||||
|
||||
PG_RETURN_DATUM(result);
|
||||
}
|
||||
19
contrib/gms_i18n/gms_i18n.h
Normal file
19
contrib/gms_i18n/gms_i18n.h
Normal file
@ -0,0 +1,19 @@
|
||||
/*---------------------------------------------------------------------------------------*
|
||||
* gms_i18n.h
|
||||
*
|
||||
* Definition about gms_i18n package.
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* contrib/gms_i18n/gms_i18n.h
|
||||
*
|
||||
* ---------------------------------------------------------------------------------------
|
||||
*/
|
||||
#ifndef __GMS_I18N__
|
||||
#define __GMS_I18N__
|
||||
|
||||
#include "postgres.h"
|
||||
|
||||
extern "C" Datum gms_i18n_raw_to_char(PG_FUNCTION_ARGS);
|
||||
extern "C" Datum gms_i18n_string_to_raw(PG_FUNCTION_ARGS);
|
||||
|
||||
#endif // __GMS_I18N__
|
||||
34
contrib/gms_i18n/sql/gms_i18n.sql
Normal file
34
contrib/gms_i18n/sql/gms_i18n.sql
Normal file
@ -0,0 +1,34 @@
|
||||
create extension gms_i18n;
|
||||
create schema gms_i18n_test;
|
||||
set search_path=gms_i18n_test;
|
||||
|
||||
-- test gms_i18n.raw_to_char
|
||||
select gms_i18n.raw_to_char(hextoraw('616263646566C2AA'), 'utf8');
|
||||
select gms_i18n.raw_to_char(hextoraw('e6b58be8af95'), 'utf8');
|
||||
select gms_i18n.raw_to_char(hextoraw('e6b58be8af95'), '');
|
||||
select gms_i18n.raw_to_char(hextoraw('e6b58be8af95'));
|
||||
select gms_i18n.raw_to_char('', 'utf8');
|
||||
select gms_i18n.raw_to_char('', '');
|
||||
select gms_i18n.raw_to_char('');
|
||||
select gms_i18n.raw_to_char(hextoraw('e6b58be8af95'), 'unvalid_charset');
|
||||
select gms_i18n.raw_to_char(hextoraw('b2e2cad4'), 'gbk');
|
||||
select gms_i18n.raw_to_char(hextoraw('b2e2cad4'), 'euc_cn');
|
||||
select gms_i18n.raw_to_char(hextoraw('b4fab8d5'), 'big5');
|
||||
select gms_i18n.raw_to_char();
|
||||
|
||||
-- test gms_i18n.string_to_raw
|
||||
select gms_i18n.string_to_raw('abcdefª', 'utf8');
|
||||
select gms_i18n.string_to_raw('测试', 'utf8');
|
||||
select gms_i18n.string_to_raw('测试', '');
|
||||
select gms_i18n.string_to_raw('测试');
|
||||
select gms_i18n.string_to_raw('', 'utf8');
|
||||
select gms_i18n.string_to_raw('', '');
|
||||
select gms_i18n.string_to_raw('');
|
||||
select gms_i18n.string_to_raw('测试', 'unvalid_charset');
|
||||
select gms_i18n.string_to_raw('测试', 'gbk');
|
||||
select gms_i18n.string_to_raw('测试', 'euc_cn');
|
||||
select gms_i18n.string_to_raw('測試', 'big5');
|
||||
select gms_i18n.string_to_raw();
|
||||
|
||||
reset search_path;
|
||||
drop schema gms_i18n_test cascade;
|
||||
18
contrib/gms_inaddr/CMakeLists.txt
Normal file
18
contrib/gms_inaddr/CMakeLists.txt
Normal file
@ -0,0 +1,18 @@
|
||||
#This is the main CMAKE for build all components.
|
||||
# gms_inaddr.so
|
||||
AUX_SOURCE_DIRECTORY(${PROJECT_OPENGS_DIR}/contrib/gms_inaddr TGT_gms_inaddr_SRC)
|
||||
|
||||
set(gms_inaddr_DEF_OPTIONS ${MACRO_OPTIONS})
|
||||
set(gms_inaddr_COMPILE_OPTIONS ${OPTIMIZE_OPTIONS} ${OS_OPTIONS} ${PROTECT_OPTIONS} ${WARNING_OPTIONS} ${LIB_SECURE_OPTIONS} ${CHECK_OPTIONS})
|
||||
set(gms_inaddr_LINK_OPTIONS ${LIB_LINK_OPTIONS})
|
||||
add_shared_libtarget(gms_inaddr TGT_gms_inaddr_SRC "" "${gms_inaddr_DEF_OPTIONS}" "${gms_inaddr_COMPILE_OPTIONS}" "${gms_inaddr_LINK_OPTIONS}")
|
||||
set_target_properties(gms_inaddr PROPERTIES PREFIX "")
|
||||
|
||||
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/gms_inaddr.control
|
||||
DESTINATION share/postgresql/extension/
|
||||
)
|
||||
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/gms_inaddr--1.0.sql
|
||||
DESTINATION share/postgresql/extension/
|
||||
)
|
||||
install(TARGETS gms_inaddr LIBRARY DESTINATION lib/postgresql)
|
||||
|
||||
25
contrib/gms_inaddr/Makefile
Normal file
25
contrib/gms_inaddr/Makefile
Normal file
@ -0,0 +1,25 @@
|
||||
# contrib/gms_inaddr/Makefile
|
||||
MODULE_big = gms_inaddr
|
||||
OBJS = gms_inaddr.o
|
||||
|
||||
EXTENSION = gms_inaddr
|
||||
DATA = gms_inaddr--1.0.sql
|
||||
|
||||
exclude_option = -fPIE
|
||||
override CPPFLAGS := -fstack-protector-strong $(filter-out $(exclude_option),$(CPPFLAGS))
|
||||
|
||||
REGRESS = gms_inaddr
|
||||
ifdef USE_PGXS
|
||||
PG_CONFIG = pg_config
|
||||
PGXS := $(shell $(PG_CONFIG) --pgxs)
|
||||
include $(PGXS)
|
||||
else
|
||||
subdir = contrib/gms_inaddr
|
||||
top_builddir = ../..
|
||||
include $(top_builddir)/src/Makefile.global
|
||||
regress_home = $(top_builddir)/src/test/regress
|
||||
REGRESS_OPTS = -c 0 -d 1 -r 1 -p 25632 --single_node -w --keep_last_data=false \
|
||||
--regconf=$(regress_home)/regress.conf \
|
||||
--temp-config=$(regress_home)/make_fastcheck_postgresql.conf
|
||||
include $(top_srcdir)/contrib/contrib-global.mk
|
||||
endif
|
||||
1
contrib/gms_inaddr/data/dummy.txt
Normal file
1
contrib/gms_inaddr/data/dummy.txt
Normal file
@ -0,0 +1 @@
|
||||
The openGauss regression needs this file to run.
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user