diff options
author | Marcello Stanisci <marcello.stanisci@inria.fr> | 2015-07-31 14:53:48 +0200 |
---|---|---|
committer | Marcello Stanisci <marcello.stanisci@inria.fr> | 2015-07-31 14:53:48 +0200 |
commit | 403e50afd96f2f3caf84c6d2c55ce4adcf026313 (patch) | |
tree | 48c18131368f6703204324da92766e78df637f98 | |
parent | 591113ccdfa19d1de0fe4ad43e27229de2b078ba (diff) | |
download | merchant-403e50afd96f2f3caf84c6d2c55ce4adcf026313.tar.gz merchant-403e50afd96f2f3caf84c6d2c55ce4adcf026313.zip |
adding /hello test for merchant MHD
-rw-r--r-- | src/backend/Makefile.am | 12 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd.c | 100 | ||||
-rw-r--r-- | src/merchant/taler_merchant_serve.c | 23 |
3 files changed, 98 insertions, 37 deletions
diff --git a/src/backend/Makefile.am b/src/backend/Makefile.am new file mode 100644 index 00000000..d16859a7 --- /dev/null +++ b/src/backend/Makefile.am | |||
@@ -0,0 +1,12 @@ | |||
1 | AM_CPPFLAGS = -I$(top_srcdir)/src/include $(POSTGRESQL_CPPFLAGS) | ||
2 | |||
3 | MERCHANT_DB = merchant_db.c merchant_db.h | ||
4 | bin_PROGRAMS = \ | ||
5 | taler-merchant-httpd | ||
6 | |||
7 | taler_merchant_httpd_SOURCES = \ | ||
8 | taler-merchant-httpd.c | ||
9 | |||
10 | taler_merchant_httpd_LDADD = \ | ||
11 | -lmicrohttpd \ | ||
12 | -lgnunetutil | ||
diff --git a/src/backend/taler-merchant-httpd.c b/src/backend/taler-merchant-httpd.c index 152f471a..eafef40b 100644 --- a/src/backend/taler-merchant-httpd.c +++ b/src/backend/taler-merchant-httpd.c | |||
@@ -20,15 +20,24 @@ | |||
20 | * @author Marcello Stanisci | 20 | * @author Marcello Stanisci |
21 | */ | 21 | */ |
22 | 22 | ||
23 | #include "platform.h" | ||
23 | #include <microhttpd.h> | 24 | #include <microhttpd.h> |
24 | #include <gnunet/gnunet_util_lib.h> | 25 | #include <gnunet/gnunet_util_lib.h> |
25 | 26 | ||
27 | /** | ||
28 | * Shorthand for exit jumps. | ||
29 | */ | ||
30 | #define EXITIF(cond) \ | ||
31 | do { \ | ||
32 | if (cond) { GNUNET_break (0); goto EXITIF_exit; } \ | ||
33 | } while (0) | ||
34 | |||
26 | // task 1. Just implement a hello world server launched a` la GNUNET | 35 | // task 1. Just implement a hello world server launched a` la GNUNET |
27 | 36 | ||
28 | /** | 37 | /** |
29 | * The port we are running on | 38 | * The port we are running on |
30 | */ | 39 | */ |
31 | static long long unsigned port; | 40 | unsigned short port; |
32 | 41 | ||
33 | /** | 42 | /** |
34 | * The MHD Daemon | 43 | * The MHD Daemon |
@@ -36,6 +45,11 @@ static long long unsigned port; | |||
36 | static struct MHD_Daemon *mhd; | 45 | static struct MHD_Daemon *mhd; |
37 | 46 | ||
38 | /** | 47 | /** |
48 | * Global return code | ||
49 | */ | ||
50 | static int result; | ||
51 | |||
52 | /** | ||
39 | * Generate the 'hello world' response | 53 | * Generate the 'hello world' response |
40 | * @param connection a MHD connection | 54 | * @param connection a MHD connection |
41 | * @param resp where to store the response for the calling function | 55 | * @param resp where to store the response for the calling function |
@@ -44,8 +58,7 @@ static struct MHD_Daemon *mhd; | |||
44 | */ | 58 | */ |
45 | 59 | ||
46 | static unsigned int | 60 | static unsigned int |
47 | generate_hello (struct MHD_Connection *connection, | 61 | generate_hello (struct MHD_Response **resp) // this parameter was preceded by a '_' in its original file. Why? |
48 | struct MHD_Response **resp) // this parameter was preceded by a '_' in its original file. Why? | ||
49 | { | 62 | { |
50 | 63 | ||
51 | const char *hello = "Hello customer"; | 64 | const char *hello = "Hello customer"; |
@@ -59,6 +72,63 @@ generate_hello (struct MHD_Connection *connection, | |||
59 | 72 | ||
60 | } | 73 | } |
61 | 74 | ||
75 | |||
76 | /** | ||
77 | * Manage a non 200 HTTP status. I.e. it shows a 'failure' page to | ||
78 | * the client | ||
79 | * @param connection the channel thorugh which send the message | ||
80 | * @status the HTTP status to examine | ||
81 | * @return GNUNET_OK on successful message sending, GNUNET_SYSERR upon error | ||
82 | * | ||
83 | */ | ||
84 | |||
85 | static int | ||
86 | failure_resp (struct MHD_Connection *connection, unsigned int status) | ||
87 | { | ||
88 | printf ("called failure mgmt\n"); | ||
89 | static char page_404[]="\ | ||
90 | <!DOCTYPE html> \ | ||
91 | <html><title>Resource not found</title><body><center> \ | ||
92 | <h3>The resource you are looking for is not found.</h3> \ | ||
93 | </center></body></html>"; | ||
94 | static char page_500[]="\ | ||
95 | <!DOCTYPE html> <html><title>Internal Server Error</title><body><center> \ | ||
96 | <h3>The server experienced an internal error and hence cannot serve your \ | ||
97 | request</h3></center></body></html>"; | ||
98 | struct MHD_Response *resp; | ||
99 | char *page; | ||
100 | size_t size; | ||
101 | #define PAGE(number) \ | ||
102 | do {page=page_ ## number; size=sizeof(page_ ## number)-1;} while(0) | ||
103 | |||
104 | GNUNET_assert (400 <= status); | ||
105 | resp = NULL; | ||
106 | switch (status) | ||
107 | { | ||
108 | case 404: | ||
109 | PAGE(404); | ||
110 | break; | ||
111 | default: | ||
112 | status = 500; | ||
113 | case 500: | ||
114 | PAGE(500); | ||
115 | } | ||
116 | #undef PAGE | ||
117 | |||
118 | EXITIF (NULL == (resp = MHD_create_response_from_buffer (size, | ||
119 | page, | ||
120 | MHD_RESPMEM_PERSISTENT))); | ||
121 | EXITIF (MHD_YES != MHD_queue_response (connection, status, resp)); | ||
122 | MHD_destroy_response (resp); | ||
123 | return GNUNET_OK; | ||
124 | |||
125 | EXITIF_exit: | ||
126 | if (NULL != resp) | ||
127 | MHD_destroy_response (resp); | ||
128 | return GNUNET_SYSERR; | ||
129 | } | ||
130 | |||
131 | |||
62 | /** | 132 | /** |
63 | * A client has requested the given url using the given method | 133 | * A client has requested the given url using the given method |
64 | * (#MHD_HTTP_METHOD_GET, #MHD_HTTP_METHOD_PUT, | 134 | * (#MHD_HTTP_METHOD_GET, #MHD_HTTP_METHOD_PUT, |
@@ -111,20 +181,23 @@ url_handler (void *cls, | |||
111 | { | 181 | { |
112 | 182 | ||
113 | unsigned int status; | 183 | unsigned int status; |
184 | unsigned int no_destroy; | ||
114 | struct MHD_Response *resp; | 185 | struct MHD_Response *resp; |
115 | 186 | ||
116 | #define URL_HELLO "/hello" | ||
117 | #define STR_404_NOTFOUND "The requested resource is not found" | ||
118 | 187 | ||
188 | printf ("hi, just called web micro server with url %s\n", url); | ||
189 | #define URL_HELLO "/hello" | ||
190 | no_destroy = 0; | ||
191 | resp = NULL; | ||
192 | status = 500; | ||
119 | if (0 == strncasecmp (url, URL_HELLO, sizeof (URL_HELLO))) | 193 | if (0 == strncasecmp (url, URL_HELLO, sizeof (URL_HELLO))) |
120 | { | 194 | { |
121 | /* parse for /contract */ | ||
122 | if (0 == strcmp (MHD_HTTP_METHOD_GET, method)) | 195 | if (0 == strcmp (MHD_HTTP_METHOD_GET, method)) |
123 | status = generate_hello (connection, &resp); //TBD | 196 | status = generate_hello (&resp); //TBD |
124 | else | 197 | else |
125 | GNUNET_break (0); /* FIXME: implement for post */ | 198 | GNUNET_break (0); |
126 | } | 199 | } |
127 | 200 | else status = 404; | |
128 | 201 | ||
129 | if (NULL != resp) | 202 | if (NULL != resp) |
130 | { | 203 | { |
@@ -156,16 +229,15 @@ int | |||
156 | main (int argc, char *const *argv) | 229 | main (int argc, char *const *argv) |
157 | { | 230 | { |
158 | 231 | ||
159 | mhd = MHD_start_daemon (MHD_USE_DEBUG, //| MHD_USE_TCP_FASTOPEN, | 232 | port = 9966; |
160 | (unsigned short) port, | 233 | mhd = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY, |
234 | port, | ||
161 | NULL, NULL, | 235 | NULL, NULL, |
162 | &url_handler, NULL, | 236 | &url_handler, NULL, |
163 | //MHD_OPTION_TCP_FASTOPEN_QUEUE_SIZE, | ||
164 | //(unsigned int) 16, | ||
165 | MHD_OPTION_END); | 237 | MHD_OPTION_END); |
166 | 238 | ||
167 | getchar (); | 239 | getchar (); |
168 | MHD_stop_daemon (daemon); | 240 | MHD_stop_daemon (mhd); |
169 | return 0; | 241 | return 0; |
170 | 242 | ||
171 | 243 | ||
diff --git a/src/merchant/taler_merchant_serve.c b/src/merchant/taler_merchant_serve.c index e6d5f887..0f00a8c2 100644 --- a/src/merchant/taler_merchant_serve.c +++ b/src/merchant/taler_merchant_serve.c | |||
@@ -1,26 +1,3 @@ | |||
1 | /* | ||
2 | This file is part of TALER | ||
3 | (C) 2014 Christian Grothoff (and other contributing authors) | ||
4 | |||
5 | TALER is free software; you can redistribute it and/or modify it under the | ||
6 | terms of the GNU General Public License as published by the Free Software | ||
7 | Foundation; either version 3, or (at your option) any later version. | ||
8 | |||
9 | TALER 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 General Public License for more details. | ||
12 | |||
13 | You should have received a copy of the GNU General Public License along with | ||
14 | TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/> | ||
15 | */ | ||
16 | |||
17 | /** | ||
18 | * @file merchant/taler_merchant_serve.c | ||
19 | * @brief Reference implementation of the merchant's HTTP interface | ||
20 | * @author Sree Harsha Totakura <sreeharsha@totakura.in> | ||
21 | */ | ||
22 | |||
23 | |||
24 | #include "platform.h" | 1 | #include "platform.h" |
25 | #include <gnunet/gnunet_util_lib.h> | 2 | #include <gnunet/gnunet_util_lib.h> |
26 | #include <microhttpd.h> | 3 | #include <microhttpd.h> |