prestogres 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +4 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +20 -0
- data/LICENSE +202 -0
- data/NOTICE +22 -0
- data/README.md +217 -0
- data/Rakefile +13 -0
- data/VERSION +1 -0
- data/bin/prestogres +254 -0
- data/config/pcp.conf.sample +28 -0
- data/config/pgpool.conf +678 -0
- data/config/pool_hba.conf +84 -0
- data/config/pool_passwd +0 -0
- data/config/postgresql.conf +2 -0
- data/ext/.gitignore +6 -0
- data/ext/depend +26 -0
- data/ext/extconf.rb +4 -0
- data/ext/prestogres_config.c +12 -0
- data/pgpool2/.gitignore +36 -0
- data/pgpool2/AUTHORS +4 -0
- data/pgpool2/COPYING +12 -0
- data/pgpool2/ChangeLog +1 -0
- data/pgpool2/INSTALL +1 -0
- data/pgpool2/Makefile.am +159 -0
- data/pgpool2/Makefile.in +1187 -0
- data/pgpool2/NEWS +4960 -0
- data/pgpool2/README +1 -0
- data/pgpool2/README.euc_jp +1 -0
- data/pgpool2/README.online-recovery +62 -0
- data/pgpool2/TODO +103 -0
- data/pgpool2/ac_func_accept_argtypes.m4 +85 -0
- data/pgpool2/aclocal.m4 +1088 -0
- data/pgpool2/c-compiler.m4 +134 -0
- data/pgpool2/c-library.m4 +325 -0
- data/pgpool2/child.c +2097 -0
- data/pgpool2/config.guess +1532 -0
- data/pgpool2/config.h.in +332 -0
- data/pgpool2/config.sub +1640 -0
- data/pgpool2/configure +15752 -0
- data/pgpool2/configure.in +392 -0
- data/pgpool2/depcomp +522 -0
- data/pgpool2/doc/basebackup.sh +17 -0
- data/pgpool2/doc/pgpool-de.html +4220 -0
- data/pgpool2/doc/pgpool-en.html +5738 -0
- data/pgpool2/doc/pgpool-fr.html +4118 -0
- data/pgpool2/doc/pgpool-ja.css +198 -0
- data/pgpool2/doc/pgpool-ja.html +11279 -0
- data/pgpool2/doc/pgpool-zh_cn.html +4445 -0
- data/pgpool2/doc/pgpool.css +280 -0
- data/pgpool2/doc/pgpool_remote_start +13 -0
- data/pgpool2/doc/recovery.conf.sample +117 -0
- data/pgpool2/doc/tutorial-en.html +707 -0
- data/pgpool2/doc/tutorial-ja.html +422 -0
- data/pgpool2/doc/tutorial-memqcache-en.html +325 -0
- data/pgpool2/doc/tutorial-memqcache-ja.html +370 -0
- data/pgpool2/doc/tutorial-memqcache-zh_cn.html +322 -0
- data/pgpool2/doc/tutorial-watchdog-en.html +306 -0
- data/pgpool2/doc/tutorial-watchdog-ja.html +343 -0
- data/pgpool2/doc/tutorial-watchdog-zh_cn.html +301 -0
- data/pgpool2/doc/tutorial-zh_cn.html +537 -0
- data/pgpool2/doc/watchdog.png +0 -0
- data/pgpool2/doc/wd-en.html +236 -0
- data/pgpool2/doc/wd-en.jpg +0 -0
- data/pgpool2/doc/wd-ja.html +219 -0
- data/pgpool2/doc/wd-ja.jpg +0 -0
- data/pgpool2/doc/wd-zh_cn.html +201 -0
- data/pgpool2/doc/where_to_send_queries.odg +0 -0
- data/pgpool2/doc/where_to_send_queries.pdf +0 -0
- data/pgpool2/general.m4 +166 -0
- data/pgpool2/getopt_long.c +200 -0
- data/pgpool2/getopt_long.h +44 -0
- data/pgpool2/install-sh +251 -0
- data/pgpool2/ltmain.sh +8406 -0
- data/pgpool2/m4/libtool.m4 +7360 -0
- data/pgpool2/m4/ltoptions.m4 +368 -0
- data/pgpool2/m4/ltsugar.m4 +123 -0
- data/pgpool2/m4/ltversion.m4 +23 -0
- data/pgpool2/m4/lt~obsolete.m4 +92 -0
- data/pgpool2/main.c +2971 -0
- data/pgpool2/md5.c +444 -0
- data/pgpool2/md5.h +28 -0
- data/pgpool2/missing +360 -0
- data/pgpool2/mkinstalldirs +40 -0
- data/pgpool2/parser/Makefile.am +50 -0
- data/pgpool2/parser/Makefile.in +559 -0
- data/pgpool2/parser/copyfuncs.c +3310 -0
- data/pgpool2/parser/gram.c +39100 -0
- data/pgpool2/parser/gram.h +940 -0
- data/pgpool2/parser/gram.y +13408 -0
- data/pgpool2/parser/gramparse.h +74 -0
- data/pgpool2/parser/keywords.c +32 -0
- data/pgpool2/parser/keywords.h +39 -0
- data/pgpool2/parser/kwlist.h +425 -0
- data/pgpool2/parser/kwlookup.c +88 -0
- data/pgpool2/parser/list.c +1156 -0
- data/pgpool2/parser/makefuncs.c +518 -0
- data/pgpool2/parser/makefuncs.h +83 -0
- data/pgpool2/parser/memnodes.h +79 -0
- data/pgpool2/parser/nodes.c +29 -0
- data/pgpool2/parser/nodes.h +609 -0
- data/pgpool2/parser/outfuncs.c +5790 -0
- data/pgpool2/parser/parsenodes.h +2615 -0
- data/pgpool2/parser/parser.c +262 -0
- data/pgpool2/parser/parser.h +46 -0
- data/pgpool2/parser/pg_class.h +158 -0
- data/pgpool2/parser/pg_config_manual.h +273 -0
- data/pgpool2/parser/pg_list.h +352 -0
- data/pgpool2/parser/pg_trigger.h +147 -0
- data/pgpool2/parser/pg_wchar.h +492 -0
- data/pgpool2/parser/pool_memory.c +342 -0
- data/pgpool2/parser/pool_memory.h +77 -0
- data/pgpool2/parser/pool_parser.h +222 -0
- data/pgpool2/parser/pool_string.c +121 -0
- data/pgpool2/parser/pool_string.h +37 -0
- data/pgpool2/parser/primnodes.h +1280 -0
- data/pgpool2/parser/scan.c +4094 -0
- data/pgpool2/parser/scan.l +1451 -0
- data/pgpool2/parser/scanner.h +120 -0
- data/pgpool2/parser/scansup.c +221 -0
- data/pgpool2/parser/scansup.h +28 -0
- data/pgpool2/parser/snprintf.c +1102 -0
- data/pgpool2/parser/stringinfo.c +294 -0
- data/pgpool2/parser/stringinfo.h +178 -0
- data/pgpool2/parser/value.c +78 -0
- data/pgpool2/parser/value.h +62 -0
- data/pgpool2/parser/wchar.c +2048 -0
- data/pgpool2/pcp.conf.sample +28 -0
- data/pgpool2/pcp/Makefile.am +40 -0
- data/pgpool2/pcp/Makefile.in +771 -0
- data/pgpool2/pcp/libpcp_ext.h +250 -0
- data/pgpool2/pcp/md5.c +444 -0
- data/pgpool2/pcp/md5.h +28 -0
- data/pgpool2/pcp/pcp.c +1652 -0
- data/pgpool2/pcp/pcp.h +61 -0
- data/pgpool2/pcp/pcp_attach_node.c +172 -0
- data/pgpool2/pcp/pcp_detach_node.c +185 -0
- data/pgpool2/pcp/pcp_error.c +87 -0
- data/pgpool2/pcp/pcp_node_count.c +160 -0
- data/pgpool2/pcp/pcp_node_info.c +198 -0
- data/pgpool2/pcp/pcp_pool_status.c +166 -0
- data/pgpool2/pcp/pcp_proc_count.c +166 -0
- data/pgpool2/pcp/pcp_proc_info.c +261 -0
- data/pgpool2/pcp/pcp_promote_node.c +185 -0
- data/pgpool2/pcp/pcp_recovery_node.c +172 -0
- data/pgpool2/pcp/pcp_stop_pgpool.c +179 -0
- data/pgpool2/pcp/pcp_stream.c +385 -0
- data/pgpool2/pcp/pcp_stream.h +52 -0
- data/pgpool2/pcp/pcp_systemdb_info.c +194 -0
- data/pgpool2/pcp/pcp_watchdog_info.c +211 -0
- data/pgpool2/pcp_child.c +1493 -0
- data/pgpool2/pg_md5.c +305 -0
- data/pgpool2/pgpool.8.in +121 -0
- data/pgpool2/pgpool.conf +553 -0
- data/pgpool2/pgpool.conf.sample +666 -0
- data/pgpool2/pgpool.conf.sample-master-slave +665 -0
- data/pgpool2/pgpool.conf.sample-replication +664 -0
- data/pgpool2/pgpool.conf.sample-stream +664 -0
- data/pgpool2/pgpool.spec +264 -0
- data/pgpool2/pgpool_adm/TODO +7 -0
- data/pgpool2/pgpool_adm/pgpool_adm--1.0.sql +85 -0
- data/pgpool2/pgpool_adm/pgpool_adm.c +558 -0
- data/pgpool2/pgpool_adm/pgpool_adm.control +5 -0
- data/pgpool2/pgpool_adm/pgpool_adm.h +46 -0
- data/pgpool2/pgpool_adm/pgpool_adm.sql.in +85 -0
- data/pgpool2/pool.h +655 -0
- data/pgpool2/pool_auth.c +1390 -0
- data/pgpool2/pool_config.c +5007 -0
- data/pgpool2/pool_config.h +284 -0
- data/pgpool2/pool_config.l +3281 -0
- data/pgpool2/pool_config_md5.c +29 -0
- data/pgpool2/pool_connection_pool.c +812 -0
- data/pgpool2/pool_error.c +242 -0
- data/pgpool2/pool_globals.c +27 -0
- data/pgpool2/pool_hba.c +1723 -0
- data/pgpool2/pool_hba.conf.sample +67 -0
- data/pgpool2/pool_ip.c +567 -0
- data/pgpool2/pool_ip.h +65 -0
- data/pgpool2/pool_ipc.h +38 -0
- data/pgpool2/pool_lobj.c +242 -0
- data/pgpool2/pool_lobj.h +32 -0
- data/pgpool2/pool_memqcache.c +3818 -0
- data/pgpool2/pool_memqcache.h +268 -0
- data/pgpool2/pool_params.c +163 -0
- data/pgpool2/pool_passwd.c +249 -0
- data/pgpool2/pool_passwd.h +41 -0
- data/pgpool2/pool_path.c +193 -0
- data/pgpool2/pool_path.h +81 -0
- data/pgpool2/pool_process_context.c +247 -0
- data/pgpool2/pool_process_context.h +62 -0
- data/pgpool2/pool_process_query.c +5001 -0
- data/pgpool2/pool_process_reporting.c +1671 -0
- data/pgpool2/pool_process_reporting.h +44 -0
- data/pgpool2/pool_proto2.c +671 -0
- data/pgpool2/pool_proto_modules.c +3524 -0
- data/pgpool2/pool_proto_modules.h +185 -0
- data/pgpool2/pool_query_cache.c +1020 -0
- data/pgpool2/pool_query_context.c +1871 -0
- data/pgpool2/pool_query_context.h +105 -0
- data/pgpool2/pool_relcache.c +284 -0
- data/pgpool2/pool_relcache.h +78 -0
- data/pgpool2/pool_rewrite_outfuncs.c +9060 -0
- data/pgpool2/pool_rewrite_query.c +715 -0
- data/pgpool2/pool_rewrite_query.h +192 -0
- data/pgpool2/pool_select_walker.c +1150 -0
- data/pgpool2/pool_select_walker.h +68 -0
- data/pgpool2/pool_sema.c +161 -0
- data/pgpool2/pool_session_context.c +952 -0
- data/pgpool2/pool_session_context.h +203 -0
- data/pgpool2/pool_shmem.c +185 -0
- data/pgpool2/pool_signal.c +158 -0
- data/pgpool2/pool_signal.h +61 -0
- data/pgpool2/pool_ssl.c +339 -0
- data/pgpool2/pool_stream.c +962 -0
- data/pgpool2/pool_stream.h +61 -0
- data/pgpool2/pool_system.c +659 -0
- data/pgpool2/pool_timestamp.c +1215 -0
- data/pgpool2/pool_timestamp.h +38 -0
- data/pgpool2/pool_type.h +171 -0
- data/pgpool2/pool_worker_child.c +384 -0
- data/pgpool2/ps_status.c +404 -0
- data/pgpool2/recovery.c +435 -0
- data/pgpool2/redhat/pgpool.conf.sample.patch +52 -0
- data/pgpool2/redhat/pgpool.init +201 -0
- data/pgpool2/redhat/pgpool.sysconfig +7 -0
- data/pgpool2/redhat/rpm_installer/basebackup-replication.sh +53 -0
- data/pgpool2/redhat/rpm_installer/basebackup-stream.sh +55 -0
- data/pgpool2/redhat/rpm_installer/config_for_script +17 -0
- data/pgpool2/redhat/rpm_installer/failover.sh +64 -0
- data/pgpool2/redhat/rpm_installer/getsources.sh +141 -0
- data/pgpool2/redhat/rpm_installer/install.sh +1363 -0
- data/pgpool2/redhat/rpm_installer/pgpool_recovery_pitr +47 -0
- data/pgpool2/redhat/rpm_installer/pgpool_remote_start +15 -0
- data/pgpool2/redhat/rpm_installer/recovery.conf +4 -0
- data/pgpool2/redhat/rpm_installer/uninstall.sh +57 -0
- data/pgpool2/sample/dist_def_pgbench.sql +73 -0
- data/pgpool2/sample/pgpool.pam +3 -0
- data/pgpool2/sample/pgpool_recovery +20 -0
- data/pgpool2/sample/pgpool_recovery_pitr +19 -0
- data/pgpool2/sample/pgpool_remote_start +13 -0
- data/pgpool2/sample/replicate_def_pgbench.sql +18 -0
- data/pgpool2/sql/insert_lock.sql +15 -0
- data/pgpool2/sql/pgpool-recovery/pgpool-recovery.c +280 -0
- data/pgpool2/sql/pgpool-recovery/pgpool-recovery.sql.in +19 -0
- data/pgpool2/sql/pgpool-recovery/pgpool_recovery--1.0.sql +24 -0
- data/pgpool2/sql/pgpool-recovery/pgpool_recovery.control +5 -0
- data/pgpool2/sql/pgpool-recovery/uninstall_pgpool-recovery.sql +3 -0
- data/pgpool2/sql/pgpool-regclass/pgpool-regclass.c +206 -0
- data/pgpool2/sql/pgpool-regclass/pgpool-regclass.sql.in +4 -0
- data/pgpool2/sql/pgpool-regclass/pgpool_regclass--1.0.sql +7 -0
- data/pgpool2/sql/pgpool-regclass/pgpool_regclass.control +5 -0
- data/pgpool2/sql/pgpool-regclass/uninstall_pgpool-regclass.sql +1 -0
- data/pgpool2/sql/system_db.sql +38 -0
- data/pgpool2/strlcpy.c +85 -0
- data/pgpool2/test/C/test_extended.c +98 -0
- data/pgpool2/test/jdbc/.cvsignore +2 -0
- data/pgpool2/test/jdbc/AutoCommitTest.java +45 -0
- data/pgpool2/test/jdbc/BatchTest.java +55 -0
- data/pgpool2/test/jdbc/ColumnTest.java +60 -0
- data/pgpool2/test/jdbc/CreateTempTableTest.java +48 -0
- data/pgpool2/test/jdbc/InsertTest.java +34 -0
- data/pgpool2/test/jdbc/LockTest.java +36 -0
- data/pgpool2/test/jdbc/PgpoolTest.java +75 -0
- data/pgpool2/test/jdbc/README.euc_jp +73 -0
- data/pgpool2/test/jdbc/RunTest.java +83 -0
- data/pgpool2/test/jdbc/SelectTest.java +37 -0
- data/pgpool2/test/jdbc/UpdateTest.java +32 -0
- data/pgpool2/test/jdbc/expected/CreateTempTable +1 -0
- data/pgpool2/test/jdbc/expected/autocommit +10 -0
- data/pgpool2/test/jdbc/expected/batch +1 -0
- data/pgpool2/test/jdbc/expected/column +100 -0
- data/pgpool2/test/jdbc/expected/insert +1 -0
- data/pgpool2/test/jdbc/expected/lock +100 -0
- data/pgpool2/test/jdbc/expected/select +2 -0
- data/pgpool2/test/jdbc/expected/update +1 -0
- data/pgpool2/test/jdbc/pgpool.properties +7 -0
- data/pgpool2/test/jdbc/prepare.sql +54 -0
- data/pgpool2/test/jdbc/run.sh +6 -0
- data/pgpool2/test/parser/.cvsignore +6 -0
- data/pgpool2/test/parser/README +32 -0
- data/pgpool2/test/parser/expected/copy.out +17 -0
- data/pgpool2/test/parser/expected/create.out +64 -0
- data/pgpool2/test/parser/expected/cursor.out +37 -0
- data/pgpool2/test/parser/expected/delete.out +10 -0
- data/pgpool2/test/parser/expected/drop.out +12 -0
- data/pgpool2/test/parser/expected/insert.out +13 -0
- data/pgpool2/test/parser/expected/misc.out +28 -0
- data/pgpool2/test/parser/expected/prepare.out +4 -0
- data/pgpool2/test/parser/expected/privileges.out +31 -0
- data/pgpool2/test/parser/expected/scanner.out +30 -0
- data/pgpool2/test/parser/expected/select.out +89 -0
- data/pgpool2/test/parser/expected/transaction.out +38 -0
- data/pgpool2/test/parser/expected/update.out +11 -0
- data/pgpool2/test/parser/expected/v84.out +37 -0
- data/pgpool2/test/parser/expected/v90.out +25 -0
- data/pgpool2/test/parser/expected/var.out +22 -0
- data/pgpool2/test/parser/input/alter.sql +2 -0
- data/pgpool2/test/parser/input/copy.sql +17 -0
- data/pgpool2/test/parser/input/create.sql +64 -0
- data/pgpool2/test/parser/input/cursor.sql +37 -0
- data/pgpool2/test/parser/input/delete.sql +10 -0
- data/pgpool2/test/parser/input/drop.sql +12 -0
- data/pgpool2/test/parser/input/insert.sql +13 -0
- data/pgpool2/test/parser/input/misc.sql +28 -0
- data/pgpool2/test/parser/input/prepare.sql +4 -0
- data/pgpool2/test/parser/input/privileges.sql +31 -0
- data/pgpool2/test/parser/input/scanner.sql +34 -0
- data/pgpool2/test/parser/input/select.sql +89 -0
- data/pgpool2/test/parser/input/transaction.sql +38 -0
- data/pgpool2/test/parser/input/update.sql +11 -0
- data/pgpool2/test/parser/input/v84.sql +37 -0
- data/pgpool2/test/parser/input/v90.sql +38 -0
- data/pgpool2/test/parser/input/var.sql +22 -0
- data/pgpool2/test/parser/main.c +96 -0
- data/pgpool2/test/parser/parse_schedule +16 -0
- data/pgpool2/test/parser/pool.h +13 -0
- data/pgpool2/test/parser/run-test +62 -0
- data/pgpool2/test/pdo-test/README.euc_jp +58 -0
- data/pgpool2/test/pdo-test/SQLlist/test1.sql +3 -0
- data/pgpool2/test/pdo-test/SQLlist/test2.sql +3 -0
- data/pgpool2/test/pdo-test/collections.inc +11 -0
- data/pgpool2/test/pdo-test/def.inc +7 -0
- data/pgpool2/test/pdo-test/log.txt +0 -0
- data/pgpool2/test/pdo-test/mod/database.inc +36 -0
- data/pgpool2/test/pdo-test/mod/def.inc +0 -0
- data/pgpool2/test/pdo-test/mod/errorhandler.inc +27 -0
- data/pgpool2/test/pdo-test/pdotest.php +11 -0
- data/pgpool2/test/pdo-test/regsql.inc +56 -0
- data/pgpool2/test/pgpool_setup +898 -0
- data/pgpool2/test/regression/README +39 -0
- data/pgpool2/test/regression/clean.sh +21 -0
- data/pgpool2/test/regression/libs.sh +16 -0
- data/pgpool2/test/regression/regress.sh +166 -0
- data/pgpool2/test/regression/tests/001.load_balance/test.sh +128 -0
- data/pgpool2/test/regression/tests/002.native_replication/PgTester.java +47 -0
- data/pgpool2/test/regression/tests/002.native_replication/create.sql +6 -0
- data/pgpool2/test/regression/tests/002.native_replication/test.sh +71 -0
- data/pgpool2/test/regression/tests/003.failover/expected.r +6 -0
- data/pgpool2/test/regression/tests/003.failover/expected.s +6 -0
- data/pgpool2/test/regression/tests/003.failover/test.sh +45 -0
- data/pgpool2/test/regression/tests/004.watchdog/master.conf +12 -0
- data/pgpool2/test/regression/tests/004.watchdog/standby.conf +19 -0
- data/pgpool2/test/regression/tests/004.watchdog/test.sh +52 -0
- data/pgpool2/test/regression/tests/050.bug58/test.sh +50 -0
- data/pgpool2/test/regression/tests/051.bug60/bug.sql +12 -0
- data/pgpool2/test/regression/tests/051.bug60/database-clean.sql +6 -0
- data/pgpool2/test/regression/tests/051.bug60/database-setup.sql +28 -0
- data/pgpool2/test/regression/tests/051.bug60/test.sh +79 -0
- data/pgpool2/test/regression/tests/052.do_query/test.sh +44 -0
- data/pgpool2/test/regression/tests/053.insert_lock_hangs/test.sh +81 -0
- data/pgpool2/test/regression/tests/054.postgres_fdw/test.sh +67 -0
- data/pgpool2/test/regression/tests/055.backend_all_down/test.sh +52 -0
- data/pgpool2/test/regression/tests/056.bug63/jdbctest2.java +66 -0
- data/pgpool2/test/regression/tests/056.bug63/test.sh +47 -0
- data/pgpool2/test/regression/tests/057.bug61/test.sh +40 -0
- data/pgpool2/test/regression/tests/058.bug68/jdbctest3.java +45 -0
- data/pgpool2/test/regression/tests/058.bug68/test.sh +47 -0
- data/pgpool2/test/timestamp/expected/insert.out +16 -0
- data/pgpool2/test/timestamp/expected/misc.out +3 -0
- data/pgpool2/test/timestamp/expected/update.out +6 -0
- data/pgpool2/test/timestamp/input/insert.sql +16 -0
- data/pgpool2/test/timestamp/input/misc.sql +3 -0
- data/pgpool2/test/timestamp/input/update.sql +6 -0
- data/pgpool2/test/timestamp/main.c +129 -0
- data/pgpool2/test/timestamp/parse_schedule +3 -0
- data/pgpool2/test/timestamp/run-test +69 -0
- data/pgpool2/version.h +1 -0
- data/pgpool2/watchdog/Makefile.am +17 -0
- data/pgpool2/watchdog/Makefile.in +505 -0
- data/pgpool2/watchdog/test/stab.c +266 -0
- data/pgpool2/watchdog/test/test.c +85 -0
- data/pgpool2/watchdog/test/wd_child_t.c +87 -0
- data/pgpool2/watchdog/test/wd_lifecheck_t.c +87 -0
- data/pgpool2/watchdog/test/wd_packet_t.c +87 -0
- data/pgpool2/watchdog/test/wd_ping_t.c +20 -0
- data/pgpool2/watchdog/watchdog.c +408 -0
- data/pgpool2/watchdog/watchdog.h +209 -0
- data/pgpool2/watchdog/wd_child.c +444 -0
- data/pgpool2/watchdog/wd_ext.h +123 -0
- data/pgpool2/watchdog/wd_heartbeat.c +577 -0
- data/pgpool2/watchdog/wd_if.c +216 -0
- data/pgpool2/watchdog/wd_init.c +126 -0
- data/pgpool2/watchdog/wd_interlock.c +347 -0
- data/pgpool2/watchdog/wd_lifecheck.c +512 -0
- data/pgpool2/watchdog/wd_list.c +429 -0
- data/pgpool2/watchdog/wd_packet.c +1159 -0
- data/pgpool2/watchdog/wd_ping.c +330 -0
- data/pgpool2/ylwrap +223 -0
- data/pgsql/presto_client.py +346 -0
- data/pgsql/prestogres.py +156 -0
- data/pgsql/setup_functions.sql +21 -0
- data/pgsql/setup_language.sql +3 -0
- data/prestogres.gemspec +23 -0
- metadata +496 -0
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
/* -*-pgsql-c-*- */
|
|
2
|
+
/*
|
|
3
|
+
*
|
|
4
|
+
* $Header$
|
|
5
|
+
*
|
|
6
|
+
* pgpool: a language independent connection pool server for PostgreSQL
|
|
7
|
+
* written by Tatsuo Ishii
|
|
8
|
+
*
|
|
9
|
+
* Copyright (c) 2003-2012 PgPool Global Development Group
|
|
10
|
+
*
|
|
11
|
+
* Permission to use, copy, modify, and distribute this software and
|
|
12
|
+
* its documentation for any purpose and without fee is hereby
|
|
13
|
+
* granted, provided that the above copyright notice appear in all
|
|
14
|
+
* copies and that both that copyright notice and this permission
|
|
15
|
+
* notice appear in supporting documentation, and that the name of the
|
|
16
|
+
* author not be used in advertising or publicity pertaining to
|
|
17
|
+
* distribution of the software without specific, written prior
|
|
18
|
+
* permission. The author makes no representations about the
|
|
19
|
+
* suitability of this software for any purpose. It is provided "as
|
|
20
|
+
* is" without express or implied warranty.
|
|
21
|
+
*
|
|
22
|
+
* pool_memqcache.h: on memory query cache related definitions
|
|
23
|
+
*
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
#ifndef POOL_MEMQCACHE_H
|
|
27
|
+
#define POOL_MEMQCACHE_H
|
|
28
|
+
|
|
29
|
+
#include "pool.h"
|
|
30
|
+
#include <sys/time.h>
|
|
31
|
+
|
|
32
|
+
#define NO_QUERY_CACHE "/*NO QUERY CACHE*/"
|
|
33
|
+
#define NO_QUERY_CACHE_COMMENT_SZ (sizeof(NO_QUERY_CACHE)-1)
|
|
34
|
+
|
|
35
|
+
#define POOL_MD5_HASHKEYLEN 32 /* MD5 hash key length */
|
|
36
|
+
|
|
37
|
+
/*
|
|
38
|
+
* On memory query cache on shmem is divided into fixed length "cache
|
|
39
|
+
* block". Each block is assigned a "cache block id", which is
|
|
40
|
+
* starting with 0.
|
|
41
|
+
*/
|
|
42
|
+
typedef char *POOL_CACH_BLOCK; /* pointer to cache block */
|
|
43
|
+
typedef unsigned int POOL_CACHE_BLOCKID; /* cache block id */
|
|
44
|
+
typedef unsigned int POOL_CACHE_ITEMID; /* cache item id */
|
|
45
|
+
|
|
46
|
+
/*
|
|
47
|
+
* "Cache id" represents "absolute address" of a cache item.
|
|
48
|
+
*/
|
|
49
|
+
typedef struct {
|
|
50
|
+
POOL_CACHE_BLOCKID blockid;
|
|
51
|
+
POOL_CACHE_ITEMID itemid;
|
|
52
|
+
} POOL_CACHEID; /* cache id */
|
|
53
|
+
|
|
54
|
+
/*
|
|
55
|
+
* Each block has management space called "cache block header" at the
|
|
56
|
+
* very beginning of the cache block.
|
|
57
|
+
*/
|
|
58
|
+
|
|
59
|
+
#define POOL_BLOCK_USED 0x0001 /* is this block used? */
|
|
60
|
+
|
|
61
|
+
typedef struct {
|
|
62
|
+
unsigned char flags; /* flags. see above */
|
|
63
|
+
unsigned int num_items; /* number of items */
|
|
64
|
+
unsigned int free_bytes; /* total free space in bytes */
|
|
65
|
+
} POOL_CACHE_BLOCK_HEADER;
|
|
66
|
+
|
|
67
|
+
typedef struct {
|
|
68
|
+
char query_hash[POOL_MD5_HASHKEYLEN];
|
|
69
|
+
} POOL_QUERY_HASH;
|
|
70
|
+
|
|
71
|
+
#define POOL_ITEM_USED 0x0001 /* is this item used? */
|
|
72
|
+
#define POOL_ITEM_HAS_NEXT 0x0002 /* is this item has "next" item? */
|
|
73
|
+
#define POOL_ITEM_DELETED 0x0004 /* is this item deleted? */
|
|
74
|
+
|
|
75
|
+
typedef struct {
|
|
76
|
+
POOL_QUERY_HASH query_hash; /* md5 hashed query signature */
|
|
77
|
+
POOL_CACHEID next; /* next cache item if any */
|
|
78
|
+
unsigned int offset; /* item offset in this block */
|
|
79
|
+
unsigned char flags; /* flags. see above */
|
|
80
|
+
} POOL_CACHE_ITEM_POINTER;
|
|
81
|
+
|
|
82
|
+
/*
|
|
83
|
+
* Each block holds several "cache item", which consists of variable
|
|
84
|
+
* length of Data(header plus RowDescription packet and DataRow
|
|
85
|
+
* packet). Each cache item is assigned "cache item id", which
|
|
86
|
+
* represents the cache item order in a block.
|
|
87
|
+
*/
|
|
88
|
+
|
|
89
|
+
/*
|
|
90
|
+
* "Cache Item" structure holds a SELECT result having several row
|
|
91
|
+
* data in memory cache. Cache item can be used with either shmem or
|
|
92
|
+
* memcached.
|
|
93
|
+
*/
|
|
94
|
+
|
|
95
|
+
/*
|
|
96
|
+
* "Cache Item header" structure is used to manage each cache item.
|
|
97
|
+
*/
|
|
98
|
+
typedef struct {
|
|
99
|
+
unsigned int total_length; /* total length in bytes including myself */
|
|
100
|
+
time_t timestamp; /* cache creation time */
|
|
101
|
+
} POOL_CACHE_ITEM_HEADER;
|
|
102
|
+
|
|
103
|
+
typedef struct {
|
|
104
|
+
POOL_CACHE_ITEM_HEADER header; /* cache item header */
|
|
105
|
+
char data[1]; /* variable length data follows */
|
|
106
|
+
} POOL_CACHE_ITEM;
|
|
107
|
+
|
|
108
|
+
/*
|
|
109
|
+
* Possible the largest free space size in bytes
|
|
110
|
+
*/
|
|
111
|
+
#define POOL_MAX_FREE_SPACE (pool_config->memqcache_cache_block_size - sizeof(POOL_CACHE_BLOCK_HEADER))
|
|
112
|
+
|
|
113
|
+
#define POOL_FSMM_RATIO (pool_config->memqcache_cache_block_size/256)
|
|
114
|
+
|
|
115
|
+
#define MAX_VALUE 8192
|
|
116
|
+
#define MAX_KEY 256
|
|
117
|
+
|
|
118
|
+
extern int memcached_connect(void);
|
|
119
|
+
extern void memcached_disconnect(void);
|
|
120
|
+
extern void memqcache_register(char kind, POOL_CONNECTION *frontend, char *data, int data_len);
|
|
121
|
+
|
|
122
|
+
/*
|
|
123
|
+
* Cache key
|
|
124
|
+
*/
|
|
125
|
+
typedef union
|
|
126
|
+
{
|
|
127
|
+
POOL_CACHEID cacheid; /* cache key (shmem configuration) */
|
|
128
|
+
char hashkey[POOL_MD5_HASHKEYLEN]; /* cache key (memcached configuration) */
|
|
129
|
+
} POOL_CACHEKEY;
|
|
130
|
+
|
|
131
|
+
/*
|
|
132
|
+
* Internal buffer structure
|
|
133
|
+
*/
|
|
134
|
+
typedef struct
|
|
135
|
+
{
|
|
136
|
+
size_t bufsize; /* buffer size */
|
|
137
|
+
size_t buflen; /* used length */
|
|
138
|
+
char *buf; /* buffer */
|
|
139
|
+
} POOL_INTERNAL_BUFFER;
|
|
140
|
+
|
|
141
|
+
/*
|
|
142
|
+
* Temporary query cache buffer
|
|
143
|
+
*/
|
|
144
|
+
typedef struct
|
|
145
|
+
{
|
|
146
|
+
bool is_exceeded; /* true if data size exceeds memqcache_maxcache */
|
|
147
|
+
bool is_discarded; /* true if this cache entry is discarded */
|
|
148
|
+
char *query; /* SELECT query */
|
|
149
|
+
POOL_INTERNAL_BUFFER *buffer;
|
|
150
|
+
int num_oids;
|
|
151
|
+
POOL_INTERNAL_BUFFER *oids;
|
|
152
|
+
} POOL_TEMP_QUERY_CACHE;
|
|
153
|
+
|
|
154
|
+
/*
|
|
155
|
+
* Temporary query cache buffer array
|
|
156
|
+
*/
|
|
157
|
+
typedef struct
|
|
158
|
+
{
|
|
159
|
+
int num_caches;
|
|
160
|
+
int array_size;
|
|
161
|
+
POOL_TEMP_QUERY_CACHE *caches[1]; /* actual data continues... */
|
|
162
|
+
} POOL_QUERY_CACHE_ARRAY;
|
|
163
|
+
|
|
164
|
+
/*
|
|
165
|
+
* Query cache statistics structure. This area must be placed on shared
|
|
166
|
+
* memory and protected by QUERY_CACHE_STATS_SEM.
|
|
167
|
+
*/
|
|
168
|
+
typedef struct
|
|
169
|
+
{
|
|
170
|
+
time_t start_time; /* start time when the statistics begins */
|
|
171
|
+
long long int num_selects; /* number of successful SELECTs */
|
|
172
|
+
long long int num_cache_hits; /* number of SELECTs extracted from cache */
|
|
173
|
+
} POOL_QUERY_CACHE_STATS;
|
|
174
|
+
|
|
175
|
+
/*
|
|
176
|
+
* Shared memory cache stats interface.
|
|
177
|
+
*/
|
|
178
|
+
typedef struct
|
|
179
|
+
{
|
|
180
|
+
int num_hash_entries; /* number of total hash entries */
|
|
181
|
+
int used_hash_entries; /* number of used hash entries */
|
|
182
|
+
int num_cache_entries; /* number of used cache entries */
|
|
183
|
+
long used_cache_entries_size; /* total size of used cache entries */
|
|
184
|
+
long free_cache_entries_size; /* total size of free(usable) cache entries */
|
|
185
|
+
long fragment_cache_entries_size; /* total size of fragment(unusable) cache entries */
|
|
186
|
+
POOL_QUERY_CACHE_STATS cache_stats;
|
|
187
|
+
} POOL_SHMEM_STATS;
|
|
188
|
+
|
|
189
|
+
/*--------------------------------------------------------------------------------
|
|
190
|
+
* On shared memory hash table implementation
|
|
191
|
+
*--------------------------------------------------------------------------------
|
|
192
|
+
*/
|
|
193
|
+
|
|
194
|
+
/* Hash element */
|
|
195
|
+
typedef struct POOL_HASH_ELEMENT
|
|
196
|
+
{
|
|
197
|
+
struct POOL_HASH_ELEMENT *next; /* link to next entry */
|
|
198
|
+
POOL_QUERY_HASH hashkey; /* MD5 hash key */
|
|
199
|
+
POOL_CACHEID cacheid; /* logical location of this cache element */
|
|
200
|
+
} POOL_HASH_ELEMENT;
|
|
201
|
+
|
|
202
|
+
typedef uint32 POOL_HASH_KEY;
|
|
203
|
+
|
|
204
|
+
/* Hash header element */
|
|
205
|
+
typedef struct
|
|
206
|
+
{
|
|
207
|
+
POOL_HASH_KEY hashkey; /* hash key */
|
|
208
|
+
POOL_HASH_ELEMENT *element; /* hash element */
|
|
209
|
+
} POOL_HEADER_ELEMENT;
|
|
210
|
+
|
|
211
|
+
/* Hash header */
|
|
212
|
+
typedef struct
|
|
213
|
+
{
|
|
214
|
+
long nhash; /* number of hash keys (power of 2) */
|
|
215
|
+
uint32 mask; /* mask for hash function */
|
|
216
|
+
POOL_HEADER_ELEMENT elements[1]; /* actual hash elements follows */
|
|
217
|
+
} POOL_HASH_HEADER;
|
|
218
|
+
|
|
219
|
+
extern int pool_hash_init(int nelements);
|
|
220
|
+
extern POOL_CACHEID *pool_hash_search(POOL_QUERY_HASH *key);
|
|
221
|
+
extern int pool_hash_delete(POOL_QUERY_HASH *key);
|
|
222
|
+
extern uint32 hash_any(unsigned char *k, int keylen);
|
|
223
|
+
|
|
224
|
+
extern POOL_STATUS pool_fetch_from_memory_cache(POOL_CONNECTION *frontend,
|
|
225
|
+
POOL_CONNECTION_POOL *backend,
|
|
226
|
+
char *contents, bool *foundp);
|
|
227
|
+
|
|
228
|
+
extern bool pool_is_likely_select(char *query);
|
|
229
|
+
extern bool pool_is_table_in_black_list(const char *table_name);
|
|
230
|
+
extern bool pool_is_table_in_white_list(const char *table_name);
|
|
231
|
+
extern bool pool_is_allow_to_cache(Node *node, char *query);
|
|
232
|
+
extern int pool_extract_table_oids(Node *node, int **oidsp);
|
|
233
|
+
extern void pool_add_dml_table_oid(int oid);
|
|
234
|
+
extern void pool_discard_oid_maps(void);
|
|
235
|
+
extern int pool_get_database_oid_from_dbname(char *dbname);
|
|
236
|
+
extern void pool_discard_oid_maps_by_db(int dboid);
|
|
237
|
+
extern bool pool_is_shmem_cache(void);
|
|
238
|
+
extern size_t pool_shared_memory_cache_size(void);
|
|
239
|
+
extern int pool_init_memory_cache(size_t size);
|
|
240
|
+
extern void pool_clear_memory_cache(void);
|
|
241
|
+
extern size_t pool_shared_memory_fsmm_size(void);
|
|
242
|
+
extern int pool_init_fsmm(size_t size);
|
|
243
|
+
extern void pool_allocate_fsmm_clock_hand(void);
|
|
244
|
+
|
|
245
|
+
extern POOL_QUERY_CACHE_ARRAY *pool_create_query_cache_array(void);
|
|
246
|
+
extern void pool_discard_query_cache_array(POOL_QUERY_CACHE_ARRAY *cache_array);
|
|
247
|
+
|
|
248
|
+
extern POOL_TEMP_QUERY_CACHE *pool_create_temp_query_cache(char *query);
|
|
249
|
+
extern void pool_handle_query_cache(POOL_CONNECTION_POOL *backend, char *query, Node *node, char state);
|
|
250
|
+
|
|
251
|
+
extern int pool_init_memqcache_stats(void);
|
|
252
|
+
extern POOL_QUERY_CACHE_STATS *pool_get_memqcache_stats(void);
|
|
253
|
+
extern void pool_reset_memqcache_stats(void);
|
|
254
|
+
extern long long int pool_stats_count_up_num_selects(long long int num);
|
|
255
|
+
extern long long int pool_stats_count_up_num_cache_hits(void);
|
|
256
|
+
extern long long int pool_tmp_stats_count_up_num_selects(void);
|
|
257
|
+
extern long long int pool_tmp_stats_get_num_selects(void);
|
|
258
|
+
extern void pool_tmp_stats_reset_num_selects(void);
|
|
259
|
+
extern POOL_SHMEM_STATS *pool_get_shmem_storage_stats(void);
|
|
260
|
+
|
|
261
|
+
extern POOL_TEMP_QUERY_CACHE *pool_get_current_cache(void);
|
|
262
|
+
extern POOL_TEMP_QUERY_CACHE *pool_get_current_cache(void);
|
|
263
|
+
extern void pool_discard_temp_query_cache(POOL_TEMP_QUERY_CACHE *temp_cache);
|
|
264
|
+
|
|
265
|
+
extern void pool_shmem_lock(void);
|
|
266
|
+
extern void pool_shmem_unlock(void);
|
|
267
|
+
|
|
268
|
+
#endif /* POOL_MEMQCACHE_H */
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/* -*-pgsql-c-*- */
|
|
2
|
+
/*
|
|
3
|
+
* $Header$
|
|
4
|
+
*
|
|
5
|
+
* pgpool: a language independent connection pool server for PostgreSQL
|
|
6
|
+
* written by Tatsuo Ishii
|
|
7
|
+
*
|
|
8
|
+
* Copyright (c) 2003-2008 PgPool Global Development Group
|
|
9
|
+
*
|
|
10
|
+
* Permission to use, copy, modify, and distribute this software and
|
|
11
|
+
* its documentation for any purpose and without fee is hereby
|
|
12
|
+
* granted, provided that the above copyright notice appear in all
|
|
13
|
+
* copies and that both that copyright notice and this permission
|
|
14
|
+
* notice appear in supporting documentation, and that the name of the
|
|
15
|
+
* author not be used in advertising or publicity pertaining to
|
|
16
|
+
* distribution of the software without specific, written prior
|
|
17
|
+
* permission. The author makes no representations about the
|
|
18
|
+
* suitability of this software for any purpose. It is provided "as
|
|
19
|
+
* is" without express or implied warranty.
|
|
20
|
+
*
|
|
21
|
+
* params.c: Parameter Status handling routines
|
|
22
|
+
*
|
|
23
|
+
*/
|
|
24
|
+
#include "config.h"
|
|
25
|
+
|
|
26
|
+
#include <stdlib.h>
|
|
27
|
+
#include <string.h>
|
|
28
|
+
|
|
29
|
+
#include "pool.h"
|
|
30
|
+
#include "parser/parser.h"
|
|
31
|
+
|
|
32
|
+
#define MAX_PARAM_ITEMS 128
|
|
33
|
+
|
|
34
|
+
/*
|
|
35
|
+
* initialize parameter structure
|
|
36
|
+
*/
|
|
37
|
+
int pool_init_params(ParamStatus *params)
|
|
38
|
+
{
|
|
39
|
+
params->num = 0;
|
|
40
|
+
params->names = malloc(MAX_PARAM_ITEMS*sizeof(char *));
|
|
41
|
+
if (params->names == NULL)
|
|
42
|
+
{
|
|
43
|
+
pool_error("pool_init_params: cannot allocate memory");
|
|
44
|
+
return -1;
|
|
45
|
+
}
|
|
46
|
+
params->values = malloc(MAX_PARAM_ITEMS*sizeof(char *));
|
|
47
|
+
if (params->values == NULL)
|
|
48
|
+
{
|
|
49
|
+
pool_error("pool_init_params: cannot allocate memory");
|
|
50
|
+
return -1;
|
|
51
|
+
}
|
|
52
|
+
return 0;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/*
|
|
56
|
+
* discard parameter structure
|
|
57
|
+
*/
|
|
58
|
+
void pool_discard_params(ParamStatus *params)
|
|
59
|
+
{
|
|
60
|
+
int i;
|
|
61
|
+
|
|
62
|
+
for (i=0;i<params->num;i++)
|
|
63
|
+
{
|
|
64
|
+
free(params->names[i]);
|
|
65
|
+
free(params->values[i]);
|
|
66
|
+
}
|
|
67
|
+
free(params->names);
|
|
68
|
+
free(params->values);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/*
|
|
72
|
+
* find param value by name. if found, its value is returned
|
|
73
|
+
* also, pos is set
|
|
74
|
+
* if not found, NULL is returned
|
|
75
|
+
*/
|
|
76
|
+
char *pool_find_name(ParamStatus *params, char *name, int *pos)
|
|
77
|
+
{
|
|
78
|
+
int i;
|
|
79
|
+
|
|
80
|
+
for (i=0;i<params->num;i++)
|
|
81
|
+
{
|
|
82
|
+
if (!strcmp(name, params->names[i]))
|
|
83
|
+
{
|
|
84
|
+
*pos = i;
|
|
85
|
+
return params->values[i];
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return NULL;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/*
|
|
92
|
+
* return name and value by index.
|
|
93
|
+
*/
|
|
94
|
+
int pool_get_param(ParamStatus *params, int index, char **name, char **value)
|
|
95
|
+
{
|
|
96
|
+
if (index < 0 || index >= params->num)
|
|
97
|
+
return -1;
|
|
98
|
+
|
|
99
|
+
*name = params->names[index];
|
|
100
|
+
*value = params->values[index];
|
|
101
|
+
|
|
102
|
+
return 0;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/*
|
|
106
|
+
* add or replace name/value pair
|
|
107
|
+
*/
|
|
108
|
+
int pool_add_param(ParamStatus *params, char *name, char *value)
|
|
109
|
+
{
|
|
110
|
+
int pos;
|
|
111
|
+
|
|
112
|
+
if (pool_find_name(params, name, &pos))
|
|
113
|
+
{
|
|
114
|
+
/* name already exists */
|
|
115
|
+
if (strlen(params->values[pos]) < strlen(value))
|
|
116
|
+
{
|
|
117
|
+
params->values[pos] = realloc(params->values[pos], strlen(value) + 1);
|
|
118
|
+
if (params->values[pos] == NULL)
|
|
119
|
+
{
|
|
120
|
+
pool_error("pool_init_params: cannot allocate memory");
|
|
121
|
+
return -1;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
strcpy(params->values[pos], value);
|
|
125
|
+
}
|
|
126
|
+
else
|
|
127
|
+
{
|
|
128
|
+
int num;
|
|
129
|
+
|
|
130
|
+
/* add name/value pair */
|
|
131
|
+
if (params->num >= MAX_PARAM_ITEMS)
|
|
132
|
+
{
|
|
133
|
+
pool_error("pool_add_param: no more room for num");
|
|
134
|
+
return -1;
|
|
135
|
+
}
|
|
136
|
+
num = params->num;
|
|
137
|
+
params->names[num] = strdup(name);
|
|
138
|
+
if (params->names[num] == NULL)
|
|
139
|
+
{
|
|
140
|
+
pool_error("pool_init_params: cannot allocate memory");
|
|
141
|
+
return -1;
|
|
142
|
+
}
|
|
143
|
+
params->values[num] = strdup(value);
|
|
144
|
+
if (params->values[num] == NULL)
|
|
145
|
+
{
|
|
146
|
+
pool_error("pool_init_params: cannot allocate memory");
|
|
147
|
+
return -1;
|
|
148
|
+
}
|
|
149
|
+
params->num++;
|
|
150
|
+
}
|
|
151
|
+
parser_set_param(name, value);
|
|
152
|
+
return 0;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
void pool_param_debug_print(ParamStatus *params)
|
|
156
|
+
{
|
|
157
|
+
int i;
|
|
158
|
+
|
|
159
|
+
for (i=0;i<params->num;i++)
|
|
160
|
+
{
|
|
161
|
+
pool_debug("No.%d: name: %s value: %s", i, params->names[i], params->values[i]);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
/* -*-pgsql-c-*- */
|
|
2
|
+
/*
|
|
3
|
+
*
|
|
4
|
+
* $Header$
|
|
5
|
+
*
|
|
6
|
+
* pgpool: a language independent connection pool server for PostgreSQL
|
|
7
|
+
* written by Tatsuo Ishii
|
|
8
|
+
*
|
|
9
|
+
* Copyright (c) 2003-2013 PgPool Global Development Group
|
|
10
|
+
*
|
|
11
|
+
* Permission to use, copy, modify, and distribute this software and
|
|
12
|
+
* its documentation for any purpose and without fee is hereby
|
|
13
|
+
* granted, provided that the above copyright notice appear in all
|
|
14
|
+
* copies and that both that copyright notice and this permission
|
|
15
|
+
* notice appear in supporting documentation, and that the name of the
|
|
16
|
+
* author not be used in advertising or publicity pertaining to
|
|
17
|
+
* distribution of the software without specific, written prior
|
|
18
|
+
* permission. The author makes no representations about the
|
|
19
|
+
* suitability of this software for any purpose. It is provided "as
|
|
20
|
+
* is" without express or implied warranty.
|
|
21
|
+
*
|
|
22
|
+
* Module to handle pool_passwd
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
#include <string.h>
|
|
26
|
+
#include <errno.h>
|
|
27
|
+
|
|
28
|
+
#include "pool.h"
|
|
29
|
+
#include "pool_passwd.h"
|
|
30
|
+
#include "md5.h"
|
|
31
|
+
|
|
32
|
+
static FILE *passwd_fd = NULL; /* File descriptor for pool_passwd */
|
|
33
|
+
static char saved_passwd_filename[POOLMAXPATHLEN+1];
|
|
34
|
+
|
|
35
|
+
/*
|
|
36
|
+
* Initialize this module.
|
|
37
|
+
* If pool_passwd does not exist yet, create it.
|
|
38
|
+
* Open pool_passwd.
|
|
39
|
+
*/
|
|
40
|
+
void pool_init_pool_passwd(char *pool_passwd_filename)
|
|
41
|
+
{
|
|
42
|
+
if (passwd_fd)
|
|
43
|
+
return;
|
|
44
|
+
|
|
45
|
+
if (saved_passwd_filename[0] == '\0')
|
|
46
|
+
{
|
|
47
|
+
int len = strlen(pool_passwd_filename);
|
|
48
|
+
memcpy(saved_passwd_filename, pool_passwd_filename, len);
|
|
49
|
+
saved_passwd_filename[len] = '\0';
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
passwd_fd = fopen(pool_passwd_filename, "r+");
|
|
53
|
+
if (!passwd_fd)
|
|
54
|
+
{
|
|
55
|
+
if (errno == ENOENT)
|
|
56
|
+
{
|
|
57
|
+
/* The file does not exist yet. Create it. */
|
|
58
|
+
passwd_fd = fopen(pool_passwd_filename, "w+");
|
|
59
|
+
if (passwd_fd)
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
pool_error("pool_init_pool_passwd: couldn't open %s. reason: %s",
|
|
64
|
+
pool_passwd_filename, strerror(errno));
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/*
|
|
69
|
+
* Update passwd. If the user does not exist, create a new entry.
|
|
70
|
+
* Returns 0 on success non 0 otherwise.
|
|
71
|
+
*/
|
|
72
|
+
int pool_create_passwdent(char *username, char *passwd)
|
|
73
|
+
{
|
|
74
|
+
int len;
|
|
75
|
+
int c;
|
|
76
|
+
char name[MAX_USER_NAME_LEN];
|
|
77
|
+
char *p;
|
|
78
|
+
int readlen;
|
|
79
|
+
|
|
80
|
+
if (!passwd_fd)
|
|
81
|
+
{
|
|
82
|
+
pool_error("pool_create_passwdent: passwd_fd is NULL");
|
|
83
|
+
return -1;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
len = strlen(passwd);
|
|
87
|
+
if (len != POOL_PASSWD_LEN)
|
|
88
|
+
{
|
|
89
|
+
pool_error("pool_create_passwdent: wrong password length:%d", len);
|
|
90
|
+
return -1;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
rewind(passwd_fd);
|
|
94
|
+
name[0] = '\0';
|
|
95
|
+
|
|
96
|
+
while (!feof(passwd_fd))
|
|
97
|
+
{
|
|
98
|
+
p = name;
|
|
99
|
+
readlen = 0;
|
|
100
|
+
|
|
101
|
+
while (readlen < sizeof(name))
|
|
102
|
+
{
|
|
103
|
+
c = fgetc(passwd_fd);
|
|
104
|
+
if (c == EOF)
|
|
105
|
+
break;
|
|
106
|
+
else if (c == ':')
|
|
107
|
+
break;
|
|
108
|
+
|
|
109
|
+
readlen++;
|
|
110
|
+
*p++ = c;
|
|
111
|
+
}
|
|
112
|
+
*p = '\0';
|
|
113
|
+
|
|
114
|
+
if (!strcmp(username, name))
|
|
115
|
+
{
|
|
116
|
+
/* User name found. Update password. */
|
|
117
|
+
while ((c = *passwd++))
|
|
118
|
+
{
|
|
119
|
+
fputc(c, passwd_fd);
|
|
120
|
+
}
|
|
121
|
+
fputc('\n', passwd_fd);
|
|
122
|
+
return 0;
|
|
123
|
+
}
|
|
124
|
+
else
|
|
125
|
+
{
|
|
126
|
+
/* Skip password */
|
|
127
|
+
while((c = fgetc(passwd_fd)) != EOF &&
|
|
128
|
+
c != '\n')
|
|
129
|
+
;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
fseek(passwd_fd, 0, SEEK_END);
|
|
134
|
+
|
|
135
|
+
/*
|
|
136
|
+
* Not found the user name.
|
|
137
|
+
* Create a new entry.
|
|
138
|
+
*/
|
|
139
|
+
while ((c = *username++))
|
|
140
|
+
{
|
|
141
|
+
fputc(c, passwd_fd);
|
|
142
|
+
}
|
|
143
|
+
fputc(':', passwd_fd);
|
|
144
|
+
while ((c = *passwd++))
|
|
145
|
+
{
|
|
146
|
+
fputc(c, passwd_fd);
|
|
147
|
+
}
|
|
148
|
+
fputc('\n', passwd_fd);
|
|
149
|
+
|
|
150
|
+
return 0;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/*
|
|
154
|
+
* Get password in pool_passwd by username. Returns NULL if specified
|
|
155
|
+
* entry does not exist or error occurred.
|
|
156
|
+
* Returned password is on the static memory.
|
|
157
|
+
*/
|
|
158
|
+
char *pool_get_passwd(char *username)
|
|
159
|
+
{
|
|
160
|
+
int c;
|
|
161
|
+
char name[MAX_USER_NAME_LEN+1];
|
|
162
|
+
static char passwd[POOL_PASSWD_LEN+1];
|
|
163
|
+
char *p;
|
|
164
|
+
int readlen;
|
|
165
|
+
|
|
166
|
+
if (!username)
|
|
167
|
+
{
|
|
168
|
+
pool_error("pool_get_passwd: username is NULL");
|
|
169
|
+
return NULL;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (!passwd_fd)
|
|
173
|
+
{
|
|
174
|
+
pool_error("pool_get_passwd: passwd_fd is NULL");
|
|
175
|
+
return NULL;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
rewind(passwd_fd);
|
|
179
|
+
name[0] = '\0';
|
|
180
|
+
|
|
181
|
+
while (!feof(passwd_fd))
|
|
182
|
+
{
|
|
183
|
+
p = name;
|
|
184
|
+
readlen = 0;
|
|
185
|
+
|
|
186
|
+
while (readlen < (sizeof(name)-1))
|
|
187
|
+
{
|
|
188
|
+
c = fgetc(passwd_fd);
|
|
189
|
+
if (c == EOF)
|
|
190
|
+
break;
|
|
191
|
+
else if (c == ':')
|
|
192
|
+
break;
|
|
193
|
+
|
|
194
|
+
readlen++;
|
|
195
|
+
*p++ = c;
|
|
196
|
+
}
|
|
197
|
+
*p = '\0';
|
|
198
|
+
|
|
199
|
+
if (!strcmp(username, name))
|
|
200
|
+
{
|
|
201
|
+
/* User name found. Return password. */
|
|
202
|
+
p = passwd;
|
|
203
|
+
readlen = 0;
|
|
204
|
+
|
|
205
|
+
while((c = fgetc(passwd_fd)) != EOF &&
|
|
206
|
+
c != '\n' && readlen < (sizeof(passwd)-1))
|
|
207
|
+
{
|
|
208
|
+
*p++ = c;
|
|
209
|
+
readlen++;
|
|
210
|
+
}
|
|
211
|
+
*p = '\0';
|
|
212
|
+
return passwd;
|
|
213
|
+
}
|
|
214
|
+
else
|
|
215
|
+
{
|
|
216
|
+
/* Skip password */
|
|
217
|
+
while((c = fgetc(passwd_fd)) != EOF &&
|
|
218
|
+
c != '\n')
|
|
219
|
+
;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
return NULL;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/*
|
|
226
|
+
* Delete the entry by username. If specified entry does not exist,
|
|
227
|
+
* does nothing.
|
|
228
|
+
*/
|
|
229
|
+
void pool_delete_passwdent(char *username)
|
|
230
|
+
{
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/*
|
|
234
|
+
* Finish this moil. Close pool_passwd.
|
|
235
|
+
*/
|
|
236
|
+
void pool_finish_pool_passwd(void)
|
|
237
|
+
{
|
|
238
|
+
if (passwd_fd)
|
|
239
|
+
{
|
|
240
|
+
fclose(passwd_fd);
|
|
241
|
+
passwd_fd = NULL;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
void pool_reopen_passwd_file(void)
|
|
246
|
+
{
|
|
247
|
+
pool_finish_pool_passwd();
|
|
248
|
+
pool_init_pool_passwd(saved_passwd_filename);
|
|
249
|
+
}
|