add "meshms list conversations" command.

This commit is contained in:
gardners 2013-05-10 20:30:25 +09:30
parent 63339f4d18
commit 020ea915f3
6 changed files with 94 additions and 4 deletions

View File

@ -2306,6 +2306,8 @@ struct cli_schema command_line_options[]={
"Get specified configuration variable."}, "Get specified configuration variable."},
{app_vomp_console,{"console",NULL}, 0, {app_vomp_console,{"console",NULL}, 0,
"Test phone call life-cycle from the console"}, "Test phone call life-cycle from the console"},
{app_meshms_list_conversations,{"meshms","list","conversations" KEYRING_PIN_OPTIONS, "<sid>","[<offset>]","[<count>]",NULL},0,
"List MeshMS threads that include <sid>"},
{app_meshms_list_messages,{"meshms","list","messages" KEYRING_PIN_OPTIONS, "<sender_sid>","<recipient_sid>",NULL},0, {app_meshms_list_messages,{"meshms","list","messages" KEYRING_PIN_OPTIONS, "<sender_sid>","<recipient_sid>",NULL},0,
"List MeshMS messages between <sender_sid> and <recipient_sid>"}, "List MeshMS messages between <sender_sid> and <recipient_sid>"},
{app_meshms_add_message,{"meshms","add","message" KEYRING_PIN_OPTIONS, "[<sender_did>]","[<recipient_did>]","<sender_sid>","<recipient_sid>","<payload>",NULL},0, {app_meshms_add_message,{"meshms","add","message" KEYRING_PIN_OPTIONS, "[<sender_did>]","[<recipient_did>]","<sender_sid>","<recipient_sid>","<payload>",NULL},0,

View File

@ -485,3 +485,34 @@ int app_meshms_ack_messages(const struct cli_parsed *parsed, void *context)
return ret; return ret;
} }
int app_meshms_list_conversations(const struct cli_parsed *parsed, void *context)
{
if (create_serval_instance_dir() == -1)
return -1;
if (!(keyring = keyring_open_instance_cli(parsed)))
return -1;
if (rhizome_opendb() == -1)
return -1;
if (config.debug.verbose)
DEBUG_cli_parsed(parsed);
const char *sid,*offset_str,*count_str;
// Parse mandatory arguments
cli_arg(parsed, "sid", &sid, cli_optional_sid, "");
cli_arg(parsed, "offset", &offset_str, NULL, "0");
cli_arg(parsed, "count", &count_str, NULL, "9999");
int offset=atoi(offset_str);
int count=atoi(count_str);
// Sanity check passed arguments
if ( strcmp(sid,"") == 0 )
{
cli_puts("One or more missing arguments"); cli_delim("\n");
}
sid_t aSid;
if (sid[0] && str_to_sid_t(&aSid, sid) == -1)
return WHYF("invalid sid: %s", sid);
return rhizome_meshms_find_conversations(sid,offset,count);
}

View File

@ -721,5 +721,6 @@ int meshms_block_type(unsigned char *buffer,int offset, int blength);
int rhizome_meshms_find_conversation(const char *sender_sid, int rhizome_meshms_find_conversation(const char *sender_sid,
const char *recipient_sid, const char *recipient_sid,
char *manifest_id, int offset); char *manifest_id, int offset);
int rhizome_meshms_find_conversations(const char *sid, int offset, int count);
#endif //__SERVALDNA__RHIZOME_H #endif //__SERVALDNA__RHIZOME_H

View File

@ -1280,11 +1280,66 @@ cleanup:
OUT(); OUT();
} }
int rhizome_meshms_find_conversations(const char *sid, int offset, int count)
{
IN();
strbuf b = strbuf_alloca(1024);
strbuf_sprintf(b, "SELECT DISTINCT sender,recipient FROM manifests WHERE 1=1");
strbuf_sprintf(b, " AND ( sender = ?3 or recipient = ?3)");
strbuf_sprintf(b, " ORDER BY MIN(sender,recipient), MAX(sender,recipient)");
const char *names[]={
"partya","partyb"
};
cli_columns(2,names);
if (offset)
strbuf_sprintf(b, " OFFSET %u", offset);
if (strbuf_overrun(b))
RETURN(WHYF("SQL command too long: ", strbuf_str(b)));
//Statement is the SQL query and retry is the response from the database
sqlite_retry_state retry = SQLITE_RETRY_STATE_DEFAULT;
sqlite3_stmt *statement = sqlite_prepare(&retry, "%s", strbuf_str(b));
if (!statement)
RETURN(-1);
int ret = 0;
if (ret==SQLITE_OK && sid && *sid)
ret = sqlite3_bind_text(statement, 3, sid, -1, SQLITE_STATIC);
if (ret!=SQLITE_OK){
ret = WHYF("Failed to bind parameters: %s", sqlite3_errmsg(rhizome_db));
goto cleanup;
}
ret=-1;
int row=0;
while (sqlite_step_retry(&retry, statement) == SQLITE_ROW) {
if (!(sqlite3_column_count(statement) == 2
&& sqlite3_column_type(statement, 0) == SQLITE_TEXT
&& sqlite3_column_type(statement, 1) == SQLITE_TEXT
)) {
WHY("Incorrect row structure");
ret=-1;
goto cleanup;
}
row++;
if (row>count) break;
const char *sida = (const char *) sqlite3_column_text(statement, 0);
const char *sidb = (const char *) sqlite3_column_text(statement, 1);
cli_put_string(sida, ":");
cli_put_string(sidb, "\n");
}
cleanup:
sqlite3_finalize(statement);
RETURN(ret);
OUT();
}
void rhizome_bytes_to_hex_upper(unsigned const char *in, char *out, int byteCount) void rhizome_bytes_to_hex_upper(unsigned const char *in, char *out, int byteCount)
{ {

View File

@ -686,6 +686,7 @@ int app_vomp_console(const struct cli_parsed *parsed, void *context);
int app_meshms_add_message(const struct cli_parsed *parsed, void *context); int app_meshms_add_message(const struct cli_parsed *parsed, void *context);
int app_meshms_ack_messages(const struct cli_parsed *parsed, void *context); int app_meshms_ack_messages(const struct cli_parsed *parsed, void *context);
int app_meshms_list_messages(const struct cli_parsed *parsed, void *context); int app_meshms_list_messages(const struct cli_parsed *parsed, void *context);
int app_meshms_list_conversations(const struct cli_parsed *parsed, void *context);
int monitor_get_fds(struct pollfd *fds,int *fdcount,int fdmax); int monitor_get_fds(struct pollfd *fds,int *fdcount,int fdmax);