diff --git a/java/org/servalproject/servaldna/ServalDCommand.java b/java/org/servalproject/servaldna/ServalDCommand.java index e28e3ee0..0bafddda 100644 --- a/java/org/servalproject/servaldna/ServalDCommand.java +++ b/java/org/servalproject/servaldna/ServalDCommand.java @@ -172,19 +172,22 @@ public class ServalDCommand public String did; public String name; public SubscriberId subscriberId; + public Map tags = new HashMap(); @Override public void putString(String value) { if (this.columnName.equals("did")) this.did = value; - if (this.columnName.equals("name")) + else if (this.columnName.equals("name")) this.name = value; - if (this.columnName.equals("sid")) + else if (this.columnName.equals("sid")) try { this.subscriberId = new SubscriberId(value); } catch (AbstractId.InvalidHexException e) { e.printStackTrace(); } + else + tags.put(columnName, value); } @Override @@ -223,10 +226,37 @@ public class ServalDCommand public static int keyringList(final AsyncResult results) throws ServalDFailureException { - return keyringList(new JniResultList(results) { + // FIXME, this is a little hacky as the number of tags is unknown so we don't have a fixed number of columns + return keyringList(new AbstractJniResults() { + IdentityResult id = null; + long fields=0; + String columnName; + @Override - public IdentityResult create() { - return new IdentityResult(); + public void putBlob(byte[] value) { + } + + @Override + public void setColumnName(int i, String name) { + columnName = name; + } + + @Override + public void putLong(long value) { + if (columnName.equals("fields")){ + fields=value; + id = new IdentityResult(); + } + } + + @Override + public void putString(String value) { + id.setColumnName(0, columnName); + id.putString(value); + if (fields--==0){ + results.result(id); + id=null; + } } }); } @@ -235,6 +265,12 @@ public class ServalDCommand return command(results, "keyring", "list"); } + public static IdentityResult keyringSetTag(SubscriberId sid, String tag, String value) throws ServalDFailureException { + IdentityResult result = new IdentityResult(); + command(result, "keyring", "set", "tag", sid.toHex(), tag, value); + return result; + } + public static IdentityResult reverseLookup(final SubscriberId sid) throws ServalDFailureException { IdentityResult result = new IdentityResult(); command(result, "reverse", "lookup", sid.toHex()); diff --git a/keyring_cli.c b/keyring_cli.c index 8ca29fde..41d003cc 100644 --- a/keyring_cli.c +++ b/keyring_cli.c @@ -196,6 +196,39 @@ static void cli_output_identity(struct cli_context *context, const keyring_ident } } +DEFINE_CMD(app_keyring_list2, 0, "List the full details of identities that can be accessed using the supplied PINs", + "keyring", "list", "--full" KEYRING_PIN_OPTIONS); +static int app_keyring_list2(const struct cli_parsed *parsed, struct cli_context *context) +{ + keyring_file *k = keyring_open_instance_cli(parsed); + if (!k) + return -1; + unsigned cn, in; + for (cn = 0; cn < k->context_count; ++cn) + for (in = 0; in < k->contexts[cn]->identity_count; ++in){ + const keyring_identity *id=k->contexts[cn]->identities[in]; + unsigned i; + unsigned fields=0; + // count the number of fields that we will output + for (i=0;ikeypair_count;i++){ + keypair *kp=id->keypairs[i]; + if (kp->type==KEYTYPE_CRYPTOBOX || kp->type==KEYTYPE_PUBLIC_TAG) + fields++; + if (kp->type==KEYTYPE_DID){ + if (strlen((char*)kp->private_key)) + fields++; + if (strlen((char*)kp->public_key)) + fields++; + } + } + cli_field_name(context, "fields", ":"); + cli_put_long(context, fields, "\n"); + cli_output_identity(context, id); + } + keyring_free(k); + return 0; +} + DEFINE_CMD(app_keyring_add, 0, "Create a new identity in the keyring protected by the supplied PIN (empty PIN if not given)", "keyring","add" KEYRING_PIN_OPTIONS,"[]");