forked from cory/tildefriends
		
	Expose stored connections to script, and only store connections that were explicitly requested.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4131 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
		
							
								
								
									
										44
									
								
								src/ssb.db.c
									
									
									
									
									
								
							
							
						
						
									
										44
									
								
								src/ssb.db.c
									
									
									
									
									
								
							| @@ -1245,3 +1245,47 @@ JSValue tf_ssb_db_get_message_by_id( tf_ssb_t* ssb, const char* id, bool is_keys | ||||
| 	} | ||||
| 	return result; | ||||
| } | ||||
|  | ||||
| tf_ssb_db_stored_connection_t* tf_ssb_db_get_stored_connections(tf_ssb_t* ssb, int* out_count) | ||||
| { | ||||
| 	sqlite3* db = tf_ssb_get_db(ssb); | ||||
| 	tf_ssb_db_stored_connection_t* result = NULL; | ||||
| 	int count = 0; | ||||
|  | ||||
| 	sqlite3_stmt* statement; | ||||
| 	if (sqlite3_prepare(db, "SELECT host, port, key FROM connections ORDER BY host, port, key", -1, &statement, NULL) == SQLITE_OK) | ||||
| 	{ | ||||
| 		while (sqlite3_step(statement) == SQLITE_ROW) | ||||
| 		{ | ||||
| 			result = tf_resize_vec(result, sizeof(tf_ssb_db_stored_connection_t) * (count + 1)); | ||||
| 			result[count] = (tf_ssb_db_stored_connection_t) | ||||
| 			{ | ||||
| 				.port = sqlite3_column_int(statement, 1), | ||||
| 			}; | ||||
| 			snprintf(result[count].address, sizeof(result[count].address), "%s", (const char*)sqlite3_column_text(statement, 0)); | ||||
| 			snprintf(result[count].pubkey, sizeof(result[count].pubkey), "%s", (const char*)sqlite3_column_text(statement, 2)); | ||||
| 			count++; | ||||
| 		} | ||||
| 		sqlite3_finalize(statement); | ||||
| 	} | ||||
|  | ||||
| 	*out_count = count; | ||||
| 	return result; | ||||
| } | ||||
|  | ||||
| void tf_ssb_db_forget_stored_connection(tf_ssb_t* ssb, const char* address, int port, const char* pubkey) | ||||
| { | ||||
| 	sqlite3* db = tf_ssb_get_db(ssb); | ||||
| 	sqlite3_stmt* statement; | ||||
| 	if (sqlite3_prepare(db, "DELETE FROM connections WHERE host = ? AND port = ? AND key = ?", -1, &statement, NULL) == SQLITE_OK) | ||||
| 	{ | ||||
| 		if (sqlite3_bind_text(statement, 0, address, -1, NULL) != SQLITE_OK || | ||||
| 			sqlite3_bind_int(statement, 1, port) != SQLITE_OK || | ||||
| 			sqlite3_bind_text(statement, 2, pubkey, -1, NULL) != SQLITE_OK || | ||||
| 			sqlite3_step(statement) != SQLITE_DONE) | ||||
| 		{ | ||||
| 			printf("Delete stored connection: %s.\n", sqlite3_errmsg(db)); | ||||
| 		} | ||||
| 		sqlite3_finalize(statement); | ||||
| 	} | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user