--- mqtt/src/pubmqtt.c 2011/11/24 15:14:08 1.1.2.5 +++ mqtt/src/pubmqtt.c 2011/11/24 15:34:18 1.1.2.6 @@ -149,3 +149,41 @@ mqtt_rtlm_fini_session(sl_config *cfg, sqlite3 *sql, c return ret; } + +/* + * mqtt_rtlm_chk_session() Check session(s) + * + * @cfg = loaded config + * @sql = SQL handle + * @user = username + * @host = hostname + * return: -1 error, 0 not logged or >0 logged found rows + */ +int +mqtt_rtlm_chk_session(sl_config *cfg, sqlite3 *sql, const char *user, const char *host) +{ + int ret = 0; + char *str, szStmt[BUFSIZ] = { 0 }; + sqlite3_stmt *stmt; + + if (!cfg || !sql) + return -1; + + str = (char*) cfg_GetAttribute(cfg, CFG("mqtt_pub"), CFG("tbl_online")); + if (!str) { + mqtt_rtlm_log("Error:: not found topics table name"); + return -1; + } + snprintf(szStmt, sizeof szStmt, "SELECT RemoteHost, RemotePort FROM %s WHERE " + "Username = '%s' AND RemoteHost LIKE '%s';", str, user, host); + + if (sqlite3_prepare_v2(sql, szStmt, strlen(szStmt), &stmt, NULL)) { + MQTT_RTLM_LOG(sql); + return -1; + } + while (sqlite3_step(stmt) == SQLITE_ROW); + ret = sqlite3_changes(sql); + sqlite3_finalize(stmt); + + return ret; +}