anastasis

Credential backup and recovery protocol and service
Log | Files | Refs | Submodules | README | LICENSE

anastasis-httpd_config.c (4415B)


      1 /*
      2   This file is part of Anastasis
      3   Copyright (C) 2020, 2021, 2024 Anastasis SARL
      4 
      5   Anastasis is free software; you can redistribute it and/or modify it under the
      6   terms of the GNU Affero General Public License as published by the Free Software
      7   Foundation; either version 3, or (at your option) any later version.
      8 
      9   Anastasis is distributed in the hope that it will be useful, but WITHOUT ANY
     10   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
     11   A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more details.
     12 
     13   You should have received a copy of the GNU Affero General Public License along with
     14   Anastasis; see the file COPYING.GPL.  If not, see <http://www.gnu.org/licenses/>
     15 */
     16 /**
     17  * @file backend/anastasis-httpd_config.c
     18  * @brief headers for /terms handler
     19  * @author Christian Grothoff
     20  * @author Dennis Neufeld
     21  * @author Dominik Meister
     22  */
     23 #include "platform.h"
     24 #include <jansson.h>
     25 #include "anastasis-httpd_config.h"
     26 #include "anastasis-httpd.h"
     27 #include <taler/taler_json_lib.h>
     28 #include "anastasis_authorization_lib.h"
     29 
     30 
     31 /**
     32  * Add enabled methods and their fees to the ``/config`` response.
     33  *
     34  * @param[in,out] cls a `json_t` array to build
     35  * @param section configuration section to inspect
     36  */
     37 static void
     38 add_methods (void *cls,
     39              const char *section)
     40 {
     41   json_t *method_arr = cls;
     42   struct ANASTASIS_AuthorizationPlugin *p;
     43   json_t *method;
     44 
     45   if (0 != strncasecmp (section,
     46                         "authorization-",
     47                         strlen ("authorization-")))
     48     return;
     49   if (GNUNET_YES !=
     50       GNUNET_CONFIGURATION_get_value_yesno (AH_cfg,
     51                                             section,
     52                                             "ENABLED"))
     53     return;
     54   section += strlen ("authorization-");
     55   p = ANASTASIS_authorization_plugin_load (section,
     56                                            db,
     57                                            AH_cfg);
     58   if (NULL == p)
     59   {
     60     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     61                 "Failed to load authorization plugin `%s'\n",
     62                 section);
     63     return;
     64   }
     65   method = GNUNET_JSON_PACK (
     66     GNUNET_JSON_pack_string ("type",
     67                              section),
     68     TALER_JSON_pack_amount ("cost",
     69                             &p->cost));
     70   GNUNET_assert (
     71     0 ==
     72     json_array_append_new (method_arr,
     73                            method));
     74 }
     75 
     76 
     77 MHD_RESULT
     78 AH_handler_config (struct AH_RequestHandler *rh,
     79                    struct MHD_Connection *connection)
     80 {
     81   static struct MHD_Response *response;
     82 
     83   if (NULL == response)
     84   {
     85     json_t *method_arr = json_array ();
     86 
     87     GNUNET_assert (NULL != method_arr);
     88     {
     89       json_t *method;
     90 
     91       method = GNUNET_JSON_PACK (
     92         GNUNET_JSON_pack_string ("type",
     93                                  "question"),
     94         TALER_JSON_pack_amount ("cost",
     95                                 &AH_question_cost));
     96       GNUNET_assert (
     97         0 ==
     98         json_array_append_new (method_arr,
     99                                method));
    100     }
    101     GNUNET_CONFIGURATION_iterate_sections (AH_cfg,
    102                                            &add_methods,
    103                                            method_arr);
    104 
    105     response = TALER_MHD_MAKE_JSON_PACK (
    106       GNUNET_JSON_pack_string ("name",
    107                                "anastasis"),
    108       GNUNET_JSON_pack_string ("version",
    109                                "0:3:0"),
    110       GNUNET_JSON_pack_string ("implementation",
    111                                "urn:net:taler:specs:anastasis:c-reference"),
    112       GNUNET_JSON_pack_string ("business_name",
    113                                AH_business_name),
    114       GNUNET_JSON_pack_array_steal ("methods",
    115                                     method_arr),
    116       GNUNET_JSON_pack_uint64 ("storage_limit_in_megabytes",
    117                                AH_upload_limit_mb),
    118       TALER_JSON_pack_amount ("annual_fee",
    119                               &AH_annual_fee),
    120       TALER_JSON_pack_amount ("truth_upload_fee",
    121                               &AH_truth_upload_fee),
    122       TALER_JSON_pack_amount ("liability_limit",
    123                               &AH_insurance),
    124       GNUNET_JSON_pack_data_auto ("provider_salt",
    125                                   &AH_provider_salt));
    126   }
    127   return MHD_queue_response (connection,
    128                              MHD_HTTP_OK,
    129                              response);
    130 }
    131 
    132 
    133 /* end of anastasis-httpd_config.c */