diff options
Diffstat (limited to 'src/stasis/plugin_anastasis_postgres.c')
-rw-r--r-- | src/stasis/plugin_anastasis_postgres.c | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/stasis/plugin_anastasis_postgres.c b/src/stasis/plugin_anastasis_postgres.c index 9d206c7..325bae8 100644 --- a/src/stasis/plugin_anastasis_postgres.c +++ b/src/stasis/plugin_anastasis_postgres.c | |||
@@ -1759,6 +1759,11 @@ struct CheckValidityContext | |||
1759 | bool valid; | 1759 | bool valid; |
1760 | 1760 | ||
1761 | /** | 1761 | /** |
1762 | * Set to true if a code matching @e hashed_code was set to 'satisfied' by the plugin. | ||
1763 | */ | ||
1764 | bool satisfied; | ||
1765 | |||
1766 | /** | ||
1762 | * Set to true if we had a database failure. | 1767 | * Set to true if we had a database failure. |
1763 | */ | 1768 | */ |
1764 | bool db_failure; | 1769 | bool db_failure; |
@@ -1786,9 +1791,12 @@ check_valid_code (void *cls, | |||
1786 | for (unsigned int i = 0; i < num_results; i++) | 1791 | for (unsigned int i = 0; i < num_results; i++) |
1787 | { | 1792 | { |
1788 | uint64_t server_code; | 1793 | uint64_t server_code; |
1794 | uint8_t sat; | ||
1789 | struct GNUNET_PQ_ResultSpec rs[] = { | 1795 | struct GNUNET_PQ_ResultSpec rs[] = { |
1790 | GNUNET_PQ_result_spec_uint64 ("code", | 1796 | GNUNET_PQ_result_spec_uint64 ("code", |
1791 | &server_code), | 1797 | &server_code), |
1798 | GNUNET_PQ_result_spec_auto_from_type ("satisfied", | ||
1799 | &sat), | ||
1792 | GNUNET_PQ_result_spec_end | 1800 | GNUNET_PQ_result_spec_end |
1793 | }; | 1801 | }; |
1794 | 1802 | ||
@@ -1811,6 +1819,7 @@ check_valid_code (void *cls, | |||
1811 | cvc->hashed_code)) | 1819 | cvc->hashed_code)) |
1812 | { | 1820 | { |
1813 | cvc->valid = true; | 1821 | cvc->valid = true; |
1822 | cvc->satisfied = (0 != sat); | ||
1814 | } | 1823 | } |
1815 | else | 1824 | else |
1816 | { | 1825 | { |
@@ -1844,13 +1853,15 @@ check_valid_code (void *cls, | |||
1844 | * @param cls closure | 1853 | * @param cls closure |
1845 | * @param truth_uuid identification of the challenge which the code corresponds to | 1854 | * @param truth_uuid identification of the challenge which the code corresponds to |
1846 | * @param hashed_code code which the user provided and wants to verify | 1855 | * @param hashed_code code which the user provided and wants to verify |
1856 | * @param[out] satisfied set to true if the challenge is set to satisfied | ||
1847 | * @return code validity status | 1857 | * @return code validity status |
1848 | */ | 1858 | */ |
1849 | enum ANASTASIS_DB_CodeStatus | 1859 | enum ANASTASIS_DB_CodeStatus |
1850 | postgres_verify_challenge_code ( | 1860 | postgres_verify_challenge_code ( |
1851 | void *cls, | 1861 | void *cls, |
1852 | const struct ANASTASIS_CRYPTO_TruthUUIDP *truth_uuid, | 1862 | const struct ANASTASIS_CRYPTO_TruthUUIDP *truth_uuid, |
1853 | const struct GNUNET_HashCode *hashed_code) | 1863 | const struct GNUNET_HashCode *hashed_code, |
1864 | bool *satisfied) | ||
1854 | { | 1865 | { |
1855 | struct PostgresClosure *pg = cls; | 1866 | struct PostgresClosure *pg = cls; |
1856 | struct CheckValidityContext cvc = { | 1867 | struct CheckValidityContext cvc = { |
@@ -1866,6 +1877,7 @@ postgres_verify_challenge_code ( | |||
1866 | }; | 1877 | }; |
1867 | enum GNUNET_DB_QueryStatus qs; | 1878 | enum GNUNET_DB_QueryStatus qs; |
1868 | 1879 | ||
1880 | *satisfied = false; | ||
1869 | check_connection (pg); | 1881 | check_connection (pg); |
1870 | GNUNET_TIME_round_abs (&now); | 1882 | GNUNET_TIME_round_abs (&now); |
1871 | qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, | 1883 | qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, |
@@ -1877,7 +1889,10 @@ postgres_verify_challenge_code ( | |||
1877 | (cvc.db_failure) ) | 1889 | (cvc.db_failure) ) |
1878 | return ANASTASIS_DB_CODE_STATUS_HARD_ERROR; | 1890 | return ANASTASIS_DB_CODE_STATUS_HARD_ERROR; |
1879 | if (cvc.valid) | 1891 | if (cvc.valid) |
1892 | { | ||
1893 | *satisfied = cvc.satisfied; | ||
1880 | return ANASTASIS_DB_CODE_STATUS_VALID_CODE_STORED; | 1894 | return ANASTASIS_DB_CODE_STATUS_VALID_CODE_STORED; |
1895 | } | ||
1881 | if (0 == qs) | 1896 | if (0 == qs) |
1882 | return ANASTASIS_DB_CODE_STATUS_NO_RESULTS; | 1897 | return ANASTASIS_DB_CODE_STATUS_NO_RESULTS; |
1883 | return ANASTASIS_DB_CODE_STATUS_CHALLENGE_CODE_MISMATCH; | 1898 | return ANASTASIS_DB_CODE_STATUS_CHALLENGE_CODE_MISMATCH; |
@@ -2523,6 +2538,7 @@ libanastasis_plugin_db_postgres_init (void *cls) | |||
2523 | GNUNET_PQ_make_prepare ("challengecode_select", | 2538 | GNUNET_PQ_make_prepare ("challengecode_select", |
2524 | "SELECT " | 2539 | "SELECT " |
2525 | " code" | 2540 | " code" |
2541 | ",satisfied" | ||
2526 | " FROM anastasis_challengecode" | 2542 | " FROM anastasis_challengecode" |
2527 | " WHERE truth_uuid=$1" | 2543 | " WHERE truth_uuid=$1" |
2528 | " AND expiration_date > $2" | 2544 | " AND expiration_date > $2" |