twister

HTTP fault injector for testing
Log | Files | Refs | README | LICENSE

commit 508e39712f99f701941f49ae9a8c0b79746ad7b0
parent d174a733b719570fd7853066a3140222ee303c25
Author: Marcello Stanisci <stanisci.m@gmail.com>
Date:   Mon, 26 Feb 2018 15:34:14 +0100

indent

Diffstat:
Msrc/include/taler_twister_service.h | 35+++++++++++++++++++----------------
Msrc/test/test_twister_webserver.c | 47++++++++++++++++++++++++++++-------------------
Msrc/twister/taler-twister-service.c | 22+++++++++++-----------
Msrc/twister/taler-twister.c | 45+++++++++++++++++++++++----------------------
Msrc/twister/twister_api.c | 40++++++++++++++++++++++------------------
5 files changed, 103 insertions(+), 86 deletions(-)

diff --git a/src/include/taler_twister_service.h b/src/include/taler_twister_service.h @@ -3,19 +3,19 @@ Copyright (C) 2018 Taler Systems SA Taler is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3, or (at your - option) any later version. + it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 3, + or (at your option) any later version. Taler is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See + the GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with Taler; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. + You should have received a copy of the GNU General Public + License along with Taler; see the file COPYING. If not, + write to the Free Software Foundation, Inc., 51 Franklin + Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef TALER_TWISTER_SERVICE_H_ @@ -53,7 +53,8 @@ struct TALER_TWISTER_Handle; * @return handle to use in #TALER_TWISTER_disconnect to disconnect */ struct TALER_TWISTER_Handle * -TALER_TWISTER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg); +TALER_TWISTER_connect + (const struct GNUNET_CONFIGURATION_Handle *cfg); /** @@ -81,10 +82,11 @@ struct TALER_TWISTER_Operation; * @return operation handle (to possibly abort) */ struct TALER_TWISTER_Operation * -TALER_TWISTER_change_response_code (struct TALER_TWISTER_Handle *h, - unsigned int new_rc, - GNUNET_SCHEDULER_TaskCallback cb, - void *cb_cls); +TALER_TWISTER_change_response_code + (struct TALER_TWISTER_Handle *h, + unsigned int new_rc, + GNUNET_SCHEDULER_TaskCallback cb, + void *cb_cls); /** @@ -92,13 +94,14 @@ TALER_TWISTER_change_response_code (struct TALER_TWISTER_Handle *h, * changes requested by the operation, or not! Must be called * before the operations callback was invoked. * - * @param op operation to cancel, operation's callback will not be called + * @param op operation to cancel, operation's callback will not + * be called */ void TALER_TWISTER_cancel (struct TALER_TWISTER_Operation *op); -#if 0 /* keep Emacsens' auto-indent happy */ +#if 0 /* keep Emacsens' auto-indent happy */ { #endif #ifdef __cplusplus diff --git a/src/test/test_twister_webserver.c b/src/test/test_twister_webserver.c @@ -4,19 +4,19 @@ Copyright (C) 2018 Taler Systems SA Taler is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3, or (at your - option) any later version. + it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 3, + or (at your option) any later version. Taler is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with Taler; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. + You should have received a copy of the GNU General Public + License along with Taler; see the file COPYING. If not, + write to the Free Software Foundation, Inc., 51 Franklin + Street, Fifth Floor, Boston, MA 02110-1301, USA. */ /** @@ -37,10 +37,11 @@ #define PORT 8080 static int -answer_to_connection (void *cls, struct MHD_Connection *connection, - const char *url, const char *method, - const char *version, const char *upload_data, - size_t *upload_data_size, void **con_cls) +answer_to_connection + (void *cls, struct MHD_Connection *connection, + const char *url, const char *method, + const char *version, const char *upload_data, + size_t *upload_data_size, void **con_cls) { const char *page = "<html><body>Hello, browser!</body></html>"; struct MHD_Response *response; @@ -53,23 +54,31 @@ answer_to_connection (void *cls, struct MHD_Connection *connection, (void)upload_data_size; /* Unused. Silent compiler warning. */ (void)con_cls; /* Unused. Silent compiler warning. */ - response = - MHD_create_response_from_buffer (strlen (page), (void *) page, - MHD_RESPMEM_PERSISTENT); + response = MHD_create_response_from_buffer + (strlen (page), + (void *) page, + MHD_RESPMEM_PERSISTENT); ret = MHD_queue_response (connection, MHD_HTTP_OK, response); MHD_destroy_response (response); return ret; } - +/** + * This minimalist Web server listens on port PORT and responds + * with a HTTP status 200 OK and some static "hello world" body, + * _always_. + */ int main (void) { struct MHD_Daemon *daemon; - daemon = MHD_start_daemon (MHD_USE_AUTO | MHD_USE_INTERNAL_POLLING_THREAD, PORT, NULL, NULL, - &answer_to_connection, NULL, MHD_OPTION_END); + daemon = MHD_start_daemon (MHD_USE_AUTO + | MHD_USE_INTERNAL_POLLING_THREAD, + PORT, NULL, NULL, + &answer_to_connection, NULL, + MHD_OPTION_END); if (NULL == daemon) return 1; sleep (UINT_MAX); diff --git a/src/twister/taler-twister-service.c b/src/twister/taler-twister-service.c @@ -4,27 +4,27 @@ Copyright (C) 2018 Taler Systems SA GNUnet is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3, or (at your - option) any later version. + it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 3, + or (at your option) any later version. GNUnet is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with GNUnet; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. + You should have received a copy of the GNU General Public + License along with GNUnet; see the file COPYING. If not, + write to the Free Software Foundation, Inc., 51 Franklin + Street, Fifth Floor, Boston, MA 02110-1301, USA. */ /** * @author Martin Schanzenbach * @author Christian Grothoff * @author Marcello Stanisci * @file src/twister/taler-twister-service.c - * @brief HTTP proxy that acts as a man in the middle making changes to - * requests or responses + * @brief HTTP proxy that acts as a man in the + * middle making changes to requests or responses */ #include "platform.h" #include <microhttpd.h> diff --git a/src/twister/taler-twister.c b/src/twister/taler-twister.c @@ -3,20 +3,20 @@ Copyright (C) 2008--2014, 2016 GNUnet e.V. Copyright (C) 2018 Taler Systems SA - Taler is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3, or (at your - option) any later version. + Taler is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version + 3, or (at your option) any later version. Taler is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with Taler; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. + You should have received a copy of the GNU General Public + License along with Taler; see the file COPYING. If not, + write to the Free Software Foundation, Inc., 51 Franklin + Street, Fifth Floor, Boston, MA 02110-1301, USA. */ /** @@ -39,8 +39,8 @@ static struct TALER_TWISTER_Handle *tth; static int status; /** - * What response code value should twister hack into the connection? - * 0 for no change. + * What response code value should twister hack into the + * connection? 0 for no change. */ static unsigned int hack_response_code; @@ -106,11 +106,11 @@ run (void *cls, return; } if ( (0 != hack_response_code) && - (NULL != - TALER_TWISTER_change_response_code (tth, - hack_response_code, - &handle_acknowledgement, - NULL)) ) + (NULL != TALER_TWISTER_change_response_code + (tth, + hack_response_code, + &handle_acknowledgement, + NULL)) ) num_ops++; /* TODO: add other operations here */ @@ -135,11 +135,12 @@ main (int argc, char *const *argv) { struct GNUNET_GETOPT_CommandLineOption options[] = { - GNUNET_GETOPT_option_uint ('r', - "responsecode", - "STATUS", - gettext_noop ("set the next response code to STATUS"), - &hack_response_code), + GNUNET_GETOPT_option_uint + ('r', + "responsecode", + "STATUS", + gettext_noop ("set the next response code to STATUS"), + &hack_response_code), GNUNET_GETOPT_OPTION_END }; diff --git a/src/twister/twister_api.c b/src/twister/twister_api.c @@ -4,19 +4,19 @@ Copyright (C) 2018 Taler Systems SA Taler is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3, or (at your - option) any later version. + it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 3, + or (at your option) any later version. Taler is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with Taler; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. + You should have received a copy of the GNU General Public + License along with Taler; see the file COPYING. If not, + write to the Free Software Foundation, Inc., 51 Franklin + Street, Fifth Floor, Boston, MA 02110-1301, USA. */ /** @@ -30,7 +30,8 @@ #include "taler_twister_service.h" #include "twister.h" -#define LOG(kind,...) GNUNET_log_from (kind, "twister-api",__VA_ARGS__) +#define LOG(kind,...) \ + GNUNET_log_from (kind, "twister-api",__VA_ARGS__) @@ -208,10 +209,11 @@ TALER_TWISTER_cancel (struct TALER_TWISTER_Operation *op) * @return operation handle (to possibly abort) */ struct TALER_TWISTER_Operation * -TALER_TWISTER_change_response_code (struct TALER_TWISTER_Handle *h, - unsigned int new_rc, - GNUNET_SCHEDULER_TaskCallback cb, - void *cb_cls) +TALER_TWISTER_change_response_code + (struct TALER_TWISTER_Handle *h, + unsigned int new_rc, + GNUNET_SCHEDULER_TaskCallback cb, + void *cb_cls) { struct TALER_TWISTER_Operation *op; struct GNUNET_MQ_Envelope *env; @@ -224,11 +226,13 @@ TALER_TWISTER_change_response_code (struct TALER_TWISTER_Handle *h, GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op); - env = GNUNET_MQ_msg (src, - TWISTER_MESSAGE_TYPE_SET_RESPONSE_CODE); + /* Prepare *env*elope. */ + env = GNUNET_MQ_msg + (src, TWISTER_MESSAGE_TYPE_SET_RESPONSE_CODE); + /* Put data into the envelope. */ src->response_code = htonl ((uint32_t) new_rc); - GNUNET_MQ_send (h->mq, - env); + /* Send message. */ + GNUNET_MQ_send (h->mq, env); return op; }