diff options
| author | Bruce Momjian <bruce@momjian.us> | 2007-11-15 21:14:46 +0000 |
|---|---|---|
| committer | Bruce Momjian <bruce@momjian.us> | 2007-11-15 21:14:46 +0000 |
| commit | fdf5a5efb7b28c13085fe7313658de8d7b9914f6 (patch) | |
| tree | a75cf1422fa1eef4e801cf502b148d8ce1b5dfe7 /src/interfaces | |
| parent | 3adc760fb92eab1a8720337a8bf9b66486609eb3 (diff) | |
| download | postgresql-fdf5a5efb7b28c13085fe7313658de8d7b9914f6.tar.gz | |
pgindent run for 8.3.
Diffstat (limited to 'src/interfaces')
30 files changed, 754 insertions, 694 deletions
diff --git a/src/interfaces/ecpg/compatlib/informix.c b/src/interfaces/ecpg/compatlib/informix.c index 7f2e6613b4..77b5656f55 100644 --- a/src/interfaces/ecpg/compatlib/informix.c +++ b/src/interfaces/ecpg/compatlib/informix.c @@ -1,4 +1,4 @@ -/* $PostgreSQL: pgsql/src/interfaces/ecpg/compatlib/informix.c,v 1.52 2007/10/03 13:20:19 meskes Exp $ */ +/* $PostgreSQL: pgsql/src/interfaces/ecpg/compatlib/informix.c,v 1.53 2007/11/15 21:14:45 momjian Exp $ */ #include <math.h> #include <ctype.h> @@ -201,7 +201,7 @@ deccvasc(char *cp, int len, decimal *np) } else { - int i = PGTYPESnumeric_to_decimal(result, np); + int i = PGTYPESnumeric_to_decimal(result, np); free(result); if (i != 0) @@ -700,7 +700,7 @@ initValue(long lng_val) value.remaining = value.digits; /* convert the long to string */ - if ((value.val_string = (char *) malloc(value.digits + 1)) == NULL) + if ((value.val_string = (char *) malloc(value.digits + 1)) == NULL) return -1; dig = value.val; for (i = value.digits, j = 0; i > 0; i--, j++) diff --git a/src/interfaces/ecpg/ecpglib/connect.c b/src/interfaces/ecpg/ecpglib/connect.c index efc0fe618c..e1f0957d43 100644 --- a/src/interfaces/ecpg/ecpglib/connect.c +++ b/src/interfaces/ecpg/ecpglib/connect.c @@ -1,4 +1,4 @@ -/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/connect.c,v 1.47 2007/10/03 11:11:12 meskes Exp $ */ +/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/connect.c,v 1.48 2007/11/15 21:14:45 momjian Exp $ */ #define POSTGRES_ECPG_INTERNAL #include "postgres_fe.h" @@ -11,9 +11,9 @@ #include "sqlca.h" #ifdef ENABLE_THREAD_SAFETY -static pthread_mutex_t connections_mutex = PTHREAD_MUTEX_INITIALIZER; -static pthread_key_t actual_connection_key; -static pthread_once_t actual_connection_key_once = PTHREAD_ONCE_INIT; +static pthread_mutex_t connections_mutex = PTHREAD_MUTEX_INITIALIZER; +static pthread_key_t actual_connection_key; +static pthread_once_t actual_connection_key_once = PTHREAD_ONCE_INIT; #endif static struct connection *actual_connection = NULL; static struct connection *all_connections = NULL; @@ -272,7 +272,10 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p ecpg_init_sqlca(sqlca); - /* clear auto_mem structure because some error handling functions might access it */ + /* + * clear auto_mem structure because some error handling functions might + * access it + */ ecpg_clear_auto_mem(); if (INFORMIX_MODE(compat)) @@ -305,7 +308,7 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p { ecpg_free(dbname); ecpg_log("ECPGconnect: connection identifier %s is already in use\n", - connection_name); + connection_name); return false; } @@ -458,11 +461,11 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p actual_connection = all_connections; ecpg_log("ECPGconnect: opening database %s on %s port %s %s%s%s%s\n", - realname ? realname : "<DEFAULT>", - host ? host : "<DEFAULT>", - port ? (ecpg_internal_regression_mode ? "<REGRESSION_PORT>" : port) : "<DEFAULT>", - options ? "with options " : "", options ? options : "", - user ? "for user " : "", user ? user : ""); + realname ? realname : "<DEFAULT>", + host ? host : "<DEFAULT>", + port ? (ecpg_internal_regression_mode ? "<REGRESSION_PORT>" : port) : "<DEFAULT>", + options ? "with options " : "", options ? options : "", + user ? "for user " : "", user ? user : ""); this->connection = PQsetdbLogin(host, port, options, NULL, realname, user, passwd); @@ -472,12 +475,12 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p const char *db = realname ? realname : "<DEFAULT>"; ecpg_log("ECPGconnect: could not open database %s on %s port %s %s%s%s%s in line %d\n\t%s\n", - db, - host ? host : "<DEFAULT>", - port ? (ecpg_internal_regression_mode ? "<REGRESSION_PORT>" : port) : "<DEFAULT>", - options ? "with options " : "", options ? options : "", - user ? "for user " : "", user ? user : "", - lineno, errmsg); + db, + host ? host : "<DEFAULT>", + port ? (ecpg_internal_regression_mode ? "<REGRESSION_PORT>" : port) : "<DEFAULT>", + options ? "with options " : "", options ? options : "", + user ? "for user " : "", user ? user : "", + lineno, errmsg); ecpg_finish(this); #ifdef ENABLE_THREAD_SAFETY diff --git a/src/interfaces/ecpg/ecpglib/data.c b/src/interfaces/ecpg/ecpglib/data.c index 07282ffbe2..0285c71831 100644 --- a/src/interfaces/ecpg/ecpglib/data.c +++ b/src/interfaces/ecpg/ecpglib/data.c @@ -1,4 +1,4 @@ -/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/data.c,v 1.39 2007/10/03 11:11:12 meskes Exp $ */ +/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/data.c,v 1.40 2007/11/15 21:14:45 momjian Exp $ */ #define POSTGRES_ECPG_INTERNAL #include "postgres_fe.h" @@ -40,9 +40,9 @@ garbage_left(enum ARRAY_TYPE isarray, char *scan_length, enum COMPAT_MODE compat bool ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno, - enum ECPGttype type, enum ECPGttype ind_type, - char *var, char *ind, long varcharsize, long offset, - long ind_offset, enum ARRAY_TYPE isarray, enum COMPAT_MODE compat, bool force_indicator) + enum ECPGttype type, enum ECPGttype ind_type, + char *var, char *ind, long varcharsize, long offset, + long ind_offset, enum ARRAY_TYPE isarray, enum COMPAT_MODE compat, bool force_indicator) { struct sqlca_t *sqlca = ECPGget_sqlca(); char *pval = (char *) PQgetvalue(results, act_tuple, act_field); @@ -105,16 +105,16 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno, else { ecpg_raise(lineno, ECPG_MISSING_INDICATOR, - ECPG_SQLSTATE_NULL_VALUE_NO_INDICATOR_PARAMETER, - NULL); + ECPG_SQLSTATE_NULL_VALUE_NO_INDICATOR_PARAMETER, + NULL); return (false); } } break; default: ecpg_raise(lineno, ECPG_UNSUPPORTED, - ECPG_SQLSTATE_ECPG_INTERNAL_ERROR, - ecpg_type_name(ind_type)); + ECPG_SQLSTATE_ECPG_INTERNAL_ERROR, + ecpg_type_name(ind_type)); return (false); break; } @@ -129,7 +129,7 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno, if (!pval || *pval != '{') { ecpg_raise(lineno, ECPG_DATA_NOT_ARRAY, - ECPG_SQLSTATE_DATATYPE_MISMATCH, NULL); + ECPG_SQLSTATE_DATATYPE_MISMATCH, NULL); return (false); } @@ -214,7 +214,7 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno, if (garbage_left(isarray, scan_length, compat)) { ecpg_raise(lineno, ECPG_INT_FORMAT, - ECPG_SQLSTATE_DATATYPE_MISMATCH, pval); + ECPG_SQLSTATE_DATATYPE_MISMATCH, pval); return (false); } pval = scan_length; @@ -248,7 +248,7 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno, if (garbage_left(isarray, scan_length, compat)) { ecpg_raise(lineno, ECPG_UINT_FORMAT, - ECPG_SQLSTATE_DATATYPE_MISMATCH, pval); + ECPG_SQLSTATE_DATATYPE_MISMATCH, pval); return (false); } pval = scan_length; @@ -326,7 +326,7 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno, if (garbage_left(isarray, scan_length, compat)) { ecpg_raise(lineno, ECPG_FLOAT_FORMAT, - ECPG_SQLSTATE_DATATYPE_MISMATCH, pval); + ECPG_SQLSTATE_DATATYPE_MISMATCH, pval); return (false); } pval = scan_length; @@ -359,8 +359,8 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno, *((int *) (var + offset * act_tuple)) = false; else ecpg_raise(lineno, ECPG_CONVERT_BOOL, - ECPG_SQLSTATE_DATATYPE_MISMATCH, - "different size"); + ECPG_SQLSTATE_DATATYPE_MISMATCH, + "different size"); break; } else if (pval[0] == 't' && pval[1] == '\0') @@ -371,8 +371,8 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno, *((int *) (var + offset * act_tuple)) = true; else ecpg_raise(lineno, ECPG_CONVERT_BOOL, - ECPG_SQLSTATE_DATATYPE_MISMATCH, - "different size"); + ECPG_SQLSTATE_DATATYPE_MISMATCH, + "different size"); break; } else if (pval[0] == '\0' && PQgetisnull(results, act_tuple, act_field)) @@ -383,7 +383,7 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno, } ecpg_raise(lineno, ECPG_CONVERT_BOOL, - ECPG_SQLSTATE_DATATYPE_MISMATCH, pval); + ECPG_SQLSTATE_DATATYPE_MISMATCH, pval); return (false); break; @@ -491,7 +491,7 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno, if (nres == NULL) { ecpg_log("ecpg_get_data line %d: RESULT: %s errno %d\n", - lineno, pval ? pval : "", errno); + lineno, pval ? pval : "", errno); if (INFORMIX_MODE(compat)) { @@ -554,7 +554,7 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno, if (ires == NULL) { ecpg_log("ecpg_get_data line %d: RESULT: %s errno %d\n", - lineno, pval ? pval : "", errno); + lineno, pval ? pval : "", errno); if (INFORMIX_MODE(compat)) { @@ -608,7 +608,7 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno, if (errno != 0) { ecpg_log("ecpg_get_data line %d: RESULT: %s errno %d\n", - lineno, pval ? pval : "", errno); + lineno, pval ? pval : "", errno); if (INFORMIX_MODE(compat)) { @@ -655,7 +655,7 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno, if (errno != 0) { ecpg_log("ecpg_get_data line %d: RESULT: %s errno %d\n", - lineno, pval ? pval : "", errno); + lineno, pval ? pval : "", errno); if (INFORMIX_MODE(compat)) { @@ -692,8 +692,8 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno, default: ecpg_raise(lineno, ECPG_UNSUPPORTED, - ECPG_SQLSTATE_ECPG_INTERNAL_ERROR, - ecpg_type_name(type)); + ECPG_SQLSTATE_ECPG_INTERNAL_ERROR, + ecpg_type_name(type)); return (false); break; } diff --git a/src/interfaces/ecpg/ecpglib/descriptor.c b/src/interfaces/ecpg/ecpglib/descriptor.c index f683c0f285..0e76e244b1 100644 --- a/src/interfaces/ecpg/ecpglib/descriptor.c +++ b/src/interfaces/ecpg/ecpglib/descriptor.c @@ -1,6 +1,6 @@ /* dynamic SQL support routines * - * $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/descriptor.c,v 1.27 2007/10/03 16:03:25 tgl Exp $ + * $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/descriptor.c,v 1.28 2007/11/15 21:14:45 momjian Exp $ */ #define POSTGRES_ECPG_INTERNAL @@ -15,14 +15,14 @@ #include "sqlca.h" #include "sql3types.h" -static void descriptor_free(struct descriptor *desc); +static void descriptor_free(struct descriptor * desc); /* We manage descriptors separately for each thread. */ #ifdef ENABLE_THREAD_SAFETY -static pthread_key_t descriptor_key; -static pthread_once_t descriptor_once = PTHREAD_ONCE_INIT; +static pthread_key_t descriptor_key; +static pthread_once_t descriptor_once = PTHREAD_ONCE_INIT; -static void descriptor_deallocate_all(struct descriptor *list); +static void descriptor_deallocate_all(struct descriptor * list); static void descriptor_destructor(void *arg) @@ -44,13 +44,13 @@ get_descriptors(void) } static void -set_descriptors(struct descriptor *value) +set_descriptors(struct descriptor * value) { pthread_setspecific(descriptor_key, value); } - #else -static struct descriptor *all_descriptors = NULL; +static struct descriptor *all_descriptors = NULL; + #define get_descriptors() (all_descriptors) #define set_descriptors(value) do { all_descriptors = (value); } while(0) #endif @@ -60,6 +60,7 @@ static PGresult * ecpg_result_by_descriptor(int line, const char *name) { struct descriptor *desc = ecpg_find_desc(line, name); + if (desc == NULL) return NULL; return desc->result; @@ -381,7 +382,7 @@ ECPGget_desc(int lineno, const char *desc_name, int index,...) if (arrsize > 0 && ntuples > arrsize) { ecpg_log("ECPGget_desc line %d: Incorrect number of matches: %d don't fit into array of %d\n", - lineno, ntuples, arrsize); + lineno, ntuples, arrsize); ecpg_raise(lineno, ECPG_TOO_MANY_MATCHES, ECPG_SQLSTATE_CARDINALITY_VIOLATION, NULL); return false; } @@ -450,7 +451,7 @@ ECPGget_desc(int lineno, const char *desc_name, int index,...) if (data_var.ind_arrsize > 0 && ntuples > data_var.ind_arrsize) { ecpg_log("ECPGget_desc line %d: Incorrect number of matches (indicator): %d don't fit into array of %d\n", - lineno, ntuples, data_var.ind_arrsize); + lineno, ntuples, data_var.ind_arrsize); ecpg_raise(lineno, ECPG_TOO_MANY_MATCHES, ECPG_SQLSTATE_CARDINALITY_VIOLATION, NULL); return false; } @@ -483,6 +484,7 @@ bool ECPGset_desc_header(int lineno, const char *desc_name, int count) { struct descriptor *desc = ecpg_find_desc(lineno, desc_name); + if (desc == NULL) return false; desc->count = count; @@ -556,7 +558,7 @@ ECPGset_desc(int lineno, const char *desc_name, int index,...) var->varcharsize = 0; var->next = NULL; - + switch (itemtype) { case ECPGd_data: @@ -567,7 +569,8 @@ ECPGset_desc(int lineno, const char *desc_name, int index,...) return false; } - ecpg_free(desc_item->data); /* free() takes care of a potential NULL value */ + ecpg_free(desc_item->data); /* free() takes care of a + * potential NULL value */ desc_item->data = (char *) tobeinserted; tobeinserted = NULL; break; @@ -611,7 +614,7 @@ ECPGset_desc(int lineno, const char *desc_name, int index,...) /* Free the descriptor and items in it. */ static void -descriptor_free(struct descriptor *desc) +descriptor_free(struct descriptor * desc) { struct descriptor_item *desc_item; @@ -658,17 +661,17 @@ ECPGdeallocate_desc(int line, const char *name) /* Deallocate all descriptors in the list */ static void -descriptor_deallocate_all(struct descriptor *list) +descriptor_deallocate_all(struct descriptor * list) { while (list) { struct descriptor *next = list->next; + descriptor_free(list); list = next; } } - -#endif /* ENABLE_THREAD_SAFETY */ +#endif /* ENABLE_THREAD_SAFETY */ bool ECPGallocate_desc(int line, const char *name) @@ -715,7 +718,7 @@ ecpg_find_desc(int line, const char *name) } ecpg_raise(line, ECPG_UNKNOWN_DESCRIPTOR, ECPG_SQLSTATE_INVALID_SQL_DESCRIPTOR_NAME, name); - return NULL; /* not found */ + return NULL; /* not found */ } bool diff --git a/src/interfaces/ecpg/ecpglib/error.c b/src/interfaces/ecpg/ecpglib/error.c index b33d3f857b..cce370aca6 100644 --- a/src/interfaces/ecpg/ecpglib/error.c +++ b/src/interfaces/ecpg/ecpglib/error.c @@ -1,4 +1,4 @@ -/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/error.c,v 1.18 2007/10/03 11:11:12 meskes Exp $ */ +/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/error.c,v 1.19 2007/11/15 21:14:45 momjian Exp $ */ #define POSTGRES_ECPG_INTERNAL #include "postgres_fe.h" @@ -189,7 +189,7 @@ ecpg_raise_backend(int line, PGresult *result, PGconn *conn, int compat) sqlca->sqlcode = ECPG_PGSQL; ecpg_log("raising sqlstate %.*s (sqlcode: %d) in line %d, '%s'.\n", - sizeof(sqlca->sqlstate), sqlca->sqlstate, sqlca->sqlcode, line, sqlca->sqlerrm.sqlerrmc); + sizeof(sqlca->sqlstate), sqlca->sqlstate, sqlca->sqlcode, line, sqlca->sqlerrm.sqlerrmc); /* free all memory we have allocated for the user */ ECPGfree_auto_mem(); @@ -197,7 +197,7 @@ ecpg_raise_backend(int line, PGresult *result, PGconn *conn, int compat) /* filter out all error codes */ bool -ecpg_check_PQresult(PGresult *results, int lineno, PGconn *connection, enum COMPAT_MODE compat) +ecpg_check_PQresult(PGresult *results, int lineno, PGconn *connection, enum COMPAT_MODE compat) { if (results == NULL) { @@ -230,20 +230,20 @@ ecpg_check_PQresult(PGresult *results, int lineno, PGconn *connection, enum COMP return (false); break; case PGRES_COPY_OUT: - return(true); + return (true); break; case PGRES_COPY_IN: ecpg_log("ecpg_check_PQresult line %d: Got PGRES_COPY_IN ... tossing.\n", lineno); PQendcopy(connection); PQclear(results); - return(false); + return (false); break; default: ecpg_log("ecpg_check_PQresult line %d: Got something else, postgres error.\n", - lineno); + lineno); ecpg_raise_backend(lineno, results, connection, compat); PQclear(results); - return(false); + return (false); break; } } diff --git a/src/interfaces/ecpg/ecpglib/execute.c b/src/interfaces/ecpg/ecpglib/execute.c index 034db8570c..689421a9c0 100644 --- a/src/interfaces/ecpg/ecpglib/execute.c +++ b/src/interfaces/ecpg/ecpglib/execute.c @@ -1,4 +1,4 @@ -/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.72 2007/10/03 11:11:12 meskes Exp $ */ +/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.73 2007/11/15 21:14:45 momjian Exp $ */ /* * The aim is to get a simpler inteface to the database routines. @@ -38,10 +38,10 @@ static char * quote_postgres(char *arg, bool quote, int lineno) { - char *res; - size_t length; - size_t escaped_len; - size_t buffer_len; + char *res; + size_t length; + size_t escaped_len; + size_t buffer_len; /* * if quote is false we just need to store things in a descriptor they @@ -56,22 +56,22 @@ quote_postgres(char *arg, bool quote, int lineno) res = (char *) ecpg_alloc(buffer_len + 3, lineno); if (!res) return (res); - escaped_len = PQescapeString(res+1, arg, buffer_len); + escaped_len = PQescapeString(res + 1, arg, buffer_len); if (length == escaped_len) { - res[0] = res[escaped_len+1] = '\''; - res[escaped_len+2] = '\0'; + res[0] = res[escaped_len + 1] = '\''; + res[escaped_len + 2] = '\0'; } else { - /* + /* * We don't know if the target database is using * standard_conforming_strings, so we always use E'' strings. */ - memmove(res+2, res+1, escaped_len); + memmove(res + 2, res + 1, escaped_len); res[0] = ESCAPE_STRING_SYNTAX; - res[1] = res[escaped_len+2] = '\''; - res[escaped_len+3] = '\0'; + res[1] = res[escaped_len + 2] = '\''; + res[escaped_len + 3] = '\0'; } ecpg_free(arg); return res; @@ -108,31 +108,31 @@ free_statement(struct statement * stmt) ecpg_free(stmt); } -static int +static int next_insert(char *text, int pos, bool questionmarks) { bool string = false; - int p = pos; + int p = pos; for (; text[p] != '\0'; p++) { - if (text[p] == '\\') /* escape character */ + if (text[p] == '\\') /* escape character */ p++; else if (text[p] == '\'') string = string ? false : true; else if (!string) { - if (text[p] == '$' && isdigit(text[p+1])) + if (text[p] == '$' && isdigit(text[p + 1])) { /* this can be either a dollar quote or a variable */ - int i; + int i; for (i = p + 1; isdigit(text[i]); i++); - if (!isalpha(text[i]) && isascii(text[i]) && text[i] != '_') + if (!isalpha(text[i]) &&isascii(text[i]) &&text[i] != '_') /* not dollar delimeted quote */ return p; } - else if (questionmarks && text[p] == '?') + else if (questionmarks && text[p] == '?') { /* also allow old style placeholders */ return p; @@ -306,7 +306,7 @@ ecpg_is_type_an_array(int type, const struct statement * stmt, const struct vari bool ecpg_store_result(const PGresult *results, int act_field, - const struct statement * stmt, struct variable * var) + const struct statement * stmt, struct variable * var) { enum ARRAY_TYPE isarray; int act_tuple, @@ -327,7 +327,7 @@ ecpg_store_result(const PGresult *results, int act_field, if ((var->arrsize > 0 && ntuples > var->arrsize) || (var->ind_arrsize > 0 && ntuples > var->ind_arrsize)) { ecpg_log("ecpg_store_result line %d: Incorrect number of matches: %d don't fit into array of %d\n", - stmt->lineno, ntuples, var->arrsize); + stmt->lineno, ntuples, var->arrsize); ecpg_raise(stmt->lineno, INFORMIX_MODE(stmt->compat) ? ECPG_INFORMIX_SUBSELECT_NOT_ONE : ECPG_TOO_MANY_MATCHES, ECPG_SQLSTATE_CARDINALITY_VIOLATION, NULL); return false; } @@ -422,8 +422,8 @@ ecpg_store_result(const PGresult *results, int act_field, int len = strlen(PQgetvalue(results, act_tuple, act_field)) + 1; if (!ecpg_get_data(results, act_tuple, act_field, stmt->lineno, - var->type, var->ind_type, current_data_location, - var->ind_value, len, 0, var->ind_offset, isarray, stmt->compat, stmt->force_indicator)) + var->type, var->ind_type, current_data_location, + var->ind_value, len, 0, var->ind_offset, isarray, stmt->compat, stmt->force_indicator)) status = false; else { @@ -441,8 +441,8 @@ ecpg_store_result(const PGresult *results, int act_field, for (act_tuple = 0; act_tuple < ntuples && status; act_tuple++) { if (!ecpg_get_data(results, act_tuple, act_field, stmt->lineno, - var->type, var->ind_type, var->value, - var->ind_value, var->varcharsize, var->offset, var->ind_offset, isarray, stmt->compat, stmt->force_indicator)) + var->type, var->ind_type, var->value, + var->ind_value, var->varcharsize, var->offset, var->ind_offset, isarray, stmt->compat, stmt->force_indicator)) status = false; } } @@ -451,7 +451,7 @@ ecpg_store_result(const PGresult *results, int act_field, bool ecpg_store_input(const int lineno, const bool force_indicator, const struct variable * var, - const char **tobeinserted_p, bool quote) + const char **tobeinserted_p, bool quote) { char *mallocedval = NULL; char *newcopy = NULL; @@ -1035,13 +1035,13 @@ ecpg_store_input(const int lineno, const bool force_indicator, const struct vari static void free_params(const char **paramValues, int nParams, bool print, int lineno) { - int n; + int n; for (n = 0; n < nParams; n++) { if (print) ecpg_log("free_params line %d: parameter %d = %s\n", lineno, n + 1, paramValues[n] ? paramValues[n] : "null"); - ecpg_free((void *)(paramValues[n])); + ecpg_free((void *) (paramValues[n])); } ecpg_free(paramValues); } @@ -1055,22 +1055,22 @@ ecpg_execute(struct statement * stmt) PGnotify *notify; struct variable *var; int desc_counter = 0; - const char * *paramValues = NULL; - int nParams = 0; - int position = 0; + const char **paramValues = NULL; + int nParams = 0; + int position = 0; struct sqlca_t *sqlca = ECPGget_sqlca(); - bool clear_result = true; + bool clear_result = true; /* - * If the type is one of the fill in types then we take the argument - * and enter it to our parameter array at the first position. Then if there + * If the type is one of the fill in types then we take the argument and + * enter it to our parameter array at the first position. Then if there * are any more fill in types we add more parameters. */ var = stmt->inlist; while (var) { const char *tobeinserted; - int counter = 1; + int counter = 1; tobeinserted = NULL; @@ -1134,8 +1134,9 @@ ecpg_execute(struct statement * stmt) /* * now tobeinserted points to an area that contains the next parameter - * if var->type=ECPGt_char_variable we have a dynamic cursor - * we have to simulate a dynamic cursor because there is no backend functionality for it + * if var->type=ECPGt_char_variable we have a dynamic cursor we have + * to simulate a dynamic cursor because there is no backend + * functionality for it */ if (var->type != ECPGt_char_variable) { @@ -1156,17 +1157,19 @@ ecpg_execute(struct statement * stmt) */ ecpg_raise(stmt->lineno, ECPG_TOO_MANY_ARGUMENTS, ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_PARAMETERS, - NULL); + NULL); free_params(paramValues, nParams, false, stmt->lineno); return false; } - + /* let's see if this was an old style placeholder */ - if (stmt->command[position-1] == '?') + if (stmt->command[position - 1] == '?') { /* yes, replace with new style */ - int buffersize = sizeof(int) * CHAR_BIT * 10 / 3; /* a rough guess of the size we need */ - char *buffer, *newcopy; + int buffersize = sizeof(int) * CHAR_BIT * 10 / 3; /* a rough guess of the + * size we need */ + char *buffer, + *newcopy; if (!(buffer = (char *) ecpg_alloc(buffersize, stmt->lineno))) { @@ -1202,11 +1205,11 @@ ecpg_execute(struct statement * stmt) } else { - char *newcopy; + char *newcopy; if (!(newcopy = (char *) ecpg_alloc(strlen(stmt->command) - + strlen(tobeinserted) - + 1, stmt->lineno))) + + strlen(tobeinserted) + + 1, stmt->lineno))) { free_params(paramValues, nParams, false, stmt->lineno); return false; @@ -1221,14 +1224,14 @@ ecpg_execute(struct statement * stmt) */ ecpg_raise(stmt->lineno, ECPG_TOO_MANY_ARGUMENTS, ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_PARAMETERS, - NULL); + NULL); free_params(paramValues, nParams, false, stmt->lineno); ecpg_free(newcopy); return false; } else { - int ph_len = (stmt->command[position] == '?') ? strlen("?") : strlen("$1"); + int ph_len = (stmt->command[position] == '?') ? strlen("?") : strlen("$1"); strcpy(newcopy + position - 1, tobeinserted); @@ -1238,14 +1241,14 @@ ecpg_execute(struct statement * stmt) */ strcat(newcopy, stmt->command - + position + + position + ph_len - 1); } ecpg_free(stmt->command); stmt->command = newcopy; - - ecpg_free((char *)tobeinserted); + + ecpg_free((char *) tobeinserted); tobeinserted = NULL; } @@ -1257,7 +1260,7 @@ ecpg_execute(struct statement * stmt) if (next_insert(stmt->command, position, stmt->questionmarks) >= 0) { ecpg_raise(stmt->lineno, ECPG_TOO_FEW_ARGUMENTS, - ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_PARAMETERS, NULL); + ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_PARAMETERS, NULL); free_params(paramValues, nParams, false, stmt->lineno); return false; } @@ -1304,9 +1307,9 @@ ecpg_execute(struct statement * stmt) var = stmt->outlist; switch (PQresultStatus(results)) { - int nfields, - ntuples, - act_field; + int nfields, + ntuples, + act_field; case PGRES_TUPLES_OK: nfields = PQnfields(results); @@ -1318,7 +1321,7 @@ ecpg_execute(struct statement * stmt) { if (ntuples) ecpg_log("ecpg_execute line %d: Incorrect number of matches: %d\n", - stmt->lineno, ntuples); + stmt->lineno, ntuples); ecpg_raise(stmt->lineno, ECPG_NOT_FOUND, ECPG_SQLSTATE_NO_DATA, NULL); status = false; break; @@ -1327,6 +1330,7 @@ ecpg_execute(struct statement * stmt) if (var != NULL && var->type == ECPGt_descriptor) { struct descriptor *desc = ecpg_find_desc(stmt->lineno, var->pointer); + if (desc == NULL) status = false; else @@ -1399,9 +1403,13 @@ ecpg_execute(struct statement * stmt) break; } default: - /* execution should never reach this code because it is already handled in ECPGcheck_PQresult() */ + + /* + * execution should never reach this code because it is already + * handled in ECPGcheck_PQresult() + */ ecpg_log("ecpg_execute line %d: Got something else, postgres error.\n", - stmt->lineno); + stmt->lineno); ecpg_raise_backend(stmt->lineno, results, stmt->connection->connection, stmt->compat); status = false; break; @@ -1414,7 +1422,7 @@ ecpg_execute(struct statement * stmt) if (notify) { ecpg_log("ecpg_execute line %d: ASYNC NOTIFY of '%s' from backend pid '%d' received\n", - stmt->lineno, notify->relname, notify->be_pid); + stmt->lineno, notify->relname, notify->be_pid); PQfreemem(notify); } @@ -1432,12 +1440,12 @@ ECPGdo(const int lineno, const int compat, const int force_indicator, const char enum ECPGttype type; struct variable **list; enum ECPG_statement_type statement_type = st; - char *prepname; + char *prepname; if (!query) { ecpg_raise(lineno, ECPG_EMPTY, ECPG_SQLSTATE_ECPG_INTERNAL_ERROR, NULL); - return(false); + return (false); } /* Make sure we do NOT honor the locale for numeric input/output */ @@ -1462,22 +1470,16 @@ ECPGdo(const int lineno, const int compat, const int force_indicator, const char va_start(args, query); /* - * create a list of variables - * The variables are listed with input variables preceding outputvariables - * The end of each group is marked by an end marker. - * per variable we list: - * type - as defined in ecpgtype.h - * value - where to store the data - * varcharsize - length of string in case we have a stringvariable, else 0 - * arraysize - 0 for pointer (we don't know the size of the array), - * 1 for simple variable, size for arrays - * offset - offset between ith and (i+1)th entry in an array, - * normally that means sizeof(type) - * ind_type - type of indicator variable - * ind_value - pointer to indicator variable - * ind_varcharsize - empty - * ind_arraysize - arraysize of indicator array - * ind_offset - indicator offset + * create a list of variables The variables are listed with input + * variables preceding outputvariables The end of each group is marked by + * an end marker. per variable we list: type - as defined in ecpgtype.h + * value - where to store the data varcharsize - length of string in case + * we have a stringvariable, else 0 arraysize - 0 for pointer (we don't + * know the size of the array), 1 for simple variable, size for arrays + * offset - offset between ith and (i+1)th entry in an array, normally + * that means sizeof(type) ind_type - type of indicator variable ind_value + * - pointer to indicator variable ind_varcharsize - empty ind_arraysize - + * arraysize of indicator array ind_offset - indicator offset */ if (!(stmt = (struct statement *) ecpg_alloc(sizeof(struct statement), lineno))) { @@ -1487,14 +1489,19 @@ ECPGdo(const int lineno, const int compat, const int force_indicator, const char return false; } - /* If statement type is ECPGst_prepnormal we are supposed to prepare - * the statement before executing them */ + /* + * If statement type is ECPGst_prepnormal we are supposed to prepare the + * statement before executing them + */ if (statement_type == ECPGst_prepnormal) { if (!ecpg_auto_prepare(lineno, connection_name, questionmarks, &prepname, query)) - return(false); + return (false); - /* statement is now prepared, so instead of the query we have to execute the name */ + /* + * statement is now prepared, so instead of the query we have to + * execute the name + */ stmt->command = prepname; statement_type = ECPGst_execute; } @@ -1506,7 +1513,7 @@ ECPGdo(const int lineno, const int compat, const int force_indicator, const char if (statement_type == ECPGst_execute) { /* if we have an EXECUTE command, only the name is send */ - char *command = ecpg_prepared(stmt->command, con, lineno); + char *command = ecpg_prepared(stmt->command, con, lineno); if (command) { @@ -1559,7 +1566,8 @@ ECPGdo(const int lineno, const int compat, const int force_indicator, const char var->value = var->pointer; /* - * negative values are used to indicate an array without given bounds + * negative values are used to indicate an array without given + * bounds */ /* reset to zero for us */ if (var->arrsize < 0) @@ -1582,7 +1590,8 @@ ECPGdo(const int lineno, const int compat, const int force_indicator, const char var->ind_value = var->ind_pointer; /* - * negative values are used to indicate an array without given bounds + * negative values are used to indicate an array without given + * bounds */ /* reset to zero for us */ if (var->ind_arrsize < 0) diff --git a/src/interfaces/ecpg/ecpglib/extern.h b/src/interfaces/ecpg/ecpglib/extern.h index f14aca7a19..e366c9ce44 100644 --- a/src/interfaces/ecpg/ecpglib/extern.h +++ b/src/interfaces/ecpg/ecpglib/extern.h @@ -1,4 +1,4 @@ -/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/extern.h,v 1.31 2007/10/03 11:11:12 meskes Exp $ */ +/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/extern.h,v 1.32 2007/11/15 21:14:45 momjian Exp $ */ #ifndef _ECPG_LIB_EXTERN_H #define _ECPG_LIB_EXTERN_H @@ -53,7 +53,7 @@ struct statement enum COMPAT_MODE compat; bool force_indicator; enum ECPG_statement_type statement_type; - bool questionmarks; + bool questionmarks; struct variable *inlist; struct variable *outlist; }; @@ -115,8 +115,8 @@ struct variable void ecpg_add_mem(void *ptr, int lineno); bool ecpg_get_data(const PGresult *, int, int, int, enum ECPGttype type, - enum ECPGttype, char *, char *, long, long, long, - enum ARRAY_TYPE, enum COMPAT_MODE, bool); + enum ECPGttype, char *, char *, long, long, long, + enum ARRAY_TYPE, enum COMPAT_MODE, bool); #ifdef ENABLE_THREAD_SAFETY void ecpg_pthreads_init(void); @@ -128,7 +128,7 @@ void ecpg_free(void *); bool ecpg_init(const struct connection *, const char *, const int); char *ecpg_strdup(const char *, int); const char *ecpg_type_name(enum ECPGttype); -int ecpg_dynamic_type(Oid); +int ecpg_dynamic_type(Oid); void ecpg_free_auto_mem(void); void ecpg_clear_auto_mem(void); @@ -137,17 +137,17 @@ struct descriptor *ecpggetdescp(int, char *); struct descriptor *ecpg_find_desc(int line, const char *name); bool ecpg_store_result(const PGresult *results, int act_field, - const struct statement * stmt, struct variable * var); -bool ecpg_store_input(const int, const bool, const struct variable *, const char **, bool); - -bool ecpg_check_PQresult(PGresult *, int, PGconn *, enum COMPAT_MODE); -void ecpg_raise(int line, int code, const char *sqlstate, const char *str); -void ecpg_raise_backend(int line, PGresult *result, PGconn *conn, int compat); -char *ecpg_prepared(const char *, struct connection *, int); -bool ecpg_deallocate_all_conn(int lineno, enum COMPAT_MODE c, struct connection *conn); -void ecpg_log(const char *format,...); -bool ecpg_auto_prepare(int, const char *, const int, char **, const char *); -void ecpg_init_sqlca(struct sqlca_t * sqlca); + const struct statement * stmt, struct variable * var); +bool ecpg_store_input(const int, const bool, const struct variable *, const char **, bool); + +bool ecpg_check_PQresult(PGresult *, int, PGconn *, enum COMPAT_MODE); +void ecpg_raise(int line, int code, const char *sqlstate, const char *str); +void ecpg_raise_backend(int line, PGresult *result, PGconn *conn, int compat); +char *ecpg_prepared(const char *, struct connection *, int); +bool ecpg_deallocate_all_conn(int lineno, enum COMPAT_MODE c, struct connection * conn); +void ecpg_log(const char *format,...); +bool ecpg_auto_prepare(int, const char *, const int, char **, const char *); +void ecpg_init_sqlca(struct sqlca_t * sqlca); /* SQLSTATE values generated or processed by ecpglib (intentionally * not exported -- users should refer to the codes directly) */ diff --git a/src/interfaces/ecpg/ecpglib/memory.c b/src/interfaces/ecpg/ecpglib/memory.c index cb22a15b75..63b57177ec 100644 --- a/src/interfaces/ecpg/ecpglib/memory.c +++ b/src/interfaces/ecpg/ecpglib/memory.c @@ -1,4 +1,4 @@ -/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/memory.c,v 1.11 2007/10/03 11:11:12 meskes Exp $ */ +/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/memory.c,v 1.12 2007/11/15 21:14:45 momjian Exp $ */ #define POSTGRES_ECPG_INTERNAL #include "postgres_fe.h" @@ -69,8 +69,8 @@ struct auto_mem }; #ifdef ENABLE_THREAD_SAFETY -static pthread_key_t auto_mem_key; -static pthread_once_t auto_mem_once = PTHREAD_ONCE_INIT; +static pthread_key_t auto_mem_key; +static pthread_once_t auto_mem_once = PTHREAD_ONCE_INIT; static void auto_mem_destructor(void *arg) @@ -92,13 +92,13 @@ get_auto_allocs(void) } static void -set_auto_allocs(struct auto_mem *am) +set_auto_allocs(struct auto_mem * am) { pthread_setspecific(auto_mem_key, am); } - #else -static struct auto_mem *auto_allocs = NULL; +static struct auto_mem *auto_allocs = NULL; + #define get_auto_allocs() (auto_allocs) #define set_auto_allocs(am) do { auto_allocs = (am); } while(0) #endif @@ -124,10 +124,11 @@ ECPGfree_auto_mem(void) do { struct auto_mem *act = am; + am = am->next; ecpg_free(act->pointer); ecpg_free(act); - } while(am); + } while (am); set_auto_allocs(NULL); } } @@ -143,9 +144,10 @@ ecpg_clear_auto_mem(void) do { struct auto_mem *act = am; + am = am->next; ecpg_free(act); - } while(am); + } while (am); set_auto_allocs(NULL); } } diff --git a/src/interfaces/ecpg/ecpglib/misc.c b/src/interfaces/ecpg/ecpglib/misc.c index a5aa52afcd..4c2b2447e9 100644 --- a/src/interfaces/ecpg/ecpglib/misc.c +++ b/src/interfaces/ecpg/ecpglib/misc.c @@ -1,4 +1,4 @@ -/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/misc.c,v 1.40 2007/10/03 11:11:12 meskes Exp $ */ +/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/misc.c,v 1.41 2007/11/15 21:14:45 momjian Exp $ */ #define POSTGRES_ECPG_INTERNAL #include "postgres_fe.h" @@ -26,7 +26,7 @@ #endif #endif -bool ecpg_internal_regression_mode = false; +bool ecpg_internal_regression_mode = false; static struct sqlca_t sqlca_init = { @@ -109,7 +109,7 @@ ecpg_init(const struct connection * con, const char *connection_name, const int if (con == NULL) { ecpg_raise(lineno, ECPG_NO_CONN, ECPG_SQLSTATE_CONNECTION_DOES_NOT_EXIST, - connection_name ? connection_name : "NULL"); + connection_name ? connection_name : "NULL"); return (false); } @@ -120,7 +120,7 @@ ecpg_init(const struct connection * con, const char *connection_name, const int static void ecpg_sqlca_key_destructor(void *arg) { - free(arg); /* sqlca structure allocated in ECPGget_sqlca */ + free(arg); /* sqlca structure allocated in ECPGget_sqlca */ } static void @@ -219,10 +219,10 @@ ECPGdebug(int n, FILE *dbgs) pthread_mutex_lock(&debug_init_mutex); #endif - if (n > 100) + if (n > 100) { ecpg_internal_regression_mode = true; - simple_debug = n-100; + simple_debug = n - 100; } else simple_debug = n; @@ -420,18 +420,18 @@ win32_pthread_mutex(volatile pthread_mutex_t *mutex) { if (mutex->handle == NULL) { - while (InterlockedExchange((LONG *)&mutex->initlock, 1) == 1) + while (InterlockedExchange((LONG *) & mutex->initlock, 1) == 1) Sleep(0); if (mutex->handle == NULL) mutex->handle = CreateMutex(NULL, FALSE, NULL); - InterlockedExchange((LONG *)&mutex->initlock, 0); + InterlockedExchange((LONG *) & mutex->initlock, 0); } } -static pthread_mutex_t win32_pthread_once_lock = PTHREAD_MUTEX_INITIALIZER; +static pthread_mutex_t win32_pthread_once_lock = PTHREAD_MUTEX_INITIALIZER; void -win32_pthread_once(volatile pthread_once_t *once, void (*fn)(void)) +win32_pthread_once(volatile pthread_once_t *once, void (*fn) (void)) { if (!*once) { @@ -444,6 +444,6 @@ win32_pthread_once(volatile pthread_once_t *once, void (*fn)(void)) pthread_mutex_unlock(&win32_pthread_once_lock); } } +#endif /* ENABLE_THREAD_SAFETY */ -#endif /* ENABLE_THREAD_SAFETY */ -#endif /* WIN32 */ +#endif /* WIN32 */ diff --git a/src/interfaces/ecpg/ecpglib/prepare.c b/src/interfaces/ecpg/ecpglib/prepare.c index 2433478a05..930bb4f64e 100644 --- a/src/interfaces/ecpg/ecpglib/prepare.c +++ b/src/interfaces/ecpg/ecpglib/prepare.c @@ -1,4 +1,4 @@ -/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/prepare.c,v 1.23 2007/11/05 20:57:24 tgl Exp $ */ +/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/prepare.c,v 1.24 2007/11/15 21:14:45 momjian Exp $ */ #define POSTGRES_ECPG_INTERNAL #include "postgres_fe.h" @@ -13,32 +13,32 @@ struct prepared_statement { - char *name; - bool prepared; - struct statement *stmt; - struct prepared_statement *next; + char *name; + bool prepared; + struct statement *stmt; + struct prepared_statement *next; }; #define STMTID_SIZE 32 -typedef struct +typedef struct { - int lineno; - char stmtID[STMTID_SIZE]; - char *ecpgQuery; - long execs; /* # of executions */ - char *connection; /* connection for the statement */ -} stmtCacheEntry; - -static int nextStmtID = 1; -static const int stmtCacheNBuckets = 2039; /* # buckets - a prime # */ -static const int stmtCacheEntPerBucket = 8; /* # entries/bucket */ -static stmtCacheEntry stmtCacheEntries[16384] = {{0,{0},0,0,0}}; + int lineno; + char stmtID[STMTID_SIZE]; + char *ecpgQuery; + long execs; /* # of executions */ + char *connection; /* connection for the statement */ +} stmtCacheEntry; + +static int nextStmtID = 1; +static const int stmtCacheNBuckets = 2039; /* # buckets - a prime # */ +static const int stmtCacheEntPerBucket = 8; /* # entries/bucket */ +static stmtCacheEntry stmtCacheEntries[16384] = {{0, {0}, 0, 0, 0}}; static struct prepared_statement *find_prepared_statement(const char *name, - struct connection *con, struct prepared_statement **prev); -static bool deallocate_one(int lineno, enum COMPAT_MODE c, struct connection *con, - struct prepared_statement *prev, struct prepared_statement *this); + struct connection * con, struct prepared_statement ** prev); +static bool deallocate_one(int lineno, enum COMPAT_MODE c, struct connection * con, + struct prepared_statement * prev, struct prepared_statement * this); static bool isvarchar(unsigned char c) @@ -58,8 +58,9 @@ isvarchar(unsigned char c) static bool replace_variables(char **text, int lineno, bool questionmarks) { - bool string = false; - int counter = 1, ptr = 0; + bool string = false; + int counter = 1, + ptr = 0; for (; (*text)[ptr] != '\0'; ptr++) { @@ -69,21 +70,23 @@ replace_variables(char **text, int lineno, bool questionmarks) if (string || (((*text)[ptr] != ':') && ((*text)[ptr] != '?'))) continue; - if (((*text)[ptr] == ':') && ((*text)[ptr+1] == ':')) - ptr += 2; /* skip '::' */ + if (((*text)[ptr] == ':') && ((*text)[ptr + 1] == ':')) + ptr += 2; /* skip '::' */ else { - int len; - int buffersize = sizeof(int) * CHAR_BIT * 10 / 3; /* a rough guess of the size we need */ - char *buffer, *newcopy; + int len; + int buffersize = sizeof(int) * CHAR_BIT * 10 / 3; /* a rough guess of the + * size we need */ + char *buffer, + *newcopy; if (!(buffer = (char *) ecpg_alloc(buffersize, lineno))) return false; snprintf(buffer, buffersize, "$%d", counter++); - for (len=1; (*text)[ptr+len] && isvarchar((*text)[ptr+len]); len++); - if (!(newcopy = (char *) ecpg_alloc(strlen(*text) - len + strlen(buffer) + 1, lineno))) + for (len = 1; (*text)[ptr + len] && isvarchar((*text)[ptr + len]); len++); + if (!(newcopy = (char *) ecpg_alloc(strlen(*text) -len + strlen(buffer) + 1, lineno))) { ecpg_free(buffer); return false; @@ -91,16 +94,16 @@ replace_variables(char **text, int lineno, bool questionmarks) strncpy(newcopy, *text, ptr); strcpy(newcopy + ptr, buffer); - strcat(newcopy, (*text) + ptr + len); + strcat(newcopy, (*text) +ptr + len); ecpg_free(*text); ecpg_free(buffer); *text = newcopy; - if ((*text)[ptr] == '\0') /* we reached the end */ - ptr--; /* since we will (*text)[ptr]++ in the top level for - * loop */ + if ((*text)[ptr] == '\0') /* we reached the end */ + ptr--; /* since we will (*text)[ptr]++ in the top + * level for loop */ } } return true; @@ -110,10 +113,10 @@ replace_variables(char **text, int lineno, bool questionmarks) bool ECPGprepare(int lineno, const char *connection_name, const int questionmarks, const char *name, const char *variable) { - struct connection *con; - struct statement *stmt; - struct prepared_statement *this, - *prev; + struct connection *con; + struct statement *stmt; + struct prepared_statement *this, + *prev; struct sqlca_t *sqlca = ECPGget_sqlca(); PGresult *query; @@ -174,11 +177,12 @@ ECPGprepare(int lineno, const char *connection_name, const int questionmarks, co return true; } -static struct prepared_statement *find_prepared_statement(const char *name, - struct connection *con, struct prepared_statement **prev_) +static struct prepared_statement * +find_prepared_statement(const char *name, + struct connection * con, struct prepared_statement ** prev_) { - struct prepared_statement *this, - *prev; + struct prepared_statement *this, + *prev; for (this = con->prep_stmts, prev = NULL; this != NULL; prev = this, this = this->next) { @@ -193,19 +197,20 @@ static struct prepared_statement *find_prepared_statement(const char *name, } static bool -deallocate_one(int lineno, enum COMPAT_MODE c, struct connection *con, struct prepared_statement *prev, struct prepared_statement *this) +deallocate_one(int lineno, enum COMPAT_MODE c, struct connection * con, struct prepared_statement * prev, struct prepared_statement * this) { - bool r = false; + bool r = false; ecpg_log("ECPGdeallocate line %d: NAME: %s\n", lineno, this->name); /* first deallocate the statement in the backend */ if (this->prepared) { - char *text; - PGresult *query; - + char *text; + PGresult *query; + text = (char *) ecpg_alloc(strlen("deallocate \"\" ") + strlen(this->name), this->stmt->lineno); + if (text) { sprintf(text, "deallocate \"%s\"", this->name); @@ -220,15 +225,15 @@ deallocate_one(int lineno, enum COMPAT_MODE c, struct connection *con, struct pr } /* - * Just ignore all errors since we do not know the list of cursors we - * are allowed to free. We have to trust the software. + * Just ignore all errors since we do not know the list of cursors we are + * allowed to free. We have to trust the software. */ if (!r && !INFORMIX_MODE(c)) { ecpg_raise(lineno, ECPG_INVALID_STMT, ECPG_SQLSTATE_INVALID_SQL_STATEMENT_NAME, this->name); return false; } - + /* okay, free all the resources */ ecpg_free(this->stmt->command); ecpg_free(this->stmt); @@ -245,9 +250,9 @@ deallocate_one(int lineno, enum COMPAT_MODE c, struct connection *con, struct pr bool ECPGdeallocate(int lineno, int c, const char *connection_name, const char *name) { - struct connection *con; - struct prepared_statement *this, - *prev; + struct connection *con; + struct prepared_statement *this, + *prev; con = ecpg_get_connection(connection_name); @@ -263,7 +268,7 @@ ECPGdeallocate(int lineno, int c, const char *connection_name, const char *name) } bool -ecpg_deallocate_all_conn(int lineno, enum COMPAT_MODE c, struct connection *con) +ecpg_deallocate_all_conn(int lineno, enum COMPAT_MODE c, struct connection * con) { /* deallocate all prepared statements */ while (con->prep_stmts) @@ -282,9 +287,10 @@ ECPGdeallocate_all(int lineno, int compat, const char *connection_name) } char * -ecpg_prepared(const char *name, struct connection *con, int lineno) +ecpg_prepared(const char *name, struct connection * con, int lineno) { - struct prepared_statement *this; + struct prepared_statement *this; + this = find_prepared_statement(name, con, NULL); return this ? this->stmt->command : NULL; } @@ -302,97 +308,102 @@ ECPGprepared_statement(const char *connection_name, const char *name, int lineno static int HashStmt(const char *ecpgQuery) { - int stmtIx, bucketNo, hashLeng, stmtLeng; - long long hashVal, rotVal; - - stmtLeng = strlen(ecpgQuery); - hashLeng = 50; /* use 1st 50 characters of statement */ - if(hashLeng > stmtLeng) /* if the statement isn't that long */ - hashLeng = stmtLeng; /* use its actual length */ - - hashVal = 0; - for(stmtIx = 0; stmtIx < hashLeng; ++stmtIx) - { - hashVal = hashVal + (int) ecpgQuery[stmtIx]; - hashVal = hashVal << 13; - rotVal = (hashVal & 0x1fff00000000LL) >> 32; - hashVal = (hashVal & 0xffffffffLL) | rotVal; - } - - bucketNo = hashVal % stmtCacheNBuckets; - bucketNo += 1; /* don't use bucket # 0 */ - - return (bucketNo * stmtCacheEntPerBucket); + int stmtIx, + bucketNo, + hashLeng, + stmtLeng; + long long hashVal, + rotVal; + + stmtLeng = strlen(ecpgQuery); + hashLeng = 50; /* use 1st 50 characters of statement */ + if (hashLeng > stmtLeng) /* if the statement isn't that long */ + hashLeng = stmtLeng; /* use its actual length */ + + hashVal = 0; + for (stmtIx = 0; stmtIx < hashLeng; ++stmtIx) + { + hashVal = hashVal + (int) ecpgQuery[stmtIx]; + hashVal = hashVal << 13; + rotVal = (hashVal & 0x1fff00000000LL) >> 32; + hashVal = (hashVal & 0xffffffffLL) | rotVal; + } + + bucketNo = hashVal % stmtCacheNBuckets; + bucketNo += 1; /* don't use bucket # 0 */ + + return (bucketNo * stmtCacheEntPerBucket); } /* * search the statement cache - search for entry with matching ECPG-format query * Returns entry # in cache if found - * OR zero if not present (zero'th entry isn't used) + * OR zero if not present (zero'th entry isn't used) */ static int SearchStmtCache(const char *ecpgQuery) { - int entNo, entIx; - -/* hash the statement */ - entNo = HashStmt(ecpgQuery); - -/* search the cache */ - for(entIx = 0; entIx < stmtCacheEntPerBucket; ++entIx) - { - if(stmtCacheEntries[entNo].stmtID[0]) /* check if entry is in use */ - { - if(!strcmp(ecpgQuery, stmtCacheEntries[entNo].ecpgQuery)) - break; /* found it */ - } - ++entNo; /* incr entry # */ - } + int entNo, + entIx; + +/* hash the statement */ + entNo = HashStmt(ecpgQuery); + +/* search the cache */ + for (entIx = 0; entIx < stmtCacheEntPerBucket; ++entIx) + { + if (stmtCacheEntries[entNo].stmtID[0]) /* check if entry is in use */ + { + if (!strcmp(ecpgQuery, stmtCacheEntries[entNo].ecpgQuery)) + break; /* found it */ + } + ++entNo; /* incr entry # */ + } /* if entry wasn't found - set entry # to zero */ - if(entIx >= stmtCacheEntPerBucket) - entNo = 0; + if (entIx >= stmtCacheEntPerBucket) + entNo = 0; - return(entNo); + return (entNo); } /* * free an entry in the statement cache * Returns entry # in cache used - * OR negative error code + * OR negative error code */ static int -ecpg_freeStmtCacheEntry(int entNo) /* entry # to free */ +ecpg_freeStmtCacheEntry(int entNo) /* entry # to free */ { - stmtCacheEntry *entry; - PGresult *results; - char deallocText[100]; - struct connection *con; - - entry = &stmtCacheEntries[entNo]; - if(!entry->stmtID[0]) /* return if the entry isn't in use */ - return(0); - - con = ecpg_get_connection(entry->connection); -/* free the server resources for the statement */ - ecpg_log("ecpg_freeStmtCacheEntry line %d: deallocate %s, cache entry #%d\n", entry->lineno, entry->stmtID, entNo); - sprintf(deallocText, "DEALLOCATE PREPARE %s", entry->stmtID); - results = PQexec(con->connection, deallocText); - - if (!ecpg_check_PQresult(results, entry->lineno, con->connection, ECPG_COMPAT_PGSQL)) - return(-1); - PQclear(results); - - entry->stmtID[0] = '\0'; - -/* free the memory used by the cache entry */ - if(entry->ecpgQuery) - { - ecpg_free(entry->ecpgQuery); - entry->ecpgQuery = 0; - } - - return(entNo); + stmtCacheEntry *entry; + PGresult *results; + char deallocText[100]; + struct connection *con; + + entry = &stmtCacheEntries[entNo]; + if (!entry->stmtID[0]) /* return if the entry isn't in use */ + return (0); + + con = ecpg_get_connection(entry->connection); +/* free the server resources for the statement */ + ecpg_log("ecpg_freeStmtCacheEntry line %d: deallocate %s, cache entry #%d\n", entry->lineno, entry->stmtID, entNo); + sprintf(deallocText, "DEALLOCATE PREPARE %s", entry->stmtID); + results = PQexec(con->connection, deallocText); + + if (!ecpg_check_PQresult(results, entry->lineno, con->connection, ECPG_COMPAT_PGSQL)) + return (-1); + PQclear(results); + + entry->stmtID[0] = '\0'; + +/* free the memory used by the cache entry */ + if (entry->ecpgQuery) + { + ecpg_free(entry->ecpgQuery); + entry->ecpgQuery = 0; + } + + return (entNo); } /* @@ -400,63 +411,67 @@ ecpg_freeStmtCacheEntry(int entNo) /* entry # to free */ * returns entry # in cache used OR negative error code */ static int -AddStmtToCache(int lineno, /* line # of statement */ - char *stmtID, /* statement ID */ - const char *connection, /* connection */ - const char *ecpgQuery) /* query */ +AddStmtToCache(int lineno, /* line # of statement */ + char *stmtID, /* statement ID */ + const char *connection, /* connection */ + const char *ecpgQuery) /* query */ { - int ix, initEntNo, luEntNo, entNo; - stmtCacheEntry *entry; - -/* hash the statement */ - initEntNo = HashStmt(ecpgQuery); - -/* search for an unused entry */ - entNo = initEntNo; /* start with the initial entry # for the bucket */ - luEntNo = initEntNo; /* use it as the initial 'least used' entry */ - for(ix = 0; ix < stmtCacheEntPerBucket; ++ix) - { - entry = &stmtCacheEntries[entNo]; - if(!entry->stmtID[0]) /* unused entry - use it */ - break; - if(entry->execs < stmtCacheEntries[luEntNo].execs) - luEntNo = entNo; /* save new 'least used' entry */ - ++entNo; /* increment entry # */ - } - -/* if no unused entries were found - use the 'least used' entry found in the bucket */ - if(ix >= stmtCacheEntPerBucket) /* if no unused entries were found */ - entNo = luEntNo; /* re-use the 'least used' entry */ - -/* 'entNo' is the entry to use - make sure its free */ - if (ecpg_freeStmtCacheEntry(entNo) < 0) - return (-1); - -/* add the query to the entry */ - entry = &stmtCacheEntries[entNo]; - entry->lineno = lineno; - entry->ecpgQuery = ecpg_strdup(ecpgQuery, lineno); - entry->connection = (char *)connection; - entry->execs = 0; - memcpy(entry->stmtID, stmtID, sizeof(entry->stmtID)); - - return(entNo); + int ix, + initEntNo, + luEntNo, + entNo; + stmtCacheEntry *entry; + +/* hash the statement */ + initEntNo = HashStmt(ecpgQuery); + +/* search for an unused entry */ + entNo = initEntNo; /* start with the initial entry # for the + * bucket */ + luEntNo = initEntNo; /* use it as the initial 'least used' entry */ + for (ix = 0; ix < stmtCacheEntPerBucket; ++ix) + { + entry = &stmtCacheEntries[entNo]; + if (!entry->stmtID[0]) /* unused entry - use it */ + break; + if (entry->execs < stmtCacheEntries[luEntNo].execs) + luEntNo = entNo; /* save new 'least used' entry */ + ++entNo; /* increment entry # */ + } + +/* if no unused entries were found - use the 'least used' entry found in the bucket */ + if (ix >= stmtCacheEntPerBucket) /* if no unused entries were found */ + entNo = luEntNo; /* re-use the 'least used' entry */ + +/* 'entNo' is the entry to use - make sure its free */ + if (ecpg_freeStmtCacheEntry(entNo) < 0) + return (-1); + +/* add the query to the entry */ + entry = &stmtCacheEntries[entNo]; + entry->lineno = lineno; + entry->ecpgQuery = ecpg_strdup(ecpgQuery, lineno); + entry->connection = (char *) connection; + entry->execs = 0; + memcpy(entry->stmtID, stmtID, sizeof(entry->stmtID)); + + return (entNo); } /* handle cache and preparation of statments in auto-prepare mode */ bool ecpg_auto_prepare(int lineno, const char *connection_name, const int questionmarks, char **name, const char *query) { - int entNo; + int entNo; - /* search the statement cache for this statement */ + /* search the statement cache for this statement */ entNo = SearchStmtCache(query); - /* if not found - add the statement to the cache */ - if(entNo) + /* if not found - add the statement to the cache */ + if (entNo) { ecpg_log("ecpg_auto_prepare line %d: stmt found in cache, entry %d\n", lineno, entNo); - *name = ecpg_strdup(stmtCacheEntries[entNo].stmtID, lineno); + *name = ecpg_strdup(stmtCacheEntries[entNo].stmtID, lineno); } else { @@ -467,13 +482,13 @@ ecpg_auto_prepare(int lineno, const char *connection_name, const int questionmar sprintf(*name, "ecpg%d", nextStmtID++); if (!ECPGprepare(lineno, connection_name, questionmarks, ecpg_strdup(*name, lineno), query)) - return(false); + return (false); if (AddStmtToCache(lineno, *name, connection_name, query) < 0) - return(false); + return (false); } /* increase usage counter */ stmtCacheEntries[entNo].execs++; - return(true); + return (true); } diff --git a/src/interfaces/ecpg/ecpglib/typename.c b/src/interfaces/ecpg/ecpglib/typename.c index 8a0c779809..e20c73cf75 100644 --- a/src/interfaces/ecpg/ecpglib/typename.c +++ b/src/interfaces/ecpg/ecpglib/typename.c @@ -1,4 +1,4 @@ -/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/typename.c,v 1.13 2007/10/03 11:11:12 meskes Exp $ */ +/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/typename.c,v 1.14 2007/11/15 21:14:45 momjian Exp $ */ #define POSTGRES_ECPG_INTERNAL #include "postgres_fe.h" @@ -96,6 +96,6 @@ ecpg_dynamic_type(Oid type) case NUMERICOID: return SQL3_NUMERIC; /* numeric */ default: - return -(int)type; + return -(int) type; } } diff --git a/src/interfaces/ecpg/include/ecpg-pthread-win32.h b/src/interfaces/ecpg/include/ecpg-pthread-win32.h index 991a33dcf1..dce8c38715 100644 --- a/src/interfaces/ecpg/include/ecpg-pthread-win32.h +++ b/src/interfaces/ecpg/include/ecpg-pthread-win32.h @@ -1,4 +1,4 @@ -/* $PostgreSQL: pgsql/src/interfaces/ecpg/include/ecpg-pthread-win32.h,v 1.4 2007/10/03 08:55:23 meskes Exp $ */ +/* $PostgreSQL: pgsql/src/interfaces/ecpg/include/ecpg-pthread-win32.h,v 1.5 2007/11/15 21:14:45 momjian Exp $ */ /* * pthread mapping macros for win32 native thread implementation */ @@ -10,7 +10,6 @@ #ifndef WIN32 #include <pthread.h> - #else typedef struct pthread_mutex_t @@ -19,14 +18,14 @@ typedef struct pthread_mutex_t LONG initlock; } pthread_mutex_t; -typedef DWORD pthread_key_t; -typedef bool pthread_once_t; +typedef DWORD pthread_key_t; +typedef bool pthread_once_t; #define PTHREAD_MUTEX_INITIALIZER { NULL, 0 } #define PTHREAD_ONCE_INIT false -void win32_pthread_mutex(volatile pthread_mutex_t *mutex); -void win32_pthread_once(volatile pthread_once_t *once, void (*fn)(void)); +void win32_pthread_mutex(volatile pthread_mutex_t *mutex); +void win32_pthread_once(volatile pthread_once_t *once, void (*fn) (void)); #define pthread_mutex_lock(mutex) \ do { \ @@ -53,9 +52,7 @@ void win32_pthread_once(volatile pthread_once_t *once, void (*fn)(void)); if (!*(once)) \ win32_pthread_once((once), (fn)); \ } while(0) +#endif /* WIN32 */ +#endif /* ENABLE_THREAD_SAFETY */ -#endif /* WIN32 */ - -#endif /* ENABLE_THREAD_SAFETY */ - -#endif /* _ECPG_PTHREAD_WIN32_H */ +#endif /* _ECPG_PTHREAD_WIN32_H */ diff --git a/src/interfaces/ecpg/pgtypeslib/datetime.c b/src/interfaces/ecpg/pgtypeslib/datetime.c index 70128d1802..3910859d34 100644 --- a/src/interfaces/ecpg/pgtypeslib/datetime.c +++ b/src/interfaces/ecpg/pgtypeslib/datetime.c @@ -1,4 +1,4 @@ -/* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/datetime.c,v 1.33 2007/08/14 10:01:52 meskes Exp $ */ +/* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/datetime.c,v 1.34 2007/11/15 21:14:45 momjian Exp $ */ #include "postgres_fe.h" @@ -75,7 +75,7 @@ PGTYPESdate_from_asc(char *str, char **endptr) } if (ParseDateTime(str, lowstr, field, ftype, MAXDATEFIELDS, &nf, ptr) != 0 || - DecodeDateTime(field, ftype, nf, &dtype, tm, &fsec, EuroDates) != 0) + DecodeDateTime(field, ftype, nf, &dtype, tm, &fsec, EuroDates) != 0) { errno = PGTYPES_DATE_BAD_DATE; return INT_MIN; diff --git a/src/interfaces/ecpg/pgtypeslib/dt.h b/src/interfaces/ecpg/pgtypeslib/dt.h index c75775ffb5..47905dedfe 100644 --- a/src/interfaces/ecpg/pgtypeslib/dt.h +++ b/src/interfaces/ecpg/pgtypeslib/dt.h @@ -1,4 +1,4 @@ -/* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/dt.h,v 1.38 2007/08/22 08:20:58 meskes Exp $ */ +/* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/dt.h,v 1.39 2007/11/15 21:14:45 momjian Exp $ */ #ifndef DT_H #define DT_H @@ -310,24 +310,24 @@ do { \ #define TIMESTAMP_IS_NOEND(j) ((j) == DT_NOEND) #define TIMESTAMP_NOT_FINITE(j) (TIMESTAMP_IS_NOBEGIN(j) || TIMESTAMP_IS_NOEND(j)) -int DecodeTimeOnly(char **, int *, int, int *, struct tm *, fsec_t *, int *); -int DecodeInterval(char **, int *, int, int *, struct tm *, fsec_t *); -int DecodeTime(char *, int, int *, struct tm *, fsec_t *); -int EncodeTimeOnly(struct tm *, fsec_t, int *, int, char *); -int EncodeDateTime(struct tm *, fsec_t, int *, char **, int, char *, bool); -int EncodeInterval(struct tm *, fsec_t, int, char *); -int tm2timestamp(struct tm *, fsec_t, int *, timestamp *); -int DecodeUnits(int field, char *lowtoken, int *val); -bool CheckDateTokenTables(void); -int EncodeDateOnly(struct tm *, int, char *, bool); -void GetEpochTime(struct tm *); -int ParseDateTime(char *, char *, char **, int *, int, int *, char **); -int DecodeDateTime(char **, int *, int, int *, struct tm *, fsec_t *, bool); -void j2date(int, int *, int *, int *); -void GetCurrentDateTime(struct tm *); -int date2j(int, int, int); -void TrimTrailingZeros(char *); -void dt2time(double, int *, int *, int *, fsec_t *); +int DecodeTimeOnly(char **, int *, int, int *, struct tm *, fsec_t *, int *); +int DecodeInterval(char **, int *, int, int *, struct tm *, fsec_t *); +int DecodeTime(char *, int, int *, struct tm *, fsec_t *); +int EncodeTimeOnly(struct tm *, fsec_t, int *, int, char *); +int EncodeDateTime(struct tm *, fsec_t, int *, char **, int, char *, bool); +int EncodeInterval(struct tm *, fsec_t, int, char *); +int tm2timestamp(struct tm *, fsec_t, int *, timestamp *); +int DecodeUnits(int field, char *lowtoken, int *val); +bool CheckDateTokenTables(void); +int EncodeDateOnly(struct tm *, int, char *, bool); +void GetEpochTime(struct tm *); +int ParseDateTime(char *, char *, char **, int *, int, int *, char **); +int DecodeDateTime(char **, int *, int, int *, struct tm *, fsec_t *, bool); +void j2date(int, int *, int *, int *); +void GetCurrentDateTime(struct tm *); +int date2j(int, int, int); +void TrimTrailingZeros(char *); +void dt2time(double, int *, int *, int *, fsec_t *); extern char *pgtypes_date_weekdays_short[]; extern char *pgtypes_date_months[]; diff --git a/src/interfaces/ecpg/pgtypeslib/dt_common.c b/src/interfaces/ecpg/pgtypeslib/dt_common.c index 212ca0eebb..62a90352d4 100644 --- a/src/interfaces/ecpg/pgtypeslib/dt_common.c +++ b/src/interfaces/ecpg/pgtypeslib/dt_common.c @@ -1,4 +1,4 @@ -/* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/dt_common.c,v 1.43 2007/09/30 11:38:48 meskes Exp $ */ +/* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/dt_common.c,v 1.44 2007/11/15 21:14:45 momjian Exp $ */ #include "postgres_fe.h" @@ -214,7 +214,7 @@ static datetkn datetktbl[] = { {"irkst", DTZ, POS(36)}, /* Irkutsk Summer Time */ {"irkt", TZ, POS(32)}, /* Irkutsk Time */ {"irt", TZ, POS(14)}, /* Iran Time */ - {"isodow", RESERV, DTK_ISODOW}, /* ISO day of week, Sunday == 7 */ + {"isodow", RESERV, DTK_ISODOW}, /* ISO day of week, Sunday == 7 */ #if 0 isst #endif @@ -1816,7 +1816,7 @@ ParseDateTime(char *timestr, char *lowstr, */ int DecodeDateTime(char **field, int *ftype, int nf, - int *dtype, struct tm * tm, fsec_t *fsec, bool EuroDates) + int *dtype, struct tm * tm, fsec_t *fsec, bool EuroDates) { int fmask = 0, tmask, @@ -1829,7 +1829,7 @@ DecodeDateTime(char **field, int *ftype, int nf, int is2digits = FALSE; int bc = FALSE; int t = 0; - int *tzp = &t; + int *tzp = &t; /*** * We'll insist on at least all of the date fields, but initialize the @@ -2377,12 +2377,13 @@ DecodeDateTime(char **field, int *ftype, int nf, if (tm->tm_mday < 1 || tm->tm_mday > day_tab[isleap(tm->tm_year)][tm->tm_mon - 1]) return -1; - /* backend tried to find local timezone here - * but we don't use the result afterwards anyway - * so we only check for this error: - * daylight savings time modifier but no standard timezone? */ + /* + * backend tried to find local timezone here but we don't use the + * result afterwards anyway so we only check for this error: daylight + * savings time modifier but no standard timezone? + */ if ((fmask & DTK_DATE_M) == DTK_DATE_M && tzp != NULL && !(fmask & DTK_M(TZ)) && (fmask & DTK_M(DTZMOD))) - return -1; + return -1; } return 0; diff --git a/src/interfaces/ecpg/preproc/ecpg.c b/src/interfaces/ecpg/preproc/ecpg.c index 1dbe4d4ef4..4401c96e4d 100644 --- a/src/interfaces/ecpg/preproc/ecpg.c +++ b/src/interfaces/ecpg/preproc/ecpg.c @@ -1,4 +1,4 @@ -/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/ecpg.c,v 1.101 2007/08/29 13:58:13 meskes Exp $ */ +/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/ecpg.c,v 1.102 2007/11/15 21:14:45 momjian Exp $ */ /* New main for ecpg, the PostgreSQL embedded SQL precompiler. */ /* (C) Michael Meskes <meskes@postgresql.org> Feb 5th, 1998 */ @@ -22,7 +22,7 @@ int ret_value = 0, regression_mode = false, auto_prepare = false; -char *output_filename; +char *output_filename; enum COMPAT_MODE compat = ECPG_COMPAT_PGSQL; @@ -126,7 +126,7 @@ main(int argc, char *const argv[]) {"help", no_argument, NULL, ECPG_GETOPT_LONG_HELP}, {"version", no_argument, NULL, ECPG_GETOPT_LONG_VERSION}, {"regression", no_argument, NULL, ECPG_GETOPT_LONG_REGRESSION}, - { NULL, 0, NULL, 0} + {NULL, 0, NULL, 0} }; int fnr, @@ -154,12 +154,14 @@ main(int argc, char *const argv[]) case ECPG_GETOPT_LONG_HELP: help(progname); exit(0); - /* - * -? is an alternative spelling of --help. However it is also - * returned by getopt_long for unknown options. We can distinguish - * both cases by means of the optopt variable which is set to 0 if - * it was really -? and not an unknown option character. - */ + + /* + * -? is an alternative spelling of --help. However it is also + * returned by getopt_long for unknown options. We can + * distinguish both cases by means of the optopt variable + * which is set to 0 if it was really -? and not an unknown + * option character. + */ case '?': if (optopt == 0) { @@ -177,7 +179,7 @@ main(int argc, char *const argv[]) else yyout = fopen(output_filename, PG_BINARY_W); - if (yyout == NULL) + if (yyout == NULL) { fprintf(stderr, "%s: could not open file \"%s\": %s\n", progname, output_filename, strerror(errno)); @@ -280,7 +282,7 @@ main(int argc, char *const argv[]) /* after the options there must not be anything but filenames */ for (fnr = optind; fnr < argc; fnr++) { - char *ptr2ext; + char *ptr2ext; /* If argv[fnr] is "-" we have to read from stdin */ if (strcmp(argv[fnr], "-") == 0) @@ -430,7 +432,7 @@ main(int argc, char *const argv[]) /* we need several includes */ /* but not if we are in header mode */ - if (regression_mode) + if (regression_mode) fprintf(yyout, "/* Processed by ecpg (regression mode) */\n"); else fprintf(yyout, "/* Processed by ecpg (%d.%d.%d) */\n", MAJOR_VERSION, MINOR_VERSION, PATCHLEVEL); @@ -446,7 +448,7 @@ main(int argc, char *const argv[]) fprintf(yyout, "/* End of automatic include section */\n"); } - if (regression_mode) + if (regression_mode) fprintf(yyout, "#define ECPGdebug(X,Y) ECPGdebug((X)+100,(Y))\n"); output_line_number(); diff --git a/src/interfaces/ecpg/preproc/ecpg_keywords.c b/src/interfaces/ecpg/preproc/ecpg_keywords.c index 6155bc1f73..98179fe39f 100644 --- a/src/interfaces/ecpg/preproc/ecpg_keywords.c +++ b/src/interfaces/ecpg/preproc/ecpg_keywords.c @@ -4,7 +4,7 @@ * lexical token lookup for reserved words in postgres embedded SQL * * IDENTIFICATION - * $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/ecpg_keywords.c,v 1.36 2007/08/22 08:20:58 meskes Exp $ + * $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/ecpg_keywords.c,v 1.37 2007/11/15 21:14:45 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -63,4 +63,3 @@ static const ScanKeyword ScanECPGKeywords[] = { {"var", SQL_VAR}, {"whenever", SQL_WHENEVER}, }; - diff --git a/src/interfaces/ecpg/preproc/extern.h b/src/interfaces/ecpg/preproc/extern.h index ecd646100e..c9097c87ee 100644 --- a/src/interfaces/ecpg/preproc/extern.h +++ b/src/interfaces/ecpg/preproc/extern.h @@ -1,4 +1,4 @@ -/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/extern.h,v 1.69 2007/08/22 08:20:58 meskes Exp $ */ +/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/extern.h,v 1.70 2007/11/15 21:14:45 momjian Exp $ */ #ifndef _ECPG_PREPROC_EXTERN_H #define _ECPG_PREPROC_EXTERN_H @@ -97,11 +97,11 @@ extern void remove_typedefs(int); extern void remove_variables(int); extern struct variable *new_variable(const char *, struct ECPGtype *, int); extern const ScanKeyword *ScanKeywordLookup(char *text); -extern const ScanKeyword *DoLookup(char *, const ScanKeyword *,const ScanKeyword *); +extern const ScanKeyword *DoLookup(char *, const ScanKeyword *, const ScanKeyword *); extern void scanner_init(const char *); extern void parser_init(void); extern void scanner_finish(void); -extern int filtered_base_yylex(void); +extern int filtered_base_yylex(void); /* return codes */ diff --git a/src/interfaces/ecpg/preproc/keywords.c b/src/interfaces/ecpg/preproc/keywords.c index 62dffb74af..d6e5c3f647 100644 --- a/src/interfaces/ecpg/preproc/keywords.c +++ b/src/interfaces/ecpg/preproc/keywords.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/keywords.c,v 1.83 2007/10/10 06:33:17 meskes Exp $ + * $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/keywords.c,v 1.84 2007/11/15 21:14:45 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -474,4 +474,3 @@ ScanKeywordLookup(char *text) return DoLookup(word, &ScanECPGKeywords[0], endof(ScanECPGKeywords) - 1); } - diff --git a/src/interfaces/ecpg/preproc/output.c b/src/interfaces/ecpg/preproc/output.c index 2a4a638004..74da49a0d2 100644 --- a/src/interfaces/ecpg/preproc/output.c +++ b/src/interfaces/ecpg/preproc/output.c @@ -1,4 +1,4 @@ -/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/output.c,v 1.22 2007/09/26 10:57:00 meskes Exp $ */ +/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/output.c,v 1.23 2007/11/15 21:14:45 momjian Exp $ */ #include "postgres_fe.h" @@ -130,7 +130,7 @@ output_statement(char *stmt, int whenever_mode, enum ECPG_statement_type st) fputs("ECPGt_EORT);", yyout); reset_variables(); - whenever_action(whenever_mode|2); + whenever_action(whenever_mode | 2); free(stmt); if (connection != NULL) free(connection); @@ -153,7 +153,8 @@ output_prepare_statement(char *name, char *stmt) void output_deallocate_prepare_statement(char *name) { - const char* con = connection ? connection : "NULL"; + const char *con = connection ? connection : "NULL"; + if (strcmp(name, "all")) { fprintf(yyout, "{ ECPGdeallocate(__LINE__, %d, %s, ", compat, con); @@ -172,10 +173,12 @@ output_deallocate_prepare_statement(char *name) static void output_escaped_str(char *str, bool quoted) { - int i = 0; - int len = strlen(str); - - if (quoted && str[0] == '\"' && str[len-1] == '\"') /* do not escape quotes at beginning and end if quoted string */ + int i = 0; + int len = strlen(str); + + if (quoted && str[0] == '\"' && str[len - 1] == '\"') /* do not escape quotes + * at beginning and end + * if quoted string */ { i = 1; len--; @@ -200,6 +203,6 @@ output_escaped_str(char *str, bool quoted) fputc(str[i], yyout); } - if (quoted && str[0] == '\"' && str[len] == '\"') + if (quoted && str[0] == '\"' && str[len] == '\"') fputs("\"", yyout); } diff --git a/src/interfaces/ecpg/preproc/parser.c b/src/interfaces/ecpg/preproc/parser.c index 21fd2dd0a5..519973277c 100644 --- a/src/interfaces/ecpg/preproc/parser.c +++ b/src/interfaces/ecpg/preproc/parser.c @@ -14,7 +14,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/parser.c,v 1.1 2007/10/26 14:17:53 tgl Exp $ + * $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/parser.c,v 1.2 2007/11/15 21:14:45 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -25,8 +25,8 @@ #include "preproc.h" -static bool have_lookahead; /* is lookahead info valid? */ -static int lookahead_token; /* one-token lookahead */ +static bool have_lookahead; /* is lookahead info valid? */ +static int lookahead_token; /* one-token lookahead */ static YYSTYPE lookahead_yylval; /* yylval for lookahead token */ static YYLTYPE lookahead_yylloc; /* yylloc for lookahead token */ @@ -67,6 +67,7 @@ filtered_base_yylex(void) switch (cur_token) { case NULLS_P: + /* * NULLS FIRST and NULLS LAST must be reduced to one token */ @@ -95,6 +96,7 @@ filtered_base_yylex(void) break; case WITH: + /* * WITH CASCADED, LOCAL, or CHECK must be reduced to one token * diff --git a/src/interfaces/ecpg/preproc/type.c b/src/interfaces/ecpg/preproc/type.c index 67ea33a0a0..9a3f3ef7a3 100644 --- a/src/interfaces/ecpg/preproc/type.c +++ b/src/interfaces/ecpg/preproc/type.c @@ -1,4 +1,4 @@ -/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/type.c,v 1.75 2007/10/03 11:11:12 meskes Exp $ */ +/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/type.c,v 1.76 2007/11/15 21:14:45 momjian Exp $ */ #include "postgres_fe.h" @@ -101,7 +101,7 @@ ECPGmake_simple_type(enum ECPGttype type, char *size, int lineno) ne->size = size; ne->u.element = NULL; ne->struct_sizeof = NULL; - ne->lineno = lineno; /* only needed for varchar */ + ne->lineno = lineno; /* only needed for varchar */ return ne; } @@ -259,7 +259,7 @@ ECPGdump_a_type(FILE *o, const char *name, struct ECPGtype * type, ECPGdump_a_simple(o, name, type->u.element->type, - type->u.element->size, type->size, NULL, prefix, type->lineno); + type->u.element->size, type->size, NULL, prefix, type->lineno); if (ind_type != NULL) { @@ -328,7 +328,7 @@ ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype type, else { char *variable = (char *) mm_alloc(strlen(name) + ((prefix == NULL) ? 0 : strlen(prefix)) + 4); - char *offset = (char *) mm_alloc(strlen(name) + strlen("sizeof(struct varchar_)") + 1 + strlen(varcharsize)+ sizeof(int) * CHAR_BIT * 10 / 3); + char *offset = (char *) mm_alloc(strlen(name) + strlen("sizeof(struct varchar_)") + 1 + strlen(varcharsize) + sizeof(int) * CHAR_BIT * 10 / 3); switch (type) { diff --git a/src/interfaces/ecpg/preproc/type.h b/src/interfaces/ecpg/preproc/type.h index eff94b40d1..94c1e56f53 100644 --- a/src/interfaces/ecpg/preproc/type.h +++ b/src/interfaces/ecpg/preproc/type.h @@ -25,7 +25,7 @@ struct ECPGtype struct ECPGstruct_member *members; /* A pointer to a list of * members. */ } u; - int lineno; + int lineno; }; /* Everything is malloced. */ @@ -97,9 +97,9 @@ struct su_symbol struct prep { - char *name; - char *stmt; - char *type; + char *name; + char *stmt; + char *type; }; struct this_type diff --git a/src/interfaces/ecpg/test/pg_regress_ecpg.c b/src/interfaces/ecpg/test/pg_regress_ecpg.c index ae0aa1c134..a24ac01e1d 100644 --- a/src/interfaces/ecpg/test/pg_regress_ecpg.c +++ b/src/interfaces/ecpg/test/pg_regress_ecpg.c @@ -11,7 +11,7 @@ * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/interfaces/ecpg/test/pg_regress_ecpg.c,v 1.2 2007/06/14 13:10:11 mha Exp $ + * $PostgreSQL: pgsql/src/interfaces/ecpg/test/pg_regress_ecpg.c,v 1.3 2007/11/15 21:14:46 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -23,13 +23,12 @@ static void ecpg_filter(const char *sourcefile, const char *outfile) { /* - * Create a filtered copy of sourcefile, replacing - * #line x "./../bla/foo.h" - * with - * #line x "foo.h" + * Create a filtered copy of sourcefile, replacing #line x + * "./../bla/foo.h" with #line x "foo.h" */ - FILE *s, *t; - char linebuf[LINEBUFSIZE]; + FILE *s, + *t; + char linebuf[LINEBUFSIZE]; s = fopen(sourcefile, "r"); if (!s) @@ -49,9 +48,10 @@ ecpg_filter(const char *sourcefile, const char *outfile) /* check for "#line " in the beginning */ if (strstr(linebuf, "#line ") == linebuf) { - char *p = strchr(linebuf, '"'); - char *n; - int plen = 1; + char *p = strchr(linebuf, '"'); + char *n; + int plen = 1; + while (*p && (*(p + plen) == '.' || strchr(p + plen, '/') != NULL)) { plen++; @@ -60,8 +60,8 @@ ecpg_filter(const char *sourcefile, const char *outfile) if (plen > 1) { n = (char *) malloc(plen); - strncpy(n, p+1, plen - 1); - n[plen-1] = '\0'; + strncpy(n, p + 1, plen - 1); + n[plen - 1] = '\0'; replace_string(linebuf, n, ""); } } @@ -78,18 +78,21 @@ ecpg_filter(const char *sourcefile, const char *outfile) static PID_TYPE ecpg_start_test(const char *testname, - _stringlist **resultfiles, - _stringlist **expectfiles, - _stringlist **tags) + _stringlist ** resultfiles, + _stringlist ** expectfiles, + _stringlist ** tags) { PID_TYPE pid; char inprg[MAXPGPATH]; char insource[MAXPGPATH]; - char *outfile_stdout, expectfile_stdout[MAXPGPATH]; - char *outfile_stderr, expectfile_stderr[MAXPGPATH]; - char *outfile_source, expectfile_source[MAXPGPATH]; + char *outfile_stdout, + expectfile_stdout[MAXPGPATH]; + char *outfile_stderr, + expectfile_stderr[MAXPGPATH]; + char *outfile_source, + expectfile_source[MAXPGPATH]; char cmd[MAXPGPATH * 3]; - char *testname_dash; + char *testname_dash; snprintf(inprg, sizeof(inprg), "%s/%s", inputdir, testname); @@ -161,11 +164,11 @@ ecpg_init(void) /* no reason to set -w for ecpg checks, except for when on windows */ if (strstr(host_platform, "-win32") || strstr(host_platform, "-mingw32")) basic_diff_opts = "-w"; - else + else basic_diff_opts = ""; if (strstr(host_platform, "-win32") || strstr(host_platform, "-mingw32")) pretty_diff_opts = "-C3 -w"; - else + else pretty_diff_opts = "-C3"; } @@ -174,4 +177,3 @@ main(int argc, char *argv[]) { return regression_main(argc, argv, ecpg_init, ecpg_start_test); } - diff --git a/src/interfaces/libpq/fe-auth.c b/src/interfaces/libpq/fe-auth.c index 69ec74c4c0..38cae4de91 100644 --- a/src/interfaces/libpq/fe-auth.c +++ b/src/interfaces/libpq/fe-auth.c @@ -7,7 +7,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/interfaces/libpq/fe-auth.c,v 1.132 2007/09/25 16:29:34 petere Exp $ + * $PostgreSQL: pgsql/src/interfaces/libpq/fe-auth.c,v 1.133 2007/11/15 21:14:46 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -139,8 +139,8 @@ pg_krb5_init(PQExpBuffer errorMessage, struct krb5_info * info) if (retval) { printfPQExpBuffer(errorMessage, - "pg_krb5_init: krb5_init_context: %s\n", - error_message(retval)); + "pg_krb5_init: krb5_init_context: %s\n", + error_message(retval)); return STATUS_ERROR; } @@ -148,8 +148,8 @@ pg_krb5_init(PQExpBuffer errorMessage, struct krb5_info * info) if (retval) { printfPQExpBuffer(errorMessage, - "pg_krb5_init: krb5_cc_default: %s\n", - error_message(retval)); + "pg_krb5_init: krb5_cc_default: %s\n", + error_message(retval)); krb5_free_context(info->pg_krb5_context); return STATUS_ERROR; } @@ -159,8 +159,8 @@ pg_krb5_init(PQExpBuffer errorMessage, struct krb5_info * info) if (retval) { printfPQExpBuffer(errorMessage, - "pg_krb5_init: krb5_cc_get_principal: %s\n", - error_message(retval)); + "pg_krb5_init: krb5_cc_get_principal: %s\n", + error_message(retval)); krb5_cc_close(info->pg_krb5_context, info->pg_krb5_ccache); krb5_free_context(info->pg_krb5_context); return STATUS_ERROR; @@ -170,8 +170,8 @@ pg_krb5_init(PQExpBuffer errorMessage, struct krb5_info * info) if (retval) { printfPQExpBuffer(errorMessage, - "pg_krb5_init: krb5_unparse_name: %s\n", - error_message(retval)); + "pg_krb5_init: krb5_unparse_name: %s\n", + error_message(retval)); krb5_free_principal(info->pg_krb5_context, info->pg_krb5_client); krb5_cc_close(info->pg_krb5_context, info->pg_krb5_ccache); krb5_free_context(info->pg_krb5_context); @@ -235,7 +235,7 @@ pg_krb5_sendauth(PGconn *conn) if (!conn->pghost) { printfPQExpBuffer(&conn->errorMessage, - "pg_krb5_sendauth: hostname must be specified for Kerberos authentication\n"); + "pg_krb5_sendauth: hostname must be specified for Kerberos authentication\n"); return STATUS_ERROR; } @@ -243,14 +243,14 @@ pg_krb5_sendauth(PGconn *conn) if (ret != STATUS_OK) return ret; - retval = krb5_sname_to_principal(info.pg_krb5_context, conn->pghost, + retval = krb5_sname_to_principal(info.pg_krb5_context, conn->pghost, conn->krbsrvname, KRB5_NT_SRV_HST, &server); if (retval) { printfPQExpBuffer(&conn->errorMessage, - "pg_krb5_sendauth: krb5_sname_to_principal: %s\n", - error_message(retval)); + "pg_krb5_sendauth: krb5_sname_to_principal: %s\n", + error_message(retval)); pg_krb5_destroy(&info); return STATUS_ERROR; } @@ -265,14 +265,14 @@ pg_krb5_sendauth(PGconn *conn) char sebuf[256]; printfPQExpBuffer(&conn->errorMessage, - libpq_gettext("could not set socket to blocking mode: %s\n"), pqStrerror(errno, sebuf, sizeof(sebuf))); + libpq_gettext("could not set socket to blocking mode: %s\n"), pqStrerror(errno, sebuf, sizeof(sebuf))); krb5_free_principal(info.pg_krb5_context, server); pg_krb5_destroy(&info); return STATUS_ERROR; } retval = krb5_sendauth(info.pg_krb5_context, &auth_context, - (krb5_pointer) & conn->sock, (char *) conn->krbsrvname, + (krb5_pointer) & conn->sock, (char *) conn->krbsrvname, info.pg_krb5_client, server, AP_OPTS_MUTUAL_REQUIRED, NULL, 0, /* no creds, use ccache instead */ @@ -284,12 +284,12 @@ pg_krb5_sendauth(PGconn *conn) #if defined(HAVE_KRB5_ERROR_TEXT_DATA) printfPQExpBuffer(&conn->errorMessage, libpq_gettext("Kerberos 5 authentication rejected: %*s\n"), - (int) err_ret->text.length, err_ret->text.data); + (int) err_ret->text.length, err_ret->text.data); #elif defined(HAVE_KRB5_ERROR_E_DATA) printfPQExpBuffer(&conn->errorMessage, libpq_gettext("Kerberos 5 authentication rejected: %*s\n"), - (int) err_ret->e_data->length, - (const char *) err_ret->e_data->data); + (int) err_ret->e_data->length, + (const char *) err_ret->e_data->data); #else #error "bogus configuration" #endif @@ -297,7 +297,7 @@ pg_krb5_sendauth(PGconn *conn) else { printfPQExpBuffer(&conn->errorMessage, - "krb5_sendauth: %s\n", error_message(retval)); + "krb5_sendauth: %s\n", error_message(retval)); } if (err_ret) @@ -314,7 +314,7 @@ pg_krb5_sendauth(PGconn *conn) printfPQExpBuffer(&conn->errorMessage, libpq_gettext("could not restore non-blocking mode on socket: %s\n"), - pqStrerror(errno, sebuf, sizeof(sebuf))); + pqStrerror(errno, sebuf, sizeof(sebuf))); ret = STATUS_ERROR; } pg_krb5_destroy(&info); @@ -335,7 +335,7 @@ pg_krb5_sendauth(PGconn *conn) * from src/athena/auth/krb5/src/lib/gssapi/generic/gssapi_generic.c */ static const gss_OID_desc GSS_C_NT_HOSTBASED_SERVICE_desc = - {10, (void *)"\x2a\x86\x48\x86\xf7\x12\x01\x02\x01\x04"}; +{10, (void *) "\x2a\x86\x48\x86\xf7\x12\x01\x02\x01\x04"}; static GSS_DLLIMP gss_OID GSS_C_NT_HOSTBASED_SERVICE = &GSS_C_NT_HOSTBASED_SERVICE_desc; #endif @@ -345,22 +345,23 @@ static GSS_DLLIMP gss_OID GSS_C_NT_HOSTBASED_SERVICE = &GSS_C_NT_HOSTBASED_SERVI */ static void pg_GSS_error_int(char *mprefix, char *msg, int msglen, - OM_uint32 stat, int type) + OM_uint32 stat, int type) { - int curlen = 0; - OM_uint32 lmaj_s, lmin_s; - gss_buffer_desc lmsg; - OM_uint32 msg_ctx = 0; + int curlen = 0; + OM_uint32 lmaj_s, + lmin_s; + gss_buffer_desc lmsg; + OM_uint32 msg_ctx = 0; - do + do { - lmaj_s = gss_display_status(&lmin_s, stat, type, - GSS_C_NO_OID, &msg_ctx, &lmsg); + lmaj_s = gss_display_status(&lmin_s, stat, type, + GSS_C_NO_OID, &msg_ctx, &lmsg); if (curlen < msglen) { snprintf(msg + curlen, msglen - curlen, "%s: %s\n", - mprefix, (char *)lmsg.value); + mprefix, (char *) lmsg.value); curlen += lmsg.length; } gss_release_buffer(&lmin_s, &lmsg); @@ -373,42 +374,44 @@ pg_GSS_error_int(char *mprefix, char *msg, int msglen, */ static void pg_GSS_error(char *mprefix, PGconn *conn, - OM_uint32 maj_stat, OM_uint32 min_stat) + OM_uint32 maj_stat, OM_uint32 min_stat) { - int mlen; + int mlen; /* Fetch major error codes */ - pg_GSS_error_int(mprefix, conn->errorMessage.data, - conn->errorMessage.maxlen, maj_stat, GSS_C_GSS_CODE); + pg_GSS_error_int(mprefix, conn->errorMessage.data, + conn->errorMessage.maxlen, maj_stat, GSS_C_GSS_CODE); mlen = strlen(conn->errorMessage.data); /* If there is room left, try to add the minor codes as well */ if (mlen < conn->errorMessage.maxlen - 1) - pg_GSS_error_int(mprefix, conn->errorMessage.data + mlen, + pg_GSS_error_int(mprefix, conn->errorMessage.data + mlen, conn->errorMessage.maxlen - mlen, min_stat, GSS_C_MECH_CODE); } -/* +/* * Continue GSS authentication with next token as needed. */ static int pg_GSS_continue(PGconn *conn) { - OM_uint32 maj_stat, min_stat, lmin_s; + OM_uint32 maj_stat, + min_stat, + lmin_s; maj_stat = gss_init_sec_context(&min_stat, - GSS_C_NO_CREDENTIAL, - &conn->gctx, - conn->gtarg_nam, - GSS_C_NO_OID, - GSS_C_MUTUAL_FLAG, - 0, - GSS_C_NO_CHANNEL_BINDINGS, - (conn->gctx==GSS_C_NO_CONTEXT)?GSS_C_NO_BUFFER:&conn->ginbuf, - NULL, - &conn->goutbuf, - NULL, - NULL); + GSS_C_NO_CREDENTIAL, + &conn->gctx, + conn->gtarg_nam, + GSS_C_NO_OID, + GSS_C_MUTUAL_FLAG, + 0, + GSS_C_NO_CHANNEL_BINDINGS, + (conn->gctx == GSS_C_NO_CONTEXT) ? GSS_C_NO_BUFFER : &conn->ginbuf, + NULL, + &conn->goutbuf, + NULL, + NULL); if (conn->gctx != GSS_C_NO_CONTEXT) { @@ -420,13 +423,13 @@ pg_GSS_continue(PGconn *conn) if (conn->goutbuf.length != 0) { /* - * GSS generated data to send to the server. We don't care if it's - * the first or subsequent packet, just send the same kind of - * password packet. + * GSS generated data to send to the server. We don't care if it's the + * first or subsequent packet, just send the same kind of password + * packet. */ if (pqPacketSend(conn, 'p', - conn->goutbuf.value, conn->goutbuf.length) - != STATUS_OK) + conn->goutbuf.value, conn->goutbuf.length) + != STATUS_OK) { gss_release_buffer(&lmin_s, &conn->goutbuf); return STATUS_ERROR; @@ -437,8 +440,8 @@ pg_GSS_continue(PGconn *conn) if (maj_stat != GSS_S_COMPLETE && maj_stat != GSS_S_CONTINUE_NEEDED) { pg_GSS_error(libpq_gettext("GSSAPI continuation error"), - conn, - maj_stat, min_stat); + conn, + maj_stat, min_stat); gss_release_name(&lmin_s, &conn->gtarg_nam); if (conn->gctx) gss_delete_sec_context(&lmin_s, &conn->gctx, GSS_C_NO_BUFFER); @@ -451,54 +454,55 @@ pg_GSS_continue(PGconn *conn) return STATUS_OK; } -/* +/* * Send initial GSS authentication token */ static int pg_GSS_startup(PGconn *conn) { - OM_uint32 maj_stat, min_stat; + OM_uint32 maj_stat, + min_stat; int maxlen; - gss_buffer_desc temp_gbuf; + gss_buffer_desc temp_gbuf; if (conn->gctx) { printfPQExpBuffer(&conn->errorMessage, - libpq_gettext("duplicate GSS authentication request\n")); + libpq_gettext("duplicate GSS authentication request\n")); return STATUS_ERROR; } /* - * Import service principal name so the proper ticket can be - * acquired by the GSSAPI system. + * Import service principal name so the proper ticket can be acquired by + * the GSSAPI system. */ maxlen = NI_MAXHOST + strlen(conn->krbsrvname) + 2; - temp_gbuf.value = (char*)malloc(maxlen); - snprintf(temp_gbuf.value, maxlen, "%s@%s", - conn->krbsrvname, conn->pghost); + temp_gbuf.value = (char *) malloc(maxlen); + snprintf(temp_gbuf.value, maxlen, "%s@%s", + conn->krbsrvname, conn->pghost); temp_gbuf.length = strlen(temp_gbuf.value); maj_stat = gss_import_name(&min_stat, &temp_gbuf, - GSS_C_NT_HOSTBASED_SERVICE, &conn->gtarg_nam); + GSS_C_NT_HOSTBASED_SERVICE, &conn->gtarg_nam); free(temp_gbuf.value); if (maj_stat != GSS_S_COMPLETE) { - pg_GSS_error(libpq_gettext("GSSAPI name import error"), - conn, - maj_stat, min_stat); + pg_GSS_error(libpq_gettext("GSSAPI name import error"), + conn, + maj_stat, min_stat); return STATUS_ERROR; } /* - * Initial packet is the same as a continuation packet with - * no initial context. + * Initial packet is the same as a continuation packet with no initial + * context. */ conn->gctx = GSS_C_NO_CONTEXT; return pg_GSS_continue(conn); } -#endif /* ENABLE_GSS */ +#endif /* ENABLE_GSS */ #ifdef ENABLE_SSPI @@ -509,30 +513,30 @@ pg_GSS_startup(PGconn *conn) static void pg_SSPI_error(PGconn *conn, char *mprefix, SECURITY_STATUS r) { - char sysmsg[256]; + char sysmsg[256]; if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, r, 0, sysmsg, sizeof(sysmsg), NULL) == 0) printfPQExpBuffer(&conn->errorMessage, "%s: sspi error %x", - mprefix, (unsigned int)r); + mprefix, (unsigned int) r); else printfPQExpBuffer(&conn->errorMessage, "%s: %s (%x)", - mprefix, sysmsg, (unsigned int)r); + mprefix, sysmsg, (unsigned int) r); } -/* +/* * Continue SSPI authentication with next token as needed. */ static int pg_SSPI_continue(PGconn *conn) { - SECURITY_STATUS r; - CtxtHandle newContext; - ULONG contextAttr; - SecBufferDesc inbuf; - SecBufferDesc outbuf; - SecBuffer OutBuffers[1]; - SecBuffer InBuffers[1]; + SECURITY_STATUS r; + CtxtHandle newContext; + ULONG contextAttr; + SecBufferDesc inbuf; + SecBufferDesc outbuf; + SecBuffer OutBuffers[1]; + SecBuffer InBuffers[1]; if (conn->sspictx != NULL) { @@ -556,18 +560,18 @@ pg_SSPI_continue(PGconn *conn) outbuf.ulVersion = SECBUFFER_VERSION; r = InitializeSecurityContext(conn->sspicred, - conn->sspictx, - conn->sspitarget, - ISC_REQ_ALLOCATE_MEMORY, - 0, - SECURITY_NETWORK_DREP, - (conn->sspictx == NULL)?NULL:&inbuf, - 0, - &newContext, - &outbuf, - &contextAttr, - NULL); - + conn->sspictx, + conn->sspitarget, + ISC_REQ_ALLOCATE_MEMORY, + 0, + SECURITY_NETWORK_DREP, + (conn->sspictx == NULL) ? NULL : &inbuf, + 0, + &newContext, + &outbuf, + &contextAttr, + NULL); + if (r != SEC_E_OK && r != SEC_I_CONTINUE_NEEDED) { pg_SSPI_error(conn, libpq_gettext("SSPI continuation error"), r); @@ -589,8 +593,8 @@ pg_SSPI_continue(PGconn *conn) else { /* - * On subsequent runs when we had data to send, free buffers that contained - * this data. + * On subsequent runs when we had data to send, free buffers that + * contained this data. */ free(conn->ginbuf.value); conn->ginbuf.value = NULL; @@ -598,23 +602,24 @@ pg_SSPI_continue(PGconn *conn) } /* - * If SSPI returned any data to be sent to the server (as it normally would), - * send this data as a password packet. + * If SSPI returned any data to be sent to the server (as it normally + * would), send this data as a password packet. */ if (outbuf.cBuffers > 0) { if (outbuf.cBuffers != 1) { /* - * This should never happen, at least not for Kerberos authentication. Keep check - * in case it shows up with other authentication methods later. + * This should never happen, at least not for Kerberos + * authentication. Keep check in case it shows up with other + * authentication methods later. */ printfPQExpBuffer(&conn->errorMessage, "SSPI returned invalid number of output buffers\n"); return STATUS_ERROR; } if (pqPacketSend(conn, 'p', - outbuf.pBuffers[0].pvBuffer, outbuf.pBuffers[0].cbBuffer)) + outbuf.pBuffers[0].pvBuffer, outbuf.pBuffers[0].cbBuffer)) { FreeContextBuffer(outbuf.pBuffers[0].pvBuffer); return STATUS_ERROR; @@ -626,7 +631,7 @@ pg_SSPI_continue(PGconn *conn) return STATUS_OK; } -/* +/* * Send initial SSPI authentication token. * If use_negotiate is 0, use kerberos authentication package which is * compatible with Unix. If use_negotiate is 1, use the negotiate package @@ -635,8 +640,8 @@ pg_SSPI_continue(PGconn *conn) static int pg_SSPI_startup(PGconn *conn, int use_negotiate) { - SECURITY_STATUS r; - TimeStamp expire; + SECURITY_STATUS r; + TimeStamp expire; conn->sspictx = NULL; @@ -650,7 +655,7 @@ pg_SSPI_startup(PGconn *conn, int use_negotiate) return STATUS_ERROR; } - r = AcquireCredentialsHandle(NULL, use_negotiate?"negotiate":"kerberos", SECPKG_CRED_OUTBOUND, NULL, NULL, NULL, NULL, conn->sspicred, &expire); + r = AcquireCredentialsHandle(NULL, use_negotiate ? "negotiate" : "kerberos", SECPKG_CRED_OUTBOUND, NULL, NULL, NULL, NULL, conn->sspicred, &expire); if (r != SEC_E_OK) { pg_SSPI_error(conn, "acquire credentials failed", r); @@ -660,16 +665,16 @@ pg_SSPI_startup(PGconn *conn, int use_negotiate) } /* - * Compute target principal name. SSPI has a different format from GSSAPI, but - * not more complex. We can skip the @REALM part, because Windows will fill that - * in for us automatically. + * Compute target principal name. SSPI has a different format from GSSAPI, + * but not more complex. We can skip the @REALM part, because Windows will + * fill that in for us automatically. */ if (conn->pghost == NULL) { printfPQExpBuffer(&conn->errorMessage, libpq_gettext("host name must be specified\n")); return STATUS_ERROR; } - conn->sspitarget = malloc(strlen(conn->krbsrvname)+strlen(conn->pghost)+2); + conn->sspitarget = malloc(strlen(conn->krbsrvname) + strlen(conn->pghost) + 2); if (!conn->sspitarget) { printfPQExpBuffer(&conn->errorMessage, libpq_gettext("out of memory\n")); @@ -685,7 +690,7 @@ pg_SSPI_startup(PGconn *conn, int use_negotiate) return pg_SSPI_continue(conn); } -#endif /* ENABLE_SSPI */ +#endif /* ENABLE_SSPI */ /* * Respond to AUTH_REQ_SCM_CREDS challenge. @@ -738,14 +743,14 @@ pg_local_sendauth(PGconn *conn) char sebuf[256]; printfPQExpBuffer(&conn->errorMessage, - "pg_local_sendauth: sendmsg: %s\n", - pqStrerror(errno, sebuf, sizeof(sebuf))); + "pg_local_sendauth: sendmsg: %s\n", + pqStrerror(errno, sebuf, sizeof(sebuf))); return STATUS_ERROR; } return STATUS_OK; #else printfPQExpBuffer(&conn->errorMessage, - libpq_gettext("SCM_CRED authentication method not supported\n")); + libpq_gettext("SCM_CRED authentication method not supported\n")); return STATUS_ERROR; #endif } @@ -850,14 +855,17 @@ pg_fe_sendauth(AuthRequest areq, PGconn *conn) #if defined(ENABLE_GSS) || defined(ENABLE_SSPI) case AUTH_REQ_GSS: { - int r; + int r; + pglock_thread(); + /* * If we have both GSS and SSPI support compiled in, use SSPI - * support by default. This is overridable by a connection string parameter. - * Note that when using SSPI we still leave the negotiate parameter off, - * since we want SSPI to use the GSSAPI kerberos protocol. For actual - * SSPI negotiate protocol, we use AUTH_REQ_SSPI. + * support by default. This is overridable by a connection + * string parameter. Note that when using SSPI we still leave + * the negotiate parameter off, since we want SSPI to use the + * GSSAPI kerberos protocol. For actual SSPI negotiate + * protocol, we use AUTH_REQ_SSPI. */ #if defined(ENABLE_GSS) && defined(ENABLE_SSPI) if (conn->gsslib && (pg_strcasecmp(conn->gsslib, "gssapi") == 0)) @@ -881,7 +889,8 @@ pg_fe_sendauth(AuthRequest areq, PGconn *conn) case AUTH_REQ_GSS_CONT: { - int r; + int r; + pglock_thread(); #if defined(ENABLE_GSS) && defined(ENABLE_SSPI) if (conn->usesspi) @@ -902,21 +911,21 @@ pg_fe_sendauth(AuthRequest areq, PGconn *conn) pgunlock_thread(); } break; - #else case AUTH_REQ_GSS: case AUTH_REQ_GSS_CONT: printfPQExpBuffer(&conn->errorMessage, - libpq_gettext("GSSAPI authentication not supported\n")); + libpq_gettext("GSSAPI authentication not supported\n")); return STATUS_ERROR; #endif #ifdef ENABLE_SSPI case AUTH_REQ_SSPI: - /* + + /* * SSPI has it's own startup message so libpq can decide which - * method to use. Indicate to pg_SSPI_startup that we want - * SSPI negotiation instead of Kerberos. + * method to use. Indicate to pg_SSPI_startup that we want SSPI + * negotiation instead of Kerberos. */ pglock_thread(); if (pg_SSPI_startup(conn, 1) != STATUS_OK) @@ -930,7 +939,7 @@ pg_fe_sendauth(AuthRequest areq, PGconn *conn) #else case AUTH_REQ_SSPI: printfPQExpBuffer(&conn->errorMessage, - libpq_gettext("SSPI authentication not supported\n")); + libpq_gettext("SSPI authentication not supported\n")); return STATUS_ERROR; #endif @@ -938,10 +947,10 @@ pg_fe_sendauth(AuthRequest areq, PGconn *conn) case AUTH_REQ_MD5: case AUTH_REQ_CRYPT: case AUTH_REQ_PASSWORD: - if (conn->pgpass == NULL || *conn->pgpass== '\0') + if (conn->pgpass == NULL || *conn->pgpass == '\0') { printfPQExpBuffer(&conn->errorMessage, - PQnoPasswordSupplied); + PQnoPasswordSupplied); return STATUS_ERROR; } if (pg_password_sendauth(conn, conn->pgpass, areq) != STATUS_OK) diff --git a/src/interfaces/libpq/fe-auth.h b/src/interfaces/libpq/fe-auth.h index b6f5253937..a912c678f9 100644 --- a/src/interfaces/libpq/fe-auth.h +++ b/src/interfaces/libpq/fe-auth.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/interfaces/libpq/fe-auth.h,v 1.27 2007/07/23 17:52:06 mha Exp $ + * $PostgreSQL: pgsql/src/interfaces/libpq/fe-auth.h,v 1.28 2007/11/15 21:14:46 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -18,7 +18,7 @@ #include "libpq-int.h" -extern int pg_fe_sendauth(AuthRequest areq, PGconn *conn); +extern int pg_fe_sendauth(AuthRequest areq, PGconn *conn); extern char *pg_fe_getauthname(PQExpBuffer errorMessage); #endif /* FE_AUTH_H */ diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c index 5318cbaccf..65033b5af5 100644 --- a/src/interfaces/libpq/fe-connect.c +++ b/src/interfaces/libpq/fe-connect.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.352 2007/10/09 15:03:27 mha Exp $ + * $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.353 2007/11/15 21:14:46 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -188,7 +188,11 @@ static const PQconninfoOption PQconninfoOptions[] = { #endif #if defined(ENABLE_GSS) && defined(ENABLE_SSPI) - /* GSSAPI and SSPI both enabled, give a way to override which is used by default */ + + /* + * GSSAPI and SSPI both enabled, give a way to override which is used by + * default + */ {"gsslib", "PGGSSLIB", NULL, NULL, "GSS-library", "", 7}, /* sizeof("gssapi") = 7 */ #endif @@ -584,36 +588,36 @@ PQsetdbLogin(const char *pghost, const char *pgport, const char *pgoptions, conn = makeEmptyPGconn(); if (conn == NULL) return NULL; - /* - * If the dbName parameter contains '=', assume it's a conninfo - * string. - */ - if (dbName && strchr(dbName,'=')) - { - if (!connectOptions1(conn, dbName)) - return conn; - } - else - { - /* - * Old-style path: first, parse an empty conninfo string in - * order to set up the same defaults that PQconnectdb() would use. - */ - if (!connectOptions1(conn, "")) - return conn; - - /* Insert dbName parameter value into struct */ - if (dbName && dbName[0] != '\0') - { - if (conn->dbName) - free(conn->dbName); - conn->dbName = strdup(dbName); - } - } - - /* - * Insert remaining parameters into struct, overriding defaults - * (as well as any conflicting data from dbName taken as a conninfo). + + /* + * If the dbName parameter contains '=', assume it's a conninfo string. + */ + if (dbName && strchr(dbName, '=')) + { + if (!connectOptions1(conn, dbName)) + return conn; + } + else + { + /* + * Old-style path: first, parse an empty conninfo string in order to + * set up the same defaults that PQconnectdb() would use. + */ + if (!connectOptions1(conn, "")) + return conn; + + /* Insert dbName parameter value into struct */ + if (dbName && dbName[0] != '\0') + { + if (conn->dbName) + free(conn->dbName); + conn->dbName = strdup(dbName); + } + } + + /* + * Insert remaining parameters into struct, overriding defaults (as well + * as any conflicting data from dbName taken as a conninfo). */ if (pghost && pghost[0] != '\0') { @@ -1507,8 +1511,8 @@ keep_going: /* We will come back to here until there is /* * Try to validate message length before using it. * Authentication requests can't be very large, although GSS - * auth requests may not be that small. Errors can be - * a little larger, but not huge. If we see a large apparent + * auth requests may not be that small. Errors can be a + * little larger, but not huge. If we see a large apparent * length in an error, it means we're really talking to a * pre-3.0-protocol server; cope. */ @@ -1672,16 +1676,18 @@ keep_going: /* We will come back to here until there is } } #if defined(ENABLE_GSS) || defined(ENABLE_SSPI) + /* * Continue GSSAPI/SSPI authentication */ if (areq == AUTH_REQ_GSS_CONT) { - int llen = msgLength - 4; + int llen = msgLength - 4; + /* - * We can be called repeatedly for the same buffer. - * Avoid re-allocating the buffer in this case - - * just re-use the old buffer. + * We can be called repeatedly for the same buffer. Avoid + * re-allocating the buffer in this case - just re-use the + * old buffer. */ if (llen != conn->ginbuf.length) { @@ -2017,6 +2023,7 @@ freePGconn(PGconn *conn) #ifdef ENABLE_GSS { OM_uint32 min_s; + if (conn->gctx) gss_delete_sec_context(&min_s, &conn->gctx, GSS_C_NO_BUFFER); if (conn->gtarg_nam) @@ -2542,7 +2549,7 @@ ldapServiceLookup(const char *purl, PQconninfoOption *options, if (pg_strncasecmp(url, LDAP_URL, strlen(LDAP_URL)) != 0) { printfPQExpBuffer(errorMessage, - libpq_gettext("invalid LDAP URL \"%s\": scheme must be ldap://\n"), purl); + libpq_gettext("invalid LDAP URL \"%s\": scheme must be ldap://\n"), purl); free(url); return 3; } @@ -2557,7 +2564,7 @@ ldapServiceLookup(const char *purl, PQconninfoOption *options, if (p == NULL || *(p + 1) == '\0' || *(p + 1) == '?') { printfPQExpBuffer(errorMessage, libpq_gettext( - "invalid LDAP URL \"%s\": missing distinguished name\n"), purl); + "invalid LDAP URL \"%s\": missing distinguished name\n"), purl); free(url); return 3; } @@ -2568,7 +2575,7 @@ ldapServiceLookup(const char *purl, PQconninfoOption *options, if ((p = strchr(dn, '?')) == NULL || *(p + 1) == '\0' || *(p + 1) == '?') { printfPQExpBuffer(errorMessage, libpq_gettext( - "invalid LDAP URL \"%s\": must have exactly one attribute\n"), purl); + "invalid LDAP URL \"%s\": must have exactly one attribute\n"), purl); free(url); return 3; } @@ -2589,7 +2596,7 @@ ldapServiceLookup(const char *purl, PQconninfoOption *options, if ((p = strchr(scopestr, '?')) == NULL || *(p + 1) == '\0' || *(p + 1) == '?') { printfPQExpBuffer(errorMessage, - libpq_gettext("invalid LDAP URL \"%s\": no filter\n"), purl); + libpq_gettext("invalid LDAP URL \"%s\": no filter\n"), purl); free(url); return 3; } @@ -2610,7 +2617,7 @@ ldapServiceLookup(const char *purl, PQconninfoOption *options, if (*portstr == '\0' || *endptr != '\0' || errno || lport < 0 || lport > 65535) { printfPQExpBuffer(errorMessage, libpq_gettext( - "invalid LDAP URL \"%s\": invalid port number\n"), purl); + "invalid LDAP URL \"%s\": invalid port number\n"), purl); free(url); return 3; } @@ -2621,7 +2628,7 @@ ldapServiceLookup(const char *purl, PQconninfoOption *options, if (strchr(attrs[0], ',') != NULL) { printfPQExpBuffer(errorMessage, libpq_gettext( - "invalid LDAP URL \"%s\": must have exactly one attribute\n"), purl); + "invalid LDAP URL \"%s\": must have exactly one attribute\n"), purl); free(url); return 3; } @@ -3735,7 +3742,11 @@ PasswordFromFile(char *hostname, char *port, char *dbname, char *username) return NULL; } #else - /* On Win32, the directory is protected, so we don't have to check the file. */ + + /* + * On Win32, the directory is protected, so we don't have to check the + * file. + */ #endif fp = fopen(pgpassfile, "r"); diff --git a/src/interfaces/libpq/fe-lobj.c b/src/interfaces/libpq/fe-lobj.c index 5bd8315193..6bb748d626 100644 --- a/src/interfaces/libpq/fe-lobj.c +++ b/src/interfaces/libpq/fe-lobj.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/interfaces/libpq/fe-lobj.c,v 1.62 2007/03/03 19:52:46 momjian Exp $ + * $PostgreSQL: pgsql/src/interfaces/libpq/fe-lobj.c,v 1.63 2007/11/15 21:14:46 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -124,7 +124,7 @@ lo_close(PGconn *conn, int fd) /* * lo_truncate - * truncates an existing large object to the given size + * truncates an existing large object to the given size * * returns 0 upon success * returns -1 upon failure @@ -147,14 +147,14 @@ lo_truncate(PGconn *conn, int fd, size_t len) if (conn->lobjfuncs->fn_lo_truncate == 0) { printfPQExpBuffer(&conn->errorMessage, - libpq_gettext("cannot determine OID of function lo_truncate\n")); + libpq_gettext("cannot determine OID of function lo_truncate\n")); return -1; } argv[0].isint = 1; argv[0].len = 4; argv[0].u.integer = fd; - + argv[1].isint = 1; argv[1].len = 4; argv[1].u.integer = len; diff --git a/src/interfaces/libpq/fe-secure.c b/src/interfaces/libpq/fe-secure.c index 4e4a2cd4ac..a60f018ae8 100644 --- a/src/interfaces/libpq/fe-secure.c +++ b/src/interfaces/libpq/fe-secure.c @@ -11,7 +11,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/interfaces/libpq/fe-secure.c,v 1.99 2007/10/03 15:12:45 tgl Exp $ + * $PostgreSQL: pgsql/src/interfaces/libpq/fe-secure.c,v 1.100 2007/11/15 21:14:46 momjian Exp $ * * NOTES * [ Most of these notes are wrong/obsolete, but perhaps not all ] @@ -113,7 +113,7 @@ #include <openssl/ssl.h> #include <openssl/bio.h> #if (SSLEAY_VERSION_NUMBER >= 0x00907000L) -#include <openssl/conf.h> +#include <openssl/conf.h> #endif #if (SSLEAY_VERSION_NUMBER >= 0x00907000L) && !defined(OPENSSL_NO_ENGINE) #include <openssl/engine.h> @@ -588,11 +588,11 @@ client_cert_cb(SSL *ssl, X509 **x509, EVP_PKEY **pkey) #ifndef WIN32 struct stat buf2; - FILE *fp; + FILE *fp; #endif char fnbuf[MAXPGPATH]; - BIO *bio; - PGconn *conn = (PGconn *) SSL_get_app_data(ssl); + BIO *bio; + PGconn *conn = (PGconn *) SSL_get_app_data(ssl); char sebuf[256]; if (!pqGetHomeDirectory(homedir, sizeof(homedir))) @@ -605,20 +605,20 @@ client_cert_cb(SSL *ssl, X509 **x509, EVP_PKEY **pkey) /* read the user certificate */ snprintf(fnbuf, sizeof(fnbuf), "%s/%s", homedir, USER_CERT_FILE); - /* - * OpenSSL <= 0.9.8 lacks error stack handling, which means it's likely - * to report wrong error messages if access to the cert file fails. - * Do our own check for the readability of the file to catch the - * majority of such problems before OpenSSL gets involved. + /* + * OpenSSL <= 0.9.8 lacks error stack handling, which means it's likely to + * report wrong error messages if access to the cert file fails. Do our + * own check for the readability of the file to catch the majority of such + * problems before OpenSSL gets involved. */ #ifndef HAVE_ERR_SET_MARK { - FILE *fp2; + FILE *fp2; if ((fp2 = fopen(fnbuf, "r")) == NULL) { printfPQExpBuffer(&conn->errorMessage, - libpq_gettext("could not open certificate file \"%s\": %s\n"), + libpq_gettext("could not open certificate file \"%s\": %s\n"), fnbuf, pqStrerror(errno, sebuf, sizeof(sebuf))); return 0; } @@ -628,7 +628,7 @@ client_cert_cb(SSL *ssl, X509 **x509, EVP_PKEY **pkey) /* save OpenSSL error stack */ ERR_set_mark(); - + if ((bio = BIO_new_file(fnbuf, "r")) == NULL) { printfPQExpBuffer(&conn->errorMessage, @@ -657,15 +657,15 @@ client_cert_cb(SSL *ssl, X509 **x509, EVP_PKEY **pkey) if (getenv("PGSSLKEY")) { /* read the user key from engine */ - char *engine_env = getenv("PGSSLKEY"); - char *engine_colon = strchr(engine_env, ':'); - char *engine_str; - ENGINE *engine_ptr; + char *engine_env = getenv("PGSSLKEY"); + char *engine_colon = strchr(engine_env, ':'); + char *engine_str; + ENGINE *engine_ptr; if (!engine_colon) { printfPQExpBuffer(&conn->errorMessage, - libpq_gettext("invalid value of PGSSLKEY environment variable\n")); + libpq_gettext("invalid value of PGSSLKEY environment variable\n")); ERR_pop_to_mark(); return 0; } @@ -675,10 +675,10 @@ client_cert_cb(SSL *ssl, X509 **x509, EVP_PKEY **pkey) engine_ptr = ENGINE_by_id(engine_str); if (engine_ptr == NULL) { - char *err = SSLerrmessage(); + char *err = SSLerrmessage(); printfPQExpBuffer(&conn->errorMessage, - libpq_gettext("could not load SSL engine \"%s\": %s\n"), + libpq_gettext("could not load SSL engine \"%s\": %s\n"), engine_str, err); SSLerrfree(err); free(engine_str); @@ -690,10 +690,10 @@ client_cert_cb(SSL *ssl, X509 **x509, EVP_PKEY **pkey) NULL, NULL); if (*pkey == NULL) { - char *err = SSLerrmessage(); + char *err = SSLerrmessage(); printfPQExpBuffer(&conn->errorMessage, - libpq_gettext("could not read private SSL key \"%s\" from engine \"%s\": %s\n"), + libpq_gettext("could not read private SSL key \"%s\" from engine \"%s\": %s\n"), engine_colon + 1, engine_str, err); SSLerrfree(err); free(engine_str); @@ -703,15 +703,15 @@ client_cert_cb(SSL *ssl, X509 **x509, EVP_PKEY **pkey) free(engine_str); } else -#endif /* use PGSSLKEY */ +#endif /* use PGSSLKEY */ { /* read the user key from file */ snprintf(fnbuf, sizeof(fnbuf), "%s/%s", homedir, USER_KEY_FILE); if (stat(fnbuf, &buf) == -1) { printfPQExpBuffer(&conn->errorMessage, - libpq_gettext("certificate present, but not private key file \"%s\"\n"), - fnbuf); + libpq_gettext("certificate present, but not private key file \"%s\"\n"), + fnbuf); ERR_pop_to_mark(); return 0; } @@ -720,8 +720,8 @@ client_cert_cb(SSL *ssl, X509 **x509, EVP_PKEY **pkey) buf.st_uid != geteuid()) { printfPQExpBuffer(&conn->errorMessage, - libpq_gettext("private key file \"%s\" has wrong permissions\n"), - fnbuf); + libpq_gettext("private key file \"%s\" has wrong permissions\n"), + fnbuf); ERR_pop_to_mark(); return 0; } @@ -730,8 +730,8 @@ client_cert_cb(SSL *ssl, X509 **x509, EVP_PKEY **pkey) if ((bio = BIO_new_file(fnbuf, "r")) == NULL) { printfPQExpBuffer(&conn->errorMessage, - libpq_gettext("could not open private key file \"%s\": %s\n"), - fnbuf, pqStrerror(errno, sebuf, sizeof(sebuf))); + libpq_gettext("could not open private key file \"%s\": %s\n"), + fnbuf, pqStrerror(errno, sebuf, sizeof(sebuf))); ERR_pop_to_mark(); return 0; } @@ -741,7 +741,7 @@ client_cert_cb(SSL *ssl, X509 **x509, EVP_PKEY **pkey) buf.st_dev != buf2.st_dev || buf.st_ino != buf2.st_ino) { printfPQExpBuffer(&conn->errorMessage, - libpq_gettext("private key file \"%s\" changed during execution\n"), fnbuf); + libpq_gettext("private key file \"%s\" changed during execution\n"), fnbuf); ERR_pop_to_mark(); return 0; } @@ -752,8 +752,8 @@ client_cert_cb(SSL *ssl, X509 **x509, EVP_PKEY **pkey) char *err = SSLerrmessage(); printfPQExpBuffer(&conn->errorMessage, - libpq_gettext("could not read private key file \"%s\": %s\n"), - fnbuf, err); + libpq_gettext("could not read private key file \"%s\": %s\n"), + fnbuf, err); SSLerrfree(err); BIO_free(bio); @@ -852,7 +852,7 @@ init_ssl_system(PGconn *conn) { #if SSLEAY_VERSION_NUMBER >= 0x00907000L OPENSSL_config(NULL); -#endif +#endif SSL_library_init(); SSL_load_error_strings(); } diff --git a/src/interfaces/libpq/libpq-int.h b/src/interfaces/libpq/libpq-int.h index 08a6bd1bb5..5a9709b073 100644 --- a/src/interfaces/libpq/libpq-int.h +++ b/src/interfaces/libpq/libpq-int.h @@ -12,7 +12,7 @@ * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/interfaces/libpq/libpq-int.h,v 1.126 2007/07/23 18:59:50 tgl Exp $ + * $PostgreSQL: pgsql/src/interfaces/libpq/libpq-int.h,v 1.127 2007/11/15 21:14:46 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -61,12 +61,13 @@ /* * Define a fake structure compatible with GSSAPI on Unix. */ -typedef struct { - void *value; - int length; -} gss_buffer_desc; +typedef struct +{ + void *value; + int length; +} gss_buffer_desc; #endif -#endif /* ENABLE_SSPI */ +#endif /* ENABLE_SSPI */ #ifdef USE_SSL #include <openssl/ssl.h> @@ -262,7 +263,7 @@ typedef struct pgLobjfuncs Oid fn_lo_unlink; /* OID of backend function lo_unlink */ Oid fn_lo_lseek; /* OID of backend function lo_lseek */ Oid fn_lo_tell; /* OID of backend function lo_tell */ - Oid fn_lo_truncate; /* OID of backend function lo_truncate */ + Oid fn_lo_truncate; /* OID of backend function lo_truncate */ Oid fn_lo_read; /* OID of backend function LOread */ Oid fn_lo_write; /* OID of backend function LOwrite */ } PGlobjfuncs; @@ -322,7 +323,7 @@ struct pg_conn SockAddr raddr; /* Remote address */ ProtocolVersion pversion; /* FE/BE protocol version in use */ int sversion; /* server version, e.g. 70401 for 7.4.1 */ - AuthRequest areq; /* auth type demanded by server */ + AuthRequest areq; /* auth type demanded by server */ /* Transient state needed while establishing connection */ struct addrinfo *addrlist; /* list of possible backend addresses */ @@ -374,22 +375,24 @@ struct pg_conn #endif #ifdef ENABLE_GSS - gss_ctx_id_t gctx; /* GSS context */ - gss_name_t gtarg_nam; /* GSS target name */ - gss_buffer_desc ginbuf; /* GSS input token */ - gss_buffer_desc goutbuf; /* GSS output token */ + gss_ctx_id_t gctx; /* GSS context */ + gss_name_t gtarg_nam; /* GSS target name */ + gss_buffer_desc ginbuf; /* GSS input token */ + gss_buffer_desc goutbuf; /* GSS output token */ #endif #ifdef ENABLE_SSPI #ifndef ENABLE_GSS - gss_buffer_desc ginbuf; /* GSS input token */ + gss_buffer_desc ginbuf; /* GSS input token */ #else - char *gsslib; /* What GSS librart to use ("gssapi" or "sspi") */ + char *gsslib; /* What GSS librart to use ("gssapi" or + * "sspi") */ #endif - CredHandle *sspicred; /* SSPI credentials handle */ - CtxtHandle *sspictx; /* SSPI context */ - char *sspitarget;/* SSPI target name */ - int usesspi; /* Indicate if SSPI is in use on the connection */ + CredHandle *sspicred; /* SSPI credentials handle */ + CtxtHandle *sspictx; /* SSPI context */ + char *sspitarget; /* SSPI target name */ + int usesspi; /* Indicate if SSPI is in use on the + * connection */ #endif |
