Lines Matching refs:state

266 db_connect(mysql_data_t *state, mysql_instance_t *dbi) {
276 if (state->log != NULL)
277 state->log(ISC_LOG_INFO, "%s: init connection %d ",
280 conn = mysql_real_connect(dbi->sock, state->db_host,
281 state->db_user, state->db_pass,
282 state->db_name, 0, NULL,
285 if (state->log != NULL)
286 state->log(ISC_LOG_ERROR,
299 get_dbi(mysql_data_t *state) {
306 if (dlz_mutex_trylock(&state->db[i].mutex) == 0)
311 if (state->debug && state->log != NULL)
312 state->log(ISC_LOG_ERROR,
316 return (&state->db[i]);
373 build_query(mysql_data_t *state, mysql_instance_t *dbi,
387 dbi = get_dbi(state);
394 if (!db_connect(state, dbi))
551 validate_txn(mysql_data_t *state, mysql_transaction_t *txn) {
555 dlz_mutex_lock(&state->tx_mutex);
556 for (txp = state->transactions; txp != NULL; txp = txp->next) {
562 dlz_mutex_unlock(&state->tx_mutex);
564 if (result != ISC_R_SUCCESS && state->log != NULL)
565 state->log(ISC_LOG_ERROR, "%s: invalid txn %x", modname, txn);
571 db_execute(mysql_data_t *state, mysql_instance_t *dbi, const char *query) {
575 if (!db_connect(state, dbi))
580 if (state->debug && state->log != NULL)
581 state->log(ISC_LOG_ERROR,
587 if (state->debug && state->log != NULL)
588 state->log(ISC_LOG_INFO, "%s: execute(%d) %s",
595 db_query(mysql_data_t *state, mysql_instance_t *dbi, const char *query) {
605 dbi = get_dbi(state);
612 if (!db_connect(state, dbi))
615 result = db_execute(state, dbi, query);
621 if (state->log != NULL)
622 state->log(ISC_LOG_ERROR,
628 if (state->debug && state->log != NULL)
629 state->log(ISC_LOG_INFO,
723 notify(mysql_data_t *state, const char *zone, int sn) {
734 query = build_query(state, NULL, Q_GETNS, zone);
735 res = db_query(state, NULL, query);
788 if (state->log != NULL)
789 state->log(ISC_LOG_INFO,
807 makerecord(mysql_data_t *state, const char *name, const char *rdatastr) {
816 if (state->log != NULL)
817 state->log(ISC_LOG_ERROR,
825 if (state->log != NULL)
826 state->log(ISC_LOG_ERROR,
878 b9_add_helper(mysql_data_t *state, const char *helper_name, void *ptr) {
880 state->log = (log_t *)ptr;
882 state->putrr = (dns_sdlz_putrr_t *)ptr;
884 state->putnamedrr = (dns_sdlz_putnamedrr_t *)ptr;
886 state->writeable_zone = (dns_dlz_writeablezone_t *)ptr;
910 mysql_data_t *state;
917 state = calloc(1, sizeof(mysql_data_t));
918 if (state == NULL)
921 dlz_mutex_init(&state->tx_mutex, NULL);
922 state->transactions = NULL;
927 b9_add_helper(state, helper_name, va_arg(ap, void *));
930 if (state->log != NULL)
931 state->log(ISC_LOG_INFO, "loading %s module", modname);
934 if (state->log != NULL)
935 state->log(ISC_LOG_ERROR,
938 dlz_destroy(state);
942 state->db_name = strdup(argv[1]);
944 state->db_host = strdup(argv[2]);
946 state->db_user = strdup(argv[3]);
947 state->db_pass = strdup(argv[4]);
949 state->db_user = strdup("bind");
950 state->db_pass = strdup("");
953 state->db_host = strdup("localhost");
954 state->db_user = strdup("bind");
955 state->db_pass = strdup("");
958 if (state->log != NULL)
959 state->log(ISC_LOG_INFO,
961 modname, state->db_name,
962 state->db_host, state->db_user);
965 * Assign the 'state' to dbdata so we get it in our callbacks
969 dlz_mutex_lock(&state->tx_mutex);
977 dlz_mutex_init(&state->db[n].mutex, NULL);
978 dlz_mutex_lock(&state->db[n].mutex);
979 state->db[n].id = n;
980 state->db[n].connected = 0;
981 state->db[n].sock = mysql_init(NULL);
982 mysql_options(state->db[n].sock,
985 mysql_options(state->db[n].sock,
987 dlz_mutex_unlock(&state->db[n].mutex);
990 *dbdata = state;
991 dlz_mutex_unlock(&state->tx_mutex);
995 free(state->db_name);
996 free(state->db_host);
997 free(state->db_user);
998 free(state->db_pass);
999 dlz_mutex_destroy(&state->tx_mutex);
1000 free(state);
1009 mysql_data_t *state = (mysql_data_t *)dbdata;
1012 if (state->debug && state->log != NULL)
1013 state->log(ISC_LOG_INFO, "%s: shutting down", modname);
1016 if (state->db[i].sock) {
1017 mysql_close(state->db[i].sock);
1018 state->db[i].sock=NULL;
1021 free(state->db_name);
1022 free(state->db_host);
1023 free(state->db_user);
1024 free(state->db_pass);
1025 dlz_mutex_destroy(&state->tx_mutex);
1026 free(state);
1038 mysql_data_t *state = (mysql_data_t *)dbdata;
1043 query = build_query(state, NULL, Q_FINDZONE, name);
1048 res = db_query(state, NULL, query);
1068 mysql_data_t *state = (mysql_data_t *)dbdata;
1077 if (state->putrr == NULL) {
1078 if (state->log != NULL)
1079 state->log(ISC_LOG_ERROR,
1088 if (txn != NULL && validate_txn(state, txn) == ISC_R_SUCCESS)
1091 state->log(ISC_LOG_DEBUG(1),
1114 query = build_query(state, dbi, Q_GETSOA, zone);
1120 res = db_query(state, dbi, query);
1141 result = state->putrr(lookup, "soa", ttl, data);
1154 query = build_query(state, dbi, Q_GETAPEX, zone, real_name);
1156 query = build_query(state, dbi, Q_GETNODE, zone, real_name);
1158 res = db_query(state, dbi, query);
1169 result = state->putrr(lookup, row[0], ttl, row[1]);
1179 if (state->debug && state->log != NULL)
1180 state->log(ISC_LOG_INFO,
1199 mysql_data_t *state = (mysql_data_t *)dbdata;
1201 if (state->debug && state->log != NULL)
1202 state->log(ISC_LOG_INFO,
1215 mysql_data_t *state = (mysql_data_t *)dbdata;
1222 if (state->debug && (state->log != NULL))
1223 state->log(ISC_LOG_INFO, "dlz_allnodes: %s", zone);
1225 if (state->putnamedrr == NULL)
1231 query = build_query(state, NULL, Q_GETALL, zone);
1235 res = db_query(state, NULL, query);
1246 result = state->putnamedrr(allnodes, hostname,
1262 mysql_data_t *state = (mysql_data_t *) dbdata;
1272 query = build_query(state, NULL, Q_WRITEABLE, zone);
1276 res = db_query(state, NULL, query);
1292 dlz_mutex_lock(&state->tx_mutex);
1293 for (txn = state->transactions; txn != NULL; txn = txn->next) {
1295 if (state->log != NULL)
1296 state->log(ISC_LOG_ERROR,
1299 dlz_mutex_unlock(&state->tx_mutex);
1311 newtx->dbi = get_dbi(state);
1319 result = db_execute(state, newtx->dbi, "START TRANSACTION");
1328 newtx->next = state->transactions;
1329 state->transactions = newtx;
1331 if (state->debug && (state->log != NULL))
1332 state->log(ISC_LOG_INFO, "%s: New tx %x", modname, newtx);
1335 dlz_mutex_unlock(&state->tx_mutex);
1339 dlz_mutex_unlock(&state->tx_mutex);
1356 mysql_data_t *state = (mysql_data_t *)dbdata;
1366 dlz_mutex_lock(&state->tx_mutex);
1367 if (state->transactions == txn) {
1369 state->transactions = txn->next;
1371 txp = state->transactions;
1390 dlz_mutex_unlock(&state->tx_mutex);
1400 query = build_query(state, txn->dbi, Q_GETSERIAL, zone);
1401 if (query == NULL && state->log != NULL) {
1402 state->log(ISC_LOG_ERROR,
1409 res = db_query(state, txn->dbi, query);
1419 result = db_execute(state, txn->dbi, "COMMIT");
1420 if (result != ISC_R_SUCCESS && state->log != NULL) {
1421 state->log(ISC_LOG_INFO,
1427 if (state->debug && state->log != NULL)
1428 state->log(ISC_LOG_INFO,
1436 query = build_query(state, txn->dbi, Q_GETSERIAL, zone);
1437 res = db_query(state, txn->dbi, query);
1450 notify(state, zone, newsn);
1452 result = db_execute(state, txn->dbi, "ROLLBACK");
1453 if (state->debug && (state->log != NULL))
1454 state->log(ISC_LOG_INFO,
1483 mysql_data_t *state = (mysql_data_t *)dbdata;
1494 if (state->debug && state->log != NULL)
1495 state->log(ISC_LOG_INFO, "%s: dlz_confgure", modname);
1497 if (state->writeable_zone == NULL) {
1498 if (state->log != NULL)
1499 state->log(ISC_LOG_ERROR,
1508 res = db_query(state, NULL, Q_GETZONES);
1516 notify(state, row[0], sn);
1517 result = state->writeable_zone(view,
1523 if (state->log != NULL)
1524 state->log(ISC_LOG_ERROR,
1534 if (state->debug && state->log != NULL)
1535 state->log(ISC_LOG_INFO,
1548 mysql_data_t *state = (mysql_data_t *)dbdata;
1556 if (state->debug && state->log != NULL)
1557 state->log(ISC_LOG_INFO,
1567 mysql_data_t *state = (mysql_data_t *)dbdata;
1580 if (state->debug && (state->log != NULL))
1581 state->log(ISC_LOG_INFO, "%s: add (%x) %s (as %s) %s",
1584 record = makerecord(state, new_name, rdatastr);
1591 query = build_query(state, txn->dbi, I_DATA,
1599 result = db_execute(state, txn->dbi, query);
1609 query = build_query(state, txn->dbi, U_SERIAL, sn,
1615 result = db_execute(state, txn->dbi, query);
1628 mysql_data_t *state = (mysql_data_t *)dbdata;
1641 if (state->debug && (state->log != NULL))
1642 state->log(ISC_LOG_INFO, "%s: sub (%x) %s %s",
1645 record = makerecord(state, new_name, rdatastr);
1655 query = build_query(state, txn->dbi, D_RECORD,
1664 result = db_execute(state, txn->dbi, query);
1677 mysql_data_t *state = (mysql_data_t *)dbdata;
1689 if (state->debug && (state->log != NULL))
1690 state->log(ISC_LOG_INFO, "%s: del (%x) %s %s",
1693 query = build_query(state, txn->dbi, D_RRSET,
1700 result = db_execute(state, txn->dbi, query);