コード例 #1
0
ファイル: dict_mysql.c プロジェクト: TonyChengTW/Rmail
static MYSQL_RES *plmysql_query(PLMYSQL *PLDB,
                                const char *query,
                                char *dbname,
                                char *username,
                                char *password)
{
    HOST   *host;
    MYSQL_RES *res = 0;

    while ((host = dict_mysql_get_active(PLDB, dbname, username, password)) != NULL) {
        if (!(mysql_query(host->db, query))) {
            if ((res = mysql_store_result(host->db)) == 0) {
                msg_warn("mysql query failed: %s", mysql_error(host->db));
                plmysql_down_host(host);
            } else {
                if (msg_verbose)
                    msg_info("dict_mysql: successful query from host %s", host->hostname);
                event_request_timer(dict_mysql_event, (char *) host, IDLE_CONN_INTV);
                break;
            }
        } else {
            msg_warn("mysql query failed: %s", mysql_error(host->db));
            plmysql_down_host(host);
        }
    }

    return res;
}
コード例 #2
0
ファイル: dict_mysql.c プロジェクト: ajinkya93/netbsd-src
static MYSQL_RES *plmysql_query(DICT_MYSQL *dict_mysql,
				        const char *name,
				        VSTRING *query)
{
    HOST   *host;
    MYSQL_RES *res = 0;

    while ((host = dict_mysql_get_active(dict_mysql)) != NULL) {
#if defined(MYSQL_VERSION_ID) && MYSQL_VERSION_ID >= 40000

	/*
	 * The active host is used to escape strings in the context of the
	 * active connection's character encoding.
	 */
	dict_mysql->active_host = host;
	VSTRING_RESET(query);
	VSTRING_TERMINATE(query);
	db_common_expand(dict_mysql->ctx, dict_mysql->query,
			 name, 0, query, dict_mysql_quote);
	dict_mysql->active_host = 0;
#endif

	if (!(mysql_query(host->db, vstring_str(query)))) {
	    if ((res = mysql_store_result(host->db)) == 0) {
		msg_warn("mysql query failed: %s", mysql_error(host->db));
		plmysql_down_host(host);
	    } else {
		if (msg_verbose)
		    msg_info("dict_mysql: successful query from host %s", host->hostname);
		event_request_timer(dict_mysql_event, (char *) host, IDLE_CONN_INTV);
		break;
	    }
	} else {
	    msg_warn("mysql query failed: %s", mysql_error(host->db));
	    plmysql_down_host(host);
	}
    }

    return res;
}
コード例 #3
0
ファイル: dict_mysql.c プロジェクト: TonyChengTW/Rmail
/*
 * plmysql_connect_single -
 * used to reconnect to a single database when one is down or none is
 * connected yet. Log all errors and set the stat field of host accordingly
 */
static void plmysql_connect_single(HOST *host, char *dbname, char *username, char *password)
{
    if ((host->db = mysql_init(NULL)) == NULL)
        msg_fatal("dict_mysql: insufficient memory");
    if (mysql_real_connect(host->db,
                           (host->type == TYPEINET ? host->name : 0),
                           username,
                           password,
                           dbname,
                           host->port,
                           (host->type == TYPEUNIX ? host->name : 0),
                           0)) {
        if (msg_verbose)
            msg_info("dict_mysql: successful connection to host %s",
                     host->hostname);
        host->stat = STATACTIVE;
    } else {
        msg_warn("connect to mysql server %s: %s",
                 host->hostname, mysql_error(host->db));
        plmysql_down_host(host);
    }
}
コード例 #4
0
ファイル: dict_mysql.c プロジェクト: ajinkya93/netbsd-src
/*
 * plmysql_connect_single -
 * used to reconnect to a single database when one is down or none is
 * connected yet. Log all errors and set the stat field of host accordingly
 */
static void plmysql_connect_single(DICT_MYSQL *dict_mysql, HOST *host)
{
    if ((host->db = mysql_init(NULL)) == NULL)
	msg_fatal("dict_mysql: insufficient memory");
    if (dict_mysql->option_file)
	mysql_options(host->db, MYSQL_READ_DEFAULT_FILE, dict_mysql->option_file);
    if (dict_mysql->option_group)
	mysql_options(host->db, MYSQL_READ_DEFAULT_GROUP, dict_mysql->option_group);
#if defined(MYSQL_VERSION_ID) && MYSQL_VERSION_ID >= 40000
    if (dict_mysql->tls_key_file || dict_mysql->tls_cert_file ||
	dict_mysql->tls_CAfile || dict_mysql->tls_CApath || dict_mysql->tls_ciphers)
	mysql_ssl_set(host->db,
		      dict_mysql->tls_key_file, dict_mysql->tls_cert_file,
		      dict_mysql->tls_CAfile, dict_mysql->tls_CApath,
		      dict_mysql->tls_ciphers);
#if MYSQL_VERSION_ID >= 50023
    if (dict_mysql->tls_verify_cert != -1)
	mysql_options(host->db, MYSQL_OPT_SSL_VERIFY_SERVER_CERT,
		      &dict_mysql->tls_verify_cert);
#endif
#endif
    if (mysql_real_connect(host->db,
			   (host->type == TYPEINET ? host->name : 0),
			   dict_mysql->username,
			   dict_mysql->password,
			   dict_mysql->dbname,
			   host->port,
			   (host->type == TYPEUNIX ? host->name : 0),
			   0)) {
	if (msg_verbose)
	    msg_info("dict_mysql: successful connection to host %s",
		     host->hostname);
	host->stat = STATACTIVE;
    } else {
	msg_warn("connect to mysql server %s: %s",
		 host->hostname, mysql_error(host->db));
	plmysql_down_host(host);
    }
}