aboutsummaryrefslogtreecommitdiff
path: root/src/backend/taler-merchant-httpd_proposal.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/taler-merchant-httpd_proposal.c')
-rw-r--r--src/backend/taler-merchant-httpd_proposal.c62
1 files changed, 56 insertions, 6 deletions
diff --git a/src/backend/taler-merchant-httpd_proposal.c b/src/backend/taler-merchant-httpd_proposal.c
index aa56e613..06788f02 100644
--- a/src/backend/taler-merchant-httpd_proposal.c
+++ b/src/backend/taler-merchant-httpd_proposal.c
@@ -139,6 +139,59 @@ json_parse_cleanup (struct TM_HandlerContext *hc)
139 139
140 140
141/** 141/**
142 * Generate the base URL for the given merchant instance.
143 *
144 * @param connection the MHD connection
145 * @param instance_id the merchant instance ID
146 * @returns the merchant instance's base URL
147 */
148static char *
149make_merchant_base_url (struct MHD_Connection *connection, const
150 char *instance_id)
151{
152 const char *host;
153 const char *forwarded_host;
154 const char *uri_path;
155 struct TALER_Buffer buf = { 0 };
156
157 if (GNUNET_YES == TALER_mhd_is_https (connection))
158 TALER_buffer_write_str (&buf, "https://");
159 else
160 TALER_buffer_write_str (&buf, "http://");
161
162
163 host = MHD_lookup_connection_value (connection, MHD_HEADER_KIND, "Host");
164 forwarded_host = MHD_lookup_connection_value (connection, MHD_HEADER_KIND,
165 "X-Forwarded-Host");
166
167 if (NULL != forwarded_host)
168 {
169 TALER_buffer_write_str (&buf, forwarded_host);
170 }
171 else
172 {
173 GNUNET_assert (NULL != host);
174 TALER_buffer_write_str (&buf, host);
175 }
176
177 uri_path = MHD_lookup_connection_value (connection, MHD_HEADER_KIND,
178 "X-Forwarded-Prefix");
179
180 if (NULL != uri_path)
181 TALER_buffer_write_path (&buf, uri_path);
182
183 if (0 != strcmp (instance_id, "default"))
184 {
185 TALER_buffer_write_path (&buf, "/instance/");
186 TALER_buffer_write_str (&buf, instance_id);
187 }
188 TALER_buffer_write_path (&buf, "");
189
190 return TALER_buffer_reap_str (&buf);
191}
192
193
194/**
142 * Transform an order into a proposal and store it in the 195 * Transform an order into a proposal and store it in the
143 * database. Write the resulting proposal or an error message 196 * database. Write the resulting proposal or an error message
144 * of a MHD connection. 197 * of a MHD connection.
@@ -286,16 +339,13 @@ proposal_put (struct MHD_Connection *connection,
286 } 339 }
287 340
288 if (NULL == json_object_get (order, 341 if (NULL == json_object_get (order,
289 "pay_url")) 342 "merchant_base_url"))
290 { 343 {
291 char *url; 344 char *url;
292 345
293 url = TALER_url_absolute_mhd (connection, 346 url = make_merchant_base_url (connection, mi->id);
294 "/public/pay",
295 NULL);
296
297 json_object_set_new (order, 347 json_object_set_new (order,
298 "pay_url", 348 "merchant_base_url",
299 json_string (url)); 349 json_string (url));
300 GNUNET_free (url); 350 GNUNET_free (url);
301 } 351 }