mirror of
https://github.com/postgres/postgres.git
synced 2025-07-30 11:03:19 +03:00
pgindent run. Make it all clean.
This commit is contained in:
@ -4,76 +4,81 @@
|
||||
|
||||
#include "utils/elog.h"
|
||||
|
||||
static char * PARSE_BUFFER;
|
||||
static char * PARSE_BUFFER_PTR;
|
||||
static unsigned int PARSE_BUFFER_SIZE;
|
||||
static char *PARSE_BUFFER;
|
||||
static char *PARSE_BUFFER_PTR;
|
||||
static unsigned int PARSE_BUFFER_SIZE;
|
||||
static unsigned int SCANNER_POS;
|
||||
|
||||
void set_parse_buffer( char* s );
|
||||
void reset_parse_buffer( void );
|
||||
int read_parse_buffer( void );
|
||||
char * parse_buffer( void );
|
||||
char * parse_buffer_ptr( void );
|
||||
unsigned int parse_buffer_curr_char( void );
|
||||
unsigned int parse_buffer_size( void );
|
||||
unsigned int parse_buffer_pos( void );
|
||||
void set_parse_buffer(char *s);
|
||||
void reset_parse_buffer(void);
|
||||
int read_parse_buffer(void);
|
||||
char *parse_buffer(void);
|
||||
char *parse_buffer_ptr(void);
|
||||
unsigned int parse_buffer_curr_char(void);
|
||||
unsigned int parse_buffer_size(void);
|
||||
unsigned int parse_buffer_pos(void);
|
||||
|
||||
extern void cube_flush_scanner_buffer(void); /* defined in cubescan.l */
|
||||
extern void cube_flush_scanner_buffer(void); /* defined in cubescan.l */
|
||||
|
||||
void set_parse_buffer( char* s )
|
||||
void
|
||||
set_parse_buffer(char *s)
|
||||
{
|
||||
PARSE_BUFFER = s;
|
||||
PARSE_BUFFER_SIZE = strlen(s);
|
||||
if ( PARSE_BUFFER_SIZE == 0 ) {
|
||||
elog(ERROR, "cube_in: can't parse an empty string");
|
||||
}
|
||||
PARSE_BUFFER_PTR = PARSE_BUFFER;
|
||||
SCANNER_POS = 0;
|
||||
PARSE_BUFFER = s;
|
||||
PARSE_BUFFER_SIZE = strlen(s);
|
||||
if (PARSE_BUFFER_SIZE == 0)
|
||||
elog(ERROR, "cube_in: can't parse an empty string");
|
||||
PARSE_BUFFER_PTR = PARSE_BUFFER;
|
||||
SCANNER_POS = 0;
|
||||
}
|
||||
|
||||
void reset_parse_buffer( void )
|
||||
void
|
||||
reset_parse_buffer(void)
|
||||
{
|
||||
PARSE_BUFFER_PTR = PARSE_BUFFER;
|
||||
SCANNER_POS = 0;
|
||||
cube_flush_scanner_buffer();
|
||||
PARSE_BUFFER_PTR = PARSE_BUFFER;
|
||||
SCANNER_POS = 0;
|
||||
cube_flush_scanner_buffer();
|
||||
}
|
||||
|
||||
int read_parse_buffer( void )
|
||||
int
|
||||
read_parse_buffer(void)
|
||||
{
|
||||
int c;
|
||||
/*
|
||||
c = *PARSE_BUFFER_PTR++;
|
||||
SCANNER_POS++;
|
||||
*/
|
||||
c = PARSE_BUFFER[SCANNER_POS];
|
||||
if(SCANNER_POS < PARSE_BUFFER_SIZE)
|
||||
SCANNER_POS++;
|
||||
return c;
|
||||
int c;
|
||||
|
||||
/*
|
||||
* c = *PARSE_BUFFER_PTR++; SCANNER_POS++;
|
||||
*/
|
||||
c = PARSE_BUFFER[SCANNER_POS];
|
||||
if (SCANNER_POS < PARSE_BUFFER_SIZE)
|
||||
SCANNER_POS++;
|
||||
return c;
|
||||
}
|
||||
|
||||
char * parse_buffer( void )
|
||||
char *
|
||||
parse_buffer(void)
|
||||
{
|
||||
return PARSE_BUFFER;
|
||||
return PARSE_BUFFER;
|
||||
}
|
||||
|
||||
unsigned int parse_buffer_curr_char( void )
|
||||
unsigned int
|
||||
parse_buffer_curr_char(void)
|
||||
{
|
||||
return PARSE_BUFFER[SCANNER_POS];
|
||||
return PARSE_BUFFER[SCANNER_POS];
|
||||
}
|
||||
|
||||
char * parse_buffer_ptr( void )
|
||||
char *
|
||||
parse_buffer_ptr(void)
|
||||
{
|
||||
return PARSE_BUFFER_PTR;
|
||||
return PARSE_BUFFER_PTR;
|
||||
}
|
||||
|
||||
unsigned int parse_buffer_pos( void )
|
||||
unsigned int
|
||||
parse_buffer_pos(void)
|
||||
{
|
||||
return SCANNER_POS;
|
||||
return SCANNER_POS;
|
||||
}
|
||||
|
||||
unsigned int parse_buffer_size( void )
|
||||
unsigned int
|
||||
parse_buffer_size(void)
|
||||
{
|
||||
return PARSE_BUFFER_SIZE;
|
||||
return PARSE_BUFFER_SIZE;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
extern void set_parse_buffer( char* s );
|
||||
extern void reset_parse_buffer( void );
|
||||
extern int read_parse_buffer( void );
|
||||
extern char * parse_buffer( void );
|
||||
extern char * parse_buffer_ptr( void );
|
||||
extern unsigned int parse_buffer_curr_char( void );
|
||||
extern unsigned int parse_buffer_pos( void );
|
||||
extern unsigned int parse_buffer_size( void );
|
||||
extern void set_parse_buffer(char *s);
|
||||
extern void reset_parse_buffer(void);
|
||||
extern int read_parse_buffer(void);
|
||||
extern char *parse_buffer(void);
|
||||
extern char *parse_buffer_ptr(void);
|
||||
extern unsigned int parse_buffer_curr_char(void);
|
||||
extern unsigned int parse_buffer_pos(void);
|
||||
extern unsigned int parse_buffer_size(void);
|
||||
|
1646
contrib/cube/cube.c
1646
contrib/cube/cube.c
File diff suppressed because it is too large
Load Diff
@ -1,5 +1,6 @@
|
||||
typedef struct NDBOX {
|
||||
unsigned int size; /* required to be a Postgres varlena type */
|
||||
unsigned int dim;
|
||||
float x[1];
|
||||
} NDBOX;
|
||||
typedef struct NDBOX
|
||||
{
|
||||
unsigned int size; /* required to be a Postgres varlena type */
|
||||
unsigned int dim;
|
||||
float x[1];
|
||||
} NDBOX;
|
||||
|
@ -9,7 +9,7 @@
|
||||
const int EARTH_RADIUS = 3958.747716;
|
||||
const int TWO_PI = 2.0 * M_PI;
|
||||
|
||||
double *geo_distance(Point *pt1, Point *pt2);
|
||||
double *geo_distance(Point *pt1, Point *pt2);
|
||||
|
||||
|
||||
/******************************************************
|
||||
|
@ -20,7 +20,7 @@ main(int argc, char **argv)
|
||||
char attname[256];
|
||||
char typname[256];
|
||||
int count;
|
||||
char optstr[256];
|
||||
char optstr[256];
|
||||
|
||||
if (argc != 2)
|
||||
halt("Usage: %s database\n", argv[0]);
|
||||
|
@ -62,11 +62,11 @@ select p.* from product p, title_fti f1, title_fti f2 where
|
||||
that can build the final query automatigally?
|
||||
*/
|
||||
|
||||
extern Datum fti(PG_FUNCTION_ARGS);
|
||||
static char *breakup(char *, char *);
|
||||
static bool is_stopword(char *);
|
||||
extern Datum fti(PG_FUNCTION_ARGS);
|
||||
static char *breakup(char *, char *);
|
||||
static bool is_stopword(char *);
|
||||
|
||||
static bool new_tuple = false;
|
||||
static bool new_tuple = false;
|
||||
|
||||
|
||||
/* THIS LIST MUST BE IN SORTED ORDER, A BINARY SEARCH IS USED!!!! */
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* PostgreSQL type definitions for managed LargeObjects.
|
||||
*
|
||||
* $Header: /cvsroot/pgsql/contrib/lo/lo.c,v 1.7 2001/02/10 02:31:25 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/contrib/lo/lo.c,v 1.8 2001/03/22 03:59:09 momjian Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
@ -36,7 +36,7 @@ Blob *lo_in(char *str); /* Create from String */
|
||||
char *lo_out(Blob * addr);/* Output oid as String */
|
||||
Oid lo_oid(Blob * addr);/* Return oid as an oid */
|
||||
Blob *lo(Oid oid); /* Return Blob based on oid */
|
||||
Datum lo_manage(PG_FUNCTION_ARGS); /* Trigger handler */
|
||||
Datum lo_manage(PG_FUNCTION_ARGS); /* Trigger handler */
|
||||
|
||||
/*
|
||||
* This creates a large object, and sets its OID to the value in the
|
||||
@ -69,7 +69,7 @@ lo_in(char *str)
|
||||
* There is no Oid passed, so create a new one
|
||||
*/
|
||||
oid = DatumGetObjectId(DirectFunctionCall1(lo_creat,
|
||||
Int32GetDatum(INV_READ | INV_WRITE)));
|
||||
Int32GetDatum(INV_READ | INV_WRITE)));
|
||||
if (oid == InvalidOid)
|
||||
elog(ERROR, "lo_in: InvalidOid returned from lo_creat");
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
/*
|
||||
oid2name; a postgresql 7.1 (+?) app to map OIDs on the filesystem
|
||||
to table and database names.
|
||||
to table and database names.
|
||||
|
||||
b. palmer, bpalmer@crimelabs.net 1-17-2001
|
||||
|
||||
@ -13,433 +13,439 @@
|
||||
#include "libpq-fe.h"
|
||||
|
||||
/* these are the opts structures for command line params */
|
||||
struct options {
|
||||
int getdatabase;
|
||||
int gettable;
|
||||
int getoid;
|
||||
|
||||
int systables;
|
||||
struct options
|
||||
{
|
||||
int getdatabase;
|
||||
int gettable;
|
||||
int getoid;
|
||||
|
||||
int remotehost;
|
||||
int remoteport;
|
||||
int remoteuser;
|
||||
int remotepass;
|
||||
int systables;
|
||||
|
||||
int _oid;
|
||||
char _dbname[128];
|
||||
char _tbname[128];
|
||||
int remotehost;
|
||||
int remoteport;
|
||||
int remoteuser;
|
||||
int remotepass;
|
||||
|
||||
char _hostname[128];
|
||||
char _port[6];
|
||||
char _username[128];
|
||||
char _password[128];
|
||||
int _oid;
|
||||
char _dbname[128];
|
||||
char _tbname[128];
|
||||
|
||||
char _hostname[128];
|
||||
char _port[6];
|
||||
char _username[128];
|
||||
char _password[128];
|
||||
};
|
||||
|
||||
/* function prototypes */
|
||||
void get_opts(int, char **, struct options *);
|
||||
PGconn *sql_conn(char *, struct options *);
|
||||
void sql_exec_error (int);
|
||||
int sql_exec(PGconn *, char *, int);
|
||||
void sql_exec_dumpdb(PGconn *);
|
||||
void sql_exec_dumptable(PGconn *, int);
|
||||
void sql_exec_searchtable(PGconn *, char *);
|
||||
void sql_exec_searchoid(PGconn *, int);
|
||||
void get_opts(int, char **, struct options *);
|
||||
PGconn *sql_conn(char *, struct options *);
|
||||
void sql_exec_error(int);
|
||||
int sql_exec(PGconn *, char *, int);
|
||||
void sql_exec_dumpdb(PGconn *);
|
||||
void sql_exec_dumptable(PGconn *, int);
|
||||
void sql_exec_searchtable(PGconn *, char *);
|
||||
void sql_exec_searchoid(PGconn *, int);
|
||||
|
||||
/* fuction to parse command line options and check for some usage errors. */
|
||||
void get_opts(int argc, char **argv, struct options *my_opts)
|
||||
void
|
||||
get_opts(int argc, char **argv, struct options * my_opts)
|
||||
{
|
||||
char c;
|
||||
char c;
|
||||
|
||||
/* set the defaults */
|
||||
my_opts->getdatabase = 0;
|
||||
my_opts->gettable = 0;
|
||||
my_opts->getoid = 0;
|
||||
/* set the defaults */
|
||||
my_opts->getdatabase = 0;
|
||||
my_opts->gettable = 0;
|
||||
my_opts->getoid = 0;
|
||||
|
||||
my_opts->systables = 0;
|
||||
my_opts->systables = 0;
|
||||
|
||||
my_opts->remotehost = 0;
|
||||
my_opts->remoteport = 0;
|
||||
my_opts->remoteuser = 0;
|
||||
my_opts->remotepass = 0;
|
||||
my_opts->remotehost = 0;
|
||||
my_opts->remoteport = 0;
|
||||
my_opts->remoteuser = 0;
|
||||
my_opts->remotepass = 0;
|
||||
|
||||
/* get opts */
|
||||
while( (c = getopt(argc, argv, "H:p:U:P:d:t:o:xh?")) != EOF)
|
||||
{
|
||||
switch(c)
|
||||
/* get opts */
|
||||
while ((c = getopt(argc, argv, "H:p:U:P:d:t:o:xh?")) != EOF)
|
||||
{
|
||||
/* specify the database */
|
||||
case 'd':
|
||||
my_opts->getdatabase = 1;
|
||||
sscanf(optarg, "%s", my_opts->_dbname);
|
||||
break;
|
||||
switch (c)
|
||||
{
|
||||
/* specify the database */
|
||||
case 'd':
|
||||
my_opts->getdatabase = 1;
|
||||
sscanf(optarg, "%s", my_opts->_dbname);
|
||||
break;
|
||||
|
||||
/* specify the table name */
|
||||
case 't':
|
||||
/* make sure we set the database first */
|
||||
if(!my_opts->getdatabase)
|
||||
{
|
||||
fprintf(stderr, "Sorry, but you must specify a database to dump from.\n");
|
||||
exit(1);
|
||||
}
|
||||
/* make sure we don't try to do a -o also */
|
||||
if(my_opts->getoid)
|
||||
{
|
||||
fprintf(stderr, "Sorry, you can only specify either oid or table\n");
|
||||
exit(1);
|
||||
}
|
||||
/* specify the table name */
|
||||
case 't':
|
||||
/* make sure we set the database first */
|
||||
if (!my_opts->getdatabase)
|
||||
{
|
||||
fprintf(stderr, "Sorry, but you must specify a database to dump from.\n");
|
||||
exit(1);
|
||||
}
|
||||
/* make sure we don't try to do a -o also */
|
||||
if (my_opts->getoid)
|
||||
{
|
||||
fprintf(stderr, "Sorry, you can only specify either oid or table\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
my_opts->gettable = 1;
|
||||
sscanf(optarg, "%s", my_opts->_tbname);
|
||||
my_opts->gettable = 1;
|
||||
sscanf(optarg, "%s", my_opts->_tbname);
|
||||
|
||||
break;
|
||||
break;
|
||||
|
||||
/* specify the oid int */
|
||||
case 'o':
|
||||
/* make sure we set the database first */
|
||||
if(!my_opts->getdatabase)
|
||||
{
|
||||
fprintf(stderr, "Sorry, but you must specify a database to dump from.\n");
|
||||
exit(1);
|
||||
}
|
||||
/* make sure we don't try to do a -t also */
|
||||
if(my_opts->gettable)
|
||||
{
|
||||
fprintf(stderr, "Sorry, you can only specify either oid or table\n");
|
||||
exit(1);
|
||||
}
|
||||
/* specify the oid int */
|
||||
case 'o':
|
||||
/* make sure we set the database first */
|
||||
if (!my_opts->getdatabase)
|
||||
{
|
||||
fprintf(stderr, "Sorry, but you must specify a database to dump from.\n");
|
||||
exit(1);
|
||||
}
|
||||
/* make sure we don't try to do a -t also */
|
||||
if (my_opts->gettable)
|
||||
{
|
||||
fprintf(stderr, "Sorry, you can only specify either oid or table\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
my_opts->getoid = 1;
|
||||
sscanf(optarg, "%i", &my_opts->_oid);
|
||||
my_opts->getoid = 1;
|
||||
sscanf(optarg, "%i", &my_opts->_oid);
|
||||
|
||||
break;
|
||||
break;
|
||||
|
||||
/* host to connect to */
|
||||
case 'H':
|
||||
my_opts->remotehost = 1;
|
||||
sscanf(optarg, "%s", my_opts->_hostname);
|
||||
break;
|
||||
/* host to connect to */
|
||||
case 'H':
|
||||
my_opts->remotehost = 1;
|
||||
sscanf(optarg, "%s", my_opts->_hostname);
|
||||
break;
|
||||
|
||||
/* port to connect to on remote host */
|
||||
case 'p':
|
||||
my_opts->remoteport = 1;
|
||||
sscanf(optarg, "%s", my_opts->_port);
|
||||
break;
|
||||
/* port to connect to on remote host */
|
||||
case 'p':
|
||||
my_opts->remoteport = 1;
|
||||
sscanf(optarg, "%s", my_opts->_port);
|
||||
break;
|
||||
|
||||
/* username */
|
||||
case 'U':
|
||||
my_opts->remoteuser = 1;
|
||||
sscanf(optarg, "%s", my_opts->_username);
|
||||
break;
|
||||
/* username */
|
||||
case 'U':
|
||||
my_opts->remoteuser = 1;
|
||||
sscanf(optarg, "%s", my_opts->_username);
|
||||
break;
|
||||
|
||||
/* password */
|
||||
case 'P':
|
||||
my_opts->remotepass = 1;
|
||||
sscanf(optarg, "%s", my_opts->_password);
|
||||
break;
|
||||
/* password */
|
||||
case 'P':
|
||||
my_opts->remotepass = 1;
|
||||
sscanf(optarg, "%s", my_opts->_password);
|
||||
break;
|
||||
|
||||
/* display system tables */
|
||||
case 'x':
|
||||
/* display system tables */
|
||||
case 'x':
|
||||
|
||||
my_opts->systables = 1;
|
||||
break;
|
||||
my_opts->systables = 1;
|
||||
break;
|
||||
|
||||
/* help! (ugly in code for easier editing) */
|
||||
case '?':
|
||||
case 'h':
|
||||
fprintf(stderr, "\n\
|
||||
/* help! (ugly in code for easier editing) */
|
||||
case '?':
|
||||
case 'h':
|
||||
fprintf(stderr, "\n\
|
||||
Usage: pg_oid2name [-d database [-x] ] [-t table | -o oid] \n\
|
||||
dafault action display all databases
|
||||
dafault action display all databases\n\
|
||||
-d database database to oid2name\n\
|
||||
-x display system tables\n\
|
||||
-t table | -o oid search for table name (-t) or\n\
|
||||
oid (-o) in -d database
|
||||
oid (-o) in -d database\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\n\
|
||||
");
|
||||
exit(1);
|
||||
break;
|
||||
exit(1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* establish connection with database. */
|
||||
PGconn *sql_conn(char *dbName, struct options *my_opts)
|
||||
PGconn *
|
||||
sql_conn(char *dbName, struct options * my_opts)
|
||||
{
|
||||
char *pghost, *pgport;
|
||||
char *pgoptions, *pgtty;
|
||||
char *pguser, *pgpass;
|
||||
char *pghost,
|
||||
*pgport;
|
||||
char *pgoptions,
|
||||
*pgtty;
|
||||
char *pguser,
|
||||
*pgpass;
|
||||
|
||||
PGconn *conn;
|
||||
PGconn *conn;
|
||||
|
||||
pghost = NULL;
|
||||
pgport = NULL;
|
||||
|
||||
pgoptions = NULL; /* special options to start up the backend
|
||||
* server */
|
||||
pgtty = NULL; /* debugging tty for the backend server */
|
||||
pghost = NULL;
|
||||
pgport = NULL;
|
||||
|
||||
pguser = NULL;
|
||||
pgpass = NULL;
|
||||
pgoptions = NULL; /* special options to start up the backend
|
||||
* server */
|
||||
pgtty = NULL; /* debugging tty for the backend server */
|
||||
|
||||
/* override the NULLs with the user params if passed */
|
||||
if(my_opts->remotehost)
|
||||
{
|
||||
pghost = (char *) malloc (128);
|
||||
sscanf(my_opts->_hostname, "%s", pghost);
|
||||
}
|
||||
|
||||
if(my_opts->remoteport)
|
||||
{
|
||||
pgport = (char *) malloc (6);
|
||||
sscanf(my_opts->_port, "%s", pgport);
|
||||
}
|
||||
pguser = NULL;
|
||||
pgpass = NULL;
|
||||
|
||||
if(my_opts->remoteuser)
|
||||
{
|
||||
pguser = (char *) malloc (128);
|
||||
sscanf(my_opts->_username, "%s", pguser);
|
||||
}
|
||||
/* override the NULLs with the user params if passed */
|
||||
if (my_opts->remotehost)
|
||||
{
|
||||
pghost = (char *) malloc(128);
|
||||
sscanf(my_opts->_hostname, "%s", pghost);
|
||||
}
|
||||
|
||||
if(my_opts->remotepass)
|
||||
{
|
||||
pgpass = (char *) malloc (128);
|
||||
sscanf(my_opts->_password, "%s", pgpass);
|
||||
}
|
||||
if (my_opts->remoteport)
|
||||
{
|
||||
pgport = (char *) malloc(6);
|
||||
sscanf(my_opts->_port, "%s", pgport);
|
||||
}
|
||||
|
||||
/* login */
|
||||
conn = PQsetdbLogin(pghost, pgport, pgoptions, pgtty, dbName, pguser, pgpass);
|
||||
if (my_opts->remoteuser)
|
||||
{
|
||||
pguser = (char *) malloc(128);
|
||||
sscanf(my_opts->_username, "%s", pguser);
|
||||
}
|
||||
|
||||
/* deal with errors */
|
||||
if (PQstatus(conn) == CONNECTION_BAD)
|
||||
{
|
||||
fprintf(stderr, "Connection to database '%s' failed.\n", dbName);
|
||||
fprintf(stderr, "%s", PQerrorMessage(conn));
|
||||
|
||||
|
||||
PQfinish(conn);
|
||||
exit(1);
|
||||
if (my_opts->remotepass)
|
||||
{
|
||||
pgpass = (char *) malloc(128);
|
||||
sscanf(my_opts->_password, "%s", pgpass);
|
||||
}
|
||||
|
||||
}
|
||||
/* login */
|
||||
conn = PQsetdbLogin(pghost, pgport, pgoptions, pgtty, dbName, pguser, pgpass);
|
||||
|
||||
/* return the conn if good */
|
||||
return conn;
|
||||
/* deal with errors */
|
||||
if (PQstatus(conn) == CONNECTION_BAD)
|
||||
{
|
||||
fprintf(stderr, "Connection to database '%s' failed.\n", dbName);
|
||||
fprintf(stderr, "%s", PQerrorMessage(conn));
|
||||
|
||||
|
||||
PQfinish(conn);
|
||||
exit(1);
|
||||
|
||||
}
|
||||
|
||||
/* return the conn if good */
|
||||
return conn;
|
||||
}
|
||||
|
||||
/* If the sql_ command has an error, this function looks up the error number and prints it out. */
|
||||
void sql_exec_error (int error_number)
|
||||
void
|
||||
sql_exec_error(int error_number)
|
||||
{
|
||||
fprintf(stderr, "Error number %i.\n", error_number);
|
||||
switch(error_number)
|
||||
{
|
||||
case 3:
|
||||
fprintf(stderr, "Error: PGRES_COPY_OUT\n");
|
||||
break;
|
||||
|
||||
case 4:
|
||||
fprintf(stderr, "Error: PGRES_COPY_IN\n");
|
||||
break;
|
||||
|
||||
case 5:
|
||||
fprintf(stderr, "Error: PGRES_BAD_RESPONCE\n");
|
||||
break;
|
||||
|
||||
case 6:
|
||||
fprintf(stderr, "Error: PGRES_NONFATAL_ERROR\n");
|
||||
break;
|
||||
|
||||
case 7:
|
||||
fprintf(stderr, "Error: PGRES_FATAL_ERROR\n");
|
||||
break;
|
||||
}
|
||||
fprintf(stderr, "Error number %i.\n", error_number);
|
||||
switch (error_number)
|
||||
{
|
||||
case 3:
|
||||
fprintf(stderr, "Error: PGRES_COPY_OUT\n");
|
||||
break;
|
||||
|
||||
case 4:
|
||||
fprintf(stderr, "Error: PGRES_COPY_IN\n");
|
||||
break;
|
||||
|
||||
case 5:
|
||||
fprintf(stderr, "Error: PGRES_BAD_RESPONCE\n");
|
||||
break;
|
||||
|
||||
case 6:
|
||||
fprintf(stderr, "Error: PGRES_NONFATAL_ERROR\n");
|
||||
break;
|
||||
|
||||
case 7:
|
||||
fprintf(stderr, "Error: PGRES_FATAL_ERROR\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* actual code to make call to the database and print the output data */
|
||||
int sql_exec(PGconn *conn, char *todo, int match)
|
||||
int
|
||||
sql_exec(PGconn *conn, char *todo, int match)
|
||||
{
|
||||
PGresult *res;
|
||||
PGresult *res;
|
||||
|
||||
int numbfields;
|
||||
int error_number;
|
||||
int i, len;
|
||||
int numbfields;
|
||||
int error_number;
|
||||
int i,
|
||||
len;
|
||||
|
||||
/* make the call */
|
||||
res = PQexec(conn, todo);
|
||||
/* make the call */
|
||||
res = PQexec(conn, todo);
|
||||
|
||||
/* check and deal with errors */
|
||||
if (!res || PQresultStatus(res) > 2)
|
||||
{
|
||||
error_number = PQresultStatus(res);
|
||||
fprintf(stderr, "There was an error in the SQL command:\n%s\n", todo);
|
||||
sql_exec_error(error_number);
|
||||
fprintf(stderr, "PQerrorMessage = %s\n", PQerrorMessage(conn));
|
||||
|
||||
PQclear(res);
|
||||
PQfinish(conn);
|
||||
exit(-1);
|
||||
}
|
||||
/* check and deal with errors */
|
||||
if (!res || PQresultStatus(res) > 2)
|
||||
{
|
||||
error_number = PQresultStatus(res);
|
||||
fprintf(stderr, "There was an error in the SQL command:\n%s\n", todo);
|
||||
sql_exec_error(error_number);
|
||||
fprintf(stderr, "PQerrorMessage = %s\n", PQerrorMessage(conn));
|
||||
|
||||
/* get the number of fields */
|
||||
numbfields = PQntuples(res);
|
||||
PQclear(res);
|
||||
PQfinish(conn);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
/* if we only expect 1 and there mode than, return -2 */
|
||||
if(match == 1 && numbfields > 1)
|
||||
return -2;
|
||||
/* get the number of fields */
|
||||
numbfields = PQntuples(res);
|
||||
|
||||
/* return -1 if there aren't any returns */
|
||||
if(match == 1 && numbfields < 1)
|
||||
return -1;
|
||||
/* if we only expect 1 and there mode than, return -2 */
|
||||
if (match == 1 && numbfields > 1)
|
||||
return -2;
|
||||
|
||||
/* for each row, dump the information */
|
||||
for(i = 0; i < numbfields; i++)
|
||||
{
|
||||
len = strlen(PQgetvalue(res, i, 0));
|
||||
/* return -1 if there aren't any returns */
|
||||
if (match == 1 && numbfields < 1)
|
||||
return -1;
|
||||
|
||||
fprintf(stdout, "%-6s = %s\n", PQgetvalue(res, i, 0), PQgetvalue(res, i, 1));
|
||||
}
|
||||
/* for each row, dump the information */
|
||||
for (i = 0; i < numbfields; i++)
|
||||
{
|
||||
len = strlen(PQgetvalue(res, i, 0));
|
||||
|
||||
/* clean the PGconn once done */
|
||||
PQclear(res);
|
||||
fprintf(stdout, "%-6s = %s\n", PQgetvalue(res, i, 0), PQgetvalue(res, i, 1));
|
||||
}
|
||||
|
||||
return 0;
|
||||
/* clean the PGconn once done */
|
||||
PQclear(res);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* dump all databases know by the system table */
|
||||
void sql_exec_dumpdb(PGconn *conn)
|
||||
void
|
||||
sql_exec_dumpdb(PGconn *conn)
|
||||
{
|
||||
char *todo;
|
||||
char *todo;
|
||||
|
||||
todo = (char *) malloc (1024);
|
||||
todo = (char *) malloc(1024);
|
||||
|
||||
/* get the oid and database name from the system pg_database table */
|
||||
sprintf(todo, "select oid,datname from pg_database");
|
||||
/* get the oid and database name from the system pg_database table */
|
||||
sprintf(todo, "select oid,datname from pg_database");
|
||||
|
||||
sql_exec(conn, todo, 0);
|
||||
sql_exec(conn, todo, 0);
|
||||
}
|
||||
|
||||
/* display all tables in whatever db we are connected to. don't display the
|
||||
system tables by default */
|
||||
void sql_exec_dumptable(PGconn *conn, int systables)
|
||||
void
|
||||
sql_exec_dumptable(PGconn *conn, int systables)
|
||||
{
|
||||
char *todo;
|
||||
char *todo;
|
||||
|
||||
todo = (char *) malloc (1024);
|
||||
todo = (char *) malloc(1024);
|
||||
|
||||
/* don't exclude the systables if this is set */
|
||||
if(systables == 1)
|
||||
sprintf(todo, "select relfilenode,relname from pg_class order by relname");
|
||||
else
|
||||
sprintf(todo, "select relfilenode,relname from pg_class where relname not like 'pg_%%' order by relname");
|
||||
/* don't exclude the systables if this is set */
|
||||
if (systables == 1)
|
||||
sprintf(todo, "select relfilenode,relname from pg_class order by relname");
|
||||
else
|
||||
sprintf(todo, "select relfilenode,relname from pg_class where relname not like 'pg_%%' order by relname");
|
||||
|
||||
sql_exec(conn, todo, 0);
|
||||
sql_exec(conn, todo, 0);
|
||||
}
|
||||
|
||||
/* display the oid for a given tablename for whatever db we are connected
|
||||
to. do we want to allow %bar% in the search? Not now. */
|
||||
void sql_exec_searchtable(PGconn *conn, char *tablename)
|
||||
to. do we want to allow %bar% in the search? Not now. */
|
||||
void
|
||||
sql_exec_searchtable(PGconn *conn, char *tablename)
|
||||
{
|
||||
int returnvalue;
|
||||
char *todo;
|
||||
int returnvalue;
|
||||
char *todo;
|
||||
|
||||
todo = (char *) malloc (1024);
|
||||
todo = (char *) malloc(1024);
|
||||
|
||||
/* get the oid and tablename where the name matches tablename */
|
||||
sprintf(todo, "select relfilenode,relname from pg_class where relname = '%s'", tablename);
|
||||
/* get the oid and tablename where the name matches tablename */
|
||||
sprintf(todo, "select relfilenode,relname from pg_class where relname = '%s'", tablename);
|
||||
|
||||
returnvalue = sql_exec(conn, todo, 1);
|
||||
returnvalue = sql_exec(conn, todo, 1);
|
||||
|
||||
/* deal with the return errors */
|
||||
if(returnvalue == -1)
|
||||
{
|
||||
printf("No tables with that name found\n");
|
||||
}
|
||||
|
||||
if(returnvalue == -2)
|
||||
{
|
||||
printf("VERY scary: more than one table with that name found!!\n");
|
||||
}
|
||||
/* deal with the return errors */
|
||||
if (returnvalue == -1)
|
||||
printf("No tables with that name found\n");
|
||||
|
||||
if (returnvalue == -2)
|
||||
printf("VERY scary: more than one table with that name found!!\n");
|
||||
}
|
||||
|
||||
/* same as above */
|
||||
void sql_exec_searchoid(PGconn *conn, int oid)
|
||||
void
|
||||
sql_exec_searchoid(PGconn *conn, int oid)
|
||||
{
|
||||
int returnvalue;
|
||||
char *todo;
|
||||
int returnvalue;
|
||||
char *todo;
|
||||
|
||||
todo = (char *) malloc (1024);
|
||||
todo = (char *) malloc(1024);
|
||||
|
||||
sprintf(todo, "select relfilenode,relname from pg_class where oid = %i", oid);
|
||||
sprintf(todo, "select relfilenode,relname from pg_class where oid = %i", oid);
|
||||
|
||||
returnvalue = sql_exec(conn, todo, 1);
|
||||
returnvalue = sql_exec(conn, todo, 1);
|
||||
|
||||
if(returnvalue == -1)
|
||||
{
|
||||
printf("No tables with that oid found\n");
|
||||
}
|
||||
|
||||
if(returnvalue == -2)
|
||||
{
|
||||
printf("VERY scary: more than one table with that oid found!!\n");
|
||||
}
|
||||
if (returnvalue == -1)
|
||||
printf("No tables with that oid found\n");
|
||||
|
||||
if (returnvalue == -2)
|
||||
printf("VERY scary: more than one table with that oid found!!\n");
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
struct options *my_opts;
|
||||
PGconn *pgconn;
|
||||
struct options *my_opts;
|
||||
PGconn *pgconn;
|
||||
|
||||
my_opts = (struct options *) malloc (sizeof(struct options));
|
||||
my_opts = (struct options *) malloc(sizeof(struct options));
|
||||
|
||||
/* parse the opts */
|
||||
get_opts(argc, argv, my_opts);
|
||||
/* parse the opts */
|
||||
get_opts(argc, argv, my_opts);
|
||||
|
||||
/* display all the tables in the database */
|
||||
if(my_opts->getdatabase & my_opts->gettable)
|
||||
{
|
||||
printf("Oid of table %s from database \"%s\":\n", my_opts->_tbname, my_opts->_dbname);
|
||||
printf("_______________________________\n");
|
||||
/* display all the tables in the database */
|
||||
if (my_opts->getdatabase & my_opts->gettable)
|
||||
{
|
||||
printf("Oid of table %s from database \"%s\":\n", my_opts->_tbname, my_opts->_dbname);
|
||||
printf("_______________________________\n");
|
||||
|
||||
pgconn = sql_conn(my_opts->_dbname, my_opts);
|
||||
sql_exec_searchtable(pgconn, my_opts->_tbname);
|
||||
PQfinish(pgconn);
|
||||
pgconn = sql_conn(my_opts->_dbname, my_opts);
|
||||
sql_exec_searchtable(pgconn, my_opts->_tbname);
|
||||
PQfinish(pgconn);
|
||||
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* search for the tablename of the given OID */
|
||||
if(my_opts->getdatabase & my_opts->getoid)
|
||||
{
|
||||
printf("Tablename of oid %i from database \"%s\":\n", my_opts->_oid, my_opts->_dbname);
|
||||
printf("---------------------------------\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
pgconn = sql_conn(my_opts->_dbname, my_opts);
|
||||
sql_exec_searchoid(pgconn, my_opts->_oid);
|
||||
PQfinish(pgconn);
|
||||
/* search for the tablename of the given OID */
|
||||
if (my_opts->getdatabase & my_opts->getoid)
|
||||
{
|
||||
printf("Tablename of oid %i from database \"%s\":\n", my_opts->_oid, my_opts->_dbname);
|
||||
printf("---------------------------------\n");
|
||||
|
||||
exit(1);
|
||||
}
|
||||
pgconn = sql_conn(my_opts->_dbname, my_opts);
|
||||
sql_exec_searchoid(pgconn, my_opts->_oid);
|
||||
PQfinish(pgconn);
|
||||
|
||||
/* search for the oid for the given tablename */
|
||||
if(my_opts->getdatabase)
|
||||
{
|
||||
printf("All tables from database \"%s\":\n", my_opts->_dbname);
|
||||
printf("---------------------------------\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
pgconn = sql_conn(my_opts->_dbname, my_opts);
|
||||
sql_exec_dumptable(pgconn, my_opts->systables);
|
||||
PQfinish(pgconn);
|
||||
/* search for the oid for the given tablename */
|
||||
if (my_opts->getdatabase)
|
||||
{
|
||||
printf("All tables from database \"%s\":\n", my_opts->_dbname);
|
||||
printf("---------------------------------\n");
|
||||
|
||||
exit(1);
|
||||
}
|
||||
pgconn = sql_conn(my_opts->_dbname, my_opts);
|
||||
sql_exec_dumptable(pgconn, my_opts->systables);
|
||||
PQfinish(pgconn);
|
||||
|
||||
/* display all the databases for the server we are connected to.. */
|
||||
printf("All databases:\n");
|
||||
printf("---------------------------------\n");
|
||||
|
||||
pgconn = sql_conn("template1", my_opts);
|
||||
sql_exec_dumpdb(pgconn);
|
||||
PQfinish(pgconn);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
exit(0);
|
||||
/* display all the databases for the server we are connected to.. */
|
||||
printf("All databases:\n");
|
||||
printf("---------------------------------\n");
|
||||
|
||||
pgconn = sql_conn("template1", my_opts);
|
||||
sql_exec_dumpdb(pgconn);
|
||||
PQfinish(pgconn);
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
* copyright (c) Oliver Elphick <olly@lfix.co.uk>, 2001;
|
||||
* licence: BSD
|
||||
*
|
||||
* $Header: /cvsroot/pgsql/contrib/pg_controldata/Attic/pg_controldata.c,v 1.2 2001/03/13 01:17:40 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/contrib/pg_controldata/Attic/pg_controldata.c,v 1.3 2001/03/22 03:59:09 momjian Exp $
|
||||
*/
|
||||
#include "postgres.h"
|
||||
|
||||
@ -24,7 +24,7 @@ dbState(DBState state)
|
||||
{
|
||||
switch (state)
|
||||
{
|
||||
case DB_STARTUP:
|
||||
case DB_STARTUP:
|
||||
return "STARTUP";
|
||||
case DB_SHUTDOWNED:
|
||||
return "SHUTDOWNED";
|
||||
@ -43,16 +43,17 @@ int
|
||||
main()
|
||||
{
|
||||
ControlFileData ControlFile;
|
||||
int fd;
|
||||
char ControlFilePath[MAXPGPATH];
|
||||
char *DataDir;
|
||||
crc64 crc;
|
||||
char pgctime_str[32];
|
||||
char ckpttime_str[32];
|
||||
int fd;
|
||||
char ControlFilePath[MAXPGPATH];
|
||||
char *DataDir;
|
||||
crc64 crc;
|
||||
char pgctime_str[32];
|
||||
char ckpttime_str[32];
|
||||
|
||||
DataDir = getenv("PGDATA");
|
||||
if ( DataDir == NULL ) {
|
||||
fprintf(stderr,"PGDATA is not defined\n");
|
||||
if (DataDir == NULL)
|
||||
{
|
||||
fprintf(stderr, "PGDATA is not defined\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@ -73,8 +74,8 @@ main()
|
||||
|
||||
/* Check the CRC. */
|
||||
INIT_CRC64(crc);
|
||||
COMP_CRC64(crc,
|
||||
(char*) &ControlFile + sizeof(crc64),
|
||||
COMP_CRC64(crc,
|
||||
(char *) &ControlFile + sizeof(crc64),
|
||||
sizeof(ControlFileData) - sizeof(crc64));
|
||||
FIN_CRC64(crc);
|
||||
|
||||
@ -93,7 +94,7 @@ main()
|
||||
"Database state: %s\n"
|
||||
"pg_control last modified: %s\n"
|
||||
"Current log file id: %u\n"
|
||||
"Next log file segment: %u\n"
|
||||
"Next log file segment: %u\n"
|
||||
"Latest checkpoint location: %X/%X\n"
|
||||
"Prior checkpoint location: %X/%X\n"
|
||||
"Latest checkpoint's REDO location: %X/%X\n"
|
||||
|
@ -1,20 +1,20 @@
|
||||
/* -------------------------------------------------------------------------
|
||||
* pg_dumplo
|
||||
*
|
||||
* $Header: /cvsroot/pgsql/contrib/pg_dumplo/Attic/lo_export.c,v 1.5 2001/01/24 19:42:44 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/contrib/pg_dumplo/Attic/lo_export.c,v 1.6 2001/03/22 03:59:10 momjian Exp $
|
||||
*
|
||||
* Karel Zak 1999-2000
|
||||
* -------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <errno.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <libpq-fe.h>
|
||||
@ -22,17 +22,17 @@
|
||||
|
||||
#include "pg_dumplo.h"
|
||||
|
||||
extern int errno;
|
||||
extern int errno;
|
||||
|
||||
|
||||
void
|
||||
load_lolist( LODumpMaster *pgLO )
|
||||
void
|
||||
load_lolist(LODumpMaster * pgLO)
|
||||
{
|
||||
LOlist *ll;
|
||||
int i;
|
||||
int n;
|
||||
LOlist *ll;
|
||||
int i;
|
||||
int n;
|
||||
|
||||
/* ----------
|
||||
/* ----------
|
||||
* Now find any candidate tables who have columns of type oid.
|
||||
*
|
||||
* NOTE: System tables including pg_largeobject will be ignored.
|
||||
@ -40,8 +40,8 @@ load_lolist( LODumpMaster *pgLO )
|
||||
*
|
||||
* NOTE: the system oid column is ignored, as it has attnum < 1.
|
||||
* This shouldn't matter for correctness, but it saves time.
|
||||
* ----------
|
||||
*/
|
||||
* ----------
|
||||
*/
|
||||
pgLO->res = PQexec(pgLO->conn,
|
||||
"SELECT c.relname, a.attname "
|
||||
"FROM pg_class c, pg_attribute a, pg_type t "
|
||||
@ -52,43 +52,49 @@ load_lolist( LODumpMaster *pgLO )
|
||||
" AND c.relkind = 'r' "
|
||||
" AND c.relname NOT LIKE 'pg_%'");
|
||||
|
||||
if (PQresultStatus(pgLO->res) != PGRES_TUPLES_OK) {
|
||||
if (PQresultStatus(pgLO->res) != PGRES_TUPLES_OK)
|
||||
{
|
||||
fprintf(stderr, "%s: Failed to get LO OIDs:\n%s", progname,
|
||||
PQerrorMessage(pgLO->conn));
|
||||
exit(RE_ERROR);
|
||||
}
|
||||
|
||||
if ((n = PQntuples(pgLO->res)) == 0) {
|
||||
if ((n = PQntuples(pgLO->res)) == 0)
|
||||
{
|
||||
fprintf(stderr, "%s: No OID columns in the database.\n", progname);
|
||||
exit(RE_ERROR);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
pgLO->lolist = (LOlist *) malloc((n + 1) * sizeof(LOlist));
|
||||
|
||||
if (!pgLO->lolist) {
|
||||
|
||||
if (!pgLO->lolist)
|
||||
{
|
||||
fprintf(stderr, "%s: can't allocate memory\n", progname);
|
||||
exit(RE_ERROR);
|
||||
}
|
||||
|
||||
for (i = 0, ll = pgLO->lolist; i < n; i++, ll++) {
|
||||
ll->lo_table = strdup(PQgetvalue(pgLO->res, i, 0));
|
||||
ll->lo_attr = strdup(PQgetvalue(pgLO->res, i, 1));
|
||||
}
|
||||
ll->lo_table = ll->lo_attr = (char *) NULL;
|
||||
|
||||
|
||||
for (i = 0, ll = pgLO->lolist; i < n; i++, ll++)
|
||||
{
|
||||
ll->lo_table = strdup(PQgetvalue(pgLO->res, i, 0));
|
||||
ll->lo_attr = strdup(PQgetvalue(pgLO->res, i, 1));
|
||||
}
|
||||
ll->lo_table = ll->lo_attr = (char *) NULL;
|
||||
|
||||
PQclear(pgLO->res);
|
||||
}
|
||||
|
||||
void
|
||||
pglo_export(LODumpMaster *pgLO)
|
||||
void
|
||||
pglo_export(LODumpMaster * pgLO)
|
||||
{
|
||||
LOlist *ll;
|
||||
int tuples;
|
||||
LOlist *ll;
|
||||
int tuples;
|
||||
char path[BUFSIZ],
|
||||
Qbuff[QUERY_BUFSIZ];
|
||||
|
||||
if (pgLO->action != ACTION_SHOW) {
|
||||
time_t t;
|
||||
Qbuff[QUERY_BUFSIZ];
|
||||
|
||||
if (pgLO->action != ACTION_SHOW)
|
||||
{
|
||||
time_t t;
|
||||
|
||||
time(&t);
|
||||
fprintf(pgLO->index, "#\n# This is the PostgreSQL large object dump index\n#\n");
|
||||
fprintf(pgLO->index, "#\tDate: %s", ctime(&t));
|
||||
@ -97,90 +103,102 @@ pglo_export(LODumpMaster *pgLO)
|
||||
fprintf(pgLO->index, "#\tUser: %s\n", pgLO->user);
|
||||
fprintf(pgLO->index, "#\n# oid\ttable\tattribut\tinfile\n#\n");
|
||||
}
|
||||
|
||||
|
||||
pgLO->counter = 0;
|
||||
|
||||
for(ll=pgLO->lolist; ll->lo_table != NULL; ll++) {
|
||||
|
||||
for (ll = pgLO->lolist; ll->lo_table != NULL; ll++)
|
||||
{
|
||||
|
||||
/* ----------
|
||||
* Query: find the LOs referenced by this column
|
||||
* ----------
|
||||
*/
|
||||
sprintf(Qbuff, "SELECT DISTINCT l.loid FROM \"%s\" x, pg_largeobject l WHERE x.\"%s\" = l.loid",
|
||||
ll->lo_table, ll->lo_attr);
|
||||
|
||||
|
||||
/* puts(Qbuff); */
|
||||
|
||||
|
||||
pgLO->res = PQexec(pgLO->conn, Qbuff);
|
||||
|
||||
if (PQresultStatus(pgLO->res) != PGRES_TUPLES_OK) {
|
||||
if (PQresultStatus(pgLO->res) != PGRES_TUPLES_OK)
|
||||
{
|
||||
fprintf(stderr, "%s: Failed to get LO OIDs:\n%s", progname,
|
||||
PQerrorMessage(pgLO->conn));
|
||||
}
|
||||
else if ((tuples = PQntuples(pgLO->res)) == 0) {
|
||||
}
|
||||
else if ((tuples = PQntuples(pgLO->res)) == 0)
|
||||
{
|
||||
if (!pgLO->quiet && pgLO->action == ACTION_EXPORT_ATTR)
|
||||
printf("%s: no large objects in \"%s\".\"%s\"\n",
|
||||
progname, ll->lo_table, ll->lo_attr);
|
||||
} else {
|
||||
|
||||
int t;
|
||||
char *val;
|
||||
|
||||
progname, ll->lo_table, ll->lo_attr);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
int t;
|
||||
char *val;
|
||||
|
||||
/* ----------
|
||||
* Create DIR/FILE
|
||||
* ----------
|
||||
*/
|
||||
if (pgLO->action != ACTION_SHOW) {
|
||||
|
||||
if (pgLO->action != ACTION_SHOW)
|
||||
{
|
||||
|
||||
sprintf(path, "%s/%s/%s", pgLO->space, pgLO->db,
|
||||
ll->lo_table);
|
||||
|
||||
if (mkdir(path, DIR_UMASK) == -1) {
|
||||
if (errno != EEXIST) {
|
||||
if (mkdir(path, DIR_UMASK) == -1)
|
||||
{
|
||||
if (errno != EEXIST)
|
||||
{
|
||||
perror(path);
|
||||
exit(RE_ERROR);
|
||||
}
|
||||
exit(RE_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
sprintf(path, "%s/%s/%s/%s", pgLO->space, pgLO->db,
|
||||
ll->lo_table, ll->lo_attr);
|
||||
|
||||
if (mkdir(path, DIR_UMASK) == -1) {
|
||||
if (errno != EEXIST) {
|
||||
ll->lo_table, ll->lo_attr);
|
||||
|
||||
if (mkdir(path, DIR_UMASK) == -1)
|
||||
{
|
||||
if (errno != EEXIST)
|
||||
{
|
||||
perror(path);
|
||||
exit(RE_ERROR);
|
||||
}
|
||||
exit(RE_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!pgLO->quiet)
|
||||
printf("dump %s.%s (%d large obj)\n",
|
||||
ll->lo_table, ll->lo_attr, tuples);
|
||||
printf("dump %s.%s (%d large obj)\n",
|
||||
ll->lo_table, ll->lo_attr, tuples);
|
||||
}
|
||||
|
||||
pgLO->counter += tuples;
|
||||
|
||||
for(t=0; t<tuples; t++) {
|
||||
Oid lo;
|
||||
|
||||
|
||||
for (t = 0; t < tuples; t++)
|
||||
{
|
||||
Oid lo;
|
||||
|
||||
val = PQgetvalue(pgLO->res, t, 0);
|
||||
|
||||
|
||||
lo = atooid(val);
|
||||
|
||||
if (pgLO->action == ACTION_SHOW) {
|
||||
|
||||
if (pgLO->action == ACTION_SHOW)
|
||||
{
|
||||
printf("%s.%s: %u\n", ll->lo_table, ll->lo_attr, lo);
|
||||
continue;
|
||||
}
|
||||
|
||||
sprintf(path, "%s/%s/%s/%s/%s", pgLO->space,
|
||||
pgLO->db, ll->lo_table, ll->lo_attr, val);
|
||||
|
||||
if (lo_export(pgLO->conn, lo, path) < 0)
|
||||
|
||||
sprintf(path, "%s/%s/%s/%s/%s", pgLO->space,
|
||||
pgLO->db, ll->lo_table, ll->lo_attr, val);
|
||||
|
||||
if (lo_export(pgLO->conn, lo, path) < 0)
|
||||
fprintf(stderr, "%s: lo_export failed:\n%s", progname,
|
||||
PQerrorMessage(pgLO->conn));
|
||||
|
||||
else
|
||||
fprintf(pgLO->index, "%s\t%s\t%s\t%s/%s/%s/%s\n", val,
|
||||
ll->lo_table, ll->lo_attr, pgLO->db, ll->lo_table, ll->lo_attr, val);
|
||||
|
||||
else
|
||||
fprintf(pgLO->index, "%s\t%s\t%s\t%s/%s/%s/%s\n", val,
|
||||
ll->lo_table, ll->lo_attr, pgLO->db, ll->lo_table, ll->lo_attr, val);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,20 +1,20 @@
|
||||
/* -------------------------------------------------------------------------
|
||||
* pg_dumplo
|
||||
*
|
||||
* $Header: /cvsroot/pgsql/contrib/pg_dumplo/Attic/lo_import.c,v 1.3 2001/01/24 19:42:45 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/contrib/pg_dumplo/Attic/lo_import.c,v 1.4 2001/03/22 03:59:10 momjian Exp $
|
||||
*
|
||||
* Karel Zak 1999-2000
|
||||
* -------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <errno.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <libpq-fe.h>
|
||||
@ -22,76 +22,82 @@
|
||||
|
||||
#include "pg_dumplo.h"
|
||||
|
||||
extern int errno;
|
||||
extern int errno;
|
||||
|
||||
void
|
||||
pglo_import(LODumpMaster *pgLO)
|
||||
void
|
||||
pglo_import(LODumpMaster * pgLO)
|
||||
{
|
||||
LOlist loa;
|
||||
Oid new_oid;
|
||||
char tab[MAX_TABLE_NAME], attr[MAX_ATTR_NAME],
|
||||
path[BUFSIZ], lo_path[BUFSIZ],
|
||||
Qbuff[QUERY_BUFSIZ];
|
||||
|
||||
while(fgets(Qbuff, QUERY_BUFSIZ, pgLO->index)) {
|
||||
|
||||
Oid new_oid;
|
||||
char tab[MAX_TABLE_NAME],
|
||||
attr[MAX_ATTR_NAME],
|
||||
path[BUFSIZ],
|
||||
lo_path[BUFSIZ],
|
||||
Qbuff[QUERY_BUFSIZ];
|
||||
|
||||
while (fgets(Qbuff, QUERY_BUFSIZ, pgLO->index))
|
||||
{
|
||||
|
||||
if (*Qbuff == '#')
|
||||
continue;
|
||||
|
||||
if (! pgLO->remove && ! pgLO->quiet)
|
||||
if (!pgLO->remove && !pgLO->quiet)
|
||||
printf(Qbuff);
|
||||
|
||||
sscanf(Qbuff, "%u\t%s\t%s\t%s\n", &loa.lo_oid, tab, attr, path);
|
||||
loa.lo_table = tab;
|
||||
loa.lo_attr = attr;
|
||||
|
||||
sprintf(lo_path, "%s/%s", pgLO->space, path);
|
||||
sscanf(Qbuff, "%u\t%s\t%s\t%s\n", &loa.lo_oid, tab, attr, path);
|
||||
loa.lo_table = tab;
|
||||
loa.lo_attr = attr;
|
||||
|
||||
sprintf(lo_path, "%s/%s", pgLO->space, path);
|
||||
|
||||
/* ----------
|
||||
* Import LO
|
||||
* ----------
|
||||
*/
|
||||
if ((new_oid = lo_import(pgLO->conn, lo_path)) == 0) {
|
||||
|
||||
if ((new_oid = lo_import(pgLO->conn, lo_path)) == 0)
|
||||
{
|
||||
|
||||
fprintf(stderr, "%s: %s\n", progname, PQerrorMessage(pgLO->conn));
|
||||
|
||||
|
||||
PQexec(pgLO->conn, "ROLLBACK");
|
||||
fprintf(stderr, "\n%s: ROLLBACK\n", progname);
|
||||
exit(RE_ERROR);
|
||||
}
|
||||
|
||||
if (pgLO->remove) {
|
||||
if (pgLO->remove)
|
||||
{
|
||||
notice(pgLO, FALSE);
|
||||
if (lo_unlink(pgLO->conn, loa.lo_oid) < 0)
|
||||
fprintf(stderr, "%s: can't remove LO %u:\n%s",
|
||||
progname, loa.lo_oid, PQerrorMessage(pgLO->conn));
|
||||
|
||||
if (lo_unlink(pgLO->conn, loa.lo_oid) < 0)
|
||||
fprintf(stderr, "%s: can't remove LO %u:\n%s",
|
||||
progname, loa.lo_oid, PQerrorMessage(pgLO->conn));
|
||||
|
||||
else if (!pgLO->quiet)
|
||||
printf("remove old %u and create new %u\n",
|
||||
loa.lo_oid, new_oid);
|
||||
notice(pgLO, TRUE);
|
||||
printf("remove old %u and create new %u\n",
|
||||
loa.lo_oid, new_oid);
|
||||
notice(pgLO, TRUE);
|
||||
}
|
||||
|
||||
|
||||
pgLO->counter++;
|
||||
|
||||
|
||||
/* ----------
|
||||
* UPDATE oid in tab
|
||||
* ----------
|
||||
*/
|
||||
sprintf(Qbuff, "UPDATE \"%s\" SET \"%s\"=%u WHERE \"%s\"=%u",
|
||||
sprintf(Qbuff, "UPDATE \"%s\" SET \"%s\"=%u WHERE \"%s\"=%u",
|
||||
loa.lo_table, loa.lo_attr, new_oid, loa.lo_attr, loa.lo_oid);
|
||||
|
||||
/*fprintf(stderr, Qbuff);*/
|
||||
|
||||
/* fprintf(stderr, Qbuff); */
|
||||
|
||||
pgLO->res = PQexec(pgLO->conn, Qbuff);
|
||||
|
||||
if (PQresultStatus(pgLO->res) != PGRES_COMMAND_OK) {
|
||||
fprintf(stderr, "%s: %s\n",progname, PQerrorMessage(pgLO->conn));
|
||||
|
||||
if (PQresultStatus(pgLO->res) != PGRES_COMMAND_OK)
|
||||
{
|
||||
fprintf(stderr, "%s: %s\n", progname, PQerrorMessage(pgLO->conn));
|
||||
PQclear(pgLO->res);
|
||||
PQexec(pgLO->conn, "ROLLBACK");
|
||||
fprintf(stderr, "\n%s: ROLLBACK\n", progname);
|
||||
exit(RE_ERROR);
|
||||
}
|
||||
}
|
||||
PQclear(pgLO->res);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
/* -------------------------------------------------------------------------
|
||||
* pg_dumplo
|
||||
*
|
||||
* $Header: /cvsroot/pgsql/contrib/pg_dumplo/Attic/main.c,v 1.6 2001/02/10 02:31:25 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/contrib/pg_dumplo/Attic/main.c,v 1.7 2001/03/22 03:59:10 momjian Exp $
|
||||
*
|
||||
* Karel Zak 1999-2000
|
||||
* -------------------------------------------------------------------------
|
||||
@ -12,238 +12,254 @@
|
||||
#include "postgres_fe.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <libpq-fe.h>
|
||||
#include <libpq/libpq-fs.h>
|
||||
|
||||
#include "pg_dumplo.h"
|
||||
#include "pg_dumplo.h"
|
||||
|
||||
#ifdef HAVE_GETOPT_LONG
|
||||
#include <getopt.h>
|
||||
#define no_argument 0
|
||||
#define required_argument 1
|
||||
#include <getopt.h>
|
||||
#define no_argument 0
|
||||
#define required_argument 1
|
||||
#endif
|
||||
|
||||
extern int errno;
|
||||
|
||||
char *progname = NULL;
|
||||
extern int errno;
|
||||
|
||||
int main(int argc, char **argv);
|
||||
char *progname = NULL;
|
||||
|
||||
int main(int argc, char **argv);
|
||||
static void usage(void);
|
||||
static void parse_lolist (LODumpMaster *pgLO);
|
||||
|
||||
static void parse_lolist(LODumpMaster * pgLO);
|
||||
|
||||
|
||||
/*-----
|
||||
* The mother of all C functions
|
||||
*-----
|
||||
*/
|
||||
int
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
LODumpMaster _pgLO, *pgLO = &_pgLO;
|
||||
char *pwd = NULL;
|
||||
{
|
||||
LODumpMaster _pgLO,
|
||||
*pgLO = &_pgLO;
|
||||
char *pwd = NULL;
|
||||
|
||||
pgLO->argv = argv;
|
||||
pgLO->argc = argc;
|
||||
pgLO->action = 0;
|
||||
pgLO->lolist = NULL;
|
||||
pgLO->user = NULL;
|
||||
pgLO->db = NULL;
|
||||
pgLO->host = NULL;
|
||||
pgLO->space = NULL;
|
||||
pgLO->index = NULL;
|
||||
pgLO->remove = FALSE;
|
||||
pgLO->quiet = FALSE;
|
||||
pgLO->counter = 0;
|
||||
pgLO->argv = argv;
|
||||
pgLO->argc = argc;
|
||||
pgLO->action = 0;
|
||||
pgLO->lolist = NULL;
|
||||
pgLO->user = NULL;
|
||||
pgLO->db = NULL;
|
||||
pgLO->host = NULL;
|
||||
pgLO->space = NULL;
|
||||
pgLO->index = NULL;
|
||||
pgLO->remove = FALSE;
|
||||
pgLO->quiet = FALSE;
|
||||
pgLO->counter = 0;
|
||||
pgLO->lolist_start = 0;
|
||||
|
||||
|
||||
progname = argv[0];
|
||||
|
||||
/* ----------
|
||||
* Parse ARGV
|
||||
* ----------
|
||||
*/
|
||||
if (argc > 1) {
|
||||
int arg;
|
||||
extern int optind;
|
||||
if (argc > 1)
|
||||
{
|
||||
int arg;
|
||||
extern int optind;
|
||||
|
||||
#ifdef HAVE_GETOPT_LONG
|
||||
int l_index=0;
|
||||
static struct option l_opt[] = {
|
||||
{ "help", no_argument, 0, 'h' },
|
||||
{ "user", required_argument, 0, 'u' },
|
||||
{ "pwd", required_argument, 0, 'p' },
|
||||
{ "db", required_argument, 0, 'd' },
|
||||
{ "host", required_argument, 0, 'h' },
|
||||
{ "space", required_argument, 0, 's' },
|
||||
{ "import", no_argument, 0, 'i' },
|
||||
{ "export", no_argument, 0, 'e' },
|
||||
{ "remove", no_argument, 0, 'r' },
|
||||
{ "quiet", no_argument, 0, 'q' },
|
||||
{ "all", no_argument, 0, 'a' },
|
||||
{ "show", no_argument, 0, 'w' },
|
||||
{ NULL, 0, 0, 0 }
|
||||
};
|
||||
#ifdef HAVE_GETOPT_LONG
|
||||
int l_index = 0;
|
||||
static struct option l_opt[] = {
|
||||
{"help", no_argument, 0, 'h'},
|
||||
{"user", required_argument, 0, 'u'},
|
||||
{"pwd", required_argument, 0, 'p'},
|
||||
{"db", required_argument, 0, 'd'},
|
||||
{"host", required_argument, 0, 'h'},
|
||||
{"space", required_argument, 0, 's'},
|
||||
{"import", no_argument, 0, 'i'},
|
||||
{"export", no_argument, 0, 'e'},
|
||||
{"remove", no_argument, 0, 'r'},
|
||||
{"quiet", no_argument, 0, 'q'},
|
||||
{"all", no_argument, 0, 'a'},
|
||||
{"show", no_argument, 0, 'w'},
|
||||
{NULL, 0, 0, 0}
|
||||
};
|
||||
|
||||
while((arg = getopt_long(argc, argv, "?aehu:p:qd:l:t:irs:w", l_opt, &l_index)) != -1) {
|
||||
while ((arg = getopt_long(argc, argv, "?aehu:p:qd:l:t:irs:w", l_opt, &l_index)) != -1)
|
||||
{
|
||||
#else
|
||||
while((arg = getopt(argc, argv, "?aehu:p:qd:l:t:irs:w")) != -1) {
|
||||
while ((arg = getopt(argc, argv, "?aehu:p:qd:l:t:irs:w")) != -1)
|
||||
{
|
||||
#endif
|
||||
switch(arg) {
|
||||
case '?':
|
||||
case 'h':
|
||||
usage();
|
||||
switch (arg)
|
||||
{
|
||||
case '?':
|
||||
case 'h':
|
||||
usage();
|
||||
exit(RE_OK);
|
||||
case 'u':
|
||||
pgLO->user = strdup(optarg);
|
||||
break;
|
||||
case 't':
|
||||
pgLO->host = strdup(optarg);
|
||||
break;
|
||||
case 'p':
|
||||
pwd = strdup(optarg);
|
||||
break;
|
||||
case 'd':
|
||||
pgLO->db = strdup(optarg);
|
||||
break;
|
||||
case 's':
|
||||
pgLO->space = strdup(optarg);
|
||||
break;
|
||||
case 'i':
|
||||
pgLO->action = ACTION_IMPORT;
|
||||
break;
|
||||
case 'l':
|
||||
pgLO->action = ACTION_EXPORT_ATTR;
|
||||
pgLO->lolist_start = optind-1;
|
||||
parse_lolist (pgLO);
|
||||
break;
|
||||
case 'e':
|
||||
case 'a':
|
||||
case 'u':
|
||||
pgLO->user = strdup(optarg);
|
||||
break;
|
||||
case 't':
|
||||
pgLO->host = strdup(optarg);
|
||||
break;
|
||||
case 'p':
|
||||
pwd = strdup(optarg);
|
||||
break;
|
||||
case 'd':
|
||||
pgLO->db = strdup(optarg);
|
||||
break;
|
||||
case 's':
|
||||
pgLO->space = strdup(optarg);
|
||||
break;
|
||||
case 'i':
|
||||
pgLO->action = ACTION_IMPORT;
|
||||
break;
|
||||
case 'l':
|
||||
pgLO->action = ACTION_EXPORT_ATTR;
|
||||
pgLO->lolist_start = optind - 1;
|
||||
parse_lolist(pgLO);
|
||||
break;
|
||||
case 'e':
|
||||
case 'a':
|
||||
pgLO->action = ACTION_EXPORT_ALL;
|
||||
break;
|
||||
case 'w':
|
||||
pgLO->action = ACTION_SHOW;
|
||||
break;
|
||||
case 'r':
|
||||
pgLO->remove = TRUE;
|
||||
break;
|
||||
case 'q':
|
||||
pgLO->quiet = TRUE;
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "%s: bad arg -%c\n", progname, arg);
|
||||
usage();
|
||||
exit(RE_ERROR);
|
||||
break;
|
||||
case 'r':
|
||||
pgLO->remove = TRUE;
|
||||
break;
|
||||
case 'q':
|
||||
pgLO->quiet = TRUE;
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "%s: bad arg -%c\n", progname, arg);
|
||||
usage();
|
||||
exit(RE_ERROR);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
usage();
|
||||
exit(RE_ERROR);
|
||||
}
|
||||
exit(RE_ERROR);
|
||||
}
|
||||
|
||||
/* ----------
|
||||
* Check space
|
||||
* ----------
|
||||
*/
|
||||
if (! pgLO->space && ! pgLO->action == ACTION_SHOW) {
|
||||
if (!(pgLO->space = getenv("PWD"))) {
|
||||
if (!pgLO->space && !pgLO->action == ACTION_SHOW)
|
||||
{
|
||||
if (!(pgLO->space = getenv("PWD")))
|
||||
{
|
||||
fprintf(stderr, "%s: not set space for dump-tree (option '-s' or $PWD).\n", progname);
|
||||
exit(RE_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!pgLO->action) {
|
||||
|
||||
if (!pgLO->action)
|
||||
{
|
||||
fprintf(stderr, "%s: What do you want - export or import?\n", progname);
|
||||
exit(RE_ERROR);
|
||||
}
|
||||
|
||||
|
||||
/* ----------
|
||||
* Make connection
|
||||
* ----------
|
||||
*/
|
||||
pgLO->conn = PQsetdbLogin(pgLO->host, NULL, NULL, NULL, pgLO->db,
|
||||
pgLO->user, pwd);
|
||||
|
||||
if (PQstatus(pgLO->conn) == CONNECTION_BAD) {
|
||||
pgLO->conn = PQsetdbLogin(pgLO->host, NULL, NULL, NULL, pgLO->db,
|
||||
pgLO->user, pwd);
|
||||
|
||||
if (PQstatus(pgLO->conn) == CONNECTION_BAD)
|
||||
{
|
||||
fprintf(stderr, "%s (connection): %s\n", progname, PQerrorMessage(pgLO->conn));
|
||||
exit(RE_ERROR);
|
||||
}
|
||||
}
|
||||
pgLO->host = PQhost(pgLO->conn) ? PQhost(pgLO->conn) : "localhost";
|
||||
pgLO->db = PQdb(pgLO->conn);
|
||||
pgLO->user = PQuser(pgLO->conn);
|
||||
|
||||
|
||||
pgLO->db = PQdb(pgLO->conn);
|
||||
pgLO->user = PQuser(pgLO->conn);
|
||||
|
||||
|
||||
/* ----------
|
||||
* Init index file
|
||||
* ----------
|
||||
*/
|
||||
if (pgLO->action != ACTION_SHOW)
|
||||
if (pgLO->action != ACTION_SHOW)
|
||||
index_file(pgLO);
|
||||
|
||||
|
||||
PQexec(pgLO->conn, "BEGIN");
|
||||
|
||||
switch(pgLO->action) {
|
||||
|
||||
switch (pgLO->action)
|
||||
{
|
||||
|
||||
case ACTION_SHOW:
|
||||
case ACTION_EXPORT_ALL:
|
||||
load_lolist(pgLO);
|
||||
/* FALL THROUGH */
|
||||
|
||||
|
||||
case ACTION_EXPORT_ATTR:
|
||||
pglo_export(pgLO);
|
||||
if (!pgLO->quiet) {
|
||||
if (!pgLO->quiet)
|
||||
{
|
||||
if (pgLO->action == ACTION_SHOW)
|
||||
printf("\nDatabase '%s' contains %d large objects.\n\n", pgLO->db, pgLO->counter);
|
||||
else
|
||||
else
|
||||
printf("\nExported %d large objects.\n\n", pgLO->counter);
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case ACTION_IMPORT:
|
||||
pglo_import(pgLO);
|
||||
if (!pgLO->quiet)
|
||||
printf("\nImported %d large objects.\n\n", pgLO->counter);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
PQexec(pgLO->conn, "COMMIT");
|
||||
PQfinish(pgLO->conn);
|
||||
|
||||
PQfinish(pgLO->conn);
|
||||
|
||||
if (pgLO->action != ACTION_SHOW)
|
||||
fclose(pgLO->index);
|
||||
|
||||
|
||||
exit(RE_OK);
|
||||
}
|
||||
|
||||
static void
|
||||
parse_lolist (LODumpMaster *pgLO)
|
||||
parse_lolist(LODumpMaster * pgLO)
|
||||
{
|
||||
LOlist *ll;
|
||||
char **d,
|
||||
*loc,
|
||||
buff[MAX_TABLE_NAME + MAX_ATTR_NAME +1];
|
||||
LOlist *ll;
|
||||
char **d,
|
||||
*loc,
|
||||
buff[MAX_TABLE_NAME + MAX_ATTR_NAME + 1];
|
||||
|
||||
pgLO->lolist = (LOlist *) malloc(pgLO->argc * sizeof(LOlist));
|
||||
|
||||
if (! pgLO->lolist) {
|
||||
|
||||
if (!pgLO->lolist)
|
||||
{
|
||||
fprintf(stderr, "%s: can't allocate memory\n", progname);
|
||||
exit(RE_ERROR);
|
||||
}
|
||||
|
||||
for( d=pgLO->argv + pgLO->lolist_start, ll=pgLO->lolist;
|
||||
*d != NULL;
|
||||
d++, ll++) {
|
||||
|
||||
|
||||
for (d = pgLO->argv + pgLO->lolist_start, ll = pgLO->lolist;
|
||||
*d != NULL;
|
||||
d++, ll++)
|
||||
{
|
||||
|
||||
strncpy(buff, *d, MAX_TABLE_NAME + MAX_ATTR_NAME);
|
||||
|
||||
if ((loc = strchr(buff, '.')) == NULL) {
|
||||
|
||||
if ((loc = strchr(buff, '.')) == NULL)
|
||||
{
|
||||
fprintf(stderr, "%s: '%s' is bad 'table.attr'\n", progname, buff);
|
||||
exit(RE_ERROR);
|
||||
exit(RE_ERROR);
|
||||
}
|
||||
*loc = '\0';
|
||||
ll->lo_table = strdup(buff);
|
||||
@ -254,55 +270,55 @@ parse_lolist (LODumpMaster *pgLO)
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
static void
|
||||
usage()
|
||||
{
|
||||
printf("\npg_dumplo %s - PostgreSQL large objects dump\n", VERSION);
|
||||
puts("pg_dumplo [option]\n\n"
|
||||
puts("pg_dumplo [option]\n\n"
|
||||
|
||||
#ifdef HAVE_GETOPT_LONG
|
||||
|
||||
"-h --help this help\n"
|
||||
"-u --user=<username> username for connection to server\n"
|
||||
"-p --password=<password> password for connection to server\n"
|
||||
"-d --db=<database> database name\n"
|
||||
"-t --host=<hostname> server hostname\n"
|
||||
"-s --space=<dir> directory with dump tree (for export/import)\n"
|
||||
"-i --import import large obj dump tree to DB\n"
|
||||
"-e --export export (dump) large obj to dump tree\n"
|
||||
"-l <table.attr ...> dump attribute (columns) with LO to dump tree\n"
|
||||
"-a --all dump all LO in DB (default)\n"
|
||||
"-r --remove if is set '-i' try remove old LO\n"
|
||||
"-q --quiet run quietly\n"
|
||||
"-w --show not dump, but show all LO in DB\n"
|
||||
); /* puts() */
|
||||
|
||||
"-h --help this help\n"
|
||||
"-u --user=<username> username for connection to server\n"
|
||||
"-p --password=<password> password for connection to server\n"
|
||||
"-d --db=<database> database name\n"
|
||||
"-t --host=<hostname> server hostname\n"
|
||||
"-s --space=<dir> directory with dump tree (for export/import)\n"
|
||||
"-i --import import large obj dump tree to DB\n"
|
||||
"-e --export export (dump) large obj to dump tree\n"
|
||||
"-l <table.attr ...> dump attribute (columns) with LO to dump tree\n"
|
||||
"-a --all dump all LO in DB (default)\n"
|
||||
"-r --remove if is set '-i' try remove old LO\n"
|
||||
"-q --quiet run quietly\n"
|
||||
"-w --show not dump, but show all LO in DB\n"
|
||||
); /* puts() */
|
||||
|
||||
#else
|
||||
"-h this help\n"
|
||||
"-u <username> username for connection to server\n"
|
||||
"-p <password> password for connection to server\n"
|
||||
"-d <database> database name\n"
|
||||
"-t <hostname> server hostname\n"
|
||||
"-s <dir> directory with dump tree (for export/import)\n"
|
||||
"-i import large obj dump tree to DB\n"
|
||||
"-e export (dump) large obj to dump tree\n"
|
||||
"-l <table.attr ...> dump attribute (columns) with LO to dump tree\n"
|
||||
"-a dump all LO in DB (default)\n"
|
||||
"-r if is set '-i' try remove old LO\n"
|
||||
"-q run quietly\n"
|
||||
"-w not dump, but show all LO in DB\n"
|
||||
); /* puts() */
|
||||
"-h this help\n"
|
||||
"-u <username> username for connection to server\n"
|
||||
"-p <password> password for connection to server\n"
|
||||
"-d <database> database name\n"
|
||||
"-t <hostname> server hostname\n"
|
||||
"-s <dir> directory with dump tree (for export/import)\n"
|
||||
"-i import large obj dump tree to DB\n"
|
||||
"-e export (dump) large obj to dump tree\n"
|
||||
"-l <table.attr ...> dump attribute (columns) with LO to dump tree\n"
|
||||
"-a dump all LO in DB (default)\n"
|
||||
"-r if is set '-i' try remove old LO\n"
|
||||
"-q run quietly\n"
|
||||
"-w not dump, but show all LO in DB\n"
|
||||
); /* puts() */
|
||||
|
||||
#endif
|
||||
|
||||
puts(
|
||||
"Example (dump): pg_dumplo -d my_db -s /my_dump/dir -l t1.a t1.b t2.a\n"
|
||||
" pg_dumplo -a -d my_db -s /my_dump/dir\n"
|
||||
"Example (import): pg_dumplo -i -d my_db -s /my_dump/dir\n"
|
||||
"Example (show): pg_dumplo -w -d my_db\n\n"
|
||||
"Note: * option '-l' must be last option!\n"
|
||||
" * option '-i' without option '-r' make new large obj in DB\n"
|
||||
" not rewrite old, the '-i' UPDATE oid numbers in table.attr only!\n"
|
||||
" * if is not set option -s, the pg_dumplo use $PWD\n"
|
||||
); /* puts()*/
|
||||
"Example (dump): pg_dumplo -d my_db -s /my_dump/dir -l t1.a t1.b t2.a\n"
|
||||
" pg_dumplo -a -d my_db -s /my_dump/dir\n"
|
||||
"Example (import): pg_dumplo -i -d my_db -s /my_dump/dir\n"
|
||||
"Example (show): pg_dumplo -w -d my_db\n\n"
|
||||
"Note: * option '-l' must be last option!\n"
|
||||
" * option '-i' without option '-r' make new large obj in DB\n"
|
||||
" not rewrite old, the '-i' UPDATE oid numbers in table.attr only!\n"
|
||||
" * if is not set option -s, the pg_dumplo use $PWD\n"
|
||||
); /* puts() */
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
/* -------------------------------------------------------------------------
|
||||
* pg_dumplo
|
||||
*
|
||||
* $Header: /cvsroot/pgsql/contrib/pg_dumplo/Attic/pg_dumplo.h,v 1.3 2001/01/24 19:42:45 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/contrib/pg_dumplo/Attic/pg_dumplo.h,v 1.4 2001/03/22 03:59:10 momjian Exp $
|
||||
*
|
||||
* Karel Zak 1999-2000
|
||||
* -------------------------------------------------------------------------
|
||||
@ -17,12 +17,12 @@
|
||||
/* ----------
|
||||
* Define
|
||||
* ----------
|
||||
*/
|
||||
*/
|
||||
#define QUERY_BUFSIZ (8*1024)
|
||||
#define DIR_UMASK 0755
|
||||
#define FILE_UMASK 0644
|
||||
|
||||
#define TRUE 1
|
||||
#define TRUE 1
|
||||
#define FALSE 0
|
||||
#define RE_OK 0
|
||||
#define RE_ERROR 1
|
||||
@ -36,44 +36,47 @@
|
||||
* LO struct
|
||||
* ----------
|
||||
*/
|
||||
typedef struct {
|
||||
char *lo_table,
|
||||
*lo_attr;
|
||||
Oid lo_oid;
|
||||
} LOlist;
|
||||
typedef struct
|
||||
{
|
||||
char *lo_table,
|
||||
*lo_attr;
|
||||
Oid lo_oid;
|
||||
} LOlist;
|
||||
|
||||
typedef struct {
|
||||
int action;
|
||||
LOlist *lolist;
|
||||
char **argv,
|
||||
*user,
|
||||
*db,
|
||||
*host,
|
||||
*space;
|
||||
FILE *index;
|
||||
int counter,
|
||||
argc,
|
||||
lolist_start,
|
||||
remove,
|
||||
quiet;
|
||||
PGresult *res;
|
||||
PGconn *conn;
|
||||
} LODumpMaster;
|
||||
typedef struct
|
||||
{
|
||||
int action;
|
||||
LOlist *lolist;
|
||||
char **argv,
|
||||
*user,
|
||||
*db,
|
||||
*host,
|
||||
*space;
|
||||
FILE *index;
|
||||
int counter,
|
||||
argc,
|
||||
lolist_start,
|
||||
remove,
|
||||
quiet;
|
||||
PGresult *res;
|
||||
PGconn *conn;
|
||||
} LODumpMaster;
|
||||
|
||||
typedef enum {
|
||||
typedef enum
|
||||
{
|
||||
ACTION_NONE,
|
||||
ACTION_SHOW,
|
||||
ACTION_EXPORT_ATTR,
|
||||
ACTION_EXPORT_ALL,
|
||||
ACTION_EXPORT_ATTR,
|
||||
ACTION_EXPORT_ALL,
|
||||
ACTION_IMPORT
|
||||
} PGLODUMP_ACTIONS;
|
||||
} PGLODUMP_ACTIONS;
|
||||
|
||||
extern char *progname;
|
||||
|
||||
extern void notice (LODumpMaster *pgLO, int set);
|
||||
extern void index_file (LODumpMaster *pgLO);
|
||||
extern void load_lolist (LODumpMaster *pgLO);
|
||||
extern void pglo_export (LODumpMaster *pgLO);
|
||||
extern void pglo_import (LODumpMaster *pgLO);
|
||||
extern void notice(LODumpMaster * pgLO, int set);
|
||||
extern void index_file(LODumpMaster * pgLO);
|
||||
extern void load_lolist(LODumpMaster * pgLO);
|
||||
extern void pglo_export(LODumpMaster * pgLO);
|
||||
extern void pglo_import(LODumpMaster * pgLO);
|
||||
|
||||
#endif /* PG_DUMPLO_H */
|
||||
#endif /* PG_DUMPLO_H */
|
||||
|
@ -1,20 +1,20 @@
|
||||
/* -------------------------------------------------------------------------
|
||||
* pg_dumplo
|
||||
*
|
||||
* $Header: /cvsroot/pgsql/contrib/pg_dumplo/Attic/utils.c,v 1.3 2001/01/24 19:42:45 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/contrib/pg_dumplo/Attic/utils.c,v 1.4 2001/03/22 03:59:10 momjian Exp $
|
||||
*
|
||||
* Karel Zak 1999-2000
|
||||
* -------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <errno.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <libpq-fe.h>
|
||||
@ -22,65 +22,76 @@
|
||||
|
||||
#include "pg_dumplo.h"
|
||||
|
||||
extern int errno;
|
||||
extern int errno;
|
||||
|
||||
static void Dummy_NoticeProcessor(void *arg, const char *message);
|
||||
static void Default_NoticeProcessor(void *arg, const char *message);
|
||||
|
||||
static void Dummy_NoticeProcessor(void * arg, const char * message);
|
||||
static void Default_NoticeProcessor(void * arg, const char * message);
|
||||
|
||||
|
||||
void
|
||||
index_file(LODumpMaster *pgLO)
|
||||
index_file(LODumpMaster * pgLO)
|
||||
{
|
||||
char path[BUFSIZ];
|
||||
char path[BUFSIZ];
|
||||
|
||||
if (pgLO->action == ACTION_SHOW)
|
||||
return;
|
||||
|
||||
sprintf(path, "%s/%s", pgLO->space, pgLO->db);
|
||||
|
||||
if (pgLO->action == ACTION_EXPORT_ATTR ||
|
||||
pgLO->action == ACTION_EXPORT_ALL) {
|
||||
|
||||
if (mkdir(path, DIR_UMASK) == -1) {
|
||||
if (errno != EEXIST) {
|
||||
perror(path);
|
||||
exit(RE_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
sprintf(path, "%s/lo_dump.index", path);
|
||||
|
||||
if ((pgLO->index = fopen(path, "w")) == NULL) {
|
||||
sprintf(path, "%s/%s", pgLO->space, pgLO->db);
|
||||
|
||||
if (pgLO->action == ACTION_EXPORT_ATTR ||
|
||||
pgLO->action == ACTION_EXPORT_ALL)
|
||||
{
|
||||
|
||||
if (mkdir(path, DIR_UMASK) == -1)
|
||||
{
|
||||
if (errno != EEXIST)
|
||||
{
|
||||
perror(path);
|
||||
exit(RE_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
sprintf(path, "%s/lo_dump.index", path);
|
||||
|
||||
if ((pgLO->index = fopen(path, "w")) == NULL)
|
||||
{
|
||||
perror(path);
|
||||
exit(RE_ERROR);
|
||||
}
|
||||
|
||||
} else if (pgLO->action != ACTION_NONE ) {
|
||||
|
||||
sprintf(path, "%s/lo_dump.index", path);
|
||||
|
||||
if ((pgLO->index = fopen(path, "r")) == NULL) {
|
||||
}
|
||||
else if (pgLO->action != ACTION_NONE)
|
||||
{
|
||||
|
||||
sprintf(path, "%s/lo_dump.index", path);
|
||||
|
||||
if ((pgLO->index = fopen(path, "r")) == NULL)
|
||||
{
|
||||
perror(path);
|
||||
exit(RE_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
void Dummy_NoticeProcessor(void * arg, const char * message)
|
||||
static
|
||||
void
|
||||
Dummy_NoticeProcessor(void *arg, const char *message)
|
||||
{
|
||||
;
|
||||
;
|
||||
}
|
||||
|
||||
static
|
||||
void Default_NoticeProcessor(void * arg, const char * message)
|
||||
static
|
||||
void
|
||||
Default_NoticeProcessor(void *arg, const char *message)
|
||||
{
|
||||
fprintf(stderr, "%s", message);
|
||||
fprintf(stderr, "%s", message);
|
||||
}
|
||||
|
||||
void
|
||||
notice(LODumpMaster *pgLO, int set)
|
||||
{
|
||||
if (set)PQsetNoticeProcessor(pgLO->conn, Default_NoticeProcessor, NULL);
|
||||
else PQsetNoticeProcessor(pgLO->conn, Dummy_NoticeProcessor, NULL);
|
||||
void
|
||||
notice(LODumpMaster * pgLO, int set)
|
||||
{
|
||||
if (set)
|
||||
PQsetNoticeProcessor(pgLO->conn, Default_NoticeProcessor, NULL);
|
||||
else
|
||||
PQsetNoticeProcessor(pgLO->conn, Dummy_NoticeProcessor, NULL);
|
||||
}
|
||||
|
@ -2,10 +2,10 @@
|
||||
*
|
||||
* Copyright 2001 by Nathan Myers <ncm@nospam.cantrip.org>
|
||||
* This software is distributed free of charge with no warranty of any kind.
|
||||
* You have permission to make copies for any purpose, provided that (1)
|
||||
* this copyright notice is retained unchanged, and (2) you agree to
|
||||
* absolve the author of all responsibility for all consequences arising
|
||||
* from any use.
|
||||
* You have permission to make copies for any purpose, provided that (1)
|
||||
* this copyright notice is retained unchanged, and (2) you agree to
|
||||
* absolve the author of all responsibility for all consequences arising
|
||||
* from any use.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
@ -13,73 +13,94 @@
|
||||
#include <syslog.h>
|
||||
#include <string.h>
|
||||
|
||||
struct {
|
||||
const char *tag;
|
||||
int size;
|
||||
int priority;
|
||||
} tags[] = {
|
||||
{ "", 0, LOG_NOTICE },
|
||||
{ "emerg:", sizeof("emerg"), LOG_EMERG },
|
||||
{ "alert:", sizeof("alert"), LOG_ALERT },
|
||||
{ "crit:", sizeof("crit"), LOG_CRIT },
|
||||
{ "err:", sizeof("err"), LOG_ERR },
|
||||
{ "error:", sizeof("error"), LOG_ERR },
|
||||
{ "warning:", sizeof("warning"), LOG_WARNING },
|
||||
{ "notice:", sizeof("notice"), LOG_NOTICE },
|
||||
{ "info:", sizeof("info"), LOG_INFO },
|
||||
{ "debug:", sizeof("debug"), LOG_DEBUG }
|
||||
struct
|
||||
{
|
||||
const char *tag;
|
||||
int size;
|
||||
int priority;
|
||||
} tags[] =
|
||||
|
||||
{
|
||||
{
|
||||
"", 0, LOG_NOTICE
|
||||
},
|
||||
{
|
||||
"emerg:", sizeof("emerg"), LOG_EMERG
|
||||
},
|
||||
{
|
||||
"alert:", sizeof("alert"), LOG_ALERT
|
||||
},
|
||||
{
|
||||
"crit:", sizeof("crit"), LOG_CRIT
|
||||
},
|
||||
{
|
||||
"err:", sizeof("err"), LOG_ERR
|
||||
},
|
||||
{
|
||||
"error:", sizeof("error"), LOG_ERR
|
||||
},
|
||||
{
|
||||
"warning:", sizeof("warning"), LOG_WARNING
|
||||
},
|
||||
{
|
||||
"notice:", sizeof("notice"), LOG_NOTICE
|
||||
},
|
||||
{
|
||||
"info:", sizeof("info"), LOG_INFO
|
||||
},
|
||||
{
|
||||
"debug:", sizeof("debug"), LOG_DEBUG
|
||||
}
|
||||
};
|
||||
|
||||
int main()
|
||||
int
|
||||
main()
|
||||
{
|
||||
char buf[301];
|
||||
int c;
|
||||
char *pos = buf;
|
||||
const char *colon = 0;
|
||||
char buf[301];
|
||||
int c;
|
||||
char *pos = buf;
|
||||
const char *colon = 0;
|
||||
|
||||
#ifndef DEBUG
|
||||
openlog("postgresql", LOG_CONS, LOG_LOCAL1);
|
||||
openlog("postgresql", LOG_CONS, LOG_LOCAL1);
|
||||
#endif
|
||||
while ( (c = getchar()) != EOF) {
|
||||
if (c == '\r') {
|
||||
continue;
|
||||
}
|
||||
if (c == '\n') {
|
||||
int level = sizeof(tags)/sizeof(*tags);
|
||||
char *bol;
|
||||
while ((c = getchar()) != EOF)
|
||||
{
|
||||
if (c == '\r')
|
||||
continue;
|
||||
if (c == '\n')
|
||||
{
|
||||
int level = sizeof(tags) / sizeof(*tags);
|
||||
char *bol;
|
||||
|
||||
if (colon == 0 || (size_t)(colon - buf) > sizeof("warning")) {
|
||||
level = 1;
|
||||
}
|
||||
*pos = 0;
|
||||
while (--level) {
|
||||
if (pos - buf >= tags[level].size
|
||||
&& strncmp(buf, tags[level].tag, tags[level].size) == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
bol = buf + tags[level].size;
|
||||
if (bol > buf && *bol == ' ') {
|
||||
++bol;
|
||||
}
|
||||
if (pos - bol > 0) {
|
||||
if (colon == 0 || (size_t) (colon - buf) > sizeof("warning"))
|
||||
level = 1;
|
||||
*pos = 0;
|
||||
while (--level)
|
||||
{
|
||||
if (pos - buf >= tags[level].size
|
||||
&& strncmp(buf, tags[level].tag, tags[level].size) == 0)
|
||||
break;
|
||||
}
|
||||
bol = buf + tags[level].size;
|
||||
if (bol > buf && *bol == ' ')
|
||||
++bol;
|
||||
if (pos - bol > 0)
|
||||
{
|
||||
#ifndef DEBUG
|
||||
syslog(tags[level].priority, "%s", bol);
|
||||
syslog(tags[level].priority, "%s", bol);
|
||||
#else
|
||||
printf("%d/%s\n", tags[level].priority, bol);
|
||||
printf("%d/%s\n", tags[level].priority, bol);
|
||||
#endif
|
||||
}
|
||||
pos = buf;
|
||||
colon = (char const *)0;
|
||||
continue;
|
||||
}
|
||||
if (c == ':' && !colon) {
|
||||
colon = pos;
|
||||
}
|
||||
if ((size_t)(pos - buf) < sizeof(buf)-1) {
|
||||
*pos++ = c;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
pos = buf;
|
||||
colon = (char const *) 0;
|
||||
continue;
|
||||
}
|
||||
if (c == ':' && !colon)
|
||||
colon = pos;
|
||||
if ((size_t) (pos - buf) < sizeof(buf) - 1)
|
||||
*pos++ = c;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -5,15 +5,15 @@
|
||||
* Can also rebuild pg_control if needed.
|
||||
*
|
||||
* The theory of operation is fairly simple:
|
||||
* 1. Read the existing pg_control (which will include the last
|
||||
* 1. Read the existing pg_control (which will include the last
|
||||
* checkpoint record). If it is an old format then update to
|
||||
* current format.
|
||||
* 2. If pg_control is corrupt, attempt to intuit reasonable values,
|
||||
* by scanning the old xlog if necessary.
|
||||
* 3. Modify pg_control to reflect a "shutdown" state with a checkpoint
|
||||
* record at the start of xlog.
|
||||
* record at the start of xlog.
|
||||
* 4. Flush the existing xlog files and write a new segment with
|
||||
* just a checkpoint record in it. The new segment is positioned
|
||||
* just a checkpoint record in it. The new segment is positioned
|
||||
* just past the end of the old xlog, so that existing LSNs in
|
||||
* data pages will appear to be "in the past".
|
||||
* This is all pretty straightforward except for the intuition part of
|
||||
@ -23,7 +23,7 @@
|
||||
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Header: /cvsroot/pgsql/contrib/pg_resetxlog/Attic/pg_resetxlog.c,v 1.2 2001/03/16 05:08:39 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/contrib/pg_resetxlog/Attic/pg_resetxlog.c,v 1.3 2001/03/22 03:59:10 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -63,7 +63,7 @@
|
||||
* Compute ID and segment from an XLogRecPtr.
|
||||
*
|
||||
* For XLByteToSeg, do the computation at face value. For XLByteToPrevSeg,
|
||||
* a boundary byte is taken to be in the previous segment. This is suitable
|
||||
* a boundary byte is taken to be in the previous segment. This is suitable
|
||||
* for deciding which segment to write given a pointer to a record end,
|
||||
* for example.
|
||||
*/
|
||||
@ -109,8 +109,9 @@ static char *DataDir; /* locations of important stuff */
|
||||
static char XLogDir[MAXPGPATH];
|
||||
static char ControlFilePath[MAXPGPATH];
|
||||
|
||||
static ControlFileData ControlFile; /* pg_control values */
|
||||
static uint32 newXlogId, newXlogSeg; /* ID/Segment of new XLOG segment */
|
||||
static ControlFileData ControlFile; /* pg_control values */
|
||||
static uint32 newXlogId,
|
||||
newXlogSeg; /* ID/Segment of new XLOG segment */
|
||||
static bool guessed = false; /* T if we had to guess at any values */
|
||||
|
||||
|
||||
@ -139,17 +140,18 @@ XLogFileOpen(uint32 log, uint32 seg)
|
||||
static bool
|
||||
ReadControlFile(void)
|
||||
{
|
||||
int fd;
|
||||
int len;
|
||||
char *buffer;
|
||||
crc64 crc;
|
||||
int fd;
|
||||
int len;
|
||||
char *buffer;
|
||||
crc64 crc;
|
||||
|
||||
if ((fd = open(ControlFilePath, O_RDONLY)) < 0)
|
||||
{
|
||||
|
||||
/*
|
||||
* If pg_control is not there at all, or we can't read it,
|
||||
* the odds are we've been handed a bad DataDir path, so give up.
|
||||
* User can do "touch pg_control" to force us to proceed.
|
||||
* If pg_control is not there at all, or we can't read it, the
|
||||
* odds are we've been handed a bad DataDir path, so give up. User
|
||||
* can do "touch pg_control" to force us to proceed.
|
||||
*/
|
||||
perror("Failed to open $PGDATA/global/pg_control for reading");
|
||||
if (errno == ENOENT)
|
||||
@ -175,7 +177,7 @@ ReadControlFile(void)
|
||||
{
|
||||
/* Seems to be current version --- check the CRC. */
|
||||
INIT_CRC64(crc);
|
||||
COMP_CRC64(crc,
|
||||
COMP_CRC64(crc,
|
||||
buffer + sizeof(crc64),
|
||||
sizeof(ControlFileData) - sizeof(crc64));
|
||||
FIN_CRC64(crc);
|
||||
@ -193,6 +195,7 @@ ReadControlFile(void)
|
||||
guessed = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Maybe it's a 7.1beta pg_control.
|
||||
*/
|
||||
@ -217,75 +220,75 @@ ReadControlFile(void)
|
||||
|
||||
typedef struct crc64V0
|
||||
{
|
||||
uint32 crc1;
|
||||
uint32 crc2;
|
||||
} crc64V0;
|
||||
uint32 crc1;
|
||||
uint32 crc2;
|
||||
} crc64V0;
|
||||
|
||||
static uint32 crc_tableV0[] = {
|
||||
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
|
||||
0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
|
||||
0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2,
|
||||
0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
|
||||
0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
|
||||
0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
|
||||
0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c,
|
||||
0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
|
||||
0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423,
|
||||
0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
|
||||
0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106,
|
||||
0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
|
||||
0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d,
|
||||
0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
|
||||
0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
|
||||
0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
|
||||
0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7,
|
||||
0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
|
||||
0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa,
|
||||
0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
|
||||
0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81,
|
||||
0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,
|
||||
0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84,
|
||||
0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
|
||||
0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
|
||||
0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,
|
||||
0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e,
|
||||
0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
|
||||
0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55,
|
||||
0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
|
||||
0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28,
|
||||
0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
|
||||
0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f,
|
||||
0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,
|
||||
0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
|
||||
0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
|
||||
0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69,
|
||||
0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,
|
||||
0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc,
|
||||
0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
|
||||
0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693,
|
||||
0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
|
||||
0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
|
||||
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
|
||||
0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
|
||||
0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2,
|
||||
0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
|
||||
0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
|
||||
0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
|
||||
0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c,
|
||||
0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
|
||||
0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423,
|
||||
0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
|
||||
0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106,
|
||||
0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
|
||||
0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d,
|
||||
0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
|
||||
0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
|
||||
0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
|
||||
0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7,
|
||||
0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
|
||||
0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa,
|
||||
0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
|
||||
0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81,
|
||||
0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,
|
||||
0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84,
|
||||
0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
|
||||
0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
|
||||
0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,
|
||||
0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e,
|
||||
0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
|
||||
0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55,
|
||||
0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
|
||||
0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28,
|
||||
0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
|
||||
0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f,
|
||||
0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,
|
||||
0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
|
||||
0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
|
||||
0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69,
|
||||
0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,
|
||||
0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc,
|
||||
0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
|
||||
0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693,
|
||||
0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
|
||||
0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
|
||||
};
|
||||
|
||||
#define INIT_CRC64V0(crc) ((crc).crc1 = 0xffffffff, (crc).crc2 = 0xffffffff)
|
||||
#define FIN_CRC64V0(crc) ((crc).crc1 ^= 0xffffffff, (crc).crc2 ^= 0xffffffff)
|
||||
#define COMP_CRC64V0(crc, data, len) \
|
||||
{\
|
||||
uint32 __c1 = (crc).crc1;\
|
||||
uint32 __c2 = (crc).crc2;\
|
||||
char *__data = (char *) (data);\
|
||||
uint32 __len = (len);\
|
||||
uint32 __c1 = (crc).crc1;\
|
||||
uint32 __c2 = (crc).crc2;\
|
||||
char *__data = (char *) (data);\
|
||||
uint32 __len = (len);\
|
||||
\
|
||||
while (__len >= 2)\
|
||||
{\
|
||||
__c1 = crc_tableV0[(__c1 ^ *__data++) & 0xff] ^ (__c1 >> 8);\
|
||||
__c2 = crc_tableV0[(__c2 ^ *__data++) & 0xff] ^ (__c2 >> 8);\
|
||||
__len -= 2;\
|
||||
}\
|
||||
if (__len > 0)\
|
||||
__c1 = crc_tableV0[(__c1 ^ *__data++) & 0xff] ^ (__c1 >> 8);\
|
||||
(crc).crc1 = __c1;\
|
||||
(crc).crc2 = __c2;\
|
||||
while (__len >= 2)\
|
||||
{\
|
||||
__c1 = crc_tableV0[(__c1 ^ *__data++) & 0xff] ^ (__c1 >> 8);\
|
||||
__c2 = crc_tableV0[(__c2 ^ *__data++) & 0xff] ^ (__c2 >> 8);\
|
||||
__len -= 2;\
|
||||
}\
|
||||
if (__len > 0)\
|
||||
__c1 = crc_tableV0[(__c1 ^ *__data++) & 0xff] ^ (__c1 >> 8);\
|
||||
(crc).crc1 = __c1;\
|
||||
(crc).crc2 = __c2;\
|
||||
}
|
||||
|
||||
#define EQ_CRC64V0(c1,c2) ((c1).crc1 == (c2).crc1 && (c1).crc2 == (c2).crc2)
|
||||
@ -295,51 +298,51 @@ static uint32 crc_tableV0[] = {
|
||||
|
||||
typedef struct ControlFileDataV0
|
||||
{
|
||||
crc64V0 crc;
|
||||
uint32 logId; /* current log file id */
|
||||
uint32 logSeg; /* current log file segment (1-based) */
|
||||
XLogRecPtr checkPoint; /* last check point record ptr */
|
||||
time_t time; /* time stamp of last modification */
|
||||
DBState state; /* see enum above */
|
||||
uint32 blcksz; /* block size for this DB */
|
||||
uint32 relseg_size; /* blocks per segment of large relation */
|
||||
uint32 catalog_version_no; /* internal version number */
|
||||
char lc_collate[LOCALE_NAME_BUFLEN_V0];
|
||||
char lc_ctype[LOCALE_NAME_BUFLEN_V0];
|
||||
char archdir[MAXPGPATH]; /* where to move offline log files */
|
||||
} ControlFileDataV0;
|
||||
crc64V0 crc;
|
||||
uint32 logId; /* current log file id */
|
||||
uint32 logSeg; /* current log file segment (1-based) */
|
||||
XLogRecPtr checkPoint; /* last check point record ptr */
|
||||
time_t time; /* time stamp of last modification */
|
||||
DBState state; /* see enum above */
|
||||
uint32 blcksz; /* block size for this DB */
|
||||
uint32 relseg_size; /* blocks per segment of large relation */
|
||||
uint32 catalog_version_no; /* internal version number */
|
||||
char lc_collate[LOCALE_NAME_BUFLEN_V0];
|
||||
char lc_ctype[LOCALE_NAME_BUFLEN_V0];
|
||||
char archdir[MAXPGPATH]; /* where to move offline log files */
|
||||
} ControlFileDataV0;
|
||||
|
||||
typedef struct CheckPointV0
|
||||
{
|
||||
XLogRecPtr redo; /* next RecPtr available when we */
|
||||
/* began to create CheckPoint */
|
||||
/* (i.e. REDO start point) */
|
||||
XLogRecPtr undo; /* first record of oldest in-progress */
|
||||
/* transaction when we started */
|
||||
/* (i.e. UNDO end point) */
|
||||
StartUpID ThisStartUpID;
|
||||
TransactionId nextXid;
|
||||
Oid nextOid;
|
||||
bool Shutdown;
|
||||
} CheckPointV0;
|
||||
XLogRecPtr redo; /* next RecPtr available when we */
|
||||
/* began to create CheckPoint */
|
||||
/* (i.e. REDO start point) */
|
||||
XLogRecPtr undo; /* first record of oldest in-progress */
|
||||
/* transaction when we started */
|
||||
/* (i.e. UNDO end point) */
|
||||
StartUpID ThisStartUpID;
|
||||
TransactionId nextXid;
|
||||
Oid nextOid;
|
||||
bool Shutdown;
|
||||
} CheckPointV0;
|
||||
|
||||
typedef struct XLogRecordV0
|
||||
{
|
||||
crc64V0 xl_crc;
|
||||
XLogRecPtr xl_prev; /* ptr to previous record in log */
|
||||
XLogRecPtr xl_xact_prev; /* ptr to previous record of this xact */
|
||||
TransactionId xl_xid; /* xact id */
|
||||
uint16 xl_len; /* total len of record *data* */
|
||||
uint8 xl_info;
|
||||
RmgrId xl_rmid; /* resource manager inserted this record */
|
||||
} XLogRecordV0;
|
||||
crc64V0 xl_crc;
|
||||
XLogRecPtr xl_prev; /* ptr to previous record in log */
|
||||
XLogRecPtr xl_xact_prev; /* ptr to previous record of this xact */
|
||||
TransactionId xl_xid; /* xact id */
|
||||
uint16 xl_len; /* total len of record *data* */
|
||||
uint8 xl_info;
|
||||
RmgrId xl_rmid; /* resource manager inserted this record */
|
||||
} XLogRecordV0;
|
||||
|
||||
#define SizeOfXLogRecordV0 DOUBLEALIGN(sizeof(XLogRecordV0))
|
||||
|
||||
typedef struct XLogContRecordV0
|
||||
{
|
||||
uint16 xl_len; /* len of data left */
|
||||
} XLogContRecordV0;
|
||||
uint16 xl_len; /* len of data left */
|
||||
} XLogContRecordV0;
|
||||
|
||||
#define SizeOfXLogContRecordV0 DOUBLEALIGN(sizeof(XLogContRecordV0))
|
||||
|
||||
@ -347,16 +350,16 @@ typedef struct XLogContRecordV0
|
||||
|
||||
typedef struct XLogPageHeaderDataV0
|
||||
{
|
||||
uint32 xlp_magic;
|
||||
uint16 xlp_info;
|
||||
} XLogPageHeaderDataV0;
|
||||
uint32 xlp_magic;
|
||||
uint16 xlp_info;
|
||||
} XLogPageHeaderDataV0;
|
||||
|
||||
#define SizeOfXLogPHDV0 DOUBLEALIGN(sizeof(XLogPageHeaderDataV0))
|
||||
|
||||
typedef XLogPageHeaderDataV0 *XLogPageHeaderV0;
|
||||
|
||||
|
||||
static bool RecordIsValidV0(XLogRecordV0 *record);
|
||||
static bool RecordIsValidV0(XLogRecordV0 * record);
|
||||
static XLogRecordV0 *ReadRecordV0(XLogRecPtr *RecPtr, char *buffer);
|
||||
static bool ValidXLOGHeaderV0(XLogPageHeaderV0 hdr);
|
||||
|
||||
@ -376,7 +379,7 @@ CheckControlVersion0(char *buffer, int len)
|
||||
return false;
|
||||
/* Check CRC the version-0 way. */
|
||||
INIT_CRC64V0(crc);
|
||||
COMP_CRC64V0(crc,
|
||||
COMP_CRC64V0(crc,
|
||||
buffer + sizeof(crc64V0),
|
||||
sizeof(ControlFileDataV0) - sizeof(crc64V0));
|
||||
FIN_CRC64V0(crc);
|
||||
@ -409,12 +412,13 @@ CheckControlVersion0(char *buffer, int len)
|
||||
(char *) malloc(_INTL_MAXLOGRECSZ));
|
||||
if (record == NULL)
|
||||
{
|
||||
|
||||
/*
|
||||
* We have to guess at the checkpoint contents.
|
||||
*/
|
||||
guessed = true;
|
||||
ControlFile.checkPointCopy.ThisStartUpID = 0;
|
||||
ControlFile.checkPointCopy.nextXid = (TransactionId) 514; /* XXX */
|
||||
ControlFile.checkPointCopy.nextXid = (TransactionId) 514; /* XXX */
|
||||
ControlFile.checkPointCopy.nextOid = BootstrapObjectIdData;
|
||||
return true;
|
||||
}
|
||||
@ -435,26 +439,26 @@ CheckControlVersion0(char *buffer, int len)
|
||||
* We assume all of the record has been read into memory at *record.
|
||||
*/
|
||||
static bool
|
||||
RecordIsValidV0(XLogRecordV0 *record)
|
||||
RecordIsValidV0(XLogRecordV0 * record)
|
||||
{
|
||||
crc64V0 crc;
|
||||
uint32 len = record->xl_len;
|
||||
|
||||
/*
|
||||
* NB: this code is not right for V0 records containing backup blocks,
|
||||
* but for now it's only going to be applied to checkpoint records,
|
||||
* so I'm not going to worry about it...
|
||||
* but for now it's only going to be applied to checkpoint records, so
|
||||
* I'm not going to worry about it...
|
||||
*/
|
||||
INIT_CRC64V0(crc);
|
||||
COMP_CRC64V0(crc, XLogRecGetData(record), len);
|
||||
COMP_CRC64V0(crc, (char*) record + sizeof(crc64V0),
|
||||
COMP_CRC64V0(crc, (char *) record + sizeof(crc64V0),
|
||||
SizeOfXLogRecordV0 - sizeof(crc64V0));
|
||||
FIN_CRC64V0(crc);
|
||||
|
||||
if (!EQ_CRC64V0(record->xl_crc, crc))
|
||||
return false;
|
||||
|
||||
return(true);
|
||||
return (true);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -489,7 +493,7 @@ ReadRecordV0(XLogRecPtr *RecPtr, char *buffer)
|
||||
readFile = XLogFileOpen(readId, readSeg);
|
||||
if (readFile < 0)
|
||||
goto next_record_is_invalid;
|
||||
readOff = (uint32) (-1); /* force read to occur below */
|
||||
readOff = (uint32) (-1);/* force read to occur below */
|
||||
}
|
||||
|
||||
targetPageOff = ((RecPtr->xrecoff % XLogSegSize) / BLCKSZ) * BLCKSZ;
|
||||
@ -510,10 +514,13 @@ ReadRecordV0(XLogRecPtr *RecPtr, char *buffer)
|
||||
|
||||
if (record->xl_len == 0)
|
||||
goto next_record_is_invalid;
|
||||
|
||||
/*
|
||||
* Compute total length of record including any appended backup blocks.
|
||||
* Compute total length of record including any appended backup
|
||||
* blocks.
|
||||
*/
|
||||
total_len = SizeOfXLogRecordV0 + record->xl_len;
|
||||
|
||||
/*
|
||||
* Make sure it will fit in buffer (currently, it is mechanically
|
||||
* impossible for this test to fail, but it seems like a good idea
|
||||
@ -526,7 +533,7 @@ ReadRecordV0(XLogRecPtr *RecPtr, char *buffer)
|
||||
{
|
||||
/* Need to reassemble record */
|
||||
XLogContRecordV0 *contrecord;
|
||||
uint32 gotlen = len;
|
||||
uint32 gotlen = len;
|
||||
|
||||
memcpy(buffer, record, len);
|
||||
record = (XLogRecordV0 *) buffer;
|
||||
@ -551,13 +558,13 @@ ReadRecordV0(XLogRecPtr *RecPtr, char *buffer)
|
||||
if (!(((XLogPageHeaderV0) readBuf)->xlp_info & XLP_FIRST_IS_CONTRECORD))
|
||||
goto next_record_is_invalid;
|
||||
contrecord = (XLogContRecordV0 *) ((char *) readBuf + SizeOfXLogPHDV0);
|
||||
if (contrecord->xl_len == 0 ||
|
||||
if (contrecord->xl_len == 0 ||
|
||||
total_len != (contrecord->xl_len + gotlen))
|
||||
goto next_record_is_invalid;
|
||||
len = BLCKSZ - SizeOfXLogPHDV0 - SizeOfXLogContRecordV0;
|
||||
if (contrecord->xl_len > len)
|
||||
{
|
||||
memcpy(buffer, (char *)contrecord + SizeOfXLogContRecordV0, len);
|
||||
memcpy(buffer, (char *) contrecord + SizeOfXLogContRecordV0, len);
|
||||
gotlen += len;
|
||||
buffer += len;
|
||||
continue;
|
||||
@ -587,7 +594,7 @@ next_record_is_invalid:;
|
||||
* Check whether the xlog header of a page just read in looks valid.
|
||||
*
|
||||
* This is just a convenience subroutine to avoid duplicated code in
|
||||
* ReadRecord. It's not intended for use from anywhere else.
|
||||
* ReadRecord. It's not intended for use from anywhere else.
|
||||
*/
|
||||
static bool
|
||||
ValidXLOGHeaderV0(XLogPageHeaderV0 hdr)
|
||||
@ -610,6 +617,7 @@ GuessControlValues(void)
|
||||
{
|
||||
#ifdef USE_LOCALE
|
||||
char *localeptr;
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
@ -625,7 +633,7 @@ GuessControlValues(void)
|
||||
ControlFile.checkPointCopy.redo.xrecoff = SizeOfXLogPHD;
|
||||
ControlFile.checkPointCopy.undo = ControlFile.checkPointCopy.redo;
|
||||
ControlFile.checkPointCopy.ThisStartUpID = 0;
|
||||
ControlFile.checkPointCopy.nextXid = (TransactionId) 514; /* XXX */
|
||||
ControlFile.checkPointCopy.nextXid = (TransactionId) 514; /* XXX */
|
||||
ControlFile.checkPointCopy.nextOid = BootstrapObjectIdData;
|
||||
ControlFile.checkPointCopy.time = time(NULL);
|
||||
|
||||
@ -677,7 +685,7 @@ PrintControlValues(void)
|
||||
"pg_control version number: %u\n"
|
||||
"Catalog version number: %u\n"
|
||||
"Current log file id: %u\n"
|
||||
"Next log file segment: %u\n"
|
||||
"Next log file segment: %u\n"
|
||||
"Latest checkpoint's StartUpID: %u\n"
|
||||
"Latest checkpoint's NextXID: %u\n"
|
||||
"Latest checkpoint's NextOID: %u\n"
|
||||
@ -707,11 +715,11 @@ static void
|
||||
RewriteControlFile(void)
|
||||
{
|
||||
int fd;
|
||||
char buffer[BLCKSZ]; /* need not be aligned */
|
||||
char buffer[BLCKSZ]; /* need not be aligned */
|
||||
|
||||
/*
|
||||
* Adjust fields as needed to force an empty XLOG starting at the
|
||||
* next available segment.
|
||||
* Adjust fields as needed to force an empty XLOG starting at the next
|
||||
* available segment.
|
||||
*/
|
||||
newXlogId = ControlFile.logId;
|
||||
newXlogSeg = ControlFile.logSeg;
|
||||
@ -734,17 +742,17 @@ RewriteControlFile(void)
|
||||
|
||||
/* Contents are protected with a CRC */
|
||||
INIT_CRC64(ControlFile.crc);
|
||||
COMP_CRC64(ControlFile.crc,
|
||||
(char*) &ControlFile + sizeof(crc64),
|
||||
COMP_CRC64(ControlFile.crc,
|
||||
(char *) &ControlFile + sizeof(crc64),
|
||||
sizeof(ControlFileData) - sizeof(crc64));
|
||||
FIN_CRC64(ControlFile.crc);
|
||||
|
||||
/*
|
||||
* We write out BLCKSZ bytes into pg_control, zero-padding the
|
||||
* excess over sizeof(ControlFileData). This reduces the odds
|
||||
* of premature-EOF errors when reading pg_control. We'll still
|
||||
* fail when we check the contents of the file, but hopefully with
|
||||
* a more specific error than "couldn't read pg_control".
|
||||
* We write out BLCKSZ bytes into pg_control, zero-padding the excess
|
||||
* over sizeof(ControlFileData). This reduces the odds of
|
||||
* premature-EOF errors when reading pg_control. We'll still fail
|
||||
* when we check the contents of the file, but hopefully with a more
|
||||
* specific error than "couldn't read pg_control".
|
||||
*/
|
||||
if (sizeof(ControlFileData) > BLCKSZ)
|
||||
{
|
||||
@ -786,9 +794,9 @@ RewriteControlFile(void)
|
||||
static void
|
||||
KillExistingXLOG(void)
|
||||
{
|
||||
DIR *xldir;
|
||||
struct dirent *xlde;
|
||||
char path[MAXPGPATH];
|
||||
DIR *xldir;
|
||||
struct dirent *xlde;
|
||||
char path[MAXPGPATH];
|
||||
|
||||
xldir = opendir(XLogDir);
|
||||
if (xldir == NULL)
|
||||
@ -803,7 +811,7 @@ KillExistingXLOG(void)
|
||||
if (strlen(xlde->d_name) == 16 &&
|
||||
strspn(xlde->d_name, "0123456789ABCDEF") == 16)
|
||||
{
|
||||
sprintf(path, "%s%c%s", XLogDir, SEP_CHAR, xlde->d_name);
|
||||
sprintf(path, "%s%c%s", XLogDir, SEP_CHAR, xlde->d_name);
|
||||
if (unlink(path) < 0)
|
||||
{
|
||||
perror(path);
|
||||
@ -858,7 +866,7 @@ WriteEmptyXLOG(void)
|
||||
|
||||
INIT_CRC64(crc);
|
||||
COMP_CRC64(crc, &ControlFile.checkPointCopy, sizeof(CheckPoint));
|
||||
COMP_CRC64(crc, (char*) record + sizeof(crc64),
|
||||
COMP_CRC64(crc, (char *) record + sizeof(crc64),
|
||||
SizeOfXLogRecord - sizeof(crc64));
|
||||
FIN_CRC64(crc);
|
||||
record->xl_crc = crc;
|
||||
@ -914,13 +922,13 @@ usage(void)
|
||||
|
||||
|
||||
int
|
||||
main(int argc, char ** argv)
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
int argn;
|
||||
bool force = false;
|
||||
bool noupdate = false;
|
||||
int fd;
|
||||
char path[MAXPGPATH];
|
||||
int argn;
|
||||
bool force = false;
|
||||
bool noupdate = false;
|
||||
int fd;
|
||||
char path[MAXPGPATH];
|
||||
|
||||
for (argn = 1; argn < argc; argn++)
|
||||
{
|
||||
@ -934,7 +942,7 @@ main(int argc, char ** argv)
|
||||
usage();
|
||||
}
|
||||
|
||||
if (argn != argc-1) /* one required non-switch argument */
|
||||
if (argn != argc - 1) /* one required non-switch argument */
|
||||
usage();
|
||||
|
||||
DataDir = argv[argn++];
|
||||
@ -946,7 +954,8 @@ main(int argc, char ** argv)
|
||||
|
||||
/*
|
||||
* Check for a postmaster lock file --- if there is one, refuse to
|
||||
* proceed, on grounds we might be interfering with a live installation.
|
||||
* proceed, on grounds we might be interfering with a live
|
||||
* installation.
|
||||
*/
|
||||
snprintf(path, MAXPGPATH, "%s%cpostmaster.pid", DataDir, SEP_CHAR);
|
||||
|
||||
@ -973,8 +982,8 @@ main(int argc, char ** argv)
|
||||
GuessControlValues();
|
||||
|
||||
/*
|
||||
* If we had to guess anything, and -f was not given, just print
|
||||
* the guessed values and exit. Also print if -n is given.
|
||||
* If we had to guess anything, and -f was not given, just print the
|
||||
* guessed values and exit. Also print if -n is given.
|
||||
*/
|
||||
if ((guessed && !force) || noupdate)
|
||||
{
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* encode.c
|
||||
* Various data encoding/decoding things.
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2001 Marko Kreen
|
||||
* All rights reserved.
|
||||
*
|
||||
@ -9,15 +9,15 @@
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
@ -26,7 +26,7 @@
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: encode.c,v 1.3 2001/02/10 02:31:25 tgl Exp $
|
||||
* $Id: encode.c,v 1.4 2001/03/22 03:59:10 momjian Exp $
|
||||
*/
|
||||
|
||||
#include "postgres.h"
|
||||
@ -43,9 +43,9 @@
|
||||
#endif
|
||||
|
||||
static pg_coding *
|
||||
find_coding(pg_coding *hbuf, text *name, int silent);
|
||||
find_coding(pg_coding * hbuf, text *name, int silent);
|
||||
static pg_coding *
|
||||
pg_find_coding(pg_coding *res, char *name);
|
||||
pg_find_coding(pg_coding * res, char *name);
|
||||
|
||||
|
||||
/* SQL function: encode(bytea, text) returns text */
|
||||
@ -54,34 +54,37 @@ PG_FUNCTION_INFO_V1(encode);
|
||||
Datum
|
||||
encode(PG_FUNCTION_ARGS)
|
||||
{
|
||||
text *arg;
|
||||
text *name;
|
||||
uint len, rlen, rlen0;
|
||||
pg_coding *c, cbuf;
|
||||
text *res;
|
||||
|
||||
text *arg;
|
||||
text *name;
|
||||
uint len,
|
||||
rlen,
|
||||
rlen0;
|
||||
pg_coding *c,
|
||||
cbuf;
|
||||
text *res;
|
||||
|
||||
if (PG_ARGISNULL(0) || PG_ARGISNULL(1))
|
||||
PG_RETURN_NULL();
|
||||
|
||||
name = PG_GETARG_TEXT_P(1);
|
||||
c = find_coding(&cbuf, name, 0); /* will give error if fails */
|
||||
|
||||
name = PG_GETARG_TEXT_P(1);
|
||||
c = find_coding(&cbuf, name, 0); /* will give error if fails */
|
||||
|
||||
arg = PG_GETARG_TEXT_P(0);
|
||||
len = VARSIZE(arg) - VARHDRSZ;
|
||||
|
||||
|
||||
rlen0 = c->encode_len(len);
|
||||
|
||||
res = (text *)palloc(rlen0 + VARHDRSZ);
|
||||
|
||||
|
||||
res = (text *) palloc(rlen0 + VARHDRSZ);
|
||||
|
||||
rlen = c->encode(VARDATA(arg), len, VARDATA(res));
|
||||
VARATT_SIZEP(res) = rlen + VARHDRSZ;
|
||||
|
||||
if (rlen > rlen0)
|
||||
elog(FATAL, "pg_encode: overflow, encode estimate too small");
|
||||
|
||||
|
||||
PG_FREE_IF_COPY(arg, 0);
|
||||
PG_FREE_IF_COPY(name, 1);
|
||||
|
||||
|
||||
PG_RETURN_TEXT_P(res);
|
||||
}
|
||||
|
||||
@ -91,54 +94,58 @@ PG_FUNCTION_INFO_V1(decode);
|
||||
Datum
|
||||
decode(PG_FUNCTION_ARGS)
|
||||
{
|
||||
text *arg;
|
||||
text *name;
|
||||
uint len, rlen, rlen0;
|
||||
pg_coding *c, cbuf;
|
||||
text *res;
|
||||
|
||||
text *arg;
|
||||
text *name;
|
||||
uint len,
|
||||
rlen,
|
||||
rlen0;
|
||||
pg_coding *c,
|
||||
cbuf;
|
||||
text *res;
|
||||
|
||||
if (PG_ARGISNULL(0) || PG_ARGISNULL(1))
|
||||
PG_RETURN_NULL();
|
||||
|
||||
name = PG_GETARG_TEXT_P(1);
|
||||
c = find_coding(&cbuf, name, 0); /* will give error if fails */
|
||||
|
||||
name = PG_GETARG_TEXT_P(1);
|
||||
c = find_coding(&cbuf, name, 0); /* will give error if fails */
|
||||
|
||||
arg = PG_GETARG_TEXT_P(0);
|
||||
len = VARSIZE(arg) - VARHDRSZ;
|
||||
|
||||
|
||||
rlen0 = c->decode_len(len);
|
||||
|
||||
res = (text *)palloc(rlen0 + VARHDRSZ);
|
||||
|
||||
|
||||
res = (text *) palloc(rlen0 + VARHDRSZ);
|
||||
|
||||
rlen = c->decode(VARDATA(arg), len, VARDATA(res));
|
||||
VARATT_SIZEP(res) = rlen + VARHDRSZ;
|
||||
|
||||
if (rlen > rlen0)
|
||||
elog(FATAL, "pg_decode: overflow, decode estimate too small");
|
||||
|
||||
|
||||
PG_FREE_IF_COPY(arg, 0);
|
||||
PG_FREE_IF_COPY(name, 1);
|
||||
|
||||
|
||||
PG_RETURN_TEXT_P(res);
|
||||
}
|
||||
|
||||
static pg_coding *
|
||||
find_coding(pg_coding *dst, text *name, int silent)
|
||||
find_coding(pg_coding * dst, text *name, int silent)
|
||||
{
|
||||
pg_coding *p;
|
||||
char buf[NAMEDATALEN];
|
||||
uint len;
|
||||
|
||||
pg_coding *p;
|
||||
char buf[NAMEDATALEN];
|
||||
uint len;
|
||||
|
||||
len = VARSIZE(name) - VARHDRSZ;
|
||||
if (len >= NAMEDATALEN) {
|
||||
if (len >= NAMEDATALEN)
|
||||
{
|
||||
if (silent)
|
||||
return NULL;
|
||||
elog(ERROR, "Encoding type does not exist (name too long)");
|
||||
}
|
||||
|
||||
|
||||
memcpy(buf, VARDATA(name), len);
|
||||
buf[len] = 0;
|
||||
|
||||
|
||||
p = pg_find_coding(dst, buf);
|
||||
|
||||
if (p == NULL && !silent)
|
||||
@ -151,21 +158,23 @@ static char *hextbl = "0123456789abcdef";
|
||||
uint
|
||||
hex_encode(uint8 *src, uint len, uint8 *dst)
|
||||
{
|
||||
uint8 *end = src + len;
|
||||
while (src < end) {
|
||||
uint8 *end = src + len;
|
||||
|
||||
while (src < end)
|
||||
{
|
||||
*dst++ = hextbl[(*src >> 4) & 0xF];
|
||||
*dst++ = hextbl[*src & 0xF];
|
||||
src++;
|
||||
}
|
||||
return len*2;
|
||||
return len * 2;
|
||||
}
|
||||
|
||||
/* probably should use lookup table */
|
||||
static uint8
|
||||
get_hex(char c)
|
||||
{
|
||||
uint8 res = 0;
|
||||
|
||||
uint8 res = 0;
|
||||
|
||||
if (c >= '0' && c <= '9')
|
||||
res = c - '0';
|
||||
else if (c >= 'a' && c <= 'f')
|
||||
@ -174,19 +183,26 @@ get_hex(char c)
|
||||
res = c - 'A' + 10;
|
||||
else
|
||||
elog(ERROR, "Bad hex code: '%c'", c);
|
||||
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
uint
|
||||
hex_decode(uint8 *src, uint len, uint8 *dst)
|
||||
{
|
||||
uint8 *s, *srcend, v1, v2, *p = dst;
|
||||
|
||||
uint8 *s,
|
||||
*srcend,
|
||||
v1,
|
||||
v2,
|
||||
*p = dst;
|
||||
|
||||
srcend = src + len;
|
||||
s = src; p = dst;
|
||||
while (s < srcend) {
|
||||
if (*s == ' ' || *s == '\n' || *s == '\t' || *s == '\r') {
|
||||
s = src;
|
||||
p = dst;
|
||||
while (s < srcend)
|
||||
{
|
||||
if (*s == ' ' || *s == '\n' || *s == '\t' || *s == '\r')
|
||||
{
|
||||
s++;
|
||||
continue;
|
||||
}
|
||||
@ -196,30 +212,36 @@ hex_decode(uint8 *src, uint len, uint8 *dst)
|
||||
v2 = get_hex(*s++);
|
||||
*p++ = v1 | v2;
|
||||
}
|
||||
|
||||
|
||||
return p - dst;
|
||||
}
|
||||
|
||||
|
||||
static unsigned char _base64[] =
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
|
||||
uint
|
||||
b64_encode(uint8 *src, uint len, uint8 *dst)
|
||||
{
|
||||
uint8 *s, *p, *end = src + len, *lend = dst + 76;
|
||||
int pos = 2;
|
||||
uint8 *s,
|
||||
*p,
|
||||
*end = src + len,
|
||||
*lend = dst + 76;
|
||||
int pos = 2;
|
||||
unsigned long buf = 0;
|
||||
|
||||
s = src; p = dst;
|
||||
|
||||
while (s < end) {
|
||||
s = src;
|
||||
p = dst;
|
||||
|
||||
while (s < end)
|
||||
{
|
||||
buf |= *s << (pos << 3);
|
||||
pos--;
|
||||
s++;
|
||||
|
||||
|
||||
/* write it out */
|
||||
if (pos < 0) {
|
||||
if (pos < 0)
|
||||
{
|
||||
*p++ = _base64[(buf >> 18) & 0x3f];
|
||||
*p++ = _base64[(buf >> 12) & 0x3f];
|
||||
*p++ = _base64[(buf >> 6) & 0x3f];
|
||||
@ -228,12 +250,14 @@ b64_encode(uint8 *src, uint len, uint8 *dst)
|
||||
pos = 2;
|
||||
buf = 0;
|
||||
}
|
||||
if (p >= lend) {
|
||||
if (p >= lend)
|
||||
{
|
||||
*p++ = '\n';
|
||||
lend = p + 76;
|
||||
}
|
||||
}
|
||||
if (pos != 2) {
|
||||
if (pos != 2)
|
||||
{
|
||||
*p++ = _base64[(buf >> 18) & 0x3f];
|
||||
*p++ = _base64[(buf >> 12) & 0x3f];
|
||||
*p++ = (pos == 0) ? _base64[(buf >> 6) & 0x3f] : '=';
|
||||
@ -247,14 +271,17 @@ b64_encode(uint8 *src, uint len, uint8 *dst)
|
||||
uint
|
||||
b64_decode(uint8 *src, uint len, uint8 *dst)
|
||||
{
|
||||
char *srcend = src + len, *s = src;
|
||||
uint8 *p = dst;
|
||||
char c;
|
||||
uint b = 0;
|
||||
char *srcend = src + len,
|
||||
*s = src;
|
||||
uint8 *p = dst;
|
||||
char c;
|
||||
uint b = 0;
|
||||
unsigned long buf = 0;
|
||||
int pos = 0, end = 0;
|
||||
|
||||
while (s < srcend) {
|
||||
int pos = 0,
|
||||
end = 0;
|
||||
|
||||
while (s < srcend)
|
||||
{
|
||||
c = *s++;
|
||||
if (c >= 'A' && c <= 'Z')
|
||||
b = c - 'A';
|
||||
@ -266,16 +293,21 @@ b64_decode(uint8 *src, uint len, uint8 *dst)
|
||||
b = 62;
|
||||
else if (c == '/')
|
||||
b = 63;
|
||||
else if (c == '=') {
|
||||
else if (c == '=')
|
||||
{
|
||||
/* end sequence */
|
||||
if (!end) {
|
||||
if (pos == 2) end = 1;
|
||||
else if (pos == 3) end = 2;
|
||||
if (!end)
|
||||
{
|
||||
if (pos == 2)
|
||||
end = 1;
|
||||
else if (pos == 3)
|
||||
end = 2;
|
||||
else
|
||||
elog(ERROR, "base64: unexpected '='");
|
||||
}
|
||||
b = 0;
|
||||
} else if (c == ' ' || c == '\t' || c == '\n' || c == '\r')
|
||||
}
|
||||
else if (c == ' ' || c == '\t' || c == '\n' || c == '\r')
|
||||
continue;
|
||||
else
|
||||
elog(ERROR, "base64: Invalid symbol");
|
||||
@ -283,7 +315,8 @@ b64_decode(uint8 *src, uint len, uint8 *dst)
|
||||
/* add it to buffer */
|
||||
buf = (buf << 6) + b;
|
||||
pos++;
|
||||
if (pos == 4) {
|
||||
if (pos == 4)
|
||||
{
|
||||
*p++ = (buf >> 16) & 255;
|
||||
if (end == 0 || end > 1)
|
||||
*p++ = (buf >> 8) & 255;
|
||||
@ -326,21 +359,22 @@ b64_dec_len(uint srclen)
|
||||
}
|
||||
|
||||
static pg_coding
|
||||
encoding_list [] = {
|
||||
{ "hex", hex_enc_len, hex_dec_len, hex_encode, hex_decode},
|
||||
{ "base64", b64_enc_len, b64_dec_len, b64_encode, b64_decode},
|
||||
{ NULL, NULL, NULL, NULL, NULL}
|
||||
encoding_list[] = {
|
||||
{"hex", hex_enc_len, hex_dec_len, hex_encode, hex_decode},
|
||||
{"base64", b64_enc_len, b64_dec_len, b64_encode, b64_decode},
|
||||
{NULL, NULL, NULL, NULL, NULL}
|
||||
};
|
||||
|
||||
|
||||
static pg_coding *
|
||||
pg_find_coding(pg_coding *res, char *name)
|
||||
pg_find_coding(pg_coding * res, char *name)
|
||||
{
|
||||
pg_coding *p;
|
||||
for (p = encoding_list; p->name; p++) {
|
||||
pg_coding *p;
|
||||
|
||||
for (p = encoding_list; p->name; p++)
|
||||
{
|
||||
if (!strcasecmp(p->name, name))
|
||||
return p;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* pg_encode.h
|
||||
* encode.c
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2001 Marko Kreen
|
||||
* All rights reserved.
|
||||
*
|
||||
@ -9,15 +9,15 @@
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
@ -26,35 +26,35 @@
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: encode.h,v 1.1 2001/01/24 03:46:16 momjian Exp $
|
||||
* $Id: encode.h,v 1.2 2001/03/22 03:59:10 momjian Exp $
|
||||
*/
|
||||
|
||||
#ifndef __PG_ENCODE_H
|
||||
#define __PG_ENCODE_H
|
||||
|
||||
/* exported functions */
|
||||
Datum encode(PG_FUNCTION_ARGS);
|
||||
Datum decode(PG_FUNCTION_ARGS);
|
||||
Datum encode(PG_FUNCTION_ARGS);
|
||||
Datum decode(PG_FUNCTION_ARGS);
|
||||
|
||||
typedef struct _pg_coding pg_coding;
|
||||
struct _pg_coding {
|
||||
char *name;
|
||||
uint (*encode_len)(uint dlen);
|
||||
uint (*decode_len)(uint dlen);
|
||||
uint (*encode)(uint8 *data, uint dlen, uint8 *res);
|
||||
uint (*decode)(uint8 *data, uint dlen, uint8 *res);
|
||||
struct _pg_coding
|
||||
{
|
||||
char *name;
|
||||
uint (*encode_len) (uint dlen);
|
||||
uint (*decode_len) (uint dlen);
|
||||
uint (*encode) (uint8 *data, uint dlen, uint8 *res);
|
||||
uint (*decode) (uint8 *data, uint dlen, uint8 *res);
|
||||
};
|
||||
|
||||
/* They are for outside usage in C code, if needed */
|
||||
uint hex_encode(uint8 *src, uint len, uint8 *dst);
|
||||
uint hex_decode(uint8 *src, uint len, uint8 *dst);
|
||||
uint b64_encode(uint8 *src, uint len, uint8 *dst);
|
||||
uint b64_decode(uint8 *src, uint len, uint8 *dst);
|
||||
uint hex_encode(uint8 *src, uint len, uint8 *dst);
|
||||
uint hex_decode(uint8 *src, uint len, uint8 *dst);
|
||||
uint b64_encode(uint8 *src, uint len, uint8 *dst);
|
||||
uint b64_decode(uint8 *src, uint len, uint8 *dst);
|
||||
|
||||
uint hex_enc_len(uint srclen);
|
||||
uint hex_dec_len(uint srclen);
|
||||
uint b64_enc_len(uint srclen);
|
||||
uint b64_dec_len(uint srclen);
|
||||
|
||||
#endif /* __PG_ENCODE_H */
|
||||
uint hex_enc_len(uint srclen);
|
||||
uint hex_dec_len(uint srclen);
|
||||
uint b64_enc_len(uint srclen);
|
||||
uint b64_dec_len(uint srclen);
|
||||
|
||||
#endif /* __PG_ENCODE_H */
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* internal.c
|
||||
* Wrapper for builtin functions
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2000 Marko Kreen
|
||||
* All rights reserved.
|
||||
*
|
||||
@ -9,15 +9,15 @@
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
@ -26,7 +26,7 @@
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: internal.c,v 1.2 2001/02/10 02:31:25 tgl Exp $
|
||||
* $Id: internal.c,v 1.3 2001/03/22 03:59:10 momjian Exp $
|
||||
*/
|
||||
|
||||
#include "postgres.h"
|
||||
@ -49,31 +49,32 @@
|
||||
#endif
|
||||
|
||||
static uint
|
||||
pg_md5_len(pg_digest *h);
|
||||
pg_md5_len(pg_digest * h);
|
||||
static uint8 *
|
||||
pg_md5_digest(pg_digest *h, uint8 *src, uint len, uint8 *buf);
|
||||
pg_md5_digest(pg_digest * h, uint8 *src, uint len, uint8 *buf);
|
||||
|
||||
static uint
|
||||
pg_sha1_len(pg_digest *h);
|
||||
pg_sha1_len(pg_digest * h);
|
||||
static uint8 *
|
||||
pg_sha1_digest(pg_digest *h, uint8 *src, uint len, uint8 *buf);
|
||||
pg_sha1_digest(pg_digest * h, uint8 *src, uint len, uint8 *buf);
|
||||
|
||||
static pg_digest
|
||||
int_digest_list [] = {
|
||||
{ "md5", pg_md5_len, pg_md5_digest, {0}},
|
||||
{ "sha1", pg_sha1_len, pg_sha1_digest, {0}},
|
||||
{ NULL, NULL, NULL, {0}}
|
||||
int_digest_list[] = {
|
||||
{"md5", pg_md5_len, pg_md5_digest, {0}},
|
||||
{"sha1", pg_sha1_len, pg_sha1_digest, {0}},
|
||||
{NULL, NULL, NULL, {0}}
|
||||
};
|
||||
|
||||
static uint
|
||||
pg_md5_len(pg_digest *h) {
|
||||
pg_md5_len(pg_digest * h)
|
||||
{
|
||||
return MD5_DIGEST_LENGTH;
|
||||
}
|
||||
|
||||
static uint8 *
|
||||
pg_md5_digest(pg_digest *h, uint8 *src, uint len, uint8 *buf)
|
||||
pg_md5_digest(pg_digest * h, uint8 *src, uint len, uint8 *buf)
|
||||
{
|
||||
MD5_CTX ctx;
|
||||
MD5_CTX ctx;
|
||||
|
||||
MD5Init(&ctx);
|
||||
MD5Update(&ctx, src, len);
|
||||
@ -83,32 +84,31 @@ pg_md5_digest(pg_digest *h, uint8 *src, uint len, uint8 *buf)
|
||||
}
|
||||
|
||||
static uint
|
||||
pg_sha1_len(pg_digest *h) {
|
||||
pg_sha1_len(pg_digest * h)
|
||||
{
|
||||
return SHA1_DIGEST_LENGTH;
|
||||
}
|
||||
|
||||
static uint8 *
|
||||
pg_sha1_digest(pg_digest *h, uint8 *src, uint len, uint8 *buf)
|
||||
pg_sha1_digest(pg_digest * h, uint8 *src, uint len, uint8 *buf)
|
||||
{
|
||||
SHA1_CTX ctx;
|
||||
SHA1_CTX ctx;
|
||||
|
||||
SHA1Init(&ctx);
|
||||
SHA1Update(&ctx, src, len);
|
||||
SHA1Final(buf, &ctx);
|
||||
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
||||
pg_digest *
|
||||
pg_find_digest(pg_digest *h, char *name)
|
||||
pg_digest *
|
||||
pg_find_digest(pg_digest * h, char *name)
|
||||
{
|
||||
pg_digest *p;
|
||||
pg_digest *p;
|
||||
|
||||
for (p = int_digest_list; p->name; p++)
|
||||
if (!strcasecmp(p->name, name))
|
||||
return p;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* krb.c
|
||||
* Wrapper for Kerberos5 libdes SHA1/MD5.
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2000 Marko Kreen
|
||||
* All rights reserved.
|
||||
*
|
||||
@ -9,15 +9,15 @@
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
@ -26,12 +26,12 @@
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
*
|
||||
* NOTES
|
||||
* It is possible that this works with other SHA1/MD5
|
||||
* implementations too.
|
||||
*
|
||||
* $Id: krb.c,v 1.3 2001/02/20 15:34:14 momjian Exp $
|
||||
* $Id: krb.c,v 1.4 2001/03/22 03:59:10 momjian Exp $
|
||||
*/
|
||||
|
||||
#include "postgres.h"
|
||||
@ -54,31 +54,32 @@
|
||||
#endif
|
||||
|
||||
static uint
|
||||
pg_md5_len(pg_digest *h);
|
||||
pg_md5_len(pg_digest * h);
|
||||
static uint8 *
|
||||
pg_md5_digest(pg_digest *h, uint8 *src, uint len, uint8 *buf);
|
||||
pg_md5_digest(pg_digest * h, uint8 *src, uint len, uint8 *buf);
|
||||
|
||||
static uint
|
||||
pg_sha1_len(pg_digest *h);
|
||||
pg_sha1_len(pg_digest * h);
|
||||
static uint8 *
|
||||
pg_sha1_digest(pg_digest *h, uint8 *src, uint len, uint8 *buf);
|
||||
pg_sha1_digest(pg_digest * h, uint8 *src, uint len, uint8 *buf);
|
||||
|
||||
static pg_digest
|
||||
int_digest_list [] = {
|
||||
{ "md5", pg_md5_len, pg_md5_digest, {0}},
|
||||
{ "sha1", pg_sha1_len, pg_sha1_digest, {0}},
|
||||
{ NULL, NULL, NULL, {0}}
|
||||
int_digest_list[] = {
|
||||
{"md5", pg_md5_len, pg_md5_digest, {0}},
|
||||
{"sha1", pg_sha1_len, pg_sha1_digest, {0}},
|
||||
{NULL, NULL, NULL, {0}}
|
||||
};
|
||||
|
||||
static uint
|
||||
pg_md5_len(pg_digest *h) {
|
||||
pg_md5_len(pg_digest * h)
|
||||
{
|
||||
return MD5_DIGEST_LENGTH;
|
||||
}
|
||||
|
||||
static uint8 *
|
||||
pg_md5_digest(pg_digest *h, uint8 *src, uint len, uint8 *buf)
|
||||
pg_md5_digest(pg_digest * h, uint8 *src, uint len, uint8 *buf)
|
||||
{
|
||||
MD5_CTX ctx;
|
||||
MD5_CTX ctx;
|
||||
|
||||
MD5Init(&ctx);
|
||||
MD5Update(&ctx, src, len);
|
||||
@ -88,32 +89,31 @@ pg_md5_digest(pg_digest *h, uint8 *src, uint len, uint8 *buf)
|
||||
}
|
||||
|
||||
static uint
|
||||
pg_sha1_len(pg_digest *h) {
|
||||
pg_sha1_len(pg_digest * h)
|
||||
{
|
||||
return SHA1_DIGEST_LENGTH;
|
||||
}
|
||||
|
||||
static uint8 *
|
||||
pg_sha1_digest(pg_digest *h, uint8 *src, uint len, uint8 *buf)
|
||||
pg_sha1_digest(pg_digest * h, uint8 *src, uint len, uint8 *buf)
|
||||
{
|
||||
SHA1_CTX ctx;
|
||||
SHA1_CTX ctx;
|
||||
|
||||
SHA1Init(&ctx);
|
||||
SHA1Update(&ctx, src, len);
|
||||
SHA1Final(buf, &ctx);
|
||||
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
||||
pg_digest *
|
||||
pg_find_digest(pg_digest *h, char *name)
|
||||
pg_digest *
|
||||
pg_find_digest(pg_digest * h, char *name)
|
||||
{
|
||||
pg_digest *p;
|
||||
pg_digest *p;
|
||||
|
||||
for (p = int_digest_list; p->name; p++)
|
||||
if (!strcasecmp(p->name, name))
|
||||
return p;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* $Id: md5.c,v 1.4 2001/02/10 02:31:25 tgl Exp $ */
|
||||
/* $KAME: md5.c,v 1.3 2000/02/22 14:01:17 itojun Exp $ */
|
||||
/* $Id: md5.c,v 1.5 2001/03/22 03:59:10 momjian Exp $ */
|
||||
/* $KAME: md5.c,v 1.3 2000/02/22 14:01:17 itojun Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
|
||||
@ -9,18 +9,18 @@
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the project nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
@ -93,42 +93,43 @@
|
||||
/* Integer part of 4294967296 times abs(sin(i)), where i is in radians. */
|
||||
static const uint32 T[65] = {
|
||||
0,
|
||||
0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee,
|
||||
0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501,
|
||||
0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be,
|
||||
0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821,
|
||||
0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee,
|
||||
0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501,
|
||||
0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be,
|
||||
0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821,
|
||||
|
||||
0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa,
|
||||
0xd62f105d, 0x2441453, 0xd8a1e681, 0xe7d3fbc8,
|
||||
0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed,
|
||||
0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a,
|
||||
0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa,
|
||||
0xd62f105d, 0x2441453, 0xd8a1e681, 0xe7d3fbc8,
|
||||
0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed,
|
||||
0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a,
|
||||
|
||||
0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c,
|
||||
0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70,
|
||||
0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x4881d05,
|
||||
0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665,
|
||||
0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c,
|
||||
0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70,
|
||||
0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x4881d05,
|
||||
0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665,
|
||||
|
||||
0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039,
|
||||
0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1,
|
||||
0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1,
|
||||
0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391,
|
||||
0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039,
|
||||
0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1,
|
||||
0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1,
|
||||
0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391,
|
||||
};
|
||||
|
||||
static const uint8 md5_paddat[MD5_BUFLEN] = {
|
||||
0x80, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0x80, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
};
|
||||
|
||||
static void md5_calc (uint8 *, md5_ctxt *);
|
||||
static void md5_calc(uint8 *, md5_ctxt *);
|
||||
|
||||
void md5_init(ctxt)
|
||||
md5_ctxt *ctxt;
|
||||
void
|
||||
md5_init(ctxt)
|
||||
md5_ctxt *ctxt;
|
||||
{
|
||||
ctxt->md5_n = 0;
|
||||
ctxt->md5_i = 0;
|
||||
@ -139,56 +140,64 @@ void md5_init(ctxt)
|
||||
bzero(ctxt->md5_buf, sizeof(ctxt->md5_buf));
|
||||
}
|
||||
|
||||
void md5_loop(ctxt, input, len)
|
||||
md5_ctxt *ctxt;
|
||||
uint8 *input;
|
||||
unsigned int len; /* number of bytes */
|
||||
void
|
||||
md5_loop(ctxt, input, len)
|
||||
md5_ctxt *ctxt;
|
||||
uint8 *input;
|
||||
unsigned int len; /* number of bytes */
|
||||
{
|
||||
unsigned int gap, i;
|
||||
unsigned int gap,
|
||||
i;
|
||||
|
||||
ctxt->md5_n += len * 8; /* byte to bit */
|
||||
ctxt->md5_n += len * 8; /* byte to bit */
|
||||
gap = MD5_BUFLEN - ctxt->md5_i;
|
||||
|
||||
if (len >= gap) {
|
||||
bcopy((void *)input, (void *)(ctxt->md5_buf + ctxt->md5_i),
|
||||
gap);
|
||||
if (len >= gap)
|
||||
{
|
||||
bcopy((void *) input, (void *) (ctxt->md5_buf + ctxt->md5_i),
|
||||
gap);
|
||||
md5_calc(ctxt->md5_buf, ctxt);
|
||||
|
||||
for (i = gap; i + MD5_BUFLEN <= len; i += MD5_BUFLEN) {
|
||||
md5_calc((uint8 *)(input + i), ctxt);
|
||||
}
|
||||
|
||||
for (i = gap; i + MD5_BUFLEN <= len; i += MD5_BUFLEN)
|
||||
md5_calc((uint8 *) (input + i), ctxt);
|
||||
|
||||
ctxt->md5_i = len - i;
|
||||
bcopy((void *)(input + i), (void *)ctxt->md5_buf, ctxt->md5_i);
|
||||
} else {
|
||||
bcopy((void *)input, (void *)(ctxt->md5_buf + ctxt->md5_i),
|
||||
len);
|
||||
bcopy((void *) (input + i), (void *) ctxt->md5_buf, ctxt->md5_i);
|
||||
}
|
||||
else
|
||||
{
|
||||
bcopy((void *) input, (void *) (ctxt->md5_buf + ctxt->md5_i),
|
||||
len);
|
||||
ctxt->md5_i += len;
|
||||
}
|
||||
}
|
||||
|
||||
void md5_pad(ctxt)
|
||||
md5_ctxt *ctxt;
|
||||
void
|
||||
md5_pad(ctxt)
|
||||
md5_ctxt *ctxt;
|
||||
{
|
||||
unsigned int gap;
|
||||
|
||||
/* Don't count up padding. Keep md5_n. */
|
||||
/* Don't count up padding. Keep md5_n. */
|
||||
gap = MD5_BUFLEN - ctxt->md5_i;
|
||||
if (gap > 8) {
|
||||
bcopy((void *)md5_paddat,
|
||||
(void *)(ctxt->md5_buf + ctxt->md5_i),
|
||||
gap - sizeof(ctxt->md5_n));
|
||||
} else {
|
||||
if (gap > 8)
|
||||
{
|
||||
bcopy((void *) md5_paddat,
|
||||
(void *) (ctxt->md5_buf + ctxt->md5_i),
|
||||
gap - sizeof(ctxt->md5_n));
|
||||
}
|
||||
else
|
||||
{
|
||||
/* including gap == 8 */
|
||||
bcopy((void *)md5_paddat, (void *)(ctxt->md5_buf + ctxt->md5_i),
|
||||
gap);
|
||||
bcopy((void *) md5_paddat, (void *) (ctxt->md5_buf + ctxt->md5_i),
|
||||
gap);
|
||||
md5_calc(ctxt->md5_buf, ctxt);
|
||||
bcopy((void *)(md5_paddat + gap),
|
||||
(void *)ctxt->md5_buf,
|
||||
MD5_BUFLEN - sizeof(ctxt->md5_n));
|
||||
bcopy((void *) (md5_paddat + gap),
|
||||
(void *) ctxt->md5_buf,
|
||||
MD5_BUFLEN - sizeof(ctxt->md5_n));
|
||||
}
|
||||
|
||||
/* 8 byte word */
|
||||
/* 8 byte word */
|
||||
#if BYTE_ORDER == LITTLE_ENDIAN
|
||||
bcopy(&ctxt->md5_n8[0], &ctxt->md5_buf[56], 8);
|
||||
#endif
|
||||
@ -206,98 +215,192 @@ void md5_pad(ctxt)
|
||||
md5_calc(ctxt->md5_buf, ctxt);
|
||||
}
|
||||
|
||||
void md5_result(digest, ctxt)
|
||||
uint8 *digest;
|
||||
md5_ctxt *ctxt;
|
||||
void
|
||||
md5_result(digest, ctxt)
|
||||
uint8 *digest;
|
||||
md5_ctxt *ctxt;
|
||||
{
|
||||
/* 4 byte words */
|
||||
#if BYTE_ORDER == LITTLE_ENDIAN
|
||||
bcopy(&ctxt->md5_st8[0], digest, 16);
|
||||
#endif
|
||||
#if BYTE_ORDER == BIG_ENDIAN
|
||||
digest[ 0] = ctxt->md5_st8[ 3]; digest[ 1] = ctxt->md5_st8[ 2];
|
||||
digest[ 2] = ctxt->md5_st8[ 1]; digest[ 3] = ctxt->md5_st8[ 0];
|
||||
digest[ 4] = ctxt->md5_st8[ 7]; digest[ 5] = ctxt->md5_st8[ 6];
|
||||
digest[ 6] = ctxt->md5_st8[ 5]; digest[ 7] = ctxt->md5_st8[ 4];
|
||||
digest[ 8] = ctxt->md5_st8[11]; digest[ 9] = ctxt->md5_st8[10];
|
||||
digest[10] = ctxt->md5_st8[ 9]; digest[11] = ctxt->md5_st8[ 8];
|
||||
digest[12] = ctxt->md5_st8[15]; digest[13] = ctxt->md5_st8[14];
|
||||
digest[14] = ctxt->md5_st8[13]; digest[15] = ctxt->md5_st8[12];
|
||||
digest[0] = ctxt->md5_st8[3];
|
||||
digest[1] = ctxt->md5_st8[2];
|
||||
digest[2] = ctxt->md5_st8[1];
|
||||
digest[3] = ctxt->md5_st8[0];
|
||||
digest[4] = ctxt->md5_st8[7];
|
||||
digest[5] = ctxt->md5_st8[6];
|
||||
digest[6] = ctxt->md5_st8[5];
|
||||
digest[7] = ctxt->md5_st8[4];
|
||||
digest[8] = ctxt->md5_st8[11];
|
||||
digest[9] = ctxt->md5_st8[10];
|
||||
digest[10] = ctxt->md5_st8[9];
|
||||
digest[11] = ctxt->md5_st8[8];
|
||||
digest[12] = ctxt->md5_st8[15];
|
||||
digest[13] = ctxt->md5_st8[14];
|
||||
digest[14] = ctxt->md5_st8[13];
|
||||
digest[15] = ctxt->md5_st8[12];
|
||||
#endif
|
||||
}
|
||||
|
||||
#if BYTE_ORDER == BIG_ENDIAN
|
||||
uint32 X[16];
|
||||
uint32 X[16];
|
||||
|
||||
#endif
|
||||
|
||||
static void md5_calc(b64, ctxt)
|
||||
uint8 *b64;
|
||||
md5_ctxt *ctxt;
|
||||
static void
|
||||
md5_calc(b64, ctxt)
|
||||
uint8 *b64;
|
||||
md5_ctxt *ctxt;
|
||||
{
|
||||
uint32 A = ctxt->md5_sta;
|
||||
uint32 B = ctxt->md5_stb;
|
||||
uint32 C = ctxt->md5_stc;
|
||||
uint32 D = ctxt->md5_std;
|
||||
uint32 A = ctxt->md5_sta;
|
||||
uint32 B = ctxt->md5_stb;
|
||||
uint32 C = ctxt->md5_stc;
|
||||
uint32 D = ctxt->md5_std;
|
||||
|
||||
#if BYTE_ORDER == LITTLE_ENDIAN
|
||||
uint32 *X = (uint32 *)b64;
|
||||
#endif
|
||||
uint32 *X = (uint32 *) b64;
|
||||
|
||||
#endif
|
||||
#if BYTE_ORDER == BIG_ENDIAN
|
||||
/* 4 byte words */
|
||||
/* what a brute force but fast! */
|
||||
uint8 *y = (uint8 *)X;
|
||||
y[ 0] = b64[ 3]; y[ 1] = b64[ 2]; y[ 2] = b64[ 1]; y[ 3] = b64[ 0];
|
||||
y[ 4] = b64[ 7]; y[ 5] = b64[ 6]; y[ 6] = b64[ 5]; y[ 7] = b64[ 4];
|
||||
y[ 8] = b64[11]; y[ 9] = b64[10]; y[10] = b64[ 9]; y[11] = b64[ 8];
|
||||
y[12] = b64[15]; y[13] = b64[14]; y[14] = b64[13]; y[15] = b64[12];
|
||||
y[16] = b64[19]; y[17] = b64[18]; y[18] = b64[17]; y[19] = b64[16];
|
||||
y[20] = b64[23]; y[21] = b64[22]; y[22] = b64[21]; y[23] = b64[20];
|
||||
y[24] = b64[27]; y[25] = b64[26]; y[26] = b64[25]; y[27] = b64[24];
|
||||
y[28] = b64[31]; y[29] = b64[30]; y[30] = b64[29]; y[31] = b64[28];
|
||||
y[32] = b64[35]; y[33] = b64[34]; y[34] = b64[33]; y[35] = b64[32];
|
||||
y[36] = b64[39]; y[37] = b64[38]; y[38] = b64[37]; y[39] = b64[36];
|
||||
y[40] = b64[43]; y[41] = b64[42]; y[42] = b64[41]; y[43] = b64[40];
|
||||
y[44] = b64[47]; y[45] = b64[46]; y[46] = b64[45]; y[47] = b64[44];
|
||||
y[48] = b64[51]; y[49] = b64[50]; y[50] = b64[49]; y[51] = b64[48];
|
||||
y[52] = b64[55]; y[53] = b64[54]; y[54] = b64[53]; y[55] = b64[52];
|
||||
y[56] = b64[59]; y[57] = b64[58]; y[58] = b64[57]; y[59] = b64[56];
|
||||
y[60] = b64[63]; y[61] = b64[62]; y[62] = b64[61]; y[63] = b64[60];
|
||||
uint8 *y = (uint8 *) X;
|
||||
|
||||
y[0] = b64[3];
|
||||
y[1] = b64[2];
|
||||
y[2] = b64[1];
|
||||
y[3] = b64[0];
|
||||
y[4] = b64[7];
|
||||
y[5] = b64[6];
|
||||
y[6] = b64[5];
|
||||
y[7] = b64[4];
|
||||
y[8] = b64[11];
|
||||
y[9] = b64[10];
|
||||
y[10] = b64[9];
|
||||
y[11] = b64[8];
|
||||
y[12] = b64[15];
|
||||
y[13] = b64[14];
|
||||
y[14] = b64[13];
|
||||
y[15] = b64[12];
|
||||
y[16] = b64[19];
|
||||
y[17] = b64[18];
|
||||
y[18] = b64[17];
|
||||
y[19] = b64[16];
|
||||
y[20] = b64[23];
|
||||
y[21] = b64[22];
|
||||
y[22] = b64[21];
|
||||
y[23] = b64[20];
|
||||
y[24] = b64[27];
|
||||
y[25] = b64[26];
|
||||
y[26] = b64[25];
|
||||
y[27] = b64[24];
|
||||
y[28] = b64[31];
|
||||
y[29] = b64[30];
|
||||
y[30] = b64[29];
|
||||
y[31] = b64[28];
|
||||
y[32] = b64[35];
|
||||
y[33] = b64[34];
|
||||
y[34] = b64[33];
|
||||
y[35] = b64[32];
|
||||
y[36] = b64[39];
|
||||
y[37] = b64[38];
|
||||
y[38] = b64[37];
|
||||
y[39] = b64[36];
|
||||
y[40] = b64[43];
|
||||
y[41] = b64[42];
|
||||
y[42] = b64[41];
|
||||
y[43] = b64[40];
|
||||
y[44] = b64[47];
|
||||
y[45] = b64[46];
|
||||
y[46] = b64[45];
|
||||
y[47] = b64[44];
|
||||
y[48] = b64[51];
|
||||
y[49] = b64[50];
|
||||
y[50] = b64[49];
|
||||
y[51] = b64[48];
|
||||
y[52] = b64[55];
|
||||
y[53] = b64[54];
|
||||
y[54] = b64[53];
|
||||
y[55] = b64[52];
|
||||
y[56] = b64[59];
|
||||
y[57] = b64[58];
|
||||
y[58] = b64[57];
|
||||
y[59] = b64[56];
|
||||
y[60] = b64[63];
|
||||
y[61] = b64[62];
|
||||
y[62] = b64[61];
|
||||
y[63] = b64[60];
|
||||
#endif
|
||||
|
||||
ROUND1(A, B, C, D, 0, Sa, 1); ROUND1(D, A, B, C, 1, Sb, 2);
|
||||
ROUND1(C, D, A, B, 2, Sc, 3); ROUND1(B, C, D, A, 3, Sd, 4);
|
||||
ROUND1(A, B, C, D, 4, Sa, 5); ROUND1(D, A, B, C, 5, Sb, 6);
|
||||
ROUND1(C, D, A, B, 6, Sc, 7); ROUND1(B, C, D, A, 7, Sd, 8);
|
||||
ROUND1(A, B, C, D, 8, Sa, 9); ROUND1(D, A, B, C, 9, Sb, 10);
|
||||
ROUND1(C, D, A, B, 10, Sc, 11); ROUND1(B, C, D, A, 11, Sd, 12);
|
||||
ROUND1(A, B, C, D, 12, Sa, 13); ROUND1(D, A, B, C, 13, Sb, 14);
|
||||
ROUND1(C, D, A, B, 14, Sc, 15); ROUND1(B, C, D, A, 15, Sd, 16);
|
||||
|
||||
ROUND2(A, B, C, D, 1, Se, 17); ROUND2(D, A, B, C, 6, Sf, 18);
|
||||
ROUND2(C, D, A, B, 11, Sg, 19); ROUND2(B, C, D, A, 0, Sh, 20);
|
||||
ROUND2(A, B, C, D, 5, Se, 21); ROUND2(D, A, B, C, 10, Sf, 22);
|
||||
ROUND2(C, D, A, B, 15, Sg, 23); ROUND2(B, C, D, A, 4, Sh, 24);
|
||||
ROUND2(A, B, C, D, 9, Se, 25); ROUND2(D, A, B, C, 14, Sf, 26);
|
||||
ROUND2(C, D, A, B, 3, Sg, 27); ROUND2(B, C, D, A, 8, Sh, 28);
|
||||
ROUND2(A, B, C, D, 13, Se, 29); ROUND2(D, A, B, C, 2, Sf, 30);
|
||||
ROUND2(C, D, A, B, 7, Sg, 31); ROUND2(B, C, D, A, 12, Sh, 32);
|
||||
ROUND1(A, B, C, D, 0, Sa, 1);
|
||||
ROUND1(D, A, B, C, 1, Sb, 2);
|
||||
ROUND1(C, D, A, B, 2, Sc, 3);
|
||||
ROUND1(B, C, D, A, 3, Sd, 4);
|
||||
ROUND1(A, B, C, D, 4, Sa, 5);
|
||||
ROUND1(D, A, B, C, 5, Sb, 6);
|
||||
ROUND1(C, D, A, B, 6, Sc, 7);
|
||||
ROUND1(B, C, D, A, 7, Sd, 8);
|
||||
ROUND1(A, B, C, D, 8, Sa, 9);
|
||||
ROUND1(D, A, B, C, 9, Sb, 10);
|
||||
ROUND1(C, D, A, B, 10, Sc, 11);
|
||||
ROUND1(B, C, D, A, 11, Sd, 12);
|
||||
ROUND1(A, B, C, D, 12, Sa, 13);
|
||||
ROUND1(D, A, B, C, 13, Sb, 14);
|
||||
ROUND1(C, D, A, B, 14, Sc, 15);
|
||||
ROUND1(B, C, D, A, 15, Sd, 16);
|
||||
|
||||
ROUND3(A, B, C, D, 5, Si, 33); ROUND3(D, A, B, C, 8, Sj, 34);
|
||||
ROUND3(C, D, A, B, 11, Sk, 35); ROUND3(B, C, D, A, 14, Sl, 36);
|
||||
ROUND3(A, B, C, D, 1, Si, 37); ROUND3(D, A, B, C, 4, Sj, 38);
|
||||
ROUND3(C, D, A, B, 7, Sk, 39); ROUND3(B, C, D, A, 10, Sl, 40);
|
||||
ROUND3(A, B, C, D, 13, Si, 41); ROUND3(D, A, B, C, 0, Sj, 42);
|
||||
ROUND3(C, D, A, B, 3, Sk, 43); ROUND3(B, C, D, A, 6, Sl, 44);
|
||||
ROUND3(A, B, C, D, 9, Si, 45); ROUND3(D, A, B, C, 12, Sj, 46);
|
||||
ROUND3(C, D, A, B, 15, Sk, 47); ROUND3(B, C, D, A, 2, Sl, 48);
|
||||
|
||||
ROUND4(A, B, C, D, 0, Sm, 49); ROUND4(D, A, B, C, 7, Sn, 50);
|
||||
ROUND4(C, D, A, B, 14, So, 51); ROUND4(B, C, D, A, 5, Sp, 52);
|
||||
ROUND4(A, B, C, D, 12, Sm, 53); ROUND4(D, A, B, C, 3, Sn, 54);
|
||||
ROUND4(C, D, A, B, 10, So, 55); ROUND4(B, C, D, A, 1, Sp, 56);
|
||||
ROUND4(A, B, C, D, 8, Sm, 57); ROUND4(D, A, B, C, 15, Sn, 58);
|
||||
ROUND4(C, D, A, B, 6, So, 59); ROUND4(B, C, D, A, 13, Sp, 60);
|
||||
ROUND4(A, B, C, D, 4, Sm, 61); ROUND4(D, A, B, C, 11, Sn, 62);
|
||||
ROUND4(C, D, A, B, 2, So, 63); ROUND4(B, C, D, A, 9, Sp, 64);
|
||||
ROUND2(A, B, C, D, 1, Se, 17);
|
||||
ROUND2(D, A, B, C, 6, Sf, 18);
|
||||
ROUND2(C, D, A, B, 11, Sg, 19);
|
||||
ROUND2(B, C, D, A, 0, Sh, 20);
|
||||
ROUND2(A, B, C, D, 5, Se, 21);
|
||||
ROUND2(D, A, B, C, 10, Sf, 22);
|
||||
ROUND2(C, D, A, B, 15, Sg, 23);
|
||||
ROUND2(B, C, D, A, 4, Sh, 24);
|
||||
ROUND2(A, B, C, D, 9, Se, 25);
|
||||
ROUND2(D, A, B, C, 14, Sf, 26);
|
||||
ROUND2(C, D, A, B, 3, Sg, 27);
|
||||
ROUND2(B, C, D, A, 8, Sh, 28);
|
||||
ROUND2(A, B, C, D, 13, Se, 29);
|
||||
ROUND2(D, A, B, C, 2, Sf, 30);
|
||||
ROUND2(C, D, A, B, 7, Sg, 31);
|
||||
ROUND2(B, C, D, A, 12, Sh, 32);
|
||||
|
||||
ROUND3(A, B, C, D, 5, Si, 33);
|
||||
ROUND3(D, A, B, C, 8, Sj, 34);
|
||||
ROUND3(C, D, A, B, 11, Sk, 35);
|
||||
ROUND3(B, C, D, A, 14, Sl, 36);
|
||||
ROUND3(A, B, C, D, 1, Si, 37);
|
||||
ROUND3(D, A, B, C, 4, Sj, 38);
|
||||
ROUND3(C, D, A, B, 7, Sk, 39);
|
||||
ROUND3(B, C, D, A, 10, Sl, 40);
|
||||
ROUND3(A, B, C, D, 13, Si, 41);
|
||||
ROUND3(D, A, B, C, 0, Sj, 42);
|
||||
ROUND3(C, D, A, B, 3, Sk, 43);
|
||||
ROUND3(B, C, D, A, 6, Sl, 44);
|
||||
ROUND3(A, B, C, D, 9, Si, 45);
|
||||
ROUND3(D, A, B, C, 12, Sj, 46);
|
||||
ROUND3(C, D, A, B, 15, Sk, 47);
|
||||
ROUND3(B, C, D, A, 2, Sl, 48);
|
||||
|
||||
ROUND4(A, B, C, D, 0, Sm, 49);
|
||||
ROUND4(D, A, B, C, 7, Sn, 50);
|
||||
ROUND4(C, D, A, B, 14, So, 51);
|
||||
ROUND4(B, C, D, A, 5, Sp, 52);
|
||||
ROUND4(A, B, C, D, 12, Sm, 53);
|
||||
ROUND4(D, A, B, C, 3, Sn, 54);
|
||||
ROUND4(C, D, A, B, 10, So, 55);
|
||||
ROUND4(B, C, D, A, 1, Sp, 56);
|
||||
ROUND4(A, B, C, D, 8, Sm, 57);
|
||||
ROUND4(D, A, B, C, 15, Sn, 58);
|
||||
ROUND4(C, D, A, B, 6, So, 59);
|
||||
ROUND4(B, C, D, A, 13, Sp, 60);
|
||||
ROUND4(A, B, C, D, 4, Sm, 61);
|
||||
ROUND4(D, A, B, C, 11, Sn, 62);
|
||||
ROUND4(C, D, A, B, 2, So, 63);
|
||||
ROUND4(B, C, D, A, 9, Sp, 64);
|
||||
|
||||
ctxt->md5_sta += A;
|
||||
ctxt->md5_stb += B;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* $Id: md5.h,v 1.3 2001/01/09 16:07:13 momjian Exp $ */
|
||||
/* $KAME: md5.h,v 1.3 2000/02/22 14:01:18 itojun Exp $ */
|
||||
/* $Id: md5.h,v 1.4 2001/03/22 03:59:10 momjian Exp $ */
|
||||
/* $KAME: md5.h,v 1.3 2000/02/22 14:01:18 itojun Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
|
||||
@ -9,18 +9,18 @@
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the project nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
@ -35,11 +35,13 @@
|
||||
|
||||
#define MD5_BUFLEN 64
|
||||
|
||||
typedef struct {
|
||||
union {
|
||||
typedef struct
|
||||
{
|
||||
union
|
||||
{
|
||||
uint32 md5_state32[4];
|
||||
uint8 md5_state8[16];
|
||||
} md5_st;
|
||||
} md5_st;
|
||||
|
||||
#define md5_sta md5_st.md5_state32[0]
|
||||
#define md5_stb md5_st.md5_state32[1]
|
||||
@ -47,21 +49,22 @@ typedef struct {
|
||||
#define md5_std md5_st.md5_state32[3]
|
||||
#define md5_st8 md5_st.md5_state8
|
||||
|
||||
union {
|
||||
union
|
||||
{
|
||||
uint64 md5_count64;
|
||||
uint8 md5_count8[8];
|
||||
} md5_count;
|
||||
} md5_count;
|
||||
#define md5_n md5_count.md5_count64
|
||||
#define md5_n8 md5_count.md5_count8
|
||||
|
||||
unsigned int md5_i;
|
||||
uint8 md5_buf[MD5_BUFLEN];
|
||||
} md5_ctxt;
|
||||
unsigned int md5_i;
|
||||
uint8 md5_buf[MD5_BUFLEN];
|
||||
} md5_ctxt;
|
||||
|
||||
extern void md5_init (md5_ctxt *);
|
||||
extern void md5_loop (md5_ctxt *, uint8 *, unsigned int);
|
||||
extern void md5_pad (md5_ctxt *);
|
||||
extern void md5_result (uint8 *, md5_ctxt *);
|
||||
extern void md5_init(md5_ctxt *);
|
||||
extern void md5_loop(md5_ctxt *, uint8 *, unsigned int);
|
||||
extern void md5_pad(md5_ctxt *);
|
||||
extern void md5_result(uint8 *, md5_ctxt *);
|
||||
|
||||
/* compatibility */
|
||||
#define MD5_CTX md5_ctxt
|
||||
@ -73,4 +76,4 @@ do { \
|
||||
md5_result((x), (y)); \
|
||||
} while (0)
|
||||
|
||||
#endif /* ! _NETINET6_MD5_H_*/
|
||||
#endif /* ! _NETINET6_MD5_H_ */
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* mhash.c
|
||||
* Wrapper for mhash library.
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2000 Marko Kreen
|
||||
* All rights reserved.
|
||||
*
|
||||
@ -9,15 +9,15 @@
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
@ -26,7 +26,7 @@
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: mhash.c,v 1.2 2001/02/10 02:31:26 tgl Exp $
|
||||
* $Id: mhash.c,v 1.3 2001/03/22 03:59:10 momjian Exp $
|
||||
*/
|
||||
|
||||
#include "postgres.h"
|
||||
@ -36,45 +36,50 @@
|
||||
#include <mhash.h>
|
||||
|
||||
static uint
|
||||
pg_mhash_len(pg_digest *hash);
|
||||
static uint8 *
|
||||
pg_mhash_digest(pg_digest *hash, uint8 *src,
|
||||
uint len, uint8 *buf);
|
||||
pg_mhash_len(pg_digest * hash);
|
||||
static uint8 *pg_mhash_digest(pg_digest * hash, uint8 *src,
|
||||
uint len, uint8 *buf);
|
||||
|
||||
static uint
|
||||
pg_mhash_len(pg_digest *h) {
|
||||
pg_mhash_len(pg_digest * h)
|
||||
{
|
||||
return mhash_get_block_size(h->misc.code);
|
||||
}
|
||||
|
||||
static uint8 *
|
||||
pg_mhash_digest(pg_digest *h, uint8 *src, uint len, uint8 *dst)
|
||||
pg_mhash_digest(pg_digest * h, uint8 *src, uint len, uint8 *dst)
|
||||
{
|
||||
uint8 *res;
|
||||
|
||||
MHASH mh = mhash_init(h->misc.code);
|
||||
uint8 *res;
|
||||
|
||||
MHASH mh = mhash_init(h->misc.code);
|
||||
|
||||
mhash(mh, src, len);
|
||||
res = mhash_end(mh);
|
||||
|
||||
|
||||
memcpy(dst, res, mhash_get_block_size(h->misc.code));
|
||||
mhash_free(res);
|
||||
|
||||
|
||||
return dst;
|
||||
}
|
||||
|
||||
pg_digest *
|
||||
pg_find_digest(pg_digest *h, char *name)
|
||||
pg_digest *
|
||||
pg_find_digest(pg_digest * h, char *name)
|
||||
{
|
||||
size_t hnum, i, b;
|
||||
char *mname;
|
||||
|
||||
size_t hnum,
|
||||
i,
|
||||
b;
|
||||
char *mname;
|
||||
|
||||
hnum = mhash_count();
|
||||
for (i = 0; i <= hnum; i++) {
|
||||
for (i = 0; i <= hnum; i++)
|
||||
{
|
||||
mname = mhash_get_hash_name(i);
|
||||
if (mname == NULL)
|
||||
continue;
|
||||
b = strcasecmp(name, mname);
|
||||
free(mname);
|
||||
if (!b) {
|
||||
if (!b)
|
||||
{
|
||||
h->name = mhash_get_hash_name(i);
|
||||
h->length = pg_mhash_len;
|
||||
h->digest = pg_mhash_digest;
|
||||
@ -84,4 +89,3 @@ pg_find_digest(pg_digest *h, char *name)
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* openssl.c
|
||||
* Wrapper for OpenSSL library.
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2000 Marko Kreen
|
||||
* All rights reserved.
|
||||
*
|
||||
@ -9,15 +9,15 @@
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
@ -26,7 +26,7 @@
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: openssl.c,v 1.2 2001/02/10 02:31:26 tgl Exp $
|
||||
* $Id: openssl.c,v 1.3 2001/03/22 03:59:10 momjian Exp $
|
||||
*/
|
||||
|
||||
#include "postgres.h"
|
||||
@ -36,50 +36,50 @@
|
||||
#include <evp.h>
|
||||
|
||||
static uint
|
||||
pg_ossl_len(pg_digest *h);
|
||||
pg_ossl_len(pg_digest * h);
|
||||
static uint8 *
|
||||
pg_ossl_digest(pg_digest *h, uint8 *src, uint len, uint8 *buf);
|
||||
pg_ossl_digest(pg_digest * h, uint8 *src, uint len, uint8 *buf);
|
||||
|
||||
static uint
|
||||
pg_ossl_len(pg_digest *h) {
|
||||
return EVP_MD_size((EVP_MD*)h->misc.ptr);
|
||||
pg_ossl_len(pg_digest * h)
|
||||
{
|
||||
return EVP_MD_size((EVP_MD *) h->misc.ptr);
|
||||
}
|
||||
|
||||
static uint8 *
|
||||
pg_ossl_digest(pg_digest *h, uint8 *src, uint len, uint8 *buf)
|
||||
pg_ossl_digest(pg_digest * h, uint8 *src, uint len, uint8 *buf)
|
||||
{
|
||||
EVP_MD *md = (EVP_MD*)h->misc.ptr;
|
||||
EVP_MD_CTX ctx;
|
||||
EVP_MD *md = (EVP_MD *) h->misc.ptr;
|
||||
EVP_MD_CTX ctx;
|
||||
|
||||
EVP_DigestInit(&ctx, md);
|
||||
EVP_DigestUpdate(&ctx, src, len);
|
||||
EVP_DigestFinal(&ctx, buf, NULL);
|
||||
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
static int pg_openssl_initialized = 0;
|
||||
static int pg_openssl_initialized = 0;
|
||||
|
||||
pg_digest *
|
||||
pg_find_digest(pg_digest *h, char *name)
|
||||
pg_digest *
|
||||
pg_find_digest(pg_digest * h, char *name)
|
||||
{
|
||||
const EVP_MD *md;
|
||||
|
||||
if (!pg_openssl_initialized) {
|
||||
if (!pg_openssl_initialized)
|
||||
{
|
||||
OpenSSL_add_all_digests();
|
||||
pg_openssl_initialized = 1;
|
||||
}
|
||||
|
||||
|
||||
md = EVP_get_digestbyname(name);
|
||||
if (md == NULL)
|
||||
return NULL;
|
||||
|
||||
|
||||
h->name = name;
|
||||
h->length = pg_ossl_len;
|
||||
h->digest = pg_ossl_digest;
|
||||
h->misc.ptr = (void*)md;
|
||||
|
||||
h->misc.ptr = (void *) md;
|
||||
|
||||
return h;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* pgcrypto.c
|
||||
* Cryptographic digests for PostgreSQL.
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2000 Marko Kreen
|
||||
* All rights reserved.
|
||||
*
|
||||
@ -9,15 +9,15 @@
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
@ -26,7 +26,7 @@
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: pgcrypto.c,v 1.6 2001/02/10 02:31:26 tgl Exp $
|
||||
* $Id: pgcrypto.c,v 1.7 2001/03/22 03:59:10 momjian Exp $
|
||||
*/
|
||||
|
||||
#include "postgres.h"
|
||||
@ -44,12 +44,12 @@
|
||||
|
||||
|
||||
/* exported functions */
|
||||
Datum digest(PG_FUNCTION_ARGS);
|
||||
Datum digest_exists(PG_FUNCTION_ARGS);
|
||||
Datum digest(PG_FUNCTION_ARGS);
|
||||
Datum digest_exists(PG_FUNCTION_ARGS);
|
||||
|
||||
/* private stuff */
|
||||
static pg_digest *
|
||||
find_digest(pg_digest *hbuf, text *name, int silent);
|
||||
find_digest(pg_digest * hbuf, text *name, int silent);
|
||||
|
||||
|
||||
/* SQL function: hash(text, text) returns text */
|
||||
@ -58,31 +58,33 @@ PG_FUNCTION_INFO_V1(digest);
|
||||
Datum
|
||||
digest(PG_FUNCTION_ARGS)
|
||||
{
|
||||
text *arg;
|
||||
text *name;
|
||||
uint len, hlen;
|
||||
pg_digest *h, _hbuf;
|
||||
text *res;
|
||||
|
||||
text *arg;
|
||||
text *name;
|
||||
uint len,
|
||||
hlen;
|
||||
pg_digest *h,
|
||||
_hbuf;
|
||||
text *res;
|
||||
|
||||
if (PG_ARGISNULL(0) || PG_ARGISNULL(1))
|
||||
PG_RETURN_NULL();
|
||||
|
||||
name = PG_GETARG_TEXT_P(1);
|
||||
h = find_digest(&_hbuf, name, 0); /* will give error if fails */
|
||||
|
||||
name = PG_GETARG_TEXT_P(1);
|
||||
h = find_digest(&_hbuf, name, 0); /* will give error if fails */
|
||||
|
||||
hlen = h->length(h);
|
||||
|
||||
res = (text *)palloc(hlen + VARHDRSZ);
|
||||
|
||||
res = (text *) palloc(hlen + VARHDRSZ);
|
||||
VARATT_SIZEP(res) = hlen + VARHDRSZ;
|
||||
|
||||
|
||||
arg = PG_GETARG_TEXT_P(0);
|
||||
len = VARSIZE(arg) - VARHDRSZ;
|
||||
|
||||
|
||||
h->digest(h, VARDATA(arg), len, VARDATA(res));
|
||||
|
||||
|
||||
PG_FREE_IF_COPY(arg, 0);
|
||||
PG_FREE_IF_COPY(name, 1);
|
||||
|
||||
|
||||
PG_RETURN_TEXT_P(res);
|
||||
}
|
||||
|
||||
@ -92,16 +94,17 @@ PG_FUNCTION_INFO_V1(digest_exists);
|
||||
Datum
|
||||
digest_exists(PG_FUNCTION_ARGS)
|
||||
{
|
||||
text *name;
|
||||
pg_digest _hbuf, *res;
|
||||
text *name;
|
||||
pg_digest _hbuf,
|
||||
*res;
|
||||
|
||||
if (PG_ARGISNULL(0))
|
||||
PG_RETURN_NULL();
|
||||
|
||||
|
||||
name = PG_GETARG_TEXT_P(0);
|
||||
|
||||
|
||||
res = find_digest(&_hbuf, name, 1);
|
||||
|
||||
|
||||
PG_FREE_IF_COPY(name, 0);
|
||||
|
||||
if (res != NULL)
|
||||
@ -110,26 +113,26 @@ digest_exists(PG_FUNCTION_ARGS)
|
||||
}
|
||||
|
||||
static pg_digest *
|
||||
find_digest(pg_digest *hbuf, text *name, int silent)
|
||||
find_digest(pg_digest * hbuf, text *name, int silent)
|
||||
{
|
||||
pg_digest *p;
|
||||
char buf[NAMEDATALEN];
|
||||
uint len;
|
||||
|
||||
pg_digest *p;
|
||||
char buf[NAMEDATALEN];
|
||||
uint len;
|
||||
|
||||
len = VARSIZE(name) - VARHDRSZ;
|
||||
if (len >= NAMEDATALEN) {
|
||||
if (len >= NAMEDATALEN)
|
||||
{
|
||||
if (silent)
|
||||
return NULL;
|
||||
elog(ERROR, "Hash type does not exist (name too long)");
|
||||
}
|
||||
|
||||
|
||||
memcpy(buf, VARDATA(name), len);
|
||||
buf[len] = 0;
|
||||
|
||||
|
||||
p = pg_find_digest(hbuf, buf);
|
||||
|
||||
if (p == NULL && !silent)
|
||||
elog(ERROR, "Hash type does not exist: '%s'", buf);
|
||||
return p;
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* pgcrypto.h
|
||||
* Header file for pgcrypto.
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2000 Marko Kreen
|
||||
* All rights reserved.
|
||||
*
|
||||
@ -9,15 +9,15 @@
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
@ -26,25 +26,27 @@
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: pgcrypto.h,v 1.2 2001/01/09 16:07:13 momjian Exp $
|
||||
* $Id: pgcrypto.h,v 1.3 2001/03/22 03:59:10 momjian Exp $
|
||||
*/
|
||||
|
||||
#ifndef _PG_CRYPTO_H
|
||||
#define _PG_CRYPTO_H
|
||||
|
||||
typedef struct _pg_digest pg_digest;
|
||||
struct _pg_digest {
|
||||
char *name;
|
||||
uint (*length)(pg_digest *h);
|
||||
uint8 *(*digest)(pg_digest *h, uint8 *data,
|
||||
uint dlen, uint8 *buf);
|
||||
struct _pg_digest
|
||||
{
|
||||
char *name;
|
||||
uint (*length) (pg_digest * h);
|
||||
uint8 *(*digest) (pg_digest * h, uint8 *data,
|
||||
uint dlen, uint8 *buf);
|
||||
/* private */
|
||||
union {
|
||||
uint code;
|
||||
union
|
||||
{
|
||||
uint code;
|
||||
const void *ptr;
|
||||
} misc;
|
||||
} misc;
|
||||
};
|
||||
|
||||
extern pg_digest *pg_find_digest(pg_digest *hbuf, char *name);
|
||||
extern pg_digest *pg_find_digest(pg_digest * hbuf, char *name);
|
||||
|
||||
#endif
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* $Id: sha1.c,v 1.4 2001/02/10 02:31:26 tgl Exp $ */
|
||||
/* $KAME: sha1.c,v 1.3 2000/02/22 14:01:18 itojun Exp $ */
|
||||
/* $Id: sha1.c,v 1.5 2001/03/22 03:59:10 momjian Exp $ */
|
||||
/* $KAME: sha1.c,v 1.3 2000/02/22 14:01:18 itojun Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
|
||||
@ -9,18 +9,18 @@
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the project nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
@ -41,120 +41,182 @@
|
||||
|
||||
/* sanity check */
|
||||
#if BYTE_ORDER != BIG_ENDIAN
|
||||
# if BYTE_ORDER != LITTLE_ENDIAN
|
||||
# define unsupported 1
|
||||
# endif
|
||||
#if BYTE_ORDER != LITTLE_ENDIAN
|
||||
#define unsupported 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef unsupported
|
||||
|
||||
/* constant table */
|
||||
static uint32 _K[] = { 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xca62c1d6 };
|
||||
#define K(t) _K[(t) / 20]
|
||||
static uint32 _K[] = {0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xca62c1d6};
|
||||
|
||||
#define F0(b, c, d) (((b) & (c)) | ((~(b)) & (d)))
|
||||
#define F1(b, c, d) (((b) ^ (c)) ^ (d))
|
||||
#define F2(b, c, d) (((b) & (c)) | ((b) & (d)) | ((c) & (d)))
|
||||
#define F3(b, c, d) (((b) ^ (c)) ^ (d))
|
||||
#define K(t) _K[(t) / 20]
|
||||
|
||||
#define S(n, x) (((x) << (n)) | ((x) >> (32 - n)))
|
||||
#define F0(b, c, d) (((b) & (c)) | ((~(b)) & (d)))
|
||||
#define F1(b, c, d) (((b) ^ (c)) ^ (d))
|
||||
#define F2(b, c, d) (((b) & (c)) | ((b) & (d)) | ((c) & (d)))
|
||||
#define F3(b, c, d) (((b) ^ (c)) ^ (d))
|
||||
|
||||
#define H(n) (ctxt->h.b32[(n)])
|
||||
#define COUNT (ctxt->count)
|
||||
#define BCOUNT (ctxt->c.b64[0] / 8)
|
||||
#define W(n) (ctxt->m.b32[(n)])
|
||||
#define S(n, x) (((x) << (n)) | ((x) >> (32 - n)))
|
||||
|
||||
#define PUTBYTE(x) { \
|
||||
#define H(n) (ctxt->h.b32[(n)])
|
||||
#define COUNT (ctxt->count)
|
||||
#define BCOUNT (ctxt->c.b64[0] / 8)
|
||||
#define W(n) (ctxt->m.b32[(n)])
|
||||
|
||||
#define PUTBYTE(x) { \
|
||||
ctxt->m.b8[(COUNT % 64)] = (x); \
|
||||
COUNT++; \
|
||||
COUNT %= 64; \
|
||||
ctxt->c.b64[0] += 8; \
|
||||
if (COUNT % 64 == 0) \
|
||||
sha1_step(ctxt); \
|
||||
}
|
||||
}
|
||||
|
||||
#define PUTPAD(x) { \
|
||||
#define PUTPAD(x) { \
|
||||
ctxt->m.b8[(COUNT % 64)] = (x); \
|
||||
COUNT++; \
|
||||
COUNT %= 64; \
|
||||
if (COUNT % 64 == 0) \
|
||||
sha1_step(ctxt); \
|
||||
}
|
||||
}
|
||||
|
||||
static void sha1_step (struct sha1_ctxt *);
|
||||
static void sha1_step(struct sha1_ctxt *);
|
||||
|
||||
static void
|
||||
sha1_step(ctxt)
|
||||
struct sha1_ctxt *ctxt;
|
||||
struct sha1_ctxt *ctxt;
|
||||
{
|
||||
uint32 a, b, c, d, e;
|
||||
size_t t, s;
|
||||
uint32 tmp;
|
||||
uint32 a,
|
||||
b,
|
||||
c,
|
||||
d,
|
||||
e;
|
||||
size_t t,
|
||||
s;
|
||||
uint32 tmp;
|
||||
|
||||
#if BYTE_ORDER == LITTLE_ENDIAN
|
||||
struct sha1_ctxt tctxt;
|
||||
|
||||
bcopy(&ctxt->m.b8[0], &tctxt.m.b8[0], 64);
|
||||
ctxt->m.b8[0] = tctxt.m.b8[3]; ctxt->m.b8[1] = tctxt.m.b8[2];
|
||||
ctxt->m.b8[2] = tctxt.m.b8[1]; ctxt->m.b8[3] = tctxt.m.b8[0];
|
||||
ctxt->m.b8[4] = tctxt.m.b8[7]; ctxt->m.b8[5] = tctxt.m.b8[6];
|
||||
ctxt->m.b8[6] = tctxt.m.b8[5]; ctxt->m.b8[7] = tctxt.m.b8[4];
|
||||
ctxt->m.b8[8] = tctxt.m.b8[11]; ctxt->m.b8[9] = tctxt.m.b8[10];
|
||||
ctxt->m.b8[10] = tctxt.m.b8[9]; ctxt->m.b8[11] = tctxt.m.b8[8];
|
||||
ctxt->m.b8[12] = tctxt.m.b8[15]; ctxt->m.b8[13] = tctxt.m.b8[14];
|
||||
ctxt->m.b8[14] = tctxt.m.b8[13]; ctxt->m.b8[15] = tctxt.m.b8[12];
|
||||
ctxt->m.b8[16] = tctxt.m.b8[19]; ctxt->m.b8[17] = tctxt.m.b8[18];
|
||||
ctxt->m.b8[18] = tctxt.m.b8[17]; ctxt->m.b8[19] = tctxt.m.b8[16];
|
||||
ctxt->m.b8[20] = tctxt.m.b8[23]; ctxt->m.b8[21] = tctxt.m.b8[22];
|
||||
ctxt->m.b8[22] = tctxt.m.b8[21]; ctxt->m.b8[23] = tctxt.m.b8[20];
|
||||
ctxt->m.b8[24] = tctxt.m.b8[27]; ctxt->m.b8[25] = tctxt.m.b8[26];
|
||||
ctxt->m.b8[26] = tctxt.m.b8[25]; ctxt->m.b8[27] = tctxt.m.b8[24];
|
||||
ctxt->m.b8[28] = tctxt.m.b8[31]; ctxt->m.b8[29] = tctxt.m.b8[30];
|
||||
ctxt->m.b8[30] = tctxt.m.b8[29]; ctxt->m.b8[31] = tctxt.m.b8[28];
|
||||
ctxt->m.b8[32] = tctxt.m.b8[35]; ctxt->m.b8[33] = tctxt.m.b8[34];
|
||||
ctxt->m.b8[34] = tctxt.m.b8[33]; ctxt->m.b8[35] = tctxt.m.b8[32];
|
||||
ctxt->m.b8[36] = tctxt.m.b8[39]; ctxt->m.b8[37] = tctxt.m.b8[38];
|
||||
ctxt->m.b8[38] = tctxt.m.b8[37]; ctxt->m.b8[39] = tctxt.m.b8[36];
|
||||
ctxt->m.b8[40] = tctxt.m.b8[43]; ctxt->m.b8[41] = tctxt.m.b8[42];
|
||||
ctxt->m.b8[42] = tctxt.m.b8[41]; ctxt->m.b8[43] = tctxt.m.b8[40];
|
||||
ctxt->m.b8[44] = tctxt.m.b8[47]; ctxt->m.b8[45] = tctxt.m.b8[46];
|
||||
ctxt->m.b8[46] = tctxt.m.b8[45]; ctxt->m.b8[47] = tctxt.m.b8[44];
|
||||
ctxt->m.b8[48] = tctxt.m.b8[51]; ctxt->m.b8[49] = tctxt.m.b8[50];
|
||||
ctxt->m.b8[50] = tctxt.m.b8[49]; ctxt->m.b8[51] = tctxt.m.b8[48];
|
||||
ctxt->m.b8[52] = tctxt.m.b8[55]; ctxt->m.b8[53] = tctxt.m.b8[54];
|
||||
ctxt->m.b8[54] = tctxt.m.b8[53]; ctxt->m.b8[55] = tctxt.m.b8[52];
|
||||
ctxt->m.b8[56] = tctxt.m.b8[59]; ctxt->m.b8[57] = tctxt.m.b8[58];
|
||||
ctxt->m.b8[58] = tctxt.m.b8[57]; ctxt->m.b8[59] = tctxt.m.b8[56];
|
||||
ctxt->m.b8[60] = tctxt.m.b8[63]; ctxt->m.b8[61] = tctxt.m.b8[62];
|
||||
ctxt->m.b8[62] = tctxt.m.b8[61]; ctxt->m.b8[63] = tctxt.m.b8[60];
|
||||
ctxt->m.b8[0] = tctxt.m.b8[3];
|
||||
ctxt->m.b8[1] = tctxt.m.b8[2];
|
||||
ctxt->m.b8[2] = tctxt.m.b8[1];
|
||||
ctxt->m.b8[3] = tctxt.m.b8[0];
|
||||
ctxt->m.b8[4] = tctxt.m.b8[7];
|
||||
ctxt->m.b8[5] = tctxt.m.b8[6];
|
||||
ctxt->m.b8[6] = tctxt.m.b8[5];
|
||||
ctxt->m.b8[7] = tctxt.m.b8[4];
|
||||
ctxt->m.b8[8] = tctxt.m.b8[11];
|
||||
ctxt->m.b8[9] = tctxt.m.b8[10];
|
||||
ctxt->m.b8[10] = tctxt.m.b8[9];
|
||||
ctxt->m.b8[11] = tctxt.m.b8[8];
|
||||
ctxt->m.b8[12] = tctxt.m.b8[15];
|
||||
ctxt->m.b8[13] = tctxt.m.b8[14];
|
||||
ctxt->m.b8[14] = tctxt.m.b8[13];
|
||||
ctxt->m.b8[15] = tctxt.m.b8[12];
|
||||
ctxt->m.b8[16] = tctxt.m.b8[19];
|
||||
ctxt->m.b8[17] = tctxt.m.b8[18];
|
||||
ctxt->m.b8[18] = tctxt.m.b8[17];
|
||||
ctxt->m.b8[19] = tctxt.m.b8[16];
|
||||
ctxt->m.b8[20] = tctxt.m.b8[23];
|
||||
ctxt->m.b8[21] = tctxt.m.b8[22];
|
||||
ctxt->m.b8[22] = tctxt.m.b8[21];
|
||||
ctxt->m.b8[23] = tctxt.m.b8[20];
|
||||
ctxt->m.b8[24] = tctxt.m.b8[27];
|
||||
ctxt->m.b8[25] = tctxt.m.b8[26];
|
||||
ctxt->m.b8[26] = tctxt.m.b8[25];
|
||||
ctxt->m.b8[27] = tctxt.m.b8[24];
|
||||
ctxt->m.b8[28] = tctxt.m.b8[31];
|
||||
ctxt->m.b8[29] = tctxt.m.b8[30];
|
||||
ctxt->m.b8[30] = tctxt.m.b8[29];
|
||||
ctxt->m.b8[31] = tctxt.m.b8[28];
|
||||
ctxt->m.b8[32] = tctxt.m.b8[35];
|
||||
ctxt->m.b8[33] = tctxt.m.b8[34];
|
||||
ctxt->m.b8[34] = tctxt.m.b8[33];
|
||||
ctxt->m.b8[35] = tctxt.m.b8[32];
|
||||
ctxt->m.b8[36] = tctxt.m.b8[39];
|
||||
ctxt->m.b8[37] = tctxt.m.b8[38];
|
||||
ctxt->m.b8[38] = tctxt.m.b8[37];
|
||||
ctxt->m.b8[39] = tctxt.m.b8[36];
|
||||
ctxt->m.b8[40] = tctxt.m.b8[43];
|
||||
ctxt->m.b8[41] = tctxt.m.b8[42];
|
||||
ctxt->m.b8[42] = tctxt.m.b8[41];
|
||||
ctxt->m.b8[43] = tctxt.m.b8[40];
|
||||
ctxt->m.b8[44] = tctxt.m.b8[47];
|
||||
ctxt->m.b8[45] = tctxt.m.b8[46];
|
||||
ctxt->m.b8[46] = tctxt.m.b8[45];
|
||||
ctxt->m.b8[47] = tctxt.m.b8[44];
|
||||
ctxt->m.b8[48] = tctxt.m.b8[51];
|
||||
ctxt->m.b8[49] = tctxt.m.b8[50];
|
||||
ctxt->m.b8[50] = tctxt.m.b8[49];
|
||||
ctxt->m.b8[51] = tctxt.m.b8[48];
|
||||
ctxt->m.b8[52] = tctxt.m.b8[55];
|
||||
ctxt->m.b8[53] = tctxt.m.b8[54];
|
||||
ctxt->m.b8[54] = tctxt.m.b8[53];
|
||||
ctxt->m.b8[55] = tctxt.m.b8[52];
|
||||
ctxt->m.b8[56] = tctxt.m.b8[59];
|
||||
ctxt->m.b8[57] = tctxt.m.b8[58];
|
||||
ctxt->m.b8[58] = tctxt.m.b8[57];
|
||||
ctxt->m.b8[59] = tctxt.m.b8[56];
|
||||
ctxt->m.b8[60] = tctxt.m.b8[63];
|
||||
ctxt->m.b8[61] = tctxt.m.b8[62];
|
||||
ctxt->m.b8[62] = tctxt.m.b8[61];
|
||||
ctxt->m.b8[63] = tctxt.m.b8[60];
|
||||
#endif
|
||||
|
||||
a = H(0); b = H(1); c = H(2); d = H(3); e = H(4);
|
||||
a = H(0);
|
||||
b = H(1);
|
||||
c = H(2);
|
||||
d = H(3);
|
||||
e = H(4);
|
||||
|
||||
for (t = 0; t < 20; t++) {
|
||||
for (t = 0; t < 20; t++)
|
||||
{
|
||||
s = t & 0x0f;
|
||||
if (t >= 16) {
|
||||
W(s) = S(1, W((s+13) & 0x0f) ^ W((s+8) & 0x0f) ^ W((s+2) & 0x0f) ^ W(s));
|
||||
}
|
||||
if (t >= 16)
|
||||
W(s) = S(1, W((s + 13) & 0x0f) ^ W((s + 8) & 0x0f) ^ W((s + 2) & 0x0f) ^ W(s));
|
||||
tmp = S(5, a) + F0(b, c, d) + e + W(s) + K(t);
|
||||
e = d; d = c; c = S(30, b); b = a; a = tmp;
|
||||
e = d;
|
||||
d = c;
|
||||
c = S(30, b);
|
||||
b = a;
|
||||
a = tmp;
|
||||
}
|
||||
for (t = 20; t < 40; t++) {
|
||||
for (t = 20; t < 40; t++)
|
||||
{
|
||||
s = t & 0x0f;
|
||||
W(s) = S(1, W((s+13) & 0x0f) ^ W((s+8) & 0x0f) ^ W((s+2) & 0x0f) ^ W(s));
|
||||
W(s) = S(1, W((s + 13) & 0x0f) ^ W((s + 8) & 0x0f) ^ W((s + 2) & 0x0f) ^ W(s));
|
||||
tmp = S(5, a) + F1(b, c, d) + e + W(s) + K(t);
|
||||
e = d; d = c; c = S(30, b); b = a; a = tmp;
|
||||
e = d;
|
||||
d = c;
|
||||
c = S(30, b);
|
||||
b = a;
|
||||
a = tmp;
|
||||
}
|
||||
for (t = 40; t < 60; t++) {
|
||||
for (t = 40; t < 60; t++)
|
||||
{
|
||||
s = t & 0x0f;
|
||||
W(s) = S(1, W((s+13) & 0x0f) ^ W((s+8) & 0x0f) ^ W((s+2) & 0x0f) ^ W(s));
|
||||
W(s) = S(1, W((s + 13) & 0x0f) ^ W((s + 8) & 0x0f) ^ W((s + 2) & 0x0f) ^ W(s));
|
||||
tmp = S(5, a) + F2(b, c, d) + e + W(s) + K(t);
|
||||
e = d; d = c; c = S(30, b); b = a; a = tmp;
|
||||
e = d;
|
||||
d = c;
|
||||
c = S(30, b);
|
||||
b = a;
|
||||
a = tmp;
|
||||
}
|
||||
for (t = 60; t < 80; t++) {
|
||||
for (t = 60; t < 80; t++)
|
||||
{
|
||||
s = t & 0x0f;
|
||||
W(s) = S(1, W((s+13) & 0x0f) ^ W((s+8) & 0x0f) ^ W((s+2) & 0x0f) ^ W(s));
|
||||
W(s) = S(1, W((s + 13) & 0x0f) ^ W((s + 8) & 0x0f) ^ W((s + 2) & 0x0f) ^ W(s));
|
||||
tmp = S(5, a) + F3(b, c, d) + e + W(s) + K(t);
|
||||
e = d; d = c; c = S(30, b); b = a; a = tmp;
|
||||
e = d;
|
||||
d = c;
|
||||
c = S(30, b);
|
||||
b = a;
|
||||
a = tmp;
|
||||
}
|
||||
|
||||
H(0) = H(0) + a;
|
||||
@ -170,7 +232,7 @@ sha1_step(ctxt)
|
||||
|
||||
void
|
||||
sha1_init(ctxt)
|
||||
struct sha1_ctxt *ctxt;
|
||||
struct sha1_ctxt *ctxt;
|
||||
{
|
||||
bzero(ctxt, sizeof(struct sha1_ctxt));
|
||||
H(0) = 0x67452301;
|
||||
@ -182,55 +244,65 @@ sha1_init(ctxt)
|
||||
|
||||
void
|
||||
sha1_pad(ctxt)
|
||||
struct sha1_ctxt *ctxt;
|
||||
struct sha1_ctxt *ctxt;
|
||||
{
|
||||
size_t padlen; /*pad length in bytes*/
|
||||
size_t padstart;
|
||||
size_t padlen; /* pad length in bytes */
|
||||
size_t padstart;
|
||||
|
||||
PUTPAD(0x80);
|
||||
|
||||
padstart = COUNT % 64;
|
||||
padlen = 64 - padstart;
|
||||
if (padlen < 8) {
|
||||
if (padlen < 8)
|
||||
{
|
||||
bzero(&ctxt->m.b8[padstart], padlen);
|
||||
COUNT += padlen;
|
||||
COUNT %= 64;
|
||||
sha1_step(ctxt);
|
||||
padstart = COUNT % 64; /* should be 0 */
|
||||
padlen = 64 - padstart; /* should be 64 */
|
||||
padlen = 64 - padstart; /* should be 64 */
|
||||
}
|
||||
bzero(&ctxt->m.b8[padstart], padlen - 8);
|
||||
COUNT += (padlen - 8);
|
||||
COUNT %= 64;
|
||||
#if BYTE_ORDER == BIG_ENDIAN
|
||||
PUTPAD(ctxt->c.b8[0]); PUTPAD(ctxt->c.b8[1]);
|
||||
PUTPAD(ctxt->c.b8[2]); PUTPAD(ctxt->c.b8[3]);
|
||||
PUTPAD(ctxt->c.b8[4]); PUTPAD(ctxt->c.b8[5]);
|
||||
PUTPAD(ctxt->c.b8[6]); PUTPAD(ctxt->c.b8[7]);
|
||||
PUTPAD(ctxt->c.b8[0]);
|
||||
PUTPAD(ctxt->c.b8[1]);
|
||||
PUTPAD(ctxt->c.b8[2]);
|
||||
PUTPAD(ctxt->c.b8[3]);
|
||||
PUTPAD(ctxt->c.b8[4]);
|
||||
PUTPAD(ctxt->c.b8[5]);
|
||||
PUTPAD(ctxt->c.b8[6]);
|
||||
PUTPAD(ctxt->c.b8[7]);
|
||||
#else
|
||||
PUTPAD(ctxt->c.b8[7]); PUTPAD(ctxt->c.b8[6]);
|
||||
PUTPAD(ctxt->c.b8[5]); PUTPAD(ctxt->c.b8[4]);
|
||||
PUTPAD(ctxt->c.b8[3]); PUTPAD(ctxt->c.b8[2]);
|
||||
PUTPAD(ctxt->c.b8[1]); PUTPAD(ctxt->c.b8[0]);
|
||||
PUTPAD(ctxt->c.b8[7]);
|
||||
PUTPAD(ctxt->c.b8[6]);
|
||||
PUTPAD(ctxt->c.b8[5]);
|
||||
PUTPAD(ctxt->c.b8[4]);
|
||||
PUTPAD(ctxt->c.b8[3]);
|
||||
PUTPAD(ctxt->c.b8[2]);
|
||||
PUTPAD(ctxt->c.b8[1]);
|
||||
PUTPAD(ctxt->c.b8[0]);
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
sha1_loop(ctxt, input0, len)
|
||||
struct sha1_ctxt *ctxt;
|
||||
const caddr_t input0;
|
||||
size_t len;
|
||||
struct sha1_ctxt *ctxt;
|
||||
const caddr_t input0;
|
||||
size_t len;
|
||||
{
|
||||
const uint8 *input;
|
||||
size_t gaplen;
|
||||
size_t gapstart;
|
||||
size_t off;
|
||||
size_t copysiz;
|
||||
size_t gaplen;
|
||||
size_t gapstart;
|
||||
size_t off;
|
||||
size_t copysiz;
|
||||
|
||||
input = (const uint8 *)input0;
|
||||
input = (const uint8 *) input0;
|
||||
off = 0;
|
||||
|
||||
while (off < len) {
|
||||
while (off < len)
|
||||
{
|
||||
gapstart = COUNT % 64;
|
||||
gaplen = 64 - gapstart;
|
||||
|
||||
@ -247,27 +319,37 @@ sha1_loop(ctxt, input0, len)
|
||||
|
||||
void
|
||||
sha1_result(ctxt, digest0)
|
||||
struct sha1_ctxt *ctxt;
|
||||
caddr_t digest0;
|
||||
struct sha1_ctxt *ctxt;
|
||||
caddr_t digest0;
|
||||
{
|
||||
uint8 *digest;
|
||||
uint8 *digest;
|
||||
|
||||
digest = (uint8 *)digest0;
|
||||
digest = (uint8 *) digest0;
|
||||
sha1_pad(ctxt);
|
||||
#if BYTE_ORDER == BIG_ENDIAN
|
||||
bcopy(&ctxt->h.b8[0], digest, 20);
|
||||
#else
|
||||
digest[0] = ctxt->h.b8[3]; digest[1] = ctxt->h.b8[2];
|
||||
digest[2] = ctxt->h.b8[1]; digest[3] = ctxt->h.b8[0];
|
||||
digest[4] = ctxt->h.b8[7]; digest[5] = ctxt->h.b8[6];
|
||||
digest[6] = ctxt->h.b8[5]; digest[7] = ctxt->h.b8[4];
|
||||
digest[8] = ctxt->h.b8[11]; digest[9] = ctxt->h.b8[10];
|
||||
digest[10] = ctxt->h.b8[9]; digest[11] = ctxt->h.b8[8];
|
||||
digest[12] = ctxt->h.b8[15]; digest[13] = ctxt->h.b8[14];
|
||||
digest[14] = ctxt->h.b8[13]; digest[15] = ctxt->h.b8[12];
|
||||
digest[16] = ctxt->h.b8[19]; digest[17] = ctxt->h.b8[18];
|
||||
digest[18] = ctxt->h.b8[17]; digest[19] = ctxt->h.b8[16];
|
||||
digest[0] = ctxt->h.b8[3];
|
||||
digest[1] = ctxt->h.b8[2];
|
||||
digest[2] = ctxt->h.b8[1];
|
||||
digest[3] = ctxt->h.b8[0];
|
||||
digest[4] = ctxt->h.b8[7];
|
||||
digest[5] = ctxt->h.b8[6];
|
||||
digest[6] = ctxt->h.b8[5];
|
||||
digest[7] = ctxt->h.b8[4];
|
||||
digest[8] = ctxt->h.b8[11];
|
||||
digest[9] = ctxt->h.b8[10];
|
||||
digest[10] = ctxt->h.b8[9];
|
||||
digest[11] = ctxt->h.b8[8];
|
||||
digest[12] = ctxt->h.b8[15];
|
||||
digest[13] = ctxt->h.b8[14];
|
||||
digest[14] = ctxt->h.b8[13];
|
||||
digest[15] = ctxt->h.b8[12];
|
||||
digest[16] = ctxt->h.b8[19];
|
||||
digest[17] = ctxt->h.b8[18];
|
||||
digest[18] = ctxt->h.b8[17];
|
||||
digest[19] = ctxt->h.b8[16];
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif /*unsupported*/
|
||||
#endif /* unsupported */
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* $Id: sha1.h,v 1.3 2001/01/09 16:07:13 momjian Exp $ */
|
||||
/* $KAME: sha1.h,v 1.4 2000/02/22 14:01:18 itojun Exp $ */
|
||||
/* $Id: sha1.h,v 1.4 2001/03/22 03:59:10 momjian Exp $ */
|
||||
/* $KAME: sha1.h,v 1.4 2000/02/22 14:01:18 itojun Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
|
||||
@ -9,18 +9,18 @@
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the project nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
@ -38,33 +38,38 @@
|
||||
#ifndef _NETINET6_SHA1_H_
|
||||
#define _NETINET6_SHA1_H_
|
||||
|
||||
struct sha1_ctxt {
|
||||
union {
|
||||
struct sha1_ctxt
|
||||
{
|
||||
union
|
||||
{
|
||||
uint8 b8[20];
|
||||
uint32 b32[5];
|
||||
} h;
|
||||
union {
|
||||
} h;
|
||||
union
|
||||
{
|
||||
uint8 b8[8];
|
||||
uint64 b64[1];
|
||||
} c;
|
||||
union {
|
||||
} c;
|
||||
union
|
||||
{
|
||||
uint8 b8[64];
|
||||
uint32 b32[16];
|
||||
} m;
|
||||
uint8 count;
|
||||
} m;
|
||||
uint8 count;
|
||||
};
|
||||
|
||||
extern void sha1_init (struct sha1_ctxt *);
|
||||
extern void sha1_pad (struct sha1_ctxt *);
|
||||
extern void sha1_loop (struct sha1_ctxt *, const caddr_t, size_t);
|
||||
extern void sha1_result (struct sha1_ctxt *, caddr_t);
|
||||
extern void sha1_init(struct sha1_ctxt *);
|
||||
extern void sha1_pad(struct sha1_ctxt *);
|
||||
extern void sha1_loop(struct sha1_ctxt *, const caddr_t, size_t);
|
||||
extern void sha1_result(struct sha1_ctxt *, caddr_t);
|
||||
|
||||
/* compatibilty with other SHA1 source codes */
|
||||
typedef struct sha1_ctxt SHA1_CTX;
|
||||
|
||||
#define SHA1Init(x) sha1_init((x))
|
||||
#define SHA1Update(x, y, z) sha1_loop((x), (y), (z))
|
||||
#define SHA1Update(x, y, z) sha1_loop((x), (y), (z))
|
||||
#define SHA1Final(x, y) sha1_result((y), (x))
|
||||
|
||||
#define SHA1_RESULTLEN (160/8)
|
||||
#define SHA1_RESULTLEN (160/8)
|
||||
|
||||
#endif /*_NETINET6_SHA1_H_*/
|
||||
#endif /* _NETINET6_SHA1_H_ */
|
||||
|
@ -16,18 +16,20 @@
|
||||
PG_FUNCTION_INFO_V1(_rserv_log_);
|
||||
PG_FUNCTION_INFO_V1(_rserv_sync_);
|
||||
PG_FUNCTION_INFO_V1(_rserv_debug_);
|
||||
Datum _rserv_log_(PG_FUNCTION_ARGS);
|
||||
Datum _rserv_sync_(PG_FUNCTION_ARGS);
|
||||
Datum _rserv_debug_(PG_FUNCTION_ARGS);
|
||||
Datum _rserv_log_(PG_FUNCTION_ARGS);
|
||||
Datum _rserv_sync_(PG_FUNCTION_ARGS);
|
||||
Datum _rserv_debug_(PG_FUNCTION_ARGS);
|
||||
|
||||
#else
|
||||
HeapTuple _rserv_log_(void);
|
||||
int32 _rserv_sync_(int32);
|
||||
int32 _rserv_debug_(int32);
|
||||
|
||||
#endif
|
||||
|
||||
static int debug = 0;
|
||||
|
||||
static char* OutputValue(char *key, char *buf, int size);
|
||||
static char *OutputValue(char *key, char *buf, int size);
|
||||
|
||||
#ifdef PG_FUNCTION_INFO_V1
|
||||
Datum
|
||||
@ -68,7 +70,7 @@ _rserv_log_()
|
||||
nargs = trigger->tgnargs;
|
||||
args = trigger->tgargs;
|
||||
|
||||
if (nargs != 1) /* odd number of arguments! */
|
||||
if (nargs != 1) /* odd number of arguments! */
|
||||
elog(ERROR, "_rserv_log_: need in *one* argument");
|
||||
|
||||
keynum = atoi(args[0]);
|
||||
@ -79,7 +81,7 @@ _rserv_log_()
|
||||
rel = CurrentTriggerData->tg_relation;
|
||||
tupdesc = rel->rd_att;
|
||||
|
||||
deleted = (TRIGGER_FIRED_BY_DELETE(CurrentTriggerData->tg_event)) ?
|
||||
deleted = (TRIGGER_FIRED_BY_DELETE(CurrentTriggerData->tg_event)) ?
|
||||
1 : 0;
|
||||
|
||||
if (TRIGGER_FIRED_BY_UPDATE(CurrentTriggerData->tg_event))
|
||||
@ -115,7 +117,7 @@ _rserv_log_()
|
||||
if (strcmp(newkey, key) == 0)
|
||||
newkey = NULL;
|
||||
else
|
||||
deleted = 1; /* old key was deleted */
|
||||
deleted = 1; /* old key was deleted */
|
||||
}
|
||||
|
||||
if (strpbrk(key, "\\ \n'"))
|
||||
@ -124,7 +126,7 @@ _rserv_log_()
|
||||
okey = key;
|
||||
|
||||
sprintf(sql, "update _RSERV_LOG_ set logid = %d, logtime = now(), "
|
||||
"deleted = %d where reloid = %u and key = '%s'",
|
||||
"deleted = %d where reloid = %u and key = '%s'",
|
||||
GetCurrentTransactionId(), deleted, rel->rd_id, okey);
|
||||
|
||||
if (debug)
|
||||
@ -145,7 +147,7 @@ _rserv_log_()
|
||||
sprintf(sql, "insert into _RSERV_LOG_ "
|
||||
"(reloid, logid, logtime, deleted, key) "
|
||||
"values (%u, %d, now(), %d, '%s')",
|
||||
rel->rd_id, GetCurrentTransactionId(),
|
||||
rel->rd_id, GetCurrentTransactionId(),
|
||||
deleted, okey);
|
||||
|
||||
if (debug)
|
||||
@ -169,7 +171,7 @@ _rserv_log_()
|
||||
|
||||
sprintf(sql, "insert into _RSERV_LOG_ "
|
||||
"(reloid, logid, logtime, deleted, key) "
|
||||
"values (%u, %d, now(), 0, '%s')",
|
||||
"values (%u, %d, now(), 0, '%s')",
|
||||
rel->rd_id, GetCurrentTransactionId(), okey);
|
||||
|
||||
if (debug)
|
||||
@ -202,13 +204,14 @@ _rserv_sync_(int32 server)
|
||||
#endif
|
||||
{
|
||||
#ifdef PG_FUNCTION_INFO_V1
|
||||
int32 server = PG_GETARG_INT32(0);
|
||||
int32 server = PG_GETARG_INT32(0);
|
||||
|
||||
#endif
|
||||
char sql[8192];
|
||||
char buf[8192];
|
||||
char *active = buf;
|
||||
uint32 xcnt;
|
||||
int ret;
|
||||
char sql[8192];
|
||||
char buf[8192];
|
||||
char *active = buf;
|
||||
uint32 xcnt;
|
||||
int ret;
|
||||
|
||||
if (SerializableSnapshot == NULL)
|
||||
elog(ERROR, "_rserv_sync_: SerializableSnapshot is NULL");
|
||||
@ -217,7 +220,7 @@ _rserv_sync_(int32 server)
|
||||
for (xcnt = 0; xcnt < SerializableSnapshot->xcnt; xcnt++)
|
||||
{
|
||||
sprintf(buf + strlen(buf), "%s%u", (xcnt) ? ", " : "",
|
||||
SerializableSnapshot->xip[xcnt]);
|
||||
SerializableSnapshot->xip[xcnt]);
|
||||
}
|
||||
|
||||
if ((ret = SPI_connect()) < 0)
|
||||
@ -225,7 +228,7 @@ _rserv_sync_(int32 server)
|
||||
|
||||
sprintf(sql, "insert into _RSERV_SYNC_ "
|
||||
"(server, syncid, synctime, status, minid, maxid, active) "
|
||||
"values (%u, currval('_rserv_sync_seq_'), now(), 0, %d, %d, '%s')",
|
||||
"values (%u, currval('_rserv_sync_seq_'), now(), 0, %d, %d, '%s')",
|
||||
server, SerializableSnapshot->xmin, SerializableSnapshot->xmax, active);
|
||||
|
||||
ret = SPI_exec(sql, 0);
|
||||
@ -247,18 +250,19 @@ _rserv_debug_(int32 newval)
|
||||
#endif
|
||||
{
|
||||
#ifdef PG_FUNCTION_INFO_V1
|
||||
int32 newval = PG_GETARG_INT32(0);
|
||||
int32 newval = PG_GETARG_INT32(0);
|
||||
|
||||
#endif
|
||||
int32 oldval = debug;
|
||||
int32 oldval = debug;
|
||||
|
||||
debug = newval;
|
||||
|
||||
return (oldval);
|
||||
}
|
||||
|
||||
#define ExtendBy 1024
|
||||
#define ExtendBy 1024
|
||||
|
||||
static char*
|
||||
static char *
|
||||
OutputValue(char *key, char *buf, int size)
|
||||
{
|
||||
int i = 0;
|
||||
@ -267,39 +271,45 @@ OutputValue(char *key, char *buf, int size)
|
||||
int slen = 0;
|
||||
|
||||
size--;
|
||||
for ( ; ; )
|
||||
for (;;)
|
||||
{
|
||||
switch (*key)
|
||||
{
|
||||
case '\\': subst ="\\\\";
|
||||
slen = 2;
|
||||
break;
|
||||
case ' ': subst = "\\011";
|
||||
slen = 4;
|
||||
break;
|
||||
case '\n': subst = "\\012";
|
||||
slen = 4;
|
||||
break;
|
||||
case '\'': subst = "\\047";
|
||||
slen = 4;
|
||||
break;
|
||||
case '\0': out[i] = 0;
|
||||
return(out);
|
||||
default: slen = 1;
|
||||
break;
|
||||
case '\\':
|
||||
subst = "\\\\";
|
||||
slen = 2;
|
||||
break;
|
||||
case ' ':
|
||||
subst = "\\011";
|
||||
slen = 4;
|
||||
break;
|
||||
case '\n':
|
||||
subst = "\\012";
|
||||
slen = 4;
|
||||
break;
|
||||
case '\'':
|
||||
subst = "\\047";
|
||||
slen = 4;
|
||||
break;
|
||||
case '\0':
|
||||
out[i] = 0;
|
||||
return (out);
|
||||
default:
|
||||
slen = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
if (i + slen >= size)
|
||||
{
|
||||
if (out == buf)
|
||||
{
|
||||
out = (char*) palloc(size + ExtendBy);
|
||||
out = (char *) palloc(size + ExtendBy);
|
||||
strncpy(out, buf, i);
|
||||
size += ExtendBy;
|
||||
}
|
||||
else
|
||||
{
|
||||
out = (char*) repalloc(out, size + ExtendBy);
|
||||
out = (char *) repalloc(out, size + ExtendBy);
|
||||
size += ExtendBy;
|
||||
}
|
||||
}
|
||||
@ -314,6 +324,6 @@ OutputValue(char *key, char *buf, int size)
|
||||
key++;
|
||||
}
|
||||
|
||||
return(out);
|
||||
return (out);
|
||||
|
||||
}
|
||||
|
@ -4,76 +4,81 @@
|
||||
|
||||
#include "utils/elog.h"
|
||||
|
||||
static char * PARSE_BUFFER;
|
||||
static char * PARSE_BUFFER_PTR;
|
||||
static unsigned int PARSE_BUFFER_SIZE;
|
||||
static char *PARSE_BUFFER;
|
||||
static char *PARSE_BUFFER_PTR;
|
||||
static unsigned int PARSE_BUFFER_SIZE;
|
||||
static unsigned int SCANNER_POS;
|
||||
|
||||
void set_parse_buffer( char* s );
|
||||
void reset_parse_buffer( void );
|
||||
int read_parse_buffer( void );
|
||||
char * parse_buffer( void );
|
||||
char * parse_buffer_ptr( void );
|
||||
unsigned int parse_buffer_curr_char( void );
|
||||
unsigned int parse_buffer_size( void );
|
||||
unsigned int parse_buffer_pos( void );
|
||||
void set_parse_buffer(char *s);
|
||||
void reset_parse_buffer(void);
|
||||
int read_parse_buffer(void);
|
||||
char *parse_buffer(void);
|
||||
char *parse_buffer_ptr(void);
|
||||
unsigned int parse_buffer_curr_char(void);
|
||||
unsigned int parse_buffer_size(void);
|
||||
unsigned int parse_buffer_pos(void);
|
||||
|
||||
extern void seg_flush_scanner_buffer(void); /* defined in segscan.l */
|
||||
extern void seg_flush_scanner_buffer(void); /* defined in segscan.l */
|
||||
|
||||
void set_parse_buffer( char* s )
|
||||
void
|
||||
set_parse_buffer(char *s)
|
||||
{
|
||||
PARSE_BUFFER = s;
|
||||
PARSE_BUFFER_SIZE = strlen(s);
|
||||
if ( PARSE_BUFFER_SIZE == 0 ) {
|
||||
elog(ERROR, "seg_in: can't parse an empty string");
|
||||
}
|
||||
PARSE_BUFFER_PTR = PARSE_BUFFER;
|
||||
SCANNER_POS = 0;
|
||||
PARSE_BUFFER = s;
|
||||
PARSE_BUFFER_SIZE = strlen(s);
|
||||
if (PARSE_BUFFER_SIZE == 0)
|
||||
elog(ERROR, "seg_in: can't parse an empty string");
|
||||
PARSE_BUFFER_PTR = PARSE_BUFFER;
|
||||
SCANNER_POS = 0;
|
||||
}
|
||||
|
||||
void reset_parse_buffer( void )
|
||||
void
|
||||
reset_parse_buffer(void)
|
||||
{
|
||||
PARSE_BUFFER_PTR = PARSE_BUFFER;
|
||||
SCANNER_POS = 0;
|
||||
seg_flush_scanner_buffer();
|
||||
PARSE_BUFFER_PTR = PARSE_BUFFER;
|
||||
SCANNER_POS = 0;
|
||||
seg_flush_scanner_buffer();
|
||||
}
|
||||
|
||||
int read_parse_buffer( void )
|
||||
int
|
||||
read_parse_buffer(void)
|
||||
{
|
||||
int c;
|
||||
/*
|
||||
c = *PARSE_BUFFER_PTR++;
|
||||
SCANNER_POS++;
|
||||
*/
|
||||
c = PARSE_BUFFER[SCANNER_POS];
|
||||
if(SCANNER_POS < PARSE_BUFFER_SIZE)
|
||||
SCANNER_POS++;
|
||||
return c;
|
||||
int c;
|
||||
|
||||
/*
|
||||
* c = *PARSE_BUFFER_PTR++; SCANNER_POS++;
|
||||
*/
|
||||
c = PARSE_BUFFER[SCANNER_POS];
|
||||
if (SCANNER_POS < PARSE_BUFFER_SIZE)
|
||||
SCANNER_POS++;
|
||||
return c;
|
||||
}
|
||||
|
||||
char * parse_buffer( void )
|
||||
char *
|
||||
parse_buffer(void)
|
||||
{
|
||||
return PARSE_BUFFER;
|
||||
return PARSE_BUFFER;
|
||||
}
|
||||
|
||||
unsigned int parse_buffer_curr_char( void )
|
||||
unsigned int
|
||||
parse_buffer_curr_char(void)
|
||||
{
|
||||
return PARSE_BUFFER[SCANNER_POS];
|
||||
return PARSE_BUFFER[SCANNER_POS];
|
||||
}
|
||||
|
||||
char * parse_buffer_ptr( void )
|
||||
char *
|
||||
parse_buffer_ptr(void)
|
||||
{
|
||||
return PARSE_BUFFER_PTR;
|
||||
return PARSE_BUFFER_PTR;
|
||||
}
|
||||
|
||||
unsigned int parse_buffer_pos( void )
|
||||
unsigned int
|
||||
parse_buffer_pos(void)
|
||||
{
|
||||
return SCANNER_POS;
|
||||
return SCANNER_POS;
|
||||
}
|
||||
|
||||
unsigned int parse_buffer_size( void )
|
||||
unsigned int
|
||||
parse_buffer_size(void)
|
||||
{
|
||||
return PARSE_BUFFER_SIZE;
|
||||
return PARSE_BUFFER_SIZE;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
extern void set_parse_buffer( char* s );
|
||||
extern void reset_parse_buffer( void );
|
||||
extern int read_parse_buffer( void );
|
||||
extern char * parse_buffer( void );
|
||||
extern char * parse_buffer_ptr( void );
|
||||
extern unsigned int parse_buffer_curr_char( void );
|
||||
extern unsigned int parse_buffer_pos( void );
|
||||
extern unsigned int parse_buffer_size( void );
|
||||
extern void set_parse_buffer(char *s);
|
||||
extern void reset_parse_buffer(void);
|
||||
extern int read_parse_buffer(void);
|
||||
extern char *parse_buffer(void);
|
||||
extern char *parse_buffer_ptr(void);
|
||||
extern unsigned int parse_buffer_curr_char(void);
|
||||
extern unsigned int parse_buffer_pos(void);
|
||||
extern unsigned int parse_buffer_size(void);
|
||||
|
1367
contrib/seg/seg.c
1367
contrib/seg/seg.c
File diff suppressed because it is too large
Load Diff
@ -1,8 +1,9 @@
|
||||
typedef struct SEG {
|
||||
float lower;
|
||||
float upper;
|
||||
char l_sigd;
|
||||
char u_sigd;
|
||||
char l_ext;
|
||||
char u_ext;
|
||||
} SEG;
|
||||
typedef struct SEG
|
||||
{
|
||||
float lower;
|
||||
float upper;
|
||||
char l_sigd;
|
||||
char u_sigd;
|
||||
char l_ext;
|
||||
char u_ext;
|
||||
} SEG;
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $Header: /cvsroot/pgsql/contrib/soundex/Attic/soundex.c,v 1.10 2001/02/10 02:31:26 tgl Exp $ */
|
||||
/* $Header: /cvsroot/pgsql/contrib/soundex/Attic/soundex.c,v 1.11 2001/03/22 03:59:10 momjian Exp $ */
|
||||
#include "postgres.h"
|
||||
|
||||
#include <ctype.h>
|
||||
@ -7,7 +7,7 @@
|
||||
#include "utils/builtins.h"
|
||||
|
||||
|
||||
Datum text_soundex(PG_FUNCTION_ARGS);
|
||||
Datum text_soundex(PG_FUNCTION_ARGS);
|
||||
|
||||
static void soundex(const char *instr, char *outstr);
|
||||
|
||||
@ -37,11 +37,12 @@ text_soundex(PG_FUNCTION_ARGS)
|
||||
PG_RETURN_TEXT_P(_textin(outstr));
|
||||
}
|
||||
|
||||
#endif /* not SOUNDEX_TEST */
|
||||
#endif /* not SOUNDEX_TEST */
|
||||
|
||||
|
||||
/* ABCDEFGHIJKLMNOPQRSTUVWXYZ */
|
||||
/* ABCDEFGHIJKLMNOPQRSTUVWXYZ */
|
||||
static const char *soundex_table = "01230120022455012623010202";
|
||||
|
||||
#define soundex_code(letter) soundex_table[toupper((unsigned char) (letter)) - 'A']
|
||||
|
||||
|
||||
@ -98,7 +99,7 @@ soundex(const char *instr, char *outstr)
|
||||
|
||||
#ifdef SOUNDEX_TEST
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
if (argc < 2)
|
||||
{
|
||||
@ -107,11 +108,12 @@ main (int argc, char *argv[])
|
||||
}
|
||||
else
|
||||
{
|
||||
char output[SOUNDEX_LEN + 1];
|
||||
char output[SOUNDEX_LEN + 1];
|
||||
|
||||
soundex(argv[1], output);
|
||||
printf("soundex(%s) = %s\n", argv[1], output);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
#endif /* SOUNDEX_TEST */
|
||||
|
||||
#endif /* SOUNDEX_TEST */
|
||||
|
@ -10,7 +10,7 @@
|
||||
#include "commands/trigger.h" /* -"- and triggers */
|
||||
#include "miscadmin.h" /* for GetUserName() */
|
||||
|
||||
extern Datum insert_username(PG_FUNCTION_ARGS);
|
||||
extern Datum insert_username(PG_FUNCTION_ARGS);
|
||||
|
||||
PG_FUNCTION_INFO_V1(insert_username);
|
||||
|
||||
@ -65,7 +65,7 @@ insert_username(PG_FUNCTION_ARGS)
|
||||
|
||||
/* create fields containing name */
|
||||
newval = DirectFunctionCall1(textin,
|
||||
CStringGetDatum(GetUserName(GetUserId())));
|
||||
CStringGetDatum(GetUserName(GetUserId())));
|
||||
|
||||
/* construct new tuple */
|
||||
rettuple = SPI_modifytuple(rel, rettuple, 1, &attnum, &newval, NULL);
|
||||
|
@ -15,7 +15,7 @@ OH, me, I'm Terry Mackintosh <terry@terrym.com>
|
||||
#include "executor/spi.h" /* this is what you need to work with SPI */
|
||||
#include "commands/trigger.h" /* -"- and triggers */
|
||||
|
||||
extern Datum moddatetime(PG_FUNCTION_ARGS);
|
||||
extern Datum moddatetime(PG_FUNCTION_ARGS);
|
||||
|
||||
PG_FUNCTION_INFO_V1(moddatetime);
|
||||
|
||||
|
@ -373,7 +373,7 @@ set_timetravel(PG_FUNCTION_ARGS)
|
||||
else
|
||||
TTOff = realloc(TTOff, (nTTOff + 1) * sizeof(char *));
|
||||
s = rname = DatumGetCString(DirectFunctionCall1(nameout,
|
||||
NameGetDatum(relname)));
|
||||
NameGetDatum(relname)));
|
||||
d = TTOff[nTTOff] = malloc(strlen(rname) + 1);
|
||||
while (*s)
|
||||
*d++ = tolower((unsigned char) *s++);
|
||||
|
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/contrib/vacuumlo/vacuumlo.c,v 1.8 2001/01/24 19:42:45 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/contrib/vacuumlo/vacuumlo.c,v 1.9 2001/03/22 03:59:11 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -76,6 +76,7 @@ vacuumlo(char *database, int verbose)
|
||||
return -1;
|
||||
}
|
||||
PQclear(res);
|
||||
|
||||
/*
|
||||
* Vacuum the temp table so that planner will generate decent plans
|
||||
* for the DELETEs below.
|
||||
@ -96,13 +97,13 @@ vacuumlo(char *database, int verbose)
|
||||
/*
|
||||
* Now find any candidate tables who have columns of type oid.
|
||||
*
|
||||
* NOTE: the temp table formed above is ignored, because its real
|
||||
* table name will be pg_something. Also, pg_largeobject will be
|
||||
* ignored. If either of these were scanned, obviously we'd end up
|
||||
* with nothing to delete...
|
||||
* NOTE: the temp table formed above is ignored, because its real table
|
||||
* name will be pg_something. Also, pg_largeobject will be ignored.
|
||||
* If either of these were scanned, obviously we'd end up with nothing
|
||||
* to delete...
|
||||
*
|
||||
* NOTE: the system oid column is ignored, as it has attnum < 1.
|
||||
* This shouldn't matter for correctness, but it saves time.
|
||||
* NOTE: the system oid column is ignored, as it has attnum < 1. This
|
||||
* shouldn't matter for correctness, but it saves time.
|
||||
*/
|
||||
buf[0] = '\0';
|
||||
strcat(buf, "SELECT c.relname, a.attname ");
|
||||
@ -135,9 +136,9 @@ vacuumlo(char *database, int verbose)
|
||||
fprintf(stdout, "Checking %s in %s\n", field, table);
|
||||
|
||||
/*
|
||||
* We use a DELETE with implicit join for efficiency. This
|
||||
* is a Postgres-ism and not portable to other DBMSs, but
|
||||
* then this whole program is a Postgres-ism.
|
||||
* We use a DELETE with implicit join for efficiency. This is a
|
||||
* Postgres-ism and not portable to other DBMSs, but then this
|
||||
* whole program is a Postgres-ism.
|
||||
*/
|
||||
sprintf(buf, "DELETE FROM vacuum_l WHERE lo = \"%s\".\"%s\" ",
|
||||
table, field);
|
||||
@ -157,10 +158,10 @@ vacuumlo(char *database, int verbose)
|
||||
PQclear(res);
|
||||
|
||||
/*
|
||||
* Run the actual deletes in a single transaction. Note that this
|
||||
* Run the actual deletes in a single transaction. Note that this
|
||||
* would be a bad idea in pre-7.1 Postgres releases (since rolling
|
||||
* back a table delete used to cause problems), but it should
|
||||
* be safe now.
|
||||
* back a table delete used to cause problems), but it should be safe
|
||||
* now.
|
||||
*/
|
||||
res = PQexec(conn, "begin");
|
||||
PQclear(res);
|
||||
|
Reference in New Issue
Block a user