version 1.2.2.3, 2012/04/11 15:08:27
|
version 1.2.2.4, 2012/04/25 07:37:16
|
Line 39 mqtt_rtlm_open(cfg_root_t *cfg)
|
Line 39 mqtt_rtlm_open(cfg_root_t *cfg)
|
if (!cfg) |
if (!cfg) |
return NULL; |
return NULL; |
|
|
/* | sqlite3_config(SQLITE_CONFIG_SERIALIZED); |
if (!sqlite3_threadsafe() || sqlite3_config(SQLITE_CONFIG_SERIALIZED)) | if (!sqlite3_threadsafe()) |
return NULL; |
return NULL; |
*/ |
|
|
|
str = cfg_getAttribute(cfg, "mqtt_pub", "name"); |
str = cfg_getAttribute(cfg, "mqtt_pub", "name"); |
if (!str) { |
if (!str) { |
Line 56 mqtt_rtlm_open(cfg_root_t *cfg)
|
Line 55 mqtt_rtlm_open(cfg_root_t *cfg)
|
return NULL; |
return NULL; |
} |
} |
|
|
|
sqlite3_mutex_enter(sqlite3_db_mutex(sql)); |
if (sqlite3_exec(sql, sql_schema, NULL, NULL, NULL)) { |
if (sqlite3_exec(sql, sql_schema, NULL, NULL, NULL)) { |
MQTT_RTLM_LOG(sql); |
MQTT_RTLM_LOG(sql); |
|
sqlite3_mutex_leave(sqlite3_db_mutex(sql)); |
sqlite3_close(sql); |
sqlite3_close(sql); |
return NULL; |
return NULL; |
} |
} |
|
sqlite3_mutex_leave(sqlite3_db_mutex(sql)); |
return sql; |
return sql; |
} |
} |
|
|
Line 118 mqtt_rtlm_init_session(cfg_root_t *cfg, sqlite3 *sql,
|
Line 120 mqtt_rtlm_init_session(cfg_root_t *cfg, sqlite3 *sql,
|
va_end(lst); |
va_end(lst); |
} |
} |
|
|
|
sqlite3_mutex_enter(sqlite3_db_mutex(sql)); |
if (sqlite3_prepare_v2(sql, szStmt, strlen(szStmt), &stmt, NULL)) { |
if (sqlite3_prepare_v2(sql, szStmt, strlen(szStmt), &stmt, NULL)) { |
MQTT_RTLM_LOG(sql); |
MQTT_RTLM_LOG(sql); |
|
sqlite3_mutex_leave(sqlite3_db_mutex(sql)); |
return -1; |
return -1; |
} |
} |
if ((ret = sqlite3_step(stmt)) == SQLITE_DONE) |
if ((ret = sqlite3_step(stmt)) == SQLITE_DONE) |
Line 130 mqtt_rtlm_init_session(cfg_root_t *cfg, sqlite3 *sql,
|
Line 134 mqtt_rtlm_init_session(cfg_root_t *cfg, sqlite3 *sql,
|
ret = 0; |
ret = 0; |
} |
} |
sqlite3_finalize(stmt); |
sqlite3_finalize(stmt); |
|
sqlite3_mutex_leave(sqlite3_db_mutex(sql)); |
|
|
return ret; |
return ret; |
} |
} |
Line 162 mqtt_rtlm_fini_session(cfg_root_t *cfg, sqlite3 *sql,
|
Line 167 mqtt_rtlm_fini_session(cfg_root_t *cfg, sqlite3 *sql,
|
snprintf(szStmt, sizeof szStmt, "DELETE FROM %s WHERE ConnID = '%s' AND Username = '%s' " |
snprintf(szStmt, sizeof szStmt, "DELETE FROM %s WHERE ConnID = '%s' AND Username = '%s' " |
"AND RemoteHost LIKE '%s';", str, connid, user, host); |
"AND RemoteHost LIKE '%s';", str, connid, user, host); |
|
|
|
sqlite3_mutex_enter(sqlite3_db_mutex(sql)); |
if (sqlite3_prepare_v2(sql, szStmt, strlen(szStmt), &stmt, NULL)) { |
if (sqlite3_prepare_v2(sql, szStmt, strlen(szStmt), &stmt, NULL)) { |
MQTT_RTLM_LOG(sql); |
MQTT_RTLM_LOG(sql); |
|
sqlite3_mutex_leave(sqlite3_db_mutex(sql)); |
return -1; |
return -1; |
} |
} |
if ((ret = sqlite3_step(stmt)) == SQLITE_DONE) |
if ((ret = sqlite3_step(stmt)) == SQLITE_DONE) |
Line 174 mqtt_rtlm_fini_session(cfg_root_t *cfg, sqlite3 *sql,
|
Line 181 mqtt_rtlm_fini_session(cfg_root_t *cfg, sqlite3 *sql,
|
ret = 0; |
ret = 0; |
} |
} |
sqlite3_finalize(stmt); |
sqlite3_finalize(stmt); |
|
sqlite3_mutex_leave(sqlite3_db_mutex(sql)); |
|
|
return ret; |
return ret; |
} |
} |
Line 207 mqtt_rtlm_chk_session(cfg_root_t *cfg, sqlite3 *sql, c
|
Line 215 mqtt_rtlm_chk_session(cfg_root_t *cfg, sqlite3 *sql, c
|
"ConnID = '%s' AND Username = '%s' AND RemoteHost LIKE '%s';", |
"ConnID = '%s' AND Username = '%s' AND RemoteHost LIKE '%s';", |
str, connid, user, host); |
str, connid, user, host); |
|
|
|
sqlite3_mutex_enter(sqlite3_db_mutex(sql)); |
if (sqlite3_prepare_v2(sql, szStmt, strlen(szStmt), &stmt, NULL)) { |
if (sqlite3_prepare_v2(sql, szStmt, strlen(szStmt), &stmt, NULL)) { |
MQTT_RTLM_LOG(sql); |
MQTT_RTLM_LOG(sql); |
|
sqlite3_mutex_leave(sqlite3_db_mutex(sql)); |
return -1; |
return -1; |
} |
} |
if (sqlite3_step(stmt) == SQLITE_ROW) |
if (sqlite3_step(stmt) == SQLITE_ROW) |
Line 216 mqtt_rtlm_chk_session(cfg_root_t *cfg, sqlite3 *sql, c
|
Line 226 mqtt_rtlm_chk_session(cfg_root_t *cfg, sqlite3 *sql, c
|
else |
else |
ret = 0; |
ret = 0; |
sqlite3_finalize(stmt); |
sqlite3_finalize(stmt); |
|
sqlite3_mutex_leave(sqlite3_db_mutex(sql)); |
|
|
return ret; |
return ret; |
} |
} |
Line 254 mqtt_rtlm_write_topic(cfg_root_t *cfg, sqlite3 *sql, u
|
Line 265 mqtt_rtlm_write_topic(cfg_root_t *cfg, sqlite3 *sql, u
|
"datetime('now', 'localtime'), '%s');", |
"datetime('now', 'localtime'), '%s');", |
str, retain, msgid, topic, txt, user, host); |
str, retain, msgid, topic, txt, user, host); |
|
|
|
sqlite3_mutex_enter(sqlite3_db_mutex(sql)); |
if (sqlite3_prepare_v2(sql, szStmt, strlen(szStmt), &stmt, NULL)) { |
if (sqlite3_prepare_v2(sql, szStmt, strlen(szStmt), &stmt, NULL)) { |
MQTT_RTLM_LOG(sql); |
MQTT_RTLM_LOG(sql); |
|
sqlite3_mutex_leave(sqlite3_db_mutex(sql)); |
return -1; |
return -1; |
} |
} |
if ((ret = sqlite3_step(stmt)) == SQLITE_DONE) |
if ((ret = sqlite3_step(stmt)) == SQLITE_DONE) |
Line 266 mqtt_rtlm_write_topic(cfg_root_t *cfg, sqlite3 *sql, u
|
Line 279 mqtt_rtlm_write_topic(cfg_root_t *cfg, sqlite3 *sql, u
|
ret = 0; |
ret = 0; |
} |
} |
sqlite3_finalize(stmt); |
sqlite3_finalize(stmt); |
|
sqlite3_mutex_leave(sqlite3_db_mutex(sql)); |
|
|
return ret; |
return ret; |
} |
} |
Line 313 mqtt_rtlm_delete_topic(cfg_root_t *cfg, sqlite3 *sql,
|
Line 327 mqtt_rtlm_delete_topic(cfg_root_t *cfg, sqlite3 *sql,
|
"PubUser LIKE '%s' AND PubHost LIKE '%s' %s;", str, |
"PubUser LIKE '%s' AND PubHost LIKE '%s' %s;", str, |
msgid, topic, user, host, rtn); |
msgid, topic, user, host, rtn); |
|
|
|
sqlite3_mutex_enter(sqlite3_db_mutex(sql)); |
if (sqlite3_prepare_v2(sql, szStmt, strlen(szStmt), &stmt, NULL)) { |
if (sqlite3_prepare_v2(sql, szStmt, strlen(szStmt), &stmt, NULL)) { |
MQTT_RTLM_LOG(sql); |
MQTT_RTLM_LOG(sql); |
|
sqlite3_mutex_leave(sqlite3_db_mutex(sql)); |
return -1; |
return -1; |
} |
} |
if ((ret = sqlite3_step(stmt)) == SQLITE_DONE) |
if ((ret = sqlite3_step(stmt)) == SQLITE_DONE) |
Line 325 mqtt_rtlm_delete_topic(cfg_root_t *cfg, sqlite3 *sql,
|
Line 341 mqtt_rtlm_delete_topic(cfg_root_t *cfg, sqlite3 *sql,
|
ret = 0; |
ret = 0; |
} |
} |
sqlite3_finalize(stmt); |
sqlite3_finalize(stmt); |
|
sqlite3_mutex_leave(sqlite3_db_mutex(sql)); |
|
|
return ret; |
return ret; |
} |
} |
Line 372 mqtt_rtlm_read_topic(cfg_root_t *cfg, sqlite3 *sql, u_
|
Line 389 mqtt_rtlm_read_topic(cfg_root_t *cfg, sqlite3 *sql, u_
|
"MsgID = %d AND Topic LIKE '%s' %s;", |
"MsgID = %d AND Topic LIKE '%s' %s;", |
str, msgid, topic, szStr); |
str, msgid, topic, szStr); |
|
|
|
sqlite3_mutex_enter(sqlite3_db_mutex(sql)); |
if (sqlite3_prepare_v2(sql, szStmt, strlen(szStmt), &stmt, NULL)) { |
if (sqlite3_prepare_v2(sql, szStmt, strlen(szStmt), &stmt, NULL)) { |
MQTT_RTLM_LOG(sql); |
MQTT_RTLM_LOG(sql); |
|
sqlite3_mutex_leave(sqlite3_db_mutex(sql)); |
return NULL; |
return NULL; |
} |
} |
|
|
Line 397 mqtt_rtlm_read_topic(cfg_root_t *cfg, sqlite3 *sql, u_
|
Line 416 mqtt_rtlm_read_topic(cfg_root_t *cfg, sqlite3 *sql, u_
|
} |
} |
end: |
end: |
sqlite3_finalize(stmt); |
sqlite3_finalize(stmt); |
|
sqlite3_mutex_leave(sqlite3_db_mutex(sql)); |
|
|
return s; |
return s; |
} |
} |
Line 434 mqtt_rtlm_write_subscribe(cfg_root_t *cfg, sqlite3 *sq
|
Line 454 mqtt_rtlm_write_subscribe(cfg_root_t *cfg, sqlite3 *sq
|
"datetime('now', 'localtime'), '%s');", str, |
"datetime('now', 'localtime'), '%s');", str, |
msgid, qos, topic, user, host); |
msgid, qos, topic, user, host); |
|
|
|
sqlite3_mutex_enter(sqlite3_db_mutex(sql)); |
if (sqlite3_prepare_v2(sql, szStmt, strlen(szStmt), &stmt, NULL)) { |
if (sqlite3_prepare_v2(sql, szStmt, strlen(szStmt), &stmt, NULL)) { |
MQTT_RTLM_LOG(sql); |
MQTT_RTLM_LOG(sql); |
|
sqlite3_mutex_leave(sqlite3_db_mutex(sql)); |
return -1; |
return -1; |
} |
} |
if ((ret = sqlite3_step(stmt)) == SQLITE_DONE) |
if ((ret = sqlite3_step(stmt)) == SQLITE_DONE) |
Line 446 mqtt_rtlm_write_subscribe(cfg_root_t *cfg, sqlite3 *sq
|
Line 468 mqtt_rtlm_write_subscribe(cfg_root_t *cfg, sqlite3 *sq
|
ret = 0; |
ret = 0; |
} |
} |
sqlite3_finalize(stmt); |
sqlite3_finalize(stmt); |
|
sqlite3_mutex_leave(sqlite3_db_mutex(sql)); |
|
|
return ret; |
return ret; |
} |
} |
Line 483 mqtt_rtlm_delete_subscribe(cfg_root_t *cfg, sqlite3 *s
|
Line 506 mqtt_rtlm_delete_subscribe(cfg_root_t *cfg, sqlite3 *s
|
"PubUser LIKE '%s' AND PubHost LIKE '%s' %s;", str, |
"PubUser LIKE '%s' AND PubHost LIKE '%s' %s;", str, |
topic, user, host, szStr); |
topic, user, host, szStr); |
|
|
|
sqlite3_mutex_enter(sqlite3_db_mutex(sql)); |
if (sqlite3_prepare_v2(sql, szStmt, strlen(szStmt), &stmt, NULL)) { |
if (sqlite3_prepare_v2(sql, szStmt, strlen(szStmt), &stmt, NULL)) { |
MQTT_RTLM_LOG(sql); |
MQTT_RTLM_LOG(sql); |
|
sqlite3_mutex_leave(sqlite3_db_mutex(sql)); |
return -1; |
return -1; |
} |
} |
if ((ret = sqlite3_step(stmt)) == SQLITE_DONE) |
if ((ret = sqlite3_step(stmt)) == SQLITE_DONE) |
Line 495 mqtt_rtlm_delete_subscribe(cfg_root_t *cfg, sqlite3 *s
|
Line 520 mqtt_rtlm_delete_subscribe(cfg_root_t *cfg, sqlite3 *s
|
ret = 0; |
ret = 0; |
} |
} |
sqlite3_finalize(stmt); |
sqlite3_finalize(stmt); |
|
sqlite3_mutex_leave(sqlite3_db_mutex(sql)); |
|
|
return ret; |
return ret; |
} |
} |
Line 526 mqtt_rtlm_read_subscribe(cfg_root_t *cfg, sqlite3 *sql
|
Line 552 mqtt_rtlm_read_subscribe(cfg_root_t *cfg, sqlite3 *sql
|
} |
} |
snprintf(szStmt, sizeof szStmt, "SELECT QoS, Topic FROM %s WHERE Topic LIKE '%s';", str, topic); |
snprintf(szStmt, sizeof szStmt, "SELECT QoS, Topic FROM %s WHERE Topic LIKE '%s';", str, topic); |
|
|
|
sqlite3_mutex_enter(sqlite3_db_mutex(sql)); |
if (sqlite3_prepare_v2(sql, szStmt, strlen(szStmt), &stmt, NULL)) { |
if (sqlite3_prepare_v2(sql, szStmt, strlen(szStmt), &stmt, NULL)) { |
MQTT_RTLM_LOG(sql); |
MQTT_RTLM_LOG(sql); |
|
sqlite3_mutex_leave(sqlite3_db_mutex(sql)); |
return NULL; |
return NULL; |
} |
} |
|
|
Line 551 mqtt_rtlm_read_subscribe(cfg_root_t *cfg, sqlite3 *sql
|
Line 579 mqtt_rtlm_read_subscribe(cfg_root_t *cfg, sqlite3 *sql
|
} |
} |
end: |
end: |
sqlite3_finalize(stmt); |
sqlite3_finalize(stmt); |
|
sqlite3_mutex_leave(sqlite3_db_mutex(sql)); |
|
|
return s; |
return s; |
} |
} |