[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-anastasis] 01/04: fixed ugly thing
From: |
gnunet |
Subject: |
[taler-anastasis] 01/04: fixed ugly thing |
Date: |
Tue, 25 Aug 2020 14:48:51 +0200 |
This is an automated email from the git hooks/post-receive script.
dennis-neufeld pushed a commit to branch master
in repository anastasis.
commit e25bd2af3a887a7445818e0953b11bd8effe5a4d
Author: Dennis Neufeld <dennis.neufeld@students.bfh.ch>
AuthorDate: Sat Aug 22 17:00:47 2020 +0000
fixed ugly thing
---
src/cli/anastasis-cli-assembler.c | 8 +--
src/cli/anastasis-cli-splitter.c | 138 ++++++++++++++++++++++++++------------
src/include/anastasis.h | 2 +-
3 files changed, 100 insertions(+), 48 deletions(-)
diff --git a/src/cli/anastasis-cli-assembler.c
b/src/cli/anastasis-cli-assembler.c
index cabd4fe..44a7bec 100644
--- a/src/cli/anastasis-cli-assembler.c
+++ b/src/cli/anastasis-cli-assembler.c
@@ -225,9 +225,7 @@ challenge_answer_cb (void *af_cls,
return;
}
printf ("Success truth#%u\n", cs->challenge_index);
- unsigned int *solved = GNUNET_new (unsigned int);
- *solved = 1;
- challenges[cs->challenge_index].solved = solved;
+ challenges[cs->challenge_index].solved = 1;
}
@@ -308,7 +306,7 @@ read_keyboard_command (void *cls)
for (unsigned int i = 0; i < challenges_length; i++)
{
char solved_state = '-';
- if (*challenges[i].solved == 1)
+ if (challenges[i].solved == 1)
solved_state = '+';
printf ("truth#%u(%c): %s %s ",
i,
@@ -411,7 +409,7 @@ read_keyboard_command (void *cls)
if (0 == memcmp (&policies[i].nonces[j],
challenges[k].nonce,
sizeof(struct ANASTASIS_CRYPTO_NonceP)))
- if (1 != *challenges[k].solved)
+ if (1 != challenges[k].solved)
printf ("truth#%u ", k);
}
}
diff --git a/src/cli/anastasis-cli-splitter.c b/src/cli/anastasis-cli-splitter.c
index ba8a5a0..a2cbd85 100644
--- a/src/cli/anastasis-cli-splitter.c
+++ b/src/cli/anastasis-cli-splitter.c
@@ -741,7 +741,7 @@ read_keyboard_command (void *cls)
"Unknown command '%c'\n",
buffer[0]);
free (buffer);
- buffer = (char *)NULL;
+ buffer = (char *) NULL;
break;
}
start_read_keyboard ();
@@ -771,7 +771,7 @@ read_keyboard_command (void *cls)
printf ("Please add a server before!\n");
free (buffer);
- buffer = (char *)NULL;
+ buffer = (char *) NULL;
start_read_keyboard ();
return;
}
@@ -783,12 +783,13 @@ read_keyboard_command (void *cls)
struct SaltState *ss = GNUNET_new (struct SaltState);
size_t url_len = characters - strlen ("server add ");
- if (0 == url_len ||
- characters < strlen ("server add "))
+ if ((0 == url_len)||
+ (characters < strlen ("server add ")))
{
- printf ("Sorry, something went wrong with your command: Server Url
missing.\n");
+ printf (
+ "Sorry, something went wrong with your command: Server Url
missing.\n");
free (buffer);
- buffer = (char *)NULL;
+ buffer = (char *) NULL;
keyboard_task = NULL;
start_read_keyboard ();
return;
@@ -812,7 +813,7 @@ read_keyboard_command (void *cls)
{
GNUNET_break (0);
free (buffer);
- buffer = (char *)NULL;
+ buffer = (char *) NULL;
keyboard_task = NULL;
return;
}
@@ -849,7 +850,7 @@ read_keyboard_command (void *cls)
printf ("Please add a truth before!\n");
free (buffer);
- buffer = (char *)NULL;
+ buffer = (char *) NULL;
keyboard_task = NULL;
start_read_keyboard ();
return;
@@ -863,16 +864,35 @@ read_keyboard_command (void *cls)
struct TruthUploadState *tus = GNUNET_new (struct TruthUploadState);
char *truth_details = &buffer[strlen ("truth add ")];
char *token = strtok (truth_details, " ");
- int server_num;
+ if (! token)
+ {
+ printf ("Sorry, something went wrong with your command: Server is
missing.\n");
+ printf ("Example: truth add server#0 question \"question\"
\"answer\"\n");
+ free (buffer);
+ buffer = (char *) NULL;
+ keyboard_task = NULL;
+ start_read_keyboard ();
+ return;
+ }
+ unsigned int server_num;
tus->secret_question = NULL;
tus->secret_answer = NULL;
tus->instructions = NULL;
-
if (0 == strncmp ("server#",
token,
strlen ("server#")))
{
server_num = (int) token[strlen ("server#")] - 48;
+ if (server_num > servers_length)
+ {
+ printf ("Sorry, something went wrong with your command: Server
number is missing.\n");
+ printf ("Example: truth add server#0 question \"question\"
\"answer\"\n");
+ free (buffer);
+ buffer = (char *) NULL;
+ keyboard_task = NULL;
+ start_read_keyboard ();
+ return;
+ }
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"At %s:%d server is %s\n", __FILE__, __LINE__,
token);
@@ -880,11 +900,11 @@ read_keyboard_command (void *cls)
"At %s:%d server number is %u\n", __FILE__, __LINE__,
server_num);
token = strtok (NULL, " ");
- if (!token)
+ if (! token)
{
- printf ("Sorry, something went wrong with your command.\n");
+ printf ("Sorry, something went wrong with your command: Method is
missing.\n");
free (buffer);
- buffer = (char *)NULL;
+ buffer = (char *) NULL;
keyboard_task = NULL;
start_read_keyboard ();
return;
@@ -902,11 +922,12 @@ read_keyboard_command (void *cls)
if (0 == strcmp ("question", tus->method))
{
token = strtok (NULL, "\"");
- if (!token)
+ if (! token)
{
- printf ("Sorry, something went wrong with your command.\n");
+ printf ("Sorry, something went wrong with your command: Question
is missing.\n");
+ printf ("Example: truth add server#0 question \"question\"
\"answer\"\n");
free (buffer);
- buffer = (char *)NULL;
+ buffer = (char *) NULL;
keyboard_task = NULL;
start_read_keyboard ();
return;
@@ -921,11 +942,12 @@ read_keyboard_command (void *cls)
token = strtok (NULL, "\"");
token = strtok (NULL, "\"");
- if (!token)
+ if (! token)
{
- printf ("Sorry, something went wrong with your command.\n");
+ printf ("Sorry, something went wrong with your command: Answer
is missing.\n");
+ printf ("Example: truth add server#0 question \"question\"
\"answer\"\n");
free (buffer);
- buffer = (char *)NULL;
+ buffer = (char *) NULL;
keyboard_task = NULL;
start_read_keyboard ();
return;
@@ -942,7 +964,7 @@ read_keyboard_command (void *cls)
tus->truth_data = tus->secret_answer;
tus->truth_data_size = strlen (tus->secret_answer);
}
- if (0 == strcmp ("sms", tus->method))
+ else if (0 == strcmp ("sms", tus->method))
{
token = strtok (NULL, " ");
tus->phone = GNUNET_malloc (strlen (token) + 1);
@@ -954,6 +976,18 @@ read_keyboard_command (void *cls)
tus->truth_data = tus->phone;
tus->truth_data_size = strlen (tus->phone);
}
+ else
+ {
+ printf ("Sorry, server#%u does not support '%s'\n",
+ server_num,
+ tus->method);
+ free (buffer);
+ buffer = (char *) NULL;
+ keyboard_task = NULL;
+ start_read_keyboard ();
+ return;
+ }
+
json_error_t error;
if (NULL == (tus->id_data = json_load_file (import_id,
JSON_DECODE_ANY,
@@ -967,11 +1001,14 @@ read_keyboard_command (void *cls)
error.column,
error.position);
free (buffer);
- buffer = (char *)NULL;
+ buffer = (char *) NULL;
GNUNET_SCHEDULER_shutdown ();
return;
}
tus->index = tu_states_length;
+ GNUNET_array_append (tu_states,
+ tu_states_length,
+ *tus);
tus->tuo = ANASTASIS_truth_upload (ctx,
servers[server_num].user_id,
servers[server_num].backend_url,
@@ -990,17 +1027,14 @@ read_keyboard_command (void *cls)
{
GNUNET_break (0);
free (buffer);
- buffer = (char *)NULL;
+ buffer = (char *) NULL;
return;
}
- GNUNET_array_append (tu_states,
- tu_states_length,
- *tus);
printf ("Truth #%u added for server #%u\n",
tus->index,
server_num);
free (buffer);
- buffer = (char *)NULL;
+ buffer = (char *) NULL;
return;
}
else
@@ -1008,12 +1042,22 @@ read_keyboard_command (void *cls)
server_num,
tus->method);
}
+ else
+ {
+ printf ("Sorry, something went wrong with your command: Server is not
correct.\n");
+ printf ("Example: truth add server#0 question \"question\"
\"answer\"\n");
+ free (buffer);
+ buffer = (char *) NULL;
+ keyboard_task = NULL;
+ start_read_keyboard ();
+ return;
+ }
}
else
printf ("Please add a server before!\n");
free (buffer);
- buffer = (char *)NULL;
+ buffer = (char *) NULL;
keyboard_task = NULL;
start_read_keyboard ();
return;
@@ -1047,7 +1091,7 @@ read_keyboard_command (void *cls)
printf ("Please add a truth before!\n");
free (buffer);
- buffer = (char *)NULL;
+ buffer = (char *) NULL;
start_read_keyboard ();
return;
}
@@ -1075,7 +1119,7 @@ read_keyboard_command (void *cls)
else
printf ("Please add a policy before!\n");
free (buffer);
- buffer = (char *)NULL;
+ buffer = (char *) NULL;
start_read_keyboard ();
return;
}
@@ -1095,16 +1139,26 @@ read_keyboard_command (void *cls)
{
printf ("Wrong argument: %s!\n", token);
free (buffer);
- buffer = (char *)NULL;
+ buffer = (char *) NULL;
start_read_keyboard ();
return;
}
tus_index = (int) token[strlen ("truth#")] - 48;
-
- GNUNET_array_append (pcs->tu_states,
- pcs->tu_states_len,
- &tu_states[tus_index]);
- token = strtok (NULL, " ");
+ if (tus_index < tu_states_length)
+ {
+ GNUNET_array_append (pcs->tu_states,
+ pcs->tu_states_len,
+ &tu_states[tus_index]);
+ token = strtok (NULL, " ");
+ }
+ else
+ {
+ printf ("Wrong argument: truth#%i not existing!\n", tus_index);
+ free (buffer);
+ buffer = (char *) NULL;
+ start_read_keyboard ();
+ return;
+ }
}
GNUNET_array_append (pc_states,
@@ -1113,7 +1167,7 @@ read_keyboard_command (void *cls)
printf ("Policy #%u defined\n",
(pc_states_length > 0) ? pc_states_length - 1 : 0);
free (buffer);
- buffer = (char *)NULL;
+ buffer = (char *) NULL;
start_read_keyboard ();
return;
}
@@ -1155,7 +1209,7 @@ read_keyboard_command (void *cls)
error.column,
error.position);
free (buffer);
- buffer = (char *)NULL;
+ buffer = (char *) NULL;
GNUNET_SCHEDULER_shutdown ();
return;
}
@@ -1199,7 +1253,7 @@ read_keyboard_command (void *cls)
characters);
pds[i]->payment_order_id = (const char *) payment_order_id;
free (buffer);
- buffer = (char *)NULL;
+ buffer = (char *) NULL;
}
printf ("\n");
}
@@ -1222,15 +1276,15 @@ read_keyboard_command (void *cls)
{
GNUNET_break (0);
free (buffer);
- buffer = (char *)NULL;
+ buffer = (char *) NULL;
return;
}
free (buffer);
- buffer = (char *)NULL;
+ buffer = (char *) NULL;
return;
}
free (buffer);
- buffer = (char *)NULL;
+ buffer = (char *) NULL;
return;
}
@@ -1238,7 +1292,7 @@ read_keyboard_command (void *cls)
"Unknown command '%s'\n",
(char *) buffer);
free (buffer);
- buffer = (char *)NULL;
+ buffer = (char *) NULL;
keyboard_task = NULL;
start_read_keyboard ();
}
diff --git a/src/include/anastasis.h b/src/include/anastasis.h
index e2ebf07..0106ef3 100644
--- a/src/include/anastasis.h
+++ b/src/include/anastasis.h
@@ -153,7 +153,7 @@ struct ANASTASIS_ChallengeInformation
const char *url;
const char *instructions;
struct TALER_Amount *cost;
- const unsigned int *solved;
+ unsigned int solved;
const struct ANASTASIS_CRYPTO_TruthPublicKeyP *truth_public_key;
const struct ANASTASIS_CRYPTO_NonceP *nonce;
char *currency;
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.