summaryrefslogtreecommitdiff
path: root/src/backenddb/merchant-0004.sql
diff options
context:
space:
mode:
Diffstat (limited to 'src/backenddb/merchant-0004.sql')
-rw-r--r--src/backenddb/merchant-0004.sql382
1 files changed, 0 insertions, 382 deletions
diff --git a/src/backenddb/merchant-0004.sql b/src/backenddb/merchant-0004.sql
index eebe2889..204f14ca 100644
--- a/src/backenddb/merchant-0004.sql
+++ b/src/backenddb/merchant-0004.sql
@@ -50,385 +50,3 @@ COMMENT ON COLUMN merchant_template.image
COMMENT ON COLUMN merchant_template.template_contract
IS 'The template contract will contains some additional information.'
-
--- C CODE
-
-/**
- * Delete information about a template.
- *
- * @param cls closure
- * @param instance_id instance to delete product of
- * @param template_id template to delete
- * @return DB status code, #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS
- * if template unknow.
- */
-static enum GNUNET_DB_QueryStatus
-postgres_delete_template (void *cls,
- const char *instance_id,
- const char *template_id)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_string (instance_id),
- GNUNET_PQ_query_param_string (template_id),
- GNUNET_PQ_query_param_end
- };
-
- check_connection (pg);
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "delete_template",
- params);
-}
-
-/**
- * Insert details about a particular template.
- *
- * @param cls closure
- * @param instance_id instance to insert template for
- * @param template_id template identifier of template to insert
- * @param pd the template details to insert
- * @return database result code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_insert_template (void *cls,
- const char *instance_id,
- const char *template_id,
- const struct TALER_MERCHANTDB_TemplateDetails *pd)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_string (instance_id),
- GNUNET_PQ_query_param_string (template_id),
- GNUNET_PQ_query_param_string (pd->template_description),
- GNUNET_PQ_query_param_string (pd->image),
- GNUNET_PQ_query_param_string (pd->template_contract),
- GNUNET_PQ_query_param_end
-
- };
-
- check_connection (pg);
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_template",
- params);
-}
-
-/**
- * Update details about a particular template.
- *
- * @param cls closure
- * @param instance_id instance to update template for
- * @param template_id template to update
- * @param pd update to the template details on success, can be NULL
- * (in that case we only want to check if the template exists)
- * @return database result code, #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS if the template
- * does not yet exist.
- */
-static enum GNUNET_DB_QueryStatus
-postgres_update_template (void *cls,
- const char *instance_id,
- const char *template_id,
- const struct TALER_MERCHANTDB_TemplateDetails *pd)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_string (instance_id),
- GNUNET_PQ_query_param_string (template_id),
- GNUNET_PQ_query_param_string (pd->template_description),
- GNUNET_PQ_query_param_string (pd->image),
- GNUNET_PQ_query_param_string (pd->template_contract),
- GNUNET_PQ_query_param_end
- };
-
- {
- GNUNET_break (0);
- return GNUNET_DB_STATUS_HARD_ERROR;
- }
- check_connection (pg);
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "update_template",
- params);
-}
-
-
-
-
-/**
- * Context used for postgres_lookup_template().
- */
-struct LookupTemplateContext
-{
- /**
- * Function to call with the results.
- */
- TALER_MERCHANTDB_TemplateCallback cb;
-
- /**
- * Closure for @a cb.
- */
- void *cb_cls;
-
- /**
- * Did database result extraction fail?
- */
- bool extract_failed;
-};
-
-
-/**
- * Function to be called with the results of a SELECT statement
- * that has returned @a num_results results about template.
- *
- * @param[in,out] cls of type `struct LookupTemplateContext *`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-lookup_templates_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct LookupTemplateContext *tlc = cls;
-
- for (unsigned int i = 0; i < num_results; i++)
- {
- char *template_id;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_string ("template_id",
- &template_id),
- GNUNET_PQ_result_spec_string ("template_description",
- &template_description),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- tlc->extract_failed = true;
- return;
- }
- tlc->cb (tlc->cb_cls,
- template_id);
- GNUNET_PQ_cleanup_result (rs);
- }
-}
-
-
-/**
- * Lookup all of the templates the given instance has configured.
- *
- * @param cls closure
- * @param instance_id instance to lookup template for
- * @param cb function to call on all template found
- * @param cb_cls closure for @a cb
- * @return database result code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_lookup_templates (void *cls,
- const char *instance_id,
- TALER_MERCHANTDB_TemplateCallback cb,
- void *cb_cls)
-{
- struct PostgresClosure *pg = cls;
- struct LookupTemplateContext tlc = {
- .cb = cb,
- .cb_cls = cb_cls,
- /* Can be overwritten by the lookup_template_cb */
- .extract_failed = false,
- };
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_string (instance_id),
- GNUNET_PQ_query_param_end
- };
- enum GNUNET_DB_QueryStatus qs;
-
- check_connection (pg);
- qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- "lookup_templates",
- params,
- &lookup_templates_cb,
- &tlc);
- /* If there was an error inside lookup_template_cb, return a hard error. */
- if (tlc.extract_failed)
- return GNUNET_DB_STATUS_HARD_ERROR;
- return qs;
-}
-
-/**
- * Lookup details about a particular template.
- *
- * @param cls closure
- * @param instance_id instance to lookup template for
- * @param template_id template to lookup
- * @param[out] pd set to the template details on success, can be NULL
- * (in that case we only want to check if the template exists)
- * @return database result code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_lookup_template (void *cls,
- const char *instance_id,
- const char *template_id,
- struct TALER_MERCHANTDB_TemplateDetails *pd)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_string (instance_id),
- GNUNET_PQ_query_param_string (template_id),
- GNUNET_PQ_query_param_end
- };
-
- if (NULL == pd)
- {
- struct GNUNET_PQ_ResultSpec rs_null[] = {
- GNUNET_PQ_result_spec_end
- };
-
- check_connection (pg);
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "lookup_template",
- params,
- rs_null);
- }
- else
- {
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_string ("template_description",
- &pd->template_description),
- GNUNET_PQ_result_spec_string ("image",
- &pd->image),
- GNUNET_PQ_result_spec_string ("template_contract",
- &pd->template_contract),
- GNUNET_PQ_result_spec_end
- };
-
- check_connection (pg);
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "lookup_template",
- params,
- rs);
- }
-}
-
-
-
-------------------------------API--------------------------------
-
-/**
- * Typically called by `lookup_templates`.
- *
- * @param cls a `json_t *` JSON array to build
- * @param template_id ID of the template
- */
-typedef void
-(*TALER_MERCHANTDB_TemplatesCallback)(void *cls,
- const char *template_id,
- const char *template_description);
-
-
-/**
- * Details about a template.
- */
-struct TALER_MERCHANTDB_TemplateDetails
-{
- /**
- * Description of the template.
- */
- const char *template_description;
-
- /**
- * Base64-encoded product image, or NULL.
- */
- const char *image;
-
- /**
- * In this template contract, we can have additional information.
- */
- const json_t *template_contract;
-};
-
-
-
-/**
- * Lookup all of the templates the given instance has configured.
- *
- * @param cls closure
- * @param instance_id instance to lookup template for
- * @param cb function to call on all template found
- * @param cb_cls closure for @a cb
- * @return database result code
- */
-enum GNUNET_DB_QueryStatus
-(*lookup_templates) (void *cls,
- const char *instance_id,
- TALER_MERCHANTDB_TemplateCallback cb,
- void *cb_cls);
-
-
-/**
- * Lookup details about a particular template.
- *
- * @param cls closure
- * @param instance_id instance to lookup template for
- * @param template_id template to lookup
- * @param[out] pd set to the template details on success, can be NULL
- * (in that case we only want to check if the template exists)
- * @return database result code
- */
-enum GNUNET_DB_QueryStatus
-(*lookup_template) (void *cls,
- const char *instance_id,
- const char *template_id,
- struct TALER_MERCHANTDB_TemplateDetails *pd);
-
-/**
- * Delete information about a template.
- *
- * @param cls closure
- * @param instance_id instance to delete product of
- * @param template_id template to delete
- * @return DB status code, #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS
- * if template unknow.
- */
-enum GNUNET_DB_QueryStatus
-(*delete_template) (void *cls,
- const char *instance_id,
- const char *template_id);
-
-
-
-/**
- * Insert details about a particular template.
- *
- * @param cls closure
- * @param instance_id instance to insert template for
- * @param template_id template identifier of template to insert
- * @param pd the template details to insert
- * @return database result code
- */
-enum GNUNET_DB_QueryStatus
-(*insert_template) (void *cls,
- const char *instance_id,
- const char *template_id,
- const struct TALER_MERCHANTDB_TemplateDetails *pd);
-
-
-
-/**
- * Update details about a particular template.
- *
- * @param cls closure
- * @param instance_id instance to update template for
- * @param template_id template to update
- * @param pd update to the template details on success, can be NULL
- * (in that case we only want to check if the template exists)
- * @return database result code, #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS if the template
- * does not yet exist.
- */
-
-enum GNUNET_DB_QueryStatus
-(*update_template) (void *cls,
- const char *instance_id,
- const char *template_id,
- const struct TALER_MERCHANTDB_TemplateDetails *pd)