void init_ssl() { #ifdef ENABLE_TCMALLOC HeapLeakChecker::Disabler disabler; #endif load_ssl_library(); if ((CRYPTO_get_id_callback() == NULL) && (CRYPTO_get_locking_callback() == NULL)) { //cuint_t n; CRYPTO_set_id_callback (__get_thread_id); CRYPTO_set_locking_callback (__lock_thread); int locks_num = CRYPTO_num_locks(); ssl_lock = new KMutex[locks_num]; } }
Bool DBConnection_MYSQL::connect(char **args, int numargs) { if (isConnected) return True; if (numargs < 4) return False; char *t_dbname; t_dbname = args[1]; char *t_user; t_user = args[2]; char *t_password; t_password = args[3]; char *t_use_ssl_string; t_use_ssl_string = NULL; if (numargs >= 5) t_use_ssl_string = args[4]; // Parse args[0] to obtain the host and port. char *t_delimiter; t_delimiter = strchr(args[0], ':'); char *t_host; t_host = args[0]; char *t_port_string; t_port_string = NULL; if (t_delimiter != NULL) { t_port_string = (t_delimiter + (1 * sizeof(char))); *t_delimiter = NULL; } int t_port; t_port = 0; if (t_port_string != NULL) t_port = atoi(t_port_string); int t_use_ssl; t_use_ssl = 0; if (t_use_ssl_string != NULL && (strlen(t_use_ssl_string) != 0)) if (strcasecmp(t_use_ssl_string, "true") == 0) t_use_ssl = 1; else t_use_ssl = atoi(t_use_ssl_string); else t_use_ssl = 0; #ifndef _MOBILE if (t_use_ssl && !load_ssl_library()) { errorMessageSet("Unable to load SSL library"); return false; } #endif //initialize mysql data structure for connection if (!mysql_init(getMySQL())) return False; // MM-2011-09-09: [[ BZ 9712]] Allow the user to specify the socket or named pipe to connect with char *t_socket; if (numargs >= 6 && strlen(args[5]) != 0) t_socket = args[5]; else t_socket = NULL; // Set timeout value for TCP/IP connections to 20 seconds. // According to API docs, total effective timeout is 3 times this due to retries, // but testing on windows shows connections timing out after 20 seconds // MM-2011-09-09: Updated to allow the user to specify the read/write timeout int t_read_write_timeout; if(numargs < 7 || args[6] == NULL || strlen(args[6]) == 0 || sscanf(args[6], "%d", &t_read_write_timeout) == 0 || t_read_write_timeout < 0) t_read_write_timeout = 20; if (mysql_options(getMySQL(), MYSQL_OPT_READ_TIMEOUT, &t_read_write_timeout) || mysql_options(getMySQL(), MYSQL_OPT_WRITE_TIMEOUT, &t_read_write_timeout)) return false; // MM-2011-09-09: Allow the user to specify the auto-reconnect option. If connection to the server has been lost, // the driver will automatically try to reconnect. To prevent the reconnect hanging, set the reconnect timeout also. bool t_auto_reconnect; t_auto_reconnect = (numargs >= 8 && args[7] != NULL && strlen(args[7]) != 0 && strcasecmp(args[7], "true") == 0); if (t_auto_reconnect) if (mysql_options(getMySQL(), MYSQL_OPT_RECONNECT, &t_auto_reconnect) || mysql_options(getMySQL(), MYSQL_OPT_CONNECT_TIMEOUT, &t_read_write_timeout)) return false; //connect to mysql database. if (!mysql_real_connect(getMySQL(), t_host, t_user, t_password, t_dbname, t_port, t_socket, t_use_ssl > 0 ? CLIENT_SSL : 0)) return False; connectionType = CT_MYSQL, isConnected = True; return True; }