From cf0a57dfc6d50e9c24e3c38f990e665c0eaa2510 Mon Sep 17 00:00:00 2001 From: FreeArtMan Date: Thu, 9 Nov 2017 23:29:45 +0000 Subject: Added base64 encoding for TODO command --- cmd/cmd_todo.c | 27 +++++++++++++++++++++++---- cmd/cmd_todo.h | 1 + 2 files changed, 24 insertions(+), 4 deletions(-) (limited to 'cmd') diff --git a/cmd/cmd_todo.c b/cmd/cmd_todo.c index 50218b0..e90aeb7 100644 --- a/cmd/cmd_todo.c +++ b/cmd/cmd_todo.c @@ -1,12 +1,20 @@ #include "cmd_todo.h" +//https://github.com/littlstar/b64.c +//https://www.google.nl/url?sa=t&rct=j&q=&esrc=s&source=web&cd=4&cad=rja&uact=8&ved=0ahUKEwiMu9_F5ZrXAhVLOMAKHZ6NDQYQFghDMAM&url=https%3A%2F%2Fopensource.apple.com%2Fsource%2FQuickTimeStreamingServer%2FQuickTimeStreamingServer-452%2FCommonUtilitiesLib%2Fbase64.c&usg=AOvVaw3tk0M33ne4ru28Bn_R1KI3 + static int add_todo(sqlite3 *db, char *user, char *todo) { int rc; - char sql_add_table[1024]; - snprintf(sql_add_table, 1024, "INSERT INTO todo(user,todo) VALUES('%s','%s');", user, todo); + char sql_add_table[3*256]; + char *b64_user, *b64_todo; + b64_user = b64_encode(user, strlen(user)); + b64_todo = b64_encode(todo, strlen(todo)); + snprintf(sql_add_table, 1024, "INSERT INTO todo(user,todo) VALUES('%s','%s');", b64_user, b64_todo); printf("%s\n", sql_add_table); + free(b64_user); + free(b64_todo); if ((rc = sqlite3_exec(db, sql_add_table, 0, 0, 0)) != SQLITE_OK) { @@ -33,7 +41,9 @@ static int cb_list_todo_table(void *param1, int argc, char **argv, char **cname) *out = sdscat(*out, " - "); } else if (strncmp(cname[i],"todo",4) == 0) { - *out = sdscat(*out, argv[i]); + char *b64_todo = b64_decode(argv[i], strlen(argv[i])); + *out = sdscat(*out, b64_todo); + free(b64_todo); *out = sdscat(*out, "\n"); } } @@ -49,7 +59,12 @@ static int list_todo(sqlite3 *db, char *user, sds *out) char *err_msg = NULL; char sql_list_table[1024]; - snprintf(sql_list_table, 1024, "SELECT * FROM todo WHERE user='%s'", user); + char *b64_user; + + b64_user = b64_encode(user, strlen(user)); + snprintf(sql_list_table, 1024, "SELECT * FROM todo WHERE user='%s'", b64_user); + printf("%s\n",sql_list_table); + free(b64_user); if ((rc = sqlite3_exec(db, sql_list_table, cb_list_todo_table, out, &err_msg )) != SQLITE_OK) { @@ -69,7 +84,11 @@ static int del_todo(sqlite3 *db, char *user, int id) char *err_msg; char sql_del_table[1024]; + char *b64_user; + + b64_user = b64_encode(user, strlen(user)); snprintf(sql_del_table, 1024, "DELETE FROM todo WHERE user='%s' AND id=%d;", user, id); + free(b64_user); if ((rc = sqlite3_exec(db, sql_del_table, 0, 0, &err_msg )) != SQLITE_OK) { diff --git a/cmd/cmd_todo.h b/cmd/cmd_todo.h index 210529e..e78de97 100644 --- a/cmd/cmd_todo.h +++ b/cmd/cmd_todo.h @@ -15,6 +15,7 @@ #include "debug.h" #include "nbrpc_call.h" #include "sds.h" +#include "b64.h" void *cmd_todo(void *data); -- cgit v1.2.3