Subversion Repositories RepoView

Rev

Rev 5 | Rev 13 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5 Rev 7
Line 1... Line 1...
1
/* $Id: sqlite.c 5 2024-08-20 22:43:56Z nishi $ */
1
/* $Id: sqlite.c 7 2024-08-21 01:12:44Z nishi $ */
2
 
2
 
3
#include "rv_db.h"
3
#include "rv_db.h"
4
 
4
 
5
#include "../../config.h"
5
#include "../../config.h"
6
 
6
 
Line 133... Line 133...
133
	return 0;
133
	return 0;
134
}
134
}
135
 
135
 
136
char* rv_who_has_token(const char* token) {
136
char* rv_who_has_token(const char* token) {
137
	char* err;
137
	char* err;
138
	char cbuf[2];
-
 
139
	cbuf[1] = 0;
-
 
140
	count = 0;
138
	count = 0;
141
	char* query = rv_strcat3("select * from tokens where token = '", token, "'");
139
	char* query = rv_strcat3("select * from tokens where token = '", token, "'");
142
	int ret;
140
	int ret;
143
	has_username = NULL;
141
	has_username = NULL;
144
	ret = sqlite3_exec(sql, query, sqlget, (void*)token, &err);
142
	ret = sqlite3_exec(sql, query, sqlget, (void*)token, &err);
Line 150... Line 148...
150
	return has_username;
148
	return has_username;
151
}
149
}
152
 
150
 
153
bool rv_has_token(const char* token) {
151
bool rv_has_token(const char* token) {
154
	char* err;
152
	char* err;
155
	char cbuf[2];
-
 
156
	cbuf[1] = 0;
-
 
157
	count = 0;
-
 
158
	char* query = rv_strcat3("select * from tokens where token = '", token, "'");
153
	char* query = rv_strcat3("select * from tokens where token = '", token, "'");
159
	int ret;
154
	int ret;
-
 
155
	count = 0;
160
	ret = sqlite3_exec(sql, query, sqlcount, NULL, &err);
156
	ret = sqlite3_exec(sql, query, sqlcount, NULL, &err);
161
	free(query);
157
	free(query);
162
	if(ret != SQLITE_OK) {
158
	if(ret != SQLITE_OK) {
163
		sqlite3_free(err);
159
		sqlite3_free(err);
164
	}
160
	}
165
	return count > 0;
161
	return count > 0;
166
}
162
}
167
 
163
 
-
 
164
void rv_remove_token(const char* token) {
-
 
165
	char* err;
-
 
166
	char* query = rv_strcat3("delete from tokens where token = '", token, "'");
-
 
167
	int ret;
-
 
168
	ret = sqlite3_exec(sql, query, sqlcount, NULL, &err);
-
 
169
	free(query);
-
 
170
	if(ret != SQLITE_OK) {
-
 
171
		sqlite3_free(err);
-
 
172
	}
-
 
173
}
-
 
174
 
168
bool rv_has_user(const char* username) {
175
bool rv_has_user(const char* username) {
169
	char* err;
176
	char* err;
170
	char cbuf[2];
-
 
171
	cbuf[1] = 0;
-
 
172
	count = 0;
177
	count = 0;
173
	char* esc = escape_sql(username);
178
	char* esc = escape_sql(username);
174
	char* query = rv_strcat3("select * from users where user = '", esc, "'");
179
	char* query = rv_strcat3("select * from users where user = '", esc, "'");
175
	free(esc);
180
	free(esc);
176
	int ret;
181
	int ret;