summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Momjian2005-10-15 02:49:52 +0000
committerBruce Momjian2005-10-15 02:49:52 +0000
commit1dc34982511d91ef8a2b71bdcb870f067c1b3da9 (patch)
tree1046adab1d4b964e0c38afeec0ee6546f61d9a8a
parent790c01d28099587bbe2c623d4389b62ee49b1dee (diff)
Standard pgindent run for 8.1.
-rw-r--r--contrib/btree_gist/btree_cash.c10
-rw-r--r--contrib/btree_gist/btree_date.c16
-rw-r--r--contrib/btree_gist/btree_float4.c6
-rw-r--r--contrib/btree_gist/btree_float8.c6
-rw-r--r--contrib/btree_gist/btree_inet.c8
-rw-r--r--contrib/btree_gist/btree_int2.c10
-rw-r--r--contrib/btree_gist/btree_int4.c12
-rw-r--r--contrib/btree_gist/btree_int8.c12
-rw-r--r--contrib/btree_gist/btree_interval.c12
-rw-r--r--contrib/btree_gist/btree_macaddr.c10
-rw-r--r--contrib/btree_gist/btree_oid.c6
-rw-r--r--contrib/btree_gist/btree_text.c10
-rw-r--r--contrib/btree_gist/btree_time.c26
-rw-r--r--contrib/btree_gist/btree_ts.c54
-rw-r--r--contrib/btree_gist/btree_utils_num.h10
-rw-r--r--contrib/btree_gist/btree_utils_var.c154
-rw-r--r--contrib/btree_gist/btree_utils_var.h3
-rw-r--r--contrib/chkpass/chkpass.c6
-rw-r--r--contrib/cube/cube.c55
-rw-r--r--contrib/dbase/dbf.c11
-rw-r--r--contrib/dbase/dbf.h12
-rw-r--r--contrib/dbase/dbf2pg.c26
-rw-r--r--contrib/dblink/dblink.c99
-rw-r--r--contrib/dbmirror/pending.c12
-rw-r--r--contrib/earthdistance/earthdistance.c2
-rw-r--r--contrib/fulltextindex/fti.c12
-rw-r--r--contrib/fuzzystrmatch/dmetaphone.c71
-rw-r--r--contrib/fuzzystrmatch/fuzzystrmatch.c73
-rw-r--r--contrib/intagg/int_aggregate.c24
-rw-r--r--contrib/intarray/_int_gist.c39
-rw-r--r--contrib/intarray/_int_op.c8
-rw-r--r--contrib/intarray/_intbig_gist.c2
-rw-r--r--contrib/ltree/_ltree_op.c2
-rw-r--r--contrib/ltree/lquery_op.c4
-rw-r--r--contrib/ltree/ltree.h2
-rw-r--r--contrib/ltree/ltree_gist.c16
-rw-r--r--contrib/ltree/ltree_io.c6
-rw-r--r--contrib/mSQL-interface/mpgsql.c4
-rw-r--r--contrib/oid2name/oid2name.c122
-rw-r--r--contrib/pg_buffercache/pg_buffercache_pages.c93
-rw-r--r--contrib/pg_trgm/trgm_op.c4
-rw-r--r--contrib/pgbench/pgbench.c197
-rw-r--r--contrib/pgcrypto/crypt-blowfish.c3
-rw-r--r--contrib/pgcrypto/crypt-des.c48
-rw-r--r--contrib/pgcrypto/crypt-gensalt.c8
-rw-r--r--contrib/pgcrypto/crypt-md5.c8
-rw-r--r--contrib/pgcrypto/fortuna.c146
-rw-r--r--contrib/pgcrypto/fortuna.h7
-rw-r--r--contrib/pgcrypto/internal.c75
-rw-r--r--contrib/pgcrypto/mbuf.c45
-rw-r--r--contrib/pgcrypto/mbuf.h45
-rw-r--r--contrib/pgcrypto/md5.h2
-rw-r--r--contrib/pgcrypto/openssl.c34
-rw-r--r--contrib/pgcrypto/pgcrypto.c4
-rw-r--r--contrib/pgcrypto/pgp-armor.c26
-rw-r--r--contrib/pgcrypto/pgp-cfb.c59
-rw-r--r--contrib/pgcrypto/pgp-compress.c60
-rw-r--r--contrib/pgcrypto/pgp-decrypt.c281
-rw-r--r--contrib/pgcrypto/pgp-encrypt.c101
-rw-r--r--contrib/pgcrypto/pgp-info.c52
-rw-r--r--contrib/pgcrypto/pgp-mpi-internal.c18
-rw-r--r--contrib/pgcrypto/pgp-mpi-openssl.c180
-rw-r--r--contrib/pgcrypto/pgp-mpi.c53
-rw-r--r--contrib/pgcrypto/pgp-pgsql.c199
-rw-r--r--contrib/pgcrypto/pgp-pubdec.c72
-rw-r--r--contrib/pgcrypto/pgp-pubenc.c62
-rw-r--r--contrib/pgcrypto/pgp-pubkey.c167
-rw-r--r--contrib/pgcrypto/pgp-s2k.c39
-rw-r--r--contrib/pgcrypto/pgp.c41
-rw-r--r--contrib/pgcrypto/pgp.h203
-rw-r--r--contrib/pgcrypto/px-crypt.c7
-rw-r--r--contrib/pgcrypto/px-crypt.h10
-rw-r--r--contrib/pgcrypto/px.c34
-rw-r--r--contrib/pgcrypto/px.h23
-rw-r--r--contrib/pgcrypto/random.c57
-rw-r--r--contrib/pgcrypto/rijndael.c4
-rw-r--r--contrib/pgcrypto/sha2.c481
-rw-r--r--contrib/pgcrypto/sha2.h66
-rw-r--r--contrib/pgstattuple/pgstattuple.c12
-rw-r--r--contrib/seg/seg.c71
-rw-r--r--contrib/spi/autoinc.c4
-rw-r--r--contrib/spi/insert_username.c4
-rw-r--r--contrib/spi/moddatetime.c9
-rw-r--r--contrib/spi/refint.c72
-rw-r--r--contrib/spi/timetravel.c23
-rw-r--r--contrib/tablefunc/tablefunc.c145
-rw-r--r--contrib/tsearch2/dict.c18
-rw-r--r--contrib/tsearch2/dict.h30
-rw-r--r--contrib/tsearch2/dict_ex.c2
-rw-r--r--contrib/tsearch2/dict_ispell.c18
-rw-r--r--contrib/tsearch2/dict_snowball.c2
-rw-r--r--contrib/tsearch2/dict_syn.c4
-rw-r--r--contrib/tsearch2/gistidx.c36
-rw-r--r--contrib/tsearch2/gistidx.h6
-rw-r--r--contrib/tsearch2/ispell/spell.c64
-rw-r--r--contrib/tsearch2/ispell/spell.h10
-rw-r--r--contrib/tsearch2/prs_dcfg.c16
-rw-r--r--contrib/tsearch2/query.c35
-rw-r--r--contrib/tsearch2/rank.c95
-rw-r--r--contrib/tsearch2/snowball/api.c122
-rw-r--r--contrib/tsearch2/snowball/api.h27
-rw-r--r--contrib/tsearch2/snowball/english_stem.c2580
-rw-r--r--contrib/tsearch2/snowball/english_stem.h11
-rw-r--r--contrib/tsearch2/snowball/header.h62
-rw-r--r--contrib/tsearch2/snowball/russian_stem.c1487
-rw-r--r--contrib/tsearch2/snowball/russian_stem.h11
-rw-r--r--contrib/tsearch2/snowball/utilities.c904
-rw-r--r--contrib/tsearch2/stopword.c4
-rw-r--r--contrib/tsearch2/ts_cfg.c62
-rw-r--r--contrib/tsearch2/ts_stat.c8
-rw-r--r--contrib/tsearch2/tsvector.c26
-rw-r--r--contrib/tsearch2/tsvector.h14
-rw-r--r--contrib/tsearch2/tsvector_op.c2
-rw-r--r--contrib/tsearch2/wparser.c16
-rw-r--r--contrib/tsearch2/wparser_def.c2
-rw-r--r--contrib/vacuumlo/vacuumlo.c19
-rw-r--r--contrib/xml2/xpath.c64
-rw-r--r--contrib/xml2/xslt_proc.c2
-rw-r--r--src/backend/access/common/heaptuple.c188
-rw-r--r--src/backend/access/common/indextuple.c37
-rw-r--r--src/backend/access/common/printtup.c21
-rw-r--r--src/backend/access/common/tupdesc.c52
-rw-r--r--src/backend/access/gist/gistproc.c4
-rw-r--r--src/backend/access/hash/hash.c63
-rw-r--r--src/backend/access/hash/hashfunc.c31
-rw-r--r--src/backend/access/hash/hashinsert.c29
-rw-r--r--src/backend/access/hash/hashovfl.c58
-rw-r--r--src/backend/access/hash/hashpage.c134
-rw-r--r--src/backend/access/hash/hashscan.c8
-rw-r--r--src/backend/access/hash/hashsearch.c38
-rw-r--r--src/backend/access/heap/heapam.c428
-rw-r--r--src/backend/access/heap/hio.c91
-rw-r--r--src/backend/access/heap/tuptoaster.c98
-rw-r--r--src/backend/access/index/genam.c12
-rw-r--r--src/backend/access/index/indexam.c85
-rw-r--r--src/backend/access/nbtree/nbtinsert.c268
-rw-r--r--src/backend/access/nbtree/nbtpage.c194
-rw-r--r--src/backend/access/nbtree/nbtree.c180
-rw-r--r--src/backend/access/nbtree/nbtsearch.c279
-rw-r--r--src/backend/access/nbtree/nbtsort.c138
-rw-r--r--src/backend/access/nbtree/nbtutils.c86
-rw-r--r--src/backend/access/nbtree/nbtxlog.c20
-rw-r--r--src/backend/access/rtree/rtget.c40
-rw-r--r--src/backend/access/rtree/rtproc.c6
-rw-r--r--src/backend/access/rtree/rtree.c184
-rw-r--r--src/backend/access/rtree/rtscan.c21
-rw-r--r--src/backend/access/transam/clog.c22
-rw-r--r--src/backend/access/transam/multixact.c380
-rw-r--r--src/backend/access/transam/slru.c132
-rw-r--r--src/backend/access/transam/subtrans.c21
-rw-r--r--src/backend/access/transam/transam.c40
-rw-r--r--src/backend/access/transam/twophase.c310
-rw-r--r--src/backend/access/transam/twophase_rmgr.c38
-rw-r--r--src/backend/access/transam/varsup.c138
-rw-r--r--src/backend/access/transam/xact.c639
-rw-r--r--src/backend/access/transam/xlog.c1129
-rw-r--r--src/backend/access/transam/xlogutils.c28
-rw-r--r--src/backend/bootstrap/bootstrap.c49
-rw-r--r--src/backend/catalog/aclchk.c279
-rw-r--r--src/backend/catalog/catalog.c20
-rw-r--r--src/backend/catalog/dependency.c179
-rw-r--r--src/backend/catalog/heap.c258
-rw-r--r--src/backend/catalog/index.c326
-rw-r--r--src/backend/catalog/indexing.c10
-rw-r--r--src/backend/catalog/namespace.c258
-rw-r--r--src/backend/catalog/pg_aggregate.c80
-rw-r--r--src/backend/catalog/pg_constraint.c51
-rw-r--r--src/backend/catalog/pg_conversion.c19
-rw-r--r--src/backend/catalog/pg_depend.c35
-rw-r--r--src/backend/catalog/pg_operator.c62
-rw-r--r--src/backend/catalog/pg_proc.c90
-rw-r--r--src/backend/catalog/pg_shdepend.c219
-rw-r--r--src/backend/catalog/pg_type.c41
-rw-r--r--src/backend/commands/aggregatecmds.c53
-rw-r--r--src/backend/commands/alter.c18
-rw-r--r--src/backend/commands/analyze.c305
-rw-r--r--src/backend/commands/async.c213
-rw-r--r--src/backend/commands/cluster.c184
-rw-r--r--src/backend/commands/comment.c62
-rw-r--r--src/backend/commands/conversioncmds.c21
-rw-r--r--src/backend/commands/copy.c539
-rw-r--r--src/backend/commands/dbcommands.c186
-rw-r--r--src/backend/commands/define.c8
-rw-r--r--src/backend/commands/explain.c90
-rw-r--r--src/backend/commands/functioncmds.c114
-rw-r--r--src/backend/commands/indexcmds.c166
-rw-r--r--src/backend/commands/lockcmds.c10
-rw-r--r--src/backend/commands/opclasscmds.c76
-rw-r--r--src/backend/commands/operatorcmds.c27
-rw-r--r--src/backend/commands/portalcmds.c77
-rw-r--r--src/backend/commands/prepare.c82
-rw-r--r--src/backend/commands/proclang.c52
-rw-r--r--src/backend/commands/schemacmds.c57
-rw-r--r--src/backend/commands/sequence.c86
-rw-r--r--src/backend/commands/tablecmds.c954
-rw-r--r--src/backend/commands/tablespace.c139
-rw-r--r--src/backend/commands/trigger.c386
-rw-r--r--src/backend/commands/typecmds.c255
-rw-r--r--src/backend/commands/user.c174
-rw-r--r--src/backend/commands/vacuum.c605
-rw-r--r--src/backend/commands/vacuumlazy.c190
-rw-r--r--src/backend/commands/variable.c110
-rw-r--r--src/backend/commands/view.c77
-rw-r--r--src/backend/executor/execAmi.c21
-rw-r--r--src/backend/executor/execGrouping.c34
-rw-r--r--src/backend/executor/execJunk.c32
-rw-r--r--src/backend/executor/execMain.c341
-rw-r--r--src/backend/executor/execProcnode.c20
-rw-r--r--src/backend/executor/execQual.c443
-rw-r--r--src/backend/executor/execScan.c43
-rw-r--r--src/backend/executor/execTuples.c58
-rw-r--r--src/backend/executor/execUtils.c106
-rw-r--r--src/backend/executor/functions.c204
-rw-r--r--src/backend/executor/instrument.c6
-rw-r--r--src/backend/executor/nodeAgg.c255
-rw-r--r--src/backend/executor/nodeAppend.c51
-rw-r--r--src/backend/executor/nodeBitmapAnd.c18
-rw-r--r--src/backend/executor/nodeBitmapHeapscan.c69
-rw-r--r--src/backend/executor/nodeBitmapIndexscan.c48
-rw-r--r--src/backend/executor/nodeBitmapOr.c14
-rw-r--r--src/backend/executor/nodeFunctionscan.c31
-rw-r--r--src/backend/executor/nodeGroup.c31
-rw-r--r--src/backend/executor/nodeHash.c84
-rw-r--r--src/backend/executor/nodeHashjoin.c162
-rw-r--r--src/backend/executor/nodeIndexscan.c155
-rw-r--r--src/backend/executor/nodeLimit.c36
-rw-r--r--src/backend/executor/nodeMaterial.c46
-rw-r--r--src/backend/executor/nodeMergejoin.c289
-rw-r--r--src/backend/executor/nodeNestloop.c61
-rw-r--r--src/backend/executor/nodeResult.c32
-rw-r--r--src/backend/executor/nodeSeqscan.c60
-rw-r--r--src/backend/executor/nodeSetOp.c24
-rw-r--r--src/backend/executor/nodeSort.c25
-rw-r--r--src/backend/executor/nodeSubplan.c243
-rw-r--r--src/backend/executor/nodeSubqueryscan.c26
-rw-r--r--src/backend/executor/nodeTidscan.c31
-rw-r--r--src/backend/executor/nodeUnique.c34
-rw-r--r--src/backend/executor/spi.c118
-rw-r--r--src/backend/lib/dllist.c6
-rw-r--r--src/backend/lib/stringinfo.c39
-rw-r--r--src/backend/libpq/auth.c93
-rw-r--r--src/backend/libpq/be-fsstubs.c45
-rw-r--r--src/backend/libpq/be-secure.c70
-rw-r--r--src/backend/libpq/crypt.c8
-rw-r--r--src/backend/libpq/hba.c106
-rw-r--r--src/backend/libpq/md5.c6
-rw-r--r--src/backend/libpq/pqcomm.c112
-rw-r--r--src/backend/libpq/pqformat.c11
-rw-r--r--src/backend/libpq/pqsignal.c11
-rw-r--r--src/backend/main/main.c114
-rw-r--r--src/backend/nodes/bitmapset.c8
-rw-r--r--src/backend/nodes/copyfuncs.c19
-rw-r--r--src/backend/nodes/equalfuncs.c61
-rw-r--r--src/backend/nodes/list.c24
-rw-r--r--src/backend/nodes/makefuncs.c15
-rw-r--r--src/backend/nodes/outfuncs.c27
-rw-r--r--src/backend/nodes/print.c6
-rw-r--r--src/backend/nodes/read.c21
-rw-r--r--src/backend/nodes/readfuncs.c50
-rw-r--r--src/backend/nodes/tidbitmap.c108
-rw-r--r--src/backend/optimizer/geqo/geqo_erx.c45
-rw-r--r--src/backend/optimizer/geqo/geqo_eval.c91
-rw-r--r--src/backend/optimizer/geqo/geqo_main.c9
-rw-r--r--src/backend/optimizer/geqo/geqo_misc.c10
-rw-r--r--src/backend/optimizer/geqo/geqo_pool.c20
-rw-r--r--src/backend/optimizer/geqo/geqo_recombination.c10
-rw-r--r--src/backend/optimizer/geqo/geqo_selection.c15
-rw-r--r--src/backend/optimizer/path/allpaths.c127
-rw-r--r--src/backend/optimizer/path/clausesel.c88
-rw-r--r--src/backend/optimizer/path/costsize.c470
-rw-r--r--src/backend/optimizer/path/indxpath.c371
-rw-r--r--src/backend/optimizer/path/joinpath.c171
-rw-r--r--src/backend/optimizer/path/joinrels.c135
-rw-r--r--src/backend/optimizer/path/orindxpath.c34
-rw-r--r--src/backend/optimizer/path/pathkeys.c291
-rw-r--r--src/backend/optimizer/path/tidpath.c6
-rw-r--r--src/backend/optimizer/plan/createplan.c401
-rw-r--r--src/backend/optimizer/plan/initsplan.c231
-rw-r--r--src/backend/optimizer/plan/planagg.c126
-rw-r--r--src/backend/optimizer/plan/planmain.c124
-rw-r--r--src/backend/optimizer/plan/planner.c354
-rw-r--r--src/backend/optimizer/plan/setrefs.c158
-rw-r--r--src/backend/optimizer/plan/subselect.c264
-rw-r--r--src/backend/optimizer/prep/prepjointree.c164
-rw-r--r--src/backend/optimizer/prep/prepqual.c61
-rw-r--r--src/backend/optimizer/prep/preptlist.c105
-rw-r--r--src/backend/optimizer/prep/prepunion.c189
-rw-r--r--src/backend/optimizer/util/clauses.c367
-rw-r--r--src/backend/optimizer/util/pathnode.c175
-rw-r--r--src/backend/optimizer/util/plancat.c132
-rw-r--r--src/backend/optimizer/util/predtest.c122
-rw-r--r--src/backend/optimizer/util/relnode.c84
-rw-r--r--src/backend/optimizer/util/restrictinfo.c67
-rw-r--r--src/backend/optimizer/util/tlist.c4
-rw-r--r--src/backend/optimizer/util/var.c38
-rw-r--r--src/backend/parser/analyze.c534
-rw-r--r--src/backend/parser/keywords.c6
-rw-r--r--src/backend/parser/parse_agg.c79
-rw-r--r--src/backend/parser/parse_clause.c257
-rw-r--r--src/backend/parser/parse_coerce.c246
-rw-r--r--src/backend/parser/parse_expr.c176
-rw-r--r--src/backend/parser/parse_func.c241
-rw-r--r--src/backend/parser/parse_node.c38
-rw-r--r--src/backend/parser/parse_oper.c108
-rw-r--r--src/backend/parser/parse_relation.c156
-rw-r--r--src/backend/parser/parse_target.c113
-rw-r--r--src/backend/parser/parse_type.c18
-rw-r--r--src/backend/parser/scansup.c24
-rw-r--r--src/backend/port/beos/sem.c22
-rw-r--r--src/backend/port/beos/shm.c11
-rw-r--r--src/backend/port/beos/support.c18
-rw-r--r--src/backend/port/dynloader/aix.c48
-rw-r--r--src/backend/port/dynloader/aix.h4
-rw-r--r--src/backend/port/dynloader/bsdi.c11
-rw-r--r--src/backend/port/dynloader/bsdi.h3
-rw-r--r--src/backend/port/dynloader/hpux.c4
-rw-r--r--src/backend/port/dynloader/linux.c11
-rw-r--r--src/backend/port/dynloader/ultrix4.c10
-rw-r--r--src/backend/port/dynloader/win32.c48
-rw-r--r--src/backend/port/ipc_test.c6
-rw-r--r--src/backend/port/posix_sema.c75
-rw-r--r--src/backend/port/qnx4/sem.c7
-rw-r--r--src/backend/port/qnx4/shm.c14
-rw-r--r--src/backend/port/sysv_sema.c126
-rw-r--r--src/backend/port/sysv_shmem.c96
-rw-r--r--src/backend/port/win32/error.c4
-rw-r--r--src/backend/port/win32/security.c38
-rw-r--r--src/backend/port/win32/sema.c6
-rw-r--r--src/backend/port/win32/shmem.c4
-rw-r--r--src/backend/port/win32/signal.c32
-rw-r--r--src/backend/port/win32/socket.c14
-rw-r--r--src/backend/postmaster/autovacuum.c270
-rw-r--r--src/backend/postmaster/bgwriter.c109
-rw-r--r--src/backend/postmaster/fork_process.c35
-rw-r--r--src/backend/postmaster/pgarch.c53
-rw-r--r--src/backend/postmaster/pgstat.c471
-rw-r--r--src/backend/postmaster/postmaster.c685
-rw-r--r--src/backend/postmaster/syslogger.c120
-rw-r--r--src/backend/regex/regc_color.c6
-rw-r--r--src/backend/regex/regc_cvec.c5
-rw-r--r--src/backend/regex/regc_lex.c11
-rw-r--r--src/backend/regex/regc_locale.c12
-rw-r--r--src/backend/regex/regc_nfa.c19
-rw-r--r--src/backend/regex/regcomp.c37
-rw-r--r--src/backend/regex/rege_dfa.c8
-rw-r--r--src/backend/regex/regexec.c17
-rw-r--r--src/backend/rewrite/rewriteDefine.c124
-rw-r--r--src/backend/rewrite/rewriteHandler.c321
-rw-r--r--src/backend/rewrite/rewriteManip.c104
-rw-r--r--src/backend/rewrite/rewriteRemove.c10
-rw-r--r--src/backend/rewrite/rewriteSupport.c5
-rw-r--r--src/backend/storage/buffer/buf_init.c6
-rw-r--r--src/backend/storage/buffer/buf_table.c8
-rw-r--r--src/backend/storage/buffer/bufmgr.c284
-rw-r--r--src/backend/storage/buffer/freelist.c38
-rw-r--r--src/backend/storage/buffer/localbuf.c24
-rw-r--r--src/backend/storage/file/buffile.c37
-rw-r--r--src/backend/storage/file/fd.c93
-rw-r--r--src/backend/storage/freespace/freespace.c179
-rw-r--r--src/backend/storage/ipc/ipc.c23
-rw-r--r--src/backend/storage/ipc/ipci.c19
-rw-r--r--src/backend/storage/ipc/pmsignal.c8
-rw-r--r--src/backend/storage/ipc/procarray.c129
-rw-r--r--src/backend/storage/ipc/shmem.c51
-rw-r--r--src/backend/storage/ipc/sinval.c99
-rw-r--r--src/backend/storage/ipc/sinvaladt.c22
-rw-r--r--src/backend/storage/large_object/inv_api.c37
-rw-r--r--src/backend/storage/lmgr/deadlock.c99
-rw-r--r--src/backend/storage/lmgr/lmgr.c34
-rw-r--r--src/backend/storage/lmgr/lock.c270
-rw-r--r--src/backend/storage/lmgr/lwlock.c93
-rw-r--r--src/backend/storage/lmgr/proc.c225
-rw-r--r--src/backend/storage/lmgr/s_lock.c120
-rw-r--r--src/backend/storage/lmgr/spin.c11
-rw-r--r--src/backend/storage/page/bufpage.c64
-rw-r--r--src/backend/storage/smgr/md.c171
-rw-r--r--src/backend/storage/smgr/smgr.c128
-rw-r--r--src/backend/tcop/dest.c7
-rw-r--r--src/backend/tcop/fastpath.c43
-rw-r--r--src/backend/tcop/postgres.c644
-rw-r--r--src/backend/tcop/pquery.c220
-rw-r--r--src/backend/tcop/utility.c92
-rw-r--r--src/backend/utils/adt/acl.c266
-rw-r--r--src/backend/utils/adt/array_userfuncs.c43
-rw-r--r--src/backend/utils/adt/arrayfuncs.c342
-rw-r--r--src/backend/utils/adt/ascii.c6
-rw-r--r--src/backend/utils/adt/cash.c24
-rw-r--r--src/backend/utils/adt/char.c8
-rw-r--r--src/backend/utils/adt/date.c195
-rw-r--r--src/backend/utils/adt/datetime.c337
-rw-r--r--src/backend/utils/adt/datum.c11
-rw-r--r--src/backend/utils/adt/dbsize.c142
-rw-r--r--src/backend/utils/adt/encode.c8
-rw-r--r--src/backend/utils/adt/float.c122
-rw-r--r--src/backend/utils/adt/format_type.c42
-rw-r--r--src/backend/utils/adt/formatting.c339
-rw-r--r--src/backend/utils/adt/genfile.c57
-rw-r--r--src/backend/utils/adt/geo_ops.c135
-rw-r--r--src/backend/utils/adt/inet_net_ntop.c20
-rw-r--r--src/backend/utils/adt/inet_net_pton.c5
-rw-r--r--src/backend/utils/adt/int.c148
-rw-r--r--src/backend/utils/adt/int8.c140
-rw-r--r--src/backend/utils/adt/like.c46
-rw-r--r--src/backend/utils/adt/like_match.c42
-rw-r--r--src/backend/utils/adt/lockfuncs.c29
-rw-r--r--src/backend/utils/adt/mac.c6
-rw-r--r--src/backend/utils/adt/misc.c21
-rw-r--r--src/backend/utils/adt/nabstime.c147
-rw-r--r--src/backend/utils/adt/name.c6
-rw-r--r--src/backend/utils/adt/network.c28
-rw-r--r--src/backend/utils/adt/numeric.c328
-rw-r--r--src/backend/utils/adt/numutils.c16
-rw-r--r--src/backend/utils/adt/oid.c28
-rw-r--r--src/backend/utils/adt/oracle_compat.c74
-rw-r--r--src/backend/utils/adt/pg_locale.c27
-rw-r--r--src/backend/utils/adt/pg_lzcompress.c102
-rw-r--r--src/backend/utils/adt/pgstatfuncs.c12
-rw-r--r--src/backend/utils/adt/quote.c6
-rw-r--r--src/backend/utils/adt/regexp.c63
-rw-r--r--src/backend/utils/adt/regproc.c133
-rw-r--r--src/backend/utils/adt/ri_triggers.c504
-rw-r--r--src/backend/utils/adt/rowtypes.c61
-rw-r--r--src/backend/utils/adt/ruleutils.c367
-rw-r--r--src/backend/utils/adt/selfuncs.c748
-rw-r--r--src/backend/utils/adt/timestamp.c509
-rw-r--r--src/backend/utils/adt/varbit.c50
-rw-r--r--src/backend/utils/adt/varchar.c44
-rw-r--r--src/backend/utils/adt/varlena.c214
-rw-r--r--src/backend/utils/cache/catcache.c195
-rw-r--r--src/backend/utils/cache/inval.c93
-rw-r--r--src/backend/utils/cache/lsyscache.c40
-rw-r--r--src/backend/utils/cache/relcache.c408
-rw-r--r--src/backend/utils/cache/syscache.c77
-rw-r--r--src/backend/utils/cache/typcache.c41
-rw-r--r--src/backend/utils/error/assert.c6
-rw-r--r--src/backend/utils/error/elog.c198
-rw-r--r--src/backend/utils/fmgr/dfmgr.c16
-rw-r--r--src/backend/utils/fmgr/fmgr.c99
-rw-r--r--src/backend/utils/fmgr/funcapi.c83
-rw-r--r--src/backend/utils/hash/dynahash.c78
-rw-r--r--src/backend/utils/hash/hashfn.c8
-rw-r--r--src/backend/utils/hash/pg_crc.c6
-rw-r--r--src/backend/utils/init/flatfiles.c193
-rw-r--r--src/backend/utils/init/miscinit.c153
-rw-r--r--src/backend/utils/init/postinit.c115
-rw-r--r--src/backend/utils/mb/conv.c13
-rw-r--r--src/backend/utils/mb/conversion_procs/euc_jp_and_sjis/euc_jp_and_sjis.c14
-rw-r--r--src/backend/utils/mb/conversion_procs/euc_tw_and_big5/big5.c35
-rw-r--r--src/backend/utils/mb/conversion_procs/utf8_and_cyrillic/utf8_and_cyrillic.c6
-rw-r--r--src/backend/utils/mb/conversion_procs/utf8_and_euc_cn/utf8_and_euc_cn.c4
-rw-r--r--src/backend/utils/mb/conversion_procs/utf8_and_euc_jp/utf8_and_euc_jp.c4
-rw-r--r--src/backend/utils/mb/conversion_procs/utf8_and_euc_kr/utf8_and_euc_kr.c4
-rw-r--r--src/backend/utils/mb/conversion_procs/utf8_and_euc_tw/utf8_and_euc_tw.c4
-rw-r--r--src/backend/utils/mb/conversion_procs/utf8_and_gb18030/utf8_and_gb18030.c4
-rw-r--r--src/backend/utils/mb/conversion_procs/utf8_and_iso8859/utf8_and_iso8859.c4
-rw-r--r--src/backend/utils/mb/conversion_procs/utf8_and_johab/utf8_and_johab.c4
-rw-r--r--src/backend/utils/mb/conversion_procs/utf8_and_win1250/utf8_and_win1250.c4
-rw-r--r--src/backend/utils/mb/conversion_procs/utf8_and_win1252/utf8_and_win1252.c4
-rw-r--r--src/backend/utils/mb/conversion_procs/utf8_and_win1256/utf8_and_win1256.c4
-rw-r--r--src/backend/utils/mb/conversion_procs/utf8_and_win1258/utf8_and_win1258.c4
-rw-r--r--src/backend/utils/mb/conversion_procs/utf8_and_win874/utf8_and_win874.c4
-rw-r--r--src/backend/utils/mb/encnames.c22
-rw-r--r--src/backend/utils/mb/mbutils.c30
-rw-r--r--src/backend/utils/mb/wchar.c123
-rw-r--r--src/backend/utils/misc/guc.c436
-rw-r--r--src/backend/utils/misc/pg_rusage.c6
-rw-r--r--src/backend/utils/misc/ps_status.c48
-rw-r--r--src/backend/utils/misc/superuser.c8
-rw-r--r--src/backend/utils/mmgr/aset.c128
-rw-r--r--src/backend/utils/mmgr/mcxt.c39
-rw-r--r--src/backend/utils/mmgr/portalmem.c107
-rw-r--r--src/backend/utils/resowner/resowner.c68
-rw-r--r--src/backend/utils/sort/logtape.c104
-rw-r--r--src/backend/utils/sort/tuplesort.c326
-rw-r--r--src/backend/utils/sort/tuplestore.c90
-rw-r--r--src/backend/utils/time/tqual.c64
-rw-r--r--src/bin/initdb/initdb.c246
-rw-r--r--src/bin/pg_config/pg_config.c81
-rw-r--r--src/bin/pg_controldata/pg_controldata.c14
-rw-r--r--src/bin/pg_ctl/pg_ctl.c70
-rw-r--r--src/bin/pg_dump/common.c25
-rw-r--r--src/bin/pg_dump/dumputils.c63
-rw-r--r--src/bin/pg_dump/pg_backup.h19
-rw-r--r--src/bin/pg_dump/pg_backup_archiver.c182
-rw-r--r--src/bin/pg_dump/pg_backup_archiver.h38
-rw-r--r--src/bin/pg_dump/pg_backup_custom.c37
-rw-r--r--src/bin/pg_dump/pg_backup_db.c81
-rw-r--r--src/bin/pg_dump/pg_backup_files.c4
-rw-r--r--src/bin/pg_dump/pg_backup_null.c5
-rw-r--r--src/bin/pg_dump/pg_backup_tar.c76
-rw-r--r--src/bin/pg_dump/pg_dump.c678
-rw-r--r--src/bin/pg_dump/pg_dump.h13
-rw-r--r--src/bin/pg_dump/pg_dump_sort.c113
-rw-r--r--src/bin/pg_dump/pg_dumpall.c76
-rw-r--r--src/bin/pg_dump/pg_restore.c12
-rw-r--r--src/bin/pg_resetxlog/pg_resetxlog.c59
-rw-r--r--src/bin/pgevent/pgevent.c10
-rw-r--r--src/bin/psql/command.c85
-rw-r--r--src/bin/psql/common.c134
-rw-r--r--src/bin/psql/common.h4
-rw-r--r--src/bin/psql/copy.c19
-rw-r--r--src/bin/psql/describe.c229
-rw-r--r--src/bin/psql/help.c136
-rw-r--r--src/bin/psql/input.c8
-rw-r--r--src/bin/psql/large_obj.c8
-rw-r--r--src/bin/psql/mainloop.c40
-rw-r--r--src/bin/psql/mbprint.c22
-rw-r--r--src/bin/psql/print.c224
-rw-r--r--src/bin/psql/print.h29
-rw-r--r--src/bin/psql/prompt.c9
-rw-r--r--src/bin/psql/settings.h11
-rw-r--r--src/bin/psql/startup.c49
-rw-r--r--src/bin/psql/stringutils.c35
-rw-r--r--src/bin/psql/tab-complete.c2869
-rw-r--r--src/bin/psql/variables.c6
-rw-r--r--src/bin/scripts/common.c8
-rw-r--r--src/bin/scripts/common.h18
-rw-r--r--src/bin/scripts/createlang.c12
-rw-r--r--src/bin/scripts/createuser.c6
-rw-r--r--src/bin/scripts/droplang.c34
-rw-r--r--src/bin/scripts/reindexdb.c96
-rw-r--r--src/include/access/genam.h10
-rw-r--r--src/include/access/gist.h23
-rw-r--r--src/include/access/gist_private.h217
-rw-r--r--src/include/access/hash.h24
-rw-r--r--src/include/access/heapam.h43
-rw-r--r--src/include/access/hio.h4
-rw-r--r--src/include/access/htup.h24
-rw-r--r--src/include/access/itup.h6
-rw-r--r--src/include/access/multixact.h20
-rw-r--r--src/include/access/nbtree.h9
-rw-r--r--src/include/access/relscan.h8
-rw-r--r--src/include/access/slru.h28
-rw-r--r--src/include/access/transam.h12
-rw-r--r--src/include/access/tupmacs.h4
-rw-r--r--src/include/access/twophase.h8
-rw-r--r--src/include/access/twophase_rmgr.h10
-rw-r--r--src/include/access/xact.h4
-rw-r--r--src/include/access/xlog.h13
-rw-r--r--src/include/c.h14
-rw-r--r--src/include/catalog/catalog.h6
-rw-r--r--src/include/catalog/dependency.h23
-rw-r--r--src/include/catalog/heap.h5
-rw-r--r--src/include/catalog/index.h14
-rw-r--r--src/include/catalog/indexing.h142
-rw-r--r--src/include/catalog/namespace.h4
-rw-r--r--src/include/catalog/pg_aggregate.h8
-rw-r--r--src/include/catalog/pg_am.h18
-rw-r--r--src/include/catalog/pg_amop.h124
-rw-r--r--src/include/catalog/pg_attribute.h56
-rw-r--r--src/include/catalog/pg_authid.h8
-rw-r--r--src/include/catalog/pg_autovacuum.h16
-rw-r--r--src/include/catalog/pg_cast.h18
-rw-r--r--src/include/catalog/pg_class.h8
-rw-r--r--src/include/catalog/pg_constraint.h25
-rw-r--r--src/include/catalog/pg_control.h45
-rw-r--r--src/include/catalog/pg_database.h4
-rw-r--r--src/include/catalog/pg_index.h12
-rw-r--r--src/include/catalog/pg_inherits.h4
-rw-r--r--src/include/catalog/pg_language.h4
-rw-r--r--src/include/catalog/pg_listener.h4
-rw-r--r--src/include/catalog/pg_namespace.h4
-rw-r--r--src/include/catalog/pg_operator.h28
-rw-r--r--src/include/catalog/pg_proc.h1104
-rw-r--r--src/include/catalog/pg_shdepend.h12
-rw-r--r--src/include/catalog/pg_statistic.h28
-rw-r--r--src/include/catalog/pg_type.h66
-rw-r--r--src/include/commands/async.h4
-rw-r--r--src/include/commands/cluster.h4
-rw-r--r--src/include/commands/dbcommands.h10
-rw-r--r--src/include/commands/defrem.h8
-rw-r--r--src/include/commands/tablecmds.h10
-rw-r--r--src/include/commands/tablespace.h6
-rw-r--r--src/include/commands/trigger.h14
-rw-r--r--src/include/commands/typecmds.h4
-rw-r--r--src/include/commands/vacuum.h14
-rw-r--r--src/include/commands/variable.h4
-rw-r--r--src/include/executor/execdebug.h3
-rw-r--r--src/include/executor/executor.h30
-rw-r--r--src/include/executor/functions.h6
-rw-r--r--src/include/executor/hashjoin.h25
-rw-r--r--src/include/executor/instrument.h10
-rw-r--r--src/include/executor/nodeHash.h18
-rw-r--r--src/include/executor/nodeHashjoin.h4
-rw-r--r--src/include/executor/nodeIndexscan.h8
-rw-r--r--src/include/executor/spi.h20
-rw-r--r--src/include/executor/spi_priv.h4
-rw-r--r--src/include/executor/tuptable.h17
-rw-r--r--src/include/fmgr.h19
-rw-r--r--src/include/funcapi.h90
-rw-r--r--src/include/getaddrinfo.h10
-rw-r--r--src/include/lib/dllist.h6
-rw-r--r--src/include/libpq/auth.h4
-rw-r--r--src/include/libpq/be-fsstubs.h4
-rw-r--r--src/include/libpq/hba.h10
-rw-r--r--src/include/libpq/libpq-be.h47
-rw-r--r--src/include/libpq/libpq.h4
-rw-r--r--src/include/libpq/pqcomm.h6
-rw-r--r--src/include/mb/pg_wchar.h34
-rw-r--r--src/include/miscadmin.h13
-rw-r--r--src/include/nodes/execnodes.h61
-rw-r--r--src/include/nodes/makefuncs.h8
-rw-r--r--src/include/nodes/nodes.h31
-rw-r--r--src/include/nodes/parsenodes.h111
-rw-r--r--src/include/nodes/pg_list.h3
-rw-r--r--src/include/nodes/plannodes.h63
-rw-r--r--src/include/nodes/primnodes.h89
-rw-r--r--src/include/nodes/relation.h108
-rw-r--r--src/include/nodes/tidbitmap.h6
-rw-r--r--src/include/optimizer/clauses.h16
-rw-r--r--src/include/optimizer/cost.h4
-rw-r--r--src/include/optimizer/geqo.h7
-rw-r--r--src/include/optimizer/pathnode.h16
-rw-r--r--src/include/optimizer/paths.h12
-rw-r--r--src/include/optimizer/planmain.h14
-rw-r--r--src/include/optimizer/planner.h4
-rw-r--r--src/include/optimizer/predtest.h6
-rw-r--r--src/include/optimizer/prep.h4
-rw-r--r--src/include/optimizer/restrictinfo.h10
-rw-r--r--src/include/optimizer/subselect.h4
-rw-r--r--src/include/parser/parse_node.h9
-rw-r--r--src/include/parser/parse_target.h4
-rw-r--r--src/include/parser/parsetree.h4
-rw-r--r--src/include/pgstat.h47
-rw-r--r--src/include/pgtime.h18
-rw-r--r--src/include/port.h32
-rw-r--r--src/include/port/darwin.h1
-rw-r--r--src/include/port/hpux.h2
-rw-r--r--src/include/port/ultrix4.h3
-rw-r--r--src/include/port/win32.h11
-rw-r--r--src/include/port/win32/sys/socket.h2
-rw-r--r--src/include/postmaster/autovacuum.h22
-rw-r--r--src/include/postmaster/fork_process.h4
-rw-r--r--src/include/postmaster/syslogger.h3
-rw-r--r--src/include/regex/regcustom.h11
-rw-r--r--src/include/regex/regex.h8
-rw-r--r--src/include/regex/regguts.h14
-rw-r--r--src/include/storage/backendid.h5
-rw-r--r--src/include/storage/buf_internals.h25
-rw-r--r--src/include/storage/bufmgr.h4
-rw-r--r--src/include/storage/fd.h4
-rw-r--r--src/include/storage/itemptr.h5
-rw-r--r--src/include/storage/lmgr.h21
-rw-r--r--src/include/storage/lock.h45
-rw-r--r--src/include/storage/lwlock.h5
-rw-r--r--src/include/storage/pg_shmem.h4
-rw-r--r--src/include/storage/proc.h16
-rw-r--r--src/include/storage/procarray.h4
-rw-r--r--src/include/storage/sinval.h8
-rw-r--r--src/include/storage/sinvaladt.h9
-rw-r--r--src/include/storage/smgr.h4
-rw-r--r--src/include/tcop/dest.h4
-rw-r--r--src/include/tcop/pquery.h4
-rw-r--r--src/include/tcop/tcopprot.h4
-rw-r--r--src/include/utils/acl.h10
-rw-r--r--src/include/utils/array.h4
-rw-r--r--src/include/utils/builtins.h4
-rw-r--r--src/include/utils/catcache.h65
-rw-r--r--src/include/utils/date.h13
-rw-r--r--src/include/utils/datetime.h30
-rw-r--r--src/include/utils/elog.h32
-rw-r--r--src/include/utils/flatfiles.h8
-rw-r--r--src/include/utils/fmgrtab.h5
-rw-r--r--src/include/utils/guc.h10
-rw-r--r--src/include/utils/hsearch.h15
-rw-r--r--src/include/utils/inval.h4
-rw-r--r--src/include/utils/lsyscache.h6
-rw-r--r--src/include/utils/nabstime.h4
-rw-r--r--src/include/utils/palloc.h5
-rw-r--r--src/include/utils/pg_crc.h10
-rw-r--r--src/include/utils/portal.h45
-rw-r--r--src/include/utils/rel.h25
-rw-r--r--src/include/utils/relcache.h6
-rw-r--r--src/include/utils/selfuncs.h4
-rw-r--r--src/include/utils/syscache.h4
-rw-r--r--src/include/utils/timestamp.h35
-rw-r--r--src/include/utils/tqual.h6
-rw-r--r--src/include/utils/typcache.h12
-rw-r--r--src/interfaces/ecpg/compatlib/informix.c59
-rw-r--r--src/interfaces/ecpg/ecpglib/connect.c37
-rw-r--r--src/interfaces/ecpg/ecpglib/data.c26
-rw-r--r--src/interfaces/ecpg/ecpglib/error.c16
-rw-r--r--src/interfaces/ecpg/ecpglib/execute.c53
-rw-r--r--src/interfaces/ecpg/ecpglib/extern.h3
-rw-r--r--src/interfaces/ecpg/ecpglib/memory.c4
-rw-r--r--src/interfaces/ecpg/ecpglib/misc.c19
-rw-r--r--src/interfaces/ecpg/ecpglib/prepare.c12
-rw-r--r--src/interfaces/ecpg/include/ecpgtype.h8
-rw-r--r--src/interfaces/ecpg/include/pgtypes_interval.h11
-rw-r--r--src/interfaces/ecpg/include/pgtypes_numeric.h18
-rw-r--r--src/interfaces/ecpg/include/pgtypes_timestamp.h5
-rw-r--r--src/interfaces/ecpg/pgtypeslib/common.c3
-rw-r--r--src/interfaces/ecpg/pgtypeslib/datetime.c74
-rw-r--r--src/interfaces/ecpg/pgtypeslib/dt.h29
-rw-r--r--src/interfaces/ecpg/pgtypeslib/dt_common.c326
-rw-r--r--src/interfaces/ecpg/pgtypeslib/extern.h8
-rw-r--r--src/interfaces/ecpg/pgtypeslib/interval.c58
-rw-r--r--src/interfaces/ecpg/pgtypeslib/numeric.c90
-rw-r--r--src/interfaces/ecpg/pgtypeslib/timestamp.c171
-rw-r--r--src/interfaces/ecpg/preproc/ecpg.c8
-rw-r--r--src/interfaces/ecpg/preproc/ecpg_keywords.c18
-rw-r--r--src/interfaces/ecpg/preproc/keywords.c723
-rw-r--r--src/interfaces/ecpg/preproc/type.c18
-rw-r--r--src/interfaces/ecpg/preproc/type.h13
-rw-r--r--src/interfaces/ecpg/preproc/variable.c20
-rw-r--r--src/interfaces/libpq/fe-auth.c36
-rw-r--r--src/interfaces/libpq/fe-auth.h4
-rw-r--r--src/interfaces/libpq/fe-connect.c381
-rw-r--r--src/interfaces/libpq/fe-exec.c200
-rw-r--r--src/interfaces/libpq/fe-lobj.c49
-rw-r--r--src/interfaces/libpq/fe-misc.c146
-rw-r--r--src/interfaces/libpq/fe-print.c37
-rw-r--r--src/interfaces/libpq/fe-protocol2.c189
-rw-r--r--src/interfaces/libpq/fe-protocol3.c198
-rw-r--r--src/interfaces/libpq/fe-secure.c160
-rw-r--r--src/interfaces/libpq/libpq-fe.h46
-rw-r--r--src/interfaces/libpq/libpq-int.h99
-rw-r--r--src/interfaces/libpq/pqexpbuffer.c33
-rw-r--r--src/interfaces/libpq/pthread-win32.h14
-rw-r--r--src/interfaces/libpq/win32.c4
-rw-r--r--src/pl/plperl/plperl.c245
-rw-r--r--src/pl/plperl/ppport.h14
-rw-r--r--src/pl/plperl/spi_internal.h6
-rw-r--r--src/pl/plpgsql/src/pl_comp.c268
-rw-r--r--src/pl/plpgsql/src/pl_exec.c893
-rw-r--r--src/pl/plpgsql/src/pl_funcs.c134
-rw-r--r--src/pl/plpgsql/src/pl_handler.c8
-rw-r--r--src/pl/plpgsql/src/plpgsql.h131
-rw-r--r--src/pl/plpython/plpython.c100
-rw-r--r--src/pl/tcl/pltcl.c137
-rw-r--r--src/port/copydir.c8
-rw-r--r--src/port/crypt.c25
-rw-r--r--src/port/dirmod.c50
-rw-r--r--src/port/exec.c65
-rw-r--r--src/port/getaddrinfo.c32
-rw-r--r--src/port/getopt.c3
-rw-r--r--src/port/getopt_long.c4
-rw-r--r--src/port/getrusage.c26
-rw-r--r--src/port/inet_aton.c10
-rw-r--r--src/port/isinf.c8
-rw-r--r--src/port/memcmp.c14
-rw-r--r--src/port/noblock.c5
-rw-r--r--src/port/open.c24
-rw-r--r--src/port/path.c75
-rw-r--r--src/port/qsort.c14
-rw-r--r--src/port/snprintf.c39
-rw-r--r--src/port/sprompt.c7
-rw-r--r--src/port/strtol.c23
-rw-r--r--src/port/thread.c7
-rw-r--r--src/port/unsetenv.c25
-rw-r--r--src/test/examples/testlibpq.c17
-rw-r--r--src/test/examples/testlibpq2.c18
-rw-r--r--src/test/examples/testlibpq3.c31
-rw-r--r--src/test/examples/testlibpq4.c11
-rw-r--r--src/test/regress/regress.c24
-rw-r--r--src/timezone/ialloc.c8
-rw-r--r--src/timezone/localtime.c172
-rw-r--r--src/timezone/pgtz.c229
-rw-r--r--src/timezone/pgtz.h13
-rw-r--r--src/timezone/scheck.c10
-rw-r--r--src/timezone/strftime.c51
-rw-r--r--src/timezone/tzfile.h17
-rw-r--r--src/timezone/zic.c221
-rw-r--r--src/tools/entab/entab.c6
-rw-r--r--src/tools/entab/halt.c4
-rw-r--r--src/tools/findoidjoins/findoidjoins.c8
-rw-r--r--src/tools/fsync/test_fsync.c3
-rw-r--r--src/tools/thread/thread_test.c95
-rw-r--r--src/tutorial/beard.c4
-rw-r--r--src/tutorial/funcs_new.c3
770 files changed, 34394 insertions, 32567 deletions
diff --git a/contrib/btree_gist/btree_cash.c b/contrib/btree_gist/btree_cash.c
index cef6103734..13f8200fb7 100644
--- a/contrib/btree_gist/btree_cash.c
+++ b/contrib/btree_gist/btree_cash.c
@@ -125,10 +125,10 @@ Datum
gbt_cash_penalty(PG_FUNCTION_ARGS)
{
cashKEY *origentry = (cashKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
- cashKEY *newentry = (cashKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
- float *result = (float *) PG_GETARG_POINTER(2);
+ cashKEY *newentry = (cashKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
+ float *result = (float *) PG_GETARG_POINTER(2);
- penalty_num(result,origentry->lower,origentry->upper,newentry->lower,newentry->upper);
+ penalty_num(result, origentry->lower, origentry->upper, newentry->lower, newentry->upper);
PG_RETURN_POINTER(result);
@@ -138,8 +138,8 @@ Datum
gbt_cash_picksplit(PG_FUNCTION_ARGS)
{
PG_RETURN_POINTER(gbt_num_picksplit(
- (GistEntryVector *) PG_GETARG_POINTER(0),
- (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
+ (GistEntryVector *) PG_GETARG_POINTER(0),
+ (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
&tinfo
));
}
diff --git a/contrib/btree_gist/btree_date.c b/contrib/btree_gist/btree_date.c
index d3ce33c717..b14888889d 100644
--- a/contrib/btree_gist/btree_date.c
+++ b/contrib/btree_gist/btree_date.c
@@ -148,15 +148,15 @@ gbt_date_penalty(PG_FUNCTION_ARGS)
diff = DatumGetInt32(DirectFunctionCall2(
date_mi,
- DateADTGetDatum(newentry->upper),
- DateADTGetDatum(origentry->upper)));
+ DateADTGetDatum(newentry->upper),
+ DateADTGetDatum(origentry->upper)));
res = Max(diff, 0);
diff = DatumGetInt32(DirectFunctionCall2(
date_mi,
- DateADTGetDatum(origentry->lower),
- DateADTGetDatum(newentry->lower)));
+ DateADTGetDatum(origentry->lower),
+ DateADTGetDatum(newentry->lower)));
res += Max(diff, 0);
@@ -166,8 +166,8 @@ gbt_date_penalty(PG_FUNCTION_ARGS)
{
diff = DatumGetInt32(DirectFunctionCall2(
date_mi,
- DateADTGetDatum(origentry->upper),
- DateADTGetDatum(origentry->lower)));
+ DateADTGetDatum(origentry->upper),
+ DateADTGetDatum(origentry->lower)));
*result += FLT_MIN;
*result += (float) (res / ((double) (res + diff)));
*result *= (FLT_MAX / (((GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1));
@@ -181,8 +181,8 @@ Datum
gbt_date_picksplit(PG_FUNCTION_ARGS)
{
PG_RETURN_POINTER(gbt_num_picksplit(
- (GistEntryVector *) PG_GETARG_POINTER(0),
- (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
+ (GistEntryVector *) PG_GETARG_POINTER(0),
+ (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
&tinfo
));
}
diff --git a/contrib/btree_gist/btree_float4.c b/contrib/btree_gist/btree_float4.c
index 9d6c174773..a4c941f835 100644
--- a/contrib/btree_gist/btree_float4.c
+++ b/contrib/btree_gist/btree_float4.c
@@ -127,7 +127,7 @@ gbt_float4_penalty(PG_FUNCTION_ARGS)
float4KEY *newentry = (float4KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
float *result = (float *) PG_GETARG_POINTER(2);
- penalty_num(result,origentry->lower,origentry->upper,newentry->lower,newentry->upper);
+ penalty_num(result, origentry->lower, origentry->upper, newentry->lower, newentry->upper);
PG_RETURN_POINTER(result);
@@ -137,8 +137,8 @@ Datum
gbt_float4_picksplit(PG_FUNCTION_ARGS)
{
PG_RETURN_POINTER(gbt_num_picksplit(
- (GistEntryVector *) PG_GETARG_POINTER(0),
- (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
+ (GistEntryVector *) PG_GETARG_POINTER(0),
+ (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
&tinfo
));
}
diff --git a/contrib/btree_gist/btree_float8.c b/contrib/btree_gist/btree_float8.c
index 7345d37b21..1b87b4ee1b 100644
--- a/contrib/btree_gist/btree_float8.c
+++ b/contrib/btree_gist/btree_float8.c
@@ -129,7 +129,7 @@ gbt_float8_penalty(PG_FUNCTION_ARGS)
float8KEY *newentry = (float8KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
float *result = (float *) PG_GETARG_POINTER(2);
- penalty_num(result,origentry->lower,origentry->upper,newentry->lower,newentry->upper);
+ penalty_num(result, origentry->lower, origentry->upper, newentry->lower, newentry->upper);
PG_RETURN_POINTER(result);
@@ -139,8 +139,8 @@ Datum
gbt_float8_picksplit(PG_FUNCTION_ARGS)
{
PG_RETURN_POINTER(gbt_num_picksplit(
- (GistEntryVector *) PG_GETARG_POINTER(0),
- (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
+ (GistEntryVector *) PG_GETARG_POINTER(0),
+ (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
&tinfo
));
}
diff --git a/contrib/btree_gist/btree_inet.c b/contrib/btree_gist/btree_inet.c
index 3719d3bb1a..5f27a007f5 100644
--- a/contrib/btree_gist/btree_inet.c
+++ b/contrib/btree_gist/btree_inet.c
@@ -194,8 +194,8 @@ gbt_inet_penalty(PG_FUNCTION_ARGS)
inetKEY *newentry = (inetKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
float *result = (float *) PG_GETARG_POINTER(2);
- penalty_num(result,origentry->lower,origentry->upper,newentry->lower,newentry->upper);
-
+ penalty_num(result, origentry->lower, origentry->upper, newentry->lower, newentry->upper);
+
PG_RETURN_POINTER(result);
}
@@ -204,8 +204,8 @@ Datum
gbt_inet_picksplit(PG_FUNCTION_ARGS)
{
PG_RETURN_POINTER(gbt_num_picksplit(
- (GistEntryVector *) PG_GETARG_POINTER(0),
- (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
+ (GistEntryVector *) PG_GETARG_POINTER(0),
+ (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
&tinfo
));
}
diff --git a/contrib/btree_gist/btree_int2.c b/contrib/btree_gist/btree_int2.c
index 8bbdb1d802..5e2a66526e 100644
--- a/contrib/btree_gist/btree_int2.c
+++ b/contrib/btree_gist/btree_int2.c
@@ -128,10 +128,10 @@ Datum
gbt_int2_penalty(PG_FUNCTION_ARGS)
{
int16KEY *origentry = (int16KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
- int16KEY *newentry = (int16KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
- float *result = (float *) PG_GETARG_POINTER(2);
+ int16KEY *newentry = (int16KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
+ float *result = (float *) PG_GETARG_POINTER(2);
- penalty_num(result,origentry->lower,origentry->upper,newentry->lower,newentry->upper);
+ penalty_num(result, origentry->lower, origentry->upper, newentry->lower, newentry->upper);
PG_RETURN_POINTER(result);
}
@@ -140,8 +140,8 @@ Datum
gbt_int2_picksplit(PG_FUNCTION_ARGS)
{
PG_RETURN_POINTER(gbt_num_picksplit(
- (GistEntryVector *) PG_GETARG_POINTER(0),
- (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
+ (GistEntryVector *) PG_GETARG_POINTER(0),
+ (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
&tinfo
));
}
diff --git a/contrib/btree_gist/btree_int4.c b/contrib/btree_gist/btree_int4.c
index 43a4cbe6be..6a69b85bdd 100644
--- a/contrib/btree_gist/btree_int4.c
+++ b/contrib/btree_gist/btree_int4.c
@@ -126,10 +126,10 @@ Datum
gbt_int4_penalty(PG_FUNCTION_ARGS)
{
int32KEY *origentry = (int32KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
- int32KEY *newentry = (int32KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
- float *result = (float *) PG_GETARG_POINTER(2);
-
- penalty_num(result,origentry->lower,origentry->upper,newentry->lower,newentry->upper);
+ int32KEY *newentry = (int32KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
+ float *result = (float *) PG_GETARG_POINTER(2);
+
+ penalty_num(result, origentry->lower, origentry->upper, newentry->lower, newentry->upper);
PG_RETURN_POINTER(result);
}
@@ -138,8 +138,8 @@ Datum
gbt_int4_picksplit(PG_FUNCTION_ARGS)
{
PG_RETURN_POINTER(gbt_num_picksplit(
- (GistEntryVector *) PG_GETARG_POINTER(0),
- (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
+ (GistEntryVector *) PG_GETARG_POINTER(0),
+ (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
&tinfo
));
}
diff --git a/contrib/btree_gist/btree_int8.c b/contrib/btree_gist/btree_int8.c
index 7de02dbca7..83275f2c7a 100644
--- a/contrib/btree_gist/btree_int8.c
+++ b/contrib/btree_gist/btree_int8.c
@@ -125,11 +125,11 @@ Datum
gbt_int8_penalty(PG_FUNCTION_ARGS)
{
int64KEY *origentry = (int64KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
- int64KEY *newentry = (int64KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
- float *result = (float *) PG_GETARG_POINTER(2);
+ int64KEY *newentry = (int64KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
+ float *result = (float *) PG_GETARG_POINTER(2);
+
+ penalty_num(result, origentry->lower, origentry->upper, newentry->lower, newentry->upper);
- penalty_num(result,origentry->lower,origentry->upper,newentry->lower,newentry->upper);
-
PG_RETURN_POINTER(result);
}
@@ -137,8 +137,8 @@ Datum
gbt_int8_picksplit(PG_FUNCTION_ARGS)
{
PG_RETURN_POINTER(gbt_num_picksplit(
- (GistEntryVector *) PG_GETARG_POINTER(0),
- (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
+ (GistEntryVector *) PG_GETARG_POINTER(0),
+ (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
&tinfo
));
}
diff --git a/contrib/btree_gist/btree_interval.c b/contrib/btree_gist/btree_interval.c
index 3c671a3f04..b7776295a0 100644
--- a/contrib/btree_gist/btree_interval.c
+++ b/contrib/btree_gist/btree_interval.c
@@ -63,8 +63,8 @@ gbt_intvkey_cmp(const void *a, const void *b)
{
return DatumGetInt32(
DirectFunctionCall2(interval_cmp,
- IntervalPGetDatum(((Nsrt *) a)->t),
- IntervalPGetDatum(((Nsrt *) b)->t)
+ IntervalPGetDatum(((Nsrt *) a)->t),
+ IntervalPGetDatum(((Nsrt *) b)->t)
)
);
}
@@ -78,7 +78,7 @@ intr2num(const Interval *i)
/*
* INTERVALSIZE should be the actual size-on-disk of an Interval, as shown
- * in pg_type. This might be less than sizeof(Interval) if the compiler
+ * in pg_type. This might be less than sizeof(Interval) if the compiler
* insists on adding alignment padding at the end of the struct.
*/
#define INTERVALSIZE 16
@@ -202,7 +202,7 @@ gbt_intv_penalty(PG_FUNCTION_ARGS)
inew[0] = intr2num(&newentry->lower);
inew[1] = intr2num(&newentry->upper);
- penalty_num(result,iorg[0],iorg[1],inew[0],inew[1]);
+ penalty_num(result, iorg[0], iorg[1], inew[0], inew[1]);
PG_RETURN_POINTER(result);
@@ -212,8 +212,8 @@ Datum
gbt_intv_picksplit(PG_FUNCTION_ARGS)
{
PG_RETURN_POINTER(gbt_num_picksplit(
- (GistEntryVector *) PG_GETARG_POINTER(0),
- (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
+ (GistEntryVector *) PG_GETARG_POINTER(0),
+ (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
&tinfo
));
}
diff --git a/contrib/btree_gist/btree_macaddr.c b/contrib/btree_gist/btree_macaddr.c
index ee56f0fac1..52cf4cb1d4 100644
--- a/contrib/btree_gist/btree_macaddr.c
+++ b/contrib/btree_gist/btree_macaddr.c
@@ -63,8 +63,8 @@ gbt_macadkey_cmp(const void *a, const void *b)
return DatumGetInt32(
DirectFunctionCall2(
macaddr_cmp,
- PointerGetDatum(&((Nsrt *) a)->t[0]),
- PointerGetDatum(&((Nsrt *) b)->t[0])
+ PointerGetDatum(&((Nsrt *) a)->t[0]),
+ PointerGetDatum(&((Nsrt *) b)->t[0])
)
);
}
@@ -157,7 +157,7 @@ gbt_macad_penalty(PG_FUNCTION_ARGS)
inew[0] = mac_2_uint64(&newentry->lower);
inew[1] = mac_2_uint64(&newentry->upper);
- penalty_num(result,iorg[0],iorg[1],inew[0],inew[1]);
+ penalty_num(result, iorg[0], iorg[1], inew[0], inew[1]);
PG_RETURN_POINTER(result);
@@ -167,8 +167,8 @@ Datum
gbt_macad_picksplit(PG_FUNCTION_ARGS)
{
PG_RETURN_POINTER(gbt_num_picksplit(
- (GistEntryVector *) PG_GETARG_POINTER(0),
- (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
+ (GistEntryVector *) PG_GETARG_POINTER(0),
+ (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
&tinfo
));
}
diff --git a/contrib/btree_gist/btree_oid.c b/contrib/btree_gist/btree_oid.c
index d76d876372..979d728a73 100644
--- a/contrib/btree_gist/btree_oid.c
+++ b/contrib/btree_gist/btree_oid.c
@@ -129,7 +129,7 @@ gbt_oid_penalty(PG_FUNCTION_ARGS)
oidKEY *newentry = (oidKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
float *result = (float *) PG_GETARG_POINTER(2);
- penalty_num(result,origentry->lower,origentry->upper,newentry->lower,newentry->upper);
+ penalty_num(result, origentry->lower, origentry->upper, newentry->lower, newentry->upper);
PG_RETURN_POINTER(result);
}
@@ -138,8 +138,8 @@ Datum
gbt_oid_picksplit(PG_FUNCTION_ARGS)
{
PG_RETURN_POINTER(gbt_num_picksplit(
- (GistEntryVector *) PG_GETARG_POINTER(0),
- (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
+ (GistEntryVector *) PG_GETARG_POINTER(0),
+ (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
&tinfo
));
}
diff --git a/contrib/btree_gist/btree_text.c b/contrib/btree_gist/btree_text.c
index 1275df6aef..6ab77f86ae 100644
--- a/contrib/btree_gist/btree_text.c
+++ b/contrib/btree_gist/btree_text.c
@@ -87,7 +87,7 @@ gbt_text_compress(PG_FUNCTION_ARGS)
{
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
- if ( tinfo.eml == 0 )
+ if (tinfo.eml == 0)
{
tinfo.eml = pg_database_encoding_max_length();
}
@@ -102,7 +102,7 @@ gbt_bpchar_compress(PG_FUNCTION_ARGS)
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
GISTENTRY *retval;
- if ( tinfo.eml == 0 )
+ if (tinfo.eml == 0)
{
tinfo.eml = pg_database_encoding_max_length();
}
@@ -111,7 +111,7 @@ gbt_bpchar_compress(PG_FUNCTION_ARGS)
{
Datum d = DirectFunctionCall1(rtrim1, entry->key);
- GISTENTRY trim;
+ GISTENTRY trim;
gistentryinit(trim, d,
entry->rel, entry->page,
@@ -136,7 +136,7 @@ gbt_text_consistent(PG_FUNCTION_ARGS)
bool retval = FALSE;
GBT_VARKEY_R r = gbt_var_key_readable(key);
- if ( tinfo.eml == 0 )
+ if (tinfo.eml == 0)
{
tinfo.eml = pg_database_encoding_max_length();
}
@@ -158,7 +158,7 @@ gbt_bpchar_consistent(PG_FUNCTION_ARGS)
bool retval;
GBT_VARKEY_R r = gbt_var_key_readable(key);
- if ( tinfo.eml == 0 )
+ if (tinfo.eml == 0)
{
tinfo.eml = pg_database_encoding_max_length();
}
diff --git a/contrib/btree_gist/btree_time.c b/contrib/btree_gist/btree_time.c
index 02f2664349..c6a5697af0 100644
--- a/contrib/btree_gist/btree_time.c
+++ b/contrib/btree_gist/btree_time.c
@@ -36,7 +36,7 @@ static bool
gbt_timegt(const void *a, const void *b)
{
return DatumGetBool(
- DirectFunctionCall2(time_gt, PointerGetDatum(a), PointerGetDatum(b))
+ DirectFunctionCall2(time_gt, PointerGetDatum(a), PointerGetDatum(b))
);
}
@@ -44,7 +44,7 @@ static bool
gbt_timege(const void *a, const void *b)
{
return DatumGetBool(
- DirectFunctionCall2(time_ge, PointerGetDatum(a), PointerGetDatum(b))
+ DirectFunctionCall2(time_ge, PointerGetDatum(a), PointerGetDatum(b))
);
}
@@ -52,7 +52,7 @@ static bool
gbt_timeeq(const void *a, const void *b)
{
return DatumGetBool(
- DirectFunctionCall2(time_eq, PointerGetDatum(a), PointerGetDatum(b))
+ DirectFunctionCall2(time_eq, PointerGetDatum(a), PointerGetDatum(b))
);
}
@@ -60,7 +60,7 @@ static bool
gbt_timele(const void *a, const void *b)
{
return DatumGetBool(
- DirectFunctionCall2(time_le, PointerGetDatum(a), PointerGetDatum(b))
+ DirectFunctionCall2(time_le, PointerGetDatum(a), PointerGetDatum(b))
);
}
@@ -68,7 +68,7 @@ static bool
gbt_timelt(const void *a, const void *b)
{
return DatumGetBool(
- DirectFunctionCall2(time_lt, PointerGetDatum(a), PointerGetDatum(b))
+ DirectFunctionCall2(time_lt, PointerGetDatum(a), PointerGetDatum(b))
);
}
@@ -212,15 +212,15 @@ gbt_time_penalty(PG_FUNCTION_ARGS)
intr = DatumGetIntervalP(DirectFunctionCall2(
time_mi_time,
- P_TimeADTGetDatum(newentry->upper),
- P_TimeADTGetDatum(origentry->upper)));
+ P_TimeADTGetDatum(newentry->upper),
+ P_TimeADTGetDatum(origentry->upper)));
res = INTERVAL_TO_SEC(intr);
res = Max(res, 0);
intr = DatumGetIntervalP(DirectFunctionCall2(
time_mi_time,
- P_TimeADTGetDatum(origentry->lower),
- P_TimeADTGetDatum(newentry->lower)));
+ P_TimeADTGetDatum(origentry->lower),
+ P_TimeADTGetDatum(newentry->lower)));
res2 = INTERVAL_TO_SEC(intr);
res2 = Max(res2, 0);
@@ -232,8 +232,8 @@ gbt_time_penalty(PG_FUNCTION_ARGS)
{
intr = DatumGetIntervalP(DirectFunctionCall2(
time_mi_time,
- P_TimeADTGetDatum(origentry->upper),
- P_TimeADTGetDatum(origentry->lower)));
+ P_TimeADTGetDatum(origentry->upper),
+ P_TimeADTGetDatum(origentry->lower)));
*result += FLT_MIN;
*result += (float) (res / (res + INTERVAL_TO_SEC(intr)));
*result *= (FLT_MAX / (((GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1));
@@ -247,8 +247,8 @@ Datum
gbt_time_picksplit(PG_FUNCTION_ARGS)
{
PG_RETURN_POINTER(gbt_num_picksplit(
- (GistEntryVector *) PG_GETARG_POINTER(0),
- (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
+ (GistEntryVector *) PG_GETARG_POINTER(0),
+ (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
&tinfo
));
}
diff --git a/contrib/btree_gist/btree_ts.c b/contrib/btree_gist/btree_ts.c
index 119c45093e..9f305119d8 100644
--- a/contrib/btree_gist/btree_ts.c
+++ b/contrib/btree_gist/btree_ts.c
@@ -32,13 +32,13 @@ Datum gbt_ts_penalty(PG_FUNCTION_ARGS);
Datum gbt_ts_same(PG_FUNCTION_ARGS);
-#define P_TimestampGetDatum(x) PointerGetDatum( &(x) )
+#define P_TimestampGetDatum(x) PointerGetDatum( &(x) )
static bool
gbt_tsgt(const void *a, const void *b)
{
return DatumGetBool(
- DirectFunctionCall2(timestamp_gt, PointerGetDatum(a), PointerGetDatum(b))
+ DirectFunctionCall2(timestamp_gt, PointerGetDatum(a), PointerGetDatum(b))
);
}
@@ -46,7 +46,7 @@ static bool
gbt_tsge(const void *a, const void *b)
{
return DatumGetBool(
- DirectFunctionCall2(timestamp_ge, PointerGetDatum(a), PointerGetDatum(b))
+ DirectFunctionCall2(timestamp_ge, PointerGetDatum(a), PointerGetDatum(b))
);
}
@@ -54,7 +54,7 @@ static bool
gbt_tseq(const void *a, const void *b)
{
return DatumGetBool(
- DirectFunctionCall2(timestamp_eq, PointerGetDatum(a), PointerGetDatum(b))
+ DirectFunctionCall2(timestamp_eq, PointerGetDatum(a), PointerGetDatum(b))
);
}
@@ -62,7 +62,7 @@ static bool
gbt_tsle(const void *a, const void *b)
{
return DatumGetBool(
- DirectFunctionCall2(timestamp_le, PointerGetDatum(a), PointerGetDatum(b))
+ DirectFunctionCall2(timestamp_le, PointerGetDatum(a), PointerGetDatum(b))
);
}
@@ -70,7 +70,7 @@ static bool
gbt_tslt(const void *a, const void *b)
{
return DatumGetBool(
- DirectFunctionCall2(timestamp_lt, PointerGetDatum(a), PointerGetDatum(b))
+ DirectFunctionCall2(timestamp_lt, PointerGetDatum(a), PointerGetDatum(b))
);
}
@@ -114,7 +114,7 @@ tstz_to_ts_gmt(Timestamp *gmt, TimestampTz *ts)
*gmt = *ts;
DecodeSpecial(0, "gmt", &val);
- if ( *ts < DT_NOEND && *ts > DT_NOBEGIN )
+ if (*ts < DT_NOEND && *ts > DT_NOBEGIN)
{
tz = val * 60;
@@ -217,10 +217,10 @@ gbt_ts_union(PG_FUNCTION_ARGS)
#define penalty_check_max_float(val) do { \
- if ( val > FLT_MAX ) \
- val = FLT_MAX; \
- if ( val < -FLT_MAX ) \
- val = -FLT_MAX; \
+ if ( val > FLT_MAX ) \
+ val = FLT_MAX; \
+ if ( val < -FLT_MAX ) \
+ val = -FLT_MAX; \
} while(false);
@@ -232,24 +232,24 @@ gbt_ts_penalty(PG_FUNCTION_ARGS)
tsKEY *newentry = (tsKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
float *result = (float *) PG_GETARG_POINTER(2);
- double orgdbl[2],
- newdbl[2];
+ double orgdbl[2],
+ newdbl[2];
/*
- We are allways using "double" timestamps here.
- Precision should be good enough.
- */
- orgdbl[0] = ( (double) origentry->lower ) ;
- orgdbl[1] = ( (double) origentry->upper ) ;
- newdbl[0] = ( (double) newentry->lower ) ;
- newdbl[1] = ( (double) newentry->upper ) ;
+ * We are allways using "double" timestamps here. Precision should be good
+ * enough.
+ */
+ orgdbl[0] = ((double) origentry->lower);
+ orgdbl[1] = ((double) origentry->upper);
+ newdbl[0] = ((double) newentry->lower);
+ newdbl[1] = ((double) newentry->upper);
- penalty_check_max_float( orgdbl[0] );
- penalty_check_max_float( orgdbl[1] );
- penalty_check_max_float( newdbl[0] );
- penalty_check_max_float( newdbl[1] );
+ penalty_check_max_float(orgdbl[0]);
+ penalty_check_max_float(orgdbl[1]);
+ penalty_check_max_float(newdbl[0]);
+ penalty_check_max_float(newdbl[1]);
- penalty_num(result,orgdbl[0],orgdbl[1],newdbl[0],newdbl[1]);
+ penalty_num(result, orgdbl[0], orgdbl[1], newdbl[0], newdbl[1]);
PG_RETURN_POINTER(result);
@@ -260,8 +260,8 @@ Datum
gbt_ts_picksplit(PG_FUNCTION_ARGS)
{
PG_RETURN_POINTER(gbt_num_picksplit(
- (GistEntryVector *) PG_GETARG_POINTER(0),
- (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
+ (GistEntryVector *) PG_GETARG_POINTER(0),
+ (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
&tinfo
));
}
diff --git a/contrib/btree_gist/btree_utils_num.h b/contrib/btree_gist/btree_utils_num.h
index 94d4bf7437..322c5759e4 100644
--- a/contrib/btree_gist/btree_utils_num.h
+++ b/contrib/btree_gist/btree_utils_num.h
@@ -48,17 +48,17 @@ typedef struct
* Note: The factor 0.49 in following macro avoids floating point overflows
*/
#define penalty_num(result,olower,oupper,nlower,nupper) do { \
- double tmp = 0.0F; \
- (*(result)) = 0.0F; \
+ double tmp = 0.0F; \
+ (*(result)) = 0.0F; \
if ( (nupper) > (oupper) ) \
tmp += ( ((double)nupper)*0.49F - ((double)oupper)*0.49F ); \
if ( (olower) > (nlower) ) \
tmp += ( ((double)olower)*0.49F - ((double)nlower)*0.49F ); \
if (tmp > 0.0F) \
{ \
- (*(result)) += FLT_MIN; \
- (*(result)) += (float) ( ((double)(tmp)) / ( (double)(tmp) + ( ((double)(oupper))*0.49F - ((double)(olower))*0.49F ) ) ); \
- (*(result)) *= (FLT_MAX / (((GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1)); \
+ (*(result)) += FLT_MIN; \
+ (*(result)) += (float) ( ((double)(tmp)) / ( (double)(tmp) + ( ((double)(oupper))*0.49F - ((double)(olower))*0.49F ) ) ); \
+ (*(result)) *= (FLT_MAX / (((GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1)); \
} \
} while (0);
diff --git a/contrib/btree_gist/btree_utils_var.c b/contrib/btree_gist/btree_utils_var.c
index 8de39bb327..20a1e427f2 100644
--- a/contrib/btree_gist/btree_utils_var.c
+++ b/contrib/btree_gist/btree_utils_var.c
@@ -4,14 +4,14 @@
#include "utils/builtins.h"
PG_FUNCTION_INFO_V1(gbt_var_decompress);
-Datum gbt_var_decompress(PG_FUNCTION_ARGS);
+Datum gbt_var_decompress(PG_FUNCTION_ARGS);
Datum
gbt_var_decompress(PG_FUNCTION_ARGS)
{
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
- GBT_VARKEY *key = (GBT_VARKEY *) DatumGetPointer(PG_DETOAST_DATUM(entry->key));
+ GBT_VARKEY *key = (GBT_VARKEY *) DatumGetPointer(PG_DETOAST_DATUM(entry->key));
if (key != (GBT_VARKEY *) DatumGetPointer(entry->key))
{
@@ -92,45 +92,47 @@ static int32
gbt_var_node_cp_len(const GBT_VARKEY * node, const gbtree_vinfo * tinfo)
{
- GBT_VARKEY_R r = gbt_var_key_readable(node);
- int32 i = 0;
- int32 l = 0;
- int32 t1len = VARSIZE(r.lower) - VARHDRSZ ;
- int32 t2len = VARSIZE(r.upper) - VARHDRSZ ;
- int32 ml = Min(t1len, t2len);
+ GBT_VARKEY_R r = gbt_var_key_readable(node);
+ int32 i = 0;
+ int32 l = 0;
+ int32 t1len = VARSIZE(r.lower) - VARHDRSZ;
+ int32 t2len = VARSIZE(r.upper) - VARHDRSZ;
+ int32 ml = Min(t1len, t2len);
- char *p1 = VARDATA(r.lower);
- char *p2 = VARDATA(r.upper);
+ char *p1 = VARDATA(r.lower);
+ char *p2 = VARDATA(r.upper);
- if ( ml == 0 )
- return 0;
+ if (ml == 0)
+ return 0;
- while ( i < ml )
+ while (i < ml)
{
- if ( tinfo->eml > 1 && l == 0 )
- {
-
- if ( ( l = pg_mblen(p1) ) != pg_mblen(p2) )
- {
- return i;
- }
- }
- if (*p1 != *p2)
- {
- if( tinfo->eml > 1 )
- {
- return (i-l+1);
- } else {
- return i;
- }
- }
-
- p1++;
- p2++;
- l--;
- i++;
+ if (tinfo->eml > 1 && l == 0)
+ {
+
+ if ((l = pg_mblen(p1)) != pg_mblen(p2))
+ {
+ return i;
+ }
+ }
+ if (*p1 != *p2)
+ {
+ if (tinfo->eml > 1)
+ {
+ return (i - l + 1);
+ }
+ else
+ {
+ return i;
+ }
+ }
+
+ p1++;
+ p2++;
+ l--;
+ i++;
}
- return (ml); /* lower == upper */
+ return (ml); /* lower == upper */
}
@@ -141,35 +143,37 @@ static bool
gbt_bytea_pf_match(const bytea *pf, const bytea *query, const gbtree_vinfo * tinfo)
{
- bool out = FALSE;
- int32 k = 0;
- int32 qlen = VARSIZE(query) - VARHDRSZ ;
- int32 nlen = VARSIZE(pf) - VARHDRSZ ;
+ bool out = FALSE;
+ int32 k = 0;
+ int32 qlen = VARSIZE(query) - VARHDRSZ;
+ int32 nlen = VARSIZE(pf) - VARHDRSZ;
if (nlen <= qlen)
{
- char *q = VARDATA(query);
- char *n = VARDATA(pf);
-
- if ( tinfo->eml > 1 )
- {
- out = ( varstr_cmp(q, nlen, n, nlen) == 0 );
- } else {
- out = TRUE;
- for (k = 0; k < nlen; k++)
- {
- if (*n != *q)
- {
- out = FALSE;
- break;
- }
- if (k < (nlen - 1))
- {
- q++;
- n++;
- }
- }
- }
+ char *q = VARDATA(query);
+ char *n = VARDATA(pf);
+
+ if (tinfo->eml > 1)
+ {
+ out = (varstr_cmp(q, nlen, n, nlen) == 0);
+ }
+ else
+ {
+ out = TRUE;
+ for (k = 0; k < nlen; k++)
+ {
+ if (*n != *q)
+ {
+ out = FALSE;
+ break;
+ }
+ if (k < (nlen - 1))
+ {
+ q++;
+ n++;
+ }
+ }
+ }
}
return out;
@@ -184,10 +188,10 @@ static bool
gbt_var_node_pf_match(const GBT_VARKEY_R * node, const bytea *query, const gbtree_vinfo * tinfo)
{
- return ( tinfo->trnc && (
- gbt_bytea_pf_match(node->lower, query, tinfo) ||
- gbt_bytea_pf_match(node->upper, query, tinfo)
- ) );
+ return (tinfo->trnc && (
+ gbt_bytea_pf_match(node->lower, query, tinfo) ||
+ gbt_bytea_pf_match(node->upper, query, tinfo)
+ ));
}
@@ -201,18 +205,18 @@ gbt_var_node_truncate(const GBT_VARKEY * node, int32 cpf_length, const gbtree_vi
{
GBT_VARKEY *out = NULL;
GBT_VARKEY_R r = gbt_var_key_readable(node);
- int32 len1 = VARSIZE(r.lower) - VARHDRSZ;
- int32 len2 = VARSIZE(r.upper) - VARHDRSZ;
- int32 si = 0;
+ int32 len1 = VARSIZE(r.lower) - VARHDRSZ;
+ int32 len2 = VARSIZE(r.upper) - VARHDRSZ;
+ int32 si = 0;
- len1 = Min(len1,(cpf_length + 1));
- len2 = Min(len2,(cpf_length + 1));
+ len1 = Min(len1, (cpf_length + 1));
+ len2 = Min(len2, (cpf_length + 1));
si = 2 * VARHDRSZ + INTALIGN(VARHDRSZ + len1) + len2;
out = (GBT_VARKEY *) palloc(si);
out->vl_len = si;
- memcpy((void *) &(((char *) out)[VARHDRSZ]), (void *) r.lower, len1 + VARHDRSZ );
- memcpy((void *) &(((char *) out)[VARHDRSZ + INTALIGN(VARHDRSZ + len1)]), (void *) r.upper, len2 + VARHDRSZ );
+ memcpy((void *) &(((char *) out)[VARHDRSZ]), (void *) r.lower, len1 + VARHDRSZ);
+ memcpy((void *) &(((char *) out)[VARHDRSZ + INTALIGN(VARHDRSZ + len1)]), (void *) r.upper, len2 + VARHDRSZ);
*((int32 *) &(((char *) out)[VARHDRSZ])) = len1 + VARHDRSZ;
*((int32 *) &(((char *) out)[VARHDRSZ + INTALIGN(VARHDRSZ + len1)])) = len2 + VARHDRSZ;
@@ -568,8 +572,8 @@ gbt_var_consistent(
else
retval = (
(
- (*tinfo->f_cmp) (key->lower, (bytea *) query) <= 0 &&
- (*tinfo->f_cmp) ((bytea *) query, (void *) key->upper) <= 0
+ (*tinfo->f_cmp) (key->lower, (bytea *) query) <= 0 &&
+ (*tinfo->f_cmp) ((bytea *) query, (void *) key->upper) <= 0
) || gbt_var_node_pf_match(key, query, tinfo)
);
break;
diff --git a/contrib/btree_gist/btree_utils_var.h b/contrib/btree_gist/btree_utils_var.h
index e4d48d3910..9b7be0de0d 100644
--- a/contrib/btree_gist/btree_utils_var.h
+++ b/contrib/btree_gist/btree_utils_var.h
@@ -28,7 +28,8 @@ typedef struct
/* Attribs */
enum gbtree_type t; /* data type */
- int32 eml; /* cached pg_database_encoding_max_length (0: undefined) */
+ int32 eml; /* cached pg_database_encoding_max_length (0:
+ * undefined) */
bool trnc; /* truncate (=compress) key */
/* Methods */
diff --git a/contrib/chkpass/chkpass.c b/contrib/chkpass/chkpass.c
index 8dda0bc4ad..8b77fb2a3a 100644
--- a/contrib/chkpass/chkpass.c
+++ b/contrib/chkpass/chkpass.c
@@ -4,7 +4,7 @@
* darcy@druid.net
* http://www.druid.net/darcy/
*
- * $PostgreSQL: pgsql/contrib/chkpass/chkpass.c,v 1.13 2005/01/29 22:35:01 tgl Exp $
+ * $PostgreSQL: pgsql/contrib/chkpass/chkpass.c,v 1.14 2005/10/15 02:49:04 momjian Exp $
* best viewed with tabs set to 4
*/
@@ -90,8 +90,8 @@ chkpass_in(PG_FUNCTION_ARGS)
mysalt[0] = salt_chars[random() & 0x3f];
mysalt[1] = salt_chars[random() & 0x3f];
- mysalt[2] = 0; /* technically the terminator is not
- * necessary but I like to play safe */
+ mysalt[2] = 0; /* technically the terminator is not necessary
+ * but I like to play safe */
strcpy(result->password, crypt(str, mysalt));
PG_RETURN_POINTER(result);
}
diff --git a/contrib/cube/cube.c b/contrib/cube/cube.c
index cc6e1a39fe..fca03f02d7 100644
--- a/contrib/cube/cube.c
+++ b/contrib/cube/cube.c
@@ -115,7 +115,7 @@ NDBOX *
cube(text *str)
{
return cube_in(DatumGetCString(DirectFunctionCall1(textout,
- PointerGetDatum(str))));
+ PointerGetDatum(str))));
}
char *
@@ -219,7 +219,7 @@ g_cube_union(GistEntryVector *entryvec, int *sizep)
for (i = 1; i < entryvec->n; i++)
{
out = g_cube_binary_union(tmp, (NDBOX *)
- DatumGetPointer(entryvec->vector[i].key),
+ DatumGetPointer(entryvec->vector[i].key),
sizep);
tmp = out;
}
@@ -329,8 +329,7 @@ g_cube_picksplit(GistEntryVector *entryvec,
size_waste = size_union - size_inter;
/*
- * are these a more promising split than what we've already
- * seen?
+ * are these a more promising split than what we've already seen?
*/
if (size_waste > waste || firsttime)
@@ -356,24 +355,24 @@ g_cube_picksplit(GistEntryVector *entryvec,
rt_cube_size(datum_r, &size_r);
/*
- * Now split up the regions between the two seeds. An important
- * property of this split algorithm is that the split vector v has the
- * indices of items to be split in order in its left and right
- * vectors. We exploit this property by doing a merge in the code
- * that actually splits the page.
+ * Now split up the regions between the two seeds. An important property
+ * of this split algorithm is that the split vector v has the indices of
+ * items to be split in order in its left and right vectors. We exploit
+ * this property by doing a merge in the code that actually splits the
+ * page.
*
- * For efficiency, we also place the new index tuple in this loop. This
- * is handled at the very end, when we have placed all the existing
- * tuples and i == maxoff + 1.
+ * For efficiency, we also place the new index tuple in this loop. This is
+ * handled at the very end, when we have placed all the existing tuples
+ * and i == maxoff + 1.
*/
maxoff = OffsetNumberNext(maxoff);
for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i))
{
/*
- * If we've already decided where to place this item, just put it
- * on the right list. Otherwise, we need to figure out which page
- * needs the least enlargement in order to store the item.
+ * If we've already decided where to place this item, just put it on
+ * the right list. Otherwise, we need to figure out which page needs
+ * the least enlargement in order to store the item.
*/
if (i == seed_1)
@@ -542,8 +541,8 @@ cube_union(NDBOX * a, NDBOX * b)
}
/*
- * use the potentially smaller of the two boxes (b) to fill in the
- * result, padding absent dimensions with zeroes
+ * use the potentially smaller of the two boxes (b) to fill in the result,
+ * padding absent dimensions with zeroes
*/
for (i = 0; i < b->dim; i++)
{
@@ -562,7 +561,7 @@ cube_union(NDBOX * a, NDBOX * b)
result->x[i] =
Min(Min(a->x[i], a->x[i + a->dim]), result->x[i]);
result->x[i + a->dim] = Max(Max(a->x[i],
- a->x[i + a->dim]), result->x[i + a->dim]);
+ a->x[i + a->dim]), result->x[i + a->dim]);
}
return (result);
@@ -620,12 +619,11 @@ cube_inter(NDBOX * a, NDBOX * b)
result->x[i] =
Max(Min(a->x[i], a->x[i + a->dim]), result->x[i]);
result->x[i + a->dim] = Min(Max(a->x[i],
- a->x[i + a->dim]), result->x[i + a->dim]);
+ a->x[i + a->dim]), result->x[i + a->dim]);
}
/*
- * Is it OK to return a non-null intersection for non-overlapping
- * boxes?
+ * Is it OK to return a non-null intersection for non-overlapping boxes?
*/
return (result);
}
@@ -713,8 +711,8 @@ cube_cmp(NDBOX * a, NDBOX * b)
}
/*
- * if all common dimensions are equal, the cube with more
- * dimensions wins
+ * if all common dimensions are equal, the cube with more dimensions
+ * wins
*/
return 1;
}
@@ -736,8 +734,8 @@ cube_cmp(NDBOX * a, NDBOX * b)
}
/*
- * if all common dimensions are equal, the cube with more
- * dimensions wins
+ * if all common dimensions are equal, the cube with more dimensions
+ * wins
*/
return -1;
}
@@ -797,10 +795,9 @@ cube_contains(NDBOX * a, NDBOX * b)
if (a->dim < b->dim)
{
/*
- * the further comparisons will make sense if the excess
- * dimensions of (b) were zeroes Since both UL and UR coordinates
- * must be zero, we can check them all without worrying about
- * which is which.
+ * the further comparisons will make sense if the excess dimensions of
+ * (b) were zeroes Since both UL and UR coordinates must be zero, we
+ * can check them all without worrying about which is which.
*/
for (i = a->dim; i < b->dim; i++)
{
diff --git a/contrib/dbase/dbf.c b/contrib/dbase/dbf.c
index 6a13aac972..4c79a07d60 100644
--- a/contrib/dbase/dbf.c
+++ b/contrib/dbase/dbf.c
@@ -88,10 +88,10 @@ dbf_open(char *file, int flags)
dbh->db_nfields = (dbh->db_hlen - sizeof(dbf_header)) / sizeof(dbf_field);
/*
- * dbh->db_hlen - sizeof(dbf_header) isn't the correct size, cos
- * dbh->hlen is in fact a little more cos of the 0x0D (and possibly
- * another byte, 0x4E, I have seen this somewhere). Because of
- * rounding everything turns out right :)
+ * dbh->db_hlen - sizeof(dbf_header) isn't the correct size, cos dbh->hlen
+ * is in fact a little more cos of the 0x0D (and possibly another byte,
+ * 0x4E, I have seen this somewhere). Because of rounding everything turns
+ * out right :)
*/
if ((fields = (f_descr *) calloc(dbh->db_nfields, sizeof(f_descr)))
@@ -155,8 +155,7 @@ dbf_write_head(dbhead * dbh)
now = time((time_t *) NULL);
dbf_time = localtime(&now);
head.dbh_year = dbf_time->tm_year;
- head.dbh_month = dbf_time->tm_mon + 1; /* Months since January +
- * 1 */
+ head.dbh_month = dbf_time->tm_mon + 1; /* Months since January + 1 */
head.dbh_day = dbf_time->tm_mday;
put_long(head.dbh_records, dbh->db_records);
diff --git a/contrib/dbase/dbf.h b/contrib/dbase/dbf.h
index 9a5a2bee83..d9c88ed35b 100644
--- a/contrib/dbase/dbf.h
+++ b/contrib/dbase/dbf.h
@@ -9,7 +9,7 @@
#define _DBF_H
#ifdef _WIN32
-#include <gmon.h> /* we need it to define u_char type */
+#include <gmon.h> /* we need it to define u_char type */
#endif
#include <sys/types.h>
@@ -64,8 +64,7 @@ typedef struct
u_char dbf_type; /* field-type */
u_char dbf_reserved[4]; /* some reserved stuff */
u_char dbf_flen; /* field-length */
- u_char dbf_dec; /* number of decimal positions if type is
- * 'N' */
+ u_char dbf_dec; /* number of decimal positions if type is 'N' */
u_char dbf_stub[14]; /* stuff we don't need */
} dbf_field;
@@ -89,15 +88,14 @@ typedef struct
u_char db_year; /* last update as YYMMDD */
u_char db_month;
u_char db_day;
- u_long db_hlen; /* length of the diskheader, for
- * calculating the offsets */
+ u_long db_hlen; /* length of the diskheader, for calculating
+ * the offsets */
u_long db_records; /* number of records */
u_long db_currec; /* current record-number starting at 0 */
u_short db_rlen; /* length of the record */
u_char db_nfields; /* number of fields */
u_char *db_buff; /* record-buffer to save malloc()'s */
- f_descr *db_fields; /* pointer to an array of field-
- * descriptions */
+ f_descr *db_fields; /* pointer to an array of field- descriptions */
} dbhead;
/* structure that contains everything a user wants from a field, including
diff --git a/contrib/dbase/dbf2pg.c b/contrib/dbase/dbf2pg.c
index c3e50dc4ac..7d42798dbe 100644
--- a/contrib/dbase/dbf2pg.c
+++ b/contrib/dbase/dbf2pg.c
@@ -169,7 +169,7 @@ usage(void)
{
printf("dbf2pg\n"
"usage: dbf2pg [-u | -l] [-h hostname] [-W] [-U username]\n"
- " [-B transaction_size] [-F charset_from [-T charset_to]]\n"
+ " [-B transaction_size] [-F charset_from [-T charset_to]]\n"
" [-s oldname=[newname][,oldname=[newname][...]]] [-d dbase]\n"
" [-t table] [-c | -D] [-f] [-v[v]] dbf-file\n");
}
@@ -251,7 +251,7 @@ do_create(PGconn *conn, char *table, dbhead * dbh)
printf("Building CREATE-clause\n");
if (!(query = (char *) malloc(
- (dbh->db_nfields * 40) + 29 + strlen(table))))
+ (dbh->db_nfields * 40) + 29 + strlen(table))))
{
fprintf(stderr, "Memory allocation error in function do_create\n");
PQfinish(conn);
@@ -359,9 +359,8 @@ do_inserts(PGconn *conn, char *table, dbhead * dbh)
}
/*
- * make sure we can build the COPY query, note that we don't need to
- * just add this value, since the COPY query is a separate query (see
- * below)
+ * make sure we can build the COPY query, note that we don't need to just
+ * add this value, since the COPY query is a separate query (see below)
*/
if (h < 17 + strlen(table))
h = 17 + strlen(table);
@@ -370,7 +369,7 @@ do_inserts(PGconn *conn, char *table, dbhead * dbh)
{
PQfinish(conn);
fprintf(stderr,
- "Memory allocation error in function do_inserts (query)\n");
+ "Memory allocation error in function do_inserts (query)\n");
close(dbh->db_fd);
free(dbh);
exit(1);
@@ -386,12 +385,10 @@ do_inserts(PGconn *conn, char *table, dbhead * dbh)
exit(1);
}
- if (end == 0) /* "end" is a user option, if not
- * specified, */
+ if (end == 0) /* "end" is a user option, if not specified, */
end = dbh->db_records; /* then all records are processed. */
- if (t_block == 0) /* user not specified transaction block
- * size */
+ if (t_block == 0) /* user not specified transaction block size */
t_block = end - begin; /* then we set it to be the full data */
for (i = begin; i < end; i++)
@@ -426,9 +423,8 @@ do_inserts(PGconn *conn, char *table, dbhead * dbh)
j = 0; /* counter for fields in the output */
for (h = 0; h < dbh->db_nfields; h++)
{
- if (!strlen(fields[h].db_name)) /* When the new fieldname
- * is empty, the field is
- * skipped */
+ if (!strlen(fields[h].db_name)) /* When the new fieldname is
+ * empty, the field is skipped */
continue;
else
j++;
@@ -639,8 +635,8 @@ main(int argc, char **argv)
usage();
/*
- * FIXME: Ivan thinks this is bad: printf("unknown
- * argument: %s\n", argv[0]);
+ * FIXME: Ivan thinks this is bad: printf("unknown argument:
+ * %s\n", argv[0]);
*/
exit(1);
break;
diff --git a/contrib/dblink/dblink.c b/contrib/dblink/dblink.c
index c1d70ebf22..c11b15860a 100644
--- a/contrib/dblink/dblink.c
+++ b/contrib/dblink/dblink.c
@@ -60,10 +60,9 @@
typedef struct remoteConn
{
- PGconn *conn; /* Hold the remote connection */
- int autoXactCursors; /* Indicates the number of open cursors,
- * non-zero means we opened the xact
- * ourselves */
+ PGconn *conn; /* Hold the remote connection */
+ int autoXactCursors;/* Indicates the number of open cursors,
+ * non-zero means we opened the xact ourselves */
} remoteConn;
/*
@@ -71,7 +70,7 @@ typedef struct remoteConn
*/
static remoteConn *getConnectionByName(const char *name);
static HTAB *createConnHash(void);
-static void createNewConnection(const char *name, remoteConn *rconn);
+static void createNewConnection(const char *name, remoteConn * rconn);
static void deleteConnection(const char *name);
static char **get_pkey_attnames(Oid relid, int16 *numatts);
static char *get_sql_insert(Oid relid, int2vector *pkattnums, int16 pknumatts, char **src_pkattvals, char **tgt_pkattvals);
@@ -224,9 +223,9 @@ dblink_connect(PG_FUNCTION_ARGS)
pfree(rconn);
ereport(ERROR,
- (errcode(ERRCODE_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION),
- errmsg("could not establish connection"),
- errdetail("%s", msg)));
+ (errcode(ERRCODE_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION),
+ errmsg("could not establish connection"),
+ errdetail("%s", msg)));
}
if (connname)
@@ -514,8 +513,7 @@ dblink_fetch(PG_FUNCTION_ARGS)
funcctx = SRF_FIRSTCALL_INIT();
/*
- * switch to memory context appropriate for multiple function
- * calls
+ * switch to memory context appropriate for multiple function calls
*/
oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
@@ -664,8 +662,7 @@ dblink_record(PG_FUNCTION_ARGS)
funcctx = SRF_FIRSTCALL_INIT();
/*
- * switch to memory context appropriate for multiple function
- * calls
+ * switch to memory context appropriate for multiple function calls
*/
oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
@@ -730,8 +727,8 @@ dblink_record(PG_FUNCTION_ARGS)
TEXTOID, -1, 0);
/*
- * and save a copy of the command status string to return as
- * our result tuple
+ * and save a copy of the command status string to return as our
+ * result tuple
*/
sql_cmd_status = PQcmdStatus(res);
funcctx->max_calls = 1;
@@ -766,8 +763,8 @@ dblink_record(PG_FUNCTION_ARGS)
/* failed to determine actual type of RECORD */
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
- errmsg("function returning record called in context "
- "that cannot accept type record")));
+ errmsg("function returning record called in context "
+ "that cannot accept type record")));
break;
default:
/* result type isn't composite */
@@ -935,8 +932,8 @@ dblink_exec(PG_FUNCTION_ARGS)
{
PQclear(res);
ereport(ERROR,
- (errcode(ERRCODE_S_R_E_PROHIBITED_SQL_STATEMENT_ATTEMPTED),
- errmsg("statement returning results not allowed")));
+ (errcode(ERRCODE_S_R_E_PROHIBITED_SQL_STATEMENT_ATTEMPTED),
+ errmsg("statement returning results not allowed")));
}
/* if needed, close the connection to the database and cleanup */
@@ -975,8 +972,7 @@ dblink_get_pkey(PG_FUNCTION_ARGS)
funcctx = SRF_FIRSTCALL_INIT();
/*
- * switch to memory context appropriate for multiple function
- * calls
+ * switch to memory context appropriate for multiple function calls
*/
oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
@@ -989,8 +985,7 @@ dblink_get_pkey(PG_FUNCTION_ARGS)
GET_STR(PG_GETARG_TEXT_P(0)))));
/*
- * need a tuple descriptor representing one INT and one TEXT
- * column
+ * need a tuple descriptor representing one INT and one TEXT column
*/
tupdesc = CreateTemplateTupleDesc(2, false);
TupleDescInitEntry(tupdesc, (AttrNumber) 1, "position",
@@ -999,8 +994,8 @@ dblink_get_pkey(PG_FUNCTION_ARGS)
TEXTOID, -1, 0);
/*
- * Generate attribute metadata needed later to produce tuples from
- * raw C strings
+ * Generate attribute metadata needed later to produce tuples from raw
+ * C strings
*/
attinmeta = TupleDescGetAttInMetadata(tupdesc);
funcctx->attinmeta = attinmeta;
@@ -1145,8 +1140,8 @@ dblink_build_sql_insert(PG_FUNCTION_ARGS)
tgt_pkattvals_arry = PG_GETARG_ARRAYTYPE_P(4);
/*
- * Source array is made up of key values that will be used to locate
- * the tuple of interest from the local system.
+ * Source array is made up of key values that will be used to locate the
+ * tuple of interest from the local system.
*/
src_ndim = ARR_NDIM(src_pkattvals_arry);
src_dim = ARR_DIMS(src_pkattvals_arry);
@@ -1158,8 +1153,8 @@ dblink_build_sql_insert(PG_FUNCTION_ARGS)
if (src_nitems != pknumatts)
ereport(ERROR,
(errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
- errmsg("source key array length must match number of key " \
- "attributes")));
+ errmsg("source key array length must match number of key " \
+ "attributes")));
/*
* get array of pointers to c-strings from the input source array
@@ -1178,8 +1173,8 @@ dblink_build_sql_insert(PG_FUNCTION_ARGS)
}
/*
- * Target array is made up of key values that will be used to build
- * the SQL string for use on the remote system.
+ * Target array is made up of key values that will be used to build the
+ * SQL string for use on the remote system.
*/
tgt_ndim = ARR_NDIM(tgt_pkattvals_arry);
tgt_dim = ARR_DIMS(tgt_pkattvals_arry);
@@ -1191,8 +1186,8 @@ dblink_build_sql_insert(PG_FUNCTION_ARGS)
if (tgt_nitems != pknumatts)
ereport(ERROR,
(errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
- errmsg("target key array length must match number of key " \
- "attributes")));
+ errmsg("target key array length must match number of key " \
+ "attributes")));
/*
* get array of pointers to c-strings from the input target array
@@ -1291,8 +1286,8 @@ dblink_build_sql_delete(PG_FUNCTION_ARGS)
tgt_pkattvals_arry = PG_GETARG_ARRAYTYPE_P(3);
/*
- * Target array is made up of key values that will be used to build
- * the SQL string for use on the remote system.
+ * Target array is made up of key values that will be used to build the
+ * SQL string for use on the remote system.
*/
tgt_ndim = ARR_NDIM(tgt_pkattvals_arry);
tgt_dim = ARR_DIMS(tgt_pkattvals_arry);
@@ -1304,8 +1299,8 @@ dblink_build_sql_delete(PG_FUNCTION_ARGS)
if (tgt_nitems != pknumatts)
ereport(ERROR,
(errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
- errmsg("target key array length must match number of key " \
- "attributes")));
+ errmsg("target key array length must match number of key " \
+ "attributes")));
/*
* get array of pointers to c-strings from the input target array
@@ -1414,8 +1409,8 @@ dblink_build_sql_update(PG_FUNCTION_ARGS)
tgt_pkattvals_arry = PG_GETARG_ARRAYTYPE_P(4);
/*
- * Source array is made up of key values that will be used to locate
- * the tuple of interest from the local system.
+ * Source array is made up of key values that will be used to locate the
+ * tuple of interest from the local system.
*/
src_ndim = ARR_NDIM(src_pkattvals_arry);
src_dim = ARR_DIMS(src_pkattvals_arry);
@@ -1427,8 +1422,8 @@ dblink_build_sql_update(PG_FUNCTION_ARGS)
if (src_nitems != pknumatts)
ereport(ERROR,
(errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
- errmsg("source key array length must match number of key " \
- "attributes")));
+ errmsg("source key array length must match number of key " \
+ "attributes")));
/*
* get array of pointers to c-strings from the input source array
@@ -1447,8 +1442,8 @@ dblink_build_sql_update(PG_FUNCTION_ARGS)
}
/*
- * Target array is made up of key values that will be used to build
- * the SQL string for use on the remote system.
+ * Target array is made up of key values that will be used to build the
+ * SQL string for use on the remote system.
*/
tgt_ndim = ARR_NDIM(tgt_pkattvals_arry);
tgt_dim = ARR_DIMS(tgt_pkattvals_arry);
@@ -1460,8 +1455,8 @@ dblink_build_sql_update(PG_FUNCTION_ARGS)
if (tgt_nitems != pknumatts)
ereport(ERROR,
(errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
- errmsg("target key array length must match number of key " \
- "attributes")));
+ errmsg("target key array length must match number of key " \
+ "attributes")));
/*
* get array of pointers to c-strings from the input target array
@@ -1610,7 +1605,7 @@ get_sql_insert(Oid relid, int2vector *pkattnums, int16 pknumatts, char **src_pka
appendStringInfo(str, ",");
appendStringInfo(str, "%s",
- quote_ident_cstr(NameStr(tupdesc->attrs[i]->attname)));
+ quote_ident_cstr(NameStr(tupdesc->attrs[i]->attname)));
needComma = true;
}
@@ -1688,7 +1683,7 @@ get_sql_delete(Oid relid, int2vector *pkattnums, int16 pknumatts, char **tgt_pka
appendStringInfo(str, " AND ");
appendStringInfo(str, "%s",
- quote_ident_cstr(NameStr(tupdesc->attrs[pkattnum - 1]->attname)));
+ quote_ident_cstr(NameStr(tupdesc->attrs[pkattnum - 1]->attname)));
if (tgt_pkattvals != NULL)
val = pstrdup(tgt_pkattvals[i]);
@@ -1756,7 +1751,7 @@ get_sql_update(Oid relid, int2vector *pkattnums, int16 pknumatts, char **src_pka
appendStringInfo(str, ", ");
appendStringInfo(str, "%s = ",
- quote_ident_cstr(NameStr(tupdesc->attrs[i]->attname)));
+ quote_ident_cstr(NameStr(tupdesc->attrs[i]->attname)));
if (tgt_pkattvals != NULL)
key = get_attnum_pk_pos(pkattnums, pknumatts, i + 1);
@@ -1788,7 +1783,7 @@ get_sql_update(Oid relid, int2vector *pkattnums, int16 pknumatts, char **src_pka
appendStringInfo(str, " AND ");
appendStringInfo(str, "%s",
- quote_ident_cstr(NameStr(tupdesc->attrs[pkattnum - 1]->attname)));
+ quote_ident_cstr(NameStr(tupdesc->attrs[pkattnum - 1]->attname)));
if (tgt_pkattvals != NULL)
val = pstrdup(tgt_pkattvals[i]);
@@ -1894,8 +1889,8 @@ get_tuple_of_interest(Oid relid, int2vector *pkattnums, int16 pknumatts, char **
elog(ERROR, "SPI connect failure - returned %d", ret);
/*
- * Build sql statement to look up tuple of interest Use src_pkattvals
- * as the criteria.
+ * Build sql statement to look up tuple of interest Use src_pkattvals as
+ * the criteria.
*/
appendStringInfo(str, "SELECT * FROM %s WHERE ", relname);
@@ -1907,7 +1902,7 @@ get_tuple_of_interest(Oid relid, int2vector *pkattnums, int16 pknumatts, char **
appendStringInfo(str, " AND ");
appendStringInfo(str, "%s",
- quote_ident_cstr(NameStr(tupdesc->attrs[pkattnum - 1]->attname)));
+ quote_ident_cstr(NameStr(tupdesc->attrs[pkattnum - 1]->attname)));
val = pstrdup(src_pkattvals[i]);
if (val != NULL)
@@ -2045,7 +2040,7 @@ createConnHash(void)
}
static void
-createNewConnection(const char *name, remoteConn *rconn)
+createNewConnection(const char *name, remoteConn * rconn)
{
remoteConnHashEnt *hentry;
bool found;
diff --git a/contrib/dbmirror/pending.c b/contrib/dbmirror/pending.c
index 36f5837bbd..f0204f73aa 100644
--- a/contrib/dbmirror/pending.c
+++ b/contrib/dbmirror/pending.c
@@ -1,7 +1,7 @@
/****************************************************************************
* pending.c
- * $Id: pending.c,v 1.22 2005/10/02 23:50:05 tgl Exp $
- * $PostgreSQL: pgsql/contrib/dbmirror/pending.c,v 1.22 2005/10/02 23:50:05 tgl Exp $
+ * $Id: pending.c,v 1.23 2005/10/15 02:49:04 momjian Exp $
+ * $PostgreSQL: pgsql/contrib/dbmirror/pending.c,v 1.23 2005/10/15 02:49:04 momjian Exp $
*
* This file contains a trigger for Postgresql-7.x to record changes to tables
* to a pending table for mirroring.
@@ -115,7 +115,7 @@ recordchange(PG_FUNCTION_ARGS)
if (SPI_connect() < 0)
{
ereport(ERROR, (errcode(ERRCODE_CONNECTION_FAILURE),
- errmsg("dbmirror:recordchange could not connect to SPI")));
+ errmsg("dbmirror:recordchange could not connect to SPI")));
return -1;
}
trigdata = (TriggerData *) fcinfo->context;
@@ -155,7 +155,7 @@ recordchange(PG_FUNCTION_ARGS)
else
{
ereport(ERROR, (errcode(ERRCODE_TRIGGERED_ACTION_EXCEPTION),
- errmsg("dbmirror:recordchange Unknown operation")));
+ errmsg("dbmirror:recordchange Unknown operation")));
}
@@ -219,7 +219,7 @@ storePending(char *cpTableName, HeapTuple tBeforeTuple,
vpPlan = SPI_prepare(cpQueryBase, 3, taPlanArgTypes);
if (vpPlan == NULL)
ereport(ERROR, (errcode(ERRCODE_TRIGGERED_ACTION_EXCEPTION),
- errmsg("dbmirror:storePending error creating plan")));
+ errmsg("dbmirror:storePending error creating plan")));
saPlanData[0] = PointerGetDatum(cpTableName);
@@ -662,7 +662,7 @@ saveSequenceUpdate(Oid relid, int64 nextValue, bool iscalled)
if (SPI_connect() < 0)
ereport(ERROR,
(errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
- errmsg("dbmirror:savesequenceupdate could not connect to SPI")));
+ errmsg("dbmirror:savesequenceupdate could not connect to SPI")));
insertPlan = SPI_prepare(insertQuery, 2, insertArgTypes);
insertDataPlan = SPI_prepare(insertDataQuery, 1, insertDataArgTypes);
diff --git a/contrib/earthdistance/earthdistance.c b/contrib/earthdistance/earthdistance.c
index 28ce40378c..f91eeb5392 100644
--- a/contrib/earthdistance/earthdistance.c
+++ b/contrib/earthdistance/earthdistance.c
@@ -67,7 +67,7 @@ geo_distance(Point *pt1, Point *pt2)
longdiff = TWO_PI - longdiff;
sino = sqrt(sin(fabs(lat1 - lat2) / 2.) * sin(fabs(lat1 - lat2) / 2.) +
- cos(lat1) * cos(lat2) * sin(longdiff / 2.) * sin(longdiff / 2.));
+ cos(lat1) * cos(lat2) * sin(longdiff / 2.) * sin(longdiff / 2.));
if (sino > 1.)
sino = 1.;
*resultp = 2. * EARTH_RADIUS * asin(sino);
diff --git a/contrib/fulltextindex/fti.c b/contrib/fulltextindex/fti.c
index e5095ff1a1..a3ac6da586 100644
--- a/contrib/fulltextindex/fti.c
+++ b/contrib/fulltextindex/fti.c
@@ -339,8 +339,8 @@ fti(PG_FUNCTION_ARGS)
ret = SPI_execp(*(plan->splan), values, NULL, 0);
if (ret != SPI_OK_INSERT)
ereport(ERROR,
- (errcode(ERRCODE_TRIGGERED_ACTION_EXCEPTION),
- errmsg("error executing insert")));
+ (errcode(ERRCODE_TRIGGERED_ACTION_EXCEPTION),
+ errmsg("error executing insert")));
}
pfree(buff);
pfree(data);
@@ -367,9 +367,8 @@ breakup(char *string, char *substring)
while (cur_pos > string) /* don't read before start of 'string' */
{
/*
- * skip pieces at the end of a string that are not alfa-numeric
- * (ie. 'string$%^&', last_start first points to '&', and after
- * this to 'g'
+ * skip pieces at the end of a string that are not alfa-numeric (ie.
+ * 'string$%^&', last_start first points to '&', and after this to 'g'
*/
if (!isalnum((unsigned char) *last_start))
{
@@ -379,8 +378,7 @@ breakup(char *string, char *substring)
cur_pos = last_start;
}
- cur_pos--; /* substrings are at minimum 2 characters
- * long */
+ cur_pos--; /* substrings are at minimum 2 characters long */
if (isalnum((unsigned char) *cur_pos))
{
diff --git a/contrib/fuzzystrmatch/dmetaphone.c b/contrib/fuzzystrmatch/dmetaphone.c
index c8d9c8979b..216f39b7a7 100644
--- a/contrib/fuzzystrmatch/dmetaphone.c
+++ b/contrib/fuzzystrmatch/dmetaphone.c
@@ -48,8 +48,8 @@
/*
- * $Revision: 1.5 $
- * $Id: dmetaphone.c,v 1.5 2005/09/30 22:38:44 momjian Exp $
+ * $Revision: 1.6 $
+ * $Id: dmetaphone.c,v 1.6 2005/10/15 02:49:05 momjian Exp $
*/
@@ -154,10 +154,10 @@ dmetaphone(PG_FUNCTION_ARGS)
alen = VARSIZE(arg) - VARHDRSZ;
/*
- * Postgres' string values might not have trailing nuls. The VARSIZE
- * will not include the nul in any case so we copy things out and add
- * a trailing nul. When we copy back we ignore the nul (and we don't
- * make space for it).
+ * Postgres' string values might not have trailing nuls. The VARSIZE will
+ * not include the nul in any case so we copy things out and add a
+ * trailing nul. When we copy back we ignore the nul (and we don't make
+ * space for it).
*/
aptr = palloc(alen + 1);
@@ -236,7 +236,6 @@ dmetaphone_alt(PG_FUNCTION_ARGS)
*/
#define META_FREE(x) /* pfree((x)) */
-
#else /* not defined DMETAPHONE_MAIN */
/* use the standard malloc library when not running in PostgreSQL */
@@ -512,8 +511,8 @@ DoubleMetaphone(char *str, char **codes)
&& StringAt(original, (current - 1), 3, "ACH", "")
&& ((GetAt(original, current + 2) != 'I')
&& ((GetAt(original, current + 2) != 'E')
- || StringAt(original, (current - 2), 6, "BACHER",
- "MACHER", ""))))
+ || StringAt(original, (current - 2), 6, "BACHER",
+ "MACHER", ""))))
{
MetaphAdd(primary, "K");
MetaphAdd(secondary, "K");
@@ -582,9 +581,9 @@ DoubleMetaphone(char *str, char **codes)
/*
* e.g., 'wachtler', 'wechsler', but not 'tichner'
*/
- && StringAt(original, (current + 2), 1, "L", "R",
- "N", "M", "B", "H", "F", "V", "W",
- " ", "")))
+ && StringAt(original, (current + 2), 1, "L", "R",
+ "N", "M", "B", "H", "F", "V", "W",
+ " ", "")))
{
MetaphAdd(primary, "K");
MetaphAdd(secondary, "K");
@@ -639,14 +638,14 @@ DoubleMetaphone(char *str, char **codes)
{
/* 'bellocchio' but not 'bacchus' */
if (StringAt(original, (current + 2), 1, "I", "E", "H", "")
- && !StringAt(original, (current + 2), 2, "HU", ""))
+ && !StringAt(original, (current + 2), 2, "HU", ""))
{
/* 'accident', 'accede' 'succeed' */
if (
((current == 1)
&& (GetAt(original, current - 1) == 'A'))
- || StringAt(original, (current - 1), 5, "UCCEE",
- "UCCES", ""))
+ || StringAt(original, (current - 1), 5, "UCCEE",
+ "UCCES", ""))
{
MetaphAdd(primary, "KS");
MetaphAdd(secondary, "KS");
@@ -787,8 +786,8 @@ DoubleMetaphone(char *str, char **codes)
}
/*
- * Parker's rule (with some further refinements) -
- * e.g., 'hugh'
+ * Parker's rule (with some further refinements) - e.g.,
+ * 'hugh'
*/
if (
((current > 1)
@@ -873,9 +872,9 @@ DoubleMetaphone(char *str, char **codes)
/* -ges-,-gep-,-gel-, -gie- at beginning */
if ((current == 0)
&& ((GetAt(original, current + 1) == 'Y')
- || StringAt(original, (current + 1), 2, "ES", "EP",
- "EB", "EL", "EY", "IB", "IL", "IN", "IE",
- "EI", "ER", "")))
+ || StringAt(original, (current + 1), 2, "ES", "EP",
+ "EB", "EL", "EY", "IB", "IL", "IN", "IE",
+ "EI", "ER", "")))
{
MetaphAdd(primary, "K");
MetaphAdd(secondary, "J");
@@ -1002,7 +1001,7 @@ DoubleMetaphone(char *str, char **codes)
else
{
if (!StringAt(original, (current + 1), 1, "L", "T",
- "K", "S", "N", "M", "B", "Z", "")
+ "K", "S", "N", "M", "B", "Z", "")
&& !StringAt(original, (current - 1), 1,
"S", "K", "L", ""))
{
@@ -1035,10 +1034,10 @@ DoubleMetaphone(char *str, char **codes)
if (((current == (length - 3))
&& StringAt(original, (current - 1), 4, "ILLO",
"ILLA", "ALLE", ""))
- || ((StringAt(original, (last - 1), 2, "AS", "OS", "")
- || StringAt(original, last, 1, "A", "O", ""))
- && StringAt(original, (current - 1), 4,
- "ALLE", "")))
+ || ((StringAt(original, (last - 1), 2, "AS", "OS", "")
+ || StringAt(original, last, 1, "A", "O", ""))
+ && StringAt(original, (current - 1), 4,
+ "ALLE", "")))
{
MetaphAdd(primary, "L");
MetaphAdd(secondary, "");
@@ -1056,7 +1055,7 @@ DoubleMetaphone(char *str, char **codes)
case 'M':
if ((StringAt(original, (current - 1), 3, "UMB", "")
&& (((current + 1) == last)
- || StringAt(original, (current + 2), 2, "ER", "")))
+ || StringAt(original, (current + 2), 2, "ER", "")))
/* 'dumb','thumb' */
|| (GetAt(original, current + 1) == 'M'))
current += 2;
@@ -1113,7 +1112,7 @@ DoubleMetaphone(char *str, char **codes)
if ((current == last)
&& !SlavoGermanic(original)
&& StringAt(original, (current - 2), 2, "IE", "")
- && !StringAt(original, (current - 4), 2, "ME", "MA", ""))
+ && !StringAt(original, (current - 4), 2, "ME", "MA", ""))
{
MetaphAdd(primary, "");
MetaphAdd(secondary, "R");
@@ -1152,8 +1151,8 @@ DoubleMetaphone(char *str, char **codes)
{
/* germanic */
if (StringAt
- (original, (current + 1), 4, "HEIM", "HOEK", "HOLM",
- "HOLZ", ""))
+ (original, (current + 1), 4, "HEIM", "HOEK", "HOLM",
+ "HOLZ", ""))
{
MetaphAdd(primary, "S");
MetaphAdd(secondary, "S");
@@ -1187,8 +1186,8 @@ DoubleMetaphone(char *str, char **codes)
/*
* german & anglicisations, e.g. 'smith' match 'schmidt',
- * 'snider' match 'schneider' also, -sz- in slavic
- * language although in hungarian it is pronounced 's'
+ * 'snider' match 'schneider' also, -sz- in slavic language
+ * although in hungarian it is pronounced 's'
*/
if (((current == 0)
&& StringAt(original, (current + 1), 1,
@@ -1264,7 +1263,7 @@ DoubleMetaphone(char *str, char **codes)
/* french e.g. 'resnais', 'artois' */
if ((current == last)
- && StringAt(original, (current - 2), 2, "AI", "OI", ""))
+ && StringAt(original, (current - 2), 2, "AI", "OI", ""))
{
MetaphAdd(primary, "");
MetaphAdd(secondary, "S");
@@ -1365,8 +1364,8 @@ DoubleMetaphone(char *str, char **codes)
/* Arnow should match Arnoff */
if (((current == last) && IsVowel(original, current - 1))
- || StringAt(original, (current - 1), 5, "EWSKI", "EWSKY",
- "OWSKI", "OWSKY", "")
+ || StringAt(original, (current - 1), 5, "EWSKI", "EWSKY",
+ "OWSKI", "OWSKY", "")
|| StringAt(original, 0, 3, "SCH", ""))
{
MetaphAdd(primary, "");
@@ -1442,8 +1441,8 @@ DoubleMetaphone(char *str, char **codes)
}
/*
- * printf("PRIMARY: %s\n", primary->str); printf("SECONDARY:
- * %s\n", secondary->str);
+ * printf("PRIMARY: %s\n", primary->str); printf("SECONDARY: %s\n",
+ * secondary->str);
*/
}
diff --git a/contrib/fuzzystrmatch/fuzzystrmatch.c b/contrib/fuzzystrmatch/fuzzystrmatch.c
index 8ffc02ffa3..e76e5038c2 100644
--- a/contrib/fuzzystrmatch/fuzzystrmatch.c
+++ b/contrib/fuzzystrmatch/fuzzystrmatch.c
@@ -65,10 +65,10 @@ levenshtein(PG_FUNCTION_ARGS)
int j;
/*
- * Fetch the arguments. str_s is referred to as the "source" cols =
- * length of source + 1 to allow for the initialization column str_t
- * is referred to as the "target", rows = length of target + 1 rows =
- * length of target + 1 to allow for the initialization row
+ * Fetch the arguments. str_s is referred to as the "source" cols = length
+ * of source + 1 to allow for the initialization column str_t is referred
+ * to as the "target", rows = length of target + 1 rows = length of target
+ * + 1 to allow for the initialization row
*/
str_s = DatumGetCString(DirectFunctionCall1(textout, PointerGetDatum(PG_GETARG_TEXT_P(0))));
str_t = DatumGetCString(DirectFunctionCall1(textout, PointerGetDatum(PG_GETARG_TEXT_P(1))));
@@ -78,10 +78,9 @@ levenshtein(PG_FUNCTION_ARGS)
/*
* Restrict the length of the strings being compared to something
- * reasonable because we will have to perform rows * cols
- * calculations. If longer strings need to be compared, increase
- * MAX_LEVENSHTEIN_STRLEN to suit (but within your tolerance for speed
- * and memory usage).
+ * reasonable because we will have to perform rows * cols calculations. If
+ * longer strings need to be compared, increase MAX_LEVENSHTEIN_STRLEN to
+ * suit (but within your tolerance for speed and memory usage).
*/
if ((cols > MAX_LEVENSHTEIN_STRLEN + 1) || (rows > MAX_LEVENSHTEIN_STRLEN + 1))
ereport(ERROR,
@@ -90,9 +89,9 @@ levenshtein(PG_FUNCTION_ARGS)
MAX_LEVENSHTEIN_STRLEN)));
/*
- * If either rows or cols is 0, the answer is the other value. This
- * makes sense since it would take that many insertions the build a
- * matching string
+ * If either rows or cols is 0, the answer is the other value. This makes
+ * sense since it would take that many insertions the build a matching
+ * string
*/
if (cols == 0)
@@ -102,9 +101,8 @@ levenshtein(PG_FUNCTION_ARGS)
PG_RETURN_INT32(cols);
/*
- * Allocate two vectors of integers. One will be used for the "upper"
- * row, the other for the "lower" row. Initialize the "upper" row to
- * 0..cols
+ * Allocate two vectors of integers. One will be used for the "upper" row,
+ * the other for the "lower" row. Initialize the "upper" row to 0..cols
*/
u_cells = palloc(sizeof(int) * cols);
for (i = 0; i < cols; i++)
@@ -119,14 +117,13 @@ levenshtein(PG_FUNCTION_ARGS)
str_s0 = str_s;
/*
- * Loop through the rows, starting at row 1. Row 0 is used for the
- * initial "upper" row.
+ * Loop through the rows, starting at row 1. Row 0 is used for the initial
+ * "upper" row.
*/
for (j = 1; j < rows; j++)
{
/*
- * We'll always start with col 1, and initialize lower row col 0
- * to j
+ * We'll always start with col 1, and initialize lower row col 0 to j
*/
l_cells[0] = j;
@@ -140,8 +137,7 @@ levenshtein(PG_FUNCTION_ARGS)
/*
* The "cost" value is 0 if the character at the current col
* position in the source string, matches the character at the
- * current row position in the target string; cost is 1
- * otherwise.
+ * current row position in the target string; cost is 1 otherwise.
*/
c = ((CHAREQ(str_s, str_t)) ? 0 : 1);
@@ -172,8 +168,8 @@ levenshtein(PG_FUNCTION_ARGS)
}
/*
- * Lower row now becomes the upper row, and the upper row gets
- * reused as the new lower row.
+ * Lower row now becomes the upper row, and the upper row gets reused
+ * as the new lower row.
*/
tmp = u_cells;
u_cells = l_cells;
@@ -301,8 +297,8 @@ Lookahead(char *word, int how_far)
for (idx = 0; word[idx] != '\0' && idx < how_far; idx++);
/* Edge forward in the string... */
- letter_ahead = word[idx]; /* idx will be either == to how_far or at
- * the end of the string */
+ letter_ahead = word[idx]; /* idx will be either == to how_far or at the
+ * end of the string */
return letter_ahead;
}
@@ -453,11 +449,11 @@ _metaphone(
/*
- * THOUGHT: It would be nice if, rather than having things
- * like... well, SCI. For SCI you encode the S, then have to
- * remember to skip the C. So the phonome SCI invades both S and
- * C. It would be better, IMHO, to skip the C from the S part of
- * the encoding. Hell, I'm trying it.
+ * THOUGHT: It would be nice if, rather than having things like...
+ * well, SCI. For SCI you encode the S, then have to remember to skip
+ * the C. So the phonome SCI invades both S and C. It would be
+ * better, IMHO, to skip the C from the S part of the encoding. Hell,
+ * I'm trying it.
*/
/* Ignore non-alphas */
@@ -478,9 +474,9 @@ _metaphone(
break;
/*
- * 'sh' if -CIA- or -CH, but not SCH, except SCHW. (SCHW
- * is handled in S) S if -CI-, -CE- or -CY- dropped if
- * -SCI-, SCE-, -SCY- (handed in S) else K
+ * 'sh' if -CIA- or -CH, but not SCH, except SCHW. (SCHW is
+ * handled in S) S if -CI-, -CE- or -CY- dropped if -SCI-,
+ * SCE-, -SCY- (handed in S) else K
*/
case 'C':
if (MAKESOFT(Next_Letter))
@@ -534,8 +530,8 @@ _metaphone(
/*
* F if in -GH and not B--GH, D--GH, -H--GH, -H---GH else
* dropped if -GNED, -GN, else dropped if -DGE-, -DGI- or
- * -DGY- (handled in D) else J if in -GE-, -GI, -GY and
- * not GG else K
+ * -DGY- (handled in D) else J if in -GE-, -GI, -GY and not GG
+ * else K
*/
case 'G':
if (Next_Letter == 'H')
@@ -761,14 +757,17 @@ PG_FUNCTION_INFO_V1(difference);
Datum
difference(PG_FUNCTION_ARGS)
{
- char sndx1[SOUNDEX_LEN+1], sndx2[SOUNDEX_LEN+1];
- int i, result;
+ char sndx1[SOUNDEX_LEN + 1],
+ sndx2[SOUNDEX_LEN + 1];
+ int i,
+ result;
_soundex(_textout(PG_GETARG_TEXT_P(0)), sndx1);
_soundex(_textout(PG_GETARG_TEXT_P(1)), sndx2);
result = 0;
- for (i=0; i<SOUNDEX_LEN; i++) {
+ for (i = 0; i < SOUNDEX_LEN; i++)
+ {
if (sndx1[i] == sndx2[i])
result++;
}
diff --git a/contrib/intagg/int_aggregate.c b/contrib/intagg/int_aggregate.c
index f4391b4699..3c7bb7ff87 100644
--- a/contrib/intagg/int_aggregate.c
+++ b/contrib/intagg/int_aggregate.c
@@ -59,8 +59,8 @@ typedef struct callContext
#define START_NUM 8 /* initial size of arrays */
#define PGARRAY_SIZE(n) (sizeof(PGARRAY) + (((n)-1)*sizeof(int4)))
-static PGARRAY *GetPGArray(PGARRAY *p, AggState *aggstate, bool fAdd);
-static PGARRAY *ShrinkPGArray(PGARRAY *p);
+static PGARRAY *GetPGArray(PGARRAY * p, AggState *aggstate, bool fAdd);
+static PGARRAY *ShrinkPGArray(PGARRAY * p);
Datum int_agg_state(PG_FUNCTION_ARGS);
Datum int_agg_final_array(PG_FUNCTION_ARGS);
@@ -77,7 +77,7 @@ PG_FUNCTION_INFO_V1(int_enum);
* ie the Agg node's aggcontext.
*/
static PGARRAY *
-GetPGArray(PGARRAY *p, AggState *aggstate, bool fAdd)
+GetPGArray(PGARRAY * p, AggState *aggstate, bool fAdd)
{
if (!p)
{
@@ -97,7 +97,7 @@ GetPGArray(PGARRAY *p, AggState *aggstate, bool fAdd)
/* Ensure array has space for another item */
if (p->items >= p->lower)
{
- PGARRAY *pn;
+ PGARRAY *pn;
int n = p->lower * 2;
int cbNew = PGARRAY_SIZE(n);
@@ -117,9 +117,10 @@ GetPGArray(PGARRAY *p, AggState *aggstate, bool fAdd)
* memory allocation context
*/
static PGARRAY *
-ShrinkPGArray(PGARRAY *p)
+ShrinkPGArray(PGARRAY * p)
{
PGARRAY *pnew;
+
/* get target size */
int cb = PGARRAY_SIZE(p->items);
@@ -158,11 +159,11 @@ int_agg_state(PG_FUNCTION_ARGS)
if (!PG_ARGISNULL(1))
{
- int4 value = PG_GETARG_INT32(1);
+ int4 value = PG_GETARG_INT32(1);
- if (!p) /* internal error */
+ if (!p) /* internal error */
elog(ERROR, "no aggregate storage");
- else if (p->items >= p->lower) /* internal error */
+ else if (p->items >= p->lower) /* internal error */
elog(ERROR, "aggregate storage too small");
else
p->array[p->items++] = value;
@@ -212,7 +213,7 @@ int_enum(PG_FUNCTION_ARGS)
if (!rsi || !IsA(rsi, ReturnSetInfo))
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
- errmsg("int_enum called in context that cannot accept a set")));
+ errmsg("int_enum called in context that cannot accept a set")));
if (!p)
{
@@ -223,7 +224,7 @@ int_enum(PG_FUNCTION_ARGS)
if (!fcinfo->flinfo->fn_extra)
{
/* Allocate working state */
- MemoryContext oldcontext;
+ MemoryContext oldcontext;
oldcontext = MemoryContextSwitchTo(fcinfo->flinfo->fn_mcxt);
@@ -250,7 +251,8 @@ int_enum(PG_FUNCTION_ARGS)
fcinfo->flinfo->fn_extra = (void *) pc;
MemoryContextSwitchTo(oldcontext);
}
- else /* use existing working state */
+ else
+ /* use existing working state */
pc = (CTX *) fcinfo->flinfo->fn_extra;
/* Are we done yet? */
diff --git a/contrib/intarray/_int_gist.c b/contrib/intarray/_int_gist.c
index 2d5e82a459..4f777bc40b 100644
--- a/contrib/intarray/_int_gist.c
+++ b/contrib/intarray/_int_gist.c
@@ -38,8 +38,8 @@ g_int_consistent(PG_FUNCTION_ARGS)
if (strategy == BooleanSearchStrategy)
PG_RETURN_BOOL(execconsistent((QUERYTYPE *) query,
- (ArrayType *) DatumGetPointer(entry->key),
- ISLEAFKEY((ArrayType *) DatumGetPointer(entry->key))));
+ (ArrayType *) DatumGetPointer(entry->key),
+ ISLEAFKEY((ArrayType *) DatumGetPointer(entry->key))));
/* XXX are we sure it's safe to scribble on the query object here? */
/* XXX what about toasted input? */
@@ -73,7 +73,7 @@ g_int_consistent(PG_FUNCTION_ARGS)
case RTContainedByStrategyNumber:
if (GIST_LEAF(entry))
retval = inner_int_contains(query,
- (ArrayType *) DatumGetPointer(entry->key));
+ (ArrayType *) DatumGetPointer(entry->key));
else
retval = inner_int_overlap((ArrayType *) DatumGetPointer(entry->key),
query);
@@ -134,7 +134,7 @@ g_int_compress(PG_FUNCTION_ARGS)
r->flags |= LEAFKEY;
retval = palloc(sizeof(GISTENTRY));
gistentryinit(*retval, PointerGetDatum(r),
- entry->rel, entry->page, entry->offset, VARSIZE(r), FALSE);
+ entry->rel, entry->page, entry->offset, VARSIZE(r), FALSE);
PG_RETURN_POINTER(retval);
}
@@ -175,7 +175,7 @@ g_int_compress(PG_FUNCTION_ARGS)
r = resize_intArrayType(r, len);
retval = palloc(sizeof(GISTENTRY));
gistentryinit(*retval, PointerGetDatum(r),
- entry->rel, entry->page, entry->offset, VARSIZE(r), FALSE);
+ entry->rel, entry->page, entry->offset, VARSIZE(r), FALSE);
PG_RETURN_POINTER(retval);
}
else
@@ -211,7 +211,7 @@ g_int_decompress(PG_FUNCTION_ARGS)
{
retval = palloc(sizeof(GISTENTRY));
gistentryinit(*retval, PointerGetDatum(in),
- entry->rel, entry->page, entry->offset, VARSIZE(in), FALSE);
+ entry->rel, entry->page, entry->offset, VARSIZE(in), FALSE);
PG_RETURN_POINTER(retval);
}
@@ -233,7 +233,7 @@ g_int_decompress(PG_FUNCTION_ARGS)
pfree(in);
retval = palloc(sizeof(GISTENTRY));
gistentryinit(*retval, PointerGetDatum(r),
- entry->rel, entry->page, entry->offset, VARSIZE(r), FALSE);
+ entry->rel, entry->page, entry->offset, VARSIZE(r), FALSE);
PG_RETURN_POINTER(retval);
}
@@ -378,8 +378,7 @@ g_int_picksplit(PG_FUNCTION_ARGS)
pfree(inter_d);
/*
- * are these a more promising split that what we've already
- * seen?
+ * are these a more promising split that what we've already seen?
*/
if (size_waste > waste || firsttime)
@@ -430,15 +429,15 @@ g_int_picksplit(PG_FUNCTION_ARGS)
qsort((void *) costvector, maxoff, sizeof(SPLITCOST), comparecost);
/*
- * Now split up the regions between the two seeds. An important
- * property of this split algorithm is that the split vector v has the
- * indices of items to be split in order in its left and right
- * vectors. We exploit this property by doing a merge in the code
- * that actually splits the page.
+ * Now split up the regions between the two seeds. An important property
+ * of this split algorithm is that the split vector v has the indices of
+ * items to be split in order in its left and right vectors. We exploit
+ * this property by doing a merge in the code that actually splits the
+ * page.
*
- * For efficiency, we also place the new index tuple in this loop. This
- * is handled at the very end, when we have placed all the existing
- * tuples and i == maxoff + 1.
+ * For efficiency, we also place the new index tuple in this loop. This is
+ * handled at the very end, when we have placed all the existing tuples
+ * and i == maxoff + 1.
*/
@@ -447,9 +446,9 @@ g_int_picksplit(PG_FUNCTION_ARGS)
i = costvector[j].pos;
/*
- * If we've already decided where to place this item, just put it
- * on the right list. Otherwise, we need to figure out which page
- * needs the least enlargement in order to store the item.
+ * If we've already decided where to place this item, just put it on
+ * the right list. Otherwise, we need to figure out which page needs
+ * the least enlargement in order to store the item.
*/
if (i == seed_1)
diff --git a/contrib/intarray/_int_op.c b/contrib/intarray/_int_op.c
index 9f30bb2173..70951bfd47 100644
--- a/contrib/intarray/_int_op.c
+++ b/contrib/intarray/_int_op.c
@@ -24,8 +24,8 @@ _int_contained(PG_FUNCTION_ARGS)
PG_RETURN_BOOL(DatumGetBool(
DirectFunctionCall2(
_int_contains,
- PointerGetDatum(PG_GETARG_POINTER(1)),
- PointerGetDatum(PG_GETARG_POINTER(0))
+ PointerGetDatum(PG_GETARG_POINTER(1)),
+ PointerGetDatum(PG_GETARG_POINTER(0))
)
));
}
@@ -54,8 +54,8 @@ _int_different(PG_FUNCTION_ARGS)
PG_RETURN_BOOL(!DatumGetBool(
DirectFunctionCall2(
_int_same,
- PointerGetDatum(PG_GETARG_POINTER(0)),
- PointerGetDatum(PG_GETARG_POINTER(1))
+ PointerGetDatum(PG_GETARG_POINTER(0)),
+ PointerGetDatum(PG_GETARG_POINTER(1))
)
));
}
diff --git a/contrib/intarray/_intbig_gist.c b/contrib/intarray/_intbig_gist.c
index 07a051dd50..237281aec5 100644
--- a/contrib/intarray/_intbig_gist.c
+++ b/contrib/intarray/_intbig_gist.c
@@ -487,7 +487,7 @@ g_intbig_consistent(PG_FUNCTION_ARGS)
if (strategy == BooleanSearchStrategy)
{
PG_RETURN_BOOL(signconsistent((QUERYTYPE *) query,
- GETSIGN(DatumGetPointer(entry->key)),
+ GETSIGN(DatumGetPointer(entry->key)),
false));
}
diff --git a/contrib/ltree/_ltree_op.c b/contrib/ltree/_ltree_op.c
index 3890769ce1..729d19c082 100644
--- a/contrib/ltree/_ltree_op.c
+++ b/contrib/ltree/_ltree_op.c
@@ -53,7 +53,7 @@ array_iterator(ArrayType *la, PGCALL2 callback, void *param, ltree ** found)
while (num > 0)
{
if (DatumGetBool(DirectFunctionCall2(callback,
- PointerGetDatum(item), PointerGetDatum(param))))
+ PointerGetDatum(item), PointerGetDatum(param))))
{
if (found)
diff --git a/contrib/ltree/lquery_op.c b/contrib/ltree/lquery_op.c
index 81a1b788aa..54466a5b6b 100644
--- a/contrib/ltree/lquery_op.c
+++ b/contrib/ltree/lquery_op.c
@@ -101,7 +101,7 @@ checkLevel(lquery_level * curq, ltree_level * curt)
else if (
(
curvar->len == curt->len ||
- (curt->len > curvar->len && (curvar->flag & LVAR_ANYEND))
+ (curt->len > curvar->len && (curvar->flag & LVAR_ANYEND))
) &&
(*cmpptr) (curvar->name, curt->name, curvar->len) == 0)
{
@@ -332,7 +332,7 @@ lt_q_regex(PG_FUNCTION_ARGS)
while (num > 0)
{
if (DatumGetBool(DirectFunctionCall2(ltq_regex,
- PointerGetDatum(tree), PointerGetDatum(query))))
+ PointerGetDatum(tree), PointerGetDatum(query))))
{
res = true;
diff --git a/contrib/ltree/ltree.h b/contrib/ltree/ltree.h
index 2057751cfe..0400db8b77 100644
--- a/contrib/ltree/ltree.h
+++ b/contrib/ltree/ltree.h
@@ -157,7 +157,7 @@ bool ltree_execute(ITEM * curitem, void *checkval,
int ltree_compare(const ltree * a, const ltree * b);
bool inner_isparent(const ltree * c, const ltree * p);
bool compare_subnode(ltree_level * t, char *q, int len,
- int (*cmpptr) (const char *, const char *, size_t), bool anyend);
+ int (*cmpptr) (const char *, const char *, size_t), bool anyend);
ltree *lca_inner(ltree ** a, int len);
#define PG_GETARG_LTREE(x) ((ltree*)DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(x))))
diff --git a/contrib/ltree/ltree_gist.c b/contrib/ltree/ltree_gist.c
index 693244d9da..7e7ede0285 100644
--- a/contrib/ltree/ltree_gist.c
+++ b/contrib/ltree/ltree_gist.c
@@ -647,9 +647,9 @@ ltree_consistent(PG_FUNCTION_ARGS)
res = (ltree_compare((ltree *) query, LTG_NODE(key)) == 0);
else
res = (
- ltree_compare((ltree *) query, LTG_GETLNODE(key)) >= 0
+ ltree_compare((ltree *) query, LTG_GETLNODE(key)) >= 0
&&
- ltree_compare((ltree *) query, LTG_GETRNODE(key)) <= 0
+ ltree_compare((ltree *) query, LTG_GETRNODE(key)) <= 0
);
break;
case BTGreaterEqualStrategyNumber:
@@ -677,8 +677,8 @@ ltree_consistent(PG_FUNCTION_ARGS)
case 13:
if (GIST_LEAF(entry))
res = DatumGetBool(DirectFunctionCall2(ltq_regex,
- PointerGetDatum(LTG_NODE(key)),
- PointerGetDatum((lquery *) query)
+ PointerGetDatum(LTG_NODE(key)),
+ PointerGetDatum((lquery *) query)
));
else
res = (gist_qe(key, (lquery *) query) && gist_between(key, (lquery *) query));
@@ -687,8 +687,8 @@ ltree_consistent(PG_FUNCTION_ARGS)
case 15:
if (GIST_LEAF(entry))
res = DatumGetBool(DirectFunctionCall2(ltxtq_exec,
- PointerGetDatum(LTG_NODE(key)),
- PointerGetDatum((lquery *) query)
+ PointerGetDatum(LTG_NODE(key)),
+ PointerGetDatum((lquery *) query)
));
else
res = gist_qtxt(key, (ltxtquery *) query);
@@ -697,8 +697,8 @@ ltree_consistent(PG_FUNCTION_ARGS)
case 17:
if (GIST_LEAF(entry))
res = DatumGetBool(DirectFunctionCall2(lt_q_regex,
- PointerGetDatum(LTG_NODE(key)),
- PointerGetDatum((ArrayType *) query)
+ PointerGetDatum(LTG_NODE(key)),
+ PointerGetDatum((ArrayType *) query)
));
else
res = arrq_cons(key, (ArrayType *) query);
diff --git a/contrib/ltree/ltree_io.c b/contrib/ltree/ltree_io.c
index d0a8c20903..ccc6fc8ff7 100644
--- a/contrib/ltree/ltree_io.c
+++ b/contrib/ltree/ltree_io.c
@@ -82,7 +82,7 @@ ltree_in(PG_FUNCTION_ARGS)
errmsg("name of level is too long"),
errdetail("name length is %d, must " \
"be < 256, in position %d",
- lptr->len, (int) (lptr->start - buf))));
+ lptr->len, (int) (lptr->start - buf))));
totallen += MAXALIGN(lptr->len + LEVEL_HDRSIZE);
lptr++;
@@ -284,7 +284,7 @@ lquery_in(PG_FUNCTION_ARGS)
errmsg("name of level is too long"),
errdetail("name length is %d, must " \
"be < 256, in position %d",
- lptr->len, (int) (lptr->start - buf))));
+ lptr->len, (int) (lptr->start - buf))));
state = LQPRS_WAITVAR;
}
@@ -300,7 +300,7 @@ lquery_in(PG_FUNCTION_ARGS)
errmsg("name of level is too long"),
errdetail("name length is %d, must " \
"be < 256, in position %d",
- lptr->len, (int) (lptr->start - buf))));
+ lptr->len, (int) (lptr->start - buf))));
state = LQPRS_WAITLEVEL;
curqlevel = NEXTLEV(curqlevel);
diff --git a/contrib/mSQL-interface/mpgsql.c b/contrib/mSQL-interface/mpgsql.c
index cd3daba337..1f43f61ea1 100644
--- a/contrib/mSQL-interface/mpgsql.c
+++ b/contrib/mSQL-interface/mpgsql.c
@@ -264,7 +264,7 @@ msqlListTables(int a)
char tbuf[BUFSIZ];
snprintf(tbuf, BUFSIZ,
- "select relname from pg_class where relkind='r' and relowner=%d",
+ "select relname from pg_class where relkind='r' and relowner=%d",
geteuid());
if (msqlQuery(a, tbuf) > 0)
{
@@ -288,7 +288,7 @@ msqlListIndex(int a, char *b, char *c)
char tbuf[BUFSIZ];
snprintf(tbuf, BUFSIZ,
- "select relname from pg_class where relkind='i' and relowner=%d",
+ "select relname from pg_class where relkind='i' and relowner=%d",
geteuid());
if (msqlQuery(a, tbuf) > 0)
{
diff --git a/contrib/oid2name/oid2name.c b/contrib/oid2name/oid2name.c
index 9bea98b507..069c1708d6 100644
--- a/contrib/oid2name/oid2name.c
+++ b/contrib/oid2name/oid2name.c
@@ -17,10 +17,10 @@
/* an extensible array to keep track of elements to show */
typedef struct
{
- char **array;
- int num;
- int alloc;
-} eary;
+ char **array;
+ int num;
+ int alloc;
+} eary;
/* these are the opts structures for command line params */
struct options
@@ -36,19 +36,19 @@ struct options
bool extended;
bool tablespaces;
- char *dbname;
- char *hostname;
- char *port;
- char *username;
- char *password;
+ char *dbname;
+ char *hostname;
+ char *port;
+ char *username;
+ char *password;
};
/* function prototypes */
void get_opts(int, char **, struct options *);
void *myalloc(size_t size);
char *mystrdup(const char *str);
-void add_one_elt(char *eltname, eary *eary);
-char *get_comma_elts(eary *eary);
+void add_one_elt(char *eltname, eary * eary);
+char *get_comma_elts(eary * eary);
PGconn *sql_conn(struct options *);
int sql_exec(PGconn *, const char *sql, bool quiet);
void sql_exec_dumpalldbs(PGconn *, struct options *);
@@ -95,7 +95,7 @@ get_opts(int argc, char **argv, struct options * my_opts)
add_one_elt(optarg, my_opts->oids);
break;
- /* specify one filenode to show*/
+ /* specify one filenode to show */
case 'f':
add_one_elt(optarg, my_opts->filenodes);
break;
@@ -149,23 +149,23 @@ get_opts(int argc, char **argv, struct options * my_opts)
case '?':
case 'h':
fprintf(stderr,
-"Usage: oid2name [-s|-d database] [-S][-i][-q][-x] [-t table|-o oid|-f file] ...\n"
-" default action show all database Oids\n"
-" -d database database to connect to\n"
-" -s show all tablespaces\n"
-" -S show system objects too\n"
-" -i show indexes and sequences too\n"
-" -x extended (show additional columns)\n"
-" -q quiet (don't show headers)\n"
-" -t <table> show info for table named <table>\n"
-" -o <oid> show info for table with Oid <oid>\n"
-" -f <filenode> show info for table with filenode <filenode>\n"
-" -H host connect to remote host\n"
-" -p port host port to connect to\n"
-" -U username username to connect with\n"
-" -P password password for username\n"
-" (see also $PGPASSWORD and ~/.pgpass)\n"
-);
+ "Usage: oid2name [-s|-d database] [-S][-i][-q][-x] [-t table|-o oid|-f file] ...\n"
+ " default action show all database Oids\n"
+ " -d database database to connect to\n"
+ " -s show all tablespaces\n"
+ " -S show system objects too\n"
+ " -i show indexes and sequences too\n"
+ " -x extended (show additional columns)\n"
+ " -q quiet (don't show headers)\n"
+ " -t <table> show info for table named <table>\n"
+ " -o <oid> show info for table with Oid <oid>\n"
+ " -f <filenode> show info for table with filenode <filenode>\n"
+ " -H host connect to remote host\n"
+ " -p port host port to connect to\n"
+ " -U username username to connect with\n"
+ " -P password password for username\n"
+ " (see also $PGPASSWORD and ~/.pgpass)\n"
+ );
exit(1);
break;
}
@@ -175,7 +175,8 @@ get_opts(int argc, char **argv, struct options * my_opts)
void *
myalloc(size_t size)
{
- void *ptr = malloc(size);
+ void *ptr = malloc(size);
+
if (!ptr)
{
fprintf(stderr, "out of memory");
@@ -187,7 +188,8 @@ myalloc(size_t size)
char *
mystrdup(const char *str)
{
- char *result = strdup(str);
+ char *result = strdup(str);
+
if (!result)
{
fprintf(stderr, "out of memory");
@@ -202,7 +204,7 @@ mystrdup(const char *str)
* Add one element to a (possibly empty) eary struct.
*/
void
-add_one_elt(char *eltname, eary *eary)
+add_one_elt(char *eltname, eary * eary)
{
if (eary->alloc == 0)
{
@@ -233,11 +235,12 @@ add_one_elt(char *eltname, eary *eary)
* SQL statement.
*/
char *
-get_comma_elts(eary *eary)
+get_comma_elts(eary * eary)
{
- char *ret,
- *ptr;
- int i, length = 0;
+ char *ret,
+ *ptr;
+ int i,
+ length = 0;
if (eary->num == 0)
return mystrdup("");
@@ -272,9 +275,9 @@ sql_conn(struct options * my_opts)
/* login */
conn = PQsetdbLogin(my_opts->hostname,
- my_opts->port,
- NULL, /* options */
- NULL, /* tty */
+ my_opts->port,
+ NULL, /* options */
+ NULL, /* tty */
my_opts->dbname,
my_opts->username,
my_opts->password);
@@ -303,7 +306,9 @@ sql_exec(PGconn *conn, const char *todo, bool quiet)
int nfields;
int nrows;
- int i, j, l;
+ int i,
+ j,
+ l;
int *length;
char *pad;
@@ -334,7 +339,7 @@ sql_exec(PGconn *conn, const char *todo, bool quiet)
{
for (j = 0; j < nfields; j++)
{
- l = strlen(PQgetvalue(res, i, j));
+ l = strlen(PQgetvalue(res, i, j));
if (l > length[j])
length[j] = strlen(PQgetvalue(res, i, j));
}
@@ -372,36 +377,36 @@ sql_exec(PGconn *conn, const char *todo, bool quiet)
}
/*
- * Dump all databases. There are no system objects to worry about.
+ * Dump all databases. There are no system objects to worry about.
*/
void
-sql_exec_dumpalldbs(PGconn *conn, struct options *opts)
+sql_exec_dumpalldbs(PGconn *conn, struct options * opts)
{
char todo[1024];
/* get the oid and database name from the system pg_database table */
snprintf(todo, sizeof(todo),
"SELECT d.oid AS \"Oid\", datname AS \"Database Name\", "
- "spcname AS \"Tablespace\" FROM pg_database d JOIN pg_tablespace t ON "
+ "spcname AS \"Tablespace\" FROM pg_database d JOIN pg_tablespace t ON "
"(dattablespace = t.oid) ORDER BY 2");
sql_exec(conn, todo, opts->quiet);
}
-/*
+/*
* Dump all tables, indexes and sequences in the current database.
*/
void
-sql_exec_dumpalltables(PGconn *conn, struct options *opts)
+sql_exec_dumpalltables(PGconn *conn, struct options * opts)
{
char todo[1024];
char *addfields = ",c.oid AS \"Oid\", nspname AS \"Schema\", spcname as \"Tablespace\" ";
snprintf(todo, sizeof(todo),
- "SELECT relfilenode as \"Filenode\", relname as \"Table Name\" %s "
+ "SELECT relfilenode as \"Filenode\", relname as \"Table Name\" %s "
"FROM pg_class c "
- " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace "
- " LEFT JOIN pg_catalog.pg_database d ON d.datname = current_database(),"
+ " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace "
+ " LEFT JOIN pg_catalog.pg_database d ON d.datname = current_database(),"
" pg_catalog.pg_tablespace t "
"WHERE relkind IN ('r'%s) AND "
" %s"
@@ -412,7 +417,7 @@ sql_exec_dumpalltables(PGconn *conn, struct options *opts)
"ORDER BY relname",
opts->extended ? addfields : "",
opts->indexes ? ", 'i', 'S', 't'" : "",
- opts->systables ? "" : "n.nspname NOT IN ('pg_catalog', 'pg_toast', 'information_schema') AND");
+ opts->systables ? "" : "n.nspname NOT IN ('pg_catalog', 'pg_toast', 'information_schema') AND");
sql_exec(conn, todo, opts->quiet);
}
@@ -422,11 +427,14 @@ sql_exec_dumpalltables(PGconn *conn, struct options *opts)
* given objects in the current database.
*/
void
-sql_exec_searchtables(PGconn *conn, struct options *opts)
+sql_exec_searchtables(PGconn *conn, struct options * opts)
{
char *todo;
- char *qualifiers, *ptr;
- char *comma_oids, *comma_filenodes, *comma_tables;
+ char *qualifiers,
+ *ptr;
+ char *comma_oids,
+ *comma_filenodes,
+ *comma_tables;
bool written = false;
char *addfields = ",c.oid AS \"Oid\", nspname AS \"Schema\", spcname as \"Tablespace\" ";
@@ -465,9 +473,9 @@ sql_exec_searchtables(PGconn *conn, struct options *opts)
/* now build the query */
todo = (char *) myalloc(650 + strlen(qualifiers));
snprintf(todo, 650 + strlen(qualifiers),
- "SELECT relfilenode as \"Filenode\", relname as \"Table Name\" %s\n"
+ "SELECT relfilenode as \"Filenode\", relname as \"Table Name\" %s\n"
"FROM pg_class c \n"
- " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace \n"
+ " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace \n"
" LEFT JOIN pg_catalog.pg_database d ON d.datname = current_database(),\n"
" pg_catalog.pg_tablespace t \n"
"WHERE relkind IN ('r', 'i', 'S', 't') AND \n"
@@ -486,9 +494,9 @@ sql_exec_searchtables(PGconn *conn, struct options *opts)
}
void
-sql_exec_dumpalltbspc(PGconn *conn, struct options *opts)
+sql_exec_dumpalltbspc(PGconn *conn, struct options * opts)
{
- char todo[1024];
+ char todo[1024];
snprintf(todo, sizeof(todo),
"SELECT oid AS \"Oid\", spcname as \"Tablespace Name\"\n"
diff --git a/contrib/pg_buffercache/pg_buffercache_pages.c b/contrib/pg_buffercache/pg_buffercache_pages.c
index e511c0df9a..a0ae43f77d 100644
--- a/contrib/pg_buffercache/pg_buffercache_pages.c
+++ b/contrib/pg_buffercache/pg_buffercache_pages.c
@@ -1,9 +1,9 @@
/*-------------------------------------------------------------------------
*
* pg_buffercache_pages.c
- * display some contents of the buffer cache
+ * display some contents of the buffer cache
*
- * $PostgreSQL: pgsql/contrib/pg_buffercache/pg_buffercache_pages.c,v 1.5 2005/10/12 16:45:13 tgl Exp $
+ * $PostgreSQL: pgsql/contrib/pg_buffercache/pg_buffercache_pages.c,v 1.6 2005/10/15 02:49:05 momjian Exp $
*-------------------------------------------------------------------------
*/
#include "postgres.h"
@@ -17,11 +17,11 @@
#define NUM_BUFFERCACHE_PAGES_ELEM 6
#if defined(WIN32) || defined(__CYGWIN__)
-extern DLLIMPORT BufferDesc *BufferDescriptors;
-extern DLLIMPORT volatile uint32 InterruptHoldoffCount;
+extern DLLIMPORT BufferDesc *BufferDescriptors;
+extern DLLIMPORT volatile uint32 InterruptHoldoffCount;
#endif
-Datum pg_buffercache_pages(PG_FUNCTION_ARGS);
+Datum pg_buffercache_pages(PG_FUNCTION_ARGS);
/*
@@ -34,24 +34,24 @@ typedef struct
Oid relfilenode;
Oid reltablespace;
Oid reldatabase;
- BlockNumber blocknum;
+ BlockNumber blocknum;
bool isvalid;
bool isdirty;
-} BufferCachePagesRec;
+} BufferCachePagesRec;
/*
* Function context for data persisting over repeated calls.
*/
-typedef struct
+typedef struct
{
- AttInMetadata *attinmeta;
- BufferCachePagesRec *record;
- char *values[NUM_BUFFERCACHE_PAGES_ELEM];
+ AttInMetadata *attinmeta;
+ BufferCachePagesRec *record;
+ char *values[NUM_BUFFERCACHE_PAGES_ELEM];
-} BufferCachePagesContext;
+} BufferCachePagesContext;
/*
@@ -63,44 +63,44 @@ Datum
pg_buffercache_pages(PG_FUNCTION_ARGS)
{
- FuncCallContext *funcctx;
- Datum result;
- MemoryContext oldcontext;
- BufferCachePagesContext *fctx; /* User function context. */
- TupleDesc tupledesc;
- HeapTuple tuple;
+ FuncCallContext *funcctx;
+ Datum result;
+ MemoryContext oldcontext;
+ BufferCachePagesContext *fctx; /* User function context. */
+ TupleDesc tupledesc;
+ HeapTuple tuple;
if (SRF_IS_FIRSTCALL())
{
uint32 i;
- volatile BufferDesc *bufHdr;
+ volatile BufferDesc *bufHdr;
funcctx = SRF_FIRSTCALL_INIT();
/* Switch context when allocating stuff to be used in later calls */
oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
-
+
/* Construct a tuple to return. */
tupledesc = CreateTemplateTupleDesc(NUM_BUFFERCACHE_PAGES_ELEM, false);
TupleDescInitEntry(tupledesc, (AttrNumber) 1, "bufferid",
- INT4OID, -1, 0);
+ INT4OID, -1, 0);
TupleDescInitEntry(tupledesc, (AttrNumber) 2, "relfilenode",
- OIDOID, -1, 0);
+ OIDOID, -1, 0);
TupleDescInitEntry(tupledesc, (AttrNumber) 3, "reltablespace",
- OIDOID, -1, 0);
+ OIDOID, -1, 0);
TupleDescInitEntry(tupledesc, (AttrNumber) 4, "reldatabase",
- OIDOID, -1, 0);
+ OIDOID, -1, 0);
TupleDescInitEntry(tupledesc, (AttrNumber) 5, "relblocknumber",
- INT8OID, -1, 0);
+ INT8OID, -1, 0);
TupleDescInitEntry(tupledesc, (AttrNumber) 6, "isdirty",
- BOOLOID, -1, 0);
+ BOOLOID, -1, 0);
/* Generate attribute metadata needed later to produce tuples */
funcctx->attinmeta = TupleDescGetAttInMetadata(tupledesc);
- /*
- * Create a function context for cross-call persistence
- * and initialize the buffer counters.
+ /*
+ * Create a function context for cross-call persistence and initialize
+ * the buffer counters.
*/
fctx = (BufferCachePagesContext *) palloc(sizeof(BufferCachePagesContext));
funcctx->max_calls = NBuffers;
@@ -118,12 +118,12 @@ pg_buffercache_pages(PG_FUNCTION_ARGS)
fctx->values[4] = (char *) palloc(3 * sizeof(uint32) + 1);
fctx->values[5] = (char *) palloc(2);
-
+
/* Return to original context when allocating transient memory */
MemoryContextSwitchTo(oldcontext);
- /*
+ /*
* Lock Buffer map and scan though all the buffers, saving the
* relevant fields in the fctx->record structure.
*/
@@ -140,7 +140,7 @@ pg_buffercache_pages(PG_FUNCTION_ARGS)
fctx->record[i].reldatabase = bufHdr->tag.rnode.dbNode;
fctx->record[i].blocknum = bufHdr->tag.blockNum;
- if (bufHdr->flags & BM_DIRTY)
+ if (bufHdr->flags & BM_DIRTY)
fctx->record[i].isdirty = true;
else
fctx->record[i].isdirty = false;
@@ -159,34 +159,34 @@ pg_buffercache_pages(PG_FUNCTION_ARGS)
}
funcctx = SRF_PERCALL_SETUP();
-
+
/* Get the saved state */
fctx = funcctx->user_fctx;
if (funcctx->call_cntr < funcctx->max_calls)
{
- uint32 i = funcctx->call_cntr;
- char *values[NUM_BUFFERCACHE_PAGES_ELEM];
+ uint32 i = funcctx->call_cntr;
+ char *values[NUM_BUFFERCACHE_PAGES_ELEM];
int j;
-
- /*
- * Use a temporary values array, initially pointing to
- * fctx->values, so it can be reassigned w/o losing the storage
- * for subsequent calls.
+
+ /*
+ * Use a temporary values array, initially pointing to fctx->values,
+ * so it can be reassigned w/o losing the storage for subsequent
+ * calls.
*/
for (j = 0; j < NUM_BUFFERCACHE_PAGES_ELEM; j++)
{
values[j] = fctx->values[j];
}
-
+
/*
- * Set all fields except the bufferid to null if the buffer is
- * unused or not valid.
+ * Set all fields except the bufferid to null if the buffer is unused
+ * or not valid.
*/
if (fctx->record[i].blocknum == InvalidBlockNumber ||
- fctx->record[i].isvalid == false )
+ fctx->record[i].isvalid == false)
{
sprintf(values[0], "%u", fctx->record[i].bufferid);
@@ -205,7 +205,7 @@ pg_buffercache_pages(PG_FUNCTION_ARGS)
sprintf(values[2], "%u", fctx->record[i].reltablespace);
sprintf(values[3], "%u", fctx->record[i].reldatabase);
sprintf(values[4], "%u", fctx->record[i].blocknum);
- if (fctx->record[i].isdirty)
+ if (fctx->record[i].isdirty)
{
strcpy(values[5], "t");
}
@@ -213,7 +213,7 @@ pg_buffercache_pages(PG_FUNCTION_ARGS)
{
strcpy(values[5], "f");
}
-
+
}
@@ -228,4 +228,3 @@ pg_buffercache_pages(PG_FUNCTION_ARGS)
SRF_RETURN_DONE(funcctx);
}
-
diff --git a/contrib/pg_trgm/trgm_op.c b/contrib/pg_trgm/trgm_op.c
index 57fb944a56..407b317f28 100644
--- a/contrib/pg_trgm/trgm_op.c
+++ b/contrib/pg_trgm/trgm_op.c
@@ -300,8 +300,8 @@ similarity_op(PG_FUNCTION_ARGS)
{
float4 res = DatumGetFloat4(DirectFunctionCall2(
similarity,
- PG_GETARG_DATUM(0),
- PG_GETARG_DATUM(1)
+ PG_GETARG_DATUM(0),
+ PG_GETARG_DATUM(1)
));
PG_RETURN_BOOL(res >= trgm_limit);
diff --git a/contrib/pgbench/pgbench.c b/contrib/pgbench/pgbench.c
index 1b3d6bb09e..4ec056b343 100644
--- a/contrib/pgbench/pgbench.c
+++ b/contrib/pgbench/pgbench.c
@@ -1,5 +1,5 @@
/*
- * $PostgreSQL: pgsql/contrib/pgbench/pgbench.c,v 1.42 2005/10/07 15:34:17 tgl Exp $
+ * $PostgreSQL: pgsql/contrib/pgbench/pgbench.c,v 1.43 2005/10/15 02:49:06 momjian Exp $
*
* pgbench: a simple benchmark program for PostgreSQL
* written by Tatsuo Ishii
@@ -55,8 +55,7 @@ extern int optind;
#define MAXCLIENTS 1024 /* max number of clients allowed */
int nclients = 1; /* default number of simulated clients */
-int nxacts = 10; /* default number of transactions per
- * clients */
+int nxacts = 10; /* default number of transactions per clients */
/*
* scaling factor. for example, tps = 10 will make 1000000 tuples of
@@ -78,8 +77,7 @@ bool use_log; /* log transaction latencies to a file */
int remains; /* number of remaining clients */
-int is_connect; /* establish connection for each
- * transaction */
+int is_connect; /* establish connection for each transaction */
char *pghost = "";
char *pgport = NULL;
@@ -92,8 +90,8 @@ char *dbName;
/* variable definitions */
typedef struct
{
- char *name; /* variable name */
- char *value; /* its value */
+ char *name; /* variable name */
+ char *value; /* its value */
} Variable;
/*
@@ -107,8 +105,8 @@ typedef struct
int state; /* state No. */
int cnt; /* xacts count */
int ecnt; /* error count */
- int listen; /* 0 indicates that an async query has
- * been sent */
+ int listen; /* 0 indicates that an async query has been
+ * sent */
Variable *variables; /* array of variable definitions */
int nvariables;
struct timeval txn_begin; /* used for measuring latencies */
@@ -124,48 +122,48 @@ typedef struct
typedef struct
{
- int type; /* command type (SQL_COMMAND or META_COMMAND) */
- int argc; /* number of commands */
- char *argv[MAX_ARGS]; /* command list */
+ int type; /* command type (SQL_COMMAND or META_COMMAND) */
+ int argc; /* number of commands */
+ char *argv[MAX_ARGS]; /* command list */
} Command;
#define MAX_FILES 128 /* max number of SQL script files allowed */
-Command **sql_files[MAX_FILES]; /* SQL script files */
-int num_files; /* its number */
+Command **sql_files[MAX_FILES]; /* SQL script files */
+int num_files; /* its number */
/* default scenario */
static char *tpc_b = {
-"\\setrandom aid 1 100000\n"
-"\\setrandom bid 1 1\n"
-"\\setrandom tid 1 10\n"
-"\\setrandom delta 1 10000\n"
-"BEGIN;\n"
-"UPDATE accounts SET abalance = abalance + :delta WHERE aid = :aid;\n"
-"SELECT abalance FROM accounts WHERE aid = :aid;\n"
-"UPDATE tellers SET tbalance = tbalance + :delta WHERE tid = :tid;\n"
-"UPDATE branches SET bbalance = bbalance + :delta WHERE bid = :bid;\n"
-"INSERT INTO history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);\n"
-"END;\n"
+ "\\setrandom aid 1 100000\n"
+ "\\setrandom bid 1 1\n"
+ "\\setrandom tid 1 10\n"
+ "\\setrandom delta 1 10000\n"
+ "BEGIN;\n"
+ "UPDATE accounts SET abalance = abalance + :delta WHERE aid = :aid;\n"
+ "SELECT abalance FROM accounts WHERE aid = :aid;\n"
+ "UPDATE tellers SET tbalance = tbalance + :delta WHERE tid = :tid;\n"
+ "UPDATE branches SET bbalance = bbalance + :delta WHERE bid = :bid;\n"
+ "INSERT INTO history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);\n"
+ "END;\n"
};
/* -N case */
static char *simple_update = {
-"\\setrandom aid 1 100000\n"
-"\\setrandom bid 1 1\n"
-"\\setrandom tid 1 10\n"
-"\\setrandom delta 1 10000\n"
-"BEGIN;\n"
-"UPDATE accounts SET abalance = abalance + :delta WHERE aid = :aid;\n"
-"SELECT abalance FROM accounts WHERE aid = :aid;\n"
-"INSERT INTO history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);\n"
-"END;\n"
+ "\\setrandom aid 1 100000\n"
+ "\\setrandom bid 1 1\n"
+ "\\setrandom tid 1 10\n"
+ "\\setrandom delta 1 10000\n"
+ "BEGIN;\n"
+ "UPDATE accounts SET abalance = abalance + :delta WHERE aid = :aid;\n"
+ "SELECT abalance FROM accounts WHERE aid = :aid;\n"
+ "INSERT INTO history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);\n"
+ "END;\n"
};
/* -S case */
static char *select_only = {
-"\\setrandom aid 1 100000\n"
-"SELECT abalance FROM accounts WHERE aid = :aid;\n"
+ "\\setrandom aid 1 100000\n"
+ "SELECT abalance FROM accounts WHERE aid = :aid;\n"
};
static void
@@ -262,7 +260,7 @@ compareVariables(const void *v1, const void *v2)
static char *
getVariable(CState * st, char *name)
{
- Variable key = { name }, *var;
+ Variable key = {name}, *var;
/* On some versions of Solaris, bsearch of zero items dumps core */
if (st->nvariables <= 0)
@@ -282,7 +280,7 @@ getVariable(CState * st, char *name)
static int
putVariable(CState * st, char *name, char *value)
{
- Variable key = { name }, *var;
+ Variable key = {name}, *var;
/* On some versions of Solaris, bsearch of zero items dumps core */
if (st->nvariables > 0)
@@ -300,7 +298,7 @@ putVariable(CState * st, char *name, char *value)
if (st->variables)
newvars = (Variable *) realloc(st->variables,
- (st->nvariables + 1) * sizeof(Variable));
+ (st->nvariables + 1) * sizeof(Variable));
else
newvars = (Variable *) malloc(sizeof(Variable));
@@ -341,15 +339,19 @@ putVariable(CState * st, char *name, char *value)
static char *
assignVariables(CState * st, char *sql)
{
- int i, j;
- char *p, *name, *val;
+ int i,
+ j;
+ char *p,
+ *name,
+ *val;
void *tmp;
i = 0;
while ((p = strchr(&sql[i], ':')) != NULL)
{
i = j = p - sql;
- do {
+ do
+ {
i++;
} while (isalnum((unsigned char) sql[i]) || sql[i] == '_');
if (i == j + 1)
@@ -403,7 +405,7 @@ doCustom(CState * state, int n, int debug)
{
PGresult *res;
CState *st = &state[n];
- Command **commands;
+ Command **commands;
commands = sql_files[st->use_file];
@@ -414,20 +416,19 @@ doCustom(CState * state, int n, int debug)
if (debug)
fprintf(stderr, "client %d receiving\n", n);
if (!PQconsumeInput(st->con))
- { /* there's something wrong */
+ { /* there's something wrong */
fprintf(stderr, "Client %d aborted in state %d. Probably the backend died while processing.\n", n, st->state);
- remains--; /* I've aborted */
+ remains--; /* I've aborted */
PQfinish(st->con);
st->con = NULL;
return;
}
if (PQisBusy(st->con))
- return; /* don't have the whole result yet */
+ return; /* don't have the whole result yet */
}
/*
- * transaction finished: record the time it took in the
- * log
+ * transaction finished: record the time it took in the log
*/
if (use_log && commands[st->state + 1] == NULL)
{
@@ -468,7 +469,7 @@ doCustom(CState * state, int n, int debug)
if (++st->cnt >= nxacts)
{
- remains--; /* I've done */
+ remains--; /* I've done */
if (st->con != NULL)
{
PQfinish(st->con);
@@ -483,7 +484,7 @@ doCustom(CState * state, int n, int debug)
if (commands[st->state] == NULL)
{
st->state = 0;
- st->use_file = getrand(0, num_files-1);
+ st->use_file = getrand(0, num_files - 1);
}
}
@@ -525,13 +526,14 @@ doCustom(CState * state, int n, int debug)
}
else
{
- st->listen = 1; /* flags that should be listened */
+ st->listen = 1; /* flags that should be listened */
}
free(sql);
}
else if (commands[st->state]->type == META_COMMAND)
{
- int argc = commands[st->state]->argc, i;
+ int argc = commands[st->state]->argc,
+ i;
char **argv = commands[st->state]->argv;
if (debug)
@@ -748,28 +750,29 @@ init(void)
PQfinish(con);
}
-static Command*
+static Command *
process_commands(char *buf)
{
const char delim[] = " \f\n\r\t\v";
- Command *my_commands;
+ Command *my_commands;
int j;
- char *p, *tok;
+ char *p,
+ *tok;
if ((p = strchr(buf, '\n')) != NULL)
- *p = '\0';
+ *p = '\0';
p = buf;
while (isspace((unsigned char) *p))
- p++;
+ p++;
if (*p == '\0' || strncmp(p, "--", 2) == 0)
{
return NULL;
}
- my_commands = (Command *)malloc(sizeof(Command));
+ my_commands = (Command *) malloc(sizeof(Command));
if (my_commands == NULL)
{
return NULL;
@@ -794,10 +797,11 @@ process_commands(char *buf)
j++;
tok = strtok(NULL, delim);
}
-
+
if (strcasecmp(my_commands->argv[0], "setrandom") == 0)
{
- int min, max;
+ int min,
+ max;
if (my_commands->argc < 4)
{
@@ -806,8 +810,8 @@ process_commands(char *buf)
}
for (j = 4; j < my_commands->argc; j++)
- fprintf(stderr, "%s: extra argument \"%s\" ignored\n",
- my_commands->argv[0], my_commands->argv[j]);
+ fprintf(stderr, "%s: extra argument \"%s\" ignored\n",
+ my_commands->argv[0], my_commands->argv[j]);
if ((min = atoi(my_commands->argv[2])) < 0)
{
@@ -825,7 +829,7 @@ process_commands(char *buf)
}
else
{
- fprintf(stderr, "invalid command %s\n", my_commands->argv[0]);
+ fprintf(stderr, "invalid command %s\n", my_commands->argv[0]);
return NULL;
}
}
@@ -847,11 +851,11 @@ process_file(char *filename)
{
#define COMMANDS_ALLOC_NUM 128
- Command **my_commands;
+ Command **my_commands;
FILE *fd;
int lineno;
char buf[BUFSIZ];
- int alloc_num;
+ int alloc_num;
if (num_files >= MAX_FILES)
{
@@ -860,7 +864,7 @@ process_file(char *filename)
}
alloc_num = COMMANDS_ALLOC_NUM;
- my_commands = (Command **)malloc(sizeof(Command **)*alloc_num);
+ my_commands = (Command **) malloc(sizeof(Command **) * alloc_num);
if (my_commands == NULL)
return false;
@@ -876,7 +880,7 @@ process_file(char *filename)
while (fgets(buf, sizeof(buf), fd) != NULL)
{
- Command *commands;
+ Command *commands;
commands = process_commands(buf);
if (commands == NULL)
@@ -913,25 +917,25 @@ process_builtin(char *tb)
{
#define COMMANDS_ALLOC_NUM 128
- Command **my_commands;
+ Command **my_commands;
int lineno;
char buf[BUFSIZ];
- int alloc_num;
+ int alloc_num;
if (*tb == '\0')
return NULL;
alloc_num = COMMANDS_ALLOC_NUM;
- my_commands = malloc(sizeof(Command **)*alloc_num);
+ my_commands = malloc(sizeof(Command **) * alloc_num);
if (my_commands == NULL)
return NULL;
lineno = 0;
- for(;;)
+ for (;;)
{
- char *p;
- Command *commands;
+ char *p;
+ Command *commands;
p = buf;
while (*tb && *tb != '\n')
@@ -1016,20 +1020,18 @@ main(int argc, char **argv)
{
int c;
int is_init_mode = 0; /* initialize mode? */
- int is_no_vacuum = 0; /* no vacuum at all before
- * testing? */
+ int is_no_vacuum = 0; /* no vacuum at all before testing? */
int is_full_vacuum = 0; /* do full vacuum before testing? */
int debug = 0; /* debug flag */
- int ttype = 0; /* transaction type. 0: TPC-B, 1: SELECT
- * only, 2: skip update of branches and
- * tellers */
+ int ttype = 0; /* transaction type. 0: TPC-B, 1: SELECT only,
+ * 2: skip update of branches and tellers */
char *filename = NULL;
static CState *state; /* status of clients */
struct timeval tv1; /* start up time */
- struct timeval tv2; /* after establishing all connections to
- * the backend */
+ struct timeval tv2; /* after establishing all connections to the
+ * backend */
struct timeval tv3; /* end time */
int i;
@@ -1105,7 +1107,8 @@ main(int argc, char **argv)
fprintf(stderr, "Use limit/ulimt to increase the limit before using pgbench.\n");
exit(1);
}
-#endif /* #if !(defined(__CYGWIN__) || defined(__MINGW32__)) */
+#endif /* #if !(defined(__CYGWIN__) ||
+ * defined(__MINGW32__)) */
break;
case 'C':
is_connect = 1;
@@ -1305,35 +1308,35 @@ main(int argc, char **argv)
/* process bultin SQL scripts */
switch (ttype)
{
- char buf[128];
+ char buf[128];
case 0:
sql_files[0] = process_builtin(tpc_b);
- snprintf(buf, sizeof(buf), "%d", 100000*tps);
+ snprintf(buf, sizeof(buf), "%d", 100000 * tps);
sql_files[0][0]->argv[3] = strdup(buf);
- snprintf(buf, sizeof(buf), "%d", 1*tps);
+ snprintf(buf, sizeof(buf), "%d", 1 * tps);
sql_files[0][1]->argv[3] = strdup(buf);
- snprintf(buf, sizeof(buf), "%d", 10*tps);
+ snprintf(buf, sizeof(buf), "%d", 10 * tps);
sql_files[0][2]->argv[3] = strdup(buf);
- snprintf(buf, sizeof(buf), "%d", 10000*tps);
+ snprintf(buf, sizeof(buf), "%d", 10000 * tps);
sql_files[0][3]->argv[3] = strdup(buf);
num_files = 1;
break;
case 1:
sql_files[0] = process_builtin(select_only);
- snprintf(buf, sizeof(buf), "%d", 100000*tps);
+ snprintf(buf, sizeof(buf), "%d", 100000 * tps);
sql_files[0][0]->argv[3] = strdup(buf);
num_files = 1;
break;
case 2:
sql_files[0] = process_builtin(simple_update);
- snprintf(buf, sizeof(buf), "%d", 100000*tps);
+ snprintf(buf, sizeof(buf), "%d", 100000 * tps);
sql_files[0][0]->argv[3] = strdup(buf);
- snprintf(buf, sizeof(buf), "%d", 1*tps);
+ snprintf(buf, sizeof(buf), "%d", 1 * tps);
sql_files[0][1]->argv[3] = strdup(buf);
- snprintf(buf, sizeof(buf), "%d", 10*tps);
+ snprintf(buf, sizeof(buf), "%d", 10 * tps);
sql_files[0][2]->argv[3] = strdup(buf);
- snprintf(buf, sizeof(buf), "%d", 10000*tps);
+ snprintf(buf, sizeof(buf), "%d", 10000 * tps);
sql_files[0][3]->argv[3] = strdup(buf);
num_files = 1;
break;
@@ -1344,7 +1347,7 @@ main(int argc, char **argv)
/* send start up queries in async manner */
for (i = 0; i < nclients; i++)
{
- state[i].use_file = getrand(0, num_files-1);
+ state[i].use_file = getrand(0, num_files - 1);
doCustom(state, i, debug);
}
@@ -1366,9 +1369,9 @@ main(int argc, char **argv)
maxsock = -1;
for (i = 0; i < nclients; i++)
{
- Command **commands = sql_files[state[i].use_file];
+ Command **commands = sql_files[state[i].use_file];
- if (state[i].con && commands[state[i].state]->type != META_COMMAND)
+ if (state[i].con && commands[state[i].state]->type != META_COMMAND)
{
int sock = PQsocket(state[i].con);
@@ -1396,7 +1399,7 @@ main(int argc, char **argv)
exit(1);
}
else if (nsocks == 0)
- { /* timeout */
+ { /* timeout */
fprintf(stderr, "select timeout\n");
for (i = 0; i < nclients; i++)
{
@@ -1410,10 +1413,10 @@ main(int argc, char **argv)
/* ok, backend returns reply */
for (i = 0; i < nclients; i++)
{
- Command **commands = sql_files[state[i].use_file];
+ Command **commands = sql_files[state[i].use_file];
if (state[i].con && (FD_ISSET(PQsocket(state[i].con), &input_mask)
- || commands[state[i].state]->type == META_COMMAND))
+ || commands[state[i].state]->type == META_COMMAND))
{
doCustom(state, i, debug);
}
diff --git a/contrib/pgcrypto/crypt-blowfish.c b/contrib/pgcrypto/crypt-blowfish.c
index a882cf4c87..42a694b62f 100644
--- a/contrib/pgcrypto/crypt-blowfish.c
+++ b/contrib/pgcrypto/crypt-blowfish.c
@@ -520,7 +520,6 @@ extern void _BF_body_r(BF_ctx * ctx);
#define BF_body() \
_BF_body_r(&data.ctx);
-
#else
#define BF_body() \
@@ -712,7 +711,7 @@ _crypt_blowfish_rn(const char *key, const char *setting,
memcpy(output, setting, 7 + 22 - 1);
output[7 + 22 - 1] = BF_itoa64[(int)
- BF_atoi64[(int) setting[7 + 22 - 1] - 0x20] & 0x30];
+ BF_atoi64[(int) setting[7 + 22 - 1] - 0x20] & 0x30];
/* This has to be bug-compatible with the original implementation, so
* only encode 23 of the 24 bytes. :-) */
diff --git a/contrib/pgcrypto/crypt-des.c b/contrib/pgcrypto/crypt-des.c
index 74768e73a7..6ed7188f4a 100644
--- a/contrib/pgcrypto/crypt-des.c
+++ b/contrib/pgcrypto/crypt-des.c
@@ -246,8 +246,8 @@ des_init(void)
}
/*
- * Convert the inverted S-boxes into 4 arrays of 8 bits. Each will
- * handle 12 bits of the S-box input.
+ * Convert the inverted S-boxes into 4 arrays of 8 bits. Each will handle
+ * 12 bits of the S-box input.
*/
for (b = 0; b < 4; b++)
for (i = 0; i < 64; i++)
@@ -267,8 +267,8 @@ des_init(void)
}
/*
- * Invert the key permutation and initialise the inverted key
- * compression permutation.
+ * Invert the key permutation and initialise the inverted key compression
+ * permutation.
*/
for (i = 0; i < 56; i++)
{
@@ -284,8 +284,8 @@ des_init(void)
inv_comp_perm[comp_perm[i] - 1] = i;
/*
- * Set up the OR-mask arrays for the initial and final permutations,
- * and for the key initial and compression permutations.
+ * Set up the OR-mask arrays for the initial and final permutations, and
+ * for the key initial and compression permutations.
*/
for (k = 0; k < 8; k++)
{
@@ -347,8 +347,8 @@ des_init(void)
}
/*
- * Invert the P-box permutation, and convert into OR-masks for
- * handling the output of the S-box arrays setup above.
+ * Invert the P-box permutation, and convert into OR-masks for handling
+ * the output of the S-box arrays setup above.
*/
for (i = 0; i < 32; i++)
un_pbox[pbox[i] - 1] = i;
@@ -411,9 +411,9 @@ des_setkey(const char *key)
&& rawkey1 == old_rawkey1)
{
/*
- * Already setup for this key. This optimisation fails on a zero
- * key (which is weak and has bad parity anyway) in order to
- * simplify the starting conditions.
+ * Already setup for this key. This optimisation fails on a zero key
+ * (which is weak and has bad parity anyway) in order to simplify the
+ * starting conditions.
*/
return (0);
}
@@ -560,16 +560,16 @@ do_des(uint32 l_in, uint32 r_in, uint32 *l_out, uint32 *r_out, int count)
| ((r & 0x80000000) >> 31);
/*
- * Do salting for crypt() and friends, and XOR with the
- * permuted key.
+ * Do salting for crypt() and friends, and XOR with the permuted
+ * key.
*/
f = (r48l ^ r48r) & saltbits;
r48l ^= f ^ *kl++;
r48r ^= f ^ *kr++;
/*
- * Do sbox lookups (which shrink it back to 32 bits) and do
- * the pbox permutation at the same time.
+ * Do sbox lookups (which shrink it back to 32 bits) and do the
+ * pbox permutation at the same time.
*/
f = psbox[0][m_sbox[0][r48l >> 12]]
| psbox[1][m_sbox[1][r48l & 0xfff]]
@@ -660,8 +660,8 @@ px_crypt_des(const char *key, const char *setting)
/*
- * Copy the key, shifting each character up by one bit and padding
- * with zeros.
+ * Copy the key, shifting each character up by one bit and padding with
+ * zeros.
*/
q = (uint8 *) keybuf;
while (q - (uint8 *) keybuf - 8)
@@ -706,10 +706,10 @@ px_crypt_des(const char *key, const char *setting)
strncpy(output, setting, 9);
/*
- * Double check that we weren't given a short setting. If we were,
- * the above code will probably have created wierd values for
- * count and salt, but we don't really care. Just make sure the
- * output string doesn't have an extra NUL in it.
+ * Double check that we weren't given a short setting. If we were, the
+ * above code will probably have created wierd values for count and
+ * salt, but we don't really care. Just make sure the output string
+ * doesn't have an extra NUL in it.
*/
output[9] = '\0';
p = output + strlen(output);
@@ -728,9 +728,9 @@ px_crypt_des(const char *key, const char *setting)
output[0] = setting[0];
/*
- * If the encrypted password that the salt was extracted from is
- * only 1 character long, the salt will be corrupted. We need to
- * ensure that the output string doesn't have an extra NUL in it!
+ * If the encrypted password that the salt was extracted from is only
+ * 1 character long, the salt will be corrupted. We need to ensure
+ * that the output string doesn't have an extra NUL in it!
*/
output[1] = setting[1] ? setting[1] : output[0];
diff --git a/contrib/pgcrypto/crypt-gensalt.c b/contrib/pgcrypto/crypt-gensalt.c
index 8713b99a16..656ab03ef7 100644
--- a/contrib/pgcrypto/crypt-gensalt.c
+++ b/contrib/pgcrypto/crypt-gensalt.c
@@ -22,7 +22,7 @@ unsigned char _crypt_itoa64[64 + 1] =
char *
_crypt_gensalt_traditional_rn(unsigned long count,
- const char *input, int size, char *output, int output_size)
+ const char *input, int size, char *output, int output_size)
{
if (size < 2 || output_size < 2 + 1 || (count && count != 25))
{
@@ -40,7 +40,7 @@ _crypt_gensalt_traditional_rn(unsigned long count,
char *
_crypt_gensalt_extended_rn(unsigned long count,
- const char *input, int size, char *output, int output_size)
+ const char *input, int size, char *output, int output_size)
{
unsigned long value;
@@ -76,7 +76,7 @@ _crypt_gensalt_extended_rn(unsigned long count,
char *
_crypt_gensalt_md5_rn(unsigned long count,
- const char *input, int size, char *output, int output_size)
+ const char *input, int size, char *output, int output_size)
{
unsigned long value;
@@ -158,7 +158,7 @@ BF_encode(char *dst, const BF_word * src, int size)
char *
_crypt_gensalt_blowfish_rn(unsigned long count,
- const char *input, int size, char *output, int output_size)
+ const char *input, int size, char *output, int output_size)
{
if (size < 16 || output_size < 7 + 22 + 1 ||
(count && (count < 4 || count > 31)))
diff --git a/contrib/pgcrypto/crypt-md5.c b/contrib/pgcrypto/crypt-md5.c
index dceb599775..a9f22c412a 100644
--- a/contrib/pgcrypto/crypt-md5.c
+++ b/contrib/pgcrypto/crypt-md5.c
@@ -8,7 +8,7 @@
*
* $FreeBSD: src/lib/libcrypt/crypt-md5.c,v 1.5 1999/12/17 20:21:45 peter Exp $
*
- * $PostgreSQL: pgsql/contrib/pgcrypto/crypt-md5.c,v 1.5 2005/09/24 19:14:04 tgl Exp $
+ * $PostgreSQL: pgsql/contrib/pgcrypto/crypt-md5.c,v 1.6 2005/10/15 02:49:06 momjian Exp $
*/
#include "postgres.h"
@@ -24,9 +24,9 @@
char *
px_crypt_md5(const char *pw, const char *salt, char *passwd, unsigned dstlen)
{
- static char *magic = "$1$"; /* This string is magic for this
- * algorithm. Having it this way, we can
- * get get better later on */
+ static char *magic = "$1$"; /* This string is magic for this algorithm.
+ * Having it this way, we can get get better
+ * later on */
static char *p;
static const char *sp,
*ep;
diff --git a/contrib/pgcrypto/fortuna.c b/contrib/pgcrypto/fortuna.c
index 4645076109..1b13337301 100644
--- a/contrib/pgcrypto/fortuna.c
+++ b/contrib/pgcrypto/fortuna.c
@@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $PostgreSQL: pgsql/contrib/pgcrypto/fortuna.c,v 1.4 2005/07/18 17:12:54 tgl Exp $
+ * $PostgreSQL: pgsql/contrib/pgcrypto/fortuna.c,v 1.5 2005/10/15 02:49:06 momjian Exp $
*/
#include "postgres.h"
@@ -43,16 +43,16 @@
* Why Fortuna-like: There does not seem to be any definitive reference
* on Fortuna in the net. Instead this implementation is based on
* following references:
- *
+ *
* http://en.wikipedia.org/wiki/Fortuna_(PRNG)
- * - Wikipedia article
+ * - Wikipedia article
* http://jlcooke.ca/random/
- * - Jean-Luc Cooke Fortuna-based /dev/random driver for Linux.
+ * - Jean-Luc Cooke Fortuna-based /dev/random driver for Linux.
*/
/*
* There is some confusion about whether and how to carry forward
- * the state of the pools. Seems like original Fortuna does not
+ * the state of the pools. Seems like original Fortuna does not
* do it, resetting hash after each request. I guess expecting
* feeding to happen more often that requesting. This is absolutely
* unsuitable for pgcrypto, as nothing asynchronous happens here.
@@ -76,7 +76,7 @@
* How many pools.
*
* Original Fortuna uses 32 pools, that means 32'th pool is
- * used not earlier than in 13th year. This is a waste in
+ * used not earlier than in 13th year. This is a waste in
* pgcrypto, as we have very low-frequancy seeding. Here
* is preferable to have all entropy usable in reasonable time.
*
@@ -89,12 +89,12 @@
#define NUM_POOLS 23
/* in microseconds */
-#define RESEED_INTERVAL 100000 /* 0.1 sec */
+#define RESEED_INTERVAL 100000 /* 0.1 sec */
/* for one big request, reseed after this many bytes */
#define RESEED_BYTES (1024*1024)
-/*
+/*
* Skip reseed if pool 0 has less than this many
* bytes added since last reseed.
*/
@@ -114,17 +114,18 @@
#define MD_CTX SHA256_CTX
#define CIPH_CTX rijndael_ctx
-struct fortuna_state {
- uint8 counter[CIPH_BLOCK];
- uint8 result[CIPH_BLOCK];
- uint8 key[BLOCK];
- MD_CTX pool[NUM_POOLS];
- CIPH_CTX ciph;
- unsigned reseed_count;
- struct timeval last_reseed_time;
- unsigned pool0_bytes;
- unsigned rnd_pos;
- int counter_init;
+struct fortuna_state
+{
+ uint8 counter[CIPH_BLOCK];
+ uint8 result[CIPH_BLOCK];
+ uint8 key[BLOCK];
+ MD_CTX pool[NUM_POOLS];
+ CIPH_CTX ciph;
+ unsigned reseed_count;
+ struct timeval last_reseed_time;
+ unsigned pool0_bytes;
+ unsigned rnd_pos;
+ int counter_init;
};
typedef struct fortuna_state FState;
@@ -137,29 +138,35 @@ typedef struct fortuna_state FState;
* - No memory allocations.
*/
-static void ciph_init(CIPH_CTX *ctx, const uint8 *key, int klen)
+static void
+ciph_init(CIPH_CTX * ctx, const uint8 *key, int klen)
{
- rijndael_set_key(ctx, (const uint32 *)key, klen, 1);
+ rijndael_set_key(ctx, (const uint32 *) key, klen, 1);
}
-static void ciph_encrypt(CIPH_CTX *ctx, const uint8 *in, uint8 *out)
+static void
+ciph_encrypt(CIPH_CTX * ctx, const uint8 *in, uint8 *out)
{
- rijndael_encrypt(ctx, (const uint32 *)in, (uint32 *)out);
+ rijndael_encrypt(ctx, (const uint32 *) in, (uint32 *) out);
}
-static void md_init(MD_CTX *ctx)
+static void
+md_init(MD_CTX * ctx)
{
SHA256_Init(ctx);
}
-static void md_update(MD_CTX *ctx, const uint8 *data, int len)
+static void
+md_update(MD_CTX * ctx, const uint8 *data, int len)
{
SHA256_Update(ctx, data, len);
}
-static void md_result(MD_CTX *ctx, uint8 *dst)
+static void
+md_result(MD_CTX * ctx, uint8 *dst)
{
- SHA256_CTX tmp;
+ SHA256_CTX tmp;
+
memcpy(&tmp, ctx, sizeof(*ctx));
SHA256_Final(dst, &tmp);
memset(&tmp, 0, sizeof(tmp));
@@ -168,9 +175,11 @@ static void md_result(MD_CTX *ctx, uint8 *dst)
/*
* initialize state
*/
-static void init_state(FState *st)
+static void
+init_state(FState * st)
{
- int i;
+ int i;
+
memset(st, 0, sizeof(*st));
for (i = 0; i < NUM_POOLS; i++)
md_init(&st->pool[i]);
@@ -180,9 +189,11 @@ static void init_state(FState *st)
* Endianess does not matter.
* It just needs to change without repeating.
*/
-static void inc_counter(FState *st)
+static void
+inc_counter(FState * st)
{
- uint32 *val = (uint32*)st->counter;
+ uint32 *val = (uint32 *) st->counter;
+
if (++val[0])
return;
if (++val[1])
@@ -195,7 +206,8 @@ static void inc_counter(FState *st)
/*
* This is called 'cipher in counter mode'.
*/
-static void encrypt_counter(FState *st, uint8 *dst)
+static void
+encrypt_counter(FState * st, uint8 *dst)
{
ciph_encrypt(&st->ciph, st->counter, dst);
inc_counter(st);
@@ -206,12 +218,13 @@ static void encrypt_counter(FState *st, uint8 *dst)
* The time between reseed must be at least RESEED_INTERVAL
* microseconds.
*/
-static int too_often(FState *st)
+static int
+too_often(FState * st)
{
- int ok;
+ int ok;
struct timeval tv;
struct timeval *last = &st->last_reseed_time;
-
+
gettimeofday(&tv, NULL);
ok = 0;
@@ -229,19 +242,19 @@ static int too_often(FState *st)
/*
* generate new key from all the pools
*/
-static void reseed(FState *st)
+static void
+reseed(FState * st)
{
- unsigned k;
- unsigned n;
- MD_CTX key_md;
- uint8 buf[BLOCK];
+ unsigned k;
+ unsigned n;
+ MD_CTX key_md;
+ uint8 buf[BLOCK];
/* set pool as empty */
st->pool0_bytes = 0;
/*
- * Both #0 and #1 reseed would use only pool 0.
- * Just skip #0 then.
+ * Both #0 and #1 reseed would use only pool 0. Just skip #0 then.
*/
n = ++st->reseed_count;
@@ -249,7 +262,8 @@ static void reseed(FState *st)
* The goal: use k-th pool only 1/(2^k) of the time.
*/
md_init(&key_md);
- for (k = 0; k < NUM_POOLS; k++) {
+ for (k = 0; k < NUM_POOLS; k++)
+ {
md_result(&st->pool[k], buf);
md_update(&key_md, buf, BLOCK);
@@ -272,11 +286,12 @@ static void reseed(FState *st)
}
/*
- * Pick a random pool. This uses key bytes as random source.
+ * Pick a random pool. This uses key bytes as random source.
*/
-static unsigned get_rand_pool(FState *st)
+static unsigned
+get_rand_pool(FState * st)
{
- unsigned rnd;
+ unsigned rnd;
/*
* This slightly prefers lower pools - thats OK.
@@ -293,11 +308,12 @@ static unsigned get_rand_pool(FState *st)
/*
* update pools
*/
-static void add_entropy(FState *st, const uint8 *data, unsigned len)
+static void
+add_entropy(FState * st, const uint8 *data, unsigned len)
{
- unsigned pos;
- uint8 hash[BLOCK];
- MD_CTX md;
+ unsigned pos;
+ uint8 hash[BLOCK];
+ MD_CTX md;
/* hash given data */
md_init(&md);
@@ -305,14 +321,13 @@ static void add_entropy(FState *st, const uint8 *data, unsigned len)
md_result(&md, hash);
/*
- * Make sure the pool 0 is initialized,
- * then update randomly.
+ * Make sure the pool 0 is initialized, then update randomly.
*/
if (st->reseed_count == 0 && st->pool0_bytes < POOL0_FILL)
pos = 0;
else
pos = get_rand_pool(st);
- md_update( &st->pool[pos], hash, BLOCK);
+ md_update(&st->pool[pos], hash, BLOCK);
if (pos == 0)
st->pool0_bytes += len;
@@ -324,7 +339,8 @@ static void add_entropy(FState *st, const uint8 *data, unsigned len)
/*
* Just take 2 next blocks as new key
*/
-static void rekey(FState *st)
+static void
+rekey(FState * st)
{
encrypt_counter(st, st->key);
encrypt_counter(st, st->key + CIPH_BLOCK);
@@ -336,7 +352,8 @@ static void rekey(FState *st)
* In case it does not, slow down the attacker by initialising
* the couter to random value.
*/
-static void init_counter(FState *st)
+static void
+init_counter(FState * st)
{
/* Use next block as counter. */
encrypt_counter(st, st->counter);
@@ -348,10 +365,11 @@ static void init_counter(FState *st)
st->counter_init = 1;
}
-static void extract_data(FState *st, unsigned count, uint8 *dst)
+static void
+extract_data(FState * st, unsigned count, uint8 *dst)
{
- unsigned n;
- unsigned block_nr = 0;
+ unsigned n;
+ unsigned block_nr = 0;
/* Can we reseed? */
if (st->pool0_bytes >= POOL0_FILL && !too_often(st))
@@ -361,7 +379,8 @@ static void extract_data(FState *st, unsigned count, uint8 *dst)
if (!st->counter_init)
init_counter(st);
- while (count > 0) {
+ while (count > 0)
+ {
/* produce bytes */
encrypt_counter(st, st->result);
@@ -391,9 +410,10 @@ static void extract_data(FState *st, unsigned count, uint8 *dst)
*/
static FState main_state;
-static int init_done = 0;
+static int init_done = 0;
-void fortuna_add_entropy(const uint8 *data, unsigned len)
+void
+fortuna_add_entropy(const uint8 *data, unsigned len)
{
if (!init_done)
{
@@ -405,7 +425,8 @@ void fortuna_add_entropy(const uint8 *data, unsigned len)
add_entropy(&main_state, data, len);
}
-void fortuna_get_bytes(unsigned len, uint8 *dst)
+void
+fortuna_get_bytes(unsigned len, uint8 *dst)
{
if (!init_done)
{
@@ -416,4 +437,3 @@ void fortuna_get_bytes(unsigned len, uint8 *dst)
return;
extract_data(&main_state, len, dst);
}
-
diff --git a/contrib/pgcrypto/fortuna.h b/contrib/pgcrypto/fortuna.h
index 12e0c56832..b4d7064dec 100644
--- a/contrib/pgcrypto/fortuna.h
+++ b/contrib/pgcrypto/fortuna.h
@@ -26,14 +26,13 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $PostgreSQL: pgsql/contrib/pgcrypto/fortuna.h,v 1.2 2005/07/18 17:12:54 tgl Exp $
+ * $PostgreSQL: pgsql/contrib/pgcrypto/fortuna.h,v 1.3 2005/10/15 02:49:06 momjian Exp $
*/
#ifndef __FORTUNA_H
#define __FORTUNA_H
-void fortuna_get_bytes(unsigned len, uint8 *dst);
-void fortuna_add_entropy(const uint8 *data, unsigned len);
+void fortuna_get_bytes(unsigned len, uint8 *dst);
+void fortuna_add_entropy(const uint8 *data, unsigned len);
#endif
-
diff --git a/contrib/pgcrypto/internal.c b/contrib/pgcrypto/internal.c
index bfe4eeb2b7..f5dd11c90b 100644
--- a/contrib/pgcrypto/internal.c
+++ b/contrib/pgcrypto/internal.c
@@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $PostgreSQL: pgsql/contrib/pgcrypto/internal.c,v 1.22 2005/07/18 17:12:54 tgl Exp $
+ * $PostgreSQL: pgsql/contrib/pgcrypto/internal.c,v 1.23 2005/10/15 02:49:06 momjian Exp $
*/
#include "postgres.h"
@@ -52,7 +52,7 @@
/*
* The chance is x/256 that the reseed happens.
*/
-#define SYSTEM_RESEED_CHANCE (4) /* 256/4 * 10min ~ 10h */
+#define SYSTEM_RESEED_CHANCE (4) /* 256/4 * 10min ~ 10h */
/*
* If this much time has passed, force reseed.
@@ -88,13 +88,13 @@ struct int_digest
};
static const struct int_digest
-int_digest_list[] = {
- { "md5", init_md5 },
- { "sha1", init_sha1 },
- { "sha256", init_sha256 },
- { "sha384", init_sha384 },
- { "sha512", init_sha512 },
- { NULL, NULL }
+ int_digest_list[] = {
+ {"md5", init_md5},
+ {"sha1", init_sha1},
+ {"sha256", init_sha256},
+ {"sha384", init_sha384},
+ {"sha512", init_sha512},
+ {NULL, NULL}
};
/* MD5 */
@@ -210,7 +210,7 @@ int_sha256_block_len(PX_MD * h)
static void
int_sha256_update(PX_MD * h, const uint8 *data, unsigned dlen)
{
- SHA256_CTX *ctx = (SHA256_CTX *) h->p.ptr;
+ SHA256_CTX *ctx = (SHA256_CTX *) h->p.ptr;
SHA256_Update(ctx, data, dlen);
}
@@ -218,7 +218,7 @@ int_sha256_update(PX_MD * h, const uint8 *data, unsigned dlen)
static void
int_sha256_reset(PX_MD * h)
{
- SHA256_CTX *ctx = (SHA256_CTX *) h->p.ptr;
+ SHA256_CTX *ctx = (SHA256_CTX *) h->p.ptr;
SHA256_Init(ctx);
}
@@ -226,7 +226,7 @@ int_sha256_reset(PX_MD * h)
static void
int_sha256_finish(PX_MD * h, uint8 *dst)
{
- SHA256_CTX *ctx = (SHA256_CTX *) h->p.ptr;
+ SHA256_CTX *ctx = (SHA256_CTX *) h->p.ptr;
SHA256_Final(dst, ctx);
}
@@ -234,12 +234,13 @@ int_sha256_finish(PX_MD * h, uint8 *dst)
static void
int_sha256_free(PX_MD * h)
{
- SHA256_CTX *ctx = (SHA256_CTX *) h->p.ptr;
+ SHA256_CTX *ctx = (SHA256_CTX *) h->p.ptr;
memset(ctx, 0, sizeof(*ctx));
px_free(ctx);
px_free(h);
}
+
/* SHA384 */
static unsigned
@@ -257,7 +258,7 @@ int_sha384_block_len(PX_MD * h)
static void
int_sha384_update(PX_MD * h, const uint8 *data, unsigned dlen)
{
- SHA384_CTX *ctx = (SHA384_CTX *) h->p.ptr;
+ SHA384_CTX *ctx = (SHA384_CTX *) h->p.ptr;
SHA384_Update(ctx, data, dlen);
}
@@ -265,7 +266,7 @@ int_sha384_update(PX_MD * h, const uint8 *data, unsigned dlen)
static void
int_sha384_reset(PX_MD * h)
{
- SHA384_CTX *ctx = (SHA384_CTX *) h->p.ptr;
+ SHA384_CTX *ctx = (SHA384_CTX *) h->p.ptr;
SHA384_Init(ctx);
}
@@ -273,7 +274,7 @@ int_sha384_reset(PX_MD * h)
static void
int_sha384_finish(PX_MD * h, uint8 *dst)
{
- SHA384_CTX *ctx = (SHA384_CTX *) h->p.ptr;
+ SHA384_CTX *ctx = (SHA384_CTX *) h->p.ptr;
SHA384_Final(dst, ctx);
}
@@ -281,7 +282,7 @@ int_sha384_finish(PX_MD * h, uint8 *dst)
static void
int_sha384_free(PX_MD * h)
{
- SHA384_CTX *ctx = (SHA384_CTX *) h->p.ptr;
+ SHA384_CTX *ctx = (SHA384_CTX *) h->p.ptr;
memset(ctx, 0, sizeof(*ctx));
px_free(ctx);
@@ -305,7 +306,7 @@ int_sha512_block_len(PX_MD * h)
static void
int_sha512_update(PX_MD * h, const uint8 *data, unsigned dlen)
{
- SHA512_CTX *ctx = (SHA512_CTX *) h->p.ptr;
+ SHA512_CTX *ctx = (SHA512_CTX *) h->p.ptr;
SHA512_Update(ctx, data, dlen);
}
@@ -313,7 +314,7 @@ int_sha512_update(PX_MD * h, const uint8 *data, unsigned dlen)
static void
int_sha512_reset(PX_MD * h)
{
- SHA512_CTX *ctx = (SHA512_CTX *) h->p.ptr;
+ SHA512_CTX *ctx = (SHA512_CTX *) h->p.ptr;
SHA512_Init(ctx);
}
@@ -321,7 +322,7 @@ int_sha512_reset(PX_MD * h)
static void
int_sha512_finish(PX_MD * h, uint8 *dst)
{
- SHA512_CTX *ctx = (SHA512_CTX *) h->p.ptr;
+ SHA512_CTX *ctx = (SHA512_CTX *) h->p.ptr;
SHA512_Final(dst, ctx);
}
@@ -329,7 +330,7 @@ int_sha512_finish(PX_MD * h, uint8 *dst)
static void
int_sha512_free(PX_MD * h)
{
- SHA512_CTX *ctx = (SHA512_CTX *) h->p.ptr;
+ SHA512_CTX *ctx = (SHA512_CTX *) h->p.ptr;
memset(ctx, 0, sizeof(*ctx));
px_free(ctx);
@@ -381,7 +382,7 @@ init_sha1(PX_MD * md)
static void
init_sha256(PX_MD * md)
{
- SHA256_CTX *ctx;
+ SHA256_CTX *ctx;
ctx = px_alloc(sizeof(*ctx));
memset(ctx, 0, sizeof(*ctx));
@@ -401,7 +402,7 @@ init_sha256(PX_MD * md)
static void
init_sha384(PX_MD * md)
{
- SHA384_CTX *ctx;
+ SHA384_CTX *ctx;
ctx = px_alloc(sizeof(*ctx));
memset(ctx, 0, sizeof(*ctx));
@@ -421,7 +422,7 @@ init_sha384(PX_MD * md)
static void
init_sha512(PX_MD * md)
{
- SHA512_CTX *ctx;
+ SHA512_CTX *ctx;
ctx = px_alloc(sizeof(*ctx));
memset(ctx, 0, sizeof(*ctx));
@@ -752,12 +753,12 @@ struct int_cipher
};
static const struct int_cipher
-int_ciphers[] = {
- { "bf-cbc", bf_cbc_load },
- { "bf-ecb", bf_ecb_load },
- { "aes-128-cbc", rj_128_cbc },
- { "aes-128-ecb", rj_128_ecb },
- { NULL, NULL }
+ int_ciphers[] = {
+ {"bf-cbc", bf_cbc_load},
+ {"bf-ecb", bf_ecb_load},
+ {"aes-128-cbc", rj_128_cbc},
+ {"aes-128-ecb", rj_128_ecb},
+ {NULL, NULL}
};
static const PX_Alias int_aliases[] = {
@@ -828,7 +829,7 @@ px_find_cipher(const char *name, PX_Cipher ** res)
int
px_get_pseudo_random_bytes(uint8 *dst, unsigned count)
{
- int i;
+ int i;
for (i = 0; i < count; i++)
*dst++ = random();
@@ -838,12 +839,13 @@ px_get_pseudo_random_bytes(uint8 *dst, unsigned count)
static time_t seed_time = 0;
static time_t check_time = 0;
-static void system_reseed(void)
+static void
+system_reseed(void)
{
- uint8 buf[1024];
- int n;
- time_t t;
- int skip = 1;
+ uint8 buf[1024];
+ int n;
+ time_t t;
+ int skip = 1;
t = time(NULL);
@@ -890,4 +892,3 @@ px_add_entropy(const uint8 *data, unsigned count)
fortuna_add_entropy(data, count);
return 0;
}
-
diff --git a/contrib/pgcrypto/mbuf.c b/contrib/pgcrypto/mbuf.c
index ac59d7fc97..c6a1b99100 100644
--- a/contrib/pgcrypto/mbuf.c
+++ b/contrib/pgcrypto/mbuf.c
@@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $PostgreSQL: pgsql/contrib/pgcrypto/mbuf.c,v 1.2 2005/07/11 15:07:59 tgl Exp $
+ * $PostgreSQL: pgsql/contrib/pgcrypto/mbuf.c,v 1.3 2005/10/15 02:49:06 momjian Exp $
*/
#include "postgres.h"
@@ -166,7 +166,8 @@ mbuf_grab(MBuf * mbuf, int len, uint8 **data_p)
return len;
}
-int mbuf_rewind(MBuf *mbuf)
+int
+mbuf_rewind(MBuf * mbuf)
{
mbuf->read_pos = mbuf->data;
return 0;
@@ -175,7 +176,7 @@ int mbuf_rewind(MBuf *mbuf)
int
mbuf_steal_data(MBuf * mbuf, uint8 **data_p)
{
- int len = mbuf_size(mbuf);
+ int len = mbuf_size(mbuf);
mbuf->no_write = 1;
mbuf->own_data = 0;
@@ -193,7 +194,7 @@ mbuf_steal_data(MBuf * mbuf, uint8 **data_p)
struct PullFilter
{
- PullFilter *src;
+ PullFilter *src;
const PullFilterOps *op;
int buflen;
uint8 *buf;
@@ -204,7 +205,7 @@ struct PullFilter
int
pullf_create(PullFilter ** pf_p, const PullFilterOps * op, void *init_arg, PullFilter * src)
{
- PullFilter *pf;
+ PullFilter *pf;
void *priv;
int res;
@@ -260,13 +261,14 @@ pullf_free(PullFilter * pf)
int
pullf_read(PullFilter * pf, int len, uint8 **data_p)
{
- int res;
+ int res;
+
if (pf->op->pull)
{
if (pf->buflen && len > pf->buflen)
len = pf->buflen;
res = pf->op->pull(pf->priv, pf->src, len, data_p,
- pf->buf, pf->buflen);
+ pf->buf, pf->buflen);
}
else
res = pullf_read(pf->src, len, data_p);
@@ -276,8 +278,9 @@ pullf_read(PullFilter * pf, int len, uint8 **data_p)
int
pullf_read_max(PullFilter * pf, int len, uint8 **data_p, uint8 *tmpbuf)
{
- int res, total;
- uint8 *tmp;
+ int res,
+ total;
+ uint8 *tmp;
res = pullf_read(pf, len, data_p);
if (res <= 0 || res == len)
@@ -288,8 +291,9 @@ pullf_read_max(PullFilter * pf, int len, uint8 **data_p, uint8 *tmpbuf)
*data_p = tmpbuf;
len -= res;
total = res;
-
- while (len > 0) {
+
+ while (len > 0)
+ {
res = pullf_read(pf, len, &tmp);
if (res < 0)
{
@@ -308,10 +312,12 @@ pullf_read_max(PullFilter * pf, int len, uint8 **data_p, uint8 *tmpbuf)
/*
* caller wants exatly len bytes and dont bother with references
*/
-int pullf_read_fixed(PullFilter *src, int len, uint8 *dst)
+int
+pullf_read_fixed(PullFilter * src, int len, uint8 *dst)
{
- int res;
- uint8 *p;
+ int res;
+ uint8 *p;
+
res = pullf_read_max(src, len, &p, dst);
if (res < 0)
return res;
@@ -330,9 +336,10 @@ int pullf_read_fixed(PullFilter *src, int len, uint8 *dst)
*/
static int
pull_from_mbuf(void *arg, PullFilter * src, int len,
- uint8 **data_p, uint8 *buf, int buflen)
+ uint8 **data_p, uint8 *buf, int buflen)
{
MBuf *mbuf = arg;
+
return mbuf_grab(mbuf, len, data_p);
}
@@ -364,7 +371,7 @@ struct PushFilter
int
pushf_create(PushFilter ** mp_p, const PushFilterOps * op, void *init_arg, PushFilter * next)
{
- PushFilter *mp;
+ PushFilter *mp;
void *priv;
int res;
@@ -419,7 +426,7 @@ pushf_free(PushFilter * mp)
void
pushf_free_all(PushFilter * mp)
{
- PushFilter *tmp;
+ PushFilter *tmp;
while (mp)
{
@@ -549,8 +556,8 @@ static const struct PushFilterOps mbuf_filter = {
NULL, push_into_mbuf, NULL, NULL
};
-int pushf_create_mbuf_writer(PushFilter **res, MBuf *dst)
+int
+pushf_create_mbuf_writer(PushFilter ** res, MBuf * dst)
{
return pushf_create(res, &mbuf_filter, dst, NULL);
}
-
diff --git a/contrib/pgcrypto/mbuf.h b/contrib/pgcrypto/mbuf.h
index 6042a4fc2e..91ef821ed4 100644
--- a/contrib/pgcrypto/mbuf.h
+++ b/contrib/pgcrypto/mbuf.h
@@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $PostgreSQL: pgsql/contrib/pgcrypto/mbuf.h,v 1.1 2005/07/10 13:46:28 momjian Exp $
+ * $PostgreSQL: pgsql/contrib/pgcrypto/mbuf.h,v 1.2 2005/10/15 02:49:06 momjian Exp $
*/
#ifndef __PX_MBUF_H
@@ -40,32 +40,36 @@ typedef struct PullFilterOps PullFilterOps;
struct PushFilterOps
{
- /* should return needed buffer size, 0- no buffering, <0 on error
- * if NULL, no buffering, and priv=init_arg
+ /*
+ * should return needed buffer size, 0- no buffering, <0 on error if NULL,
+ * no buffering, and priv=init_arg
*/
int (*init) (PushFilter * next, void *init_arg, void **priv_p);
- /* send data to next. should consume all?
- * if null, it will be simply copied (in-place)
- * returns 0 on error
+
+ /*
+ * send data to next. should consume all? if null, it will be simply
+ * copied (in-place) returns 0 on error
*/
int (*push) (PushFilter * next, void *priv,
- const uint8 *src, int len);
+ const uint8 *src, int len);
int (*flush) (PushFilter * next, void *priv);
void (*free) (void *priv);
};
struct PullFilterOps
{
- /* should return needed buffer size, 0- no buffering, <0 on error
- * if NULL, no buffering, and priv=init_arg
+ /*
+ * should return needed buffer size, 0- no buffering, <0 on error if NULL,
+ * no buffering, and priv=init_arg
*/
int (*init) (void **priv_p, void *init_arg, PullFilter * src);
- /* request data from src, put result ptr to data_p
- * can use ptr from src or use buf as work area
- * if NULL in-place copy
+
+ /*
+ * request data from src, put result ptr to data_p can use ptr from src or
+ * use buf as work area if NULL in-place copy
*/
int (*pull) (void *priv, PullFilter * src, int len,
- uint8 **data_p, uint8 *buf, int buflen);
+ uint8 **data_p, uint8 *buf, int buflen);
void (*free) (void *priv);
};
@@ -86,8 +90,8 @@ int mbuf_free(MBuf * mbuf);
/*
* Push filter
*/
-int pushf_create(PushFilter ** res, const PushFilterOps * ops, void *init_arg,
- PushFilter * next);
+int pushf_create(PushFilter ** res, const PushFilterOps * ops, void *init_arg,
+ PushFilter * next);
int pushf_write(PushFilter * mp, const uint8 *data, int len);
void pushf_free_all(PushFilter * mp);
void pushf_free(PushFilter * mp);
@@ -98,13 +102,13 @@ int pushf_create_mbuf_writer(PushFilter ** mp_p, MBuf * mbuf);
/*
* Pull filter
*/
-int pullf_create(PullFilter ** res, const PullFilterOps * ops,
- void *init_arg, PullFilter * src);
+int pullf_create(PullFilter ** res, const PullFilterOps * ops,
+ void *init_arg, PullFilter * src);
int pullf_read(PullFilter * mp, int len, uint8 **data_p);
-int pullf_read_max(PullFilter * mp, int len,
- uint8 **data_p, uint8 *tmpbuf);
+int pullf_read_max(PullFilter * mp, int len,
+ uint8 **data_p, uint8 *tmpbuf);
void pullf_free(PullFilter * mp);
-int pullf_read_fixed(PullFilter *src, int len, uint8 *dst);
+int pullf_read_fixed(PullFilter * src, int len, uint8 *dst);
int pullf_create_mbuf_reader(PullFilter ** pf_p, MBuf * mbuf);
@@ -118,4 +122,3 @@ int pullf_create_mbuf_reader(PullFilter ** pf_p, MBuf * mbuf);
} while (0)
#endif /* __PX_MBUF_H */
-
diff --git a/contrib/pgcrypto/md5.h b/contrib/pgcrypto/md5.h
index 9e32be2f08..933dcaa9b9 100644
--- a/contrib/pgcrypto/md5.h
+++ b/contrib/pgcrypto/md5.h
@@ -1,4 +1,4 @@
-/* $PostgreSQL: pgsql/contrib/pgcrypto/md5.h,v 1.8 2003/11/29 22:39:28 pgsql Exp $ */
+/* $PostgreSQL: pgsql/contrib/pgcrypto/md5.h,v 1.9 2005/10/15 02:49:06 momjian Exp $ */
/* $KAME: md5.h,v 1.3 2000/02/22 14:01:18 itojun Exp $ */
/*
diff --git a/contrib/pgcrypto/openssl.c b/contrib/pgcrypto/openssl.c
index 67358c941f..a4840227ad 100644
--- a/contrib/pgcrypto/openssl.c
+++ b/contrib/pgcrypto/openssl.c
@@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $PostgreSQL: pgsql/contrib/pgcrypto/openssl.c,v 1.25 2005/07/12 20:27:42 tgl Exp $
+ * $PostgreSQL: pgsql/contrib/pgcrypto/openssl.c,v 1.26 2005/10/15 02:49:06 momjian Exp $
*/
#include "postgres.h"
@@ -47,14 +47,13 @@
#define MAX_IV (128/8)
/*
- * Does OpenSSL support AES?
+ * Does OpenSSL support AES?
*/
#if OPENSSL_VERSION_NUMBER >= 0x00907000L
/* Yes, it does. */
#include <openssl/aes.h>
-
-#else /* old OPENSSL */
+#else /* old OPENSSL */
/*
* No, it does not. So use included rijndael code to emulate it.
@@ -91,8 +90,7 @@
memcpy(iv, (src) + (len) - 16, 16); \
} \
} while (0)
-
-#endif /* old OPENSSL */
+#endif /* old OPENSSL */
/*
* Compatibility with older OpenSSL API for DES.
@@ -157,8 +155,8 @@ digest_finish(PX_MD * h, uint8 *dst)
EVP_DigestFinal(ctx, dst, NULL);
/*
- * Some builds of 0.9.7x clear all of ctx in EVP_DigestFinal.
- * Fix it by reinitializing ctx.
+ * Some builds of 0.9.7x clear all of ctx in EVP_DigestFinal. Fix it by
+ * reinitializing ctx.
*/
EVP_DigestInit(ctx, md);
}
@@ -246,7 +244,9 @@ typedef struct
} des;
struct
{
- DES_key_schedule k1, k2, k3;
+ DES_key_schedule k1,
+ k2,
+ k3;
} des3;
CAST_KEY cast_key;
AES_KEY aes_key;
@@ -597,12 +597,12 @@ ossl_aes_init(PX_Cipher * c, const uint8 *key, unsigned klen, const uint8 *iv)
ossldata *od = c->ptr;
unsigned bs = gen_ossl_block_size(c);
- if (klen <= 128/8)
- od->klen = 128/8;
- else if (klen <= 192/8)
- od->klen = 192/8;
- else if (klen <= 256/8)
- od->klen = 256/8;
+ if (klen <= 128 / 8)
+ od->klen = 128 / 8;
+ else if (klen <= 192 / 8)
+ od->klen = 192 / 8;
+ else if (klen <= 256 / 8)
+ od->klen = 256 / 8;
else
return PXE_KEY_TOO_BIG;
@@ -825,7 +825,8 @@ static int openssl_random_init = 0;
* OpenSSL random should re-feeded occasionally. From /dev/urandom
* preferably.
*/
-static void init_openssl_rand(void)
+static void
+init_openssl_rand(void)
{
if (RAND_get_rand_method() == NULL)
RAND_set_rand_method(RAND_SSLeay());
@@ -871,4 +872,3 @@ px_add_entropy(const uint8 *data, unsigned count)
RAND_add(data, count, 0);
return 0;
}
-
diff --git a/contrib/pgcrypto/pgcrypto.c b/contrib/pgcrypto/pgcrypto.c
index 4888fb8725..cc3814aacd 100644
--- a/contrib/pgcrypto/pgcrypto.c
+++ b/contrib/pgcrypto/pgcrypto.c
@@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $PostgreSQL: pgsql/contrib/pgcrypto/pgcrypto.c,v 1.19 2005/09/24 19:14:04 tgl Exp $
+ * $PostgreSQL: pgsql/contrib/pgcrypto/pgcrypto.c,v 1.20 2005/10/15 02:49:06 momjian Exp $
*/
#include "postgres.h"
@@ -244,7 +244,7 @@ pg_gen_salt_rounds(PG_FUNCTION_ARGS)
if (len < 0)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg("gen_salt: %s", px_strerror(len))));
+ errmsg("gen_salt: %s", px_strerror(len))));
res = (text *) palloc(len + VARHDRSZ);
VARATT_SIZEP(res) = len + VARHDRSZ;
diff --git a/contrib/pgcrypto/pgp-armor.c b/contrib/pgcrypto/pgp-armor.c
index b379b2538e..7963ccc329 100644
--- a/contrib/pgcrypto/pgp-armor.c
+++ b/contrib/pgcrypto/pgp-armor.c
@@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $PostgreSQL: pgsql/contrib/pgcrypto/pgp-armor.c,v 1.2 2005/07/11 15:07:59 tgl Exp $
+ * $PostgreSQL: pgsql/contrib/pgcrypto/pgp-armor.c,v 1.3 2005/10/15 02:49:06 momjian Exp $
*/
#include "postgres.h"
@@ -40,7 +40,7 @@
*/
static const unsigned char _base64[] =
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static int
b64_encode(const uint8 *src, unsigned len, uint8 *dst)
@@ -96,13 +96,13 @@ static int
b64_decode(const uint8 *src, unsigned len, uint8 *dst)
{
const uint8 *srcend = src + len,
- *s = src;
+ *s = src;
uint8 *p = dst;
char c;
unsigned b = 0;
unsigned long buf = 0;
int pos = 0,
- end = 0;
+ end = 0;
while (s < srcend)
{
@@ -242,11 +242,13 @@ static const uint8 *
find_str(const uint8 *data, const uint8 *data_end, const char *str, int strlen)
{
const uint8 *p = data;
+
if (!strlen)
return NULL;
if (data_end - data < strlen)
return NULL;
- while (p < data_end) {
+ while (p < data_end)
+ {
p = memchr(p, str[0], data_end - p);
if (p == NULL)
return NULL;
@@ -261,7 +263,7 @@ find_str(const uint8 *data, const uint8 *data_end, const char *str, int strlen)
static int
find_header(const uint8 *data, const uint8 *datend,
- const uint8 **start_p, int is_end)
+ const uint8 **start_p, int is_end)
{
const uint8 *p = data;
static const char *start_sep = "-----BEGIN";
@@ -285,7 +287,7 @@ find_header(const uint8 *data, const uint8 *datend,
/* check if header text ok */
for (; p < datend && *p != '-'; p++)
{
- /* various junk can be there, but definitely not line-feed */
+ /* various junk can be there, but definitely not line-feed */
if (*p >= ' ')
continue;
return PXE_PGP_CORRUPT_ARMOR;
@@ -313,7 +315,8 @@ pgp_armor_decode(const uint8 *src, unsigned len, uint8 *dst)
const uint8 *p = src;
const uint8 *data_end = src + len;
long crc;
- const uint8 *base64_start, *armor_end;
+ const uint8 *base64_start,
+ *armor_end;
const uint8 *base64_end = NULL;
uint8 buf[4];
int hlen;
@@ -329,7 +332,7 @@ pgp_armor_decode(const uint8 *src, unsigned len, uint8 *dst)
hlen = find_header(p, data_end, &armor_end, 1);
if (hlen <= 0)
goto out;
-
+
/* skip comments - find empty line */
while (p < armor_end && *p != '\n' && *p != '\r')
{
@@ -341,7 +344,7 @@ pgp_armor_decode(const uint8 *src, unsigned len, uint8 *dst)
p++;
}
base64_start = p;
-
+
/* find crc pos */
for (p = armor_end; p >= base64_start; p--)
if (*p == '=')
@@ -355,7 +358,7 @@ pgp_armor_decode(const uint8 *src, unsigned len, uint8 *dst)
/* decode crc */
if (b64_decode(p + 1, 4, buf) != 3)
goto out;
- crc = (((long)buf[0]) << 16) + (((long)buf[1]) << 8) + (long)buf[2];
+ crc = (((long) buf[0]) << 16) + (((long) buf[1]) << 8) + (long) buf[2];
/* decode data */
res = b64_decode(base64_start, base64_end - base64_start, dst);
@@ -378,4 +381,3 @@ pgp_armor_dec_len(unsigned len)
{
return b64_dec_len(len);
}
-
diff --git a/contrib/pgcrypto/pgp-cfb.c b/contrib/pgcrypto/pgp-cfb.c
index 52e56acfc0..811bb7c2c3 100644
--- a/contrib/pgcrypto/pgp-cfb.c
+++ b/contrib/pgcrypto/pgp-cfb.c
@@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $PostgreSQL: pgsql/contrib/pgcrypto/pgp-cfb.c,v 1.2 2005/07/11 15:07:59 tgl Exp $
+ * $PostgreSQL: pgsql/contrib/pgcrypto/pgp-cfb.c,v 1.3 2005/10/15 02:49:06 momjian Exp $
*/
#include "postgres.h"
@@ -35,7 +35,7 @@
#include "px.h"
#include "pgp.h"
-typedef int (*mix_data_t)(PGP_CFB *ctx, const uint8 *data, int len, uint8 *dst);
+typedef int (*mix_data_t) (PGP_CFB * ctx, const uint8 *data, int len, uint8 *dst);
struct PGP_CFB
{
@@ -50,12 +50,12 @@ struct PGP_CFB
};
int
-pgp_cfb_create(PGP_CFB **ctx_p, int algo, const uint8 *key, int key_len,
- int resync, uint8 *iv)
+pgp_cfb_create(PGP_CFB ** ctx_p, int algo, const uint8 *key, int key_len,
+ int resync, uint8 *iv)
{
- int res;
- PX_Cipher *ciph;
- PGP_CFB *ctx;
+ int res;
+ PX_Cipher *ciph;
+ PGP_CFB *ctx;
res = pgp_load_cipher(algo, &ciph);
if (res < 0)
@@ -82,7 +82,7 @@ pgp_cfb_create(PGP_CFB **ctx_p, int algo, const uint8 *key, int key_len,
}
void
-pgp_cfb_free(PGP_CFB *ctx)
+pgp_cfb_free(PGP_CFB * ctx)
{
px_cipher_free(ctx->ciph);
memset(ctx, 0, sizeof(*ctx));
@@ -90,12 +90,13 @@ pgp_cfb_free(PGP_CFB *ctx)
}
/*
- * Data processing for normal CFB. (PGP_PKT_SYMENCRYPTED_DATA_MDC)
+ * Data processing for normal CFB. (PGP_PKT_SYMENCRYPTED_DATA_MDC)
*/
static int
-mix_encrypt_normal(PGP_CFB *ctx, const uint8 *data, int len, uint8 *dst)
+mix_encrypt_normal(PGP_CFB * ctx, const uint8 *data, int len, uint8 *dst)
{
- int i;
+ int i;
+
for (i = ctx->pos; i < ctx->pos + len; i++)
*dst++ = ctx->encbuf[i] = ctx->fre[i] ^ (*data++);
ctx->pos += len;
@@ -103,9 +104,10 @@ mix_encrypt_normal(PGP_CFB *ctx, const uint8 *data, int len, uint8 *dst)
}
static int
-mix_decrypt_normal(PGP_CFB *ctx, const uint8 *data, int len, uint8 *dst)
+mix_decrypt_normal(PGP_CFB * ctx, const uint8 *data, int len, uint8 *dst)
{
- int i;
+ int i;
+
for (i = ctx->pos; i < ctx->pos + len; i++)
{
ctx->encbuf[i] = *data++;
@@ -122,9 +124,11 @@ mix_decrypt_normal(PGP_CFB *ctx, const uint8 *data, int len, uint8 *dst)
* thus its all concentrated here.
*/
static int
-mix_encrypt_resync(PGP_CFB *ctx, const uint8 *data, int len, uint8 *dst)
+mix_encrypt_resync(PGP_CFB * ctx, const uint8 *data, int len, uint8 *dst)
{
- int i,n;
+ int i,
+ n;
+
/* block #2 is 2 bytes long */
if (ctx->block_no == 2)
{
@@ -152,9 +156,11 @@ mix_encrypt_resync(PGP_CFB *ctx, const uint8 *data, int len, uint8 *dst)
}
static int
-mix_decrypt_resync(PGP_CFB *ctx, const uint8 *data, int len, uint8 *dst)
+mix_decrypt_resync(PGP_CFB * ctx, const uint8 *data, int len, uint8 *dst)
{
- int i,n;
+ int i,
+ n;
+
/* block #2 is 2 bytes long */
if (ctx->block_no == 2)
{
@@ -190,11 +196,11 @@ mix_decrypt_resync(PGP_CFB *ctx, const uint8 *data, int len, uint8 *dst)
* common code for both encrypt and decrypt.
*/
static int
-cfb_process(PGP_CFB *ctx, const uint8 *data, int len, uint8 *dst,
- mix_data_t mix_data)
+cfb_process(PGP_CFB * ctx, const uint8 *data, int len, uint8 *dst,
+ mix_data_t mix_data)
{
- int n;
- int res;
+ int n;
+ int res;
while (len > 0 && ctx->pos > 0)
{
@@ -243,16 +249,17 @@ cfb_process(PGP_CFB *ctx, const uint8 *data, int len, uint8 *dst,
*/
int
-pgp_cfb_encrypt(PGP_CFB *ctx, const uint8 *data, int len, uint8 *dst)
+pgp_cfb_encrypt(PGP_CFB * ctx, const uint8 *data, int len, uint8 *dst)
{
- mix_data_t mix = ctx->resync ? mix_encrypt_resync : mix_encrypt_normal;
+ mix_data_t mix = ctx->resync ? mix_encrypt_resync : mix_encrypt_normal;
+
return cfb_process(ctx, data, len, dst, mix);
}
int
-pgp_cfb_decrypt(PGP_CFB *ctx, const uint8 *data, int len, uint8 *dst)
+pgp_cfb_decrypt(PGP_CFB * ctx, const uint8 *data, int len, uint8 *dst)
{
- mix_data_t mix = ctx->resync ? mix_decrypt_resync : mix_decrypt_normal;
+ mix_data_t mix = ctx->resync ? mix_decrypt_resync : mix_decrypt_normal;
+
return cfb_process(ctx, data, len, dst, mix);
}
-
diff --git a/contrib/pgcrypto/pgp-compress.c b/contrib/pgcrypto/pgp-compress.c
index da0ba9a18c..d30155b28e 100644
--- a/contrib/pgcrypto/pgp-compress.c
+++ b/contrib/pgcrypto/pgp-compress.c
@@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $PostgreSQL: pgsql/contrib/pgcrypto/pgp-compress.c,v 1.4 2005/07/18 17:09:01 tgl Exp $
+ * $PostgreSQL: pgsql/contrib/pgcrypto/pgp-compress.c,v 1.5 2005/10/15 02:49:06 momjian Exp $
*/
#include "postgres.h"
@@ -180,12 +180,12 @@ compress_free(void *priv)
}
static const PushFilterOps
-compress_filter = {
+ compress_filter = {
compress_init, compress_process, compress_flush, compress_free
};
int
-pgp_compress_filter(PushFilter **res, PGP_Context *ctx, PushFilter *dst)
+pgp_compress_filter(PushFilter ** res, PGP_Context * ctx, PushFilter * dst)
{
return pushf_create(res, &compress_filter, ctx, dst);
}
@@ -195,8 +195,8 @@ pgp_compress_filter(PushFilter **res, PGP_Context *ctx, PushFilter *dst)
*/
struct DecomprData
{
- int buf_len; /* = ZIP_OUT_BUF */
- int buf_data; /* available data */
+ int buf_len; /* = ZIP_OUT_BUF */
+ int buf_data; /* available data */
uint8 *pos;
z_stream stream;
int eof;
@@ -204,14 +204,14 @@ struct DecomprData
};
static int
-decompress_init(void **priv_p, void *arg, PullFilter *src)
+decompress_init(void **priv_p, void *arg, PullFilter * src)
{
PGP_Context *ctx = arg;
struct DecomprData *dec;
- int res;
+ int res;
if (ctx->compress_algo != PGP_COMPR_ZLIB
- && ctx->compress_algo != PGP_COMPR_ZIP)
+ && ctx->compress_algo != PGP_COMPR_ZIP)
return PXE_PGP_UNSUPPORTED_COMPR;
dec = px_alloc(sizeof(*dec));
@@ -232,15 +232,16 @@ decompress_init(void **priv_p, void *arg, PullFilter *src)
px_debug("decompress_init: inflateInit error");
return PXE_PGP_COMPRESSION_ERROR;
}
-
+
return 0;
}
-static int decompress_read(void *priv, PullFilter *src, int len,
- uint8 **data_p, uint8 *buf, int buflen)
+static int
+decompress_read(void *priv, PullFilter * src, int len,
+ uint8 **data_p, uint8 *buf, int buflen)
{
- int res;
- int flush;
+ int res;
+ int flush;
struct DecomprData *dec = priv;
restart:
@@ -256,24 +257,26 @@ restart:
if (dec->eof)
return 0;
-
- if (dec->stream.avail_in == 0) {
- uint8 *tmp;
+
+ if (dec->stream.avail_in == 0)
+ {
+ uint8 *tmp;
+
res = pullf_read(src, 8192, &tmp);
if (res < 0)
return res;
dec->stream.next_in = tmp;
dec->stream.avail_in = res;
}
-
+
dec->stream.next_out = dec->buf;
dec->stream.avail_out = dec->buf_len;
dec->pos = dec->buf;
/*
- * Z_SYNC_FLUSH is tell zlib to output as much as possible.
- * It should do it anyway (Z_NO_FLUSH), but seems to reserve
- * the right not to. So lets follow the API.
+ * Z_SYNC_FLUSH is tell zlib to output as much as possible. It should do
+ * it anyway (Z_NO_FLUSH), but seems to reserve the right not to. So lets
+ * follow the API.
*/
flush = dec->stream.avail_in ? Z_SYNC_FLUSH : Z_FINISH;
res = inflate(&dec->stream, flush);
@@ -289,39 +292,38 @@ restart:
goto restart;
}
-static void decompress_free(void *priv)
+static void
+decompress_free(void *priv)
{
struct DecomprData *dec = priv;
+
inflateEnd(&dec->stream);
memset(dec, 0, sizeof(*dec));
px_free(dec);
}
static const PullFilterOps
-decompress_filter = {
+ decompress_filter = {
decompress_init, decompress_read, decompress_free
};
int
-pgp_decompress_filter(PullFilter **res, PGP_Context *ctx, PullFilter *src)
+pgp_decompress_filter(PullFilter ** res, PGP_Context * ctx, PullFilter * src)
{
return pullf_create(res, &decompress_filter, ctx, src);
}
-
-#else /* DISABLE_ZLIB */
+#else /* DISABLE_ZLIB */
int
-pgp_compress_filter(PushFilter **res, PGP_Context *ctx, PushFilter *dst)
+pgp_compress_filter(PushFilter ** res, PGP_Context * ctx, PushFilter * dst)
{
return PXE_PGP_UNSUPPORTED_COMPR;
}
int
-pgp_decompress_filter(PullFilter **res, PGP_Context *ctx, PullFilter *src)
+pgp_decompress_filter(PullFilter ** res, PGP_Context * ctx, PullFilter * src)
{
return PXE_PGP_UNSUPPORTED_COMPR;
}
#endif
-
-
diff --git a/contrib/pgcrypto/pgp-decrypt.c b/contrib/pgcrypto/pgp-decrypt.c
index 16ae78200b..63f832e2ce 100644
--- a/contrib/pgcrypto/pgp-decrypt.c
+++ b/contrib/pgcrypto/pgp-decrypt.c
@@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $PostgreSQL: pgsql/contrib/pgcrypto/pgp-decrypt.c,v 1.5 2005/09/24 19:14:04 tgl Exp $
+ * $PostgreSQL: pgsql/contrib/pgcrypto/pgp-decrypt.c,v 1.6 2005/10/15 02:49:06 momjian Exp $
*/
#include "postgres.h"
@@ -80,7 +80,7 @@ parse_new_len(PullFilter * src, int *len_p)
len = 1 << (b & 0x1F);
pkttype = PKT_STREAM;
}
-
+
if (len < 0 || len > MAX_CHUNK)
{
px_debug("parse_new_len: weird length");
@@ -130,7 +130,7 @@ pgp_parse_pkt_hdr(PullFilter * src, uint8 *tag, int *len_p, int allow_ctx)
{
int lentype;
int res;
- uint8 *p;
+ uint8 *p;
/* EOF is normal here, thus we dont use GETBYTE */
res = pullf_read(src, 1, &p);
@@ -165,15 +165,17 @@ pgp_parse_pkt_hdr(PullFilter * src, uint8 *tag, int *len_p, int allow_ctx)
/*
* Packet reader
*/
-struct PktData {
- int type;
- int len;
+struct PktData
+{
+ int type;
+ int len;
};
-static int pktreader_pull(void *priv, PullFilter *src, int len,
- uint8 **data_p, uint8 *buf, int buflen)
+static int
+pktreader_pull(void *priv, PullFilter * src, int len,
+ uint8 **data_p, uint8 *buf, int buflen)
{
- int res;
+ int res;
struct PktData *pkt = priv;
/* PKT_CONTEXT means: whatever there is */
@@ -207,6 +209,7 @@ static void
pktreader_free(void *priv)
{
struct PktData *pkt = priv;
+
memset(pkt, 0, sizeof(*pkt));
px_free(pkt);
}
@@ -217,11 +220,12 @@ static struct PullFilterOps pktreader_filter = {
/* needs helper function to pass several parameters */
int
-pgp_create_pkt_reader(PullFilter **pf_p, PullFilter *src, int len,
- int pkttype, PGP_Context *ctx)
+pgp_create_pkt_reader(PullFilter ** pf_p, PullFilter * src, int len,
+ int pkttype, PGP_Context * ctx)
{
- int res;
+ int res;
struct PktData *pkt = px_alloc(sizeof(*pkt));
+
pkt->type = pkttype;
pkt->len = len;
res = pullf_create(pf_p, &pktreader_filter, pkt, src);
@@ -234,13 +238,14 @@ pgp_create_pkt_reader(PullFilter **pf_p, PullFilter *src, int len,
* Prefix check filter
*/
-static int prefix_init(void **priv_p, void *arg, PullFilter *src)
+static int
+prefix_init(void **priv_p, void *arg, PullFilter * src)
{
PGP_Context *ctx = arg;
- int len;
- int res;
- uint8 *buf;
- uint8 tmpbuf[PGP_MAX_BLOCK + 2];
+ int len;
+ int res;
+ uint8 *buf;
+ uint8 tmpbuf[PGP_MAX_BLOCK + 2];
len = pgp_get_cipher_block_size(ctx->cipher_algo);
if (len > sizeof(tmpbuf))
@@ -259,20 +264,19 @@ static int prefix_init(void **priv_p, void *arg, PullFilter *src)
if (buf[len - 2] != buf[len] || buf[len - 1] != buf[len + 1])
{
px_debug("prefix_init: corrupt prefix");
+
/*
- * The original purpose of the 2-byte check was
- * to show user a friendly "wrong key" message.
- * This made following possible:
+ * The original purpose of the 2-byte check was to show user a
+ * friendly "wrong key" message. This made following possible:
*
- * "An Attack on CFB Mode Encryption As Used By OpenPGP"
- * by Serge Mister and Robert Zuccherato
+ * "An Attack on CFB Mode Encryption As Used By OpenPGP" by Serge Mister
+ * and Robert Zuccherato
*
- * To avoid being 'oracle', we delay reporting, which
- * basically means we prefer to run into corrupt packet
- * header.
+ * To avoid being 'oracle', we delay reporting, which basically means we
+ * prefer to run into corrupt packet header.
*
- * We _could_ throw PXE_PGP_CORRUPT_DATA here, but
- * there is possibility of attack via timing, so we don't.
+ * We _could_ throw PXE_PGP_CORRUPT_DATA here, but there is possibility
+ * of attack via timing, so we don't.
*/
ctx->corrupt_prefix = 1;
}
@@ -289,9 +293,10 @@ static struct PullFilterOps prefix_filter = {
* Decrypt filter
*/
-static int decrypt_init(void **priv_p, void *arg, PullFilter *src)
+static int
+decrypt_init(void **priv_p, void *arg, PullFilter * src)
{
- PGP_CFB *cfb = arg;
+ PGP_CFB *cfb = arg;
*priv_p = cfb;
@@ -299,15 +304,17 @@ static int decrypt_init(void **priv_p, void *arg, PullFilter *src)
return 4096;
}
-static int decrypt_read(void *priv, PullFilter *src, int len,
- uint8 **data_p, uint8 *buf, int buflen)
+static int
+decrypt_read(void *priv, PullFilter * src, int len,
+ uint8 **data_p, uint8 *buf, int buflen)
{
- PGP_CFB *cfb = priv;
- uint8 *tmp;
- int res;
+ PGP_CFB *cfb = priv;
+ uint8 *tmp;
+ int res;
res = pullf_read(src, len, &tmp);
- if (res > 0) {
+ if (res > 0)
+ {
pgp_cfb_decrypt(cfb, tmp, res, buf);
*data_p = buf;
}
@@ -323,28 +330,33 @@ struct PullFilterOps pgp_decrypt_filter = {
* MDC hasher filter
*/
-static int mdc_init(void **priv_p, void *arg, PullFilter *src)
+static int
+mdc_init(void **priv_p, void *arg, PullFilter * src)
{
PGP_Context *ctx = arg;
+
*priv_p = ctx;
return pgp_load_digest(PGP_DIGEST_SHA1, &ctx->mdc_ctx);
}
-static void mdc_free(void *priv)
+static void
+mdc_free(void *priv)
{
PGP_Context *ctx = priv;
+
if (ctx->use_mdcbuf_filter)
return;
px_md_free(ctx->mdc_ctx);
ctx->mdc_ctx = NULL;
}
-static int mdc_finish(PGP_Context *ctx, PullFilter *src,
- int len, uint8 **data_p)
+static int
+mdc_finish(PGP_Context * ctx, PullFilter * src,
+ int len, uint8 **data_p)
{
- int res;
- uint8 hash[20];
- uint8 tmpbuf[22];
+ int res;
+ uint8 hash[20];
+ uint8 tmpbuf[22];
if (len + 1 > sizeof(tmpbuf))
return PXE_BUG;
@@ -362,7 +374,7 @@ static int mdc_finish(PGP_Context *ctx, PullFilter *src,
}
return 0;
}
-
+
/* safety check */
if (ctx->in_mdc_pkt > 1)
{
@@ -370,14 +382,14 @@ static int mdc_finish(PGP_Context *ctx, PullFilter *src,
return PXE_PGP_CORRUPT_DATA;
}
ctx->in_mdc_pkt++;
-
+
/* is the packet sane? */
if (res != 20)
{
px_debug("mdc_finish: read failed, res=%d", res);
return PXE_PGP_CORRUPT_DATA;
}
-
+
/*
* ok, we got the hash, now check
*/
@@ -394,10 +406,11 @@ static int mdc_finish(PGP_Context *ctx, PullFilter *src,
return len;
}
-static int mdc_read(void *priv, PullFilter *src, int len,
- uint8 **data_p, uint8 *buf, int buflen)
+static int
+mdc_read(void *priv, PullFilter * src, int len,
+ uint8 **data_p, uint8 *buf, int buflen)
{
- int res;
+ int res;
PGP_Context *ctx = priv;
/* skip this filter? */
@@ -434,18 +447,20 @@ static struct PullFilterOps mdc_filter = {
* packet, which is silly.
*/
#define MDCBUF_LEN 8192
-struct MDCBufData {
+struct MDCBufData
+{
PGP_Context *ctx;
- int eof;
- int buflen;
- int avail;
- uint8 *pos;
- int mdc_avail;
- uint8 mdc_buf[22];
- uint8 buf[MDCBUF_LEN];
+ int eof;
+ int buflen;
+ int avail;
+ uint8 *pos;
+ int mdc_avail;
+ uint8 mdc_buf[22];
+ uint8 buf[MDCBUF_LEN];
};
-static int mdcbuf_init(void **priv_p, void *arg, PullFilter *src)
+static int
+mdcbuf_init(void **priv_p, void *arg, PullFilter * src)
{
PGP_Context *ctx = arg;
struct MDCBufData *st;
@@ -462,10 +477,11 @@ static int mdcbuf_init(void **priv_p, void *arg, PullFilter *src)
return 0;
}
-static int mdcbuf_finish(struct MDCBufData *st)
+static int
+mdcbuf_finish(struct MDCBufData * st)
{
- uint8 hash[20];
- int res;
+ uint8 hash[20];
+ int res;
st->eof = 1;
@@ -486,25 +502,29 @@ static int mdcbuf_finish(struct MDCBufData *st)
return res;
}
-static void mdcbuf_load_data(struct MDCBufData *st, uint8 *src, int len)
+static void
+mdcbuf_load_data(struct MDCBufData * st, uint8 *src, int len)
{
- uint8 *dst = st->pos + st->avail;
+ uint8 *dst = st->pos + st->avail;
+
memcpy(dst, src, len);
px_md_update(st->ctx->mdc_ctx, src, len);
st->avail += len;
}
-static void mdcbuf_load_mdc(struct MDCBufData *st, uint8 *src, int len)
+static void
+mdcbuf_load_mdc(struct MDCBufData * st, uint8 *src, int len)
{
memmove(st->mdc_buf + st->mdc_avail, src, len);
st->mdc_avail += len;
}
-static int mdcbuf_refill(struct MDCBufData *st, PullFilter *src)
+static int
+mdcbuf_refill(struct MDCBufData * st, PullFilter * src)
{
- uint8 *data;
- int res;
- int need;
+ uint8 *data;
+ int res;
+ int need;
/* put avail data in start */
if (st->avail > 0 && st->pos != st->buf)
@@ -530,7 +550,8 @@ static int mdcbuf_refill(struct MDCBufData *st, PullFilter *src)
}
else
{
- int canmove = st->mdc_avail + res - 22;
+ int canmove = st->mdc_avail + res - 22;
+
if (canmove > 0)
{
mdcbuf_load_data(st, st->mdc_buf, canmove);
@@ -542,11 +563,12 @@ static int mdcbuf_refill(struct MDCBufData *st, PullFilter *src)
return 0;
}
-static int mdcbuf_read(void *priv, PullFilter *src, int len,
- uint8 **data_p, uint8 *buf, int buflen)
+static int
+mdcbuf_read(void *priv, PullFilter * src, int len,
+ uint8 **data_p, uint8 *buf, int buflen)
{
struct MDCBufData *st = priv;
- int res;
+ int res;
if (!st->eof && len > st->avail)
{
@@ -568,6 +590,7 @@ static void
mdcbuf_free(void *priv)
{
struct MDCBufData *st = priv;
+
px_md_free(st->ctx->mdc_ctx);
st->ctx->mdc_ctx = NULL;
memset(st, 0, sizeof(*st));
@@ -583,29 +606,30 @@ static struct PullFilterOps mdcbuf_filter = {
* Decrypt separate session key
*/
static int
-decrypt_key(PGP_Context *ctx, const uint8 *src, int len)
+decrypt_key(PGP_Context * ctx, const uint8 *src, int len)
{
- int res;
- uint8 algo;
- PGP_CFB *cfb;
-
+ int res;
+ uint8 algo;
+ PGP_CFB *cfb;
+
res = pgp_cfb_create(&cfb, ctx->s2k_cipher_algo,
- ctx->s2k.key, ctx->s2k.key_len, 0, NULL);
+ ctx->s2k.key, ctx->s2k.key_len, 0, NULL);
if (res < 0)
return res;
pgp_cfb_decrypt(cfb, src, 1, &algo);
- src ++;
- len --;
+ src++;
+ len--;
pgp_cfb_decrypt(cfb, src, len, ctx->sess_key);
pgp_cfb_free(cfb);
ctx->sess_key_len = len;
ctx->cipher_algo = algo;
- if (pgp_get_cipher_key_size(algo) != len) {
+ if (pgp_get_cipher_key_size(algo) != len)
+ {
px_debug("sesskey bad len: algo=%d, expected=%d, got=%d",
- algo, pgp_get_cipher_key_size(algo), len);
+ algo, pgp_get_cipher_key_size(algo), len);
return PXE_PGP_CORRUPT_DATA;
}
return 0;
@@ -643,7 +667,7 @@ parse_symenc_sesskey(PGP_Context * ctx, PullFilter * src)
* generate key from password
*/
res = pgp_s2k_process(&ctx->s2k, ctx->s2k_cipher_algo,
- ctx->sym_key, ctx->sym_key_len);
+ ctx->sym_key, ctx->sym_key_len);
if (res < 0)
return res;
@@ -684,21 +708,23 @@ parse_symenc_sesskey(PGP_Context * ctx, PullFilter * src)
}
static int
-copy_crlf(MBuf *dst, uint8 *data, int len, int *got_cr)
+copy_crlf(MBuf * dst, uint8 *data, int len, int *got_cr)
{
- uint8 *data_end = data + len;
- uint8 tmpbuf[1024];
- uint8 *tmp_end = tmpbuf + sizeof(tmpbuf);
- uint8 *p;
- int res;
+ uint8 *data_end = data + len;
+ uint8 tmpbuf[1024];
+ uint8 *tmp_end = tmpbuf + sizeof(tmpbuf);
+ uint8 *p;
+ int res;
p = tmpbuf;
- if (*got_cr) {
+ if (*got_cr)
+ {
if (*data != '\n')
*p++ = '\r';
*got_cr = 0;
}
- while (data < data_end) {
+ while (data < data_end)
+ {
if (*data == '\r')
{
if (data + 1 < data_end)
@@ -779,8 +805,9 @@ parse_literal_data(PGP_Context * ctx, MBuf * dst, PullFilter * pkt)
ctx->unicode_mode = (type == 'u') ? 1 : 0;
/* read data */
- while (1) {
- res = pullf_read(pkt, 32*1024, &buf);
+ while (1)
+ {
+ res = pullf_read(pkt, 32 * 1024, &buf);
if (res <= 0)
break;
@@ -797,8 +824,8 @@ parse_literal_data(PGP_Context * ctx, MBuf * dst, PullFilter * pkt)
}
/* process_data_packets and parse_compressed_data call each other */
-static int process_data_packets(PGP_Context * ctx, MBuf * dst,
- PullFilter * src, int allow_compr, int need_mdc);
+static int process_data_packets(PGP_Context * ctx, MBuf * dst,
+ PullFilter * src, int allow_compr, int need_mdc);
static int
parse_compressed_data(PGP_Context * ctx, MBuf * dst, PullFilter * pkt)
@@ -822,7 +849,7 @@ parse_compressed_data(PGP_Context * ctx, MBuf * dst, PullFilter * pkt)
if (res >= 0)
{
res = process_data_packets(ctx, dst, pf_decompr,
- NO_COMPR, NO_MDC);
+ NO_COMPR, NO_MDC);
pullf_free(pf_decompr);
}
break;
@@ -850,7 +877,7 @@ process_data_packets(PGP_Context * ctx, MBuf * dst, PullFilter * src,
int got_data = 0;
int got_mdc = 0;
PullFilter *pkt = NULL;
- uint8 *tmp;
+ uint8 *tmp;
while (1)
{
@@ -951,12 +978,12 @@ static int
parse_symenc_data(PGP_Context * ctx, PullFilter * pkt, MBuf * dst)
{
int res;
- PGP_CFB *cfb = NULL;
+ PGP_CFB *cfb = NULL;
PullFilter *pf_decrypt = NULL;
PullFilter *pf_prefix = NULL;
res = pgp_cfb_create(&cfb, ctx->cipher_algo,
- ctx->sess_key, ctx->sess_key_len, 1, NULL);
+ ctx->sess_key, ctx->sess_key_len, 1, NULL);
if (res < 0)
goto out;
@@ -985,11 +1012,11 @@ static int
parse_symenc_mdc_data(PGP_Context * ctx, PullFilter * pkt, MBuf * dst)
{
int res;
- PGP_CFB *cfb = NULL;
+ PGP_CFB *cfb = NULL;
PullFilter *pf_decrypt = NULL;
PullFilter *pf_prefix = NULL;
PullFilter *pf_mdc = NULL;
- uint8 ver;
+ uint8 ver;
GETBYTE(pkt, ver);
if (ver != 1)
@@ -999,7 +1026,7 @@ parse_symenc_mdc_data(PGP_Context * ctx, PullFilter * pkt, MBuf * dst)
}
res = pgp_cfb_create(&cfb, ctx->cipher_algo,
- ctx->sess_key, ctx->sess_key_len, 0, NULL);
+ ctx->sess_key, ctx->sess_key_len, 0, NULL);
if (res < 0)
goto out;
@@ -1034,49 +1061,52 @@ out:
* skip over packet contents
*/
int
-pgp_skip_packet(PullFilter *pkt)
+pgp_skip_packet(PullFilter * pkt)
{
- int res = 1;
- uint8 *tmp;
- while (res > 0)
- res = pullf_read(pkt, 32*1024, &tmp);
- return res < 0 ? res : 0;
+ int res = 1;
+ uint8 *tmp;
+
+ while (res > 0)
+ res = pullf_read(pkt, 32 * 1024, &tmp);
+ return res < 0 ? res : 0;
}
/*
* expect to be at packet end, any data is error
*/
int
-pgp_expect_packet_end(PullFilter *pkt)
+pgp_expect_packet_end(PullFilter * pkt)
{
- int res = 1;
- uint8 *tmp;
- while (res > 0)
+ int res = 1;
+ uint8 *tmp;
+
+ while (res > 0)
{
- res = pullf_read(pkt, 32*1024, &tmp);
+ res = pullf_read(pkt, 32 * 1024, &tmp);
if (res > 0)
{
px_debug("pgp_expect_packet_end: got data");
return PXE_PGP_CORRUPT_DATA;
}
}
- return res < 0 ? res : 0;
+ return res < 0 ? res : 0;
}
int
pgp_decrypt(PGP_Context * ctx, MBuf * msrc, MBuf * mdst)
{
- int res;
+ int res;
PullFilter *src = NULL;
PullFilter *pkt = NULL;
- uint8 tag;
- int len;
- int got_key = 0;
- int got_data = 0;
+ uint8 tag;
+ int len;
+ int got_key = 0;
+ int got_data = 0;
res = pullf_create_mbuf_reader(&src, msrc);
- while (res >= 0) {
+ while (res >= 0)
+ {
res = pgp_parse_pkt_hdr(src, &tag, &len, NO_CTX_SIZE);
if (res <= 0)
break;
@@ -1086,7 +1116,8 @@ pgp_decrypt(PGP_Context * ctx, MBuf * msrc, MBuf * mdst)
break;
res = PXE_PGP_CORRUPT_DATA;
- switch (tag) {
+ switch (tag)
+ {
case PGP_PKT_MARKER:
res = pgp_skip_packet(pkt);
break;
@@ -1097,10 +1128,11 @@ pgp_decrypt(PGP_Context * ctx, MBuf * msrc, MBuf * mdst)
break;
case PGP_PKT_SYMENCRYPTED_SESSKEY:
if (got_key)
- /* Theoretically, there could be several keys,
- * both public and symmetric, all of which
- * encrypt same session key. Decrypt should try
- * with each one, before failing.
+
+ /*
+ * Theoretically, there could be several keys, both public
+ * and symmetric, all of which encrypt same session key.
+ * Decrypt should try with each one, before failing.
*/
px_debug("pgp_decrypt: using first of several keys");
else
@@ -1154,4 +1186,3 @@ pgp_decrypt(PGP_Context * ctx, MBuf * msrc, MBuf * mdst)
return res;
}
-
diff --git a/contrib/pgcrypto/pgp-encrypt.c b/contrib/pgcrypto/pgp-encrypt.c
index 06f46efc62..e2c928154b 100644
--- a/contrib/pgcrypto/pgp-encrypt.c
+++ b/contrib/pgcrypto/pgp-encrypt.c
@@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $PostgreSQL: pgsql/contrib/pgcrypto/pgp-encrypt.c,v 1.2 2005/07/11 15:07:59 tgl Exp $
+ * $PostgreSQL: pgsql/contrib/pgcrypto/pgp-encrypt.c,v 1.3 2005/10/15 02:49:06 momjian Exp $
*/
#include "postgres.h"
@@ -65,9 +65,11 @@ render_newlen(uint8 *h, int len)
return h;
}
-static int write_tag_only(PushFilter *dst, int tag)
+static int
+write_tag_only(PushFilter * dst, int tag)
{
- uint8 hdr = 0xC0 | tag;
+ uint8 hdr = 0xC0 | tag;
+
return pushf_write(dst, &hdr, 1);
}
@@ -121,7 +123,7 @@ mdc_flush(PushFilter * dst, void *priv)
* create mdc pkt
*/
pkt[0] = 0xD3;
- pkt[1] = 0x14; /* MDC_DIGEST_LEN */
+ pkt[1] = 0x14; /* MDC_DIGEST_LEN */
px_md_update(md, pkt, 2);
px_md_finish(md, pkt + 2);
@@ -150,7 +152,7 @@ static const PushFilterOps mdc_filter = {
struct EncStat
{
PGP_CFB *ciph;
- uint8 buf[ENCBUF];
+ uint8 buf[ENCBUF];
};
static int
@@ -158,28 +160,29 @@ encrypt_init(PushFilter * next, void *init_arg, void **priv_p)
{
struct EncStat *st;
PGP_Context *ctx = init_arg;
- PGP_CFB *ciph;
- int resync = 1;
- int res;
+ PGP_CFB *ciph;
+ int resync = 1;
+ int res;
/* should we use newer packet format? */
if (ctx->disable_mdc == 0)
{
- uint8 ver = 1;
+ uint8 ver = 1;
+
resync = 0;
res = pushf_write(next, &ver, 1);
if (res < 0)
return res;
}
res = pgp_cfb_create(&ciph, ctx->cipher_algo,
- ctx->sess_key, ctx->sess_key_len, resync, NULL);
+ ctx->sess_key, ctx->sess_key_len, resync, NULL);
if (res < 0)
return res;
st = px_alloc(sizeof(*st));
memset(st, 0, sizeof(*st));
st->ciph = ciph;
-
+
*priv_p = st;
return ENCBUF;
}
@@ -189,11 +192,12 @@ encrypt_process(PushFilter * next, void *priv, const uint8 *data, int len)
{
int res;
struct EncStat *st = priv;
- int avail = len;
+ int avail = len;
while (avail > 0)
{
- int tmplen = avail > ENCBUF ? ENCBUF : avail;
+ int tmplen = avail > ENCBUF ? ENCBUF : avail;
+
res = pgp_cfb_encrypt(st->ciph, data, tmplen, st->buf);
if (res < 0)
return res;
@@ -303,9 +307,11 @@ static const PushFilterOps pkt_stream_filter = {
pkt_stream_init, pkt_stream_process, pkt_stream_flush, pkt_stream_free
};
-int pgp_create_pkt_writer(PushFilter *dst, int tag, PushFilter **res_p)
+int
+pgp_create_pkt_writer(PushFilter * dst, int tag, PushFilter ** res_p)
{
- int res;
+ int res;
+
res = write_tag_only(dst, tag);
if (res < 0)
return res;
@@ -320,17 +326,19 @@ int pgp_create_pkt_writer(PushFilter *dst, int tag, PushFilter **res_p)
static int
crlf_process(PushFilter * dst, void *priv, const uint8 *data, int len)
{
- const uint8 * data_end = data + len;
- const uint8 * p2, * p1 = data;
- int line_len;
- static const uint8 crlf[] = { '\r', '\n' };
- int res = 0;
+ const uint8 *data_end = data + len;
+ const uint8 *p2,
+ *p1 = data;
+ int line_len;
+ static const uint8 crlf[] = {'\r', '\n'};
+ int res = 0;
+
while (p1 < data_end)
{
p2 = memchr(p1, '\n', data_end - p1);
if (p2 == NULL)
p2 = data_end;
-
+
line_len = p2 - p1;
/* write data */
@@ -363,13 +371,13 @@ static const PushFilterOps crlf_filter = {
* Initialize literal data packet
*/
static int
-init_litdata_packet(PushFilter **pf_res, PGP_Context *ctx, PushFilter *dst)
+init_litdata_packet(PushFilter ** pf_res, PGP_Context * ctx, PushFilter * dst)
{
int res;
int hdrlen;
uint8 hdr[6];
uint32 t;
- PushFilter *pkt;
+ PushFilter *pkt;
int type;
/*
@@ -382,10 +390,10 @@ init_litdata_packet(PushFilter **pf_res, PGP_Context *ctx, PushFilter *dst)
type = 'b';
/*
- * Store the creation time into packet.
- * The goal is to have as few known bytes as possible.
+ * Store the creation time into packet. The goal is to have as few known
+ * bytes as possible.
*/
- t = (uint32)time(NULL);
+ t = (uint32) time(NULL);
hdr[0] = type;
hdr[1] = 0;
@@ -418,10 +426,10 @@ init_litdata_packet(PushFilter **pf_res, PGP_Context *ctx, PushFilter *dst)
* Initialize compression filter
*/
static int
-init_compress(PushFilter **pf_res, PGP_Context *ctx, PushFilter *dst)
+init_compress(PushFilter ** pf_res, PGP_Context * ctx, PushFilter * dst)
{
- int res;
- uint8 type = ctx->compress_algo;
+ int res;
+ uint8 type = ctx->compress_algo;
PushFilter *pkt;
res = write_tag_only(dst, PGP_PKT_COMPRESSED_DATA);
@@ -446,7 +454,7 @@ init_compress(PushFilter **pf_res, PGP_Context *ctx, PushFilter *dst)
* Initialize encdata packet
*/
static int
-init_encdata_packet(PushFilter **pf_res, PGP_Context *ctx, PushFilter *dst)
+init_encdata_packet(PushFilter ** pf_res, PGP_Context * ctx, PushFilter * dst)
{
int res;
int tag;
@@ -467,7 +475,7 @@ init_encdata_packet(PushFilter **pf_res, PGP_Context *ctx, PushFilter *dst)
* write prefix
*/
static int
-write_prefix(PGP_Context *ctx, PushFilter * dst)
+write_prefix(PGP_Context * ctx, PushFilter * dst)
{
uint8 prefix[PGP_MAX_BLOCK + 2];
int res,
@@ -491,17 +499,17 @@ write_prefix(PGP_Context *ctx, PushFilter * dst)
*/
static int
-symencrypt_sesskey(PGP_Context *ctx, uint8 *dst)
+symencrypt_sesskey(PGP_Context * ctx, uint8 *dst)
{
- int res;
- PGP_CFB *cfb;
- uint8 algo = ctx->cipher_algo;
+ int res;
+ PGP_CFB *cfb;
+ uint8 algo = ctx->cipher_algo;
res = pgp_cfb_create(&cfb, ctx->s2k_cipher_algo,
- ctx->s2k.key, ctx->s2k.key_len, 0, NULL);
+ ctx->s2k.key, ctx->s2k.key_len, 0, NULL);
if (res < 0)
return res;
-
+
pgp_cfb_encrypt(cfb, &algo, 1, dst);
pgp_cfb_encrypt(cfb, ctx->sess_key, ctx->sess_key_len, dst + 1);
@@ -511,12 +519,12 @@ symencrypt_sesskey(PGP_Context *ctx, uint8 *dst)
/* 5.3: Symmetric-Key Encrypted Session-Key */
static int
-write_symenc_sesskey(PGP_Context *ctx, PushFilter *dst)
+write_symenc_sesskey(PGP_Context * ctx, PushFilter * dst)
{
uint8 pkt[256];
int pktlen;
int res;
- uint8 *p = pkt;
+ uint8 *p = pkt;
*p++ = 4; /* 5.3 - version number */
*p++ = ctx->s2k_cipher_algo;
@@ -564,13 +572,14 @@ init_s2k_key(PGP_Context * ctx)
return res;
return pgp_s2k_process(&ctx->s2k, ctx->s2k_cipher_algo,
- ctx->sym_key, ctx->sym_key_len);
+ ctx->sym_key, ctx->sym_key_len);
}
static int
-init_sess_key(PGP_Context *ctx)
+init_sess_key(PGP_Context * ctx)
{
- int res;
+ int res;
+
if (ctx->use_sess_key || ctx->pub_key)
{
ctx->sess_key_len = pgp_get_cipher_key_size(ctx->cipher_algo);
@@ -596,7 +605,8 @@ pgp_encrypt(PGP_Context * ctx, MBuf * src, MBuf * dst)
int res;
int len;
uint8 *buf;
- PushFilter *pf, *pf_tmp;
+ PushFilter *pf,
+ *pf_tmp;
/*
* do we have any key
@@ -618,7 +628,7 @@ pgp_encrypt(PGP_Context * ctx, MBuf * src, MBuf * dst)
if (res < 0)
goto out;
}
-
+
res = init_sess_key(ctx);
if (res < 0)
goto out;
@@ -674,7 +684,7 @@ pgp_encrypt(PGP_Context * ctx, MBuf * src, MBuf * dst)
goto out;
pf = pf_tmp;
-
+
/* text conversion? */
if (ctx->text_mode && ctx->convert_crlf)
{
@@ -696,4 +706,3 @@ out:
pushf_free_all(pf);
return res;
}
-
diff --git a/contrib/pgcrypto/pgp-info.c b/contrib/pgcrypto/pgp-info.c
index 89737f51f6..9f887ec6d9 100644
--- a/contrib/pgcrypto/pgp-info.c
+++ b/contrib/pgcrypto/pgp-info.c
@@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $PostgreSQL: pgsql/contrib/pgcrypto/pgp-info.c,v 1.3 2005/08/13 02:06:20 momjian Exp $
+ * $PostgreSQL: pgsql/contrib/pgcrypto/pgp-info.c,v 1.4 2005/10/15 02:49:06 momjian Exp $
*/
#include "postgres.h"
@@ -34,9 +34,10 @@
#include "mbuf.h"
#include "pgp.h"
-static int read_pubkey_keyid(PullFilter *pkt, uint8 *keyid_buf)
+static int
+read_pubkey_keyid(PullFilter * pkt, uint8 *keyid_buf)
{
- int res;
+ int res;
PGP_PubKey *pk = NULL;
res = _pgp_read_public_key(pkt, &pk);
@@ -66,10 +67,11 @@ err:
return res;
}
-static int read_pubenc_keyid(PullFilter *pkt, uint8 *keyid_buf)
+static int
+read_pubenc_keyid(PullFilter * pkt, uint8 *keyid_buf)
{
- uint8 ver;
- int res;
+ uint8 ver;
+ int res;
GETBYTE(pkt, ver);
if (ver != 3)
@@ -87,45 +89,50 @@ static const char hextbl[] = "0123456789ABCDEF";
static int
print_key(uint8 *keyid, char *dst)
{
- int i;
- unsigned c;
- for (i = 0; i < 8; i++) {
+ int i;
+ unsigned c;
+
+ for (i = 0; i < 8; i++)
+ {
c = keyid[i];
*dst++ = hextbl[(c >> 4) & 0x0F];
*dst++ = hextbl[c & 0x0F];
}
*dst = 0;
- return 8*2;
+ return 8 * 2;
}
-static const uint8 any_key[] =
-{ 0, 0, 0, 0, 0, 0, 0, 0 };
+static const uint8 any_key[] =
+{0, 0, 0, 0, 0, 0, 0, 0};
/*
* dst should have room for 17 bytes
*/
int
-pgp_get_keyid(MBuf *pgp_data, char *dst)
+pgp_get_keyid(MBuf * pgp_data, char *dst)
{
- int res;
+ int res;
PullFilter *src;
PullFilter *pkt = NULL;
- int len;
- uint8 tag;
- int got_pub_key=0, got_symenc_key=0, got_pubenc_key=0;
- int got_data=0;
- uint8 keyid_buf[8];
- int got_main_key=0;
+ int len;
+ uint8 tag;
+ int got_pub_key = 0,
+ got_symenc_key = 0,
+ got_pubenc_key = 0;
+ int got_data = 0;
+ uint8 keyid_buf[8];
+ int got_main_key = 0;
res = pullf_create_mbuf_reader(&src, pgp_data);
if (res < 0)
return res;
- while (1) {
+ while (1)
+ {
res = pgp_parse_pkt_hdr(src, &tag, &len, 0);
if (res <= 0)
- break;
+ break;
res = pgp_create_pkt_reader(&pkt, src, len, res, NULL);
if (res < 0)
break;
@@ -226,4 +233,3 @@ pgp_get_keyid(MBuf *pgp_data, char *dst)
return res;
}
-
diff --git a/contrib/pgcrypto/pgp-mpi-internal.c b/contrib/pgcrypto/pgp-mpi-internal.c
index 5cdc0e1b9d..3a81ed46a7 100644
--- a/contrib/pgcrypto/pgp-mpi-internal.c
+++ b/contrib/pgcrypto/pgp-mpi-internal.c
@@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $PostgreSQL: pgsql/contrib/pgcrypto/pgp-mpi-internal.c,v 1.3 2005/08/13 02:06:20 momjian Exp $
+ * $PostgreSQL: pgsql/contrib/pgcrypto/pgp-mpi-internal.c,v 1.4 2005/10/15 02:49:06 momjian Exp $
*/
#include "postgres.h"
@@ -35,27 +35,27 @@
#include "pgp.h"
int
-pgp_elgamal_encrypt(PGP_PubKey *pk, PGP_MPI *_m,
- PGP_MPI **c1_p, PGP_MPI **c2_p)
+pgp_elgamal_encrypt(PGP_PubKey * pk, PGP_MPI * _m,
+ PGP_MPI ** c1_p, PGP_MPI ** c2_p)
{
return PXE_PGP_NO_BIGNUM;
}
int
-pgp_elgamal_decrypt(PGP_PubKey *pk, PGP_MPI *_c1, PGP_MPI *_c2,
- PGP_MPI **msg_p)
+pgp_elgamal_decrypt(PGP_PubKey * pk, PGP_MPI * _c1, PGP_MPI * _c2,
+ PGP_MPI ** msg_p)
{
return PXE_PGP_NO_BIGNUM;
}
-int pgp_rsa_encrypt(PGP_PubKey *pk, PGP_MPI *m, PGP_MPI **c)
+int
+pgp_rsa_encrypt(PGP_PubKey * pk, PGP_MPI * m, PGP_MPI ** c)
{
return PXE_PGP_NO_BIGNUM;
}
-int pgp_rsa_decrypt(PGP_PubKey *pk, PGP_MPI *c, PGP_MPI **m)
+int
+pgp_rsa_decrypt(PGP_PubKey * pk, PGP_MPI * c, PGP_MPI ** m)
{
return PXE_PGP_NO_BIGNUM;
}
-
-
diff --git a/contrib/pgcrypto/pgp-mpi-openssl.c b/contrib/pgcrypto/pgp-mpi-openssl.c
index 3ae40ee075..0e692e35d2 100644
--- a/contrib/pgcrypto/pgp-mpi-openssl.c
+++ b/contrib/pgcrypto/pgp-mpi-openssl.c
@@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $PostgreSQL: pgsql/contrib/pgcrypto/pgp-mpi-openssl.c,v 1.3 2005/08/13 02:06:20 momjian Exp $
+ * $PostgreSQL: pgsql/contrib/pgcrypto/pgp-mpi-openssl.c,v 1.4 2005/10/15 02:49:06 momjian Exp $
*/
#include "postgres.h"
@@ -37,15 +37,16 @@
#include "pgp.h"
static BIGNUM *
-mpi_to_bn(PGP_MPI *n)
+mpi_to_bn(PGP_MPI * n)
{
- BIGNUM *bn = BN_bin2bn(n->data, n->bytes, NULL);
+ BIGNUM *bn = BN_bin2bn(n->data, n->bytes, NULL);
+
if (!bn)
return NULL;
if (BN_num_bits(bn) != n->bits)
{
px_debug("mpi_to_bn: bignum conversion failed: mpi=%d, bn=%d",
- n->bits, BN_num_bits(bn));
+ n->bits, BN_num_bits(bn));
BN_clear_free(bn);
return NULL;
}
@@ -55,8 +56,8 @@ mpi_to_bn(PGP_MPI *n)
static PGP_MPI *
bn_to_mpi(BIGNUM *bn)
{
- int res;
- PGP_MPI *n;
+ int res;
+ PGP_MPI *n;
res = pgp_mpi_alloc(BN_num_bits(bn), &n);
if (res < 0)
@@ -65,7 +66,7 @@ bn_to_mpi(BIGNUM *bn)
if (BN_num_bytes(bn) != n->bytes)
{
px_debug("bn_to_mpi: bignum conversion failed: bn=%d, mpi=%d",
- BN_num_bytes(bn), n->bytes);
+ BN_num_bytes(bn), n->bytes);
pgp_mpi_free(n);
return NULL;
}
@@ -81,7 +82,7 @@ bn_to_mpi(BIGNUM *bn)
*
* Until I research it further, I just mimic gpg behaviour.
* It has a special mapping table, for values <= 5120,
- * above that it uses 'arbitrary high number'. Following
+ * above that it uses 'arbitrary high number'. Following
* algorihm hovers 10-70 bits above gpg values. And for
* larger p, it uses gpg's algorihm.
*
@@ -98,20 +99,20 @@ decide_k_bits(int p_bits)
}
int
-pgp_elgamal_encrypt(PGP_PubKey *pk, PGP_MPI *_m,
- PGP_MPI **c1_p, PGP_MPI **c2_p)
+pgp_elgamal_encrypt(PGP_PubKey * pk, PGP_MPI * _m,
+ PGP_MPI ** c1_p, PGP_MPI ** c2_p)
{
- int res = PXE_PGP_MATH_FAILED;
- int k_bits;
- BIGNUM *m = mpi_to_bn(_m);
- BIGNUM *p = mpi_to_bn(pk->pub.elg.p);
- BIGNUM *g = mpi_to_bn(pk->pub.elg.g);
- BIGNUM *y = mpi_to_bn(pk->pub.elg.y);
- BIGNUM *k = BN_new();
- BIGNUM *yk = BN_new();
- BIGNUM *c1 = BN_new();
- BIGNUM *c2 = BN_new();
- BN_CTX *tmp = BN_CTX_new();
+ int res = PXE_PGP_MATH_FAILED;
+ int k_bits;
+ BIGNUM *m = mpi_to_bn(_m);
+ BIGNUM *p = mpi_to_bn(pk->pub.elg.p);
+ BIGNUM *g = mpi_to_bn(pk->pub.elg.g);
+ BIGNUM *y = mpi_to_bn(pk->pub.elg.y);
+ BIGNUM *k = BN_new();
+ BIGNUM *yk = BN_new();
+ BIGNUM *c1 = BN_new();
+ BIGNUM *c2 = BN_new();
+ BN_CTX *tmp = BN_CTX_new();
if (!m || !p || !g || !y || !k || !yk || !c1 || !c2 || !tmp)
goto err;
@@ -124,8 +125,7 @@ pgp_elgamal_encrypt(PGP_PubKey *pk, PGP_MPI *_m,
goto err;
/*
- * c1 = g^k
- * c2 = m * y^k
+ * c1 = g^k c2 = m * y^k
*/
if (!BN_mod_exp(c1, g, k, p, tmp))
goto err;
@@ -140,35 +140,44 @@ pgp_elgamal_encrypt(PGP_PubKey *pk, PGP_MPI *_m,
if (*c1_p && *c2_p)
res = 0;
err:
- if (tmp) BN_CTX_free(tmp);
- if (c2) BN_clear_free(c2);
- if (c1) BN_clear_free(c1);
- if (yk) BN_clear_free(yk);
- if (k) BN_clear_free(k);
- if (y) BN_clear_free(y);
- if (g) BN_clear_free(g);
- if (p) BN_clear_free(p);
- if (m) BN_clear_free(m);
+ if (tmp)
+ BN_CTX_free(tmp);
+ if (c2)
+ BN_clear_free(c2);
+ if (c1)
+ BN_clear_free(c1);
+ if (yk)
+ BN_clear_free(yk);
+ if (k)
+ BN_clear_free(k);
+ if (y)
+ BN_clear_free(y);
+ if (g)
+ BN_clear_free(g);
+ if (p)
+ BN_clear_free(p);
+ if (m)
+ BN_clear_free(m);
return res;
}
int
-pgp_elgamal_decrypt(PGP_PubKey *pk, PGP_MPI *_c1, PGP_MPI *_c2,
- PGP_MPI **msg_p)
+pgp_elgamal_decrypt(PGP_PubKey * pk, PGP_MPI * _c1, PGP_MPI * _c2,
+ PGP_MPI ** msg_p)
{
- int res = PXE_PGP_MATH_FAILED;
- BIGNUM *c1 = mpi_to_bn(_c1);
- BIGNUM *c2 = mpi_to_bn(_c2);
- BIGNUM *p = mpi_to_bn(pk->pub.elg.p);
- BIGNUM *x = mpi_to_bn(pk->sec.elg.x);
- BIGNUM *c1x = BN_new();
- BIGNUM *div = BN_new();
- BIGNUM *m = BN_new();
- BN_CTX *tmp = BN_CTX_new();
+ int res = PXE_PGP_MATH_FAILED;
+ BIGNUM *c1 = mpi_to_bn(_c1);
+ BIGNUM *c2 = mpi_to_bn(_c2);
+ BIGNUM *p = mpi_to_bn(pk->pub.elg.p);
+ BIGNUM *x = mpi_to_bn(pk->sec.elg.x);
+ BIGNUM *c1x = BN_new();
+ BIGNUM *div = BN_new();
+ BIGNUM *m = BN_new();
+ BN_CTX *tmp = BN_CTX_new();
if (!c1 || !c2 || !p || !x || !c1x || !div || !m || !tmp)
goto err;
-
+
/*
* m = c2 / (c1^x)
*/
@@ -184,26 +193,34 @@ pgp_elgamal_decrypt(PGP_PubKey *pk, PGP_MPI *_c1, PGP_MPI *_c2,
if (*msg_p)
res = 0;
err:
- if (tmp) BN_CTX_free(tmp);
- if (m) BN_clear_free(m);
- if (div) BN_clear_free(div);
- if (c1x) BN_clear_free(c1x);
- if (x) BN_clear_free(x);
- if (p) BN_clear_free(p);
- if (c2) BN_clear_free(c2);
- if (c1) BN_clear_free(c1);
+ if (tmp)
+ BN_CTX_free(tmp);
+ if (m)
+ BN_clear_free(m);
+ if (div)
+ BN_clear_free(div);
+ if (c1x)
+ BN_clear_free(c1x);
+ if (x)
+ BN_clear_free(x);
+ if (p)
+ BN_clear_free(p);
+ if (c2)
+ BN_clear_free(c2);
+ if (c1)
+ BN_clear_free(c1);
return res;
}
int
-pgp_rsa_encrypt(PGP_PubKey *pk, PGP_MPI *_m, PGP_MPI **c_p)
+pgp_rsa_encrypt(PGP_PubKey * pk, PGP_MPI * _m, PGP_MPI ** c_p)
{
- int res = PXE_PGP_MATH_FAILED;
- BIGNUM *m = mpi_to_bn(_m);
- BIGNUM *e = mpi_to_bn(pk->pub.rsa.e);
- BIGNUM *n = mpi_to_bn(pk->pub.rsa.n);
- BIGNUM *c = BN_new();
- BN_CTX *tmp = BN_CTX_new();
+ int res = PXE_PGP_MATH_FAILED;
+ BIGNUM *m = mpi_to_bn(_m);
+ BIGNUM *e = mpi_to_bn(pk->pub.rsa.e);
+ BIGNUM *n = mpi_to_bn(pk->pub.rsa.n);
+ BIGNUM *c = BN_new();
+ BN_CTX *tmp = BN_CTX_new();
if (!m || !e || !n || !c || !tmp)
goto err;
@@ -218,23 +235,28 @@ pgp_rsa_encrypt(PGP_PubKey *pk, PGP_MPI *_m, PGP_MPI **c_p)
if (*c_p)
res = 0;
err:
- if (tmp) BN_CTX_free(tmp);
- if (c) BN_clear_free(c);
- if (n) BN_clear_free(n);
- if (e) BN_clear_free(e);
- if (m) BN_clear_free(m);
+ if (tmp)
+ BN_CTX_free(tmp);
+ if (c)
+ BN_clear_free(c);
+ if (n)
+ BN_clear_free(n);
+ if (e)
+ BN_clear_free(e);
+ if (m)
+ BN_clear_free(m);
return res;
}
int
-pgp_rsa_decrypt(PGP_PubKey *pk, PGP_MPI *_c, PGP_MPI **m_p)
+pgp_rsa_decrypt(PGP_PubKey * pk, PGP_MPI * _c, PGP_MPI ** m_p)
{
- int res = PXE_PGP_MATH_FAILED;
- BIGNUM *c = mpi_to_bn(_c);
- BIGNUM *d = mpi_to_bn(pk->sec.rsa.d);
- BIGNUM *n = mpi_to_bn(pk->pub.rsa.n);
- BIGNUM *m = BN_new();
- BN_CTX *tmp = BN_CTX_new();
+ int res = PXE_PGP_MATH_FAILED;
+ BIGNUM *c = mpi_to_bn(_c);
+ BIGNUM *d = mpi_to_bn(pk->sec.rsa.d);
+ BIGNUM *n = mpi_to_bn(pk->pub.rsa.n);
+ BIGNUM *m = BN_new();
+ BN_CTX *tmp = BN_CTX_new();
if (!m || !d || !n || !c || !tmp)
goto err;
@@ -249,11 +271,15 @@ pgp_rsa_decrypt(PGP_PubKey *pk, PGP_MPI *_c, PGP_MPI **m_p)
if (*m_p)
res = 0;
err:
- if (tmp) BN_CTX_free(tmp);
- if (m) BN_clear_free(m);
- if (n) BN_clear_free(n);
- if (d) BN_clear_free(d);
- if (c) BN_clear_free(c);
+ if (tmp)
+ BN_CTX_free(tmp);
+ if (m)
+ BN_clear_free(m);
+ if (n)
+ BN_clear_free(n);
+ if (d)
+ BN_clear_free(d);
+ if (c)
+ BN_clear_free(c);
return res;
}
-
diff --git a/contrib/pgcrypto/pgp-mpi.c b/contrib/pgcrypto/pgp-mpi.c
index 1e19ed7fb4..da0edb1361 100644
--- a/contrib/pgcrypto/pgp-mpi.c
+++ b/contrib/pgcrypto/pgp-mpi.c
@@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $PostgreSQL: pgsql/contrib/pgcrypto/pgp-mpi.c,v 1.3 2005/08/13 02:06:20 momjian Exp $
+ * $PostgreSQL: pgsql/contrib/pgcrypto/pgp-mpi.c,v 1.4 2005/10/15 02:49:06 momjian Exp $
*/
#include "postgres.h"
@@ -34,10 +34,12 @@
#include "mbuf.h"
#include "pgp.h"
-int pgp_mpi_alloc(int bits, PGP_MPI **mpi)
+int
+pgp_mpi_alloc(int bits, PGP_MPI ** mpi)
{
- PGP_MPI *n;
- int len = (bits + 7) / 8;
+ PGP_MPI *n;
+ int len = (bits + 7) / 8;
+
if (bits < 0 || bits > 0xFFFF)
{
px_debug("pgp_mpi_alloc: unreasonable request: bits=%d", bits);
@@ -46,15 +48,16 @@ int pgp_mpi_alloc(int bits, PGP_MPI **mpi)
n = px_alloc(sizeof(*n) + len);
n->bits = bits;
n->bytes = len;
- n->data = (uint8*)(n) + sizeof(*n);
+ n->data = (uint8 *) (n) + sizeof(*n);
*mpi = n;
return 0;
}
-int pgp_mpi_create(uint8 *data, int bits, PGP_MPI **mpi)
+int
+pgp_mpi_create(uint8 *data, int bits, PGP_MPI ** mpi)
{
- int res;
- PGP_MPI *n;
+ int res;
+ PGP_MPI *n;
res = pgp_mpi_alloc(bits, &n);
if (res < 0)
@@ -64,7 +67,8 @@ int pgp_mpi_create(uint8 *data, int bits, PGP_MPI **mpi)
return 0;
}
-int pgp_mpi_free(PGP_MPI *mpi)
+int
+pgp_mpi_free(PGP_MPI * mpi)
{
if (mpi == NULL)
return 0;
@@ -73,17 +77,18 @@ int pgp_mpi_free(PGP_MPI *mpi)
return 0;
}
-int pgp_mpi_read(PullFilter *src, PGP_MPI **mpi)
+int
+pgp_mpi_read(PullFilter * src, PGP_MPI ** mpi)
{
- int res;
- uint8 hdr[2];
- int bits;
- PGP_MPI *n;
+ int res;
+ uint8 hdr[2];
+ int bits;
+ PGP_MPI *n;
res = pullf_read_fixed(src, 2, hdr);
if (res < 0)
return res;
- bits = ((unsigned)hdr[0] << 8) + hdr[1];
+ bits = ((unsigned) hdr[0] << 8) + hdr[1];
res = pgp_mpi_alloc(bits, &n);
if (res < 0)
@@ -97,10 +102,11 @@ int pgp_mpi_read(PullFilter *src, PGP_MPI **mpi)
return res;
}
-int pgp_mpi_write(PushFilter *dst, PGP_MPI *n)
+int
+pgp_mpi_write(PushFilter * dst, PGP_MPI * n)
{
- int res;
- uint8 buf[2];
+ int res;
+ uint8 buf[2];
buf[0] = n->bits >> 8;
buf[1] = n->bits & 0xFF;
@@ -110,9 +116,10 @@ int pgp_mpi_write(PushFilter *dst, PGP_MPI *n)
return res;
}
-int pgp_mpi_hash(PX_MD *md, PGP_MPI *n)
+int
+pgp_mpi_hash(PX_MD * md, PGP_MPI * n)
{
- uint8 buf[2];
+ uint8 buf[2];
buf[0] = n->bits >> 8;
buf[1] = n->bits & 0xFF;
@@ -122,9 +129,10 @@ int pgp_mpi_hash(PX_MD *md, PGP_MPI *n)
return 0;
}
-unsigned pgp_mpi_cksum(unsigned cksum, PGP_MPI *n)
+unsigned
+pgp_mpi_cksum(unsigned cksum, PGP_MPI * n)
{
- int i;
+ int i;
cksum += n->bits >> 8;
cksum += n->bits & 0xFF;
@@ -133,4 +141,3 @@ unsigned pgp_mpi_cksum(unsigned cksum, PGP_MPI *n)
return cksum & 0xFFFF;
}
-
diff --git a/contrib/pgcrypto/pgp-pgsql.c b/contrib/pgcrypto/pgp-pgsql.c
index e0172fde90..afb926c528 100644
--- a/contrib/pgcrypto/pgp-pgsql.c
+++ b/contrib/pgcrypto/pgp-pgsql.c
@@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $PostgreSQL: pgsql/contrib/pgcrypto/pgp-pgsql.c,v 1.5 2005/09/24 19:14:04 tgl Exp $
+ * $PostgreSQL: pgsql/contrib/pgcrypto/pgp-pgsql.c,v 1.6 2005/10/15 02:49:06 momjian Exp $
*/
#include "postgres.h"
@@ -42,20 +42,20 @@
/*
* public functions
*/
-Datum pgp_sym_encrypt_text(PG_FUNCTION_ARGS);
-Datum pgp_sym_encrypt_bytea(PG_FUNCTION_ARGS);
-Datum pgp_sym_decrypt_text(PG_FUNCTION_ARGS);
-Datum pgp_sym_decrypt_bytea(PG_FUNCTION_ARGS);
+Datum pgp_sym_encrypt_text(PG_FUNCTION_ARGS);
+Datum pgp_sym_encrypt_bytea(PG_FUNCTION_ARGS);
+Datum pgp_sym_decrypt_text(PG_FUNCTION_ARGS);
+Datum pgp_sym_decrypt_bytea(PG_FUNCTION_ARGS);
-Datum pgp_pub_encrypt_text(PG_FUNCTION_ARGS);
-Datum pgp_pub_encrypt_bytea(PG_FUNCTION_ARGS);
-Datum pgp_pub_decrypt_text(PG_FUNCTION_ARGS);
-Datum pgp_pub_decrypt_bytea(PG_FUNCTION_ARGS);
+Datum pgp_pub_encrypt_text(PG_FUNCTION_ARGS);
+Datum pgp_pub_encrypt_bytea(PG_FUNCTION_ARGS);
+Datum pgp_pub_decrypt_text(PG_FUNCTION_ARGS);
+Datum pgp_pub_decrypt_bytea(PG_FUNCTION_ARGS);
-Datum pgp_key_id_w(PG_FUNCTION_ARGS);
+Datum pgp_key_id_w(PG_FUNCTION_ARGS);
-Datum pg_armor(PG_FUNCTION_ARGS);
-Datum pg_dearmor(PG_FUNCTION_ARGS);
+Datum pg_armor(PG_FUNCTION_ARGS);
+Datum pg_dearmor(PG_FUNCTION_ARGS);
/* function headers */
@@ -89,9 +89,10 @@ PG_FUNCTION_INFO_V1(pg_dearmor);
/*
* Mix a block of data into RNG.
*/
-static void add_block_entropy(PX_MD *md, text *data)
+static void
+add_block_entropy(PX_MD * md, text *data)
{
- uint8 sha1[20];
+ uint8 sha1[20];
px_md_reset(md);
px_md_update(md, (uint8 *) VARDATA(data), VARSIZE(data) - VARHDRSZ);
@@ -103,13 +104,14 @@ static void add_block_entropy(PX_MD *md, text *data)
}
/*
- * Mix user data into RNG. It is for user own interests to have
+ * Mix user data into RNG. It is for user own interests to have
* RNG state shuffled.
*/
-static void add_entropy(text *data1, text *data2, text *data3)
+static void
+add_entropy(text *data1, text *data2, text *data3)
{
- PX_MD *md;
- uint8 rnd[3];
+ PX_MD *md;
+ uint8 rnd[3];
if (!data1 && !data2 && !data3)
return;
@@ -122,9 +124,9 @@ static void add_entropy(text *data1, text *data2, text *data3)
/*
* Try to make the feeding unpredictable.
- *
- * Prefer data over keys, as it's rather likely
- * that key is same in several calls.
+ *
+ * Prefer data over keys, as it's rather likely that key is same in several
+ * calls.
*/
/* chance: 7/8 */
@@ -146,14 +148,15 @@ static void add_entropy(text *data1, text *data2, text *data3)
/*
* returns src in case of no conversion or error
*/
-static text *convert_charset(text *src, int cset_from, int cset_to)
+static text *
+convert_charset(text *src, int cset_from, int cset_to)
{
- int src_len = VARSIZE(src) - VARHDRSZ;
- int dst_len;
+ int src_len = VARSIZE(src) - VARHDRSZ;
+ int dst_len;
unsigned char *dst;
unsigned char *csrc = (unsigned char *) VARDATA(src);
- text *res;
-
+ text *res;
+
dst = pg_do_encoding_conversion(csrc, src_len, cset_from, cset_to);
if (dst == csrc)
return src;
@@ -166,12 +169,14 @@ static text *convert_charset(text *src, int cset_from, int cset_to)
return res;
}
-static text *convert_from_utf8(text *src)
+static text *
+convert_from_utf8(text *src)
{
return convert_charset(src, PG_UTF8, GetDatabaseEncoding());
}
-static text *convert_to_utf8(text *src)
+static text *
+convert_to_utf8(text *src)
{
return convert_charset(src, GetDatabaseEncoding(), PG_UTF8);
}
@@ -186,20 +191,22 @@ clear_and_pfree(text *p)
/*
* expect-* arguments storage
*/
-struct debug_expect {
- int debug;
- int expect;
- int cipher_algo;
- int s2k_mode;
- int s2k_cipher_algo;
- int s2k_digest_algo;
- int compress_algo;
- int use_sess_key;
- int disable_mdc;
- int unicode_mode;
+struct debug_expect
+{
+ int debug;
+ int expect;
+ int cipher_algo;
+ int s2k_mode;
+ int s2k_cipher_algo;
+ int s2k_digest_algo;
+ int compress_algo;
+ int use_sess_key;
+ int disable_mdc;
+ int unicode_mode;
};
-static void fill_expect(struct debug_expect *ex, int text_mode)
+static void
+fill_expect(struct debug_expect * ex, int text_mode)
{
ex->debug = 0;
ex->expect = 0;
@@ -222,7 +229,8 @@ static void fill_expect(struct debug_expect *ex, int text_mode)
if (ex->arg >= 0 && ex->arg != ctx->arg) EX_MSG(arg); \
} while (0)
-static void check_expect(PGP_Context *ctx, struct debug_expect *ex)
+static void
+check_expect(PGP_Context * ctx, struct debug_expect * ex)
{
EX_CHECK(cipher_algo);
EX_CHECK(s2k_mode);
@@ -235,15 +243,18 @@ static void check_expect(PGP_Context *ctx, struct debug_expect *ex)
EX_CHECK(unicode_mode);
}
-static void show_debug(const char *msg)
+static void
+show_debug(const char *msg)
{
ereport(NOTICE, (errmsg("dbg: %s", msg)));
}
-static int set_arg(PGP_Context *ctx, char *key, char*val,
- struct debug_expect *ex)
+static int
+set_arg(PGP_Context * ctx, char *key, char *val,
+ struct debug_expect * ex)
{
- int res = 0;
+ int res = 0;
+
if (strcmp(key, "cipher-algo") == 0)
res = pgp_set_cipher_algo(ctx, val);
else if (strcmp(key, "disable-mdc") == 0)
@@ -314,11 +325,12 @@ static int set_arg(PGP_Context *ctx, char *key, char*val,
}
/*
- * Find next word. Handle ',' and '=' as words. Skip whitespace.
+ * Find next word. Handle ',' and '=' as words. Skip whitespace.
* Put word info into res_p, res_len.
* Returns ptr to next word.
*/
-static char *getword(char *p, char **res_p, int *res_len)
+static char *
+getword(char *p, char **res_p, int *res_len)
{
/* whitespace at start */
while (*p && (*p == ' ' || *p == '\t' || *p == '\n'))
@@ -330,12 +342,12 @@ static char *getword(char *p, char **res_p, int *res_len)
p++;
else
while (*p && !(*p == ' ' || *p == '\t' || *p == '\n'
- || *p == '=' || *p == ','))
+ || *p == '=' || *p == ','))
p++;
/* word end */
*res_len = p - *res_p;
-
+
/* whitespace at end */
while (*p && (*p == ' ' || *p == '\t' || *p == '\n'))
p++;
@@ -346,11 +358,15 @@ static char *getword(char *p, char **res_p, int *res_len)
/*
* Convert to lowercase asciiz string.
*/
-static char *downcase_convert(const uint8 *s, int len)
+static char *
+downcase_convert(const uint8 *s, int len)
{
- int c, i;
- char *res = palloc(len + 1);
- for (i = 0; i < len; i++) {
+ int c,
+ i;
+ char *res = palloc(len + 1);
+
+ for (i = 0; i < len; i++)
+ {
c = s[i];
if (c >= 'A' && c <= 'Z')
c += 'a' - 'A';
@@ -360,14 +376,17 @@ static char *downcase_convert(const uint8 *s, int len)
return res;
}
-static int parse_args(PGP_Context *ctx, uint8 *args, int arg_len,
- struct debug_expect *ex)
+static int
+parse_args(PGP_Context * ctx, uint8 *args, int arg_len,
+ struct debug_expect * ex)
{
- char *str = downcase_convert(args, arg_len);
- char *key, *val;
- int key_len, val_len;
- int res = 0;
- char *p = str;
+ char *str = downcase_convert(args, arg_len);
+ char *key,
+ *val;
+ int key_len,
+ val_len;
+ int res = 0;
+ char *p = str;
while (*p)
{
@@ -403,10 +422,10 @@ create_mbuf_from_vardata(text *data)
}
static void
-init_work(PGP_Context **ctx_p, int is_text,
- text *args, struct debug_expect *ex)
+init_work(PGP_Context ** ctx_p, int is_text,
+ text *args, struct debug_expect * ex)
{
- int err = pgp_init(ctx_p);
+ int err = pgp_init(ctx_p);
fill_expect(ex, is_text);
@@ -429,17 +448,18 @@ init_work(PGP_Context **ctx_p, int is_text,
static bytea *
encrypt_internal(int is_pubenc, int is_text,
- text *data, text *key, text *args)
+ text *data, text *key, text *args)
{
- MBuf *src, *dst;
- uint8 tmp[VARHDRSZ];
- uint8 *restmp;
- bytea *res;
- int res_len;
+ MBuf *src,
+ *dst;
+ uint8 tmp[VARHDRSZ];
+ uint8 *restmp;
+ bytea *res;
+ int res_len;
PGP_Context *ctx;
- int err;
+ int err;
struct debug_expect ex;
- text *tmp_data = NULL;
+ text *tmp_data = NULL;
/*
* Add data and key info RNG.
@@ -470,15 +490,16 @@ encrypt_internal(int is_pubenc, int is_text,
*/
if (is_pubenc)
{
- MBuf *kbuf = create_mbuf_from_vardata(key);
+ MBuf *kbuf = create_mbuf_from_vardata(key);
+
err = pgp_set_pubkey(ctx, kbuf,
- NULL, 0, 0);
+ NULL, 0, 0);
mbuf_free(kbuf);
}
else
err = pgp_set_symkey(ctx, (uint8 *) VARDATA(key),
VARSIZE(key) - VARHDRSZ);
-
+
/*
* encrypt
*/
@@ -520,17 +541,18 @@ encrypt_internal(int is_pubenc, int is_text,
static bytea *
decrypt_internal(int is_pubenc, int need_text, text *data,
- text *key, text *keypsw, text *args)
+ text *key, text *keypsw, text *args)
{
- int err;
- MBuf *src = NULL, *dst = NULL;
- uint8 tmp[VARHDRSZ];
- uint8 *restmp;
- bytea *res;
- int res_len;
+ int err;
+ MBuf *src = NULL,
+ *dst = NULL;
+ uint8 tmp[VARHDRSZ];
+ uint8 *restmp;
+ bytea *res;
+ int res_len;
PGP_Context *ctx = NULL;
struct debug_expect ex;
- int got_unicode = 0;
+ int got_unicode = 0;
init_work(&ctx, need_text, args, &ex);
@@ -543,15 +565,16 @@ decrypt_internal(int is_pubenc, int need_text, text *data,
* reserve room for header
*/
mbuf_append(dst, tmp, VARHDRSZ);
-
+
/*
* set key
*/
if (is_pubenc)
{
- uint8 *psw = NULL;
- int psw_len = 0;
- MBuf *kbuf;
+ uint8 *psw = NULL;
+ int psw_len = 0;
+ MBuf *kbuf;
+
if (keypsw)
{
psw = (uint8 *) VARDATA(keypsw);
@@ -608,7 +631,8 @@ out:
if (need_text && got_unicode)
{
- text *utf = convert_from_utf8(res);
+ text *utf = convert_from_utf8(res);
+
if (utf != res)
{
clear_and_pfree(res);
@@ -927,4 +951,3 @@ pgp_key_id_w(PG_FUNCTION_ARGS)
PG_FREE_IF_COPY(data, 0);
PG_RETURN_TEXT_P(res);
}
-
diff --git a/contrib/pgcrypto/pgp-pubdec.c b/contrib/pgcrypto/pgp-pubdec.c
index 04e98ceacb..600a1e2531 100644
--- a/contrib/pgcrypto/pgp-pubdec.c
+++ b/contrib/pgcrypto/pgp-pubdec.c
@@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $PostgreSQL: pgsql/contrib/pgcrypto/pgp-pubdec.c,v 1.4 2005/08/13 02:06:20 momjian Exp $
+ * $PostgreSQL: pgsql/contrib/pgcrypto/pgp-pubdec.c,v 1.5 2005/10/15 02:49:06 momjian Exp $
*/
#include "postgres.h"
@@ -35,24 +35,25 @@
#include "pgp.h"
/*
- * padded msg = 02 || PS || 00 || M
+ * padded msg = 02 || PS || 00 || M
* PS - pad bytes
* M - msg
*/
static uint8 *
check_eme_pkcs1_v15(uint8 *data, int len)
{
- uint8 *data_end = data + len;
- uint8 *p = data;
- int rnd = 0;
+ uint8 *data_end = data + len;
+ uint8 *p = data;
+ int rnd = 0;
if (len < 1 + 8 + 1)
return NULL;
if (*p++ != 2)
return NULL;
-
- while (p < data_end && *p) {
+
+ while (p < data_end && *p)
+ {
p++;
rnd++;
}
@@ -73,8 +74,9 @@ check_eme_pkcs1_v15(uint8 *data, int len)
static int
control_cksum(uint8 *msg, int msglen)
{
- int i;
- unsigned my_cksum, got_cksum;
+ int i;
+ unsigned my_cksum,
+ got_cksum;
if (msglen < 3)
return PXE_PGP_WRONG_KEY;
@@ -83,8 +85,9 @@ control_cksum(uint8 *msg, int msglen)
for (i = 1; i < msglen - 2; i++)
my_cksum += msg[i];
my_cksum &= 0xFFFF;
- got_cksum = ((unsigned)(msg[msglen-2]) << 8) + msg[msglen-1];
- if (my_cksum != got_cksum) {
+ got_cksum = ((unsigned) (msg[msglen - 2]) << 8) + msg[msglen - 1];
+ if (my_cksum != got_cksum)
+ {
px_debug("pubenc cksum failed");
return PXE_PGP_WRONG_KEY;
}
@@ -92,11 +95,11 @@ control_cksum(uint8 *msg, int msglen)
}
static int
-decrypt_elgamal(PGP_PubKey *pk, PullFilter *pkt, PGP_MPI **m_p)
+decrypt_elgamal(PGP_PubKey * pk, PullFilter * pkt, PGP_MPI ** m_p)
{
- int res;
- PGP_MPI *c1 = NULL;
- PGP_MPI *c2 = NULL;
+ int res;
+ PGP_MPI *c1 = NULL;
+ PGP_MPI *c2 = NULL;
if (pk->algo != PGP_PUB_ELG_ENCRYPT)
return PXE_PGP_WRONG_KEY;
@@ -119,13 +122,13 @@ out:
}
static int
-decrypt_rsa(PGP_PubKey *pk, PullFilter *pkt, PGP_MPI **m_p)
+decrypt_rsa(PGP_PubKey * pk, PullFilter * pkt, PGP_MPI ** m_p)
{
- int res;
- PGP_MPI *c;
+ int res;
+ PGP_MPI *c;
if (pk->algo != PGP_PUB_RSA_ENCRYPT
- && pk->algo != PGP_PUB_RSA_ENCRYPT_SIGN)
+ && pk->algo != PGP_PUB_RSA_ENCRYPT_SIGN)
return PXE_PGP_WRONG_KEY;
/* read rsa encrypted data */
@@ -142,28 +145,30 @@ decrypt_rsa(PGP_PubKey *pk, PullFilter *pkt, PGP_MPI **m_p)
/* key id is missing - user is expected to try all keys */
static const uint8
-any_key[] = {0, 0, 0, 0, 0, 0, 0, 0};
+ any_key[] = {0, 0, 0, 0, 0, 0, 0, 0};
int
-pgp_parse_pubenc_sesskey(PGP_Context *ctx, PullFilter *pkt)
+pgp_parse_pubenc_sesskey(PGP_Context * ctx, PullFilter * pkt)
{
- int ver;
- int algo;
- int res;
- uint8 key_id[8];
+ int ver;
+ int algo;
+ int res;
+ uint8 key_id[8];
PGP_PubKey *pk;
- uint8 *msg;
- int msglen;
- PGP_MPI *m;
+ uint8 *msg;
+ int msglen;
+ PGP_MPI *m;
pk = ctx->pub_key;
- if (pk == NULL) {
+ if (pk == NULL)
+ {
px_debug("no pubkey?");
return PXE_BUG;
}
GETBYTE(pkt, ver);
- if (ver != 3) {
+ if (ver != 3)
+ {
px_debug("unknown pubenc_sesskey pkt ver=%d", ver);
return PXE_PGP_CORRUPT_DATA;
}
@@ -175,7 +180,7 @@ pgp_parse_pubenc_sesskey(PGP_Context *ctx, PullFilter *pkt)
if (res < 0)
return res;
if (memcmp(key_id, any_key, 8) != 0
- && memcmp(key_id, pk->key_id, 8) != 0)
+ && memcmp(key_id, pk->key_id, 8) != 0)
{
px_debug("key_id's does not match");
return PXE_PGP_WRONG_KEY;
@@ -204,7 +209,8 @@ pgp_parse_pubenc_sesskey(PGP_Context *ctx, PullFilter *pkt)
* extract message
*/
msg = check_eme_pkcs1_v15(m->data, m->bytes);
- if (msg == NULL) {
+ if (msg == NULL)
+ {
px_debug("check_eme_pkcs1_v15 failed");
res = PXE_PGP_WRONG_KEY;
goto out;
@@ -228,5 +234,3 @@ out:
return res;
return pgp_expect_packet_end(pkt);
}
-
-
diff --git a/contrib/pgcrypto/pgp-pubenc.c b/contrib/pgcrypto/pgp-pubenc.c
index 3b2dd85c48..de729476f5 100644
--- a/contrib/pgcrypto/pgp-pubenc.c
+++ b/contrib/pgcrypto/pgp-pubenc.c
@@ -1,6 +1,6 @@
/*
* pgp-pubenc.c
- * Encrypt session key with public key.
+ * Encrypt session key with public key.
*
* Copyright (c) 2005 Marko Kreen
* All rights reserved.
@@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $PostgreSQL: pgsql/contrib/pgcrypto/pgp-pubenc.c,v 1.3 2005/08/13 02:06:20 momjian Exp $
+ * $PostgreSQL: pgsql/contrib/pgcrypto/pgp-pubenc.c,v 1.4 2005/10/15 02:49:06 momjian Exp $
*/
#include "postgres.h"
@@ -40,9 +40,10 @@
static int
pad_eme_pkcs1_v15(uint8 *data, int data_len, int res_len, uint8 **res_p)
{
- int res;
- uint8 *buf, *p;
- int pad_len = res_len - 2 - data_len;
+ int res;
+ uint8 *buf,
+ *p;
+ int pad_len = res_len - 2 - data_len;
if (pad_len < 8)
return PXE_BUG;
@@ -76,7 +77,7 @@ pad_eme_pkcs1_v15(uint8 *data, int data_len, int res_len, uint8 **res_p)
px_free(buf);
return res;
}
-
+
buf[pad_len + 1] = 0;
memcpy(buf + pad_len + 2, data, data_len);
*res_p = buf;
@@ -85,19 +86,20 @@ pad_eme_pkcs1_v15(uint8 *data, int data_len, int res_len, uint8 **res_p)
}
static int
-create_secmsg(PGP_Context *ctx, PGP_MPI **msg_p, int full_bytes)
+create_secmsg(PGP_Context * ctx, PGP_MPI ** msg_p, int full_bytes)
{
- uint8 *secmsg;
- int res, i;
- unsigned cksum = 0;
- int klen = ctx->sess_key_len;
- uint8 *padded = NULL;
- PGP_MPI *m = NULL;
+ uint8 *secmsg;
+ int res,
+ i;
+ unsigned cksum = 0;
+ int klen = ctx->sess_key_len;
+ uint8 *padded = NULL;
+ PGP_MPI *m = NULL;
/* calc checksum */
for (i = 0; i < klen; i++)
cksum += ctx->sess_key[i];
-
+
/*
* create "secret message"
*/
@@ -114,7 +116,8 @@ create_secmsg(PGP_Context *ctx, PGP_MPI **msg_p, int full_bytes)
if (res >= 0)
{
/* first byte will be 0x02 */
- int full_bits = full_bytes * 8 - 6;
+ int full_bits = full_bytes * 8 - 6;
+
res = pgp_mpi_create(padded, full_bits, &m);
}
@@ -133,10 +136,12 @@ create_secmsg(PGP_Context *ctx, PGP_MPI **msg_p, int full_bytes)
}
static int
-encrypt_and_write_elgamal(PGP_Context *ctx, PGP_PubKey *pk, PushFilter *pkt)
+encrypt_and_write_elgamal(PGP_Context * ctx, PGP_PubKey * pk, PushFilter * pkt)
{
- int res;
- PGP_MPI *m = NULL, *c1 = NULL, *c2 = NULL;
+ int res;
+ PGP_MPI *m = NULL,
+ *c1 = NULL,
+ *c2 = NULL;
/* create padded msg */
res = create_secmsg(ctx, &m, pk->pub.elg.p->bytes - 1);
@@ -162,10 +167,11 @@ err:
}
static int
-encrypt_and_write_rsa(PGP_Context *ctx, PGP_PubKey *pk, PushFilter *pkt)
+encrypt_and_write_rsa(PGP_Context * ctx, PGP_PubKey * pk, PushFilter * pkt)
{
- int res;
- PGP_MPI *m = NULL, *c = NULL;
+ int res;
+ PGP_MPI *m = NULL,
+ *c = NULL;
/* create padded msg */
res = create_secmsg(ctx, &m, pk->pub.rsa.n->bytes - 1);
@@ -186,15 +192,17 @@ err:
return res;
}
-int pgp_write_pubenc_sesskey(PGP_Context *ctx, PushFilter *dst)
+int
+pgp_write_pubenc_sesskey(PGP_Context * ctx, PushFilter * dst)
{
- int res;
+ int res;
PGP_PubKey *pk = ctx->pub_key;
- uint8 ver = 3;
+ uint8 ver = 3;
PushFilter *pkt = NULL;
- uint8 algo = pk->algo;
+ uint8 algo = pk->algo;
- if (pk == NULL) {
+ if (pk == NULL)
+ {
px_debug("no pubkey?\n");
return PXE_BUG;
}
@@ -238,5 +246,3 @@ err:
return res;
}
-
-
diff --git a/contrib/pgcrypto/pgp-pubkey.c b/contrib/pgcrypto/pgp-pubkey.c
index 9eb3c23c08..3904561806 100644
--- a/contrib/pgcrypto/pgp-pubkey.c
+++ b/contrib/pgcrypto/pgp-pubkey.c
@@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $PostgreSQL: pgsql/contrib/pgcrypto/pgp-pubkey.c,v 1.3 2005/08/13 02:06:20 momjian Exp $
+ * $PostgreSQL: pgsql/contrib/pgcrypto/pgp-pubkey.c,v 1.4 2005/10/15 02:49:06 momjian Exp $
*/
#include "postgres.h"
@@ -34,16 +34,19 @@
#include "mbuf.h"
#include "pgp.h"
-int pgp_key_alloc(PGP_PubKey **pk_p)
+int
+pgp_key_alloc(PGP_PubKey ** pk_p)
{
PGP_PubKey *pk;
+
pk = px_alloc(sizeof(*pk));
memset(pk, 0, sizeof(*pk));
*pk_p = pk;
return 0;
}
-void pgp_key_free(PGP_PubKey *pk)
+void
+pgp_key_free(PGP_PubKey * pk)
{
if (pk == NULL)
return;
@@ -79,13 +82,13 @@ void pgp_key_free(PGP_PubKey *pk)
}
static int
-calc_key_id(PGP_PubKey *pk)
+calc_key_id(PGP_PubKey * pk)
{
- int res;
- PX_MD *md;
- int len;
- uint8 hdr[3];
- uint8 hash[20];
+ int res;
+ PX_MD *md;
+ int len;
+ uint8 hdr[3];
+ uint8 hash[20];
res = pgp_load_digest(PGP_DIGEST_SHA1, &md);
if (res < 0)
@@ -121,7 +124,7 @@ calc_key_id(PGP_PubKey *pk)
px_md_update(md, &pk->ver, 1);
px_md_update(md, pk->time, 4);
px_md_update(md, &pk->algo, 1);
-
+
switch (pk->algo)
{
case PGP_PUB_ELG_ENCRYPT:
@@ -152,9 +155,10 @@ calc_key_id(PGP_PubKey *pk)
return 0;
}
-int _pgp_read_public_key(PullFilter *pkt, PGP_PubKey **pk_p)
+int
+_pgp_read_public_key(PullFilter * pkt, PGP_PubKey ** pk_p)
{
- int res;
+ int res;
PGP_PubKey *pk;
res = pgp_key_alloc(&pk);
@@ -163,11 +167,12 @@ int _pgp_read_public_key(PullFilter *pkt, PGP_PubKey **pk_p)
/* get version */
GETBYTE(pkt, pk->ver);
- if (pk->ver != 4) {
+ if (pk->ver != 4)
+ {
res = PXE_PGP_NOT_V4_KEYPKT;
goto out;
}
-
+
/* read time */
res = pullf_read_fixed(pkt, 4, pk->time);
if (res < 0)
@@ -176,16 +181,21 @@ int _pgp_read_public_key(PullFilter *pkt, PGP_PubKey **pk_p)
/* pubkey algorithm */
GETBYTE(pkt, pk->algo);
- switch (pk->algo) {
+ switch (pk->algo)
+ {
case PGP_PUB_DSA_SIGN:
res = pgp_mpi_read(pkt, &pk->pub.dsa.p);
- if (res < 0) break;
+ if (res < 0)
+ break;
res = pgp_mpi_read(pkt, &pk->pub.dsa.q);
- if (res < 0) break;
+ if (res < 0)
+ break;
res = pgp_mpi_read(pkt, &pk->pub.dsa.g);
- if (res < 0) break;
+ if (res < 0)
+ break;
res = pgp_mpi_read(pkt, &pk->pub.dsa.y);
- if (res < 0) break;
+ if (res < 0)
+ break;
res = calc_key_id(pk);
break;
@@ -194,9 +204,11 @@ int _pgp_read_public_key(PullFilter *pkt, PGP_PubKey **pk_p)
case PGP_PUB_RSA_ENCRYPT:
case PGP_PUB_RSA_ENCRYPT_SIGN:
res = pgp_mpi_read(pkt, &pk->pub.rsa.n);
- if (res < 0) break;
+ if (res < 0)
+ break;
res = pgp_mpi_read(pkt, &pk->pub.rsa.e);
- if (res < 0) break;
+ if (res < 0)
+ break;
res = calc_key_id(pk);
@@ -206,11 +218,14 @@ int _pgp_read_public_key(PullFilter *pkt, PGP_PubKey **pk_p)
case PGP_PUB_ELG_ENCRYPT:
res = pgp_mpi_read(pkt, &pk->pub.elg.p);
- if (res < 0) break;
+ if (res < 0)
+ break;
res = pgp_mpi_read(pkt, &pk->pub.elg.g);
- if (res < 0) break;
+ if (res < 0)
+ break;
res = pgp_mpi_read(pkt, &pk->pub.elg.y);
- if (res < 0) break;
+ if (res < 0)
+ break;
res = calc_key_id(pk);
@@ -236,12 +251,12 @@ out:
#define HIDE_SHA1 254
static int
-check_key_sha1(PullFilter *src, PGP_PubKey *pk)
+check_key_sha1(PullFilter * src, PGP_PubKey * pk)
{
- int res;
- uint8 got_sha1[20];
- uint8 my_sha1[20];
- PX_MD *md;
+ int res;
+ uint8 got_sha1[20];
+ uint8 my_sha1[20];
+ PX_MD *md;
res = pullf_read_fixed(src, 20, got_sha1);
if (res < 0)
@@ -282,17 +297,18 @@ err:
}
static int
-check_key_cksum(PullFilter *src, PGP_PubKey *pk)
+check_key_cksum(PullFilter * src, PGP_PubKey * pk)
{
- int res;
- unsigned got_cksum, my_cksum = 0;
- uint8 buf[2];
+ int res;
+ unsigned got_cksum,
+ my_cksum = 0;
+ uint8 buf[2];
res = pullf_read_fixed(src, 2, buf);
if (res < 0)
return res;
- got_cksum = ((unsigned)buf[0] << 8) + buf[1];
+ got_cksum = ((unsigned) buf[0] << 8) + buf[1];
switch (pk->algo)
{
case PGP_PUB_ELG_ENCRYPT:
@@ -318,17 +334,19 @@ check_key_cksum(PullFilter *src, PGP_PubKey *pk)
return 0;
}
-static int process_secret_key(PullFilter *pkt, PGP_PubKey **pk_p,
- const uint8 *key, int key_len)
+static int
+process_secret_key(PullFilter * pkt, PGP_PubKey ** pk_p,
+ const uint8 *key, int key_len)
{
- int res;
- int hide_type;
- int cipher_algo;
- int bs;
- uint8 iv[512];
- PullFilter *pf_decrypt = NULL, *pf_key;
- PGP_CFB *cfb = NULL;
- PGP_S2K s2k;
+ int res;
+ int hide_type;
+ int cipher_algo;
+ int bs;
+ uint8 iv[512];
+ PullFilter *pf_decrypt = NULL,
+ *pf_key;
+ PGP_CFB *cfb = NULL;
+ PGP_S2K s2k;
PGP_PubKey *pk;
/* first read public key part */
@@ -340,7 +358,8 @@ static int process_secret_key(PullFilter *pkt, PGP_PubKey **pk_p,
* is secret key encrypted?
*/
GETBYTE(pkt, hide_type);
- if (hide_type == HIDE_SHA1 || hide_type == HIDE_CKSUM) {
+ if (hide_type == HIDE_SHA1 || hide_type == HIDE_CKSUM)
+ {
if (key == NULL)
return PXE_PGP_NEED_SECRET_PSW;
GETBYTE(pkt, cipher_algo);
@@ -351,15 +370,17 @@ static int process_secret_key(PullFilter *pkt, PGP_PubKey **pk_p,
res = pgp_s2k_process(&s2k, cipher_algo, key, key_len);
if (res < 0)
return res;
-
+
bs = pgp_get_cipher_block_size(cipher_algo);
- if (bs == 0) {
+ if (bs == 0)
+ {
px_debug("unknown cipher algo=%d", cipher_algo);
return PXE_PGP_UNSUPPORTED_CIPHER;
}
res = pullf_read_fixed(pkt, bs, iv);
if (res < 0)
return res;
+
/*
* create decrypt filter
*/
@@ -370,26 +391,35 @@ static int process_secret_key(PullFilter *pkt, PGP_PubKey **pk_p,
if (res < 0)
return res;
pf_key = pf_decrypt;
- } else if (hide_type == HIDE_CLEAR) {
+ }
+ else if (hide_type == HIDE_CLEAR)
+ {
pf_key = pkt;
- } else {
+ }
+ else
+ {
px_debug("unknown hide type");
return PXE_PGP_KEYPKT_CORRUPT;
}
/* read secret key */
- switch (pk->algo) {
+ switch (pk->algo)
+ {
case PGP_PUB_RSA_SIGN:
case PGP_PUB_RSA_ENCRYPT:
case PGP_PUB_RSA_ENCRYPT_SIGN:
res = pgp_mpi_read(pkt, &pk->sec.rsa.d);
- if (res < 0) break;
+ if (res < 0)
+ break;
res = pgp_mpi_read(pkt, &pk->sec.rsa.p);
- if (res < 0) break;
+ if (res < 0)
+ break;
res = pgp_mpi_read(pkt, &pk->sec.rsa.q);
- if (res < 0) break;
+ if (res < 0)
+ break;
res = pgp_mpi_read(pkt, &pk->sec.rsa.u);
- if (res < 0) break;
+ if (res < 0)
+ break;
break;
case PGP_PUB_ELG_ENCRYPT:
res = pgp_mpi_read(pf_key, &pk->sec.elg.x);
@@ -426,31 +456,33 @@ static int process_secret_key(PullFilter *pkt, PGP_PubKey **pk_p,
}
static int
-internal_read_key(PullFilter *src, PGP_PubKey **pk_p,
- const uint8 *psw, int psw_len, int pubtype)
+internal_read_key(PullFilter * src, PGP_PubKey ** pk_p,
+ const uint8 *psw, int psw_len, int pubtype)
{
PullFilter *pkt = NULL;
- int res;
- uint8 tag;
- int len;
+ int res;
+ uint8 tag;
+ int len;
PGP_PubKey *enc_key = NULL;
PGP_PubKey *pk = NULL;
- int got_main_key = 0;
+ int got_main_key = 0;
/*
* Search for encryption key.
*
* Error out on anything fancy.
*/
- while (1) {
+ while (1)
+ {
res = pgp_parse_pkt_hdr(src, &tag, &len, 0);
if (res <= 0)
break;
res = pgp_create_pkt_reader(&pkt, src, len, res, NULL);
if (res < 0)
break;
-
- switch (tag) {
+
+ switch (tag)
+ {
case PGP_PKT_PUBLIC_KEY:
case PGP_PKT_SECRET_KEY:
if (got_main_key)
@@ -489,7 +521,7 @@ internal_read_key(PullFilter *src, PGP_PubKey **pk_p,
res = PXE_PGP_UNEXPECTED_PKT;
}
pullf_free(pkt);
- pkt = NULL;
+ pkt = NULL;
if (pk != NULL)
{
@@ -531,10 +563,10 @@ internal_read_key(PullFilter *src, PGP_PubKey **pk_p,
}
int
-pgp_set_pubkey(PGP_Context *ctx, MBuf *keypkt,
- const uint8 *key, int key_len, int pubtype)
+pgp_set_pubkey(PGP_Context * ctx, MBuf * keypkt,
+ const uint8 *key, int key_len, int pubtype)
{
- int res;
+ int res;
PullFilter *src;
PGP_PubKey *pk = NULL;
@@ -550,4 +582,3 @@ pgp_set_pubkey(PGP_Context *ctx, MBuf *keypkt,
return res < 0 ? res : 0;
}
-
diff --git a/contrib/pgcrypto/pgp-s2k.c b/contrib/pgcrypto/pgp-s2k.c
index cbde42a13b..84def87db6 100644
--- a/contrib/pgcrypto/pgp-s2k.c
+++ b/contrib/pgcrypto/pgp-s2k.c
@@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $PostgreSQL: pgsql/contrib/pgcrypto/pgp-s2k.c,v 1.3 2005/07/18 17:12:54 tgl Exp $
+ * $PostgreSQL: pgsql/contrib/pgcrypto/pgp-s2k.c,v 1.4 2005/10/15 02:49:06 momjian Exp $
*/
#include "postgres.h"
@@ -36,7 +36,7 @@
#include "pgp.h"
static int
-calc_s2k_simple(PGP_S2K * s2k, PX_MD *md, const uint8 *key,
+calc_s2k_simple(PGP_S2K * s2k, PX_MD * md, const uint8 *key,
unsigned key_len)
{
unsigned md_bs,
@@ -81,7 +81,7 @@ calc_s2k_simple(PGP_S2K * s2k, PX_MD *md, const uint8 *key,
}
static int
-calc_s2k_salted(PGP_S2K * s2k, PX_MD *md, const uint8 *key, unsigned key_len)
+calc_s2k_salted(PGP_S2K * s2k, PX_MD * md, const uint8 *key, unsigned key_len)
{
unsigned md_bs,
md_rlen;
@@ -126,8 +126,8 @@ calc_s2k_salted(PGP_S2K * s2k, PX_MD *md, const uint8 *key, unsigned key_len)
}
static int
-calc_s2k_iter_salted(PGP_S2K * s2k, PX_MD *md, const uint8 *key,
- unsigned key_len)
+calc_s2k_iter_salted(PGP_S2K * s2k, PX_MD * md, const uint8 *key,
+ unsigned key_len)
{
unsigned md_bs,
md_rlen;
@@ -200,7 +200,7 @@ calc_s2k_iter_salted(PGP_S2K * s2k, PX_MD *md, const uint8 *key,
/*
* Decide S2K_ISALTED iteration count
- *
+ *
* Too small: weak
* Too big: slow
* gpg defaults to 96 => 65536 iters
@@ -213,15 +213,16 @@ decide_count(unsigned rand_byte)
}
int
-pgp_s2k_fill(PGP_S2K *s2k, int mode,int digest_algo)
+pgp_s2k_fill(PGP_S2K * s2k, int mode, int digest_algo)
{
- int res = 0;
- uint8 tmp;
+ int res = 0;
+ uint8 tmp;
s2k->mode = mode;
s2k->digest_algo = digest_algo;
- switch (s2k->mode) {
+ switch (s2k->mode)
+ {
case 0:
break;
case 1:
@@ -243,13 +244,14 @@ pgp_s2k_fill(PGP_S2K *s2k, int mode,int digest_algo)
}
int
-pgp_s2k_read(PullFilter *src, PGP_S2K *s2k)
+pgp_s2k_read(PullFilter * src, PGP_S2K * s2k)
{
- int res = 0;
+ int res = 0;
GETBYTE(src, s2k->mode);
GETBYTE(src, s2k->digest_algo);
- switch (s2k->mode) {
+ switch (s2k->mode)
+ {
case 0:
break;
case 1:
@@ -267,10 +269,11 @@ pgp_s2k_read(PullFilter *src, PGP_S2K *s2k)
return res;
}
-int pgp_s2k_process(PGP_S2K *s2k, int cipher, const uint8 *key, int key_len)
+int
+pgp_s2k_process(PGP_S2K * s2k, int cipher, const uint8 *key, int key_len)
{
- int res;
- PX_MD *md;
+ int res;
+ PX_MD *md;
s2k->key_len = pgp_get_cipher_key_size(cipher);
if (s2k->key_len <= 0)
@@ -280,7 +283,8 @@ int pgp_s2k_process(PGP_S2K *s2k, int cipher, const uint8 *key, int key_len)
if (res < 0)
return res;
- switch (s2k->mode) {
+ switch (s2k->mode)
+ {
case 0:
res = calc_s2k_simple(s2k, md, key, key_len);
break;
@@ -296,4 +300,3 @@ int pgp_s2k_process(PGP_S2K *s2k, int cipher, const uint8 *key, int key_len)
px_md_free(md);
return res;
}
-
diff --git a/contrib/pgcrypto/pgp.c b/contrib/pgcrypto/pgp.c
index c9bf8d7d28..e9e732e4be 100644
--- a/contrib/pgcrypto/pgp.c
+++ b/contrib/pgcrypto/pgp.c
@@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $PostgreSQL: pgsql/contrib/pgcrypto/pgp.c,v 1.2 2005/07/11 15:07:59 tgl Exp $
+ * $PostgreSQL: pgsql/contrib/pgcrypto/pgp.c,v 1.3 2005/10/15 02:49:06 momjian Exp $
*/
#include "postgres.h"
@@ -62,8 +62,8 @@ struct cipher_info
const char *name;
int code;
const char *int_name;
- int key_len;
- int block_len;
+ int key_len;
+ int block_len;
};
static const struct digest_info digest_list[] = {
@@ -78,15 +78,15 @@ static const struct digest_info digest_list[] = {
};
static const struct cipher_info cipher_list[] = {
- {"3des", PGP_SYM_DES3, "3des-ecb", 192/8, 64/8},
- {"cast5", PGP_SYM_CAST5, "cast5-ecb", 128/8, 64/8},
- {"bf", PGP_SYM_BLOWFISH, "bf-ecb", 128/8, 64/8},
- {"blowfish", PGP_SYM_BLOWFISH, "bf-ecb", 128/8, 64/8},
- {"aes", PGP_SYM_AES_128, "aes-ecb", 128/8, 128/8},
- {"aes128", PGP_SYM_AES_128, "aes-ecb", 128/8, 128/8},
- {"aes192", PGP_SYM_AES_192, "aes-ecb", 192/8, 128/8},
- {"aes256", PGP_SYM_AES_256, "aes-ecb", 256/8, 128/8},
- {"twofish", PGP_SYM_TWOFISH, "twofish-ecb", 256/8, 128/8},
+ {"3des", PGP_SYM_DES3, "3des-ecb", 192 / 8, 64 / 8},
+ {"cast5", PGP_SYM_CAST5, "cast5-ecb", 128 / 8, 64 / 8},
+ {"bf", PGP_SYM_BLOWFISH, "bf-ecb", 128 / 8, 64 / 8},
+ {"blowfish", PGP_SYM_BLOWFISH, "bf-ecb", 128 / 8, 64 / 8},
+ {"aes", PGP_SYM_AES_128, "aes-ecb", 128 / 8, 128 / 8},
+ {"aes128", PGP_SYM_AES_128, "aes-ecb", 128 / 8, 128 / 8},
+ {"aes192", PGP_SYM_AES_192, "aes-ecb", 192 / 8, 128 / 8},
+ {"aes256", PGP_SYM_AES_256, "aes-ecb", 256 / 8, 128 / 8},
+ {"twofish", PGP_SYM_TWOFISH, "twofish-ecb", 256 / 8, 128 / 8},
{NULL, 0, NULL}
};
@@ -94,6 +94,7 @@ static const struct cipher_info *
get_cipher_info(int code)
{
const struct cipher_info *i;
+
for (i = cipher_list; i->name; i++)
if (i->code == code)
return i;
@@ -104,6 +105,7 @@ int
pgp_get_digest_code(const char *name)
{
const struct digest_info *i;
+
for (i = digest_list; i->name; i++)
if (pg_strcasecmp(i->name, name) == 0)
return i->code;
@@ -114,6 +116,7 @@ int
pgp_get_cipher_code(const char *name)
{
const struct cipher_info *i;
+
for (i = cipher_list; i->name; i++)
if (pg_strcasecmp(i->name, name) == 0)
return i->code;
@@ -124,6 +127,7 @@ const char *
pgp_get_digest_name(int code)
{
const struct digest_info *i;
+
for (i = digest_list; i->name; i++)
if (i->code == code)
return i->name;
@@ -134,6 +138,7 @@ const char *
pgp_get_cipher_name(int code)
{
const struct cipher_info *i = get_cipher_info(code);
+
if (i != NULL)
return i->name;
return NULL;
@@ -143,6 +148,7 @@ int
pgp_get_cipher_key_size(int code)
{
const struct cipher_info *i = get_cipher_info(code);
+
if (i != NULL)
return i->key_len;
return 0;
@@ -152,6 +158,7 @@ int
pgp_get_cipher_block_size(int code)
{
const struct cipher_info *i = get_cipher_info(code);
+
if (i != NULL)
return i->block_len;
return 0;
@@ -300,6 +307,7 @@ int
pgp_set_cipher_algo(PGP_Context * ctx, const char *name)
{
int code = pgp_get_cipher_code(name);
+
if (code < 0)
return code;
ctx->cipher_algo = code;
@@ -310,6 +318,7 @@ int
pgp_set_s2k_cipher_algo(PGP_Context * ctx, const char *name)
{
int code = pgp_get_cipher_code(name);
+
if (code < 0)
return code;
ctx->s2k_cipher_algo = code;
@@ -320,6 +329,7 @@ int
pgp_set_s2k_digest_algo(PGP_Context * ctx, const char *name)
{
int code = pgp_get_digest_code(name);
+
if (code < 0)
return code;
ctx->s2k_digest_algo = code;
@@ -327,20 +337,20 @@ pgp_set_s2k_digest_algo(PGP_Context * ctx, const char *name)
}
int
-pgp_get_unicode_mode(PGP_Context *ctx)
+pgp_get_unicode_mode(PGP_Context * ctx)
{
return ctx->unicode_mode;
}
int
-pgp_set_unicode_mode(PGP_Context *ctx, int mode)
+pgp_set_unicode_mode(PGP_Context * ctx, int mode)
{
ctx->unicode_mode = mode ? 1 : 0;
return 0;
}
int
-pgp_set_symkey(PGP_Context *ctx, const uint8 *key, int len)
+pgp_set_symkey(PGP_Context * ctx, const uint8 *key, int len)
{
if (key == NULL || len < 1)
return PXE_ARGUMENT_ERROR;
@@ -348,4 +358,3 @@ pgp_set_symkey(PGP_Context *ctx, const uint8 *key, int len)
ctx->sym_key_len = len;
return 0;
}
-
diff --git a/contrib/pgcrypto/pgp.h b/contrib/pgcrypto/pgp.h
index 769a248d18..d23086f533 100644
--- a/contrib/pgcrypto/pgp.h
+++ b/contrib/pgcrypto/pgp.h
@@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $PostgreSQL: pgsql/contrib/pgcrypto/pgp.h,v 1.3 2005/08/13 02:06:20 momjian Exp $
+ * $PostgreSQL: pgsql/contrib/pgcrypto/pgp.h,v 1.4 2005/10/15 02:49:06 momjian Exp $
*/
enum
@@ -55,7 +55,7 @@ enum
PGP_PKT_USER_ATTR = 17,
PGP_PKT_SYMENCRYPTED_DATA_MDC = 18,
PGP_PKT_MDC = 19,
- PGP_PKT_PRIV_61 = 61 /* occurs in gpg secring */
+ PGP_PKT_PRIV_61 = 61 /* occurs in gpg secring */
} PGP_PKT_TYPE;
enum
@@ -93,11 +93,11 @@ enum
enum
{
PGP_DIGEST_MD5 = 1, /* should, deprecated */
- PGP_DIGEST_SHA1 = 2, /* must */
+ PGP_DIGEST_SHA1 = 2, /* must */
PGP_DIGEST_RIPEMD160 = 3,
- PGP_DIGEST_XSHA = 4, /* obsolete */
+ PGP_DIGEST_XSHA = 4, /* obsolete */
PGP_DIGEST_MD2 = 5, /* obsolete */
- PGP_DIGEST_TIGER192 = 6, /* obsolete */
+ PGP_DIGEST_TIGER192 = 6, /* obsolete */
PGP_DIGEST_HAVAL5_160 = 7, /* obsolete */
PGP_DIGEST_SHA256 = 8,
PGP_DIGEST_SHA384 = 9,
@@ -114,14 +114,15 @@ typedef struct PGP_PubKey PGP_PubKey;
typedef struct PGP_Context PGP_Context;
typedef struct PGP_S2K PGP_S2K;
-struct PGP_S2K {
- uint8 mode;
- uint8 digest_algo;
- uint8 salt[8];
- uint8 iter;
+struct PGP_S2K