diff options
Diffstat (limited to 'src/json/test_json_mhd.c')
-rw-r--r-- | src/json/test_json_mhd.c | 218 |
1 files changed, 109 insertions, 109 deletions
diff --git a/src/json/test_json_mhd.c b/src/json/test_json_mhd.c index 213b95e12..6af1edd86 100644 --- a/src/json/test_json_mhd.c +++ b/src/json/test_json_mhd.c | |||
@@ -37,69 +37,69 @@ static int global_ret; | |||
37 | 37 | ||
38 | 38 | ||
39 | static int | 39 | static int |
40 | access_handler_cb(void *cls, | 40 | access_handler_cb (void *cls, |
41 | struct MHD_Connection *connection, | 41 | struct MHD_Connection *connection, |
42 | const char *url, | 42 | const char *url, |
43 | const char *method, | 43 | const char *method, |
44 | const char *version, | 44 | const char *version, |
45 | const char *upload_data, | 45 | const char *upload_data, |
46 | size_t *upload_data_size, | 46 | size_t *upload_data_size, |
47 | void **con_cls) | 47 | void **con_cls) |
48 | { | 48 | { |
49 | int ret; | 49 | int ret; |
50 | json_t *json; | 50 | json_t *json; |
51 | struct MHD_Response *resp; | 51 | struct MHD_Response *resp; |
52 | 52 | ||
53 | json = NULL; | 53 | json = NULL; |
54 | ret = GNUNET_JSON_post_parser(MAX_SIZE, | 54 | ret = GNUNET_JSON_post_parser (MAX_SIZE, |
55 | connection, | 55 | connection, |
56 | con_cls, | 56 | con_cls, |
57 | upload_data, | 57 | upload_data, |
58 | upload_data_size, | 58 | upload_data_size, |
59 | &json); | 59 | &json); |
60 | switch (ret) | 60 | switch (ret) |
61 | { | ||
62 | case GNUNET_JSON_PR_SUCCESS: | ||
63 | if (json_equal (bigj, json)) | ||
61 | { | 64 | { |
62 | case GNUNET_JSON_PR_SUCCESS: | 65 | global_ret = 0; |
63 | if (json_equal(bigj, json)) | ||
64 | { | ||
65 | global_ret = 0; | ||
66 | } | ||
67 | else | ||
68 | { | ||
69 | GNUNET_break(0); | ||
70 | global_ret = 6; | ||
71 | } | ||
72 | json_decref(json); | ||
73 | resp = MHD_create_response_from_buffer(3, "OK\n", MHD_RESPMEM_PERSISTENT); | ||
74 | ret = MHD_queue_response(connection, MHD_HTTP_OK, resp); | ||
75 | MHD_destroy_response(resp); | ||
76 | return ret; | ||
77 | |||
78 | case GNUNET_JSON_PR_CONTINUE: | ||
79 | return MHD_YES; | ||
80 | |||
81 | case GNUNET_JSON_PR_OUT_OF_MEMORY: | ||
82 | GNUNET_break(0); | ||
83 | global_ret = 3; | ||
84 | break; | ||
85 | |||
86 | case GNUNET_JSON_PR_REQUEST_TOO_LARGE: | ||
87 | GNUNET_break(0); | ||
88 | global_ret = 4; | ||
89 | break; | ||
90 | |||
91 | case GNUNET_JSON_PR_JSON_INVALID: | ||
92 | GNUNET_break(0); | ||
93 | global_ret = 5; | ||
94 | break; | ||
95 | } | 66 | } |
96 | GNUNET_break(0); | 67 | else |
68 | { | ||
69 | GNUNET_break (0); | ||
70 | global_ret = 6; | ||
71 | } | ||
72 | json_decref (json); | ||
73 | resp = MHD_create_response_from_buffer (3, "OK\n", MHD_RESPMEM_PERSISTENT); | ||
74 | ret = MHD_queue_response (connection, MHD_HTTP_OK, resp); | ||
75 | MHD_destroy_response (resp); | ||
76 | return ret; | ||
77 | |||
78 | case GNUNET_JSON_PR_CONTINUE: | ||
79 | return MHD_YES; | ||
80 | |||
81 | case GNUNET_JSON_PR_OUT_OF_MEMORY: | ||
82 | GNUNET_break (0); | ||
83 | global_ret = 3; | ||
84 | break; | ||
85 | |||
86 | case GNUNET_JSON_PR_REQUEST_TOO_LARGE: | ||
87 | GNUNET_break (0); | ||
88 | global_ret = 4; | ||
89 | break; | ||
90 | |||
91 | case GNUNET_JSON_PR_JSON_INVALID: | ||
92 | GNUNET_break (0); | ||
93 | global_ret = 5; | ||
94 | break; | ||
95 | } | ||
96 | GNUNET_break (0); | ||
97 | return MHD_NO; | 97 | return MHD_NO; |
98 | } | 98 | } |
99 | 99 | ||
100 | 100 | ||
101 | int | 101 | int |
102 | main(int argc, const char *const argv[]) | 102 | main (int argc, const char *const argv[]) |
103 | { | 103 | { |
104 | struct MHD_Daemon *daemon; | 104 | struct MHD_Daemon *daemon; |
105 | uint16_t port; | 105 | uint16_t port; |
@@ -112,79 +112,79 @@ main(int argc, const char *const argv[]) | |||
112 | uLongf dlen; | 112 | uLongf dlen; |
113 | struct curl_slist *json_header; | 113 | struct curl_slist *json_header; |
114 | 114 | ||
115 | GNUNET_log_setup("test-json-mhd", "WARNING", NULL); | 115 | GNUNET_log_setup ("test-json-mhd", "WARNING", NULL); |
116 | global_ret = 2; | 116 | global_ret = 2; |
117 | daemon = MHD_start_daemon(MHD_USE_DUAL_STACK | MHD_USE_AUTO_INTERNAL_THREAD, | 117 | daemon = MHD_start_daemon (MHD_USE_DUAL_STACK | MHD_USE_AUTO_INTERNAL_THREAD, |
118 | 0, | 118 | 0, |
119 | NULL, | 119 | NULL, |
120 | NULL, | 120 | NULL, |
121 | &access_handler_cb, | 121 | &access_handler_cb, |
122 | NULL, | 122 | NULL, |
123 | MHD_OPTION_END); | 123 | MHD_OPTION_END); |
124 | if (NULL == daemon) | 124 | if (NULL == daemon) |
125 | return 77; | 125 | return 77; |
126 | bigj = json_object(); | 126 | bigj = json_object (); |
127 | json_object_set_new(bigj, "test", json_string("value")); | 127 | json_object_set_new (bigj, "test", json_string ("value")); |
128 | for (unsigned int i = 0; i < 1000; i++) | 128 | for (unsigned int i = 0; i < 1000; i++) |
129 | { | 129 | { |
130 | char tmp[5]; | 130 | char tmp[5]; |
131 | 131 | ||
132 | GNUNET_snprintf(tmp, sizeof(tmp), "%u", i); | 132 | GNUNET_snprintf (tmp, sizeof(tmp), "%u", i); |
133 | json_object_set_new(bigj, tmp, json_string(tmp)); | 133 | json_object_set_new (bigj, tmp, json_string (tmp)); |
134 | } | 134 | } |
135 | str = json_dumps(bigj, JSON_INDENT(2)); | 135 | str = json_dumps (bigj, JSON_INDENT (2)); |
136 | slen = strlen(str); | 136 | slen = strlen (str); |
137 | 137 | ||
138 | #ifdef compressBound | 138 | #ifdef compressBound |
139 | dlen = compressBound(slen); | 139 | dlen = compressBound (slen); |
140 | #else | 140 | #else |
141 | dlen = slen + slen / 100 + 20; | 141 | dlen = slen + slen / 100 + 20; |
142 | /* documentation says 100.1% oldSize + 12 bytes, but we | 142 | /* documentation says 100.1% oldSize + 12 bytes, but we |
143 | * should be able to overshoot by more to be safe */ | 143 | * should be able to overshoot by more to be safe */ |
144 | #endif | 144 | #endif |
145 | post_data = GNUNET_malloc(dlen); | 145 | post_data = GNUNET_malloc (dlen); |
146 | if (Z_OK != | 146 | if (Z_OK != |
147 | compress2((Bytef *)post_data, &dlen, (const Bytef *)str, slen, 9)) | 147 | compress2 ((Bytef *) post_data, &dlen, (const Bytef *) str, slen, 9)) |
148 | { | 148 | { |
149 | GNUNET_break(0); | 149 | GNUNET_break (0); |
150 | MHD_stop_daemon(daemon); | 150 | MHD_stop_daemon (daemon); |
151 | json_decref(bigj); | 151 | json_decref (bigj); |
152 | GNUNET_free(post_data); | 152 | GNUNET_free (post_data); |
153 | GNUNET_free(str); | 153 | GNUNET_free (str); |
154 | return 1; | 154 | return 1; |
155 | } | 155 | } |
156 | post_data_size = (long)dlen; | 156 | post_data_size = (long) dlen; |
157 | port = MHD_get_daemon_info(daemon, MHD_DAEMON_INFO_BIND_PORT)->port; | 157 | port = MHD_get_daemon_info (daemon, MHD_DAEMON_INFO_BIND_PORT)->port; |
158 | easy = curl_easy_init(); | 158 | easy = curl_easy_init (); |
159 | GNUNET_asprintf(&url, "http://localhost:%u/", (unsigned int)port); | 159 | GNUNET_asprintf (&url, "http://localhost:%u/", (unsigned int) port); |
160 | curl_easy_setopt(easy, CURLOPT_VERBOSE, 0); | 160 | curl_easy_setopt (easy, CURLOPT_VERBOSE, 0); |
161 | curl_easy_setopt(easy, CURLOPT_URL, url); | 161 | curl_easy_setopt (easy, CURLOPT_URL, url); |
162 | curl_easy_setopt(easy, CURLOPT_POST, 1); | 162 | curl_easy_setopt (easy, CURLOPT_POST, 1); |
163 | curl_easy_setopt(easy, CURLOPT_POSTFIELDS, post_data); | 163 | curl_easy_setopt (easy, CURLOPT_POSTFIELDS, post_data); |
164 | curl_easy_setopt(easy, CURLOPT_POSTFIELDSIZE, post_data_size); | 164 | curl_easy_setopt (easy, CURLOPT_POSTFIELDSIZE, post_data_size); |
165 | 165 | ||
166 | json_header = curl_slist_append(NULL, "Content-Type: application/json"); | 166 | json_header = curl_slist_append (NULL, "Content-Type: application/json"); |
167 | json_header = curl_slist_append(json_header, "Content-Encoding: deflate"); | 167 | json_header = curl_slist_append (json_header, "Content-Encoding: deflate"); |
168 | curl_easy_setopt(easy, CURLOPT_HTTPHEADER, json_header); | 168 | curl_easy_setopt (easy, CURLOPT_HTTPHEADER, json_header); |
169 | if (0 != curl_easy_perform(easy)) | 169 | if (0 != curl_easy_perform (easy)) |
170 | { | 170 | { |
171 | GNUNET_break(0); | 171 | GNUNET_break (0); |
172 | MHD_stop_daemon(daemon); | 172 | MHD_stop_daemon (daemon); |
173 | GNUNET_free(url); | 173 | GNUNET_free (url); |
174 | json_decref(bigj); | 174 | json_decref (bigj); |
175 | GNUNET_free(post_data); | 175 | GNUNET_free (post_data); |
176 | GNUNET_free(str); | 176 | GNUNET_free (str); |
177 | curl_slist_free_all(json_header); | 177 | curl_slist_free_all (json_header); |
178 | curl_easy_cleanup(easy); | 178 | curl_easy_cleanup (easy); |
179 | return 1; | 179 | return 1; |
180 | } | 180 | } |
181 | MHD_stop_daemon(daemon); | 181 | MHD_stop_daemon (daemon); |
182 | GNUNET_free(url); | 182 | GNUNET_free (url); |
183 | json_decref(bigj); | 183 | json_decref (bigj); |
184 | GNUNET_free(post_data); | 184 | GNUNET_free (post_data); |
185 | GNUNET_free(str); | 185 | GNUNET_free (str); |
186 | curl_slist_free_all(json_header); | 186 | curl_slist_free_all (json_header); |
187 | curl_easy_cleanup(easy); | 187 | curl_easy_cleanup (easy); |
188 | return global_ret; | 188 | return global_ret; |
189 | } | 189 | } |
190 | 190 | ||