-style fixes

This commit is contained in:
Sree Harsha Totakura 2015-04-29 12:45:44 +02:00
parent 3f3d8dfbfb
commit 6a584e6c8a

View File

@ -57,12 +57,12 @@ TALER_PQ_exec_prepared (PGconn *db_conn,
param_formats[i] = 1; param_formats[i] = 1;
} }
return PQexecPrepared (db_conn, return PQexecPrepared (db_conn,
name, name,
len, len,
(const char **) param_values, (const char **) param_values,
param_lengths, param_lengths,
param_formats, param_formats,
1); 1);
} }
} }
@ -95,7 +95,7 @@ TALER_PQ_extract_result (PGresult *result,
for (i=0; NULL != rs[i].fname; i++) for (i=0; NULL != rs[i].fname; i++)
{ {
fnum = PQfnumber (result, fnum = PQfnumber (result,
rs[i].fname); rs[i].fname);
if (fnum < 0) if (fnum < 0)
{ {
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@ -107,15 +107,15 @@ TALER_PQ_extract_result (PGresult *result,
/* if a field is null, continue but /* if a field is null, continue but
* remember that we now return a different result */ * remember that we now return a different result */
if (PQgetisnull (result, if (PQgetisnull (result,
row, row,
fnum)) fnum))
{ {
had_null = GNUNET_YES; had_null = GNUNET_YES;
continue; continue;
} }
len = PQgetlength (result, len = PQgetlength (result,
row, row,
fnum); fnum);
if ( (0 != rs[i].dst_size) && if ( (0 != rs[i].dst_size) &&
(rs[i].dst_size != len) ) (rs[i].dst_size != len) )
{ {
@ -131,26 +131,26 @@ TALER_PQ_extract_result (PGresult *result,
GNUNET_free (rs[j].dst); GNUNET_free (rs[j].dst);
rs[j].dst = NULL; rs[j].dst = NULL;
if (NULL != rs[j].result_size) if (NULL != rs[j].result_size)
*rs[j].result_size = 0; *rs[j].result_size = 0;
} }
} }
return GNUNET_SYSERR; return GNUNET_SYSERR;
} }
res = PQgetvalue (result, res = PQgetvalue (result,
row, row,
fnum); fnum);
GNUNET_assert (NULL != res); GNUNET_assert (NULL != res);
if (0 == rs[i].dst_size) if (0 == rs[i].dst_size)
{ {
if (NULL != rs[i].result_size) if (NULL != rs[i].result_size)
*rs[i].result_size = len; *rs[i].result_size = len;
rs[i].dst_size = len; rs[i].dst_size = len;
*((void **) rs[i].dst) = GNUNET_malloc (len); *((void **) rs[i].dst) = GNUNET_malloc (len);
rs[i].dst = * ((void **) rs[i].dst); rs[i].dst = * ((void **) rs[i].dst);
} }
memcpy (rs[i].dst, memcpy (rs[i].dst,
res, res,
len); len);
} }
if (GNUNET_YES == had_null) if (GNUNET_YES == had_null)
return GNUNET_NO; return GNUNET_NO;
@ -160,7 +160,7 @@ TALER_PQ_extract_result (PGresult *result,
/** /**
* Extract a currency amount from a query result according to the * Extract a currency amount from a query result according to the
* given specification. * given specification.
* *
* @param result the result to extract the amount from * @param result the result to extract the amount from
* @param row which row of the result to extract the amount from (needed as results can have multiple rows) * @param row which row of the result to extract the amount from (needed as results can have multiple rows)
@ -189,24 +189,24 @@ TALER_PQ_extract_amount_nbo (PGresult *result,
/* These checks are simply to check that clients obey by our naming /* These checks are simply to check that clients obey by our naming
conventions, and not for any functional reason */ conventions, and not for any functional reason */
GNUNET_assert (NULL != GNUNET_assert (NULL !=
strstr (val_name, strstr (val_name,
"_val")); "_val"));
GNUNET_assert (NULL != GNUNET_assert (NULL !=
strstr (frac_name, strstr (frac_name,
"_frac")); "_frac"));
GNUNET_assert (NULL != GNUNET_assert (NULL !=
strstr (curr_name, strstr (curr_name,
"_curr")); "_curr"));
/* Set return value to invalid in case we don't finish */ /* Set return value to invalid in case we don't finish */
memset (r_amount_nbo, memset (r_amount_nbo,
0, 0,
sizeof (struct TALER_AmountNBO)); sizeof (struct TALER_AmountNBO));
val_num = PQfnumber (result, val_num = PQfnumber (result,
val_name); val_name);
frac_num = PQfnumber (result, frac_num = PQfnumber (result,
frac_name); frac_name);
curr_num = PQfnumber (result, curr_num = PQfnumber (result,
curr_name); curr_name);
if ( (val_num < 0) || if ( (val_num < 0) ||
(frac_num < 0) || (frac_num < 0) ||
(curr_num < 0) ) (curr_num < 0) )
@ -215,14 +215,14 @@ TALER_PQ_extract_amount_nbo (PGresult *result,
return GNUNET_SYSERR; return GNUNET_SYSERR;
} }
if ( (PQgetisnull (result, if ( (PQgetisnull (result,
row, row,
val_num)) || val_num)) ||
(PQgetisnull (result, (PQgetisnull (result,
row, row,
frac_num)) || frac_num)) ||
(PQgetisnull (result, (PQgetisnull (result,
row, row,
curr_num)) ) curr_num)) )
{ {
GNUNET_break (0); GNUNET_break (0);
return GNUNET_NO; return GNUNET_NO;
@ -230,19 +230,19 @@ TALER_PQ_extract_amount_nbo (PGresult *result,
/* Note that Postgres stores value in NBO internally, /* Note that Postgres stores value in NBO internally,
so no conversion needed in this case */ so no conversion needed in this case */
r_amount_nbo->value = *(uint64_t *) PQgetvalue (result, r_amount_nbo->value = *(uint64_t *) PQgetvalue (result,
row, row,
val_num); val_num);
r_amount_nbo->fraction = *(uint32_t *) PQgetvalue (result, r_amount_nbo->fraction = *(uint32_t *) PQgetvalue (result,
row, row,
frac_num); frac_num);
len = GNUNET_MIN (TALER_CURRENCY_LEN - 1, len = GNUNET_MIN (TALER_CURRENCY_LEN - 1,
PQgetlength (result, PQgetlength (result,
row, row,
curr_num)); curr_num));
memcpy (r_amount_nbo->currency, memcpy (r_amount_nbo->currency,
PQgetvalue (result, PQgetvalue (result,
row, row,
curr_num), curr_num),
len); len);
return GNUNET_OK; return GNUNET_OK;
} }
@ -250,13 +250,17 @@ TALER_PQ_extract_amount_nbo (PGresult *result,
/** /**
* Extract a currency amount from a query result according to the * Extract a currency amount from a query result according to the
* given specification. * given specification.
* *
* @param result the result to extract the amount from * @param result the result to extract the amount from
* @param row which row of the result to extract the amount from (needed as results can have multiple rows) * @param row which row of the result to extract the amount from (needed as
* @param val_name name of the column with the amount's "value", must include the substring "_val". * results can have multiple rows)
* @param frac_name name of the column with the amount's "fractional" value, must include the substring "_frac". * @param val_name name of the column with the amount's "value", must include
* @param curr_name name of the column with the amount's currency name, must include the substring "_curr". * the substring "_val".
* @param frac_name name of the column with the amount's "fractional" value,
* must include the substring "_frac".
* @param curr_name name of the column with the amount's currency name, must
* include the substring "_curr".
* @param[out] r_amount where to store the amount, in host byte order * @param[out] r_amount where to store the amount, in host byte order
* @return * @return
* #GNUNET_YES if all results could be extracted * #GNUNET_YES if all results could be extracted
@ -275,13 +279,13 @@ TALER_PQ_extract_amount (PGresult *result,
int ret; int ret;
ret = TALER_PQ_extract_amount_nbo (result, ret = TALER_PQ_extract_amount_nbo (result,
row, row,
val_name, val_name,
frac_name, frac_name,
curr_name, curr_name,
&amount_nbo); &amount_nbo);
TALER_amount_ntoh (r_amount, TALER_amount_ntoh (r_amount,
&amount_nbo); &amount_nbo);
return ret; return ret;
} }