[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-anastasis] branch master updated (7281285 -> aee07d5)
From: |
gnunet |
Subject: |
[taler-anastasis] branch master updated (7281285 -> aee07d5) |
Date: |
Tue, 25 Aug 2020 14:48:50 +0200 |
This is an automated email from the git hooks/post-receive script.
dennis-neufeld pushed a change to branch master
in repository anastasis.
from 7281285 fix crash when server url is not given with command 'server
add'
new e25bd2a fixed ugly thing
new c463b9b fix index
new 9de107d fix loop logic
new aee07d5 fixed cli splitter
The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
src/cli/anastasis-cli-assembler.c | 8 +-
src/cli/anastasis-cli-splitter.c | 215 ++++++++++++++++++++++++++++++--------
src/include/anastasis.h | 2 +-
3 files changed, 173 insertions(+), 52 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..89ace88 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;
}
@@ -839,7 +840,7 @@ read_keyboard_command (void *cls)
(0 == strcmp ("question", tu_states[i].method)))
{
printf ("truth#%u: %s \"%s\" <OMITTED>\n",
- i,
+ tu_states[i].index,
tu_states[i].method,
tu_states[i].secret_question);
}
@@ -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,39 @@ 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 +904,12 @@ 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 +927,14 @@ 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 +949,14 @@ 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 +973,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 +985,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 +1010,36 @@ 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;
+
+ // memorize tu_states of policies before appending tu_state
+ bool tu_mem[pc_states_length][tu_states_length];
+ if (pc_states_length > 0)
+ {
+ for (unsigned int i = 0; i < pc_states_length; i++)
+ {
+ printf ("%i:", i);
+ for (unsigned int j = 0; j < tu_states_length; j++)
+ {
+ bool match = false;
+ for (unsigned int k = 0; k < pc_states[i].tu_states_len; k++)
+ {
+ if (pc_states[i].tu_states[k]->index == j)
+ {
+ match = true;
+ break;
+ }
+ }
+ tu_mem[i][j] = match;
+ printf (" %d ", match);
+ }
+ printf ("\n");
+ }
+ }
tus->tuo = ANASTASIS_truth_upload (ctx,
servers[server_num].user_id,
servers[server_num].backend_url,
@@ -985,22 +1053,44 @@ read_keyboard_command (void *cls)
tus->tpc_cls,
&truth_upload_cb,
tus);
-
+ GNUNET_array_append (tu_states,
+ tu_states_length,
+ *tus);
+ // fix policies after appending tu_state
+ if (pc_states_length > 0)
+ {
+ printf ("\n");
+ for (unsigned int i = 0; i < pc_states_length; i++)
+ {
+ printf ("%i:", i);
+ unsigned int k = 0;
+ for (unsigned int j = 0; j < tu_states_length - 1; j++)
+ {
+ if (tu_mem[i][j] == true)
+ {
+ pc_states[i].tu_states[k] = &tu_states[j];
+ k++;
+ printf (" 1 ");
+ }
+ else
+ printf (" 0 ");
+ }
+ pc_states[i].tu_states_len = k;
+ printf ("\n");
+ }
+ }
if (NULL == tus->tuo)
{
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 +1098,24 @@ 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 +1149,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 +1177,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;
}
@@ -1083,28 +1185,48 @@ read_keyboard_command (void *cls)
buffer,
strlen ("policy add")))
{
+ if (characters == strlen ("policy add"))
+ {
+ printf ("Wrong argument: No truth given!\n");
+ printf (
+ "Example: policy add truth#0 truth#2\n");
+ free (buffer);
+ buffer = (char *) NULL;
+ start_read_keyboard ();
+ return;
+ }
struct PolicyCreateState *pcs = GNUNET_new (struct PolicyCreateState);
+ pcs->tu_states_len = 0;
char *token_start = &buffer[strlen ("policy add ")];
char *token = strtok (token_start, " ");
while (token != NULL)
{
- unsigned int tus_index;
if (0 != strncmp ("truth#",
token,
strlen ("truth#")))
{
printf ("Wrong argument: %s!\n", token);
free (buffer);
- buffer = (char *)NULL;
+ buffer = (char *) NULL;
+ start_read_keyboard ();
+ return;
+ }
+ unsigned int tus_index = (int) token[strlen ("truth#")] - 48;
+ 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;
}
- tus_index = (int) token[strlen ("truth#")] - 48;
-
- GNUNET_array_append (pcs->tu_states,
- pcs->tu_states_len,
- &tu_states[tus_index]);
- token = strtok (NULL, " ");
}
GNUNET_array_append (pc_states,
@@ -1113,7 +1235,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;
}
@@ -1133,6 +1255,7 @@ read_keyboard_command (void *cls)
for (unsigned int j = 0; j < pc_states[i].tu_states_len; j++)
{
+ GNUNET_assert (NULL != pc_states[i].tu_states[j]->truth);
truths[j] = pc_states[i].tu_states[j]->truth;
}
@@ -1155,7 +1278,7 @@ read_keyboard_command (void *cls)
error.column,
error.position);
free (buffer);
- buffer = (char *)NULL;
+ buffer = (char *) NULL;
GNUNET_SCHEDULER_shutdown ();
return;
}
@@ -1199,7 +1322,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 +1345,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 +1361,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.
- [taler-anastasis] branch master updated (7281285 -> aee07d5),
gnunet <=