aboutsummaryrefslogtreecommitdiff
path: root/src/bank-lib/fakebank.c
diff options
context:
space:
mode:
authorMarcello Stanisci <stanisci.m@gmail.com>2019-04-08 00:23:07 +0200
committerMarcello Stanisci <stanisci.m@gmail.com>2019-04-08 02:37:45 +0200
commitddb8cdfa7a2d0bb297ab8190fd17575d916beaf4 (patch)
tree0b3d792b4d029e7339e0c62702ccc7dfca8b8b26 /src/bank-lib/fakebank.c
parent3c66bb30b9ad56e934c364379095ec040b9e36e6 (diff)
Finishing /history-range implementation, untested.
Diffstat (limited to 'src/bank-lib/fakebank.c')
-rw-r--r--src/bank-lib/fakebank.c122
1 files changed, 75 insertions, 47 deletions
diff --git a/src/bank-lib/fakebank.c b/src/bank-lib/fakebank.c
index 9d73b7f04..86f4c071a 100644
--- a/src/bank-lib/fakebank.c
+++ b/src/bank-lib/fakebank.c
@@ -241,38 +241,6 @@ struct TALER_FAKEBANK_Handle
/**
- * Type for a function that decides whether or not
- * the history-building loop should iterate once again.
- * Typically called from inside the 'while' condition.
- *
- * @param ha history argument.
- * @param pos current position.
- * @return GNUNET_YES if the iteration shuold go on.
- */
-typedef int (*CheckAdvance)
- (const struct HistoryArgs *ha,
- struct Transaction *pos);
-
-/**
- * Type for a function that steps over the next element
- * in the list of all transactions, after the current @a pos
- * _got_ included in the result.
- */
-typedef struct Transaction * (*Step)
- (const struct HistoryArgs *ha,
- const struct Transaction *pos);
-
-/*
- * Type for a function that steps over the next element
- * in the list of all transactions, after the current @a pos
- * did _not_ get included in the result.
- */
-typedef struct Transaction * (*Skip)
- (const struct HistoryArgs *ha,
- const struct Transaction *pos);
-
-
-/**
* Check that the @a want_amount was transferred from
* the @a want_debit to the @a want_credit account. If
* so, set the @a subject to the transfer identifier.
@@ -783,6 +751,39 @@ handle_reject (struct TALER_FAKEBANK_Handle *h,
* Serving "/history" starts here. *
***********************************/
+/**
+ * Type for a function that decides whether or not
+ * the history-building loop should iterate once again.
+ * Typically called from inside the 'while' condition.
+ *
+ * @param ha history argument.
+ * @param pos current position.
+ * @return GNUNET_YES if the iteration shuold go on.
+ */
+typedef int (*CheckAdvance)
+ (const struct HistoryArgs *ha,
+ const struct Transaction *pos);
+
+/**
+ * Type for a function that steps over the next element
+ * in the list of all transactions, after the current @a pos
+ * _got_ included in the result.
+ */
+typedef struct Transaction * (*Step)
+ (const struct HistoryArgs *ha,
+ const struct Transaction *pos);
+
+/*
+ * Type for a function that steps over the next element
+ * in the list of all transactions, after the current @a pos
+ * did _not_ get included in the result.
+ */
+typedef struct Transaction * (*Skip)
+ (const struct HistoryArgs *ha,
+ const struct Transaction *pos);
+
+
+
/**
* Decides whether the history builder will advance or not
@@ -793,7 +794,7 @@ handle_reject (struct TALER_FAKEBANK_Handle *h,
*/
static int
handle_history_advance (const struct HistoryArgs *ha,
- struct Transaction *pos)
+ const struct Transaction *pos)
{
const struct HistoryRangeIds *hri = ha->range;
@@ -858,9 +859,16 @@ handle_history_step (const struct HistoryArgs *ha,
* @return GNUNET_YES/NO to advance/not-advance.
*/
static int
-handle_history_range_advance (const struct HistoryArgs *ha)
+handle_history_range_advance (const struct HistoryArgs *ha,
+ const struct Transaction *pos)
{
const struct HistoryRangeDates *hrd = ha->range;
+
+ if ( (NULL != pos) &&
+ (pos->date.abs_value_us <= hrd->end.abs_value_us) )
+ return GNUNET_YES;
+
+ return GNUNET_NO;
}
@@ -874,25 +882,21 @@ handle_history_range_advance (const struct HistoryArgs *ha)
* @return the next element to be processed.
*/
static struct Transaction *
-handle_history_range_skip (const struct HistoryArgs *ha)
+handle_history_range_skip (const struct HistoryArgs *ha,
+ const struct Transaction *pos)
{
- const struct HistoryRangeDates *hrd = ha->range;
+ /* Transactions
+ * are stored from "head"/older to "tail"/younger. */
+ return pos->next;
}
/**
* Iterates on the "next" element to be processed. To
* be used when the current element _gets_ inserted in the result.
- *
- * @param ha history arguments.
- * @param pos current element being processed.
- * @return the next element to be processed.
+ * Same implementation of the "skip" counterpart, as /history-range
+ * does not have the notion of count/delta.
*/
-static struct Transaction *
-handle_history_range_step (const struct HistoryArgs *ha)
-{
- const struct HistoryRangeDates *hrd = ha->range;
-}
-
+Step handle_history_range_step = handle_history_range_skip;
/**
* Actual history response builder.
@@ -1272,13 +1276,13 @@ handle_history_range (struct TALER_FAKEBANK_Handle *h,
struct MHD_Connection *connection,
void **con_cls)
{
-
struct HistoryArgs ha;
struct HistoryRangeDates hrd;
const char *start;
const char *end;
long long unsigned int start_stamp;
long long unsigned int end_stamp;
+ struct Transaction *pos;
if (GNUNET_OK != parse_history_common_args (connection,
&ha))
@@ -1306,6 +1310,23 @@ handle_history_range (struct TALER_FAKEBANK_Handle *h,
hrd.start.abs_value_us = start_stamp * 1000LL * 1000LL;
hrd.end.abs_value_us = end_stamp * 1000LL * 1000LL;
+ ha.range = &hrd;
+
+ pos = NULL;
+ /* hunt for 'pos' in the Transaction(s) LL. */
+ for (pos = h->transactions_head;
+ NULL != pos;
+ pos = pos->next)
+ {
+ if (hrd.start.abs_value_us <= pos->date.abs_value_us)
+ break;
+ }
+ return build_history_response (connection,
+ pos,
+ &ha,
+ &handle_history_range_skip,
+ handle_history_range_step,
+ &handle_history_range_advance);
}
/**
@@ -1674,6 +1695,13 @@ handle_mhd_request (void *cls,
upload_data_size,
con_cls);
if ( (0 == strcasecmp (url,
+ "/history-range")) &&
+ (0 == strcasecmp (method,
+ MHD_HTTP_METHOD_GET)) )
+ return handle_history_range (h,
+ connection,
+ con_cls);
+ if ( (0 == strcasecmp (url,
"/history")) &&
(0 == strcasecmp (method,
MHD_HTTP_METHOD_GET)) )