forked from cory/tildefriends
ssb: Add a command-line action to generate an invite, and verified that Patchwork can accept it.
This commit is contained in:
90
src/main.c
90
src/main.c
@ -149,6 +149,7 @@ static int _tf_command_run(const char* file, int argc, char* argv[]);
|
||||
static int _tf_command_sandbox(const char* file, int argc, char* argv[]);
|
||||
static int _tf_command_has_blob(const char* file, int argc, char* argv[]);
|
||||
static int _tf_command_store_blob(const char* file, int argc, char* argv[]);
|
||||
static int _tf_command_create_invite(const char* file, int argc, char* argv[]);
|
||||
static int _tf_command_get_sequence(const char* file, int argc, char* argv[]);
|
||||
static int _tf_command_get_identity(const char* file, int argc, char* argv[]);
|
||||
static int _tf_command_get_profile(const char* file, int argc, char* argv[]);
|
||||
@ -171,6 +172,7 @@ const command_t k_commands[] = {
|
||||
{ "export", _tf_command_export, "Export apps from SSB." },
|
||||
{ "publish", _tf_command_publish, "Append a message to a feed." },
|
||||
{ "private", _tf_command_private, "Append a private post message to a feed." },
|
||||
{ "create_invite", _tf_command_create_invite, "Create an invite." },
|
||||
{ "get_sequence", _tf_command_get_sequence, "Get the last sequence number for a feed." },
|
||||
{ "get_identity", _tf_command_get_identity, "Get the server account identity." },
|
||||
{ "get_profile", _tf_command_get_profile, "Get profile information for the given identity." },
|
||||
@ -801,6 +803,94 @@ static int _tf_command_has_blob(const char* file, int argc, char* argv[])
|
||||
return has ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||
}
|
||||
|
||||
static int _tf_command_create_invite(const char* file, int argc, char* argv[])
|
||||
{
|
||||
const char* default_db_path = _get_db_path();
|
||||
const char* db_path = default_db_path;
|
||||
const char* identity = NULL;
|
||||
int use_count = 0;
|
||||
int expires = 0;
|
||||
bool show_usage = false;
|
||||
const char* host = NULL;
|
||||
int port = 0;
|
||||
|
||||
while (!show_usage)
|
||||
{
|
||||
static const struct option k_options[] = {
|
||||
{ "db-path", required_argument, NULL, 'd' },
|
||||
{ "identity", required_argument, NULL, 'i' },
|
||||
{ "address", required_argument, NULL, 'a' },
|
||||
{ "port", required_argument, NULL, 'p' },
|
||||
{ "use_count", required_argument, NULL, 'u' },
|
||||
{ "expires", required_argument, NULL, 'e' },
|
||||
{ "help", no_argument, NULL, 'h' },
|
||||
{ 0 },
|
||||
};
|
||||
int c = getopt_long(argc, argv, "d:i:a:p:u:e:h", k_options, NULL);
|
||||
if (c == -1)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
switch (c)
|
||||
{
|
||||
case '?':
|
||||
case 'h':
|
||||
default:
|
||||
show_usage = true;
|
||||
break;
|
||||
case 'd':
|
||||
db_path = optarg;
|
||||
break;
|
||||
case 'i':
|
||||
identity = optarg;
|
||||
break;
|
||||
case 'a':
|
||||
host = optarg;
|
||||
break;
|
||||
case 'p':
|
||||
port = atoi(optarg);
|
||||
break;
|
||||
case 'u':
|
||||
use_count = atoi(optarg);
|
||||
break;
|
||||
case 'e':
|
||||
expires = atoi(optarg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (show_usage || !identity || !use_count || !expires || !host || !port)
|
||||
{
|
||||
tf_printf("\n%s get_sequence [options]\n\n", file);
|
||||
tf_printf("options:\n");
|
||||
tf_printf(" -d, --db-path db_path SQLite database path (default: %s).\n", default_db_path);
|
||||
tf_printf(" -i, --identity identity Account from which to get latest sequence number.\n");
|
||||
tf_printf(" -a, --address address Address to which the recipient will connect.\n");
|
||||
tf_printf(" -p, --port port Port to which the recipient will connect.\n");
|
||||
tf_printf(" -u, --use_count count Number of times this invite may be used.\n");
|
||||
tf_printf(" -e, --expires seconds How long this invite is valid in seconds (-1 for indefinitely).\n");
|
||||
tf_printf(" -h, --help Show this usage information.\n");
|
||||
tf_free((void*)default_db_path);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
int result = EXIT_FAILURE;
|
||||
tf_ssb_t* ssb = tf_ssb_create(NULL, NULL, db_path, NULL);
|
||||
tf_ssb_set_quiet(ssb, true);
|
||||
char invite[1024] = "";
|
||||
sqlite3* db = tf_ssb_acquire_db_writer(ssb);
|
||||
if (tf_ssb_db_generate_invite(db, identity, host, port, use_count, expires, invite, sizeof(invite)))
|
||||
{
|
||||
tf_printf("%s\n", invite);
|
||||
result = EXIT_SUCCESS;
|
||||
}
|
||||
tf_ssb_release_db_writer(ssb, db);
|
||||
tf_ssb_destroy(ssb);
|
||||
tf_free((void*)default_db_path);
|
||||
return result;
|
||||
}
|
||||
|
||||
static int _tf_command_get_sequence(const char* file, int argc, char* argv[])
|
||||
{
|
||||
const char* default_db_path = _get_db_path();
|
||||
|
Reference in New Issue
Block a user