From 479a2c3a74d45e69d953370fc04b2f79124da24e Mon Sep 17 00:00:00 2001 From: MassimilianoPinto Date: Tue, 10 Mar 2015 12:03:01 +0100 Subject: [PATCH 1/9] stdint.h added to config.h stdint.h added to config.h --- server/include/config.h | 1 + 1 file changed, 1 insertion(+) diff --git a/server/include/config.h b/server/include/config.h index 3648c97a0..ce10a03ae 100644 --- a/server/include/config.h +++ b/server/include/config.h @@ -18,6 +18,7 @@ * Copyright MariaDB Corporation Ab 2013-2014 */ #include +#include #include /** * @file config.h The configuration handling elements From bd25e2285ecea87a24db8bb184b68843e319b0c3 Mon Sep 17 00:00:00 2001 From: MassimilianoPinto Date: Tue, 10 Mar 2015 12:34:21 +0100 Subject: [PATCH 2/9] Notification service: added do_http_post Notification service: added do_http_post --- server/core/load_utils.c | 243 +++++++++++++++++++++------------------ 1 file changed, 133 insertions(+), 110 deletions(-) diff --git a/server/core/load_utils.c b/server/core/load_utils.c index d8a735ecd..264f25d84 100644 --- a/server/core/load_utils.c +++ b/server/core/load_utils.c @@ -65,6 +65,7 @@ static void register_module(const char *module, MODULE_INFO *info); static void unregister_module(const char *module); int module_create_feedback_report(GWBUF **buffer, MODULES *modules, FEEDBACK_CONF *cfg); +int do_http_post(GWBUF *buffer, void *cfg); struct MemoryStruct { char *data; @@ -568,13 +569,13 @@ module_feedback_send(void* data) { GWBUF *buffer = NULL; void *data_ptr=NULL; long http_code = 0; - struct MemoryStruct chunk; int last_action = _NOTIFICATION_SEND_PENDING; time_t now; struct tm *now_tm; int hour; int n_mod=0; char hex_setup_info[2 * SHA_DIGEST_LENGTH + 1]=""; + int http_send = 0; now = time(NULL); now_tm = localtime(&now); @@ -634,11 +635,6 @@ module_feedback_send(void* data) { "module_feedback_send(): task now runs: hour is [%d], last_action [%d]", hour, feedback_config->feedback_last_action))); - - /* allocate first memory chunck for httpd servr reply */ - chunk.data = malloc(1); /* will be grown as needed by the realloc above */ - chunk.size = 0; /* no data at this point */ - if (!module_create_feedback_report(&buffer, modules_list, feedback_config)) { LOGIF(LE, (skygw_log_write_flush( LOGFILE_ERROR, @@ -649,118 +645,27 @@ module_feedback_send(void* data) { return; } + /* try sending data via http/https post */ + http_send = do_http_post(buffer, feedback_config); - /* Initializing curl library for data send via HTTP */ - curl_global_init(CURL_GLOBAL_DEFAULT); - - curl = curl_easy_init(); - - if (curl) { - char error_message[CURL_ERROR_SIZE]=""; - - curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, error_message); - curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1); - curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, feedback_config->feedback_connect_timeout); - curl_easy_setopt(curl, CURLOPT_TIMEOUT, feedback_config->feedback_timeout); - - /* curl API call for data send via HTTP POST using a "file" type input */ - curl_formadd(&formpost, - &lastptr, - CURLFORM_COPYNAME, "data", - CURLFORM_BUFFER, "report.txt", - CURLFORM_BUFFERPTR, (char *)GWBUF_DATA(buffer), - CURLFORM_BUFFERLENGTH, strlen((char *)GWBUF_DATA(buffer)), - CURLFORM_CONTENTTYPE, "text/plain", - CURLFORM_END); - - curl_easy_setopt(curl, CURLOPT_HEADER, 1); - - /* some servers don't like requests that are made without a user-agent field, so we provide one */ - curl_easy_setopt(curl, CURLOPT_USERAGENT, "MaxScale-agent/http-1.0"); - /* Force HTTP/1.0 */ - curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); - - curl_easy_setopt(curl, CURLOPT_URL, feedback_config->feedback_url); - curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost); - -#ifdef SKIP_PEER_VERIFICATION - /* - * This makes the connection A LOT LESS SECURE. - */ - curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); -#endif - -#ifdef SKIP_HOSTNAME_VERIFICATION - /* - * this will make the connection less secure. - */ - curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L); -#endif - - /* send all data to this function */ - curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback); - - /* we pass our 'chunk' struct to the callback function */ - curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunk); - - /* Perform the request, res will get the return code */ - res = curl_easy_perform(curl); - - /* Check for errors */ - if(res != CURLE_OK) { - last_action = _NOTIFICATION_SEND_ERROR; - - LOGIF(LE, (skygw_log_write_flush( - LOGFILE_ERROR, - "Error: module_feedback_send(), curl call for [%s] failed due: %s, %s", - feedback_config->feedback_url, - curl_easy_strerror(res), - error_message))); - } else { - curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_code); - } - - if (http_code == 302) { - char *from = strstr(chunk.data, "

ok

"); - if (from) { - last_action = _NOTIFICATION_SEND_OK; - } else { - last_action = _NOTIFICATION_SEND_ERROR; - } - } else { - last_action = _NOTIFICATION_SEND_ERROR; - LOGIF(LE, (skygw_log_write_flush( - LOGFILE_ERROR, - "Error in module_feedback_send(), Bad HTTP Code from remote server: %lu", - http_code))); - } + if (http_send == 0) { + feedback_config->feedback_last_action = _NOTIFICATION_SEND_OK; } else { - LOGIF(LE, (skygw_log_write_flush( - LOGFILE_ERROR, - "Error in module_feedback_send(), curl object not initialized"))); - last_action = _NOTIFICATION_SEND_ERROR; - } + feedback_config->feedback_last_action = _NOTIFICATION_SEND_ERROR; - /* update last action in the config struct */ - feedback_config->feedback_last_action = last_action; + LOGIF(LT, (skygw_log_write_flush( + LOGFILE_TRACE, + "Error in module_create_feedback_report(): do_http_post ret_code is %d", http_send))); + } LOGIF(LT, (skygw_log_write_flush( LOGFILE_TRACE, - "module_feedback_send(): task run result: hour is [%d], last_action [%d], HTTP code [%d]", - hour, feedback_config->feedback_last_action, http_code))); + "module_feedback_send(): task completed: hour is [%d], last_action [%d]", + hour, + feedback_config->feedback_last_action))); - if (chunk.data) - free(chunk.data); + gwbuf_free(buffer); - if (buffer) - gwbuf_free(buffer); - - if (curl) { - curl_easy_cleanup(curl); - curl_formfree(formpost); - } - - curl_global_cleanup(); } /** @@ -865,3 +770,121 @@ module_create_feedback_report(GWBUF **buffer, MODULES *modules, FEEDBACK_CONF *c return 1; } +/** + * Send data to notification service via http/https + * + * @param buffer The GWBUF with data to send + * @param cfg The configuration details of notification service + * @return 0 on success, != 0 on failure + */ +int +do_http_post(GWBUF *buffer, void *cfg) { + CURL *curl = NULL; + CURLcode res; + struct curl_httppost *formpost=NULL; + struct curl_httppost *lastptr=NULL; + long http_code = 0; + struct MemoryStruct chunk; + int ret_code = 1; + + FEEDBACK_CONF *feedback_config = (FEEDBACK_CONF *) cfg; + + /* allocate first memory chunck for httpd servr reply */ + chunk.data = malloc(1); /* will be grown as needed by the realloc above */ + chunk.size = 0; /* no data at this point */ + + /* Initializing curl library for data send via HTTP */ + curl_global_init(CURL_GLOBAL_DEFAULT); + + curl = curl_easy_init(); + + if (curl) { + char error_message[CURL_ERROR_SIZE]=""; + + curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, error_message); + curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1); + curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, feedback_config->feedback_connect_timeout); + curl_easy_setopt(curl, CURLOPT_TIMEOUT, feedback_config->feedback_timeout); + + /* curl API call for data send via HTTP POST using a "file" type input */ + curl_formadd(&formpost, + &lastptr, + CURLFORM_COPYNAME, "data", + CURLFORM_BUFFER, "report.txt", + CURLFORM_BUFFERPTR, (char *)GWBUF_DATA(buffer), + CURLFORM_BUFFERLENGTH, strlen((char *)GWBUF_DATA(buffer)), + CURLFORM_CONTENTTYPE, "text/plain", + CURLFORM_END); + + curl_easy_setopt(curl, CURLOPT_HEADER, 1); + + /* some servers don't like requests that are made without a user-agent field, so we provide one */ + curl_easy_setopt(curl, CURLOPT_USERAGENT, "MaxScale-agent/http-1.0"); + /* Force HTTP/1.0 */ + curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); + + curl_easy_setopt(curl, CURLOPT_URL, feedback_config->feedback_url); + curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost); + + /* send all data to this function */ + curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback); + + /* we pass our 'chunk' struct to the callback function */ + curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunk); + + /* Perform the request, res will get the return code */ + res = curl_easy_perform(curl); + + /* Check for errors */ + if(res != CURLE_OK) { + ret_code = 2; + + LOGIF(LE, (skygw_log_write_flush( + LOGFILE_ERROR, + "Error: do_http_post(), curl call for [%s] failed due: %s, %s", + feedback_config->feedback_url, + curl_easy_strerror(res), + error_message))); + } else { + curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_code); + } + + if (http_code == 302) { + char *from = strstr(chunk.data, "

ok

"); + if (from) { + ret_code = 0; + } else { + ret_code = 3; + } + } else { + LOGIF(LE, (skygw_log_write_flush( + LOGFILE_ERROR, + "Error: do_http_post(), Bad HTTP Code from remote server: %lu", + http_code))); + ret_code = 4; + } + } else { + LOGIF(LE, (skygw_log_write_flush( + LOGFILE_ERROR, + "Error: do_http_post(), curl object not initialized"))); + ret_code = 1; + } + + LOGIF(LT, (skygw_log_write_flush( + LOGFILE_TRACE, + "do_http_post() ret_code [%d], HTTP code [%d]", + ret_code, http_code))); + + if (chunk.data) + free(chunk.data); + + if (curl) { + curl_easy_cleanup(curl); + curl_formfree(formpost); + } + + curl_global_cleanup(); + + return ret_code; +} + From 52918e904a94c30af6a9d50b6013d46d3731026a Mon Sep 17 00:00:00 2001 From: MassimilianoPinto Date: Tue, 10 Mar 2015 13:13:36 +0100 Subject: [PATCH 3/9] Coverity fix 88048 Coverity fix 88048 --- server/core/load_utils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/core/load_utils.c b/server/core/load_utils.c index 264f25d84..2298df581 100644 --- a/server/core/load_utils.c +++ b/server/core/load_utils.c @@ -714,7 +714,7 @@ module_create_feedback_report(GWBUF **buffer, MODULES *modules, FEEDBACK_CONF *c report_max_bytes = ((n_mod * 4) + 7) * (_NOTIFICATION_REPORT_ROW_LEN + 1); *buffer = gwbuf_alloc(report_max_bytes); - if (buffer == NULL) { + if (*buffer == NULL) { return 0; } From e1a522051af1c365218395f0763c3b5b05009a4b Mon Sep 17 00:00:00 2001 From: MassimilianoPinto Date: Tue, 10 Mar 2015 13:34:46 +0100 Subject: [PATCH 4/9] Notification Server URL update Notification Server URL update --- Documentation/Tutorials/Notification-Service.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/Tutorials/Notification-Service.md b/Documentation/Tutorials/Notification-Service.md index 4cfc89cd2..fb59bd28d 100644 --- a/Documentation/Tutorials/Notification-Service.md +++ b/Documentation/Tutorials/Notification-Service.md @@ -37,7 +37,7 @@ This feature is not enabled by default: MaxScale must be configured in [feedback [feedback] feedback_enable=1 - feedback_url=https://mariadb.org/feedback_plugin/post + feedback_url=https://enterprise.mariadb.com/feedback/post feedback_user_info=x-y-z-w The activation code that will be provided by MariaDB corp upon request by the customer and it shlud be put in feedback_user_info. From e937947f0185144e02cdfd8ea2d44d01fc062818 Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Tue, 10 Mar 2015 15:16:52 +0200 Subject: [PATCH 5/9] Added test_utils.h header which contains a testing environment initialization function. --- server/core/test/testfeedback.c | 3 ++- server/core/test/testservice.c | 25 ++++++++++++------------- server/include/test_utils.h | 26 ++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 14 deletions(-) create mode 100644 server/include/test_utils.h diff --git a/server/core/test/testfeedback.c b/server/core/test/testfeedback.c index 9e84b5cb2..883840f77 100644 --- a/server/core/test/testfeedback.c +++ b/server/core/test/testfeedback.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -47,7 +48,7 @@ int main(int argc, char** argv) GWBUF* buf; regex_t re; - hkinit(); +init_test_env(); home = getenv("MAXSCALE_HOME"); if(home == NULL) diff --git a/server/core/test/testservice.c b/server/core/test/testservice.c index ef2560481..ca6fe6618 100644 --- a/server/core/test/testservice.c +++ b/server/core/test/testservice.c @@ -31,11 +31,9 @@ #include #include #include +#include #include -#include -#include -#include "housekeeper.h" static bool success = false; @@ -58,17 +56,18 @@ DCB *dcb; int result; int argc = 3; -char* argv[] = -{ - "log_manager", - "-j", - TEST_LOG_DIR, - NULL -}; +init_test_env(); +/* char* argv[] = */ +/* { */ +/* "log_manager", */ +/* "-j", */ +/* TEST_LOG_DIR, */ +/* NULL */ +/* }; */ -skygw_logmanager_init(argc,argv); -poll_init(); -hkinit(); +/* skygw_logmanager_init(argc,argv); */ +/* poll_init(); */ +/* hkinit(); */ /* Service tests */ ss_dfprintf(stderr, diff --git a/server/include/test_utils.h b/server/include/test_utils.h new file mode 100644 index 000000000..538c5d101 --- /dev/null +++ b/server/include/test_utils.h @@ -0,0 +1,26 @@ +#ifndef TEST_UTILS_H +#define TEST_UTILS_H +#include +#include +#include +#include +#include + +void init_test_env() +{ + int argc = 3; + + char* argv[] = + { + "log_manager", + "-j", + TEST_LOG_DIR, + NULL + }; + + skygw_logmanager_init(argc,argv); + poll_init(); + hkinit(); +} + +#endif From fbedad84af15a1c752f89a4e436382a1b4d9dfb5 Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Tue, 10 Mar 2015 17:08:04 +0200 Subject: [PATCH 6/9] Fixes to Coverity defects. --- server/core/config.c | 4 ++-- server/core/dbusers.c | 2 +- server/core/load_utils.c | 8 +++++++- .../modules/routing/maxinfo/maxinfo_parse.c | 4 +++- .../routing/schemarouter/schemarouter.c | 17 +++++++++-------- .../routing/schemarouter/shardrouter.c | 19 +++++++++---------- .../schemarouter/test/testschemarouter2.c | 2 +- 7 files changed, 32 insertions(+), 24 deletions(-) diff --git a/server/core/config.c b/server/core/config.c index db9d38fed..7723ae596 100644 --- a/server/core/config.c +++ b/server/core/config.c @@ -2138,7 +2138,7 @@ config_get_release_string(char* release) *end = 0; to = strcpy(distribution, "lsb: "); - memmove(to, found, end - found + 1); + memmove(to, found, end - found + 1 < INT_MAX ? end - found + 1 : INT_MAX); strncpy(release, to, _RELEASE_STR_LENGTH); @@ -2175,7 +2175,7 @@ config_get_release_string(char* release) +5 and -8 below cut the file name part out of the full pathname that corresponds to the mask as above. */ - new_to = strcpy(distribution, found.gl_pathv[0] + 5); + new_to = strncpy(distribution, found.gl_pathv[0] + 5,_RELEASE_STR_LENGTH - 1); new_to += 8; *new_to++ = ':'; *new_to++ = ' '; diff --git a/server/core/dbusers.c b/server/core/dbusers.c index 9f4528eb5..d2211ac6e 100644 --- a/server/core/dbusers.c +++ b/server/core/dbusers.c @@ -798,7 +798,7 @@ getUsers(SERVICE *service, USERS *users) if (db_grants) { /* we have dbgrants, store them */ if(row[5]){ - strcpy(dbnm,row[5]); + strncpy(dbnm,row[5],MYSQL_DATABASE_MAXLEN); if(service->strip_db_esc) { strip_escape_chars(dbnm); } diff --git a/server/core/load_utils.c b/server/core/load_utils.c index 2298df581..6238c1255 100644 --- a/server/core/load_utils.c +++ b/server/core/load_utils.c @@ -690,6 +690,8 @@ module_create_feedback_report(GWBUF **buffer, MODULES *modules, FEEDBACK_CONF *c time_t now; struct tm *now_tm; int report_max_bytes=0; + if(buffer == NULL) + return 0; now = time(NULL); @@ -838,13 +840,13 @@ do_http_post(GWBUF *buffer, void *cfg) { /* Check for errors */ if(res != CURLE_OK) { ret_code = 2; - LOGIF(LE, (skygw_log_write_flush( LOGFILE_ERROR, "Error: do_http_post(), curl call for [%s] failed due: %s, %s", feedback_config->feedback_url, curl_easy_strerror(res), error_message))); + goto cleanup; } else { curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_code); } @@ -855,6 +857,7 @@ do_http_post(GWBUF *buffer, void *cfg) { ret_code = 0; } else { ret_code = 3; + goto cleanup; } } else { LOGIF(LE, (skygw_log_write_flush( @@ -862,18 +865,21 @@ do_http_post(GWBUF *buffer, void *cfg) { "Error: do_http_post(), Bad HTTP Code from remote server: %lu", http_code))); ret_code = 4; + goto cleanup; } } else { LOGIF(LE, (skygw_log_write_flush( LOGFILE_ERROR, "Error: do_http_post(), curl object not initialized"))); ret_code = 1; + goto cleanup; } LOGIF(LT, (skygw_log_write_flush( LOGFILE_TRACE, "do_http_post() ret_code [%d], HTTP code [%d]", ret_code, http_code))); + cleanup: if (chunk.data) free(chunk.data); diff --git a/server/modules/routing/maxinfo/maxinfo_parse.c b/server/modules/routing/maxinfo/maxinfo_parse.c index d7035dcc2..9eb445a22 100644 --- a/server/modules/routing/maxinfo/maxinfo_parse.c +++ b/server/modules/routing/maxinfo/maxinfo_parse.c @@ -126,7 +126,7 @@ MAXINFO_TREE *col, *table; /** * Parse a column list, may be a * or a valid list of string name - * seperated by a comma + * separated by a comma * * @param sql Pointer to pointer to column list updated to point to the table name * @return A tree of column names @@ -148,9 +148,11 @@ MAXINFO_TREE * rval = NULL; case LT_COMMA: rval = make_tree_node(MAXOP_COLUMNS, text, NULL, parse_column_list(ptr)); + break; case LT_FROM: rval = make_tree_node(MAXOP_COLUMNS, text, NULL, NULL); + break; default: break; } diff --git a/server/modules/routing/schemarouter/schemarouter.c b/server/modules/routing/schemarouter/schemarouter.c index d2e7de4e8..4baa795b3 100644 --- a/server/modules/routing/schemarouter/schemarouter.c +++ b/server/modules/routing/schemarouter/schemarouter.c @@ -1632,7 +1632,7 @@ gen_show_dbs_response(ROUTER_INSTANCE* router, ROUTER_CLIENT_SES* client) rval = gwbuf_append(rval, last_packet); rval = gwbuf_make_contiguous(rval); - + hashtable_iterator_free(iter); return rval; } @@ -2224,19 +2224,20 @@ static void clientReply ( goto lock_failed; } bref = get_bref_from_dcb(router_cli_ses, backend_dcb); - skygw_log_write(LOGFILE_DEBUG,"schemarouter: Received reply from %s for session %p", - bref->bref_backend->backend_server->unique_name, - router_cli_ses->rses_client_dcb->session); -#if !defined(FOR_BUG548_FIX_ONLY) - /** This makes the issue becoming visible in poll.c */ + if (bref == NULL) { /** Unlock router session */ rses_end_locked_router_action(router_cli_ses); goto lock_failed; } -#endif + skygw_log_write(LOGFILE_DEBUG,"schemarouter: Received reply from %s for session %p", + bref->bref_backend->backend_server->unique_name, + router_cli_ses->rses_client_dcb->session); + + + if(router_cli_ses->init & INIT_MAPPING) { bool mapped = true, logged = false; @@ -3905,7 +3906,7 @@ static bool handle_error_new_connection( skygw_log_write(LOGFILE_TRACE,"schemarouter: Re-mapping databases"); gen_databaselist(rses->router,rses); - + hashtable_iterator_free(iter); return_succp: return succp; } diff --git a/server/modules/routing/schemarouter/shardrouter.c b/server/modules/routing/schemarouter/shardrouter.c index 8b82e4b3c..c4a9e88ed 100644 --- a/server/modules/routing/schemarouter/shardrouter.c +++ b/server/modules/routing/schemarouter/shardrouter.c @@ -274,7 +274,8 @@ char* get_lenenc_str(void* data, int* len) if(data == NULL || len == NULL) { - *len = -1; + if(len) + *len = -1; return NULL; } @@ -1099,7 +1100,8 @@ return_rses: } #endif errorblock: - if(client_rses->subservice) + + if(client_rses && client_rses->subservice) { for(j = 0; j < i; j++) { @@ -1661,14 +1663,7 @@ routeQuery(ROUTER* instance, ret = 1; } - else - { - /** Something else went wrong, terminate connection */ - ret = 0; - } - goto retblock; - } } @@ -2794,6 +2789,9 @@ get_shard_subsvc(SUBSERVICE** subsvc,ROUTER_CLIENT_SES* session,char* target) { int i; + if(subsvc == NULL || session == NULL || target == NULL) + return false; + for(i = 0;in_subservice;i++) { if(strcmp(session->subservice[i]->service->name,target) == 0) @@ -2859,7 +2857,7 @@ router_handle_state_switch( CHK_DCB(dcb); return rc; - +#if 0 if(SERVER_IS_RUNNING(srv) && SERVER_IS_IN_CLUSTER(srv)) { goto return_rc; @@ -2882,6 +2880,7 @@ router_handle_state_switch( return_rc: return rc; +#endif } /** diff --git a/server/modules/routing/schemarouter/test/testschemarouter2.c b/server/modules/routing/schemarouter/test/testschemarouter2.c index 00c0a5bf6..a7dd1d94d 100644 --- a/server/modules/routing/schemarouter/test/testschemarouter2.c +++ b/server/modules/routing/schemarouter/test/testschemarouter2.c @@ -78,7 +78,7 @@ int main(int argc, char** argv) goto report; } - sprintf(query,"STOP SLAVE",databases[i]); + sprintf(query,"STOP SLAVE"); if(mysql_real_query(server,query,strlen(query))) { fprintf(stderr, "Failed to stop slave in %d: %s.\n", From 2f3c380df8b9632507db9c84c87ac69a86b18b69 Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Tue, 10 Mar 2015 17:23:41 +0200 Subject: [PATCH 7/9] Updated feedback test. --- server/core/test/testfeedback.c | 77 ++++++++++++++++++++++----------- 1 file changed, 51 insertions(+), 26 deletions(-) diff --git a/server/core/test/testfeedback.c b/server/core/test/testfeedback.c index 883840f77..68c6c6916 100644 --- a/server/core/test/testfeedback.c +++ b/server/core/test/testfeedback.c @@ -21,65 +21,90 @@ * @verbatim * Revision History * - * Date Who Description - * 09-03-2015 Markus Mäkelä Initial implementation + * Date Who Description + * 09-03-2015 Markus Mäkelä Initial implementation + * 10-03-2015 Massimiliano Pinto Added http_check * * @endverbatim */ -#define FAILTEST(s) printf("TEST FAILED: " s "\n");return 1; - +#define FAILTEST(s) printf("TEST FAILED: " s "\n");return 1; +#include +#include #include #include #include #include #include #include -#include #include #include #include +static char* server_options[] = { + "MariaDB Corporation MaxScale", + "--no-defaults", + "--datadir=", + "--language=", + "--skip-innodb", + "--default-storage-engine=myisam", + NULL +}; + +const int num_elements = (sizeof(server_options) / sizeof(char *)) - 1; + +static char* server_groups[] = { + "embedded", + "server", + "server", + "embedded", + "server", + "server", + NULL +}; + + int main(int argc, char** argv) { FEEDBACK_CONF* fc; - char* home; - char* cnf; GWBUF* buf; regex_t re; + char* home; + char* cnf; -init_test_env(); - home = getenv("MAXSCALE_HOME"); + hkinit(); - if(home == NULL) + mysql_library_init(num_elements, server_options, server_groups); + + if ((fc = config_get_feedback_data()) == NULL) { - FAILTEST("MAXSCALE_HOME was not defined."); + FAILTEST("Configuration for Feedback was NULL."); } - printf("Home: %s\n",home); - cnf = malloc(strlen(home) + strlen("/etc/MaxScale.cnf") + 1); - strcpy(cnf,home); - strcat(cnf,"/etc/MaxScale.cnf"); + fc->feedback_enable = 1; + fc->feedback_user_info = "TEST_user_info"; + fc->mac_sha1 = "TEST_user_info"; + fc->feedback_url = "http://127.0.0.1/post.php"; - printf("Config: %s\n",cnf); - - config_load(cnf); - - if((fc = config_get_feedback_data()) == NULL || - fc->feedback_user_info == NULL) - { - FAILTEST("Configuration was NULL."); - } + fc->feedback_last_action = _NOTIFICATION_SEND_PENDING; + fc->feedback_timeout = _NOTIFICATION_OPERATION_TIMEOUT; + fc->feedback_connect_timeout = _NOTIFICATION_CONNECT_TIMEOUT; + fc->release_info = ""; + fc->sysname=""; regcomp(&re,fc->feedback_user_info,0); module_create_feedback_report(&buf,NULL,fc); - printf("%s",(char*)buf->start); if(regexec(&re,(char*)buf->start,0,NULL,0)) { FAILTEST("Regex match of 'user_info' failed."); } + if (do_http_post(buf, fc) != 0) + { + FAILTEST("Http send failed\n"); + } + return 0; -} +} \ No newline at end of file From 11f1ed6a2c25f40d69d18a4151b228103f4e294e Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Tue, 10 Mar 2015 17:29:55 +0200 Subject: [PATCH 8/9] Small fix to test. --- server/core/test/testfeedback.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/server/core/test/testfeedback.c b/server/core/test/testfeedback.c index 68c6c6916..90c7c4a6d 100644 --- a/server/core/test/testfeedback.c +++ b/server/core/test/testfeedback.c @@ -73,24 +73,30 @@ int main(int argc, char** argv) char* cnf; hkinit(); + home = getenv("MAXSCALE_HOME"); - mysql_library_init(num_elements, server_options, server_groups); + if(home == NULL) + { + FAILTEST("MAXSCALE_HOME was not defined."); + } + printf("Home: %s\n",home); + + cnf = malloc(strlen(home) + strlen("/etc/MaxScale.cnf") + 1); + strcpy(cnf,home); + strcat(cnf,"/etc/MaxScale.cnf"); + + printf("Config: %s\n",cnf); + + + mysql_library_init(num_elements, server_options, server_groups); + + config_load(cnf); if ((fc = config_get_feedback_data()) == NULL) { FAILTEST("Configuration for Feedback was NULL."); } - fc->feedback_enable = 1; - fc->feedback_user_info = "TEST_user_info"; - fc->mac_sha1 = "TEST_user_info"; - fc->feedback_url = "http://127.0.0.1/post.php"; - - fc->feedback_last_action = _NOTIFICATION_SEND_PENDING; - fc->feedback_timeout = _NOTIFICATION_OPERATION_TIMEOUT; - fc->feedback_connect_timeout = _NOTIFICATION_CONNECT_TIMEOUT; - fc->release_info = ""; - fc->sysname=""; regcomp(&re,fc->feedback_user_info,0); From 2c31666efa807c7d46b8ffc17b7ad28412b2f311 Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Wed, 11 Mar 2015 06:51:55 +0200 Subject: [PATCH 9/9] Added a configurable frequecy for the feedback task. --- server/core/config.c | 9 +++++++-- server/include/notification.h | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/server/core/config.c b/server/core/config.c index 7723ae596..156558add 100644 --- a/server/core/config.c +++ b/server/core/config.c @@ -1338,6 +1338,10 @@ int i; { feedback.feedback_connect_timeout = atoi(value); } + if (strcmp(name, "feedback_frequency") == 0) + { + feedback.feedback_frequency = atoi(value); + } return 1; } @@ -1389,6 +1393,7 @@ feedback_defaults() feedback.feedback_timeout = _NOTIFICATION_OPERATION_TIMEOUT; feedback.feedback_connect_timeout = _NOTIFICATION_CONNECT_TIMEOUT; feedback.feedback_url = NULL; + feedback.feedback_frequency = 1800; feedback.release_info = gateway.release_string; feedback.sysname = gateway.sysname; feedback.mac_sha1 = gateway.mac_sha1; @@ -2221,14 +2226,14 @@ config_enable_feedback_task(void) { if (enable_set && url_set && user_info_set) { /* Add the task to the tasl list */ - if (hktask_add("send_feedback", module_feedback_send, cfg, 1800)) { + if (hktask_add("send_feedback", module_feedback_send, cfg, cfg->feedback_frequency)) { LOGIF(LM, (skygw_log_write_flush( LOGFILE_MESSAGE, "Notification service feedback task started: URL=%s, User-Info=%s, Frequency %u seconds", cfg->feedback_url, cfg->feedback_user_info, - 1800))); + cfg->feedback_frequency))); } } else { if (enable_set) { diff --git a/server/include/notification.h b/server/include/notification.h index 6a7f07bac..6e40f5aee 100644 --- a/server/include/notification.h +++ b/server/include/notification.h @@ -52,6 +52,7 @@ typedef struct { int feedback_timeout; /**< An attempt to write/read the data times out and fails after this many seconds */ int feedback_connect_timeout; /**< An attempt to send the data times out and fails after this many seconds */ int feedback_last_action; /**< Holds the feedback last send action status */ + int feedback_frequency; /*< Frequency of the housekeeper task */ char *release_info; /**< Operating system Release name */ char *sysname; /**< Operating system name */ uint8_t *mac_sha1; /**< First available MAC address*/